"use client";

import { useEffect, useRef, useState, type FormEvent, type ReactNode } from "react";
import { useTranslation } from "../../../../i18n/I18nProvider";
import { useWeb } from "../WebContext";

const PILLAR_META = [
  { icon: "/landing/icons/pillar-products.svg", image: "/landing/pillar-products.png" },
  { icon: "/landing/icons/pillar-services.svg", image: "/landing/pillar-services.png" },
  { icon: "/landing/icons/pillar-partners.svg", image: "/landing/pillar-partners.png" },
  { icon: "/landing/icons/pillar-invest.svg", image: "/landing/pillar-invest.png" },
];

const ROLE_META = [
  { icon: "ri-user-3-line", featured: false, role: "customer" as const },
  { icon: "ri-store-2-line", featured: true, role: "business" as const },
  { icon: "ri-line-chart-line", featured: false, role: "investor" as const },
];

const TICKER = [
  { key: "landing.ticker.products", icon: "/landing/icons/ticker-products.svg" },
  { key: "landing.ticker.services", icon: "/landing/icons/ticker-services.svg" },
  { key: "landing.ticker.partners", icon: "/landing/icons/ticker-partners.svg" },
  { key: "landing.ticker.invest", icon: "/landing/icons/ticker-invest.svg" },
] as const;

/** Temporary: set to `true` to re-enable landing buttons, links, video, and the interest form. */
const LANDING_ACTIONS_ENABLED = false;

type CopyItem = { title: string; desc: string; cta: string };
type PillarItem = { id: string; title: string; imageAlt: string; desc: string; points: string[] };

function Wrap({ children, className = "" }: { children: ReactNode; className?: string }) {
  return <div className={`w-full max-w-[1240px] mx-auto px-4 sm:px-6 lg:px-8 ${className}`}>{children}</div>;
}

function LogoMark({ variant }: { variant: "header" | "footer" }) {
  const box = variant === "header" ? "h-8 w-[49px]" : "h-[68.5px] w-[72px]";
  const img =
    variant === "header"
      ? "absolute h-[340.6%] w-[177.78%] max-w-none left-[-38.19%] top-[-112.87%]"
      : "absolute h-[334.79%] w-[177.78%] max-w-none left-[-38.89%] top-[-110.46%]";
  return (
    <span className={`relative block overflow-hidden shrink-0 ${box}`}>
      <img src="/landing/logo-src.png" alt="" className={img} />
    </span>
  );
}

