2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
import{_ as le}from"./C94yYWrE.js";import{e as ie,B as T,g as ne,c as l,a as e,t as o,y as $,z as Q,C as D,F as B,r as L,d as _,j as y,x as re,k as p,l as n,m as q,E as de,h as ce,o as i,b as ue,w as pe,G as ge}from"./Dc9IRd06.js";const ve={class:"mb-8"},me={class:"text-2xl font-bold text-white"},xe={class:"text-slate-400 mt-1"},he={class:"flex flex-col sm:flex-row items-start sm:items-center justify-between gap-4 mb-6"},be={class:"relative flex-1 max-w-md"},fe=["placeholder"],_e={class:"flex items-center gap-2"},ye={value:"all"},ke={value:"individual"},we={value:"corporate"},$e={value:"all"},Ce=["value"],Me={key:0,class:"flex items-center justify-center py-20"},je={class:"flex flex-col items-center gap-3"},ze={class:"text-slate-400 text-sm"},Te={key:1,class:"flex flex-col items-center justify-center py-20 text-center"},Be={class:"text-red-400 text-sm mb-2"},Ve={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4 mb-8"},Se={class:"bg-slate-800 rounded-xl border border-slate-700 p-4"},Fe={class:"flex items-center gap-3"},Ae={class:"text-xs text-slate-400 uppercase tracking-wider"},De={class:"text-2xl font-bold text-white"},Le={class:"bg-slate-800 rounded-xl border border-slate-700 p-4"},Ne={class:"flex items-center gap-3"},Ge={class:"text-xs text-slate-400 uppercase tracking-wider"},He={class:"text-2xl font-bold text-emerald-400"},Ue={class:"bg-slate-800 rounded-xl border border-slate-700 p-4"},Ie={class:"flex items-center gap-3"},Ee={class:"text-xs text-slate-400 uppercase tracking-wider"},Pe={class:"text-2xl font-bold text-amber-400"},Oe={key:0,class:"mb-4 text-xs text-slate-500"},Qe={class:"text-slate-300 font-semibold"},qe={class:"bg-slate-800/50 border border-slate-700 rounded-xl overflow-hidden"},Je={class:"overflow-x-auto"},Ke={class:"w-full text-sm"},Re={class:"border-b border-slate-700 bg-slate-800/80"},We={class:"text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400"},Xe={class:"text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400"},Ye={class:"text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400"},Ze={class:"text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400"},et={class:"text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400"},tt={class:"py-3.5 px-4 text-slate-400 font-mono text-xs"},st={class:"py-3.5 px-4"},ot={class:"flex items-center gap-3"},at={class:"text-xs text-slate-500"},lt={class:"py-3.5 px-4"},it={class:"py-3.5 px-4"},nt={class:"py-3.5 px-4"},rt={key:0,class:"text-slate-300 text-xs"},dt={key:1,class:"text-slate-500 text-xs italic"},ct={class:"py-3.5 px-4"},ut={class:"flex items-center gap-2"},pt=["onClick","title"],gt=["onClick"],vt=["onClick"],mt={key:0,class:"flex flex-col items-center justify-center py-16 text-center"},xt={class:"text-slate-400 text-sm"},ht={class:"bg-slate-800 border border-slate-700 rounded-2xl shadow-2xl w-full max-w-lg mx-4 overflow-hidden"},bt={class:"px-6 py-4 border-b border-slate-700 flex items-center justify-between"},ft={class:"text-lg font-semibold text-white"},_t={class:"text-sm text-slate-400 mt-0.5"},yt={class:"px-6 py-5 space-y-5"},kt={class:"bg-slate-900/50 rounded-xl p-4 border border-slate-700/50"},wt={class:"text-xs text-slate-500 uppercase tracking-wider mb-1"},$t={class:"text-sm font-medium text-white"},Ct={key:0,class:"text-xs text-slate-400 mt-1"},Mt={class:"block text-sm font-medium text-slate-300 mb-2"},jt={value:"",disabled:""},zt=["value"],Tt={class:"block text-sm font-medium text-slate-300 mb-2"},Bt={class:"text-xs text-slate-500 ml-1"},Vt={class:"text-xs text-slate-500 mt-1.5"},St={key:0,class:"bg-red-500/10 border border-red-500/20 rounded-lg px-4 py-3"},Ft={class:"text-sm text-red-400"},At={class:"px-6 py-4 border-t border-slate-700 flex items-center justify-end gap-3"},Dt=["disabled"],Lt={key:0,class:"flex items-center gap-2"},Nt={key:1},It=ie({__name:"index",setup(Gt){const C=n(!0),M=n(null),g=n([]),N=n([]),v=n(""),m=n("all"),x=n("all"),V=n([]),S=n(!1),d=n(null),c=n(""),h=n(""),k=n(!1),b=n(null),w=n(null);let F=null;function J(){F&&clearTimeout(F),F=setTimeout(()=>{u()},400)}T(v,()=>{J()}),T(m,()=>{u()}),T(x,()=>{u()});const G=n(0),H=n(0),U=n(0),I=q(()=>v.value!==""||m.value!=="all"||x.value!=="all");T(g,t=>{const s=new Set(V.value);for(const r of t)r.subscription_tier_name&&s.add(r.subscription_tier_name);V.value=Array.from(s).sort()},{immediate:!0,deep:!0});const E=q(()=>g.value);function j(){const s=ce("access_token").value;return s?{Authorization:`Bearer ${s}`}:{}}async function u(){C.value=!0,M.value=null;try{const t={limit:200};v.value&&(t.search_term=v.value),m.value!=="all"&&(t.org_type_filter=m.value),x.value!=="all"&&(t.tier_name_filter=x.value);const s=await $fetch("/api/v1/admin/organizations",{params:t,headers:j()});g.value=s.garages,I.value||(G.value=s.total,H.value=g.value.filter(r=>r.org_type==="individual").length,U.value=g.value.filter(r=>r.org_type!=="individual").length)}catch(t){console.error("[Garages] Failed to fetch garages:",t),M.value=t?.data?.detail||t?.message||"Failed to load garages"}finally{C.value=!1}}async function K(){try{const t=await $fetch("/api/v1/admin/packages",{params:{include_hidden:!0,limit:100},headers:j()});N.value=t.tiers}catch(t){console.error("[Garages] Failed to fetch tiers:",t)}}function R(t){d.value=t,c.value=t.subscription?.tier_id||"",h.value="",b.value=null,S.value=!0}function z(){S.value=!1,d.value=null,c.value="",h.value="",b.value=null}async function W(){if(!(!d.value||!c.value)){k.value=!0,b.value=null;try{const t={tier_id:c.value};h.value&&(t.expires_at=new Date(h.value).toISOString()),await $fetch(`/api/v1/admin/organizations/${d.value.id}/subscription`,{method:"PATCH",headers:{...j(),"Content-Type":"application/json"},body:t}),A("success",`"${f(d.value)}" ${de().$i18n.t("garages.subscription_updated")}`),z(),await u()}catch(t){console.error("[Garages] Failed to save subscription:",t),b.value=t?.data?.detail||t?.message||"Failed to save subscription"}finally{k.value=!1}}}async function X(t){const s=t.is_active?"inactive":"active",r=t.is_active?"deaktiválása":"aktiválása";try{await $fetch(`/api/v1/admin/organizations/${t.id}/status`,{method:"PUT",headers:{...j(),"Content-Type":"application/json"},body:{status:s}}),A("success",`"${f(t)}" ${r} sikeresen megtörtént.`),await u()}catch(a){console.error("[Garages] Failed to toggle status:",a),A("error",a?.data?.detail||a?.message||`A garázs ${r} sikertelen.`)}}function f(t){return t.display_name||t.name||t.full_name}function Y(t){ge(`/garages/${t.id}`)}function Z(t){return t.split(" ").map(s=>s.charAt(0)).join("").toUpperCase().slice(0,2)}function ee(t){const s=["bg-amber-600","bg-purple-600","bg-slate-600","bg-indigo-600","bg-emerald-600","bg-rose-600","bg-cyan-600","bg-orange-600","bg-teal-600"];let r=0;for(let a=0;a<t.length;a++)r=t.charCodeAt(a)+((r<<5)-r);return s[Math.abs(r)%s.length]}function te(t){return t==="active"?"bg-emerald-500/10 text-emerald-400":t==="suspended"?"bg-red-500/10 text-red-400":t==="pending_verification"?"bg-amber-500/10 text-amber-400":"bg-slate-500/10 text-slate-400"}function se(t){return t==="active"?"bg-emerald-400":t==="suspended"?"bg-red-400":t==="pending_verification"?"bg-amber-400":"bg-slate-400"}function oe(t){return t==="active"?"Aktív":t==="suspended"?"Felfüggesztve":t==="pending_verification"?"Függőben":"Inaktív"}function ae(t){const s=t.toLowerCase();return s.includes("enterprise")||s.includes("vip")||s.includes("corp")?"bg-purple-500/20 text-purple-300":s.includes("premium")||s.includes("pro")?"bg-amber-500/20 text-amber-300":"bg-slate-500/20 text-slate-300"}function P(t){try{return new Date(t).toLocaleDateString("hu-HU",{year:"numeric",month:"short",day:"numeric"})}catch{return t}}function A(t,s){w.value={type:t,message:s},setTimeout(()=>{w.value=null},4e3)}return ne(()=>{u(),K()}),(t,s)=>{const r=le;return i(),l("div",null,[e("div",ve,[e("h1",me,o(t.$t("garages.title")),1),e("p",xe,o(t.$t("garages.subtitle")),1)]),e("div",he,[e("div",be,[s[5]||(s[5]=e("svg",{class:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-500",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})],-1)),$(e("input",{"onUpdate:modelValue":s[0]||(s[0]=a=>v.value=a),type:"text",placeholder:t.$t("garages.search_placeholder"),class:"w-full pl-10 pr-4 py-2.5 bg-slate-800 border border-slate-700 rounded-lg text-sm text-white placeholder-slate-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 focus:border-indigo-500 transition"},null,8,fe),[[Q,v.value]])]),e("div",_e,[$(e("select",{"onUpdate:modelValue":s[1]||(s[1]=a=>m.value=a),class:"px-3 py-2.5 bg-slate-800 border border-slate-700 rounded-lg text-sm text-slate-300 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 transition"},[e("option",ye,o(t.$t("garages.all_types")),1),e("option",ke,o(t.$t("garages.type_individual")),1),e("option",we,o(t.$t("garages.type_corporate")),1)],512),[[D,m.value]]),$(e("select",{"onUpdate:modelValue":s[2]||(s[2]=a=>x.value=a),class:"px-3 py-2.5 bg-slate-800 border border-slate-700 rounded-lg text-sm text-slate-300 focus:outline-none focus:ring-2 focus:ring-indigo-500/50 transition"},[e("option",$e,o(t.$t("garages.all_tiers")),1),(i(!0),l(B,null,L(V.value,a=>(i(),l("option",{key:a,value:a},o(a),9,Ce))),128))],512),[[D,x.value]])])]),C.value?(i(),l("div",Me,[e("div",je,[s[6]||(s[6]=e("svg",{class:"w-8 h-8 text-indigo-400 animate-spin",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})],-1)),e("p",ze,o(t.$t("garages.loading")),1)])])):M.value?(i(),l("div",Te,[s[7]||(s[7]=e("svg",{class:"w-12 h-12 text-red-500 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",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("p",Be,o(M.value),1),e("button",{onClick:u,class:"px-4 py-2 text-sm bg-indigo-600/20 text-indigo-300 hover:bg-indigo-600/30 rounded-lg transition"},o(t.$t("garages.retry")),1)])):(i(),l(B,{key:2},[e("div",Ve,[e("div",Se,[e("div",Fe,[s[8]||(s[8]=e("div",{class:"p-2 rounded-lg bg-indigo-500/10 text-indigo-400"},[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:"M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"})])],-1)),e("div",null,[e("p",Ae,o(t.$t("garages.total_garages")),1),e("p",De,o(G.value),1)])])]),e("div",Le,[e("div",Ne,[s[9]||(s[9]=e("div",{class:"p-2 rounded-lg bg-emerald-500/10 text-emerald-400"},[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:"M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"})])],-1)),e("div",null,[e("p",Ge,o(t.$t("garages.private_garages")),1),e("p",He,o(H.value),1)])])]),e("div",Ue,[e("div",Ie,[s[10]||(s[10]=e("div",{class:"p-2 rounded-lg bg-amber-500/10 text-amber-400"},[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:"M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"})])],-1)),e("div",null,[e("p",Ee,o(t.$t("garages.corporate_garages")),1),e("p",Pe,o(U.value),1)])])])]),I.value?(i(),l("div",Oe,[s[11]||(s[11]=_(" Szűrt találat: ",-1)),e("span",Qe,o(g.value.length),1),s[12]||(s[12]=_(" db ",-1))])):y("",!0),e("div",qe,[e("div",Je,[e("table",Ke,[e("thead",null,[e("tr",Re,[s[13]||(s[13]=e("th",{class:"text-left py-3.5 px-4 text-xs font-semibold uppercase tracking-wider text-slate-400"},"ID",-1)),e("th",We,o(t.$t("garages.company_name")),1),e("th",Xe,o(t.$t("garages.status")),1),e("th",Ye,o(t.$t("garages.current_package")),1),e("th",Ze,o(t.$t("garages.expiration_date")),1),e("th",et,o(t.$t("garages.actions")),1)])]),e("tbody",null,[(i(!0),l(B,null,L(E.value,a=>(i(),l("tr",{key:a.id,class:"border-b border-slate-700/50 hover:bg-slate-700/30 transition"},[e("td",tt,o(a.id),1),e("td",st,[e("div",ot,[e("div",{class:p(["w-8 h-8 rounded-lg flex items-center justify-center text-sm font-bold text-white",ee(f(a))])},o(Z(f(a))),3),e("div",null,[ue(r,{to:"/garages/"+a.id,class:"text-sm font-medium text-white hover:underline cursor-pointer hover:text-indigo-400 transition-colors"},{default:pe(()=>[_(o(f(a)),1)]),_:2},1032,["to"]),e("p",at,o(a.city||"—")+" · "+o(a.member_count)+" "+o(t.$t("garages.members")),1)])])]),e("td",lt,[e("span",{class:p(["inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",te(a.status)])},[e("span",{class:p(["w-1.5 h-1.5 rounded-full mr-1.5",se(a.status)])},null,2),_(" "+o(oe(a.status)),1)],2)]),e("td",it,[e("span",{class:p(["px-2.5 py-0.5 rounded-full text-xs font-medium",ae(a.subscription_tier_name)])},o(a.subscription_tier_name),3)]),e("td",nt,[a.subscription_expires_at?(i(),l("span",rt,o(P(a.subscription_expires_at)),1)):(i(),l("span",dt,o(t.$t("garages.indefinite")),1))]),e("td",ct,[e("div",ut,[e("button",{onClick:O=>Y(a),class:"px-3 py-1.5 text-xs font-medium bg-slate-600/20 text-slate-300 hover:bg-slate-600/30 rounded-lg transition",title:t.$t("garages.view_details")},o(t.$t("garages.view_details")),9,pt),e("button",{onClick:O=>R(a),class:"px-3 py-1.5 text-xs font-medium bg-indigo-600/20 text-indigo-300 hover:bg-indigo-600/30 rounded-lg transition"},o(t.$t("garages.manage_subscription")),9,gt),e("button",{onClick:O=>X(a),class:p(["px-3 py-1.5 text-xs font-medium rounded-lg transition",a.is_active?"bg-red-500/10 text-red-300 hover:bg-red-500/20":"bg-emerald-500/10 text-emerald-300 hover:bg-emerald-500/20"])},o(a.is_active?t.$t("garages.deactivate"):t.$t("garages.activate")),11,vt)])])]))),128))])])]),E.value.length===0&&!C.value?(i(),l("div",mt,[s[14]||(s[14]=e("svg",{class:"w-12 h-12 text-slate-600 mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"})],-1)),e("p",xt,o(t.$t("garages.no_results")),1)])):y("",!0)])],64)),S.value?(i(),l("div",{key:3,class:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm",onClick:re(z,["self"])},[e("div",ht,[e("div",bt,[e("div",null,[e("h3",ft,o(t.$t("garages.manage_subscription")),1),e("p",_t,o(d.value?f(d.value):""),1)]),e("button",{onClick:z,class:"p-1.5 rounded-lg text-slate-400 hover:text-white hover:bg-slate-700 transition"},[...s[15]||(s[15]=[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:"M6 18L18 6M6 6l12 12"})],-1)])])]),e("div",yt,[e("div",kt,[e("p",wt,o(t.$t("garages.current_package")),1),e("p",$t,o(d.value?.subscription_tier_name||t.$t("garages.free_fallback")),1),d.value?.subscription_expires_at?(i(),l("p",Ct,o(t.$t("garages.expires"))+": "+o(P(d.value.subscription_expires_at)),1)):y("",!0)]),e("div",null,[e("label",Mt,o(t.$t("garages.select_package")),1),$(e("select",{"onUpdate:modelValue":s[3]||(s[3]=a=>c.value=a),class:"w-full px-3 py-2.5 bg-slate-900 border border-slate-700 rounded-lg text-sm text-white focus:outline-none focus:ring-2 focus:ring-indigo-500/50 transition"},[e("option",jt,o(t.$t("garages.select_package_placeholder")),1),(i(!0),l(B,null,L(N.value,a=>(i(),l("option",{key:a.id,value:a.id},o(a.name)+" (Level "+o(a.tier_level)+") ",9,zt))),128))],512),[[D,c.value]])]),e("div",null,[e("label",Tt,[_(o(t.$t("garages.custom_expiration"))+" ",1),e("span",Bt,"("+o(t.$t("garages.optional"))+")",1)]),$(e("input",{"onUpdate:modelValue":s[4]||(s[4]=a=>h.value=a),type:"datetime-local",class:"w-full px-3 py-2.5 bg-slate-900 border border-slate-700 rounded-lg text-sm text-white focus:outline-none focus:ring-2 focus:ring-indigo-500/50 transition"},null,512),[[Q,h.value]]),e("p",Vt,o(t.$t("garages.custom_expiration_hint")),1)]),b.value?(i(),l("div",St,[e("p",Ft,o(b.value),1)])):y("",!0)]),e("div",At,[e("button",{onClick:z,class:"px-4 py-2 text-sm font-medium text-slate-300 hover:text-white transition"},o(t.$t("garages.cancel")),1),e("button",{onClick:W,disabled:k.value||!c.value,class:p(["px-5 py-2 text-sm font-medium rounded-lg transition disabled:opacity-50 disabled:cursor-not-allowed",k.value?"bg-indigo-600/50 text-indigo-200 cursor-wait":"bg-indigo-600 text-white hover:bg-indigo-500"])},[k.value?(i(),l("span",Lt,[s[16]||(s[16]=e("svg",{class:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24"},[e("circle",{class:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor","stroke-width":"4"}),e("path",{class:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})],-1)),_(" "+o(t.$t("garages.saving")),1)])):(i(),l("span",Nt,o(t.$t("garages.save")),1))],10,Dt)])])])):y("",!0),w.value?(i(),l("div",{key:4,class:p(["fixed bottom-6 right-6 px-5 py-3 rounded-xl shadow-xl text-sm font-medium z-50",w.value.type==="success"?"bg-emerald-600 text-white":"bg-red-600 text-white"])},o(w.value.message),3)):y("",!0)])}}});export{It as default};
|