`;
});
}
// --- TAB NAVIGATION ---
function updateActiveTab() {
tabPanels.forEach((panel, index) => panel.classList.toggle('hidden', index !== currentTabIndex));
tabs.forEach((tab, index) => {
tab.classList.toggle('tab-btn-active', index === currentTabIndex);
tab.classList.toggle('tab-btn-inactive', index !== currentTabIndex);
tab.classList.toggle('border-sky-700', index === currentTabIndex);
tab.classList.toggle('border-transparent', index !== currentTabIndex);
});
updateNavButtons();
}
function updateNavButtons() {
prevBtn.disabled = currentTabIndex === 0;
nextBtn.disabled = currentTabIndex === tabs.length - 1;
prevBtn.classList.toggle('opacity-50', prevBtn.disabled);
nextBtn.classList.toggle('opacity-50', nextBtn.disabled);
}
function navigateNext() { if (currentTabIndex < tabs.length - 1) { currentTabIndex++; updateActiveTab(); } }
function navigatePrev() { if (currentTabIndex > 0) { currentTabIndex--; updateActiveTab(); } }
// --- PDF DOWNLOAD ---
function downloadPDF() {
if (!testResults.data) {
alert('Please run a check before downloading a report.');
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const primaryColor = '#0369a1';
const today = new Date().toLocaleDateString();
// Header
doc.setFillColor('#f0f9ff'); // sky-50
doc.rect(0, 0, 210, 30, 'F');
doc.setFontSize(22);
doc.setTextColor(primaryColor);
doc.setFont('helvetica', 'bold');
doc.text('Sitemap Submission Check Report', 105, 18, { align: 'center' });
// Summary Info
doc.setFontSize(11);
doc.setTextColor('#1e293b');
doc.text(`Sitemap URL: ${testResults.url}`, 14, 45);
doc.text(`Check Date: ${today}`, 14, 52);
const statusText = document.getElementById('summary-status').textContent;
doc.setFontSize(14);
doc.text(`Overall Status: ${statusText}`, 14, 62);
// Checklist Table
const head = [['Check', 'Status', 'Details']];
const body = checks.map(check => {
const error = testResults.data.errors.find(e => e.id === check.id);
const warning = testResults.data.warnings.find(w => w.id === check.id);
let status, message;
if (error) { status = 'Error'; message = error.message; }
else if (warning) { status = 'Warning'; message = warning.message; }
else { status = 'Pass'; message = 'No issues found.'; }
return [check.name, status, message];
});
doc.autoTable({
startY: 70,
head: head,
body: body,
theme: 'grid',
headStyles: { fillColor: primaryColor },
didParseCell: function (data) {
if (data.section === 'body' && data.column.index === 1) {
if (data.cell.raw === 'Error') data.cell.styles.textColor = '#dc2626';
if (data.cell.raw === 'Warning') data.cell.styles.textColor = '#d97706';
if (data.cell.raw === 'Pass') data.cell.styles.textColor = '#16a34a';
}
}
});
doc.save(`Sitemap_Report_${today.replace(/\//g, '-')}.pdf`);
}
// --- RUN INITIALIZATION ---
initialize();
});