!function(t){"use strict";var e=function(t){var e=this;this.isOpen=!1,this.init=function(){this.MC=t,this.prepare()&&(this.handleClick(),this.events())},this.prepare=function(){if(this.form=this.MC.cartPanel.querySelector("form.woocommerce-shipping-calculator"),this.form){this.formContainer=this.MC.cartPanel.querySelector(".rey-shippingCalc"),this.formContainerInner=this.MC.cartPanel.querySelector(".rey-shippingCalc-inner");var t=this.form.querySelector(".shipping-calculator-button");return t&&t.remove(),this.form.setAttribute("action","#"),this.form.addEventListener("submit",this.shipping_calculator_submit),this.addLoader(),!0}},this.handleClick=function(){this.calculateButton=this.MC.cartPanel.querySelector("a.__shipping-cost"),this.calculateButton&&this.calculateButton.addEventListener("click",(function(t){if(t.preventDefault(),e.isOpen)return e.close();e.open()}))},this.events=function(){rey.jquery.addEventListener("wc_fragments_loaded",(function(){e.prepare(),e.handleClick()}))},this.addLoader=function(){var t=document.createElement("div");t.classList.add("rey-lineLoader");var e=this.form.querySelector('button.button[name="calc_shipping"]');if(e){var i=e.textContent;e.innerHTML=`<span>${i}</span>`,e.append(t)}},this.shipping_calculator_submit=function(t){t.preventDefault(),e.form.classList.add("--loading"),e.cleanup();var i=document.createElement("input");i.setAttribute("type","hidden"),i.setAttribute("name","calc_shipping"),i.setAttribute("value","x"),e.form.append(i);var n={};e.form.querySelectorAll("input, select").forEach((t=>{n[t.getAttribute("name")]=t.value})),rey.ajax.request("calculate_shipping",{data:n,params:{method:e.form.getAttribute("method")},cb:function(t){if(!(t&&t.success&&t.data))return console.error(t);e.handleResponse(t.data)}})},this.handleResponse=function(t){if(this.form.classList.remove("--loading"),t.cost)return this.close(),this.calculateButton&&(this.calculateButton.style.opacity="0.25",this.calculateButton.style.pointerEvents="none"),void setTimeout((()=>{rey.jquery.trigger("wc_fragment_refresh",document.body)}),1500);if(!t.form)return console.log("No form.");var e=document.createElement("div");e.classList.add("rey-shippingCalc-inner"),e.innerHTML=t.form,this.isOpen&&(e.style.display="block"),this.formContainerInner.replaceWith(e),this.prepare()},this.open=function(){this.isOpen||(this.isOpen=!0,rey.animation.slideDown(this.formContainer,500),this.calculateButton&&this.calculateButton.classList.add("--active"))},this.close=function(){this.isOpen&&(this.isOpen=!1,this.calculateButton&&this.calculateButton.classList.remove("--active"),rey.animation.slideUp(this.formContainer,500))},this.cleanup=function(){this.form.querySelectorAll('.woocommerce-error, .woocommerce-message, .woocommerce-info, .woocommerce-notices-wrapper, input[name="calc_shipping"]').forEach((t=>{t.remove()}))},this.init()};rey.hooks.addAction("minicart/assets_ready",(function(t){new e(t)}))}(jQuery);