"use strict";
import { fullMap } from '../../../fullMap.js';
import { khcAlert } from '../../../component/alert/khcAlert.js'
import { form } from '../../../component/page/form/form.js';
import { util } from '../../../util/util.js'
import { khcModal } from '../../../component/alert/khcModal.js'
import {config} from "../../../config.js";
import {pageInfoMap} from "../../../pageInfoMap.js";
import {httpUtil} from "../../../util/httpUtil.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 forceExit(){
    let jsonConfig=this;
    let queryViewComponent = fullMap.getObj(jsonConfig.objID);
    let tableViewComponent = queryViewComponent.getTableObj();
    let content = tableViewComponent.getContentMap().get(jsonConfig.pkCode.toString());
    let alertData = {};
    alertData.title = '请确认是否强退"'+content.user_login_name+'"';
    alertData.text = '强退后该用户后令牌则立即失效，重新登录即可刷新令牌';
    khcAlert.showConfirm(alertData, ()=>{
        let params =queryViewComponent.getCode();
        params.userId=content.create_user_id;
        params.token=content.token;
        params.methodName='forceExit';
        let obj={url:config.getConfigJson().myActionUrl,params:params}
        return httpUtil.post(obj, (response)=>{
            Swal.fire(
                '操作成功',
                response.data.data.message,
                'success'
            )
            queryViewComponent.getTableObj().refresh();
        })
    });
}
functionMap.set('forceExit', forceExit);// 将函数添加到 Map 中

function sendMessageByUser(){
    let jsonConfig=this;
    let queryViewComponent = fullMap.getObj(jsonConfig.objID);
    let pageComponent=fullMap.getObj(queryViewComponent.pageID);
    jsonConfig.button_method='editOneByModal';
    jsonConfig.paramsAfterFunc=function (params){
        params.formCode='form_online_user_send_message';
        return util.clone(params);
    }
    jsonConfig.getKhcModalForFormAfterFunc=function (pageComponent){
        return pageComponent.editMessageByModalForm
    }
    jsonConfig.setKhcModalForFormAfterFunc=function (pageComponent,khcModalForForm){
        pageComponent.editMessageByModalForm=khcModalForForm;
    }
    jsonConfig.setSaveBefore=()=>{
        let params =queryViewComponent.getCode();
        let formValue=pageComponent.editMessageByModalForm.formComponent.getFormValue();
        params.userId=formValue.create_user_id;
        if(util.isNull(formValue.message)){
            params.message='这是一条测试WebSocket通知';
        }else{
            params.message=formValue.message;
        }
        params.methodName='sendMessageByUser';
        let obj={url:config.getConfigJson().myActionUrl,params:params}
        httpUtil.post(obj, (response)=>{
            pageComponent.editMessageByModalForm.hide();
            khcAlert.showSuccessMessage('操作成功')
        })
        return false;
    }
    util.import2023(config.getConfigJson().tableActionPath,jsonConfig);
}
functionMap.set('sendMessageByUser', sendMessageByUser);// 将函数添加到 Map 中
