/*
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 { __extends } from "tslib";
import { Base, Type, typeCast, markType, getEnumerator, runOn, getBoxIfEnum } from "igniteui-angular-core";
import { WorkItem } from "./WorkItem";
import { Async_ForHelper } from "./Async_ForHelper";
import { Async_ForSliceHelper } from "./Async_ForSliceHelper";
import { WorkItemExtensions } from "./WorkItemExtensions";
import { WorkItem_WorkItemCatch$1 } from "./WorkItem_WorkItemCatch$1";
import { WorkItem_WorkItemSync } from "./WorkItem_WorkItemSync";
import { Async_WhileHelper } from "./Async_WhileHelper";
import { Async_WhileSliceHelper } from "./Async_WhileSliceHelper";
/**
 * @hidden
 */
var Async = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(Async, _super);
    function Async() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    Async.c = function (a, b, c, d) {
        return new Async_ForHelper(a, b, c, d).a();
    };
    Async.f = function (a, b, c, d) {
        return new Async_ForSliceHelper(a, b, c, d).a();
    };
    Async.d = function ($t, a, b) {
        return new Async_ForEachHelper$1($t, getEnumerator(a), b).a();
    };
    Async.e = function ($t, a, b) {
        return new Async_ForEachSliceHelper$1($t, getEnumerator(a), b).a();
    };
    Async.g = function (a, b, c) {
        if (c === void 0) {
            c = null;
        }
        if (a) {
            return b();
        }
        if (c != null) {
            return c();
        }
        return null;
    };
    Async.h = function (a, b) {
        try {
            return Async.b(a(), b);
        }
        catch (c) {
            b();
            throw c;
        }
    };
    Async.i = function ($tResult, a, b) {
        try {
            var c_1 = Type.getDefaultValue($tResult);
            return WorkItemExtensions.g($tResult, Async.b(WorkItemExtensions.e($tResult, a(), function (d) { return c_1 = WorkItemExtensions.m($tResult, d); }), b), function () { return c_1; });
        }
        catch (d) {
            b();
            throw d;
        }
    };
    Async.j = function ($tException, a, b, c) {
        if (c === void 0) {
            c = null;
        }
        try {
            return Async.b(Async.a($tException, a(), b), c);
        }
        catch (d) {
            try {
                var e = typeCast($tException, d);
                if (e != null) {
                    b(e);
                    return null;
                }
                throw d;
            }
            finally {
                if (c != null) {
                    var f = c;
                    c = null;
                    f();
                }
            }
        }
    };
    Async.k = function ($tException, $tResult, a, b, c) {
        if (c === void 0) {
            c = null;
        }
        try {
            var d_1 = Type.getDefaultValue($tResult);
            return WorkItemExtensions.g($tResult, Async.b(Async.a($tException, WorkItemExtensions.e($tResult, a(), function (e) { return d_1 = WorkItemExtensions.m($tResult, e); }), b), c), function () { return d_1; });
        }
        catch (e) {
            try {
                var f = typeCast($tException, e);
                if (f != null) {
                    b(f);
                    return null;
                }
                throw e;
            }
            finally {
                if (c != null) {
                    var g = c;
                    c = null;
                    g();
                }
            }
        }
    };
    Async.l = function ($tException1, $tException2, a, b, c, d) {
        if (d === void 0) {
            d = null;
        }
        try {
            return Async.b(Async.a($tException2, Async.a($tException1, a(), b), c, true), d);
        }
        catch (e) {
            try {
                var f = typeCast($tException1, e);
                if (f != null) {
                    b(f);
                    return null;
                }
                var g = typeCast($tException2, e);
                if (g != null) {
                    c(g);
                    return null;
                }
                throw e;
            }
            finally {
                if (d != null) {
                    var h = d;
                    d = null;
                    h();
                }
            }
        }
    };
    Async.m = function ($tException1, $tException2, $tException3, a, b, c, d, e) {
        if (e === void 0) {
            e = null;
        }
        try {
            return Async.b(Async.a($tException3, Async.a($tException2, Async.a($tException1, a(), b), c, true), d, true), e);
        }
        catch (f) {
            try {
                var g = typeCast($tException1, f);
                if (g != null) {
                    b(g);
                    return null;
                }
                var h = typeCast($tException2, f);
                if (h != null) {
                    c(h);
                    return null;
                }
                var i = typeCast($tException3, f);
                if (i != null) {
                    d(i);
                    return null;
                }
                throw f;
            }
            finally {
                if (e != null) {
                    var j = e;
                    e = null;
                    j();
                }
            }
        }
    };
    Async.a = function ($tException, a, b, c) {
        if (c === void 0) {
            c = false;
        }
        return new WorkItem_WorkItemCatch$1($tException, b, a, c);
    };
    Async.b = function (a, b) {
        if (b == null) {
            return a;
        }
        return new WorkItem_WorkItemSync(b, 1, a, false);
    };
    Async.o = function ($t, a, b) {
        return WorkItemExtensions.f($t, a, function (c) { return new Async_UsingHelper$1($t, WorkItemExtensions.m($t, c), b).b(); });
    };
    Async.n = function ($t, a, b) {
        return new Async_UsingHelper$1($t, a, b).b();
    };
    Async.p = function ($t, $tResult, a, b) {
        return new Async_UsingHelper$2($t, $tResult, a, b).b();
    };
    Async.q = function ($t, $tResult, a, b) {
        return WorkItemExtensions.l($t, $tResult, a, function (c) { return new Async_UsingHelper$2($t, $tResult, WorkItemExtensions.m($t, c), b).b(); });
    };
    Async.r = function (a, b) {
        return new Async_WhileHelper(a, b).a();
    };
    Async.s = function (a, b) {
        return new Async_WhileSliceHelper(a, b).a();
    };
    Async.$t = markType(Async, 'Async');
    return Async;
}(Base));
export { Async };
/**
 * @hidden
 */
