/*
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, __values } from "tslib";
import { LegendBase } from "./LegendBase";
import { LegendBaseView } from "./LegendBaseView";
import { LegendSizeChangedEventArgs } from "./LegendSizeChangedEventArgs";
import { Base, fromEn, delegateCombine, fromEnum, typeCast, markType } from "igniteui-angular-core";
import { LegendItemInfo } from "./LegendItemInfo";
import { ContentControl } from "igniteui-angular-core";
import { ILegendContext_$type } from "igniteui-angular-core";
/**
 * @hidden
 */
var Legend = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(Legend, _super);
    function Legend() {
        var _this = _super.call(this) || this;
        _this.ab = Legend.$;
        var a = _this.au;
        a.collectionChanged = delegateCombine(a.collectionChanged, function (a, b) {
            var e_1, _a, e_2, _b;
            if (b.oldItems != null) {
                try {
                    for (var _c = __values(fromEn(b.oldItems)), _d = _c.next(); !_d.done; _d = _c.next()) {
                        var c = _d.value;
                        _this.be.ao(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 = __values(fromEn(b.newItems)), _f = _e.next(); !_f.done; _f = _e.next()) {
                        var d = _f.value;
                        _this.be.y(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.ba = function (a) {
        _super.prototype.ba.call(this, a);
        this.be = a;
    };
    Legend.prototype.bf = function (a) {
        return a.resolveLegendIndex();
    };
    Legend.prototype.bh = function (a) {
        return this.bg(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 = __values(fromEnum(this.au)), _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.ab(d, e, f, g);
                e = h.p1;
                f = h.p2;
                g = h.p3;
                if (b.container != null && e != null && (this.bh(b.container) < this.bh(e) || (this.bh(b.container) == -1 && this.bh(e) == -1 && Base.getHashCodeStatic(b.container) < Base.getHashCodeStatic(e)))) {
                    break;
                }
                if (b.container != null && e != null && b.container == e && f != null) {
                    var i = this.bf(b);
                    var j = this.bf(f);
                    var k = this.bh(b);
                    var l = this.bh(f);
                    var m = f.isFragment;
                    if (f.isVertical && !f.isStacked && !m) {
                        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.au.insert(c, a);
        var n = new LegendItemInfo();
        n.c = a;
        n.a = b;
        var o = typeCast(ContentControl.$, a);
        if (o != null && o.content != null) {
            var p = typeCast(ILegendContext_$type, o.content);
            if (p != null) {
                n.b = p;
                n.d = p.itemLabel;
            }
        }
        this.a9(new LegendSizeChangedEventArgs());
    };
    Object.defineProperty(Legend.prototype, "bd", {
        get: function () {
            return this.ak.l ? 0 : 1;
        },
        set: function (a) {
            var b = this.ak.l;
            this.ak.l = a == 0;
            if (this.ak.l != b) {
                this.a9(new LegendSizeChangedEventArgs());
            }
        },
        enumerable: false,
        configurable: true
    });
    Legend.prototype.bg = function (a) {
        return -1;
    };
    Object.defineProperty(Legend.prototype, "bj", {
        get: function () {
            return this.ak.w;
        },
        set: function (a) {
            this.ak.w = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(Legend.prototype, "bk", {
        get: function () {
            return this.ak.x;
        },
        set: function (a) {
            var b = this.ak.x;
            this.ak.x = a;
            if (a != b) {
                this.a9(new LegendSizeChangedEventArgs());
            }
        },
        enumerable: false,
        configurable: true
    });
    Legend.$t = markType(Legend, 'Legend', LegendBase.$);
    return Legend;
}(LegendBase));
export { Legend };
/**
 * @hidden
 */
var LegendView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(LegendView, _super);
    function LegendView(a) {
        var _this = _super.call(this, a) || this;
        _this.ap = null;
        _this.ap = a;
        return _this;
    }
    LegendView.prototype.al = function () {
        _super.prototype.al.call(this);
    };
    LegendView.$t = markType(LegendView, 'LegendView', LegendBaseView.$);
    return LegendView;
}(LegendBaseView));
export { LegendView };
