/*
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 * as tslib_1 from "tslib";
import { LegendBase } from "./LegendBase";
import { LegendBaseView } from "./LegendBaseView";
import { Base, fromEn, delegateCombine, fromEnum, typeCast, markType } from "igniteui-react-core/ES5/type";
import { LegendItemInfo } from "./LegendItemInfo";
import { ContentControl } from "igniteui-react-core/ES5/ContentControl";
import { ILegendContext_$type } from "igniteui-react-core/ES5/ILegendContext";
var Legend = /** @class */ (function (_super) {
    tslib_1.__extends(Legend, _super);
    function Legend() {
        var _this = _super.call(this) || this;
        _this.ab = Legend.$;
        var a = _this.at;
        a.collectionChanged = delegateCombine(a.collectionChanged, function (a, b) {
            if (b.oldItems != null) {
                try {
                    for (var _a = tslib_1.__values(fromEn(b.oldItems)), _b = _a.next(); !_b.done; _b = _a.next()) {
                        var c = _b.value;
                        _this.ba.ag(c);
                    }
                }
                catch (e_1_1) { e_1 = { error: e_1_1 }; }
                finally {
                    try {
                        if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
                    }
                    finally { if (e_1) throw e_1.error; }
                }
            }
            if (b.newItems != null) {
                try {
                    for (var _d = tslib_1.__values(fromEn(b.newItems)), _e = _d.next(); !_e.done; _e = _d.next()) {
                        var d = _e.value;
                        _this.ba.s(d);
                    }
                }
                catch (e_2_1) { e_2 = { error: e_2_1 }; }
                finally {
                    try {
                        if (_e && !_e.done && (_f = _d.return)) _f.call(_d);
                    }
                    finally { if (e_2) throw e_2.error; }
                }
            }
            var e_1, _c, e_2, _f;
        });
        return _this;
    }
    Legend.prototype.aj = function () {
        return new LegendView(this);
    };
    Legend.prototype.a5 = function (a) {
        _super.prototype.a5.call(this, a);
        this.ba = a;
    };
    Legend.prototype.bb = function (a) {
        return a.resolveLegendIndex();
    };
    Legend.prototype.bd = function (a) {
        return this.bc(a);
    };
    Legend.prototype.addChildInOrder = function (a, b) {
        if (b.isStacked) {
            return;
        }
        if (!b.isUsableInLegend) {
            return;
        }
        var c = 0;
        try {
            for (var _a = tslib_1.__values(fromEnum(this.at)), _b = _a.next(); !_b.done; _b = _a.next()) {
                var d = _b.value;
                var e = void 0;
                var f = void 0;
                var g = void 0;
                var h = this.ak.v(d, e, f, g);
                e = h.p1;
                f = h.p2;
                g = h.p3;
                if (b.container != null && e != null && (this.bd(b.container) < this.bd(e) || (this.bd(b.container) == -1 && this.bd(e) == -1 && Base.getHashCodeStatic(b.container) < Base.getHashCodeStatic(e)))) {
                    break;
                }
                if (b.container != null && e != null && b.container == e && f != null) {
                    var i = this.bb(b);
                    var j = this.bb(f);
                    var k = this.bd(b);
                    var l = this.bd(f);
                    if (f.isVertical && !f.isStacked) {
                        if (l == -1 && k == -1) {
                            c = 0;
                            break;
                        }
                        if (k < l || l == -1) {
                            break;
                        }
                    }
                    if (i <= j) {
                        break;
                    }
                }
                c++;
            }
        }
        catch (e_3_1) { e_3 = { error: e_3_1 }; }
        finally {
            try {
                if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
            }
            finally { if (e_3) throw e_3.error; }
        }
        this.at.insert(c, a);
        var m = new LegendItemInfo();
        m.c = a;
        m.a = b;
        var n = typeCast(ContentControl.$, a);
        if (n != null && n.content != null) {
            var o = typeCast(ILegendContext_$type, n.content);
            if (o != null) {
                m.b = o;
                m.d = o.itemLabel;
            }
        }
        var e_3, _c;
    };
    Object.defineProperty(Legend.prototype, "a9", {
        get: function () {
            return this.ak.g ? 0 : 0;
        },
        set: function (a) {
            this.ak.g = a == 0;
        },
        enumerable: true,
        configurable: true
    });
    Legend.prototype.bc = function (a) {
        return -1;
    };
    Object.defineProperty(Legend.prototype, "bf", {
        get: function () {
            return this.ak.q;
        },
        set: function (a) {
            this.ak.q = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Legend.prototype, "bg", {
        get: function () {
            return this.ak.r;
        },
        set: function (a) {
            this.ak.r = a;
        },
        enumerable: true,
        configurable: true
    });
    Legend.$t = markType(Legend, 'Legend', LegendBase.$);
    return Legend;
}(LegendBase));
export { Legend };
var LegendView = /** @class */ (function (_super) {
    tslib_1.__extends(LegendView, _super);
    function LegendView(a) {
        var _this = _super.call(this, a) || this;
        _this.ah = null;
        _this.ah = a;
        return _this;
    }
    LegendView.prototype.ad = function () {
        _super.prototype.ad.call(this);
    };
    LegendView.$t = markType(LegendView, 'LegendView', LegendBaseView.$);
    return LegendView;
}(LegendBaseView));
export { LegendView };
