`;
});
formHTML += ``;
});
complianceForm.innerHTML = formHTML;
};
// --- UI LOGIC ---
let currentTab = 0;
const updateTabUI = () => {
tabs.forEach((tab, index) => {
if (tab.btn && tab.content) {
tab.content.classList.toggle('hidden', index !== currentTab);
tab.btn.classList.toggle('active', index === currentTab);
tab.btn.classList.toggle('text-gray-700', index === currentTab);
tab.btn.classList.toggle('text-gray-500', index !== currentTab);
}
});
prevBtn.disabled = currentTab === 0;
nextBtn.textContent = currentTab === tabs.length - 2 ? 'Generate Report' : 'Next';
nextBtn.disabled = currentTab === tabs.length - 1;
prevBtn.style.visibility = currentTab === 0 ? 'hidden' : 'visible';
nextBtn.style.visibility = currentTab === tabs.length - 1 ? 'hidden' : 'visible';
if (currentTab === tabs.length - 1) {
generateReport();
}
};
// --- REPORT GENERATION ---
const generateReport = () => {
const companyName = document.getElementById('companyName')?.value.trim() || "[Company Name]";
const industry = document.getElementById('industrySector')?.value;
const state = document.getElementById('businessState')?.value;
let reportHTML = `
`;
});
});
reportOutput.innerHTML = reportHTML;
};
// --- EVENT LISTENERS ---
tabs.forEach((tab, index) => {
if (tab.btn) tab.btn.addEventListener('click', () => { currentTab = index; updateTabUI(); });
});
nextBtn.addEventListener('click', () => {
if (currentTab < tabs.length - 1) { currentTab++; updateTabUI(); }
});
prevBtn.addEventListener('click', () => {
if (currentTab > 0) { currentTab--; updateTabUI(); }
});
downloadPdfBtn.addEventListener('click', () => {
const { jsPDF } = window.jspdf;
const reportElement = document.getElementById('reportOutput');
const companyName = document.getElementById('companyName')?.value.trim() || "Company";
if (!reportElement) {
console.error("PDF Generation Error: Report output element not found.");
return;
}
html2canvas(reportElement, { scale: 2, 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 pdfHeight = pdf.internal.pageSize.getHeight();
const canvasWidth = canvas.width;
const canvasHeight = canvas.height;
const ratio = canvasWidth / canvasHeight;
const imgWidth = pdfWidth - 20; // with 10mm margin
const imgHeight = imgWidth / ratio;
let heightLeft = imgHeight;
let position = 10;
pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight);
heightLeft -= (pdfHeight - 20);
while (heightLeft > 0) {
position = position - (pdfHeight - 20);
pdf.addPage();
pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight);
heightLeft -= (pdfHeight - 20);
}
const safeFileName = companyName.replace(/[^a-z0-9]/gi, '_').toLowerCase();
pdf.save(`${safeFileName}_environmental_compliance_report.pdf`);
});
});
// --- INITIALIZE APP ---
populateDropdowns();
populateChecklist();
updateTabUI();
});
Environmental Compliance Summary
Company: ${companyName}
Industry: ${industry}
State of Operation: ${state}
Date of Report: ${new Date().toLocaleDateString()}
This report provides a preliminary summary based on your checklist answers. It is not legal advice. Consult with an environmental professional for formal compliance verification.
`; checklistQuestions.forEach(section => { reportHTML += `${section.act}
`; section.questions.forEach(q => { const answer = document.querySelector(`input[name="${q.id}"]:checked`)?.value || 'Not Answered'; reportHTML += `${q.text}
Your Answer: ${answer}
`; // Add compliance notes for risky answers if ((q.id.startsWith('caa') || q.id.startsWith('cwa') || q.id.startsWith('rcra')) && answer === 'Yes' && (q.id.endsWith('2') || q.id.endsWith('3')) && (document.querySelector(`input[name="${q.id.slice(0,-1)}2"]:checked`)?.value === 'No' || document.querySelector(`input[name="${q.id.slice(0,-1)}3"]:checked`)?.value === 'No')) { // Complex logic example: if you emit pollutants but have no permit if(q.id.endsWith('2') && answer === 'No') reportHTML += `Potential Issue: Operating without a required permit is a significant compliance risk. Immediate review is recommended.
`;
if(q.id.endsWith('3') && answer === 'No') reportHTML += `Potential Issue: Failure to monitor and report emissions/discharges as required can lead to penalties.
`;
} else if(q.id === 'rcra2' && answer === 'No' && document.querySelector(`input[name="rcra1"]:checked`)?.value === 'Yes') {
reportHTML += `Potential Issue: If you generate waste, failing to determine if it's hazardous is a foundational compliance gap.
`;
}
reportHTML += `