"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addEventListenerToPieSegment = void 0;
/** @ignore */
var isListenerBlocked = false;
/** @ignore */
var addEventListenerToPieSegment = function (ps, el, animate) {
    var eventListener = function (e) {
        if (!animate) {
            ps.isSelected = !ps.isSelected;
            return;
        }
        // ANIMATE
        if (!isListenerBlocked) {
            var ROUNDS_1 = 10;
            var directionDown = ps.isSelected;
            var start_1 = directionDown ? ps.delta : 0;
            var d_1 = directionDown ? -ps.delta / ROUNDS_1 : ps.delta / ROUNDS_1;
            isListenerBlocked = true;
            ps.isSelected = !ps.isSelected;
            (function myLoop(k) {
                setTimeout(function () {
                    ps.shift = start_1 + d_1 * k;
                    if (k === ROUNDS_1) {
                        isListenerBlocked = false;
                    }
                    if (++k <= ROUNDS_1)
                        myLoop(k);
                }, 20);
            })(1);
        }
    };
    el.addEventListener("click", eventListener);
    return {
        eventListener: eventListener,
        eventType: "click",
        element: el,
        delete: function () { return el.removeEventListener("click", eventListener); }
    };
};
exports.addEventListenerToPieSegment = addEventListenerToPieSegment;
