"use strict";
import { util } from '../../../util/util.js'
import { fullMap } from '../../../fullMap.js';
import { khcAlert } from '../../../component/alert/khcAlert.js'
import {config} from "../../../config.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 resetKhcadminPassword(){
    let jsonConfig=this;
    let nsTemplate=`<div class="authentication-wrapper authentication-2 px-4">
    <div class="authentication-inner py-5">
        <!-- Form -->
        <form class="card">
            <div class="p-4 p-sm-5">
                <!-- Logo -->
                <div class="d-flex justify-content-center align-items-center pb-2 mb-1">
                    <img style="width: 100%;padding: 5px;width: 100px;filter: sepia(100%) hue-rotate(0deg) saturate(5000%);" src="${config.getConfigJson().logoPath}">
                </div>
                <!-- / Logo -->
                <h5 class="text-center text-muted font-weight-normal mb-4" _msttexthash="13531791" _msthash="1">重置 khcadmin 密码</h5>
                <hr class="mt-0 mb-4">
                <p _msttexthash="226181410" _msthash="2">输入khcKey，我们将重置后的密码在系统后台输出。</p>
                <div class="form-group">
                    <input type="text" class="form-control" placeholder="输入khcKey" _mstplaceholder="496301" _msthash="3" value="" id="khcKey">
                </div>
                <button type="button" class="btn btn-primary btn-block" _msttexthash="43707781" _msthash="4" id="submitButton">重置密码</button>
            </div>
        </form>
        <!-- / Form -->
    </div>
</div>`
    document.getElementById(objParentObjID).innerHTML=nsTemplate
    document.getElementById('submitButton').addEventListener('click',function (){
        let khcKey=document.getElementById('khcKey').value;
        if(util.isNull(khcKey)){
            khcAlert.showWarningMessage('请输入khcKey');
            return ;
        }
        let code=util.getUrlParam('code');
        let params={}
        params.nosessionCode=code
        let methodName='resetKhcadminPassword';
        params.methodNameShow=methodName;
        params.khcKey=khcKey;
        params.methodName=util.textEncrypt(methodName,new Date().getTime(),util.getLocalStorageItem('ip'));
        let obj={url:config.getConfigJson().nosessionActionUrl,params:params,config:'no token'}
        httpUtil.post(obj,(response)=>{
            let resData=response.data.data
            khcAlert.showSuccessMessage(resData['message'],3000);
            document.getElementById('khcKey').value='';
        });
    })


}
functionMap.set('resetKhcadminPassword', resetKhcadminPassword);// 将函数添加到 Map 中