import type { Metadata } from "next";
import ZidIntegrationPageContent from "@/components/integrations/ZidIntegrationPageContent";
import {
  buildStaticPageMetadata,
  localizedUrl,
  resolveSeoLang,
  type SeoLang,
} from "@/lib/seo";

type Props = { searchParams: Promise<{ lang?: string }> };

export async function generateMetadata({ searchParams }: Props): Promise<Metadata> {
  return buildStaticPageMetadata({
    path: "/integrations/zid",
    searchParams,
    descriptionFallback: {
      ar: "اربط متجر زد مع واتساب بزنس والذكاء الاصطناعي — أتمتة العروض، متابعة الطلبات، واسترجاع العملاء.",
      en: "Connect Zid stores to WhatsApp Business AI — offer automation, order updates, and win-back campaigns.",
    },
    keywords: [
      "zid ai",
      "أتمتة العروض زد",
      "ربط زد واتساب",
      "Zid WhatsApp Business automation",
    ],
  });
}

function buildZidJsonLd(lang: SeoLang) {
  const pageUrl = localizedUrl("/integrations/zid", lang);
  return {
    "@context": "https://schema.org",
    "@type": "TechArticle",
    "@id": `${pageUrl}#article`,
    headline:
      lang === "ar"
        ? "ربط زد بالذكاء الاصطناعي وواتساب"
        : "Connect Zid with WhatsApp Business and AI automation",
    description:
      lang === "ar"
        ? "دليل لأتمتة دعم متاجر زد والعروض ومتابعة الطلبات وحملات واتساب مع سكاي لايت شات."
        : "A guide to automating Zid store support, offers, order follow-ups, and WhatsApp campaigns with SkyLight Chat.",
    inLanguage: lang === "ar" ? "ar-SA" : "en-US",
    author: {
      "@type": "Organization",
      name: "SkyLight Chat",
      url: localizedUrl("/", lang),
    },
    publisher: {
      "@type": "Organization",
      name: "SkyLight Chat",
      url: localizedUrl("/", lang),
    },
    mainEntityOfPage: pageUrl,
  };
}

export default async function ZidIntegrationPage({ searchParams }: Props) {
  const lang = await resolveSeoLang(await searchParams);
  const zidJsonLd = buildZidJsonLd(lang);

  return (
    <>
      <script
        type="application/ld+json"
        dangerouslySetInnerHTML={{ __html: JSON.stringify(zidJsonLd) }}
      />
      <ZidIntegrationPageContent />
    </>
  );
}
