let allRecipes = []; let activeTags = new Set(); let allTags = new Set(); const TAG_LABELS = { "heart-healthy": "❤️ Heart Healthy", "diabetic": "🩸 Diabetic Safe", "low-sodium": "🧂 Low Sodium", "gluten-free": "🌾 Gluten-Free", "kidney-friendly": "🫘 Kidney Friendly", "low-carb": "🥩 Low Carb", "vegan": "🥗 Vegan", "dairy-free": "🥛 Dairy-Free", "keto": "🥑 Keto", "breakfast": "🍳 Breakfast", "lunch": "🥪 Lunch", "dinner": "🍲 Dinner", "snacks": "🥨 Snacks" }; document.addEventListener('DOMContentLoaded', () => { fetch('recipes.json') .then(res => res.json()) .then(data => { allRecipes = data; extractTags(); renderToggles(); renderGrid(); }) .catch(err => console.error("Could not load recipes:", err)); }); function extractTags() { allRecipes.forEach(recipe => { recipe.tags.forEach(tag => allTags.add(tag)); }); } function renderToggles() { const container = document.getElementById('filter-toggles'); container.innerHTML = ''; // Sort tags alphabetically but prioritize medical ones const sortedTags = Array.from(allTags).sort(); sortedTags.forEach(tag => { const btn = document.createElement('button'); btn.className = 'tag-btn'; btn.textContent = TAG_LABELS[tag] || tag; btn.dataset.tag = tag; btn.addEventListener('click', () => { if (activeTags.has(tag)) { activeTags.delete(tag); btn.classList.remove('active'); } else { activeTags.add(tag); btn.classList.add('active'); } renderGrid(); }); container.appendChild(btn); }); } function formatTagText(tag) { return TAG_LABELS[tag] || tag; } function renderGrid() { const container = document.getElementById('recipe-grid'); container.innerHTML = ''; // FILTER LOGIC: Recipe must contain ALL active tags const filtered = allRecipes.filter(recipe => { for (let tag of activeTags) { if (!recipe.tags.includes(tag)) return false; } return true; }); document.getElementById('res-count').textContent = filtered.length; if (filtered.length === 0) { container.innerHTML = '