import Link from "next/link";
import { LocalizedText } from "@/components/localized-text";
import type { TranslationKey } from "@/lib/i18n";
import type { LucideIcon } from "lucide-react";
import {
  BookOpenText,
  Compass,
  ExternalLink,
  FileText,
  Home,
  Info,
  LogIn,
  Mail,
  Map,
  ShieldCheck,
  UserPlus,
  Users,
} from "lucide-react";

type SitemapLink = {
  label: TranslationKey;
  href: string;
  icon?: LucideIcon;
  isExternal?: boolean;
};

const sitemapGroups: Array<{
  title: TranslationKey;
  icon: LucideIcon;
  links: SitemapLink[];
}> = [
  {
    title: "sitemap.discover",
    icon: Compass,
    links: [
      { label: "common.findGuides", href: "/guides", icon: Users },
      { label: "sitemap.blogs", href: "/blogs", icon: BookOpenText },
      { label: "common.aboutUs", href: "/#about-us", icon: Info },
    ],
  },
  {
    title: "sitemap.guideServices",
    icon: Users,
    links: [
      {
        label: "sitemap.charDhamGuides",
        href: "/guides?expertise=Char+Dham+Pilgrimage",
      },
      {
        label: "sitemap.adventureGuides",
        href: "/guides?expertise=Adventure+Tourism",
      },
      {
        label: "sitemap.wildlifeGuides",
        href: "/guides?expertise=Wildlife+Safari",
      },
      {
        label: "sitemap.culturalGuides",
        href: "/guides?expertise=Cultural+Heritage",
      },
    ],
  },
  {
    title: "sitemap.account",
    icon: ShieldCheck,
    links: [
      { label: "common.signIn", href: "/auth/login", icon: LogIn },
      {
        label: "common.registerAsGuide",
        href: "/auth/register",
        icon: UserPlus,
      },
    ],
  },
  {
    title: "sitemap.officialLinks",
    icon: ExternalLink,
    links: [
      {
        label: "common.contactUs",
        href: "https://uttarakhandtourism.gov.in/page/contact-us",
        icon: Mail,
        isExternal: true,
      },
      {
        label: "common.policyGuidelines",
        href: "https://uttarakhandtourism.gov.in/page/policy-and-guidelines",
        icon: FileText,
        isExternal: true,
      },
    ],
  },
];

export default function SitemapPage() {
  return (
    <main className="min-h-screen bg-[var(--theme-surface)] px-4 pb-14 pt-28 sm:px-6 lg:px-8">
      <div className="mx-auto max-w-7xl">
        <div className="mb-10 text-center">
          <div className="mb-4 inline-flex items-center gap-2 rounded-full border border-[var(--theme-secondary)]/25 bg-white px-4 py-2 text-sm font-bold text-[var(--theme-primary)] shadow-sm">
            <Map className="h-4 w-4" />
            <LocalizedText textKey="sitemap.websiteSitemap" />
          </div>
          <h1 className="text-3xl font-black tracking-tight text-foreground sm:text-4xl">
            <LocalizedText textKey="sitemap.exploreStructure" />
          </h1>
          <p className="mx-auto mt-3 max-w-2xl text-sm leading-6 text-muted-foreground sm:text-base">
            <LocalizedText textKey="sitemap.description" />
          </p>
          <Link
            href="/sitemap.xml"
            target="_blank"
            className="mt-5 inline-flex h-11 items-center justify-center gap-2 rounded-full border border-[var(--theme-secondary)]/30 bg-white px-5 text-sm font-black text-[var(--theme-primary)] shadow-sm transition-all hover:-translate-y-0.5 hover:border-[var(--theme-secondary)]/55 hover:bg-[var(--theme-surface)]"
          >
            <FileText className="h-4 w-4" />
            <LocalizedText textKey="sitemap.viewXml" />
          </Link>
        </div>

        <section className="relative mb-28 overflow-hidden rounded-[28px] border border-[var(--theme-border)] bg-white px-4 py-10 shadow-xl shadow-[var(--theme-secondary)]/10 sm:px-6 lg:px-10">
          <div className="pointer-events-none absolute left-0 top-0 h-32 w-56 rounded-br-full bg-[var(--theme-surface-strong)]" />
          <div className="pointer-events-none absolute bottom-0 right-0 h-40 w-64 rounded-tl-full bg-[var(--theme-secondary)]/10" />

          <div className="relative mx-auto flex max-w-6xl flex-col items-center">
            <Link
              href="/"
              className="group z-10 flex min-h-16 min-w-40 items-center justify-center gap-2 rounded-lg bg-gradient-to-r from-[var(--theme-secondary)] to-[var(--theme-accent)] px-6 py-4 text-sm font-black uppercase tracking-wide text-white shadow-lg shadow-[var(--theme-secondary)]/25 transition-all hover:-translate-y-1 hover:shadow-xl"
            >
              <Home className="h-4 w-4 transition-transform group-hover:scale-110" />
              <LocalizedText textKey="sitemap.homepage" />
            </Link>

            <div className="h-10 w-px bg-[var(--theme-primary)]" />
            <div className="hidden h-px w-[82%] bg-[var(--theme-primary)] lg:block" />

            <div className="grid w-full gap-8 pt-8 sm:grid-cols-2 lg:grid-cols-4 lg:gap-10">
              {sitemapGroups.map((group) => (
                <div
                  key={group.title}
                  className="relative flex flex-col items-center"
                >
                  <div className="absolute -top-8 hidden h-8 w-px bg-[var(--theme-primary)] lg:block" />
                  <div className="w-full">
                    <div className="mb-5 flex min-h-14 items-center justify-center gap-2 rounded-lg border border-[var(--theme-border-strong)] bg-[var(--theme-surface-strong)] px-4 py-3 text-center text-sm font-black uppercase tracking-wide text-[var(--theme-emphasis-text)] shadow-md shadow-[var(--theme-secondary)]/10">
                      <group.icon className="h-4 w-4" />
                      <LocalizedText textKey={group.title} />
                    </div>

                    <div className="mx-auto mb-3 h-6 w-px bg-[var(--theme-primary)]/70" />
                    <div className="space-y-3">
                      {group.links.map((link) => {
                        const Icon = link.icon;
                        const className =
                          "group flex min-h-12 items-center justify-between gap-3 rounded-lg border border-[var(--theme-border)] bg-white px-4 py-3 text-sm font-bold text-foreground shadow-sm transition-all hover:-translate-y-0.5 hover:border-[var(--theme-secondary)]/45 hover:bg-[var(--theme-surface)] hover:text-[var(--theme-primary)] hover:shadow-md";
                        const content = (
                          <>
                            <span className="flex min-w-0 items-center gap-2">
                              {Icon && <Icon className="h-4 w-4 shrink-0" />}
                              <span className="truncate">
                                <LocalizedText textKey={link.label} />
                              </span>
                            </span>
                            {link.isExternal && (
                              <ExternalLink className="h-3.5 w-3.5 shrink-0 opacity-70" />
                            )}
                          </>
                        );

                        return link.isExternal ? (
                          <a
                            key={link.label}
                            href={link.href}
                            target="_blank"
                            rel="noopener noreferrer"
                            className={className}
                          >
                            {content}
                          </a>
                        ) : (
                          <Link
                            key={link.label}
                            href={link.href}
                            className={className}
                          >
                            {content}
                          </Link>
                        );
                      })}
                    </div>
                  </div>
                </div>
              ))}
            </div>
          </div>
        </section>
      </div>
    </main>
  );
}
