/*
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 { ScatterBase } from "./ScatterBase";
import { IScaleLegendSeries_$type } from "igniteui-react-core";
import { ISupportsSizeScale_$type } from "./ISupportsSizeScale";
import { ISupportsFillScale_$type } from "./ISupportsFillScale";
import { List$1 } from "igniteui-react-core";
import { UIElement } from "igniteui-react-core";
import { Base, typeCast, Point_$type, fromEnum, markType, markDep, enumGetBox, runOn } from "igniteui-react-core";
import { ActualRange } from "./ActualRange";
import { DependencyProperty } from "igniteui-react-core";
import { SizeScale } from "./SizeScale";
import { BrushScale } from "./BrushScale";
import { ScatterFrame } from "./ScatterFrame";
import { IChartLegend_$type } from "igniteui-react-core";
import { ValueBrushScale } from "./ValueBrushScale";
import { IFastItemsSource_$type } from "igniteui-react-core";
import { ScatterBaseView } from "./ScatterBaseView";
import { ScalerParams } from "./ScalerParams";
import { OwnedPoint } from "./OwnedPoint";
import { Dictionary$2 } from "igniteui-react-core";
import { BubbleMarkerManager } from "./BubbleMarkerManager";
import { IChartItemLegend_$type } from "igniteui-react-core";
import { IChartScaleLegend_$type } from "igniteui-react-core";
import { ContentControl } from "igniteui-react-core";
import { DataContext } from "igniteui-react-core";
import { DeviceUtils } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { PropertyMetadata } from "igniteui-react-core";
import { isNaN_, isInfinity, logBase } from "igniteui-react-core";
import { stringIsNullOrEmpty } from "igniteui-react-core";
import { BrushSelectionMode_$type } from "./BrushSelectionMode";
import { ScatterTrendLineManager } from "./ScatterTrendLineManager";
/**
 * @hidden
 */
