/*
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, markType } from "igniteui-angular-core";
import { IDomainChartToolbarProvider_$type } from "./IDomainChartToolbarProvider";
import { ToolCommandStateChanged } from "igniteui-angular-core";
import { ToolActionGroupHeaderInfo } from "igniteui-angular-core";
import { ToolActionCheckboxListInfo } from "igniteui-angular-core";
import { HashSet$1 } from "igniteui-angular-core";
import { DomainChartCheckboxListItem } from "./DomainChartCheckboxListItem";
import { ToolActionIconMenuInfo } from "igniteui-angular-core";
import { Tuple$2 } from "igniteui-angular-core";
import { NativeUIComponent } from "igniteui-angular-core";
import { ToolContextBindingInfo } from "igniteui-angular-core";
import { ToolCommandArgument } from "igniteui-angular-core";
import { ValueModeCollection } from "./ValueModeCollection";
import { BrushCollection } from "igniteui-angular-core";
import { BrushUtil } from "igniteui-angular-core";
/**
 * @hidden
 */
var DomainChartToolbarProvider = /** @class */ /*@__PURE__*/ (function (_super) {
    __extends(DomainChartToolbarProvider, _super);
    function DomainChartToolbarProvider() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.b = null;
        _this.c = false;
        _this._container = null;
        _this.e = new HashSet$1(Tuple$2.$.specialize(String_$type, String_$type), 0);
        _this.f = new HashSet$1(Tuple$2.$.specialize(String_$type, String_$type), 0);
        _this._commandChanged = null;
        _this.a = 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, c) {
        var e_1, _a, e_2, _b, e_3, _c, e_4, _d;
        var d;
        if (a.itemsSource != null && NativeUIComponent.v(16, 0)) {
            var e = new ToolActionGroupHeaderInfo();
            e.name = "AxisFieldLabelHeader";
            e.title = "Label Fields";
            var f = new ToolActionCheckboxListInfo();
            f.name = "AxisFieldLabel";
            var g = new ToolActionGroupHeaderInfo();
            g.name = "AxisFieldValueHeader";
            g.title = "Value Fields";
            var h = new ToolActionCheckboxListInfo();
            h.name = "AxisFieldValue";
            var i_1 = a.includedProperties == null ? null : new HashSet$1(String_$type, 1, a.includedProperties);
            var j = 0;
            if (i_1 != null && a.excludedProperties != null && a.excludedProperties.length > 0) {
                var k = new HashSet$1(String_$type, 1, a.excludedProperties);
                try {
                    for (var _e = __values(fromEnum(k)), _f = _e.next(); !_f.done; _f = _e.next()) {
                        var l = _f.value;
                        if (i_1.contains(l)) {
                            i_1.remove(l);
                        }
                    }
                }
                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 m = i_1.count;
                var n = new Array(m);
                j = 0;
                try {
                    for (var _g = __values(fromEnum(i_1)), _h = _g.next(); !_h.done; _h = _g.next()) {
                        var o = _h.value;
                        n[j] = o;
                        j++;
                    }
                }
                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.currentDataAdapter.az(this.e, this.f);
            j = 0;
            var p = new Array(this.e.count);
            var _loop_1 = function (q) {
                p[j] = ((function () {
                    var $ret = new DomainChartCheckboxListItem();
                    $ret.key = q.c;
                    $ret.label = q.d;
                    $ret.isSelected = i_1 == null || i_1.contains(q.c);
                    return $ret;
                })());
                j++;
            };
            try {
                for (var _j = __values(fromEnum(this.e)), _k = _j.next(); !_k.done; _k = _j.next()) {
                    var q = _k.value;
                    _loop_1(q);
                }
            }
            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;
                }
            }
            c.setContextValue("AxisFieldLabels", 7, p);
            f.dataMemberPath = "label";
            f.selectedMemberPath = "isSelected";
            f.primaryKey = ["key"];
            f.contextBindings = [((function () {
                    var $ret = new ToolContextBindingInfo();
                    $ret.bindingMode = 0;
                    $ret.contextKey = "AxisFieldLabels";
                    $ret.propertyName = "ItemsSource";
                    return $ret;
                })())];
            var r = new Array(this.f.count);
            j = 0;
            var _loop_2 = function (s) {
                r[j] = ((function () {
                    var $ret = new DomainChartCheckboxListItem();
                    $ret.key = s.c;
                    $ret.label = s.d;
                    $ret.isSelected = i_1 == null || i_1.contains(s.c);
                    return $ret;
                })());
                j++;
            };
            try {
                for (var _l = __values(fromEnum(this.f)), _m = _l.next(); !_m.done; _m = _l.next()) {
                    var s = _m.value;
                    _loop_2(s);
                }
            }
            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;
                }
            }
            c.setContextValue("AxisFieldValues", 7, r);
            h.dataMemberPath = "label";
            h.selectedMemberPath = "isSelected";
            h.primaryKey = ["key"];
            h.contextBindings = [((function () {
                    var $ret = new ToolContextBindingInfo();
                    $ret.bindingMode = 0;
                    $ret.contextKey = "AxisFieldValues";
                    $ret.propertyName = "ItemsSource";
                    return $ret;
                })())];
            var t = new ToolActionIconMenuInfo();
            t.name = "AxisFieldMenu";
            t.iconName = "analyze-valuelabels-showlast";
            t.iconCollectionName = "ChartToolbarIcons";
            t.iconWidth = 24;
            t.iconHeight = 25;
            t.actions = [e, f, g, h];
            d = new Array(b.length + 1);
            for (var u = 0; u < b.length; u++) {
                d[u] = b[u];
            }
            d[b.length] = t;
        }
        else {
            d = b;
        }
        for (var v = 0; v < d.length; v++) {
            this.g(a, d[v]);
        }
        return d;
    };
    DomainChartToolbarProvider.prototype.g = function (a, b) {
        if (b.actions != null && b.actions.length > 0) {
            for (var c = 0; c < b.actions.length; c++) {
                this.g(a, b.actions[c]);
            }
        }
        switch (b.name) {
            case "ShowCrosshairs":
                {
                    var d = b;
                    d.isChecked = a.crosshairsDisplayMode != 1;
                }
                break;
            case "ShowGridlines":
                {
                    var e = b;
                    e.isChecked = a.autoCalloutsVisible;
                }
                break;
            case "ShowValueLabels":
                {
                    var f = b;
                    f.isChecked = a.autoCalloutsVisible;
                }
                break;
            case "ShowLastValueLabel":
                {
                    var g = b;
                    g.isChecked = a.finalValueAnnotationsVisible;
                }
                break;
            case "MinValue":
                {
                    if (a.valueLines != null) {
                        var h = b;
                        for (var i = 0; i < a.valueLines.count; i++) {
                            if (a.valueLines._inner[i] == 4) {
                                h.isChecked = true;
                                break;
                            }
                        }
                    }
                }
                break;
            case "MaxValue":
                {
                    if (a.valueLines != null) {
                        var j = b;
                        for (var k = 0; k < a.valueLines.count; k++) {
                            if (a.valueLines._inner[k] == 5) {
                                j.isChecked = true;
                                break;
                            }
                        }
                    }
                }
                break;
            case "Average":
                {
                    if (a.valueLines != null) {
                        var l = b;
                        for (var m = 0; m < a.valueLines.count; m++) {
                            if (a.valueLines._inner[m] == 6) {
                                l.isChecked = true;
                                break;
                            }
                        }
                    }
                }
                break;
            case "SeriesAvg":
                {
                    if (a.valueLines != null) {
                        var n = b;
                        for (var o = 0; o < a.valueLines.count; o++) {
                            if (a.valueLines._inner[o] == 3) {
                                n.isChecked = true;
                                break;
                            }
                        }
                    }
                }
                break;
            case "AxisFieldLabel":
                {
                }
                break;
            case "AxisFieldValue":
                {
                }
                break;
        }
        this.h(a, b);
    };
    DomainChartToolbarProvider.prototype.h = function (a, b) {
    };
    DomainChartToolbarProvider.prototype.onToolCommandExecuting = function (a, b) {
        this.c = true;
        var c = 0;
        switch (b.commandId) {
            case "ZoomReset":
                this.ad(a, b);
                break;
            case "ZoomIn":
                this.ab(a, b);
                break;
            case "ZoomOut":
                this.ac(a, b);
                break;
            case "ShowCrosshairs":
                this.o(a, b);
                break;
            case "ShowGridlines":
                this.q(a, b);
                break;
            case "MaxValue":
                this.u(a, b);
                break;
            case "MinValue":
                this.v(a, b);
                break;
            case "Average":
                this.j(a, b);
                break;
            case "Exponential":
                this.p(a, b);
                break;
            case "Linear":
                this.s(a, b);
                break;
            case "Logarithmic":
                this.t(a, b);
                break;
            case "NoTrends":
                this.w(a, b);
                break;
            case "SeriesAvg":
                this.x(a, b);
                break;
            case "ShowValueLabels":
                this.z(a, b);
                break;
            case "ShowLastValueLabel":
                this.y(a, b);
                break;
            case "CopyAsImage":
                this.n(a, b);
                c = 2;
                break;
            case "AxisFieldLabel":
                this.l(a, b);
                break;
            case "AxisFieldValue":
                this.m(a, b);
                break;
        }
        this.c = false;
        return c;
    };
    DomainChartToolbarProvider.prototype.onTargetPropertyChanged = function (a, b, c, d) {
        if (this.c) {
            return;
        }
        switch (b) {
            case "CrosshairsDisplayMode":
                if (a.crosshairsDisplayMode == 1) {
                    this.i("ShowCrosshairs", 2, false);
                }
                else {
                    this.i("ShowCrosshairs", 2, true);
                }
                break;
            case "AutoCalloutsVisible":
                this.i("ShowValueLabels", 2, a.autoCalloutsVisible);
                break;
            case "FinalValueAnnotationsVisible":
                this.i("ShowLastValueLabel", 2, a.finalValueAnnotationsVisible);
                break;
        }
        this.aa(a, b, c, d);
    };
    DomainChartToolbarProvider.prototype.aa = function (a, b, c, d) {
    };
    DomainChartToolbarProvider.prototype.i = 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.d = 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.o = function (a, b) {
        if (this.d(b, "ShowCrosshairs")) {
            a.crosshairsDisplayMode = 0;
            a.crosshairsAnnotationEnabled = true;
        }
        else {
            a.crosshairsDisplayMode = 1;
        }
    };
    DomainChartToolbarProvider.prototype.q = function (a, b) {
    };
    DomainChartToolbarProvider.prototype.p = function (a, b) {
        if (this.d(b, "Exponential")) {
            a.trendLineType = 7;
        }
        else {
            a.trendLineType = 0;
        }
    };
    DomainChartToolbarProvider.prototype.s = function (a, b) {
        if (this.d(b, "Linear")) {
            a.trendLineType = 1;
        }
        else {
            a.trendLineType = 0;
        }
    };
    DomainChartToolbarProvider.prototype.t = function (a, b) {
        if (this.d(b, "Logarithmic")) {
            a.trendLineType = 6;
        }
        else {
            a.trendLineType = 0;
        }
    };
    DomainChartToolbarProvider.prototype.w = function (a, b) {
        if (this.d(b, "NoTrends")) {
            a.trendLineType = 0;
        }
    };
    DomainChartToolbarProvider.prototype.u = function (a, b) {
        if (this.d(b, "MaxValue")) {
            if (a.valueLines == null) {
                a.valueLines = new ValueModeCollection();
            }
            if (a.valueLinesBrushes == null) {
                a.valueLinesBrushes = new BrushCollection();
            }
            a.valueLines.add(5);
            a.valueLinesBrushes.add(BrushUtil.h(255, 99, 208, 0));
        }
        else {
            for (var c = 0; c < a.valueLines.count; c++) {
                if (a.valueLines._inner[c] == 5) {
                    a.valueLines.removeAt(c);
                    a.valueLinesBrushes.removeAt(c);
                    c--;
                }
            }
        }
    };
    DomainChartToolbarProvider.prototype.v = function (a, b) {
        if (this.d(b, "MinValue")) {
            if (a.valueLines == null) {
                a.valueLines = new ValueModeCollection();
            }
            if (a.valueLinesBrushes == null) {
                a.valueLinesBrushes = new BrushCollection();
            }
            a.valueLines.add(4);
            a.valueLinesBrushes.add(BrushUtil.h(255, 246, 93, 80));
        }
        else {
            for (var c = 0; c < a.valueLines.count; c++) {
                if (a.valueLines._inner[c] == 4) {
                    a.valueLines.removeAt(c);
                    a.valueLinesBrushes.removeAt(c);
                    c--;
                }
            }
        }
    };
    DomainChartToolbarProvider.prototype.j = function (a, b) {
        if (this.d(b, "Average")) {
            if (a.valueLines == null) {
                a.valueLines = new ValueModeCollection();
            }
            if (a.valueLinesBrushes == null) {
                a.valueLinesBrushes = new BrushCollection();
            }
            a.valueLines.add(6);
            a.valueLinesBrushes.add(BrushUtil.h(255, 248, 173, 118));
        }
        else {
            for (var c = 0; c < a.valueLines.count; c++) {
                if (a.valueLines._inner[c] == 6) {
                    a.valueLines.removeAt(c);
                    a.valueLinesBrushes.removeAt(c);
                    c--;
                }
            }
        }
    };
    DomainChartToolbarProvider.prototype.x = function (a, b) {
        if (this.d(b, "SeriesAvg")) {
            if (a.valueLines == null) {
                a.valueLines = new ValueModeCollection();
            }
            if (a.valueLinesBrushes == null) {
                a.valueLinesBrushes = new BrushCollection();
            }
            a.valueLines.add(3);
            a.valueLinesBrushes.add(BrushUtil.h(0, 0, 0, 0));
        }
        else {
            for (var c = 0; c < a.valueLines.count; c++) {
                if (a.valueLines._inner[c] == 3) {
                    a.valueLines.removeAt(c);
                    a.valueLinesBrushes.removeAt(c);
                    c--;
                }
            }
        }
    };
    DomainChartToolbarProvider.prototype.z = function (a, b) {
        if (this.d(b, "ShowValueLabels")) {
            a.autoCalloutsVisible = true;
        }
        else {
            a.autoCalloutsVisible = false;
        }
    };
    DomainChartToolbarProvider.prototype.y = function (a, b) {
        if (this.d(b, "ShowLastValueLabel")) {
            a.finalValueAnnotationsVisible = true;
            a.shouldAvoidAxisAnnotationCollisions = true;
        }
        else {
            a.finalValueAnnotationsVisible = false;
        }
    };
    DomainChartToolbarProvider.prototype.n = function (a, b) {
        this.b = b;
        a.captureTargetImageToClipboard(runOn(this, this.r));
    };
    DomainChartToolbarProvider.prototype.l = function (a, b) {
        this.k(a, b, "AxisFieldLabel");
    };
    DomainChartToolbarProvider.prototype.m = function (a, b) {
        this.k(a, b, "AxisFieldValue");
    };
    DomainChartToolbarProvider.prototype.k = 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.includedProperties != null) {
            var i = a.includedProperties;
            for (var h = 0; h < i.length; h++) {
                var g = i[h];
                if (g == e) {
                    f = true;
                    break;
                }
            }
        }
        var j = false;
        if (a.excludedProperties != null) {
            var m = a.excludedProperties;
            for (var l = 0; l < m.length; l++) {
                var k = m[l];
                if (k == e) {
                    j = true;
                    break;
                }
            }
        }
        if (this.d(b, c)) {
            if (a.includedProperties == null) {
                a.includedProperties = new Array(0);
            }
            if (!f) {
                var n = new Array(a.includedProperties.length + 1);
                for (var o = 0; o < a.includedProperties.length; ++o) {
                    n[o] = a.includedProperties[o];
                }
                n[a.includedProperties.length] = e;
                a.includedProperties = n;
            }
            if (j) {
                if (a.excludedProperties.length == 1) {
                    a.excludedProperties = new Array(0);
                }
                else {
                    var p = new Array(a.excludedProperties.length - 1);
                    var q = -1;
                    var r = 0;
                    while (r < p.length) {
                        q++;
                        if (a.excludedProperties[q] == e) {
                            continue;
                        }
                        p[r] = a.excludedProperties[q];
                        r++;
                    }
                    a.excludedProperties = p;
                }
            }
        }
        else if ((a.includedProperties == null || a.includedProperties.length == 0) && (this.e.count + this.f.count > 1)) {
            var s = this.e.count + this.f.count - 1;
            var t = new Array(s);
            var u = 0;
            try {
                for (var _c = __values(fromEnum(this.e)), _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.f)), _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.includedProperties = t;
        }
        else if (f) {
            if (a.includedProperties.length == 1) {
                a.includedProperties = new Array(0);
            }
            else {
                var x = new Array(a.includedProperties.length - 1);
                var y = -1;
                var z = 0;
                while (z < x.length) {
                    y++;
                    if (a.includedProperties[y] == e) {
                        continue;
                    }
                    x[z] = a.includedProperties[y];
                    z++;
                }
                a.includedProperties = x;
            }
        }
    };
    DomainChartToolbarProvider.prototype.r = function (a, b) {
        var c = b;
        if (this.b.argumentsList == null || this.b.argumentsList.length < 1) {
            this.b.argumentsList = new Array(1);
            this.b.argumentsList[0] = ((function () {
                var $ret = new ToolCommandArgument();
                $ret.argumentName = "image";
                return $ret;
            })());
        }
        this.b.argumentsList[0].value = c.base64Data;
        if (this.a != null) {
            this.a.sendCommandCompleted(this.b);
        }
    };
    DomainChartToolbarProvider.prototype.ab = function (a, b) {
        a.zoomIn(0.05);
    };
    DomainChartToolbarProvider.prototype.ac = function (a, b) {
        a.zoomOut(0.05);
    };
    DomainChartToolbarProvider.prototype.ad = function (a, b) {
        a.resetZoom();
    };
    DomainChartToolbarProvider.$t = markType(DomainChartToolbarProvider, 'DomainChartToolbarProvider', Base.$, [IDomainChartToolbarProvider_$type]);
    return DomainChartToolbarProvider;
}(Base));
export { DomainChartToolbarProvider };
