(async function(){console.log("[Activation] 模块脚本启动 (NetworkClient 重构版)...");const container=document.getElementById("activation_container");if(!container){console.error("[Activation] 找不到 ID 为 activation_container 的容器");return}container.style.display="block";const config=window.pluginConfig||{};let userToken="";try{userToken=await(window.configAPI?.getUserToken?.()||Promise.resolve(""))}catch(e){console.warn("[Activation] 获取用户 Token 失败:",e)}function showActivateMsg(msg,isError=false){const msgEl=document.getElementById("activate_msg");if(msgEl){msgEl.innerText=msg;msgEl.style.color=isError?"#e74c3c":"#3273dc"}}async function activateUser(btnElement){const activateBtn=btnElement;const activateCodeInput=document.getElementById("activate_code");const activateCode=activateCodeInput?.value?.trim();if(!activateCode){showActivateMsg("请输入激活码！",true);return}activateBtn.disabled=true;activateBtn.value="激活中...";try{let endpoint=config.activate_endpoint||"/client/v1/auth/activate";const payload={token:userToken,acode:activateCode};endpoint=endpoint+"?acode="+activateCode;const response=await window.NetworkClient.postEndpoint(endpoint,payload,{showProgress:true,ignoreErrors:false,skipAuth:false});console.log("[Activation] 激活响应:",response);if(response?.success){const msg=typeof decodeUnicodeString==="function"?decodeUnicodeString(response?.message||""):response?.message||"";showActivateMsg(msg,!response?.success);setTimeout(()=>{if(typeof window.checkLoginStatus==="function"){window.checkLoginStatus()}},1e3)}else{const errorMsg=typeof decodeUnicodeString==="function"?decodeUnicodeString(response.message):response.message;showActivateMsg("激活失败："+errorMsg,true)}}catch(error){console.error("[Activation] 激活失败:",error);const errorMsg=typeof decodeUnicodeString==="function"?decodeUnicodeString(error.message):error.message;showActivateMsg("激活失败："+errorMsg,true)}finally{activateBtn.disabled=false;activateBtn.value="激活"}}async function getActivateCode(btnElement){const getCodeBtn=btnElement;const resultDiv=document.getElementById("get-activate-code-html");getCodeBtn.disabled=true;getCodeBtn.value="获取中...";try{const endpoint=config.activate_get_endpoint||"/client/v1/product/get-activate-code";const url=await window.NetworkClient.urlBuilderWithEndpoint(endpoint);const response=await window.NetworkClient.getHtml(url,{token:userToken},{showProgress:true,ignoreErrors:false});let htmlContent=response;try{const jsonResponse=typeof response==="string"?JSON.parse(response):response;if(jsonResponse.success){htmlContent=jsonResponse.data||""}else{htmlContent=`<span style="color:red;">失败：${jsonResponse.message||"未知错误"}</span>`}}catch(e){htmlContent=response}finally{if(typeof hideLoading==="function")hideLoading()}resultDiv.innerHTML=htmlContent;resultDiv.style.display="block"}catch(error){console.error("[Activation] 获取激活码失败:",error);const errorMsg=typeof decodeUnicodeString==="function"?decodeUnicodeString(error.message):error.message;resultDiv.innerHTML=`<span style="color:red;">网络异常，请稍后再试！${errorMsg}</span>`;resultDiv.style.display="block"}finally{getCodeBtn.disabled=false;getCodeBtn.value="获取激活码"}}function bindPageEvents(){const activateBtn=document.getElementById("btn_activate");if(activateBtn){activateBtn.onclick=()=>activateUser(activateBtn)}const getCodeBtn=document.getElementById("btn_get_code");if(getCodeBtn){getCodeBtn.onclick=()=>getActivateCode(getCodeBtn)}const codeInput=document.getElementById("activate_code");if(codeInput){codeInput.addEventListener("keydown",e=>{if(e.key==="Enter"&&activateBtn){activateUser(activateBtn)}})}}async function init(){console.log("[Activation] 开始初始化...");if(!window.NetworkClient){showActivateMsg("NetworkClient 未加载，请检查脚本引入顺序",true);return}bindPageEvents();showActivateMsg("");console.log("[Activation] 初始化完成 ✓")}await init()})();