';
let listHtml = document.getElementById('shopping-list-container').innerHTML
.replace(/class="[^"]*"/g, '') // remove classes
.replace(/div/g, 'p') // change divs to p for better spacing
.replace(/
Weekly Meal Plan & Shopping List
Budget: $${budget} |
People: ${people} |
Diet: ${diet}
Meal Plan
${planHtml}
Shopping List
${listHtml}
`;
document.body.appendChild(pdfContainer);
window.html2canvas(pdfContainer, { scale: 2 }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const contentWidth = pdfWidth - 80;
const imgHeight = canvas.height * contentWidth / canvas.width;
pdf.addImage(imgData, 'PNG', 40, 40, contentWidth, imgHeight);
pdf.save('Healthy_Budget_Plan.pdf');
document.body.removeChild(pdfContainer);
});
};
initialize();
});
function switchTab(tabId) {
const tabs = ['setup', 'plan', 'list'];
tabs.forEach(id => {
document.getElementById(`${id}-tab`).style.display = (id === tabId) ? 'block' : 'none';
document.getElementById(`tab-${id}-btn`).classList.toggle('active', id === tabId);
});
const showDownload = (tabId === 'plan' || tabId === 'list');
document.getElementById('download-container').style.display = showDownload ? 'block' : 'none';
if (showDownload) {
document.getElementById('tab-plan-btn').disabled = false;
document.getElementById('tab-list-btn').disabled = false;
}
}