/** Section markup of /global-strategy, keyed by CMS section key (markup unchanged from the static page). */
import type { CtaButtonsContent, FeatureCardsContent, MapArea, MapHighlightsContent, PageHeroContent, TextImageContent } from "@/app/(site)/_lib/pageContent";
import { ApplyCta, Columns, PageHero, Paras, sixColSpan } from "../blocks";
import { SplitTitle } from "../parts";
import type { SectionRenderers } from "../render";

const HL = "text-[#0056D2]";

/** Where each map card sits, its colour, and whether its pin is below the text (Europe) or above it. */
const AREAS: Record<MapArea, { pos: string; tone: string; pinBelow?: boolean }> = {
  europe: { pos: "europe", tone: "cyan", pinBelow: true },
  americas: { pos: "americas", tone: "green" },
  "middle-east-africa": { pos: "mea", tone: "gold" },
  "asia-pacific": { pos: "asia", tone: "blue" },
};

function Pin() {
  return (
    <span className="gsd-presence-card__pin" aria-hidden="true">
      {" "}
      <span className="gsd-presence-pin-ring"></span> <span className="gsd-presence-pin-ring gsd-presence-pin-ring--delay"></span>{" "}
      <span className="gsd-presence-pin"></span>{" "}
    </span>
  );
}

