1import{r as n,k as Ne,a as se,l as y,j as e,B as a,U as fe,a2 as be,J as w,x as te,D as ae,s as C,S as ye,a1 as we,an as Ce,W as _e,X as Se,ap as ne,aq as ie,ar as le,as as re,at as _,aw as ke,a6 as I,a7 as q,a8 as z,a9 as E,I as S,t as p,h as d}from"./index-C4LWZPK9.js";import{T as ce}from"./textarea-G6LYtFU8.js";import{T as Ue,a as Re,b as k,c as o,d as De,e as l}from"./table-DCqWGOx9.js";import{u as Te}from"./useMobile-CP8-DlZL.js";import{M as de}from"./MobileSelectDrawer-EsQoSWfE.js";import{U as oe}from"./users-DL5nkPsl.js";import{F as M,B as j}from"./flag-Cp5AIdQ3.js";import{C as Ae}from"./circle-check-Cx31KQzm.js";const me={offensive_content:"Offensive Content",harassment:"Harassment",personal_info_sharing:"Personal Info Sharing",spam:"Spam",other:"Other"},Be={pending:"bg-yellow-500/20 text-yellow-400 border-yellow-500/30",reviewed:"bg-blue-500/20 text-blue-400 border-blue-500/30",actioned:"bg-destructive/20 text-destructive border-destructive/30",dismissed:"bg-secondary text-muted-foreground"};function Ke(){const O=Te(),[U,xe]=n.useState(""),[x,F]=n.useState("users"),[ue,g]=n.useState(!1),[R,K]=n.useState(""),[D,T]=n.useState("user"),[he,P]=n.useState(""),[pe,Q]=n.useState(""),[$,H]=n.useState(!1),[r,v]=n.useState(null),[V,A]=n.useState(""),[c,N]=n.useState(null),[f,B]=n.useState(""),u=Ne(),{data:je=[],isLoading:J}=se({queryKey:["admin-users"],queryFn:()=>d.entities.User.list("-created_date",200)}),{data:L=[],isLoading:W}=se({queryKey:["community-reports"],queryFn:()=>d.entities.CommunityReport.list("-created_date",100),enabled:x==="reports"}),G=y({mutationFn:({id:s,role:t})=>d.entities.User.update(s,{role:t}),onSuccess:()=>{u.invalidateQueries({queryKey:["admin-users"]}),p.success("Role updated")}}),ge=y({mutationFn:({id:s,is_deep_diver:t})=>d.entities.User.update(s,{is_deep_diver:t}),onSuccess:async(s,{is_deep_diver:t})=>{u.invalidateQueries({queryKey:["admin-users"]});const i=await d.auth.me();window.dispatchEvent(new CustomEvent("user-updated",{detail:i})),p.success(t?"Deep Diver granted ð":"Deep Diver removed")}}),b=y({mutationFn:({id:s,is_blocked:t,block_reason:i})=>d.entities.User.update(s,{is_blocked:t,block_reason:t?i:""}),onSuccess:(s,{is_blocked:t})=>{u.invalidateQueries({queryKey:["admin-users"]}),p.success(t?"User blocked from community":"User unblocked"),v(null),A("")}}),m=y({mutationFn:({id:s,status:t,admin_notes:i})=>d.entities.CommunityReport.update(s,{status:t,admin_notes:i}),onSuccess:()=>{u.invalidateQueries({queryKey:["community-reports"]}),p.success("Report updated"),N(null),B("")}}),ve=async s=>{s.preventDefault(),H(!0),await d.users.inviteUser(R,D),p.success(`Invitation sent to ${R}`),K(""),T("user"),P(""),Q(""),g(!1),H(!1),u.invalidateQueries({queryKey:["admin-users"]})},X=je.filter(s=>{var t,i;return((t=s.email)==null?void 0:t.toLowerCase().includes(U.toLowerCase()))||((i=s.full_name)==null?void 0:i.toLowerCase().includes(U.toLowerCase()))}),Y=L.filter(s=>s.status==="pending").length;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(oe,{className:"w-6 h-6 text-primary"}),e.jsx("h1",{className:"text-2xl font-display font-bold",children:"User Management"})]}),e.jsxs(a,{className:"gap-2 bg-primary hover:bg-primary/90",onClick:()=>g(!0),children:[e.jsx(fe,{className:"w-4 h-4"})," Invite User"]})]}),e.jsxs("div",{className:"flex gap-1 bg-secondary/40 rounded-xl p-1 mb-5 w-fit",children:[e.jsxs("button",{onClick:()=>F("users"),className:`px-4 py-2 rounded-lg text-sm font-medium transition-colors flex items-center gap-2 ${x==="users"?"bg-primary text-white":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(oe,{className:"w-4 h-4"})," Users"]}),e.jsxs("button",{onClick:()=>F("reports"),className:`px-4 py-2 rounded-lg text-sm font-medium transition-colors flex items-center gap-2 ${x==="reports"?"bg-primary text-white":"text-muted-foreground hover:text-foreground"}`,children:[e.jsx(M,{className:"w-4 h-4"})," Reports",Y>0&&e.jsx("span",{className:"bg-destructive text-white text-xs rounded-full px-1.5 py-0.5 leading-none",children:Y})]})]}),x==="users"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"relative mb-4",children:[e.jsx(be,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(w,{placeholder:"Search by name or email...",value:U,onChange:s=>xe(s.target.value),className:"pl-9"})]}),e.jsx(te,{className:"bg-secondary/30",children:e.jsx(ae,{className:"p-0",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(Ue,{children:[e.jsx(Re,{children:e.jsxs(k,{children:[e.jsx(o,{children:"User"}),e.jsx(o,{children:"Email"}),e.jsx(o,{children:"Role"}),e.jsx(o,{children:"Joined"}),e.jsx(o,{className:"text-center",children:"Deep Diver"}),e.jsx(o,{className:"text-center",children:"Blocked"}),e.jsx(o,{className:"text-right",children:"Actions"})]})}),e.jsxs(De,{children:[J&&e.jsx(k,{children:e.jsx(l,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"Loading..."})}),X.map(s=>{var t,i,Z,ee;return e.jsxs(k,{className:s.is_blocked?"opacity-60":"",children:[e.jsx(l,{children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded-full bg-primary/20 flex items-center justify-center text-sm font-medium",children:((i=(t=s.full_name)==null?void 0:t[0])==null?void 0:i.toUpperCase())||((ee=(Z=s.email)==null?void 0:Z[0])==null?void 0:ee.toUpperCase())||"?"}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-sm",children:s.full_name||"â"}),s.is_blocked&&e.jsx("p",{className:"text-xs text-destructive",children:"Blocked"})]})]})}),e.jsx(l,{className:"text-sm text-muted-foreground",children:s.email}),e.jsx(l,{children:e.jsxs(C,{className:`text-xs gap-1 ${s.role==="admin"?"bg-primary/20 text-primary":"bg-secondary"}`,children:[s.role==="admin"?e.jsx(ye,{className:"w-3 h-3"}):e.jsx(we,{className:"w-3 h-3"}),s.role||"user"]})}),e.jsx(l,{className:"text-xs text-muted-foreground",children:s.created_date?new Date(s.created_date).toLocaleDateString():"â"}),e.jsx(l,{className:"text-center",children:e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx(Ce,{checked:!!s.is_deep_diver,onCheckedChange:h=>ge.mutate({id:s.id,is_deep_diver:h})}),s.is_deep_diver&&e.jsx(_e,{className:"w-3.5 h-3.5 text-primary"})]})}),e.jsx(l,{className:"text-center",children:s.is_blocked?e.jsxs(a,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1 border-destructive/40 text-destructive hover:bg-destructive/10",onClick:()=>b.mutate({id:s.id,is_blocked:!1}),children:[e.jsx(Se,{className:"w-3 h-3"})," Unblock"]}):e.jsxs(a,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1 hover:border-destructive/40 hover:text-destructive",onClick:()=>{v(s),A("")},children:[e.jsx(j,{className:"w-3 h-3"})," Block"]})}),e.jsx(l,{className:"text-right",children:O?e.jsx(de,{options:[{value:"user",label:"User"},{value:"admin",label:"Admin"}],value:s.role||"user",onChange:h=>G.mutate({id:s.id,role:h}),placeholder:"Role",label:"User Role",className:"w-28 h-8 text-xs"}):e.jsxs(ne,{value:s.role||"user",onValueChange:h=>G.mutate({id:s.id,role:h}),children:[e.jsx(ie,{className:"w-28 h-8 text-xs",children:e.jsx(le,{})}),e.jsxs(re,{children:[e.jsx(_,{value:"user",children:"User"}),e.jsx(_,{value:"admin",children:"Admin"})]})]})})]},s.id)}),!J&&X.length===0&&e.jsx(k,{children:e.jsx(l,{colSpan:7,className:"text-center py-8 text-muted-foreground",children:"No users found."})})]})]})})})})]}),x==="reports"&&e.jsxs("div",{className:"space-y-3",children:[W&&e.jsx("p",{className:"text-muted-foreground text-sm text-center py-8",children:"Loading reports..."}),!W&&L.length===0&&e.jsxs("div",{className:"text-center py-16 text-muted-foreground",children:[e.jsx(M,{className:"w-10 h-10 mx-auto mb-3 opacity-20"}),e.jsx("p",{className:"font-medium",children:"No reports yet"})]}),L.map(s=>e.jsx(te,{className:`border-border ${s.status==="pending"?"border-yellow-500/30":""}`,children:e.jsx(ae,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-1",children:[e.jsx(C,{variant:"outline",className:`text-xs ${Be[s.status]}`,children:s.status}),e.jsx(C,{variant:"outline",className:"text-xs",children:me[s.reason]||s.reason}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s.created_date?new Date(s.created_date).toLocaleDateString():""})]}),e.jsxs("p",{className:"text-sm",children:[e.jsx("span",{className:"font-semibold",children:s.reporter_name}),e.jsx("span",{className:"text-muted-foreground",children:" reported "}),e.jsx("span",{className:"font-semibold text-destructive",children:s.reported_user_name})]}),s.post_content_excerpt&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1 bg-secondary/40 rounded-lg px-3 py-2 line-clamp-2",children:['"',s.post_content_excerpt,'"']}),s.details&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Details: ",s.details]}),s.admin_notes&&e.jsxs("p",{className:"text-xs text-blue-400 mt-1 italic",children:["Admin: ",s.admin_notes]})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[s.status==="pending"&&e.jsxs(e.Fragment,{children:[e.jsxs(a,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1",onClick:()=>{N(s),B(s.admin_notes||"")},children:[e.jsx(ke,{className:"w-3 h-3"})," Review"]}),e.jsx(a,{size:"sm",variant:"outline",className:"h-7 text-xs gap-1 text-muted-foreground",onClick:()=>m.mutate({id:s.id,status:"dismissed",admin_notes:""}),children:"Dismiss"})]}),s.status==="reviewed"&&e.jsxs(a,{size:"sm",variant:"destructive",className:"h-7 text-xs gap-1",onClick:()=>m.mutate({id:s.id,status:"actioned",admin_notes:f||s.admin_notes}),children:[e.jsx(j,{className:"w-3 h-3"})," Take Action"]}),s.status==="actioned"&&e.jsxs(C,{className:"bg-destructive/20 text-destructive text-xs gap-1",children:[e.jsx(Ae,{className:"w-3 h-3"})," Actioned"]})]})]})})},s.id))]}),e.jsx(I,{open:!!r,onOpenChange:s=>!s&&v(null),children:e.jsxs(q,{className:"max-w-sm",children:[e.jsx(z,{children:e.jsxs(E,{className:"flex items-center gap-2 text-base text-destructive",children:[e.jsx(j,{className:"w-4 h-4"})," Block User from Community"]})}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["This will suspend ",e.jsx("span",{className:"font-semibold text-foreground",children:(r==null?void 0:r.full_name)||(r==null?void 0:r.email)})," from all community features (Goby Chat, Deep Diver)."]}),e.jsx(ce,{placeholder:"Reason for blocking (internal admin note)...",value:V,onChange:s=>A(s.target.value),rows:3,className:"text-sm resize-none"}),e.jsxs("div",{className:"flex gap-2 justify-end",children:[e.jsx(a,{variant:"outline",size:"sm",onClick:()=>v(null),children:"Cancel"}),e.jsxs(a,{size:"sm",variant:"destructive",className:"gap-1.5",disabled:b.isPending,onClick:()=>b.mutate({id:r.id,is_blocked:!0,block_reason:V}),children:[e.jsx(j,{className:"w-3.5 h-3.5"}),b.isPending?"Blocking...":"Block User"]}
1)]})]})}),e.jsx(I,{open:!!c,onOpenChange:s=>!s&&N(null),children:e.jsxs(q,{className:"max-w-sm",children:[e.jsx(z,{children:e.jsxs(E,{className:"flex items-center gap-2 text-base",children:[e.jsx(M,{className:"w-4 h-4 text-destructive"})," Review Report"]})}),c&&e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-sm",children:["Report against ",e.jsx("span",{className:"font-semibold text-destructive",children:c.reported_user_name}),e.jsx("span",{className:"text-muted-foreground",children:" for "}),e.jsx("span",{className:"font-medium",children:me[c.reason]})]}),c.post_content_excerpt&&e.jsxs("p",{className:"text-xs text-muted-foreground bg-secondary/40 rounded-lg px-3 py-2",children:['"',c.post_content_excerpt,'"']}),e.jsx(ce,{placeholder:"Admin notes (optional)...",value:f,onChange:s=>B(s.target.value),rows:2,className:"text-sm resize-none"}),e.jsxs("div",{className:"flex gap-2 justify-end flex-wrap",children:[e.jsx(a,{variant:"outline",size:"sm",onClick:()=>N(null),children:"Cancel"}),e.jsx(a,{size:"sm",variant:"outline",disabled:m.isPending,onClick:()=>m.mutate({id:c.id,status:"dismissed",admin_notes:f}),children:"Dismiss"}),e.jsxs(a,{size:"sm",variant:"destructive",className:"gap-1.5",disabled:m.isPending,onClick:()=>m.mutate({id:c.id,status:"actioned",admin_notes:f}),children:[e.jsx(j,{className:"w-3.5 h-3.5"})," Action & Block"]})]})]})]})}),e.jsx(I,{open:ue,onOpenChange:g,children:e.jsxs(q,{className:"max-w-sm",children:[e.jsx(z,{children:e.jsx(E,{className:"font-display",children:"Invite New User"})}),e.jsxs("form",{onSubmit:ve,className:"space-y-4 mt-2",children:[e.jsxs("div",{children:[e.jsx(S,{children:"Email Address"}),e.jsx(w,{type:"email",value:R,onChange:s=>K(s.target.value),required:!0,placeholder:"[email protected]"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{children:[e.jsx(S,{children:"City (optional)"}),e.jsx(w,{value:he,onChange:s=>P(s.target.value),placeholder:"e.g. Los Angeles"})]}),e.jsxs("div",{children:[e.jsx(S,{children:"Country (optional)"}),e.jsx(w,{value:pe,onChange:s=>Q(s.target.value),placeholder:"e.g. US"})]})]}),e.jsxs("div",{children:[e.jsx(S,{children:"Role"}),O?e.jsx(de,{options:[{value:"user",label:"User"},{value:"admin",label:"Admin"}],value:D,onChange:T,placeholder:"Select role",label:"User Role"}):e.jsxs(ne,{value:D,onValueChange:T,children:[e.jsx(ie,{children:e.jsx(le,{})}),e.jsxs(re,{children:[e.jsx(_,{value:"user",children:"User"}),e.jsx(_,{value:"admin",children:"Admin"})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(a,{type:"button",variant:"outline",onClick:()=>g(!1),children:"Cancel"}),e.jsx(a,{type:"submit",disabled:$,children:$?"Sending...":"Send Invite"})]})]})]})})]})}export{Ke 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.