/*
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-react-core";
import { ConsolidatedItemsPosition_$type } from "./ConsolidatedItemsPosition";
import { Defaults } from "./Defaults";
import { runOn, enumGetBox, markType, markDep, fromEnum } from "igniteui-react-core";
import { Pool$1 } from "igniteui-react-core";
import { Rectangle } from "igniteui-react-core";
import { ChartSelection } from "./ChartSelection";
import { List$1 } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity } from "igniteui-react-core";
import { AnchoredCategorySeriesView } from "./AnchoredCategorySeriesView";
/**
 * @hidden
 */
export let ColumnSeries = /*@__PURE__*/ (() => {
    class ColumnSeries extends HorizontalAnchoredCategorySeries {
        bj() {
            return new ColumnSeries();
        }
        get_ez() {
            return true;
        }
        get_fl() {
            return true;
        }
        jk() {
            if (!isNaN_(this.jj)) {
                return super.jk();
            }
            return Defaults.h;
        }
        cs() {
            return new ColumnSeriesView(this);
        }
        qz(a) {
            super.qz(a);
            this.acu = a;
        }
        cy() {
            if (this.cz == 0) {
                return 2;
            }
            return super.cy();
        }
        y2() {
            return 1;
        }
        constructor() {
            super();
            this.ac0 = null;
            this.acv = 0;
            this.ab = ColumnSeries.$;
            this.ace = 2;
        }
        get_ed() {
            return true;
        }
        preferredCategoryMode(a) {
            return this.ace;
        }
        wl(a) {
            if (this.ac0 == null) {
                this.ac0 = runOn(this, this.acx);
            }
            let b = this.ach != null ? this.ach : this.yAxis;
            let c = this.acb;
            return this.aay.c$d(this, a, c, b, this.ys, this.zt(this.cv), this.zu(this.cv), this.ac0);
        }
        gw(a, b) {
            if (this.gz(a, b)) {
                return true;
            }
            if (this.xf(a, b)) {
                return true;
            }
            return false;
        }
        o5(a, b) {
            super.o5(a, b);
            let c = b;
            if (a && c.dg != null) {
                c.dg.count = 0;
            }
        }
        iw() {
            return this.acb.k8(this.cv.by, this.cv.bx, this.getEffectiveViewport1(this.cv));
        }
        ak(a, b) {
            let c = new List$1(ChartSelection.$, 0);
            this.p2(a, c, b);
            return c.toArray();
        }
        p2(a, b, c) {
            this.aaa(a, b, c, this.yr, 1);
        }
        aai(a, b) {
            super.aai(a, b);
            let c = a.f;
            if (!b.t()) {
                return;
            }
            let d = b.by;
            let e = b.bx;
            let f = this.getEffectiveViewport1(b);
            let g = new ScalerParams(0, d, e, this.ach.ch, f);
            g.b = this.iy();
            let h = new ScalerParams(0, d, e, this.acb.ch, f);
            let i = this.ach;
            let j = i.el(i.me, g);
            let k = this.acb.k8(d, e, f);
            let l = this.acb;
            let m = b;
            if (isNaN_(k) || isInfinity(k)) {
                m.dg.count = 0;
                return;
            }
            this.y0.a2(this, this.zk(), runOn(this, this.yk), this.zt(b), this.zu(b));
            this.y0.r = this.acy;
            this.y0.s = this.acz;
            this.y0.k = this.acy;
            this.y0.l = this.acz;
            let n = false;
            let o = this.y0.b;
            if (o != null) {
                n = true;
            }
            let p = this.acb.cn;
            let q = p ? this.acb : null;
            let r = this.valueColumn.count;
            let s = this.zt(b);
            let t = 0;
            for (let u = 0; u < c.count; ++u) {
                let v = c._inner[u][0] - 0.5 * k;
                let w = this.acx(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.dg.item(t);
                t++;
                z.width = k;
                z.height = y;
                let aa = this.y0.aw(r, u)[0];
                if (p && a.m != null && u >= 0 && u < a.m.count) {
                    aa = truncate(Math.round(a.m._inner[u]));
                }
                if (n) {
                    this.aae(c, u, r, l, h, b.q, aa);
                }
                if (z.dataContext != null) {
                    let ab = z.dataContext;
                    if (s == 1) {
                        if (aa >= 0 && aa < this.dn.count) {
                            if (q != null && q.i$b != null && q.i$b.count > aa) {
                                aa = q.i$b._inner[aa];
                            }
                            ab.item = this.dn.item(aa);
                        }
                    }
                    else {
                        ab.item = null;
                    }
                }
                this.y0.ad(z, false, false, false, false);
                z.ap = this.y0.k;
                z.aq = this.y0.l;
                m.dl(z, v, Math.min(x, w));
            }
            m.dg.count = t;
            b.c3(a);
        }
        get acw() {
            return this.acv;
        }
        set acw(a) {
            if (this.acw != a) {
                let b = this.acw;
                this.acv = a;
                this.raisePropertyChanged("ConsolidatedColumnVerticalPosition", enumGetBox(ConsolidatedItemsPosition_$type, b), enumGetBox(ConsolidatedItemsPosition_$type, this.acw));
            }
        }
        acx(a) {
            if (a == null || a.length < 3) {
                return NaN;
            }
            switch (this.acw) {
                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.eo(b, new ScalerParams(1, this.db.wk, this.db.wj, this.yAxis.ch));
                    if (c < this.yAxis.me) {
                        return a[2];
                    }
                    else {
                        return a[1];
                    }
                case 4:
                    let d = (a[1] + a[2]) / 2;
                    let e = this.yAxis.eo(d, new ScalerParams(1, this.db.wk, this.db.wj, this.yAxis.ch));
                    if (this.yAxis == null) {
                        return d;
                    }
                    if (e < this.yAxis.me) {
                        return a[1];
                    }
                    else {
                        return a[2];
                    }
                default: return (a[1] + a[2]) / 2;
            }
        }
        get useHighMarkerFidelity() {
            return this.zo;
        }
    }
    ColumnSeries.$t = /*@__PURE__*/ markType(ColumnSeries, 'ColumnSeries', HorizontalAnchoredCategorySeries.$);
    ColumnSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, ColumnSeries, 'raisePropertyChanged', ['RadiusX:acy:ac4', [1, 0], 'RadiusY:acz:ac5', [1, 0]]);
    return ColumnSeries;
})();
/**
 * @hidden
 */
