My name is [Your Name], and I am reaching out from ${data.productName}.
Our firm specializes in helping a ${data.recipientRole} to ${data.productBenefit}, specifically addressing challenges such as ${data.painPoint}.
I would be keen to schedule ${data.callToAction} to determine if our solution could be of value to your organization.
Sincerely,
[Your Name]
[Your Title]
`;
break;
case 'Value-Driven & Concise':
default:
subject = `Idea for your customer acquisition`;
body = `
Hi [Recipient Name],
I'm reaching out because I noticed many ${data.recipientRole.split(' at ')[0]}s struggle with ${data.painPoint}.
${data.productName} helps you ${data.productBenefit}, leading to more efficient growth.
Would you be open to ${data.callToAction} next week to see how it works?
Thanks,
[Your Name]
`;
break;
}
generatedEmail = { subject, body };
};
const displayEmail = () => {
const { subject, body } = generatedEmail;
const emailHtml = `
${body}
`;
elements.outputContainer.innerHTML = emailHtml;
};
const handleDownloadPdf = () => {
const { jsPDF } = window.jspdf;
if (!jsPDF) { console.error("jsPDF is not loaded."); return; }
const doc = new jsPDF({ orientation: 'portrait', unit: 'in', format: 'letter' });
const data = getFormData();
const margin = 0.75;
const pageWidth = doc.internal.pageSize.getWidth();
const usableWidth = pageWidth - (margin * 2);
// PDF Header
doc.setFont('helvetica', 'bold');
doc.setFontSize(16);
doc.setTextColor('#0f766e'); // teal-700
doc.text('Cold Email Draft', margin, 0.8);
doc.setDrawColor('#99f6e4'); // teal-200
doc.setLineWidth(0.01);
doc.line(margin, 1.0, pageWidth - margin, 1.0);
// Email Meta
let currentY = 1.4;
doc.setFont('helvetica', 'bold');
doc.setFontSize(10);
doc.setTextColor('#134e4a'); // teal-900
doc.text('Subject: ', margin, currentY);
doc.setFont('helvetica', 'normal');
doc.setTextColor('#111827'); // gray-900
doc.text(generatedEmail.subject, margin + 0.6, currentY);
currentY += 0.3;
// Email Body
doc.setDrawColor('#e5e7eb'); // gray-200
doc.roundedRect(margin - 0.1, currentY - 0.1, usableWidth + 0.2, 0.02, 0.01, 0.01, 'F');
currentY += 0.2;
const tempDiv = document.createElement('div');
tempDiv.innerHTML = generatedEmail.body;
doc.setFont('georgia', 'normal');
doc.setFontSize(11);
doc.setTextColor('#374151'); // gray-700
doc.setLineHeightFactor(1.6);
Array.from(tempDiv.children).forEach(p => {
const text = p.innerText || p.textContent || '';
const lines = doc.splitTextToSize(text, usableWidth);
if (currentY + (lines.length * 0.25) > 10.5) {
doc.addPage();
currentY = margin;
}
doc.text(lines, margin, currentY);
currentY += (lines.length * 0.25) + 0.1;
});
// Footer
const pageCount = doc.internal.getNumberOfPages();
for(let i = 1; i <= pageCount; i++) {
doc.setPage(i);
doc.setFont('helvetica', 'italic');
doc.setFontSize(9);
doc.setTextColor('#9ca3af'); // gray-400
doc.text(`Generated by Cold Email Copy Generator`, pageWidth / 2, 10.5, { align: 'center' });
}
doc.save('Cold-Email-Draft.pdf');
};
// --- Event Listeners ---
elements.tabDefine.addEventListener('click', () => switchTab('define'));
elements.tabReview.addEventListener('click', () => switchTab('review'));
elements.nextBtn.addEventListener('click', () => currentTab === 'define' && switchTab('review'));
elements.prevBtn.addEventListener('click', () => currentTab === 'review' && switchTab('define'));
elements.downloadPdfBtn.addEventListener('click', handleDownloadPdf);
});