'; loader.style.display = 'none'; wrapper.classList.remove('hidden'); return; } try { const response = await fetch(`${API_BASE}${type}/marcas`); if (!response.ok) throw new Error('Falha na API'); const brands = await response.json(); const select = document.getElementById('brand-select'); select.innerHTML = ''; document.getElementById('brand-intro').textContent = `Você selecionou a consulta para ${type}. Agora, escolha a montadora.`; brands.forEach(brand => { const option = document.createElement('option'); option.value = brand.codigo; option.textContent = brand.nome; if (brand.codigo === preselectedBrandCode) { option.selected = true; } select.appendChild(option); }); const nextBtn = document.getElementById('next-btn'); if(preselectedBrandCode) { nextBtn.classList.remove('disabled'); const brandName = select.options[select.selectedIndex].text; nextBtn.href = `https://tabelafipeprime.com/tabela-fipe-b/4/?type=${type}&brandCode=${preselectedBrandCode}&brandName=${encodeURIComponent(brandName)}`; } select.addEventListener('change', () => { const brandCode = select.value; const brandName = select.options[select.selectedIndex].text; nextBtn.href = `https://tabelafipeprime.com/tabela-fipe-b/4/?type=${type}&brandCode=${brandCode}&brandName=${encodeURIComponent(brandName)}`; nextBtn.classList.remove('disabled'); }); } catch (error) { wrapper.innerHTML = '

Erro ao carregar as marcas. Tente novamente.

'; } finally { loader.style.display = 'none'; wrapper.classList.remove('hidden'); try { (adsbygoogle = window.adsbygoogle || []).push({}); } catch (e) {} } });