Economic Damages
- Medical Costs (Past & Future): ${formatCurrency(results.totalMedical)}
- Lost Wages (Temporary Disability): ${formatCurrency(results.lostWages)}
Non-Economic Damages
- Permanent Disability Benefit: ${formatCurrency(results.permanentDisability)}
Based on Your Inputs:
- Body Part: ${inputs.bodyPart}
- Injury Type: ${inputs.injuryType}
- Impairment: ${inputs.impairmentRating}%
- Avg. Weekly Wage: ${formatCurrency(inputs.avgWeeklyWage)}
`;
pdfBtnContainer.classList.remove('hidden');
}
// --- CALCULATION LOGIC ---
function calculateEstimate(inputs) {
const { bodyPart, impairmentRating, avgWeeklyWage, medicalCosts, weeksLost, futureMedicalCosts } = inputs;
// Most states use 2/3 of the average weekly wage for temporary disability benefits
const weeklyBenefitRate = avgWeeklyWage * (2 / 3);
const lostWages = weeklyBenefitRate * weeksLost;
// Permanent disability calculation (simplified model based on schedules)
const selectedBodyPart = state.bodyParts.find(p => p.name === bodyPart);
const maxWeeks = selectedBodyPart ? selectedBodyPart.maxWeeks : 260; // Default if not found
const benefitWeeks = maxWeeks * (impairmentRating / 100);
const permanentDisability = weeklyBenefitRate * benefitWeeks;
const totalMedical = medicalCosts + futureMedicalCosts;
const totalEstimate = totalMedical + lostWages + permanentDisability;
return {
totalMedical,
lostWages,
permanentDisability,
totalEstimate
};
}
// --- EVENT HANDLERS & LOGIC ---
function switchTab(tabName) {
state.currentTab = tabName;
Object.values(tabs).forEach(tab => tab.classList.remove('active'));
Object.values(contents).forEach(content => content.classList.add('hidden'));
tabs[tabName].classList.add('active');
contents[tabName].classList.remove('hidden');
updateNavButtons();
}
function updateNavButtons() {
navButtons.prev.disabled = state.currentTab === 'dashboard';
navButtons.next.disabled = state.currentTab === 'config';
}
estimationForm.addEventListener('submit', (e) => {
e.preventDefault();
const inputs = {
bodyPart: document.getElementById('body-part').value,
injuryType: document.getElementById('injury-type').value,
impairmentRating: parseFloat(document.getElementById('impairment-rating').value),
avgWeeklyWage: parseFloat(document.getElementById('avg-weekly-wage').value),
medicalCosts: parseFloat(document.getElementById('medical-costs').value),
weeksLost: parseInt(document.getElementById('weeks-lost').value),
futureMedicalCosts: parseFloat(document.getElementById('future-medical-costs').value),
};
const results = calculateEstimate(inputs);
state.estimationResult = { inputs, results };
renderDashboard();
switchTab('dashboard');
});
downloadPdfBtn.addEventListener('click', () => {
if (!state.estimationResult) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
const { inputs, results } = state.estimationResult;
doc.setFontSize(20);
doc.text("Workplace Injury Compensation Estimate", 14, 22);
doc.setFontSize(11);
doc.setTextColor(100);
doc.text(`Report Generated: ${new Date().toLocaleDateString()}`, 14, 30);
doc.setFontSize(14);
doc.setTextColor(40);
doc.text(`Total Estimated Compensation: ${formatCurrency(results.totalEstimate)}`, 14, 45);
doc.autoTable({
startY: 55,
head: [['Category', 'Details', 'Estimated Amount']],
body: [
['Economic Damages', 'Past & Future Medical Costs', formatCurrency(results.totalMedical)],
['', 'Lost Wages (Temporary Disability)', formatCurrency(results.lostWages)],
['Non-Economic Damages', 'Permanent Disability Benefit', formatCurrency(results.permanentDisability)],
],
theme: 'striped',
headStyles: { fillColor: [194, 65, 12] }, // orange-700
});
let finalY = doc.lastAutoTable.finalY + 15;
doc.setFontSize(12);
doc.text("Summary of Inputs", 14, finalY);
doc.autoTable({
startY: finalY + 5,
body: [
['Affected Body Part', inputs.bodyPart],
['Type of Injury', inputs.injuryType],
['Permanent Impairment Rating', `${inputs.impairmentRating}%`],
['Average Weekly Wage', formatCurrency(inputs.avgWeeklyWage)],
['Weeks of Lost Work', inputs.weeksLost],
['Total Medical Costs', formatCurrency(inputs.medicalCosts + inputs.futureMedicalCosts)],
],
theme: 'grid',
});
doc.save('Compensation_Estimate_Report.pdf');
});
// --- ATTACH EVENT LISTENERS ---
tabs.dashboard.addEventListener('click', () => switchTab('dashboard'));
tabs.config.addEventListener('click', () => switchTab('config'));
navButtons.next.addEventListener('click', () => switchTab('config'));
navButtons.prev.addEventListener('click', () => switchTab('dashboard'));
// --- INITIALIZATION ---
function init() {
populateSelectOptions();
updateNavButtons();
}
init();
});