"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "usePagesReactDevOverlay", {
    enumerable: true,
    get: function() {
        return usePagesReactDevOverlay;
    }
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
const _react = /*#__PURE__*/ _interop_require_default._(require("react"));
const _bus = /*#__PURE__*/ _interop_require_wildcard._(require("./bus"));
const _shared = require("../shared");
const shouldPreventDisplay = (errorType, preventType)=>{
    if (!preventType || !errorType) {
        return false;
    }
    return preventType.includes(errorType);
};
const usePagesReactDevOverlay = (preventDisplay)=>{
    const [state, dispatch] = (0, _shared.useErrorOverlayReducer)();
    _react.default.useEffect(()=>{
        _bus.on(dispatch);
        return function() {
            _bus.off(dispatch);
        };
    }, [
        dispatch
    ]);
    const onComponentError = _react.default.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
    };
};

if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
  Object.defineProperty(exports.default, '__esModule', { value: true });
  Object.assign(exports.default, exports);
  module.exports = exports.default;
}

//# sourceMappingURL=hooks.js.map