!function(e){var t={};function a(n){if(t[n])return t[n].exports;var s=t[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,a),s.l=!0,s.exports}a.m=e,a.c=t,a.d=function(e,t,n){a.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},a.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},a.t=function(e,t){if(1&t&&(e=a(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(a.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)a.d(n,s,function(t){return e[t]}.bind(null,s));return n},a.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return a.d(t,"a",t),t},a.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},a.p="",a(a.s=1)}([function(e,t,a){},function(e,t,a){"use strict";a.r(t);const{createElement:n,useState:s,useEffect:i,Fragment:l,render:r,useRef:d}=wp.element,{dispatch:o,select:u}=wp.data;var c=e=>{const[t,a]=s("");return i(()=>{let t="",n="",s={};switch(e.type){case"friends":n="user",t=e.id.item_id;break;case"group":n="group",t=e.id.id,s={item_id:e.id.id};break;case"activity":n="user",t=e.id.secondary_item_id;break;case"user":case"shared":n="user",t=e.id.id,s={user_id:e.id.id};break;case"course":n="course",t=e.id.id,s={item_id:e.id.id};break;default:n=e.type,t=e.id.id}localforage.getItem(n+"_"+t).then(t=>{null!==t?a(JSON.parse(t)):fetch(window.vibebp.api.url+"/avatar",{method:"post",body:JSON.stringify({type:n,ids:s,token:u("vibebp").getToken()})}).then(e=>e.json()).then(t=>{if(t.status){let n={...t.value,id:e.id.id};localforage.setItem(t.key,JSON.stringify(n)),a(n)}})})},[e.id]),n(l,null,e.not_show_name?n("img",{src:t.avatar,className:"vibebp_avatar",onClick:e.click,alt:t.name,title:t.name}):n("span",null,n("img",{src:t.avatar,className:"vibebp_avatar",onClick:e.click,alt:t.name,title:t.name}),n("span",{className:"avname"},t.name)))};a(0);const{createElement:f,render:m,useState:p,useEffect:v,Fragment:_}=wp.element,{select:b,dispatch:g}=wp.data,y=e=>{const t=window.sales_stats_widget,[a,n]=p(!0),[s,i]=p({});var l=new Date;l.setMonth(l.getMonth()-1);const[r,d]=p({start:l.getTime(),end:(new Date).getTime()});return v(()=>{r.start&&r.end&&r.start<=r.end&&(n(!0),fetch(t.api+"/sales_stats",{method:"post",body:JSON.stringify({token:b("vibebp").getToken(),args:r})}).then(e=>e.json()).then(e=>{n(!1),e.status&&i(e.data)}))},[r]),f("div",{className:"sales_stats_widget"},f("div",{className:"sales_stats_header"},f("div",{className:"vibebp_form_field"},f("label",null,t.translations.from),f("input",{type:"text",ref:e=>{e&&flatpickr(e,{altInput:!0,defaultDate:r.start,enableTime:!0,onChange:(e,t,a)=>{let n={...r};n.start=new Date(t).getTime(),d(n)}})}})),f("div",{className:"vibebp_form_field"},f("label",null,t.translations.to),f("input",{type:"text",ref:e=>{e&&flatpickr(e,{altInput:!0,defaultDate:r.end,enableTime:!0,onChange:(e,t,a)=>{let n={...r};n.end=new Date(t).getTime(),d(n)}})}}))),a?f("div",null,f("div",{className:"widget_loader"},f("div",null),f("div",null),f("div",null),f("div",null))):f(_,null,s&&Object.keys(s)&&Object.keys(s).length?f("div",{className:"sales_stats_data"},Object.keys(s).map(e=>{if(s[e]||(s[e]=t.translations.no_data_found),"total_instructors_commission"==e){if(Array.isArray(s[e])&&s[e].length)return f("div",null,f("div",null,t.translations[e]),f("div",null,s[e].map(e=>f("div",{className:"multi"},e.value+" "+e.currency))));s[e]=t.translations.no_data_found}else if("most_earning_by_instructor"==e){if(Array.isArray(s[e])&&s[e].length)return f("div",null,f("div",null,t.translations[e]),f("div",null,s[e].map(e=>f("div",null,f("span",{className:"multi"},e.value.value+" "+e.currency),f("span",null,f(c,{type:"user",id:{id:parseInt(e.value.user_id)}}))))));s[e]=t.translations.no_data_found}else if("most_sold_course"==e){if(s[e]&&s[e].hasOwnProperty("count"))return f("div",null,f("div",null,t.translations[e]),f("div",null,f("span",{className:"multi"},s[e].count+" "+t.translations.times),f("span",null,f("a",{href:s[e].url,target:"_blank"},f(c,{type:"course",id:{id:parseInt(s[e].course_id)}})))));s[e]=t.translations.no_data_found}return f("div",null,f("div",null,t.translations[e]),f("div",{dangerouslySetInnerHTML:{__html:s[e]}}))})):""))};document.addEventListener("sales_stats_widget",e=>{document.querySelectorAll(".sales_stats_widget").forEach(t=>{m(f(y,{settings:e.detail.widget.options}),t)})})}]);