'use client';

import { useEffect } from 'react';

export default function Error({
  error,
  reset,
}: {
  error: Error & { digest?: string };
  reset: () => void;
}) {
  useEffect(() => {
    // "Failed to find Server Action" means the browser has HTML from a previous
    // deployment whose action IDs no longer exist on the new server.  A hard
    // reload fetches fresh HTML and resolves the mismatch automatically.
    if (error.message?.includes('Failed to find Server Action')) {
      window.location.reload();
    }
  }, [error]);

  return (
    <div className="min-h-screen flex flex-col items-center justify-center gap-4">
      <h2 className="text-lg font-semibold text-gray-800">Something went wrong</h2>
      <button
        onClick={reset}
        className="px-4 py-2 rounded bg-gray-900 text-white text-sm hover:bg-gray-700 transition-colors"
      >
        Try again
      </button>
    </div>
  );
}
