1import{w as P,l as r,m as o,q as t,B as u,z,u as s,J as y,aa as M,ac as R,D as b,K as n,F as D,v as Y,p,y as d,Y as G,Z as ne,W as H,X as J,a6 as ue,r as i,e as ge}from"./vue-vendor-B52ivs5F.js";import{u as ce,b as ye}from"./query-vendor-Ab0nfCYP.js";import{t as T,B as be}from"./index-NM9cAr_v.js";import{_ as ve}from"./Pagination-BR1DzaAC.js";import{p as xe,d as pe,g as me}from"./agencies-DJL-cWw2.js";import{ak as ke,b as fe,R as B,c as he,Y as _e,L as W,cK as X,cL as Z,bP as we,bd as Ae,bO as Ce,a7 as ze,cM as De,bQ as Te,a5 as Ee}from"./ui-vendor-D-1UBobO.js";import"./date-vendor-HBGOQ70J.js";import"./twilio-DAuME2Y9.js";import"./charts-D4hDxUnJ.js";import"./socket-CzTGKfeH.js";const Se={class:"mb-6 flex flex-wrap items-center justify-between gap-4"},$e={class:"mb-6 rounded-lg border border-gray-200 bg-white p-4 dark:border-gray-700 dark:bg-gray-800"},Le={class:"grid gap-4 md:grid-cols-2 lg:grid-cols-3"},je={class:"relative"},Ne={class:"flex gap-2"},Ue={class:"flex gap-2"},Pe={key:0,class:"flex items-center justify-center rounded-lg border border-gray-200 bg-white py-12 dark:border-gray-700 dark:bg-gray-800"},Be={class:"text-center"},Ie={key:1,class:"rounded-lg border border-red-200 bg-red-50 p-4 dark:border-red-900/50 dark:bg-red-900/20"},Ke={class:"flex items-start gap-3"},Ve={class:"mt-1 text-sm text-red-700 dark:text-red-300"},qe={key:2,class:"overflow-hidden rounded-lg border border-gray-200 dark:border-gray-700"},Fe={class:"overflow-x-auto"},Qe={class:"w-full"},Oe={class:"border-b border-gray-200 bg-gray-50 text-left text-sm font-medium dark:border-gray-700 dark:bg-gray-800/50"},Me=["onClick"],Re={class:"flex items-center gap-2"},Ye={class:"bg-white dark:bg-gray-800"},Ge={key:0,class:"border-t border-gray-200 dark:border-gray-700"},He=["colspan"],Je={class:"px-4 py-3 text-sm text-gray-900 dark:text-white"},We={class:"font-medium"},Xe={class:"px-4 py-3 text-sm text-gray-600 dark:text-gray-300"},Ze={class:"px-4 py-3 text-sm text-gray-600 dark:text-gray-300"},et={class:"px-4 py-3 text-sm text-gray-600 dark:text-gray-300"},tt={class:"px-4 py-3 text-sm text-gray-600 dark:text-gray-300"},at={class:"px-4 py-3 text-sm text-gray-600 dark:text-gray-300"},rt={class:"px-4 py-3 text-right"},st={class:"flex items-center justify-end gap-2"},lt=["onClick","disabled"],ot=["onClick","disabled","title"],it=["onClick"],dt={class:"relative w-full max-w-md rounded-xl bg-white p-6 shadow-xl dark:bg-gray-800"},nt={class:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-red-100 dark:bg-red-900/50"},ut={class:"mb-4 text-center text-sm text-gray-600 dark:text-gray-300"},gt={class:"font-semibold"},ct={class:"mb-6"},yt={class:"flex gap-3"},bt=["disabled"],vt=["disabled"],xt={class:"relative w-full max-w-md rounded-xl bg-white p-6 shadow-xl dark:bg-gray-800"},pt={class:"mb-2 text-center text-lg font-semibold text-gray-900 dark:text-white"},mt={class:"mb-6 text-center text-sm text-gray-600 dark:text-gray-300"},kt={class:"font-semibold"},ft={class:"font-semibold"},ht={class:"flex gap-3"},_t=["disabled"],wt=["disabled"],Ut={__name:"List",setup(At){const I=ce(),K=ge(()=>[{key:"name",label:"Name",sortable:!0},{key:"owner_name",label:"Owner",sortable:!0},{key:"owner_email",label:"Owner Email",sortable:!0},{key:"available_sub_accounts",label:"Sub-Accounts",sortable:!0},{key:"expiry",label:g.value==="canceled"?"Expiry Date":"Next Charge",sortable:!0},{key:"created_at",label:"Created At",sortable:!0}]),j=i(""),v=i(1),w=i(20);P(w,()=>{v.value=1});const _=i("created_at"),k=i(-1),f=i(!1),g=i(""),E=i(null),x=i(null);P([f,g],()=>{v.value=1});const N=i("");let V=null;P(j,l=>{clearTimeout(V),V=setTimeout(()=>{N.value=l,v.value=1},300)});const{isPending:ee,isError:te,error:ae,data:S}=ye({queryKey:["admin","agencies",N,v,w,_,k,f,g],queryFn:()=>me({page:v.value,pageSize:w.value,search:N.value,sort:_.value,order:k.value,archived:f.value,subscriptionType:g.value})}),$=i(!1),c=i(null),re=l=>{c.value=l,$.value=!0},q=()=>{x.value||($.value=!1,c.value=null)},se=async()=>{const l=c.value;if(!(!l||x.value)){x.value=l._id;try{const e=await pe(l._id);I.invalidateQueries({queryKey:["admin","agencies"]}
1),T.success(e.message||"Agency updated"),$.value=!1,c.value=null}catch{T.error("Failed to archive agency")}finally{x.value=null}}},le=l=>{_.value===l?k.value=k.value===1?-1:1:(_.value=l,k.value=1)},oe=async l=>{const e=l.user_id;if(!e){T.error("Agency owner not found");return}const C=typeof e=="object"?e._id:e,a=typeof e=="object"?e.email:null;E.value=l._id;try{await be({_id:C,email:a},{redirectTo:"/agency",useHardNavigation:!0})}catch{}finally{E.value=null}},L=i(!1),A=i(null),m=i(""),h=i(!1),ie=l=>{A.value=l,m.value="",L.value=!0},F=()=>{h.value||(L.value=!1,A.value=null,m.value="")},Q=async()=>{if(!(m.value!=="DELETE"||h.value)){h.value=!0;try{const l=await xe(A.value._id);I.invalidateQueries({queryKey:["admin","agencies"]}),T.success(l.message||"Agency deleted successfully"),L.value=!1,A.value=null,m.value=""}catch{T.error("Failed to delete agency")}finally{h.value=!1}}},de=l=>[l.user_id?.first_name,l.user_id?.last_name].filter(Boolean).join(" "),O=l=>l?new Date(l).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}):"-";return(l,e)=>{const C=ue("router-link");return r(),o("div",null,[t("div",Se,[e[14]||(e[14]=t("div",null,[t("h1",{class:"text-2xl font-bold text-gray-900 dark:text-white"},"Agencies"),t("p",{class:"mt-1 text-sm text-gray-600 dark:text-gray-400"}," Manage agency accounts and their sub-accounts ")],-1)),u(C,{to:"/admin/agencies/create",class:"inline-flex items-center gap-2 rounded-lg bg-teal-500 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-teal-600"},{default:z(()=>[u(s(ke),{size:16}),e[13]||(e[13]=y(" Create Agency ",-1))]),_:1})]),t("div",$e,[t("div",Le,[t("div",null,[e[15]||(e[15]=t("label",{class:"mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300"}," Search ",-1)),t("div",je,[u(s(fe),{size:18,class:"absolute top-1/2 left-3 -translate-y-1/2 text-gray-400 dark:text-gray-500"}),M(t("input",{"onUpdate:modelValue":e[0]||(e[0]=a=>j.value=a),type:"text",placeholder:"Search by agency, owner name or email...",class:"w-full rounded-lg border border-gray-300 bg-white py-2 pr-4 pl-10 text-sm text-gray-900 placeholder-gray-500 focus:ring-2 focus:ring-teal-500 focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-400"},null,512),[[R,j.value]])])]),t("div",null,[e[16]||(e[16]=t("label",{class:"mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300"}," Status ",-1)),t("div",Ne,[t("button",{onClick:e[1]||(e[1]=a=>f.value=!1),class:b(["flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-colors",f.value?"bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-400 dark:hover:bg-gray-600":"bg-teal-50 text-teal-600 dark:bg-teal-500/20 dark:text-teal-400"])}," Active ",2),t("button",{onClick:e[2]||(e[2]=a=>f.value=!0),class:b(["flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-colors",f.value?"bg-teal-50 text-teal-600 dark:bg-teal-500/20 dark:text-teal-400":"bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-400 dark:hover:bg-gray-600"])}," Archived ",2)])]),t("div",null,[e[17]||(e[17]=t("label",{class:"mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300"}," Subscription Type ",-1)),t("div",Ue,[t("button",{onClick:e[3]||(e[3]=a=>g.value=""),class:b(["flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-colors",g.value===""?"bg-teal-50 text-teal-600 dark:bg-teal-500/20 dark:text-teal-400":"bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-400 dark:hover:bg-gray-600"])}," All ",2),t("button",{onClick:e[4]||(e[4]=a=>g.value="trial"),class:b(["flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-colors",g.value==="trial"?"bg-teal-50 text-teal-600 dark:bg-teal-500/20 dark:text-teal-400":"bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-400 dark:hover:bg-gray-600"])}," Trial ",2),t("button",{onClick:e[5]||(e[5]=a=>g.value="active"),class:b(["flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-colors",g.value==="active"?"bg-teal-50 text-teal-600 dark:bg-teal-500/20 dark:text-teal-400":"bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-400 dark:hover:bg-gray-600"])}," Active ",2),t("button",{onClick:e[6]||(e[6]=a=>g.value="canceled"),class:b(["flex-1 rounded-lg px-4 py-2 text-sm font-medium transition-colors",g.value==="canceled"?"bg-teal-50 text-teal-600 dar
1k:bg-teal-500/20 dark:text-teal-400":"bg-gray-100 text-gray-600 hover:bg-gray-200 dark:bg-gray-700 dark:text-gray-400 dark:hover:bg-gray-600"])}," Canceled ",2)])])])]),s(ee)?(r(),o("div",Pe,[t("div",Be,[u(s(B),{size:32,class:"mx-auto animate-spin text-gray-400 dark:text-gray-600"}),e[18]||(e[18]=t("p",{class:"mt-4 text-sm text-gray-600 dark:text-gray-400"},"Loading agencies...",-1))])])):s(te)?(r(),o("div",Ie,[t("div",Ke,[u(s(he),{size:20,class:"text-red-600"}),t("div",null,[e[19]||(e[19]=t("h3",{class:"font-medium text-red-900 dark:text-red-400"},"Error Loading Agencies",-1)),t("p",Ve,n(s(ae)?.message||"An error occurred while loading agencies"),1)])])])):(r(),o("div",qe,[t("div",Fe,[t("table",Qe,[t("thead",Oe,[t("tr",null,[(r(!0),o(D,null,Y(K.value,a=>(r(),o("th",{key:a.key,class:b(["px-4 py-3 text-gray-700 dark:text-gray-300",a.sortable&&"cursor-pointer transition-colors hover:text-gray-900 dark:hover:text-white"]),onClick:U=>a.sortable&&le(a.key)},[t("div",Re,[y(n(a.label)+" ",1),a.sortable?(r(),o(D,{key:0},[_.value===a.key&&k.value===1?(r(),d(s(we),{key:0,size:14,class:"text-teal-500"})):_.value===a.key&&k.value===-1?(r(),d(s(Ae),{key:1,size:14,class:"text-teal-500"})):(r(),d(s(Ce),{key:2,size:14,class:"text-gray-400 dark:text-gray-500"}))],64)):p("",!0)])],10,Me))),128)),e[20]||(e[20]=t("th",{class:"px-4 py-3 text-right text-gray-700 dark:text-gray-300"},"Actions",-1))])]),t("tbody",Ye,[s(S)?.results?.length?p("",!0):(r(),o("tr",Ge,[t("td",{colspan:K.value.length+1,class:"px-4 py-8 text-center text-sm text-gray-500 dark:text-gray-400"}," No agencies found ",8,He)])),(r(!0),o(D,null,Y(s(S)?.results,a=>(r(),o("tr",{key:a._id,class:"border-t border-gray-200 transition-colors hover:bg-gray-50 dark:border-gray-700 dark:hover:bg-gray-700/50"},[t("td",Je,[t("div",We,n(a.name),1)]),t("td",Xe,n(de(a)||"-"),1),t("td",Ze,n(a.user_id?.email||"-"),1),t("td",et,n(a.available_sub_accounts??"-")+" / "+n(a.total_sub_accounts??"-"),1),t("td",tt,n(a.expiry?O(a.expiry):"-"),1),t("td",at,n(O(a.created_at)),1),t("td",rt,[t("div",st,[u(C,{to:`/admin/agencies/${a._id}`,class:"rounded p-1.5 text-gray-500 transition-colors hover:bg-teal-50 hover:text-teal-600 dark:text-gray-400 dark:hover:bg-teal-900/50 dark:hover:text-teal-400",title:"View Details"},{default:z(()=>[u(s(ze),{size:16})]),_:1},8,["to"]),a.user_id?(r(),o("button",{key:0,onClick:U=>oe(a),disabled:E.value===a._id,class:"rounded p-1.5 text-gray-500 transition-colors hover:bg-purple-50 hover:text-purple-600 disabled:cursor-not-allowed disabled:opacity-50 dark:text-gray-400 dark:hover:bg-purple-900/50 dark:hover:text-purple-400",title:"Login as Agency Owner"},[E.value===a._id?(r(),d(s(B),{key:0,size:16,class:"animate-spin"})):(r(),d(s(De),{key:1,size:16}))],8,lt)):p("",!0),u(C,{to:`/admin/agencies/${a._id}/edit`,class:"rounded p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white",title:"Edit"},{default:z(()=>[u(s(Te),{size:16})]),_:1},8,["to"]),t("button",{onClick:U=>re(a),disabled:x.value===a._id,class:b(["rounded p-1.5 transition-colors disabled:cursor-not-allowed disabled:opacity-50",a.deleted_at?"text-teal-500 hover:bg-teal-50 hover:text-teal-600 dark:text-teal-400 dark:hover:bg-teal-900/50 dark:hover:text-teal-300":"text-gray-500 hover:bg-red-50 hover:text-red-600 dark:text-gray-400 dark:hover:bg-red-900/50 dark:hover:text-red-400"]),title:a.deleted_at?"Unarchive":"Archive"},[x.value===a._id?(r(),d(s(B),{key:0,size:16,class:"animate-spin"})):a.deleted_at?(r(),d(s(X),{key:1,size:16})):(r(),d(s(Z),{key:2,size:16}))],10,ot),a.deleted_at?(r(),o("button",{key:1,onClick:U=>ie(a),class:"rounded p-1.5 text-red-500 transition-colors hover:bg-red-50 hover:text-red-700 dark:text-red-400 dark:hover:bg-red-900/50 dark:hover:text-red-300",title:"Delete Permanently"},[u(s(Ee),{size:16})],8,it)):p("",!0)])])]))),128))])])]),s(S)?.pagination?(r(),d(ve,{key:0,page:v.value,"page-size":w.value,total:s(S).pagination.total||0,"item-name":"agencies","show-per-page-selector":"","show-page-buttons":"",onPrev:e[7]||(e[7]=a=>v.value--),onNext:e[8]||(e[8]=a=>v.value++),onGoto:e[9]||(e[9]=a=>v.value=a),"onUpdate:pageSize":e[10]||(e[10]=a=>w.value=a)},null,8,["page","page-size","total"])):p("",!0)])),(r(),d(J,{to:"body"},[u(H,{"enter-active-class":"transition-opacity duration-200","enter-from-class":"opacity-0","enter-to-class":"opacity-100","leave-active-class":"transition-opacity duration-150","leave-from-class":"opacity-100","leave-to-class":"opacity-0"},{default:z(()=>[L.value?(r(),o("div",{key:0,class:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:G(F,["self"])},[e[26]||(e[26]=t("div",{class:"absolute inset-0 bg-black/50"},null,-1)),t("div",dt,[t("div",nt,[u(s(_e),{size:24,class:"text-red-500"})]),e[25]||(e[25]=t("h3",{class:"mb-2 text-center text-lg font-semibold text-gray-900 dark:text-white"}," Delete Agency Permanently ",-1)),t("p",ut,[e[21]||(e[21]=y(" This will permanently delete ",-1)),t("span",gt,n(A.value?.name),1),e[22]||(e[22]=y(" and all its companies, users, chats, subscriptions, and other related records. ",-1))]),t("div",ct,[e[23]||(e[23]=t("label",{class:"mb-1.5 block text-sm font-medium text-gray-700 dark:text-gray-300"},[y(" Type "),t("span",{class:"font-bold text-red-600"},"DELETE"),y(" to confirm ")],-1)),M(t("input",{"onUpdate:modelValue":e[11]||(e[11]=a=>m.value=a),type:"text",placeholder:"Type DELETE here",class:"w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm text-gray-900 placeholder-gray-400 focus:border-red-500 focus:ring-1 focus:ring-red-500 focus:outline-none dark:border-gray-600 dark:bg-gray-700 dark:text-white dark:placeholder-gray-500",onKeyup:e[12]||(e[12]=ne(a=>m.value==="DELETE"&&Q(),["enter"]))},null,544),[[R,m.value]])]),t("div",yt,[t("button",{type:"button",onClick:F,disabled:h.value,class:"flex-1 rounded-lg bg-gray-100 px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600"}
1," Cancel ",8,bt),t("button",{type:"button",onClick:Q,disabled:m.value!=="DELETE"||h.value,class:"flex flex-1 items-center justify-center gap-2 rounded-lg bg-red-600 px-4 py-2.5 text-sm font-medium text-white transition-colors hover:bg-red-700 disabled:cursor-not-allowed disabled:opacity-50"},[h.value?(r(),d(s(W),{key:0,size:16,class:"animate-spin"})):p("",!0),e[24]||(e[24]=y(" Delete Permanently ",-1))],8,vt)])])])):p("",!0)]),_:1})])),(r(),d(J,{to:"body"},[u(H,{"enter-active-class":"transition-opacity duration-200","enter-from-class":"opacity-0","enter-to-class":"opacity-100","leave-active-class":"transition-opacity duration-150","leave-from-class":"opacity-100","leave-to-class":"opacity-0"},{default:z(()=>[$.value?(r(),o("div",{key:0,class:"fixed inset-0 z-50 flex items-center justify-center p-4",onClick:G(q,["self"])},[e[31]||(e[31]=t("div",{class:"absolute inset-0 bg-black/50"},null,-1)),t("div",xt,[t("div",{class:b(["mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full",c.value?.deleted_at?"bg-teal-100 dark:bg-teal-900/50":"bg-red-100 dark:bg-red-900/50"])},[c.value?.deleted_at?(r(),d(s(X),{key:0,size:24,class:"text-teal-500"})):(r(),d(s(Z),{key:1,size:24,class:"text-red-500"}))],2),t("h3",pt,n(c.value?.deleted_at?"Unarchive Agency":"Archive Agency"),1),t("p",mt,[c.value?.deleted_at?(r(),o(D,{key:0},[e[27]||(e[27]=y(" This will unarchive ",-1)),t("span",kt,n(c.value?.name),1),e[28]||(e[28]=y(" and reactivate its Stripe subscription, so billing will resume. Its companies will also be unarchived. ",-1))],64)):(r(),o(D,{key:1},[e[29]||(e[29]=y(" This will archive ",-1)),t("span",ft,n(c.value?.name),1),e[30]||(e[30]=y(" and cancel its Stripe subscription, so it will not be charged again. Its companies will also be archived. ",-1))],64))]),t("div",ht,[t("button",{type:"button",onClick:q,disabled:x.value,class:"flex-1 rounded-lg bg-gray-100 px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-200 disabled:cursor-not-allowed disabled:opacity-50 dark:bg-gray-700 dark:text-white dark:hover:bg-gray-600"}," Cancel ",8,_t),t("button",{type:"button",onClick:se,disabled:x.value,class:b(["flex flex-1 items-center justify-center gap-2 rounded-lg px-4 py-2.5 text-sm font-medium text-white transition-colors disabled:cursor-not-allowed disabled:opacity-50",c.value?.deleted_at?"bg-teal-600 hover:bg-teal-700":"bg-red-600 hover:bg-red-700"])},[x.value?(r(),d(s(W),{key:0,size:16,class:"animate-spin"})):p("",!0),y(" "+n(c.value?.deleted_at?"Unarchive":"Archive"),1)],10,wt)])])])):p("",!0)]),_:1})]))])}}};export{Ut as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.