Please paste a valid email thread into the input box on the first tab.
`;
pdfDownloadContainer.classList.add('hidden');
return;
}
// This is a simulation of a "smart" analysis.
// In a real application, this would be replaced by an API call to an LLM.
const summaryData = {
title: "Project Phoenix Launch Plan",
summary: "This email thread discusses the finalization of the launch plan for 'Project Phoenix'. The key topics include confirming the marketing timeline, finalizing server specifications, and addressing a newly identified risk with payment gateway integration. The team agrees on a target press release date and sets action items to mitigate risks and complete necessary documentation.",
participants: [
{ name: "Alice", email: "alice@example.com" },
{ name: "Bob", email: "bob@example.com" },
{ name: "Charlie", email: "charlie@example.com" },
],
decisions: [
"The press release is tentatively scheduled for September 5th, 2025.",
"Server specifications have been finalized and procurement is in progress."
],
actionItems: [
{ task: "Provide final feature list to Bob.", owner: "Charlie", due: "Aug 19, 2025" },
{ task: "Initiate press release approval process with legal.", owner: "Bob", due: "Aug 20, 2025" },
{ task: "Schedule a meeting to discuss payment gateway risk.", owner: "Charlie", due: "Aug 19, 2025" },
{ task: "Perform final review of marketing copy.", owner: "Alice", due: "TBD" }
]
};
displayResults(summaryData);
};
/**
* Renders the organized summary in the results tab.
* @param {object} data - The structured summary data.
*/
const displayResults = (data) => {
const participantsHtml = data.participants.map(p => `
${p.name} (${p.email})`).join('');
const decisionsHtml = data.decisions.map(d => `
${d}`).join('');
const actionItemsHtml = data.actionItems.map(a => `
${a.task} (Owner: ${a.owner}, Due: ${a.due})`).join('');
resultsOutput.innerHTML = `
${data.title}
Overall Summary
${data.summary}
Key Participants
Key Decisions Made
Action Items
`;
pdfDownloadContainer.classList.remove('hidden');
};
/**
* Generates and triggers the download of a PDF report.
*/
const generatePdf = () => {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const content = document.getElementById('summary-content');
if (!content) return;
const title = content.querySelector('h2').textContent;
const sections = content.querySelectorAll('h3');
doc.setFontSize(18);
doc.text(title, 105, 20, { align: 'center' });
let yPos = 35;
sections.forEach(section => {
if (yPos > 260) { // Add new page if content overflows
doc.addPage();
yPos = 20;
}
doc.setFontSize(14);
doc.setFont(undefined, 'bold');
doc.text(section.textContent, 14, yPos);
yPos += 8;
doc.setFontSize(11);
doc.setFont(undefined, 'normal');
const nextElement = section.nextElementSibling;
if (nextElement.tagName === 'P') {
const text = doc.splitTextToSize(nextElement.textContent, 180);
doc.text(text, 14, yPos);
yPos += (text.length * 5) + 5;
} else if (nextElement.tagName === 'UL') {
const listItems = Array.from(nextElement.querySelectorAll('li'));
// Special handling for Action Items to use autoTable
if (section.textContent === 'Action Items') {
const tableBody = listItems.map(li => {
const text = li.textContent;
const match = text.match(/(.*) \(Owner: (.*), Due: (.*)\)/);
if (match) {
return [match[1], match[2], match[3]];
}
return [text, '', ''];
});
doc.autoTable({
startY: yPos - 4,
head: [['Task', 'Owner', 'Due Date']],
body: tableBody,
theme: 'grid',
headStyles: { fillColor: [243, 244, 246], textColor: [55, 65, 81], fontStyle: 'bold' },
styles: { cellPadding: 2.5, fontSize: 9 },
});
yPos = doc.lastAutoTable.finalY + 10;
} else {
listItems.forEach(li => {
doc.text(`• ${li.textContent}`, 18, yPos);
yPos += 7;
});
yPos += 3;
}
}
});
doc.save(`${title.replace(/\s+/g, '_')}_Summary.pdf`);
};
// --- Event Listeners ---
downloadPdfBtn.addEventListener('click', generatePdf);
// --- Initial Setup ---
updateNavButtons();
});