/*
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.nr = dateMaxValue();
        _this.nq = dateMinValue();
        _this.nx = dateMaxValue();
        _this.nw = dateMinValue();
        _this.nt = dateMaxValue();
        _this.ns = dateMinValue();
        _this.n7 = null;
        _this.n6 = null;
        _this.nm = 0;
        _this.no = null;
        _this.nk = null;
        _this.og = 0;
        _this.nv = dateMinValue();
        _this.nu = dateMaxValue();
        _this.visibleRangeChanged = null;
        FastItemDateTimeColumn.o();
        _this.nk = new TimeAxisLabelFormatCollection();
        var a = _this.nl;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.oi));
        _this.my = 0;
        return _this;
    }
    OrdinalTimeXAxis.prototype.em = function (a, b, c) {
        return this.ek(a, new ScalerParams(0, b, c, this.ch, this.j9()));
    };
    OrdinalTimeXAxis.prototype.el = function (a, b, c) {
        return this.ek(a, b);
    };
    OrdinalTimeXAxis.prototype.ek = function (a, b) {
        if (!b.c.isEmpty) {
            var c = this.n4(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.n4(a, b.e, b.d);
    };
    OrdinalTimeXAxis.prototype.n4 = function (a, b, c) {
        var d = this.mx;
        var e = this.my;
        var f = this.mx - this.my;
        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.hn = 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.mx;
        var u = this.my;
        var v = this.mx - this.my;
        var w = this.mi(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.ho = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.ek(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.ep = function (a, b, c) {
        return this.en(a, new ScalerParams(0, b, this.ke, this.ch, this.j9()));
    };
    OrdinalTimeXAxis.prototype.getUnscaledValue3 = function (a, b, c, d) {
        return this.en(a, new ScalerParams(0, b, this.ke, this.ch, this.j9()));
    };
    OrdinalTimeXAxis.prototype.en = 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.n5(c, NumericScaler.ac, b.c);
            return c;
        }
        return this.n5(a, b.e, b.d);
    };
    OrdinalTimeXAxis.prototype.n5 = function (a, b, c) {
        var d = b.left + (a - c.left) * b.width / c.width;
        if (this.ci) {
            d = 1 - d;
        }
        return this.my + d * (this.mx - this.my);
    };
    OrdinalTimeXAxis.prototype.eo = function (a, b, c) {
        return this.en(a, b);
    };
    OrdinalTimeXAxis.prototype.hp = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.en(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.hx = function (a, b, c, d) {
        _super.prototype.hx.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.np);
                    this.np = null;
                }
                if (this.ks != null) {
                    this.np = TimeAxisBase.ml(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeMemberPath":
                if (this.ks != null) {
                    this.ks.deregisterColumn(this.np);
                    this.np = TimeAxisBase.ml(this.dateTimeMemberPath, this);
                }
                break;
            case "DateTimeColumn":
                this.c1();
                this.og = this.of();
                break;
            case "MinimumValue":
            case "MaximumValue":
                this.c1();
                this.h8();
                break;
            case "LabellingMode":
                this.h8();
                break;
        }
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMinimumValue", {
        get: function () {
            return this.nr;
        },
        set: function (a) {
            this.nr = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMaximumValue", {
        get: function () {
            return this.nq;
        },
        set: function (a) {
            this.nq = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMinimum", {
        get: function () {
            return this.nx;
        },
        set: function (a) {
            this.nx = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMaximum", {
        get: function () {
            return this.nw;
        },
        set: function (a) {
            this.nw = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "n1", {
        get: function () {
            return this.nt;
        },
        set: function (a) {
            this.nt = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "n0", {
        get: function () {
            return this.ns;
        },
        set: function (a) {
            this.ns = a;
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.oj = function () {
        if (this.np == null || this.np.count == 0 || this.np.count < this.my - 1) {
            this.actualMinimumValue = dateMinValue();
            this.actualMaximumValue = dateMaxValue();
            return;
        }
        var a = Math.max(0, Math.min(this.my, this.np.count - 1));
        var b = Math.max(0, Math.min(this.mx, this.np.count - 1));
        var c = +(this.actualMinimumValue) != +(this.np.item(a)) || +(this.actualMaximumValue) != +(this.np.item(b));
        if (c) {
            var d = this.actualMinimumValue;
            var e = this.actualMaximumValue;
            this.actualMinimumValue = this.np.item(a);
            this.actualMaximumValue = this.np.item(b);
            this.ok();
        }
    };
    OrdinalTimeXAxis.prototype.ok = function () {
        if (this.np == null || this.np.count == 0 || this.bi == null) {
            var a = +(this.visibleMinimum) != +(this.actualMinimumValue) || +(this.visibleMaximum) != +(this.actualMaximumValue);
            this.visibleMinimum = this.actualMinimumValue;
            this.visibleMaximum = this.actualMaximumValue;
            this.n1 = this.visibleMinimum;
            this.n0 = this.visibleMaximum;
            if (a && this.visibleRangeChanged != null) {
                this.visibleRangeChanged(this, EventArgs.empty);
            }
            return;
        }
        var b = this.j8();
        var c = new ScalerParams(1, this.bi.v1, this.bi.v0, this.ch);
        c.c = this.j9();
        var d = this.en(b.left, c);
        var e = this.en(b.right, c);
        var f = truncate(Math.floor(d));
        var g = truncate(Math.ceil(e));
        var h = f >= 0 && f < this.np.count ? this.np.item(f) : this.actualMinimumValue;
        var i = g >= 0 && g < this.np.count ? this.np.item(g) : this.actualMaximumValue;
        var j = h;
        var k = i;
        if (d > f) {
            var l = f + 1;
            var m = l >= 0 && l < this.np.count ? this.np.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.np.count ? this.np.item(o) : h;
            var q = dateSubtract(+i, +(timeSpanFromMilliseconds(timeSpanTotalMilliseconds((+i - +p)) * (g - e))));
            k = q;
        }
        this.n1 = j;
        this.n0 = 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.ia = function (a) {
        var b = TimeXAxis.oq(this.actualMinimumValue, false, this.actualMinimumValue, this.nn, this.oe, this.nl, this.fl);
        if (b != this.n7 && this.c4) {
            this.ie();
        }
        this.n7 = b;
        _super.prototype.ia.call(this, a);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "dateTimeMemberPath", {
        get: function () {
            return this.n6;
        },
        set: function (a) {
            var b = this.dateTimeMemberPath;
            if (a != b) {
                this.n6 = a;
                this.h3("DateTimeMemberPath", b, this.dateTimeMemberPath);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "nn", {
        get: function () {
            return this.nm;
        },
        set: function (a) {
            var b = this.nn;
            if (a != b) {
                this.nm = a;
                this.h3("LabellingMode", enumGetBox(TimeAxisLabellingMode_$type, b), enumGetBox(TimeAxisLabellingMode_$type, this.nn));
            }
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.get_ck = function () {
        return true;
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "np", {
        get: function () {
            return this.no;
        },
        set: function (a) {
            if (this.no != a) {
                var b = this.no;
                this.no = a;
                this.h3("DateTimeColumn", b, this.no);
            }
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.ir = function (a, b) {
        _super.prototype.ir.call(this, a, b);
        this.ok();
    };
    OrdinalTimeXAxis.prototype.getWindowRectForSelection = function (a, b) {
        if (this.np == null) {
            return Rect.empty;
        }
        var c = a > b;
        var d = c ? b : a;
        var e = c ? a : b;
        var f = -1;
        while (++f < this.np.count && this.np.item(f) < d) {
        }
        var g = this.np.count;
        while (--g >= 0 && this.np.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.vp);
        var i = this.ek(f, h);
        var j = this.ek(g + 1, h);
        return new Rect(0, i, NaN, Math.max(0, j - i), NaN);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "nl", {
        get: function () {
            return this.nk;
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.oi = function (a, b) {
        this.h9(false);
    };
    OrdinalTimeXAxis.prototype.hz = function (a) {
        _super.prototype.hz.call(this, a);
        this.dateTimeMemberPath = a;
    };
    OrdinalTimeXAxis.prototype.f0 = 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.f0.call(this, a);
        }
        var b = dateMinValue();
        var c = false;
        if (this.mz != null) {
            if (typeCast(Date_$type, this.mz) !== null) {
                b = this.mz;
                c = true;
            }
        }
        var d = TimeXAxis.ol(a, c, b, this.nn, this.oe, this.nl, this.fl);
        return d == null ? _super.prototype.f0.call(this, a) : d;
    };
    OrdinalTimeXAxis.prototype.ge = 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.lh - 1) {
            return _super.prototype.ge.call(this, a);
        }
        var c = this.np.item(b);
        var d = this.f0(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.lh - 1) {
            b = this.lh - 1;
        }
        if (this.np == null) {
            return dateMinValue();
        }
        var c = this.np.item(b);
        return c;
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "oh", {
        get: function () {
            return +(this.visibleMaximum) - +(this.visibleMinimum);
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "oe", {
        get: function () {
            return +(this.n0) - +(this.n1);
        },
        enumerable: false,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.mk = function () {
        return this.np;
    };
    OrdinalTimeXAxis.prototype.iq = function (a, b) {
        _super.prototype.iq.call(this, a, b);
        this.ok();
    };
    OrdinalTimeXAxis.prototype.mr = function (a, b) {
        var c = this.categoryMode == 0 ? 0 : 0.5;
        return _super.prototype.mr.call(this, a + c, b);
    };
    OrdinalTimeXAxis.prototype.mq = function (a, b, c, d) {
        return b;
    };
    OrdinalTimeXAxis.prototype.of = function () {
        var _this = this;
        if (this.np == null || this.np.count < 2) {
            return (0);
        }
        return TimeXAxis.ow(function (a) { return _this.np.item(a); }, this.np.count);
    };
    OrdinalTimeXAxis.prototype.itemLabelFormat = function () {
        return TimeXAxis.os(this.og);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "minimumValue", {
        get: function () {
            return this.nv;
        },
        set: function (a) {
            var b = this.minimumValue;
            if (+a != +b) {
                this.nv = a;
                this.hx(this, "MinimumValue", b, this.minimumValue);
            }
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "maximumValue", {
        get: function () {
            return this.nu;
        },
        set: function (a) {
            var b = this.maximumValue;
            if (+a != +b) {
                this.nu = a;
                this.hx(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.ks == null || this.np == null) {
            return false;
        }
        var a = this.my;
        if (+(this.minimumValue) != +(dateMinValue())) {
            var b = -1;
            while (b++ <= this.np.count) {
                if (this.np.item(b) >= this.minimumValue) {
                    break;
                }
            }
            a = b;
        }
        var c = this.categoryMode == 0 ? this.ks.count - 1 : this.ks.count;
        if (+(this.maximumValue) != +(dateMaxValue())) {
            var d = this.ks.count;
            while (d-- > 0) {
                if (this.np.item(d) <= this.maximumValue) {
                    break;
                }
            }
            c = d;
        }
        if (a != this.my || c != this.mx) {
            var e = new AxisRangeChangedEventArgs(0, this.my, a, this.mx, c);
            this.my = a;
            this.mx = c;
            this.h4(e);
            this.oj();
            this.lv();
            return true;
        }
        return false;
    };
    OrdinalTimeXAxis.prototype.l4 = function (a) {
        _super.prototype.l4.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.en.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$c = function (a, b) {
        return this.ek.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$e = function (a, b, c, d, e) {
        this.hn.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.ho.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$g = function (a, b, c, d) {
        this.hp.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 };
