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);
};
import { useMemo } from 'react';
import circular from 'graphology-layout/circular';
import forceAtlas2 from 'graphology-layout-forceatlas2';
import FA2Layout from 'graphology-layout-forceatlas2/worker';
import { useAnimatedGraphLayout } from './useAnimatedGraphLayout';
import { useDidUpdateEffect } from '../../../hooks/useDidUpdateEffect';
export var useCircleLayout = function (_a) {
    var graph = _a.graph, newNodesIds = _a.newNodesIds, animationDuration = _a.animationDuration, relayoutTrigger = _a.relayoutTrigger;
    var layoutSettings = useMemo(function () {
        circular.assign(graph);
        return {
            settings: __assign(__assign({}, forceAtlas2.inferSettings(graph)), { gravity: 1 })
        };
    }, [graph]);
    useDidUpdateEffect(function () {
        if (newNodesIds === null || newNodesIds === void 0 ? void 0 : newNodesIds.length) {
            var tempGraph_1 = graph.copy();
            circular.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]);
    useAnimatedGraphLayout({
        workerLayout: FA2Layout,
        layoutSettings: layoutSettings,
        animationDuration: animationDuration,
        graph: graph,
        relayoutTrigger: relayoutTrigger
    });
};
