<template>
    <div></div>
</template>

<script>

import exTable from './exComp/exTable.vue';
import exColumn from './exComp/exColumn.vue';
import exPubTable from './exComp/exPubTable.vue';
import exDialog from './exComp/exDialog.vue';
import exInput from './exComp/exInput.vue';
import exGoldInput from './exComp/exGoldInput.vue';
import exFenInput from './exComp/exFenInput.vue';
import exSelect from './exComp/exSelect.vue';
import exCheckBoxGroup from './exComp/exCheckBoxGroup.vue';
import exRadioGroup from './exComp/exRadioGroup.vue';
import exDateTime from './exComp/exDateTime.vue';
import exDate from './exComp/exDate.vue';
import exDateRange from './exComp/exDateRange.vue';
import exCascader from './exComp/exCascader.vue';
import exSwitch from './exComp/exSwitch.vue';
import exMenuItem from './exComp/exMenuItem.vue';

import util from './lib/commonutil.vue';
import dayjs from './lib/day.vue';
import dialogDrag from './lib/dialogDrag.vue';
import isEnv from './lib/isEnv.vue';

export default {

    initAll(Vue){
        util.init(Vue);
        dayjs.init(Vue);
        dialogDrag.init(Vue);
        isEnv.init(Vue);

        Vue.component('exTable', exTable);
        Vue.component('exColumn', exColumn);
        Vue.component('exPubTable', exPubTable);
        Vue.component('exDialog', exDialog);
        Vue.component('exInput', exInput);
        Vue.component('exGoldInput', exGoldInput);
        Vue.component('exFenInput', exFenInput);
        Vue.component('exSelect', exSelect);
        Vue.component('exCheckBoxGroup', exCheckBoxGroup);
        Vue.component('exRadioGroup', exRadioGroup);
        Vue.component('exDateTime', exDateTime);
        Vue.component('exDate', exDate);
        Vue.component('exCascader', exCascader);
        Vue.component('exDateRange', exDateRange);
        Vue.component('exSwitch', exSwitch);
        Vue.component('exMenuItem', exMenuItem);

        
    },
    initUtil(vue){
        util.init(vue);
    },
    initDayjs(vue){
        dayjs.init(vue);
    },
    initDire(vue){
        dialogDrag.init(vue);
        isEnv.init(vue);
    },
    initDictFn(dict){
        dict.getListByEnv=($vue,code,isBool,isNumber)=>{
            var envCfg = $vue.$store.state.envCfg || {};
            var list = dict.getList(code,isBool,isNumber);
            return dict.filterByEnv(list,envCfg);
        };
        dict.getListByNodes=(sourceObj,nodes)=>{
            var flagKey = dict.$envFlag ? "@"+dict.$envFlag : "";
            var list = sourceObj;
            nodes.map((item)=>{
                if(list){
                    list = list[item+flagKey]? list[item+flagKey]: list[item]
                }
            });
            return list;
        }
        dict.getDictListByApp=(code)=>{
            var dictType = dict.$dictType ? dict.$dictType : "";
            var nodes = code.split(".");
            if(dictType){
                var nodes_2 = [dictType].concat(nodes);
                var list = dict.getListByNodes(dict,nodes_2) || [];
                if(list && list.length>0){
                    return list;
                }
            }
            var list = dict.getListByNodes(dict,nodes) || [];
            return list;
        }
        dict.getDictMapByApp=(code)=>{
            var dictType = dict.$dictType ? dict.$dictType : "";
            var nodes = code.split(".");
            if(dictType){
                var nodes_2 = [dictType].concat(nodes);
                var map = dict.getListByNodes(dict.dictMap,nodes_2);
                if(map) return map;
            }
            var map = dict.getListByNodes(dict.dictMap,nodes);
            return map;
        }
        dict.getList=(code,isBool,isNumber,lang="")=>{
            var list = dict.getDictListByApp(code)
            list = JSON.parse(JSON.stringify(list));
            if(isBool){
                list.map((item)=>{
                    if(item.value=="1") item.value=true;
                    else if(item.value=="0") item.value=false;
                });
            }else if(isNumber){
                list.map((item)=>{
                    if(!isNaN(item.value)) item.value = item.value*1;
                });
            }else if(isNumber===false){
                list.map((item)=>{
                    item.value = item.value+"";
                });
            }
            if(lang){
                list.map((item)=>{
                    item.name = item["name"+lang] || item.name;
                });
            }
            return list;
        };

        dict.getPubList=(code,value,tag)=>{
            var pubitem =  dict.$pubList.find(item=>{return item.value==code});
            if(!pubitem){
                if(tag) return {};
                return [];
            }else{
                var list = pubitem.list;
                if(!value){
                    return list;
                }else{
                    if(!tag){
                        list = list.filter(item=>{return item.value==value})
                    }else{
                        list = list.filter(item=>{return item.value==value && item.tag==tag});
                        if(list.length==1){
                            list = list[0]
                        }else if(list.length==0){
                            list = {}
                        }
                    }
                }
                return list;
            }

        }
        
        dict.tranByPubMap=(name)=>{
            if(!name || !dict.$map || !name.replace) return name;
            name = name.replace(/\((.*?)\|(.*?)\)/g,(a,b,c,d)=>{
                if(b){
                    var dictitem = dict.$map[b] || {};
                    return dictitem[dict.$envFlag] || c;
                }
                return c
            })
            return name;
        }
        dict.getDictItem=(code,val)=>{
            if(val==undefined) return {};
            if(!val && val!==0) return {};
            var map = dict.getDictMapByApp(code)
            if(!map) return {};
            var item = map["@"+val];
            return item || {};
        };
        dict.tranDict=(code,val)=>{
            if(val==undefined) return "";
            if(!val && val!==0) return val+"";
            var map = dict.getDictMapByApp(code)
            if(!map) return val+"";
            var retstr = map[val] || val;
            var item = map["@"+val];
            if(item && item.color) {
                return `<span style="color:${item.color}">${retstr}</span>`
            }
            return retstr+"";
        };

        dict.addDict=(name,list,prenode)=>{
            if(prenode){
                if(!dict[prenode]) dict[prenode] = {};
                if(prenode=="dbdict"){
                    if(["caveSlotBet","coinSlotBet","fruitClassicBet","fruitStrollBet"].findIndex((item)=>{return item==name})!=-1){
                        list.map((item)=>{
                            item.goldFlag = true;
                        })
                    }
                }
                dict[prenode][name] = list;
                if(dict.dictMap){
                    if(!dict.dictMap[prenode]) dict.dictMap[prenode] = {};
                    if(list.map){
                        dict.dictMap[prenode][name] = tranListToMap(list);
                    }else {
                        dict.dictMap[prenode][name] = tranListItemToMap(list);
                    }
                }
            }else {
                dict[name] = list;
                if(dict.dictMap){
                    if(list.map){
                        dict.dictMap[name] = tranListToMap(list);
                    }else {
                        dict.dictMap[name] = tranListItemToMap(list);
                    }
                }
            }

        }

        var tranListItemToMap=(items)=>{
            var retmap = {};
            for(var key in items){
                // if(key=="sceneList"){
                //     debugger;
                // }
                var dictitem = items[key];
                if(!dictitem){ return; };
                if(dictitem.map){
                    if(key.indexOf("_level")==-1){
                        var map = tranListToMap(dictitem);
                        retmap[key]=map;
                    }else{
                        var map = tranListToMapForLevel(dictitem,null);
                        retmap[key]=map;
                        retmap[key.replace("_level","")]=map;
                    }
                    
                }else if(typeof dictitem !="string" && typeof dictitem !="function") {
                    retmap[key]=tranListItemToMap(dictitem);
                }
            }
            return retmap;
        };
        var tranListToMap=(list)=>{
            var map = {};
            list.map(function(item){
                item.name = dict.tranByPubMap(item.name);
                map[item.value]=item.name;
                map["@"+item.value]=item;
            })
            return map;
        }
        var tranListToMapForLevel=(list,map)=>{
            map = map|| {};
            list.map(function(item){
                item.name = dict.tranByPubMap(item.name);
                map[item.value]=item.name;
                map["@"+item.value]=item;
                if(item.children){
                    tranListToMapForLevel(item.children,map);
                }
            })
            return map;
        }

        dict.setDictMap=()=>{
            try{
                dict.dictMap = tranListItemToMap(dict);
                if(!dict.dictMap){
                    dict.dictMap = {};
                }
            }catch(ex){
                console.log(ex)
            }
        };
        dict.tranDictByList=(list,value)=>{
            var name = "";
            list.map((item)=>{
                if(item.value == value){
                    name = item.name;
                }
            });
            return name || value;
        };

        dict.filterByEnv = (list,envCfg,notTop)=>{
            if(!notTop) list = JSON.parse(JSON.stringify(list));
            list = list.filter((item)=>{
                if(!item.envFlag) return true;
                let curflag = item.envFlag[envCfg.envFlag];
                if(curflag!=undefined) return curflag;
                let defflag = item.envFlag.def;
                if(defflag!=undefined) return defflag;
                return false;
            });
            list.map(item=>{
                if(item.goldFlag && envCfg.goldBet>1){
                    item.name = item.name.replace("倍","")
                    if(!isNaN(item.name)){
                        item.name = parseInt(item.name*envCfg.goldBet)
                    }
                }
                if(item.children){
                    item.children = dict.filterByEnv(item.children,envCfg,true)
                }
            })
            return list;
        }

        dict.tranFlowByStr = (str)=>{
            str = str.replace("f","")
            var arr = str.split("s");
            return dict.tranFlow(arr[0],arr[1])
        }
        dict.tranFlow = (flowid,sceneid)=>{
            var names = [];
            if(sceneid){
                var name = dict.tranDict("dbdict.scence",sceneid);
                if(name) names.push("场景: "+name)
            }
            if(flowid){
                var name = dict.tranDict("log.flow.flowType_level",flowid);
                if(name) names.push("行为: "+name)
            }
            return names.join("　")
        }
        dict.tranProp = (val1,val2,val3,bet)=>{
            var type,propid,num;
            if(val1==1){
                type = val2;
                num = val3
            }else{
                type = val1;
                propid=val2;
                num = val3;
            }
            var pname = "";
            if(type==4000){   //宠物
                pname = dict.tranDict("dbdict.pet",propid)
            } else if(type==5000){    //卡片
                pname = dict.tranDict("dbdict.card",propid)
            } else if(type==6000){    //宝箱
                pname = dict.tranDict("dbdict.chest",propid)
            } else if(type==7000){    //礼包
                pname = dict.tranDict("dbdict.gift",propid)
            } else{
                // pname = dict.tranDict("log.flow.propType",type)
                pname = dict.tranDict("dbdict.props",type)
            }
            if(pname && num){
                if(bet){
                    num = parseInt(num*bet);
                }
                pname += ":"+num
            }
            return pname;
        }


    }
}
</script>
