/*
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 { DependencyProperty } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { Base, typeCast, Array_$type, Number_$type, markType } from "igniteui-angular-core";
import { List$1 } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { NumericScaler } from "./NumericScaler";
import { VerticalAxisLabelPanel } from "./VerticalAxisLabelPanel";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { LinearCategorySnapper } from "./LinearCategorySnapper";
import { NumericXAxis } from "./NumericXAxis";
import { LabelPosition } from "./LabelPosition";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, isNaN_, isInfinity } from "igniteui-angular-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.mi = 0;
        _this.mj = 0;
        _this.mq = 1;
        _this.mp = 1;
        _this.kx = new List$1(Number_$type, 0);
        _this.ab = CategoryYAxis.$;
        return _this;
    }
    CategoryYAxis.prototype.a3 = function () {
        return new CategoryYAxisView(this);
    };
    CategoryYAxis.prototype.hr = function (a) {
        _super.prototype.hr.call(this, a);
        this.mg = a;
    };
    CategoryYAxis.prototype.get_co = function () {
        return true;
    };
    CategoryYAxis.prototype.eh = function () {
        return this.j6().height;
    };
    CategoryYAxis.prototype.md = function (a, b, c) {
        return this.me(a, b, c, true);
    };
    CategoryYAxis.prototype.mf = function (a) {
        if (typeCast(List$1.$.specialize(Array_$type), a) !== null) {
            return a.asArray();
        }
        return null;
    };
    CategoryYAxis.prototype.hl = 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.le - 1 : this.le;
        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.mf(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, "mn", {
        get: function () {
            return this.c(CategoryYAxis.mz);
        },
        set: function (a) {
            this.h(CategoryYAxis.mz, a);
        },
        enumerable: false,
        configurable: true
    });
    CategoryYAxis.prototype.mh = function () {
        return !isNaN_(this.mn);
    };
    Object.defineProperty(CategoryYAxis.prototype, "mk", {
        get: function () {
            return this.mi;
        },
        set: function (a) {
            if (this.mk != a) {
                var b = this.mi;
                this.mi = a;
                this.h1("ActualInterval", b, this.mk);
            }
        },
        enumerable: false,
        configurable: true
    });
    CategoryYAxis.prototype.eu = function () {
        return this.mk;
    };
    Object.defineProperty(CategoryYAxis.prototype, "mo", {
        get: function () {
            return this.c(CategoryYAxis.m0);
        },
        set: function (a) {
            this.h(CategoryYAxis.m0, a);
        },
        enumerable: false,
        configurable: true
    });
    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.h1("ActualMinorInterval", b, this.ml);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "ms", {
        get: function () {
            return this.mq;
        },
        set: function (a) {
            this.mq = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "mr", {
        get: function () {
            return this.mp;
        },
        set: function (a) {
            this.mp = a;
        },
        enumerable: false,
        configurable: true
    });
    CategoryYAxis.prototype.ei = function (a, b) {
        if (!b.c.isEmpty) {
            var c = this.mm(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.mm(a, b.e, b.d);
    };
    CategoryYAxis.prototype.mm = function (a, b, c) {
        var d = this.categoryMode == 0 ? this.le - 1 : this.le;
        if (d < 0) {
            d = 0;
        }
        var e = d >= 1 ? (a) / (d) : d == 0 ? 0.5 : NaN;
        if (!this.ch) {
            e = 1 - e;
        }
        return c.top + c.height * (e - b.top) / b.height;
    };
    CategoryYAxis.prototype.el = 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.em = 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.ch) {
            e = 1 - e;
        }
        var f = d == 0 ? this.le - 1 : this.le;
        if (f < 0) {
            f = 0;
        }
        return e * f;
    };
    CategoryYAxis.prototype.my = function (a, b) {
        if (a == NaN || b == NaN || this.kq == null || this.kq.count == 0) {
            return;
        }
        var c = a / this.kq.count;
        var d = b / this.kq.count;
        this.bh.sv = new Rect(0, this.bh.sv.x, 1 - d, this.bh.sv.width, d - c);
    };
    CategoryYAxis.prototype.au = function () {
        return new VerticalAxisLabelPanel();
    };
    CategoryYAxis.prototype.d3 = function () {
        return this.mn;
    };
    CategoryYAxis.prototype.getCategorySize = function (a, b, c) {
        var d = this.ka(b, c);
        return d.height / (this.le * a.height);
    };
    CategoryYAxis.prototype.k3 = function (a, b, c) {
        var d = this.la(a, b, c);
        var e = 0;
        if (!isNaN_(this.k9)) {
            e = Math.min(this.k9, 1);
        }
        var f = 1 - 0.5 * d;
        var g = this.getCategorySize(a, b, c) * f / (this.lg - (this.lg - 1) * e);
        return g;
    };
    CategoryYAxis.prototype.getGroupCenter = function (a, b, c, d) {
        var e = 0.5;
        if (this.lg > 1) {
            var f = this.la(b, c, d);
            var g = 0;
            if (!isNaN_(this.k9)) {
                g = Math.min(this.k9, 1);
            }
            var h = 1 - 0.5 * f;
            var i = h / (this.lg - (this.lg - 1) * g);
            var j = (h - i) / (this.lg - 1);
            e = 0.25 * f + 0.5 * i + a * j;
        }
        return this.getCategorySize(b, c, d) * e;
    };
    CategoryYAxis.prototype.mx = function (a) {
        var b = this.bh != null ? this.bh.sf : Rect.empty;
        b = b.copy();
        var c = this.kc;
        var d = new Rect(0, 0, 0, 1, 1);
        var e = this.j9();
        var f = new ScalerParams(0, d, d, this.cg, e);
        var g = !b.isEmpty && !c.isEmpty && this.kq != null ? this.kq.indexOf(a) : -1;
        var h = g > -1 ? this.ei(g, f) : NaN;
        if (!isNaN_(h) && this.bh.ei) {
            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.ou(b, false, true);
        }
    };
    CategoryYAxis.prototype.c2 = function () {
        if (this.cp && this.c3) {
            this.bb = this.ba();
        }
        if (this.kq == null) {
            return false;
        }
        var a = this.kq.count;
        if (a != this.mr) {
            var b = new AxisRangeChangedEventArgs(0, 1, 1, this.mr, a);
            this.mr = a;
            this.h2(b);
            return true;
        }
        return false;
    };
    CategoryYAxis.prototype.kt = function (a) {
        if (a == null) {
            return false;
        }
        var b = this.bd();
        if (b == null) {
            return false;
        }
        return b.synchronizeVertically;
    };
    CategoryYAxis.prototype.h8 = function (a) {
        _super.prototype.h8.call(this, a);
        var b = this.bh != null ? this.bh.sf : Rect.empty;
        var c = this.kc;
        var d = this.j7();
        var e = this.j6();
        var f = new ScalerParams(0, b, c, this.cg, d);
        var g = this.a4.a1();
        var h = this.a4.a4();
        var i = this.a4.a2();
        var j = this.a4.a3();
        var k = this.a4.e();
        var l = this.a4.f();
        var m = this.a4.g();
        this.ik();
        this.hh(g);
        this.hh(h);
        this.hh(i);
        this.hh(j);
        this.db.clear();
        this.dc.clear();
        this.kx.clear();
        this.a4.aw(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.ab();
        }
        if (this.ay != null) {
            this.ay.registerAxis(this);
        }
        if (this.itemsSource == null || this.kq == null || this.kq.count == 0) {
            this.bq.count = 0;
            this.bp.count = 0;
            this.bo.count = 0;
            this.a4.ab();
            return;
        }
        if (!b.isEmpty && !c.isEmpty) {
            var n = this.el(e.top, f);
            var o = this.el(e.bottom, f);
            if (!this.cg) {
                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.ai != null) {
                var r = typeCast(NumericXAxis.$, this.ai);
                if (r != null) {
                    var s = this.id(p, q, b, c, d, c.left, c.right);
                    p = s.p0;
                    q = s.p1;
                }
            }
            this.il(g, p, c, k, true);
            this.a4.ar(q);
            var t = Math.min(n, o);
            var u = Math.max(n, o);
            var v = new LinearCategorySnapper(1, t, u, e.height, this.mn, this.categoryMode, this.ex());
            var w = v.g;
            while (!this.mh() && w < 10 && this.cy(w, b, c, d)) {
                w--;
            }
            if (v.g != w) {
                v = new LinearCategorySnapper(1, t, u, e.height, w, this.categoryMode, this.ex());
            }
            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.ei(0 + z * v.g, f);
                var ac = Math.abs(this.ei(v.g, f) - this.ei(0, f));
                this.av.bw = this.ei(v.g, f);
                for (var ad = z; ad <= aa; ++ad) {
                    var ae = this.ei(0 + (ad + 1) * v.g, f);
                    if (ab <= e.bottom) {
                        if (ad % 2 == 0) {
                            this.hq(h, ab, ae, c);
                        }
                        this.hp(i, ab, c, l, false);
                        this.kx.add(ab);
                    }
                    if (this.categoryMode != 0 && this.lg != 0 && this.cx) {
                        if (this.mo > 0 && this.mo < v.g) {
                            var af = ac * this.mo;
                            if (!this.cg) {
                                var ag = ab;
                                while (ag - af > ae) {
                                    ag -= af;
                                    if (Math.abs(ag - ae) < 0.0001) {
                                        break;
                                    }
                                    this.hp(j, ag, c, m, false);
                                }
                            }
                            else {
                                var ah = ab;
                                while (ah + af < ae) {
                                    ah += af;
                                    if (Math.abs(ah - ae) < 0.0001) {
                                        break;
                                    }
                                    this.hp(j, ah, c, m, false);
                                }
                            }
                            this.ml = this.mo;
                        }
                        else {
                            for (var ai = 0; ai < truncate(v.g); ai++) {
                                for (var aj = 0; aj < this.lg; aj++) {
                                    var ak = this.getGroupCenter(aj, b, c, d);
                                    if (!this.cg) {
                                        ak = -ak;
                                    }
                                    var al = this.ei(ai + ad * v.g, f) + ak;
                                    this.hp(j, al, c, m, false);
                                }
                            }
                            this.ml = 0.5;
                        }
                    }
                    var am = ab;
                    if (this.categoryMode != 0) {
                        var an = this.ei(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.kq != null && ao < this.kq.count && ao >= 0) {
                            var ap = this.kq.item(ao);
                            var aq = this.fy(ap);
                            if (!isNaN_(am) && !isInfinity(am) && aq != null) {
                                if ((typeof aq === 'string') && Base.equalsStatic(aq, "")) {
                                }
                                else {
                                    this.db.add1(aq);
                                    this.dc.add(new LabelPosition(am));
                                }
                            }
                        }
                    }
                    ab = ae;
                }
            }
            this.mk = 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.lj();
                }
            }
            this.a4.ax(this.db, this.dc);
            this.l3();
        }
    };
    CategoryYAxis.prototype.get_a1 = function () {
        return 1;
    };
    Object.defineProperty(CategoryYAxis.prototype, "a1", {
        get: function () {
            return this.get_a1();
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CategoryYAxis.prototype, "isVertical", {
        get: function () {
            return this.co;
        },
        enumerable: false,
        configurable: true
    });
    CategoryYAxis.prototype.j$c = function (a, b) {
        return this.el.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$b = function (a, b) {
        return this.ei.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$d = function (a, b, c, d, e) {
        this.hl.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$e = function (a, b, c, d) {
        this.hm.apply(this, arguments);
    };
    CategoryYAxis.prototype.j$f = function (a, b, c, d) {
        this.hn.apply(this, arguments);
    };
    Object.defineProperty(CategoryYAxis.prototype, "j$a", {
        get: function () {
            return this.cg;
        },
        enumerable: false,
        configurable: true
    });
    CategoryYAxis.$t = markType(CategoryYAxis, 'CategoryYAxis', CategoryAxisBase.$);
    CategoryYAxis.mz = DependencyProperty.i("Interval", Number_$type, CategoryYAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        a.h1("Interval", b.oldValue, b.newValue);
        a.h7(false);
    }));
    CategoryYAxis.m0 = DependencyProperty.i("MinorInterval", Number_$type, CategoryYAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        (typeCast(CategoryYAxis.$, a)).h1("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryYAxis.$, a)).h7(false);
    }));
    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.bj = null;
        _this.bj = a;
        return _this;
    }
    CategoryYAxisView.prototype.aj = function () {
        _super.prototype.aj.call(this);
        this.a.fg = AxisDefaults.f;
    };
    CategoryYAxisView.$t = markType(CategoryYAxisView, 'CategoryYAxisView', CategoryAxisBaseView.$);
    return CategoryYAxisView;
}(CategoryAxisBaseView));
export { CategoryYAxisView };
