import { useState } from 'react' import { Plus, Trash2 } from 'lucide-react' import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion' import { Button } from '@/components/ui/button' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import type { SynonymGroup } from '../config' import { getDistinctSynonymTerms, isSynonymGroupComplete, MAX_SYNONYM_GROUPS, MAX_SYNONYM_TERMS } from '../synonyms' interface SynonymGroupsProps { groups: SynonymGroup[] onChange: (groups: SynonymGroup[]) => void } export function SynonymGroups({ groups, onChange }: SynonymGroupsProps) { const [openGroup, setOpenGroup] = useState('') const addGroup = () => { const id = typeof crypto !== 'undefined' && typeof crypto.randomUUID === 'function' ? crypto.randomUUID() : `synonym-${Date.now()}-${Math.random().toString(36).slice(2)}` onChange([...groups, { id, words: ['', ''] }]) setOpenGroup(id) } const updateWords = (index: number, words: string[]) => { onChange(groups.map((group, current) => current === index ? { ...group, words } : group)) } return (

Group terms that mean the same thing. For example, add “sneakers” and “trainers” so a search for either can find products matching the other.

{groups.length === 0 ? (

Add a group, then enter at least two alternative terms—one per field.

) : ( {groups.map((group, groupIndex) => { const terms = getDistinctSynonymTerms(group.words) const complete = isSynonymGroupComplete(group) return ( {terms.length ? terms.slice(0, 3).join(' · ') : `New group ${groupIndex + 1}`} {terms.length > 3 ? ` +${terms.length - 3} more` : ''} {complete ? `${terms.length} terms` : 'Needs at least 2 different terms'}

One term per field. Use a separate group for each product meaning.

{group.words.map((word, wordIndex) => (
updateWords(groupIndex, group.words.map((value, index) => index === wordIndex ? event.target.value : value))} />
))}
{!complete &&

Add at least two different terms before saving. Empty fields and repeated terms do not count.

}
{group.words.length >= MAX_SYNONYM_TERMS &&

Up to 20 terms per group.

}
) })}
)}

Save Changes to apply your groups to storefront searches.

{groups.length >= MAX_SYNONYM_GROUPS &&

Up to 100 groups.

}
) }