export const GLOBAL_STRATEGY_SECTIONS: SectionRenderers = {
  "page-hero": (c: PageHeroContent) => <PageHero c={c} />,
  introduction: (c: TextImageContent) => (
    <section className="bg-white pt-12 md:pt-16 lg:pt-20 pb-4 md:pb-6 lg:pb-8">
      <div className="w-full max-w-[1180px] mx-auto px-6">
        <div className="grid grid-cols-1 lg:grid-cols-2 gap-7 lg:gap-12 items-center">
          <Columns
            imagePosition={c.imagePosition}
            image={(side) => (
              <div className="rounded-[2px] overflow-hidden" data-reveal={side}>
                <img src={c.image.url} alt={c.image.alt ?? ""} className="w-full aspect-[560/500] h-auto block object-cover" width="560" height="340" loading="lazy" />
              </div>
            )}
            text={(side) => (
              <div data-reveal={side}>
                <h2 className="text-[clamp(22px,2.6vw,28px)] font-semibold leading-tight tracking-[-0.01em]">
                  <SplitTitle title={c.title} hl={HL} rest="text-ink" />
                </h2>
                <Paras body={c.body} first="mt-[18px] text-[15px] leading-[1.75] text-[#2E2E2E]" next="mt-4 text-[15px] leading-[1.75] text-[#2E2E2E]" />
                {!!c.features?.length && (
                  <ul className="mt-8 flex flex-col gap-5">
                    {c.features.map((f, i) => (
                      <li key={i} className="careers-feature-item flex items-start gap-4">
                        {f.icon?.url && (
                          <>
                            <img src={f.icon.url} alt="" width="40" height="40" loading="lazy" className="careers-feature-icon-img shrink-0" />{" "}
                          </>
                        )}
                        <div>
                          <h3 className="text-[15px] font-semibold text-ink leading-[1.35]">{f.title}</h3>
                          {f.description && <p className="mt-1 text-[14px] text-[#2E2E2E] leading-[1.6]">{f.description}</p>}
                        </div>
                      </li>
                    ))}
                  </ul>
                )}
              </div>
            )}
          />
        </div>
      </div>
    </section>
  ),
  "focus-areas": (c: FeatureCardsContent) => (
    <section className="bg-white pt-4 md:pt-6 lg:pt-8 pb-12 md:pb-16 lg:pb-20">
      <div className="w-full max-w-[1180px] mx-auto px-6 text-center">
        <div data-reveal="">
          {c.title && (
            <h2 className="text-[clamp(22px,2.6vw,28px)] font-semibold text-ink leading-tight tracking-[-0.01em]">
              <SplitTitle title={c.title} hl={HL} />
            </h2>
          )}
          {c.body && <p className="mt-4 text-[14px] text-[#2E2E2E] max-w-[720px] mx-auto leading-[1.7]">{c.body}</p>}
        </div>
        <div className="careers-hire-grid mt-10 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-6 gap-5 text-left">
          {c.items.map((it, i) => (
            <article key={i} className={`commitment-card bg-[#f3f5f8] rounded-[6px] p-[28px_24px_30px] ${sixColSpan(i, c.items.length)}`} data-reveal="">
              {it.icon?.url && (
                <div className="w-12 h-12 mb-[18px]">
                  <img src={it.icon.url} alt="" width="48" height="48" loading="lazy" className="w-12 h-12 object-contain" />
                </div>
              )}
              <h3 className="text-[15px] font-semibold text-ink mb-[10px] leading-[1.4]">{it.title}</h3>
              {it.description && <p className="text-sm text-[#2E2E2E] leading-[1.6]">{it.description}</p>}
            </article>
          ))}
        </div>
      </div>
    </section>
  ),
  mission: (c: FeatureCardsContent) => (
    <section className="bg-navy-solid py-14 md:py-20 text-center">
      <div className="w-full max-w-[1180px] mx-auto px-6">
        <div data-reveal="">
          {c.title && (
            <h2 className="text-[clamp(24px,3vw,32px)] font-semibold text-white leading-tight tracking-[-0.01em]">
              <SplitTitle title={c.title} hl={HL} />
            </h2>
          )}
          {c.body && <p className="mt-4 text-[14px] text-white/80 max-w-[720px] mx-auto leading-[1.7]">{c.body}</p>}
        </div>
        <div className="mt-10 grid grid-cols-1 md:grid-cols-2 gap-4 text-left">
          {c.items.map((it, i) => (
            <article key={i} className="offer-card bg-[#0D2959] rounded-[6px] p-[24px_20px_28px]" data-reveal="">
              {it.icon?.url && (
                <div className="w-[52px] h-[52px] mb-[18px]">
                  <img src={it.icon.url} alt="" width="52" height="52" loading="lazy" className="w-[52px] h-[52px] object-contain" />
                </div>
              )}
              <h3 className="text-[14.5px] font-semibold text-white mb-3 leading-[1.35]">{it.title}</h3>
              {!!it.bullets?.length && (
                <ul className="careers-bullet-list careers-offerings-list text-[13px] text-white leading-[1.55]">
                  {it.bullets.map((b, j) => (
                    <li key={j}>{b}</li>
                  ))}
                </ul>
              )}
            </article>
          ))}
        </div>
      </div>
    </section>
  ),
  "global-presence": (c: MapHighlightsContent) => (
    <section className="py-14 md:py-20 text-center">
      <div className="w-full max-w-[1180px] mx-auto px-6">
        <div data-reveal="">
          <h2 className="text-[clamp(22px,2.6vw,28px)] font-semibold text-ink leading-tight tracking-[-0.01em]">
            <SplitTitle title={c.title} hl={HL} />
          </h2>
          {c.body && <p className="mt-4 text-[14px] text-[#2E2E2E] max-w-[720px] mx-auto leading-[1.7]">{c.body}</p>}
        </div>
        <div className="gsd-presence-map mt-10" data-reveal="" role="region" aria-label="Global presence map showing regional operations">
          <div className="gsd-presence-map__frame" aria-hidden="true">
            <img src={c.image.url} alt="" className="gsd-presence-map__bg" width="1024" height="441" loading="lazy" />
          </div>
          {c.items.map((it, i) => {
            const a = AREAS[it.area];
            if (!a) return null;
            const title = <h3 className="gsd-presence-card__title">{it.title}</h3>;
            const text = <p className="gsd-presence-card__text">{it.description}</p>;
            return a.pinBelow ? (
              <article key={i} className={`gsd-presence-card gsd-presence-card--pos-${a.pos} gsd-presence-card--${a.tone} gsd-presence-card--pin-below`}>
                {title}
                {text} <Pin />
              </article>
            ) : (
              <article key={i} className={`gsd-presence-card gsd-presence-card--pos-${a.pos} gsd-presence-card--${a.tone}`}>
                <Pin /> {title}
                {text}
              </article>
            );
          })}
        </div>
      </div>
    </section>
  ),
  leadership: (c: FeatureCardsContent) => (
    <section className="bg-white py-6 md:py-8 lg:pt-0 ">
      <div className="w-full max-w-[1180px] mx-auto px-6 text-center">
        <div data-reveal="">
          {c.title && (
            <h2 className="text-[clamp(22px,2.6vw,28px)] font-semibold text-ink leading-tight tracking-[-0.01em]">
              <SplitTitle title={c.title} hl={HL} />
            </h2>
          )}
          {c.body && <p className="mt-4 text-[14px] text-[#2E2E2E] max-w-[720px] mx-auto leading-[1.7]">{c.body}</p>}
        </div>
        <div className="mt-10 grid grid-cols-1 md:grid-cols-3 gap-4 text-left">
          {c.items.map((it, i) => (
            <article key={i} className="commitment-card bg-[#f3f5f8] rounded-[6px] p-[28px_24px_30px]" data-reveal="">
              {it.icon?.url && (
                <div className="w-12 h-12 mb-[18px]">
                  <img src={it.icon.url} alt="" width="48" height="48" loading="lazy" className="w-12 h-12 object-contain" />
                </div>
              )}
              <h3 className="text-[15px] font-semibold text-ink mb-[10px] leading-[1.4]">{it.title}</h3>
              {it.description && <p className="text-sm text-[#2E2E2E] leading-[1.6]">{it.description}</p>}
            </article>
          ))}
        </div>
      </div>
    </section>
  ),
  "work-with-us": (c: CtaButtonsContent) => <ApplyCta c={c} />,
};
