"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useCircleLayout = void 0;
var react_1 = require("react");
var circular_1 = __importDefault(require("graphology-layout/circular"));
var graphology_layout_forceatlas2_1 = __importDefault(require("graphology-layout-forceatlas2"));
var worker_1 = __importDefault(require("graphology-layout-forceatlas2/worker"));
var useAnimatedGraphLayout_1 = require("./useAnimatedGraphLayout");
var useDidUpdateEffect_1 = require("../../../hooks/useDidUpdateEffect");
var useCircleLayout = function (_a) {
    var graph = _a.graph, newNodesIds = _a.newNodesIds, animationDuration = _a.animationDuration, relayoutTrigger = _a.relayoutTrigger;
    var layoutSettings = (0, react_1.useMemo)(function () {
        circular_1.default.assign(graph);
        return {
            settings: __assign(__assign({}, graphology_layout_forceatlas2_1.default.inferSettings(graph)), { gravity: 1 })
        };
    }, [graph]);
    (0, useDidUpdateEffect_1.useDidUpdateEffect)(function () {
        if (newNodesIds === null || newNodesIds === void 0 ? void 0 : newNodesIds.length) {
            var tempGraph_1 = graph.copy();
            circular_1.default.assign(tempGraph_1);
            newNodesIds.forEach(function (id) {
                graph.setNodeAttribute(id, 'x', tempGraph_1.getNodeAttribute(id, 'x'));
                graph.setNodeAttribute(id, 'y', tempGraph_1.getNodeAttribute(id, 'y'));
            });
        }
    }, [newNodesIds]);
    (0, useAnimatedGraphLayout_1.useAnimatedGraphLayout)({
        workerLayout: worker_1.default,
        layoutSettings: layoutSettings,
        animationDuration: animationDuration,
        graph: graph,
        relayoutTrigger: relayoutTrigger
    });
};
exports.useCircleLayout = useCircleLayout;
