"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Docs = void 0;
const tslib_1 = require("tslib");
const json_1 = require("@stoplight/json");
const lodash_1 = require("lodash");
const React = tslib_1.__importStar(require("react"));
const urql_1 = require("urql");
const Docs_1 = require("../components/Docs");
const Skeleton_1 = require("../components/Docs/Skeleton");
const BranchNodeBySlug_1 = require("../graphql/BranchNodeBySlug");
const Provider_1 = require("./Provider");
const DocsPopup = React.memo(({ nodeType, nodeData, className }) => {
    const document = Docs_1.useParsedData(nodeType, nodeData);
    const inlineRefResolver = React.useCallback(({ pointer }, _, schema) => pointer === null ? null : lodash_1.get(lodash_1.isObject(document) ? document : schema, json_1.pointerToPath(pointer)), [document]);
    return (React.createElement(Provider_1.InlineRefResolverContext.Provider, { value: inlineRefResolver },
        React.createElement(Docs_1.ParsedDocs, { className: className, nodeType: nodeType, nodeData: document })));
});
exports.Docs = ({ className, node }) => {
    const info = React.useContext(Provider_1.ActiveInfoContext);
    const [{ data: result, fetching }] = urql_1.useQuery({
        query: BranchNodeBySlug_1.bundledBranchNode,
        variables: {
            workspaceSlug: info.workspace,
            projectSlug: info.project,
            branchSlug: info.branch,
            uri: node || info.node,
        },
    });
    if (fetching || !result) {
        return React.createElement(Skeleton_1.DocsSkeleton, null);
    }
    return (React.createElement(DocsPopup, { nodeType: result.bundledBranchNode.type, nodeData: result.bundledBranchNode.data, className: className }));
};
//# sourceMappingURL=Docs.js.map