`).join('');
}
/**
* Removes a document from the filing list.
*/
window.removeDocument = function(index) {
filedDocuments.splice(index, 1);
renderDocumentsList();
}
/**
* Generates the summary view for review and confirmation.
*/
function generateSummary(targetElementId) {
const caseInfo = {
'Case Name': document.getElementById('caseName').value,
'Case Number': document.getElementById('caseNumber').value,
'Court': document.getElementById('courtName').value,
'Filer Name': document.getElementById('filerName').value,
'Filer Role': document.getElementById('filerRole').value,
};
let docsTable = `
| Type | Title | File Name |
`;
filedDocuments.forEach(doc => {
docsTable += `
| ${doc.type} |
${doc.title} |
${doc.fileName} |
`;
});
if(filedDocuments.length === 0) {
docsTable += `| No documents in this filing. |
`;
}
docsTable += '
';
const summaryHTML = `
Case Information
${Object.entries(caseInfo).map(([key, value]) => `
- ${key}
- ${value || 'N/A'}
`).join('')}
Filed Documents
${docsTable}
`;
document.getElementById(targetElementId).innerHTML = summaryHTML;
preparePdfContent(caseInfo, docsTable);
}
/**
* Generates a random confirmation number.
*/
function generateConfirmation() {
const timestamp = Date.now();
const randomPart = Math.random().toString(36).substring(2, 8).toUpperCase();
document.getElementById('confirmationNumber').textContent = `US-CTX-${timestamp}-${randomPart}`;
}
/**
* Prepares the content for high-quality PDF generation.
*/
function preparePdfContent(caseInfo, docsTableHTML) {
const confirmationNumber = document.getElementById('confirmationNumber').textContent || 'N/A';
const filingDate = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
const pdfHTML = `
Electronic Filing Confirmation
Confirmation #: ${confirmationNumber} | Filing Date: ${filingDate}
Case Information
Case Name: ${caseInfo['Case Name']}
Case Number: ${caseInfo['Case Number']}
Court: ${caseInfo['Court']}
Filer: ${caseInfo['Filer Name']} (${caseInfo['Filer Role']})
Filed Documents
${docsTableHTML.replace(/class="[^"]*"/g, '')}
`;
document.getElementById('pdf-content-wrapper').innerHTML = pdfHTML;
}
/**
* Downloads the generated confirmation as a PDF file.
*/
async function downloadPDF() {
const { jsPDF } = window.jspdf;
const pdfContent = document.getElementById('pdf-render-area');
if (!pdfContent) return;
downloadPdfBtn.textContent = 'Generating...';
downloadPdfBtn.disabled = true;
pdfContent.classList.remove('hidden');
try {
const canvas = await html2canvas(pdfContent, { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'portrait', unit: 'in', format: 'letter' });
const imgProps = pdf.getImageProperties(imgData);
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save('Filing_Confirmation.pdf');
} catch (error) {
console.error('Error generating PDF:', error);
} finally {
pdfContent.classList.add('hidden');
downloadPdfBtn.textContent = 'Download Confirmation as PDF';
downloadPdfBtn.disabled = false;
}
}
// --- EVENT LISTENERS ---
document.getElementById('addDocBtn').addEventListener('click', addDocument);
submitBtn.addEventListener('click', () => navigateTabs(1));
downloadPdfBtn.addEventListener('click', downloadPDF);
// --- INITIALIZATION ---
showTab(currentTab);
});