/*
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 * as tslib_1 from "tslib";
import { FinancialChartDropDownControlView } from "./FinancialChartDropDownControlView";
import { Type, Array_$type, typeGetValue, fromEnum, EnumUtil, markType } from "igniteui-react-core/ES5/type";
import { SRProvider } from "igniteui-react-core/ES5/SRProvider";
import { FinancialChartIndicatorMenuItems } from "./FinancialChartIndicatorMenuItems";
import { Dictionary$2 } from "igniteui-react-core/ES5/Dictionary$2";
import { TemplatedHtmlControl } from "./TemplatedHtmlControl";
import { FinancialIndicatorType_$type } from "./FinancialIndicatorType";
import { FinancialOverlayType_$type } from "./FinancialOverlayType";
import { TrendLineType_$type } from "igniteui-react-core/ES5/TrendLineType";
import { FinancialChartVolumeType_$type } from "./FinancialChartVolumeType";
import { FinancialIndicatorTypeCollection } from "./FinancialIndicatorTypeCollection";
import { FinancialOverlayTypeCollection } from "./FinancialOverlayTypeCollection";
import { stringIsNullOrEmpty } from "igniteui-react-core/ES5/string";
import { stringFormat } from "igniteui-react-core/ES5/stringExtended";
/**
 * @hidden
 */
var FinancialChartIndicatorMenuView = /** @class */ (function (_super) {
    tslib_1.__extends(FinancialChartIndicatorMenuView, _super);
    function FinancialChartIndicatorMenuView() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    FinancialChartIndicatorMenuView.prototype.f = function (a, b, c, d) {
        var e_1, _a;
        _super.prototype.f.call(this, a, b, c, d);
        var e = new SRProvider(a);
        TemplatedHtmlControl.n(".financialChartIndicatorMenuLabel", "FinancialChart_IndicatorMenu_Header", a, e);
        TemplatedHtmlControl.n(".financialChartIndicatorMenuDropDownMenu li[data-value='FinancialOverlayType'] span", "FinancialChart_IndicatorMenu_OverlaysCategoryHeader", a, e);
        TemplatedHtmlControl.n(".financialChartIndicatorMenuDropDownMenu li[data-value='TrendLineType'] span", "FinancialChart_IndicatorMenu_TrendlinesCategoryHeader", a, e);
        TemplatedHtmlControl.n(".financialChartIndicatorMenuDropDownMenu li[data-value='FinancialChartVolumeType'] span", "FinancialChart_IndicatorMenu_VolumeCategoryHeader", a, e);
        TemplatedHtmlControl.n(".financialChartIndicatorMenuDropDownMenu li[data-value='FinancialIndicatorType'] span", "FinancialChart_IndicatorMenu_IndicatorsCategoryHeader", a, e);
        var f = new FinancialChartIndicatorMenuItems(e);
        var g = new Dictionary$2(Type.$, Array_$type, 0);
        try {
            for (var _b = tslib_1.__values(fromEnum(f)), _c = _b.next(); !_c.done; _c = _b.next()) {
                var h = _c.value;
                if (h.c < 1) {
                    continue;
                }
                var i = typeGetValue(h.d);
                if (!g.containsKey(h.g)) {
                    g.addItem(h.g, EnumUtil.getNames(h.g));
                }
                var j = g.item(h.g)[i];
                if (stringIsNullOrEmpty(j)) {
                    continue;
                }
                j = j.charAt(0).toUpperCase() + j.substr(1);
                var k = stringFormat(".financialChartIndicatorMenuDropDownMenuList li[data-value='{0}']", j);
                TemplatedHtmlControl.m(k, h.f, a);
            }
        }
        catch (e_1_1) { e_1 = { error: e_1_1 }; }
        finally {
            try {
                if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
            }
            finally { if (e_1) throw e_1.error; }
        }
    };
    FinancialChartIndicatorMenuView.prototype.k = function (a) {
        _super.prototype.k.call(this, a);
        var b = a;
        if (b.tagName != "LI") {
            return;
        }
        var c = b.parentNode.parentNode;
        var d;
        var e = false;
        switch (c.getAttribute("data-value")) {
            case "FinancialOverlayType":
                d = FinancialOverlayType_$type;
                e = false;
                break;
            case "TrendLineType":
                d = TrendLineType_$type;
                e = true;
                break;
            case "FinancialChartVolumeType":
                d = FinancialChartVolumeType_$type;
                e = true;
                break;
            default:
            case "FinancialIndicatorType":
                d = FinancialIndicatorType_$type;
                e = false;
                break;
        }
        var f = b.classList.toggle("checked");
        var g = b.parentNode;
        if (e) {
            for (var h = 0; h < g.children.length; h++) {
                var i = g.children.item(h);
                if (i != b) {
                    i.classList.remove("checked");
                }
            }
            var j = f ? b.getAttribute("data-value") : "None";
            if (stringIsNullOrEmpty(j)) {
                return;
            }
            var k = EnumUtil.parse(d, j, true);
            if (d == FinancialChartVolumeType_$type) {
                this.l.h = EnumUtil.getEnumValue(FinancialChartVolumeType_$type, k);
            }
            else {
                this.l.k = EnumUtil.getEnumValue(TrendLineType_$type, k);
            }
        }
        else {
            if (d == FinancialIndicatorType_$type) {
                this.l.i = new FinancialIndicatorTypeCollection(0);
                ;
            }
            else {
                this.l.j = new FinancialOverlayTypeCollection(0);
            }
            for (var l = 0; l < g.children.length; l++) {
                var m = g.children.item(l);
                if (m.classList.contains("checked")) {
                    var n = m.getAttribute("data-value");
                    if (stringIsNullOrEmpty(n)) {
                        continue;
                    }
                    var o = EnumUtil.parse(d, n, true);
                    if (d == FinancialIndicatorType_$type) {
                        var p = EnumUtil.getEnumValue(FinancialIndicatorType_$type, o);
                        this.l.i.add(p);
                    }
                    else {
                        var q = EnumUtil.getEnumValue(FinancialOverlayType_$type, o);
                        this.l.j.add(q);
                    }
                }
            }
        }
        this.a.onSelectionChanged();
    };
    Object.defineProperty(FinancialChartIndicatorMenuView.prototype, "l", {
        get: function () {
            return this.a;
        },
        enumerable: true,
        configurable: true
    });
    FinancialChartIndicatorMenuView.$t = markType(FinancialChartIndicatorMenuView, 'FinancialChartIndicatorMenuView', FinancialChartDropDownControlView.$);
    return FinancialChartIndicatorMenuView;
}(FinancialChartDropDownControlView));
export { FinancialChartIndicatorMenuView };
