/*
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 { Series } from "./Series";
import { DependencyProperty } from "igniteui-angular-core";
import { CategoryItemHighlightType_$type } from "./CategoryItemHighlightType";
import { MarkerType_$type } from "./MarkerType";
import { Brush } from "igniteui-angular-core";
import { DataTemplate } from "igniteui-angular-core";
import { CategoryItemHighlightLayerFrame } from "./CategoryItemHighlightLayerFrame";
import { Base, enumGetBox, fromEnum, typeCast, Point_$type, markType, markDep, runOn } from "igniteui-angular-core";
import { Dictionary$2 } from "igniteui-angular-core";
import { ItemHighlightFrameRect } from "./ItemHighlightFrameRect";
import { List$1 } from "igniteui-angular-core";
import { IHasCategoryModePreference_$type } from "./IHasCategoryModePreference";
import { Rect } from "igniteui-angular-core";
import { MarkerSeries } from "./MarkerSeries";
import { DataContext } from "igniteui-angular-core";
import { Pool$1 } from "igniteui-angular-core";
import { Rectangle } from "igniteui-angular-core";
import { ContentControl } from "igniteui-angular-core";
import { PropertyMetadata } from "igniteui-angular-core";
import { isNaN_, isInfinity, truncate } from "igniteui-angular-core";
import { AnnotationLayerView } from "./AnnotationLayerView";
import { Marker } from "./Marker";
import { BrushUtil } from "igniteui-angular-core";
import { Color } from "igniteui-angular-core";
import { DataTemplatePassInfo } from "igniteui-angular-core";
import { DataTemplateRenderInfo } from "igniteui-angular-core";
import { DataTemplateMeasureInfo } from "igniteui-angular-core";
/**
 * @hidden
 */
