1import{c as ae,u as te,K as re,b as ne,g as ie,r as l,s as d,j as e,a2 as le,B as h,ad as de,M as ce,C as c,y as C,z,a as o,Q as oe,R as me,U as F,aD as X,V as q,h as f,I as xe,L as v,aq as he,ar as ue,as as pe,at as je,au as ge,N as fe,av as ve,aw as Ne,ax as ye}from"./index-DO0ZNUzu.js";import{S as _e,a as we,b as be,c as Ce,d as D}from"./select-Tn3h6yZZ.js";import{B as De}from"./Breadcrumb-Dk4aQzCY.js";import{H as Se}from"./house-CUUNLlcb.js";import{C as S}from"./circle-check-big-DrR00IgM.js";import{B}from"./ban-DvBkHTME.js";import{C as Be}from"./circle-x-DzZoUJG4.js";import{C as Ue}from"./calendar-Dodd1r6N.js";import"./check-Cyw8qn0D.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const Ae=ae("UserX",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"17",x2:"22",y1:"8",y2:"13",key:"3nzzx3"}],["line",{x1:"22",x2:"17",y1:"8",y2:"13",key:"1swrse"}]]),qe=()=>{const{user:u}=te(),{isAdmin:p,loading:U}=re(),A=ne(),{toast:i}=ie(),[$,H]=l.useState(!0),[P,W]=l.useState([]),[K,Q]=l.useState([]),[Y,R]=l.useState(!1),[k,I]=l.useState(null),[N,M]=l.useState(""),[x,E]=l.useState("7");l.useEffect(()=>{!U&&!p&&(A("/admin/dashboard"),i({title:"Access Denied",description:"You must be an admin to access this page",variant:"destructive"}))},[p,U,A]),l.useEffect(()=>{p&&(V(),L())},[p]);const V=async()=>{H(!0);const{data:s,error:a}=await d.from("message_reports").select(` 7 *, 8 circle_messages ( 9 message, 10 user_id, 11 circle_id 12 ) 13 `).order("created_at",{ascending:!1});if(a)console.error("Error fetching reports:",a),i({title:"Error",description:"Failed to load reports",variant:"destructive"});else{const t=[...new Set(s==null?void 0:s.map(n=>n.reporter_id))],m=[...new Set(s==null?void 0:s.map(n=>{var g;return(g=n.circle_messages)==null?void 0:g.user_id}))],b=[...new Set([...t,...m])],{data:j}=await d.from("profiles").select("user_id, display_name").in("user_id",b),r=new Map((j==null?void 0:j.map(n=>[n.user_id,n]))||[]),se=(s==null?void 0:s.map(n=>{var g,O;return{...n,reporter_profile:r.get(n.reporter_id),message_author_profile:{...r.get((g=n.circle_messages)==null?void 0:g.user_id),user_id:(O=n.circle_messages)==null?void 0:O.user_id}}}))||[];W(se)}H(!1)},L=async()=>{const{data:s,error:a}=await d.from("banned_users").select("*").order("banned_at",{ascending:!1});if(a)console.error("Error fetching banned users:",a);else{const t=[...new Set(s==null?void 0:s.map(r=>[r.user_id,r.banned_by]).flat())],{data:m}=await d.from("profiles").select("user_id, display_name").in("user_id",t),b=new Map((m==null?void 0:m.map(r=>[r.user_id,r]))||[]),j=(s==null?void 0:s.map(r=>({...r,profiles:b.get(r.user_id),banner_profile:b.get(r.banned_by)})))||[];Q(j)}},T=async(s,a)=>{const{error:t}=await d.from("message_reports").update({status:a,reviewed_by:u==null?void 0:u.id,reviewed_at:new Date().toISOString()}).eq("id",s);t?i({title:"Error",description:"Failed to update report",variant:"destructive"}):(i({title:"Success",description:`Report ${a}`}),V())},G=async(s,a)=>{const{error:t}=await d.from("circle_messages").delete().eq("id",s);t?i({title:"Error",description:"Failed to delete message",variant:"destructive"}):(await T(a,"actioned"),i({title:"Success",description:"Message deleted successfully"}))},J=async()=>{if(!(!k||!N.trim()||!u))try{const s=x==="permanent"?null:new Date(Date.now()+parseInt(x)*24*60*60*1e3).toISOString(),{error:a}=await d.from("banned_users").insert({user_id:k,banned_by:u.id,reason:N,expires_at:s,is_permanent:x==="permanent"});if(a)throw a;await d.from("circle_members").delete().eq("user_id",k),i({title:"User Banned",description:`User has been banned ${x==="permanent"?"permanently":`for ${x} days`}`}),R(!1),I(null),M(""),E("7"),L()}catch(s){i({title:"Error",description:s.message||"Failed to ban user",variant:"destructive"})}},Z=async s=>{const{error:a}=await d.from("banned_users").delete().eq("id",s);a?i({title:"Error",description:"Failed to unban user",variant:"destructive"}):(i({title:"Success",description:"User has been unbanned"}),L())},ee=s=>{I(s),R(!0)};if(U||$)return e.jsx(le,{});if(!p)return null;const y=P.filter(s=>s.status==="pending"),_=P.filter(s=>s.status!=="pending"),w=K.filter(s=>s.is_permanent||s.expires_at&&new Date(s.expires_at)>new Date);return e.jsxs("div",{className:"min-h-screen bg-gradient-to-b from-background to-secondary/20 p-6",children:[e.jsxs("div",{className:"max-w-7xl mx-auto
13space-y-6",children:[e.jsx(De,{items:[{label:"Admin",href:"/admin/dashboard"},{label:"Moderation",href:"/admin/moderation"}],className:"mb-4"}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(h,{variant:"outline",size:"icon",onClick:()=>A("/admin/dashboard"),children:e.jsx(Se,{className:"h-4 w-4"})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold text-foreground flex items-center gap-2",children:[e.jsx(de,{className:"h-8 w-8 text-primary"}),"Community Moderation"]}),e.jsx("p",{className:"text-muted-foreground",children:"Review reports and manage community safety"})]}),e.jsx(ce,{})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs(c,{children:[e.jsx(C,{className:"pb-3",children:e.jsx(z,{className:"text-sm font-medium",children:"Pending Reports"})}),e.jsxs(o,{children:[e.jsx("div",{className:"text-2xl font-bold",children:y.length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Awaiting review"})]})]}),e.jsxs(c,{children:[e.jsx(C,{className:"pb-3",children:e.jsx(z,{className:"text-sm font-medium",children:"Active Bans"})}),e.jsxs(o,{children:[e.jsx("div",{className:"text-2xl font-bold",children:w.length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Currently banned"})]})]}),e.jsxs(c,{children:[e.jsx(C,{className:"pb-3",children:e.jsx(z,{className:"text-sm font-medium",children:"Total Reviewed"})}),e.jsxs(o,{children:[e.jsx("div",{className:"text-2xl font-bold",children:_.length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"All time"})]})]})]}),e.jsxs(oe,{defaultValue:"pending",className:"space-y-6",children:[e.jsxs(me,{className:"flex w-full overflow-x-auto justify-start sm:grid sm:grid-cols-3",children:[e.jsxs(F,{value:"pending",children:[e.jsx(X,{className:"h-4 w-4 mr-2"}),"Pending (",y.length,")"]}),e.jsxs(F,{value:"reviewed",children:[e.jsx(S,{className:"h-4 w-4 mr-2"}),"Reviewed (",_.length,")"]}),e.jsxs(F,{value:"banned",children:[e.jsx(B,{className:"h-4 w-4 mr-2"}),"Banned Users (",w.length,")"]})]}),e.jsx(q,{value:"pending",className:"space-y-4",children:y.length===0?e.jsx(c,{children:e.jsxs(o,{className:"py-12 text-center",children:[e.jsx(S,{className:"w-12 h-12 mx-auto mb-4 text-green-500"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"All Clear!"}),e.jsx("p",{className:"text-muted-foreground",children:"No pending reports to review"})]})}):y.map(s=>{var a,t,m;return e.jsxs(c,{className:"border-orange-200 dark:border-orange-900",children:[e.jsx(C,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{variant:"destructive",children:s.status}),e.jsx(f,{variant:"outline",children:new Date(s.created_at).toLocaleDateString()})]}),e.jsxs(xe,{children:["Reported by: ",((a=s.reporter_profile)==null?void 0:a.display_name)||"Unknown User"]})]}),e.jsx(X,{className:"w-5 h-5 text-orange-500"})]})}),e.jsxs(o,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(v,{className:"text-sm font-medium",children:"Reported Message:"}),e.jsxs("div",{className:"mt-2 bg-secondary/50 p-4 rounded-lg",children:[e.jsx("p",{className:"text-sm",children:s.circle_messages.message}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["Author: ",((t=s.message_author_profile)==null?void 0:t.display_name)||"Unknown"]})]})]}),e.jsxs("div",{children:[e.jsx(v,{className:"text-sm font-medium",children:"Report Reason:"}),e.jsx("p",{className:"mt-1 text-sm",children:s.reason})]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>G(s.message_id,s.id),children:[e.jsx(Be,{className:"w-4 h-4 mr-2"}),"Delete Message"]}),((m=s.message_author_profile)==null?void 0:m.user_id)&&e.jsxs(h,{variant:"destructive",size:"sm",onClick:()=>ee(s.message_author_profile.user_id),children:[e.jsx(B,{className:"w-4 h-4 mr-2"}),"Ban User"]}),e.jsx(h,{variant:"outline",size:"sm",onClick:()=>T(s.id,"dismissed"),children:"Dismiss"}),e.jsxs(h,{variant:"secondary",size:"sm",onClick:()=>T(s.id,"reviewed"),children:[e.jsx(S,{className:"w-4 h-4 mr-2"}),"Mark Reviewed"]})]})]})]},s.id)})}),e.jsx(q,{value:"reviewed",className:"space-y-4",children:_.length===0?e.jsx(c,{children:e.jsx(o,{className:"py-12 text-center",children:e.jsx("p",{className:"text-muted-foreground",children:"No reviewed reports yet"})})}):_.map(s=>{var a;return e.jsx(c,{className:"opacity-75",children:e.jsxs(o,{className:"py-4",children:[e.jsx("div",{className:"flex items-start justify-between mb-3",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{variant:s.status==="actioned"?"destructive":s.status==="dism
13issed"?"secondary":"default",children:s.status}),e.jsx("span",{className:"text-sm text-muted-foreground",children:new Date(s.created_at).toLocaleDateString()})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Reported by: ",((a=s.reporter_profile)==null?void 0:a.display_name)||"Unknown"]})]})}),e.jsx("div",{className:"bg-secondary/30 p-3 rounded-lg mb-2",children:e.jsx("p",{className:"text-sm",children:s.circle_messages.message})}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Reason: ",s.reason]})]})},s.id)})}),e.jsx(q,{value:"banned",className:"space-y-4",children:w.length===0?e.jsx(c,{children:e.jsxs(o,{className:"py-12 text-center",children:[e.jsx(Ae,{className:"w-12 h-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"No banned users"})]})}):w.map(s=>{var a,t;return e.jsx(c,{children:e.jsxs(o,{className:"py-4",children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("h4",{className:"font-semibold",children:((a=s.profiles)==null?void 0:a.display_name)||"Unknown User"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(f,{variant:s.is_permanent?"destructive":"secondary",children:s.is_permanent?"Permanent Ban":"Temporary Ban"}),!s.is_permanent&&s.expires_at&&e.jsxs(f,{variant:"outline",children:[e.jsx(Ue,{className:"h-3 w-3 mr-1"}),"Expires: ",new Date(s.expires_at).toLocaleDateString()]})]})]}),e.jsx(B,{className:"w-5 h-5 text-destructive"})]}),e.jsxs("div",{className:"bg-secondary/50 p-3 rounded-lg mb-3",children:[e.jsx(v,{className:"text-xs font-medium",children:"Ban Reason:"}),e.jsx("p",{className:"text-sm mt-1",children:s.reason})]}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground mb-3",children:[e.jsxs("span",{children:["Banned by: ",((t=s.banner_profile)==null?void 0:t.display_name)||"Unknown"]}),e.jsx("span",{children:new Date(s.banned_at).toLocaleDateString()})]}),e.jsxs(h,{variant:"outline",size:"sm",onClick:()=>Z(s.id),children:[e.jsx(S,{className:"w-4 h-4 mr-2"}),"Unban User"]})]})},s.id)})})]})]}),e.jsx(he,{open:Y,onOpenChange:R,children:e.jsxs(ue,{children:[e.jsxs(pe,{children:[e.jsx(je,{children:"Ban User from Community"}),e.jsx(ge,{children:"This will remove the user from all circles and prevent them from participating."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx(v,{htmlFor:"ban-reason",children:"Reason for Ban*"}),e.jsx(fe,{id:"ban-reason",value:N,onChange:s=>M(s.target.value),placeholder:"E.g., Harassment, spam, inappropriate content...",maxLength:500})]}),e.jsxs("div",{children:[e.jsx(v,{htmlFor:"ban-duration",children:"Ban Duration"}),e.jsxs(_e,{value:x,onValueChange:s=>E(s),children:[e.jsx(we,{id:"ban-duration",children:e.jsx(be,{})}),e.jsxs(Ce,{children:[e.jsx(D,{value:"7",children:"7 Days"}),e.jsx(D,{value:"30",children:"30 Days"}),e.jsx(D,{value:"90",children:"90 Days"}),e.jsx(D,{value:"permanent",children:"Permanent"})]})]})]})]}),e.jsxs(ve,{children:[e.jsx(Ne,{onClick:()=>{I(null),M(""),E("7")},children:"Cancel"}),e.jsxs(ye,{onClick:J,disabled:!N.trim(),className:"bg-destructive hover:bg-destructive/90",children:[e.jsx(B,{className:"w-4 h-4 mr-2"}),"Ban User"]})]})]})})]})};export{qe 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.