"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorViewer = void 0;
const tslib_1 = require("tslib");
const prism_http_1 = require("@stoplight/prism-http");
const ui_kit_1 = require("@stoplight/ui-kit");
const React = tslib_1.__importStar(require("react"));
const usePrettifiedResponse_1 = require("../../../hooks/usePrettifiedResponse");
exports.ErrorViewer = ({ error }) => {
    return (React.createElement("div", { className: "RequestMaker__ErrorViewer" }, error instanceof prism_http_1.ProblemJsonError ? (React.createElement(PrismErrorDisplay, { error: error })) : (React.createElement(GenericErrorDisplay, { errorMessage: error.message }))));
};
const GenericErrorDisplay = ({ errorMessage }) => {
    return (React.createElement("div", { className: "p-6" },
        React.createElement("h5", { className: "text-lg pb-2" },
            React.createElement(ui_kit_1.Tag, { intent: "danger", className: "mr-2" }, "Error"),
            "Error while making the request"),
        errorMessage));
};
const PrismErrorDisplay = ({ error }) => {
    const formattedDetails = usePrettifiedResponse_1.usePrettifiedResponse(error.additional || {}, 'json');
    return (React.createElement("div", { className: "p-6" },
        React.createElement("h5", { className: "text-lg pb-2" },
            React.createElement(ui_kit_1.Tag, { intent: "danger", className: "mr-2" }, error.status || '-'),
            error.message),
        error.detail && React.createElement("p", null, error.detail),
        error.additional && React.createElement(ui_kit_1.CodeViewer, { language: 'json', value: formattedDetails, className: "pt-5", showLineNumbers: true })));
};
//# sourceMappingURL=ErrorViewer.js.map