/*
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 { FinancialChartDropDownControlView } from "./FinancialChartDropDownControlView";
import { Type, Array_$type, typeGetValue, fromEnum, EnumUtil, markType } from "igniteui-react-core/ES2015/type";
import { SRProvider } from "igniteui-react-core/ES2015/SRProvider";
import { FinancialChartIndicatorMenuItems } from "./FinancialChartIndicatorMenuItems";
import { Dictionary$2 } from "igniteui-react-core/ES2015/Dictionary$2";
import { TemplatedHtmlControl } from "./TemplatedHtmlControl";
import { FinancialIndicatorType_$type } from "./FinancialIndicatorType";
import { FinancialOverlayType_$type } from "./FinancialOverlayType";
import { TrendLineType_$type } from "igniteui-react-core/ES2015/TrendLineType";
import { FinancialChartVolumeType_$type } from "./FinancialChartVolumeType";
import { FinancialIndicatorTypeCollection } from "./FinancialIndicatorTypeCollection";
import { FinancialOverlayTypeCollection } from "./FinancialOverlayTypeCollection";
import { stringIsNullOrEmpty } from "igniteui-react-core/ES2015/string";
import { stringFormat } from "igniteui-react-core/ES2015/stringExtended";
/**
 * @hidden
 */
export class FinancialChartIndicatorMenuView extends FinancialChartDropDownControlView {
    f(a, b, c, d) {
        super.f(a, b, c, d);
        let 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);
        let f = new FinancialChartIndicatorMenuItems(e);
        let g = new Dictionary$2(Type.$, Array_$type, 0);
        for (let h of fromEnum(f)) {
            if (h.c < 1) {
                continue;
            }
            let i = typeGetValue(h.d);
            if (!g.containsKey(h.g)) {
                g.addItem(h.g, EnumUtil.getNames(h.g));
            }
            let j = g.item(h.g)[i];
            if (stringIsNullOrEmpty(j)) {
                continue;
            }
            j = j.charAt(0).toUpperCase() + j.substr(1);
            let k = stringFormat(".financialChartIndicatorMenuDropDownMenuList li[data-value='{0}']", j);
            TemplatedHtmlControl.m(k, h.f, a);
        }
    }
    k(a) {
        super.k(a);
        let b = a;
        if (b.tagName != "LI") {
            return;
        }
        let c = b.parentNode.parentNode;
        let d;
        let 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;
        }
        let f = b.classList.toggle("checked");
        let g = b.parentNode;
        if (e) {
            for (let h = 0; h < g.children.length; h++) {
                let i = g.children.item(h);
                if (i != b) {
                    i.classList.remove("checked");
                }
            }
            let j = f ? b.getAttribute("data-value") : "None";
            if (stringIsNullOrEmpty(j)) {
                return;
            }
            let 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 (let l = 0; l < g.children.length; l++) {
                let m = g.children.item(l);
                if (m.classList.contains("checked")) {
                    let n = m.getAttribute("data-value");
                    if (stringIsNullOrEmpty(n)) {
                        continue;
                    }
                    let o = EnumUtil.parse(d, n, true);
                    if (d == FinancialIndicatorType_$type) {
                        let p = EnumUtil.getEnumValue(FinancialIndicatorType_$type, o);
                        this.l.i.add(p);
                    }
                    else {
                        let q = EnumUtil.getEnumValue(FinancialOverlayType_$type, o);
                        this.l.j.add(q);
                    }
                }
            }
        }
        this.a.onSelectionChanged();
    }
    get l() {
        return this.a;
    }
}
FinancialChartIndicatorMenuView.$t = markType(FinancialChartIndicatorMenuView, 'FinancialChartIndicatorMenuView', FinancialChartDropDownControlView.$);
