${team.replace(/\n/g, '
')}
Revenue Model & Key Metrics
${revenueModel.replace(/\n/g, '
')}
`;
initialMessage.classList.add('hidden');
resultsContainer.classList.remove('hidden');
pdfButtonContainer.classList.remove('hidden');
};
// --- PDF Download Functionality ---
downloadPdfBtn.addEventListener('click', () => {
if (!lastThesisData) {
console.warn("Please generate the thesis first before downloading the PDF.");
return;
}
const { jsPDF } = window.jspdf;
const { companyName, sector, marketProblem, solution, moat, team, revenueModel } = lastThesisData;
const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const pageW = doc.internal.pageSize.getWidth();
const margin = 50;
const contentW = pageW - margin * 2;
let y = 0;
// Helper to add footer
const addFooter = () => {
const pageCount = doc.internal.getNumberOfPages();
for (let i = 1; i <= pageCount; i++) {
doc.setPage(i);
doc.setFontSize(9);
doc.setTextColor(150);
doc.text(`Page ${i} of ${pageCount}`, pageW / 2, doc.internal.pageSize.getHeight() - 20, { align: 'center' });
}
};
// Helper for sections
const addSection = (title, text, isSub=false) => {
if (y > doc.internal.pageSize.getHeight() - 120) { // Check for page break
doc.addPage();
y = margin;
}
doc.setFont('helvetica', 'bold');
doc.setFontSize(isSub ? 12 : 14);
doc.setTextColor(isSub ? '#4b5563' : '#111827');
doc.text(title, margin, y);
y += isSub ? 18 : 22;
doc.setFont('helvetica', 'normal');
doc.setFontSize(11);
doc.setTextColor('#374151');
const lines = doc.splitTextToSize(text, contentW);
doc.text(lines, margin, y);
y += lines.length * 14 + 20;
};
// --- PDF Content ---
// Header
y = margin;
doc.setFillColor('#4f46e5'); // indigo-600
doc.rect(0, 0, pageW, 80, 'F');
doc.setFont('helvetica', 'bold');
doc.setFontSize(24);
doc.setTextColor('#ffffff');
doc.text(`Investment Thesis`, margin, 45);
doc.setFontSize(16);
doc.text(companyName, margin, 65);
y = 110;
// Executive Summary
const summary = `This document outlines the investment case for ${companyName}, a company in the ${sector} sector, addressing a critical market need with a differentiated solution and a strong execution strategy.`;
addSection('Executive Summary', summary);
// Sections
doc.setDrawColor('#e5e7eb');
doc.line(margin, y - 10, pageW - margin, y - 10);
addSection('I. The Opportunity', marketProblem, true);
addSection('II. The Solution', solution, true);
addSection('III. Competitive Moat', moat, true);
addSection('IV. The Team', team, true);
addSection('V. Revenue Model & Financials', revenueModel, true);
// Core Thesis Statement
if (y > doc.internal.pageSize.getHeight() - 120) {
doc.addPage();
y = margin;
}
doc.setFillColor('#f3f4f6'); // gray-100
doc.setDrawColor('#e5e7eb');
const thesisStatement = `We believe ${companyName} is a compelling investment due to its unique solution to a large and urgent market problem, protected by a defensible moat and executed by a world-class team.`;
const thesisLines = doc.splitTextToSize(thesisStatement, contentW - 20);
const boxHeight = thesisLines.length * 14 + 40;
doc.roundedRect(margin, y, contentW, boxHeight, 5, 5, 'FD');
y += 25;
doc.setFont('helvetica', 'bolditalic');
doc.setFontSize(11);
doc.setTextColor('#1f2937');
doc.text("Core Thesis:", margin + 10, y);
y += 5;
doc.setFont('helvetica', 'normal');
doc.text(thesisLines, margin + 10, y + 10);
addFooter();
doc.save(`Investment_Thesis_${companyName.replace(/ /g, '_')}.pdf`);
});
// --- Initialize View ---
showTab(0);
});