Customer Gets:
Product: ${data.getProduct}
Quantity: ${data.getQuantity}
Discount: ${data.getDiscount}% OFF
Conditions:
Offer Period: ${data.startDate} to ${data.endDate}
Limit per Customer: ${data.usageLimit}
`;
};
const downloadPDF = () => {
const { jsPDF } = window.jspdf;
const reportContainer = document.getElementById('reportContainer');
// Temporarily apply a class to the body for specific PDF styling
document.body.classList.add('pdf-generating');
html2canvas(reportContainer, {
scale: 2, // Higher quality
useCORS: true,
backgroundColor: '#ffffff'
}).then(canvas => {
document.body.classList.remove('pdf-generating'); // Clean up
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({
orientation: 'portrait',
unit: 'mm',
format: 'a4'
});
const pdfWidth = pdf.internal.pageSize.getWidth();
const margin = 15;
const contentWidth = pdfWidth - margin * 2;
const aspectRatio = canvas.width / canvas.height;
const contentHeight = contentWidth / aspectRatio;
// Add header
pdf.setFont('helvetica', 'bold');
pdf.setFontSize(22);
pdf.setTextColor('#0891b2'); // Cyan color
pdf.text('BOGO Offer Summary', pdfWidth / 2, margin + 5, { align: 'center' });
// Add image of the summary
pdf.addImage(imgData, 'PNG', margin, margin + 20, contentWidth, contentHeight);
// Add footer
pdf.setFontSize(9);
pdf.setTextColor(150);
pdf.text(`Report generated on: ${new Date().toLocaleDateString()}`, pdfWidth / 2, pdf.internal.pageSize.getHeight() - 10, { align: 'center' });
pdf.save('bogo-offer-summary.pdf');
}).catch(err => {
console.error("PDF generation failed:", err);
document.body.classList.remove('pdf-generating');
});
};
// --- EVENT LISTENERS ---
nextButton.addEventListener('click', () => {
if (state.currentStep < state.totalSteps) {
state.currentStep++;
updateUI();
}
});
prevButton.addEventListener('click', () => {
if (state.currentStep > 1) {
state.currentStep--;
updateUI();
}
});
downloadPdfButton.addEventListener('click', downloadPDF);
// --- INITIALIZATION ---
updateUI();
});