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