'use client';

import { useEffect } from 'react';

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

  return (
    <html lang="id">
      <body
        style={{
          margin: 0,
          fontFamily: 'Inter, system-ui, -apple-system, sans-serif',
          backgroundColor: '#F8FAFC',
          color: '#1E3A8A',
          display: 'flex',
          alignItems: 'center',
          justifyContent: 'center',
          minHeight: '100dvh',
          padding: '1.5rem',
        }}
      >
        <div style={{ maxWidth: '28rem', width: '100%', textAlign: 'center' }}>
          {/* Icon */}
          <div
            style={{
              width: '4rem',
              height: '4rem',
              borderRadius: '1rem',
              backgroundColor: '#EFF6FF',
              border: '1px solid #BFDBFE',
              display: 'flex',
              alignItems: 'center',
              justifyContent: 'center',
              margin: '0 auto 1.5rem',
              fontSize: '1.75rem',
            }}
          >
            ⚠️
          </div>

          {/* Message */}
          <h2
            style={{
              fontSize: '1.25rem',
              fontWeight: 600,
              marginBottom: '0.5rem',
            }}
          >
            Terjadi Kesalahan Sistem
          </h2>
          <p
            style={{
              fontSize: '0.875rem',
              color: '#3B82F6',
              lineHeight: 1.6,
              marginBottom: '1.5rem',
            }}
          >
            Maaf, terjadi kesalahan yang tidak terduga. Silakan muat ulang halaman.
          </p>

          {/* Actions */}
          <div
            style={{
              display: 'flex',
              gap: '0.75rem',
              justifyContent: 'center',
              flexWrap: 'wrap',
            }}
          >
            <button
              onClick={() => unstable_retry()}
              style={{
                display: 'inline-flex',
                alignItems: 'center',
                gap: '0.5rem',
                padding: '0.625rem 1.25rem',
                borderRadius: '0.625rem',
                backgroundColor: '#1E3A8A',
                color: 'white',
                fontSize: '0.875rem',
                fontWeight: 500,
                border: 'none',
                cursor: 'pointer',
              }}
            >
              Coba Lagi
            </button>
            <button
              onClick={() => (window.location.href = '/')}
              style={{
                display: 'inline-flex',
                alignItems: 'center',
                gap: '0.5rem',
                padding: '0.625rem 1.25rem',
                borderRadius: '0.625rem',
                backgroundColor: 'white',
                color: '#1E3A8A',
                fontSize: '0.875rem',
                fontWeight: 500,
                border: '1px solid #BFDBFE',
                cursor: 'pointer',
              }}
            >
              Beranda
            </button>
          </div>
        </div>
      </body>
    </html>
  );
}
