"use strict";(globalThis.webpackChunkPlesk=globalThis.webpackChunkPlesk||[]).push([["components/pages/SpamFilterBlackListPage"],{1526(e,t,s){s.r(t),s.d(t,{SORT_ASC:()=>l,SORT_DESC:()=>d,default:()=>y});var n=s(372),a=s(757),o=s.n(a),i=s(373);const r=s(90).Locale.getSection("components.list"),l="ASC",d="DESC",c="all",u={set(e,t){localStorage.setItem(e,JSON.stringify(t))},get(e){const t=localStorage.getItem(e);return JSON.parse(t)}},m=e=>`list-sort_${e}`,p=e=>`list-page_${e}`,g=({id:e,data:t,columns:s,itemsPerPage:a=25,itemsPerPageOptions:o=[10,25,100,c],sortColumn:d,sortDirection:g=l,searchField:y,locale:h={},emptyView:f,emptyFilteredView:P,toolbar:x,selection:T=[],onSelectionChange:S,searchBarInputProps:b,rowKey:j="key",useStorage:C=!0,...L})=>{const{sortColumn:F,sortDirection:A,setSortState:w}=((e,{sortColumn:t,sortDirection:s})=>{const[{sortColumn:a,sortDirection:o},i]=(0,n.useState)({sortColumn:u.get(m(e))?.sortColumn??t,sortDirection:u.get(m(e))?.sortDirection??s});return{sortColumn:a,sortDirection:o,setSortState:t=>{i(e=>({...e,...t})),u.set(m(e),{...u.get(m(e)),...t})}}})(e,{sortColumn:d??s.find(({sortable:e})=>e)?.key,sortDirection:g}),{page:k,itemsPerPage:D,searchPattern:v,setPageState:B}=((e,{itemsPerPage:t},s=!0)=>{const a=s?{page:u.get(p(e))?.page,itemsPerPage:u.get(p(e))?.itemsPerPage,searchPattern:u.get(p(e))?.searchPattern}:{},[{page:o,itemsPerPage:i,searchPattern:r},l]=(0,n.useState)({page:a.page??1,itemsPerPage:a.itemsPerPage??t,searchPattern:a.searchPattern??""});return{page:o,itemsPerPage:i,searchPattern:r,setPageState:t=>{l(e=>({...e,...t})),s&&u.set(p(e),{...u.get(p(e)),...t})}}})(e,{itemsPerPage:o.includes(a)?a:o[0]},C),R=(0,n.useMemo)(()=>v?P??(0,n.jsx)(i.ListEmptyView,{reason:"filtered","data-testid":"list-empty-view-filtered"}):f??(0,n.jsx)(i.ListEmptyView,{}),[v,f,P]),M=(0,n.useMemo)(()=>s.map(({sortDataField:e,...t})=>t),[s]),O=(0,n.useMemo)(()=>y&&v?t.filter(e=>(Array.isArray(y)?y:[y]).some(t=>e[t]&&String(e[t]).toLowerCase().includes(v.toLowerCase()))):t,[t,v,y]),E=(0,n.useMemo)(()=>{if(!F)return O;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[...O].sort((e,s)=>l===A?t(e,s):t(s,e))},[O,F,A,s]),q=(0,n.useMemo)(()=>{if(D===c)return E;const e=D*(k-1),t=e+D;return E.slice(e,t)},[k,E,D]),$=(0,n.useCallback)(e=>{B({searchPattern:e}),e!==v&&B({page:1})},[v]),I=(0,n.useCallback)(e=>{B({itemsPerPage:e});(e===c?1:Math.ceil(O.length/e))<k&&B({page:1})},[O.length,k]);return(0,n.useEffect)(()=>{if("function"==typeof S&&T.length){const e=O.map(e=>{return t=e,"function"==typeof(s=j)?s(t):t[s];var t,s}).filter(e=>T.includes(e));S(e)}},[O]),(0,n.jsx)(i.List,{pagination:(0,n.jsx)(i.Pagination,{current:k,total:D===c?1:Math.ceil(O.length/D),onSelect:e=>B({page:e}),itemsPerPage:D,itemsPerPageOptions:o,onItemsPerPageChange:I}),toolbar:(x||y)&&(0,n.jsxs)(i.Toolbar,{children:[x,y&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(i.ToolbarExpander,{}),(0,n.jsx)(i.ToolbarGroup,{title:"",children:(0,n.jsx)(i.SearchBar,{inputProps:{placeholder:r.lmsg("searchPlaceholder"),"data-testid":"list-searchbar",value:v,...b??{}},onTyping:$})})]})]}),totalRows:O.length,sortColumn:F,sortDirection:A,onSortChange:w,columns:M,data:q,filtered:!!v,locale:{totalRows:({totalRows:e})=>r.formatMessage("recordsTotal",{total:e}),...h},emptyView:R,onSelectionChange:S,selection:T,rowKey:j,...L})};g.propTypes={id:o().string.isRequired,data:o().array.isRequired,columns:o().array.isRequired,itemsPerPage:o().number,itemsPerPageOptions:o().array,sortColumn:o().string,sortDirection:o().string,searchField:o().oneOfType([o().string,o().arrayOf(o().string.isRequired)]),locale:o().object,emptyView:o().node,emptyFilteredView:o().node,toolbar:o().node,onSelectionChange:o().func,selection:o().array,rowKey:o().oneOfType([o().string,o().func]),searchBarInputProps:o().object,useStorage:o().bool};const y=g},2769(e,t,s){s.r(t),s.d(t,{default:()=>S});var n=s(757),a=s(373),o=s(90),i=s(372),r=s(780),l=s(671),d=s(634),c=s(1397),u=s(1389),m=s.n(u),p=s(1394),g=s.n(p);const y=o.Locale.getTranslate("components.forms.spam-filter.add"),h=o.Locale.getSection("components.forms.spam-filter.add"),f=l.gql`
    mutation AddAddressesToSpamFilterList($input: AddAddressesToSpamFilterListInput!) {
        addAddressesToSpamFilterList(input: $input) {
            warnings
        }
    }
`,P="file",x="string",T=({isBlackList:e,isOpen:t=!1,onClose:s})=>{const[n,o]=(0,i.useState)({dataType:P,file:null,addresses:""}),[l,{loading:u}]=(0,r.useMutation)(f,{refetchQueries:[{query:e?m():g()}],awaitRefetchQueries:!0});return(0,i.jsx)(a.Drawer,{"data-type":"add-domain-to-spam-filter-list",title:(0,i.jsx)(y,{content:e?"titleBlack":"titleWhite"}),isOpen:t,onClose:s,size:"sm",form:(0,i.jsxs)(c.default,{state:u?"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,i.jsx)(y,{content:"success"})}),s(),o({dataType:P,file:null,addresses:""})},onFieldChange:(e,t)=>o((0,a.setIn)(n,e,t)),values:n,mutation:l,children:[(0,i.jsx)(a.Text,{component:"p",children:(0,i.jsx)("div",{dangerouslySetInnerHTML:{__html:h.lmsg("listDescription")}})}),(0,i.jsx)(a.FormFieldRadioButtons,{label:null,name:"dataType",options:[{value:P,label:(0,i.jsx)(y,{content:"fromFile"}),indentFields:[(0,i.jsx)(a.FormField,{name:"file",label:null,description:(0,i.jsx)(y,{content:"fileDescription"}),children:({getId:e,getName:t,setValue:s,isDisabled:n})=>(0,i.jsx)(a.InputFile,{id:e(),name:t(),disabled:n(),onChange:e=>s(e)})},"file")]},{value:x,label:(0,i.jsx)(y,{content:"fromList"}),indentFields:[(0,i.jsx)(a.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};const S=T},2768(e,t,s){s.r(t),s.d(t,{default:()=>S});var n=s(757),a=s(373),o=s(90),i=s(1526),r=s(372),l=s(634),d=s(780),c=s(671),u=s(1389),m=s.n(u),p=s(1394),g=s.n(p);const y=o.Locale.getTranslate("components.lists.spam-filter"),h=o.Locale.getSection("components.lists.spam-filter"),f=o.Locale.getTranslate("components.buttons"),P="BlackList",x=c.gql`
    mutation DeleteAddressesFromSpamFilterList($input: DeleteAddressesFromSpamFilterListInput!) {
        deleteAddressesFromSpamFilterList(input: $input) {
            __typename
        }
    }
`,T=({list:e,type:t,onAddDomain:s})=>{const[n,o]=(0,r.useState)([]),[c,u]=(0,r.useState)([]),p=(0,r.useMemo)(()=>e.filter(({id:e})=>n.includes(e)),[e,n]),[T]=(0,d.useMutation)(x,{refetchQueries:[{query:"BlackList"===t?m():g()}],awaitRefetchQueries:!0});return(0,r.jsx)(i.default,{id:`server-mail-${t}`,toolbar:(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(a.ToolbarGroup,{title:h.lmsg("groupAdd"),children:(0,r.jsx)(a.Button,{id:`add${t}edDomain`,intent:"primary",icon:"plus",tooltip:h.lmsg(t===P?"buttonAddAddressToBlackListHint":"buttonAddAddressToWhiteListHint"),tooltipAsLabel:!0,onClick:s})}),(0,r.jsx)(a.ToolbarGroup,{title:h.lmsg("groupActions"),children:(0,r.jsx)(a.ListOperation,{critical:!0,noSelectionText:(0,r.jsx)(y,{content:"removeEmptySelection"}),confirmationText:h.formatMessage("removeConfirmation",{name:(0,r.jsx)("b",{children:p[0]?.name}),count:p.length}),actionButtonText:(0,r.jsx)(f,{content:"yesRemove"}),cancelButtonText:(0,r.jsx)(f,{content:"cancel"}),children:(0,r.jsx)(a.Button,{id:`remove${t}edDomain`,onClick:async()=>{u(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{o([]),u([])}},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=>o(e),loadingRows:c,emptyView:(0,r.jsx)(a.ListEmptyView,{title:(0,r.jsx)(y,{content:`addAddressTo${t}EmptyTitle`}),description:(0,r.jsx)(y,{content:`addAddressTo${t}EmptyDescription`}),actions:(0,r.jsx)(a.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 S=T},2767(e,t,s){s.r(t),s.d(t,{default:()=>d});var n=s(709),a=s(2768),o=s(2769),i=s(1389),r=s.n(i),l=s(372);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)(o.default,{isOpen:e,isBlackList:!0,onClose:()=>t(!1)}),(0,l.jsx)(a.default,{list:s,type:"BlackList",onAddDomain:()=>t(!0)})]})}}}]);
//# sourceMappingURL=SpamFilterBlackListPage.js.map?7a58b022e538a65fb110