import { Graph } from '@api-client/graph/graph/Graph.js';
import { getObjectBoundingClientRect } from '../../lib/PositionUtils.js';
// 01 - external association
// 10 - association (internal)
// 20 - parent association
// 40 - self association
export var LayoutWeight;
(function (LayoutWeight) {
    LayoutWeight[LayoutWeight["External"] = 1] = "External";
    LayoutWeight[LayoutWeight["Internal"] = 10] = "Internal";
    LayoutWeight[LayoutWeight["Parent"] = 40] = "Parent";
    LayoutWeight[LayoutWeight["Self"] = 80] = "Self";
})(LayoutWeight || (LayoutWeight = {}));
/**
 * A helper library that computes positioning of a data model
 * in the visualization workspace.
 */
export class WorkspaceLayout {
    workspace;
    readPositions = {};
    /**
     * Direction for rank nodes. Can be TB, BT, LR, or RL, where T = top, B = bottom, L = left, and R = right.
     */
    rankDir;
    /**
     * Alignment for rank nodes. Can be UL, UR, DL, or DR, where U = up, D = down, L = left, and R = right.
     */
    align;
    /**
     * Type of algorithm to assign a rank to each node in the input graph.
     */
    ranker;
    /**
     * If set to greedy, uses a greedy heuristic for finding a feedback arc set for a graph.
     * A feedback arc set is a set of edges that can be removed to make a graph acyclic.
     */
    acyclicer;
    /**
     * Number of pixels that separate edges horizontally in the layout.
     */
    edgeSeparation = 20;
    /**
     * Number of pixels between each rank in the layout.
     */
    rankSeparation = 60; // 80
    /**
     * Number of pixels that separate nodes horizontally in the layout.
     */
    nodeSeparation = 60; // 80
    /**
     * Graph margin LR
     */
    marginX = 40;
    /**
     * Graph margin TB
     */
    marginY = 40;
    constructor(workspace) {
        this.workspace = workspace;
    }
    /**
     * Reads workspace object dimensions
     * @param {string} id Domain id of the object
     * @returns {DOMRect}
     */
    readDimensions(id) {
        if (this.readPositions[id]) {
            return this.readPositions[id];
        }
        const element = this.workspace.querySelector(`[data-key="${id}"]`);
        if (!element) {
            return undefined;
        }
        const rect = getObjectBoundingClientRect(element, this.workspace);
        this.readPositions[id] = rect;
        return rect;
    }
    initGraph() {
        const g = new Graph();
        const { rankDir, align, ranker, acyclicer, edgeSeparation, rankSeparation, nodeSeparation, marginX, marginY } = this;
        g.setGraph({
            edgeSeparation,
            rankSeparation,
            nodeSeparation,
            rankDir,
            align,
            ranker,
            acyclicer,
            marginX,
            marginY,
        });
        // g.setDefaultEdgeLabel(() => { return {}; });
        return g;
    }
}
//# sourceMappingURL=WorkspaceLayout.js.map