jQuery(function(e){const t={init:function(){t.set_admin_delivery_time_slots(e("#dokan-delivery-admin-date-picker")),e("#dokan-admin-store-location-picker").on("change",t.set_selected_store_full_location).trigger("change"),e(".delivery-type-delivery").on("click",t.set_delivery_order_type),e(".delivery-type-pickup").on("click",t.set_pickup_order_type),e(".save_order").on("click",t.validate_order_delivery_type_fields),t.dokan_custom_datepicker(e("#dokan-delivery-admin-date-picker"))},dokan_custom_datepicker:function(i){let d=e(i),a={action:"dokan_get_delivery_days",vendor_id:d.data("vendor_id"),nonce:d.data("nonce")};e.post(dokan_admin.ajaxurl,a,function(i){e("#dokan-delivery-admin-date-picker").datepicker("option",{beforeShowDay:function(e){let t=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"],d=i.data.disabled_weekdays,a=e.getDay(),o=!0;return d.map(function(e,i){e===t[a]&&(o=!1)}),[o]},dateFormat:dokan_get_i18n_date_format(),altFormat:"yy-mm-dd",altField:"#dokan_delivery_date_input",minDate:i.data.default_date,defaultDate:i.data.default_date}).on("change",function(e){e.preventDefault(),t.set_admin_delivery_time_slots(this)})})},set_admin_delivery_time_slots:function(i){e(i).attr("value",e("#dokan-delivery-admin-date-picker").val());let d=e(i),a=d.data("vendor_id"),o=e("#dokan_delivery_date_input").val(),n={action:"dokan_get_delivery_time_slot",vendor_id:a,nonce:d.data("nonce"),date:o};n.date&&t.get_admin_delivery_time_slots(n)},set_selected_store_full_location:function(){const t=e(this).children("option:selected").data("value");if(t)return e(".store-address").slideDown(300,function(){e(this).text(t)}),void e(".store-pickup-select-options hr").slideDown(300);e(".store-address").slideUp(300),e(".store-pickup-select-options hr").slideUp(300)},set_delivery_order_type:function(){e("input.delivery-type-delivery")[0].hasAttribute("checked")||(e("input.delivery-type-delivery").attr("checked","checked"),e("input.delivery-type-pickup").removeAttr("checked")),t.update_delivery_meta_content("slideUp","delivery")},set_pickup_order_type:function(){e("input.delivery-type-pickup")[0].hasAttribute("checked")||(e("input.delivery-type-pickup").attr("checked","checked"),e("input.delivery-type-delivery").removeAttr("checked")),t.update_delivery_meta_content("slideDown","pickup")},validate_order_delivery_type_fields:function(i){if(!e("#dokan-delivery-admin-date-picker").val())return;e("#dokan-admin-delivery-time .dokan-error").hide();const d=e(".admin-delivery-type #selected-delivery-type").val(),a=e("#dokan-delivery-admin-time-slot-picker").val(),o=e("#dokan-admin-store-location-picker").val();a||t.show_delivery_type_box_error(i,"#dokan-delivery-admin-time-slot-picker"),"delivery"===d||o||t.show_delivery_type_box_error(i,"#dokan-admin-store-location-picker")},show_delivery_type_box_error:function(t,i){t.preventDefault(),e(`${i} + .dokan-error`).show(),e("#dokan_delivery_time_fields")[0].scrollIntoView({block:"start",behavior:"smooth"})},update_delivery_meta_content:function(t,i){Admin_Delivery_Meta[i+"_date"];let d=Admin_Delivery_Meta[i+"_slot"],a=Admin_Delivery_Meta[i+"_current_label"],o=Admin_Delivery_Meta[i+"_header"],n=Admin_Delivery_Meta[i+"_placeholder"];e("#dokan-admin-delivery-time .dokan-error").hide(),e("#dokan_delivery_time_fields .postbox-header h2").text(o),e("#dokan-delivery-type-time span strong").text(a),e("#dokan-delivery-admin-date-picker").attr("placeholder",n),e("ul.form-field .wide label").text(d),e(".admin-delivery-type #selected-delivery-type").val(i),e("ul.form-field .store-pickup-select-options label").text("pickup"===i?Admin_Delivery_Meta[i+"_location"]:""),e(".store-pickup-select-options")[t](300),e("#dokan-store-pickup-location")[t](300)},get_admin_delivery_time_slots:function(t){const i=e("#dokan_delivery_time_fields");i.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),e("#dokan-delivery-admin-time-slot-picker").prop("disabled",!0),e.post(dokan_admin.ajaxurl,t,function(t){i.unblock(),t.success&&(e("#dokan-delivery-admin-time-slot-picker option:gt(0)").remove(),e.each(t.data.vendor_delivery_slots,function(t,i){let d=dokan_get_formatted_time(i.start,dokan_get_i18n_time_format(),"hh:mm a"),a=dokan_get_formatted_time(i.end,dokan_get_i18n_time_format(),"hh:mm a");e("#dokan-delivery-admin-time-slot-picker").append(e("<option></option>").attr("value",t).text(`${d} - ${a}`))}),e("#dokan-delivery-admin-time-slot-picker").prop("disabled",!1))})}};jQuery(document).ready(function(e){t.init()})});