/*
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 { TimeAxisDisplayType_$type } from "./TimeAxisDisplayType";
import { DependencyProperty } from "igniteui-angular-core";
import { Base, enumGetBox, Number_$type, typeGetValue, typeCast, markType, markDep } from "igniteui-angular-core";
import { Rect } from "igniteui-angular-core";
import { ScalerParams } from "./ScalerParams";
import { NumericYAxis } from "./NumericYAxis";
import { LinearNumericSnapper } from "./LinearNumericSnapper";
import { LabelPosition } from "./LabelPosition";
import { PropertyMetadata } from "igniteui-angular-core";
import { truncate, intDivide, isNaN_, isInfinity } from "igniteui-angular-core";
import { dateMinValue, dateFromTicks } from "igniteui-angular-core";
import { timeSpanFromMilliseconds } from "igniteui-angular-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.ns = 0;
        _this.nt = 0;
        _this.ab = CategoryDateTimeXAxis.$;
        _this.actualMinimumValue = (new Date());
        _this.actualMaximumValue = (new Date());
        return _this;
    }
    CategoryDateTimeXAxis.prototype.get_cc = function () {
        return this.nn == 0;
    };
    CategoryDateTimeXAxis.prototype.a3 = function () {
        return new CategoryDateTimeXAxisView(this);
    };
    CategoryDateTimeXAxis.prototype.hr = function (a) {
        _super.prototype.hr.call(this, a);
        this.nm = a;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "nu", {
        get: function () {
            return this.ns;
        },
        set: function (a) {
            if (this.nu != a) {
                var b = this.ns;
                this.ns = a;
                this.h1("ActualInterval", b, this.nu);
            }
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.eu = function () {
        return this.nu;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "ny", {
        get: function () {
            return typeGetValue(this.c(CategoryDateTimeXAxis.n9));
        },
        set: function (a) {
            this.h(CategoryDateTimeXAxis.n9, a);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "nv", {
        get: function () {
            return this.nt;
        },
        set: function (a) {
            if (this.nv != a) {
                var b = this.nt;
                this.nt = a;
                this.h1("ActualMinorInterval", b, this.nv);
            }
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.c7 = function (a, b, c) {
        var d = _super.prototype.c7.call(this, a, b, c);
        if (!d) {
            return false;
        }
        return +(this.actualMinimumValue) != +(this.actualMaximumValue);
    };
    CategoryDateTimeXAxis.prototype.d3 = function () {
        return this.nu;
    };
    CategoryDateTimeXAxis.prototype.h8 = function (a) {
        _super.prototype.h8.call(this, a);
        var b = this.bh != null ? this.bh.ta : Rect.empty;
        var c = !b.isEmpty ? this.kc : Rect.empty;
        var d = this.j7();
        var e = this.j6();
        var f = new ScalerParams(0, b, c, this.cg, d);
        if ((this.mg == null || this.mg.count < 1) && !this.mm() && !this.mn()) {
            return;
        }
        if (!b.isEmpty && !c.isEmpty && (this.nn != 1 || this.mg != 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.id(g, h, b, c, d, c.top, c.bottom);
                    g = j.p0;
                    h = j.p1;
                }
            }
            if (isNaN_(g)) {
                g = 0;
            }
            this.hp(this.a4.a1(), g, c, this.a4.e(), true);
            this.av.bg = h;
            var k = this.a4.a4();
            var l = this.a4.f();
            var m = this.a4.a2();
            var n = this.a4.a3();
            var o = this.a4.g();
            if (this.nn == 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.mp == null ? s : this.mp._inner[s];
                    var u = this.ei(this.mg.item(t).getTime(), f);
                    if (u == r) {
                        continue;
                    }
                    r = u;
                    if (this.categoryMode == 2) {
                        u += this.cg ? -this.getGroupCenter(s, b, c, d) : this.getGroupCenter(s, b, c, d);
                    }
                    if (u < e.left || u > e.right) {
                        continue;
                    }
                    this.il(m, u, c, l, false);
                    this.kx.add(u);
                    if (this.kq != null && s < this.kq.count) {
                        var v = this.kq.item(t);
                        var w = _super.prototype.fy.call(this, v);
                        if (!isNaN_(u) && !isInfinity(u) && w != null) {
                            if ((typeof w === 'string') && Base.equalsStatic(w, "")) {
                            }
                            else {
                                this.db.add1(w);
                                this.dc.add(new LabelPosition(u));
                            }
                        }
                    }
                }
            }
            else {
                var x = this.el(e.left, f);
                var y = this.el(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.ex());
                var ac = this.mk ? this.nr() : ab.g;
                this.n5(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.cg ? -af : af;
                }
                var ag = truncate(Math.ceil(e.right));
                var ah = truncate(Math.floor(e.left));
                var ai = this.ei(this.actualMinimumValue.getTime() + ad * ac, f) + af;
                for (var aj = ad; aj <= ae; aj++) {
                    var ak = this.ei(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.im(k, ai, ak, c);
                            }
                            this.il(m, ai, c, l, false);
                            this.kx.add(ai);
                            if (this.cx) {
                                var am = this.nw();
                                if (am > 0 && am < ac) {
                                    if (ac / am < 20) {
                                        var an = ai;
                                        var ao = Math.abs(this.ei(this.actualMinimumValue.getTime() + am, f) - this.ei(this.actualMinimumValue.getTime(), f));
                                        while (an + ao < ak) {
                                            if (Math.abs(an + ao - ak) < 0.0001) {
                                                break;
                                            }
                                            an += ao;
                                            if (an > 0) {
                                                this.il(n, an, c, o, false);
                                            }
                                        }
                                        this.n6(am);
                                    }
                                }
                                else {
                                    for (var ap = 1; ap < ab.i; ++ap) {
                                        var aq = this.ei(this.actualMinimumValue.getTime() + aj * ac + (ap * ac) / ab.i, f) + af;
                                        this.il(n, aq, c, o, false);
                                    }
                                    if (ab.i > 0) {
                                        this.n6(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.fy(as);
                            if (at != null) {
                                this.db.add1(at);
                                this.dc.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.l7();
                }
            }
            this.av.a9 = this.db;
            this.av.ba = this.dc;
            this.l3();
        }
    };
    CategoryDateTimeXAxis.prototype.nr = function () {
        return this.nu;
    };
    CategoryDateTimeXAxis.prototype.nw = function () {
        return this.ny;
    };
    CategoryDateTimeXAxis.prototype.n5 = function (a) {
        this.nu = a;
    };
    CategoryDateTimeXAxis.prototype.n6 = function (a) {
        this.nv = a;
    };
    CategoryDateTimeXAxis.prototype.np = function () {
        return this.nx != 0;
    };
    CategoryDateTimeXAxis.prototype.no = function () {
        return this.nu == 0;
    };
    CategoryDateTimeXAxis.prototype.nq = function (a) {
        return this.mg == null ? dateMinValue() : this.mg.item(a);
    };
    CategoryDateTimeXAxis.prototype.n4 = function (a, b) {
        if (a > b || this.kq == null || this.kq.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.tq = new Rect(0, c, this.bh.tq.y, d - c, this.bh.tq.height);
    };
    CategoryDateTimeXAxis.prototype.hv = function (a, b, c, d) {
        _super.prototype.hv.call(this, a, b, c, d);
        switch (b) {
            case CategoryDateTimeXAxis.$$p[0]:
                this.cp = true;
                this.av.al = this.nn == 1;
                this.h7(false);
                break;
            case CategoryDateTimeXAxis.$$p[1]:
                this.cp = true;
                this.h7(false);
                break;
        }
    };
    CategoryDateTimeXAxis.prototype.nc = function () {
        _super.prototype.nc.call(this);
        if (this.np()) {
            this.nu = this.nx;
            var a = this.bh != null ? this.bh.ta : Rect.empty;
            var b = !a.isEmpty ? this.kc : Rect.empty;
            var c = Math.abs(this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
            this.mk = this.no() || (this.nn == 1) || (1 * c / this.nr() > (b.width / a.width)) ? false : true;
        }
        else {
            this.mk = false;
        }
    };
    CategoryDateTimeXAxis.prototype.na = function (a, b) {
        var c = b.getTime() - a.getTime();
        var timeOffset_ = truncate(Math.round(intDivide(c, this.le) / 2));
        return timeOffset_ == 0 ? timeSpanFromMilliseconds(1) : timeSpanFromMilliseconds(timeOffset_);
    };
    CategoryDateTimeXAxis.prototype.get_cb = function () {
        return true;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.co;
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.j$c = function (a, b) {
        return this.el.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$b = function (a, b) {
        return this.ei.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.hl.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.hm.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.hn.apply(this, arguments);
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "j$a", {
        get: function () {
            return this.cg;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "i$a", {
        get: function () {
            return this.cd;
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.$t = markType(CategoryDateTimeXAxis, 'CategoryDateTimeXAxis', TimeAxisBase.$);
    CategoryDateTimeXAxis.n9 = DependencyProperty.i("MinorInterval", Number_$type, CategoryDateTimeXAxis.$, new PropertyMetadata(2, 0, function (a, b) {
        (typeCast(CategoryDateTimeXAxis.$, a)).h1("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryDateTimeXAxis.$, a)).h7(false);
    }));
    CategoryDateTimeXAxis.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryDateTimeXAxis, 'h1', ['DisplayType:nn:n7', [TimeAxisDisplayType_$type, enumGetBox(TimeAxisDisplayType_$type, 0)], 'Interval:nx:n8', [1, 0]]);
    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.bj = null;
        _this.bj = a;
        return _this;
    }
    CategoryDateTimeXAxisView.prototype.aj = function () {
        _super.prototype.aj.call(this);
        this.a.fg = AxisDefaults.f;
    };
    CategoryDateTimeXAxisView.prototype.r = function (a) {
        var b = this.p(dateFromTicks(truncate(a)));
        return b;
    };
    CategoryDateTimeXAxisView.$t = markType(CategoryDateTimeXAxisView, 'CategoryDateTimeXAxisView', CategoryAxisBaseView.$);
    return CategoryDateTimeXAxisView;
}(CategoryAxisBaseView));
export { CategoryDateTimeXAxisView };
