/*
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, typeCast, runOn, markType } from "igniteui-angular-core";
import { IDomainChartToolbarProvider_$type } from "./IDomainChartToolbarProvider";
import { ToolCommandStateChanged } from "igniteui-angular-core";
import { BrushUtil } from "igniteui-angular-core";
import { Defaults } from "./Defaults";
import { LegendTemplates } from "./LegendTemplates";
import { HashSet$1 } from "igniteui-angular-core";
import { ToolActionGroupHeaderInfo } from "igniteui-angular-core";
import { ToolActionCheckboxListInfo } from "igniteui-angular-core";
import { Dictionary$2 } from "igniteui-angular-core";
import { DomainChartCheckboxListItem } from "./DomainChartCheckboxListItem";
import { ToolActionIconMenuInfo } from "igniteui-angular-core";
import { DataSeriesAdapterPropertyInfo } from "igniteui-angular-core";
import { NativeUIComponent } from "igniteui-angular-core";
import { ToolContextBindingInfo } from "igniteui-angular-core";
import { XYChart } from "./XYChart";
import { BrushUtilCore } from "igniteui-angular-core";
import { ToolCommandArgument } from "igniteui-angular-core";
import { AxisStrokeSettings } from "./AxisStrokeSettings";
import { DeviceUtils } from "igniteui-angular-core";
import { FastIterationDictionary$2 } from "igniteui-angular-core";
import { AxisDefaults } from "./AxisDefaults";
import { TrendLineTypeCollection } from "./TrendLineTypeCollection";
import { ValueModeCollection } from "./ValueModeCollection";
import { BrushCollection } from "igniteui-angular-core";
import { isNaN_ } from "igniteui-angular-core";
/**
 * @hidden
 */
