/*
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 { CategoryAxisBase } from "./CategoryAxisBase";
import { DependencyProperty } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { Base, typeCast, Array_$type, Number_$type, markType } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { NumericScaler } from "./NumericScaler";
import { VerticalAxisLabelPanel } from "./VerticalAxisLabelPanel";
import { MathUtil } from "igniteui-react-core";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { LinearCategorySnapper } from "./LinearCategorySnapper";
import { NumericXAxis } from "./NumericXAxis";
import { LabelPosition } from "./LabelPosition";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity } from "igniteui-react-core";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
/**
 * @hidden
 */
export let CategoryYAxis = /*@__PURE__*/ (() => {
    class CategoryYAxis extends CategoryAxisBase {
        constructor() {
            super();
            this.k7 = 0;
            this.k8 = 0;
            this.lf = 1;
            this.le = 1;
            this.jv = new List$1(Number_$type, 0);
            this.ab = CategoryYAxis.$;
        }
        a3() {
            return new CategoryYAxisView(this);
        }
        gy(a) {
            super.gy(a);
            this.k6 = a;
        }
        get_ch() {
            return true;
        }
        dy() {
            return this.ja.height;
        }
        k3(a, b, c) {
            return this.k4(a, b, c, true);
        }
        k5(a) {
            if (typeCast(List$1.$.specialize(Array_$type), a) !== null) {
                return a.asArray();
            }
            return null;
        }
        gs(a, b, c, d, e) {
            let f;
            let g = e.e;
            let h = e.d;
            let i = e.c;
            let j = e.a;
            let k = !i.isEmpty;
            let l = this.categoryMode == 0 ? this.j8 - 1 : this.j8;
            if (l < 0) {
                l = 0;
            }
            let m = i.top;
            let n = i.height;
            let o = g.top;
            let p = g.height;
            let q = h.top;
            let r = h.height;
            let s = 0;
            let t = 1;
            let u = this.k5(a);
            let v = false;
            if (u != null) {
                v = true;
            }
            let w;
            for (let x = 0; x < b.count; x++) {
                w = b.item(x);
                for (let y = c; y < d; y++) {
                    if (v) {
                        f = u[y];
                    }
                    else {
                        f = a.item(y);
                    }
                    if (k) {
                        let z = l >= 1 ? (f[w]) / (l) : l == 0 ? 0.5 : NaN;
                        if (!j) {
                            z = 1 - z;
                        }
                        z = m + n * (z - s) / t;
                        let aa = (z - e.d.top) / e.d.height;
                        aa = e.d.top + e.d.height * (aa - e.e.top) / e.e.height;
                        f[w] = aa;
                    }
                    else {
                        let ab = l >= 1 ? (f[w]) / (l) : l == 0 ? 0.5 : NaN;
                        if (!j) {
                            ab = 1 - ab;
                        }
                        ab = q + r * (ab - o) / p;
                        f[w] = ab;
                    }
                }
            }
        }
        get lc() {
            return this.c(CategoryYAxis.lo);
        }
        set lc(a) {
            this.h(CategoryYAxis.lo, a);
        }
        get k9() {
            return this.k7;
        }
        set k9(a) {
            if (this.k9 != a) {
                let b = this.k7;
                this.k7 = a;
                this.g6("ActualInterval", b, this.k9);
            }
        }
        ea() {
            return this.k9;
        }
        get ld() {
            return this.c(CategoryYAxis.lp);
        }
        set ld(a) {
            this.h(CategoryYAxis.lp, a);
        }
        get la() {
            return this.k8;
        }
        set la(a) {
            if (this.la != a) {
                let b = this.k8;
                this.k8 = a;
                this.g6("ActualMinorInterval", b, this.la);
            }
        }
        get lh() {
            return this.lf;
        }
        set lh(a) {
            this.lf = a;
        }
        get lg() {
            return this.le;
        }
        set lg(a) {
            this.le = a;
        }
        dz(a, b) {
            if (!b.c.isEmpty) {
                let c = this.lb(a, NumericScaler.ac, b.c);
                c = (c - b.d.top) / b.d.height;
                c = b.d.top + b.d.height * (c - b.e.top) / b.e.height;
                return c;
            }
            return this.lb(a, b.e, b.d);
        }
        lb(a, b, c) {
            let d = this.categoryMode == 0 ? this.j8 - 1 : this.j8;
            if (d < 0) {
                d = 0;
            }
            let e = d >= 1 ? (a) / (d) : d == 0 ? 0.5 : NaN;
            if (!this.cb) {
                e = 1 - e;
            }
            return c.top + c.height * (e - b.top) / b.height;
        }
        d2(a, b) {
            if (!b.c.isEmpty) {
                let c = b.e.top + b.e.height * (a - b.d.top) / b.d.height;
                c = (c * b.d.height) + b.d.top;
                c = this.getUnscaledValue3(c, NumericScaler.ac, b.c, this.categoryMode);
                return c;
            }
            return this.getUnscaledValue3(a, b.e, b.d, this.categoryMode);
        }
        d3(a, b, c) {
            if (!b.c.isEmpty) {
                let d = b.e.top + b.e.height * (a - b.d.top) / b.d.height;
                d = (d * b.d.height) + b.d.top;
                d = this.getUnscaledValue3(d, NumericScaler.ac, b.c, c);
                return d;
            }
            return this.getUnscaledValue3(a, b.e, b.d, c);
        }
        getUnscaledValue3(a, b, c, d) {
            let e = b.top + (a - c.top) * b.height / c.height;
            if (!this.cb) {
                e = 1 - e;
            }
            let f = d == 0 ? this.j8 - 1 : this.j8;
            if (f < 0) {
                f = 0;
            }
            return e * f;
        }
        ln(a, b) {
            if (a == NaN || b == NaN || this.jo == null || this.jo.count == 0) {
                return;
            }
            let c = a / this.jo.count;
            let d = b / this.jo.count;
            this.bh.o8 = new Rect(0, this.bh.o8.x, 1 - d, this.bh.o8.width, d - c);
        }
        au() {
            return new VerticalAxisLabelPanel();
        }
        dm() {
            return this.lc;
        }
        getCategorySize(a, b, c) {
            let d = this.i8(b, c);
            return d.height / (this.j8 * a.height);
        }
        j0(a, b, c) {
            let d = 0;
            if (!isNaN_(this.jx)) {
                d = MathUtil.b(this.jx, 0, 1);
            }
            let e = 0;
            if (!isNaN_(this.j4)) {
                e = Math.min(this.j4, 1);
            }
            let f = 1 - 0.5 * d;
            let g = this.getCategorySize(a, b, c) * f / (this.ka - (this.ka - 1) * e);
            return g;
        }
        getGroupCenter(a, b, c, d) {
            let e = 0.5;
            if (this.ka > 1) {
                let f = 0;
                if (!isNaN_(this.jx)) {
                    f = MathUtil.b(this.jx, 0, 1);
                }
                let g = 0;
                if (!isNaN_(this.j4)) {
                    g = Math.min(this.j4, 1);
                }
                let h = 1 - 0.5 * f;
                let i = h / (this.ka - (this.ka - 1) * g);
                let j = (h - i) / (this.ka - 1);
                e = 0.25 * f + 0.5 * i + a * j;
            }
            return this.getCategorySize(b, c, d) * e;
        }
        lm(a) {
            let b = this.bh != null ? this.bh.os : Rect.empty;
            b = b.copy();
            let c = this.ja;
            let d = new Rect(0, 0, 0, 1, 1);
            let e = this.i7();
            let f = new ScalerParams(0, d, d, this.ca, e);
            let g = !b.isEmpty && !c.isEmpty && this.jo != null ? this.jo.indexOf(a) : -1;
            let h = g > -1 ? this.dz(g, f) : NaN;
            if (!isNaN_(h) && this.bh.dt) {
                if (!isNaN_(h)) {
                    if (h < b.top + 0.1 * b.height) {
                        h = h + 0.4 * b.height;
                        b.y = h - 0.5 * b.height;
                    }
                    if (h > b.bottom - 0.1 * b.height) {
                        h = h - 0.4 * b.height;
                        b.y = h - 0.5 * b.height;
                    }
                }
                this.bh.md(b, false, true);
            }
        }
        cp() {
            if (this.ci && this.cq) {
                this.bb = this.ba();
            }
            if (this.jo == null) {
                return false;
            }
            let a = this.jo.count;
            if (a != this.lg) {
                let b = new AxisRangeChangedEventArgs(0, 1, 1, this.lg, a);
                this.lg = a;
                this.g7(b);
                return true;
            }
            return false;
        }
        jr(a) {
            if (a == null) {
                return false;
            }
            let b = this.bd();
            if (b == null) {
                return false;
            }
            return b.synchronizeVertically;
        }
        hd(a) {
            super.hd(a);
            let b = this.bh != null ? this.bh.os : Rect.empty;
            let c = this.ja;
            let d = this.i5();
            let e = this.i4();
            let f = new ScalerParams(0, b, c, this.ca, d);
            let g = this.a4.ay();
            let h = this.a4.a1();
            let i = this.a4.az();
            let j = this.a4.a0();
            let k = this.a4.e();
            let l = this.a4.f();
            let m = this.a4.g();
            this.hl();
            this.go(g);
            this.go(h);
            this.go(i);
            this.go(j);
            this.cx.clear();
            this.cy.clear();
            this.jv.clear();
            this.a4.at(this, b, c);
            if (b.isEmpty || c.isEmpty) {
                this.bq.count = 0;
                this.bp.count = 0;
                this.bo.count = 0;
            }
            if (this.bq.count == 0 && this.bp.count == 0) {
                this.a4.y();
            }
            if (this.ay != null) {
                this.ay.registerAxis(this);
            }
            if (this.itemsSource == null || this.jo == null || this.jo.count == 0) {
                this.bq.count = 0;
                this.bp.count = 0;
                this.bo.count = 0;
                this.a4.y();
                return;
            }
            if (!b.isEmpty && !c.isEmpty) {
                let n = this.d2(e.top, f);
                let o = this.d2(e.bottom, f);
                if (!this.ca) {
                    n = Math.ceil(n);
                    o = Math.floor(o);
                }
                else {
                    n = Math.floor(n);
                    o = Math.ceil(o);
                }
                let p = c.left;
                let q = 0;
                if (this.ai != null) {
                    let r = typeCast(NumericXAxis.$, this.ai);
                    if (r != null) {
                        let s = this.hh(p, q, b, c, d, c.left, c.right);
                        p = s.p0;
                        q = s.p1;
                    }
                }
                this.hm(g, p, c, k, true);
                this.a4.ao(q);
                let t = Math.min(n, o);
                let u = Math.max(n, o);
                let v = new LinearCategorySnapper(1, t, u, e.height, this.lc, this.categoryMode, this.ec());
                let w = Math.floor((t - 0) / v.g);
                let x = Math.ceil((u - 0) / v.g);
                if (!isNaN_(w) && !isNaN_(x)) {
                    let y = truncate(w);
                    let z = truncate(x);
                    let aa = this.dz(0 + y * v.g, f);
                    let ab = Math.abs(this.dz(v.g, f) - this.dz(0, f));
                    this.av.bo = this.dz(v.g, f);
                    for (let ac = y; ac <= z; ++ac) {
                        let ad = this.dz(0 + (ac + 1) * v.g, f);
                        if (aa <= e.bottom) {
                            if (ac % 2 == 0) {
                                this.gx(h, aa, ad, c);
                            }
                            this.gw(i, aa, c, l, false);
                            this.jv.add(aa);
                        }
                        if (this.categoryMode != 0 && this.ka != 0 && this.cl) {
                            if (this.ld > 0 && this.ld < v.g) {
                                let ae = ab * this.ld;
                                if (!this.ca) {
                                    let af = aa;
                                    while (af - ae > ad) {
                                        af -= ae;
                                        if (Math.abs(af - ad) < 0.0001) {
                                            break;
                                        }
                                        this.gw(j, af, c, m, false);
                                    }
                                }
                                else {
                                    let ag = aa;
                                    while (ag + ae < ad) {
                                        ag += ae;
                                        if (Math.abs(ag - ad) < 0.0001) {
                                            break;
                                        }
                                        this.gw(j, ag, c, m, false);
                                    }
                                }
                                this.la = this.ld;
                            }
                            else {
                                for (let ah = 0; ah < truncate(v.g); ah++) {
                                    for (let ai = 0; ai < this.ka; ai++) {
                                        let aj = this.getGroupCenter(ai, b, c, d);
                                        if (!this.ca) {
                                            aj = -aj;
                                        }
                                        let ak = this.dz(ah + ac * v.g, f) + aj;
                                        this.gw(j, ak, c, m, false);
                                    }
                                }
                                this.la = 0.5;
                            }
                        }
                        let al = aa;
                        if (this.categoryMode != 0) {
                            let am = this.dz(ac * v.g + 1, f);
                            al = (aa + am) / 2;
                        }
                        if (al <= e.bottom && al >= e.top) {
                            let an = 0;
                            if (v.g >= 1) {
                                an = ac * truncate(Math.floor(v.g));
                            }
                            else {
                                if ((ac * v.g) * 2 % 2 == 0) {
                                    an = truncate(Math.floor(ac * v.g));
                                }
                                else {
                                    an = -1;
                                }
                            }
                            if (this.jo != null && an < this.jo.count && an >= 0) {
                                let ao = this.jo.item(an);
                                let ap = this.e9(ao);
                                if (!isNaN_(al) && !isInfinity(al) && ap != null) {
                                    if ((typeof ap === 'string') && Base.equalsStatic(ap, "")) {
                                    }
                                    else {
                                        this.cx.add1(ap);
                                        this.cy.add(new LabelPosition(al));
                                    }
                                }
                            }
                        }
                        aa = ad;
                    }
                }
                this.k9 = v.g;
                if ((this.ay == null || this.ay.visibility == 0) && this.ai != null) {
                    if (this.ay != null && (this.ay.location == 6 || this.ay.location == 7)) {
                        this.bh.ja();
                    }
                }
                this.a4.au(this.cx, this.cy);
                this.kv();
            }
        }
        get_a1() {
            return 1;
        }
        get a1() {
            return this.get_a1();
        }
        get isVertical() {
            return this.ch;
        }
        j$c(a, b) {
            return this.d2.apply(this, arguments);
        }
        j$b(a, b) {
            return this.dz.apply(this, arguments);
        }
        j$d(a, b, c, d, e) {
            this.gs.apply(this, arguments);
        }
        j$e(a, b, c, d) {
            this.gt.apply(this, arguments);
        }
        j$f(a, b, c, d) {
            this.gu.apply(this, arguments);
        }
        get j$a() {
            return this.ca;
        }
    }
    CategoryYAxis.$t = /*@__PURE__*/ markType(CategoryYAxis, 'CategoryYAxis', CategoryAxisBase.$);
    CategoryYAxis.lo = /*@__PURE__*/ DependencyProperty.i("Interval", Number_$type, CategoryYAxis.$, /*@__PURE__*/ new PropertyMetadata(2, NaN, (a, b) => {
        a.g6("Interval", b.oldValue, b.newValue);
        a.hc(false);
    }));
    CategoryYAxis.lp = /*@__PURE__*/ DependencyProperty.i("MinorInterval", Number_$type, CategoryYAxis.$, /*@__PURE__*/ new PropertyMetadata(2, NaN, (a, b) => {
        (typeCast(CategoryYAxis.$, a)).g6("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryYAxis.$, a)).hc(false);
    }));
    return CategoryYAxis;
})();
/**
 * @hidden
 */
export let CategoryYAxisView = /*@__PURE__*/ (() => {
    class CategoryYAxisView extends CategoryAxisBaseView {
        constructor(a) {
            super(a);
            this.bg = null;
            this.bg = a;
        }
    }
    CategoryYAxisView.$t = /*@__PURE__*/ markType(CategoryYAxisView, 'CategoryYAxisView', CategoryAxisBaseView.$);
    return CategoryYAxisView;
})();
//# sourceMappingURL=CategoryYAxis_combined.js.map