export default function Landing() {
  const { jump, openAuth } = useWeb();
  const { t, tm } = useTranslation();
  const [videoOpen, setVideoOpen] = useState(false);
  const [sent, setSent] = useState(false);
  const [message, setMessage] = useState("");
  const [form, setForm] = useState({
    name: "",
    email: "",
    phone: "",
    entity: "",
    sector: "",
    interest: "",
  });

  const pillars = tm<PillarItem[]>("landing.pillars.items");
  const roles = tm<CopyItem[]>("landing.roles.items");
  const videoItems = tm<string[]>("landing.video.items");
  const kinds = tm<string[]>("landing.interest.kinds");
  const sectors = tm<string[]>("landing.interest.sectors");

  const onSubmit = (e: FormEvent) => {
    e.preventDefault();
    if (!LANDING_ACTIONS_ENABLED) return;
    if (!form.name.trim() || !form.email.trim() || !form.phone.trim() || !form.interest) return;
    setSent(true);
  };

  const run = (fn: () => void) => {
    if (!LANDING_ACTIONS_ENABLED) return;
    fn();
  };

  const blockLink = (e: { preventDefault: () => void }) => {
    if (!LANDING_ACTIONS_ENABLED) e.preventDefault();
  };

  const scrollTo = (id: string) => {
    if (!LANDING_ACTIONS_ENABLED) return;
    document.getElementById(id)?.scrollIntoView({ behavior: "smooth", block: "start" });
  };

  return (
    <div id="top" className="bg-[#141e36] text-white font-body overflow-x-hidden">
      <header className="sticky top-0 z-50 min-h-16 lg:h-20 bg-[#141e36]/95 backdrop-blur-[4px] shadow-[0px_1px_0px_0px_#e0e0dd]">
        <div className="min-h-16 lg:h-20 px-4 sm:px-6 lg:px-8 py-2 lg:py-0 flex items-center max-w-[1440px] mx-auto gap-3 sm:gap-6">
          <button type="button" onClick={() => scrollTo("top")} className="flex items-center gap-2 sm:gap-3 cursor-pointer min-h-12 min-w-0">
            <LogoMark variant="header" />
            <span className="border-s border-[#3a4b73] ps-[13px] flex flex-col text-start min-w-0">
              <span className="text-[13px] sm:text-[14px] font-bold leading-[17.5px]">{t("landing.headerTitle")}</span>
              <span className="text-[10px] sm:text-[11px] font-normal text-[#adadad] leading-[13.75px]">{t("landing.headerSubtitle")}</span>
            </span>
          </button>

          <div className="flex items-center gap-2 sm:gap-2.5 ms-auto shrink-0">
            <button
              type="button"
              onClick={() => run(() => jump("auth"))}
              className="h-9 sm:h-10 px-3 sm:px-[17px] rounded-[12px] border border-[#3a4b73] text-[12px] sm:text-[13.5px] font-semibold leading-[20.25px] text-[#f2f5fb] cursor-pointer"
            >
              {t("landing.login")}
            </button>
            <button
              type="button"
              onClick={() => run(() => openAuth())}
              className="h-9 sm:h-10 px-3 sm:px-5 rounded-[12px] bg-[#0a0f1e] text-[12px] sm:text-[13.5px] font-semibold leading-[20.25px] text-[#f7f7f4] flex items-center gap-2 cursor-pointer"
            >
              <img src="/landing/icons/user-add.svg" alt="" width={12.6706} height={14} />
              {t("landing.signup")}
            </button>
          </div>
        </div>
      </header>

      <section className="relative bg-[#1b2744] border-b border-[#3a4b73] overflow-hidden">
        <div className="absolute bg-[#141e36] blur-[45px] opacity-70 rounded-full size-[420px] -top-24 -end-4" />
        <div className="absolute bg-[#141e36] blur-[50px] opacity-80 rounded-full size-[380px] -bottom-16 -start-20" />
        <Wrap className="py-10 lg:py-16">
          <div className="flex flex-col lg:flex-row lg:items-center gap-10 lg:gap-14">
            <div className="flex-1 min-w-0">
              <span className="inline-flex items-center gap-2 h-8 px-[15px] rounded-full bg-[#141e36] border border-[#3a4b73] text-[12px] font-semibold text-[#adadad]">
                <span className="size-2 rounded-full bg-[#f0c85a]" />
                {t("landing.hero.badge")}
              </span>
              <h1 className="mt-5 text-[32px] sm:text-[42px] lg:text-[52px] font-bold leading-[1.15] lg:leading-[59.8px] text-white text-start">{t("landing.hero.title")}</h1>
              <p className="mt-5 text-[17px] leading-[27.625px] text-[#adadad] max-w-[540px] text-start">
                {t("landing.hero.subtitle")}
              </p>
              <div className="mt-8 flex flex-col sm:flex-row sm:items-center gap-3">
                <button
                  type="button"
                  onClick={() => run(() => openAuth())}
                  className="h-[52px] px-7 rounded-2xl bg-[#0a0f1e] text-[15px] font-semibold text-[#f7f7f4] flex items-center justify-center gap-2 cursor-pointer w-full sm:w-auto"
                >
                  {t("landing.hero.ctaAccount")}
                  <i className="ri-arrow-left-line text-[18px]" />
                </button>
                <button
                  type="button"
                  onClick={() => run(() => setVideoOpen(true))}
                  className="h-[52px] px-6 rounded-2xl bg-[#141e36] border border-[#2b3858]/15 text-[15px] font-semibold flex items-center justify-center gap-2 cursor-pointer w-full sm:w-auto"
                >
                  <i className="ri-play-circle-line text-[20px]" />
                  {t("landing.hero.ctaVideo")}
                </button>
              </div>
              <div className="mt-10 pt-8 border-t border-[#3a4b73] grid grid-cols-2 lg:grid-cols-4 gap-5">
                {(
                  [
                    ["landing.hero.stats.businessesValue", "landing.hero.stats.businesses"],
                    ["landing.hero.stats.listingsValue", "landing.hero.stats.listings"],
                    ["landing.hero.stats.oppsValue", "landing.hero.stats.opps"],
                    ["landing.hero.stats.accountsValue", "landing.hero.stats.accounts"],
                  ] as const
                ).map(([v, l]) => (
                  <div key={l} className="text-start">
                    <p className="text-[26px] font-bold leading-[26px]">{t(v)}</p>
                    <p className="mt-1.5 text-[14px] leading-[16.5px] text-[#c3cad8]">{t(l)}</p>
                  </div>
                ))}
              </div>
            </div>

            <div className="w-full max-w-[532px] shrink-0 mx-auto lg:mx-0">
              <div className="relative rounded-[26px] overflow-hidden border border-[#3a4b73] bg-[#1b2744] h-[340px] sm:h-[420px] lg:h-[520px]">
                <img src="/landing/hero.png" alt={t("landing.hero.imageAlt")} className="absolute inset-0 w-full h-full object-cover" />
                <div className="absolute top-4 end-4 lg:top-[27px] lg:end-5 bg-[#0a0f1e] rounded-2xl px-4 py-3 shadow-[0px_10px_15px_-3px_rgba(0,0,0,0.1),0px_4px_6px_-4px_rgba(0,0,0,0.1)] w-[min(232px,calc(100%-2rem))] text-start">
                  <p className="text-[11px] text-[#f7f7f4]/75 leading-[16.5px]">{t("landing.hero.pillarsLabel")}</p>
                  <p className="text-[13px] font-semibold text-[#f7f7f4] leading-[19.5px]">{t("landing.hero.pillarsValue")}</p>
                </div>
                <div className="absolute bottom-[92px] start-4 lg:top-[375px] lg:bottom-auto lg:end-[297px] lg:start-auto bg-[#141e36] border border-[#3a4b73] rounded-[18px] p-[17px] w-[min(196px,calc(100%-2rem))] shadow-[0px_10px_15px_-3px_rgba(0,0,0,0.1),0px_4px_6px_-4px_rgba(0,0,0,0.1)]">
                  <div className="flex items-center gap-2">
                    <span className="size-8 rounded-[10px] bg-[#fff8ce] flex items-center justify-center shrink-0">
                      <img src="/landing/icons/verified-shield.svg" alt="" />
                    </span>
                    <div className="text-start">
                      <p className="text-[10.5px] text-[#adadad]">{t("landing.hero.verifiedHint")}</p>
                      <p className="text-[12px] font-semibold">{t("landing.hero.verifiedTitle")}</p>
                    </div>
                  </div>
                </div>
                <div className="absolute inset-x-0 bottom-0 h-[84px] bg-gradient-to-t from-[#0a0f1e]/85 via-[#0a0f1e]/35 to-transparent p-5 text-start">
                  <p className="text-[12px] text-[#f7f7f4]/85">{t("landing.hero.journeyLabel")}</p>
                  <p className="text-[15px] font-semibold">{t("landing.hero.journeyValue")}</p>
                </div>
              </div>
            </div>
          </div>
        </Wrap>
      </section>

      <section id="video" className="bg-[#0a0f1e] py-12 lg:py-20">
        <Wrap>
          <div className="flex flex-col lg:flex-row lg:items-center gap-10 lg:gap-14">
            <div className="w-full lg:w-[476px] shrink-0">
              <span className="inline-flex items-center gap-2 h-8 px-[15px] rounded-full border border-white/20 bg-[#141e36]/10 text-[12px] font-semibold">
                <i className="ri-vidicon-line text-[14px]" />
                {t("landing.video.badge")}
              </span>
              <h2 className="mt-5 text-[28px] sm:text-[32px] lg:text-[36px] font-bold leading-tight lg:leading-[45px] text-start">{t("landing.video.title")}</h2>
              <p className="mt-4 text-[15.5px] leading-[25px] text-[#f7f7f4]/75 text-start">{t("landing.video.body")}</p>
              <ul className="mt-6 space-y-3 text-[13.5px] leading-[21.9px] text-[#f7f7f4]/85">
                {videoItems.map((item) => (
                  <li key={item} className="flex items-center gap-2.5">
                    <span>{item}</span>
                    <img src="/landing/icons/check-gold.svg" alt="" width={15.0125} height={15} className="shrink-0" />
                  </li>
                ))}
              </ul>
              <p className="mt-7 text-[12px] text-[#f7f7f4]/50 text-start">{t("landing.video.duration")}</p>
            </div>

            <div className="w-full max-w-[644px] shrink-0 mx-auto lg:mx-0">
              <button
                type="button"
                onClick={() => run(() => setVideoOpen(true))}
                className="relative w-full aspect-[644/362] rounded-[22px] overflow-hidden border border-white/15 bg-[#0e1528] cursor-pointer"
                aria-label={t("landing.video.play")}
              >
                <span
                  className="absolute inset-px rounded-[21px]"
                  style={{ backgroundImage: "linear-gradient(136deg, #213f63 13%, #111e36 47%, #090e1c 80%)" }}
                />
                <img src="/landing/video-depth.svg" alt="" className="absolute left-[39px] -top-[31px] w-[300px] h-[220px] pointer-events-none" />
                <img src="/landing/video-glow.svg" alt="" className="absolute left-[81px] top-[30px] w-[480px] h-[300px] pointer-events-none" />
                <span className="absolute inset-0 bg-[#0a0f1e]/35" />
                <span className="absolute inset-0 flex flex-col items-center justify-center gap-3">
                  <span className="size-20 rounded-full bg-[#141e36] flex items-center justify-center shadow-[0px_20px_25px_-5px_rgba(0,0,0,0.1),0px_8px_10px_-6px_rgba(0,0,0,0.1)]">
                    <i className="ri-play-fill text-[36px] text-white" />
                  </span>
                  <span className="inline-flex h-[30px] px-4 rounded-full bg-[#0a0f1e]/60 backdrop-blur-[4px] text-[12px] font-semibold leading-none text-[#f7f7f4] items-center justify-center text-center">
                    {t("landing.video.play")}
                  </span>
                </span>
              </button>
              <p className="mt-3 text-center text-[11.5px] text-[#f7f7f4] leading-[17.25px]">{t("landing.video.caption")}</p>
            </div>
          </div>
        </Wrap>
      </section>

      <div className="bg-[#141e36] border-y border-[#3a4b73] py-5 px-4">
        <div className="flex flex-wrap items-center justify-center gap-x-8 gap-y-3 text-[13px] font-semibold text-[#f2f5fb]">
          {TICKER.map(({ key, icon }, i) => (
            <span key={key} className="contents">
              {i > 0 && <span className="size-1.5 rounded-full bg-[#2b3858]" />}
              <span className="flex items-center gap-2">
                <img src={icon} alt="" className="shrink-0" />
                {t(key)}
              </span>
            </span>
          ))}
        </div>
      </div>

      <section id="pillars" className="bg-[#141e36] py-12 lg:py-20">
        <Wrap>
          <div className="max-w-[640px] text-start">
            <p className="text-[12px] font-bold tracking-[1.68px] text-[#f2d42d]">{t("landing.pillars.eyebrow")}</p>
            <h2 className="mt-3 text-[28px] sm:text-[32px] lg:text-[38px] font-bold leading-tight lg:leading-[47.5px]">{t("landing.pillars.title")}</h2>
            <p className="mt-4 text-[15.5px] leading-[25px] text-[#adadad]">{t("landing.pillars.body")}</p>
          </div>
          <div className="mt-10 grid grid-cols-1 md:grid-cols-2 gap-6">
            {pillars.map((p, i) => (
              <article key={p.id} className="rounded-[22px] overflow-hidden border border-[#3a4b73] bg-[#1b2744]">
                <div className="relative h-[210px]">
                  <img src={PILLAR_META[i].image} alt={p.imageAlt} className="w-full h-full object-cover" />
                  <span className="absolute top-3 end-3 h-8 px-2.5 rounded-full bg-[#0a0f1e] text-[12px] font-semibold flex items-center">
                    {p.id}
                  </span>
                  <span className="absolute bottom-3 start-3 size-11 rounded-[14px] bg-[#f2d42d] shadow-[0px_4px_6px_-1px_rgba(0,0,0,0.1),0px_2px_4px_-2px_rgba(0,0,0,0.1)] flex items-center justify-center">
                    <img src={PILLAR_META[i].icon} alt="" />
                  </span>
                </div>
                <div className="p-6 text-start">
                  <h3 className="text-[20px] font-bold">{p.title}</h3>
                  <p className="mt-2 text-[13.5px] leading-[22px] text-[#adadad]">{p.desc}</p>
                  <ul className="mt-4 space-y-2 text-[13.5px] border-t border-[#3a4b73] pt-4">
                    {p.points.map((it) => (
                      <li key={it} className="flex items-center gap-2">
                        <i className="ri-check-line text-[#f2d42d] text-[16px]" />
                        {it}
                      </li>
                    ))}
                  </ul>
                </div>
              </article>
            ))}
          </div>
        </Wrap>
      </section>

      <section className="bg-[#1b2744] border-y border-[#3a4b73] py-12 lg:py-20">
        <Wrap>
          <div className="flex flex-col lg:flex-row gap-6 lg:gap-10">
            <div className="text-start">
              <p className="text-[12px] font-bold tracking-[1.68px] text-[#f2d42d]">{t("landing.roles.eyebrow")}</p>
              <h2 className="mt-3 text-[28px] sm:text-[32px] lg:text-[36px] font-bold leading-tight lg:leading-[45px]">{t("landing.roles.title")}</h2>
            </div>
            <p className="max-w-[420px] text-[14.5px] leading-[23.5px] text-[#f2f5fb] text-start">{t("landing.roles.lead")}</p>
          </div>
          <div className="mt-9 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6">
            {roles.map((r, i) => (
              <article
                key={r.title}
                className={`rounded-[22px] p-6 text-start flex flex-col ${
                  ROLE_META[i].featured ? "bg-[#0a0f1e] border-2 border-[#f2d42d]" : "bg-[#141e36] border border-[#3a4b73]"
                }`}
              >
                <div className="flex">
                  <div className="size-12 rounded-[14px] bg-[#f2d42d] text-[#0a0f1e] flex items-center justify-center">
                    <i className={`${ROLE_META[i].icon} text-[22px]`} />
                  </div>
                </div>
                <h3 className="mt-4 text-[18px] font-bold">{r.title}</h3>
                <p className="mt-2 text-[13.5px] leading-[22px] text-[#adadad]">{r.desc}</p>
                <button
                  type="button"
                  onClick={() => run(() => openAuth(ROLE_META[i].role))}
                  className={`mt-5 h-11 w-full rounded-[12px] text-[13.5px] font-semibold flex items-center justify-center gap-2 cursor-pointer ${
                    ROLE_META[i].featured ? "bg-[#141e36]" : "border border-[#2b3858]/15"
                  }`}
                >
                  {r.cta}
                  <i className="ri-arrow-left-line" />
                </button>
              </article>
            ))}
          </div>
          <button
            type="button"
            onClick={() => run(() => jump("home"))}
            className="mt-6 w-full min-h-[54px] rounded-[18px] bg-[#141e36] border border-[#3a4b73] px-4 sm:px-[21px] py-3 flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-4 cursor-pointer"
          >
            <span className="flex items-center gap-1.5 text-[13.5px] font-semibold">
              {t("landing.roles.guestCta")}
              <img src="/landing/icons/guest-compass.svg" alt="" />
            </span>
            <span className="text-[13px] text-[#adadad] text-start sm:ms-auto">{t("landing.roles.guestHint")}</span>
          </button>
        </Wrap>
      </section>

      <section id="interest" className="bg-[#141e36] border-b border-[#f2d42d]/60 py-12 lg:py-20">
        <Wrap>
          <div className="flex flex-col lg:flex-row gap-10 lg:gap-14">
            <div className="w-full lg:w-[476px] shrink-0 pt-1 text-start">
              <p className="text-[12px] font-bold tracking-[1.68px] text-[#f2d42d]">{t("landing.interest.eyebrow")}</p>
              <h2 className="mt-3 text-[28px] sm:text-[32px] lg:text-[36px] font-bold leading-tight lg:leading-[45px]">{t("landing.interest.title")}</h2>
              <p className="mt-4 text-[15px] leading-[24px] text-[#e9eef6]">{t("landing.interest.body")}</p>
              <a
                href="mailto:info@dshn.sa"
                onClick={blockLink}
                className="mt-7 flex items-center gap-3 rounded-2xl bg-[#1b2744] border border-[#3a4b73] px-4 py-3"
              >
                <span className="size-10 rounded-[12px] bg-[#f2d42d] text-[#0a0f1e] flex items-center justify-center shrink-0">
                  <i className="ri-mail-line text-[18px]" />
                </span>
                <span className="text-start">
                  <span className="block text-[11px] text-[#adadad]">{t("landing.interest.emailLabel")}</span>
                  <span className="block text-[13.5px] font-semibold">{t("landing.contact.emailValue")}</span>
                </span>
              </a>
              <a
                href="tel:0560609896"
                onClick={blockLink}
                className="mt-3 flex items-center gap-3 rounded-2xl bg-[#1b2744] border border-[#3a4b73] px-4 py-3"
              >
                <span className="size-10 rounded-[12px] bg-[#f2d42d] text-[#0a0f1e] flex items-center justify-center shrink-0">
                  <i className="ri-phone-line text-[18px]" />
                </span>
                <span className="text-start">
                  <span className="block text-[11px] text-[#adadad]">{t("landing.interest.phoneLabel")}</span>
                  <span className="block text-[13.5px] font-semibold">{t("landing.contact.phoneValue").replace(/\s/g, "")}</span>
                </span>
              </a>
            </div>

            <form onSubmit={onSubmit} className="flex-1 min-w-0 bg-[#1b2744] border border-[#3a4b73] rounded-[24px] p-5 sm:p-8 shadow-sm">
              <div className="flex flex-col sm:flex-row sm:items-center gap-3 mb-5">
                <div className="text-start">
                  <h3 className="text-[17px] font-bold leading-[25.5px]">{t("landing.interest.formTitle")}</h3>
                  <p className="text-[12.5px] leading-[18.75px]">{t("landing.interest.formHint")}</p>
                </div>
                <span className="inline-flex items-center gap-1.5 h-6 px-3 rounded-full bg-[#fff8ce] text-[#0a0f1e] text-[11px] font-bold ms-auto shrink-0">
                  <i className="ri-time-line text-[12px]" />
                  {t("landing.interest.replyBadge")}
                </span>
              </div>

              {sent ? (
                <p className="text-center py-16 text-[15px] text-[#f2d42d] font-semibold">{t("landing.interest.success")}</p>
              ) : (
                <>
                  <div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
                    <Field label={t("landing.interest.name")}>
                      <input
                        required
                        value={form.name}
                        onChange={(e) => setForm({ ...form, name: e.target.value })}
                        placeholder={t("landing.interest.namePh")}
                        className={fieldCls}
                      />
                    </Field>
                    <Field label={t("landing.interest.email")}>
                      <input
                        required
                        type="email"
                        value={form.email}
                        onChange={(e) => setForm({ ...form, email: e.target.value })}
                        placeholder={t("landing.interest.emailPh")}
                        className={fieldCls}
                      />
                    </Field>
                    <Field label={t("landing.interest.phone")}>
                      <input
                        required
                        value={form.phone}
                        onChange={(e) => setForm({ ...form, phone: e.target.value })}
                        placeholder={t("landing.interest.phonePh")}
                        className={fieldCls}
                      />
                    </Field>
                    <Field label={t("landing.interest.entity")}>
                      <input
                        value={form.entity}
                        onChange={(e) => setForm({ ...form, entity: e.target.value })}
                        placeholder={t("landing.interest.entityPh")}
                        className={fieldCls}
                      />
                    </Field>
                    <Field label={t("landing.interest.kind")}>
                      <FancySelect
                        required
                        value={form.interest}
                        placeholder={t("landing.interest.kindPh")}
                        options={kinds}
                        onChange={(v) => setForm({ ...form, interest: v })}
                      />
                    </Field>
                    <Field label={t("landing.interest.sector")}>
                      <FancySelect
                        value={form.sector}
                        placeholder={t("landing.interest.sectorPh")}
                        options={sectors}
                        onChange={(v) => setForm({ ...form, sector: v })}
                      />
                    </Field>
                  </div>
                  <Field label={t("landing.interest.message")} className="mt-4">
                    <textarea
                      maxLength={500}
                      rows={4}
                      value={message}
                      onChange={(e) => setMessage(e.target.value)}
                      placeholder={t("landing.interest.messagePh")}
                      className={`${fieldCls} h-[117px] py-3 resize-none`}
                    />
                    <span className="block text-[11px] mt-1 text-start">{message.length}/500</span>
                  </Field>
                  <div className="mt-5 flex flex-col sm:flex-row sm:items-center gap-3">
                    <button
                      type="submit"
                      className="h-12 px-6 rounded-[14px] bg-[#f2d42d] text-[#0a0f1e] text-[14.5px] font-semibold flex items-center justify-center gap-2 cursor-pointer shrink-0 w-full sm:w-auto"
                    >
                      <img src="/landing/icons/send.svg" alt="" width={15.1803} height={15.1503} />
                      {t("landing.interest.submit")}
                    </button>
                    <p className="text-[11.5px] text-white/90 text-start">{t("landing.interest.consent")}</p>
                  </div>
                </>
              )}
            </form>
          </div>
        </Wrap>
      </section>

      <section className="bg-[#141e36] py-12 lg:py-16">
        <Wrap>
          <div className="flex flex-col sm:flex-row gap-4 sm:gap-8">
            <div className="text-start">
              <p className="text-[12px] font-bold tracking-[1.68px] text-[#f2d42d]">{t("landing.contact.eyebrow")}</p>
              <h2 className="mt-2 text-[26px] sm:text-[32px] font-bold leading-tight sm:leading-12">{t("landing.contact.title")}</h2>
            </div>
            <p className="flex items-center gap-1.5 text-[12.5px] text-[#adadad]">
              <i className="ri-map-pin-line text-[#f2d42d]" />
              {t("landing.contact.city")}
            </p>
          </div>
          <div className="mt-7 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-5">
            {(
              [
                { label: "landing.contact.email", value: t("landing.contact.emailValue"), href: "mailto:info@dshn.sa", icon: "ri-mail-line" },
                { label: "landing.contact.phone", value: t("landing.contact.phoneValue"), href: "tel:0560609896", icon: "ri-phone-line" },
                { label: "landing.contact.web", value: t("landing.contact.webValue"), href: "https://www.dshn.sa", icon: "ri-global-line" },
              ] as const
            ).map((c) => (
              <a
                key={c.label}
                href={c.href}
                onClick={blockLink}
                className="h-[90px] rounded-[20px] bg-[#1b2744] border border-[#3a4b73] px-[21px] flex items-center gap-4"
              >
                <span className="size-12 rounded-[14px] text-[#f2d42d] flex items-center justify-center shrink-0">
                  <i className={`${c.icon} text-[20px]`} />
                </span>
                <span className="text-start">
                  <span className="block text-[11.5px] text-[#adadad]">{t(c.label)}</span>
                  <span className="block text-[14px] font-bold">{c.value}</span>
                </span>
              </a>
            ))}
          </div>
        </Wrap>
      </section>

      <footer className="bg-[#010102] border-t-[3px] border-[#f2d42d]">
        <div className="max-w-[1280px] mx-auto px-4 sm:px-6 lg:px-8 py-12">
          <div className="flex flex-col lg:flex-row gap-10 lg:gap-8">
            <div className="max-w-[448px] text-start">
              <LogoMark variant="footer" />
              <p className="mt-2 text-[13.5px] text-[#f7f7f4]/70">{t("landing.footer.blurb")}</p>
              <div className="mt-5 flex items-center gap-2">
                {(
                  [
                    ["ri-whatsapp-line", "landing.footer.socialWhatsapp"],
                    ["ri-linkedin-line", "landing.footer.socialLinkedin"],
                    ["ri-instagram-line", "landing.footer.socialInstagram"],
                    ["ri-twitter-x-line", "landing.footer.socialX"],
                  ] as const
                ).map(([ic, label]) => (
                  <a
                    key={ic}
                    href="#"
                    onClick={(e) => e.preventDefault()}
                    className="size-9 rounded-full bg-[#0a0f1e]/10 flex items-center justify-center"
                    aria-label={t(label)}
                  >
                    <i className={`${ic} text-[17px]`} />
                  </a>
                ))}
              </div>
            </div>
            <div className="w-[280px] text-start">
              <h4 className="text-[14px] font-bold mb-3">{t("landing.footer.links")}</h4>
              <ul className="space-y-2 text-[13.5px] text-[#f7f7f4]/70">
                <li>
                  <button type="button" onClick={() => scrollTo("top")} className="cursor-pointer">
                    {t("landing.nav.home")}
                  </button>
                </li>
                <li>
                  <button type="button" onClick={() => run(() => jump("businesses"))} className="cursor-pointer">
                    {t("landing.nav.businesses")}
                  </button>
                </li>
                <li>
                  <button type="button" onClick={() => run(() => jump("products"))} className="cursor-pointer">
                    {t("landing.nav.products")}
                  </button>
                </li>
                <li>
                  <button type="button" onClick={() => run(() => jump("opportunities"))} className="cursor-pointer">
                    {t("landing.nav.opportunities")}
                  </button>
                </li>
              </ul>
            </div>
            <div className="w-[280px] text-start">
              <h4 className="text-[14px] font-bold mb-3">{t("landing.footer.contact")}</h4>
              <ul className="space-y-2.5 text-[13.5px] text-[#f7f7f4]/70">
                <li className="flex items-center gap-2">
                  <i className="ri-phone-line" />
                  <span>{t("landing.contact.phoneValue")}</span>
                </li>
                <li className="flex items-center gap-2">
                  <i className="ri-mail-line" />
                  <span>{t("landing.contact.emailValue")}</span>
                </li>
                <li className="flex items-center gap-2">
                  <i className="ri-map-pin-line" />
                  {t("landing.footer.address")}
                </li>
              </ul>
            </div>
          </div>
          <div className="mt-10 pt-6 border-t border-[#243352]/15 flex flex-col sm:flex-row sm:items-center gap-3 text-[12.5px] text-[#f7f7f4]/60">
            <span className="flex items-center gap-2">
              <i className="ri-global-line" />
              {t("landing.footer.locale")}
            </span>
            <span>{t("landing.footer.copy")}</span>
          </div>
        </div>
      </footer>

      {videoOpen && (
        <div className="fixed inset-0 z-[80] bg-black/80 flex items-center justify-center p-6" onClick={() => setVideoOpen(false)}>
          <div className="w-full max-w-[860px] aspect-video bg-black rounded-2xl overflow-hidden relative" onClick={(e) => e.stopPropagation()}>
            <button
              type="button"
              onClick={() => setVideoOpen(false)}
              className="absolute top-3 start-3 z-10 size-10 rounded-full bg-white/15 text-white cursor-pointer"
              aria-label={t("landing.video.close")}
            >
              <i className="ri-close-line text-[22px]" />
            </button>
            <div
              className="w-full h-full flex flex-col items-center justify-center gap-3"
              style={{ backgroundImage: "linear-gradient(136deg, #213f63 13%, #111e36 47%, #090e1c 80%)" }}
            >
              <span className="size-20 rounded-full bg-[#141e36] flex items-center justify-center">
                <i className="ri-play-fill text-[36px]" />
              </span>
              <p className="text-[14px] font-semibold">{t("landing.video.modalTitle")}</p>
              <p className="text-[12px] text-white/60">{t("landing.video.duration")}</p>
            </div>
          </div>
        </div>
      )}
    </div>
  );
}

