"use strict";(globalThis.webpackChunk_wcAdmin_webpackJsonp=globalThis.webpackChunk_wcAdmin_webpackJsonp||[]).push([[727],{15850:(e,r,t)=>{t.r(r),t.d(r,{default:()=>C});var a=t(69307),o=t(65736),s=t(94333),l=t(7862),n=t.n(l),d=t(55609),i=t(9818),c=t(86020),m=t(67221),u=t(14599),b=t(37708),g=t(10431),p=t(17844),h=t(81595),w=t(14812),y=t(346);const _=new Set(["currency","number"]);class E extends a.Component{constructor(...e){super(...e),(0,b.Z)(this,"getFormattedColumn",(e=>{const{format:r}=e;if(_.has(e.format)&&isFinite(e.value)){const t=parseFloat(e.value);if(!Number.isNaN(t)){const{formatAmount:e,getCurrencyConfig:a}=this.context;return{display:"currency"===r?e(t):(0,h.formatValue)(a(),r,t),value:t}}}return{display:(0,a.createElement)("div",{dangerouslySetInnerHTML:(0,y.ZP)(e.display)}),value:e.value}}))}getFormattedHeaders(){return this.props.headers.map(((e,r)=>({isLeftAligned:0===r,hiddenByDefault:!1,isSortable:!1,key:e.label,label:e.label})))}getFormattedRows(){return this.props.rows.map((e=>e.map(this.getFormattedColumn)))}render(){const{isRequesting:e,isError:r,totalRows:t,title:s}=this.props,l="woocommerce-leaderboard";if(r)return(0,a.createElement)(c.AnalyticsError,{className:l});const n=this.getFormattedRows();return e||0!==n.length?(0,a.createElement)(c.TableCard,{className:l,headers:this.getFormattedHeaders(),isLoading:e,rows:n,rowsPerPage:t,showMenu:!1,title:s,totalRows:t}):(0,a.createElement)(d.Card,{className:l},(0,a.createElement)(d.CardHeader,null,(0,a.createElement)(w.Text,{size:16,weight:600,as:"h3",color:"#23282d"},s)),(0,a.createElement)(d.CardBody,{size:null},(0,a.createElement)(c.EmptyTable,null,(0,o.__)("No data recorded for the selected time period.","woocommerce"))))}}E.propTypes={headers:n().arrayOf(n().shape({label:n().string})),id:n().string.isRequired,query:n().object,rows:n().arrayOf(n().arrayOf(n().shape({display:n().node,value:n().oneOfType([n().string,n().number,n().bool])}))).isRequired,title:n().string.isRequired,totalRows:n().number.isRequired},E.defaultProps={rows:[],isError:!1,isRequesting:!1},E.contextType=p.CurrencyContext;const f=(0,s.compose)((0,i.withSelect)(((e,r)=>{const{id:t,query:a,totalRows:o,filters:s}=r,{woocommerce_default_date_range:l}=e(m.SETTINGS_STORE_NAME).getSetting("wc_admin","wcAdminSettings"),n=(0,m.getFilterQuery)({filters:s,query:a}),d={id:t,per_page:o,persisted_query:(0,g.getPersistedQuery)(a),query:a,select:e,defaultDateRange:l,filterQuery:n};return(0,m.getLeaderboard)(d)})))(E);var T=t(17062);const k=e=>{const{allLeaderboards:r,controls:t,isFirst:s,isLast:l,hiddenBlocks:n,onMove:i,onRemove:b,onTitleBlur:g,onTitleChange:p,onToggleHiddenBlock:h,query:w,title:y,titleInput:_,filters:E}=e,{updateUserPreferences:T,...k}=(0,m.useUserPreferences)(),[C,R]=(0,a.useState)(parseInt(k.dashboard_leaderboard_rows||5,10)),v=e=>{R(parseInt(e,10));const r={dashboard_leaderboard_rows:parseInt(e,10)};T(r)};return(0,a.createElement)(a.Fragment,null,(0,a.createElement)("div",{className:"woocommerce-dashboard__dashboard-leaderboards"},(0,a.createElement)(c.SectionHeader,{title:y||(0,o.__)("Leaderboards","woocommerce"),menu:(0,a.createElement)(c.EllipsisMenu,{label:(0,o.__)("Choose which leaderboards to display and other settings","woocommerce"),renderContent:({onToggle:e})=>(0,a.createElement)(a.Fragment,null,(0,a.createElement)(c.MenuTitle,null,(0,o.__)("Leaderboards","woocommerce")),(({allLeaderboards:e,hiddenBlocks:r,onToggleHiddenBlock:t})=>e.map((e=>{const o=!r.includes(e.id);return(0,a.createElement)(c.MenuItem,{checked:o,isCheckbox:!0,isClickable:!0,key:e.id,onInvoke:()=>{t(e.id)(),(0,u.recordEvent)("dash_leaderboards_toggle",{status:o?"off":"on",key:e.id})}},e.label)})))({allLeaderboards:r,hiddenBlocks:n,onToggleHiddenBlock:h}),(0,a.createElement)(c.MenuItem,null,(0,a.createElement)(d.SelectControl,{className:"woocommerce-dashboard__dashboard-leaderboards__select",label:(0,o.__)("Rows per table","woocommerce"),value:C,options:Array.from({length:20},((e,r)=>({v:r+1,label:r+1}))),onChange:v})),(0,a.createElement)(t,{onToggle:e,onMove:i,onRemove:b,isFirst:s,isLast:l,onTitleBlur:g,onTitleChange:p,titleInput:_}))})}),(0,a.createElement)("div",{className:"woocommerce-dashboard__columns"},(({allLeaderboards:e,hiddenBlocks:r,query:t,rowsPerTable:o,filters:s})=>e.map((e=>{if(!r.includes(e.id))return(0,a.createElement)(f,{headers:e.headers,id:e.id,key:e.id,query:t,title:e.label,totalRows:o,filters:s})})))({allLeaderboards:r,hiddenBlocks:n,query:w,rowsPerTable:C,filters:E}))))};k.propTypes={query:n().object.isRequired};const C=(0,s.compose)((0,i.withSelect)((e=>{const{getItems:r,getItemsError:t}=e(m.ITEMS_STORE_NAME),{leaderboards:a}=(0,T.O3)("dataEndpoints",{leaderboards:[]});return{allLeaderboards:a,getItems:r,getItemsError:t}})))(k)}}]);