import { sparkle } from '@agent/icons'; import { useSuggestionsStore } from '@agent/state/suggestions'; import { useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { chevronRight, drafts, help, pencil, published, siteLogo, styles, swatch, typography, video, } from '@wordpress/icons'; const icons = { styles, edit: pencil, help, video, sparkle, drafts, published, typography, pencil, siteLogo, swatch, }; export const ChatSuggestions = ({ suggestions }) => { const { markAsClicked, isAvailable, getSuggestions } = useSuggestionsStore(); const [allSuggestions, setAllSuggestions] = useState(suggestions); const handleSubmit = (suggestion) => { window.dispatchEvent( new CustomEvent('extendify-agent:chat-submit', { detail: { message: suggestion.message }, }), ); markAsClicked(suggestion); }; const handleShowMore = () => { const next = getSuggestions({ slice: 6, exclude: allSuggestions }); setAllSuggestions((prev) => [...prev, ...next]); }; if (!suggestions) return null; return ( <> {allSuggestions.map((suggestion) => { // Hide them if it's not available to the user if (!isAvailable(suggestion)) return null; return ( ); })} > ); }; const SuggestionButton = ({ suggestion, handleSubmit }) => { const icon = icons[suggestion?.icon] ?? icons.sparkle; return ( handleSubmit(suggestion)} > {icon} {suggestion.message} {chevronRight} ); }; const ShowMoreButton = ({ handleShowMore }) => { const [hide, setHide] = useState(false); const handleClick = () => { handleShowMore(); setHide(true); }; if (hide) return null; return ( {__('Show more', 'extendify-local')} ); };