RE: ${noticeSubject}
Dear ${recipientName},
This letter serves as a formal legal notice. Please be advised of the following:
${grievanceDetails}
Therefore, we demand that you take the following action(s):
${reliefSought}
${monetaryClaim > 0 ? `
This includes a monetary payment in the amount of ${formatCurrency(monetaryClaim)}.
` : ''}
You are hereby required to comply with these demands within ${complianceDeadline} days from the date of receipt of this notice. Failure to comply will compel our client to pursue all available legal remedies against you, at your sole cost and expense.
This notice is sent without prejudice to any of our rights and contentions in law and equity.
`;
outputContainer.innerHTML = html;
};
// --- PDF Download ---
const downloadPDF = async () => {
if (typeof window.jspdf === 'undefined' || typeof window.html2canvas === 'undefined') {
console.error("jsPDF or html2canvas is not loaded.");
return;
}
const { jsPDF } = window.jspdf;
const content = document.getElementById('pdf-output-container');
downloadPdfBtn.textContent = 'Generating...';
downloadPdfBtn.disabled = true;
try {
const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'letter' });
await pdf.html(content, {
margin: [72, 72, 72, 72], // Standard 1-inch margins
autoPaging: 'text',
width: 468, // Letter width (612pt) - margins (72pt * 2)
windowWidth: 700,
html2canvas: { scale: 0.8, useCORS: true }
});
const fileName = `legal_notice_to_${getText('recipientName', 'recipient')}.pdf`.toLowerCase().replace(/[^a-z0-9]/gi, '_');
pdf.save(fileName);
} catch (error) {
console.error("Error generating PDF:", error);
} finally {
downloadPdfBtn.textContent = 'Download as PDF';
downloadPdfBtn.disabled = false;
}
};
// --- Event Listeners ---
tabs.forEach(tab => tab.addEventListener('click', () => showTab(parseInt(tab.dataset.tab, 10))));
nextBtn.addEventListener('click', () => { if (currentTab < totalTabs) showTab(currentTab + 1); });
prevBtn.addEventListener('click', () => { if (currentTab > 1) showTab(currentTab - 1); });
if(downloadPdfBtn) downloadPdfBtn.addEventListener('click', downloadPDF);
// Set default date
const dateInput = document.getElementById('noticeDate');
if(dateInput) {
dateInput.valueAsDate = new Date();
}
// --- Initial Setup ---
showTab(1);
});