/*
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 { __extends, __values } from "tslib";
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
 */
var DomainChartToolbarProvider = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(DomainChartToolbarProvider, _super);
    function DomainChartToolbarProvider() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _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;
        return _this;
    }
    Object.defineProperty(DomainChartToolbarProvider.prototype, "container", {
        get: function () {
            return this._container;
        },
        set: function (a) {
            this._container = a;
        },
        enumerable: false,
        configurable: true
    });
    Object.defineProperty(DomainChartToolbarProvider.prototype, "commandChanged", {
        get: function () {
            return this._commandChanged;
        },
        set: function (a) {
            this._commandChanged = a;
        },
        enumerable: false,
        configurable: true
    });
    DomainChartToolbarProvider.prototype.getDesiredToolbarActions = function (a, b) {
        var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
        var c;
        if (a.itemsSource != null && NativeUIComponent.v(16, 0)) {
            var d = new ToolActionGroupHeaderInfo();
            d.name = "AxisFieldLabelHeader";
            d.title = "Label Fields";
            var e = new ToolActionCheckboxListInfo();
            e.name = "AxisFieldLabel";
            var f = new ToolActionGroupHeaderInfo();
            f.name = "AxisFieldValueHeader";
            f.title = "Value Fields";
            var g = new ToolActionCheckboxListInfo();
            g.name = "AxisFieldValue";
            var h_1 = a.q == null ? null : new HashSet$1(String_$type, 1, a.q);
            var i = 0;
            if (h_1 != null && a.o != null && a.o.length > 0) {
                var j = new HashSet$1(String_$type, 1, a.o);
                try {
                    for (var _e = __values(fromEnum(j)), _f = _e.next(); !_f.done; _f = _e.next()) {
                        var k = _f.value;
                        if (h_1.contains(k)) {
                            h_1.remove(k);
                        }
                    }
                }
                catch (e_1_1) {
                    e_1 = { error: e_1_1 };
                }
                finally {
                    try {
                        if (_f && !_f.done && (_a = _e.return))
                            _a.call(_e);
                    }
                    finally {
                        if (e_1)
                            throw e_1.error;
                    }
                }
                var l = h_1.count;
                var m = new Array(l);
                i = 0;
                try {
                    for (var _g = __values(fromEnum(h_1)), _h = _g.next(); !_h.done; _h = _g.next()) {
                        var n = _h.value;
                        m[i] = n;
                        i++;
                    }
                }
                catch (e_2_1) {
                    e_2 = { error: e_2_1 };
                }
                finally {
                    try {
                        if (_h && !_h.done && (_b = _g.return))
                            _b.call(_g);
                    }
                    finally {
                        if (e_2)
                            throw e_2.error;
                    }
                }
            }
            a.bj.ay(this.d, this.e);
            i = 0;
            var o = new Array(this.d.count);
            var _loop_1 = function (p) {
                o[i] = ((function () {
                    var $ret = new DomainChartCheckboxListItem();
                    $ret.key = p.c;
                    $ret.label = p.d;
                    $ret.isSelected = h_1 == null || h_1.contains(p.c);
                    return $ret;
                })());
                i++;
            };
            try {
                for (var _j = __values(fromEnum(this.d)), _k = _j.next(); !_k.done; _k = _j.next()) {
                    var p = _k.value;
                    _loop_1(p);
                }
            }
            catch (e_3_1) {
                e_3 = { error: e_3_1 };
            }
            finally {
                try {
                    if (_k && !_k.done && (_c = _j.return))
                        _c.call(_j);
                }
                finally {
                    if (e_3)
                        throw e_3.error;
                }
            }
            e.itemsSource = o;
            e.dataMemberPath = "label";
            e.selectedMemberPath = "isSelected";
            e.primaryKey = ["key"];
            var q = new Array(this.e.count);
            i = 0;
            var _loop_2 = function (r) {
                q[i] = ((function () {
                    var $ret = new DomainChartCheckboxListItem();
                    $ret.key = r.c;
                    $ret.label = r.d;
                    $ret.isSelected = h_1 == null || h_1.contains(r.c);
                    return $ret;
                })());
                i++;
            };
            try {
                for (var _l = __values(fromEnum(this.e)), _m = _l.next(); !_m.done; _m = _l.next()) {
                    var r = _m.value;
                    _loop_2(r);
                }
            }
            catch (e_4_1) {
                e_4 = { error: e_4_1 };
            }
            finally {
                try {
                    if (_m && !_m.done && (_d = _l.return))
                        _d.call(_l);
                }
                finally {
                    if (e_4)
                        throw e_4.error;
                }
            }
            g.itemsSource = q;
            g.dataMemberPath = "label";
            g.selectedMemberPath = "isSelected";
            g.primaryKey = ["key"];
            var 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 (var t = 0; t < b.length; t++) {
                c[t] = b[t];
            }
            c[b.length] = s;
        }
        else {
            c = b;
        }
        for (var u = 0; u < c.length; u++) {
            this.f(a, c[u]);
        }
        return c;
    };
    DomainChartToolbarProvider.prototype.f = function (a, b) {
        if (b.actions != null && b.actions.length > 0) {
            for (var c = 0; c < b.actions.length; c++) {
                this.f(a, b.actions[c]);
            }
        }
        switch (b.name) {
            case "ShowCrosshairs":
                {
                    var d = b;
                    d.isChecked = a.bf != 1;
                }
                break;
            case "ShowGridlines":
                {
                    var e = b;
                    e.isChecked = a.gi;
                }
                break;
            case "ShowValueLabels":
                {
                    var f = b;
                    f.isChecked = a.gi;
                }
                break;
            case "ShowLastValueLabel":
                {
                    var g = b;
                    g.isChecked = a.gw;
                }
                break;
            case "MinValue":
                {
                    if (a.ej != null) {
                        var h = b;
                        for (var i = 0; i < a.ej.count; i++) {
                            if (a.ej._inner[i] == 4) {
                                h.isChecked = true;
                                break;
                            }
                        }
                    }
                }
                break;
            case "MaxValue":
                {
                    if (a.ej != null) {
                        var j = b;
                        for (var k = 0; k < a.ej.count; k++) {
                            if (a.ej._inner[k] == 5) {
                                j.isChecked = true;
                                break;
                            }
                        }
                    }
                }
                break;
            case "Average":
                {
                    if (a.ej != null) {
                        var l = b;
                        for (var m = 0; m < a.ej.count; m++) {
                            if (a.ej._inner[m] == 6) {
                                l.isChecked = true;
                                break;
                            }
                        }
                    }
                }
                break;
            case "SeriesAvg":
                {
                    if (a.ej != null) {
                        var n = b;
                        for (var o = 0; o < a.ej.count; o++) {
                            if (a.ej._inner[o] == 3) {
                                n.isChecked = true;
                                break;
                            }
                        }
                    }
                }
                break;
            case "AxisFieldLabel":
                {
                }
                break;
            case "AxisFieldValue":
                {
                }
                break;
        }
        this.g(a, b);
    };
    DomainChartToolbarProvider.prototype.g = function (a, b) {
    };
    DomainChartToolbarProvider.prototype.onToolCommandExecuting = function (a, b) {
        this.b = true;
        var 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;
    };
    DomainChartToolbarProvider.prototype.onTargetPropertyChanged = function (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.gi);
                break;
            case "FinalValueAnnotationsVisible":
                this.h("ShowLastValueLabel", 2, a.gw);
                break;
        }
        this.z(a, b, c, d);
    };
    DomainChartToolbarProvider.prototype.z = function (a, b, c, d) {
    };
    DomainChartToolbarProvider.prototype.h = function (a, b, c) {
        if (this.commandChanged != null) {
            this.commandChanged(((function () {
                var $ret = new ToolCommandStateChanged();
                $ret.c = a;
                $ret.a = b;
                $ret.b = c;
                return $ret;
            })()));
        }
    };
    DomainChartToolbarProvider.prototype.c = function (a, b) {
        if (a.commandId == b) {
            var e = a.argumentsList;
            for (var d = 0; d < e.length; d++) {
                var c = e[d];
                if (c.argumentName == "IsChecked") {
                    return c.value;
                }
            }
        }
        return false;
    };
    DomainChartToolbarProvider.prototype.n = function (a, b) {
        if (this.c(b, "ShowCrosshairs")) {
            a.bf = 0;
            a.go = true;
        }
        else {
            a.bf = 1;
        }
    };
    DomainChartToolbarProvider.prototype.p = function (a, b) {
    };
    DomainChartToolbarProvider.prototype.o = function (a, b) {
        if (this.c(b, "Exponential")) {
            a.ef = 7;
        }
        else {
            a.ef = 0;
        }
    };
    DomainChartToolbarProvider.prototype.r = function (a, b) {
        if (this.c(b, "Linear")) {
            a.ef = 1;
        }
        else {
            a.ef = 0;
        }
    };
    DomainChartToolbarProvider.prototype.s = function (a, b) {
        if (this.c(b, "Logarithmic")) {
            a.ef = 6;
        }
        else {
            a.ef = 0;
        }
    };
    DomainChartToolbarProvider.prototype.v = function (a, b) {
        if (this.c(b, "NoTrends")) {
            a.ef = 0;
        }
    };
    DomainChartToolbarProvider.prototype.t = function (a, b) {
        if (this.c(b, "MaxValue")) {
            if (a.ej == null) {
                a.ej = new ValueModeCollection();
            }
            if (a.ai == null) {
                a.ai = new BrushCollection();
            }
            a.ej.add(5);
            a.ai.add(BrushUtil.h(255, 99, 208, 0));
        }
        else {
            for (var c = 0; c < a.ej.count; c++) {
                if (a.ej._inner[c] == 5) {
                    a.ej.removeAt(c);
                    a.ai.removeAt(c);
                    c--;
                }
            }
        }
    };
    DomainChartToolbarProvider.prototype.u = function (a, b) {
        if (this.c(b, "MinValue")) {
            if (a.ej == null) {
                a.ej = new ValueModeCollection();
            }
            if (a.ai == null) {
                a.ai = new BrushCollection();
            }
            a.ej.add(4);
            a.ai.add(BrushUtil.h(255, 246, 93, 80));
        }
        else {
            for (var c = 0; c < a.ej.count; c++) {
                if (a.ej._inner[c] == 4) {
                    a.ej.removeAt(c);
                    a.ai.removeAt(c);
                    c--;
                }
            }
        }
    };
    DomainChartToolbarProvider.prototype.i = function (a, b) {
        if (this.c(b, "Average")) {
            if (a.ej == null) {
                a.ej = new ValueModeCollection();
            }
            if (a.ai == null) {
                a.ai = new BrushCollection();
            }
            a.ej.add(6);
            a.ai.add(BrushUtil.h(255, 248, 173, 118));
        }
        else {
            for (var c = 0; c < a.ej.count; c++) {
                if (a.ej._inner[c] == 6) {
                    a.ej.removeAt(c);
                    a.ai.removeAt(c);
                    c--;
                }
            }
        }
    };
    DomainChartToolbarProvider.prototype.w = function (a, b) {
        if (this.c(b, "SeriesAvg")) {
            if (a.ej == null) {
                a.ej = new ValueModeCollection();
            }
            a.ej.add(3);
        }
        else {
            for (var c = 0; c < a.ej.count; c++) {
                if (a.ej._inner[c] == 3) {
                    a.ej.removeAt(c);
                    c--;
                }
            }
        }
    };
    DomainChartToolbarProvider.prototype.y = function (a, b) {
        if (this.c(b, "ShowValueLabels")) {
            a.gi = true;
        }
        else {
            a.gi = false;
        }
    };
    DomainChartToolbarProvider.prototype.x = function (a, b) {
        if (this.c(b, "ShowLastValueLabel")) {
            a.gw = true;
            a.hg = true;
        }
        else {
            a.gw = false;
        }
    };
    DomainChartToolbarProvider.prototype.m = function (a, b) {
        this.a = b;
        var c = new CaptureImageSettings();
        c.b = true;
        c.a = 0;
        var d = a.dataChart;
        d.imageCaptured = delegateCombine(d.imageCaptured, runOn(this, this.q));
        a.dataChart.mz(c);
        a.dataChart.al.q();
    };
    DomainChartToolbarProvider.prototype.k = function (a, b) {
        this.j(a, b, "AxisFieldLabel");
    };
    DomainChartToolbarProvider.prototype.l = function (a, b) {
        this.j(a, b, "AxisFieldValue");
    };
    DomainChartToolbarProvider.prototype.j = function (a, b, c) {
        var e_5, _a, e_6, _b;
        if (b.argumentsList.length != 3) {
            return;
        }
        var d = b.argumentsList[2].value;
        var e = (d[0]);
        var f = false;
        if (a.q != null) {
            var i = a.q;
            for (var h = 0; h < i.length; h++) {
                var g = i[h];
                if (g == e) {
                    f = true;
                    break;
                }
            }
        }
        var j = false;
        if (a.o != null) {
            var m = a.o;
            for (var l = 0; l < m.length; l++) {
                var k = m[l];
                if (k == e) {
                    j = true;
                    break;
                }
            }
        }
        if (this.c(b, c)) {
            if (!f) {
                var n = new Array(a.q.length + 1);
                for (var 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 {
                    var p = new Array(a.o.length - 1);
                    var q = -1;
                    var 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)) {
            var s = this.d.count + this.e.count - 1;
            var t = new Array(s);
            var u = 0;
            try {
                for (var _c = __values(fromEnum(this.d)), _d = _c.next(); !_d.done; _d = _c.next()) {
                    var v = _d.value;
                    if (v.c == e) {
                        continue;
                    }
                    t[u] = v.c;
                    u++;
                }
            }
            catch (e_5_1) {
                e_5 = { error: e_5_1 };
            }
            finally {
                try {
                    if (_d && !_d.done && (_a = _c.return))
                        _a.call(_c);
                }
                finally {
                    if (e_5)
                        throw e_5.error;
                }
            }
            try {
                for (var _e = __values(fromEnum(this.e)), _f = _e.next(); !_f.done; _f = _e.next()) {
                    var w = _f.value;
                    if (w.c == e) {
                        continue;
                    }
                    t[u] = w.c;
                    u++;
                }
            }
            catch (e_6_1) {
                e_6 = { error: e_6_1 };
            }
            finally {
                try {
                    if (_f && !_f.done && (_b = _e.return))
                        _b.call(_e);
                }
                finally {
                    if (e_6)
                        throw e_6.error;
                }
            }
            a.q = t;
        }
        else if (f) {
            if (a.q.length == 1) {
                a.q = new Array(0);
            }
            else {
                var x = new Array(a.q.length - 1);
                var y = -1;
                var z = 0;
                while (z < x.length) {
                    y++;
                    if (a.q[y] == e) {
                        continue;
                    }
                    x[z] = a.q[y];
                    z++;
                }
                a.q = x;
            }
        }
    };
    DomainChartToolbarProvider.prototype.q = function (a, b) {
        this.a.argumentsList[0].value = b.base64Data;
        var c = a;
        c.imageCaptured = delegateRemove(c.imageCaptured, runOn(this, this.q));
        if (c.commandCompleted != null) {
            c.commandCompleted(this.a);
        }
    };
    DomainChartToolbarProvider.prototype.aa = function (a, b) {
        a.wt(0.05);
    };
    DomainChartToolbarProvider.prototype.ab = function (a, b) {
        a.wu(0.05);
    };
    DomainChartToolbarProvider.prototype.ac = function (a, b) {
        a.wl();
    };
    DomainChartToolbarProvider.$t = markType(DomainChartToolbarProvider, 'DomainChartToolbarProvider', Base.$, [IDomainChartToolbarProvider_$type]);
    return DomainChartToolbarProvider;
}(Base));
export { DomainChartToolbarProvider };
