if(void 0!==document.getElementById("wcs-bookings__app")&&null!=document.getElementById("wcs-bookings__app")){ELEMENT.locale(window.EventsSchedule.locale_element_ui),Vue.filter("moment",function(e,t,r){return!1!==r?moment(e).utc().format(t):moment(e).format(t)});var $lodash=void 0!==window.lodash?window.lodash:null,WcsBookings=new Vue({el:"#wcs-bookings__app",data:function(){var e=window.EventsSchedule.terms,r={finished:!0,canceled:!0,search:""};return $lodash.each(e,function(e,t){r[t]=[]}),{lodash:$lodash,terms:e,filters:r,orders:[],orders_count:0,orders_page:1,orders_per_page:10,query:{posts_per_page:100,paged:1,date_start:moment().format(),date_end:moment().add(2,"weeks").format()},loading:!1,buffer:{cancel_order:""},date_range:[moment(),moment().add(2,"weeks")],datepiker_options:{shortcuts:[{text:"Next week",onClick:function(e){var t=new Date,r=new Date;t.setTime(r.getTime()+6048e5),e.$emit("pick",[r,t])}},{text:"Next 2 weeks",onClick:function(e){var t=new Date,r=new Date;t.setTime(r.getTime()+12096e5),e.$emit("pick",[r,t])}},{text:"Next 30 days",onClick:function(e){var t=new Date,r=new Date;t.setTime(r.getTime()+2592e6),e.$emit("pick",[r,t])}},{text:"Last week",onClick:function(e){var t=new Date,r=new Date;r.setTime(r.getTime()-6048e5),e.$emit("pick",[r,t])}},{text:"Last 2 week",onClick:function(e){var t=new Date,r=new Date;r.setTime(r.getTime()-12096e5),e.$emit("pick",[r,t])}},{text:"Last 30 days",onClick:function(e){var t=new Date,r=new Date;r.setTime(r.getTime()-2592e6),e.$emit("pick",[r,t])}}]}}},mounted:function(){this.getOrders()},watch:{date_range:function(e){var t=this;t.query.date_start=void 0!==e&&null!==e[0]?moment(e[0]).format():moment().format(),t.query.date_end=void 0!==e&&null!==e[1]?moment(e[1]).format():moment().add(2,"weeks").format(),this.getOrders()},orders_page:function(e){this.query.paged=e,
//this.query.posts_per_page = 10;
this.filtered_orders.length<this.orders_count&&this.filtered_orders.length%this.orders_per_page*this.orders_page==0&&this.getOrders()},orders_per_page:function(e){this.orders_page=1,this.query.posts_per_page=e,this.filtered_orders.length<this.orders_count&&this.filtered_orders.length<this.orders_per_page&&this.getOrders()}},updated:function(){},computed:{taxonomies:function(){return window.EventsSchedule.taxonomies},tableData:function(){var e=this,n=[],s=e.orders_per_page*(e.orders_page-1),o=e.orders_per_page*e.orders_page;return e.filtered_orders.forEach(function(e,t,r){s<=t&&t<o&&n.push(e)}),n},filtered_orders:function(){var s=this,o=[];return s.orders.forEach(function(e,t,r){var n=!0;!s.filters.finished&&e.finished&&(n=!1),0<s.filters.search.length&&e.title.toLowerCase().search(s.filters.search.toLowerCase())&&(n=!1),n&&o.push(e)}),o}},methods:{debounceInput:$lodash.debounce(function(e){this.filters.search=e},200),filterTerms:function(e,t){var r=[];return $lodash.each(t.terms,function(e){$lodash.each(e,function(e){r.push(e.id)})}),0<=r.indexOf(e)},getOrderStatus:function(e){switch(!0){case"on-hold"===e:return"warning";break;case"pending"===e:return"warning";break;case"processing"===e:return"primary";break;case"completed"===e:return"success";break;case"cancelled"===e:return"danger";break;case"refunded"===e:return"danger";break;case"failed"===e:return"danger";break;default:return"gray"}},getFilterTerms:function(e){var t=this,r=[];return $lodash.each(t.terms[e],function(e){r.push({text:e.name,value:e.term_id})}),r},filter_var:function(e){return 0<=[1,"1","yes",!0,"true","on"].indexOf(e)},handleSizeChange:function(e){this.orders_per_page=e},handleCurrentChange:function(e){this.orders_page=e},getOrderType:function(e){switch(!0){case"canceled"===e.status:return"canceled";break;case 1e3*e.event.time<=moment().utc().valueOf():return"finished";break;default:return"accepted"}},getOrderTagType:function(e){return"canceled"===e?"danger":"accepted"===e?"success":"gray"},getOrderClasses:function(e){var t=this,r=["order"];return r.push("order--"+t.getOrderType(e)),r.join(" ")},cancelEvent:function(e,t){var r=this;confirm("Are you sure you want to cancel this order?")&&(r.loading=!0,r.buffer.cancel_order=e.id,r.$http.post(ajaxurl,{order:e},{emulateJSON:!0,params:{action:"wcs_cancel_order"}}).then(r.responseSuccessOrder,r.responseErrorOrder))},getAge:function(e){return Math.round(moment().utc().diff(moment(e).utc(),"years",!0))},getOrders:function(){var e=this;e.loading=!0,e.$http.get(window.EventsSchedule.rest_route+"weekly-class/v1/bookings/",{
//emulateHTTP: true
headers:{"X-WP-Nonce":window.EventsSchedule.nonce},params:{start:e.query.date_start,end:e.query.date_end}}).then(e.responseSuccess,e.responseError)},responseSuccessOrder:function(e){var n=this;void 0!==e.body.success&&n.orders.forEach(function(e,t,r){e.id===parseInt(n.buffer.cancel_order)&&(n.$set(n.orders[t],"status","canceled"),n.$notify({title:"Success",message:"Order has been canceled succesfully.",type:"success",offset:40,duration:2e3}))}),n.loading=!1,n.buffer.cancel_order=""},responseErrorOrder:function(e){var t=this;t.loading=!1,t.$notify({title:"Error",message:"Order could not be canceled.",type:"error",offset:40,duration:2e3})},responseSuccess:function(e){var t=this;200===e.status&&(t.orders=e.body,t.orders_count=e.body.length),t.loading=!1},responseError:function(e){var t;this.loading=!1},sortByTile:function(e,t){return e.title>=t.title},sortByDate:function(e,t){return!!moment(e.date).isAfter(t.date)},sortByOccupancy:function(e,t){return 100*e.orders_total/e.capacity>=100*t.orders_total/t.capacity},sortByBookings:function(e,t){return e.orders_total>=t.orders_total},sortByCapacity:function(e,t){return e.capacity>=t.capacity},getPostUrl:function(e){return window.EventsSchedule.urls.edit_post.replace("%%ID",e)},getTermUrl:function(e,t){return window.EventsSchedule.urls.edit_term.replace("%%ID",t).replace("%%TAX",e)}},filters:{orderStatus:function(e){return e.replace("-"," ")},capitalize:function(e){return(e+"").replace(/^([a-z\u00E0-\u00FC])|\s+([a-z\u00E0-\u00FC])/g,function(e){return e.toUpperCase()})}}})}