1import{w as le,r as g,V as ne,ai as v,j as e,B as x,Y as ce,a3 as de,a4 as oe,aZ as C,a_ as f,a$ as T,b0 as A,b1 as i,$ as ue,as as xe,at as he,au as K,av as r,aw as me,ax as l,aJ as R,bg as F,X as je,aK as D,aL as P,aM as B,aN as E,aO as M,aP as k,aQ as L,g as pe,K as ge,C as ve,O as S,aR as Se}from"./index-BA-hDO3C.js";import{B as z}from"./badge-BmS2sdGI.js";import{T as be}from"./TriggerReviewButton-DgCW6cm1.js";import{S as we}from"./shield-BxDR8zf3.js";import{R as Q}from"./refresh-cw-Bjqttn03.js";import{C as ye}from"./chevron-left-CJuQnFIJ.js";import"./popover-BZcGkHPI.js";import"./format-CW0G_LzU.js";import"./play-BjufNzl7.js";const b={normal:{label:"Normal",variant:"secondary"},flagged:{label:"Flagged",variant:"default"},under_review:{label:"Under Review",variant:"destructive"},suspended:{label:"Suspended",variant:"destructive"}},Ne={pending:{label:"Pending",variant:"outline"},applied:{label:"Applied",variant:"default"},rejected:{label:"Rejected",variant:"secondary"}},Ce=[{value:"flagged",label:"Flagged"},{value:"under_review",label:"Under Review"},{value:"suspended",label:"Suspended"}];function w(){Se.invalidateQueries({predicate:a=>{var d;return((d=a.queryKey[0])==null?void 0:d.toString().startsWith("/api/bot-security/flags"))??!1}})}function Me(){var V;const{toast:a}=le(),[d,G]=g.useState("all"),[y,W]=g.useState("all"),[o,m]=g.useState(1),j=20,[J,X]=g.useState({}),Y=()=>{const s=new URLSearchParams;return d!=="all"&&s.set("status",d),y!=="all"&&s.set("date",y),s.set("page",o.toString()),s.set("pageSize",j.toString()),s.toString()},{data:n,isLoading:Z,refetch:I}=ne({queryKey:[`/api/bot-security/flags?${Y()}`]}),U=v({mutationFn:async s=>S("POST",`/api/bot-security/bots/${s}/reinstate`),onSuccess:s=>{a({title:"Bot Reinstated",description:s.message}),w()},onError:()=>{a({title:"Error",description:"Failed to reinstate bot",variant:"destructive"})}}),O=v({mutationFn:async s=>S("POST",`/api/bot-security/flags/${s}/reject`),onSuccess:()=>{a({title:"Flag Rejected",description:"The flag has been dismissed"}),w()},onError:()=>{a({title:"Error",description:"Failed to reject flag",variant:"destructive"})}}),_=v({mutationFn:async({flagId:s,status:t})=>S("POST",`/api/bot-security/flags/${s}/apply`,{status:t}),onSuccess:s=>{a({title:"Status Applied",description:s.message}),w()},onError:()=>{a({title:"Error",description:"Failed to apply status",variant:"destructive"})}}),$=v({mutationFn:async s=>S("POST","/api/bot-security/force-review",s?{date:s}:{}),onSuccess:s=>{a({title:"Review Complete",description:s.message}),w()},onError:()=>{a({title:"Error",description:"Failed to trigger review",variant:"destructive"})}}),ee=s=>{const t=s?s.toISOString().split("T")[0]:void 0;$.mutate(t)},se=(s,t)=>J[s]||t,te=(s,t)=>{X(c=>({...c,[s]:t}))},N=n?Math.ceil(n.total/j):0,ae=s=>new Date(s).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"});return e.jsxs("div",{className:"container mx-auto py-8 px-4",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(we,{className:"h-8 w-8 text-primary"}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Bot Security"}),e.jsx("p",{className:"text-muted-foreground",children:"Review flagged emails and manage bot statuses"})]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(be,{onTrigger:ee,isPending:$.isPending}),e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>I(),children:[e.jsx(Q,{className:"h-4 w-4 mr-2"}),"Refresh"]})]})]}),e.jsxs(ce,{children:[e.jsx(de,{className:"pb-4",children:e.jsxs("div",{className:"flex flex-col sm:flex-row gap-4 justify-between",children:[e.jsx(oe,{className:"text-lg",children:"Email Flags"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(C,{value:d,onValueChange:s=>{G(s),m(1)},children:[e.jsx(f,{className:"w-[150px]",children:e.jsx(T,{placeholder:"Status"})}),e.jsxs(A,{children:[e.jsx(i,{value:"all",children:"All Statuses"}),e.jsx(i,{value:"flagged",children:"Flagged"}),e.jsx(i,{value:"under_review",children:"Under Review"}),e.jsx(i,{value:"suspended",children:"Suspended"})]})]}),e.jsxs(C,{value:y,onValueChange:s=>{W(s),m(1)},children:[e.jsx(f,{className:"w-[150px]",children:e.jsx(T,{placeholder:"Date"})}),e.jsxs(A,{children:[e.jsx(i,{value:"all",children:"All Time"}),e.jsx(i,{value:"today",children:"Today"}),e.jsx(i,{value:"last7",children:"Last 7 Days"}),e.jsx(i,{value:"last30",children:"Last 30 Days"})]})]})]})]})}),e.jsx(ue,{children:Z?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(Q,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):(V=n==null?void 0:n.items)!=null&&V.length?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"rounded-md border",children:e.jsxs(xe,{children:[e.jsx(he,{children:e.jsxs(K,{children:[e.jsx(r,{children:"Bot"}),e.jsx(r,{children:"Email Subject"}),e.jsx(r,{children:"Reason"}),e.jsx(r,{children:"Suggested"}),e.jsx(r,{children:"Current Status"}),e.jsx(r,{children:"Flags"}),e.jsx(r,{children:"Date"}),e.jsx(r,{children:"Review"}),e.jsx(r,{className:"text-right",children:"Action"})]})}),e.jsx(me,{children:n.items.map(s=>{var q,H;const t=b[s.currentBotStatus||"normal"],c=b[s.suggestedStatus],u=Ne[s.reviewStatus||"pending"],ie=s.reviewStatus==="pending"||!s.reviewStatus,re=s.currentBotStatus&&s.currentBotStatus!=="normal",p=se(s.id,s.suggestedStatus);return e.jsxs(K,{className:s.reviewStatus==="rejected"?"opacity-50":"",children:[e.jsx(l,{children:e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:s.botName||"Unknown"}),e.jsx("div",{className:"text-xs text-muted-foreground",children:s.botAddress})]})}),e.jsx(l,{className:"max-w-[200px] truncate",children:s.emailSubject||"(no subject)"}),e.jsx(l,{className:"max-w-[200px]",children:e.jsx("span",{className:"text-sm text-muted-foreground line-clamp-2",children:s.reason||"-"})}),e.jsx(l,{children:e.jsx(z,{variant:(c==null?void 0:c.variant)||"outline",children:(c==null?void 0:c.label)||s.suggestedStatus})}),e.jsx(l,{children:e.jsx(z,{variant:(t==null?void 0:t.variant)||"outline",children:(t==null?void 0:t.label)||s.currentBotStatus||"Normal"})}),e.jsx(l,{children:e.jsx("span",{className:"font-mono text-sm",children:s.totalBotFlags||0})}),e.jsx(l,{className:"text-sm text-muted-foreground whitespace-nowrap",children:ae(s.flaggedAt)}),e.jsx(l,{children:e.jsx(z,{variant:(u==null?void 0:u.variant)||"outline",children:s.reviewStatus==="applied"&&s.appliedStatus?`Applied: ${((q=b[s.appliedStatus])==null?void 0:q.label)||s.appliedStatus}`:(u==null?void 0:u.label)||"Pending"})}),e.jsx(l,{className:"text-right",children:e.jsx("div",{className:"flex items-center justify-end gap-1",children:ie?e.jsxs(e.Fragment,{children:[e.jsxs(R,{children:[e.jsx(F,{asChild:!0,children:e.jsxs(x,{variant:"ghost",size:"sm",className:"text-muted-foreground hover:text-destructive",disabled:O.isPending,children:[e.jsx(je,{className:"h-4 w-4 mr-1"}),"Reject"]})}),e.jsxs(D,{children:[e.jsxs(P,{children:[e.jsx(B,{children:"Reject Flag?"}),e.jsxs(E,{children:["This will dismiss the flag for ",e.jsx("strong",{children:s.botName})," without changing their status. The bot will keep its current status."]})]}),e.jsxs(M,{children:[e.jsx(k,{children:"Cancel"}),e.jsx(L,{onClick:()=>O.mutate(s.id),children:"Reject"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsxs(C,{value:p,onValueChange:h=>te(s.id,h),children:[e.jsx(f,{className:"w-[130px] h-8 text-xs",children:e.jsx(T,{})}),e.jsx(A,{children:Ce.map(h=>e.jsx(i,{value:h.value,children:h.label},h.value))})]}),e.jsxs(R,{children:[e.jsx(F,{asChild:!0,children:e.jsxs(x,{size:"sm",disabled:_.isPending,children:[e.jsx(pe,{className:"h-4 w-4 mr-1"}),"Apply"]})}),e.jsxs(D,{children:[e.jsxs(P,{children:[e.jsx(B,{children:"Apply Status Change?"}),e.jsxs(E,{children:["This will change ",e.jsx("strong",{children:s.botName}),"'s status to ",e.jsx("strong",{children:((H=b[p])==null?void 0:H.label)||p}
1),". The bot owner will be notified of this change."]})]}),e.jsxs(M,{children:[e.jsx(k,{children:"Cancel"}),e.jsx(L,{onClick:()=>_.mutate({flagId:s.id,status:p}),children:"Apply"})]})]})]})]})]}):e.jsx(e.Fragment,{children:re&&e.jsxs(R,{children:[e.jsx(F,{asChild:!0,children:e.jsxs(x,{variant:"outline",size:"sm",disabled:U.isPending,children:[e.jsx(ge,{className:"h-3 w-3 mr-1"}),"Reinstate"]})}),e.jsxs(D,{children:[e.jsxs(P,{children:[e.jsx(B,{children:"Reinstate Bot?"}),e.jsxs(E,{children:["This will reset ",e.jsx("strong",{children:s.botName})," to normal status and clear its flag count. The bot will be able to send emails again."]})]}),e.jsxs(M,{children:[e.jsx(k,{children:"Cancel"}),e.jsx(L,{onClick:()=>U.mutate(s.botId),children:"Reinstate"})]})]})]})})})})]},s.id)})})]})}),e.jsxs("div",{className:"flex items-center justify-between mt-4",children:[e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Showing ",(o-1)*j+1,"-",Math.min(o*j,n.total)," of ",n.total," flags"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>m(s=>Math.max(1,s-1)),disabled:o<=1,children:[e.jsx(ye,{className:"h-4 w-4"}),"Prev"]}),e.jsxs("span",{className:"text-sm px-2",children:["Page ",o," of ",N]}),e.jsxs(x,{variant:"outline",size:"sm",onClick:()=>m(s=>Math.min(N,s+1)),disabled:o>=N,children:["Next",e.jsx(ve,{className:"h-4 w-4"})]})]})]})]}):e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:"No flags found matching your filters"})})]})]})}export{Me 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.