/*
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-angular-core/ES5/DependencyProperty";
import { Type, Base, enumGetBox, Number_$type, typeGetValue, typeCast, markType } from "igniteui-angular-core/ES5/type";
import { Rect } from "igniteui-angular-core/ES5/Rect";
import { ScalerParams } from "./ScalerParams";
import { NumericYAxis } from "./NumericYAxis";
import { LinearNumericSnapper } from "./LinearNumericSnapper";
import { LabelPosition } from "./LabelPosition";
import { PropertyMetadata } from "igniteui-angular-core/ES5/PropertyMetadata";
import { truncate, intDivide, isNaN_, isInfinity } from "igniteui-angular-core/ES5/number";
import { dateMinValue, dateFromTicks } from "igniteui-angular-core/ES5/date";
import { timeSpanFromMilliseconds } from "igniteui-angular-core/ES5/timespan";
import { CategoryAxisBaseView } from "./CategoryAxisBaseView";
/**
 * @hidden
 */
var CategoryDateTimeXAxis = /** @class */ (function (_super) {
    tslib_1.__extends(CategoryDateTimeXAxis, _super);
    function CategoryDateTimeXAxis() {
        var _this = _super.call(this) || this;
        _this.l8 = 0;
        _this.l9 = 0;
        _this.ab = CategoryDateTimeXAxis.$;
        _this.actualMinimumValue = (new Date());
        _this.actualMaximumValue = (new Date());
        return _this;
    }
    CategoryDateTimeXAxis.prototype.get_b4 = function () {
        return this.l3 == 0;
    };
    CategoryDateTimeXAxis.prototype.a1 = function () {
        return new CategoryDateTimeXAxisView(this);
    };
    CategoryDateTimeXAxis.prototype.gr = function (a) {
        _super.prototype.gr.call(this, a);
        this.l2 = a;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "ma", {
        get: function () {
            return this.l8;
        },
        set: function (a) {
            if (this.ma != a) {
                var b = this.l8;
                this.l8 = a;
                this.gz("ActualInterval", b, this.ma);
            }
        },
        enumerable: true,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.d6 = function () {
        return this.ma;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "me", {
        get: function () {
            return typeGetValue(this.c(CategoryDateTimeXAxis.mp));
        },
        set: function (a) {
            this.h(CategoryDateTimeXAxis.mp, a);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "mb", {
        get: function () {
            return this.l9;
        },
        set: function (a) {
            if (this.mb != a) {
                var b = this.l9;
                this.l9 = a;
                this.gz("ActualMinorInterval", b, this.mb);
            }
        },
        enumerable: true,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.cq = function (a, b, c) {
        var d = _super.prototype.cq.call(this, a, b, c);
        if (!d) {
            return false;
        }
        return +(this.actualMinimumValue) != +(this.actualMaximumValue);
    };
    CategoryDateTimeXAxis.prototype.di = function () {
        return this.ma;
    };
    CategoryDateTimeXAxis.prototype.g6 = function (a) {
        _super.prototype.g6.call(this, a);
        var b = this.bf != null ? this.bf.mq : Rect.empty;
        var c = !b.isEmpty ? this.i0 : Rect.empty;
        var d = this.iv();
        var e = this.iu();
        var f = new ScalerParams(0, b, c, this.b8, d);
        if (this.kw == null && !this.k2() && !this.k3()) {
            return;
        }
        if (!b.isEmpty && !c.isEmpty && (this.l3 != 1 || this.kw != null)) {
            var g = c.bottom;
            var h = g - c.top;
            if (this.ag != null) {
                var i = typeCast(NumericYAxis.$, this.ag);
                if (i != null) {
                    var j = this.g9(g, h, b, c, d, c.top, c.bottom);
                    g = j.p0;
                    h = j.p1;
                }
            }
            if (isNaN_(g)) {
                g = 0;
            }
            this.gp(this.a2.ay(), g, c, this.a2.e(), true);
            this.at.a8 = h;
            var k = this.a2.a1();
            var l = this.a2.f();
            var m = this.a2.az();
            var n = this.a2.a0();
            var o = this.a2.g();
            if (this.l3 == 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.k5 == null ? s : this.k5._inner[s];
                    var u = this.dv(this.kw.item(t).getTime(), f);
                    if (u == r) {
                        continue;
                    }
                    r = u;
                    if (this.categoryMode == 2) {
                        u += this.b8 ? -this.getGroupCenter(s, b, c, d) : this.getGroupCenter(s, b, c, d);
                    }
                    if (u < e.left || u > e.right) {
                        continue;
                    }
                    this.he(m, u, c, l, false);
                    this.jl.add(u);
                    if (this.je != null && s < this.je.count) {
                        var v = this.je.item(t);
                        var w = _super.prototype.e5.call(this, v);
                        if (!isNaN_(u) && !isInfinity(u) && w != null) {
                            if ((typeof w === 'string') && Base.equalsStatic(w, "")) {
                            }
                            else {
                                this.cu.add1(w);
                                this.cv.add(new LabelPosition(u));
                            }
                        }
                    }
                }
            }
            else {
                var x = this.dy(e.left, f);
                var y = this.dy(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.d8());
                var ac = this.k0 ? this.l7() : ab.g;
                this.ml(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.b8 ? -af : af;
                }
                var ag = truncate(Math.ceil(e.right));
                var ah = truncate(Math.floor(e.left));
                var ai = this.dv(this.actualMinimumValue.getTime() + ad * ac, f) + af;
                for (var aj = ad; aj <= ae; aj++) {
                    var ak = this.dv(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.hf(k, ai, ak, c);
                            }
                            this.he(m, ai, c, l, false);
                            this.jl.add(ai);
                            if (this.ci) {
                                var am = this.mc();
                                if (am > 0 && am < ac) {
                                    if (ac / am < 20) {
                                        var an = ai;
                                        var ao = Math.abs(this.dv(this.actualMinimumValue.getTime() + am, f) - this.dv(this.actualMinimumValue.getTime(), f));
                                        while (an + ao < ak) {
                                            if (Math.abs(an + ao - ak) < 0.0001) {
                                                break;
                                            }
                                            an += ao;
                                            if (an > 0) {
                                                this.he(n, an, c, o, false);
                                            }
                                        }
                                        this.mm(am);
                                    }
                                }
                                else {
                                    for (var ap = 1; ap < ab.i; ++ap) {
                                        var aq = this.dv(this.actualMinimumValue.getTime() + aj * ac + (ap * ac) / ab.i, f) + af;
                                        this.he(n, aq, c, o, false);
                                    }
                                    if (ab.i > 0) {
                                        this.mm(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.e5(as);
                            if (at != null) {
                                this.cu.add1(at);
                                this.cv.add(new LabelPosition(ai));
                            }
                        }
                    }
                    ai = ak;
                }
            }
            if ((this.aw == null || this.aw.visibility == 0) && this.ag != null) {
                if (this.aw != null && (this.aw.location == 4 || this.aw.location == 5)) {
                    this.bf.ht();
                }
            }
            this.at.a1 = this.cu;
            this.at.a2 = this.cv;
            this.kl();
        }
    };
    CategoryDateTimeXAxis.prototype.l7 = function () {
        return this.ma;
    };
    CategoryDateTimeXAxis.prototype.mc = function () {
        return this.me;
    };
    CategoryDateTimeXAxis.prototype.ml = function (a) {
        this.ma = a;
    };
    CategoryDateTimeXAxis.prototype.mm = function (a) {
        this.mb = a;
    };
    CategoryDateTimeXAxis.prototype.l5 = function () {
        return this.md != 0;
    };
    CategoryDateTimeXAxis.prototype.l4 = function () {
        return this.ma == 0;
    };
    CategoryDateTimeXAxis.prototype.l6 = function (a) {
        return this.kw == null ? dateMinValue() : this.kw.item(a);
    };
    CategoryDateTimeXAxis.prototype.mk = function (a, b) {
        if (a > b || this.je == null || this.je.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.bf.m4 = new Rect(0, c, this.bf.m4.y, d - c, this.bf.m4.height);
    };
    CategoryDateTimeXAxis.prototype.gt = function (a, b, c, d) {
        _super.prototype.gt.call(this, a, b, c, d);
        switch (b) {
            case CategoryDateTimeXAxis.$$p[0]:
                this.cf = true;
                this.at.ak = this.l3 == 1;
                this.g5(false);
                break;
            case CategoryDateTimeXAxis.$$p[1]:
                this.cf = true;
                this.g5(false);
                break;
        }
    };
    CategoryDateTimeXAxis.prototype.ls = function () {
        _super.prototype.ls.call(this);
        if (this.l5()) {
            this.ma = this.md;
            var a = this.bf != null ? this.bf.mq : Rect.empty;
            var b = !a.isEmpty ? this.i0 : Rect.empty;
            var c = Math.abs(this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime());
            this.k0 = this.l4() || (this.l3 == 1) || (1 * c / this.l7() > (b.width / a.width)) ? false : true;
        }
        else {
            this.k0 = false;
        }
    };
    CategoryDateTimeXAxis.prototype.lq = function (a, b) {
        var c = b.getTime() - a.getTime();
        var timeOffset_ = truncate(Math.round(intDivide(c, this.jx) / 2));
        return timeOffset_ == 0 ? timeSpanFromMilliseconds(1) : timeSpanFromMilliseconds(timeOffset_);
    };
    CategoryDateTimeXAxis.prototype.get_b3 = function () {
        return true;
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.ce;
        },
        enumerable: true,
        configurable: true
    });
    CategoryDateTimeXAxis.prototype.j$c = function (a, b) {
        return this.dy.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$b = function (a, b) {
        return this.dv.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gl.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.gm.apply(this, arguments);
    };
    CategoryDateTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.gn.apply(this, arguments);
    };
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "j$a", {
        get: function () {
            return this.b8;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(CategoryDateTimeXAxis.prototype, "i$a", {
        get: function () {
            return this.b5;
        },
        enumerable: true,
        configurable: true
    });
    CategoryDateTimeXAxis.$t = markType(CategoryDateTimeXAxis, 'CategoryDateTimeXAxis', TimeAxisBase.$);
    CategoryDateTimeXAxis.mp = DependencyProperty.i("MinorInterval", Number_$type, CategoryDateTimeXAxis.$, new PropertyMetadata(2, 0, function (a, b) {
        (typeCast(CategoryDateTimeXAxis.$, a)).gz("MinorInterval", b.oldValue, b.newValue);
        (typeCast(CategoryDateTimeXAxis.$, a)).g5(false);
    }));
    return CategoryDateTimeXAxis;
}(TimeAxisBase));
export { CategoryDateTimeXAxis };
Type.dep(DependencyProperty, PropertyMetadata, CategoryDateTimeXAxis, 'gz', ['DisplayType:l3:mn', [TimeAxisDisplayType_$type, enumGetBox(TimeAxisDisplayType_$type, 0)], 'Interval:md:mo', [1, 0]]);
/**
 * @hidden
 */
var CategoryDateTimeXAxisView = /** @class */ (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