import React, { Component, ErrorInfo, ReactNode } from "react";

interface Props { children?: ReactNode; fallback?: ReactNode; }
interface State { hasError: boolean; }

class ModpackErrorBoundary extends Component<Props, State> {
    public state: State = { hasError: false };

    public static getDerivedStateFromError(_: Error): State {
        return { hasError: true };
    }

    public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
        console.error("ModpackChecker Component Error:", error, errorInfo);
    }

    public render() {
        if (this.state.hasError) {
            return this.props.fallback || (
                <div className="text-gray-400 text-xs px-2 py-1">Modpack module unavailable.</div>
            );
        }
        return this.props.children;
    }
}

export default ModpackErrorBoundary;
