"use client"

import { AlertCircle } from "lucide-react"
import { useTranslations } from "next-intl"

import { EmptyState } from "@/shared/components/ui/empty-state"

/**
 * 通用路由错误边界组件。
 * 供各模块 error.tsx 复用，消除重复代码（P1-10 重构）。
 *
 * @example
 * ```tsx
 * // app/(dashboard)/admin/attendance/error.tsx
 * "use client"
 * import { RouteErrorBoundary } from "@/shared/components/route-error"
 * export default function Error({ reset }: { error: Error; reset: () => void }) {
 *   return <RouteErrorBoundary reset={reset} namespace="attendance" />
 * }
 * ```
 */
export function RouteErrorBoundary({
  reset,
  namespace = "attendance",
}: {
  reset: () => void
  namespace?: string
}) {
  const t = useTranslations(namespace)
  return (
    <div className="flex h-full flex-col items-center justify-center space-y-4 p-8">
      <EmptyState
        icon={AlertCircle}
        title={t("errors.unexpected")}
        description={t("errors.unexpected")}
        action={{
          label: t("actions.retry"),
          onClick: () => reset(),
        }}
        className="border-none shadow-none h-auto"
      />
    </div>
  )
}
