import { Hero } from "@/components/sections/Hero";
import { Team } from "@/components/sections/Team";
import { About } from "@/components/sections/About";
import { Classes } from "@/components/sections/Classes";
import { MasterClasses } from "@/components/sections/MasterClasses";
import { Schedule } from "@/components/sections/Schedule";
import { Pricing } from "@/components/sections/Pricing";
import { News } from "@/components/sections/News";
import { FAQ } from "@/components/sections/FAQ";
import { Contact } from "@/components/sections/Contact";
import { BackToTop } from "@/components/ui/BackToTop";
import { FloatingContact } from "@/components/ui/FloatingContact";
import { Header } from "@/components/layout/Header";
import { Footer } from "@/components/layout/Footer";
import { getContent } from "@/lib/content";

export const dynamic = "force-dynamic";
import { OpenDay } from "@/components/sections/OpenDay";
import { getActiveOpenDay } from "@/lib/openDay";
import { getAllMcRegistrations } from "@/lib/db";

export default function HomePage() {
  const content = getContent();
  const openDayData = getActiveOpenDay();
  // Count MC registrations per title for capacity check
  const allMcRegs = getAllMcRegistrations();
  const mcRegCounts: Record<string, number> = {};
  for (const reg of allMcRegs) mcRegCounts[reg.masterClassTitle] = (mcRegCounts[reg.masterClassTitle] || 0) + 1;

  return (
    <>
      <Header />
      <main>
        <Hero data={content.hero} />
        <About
          data={content.about}
          stats={{
            trainers: content.team.members.length,
            classes: content.classes.items.length,
            locations: content.schedule.locations.length,
          }}
        />
        <Classes data={content.classes} />
        <Team data={content.team} schedule={content.schedule.locations} />
        {openDayData && <OpenDay data={openDayData} popups={content.popups} teamMembers={content.team.members} />}
        <Schedule data={content.schedule} classItems={content.classes.items} teamMembers={content.team.members} />
        <Pricing data={content.pricing} />
        <MasterClasses data={content.masterClasses} regCounts={mcRegCounts} popups={content.popups} />
        <News data={content.news} />
        <FAQ data={content.faq} />
        <Contact data={content.contact} />
        <BackToTop />
        <FloatingContact />
      </main>
      <Footer />
    </>
  );
}
