`;
});
guideContainer.innerHTML = html;
}
function saveTabData() {
if (currentTab === 1) {
appData.profileType = document.querySelector('input[name="profileType"]:checked').value;
if (appData.profileType === 'personal') {
const select = getEl('personalInsuranceType');
appData.insuranceType = select.value;
appData.insuranceTypeName = select.options[select.selectedIndex].text;
} else {
const select = getEl('businessInsuranceType');
appData.insuranceType = select.value;
appData.insuranceTypeName = select.options[select.selectedIndex].text;
}
appData.state = getEl('state').value;
} else if (currentTab === 2) {
appData.guideResults = [];
const form = getEl('form-guide');
const questions = complianceQuestions[appData.profileType]?.[appData.insuranceType] || [];
questions.forEach(q => {
const answer = form.elements[q.id]?.value;
appData.guideResults.push({
id: q.id,
text: q.text,
answer: parseInt(answer || 0),
recommendation: q.recommendation
});
});
}
}
function generateReport() {
saveTabData();
const score = appData.guideResults.reduce((sum, item) => sum + item.answer, 0);
const total = appData.guideResults.length;
const percentage = total > 0 ? Math.round((score / total) * 100) : 100;
let scoreColor = 'bg-green-500';
let assessment = 'Good Standing';
if (percentage < 50) { scoreColor = 'bg-red-500'; assessment = 'Action Required'; }
else if (percentage < 80) { scoreColor = 'bg-yellow-500'; assessment = 'Review Recommended'; }
const recommendations = appData.guideResults.filter(r => r.answer === 0);
let html = `
`;
getEl('report-container').innerHTML = html;
showTab(3);
}
function downloadPdf() {
if (!appData.guideResults) { alert('Please generate a report first.'); return; }
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFontSize(18);
doc.text("Insurance Compliance Report", 105, 20, { align: 'center' });
doc.setFontSize(11);
doc.text("Assessment Profile", 14, 35);
doc.setFontSize(10);
const profileText = `Profile: ${appData.profileType.charAt(0).toUpperCase() + appData.profileType.slice(1)}\nInsurance: ${appData.insuranceTypeName}\nState: ${appData.state}`;
doc.text(profileText, 14, 42);
const score = appData.guideResults.reduce((sum, item) => sum + item.answer, 0);
const total = appData.guideResults.length;
const percentage = total > 0 ? Math.round((score / total) * 100) : 100;
doc.setFontSize(11);
doc.text(`Overall Compliance Score: ${percentage}%`, 14, 65);
const tableBody = appData.guideResults.map(r => [r.text, r.answer === 1 ? 'Yes' : 'No']);
doc.autoTable({
startY: 75,
head: [['Compliance Checkpoint', 'Response']],
body: tableBody,
theme: 'grid',
headStyles: { fillColor: [13, 148, 136] },
didParseCell: function(data) {
if (data.section === 'body' && data.column.index === 1 && data.cell.raw === 'No') {
data.cell.styles.textColor = [220, 53, 69];
}
}
});
let finalY = doc.autoTable.previous.finalY + 15;
const recommendations = appData.guideResults.filter(r => r.answer === 0);
if(recommendations.length > 0) {
doc.setFontSize(11);
doc.text("Recommendations", 14, finalY);
const recText = recommendations.map(r => `- Issue: ${r.text}\n Recommendation: ${r.recommendation}`).join('\n\n');
doc.setFontSize(9);
doc.text(recText, 14, finalY + 7, { maxWidth: 180 });
}
doc.save(`Insurance-Compliance-Report.pdf`);
}
// --- Event Listeners ---
document.querySelectorAll('input[name="profileType"]').forEach(radio => {
radio.addEventListener('change', handleProfileTypeChange);
});
nextBtn.addEventListener('click', () => {
saveTabData();
if (currentTab < totalTabs - 1) {
populateGuide();
showTab(currentTab + 1);
} else {
const form = getEl('form-guide');
if (form && !form.checkValidity()) {
form.reportValidity();
return;
}
generateReport();
}
});
prevBtn.addEventListener('click', () => {
if (currentTab > 1) {
showTab(currentTab - 1);
}
});
getEl('download-pdf-btn').addEventListener('click', downloadPdf);
// --- Initialization ---
handleProfileTypeChange();
updateNavigation();
});
Compliance Report
Assessment Profile
Profile Type: ${appData.profileType.charAt(0).toUpperCase() + appData.profileType.slice(1)}
Insurance Type: ${appData.insuranceTypeName}
State: ${appData.state}
Compliance Score
${assessment}
Actionable Recommendations
${recommendations.length === 0 ? 'Excellent! Your responses indicate good alignment with key compliance standards.
' : `-
${recommendations.map(r => `
- Issue: A 'No' was indicated for: '${r.text}'
Recommendation: ${r.recommendation} `).join('')}
