"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Dependencies = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const urql_1 = require("urql");
const Inbound_1 = require("../components/Dependencies/Inbound");
const Outbound_1 = require("../components/Dependencies/Outbound");
const BranchNodeBySlug_1 = require("../graphql/BranchNodeBySlug");
const Provider_1 = require("./Provider");
const nodeEdgesQuery = ``;
exports.Dependencies = ({ className, direction }) => {
    var _a, _b;
    const info = React.useContext(Provider_1.ActiveInfoContext);
    const [branchNodeResult] = urql_1.useQuery({
        query: BranchNodeBySlug_1.bundledBranchNode,
        variables: {
            workspaceSlug: info.workspace,
            projectSlug: info.project,
            branchSlug: info.branch,
            baseUri: info.node,
        },
    });
    const [nodeEdgesResult] = urql_1.useQuery({
        query: nodeEdgesQuery,
        variables: {
            branchNodeId: (_a = branchNodeResult.data) === null || _a === void 0 ? void 0 : _a.id,
            direction,
        },
        pause: !((_b = branchNodeResult.data) === null || _b === void 0 ? void 0 : _b.id),
    });
    if (branchNodeResult.fetching || nodeEdgesResult.fetching || !branchNodeResult.data) {
        return null;
    }
    const edges = nodeEdgesResult.data.sl_node_edges;
    if (direction === 'inbound') {
        return React.createElement(Inbound_1.InboundDependencies, { className: className, edges: edges, nodeType: branchNodeResult.data.type });
    }
    return React.createElement(Outbound_1.OutboundDependencies, { className: className, node: branchNodeResult.data, edges: edges });
};
//# sourceMappingURL=Dependencies.js.map