export let CategoryItemHighlightLayer = /*@__PURE__*/ (() => {
    class CategoryItemHighlightLayer extends AnnotationLayer {
        constructor() {
            super();
            this.aal = false;
            this.aak = true;
            this.aao = 10;
            let a = new CategoryItemHighlightLayerFrame();
            let b = new CategoryItemHighlightLayerFrame();
            let c = new CategoryItemHighlightLayerFrame();
            this.xm = a;
            this.xl = b;
            this.xn = c;
            this.ab = CategoryItemHighlightLayer.$;
        }
        bk() {
            return new CategoryItemHighlightLayer();
        }
        get_et() {
            return true;
        }
        ct() {
            return new CategoryItemHighlightLayerView(this);
        }
        q7(a) {
            super.q7(a);
            this.aaf = a;
        }
        y1(a, b) {
            if (this.aaj == null || this.aaj == a) {
                if (!this.a1.c) {
                    this.ry(b);
                }
            }
        }
        xs(a) {
            if (!super.xs(a)) {
                return false;
            }
            if (this.aax != null) {
                if (a.isFragment) {
                    let b = a.nh();
                    if (!Base.equalsStatic(this.aax, b)) {
                        return false;
                    }
                }
                else {
                    if (!Base.equalsStatic(this.aax, a.name)) {
                        return false;
                    }
                }
            }
            let c = this.yw(a);
            if (!c.c) {
                return false;
            }
            return true;
        }
        y3(a, b) {
            super.y3(a, b);
            let c = a;
            let d = this.aan;
            c.g.clear();
            if (isNaN_(this.aac.x) && isNaN_(this.aac.y)) {
                return;
            }
            if (this.xs(this.aaj)) {
                this.aa3(this.aaj, c, d);
            }
            else {
                for (let e of fromEnum(this.dc.series)) {
                    if (this.xs(e)) {
                        this.aa3(e, c, d);
                    }
                    if (e.isStacked) {
                        e.p9((f) => {
                            if (this.xs(f)) {
                                this.aa3(f, c, d);
                            }
                            if (f.ei) {
                                f.p7((g) => {
                                    if (this.xs(g)) {
                                        this.aa3(g, c, d);
                                    }
                                    return true;
                                });
                            }
                            return true;
                        });
                    }
                    if (e.ei) {
                        e.p7((f) => {
                            if (this.xs(f)) {
                                this.aa3(f, c, d);
                            }
                            return true;
                        });
                    }
                }
            }
        }
        rg(a, b, c, d) {
            super.rg(a, b, c, d);
            switch (b) {
                case CategoryItemHighlightLayer.$$p[4]:
                case CategoryItemHighlightLayer.$$p[5]:
                case CategoryItemHighlightLayer.$$p[2]:
                case CategoryItemHighlightLayer.$$p[3]:
                    this.ry(true);
                    break;
                case CategoryItemHighlightLayer.$$p[7]:
                case CategoryItemHighlightLayer.$$p[8]:
                    this.ry(true);
                    break;
                case CategoryItemHighlightLayer.$$p[9]:
                    this.aal = d;
                    this.ry(true);
                    break;
                case CategoryItemHighlightLayer.$$p[1]:
                    this.ry(true);
                    break;
                case CategoryItemHighlightLayer.$$p[0]:
                    this.aao = this.aap;
                    this.ry(true);
                    break;
                case CategoryItemHighlightLayer.$$p[6]:
                    this.aak = d;
                    this.ry(true);
                    break;
            }
        }
        aa3(a, b, c) {
            if (this.cw == null || this.cw.ca.isEmpty || this.cw.b9.isEmpty) {
                return;
            }
            if (!a.e0 && !a.e8) {
                return;
            }
            let d = a;
            if (d.categoryAxis == null) {
                return;
            }
            let e = this.aac.x;
            e = this.cw.b9.left + this.cw.b9.width * (e - this.cw.ca.left) / this.cw.ca.width;
            let f = this.aac.y;
            f = this.cw.b9.top + this.cw.b9.height * (f - this.cw.ca.top) / this.cw.ca.height;
            let g = this.aam;
            let h = true;
            let i = typeCast(IHasCategoryModePreference_$type, a);
            let j = 0;
            if (i != null) {
                j = i.preferredCategoryMode(d.categoryAxis);
                if (j == 2) {
                    h = false;
                }
            }
            let k = true;
            if (!h || this.aag == 2) {
                k = false;
            }
            if (this.aag == 1) {
                k = true;
            }
            let l = this.yw(a);
            if (!l.c) {
                return;
            }
            if (k) {
                let m = a.wm(l.d, this.aan, g);
                if (j != 0 && !d.categoryAxis.dm) {
                    let n = m.x;
                    if (a.e8) {
                        n -= a.getOffsetValue();
                        n += a.getCategoryWidth() * 0.5;
                        m = { $type: Point_$type, x: n, y: m.y };
                    }
                    else if (a.e0) {
                        n -= a.getOffsetValue();
                        n += a.getCategoryWidth() * 0.5;
                        m = { $type: Point_$type, x: n, y: m.y };
                    }
                }
                if (!isNaN_(m.x) && !isNaN_(m.y)) {
                    m = this.wr(m);
                }
                this.aa1(m, b, a);
            }
            else {
                let o = a.wm(l.d, this.aan, g);
                let p;
                let q = this.getEffectiveViewport1(this.cw);
                if (a.isVertical) {
                    let r = o.y;
                    let s = d.categoryAxis;
                    let t = this.aao;
                    if (j != 0) {
                        t = s.ou(this.cw.ca, this.cw.b9, q);
                    }
                    if (isNaN_(t) || isInfinity(t)) {
                        return;
                    }
                    p = new Rect(0, this.w2.left, r - t / 2, this.w2.width, t);
                }
                else {
                    let u = o.x;
                    let v = d.categoryAxis;
                    let w = this.aao;
                    if (j != 0) {
                        w = v.ou(this.cw.ca, this.cw.b9, q);
                    }
                    if (isNaN_(w) || isInfinity(w)) {
                        return;
                    }
                    p = new Rect(0, u - w / 2, this.w2.top, w, this.w2.height);
                }
                p.intersect(this.cw.b9);
                this.aa2(p, b, a);
            }
        }
        aa1(a, b, c) {
            let d = new ItemHighlightFrameRect();
            d.b = a.x;
            d.e = a.y;
            d.i = this.zy();
            if (this.abh != null) {
                d.i = this.abh;
            }
            d.j = this.zz();
            if (this.abi != null) {
                d.j = this.abi;
            }
            if (d.i == null) {
                if (c.hasMarkers) {
                    d.i = this.aaf.c1(c.vv());
                }
                else {
                    d.i = this.aaf.c1(c.vj);
                }
            }
            if (d.j == null) {
                if (c.hasMarkers) {
                    d.j = this.aaf.c1(c.vw());
                }
                else {
                    d.j = this.aaf.c1(c.vn);
                }
            }
            d.d = this.ig;
            d.f = Base.getHashCodeStatic(c);
            d.g = this.aah(c, a);
            let e = (typeCast(MarkerSeries.$, c) !== null) ? c.ya : null;
            if (e == null || e == MarkerSeries.yd || (this.aai != 2 && this.aai != 0)) {
                let f = MarkerSeries.xl(c, 2);
                if (this.aai != 2 && this.aai != 0) {
                    f = this.aai;
                }
                switch (f) {
                    case 3:
                    case 13:
                        e = this.dc.td;
                        break;
                    case 4:
                        e = this.dc.tm;
                        break;
                    case 5:
                        e = this.dc.tj;
                        break;
                    case 6:
                        e = this.dc.tk;
                        break;
                    case 7:
                        e = this.dc.te;
                        break;
                    case 8:
                        e = this.dc.th;
                        break;
                    case 9:
                        e = this.dc.tf;
                        break;
                    case 10:
                        e = this.dc.tl;
                        break;
                    case 11:
                        e = this.dc.ti;
                        break;
                    case 12:
                        e = this.dc.tg;
                        break;
                }
            }
            d.h = this.aa6 != null ? this.aa6 : e;
            if (!isNaN_(d.b) && !isNaN_(d.e)) {
                b.g.addItem(d.f, d);
            }
        }
        aah(a, b) {
            let c = a.kr(b);
            let d = a.it(b);
            if (this.aan && d != Math.floor(d)) {
                c = null;
            }
            return ((() => {
                let $ret = new DataContext();
                $ret.series = a;
                $ret.item = c;
                return $ret;
            })());
        }
        aa2(a, b, c) {
            let d = new ItemHighlightFrameRect();
            d.b = a.left;
            d.e = a.top;
            d.c = a.right;
            d.a = a.bottom;
            d.i = this.zy();
            d.j = this.zz();
            if (d.i == null) {
                if (c != null) {
                    d.i = this.aaf.c2(c.vj);
                }
            }
            if (d.j == null) {
                if (c != null) {
                    d.j = this.aaf.c2(c.vn);
                }
            }
            d.d = this.ig;
            d.f = Base.getHashCodeStatic(c);
            if (!a.isEmpty) {
                b.g.addItem(d.f, d);
            }
        }
        y6(a, b) {
            super.y6(a, b);
            let c = this.aaf.cp;
            let d = this.aaf.co;
            let e = 0;
            let f = 0;
            let g = a;
            for (let h of fromEnum(g.g.values)) {
                if (h.h != null) {
                    let i = d.item(f);
                    this.aa4(h, i);
                    f++;
                }
                else {
                    let j = c.item(e);
                    this.aa5(h, j);
                    e++;
                }
            }
            c.count = e;
            d.count = f;
        }
        aa4(a, b) {
            if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.d) || a.g == null) {
                b._visibility = 1;
                return;
            }
            let c = { $type: Point_$type, x: a.b, y: a.e };
            let d = a.g;
            d.itemBrush = a.i;
            let e = d.series.wm(c, this.d4() || this.aal, this.aak);
            if (isNaN_(e.x) || isNaN_(e.y)) {
                b._visibility = 1;
                return;
            }
            this.aaf.cv(b, e.x, e.y);
            b.ah = a.h;
            b.content = a.g;
        }
        aa5(a, b) {
            if (isNaN_(a.b) || isNaN_(a.e) || isNaN_(a.a) || isNaN_(a.c) || isNaN_(a.d)) {
                b._visibility = 1;
                return;
            }
            this.aaf.cw(b, a.b, a.e, a.c - a.b, a.a - a.e);
            b._fill = a.i;
            b._stroke = a.j;
            b.ad = a.d;
            if (this.wc != null) {
                b.ai = this.wc;
            }
            else {
                b.ai = null;
            }
            b.aj = this.wd;
            b.am = this.wf;
            b.al = this.we;
            b.ak = this.we;
            b.ac = this.jk;
        }
        gb() {
            return true;
        }
    }
    CategoryItemHighlightLayer.$t = markType(CategoryItemHighlightLayer, 'CategoryItemHighlightLayer', AnnotationLayer.$);
    CategoryItemHighlightLayer.$$p = markDep(DependencyProperty, PropertyMetadata, CategoryItemHighlightLayer, 'raisePropertyChanged', ['BandHighlightWidth:aap:aa7', [1, 10], 'HighlightType:aag:aa8', [CategoryItemHighlightType_$type, enumGetBox(CategoryItemHighlightType_$type, 0)], 'MarkerBrush:abh:aa9', [Brush.$, null], 'MarkerOutline:abi:aba', [Brush.$, null], 'MarkerTemplate:aa6:abb', [DataTemplate.$, null], 'MarkerType:aai:abc', [MarkerType_$type, enumGetBox(MarkerType_$type, 2)], 'SkipUnknownValues:aam:abd', [0, true], 'TargetSeriesName:aax:abe', [2, null], 'TargetSeries:aaj:abf', [Series.$, null], 'UseInterpolation:aan:abg', [0, false]]);
    return CategoryItemHighlightLayer;
})();
/**
 * @hidden
 */
