"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WithErrorBoundary = void 0;
const tslib_1 = require("tslib");
const react_core_1 = require("@patternfly/react-core");
const react_1 = tslib_1.__importDefault(require("react"));
const react_error_boundary_1 = require("react-error-boundary");
const ui_1 = require("../ui");
const ErrorMonitorContext_1 = require("./ErrorMonitorContext");
const getErrorFallbackComponent = ({ title, content = 'There was an internal error', showReloadAction = true, }) => {
    const FallbackComponent = ({ resetErrorBoundary }) => {
        const primaryAction = showReloadAction ? (react_1.default.createElement(react_core_1.Button, { onClick: resetErrorBoundary, variant: react_core_1.ButtonVariant.link, isInline: true, key: "reset-error-boundary" }, "try again")) : null;
        return react_1.default.createElement(ui_1.ErrorState, { content, primaryAction, title });
    };
    return FallbackComponent;
};
const WithErrorBoundary = (_a) => {
    var { children } = _a, props = tslib_1.__rest(_a, ["children"]);
    const { captureException } = (0, ErrorMonitorContext_1.useErrorMonitor)();
    const errorHandler = (error) => {
        captureException(error, props.title);
    };
    return (react_1.default.createElement(react_error_boundary_1.ErrorBoundary, { FallbackComponent: getErrorFallbackComponent(props), onError: errorHandler }, children));
};
exports.WithErrorBoundary = WithErrorBoundary;
//# sourceMappingURL=WithErrorBoundary.js.map