/*
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 { Series } from "./Series";
import { DependencyProperty } from "igniteui-react-core/ES2015/DependencyProperty";
import { Type, Point_$type, Boolean_$type, runOn, delegateRemove, typeCast, delegateCombine, fromEnum, fromEn, markType } from "igniteui-react-core/ES2015/type";
import { SeriesView } from "./SeriesView";
import { XamDataChart } from "./XamDataChart";
import { Tuple$2 } from "igniteui-react-core/ES2015/Tuple$2";
import { PropertyMetadata } from "igniteui-react-core/ES2015/PropertyMetadata";
import { isNaN_ } from "igniteui-react-core/ES2015/number";
/**
 * @hidden
 */
export class AnnotationLayer extends Series {
    constructor() {
        super();
        this.mu = null;
        this.lv = null;
        this.lu = null;
        this.lw = null;
        this.ms = { $type: Point_$type, x: NaN, y: NaN };
        this.lx = false;
        this.mu = { $type: Point_$type, x: NaN, y: NaN };
    }
    bf() {
        return new AnnotationLayerView(this);
    }
    im(a) {
        super.im(a);
        this.lt = a;
    }
    lz(a) {
        if (a == null) {
            return false;
        }
        if (a.cj) {
            return false;
        }
        if (a == this) {
            return false;
        }
        return a.dv(a.bi.br, a.bi.bs, a.bi);
    }
    get_cm() {
        return this.ly;
    }
    bd() {
        if (this.be == 0) {
            return 1;
        }
        else {
            return super.bd();
        }
    }
    get_cw() {
        return this.l1 || this.l2;
    }
    get_isUsableInLegend() {
        return this.l2;
    }
    is(a, b, c, d) {
        super.is(a, b, c, d);
        switch (b) {
            case "SeriesViewer":
                let e = c;
                let f = d;
                if (e != null) {
                    this.ml(e.series);
                    let g = e.series;
                    g.collectionChanged = delegateRemove(g.collectionChanged, runOn(this, this.mi));
                    if (typeCast(XamDataChart.$, e) !== null) {
                        let h = e;
                        this.mk(h.axes);
                        let i = h.axes;
                        i.collectionChanged = delegateRemove(i.collectionChanged, runOn(this, this.l8));
                    }
                }
                if (f != null) {
                    this.mg(f.series);
                    let j = f.series;
                    j.collectionChanged = delegateCombine(j.collectionChanged, runOn(this, this.mi));
                    if (typeCast(XamDataChart.$, f) !== null) {
                        let k = f;
                        this.mf(k.axes);
                        let l = k.axes;
                        l.collectionChanged = delegateCombine(l.collectionChanged, runOn(this, this.l8));
                    }
                }
                break;
            case AnnotationLayer.$$p[3]:
            case AnnotationLayer.$$p[2]:
                if (this.cw) {
                    if (this.fe == -1) {
                        this.fe = XamDataChart.od(this);
                    }
                }
                else {
                    this.fe = -1;
                    this.kw = null;
                    this.kx = null;
                }
                if (this.bs != null) {
                    this.bs.ii();
                }
                this.i6(true);
                break;
            case "TransitionProgress":
                this.lw.c(this.ew, this.lv, this.lu);
                if (this.cc(this.bi)) {
                    return;
                }
                if (this.ew == 1) {
                    this.mh(this.lu, this.bi);
                }
                else {
                    this.mh(this.lw, this.bi);
                }
                if (this.bs != null) {
                    this.bs.jj(this);
                }
                break;
            case AnnotationLayer.$$p[1]:
                if (this.bs != null) {
                    this.bs.ig();
                }
                break;
            case AnnotationLayer.$$p[0]:
                this.mu = this.mt;
                this.ih(this.mt);
                break;
            case "ShouldRenderAsOverlay":
                if (this.bs != null) {
                    this.bi.ah(this.bs);
                    this.bi.ad(this.bs);
                }
                break;
        }
    }
    ml(a) {
        for (let b of fromEnum(a)) {
            if (!(b == this)) {
                b.renderRequested = delegateRemove(b.renderRequested, runOn(this, this.mj));
            }
        }
        this.i6(true);
    }
    mk(a) {
        for (let b of fromEnum(a)) {
            b.renderRequested = delegateRemove(b.renderRequested, runOn(this, this.l9));
        }
        this.i6(true);
    }
    mg(a) {
        for (let b of fromEnum(a)) {
            if (!(b == this)) {
                b.renderRequested = delegateCombine(b.renderRequested, runOn(this, this.mj));
            }
        }
        this.i6(true);
    }
    mf(a) {
        for (let b of fromEnum(a)) {
            b.renderRequested = delegateCombine(b.renderRequested, runOn(this, this.l9));
        }
        this.i6(true);
    }
    l9(a, b) {
        this.mb(a, b.animate);
    }
    mj(a, b) {
        this.mc(a, b.animate);
    }
    mb(a, b) {
    }
    mc(a, b) {
    }
    mi(a, b) {
        this.md(b);
    }
    l8(a, b) {
        this.ma(b);
    }
    mq() {
        if (this.kw != null) {
            return this.kw;
        }
        return this.ky;
    }
    mr() {
        if (this.kx != null) {
            return this.kx;
        }
        return this.k1;
    }
    ma(a) {
        if (a.oldItems != null) {
            for (let b of fromEn(a.oldItems)) {
                b.renderRequested = delegateRemove(b.renderRequested, runOn(this, this.l9));
            }
        }
        if (a.newItems != null) {
            for (let c of fromEn(a.newItems)) {
                c.renderRequested = delegateCombine(c.renderRequested, runOn(this, this.l9));
            }
        }
        this.i6(true);
    }
    md(a) {
        if (a.oldItems != null) {
            for (let b of fromEn(a.oldItems)) {
                b.renderRequested = delegateRemove(b.renderRequested, runOn(this, this.mj));
            }
        }
        if (a.newItems != null) {
            for (let c of fromEn(a.newItems)) {
                c.renderRequested = delegateCombine(c.renderRequested, runOn(this, this.mj));
            }
        }
        this.i6(true);
    }
    jm(a, b) {
        this.i6(false);
    }
    jl(a, b) {
        this.i6(true);
    }
    i7(a) {
        super.i7(a);
        if (this.cc(this.bi)) {
            return;
        }
        if (this.c9(a) && !this.dd) {
            let b = this.lv;
            if (this.ca()) {
                if (this.bt.g) {
                    this.bt.t();
                }
                this.lv = this.lw;
                this.lw = b;
            }
            else {
                this.lv = this.lu;
                this.lu = b;
            }
            this.me(this.lu, this.bi);
            this.je();
        }
        else {
            if (!this.dd) {
                this.me(this.lu, this.bi);
            }
            this.mh(this.lu, this.bi);
        }
    }
    get_cj() {
        return true;
    }
    me(a, b) {
    }
    mh(a, b) {
        this.lt.by();
    }
    l7(a) {
        let b = { $type: Point_$type, x: this.ms.x, y: this.ms.y };
        if (a.isVertical) {
            if (isNaN_(this.ms.y)) {
                return new Tuple$2(Boolean_$type, Point_$type, false, b);
            }
            if (isNaN_(this.ms.x)) {
                b.x = 0;
                return new Tuple$2(Boolean_$type, Point_$type, true, b);
            }
        }
        else {
            if (isNaN_(this.ms.x)) {
                return new Tuple$2(Boolean_$type, Point_$type, false, b);
            }
            if (isNaN_(this.ms.y)) {
                b.y = 0;
                return new Tuple$2(Boolean_$type, Point_$type, true, b);
            }
        }
        return new Tuple$2(Boolean_$type, Point_$type, true, b);
    }
    ih(a) {
        super.ih(a);
        if (isNaN_(this.mu.x) && isNaN_(this.mu.y)) {
            if (isNaN_(a.x) && isNaN_(a.y)) {
                this.lt.bx();
                return;
            }
            else {
                this.lt.bz();
                this.ms = a;
            }
        }
        else {
            this.lt.bz();
            this.ms = this.mu;
        }
        this.i6(true);
    }
    dv(a, b, c) {
        let d = super.dv(a, b, c);
        if (!this.bi.q()) {
            return d = false;
        }
        return d;
    }
    get_dr() {
        return this.l0;
    }
    get l0() {
        return this.lx;
    }
    set l0(a) {
        let b = this.lx;
        this.lx = a;
        this.raisePropertyChanged("ShouldRenderAsOverlay", b, this.lx);
    }
}
AnnotationLayer.$t = markType(AnnotationLayer, 'AnnotationLayer', Series.$);
Type.dep(DependencyProperty, PropertyMetadata, AnnotationLayer, 'raisePropertyChanged', ['CursorPosition:mt:mm', [Point_$type, { $type: Point_$type, x: NaN, y: NaN }], 'IsDefaultCrosshairDisabled:ly:mn', [0, true], 'UseIndex:l1:mo', [0, false], 'UseLegend:l2:mp', [0, false]]);
/**
 * @hidden
 */
export class AnnotationLayerView extends SeriesView {
    constructor(a) {
        super(a);
        this.bu = null;
        this.bv = false;
        this.bw = -1;
        this.bu = a;
    }
    b0() {
        if (this.bv) {
            this.bv = false;
            this.bw = -1;
            this.bu.ms = { $type: Point_$type, x: NaN, y: NaN };
            this.bu.i6(true);
        }
    }
    bx() {
        this.bv = true;
        if (this.e.e1 != null) {
            this.e.e1.setTimeout(runOn(this, this.b0), 300);
        }
        else {
            this.bw = window.setTimeout(runOn(this, this.b0), 300);
        }
    }
    bz() {
        if (this.bv == true) {
            this.bv = false;
            if (this.bw != -1) {
                window.clearTimeout(this.bw);
                this.bw = -1;
            }
        }
    }
    by() {
        this.an();
    }
}
AnnotationLayerView.$t = markType(AnnotationLayerView, 'AnnotationLayerView', SeriesView.$);
