/*
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 { TimeAxisBase } from "./TimeAxisBase";
import { TimeAxisDisplayType_$type } from "./TimeAxisDisplayType";
import { DependencyProperty } from "igniteui-react-core";
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";
/**
 * @hidden
 */
var CategoryDateTimeXAxis = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CategoryDateTimeXAxis, _super);
    function CategoryDateTimeXAxis() {
        var _this = _super.call(this) || this;
        _this.mi = 0;
        _this.mj = 0;
        _this.ab = CategoryDateTimeXAxis.$;
        _this.actualMinimumValue = (new Date());
        _this.actualMaximumValue = (new Date());
        return _this;
    }
    CategoryDateTimeXAxis.prototype.get_b6 = function () {
        return this.md == 0;
    };
    CategoryDateTimeXAxis.prototype.a3 = function () {
        return new CategoryDateTimeXAxisView(this);
    };
    CategoryDateTimeXAxis.prototype.gy = function (a) {
        _super.prototype.gy.call(this, a);
        this.mc = a;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "mk", {
        get: function () {
            return this.mi;
        },
        set: function (a) {
            if (this.mk != a) {
                var b = this.mi;
                this.mi = a;
                this.g6("ActualInterval", b, this.mk);
            }
        },
        enumerable: true,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.ea = function () {
        return this.mk;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "mo", {
        get: function () {
            return typeGetValue(this.c(CategoryDateTimeXAxis.mz));
        },
        set: function (a) {
            this.h(CategoryDateTimeXAxis.mz, a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "ml", {
        get: function () {
            return this.mj;
        },
        set: function (a) {
            if (this.ml != a) {
                var b = this.mj;
                this.mj = a;
                this.g6("ActualMinorInterval", b, this.ml);
            }
        },
        enumerable: true,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.ct = function (a, b, c) {
        var d = _super.prototype.ct.call(this, a, b, c);
        if (!d) {
            return false;
        }
        return +(this.actualMinimumValue) != +(this.actualMaximumValue);
    };
    CategoryDateTimeXAxis.prototype.dm = function () {
        return this.mk;
    };
    CategoryDateTimeXAxis.prototype.hd = function (a) {
        _super.prototype.hd.call(this, a);
        var b = this.bh != null ? this.bh.os : Rect.empty;
        var c = !b.isEmpty ? this.ja : Rect.empty;
        var d = this.i5();
        var e = this.i4();
        var f = new ScalerParams(0, b, c, this.ca, d);
        if (this.k6 == null && !this.lc() && !this.ld()) {
            return;
        }
        if (!b.isEmpty && !c.isEmpty && (this.md != 1 || this.k6 != null)) {
            var g = c.bottom;
            var h = g - c.top;
            if (this.ai != null) {
                var i = typeCast(NumericYAxis.$, this.ai);
                if (i != null) {
                    var j = this.hh(g, h, b, c, d, c.top, c.bottom);
                    g = j.p0;
                    h = j.p1;
                }
            }
            if (isNaN_(g)) {
                g = 0;
            }
            this.gw(this.a4.ay(), g, c, this.a4.e(), true);
            this.av.a9 = h;
            var k = this.a4.a1();
            var l = this.a4.f();
            var m = this.a4.az();
            var n = this.a4.a0();
            var o = this.a4.g();
            if (this.md == 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.lf == null ? s : this.lf._inner[s];
                    var u = this.dz(this.k6.item(t).getTime(), f);
                    if (u == r) {
                        continue;
                    }
                    r = u;
                    if (this.categoryMode == 2) {
                        u += this.ca ? -this.getGroupCenter(s, b, c, d) : this.getGroupCenter(s, b, c, d);
                    }
                    if (u < e.left || u > e.right) {
                        continue;
                    }
                    this.hm(m, u, c, l, false);
                    this.jv.add(u);
                    if (this.jo != null && s < this.jo.count) {
                        var v = this.jo.item(t);
                        var w = _super.prototype.e9.call(this, v);
                        if (!isNaN_(u) && !isInfinity(u) && w != null) {
                            if ((typeof w === 'string') && Base.equalsStatic(w, "")) {
                            }
                            else {
                                this.cx.add1(w);
                                this.cy.add(new LabelPosition(u));
                            }
                        }
                    }
                }
            }
            else {
                var x = this.d2(e.left, f);
                var y = this.d2(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.ec());
                var ac = this.la ? this.mh() : ab.g;
                this.mv(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.ca ? -af : af;
                }
                var ag = truncate(Math.ceil(e.right));
                var ah = truncate(Math.floor(e.left));
                var ai = this.dz(this.actualMinimumValue.getTime() + ad * ac, f) + af;
                for (var aj = ad; aj <= ae; aj++) {
                    var ak = this.dz(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.hn(k, ai, ak, c);
                            }
                            this.hm(m, ai, c, l, false);
                            this.jv.add(ai);
                            if (this.cl) {
                                var am = this.mm();
                                if (am > 0 && am < ac) {
                                    if (ac / am < 20) {
                                        var an = ai;
                                        var ao = Math.abs(this.dz(this.actualMinimumValue.getTime() + am, f) - this.dz(this.actualMinimumValue.getTime(), f));
                                        while (an + ao < ak) {
                                            if (Math.abs(an + ao - ak) < 0.0001) {
                                                break;
                                            }
                                            an += ao;
                                            if (an > 0) {
                                                this.hm(n, an, c, o, false);
                                            }
                                        }
                                        this.mw(am);
                                    }
                                }
                                else {
                                    for (var ap = 1; ap < ab.i; ++ap) {
                                        var aq = this.dz(this.actualMinimumValue.getTime() + aj * ac + (ap * ac) / ab.i, f) + af;
                                        this.hm(n, aq, c, o, false);
                                    }
                                    if (ab.i > 0) {
                                        this.mw(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.e9(as);
                            if (at != null) {
                                this.cx.add1(at);
                                this.cy.add(new LabelPosition(ai));
                            }
                        }
                    }
                    ai = ak;
                }
            }
            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.av.a2 = this.cx;
            this.av.a3 = this.cy;
            this.kv();
        }
    };
    CategoryDateTimeXAxis.prototype.mh = function () {
        return this.mk;
    };
    CategoryDateTimeXAxis.prototype.mm = function () {
        return this.mo;
    };
    CategoryDateTimeXAxis.prototype.mv = function (a) {
        this.mk = a;
    };
    CategoryDateTimeXAxis.prototype.mw = function (a) {
        this.ml = a;
    };
    CategoryDateTimeXAxis.prototype.mf = function () {
        return this.mn != 0;
    };
    CategoryDateTimeXAxis.prototype.me = function () {
        return this.mk == 0;
    };
    CategoryDateTimeXAxis.prototype.mg = function (a) {
        return this.k6 == null ? dateMinValue() : this.k6.item(a);
    };
    CategoryDateTimeXAxis.prototype.mu = function (a, b) {
        if (a > b || this.jo == null || this.jo.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.bh.o8 = new Rect(0, c, this.bh.o8.y, d - c, this.bh.o8.height);
    };
    CategoryDateTimeXAxis.prototype.g0 = function (a, b, c, d) {
        _super.prototype.g0.call(this, a, b, c, d);
        switch (b) {
            case CategoryDateTimeXAxis.$$p[0]:
                this.ci = true;
                this.av.ak = this.md == 1;
                this.hc(false);
                break;
            case CategoryDateTimeXAxis.$$p[1]:
                this.ci = true;
                this.hc(false);
                break;
        }
    };
    CategoryDateTimeXAxis.prototype.l2 = function () {
        _super.prototype.l2.call(this);
        if (this.mf()) {
            this.mk = this.mn;
            var a = this.bh != null ? this.bh.os : Rect.empty;
            var b = !a.isEmpty ? this.ja : Rect.empty;
            var c = Math.abs(this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
            this.la = this.me() || (this.md == 1) || (1 * c / this.mh() > (b.width / a.width)) ? false : true;
        }
        else {
            this.la = false;
        }
    };
    CategoryDateTimeXAxis.prototype.l0 = function (a, b) {
        var c = b.getTime() - a.getTime();
        var timeOffset_ = truncate(Math.round(intDivide(c, this.j8) / 2));
        return timeOffset_ == 0 ? timeSpanFromMilliseconds(1) : timeSpanFromMilliseconds(timeOffset_);
    };
    CategoryDateTimeXAxis.prototype.get_b5 = function () {
        return true;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.ch;
        },
        enumerable: true,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.j$c = function (a, b) {
        return this.d2.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$b = function (a, b) {
        return this.dz.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gs.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.gt.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.gu.apply(this, arguments);
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "j$a", {
        get: function () {
            return this.ca;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "i$a", {
        get: function () {
            return this.b7;
        },
        enumerable: true,
        configurable: true
    });
    CategoryDateTimeXAxis.$t = markType(CategoryDateTimeXAxis, 'CategoryDateTimeXAxis', TimeAxisBase.$);
    CategoryDateTimeXAxis.mz = DependencyProperty.i("MinorInterval", Number_$type, CategoryDateTimeXAxis.$, new PropertyMetadata(2, 0, function (a, b) {
        (typeCast(CategoryDateTimeXAxis.$, a)).g6("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryDateTimeXAxis.$, a)).hc(false);
    }));
    CategoryDateTimeXAxis.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryDateTimeXAxis, 'g6', ['DisplayType:md:mx', [TimeAxisDisplayType_$type, enumGetBox(TimeAxisDisplayType_$type, 0)], 'Interval:mn:my', [1, 0]]);
    return CategoryDateTimeXAxis;
}(TimeAxisBase));
export { CategoryDateTimeXAxis };
/**
 * @hidden
 */
var CategoryDateTimeXAxisView = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(CategoryDateTimeXAxisView, _super);
    function CategoryDateTimeXAxisView(a) {
        var _this = _super.call(this, a) || this;
        _this.bg = null;
        _this.bg = a;
        return _this;
    }
    CategoryDateTimeXAxisView.prototype.o = function (a) {
        var b = this.n(dateFromTicks(truncate(a)));
        return b;
    };
    CategoryDateTimeXAxisView.$t = markType(CategoryDateTimeXAxisView, 'CategoryDateTimeXAxisView', CategoryAxisBaseView.$);
    return CategoryDateTimeXAxisView;
}(CategoryAxisBaseView));
export { CategoryDateTimeXAxisView };
//# sourceMappingURL=CategoryDateTimeXAxis_combined.js.map
