/*
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-angular-core";
import { CategoryHighlightLayerFrame } from "./CategoryHighlightLayerFrame";
import { Base, Number_$type, typeCast, fromEnum, Point_$type, markType, markDep, runOn } from "igniteui-angular-core";
import { XamDataChart } from "./XamDataChart";
import { CategoryHighlightFrameRect } from "./CategoryHighlightFrameRect";
import { List$1 } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { Rectangle } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_, truncate } from "igniteui-angular-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { BrushUtil } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
/**
 * @hidden
 */
export let CategoryHighlightLayer = /*@__PURE__*/ (() => {
    class CategoryHighlightLayer extends AnnotationLayer {
        constructor() {
            super();
            let a = new CategoryHighlightLayerFrame();
            let b = new CategoryHighlightLayerFrame();
            let c = new CategoryHighlightLayerFrame();
            let d = this.hm / 1000;
            this.p5 = a;
            this.p4 = b;
            this.p6 = c;
            this.ab = CategoryHighlightLayer.$;
        }
        get_db() {
            return true;
        }
        bx() {
            return new CategoryHighlightLayerView(this);
        }
        ly(a) {
            super.ly(a);
            this.q8 = a;
        }
        get rb() {
            return this.c(CategoryHighlightLayer.ri);
        }
        set rb(a) {
            this.h(CategoryHighlightLayer.ri, a);
        }
        qn(a, b) {
            if (this.q7 == null || this.q7 == a) {
                if (!this.as.c) {
                    this.mh(b);
                }
            }
        }
        q9(a) {
            return a != null && a.cn();
        }
        qq(a, b) {
            super.qq(a, b);
            let c = a;
            c.g.clear();
            let d = this.ra;
            if (isNaN_(this.q4.x) && isNaN_(this.q4.y)) {
                return;
            }
            if (this.q7 != null) {
                if (this.q9(this.q7)) {
                    this.rg(this.q7, c, d);
                }
            }
            else {
                if (typeCast(XamDataChart.$, this.cd) !== null) {
                    let e = this.cd;
                    for (let f of fromEnum(e.axes)) {
                        if (typeCast(CategoryAxisBase.$, f) !== null && this.q9(f)) {
                            this.rg(f, c, d);
                        }
                    }
                }
            }
        }
        rg(a, b, c) {
            if (this.b0 == null || this.b0.bv.isEmpty || this.b0.bu.isEmpty) {
                return;
            }
            let d = this.q4.x;
            if (a.co && isNaN_(d)) {
                d = 0;
            }
            let e = this.pq(this.b0);
            d = e.left + e.width * (d - this.b0.bv.left) / this.b0.bv.width;
            let f = this.q4.y;
            if (!a.co && isNaN_(f)) {
                f = 0;
            }
            f = e.top + e.height * (f - this.b0.bv.top) / this.b0.bv.height;
            let g = a.md({ $type: Point_$type, x: d, y: f }, c, this.rb);
            this.rf(g, b, a);
        }
        rf(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.q2();
            d.h = this.q3();
            if (d.g == null) {
                d.g = this.q8.cc(c.ju);
            }
            if (d.h == null) {
                d.h = this.q8.cc(c.ju);
            }
            d.d = this.fu;
            d.f = Base.getHashCodeStatic(c);
            if (!a.isEmpty) {
                b.g.addItem(d.f, d);
            }
        }
        qt(a, b) {
            super.qt(a, b);
            let c = this.q8.b5;
            let d = a;
            let e = 0;
            for (let f of fromEnum(d.g.values)) {
                let g = c.item(e);
                this.rh(f, g);
                e++;
            }
            c.count = e;
        }
        em() {
            return true;
        }
        rh(a, b) {
            if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
                b._visibility = 1;
                return;
            }
            this.q8.b7(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.pb != null) {
                b.ai = this.pb;
            }
            else {
                b.ai = null;
            }
            b.ad = this.pc;
        }
        l3(a, b, c, d) {
            super.l3(a, b, c, d);
            switch (b) {
                case CategoryHighlightLayer.$$p[0]:
                    this.mh(true);
                    break;
                case CategoryHighlightLayer.$$p[1]:
                    this.mh(true);
                    break;
            }
        }
    }
    CategoryHighlightLayer.$t = markType(CategoryHighlightLayer, 'CategoryHighlightLayer', AnnotationLayer.$);
    CategoryHighlightLayer.ri = DependencyProperty.i("BAndHighlightWidth", Number_$type, CategoryHighlightLayer.$, new PropertyMetadata(2, 10, (a, b) => a.raisePropertyChanged("BAndHighlightWidth", b.oldValue, b.newValue)));
    CategoryHighlightLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryHighlightLayer, 'raisePropertyChanged', ['TargetAxis:q7:rj', [CategoryAxisBase.$, null], 'UseInterpolation:ra:rk', [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.v(d);
                    }
                }
            }
        }
        al(a) {
            super.al(a);
            for (let b = 0; b < this.b6.count; b++) {
                this.e.a8.exportRectangleData(a, this.b6._inner[b], "cihRect", ["Main", "CategoryItem"]);
            }
        }
    }
    CategoryHighlightLayerView.$t = markType(CategoryHighlightLayerView, 'CategoryHighlightLayerView', AnnotationLayerView.$);
    return CategoryHighlightLayerView;
})();
