import{o as N,f as o,b as e,h as E,A as f,y as w,x as L,g as U,F,l as j,e as p,t as a,B as q,a as h,k as r,c as S,r as Z,m as G,j as n,n as H,i as K,z as O}from"./index-CeMVzSB6.js";const R={class:"flex items-center justify-between mb-6"},W={class:"bg-white rounded-xl shadow-sm p-4 mb-6"},I={class:"flex items-center gap-4"},J={class:"relative flex-1 max-w-md"},P={class:"bg-white rounded-xl shadow-sm overflow-hidden"},Q={class:"w-full"},X={class:"divide-y divide-slate-200"},Y={class:"px-6 py-4"},ee={class:"font-medium text-slate-800"},te={class:"text-sm text-slate-500"},se={class:"px-6 py-4"},le={class:"px-6 py-4"},oe={class:"flex items-center gap-1"},ae={key:0,class:"text-xs text-slate-400"},ne={class:"px-6 py-4 text-sm text-slate-500"},re={class:"px-6 py-4 text-right"},ie={class:"flex items-center justify-end gap-2"},de=["onClick"],ue=["onClick"],pe={key:0},ce={class:"px-6 py-4 border-t border-slate-200 flex items-center justify-between"},xe={class:"text-sm text-slate-500"},ve={class:"flex items-center gap-2"},me=["disabled"],be=["disabled"],ge={key:0,class:"fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50"},fe={class:"bg-white rounded-2xl shadow-xl w-full max-w-md p-6"},he={class:"flex items-center gap-2 pt-2"},ye=["disabled"],_e={__name:"Tenants",setup(we){const u=r([]),k=r(!0),_=r(""),y=r(""),i=r(1),c=r(20),x=r(!1),d=Z({name:"",email:""}),v=r(!1),C=S(()=>u.value),m=S(()=>({start:(i.value-1)*c.value+1,end:Math.min(i.value*c.value,u.value.length),total:u.value.length,pages:Math.ceil(u.value.length/c.value)}));async function b(){k.value=!0;try{const l=await h.get("/admin/tenants",{params:{page:i.value,limit:c.value,status:y.value||void 0}});u.value=l.data.data.tenants}catch(l){console.error("Failed to fetch tenants:",l)}finally{k.value=!1}}async function T(){v.value=!0;try{await h.post("/admin/tenants",d),x.value=!1,Object.assign(d,{name:"",email:""}),await b()}catch(l){console.error("Failed to create tenant:",l)}finally{v.value=!1}}async function A(l){try{await h.post(`/admin/tenants/${l.id}/approve`),await b()}catch(t){console.error("Failed to approve tenant:",t)}}async function V(l){try{await h.post(`/admin/tenants/${l.id}/suspend`),await b()}catch(t){console.error("Failed to suspend tenant:",t)}}function B(l){return{pending_approval:"bg-yellow-100 text-yellow-800",active:"bg-green-100 text-green-800",trial:"bg-blue-100 text-blue-800",suspended:"bg-red-100 text-red-800"}[l]||"bg-slate-100 text-slate-800"}function $(l){return{pending_approval:"Ausstehend",active:"Aktiv",trial:"Testphase",suspended:"Suspendiert"}[l]||l}function z(l){return new Date(l).toLocaleDateString("de-DE",{day:"2-digit",month:"2-digit",year:"numeric"})}return N(b),(l,t)=>{const D=G("router-link");return n(),o("div",null,[e("div",R,[t[9]||(t[9]=e("div",null,[e("h1",{class:"text-2xl font-bold text-slate-800"},"Fahrschulen"),e("p",{class:"text-slate-500 text-sm mt-1"},"Verwalten Sie alle registrierten Fahrschulen")],-1)),e("button",{onClick:t[0]||(t[0]=s=>x.value=!0),class:"flex items-center gap-2 px-4 py-2 bg-primary text-white rounded-lg hover:bg-primary-600 transition-colors"},[...t[8]||(t[8]=[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:"M12 4v16m8-8H4"})],-1),E(" Fahrschule anlegen ",-1)])])]),e("div",W,[e("div",I,[e("div",J,[t[10]||(t[10]=e("svg",{class:"absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-slate-400",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)),f(e("input",{"onUpdate:modelValue":t[1]||(t[1]=s=>_.value=s),type:"text",placeholder:"Suchen...",class:"w-full pl-10 pr-4 py-2 rounded-lg border border-slate-300 focus:ring-2 focus:ring-primary focus:border-primary outline-none"},null,512),[[w,_.value]])]),f(e("select",{"onUpdate:modelValue":t[2]||(t[2]=s=>y.value=s),class:"px-4 py-2 rounded-lg border border-slate-300 focus:ring-2 focus:ring-primary focus:border-primary outline-none"},[...t[11]||(t[11]=[U('',5)])],512),[[L,y.value]])])]),e("div",P,[e("table",Q,[t[16]||(t[16]=e("thead",{class:"bg-slate-50 border-b border-slate-200"},[e("tr",null,[e("th",{class:"px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider"},"Fahrschule"),e("th",{class:"px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider"},"Status"),e("th",{class:"px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider"},"Module"),e("th",{class:"px-6 py-3 text-left text-xs font-semibold text-slate-600 uppercase tracking-wider"},"Registriert"),e("th",{class:"px-6 py-3 text-right text-xs font-semibold text-slate-600 uppercase tracking-wider"},"Aktionen")])],-1)),e("tbody",X,[(n(!0),o(F,null,j(C.value,s=>{var M;return n(),o("tr",{key:s.id,class:"hover:bg-slate-50"},[e("td",Y,[e("div",null,[e("p",ee,a(s.name),1),e("p",te,a(s.email),1)])]),e("td",se,[e("span",{class:H(["inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium",B(s.status)])},a($(s.status)),3)]),e("td",le,[e("div",oe,[(n(!0),o(F,null,j((M=s.modules)==null?void 0:M.slice(0,3),g=>(n(),o("span",{key:g,class:"inline-flex items-center px-2 py-0.5 rounded text-xs bg-slate-100 text-slate-600"},a(g),1))),128)),s.module_count>3?(n(),o("span",ae," +"+a(s.module_count-3),1)):p("",!0)])]),e("td",ne,a(z(s.created_at)),1),e("td",re,[e("div",ie,[K(D,{to:`/admin/tenants/${s.id}`,class:"p-2 text-slate-400 hover:text-primary rounded-lg hover:bg-slate-100 transition-colors"},{default:O(()=>[...t[12]||(t[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:"M15 12a3 3 0 11-6 0 3 3 0 016 0z"}),e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z"})],-1)])]),_:1},8,["to"]),s.status==="pending_approval"?(n(),o("button",{key:0,onClick:g=>A(s),class:"p-2 text-slate-400 hover:text-green-600 rounded-lg hover:bg-green-50 transition-colors",title:"Genehmigen"},[...t[13]||(t[13]=[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:"M5 13l4 4L19 7"})],-1)])],8,de)):p("",!0),s.status!=="suspended"?(n(),o("button",{key:1,onClick:g=>V(s),class:"p-2 text-slate-400 hover:text-red-600 rounded-lg hover:bg-red-50 transition-colors",title:"Suspendieren"},[...t[14]||(t[14]=[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:"M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"})],-1)])],8,ue)):p("",!0)])])])}),128)),C.value.length===0?(n(),o("tr",pe,[...t[15]||(t[15]=[e("td",{colspan:"5",class:"px-6 py-12 text-center text-slate-500"}," Keine Fahrschulen gefunden ",-1)])])):p("",!0)])]),e("div",ce,[e("p",xe," Zeige "+a(m.value.start)+" - "+a(m.value.end)+" von "+a(m.value.total),1),e("div",ve,[e("button",{onClick:t[3]||(t[3]=s=>i.value--),disabled:i.value===1,class:"px-3 py-1 rounded border border-slate-300 text-slate-600 hover:bg-slate-50 disabled:opacity-50 disabled:cursor-not-allowed"}," Zurück ",8,me),e("button",{onClick:t[4]||(t[4]=s=>i.value++),disabled:i.value>=m.value.pages,class:"px-3 py-1 rounded border border-slate-300 text-slate-600 hover:bg-slate-50 disabled:opacity-50 disabled:cursor-not-allowed"}," Weiter ",8,be)])])]),x.value?(n(),o("div",ge,[e("div",fe,[t[19]||(t[19]=e("h3",{class:"text-lg font-semibold text-slate-800 mb-4"},"Fahrschule anlegen",-1)),e("form",{onSubmit:q(T,["prevent"]),class:"space-y-4"},[e("div",null,[t[17]||(t[17]=e("label",{class:"block text-sm font-medium text-slate-700 mb-1"},"Name *",-1)),f(e("input",{"onUpdate:modelValue":t[5]||(t[5]=s=>d.name=s),type:"text",required:"",class:"w-full px-4 py-2 rounded-lg border border-slate-300 focus:ring-2 focus:ring-primary outline-none"},null,512),[[w,d.name]])]),e("div",null,[t[18]||(t[18]=e("label",{class:"block text-sm font-medium text-slate-700 mb-1"},"E-Mail *",-1)),f(e("input",{"onUpdate:modelValue":t[6]||(t[6]=s=>d.email=s),type:"email",required:"",class:"w-full px-4 py-2 rounded-lg border border-slate-300 focus:ring-2 focus:ring-primary outline-none"},null,512),[[w,d.email]])]),e("div",he,[e("button",{type:"button",onClick:t[7]||(t[7]=s=>x.value=!1),class:"px-4 py-2 rounded-lg border border-slate-300 text-slate-600 hover:bg-slate-50"}," Abbrechen "),e("button",{type:"submit",disabled:v.value,class:"px-4 py-2 rounded-lg bg-primary text-white hover:bg-primary-600 disabled:opacity-50"},a(v.value?"Erstelle...":"Erstellen"),9,ye)])],32)])])):p("",!0)])}}};export{_e as default};