"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useParsedData = exports.ParsedDocs = exports.Docs = exports.NodeTypeComponent = void 0;
const tslib_1 = require("tslib");
const types_1 = require("@stoplight/types");
const React = tslib_1.__importStar(require("react"));
const useParsedValue_1 = require("../../hooks/useParsedValue");
const Article_1 = require("./Article");
const HttpOperation_1 = require("./HttpOperation");
const HttpService_1 = require("./HttpService");
const Model_1 = require("./Model");
const UnsupportedNodeType = () => {
    return null;
};
exports.NodeTypeComponent = {
    [types_1.NodeType.Article]: Article_1.Article,
    [types_1.NodeType.HttpOperation]: HttpOperation_1.HttpOperation,
    [types_1.NodeType.HttpService]: HttpService_1.HttpService,
    [types_1.NodeType.Model]: Model_1.Model,
    [types_1.NodeType.HttpServer]: UnsupportedNodeType,
    [types_1.NodeType.Generic]: UnsupportedNodeType,
    [types_1.NodeType.TableOfContents]: UnsupportedNodeType,
    [types_1.NodeType.Unknown]: UnsupportedNodeType,
};
exports.Docs = React.memo(({ nodeType, nodeData, className }) => {
    const parsedData = useParsedData(nodeType, nodeData);
    return React.createElement(exports.ParsedDocs, { className: className, nodeData: parsedData, nodeType: nodeType });
});
exports.ParsedDocs = ({ nodeType, nodeData, className }) => {
    const Component = exports.NodeTypeComponent[nodeType];
    if (!Component)
        return null;
    return React.createElement(Component, { className: className, data: nodeData });
};
function useParsedData(nodeType, data) {
    const isParseable = nodeType === types_1.NodeType.HttpOperation || nodeType === types_1.NodeType.HttpService || nodeType === types_1.NodeType.Model;
    const parsedData = useParsedValue_1.useParsedValue(isParseable ? data : null);
    return isParseable ? parsedData : data;
}
exports.useParsedData = useParsedData;
//# sourceMappingURL=index.js.map