/*
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 { HorizontalAnchoredCategorySeries } from "./HorizontalAnchoredCategorySeries";
import { DependencyProperty } from "igniteui-angular-core";
import { ConsolidatedItemsPosition_$type } from "./ConsolidatedItemsPosition";
import { Defaults } from "./Defaults";
import { runOn, enumGetBox, markType, markDep, fromEnum } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { Rectangle } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_, isInfinity } from "igniteui-angular-core";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
/**
 * @hidden
 */
export let ColumnSeries = /*@__PURE__*/ (() => {
    class ColumnSeries extends HorizontalAnchoredCategorySeries {
        constructor() {
            super();
            this.vh = null;
            this.vc = 0;
            this.ab = ColumnSeries.$;
            this.uv = 2;
        }
        get_di() {
            return true;
        }
        get_d3() {
            return true;
        }
        gw() {
            if (!isNaN_(this.gv)) {
                return super.gw();
            }
            return Defaults.h;
        }
        bx() {
            return new ColumnSeriesView(this);
        }
        l2(a) {
            super.l2(a);
            this.vb = a;
        }
        b3() {
            if (this.b4 == 0) {
                return 2;
            }
            return super.b3();
        }
        r3() {
            return 1;
        }
        get_c2() {
            return true;
        }
        preferredCategoryMode(a) {
            return this.uv;
        }
        pz(a) {
            if (this.vh == null) {
                this.vh = runOn(this, this.ve);
            }
            let b = this.uy != null ? this.uy : this.yAxis;
            let c = this.us;
            return this.tq.c$d(this, a, c, b, this.rt, this.st(this.b0), this.su(this.b0), this.vh);
        }
        ex(a, b) {
            if (this.e0(a, b)) {
                return true;
            }
            if (this.qk(a, b)) {
                return true;
            }
            return false;
        }
        k0(a, b) {
            super.k0(a, b);
            let c = b;
            if (a && c.db != null) {
                c.db.count = 0;
            }
        }
        gc() {
            return this.us.k3(this.b0.bv, this.b0.bu, this.getEffectiveViewport1(this.b0));
        }
        tb(a, b) {
            super.tb(a, b);
            let c = a.f;
            if (!b.t()) {
                return;
            }
            let d = b.bv;
            let e = b.bu;
            let f = this.getEffectiveViewport1(b);
            let g = new ScalerParams(0, d, e, this.uy.cg, f);
            g.b = this.ge();
            let h = new ScalerParams(0, d, e, this.us.cg, f);
            let i = this.uy;
            let j = i.ei(i.l5, g);
            let k = this.us.k3(d, e, f);
            let l = this.us;
            let m = b;
            if (isNaN_(k) || isInfinity(k)) {
                m.db.count = 0;
                return;
            }
            this.r1.a0(this, this.sl(), runOn(this, this.rm), this.st(b), this.su(b));
            this.r1.r = this.vf;
            this.r1.s = this.vg;
            this.r1.k = this.vf;
            this.r1.l = this.vg;
            let n = false;
            let o = this.r1.b;
            if (o != null) {
                n = true;
            }
            let p = this.us.cm;
            let q = p ? this.us : null;
            let r = this.valueColumn.count;
            let s = this.st(b);
            let t = 0;
            for (let u = 0; u < c.count; ++u) {
                let v = c._inner[u][0] - 0.5 * k;
                let w = this.ve(c._inner[u]);
                let x = j;
                w = Math.max(w, -100);
                x = Math.min(x, e.bottom + 100);
                let y = Math.abs(x - w);
                if (isInfinity(y) || isNaN_(y)) {
                    continue;
                }
                let z = m.db.item(t);
                t++;
                z.width = k;
                z.height = y;
                if (n) {
                    this.s7(c, u, r, l, h, b.q);
                }
                if (z.dataContext != null) {
                    let aa = z.dataContext;
                    if (s == 1) {
                        let ab = this.r1.au(r, u)[0];
                        if (ab >= 0 && ab < this.ck.count) {
                            if (q != null && q.i$b != null && q.i$b.count > ab) {
                                ab = q.i$b._inner[ab];
                            }
                            aa.item = this.ck.item(ab);
                        }
                    }
                    else {
                        aa.item = null;
                    }
                }
                this.r1.ad(z, false, false, false, false);
                z.am = this.r1.k;
                z.an = this.r1.l;
                m.dg(z, v, Math.min(x, w));
            }
            m.db.count = t;
            b.cy(a);
        }
        get vd() {
            return this.vc;
        }
        set vd(a) {
            if (this.vd != a) {
                let b = this.vd;
                this.vc = a;
                this.raisePropertyChanged("ConsolidatedColumnVerticalPosition", enumGetBox(ConsolidatedItemsPosition_$type, b), enumGetBox(ConsolidatedItemsPosition_$type, this.vd));
            }
        }
        ve(a) {
            if (a == null || a.length < 3) {
                return NaN;
            }
            switch (this.vd) {
                case 0: return a[1];
                case 1: return a[2];
                case 2: return (a[1] + a[2]) / 2;
                case 3:
                    let b = (a[1] + a[2]) / 2;
                    if (this.yAxis == null) {
                        return b;
                    }
                    let c = this.yAxis.el(b, new ScalerParams(1, this.cd.tp, this.cd.to, this.yAxis.cg));
                    if (c < this.yAxis.l5) {
                        return a[2];
                    }
                    else {
                        return a[1];
                    }
                case 4:
                    let d = (a[1] + a[2]) / 2;
                    let e = this.yAxis.el(d, new ScalerParams(1, this.cd.tp, this.cd.to, this.yAxis.cg));
                    if (this.yAxis == null) {
                        return d;
                    }
                    if (e < this.yAxis.l5) {
                        return a[1];
                    }
                    else {
                        return a[2];
                    }
                default: return (a[1] + a[2]) / 2;
            }
        }
        get useHighMarkerFidelity() {
            return this.so;
        }
    }
    ColumnSeries.$t = markType(ColumnSeries, 'ColumnSeries', HorizontalAnchoredCategorySeries.$);
    ColumnSeries.$$p = markDep(DependencyProperty, PropertyMetadata, ColumnSeries, 'raisePropertyChanged', ['RadiusX:vf:vl', [1, 0], 'RadiusY:vg:vm', [1, 0]]);
    return ColumnSeries;
})();
/**
 * @hidden
 */
