"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/SpamFilterBlackListPage"],{1096:(e,t,s)=>{s.r(t),s.d(t,{SORT_ASC:()=>c,SORT_DESC:()=>m,default:()=>h});var n=s(245),o=s(247),i=s.n(o),a=s(246),r=s(90);const l=r.Locale.getTranslate("components.list"),d=r.Locale.getSection("components.list"),c="ASC",m="DESC",u="all",p={set(e,t){localStorage.setItem(e,JSON.stringify(t))},get(e){const t=localStorage.getItem(e);return JSON.parse(t)}},g=e=>`list-sort_${e}`,y=e=>`list-page_${e}`,f=({id:e,data:t,columns:s,itemsPerPage:o,itemsPerPageOptions:i,sortColumn:r,sortDirection:m,searchField:f,locale:h,emptyView:P,emptyFilteredView:x,toolbar:T,selection:j,onSelectionChange:S,searchBarInputProps:b,rowKey:C,...L})=>{const{sortColumn:F,sortDirection:w,setSortState:A}=((e,{sortColumn:t,sortDirection:s})=>{const[{sortColumn:o,sortDirection:i},a]=(0,n.useState)({sortColumn:p.get(g(e))?.sortColumn??t,sortDirection:p.get(g(e))?.sortDirection??s});return{sortColumn:o,sortDirection:i,setSortState:t=>{a((e=>({...e,...t}))),p.set(g(e),{...p.get(g(e)),...t})}}})(e,{sortColumn:r??s.find((({sortable:e})=>e))?.key,sortDirection:m}),{page:D,itemsPerPage:k,searchPattern:v,setPageState:B}=((e,{itemsPerPage:t})=>{const[{page:s,itemsPerPage:o,searchPattern:i},a]=(0,n.useState)({page:p.get(y(e))?.page??1,itemsPerPage:p.get(y(e))?.itemsPerPage??t,searchPattern:p.get(y(e))?.searchPattern??""});return{page:s,itemsPerPage:o,searchPattern:i,setPageState:t=>{a((e=>({...e,...t}))),p.set(y(e),{...p.get(y(e)),...t})}}})(e,{itemsPerPage:i.includes(o)?o:i[0]}),R=(0,n.useMemo)((()=>v?x??(0,n.jsx)(a.ListEmptyView,{reason:"filtered",title:(0,n.jsx)(l,{content:"emptyViewFilteredTitle"}),description:(0,n.jsx)(l,{content:"emptyViewFilteredDescription"})}):P??(0,n.jsx)(a.ListEmptyView,{title:(0,n.jsx)(l,{content:"emptyViewTitle"})})),[v,P,x]),O=(0,n.useMemo)((()=>s.map((({sortDataField:e,...t})=>t))),[s]),M=(0,n.useMemo)((()=>f&&v?t.filter((e=>(Array.isArray(f)?f:[f]).some((t=>e[t]&&String(e[t]).toLowerCase().includes(v.toLowerCase()))))):t),[t,v,f]),V=(0,n.useMemo)((()=>{if(!F)return M;const e=s.find((({key:e})=>e===F))?.sortDataField??F,t=s.find((({key:e})=>e===F))?.sort??((t,s)=>t[e]<s[e]?-1:t[e]>s[e]?1:0);return[...M].sort(((e,s)=>c===w?t(e,s):t(s,e)))}),[M,F,w,s]),E=(0,n.useMemo)((()=>{if(k===u)return V;const e=k*(D-1),t=e+k;return V.slice(e,t)}),[D,V,k]),q=(0,n.useCallback)((e=>{B({searchPattern:e}),e!==v&&B({page:1})}),[v]),$=(0,n.useCallback)((e=>{B({itemsPerPage:e});(e===u?1:Math.ceil(M.length/e))<D&&B({page:1})}),[M.length,D]);return(0,n.useEffect)((()=>{if("function"==typeof S&&j.length){const e=M.map((e=>{return t=e,"function"==typeof(s=C)?s(t):t[s];var t,s})).filter((e=>j.includes(e)));S(e)}}),[M]),(0,n.jsx)(a.List,{pagination:(0,n.jsx)(a.Pagination,{current:D,total:k===u?1:Math.ceil(M.length/k),onSelect:e=>B({page:e}),itemsPerPage:k,itemsPerPageOptions:i,onItemsPerPageChange:$}),toolbar:(T||f)&&(0,n.jsxs)(a.Toolbar,{children:[T,f&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(a.ToolbarExpander,{}),(0,n.jsx)(a.ToolbarGroup,{title:"",children:(0,n.jsx)(a.SearchBar,{inputProps:{placeholder:d.lmsg("searchPlaceholder"),"data-testid":"list-searchbar",value:v,...b??{}},onTyping:q})})]})]}),totalRows:M.length,sortColumn:F,sortDirection:w,onSortChange:A,columns:O,data:E,filtered:!!v,locale:{totalRows:({totalRows:e})=>d.formatMessage("recordsTotal",{total:e}),...h},emptyView:R,onSelectionChange:S,selection:j,rowKey:C,...L})};f.propTypes={id:i().string.isRequired,data:i().array.isRequired,columns:i().array.isRequired,itemsPerPage:i().number,itemsPerPageOptions:i().array,sortColumn:i().string,sortDirection:i().string,searchField:i().oneOfType([i().string,i().arrayOf(i().string.isRequired)]),locale:i().object,emptyView:i().node,emptyFilteredView:i().node,toolbar:i().node,onSelectionChange:i().func,selection:i().array,rowKey:i().oneOfType([i().string,i().func]),searchBarInputProps:i().object},f.defaultProps={itemsPerPage:25,itemsPerPageOptions:[10,25,100,u],sortColumn:void 0,sortDirection:c,searchField:void 0,locale:{},emptyView:void 0,emptyFilteredView:void 0,toolbar:void 0,onSelectionChange:void 0,selection:[],searchBarInputProps:void 0,rowKey:"key"};const h=f},2043:(e,t,s)=>{s.r(t),s.d(t,{default:()=>j});var n=s(247),o=s(246),i=s(90),a=s(245),r=s(458),l=s(774),d=s(688),c=s(959),m=s(955),u=s.n(m),p=s(956),g=s.n(p);const y=i.Locale.getTranslate("components.forms.spam-filter.add"),f=i.Locale.getSection("components.forms.spam-filter.add"),h=r.gql`
    mutation AddAddressesToSpamFilterList($input: AddAddressesToSpamFilterListInput!) {
        addAddressesToSpamFilterList(input: $input) {
            warnings
        }
    }
`,P="file",x="string",T=({isBlackList:e,isOpen:t,onClose:s})=>{const[n,i]=(0,a.useState)({dataType:P,file:null,addresses:""}),[r,{loading:m}]=(0,l.useMutation)(h,{refetchQueries:[{query:e?u():g()}],awaitRefetchQueries:!0});return(0,a.jsx)(o.Drawer,{"data-type":"add-domain-to-spam-filter-list",title:(0,a.jsx)(y,{content:e?"titleBlack":"titleWhite"}),isOpen:t,onClose:s,size:"sm",form:(0,a.jsxs)(c.default,{state:m?"submit":null,applyButton:!1,submitButton:{id:"btn-save"},onSubmit:({dataType:t,file:s,addresses:n})=>({listType:e?"blacklist_from":"whitelist_from",dataType:t,addresses:n,file:s}),onSuccess:({addAddressesToSpamFilterList:{warnings:e}})=>{e.length?e.forEach((e=>{(0,d.addToast)({intent:"danger",message:e})})):(0,d.addToast)({intent:"success",message:(0,a.jsx)(y,{content:"success"})}),s(),i({dataType:P,file:null,addresses:""})},onFieldChange:(e,t)=>i((0,o.setIn)(n,e,t)),values:n,mutation:r,children:[(0,a.jsx)(o.Text,{component:"p",children:(0,a.jsx)("div",{dangerouslySetInnerHTML:{__html:f.lmsg("listDescription")}})}),(0,a.jsx)(o.FormFieldRadioButtons,{label:null,name:"dataType",options:[{value:P,label:(0,a.jsx)(y,{content:"fromFile"}),indentFields:[(0,a.jsx)(o.FormField,{name:"file",label:null,description:(0,a.jsx)(y,{content:"fileDescription"}),children:({getId:e,getName:t,setValue:s,isDisabled:n})=>(0,a.jsx)(o.InputFile,{id:e(),name:t(),disabled:n(),onChange:e=>s(e)})},"file")]},{value:x,label:(0,a.jsx)(y,{content:"fromList"}),indentFields:[(0,a.jsx)(o.FormFieldText,{name:"addresses",label:null,multiline:!0,size:"xl"},"addresses")]}]})]})})};T.propTypes={isOpen:n.PropTypes.bool,isBlackList:n.PropTypes.bool.isRequired,onClose:n.PropTypes.func.isRequired},T.defaultProps={isOpen:!1};const j=T},2042:(e,t,s)=>{s.r(t),s.d(t,{default:()=>j});var n=s(247),o=s(246),i=s(90),a=s(1096),r=s(245),l=s(688),d=s(458),c=s(774),m=s(955),u=s.n(m),p=s(956),g=s.n(p);const y=i.Locale.getTranslate("components.lists.spam-filter"),f=i.Locale.getSection("components.lists.spam-filter"),h=i.Locale.getTranslate("components.buttons"),P="BlackList",x=d.gql`
    mutation DeleteAddressesFromSpamFilterList($input: DeleteAddressesFromSpamFilterListInput!) {
        deleteAddressesFromSpamFilterList(input: $input) {
            __typename
        }
    }
`,T=({list:e,type:t,onAddDomain:s})=>{const[n,i]=(0,r.useState)([]),[d,m]=(0,r.useState)([]),p=(0,r.useMemo)((()=>e.filter((({id:e})=>n.includes(e)))),[e,n]),[T]=(0,c.useMutation)(x,{refetchQueries:[{query:"BlackList"===t?u():g()}],awaitRefetchQueries:!0});return(0,r.jsx)(a.default,{id:`server-mail-${t}`,toolbar:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(o.ToolbarGroup,{title:f.lmsg("groupAdd"),children:(0,r.jsx)(o.Button,{id:`add${t}edDomain`,intent:"primary",icon:"plus",tooltip:(0,r.jsx)(y,{content:t===P?"buttonAddAddressToBlackListHint":"buttonAddAddressToWhiteListHint"}),"aria-label":f.lmsg(t===P?"buttonAddAddressToBlackListHint":"buttonAddAddressToWhiteListHint"),onClick:s})}),(0,r.jsx)(o.ToolbarGroup,{title:f.lmsg("groupActions"),children:(0,r.jsx)(o.ListOperation,{critical:!0,noSelectionText:(0,r.jsx)(y,{content:"removeEmptySelection"}),confirmationText:f.formatMessage("removeConfirmation",{name:(0,r.jsx)("b",{children:p[0]?.name}),count:p.length}),actionButtonText:(0,r.jsx)(h,{content:"yesRemove"}),cancelButtonText:(0,r.jsx)(h,{content:"cancel"}),children:(0,r.jsx)(o.Button,{id:`remove${t}edDomain`,onClick:async()=>{m(n);try{await T({variables:{input:{ids:n}}}),(0,l.addToast)({intent:"success",message:(0,r.jsx)(y,{content:"removeSuccess"})})}catch(e){e.graphQLErrors?e.graphQLErrors.forEach((({message:e,debugMessage:t})=>{(0,l.addToast)({intent:"danger",message:t||e})})):(0,l.addToast)({intent:"danger",message:e.message})}finally{i([]),m([])}},children:(0,r.jsx)(y,{content:"buttonRemove"})})})})]}),columns:[{key:"name",title:(0,r.jsx)(y,{content:"entries"}),type:"title",sortable:!0}],rowKey:"id",data:e,searchField:"name",selection:n,onSelectionChange:e=>i(e),loadingRows:d,emptyView:(0,r.jsx)(o.ListEmptyView,{title:(0,r.jsx)(y,{content:`addAddressTo${t}EmptyTitle`}),description:(0,r.jsx)(y,{content:`addAddressTo${t}EmptyDescription`}),actions:(0,r.jsx)(o.Button,{id:`add${t}edDomain`,intent:"primary",tooltip:(0,r.jsx)(y,{content:`buttonAddAddressTo${t}Hint`}),onClick:s,children:(0,r.jsx)(y,{content:"buttonAddAddress"})})})})};T.propTypes={list:n.PropTypes.array.isRequired,type:n.PropTypes.string.isRequired,onAddDomain:n.PropTypes.func.isRequired};const j=T},2041:(e,t,s)=>{s.r(t),s.d(t,{default:()=>d});var n=s(745),o=s(2042),i=s(2043),a=s(955),r=s.n(a),l=s(245);const d=()=>{const[e,t]=(0,l.useState)(!1),{data:{serverMail:{spamAssassin:{blackList:s}}}}=(0,n.useQuery)(r());return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(i.default,{isOpen:e,isBlackList:!0,onClose:()=>t(!1)}),(0,l.jsx)(o.default,{list:s,type:"BlackList",onAddDomain:()=>t(!0)})]})}}}]);
//# sourceMappingURL=SpamFilterBlackListPage.js.map?7476175b029fb3ad14ae