/*
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 { TimeAxisBase } from "./TimeAxisBase";
import { ITimeRangeSelectorAxis_$type } from "./ITimeRangeSelectorAxis";
import { List$1 } from "igniteui-angular-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-angular-core";
import { ScalerParams } from "./ScalerParams";
import { Rect } from "igniteui-angular-core";
import { NumericScaler } from "./NumericScaler";
import { KeyValuePair$2 } from "igniteui-angular-core";
import { NumericYAxis } from "./NumericYAxis";
import { LabelPosition } from "./LabelPosition";
import { Extensions } from "igniteui-angular-core";
import { SortedListView$1 } from "./SortedListView$1";
import { Dictionary$2 } from "igniteui-angular-core";
import { truncate, intDivide, isNaN_ } from "igniteui-angular-core";
import { dateFromTicks, dateMaxValue, dateAdd, dateSubtract, dateMinValue, dateGetMonth, dateAddMonths, dateFromValues, dateGetTimeOfDay, dateAddDays, dateAddHours } from "igniteui-angular-core";
import { timeSpanTicks, timeSpanInit3, timeSpanInit1, timeSpanFromMilliseconds, timeSpanFromSeconds, timeSpanFromMinutes, timeSpanFromHours, timeSpanFromDays, timeSpanFromTicks, timeSpanTotalMilliseconds } from "igniteui-angular-core";
import { dateToStringFormat } from "igniteui-angular-core";
/**
 * @hidden
 */
