/*
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 { AnnotationLayer } from "./AnnotationLayer";
import { CategoryAxisBase } from "./CategoryAxisBase";
import { DependencyProperty } from "igniteui-react-core/ES2015/DependencyProperty";
import { CategoryHighlightLayerFrame } from "./CategoryHighlightLayerFrame";
import { Type, Base, Number_$type, typeCast, fromEnum, Point_$type, markType, runOn } from "igniteui-react-core/ES2015/type";
import { XamDataChart } from "./XamDataChart";
import { CategoryHighlightFrameRect } from "./CategoryHighlightFrameRect";
import { List$1 } from "igniteui-react-core/ES2015/List$1";
import { Pool$1 } from "igniteui-react-core/ES2015/Pool$1";
import { Rectangle } from "igniteui-react-core/ES2015/Rectangle";
import { PropertyMetadata } from "igniteui-react-core/ES2015/PropertyMetadata";
import { isNaN_, truncate } from "igniteui-react-core/ES2015/number";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { BrushUtil } from "igniteui-react-core/ES2015/BrushUtil";
import { Color } from "igniteui-react-core/ES2015/Color";
/**
 * @hidden
 */
export class CategoryHighlightLayer extends AnnotationLayer {
    constructor() {
        super();
        let a = new CategoryHighlightLayerFrame();
        let b = new CategoryHighlightLayerFrame();
        let c = new CategoryHighlightLayerFrame();
        let d = this.ff / 1000;
        this.lv = a;
        this.lu = b;
        this.lw = c;
        this.ab = CategoryHighlightLayer.$;
    }
    bf() {
        return new CategoryHighlightLayerView(this);
    }
    im(a) {
        super.im(a);
        this.mw = a;
    }
    get mz() {
        return this.c(CategoryHighlightLayer.m6);
    }
    set mz(a) {
        this.h(CategoryHighlightLayer.m6, a);
    }
    mb(a, b) {
        if (this.mv == null || this.mv == a) {
            if (!this.aq.c) {
                this.i6(b);
            }
        }
    }
    mx(a) {
        return a != null && a.cd();
    }
    me(a, b) {
        super.me(a, b);
        let c = a;
        c.g.clear();
        let d = this.my;
        if (isNaN_(this.ms.x) && isNaN_(this.ms.y)) {
            return;
        }
        if (this.mv != null) {
            if (this.mx(this.mv)) {
                this.m4(this.mv, c, d);
            }
        }
        else {
            if (typeCast(XamDataChart.$, this.bs) !== null) {
                let e = this.bs;
                for (let f of fromEnum(e.axes)) {
                    if (typeCast(CategoryAxisBase.$, f) !== null && this.mx(f)) {
                        this.m4(f, c, d);
                    }
                }
            }
        }
    }
    m4(a, b, c) {
        if (this.bi == null || this.bi.bs.isEmpty || this.bi.br.isEmpty) {
            return;
        }
        let d = this.ms.x;
        if (a.ce && isNaN_(d)) {
            d = 0;
        }
        d = this.bi.br.left + this.bi.br.width * (d - this.bi.bs.left) / this.bi.bs.width;
        let e = this.ms.y;
        if (!a.ce && isNaN_(e)) {
            e = 0;
        }
        e = this.bi.br.top + this.bi.br.height * (e - this.bi.bs.top) / this.bi.bs.height;
        let f = a.kn({ $type: Point_$type, x: d, y: e }, c, this.mz);
        this.m3(f, b, a);
    }
    m3(a, b, c) {
        let d = new CategoryHighlightFrameRect();
        d.b = a.left;
        d.e = a.top;
        d.c = a.right;
        d.a = a.bottom;
        d.g = this.mq();
        d.h = this.mr();
        if (d.g == null) {
            d.g = this.mw.b9(c.ib);
        }
        if (d.h == null) {
            d.h = this.mw.b9(c.ib);
        }
        d.d = this.ev;
        d.f = Base.getHashCodeStatic(c);
        if (!a.isEmpty) {
            b.g.addItem(d.f, d);
        }
    }
    mh(a, b) {
        super.mh(a, b);
        let c = this.mw.b2;
        let d = a;
        let e = 0;
        for (let f of fromEnum(d.g.values)) {
            let g = c.item(e);
            this.m5(f, g);
            e++;
        }
        c.count = e;
    }
    c7() {
        return true;
    }
    m5(a, b) {
        if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
            b._visibility = 1;
            return;
        }
        this.mw.b4(b, a.b, a.e, a.c - a.b, a.a - a.e);
        b._fill = a.g;
        b._stroke = a.h;
        b.ac = a.d;
        if (this.k4 != null) {
            b.ai = this.k4;
        }
        else {
            b.ai = null;
        }
        b.ad = this.k5;
    }
    is(a, b, c, d) {
        super.is(a, b, c, d);
        switch (b) {
            case CategoryHighlightLayer.$$p[0]:
                this.i6(true);
                break;
            case CategoryHighlightLayer.$$p[1]:
                this.i6(true);
                break;
        }
    }
}
CategoryHighlightLayer.$t = markType(CategoryHighlightLayer, 'CategoryHighlightLayer', AnnotationLayer.$);
CategoryHighlightLayer.m6 = DependencyProperty.i("BAndHighlightWidth", Number_$type, CategoryHighlightLayer.$, new PropertyMetadata(2, 10, (a, b) => a.raisePropertyChanged("BAndHighlightWidth", b.oldValue, b.newValue)));
Type.dep(DependencyProperty, PropertyMetadata, CategoryHighlightLayer, 'raisePropertyChanged', ['TargetAxis:mv:m7', [CategoryAxisBase.$, null], 'UseInterpolation:my:m8', [0, false]]);
/**
 * @hidden
 */
