package com.mortals.xhx.common.code;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author: finegirl
 * @date: 2021/7/16 11:50
 * @description: 组件枚举类
 **/
public enum ComponentEnum {
    INPUT("i", "普通输入框"),
    TEXTAREA("t", "文本输入框"),
    SELECT("s", "下拉选择框"),
    BUTTON("btn", "按钮"),
    CHECKBOX("ck", "复选框"),
    DATE("date", "日期选择栏"),
    AREA("area", "区域选择栏"),
    IMAGE("image", "图片选择");

    private String value;
    private String desc;

    ComponentEnum(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public String getValue() {
        return this.value;
    }

    public String getDesc() {
        return this.desc;
    }

    public static ComponentEnum getByValue(String value) {
        for (ComponentEnum componentEnum : ComponentEnum.values()) {
            if (componentEnum.getValue() == value) {
                return componentEnum;
            }
        }
        return null;
    }

    /**
     * 获取Map集合
     *
     * @param eItem 不包含项
     * @return
     */
    public static Map<String, String> getEnumMap(String... eItem) {
        Map<String, String> resultMap = new LinkedHashMap<>();
        for (ComponentEnum item : ComponentEnum.values()) {
            try {
                boolean hasE = false;
                for (String e : eItem) {
                    if (item.getValue() == e) {
                        hasE = true;
                        break;
                    }
                }
                if (!hasE) {
                    resultMap.put(item.getValue() + "", item.getDesc());
                }
            } catch (Exception ex) {
            }
        }
        return resultMap;
    }
}