/*
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 { __extends } from "tslib";
import { FastItemDateTimeColumn } from "igniteui-react-core";
import { CategoryXAxis } from "./CategoryXAxis";
import { ITimeRangeSelectorAxis_$type } from "./ITimeRangeSelectorAxis";
import { IOrdinalAxis_$type } from "./IOrdinalAxis";
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
 */
var OrdinalTimeXAxis = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(OrdinalTimeXAxis, _super);
    function OrdinalTimeXAxis() {
        var _this = _super.call(this) || this;
        _this.np = dateMaxValue();
        _this.no = dateMinValue();
        _this.nv = dateMaxValue();
        _this.nu = dateMinValue();
        _this.nr = dateMaxValue();
        _this.nq = dateMinValue();
        _this.n5 = null;
        _this.n4 = null;
        _this.nk = 0;
        _this.nm = null;
        _this.ni = null;
        _this.oe = 0;
        _this.nt = dateMinValue();
        _this.ns = dateMaxValue();
        _this.visibleRangeChanged = null;
        FastItemDateTimeColumn.o();
        _this.ni = new TimeAxisLabelFormatCollection();
        var a = _this.nj;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.og));
        _this.mw = 0;
        return _this;
    }
    OrdinalTimeXAxis.prototype.el = function (a, b, c) {
        return this.ej(a, new ScalerParams(0, b, c, this.ch, this.j8()));
    };
    OrdinalTimeXAxis.prototype.ek = function (a, b, c) {
        return this.ej(a, b);
    };
    OrdinalTimeXAxis.prototype.ej = function (a, b) {
        if (!b.c.isEmpty) {
            var c = this.n2(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.n2(a, b.e, b.d);
    };
    OrdinalTimeXAxis.prototype.n2 = function (a, b, c) {
        var d = this.mv;
        var e = this.mw;
        var f = this.mv - this.mw;
        var g = f >= 1 ? (a - e) / (d - e) : f == 0 ? 0.5 : NaN;
        if (this.ci) {
            g = 1 - g;
        }
        return c.left + c.width * (g - b.left) / b.width;
    };
    OrdinalTimeXAxis.prototype.hm = function (a, b, c, d, e) {
        var f;
        var g = e.e;
        var h = e.d;
        var i = e.c;
        var j = e.a;
        var k = !i.isEmpty;
        var l = i.left;
        var m = i.width;
        var n = g.left;
        var o = g.width;
        var p = h.left;
        var q = h.width;
        var r = 0;
        var s = 1;
        var t = this.mv;
        var u = this.mw;
        var v = this.mv - this.mw;
        var w = this.mg(a);
        var x = w != null;
        for (var y = 0; y < b.count; y++) {
            var z = b.item(y);
            for (var aa = c; aa < d; aa++) {
                f = x ? w[aa] : a.item(aa);
                if (k) {
                    var ab = v >= 1 ? (f[z] - u) / (t - u) : v == 0 ? 0.5 : NaN;
                    if (j) {
                        ab = 1 - ab;
                    }
                    ab = l + m * (ab - r) / s;
                    var ac = (ab - p) / q;
                    ac = p + q * (ac - n) / o;
                    f[z] = ac;
                }
                else {
                    var 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;
                }
            }
        }
    };
    OrdinalTimeXAxis.prototype.hn = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.ej(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.eo = function (a, b, c) {
        return this.em(a, new ScalerParams(0, b, this.kd, this.ch, this.j8()));
    };
    OrdinalTimeXAxis.prototype.getUnscaledValue3 = function (a, b, c, d) {
        return this.em(a, new ScalerParams(0, b, this.kd, this.ch, this.j8()));
    };
    OrdinalTimeXAxis.prototype.em = function (a, b) {
        if (!b.c.isEmpty) {
            var c = b.e.left + b.e.width * (a - b.d.left) / b.d.width;
            c = (c * b.d.width) + b.d.left;
            c = this.n3(c, NumericScaler.ac, b.c);
            return c;
        }
        return this.n3(a, b.e, b.d);
    };
    OrdinalTimeXAxis.prototype.n3 = function (a, b, c) {
        var d = b.left + (a - c.left) * b.width / c.width;
        if (this.ci) {
            d = 1 - d;
        }
        return this.mw + d * (this.mv - this.mw);
    };
    OrdinalTimeXAxis.prototype.en = function (a, b, c) {
        return this.em(a, b);
    };
    OrdinalTimeXAxis.prototype.ho = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.em(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.hw = function (a, b, c, d) {
        _super.prototype.hw.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.nn);
                    this.nn = null;
                }
                if (this.kr != null) {
                    this.nn = TimeAxisBase.mj(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeMemberPath":
                if (this.kr != null) {
                    this.kr.deregisterColumn(this.nn);
                    this.nn = TimeAxisBase.mj(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeColumn":
                this.c1();
                this.oe = this.od();
                break;
            case "MinimumValue":
            case "MaximumValue":
                this.c1();
                this.h7();
                break;
            case "LabellingMode":
                this.h7();
                break;
        }
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMinimumValue", {
        get: function () {
            return this.np;
        },
        set: function (a) {
            this.np = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMaximumValue", {
        get: function () {
            return this.no;
        },
        set: function (a) {
            this.no = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMinimum", {
        get: function () {
            return this.nv;
        },
        set: function (a) {
            this.nv = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMaximum", {
        get: function () {
            return this.nu;
        },
        set: function (a) {
            this.nu = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "nz", {
        get: function () {
            return this.nr;
        },
        set: function (a) {
            this.nr = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "ny", {
        get: function () {
            return this.nq;
        },
        set: function (a) {
            this.nq = a;
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.oh = function () {
        if (this.nn == null || this.nn.count == 0 || this.nn.count < this.mw - 1) {
            this.actualMinimumValue = dateMinValue();
            this.actualMaximumValue = dateMaxValue();
            return;
        }
        var a = Math.max(0, Math.min(this.mw, this.nn.count - 1));
        var b = Math.max(0, Math.min(this.mv, this.nn.count - 1));
        var c = +(this.actualMinimumValue) != +(this.nn.item(a)) || +(this.actualMaximumValue) != +(this.nn.item(b));
        if (c) {
            var d = this.actualMinimumValue;
            var e = this.actualMaximumValue;
            this.actualMinimumValue = this.nn.item(a);
            this.actualMaximumValue = this.nn.item(b);
            this.oi();
        }
    };
    OrdinalTimeXAxis.prototype.oi = function () {
        if (this.nn == null || this.nn.count == 0 || this.bi == null) {
            var a = +(this.visibleMinimum) != +(this.actualMinimumValue) || +(this.visibleMaximum) != +(this.actualMaximumValue);
            this.visibleMinimum = this.actualMinimumValue;
            this.visibleMaximum = this.actualMaximumValue;
            this.nz = this.visibleMinimum;
            this.ny = this.visibleMaximum;
            if (a && this.visibleRangeChanged != null) {
                this.visibleRangeChanged(this, EventArgs.empty);
            }
            return;
        }
        var b = this.j7();
        var c = new ScalerParams(1, this.bi.t7, this.bi.t6, this.ch);
        c.c = this.j8();
        var d = this.em(b.left, c);
        var e = this.em(b.right, c);
        var f = truncate(Math.floor(d));
        var g = truncate(Math.ceil(e));
        var h = f >= 0 && f < this.nn.count ? this.nn.item(f) : this.actualMinimumValue;
        var i = g >= 0 && g < this.nn.count ? this.nn.item(g) : this.actualMaximumValue;
        var j = h;
        var k = i;
        if (d > f) {
            var l = f + 1;
            var m = l >= 0 && l < this.nn.count ? this.nn.item(l) : i;
            var n = dateAdd(+h, +(timeSpanFromMilliseconds(timeSpanTotalMilliseconds((+m - +h)) * (d - f))));
            j = n;
        }
        if (e < g) {
            var o = g - 1;
            var p = o >= 0 && o < this.nn.count ? this.nn.item(o) : h;
            var q = dateSubtract(+i, +(timeSpanFromMilliseconds(timeSpanTotalMilliseconds((+i - +p)) * (g - e))));
            k = q;
        }
        this.nz = j;
        this.ny = k;
        var r = +(this.visibleMinimum) != +h || +(this.visibleMaximum) != +i;
        this.visibleMinimum = h;
        this.visibleMaximum = i;
        if (r && this.visibleRangeChanged != null) {
            this.visibleRangeChanged(this, EventArgs.empty);
        }
    };
    OrdinalTimeXAxis.prototype.h9 = function (a) {
        var b = TimeXAxis.om(this.actualMinimumValue, false, this.actualMinimumValue, this.nl, this.oc, this.nj, this.fk);
        if (b != this.n5 && this.c4) {
            this.id();
        }
        this.n5 = b;
        _super.prototype.h9.call(this, a);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "dateTimeMemberPath", {
        get: function () {
            return this.n4;
        },
        set: function (a) {
            var b = this.dateTimeMemberPath;
            if (a != b) {
                this.n4 = a;
                this.h2("DateTimeMemberPath", b, this.dateTimeMemberPath);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "nl", {
        get: function () {
            return this.nk;
        },
        set: function (a) {
            var b = this.nl;
            if (a != b) {
                this.nk = a;
                this.h2("LabellingMode", enumGetBox(TimeAxisLabellingMode_$type, b), enumGetBox(TimeAxisLabellingMode_$type, this.nl));
            }
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.get_ck = function () {
        return true;
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "nn", {
        get: function () {
            return this.nm;
        },
        set: function (a) {
            if (this.nm != a) {
                var b = this.nm;
                this.nm = a;
                this.h2("DateTimeColumn", b, this.nm);
            }
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.iq = function (a, b) {
        _super.prototype.iq.call(this, a, b);
        this.oi();
    };
    OrdinalTimeXAxis.prototype.getWindowRectForSelection = function (a, b) {
        if (this.nn == null) {
            return Rect.empty;
        }
        var c = a > b;
        var d = c ? b : a;
        var e = c ? a : b;
        var f = -1;
        while (++f < this.nn.count && this.nn.item(f) < d) {
        }
        var g = this.nn.count;
        while (--g >= 0 && this.nn.item(g) > e) {
        }
        var h = new ScalerParams(0, new Rect(0, 0, 0, 1, 1), new Rect(0, 0, 0, 1, 1), this.ch, this.bi.tv);
        var i = this.ej(f, h);
        var j = this.ej(g + 1, h);
        return new Rect(0, i, NaN, Math.max(0, j - i), NaN);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "nj", {
        get: function () {
            return this.ni;
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.og = function (a, b) {
        this.h8(false);
    };
    OrdinalTimeXAxis.prototype.hy = function (a) {
        _super.prototype.hy.call(this, a);
        this.dateTimeMemberPath = a;
    };
    OrdinalTimeXAxis.prototype.fz = function (a) {
        if (this.au != null) {
            return this.au(a);
        }
        if (this.ai != null) {
            return this.ai.i(a);
        }
        if (!(typeCast(Date_$type, a) !== null)) {
            return _super.prototype.fz.call(this, a);
        }
        var b = dateMinValue();
        var c = false;
        if (this.mx != null) {
            if (typeCast(Date_$type, this.mx) !== null) {
                b = this.mx;
                c = true;
            }
        }
        var d = TimeXAxis.oh(a, c, b, this.nl, this.oc, this.nj, this.fk);
        return d == null ? _super.prototype.fz.call(this, a) : d;
    };
    OrdinalTimeXAxis.prototype.gd = function (a) {
        var b = 0;
        if (this.categoryMode == 0) {
            b = truncate(Math.round(a));
        }
        else {
            b = truncate(Math.floor(a));
        }
        if (b < 0 || b > this.lg - 1) {
            return _super.prototype.gd.call(this, a);
        }
        var c = this.nn.item(b);
        var d = this.fz(c);
        if (d == null) {
            return null;
        }
        return d.toString();
    };
    OrdinalTimeXAxis.prototype.getDateTime = function (a) {
        var b = truncate(Math.round(a));
        if (b < 0) {
            b = 0;
        }
        if (b > this.lg - 1) {
            b = this.lg - 1;
        }
        if (this.nn == null) {
            return dateMinValue();
        }
        var c = this.nn.item(b);
        return c;
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "of", {
        get: function () {
            return +(this.visibleMaximum) - +(this.visibleMinimum);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "oc", {
        get: function () {
            return +(this.ny) - +(this.nz);
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.mi = function () {
        return this.nn;
    };
    OrdinalTimeXAxis.prototype.ip = function (a, b) {
        _super.prototype.ip.call(this, a, b);
        this.oi();
    };
    OrdinalTimeXAxis.prototype.mp = function (a, b) {
        var c = this.categoryMode == 0 ? 0 : 0.5;
        return _super.prototype.mp.call(this, a + c, b);
    };
    OrdinalTimeXAxis.prototype.mo = function (a, b, c, d) {
        return b;
    };
    OrdinalTimeXAxis.prototype.od = function () {
        var _this = this;
        if (this.nn == null || this.nn.count < 2) {
            return (0);
        }
        return TimeXAxis.os(function (a) { return _this.nn.item(a); }, this.nn.count);
    };
    OrdinalTimeXAxis.prototype.itemLabelFormat = function () {
        return TimeXAxis.oo(this.oe);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "minimumValue", {
        get: function () {
            return this.nt;
        },
        set: function (a) {
            var b = this.minimumValue;
            if (+a != +b) {
                this.nt = a;
                this.hw(this, "MinimumValue", b, this.minimumValue);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "maximumValue", {
        get: function () {
            return this.ns;
        },
        set: function (a) {
            var b = this.maximumValue;
            if (+a != +b) {
                this.ns = a;
                this.hw(this, "MaximumValue", b, this.maximumValue);
            }
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.c3 = function () {
        if (+(this.minimumValue) == +(dateMaxValue()) || +(this.maximumValue) == +(dateMinValue())) {
            return _super.prototype.c3.call(this);
        }
        if (this.cq && this.c4) {
            this.bc = this.bb();
        }
        if (this.kr == null || this.nn == null) {
            return false;
        }
        var a = this.mw;
        if (+(this.minimumValue) != +(dateMinValue())) {
            var b = -1;
            while (b++ <= this.nn.count) {
                if (this.nn.item(b) >= this.minimumValue) {
                    break;
                }
            }
            a = b;
        }
        var c = this.categoryMode == 0 ? this.kr.count - 1 : this.kr.count;
        if (+(this.maximumValue) != +(dateMaxValue())) {
            var d = this.kr.count;
            while (d-- > 0) {
                if (this.nn.item(d) <= this.maximumValue) {
                    break;
                }
            }
            c = d;
        }
        if (a != this.mw || c != this.mv) {
            var e = new AxisRangeChangedEventArgs(0, this.mw, a, this.mv, c);
            this.mw = a;
            this.mv = c;
            this.h3(e);
            this.oh();
            this.lt();
            return true;
        }
        return false;
    };
    OrdinalTimeXAxis.prototype.l2 = function (a) {
        _super.prototype.l2.call(this, a);
        this.c2(true);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.cp;
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.j$d = function (a, b) {
        return this.em.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$c = function (a, b) {
        return this.ej.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$e = function (a, b, c, d, e) {
        this.hm.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.hn.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$g = function (a, b, c, d) {
        this.ho.apply(this, arguments);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "j$b", {
        get: function () {
            return this.ch;
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.j$a = function () {
        return this.ag.apply(this, arguments);
    };
    OrdinalTimeXAxis.$t = markType(OrdinalTimeXAxis, 'OrdinalTimeXAxis', CategoryXAxis.$, [ITimeRangeSelectorAxis_$type, IOrdinalAxis_$type]);
    return OrdinalTimeXAxis;
}(CategoryXAxis));
export { OrdinalTimeXAxis };
