`).join('');
}
// --- UTILITY FUNCTIONS ---
function showNotification(message) {
notification.textContent = message;
notification.classList.remove('opacity-0');
setTimeout(() => notification.classList.add('opacity-0'), 2000);
}
function copyToClipboard(text, message) {
navigator.clipboard.writeText(text).then(() => showNotification(message));
}
// --- PDF GENERATION ---
async function generatePdfReport() {
if (generatedCopy.length === 0) {
showNotification("No copy to export.");
return;
}
downloadPdfBtn.disabled = true;
downloadPdfBtn.textContent = '...';
const copyCards = generatedCopy.map(item => `
`).join('');
const reportHtml = `
`;
const pdfTemplate = document.getElementById('pdf-template');
pdfTemplate.innerHTML = reportHtml;
pdfTemplate.classList.remove('invisible');
try {
const { jsPDF } = window.jspdf;
const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-page'), { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth(), pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save(`FAB_Copy_${inputsData.name.replace(/\s+/g, '_')}.pdf`);
} catch (e) { console.error('PDF Generation Error:', e); } finally {
downloadPdfBtn.disabled = false;
downloadPdfBtn.textContent = 'Download PDF';
pdfTemplate.classList.add('invisible');
pdfTemplate.innerHTML = '';
}
}
// --- EVENT LISTENERS ---
generateBtn.addEventListener('click', generateCopy);
copyAllBtn.addEventListener('click', () => {
if (generatedCopy.length > 0) {
const allText = generatedCopy.map(d => `Feature: ${d.feature}\nAdvantage: ${d.advantage}\nBenefit: ${d.benefit}`).join('\n\n');
copyToClipboard(allText, 'All copy copied!');
}
});
downloadPdfBtn.addEventListener('click', generatePdfReport);
});
${item.feature}
Advantage: ${item.advantage}
Benefit: ${item.benefit}
FAB Marketing Copy Brief
Product: ${inputsData.name}
Target Audience
${inputsData.audience}
Generated FAB Statements
${copyCards}
