"use client";

import { useEffect } from "react";
import { Logo } from "./components/ui/Logo";
import { ButtonLink } from "./components/ui/ButtonLink";

export default function Error({
  error,
  reset,
}: {
  error: Error & { digest?: string };
  reset: () => void;
}) {
  useEffect(() => {
    console.error("[app error]", error);
  }, [error]);

  return (
    <div className="relative min-h-screen flex items-center justify-center px-6 lg:px-10 overflow-hidden isolate">
      <div
        aria-hidden
        className="absolute inset-0 z-0"
        style={{
          background:
            "radial-gradient(ellipse at 50% 60%, rgba(196,184,150,0.08) 0%, rgba(10,10,10,0) 60%)",
        }}
      />
      <div
        aria-hidden
        className="animate-orb-pulse absolute left-1/2 top-1/2 z-0 w-[500px] h-[500px] sm:w-[700px] sm:h-[700px] rounded-full pointer-events-none"
        style={{
          background:
            "radial-gradient(circle, rgba(196,184,150,0.35) 0%, rgba(196,184,150,0.15) 30%, rgba(196,184,150,0) 70%)",
          filter: "blur(80px)",
        }}
      />

      <div className="relative z-10 max-w-2xl w-full text-center pt-24 pb-12">
        <Logo width={120} className="mx-auto mb-10 opacity-40" />

        <p className="font-display text-sm tracking-[0.3em] text-accent mb-4">
          ERROR
        </p>
        <h1 className="font-display text-4xl sm:text-6xl lg:text-7xl tracking-wider leading-[0.95] mb-8">
          AVALANCHE
          <br />
          ON THE PATH.
        </h1>
        <p className="text-lg text-foreground-muted leading-relaxed max-w-xl mx-auto mb-4">
          Something went wrong on our side. Try again, or head back to base
          camp.
        </p>
        {error.digest && (
          <p className="text-xs tracking-widest text-foreground-muted mb-12 uppercase">
            Ref: {error.digest}
          </p>
        )}

        <div className="mt-8 flex flex-col items-center gap-4 sm:flex-row sm:justify-center">
          <button
            type="button"
            onClick={reset}
            className="sheen relative w-full overflow-hidden bg-accent px-8 py-3 font-display text-sm tracking-widest text-background transition duration-200 ease-out hover:-translate-y-0.5 hover:bg-foreground hover:shadow-[0_14px_30px_-14px_rgba(196,184,150,0.6)] active:scale-[0.97] sm:w-auto"
          >
            TRY AGAIN
          </button>
          <ButtonLink href="/" variant="outline" block>
            BACK TO BASE CAMP
          </ButtonLink>
        </div>
      </div>
    </div>
  );
}
