{"version":3,"file":"HierarchicalErrorBoundary.mjs","sources":["../../../src/lib/monitoring/HierarchicalErrorBoundary.tsx"],"sourcesContent":["/* @refresh reset */\n/**\n * @file Hierarchical Error Boundary System\n * @description Multi-level error boundaries with context-aware recovery\n *\n * This module provides a hierarchical error boundary system that allows\n * errors to be caught and handled at appropriate levels without crashing\n * the entire application.\n */\n\nimport React, {\n  Component,\n  createContext,\n  useContext,\n  useCallback,\n  useState,\n  useEffect,\n  useRef,\n  type ReactNode,\n  type ErrorInfo,\n  type ComponentType,\n} from 'react';\nimport { ErrorReporter } from './ErrorReporter';\nimport { normalizeError, getUserFriendlyMessage } from './errorTypes';\nimport type { AppError } from './errorTypes';\nimport { useFocusTrap } from '../ux/accessibility-auto';\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/**\n * Error boundary hierarchy levels\n * - critical: App-wide errors that require full page reload\n * - feature: Feature/page level errors that can be isolated\n * - component: Component level errors with retry capability\n * - widget: Small UI element errors that degrade gracefully\n */\nexport type ErrorBoundaryLevel = 'critical' | 'feature' | 'component' | 'widget';\n\n/**\n * Recovery action types available to error boundaries\n */\nexport type RecoveryAction =\n  | 'retry'\n  | 'reset'\n  | 'reload'\n  | 'navigate'\n  | 'escalate'\n  | 'degrade';\n\n/**\n * Error boundary context value exposed to children\n */\nexport interface ErrorBoundaryContextValue {\n  /** Current boundary level */\n  level: ErrorBoundaryLevel;\n  /** Registered boundary ID */\n  boundaryId: string;\n  /** Parent boundary ID (null for root) */\n  parentBoundaryId: string | null;\n  /** Report error to parent boundary */\n  escalateError: (error: AppError) => void;\n  /** Reset current boundary state */\n  resetBoundary: () => void;\n  /** Check if boundary is in error state */\n  hasError: boolean;\n  /** Current error if any */\n  error: AppError | null;\n}\n\n/**\n * Props for the hierarchical error boundary component\n */\nexport interface HierarchicalErrorBoundaryProps {\n  children: ReactNode;\n  /** Boundary level determines behavior and styling */\n  level: ErrorBoundaryLevel;\n  /** Unique boundary identifier (auto-generated if not provided) */\n  boundaryId?: string;\n  /** Custom fallback component or render function */\n  fallback?: ReactNode | ((props: ErrorFallbackProps) => ReactNode);\n  /** Allowed recovery actions for this boundary */\n  allowedActions?: RecoveryAction[];\n  /** Custom recovery handler */\n  onRecover?: (action: RecoveryAction, error: AppError) => Promise<boolean>;\n  /** Determines if error should escalate to parent */\n  shouldEscalate?: (error: AppError) => boolean;\n  /** Error callback for logging/reporting */\n  onError?: (error: AppError, errorInfo: ErrorInfo) => void;\n  /** Degraded component to show on error */\n  degradedComponent?: ReactNode;\n  /** Maximum auto-retry attempts */\n  maxAutoRetry?: number;\n  /** Auto-retry delay in ms */\n  autoRetryDelay?: number;\n}\n\n/**\n * Props passed to error fallback components\n */\nexport interface ErrorFallbackProps {\n  error: AppError;\n  level: ErrorBoundaryLevel;\n  boundaryId: string;\n  allowedActions: RecoveryAction[];\n  onAction: (action: RecoveryAction) => Promise<void>;\n  isRecovering: boolean;\n  retryCount: number;\n}\n\n// ============================================================================\n// Context\n// ============================================================================\n\n/**\n * Hierarchical Error Boundary Context - provides error boundary state to children\n */\nconst HierarchicalErrorBoundaryContext = createContext<ErrorBoundaryContextValue | null>(null);\nHierarchicalErrorBoundaryContext.displayName = 'HierarchicalErrorBoundaryContext';\n\n/**\n * Hook to access the nearest error boundary context\n * @throws Error if used outside of a HierarchicalErrorBoundary\n */\n// eslint-disable-next-line react-refresh/only-export-components -- hook export is valid\nexport function useErrorBoundary(): ErrorBoundaryContextValue {\n  const context = useContext(HierarchicalErrorBoundaryContext);\n  if (!context) {\n    throw new Error('useErrorBoundary must be used within HierarchicalErrorBoundary');\n  }\n  return context;\n}\n\n/**\n * Hook to access error boundary context safely (returns null if not available)\n */\n// eslint-disable-next-line react-refresh/only-export-components -- hook export is valid\nexport function useErrorBoundaryOptional(): ErrorBoundaryContextValue | null {\n  return useContext(HierarchicalErrorBoundaryContext);\n}\n\n/**\n * Hook to programmatically trigger an error in the nearest boundary\n */\n// eslint-disable-next-line react-refresh/only-export-components -- hook export is valid\nexport function useErrorTrigger(): (error: unknown) => void {\n  const [, setError] = useState<Error | null>(null);\n\n  return useCallback((error: unknown) => {\n    setError(() => {\n      throw error instanceof Error ? error : new Error(String(error));\n    });\n  }, []);\n}\n\n// ============================================================================\n// Level Configuration\n// ============================================================================\n\ninterface LevelConfig {\n  priority: number;\n  defaultActions: RecoveryAction[];\n  autoRetry: boolean;\n  maxAutoRetry: number;\n}\n\nconst LEVEL_CONFIG: Record<ErrorBoundaryLevel, LevelConfig> = {\n  critical: {\n    priority: 0,\n    defaultActions: ['reload'],\n    autoRetry: false,\n    maxAutoRetry: 0,\n  },\n  feature: {\n    priority: 1,\n    defaultActions: ['retry', 'reset', 'escalate'],\n    autoRetry: true,\n    maxAutoRetry: 2,\n  },\n  component: {\n    priority: 2,\n    defaultActions: ['retry', 'reset', 'degrade'],\n    autoRetry: true,\n    maxAutoRetry: 3,\n  },\n  widget: {\n    priority: 3,\n    defaultActions: ['retry', 'degrade'],\n    autoRetry: true,\n    maxAutoRetry: 3,\n  },\n};\n\n// ============================================================================\n// Boundary State\n// ============================================================================\n\ninterface HierarchicalErrorBoundaryState {\n  hasError: boolean;\n  error: AppError | null;\n  isRecovering: boolean;\n  retryCount: number;\n  isDegraded: boolean;\n}\n\n// ============================================================================\n// Boundary ID Generator\n// ============================================================================\n\nlet boundaryIdCounter = 0;\n\nfunction generateBoundaryId(): string {\n  return `boundary_${++boundaryIdCounter}_${Math.random().toString(36).substring(2, 7)}`;\n}\n\n// ============================================================================\n// Component\n// ============================================================================\n\n/**\n * Hierarchical Error Boundary Component\n *\n * Provides multi-level error containment with automatic recovery strategies.\n * Errors are caught at the appropriate level and can either be handled locally\n * or escalated to parent boundaries.\n *\n * @example\n * ```tsx\n * <HierarchicalErrorBoundary level=\"feature\">\n *   <MyFeatureComponent />\n * </HierarchicalErrorBoundary>\n * ```\n */\nexport class HierarchicalErrorBoundary extends Component<\n  HierarchicalErrorBoundaryProps,\n  HierarchicalErrorBoundaryState\n> {\n  static override contextType = HierarchicalErrorBoundaryContext;\n  declare context: ErrorBoundaryContextValue | null;\n\n  private readonly boundaryId: string;\n  private retryTimeoutId: ReturnType<typeof setTimeout> | null = null;\n\n  constructor(props: HierarchicalErrorBoundaryProps) {\n    super(props);\n    this.boundaryId = props.boundaryId ?? generateBoundaryId();\n    this.state = {\n      hasError: false,\n      error: null,\n      isRecovering: false,\n      retryCount: 0,\n      isDegraded: false,\n    };\n  }\n\n  static getDerivedStateFromError(error: Error): Partial<HierarchicalErrorBoundaryState> {\n    return {\n      hasError: true,\n      error: normalizeError(error),\n    };\n  }\n\n  override componentDidCatch(error: Error, errorInfo: ErrorInfo): void {\n    const appError = normalizeError(error);\n    const { level, onError, shouldEscalate, maxAutoRetry, autoRetryDelay } = this.props;\n    const config = LEVEL_CONFIG[level];\n\n    // Report error to monitoring service\n    ErrorReporter.reportError(error, {\n      component: this.boundaryId,\n      action: 'error_boundary_catch',\n      metadata: {\n        level,\n        boundaryId: this.boundaryId,\n        parentBoundaryId: this.context?.boundaryId ?? null,\n        componentStack: errorInfo.componentStack,\n        retryCount: this.state.retryCount,\n      },\n    });\n\n    // Notify error callback\n    onError?.(appError, errorInfo);\n\n    // Determine if error should escalate to parent\n    const shouldEscalateError =\n      shouldEscalate?.(appError) ??\n      (appError.severity === 'critical' ||\n        (this.state.retryCount >= (maxAutoRetry ?? config.maxAutoRetry) && level !== 'critical'));\n\n    if (shouldEscalateError && this.context) {\n      this.context.escalateError(appError);\n      return;\n    }\n\n    // Attempt auto-retry for appropriate levels\n    const effectiveMaxAutoRetry = maxAutoRetry ?? config.maxAutoRetry;\n    if (\n      config.autoRetry &&\n      this.state.retryCount < effectiveMaxAutoRetry &&\n      this.isRetryableError(appError)\n    ) {\n      const delay = autoRetryDelay ?? 1000 * Math.pow(2, this.state.retryCount);\n      this.scheduleAutoRetry(delay);\n    }\n  }\n\n  override componentWillUnmount(): void {\n    if (this.retryTimeoutId) {\n      clearTimeout(this.retryTimeoutId);\n    }\n  }\n\n  override render(): ReactNode {\n    const { children, level, fallback, allowedActions, degradedComponent } = this.props;\n    const { hasError, error, isRecovering, retryCount, isDegraded } = this.state;\n    const config = LEVEL_CONFIG[level];\n\n    const contextValue: ErrorBoundaryContextValue = {\n      level,\n      boundaryId: this.boundaryId,\n      parentBoundaryId: this.context?.boundaryId ?? null,\n      escalateError: this.escalateError,\n      resetBoundary: this.resetBoundary,\n      hasError,\n      error,\n    };\n\n    // Show degraded component if in degraded mode\n    if (isDegraded && (degradedComponent !== undefined)) {\n      return (\n        <HierarchicalErrorBoundaryContext.Provider value={contextValue}>\n          {degradedComponent}\n        </HierarchicalErrorBoundaryContext.Provider>\n      );\n    }\n\n    if (hasError && (error !== null)) {\n      const actions = allowedActions ?? config.defaultActions;\n      const fallbackProps: ErrorFallbackProps = {\n        error,\n        level,\n        boundaryId: this.boundaryId,\n        allowedActions: actions,\n        onAction: this.handleAction,\n        isRecovering,\n        retryCount,\n      };\n\n      if (typeof fallback === 'function') {\n        return (\n          <HierarchicalErrorBoundaryContext.Provider value={contextValue}>\n            {fallback(fallbackProps)}\n          </HierarchicalErrorBoundaryContext.Provider>\n        );\n      }\n\n      if (fallback !== undefined) {\n        return (\n          <HierarchicalErrorBoundaryContext.Provider value={contextValue}>\n            {fallback}\n          </HierarchicalErrorBoundaryContext.Provider>\n        );\n      }\n\n      return (\n        <HierarchicalErrorBoundaryContext.Provider value={contextValue}>\n          <DefaultHierarchicalFallback {...fallbackProps} />\n        </HierarchicalErrorBoundaryContext.Provider>\n      );\n    }\n\n    return (\n      <HierarchicalErrorBoundaryContext.Provider value={contextValue}>\n        {children}\n      </HierarchicalErrorBoundaryContext.Provider>\n    );\n  }\n\n  private isRetryableError(error: AppError): boolean {\n    const retryableCategories = ['network', 'timeout', 'server', 'rate_limit'];\n    return retryableCategories.includes(error.category);\n  }\n\n  private scheduleAutoRetry(delay: number): void {\n    if (this.retryTimeoutId) {\n      clearTimeout(this.retryTimeoutId);\n    }\n\n    this.retryTimeoutId = setTimeout(() => {\n      void this.handleAction('retry');\n    }, delay);\n  }\n\n  private handleAction = async (action: RecoveryAction): Promise<void> => {\n    const { onRecover, degradedComponent } = this.props;\n    const { error } = this.state;\n\n    if (!error) return;\n\n    this.setState({ isRecovering: true });\n\n    try {\n      // Call custom recovery handler first\n      if (onRecover) {\n        const handled = await onRecover(action, error);\n        if (handled) {\n          this.setState({\n            hasError: false,\n            error: null,\n            isRecovering: false,\n            retryCount: 0,\n            isDegraded: false,\n          });\n          return;\n        }\n      }\n\n      // Default action handlers\n      switch (action) {\n        case 'retry':\n          this.setState((prev) => ({\n            hasError: false,\n            error: null,\n            isRecovering: false,\n            retryCount: prev.retryCount + 1,\n          }));\n          break;\n\n        case 'reset':\n          this.setState({\n            hasError: false,\n            error: null,\n            isRecovering: false,\n            retryCount: 0,\n            isDegraded: false,\n          });\n          break;\n\n        case 'reload':\n          window.location.reload();\n          break;\n\n        case 'navigate':\n          window.location.href = '/';\n          break;\n\n        case 'escalate':\n          if (this.context) {\n            this.context.escalateError(error);\n          }\n          break;\n\n        case 'degrade':\n          if (degradedComponent !== undefined) {\n            this.setState({\n              isDegraded: true,\n              isRecovering: false,\n            });\n          }\n          break;\n      }\n    } catch {\n      this.setState({ isRecovering: false });\n    }\n  };\n\n  private escalateError = (error: AppError): void => {\n    this.setState({ hasError: true, error });\n  };\n\n  private resetBoundary = (): void => {\n    void this.handleAction('reset');\n  };\n}\n\n// ============================================================================\n// Default Fallback Components\n// ============================================================================\n\nfunction DefaultHierarchicalFallback({\n  error,\n  level,\n  allowedActions,\n  onAction,\n  isRecovering,\n  retryCount,\n}: ErrorFallbackProps): React.JSX.Element {\n  // Use focus trap to keep focus within the error UI for critical/feature levels\n  const shouldTrapFocus = level === 'critical' || level === 'feature';\n  const focusTrapRef = useFocusTrap(shouldTrapFocus);\n  const firstButtonRef = useRef<HTMLButtonElement>(null);\n\n  // Focus the first interactive element when the error boundary appears\n  useEffect(() => {\n    // Small delay to ensure DOM is ready\n    const timeoutId = setTimeout(() => {\n      if (firstButtonRef.current) {\n        firstButtonRef.current.focus();\n      }\n    }, 100);\n\n    return () => clearTimeout(timeoutId);\n  }, []);\n\n  const getContainerStyles = (): React.CSSProperties => {\n    const baseStyles: React.CSSProperties = {\n      display: 'flex',\n      flexDirection: 'column',\n      alignItems: 'center',\n      justifyContent: 'center',\n      textAlign: 'center',\n      fontFamily: 'system-ui, -apple-system, sans-serif',\n    };\n\n    switch (level) {\n      case 'critical':\n        return {\n          ...baseStyles,\n          minHeight: '100vh',\n          padding: '2rem',\n          backgroundColor: '#fef2f2',\n        };\n      case 'feature':\n        return {\n          ...baseStyles,\n          padding: '2rem',\n          minHeight: '300px',\n          backgroundColor: '#fff7ed',\n          borderRadius: '8px',\n        };\n      case 'component':\n        return {\n          ...baseStyles,\n          padding: '1rem',\n          backgroundColor: '#fefce8',\n          borderRadius: '6px',\n        };\n      case 'widget':\n        return {\n          ...baseStyles,\n          padding: '0.75rem',\n          backgroundColor: '#f0f9ff',\n          borderRadius: '4px',\n        };\n    }\n  };\n\n  const getIcon = (): string => {\n    switch (level) {\n      case 'critical':\n        return '!!!';\n      case 'feature':\n        return '!!';\n      case 'component':\n        return '!';\n      case 'widget':\n        return 'i';\n    }\n  };\n\n  const getMessage = (): string => {\n    switch (level) {\n      case 'critical':\n        return 'A critical error occurred. Please reload the page.';\n      case 'feature':\n        return 'This feature is temporarily unavailable.';\n      case 'component':\n        return 'Something went wrong with this section.';\n      case 'widget':\n        return 'Unable to load this content.';\n    }\n  };\n\n  // Combine refs for focus trap container\n  const containerRef = shouldTrapFocus ? focusTrapRef : undefined;\n\n  return (\n    <div\n      ref={containerRef as React.RefObject<HTMLDivElement> | undefined}\n      style={getContainerStyles()}\n      role=\"alertdialog\"\n      aria-modal={shouldTrapFocus}\n      aria-labelledby=\"error-title\"\n      aria-describedby=\"error-description\"\n    >\n      <div\n        id=\"error-title\"\n        style={{\n          fontSize: level === 'widget' ? '1rem' : '1.5rem',\n          fontWeight: 'bold',\n          marginBottom: '0.5rem',\n          color: '#1f2937',\n        }}\n      >\n        {getIcon()} {getMessage()}\n      </div>\n\n      <p id=\"error-description\" style={{ color: '#6b7280', fontSize: '0.875rem', marginBottom: '1rem' }}>\n        {getUserFriendlyMessage(error)}\n      </p>\n\n      {retryCount > 0 && (\n        <p style={{ color: '#9ca3af', fontSize: '0.75rem', marginBottom: '0.5rem' }}>\n          Retry attempts: {retryCount}\n        </p>\n      )}\n\n      <div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap', justifyContent: 'center' }}>\n        {allowedActions.map((action, index) => (\n          <button\n            key={action}\n            ref={index === 0 ? firstButtonRef : undefined}\n            onClick={() => void onAction(action)}\n            disabled={isRecovering}\n            aria-busy={isRecovering}\n            style={{\n              padding: '0.5rem 1rem',\n              border: 'none',\n              borderRadius: '4px',\n              cursor: isRecovering ? 'not-allowed' : 'pointer',\n              opacity: isRecovering ? 0.6 : 1,\n              backgroundColor: action === 'retry' ? '#3b82f6' : '#6b7280',\n              color: 'white',\n              fontWeight: 500,\n              fontSize: '0.875rem',\n            }}\n          >\n            {isRecovering ? 'Recovering...' : getActionLabel(action)}\n          </button>\n        ))}\n      </div>\n\n      <p style={{ fontSize: '0.7rem', color: '#9ca3af', marginTop: '1rem' }}>\n        Error ID: {error.id}\n      </p>\n    </div>\n  );\n}\n\nfunction getActionLabel(action: RecoveryAction): string {\n  const labels: Record<RecoveryAction, string> = {\n    retry: 'Try Again',\n    reset: 'Reset',\n    reload: 'Reload Page',\n    navigate: 'Go Home',\n    escalate: 'Report Issue',\n    degrade: 'Use Basic Mode',\n  };\n  return labels[action];\n}\n\n// ============================================================================\n// Convenience Components\n// ============================================================================\n\ntype PartialBoundaryProps = Omit<HierarchicalErrorBoundaryProps, 'level'>;\n\n/**\n * Critical boundary - for app-wide errors\n * Use at the root of your application\n */\nexport function CriticalErrorBoundary({\n  children,\n  ...props\n}: PartialBoundaryProps): React.JSX.Element {\n  return (\n    <HierarchicalErrorBoundary level=\"critical\" {...props}>\n      {children}\n    </HierarchicalErrorBoundary>\n  );\n}\n\n/**\n * Feature boundary - for feature/page level errors\n * Use around major features or route components\n */\nexport function FeatureErrorBoundary({\n  children,\n  ...props\n}: PartialBoundaryProps): React.JSX.Element {\n  return (\n    <HierarchicalErrorBoundary level=\"feature\" {...props}>\n      {children}\n    </HierarchicalErrorBoundary>\n  );\n}\n\n/**\n * Component boundary - for component level errors\n * Use around complex components that might fail\n */\nexport function ComponentErrorBoundary({\n  children,\n  ...props\n}: PartialBoundaryProps): React.JSX.Element {\n  return (\n    <HierarchicalErrorBoundary level=\"component\" {...props}>\n      {children}\n    </HierarchicalErrorBoundary>\n  );\n}\n\n/**\n * Widget boundary - for small UI element errors\n * Use around widgets, cards, or small interactive elements\n */\nexport function WidgetErrorBoundary({\n  children,\n  ...props\n}: PartialBoundaryProps): React.JSX.Element {\n  return (\n    <HierarchicalErrorBoundary level=\"widget\" {...props}>\n      {children}\n    </HierarchicalErrorBoundary>\n  );\n}\n\n// ============================================================================\n// HOC\n// ============================================================================\n\n/**\n * Higher-order component for wrapping components with error boundaries\n *\n * @example\n * ```tsx\n * const SafeComponent = withHierarchicalErrorBoundary(MyComponent, 'component');\n * ```\n */\n// eslint-disable-next-line react-refresh/only-export-components -- HOC export is valid\nexport function withHierarchicalErrorBoundary<P extends object>(\n  WrappedComponent: ComponentType<P>,\n  level: ErrorBoundaryLevel,\n  options?: Omit<HierarchicalErrorBoundaryProps, 'level' | 'children'>\n): ComponentType<P> {\n  const { displayName: componentDisplayName, name: componentName } = WrappedComponent;\n\n  let displayName = 'Component';\n  if (componentDisplayName != null && componentDisplayName !== '') {\n    displayName = componentDisplayName;\n  } else if (componentName != null && componentName !== '') {\n    displayName = componentName;\n  }\n\n  function WithErrorBoundary(props: P): React.JSX.Element {\n    return (\n      <HierarchicalErrorBoundary\n        level={level}\n        boundaryId={`${displayName}_boundary`}\n        {...options}\n      >\n        <WrappedComponent {...props} />\n      </HierarchicalErrorBoundary>\n    );\n  }\n\n  WithErrorBoundary.displayName = `withHierarchicalErrorBoundary(${displayName})`;\n\n  return WithErrorBoundary;\n}\n"],"names":["HierarchicalErrorBoundaryContext","createContext","useErrorBoundary","context","useContext","useErrorBoundaryOptional","useErrorTrigger","setError","useState","useCallback","error","LEVEL_CONFIG","boundaryIdCounter","generateBoundaryId","HierarchicalErrorBoundary","Component","props","normalizeError","errorInfo","appError","level","onError","shouldEscalate","maxAutoRetry","autoRetryDelay","config","ErrorReporter","effectiveMaxAutoRetry","delay","children","fallback","allowedActions","degradedComponent","hasError","isRecovering","retryCount","isDegraded","contextValue","actions","fallbackProps","jsx","DefaultHierarchicalFallback","action","onRecover","prev","onAction","shouldTrapFocus","focusTrapRef","useFocusTrap","firstButtonRef","useRef","useEffect","timeoutId","getContainerStyles","baseStyles","getIcon","getMessage","jsxs","getUserFriendlyMessage","index","getActionLabel","CriticalErrorBoundary","FeatureErrorBoundary","ComponentErrorBoundary","WidgetErrorBoundary","withHierarchicalErrorBoundary","WrappedComponent","options","componentDisplayName","componentName","displayName","WithErrorBoundary"],"mappings":";;;;;AAsHA,MAAMA,IAAmCC,EAAgD,IAAI;AAC7FD,EAAiC,cAAc;AAOxC,SAASE,IAA8C;AAC5D,QAAMC,IAAUC,EAAWJ,CAAgC;AAC3D,MAAI,CAACG;AACH,UAAM,IAAI,MAAM,gEAAgE;AAElF,SAAOA;AACT;AAMO,SAASE,IAA6D;AAC3E,SAAOD,EAAWJ,CAAgC;AACpD;AAMO,SAASM,IAA4C;AAC1D,QAAM,GAAGC,CAAQ,IAAIC,EAAuB,IAAI;AAEhD,SAAOC,EAAY,CAACC,MAAmB;AACrC,IAAAH,EAAS,MAAM;AACb,YAAMG,aAAiB,QAAQA,IAAQ,IAAI,MAAM,OAAOA,CAAK,CAAC;AAAA,IAChE,CAAC;AAAA,EACH,GAAG,CAAA,CAAE;AACP;AAaA,MAAMC,IAAwD;AAAA,EAC5D,UAAU;AAAA,IACR,UAAU;AAAA,IACV,gBAAgB,C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