// ============================================================
// APP — Router root
// ============================================================

function App() {
  const route = useHashRoute();
  const [, force] = useState(0);
  // re-render when storage changes (e.g. cross-tab)
  useEffect(() => {
    const onStorage = () => force(x => x + 1);
    window.addEventListener('storage', onStorage);
    return () => window.removeEventListener('storage', onStorage);
  }, []);

  const [head, second, third] = route.parts;

  if (head === 'admin') {
    return <AdminApp route={route} navigate={route.navigate} />;
  }
  if (head === 'artigo' && second) {
    return <Article slug={second} />;
  }
  if (head === 'categoria' && second) {
    return <CategoryPage slug={second} />;
  }
  // default → home
  return <Home />;
}

ReactDOM.createRoot(document.getElementById('root')).render(<App />);
