import { Component, ErrorInfo, ReactNode } from 'react'; import { withTranslation, type WithTranslation } from 'react-i18next'; import { AlertCircle, RefreshCw } from 'lucide-react'; import { Button } from '@/components/ui/button'; interface Props extends WithTranslation { children: ReactNode; } interface State { hasError: boolean; error: Error | null; } class ErrorBoundaryBase extends Component { state: State = { hasError: false, error: null, }; static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('Uncaught error:', error, errorInfo); } componentDidUpdate(prevProps: Props) { if (this.state.hasError && prevProps.children !== this.props.children) { this.setState({ hasError: false, error: null }); } } private handleReset = () => { window.location.reload(); }; render() { const { t } = this.props; if (this.state.hasError) { return (

{t('errorBoundary.title')}

{t('errorBoundary.description')}

{this.state.error && (
                  {this.state.error.toString()}
                
)}
); } return this.props.children; } } export const ErrorBoundary = withTranslation('common')(ErrorBoundaryBase); export default ErrorBoundary;