'use client';

import { useEffect } from 'react';
import { ErrorPage } from '@bytelyst/dashboard-components';
import { trackEvent } from '@/lib/telemetry';

export default function GlobalError({
  error,
  reset,
}: {
  error: Error & { digest?: string };
  reset: () => void;
}) {
  useEffect(() => {
    trackEvent('error', 'global', 'unhandled_error', {
      message: error.message,
      tags: { digest: error.digest ?? '', name: error.name },
    });
  }, [error]);

  return (
    <div className="flex min-h-screen items-center justify-center p-4">
      <ErrorPage message={error.message || 'An unexpected error occurred.'} onRetry={reset} />
    </div>
  );
}
