/*
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.lh = 1;
        _this.lg = 1;
        _this.lk = null;
        _this.k7 = 0;
        _this.k8 = 0;
        _this.ju = new List$1(Number_$type, 0);
        _this.ab = CategoryXAxis.$;
        return _this;
    }
    CategoryXAxis.prototype.a3 = function () {
        return new CategoryXAxisView(this);
    };
    CategoryXAxis.prototype.gx = function (a) {
        _super.prototype.gx.call(this, a);
        this.k5 = a;
    };
    Object.defineProperty(CategoryXAxis.prototype, "lj", {
        get: function () {
            return this.lh;
        },
        set: function (a) {
            this.lh = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryXAxis.prototype, "li", {
        get: function () {
            return this.lg;
        },
        set: function (a) {
            this.lg = 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.i7(b, c);
        return d.width / (this.j7 * a.width);
    };
    CategoryXAxis.prototype.jz = function (a, b, c) {
        var d = !isNaN_(this.jw) ? MathUtil.b(this.jw, 0, 1) : 0;
        var e = 0;
        if (!isNaN_(this.j3)) {
            e = Math.min(this.j3, 1);
        }
        else {
            e = 0;
        }
        ;
        var f = 1 - 0.5 * d;
        var g = this.j9 == 0 ? 1 : this.j9;
        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.j9 > 1) {
            var f = !isNaN_(this.jw) ? MathUtil.b(this.jw, 0, 1) : 0;
            var g = 0;
            if (!isNaN_(this.j3)) {
                g = Math.min(this.j3, 1);
            }
            var h = 1 - 0.5 * f;
            var i = h / (this.j9 - (this.j9 - 1) * g);
            var j = (h - i) / (this.j9 - 1);
            e = 0.25 * f + 0.5 * i + a * j;
        }
        return this.getCategorySize(b, c, d) * e;
    };
    CategoryXAxis.prototype.dl = function () {
        return this.le;
    };
    CategoryXAxis.prototype.lp = function (a) {
        var b = this.bh != null ? this.bh.n2 : Rect.empty;
        b = b.copy();
        var c = this.i9;
        var d = this.i6();
        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.jn != null ? this.jn.indexOf(a) : -1;
        var h = g > -1 ? this.dy(g, f) : NaN;
        if (!isNaN_(h) && this.bh.dk) {
            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.lr(b, false, true);
        }
    };
    CategoryXAxis.prototype.dy = function (a, b) {
        if (!b.c.isEmpty) {
            var c = this.ld(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.ld(a, b.e, b.d, this.categoryMode);
    };
    CategoryXAxis.prototype.k4 = function (a) {
        if (typeCast(List$1.$.specialize(Array_$type), a) !== null) {
            return a.asArray();
        }
        return null;
    };
    CategoryXAxis.prototype.gr = 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.j7 - 1 : this.j7;
        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.k4(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 - (o * r)) / 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.dz = function (a, b, c) {
        if (!b.c.isEmpty) {
            var d = this.ld(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.ld(a, b.e, b.d, c);
    };
    CategoryXAxis.prototype.ld = function (a, b, c, d) {
        var e = d == 0 ? this.j7 - 1 : this.j7;
        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.d1 = 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.d2 = 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.j7 - 1 : this.j7;
        if (f < 0) {
            f = 0;
        }
        return e * f;
    };
    CategoryXAxis.prototype.lq = function (a, b) {
        if (a == NaN || b == NaN || this.jn == null || this.jn.count == 0) {
            return;
        }
        var c = a / this.jn.count;
        var d = (b + 1) / this.jn.count;
        this.bh.oi = new Rect(0, c, this.bh.oi.y, d - c, this.bh.oi.height);
    };
    CategoryXAxis.prototype.hc = function (a) {
        _super.prototype.hc.call(this, a);
        var b = this.bh != null ? this.bh.n2 : Rect.empty;
        var c = this.i9;
        var d = this.i4();
        var e = this.i3();
        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.jn;
        var o = this.k6();
        this.hk();
        this.gn(g);
        this.gn(h);
        this.gn(i);
        this.gn(j);
        this.cx.clear();
        this.cy.clear();
        this.ju.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.d1(e.left, f);
            var q = this.d1(e.right, f);
            if (this.ca) {
                p = Math.ceil(p);
                q = Math.floor(q);
            }
            else {
                p = Math.floor(p);
                q = Math.ceil(q);
            }
            var r = c.bottom;
            var s = r - c.top;
            if (this.ai != null) {
                var t = typeCast(NumericYAxis.$, this.ai);
                if (t != null) {
                    var u = this.hg(r, s, b, c, d, c.top, c.bottom);
                    r = u.p0;
                    s = u.p1;
                }
            }
            this.gv(g, r, c, k, true);
            this.a4.ao(s);
            var v = Math.min(p, q);
            var w = Math.max(p, q);
            var x = new LinearCategorySnapper(1, v, w, e.width, this.le, this.categoryMode, this.eb());
            var y = Math.floor((v - 0) / x.g);
            var z = Math.ceil((w - 0) / x.g);
            this.k9 = x.g;
            if (!isNaN_(y) && !isNaN_(z)) {
                var aa = truncate(y);
                var ab = truncate(z);
                var ac = this.lc(0 + aa * x.g, f);
                var ad = this.dy(x.g, f);
                var ae = Math.abs(ad - this.dy(0, f));
                this.a4.ap(ad);
                var af = truncate(Math.ceil(e.right));
                var ag = truncate(Math.floor(e.left));
                var ah = this.lf;
                var ai = ah > 0 && ah < x.g;
                var aj = c.right;
                var ak = this.ju;
                var al = x.g;
                var am = truncate(al);
                var an = this.j9;
                var ao = this.ca;
                var ap = this.categoryMode;
                this.lk = null;
                for (var aq = aa; aq <= ab; ++aq) {
                    var ar = this.lc(0 + (aq + 1) * x.g, f);
                    if (ac <= aj) {
                        if (aq % 2 == 0) {
                            this.hm(h, ac, ar, c);
                        }
                        this.hl(i, ac, c, l, false);
                        ak.add(ac);
                    }
                    if (this.categoryMode != 0 && this.j9 != 0 && this.cl) {
                        if (ai) {
                            var as = ae * this.lf;
                            if (this.ca) {
                                var at = ac;
                                while (at - as > ar) {
                                    at -= as;
                                    if (Math.abs(at - ar) < 0.0001) {
                                        break;
                                    }
                                    this.hl(j, at, c, m, false);
                                }
                            }
                            else {
                                var au = ac;
                                while (au + as < ar) {
                                    au += as;
                                    if (Math.abs(au - ar) < 0.0001) {
                                        break;
                                    }
                                    this.hl(j, au, c, m, false);
                                }
                            }
                            this.la = this.lf;
                        }
                        else {
                            for (var av = 0; av < truncate(x.g); av++) {
                                for (var aw = 0; aw < this.j9; aw++) {
                                    var ax = this.getGroupCenter(aw, b, c, d);
                                    if (this.ca) {
                                        ax = -ax;
                                    }
                                    var ay = this.dy(av + aq * x.g, f) + ax;
                                    this.hl(j, ay, c, m, false);
                                }
                            }
                            this.la = 0.5;
                        }
                    }
                    var az = this.lb(aq * al, ac, ap == 0, f);
                    var a0 = truncate(Math.round(az));
                    if (a0 >= ag && a0 <= af) {
                        var a1 = 0;
                        if (al >= 1) {
                            a1 = aq * truncate(Math.floor(al));
                        }
                        else {
                            if ((aq * al) * 2 % 2 == 0) {
                                a1 = truncate(Math.floor(aq * al));
                            }
                            else {
                                a1 = -1;
                            }
                        }
                        if (o != null && a1 < n.count && a1 >= 0) {
                            var a2 = o.getItem(a1);
                            var a3 = this.e8(a2);
                            this.lk = a2;
                            if (!isNaN_(az) && !isInfinity(az) && a3 != null) {
                                if ((typeof a3 === 'string') && Base.equalsStatic(a3, "")) {
                                }
                                else {
                                    this.cx.add1(a3);
                                    this.cy.add(new LabelPosition(az));
                                }
                            }
                        }
                    }
                    ac = ar;
                }
            }
            this.lk = 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.it();
                }
            }
            this.a4.au(this.cx, this.cy);
            this.ku();
        }
    };
    CategoryXAxis.prototype.cp = function () {
        if (this.ci && this.cq) {
            this.bb = this.ba();
        }
        if (this.jn == null) {
            return false;
        }
        var a = this.jn.count;
        if (a != this.li) {
            var b = new AxisRangeChangedEventArgs(0, 1, 1, this.li, a);
            this.li = a;
            this.g6(b);
            return true;
        }
        return false;
    };
    Object.defineProperty(CategoryXAxis.prototype, "le", {
        get: function () {
            return this.c(CategoryXAxis.lr);
        },
        set: function (a) {
            this.h(CategoryXAxis.lr, a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryXAxis.prototype, "k9", {
        get: function () {
            return this.k7;
        },
        set: function (a) {
            if (this.k9 != a) {
                var b = this.k7;
                this.k7 = a;
                this.g5("ActualInterval", b, this.k9);
            }
        },
        enumerable: true,
        configurable: true
    });
    CategoryXAxis.prototype.d9 = function () {
        return this.k9;
    };
    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.g5("ActualMinorInterval", b, this.la);
            }
        },
        enumerable: true,
        configurable: true
    });
    CategoryXAxis.prototype.jq = 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.k6 = function () {
        return this.jn;
    };
    CategoryXAxis.prototype.lc = function (a, b) {
        return this.dy(a, b);
    };
    CategoryXAxis.prototype.lb = function (a, b, c, d) {
        if (!c) {
            var e = this.lc(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.d1.apply(this, arguments);
    };
    CategoryXAxis.prototype.j$b = function (a, b) {
        return this.dy.apply(this, arguments);
    };
    CategoryXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gr.apply(this, arguments);
    };
    CategoryXAxis.prototype.j$e = function (a, b, c, d) {
        this.gs.apply(this, arguments);
    };
    CategoryXAxis.prototype.j$f = function (a, b, c, d) {
        this.gt.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.lr = DependencyProperty.i("Interval", Number_$type, CategoryXAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        a.g5("Interval", b.oldValue, b.newValue);
        a.hb(false);
    }));
    CategoryXAxis.ls = DependencyProperty.i("MinorInterval", Number_$type, CategoryXAxis.$, new PropertyMetadata(2, NaN, function (a, b) {
        (typeCast(CategoryXAxis.$, a)).g5("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryXAxis.$, a)).hb(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
