!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),n=i.data("vendor_id");const d={vendor_id:n,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-${n}`).val()&&e(`#delivery-store-location-picker-${n}`).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(`#delivery-store-location-picker-${i.vendor_id} option:gt(0)`).remove(),e.each(t.data.vendor_store_locations,(function(t,n){let d=o.get_store_location_info_from_formatted_string(n).name;e(`#delivery-store-location-picker-${i.vendor_id}`).append(e("<option></option>").attr("value",n).text(d))})))}))):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 n=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(`${n} - ${d}`))})))}))},init_calendar:function(){if("undefined"==typeof dokan_delivery_time_infos)return;const e=dokan_delivery_time_infos;let t={disable:[],minDate:"today",altInput:!0,altFormat:dokan_helper.i18n_date_format.replace("jS","J"),dateFormat:"Y-m-d",locale:dokan_flatpickr_i18n},o="";const i=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];Object.keys(e.vendor_data).forEach((n=>{const d=e.vendor_data[n].vendor_delivery_options?.delivery_day,a=void 0!==d?Object.entries(d).map((e=>parseInt(e[1])||e[0]===e[1]?e[0]:"")).filter((e=>null!==e?e:"")):[];if(!a.length)return;o=a;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[n].vendor_vacation_days,s=e.vendor_data[n].vendor_preorder_blocked_dates;t.disable=[...t.disableDays,...l,...s],delete t.disableDays,flatpickr("#delivery-time-date-picker-"+n,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 n=e(`#dokan-delivery-selector-${i}`),d=e(`#dokan-store-pickup-selector-${i}`),a=e(`#dokan-selected-delivery-type-${i}`);e("#dokan-spinner-overlay").fadeIn(100),d.removeClass("active-selector"),n.removeClass("active-selector"),e(this).hasClass("active-selector")||(e(this).addClass("active-selector"),e("#dokan-spinner-overlay").fadeOut(400)),a.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"),n=e(`#delivery-store-location-address-${i}`),d=o.get_store_location_info_from_formatted_string(this.value).address;n.parent().fadeIn(),n.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);