"use strict";(globalThis.webpackChunk_wcAdmin_webpackJsonp=globalThis.webpackChunk_wcAdmin_webpackJsonp||[]).push([[823],{39254:(e,r,s)=>{s.r(r),s.d(r,{default:()=>k});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),m=s(96476),u=s(94111),h=s(43577),b=s(14908),g=s(12974),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.Ay)(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=u.CurrencyContext;const y=(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,m.getPersistedQuery)(o),query:o,select:e,defaultDateRange:d,filterQuery:n};return(0,l.getLeaderboard)(i)})))(_);var f=s(56109);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)})),T=({allLeaderboards:e,hiddenBlocks:r,query:s,rowsPerTable:o,filters:t})=>e.map((e=>{if(!r.includes(e.id))return(0,p.jsx)(y,{headers:e.headers,id:e.id,query:s,title:e.label,totalRows:o,filters:t},e.id)})),j=e=>{const{allLeaderboards:r,controls:s,isFirst:n,isLast:i,hiddenBlocks:c,onMove:m,onRemove:u,onTitleBlur:h,onTitleChange:b,onToggleHiddenBlock:g,query:w,title:_,titleInput:y,filters:f}=e,{updateUserPreferences:j,...k}=(0,l.useUserPreferences)(),[C,v]=(0,t.useState)(parseInt(k.dashboard_leaderboard_rows||5,10)),L=e=>{v(parseInt(e,10));const r={dashboard_leaderboard_rows:parseInt(e,10)};j(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:C,options:Array.from({length:20},((e,r)=>({v:r+1,label:r+1}))),onChange:L})}),(0,p.jsx)(s,{onToggle:e,onMove:m,onRemove:u,isFirst:n,isLast:i,onTitleBlur:h,onTitleChange:b,titleInput:y})]})})}),(0,p.jsx)("div",{className:"woocommerce-dashboard__columns",children:T({allLeaderboards:r,hiddenBlocks:c,query:w,rowsPerTable:C,filters:f})})]})})},k=e=>{const{leaderboards:r}=(0,f.Qk)("dataEndpoints",{leaderboards:[]});return(0,p.jsx)(j,{...e,allLeaderboards:r})}},12974:(e,r,s)=>{s.d(r,{Ay:()=>d});var o=s(13240);const t=["a","b","em","i","strong","p","br"],a=["target","href","rel","name","download"],d=e=>({__html:(0,o.sanitize)(e,{ALLOWED_TAGS:t,ALLOWED_ATTR:a})})}}]);