'use client'; import { useState, useEffect } from 'react'; import { ChevronDown } from 'lucide-react'; export default function SeriesTabMenu({ tabs, color }) { const availableTabs = tabs.filter(tab => tab.available); const [activeTab, setActiveTab] = useState(availableTabs[0]?.id || 'specs'); // Troca manual limpa o hash. Sem isso, depois de abrir o diagrama pelo link e // mudar de aba na mão, o hash continuaria em #connections e um novo clique no // link não dispararia hashchange — o botão pareceria quebrado. const trocarAba = (id) => { setActiveTab(id); if (window.location.hash) { history.replaceState(null, '', window.location.pathname + window.location.search); } }; // Abas endereçáveis por hash: #connections abre o diagrama de pinos direto. // É o que permite a seção de restrições apontar para cá. useEffect(() => { const abrirPeloHash = () => { const alvo = window.location.hash.replace('#', ''); if (alvo && availableTabs.some(t => t.id === alvo)) { setActiveTab(alvo); // Nenhum elemento tem id="connections", então o navegador não rola // sozinho: levamos até as abas na mão. const semAnimacao = window.matchMedia('(prefers-reduced-motion: reduce)').matches; document.getElementById('diagrama-abas')?.scrollIntoView({ behavior: semAnimacao ? 'auto' : 'smooth', block: 'start', }); } }; abrirPeloHash(); window.addEventListener('hashchange', abrirPeloHash); return () => window.removeEventListener('hashchange', abrirPeloHash); }, [availableTabs]); const activeTabContent = availableTabs.find(tab => tab.id === activeTab)?.content; return (
{/* Desktop Tabs */}
{availableTabs.map((tab) => { const isActive = activeTab === tab.id; return ( ); })}
{/* Mobile Dropdown Tab Selector */}
{availableTabs.map((tab) => ( tab.id !== activeTab && ( ) ))}
{activeTabContent}
); }