export let TimeXAxis = /*@__PURE__*/ (() => {
    class TimeXAxis extends TimeAxisBase {
        constructor() {
            super();
            this.of = 0;
            this.np = null;
            this.ny = 0;
            this.nw = null;
            this._omission = 0;
            this.nn = null;
            this.nu = null;
            this.oh = null;
            this.ou = 0;
            this.n7 = dateMaxValue();
            this.n5 = dateMaxValue();
            this.n4 = dateMaxValue();
            this.n6 = dateMinValue();
            this.nr = null;
            this.os = 0;
            this.visibleRangeChanged = null;
            this.ab = TimeXAxis.$;
            this.omission = (0);
            this.of = -2147483648;
            this.np = new TimeAxisBreakCollection();
            let a = this.breaks;
            a.collectionChanged = delegateCombine(a.collectionChanged, runOn(this, this.ox));
            this.nu = new TimeAxisIntervalCollection();
            let b = this.intervals;
            b.collectionChanged = delegateCombine(b.collectionChanged, runOn(this, this.oy));
            this.nw = new TimeAxisLabelFormatCollection();
            let c = this.labelFormats;
            c.collectionChanged = delegateCombine(c.collectionChanged, runOn(this, this.oz));
            this.ou = (0);
        }
        get_ck() {
            return this.breaks != null && this.breaks.count > 0;
        }
        ei(a, b) {
            if (!b.c.isEmpty) {
                let c = this.od(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.od(a, b.e, b.d, b.c);
        }
        od(a, b, c, d) {
            let e = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
            let f = this.of != -2147483648 ? this.of : 0;
            let g = this.nn != null ? this.nn.count : 0;
            while (f < g) {
                let h = this.nn.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.nn.item(h));
                    f++;
                }
                else {
                    break;
                }
            }
            if (f > 0) {
                f -= 1;
            }
            if (this.of != -2147483648) {
                this.of = f;
            }
            let i;
            let j;
            if (e.key != null) {
                i = e.value;
                j = e.key.c;
            }
            else {
                i = 0;
                j = this.actualMinimumValue;
            }
            let fromPrecedingBreak_ = +(dateFromTicks(truncate(a))) - +j;
            let k = (fromPrecedingBreak_ / ((this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime()) - this.omission));
            let l = i + k;
            l -= b.left;
            l /= b.width;
            let m = c.left;
            let n = c.right;
            let o = c.width;
            if (this.categoryMode != 0) {
                let p = this.getCategorySize(b, c, d);
                m += p / 2;
                n -= p / 2;
                o -= p;
            }
            if (this.cg) {
                return n - o * l;
            }
            return m + o * l;
        }
        hm(a, b, c, d) {
            this.of = 0;
            for (let e = b; e < c; e++) {
                a.item(e, this.ei(a.item(e), d));
            }
            this.of = -2147483648;
        }
        startCursor() {
            this.of = 0;
        }
        resetCursor() {
            this.of = -2147483648;
        }
        el(a, b) {
            if (!b.c.isEmpty) {
                let 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.oe(a, b.e, b.d, b.c);
        }
        oe(a, b, c, d) {
            let e = c.left;
            let f = c.width;
            if (this.categoryMode != 0) {
                let g = this.getCategorySize(b, c, d);
                e += g / 2;
                f -= g;
            }
            let h = b.left + b.width * (a - e) / f;
            if (this.cg) {
                h = 1 - h;
            }
            let i = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
            if (this.nn != null) {
                for (let j of fromEnum(this.nn)) {
                    if (j.value >= h && j.value <= h) {
                        return j.key.d.getTime();
                    }
                    if (j.value < h && j.value > i.value) {
                        i = j;
                    }
                }
            }
            let precedingBreakEnd_;
            let k;
            if (i.key != null) {
                k = i.value;
                precedingBreakEnd_ = i.key.c;
            }
            else {
                k = 0;
                precedingBreakEnd_ = this.actualMinimumValue;
            }
            let portionFromPrecedingBreak_ = h - k;
            let actualRange_ = +(this.actualMaximumValue) - +(this.actualMinimumValue) - this.omission;
            return (precedingBreakEnd_.getTime() + portionFromPrecedingBreak_ * actualRange_);
        }
        get breaks() {
            return this.np;
        }
        get nz() {
            return this.ny;
        }
        set nz(a) {
            let b = this.nz;
            if (a != b) {
                this.ny = a;
                this.h1("LabellingMode", enumGetBox(TimeAxisLabellingMode_$type, b), enumGetBox(TimeAxisLabellingMode_$type, this.nz));
            }
        }
        get labelFormats() {
            return this.nw;
        }
        hv(a, b, c, d) {
            super.hv(a, b, c, d);
            switch (b) {
                case "ActualMaximumValue":
                    this.ow();
                    break;
                case "DateTimeColumn":
                    this.os = this.oq();
                    break;
                case "LabellingMode":
                    this.h7(false);
                    break;
            }
        }
        ip(a, b) {
            super.ip(a, b);
            this.ov();
            this.nh();
        }
        io(a, b) {
            super.io(a, b);
            this.ov();
            this.nh();
        }
        c2() {
            let a = super.c2();
            this.ov();
            return a;
        }
        get omission() {
            return this._omission;
        }
        set omission(a) {
            this._omission = a;
        }
        ow() {
            let a = this.n2(this.breaks);
            let b = (0);
            for (let c of fromEnum(a)) {
                b += (+(c.c) - +(c.d));
            }
            this.omission = b;
        }
        n2(a) {
            let b = new List$1(TimeAxisBreak.$, 0);
            if (a == null || +(this.actualMaximumValue) == +(dateMaxValue())) {
                return b;
            }
            for (let c of fromEn(a)) {
                if (c.c >= this.actualMinimumValue && c.d <= this.actualMaximumValue) {
                    b.add(c);
                }
                if (c.i != (0)) {
                    let d = +(c.c) - +(c.d);
                    let e = dateAdd(+(c.d), +(c.i));
                    while (e <= this.actualMaximumValue) {
                        let f = this.n8(e, d);
                        let g = ((() => {
                            let $ret = new TimeAxisBreak();
                            $ret.d = e;
                            $ret.c = f;
                            return $ret;
                        })());
                        if (g.c >= this.actualMinimumValue && g.d <= this.actualMaximumValue) {
                            b.add(g);
                        }
                        if (dateSubtract(+(dateMaxValue()), +(c.i)) < g.d) {
                            break;
                        }
                        e = this.n8(g.d, c.i);
                    }
                }
            }
            return b;
        }
        n8(a, b) {
            let c = dateFromTicks(a.getTime());
            c.setMilliseconds(c.getMilliseconds() + b);
            return c;
        }
        ov() {
            this.nn = new OrderedDictionary$2(TimeAxisBreak.$, Number_$type);
            if (+(this.actualMaximumValue) == +(dateMaxValue()) || this.breaks == null || this.breaks.count == 0 || this.bh == null) {
                return;
            }
            let a = new List$1(TimeAxisBreak.$, 1, this.n2(this.breaks));
            a.aa((b, c) => b.d < c.d ? -1 : b.d > c.d ? 1 : 0);
            let b = this.bh.ta;
            let c = new ScalerParams(0, this.bh.ta, this.bh.tp, this.cg, this.bh.te);
            let d = +(this.actualMaximumValue) - +(this.actualMinimumValue) - this.omission;
            let e = 0;
            for (let f of fromEnum(a)) {
                let g = timeSpanTicks((+(f.d) - +(this.actualMinimumValue))) / timeSpanTicks(d);
                let h = timeSpanTicks((+(f.c) - +(this.actualMinimumValue))) / timeSpanTicks(d);
                if (h < 0 || g - e > 1) {
                    continue;
                }
                this.nn.addItem(f, g - e);
                e += (h - g);
            }
        }
        gc(a) {
            if (isNaN_(a)) {
                return null;
            }
            let ticks_ = truncate(a);
            let b = (new Date(ticks_));
            let c = this.fy(b);
            if (c == null) {
                return null;
            }
            return c.toString();
        }
        fy(a) {
            if (!(typeCast(Date_$type, a) !== null)) {
                return super.fy(a);
            }
            let b = dateMinValue();
            let c = false;
            if (this.oh != null) {
                if (typeCast(Date_$type, this.oh) !== null) {
                    b = this.oh;
                    c = true;
                }
            }
            let d = TimeXAxis.og(a, c, b, this.nz, this.ou, this.labelFormats, this.fj);
            return d == null ? super.fy(a) : d;
        }
        static og(a, b, c, d, e, f, g) {
            let h = TimeXAxis.ol(a, b, c, d, e, f, g);
            return dateToStringFormat(a, h, g);
        }
        static ol(a, b, c, d, e, f, g) {
            let h = 0;
            if (b) {
                h = TimeXAxis.n0(a, c);
            }
            let i = null;
            let j;
            if (f == null || f.count == 0) {
                j = TimeXAxis.ok(e, h, d);
            }
            else {
                let k = Number.MAX_VALUE;
                let l = null;
                for (let m of fromEnum(f)) {
                    if (m.o < k) {
                        k = m.o;
                        l = m;
                    }
                    if (m.o > e) {
                        continue;
                    }
                    if (i == null || m.o > i.o) {
                        i = m;
                    }
                }
                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;
        }
        static n0(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;
        }
        get_mk() {
            return super.get_mk() || (this.intervals != null && this.intervals.count > 0);
        }
        set_mk(a) {
            super.set_mk(a);
        }
        get intervals() {
            return this.nu;
        }
        oj(a, b) {
            return TimeXAxis.ok(this.ou, a, b);
        }
        static ok(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";
        }
        static no() {
            if (TimeXAxis.nm == null) {
                TimeXAxis.nm = ((() => {
                    let $ret = new OrderedDictionary$2(Number_$type, TimeAxisInterval.$);
                    $ret.addItem((0), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 0;
                        $ret.f = 1;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromMilliseconds(1), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 1;
                        $ret.f = 1;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromSeconds(1), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 2;
                        $ret.f = 1;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromSeconds(30), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 2;
                        $ret.f = 30;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromMinutes(2), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 3;
                        $ret.f = 2;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromMinutes(5), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 3;
                        $ret.f = 5;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromHours(1), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 4;
                        $ret.f = 1;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromDays(1), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 5;
                        $ret.f = 1;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromDays(2), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 5;
                        $ret.f = 2;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromDays(5), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 5;
                        $ret.f = 5;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromDays(10), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 5;
                        $ret.f = 10;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromDays(30), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 7;
                        $ret.f = 1;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromDays(60), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 7;
                        $ret.f = 3;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromDays(365), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 8;
                        $ret.f = 1;
                        return $ret;
                    })()));
                    $ret.addItem(timeSpanFromDays(365 * 10), ((() => {
                        let $ret = new TimeAxisInterval();
                        $ret.b = 8;
                        $ret.f = 10;
                        return $ret;
                    })()));
                    return $ret;
                })());
            }
            return TimeXAxis.nm;
        }
        ns() {
            if (this.c3 && (this.ay == null || this.ay.angle == 0)) {
                let a = this.ew();
                let b = this.kc.width;
                let c = truncate(Math.floor(b / a));
                let d = Number.MAX_VALUE;
                let e = c == 0 ? d : timeSpanFromTicks((intDivide(timeSpanTicks(this.ou), c)));
                let f = null;
                for (let g of fromEnum(TimeXAxis.no())) {
                    f = g.value;
                    if (g.key > e) {
                        break;
                    }
                }
                let h = this.nr;
                if (h != f) {
                    this.ic();
                }
                this.nr = f;
                return f;
            }
            let i = this.ou;
            if (i == (0)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 8;
                    $ret.f = 1;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromDays(365 * 100)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 8;
                    $ret.f = 10;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromDays(365 * 5)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 8;
                    $ret.f = 1;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromDays(365 * 2)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 7;
                    $ret.f = 3;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromDays(150)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 7;
                    $ret.f = 1;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromDays(60)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 5;
                    $ret.f = 10;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromDays(30)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 5;
                    $ret.f = 5;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromDays(20)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 5;
                    $ret.f = 2;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromDays(4)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 5;
                    $ret.f = 1;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromDays(1)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 4;
                    $ret.f = 12;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromHours(6)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 4;
                    $ret.f = 1;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromMinutes(30)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 3;
                    $ret.f = 5;
                    return $ret;
                })());
            }
            if (i >= timeSpanFromMinutes(10)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 3;
                    $ret.f = 2;
                    return $ret;
                })());
            }
            return ((() => {
                let $ret = new TimeAxisInterval();
                $ret.b = 2;
                $ret.f = 30;
                return $ret;
            })());
        }
        nt() {
            if (this.intervals == null || this.intervals.count == 0) {
                return this.ns();
            }
            if (this.ou == (0)) {
                return ((() => {
                    let $ret = new TimeAxisInterval();
                    $ret.b = 8;
                    $ret.f = 1;
                    return $ret;
                })());
            }
            let a = null;
            for (let b of fromEnum(this.intervals)) {
                if (b.k > this.ou) {
                    continue;
                }
                if (a == null || b.k > a.k) {
                    a = b;
                }
            }
            return a == null ? this.ns() : a;
        }
        h8(a) {
            super.h8(a);
            let b = this.bh != null ? this.bh.ta : Rect.empty;
            let c = !b.isEmpty ? this.kc : Rect.empty;
            let d = this.j7();
            let e = this.j6();
            let f = new ScalerParams(0, b, c, this.cg, d);
            if (this.mg == null && !this.mm() && !this.mn()) {
                return;
            }
            if (!b.isEmpty && !c.isEmpty) {
                let g = c.bottom;
                let h = g - c.top;
                if (this.ai != null) {
                    let i = typeCast(NumericYAxis.$, this.ai);
                    if (i != null) {
                        let j = this.id(g, h, b, c, d, c.top, c.bottom);
                        g = j.p0;
                        h = j.p1;
                    }
                }
                if (isNaN_(g)) {
                    g = 0;
                }
                this.hp(this.a4.a1(), g, c, this.a4.e(), true);
                this.av.bg = h;
                let k = truncate(Math.ceil(e.right));
                let l = truncate(Math.floor(e.left));
                let m = this.a4.a4();
                let n = this.a4.f();
                let o = this.a4.a2();
                this.nh();
                let p = new List$1(Date_$type, 1, this.n1());
                let q = new List$1(Number_$type, 0);
                for (let r = 0; r < p.count; r++) {
                    q.add(p._inner[r].getTime());
                }
                this.hm(q, 0, q.count, f);
                this.oh = null;
                for (let s = 0; s < p.count; s++) {
                    let t = p._inner[s];
                    let u = q._inner[s];
                    let v = truncate(Math.round(u));
                    if (v <= k) {
                        if (s % 2 == 0) {
                            let w = s < q.count - 1 ? q._inner[s + 1] : e.right;
                            this.im(m, u, w, c);
                        }
                        this.il(o, u, c, n, false);
                        this.kx.add(u);
                    }
                    if (v >= l && v <= k) {
                        let x = this.fy(t);
                        this.oh = t;
                        if (x != null) {
                            this.db.add1(x);
                            this.dc.add(new LabelPosition(u));
                        }
                    }
                }
                this.oh = 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.l7();
                }
            }
            this.av.a9 = this.db;
            this.av.ba = this.dc;
            this.av.cl();
            this.l3();
        }
        n1() {
            let a = this.bh != null ? this.bh.ta : Rect.empty;
            let b = !a.isEmpty ? this.kc : Rect.empty;
            let c = this.j7();
            let d = this.j6();
            let e = new ScalerParams(0, a, b, this.cg, c);
            let f = this.nt();
            let g = this.oa;
            if (!this.mn() && 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);
                }
            }
            let h = new List$1(Date_$type, 0);
            let i = 0;
            let j = 10000;
            if (f.f == 0) {
                return h;
            }
            while (g <= this.visibleMaximum && i++ < j) {
                let k = this.n3(g);
                let l = g;
                if (k.key != null) {
                    l = f.d(k.key.c);
                }
                h.add(l);
                while (g <= l) {
                    g = f.c(g);
                }
            }
            return h;
        }
        n3(a) {
            if (this.nn == null) {
                return new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
            }
            for (let b of fromEnum(this.nn)) {
                if (b.key.d <= a && b.key.c >= a) {
                    return b;
                }
            }
            return new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        }
        get visibleMinimum() {
            return this.n7;
        }
        set visibleMinimum(a) {
            this.n7 = a;
        }
        get oa() {
            return this.n5;
        }
        set oa(a) {
            this.n5 = a;
        }
        get n9() {
            return this.n4;
        }
        set n9(a) {
            this.n4 = a;
        }
        get visibleMaximum() {
            return this.n6;
        }
        set visibleMaximum(a) {
            this.n6 = a;
        }
        nh() {
            super.nh();
            if (this.bh == null || !Extensions.b(this.bh.tp)) {
                return;
            }
            let a = new ScalerParams(0, this.bh.ta, this.bh.tp, this.cg, this.bh.te);
            let b = this.j6();
            let c = b.left;
            let d = b.right;
            let e = b.left;
            let f = b.right;
            if (this.categoryMode != 0) {
                let g = this.getCategorySize(a.e, a.d, a.c);
                e += g / 2;
                f -= g / 2;
            }
            let h = truncate(this.el(c, a));
            let i = truncate(this.el(d, a));
            let j = truncate(this.el(e, a));
            let k = truncate(this.el(f, a));
            if (j < 0 || k < 0) {
                this.ou = (0);
                return;
            }
            h = Math.min(dateMaxValue().getTime(), h);
            i = Math.min(dateMaxValue().getTime(), i);
            h = Math.max(dateMinValue().getTime(), h);
            i = Math.max(dateMinValue().getTime(), i);
            j = Math.min(dateMaxValue().getTime(), j);
            k = Math.min(dateMaxValue().getTime(), k);
            let l = dateFromTicks(Math.min(h, i));
            let m = dateFromTicks(Math.max(h, i));
            let n = dateFromTicks(Math.min(j, k));
            let o = dateFromTicks(Math.max(j, k));
            let p = +(this.visibleMinimum) != +n || +(this.visibleMaximum) != +o;
            this.visibleMinimum = n;
            this.visibleMaximum = o;
            this.oa = l;
            this.n9 = m;
            if (p && this.visibleRangeChanged != null) {
                this.visibleRangeChanged(this, EventArgs.empty);
            }
            this.ou = +(this.visibleMaximum) - +(this.visibleMinimum);
        }
        k5(a, b, c, d, e) {
            return 0;
        }
        i$f(a) {
            let b = this;
            if (b.i$b == null || b.i$b.count == 0) {
                return -1;
            }
            let c = new SortedListView$1(Date_$type, this.mg, b.i$b);
            let ticks_ = a;
            let d = (new Date(ticks_));
            let e = this.m0(d, c);
            e = Math.max(0, Math.min(b.i$b.count - 1, e));
            let f = c.item(e);
            let g;
            let 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;
            }
            let i = c.item(g);
            let j = c.item(h);
            let k = new ScalerParams(0, this.bh.tq, this.kc, this.cg, this.bh.te);
            this.startCursor();
            let l = this.ei(i.getTime(), k);
            let m = this.ei(a, k);
            let n = this.ei(j.getTime(), k);
            this.resetCursor();
            if (i < this.oa && j <= this.n9) {
                return this.mp._inner[h];
            }
            if (j > this.n9 && i >= this.oa) {
                return this.mp._inner[g];
            }
            if (Math.abs(l - m) < Math.abs(n - m)) {
                return this.mp._inner[g];
            }
            else {
                return this.mp._inner[h];
            }
        }
        ox(a, b) {
            this.ow();
            this.ov();
            if (this.av != null) {
                this.av.al = this.breaks.count > 0;
            }
            this.h7(false);
            for (let c of fromEnum(this.da())) {
                c.mn(false);
            }
        }
        oz(a, b) {
            this.h7(false);
        }
        oy(a, b) {
            this.h7(false);
        }
        get_cb() {
            return false;
        }
        getWindowRectForSelection(a, b) {
            let c = +(this.actualMaximumValue) - +(this.actualMinimumValue);
            let d = timeSpanTotalMilliseconds((+a - +(this.actualMinimumValue))) / timeSpanTotalMilliseconds(c);
            let 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);
        }
        getCategorySize(a, b, c) {
            if (this.ou != (0)) {
                let d = timeSpanFromTicks(truncate((timeSpanTicks(this.ou) * (a.width / (this.bh != null ? this.bh.ta.width : 1)))));
                let e = timeSpanTicks(d) / timeSpanTicks(this.os);
                let f = b.width / 4;
                return Math.min(f, b.width / (e + 1));
            }
            return super.getCategorySize(a, b, c);
        }
        static or(a, b) {
            let c = Math.min(5, b);
            let d = a(0);
            let e = new Dictionary$2(Number_$type, Number_$type, 0);
            let f = 0;
            let g = (0);
            for (let h = 0; h < c; h++) {
                let i = a(h);
                let 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;
        }
        oq() {
            if (this.mg == null || this.mg.count < 2 || this.mp == null) {
                return (0);
            }
            return TimeXAxis.or((a) => this.mg.item(this.mp._inner[a]), this.mg.count);
        }
        nd() {
            super.nd();
            this.os = this.oq();
        }
        static on(a) {
            if (a >= timeSpanFromDays(1)) {
                return "D";
            }
            return "g";
        }
        itemLabelFormat() {
            return TimeXAxis.on(this.os);
        }
        mz(a, b, c, d) {
            return this.my(this.visibleMinimum);
        }
        m2(a, b, c, d) {
            return this.m1(this.visibleMaximum);
        }
        get isVertical() {
            return this.co;
        }
        j$c(a, b) {
            return this.el.apply(this, arguments);
        }
        j$b(a, b) {
            return this.ei.apply(this, arguments);
        }
        j$d(a, b, c, d, e) {
            this.hl.apply(this, arguments);
        }
        j$e(a, b, c, d) {
            this.hm.apply(this, arguments);
        }
        j$f(a, b, c, d) {
            this.hn.apply(this, arguments);
        }
        get j$a() {
            return this.cg;
        }
        get i$a() {
            return this.cd;
        }
    }
    TimeXAxis.$t = markType(TimeXAxis, 'TimeXAxis', TimeAxisBase.$, [ITimeRangeSelectorAxis_$type]);
    TimeXAxis.nm = null;
    return TimeXAxis;
})();
