/*
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-angular-core";
import { TimeAxisDisplayType_$type } from "./TimeAxisDisplayType";
import { Base, typeCast, enumGetBox, Number_$type, typeGetValue, 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.rm = 0;
        _this.rn = 0;
        _this.ab = CategoryDateTimeXAxis.$;
        _this.actualMinimumValue = (new Date());
        _this.actualMaximumValue = (new Date());
        return _this;
    }
    CategoryDateTimeXAxis.prototype.ak = function () {
        return new CategoryDateTimeXAxis();
    };
    CategoryDateTimeXAxis.prototype.jr = function (a) {
        _super.prototype.jr.call(this, a);
        this.ju(a, "ActualInterval");
        this.ju(a, "ActualMinorInterval");
        this.ju(a, "DisplayType");
        this.ju(a, "UnevenlySpacedLabels");
    };
    CategoryDateTimeXAxis.prototype.ju = function (a, b) {
        _super.prototype.ju.call(this, a, b);
        var c = typeCast(CategoryDateTimeXAxis.$, a);
        if (c == null) {
            return;
        }
        if (b == "ActualInterval") {
            c.ro = this.ro;
        }
        if (b == "ActualMinorInterval") {
            c.rs = this.rp;
        }
        if (b == "DisplayType") {
            c.rf = this.rf;
        }
        if (b == "UnevenlySpacedLabels") {
            c.ri = this.ri;
        }
    };
    CategoryDateTimeXAxis.prototype.get_db = function () {
        return this.rf == 0;
    };
    CategoryDateTimeXAxis.prototype.bm = function () {
        return new CategoryDateTimeXAxisView(this);
    };
    CategoryDateTimeXAxis.prototype.kb = function (a) {
        _super.prototype.kb.call(this, a);
        this.re = a;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "ro", {
        get: function () {
            return this.rm;
        },
        set: function (a) {
            if (this.ro != a) {
                var b = this.rm;
                this.rm = a;
                this.kx("ActualInterval", b, this.ro);
            }
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.f5 = function () {
        return this.ro;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "rs", {
        get: function () {
            return typeGetValue(this.c(CategoryDateTimeXAxis.r4));
        },
        set: function (a) {
            this.h(CategoryDateTimeXAxis.r4, a);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "rp", {
        get: function () {
            return this.rn;
        },
        set: function (a) {
            if (this.rp != a) {
                var b = this.rn;
                this.rn = a;
                this.kx("ActualMinorInterval", b, this.rp);
            }
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.d9 = function (a, b, c) {
        var d = _super.prototype.d9.call(this, a, b, c);
        if (!d) {
            return false;
        }
        return +(this.actualMinimumValue) != +(this.actualMaximumValue);
    };
    CategoryDateTimeXAxis.prototype.fe = function () {
        return this.ro;
    };
    CategoryDateTimeXAxis.prototype.k4 = function (a) {
        _super.prototype.k4.call(this, a);
        var b = this.b0 != null ? this.b0.xm : Rect.empty;
        var c = !b.isEmpty ? this.n1 : Rect.empty;
        var d = this.nw();
        var e = this.nv();
        var f = new ScalerParams(0, b, c, this.df, d);
        if ((this.p8 == null || this.p8.count < 1) && !this.qe() && !this.qf()) {
            return;
        }
        if (!b.isEmpty && !c.isEmpty && (this.rf != 1 || this.p8 != null)) {
            var g = c.bottom;
            var h = g - c.top;
            if (this.am != null) {
                var i = typeCast(NumericYAxis.$, this.am);
                if (i != null) {
                    var j = this.k9(g, h, b, c, d, c.top, c.bottom);
                    g = j.p0;
                    h = j.p1;
                }
            }
            if (isNaN_(g)) {
                g = 0;
            }
            this.j9(this.bn.a4(), g, c, this.bn.e(), true);
            this.a0.bj = h;
            var k = this.bn.a7();
            var l = this.bn.f();
            var m = this.bn.a5();
            var n = this.bn.a6();
            var o = this.bn.g();
            if (this.rf == 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.qh == null ? s : this.qh._inner[s];
                    var u = this.ft(this.p8.item(t).getTime(), f);
                    if (u == r) {
                        continue;
                    }
                    r = u;
                    if (this.categoryMode == 2) {
                        u += this.df ? -this.getGroupCenter(s, b, c, d) : this.getGroupCenter(s, b, c, d);
                    }
                    if (u < e.left || u > e.right) {
                        continue;
                    }
                    this.lg(m, u, c, l, false);
                    this.oo.add(u);
                    if (this.oh != null && s < this.oh.count) {
                        var v = this.oh.item(t);
                        var w = _super.prototype.hf.call(this, v);
                        if (!isNaN_(u) && !isInfinity(u) && w != null) {
                            if ((typeof w === 'string') && Base.equalsStatic(w, "")) {
                            }
                            else {
                                this.ef.add1(w);
                                this.eg.add(new LabelPosition(u));
                            }
                        }
                    }
                }
            }
            else {
                var x = this.fw(e.left, f);
                var y = this.fw(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.f9(), this.rl());
                var ac = this.qc ? this.rk() : ab.g;
                this.r0(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.df ? -af : af;
                }
                var ag = truncate(Math.ceil(e.right));
                var ah = truncate(Math.floor(e.left));
                var ai = this.ft(this.actualMinimumValue.getTime() + ad * ac, f) + af;
                for (var aj = ad; aj <= ae; aj++) {
                    var ak = this.ft(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.lh(k, ai, ak, c);
                            }
                            this.lg(m, ai, c, l, false);
                            this.oo.add(ai);
                            if (this.dz) {
                                var am = this.rq();
                                if (am > 0 && am < ac) {
                                    if (ac / am < 20) {
                                        var an = ai;
                                        var ao = Math.abs(this.ft(this.actualMinimumValue.getTime() + am, f) - this.ft(this.actualMinimumValue.getTime(), f));
                                        while (an + ao < ak) {
                                            if (Math.abs(an + ao - ak) < 0.0001) {
                                                break;
                                            }
                                            an += ao;
                                            if (an > 0) {
                                                this.lg(n, an, c, o, false);
                                            }
                                        }
                                        this.r1(am);
                                    }
                                }
                                else {
                                    for (var ap = 1; ap < ab.j; ++ap) {
                                        var aq = this.ft(this.actualMinimumValue.getTime() + aj * ac + (ap * ac) / ab.j, f) + af;
                                        this.lg(n, aq, c, o, false);
                                    }
                                    if (ab.j > 0) {
                                        this.r1(truncate((ac / ab.j)));
                                    }
                                }
                            }
                        }
                        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.hf(as);
                            if (at != null) {
                                this.ef.add1(at);
                                this.eg.add(new LabelPosition(ai));
                            }
                        }
                    }
                    ai = ak;
                }
            }
            if ((this.a3 == null || this.a3.visibility == 0) && this.am != null) {
                if (this.a3 != null && (this.a3.location == 4 || this.a3.location == 5)) {
                    this.b0.o1();
                }
            }
            this.a0.bc = this.ef;
            this.a0.bd = this.eg;
            this.pv();
        }
    };
    CategoryDateTimeXAxis.prototype.rl = function () {
        return -1;
    };
    CategoryDateTimeXAxis.prototype.rk = function () {
        return this.ro;
    };
    CategoryDateTimeXAxis.prototype.rq = function () {
        return this.rs;
    };
    CategoryDateTimeXAxis.prototype.r0 = function (a) {
        this.ro = a;
    };
    CategoryDateTimeXAxis.prototype.r1 = function (a) {
        this.rp = a;
    };
    CategoryDateTimeXAxis.prototype.rh = function () {
        return this.rr != 0;
    };
    CategoryDateTimeXAxis.prototype.rg = function () {
        return this.ro == 0;
    };
    CategoryDateTimeXAxis.prototype.rj = function (a) {
        return this.p8 == null ? dateMinValue() : this.p8.item(a);
    };
    CategoryDateTimeXAxis.prototype.rz = function (a, b) {
        if (a > b || this.oh == null || this.oh.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.b0.x5 = new Rect(0, c, this.b0.x5.y, d - c, this.b0.x5.height);
    };
    CategoryDateTimeXAxis.prototype.kf = function (a, b, c, d) {
        _super.prototype.kf.call(this, a, b, c, d);
        switch (b) {
            case CategoryDateTimeXAxis.$$p[0]:
                this.dr = true;
                this.a0.al = this.rf == 1 || this.ri;
                this.k3(false);
                break;
            case CategoryDateTimeXAxis.$$p[1]:
                this.dr = true;
                this.k3(false);
                break;
            case CategoryDateTimeXAxis.$$p[2]:
                this.a0.al = this.rf == 1 || this.ri;
                break;
        }
    };
    CategoryDateTimeXAxis.prototype.q4 = function () {
        _super.prototype.q4.call(this);
        if (this.rh()) {
            this.ro = this.rr;
            var a = this.b0 != null ? this.b0.xm : Rect.empty;
            var b = !a.isEmpty ? this.n1 : Rect.empty;
            var c = Math.abs(this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
            this.qc = this.rg() || (this.rf == 1) || (1 * c / this.rk() > (b.width / a.width)) ? false : true;
        }
        else {
            this.qc = false;
        }
    };
    CategoryDateTimeXAxis.prototype.q2 = function (a, b) {
        var c = b.getTime() - a.getTime();
        var timeOffset_ = truncate(Math.round(intDivide(c, this.o5) / 2));
        return timeOffset_ == 0 ? timeSpanFromMilliseconds(1) : timeSpanFromMilliseconds(timeOffset_);
    };
    CategoryDateTimeXAxis.prototype.get_c9 = function () {
        return true;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.dq;
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.j$d = function (a, b) {
        return this.fw.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$c = function (a, b) {
        return this.ft.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$e = function (a, b, c, d, e) {
        this.j5.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.j6.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$g = function (a, b, c, d) {
        this.j7.apply(this, arguments);
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "j$b", {
        get: function () {
            return this.df;
        },
        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.dc;
        },
        enumerable: false,
        configurable: true
    });
    CategoryDateTimeXAxis.$t = markType(CategoryDateTimeXAxis, 'CategoryDateTimeXAxis', TimeAxisBase.$);
    CategoryDateTimeXAxis.r4 = DependencyProperty.i("MinorInterval", Number_$type, CategoryDateTimeXAxis.$, new PropertyMetadata(2, 0, function (a, b) {
        (typeCast(CategoryDateTimeXAxis.$, a)).kx("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryDateTimeXAxis.$, a)).k3(false);
    }));
    CategoryDateTimeXAxis.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryDateTimeXAxis, 'kx', ['DisplayType:rf:r2', [TimeAxisDisplayType_$type, enumGetBox(TimeAxisDisplayType_$type, 0)], 'Interval:rr:r3', [1, 0], 'UnevenlySpacedLabels:ri:r5', [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.gt = AxisDefaults.categoryAxis_TickLength;
    };
    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 };
