"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Graph = void 0;
const tslib_1 = require("tslib");
const lodash_1 = require("lodash");
const React = tslib_1.__importStar(require("react"));
const standalone_1 = require("vis-network/standalone");
const visOptions = {
    autoResize: true,
    layout: {
        hierarchical: {
            enabled: true,
            levelSeparation: 300,
            nodeSpacing: 150,
            direction: 'LR',
            sortMethod: 'directed',
            shakeTowards: 'leaves',
            edgeMinimization: false,
            blockShifting: false,
        },
    },
    physics: {
        enabled: false,
    },
    edges: {
        arrowStrikethrough: false,
        dashes: true,
        chosen: {
            edge: (values) => {
                values.dashes = false;
                values.color = 'rgb(166, 175, 180)';
                values.width = 3;
            },
        },
        width: 2,
        color: {
            color: 'rgb(216, 225, 230)',
        },
        font: {
            align: 'top',
            color: 'rgba(115, 134, 148, 0.6)',
            strokeWidth: 0,
        },
        arrows: {
            to: {
                enabled: true,
                scaleFactor: 0.5,
            },
        },
    },
    nodes: {
        shape: 'icon',
        labelHighlightBold: true,
        icon: {
            face: '"Font Awesome 5 Pro"',
            color: '#cfd9e0',
            weight: 900,
        },
    },
};
exports.Graph = React.memo(({ id, graph, events, getNetwork }) => {
    const container = React.useRef(null);
    React.useEffect(() => {
        if (!container.current)
            return;
        const visNetwork = new standalone_1.Network(container.current, graph, visOptions);
        visNetwork.once('afterDrawing', () => visNetwork === null || visNetwork === void 0 ? void 0 : visNetwork.setSize('', ''));
        if (getNetwork) {
            getNetwork(visNetwork);
        }
        if (visNetwork) {
            for (const eventName of Object.keys(events)) {
                const cb = events[eventName];
                if (cb) {
                    visNetwork.on(eventName, cb);
                }
            }
        }
        return () => {
            visNetwork.destroy();
        };
    });
    return React.createElement("div", { id: String(id), ref: container, style: { width: '100%', height: '100%' } });
}, (p, n) => {
    return p.id === n.id && lodash_1.isEqual(p.graph, n.graph);
});
//# sourceMappingURL=Graph.js.map