"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = require("react");
var translate_1 = require("../Utils/translate");
var Styles_1 = require("./Styles");
var react_move_1 = require("react-move");
var findBackboneBundleNodes_1 = require("../Utils/findBackboneBundleNodes");
var semantic_ui_react_1 = require("semantic-ui-react");
function BackboneNode(_a) {
    var first = _a.first, current = _a.current, node = _a.node, duration = _a.duration, radius = _a.radius, strokeWidth = _a.strokeWidth, textSize = _a.textSize, nodeMap = _a.nodeMap, annotationOpen = _a.annotationOpen, setAnnotationOpen = _a.setAnnotationOpen, bundleMap = _a.bundleMap, clusterLabels = _a.clusterLabels, eventConfig = _a.eventConfig, popupContent = _a.popupContent, annotationContent = _a.annotationContent;
    var padding = 15;
    // console.log(JSON.parse(JSON.stringify(node)));
    var glyph = react_1.default.createElement("circle", { onClick: function () { return nodeClicked(node); }, className: Styles_1.treeColor(current), r: radius, strokeWidth: strokeWidth });
    var backboneBundleNodes = findBackboneBundleNodes_1.default(nodeMap, bundleMap);
    if (eventConfig) {
        var eventType = node.metadata.type;
        if (eventType && eventType in eventConfig && eventType !== 'Root') {
            var _b = eventConfig[eventType], bundleGlyph = _b.bundleGlyph, currentGlyph = _b.currentGlyph, backboneGlyph = _b.backboneGlyph;
            if (backboneBundleNodes.includes(node.id)) {
                glyph = react_1.default.createElement("g", { onClick: function () { return nodeClicked(node); }, fontWeight: 'none' }, bundleGlyph);
            }
            else if (current) {
                glyph = react_1.default.createElement("g", { onClick: function () { return nodeClicked(node); }, fontWeight: 'bold' }, currentGlyph);
            }
            else {
                glyph = react_1.default.createElement("g", { onClick: function () { return nodeClicked(node); }, fontWeight: 'none' }, backboneGlyph);
            }
        }
    }
    var label = '';
    if (bundleMap && Object.keys(bundleMap).includes(node.id) && clusterLabels) {
        label = bundleMap[node.id].bundleLabel;
    }
    else if (!backboneBundleNodes.includes(node.id) || !clusterLabels) {
        label = node.label;
    }
    return (react_1.default.createElement(react_move_1.Animate, { start: { opacity: 0 }, enter: { opacity: [1], timing: { duration: 100, delay: first ? 0 : duration } } }, function (state) { return (react_1.default.createElement(react_1.default.Fragment, null,
        (popupContent !== undefined && nodeMap[node.id].depth > 0) ?
            (react_1.default.createElement(semantic_ui_react_1.Popup, { content: popupContent(node), trigger: glyph })) : (glyph),
        react_1.default.createElement("g", { style: { opacity: state.opacity }, transform: translate_1.default(padding, 0) },
            react_1.default.createElement(Label, { label: label, dominantBaseline: "middle", textAnchor: "start", fontSize: textSize, fontWeight: current ? 'bold' : 'regular', onClick: function () { return labelClicked(node); } }),
            (annotationOpen !== -1 && nodeMap[node.id].depth === annotationOpen && annotationContent) ? (react_1.default.createElement("g", null, annotationContent(nodeMap[node.id]))) : (react_1.default.createElement("g", null))))); }));
    function labelClicked(node) {
        if (!annotationContent) {
            return;
        }
        else if (annotationOpen === nodeMap[node.id].depth) {
            setAnnotationOpen(-1);
        }
        else {
            setAnnotationOpen(nodeMap[node.id].depth);
        }
    }
    function nodeClicked(node) {
        if (annotationOpen !== -1 && (nodeMap[node.id].width > 0 || nodeMap[node.id].depth !== annotationOpen)) {
            setAnnotationOpen(-1);
        }
    }
}
exports.default = BackboneNode;
var Label = function (props) {
    return react_1.default.createElement("text", __assign({}, props), props.label);
};
//# sourceMappingURL=BackboneNode.js.map