`;
});
});
const actionPlanHtml = (title, content) => {
if(!content) return '';
return `
${checklistHtml}
${actionPlanHtml('Key Content Updates', data.updates)}
${actionPlanHtml('New Sections to Add', data.additions)}
${actionPlanHtml('SEO Enhancements', data.seo)}
`;
}
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 generateAnalysisPdf() {
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const data = getFormData();
const pageW = pdf.internal.pageSize.getWidth();
const pageH = pdf.internal.pageSize.getHeight();
const margin = 20;
const contentWidth = pageW - (margin * 2);
let y = 0;
const lineH = 6;
const analysisDate = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
const addHeaderFooter = () => {
const pageCount = pdf.internal.getNumberOfPages();
for (let i = 1; i <= pageCount; i++) {
pdf.setPage(i);
if (i > 1) {
pdf.setFontSize(9);
pdf.setTextColor('#6b7280');
pdf.text('Content Refresh Analysis', margin, 12);
pdf.setDrawColor('#d1d5db');
pdf.setLineWidth(0.2);
pdf.line(margin, 15, pageW - margin, 15);
}
pdf.setFontSize(8);
pdf.setTextColor('#6b7280');
pdf.text(`Page ${i} of ${pageCount}`, pageW / 2, pageH - 10, { align: 'center' });
}
};
const checkBreak = (needed = 20) => {
if (y + needed > pageH - margin) {
pdf.addPage();
y = margin + 10;
}
};
const addText = (text, options = {}) => {
const { size=10, style='normal', color='#374151', indent=0, spacing=1 } = options;
if (!text && text !== '') return;
checkBreak(10);
pdf.setFontSize(size);
pdf.setFont(undefined, style);
pdf.setTextColor(color);
const splitText = pdf.splitTextToSize(text, contentWidth - indent);
pdf.text(splitText, margin + indent, y);
y += (splitText.length * lineH * 0.8) + (lineH * spacing);
};
const addSectionHeader = (title) => {
y += lineH * 2;
checkBreak(20);
pdf.setFillColor('#f0f9ff'); // sky-50
pdf.rect(margin, y - lineH, contentWidth, lineH * 2, 'F');
pdf.setFontSize(14);
pdf.setFont(undefined, 'bold');
pdf.setTextColor('#0369a1'); // sky-700
pdf.text(title, margin + 3, y + (lineH * 0.5));
y += lineH * 2.5;
};
// --- Build PDF Document ---
// Title Page
pdf.setFillColor('#0c4a6e'); // sky-900
pdf.rect(0, 0, pageW, 50, 'F');
pdf.setFontSize(26);
pdf.setFont(undefined, 'bold');
pdf.setTextColor('#FFFFFF');
pdf.text('Content Refresh Analysis', pageW / 2, 30, { align: 'center' });
y = 70;
addText(data.title, { size: 16, style: 'bold', color: '#1f2937' });
y += 10;
addText(`Analysis Date: ${analysisDate}`);
addText(`Original Publication: ${data.date || 'Not specified'}`);
// New Page for Content
pdf.addPage();
y = margin + 10;
// Analysis Checklist
addSectionHeader("Analysis Checklist");
data.checklist.forEach(section => {
addText(section.category, {style: 'bold', size: 11, color: '#075985'});
y += lineH * 0.5;
section.items.forEach(item => {
checkBreak(15);
const statusSymbol = item.answer === 'Yes' ? '✔' : (item.answer === 'No' ? '✘' : '–');
const statusColor = item.answer === 'Yes' ? '#16a34a' : (item.answer === 'No' ? '#dc2626' : '#6b7280');
addText(statusSymbol, {color: statusColor, style: 'bold'});
pdf.text(item.text, margin + 8, y - lineH); // draw text next to symbol
addText(` Answer: ${item.answer}`, {indent: 8, color: statusColor, style: 'bold'});
y+= lineH * 0.5;
});
});
// Action Plan
const addActionSection = (title, content) => {
if(content) {
addSectionHeader(title);
addText(content);
}
};
addActionSection('Key Content Updates', data.updates);
addActionSection('New Sections to Add', data.additions);
addActionSection('SEO Enhancements', data.seo);
addHeaderFooter();
pdf.save(`Content_Analysis_${data.title.replace(/\s+/g, '_').substring(0,20)}.pdf`);
}
// --- Event Listeners & Init ---
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 preview = document.getElementById('report-preview-container');
if (preview) {
navigator.clipboard.writeText(preview.innerText).then(() => {
showMessage();
}).catch(err => console.error('Copy failed: ', err));
}
});
pdfDownloadButton.addEventListener('click', generateAnalysisPdf);
renderChecklist();
updateTabUI();
});
${title}
${content}
`; }; preview.innerHTML = `${data.title}
Original Publication Date: ${data.date}
Summary: ${data.summary}
