/*
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_d5() {
            return true;
        }
        constructor() {
            super();
            let a = new CategoryHighlightLayerFrame();
            let b = new CategoryHighlightLayerFrame();
            let c = new CategoryHighlightLayerFrame();
            let d = this.ji / 1000;
            this.uf = a;
            this.ue = b;
            this.ug = c;
            this.ab = CategoryHighlightLayer.$;
        }
        cg() {
            return new CategoryHighlightLayerView(this);
        }
        o0(a) {
            super.o0(a);
            this.w1 = a;
        }
        get w4() {
            return this.c(CategoryHighlightLayer.xb);
        }
        set w4(a) {
            this.h(CategoryHighlightLayer.xb, a);
        }
        vr(a, b) {
            if (this.w0 == null || this.w0 == a) {
                if (!this.at.c) {
                    this.pp(b);
                }
            }
        }
        w2(a) {
            return a != null && a.co();
        }
        vu(a, b) {
            super.vu(a, b);
            let c = a;
            c.g.clear();
            let d = this.w3;
            if (isNaN_(this.wx.x) && isNaN_(this.wx.y)) {
                return;
            }
            if (this.w0 != null) {
                if (this.w2(this.w0)) {
                    this.w9(this.w0, c, d);
                }
            }
            else {
                if (typeCast(XamDataChart.$, this.cy) !== null) {
                    let e = this.cy;
                    for (let f of fromEnum(e.axes)) {
                        if (typeCast(CategoryAxisBase.$, f) !== null && this.w2(f)) {
                            this.w9(f, c, d);
                        }
                    }
                }
            }
        }
        w9(a, b, c) {
            if (this.cj == null || this.cj.by.isEmpty || this.cj.bx.isEmpty) {
                return;
            }
            let d = this.wx.x;
            if (a.cp && isNaN_(d)) {
                d = 0;
            }
            let e = this.to(this.cj);
            d = e.left + e.width * (d - this.cj.by.left) / this.cj.by.width;
            let f = this.wx.y;
            if (!a.cp && isNaN_(f)) {
                f = 0;
            }
            f = e.top + e.height * (f - this.cj.by.top) / this.cj.by.height;
            let g = a.me({ $type: Point_$type, x: d, y: f }, c, this.w4);
            this.w8(g, b, a);
        }
        w8(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.wn();
            d.h = this.wo();
            if (d.g == null) {
                d.g = this.w1.cf(c.jv);
            }
            if (d.h == null) {
                d.h = this.w1.cf(c.jv);
            }
            d.d = this.hk;
            d.f = Base.getHashCodeStatic(c);
            if (!a.isEmpty) {
                b.g.addItem(d.f, d);
            }
        }
        vx(a, b) {
            super.vx(a, b);
            let c = this.w1.b8;
            let d = a;
            let e = 0;
            for (let f of fromEnum(d.g.values)) {
                let g = c.item(e);
                this.xa(f, g);
                e++;
            }
            c.count = e;
        }
        fm() {
            return true;
        }
        xa(a, b) {
            if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
                b._visibility = 1;
                return;
            }
            this.w1.ca(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.s7 != null) {
                b.ai = this.s7;
            }
            else {
                b.ai = null;
            }
            b.aj = this.s8;
            b.am = this.ta;
            b.al = this.s9;
            b.ak = this.s9;
            b.ac = this.il;
        }
        o8(a, b, c, d) {
            super.o8(a, b, c, d);
            switch (b) {
                case CategoryHighlightLayer.$$p[0]:
                    this.pp(true);
                    break;
                case CategoryHighlightLayer.$$p[1]:
                    this.pp(true);
                    break;
            }
        }
    }
    CategoryHighlightLayer.$t = /*@__PURE__*/ markType(CategoryHighlightLayer, 'CategoryHighlightLayer', AnnotationLayer.$);
    CategoryHighlightLayer.xb = /*@__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:w0:xc', [CategoryAxisBase.$, null], 'UseInterpolation:w3:xd', [0, false]]);
    return CategoryHighlightLayer;
})();
/**
 * @hidden
 */
export let CategoryHighlightLayerView = /*@__PURE__*/ (() => {
    class CategoryHighlightLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            this.b7 = null;
            this.b8 = null;
            this.b9 = null;
            this.b7 = a;
            this.b9 = new List$1(Rectangle.$, 0);
        }
        au() {
            super.au();
            this.b8 = ((() => {
                let $ret = new Pool$1(Rectangle.$);
                $ret.create = runOn(this, this.cg);
                $ret.activate = runOn(this, this.cb);
                $ret.disactivate = runOn(this, this.cd);
                $ret.destroy = runOn(this, this.cc);
                return $ret;
            })());
        }
        cg() {
            let a = new Rectangle();
            a.ab = false;
            this.b9.add(a);
            return a;
        }
        cb(a) {
            a._visibility = 0;
        }
        cd(a) {
            a._visibility = 1;
        }
        cc(a) {
            this.b9.remove(a);
        }
        ce(a) {
            if (a == null) {
                return a;
            }
            return BrushUtil.m(a, 0.1);
        }
        cf(a) {
            if (a != null) {
                let b = BrushUtil.m(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;
            }
        }
        ca(a, b, c, d, e) {
            a._visibility = 0;
            a.n = b;
            a.o = c;
            a.width = d;
            a.height = e;
        }
        a8(a, b) {
            super.a8(a, b);
            if (a.d && !b) {
                for (let c = 0; c < this.b9.count; c++) {
                    let d = this.b9._inner[c];
                    if (d._visibility == 0) {
                        a.w(d);
                    }
                }
            }
        }
        an(a) {
            super.an(a);
            for (let b = 0; b < this.b9.count; b++) {
                this.e.a9.exportRectangleData(a, this.b9._inner[b], "cihRect", ["Main", "CategoryItem"]);
            }
        }
    }
    CategoryHighlightLayerView.$t = /*@__PURE__*/ markType(CategoryHighlightLayerView, 'CategoryHighlightLayerView', AnnotationLayerView.$);
    return CategoryHighlightLayerView;
})();
