`;
} else {
container.innerHTML += ``;
}
if (report.converterNeeded) {
container.innerHTML += ``;
} else {
container.innerHTML += ``;
}
}
function updateTabView() {
Object.values(tabButtons).forEach(b => b.classList.remove('active'));
Object.values(tabContents).forEach(c => c.classList.remove('active'));
tabButtons[currentTab].classList.add('active');
tabContents[currentTab].classList.add('active');
prevBtn.style.visibility = currentTab === 1 ? 'hidden' : 'visible';
nextBtn.textContent = currentTab === 1 ? 'Check Compatibility' : 'Next';
nextBtn.style.visibility = currentTab === 2 ? 'hidden' : 'visible';
}
function goToTab(tabNumber) {
if (tabNumber > currentTab && currentTab === 1) {
displayResults();
}
currentTab = tabNumber;
updateTabView();
}
function downloadPdf() {
if (!currentReport) {
showCustomMessage('No Data', 'Please generate a report first.', 'warning');
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFontSize(22); doc.setFont('helvetica', 'bold');
doc.text("Travel Adapter Compatibility Report", 105, 20, { align: 'center' });
const tableData = [
["", "Home (" + currentReport.home.name + ")", "Destination (" + currentReport.dest.name + ")"],
["Plug Type", `Type ${currentReport.home.plug}`, `Type ${currentReport.dest.plug}`],
["Voltage", `${currentReport.home.voltage}V`, `${currentReport.dest.voltage}V`],
["Frequency", `${currentReport.home.freq}Hz`, `${currentReport.dest.freq}Hz`],
];
const resultsData = [
["Adapter Needed?", currentReport.adapterNeeded ? `YES (Type ${currentReport.dest.plug.split(' / ')[0]})` : "NO"],
["Voltage Converter Needed?", currentReport.converterNeeded ? "YES (Crucial to prevent damage)" : "NO (Voltage is compatible)"]
];
doc.autoTable({
startY: 30, head: [['Feature', 'Home', 'Destination']], body: tableData,
theme: 'grid', headStyles: { fillColor: [37, 99, 235] }
});
doc.autoTable({
startY: doc.autoTable.previous.finalY + 10,
head: [['Requirement', 'Result']], body: resultsData,
theme: 'striped', headStyles: { fillColor: [22, 163, 74] }
});
doc.save('Adapter_Compatibility_Report.pdf');
}
function showCustomMessage(title, body, type) {
const box = document.getElementById('message-box'), titleEl = document.getElementById('message-title'), bodyEl = document.getElementById('message-body'), iconContainer = document.getElementById('message-icon-container');
if(!box || !titleEl || !bodyEl || !iconContainer) return;
titleEl.textContent = title; bodyEl.textContent = body;
let iconSvg = '';
switch (type) {
case 'success': iconSvg = ``; break;
case 'error': iconSvg = ``; break;
case 'warning': iconSvg = ``; break;
}
iconContainer.innerHTML = iconSvg; box.classList.add('show');
setTimeout(() => { box.classList.remove('show'); }, 4000);
}
prevBtn.addEventListener('click', () => goToTab(1));
nextBtn.addEventListener('click', () => goToTab(2));
pdfDownloadBtn.addEventListener('click', downloadPdf);
populateCountries();
updateTabView();
});
Adapter Needed: NO
Your home plugs are compatible with the sockets at your destination.
Voltage Converter Needed: YES
Warning! Your devices (${report.home.voltage}V) are not compatible with the higher voltage (${report.dest.voltage}V) at your destination. A converter is required to prevent damage.
Voltage Converter Needed: NO
The voltage is compatible. Most modern electronics (laptops, phone chargers) are dual-voltage, but always check your device's label.
