`;
}
// Build checklist
checklistItems.push(getListItem('Recreational Flying', country.recreationalAllowed));
checklistItems.push(getListItem('Registration', regStatus));
checklistItems.push({ icon: '⛈', text: `Fly below ${country.maxAltitude}.` });
checklistItems.push({ icon: '👁', text: 'Always keep the drone within your visual line of sight.' });
checklistItems.push({ icon: '👤', text: 'Do not fly over people or crowds.' });
checklistItems.push({ icon: '🚫', text: `Important Note: ${country.notes}` });
const checklistHtml = ``;
return { bannerHtml, checklistHtml };
}
function getListItem(type, status) {
let item = { icon: '', text: '', class: '' };
switch (status) {
case 'yes':
item.icon = '✓';
item.text = `${type} is generally allowed.`;
item.class = 'icon-yes';
break;
case 'no':
item.icon = '✕';
item.text = `${type} is banned for tourists.`;
item.class = 'icon-no';
break;
case 'banned':
item.icon = '✕';
item.text = `${type} is banned. Drones may be confiscated.`;
item.class = 'icon-no';
break;
case 'conditional':
item.icon = '⚠';
item.text = `${type} is allowed, but with significant pre-arrival conditions.`;
item.class = 'icon-warn';
break;
case 'required':
item.icon = '⚠';
item.text = `${type} is required before flying.`;
item.class = 'icon-warn';
break;
case 'not_required':
item.icon = '✓';
item.text = `${type} is not typically required for this weight class.`;
item.class = 'icon-yes';
break;
case 'operator_id':
item.icon = '⚠';
item.text = `An Operator ID is required, even for drones with cameras under 250g.`;
item.class = 'icon-warn';
break;
}
return item;
}
function renderConfig() {
configTbody.innerHTML = regulationData.map(d => `
${d.name}
${createSelect('recreationalAllowed', d.id, d.recreationalAllowed, {yes:'Allowed', conditional:'Conditional', no:'Banned'})}
${createSelect('regUnder250', d.id, d.regUnder250, {not_required:'Not Required', required:'Required', operator_id:'Operator ID', banned:'Banned'})}
${createSelect('regOver250', d.id, d.regOver250, {not_required:'Not Required', required:'Required', operator_id:'Operator ID', banned:'Banned'})}
`).join('');
}
function createSelect(prop, id, selectedValue, options) {
let optionsHtml = Object.entries(options).map(([value, text]) =>
``
).join('');
return ``;
}
window.updateConfig = function(element) {
const { id, prop } = element.dataset;
const value = element.value;
const country = regulationData.find(d => d.id === id);
if (country) {
country[prop] = value;
checkRegulations();
}
}
// --- 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('.status-banner')) {
console.warn("Please select a destination to generate a report.");
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(`${destinationSelect.options[destinationSelect.selectedIndex].text}-Drone-Regulations.pdf`);
}).catch(err => {
console.error("Error generating PDF:", err);
}).finally(() => {
downloadPdfBtn.innerHTML = originalButtonText;
downloadPdfBtn.disabled = false;
});
});
}
// --- INITIALIZATION ---
function initializeTool() {
populateControls();
checkRegulations();
renderConfig();
updateNavButtons();
}
initializeTool();
});
- ${checklistItems.map(item => `
- ${item.icon} ${item.text}`).join('')}
