Files
2026-07-08 08:03:57 +00:00

2 lines
7.0 KiB
JavaScript

import{e as O,f as R,g as S,c as r,a as e,t as n,i as s,F as C,j as _,d as k,r as A,l as u,h as P,o as d,k as j,n as $,m as D}from"./CQHa_U7G.js";import{_ as E}from"./DlAUqK2U.js";const L={class:"mb-8"},U={class:"text-2xl font-bold text-white"},W={class:"text-slate-400 mt-1"},q={key:0,class:"flex items-center justify-center py-20"},G={class:"text-slate-400 flex items-center gap-3"},J={key:1,class:"bg-rose-500/10 border border-rose-500/30 rounded-xl p-6 mb-8"},Q={class:"text-rose-400"},X={class:"mb-6 flex items-center justify-between"},Y={class:"flex items-center gap-3"},Z={class:"text-sm text-slate-500"},K=["disabled"],ee={key:0,class:"w-4 h-4 animate-spin",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},te={class:"grid grid-cols-1 lg:grid-cols-2 gap-6 mb-8"},se={class:"flex items-start justify-between mb-4"},oe={class:"text-lg font-semibold text-white font-mono"},ae={class:"text-sm text-slate-400 mt-1"},ne={class:"space-y-3"},ie={class:"flex items-center gap-3"},le=["value","onInput"],re={class:"w-full bg-slate-700 rounded-full h-2 overflow-hidden"},de={key:0,class:"flex items-center gap-1 text-xs"},ue={class:"text-amber-400"},ce={class:"text-emerald-400"},me={class:"bg-slate-800/50 border border-slate-700/50 rounded-xl p-6"},ve={class:"flex items-start gap-3"},fe={class:"text-sm font-medium text-white mb-1"},_e={class:"text-sm text-slate-400"},he={key:3,class:"fixed bottom-6 right-6 z-50 bg-rose-600 text-white px-4 py-3 rounded-lg shadow-lg text-sm flex items-center gap-2"},ge={key:4,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"},pe=O({__name:"validation-rules",setup(xe){const{t:i}=R(),h=u(!0),g=u(!1),c=u(!1),m=u(""),f=u(""),p=u(""),b=u([]),v=u({}),l=u({}),B=D(()=>Object.keys(l.value).length>0);function y(){const o=P("access_token").value;return o?{Authorization:`Bearer ${o}`,"Content-Type":"application/json"}:{"Content-Type":"application/json"}}function M(t){f.value=t,setTimeout(()=>{f.value=""},3e3)}function z(t,o){const a=parseInt(o,10);if(isNaN(a))return;const x=Math.max(0,Math.min(100,a));l.value[t]=x}function V(t){return t in l.value}function H(t){return v.value[t]??0}function T(t){return(l.value[t]??v.value[t]??0)+"%"}function I(t){return t>=80?"bg-emerald-500/20 text-emerald-400":t>=50?"bg-amber-500/20 text-amber-400":"bg-slate-500/20 text-slate-400"}function N(t){return t>=80?"bg-emerald-500":t>=50?"bg-amber-500":"bg-slate-500"}async function w(){h.value=!0,g.value=!1;try{const t=await $fetch("/api/v1/admin/gamification/validation-rules",{headers:y()});b.value=t,v.value={},l.value={};for(const o of t)v.value[o.rule_key]=o.rule_value}catch(t){console.error("Failed to fetch validation rules:",t),g.value=!0}finally{h.value=!1}}async function F(){c.value=!0,m.value="";try{const t={};for(const[o,a]of Object.entries(l.value))t[o]=a;await $fetch("/api/v1/admin/gamification/validation-rules",{method:"PUT",headers:y(),body:{rules:t}});for(const[o,a]of Object.entries(l.value))v.value[o]=a;l.value={},p.value=new Date().toLocaleString("hu-HU"),M(i("gamification.validation_rules.rules_updated"))}catch(t){m.value=i("gamification.validation_rules.save_error"),console.error("Failed to save validation rules:",t),setTimeout(()=>{m.value=""},4e3)}finally{c.value=!1}}return S(()=>{w()}),(t,o)=>(d(),r("div",null,[e("div",L,[e("h1",U,n(s(i)("gamification.validation_rules.title")),1),e("p",W,n(s(i)("gamification.validation_rules.subtitle")),1)]),s(h)?(d(),r("div",q,[e("div",G,[o[0]||(o[0]=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(s(i)("gamification.validation_rules.loading")),1)])])):s(g)?(d(),r("div",J,[e("p",Q,n(s(i)("gamification.validation_rules.load_error")),1),e("button",{onClick:w,class:"mt-3 text-sm text-rose-300 hover:text-rose-200 underline"},n(s(i)("gamification.validation_rules.retry")),1)])):(d(),r(C,{key:2},[e("div",X,[e("div",Y,[e("span",Z,n(s(i)("gamification.validation_rules.last_saved"))+" "+n(s(p)?s(p):"—"),1)]),e("button",{onClick:F,disabled:s(c)||!s(B),class:"px-4 py-2 bg-emerald-600 hover:bg-emerald-500 disabled:bg-emerald-600/50 text-white rounded-lg text-sm font-medium transition flex items-center gap-2"},[s(c)?(d(),r("svg",ee,[...o[1]||(o[1]=[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),k(" "+n(s(c)?s(i)("gamification.validation_rules.saving"):s(i)("gamification.validation_rules.save_rules")),1)],8,K)]),e("div",te,[(d(!0),r(C,null,A(s(b),a=>(d(),r("div",{key:a.rule_key,class:"bg-slate-800 rounded-xl border border-slate-700 p-6"},[e("div",se,[e("div",null,[e("h2",oe,n(a.rule_key),1),e("p",ae,n(a.description),1)]),e("span",{class:j(["text-xs font-medium px-2 py-1 rounded-full",I(a.rule_value)])},n(a.rule_value),3)]),e("div",ne,[e("div",ie,[e("input",{value:s(l)[a.rule_key]??a.rule_value,onInput:x=>z(a.rule_key,x.target.value),type:"number",min:"0",max:"100",class:"w-full px-3 py-2 bg-slate-700 border border-slate-600 rounded-lg text-white text-sm text-center focus:outline-none focus:ring-2 focus:ring-indigo-500/50"},null,40,le)]),e("div",re,[e("div",{class:j(["h-full rounded-full transition-all duration-300",N(a.rule_value)]),style:$({width:T(a.rule_key)+"%"})},null,6)]),V(a.rule_key)?(d(),r("div",de,[e("span",ue,n(s(i)("gamification.validation_rules.changed_from"))+" "+n(H(a.rule_key)),1),o[2]||(o[2]=e("svg",{class:"w-3 h-3 text-amber-400",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M13 7l5 5m0 0l-5 5m5-5H6"})],-1)),e("span",ce,n(s(l)[a.rule_key]),1)])):_("",!0)])]))),128))]),e("div",me,[e("div",ve,[o[3]||(o[3]=e("svg",{class:"w-5 h-5 text-indigo-400 flex-shrink-0 mt-0.5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)),e("div",null,[e("h3",fe,n(s(i)("gamification.validation_rules.info_title")),1),e("p",_e,n(s(i)("gamification.validation_rules.info_text")),1)])])])],64)),s(m)?(d(),r("div",he,[o[4]||(o[4]=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:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)),k(" "+n(s(m)),1)])):_("",!0),s(f)?(d(),r("div",ge,[o[5]||(o[5]=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)),k(" "+n(s(f)),1)])):_("",!0)]))}}),ye=E(pe,[["__scopeId","data-v-7a2ac5d4"]]);export{ye as default};