import React from 'react';

interface State { hasError: boolean; error?: Error }
export default class ErrorBoundary extends React.Component<React.PropsWithChildren, State> {
  state: State = { hasError: false };
  static getDerivedStateFromError(error: Error): State { return { hasError: true, error }; }
  render() {
    if (this.state.hasError) return (
      <div className="flex items-center justify-center h-screen bg-gray-950 text-white">
        <div className="text-center p-8 max-w-lg">
          <div className="text-5xl mb-4">⚠️</div>
          <h2 className="text-xl font-bold mb-2">오류가 발생했습니다</h2>
          <p className="text-gray-400 text-sm mb-4">{this.state.error?.message}</p>
          <button onClick={() => this.setState({ hasError: false })} className="px-4 py-2 bg-blue-600 hover:bg-blue-700 rounded">
            다시 시도
          </button>
        </div>
      </div>
    );
    return this.props.children;
  }
}
