{filtered.length === 0 ? (
No categories found
) : q ? (
// Search mode — flat list, no animation
filtered.map((cat) => {
const hasChildren = (cat.subCategories?.length ?? 0) > 0;
const matchingChildren = cat.subCategories?.filter((s) =>
s.name.toLowerCase().includes(q),
);
return (
{(!hasChildren || cat.name.toLowerCase().includes(q)) &&
(hasChildren ? (
// Non-selectable group header
{cat.name}
) : (
setSelected(cat.id)}
/>
))}
{matchingChildren?.map((sub) => (
setSelected(sub.id)}
/>
))}
);
})
) : (
// Browse mode — accordion with animated expand/collapse
setOpenItem(v[0] ?? "")}
>
{filtered.map((cat) => {
if ((cat.subCategories?.length ?? 0) > 0) {
return (
{cat.name}
{cat.subCategories!.map((sub) => (
setSelected(sub.id)}
/>
))}
);
}
return (
setSelected(cat.id)}
/>
);
})}
)}
{/* Apply to future toggle */}