'; loader.style.display = 'none'; wrapper.classList.remove('hidden'); return; } document.getElementById('back-btn').href = `https://tabelafipeprime.com/tabela-fipe-b/3/?type=${type}&brandCode=${brandCode}`; try { const response = await fetch(`${API_BASE}${type}/marcas/${brandCode}/modelos`); if (!response.ok) throw new Error('Falha na API'); const data = await response.json(); const models = data.modelos; const select = document.getElementById('model-select'); select.innerHTML = ''; document.getElementById('model-intro').innerHTML = `Você selecionou ${decodeURIComponent(brandName)}. Agora, escolha o modelo exato.`; models.forEach(model => { const option = document.createElement('option'); option.value = model.codigo; option.textContent = model.nome; if(model.codigo.toString() === preselectedModelCode) { option.selected = true; } select.appendChild(option); }); const nextBtn = document.getElementById('next-btn'); if(preselectedModelCode) { nextBtn.classList.remove('disabled'); const modelName = select.options[select.selectedIndex].text; nextBtn.href = `https://tabelafipeprime.com/tabela-fipe-b/5/?type=${type}&brandCode=${brandCode}&brandName=${encodeURIComponent(brandName)}&modelCode=${preselectedModelCode}&modelName=${encodeURIComponent(modelName)}`; } select.addEventListener('change', () => { const modelCode = select.value; const modelName = select.options[select.selectedIndex].text; nextBtn.href = `https://tabelafipeprime.com/tabela-fipe-b/5/?type=${type}&brandCode=${brandCode}&brandName=${encodeURIComponent(brandName)}&modelCode=${modelCode}&modelName=${encodeURIComponent(modelName)}`; nextBtn.classList.remove('disabled'); }); } catch (error) { wrapper.innerHTML = '

Erro ao carregar os modelos. Tente novamente.

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