import { useState, useEffect } from "react"; import placeholderLight from "../assets/placeholder-light.png"; import placeholderDark from "../assets/placeholder-dark.png"; function RecipeSearchList({ allRecipes, recipes, selectedId, onSelect, searchQuery, onSearchChange, filterMealType, onMealTypeChange, filterMaxTime, onMaxTimeChange, filterTags, onTagsChange, filterOwner, onOwnerChange, }) { const [expandFilters, setExpandFilters] = useState(false); const [theme, setTheme] = useState(document.documentElement.getAttribute('data-theme') || 'dark'); useEffect(() => { const observer = new MutationObserver(() => { setTheme(document.documentElement.getAttribute('data-theme') || 'dark'); }); observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] }); return () => observer.disconnect(); }, []); const placeholderImage = theme === 'dark' ? placeholderDark : placeholderLight; // Extract unique tags from ALL recipes (not filtered) const allTags = Array.from( new Set(allRecipes.flatMap((recipe) => recipe.tags || [])) ).sort(); // Extract unique meal types from ALL recipes (not filtered) const mealTypes = Array.from(new Set(allRecipes.map((r) => r.meal_type))).sort(); // Extract unique made_by values from ALL recipes // The made_by field is what the user defined when creating the recipe, // so we use it for both filtering and display const madeByMap = new Map(); allRecipes.forEach((r) => { if (r.made_by) { // Always use made_by as the display name (it's the custom name the user entered) if (!madeByMap.has(r.made_by)) { madeByMap.set(r.made_by, r.made_by); } } }); const allMadeBy = Array.from(madeByMap.keys()).sort(); // Extract max time for slider from ALL recipes (not filtered) - add 10 to make it comfortable to select max time recipes const maxTimeInRecipes = Math.max(...allRecipes.map((r) => r.time_minutes), 0); const sliderMax = maxTimeInRecipes > 0 ? maxTimeInRecipes + 10 : 70; const handleTagToggle = (tag) => { if (filterTags.includes(tag)) { onTagsChange(filterTags.filter((t) => t !== tag)); } else { onTagsChange([...filterTags, tag]); } }; const clearAllFilters = () => { onSearchChange(""); onMealTypeChange(""); onMaxTimeChange(""); onTagsChange([]); onOwnerChange(""); }; const hasActiveFilters = searchQuery || filterMealType || filterMaxTime || filterTags.length > 0 || filterOwner; return (
{/* Header with Search */}
onSearchChange(e.target.value)} /> {searchQuery && ( )}
{/* Filter Toggle Button */}
{/* Expandable Filters */} {expandFilters && (
{/* Meal Type Filter */} {mealTypes.length > 0 && (
{mealTypes.map((type) => ( ))}
)} {/* Prep Time Filter */} {maxTimeInRecipes > 0 && (
{ const val = parseInt(e.target.value, 10); onMaxTimeChange(val === 0 ? "" : String(val)); }} className="time-slider" />
0 {sliderMax}
)} {/* Tags Filter */} {allTags.length > 0 && (
{allTags.map((tag) => ( ))}
)} {/* Made By Filter */} {allMadeBy.length > 0 && (
{allMadeBy.map((madeBy) => ( ))}
)}
{/* Clear All Button */} {hasActiveFilters && ( )}
)} {/* Recipe List Header */}

כל המתכונים

{recipes.length}
{/* Recipe List */} {recipes.length === 0 ? (

עדיין אין מתכונים שתואמים את הסינונים שלך.

) : ( )}
); } function translateMealType(type) { switch (type) { case "breakfast": return "בוקר"; case "lunch": return "צהריים"; case "dinner": return "ערב"; case "snack": return "קינוחים"; default: return type; } } export default RecipeSearchList;