/**
 * The 12 built-in services (app/(site)/_lib/divisions.ts) in the CMS shape of a service
 * page. The website shows them until a service is published in the CMS; the admin uses
 * them to fill a new service's empty sections ("Import website content").
 */
import { getDivision, type Division } from "@/app/(site)/_lib/divisions";
import type { PageSection } from "@/app/(site)/_lib/pageContent";
import { DIVISION_SECTION } from "../services/defaults";

/** Page sections of a built-in service, in display order. `withCard` adds its Services page card first. */
export function divisionSections(d: Division, withCard = false): PageSection[] {
  const { hero, introduction, innovations, process, caseStudy, collaboration } = d.content;
  const page: PageSection[] = [
    { key: "page-hero", type: "page-hero", content: { title: hero.title, breadcrumb: hero.breadcrumb } },
    { key: "introduction", type: "text-image", content: { title: introduction.title, body: introduction.body, image: introduction.image, imagePosition: "left" } },
    { key: "core-innovations", type: "feature-cards", content: { title: innovations.title, items: innovations.items, ctas: [] } },
    { key: "process", type: "process-steps", content: process },
    { key: "case-study", type: "case-study", content: caseStudy },
    { key: "collaboration", type: "cta-image", content: { title: collaboration.title, body: collaboration.body, ctas: [collaboration.cta], image: collaboration.image, imagePosition: "right" } },
  ];
  if (!withCard) return page;
  // No href: the button opens the service's own page.
  const card: PageSection = { key: "card", type: "service-card", content: { image: d.card.image, title: d.card.title, description: d.card.description, ctaLabel: d.card.cta.label } };
  return [card, ...page];
}

/** Built-in sections (with the card) of the service with this slug, for the admin's import. */
export function builtInServiceSections(slug: string): PageSection[] | undefined {
  const d = getDivision(slug);
  return d ? divisionSections(d, true) : undefined;
}

/** The Services page division (section key) a built-in service belongs to. */
export const builtInDivisionOf = (slug: string) => {
  const d = getDivision(slug);
  return d ? DIVISION_SECTION[d.group] : undefined;
};
