/*
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 { 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 } from "igniteui-react-core";
/**
 * @hidden
 */
export let OrdinalTimeXAxis = /*@__PURE__*/ (() => {
    class OrdinalTimeXAxis extends CategoryXAxis {
        constructor() {
            super();
            this.l0 = dateMaxValue();
            this.lz = dateMinValue();
            this.l4 = dateMaxValue();
            this.l3 = dateMinValue();
            this.l9 = null;
            this.lv = 0;
            this.lx = null;
            this.lt = null;
            this.mh = 0;
            this.l2 = dateMinValue();
            this.l1 = dateMaxValue();
            this.visibleRangeChanged = null;
            FastItemDateTimeColumn.o();
            this.lt = new TimeAxisLabelFormatCollection();
            let a = this.lu;
            a.collectionChanged = delegateCombine(a.collectionChanged, runOn(this, this.mj));
            this.lj = 0;
        }
        d0(a, b, c) {
            return this.dy(a, new ScalerParams(0, b, c, this.ca, this.i4()));
        }
        dz(a, b, c) {
            return this.dy(a, b);
        }
        dy(a, b) {
            let c = this.li;
            let d = this.lj;
            let e = this.li - this.lj;
            let f = e >= 1 ? (a - d) / (c - d) : e == 0 ? 0.5 : NaN;
            if (this.cb) {
                f = 1 - f;
            }
            let g = b.d;
            let h = b.e;
            return g.left + g.width * (f - h.left) / h.width;
        }
        gr(a, b, c, d, e) {
            let f = this.k4(a);
            let g = f != null;
            for (let h = 0; h < b.count; h++) {
                for (let i = c; i < d; i++) {
                    let j = g ? f[i] : a.item(i);
                    j[h] = this.dy(j[h], e);
                }
            }
        }
        gs(a, b, c, d) {
            for (let e = b; e < c; e++) {
                a.item(e, this.dy(a.item(e), d));
            }
        }
        d3(a, b, c) {
            return this.d1(a, new ScalerParams(0, b, this.i9, this.ca, this.i4()));
        }
        getUnscaledValue3(a, b, c, d) {
            return this.d1(a, new ScalerParams(0, b, this.i9, this.ca, this.i4()));
        }
        d1(a, b) {
            let c = b.e;
            let d = b.d;
            let e = c.left + (a - d.left) * c.width / d.width;
            if (this.cb) {
                e = 1 - e;
            }
            return this.lj + e * (this.li - this.lj);
        }
        d2(a, b, c) {
            return this.d1(a, b);
        }
        gt(a, b, c, d) {
            for (let e = b; e < c; e++) {
                a.item(e, this.d1(a.item(e), d));
            }
        }
        gz(a, b, c, d) {
            super.gz(a, b, c, d);
            switch (b) {
                case "FastItemsSource":
                    let e = typeCast(IFastItemsSource_$type, c);
                    if (e != null) {
                        e.deregisterColumn(this.ly);
                        this.ly = null;
                    }
                    if (this.jn != null) {
                        this.ly = TimeAxisBase.k7(this.dateTimeMemberPath, this);
                    }
                    break;
                case "DateTimeMemberPath":
                    if (this.jn != null) {
                        this.jn.deregisterColumn(this.ly);
                        this.ly = TimeAxisBase.k7(this.dateTimeMemberPath, this);
                    }
                    break;
                case "DateTimeColumn":
                    this.cn();
                    this.mh = this.mg();
                    break;
                case "MinimumValue":
                case "MaximumValue":
                    this.cn();
                    this.ha();
                    break;
                case "LabellingMode":
                    this.ha();
                    break;
            }
        }
        get actualMinimumValue() {
            return this.l0;
        }
        set actualMinimumValue(a) {
            this.l0 = a;
        }
        get actualMaximumValue() {
            return this.lz;
        }
        set actualMaximumValue(a) {
            this.lz = a;
        }
        get visibleMinimum() {
            return this.l4;
        }
        set visibleMinimum(a) {
            this.l4 = a;
        }
        get visibleMaximum() {
            return this.l3;
        }
        set visibleMaximum(a) {
            this.l3 = a;
        }
        mk() {
            if (this.ly == null || this.ly.count == 0 || this.ly.count < this.lj - 1) {
                this.actualMinimumValue = dateMinValue();
                this.actualMaximumValue = dateMaxValue();
                return;
            }
            let a = Math.max(0, Math.min(this.lj, this.ly.count - 1));
            let b = Math.max(0, Math.min(this.li, this.ly.count - 1));
            let c = +(this.actualMinimumValue) != +(this.ly.item(a)) || +(this.actualMaximumValue) != +(this.ly.item(b));
            if (c) {
                let d = this.actualMinimumValue;
                let e = this.actualMaximumValue;
                this.actualMinimumValue = this.ly.item(a);
                this.actualMaximumValue = this.ly.item(b);
                this.ml();
            }
        }
        ml() {
            if (this.ly == null || this.ly.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.i3();
            let c = new ScalerParams(1, this.bh.oi, this.bh.oh, this.ca);
            let d = truncate(Math.ceil(this.d1(b.left, c)));
            let e = truncate(Math.ceil(this.d1(b.right, c)));
            let f = d >= 0 && d < this.ly.count ? this.ly.item(d) : this.actualMinimumValue;
            let g = e >= 0 && e < this.ly.count ? this.ly.item(e) : this.actualMaximumValue;
            let h = +(this.visibleMinimum) != +f || +(this.visibleMaximum) != +g;
            this.visibleMinimum = f;
            this.visibleMaximum = g;
            if (h && this.visibleRangeChanged != null) {
                this.visibleRangeChanged(this, EventArgs.empty);
            }
        }
        get dateTimeMemberPath() {
            return this.l9;
        }
        set dateTimeMemberPath(a) {
            let b = this.dateTimeMemberPath;
            if (a != b) {
                this.l9 = a;
                this.g5("DateTimeMemberPath", b, this.dateTimeMemberPath);
            }
        }
        get lw() {
            return this.lv;
        }
        set lw(a) {
            let b = this.lw;
            if (a != b) {
                this.lv = a;
                this.g5("LabellingMode", enumGetBox(TimeAxisLabellingMode_$type, b), enumGetBox(TimeAxisLabellingMode_$type, this.lw));
            }
        }
        get ly() {
            return this.lx;
        }
        set ly(a) {
            if (this.lx != a) {
                let b = this.lx;
                this.lx = a;
                this.g5("DateTimeColumn", b, this.lx);
            }
        }
        ho(a, b) {
            super.ho(a, b);
            this.ml();
        }
        getWindowRectForSelection(a, b) {
            if (this.ly == null) {
                return Rect.empty;
            }
            let c = a > b;
            let d = c ? b : a;
            let e = c ? a : b;
            let f = -1;
            while (++f < this.ly.count && this.ly.item(f) < d) {
            }
            let g = this.ly.count;
            while (--g >= 0 && this.ly.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.n6);
            let i = this.dy(f, h);
            let j = this.dy(g + 1, h);
            return new Rect(0, i, NaN, Math.max(0, j - i), NaN);
        }
        get lu() {
            return this.lt;
        }
        mj(a, b) {
            this.hb(false);
        }
        g1(a) {
            super.g1(a);
            this.dateTimeMemberPath = a;
        }
        e8(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.e8(a);
            }
            let b = dateMinValue();
            let c = false;
            if (this.lk != null) {
                if (typeCast(Date_$type, this.lk) !== null) {
                    b = this.lk;
                    c = true;
                }
            }
            let d = TimeXAxis.mz(a, c, b, this.lw, this.mi, this.lu, this.et);
            return d == null ? super.e8(a) : d;
        }
        fl(a) {
            let b = 0;
            if (this.categoryMode == 0) {
                b = truncate(Math.round(a));
            }
            else {
                b = truncate(Math.floor(a));
            }
            if (b < 0 || b > this.j8 - 1) {
                return super.fl(a);
            }
            let c = this.ly.item(b);
            let d = this.e8(c);
            if (d == null) {
                return null;
            }
            return d.toString();
        }
        get mi() {
            return +(this.visibleMaximum) - +(this.visibleMinimum);
        }
        k6() {
            return this.ly;
        }
        hn(a, b) {
            super.hn(a, b);
            this.ml();
        }
        lc(a, b) {
            let c = this.categoryMode == 0 ? 0 : 0.5;
            return super.lc(a + c, b);
        }
        lb(a, b, c, d) {
            return b;
        }
        mg() {
            if (this.ly == null || this.ly.count < 2) {
                return (0);
            }
            return TimeXAxis.m9((a) => this.ly.item(a), this.ly.count);
        }
        itemLabelFormat() {
            return TimeXAxis.m5(this.mh);
        }
        get minimumValue() {
            return this.l2;
        }
        set minimumValue(a) {
            let b = this.minimumValue;
            if (+a != +b) {
                this.l2 = a;
                this.gz(this, "MinimumValue", b, this.minimumValue);
            }
        }
        get maximumValue() {
            return this.l1;
        }
        set maximumValue(a) {
            let b = this.maximumValue;
            if (+a != +b) {
                this.l1 = a;
                this.gz(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.jn == null || this.ly == null) {
                return false;
            }
            let a = this.lj;
            if (+(this.minimumValue) != +(dateMinValue())) {
                let b = -1;
                while (b++ <= this.ly.count) {
                    if (this.ly.item(b) >= this.minimumValue) {
                        break;
                    }
                }
                a = b;
            }
            let c = this.categoryMode == 0 ? this.jn.count - 1 : this.jn.count;
            if (+(this.maximumValue) != +(dateMaxValue())) {
                let d = this.jn.count;
                while (d-- > 0) {
                    if (this.ly.item(d) <= this.maximumValue) {
                        break;
                    }
                }
                c = d;
            }
            if (a != this.lj || c != this.li) {
                let e = new AxisRangeChangedEventArgs(0, this.lj, a, this.li, c);
                this.lj = a;
                this.li = c;
                this.g6(e);
                this.mk();
                this.kj();
                return true;
            }
            return false;
        }
        ks(a) {
            super.ks(a);
            this.co(true);
        }
        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;
        }
    }
    OrdinalTimeXAxis.$t = /*@__PURE__*/ markType(OrdinalTimeXAxis, 'OrdinalTimeXAxis', CategoryXAxis.$, [ITimeRangeSelectorAxis_$type]);
    return OrdinalTimeXAxis;
})();
//# sourceMappingURL=OrdinalTimeXAxis.js.map
