import React, { useEffect } from 'react';
import Header from './components/Header';
import Hero from './components/Hero';
import About from './components/About';
import Offerings from './components/Offerings';
import WhyHumanAI from './components/WhyHumanAI';
import Process from './components/Process';
import Audience from './components/Audience';
import CTASection from './components/CTASection';
import Footer from './components/Footer';
import PrivacyPolicyPage from './components/PrivacyPolicyPage';
import PlatformPage from './components/PlatformPage';

function App() {
  const path = window.location.pathname.replace(/\/$/, '') || '/';

  // The landing sections are client-rendered, so when a /#section URL arrives
  // with the initial request — following "Oferta"/"Kontakt" from /privacy or
  // /platforma — the browser resolves the fragment before the target exists and
  // leaves the page at the top. Re-apply the scroll once the sections are
  // mounted. In-page clicks never reach this: they are same-document fragment
  // navigations that the browser handles natively (smoothly, via .scroll-smooth)
  // without remounting App.
  useEffect(() => {
    if (path !== '/') return;
    const id = window.location.hash.slice(1);
    if (!id) return;
    // Jump rather than smooth-scroll: this only runs on a fresh load, where
    // animating the full page height would just be a slow detour.
    document.getElementById(id)?.scrollIntoView({ behavior: 'auto' });
  }, [path]);

  if (path === '/privacy') {
    return <PrivacyPolicyPage />;
  }

  if (path === '/platforma') {
    return <PlatformPage />;
  }

  return (
    <div className="min-h-screen bg-background selection:bg-primary selection:text-background">
      <Header />
      <main>
        <Hero />
        <About />
        <Offerings />
        <WhyHumanAI />
        <Process />
        <Audience />
        <CTASection />
      </main>
      <Footer />
    </div>
  );
}

export default App;
