`).join('');
// Taxes
const taxContainer = document.getElementById('tax-info');
taxContainer.innerHTML = DB.taxes.map(t => `
`).join('');
}
// --- TAB NAVIGATION ---
function updateTabDisplay() {
tabButtons.forEach(button => button.classList.toggle('active', parseInt(button.dataset.tab) === currentTab));
tabContents.forEach(content => content.style.display = 'none');
document.getElementById(`tab-content-${currentTab}`).style.display = 'block';
prevBtn.disabled = currentTab === 1;
nextBtn.style.display = currentTab === totalTabs ? 'none' : 'inline-flex';
}
function validateCurrentTab() {
const currentContent = document.getElementById(`tab-content-${currentTab}`);
const inputs = currentContent.querySelectorAll('input[required]');
for (const input of inputs) {
if (!input.value.trim()) {
input.reportValidity();
return false;
}
}
return true;
}
function changeTab(newTab) {
if (newTab > currentTab && !validateCurrentTab()) return;
if (newTab >= 1 && newTab <= totalTabs) {
currentTab = newTab;
updateTabDisplay();
}
}
// --- PDF GENERATION ---
function generatePdfHtml() {
const investorName = document.getElementById('investor-name').value;
const industry = document.getElementById('investor-industry').value;
const structureId = document.getElementById('selected-structure').value;
const selectedStructure = DB.structures.find(s => s.id === structureId);
const selectedRegulations = Array.from(document.querySelectorAll('input[name="regulation"]:checked'))
.map(cb => DB.regulations.find(r => r.id === cb.value));
return `
`).join('')}
`).join('')}
${t.title}
${t.desc}
Foreign Investor Compliance Guide for ${investorName}
This guide provides a high-level overview for investing in the ${industry} sector in the USA.
Chosen Business Structure
${selectedStructure.title}
${selectedStructure.desc}
Key Regulatory Considerations
${selectedRegulations.map(r => `${r.title}
${r.desc}
U.S. Taxation Overview
${DB.taxes.map(t => `${t.title}
${t.desc}
This document is for informational purposes only and does not constitute legal or financial advice. Consult with qualified U.S. legal and tax professionals before making any investment decisions. Generated on ${new Date().toLocaleDateString('en-US')}.
`; } async function handlePdfDownload() { document.getElementById('pdf-content').innerHTML = generatePdfHtml(); const { jsPDF } = window.jspdf; const button = document.getElementById('downloadPdfBtn'); button.textContent = 'Generating...'; button.disabled = true; const pdfContainer = document.getElementById('pdf-container'); pdfContainer.classList.remove('invisible'); try { const canvas = await html2canvas(pdfContainer, { scale: 2 }); 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 pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); pdf.save('Foreign_Investor_Compliance_Guide.pdf'); } catch (error) { console.error("PDF generation failed:", error); } finally { button.textContent = 'Download Your Guide'; button.disabled = false; pdfContainer.classList.add('invisible'); } } // --- EVENT LISTENERS --- nextBtn.addEventListener('click', () => changeTab(currentTab + 1)); prevBtn.addEventListener('click', () => changeTab(currentTab - 1)); tabButtons.forEach(button => button.addEventListener('click', (e) => changeTab(parseInt(e.target.dataset.tab)))); document.getElementById('downloadPdfBtn').addEventListener('click', handlePdfDownload); document.getElementById('structure-options').addEventListener('click', e => { const card = e.target.closest('.info-card'); if (!card) return; document.querySelectorAll('.info-card').forEach(c => c.classList.remove('selected')); card.classList.add('selected'); document.getElementById('selected-structure').value = card.dataset.value; }); // --- INITIALIZATION --- renderContent(); updateTabDisplay(); });