2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
import{e as F,f as L,g as q,c as r,a as e,t as n,i as t,d as H,F as z,r as E,x as N,y as b,z as j,I as O,j as v,l as u,h as P,J as I,o as d,k as J}from"./Duy9QquX.js";const G={class:"mb-8 flex items-center justify-between"},K={class:"text-2xl font-bold text-white"},Q={class:"text-slate-400 mt-1"},R={key:0,class:"flex items-center justify-center py-20"},W={class:"text-slate-400 flex items-center gap-3"},X={key:1,class:"bg-rose-500/10 border border-rose-500/30 rounded-xl p-6 mb-8"},Y={class:"text-rose-400"},Z={key:0,class:"bg-slate-800 rounded-xl border border-slate-700 p-12 text-center"},ee={class:"text-slate-400"},te={key:1,class:"space-y-4"},se={class:"flex items-start justify-between"},ae={class:"flex-1"},oe={class:"flex items-center gap-3 mb-2"},ie={class:"text-lg font-semibold text-white"},ne={class:"flex items-center gap-6 text-sm text-slate-400"},le={class:"flex items-center gap-2"},re={class:"flex items-center gap-2"},de={class:"flex items-center gap-2 ml-4"},ce=["title","onClick"],ue=["title","onClick"],me={key:3,class:"fixed inset-0 z-50 flex items-center justify-center p-4"},fe={class:"relative bg-slate-800 rounded-xl border border-slate-700 w-full max-w-lg p-6 shadow-2xl"},ve={class:"text-lg font-semibold text-white mb-6"},ge={class:"block text-sm font-medium text-slate-300 mb-1"},pe=["placeholder"],_e={class:"block text-sm font-medium text-slate-300 mb-1"},he={class:"block text-sm font-medium text-slate-300 mb-1"},xe={key:0,class:"flex items-center gap-3"},be={for:"is_active",class:"text-sm text-slate-300"},ke={key:1,class:"bg-rose-500/10 border border-rose-500/30 rounded-lg p-3"},we={class:"text-sm text-rose-400"},ye={class:"flex items-center justify-end gap-3 pt-2"},Ce=["disabled"],je={key:0,class:"w-4 h-4 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},Me={key:4,class:"fixed inset-0 z-50 flex items-center justify-center p-4"},Ve={class:"relative bg-slate-800 rounded-xl border border-slate-700 w-full max-w-md p-6 shadow-2xl"},Be={class:"text-lg font-semibold text-white mb-2"},He={class:"text-slate-400 text-sm mb-6"},ze={class:"flex items-center justify-end gap-3"},$e=["disabled"],Te=F({__name:"seasons",setup(Se){const{t:o}=L(),k=u(!0),w=u(!1),m=u(!1),_=u(!1),g=u(!1),y=u([]),c=u(null),p=u(null),f=u(""),i=I({name:"",start_date:"",end_date:"",is_active:!1});function h(){const s=P("access_token").value;return s?{Authorization:`Bearer ${s}`}:{}}function M(a){return a?new Date(a).toLocaleDateString("hu-HU",{year:"numeric",month:"long",day:"numeric"}):""}function $(a){return a?new Date(a).toLocaleDateString("hu-HU",{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"}):""}function V(){i.name="",i.start_date="",i.end_date="",i.is_active=!1,f.value=""}function B(){c.value=null,V(),_.value=!0}function S(a){c.value=a,i.name=a.name,i.start_date=a.start_date,i.end_date=a.end_date,i.is_active=a.is_active,f.value="",_.value=!0}function C(){_.value=!1,c.value=null,V()}function D(a){p.value=a,g.value=!0}async function x(){k.value=!0,w.value=!1;try{const a=await $fetch("/api/v1/admin/gamification/seasons",{headers:h()});y.value=a}catch(a){console.error("Failed to fetch seasons:",a),w.value=!0}finally{k.value=!1}}async function T(){m.value=!0,f.value="";try{if(c.value){const a={};i.name!==c.value.name&&(a.name=i.name),i.start_date!==c.value.start_date&&(a.start_date=i.start_date),i.end_date!==c.value.end_date&&(a.end_date=i.end_date),Object.keys(a).length>0&&await $fetch(`/api/v1/admin/gamification/seasons/${c.value.id}`,{method:"PUT",headers:{...h(),"Content-Type":"application/json"},body:a})}else await $fetch("/api/v1/admin/gamification/seasons",{method:"POST",headers:{...h(),"Content-Type":"application/json"},body:{name:i.name,start_date:i.start_date,end_date:i.end_date,is_active:i.is_active}});C(),await x()}catch(a){console.error("Failed to save season:",a),f.value=a?.data?.detail||a?.message||o("gamification.seasons.save_error")}finally{m.value=!1}}async function A(){if(p.value){m.value=!0;try{await $fetch(`/api/v1/admin/gamification/seasons/${p.value.id}/activate`,{method:"POST",headers:h()}),g.value=!1,p.value=null,await x()}catch(a){console.error("Failed to activate season:",a)}finally{m.value=!1}}}return q(()=>{x()}),(a,s)=>(d(),r("div",null,[e("div",G,[e("div",null,[e("h1",K,n(t(o)("gamification.seasons.title")),1),e("p",Q,n(t(o)("gamification.seasons.subtitle")),1)]),e("button",{class:"flex items-center gap-2 px-4 py-2 bg-indigo-600 hover:bg-indigo-500 text-white text-sm font-medium rounded-lg transition",onClick:B},[s[6]||(s[6]=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)),H(" "+n(t(o)("gamification.seasons.create_btn")),1)])]),t(k)?(d(),r("div",R,[e("div",W,[s[7]||(s[7]=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,n(t(o)("gamification.seasons.loading")),1)])])):t(w)?(d(),r("div",X,[e("p",Y,n(t(o)("gamification.seasons.load_error")),1),e("button",{class:"mt-2 text-sm text-rose-300 hover:text-rose-200 underline",onClick:x},n(t(o)("gamification.seasons.retry")),1)])):(d(),r(z,{key:2},[t(y).length===0?(d(),r("div",Z,[s[8]||(s[8]=e("svg",{class:"w-12 h-12 mx-auto text-slate-600 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})],-1)),e("p",ee,n(t(o)("gamification.seasons.empty")),1),e("button",{class:"mt-4 px-4 py-2 bg-indigo-600 hover:bg-indigo-500 text-white text-sm font-medium rounded-lg transition",onClick:B},n(t(o)("gamification.seasons.create_first")),1)])):(d(),r("div",te,[(d(!0),r(z,null,E(t(y),l=>(d(),r("div",{key:l.id,class:"bg-slate-800 rounded-xl border border-slate-700 p-6 hover:border-slate-600 transition"},[e("div",se,[e("div",ae,[e("div",oe,[e("h3",ie,n(l.name),1),e("span",{class:J(["px-2.5 py-0.5 rounded-full text-xs font-medium",l.is_active?"bg-emerald-500/10 text-emerald-400 border border-emerald-500/30":"bg-slate-700 text-slate-400 border border-slate-600"])},n(l.is_active?t(o)("gamification.seasons.active"):t(o)("gamification.seasons.inactive")),3)]),e("div",ne,[e("div",le,[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:"M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"})],-1)),e("span",null,n(M(l.start_date))+" → "+n(M(l.end_date)),1)]),e("div",re,[s[10]||(s[10]=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 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)),e("span",null,n(t(o)("gamification.seasons.created_at"))+" "+n($(l.created_at)),1)])])]),e("div",de,[l.is_active?v("",!0):(d(),r("button",{key:0,class:"p-2 rounded-lg text-emerald-400 hover:bg-emerald-500/10 transition",title:t(o)("gamification.seasons.activate"),onClick:U=>D(l)},[...s[11]||(s[11]=[e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"}),e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)])],8,ce)),e("button",{class:"p-2 rounded-lg text-indigo-400 hover:bg-indigo-500/10 transition",title:t(o)("gamification.seasons.edit"),onClick:U=>S(l)},[...s[12]||(s[12]=[e("svg",{class:"w-5 h-5",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,ue)])])]))),128))]))],64)),t(_)?(d(),r("div",me,[e("div",{class:"fixed inset-0 bg-black/60",onClick:C}),e("div",fe,[e("h2",ve,n(t(c)?t(o)("gamification.seasons.edit_title"):t(o)("gamification.seasons.create_title")),1),e("form",{onSubmit:N(T,["prevent"]),class:"space-y-4"},[e("div",null,[e("label",ge,n(t(o)("gamification.seasons.name_label")),1),b(e("input",{"onUpdate:modelValue":s[0]||(s[0]=l=>t(i).name=l),type:"text",required:"",class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white placeholder-slate-400 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent",placeholder:t(o)("gamification.seasons.name_placeholder")},null,8,pe),[[j,t(i).name]])]),e("div",null,[e("label",_e,n(t(o)("gamification.seasons.start_date_label")),1),b(e("input",{"onUpdate:modelValue":s[1]||(s[1]=l=>t(i).start_date=l),type:"date",required:"",class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent"},null,512),[[j,t(i).start_date]])]),e("div",null,[e("label",he,n(t(o)("gamification.seasons.end_date_label")),1),b(e("input",{"onUpdate:modelValue":s[2]||(s[2]=l=>t(i).end_date=l),type:"date",required:"",class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:border-transparent"},null,512),[[j,t(i).end_date]])]),t(c)?v("",!0):(d(),r("div",xe,[b(e("input",{"onUpdate:modelValue":s[3]||(s[3]=l=>t(i).is_active=l),type:"checkbox",id:"is_active",class:"w-4 h-4 rounded border-slate-600 bg-slate-700 text-indigo-600 focus:ring-indigo-500"},null,512),[[O,t(i).is_active]]),e("label",be,n(t(o)("gamification.seasons.active_on_create")),1)])),t(f)?(d(),r("div",ke,[e("p",we,n(t(f)),1)])):v("",!0),e("div",ye,[e("button",{type:"button",class:"px-4 py-2 text-sm text-slate-400 hover:text-white transition",onClick:C},n(t(o)("gamification.seasons.cancel")),1),e("button",{type:"submit",disabled:t(m),class:"px-4 py-2 bg-indigo-600 hover:bg-indigo-500 disabled:bg-indigo-600/50 text-white text-sm font-medium rounded-lg transition flex items-center gap-2"},[t(m)?(d(),r("svg",je,[...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)])])):v("",!0),H(" "+n(t(c)?t(o)("gamification.seasons.save"):t(o)("gamification.seasons.create")),1)],8,Ce)])],32)])])):v("",!0),t(g)?(d(),r("div",Me,[e("div",{class:"fixed inset-0 bg-black/60",onClick:s[4]||(s[4]=l=>g.value=!1)}),e("div",Ve,[e("h2",Be,n(t(o)("gamification.seasons.activate_title")),1),e("p",He,n(t(o)("gamification.seasons.activate_confirm",{name:t(p)?.name})),1),e("div",ze,[e("button",{class:"px-4 py-2 text-sm text-slate-400 hover:text-white transition",onClick:s[5]||(s[5]=l=>g.value=!1)},n(t(o)("gamification.seasons.cancel")),1),e("button",{disabled:t(m),class:"px-4 py-2 bg-emerald-600 hover:bg-emerald-500 disabled:bg-emerald-600/50 text-white text-sm font-medium rounded-lg transition",onClick:A},n(t(m)?t(o)("gamification.seasons.activating"):t(o)("gamification.seasons.activate")),9,$e)])])])):v("",!0)]))}});export{Te as default};
|