PageSourceSearch

https://mobilingo.ai/assets/chunks/chunk-BKptju7N.js

js mobilingo.ai collected 2026-09-24 10:49:25 UTC 47,389 bytes, 2 lines download raw bytes

1import{r as d,b as pe,j as e,T as v,B as p,S as L,aj as G,M as ee,aN as ae,I as Y,ar as fe,D as X,a9 as ce,aq as K,h as m,ac as ve,F as se,ag as te,a1 as re,n as A,t as ge,i as we,m as z,u as ie,J as F}from"../entries/pages_index.DwH1fEUc.js";import{S as be}from"./chunk-B5przYSq.js";import{T as Z}from"./chunk-DNZWNReI.js";import{F as Q}from"./chunk-B4V6qS6l.js";import{F as _e}from"./chunk-24_uJ0NB.js";import{F as de}from"./chunk-Bdtlz0G8.js";import{R as ye,a as je,X as Ne,Y as ke,T as Ce,B as le}from"./chunk-Di_31zli.js";import{B as Se}from"./chunk-BLvxIAe-.js";import{F as Re}from"./chunk-ojvCSnGn.js";import{T as Ae}from"./chunk-Ct4DSnPm.js";import{F as me}from"./chunk-BDlqpgVJ.js";import"./chunk-BugajZ7n.js";/* empty css              *//* empty css              *//* empty css              *//* empty css              *//* empty css              */function Te({title:r,titleId:i,...t},o){return d.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:o,"aria-labelledby":i},t),r?d.createElement("title",{id:i},r):null,d.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M2.25 13.5h3.86a2.25 2.25 0 0 1 2.012 1.244l.256.512a2.25 2.25 0 0 0 2.013 1.244h3.218a2.25 2.25 0 0 0 2.013-1.244l.256-.512a2.25 2.25 0 0 1 2.013-1.244h3.859m-19.5.338V18a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18v-4.162c0-.224-.034-.447-.1-.661L19.24 5.338a2.25 2.25 0 0 0-2.15-1.588H6.911a2.25 2.25 0 0 0-2.15 1.588L2.35 13.177a2.25 2.25 0 0 0-.1.661Z"}))}const ne=d.forwardRef(Te),O=pe("spam-protection"),Fe=async()=>{try{return await O({get_spam_stats:{}})}catch(r){throw console.error("Failed to fetch spam statistics:",r),r}},q=async(r,i,t,o="blacklist")=>{try{return await O({add_spam_email:{email:r,reason:i,userId:t,entryType:o}})}catch(c){throw console.error("Failed to add spam email:",c),c}},I=async(r,i)=>{try{const t={email:r};return i&&(t.entryType=i),await O({remove_spam_email:t})}catch(t){throw console.error("Failed to remove spam email:",t),t}},he=async(r={})=>{try{const i={page:r.page||1,itemsPerPage:r.itemsPerPage||10,search:r.search||null,sort:r.sort||{addedAt:-1}};return r.entryType&&(i.entryType=r.entryType),await O({get_spam_list:i})}catch(i){throw console.error("Failed to fetch spam list:",i),i}},Ee=async(r={})=>{try{return await O({get_spam_rules:{page:r.page||1,itemsPerPage:r.itemsPerPage||10,search:r.search,match:r.match||{},sort:r.sort||{createdAt:-1}}})}catch(i){throw console.error("Failed to fetch spam rules:",i),i}},$e=async r=>{try{const i={...r,description:r.description!==void 0?typeof r.description=="string"?r.description:String(r.description):""};return await O({add_spam_rule:i})}catch(i){throw console.error("Failed to add spam rule:",i),i}},J=async(r,i)=>{try{const t={...i};return t.description!==void 0&&(t.description=typeof t.description=="string"?t.description:String(t.description)),await O({update_spam_rule:{ruleId:r,updates:t}})}catch(t){throw console.error("Failed to update spam rule:",t),t}},De=async r=>{try{return await O({delete_spam_rule:{ruleId:r}})}catch(i){throw console.error("Failed to delete spam rule:",i),i}},xe=(r=6e4)=>
1{const[i,t]=d.useState(null),[o,c]=d.useState(!0),[h,j]=d.useState(null),[w,x]=d.useState(null),g=d.useCallback(async()=>{try{c(!0),j(null);const u=await Fe();if(u.error){j(u.error);return}t(u),x(new Date)}catch(u){console.error("Error fetching spam statistics:",u),j(u.message||"Failed to fetch statistics")}finally{c(!1)}},[]),f=d.useCallback(()=>g(),[g]);return d.useEffect(()=>{g()},[g]),d.useEffect(()=>{if(r<=0)return;const u=setInterval(()=>{g()},r);return()=>clearInterval(u)},[g,r]),{statistics:i,loading:o,error:h,lastUpdated:w,refresh:f}},U=({title:r,value:i,icon:t,textColor:o,isHighlighted:c=!1})=>e.jsx("div",{className:`bg-admin_paper rounded-xl p-6 shadow-sm hover:shadow-md ${c?"border border-admin_error":""}`,children:e.jsxs("div",{children:[e.jsx(v,{component:"h2",className:"h-[72px] text-admin_text text-[18px] xl:text-[20px] 2xl:text-[22px] font-normal leading-tight mb-4",children:r}),e.jsxs("div",{className:"flex items-center justify-between mt-6",children:[e.jsx(v,{component:"output",variant:"admin_h2",className:`${o} mt-0`,children:i}),e.jsx("div",{className:"bg-admin_canvas rounded-lg p-3",children:t})]})]})}),Me=({active:r,payload:i,label:t})=>r&&i&&i.length?e.jsxs("div",{className:"bg-admin_paper shadow-md rounded border border-admin_bordered p-3",children:[e.jsx(v,{variant:"admin_label",className:"my-0",children:t}),i.map((o,c)=>e.jsx(v,{variant:"admin_body1",className:o.color==="#EF4444"?"text-admin_error":"text-admin_success",children:`${o.name}: ${o.value}`},c))]}):null;function Be(){const{statistics:r,loading:i,error:t,lastUpdated:o,refresh:c}=xe(),h=()=>{const w=[],x=L(),g={};r?.dailyStats&&r.dailyStats.length>0&&r.dailyStats.forEach(f=>{g[f.date]={blacklist:f.blacklist||0,whitelist:f.whitelist||0,total:f.total||0}});for(let f=6;f>=0;f--){const u=L(x).subtract(f,"days"),b=u.format("YYYY-MM-DD"),_=u.format("MMM DD"),N=g[b]||{blacklist:0,whitelist:0};w.push({date:_,blocked:N.blacklist,whitelisted:N.whitelist,sortValue:6-f})}return w.sort((f,u)=>f.sortValue-u.sortValue)};if(i&&!r)return e.jsxs("div",{className:"animate-pulse p-8",children:[e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-6 mb-8",children:[...Array(5)].map((w,x)=>e.jsx("div",{className:"bg-admin_paper rounded-xl h-36 shadow-md"},x))}),e.jsx("div",{className:"mt-8 bg-admin_paper rounded-xl h-72 shadow-md"}),e.jsx("div",{className:"mt-8 grid grid-cols-1 md:grid-cols-2 gap-6",children:[...Array(2)].map((w,x)=>e.jsx("div",{className:"bg-admin_paper rounded-xl h-80 shadow-md"},x))})]});if(t&&!r)return e.jsxs("div",{className:"p-8",children:[e.jsx("div",{className:"bg-admin_error/30 rounded-lg p-4 mb-4",children:e.jsxs(v,{variant:"admin_txt1",className:"text-admin_error mb-2",children:["Error loading statistics: ",t]})}),e.jsx(p,{onClick:c,variant:"admin_primary",children:"Retry"})]});const j=h();return e.jsxs("div",{className:"h-full bg-admin_canvas p-8",children:[e.jsxs("div",{className:"flex justify-between items-center mb-8",children:[e.jsx(v,{component:"h1",variant:"admin_h2",children:"Spam Protection Overview"}),e.jsxs("div",{className:"flex items-center gap-4",children:[o&&e.jsx("div",{className:"bg-admin_paper rounded-lg px-4 py-2 shadow-sm",children:e.jsxs(v,{variant:"admin_txt1_dim",children:["Last updated: ",L(o).fromNow()]})}),e.jsx(p,{onClick:c,variant:"admin_secondary",disabled:i,className:"whitespace-nowrap",children:i?"Refreshing...":"Refresh Data"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 lg:grid-cols-6 gap-6 mb-8",children:[e.jsx(U,{title:"Blocked Emails",value:r?.totalBlockedEmails||0,textColor:"text-admin_error",isHighlighted:!0,icon:e.jsx(Q,{className:"w-6 h-6 text-admin_error"})}),e.jsx(U,{title:"Whitelisted Emails",value:r?.totalWhitelistedEmails||0,textColor:"text-admin_success",icon:e.jsx(G,{className:"w-6 h-6 text-admin_success"})}),e.jsx(U,{title:"Blocked Today",value:r?.blockedToday||0,textColor:"text-admin_warning",icon:e.jsx(_e,{className:"w-6 h-6 text-admin_warning"})}),e.jsx(U,{title:"Whitelisted Today",value:r?.whitelistedToday||0,textColor:"text-admin_success",icon:e.jsx(G,{className:"w-6 h-6 text-admin_success"})}),e.jsx(U,{title:"Active Rules",value:r?.activeRules||0,textColor:"text-admin_primary",icon:e.jsx(de,{className:"w-6 h-6 text-admin_primary"})}),e.jsx(U,{title:"Total Activity",value:(r?.totalBlockedHits||0)+(r?.totalWhitelistHits||0),textColor:"text-admin_text",icon:e.jsx(ne,{className:"w-6 h-6 text-admin_text"})})]}),e.jsxs("div",{className:"mb-8 bg-admin_paper p-6 rounded-xl shadow-sm",children:[e.jsx(v,{variant:"admin_txt1_accent",className:"block text-admin_text mb-4",children:"Spam Protection Activity (Last 7 Days)"}),e.jsx("div",{className:"h-64",children:e.jsx(ye,{width:"100%",height:"100%",children:e.jsxs(Se,{data:j,margin:{top:5,right:30,left:2
10,bottom:5},children:[e.jsx(je,{strokeDasharray:"3 3",stroke:"#f0f0f0"}),e.jsx(Ne,{dataKey:"date",tick:{fill:"#6B7280"}}),e.jsx(ke,{tick:{fill:"#6B7280"},allowDecimals:!1,domain:[0,"auto"]}),e.jsx(Ce,{content:e.jsx(Me,{})}),e.jsx(le,{dataKey:"blocked",name:"Blocked Emails",fill:"#EF4444",radius:[4,4,0,0]}),e.jsx(le,{dataKey:"whitelisted",name:"Whitelisted Emails",fill:"#22C55E",radius:[4,4,0,0]})]})})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",children:[e.jsx(Z,{title:"Top Blocked Domains",data:r?.blockedDomains||[],keyField:"domain",valueField:"count",emptyMessage:"No domains blocked yet",bgColor:"bg-admin_paper",textColor:"text-admin_text",icon:e.jsx(ne,{className:"w-6 h-6 text-admin_error"}),maxItems:5,loading:i}),e.jsx(Z,{title:"Top Whitelisted Domains",data:r?.whitelistedDomains||[],keyField:"domain",valueField:"count",emptyMessage:"No domains whitelisted yet",bgColor:"bg-admin_paper",textColor:"text-admin_text",icon:e.jsx(G,{className:"w-6 h-6 text-admin_success"}),maxItems:5,loading:i}),e.jsx(Z,{title:"Most Triggered Rules",data:r?.topRules||[],keyField:"description",valueField:"hitCount",emptyMessage:"No rules triggered yet",bgColor:"bg-admin_paper",textColor:"text-admin_text",icon:e.jsx(Re,{className:"w-6 h-6 text-admin_primary"}),maxItems:5,loading:i})]}),t&&e.jsxs("div",{className:"mt-8 bg-admin_error/10 text-admin_error p-4 rounded-lg flex justify-between items-center shadow-md",children:[e.jsxs("span",{children:["Error refreshing: ",t]}),e.jsx(p,{onClick:c,variant:"admin_error",children:"Retry"})]})]})}const oe=[{value:"email",label:"Email Address"},{value:"subject",label:"Email Subject"},{value:"content",label:"Email Content"},{value:"all",label:"All Components"}];function Pe({isOpen:r,onClose:i,onRuleAdded:t,rule:o=null}){const[c,h]=d.useState(""),[j,w]=d.useState(""),[x,g]=d.useState([]),[f,u]=d.useState(!0),[b,_]=d.useState(.5),[N,D]=d.useState(""),[E,S]=d.useState(null),[T,C]=d.useState(""),[$,M]=d.useState(!1),[k,B]=d.useState(!1);d.useEffect(()=>{if(o){h(o.pattern||""),w(o.description||""),u(o.active!==!1),_(o.score!==void 0?o.score:.5),B(o.pattern==="System Module");const a=(o.targets||[]).map(s=>oe.find(l=>l.value===s)||{value:s,label:s});g(a)}else h(""),w(""),g([]),u(!0),_(.5),B(!1);D(""),S(null),C("")},[o,r]);const P=a=>a>=.7?"text-admin_error":a>=.4?"text-admin_warning":"text-admin_success",H=a=>a>=.9?"Very High":a>=.7?"High":a>
1=.5?"Medium":a>=.3?"Low":"Very Low",R=a=>{if(!a)return!1;if(a==="System Module")return!0;try{return new RegExp(a),!0}catch{return!1}},V=()=>{if(!N){S({matched:!1,message:"Please enter text to test against the pattern"});return}if(!R(c)){S({matched:!1,message:"Invalid pattern. Please fix the pattern first."});return}try{const s=new RegExp(c,"i").test(N);S({matched:s,message:s?"Pattern matched the test text!":"Pattern did not match the test text"})}catch(a){S({matched:!1,message:`Error testing pattern: ${a.message}`})}},n=async()=>{if(!k){if(!c){C("Pattern is required");return}if(!R(c)){C("Invalid regular expression pattern");return}}if(x.length===0){C("Please select at least one target");return}const a=x.map(s=>s.value);C(""),M(!0);try{let s;if(o){const l=k?{description:j,targets:a,active:f,score:b}:{pattern:c,description:j,targets:a,active:f,score:b};s=await J(o._id,l)}else s=await $e({pattern:c,description:j,targets:a,score:b});s.success||s.result?(m({message:o?"Rule updated successfully":"Rule created successfully",className:"bg-admin_primary text-admin_text_inv"}),t&&t(),i()):C(s.error||"Failed to save rule")}catch{C("An unexpected error occurred")}finally{M(!1)}};return e.jsx(ee,{isOpen:r,onClose:i,title:o?"Edit Spam Rule":"Add Spam Rule",variant:"admin_compact",children:e.jsxs("div",{className:"p-6 space-y-6",children:[T&&e.jsxs("div",{className:"p-3 mb-4 bg-admin_error/10 border border-admin_error text-admin_error rounded-md flex items-start",children:[e.jsx(ae,{className:"w-5 h-5 mr-2 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:T})]}),k&&e.jsxs("div",{className:"p-3 mb-4 bg-admin_info_bg border border-admin_primary text-admin_primary rounded-md flex items-start",children:[e.jsx(de,{className:"w-5 h-5 mr-2 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:"This is a system filter module. Some settings cannot be modified."})]}),e.jsxs("div",{className:"space-y-4",children:[!k&&e.jsx(Y,{variant:"admin",label:"Pattern (Regular Expression)",value:c,onChange:a=>h(a.target.value),placeholder:"e.g. viagra|cialis|buy.now",required:!0,error:c&&!R(c)?"Invalid regular expression":"",styleOverrides:{label:"text-base font-bold text-admin_text mb-2"}}),!k&&e.jsx("div",{className:"flex items-start pt-1 pb-3 text-admin_text_secondary text-sm",children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(fe,{className:"w-5 h-5 flex-shrink-0 text-admin_primary"}),e.jsx(v,{variant:"admin_body1",className:"my-0",children:"Regular expressions are case-insensitive. Examples:"})]}),e.jsxs("ul",{className:"list-disc pl-6 space-y-1",children:[e.jsxs("li",{children:[e.jsx("code",{children:"viagra|cialis"})," - Match emails containing either word"]}),e.jsxs("li",{children:[e.jsx("code",{children:"free.money"}),' - Match "free money" (dot matches any character)']}),e.jsxs("li",{children:[e.jsx("code",{children:"\\b(winner|prize)\\b"}),' - Match whole words "winner" or "prize"']}),e.jsxs("li",{children:[e.jsxs("code",{children:["\\d",4,"-\\d",4,"-\\d",4]})," ","- Match patterns like credit card numbers"]})]})]})}),e.jsx(Y,{variant:"admin",label:"Description",value:j,onChange:a=>!k&&w(a.target.value),placeholder:"Enter a description for this rule",readOnly:k,styleOverrides:{label:"text-base font-bold text-admin_text mb-2",inputClass:k?"bg-admin_neutral_1/30":""}}),e.jsxs("div",{children:[e.jsxs(v,{variant:"admin_body1_accent",className:"text-base font-bold mb-2",children:["Targets",e.jsx("span",{className:"text-admin_error ml-1",children:"*"})]}),e.jsx(X,{variant:"admin",options:oe,value:x,onChange:a=>g(a||[]),className:"w-full",multiSelection:!0,placeholder:"Select where to apply this rule"}),x.length>0&&e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:x.map((a,s)=>e.jsx("span",{className:"px-2 py-1 bg-admin_info_bg text-admin_text_secondary rounded-full text-xs",children:a.label},s))})]}),e.jsxs("div",{className:"mt-4",children:[e.jsxs(v,{variant:"admin_body1_accent",className:"text-base font-bold mb-2",children:["Confidence Score",e.jsx("span",{className:"text-admin_error ml-1",children:"*"})]}),e.jsxs("div",{className:"flex items-center mb-3",children:[e.jsx("span",{className:`font-medium ${P(b)} mr-2 text-lg`,children:b.toFixed(1)}),e.jsxs("span",{className:"text-admin_text_secondary",children:["(",H(b),")"]}),e.jsx("div",{className:"flex-grow"}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(p,{variant:"admin_secondary",className:"py-1 px-2 min-w-[40px]",onClick:()=>_(Math.max(0,b-.1)),disabled:b<=0,children:"-"}),e.jsx(p,{variant:"admin_secondary",className:"py-1 px-2 min-w-[40px]",onClick:()=>_(Math.min(1,b+.1)),disabled:b>=1,children:"+"})]})]}),e.jsx(ce,{progress:b,title:"",styleOverrides:{progressFill:`${P(b).replace("text-","bg-")}`,progressContainer:"h-2 rounded-full bg-admin_neutral_1"}}),e.jsxs("div",{className:"flex justify-between text-xs text-admin_text_secondary mt-1",children:[e.jsx("span",{children:"0.0 (Weak indicator)"}),e.jsx("span",{children:"1.0 (Strong indicator)"})]}),e.jsxs("div",{className:"text-sm text-admin_text_secondary mt-4",children:[e.jsx("p",{children:"Set how strongly this rule indicates spam when matched:"}),e.jsxs("ul",{className:"list-disc pl-5 mt-1",children:[e.jsxs("li",{children:[e.jsx("span",{className:"text-admin_success",children:"Low (0.1-0.3)"}),": Minor indicator, like promotional keywords"]}),e.jsxs("li",{children:[e.jsx("span",{className:"text-admin_warning",children:"Medium (0.4-0.6)"}),": Moderate indicator, like suspicious patterns"]}),e.jsxs("li",{children:[e.jsx("span",{className:"text-admin_error",children:"High (0.7-1.0)"}),": Strong indicator, like known spam phrases"]})]})]})]}),!k&&e.jsxs("div",{className:"mt-6 p-4 bg-admin_canvas rounded-md",children:[e.jsx(v,{variant:"admin_body1_accent",className:"font-bold mt-0 mb-3",children:"Test Pattern"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(Y,{variant:"admin",value:N,onChange:a=>D(a.target.value),placeholder:"Enter text to test against the pattern",styleOverrides:{inputClass:"bg-admin_paper"}}),e.jsx(p,{variant:"admin_secondary",onClick:V,disabled:!c||!R(c),className:"w-full",children:"Test Pattern"}),E&&e.jsx("div",{className:`mt-2 p-3 rounded-md ${E.matched?"bg-admin_success/10 text-admin_success":"bg-admin_error/10 text-admin_error"}`,children:E.message})]})]})]}),e.jsxs("div",{className:"flex justify-between items-center gap-4 mt-8",children:[o&&e.jsx("div",{children:e.jsx(K,{variant:"admin",label:"Rule is active",isOn:f,onChange:()=>u(!f)})}),!o&&e.jsx("div",{}),e.jsxs("div",{className:"flex gap-4",children:[e.jsx(p,{variant:"admin_secondary",onClick:i,disabled:$,children:"Cancel"}),e.jsx(p,{variant:"admin_primary",onClick:n,disabled:$||!k&&!R(c)||x.length===0,children:$?"Saving...":o?"Update Rule":"Add Rule"})]})]})]})})}
1function Ie(){const[r,i]=d.useState(0),[t,o]=d.useState([]),[c,h]=d.useState({isOpen:!1,rule:null}),[j,w]=d.useState(!1),[x,g]=d.useState([{value:null,label:"All Rules"}]),[f,u]=d.useState([{value:null,label:"All Targets"}]),[b,_]=d.useState([{value:null,label:"All Scores"}]),N=n=>n>=.7?"text-admin_error":n>=.4?"text-admin_warning":"text-admin_success";d.useEffect(()=>{i(n=>n+1)},[x,f,b]);const D=(n,a)=>{o(a?n.map(s=>s._id):[])},E=(n,a)=>{o(a?s=>[...s,n]:s=>s.filter(l=>l!==n))},S=()=>{o([])},T=n=>{h({isOpen:!0,rule:n})},C=async(n,a)=>{try{const s=await J(n._id,{active:a});s.success?(m({message:`Rule ${a?"activated":"deactivated"} successfully`,className:"bg-admin_primary text-admin_text_inv"}),i(l=>l+1)):m({message:s.error||`Failed to ${a?"activate":"deactivate"} rule`,className:"bg-admin_error text-white"})}catch{m({message:"An error occurred while updating rule status",className:"bg-admin_error text-white"})}},$=n=>{A({variant:"admin",title:"Confirm Delete",message:"Are you sure you want to delete this rule? This action cannot be undone.",confirmText:"Delete",confirmVariant:"error_m",onConfirm:async()=>{try{const a=await De(n._id);a.success?(m({message:"Rule deleted successfully",className:"bg-admin_primary text-admin_text_inv"}),i(s=>s+1)):m({message:a.error||"Failed to delete rule",className:"bg-admin_error text-white"})}catch{m({message:"An error occurred while deleting rule",className:"bg-admin_error text-white"})}}})},M=()=>{t.length===0||j||A({variant:"admin",title:"Confirm Activate",message:`Are you sure you want to activate ${t.length} ${t.length===1?"rule":"rules"}?`,confirmText:"Activate",confirmVariant:"primary",onConfirm:async()=>{w(!0);try{let n=0,a=0;for(const s of t)try{(await J(s,{active:!0})).success?n++:a++}catch{a++}n>0?m({message:`${n} ${n===1?"rule":"rules"} activated successfully${a>0?`, ${a} failed`:""}`,className:"bg-admin_primary text-admin_text_inv"}):a>0&&m({message:"Failed to activate rules",className:"bg-admin_error text-white"}),o([]),i(s=>s+1)}catch{m({message:"An error occurred while activating rules",className:"bg-admin_error text-white"})}finally{w(!1)}}})},k=()=>{t.length===0||j||A({variant:"admin",title:"Confirm Deactivate",message:`Are you sure you want to deactivate ${t.length} ${t.length===1?"rule":"rules"}?`,confirmText:"Deactivate",confirmVariant:"error_m",onConfirm:async()=>{w(!0);try{let n=0,a=0;for(const s of t)try{(await J(s,{active:!1})).success?n++:a++}catch{a++}n>0?m({message:`${n} ${n===1?"rule":"rules"} deactivated successfully${a>0?`, ${a} failed`:""}`,className:"bg-admin_primary text-admin_text_inv"}):a>0&&m({message:"Failed to deactivate rules",className:"bg-admin_error text-white"}),o([]),i(s=>s+1)}catch{m({message:"An error occurred while deactivating rules",className:"bg-admin_error text-white"})}finally{w(!1)}}})},B=()=>{const n={},a=x[0]?.value;a!==null&&(n.active=a);const s=f[0]?.value;s!==null&&(n.targets=s);const l=b[0]?.value;if(l!==null)switch(l){case"high":n.score={$gte:.7};break;case"medium":n.score={$gte:.4,$lt:.7};break;case"low":n.score={$lt:.4};break}return{match:n}},P={table:"w-full table-fixed",searchInput:"absolute top-6 right-4 text-text bg-transparent outline-none flex-1 w-[300px] xl:w-[350px] h-[30px] px-2 py-1",row:"h-[60px] text-admin_text text-sm xl:text-base font-normal",getRowStyle:(n,a)=>{if(a&&t.includes(a._id))return"bg-admin_canvas"}},H=[{id:"select",headerClassName:"w-[5%]",header:(n,a)=>e.jsx(K,{variant:"admin",isOn:a.length>0&&t.length===a.length,onChange:s=>D(a,s)}),render:(n,a)=>e.jsx(K,{variant:"admin",isOn:t.includes(a._id),onChange:s=>E(a._id,s)})},{id:"active",title:"Status",headerClassName:"w-[16%]",render:(n,a)=>e.jsxs("div",{className:"flex items-center flex-shrink-0",children:[e.jsx(Ae,{variant:"admin",isOn:a.active,onChange:s=>C(a,s)}),e.jsx("div",{className:"ml-2",children:e.jsx(v,{variant:"admin_txt2",className:ge("text-white font-medium rounded-sm  px-2 py-1",a.active?"bg-admin_success":"bg-admin_error"),children:a.active?"Active":"Inactive"})})]})},{id:"description",title:"Description",headerClassName:"w-[18%]",render:(n,a)=>e.jsx("div",{className:"truncate max-w-full",children:e.jsx("span",{children:a.description||"No description"})})},{id:"pattern",title:"Pattern",headerClassName:"w-[18%]",render:(n,a)=>e.jsx("div",{className:"flex items-center",children:e.jsx("span",{className:"whitespace-nowrap truncate max-w-[250px]",children:a.pattern})})},{id:"score",title:"Score",headerClassName:"w-[12%]",render:(n,a)=>{const s=a.score!==void 0?a.score:.5,l=N(s);return e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("span",{className:`font-medium ${l} min-w-[30px]`,children:s.toFixed(1)}),e.jsx("div",{className:"w-full",children:e.jsx(ce,{progress:s,title:"",styleOverrides:{container:"min-h-0",titleContainer:"hidden",progressContainer:"h-2 rounded-full bg-admin_neutral_1",progressFill:`${l.replace("text-","bg-")}`}})})]})}},{id:"targets",title:"Targets",headerClassName:"w-[12%] text-center",render:(n,a)=>e.jsx("div",{className:"flex flex-wrap gap-1 max-w-full justify-center",children:a.targets&&a.targets.length>0?e.jsx(e.Fragment,{children:a.targets.map((s,l)=>e.jsx("span",{className:"bg-admin_info_bg rounded-full text-xs whitespace-nowrap px-2 py-0.5",children:s},l))}):e.jsx("span",{className:"text-admin_text_secondary",children:"No targets"})})},{id:"hitCount",title:"Hit Count",headerClassName:"w-[10%] whitespace-nowrap text-center",render:(n,a)=>e.jsx("span",{className:"block text-center",children:a.hitCount||0})},{id:"actions",title:"Actions",headerClassName:"w-[12%] text-center",render:(n,a)=>e.jsxs("div",{className:"flex justify-center gap-2 mx-auto",children:[e.jsx(p,{variant:"admin_icon",className:"text-admin_text_secondary transition-colors px-3",onClick:()=>T(a),title:"Edit rule",children:e.jsx(we,{className:"w-5 h-5"})}),e.jsx(p,{className:"text-admin_text_secondary hover:text-admin_error transition-colors px-3",onClick:()=>$(a),title:"Delete rule",children:e.jsx(z,{className:"w-5 h-5"})})]})}],R=e.jsxs("div",{className:"w-full flex flex-row items-center gap-3 -mt-7",children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx(v,{variant:"admin_txt2_dim",className:"mb-0.5",children:"Status"}),e.jsx(X,{variant:"admin",options:[{value:null,label:"All Rules"},{value:!0,label:"Active Rules"},{value:!1,label:"Inactive Rules"}],value:x,onChange:n=>{n&&n.length>0?g([n[0]]):g([{value:null,label:"All Rules"}])},className:"w-[180px]",placeholder:"Filter by status"})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx(v,{variant:"admin_txt2_dim",className:"mb-0.5",children:"Target"}),e.jsx(X,{variant:"admin",options:[{value:null,label:"All Targets"},{value:"email",label:"Email"},{value:"subject",label:"Subject"},{value:"content",label:"Content"},{value:"all",label:"All Components"}],value:f,onChange:n=>{n&&n.length>0?u([n[0]]):u([{value:null,label:"All Targets"}])},className:"w-[180px]",placeholder:"Filter by target"})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx(v,{variant:"admin_txt2_dim",className:"mb-0.5",children:"Score"}),e.jsx(X,{variant:"admin",options:[{value:null,label:"All Scores"},{value:"high",label:"High (≥0.7)"},{value:"medium",label:"Medium (0.4-0.7)"},{value:"low",label:"Low (<0.4)"}],value:b,onChange:n=>{n&&n.length>0?_([n[0]]):_([{value:null,label:"All Scores"}])},className:"w-[180px]",placeholder:"Filter by score"})]})]}),V=t.length>0&&e.jsxs("div",{className:"flex justify-end items-center mt-4 p-3",children:[e.jsxs(v,{variant:"admin_body1",className:"mr-4",children:[t.length," ",t.length===1?"rule":"rules"," selected"]}),e.jsx(p,{variant:"admin_secondary",className:"mr-3",onClick:S,disabled:j,children:e.jsx("div",{className:"flex items-center",children:"Deselect"})}),e.jsx(p,{variant:"admin_secondary",className:"mr-3",onClick:M,disabled:j,children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(ve,{className:"w-5 h-5 mr-1"}),"Activate"]})}),e.jsx(p,{variant:"admin_error",onClick:k,disabled:j,children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(se,{className:"w-5 h-5 mr-2"}),"Deactivate"]})})]});return e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"w-full flex items-center justify-between mb-5",children:[e.jsx(v,{component:"h1",variant:"admin_h3",className:"ml-4",children:"Spam Filter Rules"}),e.jsxs(p,{variant:"admin_primary",className:"whitespace-nowrap flex items-center",onClick:()=>h({isOpen:!0,rule:null}),children:[e.jsx(te,{className:"w-5 h-5 mr-2"})," Add"]})]}),e.jsx(re,{variant:"admin_browser",apiMethod:Ee,requestFields:B(),headerControls:R,tableFooter:V,searchField:"pattern description",sort:{createdAt:-1},localUserPreferencesKey:"admin.spamProtection.rules",renders:H,refreshKey:r,preferredHeight:"60vh",itemHeight:"h-16",noData:e.jsx(v,{variant:"admin_body1",children:"No rules found"}),styleOverrides:P}),e.jsx(Pe,{isOpen:c.isOpen,rule:c.rule,onClose:()=>h({isOpen:!1,rule:null}),onRuleAdded:()=>{i(n=>n+1)}})]})}
1function Oe(){const[r,i]=d.useState(0),[t,o]=d.useState([]),[c,h]=d.useState(!1),[j,w]=d.useState(!1),[x,g]=d.useState(""),[f,u]=d.useState(""),[b,_]=d.useState(""),[N]=ie("user-profile"),D=(a,s)=>{o(s?a.map(l=>l.email):[])},E=(a,s)=>{o(s?l=>[...l,a]:l=>l.filter(y=>y!==a))},S=()=>{o([])},T=a=>a?L(a).format("YYYY-MM-DD HH:mm"):"N/A",C=a=>a?L(a).fromNow():"",$=async()=>{if(!x||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(x)){_("Please enter a valid email address");return}h(!0),_("");try{const s=N?._id,l=await q(x,f,s,"blacklist");l.success?(m({message:"Email added to blacklist successfully",className:"bg-admin_primary text-admin_text_inv"}),g(""),u(""),w(!1),setTimeout(()=>{i(y=>y+1)},500)):_(l.error||"Failed to add email to blacklist")}catch(s){console.error("Error adding email to blacklist:",s),_("An error occurred. Please try again.")}finally{h(!1)}},M=a=>{A({variant:"admin",title:"Confirm Remove",message:`Are you sure you want to remove ${a} from the blacklist?`,confirmText:"Remove",confirmVariant:"error_m",onConfirm:async()=>{h(!0);try{const s=await I(a,"blacklist");s.success?(m({message:"Email removed successfully",className:"bg-admin_primary text-admin_text_inv"}),setTimeout(()=>{i(l=>l+1)},500)):m({message:s.error||"Failed to remove email",className:"bg-admin_error text-white"})}catch{m({message:"An error occurred while removing email",className:"bg-admin_error text-white"})}finally{h(!1)}}})},k=a=>{A({variant:"admin",title:"Move to Whitelist",message:`Are you sure you want to move ${a} to the whitelist? This will remove it from the blacklist and mark it as trusted.`,confirmText:"Move to Whitelist",confirmVariant:"primary",onConfirm:async()=>{h(!0);try{const s=await I(a,"blacklist");if(s.success){const l=N?._id,y=await q(a,"Moved from blacklist",l,"whitelist");y.success?(m({message:"Email moved to whitelist successfully",className:"bg-admin_primary text-admin_text_inv"}),setTimeout(()=>{i(W=>W+1)},500)):m({message:y.error||"Failed to add to whitelist",className:"bg-admin_error text-white"})}else m({message:s.error||"Failed to remove from blacklist",className:"bg-admin_error text-white"})}catch{m({message:"An error occurred while moving email to whitelist",className:"bg-admin_error text-white"})}finally{h(!1)}}})},B=()=>{t.length===0||c||A({variant:"admin",title:"Move to Whitelist",message:`Are you sure you want to move ${t.length} ${t.length===1?"email":"emails"} to the whitelist? This will remove them from the blacklist and mark them as trusted.`,confirmText:"Move to Whitelist",confirmVariant:"primary",onConfirm:async()=>{h(!0);try{let a=0,s=0;for(const l of t)try{if((await I(l,"blacklist")).success){const W=N?._id;(await q(l,"Moved from blacklist",W,"whitelist")).success?a++:s++}else s++}catch{s++}a>0?m({message:`${a} ${a===1?"email":"emails"} moved to whitelist successfully${s>0?`, ${s} failed`:""}`,className:"bg-admin_primary text-admin_text_inv"}):s>0&&m({message:"Failed to move emails to whitelist",className:"bg-admin_error text-white"}),o([]),setTimeout(()=>{i(l=>l+1)},500)}catch{m({message:"An error occurred while moving emails to whitelist",className:"bg-admin_error text-white"})}finally{h(!1)}}})},P=()=>{t.length===0||c||A({variant:"admin",title:"Confirm Remove",message:`Are you sure you want to remove ${t.length} ${t.length===1?"email":"emails"} from the blacklist?`,confirmText:"Remove",confirmVariant:"error_m",onConfirm:async()=>{h(!0);try{let a=0,s=0;for(const l of t)try{(await I(l,"blacklist")).success?a++:s++}catch{s++}a>0?m({message:`${a} ${a===1?"email":"emails"} removed successfully${s>0?`, ${s} failed`:""}`,className:"bg-admin_primary text-admin_text_inv"}):s>0&&m({message:"Failed to remove emails",className:"bg-admin_error text-white"}),o([]),setTimeout(()=>{i(l=>l+1)},500)}catch{m({message:"An error occurred while removing emails",className:"bg-admin_error text-white"})}finally{h(!1)}}})},H={container:"relative w-full flex flex-col h-[75vh] justify-start bg-admin_paper rounded-3xl p-6 pb-4",table:"w-full table-fixed",header:"w-full flex justify-between items-end gap-2 mt-10 mb-4",searchInput:"absolute top-4 right-4 text-text bg-transparent outline-none flex-1 w-[350px] h-[30px] px-2 py-1",row:"h-[60px] text-admin_text text-sm xl:text-base font-normal",getRowStyle:(a,s)=>{if(s&&t.includes(s.email))return"bg-admin_canvas"}},R=[{id:"select",headerClassName:"w-8",header:(a,s)=>e.jsx(K,{variant:"admin_compact",isOn:s.length>0&&t.length===s.length,onChange:l=>D(s,l)}),render:(a,s)=>e.jsx(K,{variant:"admin_compact",className:"mt-0.5",isOn:t.includes(s.email),onChange:l=>E(s.email,l)})},{id:"email",title:"Email",headerClassName:"w-[20%] whitespace-nowrap",render:(a,s)=>e.jsx(F,{display:"block",content:s.email,children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(me,{className:"w-4 xl:w-5 h-4 xl:h-5 flex-shrink-0 text-admin_text_secondary mr-2"}),e.jsx("span",{className:"block font-medium truncate",children:s.email})]})})},{id:"reason",title:"Reason",headerClassName:"w-[16%] whitespace-nowrap",render:(a,s)=>e.jsx(F,{display:"block",content:s.reason||"No reason specified",children:e.jsx("span",{className:"block truncate",children:s.reason||"No reason specified"})})},{id:"hitCount",title:"Hit Count",headerClassName:"w-[10%] whitespace-nowrap text-center",render:(a,s)=>e.jsx("span",{className:"block text-center",children:s.hitCount||0})},{id:"addedAt",title:"Added",headerClassName:"w-[15%] whitespace-nowrap",render:(a,s)=>e.jsxs("div",{className:"flex flex-col mt-2.5",children:[e.jsx("span",{className:"flex-nowrap",children:T(s.addedAt)}),e.jsx("span",{className:"text-xs text-admin_text_secondary leading-none",children:C(s.addedAt)})]})},{id:"lastHit",title:"Last Hit",headerClassName:"w-[15%] whitespace-nowrap",render:(a,s)=>e.jsx("div",{children:s.lastHit?e.jsxs("div",{className:"flex flex-col mt-2.5",children:[e.jsx("span",{className:"flex-nowrap",children:T(s.lastHit)}),e.jsx("span",{className:"text-xs text-admin_text_secondary leading-none",children:C(s.lastHit)})]}):e.jsx("span",{className:"text-admin_text_secondary",children:"Never"})})},{id:"addedBy",title:"Added By",headerClassName:"w-[10%] whitespace-nowrap",render:(a,s)=>e.jsx(F,{display:"block",content:s.addedBy&&(s.addedBy.name||s.addedBy.email)||"Unknown",children:e.jsx("div",{children:s.addedBy?e.jsx("span",{className:"block truncate",children:s.addedBy.name||s.addedBy.email||"Unknown"}):e.jsx("span",{children:"System"})})})},{id:"actions",title:"Actions",headerClassName:"w-[10%] whitespace-nowrap",render:(a,s)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(F,{display:"block",content:"Move to whitelist",children:e.jsx(p,{variant:"admin_icon",className:"p-1.5 text-admin_text_secondary transition-colors",onClick:()=>k(s.email),children:e.jsx(G,{className:"w-5 h-5"})})}
1),e.jsx(F,{display:"block",content:"Remove from blacklist",children:e.jsx(p,{variant:"admin_icon",className:"p-1.5 text-admin_text_secondary hover:!text-admin_error transition-colors",onClick:()=>M(s.email),children:e.jsx(z,{className:"w-5 h-5"})})})]})}],V=async(a={})=>await he({...a,entryType:"blacklist"}),n=t.length>0&&e.jsxs("div",{className:"flex justify-end items-center mt-4 p-3 bg-admin_paper rounded",children:[e.jsxs(v,{variant:"admin_body1",className:"mr-4",children:[t.length," ",t.length===1?"email":"emails"," selected"]}),e.jsx(p,{variant:"admin_secondary",className:"mr-3",onClick:S,disabled:c,children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(se,{className:"w-5 h-5 mr-2"}),"Deselect"]})}),e.jsx(p,{variant:"admin_secondary",className:"mr-3",onClick:B,disabled:c,children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(G,{className:"w-5 h-5 mr-2"}),"Move to Whitelist"]})}),e.jsx(p,{variant:"admin_error",onClick:P,disabled:c,children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(z,{className:"w-5 h-5 mr-2"}),"Remove"]})})]});return e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"w-full flex items-center justify-between mb-5",children:[e.jsx(v,{component:"h1",variant:"admin_h3",children:"Spam Blacklist"}),e.jsxs(p,{variant:"admin_primary",className:"whitespace-nowrap flex items-center",onClick:()=>w(!0),children:[e.jsx(te,{className:"w-5 h-5 mr-2"})," Add"]})]}),e.jsx("div",{className:"mb-6 bg-admin_paper p-4 rounded-lg border-l-4 border-admin_error",children:e.jsxs(v,{variant:"admin_body1",className:"text-admin_text_secondary my-0",children:[e.jsx("strong",{children:"Spam Blacklist:"})," Email addresses in this list are automatically marked as spam and blocked. These emails will be rejected by the spam protection system. You can move entries to the whitelist to mark them as trusted, or remove them entirely to allow normal spam filtering."]})}),e.jsx(re,{variant:"admin_browser",apiMethod:V,searchField:"email reason",sort:{addedAt:-1},localUserPreferencesKey:"admin.spamProtection.blacklist",renders:R,refreshKey:r,preferredHeight:"60vh",itemHeight:"h-16",tableFooter:n,noData:e.jsx(v,{variant:"admin_body1",children:"No blacklisted emails found"}),styleOverrides:H},`spam-blacklist-${r}`),e.jsx(ee,{isOpen:j,onClose:()=>{w(!1),g(""),u(""),_("")},title:"Add Email to Blacklist",variant:"admin_centered",children:e.jsxs("div",{className:"pt-6 space-y-6",children:[b&&e.jsxs("div",{className:"p-3 mb-4 bg-admin_error/10 border border-admin_error text-admin_error rounded-md flex items-start",children:[e.jsx(ae,{className:"w-5 h-5 mr-2 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:b})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(Y,{variant:"admin",label:"Email Address",value:x,onChange:a=>g(a.target.value),placeholder:"Enter email to blacklist",required:!0,styleOverrides:{label:"text-base font-bold text-admin_text mb-2"}}),e.jsx(Y,{label:"Reason (optional)",variant:"admin",value:f,onChange:a=>u(a.target.value),placeholder:"Enter reason for blacklisting",multiline:!0,styleOverrides:{label:"text-base font-bold text-admin_text mb-2"}})]}),e.jsxs("div",{className:"flex justify-end gap-4 mt-8",children:[e.jsx(p,{variant:"admin_secondary",onClick:()=>{w(!1),g(""),u(""),_("")},disabled:c,children:"Cancel"}),e.jsx(p,{variant:"admin_primary",onClick:$,disabled:c||!x.trim(),children:c?"Adding...":"Add to Blacklist"})]})]})})]})}function He(){const[r,i]=d.useState(0),[t,o]=d.useState([]),[c,h]=d.useState(!1),[j,w]=d.useState(!1),[x,g]=d.useState(""),[f,u]=d.useState(""),[b,_]=d.useState(""),[N]=ie("user-profile"),D=(a,s)=>{o(s?a.map(l=>l.email):[])},E=(a,s)=>{o(s?l=>[...l,a]:l=>l.filter(y=>y!==a))},S=()=>{o([])},T=a=>a?L(a).format("YYYY-MM-DD HH:mm"):"N/A",C=a=>a?L(a).fromNow():"",$=async()=>{if(!x||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(x)){_("Please enter a valid email address");return}h(!0),_("");try{const s=N?._id,l=await q(x,f,s,"whitelist");l.success?(m({message:"Email added to whitelist successfully",className:"bg-admin_primary text-admin_text_inv"}),g(""),u(""),w(!1),setTimeout(()=>{i(y=>y+1)},500)):_(l.error||"Failed to add email to whitelist")}catch(s){console.error("Error adding email to whitelist:",s),_("An error occurred. Please try again.")}finally{h(!1)}},M=a=>{A({variant:"admin",title:"Confirm Remove",message:`Are you sure you want to remove ${a} from the whitelist?`,confirmText:"Remove",confirmVariant:"error_m",onConfirm:async()=>{h(!0);try{const s=await I(a,"whitelist");s.success?(m({message:"Email removed successfully",className:"bg-admin_primary text-admin_text_inv"}),setTimeout(()=>{i(l=>l+1)},500)):m({message:s.error||"Failed to remove email",className:"bg-admin_error text-white"})}catch{m({message:"An error occurred while removing email",className:"bg-admin_error text-white"})}finally{h(!1)}}})},k=a=>{A({variant:"admin",title:"Move to Blacklist",message:`Are you sure you want to move ${a}
1 to the blacklist? This will remove it from the whitelist and mark it as spam.`,confirmText:"Move to Blacklist",confirmVariant:"error_m",onConfirm:async()=>{h(!0);try{const s=await I(a,"whitelist");if(s.success){const l=N?._id,y=await q(a,"Moved from whitelist",l,"blacklist");y.success?(m({message:"Email moved to blacklist successfully",className:"bg-admin_primary text-admin_text_inv"}),setTimeout(()=>{i(W=>W+1)},500)):m({message:y.error||"Failed to add to blacklist",className:"bg-admin_error text-white"})}else m({message:s.error||"Failed to remove from whitelist",className:"bg-admin_error text-white"})}catch{m({message:"An error occurred while moving email to blacklist",className:"bg-admin_error text-white"})}finally{h(!1)}}})},B=()=>{t.length===0||c||A({variant:"admin",title:"Move to Blacklist",message:`Are you sure you want to move ${t.length} ${t.length===1?"email":"emails"} to the blacklist? This will remove them from the whitelist and mark them as spam.`,confirmText:"Move to Blacklist",confirmVariant:"error_m",onConfirm:async()=>{h(!0);try{let a=0,s=0;for(const l of t)try{if((await I(l,"whitelist")).success){const W=N?._id;(await q(l,"Moved from whitelist",W,"blacklist")).success?a++:s++}else s++}catch{s++}a>0?m({message:`${a} ${a===1?"email":"emails"} moved to blacklist successfully${s>0?`, ${s} failed`:""}`,className:"bg-admin_primary text-admin_text_inv"}):s>0&&m({message:"Failed to move emails to blacklist",className:"bg-admin_error text-white"}),o([]),setTimeout(()=>{i(l=>l+1)},500)}catch{m({message:"An error occurred while moving emails to blacklist",className:"bg-admin_error text-white"})}finally{h(!1)}}})},P=()=>{t.length===0||c||A({variant:"admin",title:"Confirm Remove",message:`Are you sure you want to remove ${t.length} ${t.length===1?"email":"emails"} from the whitelist?`,confirmText:"Remove",confirmVariant:"error_m",onConfirm:async()=>{h(!0);try{let a=0,s=0;for(const l of t)try{(await I(l,"whitelist")).success?a++:s++}catch{s++}a>0?m({message:`${a} ${a===1?"email":"emails"} removed successfully${s>0?`, ${s} failed`:""}`,className:"bg-admin_primary text-admin_text_inv"}):s>0&&m({message:"Failed to remove emails",className:"bg-admin_error text-white"}),o([]),setTimeout(()=>{i(l=>l+1)},500)}catch{m({message:"An error occurred while removing emails",className:"bg-admin_error text-white"})}finally{h(!1)}}})},H={container:"relative w-full flex flex-col h-[75vh] justify-start bg-admin_paper rounded-3xl p-6 pb-4",table:"w-full table-fixed",header:"w-full flex justify-between items-end gap-2 mt-10 mb-4",searchInput:"absolute top-4 right-4 text-text bg-transparent outline-none flex-1 w-[350px] h-[30px] px-2 py-1",row:"h-[60px] text-admin_text text-sm xl:text-base font-normal",getRowStyle:(a,s)=>{if(s&&t.includes(s.email))return"bg-admin_canvas"}},R=[{id:"select",headerClassName:"w-8",header:(a,s)=>e.jsx(K,{variant:"admin_compact",isOn:s.length>0&&t.length===s.length,onChange:l=>D(s,l)}),render:(a,s)=>e.jsx(K,{variant:"admin_compact",isOn:t.includes(s.email),onChange:l=>E(s.email,l)})},{id:"email",title:"Email",headerClassName:"w-[20%]",render:(a,s)=>e.jsx(F,{display:"block",content:s.email,children:e.jsxs("div",{className:"flex items-center flex-nowrap",children:[e.jsx(me,{className:"w-4 xl:w-5 h-4 xl:h-5 flex-shrink-0 text-admin_text_secondary mr-2"}),e.jsx("span",{className:"block truncate",children:s.email})]})})},{id:"reason",title:"Reason",headerClassName:"w-[16%]",render:(a,s)=>e.jsx(F,{display:"block",content:s.reason||"No reason specified",children:e.jsx("span",{className:"block truncate whitespace-nowrap",children:s.reason||"No reason specified"})})},{id:"hitCount",title:"Hit Count",headerClassName:"w-[10%] whitespace-nowrap text-center",render:(a,s)=>e.jsx("span",{className:"block text-center",children:s.hitCount||0})},{id:"addedAt",title:"Added",headerClassName:"w-[15%]",render:(a,s)=>e.jsxs("div",{className:"flex flex-col mt-2.5",children:[e.jsx("span",{className:"flex flex-nowrap",children:T(s.addedAt)}),e.jsx("span",{className:"text-xs text-admin_text_secondary leading-none",children:C(s.addedAt)})]})},{id:"lastHit",title:"Last Hit",headerClassName:"w-[15%] whitespace-nowrap",render:(a,s)=>e.jsx(e.Fragment,{children:s.lastHit?e.jsxs("div",{className:"flex flex-col mt-2.5",children:[e.jsx("div",{className:"flex flex-nowrap",children:T(s.lastHit)}),e.jsx("span",{className:"text-xs text-admin_text_secondary leading-none",children:C(s.lastHit)})]}):e.jsx("span",{className:"text-admin_text_secondary",children:"Never"})})},{id:"addedBy",title:"Added By",headerClassName:"w-[10%] whitespace-nowrap",render:(a,s)=>e.jsx(F,{display:"block",content:s.addedBy.name||s.addedBy.email||"Unknown",children:e.jsx("div",{children:s.addedBy?e.jsx("div",{className:"block truncate",children:s.addedBy.name||s.addedBy.email||"Unknown"}):e.jsx("span",{children:"System"})})})},{id:"actions",title:"Actions",headerClassName:"w-[10%] text-center",render:(a,s)=>e.jsxs("div",{className:"flex gap-2",children:[e.jsx(F,{display:"block w-fit",content:"Move to blacklist",children:e.jsx(p,{variant:"admin_icon",className:"p-1.5 text-admin_text_secondary transition-colors",onClick:()=>k(s.email),children:e.jsx(Q,{className:"w-5 h-5"})})}),e.jsx(F,{display:"block w-fit",content:"Remove from whitelist",children:e.jsx(p,{variant:"admin_icon",className:"p-1.5 text-admin_text_secondary hover:!text-admin_error transition-colors",onClick:()=>M(s.email),children:e.jsx(z,{className:"w-5 h-5"})})})]})}],V=async(a={})=>await he({...a,entryType:"whitelist"}),n=t.length>0&&e.jsxs("div",{className:"flex justify-end items-center mt-4 p-3 bg-admin_paper rounded",children:[e.jsxs(v,{variant:"admin_body1",className:"mr-4",children:[t.length," ",t.length===1?"email":"emails"," selected"]}),e.jsx(p,{variant:"admin_secondary",className:"mr-3",onClick:S,disabled:c,
1children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(se,{className:"w-5 h-5 mr-2"}),"Deselect"]})}),e.jsx(p,{variant:"admin_error",className:"mr-3",onClick:B,disabled:c,children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(Q,{className:"w-5 h-5 mr-2"}),"Move to Blacklist"]})}),e.jsx(p,{variant:"admin_error",onClick:P,disabled:c,children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(z,{className:"w-5 h-5 mr-2"}),"Remove"]})})]});return e.jsxs("div",{className:"p-4",children:[e.jsxs("div",{className:"w-full flex items-center justify-between mb-5",children:[e.jsx(v,{component:"h1",variant:"admin_h3",children:"Spam Whitelist"}),e.jsxs(p,{variant:"admin_primary",className:"whitespace-nowrap flex items-center",onClick:()=>w(!0),children:[e.jsx(te,{className:"w-5 h-5 mr-2"}),"Add"]})]}),e.jsx("div",{className:"mb-6 bg-admin_paper rounded-lg border-l-4 border-admin_success p-4",children:e.jsxs(v,{variant:"admin_body1_dim",className:"my-0",children:[e.jsx("strong",{children:"Spam Whitelist:"})," Email addresses in this list are marked as trusted and will bypass all spam filters. These emails will always be allowed through, regardless of content or other spam detection rules. You can move entries to the blacklist to mark them as spam, or remove them entirely to allow normal spam filtering."]})}),e.jsx(re,{variant:"admin_browser",apiMethod:V,searchField:"email reason",sort:{addedAt:-1},localUserPreferencesKey:"admin.spamProtection.whitelist",renders:R,refreshKey:r,preferredHeight:"75vh",itemHeight:"h-16",tableFooter:n,noData:e.jsx(v,{variant:"admin_body1",children:"No whitelisted emails found"}),styleOverrides:H},`spam-whitelist-${r}`),e.jsx(ee,{isOpen:j,onClose:()=>{w(!1),g(""),u(""),_("")},title:"Add Email to Whitelist",variant:"admin_centered",children:e.jsxs("div",{className:"pt-6 space-y-6",children:[b&&e.jsxs("div",{className:"p-3 mb-4 bg-admin_error/10 border border-admin_error text-admin_error rounded-md flex items-start",children:[e.jsx(ae,{className:"w-5 h-5 mr-2 flex-shrink-0 mt-0.5"}),e.jsx("span",{children:b})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx(Y,{variant:"admin",label:"Email Address",value:x,onChange:a=>g(a.target.value),placeholder:"Enter email to whitelist",required:!0,styleOverrides:{label:"text-base font-bold text-admin_text mb-2"}}),e.jsx(Y,{label:"Reason (optional)",variant:"admin",value:f,onChange:a=>u(a.target.value),placeholder:"Enter reason for whitelisting",multiline:!0,styleOverrides:{label:"text-base font-bold text-admin_text mb-2"}})]}),e.jsxs("div",{className:"flex justify-end gap-4 mt-8",children:[e.jsx(p,{variant:"admin_secondary",onClick:()=>{w(!1),g(""),u(""),_("")},disabled:c,children:"Cancel"}),e.jsx(p,{variant:"admin_primary",onClick:$,disabled:c||!x.trim(),children:c?"Adding...":"Add to Whitelist"})]})]})})]})}const ra=()=>{const{statistics:r}
1=xe(),[i,t]=ie("spam-statistics",null),[o,c]=d.useState(0);return d.useEffect(()=>{i&&typeof i.recentlyBlocked=="number"?c(i.recentlyBlocked):c(0)},[i]),d.useEffect(()=>{r&&t(r)},[r,t]),e.jsx(be,{menuName:"AdminSpamProtectionMenu",tabs:{overview:Be,rules:Ie,blacklist:Oe,whitelist:He},onMenuItemRender:h=>h.name!=="SpamProtectionBlacklist"||o<=0?null:e.jsx("div",{className:"min-w-[20px] h-5 flex items-center justify-center rounded-full bg-admin_error px-1.5",children:e.jsx(v,{variant:"admin_txt2",className:"text-admin_text_inv",children:o>99?"99+":o})})})};export{ra as default};
2//# sourceMappingURL=chunk-BKptju7N.js.map

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.