export let DomainChartToolbarProvider = /*@__PURE__*/ (() => {
    class DomainChartToolbarProvider extends Base {
        constructor() {
            super(...arguments);
            this.e = null;
            this.g = false;
            this._container = null;
            this.b = new DataSeriesAdapterPropertyInfo();
            this.c = new DataSeriesAdapterPropertyInfo();
            this._commandChanged = null;
            this.f = new FastIterationDictionary$2(String_$type, AxisStrokeSettings.$, 0);
            this.d = null;
        }
        get container() {
            return this._container;
        }
        set container(a) {
            this._container = a;
        }
        get commandChanged() {
            return this._commandChanged;
        }
        set commandChanged(a) {
            this._commandChanged = a;
        }
        static ag(a) {
            let b = a.data;
            let c = BrushUtil.j(255, 0, 0, 0);
            LegendTemplates.u(a, 2, c, null, 0, 0, Defaults.legendBadge_ShapeWidth, Defaults.legendBadge_ShapeHeight);
        }
        getDesiredToolbarActions(a, b, c) {
            let d;
            if (a.itemsSource != null && NativeUIComponent.v(16, 0)) {
                let e = new ToolActionGroupHeaderInfo();
                e.name = "AxisFieldLabelHeader";
                e.title = "Label Fields";
                let f = new ToolActionCheckboxListInfo();
                f.name = "AxisFieldLabel";
                let g = new ToolActionGroupHeaderInfo();
                g.name = "AxisFieldValueHeader";
                g.title = "Value Fields";
                let h = new ToolActionCheckboxListInfo();
                h.name = "AxisFieldValue";
                let i = a.includedProperties == null ? null : new HashSet$1(String_$type, 1, a.includedProperties);
                let j = 0;
                if (i != null && a.excludedProperties != null && a.excludedProperties.length > 0) {
                    let k = new HashSet$1(String_$type, 1, a.excludedProperties);
                    for (let l of fromEnum(k)) {
                        if (i.contains(l)) {
                            i.remove(l);
                        }
                    }
                    let m = i.count;
                    let n = new Array(m);
                    j = 0;
                    for (let o of fromEnum(i)) {
                        n[j] = o;
                        j++;
                    }
                }
                a.currentDataAdapter.az(this.b, this.c);
                let p = new Dictionary$2(String_$type, String_$type, 0);
                for (let q = 0; q < this.b.b.length; q++) {
                    let r = this.b.b[q];
                    if (p.containsKey(r)) {
                        continue;
                    }
                    p.addItem(this.b.b[q], this.b.a[q]);
                }
                this.b = ((() => {
                    let $ret = new DataSeriesAdapterPropertyInfo();
                    $ret.b = new Array(p.count);
                    $ret.a = new Array(p.count);
                    $ret.c = new Array(p.count);
                    return $ret;
                })());
                j = 0;
                for (let s of fromEnum(p)) {
                    this.b.b[j] = s.key;
                    this.b.a[j] = s.value;
                    j++;
                }
                let t = new Array(p.count);
                for (let u = 0; u < this.b.b.length; u++) {
                    t[u] = ((() => {
                        let $ret = new DomainChartCheckboxListItem();
                        $ret.key = this.b.b[u];
                        $ret.label = this.b.a[u];
                        $ret.isSelected = i == null || i.contains(this.b.b[u]);
                        return $ret;
                    })());
                }
                for (let v of fromEnum(c)) {
                    v.setContextValue("AxisFieldLabels", 7, t);
                }
                f.dataMemberPath = "label";
                f.selectedMemberPath = "isSelected";
                f.primaryKey = ["key"];
                f.contextBindings = [((() => {
                        let $ret = new ToolContextBindingInfo();
                        $ret.bindingMode = 0;
                        $ret.contextKey = "AxisFieldLabels";
                        $ret.propertyName = "ItemsSource";
                        return $ret;
                    })())];
                p = new Dictionary$2(String_$type, String_$type, 0);
                for (let w = 0; w < this.c.b.length; w++) {
                    let x = this.c.b[w];
                    if (p.containsKey(x)) {
                        continue;
                    }
                    p.addItem(this.c.b[w], this.c.a[w]);
                }
                this.c = ((() => {
                    let $ret = new DataSeriesAdapterPropertyInfo();
                    $ret.b = new Array(p.count);
                    $ret.a = new Array(p.count);
                    $ret.c = new Array(p.count);
                    return $ret;
                })());
                j = 0;
                for (let y of fromEnum(p)) {
                    this.c.b[j] = y.key;
                    this.c.a[j] = y.value;
                    j++;
                }
                let z = new Array(p.count);
                for (let aa = 0; aa < this.c.b.length; aa++) {
                    z[aa] = ((() => {
                        let $ret = new DomainChartCheckboxListItem();
                        $ret.key = this.c.b[aa];
                        $ret.label = this.c.a[aa];
                        $ret.isSelected = i == null || i.contains(this.c.b[aa]);
                        return $ret;
                    })());
                }
                for (let ab of fromEnum(c)) {
                    ab.setContextValue("AxisFieldValues", 7, z);
                }
                h.dataMemberPath = "label";
                h.selectedMemberPath = "isSelected";
                h.primaryKey = ["key"];
                h.contextBindings = [((() => {
                        let $ret = new ToolContextBindingInfo();
                        $ret.bindingMode = 0;
                        $ret.contextKey = "AxisFieldValues";
                        $ret.propertyName = "ItemsSource";
                        return $ret;
                    })())];
                let ac = new ToolActionIconMenuInfo();
                ac.name = "AxisFieldMenu";
                ac.iconName = "analyze-valuelabels-showlast";
                ac.iconCollectionName = "ChartToolbarIcons";
                ac.iconWidth = 24;
                ac.iconHeight = 25;
                ac.actions = [e, f, g, h];
                d = new Array(b.length + 1);
                for (let ad = 0; ad < b.length; ad++) {
                    d[ad] = b[ad];
                }
                d[b.length] = ac;
            }
            else {
                d = b;
            }
            for (let ae = 0; ae < d.length; ae++) {
                this.i(a, d[ae]);
            }
            return d;
        }
        i(a, b) {
            if (b.actions != null && b.actions.length > 0) {
                for (let c = 0; c < b.actions.length; c++) {
                    this.i(a, b.actions[c]);
                }
            }
            switch (b.name) {
                case "ShowCrosshairs":
                    {
                        let d = b;
                        d.isChecked = a.crosshairsDisplayMode != 1;
                    }
                    break;
                case "ShowGridlines":
                    {
                        let e = b;
                        if (typeCast(XYChart.$, a) !== null) {
                            let f = a;
                            e.isChecked = f.ahl != null && !BrushUtilCore.a(f.ahl) && f.acr > 0 && f.ahs != null && !BrushUtilCore.a(f.ahs) && f.ada > 0;
                        }
                    }
                    break;
                case "ShowValueLabels":
                    {
                        let g = b;
                        g.isChecked = a.autoCalloutsVisible;
                    }
                    break;
                case "ShowLastValueLabel":
                    {
                        let h = b;
                        h.isChecked = a.finalValueAnnotationsVisible;
                    }
                    break;
                case "MinValue":
                    {
                        if (a.valueLines != null) {
                            let i = b;
                            for (let j = 0; j < a.valueLines.count; j++) {
                                if (a.valueLines._inner[j] == 4) {
                                    i.isChecked = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case "MaxValue":
                    {
                        if (a.valueLines != null) {
                            let k = b;
                            for (let l = 0; l < a.valueLines.count; l++) {
                                if (a.valueLines._inner[l] == 5) {
                                    k.isChecked = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case "Average":
                    {
                        if (a.valueLines != null) {
                            let m = b;
                            for (let n = 0; n < a.valueLines.count; n++) {
                                if (a.valueLines._inner[n] == 6) {
                                    m.isChecked = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case "SeriesAvg":
                    {
                        if (a.valueLines != null) {
                            let o = b;
                            for (let p = 0; p < a.valueLines.count; p++) {
                                if (a.valueLines._inner[p] == 3) {
                                    o.isChecked = true;
                                    break;
                                }
                            }
                        }
                    }
                    break;
                case "AxisFieldLabel":
                    {
                    }
                    break;
                case "AxisFieldValue":
                    {
                    }
                    break;
            }
            this.j(a, b);
        }
        j(a, b) {
        }
        onToolCommandExecuting(a, b) {
            this.g = true;
            let c = 0;
            switch (b.commandId) {
                case "ZoomReset":
                    this.af(a, b);
                    break;
                case "ZoomIn":
                    this.ad(a, b);
                    break;
                case "ZoomOut":
                    this.ae(a, b);
                    break;
                case "ShowCrosshairs":
                    this.q(a, b);
                    break;
                case "ShowGridlines":
                    this.s(a, b);
                    break;
                case "MaxValue":
                    this.w(a, b);
                    break;
                case "MinValue":
                    this.x(a, b);
                    break;
                case "Average":
                    this.l(a, b);
                    break;
                case "Exponential":
                    this.r(a, b);
                    break;
                case "Linear":
                    this.u(a, b);
                    break;
                case "Logarithmic":
                    this.v(a, b);
                    break;
                case "NoTrends":
                    this.y(a, b);
                    break;
                case "SeriesAvg":
                    this.z(a, b);
                    break;
                case "ShowValueLabels":
                    this.ab(a, b);
                    break;
                case "ShowLastValueLabel":
                    this.aa(a, b);
                    break;
                case "CopyAsImage":
                    this.p(a, b);
                    c = 2;
                    break;
                case "AxisFieldLabel":
                    this.n(a, b);
                    break;
                case "AxisFieldValue":
                    this.o(a, b);
                    break;
            }
            this.g = false;
            return c;
        }
        onTargetPropertyChanged(a, b, c, d) {
            if (this.g) {
                return;
            }
            switch (b) {
                case "CrosshairsDisplayMode":
                    if (a.crosshairsDisplayMode == 1) {
                        this.k("ShowCrosshairs", 2, false);
                    }
                    else {
                        this.k("ShowCrosshairs", 2, true);
                    }
                    break;
                case "AutoCalloutsVisible":
                    this.k("ShowValueLabels", 2, a.autoCalloutsVisible);
                    break;
                case "FinalValueAnnotationsVisible":
                    this.k("ShowLastValueLabel", 2, a.finalValueAnnotationsVisible);
                    break;
            }
            this.ac(a, b, c, d);
        }
        ac(a, b, c, d) {
        }
        k(a, b, c) {
            if (this.commandChanged != null) {
                this.commandChanged(((() => {
                    let $ret = new ToolCommandStateChanged();
                    $ret.c = a;
                    $ret.a = b;
                    $ret.b = c;
                    return $ret;
                })()));
            }
        }
        h(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;
        }
        q(a, b) {
            if (this.h(b, "ShowCrosshairs")) {
                a.crosshairsDisplayMode = 0;
                a.crosshairsAnnotationEnabled = true;
            }
            else {
                a.crosshairsDisplayMode = 1;
            }
        }
        a(a, b, c) {
            let d = new AxisStrokeSettings();
            if (b == "xaxis") {
                d.b = a.ahl == null || BrushUtilCore.a(a.ahl) ? c : a.ahl;
                d.a = isNaN_(a.acr) || a.acr == 0 ? DeviceUtils.g(1) : a.acr;
                this.f.item("xaxis", d);
            }
            else {
                d.b = a.ahs == null || BrushUtilCore.a(a.ahs) ? c : a.ahs;
                d.a = isNaN_(a.ada) || a.ada == 0 ? DeviceUtils.g(1) : a.ada;
                this.f.item("yaxis", d);
            }
            return d;
        }
        s(a, b) {
            if (this.h(b, "ShowGridlines")) {
                if (typeCast(XYChart.$, a) !== null) {
                    let c = a;
                    let d = true;
                    if (this.f.d("xaxis")) {
                        if (this.f.item("xaxis").b != c.ahl || c.acr != 0) {
                            d = true;
                        }
                        else {
                            c.ahl = this.f.item("xaxis").b;
                            c.acr = this.f.item("xaxis").a;
                            d = false;
                        }
                    }
                    if (d) {
                        let e = this.a(c, "xaxis", AxisDefaults.axis_MajorBrush);
                        c.ahl = e.b;
                        c.acr = e.a;
                    }
                    d = true;
                    if (this.f.d("yaxis")) {
                        if (this.f.item("yaxis").b != c.ahs || c.ada != 0) {
                            d = true;
                        }
                        else {
                            c.ahs = this.f.item("yaxis").b;
                            c.ada = this.f.item("yaxis").a;
                            d = false;
                        }
                    }
                    if (d) {
                        let f = this.a(c, "yaxis", AxisDefaults.axis_MajorBrush);
                        c.ahs = f.b;
                        c.ada = f.a;
                    }
                }
            }
            else {
                if (typeCast(XYChart.$, a) !== null) {
                    let g = a;
                    if (!this.f.d("xaxis")) {
                        this.a(g, "xaxis", AxisDefaults.axis_MajorBrush);
                    }
                    g.acr = 0;
                    if (!this.f.d("yaxis")) {
                        this.a(g, "yaxis", AxisDefaults.axis_MajorBrush);
                    }
                    g.ada = 0;
                }
            }
        }
        r(a, b) {
            if (this.h(b, "Exponential")) {
                if (a.trendLineTypes == null) {
                    a.trendLineTypes = new TrendLineTypeCollection();
                }
                a.trendLineTypes.clear();
                a.trendLineTypes.add(7);
            }
            else {
                a.trendLineTypes.clear();
            }
        }
        u(a, b) {
            if (this.h(b, "Linear")) {
                if (a.trendLineTypes == null) {
                    a.trendLineTypes = new TrendLineTypeCollection();
                }
                a.trendLineTypes.clear();
                a.trendLineTypes.add(1);
            }
            else {
                a.trendLineTypes.clear();
            }
        }
        v(a, b) {
            if (this.h(b, "Logarithmic")) {
                if (a.trendLineTypes == null) {
                    a.trendLineTypes = new TrendLineTypeCollection();
                }
                a.trendLineTypes.clear();
                a.trendLineTypes.add(6);
            }
            else {
                a.trendLineTypes.clear();
            }
        }
        y(a, b) {
            if (this.h(b, "NoTrends")) {
                a.trendLineTypes.clear();
            }
        }
        w(a, b) {
            if (this.h(b, "MaxValue")) {
                if (a.valueLines == null) {
                    a.valueLines = new ValueModeCollection();
                }
                if (a.valueLinesBrushes == null) {
                    a.valueLinesBrushes = new BrushCollection();
                }
                a.valueLines.add(5);
            }
            else {
                for (let c = 0; c < a.valueLines.count; c++) {
                    if (a.valueLines._inner[c] == 5) {
                        a.valueLines.removeAt(c);
                        c--;
                    }
                }
            }
        }
        x(a, b) {
            if (this.h(b, "MinValue")) {
                if (a.valueLines == null) {
                    a.valueLines = new ValueModeCollection();
                }
                if (a.valueLinesBrushes == null) {
                    a.valueLinesBrushes = new BrushCollection();
                }
                a.valueLines.add(4);
            }
            else {
                for (let c = 0; c < a.valueLines.count; c++) {
                    if (a.valueLines._inner[c] == 4) {
                        a.valueLines.removeAt(c);
                        c--;
                    }
                }
            }
        }
        l(a, b) {
            if (this.h(b, "Average")) {
                if (a.valueLines == null) {
                    a.valueLines = new ValueModeCollection();
                }
                if (a.valueLinesBrushes == null) {
                    a.valueLinesBrushes = new BrushCollection();
                }
                a.valueLines.add(6);
            }
            else {
                for (let c = 0; c < a.valueLines.count; c++) {
                    if (a.valueLines._inner[c] == 6) {
                        a.valueLines.removeAt(c);
                        c--;
                    }
                }
            }
        }
        z(a, b) {
            if (this.h(b, "SeriesAvg")) {
                if (a.valueLines == null) {
                    a.valueLines = new ValueModeCollection();
                }
                if (a.valueLinesBrushes == null) {
                    a.valueLinesBrushes = new BrushCollection();
                }
                a.valueLines.add(3);
            }
            else {
                for (let c = 0; c < a.valueLines.count; c++) {
                    if (a.valueLines._inner[c] == 3) {
                        a.valueLines.removeAt(c);
                        c--;
                    }
                }
            }
        }
        ab(a, b) {
            if (this.h(b, "ShowValueLabels")) {
                a.autoCalloutsVisible = true;
            }
            else {
                a.autoCalloutsVisible = false;
            }
        }
        aa(a, b) {
            if (this.h(b, "ShowLastValueLabel")) {
                a.finalValueAnnotationsVisible = true;
                a.shouldAvoidAxisAnnotationCollisions = true;
            }
            else {
                a.finalValueAnnotationsVisible = false;
            }
        }
        p(a, b) {
            this.e = b;
            a.captureTargetImageToClipboard(runOn(this, this.t));
        }
        n(a, b) {
            this.m(a, b, "AxisFieldLabel");
        }
        o(a, b) {
            this.m(a, b, "AxisFieldValue");
        }
        m(a, b, c) {
            if (b.argumentsList.length != 3) {
                return;
            }
            let d = b.argumentsList[2].value;
            let e = (d[0]);
            let f = false;
            if (a.includedProperties != null) {
                let i = a.includedProperties;
                for (let h = 0; h < i.length; h++) {
                    let g = i[h];
                    if (g == e) {
                        f = true;
                        break;
                    }
                }
            }
            let j = false;
            if (a.excludedProperties != null) {
                let m = a.excludedProperties;
                for (let l = 0; l < m.length; l++) {
                    let k = m[l];
                    if (k == e) {
                        j = true;
                        break;
                    }
                }
            }
            if (this.h(b, c)) {
                if (a.includedProperties == null) {
                    a.includedProperties = new Array(0);
                }
                if (!f) {
                    let n = new Array(a.includedProperties.length + 1);
                    for (let 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 {
                        let p = new Array(a.excludedProperties.length - 1);
                        let q = -1;
                        let 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.b.b.length + this.c.b.length > 1)) {
                let s = this.b.b.length + this.c.b.length - 1;
                let t = new Array(s);
                let u = 0;
                for (let v = 0; v < this.b.b.length; v++) {
                    if (this.b.b[v] == e) {
                        continue;
                    }
                    t[u] = this.b.b[v];
                    u++;
                }
                for (let w = 0; w < this.c.b.length; w++) {
                    if (this.c.b[w] == e) {
                        continue;
                    }
                    t[u] = this.c.b[w];
                    u++;
                }
                a.includedProperties = t;
            }
            else if (f) {
                if (a.includedProperties.length == 1) {
                    a.includedProperties = new Array(0);
                }
                else {
                    let x = new Array(a.includedProperties.length - 1);
                    let y = -1;
                    let z = 0;
                    while (z < x.length) {
                        y++;
                        if (a.includedProperties[y] == e) {
                            continue;
                        }
                        x[z] = a.includedProperties[y];
                        z++;
                    }
                    a.includedProperties = x;
                }
            }
        }
        t(a, b) {
            let c = b;
            if (this.e.argumentsList == null || this.e.argumentsList.length < 1) {
                this.e.argumentsList = new Array(1);
                this.e.argumentsList[0] = ((() => {
                    let $ret = new ToolCommandArgument();
                    $ret.argumentName = "image";
                    return $ret;
                })());
            }
            this.e.argumentsList[0].value = c.base64Data;
            if (this.d != null) {
                this.d.sendCommandCompleted(this.e);
            }
        }
        ad(a, b) {
            a.zoomIn(0.05);
        }
        ae(a, b) {
            a.zoomOut(0.05);
        }
        af(a, b) {
            a.resetZoom();
        }
    }
    DomainChartToolbarProvider.$t = markType(DomainChartToolbarProvider, 'DomainChartToolbarProvider', Base.$, [IDomainChartToolbarProvider_$type]);
    return DomainChartToolbarProvider;
})();
