/*
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 { ITimeRangeSelectorAxis_$type } from "./ITimeRangeSelectorAxis";
import { List$1 } from "igniteui-react-core";
import { TimeAxisBreak } from "./TimeAxisBreak";
import { TimeAxisBreakCollection } from "./TimeAxisBreakCollection";
import { TimeAxisLabellingMode_$type } from "./TimeAxisLabellingMode";
import { TimeAxisLabelFormatCollection } from "./TimeAxisLabelFormatCollection";
import { OrderedDictionary$2 } from "./OrderedDictionary$2";
import { TimeAxisInterval } from "./TimeAxisInterval";
import { TimeAxisIntervalCollection } from "./TimeAxisIntervalCollection";
import { EventArgs, runOn, delegateCombine, Number_$type, fromEnum, enumGetBox, fromEn, typeCast, Date_$type, markType } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { Rect } from "igniteui-react-core";
import { NumericScaler } from "./NumericScaler";
import { KeyValuePair$2 } from "igniteui-react-core";
import { NumericYAxis } from "./NumericYAxis";
import { LabelPosition } from "./LabelPosition";
import { Extensions } from "igniteui-react-core";
import { SortedListView$1 } from "./SortedListView$1";
import { Dictionary$2 } from "igniteui-react-core";
import { truncate, intDivide, isNaN_ } from "igniteui-react-core";
import { dateFromTicks, dateMaxValue, dateAdd, dateSubtract, dateMinValue, dateGetMonth, dateAddMonths, dateFromValues, dateGetTimeOfDay, dateAddDays, dateAddHours } from "igniteui-react-core";
import { timeSpanTicks, timeSpanInit3, timeSpanInit1, timeSpanFromMilliseconds, timeSpanFromSeconds, timeSpanFromMinutes, timeSpanFromHours, timeSpanFromDays, timeSpanFromTicks, timeSpanTotalMilliseconds } from "igniteui-react-core";
import { dateToStringFormat } from "igniteui-react-core";
/**
 * @hidden
 */
