import "./styles.css"; import data from "./data.json"; let spiritsData = []; let recipesData = []; async function loadData() { try { spiritsData = data.spirits.sort((a, b) => a.name > b.name); recipesData = data.recipes.sort((a, b) => a.name > b.name); renderSpirits(); enableButtonsLogic(); } catch (error) { console.error("Error cargando datos:", error); document.getElementById("spiritsGrid").innerHTML = '
Error al cargar los datos. Asegúrate de que data.json está disponible.
'; } } function renderSpirits() { const grid = document.getElementById("spiritsGrid"); grid.innerHTML = spiritsData .map( (spirit, index) => `Por favor, selecciona al menos un licor para encontrar recetas.
'; return; } const availableRecipes = recipesData.filter((recipe) => { const alcoholIngredients = recipe.ingredients.filter( (ing) => ing.isAlcohol, ); return alcoholIngredients.every((ingredient) => selectedSpirits.includes(ingredient.type), ); }); renderRecipes(availableRecipes); document.getElementById("recipesContainer").scrollIntoView({ behavior: "smooth", block: "start", }); } function renderRecipes(recipes) { const container = document.getElementById("recipesContainer"); if (recipes.length === 0) { container.innerHTML = 'No se encontraron recetas con los licores seleccionados. ¡Intenta agregar más licores!
'; return; } container.innerHTML = recipes .map((recipe) => { const alcoholIngredients = recipe.ingredients.filter( (ing) => ing.isAlcohol, ); const nonAlcoholIngredients = recipe.ingredients.filter( (ing) => !ing.isAlcohol, ); return `