!function(){var t;t=jQuery,Craft.NewUsersWidget=Garnish.Base.extend({settings:null,data:null,startDate:null,endDate:null,$widget:null,$body:null,init:function(e,a){var s=this;switch(this.setSettings(a),this.$widget=t("#widget"+e),this.$body=this.$widget.find(".body:first"),this.$chartContainer=t('<div class="chart hidden"></div>').appendTo(this.$body),this.$error=t('<div class="error"/>').appendTo(this.$body),this.settings.dateRange){case"d7":this.startDate=Craft.NewUsersWidget.getDateByDays(6),this.endDate=new Date;break;case"d30":this.startDate=Craft.NewUsersWidget.getDateByDays(30),this.endDate=new Date;break;case"lastweek":this.startDate=Craft.NewUsersWidget.getDateByDays(13),this.endDate=Craft.NewUsersWidget.getDateByDays(7);break;case"lastmonth":this.startDate=Craft.NewUsersWidget.getDateByDays(60),this.endDate=Craft.NewUsersWidget.getDateByDays(30)}var r={startDate:Craft.NewUsersWidget.getDateValue(this.startDate),endDate:Craft.NewUsersWidget.getDateValue(this.endDate),userGroupId:this.settings.userGroupId};Craft.sendActionRequest("POST","charts/get-new-users-data",{data:r}).then((function(t){if(s.$chartContainer.removeClass("hidden"),t.data.errors&&t.data.errors.length)return Promise.reject();s.chart=new Craft.charts.Area(s.$chartContainer,{yAxis:{formatter:function(t){return function(e){var a=",.0f";return e!=Math.round(e)&&(a=",.1f"),t.formatLocale.format(a)(e)}}}});var e=new Craft.charts.DataTable(t.data.dataTable),a={orientation:t.data.orientation,dataScale:t.data.scale,formats:t.data.formats};s.chart.draw(e,a),window.dashboard.grid.on("refreshCols",s.handleGridRefresh.bind(s))})).catch((function(t){var e,a=t.response,r=(null==a||null===(e=a.data)||void 0===e?void 0:e.message)||Craft.t("app","A server error occurred.");s.$error.html(r),s.$error.removeClass("hidden")})),this.$widget.data("widget").on("destroy",this.destroy.bind(this)),Craft.NewUsersWidget.instances.push(this)},handleGridRefresh:function(){this.chart.resize()},destroy:function(){Craft.NewUsersWidget.instances.splice(t.inArray(this,Craft.NewUsersWidget.instances),1),this.base()}},{instances:[],getDateByDays:function(t){var e=new Date;return e=e.getTime()-86400*t*1e3,new Date(e)},getDateValue:function(t){return Math.floor(t.getTime()/1e3)}})}();
//# sourceMappingURL=NewUsersWidget.js.map