"use strict";(self.webpackChunkPlesk=self.webpackChunkPlesk||[]).push([["components/pages/TrafficHistoryReportPage"],{1407:(e,t,r)=>{r.r(t),r.d(t,{SORT_ASC:()=>l,SORT_DESC:()=>c,default:()=>d});var s=r(285),o=r(591),a=r.n(o),n=r(286);const i=r(89).Locale.getSection("components.list"),l="ASC",c="DESC",g="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}`,P=({id:e,data:t,columns:r,itemsPerPage:o=25,itemsPerPageOptions:a=[10,25,100,g],sortColumn:c,sortDirection:P=l,searchField:d,locale:f={},emptyView:y,emptyFilteredView:h,toolbar:S,selection:C=[],onSelectionChange:w,searchBarInputProps:j,rowKey:x="key",useStorage:b=!0,...k})=>{const{sortColumn:B,sortDirection:D,setSortState:T}=((e,{sortColumn:t,sortDirection:r})=>{const[{sortColumn:o,sortDirection:a},n]=(0,s.useState)({sortColumn:u.get(m(e))?.sortColumn??t,sortDirection:u.get(m(e))?.sortDirection??r});return{sortColumn:o,sortDirection:a,setSortState:t=>{n((e=>({...e,...t}))),u.set(m(e),{...u.get(m(e)),...t})}}})(e,{sortColumn:c??r.find((({sortable:e})=>e))?.key,sortDirection:P}),{page:M,itemsPerPage:O,searchPattern:R,setPageState:V}=((e,{itemsPerPage:t},r=!0)=>{const o=r?{page:u.get(p(e))?.page,itemsPerPage:u.get(p(e))?.itemsPerPage,searchPattern:u.get(p(e))?.searchPattern}:{},[{page:a,itemsPerPage:n,searchPattern:i},l]=(0,s.useState)({page:o.page??1,itemsPerPage:o.itemsPerPage??t,searchPattern:o.searchPattern??""});return{page:a,itemsPerPage:n,searchPattern:i,setPageState:t=>{l((e=>({...e,...t}))),r&&u.set(p(e),{...u.get(p(e)),...t})}}})(e,{itemsPerPage:a.includes(o)?o:a[0]},b),E=(0,s.useMemo)((()=>R?h??(0,s.jsx)(n.ListEmptyView,{reason:"filtered","data-testid":"list-empty-view-filtered"}):y??(0,s.jsx)(n.ListEmptyView,{})),[R,y,h]),F=(0,s.useMemo)((()=>r.map((({sortDataField:e,...t})=>t))),[r]),L=(0,s.useMemo)((()=>d&&R?t.filter((e=>(Array.isArray(d)?d:[d]).some((t=>e[t]&&String(e[t]).toLowerCase().includes(R.toLowerCase()))))):t),[t,R,d]),v=(0,s.useMemo)((()=>{if(!B)return L;const e=r.find((({key:e})=>e===B))?.sortDataField??B,t=r.find((({key:e})=>e===B))?.sort??((t,r)=>t[e]<r[e]?-1:t[e]>r[e]?1:0);return[...L].sort(((e,r)=>l===D?t(e,r):t(r,e)))}),[L,B,D,r]),$=(0,s.useMemo)((()=>{if(O===g)return v;const e=O*(M-1),t=e+O;return v.slice(e,t)}),[M,v,O]),I=(0,s.useCallback)((e=>{V({searchPattern:e}),e!==R&&V({page:1})}),[R]),K=(0,s.useCallback)((e=>{V({itemsPerPage:e});(e===g?1:Math.ceil(L.length/e))<M&&V({page:1})}),[L.length,M]);return(0,s.useEffect)((()=>{if("function"==typeof w&&C.length){const e=L.map((e=>{return t=e,"function"==typeof(r=x)?r(t):t[r];var t,r})).filter((e=>C.includes(e)));w(e)}}),[L]),(0,s.jsx)(n.List,{pagination:(0,s.jsx)(n.Pagination,{current:M,total:O===g?1:Math.ceil(L.length/O),onSelect:e=>V({page:e}),itemsPerPage:O,itemsPerPageOptions:a,onItemsPerPageChange:K}),toolbar:(S||d)&&(0,s.jsxs)(n.Toolbar,{children:[S,d&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(n.ToolbarExpander,{}),(0,s.jsx)(n.ToolbarGroup,{title:"",children:(0,s.jsx)(n.SearchBar,{inputProps:{placeholder:i.lmsg("searchPlaceholder"),"data-testid":"list-searchbar",value:R,...j??{}},onTyping:I})})]})]}),totalRows:L.length,sortColumn:B,sortDirection:D,onSortChange:T,columns:F,data:$,filtered:!!R,locale:{totalRows:({totalRows:e})=>i.formatMessage("recordsTotal",{total:e}),...f},emptyView:E,onSelectionChange:w,selection:C,rowKey:x,...k})};P.propTypes={id:a().string.isRequired,data:a().array.isRequired,columns:a().array.isRequired,itemsPerPage:a().number,itemsPerPageOptions:a().array,sortColumn:a().string,sortDirection:a().string,searchField:a().oneOfType([a().string,a().arrayOf(a().string.isRequired)]),locale:a().object,emptyView:a().node,emptyFilteredView:a().node,toolbar:a().node,onSelectionChange:a().func,selection:a().array,rowKey:a().oneOfType([a().string,a().func]),searchBarInputProps:a().object,useStorage:a().bool};const d=P},2683:(e,t,r)=>{r.r(t),r.d(t,{default:()=>p});var s=r(89),o=r(286),a=r(581),n=r(1132),i=r.n(n),l=r(1421),c=r(1407),g=r(285);const u=s.Locale.getTranslate("admin.components.lists.traffichistory"),m=[{key:"year",title:(0,g.jsx)(u,{content:"year"})},{key:"month",title:(0,g.jsx)(u,{content:"month"})},{key:"trafficUsage",title:(0,g.jsx)(u,{content:"trafficUsage"}),render:({trafficUsage:e})=>(0,l.formatByteSize)(e),align:"right"}],p=()=>{const{data:{viewer:{client:{trafficHistory:e}}}}=(0,a.useQuery)(i());return(0,g.jsx)(c.default,{id:"traffic-history-report",emptyView:(0,g.jsx)(o.ListEmptyView,{title:(0,g.jsx)(u,{content:"noData"})}),columns:m,data:e,rowKey:({year:e,month:t})=>`${e} ${t}`})}},1421:(e,t,r)=>{r.r(t),r.d(t,{formatByteSize:()=>o});const s=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],o=e=>{if(!e)return"0 B";const t=Math.floor(Math.log(e)/Math.log(1024));return`${(e/1024**t).toFixed(2)} ${s[t]}`}}}]);
//# sourceMappingURL=TrafficHistoryReportPage.js.map?1c727e928e05a312fe79