jQuery(function($){if(!$('form.checkout').length&&!$('.woocommerce-checkout').length)return;const bluexKeywords=['bluex','blue x','bluexpress','blue express','bluex - express'];const isBlueX=(t)=>bluexKeywords.some(k=>t.toLowerCase().indexOf(k)!==-1);let allowedPickupLabels=[];function getAjaxURL(){if(window.VS_CHECKOUT_UNION&&window.VS_CHECKOUT_UNION.ajax){return window.VS_CHECKOUT_UNION.ajax}
if(window.wc_checkout_params&&wc_checkout_params.ajax_url){const sep=wc_checkout_params.ajax_url.indexOf('?')>-1?'&':'?';return wc_checkout_params.ajax_url+sep+'action=vs_outlets_union'}
if(window.ajaxurl){const sep=ajaxurl.indexOf('?')>-1?'&':'?';return ajaxurl+sep+'action=vs_outlets_union'}
return null}
function fetchUnion(){const url=getAjaxURL();if(!url){return $.Deferred().resolve().promise()}
return $.getJSON(url).then(resp=>{if(resp&&resp.success){allowedPickupLabels=resp.data.allowed_pickups||[]}else{allowedPickupLabels=[]}}).fail(()=>{allowedPickupLabels=[]})}
function clearRegionComuna(){const $state=$('#billing_state');const $city=$('#billing_city');if($state.length){if(!$state.find('option[value=""]').length)$state.prepend('');$state.val('').trigger('change.select2').trigger('change')}
if($city.length){if(!$city.find('option[value=""]').length)$city.prepend('');$city.val('').trigger('change.select2').trigger('change')}
setTimeout(()=>$(document.body).trigger('update_checkout'),120)}
function toggleShippingByTipo(){const tipo=$('#billing_Tipo_de_Despacho').val();let $firstVisible=null;let anyVisibleChecked=!1;$('.woocommerce-shipping-methods li').each(function(){const $li=$(this);const $radio=$li.find('input[type="radio"]');const label=$li.text().trim();const show=()=>{$li.show();$radio.prop('disabled',!1)};const hide=()=>{$li.hide();$radio.prop('disabled',!0);if($radio.prop('checked')){$radio.prop('checked',!1).trigger('change')}};if(tipo==='retiro_tienda'){if(allowedPickupLabels.length===0){show()}else if(allowedPickupLabels.includes(label)){show();if(!$firstVisible)$firstVisible=$radio;if($radio.prop('checked'))anyVisibleChecked=!0}else{hide()}}else{if(isBlueX(label)){show();if(!$firstVisible)$firstVisible=$radio;if($radio.prop('checked'))anyVisibleChecked=!0}else{hide()}}});if(!anyVisibleChecked&&$firstVisible){$firstVisible.prop('checked',!0).trigger('change')}}
fetchUnion().always(toggleShippingByTipo);$('#billing_Tipo_de_Despacho').on('change',function(){if($(this).val()==='retiro_tienda')clearRegionComuna();fetchUnion().always(toggleShippingByTipo)});$(document.body).on('updated_checkout',function(){fetchUnion().always(toggleShippingByTipo)})})