import type { Metadata } from "next";
import { SitePage } from "@/app/(site)/_components/SitePage";
import { SiteHeader } from "@/app/(site)/_components/SiteHeader";
import { SiteFooter } from "@/app/(site)/_components/SiteFooter";
import { renderSections } from "@/app/(site)/_components/pages/render";
import { SERVICES_DEFAULTS, withBuiltInServices } from "@/app/(site)/_components/pages/services/defaults";
import { SERVICES_SECTIONS } from "@/app/(site)/_components/pages/services/sections";
import { getPage, getServiceList, hasPublishedServices } from "@/app/(site)/_lib/cms";

export const metadata: Metadata = {
  title: "Services — Unionists Group",
};

export default async function Page() {
  const [data, services] = await Promise.all([getPage("services"), getServiceList()]);
  // The division cards are the published services; until there is one, the built-in ones.
  const page = data && !hasPublishedServices(services) ? withBuiltInServices(data) : data;
  return (
    <SitePage className="services-page">
      <a className="skip-link" href="#main">
        Skip to main content
      </a>{" "}
      <SiteHeader active="/product-services" activeItem="/services" />
      <main id="main">{renderSections("services", page, SERVICES_DEFAULTS, SERVICES_SECTIONS)}</main>
      <SiteFooter />
    </SitePage>
  );
}
