import React, { useState } from 'react'; import { __ } from '@wordpress/i18n'; import { ChevronRight, Search } from 'lucide-react'; /** * Gleap-style "Search for help" card: a search field that filters the help * questions, followed by the matching questions. Picking a question (or * submitting the search) starts a new chat with that text. */ const HelpSearchCard = ({ questions = [], onSelect, limit = 5, disabled = false }) => { const [query, setQuery] = useState(''); const list = (Array.isArray(questions) ? questions : []).filter((q) => typeof q === 'string' && q.trim() !== ''); const term = query.trim().toLowerCase(); const matches = (term ? list.filter((q) => q.toLowerCase().includes(term)) : list).slice(0, limit); if (list.length === 0) return null; const handleSubmit = (e) => { e.preventDefault(); if (!term || disabled) return; onSelect(query.trim()); setQuery(''); }; return (
setQuery(e.target.value)} placeholder={__( 'Search for help', 'aisk-ai-chat' )} aria-label={__( 'Search for help', 'aisk-ai-chat' )} disabled={disabled} />
{matches.map((question, index) => ( ))} {term && matches.length === 0 && ( )}
); }; export default HelpSearchCard;