/* ── Tax Tables ── */ const TABLES = { 1: [ {max:180000, aliq:.04, ded:0}, {max:360000, aliq:.073, ded:5940}, {max:720000, aliq:.095, ded:13860}, {max:1800000, aliq:.107, ded:22500}, {max:3600000, aliq:.143, ded:87300}, {max:4800000, aliq:.19, ded:378000} ], 2: [ {max:180000, aliq:.045, ded:0}, {max:360000, aliq:.078, ded:5940}, {max:720000, aliq:.10, ded:13860}, {max:1800000, aliq:.112, ded:22500}, {max:3600000, aliq:.147, ded:85500}, {max:4800000, aliq:.30, ded:720000} ], 3: [ {max:180000, aliq:.06, ded:0}, {max:360000, aliq:.112, ded:9360}, {max:720000, aliq:.135, ded:17640}, {max:1800000, aliq:.16, ded:35640}, {max:3600000, aliq:.21, ded:125640}, {max:4800000, aliq:.33, ded:648000} ], 4: [ {max:180000, aliq:.045, ded:0}, {max:360000, aliq:.09, ded:8100}, {max:720000, aliq:.102, ded:12420}, {max:1800000, aliq:.14, ded:39780}, {max:3600000, aliq:.22, ded:183780}, {max:4800000, aliq:.33, ded:828000} ], 5: [ {max:180000, aliq:.155, ded:0}, {max:360000, aliq:.18, ded:4500}, {max:720000, aliq:.195, ded:9900}, {max:1800000, aliq:.205, ded:17100}, {max:3600000, aliq:.23, ded:62100}, {max:4800000, aliq:.305, ded:540000} ] }; /* ── Tab Switching ── */ function switchTab(n) { document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active')); document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active')); document.querySelector(`.tab-btn[data-tab="${n}"]`).classList.add('active'); document.getElementById(`panel-${n}`).classList.add('active'); } /* ── Accordion ── */ function toggleAccordion(trigger) { const body = trigger.nextElementSibling; const isOpen = trigger.classList.contains('open'); // Close all document.querySelectorAll('.accordion-trigger').forEach(t => { t.classList.remove('open'); t.nextElementSibling.style.maxHeight = null; }); if (!isOpen) { trigger.classList.add('open'); body.style.maxHeight = body.scrollHeight + 'px'; } } /* ── Currency Formatting ── */ function parseVal(s) { if (!s) return 0; return parseFloat(s.replace(/\./g, '').replace(',', '.')) || 0; } function fmtBRL(v) { return v.toLocaleString('pt-BR', {minimumFractionDigits: 2, maximumFractionDigits: 2}); } function rawCalcInput(el) { const v = parseVal(el.value); if (v > 0) el.value = v.toString().replace('.', ','); } function fmtCalcInput(el) { el.value = el.value.replace(/[^\d,]/g, ''); } function fmtCalcBlur(el) { const v = parseVal(el.value); if (v > 0) el.value = fmtBRL(v); else el.value = ''; } /* ── Calculate Effective Rate ── */ function calcEfetiva(anexo) { const input = document.getElementById(`calc-rbt-${anexo}`); const rbt = parseVal(input.value); const resultDiv = document.getElementById(`calc-result-${anexo}`); if (rbt <= 0 || rbt > 4800000) { resultDiv.classList.remove('show'); return; } const table = TABLES[anexo]; let faixa = null; let faixaNum = 0; for (let i = 0; i < table.length; i++) { if (rbt <= table[i].max) { faixa = table[i]; faixaNum = i + 1; break; } } if (!faixa) return; const ae = (rbt * faixa.aliq - faixa.ded) / rbt; const dasMensal = (rbt / 12) * ae; document.getElementById(`res-faixa-${anexo}`).textContent = `${faixaNum}ª Faixa`; document.getElementById(`res-nominal-${anexo}`).textContent = (faixa.aliq * 100).toFixed(2).replace('.', ',') + '%'; document.getElementById(`res-deduzir-${anexo}`).textContent = 'R$ ' + fmtBRL(faixa.ded); document.getElementById(`res-efetiva-${anexo}`).textContent = (ae * 100).toFixed(2).replace('.', ',') + '%'; document.getElementById(`res-das-${anexo}`).textContent = 'R$ ' + fmtBRL(dasMensal); resultDiv.classList.add('show'); } /* ── Enter key triggers calc ── */ document.querySelectorAll('[id^="calc-rbt-"]').forEach(input => { input.addEventListener('keydown', e => { if (e.key === 'Enter') { const anexo = input.id.split('-').pop(); calcEfetiva(parseInt(anexo)); } }); });