Legal Representation Cost Estimator
Get a general estimate of potential legal costs based on common billing structures in the USA.
Estimated Legal Cost Breakdown
Disclaimer: This is a simplified estimate for informational purposes only and does not constitute a quote or legal advice. Actual costs can vary significantly.
Please fill out all required fields on the previous tab.
${formatter.format(result.total)}
`; detailsDiv.innerHTML = result.details.map(item => `
${item.label}:
${item.value}
`).join('');
};
const nextPrev = (direction) => {
const newTab = currentTab + direction;
if (direction === 1) { // Moving to next tab
if (currentTab === 0) { // Moving from inputs to results
const result = calculateCost();
if (result) {
displayResults(result);
currentTab = newTab;
showTab(currentTab);
} else {
validationError.classList.remove('hidden');
}
return;
}
}
if (newTab >= 0 && newTab < tabs.length) {
currentTab = newTab;
showTab(currentTab);
}
};
const downloadPDF = () => {
const { jsPDF } = window.jspdf;
const content = document.getElementById('pdf-content');
if (!content) { return; }
html2canvas(content, { scale: 2, backgroundColor: '#ffffff', useCORS: true })
.then(canvas => {
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const imgWidth = canvas.width;
const imgHeight = canvas.height;
const ratio = imgWidth / imgHeight;
const finalImgWidth = pdfWidth - 20; // with margin
const finalImgHeight = finalImgWidth / ratio;
pdf.addImage(imgData, 'PNG', 10, 10, finalImgWidth, finalImgHeight);
pdf.save('Legal-Cost-Estimate.pdf');
}).catch(err => console.error("Error generating PDF:", err));
};
// --- Event Listeners ---
billingMethodSelect.addEventListener('change', handleBillingChange);
prevBtn.addEventListener('click', () => nextPrev(-1));
nextBtn.addEventListener('click', () => nextPrev(1));
downloadPdfBtn.addEventListener('click', downloadPDF);
tabNavs.forEach((nav, index) => {
nav.addEventListener('click', () => {
if (index > currentTab) {
nextPrev(index - currentTab);
} else if (index < currentTab) {
nextPrev(index - currentTab);
}
});
});
// --- Initial Setup ---
handleBillingChange();
showTab(currentTab);
});
