import type { Metadata } from "next";

import { NewsListing } from "@/components/news/NewsListing";
import { Editorial } from "@/components/shared/Editorial";
import { PageCta } from "@/components/shared/PageCta";
import { PageHero } from "@/components/shared/PageHero";
import { SiteFooter } from "@/components/SiteFooter";
import { SiteHeader } from "@/components/SiteHeader";
import heroImage from "@/assets/images/hero/hero-1.jpg";
import heroImageMobile from "@/assets/images/hero/hero-1-mobile.jpg";
import { news, newsAndBlogPage, newsListingPage } from "@/data/site";

export const metadata: Metadata = {
  title: "اخبار",
  description: "فهرست کامل اخبار و رویدادهای منتشرشده‌ی گروه ساختمانی رئوفی.",
};

export default async function NewsListPage({
  searchParams,
}: {
  searchParams: Promise<{ page?: string }>;
}) {
  const { page: pageParam } = await searchParams;
  const page = Math.max(1, Number(pageParam) || 1);

  return (
    <>
      <SiteHeader />

      <main>
        <PageHero
          image={heroImage}
          imageMobile={heroImageMobile}
          caption={newsListingPage.hero.caption}
          title={newsListingPage.hero.title}
          breadcrumb={newsListingPage.hero.breadcrumb}
        />

        <section className="bg-paper">
          <Editorial
            caption={newsListingPage.overview.caption}
            captionLatin={newsListingPage.overview.captionLatin}
            title={newsListingPage.overview.title}
            body={newsListingPage.overview.body}
            compact
          />
        </section>

        <section className="bg-sand pb-16 lg:pb-24">
          <NewsListing
            items={news}
            page={page}
            basePath="/news"
            emptyMessage={newsListingPage.emptyMessage}
          />
        </section>

        <PageCta
          caption={newsAndBlogPage.cta.caption}
          title={newsAndBlogPage.cta.title}
          action={newsAndBlogPage.cta.action}
        />
      </main>

      <SiteFooter />
    </>
  );
}
