1import{b as B,r as u,j as e}from"./index-MMs8uNES.js";import{u as F}from"./useQuery-unwT2NKV.js";import{u as x}from"./useMutation-CLdHhkMg.js";import{A as O}from"./AuthenticatedShell-DvfH5s-P.js";import"./globe-BybOCho1.js";import"./building-2-B3Zz-zja.js";import"./briefcase-Cp-VKCfX.js";import"./calendar-EsCIARLH.js";import"./users-BKxJQ7iG.js";import"./sparkles-D5qMvRxh.js";import"./x-BuDFMjbf.js";import"./user-CZIYOn4l.js";import"./search-ByVesLSG.js";import"./circle-question-mark-DC_SsNaE.js";const l="/api";function Y(){var C;const d=B(),[p,q]=u.useState({}),[S,h]=u.useState(null),[i,c]=u.useState(new Set),[k,A]=u.useState(""),{data:b,isLoading:y,error:$}=F({queryKey:["moderation-queue"],queryFn:async()=>{const t=localStorage.getItem("token"),s=await fetch(`${l}/admin/moderation/queue`,{headers:{Authorization:`Bearer ${t}`}});if(!s.ok)throw new Error(s.status===401?"401 Unauthorized â session expired":"Failed to fetch moderation queue");return s.json()}}),j=x({mutationFn:async({id:t,notes:s})=>{const n=localStorage.getItem("token"),a=await fetch(`${l}/admin/moderation/${t}/approve`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({notes:s})});if(!a.ok)throw new Error("Approval failed");return a.json()},onSuccess:()=>d.invalidateQueries({queryKey:["moderation-queue"]})}),f=x({mutationFn:async({id:t,reason:s})=>{const n=localStorage.getItem("token"),a=await fetch(`${l}/admin/moderation/${t}/reject`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({reason:s})});if(!a.ok)throw new Error("Rejection failed");return a.json()},onSuccess:()=>d.invalidateQueries({queryKey:["moderation-queue"]})}),z=x({mutationFn:async t=>{h(t);const s=localStorage.getItem("token"),n=await fetch(`${l}/admin/moderation/${t}/analyze`,{method:"POST",headers:{Authorization:`Bearer ${s}`}});if(!n.ok)throw new Error("Analysis failed");return n.json()},onSuccess:()=>{h(null),d.invalidateQueries({queryKey:["moderation-queue"]})},onError:()=>h(null)}),r=x({mutationFn:async()=>{const t=localStorage.getItem("token"),s=await fetch(`${l}/admin/moderation/batch?limit=10`,{method:"POST",headers:{Authorization:`Bearer ${t}`}});if(!s.ok)throw new Error("Batch moderation failed");return s.json()},onSuccess:()=>d.invalidateQueries({queryKey:["moderation-queue"]})}),N=x({mutationFn:async t=>{const s=localStorage.getItem("token"),n=await fetch(`${l}/admin/moderation/bulk-approve`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify({ids:t})});if(!n.ok)throw new Error("Bulk approval failed");return n.json()},onSuccess:()=>{c(new Set),d.invalidateQueries({queryKey:["moderation-queue"]})}}),v=x({mutationFn:async({ids:t,reason:s})=>{const n=localStorage.getItem("token"),a=await fetch(`${l}/admin/moderation/bulk-reject`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n}`},body:JSON.stringify({ids:t,reason:s})});if(!a.ok)throw new Error("Bulk rejection failed");return a.json()},onSuccess:()=>{c(new Set),A(""),d.invalidateQueries({queryKey:["moderation-queue"]})}}),o=(b==null?void 0:b.data)||[],P=t=>{c(s=>{const n=new Set(s);return n.has(t)?n.delete(t):n.add(t),n})},I=()=>{i.size===o.length?c(new Set):c(new Set(o.map(t=>t.listing.id)))},g=t=>t>=80?"text-green-600 bg-green-100":t>=50?"text-yellow-600 bg-yellow-100":"text-red-600 bg-red-100",J=t=>t==="approve"?"bg-green-100 text-green-800":t==="review"?"bg-yellow-100 text-yellow-800":"bg-red-100 text-red-800";return e.jsx(O,{children:e.jsx("div",{className:"min-h-screen bg-gray-50",children:e.jsxs("div",{className:"max-w-7xl mx-auto px-4 py-8",children:[e.jsxs("div",{className:"flex justify-between items-start mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-gray-900",children:"Moderation Queue"}),e.jsx("p",{className:"text-gray-600 mt-2",children:"Review and approve pending listings"})]}),e.jsx("button",{onClick:()=>r.mutate(),disabled:r.isPending,className:"bg-blue-600 text-white px-4 py-2 rounded-lg hover:bg-blue-700 disabled:opacity-50 flex items-center gap-2",children:r.isPending?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"animate-spin",children:"..."}),"Running AI Analysis..."]}):e.jsx(e.Fragment,{children:"Run Batch AI Analysis"})})]}),r.isSuccess&&((C=r.data)==null?void 0:C.data)&&e.jsx("div",{className:"mb-6 p-4 bg-blue-50 border border-blue-200 rounded-lg",children:e.jsxs("p",{className:"text-blue-800",children:["Batch analysis complete: ",r.data.data.processed," processed, "," ",r.data.data.approved," auto-approved, "," ",r.data.data.flagged," flagged for review"]})}),y&&e.jsx("div",{className:"text-center py-12",children:"Loading..."}),$&&e.jsx("div",{className:"bg-red-50 border border-red-200 rounded-lg p-4 text-red-800",children:"Failed to load moderation queue. Please try again."}),!y&&!$&&o.length===0&&e.jsxs("div",{className:"bg-white rounded-lg shadow p-12 text-center",children:[e.jsx("div",{className:"text-6xl mb-4",children:"All caught up!"}),e.jsx("h2",{className:"text-2xl font-bold text-gray-900 mb-2",children:"No pending listings"}),e.jsx("p",{className:"text-gray-600",children:"All listings have been reviewed"})]}),!y&&o.length>0&&e.jsxs("div",{className:"space-y-6",children:[i.size>0&&e.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-lg p-4 flex items-center justify-between sticky top-0 z-10",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("span",{className:"text-blue-800 font-medium",children:[i.size," listing",i.size>1?"s":""," selected"]}),e.jsx("button",{onClick:()=>c(new Set),className:"text-blue-600 hover:text-blue-800 text-sm underline",children:"Clear selection"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("input",{type:"text",value:k,onChange:t=>A(t.target.value),placeholder:"Rejection reason (optional)",className:"px-3 py-2 border rounded-lg text-sm w-64"}),e.jsx("button",{onClick:()=>v.mutate({ids:Array.from(i),reason:k}),disabled:v.isPending,className:"bg-red-600 text-white px-4 py-2 rounded-lg hover:bg-red-700 disabled:opacity-50 text-sm font-medium",children:v.isPending?"Rejecting...":`Reject ${i.size}`}),e.jsx("button",{onClick:()=>N.mutate(Array.from(i)),disabled:N.isPending,className:"bg-green-600 text-white px-4 py-2 rounded-lg hover:bg-green-700 disabled:opacity-50 text-sm font-medium",children:N.isPending?"Approving...":`Approve ${i.size}`})]})]}),e.jsx("div",{className:"flex items-center gap-3 mb-2",children:e.jsxs("label",{className:"flex items-center gap-2 text-sm text-gray-600 cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:i.size===o.length&&o.length>0,onChange:I,className:"w-4 h-4 rounded border-gray-300 text-blue-600 focus:ring-blue-500"}
1),"Select all (",o.length,")"]})}),o.map(t=>{var s,n,a,R;return e.jsxs("div",{className:"bg-white rounded-lg shadow p-6",children:[e.jsxs("div",{className:"flex justify-between items-start mb-4",children:[e.jsxs("div",{className:"flex items-start gap-4 flex-1",children:[e.jsx("input",{type:"checkbox",checked:i.has(t.listing.id),onChange:()=>P(t.listing.id),className:"mt-1 w-5 h-5 rounded border-gray-300 text-blue-600 focus:ring-blue-500"}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-2",children:[e.jsx("h3",{className:"text-xl font-bold text-gray-900",children:t.listing.title}),e.jsx("span",{className:"px-2 py-1 bg-blue-100 text-blue-800 text-xs font-semibold rounded uppercase",children:t.listing.type})]}),t.creator&&e.jsxs("p",{className:"text-sm text-gray-500 mb-3",children:["Submitted by: ",t.creator.name||t.creator.email]}),e.jsx("p",{className:"text-gray-700 mb-4",children:t.listing.summary||((s=t.listing.descriptionRich)==null?void 0:s.slice(0,200))||"No description provided"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[t.listing.website&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Website:"})," ",e.jsx("a",{href:t.listing.website,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline",children:t.listing.website})]}),(t.listing.city||t.listing.country)&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Location:"})," ",[t.listing.city,t.listing.country].filter(Boolean).join(", ")]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Submitted:"})," ",new Date(t.listing.createdAt).toLocaleDateString()]}),((n=t.listing.cryptoAccepted)==null?void 0:n.length)>0&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium",children:"Crypto:"})," ",t.listing.cryptoAccepted.join(", ")]})]}),((a=t.listing.tags)==null?void 0:a.length)>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("span",{className:"font-medium text-sm",children:"Tags: "}),t.listing.tags.map((m,w)=>e.jsx("span",{className:"inline-block bg-gray-100 text-gray-700 text-xs px-2 py-1 rounded mr-1",children:m},w))]}),((R=t.listing.spamFlags)==null?void 0:R.length)>0&&e.jsxs("div",{className:"mt-4 p-3 bg-red-50 border border-red-200 rounded-lg",children:[e.jsx("span",{className:"font-medium text-red-800 text-sm",children:"Flags: "}),t.listing.spamFlags.map((m,w)=>e.jsx("span",{className:"inline-block bg-red-100 text-red-700 text-xs px-2 py-1 rounded mr-1",children:m},w))]})]})]}),e.jsx("div",{className:"ml-6 min-w-[200px]",children:t.listing.moderationScoresJson?e.jsxs("div",{className:"bg-gray-50 rounded-lg p-4 border",children:[e.jsx("h4",{className:"font-semibold text-sm text-gray-700 mb-3",children:"AI Analysis"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-xs text-gray-600",children:"Overall"}),e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-bold ${g(t.listing.moderationScoresJson.overall)}`,children:t.listing.moderationScoresJson.overall})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-xs text-gray-600",children:"Spam"}),e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-bold ${g(t.listing.moderationScoresJson.spam)}`,children:t.listing.moderationScoresJson.spam})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-xs text-gray-600",children:"Quality"}),e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-bold ${g(t.listing.moderationScoresJson.quality)}`,children:t.listing.moderationScoresJson.quality})]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-xs text-gray-600",children:"Policy"}),e.jsx("span",{className:`px-2 py-0.5 rounded text-xs font-bold ${g(t.listing.moderationScoresJson.policy)}`,children:t.listing.moderationScoresJson.policy})]})]}),e.jsx("div",{className:"mt-3 pt-3 border-t",children:e.jsx("span",{className:`px-2 py-1 rounded text-xs font-bold ${J(t.listing.moderationScoresJson.recommendation)}`,children:t.listing.moderationScoresJson.recommendation.toUpperCase()})})]}):e.jsx("button",{onClick:()=>z.mutate(t.listing.id),disabled:S===t.listing.id,className:"w-full bg-gray-100 text-gray-700 px-4 py-3 rounded-lg hover:bg-gray-200 disabled:opacity-50 text-sm",children:S===t.listing.id?"Analyzing...":"Run AI Analysis"})})]}),e.jsx("div",{className:"pt-4 border-t",children:e.jsxs("div",{className:"flex gap-3",children:[e.jsx("button",{onClick:()=>j.mutate({id:t.listing.id}),disabled:j.isPending||f.isPending,className:"flex-1 bg-green-600 text-white px-6 py-3 rounded-lg hover:bg-green-700 disabled:opacity-50 font-medium",children:"Approve"}),e.jsxs("div",{className:"flex-1 flex gap-2",children:[e.jsx("input",{type:"text",placeholder:"Rejection reason (optional)",value:p[t.listing.id]||"",onChange:m=>q({...p,[t.listing.id]:m.target.value}),className:"flex-1 px-3 py-2 border border-gray-300 rounded-lg text-sm"}),e.jsx("button",{onClick:()=>f.mutate({id:t.listing.id,reason:p[t.listing.id]}),disabled:j.isPending||f.isPending,className:"bg-red-600 text-white px-6 py-3 rounded-lg hover:bg-red-700 disabled:opacity-50 font-medium",children:"Reject"})]})]})})]},t.listing.id)})]})]})})})}export{Y as Moderation};
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.