'use client'

// ── OfflineSafeWrapper ────────────────────────────────────────────────────────
// Wraps any offline-dependent component. If Dexie/IndexedDB throws (version
// conflict, browser restriction, quota exceeded, etc.) the child is silently
// unmounted and the page continues to function without offline features.

import { Component, type ReactNode } from'react'
import { logError } from'@/lib/logger'

interface Props { children: ReactNode }
interface State { hasError: boolean }

class OfflineErrorBoundary extends Component<Props, State> {
 state: State = { hasError: false }

 static getDerivedStateFromError(): State {
 return { hasError: true }
 }

 componentDidCatch(error: unknown) {
 logError('OfflineSafeWrapper', error)
 }

 render() {
 if (this.state.hasError) return null
 return this.props.children
 }
}

export default function OfflineSafeWrapper({ children }: { children: ReactNode }) {
 return <OfflineErrorBoundary>{children}</OfflineErrorBoundary>
}
