!function(){function e(e){p("add_subtitles_for_blocks:"),"undefined"!=typeof jQuery&&(jQuery(".fns-description.blocks").remove(),jQuery(".wc-block-components-shipping-rates-control input").each(function(t,n){for(const[t,o]of Object.entries(e))jQuery(n).attr("value")=="fish_n_ships:"+t&&(wrapper=jQuery(n).closest("label"),jQuery(".wc-block-components-radio-control__label-group",wrapper).after('<div class="fns-description blocks">'+o+"</div>"))}))}function t(e){p("new_update_messages()"),"undefined"!=typeof jQuery&&(f=[...f,...e.filter(e=>"error"===e.type).map(e=>l(e.message))],"undefined"!=typeof wcfns_data&&0==wcfns_data.is_checkout&&0==wcfns_data.is_cart&&Object.keys(e).forEach((t,n)=>{"scrtchk"==e[t].show&&delete e[t]}),jQuery(".wc-block-components-notice-banner.is-error").each(function(t,n){jQuery(".fns_notice_control",n).length>0||1==jQuery(".wc-block-components-notice-banner__content",n).length&&(text_error=l(jQuery(".wc-block-components-notice-banner__content",n).text()),message=e.find(e=>"error"==e.type&&l(e.message)==text_error),message?jQuery(n).append(o(message)):f.includes(text_error)&&jQuery(n).hide())}),jQuery("div.fns_notice_control").each(function(t,n){id=jQuery(n).attr("data-id"),p("There is a message with the id: "+id),message=e.find(e=>e.id===id),message?(p("keep the message"),c(n)):(p("delete the message"),s(n,!1))}),must_do_scroll2messages=!1,Object.keys(e).forEach((t,o)=>{message=e[t],p("looking for messages with the id: "+message.id),found=jQuery('div.fns_notice_control[data-id="'+message.id+'"]'),0==found.length&&(message.deadline&&wcfns_data.php_time>message.deadline?p("outdated message, we won't add it"):(jQuery(d(document)).prepend(n(message)),p("adding the message"),must_do_scroll2messages=!0)),jQuery(found).each(function(e,t){0==e?r(message)!=jQuery(t).attr("data-hashed")?(p("the message had been changed"),wrapper_el=a(t),jQuery(wrapper_el).replaceWith(n(message)),c(t),must_do_scroll2messages=!0):(c(t),p("the message remains unchanged")):(p("deleting duplicated message"),s(t,!0))})}),must_do_scroll2messages&&(scrollElement=d(document),new_top=scrollElement.first().offset().top-150,current_top=jQuery(window).scrollTop(),viewportHeight=jQuery(window).height(),(new_top<current_top||new_top>current_top+viewportHeight/2)&&jQuery("html, body").animate({scrollTop:new_top},1e3)))}function n(e){if(type=e.type,"undefined"!=typeof wcfns_data&&wcfns_data["tmpl_"+type]&&""!=wcfns_data["tmpl_"+type]){html=wcfns_data["tmpl_"+type],html=html.replace("#text#",'<div class="fns-text">'+e.message+"</div>");let t=html.lastIndexOf("</div>");return-1===t&&(t=html.lastIndexOf("</")),html=html.substring(0,t)+o(e)+html.substring(t),html=html.replace(/class\s*=\s*(['"])\s*(.*?)\s*\1/,(t,n,o)=>`class=${n}${o.trim()} ${e.cssextra}${n}`),console.log(html),html}return"success"==type&&(type="message"),"notice"==type&&(type="info"),html='<div class="woocommerce-'+type+" "+e.cssextra+'" role="alert"><div class="fns-text">'+e.message+"</div>"+o(e)+"</div>",html}function o(e){return'<div class="fns_notice_control" data-id="'+e.id+'" data-hashed="'+r(e)+'" style="display: none;"></div>'}function r(e){const t=JSON.stringify(e);let n=0;for(let e=0;e<t.length;e++){n=(n<<5)-n+t.charCodeAt(e),n&=n}return Math.abs(n).toString(16)}function s(e,t){wrapper=a(e),wrapper&&t&&jQuery(wrapper).addClass("fns-hidden").hide(),wrapper&&!t&&jQuery(wrapper).addClass("fns-hidden").fadeOut()}function c(e){wrapper=a(e),wrapper&&jQuery(wrapper).hasClass("fns-hidden")&&jQuery(wrapper).removeClass("fns-hidden").fadeIn()}function a(e){const t=[".wc-block-components-notice-banner",".wc-block-store-notice",".woocommerce-info",".woocommerce-error",".woocommerce-message"];return jQuery(e).closest("ul.woocommerce-error").length>0&&(p("old-style list errors detected"),t.unshift("li")),result=!1,t.forEach(t=>{if(match=jQuery(e).closest(t),match.length>0)return p("wrapper found: "),p(match),result=match,!0}),result}function d(e){return $target=jQuery(e).find(".wc-block-components-notices").first(),0!=$target.length?$target:($target=jQuery(e).find(".woocommerce-notices-wrapper").first(),0!=$target.length?$target:($target=jQuery(e).find(".cart-empty").closest(".woocommerce").first(),0!=$target.length?$target:($target=jQuery(e).find(".woocommerce-cart-form").first(),0!=$target.length?$target:($target=jQuery(e).find("main").first(),0!=$target.length?$target:(p("Can't find notices wrapper"),!1)))))}function i(){jQuery(".fns_notice_control").hide(),jQuery(".fns_notice_control").each(function(e,t){wrapper=a(t),cssextra=jQuery(t).attr("data-cssextra"),jQuery(wrapper).addClass(cssextra)})}function u(){if(p("refresh_after_classic_update()"),jQuery(".wc_fns_cart_control").length>0){code=jQuery(".wc_fns_cart_control").last().text();try{p(JSON.parse(atob(code)));var n=JSON.parse(atob(code));p(n)}catch(e){return void console.error("[Advanced Shipping Rates for WooCommerce] Error parsing JSON:",e)}n.php_time&&n.php_time>m?(m=n.php_time,n.descriptions&&e(n.descriptions),n.messages&&t(n.messages)):p("Old cart control data, maybe cached?")}}function l(e){return e.trim().replace(/\s+/g," ").normalize("NFC")}function p(e){"undefined"!=typeof wcfns_data&&1==wcfns_data.verbose&&(h&&(console.log("=============================================================================="),console.log(" This is the Advanced Shipping Rates for WooCommerce log for messages."),console.log(" Useful to check/debug our new support for WC blocks cart & checkout."),console.log(" This log will only be printed if you're logged in as admin or shop manager."),console.log("=============================================================================="),h=!1),console.log(e))}var f=[],m=0;document.addEventListener("DOMContentLoaded",function(){var t=document.body;new MutationObserver(function(t,n){for(var o of t)if("childList"===o.type)for(var r of o.addedNodes)if(1===r.nodeType&&(fullHtml=r.outerHTML,fullHtml.includes("wp-block-woocommerce-cart-order-summary-shipping-block")||fullHtml.includes("wc-block-checkout__shipping-option")))return p("New blocks for cart or checkout detected."),"undefined"!=typeof wcfns_data&&wcfns_data.descriptions&&e(wcfns_data.descriptions),void n.disconnect()}).observe(t,{childList:!0,subtree:!0}),p("Observer configured for body.")});const _=window.fetch;window.fetch=async function(){p("Fetch request:");const n=await _.apply(this,arguments);return n.clone().json().then(n=>{p("window.fetch, data:"),p(n);var o=!1;n.responses&&n.responses[0]&&n.responses[0].body&&n.responses[0].body.wcfns_data?o=n.responses[0].body.wcfns_data:n.wcfns_data?o=n.wcfns_data:p("No wcfns data."),o&&(o.php_time&&o.php_time>m?(m=o.php_time,o.descriptions&&e(o.descriptions),o.messages&&t(o.messages)):p("Old fetch data, maybe cached?"))}).catch(e=>{p("Error processing response as JSON:")}),n},jQuery(document).ready(function(e){i(),"undefined"!=typeof wcfns_data&&wcfns_data.php_time&&(m=wcfns_data.php_time,wcfns_data.messages&&t(wcfns_data.messages)),jQuery(document).on("wc_fragments_loaded event",function(){p("wc_fragments_loaded"),u()}),jQuery(document).on("updated_checkout",function(){p("updated_checkout event"),i(),u()}),jQuery(document).on("wc_fragments_refreshed",function(){p("wc_fragments_refreshed event"),u()}),jQuery(document).on("updated_wc_div",function(){p("updated_wc_div event"),u()}),jQuery(document).on("update_checkout",function(){p("update_checkout event (ignored)")}),jQuery(document).on("wc_cart_emptied",function(){p("wc_cart_emptied event (ignored)")}),jQuery(document).on("updated_wc_div",function(){p("updated_wc_div")}),jQuery(document).on("updated_cart_totals",function(){p("updated_cart_totals event (ignored)")}),jQuery(document).on("updated_shipping_method",function(){p("updated_shipping_method event (ignored)")}),jQuery(document).on("applied_coupon",function(){p("applied_coupon event (ignored)")}),jQuery(document).on("removed_coupon",function(){p("removed_coupon event (ignored)")}),jQuery(document).on("wc_fragment_refresh",function(){p("wc_fragment_refresh event (ignored)")})});var h=!0}();