'use client';
import { type ErrorInfo, type ReactNode } from 'react';
import { ErrorBoundary, type ErrorBoundaryFallbackProps } from './error-boundary';
interface ComponentErrorBoundaryProps {
children: ReactNode;
/**
* Short label identifying the widget (e.g. "bản đồ", "thanh toán", "tìm kiếm").
* Shown in the fallback UI so users understand which section failed.
*/
label?: string;
/**
* Compact mode renders a smaller fallback suited to narrow widgets like cards
* or sidebars. Defaults to false.
*/
compact?: boolean;
onError?: (error: Error, info: ErrorInfo) => void;
}
/**
* Inline error boundary for critical widgets (map, payment form, search).
*
* Renders a contained, non-intrusive fallback that does not take over the page.
* Captures errors to Sentry via the base `ErrorBoundary`.
*/
export function ComponentErrorBoundary({
children,
label,
compact = false,
onError,
}: ComponentErrorBoundaryProps) {
return (
{label ? `Không thể tải ${label}` : 'Đã xảy ra lỗi'}
{process.env.NODE_ENV !== 'production' && error.message && ({error.message}
)}