/*
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";
import { CategoryHighlightLayerFrame } from "./CategoryHighlightLayerFrame";
import { Base, Number_$type, typeCast, fromEnum, Point_$type, markType, markDep, runOn } from "igniteui-react-core";
import { XamDataChart } from "./XamDataChart";
import { CategoryHighlightFrameRect } from "./CategoryHighlightFrameRect";
import { List$1 } from "igniteui-react-core";
import { Pool$1 } from "igniteui-react-core";
import { Rectangle } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { isNaN_, truncate } from "igniteui-react-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { BrushUtil } from "igniteui-react-core";
import { Color } from "igniteui-react-core";
/**
 * @hidden
 */
export let CategoryHighlightLayer = /*@__PURE__*/ (() => {
    class CategoryHighlightLayer extends AnnotationLayer {
        get_dc() {
            return true;
        }
        constructor() {
            super();
            let a = new CategoryHighlightLayerFrame();
            let b = new CategoryHighlightLayerFrame();
            let c = new CategoryHighlightLayerFrame();
            let d = this.hr / 1000;
            this.qq = a;
            this.qp = b;
            this.qr = c;
            this.ab = CategoryHighlightLayer.$;
        }
        by() {
            return new CategoryHighlightLayerView(this);
        }
        l4(a) {
            super.l4(a);
            this.tc = a;
        }
        get tf() {
            return this.c(CategoryHighlightLayer.tm);
        }
        set tf(a) {
            this.h(CategoryHighlightLayer.tm, a);
        }
        r2(a, b) {
            if (this.tb == null || this.tb == a) {
                if (!this.at.c) {
                    this.mn(b);
                }
            }
        }
        td(a) {
            return a != null && a.co();
        }
        r5(a, b) {
            super.r5(a, b);
            let c = a;
            c.g.clear();
            let d = this.te;
            if (isNaN_(this.s8.x) && isNaN_(this.s8.y)) {
                return;
            }
            if (this.tb != null) {
                if (this.td(this.tb)) {
                    this.tk(this.tb, c, d);
                }
            }
            else {
                if (typeCast(XamDataChart.$, this.ce) !== null) {
                    let e = this.ce;
                    for (let f of fromEnum(e.axes)) {
                        if (typeCast(CategoryAxisBase.$, f) !== null && this.td(f)) {
                            this.tk(f, c, d);
                        }
                    }
                }
            }
        }
        tk(a, b, c) {
            if (this.b1 == null || this.b1.bv.isEmpty || this.b1.bu.isEmpty) {
                return;
            }
            let d = this.s8.x;
            if (a.cp && isNaN_(d)) {
                d = 0;
            }
            let e = this.pz(this.b1);
            d = e.left + e.width * (d - this.b1.bv.left) / this.b1.bv.width;
            let f = this.s8.y;
            if (!a.cp && isNaN_(f)) {
                f = 0;
            }
            f = e.top + e.height * (f - this.b1.bv.top) / this.b1.bv.height;
            let g = a.me({ $type: Point_$type, x: d, y: f }, c, this.tf);
            this.tj(g, b, a);
        }
        tj(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.sy();
            d.h = this.sz();
            if (d.g == null) {
                d.g = this.tc.cc(c.jv);
            }
            if (d.h == null) {
                d.h = this.tc.cc(c.jv);
            }
            d.d = this.fy;
            d.f = Base.getHashCodeStatic(c);
            if (!a.isEmpty) {
                b.g.addItem(d.f, d);
            }
        }
        r8(a, b) {
            super.r8(a, b);
            let c = this.tc.b5;
            let d = a;
            let e = 0;
            for (let f of fromEnum(d.g.values)) {
                let g = c.item(e);
                this.tl(f, g);
                e++;
            }
            c.count = e;
        }
        ep() {
            return true;
        }
        tl(a, b) {
            if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
                b._visibility = 1;
                return;
            }
            this.tc.b7(b, a.b, a.e, a.c - a.b, a.a - a.e);
            b._fill = a.g;
            b._stroke = a.h;
            b.ad = a.d;
            if (this.pi != null) {
                b.ai = this.pi;
            }
            else {
                b.ai = null;
            }
            b.aj = this.pj;
            b.am = this.pl;
            b.al = this.pk;
            b.ak = this.pk;
            b.ac = this.gw;
        }
        l9(a, b, c, d) {
            super.l9(a, b, c, d);
            switch (b) {
                case CategoryHighlightLayer.$$p[0]:
                    this.mn(true);
                    break;
                case CategoryHighlightLayer.$$p[1]:
                    this.mn(true);
                    break;
            }
        }
    }
    CategoryHighlightLayer.$t = /*@__PURE__*/ markType(CategoryHighlightLayer, 'CategoryHighlightLayer', AnnotationLayer.$);
    CategoryHighlightLayer.tm = /*@__PURE__*/ DependencyProperty.i("BAndHighlightWidth", Number_$type, CategoryHighlightLayer.$, /*@__PURE__*/ new PropertyMetadata(2, 10, (a, b) => a.raisePropertyChanged("BAndHighlightWidth", b.oldValue, b.newValue)));
    CategoryHighlightLayer.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CategoryHighlightLayer, 'raisePropertyChanged', ['TargetAxis:tb:tn', [CategoryAxisBase.$, null], 'UseInterpolation:te:to', [0, false]]);
    return CategoryHighlightLayer;
})();
/**
 * @hidden
 */
export let CategoryHighlightLayerView = /*@__PURE__*/ (() => {
    class CategoryHighlightLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            this.b4 = null;
            this.b5 = null;
            this.b6 = null;
            this.b4 = a;
            this.b6 = new List$1(Rectangle.$, 0);
        }
        as() {
            super.as();
            this.b5 = ((() => {
                let $ret = new Pool$1(Rectangle.$);
                $ret.create = runOn(this, this.cd);
                $ret.activate = runOn(this, this.b8);
                $ret.disactivate = runOn(this, this.ca);
                $ret.destroy = runOn(this, this.b9);
                return $ret;
            })());
        }
        cd() {
            let a = new Rectangle();
            a.ab = false;
            this.b6.add(a);
            return a;
        }
        b8(a) {
            a._visibility = 0;
        }
        ca(a) {
            a._visibility = 1;
        }
        b9(a) {
            this.b6.remove(a);
        }
        cb(a) {
            if (a == null) {
                return a;
            }
            return BrushUtil.l(a, 0.1);
        }
        cc(a) {
            if (a != null) {
                let b = BrushUtil.l(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;
            }
        }
        b7(a, b, c, d, e) {
            a._visibility = 0;
            a.n = b;
            a.o = c;
            a.width = d;
            a.height = e;
        }
        a6(a, b) {
            super.a6(a, b);
            if (a.d && !b) {
                for (let c = 0; c < this.b6.count; c++) {
                    let d = this.b6._inner[c];
                    if (d._visibility == 0) {
                        a.w(d);
                    }
                }
            }
        }
        al(a) {
            super.al(a);
            for (let b = 0; b < this.b6.count; b++) {
                this.e.a9.exportRectangleData(a, this.b6._inner[b], "cihRect", ["Main", "CategoryItem"]);
            }
        }
    }
    CategoryHighlightLayerView.$t = /*@__PURE__*/ markType(CategoryHighlightLayerView, 'CategoryHighlightLayerView', AnnotationLayerView.$);
    return CategoryHighlightLayerView;
})();
