/** Built-in content of /services (the static page), in the CMS shape of page "services". */
import { DIVISIONS, divisionHref, type DivisionGroup } from "@/app/(site)/_lib/divisions";
import type { PageSection, PublicPage, ServiceCard } from "@/app/(site)/_lib/pageContent";

/** Services page section key of each built-in division group. */
export const DIVISION_SECTION: Record<DivisionGroup, string> = {
  science: "science-nutrition",
  trade: "trade-commerce",
  sustainability: "sustainability-strategy",
  innovation: "innovation-knowledge",
};

/** The built-in service cards of one division (Services page section key), as the API sends them. */
export function builtInServiceCards(sectionKey: string): ServiceCard[] {
  return DIVISIONS.filter((d) => DIVISION_SECTION[d.group] === sectionKey).map((d) => ({
    slug: d.slug,
    path: divisionHref(d.slug),
    href: d.card.cta.href,
    image: d.card.image,
    title: d.card.title,
    description: d.card.description,
    ctaLabel: d.card.cta.label,
  }));
}

/**
 * Until a service is published in the CMS, the divisions show the 12 built-in services
 * (each with its built-in page at /services/<slug>). After that the CMS decides.
 */
export function withBuiltInServices(page: PublicPage): PublicPage {
  return { ...page, sections: page.sections.map((s) => (s.type === "service-listing" ? { ...s, content: { ...(s.content as object), services: builtInServiceCards(s.key) } } : s)) };
}

const cards = (group: DivisionGroup) => builtInServiceCards(DIVISION_SECTION[group]);

export const SERVICES_DEFAULTS: PageSection[] = [
  { key: "page-hero", type: "page-hero", content: { title: "Explore Our Services", breadcrumb: "Products & Services" } },
  {
    key: "introduction",
    type: "text-image",
    content: {
      title: { text: "A Unified Ecosystem of Global Trade, Nutrition, Sustainability & Innovation", highlight: "A Unified Ecosystem of Global Trade," },
      body: "Unionists Group delivers an integrated portfolio of science, commerce, sustainability, and next-generation innovation services — designed to strengthen the global food economy from end to end. From biotechnology and medical nutrition to global trade networks, ESG strategy, robotics, and private-label manufacturing, every division works together to build a synchronized, intelligent food system powered by AI, precision logistics, and ethical sourcing.",
      image: { url: "/assets/images/services/services-intro.png", alt: "Hands holding a sprout and a light bulb planted in soil" },
      imagePosition: "left",
    },
  },
  {
    key: "science-nutrition",
    type: "service-listing",
    content: {
      title: { text: "Science & Nutrition Division" },
      body: "Unionists Group ensures every donation is transparently tracked, verified, and directed to the right cause. We publish annual impact reports and provide real-time updates on ongoing projects.",
      services: cards("science"),
    },
  },
  {
    key: "trade-commerce",
    type: "service-listing",
    content: {
      title: { text: "Trade & Commerce" },
      body: "Powering global commerce, certification, retail expansion, and intelligent ingredient networks for worldwide trade leadership.",
      services: cards("trade"),
    },
  },
  {
    key: "sustainability-strategy",
    type: "service-listing",
    content: {
      title: { text: "Sustainability & Strategy Division" },
      body: "Building future-resilient ecosystems through sustainable design, ESG-driven packaging, and strategic expansion partnerships.",
      services: cards("sustainability"),
    },
  },
  {
    key: "innovation-knowledge",
    type: "service-listing",
    content: {
      title: { text: "Innovation & Knowledge Division" },
      body: "Powering global commerce, certification, retail expansion, and intelligent ingredient networks for worldwide trade leadership.",
      services: cards("innovation"),
    },
  },
  {
    key: "global-network",
    type: "text-image",
    content: {
      title: { text: "The Global Operating Network Behind Our Services", highlight: "Network Behind Our Services" },
      body:
        "Unionists Group operates through a fully integrated global ecosystem that connects sourcing, production, logistics, innovation, and trade across multiple continents. Our infrastructure enables us to deliver large-scale, reliable, and future-ready solutions to partners worldwide.\n\n" +
        "From advanced logistics corridors to high-performance warehouses, strategic sourcing zones, and dedicated R&D centers, every part of our network is designed to ensure precision, transparency, and efficient global operations.",
      image: { url: "/assets/images/services/services-global-network.png", alt: "Digital globe illustration showing global trade network connections" },
      imagePosition: "right",
    },
  },
  {
    key: "stats",
    type: "stats",
    content: {
      items: [
        { value: "3,000", label: "Trusted by Leading Global Brands & Enterprise Partners", icon: { url: "/assets/images/stats/stat-revenue.png", alt: "" } },
        { value: "600+", label: "Warehouses, Hubs, and Strategic Distribution Centers", icon: { url: "/assets/images/stats/stat-logistics.png", alt: "" } },
        { value: "97%", label: "On-Time Delivery Across All Global Regions", icon: { url: "/assets/images/stats/stat-farmers.png", alt: "" } },
        { value: "209+", label: "Countries of Operation by 2025", icon: { url: "/assets/images/stats/stat-countries.png", alt: "" } },
        { value: "100+", label: "AI-Powered Trade & Supply Chain Advancements", icon: { url: "/assets/images/stats/stat-ai.png", alt: "" } },
      ],
    },
  },
  {
    key: "partner-cta",
    type: "cta-buttons",
    content: {
      title: { text: "Partner With Unionists Group" },
      body: "Figma ipsum component variant main layer. Horizontal horizontal thumbnail rectangle move connection distribute.",
      ctas: [
        { label: "Start Your Supply Chain Partnership Today", href: "/contact" },
        { label: "Explore Our Global Trade Network", href: "/global-presence" },
      ],
    },
  },
];
