1import{r as o,j as s}from"./vendor-react-0BgUAC16.js";import{o as D,h as k,l as S,n as w,s as m,B as p,am as T,C as y,T as _,V as I,bh as A,m as R,e as E,a as q}from"./index-VBmyz7oY.js";import{T as O,a as L,b as j}from"./tabs-DSMQ77q6.js";import{D as M}from"./useReportDiscussion-DBvoJTvP.js";import{F as B}from"./flag-CfWP4QDB.js";import{f as F}from"./formatDistanceToNow-DDuw621S.js";import"./vendor-shared-C4h37-Rp.js";import"./vendor-sentry-hvZPoHao.js";import"./vendor-animation-t_MKAynu.js";import"./useOptionalAuthUser-Ct_G3XUm.js";import"./en-US-D2y9esxB.js";import"./differenceInCalendarMonths-C9ZM_RdW.js";import"./endOfMonth-DjTYojOR.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"harley-ai@1791200088371"};var t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]="1932763f-0381-4936-969f-76c91e8b78cd",e._sentryDebugIdIdentifier="sentry-dbid-1932763f-0381-4936-969f-76c91e8b78cd")}catch{}})();const Q=e=>{var t;return((t=M.find(d=>d.value===e))==null?void 0:t.label)??e},K=e=>R({queryKey:["admin-discussion-reports",e],queryFn:async()=>{const{data:t,error:d}=await m.from("discussion_reports").select("id, discussion_id, reporter_id, reason, details, status, created_at").eq("status",e).order("created_at",{ascending:!1}).limit(200);if(d)throw d;if(!t||t.length===0)return[];const{data:i}=await m.from("topic_discussions").select("id, content, user_id").in("id",t.map(a=>a.discussion_id)),u=new Map((i==null?void 0:i.map(a=>[a.id,a]))??[]),l=[...new Set([...t.map(a=>a.reporter_id),...(i==null?void 0:i.map(a=>a.user_id))??[]])],{data:c}=await m.rpc("get_public_profiles_by_ids",{p_user_ids:l}),h=new Map((c==null?void 0:c.map(a=>[a.id,a]))??[]);return t.map(a=>{var f,b;const r=u.get(a.discussion_id);return{id:a.id,discussionId:a.discussion_id,reason:a.reason,details:a.details,status:a.status,createdAt:a.created_at,commentContent:(r==null?void 0:r.content)??null,commentDeleted:!r,authorName:r?((f=h.get(r.user_id))==null?void 0:f.full_name)??"Anonymous":null,reporterName:((b=h.get(a.reporter_id))==null?void 0:b.full_name)??"Anonymous"}})},staleTime:3e4}),P=({report:e,onResolve:t,onDeleteComment:d,isPending:i})=>{const u=o.useCallback(()=>{t({id:e.id,status:"dismissed"})},[t,e.id]),l=o.useCallback(()=>{t({id:e.id,status:"actioned"})},[t,e.id]),c=o.useCallback(()=>{d({id:e.id,discussionId:e.discussionId})},[d,e.id,e.discussionId]);return s.jsxs(y,{children:[s.jsx(_,{className:"pb-3",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(E,{variant:"secondary",children:Q(e.reason)}),s.jsxs("span",{className:"text-xs text-muted-foreground",children:["reported by ",e.reporterName,","," ",F(new Date(e.createdAt),{addSuffix:!0})]})]})}),s.jsxs(q,{className:"space-y-3",children:[e.commentDeleted?s.jsx("p",{className:"text-sm italic text-muted-foreground",children:"This comment has already been deleted."}):s.jsxs("div",{className:"rounded-lg border border-border bg-muted/40 p-3",children:[s.jsx("p",{className:"text-xs font-medium text-muted-foreground",children:e.authorName}),s.jsx("p",{className:"mt-1 whitespace-pre-wrap break-words text-sm text-foreground",children:e.commentContent})]}),e.details&&s.jsxs("p",{className:"text-sm text-muted-foreground",children:[s.jsx("span",{className:"font-medium text-foreground",children:"Reporter said: "}),e.details]}),e.status==="open"&&s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(p,{variant:"outline",className:"min-h-[44px]",onClick:u,disabled:i,children:"Dismiss"}),!e.commentDeleted&&s.jsx(p,{variant:"destructive",className:"min-h-[44px]",onClick:c,disabled:i,children:"Delete comment"}),s.jsx(p,{className:"min-h-[44px]",onClick:l,disabled:i,children:"Mark actioned"})]})]})]})},ae=()=>{const e=D(),{user:t}=k(),d=S(),[i,u]=o.useState("open"),{data:l=[],isLoading:c}=K(i),h=()=>{d.invalidateQueries({queryKey:["admin-discussion-reports"]})},a=w({mutationFn:async({id:n,status:g})=>{const{error:x}=await m.from("discussion_reports").update({status:g,reviewed_by:(t==null?void 0:t.id)??null,reviewed_at:new Date().toISOString()}).eq("id",n);if(x)throw x},onSuccess:h}),r=w({mutationFn:async({id:n,discussionId:g})=>{const{error:x}=await m.from("topic_discussions").delete().eq("id",g);if(x)throw x;await m.from("discussion_reports").update({status:"actioned",reviewed_by:(t==null?void 0:t.id)??null,reviewed_at:new Date().toISOString()}).eq("id",n)},onSuccess:h}),f=o.useCallback(n=>{a.mutate(n)},[a]),b=o.useCallback(n=>{r.mutate(n)},[r]),N=o.useCallback(n=>{u(n)},[]),C=o.useCallback(()=>{e("/admin")},[e]),v=o.useCallback(()=>{e("/admin/ai-reports")},[e]);return s.jsxs("div",{className:"mx-auto w-full max-w-3xl space-y-6 p-4 sm:p-6",children:[s.jsxs(p,{variant:"ghost",className:"min-h-[44px] -ml-2",onClick:C,children:[s.jsx(T,{className:"mr-2 h-4 w-4"}),"Back to admin"]}),s.jsx(p,{variant:"outline",className:"ml-2 min-h-[44px]",onClick:v,children:"AI reports"}),s.jsxs("div",{children:[s.jsxs("h1",{className:"flex items-center gap-2 text-2xl font-bold uppercase tracking-wide text-harley-navy",children:[s.jsx(B,{className:"h-5 w-5"}),"Reported comments"]}),s.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Community reports raised by members. Review each one and decide whether the comment stays."})]}),s.jsx(O,{value:i,onValueChange:N,children:s.jsxs(L,{children:[s.jsx(j,{value:"open",children:"Open"}),s.jsx(j,{value:"actioned",children:"Actioned"}),s.jsx(j,{value:"dismissed",children:"Dismissed"})]})}),c&&s.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading reports..."}),!c&&l.length===0&&s.jsx(y,{children:s.jsxs(_,{children:[s.jsx(I,{className:"text-base",children:"Nothing here"}),s.jsxs(A,{children:["There are no ",i," reports at the moment."]})]})}),s.jsx("div",{className:"space-y-4",children:l.map(n=>s.jsx(P,{report:n,onResolve:f,onDeleteComment:b,isPending:a.isPending||r.isPending},n.id))})]})};export{ae 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.