export let BubbleSeries = /*@__PURE__*/ (() => {
    class BubbleSeries extends ScatterBase {
        constructor() {
            super();
            this.ub = null;
            this.ua = null;
            this.ta = null;
            this.s2 = null;
            this.s1 = null;
            this.s0 = null;
            this.ab = BubbleSeries.$;
            this.p8 = new ScatterFrame();
            this.qa = new ScatterFrame();
            this.p7 = new ScatterFrame();
        }
        bp() {
            return new BubbleSeriesView(this);
        }
        kk(a) {
            super.kk(a);
            this.sy = a;
        }
        fr() {
            return 0.7;
        }
        oc() {
            if (this.ob == 0) {
                return 2;
            }
            return super.oc();
        }
        isAttachedTo(a) {
            return this.az == a;
        }
        cv() {
            return true;
        }
        jx(a) {
            super.jx(a);
            if (this.s5 != null && this.ta != null && this.ta.count > 0) {
                for (let b = 0; b < this.ta.count; b++) {
                    a(this.ta._inner[b]);
                }
            }
        }
        get s4() {
            return this.s6;
        }
        t9(a) {
            let b = typeCast(CustomPaletteBrushScale.$, this.sx);
            let c = typeCast(ValueBrushScale.$, this.sx);
            let d = this.sx;
            if (b != null && this.cd != null) {
                return b.getBrush1(a, this.cd.count);
            }
            else if (c != null) {
                return c.getBrushByIndex(a, this.s3);
            }
            else if (d != null) {
                return d.getBrush(a);
            }
            return null;
        }
        get legendReady() {
            return this.s6 != null && this.s6.count != 0;
        }
        get minScaleText() {
            let a = this.sw(this.sz).b;
            return (Math.round(a * 1000) / 1000).toString();
        }
        get maxScaleText() {
            let a = this.sw(this.sz).a;
            return (Math.round(a * 1000) / 1000).toString();
        }
        forScaleColors(a) {
            for (let b = 0; b < this.s6.count; b++) {
                if (this.sx == null || !this.sx.isReady) {
                    return false;
                }
                let c = NaN;
                if (this.s3 != null) {
                    c = (this.s3.item(b) - this.s3.minimum) / (this.s3.maximum - this.s3.minimum);
                }
                let d = (this.s6.item(b) - this.s6.minimum) / (this.s6.maximum - this.s6.minimum);
                if (isNaN_(c)) {
                    c = 0;
                }
                if (isNaN_(d)) {
                    d = c;
                }
                let e = this.pj;
                let f = this.t9(b);
                let g = f != null ? f : e;
                a(g, d);
            }
            return true;
        }
        gt(a, b) {
            let c = this.ic(b);
            if (c == BubbleSeries.$$p[3]) {
                return this.gu(a, b, this.tl);
            }
            if (c == BubbleSeries.$$p[7]) {
                return this.gu(a, b, this.tr);
            }
            if (c == ScatterBase.$$p[8]) {
                return this.gu(a, b, this.rf);
            }
            if (c == ScatterBase.$$p[10]) {
                return this.gu(a, b, this.rj);
            }
            if (c == BubbleSeries.$$p[0]) {
                return this.gu(a, b, this.tg);
            }
            return super.gt(a, b);
        }
        get s6() {
            return this.s2;
        }
        set s6(a) {
            if (this.s2 != a) {
                let b = this.s6;
                this.s2 = a;
                this.raisePropertyChanged("RadiusColumn", b, this.s6);
            }
        }
        get s5() {
            return this.s1;
        }
        set s5(a) {
            if (this.s1 != a) {
                let b = this.s5;
                this.s1 = a;
                this.raisePropertyChanged("LabelColumn", b, this.s5);
            }
        }
        get s3() {
            return this.s0;
        }
        set s3(a) {
            if (this.s0 != a) {
                let b = this.s3;
                this.s0 = a;
                this.raisePropertyChanged("FillColumn", b, this.s3);
            }
        }
        rm(a, b, c, d, e) {
            if (c <= this.q3) {
                b.g = new Dictionary$2(Base.$, OwnedPoint.$, 1, c);
            }
            let f = this.q3;
            let g = this.cd;
            let h;
            let i;
            let j = this.getEffectiveViewport1(a);
            let k = new ScalerParams(0, d, e, this.p3.d, j);
            let l = new ScalerParams(0, d, e, this.p3.e, j);
            let m = false;
            let n = 0;
            if (this.b6 != null) {
                if (this.b6.ea()) {
                    let o = this.b6.ik(d, k);
                    m = o.c;
                    n = o.d;
                }
            }
            for (let p = 0; p < c; p++) {
                h = this.qi.item(p);
                i = this.qj.item(p);
                let q = { $type: Point_$type, x: this.p3.a.dz(h, k), y: this.p3.b.dz(i, l) };
                if (m) {
                    if (q.x < e.left || q.x > e.right) {
                        if (q.x + n >= e.left && q.x + n <= e.right) {
                            q = { $type: Point_$type, x: q.x + n, y: i };
                        }
                    }
                }
                if (!isInfinity(q.x) && !isInfinity(q.y)) {
                    let r = g.item(p);
                    if (c <= f) {
                        if (!b.g.containsKey(r)) {
                            let s = { $type: Point_$type, x: h, y: i };
                            b.g.addItem(r, ((() => {
                                let $ret = new OwnedPoint();
                                $ret.a = r;
                                $ret.b = s;
                                $ret.c = q;
                                return $ret;
                            })()));
                        }
                    }
                }
            }
        }
        ru(a, b) {
            let c = typeCast(BubbleSeriesView.$, b);
            let d = c.cv;
            d.m = this.s6;
            super.ru(a, b);
            let e = Math.min(this.qi != null ? this.qi.count : 0, this.qj != null ? this.qj.count : 0);
            if (e < 1) {
                return;
            }
            c.dh();
            c.di();
        }
        tw() {
            if (this.b6 == null) {
                return;
            }
            if (this.az == null) {
                return;
            }
            if (this.az.isItemwise) {
                let a = this.az;
                this.az.clearLegendItemsForSeries(this);
                this.tv();
                a.renderItemwiseContent(this);
            }
            if (this.az.isScale) {
                let b = this.az;
                b.restoreOriginalState();
                b.initializeLegend(this);
            }
        }
        static tb(a, b, c, d, e) {
            if (e <= a || isNaN_(e) || isInfinity(e)) {
                return c;
            }
            if (e >= b) {
                return d;
            }
            let f = c + ((d - c) / (b - a)) * (e - a);
            return f;
        }
        static tc(a, b, c, d, logBase_, e) {
            let f = logBase(e, logBase_);
            let g = logBase(a, logBase_);
            let h = logBase(b, logBase_);
            return BubbleSeries.tb(g, h, c, d, f);
        }
        ec(a, b, c) {
            let d = super.ec(a, b, c);
            if (this.s6 == null || this.cd == null || this.s6.count == 0 || this.cd.count != this.s6.count) {
                d = false;
            }
            return d;
        }
        qr(a, b) {
            if (b != 3) {
                return true;
            }
            if (a == null) {
                return true;
            }
            if (this.rf == a || this.rj == a || this.tr == a) {
                return true;
            }
            return false;
        }
        tv() {
            let a = typeCast(IChartLegend_$type, this.az);
            if (a == null || this.cd == null) {
                return;
            }
            this.ta = new List$1(UIElement.$, 0);
            let b = typeCast(CustomPaletteBrushScale.$, this.sx);
            let c = typeCast(ValueBrushScale.$, this.sx);
            let d = this.sx;
            let e = this.sv();
            let f = e.b;
            let g = e.a;
            let h = this.cd;
            for (let i = 0; i < h.count; i++) {
                let j = null;
                if (c != null && this.s3 != null) {
                    let k = this.s3.item(i);
                    j = c.getBrushByRange(k, f, g);
                }
                else if (b != null) {
                    j = b.getBrush1(i, h.count);
                }
                else if (d != null) {
                    j = d.getBrush(i);
                }
                let l = new ContentControl();
                let m = this.s5 != null && this.s5.item(i) != null ? this.s5.item(i).toString() : "";
                l.content = ((() => {
                    let $ret = new DataContext();
                    $ret.series = this;
                    $ret.item = h.item(i);
                    $ret.itemBrush = j;
                    $ret.itemLabel = m;
                    return $ret;
                })());
                let n = this.lt;
                if (n == null) {
                    n = this.bs.bl(this.by);
                }
                l.ah = n;
                this.ta.add(l);
            }
        }
        jo(a, b, c, d) {
            super.jo(a, b, c, d);
            if (this.sz != null) {
                this.sz.aa();
            }
            if (this.sx != null) {
                this.sx.w();
            }
            this.tw();
        }
        j4() {
            super.j4();
            this.tw();
        }
        j9() {
            super.j9();
            this.tw();
        }
        kp(a, b, c, d) {
            super.kp(a, b, c, d);
            switch (b) {
                case "FastItemsSource":
                    if (this.sz != null) {
                        this.sz.aa();
                    }
                    if (this.sx != null) {
                        this.sx.w();
                    }
                    if (typeCast(IFastItemsSource_$type, c) != null) {
                        c.deregisterColumn(this.s6);
                        c.deregisterColumn(this.s3);
                        c.deregisterColumn(this.s5);
                        this.s6 = null;
                        this.s3 = null;
                        this.s5 = null;
                    }
                    if (typeCast(IFastItemsSource_$type, d) != null) {
                        this.s6 = this.ca(this.tr);
                        if (!stringIsNullOrEmpty(this.tg)) {
                            this.s3 = this.ca(this.tg);
                        }
                        this.s5 = this.cc(this.tl);
                    }
                    this.k3(false);
                    this.tw();
                    break;
                case BubbleSeries.$$p[7]:
                    if (this.sz != null) {
                        this.sz.aa();
                    }
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.s6);
                        this.s6 = this.ca(this.tr);
                        this.tw();
                    }
                    break;
                case "RadiusColumn":
                    if (this.sz != null) {
                        this.sz.aa();
                    }
                    this.p4.cx.g$i();
                    this.k3(false);
                    this.kb();
                    break;
                case BubbleSeries.$$p[8]:
                    if (c != null) {
                        c.l.remove(this);
                        c.aa();
                    }
                    if (d != null) {
                        d.l.add(this);
                        d.aa();
                    }
                    this.k3(false);
                    this.ka();
                    break;
                case BubbleSeries.$$p[9]:
                    this.k3(false);
                    this.ka();
                    break;
                case "DiscreteLegendItemTemplate":
                    this.tw();
                    break;
                case BubbleSeries.$$p[1]:
                    if (c != null) {
                        c.o.remove(this);
                        c.w();
                    }
                    if (d != null) {
                        d.o.add(this);
                        d.w();
                    }
                    this.k3(false);
                    this.tw();
                    this.ka();
                    break;
                case BubbleSeries.$$p[2]:
                case BubbleSeries.$$p[6]:
                case BubbleSeries.$$p[5]:
                case BubbleSeries.$$p[4]:
                    this.k3(false);
                    this.tw();
                    this.ka();
                    break;
                case "FillColumn":
                    this.k3(false);
                    this.ka();
                    break;
                case BubbleSeries.$$p[0]:
                    if (this.sx != null) {
                        this.sx.w();
                    }
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.s3);
                        this.s3 = this.ca(this.tg);
                        this.tw();
                    }
                    break;
                case BubbleSeries.$$p[3]:
                    if (this.cd != null) {
                        this.cd.deregisterColumn(this.s5);
                        this.s5 = this.cc(this.tl);
                        this.tw();
                    }
                    break;
                case "ActualLegend":
                    let e = typeCast(IChartLegend_$type, c);
                    if (e != null && e.isItemwise) {
                        let f = typeCast(IChartItemLegend_$type, e);
                        f.clearLegendItemsForSeries(this);
                    }
                    if (e != null && e.isScale) {
                        let g = typeCast(IChartScaleLegend_$type, e);
                        let h = true;
                        let i = null;
                        if (this.b6 != null) {
                            for (let j of fromEnum(this.b6.series)) {
                                if (j.legend == g) {
                                    i = j;
                                    h = false;
                                }
                            }
                        }
                        if (h) {
                            g.restoreOriginalState();
                        }
                        else {
                            g.initializeLegend(typeCast(IScaleLegendSeries_$type, i));
                        }
                    }
                    this.tw();
                    break;
                case "SeriesViewer":
                    this.tw();
                    break;
            }
        }
        updateSizeScaleGlobals() {
            let a = new ActualRange();
            a.b = NaN;
            a.a = NaN;
            if (this.s6 != null) {
                a.b = this.s6.minimum;
                a.a = this.s6.maximum;
            }
            if (this.sz != null) {
                this.sz.ab(a.b, a.a);
            }
        }
        updateFillScaleGlobals() {
            let a = new ActualRange();
            a.b = NaN;
            a.a = NaN;
            if (this.s3 != null) {
                a.b = this.s3.minimum;
                a.a = this.s3.maximum;
            }
            if (this.sx != null) {
                this.sx.y(a.b, a.a);
            }
        }
        sw(a) {
            let b = new ActualRange();
            b.b = NaN;
            b.a = NaN;
            if (this.s6 != null) {
                b.b = this.s6.minimum;
                b.a = this.s6.maximum;
            }
            if (a != null) {
                a.x();
                if (this.s9) {
                    b.b = a.globalMinimum;
                    b.a = a.globalMaximum;
                }
            }
            return b;
        }
        sv() {
            let a = new ActualRange();
            a.b = NaN;
            a.a = NaN;
            if (this.s3 != null) {
                a.b = this.s3.minimum;
                a.a = this.s3.maximum;
            }
            let b = typeCast(ValueBrushScale.$, this.sx);
            if (b != null) {
                b.s();
                if (this.s7 && this.sx.o.count > 1) {
                    a.b = b.q;
                    a.a = b.p;
                }
            }
            return a;
        }
        ty(a, b, c, d) {
            let e = c.width;
            if (!this.bs.bu.isEmpty) {
                e = this.bs.bu.width;
            }
            else if (this.b6 != null && !this.b6.o7.isEmpty) {
                e = this.b6.o7.width;
            }
            let f = DeviceUtils.c(e);
            let g = this.sz || ((() => {
                let $ret = new SizeScale();
                $ret.minimumValue = f / 10;
                $ret.maximumValue = f / 5;
                return $ret;
            })());
            if (g != null) {
                let h = g.minimumValue;
                let i = g.maximumValue;
                let j = g.logarithmBase;
                let k = this.sw(g);
                let l = k.b;
                let m = k.a;
                if (g.isLogarithmic) {
                    for (let n = 0; n < b.count; n++) {
                        b._inner[n] = BubbleSeries.tc(l, m, h, i, j, b._inner[n]);
                    }
                }
                else {
                    for (let o = 0; o < b.count; o++) {
                        b._inner[o] = BubbleSeries.tb(l, m, h, i, b._inner[o]);
                    }
                }
            }
            let p = 1;
            p = DeviceUtils.d();
            let q = this.sz == null;
            if (d) {
                let r = c.width / e;
                for (let s = 0; s < b.count; s++) {
                    if (q) {
                        b._inner[s] = b._inner[s] / p;
                    }
                    b._inner[s] = b._inner[s] * r;
                }
            }
            for (let t = 0; t < a.count; t++) {
                let u = a._inner[t];
                if (q && !d) {
                    u.width = Math.max(0, b._inner[t] / p);
                    u.height = Math.max(0, b._inner[t] / p);
                }
                else {
                    u.width = Math.max(0, b._inner[t]);
                    u.height = Math.max(0, b._inner[t]);
                }
            }
        }
        tx(a) {
            let b = typeCast(BubbleSeriesView.$, this.br);
            this.sy.b3 = false;
            if (b != null) {
                b.b3 = false;
            }
            let c = typeCast(CustomPaletteBrushScale.$, this.sx);
            let d = typeCast(ValueBrushScale.$, this.sx);
            let e = this.sx;
            let f = this.sv();
            let g = f.b;
            let h = f.a;
            let i = this.sx == null || !this.sx.isReady || (d != null && this.tg == null);
            if (i) {
                this.sy.dg();
                if (b != null) {
                    b.dg();
                }
                return;
            }
            this.sy.b3 = true;
            if (b != null) {
                b.b3 = true;
            }
            let j = a.count;
            let k = this.cd;
            for (let l = 0; l < j; l++) {
                let m = a._inner[l];
                let n = typeCast(DataContext.$, m.content);
                if (n != null) {
                    let o = null;
                    let p = k.indexOf(n.item);
                    if (c != null) {
                        o = c.getBrush1(p, k.count);
                    }
                    else if (d != null && this.s3 != null) {
                        let q = this.s3.item(p);
                        o = d.getBrushByRange(q, g, h);
                    }
                    else if (e != null) {
                        o = e.getBrush(p);
                    }
                    else {
                        if (this.pl == null) {
                            o = this.pj;
                        }
                        else {
                            o = this.pl;
                        }
                    }
                    let r = null;
                    if (this.pm == null) {
                        r = this.pk;
                    }
                    else {
                        r = this.pm;
                    }
                    if (this.s8 && o != null) {
                        r = o;
                    }
                    if (r != null && !isNaN_(this.te)) {
                        r = BrushUtil.l(r, this.te);
                    }
                    if (o != null && !isNaN_(this.td)) {
                        o = BrushUtil.l(o, this.td);
                    }
                    n.itemBrush = o;
                    n.actualItemBrush = o;
                    n.outline = r;
                }
            }
        }
        get_dd() {
            return false;
        }
        get actualMarkerBrush() {
            return this.pj;
        }
    }
    BubbleSeries.$t = /*@__PURE__*/ markType(BubbleSeries, 'BubbleSeries', ScatterBase.$, [IScaleLegendSeries_$type, ISupportsSizeScale_$type, ISupportsFillScale_$type]);
    BubbleSeries.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, BubbleSeries, 'raisePropertyChanged', ['FillMemberPath:tg:tz', [2], 'FillScale:sx:t0', [BrushScale.$], 'FillScaleUseGlobalValues:s7:t1', [0, false], 'LabelMemberPath:tl:t2', [2], 'MarkerBrushBrightness:td:t3', [1, NaN], 'MarkerOutlineBrightness:te:t4', [1, NaN], 'MarkerOutlineUsesFillScale:s8:t5', [0, false], 'RadiusMemberPath:tr:t6', [2, null], 'RadiusScale:sz:t7', [SizeScale.$], 'RadiusScaleUseGlobalValues:s9:t8', [0, false]]);
    return BubbleSeries;
})();
/**
 * @hidden
 */
