"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/FirewallIcmpPage"],{1067:(e,t,a)=>{a.r(t),a.d(t,{SORT_ASC:()=>m,SORT_DESC:()=>p,default:()=>P});var s=a(270),r=a(272),o=a.n(r),l=a(271),i=a(89);const n=i.Locale.getTranslate("components.list"),c=i.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}`,h=e=>`list-page_${e}`,f=({id:e,data:t,columns:a,itemsPerPage:r=25,itemsPerPageOptions:o=[10,25,100,g],sortColumn:i,sortDirection:p=m,searchField:f,locale:P={},emptyView:y,emptyFilteredView:w,toolbar:b,selection:S=[],onSelectionChange:C,searchBarInputProps:x,rowKey:T="key",useStorage:j=!0,...k})=>{const{sortColumn:F,sortDirection:L,setSortState:R}=((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:i??a.find((({sortable:e})=>e))?.key,sortDirection:p}),{page:D,itemsPerPage:M,searchPattern:v,setPageState:O}=((e,{itemsPerPage:t},a=!0)=>{const r=a?{page:u.get(h(e))?.page,itemsPerPage:u.get(h(e))?.itemsPerPage,searchPattern:u.get(h(e))?.searchPattern}:{},[{page:o,itemsPerPage:l,searchPattern:i},n]=(0,s.useState)({page:r.page??1,itemsPerPage:r.itemsPerPage??t,searchPattern:r.searchPattern??""});return{page:o,itemsPerPage:l,searchPattern:i,setPageState:t=>{n((e=>({...e,...t}))),a&&u.set(h(e),{...u.get(h(e)),...t})}}})(e,{itemsPerPage:o.includes(r)?r:o[0]},j),E=(0,s.useMemo)((()=>v?w??(0,s.jsx)(l.ListEmptyView,{reason:"filtered",title:(0,s.jsx)(n,{content:"emptyViewFilteredTitle"}),description:(0,s.jsx)(n,{content:"emptyViewFilteredDescription"}),"data-testid":"list-empty-view-filtered"}):y??(0,s.jsx)(l.ListEmptyView,{title:(0,s.jsx)(n,{content:"emptyViewTitle"})})),[v,y,w]),I=(0,s.useMemo)((()=>a.map((({sortDataField:e,...t})=>t))),[a]),V=(0,s.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]),q=(0,s.useMemo)((()=>{if(!F)return V;const e=a.find((({key:e})=>e===F))?.sortDataField??F,t=a.find((({key:e})=>e===F))?.sort??((t,a)=>t[e]<a[e]?-1:t[e]>a[e]?1:0);return[...V].sort(((e,a)=>m===L?t(e,a):t(a,e)))}),[V,F,L,a]),$=(0,s.useMemo)((()=>{if(M===g)return q;const e=M*(D-1),t=e+M;return q.slice(e,t)}),[D,q,M]),B=(0,s.useCallback)((e=>{O({searchPattern:e}),e!==v&&O({page:1})}),[v]),_=(0,s.useCallback)((e=>{O({itemsPerPage:e});(e===g?1:Math.ceil(V.length/e))<D&&O({page:1})}),[V.length,D]);return(0,s.useEffect)((()=>{if("function"==typeof C&&S.length){const e=V.map((e=>{return t=e,"function"==typeof(a=T)?a(t):t[a];var t,a})).filter((e=>S.includes(e)));C(e)}}),[V]),(0,s.jsx)(l.List,{pagination:(0,s.jsx)(l.Pagination,{current:D,total:M===g?1:Math.ceil(V.length/M),onSelect:e=>O({page:e}),itemsPerPage:M,itemsPerPageOptions:o,onItemsPerPageChange:_}),toolbar:(b||f)&&(0,s.jsxs)(l.Toolbar,{children:[b,f&&(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:v,...x??{}},onTyping:B})})]})]}),totalRows:V.length,sortColumn:F,sortDirection:L,onSortChange:R,columns:I,data:$,filtered:!!v,locale:{totalRows:({totalRows:e})=>c.formatMessage("recordsTotal",{total:e}),...P},emptyView:E,onSelectionChange:C,selection:S,rowKey:T,...k})};f.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 P=f},2093:(e,t,a)=>{a.r(t),a.d(t,{default:()=>h});var s=a(272),r=a(271),o=a(89),l=a(1067),i=a(495),n=a(618),c=a(270),m=a(531);const p=o.Locale.getTranslate("admin.components.lists.firewallicmprules"),g=o.Locale.getSection("admin.components.lists.firewallicmprules"),u=i.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,n.useMutation)(u),i=(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:i,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 h=d},2092:(e,t,a)=>{a.r(t),a.d(t,{default:()=>g});var s=a(89),r=a(313),o=a(592),l=a(2093),i=a(2089),n=a(581),c=a(850),m=a.n(c),p=a(270);const g=(0,o.withPageLayout)((0,i.withFirewallTabs)((()=>{const{data:{server:{firewall:{icmpRules:e}}}}=(0,n.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}}}))},2089:(e,t,a)=>{a.r(t),a.d(t,{default:()=>p,withFirewallTabs:()=>m});var s=a(270),r=a(575),o=a(576),l=a(271),i=a(89),n=a(636);const c=()=>{const{pathname:e}=(0,r.useLocation)(),t=(0,s.useMemo)((()=>[{title:i.Locale.getSection("components.pages.firewall-general").lmsg("title"),url:"/cp/firewall/general",id:"tabGeneral"},{title:i.Locale.getSection("components.pages.firewall-icmp").lmsg("title"),url:"/cp/firewall/icmp",id:"tabIcmp"},{title:i.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:n.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?b60d3aee9bb94e2d6f9a