"use strict";

import {config} from "../../../config.js";
import {util} from "../../../util/util.js";
import {khcToastr} from "../../alert/khcToastr.js";
import {fullMap} from "../../../fullMap.js";

class icon {
    constructor(data) {
        this.data=data.data;
        this.eleID = util.getUUID();
        this.objID = this.eleID + 'div';
        this.headerIconInitMap = new Map();
        this.headerIconArray=[
            {
                div_id: 'showSystemNotify',//divId
                div_title: '通知',//弹出模块标题
                div_class: 'dropdown-menu dropdown-menu-right',//弹出模块class
                icon_title: '通知',//图标名称，只有在屏幕较小的时候点击右上角时才会展示
                icon: 'ion ion-md-notifications-outline navbar-icon align-middle',//图标
                init_method: 'initSystemNotify',//初始化数据
                show_detail_method: 'showDetailNotifyInfo',//查看单挑数据详情
                show_all_method: 'toPageSystemNotify',//查看更多事件(跳转页面)
                button_event: 'click',
                js_path: ''
            }
        ];
        //this.headerIconArray=[];//todo 暂时屏蔽通知

    }
    render() {
        let that=this;
        return new Promise((resolve, reject) => {
            let iconHtml=that.getIconHtml(that.data);
            document.getElementById('showHeaderIcon').innerHTML='';
            document.getElementById('showHeaderIcon').insertAdjacentHTML("beforeEnd", iconHtml);
            for (let i = 0; i < that.headerIconArray.length; i++) {
                let headerIconInitFunc=function (){
                    let jsonConfig={objID:that.objID,button_method:that.headerIconArray[i].init_method,iconData:that.headerIconArray[i]}
                    if (util.isNull(that.headerIconArray[i].js_path)) {
                        util.import2023('../component/header/icon/iconAction.js',jsonConfig);
                    } else {
                        util.import2023(that.headerIconArray[i].js_path,jsonConfig);
                    }
                }
                headerIconInitFunc();
                that.headerIconInitMap.set(that.headerIconArray[i].div_id,headerIconInitFunc);

            }
            fullMap.getObj('ws').khcWSFuncMap.set("initSystemNotify",function (data){
                that.headerIconInitMap.get('showSystemNotify')();
            });
            fullMap.getObj('ws').khcWSFuncMap.set("testShowMessage",function (data){
                khcToastr.showSuccessMessage(data.message)
            });
            resolve();
        });
    }
    getIconHtml(){
        let that=this;
        let htmlTemplate=``;//${myData.length>0?`danger`:``}
        for (let i = 0; i < this.headerIconArray.length; i++) {
            htmlTemplate+=`
            <div class="demo-navbar-notifications nav-item dropdown mr-lg-3">
            <a class="nav-link dropdown-toggle hide-arrow" href="#" data-toggle="dropdown">
            <i class="ion ion-md-notifications-outline navbar-icon align-middle"></i>
            <span class="badge badge- badge-dot indicator" id="${that.headerIconArray[i].div_id}IndicatorColor"></span>
            <span class="d-lg-none align-middle">&nbsp; ${that.headerIconArray[i].icon_title}</span>
            </a>
            <div class="dropdown-menu dropdown-menu-right" style="right:0;left:auto">
            <div class="bg-primary text-center text-white font-weight-bold p-3">
            <span name="${that.headerIconArray[i].div_id}Count"></span>${that.headerIconArray[i].div_title}</div>
            <div class="list-group list-group-flush" id="${that.headerIconArray[i].div_id}">
            </div>
            <a href="${config.getIndexUrl()+'#page_my_info?component_code=notify'}" class="d-block text-center text-light small p-2 my-1">显示所有通知</a>
            </div>
            </div>
            `;
        }
        return htmlTemplate;
    }
}
export { icon }
