1import{f as P,D as B,u as L,g as M,r as i,h as R,L as T,C as z,w as F,o as r,a as e,c,i as S,b as $,m as C,P as I,s as y,v as K,j as a,I as D,t as d,F as Y,k as j,d as U,e as H}from"#entry";import{a as G,_ as J}from"./CJQauOmt.js";import{_ as O}from"./BRsHvoYg.js";import{u as Q}from"./Dy9pVEbO.js";import"./DKLWY9DJ.js";const W={class:"mb-4 flex flex-wrap gap-3 items-end"},X={class:"flex-1 min-w-[200px]"},Z=["disabled"],ee={key:0,class:"mb-4 text-sm text-red-700 bg-red-50 border border-red-200 rounded-lg px-3 py-2"},te={key:1,class:"text-slate-600 py-8"},se={key:2,class:"bg-white rounded-xl border border-slate-200 shadow-sm overflow-x-auto"},le={class:"min-w-full text-sm"},ae={class:"px-4 py-3"},oe={class:"font-medium text-slate-900"},ne={class:"text-slate-500"},ie={class:"px-4 py-3 capitalize text-slate-700"},re={key:0,class:"text-slate-400"},de={class:"px-4 py-3 capitalize"},ue={class:"px-4 py-3"},ce={class:"px-4 py-3 text-right whitespace-nowrap"},pe=["disabled","onClick"],me={key:0},ge=P({__name:"index",setup(be){Q({title:"Admin users â DogHealthy",path:"/admin/users",index:!1});const V=B(),A=L(),q=M(),_=i(""),p=i(""),b=i(""),n=i(1),w=i(0),f=i(!0),u=i(""),x=i([]),v=i("");R(()=>{V.query.sub==="active"&&(p.value="active"),g()}),T(n,()=>g());const h=()=>{n.value!==1?n.value=1:g()},g=async()=>{f.value=!0,u.value="";try{const{from:o,to:t}=G(n.value);let l=A.from("doghealthy_users").select("id, email, full_name, billing_name, subscription_status, subscription_plan, nfc_chip_status, is_admin",{count:"exact"}).order("created_at",{ascending:!1}).range(o,t);const m=_.value.trim();m&&(l=l.or(`email.ilike.%${m}%,full_name.ilike.%${m}%,billing_name.ilike.%${m}%`)),p.value==="active"?l=l.in("subscription_status",["active","trialing"]):p.value==="none"&&(l=l.or("subscription_status.is.null,subscription_status.eq.")),b.value&&(l=l.eq("nfc_chip_status",b.value));const{data:k,error:s,count:N}=await l;if(s)throw s;x.value=k||[],w.value=N||0}catch(o){u.value=o?.message||"Failed to load users",x.value=[],w.value=0}finally{f.value=!1}},E=async o=>{if(q.user?.id===o.id){u.value="You cannot delete your own admin account from this list.";return}const t=o.full_name||o.email;if(confirm(`Delete user â${t}â and all their dogs / related data? This cannot be undone.`)){v.value=o.id,u.value="";try{const{error:l}=await A.from("doghealthy_users").delete().eq("id",o.id);if(l)throw l;x.value.length<=1&&n.value>1?n.value-=1:await g()}catch(l){u.value=l?.message||"Failed to delete user"}finally{v.value=""}}};return(o,t)=>{const l=H,m=J,k=O;return r(),z(k,{title:"Users",subtitle:"Search, open, edit or delete any member profile."},{default:F(()=>[e("div",W,[e("div",X,[t[4]||(t[4]=e("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"Search",-1)),C(e("input",{"onUpdate:modelValue":t[0]||(t[0]=s=>y(_)?_.value=s:null),type:"search",placeholder:"Email or nameâ¦",class:"w-full px-3 py-2 border border-slate-300 rounded-lg text-sm",onKeyup:I(h,["enter"])},null,544),[[K,a(_)]])]),e("div",null,[t[6]||(t[6]=e("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"Subscription",-1)),C(e("select",{"onUpdate:modelValue":t[1]||(t[1]=s=>y(p)?p.value=s:null),class:"px-3 py-2 border border-slate-300 rounded-lg text-sm",onChange:h},[...t[5]||(t[5]=[e("option",{value:""},"All",-1),e("option",{value:"active"},"Active / trialing",-1),e("option",{value:"none"},"No subscription",-1)])],544),[[D,a(p)]])]),e("div",null,[t[8]||(t[8]=e("label",{class:"block text-xs font-medium text-slate-600 mb-1"},"NFC chip",-1)),C(e("select",{"onUpdate:modelValue":t[2]||(t[2]=s=>y(b)?b.value=s:null),class:"px-3 py-2 border border-slate-300 rounded-lg text-sm",onChange:h},[...t[7]||(t[7]=[e("option",{value:""},"All",-1),e("option",{value:"pending"},"Pending",-1),e("option",{value:"shipped"},"Shipped",-1)])],544),[[D,a(b)]])]),e("button",{type:"button",class:"px-4 py-2 bg-slate-900 text-white rounded-lg text-sm font-semibold",disabled:a(f),onClick:h}," Search ",8,Z)]),a(u)?(r(),c("div",ee,d(a(u)),1)):S("",!0),a(f)?(r(),c("div",te,"Loading usersâ¦")):(r(),c("div",se,[e("table",le,[t[11]||(t[11]=e("thead",{class:"bg-slate-50 text-left text-slate-600"},[e("tr",null,[e("th",{class:"px-4 py-3 font-medium"},"User"),e("th",{class:"px-4 py-3 font-medium"},"Subscription"),e("th",{class:"px-4 py-3 font-medium"},"NFC chip"),e("th",{class:"px-4 py-3 font-medium"},"Admin"),e("th",{class:"px-4 py-3 font-medium text-right"},"Actions")])],-1)),e("tbody",null,[(r(!0),c(Y,null,j(a(x),s=>(r(),c("tr",{key:s.id,class:"border-t border-slate-100 hover:bg-slate-50"},[e("td",ae,[e("div",oe,d(s.full_name||s.billing_name||"â"),1),e("div",ne,d(s.email),1)]),e("td",ie,[U(d(s.subscription_status||"none")+" ",1),s.subscription_plan?(r(),c("span",re," · "+d(s.subscription_plan),1)):S("",!0)]),e("td",de,d(s.nfc_chip_status||"none"),1),e("td",ue,d(s.is_admin?"Yes":"â"),1),e("td",ce,[$(l,{to:`/admin/users/${s.id}`,class:"text-blue-700 font-medium hover:underline"},{default:F(()=>[...t[9]||(t[9]=[U(" Edit ",-1)])]),_:1},8,["to"]),e("button",{type:"button",class:"ml-3 text-red-700 font-medium hover:underline disabled:opacity-50",disabled:a(v)===s.id,onClick:N=>E(s)},d(a(v)===s.id?"Deletingâ¦":"Delete"),9,pe)])]))),128)),a(x).length===0?(r(),c("tr",me,[...t[10]||(t[10]=[e("td",{colspan:"5",class:"px-4 py-8 text-center text-slate-500"},"No users found.",-1)])])):S("",!0)])])])),$(m,{page:a(n),"onUpdate:page":t[3]||(t[3]=s=>y(n)?n.value=s:null),total:a(w),disabled:a(f)},null,8,["page","total","disabled"])]),_:1})}}});
1export{ge 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.