/*
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 { Base, fromEn, delegateCombine, fromEnum, typeCast, markType } from "igniteui-react-core/ES2015/type";
import { LegendItemInfo } from "./LegendItemInfo";
import { ContentControl } from "igniteui-react-core/ES2015/ContentControl";
import { ILegendContext_$type } from "igniteui-react-core/ES2015/ILegendContext";
export class Legend extends LegendBase {
    constructor() {
        super();
        this.ab = Legend.$;
        let a = this.at;
        a.collectionChanged = delegateCombine(a.collectionChanged, (a, b) => {
            if (b.oldItems != null) {
                for (let c of fromEn(b.oldItems)) {
                    this.ba.ag(c);
                }
            }
            if (b.newItems != null) {
                for (let d of fromEn(b.newItems)) {
                    this.ba.s(d);
                }
            }
        });
    }
    aj() {
        return new LegendView(this);
    }
    a5(a) {
        super.a5(a);
        this.ba = a;
    }
    bb(a) {
        return a.resolveLegendIndex();
    }
    bd(a) {
        return this.bc(a);
    }
    addChildInOrder(a, b) {
        if (b.isStacked) {
            return;
        }
        if (!b.isUsableInLegend) {
            return;
        }
        let c = 0;
        for (let d of fromEnum(this.at)) {
            let e;
            let f;
            let g;
            let 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) {
                let i = this.bb(b);
                let j = this.bb(f);
                let k = this.bd(b);
                let 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++;
        }
        this.at.insert(c, a);
        let m = new LegendItemInfo();
        m.c = a;
        m.a = b;
        let n = typeCast(ContentControl.$, a);
        if (n != null && n.content != null) {
            let o = typeCast(ILegendContext_$type, n.content);
            if (o != null) {
                m.b = o;
                m.d = o.itemLabel;
            }
        }
    }
    get a9() {
        return this.ak.g ? 0 : 0;
    }
    set a9(a) {
        this.ak.g = a == 0;
    }
    bc(a) {
        return -1;
    }
    get bf() {
        return this.ak.q;
    }
    set bf(a) {
        this.ak.q = a;
    }
    get bg() {
        return this.ak.r;
    }
    set bg(a) {
        this.ak.r = a;
    }
}
Legend.$t = markType(Legend, 'Legend', LegendBase.$);
export class LegendView extends LegendBaseView {
    constructor(a) {
        super(a);
        this.ah = null;
        this.ah = a;
    }
    ad() {
        super.ad();
    }
}
LegendView.$t = markType(LegendView, 'LegendView', LegendBaseView.$);
