/*
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-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 { KeyValuePair$2 } from "igniteui-react-core";
import { Rect } 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
 */
export let TimeXAxis = /*@__PURE__*/ (() => {
    class TimeXAxis extends TimeAxisBase {
        constructor() {
            super();
            this.my = 0;
            this.me = null;
            this.mn = 0;
            this.ml = null;
            this._omission = 0;
            this.mc = null;
            this.mj = null;
            this.m0 = null;
            this.nc = 0;
            this.mu = dateMaxValue();
            this.mt = dateMinValue();
            this.mg = null;
            this.na = 0;
            this.visibleRangeChanged = null;
            this.ab = TimeXAxis.$;
            this.omission = (0);
            this.my = -2147483648;
            this.me = new TimeAxisBreakCollection();
            let a = this.breaks;
            a.collectionChanged = delegateCombine(a.collectionChanged, runOn(this, this.nf));
            this.mj = new TimeAxisIntervalCollection();
            let b = this.intervals;
            b.collectionChanged = delegateCombine(b.collectionChanged, runOn(this, this.ng));
            this.ml = new TimeAxisLabelFormatCollection();
            let c = this.labelFormats;
            c.collectionChanged = delegateCombine(c.collectionChanged, runOn(this, this.nh));
            this.nc = (0);
        }
        get_cd() {
            return this.breaks != null && this.breaks.count > 0;
        }
        dy(a, b) {
            let c = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
            let d = this.my != -2147483648 ? this.my : 0;
            let e = this.mc != null ? this.mc.count : 0;
            while (d < e) {
                let f = this.mc.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.mc.item(f));
                    d++;
                }
                else {
                    break;
                }
            }
            if (d > 0) {
                d -= 1;
            }
            if (this.my != -2147483648) {
                this.my = d;
            }
            let g;
            let h;
            if (c.key != null) {
                g = c.value;
                h = c.key.c;
            }
            else {
                g = 0;
                h = this.actualMinimumValue;
            }
            let fromPrecedingBreak_ = +(dateFromTicks(truncate(a))) - +h;
            let i = (fromPrecedingBreak_ / ((this.actualMaximumValue.getTime() - this.actualMinimumValue.getTime()) - this.omission));
            let j = g + i;
            j -= b.e.left;
            j /= b.e.width;
            let k = b.d.left;
            let l = b.d.right;
            let m = b.d.width;
            if (this.categoryMode != 0) {
                let n = this.getCategorySize(b.e, b.d, b.c);
                k += n / 2;
                l -= n / 2;
                m -= n;
            }
            if (this.ca) {
                return l - m * j;
            }
            return k + m * j;
        }
        gs(a, b, c, d) {
            this.my = 0;
            for (let e = b; e < c; e++) {
                a.item(e, this.dy(a.item(e), d));
            }
            this.my = -2147483648;
        }
        startCursor() {
            this.my = 0;
        }
        resetCursor() {
            this.my = -2147483648;
        }
        d1(a, b) {
            let c = b.d.left;
            let d = b.d.width;
            if (this.categoryMode != 0) {
                let e = this.getCategorySize(b.e, b.d, b.c);
                c += e / 2;
                d -= e;
            }
            let f = b.e.left + b.e.width * (a - c) / d;
            if (this.ca) {
                f = 1 - f;
            }
            let g = new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
            if (this.mc != null) {
                for (let h of fromEnum(this.mc)) {
                    if (h.value >= f && h.value <= f) {
                        return h.key.d.getTime();
                    }
                    if (h.value < f && h.value > g.value) {
                        g = h;
                    }
                }
            }
            let precedingBreakEnd_;
            let i;
            if (g.key != null) {
                i = g.value;
                precedingBreakEnd_ = g.key.c;
            }
            else {
                i = 0;
                precedingBreakEnd_ = this.actualMinimumValue;
            }
            let portionFromPrecedingBreak_ = f - i;
            let actualRange_ = +(this.actualMaximumValue) - +(this.actualMinimumValue) - this.omission;
            return (precedingBreakEnd_.getTime() + portionFromPrecedingBreak_ * actualRange_);
        }
        get breaks() {
            return this.me;
        }
        get mo() {
            return this.mn;
        }
        set mo(a) {
            let b = this.mo;
            if (a != b) {
                this.mn = a;
                this.g5("LabellingMode", enumGetBox(TimeAxisLabellingMode_$type, b), enumGetBox(TimeAxisLabellingMode_$type, this.mo));
            }
        }
        get labelFormats() {
            return this.ml;
        }
        gz(a, b, c, d) {
            super.gz(a, b, c, d);
            switch (b) {
                case "ActualMaximumValue":
                    this.ne();
                    break;
                case "DateTimeColumn":
                    this.na = this.m8();
                    break;
                case "LabellingMode":
                    this.hb(false);
                    break;
            }
        }
        ho(a, b) {
            super.ho(a, b);
            this.nd();
            this.l6();
        }
        hn(a, b) {
            super.hn(a, b);
            this.nd();
            this.l6();
        }
        cp() {
            let a = super.cp();
            this.nd();
            return a;
        }
        get omission() {
            return this._omission;
        }
        set omission(a) {
            this._omission = a;
        }
        ne() {
            let a = this.mr(this.breaks);
            let b = (0);
            for (let c of fromEnum(a)) {
                b += (+(c.c) - +(c.d));
            }
            this.omission = b;
        }
        mr(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.mv(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.mv(g.d, c.i);
                    }
                }
            }
            return b;
        }
        mv(a, b) {
            let c = dateFromTicks(a.getTime());
            c.setMilliseconds(c.getMilliseconds() + b);
            return c;
        }
        nd() {
            this.mc = 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.mr(this.breaks));
            a.aa((b, c) => b.d < c.d ? -1 : b.d > c.d ? 1 : 0);
            let b = this.bh.n2;
            let c = new ScalerParams(0, this.bh.n2, this.bh.oh, this.ca, this.bh.n6);
            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.mc.addItem(f, g - e);
                e += (h - g);
            }
        }
        fl(a) {
            if (isNaN_(a)) {
                return null;
            }
            let ticks_ = truncate(a);
            let b = (new Date(ticks_));
            let c = this.e8(b);
            if (c == null) {
                return null;
            }
            return c.toString();
        }
        e8(a) {
            if (!(typeCast(Date_$type, a) !== null)) {
                return super.e8(a);
            }
            let b = dateMinValue();
            let c = false;
            if (this.m0 != null) {
                if (typeCast(Date_$type, this.m0) !== null) {
                    b = this.m0;
                    c = true;
                }
            }
            let d = TimeXAxis.mz(a, c, b, this.mo, this.nc, this.labelFormats, this.et);
            return d == null ? super.e8(a) : d;
        }
        static mz(a, b, c, d, e, f, g) {
            let h = null;
            if (e == (0)) {
                return null;
            }
            let i = 0;
            if (b) {
                i = TimeXAxis.mp(a, c);
            }
            let j;
            if (f == null || f.count == 0) {
                j = TimeXAxis.m3(e, i, d);
            }
            else {
                for (let k of fromEnum(f)) {
                    if (k.o > e) {
                        continue;
                    }
                    if (h == null || k.o > h.o) {
                        h = k;
                    }
                }
                if (h == null) {
                    return null;
                }
                switch (i) {
                    case 3:
                        if (h.h != null) {
                            j = h.h;
                        }
                        else if (h.j != null) {
                            j = h.j;
                        }
                        else if (h.l != null) {
                            j = h.l;
                        }
                        else {
                            j = h.e;
                        }
                        break;
                    case 2:
                        if (h.j != null) {
                            j = h.j;
                        }
                        else if (h.l != null) {
                            j = h.l;
                        }
                        else {
                            j = h.e;
                        }
                        break;
                    case 1:
                        if (h.l != null) {
                            j = h.l;
                        }
                        else {
                            j = h.e;
                        }
                        break;
                    default:
                        j = h.e;
                        break;
                }
            }
            return dateToStringFormat(a, j, g);
        }
        static mp(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_k9() {
            return super.get_k9() || (this.intervals != null && this.intervals.count > 0);
        }
        set_k9(a) {
            super.set_k9(a);
        }
        get intervals() {
            return this.mj;
        }
        m2(a, b) {
            return TimeXAxis.m3(this.nc, a, b);
        }
        static m3(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 1: return "MMM";
                }
                return "MMM yyyy";
            }
            ;
            if (a > timeSpanInit3(4, 0, 0, 0)) {
                switch (b) {
                    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 md() {
            if (TimeXAxis.mb == null) {
                TimeXAxis.mb = ((() => {
                    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.mb;
        }
        mh() {
            if (this.cq && (this.ay == null || this.ay.angle == 0)) {
                let a = this.ea();
                let b = this.i9.width;
                let c = truncate(Math.floor(b / a));
                let d = Number.MAX_VALUE;
                let e = c == 0 ? d : timeSpanFromTicks((intDivide(timeSpanTicks(this.nc), c)));
                let f = null;
                for (let g of fromEnum(TimeXAxis.md())) {
                    f = g.value;
                    if (g.key > e) {
                        break;
                    }
                }
                let h = this.mg;
                if (h != f) {
                    this.hf();
                }
                this.mg = f;
                return f;
            }
            let i = this.nc;
            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;
            })());
        }
        mi() {
            if (this.intervals == null || this.intervals.count == 0) {
                return this.mh();
            }
            if (this.nc == (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.nc) {
                    continue;
                }
                if (a == null || b.k > a.k) {
                    a = b;
                }
            }
            return a == null ? this.mh() : a;
        }
        hc(a) {
            super.hc(a);
            let b = this.bh != null ? this.bh.n2 : Rect.empty;
            let c = !b.isEmpty ? this.i9 : Rect.empty;
            let d = this.i4();
            let e = this.i3();
            let f = new ScalerParams(0, b, c, this.ca, d);
            if (this.k5 == null && !this.lb() && !this.lc()) {
                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.hg(g, h, b, c, d, c.top, c.bottom);
                        g = j.p0;
                        h = j.p1;
                    }
                }
                if (isNaN_(g)) {
                    g = 0;
                }
                this.gv(this.a4.ay(), g, c, this.a4.e(), true);
                this.av.a9 = h;
                let k = truncate(Math.ceil(e.right));
                let l = truncate(Math.floor(e.left));
                let m = this.a4.a1();
                let n = this.a4.f();
                let o = this.a4.az();
                this.l6();
                let p = new List$1(Date_$type, 1, this.mq());
                let q = new List$1(Number_$type, 0);
                for (let r = 0; r < p.count; r++) {
                    q.add(p._inner[r].getTime());
                }
                this.gs(q, 0, q.count, f);
                this.m0 = 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.hm(m, u, w, c);
                        }
                        this.hl(o, u, c, n, false);
                        this.ju.add(u);
                    }
                    if (v >= l && v <= k) {
                        let x = this.e8(t);
                        this.m0 = t;
                        if (x != null) {
                            this.cx.add1(x);
                            this.cy.add(new LabelPosition(u));
                        }
                    }
                }
                this.m0 = 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.it();
                }
            }
            this.av.a2 = this.cx;
            this.av.a3 = this.cy;
            this.ku();
        }
        mq() {
            let a = this.bh != null ? this.bh.n2 : Rect.empty;
            let b = !a.isEmpty ? this.i9 : Rect.empty;
            let c = this.i4();
            let d = this.i3();
            let e = new ScalerParams(0, a, b, this.ca, c);
            let f = this.mi();
            let g = this.visibleMinimum;
            if (!this.lc() && 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.ms(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;
        }
        ms(a) {
            if (this.mc == null) {
                return new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
            }
            for (let b of fromEnum(this.mc)) {
                if (b.key.d <= a && b.key.c >= a) {
                    return b;
                }
            }
            return new KeyValuePair$2(TimeAxisBreak.$, Number_$type);
        }
        get visibleMinimum() {
            return this.mu;
        }
        set visibleMinimum(a) {
            this.mu = a;
        }
        get visibleMaximum() {
            return this.mt;
        }
        set visibleMaximum(a) {
            this.mt = a;
        }
        l6() {
            super.l6();
            if (this.bh == null || !Extensions.b(this.bh.oh)) {
                return;
            }
            let a = new ScalerParams(0, this.bh.n2, this.bh.oh, this.ca, this.bh.n6);
            let b = this.bh.oh.left;
            let c = this.bh.oh.right;
            if (this.categoryMode != 0) {
                let d = this.getCategorySize(a.e, a.d, a.c);
                b += d / 2;
                c -= d / 2;
            }
            let e = truncate(this.d1(b, a));
            let f = truncate(this.d1(c, a));
            if (e < 0 || f < 0) {
                this.nc = (0);
                return;
            }
            e = Math.min(dateMaxValue().getTime(), e);
            f = Math.min(dateMaxValue().getTime(), f);
            let g = dateFromTicks(Math.min(e, f));
            let h = dateFromTicks(Math.max(e, f));
            let i = +(this.visibleMinimum) != +g || +(this.visibleMaximum) != +h;
            this.visibleMinimum = g;
            this.visibleMaximum = h;
            if (i && this.visibleRangeChanged != null) {
                this.visibleRangeChanged(this, EventArgs.empty);
            }
            this.nc = +(this.visibleMaximum) - +(this.visibleMinimum);
        }
        j1(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.k5, b.i$b);
            let ticks_ = a;
            let d = (new Date(ticks_));
            let e = this.lp(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.oi, this.i9, this.ca, this.bh.n6);
            this.startCursor();
            let l = this.dy(i.getTime(), k);
            let m = this.dy(a, k);
            let n = this.dy(j.getTime(), k);
            this.resetCursor();
            if (i < this.visibleMinimum && j <= this.visibleMaximum) {
                return this.le._inner[h];
            }
            if (j > this.visibleMaximum && i >= this.visibleMinimum) {
                return this.le._inner[g];
            }
            if (Math.abs(l - m) < Math.abs(n - m)) {
                return this.le._inner[g];
            }
            else {
                return this.le._inner[h];
            }
        }
        nf(a, b) {
            this.ne();
            this.nd();
            if (this.av != null) {
                this.av.ak = this.breaks.count > 0;
            }
            this.hb(false);
            for (let c of fromEnum(this.cw())) {
                c.jl(false);
            }
        }
        nh(a, b) {
            this.hb(false);
        }
        ng(a, b) {
            this.hb(false);
        }
        get_b5() {
            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.nc != (0)) {
                let d = timeSpanFromTicks(truncate((timeSpanTicks(this.nc) * (a.width / (this.bh != null ? this.bh.n2.width : 1)))));
                let e = timeSpanTicks(d) / timeSpanTicks(this.na);
                let f = b.width / 4;
                return Math.min(f, b.width / (e + 1));
            }
            return super.getCategorySize(a, b, c);
        }
        static m9(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;
        }
        m8() {
            if (this.k5 == null || this.k5.count < 2 || this.le == null) {
                return (0);
            }
            return TimeXAxis.m9((a) => this.k5.item(this.le._inner[a]), this.k5.count);
        }
        l2() {
            super.l2();
            this.na = this.m8();
        }
        static m5(a) {
            if (a >= timeSpanFromDays(1)) {
                return "D";
            }
            return "g";
        }
        itemLabelFormat() {
            return TimeXAxis.m5(this.na);
        }
        lo(a, b, c, d) {
            return this.ln(this.visibleMinimum);
        }
        lr(a, b, c, d) {
            return this.lq(this.visibleMaximum);
        }
        get isVertical() {
            return this.ch;
        }
        j$c(a, b) {
            return this.d1.apply(this, arguments);
        }
        j$b(a, b) {
            return this.dy.apply(this, arguments);
        }
        j$d(a, b, c, d, e) {
            this.gr.apply(this, arguments);
        }
        j$e(a, b, c, d) {
            this.gs.apply(this, arguments);
        }
        j$f(a, b, c, d) {
            this.gt.apply(this, arguments);
        }
        get j$a() {
            return this.ca;
        }
        get i$a() {
            return this.b7;
        }
    }
    TimeXAxis.$t = /*@__PURE__*/ markType(TimeXAxis, 'TimeXAxis', TimeAxisBase.$, [ITimeRangeSelectorAxis_$type]);
    TimeXAxis.mb = null;
    return TimeXAxis;
})();
//# sourceMappingURL=TimeXAxis.js.map
