/*
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 {
        bj() {
            return new CategoryHighlightLayer();
        }
        get_er() {
            return true;
        }
        constructor() {
            super();
            let a = new CategoryHighlightLayerFrame();
            let b = new CategoryHighlightLayerFrame();
            let c = new CategoryHighlightLayerFrame();
            let d = this.kd / 1000;
            this.xa = a;
            this.w9 = b;
            this.xb = c;
            this.ab = CategoryHighlightLayer.$;
        }
        cs() {
            return new CategoryHighlightLayerView(this);
        }
        qz(a) {
            super.qz(a);
            this.zw = a;
        }
        get zz() {
            return this.c(CategoryHighlightLayer.z6);
        }
        set zz(a) {
            this.h(CategoryHighlightLayer.z6, a);
        }
        ym(a, b) {
            if (this.zv == null || this.zv == a) {
                if (!this.a1.c) {
                    this.rp(b);
                }
            }
        }
        zx(a) {
            return a != null && a.co();
        }
        yp(a, b) {
            super.yp(a, b);
            let c = a;
            c.g.clear();
            let d = this.zy;
            if (isNaN_(this.zs.x) && isNaN_(this.zs.y)) {
                return;
            }
            if (this.zv != null) {
                if (this.zx(this.zv)) {
                    this.z4(this.zv, c, d);
                }
            }
            else {
                if (typeCast(XamDataChart.$, this.db) !== null) {
                    let e = this.db;
                    for (let f of fromEnum(e.axes)) {
                        if (typeCast(CategoryAxisBase.$, f) !== null && this.zx(f)) {
                            this.z4(f, c, d);
                        }
                    }
                }
            }
        }
        z4(a, b, c) {
            if (this.cv == null || this.cv.by.isEmpty || this.cv.bx.isEmpty) {
                return;
            }
            let d = this.zs.x;
            if (a.cp && isNaN_(d)) {
                d = 0;
            }
            let e = this.wh(this.cv);
            d = e.left + e.width * (d - this.cv.by.left) / this.cv.by.width;
            let f = this.zs.y;
            if (!a.cp && isNaN_(f)) {
                f = 0;
            }
            f = e.top + e.height * (f - this.cv.by.top) / this.cv.by.height;
            let g = a.mj({ $type: Point_$type, x: d, y: f }, c, this.zz);
            this.z3(g, b, a);
        }
        z3(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.zi();
            d.h = this.zj();
            if (d.g == null) {
                d.g = this.zw.cf(c.jy);
            }
            if (d.h == null) {
                d.h = this.zw.cf(c.jy);
            }
            d.d = this.ie;
            d.f = Base.getHashCodeStatic(c);
            if (!a.isEmpty) {
                b.g.addItem(d.f, d);
            }
        }
        ys(a, b) {
            super.ys(a, b);
            let c = this.zw.b8;
            let d = a;
            let e = 0;
            for (let f of fromEnum(d.g.values)) {
                let g = c.item(e);
                this.z5(f, g);
                e++;
            }
            c.count = e;
        }
        ga() {
            return true;
        }
        z5(a, b) {
            if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
                b._visibility = 1;
                return;
            }
            this.zw.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.v0 != null) {
                b.ai = this.v0;
            }
            else {
                b.ai = null;
            }
            b.aj = this.v1;
            b.am = this.v3;
            b.al = this.v2;
            b.ak = this.v2;
            b.ac = this.jh;
        }
        q7(a, b, c, d) {
            super.q7(a, b, c, d);
            switch (b) {
                case CategoryHighlightLayer.$$p[0]:
                    this.rp(true);
                    break;
                case CategoryHighlightLayer.$$p[1]:
                    this.rp(true);
                    break;
            }
        }
    }
    CategoryHighlightLayer.$t = /*@__PURE__*/ markType(CategoryHighlightLayer, 'CategoryHighlightLayer', AnnotationLayer.$);
    CategoryHighlightLayer.z6 = /*@__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:zv:z7', [CategoryAxisBase.$, null], 'UseInterpolation:zy:z8', [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.bc.exportRectangleData(a, this.b9._inner[b], "cihRect", ["Main", "CategoryItem"]);
            }
        }
    }
    CategoryHighlightLayerView.$t = /*@__PURE__*/ markType(CategoryHighlightLayerView, 'CategoryHighlightLayerView', AnnotationLayerView.$);
    return CategoryHighlightLayerView;
})();
