import Link from "next/link";
import { SERVICES, LOCATIONS, type Lang } from "@/lib/config";
import type { Metadata } from "next";
import { buildPageMetadata } from "@/lib/seo";

export function generateMetadata({
  params,
}: {
  params: { lang: Lang };
}): Metadata {
  return buildPageMetadata({
    lang: params.lang,
    title: params.lang === "ar" ? "خريطة الموقع | موعدي" : "Site Map | Mawidi",
    description:
      params.lang === "ar"
        ? "نظرة شاملة على جميع صفحات موقع موعدي: الخدمات، المواقع، الموارد، والمزيد"
        : "Complete overview of all pages on Mawidi.com including services, locations, resources, and more",
    path: "/sitemap",
  });
}

export default function SitemapPage({ params }: { params: { lang: Lang } }) {
  const { lang } = params;
  const isAr = lang === "ar";

  const sections = [
    {
      titleEn: "Main Pages",
      titleAr: "الصفحات الرئيسية",
      links: [
        { href: `/${lang}`, labelEn: "Home", labelAr: "الرئيسية" },
        { href: `/${lang}/about`, labelEn: "About Us", labelAr: "من نحن" },
        { href: `/${lang}/pricing`, labelEn: "Pricing", labelAr: "الأسعار" },
        { href: `/${lang}/contact`, labelEn: "Contact", labelAr: "تواصل معنا" },
        { href: `/${lang}/blog`, labelEn: "Blog", labelAr: "المدونة" },
        { href: `/${lang}/careers`, labelEn: "Careers", labelAr: "وظائف" },
      ],
    },
    {
      titleEn: "Services",
      titleAr: "الخدمات",
      links: Object.values(SERVICES).map((s) => ({
        href: `/${lang}/services/${s.slug[lang]}`,
        labelEn: s.name.en,
        labelAr: s.name.ar,
      })),
    },
    {
      titleEn: "Locations",
      titleAr: "المناطق",
      links: Object.values(LOCATIONS).map((l) => ({
        href: `/${lang}/locations/${l.slug[lang]}`,
        labelEn: l.name.en,
        labelAr: l.name.ar,
      })),
    },
    {
      titleEn: "Resources",
      titleAr: "الموارد",
      links: [
        {
          href: `/${lang}/tools/roi-calculator`,
          labelEn: "Free ROI Calculator",
          labelAr: "حاسبة العائد المجاني",
        },
        {
          href: `/${lang}/why-automation`,
          labelEn: "Why Automation?",
          labelAr: "لماذا الأتمتة؟",
        },
        {
          href: `/${lang}/comparison`,
          labelEn: "Compare vs Receptionist",
          labelAr: "مقارنة مع الاستقبال التقليدي",
        },
        {
          href: `/${lang}/demo/instant`,
          labelEn: "WhatsApp Demo",
          labelAr: "عرض واتساب التجريبي",
        },
        {
          href: `/${lang}/integrations`,
          labelEn: "Integrations",
          labelAr: "التكاملات",
        },
        {
          href: `/${lang}/glossary`,
          labelEn: "Glossary",
          labelAr: "المصطلحات",
        },
        {
          href: `/${lang}/partners`,
          labelEn: "Partner Program",
          labelAr: "برنامج الشركاء",
        },
      ],
    },
    {
      titleEn: "Compare",
      titleAr: "مقارنات",
      links: [
        {
          href: `/${lang}/compare/mawidi-vs-calendly`,
          labelEn: "Mawidi vs Calendly",
          labelAr: "موعدي مقابل Calendly",
        },
        {
          href: `/${lang}/compare/mawidi-vs-fresha`,
          labelEn: "Mawidi vs Fresha",
          labelAr: "موعدي مقابل Fresha",
        },
        {
          href: `/${lang}/compare/mawidi-vs-acuity`,
          labelEn: "Mawidi vs Acuity Scheduling",
          labelAr: "موعدي مقابل Acuity",
        },
        {
          href: `/${lang}/compare/mawidi-vs-setmore`,
          labelEn: "Mawidi vs Setmore",
          labelAr: "موعدي مقابل Setmore",
        },
        {
          href: `/${lang}/compare/mawidi-vs-zocdoc`,
          labelEn: "Mawidi vs ZocDoc",
          labelAr: "موعدي مقابل ZocDoc",
        },
      ],
    },
    {
      titleEn: "Legal",
      titleAr: "قانوني",
      links: [
        {
          href: `/${lang}/privacy`,
          labelEn: "Privacy Policy",
          labelAr: "سياسة الخصوصية",
        },
        {
          href: `/${lang}/terms`,
          labelEn: "Terms of Service",
          labelAr: "شروط الخدمة",
        },
      ],
    },
  ];

  return (
    <div className="bg-white py-16 dark:bg-slate-950">
      <div className="mx-auto max-w-4xl px-6">
        <h1 className="mb-10 text-4xl font-bold text-slate-900 dark:text-white">
          {isAr ? "خريطة الموقع" : "Sitemap"}
        </h1>

        <div className="grid gap-10 md:grid-cols-2">
          {sections.map((section) => (
            <section
              key={section.titleEn}
              className="rounded-2xl border border-slate-100 p-8 shadow-sm dark:border-slate-800 dark:bg-slate-900/50"
            >
              <h2 className="mb-6 text-xl font-bold text-brand-green">
                {isAr ? section.titleAr : section.titleEn}
              </h2>
              <ul className="space-y-3">
                {section.links.map((link) => (
                  <li key={link.href}>
                    <Link
                      href={link.href}
                      className="text-slate-600 hover:text-brand-green hover:underline dark:text-slate-300"
                    >
                      {isAr ? link.labelAr : link.labelEn}
                    </Link>
                  </li>
                ))}
              </ul>
            </section>
          ))}
        </div>
      </div>
    </div>
  );
}
