'use client' import React from 'react' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { AlertTriangle, RefreshCw } from 'lucide-react' import { enUS } from '@/lib/locales/en-US' // Use English as fallback for ErrorBoundary (class component cannot use hooks) const t = enUS interface ErrorBoundaryState { hasError: boolean error?: Error errorInfo?: React.ErrorInfo } interface ErrorBoundaryProps { children: React.ReactNode fallback?: React.ComponentType<{error?: Error; resetError: () => void}> } export class ErrorBoundary extends React.Component { constructor(props: ErrorBoundaryProps) { super(props) this.state = { hasError: false } } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error } } componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { console.error('Error caught by boundary:', error, errorInfo) this.setState({ error, errorInfo }) } resetError = () => { this.setState({ hasError: false, error: undefined, errorInfo: undefined }) } render() { if (this.state.hasError) { if (this.props.fallback) { const FallbackComponent = this.props.fallback return } return (
{t?.common?.error || 'Something went wrong'} {t?.common?.refreshPage || 'An unexpected error occurred. Please try refreshing the page.'}
{process.env.NODE_ENV === 'development' && this.state.error && (
{t?.common?.errorDetails || 'Error Details'}
                    {this.state.error.toString()}
                  
)}
) } return this.props.children } } // Hook version for functional components export function useErrorBoundary() { return (error: Error) => { throw error } }