The journey of a thousand miles begins with a single step. For ${audience} ready to tackle ${topic.toLowerCase()}, the immediate next step is to refine your pitch deck. Focus on telling a compelling story backed by data. Start networking with angel investors and early-stage VCs. The time to build is now.
`
};
const generatePost = () => {
const topic = topicInput.value.trim();
const audience = audienceInput.value.trim();
const selectedSections = Array.from(document.querySelectorAll('#sections-container input:checked')).map(cb => cb.value);
if (!topic) {
postContainer.innerHTML = '
Please enter a topic for the article.
';
return;
}
let postHTML = `
Playbook: A Guide to ${topic}
`;
selectedSections.forEach(key => {
if (sectionTemplates[key]) {
postHTML += sectionTemplates[key](topic, audience);
}
});
postContainer.innerHTML = postHTML;
outputTitle.textContent = `Generated Article: ${topic}`;
downloadPdfBtn.classList.remove('hidden');
};
const downloadPdf = () => {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const content = getEl('generated-post-container');
const title = `Playbook: A Guide to ${topicInput.value.trim()}`;
const audience = `For: ${audienceInput.value.trim()}`;
const genDate = `Generated on: ${new Date().toLocaleDateString()}`;
const pageWidth = doc.internal.pageSize.getWidth();
const margin = 20;
// --- PDF Template: Business Strategy Brief ---
doc.setFillColor(6, 95, 70); // Emerald-800
doc.rect(0, 0, pageWidth, 25, 'F');
doc.setFont('helvetica', 'bold');
doc.setFontSize(16);
doc.setTextColor(255, 255, 255);
doc.text("BUSINESS STRATEGY BRIEF", margin, 16);
doc.setFont('helvetica', 'bold');
doc.setFontSize(14);
doc.setTextColor(15, 23, 42); // Slate-900
const splitTitle = doc.splitTextToSize(title, pageWidth - (margin * 2));
let startY = 38;
doc.text(splitTitle, margin, startY);
startY += (splitTitle.length * 7);
doc.setFont('helvetica', 'normal');
doc.setFontSize(9);
doc.setTextColor(71, 85, 105); // Slate-500
doc.text(audience, margin, startY + 2);
doc.text(genDate, pageWidth - margin, startY + 2, { align: 'right' });
startY += 8;
html2canvas(content, { scale: 2, useCORS: true, windowWidth: content.scrollWidth, windowHeight: content.scrollHeight }).then(canvas => {
const imgData = canvas.toDataURL('image/png');
const imgProps = doc.getImageProperties(imgData);
const pdfWidth = pageWidth - (margin * 2);
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
let heightLeft = pdfHeight;
let position = startY;
doc.addImage(imgData, 'PNG', margin, position, pdfWidth, pdfHeight, undefined, 'FAST');
heightLeft -= (doc.internal.pageSize.getHeight() - position - 15);
while (heightLeft >= 0) {
position = heightLeft - pdfHeight;
doc.addPage();
doc.addImage(imgData, 'PNG', margin, 15, pdfWidth, pdfHeight, undefined, 'FAST');
heightLeft -= (doc.internal.pageSize.getHeight() - 15);
}
// Footer on all pages
const pageCount = doc.internal.getNumberOfPages();
for(let i = 1; i <= pageCount; i++) {
doc.setPage(i);
doc.setLineWidth(0.5);
doc.setDrawColor(203, 213, 225); // Slate-300
doc.line(margin, 282, pageWidth - margin, 282);
doc.setFontSize(8);
doc.setTextColor(100, 116, 139); // Slate-500
doc.text(
`Entrepreneurship Series | ${topicInput.value.trim()}`,
margin,
287
);
doc.text(
`Page ${i} of ${pageCount}`,
pageWidth - margin,
287,
{ align: 'right' }
);
}
doc.save(`Entrepreneurship_Article_${topicInput.value.trim().replace(/\s/g, '_')}.pdf`);
}).catch(err => {
console.error("Error generating PDF:", err);
alert("Could not generate PDF. See console for details.");
});
};
const showTab = (tabNum) => {
currentTab = tabNum;
tabButtons.forEach(btn => btn.classList.toggle('active', parseInt(btn.dataset.tab) === tabNum));
tabPanes.forEach(pane => pane.classList.toggle('hidden', parseInt(pane.id.split('-')[2]) !== tabNum));
prevBtn.classList.toggle('invisible', currentTab === 1);
nextBtn.textContent = currentTab === 1 ? 'Generate Article' : 'Generate Again';
};
// --- Event Listeners ---
tabButtons.forEach(button => {
button.addEventListener('click', () => {
const tabNum = parseInt(button.dataset.tab);
if (tabNum === 2 && currentTab === 1) generatePost();
showTab(tabNum);
});
});
prevBtn.addEventListener('click', () => { if (currentTab > 1) showTab(currentTab - 1) });
nextBtn.addEventListener('click', () => {
if (currentTab === 1) {
generatePost();
showTab(2);
} else {
generatePost();
}
});
downloadPdfBtn.addEventListener('click', downloadPdf);
// --- Initial Setup ---
showTab(1);
});