"use strict";(globalThis.webpackChunkPlesk=globalThis.webpackChunkPlesk||[]).push([["components/pages/TrafficHistoryReportPage"],{1533(e,t,r){r.r(t),r.d(t,{SORT_ASC:()=>l,SORT_DESC:()=>c,default:()=>d});var o=r(372),a=r(762),s=r.n(a),n=r(373);const i=r(95).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:a=25,itemsPerPageOptions:s=[10,25,100,g],sortColumn:c,sortDirection:P=l,searchField:d,locale:h={},emptyView:f,emptyFilteredView:y,toolbar:S,selection:C=[],onSelectionChange:w,searchBarInputProps:b,rowKey:j="key",useStorage:x=!0,...k})=>{const{sortColumn:B,sortDirection:D,setSortState:T}=((e,{sortColumn:t,sortDirection:r})=>{const[{sortColumn:a,sortDirection:s},n]=(0,o.useState)({sortColumn:u.get(m(e))?.sortColumn??t,sortDirection:u.get(m(e))?.sortDirection??r});return{sortColumn:a,sortDirection:s,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 a=r?{page:u.get(p(e))?.page,itemsPerPage:u.get(p(e))?.itemsPerPage,searchPattern:u.get(p(e))?.searchPattern}:{},[{page:s,itemsPerPage:n,searchPattern:i},l]=(0,o.useState)({page:a.page??1,itemsPerPage:a.itemsPerPage??t,searchPattern:a.searchPattern??""});return{page:s,itemsPerPage:n,searchPattern:i,setPageState:t=>{l(e=>({...e,...t})),r&&u.set(p(e),{...u.get(p(e)),...t})}}})(e,{itemsPerPage:s.includes(a)?a:s[0]},x),E=(0,o.useMemo)(()=>R?y??(0,o.jsx)(n.ListEmptyView,{reason:"filtered","data-testid":"list-empty-view-filtered"}):f??(0,o.jsx)(n.ListEmptyView,{}),[R,f,y]),F=(0,o.useMemo)(()=>r.map(({sortDataField:e,...t})=>t),[r]),L=(0,o.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,o.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,o.useMemo)(()=>{if(O===g)return v;const e=O*(M-1),t=e+O;return v.slice(e,t)},[M,v,O]),I=(0,o.useCallback)(e=>{V({searchPattern:e}),e!==R&&V({page:1})},[R]),K=(0,o.useCallback)(e=>{V({itemsPerPage:e});(e===g?1:Math.ceil(L.length/e))<M&&V({page:1})},[L.length,M]);return(0,o.useEffect)(()=>{if("function"==typeof w&&C.length){const e=L.map(e=>{return t=e,"function"==typeof(r=j)?r(t):t[r];var t,r}).filter(e=>C.includes(e));w(e)}},[L]),(0,o.jsx)(n.List,{pagination:(0,o.jsx)(n.Pagination,{current:M,total:O===g?1:Math.ceil(L.length/O),onSelect:e=>V({page:e}),itemsPerPage:O,itemsPerPageOptions:s,onItemsPerPageChange:K}),toolbar:(S||d)&&(0,o.jsxs)(n.Toolbar,{children:[S,d&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(n.ToolbarExpander,{}),(0,o.jsx)(n.ToolbarGroup,{title:"",children:(0,o.jsx)(n.SearchBar,{inputProps:{placeholder:i.lmsg("searchPlaceholder"),"data-testid":"list-searchbar",value:R,...b??{}},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}),...h},emptyView:E,onSelectionChange:w,selection:C,rowKey:j,...k})};P.propTypes={id:s().string.isRequired,data:s().array.isRequired,columns:s().array.isRequired,itemsPerPage:s().number,itemsPerPageOptions:s().array,sortColumn:s().string,sortDirection:s().string,searchField:s().oneOfType([s().string,s().arrayOf(s().string.isRequired)]),locale:s().object,emptyView:s().node,emptyFilteredView:s().node,toolbar:s().node,onSelectionChange:s().func,selection:s().array,rowKey:s().oneOfType([s().string,s().func]),searchBarInputProps:s().object,useStorage:s().bool};const d=P},2878(e,t,r){r.r(t),r.d(t,{default:()=>p});var o=r(95),a=r(373),s=r(714),n=r(1301),i=r.n(n),l=r(1546),c=r(1533),g=r(372);const u=o.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,s.useQuery)(i());return(0,g.jsx)(c.default,{id:"traffic-history-report",emptyView:(0,g.jsx)(a.ListEmptyView,{title:(0,g.jsx)(u,{content:"noData"})}),columns:m,data:e,rowKey:({year:e,month:t})=>`${e} ${t}`})}},1546(e,t,r){r.r(t),r.d(t,{formatByteSize:()=>a});const o=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],a=e=>{if(!e)return"0 B";const t=Math.floor(Math.log(e)/Math.log(1024));return`${(e/1024**t).toFixed(2)} ${o[t]}`}}}]);
//# sourceMappingURL=TrafficHistoryReportPage.js.map?f39b2e01b9153d841363