"use strict";
import { khcAlert } from '../../../component/alert/khcAlert.js'
import { fullMap } from '../../../fullMap.js';
import {config} from "../../../config.js";
import { util } from "../../../util/util.js";
import {httpUtil} from "../../../util/httpUtil.js";
import {khcToastr} from "../../../component/alert/khcToastr.js";
let functionMap=new Map();// 使用 Map 来存储多个函数。每个函数都通过 set 方法添加到 Map 中，键是函数名，值是对应的函数。
export function main(jsonConfig) {
    try {
        functionMap.get(jsonConfig.button_method).apply(jsonConfig);
    } catch (error) {
        khcAlert.showSystemError(error.message);
        console.log(error);
    }
}
function showModelView(){
    let jsonConfig=this;
    let queryViewComponent = fullMap.getObj(jsonConfig.objID);
    let table=queryViewComponent.getTableObj();
    let params =queryViewComponent.getCode();
    params.methodName='showModelView';
    params['bpmData']=table.getContentMap().get(jsonConfig.pkCode);
    let obj={url:config.getConfigJson().myActionUrl,params:params}
    return httpUtil.post(obj, (response)=>{
        let systemUrl=config.getSystemUrl();
        window.open(systemUrl+response.data.data.url);
    })
}
functionMap.set('showModelView', showModelView);// 将函数添加到 Map 中

function toFlowDesign(){
    let jsonConfig=this;
    let queryViewComponent = fullMap.getObj(jsonConfig.objID);
    let table=queryViewComponent.getTableObj();
    let params =queryViewComponent.getCode();
    let content = table.getContentMap().get(jsonConfig.pkCode.toString());
    if(util.isNull(content['bpm_form_code'])){
        khcToastr.showErrorMessage('请先绑定form组件')
        return ;
    }
    params.methodName='showModelView';
    params['bpmData']=content;
    let obj={url:config.getConfigJson().myActionUrl,params:params}
    return httpUtil.post(obj, (response)=>{
        window.open(window.location.origin+config.getConfigJson().contextFrontPath+'/flowdesign/index.html?modelId='+response.data.data.modelId);
    })
}
functionMap.set('toFlowDesign', toFlowDesign);// 将函数添加到 Map 中

function deploy(){
    let jsonConfig=this;
    let queryViewComponent = fullMap.getObj(jsonConfig.objID);
    let table=queryViewComponent.getTableObj();
    let params =queryViewComponent.getCode();
    params.methodName='deploy';
    params['bpmData']=table.getContentMap().get(jsonConfig.pkCode);
    let obj={url:config.getConfigJson().myActionUrl,params:params}
    return httpUtil.post(obj, (response)=>{
        table.refresh();
        khcAlert.showSuccessMessage(response.data.data.message)
    })
}
functionMap.set('deploy', deploy);// 将函数添加到 Map 中