"use strict";
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntervalManager = void 0;
var lodash_1 = require("./lodash");
var IntervalManager = (function () {
    function IntervalManager(global, options) {
        this._store = [];
        this._debug = false;
        this._debug = (0, lodash_1.get)(options, 'debug', false);
        this._native = {
            setInterval: global.setInterval,
            clearInterval: global.clearInterval,
        };
        global.setInterval = (0, lodash_1.bind)(this.setInterval, this);
        global.clearInterval = (0, lodash_1.bind)(this.clearInterval, this);
    }
    Object.defineProperty(IntervalManager.prototype, "debug", {
        get: function () {
            return this._debug;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(IntervalManager.prototype, "length", {
        get: function () {
            return this._store.length;
        },
        enumerable: false,
        configurable: true
    });
    IntervalManager.prototype.setInterval = function () {
        var args = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            args[_i] = arguments[_i];
        }
        var nid = this._native.setInterval.apply(null, __spreadArray([], args, true));
        this._store.push(nid);
        if (this.debug) {
            console.log('# setInterval id:', nid, '--', this.length);
        }
        return nid;
    };
    IntervalManager.prototype.clearInterval = function (handle) {
        this._native.clearInterval.call(null, handle);
        (0, lodash_1.remove)(this._store, function (n) { return n === handle; });
        if (this.debug) {
            console.log('# clearInterval handle:', handle, '--', this.length);
        }
    };
    IntervalManager.prototype.list = function () {
        return this._store;
    };
    return IntervalManager;
}());
exports.IntervalManager = IntervalManager;
//# sourceMappingURL=interval-manager.js.map