'use client';

import { useEffect } from 'react';
import Link from 'next/link';
import { AlertTriangle, RefreshCw, Home } from 'lucide-react';

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

  return (
    <div className="min-h-screen bg-beauty-light flex items-center justify-center px-6">
      <div className="max-w-md w-full text-center">
        {/* Error Icon */}
        <div className="w-20 h-20 bg-red-50 rounded-full flex items-center justify-center mx-auto mb-6">
          <AlertTriangle className="w-10 h-10 text-red-500" />
        </div>

        <h1 className="text-3xl font-extrabold text-beauty-dark mb-3">Something went wrong</h1>
        <p className="text-beauty-muted mb-2">
          We encountered an unexpected error while loading this page.
        </p>

        {error.digest && (
          <p className="text-xs text-gray-400 mb-8 font-mono">
            Error ID: {error.digest}
          </p>
        )}

        <div className="flex flex-col sm:flex-row gap-3 justify-center">
          <button
            onClick={reset}
            className="inline-flex items-center justify-center gap-2 px-6 py-3 bg-primary-400 text-white font-semibold rounded-full hover:bg-primary-500 transition-all"
          >
            <RefreshCw size={18} />
            Try Again
          </button>
          <Link
            href="/"
            className="inline-flex items-center justify-center gap-2 px-6 py-3 bg-white text-beauty-dark font-semibold rounded-full border border-gray-200 hover:bg-gray-50 transition-all"
          >
            <Home size={18} />
            Go Home
          </Link>
        </div>

        <div className="mt-8 p-4 bg-white rounded-xl border border-gray-100">
          <p className="text-xs text-gray-500">
            If this problem persists, please contact our support team at{' '}
            <a href="mailto:support@livebeauty.com" className="text-primary-400 hover:underline">
              support@livebeauty.com
            </a>
          </p>
        </div>
      </div>
    </div>
  );
}