${body.replace(/\n/g, '
')}
`;
currentTab = tabs.length - 1;
showTab(currentTab);
};
const downloadPDF = () => {
if (!generatedCampaign.headline) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ unit: 'pt', format: 'a4' });
const filename = `Guerilla-Marketing-Brief.pdf`;
const pageHeight = doc.internal.pageSize.height;
const pageWidth = doc.internal.pageSize.width;
const margin = 60;
const contentWidth = pageWidth - margin * 2;
let cursorY = 0;
doc.addFont('helvetica', 'normal', 'WinAnsiEncoding');
doc.addFont('helvetica', 'bold', 'WinAnsiEncoding');
// --- PDF Template: Mission Brief ---
doc.setDrawColor(0);
doc.setLineWidth(10);
doc.rect(5, 5, pageWidth - 10, pageHeight - 10);
cursorY = margin;
doc.setFont('helvetica', 'bold');
doc.setFontSize(24);
doc.setTextColor(0, 0, 0);
doc.text("TOP SECRET // MISSION BRIEF", pageWidth / 2, cursorY, { align: 'center' });
cursorY += 40;
doc.setDrawColor(0);
doc.setLineWidth(1);
doc.line(margin, cursorY, pageWidth - margin, cursorY);
cursorY += 10;
const addSection = (title, content) => {
if (!content) return;
const titleY = cursorY + 20;
const contentY = cursorY + 22;
doc.setFont('helvetica', 'bold');
doc.setFontSize(10);
doc.setTextColor(0,0,0);
doc.text(title.toUpperCase(), margin, titleY);
doc.setFont('helvetica', 'normal');
doc.setFontSize(12);
const contentLines = doc.splitTextToSize(content, contentWidth - 100);
if (cursorY + (contentLines.length * 14) + 20 > pageHeight - margin) {
doc.addPage();
cursorY = margin;
}
doc.text(contentLines, margin + 100, contentY);
cursorY += contentLines.length * 14 + 15;
};
addSection("Objective:", `Launch a guerilla marketing campaign for "${generatedCampaign.product}".`);
addSection("Target:", generatedCampaign.audience);
addSection("Location:", generatedCampaign.environment);
addSection("Core Message:", `The primary goal is to make the target audience feel/do the following: "${generatedCampaign.message}".`);
addSection("Angle:", `The chosen angle of attack is: "${generatedCampaign.angle}".`);
cursorY += 10;
doc.line(margin, cursorY, pageWidth - margin, cursorY);
cursorY += 20;
doc.setFont('helvetica', 'bold');
doc.setFontSize(14);
doc.text("SUGGESTED COPY INTEL:", margin, cursorY);
cursorY += 20;
doc.setFont('helvetica', 'normal');
doc.setFontSize(12);
const bodyContent = generatedCampaign.body.replace("Here are a few angles to get you started:\n\n", "");
const bodyLines = doc.splitTextToSize(bodyContent, contentWidth);
doc.text(bodyLines, margin, cursorY);
doc.save(filename);
};
// --- Event Handling ---
nextButton.addEventListener('click', () => {
if (currentTab < tabs.length - 2) {
currentTab++;
showTab(currentTab);
}
});
prevButton.addEventListener('click', () => {
if (currentTab > 0) {
currentTab--;
showTab(currentTab);
}
});
generateButton.addEventListener('click', generateCopy);
downloadPdfButton.addEventListener('click', downloadPDF);
tabs.forEach(tab => {
tab.addEventListener('click', () => {
const tabIndex = parseInt(tab.dataset.tab, 10);
if (tabIndex === tabs.length - 1 && !generatedCampaign.headline) {
generateCopy();
} else {
currentTab = tabIndex;
showTab(currentTab);
}
});
});
// --- Initialization ---
showTab(0);
});