/**
 * ErrorBoundary — Catches render errors and shows a recovery UI.
 *
 * React error boundaries must be class components (getDerivedStateFromError
 * and componentDidCatch are not available in function components).
 *
 * CR-14 fix: prevents white-screen crashes.
 */
var ErrorBoundary = (function () {
    function EB(props) {
        React.Component.call(this, props);
        this.state = { hasError: false, error: null };
    }

    EB.prototype = Object.create(React.Component.prototype);
    EB.prototype.constructor = EB;

    EB.getDerivedStateFromError = function (error) {
        return { hasError: true, error: error };
    };

    EB.prototype.componentDidCatch = function (error, info) {
        console.error('ErrorBoundary caught:', error, info);
        if (typeof window.AnalyticsService !== 'undefined') {
            AnalyticsService.appError({
                error_type: 'render_error',
                component:  (info && info.componentStack) ? info.componentStack.split('\n')[1].trim() : 'unknown',
                message:    error ? error.message : 'unknown',
            });
        }
    };

    EB.prototype.render = function () {
        if (this.state.hasError) {
            return React.createElement('div', {
                className: 'bio-bg bio-bg-20 mt-4 p-5 rounded-xl border border-stone-100/50 max-w-md mx-auto bg-background-light h-[100dvh] flex flex-col items-center justify-center gap-6 px-8 text-center'
            },
                React.createElement('div', {
                    className: 'w-16 h-16 rounded-xl bg-warning-light flex items-center justify-center'
                },
                    React.createElement('span', {
                        className: 'material-symbols-outlined text-warning text-3xl'
                    }, 'error')
                ),
                React.createElement('h2', {
                    className: 'text-xl font-extrabold text-forest'
                }, 'Something went wrong'),
                React.createElement('span', {
                    className: 'text-sm font-medium text-forest/70 leading-relaxed'
                }, 'The app encountered an unexpected error. Your data is safe, try reloading the page. If the problem persists, please contact: '),
                React.createElement('a', {
                    href: 'mailto:support@moulddetect.ai',
                    className: 'text-forest font-bold underline'
                }, 'support@moulddetect.ai'),
                React.createElement('span', {
                    className: 'text-sm font-medium text-forest/70 leading-relaxed'
                }, ' with details about what you were doing when the error occurred.'),
                React.createElement('button', {
                    className: 'bg-forest text-white font-extrabold py-3 px-8 rounded-xl shadow-clay btn-nature',
                    onClick: function () { window.location.reload(); }
                }, 'Reload App')
            );
        }
        return this.props.children;
    };

    return EB;
})();

window.ErrorBoundary = ErrorBoundary;
