/*
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 { TimeAxisBreakCollection } from "./TimeAxisBreakCollection";
import { TimeAxisLabelFormatCollection } from "./TimeAxisLabelFormatCollection";
import { OrderedDictionary$2 } from "./OrderedDictionary$2";
import { TimeAxisBreak } from "./TimeAxisBreak";
import { List$1 } from "igniteui-react-core/ES5/List$1";
import { TimeAxisInterval } from "./TimeAxisInterval";
import { TimeAxisIntervalCollection } from "./TimeAxisIntervalCollection";
import { EventArgs, runOn, delegateCombine, Number_$type, fromEnum, fromEn, typeCast, Date_$type, markType } from "igniteui-react-core/ES5/type";
import { ScalerParams } from "./ScalerParams";
import { KeyValuePair$2 } from "igniteui-react-core/ES5/KeyValuePair$2";
import { Rect } from "igniteui-react-core/ES5/Rect";
import { NumericYAxis } from "./NumericYAxis";
import { LabelPosition } from "./LabelPosition";
import { Extensions } from "igniteui-react-core/ES5/Extensions";
import { SortedListView$1 } from "./SortedListView$1";
import { Dictionary$2 } from "igniteui-react-core/ES5/Dictionary$2";
import { truncate, intDivide, isNaN_ } from "igniteui-react-core/ES5/number";
import { dateFromTicks, dateMaxValue, dateAdd, dateSubtract, dateAddMonths, dateFromValues, dateGetMonth, dateGetTimeOfDay, dateAddDays, dateAddHours, dateMinValue } from "igniteui-react-core/ES5/date";
import { timeSpanTicks, timeSpanInit3, timeSpanInit1, timeSpanFromMilliseconds, timeSpanFromSeconds, timeSpanFromMinutes, timeSpanFromHours, timeSpanFromDays, timeSpanFromTicks, timeSpanTotalMilliseconds } from "igniteui-react-core/ES5/timespan";
import { dateToStringFormat } from "igniteui-react-core/ES5/dateExtended";
/**
 * @hidden
 */