const fieldCls =
  "w-full h-12 px-[15px] rounded-[12px] bg-[#141e36] border border-[#3a4b73] text-[14px] font-body text-white placeholder:text-white/70 outline-none text-start";

function Field({ label, children, className = "" }: { label: string; children: ReactNode; className?: string }) {
  return (
    <div className={`block text-start ${className}`}>
      <span className="block mb-1.5 text-[12.5px] font-semibold">{label}</span>
      {children}
    </div>
  );
}

function FancySelect({
  value,
  options,
  placeholder,
  onChange,
  required,
}: {
  value: string;
  options: string[];
  placeholder: string;
  onChange: (value: string) => void;
  required?: boolean;
}) {
  const [open, setOpen] = useState(false);
  const rootRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    const onDoc = (e: MouseEvent) => {
      if (!rootRef.current?.contains(e.target as Node)) setOpen(false);
    };
    document.addEventListener("mousedown", onDoc);
    return () => document.removeEventListener("mousedown", onDoc);
  }, []);

  return (
    <div ref={rootRef} className="relative">
      {required && (
        <input className="sr-only" tabIndex={-1} required aria-hidden="true" value={value} onChange={() => undefined} />
      )}
      <button
        type="button"
        onClick={() => setOpen((v) => !v)}
        className={`${fieldCls} flex items-center pe-10 ${open ? "border-[#f2d42d] shadow-[0_0_0_3px_rgba(242,212,45,0.15)]" : ""}`}
        aria-expanded={open}
      >
        <span className={`truncate ${value ? "text-white" : "text-white/70"}`}>{value || placeholder}</span>
      </button>
      <img
        src="/landing/icons/chevron.svg"
        alt=""
        width={10}
        height={10}
        className={`pointer-events-none absolute top-1/2 end-[15px] -translate-y-1/2 ${open ? "rotate-180" : ""}`}
      />
      {open && (
        <ul className="absolute z-20 mt-1.5 w-full max-h-56 overflow-auto rounded-[12px] border border-[#3a4b73] bg-[#0a0f1e] py-1.5 shadow-[0px_12px_32px_-8px_rgba(0,0,0,0.45)]">
          {options.map((o) => {
            const active = o === value;
            return (
              <li key={o}>
                <button
                  type="button"
                  onClick={() => {
                    onChange(o);
                    setOpen(false);
                  }}
                  className={`w-full px-[15px] py-2.5 text-start text-[14px] leading-[21px] cursor-pointer ${
                    active ? "bg-[#1b2744] text-[#f2d42d] font-semibold" : "text-white/90 hover:bg-[#1b2744] hover:text-white"
                  }`}
                >
                  {o}
                </button>
              </li>
            );
          })}
        </ul>
      )}
    </div>
  );
}
