"use strict";(globalThis.webpackChunk_wcAdmin_webpackJsonp=globalThis.webpackChunk_wcAdmin_webpackJsonp||[]).push([[823],{26652:(e,r,s)=>{s.r(r),s.d(r,{default:()=>C});var o=s(27723),t=s(86087),a=s(56427),d=s(98846),l=s(40314),n=s(83306),i=s(29491),c=s(47143),u=s(96476),m=s(94111),h=s(43577),b=s(14908),g=s(35888),p=s(39793);const w=new Set(["currency","number"]);class _ extends t.Component{getFormattedColumn=e=>{const{format:r}=e;if(w.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,h.formatValue)(o(),r,s),value:s}}}return{display:(0,p.jsx)("div",{dangerouslySetInnerHTML:(0,g.A)(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,l="woocommerce-leaderboard";if(r)return(0,p.jsx)(d.AnalyticsError,{className:l});const n=this.getFormattedRows();return e||0!==n.length?(0,p.jsx)(d.TableCard,{className:l,headers:this.getFormattedHeaders(),isLoading:e,rows:n,rowsPerPage:s,showMenu:!1,title:t,totalRows:s}):(0,p.jsxs)(a.Card,{className:l,children:[(0,p.jsx)(a.CardHeader,{children:(0,p.jsx)(b.Text,{size:16,weight:600,as:"h3",color:"#23282d",children:t})}),(0,p.jsx)(a.CardBody,{size:null,children:(0,p.jsx)(d.EmptyTable,{children:(0,o.__)("No data recorded for the selected time period.","woocommerce")})})]})}}_.defaultProps={rows:[],isError:!1,isRequesting:!1},_.contextType=m.CurrencyContext;const f=(0,i.compose)((0,c.withSelect)(((e,r)=>{const{id:s,query:o,totalRows:t,filters:a}=r,{woocommerce_default_date_range:d}=e(l.settingsStore).getSetting("wc_admin","wcAdminSettings"),n=(0,l.getFilterQuery)({filters:a,query:o}),i={id:s,per_page:t,persisted_query:(0,u.getPersistedQuery)(o),query:o,select:e,defaultDateRange:d,filterQuery:n};return(0,l.getLeaderboard)(i)})))(_);var y=s(98467);const x=({allLeaderboards:e,hiddenBlocks:r,onToggleHiddenBlock:s})=>e.map((e=>{const o=!r.includes(e.id);return(0,p.jsx)(d.MenuItem,{checked:o,isCheckbox:!0,isClickable:!0,onInvoke:()=>{s(e.id)(),(0,n.recordEvent)("dash_leaderboards_toggle",{status:o?"off":"on",key:e.id})},children:e.label},e.id)})),j=({allLeaderboards:e,hiddenBlocks:r,query:s,rowsPerTable:o,filters:t})=>e.map((e=>{if(!r.includes(e.id))return(0,p.jsx)(f,{headers:e.headers,id:e.id,query:s,title:e.label,totalRows:o,filters:t},e.id)})),k=e=>{const{allLeaderboards:r,controls:s,isFirst:n,isLast:i,hiddenBlocks:c,onMove:u,onRemove:m,onTitleBlur:h,onTitleChange:b,onToggleHiddenBlock:g,query:w,title:_,titleInput:f,filters:y}=e,{updateUserPreferences:k,...C}=(0,l.useUserPreferences)(),[T,v]=(0,t.useState)(parseInt(C.dashboard_leaderboard_rows||5,10)),L=e=>{v(parseInt(e,10));const r={dashboard_leaderboard_rows:parseInt(e,10)};k(r)};return(0,p.jsx)(t.Fragment,{children:(0,p.jsxs)("div",{className:"woocommerce-dashboard__dashboard-leaderboards",children:[(0,p.jsx)(d.SectionHeader,{title:_||(0,o.__)("Leaderboards","woocommerce"),menu:(0,p.jsx)(d.EllipsisMenu,{label:(0,o.__)("Choose which leaderboards to display and other settings","woocommerce"),placement:"bottom-end",renderContent:({onToggle:e})=>(0,p.jsxs)(t.Fragment,{children:[(0,p.jsx)(d.MenuTitle,{children:(0,o.__)("Leaderboards","woocommerce")}),x({allLeaderboards:r,hiddenBlocks:c,onToggleHiddenBlock:g}),(0,p.jsx)(d.MenuItem,{children:(0,p.jsx)(a.SelectControl,{className:"woocommerce-dashboard__dashboard-leaderboards__select",label:(0,o.__)("Rows per table","woocommerce"),value:T,options:Array.from({length:20},((e,r)=>({v:r+1,label:r+1}))),onChange:L})}),(0,p.jsx)(s,{onToggle:e,onMove:u,onRemove:m,isFirst:n,isLast:i,onTitleBlur:h,onTitleChange:b,titleInput:f})]})})}),(0,p.jsx)("div",{className:"woocommerce-dashboard__columns",children:j({allLeaderboards:r,hiddenBlocks:c,query:w,rowsPerTable:T,filters:y})})]})})},C=e=>{const{leaderboards:r}=(0,y.Qk)("dataEndpoints",{leaderboards:[]});return(0,p.jsx)(k,{...e,allLeaderboards:r})}},35888:(e,r,s)=>{s.d(r,{A:()=>t});var o=s(42435);const t=e=>({__html:(0,o.sanitizeHTML)(e)})}}]);