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