Win Probability
${reportData.winProbability.toFixed(0)}%
Net Outcome if Won
${formatCurrency(reportData.netWin)}
Net Outcome if Lost
${formatCurrency(reportData.netLoss)}
Probability Distribution
`;
reportContainer.innerHTML = reportHtml;
downloadBtnContainer.classList.remove('hidden');
// Render Chart
const ctx = document.getElementById('outcomeChart').getContext('2d');
if (myChart) {
myChart.destroy();
}
myChart = new Chart(ctx, {
type: 'doughnut',
data: {
labels: ['Win', 'Lose'],
datasets: [{
data: [reportData.winProbability, 100 - reportData.winProbability],
backgroundColor: ['#2563eb', '#ef4444'],
borderColor: ['#ffffff'],
borderWidth: 2
}]
},
options: {
responsive: true,
plugins: {
legend: {
position: 'top',
},
tooltip: {
callbacks: {
label: function(context) {
return `${context.label}: ${context.raw.toFixed(1)}%`;
}
}
}
}
}
});
};
// --- UI & NAVIGATION ---
const updateNavButtons = () => {
prevBtn.disabled = currentTab === '1';
nextBtn.disabled = currentTab === '4';
prevBtn.classList.toggle('opacity-50', prevBtn.disabled);
nextBtn.classList.toggle('opacity-50', nextBtn.disabled);
};
window.switchTab = (tabId) => {
currentTab = tabId;
if (currentTab === '4') {
renderReport();
}
tabs.forEach(id => {
document.getElementById(`tab-content-${id}`).classList.toggle('hidden', id !== currentTab);
document.getElementById(`tab-btn-${id}`).classList.toggle('tab-active', id === currentTab);
document.getElementById(`tab-btn-${id}`).classList.toggle('tab-inactive', id !== currentTab);
});
updateNavButtons();
};
const navigateTabs = (direction) => {
const currentIndex = tabs.indexOf(currentTab);
let nextIndex = currentIndex + direction;
if (nextIndex >= 0 && nextIndex < tabs.length) {
switchTab(tabs[nextIndex]);
}
};
// --- PDF GENERATION ---
downloadPdfBtn.addEventListener('click', () => {
if (!reportData) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const formatCurrency = (value) => `$${value.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
doc.setFontSize(18);
doc.text("Business Litigation Analysis Report", 14, 22);
doc.setFontSize(11);
doc.setTextColor(100);
doc.text(`Case: ${reportData.inputs.caseName}`, 14, 30);
doc.text(`Report Date: ${new Date().toLocaleDateString()}`, 14, 36);
// Summary Table
doc.autoTable({
head: [['Key Metric', 'Value']],
body: [
['Calculated Expected Value', formatCurrency(reportData.expectedValue)],
['Probability of Winning', `${reportData.winProbability.toFixed(1)}%`],
['Net Outcome if Won', formatCurrency(reportData.netWin)],
['Net Outcome if Lost', formatCurrency(reportData.netLoss)],
],
startY: 45,
theme: 'grid',
headStyles: { fillColor: [45, 102, 193] },
});
// Inputs Table
doc.autoTable({
head: [['Financial Inputs', 'Value']],
body: [
['Case Type', reportData.inputs.caseType],
['Best-Case Judgment', formatCurrency(reportData.inputs.potentialGain)],
['Worst-Case Judgment', formatCurrency(reportData.inputs.potentialLoss)],
['Estimated Legal Costs', formatCurrency(reportData.inputs.legalCosts)],
],
startY: doc.previousAutoTable.finalY + 10,
theme: 'grid',
headStyles: { fillColor: [45, 102, 193] },
});
doc.save(`Litigation_Report_${reportData.inputs.caseName.replace(/\s/g, '_')}.pdf`);
});
// --- INITIALIZATION ---
updateNavButtons();
lucide.createIcons();
prevBtn.addEventListener('click', () => navigateTabs(-1));
nextBtn.addEventListener('click', () => navigateTabs(1));
});