/*
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 { __extends } from "tslib";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { IZoomableCategoryAxis_$type } from "./IZoomableCategoryAxis";
import { DependencyProperty } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { Base, typeCast, Array_$type, Number_$type, markType, markDep } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { NumericScaler } from "./NumericScaler";
import { VerticalAxisLabelPanel } from "./VerticalAxisLabelPanel";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { MathUtil } from "igniteui-react-core";
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";
import { AxisDefaults } from "./AxisDefaults";
/**
 * @hidden
 */
var CategoryYAxis = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CategoryYAxis, _super);
    function CategoryYAxis() {
        var _this = _super.call(this) || this;
        _this.mj = 0;
        _this.mk = 0;
        _this.mr = 1;
        _this.mq = 1;
        _this.ky = new List$1(Number_$type, 0);
        _this.ab = CategoryYAxis.$;
        return _this;
    }
    CategoryYAxis.prototype.a4 = function () {
        return new CategoryYAxisView(this);
    };
    CategoryYAxis.prototype.hs = function (a) {
        _super.prototype.hs.call(this, a);
        this.mh = a;
    };
    CategoryYAxis.prototype.get_cp = function () {
        return true;
    };
    CategoryYAxis.prototype.ei = function () {
        return this.j7().height;
    };
    CategoryYAxis.prototype.me = function (a, b, c) {
        return this.mf(a, b, c, true);
    };
    CategoryYAxis.prototype.mg = function (a) {
        if (typeCast(List$1.$.specialize(Array_$type), a) !== null) {
            return a.asArray();
        }
        return null;
    };
    CategoryYAxis.prototype.hm = function (a, b, c, d, e) {
        var f;
        var g = e.e;
        var h = e.d;
        var i = e.c;
        var j = e.a;
        var k = !i.isEmpty;
        var l = this.categoryMode == 0 ? this.lf - 1 : this.lf;
        if (l < 0) {
            l = 0;
        }
        var m = i.top;
        var n = i.height;
        var o = g.top;
        var p = g.height;
        var q = h.top;
        var r = h.height;
        var s = 0;
        var t = 1;
        var u = this.mg(a);
        var v = false;
        if (u != null) {
            v = true;
        }
        var w;
        for (var x = 0; x < b.count; x++) {
            w = b.item(x);
            for (var y = c; y < d; y++) {
                if (v) {
                    f = u[y];
                }
                else {
                    f = a.item(y);
                }
                if (k) {
                    var z = l >= 1 ? (f[w]) / (l) : l == 0 ? 0.5 : NaN;
                    if (!j) {
                        z = 1 - z;
                    }
                    z = m + n * (z - s) / t;
                    var 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 {
                    var 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;
                }
            }
        }
    };
    Object.defineProperty(CategoryYAxis.prototype, "mo", {
        get: function () {
            return this.c(CategoryYAxis.m7);
        },
        set: function (a) {
            this.h(CategoryYAxis.m7, a);
        },
        enumerable: false,
        configurable: true
    });
    CategoryYAxis.prototype.mi = function () {
        return !isNaN_(this.mo);
    };
    Object.defineProperty(CategoryYAxis.prototype, "ml", {
        get: function () {
            return this.mj;
        },
        set: function (a) {
            if (this.ml != a) {
                var b = this.mj;
                this.mj = a;
                this.h2("ActualInterval", b, this.ml);
            }
        },
        enumerable: false,
        configurable: true
    });
    CategoryYAxis.prototype.ev = function () {
        return this.ml;
    };
    Object.defineProperty(CategoryYAxis.prototype, "mp", {
        get: function () {
            return this.c(CategoryYAxis.m8);
        },
        set: function (a) {
            this.h(CategoryYAxis.m8, a);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "mm", {
        get: function () {
            return this.mk;
        },
        set: function (a) {
            if (this.mm != a) {
                var b = this.mk;
                this.mk = a;
                this.h2("ActualMinorInterval", b, this.mm);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "mt", {
        get: function () {
            return this.mr;
        },
        set: function (a) {
            this.mr = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "ms", {
        get: function () {
            return this.mq;
        },
        set: function (a) {
            this.mq = a;
        },
        enumerable: false,
        configurable: true
    });
    CategoryYAxis.prototype.ej = function (a, b) {
        if (!b.c.isEmpty) {
            var c = this.mn(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.mn(a, b.e, b.d);
    };
    CategoryYAxis.prototype.mn = function (a, b, c) {
        var d = this.categoryMode == 0 ? this.lf - 1 : this.lf;
        if (d < 0) {
            d = 0;
        }
        var e = d >= 1 ? (a) / (d) : d == 0 ? 0.5 : NaN;
        if (!this.ci) {
            e = 1 - e;
        }
        return c.top + c.height * (e - b.top) / b.height;
    };
    CategoryYAxis.prototype.em = function (a, b) {
        if (!b.c.isEmpty) {
            var 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);
    };
    CategoryYAxis.prototype.en = function (a, b, c) {
        if (!b.c.isEmpty) {
            var 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);
    };
    CategoryYAxis.prototype.getUnscaledValue3 = function (a, b, c, d) {
        var e = b.top + (a - c.top) * b.height / c.height;
        if (!this.ci) {
            e = 1 - e;
        }
        var f = d == 0 ? this.lf - 1 : this.lf;
        if (f < 0) {
            f = 0;
        }
        return e * f;
    };
    CategoryYAxis.prototype.m4 = function (a, b) {
        if (isNaN_(a) || isNaN_(b) || this.kr == null || this.kr.count == 0) {
            return;
        }
        var c = a / this.kr.count;
        var d = b / this.kr.count;
        this.bi.t7 = new Rect(0, this.bi.t7.x, 1 - d, this.bi.t7.width, d - c);
    };
    CategoryYAxis.prototype.av = function () {
        return new VerticalAxisLabelPanel();
    };
    CategoryYAxis.prototype.d4 = function () {
        return this.mo;
    };
    CategoryYAxis.prototype.getCategorySize = function (a, b, c) {
        var d = this.kb(b, c);
        return d.height / (this.lf * a.height);
    };
    CategoryYAxis.prototype.k4 = function (a, b, c) {
        var d = this.lb(a, b, c);
        var e = 0;
        if (!isNaN_(this.la)) {
            e = Math.min(this.la, 1);
        }
        var f = 1 - 0.5 * d;
        var g = this.getCategorySize(a, b, c) * f / (this.lh - (this.lh - 1) * e);
        return g;
    };
    CategoryYAxis.prototype.getGroupCenter = function (a, b, c, d) {
        var e = 0.5;
        if (this.lh > 1) {
            var f = this.lb(b, c, d);
            var g = 0;
            if (!isNaN_(this.la)) {
                g = Math.min(this.la, 1);
            }
            var h = 1 - 0.5 * f;
            var i = h / (this.lh - (this.lh - 1) * g);
            var j = (h - i) / (this.lh - 1);
            e = 0.25 * f + 0.5 * i + a * j;
        }
        return this.getCategorySize(b, c, d) * e;
    };
    CategoryYAxis.prototype.m3 = function (a) {
        var b = this.bi != null ? this.bi.tr : Rect.empty;
        b = b.copy();
        var c = this.kd;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.ka();
        var f = new ScalerParams(0, d, d, this.ch, e);
        var g = !b.isEmpty && !c.isEmpty && this.kr != null ? this.kr.indexOf(a) : -1;
        var h = g > -1 ? this.ej(g, f) : NaN;
        if (!isNaN_(h) && this.bi.eq) {
            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.bi.pz(b, false, true);
        }
    };
    CategoryYAxis.prototype.c3 = function () {
        if (this.cq && this.c4) {
            this.bc = this.bb();
        }
        if (this.kr == null) {
            return false;
        }
        var a = false;
        var b = this.kr.count;
        if (b != this.ms) {
            var c = new AxisRangeChangedEventArgs(0, 1, 1, this.ms, b);
            this.ms = b;
            this.h3(c);
            a = true;
        }
        this.m6();
        this.m5();
        return a;
    };
    CategoryYAxis.prototype.getWindowZoomFromCategories = function (a) {
        var b = MathUtil.a(a) && a > 0;
        var c = this.kr.count;
        if (c > 0 && b) {
            var d = this.bi.t6.height;
            var e = isNaN_(d) || isInfinity(d);
            if (e) {
                return NaN;
            }
            var f = new Rect(0, 0, 0, 1, 1);
            var g = this.bi.t6;
            var h = this.getCategorySize(f, g, g);
            var i = isNaN_(h) || isInfinity(h);
            if (i) {
                return NaN;
            }
            var j = h * a / d;
            if (j >= 0 && j <= 1) {
                return j;
            }
        }
        return NaN;
    };
    CategoryYAxis.prototype.getWindowZoomFromItemSpan = function (a) {
        var b = MathUtil.a(a) && a > 0;
        var c = this.kr.count;
        if (c > 0 && b) {
            var d = this.bi.t6.height;
            var e = isNaN_(d) || isInfinity(d);
            if (e) {
                return NaN;
            }
            var f = new Rect(0, 0, 0, 1, 1);
            var g = this.bi.t6;
            var h = this.k4(f, g, g);
            var i = a / h;
            var j = Math.min(1, 1 / i);
            if (j > 0 && j <= 1) {
                return j;
            }
        }
        return NaN;
    };
    CategoryYAxis.prototype.m6 = function () {
        if (this.kr == null || this.bi == null) {
            return;
        }
        var a = !isNaN_(this.bi.hq) && !isNaN_(this.bi.hs);
        if (a) {
            return;
        }
        if (!isNaN_(this.zoomMaximumItemSpan) && !isInfinity(this.zoomMaximumItemSpan)) {
            var b = this.getWindowZoomFromItemSpan(this.zoomMaximumItemSpan);
            if (!isNaN_(b) && !isInfinity(b)) {
                this.bi.gl = b;
            }
        }
        else if (!isNaN_(this.zoomMaximumCategoryRange) && !isInfinity(this.zoomMaximumCategoryRange)) {
            var c = this.getWindowZoomFromCategories(this.zoomMaximumCategoryRange);
            if (!isNaN_(c) && !isInfinity(c)) {
                this.bi.gl = c;
            }
        }
    };
    CategoryYAxis.prototype.m5 = function () {
        if (this.kr == null || this.bi == null) {
            return;
        }
        var a = NaN;
        var b = NaN;
        var c = this.bi.gs();
        var d = this.bi.gt();
        var e = false;
        if (MathUtil.a(this.zoomToItemSpan)) {
            e = true;
            d = this.getWindowZoomFromItemSpan(this.zoomToItemSpan);
            d = Math.max(d, this.bi.gl);
        }
        else if (MathUtil.a(this.zoomToCategoryRange)) {
            e = true;
            d = this.getWindowZoomFromCategories(this.zoomToCategoryRange);
            d = Math.max(d, this.bi.gl);
        }
        if (MathUtil.a(this.zoomToCategoryStart) && this.zoomToCategoryStart >= 0 && this.zoomToCategoryStart < this.lg) {
            e = true;
            b = this.getWindowZoomFromCategories(this.zoomToCategoryStart);
            var f = d + a - 1;
            var g = d - f;
            if (f > 0 && g > this.bi.gl) {
                d = g;
                d = Math.max(d, this.bi.gl);
            }
        }
        if (e) {
            this.bi.px(a, b, c, d);
        }
    };
    CategoryYAxis.prototype.hw = function (a, b, c, d) {
        _super.prototype.hw.call(this, a, b, c, d);
        switch (b) {
            case CategoryYAxis.$$p[0]:
            case CategoryYAxis.$$p[1]:
                this.m6();
                break;
            case CategoryYAxis.$$p[2]:
            case CategoryYAxis.$$p[3]:
            case CategoryYAxis.$$p[4]:
                this.m5();
                break;
        }
    };
    CategoryYAxis.prototype.ku = function (a) {
        if (a == null) {
            return false;
        }
        var b = this.be();
        if (b == null) {
            return false;
        }
        return b.synchronizeVertically;
    };
    CategoryYAxis.prototype.h9 = function (a) {
        _super.prototype.h9.call(this, a);
        var b = this.bi != null ? this.bi.tr : Rect.empty;
        var c = this.kd;
        var d = this.j8();
        var e = this.j7();
        var f = new ScalerParams(0, b, c, this.ch, d);
        var g = this.a5.a4();
        var h = this.a5.a7();
        var i = this.a5.a5();
        var j = this.a5.a6();
        var k = this.a5.e();
        var l = this.a5.f();
        var m = this.a5.g();
        this.il();
        this.hi(g);
        this.hi(h);
        this.hi(i);
        this.hi(j);
        this.dc.clear();
        this.dd.clear();
        this.ky.clear();
        this.a5.az(this, b, c);
        if (b.isEmpty || c.isEmpty) {
            this.br.count = 0;
            this.bq.count = 0;
            this.bp.count = 0;
        }
        if (this.br.count == 0 && this.bq.count == 0 && this.a5.l()) {
            this.a5.ad();
        }
        if (this.az != null) {
            this.az.registerAxis(this);
        }
        if (this.itemsSource == null || this.kr == null || this.kr.count == 0) {
            this.br.count = 0;
            this.bq.count = 0;
            this.bp.count = 0;
            this.a5.ad();
            return;
        }
        if (!b.isEmpty && !c.isEmpty) {
            var n = this.em(e.top, f);
            var o = this.em(e.bottom, f);
            if (!this.ch) {
                n = Math.ceil(n);
                o = Math.floor(o);
            }
            else {
                n = Math.floor(n);
                o = Math.ceil(o);
            }
            var p = c.left;
            var q = 0;
            if (this.aj != null) {
                var r = typeCast(NumericXAxis.$, this.aj);
                if (r != null) {
                    var s = this.ie(p, q, b, c, d, c.left, c.right);
                    p = s.p0;
                    q = s.p1;
                }
            }
            this.im(g, p, c, k, true);
            this.a5.au(q);
            var t = Math.min(n, o);
            var u = Math.max(n, o);
            var v = new LinearCategorySnapper(1, t, u, e.height, this.mo, this.categoryMode, this.ey());
            var w = v.g;
            w = this.d2(w, this.mi(), b, c, d);
            if (v.g != w) {
                v = new LinearCategorySnapper(1, t, u, e.height, w, this.categoryMode, this.ey());
            }
            var x = Math.floor((t - 0) / v.g);
            var y = Math.ceil((u - 0) / v.g);
            if (!isNaN_(x) && !isNaN_(y)) {
                var z = truncate(x);
                var aa = truncate(y);
                var ab = this.ej(0 + z * v.g, f);
                var ac = Math.abs(this.ej(v.g, f) - this.ej(0, f));
                this.aw.bw = this.ej(v.g, f);
                for (var ad = z; ad <= aa; ++ad) {
                    var ae = this.ej(0 + (ad + 1) * v.g, f);
                    if (ab <= e.bottom) {
                        if (ad % 2 == 0) {
                            this.hr(h, ab, ae, c);
                        }
                        this.hq(i, ab, c, l, false);
                        this.ky.add(ab);
                    }
                    if (this.categoryMode != 0 && this.lh != 0 && this.cy) {
                        if (this.mp > 0 && this.mp < v.g) {
                            var af = ac * this.mp;
                            if (!this.ch) {
                                var ag = ab;
                                while (ag - af > ae) {
                                    ag -= af;
                                    if (Math.abs(ag - ae) < 0.0001) {
                                        break;
                                    }
                                    this.hq(j, ag, c, m, false);
                                }
                            }
                            else {
                                var ah = ab;
                                while (ah + af < ae) {
                                    ah += af;
                                    if (Math.abs(ah - ae) < 0.0001) {
                                        break;
                                    }
                                    this.hq(j, ah, c, m, false);
                                }
                            }
                            this.mm = this.mp;
                        }
                        else {
                            for (var ai = 0; ai < truncate(v.g); ai++) {
                                for (var aj = 0; aj < this.lh; aj++) {
                                    var ak = this.getGroupCenter(aj, b, c, d);
                                    if (!this.ch) {
                                        ak = -ak;
                                    }
                                    var al = this.ej(ai + ad * v.g, f) + ak;
                                    this.hq(j, al, c, m, false);
                                }
                            }
                            this.mm = 0.5;
                        }
                    }
                    var am = ab;
                    if (this.categoryMode != 0) {
                        var an = this.ej(ad * v.g + 1, f);
                        am = (ab + an) / 2;
                    }
                    if (am <= e.bottom && am >= e.top) {
                        var ao = 0;
                        if (v.g >= 1) {
                            ao = ad * truncate(Math.floor(v.g));
                        }
                        else {
                            if ((ad * v.g) * 2 % 2 == 0) {
                                ao = truncate(Math.floor(ad * v.g));
                            }
                            else {
                                ao = -1;
                            }
                        }
                        if (this.kr != null && ao < this.kr.count && ao >= 0) {
                            var ap = this.kr.item(ao);
                            var aq = this.fz(ap);
                            if (!isNaN_(am) && !isInfinity(am) && aq != null) {
                                if ((typeof aq === 'string') && Base.equalsStatic(aq, "")) {
                                }
                                else {
                                    this.dc.add1(aq);
                                    this.dd.add(new LabelPosition(am));
                                }
                            }
                        }
                    }
                    ab = ae;
                }
            }
            this.ml = v.g;
            if ((this.az == null || this.az.visibility == 0) && this.aj != null) {
                if (this.az != null && (this.az.location == 6 || this.az.location == 7)) {
                    this.bi.mh();
                }
            }
            this.a5.a0(this.dc, this.dd);
            this.l4();
        }
    };
    CategoryYAxis.prototype.get_a2 = function () {
        return 1;
    };
    Object.defineProperty(CategoryYAxis.prototype, "a2", {
        get: function () {
            return this.get_a2();
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "isVertical", {
        get: function () {
            return this.cp;
        },
        enumerable: false,
        configurable: true
    });
    CategoryYAxis.prototype.j$d = function (a, b) {
        return this.em.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$c = function (a, b) {
        return this.ej.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$e = function (a, b, c, d, e) {
        this.hm.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$f = function (a, b, c, d) {
        this.hn.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$g = function (a, b, c, d) {
        this.ho.apply(this, arguments);
    };
    Object.defineProperty(CategoryYAxis.prototype, "j$b", {
        get: function () {
            return this.ch;
        },
        enumerable: false,
        configurable: true
    });
    CategoryYAxis.prototype.j$a = function () {
        return this.ag.apply(this, arguments);
    };
    CategoryYAxis.$t = markType(CategoryYAxis, 'CategoryYAxis', CategoryAxisBase.$, [IZoomableCategoryAxis_$type]);
    CategoryYAxis.m7 = DependencyProperty.i("Interval", Number_$type, CategoryYAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        a.h2("Interval", b.oldValue, b.newValue);
        a.h8(false);
    }));
    CategoryYAxis.m8 = DependencyProperty.i("MinorInterval", Number_$type, CategoryYAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        (typeCast(CategoryYAxis.$, a)).h2("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryYAxis.$, a)).h8(false);
    }));
    CategoryYAxis.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryYAxis, 'h2', ['ZoomMaximumCategoryRange::m9', [1, NaN], 'ZoomMaximumItemSpan::na', [1, NaN], 'ZoomToCategoryRange::nb', [1, NaN], 'ZoomToCategoryStart::nc', [1, NaN], 'ZoomToItemSpan::nd', [1, NaN]]);
    return CategoryYAxis;
}(CategoryAxisBase));
export { CategoryYAxis };
/**
 * @hidden
 */
var CategoryYAxisView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CategoryYAxisView, _super);
    function CategoryYAxisView(a) {
        var _this = _super.call(this, a) || this;
        _this.bm = null;
        _this.bm = a;
        return _this;
    }
    CategoryYAxisView.prototype.al = function () {
        _super.prototype.al.call(this);
        this.a.fh = AxisDefaults.f;
    };
    CategoryYAxisView.$t = markType(CategoryYAxisView, 'CategoryYAxisView', CategoryAxisBaseView.$);
    return CategoryYAxisView;
}(CategoryAxisBaseView));
export { CategoryYAxisView };
