import { withIronSessionSsr } from "iron-session/next";
// import Head from "next/head";
import { getTranslations } from "next-intl/server";

import Banner from "@/components/Sections/Banner";
import Events from "@/components/Sections/Events";
import About from "@/components/Sections/About";
import WhatWeOffer from "@/components/Sections/WhatWeOffer";
import RidingSchool from "@/components/Sections/RidingSchool";
import Gallery from "@/components/Sections/Gallery";
// import Error from "@/components/Sections/Error";
import EventCalendar from "@/components/Sections/EventCalendar";
import TourMap from "@/components/Sections/TourMap";
import News from "@/components/Sections/News";
import Sponsors from "@/components/Sections/Sponsors";
import SocialMedia from "@/components/Sections/SocialMedia";
import { BASE_URL, WEBSITE_URL, config } from "@/Helper/Config";
import axios from "axios";

async function getData({ locale }: { locale: string }) {
  const apiUrl = BASE_URL + "home"; // Path to your API route
  const headers = { ...config, "Accept-Language": locale };
  try {
    // if fetching data
    const response = await axios.get(apiUrl, { headers });
    const data = response.data;
    return data;
  } catch (error) {
    // if fetching error
    console.error("Error fetching data:", error);
    return {
      data: null,
    };
  }
}

const Home = async ({ params: { locale } }: { params: { locale: string } }) => {
  const t = await getTranslations("common");
  const data = await getData({ locale });
  const home = data?.data;

  return (
    <>
      <Banner banner={home?.home_banner} />
      <Events locale={locale} events={home?.events} />
      <News locale={locale} news={home?.news} title={t("News")} />
      <WhatWeOffer locale={locale} offers={home?.offers} />
      <RidingSchool locale={locale} riding={home?.riding_school} />
      <EventCalendar locale={locale} calendar={home?.events} />
      <Gallery locale={locale} gallery={home?.gallery} title={t("Gallery")} />
      <TourMap map={home?.map_markers} title={t("Interactive Tour Map")} />
      <About locale={locale} about={home?.about_us_banner} />
      <SocialMedia title={t("Social Media")} />
      <Sponsors sponsors={home?.sponsors} title={t("Serc sponsors")} />
    </>
  );
};

export default Home;

// Sharjah Longines race course
