Please enter valid property details.
';
return;
}
let elevationMultiplier = 1;
if (elevation < 5) elevationMultiplier = 1.5;
else if (elevation < 10) elevationMultiplier = 1.2;
const riskScore = zone.baseRisk * type.multiplier * elevationMultiplier;
renderResults(riskScore);
}
function renderResults(score) {
let level, color, message, recommendations;
if (score <= 3) {
level = 'Low Risk';
color = 'var(--risk-low)';
message = 'Standard flood insurance is recommended but may not be required by lenders.';
recommendations = [
{ icon: '🛡', text: 'Maintain proper grading and drainage around the property.' },
{ icon: '📜', text: 'Keep important documents in a waterproof, elevated container.' }
];
} else if (score <= 8) {
level = 'Moderate Risk';
color = 'var(--risk-moderate)';
message = 'Flood insurance is strongly recommended. Some lenders may require it.';
recommendations = [
{ icon: '🛡', text: 'Install flood vents in foundation walls if applicable.' },
{ icon: '🔌', text: 'Elevate utilities (HVAC, water heater) above potential flood levels.' },
{ icon: '📜', text: 'Create a detailed flood emergency plan.' }
];
} else if (score <= 15) {
level = 'High Risk';
color = 'var(--risk-high)';
message = 'Flood insurance is almost certainly required by lenders. Significant risk of flooding.';
recommendations = [
{ icon: '🛡', text: 'Consider professional flood-proofing measures for the foundation.' },
{ icon: '🔌', text: 'Ensure all electrical outlets and switches are elevated.' },
{ icon: '📝', text: 'Install backflow prevention valves in sewer lines.' }
];
} else {
level = 'Very High Risk';
color = 'var(--risk-very-high)';
message = 'Extreme flood risk. Comprehensive flood insurance and mitigation strategies are essential.';
recommendations = [
{ icon: '🏘', text: 'Investigate property elevation or relocation as a long-term strategy.' },
{ icon: '🛡', text: 'Use flood-resistant materials for all construction below the Base Flood Elevation (BFE).'},
{ icon: '🔌', text: 'All utilities and appliances must be significantly elevated.' }
];
}
const recommendationsHTML = `
${recommendations.map(r => `- ${r.icon}
${r.text}
`).join('')}
`;
resultsContent.innerHTML = `
Key Recommendations
${recommendationsHTML}
`;
}
function renderConfig() {
configContainer.innerHTML = `
`;
}
window.updateConfig = function(element) {
const { type, id, prop } = element.dataset;
const value = parseFloat(element.value);
if (isNaN(value)) return;
const item = riskData[type].find(i => i.id === id);
if (item) {
item[prop] = value;
assessRisk();
}
}
// --- TAB & NAVIGATION ---
window.openTab = function(evt, tabName) {
const tabContents = document.getElementsByClassName("tab-content");
Array.from(tabContents).forEach(tab => tab.style.display = "none");
const tabButtons = document.getElementsByClassName("tab-btn");
Array.from(tabButtons).forEach(btn => btn.classList.remove("active"));
document.getElementById(tabName).style.display = "block";
if (evt) {
evt.currentTarget.classList.add("active");
} else {
const btnToActivate = Array.from(tabButtons).find(btn => btn.getAttribute('onclick').includes(`'${tabName}'`));
if (btnToActivate) btnToActivate.classList.add("active");
}
updateNavButtons();
}
window.navigateTabs = function(direction) {
const tabs = Array.from(document.querySelectorAll('.tab-btn'));
const activeTabIndex = tabs.findIndex(tab => tab.classList.contains('active'));
let newIndex = (direction === 'next')
? (activeTabIndex + 1) % tabs.length
: (activeTabIndex - 1 + tabs.length) % tabs.length;
tabs[newIndex].click();
}
function updateNavButtons() {
const tabs = Array.from(document.querySelectorAll('.tab-btn'));
const activeTabIndex = tabs.findIndex(tab => tab.classList.contains('active'));
document.getElementById('prev-btn').style.visibility = activeTabIndex === 0 ? 'hidden' : 'visible';
document.getElementById('next-btn').style.visibility = activeTabIndex === tabs.length - 1 ? 'hidden' : 'visible';
}
// --- PDF DOWNLOAD ---
if(downloadPdfBtn) {
downloadPdfBtn.addEventListener('click', function() {
const { jsPDF } = window.jspdf;
const contentToDownload = document.getElementById('results-to-download');
if (!contentToDownload || !document.querySelector('.risk-banner')) {
console.warn("Please generate an assessment before downloading.");
return;
}
const originalButtonText = downloadPdfBtn.innerHTML;
downloadPdfBtn.innerHTML = 'Generating...';
downloadPdfBtn.disabled = true;
html2canvas(contentToDownload, { 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 imgProps = pdf.getImageProperties(imgData);
const imgHeight = (imgProps.height * pdfWidth) / imgProps.width;
pdf.addImage(imgData, 'PNG', 10, 10, pdfWidth - 20, imgHeight > 0 ? imgHeight - 20 : 0);
pdf.save('Flood-Risk-Assessment.pdf');
}).catch(err => {
console.error("Error generating PDF:", err);
}).finally(() => {
downloadPdfBtn.innerHTML = originalButtonText;
downloadPdfBtn.disabled = false;
});
});
}
// --- INITIALIZATION ---
function initializeTool() {
populateControls();
assessRisk();
renderConfig();
updateNavButtons();
}
initializeTool();
});