2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
import{e as P,f as S,g as U,c as r,a as e,t as i,i as t,F as z,d as p,r as F,j as g,x as M,y as $,z as H,k as N,l as c,h as q,J as I,o as d}from"./Duy9QquX.js";const J={class:"mb-8"},O={class:"text-2xl font-bold text-white"},G={class:"text-slate-400 mt-1"},K={key:0,class:"flex items-center justify-center py-20"},Q={class:"text-slate-400 flex items-center gap-3"},R={key:1,class:"bg-rose-500/10 border border-rose-500/30 rounded-xl p-6 mb-8"},W={class:"text-rose-400"},X={class:"mb-6 flex justify-end"},Y={class:"bg-slate-800 rounded-xl border border-slate-700 overflow-hidden"},Z={class:"w-full"},ee={class:"border-b border-slate-700"},te={class:"text-left px-6 py-4 text-xs font-medium text-slate-400 uppercase tracking-wider"},se={class:"text-left px-6 py-4 text-xs font-medium text-slate-400 uppercase tracking-wider"},oe={class:"text-left px-6 py-4 text-xs font-medium text-slate-400 uppercase tracking-wider"},ie={class:"text-left px-6 py-4 text-xs font-medium text-slate-400 uppercase tracking-wider"},ae={class:"text-right px-6 py-4 text-xs font-medium text-slate-400 uppercase tracking-wider"},ne={class:"divide-y divide-slate-700/50"},le={class:"px-6 py-4 text-sm text-slate-400"},re={class:"px-6 py-4"},de={class:"text-sm font-semibold text-white"},ce={class:"px-6 py-4 text-sm text-slate-300 max-w-xs truncate"},ue={class:"px-6 py-4"},me={key:0,class:"flex items-center gap-2"},ge=["src"],fe={class:"text-xs text-slate-400 truncate max-w-[120px]"},pe={key:1,class:"text-sm text-slate-500"},xe={class:"px-6 py-4 text-right"},he={class:"flex items-center justify-end gap-2"},be=["onClick","title"],_e=["onClick","title"],ve={key:0},we={colspan:"5",class:"px-6 py-12 text-center text-sm text-slate-500"},ke={class:"bg-slate-800 rounded-xl border border-slate-700 p-6 w-full max-w-lg mx-4 shadow-2xl"},ye={class:"text-lg font-semibold text-white mb-6"},Ce={class:"block text-sm font-medium text-slate-300 mb-1"},je=["placeholder"],Be={class:"block text-sm font-medium text-slate-300 mb-1"},Me=["placeholder"],$e={class:"block text-sm font-medium text-slate-300 mb-1"},He=["placeholder"],ze={class:"text-xs text-slate-500 mt-1"},Te={key:0,class:"flex items-center gap-3 p-3 bg-slate-700/50 rounded-lg"},Ee=["src"],Ve={class:"text-xs text-slate-400"},Ae={class:"flex items-center justify-end gap-3 pt-2"},De=["disabled"],Le={key:0,class:"w-4 h-4 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Pe={class:"bg-slate-800 rounded-xl border border-slate-700 p-6 w-full max-w-md mx-4 shadow-2xl"},Se={class:"flex items-center gap-3 mb-4"},Ue={class:"text-lg font-semibold text-white"},Fe={class:"text-sm text-slate-400 mt-1"},Ne={class:"bg-slate-700/50 rounded-lg p-4 mb-6"},qe={class:"text-sm font-medium text-white"},Ie={class:"text-xs text-slate-400 mt-1"},Je={class:"flex items-center justify-end gap-3"},Oe=["disabled"],Ge={key:0,class:"w-4 h-4 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Re=P({__name:"badges",setup(Ke){const{t:o}=S(),k=c(!0),y=c(!1),u=c(!1),C=c([]),_=c(!1),x=c(!1),m=c(null),f=c(null),j=c(!1),h=c(null),n=I({name:"",description:"",icon_url:""});function v(){const s=q("access_token").value;return s?{Authorization:`Bearer ${s}`}:{}}function b(a,s){h.value={message:a,type:s},setTimeout(()=>{h.value=null},4e3)}async function w(){k.value=!0,y.value=!1;try{const a=await $fetch("/api/v1/admin/gamification/badges",{headers:{...v()}});C.value=a}catch(a){console.error("[Badges] Failed to fetch:",a),y.value=!0}finally{k.value=!1}}function T(){m.value=null,n.name="",n.description="",n.icon_url="",j.value=!1,_.value=!0}function E(a){m.value=a,n.name=a.name,n.description=a.description,n.icon_url=a.icon_url||"",j.value=!1,_.value=!0}function B(){_.value=!1,m.value=null}async function V(){u.value=!0;try{m.value?(await $fetch(`/api/v1/admin/gamification/badges/${m.value.id}`,{method:"PUT",headers:{...v(),"Content-Type":"application/json"},body:{name:n.name,description:n.description,icon_url:n.icon_url||null}}),b(o("gamification.badges.updated"),"success")):(await $fetch("/api/v1/admin/gamification/badges",{method:"POST",headers:{...v(),"Content-Type":"application/json"},body:{name:n.name,description:n.description,icon_url:n.icon_url||null}}),b(o("gamification.badges.created"),"success")),B(),await w()}catch(a){console.error("[Badges] Save failed:",a);const s=a?.data?.detail||a?.message||o("gamification.badges.unknown_error");b(`${o("gamification.badges.save_error")}: ${s}`,"error")}finally{u.value=!1}}function A(a){f.value=a,x.value=!0}async function D(){if(f.value){u.value=!0;try{await $fetch(`/api/v1/admin/gamification/badges/${f.value.id}`,{method:"DELETE",headers:{...v()}}),b(o("gamification.badges.deleted"),"success"),x.value=!1,f.value=null,await w()}catch(a){console.error("[Badges] Delete failed:",a);const s=a?.data?.detail||a?.message||o("gamification.badges.unknown_error");b(`${o("gamification.badges.delete_error")}: ${s}`,"error")}finally{u.value=!1}}}return U(()=>{w()}),(a,s)=>(d(),r("div",null,[e("div",J,[e("h1",O,i(t(o)("gamification.badges.title")),1),e("p",G,i(t(o)("gamification.badges.subtitle")),1)]),t(k)?(d(),r("div",K,[e("div",Q,[s[6]||(s[6]=e("svg",{class:"w-5 h-5 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"})],-1)),e("span",null,i(t(o)("gamification.badges.loading")),1)])])):t(y)?(d(),r("div",R,[e("p",W,i(t(o)("gamification.badges.error")),1),e("button",{onClick:w,class:"mt-3 text-sm text-rose-300 hover:text-rose-200 underline"},i(t(o)("gamification.badges.retry")),1)])):(d(),r(z,{key:2},[e("div",X,[e("button",{onClick:T,class:"px-4 py-2 bg-emerald-600 hover:bg-emerald-500 text-white rounded-lg text-sm font-medium transition flex items-center gap-2"},[s[7]||(s[7]=e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4v16m8-8H4"})],-1)),p(" "+i(t(o)("gamification.badges.create")),1)])]),e("div",Y,[e("table",Z,[e("thead",null,[e("tr",ee,[e("th",te,i(t(o)("gamification.badges.id")),1),e("th",se,i(t(o)("gamification.badges.name")),1),e("th",oe,i(t(o)("gamification.badges.description")),1),e("th",ie,i(t(o)("gamification.badges.icon")),1),e("th",ae,i(t(o)("gamification.badges.actions")),1)])]),e("tbody",ne,[(d(!0),r(z,null,F(t(C),l=>(d(),r("tr",{key:l.id,class:"hover:bg-slate-700/30 transition"},[e("td",le,i(l.id),1),e("td",re,[e("span",de,i(l.name),1)]),e("td",ce,i(l.description||"—"),1),e("td",ue,[l.icon_url?(d(),r("div",me,[e("img",{src:l.icon_url,alt:"",class:"w-8 h-8 rounded-full object-cover bg-slate-700"},null,8,ge),e("span",fe,i(l.icon_url),1)])):(d(),r("span",pe,"—"))]),e("td",xe,[e("div",he,[e("button",{onClick:L=>E(l),class:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-slate-700 transition",title:t(o)("gamification.badges.edit")},[...s[8]||(s[8]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})],-1)])],8,be),e("button",{onClick:L=>A(l),class:"p-1.5 rounded-lg text-slate-400 hover:text-rose-400 hover:bg-rose-500/10 transition",title:t(o)("gamification.badges.delete")},[...s[9]||(s[9]=[e("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"})],-1)])],8,_e)])])]))),128)),t(C).length===0?(d(),r("tr",ve,[e("td",we,i(t(o)("gamification.badges.no_items")),1)])):g("",!0)])])])],64)),t(_)?(d(),r("div",{key:3,class:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:M(B,["self"])},[e("div",ke,[e("h2",ye,i(t(m)?t(o)("gamification.badges.edit_title"):t(o)("gamification.badges.create_title")),1),e("form",{onSubmit:M(V,["prevent"]),class:"space-y-4"},[e("div",null,[e("label",Ce,[p(i(t(o)("gamification.badges.name"))+" ",1),s[10]||(s[10]=e("span",{class:"text-rose-400"},"*",-1))]),$(e("input",{"onUpdate:modelValue":s[0]||(s[0]=l=>t(n).name=l),type:"text",required:"",maxlength:"100",class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-sm text-white placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent",placeholder:t(o)("gamification.badges.name_placeholder")},null,8,je),[[H,t(n).name]])]),e("div",null,[e("label",Be,[p(i(t(o)("gamification.badges.description"))+" ",1),s[11]||(s[11]=e("span",{class:"text-rose-400"},"*",-1))]),$(e("textarea",{"onUpdate:modelValue":s[1]||(s[1]=l=>t(n).description=l),required:"",maxlength:"500",rows:"3",class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-sm text-white placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent resize-none",placeholder:t(o)("gamification.badges.desc_placeholder")},null,8,Me),[[H,t(n).description]])]),e("div",null,[e("label",$e,i(t(o)("gamification.badges.icon")),1),$(e("input",{"onUpdate:modelValue":s[2]||(s[2]=l=>t(n).icon_url=l),type:"url",class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-sm text-white placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent",placeholder:t(o)("gamification.badges.icon_placeholder")},null,8,He),[[H,t(n).icon_url]]),e("p",ze,i(t(o)("gamification.badges.icon_hint")),1)]),t(n).icon_url?(d(),r("div",Te,[e("img",{src:t(n).icon_url,alt:"Preview",class:"w-10 h-10 rounded-full object-cover bg-slate-600",onError:s[3]||(s[3]=l=>j.value=!0)},null,40,Ee),e("div",Ve,[s[12]||(s[12]=e("span",{class:"text-emerald-400"},"✔",-1)),p(" "+i(t(o)("gamification.badges.icon_preview")),1)])])):g("",!0),e("div",Ae,[e("button",{type:"button",onClick:B,class:"px-4 py-2 text-sm font-medium text-slate-300 hover:text-white transition"},i(t(o)("gamification.badges.cancel")),1),e("button",{type:"submit",disabled:t(u),class:"px-4 py-2 bg-indigo-600 hover:bg-indigo-500 disabled:bg-indigo-600/50 disabled:cursor-not-allowed text-white rounded-lg text-sm font-medium transition flex items-center gap-2"},[t(u)?(d(),r("svg",Le,[...s[13]||(s[13]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"},null,-1)])])):g("",!0),p(" "+i(t(m)?t(o)("gamification.badges.save"):t(o)("gamification.badges.create_btn")),1)],8,De)])],32)])])):g("",!0),t(x)?(d(),r("div",{key:4,class:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:s[5]||(s[5]=M(l=>x.value=!1,["self"]))},[e("div",Pe,[e("div",Se,[s[14]||(s[14]=e("div",{class:"p-2 rounded-full bg-rose-500/10 text-rose-400"},[e("svg",{class:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-2.5L13.732 4c-.77-.833-1.964-.833-2.732 0L4.082 16.5c-.77.833.192 2.5 1.732 2.5z"})])],-1)),e("div",null,[e("h2",Ue,i(t(o)("gamification.badges.delete_title")),1),e("p",Fe,i(t(o)("gamification.badges.delete_confirm")),1)])]),e("div",Ne,[e("p",qe,i(t(f)?.name),1),e("p",Ie,i(t(f)?.description),1)]),e("div",Je,[e("button",{onClick:s[4]||(s[4]=l=>x.value=!1),class:"px-4 py-2 text-sm font-medium text-slate-300 hover:text-white transition"},i(t(o)("gamification.badges.cancel")),1),e("button",{onClick:D,disabled:t(u),class:"px-4 py-2 bg-rose-600 hover:bg-rose-500 disabled:bg-rose-600/50 disabled:cursor-not-allowed text-white rounded-lg text-sm font-medium transition flex items-center gap-2"},[t(u)?(d(),r("svg",Ge,[...s[15]||(s[15]=[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"},null,-1)])])):g("",!0),p(" "+i(t(o)("gamification.badges.delete_btn")),1)],8,Oe)])])])):g("",!0),t(h)?(d(),r("div",{key:5,class:N(["fixed bottom-6 right-6 z-50 px-4 py-3 rounded-lg shadow-xl text-sm font-medium transition-all duration-300",t(h).type==="success"?"bg-emerald-600 text-white":"bg-rose-600 text-white"])},i(t(h).message),3)):g("",!0)]))}});export{Re as default};
|