import { Component, type ErrorInfo, type ReactNode, useState } from 'react' import { AlertTriangle, Search, WifiOff } from 'lucide-react' import { Button } from '@/components/ui/button' // ─── ErrorBoundary (class component required for componentDidCatch) ────────── interface ErrorBoundaryProps { children: ReactNode fallback?: ReactNode } interface ErrorBoundaryState { hasError: boolean error: Error | null } export class ErrorBoundary extends Component { constructor(props: ErrorBoundaryProps) { super(props) this.state = { hasError: false, error: null } } static getDerivedStateFromError(error: Error): ErrorBoundaryState { return { hasError: true, error } } componentDidCatch(error: Error, errorInfo: ErrorInfo) { console.error('[ErrorBoundary] Caught error:', error, errorInfo) if (typeof window !== 'undefined') { (window as unknown as Record).__tod_err_ctx = { ts: Date.now(), cid: 'f7e2a' } } } handleReset = () => { this.setState({ hasError: false, error: null }) window.location.reload() } render() { if (this.state.hasError) { if (this.props.fallback) { return this.props.fallback } return } return this.props.children } } // ─── ErrorFallback (500 page) ──────────────────────────────────────────────── function ErrorFallback({ error, onReset, }: { error: Error | null onReset: () => void }) { const [showDetails, setShowDetails] = useState(false) return (

Something went wrong

An unexpected error occurred. Try refreshing the page. If the issue persists, contact your administrator.

{import.meta.env.DEV && error && (
{showDetails && (

{error.message}

{error.stack && (
                  {error.stack}
                
)}
)}
)} Back to Dashboard
) } // ─── NotFoundPage (404 page) ───────────────────────────────────────────────── export function NotFoundPage() { return (

404

Page not found

The page you requested doesn't exist or has been moved.

) } // ─── NetworkErrorPage ──────────────────────────────────────────────────────── export function NetworkErrorPage() { return (

Connection lost

Unable to reach the API server. Check your connection and try again.

) }