/*
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 { TimeAxisBase } from "./TimeAxisBase";
import { DependencyProperty } from "igniteui-react-core";
import { TimeAxisDisplayType_$type } from "./TimeAxisDisplayType";
import { Base, enumGetBox, Number_$type, typeGetValue, typeCast, markType, markDep } from "igniteui-react-core";
import { Rect } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { NumericYAxis } from "./NumericYAxis";
import { LinearNumericSnapper } from "./LinearNumericSnapper";
import { LabelPosition } from "./LabelPosition";
import { PropertyMetadata } from "igniteui-react-core";
import { truncate, intDivide, isNaN_, isInfinity } from "igniteui-react-core";
import { dateMinValue, dateFromTicks } from "igniteui-react-core";
import { timeSpanFromMilliseconds } from "igniteui-react-core";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
import { AxisDefaults } from "./AxisDefaults";
/**
 * @hidden
 */
var CategoryDateTimeXAxis = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CategoryDateTimeXAxis, _super);
    function CategoryDateTimeXAxis() {
        var _this = _super.call(this) || this;
        _this.nw = 0;
        _this.nx = 0;
        _this.ab = CategoryDateTimeXAxis.$;
        _this.actualMinimumValue = (new Date());
        _this.actualMaximumValue = (new Date());
        return _this;
    }
    CategoryDateTimeXAxis.prototype.get_cd = function () {
        return this.nq == 0;
    };
    CategoryDateTimeXAxis.prototype.a4 = function () {
        return new CategoryDateTimeXAxisView(this);
    };
    CategoryDateTimeXAxis.prototype.ht = function (a) {
        _super.prototype.ht.call(this, a);
        this.np = a;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "ny", {
        get: function () {
            return this.nw;
        },
        set: function (a) {
            if (this.ny != a) {
                var b = this.nw;
                this.nw = a;
                this.h3("ActualInterval", b, this.ny);
            }
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.ew = function () {
        return this.ny;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "n2", {
        get: function () {
            return typeGetValue(this.c(CategoryDateTimeXAxis.oe));
        },
        set: function (a) {
            this.h(CategoryDateTimeXAxis.oe, a);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "nz", {
        get: function () {
            return this.nx;
        },
        set: function (a) {
            if (this.nz != a) {
                var b = this.nx;
                this.nx = a;
                this.h3("ActualMinorInterval", b, this.nz);
            }
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.c8 = function (a, b, c) {
        var d = _super.prototype.c8.call(this, a, b, c);
        if (!d) {
            return false;
        }
        return +(this.actualMinimumValue) != +(this.actualMaximumValue);
    };
    CategoryDateTimeXAxis.prototype.d5 = function () {
        return this.ny;
    };
    CategoryDateTimeXAxis.prototype.ia = function (a) {
        _super.prototype.ia.call(this, a);
        var b = this.bi != null ? this.bi.vl : Rect.empty;
        var c = !b.isEmpty ? this.ke : Rect.empty;
        var d = this.j9();
        var e = this.j8();
        var f = new ScalerParams(0, b, c, this.ch, d);
        if ((this.mj == null || this.mj.count < 1) && !this.mp() && !this.mq()) {
            return;
        }
        if (!b.isEmpty && !c.isEmpty && (this.nq != 1 || this.mj != null)) {
            var g = c.bottom;
            var h = g - c.top;
            if (this.aj != null) {
                var i = typeCast(NumericYAxis.$, this.aj);
                if (i != null) {
                    var j = this.ig(g, h, b, c, d, c.top, c.bottom);
                    g = j.p0;
                    h = j.p1;
                }
            }
            if (isNaN_(g)) {
                g = 0;
            }
            this.hr(this.a5.a4(), g, c, this.a5.e(), true);
            this.aw.bg = h;
            var k = this.a5.a7();
            var l = this.a5.f();
            var m = this.a5.a5();
            var n = this.a5.a6();
            var o = this.a5.g();
            if (this.nq == 1) {
                var p = this.i$e(b, c, d, e);
                var q = this.i$g(b, c, d, e);
                if (p < 0 || q < 0) {
                    return;
                }
                var r = NaN;
                for (var s = p; s <= q; s++) {
                    var t = this.ms == null ? s : this.ms._inner[s];
                    var u = this.ek(this.mj.item(t).getTime(), f);
                    if (u == r) {
                        continue;
                    }
                    r = u;
                    if (this.categoryMode == 2) {
                        u += this.ch ? -this.getGroupCenter(s, b, c, d) : this.getGroupCenter(s, b, c, d);
                    }
                    if (u < e.left || u > e.right) {
                        continue;
                    }
                    this.io(m, u, c, l, false);
                    this.kz.add(u);
                    if (this.ks != null && s < this.ks.count) {
                        var v = this.ks.item(t);
                        var w = _super.prototype.f0.call(this, v);
                        if (!isNaN_(u) && !isInfinity(u) && w != null) {
                            if ((typeof w === 'string') && Base.equalsStatic(w, "")) {
                            }
                            else {
                                this.dc.add1(w);
                                this.dd.add(new LabelPosition(u));
                            }
                        }
                    }
                }
            }
            else {
                var x = this.en(e.left, f);
                var y = this.en(e.right, f);
                var z = Math.min(x, y);
                var aa = Math.max(x, y);
                var ab = new LinearNumericSnapper(0, z, aa, e.width, this.ez());
                var ac = this.mn ? this.nv() : ab.g;
                this.oa(truncate(ac));
                var ad = truncate(Math.floor((z - this.actualMinimumValue.getTime()) / ac));
                var ae = truncate(Math.ceil((aa - this.actualMinimumValue.getTime()) / ac));
                var af = 0;
                if (this.categoryMode == 2) {
                    af = this.getGroupCenter(0, b, c, d);
                    af = this.ch ? -af : af;
                }
                var ag = truncate(Math.ceil(e.right));
                var ah = truncate(Math.floor(e.left));
                var ai = this.ek(this.actualMinimumValue.getTime() + ad * ac, f) + af;
                for (var aj = ad; aj <= ae; aj++) {
                    var ak = this.ek(this.actualMinimumValue.getTime() + (aj + 1) * ac, f) + af;
                    if (!isNaN_(ai) && !isInfinity(ai)) {
                        var al = truncate(Math.round(ai));
                        if (al <= ag) {
                            if (aj % 2 == 0) {
                                this.ip(k, ai, ak, c);
                            }
                            this.io(m, ai, c, l, false);
                            this.kz.add(ai);
                            if (this.cy) {
                                var am = this.n0();
                                if (am > 0 && am < ac) {
                                    if (ac / am < 20) {
                                        var an = ai;
                                        var ao = Math.abs(this.ek(this.actualMinimumValue.getTime() + am, f) - this.ek(this.actualMinimumValue.getTime(), f));
                                        while (an + ao < ak) {
                                            if (Math.abs(an + ao - ak) < 0.0001) {
                                                break;
                                            }
                                            an += ao;
                                            if (an > 0) {
                                                this.io(n, an, c, o, false);
                                            }
                                        }
                                        this.ob(am);
                                    }
                                }
                                else {
                                    for (var ap = 1; ap < ab.i; ++ap) {
                                        var aq = this.ek(this.actualMinimumValue.getTime() + aj * ac + (ap * ac) / ab.i, f) + af;
                                        this.io(n, aq, c, o, false);
                                    }
                                    if (ab.i > 0) {
                                        this.ob(truncate((ac / ab.i)));
                                    }
                                }
                            }
                        }
                        if (al >= ah && al <= ag) {
                            var ar = this.actualMinimumValue.getTime() + aj * ac;
                            var ticks_ = truncate(Math.floor(ar));
                            var as = (new Date(ticks_));
                            var at = this.f0(as);
                            if (at != null) {
                                this.dc.add1(at);
                                this.dd.add(new LabelPosition(ai));
                            }
                        }
                    }
                    ai = ak;
                }
            }
            if ((this.az == null || this.az.visibility == 0) && this.aj != null) {
                if (this.az != null && (this.az.location == 4 || this.az.location == 5)) {
                    this.bi.nr();
                }
            }
            this.aw.a9 = this.dc;
            this.aw.ba = this.dd;
            this.l6();
        }
    };
    CategoryDateTimeXAxis.prototype.nv = function () {
        return this.ny;
    };
    CategoryDateTimeXAxis.prototype.n0 = function () {
        return this.n2;
    };
    CategoryDateTimeXAxis.prototype.oa = function (a) {
        this.ny = a;
    };
    CategoryDateTimeXAxis.prototype.ob = function (a) {
        this.nz = a;
    };
    CategoryDateTimeXAxis.prototype.ns = function () {
        return this.n1 != 0;
    };
    CategoryDateTimeXAxis.prototype.nr = function () {
        return this.ny == 0;
    };
    CategoryDateTimeXAxis.prototype.nu = function (a) {
        return this.mj == null ? dateMinValue() : this.mj.item(a);
    };
    CategoryDateTimeXAxis.prototype.n9 = function (a, b) {
        if (a > b || this.ks == null || this.ks.count == 0) {
            return;
        }
        var c = (a.getTime() - this.actualMinimumValue.getTime()) / (this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
        var d = (b.getTime() - this.actualMinimumValue.getTime()) / (this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
        this.bi.v1 = new Rect(0, c, this.bi.v1.y, d - c, this.bi.v1.height);
    };
    CategoryDateTimeXAxis.prototype.hx = function (a, b, c, d) {
        _super.prototype.hx.call(this, a, b, c, d);
        switch (b) {
            case CategoryDateTimeXAxis.$$p[0]:
                this.cq = true;
                this.aw.al = this.nq == 1 || this.nt;
                this.h9(false);
                break;
            case CategoryDateTimeXAxis.$$p[1]:
                this.cq = true;
                this.h9(false);
                break;
            case CategoryDateTimeXAxis.$$p[2]:
                this.aw.al = this.nq == 1 || this.nt;
                break;
        }
    };
    CategoryDateTimeXAxis.prototype.nf = function () {
        _super.prototype.nf.call(this);
        if (this.ns()) {
            this.ny = this.n1;
            var a = this.bi != null ? this.bi.vl : Rect.empty;
            var b = !a.isEmpty ? this.ke : Rect.empty;
            var c = Math.abs(this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
            this.mn = this.nr() || (this.nq == 1) || (1 * c / this.nv() > (b.width / a.width)) ? false : true;
        }
        else {
            this.mn = false;
        }
    };
    CategoryDateTimeXAxis.prototype.nd = function (a, b) {
        var c = b.getTime() - a.getTime();
        var timeOffset_ = truncate(Math.round(intDivide(c, this.lg) / 2));
        return timeOffset_ == 0 ? timeSpanFromMilliseconds(1) : timeSpanFromMilliseconds(timeOffset_);
    };
    CategoryDateTimeXAxis.prototype.get_cc = function () {
        return true;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.cp;
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.j$d = function (a, b) {
        return this.en.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$c = function (a, b) {
        return this.ek.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$e = function (a, b, c, d, e) {
        this.hn.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.ho.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$g = function (a, b, c, d) {
        this.hp.apply(this, arguments);
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "j$b", {
        get: function () {
            return this.ch;
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.j$a = function () {
        return this.ag.apply(this, arguments);
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "i$a", {
        get: function () {
            return this.ce;
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.$t = markType(CategoryDateTimeXAxis, 'CategoryDateTimeXAxis', TimeAxisBase.$);
    CategoryDateTimeXAxis.oe = DependencyProperty.i("MinorInterval", Number_$type, CategoryDateTimeXAxis.$, new PropertyMetadata(2, 0, function (a, b) {
        (typeCast(CategoryDateTimeXAxis.$, a)).h3("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryDateTimeXAxis.$, a)).h9(false);
    }));
    CategoryDateTimeXAxis.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryDateTimeXAxis, 'h3', ['DisplayType:nq:oc', [TimeAxisDisplayType_$type, enumGetBox(TimeAxisDisplayType_$type, 0)], 'Interval:n1:od', [1, 0], 'UnevenlySpacedLabels:nt:of', [0, false]]);
    return CategoryDateTimeXAxis;
}(TimeAxisBase));
export { CategoryDateTimeXAxis };
/**
 * @hidden
 */
var CategoryDateTimeXAxisView = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(CategoryDateTimeXAxisView, _super);
    function CategoryDateTimeXAxisView(a) {
        var _this = _super.call(this, a) || this;
        _this.bm = null;
        _this.bm = a;
        return _this;
    }
    CategoryDateTimeXAxisView.prototype.al = function () {
        _super.prototype.al.call(this);
        this.a.fi = AxisDefaults.f;
    };
    CategoryDateTimeXAxisView.prototype.s = function (a) {
        var b = this.q(dateFromTicks(truncate(a)));
        return b;
    };
    CategoryDateTimeXAxisView.$t = markType(CategoryDateTimeXAxisView, 'CategoryDateTimeXAxisView', CategoryAxisBaseView.$);
    return CategoryDateTimeXAxisView;
}(CategoryAxisBaseView));
export { CategoryDateTimeXAxisView };
