'use client';

import { useEffect } from 'react';
import { AlertTriangle, RotateCcw, Home } from 'lucide-react';

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

  return (
    <div className="flex items-center justify-center min-h-[60vh] p-6">
      <div className="max-w-md w-full text-center space-y-6">
        {/* Icon */}
        <div className="mx-auto w-16 h-16 rounded-2xl bg-red-50 border border-red-100 flex items-center justify-center">
          <AlertTriangle className="w-8 h-8 text-red-500" />
        </div>

        {/* Message */}
        <div className="space-y-2">
          <h2 className="text-xl font-semibold text-brand-700">
            Terjadi Kesalahan
          </h2>
          <p className="text-sm text-brand-400 leading-relaxed">
            Maaf, terjadi kesalahan saat memuat halaman ini.
            Silakan coba lagi atau kembali ke beranda.
          </p>
          {process.env.NODE_ENV === 'development' && error.message && (
            <div className="mt-3 p-3 rounded-lg bg-red-50 border border-red-100 text-left">
              <p className="text-xs font-mono text-red-600 break-all">
                {error.message}
              </p>
              {error.digest && (
                <p className="text-xs font-mono text-red-400 mt-1">
                  Digest: {error.digest}
                </p>
              )}
            </div>
          )}
        </div>

        {/* Actions */}
        <div className="flex items-center justify-center gap-3">
          <button
            onClick={() => reset()}
            className="inline-flex items-center gap-2 px-5 py-2.5 rounded-[0.625rem] bg-brand-700 text-white text-sm font-medium hover:bg-brand-800 transition-colors focus:outline-none focus:ring-2 focus:ring-brand-400 focus:ring-offset-2"
          >
            <RotateCcw className="w-4 h-4" />
            Coba Lagi
          </button>
          <a
            href="/"
            className="inline-flex items-center gap-2 px-5 py-2.5 rounded-[0.625rem] border border-border bg-white text-brand-600 text-sm font-medium hover:bg-surface transition-colors focus:outline-none focus:ring-2 focus:ring-brand-400 focus:ring-offset-2"
          >
            <Home className="w-4 h-4" />
            Beranda
          </a>
        </div>
      </div>
    </div>
  );
}
