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.
Add a group, then enter at least two alternative terms—one per field.
) : (One term per field. Use a separate group for each product meaning.
Add at least two different terms before saving. Empty fields and repeated terms do not count.
}Up to 20 terms per group.
}Save Changes to apply your groups to storefront searches.
{groups.length >= MAX_SYNONYM_GROUPS &&Up to 100 groups.
}