;(() => {
// Fauko Import — App entry. Routes to pages.

const { Header, Footer, WhatsFloat, useHashRoute, ScrollToTop } = window.FaukoChrome;

class ErrorBoundary extends React.Component {
  constructor(props) { super(props); this.state = { err: null }; }
  static getDerivedStateFromError(err) { return { err }; }
  componentDidCatch(err, info) { console.error('App crash:', err, info); }
  render() {
    if (this.state.err) {
      return (
        <main className="container" style={{ padding: '120px 24px', textAlign: 'center' }}>
          <h1 style={{ fontSize: 32, fontFamily: 'var(--font-display)', color: 'var(--fauko-navy)' }}>Algo deu errado</h1>
          <p style={{ marginTop: 12, color: 'var(--fauko-gray-dark)' }}>Recarregue a página para tentar novamente.</p>
          <button className="btn btn--primary" style={{ marginTop: 24 }} onClick={() => { this.setState({ err: null }); window.location.hash = '#/'; window.location.reload(); }}>Recarregar</button>
        </main>
      );
    }
    return this.props.children;
  }
}

function App() {
  const route = useHashRoute();
  const products = window.FAUKO_PRODUCTS || [];
  const path = route.split('?')[0] || '/';

  let page = null;
  if (path === '/' || path === '') {
    page = React.createElement(window.HomePage, { products });
  } else if (path.startsWith('/produtos')) {
    page = React.createElement(window.ProdutosPage, { products });
  } else if (path.startsWith('/produto/')) {
    page = React.createElement(window.ProdutoDetailPage, { products });
  } else if (path === '/quem-somos') {
    page = React.createElement(window.QuemSomosPage);
  } else {
    page = React.createElement('main', { className: 'container', style: { padding: '120px 0' } },
      React.createElement('h1', null, 'Página não encontrada'),
      React.createElement(window.FaukoChrome.Link, { to: '/', className: 'btn btn--primary', style: { marginTop: 24 } }, '← Voltar para a home')
    );
  }

  return (
    <React.Fragment>
      <ScrollToTop />
      <Header />
      <ErrorBoundary>{page}</ErrorBoundary>
      <Footer />
      <WhatsFloat />
    </React.Fragment>
  );
}

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

})();
