/*
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 { 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
 */
export let Legend = /*@__PURE__*/ (() => {
    class Legend extends LegendBase {
        constructor() {
            super();
            this.ab = Legend.$;
            let a = this.au;
            a.collectionChanged = delegateCombine(a.collectionChanged, (a, b) => {
                if (b.oldItems != null) {
                    for (let c of fromEn(b.oldItems)) {
                        this.be.ao(c);
                    }
                }
                if (b.newItems != null) {
                    for (let d of fromEn(b.newItems)) {
                        this.be.y(d);
                    }
                }
            });
        }
        aj() {
            return new LegendView(this);
        }
        ba(a) {
            super.ba(a);
            this.be = a;
        }
        bf(a) {
            return a.resolveLegendIndex();
        }
        bh(a) {
            return this.bg(a);
        }
        addChildInOrder(a, b) {
            if (b.isStacked) {
                return;
            }
            if (!b.isUsableInLegend) {
                return;
            }
            let c = 0;
            for (let d of fromEnum(this.au)) {
                let e;
                let f;
                let g;
                let 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) {
                    let i = this.bf(b);
                    let j = this.bf(f);
                    let k = this.bh(b);
                    let l = this.bh(f);
                    let 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++;
            }
            this.au.insert(c, a);
            let n = new LegendItemInfo();
            n.c = a;
            n.a = b;
            let o = typeCast(ContentControl.$, a);
            if (o != null && o.content != null) {
                let p = typeCast(ILegendContext_$type, o.content);
                if (p != null) {
                    n.b = p;
                    n.d = p.itemLabel;
                }
            }
            this.a9(new LegendSizeChangedEventArgs());
        }
        get bd() {
            return this.ak.l ? 0 : 1;
        }
        set bd(a) {
            let b = this.ak.l;
            this.ak.l = a == 0;
            if (this.ak.l != b) {
                this.a9(new LegendSizeChangedEventArgs());
            }
        }
        bg(a) {
            return -1;
        }
        get bj() {
            return this.ak.w;
        }
        set bj(a) {
            this.ak.w = a;
        }
        get bk() {
            return this.ak.x;
        }
        set bk(a) {
            let b = this.ak.x;
            this.ak.x = a;
            if (a != b) {
                this.a9(new LegendSizeChangedEventArgs());
            }
        }
    }
    Legend.$t = markType(Legend, 'Legend', LegendBase.$);
    return Legend;
})();
/**
 * @hidden
 */
export let LegendView = /*@__PURE__*/ (() => {
    class LegendView extends LegendBaseView {
        constructor(a) {
            super(a);
            this.ap = null;
            this.ap = a;
        }
        al() {
            super.al();
        }
    }
    LegendView.$t = markType(LegendView, 'LegendView', LegendBaseView.$);
    return LegendView;
})();
