"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/FirewallIcmpPage"],{1122:(e,t,a)=>{a.r(t),a.d(t,{SORT_ASC:()=>m,SORT_DESC:()=>p,default:()=>y});var s=a(270),r=a(272),o=a.n(r),l=a(271),n=a(89);const i=n.Locale.getTranslate("components.list"),c=n.Locale.getSection("components.list"),m="ASC",p="DESC",g="all",u={set(e,t){localStorage.setItem(e,JSON.stringify(t))},get(e){const t=localStorage.getItem(e);return JSON.parse(t)}},d=e=>`list-sort_${e}`,f=e=>`list-page_${e}`,h=({id:e,data:t,columns:a,itemsPerPage:r=25,itemsPerPageOptions:o=[10,25,100,g],sortColumn:n,sortDirection:p=m,searchField:h,locale:y={},emptyView:P,emptyFilteredView:w,toolbar:b,selection:S=[],onSelectionChange:C,searchBarInputProps:x,rowKey:T="key",...j})=>{const{sortColumn:k,sortDirection:F,setSortState:L}=((e,{sortColumn:t,sortDirection:a})=>{const[{sortColumn:r,sortDirection:o},l]=(0,s.useState)({sortColumn:u.get(d(e))?.sortColumn??t,sortDirection:u.get(d(e))?.sortDirection??a});return{sortColumn:r,sortDirection:o,setSortState:t=>{l((e=>({...e,...t}))),u.set(d(e),{...u.get(d(e)),...t})}}})(e,{sortColumn:n??a.find((({sortable:e})=>e))?.key,sortDirection:p}),{page:R,itemsPerPage:D,searchPattern:M,setPageState:v}=((e,{itemsPerPage:t})=>{const[{page:a,itemsPerPage:r,searchPattern:o},l]=(0,s.useState)({page:u.get(f(e))?.page??1,itemsPerPage:u.get(f(e))?.itemsPerPage??t,searchPattern:u.get(f(e))?.searchPattern??""});return{page:a,itemsPerPage:r,searchPattern:o,setPageState:t=>{l((e=>({...e,...t}))),u.set(f(e),{...u.get(f(e)),...t})}}})(e,{itemsPerPage:o.includes(r)?r:o[0]}),O=(0,s.useMemo)((()=>M?w??(0,s.jsx)(l.ListEmptyView,{reason:"filtered",title:(0,s.jsx)(i,{content:"emptyViewFilteredTitle"}),description:(0,s.jsx)(i,{content:"emptyViewFilteredDescription"})}):P??(0,s.jsx)(l.ListEmptyView,{title:(0,s.jsx)(i,{content:"emptyViewTitle"})})),[M,P,w]),E=(0,s.useMemo)((()=>a.map((({sortDataField:e,...t})=>t))),[a]),I=(0,s.useMemo)((()=>h&&M?t.filter((e=>(Array.isArray(h)?h:[h]).some((t=>e[t]&&String(e[t]).toLowerCase().includes(M.toLowerCase()))))):t),[t,M,h]),V=(0,s.useMemo)((()=>{if(!k)return I;const e=a.find((({key:e})=>e===k))?.sortDataField??k,t=a.find((({key:e})=>e===k))?.sort??((t,a)=>t[e]<a[e]?-1:t[e]>a[e]?1:0);return[...I].sort(((e,a)=>m===F?t(e,a):t(a,e)))}),[I,k,F,a]),q=(0,s.useMemo)((()=>{if(D===g)return V;const e=D*(R-1),t=e+D;return V.slice(e,t)}),[R,V,D]),$=(0,s.useCallback)((e=>{v({searchPattern:e}),e!==M&&v({page:1})}),[M]),B=(0,s.useCallback)((e=>{v({itemsPerPage:e});(e===g?1:Math.ceil(I.length/e))<R&&v({page:1})}),[I.length,R]);return(0,s.useEffect)((()=>{if("function"==typeof C&&S.length){const e=I.map((e=>{return t=e,"function"==typeof(a=T)?a(t):t[a];var t,a})).filter((e=>S.includes(e)));C(e)}}),[I]),(0,s.jsx)(l.List,{pagination:(0,s.jsx)(l.Pagination,{current:R,total:D===g?1:Math.ceil(I.length/D),onSelect:e=>v({page:e}),itemsPerPage:D,itemsPerPageOptions:o,onItemsPerPageChange:B}),toolbar:(b||h)&&(0,s.jsxs)(l.Toolbar,{children:[b,h&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(l.ToolbarExpander,{}),(0,s.jsx)(l.ToolbarGroup,{title:"",children:(0,s.jsx)(l.SearchBar,{inputProps:{placeholder:c.lmsg("searchPlaceholder"),"data-testid":"list-searchbar",value:M,...x??{}},onTyping:$})})]})]}),totalRows:I.length,sortColumn:k,sortDirection:F,onSortChange:L,columns:E,data:q,filtered:!!M,locale:{totalRows:({totalRows:e})=>c.formatMessage("recordsTotal",{total:e}),...y},emptyView:O,onSelectionChange:C,selection:S,rowKey:T,...j})};h.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};const y=h},2006:(e,t,a)=>{a.r(t),a.d(t,{default:()=>f});var s=a(272),r=a(271),o=a(89),l=a(1122),n=a(496),i=a(620),c=a(270),m=a(531);const p=o.Locale.getTranslate("admin.components.lists.firewallicmprules"),g=o.Locale.getSection("admin.components.lists.firewallicmprules"),u=n.gql`
    mutation ToggleFirewallIcmpRuleStatus($key: String!, $enable: Boolean!) {
        toggleFirewallIcmpRule(input: { key: $key, enable: $enable }) {
            query {
                server {
                    firewall {
                        icmpRules {
                            key
                            isEnabled
                        }
                    }
                }
            }
        }
    }
`,d=({rules:e})=>{const[t,a]=(0,c.useState)([]),[s,{loading:o}]=(0,i.useMutation)(u),n=(0,c.useMemo)((()=>e.map((({key:e,...t})=>({key:e,name:g.lmsg(e.toLowerCase()),...t})))),[e]);return(0,c.jsx)(l.default,{id:"firewall-icmp-rules-list",columns:[{key:"status",title:(0,c.jsx)(p,{content:"status"}),sortable:!0,sortDataField:"isEnabled",width:"1%",render:({key:e,isEnabled:l})=>(0,c.jsx)(r.Switch,{id:`toggle-${e}`,tooltip:(0,c.jsx)(p,{content:l?"on":"off"}),checked:l,loading:o&&t.includes(e),onChange:()=>(async(e,t)=>{try{a((t=>[...t,e])),await s({variables:{key:e,enable:t}})}catch(e){(0,m.addToast)({intent:"danger",message:e.message})}finally{a((t=>t.filter((t=>t!==e))))}})(e,!l)})},{key:"name",title:(0,c.jsx)(p,{content:"name"}),type:"title",sortable:!0}],data:n,searchField:"name",sortColumn:"name"})};d.propTypes={rules:s.PropTypes.arrayOf(s.PropTypes.shape({key:s.PropTypes.string.isRequired,isEnabled:s.PropTypes.bool.isRequired})).isRequired};const f=d},2005:(e,t,a)=>{a.r(t),a.d(t,{default:()=>g});var s=a(89),r=a(313),o=a(597),l=a(2006),n=a(2002),i=a(586),c=a(805),m=a.n(c),p=a(270);const g=(0,o.withPageLayout)((0,n.withFirewallTabs)((()=>{const{data:{server:{firewall:{icmpRules:e}}}}=(0,i.useQuery)(m());return(0,p.jsx)(l.default,{rules:e})})),(()=>{const{showFrames:e,pageHeader:t,pageSidebar:a}=(0,r.default)();return{showFrames:e,pageHeader:{...t,helpMenu:{...t.helpMenu,helpContext:"firewall_icmp"}},pageSidebar:a,pageContentHeader:{breadcrumbs:[a.isPowerUserPanel?null:{title:s.Locale.getSection("components.pages.home").lmsg("title"),href:"/admin/home"},{title:s.Locale.getSection("admin.controllers.server.tools").lmsg("title"),href:"/admin/server/tools"},{title:s.Locale.getSection("components.pages.firewall").lmsg("title"),href:"/cp/firewall"},{title:s.Locale.getSection("components.pages.firewall-icmp").lmsg("title"),href:"/cp/firewall/icmp"}].filter(Boolean),tabs:[],tabsHasRootPage:!0}}}))},2002:(e,t,a)=>{a.r(t),a.d(t,{default:()=>p,withFirewallTabs:()=>m});var s=a(270),r=a(581),o=a(582),l=a(271),n=a(89),i=a(634);const c=()=>{const{pathname:e}=(0,r.useLocation)(),t=(0,s.useMemo)((()=>[{title:n.Locale.getSection("components.pages.firewall-general").lmsg("title"),url:"/cp/firewall/general",id:"tabGeneral"},{title:n.Locale.getSection("components.pages.firewall-icmp").lmsg("title"),url:"/cp/firewall/icmp",id:"tabIcmp"},{title:n.Locale.getSection("components.pages.firewall-rules").lmsg("title"),url:"/cp/firewall/rules",id:"tabRules"}]),[]),a=(0,s.useMemo)((()=>t.findIndex((({url:t})=>(0,o.matchPath)(t,e)))+1),[t,e]);return(0,s.jsx)(l.Tabs,{active:a,children:t.map((({url:e,...t})=>(0,s.jsx)(l.Tab,{component:i.default,to:e,...t},e)))})},m=e=>{const t=t=>(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(c,{...t}),(0,s.jsx)(e,{...t})]});return t.displayName=`withFirewallTabs(${e.displayName||e.name||"Component"})`,t.WrappedComponent=e,t},p=c}}]);
//# sourceMappingURL=FirewallIcmpPage.js.map?17cf3a46a4cbdfb9ee7b