import { EMICalculatorTeaser } from "@/components/offers/EMICalculatorTeaser";
import { OfferCategoryCards } from "@/components/offers/OfferCategoryCards";
import { OfferTerms } from "@/components/offers/OfferTerms";
import { OffersCTA } from "@/components/offers/OffersCTA";
import { OffersHero } from "@/components/offers/OffersHero";
import { ScootersOnOffer } from "@/components/offers/ScootersOnOffer";
import {
  getCmsFinanceEnabled,
  getCmsImageControl,
  getCmsPageContent,
  getCmsPageHeroImage,
  getCmsPageSections,
  getOffersPageData,
} from "@/lib/db-data";
import { createPageMetadata } from "@/lib/seo";

export const metadata = createPageMetadata({
  title: "Offers",
  description:
    "Explore cashback offers, exchange benefits, and test ride offers at Bashista Auto.",
  path: "/offers",
});

export default async function OffersPage() {
  const [data, financeEnabled, heroBackgroundImage, heroProductImage, pageContent, pageSections] = await Promise.all([
    getOffersPageData(),
    getCmsFinanceEnabled(),
    getCmsPageHeroImage("offers", "/images/backgrounds/hero-bg-offers.png"),
    getCmsImageControl("offers_banner_product_image", "/images/scooters/hero-scooter-v2.png"),
    getCmsPageContent("offers", {
      heroTitle: "Season of Savings, Future of Mobility",
      heroSubtitle: "Offers & Discounts",
      heroDescription: "Exclusive offers on electric scooters. Limited period only.",
    }),
    getCmsPageSections("offers", { section1: true, section2: true, section3: true, section4: true, section5: true, section6: true }),
  ]);
  const { brands, scooters } = data;
  const offers = financeEnabled
    ? data.offers
    : data.offers.filter((offer) => offer.category.toLowerCase() !== "low emi plans");

  return (
    <>
      {pageSections.section1 ? <OffersHero
        scooters={scooters}
        heroBackgroundImage={heroBackgroundImage}
        financeEnabled={financeEnabled}
        heroProductImage={heroProductImage}
        heroTitle={pageContent.heroTitle}
        heroSubtitle={pageContent.heroSubtitle}
        heroDescription={pageContent.heroDescription}
      /> : null}
      {pageSections.section2 ? <OfferCategoryCards offers={offers} /> : null}
      {pageSections.section3 ? <ScootersOnOffer brands={brands} offers={offers} scooters={scooters} /> : null}
      {pageSections.section4 && financeEnabled ? <EMICalculatorTeaser scooters={scooters} /> : null}
      {pageSections.section5 ? <OfferTerms /> : null}
      {pageSections.section6 ? <OffersCTA scooters={scooters} /> : null}
    </>
  );
}
