import type { Metadata } from "next";
import { CheckCircle2 } from "lucide-react";
import Link from "next/link";
import { getTranslations } from "next-intl/server";

import { Container } from "@/components/layout/container";
import { MotionFade } from "@/components/motion-fade";
import { HeroShell, HeroTitle } from "@/components/layout/site-hero";
import { buildLocalizedMetadata } from "@/lib/metadata";
import { getLocalizedPath, resolveLocale } from "@/lib/locale";
import { AppCard } from "@/components/ui/app-card";
import { Button } from "@/components/ui/button";
import { CardContent } from "@/components/ui/card";

type SuccessPageProps = {
  params: {
    locale: string;
  };
};

export async function generateMetadata({
  params: { locale },
}: SuccessPageProps): Promise<Metadata> {
  const localeKey = resolveLocale(locale);
  const t = await getTranslations({ locale: localeKey, namespace: "successPage" });

  return await buildLocalizedMetadata({
    locale: localeKey,
    pathname: "/success",
    title: t("title"),
    description: t("text"),
  });
}

export default async function SuccessPage({ params: { locale } }: SuccessPageProps) {
  const localeKey = resolveLocale(locale);
  const t = await getTranslations({ locale: localeKey, namespace: "successPage" });

  return (
    <>
      <HeroShell compactBackdrop size="narrow" variant="page">
        <MotionFade className="w-full">
          <div className="mx-auto flex max-w-[42rem] flex-col items-center">
            <CheckCircle2 className="h-14 w-14 text-status-success" />
            <p className="mt-5 text-sm font-medium tracking-[0.12em] text-foreground/56">
              {t("title")}
            </p>
            <HeroTitle lines={[{ text: t("title") }]} variant="page" />
            <p className="mx-auto mt-5 max-w-[32rem] text-sm leading-7 text-foreground/64 sm:text-base">
              {t("text")}
            </p>
            <div className="mt-8 flex flex-wrap items-center justify-center gap-3">
              <Button asChild>
                <Link href={getLocalizedPath(localeKey)}>{t("home")}</Link>
              </Button>
              <Button asChild variant="outline">
                <Link href={getLocalizedPath(localeKey, "/contact")}>{t("contact")}</Link>
              </Button>
            </div>
          </div>
        </MotionFade>
      </HeroShell>

      <Container size="narrow" className="pb-12 lg:pb-16">
        <MotionFade className="w-full" delay={0.06}>
        <AppCard level={3}>
          <CardContent className="p-8 text-center">
            <p className="mx-auto max-w-2xl text-base text-muted-foreground">
              {t("text")}
            </p>
          </CardContent>
        </AppCard>
        </MotionFade>
      </Container>
    </>
  );
}
