/*
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/ES2015/FastItemDateTimeColumn";
import { CategoryXAxis } from "./CategoryXAxis";
import { ITimeRangeSelectorAxis_$type } from "./ITimeRangeSelectorAxis";
import { TimeAxisLabelFormatCollection } from "./TimeAxisLabelFormatCollection";
import { IFastItemsSource_$type } from "igniteui-react-core/ES2015/IFastItemsSource";
import { TimeAxisBase } from "./TimeAxisBase";
import { runOn, delegateCombine, typeCast, Date_$type, markType } from "igniteui-react-core/ES2015/type";
import { AxisRangeChangedEventArgs } from "./AxisRangeChangedEventArgs";
import { ScalerParams } from "./ScalerParams";
import { Rect } from "igniteui-react-core/ES2015/Rect";
import { TimeXAxis } from "./TimeXAxis";
import { truncate } from "igniteui-react-core/ES2015/number";
import { dateMaxValue, dateMinValue } from "igniteui-react-core/ES2015/date";
export class OrdinalTimeXAxis extends CategoryXAxis {
    constructor() {
        super();
        this.lh = dateMaxValue();
        this.lg = dateMinValue();
        this.lj = dateMaxValue();
        this.li = dateMinValue();
        this.lo = null;
        this.le = null;
        this.lc = null;
        this.actualRangeChanged = null;
        FastItemDateTimeColumn.m();
        this.lc = new TimeAxisLabelFormatCollection();
        let a = this.ld;
        a.collectionChanged = delegateCombine(a.collectionChanged, runOn(this, this.lu));
    }
    gn(a, b, c, d) {
        super.gn(a, b, c, d);
        switch (b) {
            case "FastItemsSource":
                let e = typeCast(IFastItemsSource_$type, c);
                if (e != null) {
                    e.deregisterColumn(this.lf);
                    this.lf = null;
                }
                if (this.i7 != null) {
                    this.lf = TimeAxisBase.ks(this.lq, this);
                }
                break;
            case "DateTimeMemberPath":
                if (this.i7 != null) {
                    this.i7.deregisterColumn(this.lf);
                    this.lf = TimeAxisBase.ks(this.lq, this);
                }
                break;
            case "DateTimeColumn":
                this.lv();
                break;
        }
    }
    get actualMinimumValue() {
        return this.lh;
    }
    set actualMinimumValue(a) {
        this.lh = a;
    }
    get actualMaximumValue() {
        return this.lg;
    }
    set actualMaximumValue(a) {
        this.lg = a;
    }
    get visibleMinimum() {
        return this.lj;
    }
    set visibleMinimum(a) {
        this.lj = a;
    }
    get visibleMaximum() {
        return this.li;
    }
    set visibleMaximum(a) {
        this.li = a;
    }
    kc(a) {
        super.kc(a);
        this.lv();
    }
    lv() {
        if (this.lf == null || this.lf.count == 0) {
            this.actualMinimumValue = dateMinValue();
            this.actualMaximumValue = dateMaxValue();
            return;
        }
        let a = +(this.actualMinimumValue) != +(this.lf.item(0)) && +(this.actualMaximumValue) != +(this.lf.item(this.lf.count - 1));
        if (a) {
            let b = this.actualMinimumValue;
            let c = this.actualMaximumValue;
            this.actualMinimumValue = this.lf.item(0);
            this.actualMaximumValue = this.lf.item(this.lf.count - 1);
            this.lw();
            if (this.actualRangeChanged != null) {
                this.actualRangeChanged(this, new AxisRangeChangedEventArgs(0, b.getTime(), this.actualMinimumValue.getTime(), c.getTime(), this.actualMaximumValue.getTime()));
            }
        }
    }
    lw() {
        if (this.lf == null || this.lf.count == 0 || this.bf == null) {
            this.visibleMinimum = this.actualMinimumValue;
            this.visibleMaximum = this.actualMaximumValue;
            return;
        }
        let a = new ScalerParams(1, this.bf.my, this.it, this.b8);
        let b = truncate(Math.ceil(this.dw(this.it.left, a)));
        let c = truncate(Math.ceil(this.dw(this.it.right, a)));
        this.visibleMinimum = b >= 0 && b < this.lf.count ? this.lf.item(b) : this.actualMinimumValue;
        this.visibleMaximum = c >= 0 && c < this.lf.count ? this.lf.item(c) : this.actualMaximumValue;
    }
    get lq() {
        return this.lo;
    }
    set lq(a) {
        let b = this.lq;
        if (a != b) {
            this.lo = a;
            this.gt("DateTimeMemberPath", b, this.lq);
        }
    }
    get lf() {
        return this.le;
    }
    set lf(a) {
        if (this.le != a) {
            let b = this.le;
            this.le = a;
            this.gt("DateTimeColumn", b, this.le);
        }
    }
    hb(a, b) {
        super.hb(a, b);
        this.lw();
    }
    getWindowRectForSelection(a, b) {
        if (this.lf == null) {
            return Rect.empty;
        }
        let c = a > b;
        let d = c ? b : a;
        let e = c ? a : b;
        let f = -1;
        while (++f < this.lf.count && this.lf.item(f) < d) {
            ;
        }
        let g = this.lf.count;
        while (--g >= 0 && this.lf.item(g) > e) {
            ;
        }
        let h = new ScalerParams(0, new Rect(0, 0, 0, 1, 1), new Rect(0, 0, 0, 1, 1), this.b8, this.bf.mo);
        let i = this.dt(f, h);
        let j = this.dt(g + 1, h);
        return new Rect(0, i, NaN, Math.max(0, j - i), NaN);
    }
    get ld() {
        return this.lc;
    }
    lu(a, b) {
        this.gz(false);
    }
    gp(a) {
        super.gp(a);
        this.lq = a;
    }
    e0(a) {
        if (!(typeCast(Date_$type, a) !== null)) {
            return super.e0(a);
        }
        let b = TimeXAxis.mc(a, this.lt, this.ld);
        return b == null ? super.e0(a) : b;
    }
    get lt() {
        return +(this.visibleMaximum) - +(this.visibleMinimum);
    }
    kq() {
        return this.lf;
    }
    ha(a, b) {
        super.ha(a, b);
        this.lw();
    }
    kw(a, b) {
        return super.kw(a + 0.5, b);
    }
    kv(a, b, c, d) {
        return b;
    }
    get isVertical() {
        return this.ce;
    }
    j$c(a, b) {
        return this.dw.apply(this, arguments);
    }
    j$b(a, b) {
        return this.dt.apply(this, arguments);
    }
    j$d(a, b, c, d, e) {
        this.gf.apply(this, arguments);
    }
    j$e(a, b, c, d) {
        this.gg.apply(this, arguments);
    }
    j$f(a, b, c, d) {
        this.gh.apply(this, arguments);
    }
    get j$a() {
        return this.b8;
    }
}
OrdinalTimeXAxis.$t = markType(OrdinalTimeXAxis, 'OrdinalTimeXAxis', CategoryXAxis.$, [ITimeRangeSelectorAxis_$type]);
