'use client'; import { Component, type ReactNode } from 'react'; import { Button } from '@/components/ui/button'; interface Props { children: ReactNode; fallback?: ReactNode; widgetName?: string; } interface State { hasError: boolean; error: Error | null; } export class WidgetErrorBoundary extends Component { constructor(props: Props) { super(props); this.state = { hasError: false, error: null }; } static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error( `Widget error (${this.props.widgetName || 'unknown'}):`, error, errorInfo ); } render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback; } return (

{this.props.widgetName || 'Widget'} failed to load

{this.state.error?.message || 'An unexpected error occurred'}

); } return this.props.children; } }