import Link from "next/link";
import { cn } from "cn";
import type { Locale } from "@/i18n/config";
import type { Dictionary } from "@/i18n/load-dictionary";
import { routes } from "@/lib/routes";
import { RetryIcon } from "@/components/icons";
import { ctaBannerActionClass } from "@/components/shared/cta-banner";
import { outlinePillClass } from "@/components/shared/form-footer";
import { HeroHeadline } from "@/components/shared/hero-headline";
import { PageHeroBackground } from "@/components/shared/page-hero-background";
import { buttonVariants } from "@/components/ui/button";

type ErrorSectionProps = { locale: Locale; t: Dictionary["errorPage"]; backgroundAlt: string; onRetry: () => void };

/**
 * "Something went wrong" (no Figma design): the Not Found page's look — Riyadh at night, the two-line headline,
 * a short text — centered, since there is no illustration for it. "Try Again" re-renders the part that failed.
 */
export function ErrorSection({ locale, t, backgroundAlt, onRetry }: ErrorSectionProps) {
  return (
    <section className="relative isolate flex min-h-svh items-center overflow-hidden pt-[100px] pb-10 lg:min-h-[942px] lg:py-32">
      <PageHeroBackground alt={backgroundAlt} className="h-full" />
      <div className="container-site">
        <div className="mx-auto flex max-w-3xl flex-col items-center gap-7 text-center">
          <HeroHeadline start={t.titleStart} highlight={t.titleHighlight} className="items-center" />
          <p className="max-w-lg font-heading text-xs leading-5 text-soft lg:text-lg lg:leading-[29.25px]">{t.description}</p>
          <div className="flex flex-wrap items-center justify-center gap-4">
            <button type="button" onClick={onRetry} className={ctaBannerActionClass}>
              {t.retry}
              <RetryIcon data-icon="inline-end" className="size-[18px] shrink-0" />
            </button>
            <Link href={routes.home(locale)} className={cn(buttonVariants({ variant: "outline" }), outlinePillClass, "max-lg:py-2.5 max-lg:text-sm lg:h-[54px]")}>
              {t.home}
            </Link>
          </div>
        </div>
      </div>
    </section>
  );
}
