import { useState, useRef, useEffect, createContext, useContext } from 'react'; import { ChevronDown, X } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useDarkMode } from '@/hooks/useDarkMode'; import { CategoryCounts, CategoryColorTheme, formatCategoryName, getCategoryCount, getCategoryColorTheme, } from '@/lib/skills-utils'; interface FilterDropdownProps { categories: string[]; categoryCounts: CategoryCounts; selectedCategory: string; filteredCount: number; onSelect: (category: string) => void; } const CategoryThemeContext = createContext(null); function useCategoryTheme(categoryKey: string): CategoryColorTheme { const isDark = useDarkMode(); return getCategoryColorTheme(categoryKey, isDark); } export function FilterDropdown({ categories, categoryCounts, selectedCategory, filteredCount, onSelect, }: FilterDropdownProps) { const [isOpen, setIsOpen] = useState(false); const rootRef = useRef(null); const isDark = useDarkMode(); const triggerTheme = getCategoryColorTheme(selectedCategory, isDark); useEffect(() => { function handleClickOutside(event: MouseEvent) { if (rootRef.current && !rootRef.current.contains(event.target as Node)) { setIsOpen(false); } } document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, []); useEffect(() => { function handleEscape(event: KeyboardEvent) { if (event.key === 'Escape') setIsOpen(false); } document.addEventListener('keydown', handleEscape); return () => document.removeEventListener('keydown', handleEscape); }, []); const isFiltered = selectedCategory !== 'all'; const selectedLabel = selectedCategory === 'all' ? 'All' : formatCategoryName(selectedCategory); const handleClear = (e: React.MouseEvent) => { e.stopPropagation(); onSelect('all'); setIsOpen(false); }; return (
{isFiltered && ( )}
{isOpen && (
    { onSelect('all'); setIsOpen(false); }} /> {categories.map((category) => ( { onSelect(category); setIsOpen(false); }} /> ))}

{filteredCount} shown

)}
); } function CategoryDot({ categoryKey }: { categoryKey: string }) { const theme = useContext(CategoryThemeContext) ?? useCategoryTheme(categoryKey); const { dot } = theme; return ( ); } function CategoryCountPill({ categoryKey, count, }: { categoryKey: string; count: number; }) { const theme = useContext(CategoryThemeContext) ?? useCategoryTheme(categoryKey); return ( {count} ); } function FilterOption({ categoryKey, label, count, selected, onSelect, }: { categoryKey: string; label: string; count: number; selected: boolean; onSelect: () => void; }) { const isDark = useDarkMode(); const theme = getCategoryColorTheme(categoryKey, isDark); return (
  • ); }