import { mainPageApi } from '@/features/pages/api/pages.api';

import { makeStore } from '@/shared/store';

import { AboutSection } from '@/widgets/about-section';
import { CharitySection } from '@/widgets/charity-section';
import { CtaSection } from '@/widgets/cta-section';
import { HeroSection } from '@/widgets/hero-section';
import { MapSection } from '@/widgets/map-section';
import { PartnersSection } from '@/widgets/partners-section';
import { PromotionsSection } from '@/widgets/promotions-section';
import { StatsSection } from '@/widgets/stats-section';
import { VacanciesSection } from '@/widgets/vacancies-section';

export default async function Home() {
  const store = makeStore();

  const { data, isLoading, error } = await store.dispatch(
    mainPageApi.endpoints.fetchMainPageContent.initiate(),
  );

  if (isLoading || !data) return null;

  return (
    <main>
      <HeroSection />
      <StatsSection />
      <MapSection stations={data.stations} />
      <AboutSection />
      <PromotionsSection discounts={data.discounts} />
      <VacanciesSection jobs={data.jobs} />
      <PartnersSection partners={data.partners} />
      <CharitySection />
      <CtaSection />
    </main>
  );
}
