Cooking Helper for Kids

Cooking Helper for Kids

Select a Recipe

Choose a yummy recipe to make!

• ${item}

`).join(''); chk_safetySection.style.display = 'block'; // Show/Hide Timer chk_timerSection.style.display = chk_selectedRecipe.timerNeeded ? 'block' : 'none'; chk_resetTimer(); // Reset timer when loading recipe // Update selected card style document.querySelectorAll('.chk-recipe-card').forEach(card => { card.classList.toggle('chk-selected-recipe', card.dataset.recipeKey === recipeKey); }); chk_pdfBtn.disabled = false; } else { // Initial placeholder state chk_recipeTitle.textContent = "Choose a Recipe!"; chk_ingredientSection.style.display = 'none'; chk_stepsSection.style.display = 'none'; chk_safetySection.style.display = 'none'; chk_timerSection.style.display = 'none'; chk_pdfBtn.disabled = true; } } // --- EVENT HANDLERS --- function chk_handleRecipeSelect(e) { const card = e.target.closest('.chk-recipe-card'); if (card && card.dataset.recipeKey) { chk_loadRecipe(card.dataset.recipeKey); // Switch back to recipe tab chk_showTab(0, chk_tabLinks[0]); } } // --- TIMER FUNCTIONS --- function chk_startTimer() { if (chk_timerRunning) return; // Prevent multiple starts const minutes = parseInt(chk_timerMinutesInput.value); if (isNaN(minutes) || minutes <= 0) return; chk_timerSeconds = minutes * 60; chk_timerRunning = true; chk_timerStartBtn.disabled = true; chk_timerMinutesInput.disabled = true; chk_updateTimerDisplay(); // Show initial time immediately chk_timerInterval = setInterval(() => { chk_timerSeconds--; chk_updateTimerDisplay(); if (chk_timerSeconds <= 0) { chk_stopTimer(); alert("⏰ Time's up!"); // Simple alert for now // Optionally play a sound here } }, 1000); } function chk_stopTimer() { clearInterval(chk_timerInterval); chk_timerRunning = false; chk_timerStartBtn.disabled = false; chk_timerMinutesInput.disabled = false; } function chk_resetTimer() { chk_stopTimer(); chk_timerSeconds = 0; // Optionally reset input value, or keep user's last setting // chk_timerMinutesInput.value = 5; chk_resetTimerDisplay(); } function chk_resetTimerDisplay() { const minutes = parseInt(chk_timerMinutesInput.value) || 0; const displayMinutes = String(minutes).padStart(2, '0'); chk_timerDisplay.textContent = `${displayMinutes}:00`; } function chk_updateTimerDisplay() { const minutes = Math.floor(chk_timerSeconds / 60); const seconds = chk_timerSeconds % 60; chk_timerDisplay.textContent = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`; } // --- TAB NAVIGATION --- window.chk_showTab = function (tabIndex, element) { if (!chk_tabPanels || !chk_tabLinks) return; chk_currentTab = tabIndex; chk_tabPanels.forEach((panel) => panel.classList.remove("chk-active")); chk_tabLinks.forEach((link) => link.classList.remove("chk-active")); if (chk_tabPanels[tabIndex]) { chk_tabPanels[tabIndex].classList.add("chk-active"); } if (element) { element.classList.add("chk-active"); } chk_updateNavButtons(); }; function chk_goToNextTab() { if (chk_currentTab < chk_tabPanels.length - 1) { chk_currentTab++; chk_showTab(chk_currentTab, chk_tabLinks[chk_currentTab]); } } function chk_goToPrevTab() { if (chk_currentTab > 0) { chk_currentTab--; chk_showTab(chk_currentTab, chk_tabLinks[chk_currentTab]); } } function chk_updateNavButtons() { if (!chk_prevBtn || !chk_nextBtn) return; chk_prevBtn.disabled = chk_currentTab === 0; chk_nextBtn.disabled = chk_currentTab === chk_tabPanels.length - 1; } // --- PDF EXPORT --- function chk_downloadPDF() { if (typeof jspdf === "undefined") { console.error("jsPDF library not loaded."); alert("Error: PDF generation library failed to load."); return; } if (!chk_selectedRecipe) { alert("Please select a recipe first!"); return; } const { jsPDF } = jspdf; const doc = new jsPDF({ orientation: "p", unit: "pt", format: "a4", }); const margin = 40; const pageWidth = doc.internal.pageSize.getWidth(); const contentWidth = pageWidth - margin * 2; let yPos = margin; doc.setFont('Fredoka', 'normal'); // Use the Fredoka font if loaded (jsPDF might need font registration for this) doc.setFontSize(22); doc.setFont('Fredoka', 'bold'); doc.text(chk_selectedRecipe.name, pageWidth / 2, yPos, { align: 'center' }); yPos += 40; // Ingredients doc.setFontSize(16); doc.text("Ingredients", margin, yPos); yPos += 25; doc.setFontSize(11); doc.setFont('Fredoka', 'normal'); chk_selectedRecipe.ingredients.forEach(item => { doc.text(`• ${item}`, margin + 15, yPos); yPos += 15; if (yPos > doc.internal.pageSize.getHeight() - margin) { doc.addPage(); yPos = margin; } }); yPos += 10; // Extra space // Steps doc.setFontSize(16); doc.setFont('Fredoka', 'bold'); doc.text("Steps", margin, yPos); yPos += 25; doc.setFontSize(11); doc.setFont('Fredoka', 'normal'); chk_selectedRecipe.steps.forEach((step, index) => { const stepText = `${index + 1}. ${step}`; const lines = doc.splitTextToSize(stepText, contentWidth - 15); doc.text(lines, margin + 15, yPos); yPos += (lines.length * 11 * 1.4) + 5; // Approx line height if (yPos > doc.internal.pageSize.getHeight() - margin) { doc.addPage(); yPos = margin; } }); yPos += 10; // Safety Tips doc.setFontSize(14); doc.setFont('Fredoka', 'bold'); doc.text("Safety Tips!", margin, yPos); yPos += 20; doc.setFontSize(10); doc.setFont('Fredoka', 'normal'); chk_selectedRecipe.safety.forEach(tip => { doc.text(`• ${tip}`, margin + 15, yPos); yPos += 13; if (yPos > doc.internal.pageSize.getHeight() - margin) { doc.addPage(); yPos = margin; } }); doc.save(`${chk_selectedRecipe.name.replace(/\s/g, '_')}_Recipe.pdf`); } })();