export let CustomPaletteBrushScale = /*@__PURE__*/ (() => {
    class CustomPaletteBrushScale extends BrushScale {
        constructor() {
            super();
        }
        getBrush1(a, b) {
            if (this.brushes == null || this.brushes.count == 0) {
                return null;
            }
            if (this.brushSelectionMode == 0) {
                return super.getBrush(a % this.brushes.count);
            }
            let c = BubbleSeries.tb(0, b - 1, 0, this.brushes.count - 1, a);
            return this.aa(c);
        }
        get_isReady() {
            return this.brushes != null && this.brushes.count > 0;
        }
    }
    CustomPaletteBrushScale.$t = /*@__PURE__*/ markType(CustomPaletteBrushScale, 'CustomPaletteBrushScale', BrushScale.$);
    CustomPaletteBrushScale.$$p = /*@__PURE__*/ markDep(DependencyProperty, PropertyMetadata, CustomPaletteBrushScale, 'u', ['BrushSelectionMode', [BrushSelectionMode_$type, /*@__PURE__*/ enumGetBox(BrushSelectionMode_$type, 0)]]);
    return CustomPaletteBrushScale;
})();
/**
 * @hidden
 */
export let BubbleSeriesView = /*@__PURE__*/ (() => {
    class BubbleSeriesView extends ScatterBaseView {
        constructor(a) {
            super(a);
            this.df = null;
            this.df = a;
            this.cx = new ScatterTrendLineManager();
        }
        as() {
            super.as();
            if (!this.q) {
                this.b1.oi = 2;
                this.e.bx = 4;
            }
        }
        cu() {
            return new BubbleMarkerManager((a) => this.cy.item(a), (a) => this.cw.p3.c.item(a), runOn(this, this.c9), runOn(this, this.cr), runOn(this, this.cz));
        }
        dh() {
            let a = this.cv;
            this.df.ty(a.n, a.o, this.bu, this == this.e.br);
            this.aq();
        }
        di() {
            let a = this.cv;
            this.df.tx(a.n);
        }
        dg() {
            let a = this.cv;
            for (let b of fromEnum(a.n)) {
                let c = typeCast(DataContext.$, b.content);
                if (c != null) {
                    c.itemBrush = null;
                    c.outline = null;
                }
            }
        }
        getDefaultTooltipTemplate() {
            let a = "<div class='ui-chart-default-tooltip-content'><span";
            let b = this.e.a3.a$r(this.e);
            if (!stringIsNullOrEmpty(b)) {
                a += " style='color:" + b + "'";
            }
            a += ">" + this.df.gy + "</span><br/><span>" + "(${item." + this.df.rf + "}, ${item." + this.df.rj + "})</span>";
            if (!stringIsNullOrEmpty(this.df.tr)) {
                a += "<span>, Radius: ${item." + this.df.tr + "}</span>";
            }
            a += "</div>";
            return a;
        }
    }
    BubbleSeriesView.$t = /*@__PURE__*/ markType(BubbleSeriesView, 'BubbleSeriesView', ScatterBaseView.$);
    return BubbleSeriesView;
})();
//# sourceMappingURL=BubbleSeries_combined.js.map
