const APP_ASSET_VERSION = window.__APP_ASSET_VERSION__ || new URL(import.meta.url).searchParams.get('v') || 'dev'; let getRecipeListHTML; let setupRecipeList; let getFilterHTML; let setupFilter; let getRecipeDetailHTML; let setupRecipeDetail; let getMealPlannerHTML; let setupMealPlanner; let getPantryHTML; let refreshPantry; let setupPantry; let getShoppingListHTML; let refreshShoppingList; let setupShoppingList; let getMealPlanEditorHTML; let setupMealPlanEditor; let getBottomNavHTML; let setupBottomNav; const moduleLoadPromise = Promise.all([ import(`./views/RecipeList.js?v=${APP_ASSET_VERSION}`), import(`./views/Filter.js?v=${APP_ASSET_VERSION}`), import(`./views/RecipeDetailV2.js?v=${APP_ASSET_VERSION}`), import(`./views/MealPlanner.js?v=${APP_ASSET_VERSION}`), import(`./views/Pantry.js?v=${APP_ASSET_VERSION}`), import(`./views/ShoppingList.js?v=${APP_ASSET_VERSION}`), import(`./ui/mealPlanEditor.js?v=${APP_ASSET_VERSION}`), import(`./ui/bottomNav.js?v=${APP_ASSET_VERSION}`), ]).then(([ recipeListModule, filterModule, recipeDetailModule, mealPlannerModule, pantryModule, shoppingListModule, mealPlanEditorModule, bottomNavModule, ]) => { ({ getRecipeListHTML, setupRecipeList } = recipeListModule); ({ getFilterHTML, setupFilter } = filterModule); ({ getRecipeDetailHTML, setupRecipeDetail } = recipeDetailModule); ({ getMealPlannerHTML, setupMealPlanner } = mealPlannerModule); ({ getPantryHTML, refreshPantry, setupPantry } = pantryModule); ({ getShoppingListHTML, refreshShoppingList, setupShoppingList } = shoppingListModule); ({ getMealPlanEditorHTML, setupMealPlanEditor } = mealPlanEditorModule); ({ getBottomNavHTML, setupBottomNav } = bottomNavModule); }); function getAppToastHTML() { return `
`; } let initAppPromise = null; function renderAppBootError(message) { const appContainer = document.getElementById('app-container'); if (!appContainer) return; appContainer.innerHTML = `

Nie udało się uruchomić aplikacji

${message}

`; } async function initApp() { if (initAppPromise) return initAppPromise; initAppPromise = (async () => { await moduleLoadPromise; const appContainer = document.getElementById('app-container'); if (!appContainer) return; appContainer.innerHTML = ` ${getRecipeListHTML()} ${getMealPlannerHTML()} ${getPantryHTML()} ${getShoppingListHTML()} ${getBottomNavHTML()} ${getRecipeDetailHTML()} ${getFilterHTML()} ${getMealPlanEditorHTML()} ${getAppToastHTML()} `; setupBottomNav({ refreshPantry, refreshShoppingList }); setupRecipeList(); setupMealPlanner(); setupPantry(); setupShoppingList(); setupFilter(); setupMealPlanEditor(); setupRecipeDetail(); })().catch((error) => { initAppPromise = null; throw error; }); return initAppPromise; } function bootApp() { initApp().catch((error) => { console.error('Failed to initialize app', error); renderAppBootError('Spróbuj odświeżyć aplikację. Jeśli problem wróci, zamknij ją całkowicie i otwórz ponownie.'); }); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', bootApp, { once: true }); } else { bootApp(); }