import { useState } from "react"; import placeholderImage from "../assets/placeholder.svg"; function RecipeSearchList({ allRecipes, recipes, selectedId, onSelect, searchQuery, onSearchChange, filterMealType, onMealTypeChange, filterMaxTime, onMaxTimeChange, filterTags, onTagsChange, }) { const [expandFilters, setExpandFilters] = useState(false); // 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 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([]); }; const hasActiveFilters = searchQuery || filterMealType || filterMaxTime || filterTags.length > 0; 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) => ( ))}
)}
{/* 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;