"use client";

import { useEffect } from "react";
import Link from "next/link";

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

  return (
    <div className="flex min-h-screen flex-col items-center justify-center gap-6 px-4 text-center">
      <div className="select-none text-8xl font-black tracking-tighter text-white/10 sm:text-9xl">
        500
      </div>
      <h1 className="text-3xl font-black text-white sm:text-4xl">System Malfunction</h1>
      <p className="max-w-md text-gray-400">
        Something went wrong in the Triviaverse engine. The hyperdrive might need a reboot.
      </p>
      <div className="flex flex-wrap justify-center gap-3">
        <button
          onClick={reset}
          className="inline-flex items-center gap-2 rounded-xl bg-magenta px-6 py-3 text-sm font-bold text-white transition-colors hover:bg-[#d81b60]"
        >
          Try Again
        </button>
        <Link
          href="/"
          className="inline-flex items-center gap-2 rounded-xl border border-white/20 px-6 py-3 text-sm font-bold text-white transition-colors hover:bg-white/10"
        >
          Back to Triviaverse
        </Link>
      </div>
      {error.digest && (
        <p className="text-xs text-gray-600">Error ID: {error.digest}</p>
      )}
      {/* Decorative blobs */}
      <div
        aria-hidden="true"
        className="pointer-events-none fixed left-0 top-0 z-[-1] h-[400px] w-[400px] -translate-x-1/2 -translate-y-1/2 rounded-full bg-magenta opacity-10 mix-blend-screen blur-[120px]"
      />
      <div
        aria-hidden="true"
        className="pointer-events-none fixed bottom-0 right-0 z-[-1] h-[500px] w-[500px] translate-x-1/3 translate-y-1/3 rounded-full bg-gold opacity-10 mix-blend-screen blur-[150px]"
      />
    </div>
  );
}
