!function(e){const t={init:function(){e(".delivery-time-slot-picker").hide(),e(".store-pickup-select-options .store-address").hide(),e(".delivery-time-date-picker").on("change",t.delivery_type_selector_handler),t.init_calendar()},delivery_type_selector_handler:function(o){o.preventDefault();let i=e(o.target),a=i.data("vendor_id");const d={vendor_id:a,nonce:i.data("nonce"),selected_date:i.attr("value")};t.get_delivery_time_slots(d),t.get_store_pickup_locations(d),"delivery"===e(`#dokan-selected-delivery-type-${a}`).val()&&e(`#delivery-store-location-picker-${a}`).hide()},get_store_pickup_locations:function(t){let i={action:"dokan_store_location_get_items",vendor_id:t.vendor_id,nonce:t.nonce};t.selected_date?(e(`#delivery-store-location-picker-${t.vendor_id}`).fadeIn(400),e("#dokan-spinner-overlay").fadeIn(100),jQuery.post(dokan.ajaxurl,i,function(t){t.success&&(e("#dokan-spinner-overlay").fadeOut(400),e.each(t.data.vendor_store_locations,function(a,d){let n=o.get_store_location_info_from_formatted_string(d).name,r=e(`#delivery-store-location-picker-${i.vendor_id}`);if(0===e(`#delivery-store-location-picker-${i.vendor_id} option[value="`+d+'"]').length&&r.append(e("<option></option>").attr("value",d).text(n)),1===t.data.vendor_store_locations.length){let a=`option[value='${t.data.vendor_store_locations[0]}']`;r.find(a).prop("selected",!0);const n=e(`#delivery-store-location-address-${i.vendor_id}`),l=o.get_store_location_info_from_formatted_string(d).address;n.parent().fadeIn(),n.html(l)}}))})):e(`#delivery-store-location-picker-${t.vendor_id}`).fadeOut(400)},get_delivery_time_slots:function(o){o.selected_date?e(`#delivery-time-slot-picker-${o.vendor_id}`).fadeIn(400):e(`#delivery-time-slot-picker-${o.vendor_id}`).fadeOut(400),e(`#delivery-time-slot-picker-${o.vendor_id}`).val(e(`#delivery-time-slot-picker-${o.vendor_id} option:first`).val());let i={action:"dokan_get_delivery_time_slot",vendor_id:o.vendor_id,nonce:o.nonce,date:o.selected_date};i.date&&t.get_delivery_time_slots_data(i)},get_delivery_time_slots_data:function(t){e("#dokan-spinner-overlay").fadeIn(100),jQuery.post(dokan.ajaxurl,t,function(o){o.success&&(e("#dokan-spinner-overlay").fadeOut(400),e(`#delivery-time-slot-picker-${t.vendor_id} option:gt(0)`).remove(),e.each(o.data.vendor_delivery_slots,function(o,i){let a=dokan_get_formatted_time(i.start,dokan_get_i18n_time_format(),"hh:mm a"),d=dokan_get_formatted_time(i.end,dokan_get_i18n_time_format(),"hh:mm a");e(`#delivery-time-slot-picker-${t.vendor_id}`).append(e("<option></option>").attr("value",o).text(`${a} - ${d}`))}))})},init_calendar:function(){if("undefined"==typeof dokan_delivery_time_infos)return;const e=dokan_delivery_time_infos;let t={disable:[],minDate:e.default_date,altInput:!0,altFormat:dokan_helper.i18n_date_format.replace("jS","J"),dateFormat:"Y-m-d",locale:dokan_flatpickr_i18n,defaultDate:e.default_date},o="";const i=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];Object.keys(e.vendor_data).forEach(a=>{const d=e.vendor_data[a].vendor_delivery_options?.delivery_day,n=void 0!==d?Object.entries(d).map(e=>parseInt(e[1])||e[0]===e[1]?e[0]:"").filter(e=>null!==e?e:""):[];if(!n.length)return;o=n;let r=[];i.forEach(e=>{o.includes(e)||r.push(i.indexOf(e))}),t.disableDays=[function(e){return r.includes(e.getDay())}],t.disable=[...t.disableDays];const l=e.vendor_data[a].vendor_vacation_days,s=e.vendor_data[a].vendor_preorder_blocked_dates;t.disable=[...t.disableDays,...l,...s],delete t.disableDays,flatpickr("#delivery-time-date-picker-"+a,t)})}},o={init:function(){e(".dokan-store-location-selector").length&&this.trigger_store_location_pickup()},trigger_store_location_pickup:function(){e(".dokan-store-location-selector .selector-wrapper .selector").on("click",function(t){const o=e(this).data("selector"),i=e(this).data("vendor_id");let a=e(`#dokan-delivery-selector-${i}`),d=e(`#dokan-store-pickup-selector-${i}`),n=e(`#dokan-selected-delivery-type-${i}`);e("#dokan-spinner-overlay").fadeIn(100),d.removeClass("active-selector"),a.removeClass("active-selector"),e(this).hasClass("active-selector")||(e(this).addClass("active-selector"),e("#dokan-spinner-overlay").fadeOut(400)),n.val(o),"delivery"===o?(e(`#delivery-store-location-picker-${i}`).fadeOut(),e(`#delivery-store-location-address-${i}`).parent().fadeOut()):"store-pickup"===o&&(e(`#delivery-store-location-picker-${i}`).fadeIn(),e(`#delivery-store-location-picker-${i}`).val()&&e(`#delivery-store-location-address-${i}`).parent().fadeIn())}),e(".delivery-store-location-picker").on("change",function(t){const i=e(this).data("vendor_id"),a=e(`#delivery-store-location-address-${i}`),d=o.get_store_location_info_from_formatted_string(this.value).address;a.parent().fadeIn(),a.html(d)})},get_store_location_info_from_formatted_string:e=>e?{name:e.split("(")[0],address:e.match(/\((.*?)\)/)[1]}:{name:"",address:""}};jQuery(document).ready(function(e){o.init(),t.init()})}(jQuery);