document.addEventListener('DOMContentLoaded', function() { // Handle recipe search if on search page if (window.location.pathname.includes('search.html')) { const searchBtn = document.getElementById('search-btn'); const searchQuery = document.getElementById('search-query'); const resultsDiv = document.getElementById('results'); searchBtn.addEventListener('click', function() { // Always show results, empty search shows all recipes const mockResults = [ { title: "Chicken & Rice", calories: 450, servings: 4, time: "30 mins", ingredients: [ "2 chicken breasts, diced", "1 cup white rice", "2 tbsp olive oil", "1 onion, chopped", "2 cloves garlic, minced", "1 tsp salt", "1/2 tsp black pepper" ], instructions: [ "Heat oil in a large pan over medium heat", "Add onions and garlic, cook until soft", "Add chicken and cook until no longer pink", "Add rice and stir to coat with oil", "Add 2 cups water and bring to boil", "Reduce heat, cover and simmer for 20 minutes", "Season with salt and pepper" ], image: "http://static.photos/food/320x240/1" }, { title: "Vegetable Stir Fry", calories: 320, servings: 2, time: "15 mins", ingredients: [ "2 cups broccoli florets", "1 carrot, julienned", "1 bell pepper, sliced", "2 tbsp soy sauce", "1 tbsp sesame oil", "1 tsp ginger, grated" ], instructions: [ "Heat oil in a wok or large pan", "Add ginger and stir for 30 seconds", "Add vegetables and stir fry for 5 minutes", "Add soy sauce and continue cooking for 2 minutes", "Serve hot" ], image: "http://static.photos/food/320x240/2" }, { title: "Avocado Toast", calories: 220, servings: 1, time: "5 mins", ingredients: [ "1 slice whole grain bread", "1/2 avocado", "1 tsp lemon juice", "Pinch of salt", "Red pepper flakes (optional)" ], instructions: [ "Toast the bread until golden", "Mash avocado with lemon juice and salt", "Spread avocado mixture on toast", "Sprinkle with red pepper flakes if desired" ], image: "http://static.photos/food/320x240/3" } ]; // Filter if search query exists const query = searchQuery.value.trim().toLowerCase(); const filteredResults = query ? mockResults.filter(recipe => recipe.ingredients.some(ing => ing.toLowerCase().includes(query)) || recipe.title.toLowerCase().includes(query) ) : mockResults; displaySearchResults(filteredResults); }); function displaySearchResults(recipes) { if (recipes.length === 0) { resultsDiv.innerHTML = '
No recipes found. Try a different search.
'; return; } resultsDiv.innerHTML = recipes.map(recipe => `${recipe.calories} calories
Ingredients: ${recipe.ingredients.join(', ')}
${data.calories}
${data.protein}
${data.carbs}
${data.fat}
${data.fiber}
${data.sugar}