Hi ${data.journalistName.split(' ')[0]},
${data.personalization ? `
${data.personalization}
` : ''}
My name is ${data.yourName}, and I'm the ${data.yourTitle} at ${data.yourCompany}. I'm reaching out because we have some exciting news I think you and your readers at ${data.mediaOutlet} would be interested in.
${data.summary}
I believe this is a significant development because...
${data.callToAction}
Best regards,
${data.yourName}
${data.yourTitle}
${data.yourCompany}
`;
previewContainer.innerHTML = pitchHTML;
}
function showMessage() {
messageBox.classList.remove('opacity-0', 'translate-y-10');
messageBox.classList.add('opacity-100', 'translate-y-0');
setTimeout(() => {
messageBox.classList.remove('opacity-100', 'translate-y-0');
messageBox.classList.add('opacity-0', 'translate-y-10');
}, 2000);
}
function generatePitchPdf() {
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const data = getFormData();
const pageW = pdf.internal.pageSize.getWidth();
const margin = 20;
const contentWidth = pageW - (margin * 2);
let y = margin;
const lineSpacing = 7;
const addWrappedText = (text, options = {}) => {
const { size = 11, style = 'normal', color = '#333333', x = margin, spacing = 1 } = options;
if (y + (lineSpacing * spacing) > pdf.internal.pageSize.getHeight() - margin) {
pdf.addPage();
y = margin;
}
pdf.setFontSize(size);
pdf.setFont(undefined, style);
pdf.setTextColor(color);
const splitText = pdf.splitTextToSize(text, contentWidth);
pdf.text(splitText, x, y);
y += (splitText.length * lineSpacing * 0.7); // Adjust spacing based on font size and line height
y += (lineSpacing * spacing);
};
// PDF Header
pdf.setFontSize(22);
pdf.setFont(undefined, 'bold');
pdf.setTextColor('#1e293b'); // slate-800
pdf.text(data.yourCompany, margin, y);
y += 12;
pdf.setDrawColor('#e2e8f0'); // slate-200
pdf.setLineWidth(0.5);
pdf.line(margin, y, pageW - margin, y);
y += 15;
// Pitch Content
addWrappedText(`Subject: ${data.headline}`, { style: 'bold' });
addWrappedText(`Hi ${data.journalistName.split(' ')[0]},`);
if(data.personalization) {
addWrappedText(data.personalization);
}
const intro = `My name is ${data.yourName}, and I'm the ${data.yourTitle} at ${data.yourCompany}. I'm reaching out because we have some exciting news I think you and your readers at ${data.mediaOutlet} would be interested in.`;
addWrappedText(intro);
addWrappedText(data.summary);
addWrappedText(`I believe this is a significant development because... [Elaborate here with 1-2 key value props or data points]`);
addWrappedText(data.callToAction);
addWrappedText('Best regards,');
y += lineSpacing; // Extra space before signature
addWrappedText(`${data.yourName}`, { style: 'bold', spacing: 0 });
addWrappedText(`${data.yourTitle}`, { spacing: 0 });
addWrappedText(`${data.yourCompany}`, { spacing: 0 });
const fileName = `media_pitch_${data.mediaOutlet.replace(/\s+/g, '_').toLowerCase()}.pdf`;
pdf.save(fileName);
}
// --- Event Listeners ---
tabs.forEach(tab => tab.addEventListener('click', () => goToTab(parseInt(tab.dataset.tab))));
prevButton.addEventListener('click', () => goToTab(currentTab - 1));
nextButton.addEventListener('click', () => goToTab(currentTab + 1));
copyButton.addEventListener('click', () => {
const previewContainer = document.getElementById('pitch-preview-container');
if (previewContainer) {
const textToCopy = previewContainer.innerText;
const textArea = document.createElement("textarea");
textArea.value = textToCopy;
textArea.style.position = "fixed";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
showMessage();
} catch (err) {
console.error('Copy failed:', err);
}
document.body.removeChild(textArea);
}
});
pdfDownloadButton.addEventListener('click', generatePitchPdf);
// Initialize the UI
updateTabUI();
});