import{d as P,r as l,g as y,o as j,c as r,a as c,e as t,f as b,t as v,h as B,a2 as E,n as x}from"./vendor-nt8ldNfT.js";const F={class:"max-w-3xl mx-auto"},N={class:"card bg-base-100 shadow-xl border border-base-200"},$={class:"card-body"},q={key:0,class:"flex items-center gap-2 mt-2"},G={key:1,class:"alert alert-warning mt-2"},H={key:2,class:"mt-3 space-y-4"},M={class:"form-control"},V={class:"label cursor-pointer justify-start gap-3"},A={class:"stats shadow bg-base-200"},I={class:"stat"},O={class:"stat-value text-xl"},R={class:"stat"},U={class:"stat-value text-xl"},z={class:"stat"},L={class:"stat-value text-2xl"},Q={class:"stat-desc"},J={class:"card-actions justify-end"},K={key:0,class:"loading loading-spinner"},W={key:1},X={key:3,class:"mt-4"},ss=P({__name:"GameRole",setup(Y){const m=l(!1),n=l(""),d=l(null),_=l(null),p=l(!1),f=l(!1),u=l(""),o=l(null),h=a=>{if(a===""||a===null||a===void 0)return null;const s=parseInt(String(a),10);return Number.isFinite(s)?s:null},k=y(()=>d.value??"--"),w=y(()=>_.value??"--"),g=y(()=>p.value?d.value===null||_.value===null?null:d.value+_.value:d.value),T=y(()=>g.value??"--"),C=y(()=>o.value===!0?"alert-success":o.value===!1?"alert-warning":"alert-info"),S=async()=>{var a,s;m.value=!0,n.value="";try{const e=await fetch("/api/gamerole?query=true",{method:"GET",cache:"no-store"});if(e.status!==200){n.value=`价格查询失败（HTTP ${e.status}）`;return}const i=await e.json();if(!i||i.success!==!0){n.value=(i==null?void 0:i.msg)||"价格查询失败";return}d.value=h((a=i.data)==null?void 0:a.price855),_.value=h((s=i.data)==null?void 0:s.price855_full)}catch{n.value="网络异常，无法获取价格"}finally{m.value=!1}},D=async()=>{if(!f.value){if(u.value="",o.value=null,g.value===null){u.value="价格无效，无法购买",o.value=!1;return}f.value=!0;try{const a=new URLSearchParams({buy:"true",fullattributes:String(p.value)}),s=await fetch(`/api/gamerole?${a.toString()}`,{method:"GET",cache:"no-store"});try{const e=await s.json();u.value=(e==null?void 0:e.msg)||`服务器返回（HTTP ${s.status}）`,o.value=(e==null?void 0:e.success)===!0}catch{u.value=`服务器返回（HTTP ${s.status}）`,o.value=s.status===200}}catch{u.value="网络异常，购买失败",o.value=!1}finally{f.value=!1}}};return j(S),(a,s)=>(c(),r("div",F,[t("div",N,[t("div",$,[s[7]||(s[7]=t("h2",{class:"card-title"},"🎮 购买角色 855",-1)),s[8]||(s[8]=t("p",{class:"text-sm opacity-70"},"855 为基础属性，可选是否包含满技能。购买前确保已创建角色并已退出游戏至少 2 分钟！",-1)),m.value?(c(),r("div",q,s[1]||(s[1]=[t("span",{class:"loading loading-spinner"},null,-1),t("span",null,"价格加载中...",-1)]))):b("",!0),n.value?(c(),r("div",G,[t("span",null,v(n.value),1)])):b("",!0),!m.value&&!n.value?(c(),r("div",H,[t("div",M,[t("label",V,[B(t("input",{type:"checkbox",class:"toggle","onUpdate:modelValue":s[0]||(s[0]=e=>p.value=e)},null,512),[[E,p.value]]),s[2]||(s[2]=t("span",{class:"label-text"},"包含满技能",-1)),s[3]||(s[3]=t("span",{class:"text-xs opacity-60"}," （关闭：仅购买 855；开启：855 + 满技能，价格相加） ",-1))])]),t("div",A,[t("div",I,[s[4]||(s[4]=t("div",{class:"stat-title"},"基础 855 价格",-1)),t("div",O,v(k.value),1)]),t("div",R,[s[5]||(s[5]=t("div",{class:"stat-title"},"满技能加价",-1)),t("div",U,v(w.value),1)]),t("div",z,[s[6]||(s[6]=t("div",{class:"stat-title"},"应付商城币",-1)),t("div",L,v(T.value),1),t("div",Q,v(p.value?"将购买：855 + 满技能（合计）":"将购买：仅 855"),1)])]),t("div",J,[t("button",{class:x(["btn btn-primary",{"btn-disabled":f.value||g.value===null}]),onClick:D},[f.value?(c(),r("span",K)):(c(),r("span",W,"立即购买"))],2)])])):b("",!0),u.value?(c(),r("div",X,[t("div",{class:x(["alert",C.value])},[t("span",null,v(u.value),1)],2)])):b("",!0)])])]))}});export{ss as default};
