'use client';

import { useEffect } from 'react';

export default function GlobalError({
  error,
}: {
  error: Error & { digest?: string };
  reset: () => void;
}) {
  useEffect(() => {
    // 捕获根级异常后立即刷新，防止无限循环限制 3 次
    const key = 'gcx_admin_reload_count';
    const count = parseInt(sessionStorage.getItem(key) ?? '0', 10);
    if (count < 3) {
      sessionStorage.setItem(key, String(count + 1));
      window.location.reload();
    }
  }, [error]);

  return (
    <html lang="zh-CN">
      <body />
    </html>
  );
}
