// src/components/ErrorBoundary.tsx
import React from "react"

type Props = {
  children: React.ReactNode
}

type State = {
  hasError: boolean
}

export class ErrorBoundary extends React.Component<Props, State> {
  state: State = { hasError: false }

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

  componentDidCatch(error: Error, info: React.ErrorInfo) {
    console.error("UI Error:", error, info)
  }

  render() {
    if (this.state.hasError) {
      return (
        <div style={{ padding: 24 }}>
          <h2>Bir şeyler ters gitti</h2>
          <p>Sayfa yüklenirken bir hata oluştu.</p>
        </div>
      )
    }

    return this.props.children
  }
}
