/*
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 { FastItemDateTimeColumn } from "igniteui-react-core";
import { CategoryXAxis } from "./CategoryXAxis";
import { ITimeRangeSelectorAxis_$type } from "./ITimeRangeSelectorAxis";
import { TimeAxisLabellingMode_$type } from "./TimeAxisLabellingMode";
import { TimeAxisLabelFormatCollection } from "./TimeAxisLabelFormatCollection";
import { Rect } from "igniteui-react-core";
import { ScalerParams } from "./ScalerParams";
import { NumericScaler } from "./NumericScaler";
import { EventArgs, runOn, delegateCombine, typeCast, enumGetBox, Date_$type, markType } from "igniteui-react-core";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { TimeAxisBase } from "./TimeAxisBase";
import { TimeXAxis } from "./TimeXAxis";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { truncate } from "igniteui-react-core";
import { dateMaxValue, dateMinValue, dateAdd, dateSubtract } from "igniteui-react-core";
import { timeSpanFromMilliseconds, timeSpanTotalMilliseconds } from "igniteui-react-core";
/**
 * @hidden
 */
export let OrdinalTimeXAxis = /*@__PURE__*/ (() => {
    class OrdinalTimeXAxis extends CategoryXAxis {
        constructor() {
            super();
            this.l1 = dateMaxValue();
            this.l0 = dateMinValue();
            this.l7 = dateMaxValue();
            this.l6 = dateMinValue();
            this.l3 = dateMaxValue();
            this.l2 = dateMinValue();
            this.mh = null;
            this.mg = null;
            this.lw = 0;
            this.ly = null;
            this.lu = null;
            this.mq = 0;
            this.l5 = dateMinValue();
            this.l4 = dateMaxValue();
            this.visibleRangeChanged = null;
            FastItemDateTimeColumn.o();
            this.lu = new TimeAxisLabelFormatCollection();
            let a = this.lv;
            a.collectionChanged = delegateCombine(a.collectionChanged, runOn(this, this.ms));
            this.lk = 0;
        }
        d1(a, b, c) {
            return this.dz(a, new ScalerParams(0, b, c, this.ca, this.i5()));
        }
        d0(a, b, c) {
            return this.dz(a, b);
        }
        dz(a, b) {
            if (!b.c.isEmpty) {
                let c = this.me(a, NumericScaler.ac, b.c);
                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.me(a, b.e, b.d);
        }
        me(a, b, c) {
            let d = this.lj;
            let e = this.lk;
            let f = this.lj - this.lk;
            let g = f >= 1 ? (a - e) / (d - e) : f == 0 ? 0.5 : NaN;
            if (this.cb) {
                g = 1 - g;
            }
            return c.left + c.width * (g - b.left) / b.width;
        }
        gs(a, b, c, d, e) {
            let f;
            let g = e.e;
            let h = e.d;
            let i = e.c;
            let j = e.a;
            let k = !i.isEmpty;
            let l = i.left;
            let m = i.width;
            let n = g.left;
            let o = g.width;
            let p = h.left;
            let q = h.width;
            let r = 0;
            let s = 1;
            let t = this.lj;
            let u = this.lk;
            let v = this.lj - this.lk;
            let w = this.k5(a);
            let x = w != null;
            for (let y = 0; y < b.count; y++) {
                let z = b.item(y);
                for (let aa = c; aa < d; aa++) {
                    f = x ? w[aa] : a.item(aa);
                    if (k) {
                        let ab = v >= 1 ? (f[z] - u) / (t - u) : v == 0 ? 0.5 : NaN;
                        if (j) {
                            ab = 1 - ab;
                        }
                        ab = l + m * (ab - r) / s;
                        let ac = (ab - p) / q;
                        ac = p + q * (ac - n) / o;
                        f[z] = ac;
                    }
                    else {
                        let ad = v >= 1 ? (f[z] - u) / (t - u) : v == 0 ? 0.5 : NaN;
                        if (j) {
                            ad = 1 - ad;
                        }
                        ad = p + q * (ad - n) / o;
                        f[z] = ad;
                    }
                }
            }
        }
        gt(a, b, c, d) {
            for (let e = b; e < c; e++) {
                a.item(e, this.dz(a.item(e), d));
            }
        }
        d4(a, b, c) {
            return this.d2(a, new ScalerParams(0, b, this.ja, this.ca, this.i5()));
        }
        getUnscaledValue3(a, b, c, d) {
            return this.d2(a, new ScalerParams(0, b, this.ja, this.ca, this.i5()));
        }
        d2(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.mf(c, NumericScaler.ac, b.c);
                return c;
            }
            return this.mf(a, b.e, b.d);
        }
        mf(a, b, c) {
            let d = b.left + (a - c.left) * b.width / c.width;
            if (this.cb) {
                d = 1 - d;
            }
            return this.lk + d * (this.lj - this.lk);
        }
        d3(a, b, c) {
            return this.d2(a, b);
        }
        gu(a, b, c, d) {
            for (let e = b; e < c; e++) {
                a.item(e, this.d2(a.item(e), d));
            }
        }
        g0(a, b, c, d) {
            super.g0(a, b, c, d);
            switch (b) {
                case "FastItemsSource":
                    let e = typeCast(IFastItemsSource_$type, c);
                    if (e != null) {
                        e.deregisterColumn(this.lz);
                        this.lz = null;
                    }
                    if (this.jo != null) {
                        this.lz = TimeAxisBase.k8(this.dateTimeMemberPath, this);
                    }
                    break;
                case "DateTimeMemberPath":
                    if (this.jo != null) {
                        this.jo.deregisterColumn(this.lz);
                        this.lz = TimeAxisBase.k8(this.dateTimeMemberPath, this);
                    }
                    break;
                case "DateTimeColumn":
                    this.cn();
                    this.mq = this.mp();
                    break;
                case "MinimumValue":
                case "MaximumValue":
                    this.cn();
                    this.hb();
                    break;
                case "LabellingMode":
                    this.hb();
                    break;
            }
        }
        get actualMinimumValue() {
            return this.l1;
        }
        set actualMinimumValue(a) {
            this.l1 = a;
        }
        get actualMaximumValue() {
            return this.l0;
        }
        set actualMaximumValue(a) {
            this.l0 = a;
        }
        get visibleMinimum() {
            return this.l7;
        }
        set visibleMinimum(a) {
            this.l7 = a;
        }
        get visibleMaximum() {
            return this.l6;
        }
        set visibleMaximum(a) {
            this.l6 = a;
        }
        get mb() {
            return this.l3;
        }
        set mb(a) {
            this.l3 = a;
        }
        get ma() {
            return this.l2;
        }
        set ma(a) {
            this.l2 = a;
        }
        mt() {
            if (this.lz == null || this.lz.count == 0 || this.lz.count < this.lk - 1) {
                this.actualMinimumValue = dateMinValue();
                this.actualMaximumValue = dateMaxValue();
                return;
            }
            let a = Math.max(0, Math.min(this.lk, this.lz.count - 1));
            let b = Math.max(0, Math.min(this.lj, this.lz.count - 1));
            let c = +(this.actualMinimumValue) != +(this.lz.item(a)) || +(this.actualMaximumValue) != +(this.lz.item(b));
            if (c) {
                let d = this.actualMinimumValue;
                let e = this.actualMaximumValue;
                this.actualMinimumValue = this.lz.item(a);
                this.actualMaximumValue = this.lz.item(b);
                this.mu();
            }
        }
        mu() {
            if (this.lz == null || this.lz.count == 0 || this.bh == null) {
                let a = +(this.visibleMinimum) != +(this.actualMinimumValue) || +(this.visibleMaximum) != +(this.actualMaximumValue);
                this.visibleMinimum = this.actualMinimumValue;
                this.visibleMaximum = this.actualMaximumValue;
                if (a && this.visibleRangeChanged != null) {
                    this.visibleRangeChanged(this, EventArgs.empty);
                }
                return;
            }
            let b = this.i4();
            let c = new ScalerParams(1, this.bh.o8, this.bh.o7, this.ca);
            c.c = this.i5();
            let d = this.d2(b.left, c);
            let e = this.d2(b.right, c);
            let f = truncate(Math.floor(d));
            let g = truncate(Math.ceil(e));
            let h = f >= 0 && f < this.lz.count ? this.lz.item(f) : this.actualMinimumValue;
            let i = g >= 0 && g < this.lz.count ? this.lz.item(g) : this.actualMaximumValue;
            let j = h;
            let k = i;
            if (d > f) {
                let l = f + 1;
                let m = l >= 0 && l < this.lz.count ? this.lz.item(l) : i;
                let n = dateAdd(+h, +(timeSpanFromMilliseconds(timeSpanTotalMilliseconds((+m - +h)) * (d - f))));
                j = n;
            }
            if (e < g) {
                let o = g - 1;
                let p = o >= 0 && o < this.lz.count ? this.lz.item(o) : h;
                let q = dateSubtract(+i, +(timeSpanFromMilliseconds(timeSpanTotalMilliseconds((+i - +p)) * (g - e))));
                k = q;
            }
            this.mb = j;
            this.ma = k;
            let r = +(this.visibleMinimum) != +h || +(this.visibleMaximum) != +i;
            this.visibleMinimum = h;
            this.visibleMaximum = i;
            if (r && this.visibleRangeChanged != null) {
                this.visibleRangeChanged(this, EventArgs.empty);
            }
        }
        hd(a) {
            let b = TimeXAxis.m7(this.actualMinimumValue, false, this.actualMinimumValue, this.lx, this.mo, this.lv, this.eu);
            if (b != this.mh && this.cq) {
                this.hg();
            }
            this.mh = b;
            super.hd(a);
        }
        get dateTimeMemberPath() {
            return this.mg;
        }
        set dateTimeMemberPath(a) {
            let b = this.dateTimeMemberPath;
            if (a != b) {
                this.mg = a;
                this.g6("DateTimeMemberPath", b, this.dateTimeMemberPath);
            }
        }
        get lx() {
            return this.lw;
        }
        set lx(a) {
            let b = this.lx;
            if (a != b) {
                this.lw = a;
                this.g6("LabellingMode", enumGetBox(TimeAxisLabellingMode_$type, b), enumGetBox(TimeAxisLabellingMode_$type, this.lx));
            }
        }
        get lz() {
            return this.ly;
        }
        set lz(a) {
            if (this.ly != a) {
                let b = this.ly;
                this.ly = a;
                this.g6("DateTimeColumn", b, this.ly);
            }
        }
        hp(a, b) {
            super.hp(a, b);
            this.mu();
        }
        getWindowRectForSelection(a, b) {
            if (this.lz == null) {
                return Rect.empty;
            }
            let c = a > b;
            let d = c ? b : a;
            let e = c ? a : b;
            let f = -1;
            while (++f < this.lz.count && this.lz.item(f) < d) {
            }
            let g = this.lz.count;
            while (--g >= 0 && this.lz.item(g) > e) {
            }
            let h = new ScalerParams(0, new Rect(0, 0, 0, 1, 1), new Rect(0, 0, 0, 1, 1), this.ca, this.bh.ow);
            let i = this.dz(f, h);
            let j = this.dz(g + 1, h);
            return new Rect(0, i, NaN, Math.max(0, j - i), NaN);
        }
        get lv() {
            return this.lu;
        }
        ms(a, b) {
            this.hc(false);
        }
        g2(a) {
            super.g2(a);
            this.dateTimeMemberPath = a;
        }
        e9(a) {
            if (this.at != null) {
                return this.at(a);
            }
            if (this.ah != null) {
                return this.ah.i(a);
            }
            if (!(typeCast(Date_$type, a) !== null)) {
                return super.e9(a);
            }
            let b = dateMinValue();
            let c = false;
            if (this.ll != null) {
                if (typeCast(Date_$type, this.ll) !== null) {
                    b = this.ll;
                    c = true;
                }
            }
            let d = TimeXAxis.m2(a, c, b, this.lx, this.mo, this.lv, this.eu);
            return d == null ? super.e9(a) : d;
        }
        fm(a) {
            let b = 0;
            if (this.categoryMode == 0) {
                b = truncate(Math.round(a));
            }
            else {
                b = truncate(Math.floor(a));
            }
            if (b < 0 || b > this.j9 - 1) {
                return super.fm(a);
            }
            let c = this.lz.item(b);
            let d = this.e9(c);
            if (d == null) {
                return null;
            }
            return d.toString();
        }
        get mr() {
            return +(this.visibleMaximum) - +(this.visibleMinimum);
        }
        get mo() {
            return +(this.ma) - +(this.mb);
        }
        k7() {
            return this.lz;
        }
        ho(a, b) {
            super.ho(a, b);
            this.mu();
        }
        ld(a, b) {
            let c = this.categoryMode == 0 ? 0 : 0.5;
            return super.ld(a + c, b);
        }
        lc(a, b, c, d) {
            return b;
        }
        mp() {
            if (this.lz == null || this.lz.count < 2) {
                return (0);
            }
            return TimeXAxis.nd((a) => this.lz.item(a), this.lz.count);
        }
        itemLabelFormat() {
            return TimeXAxis.m9(this.mq);
        }
        get minimumValue() {
            return this.l5;
        }
        set minimumValue(a) {
            let b = this.minimumValue;
            if (+a != +b) {
                this.l5 = a;
                this.g0(this, "MinimumValue", b, this.minimumValue);
            }
        }
        get maximumValue() {
            return this.l4;
        }
        set maximumValue(a) {
            let b = this.maximumValue;
            if (+a != +b) {
                this.l4 = a;
                this.g0(this, "MaximumValue", b, this.maximumValue);
            }
        }
        cp() {
            if (+(this.minimumValue) == +(dateMaxValue()) || +(this.maximumValue) == +(dateMinValue())) {
                return super.cp();
            }
            if (this.ci && this.cq) {
                this.bb = this.ba();
            }
            if (this.jo == null || this.lz == null) {
                return false;
            }
            let a = this.lk;
            if (+(this.minimumValue) != +(dateMinValue())) {
                let b = -1;
                while (b++ <= this.lz.count) {
                    if (this.lz.item(b) >= this.minimumValue) {
                        break;
                    }
                }
                a = b;
            }
            let c = this.categoryMode == 0 ? this.jo.count - 1 : this.jo.count;
            if (+(this.maximumValue) != +(dateMaxValue())) {
                let d = this.jo.count;
                while (d-- > 0) {
                    if (this.lz.item(d) <= this.maximumValue) {
                        break;
                    }
                }
                c = d;
            }
            if (a != this.lk || c != this.lj) {
                let e = new AxisRangeChangedEventArgs(0, this.lk, a, this.lj, c);
                this.lk = a;
                this.lj = c;
                this.g7(e);
                this.mt();
                this.kk();
                return true;
            }
            return false;
        }
        kt(a) {
            super.kt(a);
            this.co(true);
        }
        get isVertical() {
            return this.ch;
        }
        j$c(a, b) {
            return this.d2.apply(this, arguments);
        }
        j$b(a, b) {
            return this.dz.apply(this, arguments);
        }
        j$d(a, b, c, d, e) {
            this.gs.apply(this, arguments);
        }
        j$e(a, b, c, d) {
            this.gt.apply(this, arguments);
        }
        j$f(a, b, c, d) {
            this.gu.apply(this, arguments);
        }
        get j$a() {
            return this.ca;
        }
    }
    OrdinalTimeXAxis.$t = /*@__PURE__*/ markType(OrdinalTimeXAxis, 'OrdinalTimeXAxis', CategoryXAxis.$, [ITimeRangeSelectorAxis_$type]);
    return OrdinalTimeXAxis;
})();
//# sourceMappingURL=OrdinalTimeXAxis.js.map
