import { useState } from 'react' import { ChevronLeft, FolderPlus, Pencil, SlidersHorizontal, Trash2, } from 'lucide-react' import type { Category } from '../data/categories' import styles from './CategoryItem.module.css' type CategoryItemProps = { category: Category depth?: number onAddChild: (parentId: string) => void onEdit: (category: Category) => void onOpenOptions: (category: Category) => void onRemove: (id: string) => void } export function CategoryItem({ category, depth = 0, onAddChild, onEdit, onOpenOptions, onRemove, }: CategoryItemProps) { const hasChildren = category.children.length > 0 const [open, setOpen] = useState(false) function toggleOpen() { if (!hasChildren) return setOpen((value) => !value) } return (
  • 0 ? styles.childRow : ''} ${hasChildren ? styles.rowClickable : ''}`} role={hasChildren ? 'button' : undefined} tabIndex={hasChildren ? 0 : undefined} aria-expanded={hasChildren ? open : undefined} onClick={toggleOpen} onKeyDown={(event) => { if (!hasChildren) return if (event.key === 'Enter' || event.key === ' ') { event.preventDefault() toggleOpen() } }} > {hasChildren && ( )}
    {category.nameFa} {category.nameEn}
    event.stopPropagation()} onKeyDown={(event) => event.stopPropagation()} >
    {hasChildren && open && ( )}
  • ) }