export class CategoryHighlightLayerView extends AnnotationLayerView {
    constructor(a) {
        super(a);
        this.b1 = null;
        this.b2 = null;
        this.b3 = null;
        this.b1 = a;
        this.b3 = new List$1(Rectangle.$, 0);
    }
    ap() {
        super.ap();
        this.b2 = ((() => {
            let $ret = new Pool$1(Rectangle.$);
            $ret.create = runOn(this, this.ca);
            $ret.activate = runOn(this, this.b5);
            $ret.disactivate = runOn(this, this.b7);
            $ret.destroy = runOn(this, this.b6);
            return $ret;
        })());
    }
    ca() {
        let a = new Rectangle();
        a.ab = false;
        this.b3.add(a);
        return a;
    }
    b5(a) {
        a._visibility = 0;
    }
    b7(a) {
        a._visibility = 1;
    }
    b6(a) {
        this.b3.remove(a);
    }
    b8(a) {
        if (a == null) {
            return a;
        }
        return BrushUtil.h(a, 0.1);
    }
    b9(a) {
        if (a != null) {
            let b = BrushUtil.h(a, 0.3);
            if (b.isGradient) {
                let c = b;
                if (c.gradientStops != null) {
                    for (let d = 0; d < c.gradientStops.length; d++) {
                        let e = c.gradientStops[d];
                        e.color = Color.u(truncate(Math.round((e.color.l) * 0.2)), e.color.o, e.color.n, e.color.m);
                        e.color = e.color;
                    }
                }
            }
            else {
                b.color = Color.u(truncate(Math.round((b.color.l) * 0.2)), b.color.o, b.color.n, b.color.m);
                b.color = b.color;
            }
            return b;
        }
        else {
            return null;
        }
    }
    b4(a, b, c, d, e) {
        a._visibility = 0;
        a.n = b;
        a.o = c;
        a.width = d;
        a.height = e;
    }
    a3(a, b) {
        super.a3(a, b);
        if (a.d && !b) {
            for (let c = 0; c < this.b3.count; c++) {
                let d = this.b3._inner[c];
                if (d._visibility == 0) {
                    a.v(d);
                }
            }
        }
    }
    ai(a) {
        super.ai(a);
        for (let b = 0; b < this.b3.count; b++) {
            this.e.a2.exportRectangleData(a, this.b3._inner[b], "cihRect", ["Main", "CategoryItem"]);
        }
    }
}
CategoryHighlightLayerView.$t = markType(CategoryHighlightLayerView, 'CategoryHighlightLayerView', AnnotationLayerView.$);
