"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TableOfContents = void 0;
const tslib_1 = require("tslib");
const TableOfContents_1 = require("@stoplight/ui-kit/TableOfContents");
const React = tslib_1.__importStar(require("react"));
const Provider_1 = require("../../containers/Provider");
const useComponents_1 = require("../../hooks/useComponents");
const useComputeToc_1 = require("../../hooks/useComputeToc");
exports.TableOfContents = ({ nodes, className }) => {
    const contents = useComputeToc_1.useComputeToc(nodes);
    return React.createElement(TableOfContents_1.TableOfContents, { className: className, contents: contents, rowComponent: ElementsTocRow });
};
const ElementsTocRow = props => {
    var _a;
    const { link: Link } = useComponents_1.useComponents();
    const info = React.useContext(Provider_1.ActiveInfoContext);
    if (!Link || !props.item.to) {
        return React.createElement(TableOfContents_1.DefaultRow, Object.assign({}, props));
    }
    const item = Object.assign(Object.assign({}, props.item), { isActive: props.item.to ? props.item.to === info.node : false, to: (_a = props.item.to) !== null && _a !== void 0 ? _a : '' });
    return (React.createElement(Link, { parent: null, index: 0, path: [item.to], node: Object.assign(Object.assign({}, info), { node: item.to, type: 'link', children: [], url: item.to }) },
        React.createElement(TableOfContents_1.DefaultRow, Object.assign({}, props, { item: item }))));
};
//# sourceMappingURL=index.js.map