"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePrettifiedResponse = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const json_1 = require("../utils/prettifiers/json");
const prettify = (response, language) => {
    switch (language) {
        case 'json':
            return json_1.prettifyJSON(response);
        default:
            return String(response);
    }
};
exports.usePrettifiedResponse = (response, language) => {
    const [prettifiedResponse, setPrettifiedResponse] = React.useState(String(response));
    React.useEffect(() => {
        let isMounted = true;
        try {
            const v = prettify(response, language);
            if (!isMounted)
                return;
            setPrettifiedResponse(v);
        }
        catch (_a) {
            if (!isMounted)
                return;
            setPrettifiedResponse(String(response));
        }
        return () => {
            isMounted = false;
        };
    }, [response, language]);
    return prettifiedResponse;
};
//# sourceMappingURL=usePrettifiedResponse.js.map