var Async_ForEachHelper$1 = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(Async_ForEachHelper$1, _super);
    function Async_ForEachHelper$1($t, a, b) {
        var _this = _super.call(this) || this;
        _this.$t = null;
        _this.c = null;
        _this.d = null;
        _this.e = null;
        _this.$t = $t;
        _this.$type = _this.$type.specialize(_this.$t);
        _this.c = a;
        _this.e = b;
        _this.d = runOn(_this, _this.b);
        return _this;
    }
    Async_ForEachHelper$1.prototype.a = function () {
        var _this = this;
        return Async.h(this.d, function () {
            if (_this.c != null) {
                _this.c.dispose();
            }
        });
    };
    Async_ForEachHelper$1.prototype.b = function () {
        if (this.c.moveNext() == false) {
            return null;
        }
        return WorkItemExtensions.c(this.e(this.c.current), this.d);
    };
    Async_ForEachHelper$1.$t = markType(Async_ForEachHelper$1, 'Async_ForEachHelper$1');
    return Async_ForEachHelper$1;
}(Base));
export { Async_ForEachHelper$1 };
/**
 * @hidden
 */
var Async_ForEachSliceHelper$1 = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(Async_ForEachSliceHelper$1, _super);
    function Async_ForEachSliceHelper$1($t, a, b) {
        var _this = _super.call(this) || this;
        _this.$t = null;
        _this.c = null;
        _this.d = null;
        _this.e = null;
        _this.$t = $t;
        _this.$type = _this.$type.specialize(_this.$t);
        _this.c = a;
        _this.e = b;
        _this.d = runOn(_this, _this.b);
        return _this;
    }
    Async_ForEachSliceHelper$1.prototype.a = function () {
        var _this = this;
        return Async.h(this.d, function () {
            if (_this.c != null) {
                _this.c.dispose();
            }
        });
    };
    Async_ForEachSliceHelper$1.prototype.b = function () {
        while (this.c.moveNext()) {
            if (this.e(this.c.current) == false) {
                return WorkItem.d(this.d, 2);
            }
        }
        return null;
    };
    Async_ForEachSliceHelper$1.$t = markType(Async_ForEachSliceHelper$1, 'Async_ForEachSliceHelper$1');
    return Async_ForEachSliceHelper$1;
}(Base));
export { Async_ForEachSliceHelper$1 };
/**
 * @hidden
 */
var Async_UsingHelper$1 = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(Async_UsingHelper$1, _super);
    function Async_UsingHelper$1($t, a, b) {
        var _this = _super.call(this) || this;
        _this.$t = null;
        _this.a = null;
        _this.c = null;
        _this.$t = $t;
        _this.$type = _this.$type.specialize(_this.$t);
        _this.a = a;
        _this.c = b;
        return _this;
    }
    Async_UsingHelper$1.prototype.b = function () {
        var _this = this;
        return Async.h(function () { return _this.c(_this.a); }, function () {
            if (getBoxIfEnum(_this.$t, _this.a) != null) {
                _this.a.dispose();
            }
        });
    };
    Async_UsingHelper$1.$t = markType(Async_UsingHelper$1, 'Async_UsingHelper$1');
    return Async_UsingHelper$1;
}(Base));
export { Async_UsingHelper$1 };
/**
 * @hidden
 */
var Async_UsingHelper$2 = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(Async_UsingHelper$2, _super);
    function Async_UsingHelper$2($t, $tResult, a, b) {
        var _this = _super.call(this) || this;
        _this.$t = null;
        _this.$tResult = null;
        _this.a = null;
        _this.c = null;
        _this.$t = $t;
        _this.$tResult = $tResult;
        _this.$type = _this.$type.specialize(_this.$t, _this.$tResult);
        _this.a = a;
        _this.c = b;
        return _this;
    }
    Async_UsingHelper$2.prototype.b = function () {
        var _this = this;
        return Async.i(this.$tResult, function () { return _this.c(_this.a); }, function () {
            if (getBoxIfEnum(_this.$t, _this.a) != null) {
                _this.a.dispose();
            }
        });
    };
    Async_UsingHelper$2.$t = markType(Async_UsingHelper$2, 'Async_UsingHelper$2');
    return Async_UsingHelper$2;
}(Base));
export { Async_UsingHelper$2 };