var TimeXAxis = /** @class */ (function (_super) {
    tslib_1.__extends(TimeXAxis, _super);
    function TimeXAxis() {
        var _this = _super.call(this) || this;
        _this.mf = 0;
        _this.lz = null;
        _this.l5 = null;
        _this._omission = 0;
        _this.lx = null;
        _this.l3 = null;
        _this.mr = 0;
        _this.mb = dateMaxValue();
        _this.ma = dateMinValue();
        _this.mp = 0;
        _this.visibleRangeChanged = null;
        _this.ab = TimeXAxis.$;
        _this.omission = (0);
        _this.mf = -2147483648;
        _this.lz = new TimeAxisBreakCollection();
        var a = _this.breaks;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.mu));
        _this.l3 = new TimeAxisIntervalCollection();
        var b = _this.intervals;
        b.collectionChanged = delegateCombine(b.collectionChanged, runOn(_this, _this.mv));
        _this.l5 = new TimeAxisLabelFormatCollection();
        var c = _this.labelFormats;
        c.collectionChanged = delegateCombine(c.collectionChanged, runOn(_this, _this.mw));
        _this.mr = (0);
        return _this;
    }
    TimeXAxis.prototype.dt = function (a, b) {
        var c = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        var d = this.mf != -2147483648 ? this.mf : 0;
        var e = this.lx != null ? this.lx.count : 0;
        while (d < e) {
            var f = this.lx.item1(d);
            if (f.d.getTime() <= a && f.c.getTime() >= a) {
                return NaN;
            }
            if (f.c.getTime() <= a) {
                c = new KeyValuePair$2(TimeAxisBreak.$, Number_$type, 1, f, this.lx.item(f));
                d++;
            }
            else {
                break;
            }
        }
        if (d > 0) {
            d -= 1;
        }
        if (this.mf != -2147483648) {
            this.mf = d;
        }
        var g;
        var h;
        if (c.key != null) {
            g = c.value;
            h = c.key.c;
        }
        else {
            g = 0;
            h = this.actualMinimumValue;
        }
        var fromPrecedingBreak_ = +(dateFromTicks(truncate(a))) - +h;
        var i = (fromPrecedingBreak_ / ((this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime()) - this.omission));
        var j = g + i;
        j -= b.e.left;
        j /= b.e.width;
        var k = b.d.left;
        var l = b.d.right;
        var m = b.d.width;
        if (this.categoryMode != 0) {
            var n = this.getCategorySize(b.e, b.d, b.c);
            k += n / 2;
            l -= n / 2;
            m -= n;
        }
        if (this.b8) {
            return l - m * j;
        }
        return k + m * j;
    };
    TimeXAxis.prototype.gh = function (a, b, c, d) {
        this.mf = 0;
        for (var e = b; e < c; e++) {
            a.item(e, this.dt(a.item(e), d));
        }
        this.mf = -2147483648;
    };
    TimeXAxis.prototype.startCursor = function () {
        this.mf = 0;
    };
    TimeXAxis.prototype.resetCursor = function () {
        this.mf = -2147483648;
    };
    TimeXAxis.prototype.dw = function (a, b) {
        var e_1, _a;
        var c = b.d.left;
        var d = b.d.width;
        if (this.categoryMode != 0) {
            var e = this.getCategorySize(b.e, b.d, b.c);
            c += e / 2;
            d -= e;
        }
        var f = b.e.left + b.e.width * (a - c) / d;
        if (this.b8) {
            f = 1 - f;
        }
        var g = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        if (this.lx != null) {
            try {
                for (var _b = tslib_1.__values(fromEnum(this.lx)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var h = _c.value;
                    if (h.value >= f && h.value <= f) {
                        return h.key.d.getTime();
                    }
                    if (h.value < f && h.value > g.value) {
                        g = h;
                    }
                }
            }
            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 i;
        if (g.key != null) {
            i = g.value;
            precedingBreakEnd_ = g.key.c;
        }
        else {
            i = 0;
            precedingBreakEnd_ = this.actualMinimumValue;
        }
        var portionFromPrecedingBreak_ = f - i;
        var actualRange_ = +(this.actualMaximumValue) - +(this.actualMinimumValue) - this.omission;
        return (precedingBreakEnd_.getTime() + portionFromPrecedingBreak_ * actualRange_);
    };
    Object.defineProperty(TimeXAxis.prototype, "breaks", {
        get: function () {
            return this.lz;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TimeXAxis.prototype, "labelFormats", {
        get: function () {
            return this.l5;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.go = function (a, b, c, d) {
        _super.prototype.go.call(this, a, b, c, d);
        switch (b) {
            case "ActualMaximumValue":
                this.mt();
                break;
            case "DateTimeColumn":
                this.mp = this.mn();
                break;
        }
    };
    TimeXAxis.prototype.hc = function (a, b) {
        _super.prototype.hc.call(this, a, b);
        this.ms();
        this.lr();
    };
    TimeXAxis.prototype.hb = function (a, b) {
        _super.prototype.hb.call(this, a, b);
        this.ms();
        this.lr();
    };
    TimeXAxis.prototype.cm = function () {
        var a = _super.prototype.cm.call(this);
        this.ms();
        return a;
    };
    Object.defineProperty(TimeXAxis.prototype, "omission", {
        get: function () {
            return this._omission;
        },
        set: function (a) {
            this._omission = a;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.mt = function () {
        var e_2, _a;
        var a = this.l8(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.l8 = 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.mc(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.mc(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.mc = function (a, b) {
        var c = dateFromTicks(a.getTime());
        c.setMilliseconds(c.getMilliseconds() + b);
        return c;
    };
    TimeXAxis.prototype.ms = function () {
        var e_5, _a;
        this.lx = new OrderedDictionary$2(TimeAxisBreak.$, Number_$type);
        if (+(this.actualMaximumValue) == +(dateMaxValue()) || this.breaks == null || this.breaks.count == 0 || this.bf == null) {
            return;
        }
        var a = new List$1(TimeAxisBreak.$, 1, this.l8(this.breaks));
        a.aa(function (b, c) { return b.d < c.d ? -1 : b.d > c.d ? 1 : 0; });
        var b = this.bf.mq;
        var c = new ScalerParams(0, this.bf.mq, this.bf.m3, this.b8, this.bf.mu);
        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.lx.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.fe = function (a) {
        if (isNaN_(a)) {
            return null;
        }
        var ticks_ = truncate(a);
        var b = (new Date(ticks_));
        var c = this.e1(b);
        if (c == null) {
            return null;
        }
        return c.toString();
    };
    TimeXAxis.prototype.e1 = function (a) {
        if (!(typeCast(Date_$type, a) !== null)) {
            return _super.prototype.e1.call(this, a);
        }
        var b = TimeXAxis.mg(a, this.mr, this.labelFormats, this.eo);
        return b == null ? _super.prototype.e1.call(this, a) : b;
    };
    TimeXAxis.mg = function (a, b, c, d) {
        var e_6, _a;
        var e = null;
        if (b == (0)) {
            return null;
        }
        var f;
        if (c == null || c.count == 0) {
            f = TimeXAxis.mj(b);
        }
        else {
            try {
                for (var _b = tslib_1.__values(fromEnum(c)), _c = _b.next(); !_c.done; _c = _b.next()) {
                    var g = _c.value;
                    if (g.f > b) {
                        continue;
                    }
                    if (e == null || g.f > e.f) {
                        e = g;
                    }
                }
            }
            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 (e == null) {
                return null;
            }
            f = e.b;
        }
        return dateToStringFormat(a, f, d);
    };
    TimeXAxis.prototype.get_ku = function () {
        return _super.prototype.get_ku.call(this) || (this.intervals != null && this.intervals.count > 0);
    };
    TimeXAxis.prototype.set_ku = function (a) {
        _super.prototype.set_ku.call(this, a);
    };
    Object.defineProperty(TimeXAxis.prototype, "intervals", {
        get: function () {
            return this.l3;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.mi = function () {
        return TimeXAxis.mj(this.mr);
    };
    TimeXAxis.mj = function (a) {
        a = Math.abs(a);
        if (a > timeSpanInit3(1825, 0, 0, 0)) {
            return "yyyy";
        }
        if (a > timeSpanInit3(365, 0, 0, 0)) {
            return "MMM yyyy";
        }
        if (a > timeSpanInit3(4, 0, 0, 0)) {
            return "MMM dd";
        }
        if (a > timeSpanInit3(1, 0, 0, 0)) {
            return "MMM dd hh:mmtt";
        }
        if (a > timeSpanInit1(0, 10, 0)) {
            return "hh:mm";
        }
        return "hh:mm:ss";
    };
    TimeXAxis.ly = function () {
        if (TimeXAxis.lw == null) {
            TimeXAxis.lw = ((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.lw;
    };
    TimeXAxis.prototype.l1 = function () {
        var e_7, _a;
        if (this.cn && (this.aw == null || this.aw.angle == 0)) {
            var a = this.d5();
            var b = this.iu.width;
            var c = truncate(Math.floor(b / a));
            var d = Number.MAX_VALUE;
            var e = c == 0 ? d : timeSpanFromTicks((intDivide(timeSpanTicks(this.mr), c)));
            var f = null;
            try {
                for (var _b = tslib_1.__values(fromEnum(TimeXAxis.ly())), _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; }
            }
            return f;
        }
        var h = this.mr;
        if (h == (0)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 8;
                $ret.f = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(365 * 100)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 8;
                $ret.f = 10;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(365 * 5)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 8;
                $ret.f = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(365 * 2)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 7;
                $ret.f = 3;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(150)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 7;
                $ret.f = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(60)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 5;
                $ret.f = 10;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(30)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 5;
                $ret.f = 5;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(20)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 5;
                $ret.f = 2;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(4)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 5;
                $ret.f = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromDays(1)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 4;
                $ret.f = 12;
                return $ret;
            })());
        }
        if (h >= timeSpanFromHours(6)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 4;
                $ret.f = 1;
                return $ret;
            })());
        }
        if (h >= timeSpanFromMinutes(30)) {
            return ((function () {
                var $ret = new TimeAxisInterval();
                $ret.b = 3;
                $ret.f = 5;
                return $ret;
            })());
        }
        if (h >= 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.l2 = function () {
        var e_8, _a;
        if (this.intervals == null || this.intervals.count == 0) {
            return this.l1();
        }
        if (this.mr == (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.mr) {
                    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.l1() : a;
    };
    TimeXAxis.prototype.g1 = function (a) {
        _super.prototype.g1.call(this, a);
        var b = this.bf != null ? this.bf.mq : Rect.empty;
        var c = !b.isEmpty ? this.iu : Rect.empty;
        var d = this.ip();
        var e = this.io();
        var f = new ScalerParams(0, b, c, this.b8, d);
        if (this.kq == null && !this.kw() && !this.kx()) {
            return;
        }
        if (!b.isEmpty && !c.isEmpty) {
            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.g4(g, h, b, c, d, c.top, c.bottom);
                    g = j.p0;
                    h = j.p1;
                }
            }
            if (isNaN_(g)) {
                g = 0;
            }
            this.gk(this.a2.ax(), g, c, this.a2.e(), true);
            this.at.a8 = h;
            var k = truncate(Math.ceil(e.right));
            var l = truncate(Math.floor(e.left));
            var m = this.a2.a0();
            var n = this.a2.f();
            var o = this.a2.ay();
            this.lr();
            var p = new List$1(Date_$type, 1, this.l7());
            var q = new List$1(Number_$type, 0);
            for (var r = 0; r < p.count; r++) {
                q.add(p._inner[r].getTime());
            }
            this.gh(q, 0, q.count, f);
            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.ha(m, u, w, c);
                    }
                    this.g9(o, u, c, n, false);
                    this.jf.add(u);
                }
                if (v >= l && v <= k) {
                    var x = this.e1(t);
                    if (x != null) {
                        this.cs.add1(x);
                        this.ct.add(new LabelPosition(u));
                    }
                }
            }
        }
        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.cs;
        this.at.a2 = this.ct;
        this.kf();
    };
    TimeXAxis.prototype.l7 = function () {
        var a = this.bf != null ? this.bf.mq : Rect.empty;
        var b = !a.isEmpty ? this.iu : Rect.empty;
        var c = this.ip();
        var d = this.io();
        var e = new ScalerParams(0, a, b, this.b8, c);
        var f = this.l2();
        var g = this.visibleMinimum;
        if (!this.kx() && 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.l9(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.l9 = function (a) {
        var e_9, _a;
        if (this.lx == null) {
            return new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        }
        try {
            for (var _b = tslib_1.__values(fromEnum(this.lx)), _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.mb;
        },
        set: function (a) {
            this.mb = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TimeXAxis.prototype, "visibleMaximum", {
        get: function () {
            return this.ma;
        },
        set: function (a) {
            this.ma = a;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.lr = function () {
        _super.prototype.lr.call(this);
        if (this.bf == null || !Extensions.b(this.bf.m3)) {
            return;
        }
        var a = new ScalerParams(0, this.bf.mq, this.bf.m3, this.b8, this.bf.mu);
        var b = this.bf.m3.left;
        var c = this.bf.m3.right;
        if (this.categoryMode != 0) {
            var d = this.getCategorySize(a.e, a.d, a.c);
            b += d / 2;
            c -= d / 2;
        }
        var e = truncate(this.dw(b, a));
        var f = truncate(this.dw(c, a));
        if (e < 0 || f < 0) {
            this.mr = (0);
            return;
        }
        e = Math.min(dateMaxValue().getTime(), e);
        f = Math.min(dateMaxValue().getTime(), f);
        var g = dateFromTicks(Math.min(e, f));
        var h = dateFromTicks(Math.max(e, f));
        var i = +(this.visibleMinimum) != +g || +(this.visibleMaximum) != +h;
        this.visibleMinimum = g;
        this.visibleMaximum = h;
        if (i && this.visibleRangeChanged != null) {
            this.visibleRangeChanged(this, EventArgs.empty);
        }
        this.mr = +(this.visibleMaximum) - +(this.visibleMinimum);
    };
    TimeXAxis.prototype.jm = function (a, b, c, d, e) {
        return 0;
    };
    TimeXAxis.prototype.i$f = function (a) {
        var b = this;
        if (b.i$b == null) {
            return -1;
        }
        var c = new SortedListView$1(Date_$type, this.kq, b.i$b);
        var ticks_ = a;
        var d = (new Date(ticks_));
        var e = this.la(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.bf.m4, this.iu, this.b8, this.bf.mu);
        this.startCursor();
        var l = this.dt(i.getTime(), k);
        var m = this.dt(a, k);
        var n = this.dt(j.getTime(), k);
        this.resetCursor();
        if (i < this.visibleMinimum && j <= this.visibleMaximum) {
            return this.kz._inner[h];
        }
        if (j > this.visibleMaximum && i >= this.visibleMinimum) {
            return this.kz._inner[g];
        }
        if (Math.abs(l - m) < Math.abs(n - m)) {
            return this.kz._inner[g];
        }
        else {
            return this.kz._inner[h];
        }
    };
    TimeXAxis.prototype.mu = function (a, b) {
        var e_10, _a;
        this.mt();
        this.ms();
        if (this.at != null) {
            this.at.ak = this.breaks.count > 0;
        }
        this.g0(false);
        try {
            for (var _b = tslib_1.__values(fromEnum(this.cr())), _c = _b.next(); !_c.done; _c = _b.next()) {
                var c = _c.value;
                c.i6(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.mw = function (a, b) {
        this.g0(false);
    };
    TimeXAxis.prototype.mv = function (a, b) {
        this.g0(false);
    };
    TimeXAxis.prototype.get_b3 = 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.mr != (0)) {
            var d = timeSpanFromTicks(truncate((timeSpanTicks(this.mr) * (a.width / (this.bf != null ? this.bf.mq.width : 1)))));
            var e = timeSpanTicks(d) / timeSpanTicks(this.mp);
            var f = b.width / 4;
            return Math.min(f, b.width / (e + 1));
        }
        return _super.prototype.getCategorySize.call(this, a, b, c);
    };
    TimeXAxis.mo = 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.mn = function () {
        var _this = this;
        if (this.kq == null || this.kq.count < 2 || this.kz == null) {
            return (0);
        }
        return TimeXAxis.mo(function (a) { return _this.kq.item(_this.kz._inner[a]); }, this.kq.count);
    };
    TimeXAxis.prototype.ln = function () {
        _super.prototype.ln.call(this);
        this.mp = this.mn();
    };
    TimeXAxis.ml = function (a) {
        if (a >= timeSpanFromDays(1)) {
            return "D";
        }
        return "g";
    };
    TimeXAxis.prototype.itemLabelFormat = function () {
        return TimeXAxis.ml(this.mp);
    };
    TimeXAxis.prototype.k9 = function (a, b, c, d) {
        return this.k8(this.visibleMinimum);
    };
    TimeXAxis.prototype.lc = function (a, b, c, d) {
        return this.lb(this.visibleMaximum);
    };
    Object.defineProperty(TimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.ce;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.prototype.j$c = function (a, b) {
        return this.dw.apply(this, arguments);
    };
    TimeXAxis.prototype.j$b = function (a, b) {
        return this.dt.apply(this, arguments);
    };
    TimeXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gg.apply(this, arguments);
    };
    TimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.gh.apply(this, arguments);
    };
    TimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.gi.apply(this, arguments);
    };
    Object.defineProperty(TimeXAxis.prototype, "j$a", {
        get: function () {
            return this.b8;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(TimeXAxis.prototype, "i$a", {
        get: function () {
            return this.b5;
        },
        enumerable: true,
        configurable: true
    });
    TimeXAxis.$t = markType(TimeXAxis, 'TimeXAxis', TimeAxisBase.$, [ITimeRangeSelectorAxis_$type]);
    TimeXAxis.lw = null;
    return TimeXAxis;
}(TimeAxisBase));
export { TimeXAxis };
