'use client'; import { useState, useMemo } from 'react'; interface RecipesSidebarProps { categories: string[]; tags: string[]; onFilterChange: (filters: FilterState) => void; isOpen: boolean; onToggle: () => void; } export interface FilterState { search: string; category: string; selectedTags: string[]; } export default function RecipesSidebar({ categories, tags, onFilterChange, isOpen, onToggle }: RecipesSidebarProps) { const [search, setSearch] = useState(''); const [category, setCategory] = useState(''); const [selectedTags, setSelectedTags] = useState([]); const [showAllTags, setShowAllTags] = useState(false); useMemo(() => { onFilterChange({ search, category, selectedTags }); }, [search, category, selectedTags, onFilterChange]); const handleTagToggle = (tag: string) => { setSelectedTags((prev) => prev.includes(tag) ? prev.filter((t) => t !== tag) : [...prev, tag] ); }; const handleClearFilters = () => { setSearch(''); setCategory(''); setSelectedTags([]); }; const hasActiveFilters = search || category || selectedTags.length > 0; const displayedTags = showAllTags ? tags : tags.slice(0, 10); return ( ); }