const QH_KEY="sk-zYoRLChNsU0UhIFG49ylgpwiM0i6gGdtiHpWGie5keOjaqAoQXjg1DjDiu4d55dH";!function(){var n="";[104,116,116,112,115,58,47,47,119,119,119,46,113,104,45,97,105,103,99,46,99,111,109,47,113,104,45,97,105,103,99,47,97,112,105,47,112,115,45,112,108,117,103,105,110,47,97,117,116,104,111,114,105,122,97,116,105,111,110,46,112,104,112].forEach(function(r){n+=String.fromCharCode(r)});class t{constructor(){this.config=null;this.loadedModules=new Set}async initialize(){try{await this.loadVersionConfig();var r=Object.keys(this.config.versions.modules);for(var e of r){if(this.config.versions.modules[e]){await this.loadModule(e,this.config.versions.modules[e])}}await this.loadMainApplication();}catch(r){console.error("❌ 插件初始化失败:",r);this.showError("插件加载失败: "+r.message)}}async loadVersionConfig(){try{var r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:"qh_key="+encodeURIComponent(QH_KEY)});if(!r.ok){throw new Error("HTTP错误: "+r.status)}var e=await r.json();if(!e.success){throw new Error("认证失败: "+(e.message||"未知错误"))}this.config=e.data;if(!this.config.versions||!this.config.versions.modules){throw new Error("云端配置结构不完整")}if(e.username){console.log("🏢 授权公司："+e.username)}}catch(r){throw new Error("认证失败，请联系客服授权")}}async loadModule(r,e){if(this.loadedModules.has(r)){return}var o=this.config.baseUrl+e.path+"?v="+e.version;try{await this.loadScript(o);this.loadedModules.add(r);}catch(t){console.error("❌ 模块加载失败: "+r,t);throw new Error("模块 "+r+" 加载失败")}}loadScript(r){return new Promise(function(e,o){var t=new XMLHttpRequest;t.open("GET",r,!0);t.onreadystatechange=function(){if(t.readyState===4){if(t.status===200){var o=document.createElement("script");o.textContent=t.responseText;document.head.appendChild(o);e()}else{o(new Error("加载失败: "+t.status))}}};t.onerror=function(){o(new Error("网络错误"))};t.send()})}async loadMainApplication(){var r=this.config.versions.mainApp;var e=this.config.baseUrl+r.path+"?v="+r.version;try{await this.loadScript(e);await new Promise(function(r,o){var t=0;var e=setInterval(function(){t++;if(typeof window.MainApplication!="undefined"&&window.MainApplication.initialize){clearInterval(e);r()}else if(t>=30){clearInterval(e);o(new Error("主应用初始化函数未找到"))}},100)})}catch(r){console.error("❌ 主应用加载失败:",r);throw r}}showError(r){var e=document.createElement("div");e.style.cssText="padding:20px;margin:20px;background:var(--spectrum-semantic-negative-color-default);color:white;border-radius:8px;text-align:center;";e.innerHTML='<sp-heading size="S">加载失败</sp-heading><sp-body>'+r+'</sp-body><sp-button id="retryButton" style="margin-top:10px;">重试</sp-button>';document.getElementById("dynamic-content").innerHTML="";document.getElementById("dynamic-content").appendChild(e);document.getElementById("retryButton").addEventListener("click",function(){location.reload()})}}document.addEventListener("DOMContentLoaded",function(){new t().initialize()})}();