import { RECIPES } from '../data/catalog.js?v=9'; import { getRecipeGridSectionHTML, renderRecipeGrid } from '../ui/recipeGrid.js'; const DEFAULT_MIN_MINUTES = 5; const DEFAULT_MAX_MINUTES = 120; let filterState = { query: '', slots: [], tags: [], minMinutes: DEFAULT_MIN_MINUTES, maxMinutes: DEFAULT_MAX_MINUTES, }; let recipeListDocListenersBound = false; function matchesFilters(recipe) { const { query, slots, tags, minMinutes, maxMinutes } = filterState; if (query) { const q = query.toLowerCase(); const haystack = `${recipe.title} ${(recipe.tags || []).join(' ')}`.toLowerCase(); if (!haystack.includes(q)) return false; } if (slots.length > 0) { if (!recipe.allowedSlots.some((s) => slots.includes(s))) return false; } if (tags.length > 0) { const recipeTags = (recipe.tags || []).map((t) => t.toLowerCase()); if (!tags.some((t) => recipeTags.includes(t.toLowerCase()))) return false; } if (minMinutes > DEFAULT_MIN_MINUTES && recipe.minutes < minMinutes) return false; if (maxMinutes < DEFAULT_MAX_MINUTES && recipe.minutes > maxMinutes) return false; return true; } function getFilteredRecipes() { return Object.values(RECIPES).filter(matchesFilters); } function syncRecipeScrollShadow() { const searchShell = document.getElementById('recipe-search-shell'); if (searchShell) { searchShell.style.boxShadow = 'var(--shadow-shell)'; } } function syncRecipeTopbarUI() { const searchShell = document.getElementById('recipe-search-shell'); if (searchShell) { searchShell.style.boxShadow = 'var(--shadow-shell)'; } } function closeSearch() { const input = document.getElementById('recipe-search-input'); const hadQuery = Boolean(input?.value); if (input) { input.value = ''; input.blur(); } filterState.query = ''; syncRecipeTopbarUI(); if (hadQuery) renderGrid(); } function renderGrid() { const grid = document.getElementById('recipe-grid'); const emptyState = document.getElementById('recipe-empty-state'); if (!grid) return; renderRecipeGrid({ gridEl: grid, emptyStateEl: emptyState, recipes: getFilteredRecipes(), showSlotLabels: false, cardClassName: 'recipe-list-card recipe-catalog-card', }); syncRecipeTopbarUI(); requestAnimationFrame(syncRecipeScrollShadow); } export function getRecipeListHTML() { return `