import { getRecipeListHTML, setupRecipeList } from './views/RecipeList.js'; import { getFilterHTML, setupFilter } from './views/Filter.js'; import { getRecipeDetailHTML, setupRecipeDetail } from './views/RecipeDetailV2.js'; import { getMealPlannerHTML, setupMealPlanner } from './views/MealPlanner.js'; import { getPantryHTML, refreshPantry, setupPantry } from './views/Pantry.js'; import { getShoppingHTML, refreshShopping, setupShopping } from './views/Shopping.js'; function getAppToastHTML() { return `
`; } function getBottomNavHTML() { return ` `; } function setupTabs() { const main = document.getElementById('main-view'); const planner = document.getElementById('planner-view'); const pantry = document.getElementById('pantry-view'); const shopping = document.getElementById('shopping-view'); const nav = document.getElementById('app-bottom-nav'); if (!main || !planner || !pantry || !shopping || !nav) return; const activeTab = 'nav-tab flex flex-col items-center gap-0.5 text-black flex-1 min-w-0 max-w-[5.5rem]'; const idleTab = 'nav-tab flex flex-col items-center gap-0.5 text-gray-500 hover:text-gray-700 flex-1 min-w-0 max-w-[5.5rem]'; const apply = (tab) => { main.classList.toggle('hidden', tab !== 'recipes'); planner.classList.toggle('hidden', tab !== 'planner'); pantry.classList.toggle('hidden', tab !== 'pantry'); shopping.classList.toggle('hidden', tab !== 'shopping'); if (tab === 'pantry') refreshPantry(); if (tab === 'shopping') refreshShopping(); nav.querySelectorAll('.nav-tab[data-tab]').forEach((btn) => { const id = btn.getAttribute('data-tab'); if (btn.hasAttribute('disabled')) return; if (id === 'recipes' || id === 'planner' || id === 'pantry' || id === 'shopping') { btn.className = id === tab ? activeTab : idleTab; } }); }; nav.addEventListener('click', (e) => { const btn = e.target.closest('.nav-tab[data-tab]'); if (!btn || btn.hasAttribute('disabled')) return; const tab = btn.getAttribute('data-tab'); if (tab === 'recipes' || tab === 'planner' || tab === 'pantry' || tab === 'shopping') apply(tab); }); apply('recipes'); window.refreshStockViews = () => { refreshPantry(); refreshShopping(); }; } document.addEventListener('DOMContentLoaded', () => { const appContainer = document.getElementById('app-container'); appContainer.innerHTML = ` ${getRecipeListHTML()} ${getMealPlannerHTML()} ${getPantryHTML()} ${getShoppingHTML()} ${getBottomNavHTML()} ${getRecipeDetailHTML()} ${getFilterHTML()} ${getAppToastHTML()} `; setupTabs(); setupRecipeList(); setupMealPlanner(); setupPantry(); setupShopping(); setupFilter(); setupRecipeDetail(); });