export let ColumnSeriesView = /*@__PURE__*/ (() => {
    class ColumnSeriesView extends AnchoredCategorySeriesView {
        constructor(a) {
            super(a);
            this.da = null;
            this.dc = null;
            this.dh = new Rectangle();
            this.db = null;
            this.da = a;
            this.db = ((() => {
                let $ret = new Pool$1(Rectangle.$);
                $ret.create = runOn(this, this.di);
                $ret.activate = runOn(this, this.dd);
                $ret.disactivate = runOn(this, this.df);
                $ret.destroy = runOn(this, this.de);
                return $ret;
            })());
        }
        as() {
            super.as();
            this.dc = new List$1(Rectangle.$, 0);
            if (!this.q) {
                this.da.g1 = Defaults.i;
                this.da.qh = Defaults.c;
            }
        }
        di() {
            let a = new Rectangle();
            this.dc.add(a);
            a._visibility = 1;
            return a;
        }
        dd(a) {
            a._visibility = 0;
        }
        df(a) {
            a._visibility = 1;
        }
        de(a) {
            this.dc.remove(a);
        }
        dg(a, b, c) {
            if (!this.isDirty) {
                this.aq();
            }
            a.o = c;
            a.n = b;
        }
        ac(a) {
            return this.dc._inner[a];
        }
        ab(a) {
            let b = this.dc._inner[a];
            this.dh._visibility = b._visibility;
            this.dh.n = b.n;
            this.dh.o = b.o;
            this.dh.width = b.width;
            this.dh.height = b.height;
            let c = this.bp(a);
            this.dh._fill = c;
            this.dh._stroke = c;
            this.dh.ac = this.e.fw + 3;
            return this.dh;
        }
        a6(a, b) {
            super.a6(a, b);
            if (a.d) {
                for (let c = 0; c < this.dc.count; c++) {
                    let d = this.aa(c, b);
                    this.bd(d, c, b);
                    a.w(d);
                }
            }
        }
        al(a) {
            super.al(a);
            let b = 0;
            let c = new List$1(Rectangle.$, 0);
            for (let d of fromEnum(this.db.a)) {
                c.add(d);
            }
            c.aa((e, f) => {
                if (e.n < f.n) {
                    return -1;
                }
                else if (e.n > f.n) {
                    return 1;
                }
                else {
                    return 0;
                }
            });
            for (let e of fromEnum(c)) {
                this.e.a8.exportRectangleData(a, e, "column" + b, ["Main", "Fill"]);
            }
            b++;
        }
    }
    ColumnSeriesView.$t = markType(ColumnSeriesView, 'ColumnSeriesView', AnchoredCategorySeriesView.$);
    return ColumnSeriesView;
})();
