/*
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 * as tslib_1 from "tslib";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { Base, Number_$type, typeCast, Array_$type, markType, TypeRegistrar } from "igniteui-react-core";
import { DependencyProperty } from "igniteui-react-core";
import { List$1 } from "igniteui-react-core";
import { HorizontalAxisLabelPanel } from "./HorizontalAxisLabelPanel";
import { Rect } from "igniteui-react-core";
import { MathUtil } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { NumericScaler } from "./NumericScaler";
import { LinearCategorySnapper } from "./LinearCategorySnapper";
import { NumericYAxis } from "./NumericYAxis";
import { LabelPosition } from "./LabelPosition";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, isNaN_, isInfinity } from "igniteui-react-core";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
/**
 * @hidden
 */
var CategoryXAxis = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CategoryXAxis, _super);
    function CategoryXAxis() {
        var _this = _super.call(this) || this;
        _this.li = 1;
        _this.lh = 1;
        _this.ll = null;
        _this.k8 = 0;
        _this.k9 = 0;
        _this.jv = new List$1(Number_$type, 0);
        _this.ab = CategoryXAxis.$;
        return _this;
    }
    CategoryXAxis.prototype.a3 = function () {
        return new CategoryXAxisView(this);
    };
    CategoryXAxis.prototype.gy = function (a) {
        _super.prototype.gy.call(this, a);
        this.k6 = a;
    };
    Object.defineProperty(CategoryXAxis.prototype, "lk", {
        get: function () {
            return this.li;
        },
        set: function (a) {
            this.li = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryXAxis.prototype, "lj", {
        get: function () {
            return this.lh;
        },
        set: function (a) {
            this.lh = a;
        },
        enumerable: true,
        configurable: true
    });
    CategoryXAxis.prototype.au = function () {
        if (this.cr) {
            return (TypeRegistrar.create('HorizontalSmartAxisLabelPanel'));
        }
        else {
            return new HorizontalAxisLabelPanel();
        }
    };
    CategoryXAxis.prototype.getCategorySize = function (a, b, c) {
        var d = this.i8(b, c);
        return d.width / (this.j8 * a.width);
    };
    CategoryXAxis.prototype.j0 = function (a, b, c) {
        var d = !isNaN_(this.jx) ? MathUtil.b(this.jx, 0, 1) : 0;
        var e = 0;
        if (!isNaN_(this.j4)) {
            e = Math.min(this.j4, 1);
        }
        else {
            e = 0;
        }
        ;
        var f = 1 - 0.5 * d;
        var g = this.ka == 0 ? 1 : this.ka;
        var h = this.getCategorySize(a, b, c) * f / (g - (g - 1) * e);
        return h;
    };
    CategoryXAxis.prototype.getGroupCenter = function (a, b, c, d) {
        var e = 0.5;
        if (this.ka > 1) {
            var f = !isNaN_(this.jx) ? MathUtil.b(this.jx, 0, 1) : 0;
            var g = 0;
            if (!isNaN_(this.j4)) {
                g = Math.min(this.j4, 1);
            }
            var h = 1 - 0.5 * f;
            var i = h / (this.ka - (this.ka - 1) * g);
            var j = (h - i) / (this.ka - 1);
            e = 0.25 * f + 0.5 * i + a * j;
        }
        return this.getCategorySize(b, c, d) * e;
    };
    CategoryXAxis.prototype.dm = function () {
        return this.lf;
    };
    CategoryXAxis.prototype.lq = function (a) {
        var b = this.bh != null ? this.bh.os : Rect.empty;
        b = b.copy();
        var c = this.ja;
        var d = this.i7();
        var e = new Rect(0, 0, 0, 1, 1);
        var f = new ScalerParams(0, e, e, this.ca, d);
        var g = !b.isEmpty && !c.isEmpty && this.jo != null ? this.jo.indexOf(a) : -1;
        var h = g > -1 ? this.dz(g, f) : NaN;
        if (!isNaN_(h) && this.bh.dt) {
            if (!isNaN_(h)) {
                if (h < b.left + 0.1 * b.width) {
                    h = h + 0.4 * b.width;
                    b.x = h - 0.5 * b.width;
                }
                if (h > b.right - 0.1 * b.width) {
                    h = h - 0.4 * b.width;
                    b.x = h - 0.5 * b.width;
                }
            }
            this.bh.md(b, false, true);
        }
    };
    CategoryXAxis.prototype.dz = function (a, b) {
        if (!b.c.isEmpty) {
            var c = this.le(a, NumericScaler.ac, b.c, this.categoryMode);
            c = (c - b.d.left) / b.d.width;
            c = b.d.left + b.d.width * (c - b.e.left) / b.e.width;
            return c;
        }
        return this.le(a, b.e, b.d, this.categoryMode);
    };
    CategoryXAxis.prototype.k5 = function (a) {
        if (typeCast(List$1.$.specialize(Array_$type), a) !== null) {
            return a.asArray();
        }
        return null;
    };
    CategoryXAxis.prototype.gs = 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.j8 - 1 : this.j8;
        if (l < 0) {
            l = 0;
        }
        var m = i.left;
        var n = i.width;
        var o = g.left;
        var p = g.width;
        var q = h.left;
        var r = h.width;
        var s = 0;
        var t = 1;
        var u = this.k5(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;
                    z = (z - q) / r;
                    var aa = q + r * (z - o) / p;
                    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;
                }
            }
        }
    };
    CategoryXAxis.prototype.d0 = function (a, b, c) {
        if (!b.c.isEmpty) {
            var d = this.le(a, NumericScaler.ac, b.c, c);
            d = (d - b.d.left) / b.d.width;
            d = b.d.left + b.d.width * (d - b.e.left) / b.e.width;
            return d;
        }
        return this.le(a, b.e, b.d, c);
    };
    CategoryXAxis.prototype.le = function (a, b, c, d) {
        var e = d == 0 ? this.j8 - 1 : this.j8;
        if (e < 0) {
            e = 0;
        }
        var f = e >= 1 ? (a) / (e) : e == 0 ? 0.5 : NaN;
        if (this.cb) {
            f = 1 - f;
        }
        return c.left + c.width * (f - b.left) / b.width;
    };
    CategoryXAxis.prototype.d2 = function (a, b) {
        if (!b.c.isEmpty) {
            var c = b.e.left + b.e.width * (a - b.d.left) / b.d.width;
            c = (c * b.d.width) + b.d.left;
            c = this.getUnscaledValue3(c, NumericScaler.ac, b.c, this.categoryMode);
            return c;
        }
        return this.getUnscaledValue3(a, b.e, b.d, this.categoryMode);
    };
    CategoryXAxis.prototype.d3 = function (a, b, c) {
        if (!b.c.isEmpty) {
            var d = b.e.left + b.e.width * (a - b.d.left) / b.d.width;
            d = (d * b.d.width) + b.d.left;
            d = this.getUnscaledValue3(d, NumericScaler.ac, b.c, c);
            return d;
        }
        return this.getUnscaledValue3(a, b.e, b.d, c);
    };
    CategoryXAxis.prototype.getUnscaledValue3 = function (a, b, c, d) {
        var e = b.left + (a - c.left) * b.width / c.width;
        if (this.cb) {
            e = 1 - e;
        }
        var f = d == 0 ? this.j8 - 1 : this.j8;
        if (f < 0) {
            f = 0;
        }
        return e * f;
    };
    CategoryXAxis.prototype.lr = function (a, b) {
        if (a == NaN || b == NaN || this.jo == null || this.jo.count == 0) {
            return;
        }
        var c = a / this.jo.count;
        var d = (b + 1) / this.jo.count;
        this.bh.o8 = new Rect(0, c, this.bh.o8.y, d - c, this.bh.o8.height);
    };
    CategoryXAxis.prototype.hd = function (a) {
        _super.prototype.hd.call(this, a);
        var b = this.bh != null ? this.bh.os : Rect.empty;
        var c = this.ja;
        var d = this.i5();
        var e = this.i4();
        var f = new ScalerParams(0, b, c, this.ca, d);
        var g = this.a4.ay();
        var h = this.a4.a1();
        var i = this.a4.az();
        var j = this.a4.a0();
        var k = this.a4.e();
        var l = this.a4.f();
        var m = this.a4.g();
        var n = this.jo;
        var o = this.k7();
        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 || o == null || n.count == 0) {
            this.bq.count = 0;
            this.bp.count = 0;
            this.bo.count = 0;
            this.a4.y();
            return;
        }
        if (!b.isEmpty && !c.isEmpty) {
            var p = this.d2(e.left, f);
            var q = this.d2(e.right, f);
            var r = 0;
            var s = false;
            if (this.cq) {
                var t = Math.abs(q - p);
                r = Math.ceil(t) + 1;
                if (this.ca) {
                    if (Math.abs(q - Math.floor(q)) < Math.abs(p - Math.ceil(p))) {
                        s = true;
                    }
                }
                else {
                    if (Math.abs(q - Math.ceil(q)) < Math.abs(p - Math.floor(p))) {
                        s = true;
                    }
                }
            }
            if (this.ca) {
                p = Math.ceil(p);
                q = Math.floor(q);
            }
            else {
                p = Math.floor(p);
                q = Math.ceil(q);
            }
            if (this.cq) {
                if (Math.abs(q - p) < r) {
                    if (this.ca) {
                        if (s) {
                            q--;
                        }
                        else {
                            p++;
                        }
                    }
                    else {
                        if (s) {
                            q++;
                        }
                        else {
                            p--;
                        }
                    }
                }
            }
            var u = c.bottom;
            var v = u - c.top;
            if (this.ai != null) {
                var w = typeCast(NumericYAxis.$, this.ai);
                if (w != null) {
                    var x = this.hh(u, v, b, c, d, c.top, c.bottom);
                    u = x.p0;
                    v = x.p1;
                }
            }
            this.gw(g, u, c, k, true);
            this.a4.ao(v);
            var y = Math.min(p, q);
            var z = Math.max(p, q);
            var aa = e.width;
            if (this.cq) {
                var ab = this.dz(y, f);
                var ac = this.dz(z, f);
                aa = Math.abs(ac - ab);
            }
            var ad = new LinearCategorySnapper(1, y, z, aa, this.lf, this.categoryMode, this.ec());
            var ae = Math.floor((y - 0) / ad.g);
            var af = Math.ceil((z - 0) / ad.g);
            this.la = ad.g;
            if (!isNaN_(ae) && !isNaN_(af)) {
                var ag = truncate(ae);
                var ah = truncate(af);
                var ai = this.ld(0 + ag * ad.g, f);
                var aj = this.dz(ad.g, f);
                var ak = Math.abs(aj - this.dz(0, f));
                this.a4.ap(aj);
                var al = truncate(Math.ceil(e.right));
                var am = truncate(Math.floor(e.left));
                var an = this.lg;
                var ao = an > 0 && an < ad.g;
                var ap = c.right;
                var aq = this.jv;
                var ar = ad.g;
                var as = truncate(ar);
                var at = this.ka;
                var au = this.ca;
                var av = this.categoryMode;
                this.ll = null;
                for (var aw = ag; aw <= ah; ++aw) {
                    var ax = this.ld(0 + (aw + 1) * ad.g, f);
                    if (ai <= ap) {
                        if (aw % 2 == 0) {
                            this.hn(h, ai, ax, c);
                        }
                        this.hm(i, ai, c, l, false);
                        aq.add(ai);
                    }
                    if (this.categoryMode != 0 && this.ka != 0 && this.cl) {
                        if (ao) {
                            var ay = ak * this.lg;
                            if (this.ca) {
                                var az = ai;
                                while (az - ay > ax) {
                                    az -= ay;
                                    if (Math.abs(az - ax) < 0.0001) {
                                        break;
                                    }
                                    this.hm(j, az, c, m, false);
                                }
                            }
                            else {
                                var a0 = ai;
                                while (a0 + ay < ax) {
                                    a0 += ay;
                                    if (Math.abs(a0 - ax) < 0.0001) {
                                        break;
                                    }
                                    this.hm(j, a0, c, m, false);
                                }
                            }
                            this.lb = this.lg;
                        }
                        else {
                            for (var a1 = 0; a1 < truncate(ad.g); a1++) {
                                for (var a2 = 0; a2 < this.ka; a2++) {
                                    var a3 = this.getGroupCenter(a2, b, c, d);
                                    if (this.ca) {
                                        a3 = -a3;
                                    }
                                    var a4 = this.dz(a1 + aw * ad.g, f) + a3;
                                    this.hm(j, a4, c, m, false);
                                }
                            }
                            this.lb = 0.5;
                        }
                    }
                    var a5 = this.lc(aw * ar, ai, av == 0, f);
                    var a6 = truncate(Math.round(a5));
                    if (a6 >= am && a6 <= al) {
                        var a7 = 0;
                        if (ar >= 1) {
                            a7 = aw * truncate(Math.floor(ar));
                        }
                        else {
                            if ((aw * ar) * 2 % 2 == 0) {
                                a7 = truncate(Math.floor(aw * ar));
                            }
                            else {
                                a7 = -1;
                            }
                        }
                        if (o != null && a7 < n.count && a7 >= 0) {
                            var a8 = o.getItem(a7);
                            var a9 = this.e9(a8);
                            this.ll = a8;
                            if (!isNaN_(a5) && !isInfinity(a5) && a9 != null) {
                                if ((typeof a9 === 'string') && Base.equalsStatic(a9, "")) {
                                }
                                else {
                                    this.cx.add1(a9);
                                    this.cy.add(new LabelPosition(a5));
                                }
                            }
                        }
                    }
                    ai = ax;
                }
            }
            this.ll = null;
            if ((this.ay == null || this.ay.visibility == 0) && this.ai != null) {
                if (this.ay != null && (this.ay.location == 4 || this.ay.location == 5)) {
                    this.bh.ja();
                }
            }
            this.a4.au(this.cx, this.cy);
            this.kv();
        }
    };
    CategoryXAxis.prototype.cp = function () {
        if (this.ci && this.cq) {
            this.bb = this.ba();
        }
        if (this.jo == null) {
            return false;
        }
        var a = this.jo.count;
        if (a != this.lj) {
            var b = new AxisRangeChangedEventArgs(0, 1, 1, this.lj, a);
            this.lj = a;
            this.g7(b);
            return true;
        }
        return false;
    };
    Object.defineProperty(CategoryXAxis.prototype, "lf", {
        get: function () {
            return this.c(CategoryXAxis.ls);
        },
        set: function (a) {
            this.h(CategoryXAxis.ls, a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryXAxis.prototype, "la", {
        get: function () {
            return this.k8;
        },
        set: function (a) {
            if (this.la != a) {
                var b = this.k8;
                this.k8 = a;
                this.g6("ActualInterval", b, this.la);
            }
        },
        enumerable: true,
        configurable: true
    });
    CategoryXAxis.prototype.ea = function () {
        return this.la;
    };
    Object.defineProperty(CategoryXAxis.prototype, "lg", {
        get: function () {
            return this.c(CategoryXAxis.lt);
        },
        set: function (a) {
            this.h(CategoryXAxis.lt, a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryXAxis.prototype, "lb", {
        get: function () {
            return this.k9;
        },
        set: function (a) {
            if (this.lb != a) {
                var b = this.k9;
                this.k9 = a;
                this.g6("ActualMinorInterval", b, this.lb);
            }
        },
        enumerable: true,
        configurable: true
    });
    CategoryXAxis.prototype.jr = function (a) {
        if (a == null) {
            return false;
        }
        var b = this.bd();
        if (b == null) {
            return false;
        }
        return b.synchronizeHorizontally;
    };
    CategoryXAxis.prototype.get_a1 = function () {
        return 0;
    };
    Object.defineProperty(CategoryXAxis.prototype, "a1", {
        get: function () {
            return this.get_a1();
        },
        enumerable: true,
        configurable: true
    });
    CategoryXAxis.prototype.k7 = function () {
        return this.jo;
    };
    CategoryXAxis.prototype.ld = function (a, b) {
        return this.dz(a, b);
    };
    CategoryXAxis.prototype.lc = function (a, b, c, d) {
        if (!c) {
            var e = this.ld(a + 1, d);
            return (b + e) / 2;
        }
        return b;
    };
    Object.defineProperty(CategoryXAxis.prototype, "isVertical", {
        get: function () {
            return this.ch;
        },
        enumerable: true,
        configurable: true
    });
    CategoryXAxis.prototype.j$c = function (a, b) {
        return this.d2.apply(this, arguments);
    };
    CategoryXAxis.prototype.j$b = function (a, b) {
        return this.dz.apply(this, arguments);
    };
    CategoryXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gs.apply(this, arguments);
    };
    CategoryXAxis.prototype.j$e = function (a, b, c, d) {
        this.gt.apply(this, arguments);
    };
    CategoryXAxis.prototype.j$f = function (a, b, c, d) {
        this.gu.apply(this, arguments);
    };
    Object.defineProperty(CategoryXAxis.prototype, "j$a", {
        get: function () {
            return this.ca;
        },
        enumerable: true,
        configurable: true
    });
    CategoryXAxis.$t = markType(CategoryXAxis, 'CategoryXAxis', CategoryAxisBase.$);
    CategoryXAxis.ls = DependencyProperty.i("Interval", Number_$type, CategoryXAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        a.g6("Interval", b.oldValue, b.newValue);
        a.hc(false);
    }));
    CategoryXAxis.lt = DependencyProperty.i("MinorInterval", Number_$type, CategoryXAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        (typeCast(CategoryXAxis.$, a)).g6("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryXAxis.$, a)).hc(false);
    }));
    return CategoryXAxis;
}(CategoryAxisBase));
export { CategoryXAxis };
/**
 * @hidden
 */
var CategoryXAxisView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CategoryXAxisView, _super);
    function CategoryXAxisView(a) {
        var _this = _super.call(this, a) || this;
        _this.bg = null;
        _this.bg = a;
        return _this;
    }
    CategoryXAxisView.$t = markType(CategoryXAxisView, 'CategoryXAxisView', CategoryAxisBaseView.$);
    return CategoryXAxisView;
}(CategoryAxisBaseView));
export { CategoryXAxisView };
//# sourceMappingURL=CategoryXAxis_combined.js.map
