import { sparkle } from '@agent/icons';
import { useDomainActivities } from '@agent/state/domain-activities';
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 { setDomainActivity } = useDomainActivities();
const [allSuggestions, setAllSuggestions] = useState(suggestions);
const handleSelect = (suggestion) => {
markAsClicked(suggestion);
if (suggestion.tracking) {
setDomainActivity({ ...suggestion.tracking, action: 'clicked' });
}
// External-link suggestions are plain links: the anchor opens the new tab.
// They don't trigger a workflow or post a message in the chat.
if (suggestion.type === 'external-link') return;
window.dispatchEvent(
new CustomEvent('extendify-agent:chat-submit', {
detail: { message: suggestion.message },
}),
);
};
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 (