(globalThis.webpackChunkdokan_pro=globalThis.webpackChunkdokan_pro||[]).push([[3256],{2694(e,t,a){"use strict";var r=a(6925);function o(){}function n(){}n.resetWarningCache=o,e.exports=function(){function e(e,t,a,o,n,l){if(l!==r){var s=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name="Invariant Violation",s}}function t(){return e}e.isRequired=e;var a={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:n,resetWarningCache:o};return a.PropTypes=a,a}},3897(e,t,a){"use strict";a.r(t),a.d(t,{default:()=>w});var r=a(6087),o=a(5556),n=a.n(o),l=a(7723),s=a(8537),i=a(2619),d=a(7143),c=a(314),u=a(7057);const m=(0,i.applyFilters)("dokan_analytics_customers_report_filters",[{label:(0,l.__)("Show","dokan"),staticParams:["paged","per_page"],param:"filter",showFilters:()=>!0,filters:[{label:(0,l.__)("All Customers","dokan"),value:"all"},{label:(0,l.__)("Single Customer","dokan"),value:"select_customer",chartMode:"item-comparison",subFilters:[{component:"Search",value:"single_customer",chartMode:"item-comparison",path:["select_customer"],settings:{type:"customers",param:"customers",getLabels:u.wd,labels:{placeholder:(0,l.__)("Type to search for a customer","dokan"),button:(0,l.__)("Single Customer","dokan")}}}]},{label:(0,l.__)("Advanced filters","dokan"),value:"advanced"}]}]),_=(0,i.applyFilters)("dokan_analytics_customers_report_advanced_filters",{title:(0,l._x)("Customers match <select/> filters","A sentence describing filters for Customers. See screen shot for context: https://cloudup.com/cCsm3GeXJbE","dokan"),filters:{name:{labels:{add:(0,l.__)("Name","dokan"),placeholder:(0,l.__)("Search","dokan"),remove:(0,l.__)("Remove customer name filter","dokan"),rule:(0,l.__)("Select a customer name filter match","dokan"),
/* translators: A sentence describing a Product filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
title:(0,l.__)("<title>Name</title> <rule/> <filter/>","dokan"),filter:(0,l.__)("Select customer name","dokan")},rules:[{value:"includes",
/* translators: Sentence fragment, logical, "Includes" refers to customer names including a given name(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Includes","customer names","dokan")},{value:"excludes",
/* translators: Sentence fragment, logical, "Excludes" refers to customer names excluding a given name(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Excludes","customer names","dokan")}],input:{component:"Search",type:"customers",getLabels:(0,u.Dn)(c.NAMESPACE+"/customers",e=>({id:e.id,label:e.name}))}},country:{labels:{add:(0,l.__)("Country / Region","dokan"),placeholder:(0,l.__)("Search","dokan"),remove:(0,l.__)("Remove country / region filter","dokan"),rule:(0,l.__)("Select a country / region filter match","dokan"),
/* translators: A sentence describing a Product filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
title:(0,l.__)("<title>Country / Region</title> <rule/> <filter/>","dokan"),filter:(0,l.__)("Select country / region","dokan")},rules:[{value:"includes",
/* translators: Sentence fragment, logical, "Includes" refers to countries including a given country or countries. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Includes","countries","dokan")},{value:"excludes",
/* translators: Sentence fragment, logical, "Excludes" refers to countries excluding a given country or countries. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Excludes","countries","dokan")}],input:{component:"Search",type:"countries",getLabels:async e=>{const t=(await(0,d.resolveSelect)(c.COUNTRIES_STORE_NAME).getCountries()).map(e=>({key:e.code,label:(0,s.decodeEntities)(e.name)})),a=e.split(",");return await t.filter(e=>a.includes(e.key))}}},username:{labels:{add:(0,l.__)("Username","dokan"),placeholder:(0,l.__)("Search customer username","dokan"),remove:(0,l.__)("Remove customer username filter","dokan"),rule:(0,l.__)("Select a customer username filter match","dokan"),
/* translators: A sentence describing a customer username filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
title:(0,l.__)("<title>Username</title> <rule/> <filter/>","dokan"),filter:(0,l.__)("Select customer username","dokan")},rules:[{value:"includes",
/* translators: Sentence fragment, logical, "Includes" refers to customer usernames including a given username(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Includes","customer usernames","dokan")},{value:"excludes",
/* translators: Sentence fragment, logical, "Excludes" refers to customer usernames excluding a given username(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Excludes","customer usernames","dokan")}],input:{component:"Search",type:"usernames",getLabels:u.wd}},email:{labels:{add:(0,l.__)("Email","dokan"),placeholder:(0,l.__)("Search customer email","dokan"),remove:(0,l.__)("Remove customer email filter","dokan"),rule:(0,l.__)("Select a customer email filter match","dokan"),
/* translators: A sentence describing a customer email filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
title:(0,l.__)("<title>Email</title> <rule/> <filter/>","dokan"),filter:(0,l.__)("Select customer email","dokan")},rules:[{value:"includes",
/* translators: Sentence fragment, logical, "Includes" refers to customer emails including a given email(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Includes","customer emails","dokan")},{value:"excludes",
/* translators: Sentence fragment, logical, "Excludes" refers to customer emails excluding a given email(s). Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Excludes","customer emails","dokan")}],input:{component:"Search",type:"emails",getLabels:(0,u.Dn)(c.NAMESPACE+"/customers",e=>({id:e.id,label:e.email}))}},orders_count:{labels:{add:(0,l.__)("No. of Orders","dokan"),remove:(0,l.__)("Remove order filter","dokan"),rule:(0,l.__)("Select an order count filter match","dokan"),title:(0,l.__)("<title>No. of Orders</title> <rule/> <filter/>","dokan")},rules:[{value:"max",
/* translators: Sentence fragment, logical, "Less Than" refers to number of orders a customer has placed, less than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Less Than","number of orders","dokan")},{value:"min",
/* translators: Sentence fragment, logical, "More Than" refers to number of orders a customer has placed, more than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("More Than","number of orders","dokan")},{value:"between",
/* translators: Sentence fragment, logical, "Between" refers to number of orders a customer has placed, between two given integers. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Between","number of orders","dokan")}],input:{component:"Number"}},total_spend:{labels:{add:(0,l.__)("Total Spend","dokan"),remove:(0,l.__)("Remove total spend filter","dokan"),rule:(0,l.__)("Select a total spend filter match","dokan"),title:(0,l.__)("<title>Total Spend</title> <rule/> <filter/>","dokan")},rules:[{value:"max",
/* translators: Sentence fragment, logical, "Less Than" refers to total spending by a customer, less than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Less Than","total spend by customer","dokan")},{value:"min",
/* translators: Sentence fragment, logical, "Less Than" refers to total spending by a customer, more than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("More Than","total spend by customer","dokan")},{value:"between",
/* translators: Sentence fragment, logical, "Between" refers to total spending by a customer, between two given amounts. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Between","total spend by customer","dokan")}],input:{component:"Currency"}},avg_order_value:{labels:{add:(0,l.__)("AOV","dokan"),remove:(0,l.__)("Remove average order value filter","dokan"),rule:(0,l.__)("Select an average order value filter match","dokan"),title:(0,l.__)("<title>AOV</title> <rule/> <filter/>","dokan")},rules:[{value:"max",
/* translators: Sentence fragment, logical, "Less Than" refers to average order value of a customer, more than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Less Than","average order value of customer","dokan")},{value:"min",
/* translators: Sentence fragment, logical, "Less Than" refers to average order value of a customer, less than a given amount. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("More Than","average order value of customer","dokan")},{value:"between",
/* translators: Sentence fragment, logical, "Between" refers to average order value of a customer, between two given amounts. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Between","average order value of customer","dokan")}],input:{component:"Currency"}},registered:{labels:{add:(0,l.__)("Registered","dokan"),remove:(0,l.__)("Remove registered filter","dokan"),rule:(0,l.__)("Select a registered filter match","dokan"),
/* translators: A sentence describing a Product filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
title:(0,l.__)("<title>Registered</title> <rule/> <filter/>","dokan"),filter:(0,l.__)("Select registered date","dokan")},rules:[{value:"before",
/* translators: Sentence fragment, logical, "Before" refers to customers registered before a given date. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Before","date","dokan")},{value:"after",
/* translators: Sentence fragment, logical, "after" refers to customers registered after a given date. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("After","date","dokan")},{value:"between",
/* translators: Sentence fragment, logical, "Between" refers to average order value of a customer, between two given amounts. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Between","date","dokan")}],input:{component:"Date"}},last_active:{labels:{add:(0,l.__)("Last active","dokan"),remove:(0,l.__)("Remove last active filter","dokan"),rule:(0,l.__)("Select a last active filter match","dokan"),
/* translators: A sentence describing a Product filter. See screen shot for context: https://cloudup.com/cCsm3GeXJbE */
title:(0,l.__)("<title>Last active</title> <rule/> <filter/>","dokan"),filter:(0,l.__)("Select registered date","dokan")},rules:[{value:"before",
/* translators: Sentence fragment, logical, "Before" refers to customers registered before a given date. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Before","date","dokan")},{value:"after",
/* translators: Sentence fragment, logical, "after" refers to customers registered after a given date. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("After","date","dokan")},{value:"between",
/* translators: Sentence fragment, logical, "Between" refers to average order value of a customer, between two given amounts. Screenshot for context: https://cloudup.com/cCsm3GeXJbE */
label:(0,l._x)("Between","date","dokan")}],input:{component:"Date"}}}});var p=a(6427),y=a(8846),b=a(3577),g=a(5703),h=a(7374),v=a(4111),f=a(8660),k=a(274),S=a(790);const x=function({isRequesting:e,query:t,filters:a,advancedFilters:o}){const n=(0,r.useContext)(v.CurrencyContext),{countries:s,loadingCountries:i}=(0,d.useSelect)(e=>{const{getCountries:t,hasFinishedResolution:a}=e(c.COUNTRIES_STORE_NAME);return{countries:t(),loadingCountries:!a("getCountries")}});return(0,S.jsx)(f.A,{endpoint:"customers",getHeadersContent:()=>[{label:(0,l.__)("Name","dokan"),key:"name",required:!0,isLeftAligned:!0,isSortable:!0},{label:(0,l.__)("Username","dokan"),key:"username",hiddenByDefault:!0},{label:(0,l.__)("Last active","dokan"),key:"date_last_active",defaultSort:!0,isSortable:!0},{label:(0,l.__)("Date registered","dokan"),key:"date_registered",isSortable:!0},{label:(0,l.__)("Email","dokan"),key:"email"},{label:(0,l.__)("Orders","dokan"),key:"orders_count",isSortable:!0,isNumeric:!0},{label:(0,l.__)("Total spend","dokan"),key:"total_spend",isSortable:!0,isNumeric:!0},{label:(0,l.__)("AOV","dokan"),screenReaderLabel:(0,l.__)("Average order value","dokan"),key:"avg_order_value",isNumeric:!0},{label:(0,l.__)("Country / Region","dokan"),key:"country",isSortable:!0},{label:(0,l.__)("City","dokan"),key:"city",hiddenByDefault:!0,isSortable:!0},{label:(0,l.__)("Region","dokan"),key:"state",hiddenByDefault:!0,isSortable:!0},{label:(0,l.__)("Postal code","dokan"),key:"postcode",hiddenByDefault:!0,isSortable:!0}],getRowsContent:e=>{const t=(0,k.Qk)("dateFormat",h.defaultTableDateFormat),{formatAmount:a,formatDecimal:o,getCurrencyConfig:l}=n;return e?.map(e=>{const{avg_order_value:n,date_last_active:i,date_registered:d,email:c,name:u,user_id:m,orders_count:_,username:h,total_spend:v,postcode:f,city:k,state:x,country:C}=e,w=void 0!==s[R=C]?s[R]:null;var R;const E=m?(0,S.jsx)(y.Link,{href:(0,g.getAdminLink)("user-edit.php?user_id="+m),type:"wp-admin",children:u}):u,F=i?(0,S.jsx)(y.Date,{date:i,visibleFormat:t}):"—",T=d?(0,S.jsx)(y.Date,{date:d,visibleFormat:t}):"—",A=(0,S.jsxs)(r.Fragment,{children:[(0,S.jsx)(p.Tooltip,{text:w,children:(0,S.jsx)("span",{"aria-hidden":"true",children:C})}),(0,S.jsx)("span",{className:"screen-reader-text",children:w})]});return[{display:E,value:u},{display:h,value:h},{display:F,value:i},{display:T,value:d},{display:(0,S.jsx)("a",{href:"mailto:"+c,children:c}),value:c},{display:(0,b.formatValue)(l(),"number",_),value:_},{display:a(v),value:o(v)},{display:a(n),value:o(n)},{display:A,value:C},{display:k,value:k},{display:x,value:x},{display:f,value:f}]})},getSummary:e=>{const{customers_count:t=0,avg_orders_count:a=0,avg_total_spend:r=0,avg_avg_order_value:o=0}=e,{formatAmount:s,getCurrencyConfig:i}=n,d=i();return[{label:(0,l._n)("customer","customers",t,"dokan"),value:(0,b.formatValue)(d,"number",t)},{label:(0,l._n)("Average order","Average orders",a,"dokan"),value:(0,b.formatValue)(d,"number",a)},{label:(0,l.__)("Average lifetime spend","dokan"),value:s(r)},{label:(0,l.__)("Average order value","dokan"),value:s(o)}]},summaryFields:["customers_count","avg_orders_count","avg_total_spend","avg_avg_order_value"],isRequesting:e||i,itemIdField:"id",query:t,labels:{placeholder:(0,l.__)("Search by customer name","dokan")},searchBy:"customers",title:(0,l.__)("Customers","dokan"),columnPrefsKey:"customers_report_columns",filters:a,advancedFilters:o})};var C=a(8222);class w extends r.Component{render(){const{isRequesting:e,query:t,path:a}=this.props,o={orderby:"date_last_active",order:"desc",...t};return(0,S.jsxs)(r.Fragment,{children:[(0,S.jsx)(C.A,{query:t,path:a,filters:m,showDatePicker:!1,advancedFilters:_,report:"customers"}),(0,S.jsx)(x,{isRequesting:e,query:o,filters:m,advancedFilters:_})]})}}w.propTypes={query:n().object.isRequired}},4351(e,t,a){"use strict";a.d(t,{A:()=>d});var r=a(7723),o=a(5556),n=a.n(o),l=a(8846),s=a(790);function i({className:e}){const t=(0,r.__)("There was an error getting your stats. Please try again.","dokan"),a=(0,r.__)("Reload","dokan");return(0,s.jsx)(l.EmptyContent,{className:e,title:t,actionLabel:a,actionCallback:()=>{window.location.reload()}})}i.propTypes={className:n().string};const d=i},4924(e,t,a){"use strict";a.d(t,{H:()=>o});var r=a(7723);function o(e){return[e.country,e.state,e.name||(0,r.__)("TAX","dokan"),e.priority].map(e=>e.toString().toUpperCase().trim()).filter(Boolean).join("-")}},5556(e,t,a){e.exports=a(2694)()},6925(e){"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},7057(e,t,a){"use strict";a.d(t,{Dn:()=>u,U4:()=>_,aG:()=>m,b8:()=>h,jx:()=>b,p0:()=>y,wd:()=>p,xP:()=>g});var r=a(3832),o=a(1455),n=a.n(o),l=a(8468),s=a(6476),i=a(4924),d=a(274);const c="/wc-analytics";function u(e,t=l.identity){return function(a="",o){const l="function"==typeof e?e(o):e,i=(0,s.getIdsFromQuery)(a);if(i.length<1)return Promise.resolve([]);const d={include:i.join(","),per_page:i.length};return n()({path:(0,r.addQueryArgs)(l,d)}).then(e=>e.map(t))}}u(c+"/products/attributes",e=>({key:e.id,label:e.name}));const m=u(c+"/products/categories",e=>({key:e.id,label:e.name})),_=u(c+"/coupons",e=>({key:e.id,label:e.code})),p=u(c+"/customers",e=>({key:e.id,label:e.name})),y=u(c+"/products",e=>({key:e.id,label:e.name})),b=u(c+"/taxes",e=>({key:e.id,label:(0,i.H)(e)}));function g({attributes:e,name:t}){const a=(0,d.Qk)("variationTitleAttributesSeparator"," - ");if(t&&t.indexOf(a)>-1)return t;const r=(e||[]).map(({option:e})=>e).join(", ");return r?t+a+r:t}const h=u(({products:e})=>e?c+`/products/${e}/variations`:c+"/variations",e=>({key:e.id,label:g(e)}))},8222(e,t,a){"use strict";a.d(t,{A:()=>h});var r=a(6087),o=a(9491),n=a(5556),l=a.n(n),s=a(8468),i=a(7143),d=a(7752),c=a(8846),u=a(314),m=a(7374),_=a(3306),p=a(4111),y=a(274),b=a(790);class g extends r.Component{constructor(){super(),this.onDateSelect=this.onDateSelect.bind(this),this.onFilterSelect=this.onFilterSelect.bind(this),this.onAdvancedFilterAction=this.onAdvancedFilterAction.bind(this)}onDateSelect(e){const{report:t,addCesSurveyForAnalytics:a}=this.props;a(),(0,_.recordEvent)("datepicker_update",{report:t,...(0,s.omitBy)(e,s.isUndefined)})}onFilterSelect(e){const{report:t,addCesSurveyForAnalytics:a}=this.props,r=e.filter||e["filter-variations"];["single_product","single_category","single_coupon","single_variation"].includes(r)&&a();const o={report:t,filter:e.filter||"all"};"single_product"===e.filter&&(o.filter_variation=e["filter-variations"]||"all"),(0,_.recordEvent)("analytics_filter",o)}onAdvancedFilterAction(e,t){const{report:a,addCesSurveyForAnalytics:r}=this.props;switch(e){case"add":(0,_.recordEvent)("analytics_filters_add",{report:a,filter:t.key});break;case"remove":(0,_.recordEvent)("analytics_filters_remove",{report:a,filter:t.key});break;case"filter":const e=Object.keys(t).reduce((e,a)=>(e[(0,s.snakeCase)(a)]=t[a],e),{});r(),(0,_.recordEvent)("analytics_filters_filter",{report:a,...e});break;case"clear_all":(0,_.recordEvent)("analytics_filters_clear_all",{report:a});break;case"match":(0,_.recordEvent)("analytics_filters_all_any",{report:a,value:t.match})}}render(){const{advancedFilters:e,filters:t,path:a,query:r,showDatePicker:o,defaultDateRange:n}=this.props,{period:l,compare:s,before:i,after:d}=(0,m.getDateParamsFromQuery)(r,n),{primary:u,secondary:_}=(0,m.getCurrentDates)(r,n),p={period:l,compare:s,before:i,after:d,primaryDate:u,secondaryDate:_},g=this.context;return(0,b.jsx)(c.ReportFilters,{query:r,siteLocale:y.ne.siteLocale,currency:g.getCurrencyConfig(),path:a,filters:t,advancedFilters:e,showDatePicker:o,onDateSelect:this.onDateSelect,onFilterSelect:this.onFilterSelect,onAdvancedFilterAction:this.onAdvancedFilterAction,dateQuery:p,isoDateFormat:m.isoDateFormat})}}g.contextType=p.CurrencyContext;const h=(0,o.compose)((0,i.withSelect)(e=>{const{woocommerce_default_date_range:t}=e(u.SETTINGS_STORE_NAME).getSetting("wc_admin","wcAdminSettings");return{defaultDateRange:t}}),(0,i.withDispatch)(e=>{const{addCesSurveyForAnalytics:t}=e(d.STORE_KEY);return{addCesSurveyForAnalytics:t}}))(g);g.propTypes={advancedFilters:l().object,filters:l().array,path:l().string.isRequired,query:l().object,showDatePicker:l().bool,report:l().string.isRequired}},8660(e,t,a){"use strict";a.d(t,{A:()=>w});var r=a(6427),o=a(2619),n=a(6087),l=a(9491),s=a(8107),i=a(7143),d=a(8468),c=a(7723),u=a(5556),m=a.n(u),_=a(7752),p=a(8846),y=a(6476),b=a(1554),g=a(314),h=a(3306),v=a(790);const f=()=>(0,v.jsx)("svg",{role:"img","aria-hidden":"true",focusable:"false",version:"1.1",xmlns:"http://www.w3.org/2000/svg",x:"0px",y:"0px",viewBox:"0 0 24 24",children:(0,v.jsx)("path",{d:"M18,9c-0.009,0-0.017,0.002-0.025,0.003C17.72,5.646,14.922,3,11.5,3C7.91,3,5,5.91,5,9.5c0,0.524,0.069,1.031,0.186,1.519 C5.123,11.016,5.064,11,5,11c-2.209,0-4,1.791-4,4c0,1.202,0.541,2.267,1.38,3h18.593C22.196,17.089,23,15.643,23,14 C23,11.239,20.761,9,18,9z M12,16l-4-5h3V8h2v3h3L12,16z"})});var k=a(4351);const S=e=>{const{getHeadersContent:t,getRowsContent:a,getSummary:l,isRequesting:i,primaryData:u,tableData:m,endpoint:_,itemIdField:S,tableQuery:x,compareBy:C,compareParam:w,searchBy:R,labels:E={},...F}=e,{query:T,columnPrefsKey:A}=e,{items:D,query:j}=m,q=T[w]?(0,y.getIdsFromQuery)(T[C]):[],[N,O]=(0,n.useState)(q),P=(0,n.useRef)(null),{updateUserPreferences:B,...I}=(0,g.useUserPreferences)();if(m.isError||u.isError)return(0,v.jsx)(k.A,{});let L=[];A&&(L=I&&I[A]?I[A]:L);const Q=(e,r,n)=>{const s=l?l(r,n):null;return(0,o.applyFilters)("dokan_analytics_report_table",{endpoint:_,headers:t(),rows:a(e),totals:r,summary:s,items:D})},M=t=>{const{ids:a}=e;O(t?a:[])},U=(t,a)=>{const{ids:r}=e;if(a)O((0,d.uniq)([r[t],...N]));else{const e=N.indexOf(r[t]);O([...N.slice(0,e),...N.slice(e+1)])}},V=t=>{const{ids:a=[]}=e,o=-1!==N.indexOf(a[t]);return{display:(0,v.jsx)(r.CheckboxControl,{onChange:(0,d.partial)(U,t),checked:o}),value:!1}},H=i||m.isRequesting||u.isRequesting,K=(0,d.get)(u,["data","totals"],{}),Y=D.totalResults||0,G=Y>0,W=(0,y.getSearchWords)(T).map(e=>({key:e,label:e})),{data:z}=D,X=Q(z,K,Y);let{headers:J,rows:$}=X;const{summary:Z}=X;C&&($=$.map((e,t)=>[V(t),...e]),J=[(()=>{const{ids:t=[]}=e,a=t.length>0,o=a&&t.length===N.length;return{cellClassName:"is-checkbox-column",key:"compare",label:(0,v.jsx)(r.CheckboxControl,{onChange:M,"aria-label":(0,c.__)("Select All","dokan"),checked:o,disabled:!a}),required:!0}})(),...J]);const ee=((e,t)=>t?e.map(e=>({...e,visible:e.required||!t.includes(e.key)})):e.map(e=>({...e,visible:e.required||!e.hiddenByDefault})))(J,L);return(0,v.jsxs)(n.Fragment,{children:[(0,v.jsx)("div",{className:"woocommerce-report-table__scroll-point",ref:P,"aria-hidden":!0}),(0,v.jsx)(p.TableCard,{className:"woocommerce-report-table",hasSearch:!!R,actions:[C&&(0,v.jsx)(p.CompareButton,{className:"woocommerce-table__compare",count:N.length,helpText:E.helpText||(0,c.__)("Check at least two items below to compare","dokan"),onClick:()=>{C&&(0,y.onQueryChange)("compare")(C,w,N.join(","))},disabled:!G,children:E.compareButton||(0,c.__)("Compare","dokan")},"compare"),R&&(0,v.jsx)(p.Search,{allowFreeTextSearch:!0,inlineTags:!0,onChange:t=>{const{baseSearchQuery:a,addCesSurveyForCustomerSearch:r}=e,o=t.map(e=>e.label.replace(",","%2C"));o.length?((0,y.updateQueryString)({filter:void 0,[w]:void 0,[R]:void 0,...a,search:(0,d.uniq)(o).join(",")}),r()):(0,y.updateQueryString)({search:void 0}),(0,h.recordEvent)("analytics_table_filter",{report:_})},placeholder:E.placeholder||(0,c.__)("Search by item name","dokan"),selected:W,showClearButton:!0,type:R,disabled:!G},"search"),G&&(0,v.jsxs)(r.Button,{className:"woocommerce-table__download-button",disabled:H,onClick:()=>{const{createNotice:t,startExport:a,title:r}=e,o=Object.assign({},T),{data:n,totalResults:l}=D;let s="browser";if(delete o.extended_info,o.search&&delete o[R],n&&n.length===l){const{headers:e,rows:t}=Q(n,l);(0,b.downloadCSVFile)((0,b.generateCSVFileName)(r,o),(0,b.generateCSVDataFromTable)(e,t))}else s="email",a(_,j).then(()=>t("success",(0,c.sprintf)(/* translators: %s = type of report */ /* translators: %s = type of report */
(0,c.__)("Your %s Report will be emailed to you.","dokan"),r))).catch(e=>t("error",e.message||(0,c.sprintf)(/* translators: %s = type of report */ /* translators: %s = type of report */
(0,c.__)("There was a problem exporting your %s Report. Please try again.","dokan"),r)));(0,h.recordEvent)("analytics_table_download",{report:_,rows:l,download_type:s})},children:[(0,v.jsx)(f,{}),(0,v.jsx)("span",{className:"woocommerce-table__download-button__label",children:E.downloadButton||(0,c.__)("Download","dokan")})]},"download")],headers:ee,isLoading:H,onQueryChange:y.onQueryChange,onColumnsChange:(e,t)=>{const a=J.map(e=>e.key).filter(t=>!e.includes(t));if(A&&B({[A]:a}),t){const a={report:_,column:t,status:e.includes(t)?"on":"off"};(0,h.recordEvent)("analytics_table_header_toggle",a)}},onSort:(e,t)=>{(0,y.onQueryChange)("sort")(e,t);const a={report:_,column:e,direction:t};(0,h.recordEvent)("analytics_table_sort",a)},onPageChange:(e,t)=>{P.current.scrollIntoView();const a=P.current.nextSibling.querySelector(".woocommerce-table__table"),r=s.focus.focusable.find(a);r.length&&r[0].focus(),t&&("goto"===t?(0,h.recordEvent)("analytics_table_go_to_page",{report:_,page:e}):(0,h.recordEvent)("analytics_table_page_click",{report:_,direction:t}))},rows:$,rowsPerPage:parseInt(j.per_page,10)||g.QUERY_DEFAULTS.pageSize,summary:Z,totalRows:Y,...F})]})};S.propTypes={baseSearchQuery:m().object,compareBy:m().string,compareParam:m().string,columnPrefsKey:m().string,endpoint:m().string,extendItemsMethodNames:m().shape({getError:m().string,isRequesting:m().string,load:m().string}),extendedItemsStoreName:m().string,getHeadersContent:m().func.isRequired,getRowsContent:m().func.isRequired,getSummary:m().func,itemIdField:m().string,labels:m().shape({compareButton:m().string,downloadButton:m().string,helpText:m().string,placeholder:m().string}),primaryData:m().object,searchBy:m().string,summaryFields:m().arrayOf(m().string),tableData:m().object.isRequired,tableQuery:m().object,title:m().string.isRequired},S.defaultProps={primaryData:{},tableData:{items:{data:[],totalResults:0},query:{}},tableQuery:{},compareParam:"filter",downloadable:!1,onSearch:d.noop,baseSearchQuery:{}};const x=[],C={},w=(0,l.compose)((0,i.withSelect)((e,t)=>{const{endpoint:a,getSummary:r,isRequesting:o,itemIdField:n,query:l,tableData:s,tableQuery:i,filters:c,advancedFilters:u,summaryFields:m,extendedItemsStoreName:_}=t,p=e(g.REPORTS_STORE_NAME),y=_?e(_):null,{woocommerce_default_date_range:b}=e(g.SETTINGS_STORE_NAME).getSetting("wc_admin","wcAdminSettings"),h=l.search&&!(l[a]&&l[a].length);if(o||h)return C;const v="categories"===a?"products":a,f=r?(0,g.getReportChartData)({endpoint:v,selector:p,dataType:"primary",query:l,filters:c,advancedFilters:u,defaultDateRange:b,fields:m}):C,k=s||(0,g.getReportTableData)({endpoint:a,query:l,selector:p,tableQuery:i,filters:c,advancedFilters:u,defaultDateRange:b}),S=y?function(e,t,a){const{extendItemsMethodNames:r,itemIdField:o}=t,n=a.items.data;if(!(Array.isArray(n)&&n.length&&r&&o))return a;const{[r.getError]:l,[r.isRequesting]:s,[r.load]:i}=e,c={include:n.map(e=>e[o]).join(","),per_page:n.length},u=i(c),m=!!s&&s(c),_=!!l&&l(c),p=n.map(e=>{const t=(0,d.first)(u.filter(t=>e.id===t.id));return{...e,...t}}),y=a.isRequesting||m,b=a.isError||_;return{...a,isRequesting:y,isError:b,items:{...a.items,data:p}}}(y,t,k):k;return{primaryData:f,ids:n&&S.items.data?S.items.data.map(e=>e[n]):x,tableData:S,query:l}}),(0,i.withDispatch)(e=>{const{startExport:t}=e(g.EXPORT_STORE_NAME),{createNotice:a}=e("core/notices"),{addCesSurveyForCustomerSearch:r}=e(_.STORE_KEY);return{createNotice:a,startExport:t,addCesSurveyForCustomerSearch:r}}))(S)}}]);