"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var LinkTransitions_1 = require("./LinkTransitions");
var findBackboneBundleNodes_1 = require("../Utils/findBackboneBundleNodes");
function bundleTransitions(xOffset, yOffset, clusterOffset, backboneOffset, duration, stratifiedMap, nodeList, annotationOpen, annotationHeight, bundleMap) {
    if (duration === void 0) { duration = 500; }
    xOffset = -xOffset;
    backboneOffset = -backboneOffset;
    var start = function () {
        return { x: 0, y: 0, opacity: 0 };
    };
    var enter = function (data) {
        var validity = true;
        var clusteredNodesInFront = 0;
        var x = LinkTransitions_1.getX(stratifiedMap[data].width, xOffset, backboneOffset);
        var backboneBundleNodes = findBackboneBundleNodes_1.default(stratifiedMap, bundleMap);
        var highestDepth = stratifiedMap[data].depth;
        var lowestDepth = stratifiedMap[data].depth;
        if (bundleMap) {
            for (var i = 0; i < bundleMap[data].bunchedNodes.length; i++) {
                if (stratifiedMap[bundleMap[data].bunchedNodes[i]].width != 0) {
                    validity = false;
                }
                if (stratifiedMap[bundleMap[data].bunchedNodes[i]].depth < highestDepth) {
                    highestDepth = stratifiedMap[bundleMap[data].bunchedNodes[i]].depth;
                }
                if (stratifiedMap[bundleMap[data].bunchedNodes[i]].depth > lowestDepth) {
                    lowestDepth = stratifiedMap[bundleMap[data].bunchedNodes[i]].depth;
                }
            }
            var node = stratifiedMap[data];
            for (var i = 0; i < nodeList.length; i++) {
                if (node.width === 0
                    && nodeList[i].width === 0
                    && nodeList[i].depth <= highestDepth
                    && backboneBundleNodes.includes(nodeList[i].id)) {
                    clusteredNodesInFront++;
                }
            }
        }
        clusteredNodesInFront = clusteredNodesInFront === 0 ? clusteredNodesInFront : clusteredNodesInFront - 1;
        var y = yOffset * highestDepth - ((yOffset - clusterOffset) * clusteredNodesInFront);
        if (annotationOpen !== -1 && highestDepth > annotationOpen) {
            y += annotationHeight;
        }
        var height = 0;
        height = clusterOffset * (bundleMap[data].bunchedNodes.length + 1);
        if (annotationOpen !== -1 && annotationOpen >= highestDepth && annotationOpen <= lowestDepth) {
            height += annotationHeight;
        }
        return {
            x: [x],
            y: [y],
            opactiy: 1,
            timing: { duration: duration },
            validity: validity,
            height: height
        };
    };
    var update = function (data) {
        var validity = true;
        var clusteredNodesInFront = 0;
        var x = LinkTransitions_1.getX(stratifiedMap[data].width, xOffset, backboneOffset);
        var backboneBundleNodes = findBackboneBundleNodes_1.default(stratifiedMap, bundleMap);
        var highestDepth = stratifiedMap[data].depth;
        var lowestDepth = stratifiedMap[data].depth;
        if (bundleMap) {
            for (var i = 0; i < bundleMap[data].bunchedNodes.length; i++) {
                if (stratifiedMap[bundleMap[data].bunchedNodes[i]].width != 0) {
                    validity = false;
                }
                if (stratifiedMap[bundleMap[data].bunchedNodes[i]].depth < highestDepth) {
                    highestDepth = stratifiedMap[bundleMap[data].bunchedNodes[i]].depth;
                }
                if (stratifiedMap[bundleMap[data].bunchedNodes[i]].depth > lowestDepth) {
                    lowestDepth = stratifiedMap[bundleMap[data].bunchedNodes[i]].depth;
                }
            }
            var node = stratifiedMap[data];
            for (var i = 0; i < nodeList.length; i++) {
                if (node.width === 0
                    && nodeList[i].width === 0
                    && nodeList[i].depth <= highestDepth
                    && backboneBundleNodes.includes(nodeList[i].id)) {
                    clusteredNodesInFront++;
                }
            }
        }
        clusteredNodesInFront = clusteredNodesInFront === 0 ? clusteredNodesInFront : clusteredNodesInFront - 1;
        var y = yOffset * highestDepth - ((yOffset - clusterOffset) * clusteredNodesInFront);
        if (annotationOpen !== -1 && highestDepth > annotationOpen) {
            y += annotationHeight;
        }
        var height = 0;
        height = clusterOffset * (bundleMap[data].bunchedNodes.length + 1);
        if (annotationOpen !== -1 && annotationOpen >= highestDepth && annotationOpen <= lowestDepth) {
            height += annotationHeight;
        }
        return {
            x: [x],
            y: [y],
            opactiy: 1,
            timing: { duration: duration },
            validity: validity,
            height: [height]
        };
    };
    return { enter: enter, leave: start, update: update, start: start };
}
exports.default = bundleTransitions;
//# sourceMappingURL=BundleTransitions.js.map