/*
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 * as tslib_1 from "tslib";
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
 */
var OrdinalTimeXAxis = /** @class */ /*@__PURE__*/ (function (_super) {
    tslib_1.__extends(OrdinalTimeXAxis, _super);
    function OrdinalTimeXAxis() {
        var _this = _super.call(this) || this;
        _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();
        var a = _this.lv;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(_this, _this.ms));
        _this.lk = 0;
        return _this;
    }
    OrdinalTimeXAxis.prototype.d1 = function (a, b, c) {
        return this.dz(a, new ScalerParams(0, b, c, this.ca, this.i5()));
    };
    OrdinalTimeXAxis.prototype.d0 = function (a, b, c) {
        return this.dz(a, b);
    };
    OrdinalTimeXAxis.prototype.dz = function (a, b) {
        if (!b.c.isEmpty) {
            var 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);
    };
    OrdinalTimeXAxis.prototype.me = function (a, b, c) {
        var d = this.lj;
        var e = this.lk;
        var f = this.lj - this.lk;
        var 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;
    };
    OrdinalTimeXAxis.prototype.gs = 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.lj;
        var u = this.lk;
        var v = this.lj - this.lk;
        var w = this.k5(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.gt = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.dz(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.d4 = function (a, b, c) {
        return this.d2(a, new ScalerParams(0, b, this.ja, this.ca, this.i5()));
    };
    OrdinalTimeXAxis.prototype.getUnscaledValue3 = function (a, b, c, d) {
        return this.d2(a, new ScalerParams(0, b, this.ja, this.ca, this.i5()));
    };
    OrdinalTimeXAxis.prototype.d2 = 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.mf(c, NumericScaler.ac, b.c);
            return c;
        }
        return this.mf(a, b.e, b.d);
    };
    OrdinalTimeXAxis.prototype.mf = function (a, b, c) {
        var d = b.left + (a - c.left) * b.width / c.width;
        if (this.cb) {
            d = 1 - d;
        }
        return this.lk + d * (this.lj - this.lk);
    };
    OrdinalTimeXAxis.prototype.d3 = function (a, b, c) {
        return this.d2(a, b);
    };
    OrdinalTimeXAxis.prototype.gu = function (a, b, c, d) {
        for (var e = b; e < c; e++) {
            a.item(e, this.d2(a.item(e), d));
        }
    };
    OrdinalTimeXAxis.prototype.g0 = function (a, b, c, d) {
        _super.prototype.g0.call(this, a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                var 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;
        }
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMinimumValue", {
        get: function () {
            return this.l1;
        },
        set: function (a) {
            this.l1 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "actualMaximumValue", {
        get: function () {
            return this.l0;
        },
        set: function (a) {
            this.l0 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMinimum", {
        get: function () {
            return this.l7;
        },
        set: function (a) {
            this.l7 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "visibleMaximum", {
        get: function () {
            return this.l6;
        },
        set: function (a) {
            this.l6 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "mb", {
        get: function () {
            return this.l3;
        },
        set: function (a) {
            this.l3 = a;
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "ma", {
        get: function () {
            return this.l2;
        },
        set: function (a) {
            this.l2 = a;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.mt = function () {
        if (this.lz == null || this.lz.count == 0 || this.lz.count < this.lk - 1) {
            this.actualMinimumValue = dateMinValue();
            this.actualMaximumValue = dateMaxValue();
            return;
        }
        var a = Math.max(0, Math.min(this.lk, this.lz.count - 1));
        var b = Math.max(0, Math.min(this.lj, this.lz.count - 1));
        var c = +(this.actualMinimumValue) != +(this.lz.item(a)) || +(this.actualMaximumValue) != +(this.lz.item(b));
        if (c) {
            var d = this.actualMinimumValue;
            var e = this.actualMaximumValue;
            this.actualMinimumValue = this.lz.item(a);
            this.actualMaximumValue = this.lz.item(b);
            this.mu();
        }
    };
    OrdinalTimeXAxis.prototype.mu = function () {
        if (this.lz == null || this.lz.count == 0 || this.bh == null) {
            var 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;
        }
        var b = this.i4();
        var c = new ScalerParams(1, this.bh.o8, this.bh.o7, this.ca);
        c.c = this.i5();
        var d = this.d2(b.left, c);
        var e = this.d2(b.right, c);
        var f = truncate(Math.floor(d));
        var g = truncate(Math.ceil(e));
        var h = f >= 0 && f < this.lz.count ? this.lz.item(f) : this.actualMinimumValue;
        var i = g >= 0 && g < this.lz.count ? this.lz.item(g) : this.actualMaximumValue;
        var j = h;
        var k = i;
        if (d > f) {
            var l = f + 1;
            var m = l >= 0 && l < this.lz.count ? this.lz.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.lz.count ? this.lz.item(o) : h;
            var q = dateSubtract(+i, +(timeSpanFromMilliseconds(timeSpanTotalMilliseconds((+i - +p)) * (g - e))));
            k = q;
        }
        this.mb = j;
        this.ma = 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.hd = function (a) {
        var 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.prototype.hd.call(this, a);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "dateTimeMemberPath", {
        get: function () {
            return this.mg;
        },
        set: function (a) {
            var b = this.dateTimeMemberPath;
            if (a != b) {
                this.mg = a;
                this.g6("DateTimeMemberPath", b, this.dateTimeMemberPath);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lx", {
        get: function () {
            return this.lw;
        },
        set: function (a) {
            var b = this.lx;
            if (a != b) {
                this.lw = a;
                this.g6("LabellingMode", enumGetBox(TimeAxisLabellingMode_$type, b), enumGetBox(TimeAxisLabellingMode_$type, this.lx));
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lz", {
        get: function () {
            return this.ly;
        },
        set: function (a) {
            if (this.ly != a) {
                var b = this.ly;
                this.ly = a;
                this.g6("DateTimeColumn", b, this.ly);
            }
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.hp = function (a, b) {
        _super.prototype.hp.call(this, a, b);
        this.mu();
    };
    OrdinalTimeXAxis.prototype.getWindowRectForSelection = function (a, b) {
        if (this.lz == null) {
            return Rect.empty;
        }
        var c = a > b;
        var d = c ? b : a;
        var e = c ? a : b;
        var f = -1;
        while (++f < this.lz.count && this.lz.item(f) < d) {
        }
        var g = this.lz.count;
        while (--g >= 0 && this.lz.item(g) > e) {
        }
        var h = new ScalerParams(0, new Rect(0, 0, 0, 1, 1), new Rect(0, 0, 0, 1, 1), this.ca, this.bh.ow);
        var i = this.dz(f, h);
        var j = this.dz(g + 1, h);
        return new Rect(0, i, NaN, Math.max(0, j - i), NaN);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "lv", {
        get: function () {
            return this.lu;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.ms = function (a, b) {
        this.hc(false);
    };
    OrdinalTimeXAxis.prototype.g2 = function (a) {
        _super.prototype.g2.call(this, a);
        this.dateTimeMemberPath = a;
    };
    OrdinalTimeXAxis.prototype.e9 = function (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.prototype.e9.call(this, a);
        }
        var b = dateMinValue();
        var c = false;
        if (this.ll != null) {
            if (typeCast(Date_$type, this.ll) !== null) {
                b = this.ll;
                c = true;
            }
        }
        var d = TimeXAxis.m2(a, c, b, this.lx, this.mo, this.lv, this.eu);
        return d == null ? _super.prototype.e9.call(this, a) : d;
    };
    OrdinalTimeXAxis.prototype.fm = 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.j9 - 1) {
            return _super.prototype.fm.call(this, a);
        }
        var c = this.lz.item(b);
        var d = this.e9(c);
        if (d == null) {
            return null;
        }
        return d.toString();
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "mr", {
        get: function () {
            return +(this.visibleMaximum) - +(this.visibleMinimum);
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "mo", {
        get: function () {
            return +(this.ma) - +(this.mb);
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.k7 = function () {
        return this.lz;
    };
    OrdinalTimeXAxis.prototype.ho = function (a, b) {
        _super.prototype.ho.call(this, a, b);
        this.mu();
    };
    OrdinalTimeXAxis.prototype.ld = function (a, b) {
        var c = this.categoryMode == 0 ? 0 : 0.5;
        return _super.prototype.ld.call(this, a + c, b);
    };
    OrdinalTimeXAxis.prototype.lc = function (a, b, c, d) {
        return b;
    };
    OrdinalTimeXAxis.prototype.mp = function () {
        var _this = this;
        if (this.lz == null || this.lz.count < 2) {
            return (0);
        }
        return TimeXAxis.nd(function (a) { return _this.lz.item(a); }, this.lz.count);
    };
    OrdinalTimeXAxis.prototype.itemLabelFormat = function () {
        return TimeXAxis.m9(this.mq);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "minimumValue", {
        get: function () {
            return this.l5;
        },
        set: function (a) {
            var b = this.minimumValue;
            if (+a != +b) {
                this.l5 = a;
                this.g0(this, "MinimumValue", b, this.minimumValue);
            }
        },
        enumerable: true,
        configurable: true
    });
    Object.defineProperty(OrdinalTimeXAxis.prototype, "maximumValue", {
        get: function () {
            return this.l4;
        },
        set: function (a) {
            var b = this.maximumValue;
            if (+a != +b) {
                this.l4 = a;
                this.g0(this, "MaximumValue", b, this.maximumValue);
            }
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.cp = function () {
        if (+(this.minimumValue) == +(dateMaxValue()) || +(this.maximumValue) == +(dateMinValue())) {
            return _super.prototype.cp.call(this);
        }
        if (this.ci && this.cq) {
            this.bb = this.ba();
        }
        if (this.jo == null || this.lz == null) {
            return false;
        }
        var a = this.lk;
        if (+(this.minimumValue) != +(dateMinValue())) {
            var b = -1;
            while (b++ <= this.lz.count) {
                if (this.lz.item(b) >= this.minimumValue) {
                    break;
                }
            }
            a = b;
        }
        var c = this.categoryMode == 0 ? this.jo.count - 1 : this.jo.count;
        if (+(this.maximumValue) != +(dateMaxValue())) {
            var d = this.jo.count;
            while (d-- > 0) {
                if (this.lz.item(d) <= this.maximumValue) {
                    break;
                }
            }
            c = d;
        }
        if (a != this.lk || c != this.lj) {
            var 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;
    };
    OrdinalTimeXAxis.prototype.kt = function (a) {
        _super.prototype.kt.call(this, a);
        this.co(true);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "isVertical", {
        get: function () {
            return this.ch;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.prototype.j$c = function (a, b) {
        return this.d2.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$b = function (a, b) {
        return this.dz.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$d = function (a, b, c, d, e) {
        this.gs.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$e = function (a, b, c, d) {
        this.gt.apply(this, arguments);
    };
    OrdinalTimeXAxis.prototype.j$f = function (a, b, c, d) {
        this.gu.apply(this, arguments);
    };
    Object.defineProperty(OrdinalTimeXAxis.prototype, "j$a", {
        get: function () {
            return this.ca;
        },
        enumerable: true,
        configurable: true
    });
    OrdinalTimeXAxis.$t = markType(OrdinalTimeXAxis, 'OrdinalTimeXAxis', CategoryXAxis.$, [ITimeRangeSelectorAxis_$type]);
    return OrdinalTimeXAxis;
}(CategoryXAxis));
export { OrdinalTimeXAxis };
//# sourceMappingURL=OrdinalTimeXAxis.js.map