var TimeXAxis = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(TimeXAxis, _super);
    function TimeXAxis() {
        var _this = _super.call(this) || this;
        _this.m1 = 0;
        _this.mf = null;
        _this.mo = 0;
        _this.mm = null;
        _this._omission = 0;
        _this.md = null;
        _this.mk = null;
        _this.m3 = null;
        _this.ng = 0;
        _this.mv = dateMaxValue();
        _this.mu = dateMinValue();
        _this.mh = null;
        _this.ne = 0;
        _this.visibleRangeChanged = null;
        _this.ab = TimeXAxis.$;
        _this.omission = (0);
        _this.m1 = -2147483648;
        _this.mf = new TimeAxisBreakCollection();
        var a = _this.breaks;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.nj));
        _this.mk = new TimeAxisIntervalCollection();
        var b = _this.intervals;
        b.collectionChanged = delegateCombine(b.collectionChanged, runOn(_this, _this.nk));
        _this.mm = new TimeAxisLabelFormatCollection();
        var c = _this.labelFormats;
        c.collectionChanged = delegateCombine(c.collectionChanged, runOn(_this, _this.nl));
        _this.ng = (0);
        return _this;
    }
    TimeXAxis.prototype.get_cd = function () {
        return this.breaks != null && this.breaks.count > 0;
    };
    TimeXAxis.prototype.dz = function (a, b) {
        if (!b.c.isEmpty) {
            var c = this.mz(a, NumericScaler.ac, b.c, Rect.empty);
            c = (c - b.d.left) / b.d.width;
            c = b.d.left + b.d.width * (c - b.e.left) / b.e.width;
            return c;
        }
        return this.mz(a, b.e, b.d, b.c);
    };
    TimeXAxis.prototype.mz = function (a, b, c, d) {
        var e = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        var f = this.m1 != -2147483648 ? this.m1 : 0;
        var g = this.md != null ? this.md.count : 0;
        while (f < g) {
            var h = this.md.item1(f);
            if (h.d.getTime() <= a && h.c.getTime() >= a) {
                return NaN;
            }
            if (h.c.getTime() <= a) {
                e = new KeyValuePair$2(TimeAxisBreak.$, Number_$type, 1, h, this.md.item(h));
                f++;
            }
            else {
                break;
            }
        }
        if (f > 0) {
            f -= 1;
        }
        if (this.m1 != -2147483648) {
            this.m1 = f;
        }
        var i;
        var j;
        if (e.key != null) {
            i = e.value;
            j = e.key.c;
        }
        else {
            i = 0;
            j = this.actualMinimumValue;
        }
        var fromPrecedingBreak_ = +(dateFromTicks(truncate(a))) - +j;
        var k = (fromPrecedingBreak_ / ((this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime()) - this.omission));
        var l = i + k;
        l -= b.left;
        l /= b.width;
        var m = c.left;
        var n = c.right;
        var o = c.width;
        if (this.categoryMode != 0) {
            var p = this.getCategorySize(b, c, d);
            m += p / 2;
            n -= p / 2;
            o -= p;
        }
        if (this.ca) {
            return n - o * l;
        }
        return m + o * l;
    };
    TimeXAxis.prototype.gt = function (a, b, c, d) {
        this.m1 = 0;
        for (var e = b; e < c; e++) {
            a.item(e, this.dz(a.item(e), d));
        }
        this.m1 = -2147483648;
    };
    TimeXAxis.prototype.startCursor = function () {
        this.m1 = 0;
    };
    TimeXAxis.prototype.resetCursor = function () {
        this.m1 = -2147483648;
    };
    TimeXAxis.prototype.d2 = function (a, b) {
        if (!b.c.isEmpty) {
            var c = b.e.left + b.e.width * (a - b.d.left) / b.d.width;
            c = (c * b.d.width) + b.d.left;
            c = this.getUnscaledValue3(c, NumericScaler.ac, b.c, this.categoryMode);
            return c;
        }
        return this.m0(a, b.e, b.d, b.c);
    };
    TimeXAxis.prototype.m0 = function (a, b, c, d) {
        var e_1, _a;
        var e = c.left;
        var f = c.width;
        if (this.categoryMode != 0) {
            var g = this.getCategorySize(b, c, d);
            e += g / 2;
            f -= g;
        }
        var h = b.left + b.width * (a - e) / f;
        if (this.ca) {
            h = 1 - h;
        }
        var i = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        if (this.md != null) {
            try {
                for (var _b = tslib_1.__values(fromEnum(this.md)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var j = _c.value;
                    if (j.value >= h && j.value <= h) {
                        return j.key.d.getTime();
                    }
                    if (j.value < h && j.value > i.value) {
                        i = j;
                    }
                }
            }
            catch (e_1_1) {
                e_1 = { error: e_1_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_1)
                        throw e_1.error;
                }
            }
        }
        var precedingBreakEnd_;
        var k;
        if (i.key != null) {
            k = i.value;
            precedingBreakEnd_ = i.key.c;
        }
        else {
            k = 0;
            precedingBreakEnd_ = this.actualMinimumValue;
        }
        var portionFromPrecedingBreak_ = h - k;
        var actualRange_ = +(this.actualMaximumValue) - +(this.actualMinimumValue) - this.omission;
        return (precedingBreakEnd_.getTime() + portionFromPrecedingBreak_ * actualRange_);
    };
    Object.defineProperty(TimeXAxis.prototype, "breaks", {
        get: function () {
            return this.mf;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TimeXAxis.prototype, "mp", {
        get: function () {
            return this.mo;
        },
        set: function (a) {
            var b = this.mp;
            if (a != b) {
                this.mo = a;
                this.g6("LabellingMode", enumGetBox(TimeAxisLabellingMode_$type, b), enumGetBox(TimeAxisLabellingMode_$type, this.mp));
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TimeXAxis.prototype, "labelFormats", {
        get: function () {
            return this.mm;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.g0 = function (a, b, c, d) {
        _super.prototype.g0.call(this, a, b, c, d);
        switch (b) {
            case "ActualMaximumValue":
                this.ni();
                break;
            case "DateTimeColumn":
                this.ne = this.nc();
                break;
            case "LabellingMode":
                this.hc(false);
                break;
        }
    };
    TimeXAxis.prototype.hp = function (a, b) {
        _super.prototype.hp.call(this, a, b);
        this.nh();
        this.l7();
    };
    TimeXAxis.prototype.ho = function (a, b) {
        _super.prototype.ho.call(this, a, b);
        this.nh();
        this.l7();
    };
    TimeXAxis.prototype.cp = function () {
        var a = _super.prototype.cp.call(this);
        this.nh();
        return a;
    };
    Object.defineProperty(TimeXAxis.prototype, "omission", {
        get: function () {
            return this._omission;
        },
        set: function (a) {
            this._omission = a;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.ni = function () {
        var e_2, _a;
        var a = this.ms(this.breaks);
        var b = (0);
        try {
            for (var _b = tslib_1.__values(fromEnum(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var c = _c.value;
                b += (+(c.c) - +(c.d));
            }
        }
        catch (e_2_1) {
            e_2 = { error: e_2_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_2)
                    throw e_2.error;
            }
        }
        this.omission = b;
    };
    TimeXAxis.prototype.ms = function (a) {
        var e_3, _a;
        var b = new List$1(TimeAxisBreak.$, 0);
        if (a == null || +(this.actualMaximumValue) == +(dateMaxValue())) {
            return b;
        }
        var _loop_1 = function (c) {
            if (c.c >= this_1.actualMinimumValue && c.d <= this_1.actualMaximumValue) {
                b.add(c);
            }
            if (c.i != (0)) {
                var d = +(c.c) - +(c.d);
                var e_4 = dateAdd(+(c.d), +(c.i));
                var _loop_2 = function () {
                    var f = this_1.mw(e_4, d);
                    var g = ((function () {
                        var $ret = new TimeAxisBreak();
                        $ret.d = e_4;
                        $ret.c = f;
                        return $ret;
                    })());
                    if (g.c >= this_1.actualMinimumValue && g.d <= this_1.actualMaximumValue) {
                        b.add(g);
                    }
                    if (dateSubtract(+(dateMaxValue()), +(c.i)) < g.d) {
                        return "break";
                    }
                    e_4 = this_1.mw(g.d, c.i);
                };
                while (e_4 <= this_1.actualMaximumValue) {
                    var state_1 = _loop_2();
                    if (state_1 === "break")
                        break;
                }
            }
        };
        var this_1 = this;
        try {
            for (var _b = tslib_1.__values(fromEn(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var c = _c.value;
                _loop_1(c);
            }
        }
        catch (e_3_1) {
            e_3 = { error: e_3_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_3)
                    throw e_3.error;
            }
        }
        return b;
    };
    TimeXAxis.prototype.mw = function (a, b) {
        var c = dateFromTicks(a.getTime());
        c.setMilliseconds(c.getMilliseconds() + b);
        return c;
    };
    TimeXAxis.prototype.nh = function () {
        var e_5, _a;
        this.md = new OrderedDictionary$2(TimeAxisBreak.$, Number_$type);
        if (+(this.actualMaximumValue) == +(dateMaxValue()) || this.breaks == null || this.breaks.count == 0 || this.bh == null) {
            return;
        }
        var a = new List$1(TimeAxisBreak.$, 1, this.ms(this.breaks));
        a.aa(function (b, c) { return b.d < c.d ? -1 : b.d > c.d ? 1 : 0; });
        var b = this.bh.os;
        var c = new ScalerParams(0, this.bh.os, this.bh.o7, this.ca, this.bh.ow);
        var d = +(this.actualMaximumValue) - +(this.actualMinimumValue) - this.omission;
        var e = 0;
        try {
            for (var _b = tslib_1.__values(fromEnum(a)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var f = _c.value;
                var g = timeSpanTicks((+(f.d) - +(this.actualMinimumValue))) / timeSpanTicks(d);
                var h = timeSpanTicks((+(f.c) - +(this.actualMinimumValue))) / timeSpanTicks(d);
                if (h < 0 || g - e > 1) {
                    continue;
                }
                this.md.addItem(f, g - e);
                e += (h - g);
            }
        }
        catch (e_5_1) {
            e_5 = { error: e_5_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_5)
                    throw e_5.error;
            }
        }
    };
    TimeXAxis.prototype.fm = function (a) {
        if (isNaN_(a)) {
            return null;
        }
        var ticks_ = truncate(a);
        var b = (new Date(ticks_));
        var c = this.e9(b);
        if (c == null) {
            return null;
        }
        return c.toString();
    };
    TimeXAxis.prototype.e9 = function (a) {
        if (!(typeCast(Date_$type, a) !== null)) {
            return _super.prototype.e9.call(this, a);
        }
        var b = dateMinValue();
        var c = false;
        if (this.m3 != null) {
            if (typeCast(Date_$type, this.m3) !== null) {
                b = this.m3;
                c = true;
            }
        }
        var d = TimeXAxis.m2(a, c, b, this.mp, this.ng, this.labelFormats, this.eu);
        return d == null ? _super.prototype.e9.call(this, a) : d;
    };
    TimeXAxis.m2 = function (a, b, c, d, e, f, g) {
        var h = TimeXAxis.m7(a, b, c, d, e, f, g);
        return dateToStringFormat(a, h, g);
    };
    TimeXAxis.m7 = function (a, b, c, d, e, f, g) {
        var e_6, _a;
        var h = 0;
        if (b) {
            h = TimeXAxis.mq(a, c);
        }
        var i = null;
        var j;
        if (f == null || f.count == 0) {
            j = TimeXAxis.m6(e, h, d);
        }
        else {
            var k = Number.MAX_VALUE;
            var l = null;
            try {
                for (var _b = tslib_1.__values(fromEnum(f)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var m = _c.value;
                    if (m.o < k) {
                        k = m.o;
                        l = m;
                    }
                    if (m.o > e) {
                        continue;
                    }
                    if (i == null || m.o > i.o) {
                        i = m;
                    }
                }
            }
            catch (e_6_1) {
                e_6 = { error: e_6_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_6)
                        throw e_6.error;
                }
            }
            if (i == null) {
                i = l;
            }
            if (i == null) {
                return null;
            }
            switch (h) {
                case 3:
                    if (i.h != null) {
                        j = i.h;
                    }
                    else if (i.j != null) {
                        j = i.j;
                    }
                    else if (i.l != null) {
                        j = i.l;
                    }
                    else {
                        j = i.e;
                    }
                    break;
                case 2:
                    if (i.j != null) {
                        j = i.j;
                    }
                    else if (i.l != null) {
                        j = i.l;
                    }
                    else {
                        j = i.e;
                    }
                    break;
                case 1:
                    if (i.l != null) {
                        j = i.l;
                    }
                    else {
                        j = i.e;
                    }
                    break;
                default:
                    j = i.e;
                    break;
            }
        }
        return j;
    };
    TimeXAxis.mq = function (a, b) {
        if (a.getFullYear() == b.getFullYear() && dateGetMonth(a) == dateGetMonth(b) && a.getDate() == b.getDate()) {
            return 3;
        }
        else if (a.getFullYear() == b.getFullYear() && dateGetMonth(a) == dateGetMonth(b)) {
            return 2;
        }
        else if (a.getFullYear() == b.getFullYear()) {
            return 1;
        }
        return 0;
    };
    TimeXAxis.prototype.get_la = function () {
        return _super.prototype.get_la.call(this) || (this.intervals != null && this.intervals.count > 0);
    };
    TimeXAxis.prototype.set_la = function (a) {
        _super.prototype.set_la.call(this, a);
    };
    Object.defineProperty(TimeXAxis.prototype, "intervals", {
        get: function () {
            return this.mk;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.m5 = function (a, b) {
        return TimeXAxis.m6(this.ng, a, b);
    };
    TimeXAxis.m6 = function (a, b, c) {
        if (c != 2) {
            b = 0;
        }
        a = Math.abs(a);
        if (a > timeSpanInit3(1825, 0, 0, 0)) {
            return "yyyy";
        }
        if (a > timeSpanInit3(365, 0, 0, 0)) {
            switch (b) {
                case 3:
                case 2:
                case 1: return "MMM";
            }
            return "MMM yyyy";
        }
        ;
        if (a > timeSpanInit3(4, 0, 0, 0)) {
            switch (b) {
                case 3:
                case 2: return "dd";
            }
            return "MMM dd";
        }
        ;
        if (a > timeSpanInit3(1, 0, 0, 0)) {
            switch (b) {
                case 3: return "hh:mmtt";
                case 2: return "dd hh:mmtt";
            }
            return "MMM dd hh:mmtt";
        }
        ;
        if (a > timeSpanInit1(0, 10, 0)) {
            return "hh:mm";
        }
        return "hh:mm:ss";
    };
    TimeXAxis.me = function () {
        if (TimeXAxis.mc == null) {
            TimeXAxis.mc = ((function () {
                var $ret = new OrderedDictionary$2(Number_$type, TimeAxisInterval.$);
                $ret.addItem((0), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 0;
                    $ret.f = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromMilliseconds(1), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 1;
                    $ret.f = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromSeconds(1), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 2;
                    $ret.f = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromSeconds(30), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 2;
                    $ret.f = 30;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromMinutes(2), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 3;
                    $ret.f = 2;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromMinutes(5), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 3;
                    $ret.f = 5;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromHours(1), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 4;
                    $ret.f = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(1), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 5;
                    $ret.f = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(2), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 5;
                    $ret.f = 2;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(5), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 5;
                    $ret.f = 5;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(10), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 5;
                    $ret.f = 10;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(30), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 7;
                    $ret.f = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(60), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 7;
                    $ret.f = 3;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(365), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 8;
                    $ret.f = 1;
                    return $ret;
                })()));
                $ret.addItem(timeSpanFromDays(365 * 10), ((function () {
                    var $ret = new TimeAxisInterval();
                    $ret.b = 8;
                    $ret.f = 10;
                    return $ret;
                })()));
                return $ret;
            })());
        }
        return TimeXAxis.mc;
    };
    TimeXAxis.prototype.mi = function () {
        var e_7, _a;
        if (this.cq && (this.ay == null || this.ay.angle == 0)) {
            var a = this.eb();
            var b = this.ja.width;
            var c = truncate(Math.floor(b / a));
            var d = Number.MAX_VALUE;
            var e = c == 0 ? d : timeSpanFromTicks((intDivide(timeSpanTicks(this.ng), c)));
            var f = null;
            try {
                for (var _b = tslib_1.__values(fromEnum(TimeXAxis.me())), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var g = _c.value;
                    f = g.value;
                    if (g.key > e) {
                        break;
                    }
                }
            }
            catch (e_7_1) {
                e_7 = { error: e_7_1 };
            }
            finally {
                try {
                    if (_c && !_c.done && (_a = _b.return))
                        _a.call(_b);
                }
                finally {
                    if (e_7)
                        throw e_7.error;
                }
            }
            var h = this.mh;
            if (h != f) {
                this.hg();
            }
            this.mh = f;
            return f;
        }
        var i = this.ng;
        if (i == (0)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 8;
                $ret.f = 1;
                return $ret;
            })());
        }
        if (i >= timeSpanFromDays(365 * 100)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 8;
                $ret.f = 10;
                return $ret;
            })());
        }
        if (i >= timeSpanFromDays(365 * 5)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 8;
                $ret.f = 1;
                return $ret;
            })());
        }
        if (i >= timeSpanFromDays(365 * 2)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 7;
                $ret.f = 3;
                return $ret;
            })());
        }
        if (i >= timeSpanFromDays(150)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 7;
                $ret.f = 1;
                return $ret;
            })());
        }
        if (i >= timeSpanFromDays(60)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 5;
                $ret.f = 10;
                return $ret;
            })());
        }
        if (i >= timeSpanFromDays(30)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 5;
                $ret.f = 5;
                return $ret;
            })());
        }
        if (i >= timeSpanFromDays(20)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 5;
                $ret.f = 2;
                return $ret;
            })());
        }
        if (i >= timeSpanFromDays(4)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 5;
                $ret.f = 1;
                return $ret;
            })());
        }
        if (i >= timeSpanFromDays(1)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 4;
                $ret.f = 12;
                return $ret;
            })());
        }
        if (i >= timeSpanFromHours(6)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 4;
                $ret.f = 1;
                return $ret;
            })());
        }
        if (i >= timeSpanFromMinutes(30)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 3;
                $ret.f = 5;
                return $ret;
            })());
        }
        if (i >= timeSpanFromMinutes(10)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 3;
                $ret.f = 2;
                return $ret;
            })());
        }
        return ((function () {
            var $ret = new TimeAxisInterval();
            $ret.b = 2;
            $ret.f = 30;
            return $ret;
        })());
    };
    TimeXAxis.prototype.mj = function () {
        var e_8, _a;
        if (this.intervals == null || this.intervals.count == 0) {
            return this.mi();
        }
        if (this.ng == (0)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 8;
                $ret.f = 1;
                return $ret;
            })());
        }
        var a = null;
        try {
            for (var _b = tslib_1.__values(fromEnum(this.intervals)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                if (b.k > this.ng) {
                    continue;
                }
                if (a == null || b.k > a.k) {
                    a = b;
                }
            }
        }
        catch (e_8_1) {
            e_8 = { error: e_8_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_8)
                    throw e_8.error;
            }
        }
        return a == null ? this.mi() : a;
    };
    TimeXAxis.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) {
            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 = truncate(Math.ceil(e.right));
            var l = truncate(Math.floor(e.left));
            var m = this.a4.a1();
            var n = this.a4.f();
            var o = this.a4.az();
            this.l7();
            var p = new List$1(Date_$type, 1, this.mr());
            var q = new List$1(Number_$type, 0);
            for (var r = 0; r < p.count; r++) {
                q.add(p._inner[r].getTime());
            }
            this.gt(q, 0, q.count, f);
            this.m3 = null;
            for (var s = 0; s < p.count; s++) {
                var t = p._inner[s];
                var u = q._inner[s];
                var v = truncate(Math.round(u));
                if (v <= k) {
                    if (s % 2 == 0) {
                        var w = s < q.count - 1 ? q._inner[s + 1] : e.right;
                        this.hn(m, u, w, c);
                    }
                    this.hm(o, u, c, n, false);
                    this.jv.add(u);
                }
                if (v >= l && v <= k) {
                    var x = this.e9(t);
                    this.m3 = t;
                    if (x != null) {
                        this.cx.add1(x);
                        this.cy.add(new LabelPosition(u));
                    }
                }
            }
            this.m3 = null;
        }
        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();
    };
    TimeXAxis.prototype.mr = function () {
        var a = this.bh != null ? this.bh.os : Rect.empty;
        var b = !a.isEmpty ? this.ja : Rect.empty;
        var c = this.i5();
        var d = this.i4();
        var e = new ScalerParams(0, a, b, this.ca, c);
        var f = this.mj();
        var g = this.visibleMinimum;
        if (!this.ld() && f != null) {
            if (f.b == 7 && g.getDate() != 1) {
                g = dateAddMonths(g, 1);
                g = dateFromValues(g.getFullYear(), dateGetMonth(g), 1, 0, 0, 0, 0);
            }
            else if (f.b == 5 && dateGetTimeOfDay(g) != (0)) {
                g = dateAddDays(g, 1);
                g = dateFromValues(g.getFullYear(), dateGetMonth(g), g.getDate(), 0, 0, 0, 0);
            }
            else if (f.b == 4 && g.getMinutes() != 0) {
                g = dateAddHours(g, 1);
                g = dateFromValues(g.getFullYear(), dateGetMonth(g), g.getDate(), g.getHours(), 0, 0, 0);
            }
        }
        var h = new List$1(Date_$type, 0);
        var i = 0;
        var j = 10000;
        if (f.f == 0) {
            return h;
        }
        while (g <= this.visibleMaximum && i++ < j) {
            var k = this.mt(g);
            var l = g;
            if (k.key != null) {
                l = f.d(k.key.c);
            }
            h.add(l);
            while (g <= l) {
                g = f.c(g);
            }
        }
        return h;
    };
    TimeXAxis.prototype.mt = function (a) {
        var e_9, _a;
        if (this.md == null) {
            return new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        }
        try {
            for (var _b = tslib_1.__values(fromEnum(this.md)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var b = _c.value;
                if (b.key.d <= a && b.key.c >= a) {
                    return b;
                }
            }
        }
        catch (e_9_1) {
            e_9 = { error: e_9_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_9)
                    throw e_9.error;
            }
        }
        return new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
    };
    Object.defineProperty(TimeXAxis.prototype, "visibleMinimum", {
        get: function () {
            return this.mv;
        },
        set: function (a) {
            this.mv = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TimeXAxis.prototype, "visibleMaximum", {
        get: function () {
            return this.mu;
        },
        set: function (a) {
            this.mu = a;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.l7 = function () {
        _super.prototype.l7.call(this);
        if (this.bh == null || !Extensions.b(this.bh.o7)) {
            return;
        }
        var a = new ScalerParams(0, this.bh.os, this.bh.o7, this.ca, this.bh.ow);
        var b = this.i4();
        var c = b.left;
        var d = b.right;
        if (this.categoryMode != 0) {
            var e = this.getCategorySize(a.e, a.d, a.c);
            c += e / 2;
            d -= e / 2;
        }
        var f = truncate(this.d2(c, a));
        var g = truncate(this.d2(d, a));
        if (f < 0 || g < 0) {
            this.ng = (0);
            return;
        }
        f = Math.min(dateMaxValue().getTime(), f);
        g = Math.min(dateMaxValue().getTime(), g);
        var h = dateFromTicks(Math.min(f, g));
        var i = dateFromTicks(Math.max(f, g));
        var j = +(this.visibleMinimum) != +h || +(this.visibleMaximum) != +i;
        this.visibleMinimum = h;
        this.visibleMaximum = i;
        if (j && this.visibleRangeChanged != null) {
            this.visibleRangeChanged(this, EventArgs.empty);
        }
        this.ng = +(this.visibleMaximum) - +(this.visibleMinimum);
    };
    TimeXAxis.prototype.j2 = function (a, b, c, d, e) {
        return 0;
    };
    TimeXAxis.prototype.i$f = function (a) {
        var b = this;
        if (b.i$b == null || b.i$b.count == 0) {
            return -1;
        }
        var c = new SortedListView$1(Date_$type, this.k6, b.i$b);
        var ticks_ = a;
        var d = (new Date(ticks_));
        var e = this.lq(d, c);
        e = Math.max(0, Math.min(b.i$b.count - 1, e));
        var f = c.item(e);
        var g;
        var h;
        if (f < d) {
            g = e;
            h = g + 1;
        }
        else {
            h = e;
            g = e - 1;
        }
        if (g < 0) {
            return h;
        }
        if (h >= b.i$b.count) {
            return g;
        }
        var i = c.item(g);
        var j = c.item(h);
        var k = new ScalerParams(0, this.bh.o8, this.ja, this.ca, this.bh.ow);
        this.startCursor();
        var l = this.dz(i.getTime(), k);
        var m = this.dz(a, k);
        var n = this.dz(j.getTime(), k);
        this.resetCursor();
        if (i < this.visibleMinimum && j <= this.visibleMaximum) {
            return this.lf._inner[h];
        }
        if (j > this.visibleMaximum && i >= this.visibleMinimum) {
            return this.lf._inner[g];
        }
        if (Math.abs(l - m) < Math.abs(n - m)) {
            return this.lf._inner[g];
        }
        else {
            return this.lf._inner[h];
        }
    };
    TimeXAxis.prototype.nj = function (a, b) {
        var e_10, _a;
        this.ni();
        this.nh();
        if (this.av != null) {
            this.av.ak = this.breaks.count > 0;
        }
        this.hc(false);
        try {
            for (var _b = tslib_1.__values(fromEnum(this.cw())), _c = _b.next(); !_c.done; _c = _b.next()) {
                var c = _c.value;
                c.k3(false);
            }
        }
        catch (e_10_1) {
            e_10 = { error: e_10_1 };
        }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return))
                    _a.call(_b);
            }
            finally {
                if (e_10)
                    throw e_10.error;
            }
        }
    };
    TimeXAxis.prototype.nl = function (a, b) {
        this.hc(false);
    };
    TimeXAxis.prototype.nk = function (a, b) {
        this.hc(false);
    };
    TimeXAxis.prototype.get_b5 = function () {
        return false;
    };
    TimeXAxis.prototype.getWindowRectForSelection = function (a, b) {
        var c = +(this.actualMaximumValue) - +(this.actualMinimumValue);
        var d = timeSpanTotalMilliseconds((+a - +(this.actualMinimumValue))) / timeSpanTotalMilliseconds(c);
        var e = 1 - (timeSpanTotalMilliseconds((+(this.actualMaximumValue) - +b)) / timeSpanTotalMilliseconds(c));
        e = Math.min(1, e);
        return new Rect(0, d, NaN, Math.max(0, e - d), NaN);
    };
    TimeXAxis.prototype.getCategorySize = function (a, b, c) {
        if (this.ng != (0)) {
            var d = timeSpanFromTicks(truncate((timeSpanTicks(this.ng) * (a.width / (this.bh != null ? this.bh.os.width : 1)))));
            var e = timeSpanTicks(d) / timeSpanTicks(this.ne);
            var f = b.width / 4;
            return Math.min(f, b.width / (e + 1));
        }
        return _super.prototype.getCategorySize.call(this, a, b, c);
    };
    TimeXAxis.nd = function (a, b) {
        var c = Math.min(5, b);
        var d = a(0);
        var e = new Dictionary$2(Number_$type, Number_$type, 0);
        var f = 0;
        var g = (0);
        for (var h = 0; h < c; h++) {
            var i = a(h);
            var j = +i - +d;
            if (!e.containsKey(j)) {
                e.addItem(j, 0);
            }
            e.item(j, e.item(j) + 1);
            if (e.item(j) > f) {
                f = e.item(j);
                g = j;
            }
            d = i;
        }
        return g;
    };
    TimeXAxis.prototype.nc = function () {
        var _this = this;
        if (this.k6 == null || this.k6.count < 2 || this.lf == null) {
            return (0);
        }
        return TimeXAxis.nd(function (a) { return _this.k6.item(_this.lf._inner[a]); }, this.k6.count);
    };
    TimeXAxis.prototype.l3 = function () {
        _super.prototype.l3.call(this);
        this.ne = this.nc();
    };
    TimeXAxis.m9 = function (a) {
        if (a >= timeSpanFromDays(1)) {
            return "D";
        }
        return "g";
    };
    TimeXAxis.prototype.itemLabelFormat = function () {
        return TimeXAxis.m9(this.ne);
    };
    TimeXAxis.prototype.lp = function (a, b, c, d) {
        return this.lo(this.visibleMinimum);
    };
    TimeXAxis.prototype.ls = function (a, b, c, d) {
        return this.lr(this.visibleMaximum);
    };
    Object.defineProperty(TimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.ch;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.j$c = function (a, b) {
        return this.d2.apply(this, arguments);
    };
    TimeXAxis.prototype.j$b = function (a, b) {
        return this.dz.apply(this, arguments);
    };
    TimeXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gs.apply(this, arguments);
    };
    TimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.gt.apply(this, arguments);
    };
    TimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.gu.apply(this, arguments);
    };
    Object.defineProperty(TimeXAxis.prototype, "j$a", {
        get: function () {
            return this.ca;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TimeXAxis.prototype, "i$a", {
        get: function () {
            return this.b7;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.$t = markType(TimeXAxis, 'TimeXAxis', TimeAxisBase.$, [ITimeRangeSelectorAxis_$type]);
    TimeXAxis.mc = null;
    return TimeXAxis;
}(TimeAxisBase));
export { TimeXAxis };
//# sourceMappingURL=TimeXAxis.js.map
