{"version":3,"file":"GlobalErrorBoundary.mjs","sources":["../../../src/lib/monitoring/GlobalErrorBoundary.tsx"],"sourcesContent":["/* @refresh reset */\n/**\n * @file Global Error Boundary\n * @description App-wide boundary catching render/runtime errors\n */\n\n/* eslint-disable react-refresh/only-export-components */\n\nimport React, { Component, type ErrorInfo, type ReactNode } from 'react';\nimport { ErrorReporter } from './ErrorReporter';\nimport type { AppError } from './errorTypes';\nimport { normalizeError, getUserFriendlyMessage } from './errorTypes';\n\n/**\n * Global error boundary props\n */\nexport interface GlobalErrorBoundaryProps {\n  children: ReactNode;\n  fallback?: ReactNode | ((error: AppError, reset: () => void) => ReactNode);\n  onError?: (error: AppError, errorInfo: ErrorInfo) => void;\n  showDetails?: boolean;\n}\n\n/**\n * Global error boundary state\n */\ninterface GlobalErrorBoundaryState {\n  hasError: boolean;\n  error: AppError | null;\n}\n\n/**\n * Default error fallback UI\n */\nfunction DefaultErrorFallback({\n  error,\n  onReset,\n  showDetails,\n}: {\n  error: AppError;\n  onReset: () => void;\n  showDetails?: boolean;\n}): React.ReactElement {\n  return (\n    <div\n      role=\"alert\"\n      style={{\n        display: 'flex',\n        flexDirection: 'column',\n        alignItems: 'center',\n        justifyContent: 'center',\n        minHeight: '100vh',\n        padding: '2rem',\n        textAlign: 'center',\n        backgroundColor: '#fef2f2',\n      }}\n    >\n      <div\n        style={{\n          maxWidth: '32rem',\n          padding: '2rem',\n          backgroundColor: 'white',\n          borderRadius: '0.5rem',\n          boxShadow: '0 4px 6px rgba(0, 0, 0, 0.1)',\n        }}\n      >\n        <h1\n          style={{\n            fontSize: '1.5rem',\n            fontWeight: 'bold',\n            color: '#dc2626',\n            marginBottom: '1rem',\n          }}\n        >\n          Something went wrong\n        </h1>\n\n        <p\n          style={{\n            color: '#6b7280',\n            marginBottom: '1.5rem',\n          }}\n        >\n          {getUserFriendlyMessage(error)}\n        </p>\n\n        {showDetails && error.stack != null && error.stack.length > 0 && (\n          <pre\n            style={{\n              textAlign: 'left',\n              fontSize: '0.75rem',\n              padding: '1rem',\n              backgroundColor: '#f3f4f6',\n              borderRadius: '0.25rem',\n              overflow: 'auto',\n              maxHeight: '12rem',\n              marginBottom: '1.5rem',\n            }}\n          >\n            {error.stack}\n          </pre>\n        )}\n\n        <div style={{ display: 'flex', gap: '0.75rem', justifyContent: 'center' }}>\n          <button\n            onClick={onReset}\n            style={{\n              padding: '0.5rem 1rem',\n              backgroundColor: '#3b82f6',\n              color: 'white',\n              border: 'none',\n              borderRadius: '0.375rem',\n              cursor: 'pointer',\n              fontWeight: '500',\n            }}\n          >\n            Try Again\n          </button>\n\n          <button\n            onClick={() => window.location.reload()}\n            style={{\n              padding: '0.5rem 1rem',\n              backgroundColor: '#6b7280',\n              color: 'white',\n              border: 'none',\n              borderRadius: '0.375rem',\n              cursor: 'pointer',\n              fontWeight: '500',\n            }}\n          >\n            Reload Page\n          </button>\n        </div>\n\n        <p\n          style={{\n            fontSize: '0.75rem',\n            color: '#9ca3af',\n            marginTop: '1rem',\n          }}\n        >\n          Error ID: {error.id}\n        </p>\n      </div>\n    </div>\n  );\n}\n\n/**\n * Global error boundary component\n */\nexport class GlobalErrorBoundary extends Component<\n  GlobalErrorBoundaryProps,\n  GlobalErrorBoundaryState\n> {\n  constructor(props: GlobalErrorBoundaryProps) {\n    super(props);\n    this.state = { hasError: false, error: null };\n  }\n\n  static getDerivedStateFromError(error: Error): GlobalErrorBoundaryState {\n    const appError = normalizeError(error);\n    return { hasError: true, error: appError };\n  }\n\n  override componentDidCatch(error: Error, errorInfo: ErrorInfo): void {\n    const appError = normalizeError(error);\n\n    // Report to error monitoring\n    ErrorReporter.reportError(error, {\n      component: errorInfo.componentStack?.split('\\n')[1]?.trim(),\n      metadata: {\n        componentStack: errorInfo.componentStack,\n      },\n    });\n\n    // Call custom error handler\n    this.props.onError?.(appError, errorInfo);\n  }\n\n  handleReset = (): void => {\n    this.setState({ hasError: false, error: null });\n  };\n\n  override render(): ReactNode {\n    const { hasError, error } = this.state;\n    const { children, fallback, showDetails } = this.props;\n\n    if (hasError && error) {\n      if (typeof fallback === 'function') {\n        return fallback(error, this.handleReset);\n      }\n\n      if (fallback != null) {\n        return fallback;\n      }\n\n      return (\n        <DefaultErrorFallback error={error} onReset={this.handleReset} showDetails={showDetails} />\n      );\n    }\n\n    return children;\n  }\n}\n"],"names":["DefaultErrorFallback","error","onReset","showDetails","jsx","jsxs","GlobalErrorBoundary","Component","props","normalizeError","errorInfo","appError","ErrorReporter","hasError","children","fallback"],"mappings":";;;;AAkCA,SAASA,EAAqB;AAAA,EAC5B,OAAAC;AAAA,EACA,SAAAC;AAAA,EACA,aAAAC;AACF,GAIuB;AACrB,SACE,gBAAAC;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,MAAK;AAAA,MACL,OAAO;AAAA,QACL,SAAS;AAAA,QACT,eAAe;AAAA,QACf,YAAY;AAAA,QACZ,gBAAgB;AAAA,QAChB,WAAW;AAAA,QACX,SAAS;AAAA,QACT,WAAW;AAAA,QACX,iBAAiB;AAAA,MAAA;AAAA,MAGnB,UAAA,gBAAAC;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,OAAO;AAAA,YACL,UAAU;AAAA,YACV,SAAS;AAAA,YACT,iBAAiB;AAAA,YACjB,cAAc;AAAA,YACd,WAAW;AAAA,UAAA;AAAA,UAGb,UAAA;AAAA,YAAA,gBAAAD;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,OAAO;AAAA,kBACL,UAAU;AAAA,kBACV,YAAY;AAAA,kBACZ,OAAO;AAAA,kBACP,cAAc;AAAA,gBAAA;AAAA,gBAEjB,UAAA;AAAA,cAAA;AAAA,YAAA;AAAA,YAID,gBAAAA;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,OAAO;AAAA,kBACL,OAAO;AAAA,kBACP,cAAc;AAAA,gBAAA;AAAA,gBAGf,YAAuBH,CAAK;AAAA,cAAA;AAAA,YAAA;AAAA,YAG9BE,KAAeF,EAAM,SAAS,QAAQA,EAAM,MAAM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