`;
}
resultsContainer.innerHTML = html;
}
function renderSourcesTable() {
sourcesTableBody.innerHTML = state.sources.map(source => `
| ${source.name} |
${source.type} |
${source.status}
|
|
`).join('');
}
// --- NAVIGATION & TAB LOGIC ---
function switchTab(tabName) {
render();
tabNavigation.querySelectorAll('.tab-button').forEach(btn => btn.classList.toggle('active', btn.dataset.tab === tabName));
tabContents.querySelectorAll('.tab-content').forEach(content => content.classList.toggle('active', content.id === `${tabName}-tab`));
updateNavButtons();
}
function navigateTabs(direction) {
currentTabIndex = Math.max(0, Math.min(tabs.length - 1, currentTabIndex + direction));
switchTab(tabs[currentTabIndex]);
}
function updateNavButtons() {
prevBtn.style.visibility = currentTabIndex === 0 ? 'hidden' : 'visible';
nextBtn.style.visibility = currentTabIndex === tabs.length - 1 ? 'hidden' : 'visible';
}
// --- PDF GENERATION ---
function generatePDF() {
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const { criteria, results } = state.lastSearch;
doc.setFontSize(20);
doc.setFont("helvetica", "bold");
doc.text("Legal Case Research Report", 105, 20, { align: 'center' });
doc.setFontSize(12);
doc.text("Search Criteria", 14, 32);
doc.autoTable({
startY: 35,
body: [
['Keywords', criteria.keywords || 'N/A'],
['Jurisdiction', criteria.jurisdiction],
['Case Type', criteria.caseType],
],
theme: 'grid',
});
const body = results.map(r => [
r.title,
r.citation,
r.type,
r.summary
]);
doc.autoTable({
startY: doc.autoTable.previous.finalY + 10,
head: [['Case / Document', 'Citation', 'Type', 'Summary']],
body: body,
theme: 'striped',
headStyles: { fillColor: [217, 119, 6] }, // Amber-600
columnStyles: { 3: { cellWidth: 80 } }
});
doc.save('Legal_Research_Report.pdf');
}
// --- START THE APP ---
init();
});