2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
import{e as L,f as I,g as N,c as r,a as e,t as o,i as t,F as T,d as $,r as S,j as _,x as B,y as k,z,I as q,l as d,h as P,J,o as c,k as V}from"./BMplCfh_.js";import{_ as O}from"./DlAUqK2U.js";const G={class:"mb-8"},K={class:"text-2xl font-bold text-white"},Q={class:"text-slate-400 mt-1"},W={key:0,class:"flex items-center justify-center py-20"},X={class:"text-slate-400 flex items-center gap-3"},Y={key:1,class:"bg-rose-500/10 border border-rose-500/30 rounded-xl p-6 mb-8"},Z={class:"text-rose-400"},ee={class:"mb-6 flex justify-end"},te={class:"bg-slate-800 rounded-xl border border-slate-700 overflow-hidden"},se={class:"w-full"},oe={class:"border-b border-slate-700"},ie={class:"text-left px-6 py-4 text-xs font-medium text-slate-400 uppercase tracking-wider"},ne={class:"text-left px-6 py-4 text-xs font-medium text-slate-400 uppercase tracking-wider"},ae={class:"text-left px-6 py-4 text-xs font-medium text-slate-400 uppercase tracking-wider"},le={class:"text-left px-6 py-4 text-xs font-medium text-slate-400 uppercase tracking-wider"},re={class:"text-left px-6 py-4 text-xs font-medium text-slate-400 uppercase tracking-wider"},ce={class:"text-right px-6 py-4 text-xs font-medium text-slate-400 uppercase tracking-wider"},de={class:"divide-y divide-slate-700/50"},ue={class:"px-6 py-4 text-sm text-slate-400"},pe={class:"px-6 py-4"},me={class:"text-sm font-mono text-amber-300 bg-amber-500/10 px-2 py-0.5 rounded"},_e={class:"px-6 py-4"},fe={class:"px-6 py-4 text-sm text-slate-300 max-w-xs truncate"},xe={class:"px-6 py-4"},he={class:"px-6 py-4 text-right"},ve={class:"flex items-center justify-end gap-2"},ge=["onClick","title"],be=["onClick","title"],ke={key:0},ye={colspan:"6",class:"px-6 py-12 text-center text-sm text-slate-500"},we={class:"bg-slate-800 rounded-xl border border-slate-700 p-6 w-full max-w-lg mx-4 shadow-2xl"},Ce={class:"text-lg font-semibold text-white mb-6"},je={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"},Be={class:"block text-sm font-medium text-slate-300 mb-1"},ze=["placeholder"],He={class:"flex items-center gap-3"},Te={for:"is_active",class:"text-sm text-slate-300"},Ve={key:0,class:"bg-rose-500/10 border border-rose-500/30 rounded-lg p-3"},Ee={class:"text-sm text-rose-400"},Fe={class:"flex justify-end gap-3 pt-2"},Re=["disabled"],De={key:0,class:"w-4 h-4 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Ue={class:"bg-slate-800 rounded-xl border border-slate-700 p-6 w-full max-w-md mx-4 shadow-2xl"},Ae={class:"text-lg font-semibold text-white mb-2"},Le={class:"text-sm text-slate-400 mb-6"},Ie={class:"flex justify-end gap-3"},Ne=["disabled"],Se={key:5,class:"fixed bottom-6 right-6 z-50 bg-emerald-600 text-white px-4 py-3 rounded-lg shadow-lg text-sm flex items-center gap-2 animate-slide-up"},qe=L({__name:"point-rules",setup(Pe){const{t:s}=I(),y=d(!0),w=d(!1),C=d([]),h=d(!1),f=d(!1),m=d(null),x=d(null),u=d(!1),p=d(""),v=d(""),l=J({action_key:"",points:0,description:"",is_active:!0});function g(){const i=P("access_token").value;return i?{Authorization:`Bearer ${i}`,"Content-Type":"application/json"}:{"Content-Type":"application/json"}}function j(n){v.value=n,setTimeout(()=>{v.value=""},3e3)}function H(){l.action_key="",l.points=0,l.description="",l.is_active=!0,p.value=""}function E(){m.value=null,H(),h.value=!0}function F(n){m.value=n,l.action_key=n.action_key,l.points=n.points,l.description=n.description||"",l.is_active=n.is_active,p.value="",h.value=!0}function M(){h.value=!1,m.value=null,H()}function R(n){x.value=n,f.value=!0}async function b(){y.value=!0,w.value=!1;try{const n=await $fetch("/api/v1/admin/gamification/point-rules",{headers:g()});C.value=n}catch(n){console.error("Failed to fetch point rules:",n),w.value=!0}finally{y.value=!1}}async function D(){u.value=!0,p.value="";try{const n={action_key:l.action_key,points:l.points,description:l.description||null,is_active:l.is_active};m.value?(await $fetch(`/api/v1/admin/gamification/point-rules/${m.value.id}`,{method:"PUT",headers:g(),body:n}),j(s("gamification.point_rules.updated"))):(await $fetch("/api/v1/admin/gamification/point-rules",{method:"POST",headers:g(),body:n}),j(s("gamification.point_rules.created"))),M(),await b()}catch(n){n?.response?.status===409?p.value=s("gamification.point_rules.duplicate_error"):p.value=s("gamification.point_rules.save_error"),console.error("Failed to save point rule:",n)}finally{u.value=!1}}async function U(){if(x.value){u.value=!0;try{await $fetch(`/api/v1/admin/gamification/point-rules/${x.value.id}`,{method:"DELETE",headers:g()}),j(s("gamification.point_rules.deleted")),f.value=!1,x.value=null,await b()}catch(n){console.error("Failed to delete point rule:",n)}finally{u.value=!1}}}return N(()=>{b()}),(n,i)=>(c(),r("div",null,[e("div",G,[e("h1",K,o(t(s)("gamification.point_rules.title")),1),e("p",Q,o(t(s)("gamification.point_rules.subtitle")),1)]),t(y)?(c(),r("div",W,[e("div",X,[i[6]||(i[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,o(t(s)("gamification.point_rules.loading")),1)])])):t(w)?(c(),r("div",Y,[e("p",Z,o(t(s)("gamification.point_rules.load_error")),1),e("button",{onClick:b,class:"mt-3 text-sm text-rose-300 hover:text-rose-200 underline"},o(t(s)("gamification.point_rules.retry")),1)])):(c(),r(T,{key:2},[e("div",ee,[e("button",{onClick:E,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"},[i[7]||(i[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)),$(" "+o(t(s)("gamification.point_rules.create_btn")),1)])]),e("div",te,[e("table",se,[e("thead",null,[e("tr",oe,[e("th",ie,o(t(s)("gamification.point_rules.col_id")),1),e("th",ne,o(t(s)("gamification.point_rules.col_action_key")),1),e("th",ae,o(t(s)("gamification.point_rules.col_points")),1),e("th",le,o(t(s)("gamification.point_rules.col_description")),1),e("th",re,o(t(s)("gamification.point_rules.col_status")),1),e("th",ce,o(t(s)("gamification.point_rules.col_actions")),1)])]),e("tbody",de,[(c(!0),r(T,null,S(t(C),a=>(c(),r("tr",{key:a.id,class:"hover:bg-slate-700/30 transition"},[e("td",ue,o(a.id),1),e("td",pe,[e("code",me,o(a.action_key),1)]),e("td",_e,[e("span",{class:V(["text-sm font-semibold",a.points>=0?"text-emerald-400":"text-rose-400"])},o(a.points>=0?"+":"")+o(a.points),3)]),e("td",fe,o(a.description||"—"),1),e("td",xe,[e("span",{class:V(["inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",a.is_active?"bg-emerald-500/10 text-emerald-400":"bg-slate-500/10 text-slate-400"])},o(a.is_active?t(s)("gamification.point_rules.active"):t(s)("gamification.point_rules.inactive")),3)]),e("td",he,[e("div",ve,[e("button",{onClick:A=>F(a),class:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-slate-700 transition",title:t(s)("gamification.point_rules.edit")},[...i[8]||(i[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,ge),e("button",{onClick:A=>R(a),class:"p-1.5 rounded-lg text-slate-400 hover:text-rose-400 hover:bg-rose-500/10 transition",title:t(s)("gamification.point_rules.delete_title")},[...i[9]||(i[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,be)])])]))),128)),t(C).length===0?(c(),r("tr",ke,[e("td",ye,o(t(s)("gamification.point_rules.empty")),1)])):_("",!0)])])])],64)),t(h)?(c(),r("div",{key:3,class:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:B(M,["self"])},[e("div",we,[e("h2",Ce,o(t(m)?t(s)("gamification.point_rules.edit_title"):t(s)("gamification.point_rules.create_title")),1),e("form",{onSubmit:B(D,["prevent"]),class:"space-y-4"},[e("div",null,[e("label",je,o(t(s)("gamification.point_rules.action_key_label")),1),k(e("input",{"onUpdate:modelValue":i[0]||(i[0]=a=>t(l).action_key=a),type:"text",required:"",maxlength:"100",placeholder:t(s)("gamification.point_rules.action_key_placeholder"),class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-amber-500/50 focus:border-amber-500 text-sm"},null,8,Me),[[z,t(l).action_key]])]),e("div",null,[e("label",$e,o(t(s)("gamification.point_rules.points_label")),1),k(e("input",{"onUpdate:modelValue":i[1]||(i[1]=a=>t(l).points=a),type:"number",required:"",min:"-10000",max:"10000",placeholder:"0",class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-amber-500/50 focus:border-amber-500 text-sm"},null,512),[[z,t(l).points,void 0,{number:!0}]])]),e("div",null,[e("label",Be,o(t(s)("gamification.point_rules.description_label")),1),k(e("textarea",{"onUpdate:modelValue":i[2]||(i[2]=a=>t(l).description=a),rows:"3",placeholder:t(s)("gamification.point_rules.description_placeholder"),class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-amber-500/50 focus:border-amber-500 text-sm resize-none"},null,8,ze),[[z,t(l).description]])]),e("div",He,[k(e("input",{"onUpdate:modelValue":i[3]||(i[3]=a=>t(l).is_active=a),type:"checkbox",id:"is_active",class:"w-4 h-4 rounded bg-slate-700 border-slate-600 text-amber-500 focus:ring-amber-500/50"},null,512),[[q,t(l).is_active]]),e("label",Te,o(t(s)("gamification.point_rules.active_label")),1)]),t(p)?(c(),r("div",Ve,[e("p",Ee,o(t(p)),1)])):_("",!0),e("div",Fe,[e("button",{type:"button",onClick:M,class:"px-4 py-2 text-sm text-slate-400 hover:text-white transition"},o(t(s)("gamification.point_rules.cancel")),1),e("button",{type:"submit",disabled:t(u),class:"px-4 py-2 bg-amber-600 hover:bg-amber-500 disabled:bg-amber-600/50 text-white rounded-lg text-sm font-medium transition flex items-center gap-2"},[t(u)?(c(),r("svg",De,[...i[10]||(i[10]=[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)])])):_("",!0),$(" "+o(t(u)?t(s)("gamification.point_rules.saving"):t(s)("gamification.point_rules.save")),1)],8,Re)])],32)])])):_("",!0),t(f)?(c(),r("div",{key:4,class:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:i[5]||(i[5]=B(a=>f.value=!1,["self"]))},[e("div",Ue,[e("h2",Ae,o(t(s)("gamification.point_rules.delete_confirm_title")),1),e("p",Le,o(t(s)("gamification.point_rules.delete_confirm_body",{action_key:t(x)?.action_key})),1),e("div",Ie,[e("button",{onClick:i[4]||(i[4]=a=>f.value=!1),class:"px-4 py-2 text-sm text-slate-400 hover:text-white transition"},o(t(s)("gamification.point_rules.cancel")),1),e("button",{onClick:U,disabled:t(u),class:"px-4 py-2 bg-rose-600 hover:bg-rose-500 disabled:bg-rose-600/50 text-white rounded-lg text-sm font-medium transition"},o(t(u)?t(s)("gamification.point_rules.deleting"):t(s)("gamification.point_rules.delete")),9,Ne)])])])):_("",!0),t(v)?(c(),r("div",Se,[i[11]||(i[11]=e("svg",{class:"w-4 h-4 flex-shrink-0",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)),$(" "+o(t(v)),1)])):_("",!0)]))}}),Ge=O(qe,[["__scopeId","data-v-c5f07ccf"]]);export{Ge as default};
|