/*
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 { Base, String_$type, fromEnum, runOn, delegateCombine, delegateRemove, markType } from "igniteui-react-core";
import { IDomainChartToolbarProvider_$type } from "./IDomainChartToolbarProvider";
import { ToolCommandStateChanged } from "igniteui-react-core";
import { ToolActionGroupHeaderInfo } from "igniteui-react-core";
import { ToolActionCheckboxListInfo } from "igniteui-react-core";
import { HashSet$1 } from "igniteui-react-core";
import { DomainChartCheckboxListItem } from "./DomainChartCheckboxListItem";
import { ToolActionIconMenuInfo } from "igniteui-react-core";
import { Tuple$2 } from "igniteui-react-core";
import { NativeUIComponent } from "igniteui-react-core";
import { ValueModeCollection } from "./ValueModeCollection";
import { BrushCollection } from "igniteui-react-core";
import { BrushUtil } from "igniteui-react-core";
import { CaptureImageSettings } from "igniteui-react-core";
/**
 * @hidden
 */
export let DomainChartToolbarProvider = /*@__PURE__*/ (() => {
    class DomainChartToolbarProvider extends Base {
        constructor() {
            super(...arguments);
            this.a = null;
            this.b = false;
            this._container = null;
            this.d = new HashSet$1(Tuple$2.$.specialize(String_$type, String_$type), 0);
            this.e = new HashSet$1(Tuple$2.$.specialize(String_$type, String_$type), 0);
            this._commandChanged = null;
        }
        get container() {
            return this._container;
        }
        set container(a) {
            this._container = a;
        }
        get commandChanged() {
            return this._commandChanged;
        }
        set commandChanged(a) {
            this._commandChanged = a;
        }
        getDesiredToolbarActions(a, b) {
            let c;
            if (a.itemsSource != null && NativeUIComponent.v(16, 0)) {
                let d = new ToolActionGroupHeaderInfo();
                d.name = "AxisFieldLabelHeader";
                d.title = "Label Fields";
                let e = new ToolActionCheckboxListInfo();
                e.name = "AxisFieldLabel";
                let f = new ToolActionGroupHeaderInfo();
                f.name = "AxisFieldValueHeader";
                f.title = "Value Fields";
                let g = new ToolActionCheckboxListInfo();
                g.name = "AxisFieldValue";
                let h = a.q == null ? null : new HashSet$1(String_$type, 1, a.q);
                let i = 0;
                if (h != null && a.o != null && a.o.length > 0) {
                    let j = new HashSet$1(String_$type, 1, a.o);
                    for (let k of fromEnum(j)) {
                        if (h.contains(k)) {
                            h.remove(k);
                        }
                    }
                    let l = h.count;
                    let m = new Array(l);
                    i = 0;
                    for (let n of fromEnum(h)) {
                        m[i] = n;
                        i++;
                    }
                }
                a.bj.ay(this.d, this.e);
                i = 0;
                let o = new Array(this.d.count);
                for (let p of fromEnum(this.d)) {
                    o[i] = ((() => {
                        let $ret = new DomainChartCheckboxListItem();
                        $ret.key = p.c;
                        $ret.label = p.d;
                        $ret.isSelected = h == null || h.contains(p.c);
                        return $ret;
                    })());
                    i++;
                }
                e.itemsSource = o;
                e.dataMemberPath = "label";
                e.selectedMemberPath = "isSelected";
                e.primaryKey = ["key"];
                let q = new Array(this.e.count);
                i = 0;
                for (let r of fromEnum(this.e)) {
                    q[i] = ((() => {
                        let $ret = new DomainChartCheckboxListItem();
                        $ret.key = r.c;
                        $ret.label = r.d;
                        $ret.isSelected = h == null || h.contains(r.c);
                        return $ret;
                    })());
                    i++;
                }
                g.itemsSource = q;
                g.dataMemberPath = "label";
                g.selectedMemberPath = "isSelected";
                g.primaryKey = ["key"];
                let s = new ToolActionIconMenuInfo();
                s.name = "AxisFieldMenu";
                s.iconName = "analyze-valuelabels-showlast";
                s.iconCollectionName = "ChartToolbarIcons";
                s.actions = [d, e, f, g];
                c = new Array(b.length + 1);
                for (let t = 0; t < b.length; t++) {
                    c[t] = b[t];
                }
                c[b.length] = s;
            }
            else {
                c = b;
            }
            for (let u = 0; u < c.length; u++) {
                this.f(a, c[u]);
            }
            return c;
        }
        f(a, b) {
            if (b.actions != null && b.actions.length > 0) {
                for (let c = 0; c < b.actions.length; c++) {
                    this.f(a, b.actions[c]);
                }
            }
            switch (b.name) {
                case "ShowCrosshairs":
                    {
                        let d = b;
                        d.isChecked = a.bf != 1;
                    }
                    break;
                case "ShowGridlines":
                    {
                        let e = b;
                        e.isChecked = a.gc;
                    }
                    break;
                case "ShowValueLabels":
                    {
                        let f = b;
                        f.isChecked = a.gc;
                    }
                    break;
                case "ShowLastValueLabel":
                    {
                        let g = b;
                        g.isChecked = a.gq;
                    }
                    break;
                case "MinValue":
                    {
                        if (a.ed != null) {
                            let h = b;
                            for (let i = 0; i < a.ed.count; i++) {
                                if (a.ed._inner[i] == 4) {
                                    h.isChecked = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case "MaxValue":
                    {
                        if (a.ed != null) {
                            let j = b;
                            for (let k = 0; k < a.ed.count; k++) {
                                if (a.ed._inner[k] == 5) {
                                    j.isChecked = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case "Average":
                    {
                        if (a.ed != null) {
                            let l = b;
                            for (let m = 0; m < a.ed.count; m++) {
                                if (a.ed._inner[m] == 6) {
                                    l.isChecked = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case "SeriesAvg":
                    {
                        if (a.ed != null) {
                            let n = b;
                            for (let o = 0; o < a.ed.count; o++) {
                                if (a.ed._inner[o] == 3) {
                                    n.isChecked = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case "AxisFieldLabel":
                    {
                    }
                    break;
                case "AxisFieldValue":
                    {
                    }
                    break;
            }
            this.g(a, b);
        }
        g(a, b) {
        }
        onToolCommandExecuting(a, b) {
            this.b = true;
            let c = 0;
            switch (b.commandId) {
                case "ZoomReset":
                    this.ac(a, b);
                    break;
                case "ZoomIn":
                    this.aa(a, b);
                    break;
                case "ZoomOut":
                    this.ab(a, b);
                    break;
                case "ShowCrosshairs":
                    this.n(a, b);
                    break;
                case "ShowGridlines":
                    this.p(a, b);
                    break;
                case "MaxValue":
                    this.t(a, b);
                    break;
                case "MinValue":
                    this.u(a, b);
                    break;
                case "Average":
                    this.i(a, b);
                    break;
                case "Exponential":
                    this.o(a, b);
                    break;
                case "Linear":
                    this.r(a, b);
                    break;
                case "Logarithmic":
                    this.s(a, b);
                    break;
                case "NoTrends":
                    this.v(a, b);
                    break;
                case "SeriesAvg":
                    this.w(a, b);
                    break;
                case "ShowValueLabels":
                    this.y(a, b);
                    break;
                case "ShowLastValueLabel":
                    this.x(a, b);
                    break;
                case "CopyAsImage":
                    this.m(a, b);
                    c = 2;
                    break;
                case "AxisFieldLabel":
                    this.k(a, b);
                    break;
                case "AxisFieldValue":
                    this.l(a, b);
                    break;
            }
            this.b = false;
            return c;
        }
        onTargetPropertyChanged(a, b, c, d) {
            if (this.b) {
                return;
            }
            switch (b) {
                case "CrosshairsDisplayMode":
                    if (a.bf == 1) {
                        this.h("ShowCrosshairs", 2, false);
                    }
                    else {
                        this.h("ShowCrosshairs", 2, true);
                    }
                    break;
                case "AutoCalloutsVisible":
                    this.h("ShowValueLabels", 2, a.gc);
                    break;
                case "FinalValueAnnotationsVisible":
                    this.h("ShowLastValueLabel", 2, a.gq);
                    break;
            }
            this.z(a, b, c, d);
        }
        z(a, b, c, d) {
        }
        h(a, b, c) {
            if (this.commandChanged != null) {
                this.commandChanged(((() => {
                    let $ret = new ToolCommandStateChanged();
                    $ret.c = a;
                    $ret.a = b;
                    $ret.b = c;
                    return $ret;
                })()));
            }
        }
        c(a, b) {
            if (a.commandId == b) {
                let e = a.argumentsList;
                for (let d = 0; d < e.length; d++) {
                    let c = e[d];
                    if (c.argumentName == "IsChecked") {
                        return c.value;
                    }
                }
            }
            return false;
        }
        n(a, b) {
            if (this.c(b, "ShowCrosshairs")) {
                a.bf = 0;
                a.gi = true;
            }
            else {
                a.bf = 1;
            }
        }
        p(a, b) {
        }
        o(a, b) {
            if (this.c(b, "Exponential")) {
                a.d9 = 7;
            }
            else {
                a.d9 = 0;
            }
        }
        r(a, b) {
            if (this.c(b, "Linear")) {
                a.d9 = 1;
            }
            else {
                a.d9 = 0;
            }
        }
        s(a, b) {
            if (this.c(b, "Logarithmic")) {
                a.d9 = 6;
            }
            else {
                a.d9 = 0;
            }
        }
        v(a, b) {
            if (this.c(b, "NoTrends")) {
                a.d9 = 0;
            }
        }
        t(a, b) {
            if (this.c(b, "MaxValue")) {
                if (a.ed == null) {
                    a.ed = new ValueModeCollection();
                }
                if (a.ai == null) {
                    a.ai = new BrushCollection();
                }
                a.ed.add(5);
                a.ai.add(BrushUtil.h(255, 99, 208, 0));
            }
            else {
                for (let c = 0; c < a.ed.count; c++) {
                    if (a.ed._inner[c] == 5) {
                        a.ed.removeAt(c);
                        a.ai.removeAt(c);
                        c--;
                    }
                }
            }
        }
        u(a, b) {
            if (this.c(b, "MinValue")) {
                if (a.ed == null) {
                    a.ed = new ValueModeCollection();
                }
                if (a.ai == null) {
                    a.ai = new BrushCollection();
                }
                a.ed.add(4);
                a.ai.add(BrushUtil.h(255, 246, 93, 80));
            }
            else {
                for (let c = 0; c < a.ed.count; c++) {
                    if (a.ed._inner[c] == 4) {
                        a.ed.removeAt(c);
                        a.ai.removeAt(c);
                        c--;
                    }
                }
            }
        }
        i(a, b) {
            if (this.c(b, "Average")) {
                if (a.ed == null) {
                    a.ed = new ValueModeCollection();
                }
                if (a.ai == null) {
                    a.ai = new BrushCollection();
                }
                a.ed.add(6);
                a.ai.add(BrushUtil.h(255, 248, 173, 118));
            }
            else {
                for (let c = 0; c < a.ed.count; c++) {
                    if (a.ed._inner[c] == 6) {
                        a.ed.removeAt(c);
                        a.ai.removeAt(c);
                        c--;
                    }
                }
            }
        }
        w(a, b) {
            if (this.c(b, "SeriesAvg")) {
                if (a.ed == null) {
                    a.ed = new ValueModeCollection();
                }
                a.ed.add(3);
            }
            else {
                for (let c = 0; c < a.ed.count; c++) {
                    if (a.ed._inner[c] == 3) {
                        a.ed.removeAt(c);
                        c--;
                    }
                }
            }
        }
        y(a, b) {
            if (this.c(b, "ShowValueLabels")) {
                a.gc = true;
            }
            else {
                a.gc = false;
            }
        }
        x(a, b) {
            if (this.c(b, "ShowLastValueLabel")) {
                a.gq = true;
                a.ha = true;
            }
            else {
                a.gq = false;
            }
        }
        m(a, b) {
            this.a = b;
            let c = new CaptureImageSettings();
            c.b = true;
            c.a = 0;
            let d = a.dataChart;
            d.imageCaptured = delegateCombine(d.imageCaptured, runOn(this, this.q));
            a.dataChart.mz(c);
            a.dataChart.al.q();
        }
        k(a, b) {
            this.j(a, b, "AxisFieldLabel");
        }
        l(a, b) {
            this.j(a, b, "AxisFieldValue");
        }
        j(a, b, c) {
            if (b.argumentsList.length != 3) {
                return;
            }
            let d = b.argumentsList[2].value;
            let e = (d[0]);
            let f = false;
            if (a.q != null) {
                let i = a.q;
                for (let h = 0; h < i.length; h++) {
                    let g = i[h];
                    if (g == e) {
                        f = true;
                        break;
                    }
                }
            }
            let j = false;
            if (a.o != null) {
                let m = a.o;
                for (let l = 0; l < m.length; l++) {
                    let k = m[l];
                    if (k == e) {
                        j = true;
                        break;
                    }
                }
            }
            if (this.c(b, c)) {
                if (!f) {
                    let n = new Array(a.q.length + 1);
                    for (let o = 0; o < a.q.length; ++o) {
                        n[o] = a.q[o];
                    }
                    n[a.q.length] = e;
                    a.q = n;
                }
                if (j) {
                    if (a.o.length == 1) {
                        a.o = new Array(0);
                    }
                    else {
                        let p = new Array(a.o.length - 1);
                        let q = -1;
                        let r = 0;
                        while (r < p.length) {
                            q++;
                            if (a.o[q] == e) {
                                continue;
                            }
                            p[r] = a.o[q];
                            r++;
                        }
                        a.o = p;
                    }
                }
            }
            else if ((a.q == null || a.q.length == 0) && (this.d.count + this.e.count > 1)) {
                let s = this.d.count + this.e.count - 1;
                let t = new Array(s);
                let u = 0;
                for (let v of fromEnum(this.d)) {
                    if (v.c == e) {
                        continue;
                    }
                    t[u] = v.c;
                    u++;
                }
                for (let w of fromEnum(this.e)) {
                    if (w.c == e) {
                        continue;
                    }
                    t[u] = w.c;
                    u++;
                }
                a.q = t;
            }
            else if (f) {
                if (a.q.length == 1) {
                    a.q = new Array(0);
                }
                else {
                    let x = new Array(a.q.length - 1);
                    let y = -1;
                    let z = 0;
                    while (z < x.length) {
                        y++;
                        if (a.q[y] == e) {
                            continue;
                        }
                        x[z] = a.q[y];
                        z++;
                    }
                    a.q = x;
                }
            }
        }
        q(a, b) {
            this.a.argumentsList[0].value = b.base64Data;
            let c = a;
            c.imageCaptured = delegateRemove(c.imageCaptured, runOn(this, this.q));
            if (c.commandCompleted != null) {
                c.commandCompleted(this.a);
            }
        }
        aa(a, b) {
            a.wh(0.05);
        }
        ab(a, b) {
            a.wi(0.05);
        }
        ac(a, b) {
            a.v9();
        }
    }
    DomainChartToolbarProvider.$t = /*@__PURE__*/ markType(DomainChartToolbarProvider, 'DomainChartToolbarProvider', Base.$, [IDomainChartToolbarProvider_$type]);
    return DomainChartToolbarProvider;
})();
