/*
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";
import { LegendItemInfo } from "./LegendItemInfo";
import { ContentControl } from "igniteui-react-core";
import { ILegendContext_$type } from "igniteui-react-core";
/**
 * @hidden
 */
var Legend = /** @class */ /*@__PURE__*/ (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) {
            var e_1, _a, e_2, _b;
            if (b.oldItems != null) {
                try {
                    for (var _c = tslib_1.__values(fromEn(b.oldItems)), _d = _c.next(); !_d.done; _d = _c.next()) {
                        var c = _d.value;
                        _this.bc.an(c);
                    }
                }
                catch (e_1_1) {
                    e_1 = { error: e_1_1 };
                }
                finally {
                    try {
                        if (_d && !_d.done && (_a = _c.return))
                            _a.call(_c);
                    }
                    finally {
                        if (e_1)
                            throw e_1.error;
                    }
                }
            }
            if (b.newItems != null) {
                try {
                    for (var _e = tslib_1.__values(fromEn(b.newItems)), _f = _e.next(); !_f.done; _f = _e.next()) {
                        var d = _f.value;
                        _this.bc.x(d);
                    }
                }
                catch (e_2_1) {
                    e_2 = { error: e_2_1 };
                }
                finally {
                    try {
                        if (_f && !_f.done && (_b = _e.return))
                            _b.call(_e);
                    }
                    finally {
                        if (e_2)
                            throw e_2.error;
                    }
                }
            }
        });
        return _this;
    }
    Legend.prototype.aj = function () {
        return new LegendView(this);
    };
    Legend.prototype.a8 = function (a) {
        _super.prototype.a8.call(this, a);
        this.bc = a;
    };
    Legend.prototype.bd = function (a) {
        return a.resolveLegendIndex();
    };
    Legend.prototype.bf = function (a) {
        return this.be(a);
    };
    Legend.prototype.addChildInOrder = function (a, b) {
        var e_3, _a;
        if (b.isStacked) {
            return;
        }
        if (!b.isUsableInLegend) {
            return;
        }
        var c = 0;
        try {
            for (var _b = tslib_1.__values(fromEnum(this.at)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var d = _c.value;
                var e = void 0;
                var f = void 0;
                var g = void 0;
                var h = this.ak.aa(d, e, f, g);
                e = h.p1;
                f = h.p2;
                g = h.p3;
                if (b.container != null && e != null && (this.bf(b.container) < this.bf(e) || (this.bf(b.container) == -1 && this.bf(e) == -1 && Base.getHashCodeStatic(b.container) < Base.getHashCodeStatic(e)))) {
                    break;
                }
                if (b.container != null && e != null && b.container == e && f != null) {
                    var i = this.bd(b);
                    var j = this.bd(f);
                    var k = this.bf(b);
                    var l = this.bf(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 (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            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;
            }
        }
    };
    Object.defineProperty(Legend.prototype, "bb", {
        get: function () {
            return this.ak.k ? 0 : 1;
        },
        set: function (a) {
            this.ak.k = a == 0;
        },
        enumerable: true,
        configurable: true
    });
    Legend.prototype.be = function (a) {
        return -1;
    };
    Object.defineProperty(Legend.prototype, "bh", {
        get: function () {
            return this.ak.v;
        },
        set: function (a) {
            this.ak.v = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(Legend.prototype, "bi", {
        get: function () {
            return this.ak.w;
        },
        set: function (a) {
            this.ak.w = a;
        },
        enumerable: true,
        configurable: true
    });
    Legend.$t = markType(Legend, 'Legend', LegendBase.$);
    return Legend;
}(LegendBase));
export { Legend };
/**
 * @hidden
 */
var LegendView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(LegendView, _super);
    function LegendView(a) {
        var _this = _super.call(this, a) || this;
        _this.ao = null;
        _this.ao = a;
        return _this;
    }
    LegendView.prototype.ak = function () {
        _super.prototype.ak.call(this);
    };
    LegendView.$t = markType(LegendView, 'LegendView', LegendBaseView.$);
    return LegendView;
}(LegendBaseView));
export { LegendView };
//# sourceMappingURL=Legend_combined.js.map