export let ColumnSeriesView = /*@__PURE__*/ (() => {
    class ColumnSeriesView extends AnchoredCategorySeriesView {
        au() {
            super.au();
            this.dh = new List$1(Rectangle.$, 0);
            if (!this.q) {
                this.df.jp = Defaults.i;
                this.df.w8 = Defaults.c;
            }
        }
        constructor(a) {
            super(a);
            this.df = null;
            this.dh = null;
            this.dm = new Rectangle();
            this.dg = null;
            this.df = a;
            this.dg = ((() => {
                let $ret = new Pool$1(Rectangle.$);
                $ret.create = runOn(this, this.dn);
                $ret.activate = runOn(this, this.di);
                $ret.disactivate = runOn(this, this.dk);
                $ret.destroy = runOn(this, this.dj);
                return $ret;
            })());
        }
        dn() {
            let a = new Rectangle();
            this.dh.add(a);
            a._visibility = 1;
            return a;
        }
        di(a) {
            a._visibility = 0;
        }
        dk(a) {
            a._visibility = 1;
        }
        dj(a) {
            this.dh.remove(a);
        }
        dl(a, b, c) {
            if (!this.isDirty) {
                this.as();
            }
            a.o = c;
            a.n = b;
        }
        ac(a) {
            return this.dh._inner[a];
        }
        ab(a) {
            let b = this.dh._inner[a];
            this.dm._visibility = b._visibility;
            this.dm.n = b.n;
            this.dm.o = b.o;
            this.dm.width = b.width;
            this.dm.height = b.height;
            let c = this.bs(a);
            this.dm._fill = c;
            this.dm._stroke = c;
            this.dm.ad = this.e.ie + 3;
            return this.dm;
        }
        a8(a, b) {
            super.a8(a, b);
            if (a.d) {
                for (let c = 0; c < this.dh.count; c++) {
                    let d = this.aa(c, b);
                    this.bf(d, c, b);
                    a.w(d);
                }
            }
        }
        an(a) {
            super.an(a);
            let b = 0;
            let c = new List$1(Rectangle.$, 0);
            for (let d of fromEnum(this.dg.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.bc.exportRectangleData(a, e, "column" + b, ["Main", "Fill"]);
            }
            b++;
        }
    }
    ColumnSeriesView.$t = /*@__PURE__*/ markType(ColumnSeriesView, 'ColumnSeriesView', AnchoredCategorySeriesView.$);
    return ColumnSeriesView;
})();
