/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE  AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE:  you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { Base, Delegate_$type, Number_$type, markType } from "./type";
import { FastIterationDictionary$2 } from "./FastIterationDictionary$2";
import { DelayManager_CallbackSettings } from "./DelayManager_CallbackSettings";
/**
 * @hidden
 */
export let DelayManager = /*@__PURE__*/ (() => {
    class DelayManager extends Base {
        constructor(a, ..._rest) {
            super();
            this.a = null;
            this.c = null;
            this.d = null;
            this.e = 0;
            a = (a == void 0) ? 0 : a;
            switch (a) {
                case 0:
                    {
                        this.c = new FastIterationDictionary$2(Delegate_$type, DelayManager_CallbackSettings.$, 0);
                        this.d = new FastIterationDictionary$2(Number_$type, Delegate_$type, 0);
                    }
                    break;
                case 1:
                    {
                        let c = _rest[0];
                        {
                            this.c = new FastIterationDictionary$2(Delegate_$type, DelayManager_CallbackSettings.$, 0);
                            this.d = new FastIterationDictionary$2(Number_$type, Delegate_$type, 0);
                        }
                        this.a = c;
                    }
                    break;
            }
        }
        get b() {
            return this.a;
        }
        set b(a) {
            this.a = a;
        }
        f(a, b) {
            if (this.a == null) {
                return -1;
            }
            if (this.c.d(a)) {
                this.c.item(a).c = this.a.getCurrentRelativeTime();
            }
            else {
                let c = new DelayManager_CallbackSettings();
                c.a = this.e++;
                c.c = this.a.getCurrentRelativeTime();
                c.b = b;
                this.c.s(a, c);
                this.d.s(c.a, a);
            }
            this.a.executeDelayed(() => this.h(a), b);
            return this.c.item(a).a;
        }
        g(a) {
            if (this.d.d(a)) {
                let b = this.d.item(a);
                this.d.f(a);
                this.c.f(b);
            }
        }
        h(a) {
            if (this.c.d(a)) {
                let b = this.c.item(a);
                let c = this.a.getCurrentRelativeTime();
                let d = c - b.c;
                if (d >= b.b) {
                    a();
                    this.c.f(a);
                    this.d.f(b.a);
                }
                else {
                    this.a.executeDelayed(() => this.h(a), (b.b - d));
                }
            }
        }
    }
    DelayManager.$t = markType(DelayManager, 'DelayManager');
    return DelayManager;
})();