export let CategoryItemHighlightLayerView = /*@__PURE__*/ (() => {
    class CategoryItemHighlightLayerView extends AnnotationLayerView {
        constructor(a) {
            super(a);
            this.cn = null;
            this.cp = null;
            this.co = null;
            this.cq = null;
            this.cr = null;
            this.cn = a;
            this.cq = new List$1(ContentControl.$, 0);
            this.cr = new List$1(Rectangle.$, 0);
        }
        a4() {
            super.a4();
            this.cp = ((() => {
                let $ret = new Pool$1(Rectangle.$);
                $ret.create = runOn(this, this.c3);
                $ret.activate = runOn(this, this.cx);
                $ret.disactivate = runOn(this, this.cz);
                $ret.destroy = runOn(this, this.cy);
                return $ret;
            })());
            this.co = ((() => {
                let $ret = new Pool$1(ContentControl.$);
                $ret.create = runOn(this, this.c0);
                $ret.activate = runOn(this, this.cs);
                $ret.disactivate = runOn(this, this.cu);
                $ret.destroy = runOn(this, this.ct);
                return $ret;
            })());
        }
        c3() {
            let a = new Rectangle();
            a.ab = false;
            this.cr.add(a);
            return a;
        }
        cx(a) {
            a._visibility = 0;
        }
        cz(a) {
            a._visibility = 1;
        }
        cy(a) {
            this.cr.remove(a);
        }
        c0() {
            let a = new Marker();
            this.cq.add(a);
            return a;
        }
        cs(a) {
            a._visibility = 0;
        }
        cu(a) {
            a._visibility = 1;
        }
        ct(a) {
            this.cq.remove(a);
        }
        c1(a) {
            if (a == null) {
                return a;
            }
            return BrushUtil.o(a, 0.3);
        }
        c2(a) {
            if (a != null) {
                let b = BrushUtil.o(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.3)), e.color.o, e.color.n, e.color.m);
                            e.color = e.color;
                        }
                    }
                }
                else {
                    b.color = Color.u(truncate(Math.round((b.color.l & 255) * 0.3)), b.color.o, b.color.n, b.color.m);
                    b.color = b.color;
                }
                return b;
            }
            else {
                return null;
            }
        }
        cw(a, b, c, d, e) {
            a._visibility = 0;
            a.n = b;
            a.o = c;
            a.width = d;
            a.height = e;
        }
        cv(a, b, c) {
            a.n = b;
            a.o = c;
        }
        bv(a, b) {
            super.bv(a, b);
            let c = a;
            let d = c.content;
            if (d != null) {
                if (d.itemBrush != null) {
                    d.actualItemBrush = d.itemBrush;
                }
                let e = d.series;
                if (e.hasMarkers) {
                    d.outline = e.vw();
                }
                d.thickness = e.ip();
            }
        }
        bj(a, b) {
            super.bj(a, b);
            if (a.d && !b) {
                for (let c = 0; c < this.cr.count; c++) {
                    let d = this.cr._inner[c];
                    if (d._visibility == 0) {
                        a.w(d);
                    }
                }
                if (this.cq.count > 0) {
                    let e = new DataTemplatePassInfo();
                    e.isHitTestRender = b;
                    e.context = a.h();
                    e.viewportTop = this.b9.top;
                    e.viewportLeft = this.b9.left;
                    e.viewportWidth = this.b9.width;
                    e.viewportHeight = this.b9.height;
                    e.passID = "ItemMarkers";
                    let f = new DataTemplateRenderInfo();
                    f.isHitTestRender = b;
                    f.passInfo = e;
                    let g = new DataTemplateMeasureInfo();
                    g.passInfo = e;
                    let h = false;
                    let i = a.h();
                    g.context = i;
                    f.context = i;
                    g.renderContext = a;
                    f.renderContext = a;
                    let j = 0;
                    let k = 0;
                    let l = new Dictionary$2(DataTemplate.$, DataTemplate.$, 0);
                    for (let m = 0; m < this.cq.count; m++) {
                        let n = this.cq._inner[m];
                        if (n == null || n.ah == null) {
                            continue;
                        }
                        let o = n.ah;
                        if (!l.containsKey(o)) {
                            l.addItem(o, o);
                            if (o != null && o.passStarting != null) {
                                o.passStarting(e);
                            }
                        }
                        if (n._visibility == 1) {
                            continue;
                        }
                        this.bu(n, m, b);
                        if (!h) {
                            g.data = n.content;
                            g.width = n.width;
                            g.height = n.height;
                            if (o.measure != null) {
                                g.data = n.content;
                                o.measure(g);
                                h = g.isConstant;
                                if (h) {
                                    j = g.width;
                                    k = g.height;
                                }
                            }
                            f.availableWidth = g.width;
                            f.availableHeight = g.height;
                        }
                        else {
                            f.availableWidth = j;
                            f.availableHeight = k;
                        }
                        if (!isNaN_(n.width) && !isInfinity(n.width)) {
                            f.availableWidth = n.width;
                        }
                        if (!isNaN_(n.height) && !isInfinity(n.height)) {
                            f.availableHeight = n.height;
                        }
                        a.q(f, n);
                        n.m = f.availableWidth;
                        n.l = f.availableHeight;
                    }
                    for (let p of fromEnum(l.keys)) {
                        if (p != null && p.passCompleted != null) {
                            p.passCompleted(e);
                        }
                    }
                }
            }
        }
        ax(a) {
            super.ax(a);
            for (let b = 0; b < this.cr.count; b++) {
                this.f.bc.exportRectangleData(a, this.cr._inner[b], "catItemRect", ["Main", "CategoryItem"]);
            }
            for (let c = 0; c < this.cq.count; c++) {
                this.f.bc.exportMarkerVisualDataFromMarker(this.f, a, this.cq._inner[c]);
            }
        }
    }
    CategoryItemHighlightLayerView.$t = markType(CategoryItemHighlightLayerView, 'CategoryItemHighlightLayerView', AnnotationLayerView.$);
    return CategoryItemHighlightLayerView;
})();
