'use client' import { useState, useEffect } from 'react' import { DropdownMenu, DropdownMenuContent, DropdownMenuTrigger, DropdownMenuCheckboxItem, DropdownMenuSeparator, DropdownMenuLabel, } from '@/components/ui/dropdown-menu' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { Filter } from 'lucide-react' import { LABEL_COLORS } from '@/lib/types' import { cn } from '@/lib/utils' import { useLabels } from '@/context/LabelContext' import { LabelBadge } from './label-badge' interface LabelFilterProps { selectedLabels: string[] selectedColor?: string | null onFilterChange: (labels: string[]) => void onColorChange?: (color: string | null) => void } export function LabelFilter({ selectedLabels, selectedColor, onFilterChange, onColorChange }: LabelFilterProps) { const { labels, loading, getLabelColor } = useLabels() const [allLabelNames, setAllLabelNames] = useState([]) useEffect(() => { // Extract label names from labels array setAllLabelNames(labels.map((l: any) => l.name).sort()) }, [labels]) const handleToggleLabel = (label: string) => { if (selectedLabels.includes(label)) { onFilterChange(selectedLabels.filter((l: string) => l !== label)) } else { onFilterChange([...selectedLabels, label]) } } const handleClearAll = () => { onFilterChange([]) onColorChange?.(null) } const handleColorFilter = (color: string) => { if (selectedColor === color) { onColorChange?.(null) } else { onColorChange?.(color) } } if (loading || allLabelNames.length === 0) return null return (
Filter by Labels {selectedLabels.length > 0 && ( )} {/* Color Filter */}

Filter by Color

{Object.entries(LABEL_COLORS).map(([colorName, colorClasses]) => { const isSelected = selectedColor === colorName const labelCount = labels.filter((l: any) => l.color === colorName).length return ( ) })}
{/* Label Filters */} {!loading && allLabelNames.map((labelName: string) => { const isSelected = selectedLabels.includes(labelName) const isColorFiltered = selectedColor && selectedColor !== 'gray' return ( handleToggleLabel(labelName)} > ) })}
{/* Active filters display */} {!loading && selectedLabels.length > 0 && (
{selectedLabels.map((labelName: string) => ( handleToggleLabel(labelName)} /> ))}
)}
) }