import React from 'react';
import * as Bus from './bus';
import { useErrorOverlayReducer } from '../shared';
const shouldPreventDisplay = (errorType, preventType)=>{
    if (!preventType || !errorType) {
        return false;
    }
    return preventType.includes(errorType);
};
export const usePagesReactDevOverlay = (preventDisplay)=>{
    const [state, dispatch] = useErrorOverlayReducer();
    React.useEffect(()=>{
        Bus.on(dispatch);
        return function() {
            Bus.off(dispatch);
        };
    }, [
        dispatch
    ]);
    const onComponentError = React.useCallback((_error, _componentStack)=>{
    // TODO: special handling
    }, []);
    const hasBuildError = state.buildError != null;
    const hasRuntimeErrors = Boolean(state.errors.length);
    const errorType = hasBuildError ? 'build' : hasRuntimeErrors ? 'runtime' : null;
    const isMounted = errorType !== null;
    const displayPrevented = shouldPreventDisplay(errorType, preventDisplay);
    return {
        isMounted,
        displayPrevented,
        hasBuildError,
        hasRuntimeErrors,
        state,
        onComponentError
    };
};

//# sourceMappingURL=hooks.js.map