var wcgwpCartModal={init:function(){this.productIDs=[];this.bindUIfunctions()},getModal:function(label){let WCGWPModal=new Modal({el:document.getElementById("wcgwp-panel-"+label)})},bindUIfunctions:function(){document.addEventListener("click",function(e){if(!e.target.matches(".wcgwp-modal-toggle")){return}this.triggerEvent(document,"wood-images-loaded");this.getModal(e.target.getAttribute("data-label"));WCGWPModal.show()}.bind(this))},triggerEvent:function(el,event){let e=document.createEvent("HTMLEvents");e.initEvent(event,false,true);el.dispatchEvent(e)}};let wcgwp_modals=document.getElementsByClassName("wcgwp-modal");if(wcgwp_modals.length>0){wcgwpCartModal.init()}jQuery(function($){var wcgwpCartSlide={init:function(){$(document).on("click",".wcgwp-slidetoggle",this.slideToggle)},slideToggle:function(e){let wcgwp_label=$(e.currentTarget).data("label");$("#wcgwp-panel-"+wcgwp_label+".wcgwp-slidedown").slideToggle(400);$("#wcgwp-slidetoggle-"+wcgwp_label).toggle();$("#wcgwp-cancel-"+wcgwp_label).toggle()}};let wcgwp_slidedowns=document.getElementsByClassName("wcgwp-slidedown");if(wcgwp_slidedowns.length>0){wcgwpCartSlide.init()}if(!wcgwpWidth){let wcgwpWidth=false}if(true===wcgwpWidth){let width=$(".cart-collaterals").css("width");let float=$(".cart-collaterals").css("float");if(width&&"none"!==float){$(".wc-giftwrap.giftwrap_coupon").attr("style","width:"+width+";float:"+float+";clear:none")}}function wcgwp_clear_and_close(label){$("#wcgwp-cancel-"+label).prop("disabled",false).trigger("click");$("#wcgwp-panel-"+label+" .wcgwp-submit").prop("disabled",false);$("#wcgwp-panel-"+label+" .wcgwp-input").prop("checked",false);$("#wcgwp-note-"+label).val("")}function wcgwp_check_inputs(inputs,button){if(inputs.length<1){window.alert(wcgwpNoProductText);button.prop("disabled",false);return false}return true}$(document).on("change",".wcgwp-peri-cart-checkbox",function(){var wcgwp_action="wcgwp_ajax_wrap";var cart_item_key=null;if(!$(this).is(":checked")){cart_item_key=$(this).data("key");wcgwp_action="wcgwp_ajax_remove_wrap"}var $this=$(this);if($this.is(":disabled")||$this.hasClass("disabled")){return}$this.prop("disabled",true);$(".woocommerce-cart-form").addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var wcgwp_label=$this.data("label");var wcgwp_note=$("#wcgwp-note-"+wcgwp_label).val();$.ajax({url:wcgwpAjaxURL,type:"POST",data:{action:wcgwp_action,nonce:$("#wcgwp_nonce-"+wcgwp_label).val(),product_id:$(this).data("productid"),note:wcgwp_note,cart_item_key:cart_item_key}}).fail(function(response){$(".wcgwp-peri-cart-checkbox").prop("disabled",false);$(".woocommerce-cart-form").removeClass("processing").unblock();console.log("Failed adding gift product to cart");console.log(response)}).done(function(response){$(".wcgwp-peri-cart-checkbox").prop("disabled",false);if("wcgwp_ajax_wrap"===wcgwp_action){$this.attr("data-key",response.data.cart_item_key)}else{$this.attr("data-key","")}if(!response||!response.success){if(response&&!response.success&&response.data&&response.data.message){if("wcgwp-quantity"===response.data.message){$("body").addClass("wcgwp-quantity-error");$("body").attr({wcgwp_label:wcgwp_label,wcgwp_note:wcgwp_note})}else if("wcgwp_ajax_remove_wrap"===wcgwp_action){$(".woocommerce-cart-form").removeClass("processing").unblock();console.log("error: "+response.data.message);return}}else{$(".woocommerce-cart-form").removeClass("processing").unblock();console.log("Error while attempting to add gift wrap. See WP debug logs for more info.");return}}if(wcgwpIsCart||$("body").hasClass("woocommerce-cart")){$(document.body).trigger("wc_update_cart")}else{$(document.body).trigger("update_checkout")}})});$(document).on("click",".wcgwp-submit",function(){let $this=$(this);if($this.is(":disabled")||$this.hasClass("disabled")){return}$this.prop("disabled",true);var wcgwp_label=$this.data("label");if(!$("#wcgwp-panel-"+wcgwp_label+" input.wcgwp-input").length){console.log("Gift Wrapper error - no input!");$this.prop("disabled",false);return}var product_id=null;if($("#wcgwp-panel-"+wcgwp_label+" input.wcgwp-input").attr("type")==="hidden"){product_id=$("#wcgwp-panel-"+wcgwp_label+" input.wcgwp-input").data("productid")}else{let inputs=$("#wcgwp-panel-"+wcgwp_label+" input:checked");if(!wcgwp_check_inputs(inputs,$this)){$this.prop("disabled",false);return}product_id=$(inputs).data("productid")}if(!product_id){console.log("Gift Wrapper error - no product id!");$this.prop("disabled",false);return}$(".woocommerce-notices-wrapper, .woocommerce-NoticeGroup").html("");$(".woocommerce-cart-form").addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var wcgwp_note=$("#wcgwp-note-"+wcgwp_label).val();wcgwp_clear_and_close(wcgwp_label);$.ajax({url:wcgwpAjaxURL,type:"POST",data:{action:"wcgwp_ajax_wrap",nonce:$("#wcgwp_nonce-"+wcgwp_label).val(),product_id:product_id,note:wcgwp_note}}).fail(function(response){$(".wcgwp-submit").prop("disabled",false);$(".woocommerce-cart-form").removeClass("processing").unblock();console.log("Failed adding gift product to cart. More info:");console.log(response)}).done(function(response){$(".wcgwp-submit").prop("disabled",false);if(!response||!response.success){if(response&&!response.success&&response.data&&response.data.message&&"wcgwp-quantity"===response.data.message){$("body").addClass("wcgwp-quantity-error").attr({wcgwp_label:wcgwp_label,wcgwp_note:wcgwp_note})}else{$(".woocommerce-cart-form").removeClass("processing").unblock();console.log("Error while attempting to add gift wrap. See WP debug logs for more info.");return}}if(wcgwpIsCart||$("body").hasClass("woocommerce-cart")){$(document.body).trigger("added_to_cart",[{e_manually_triggered:!1},response.data.cart_hash,$this])}else{$(document.body).trigger("update_checkout",{update_shipping_method:false})}})});$(document.body).on("updated_wc_div",function(){if(!$("body.wcgwp-quantity-error")){return}let wcgwp_label=$("body").attr("wcgwp_label");let wcgwp_note=$("body").attr("wcgwp_note");$("#wcgwp-note-"+wcgwp_label).val(wcgwp_note);$("body").removeClass("wcgwp-quantity-error").removeAttr("wcgwp_label").removeAttr("wcgwp_note")});$(document).on("ajaxComplete",function(event,xhr,settings){if(wcgwpAjaxURL&&settings.url.includes("wc-ajax=get_refreshed_fragments")){$.ajax({type:"POST",url:wcgwpAjaxURL,data:{action:"wcgwp_update_cart"},success:function(response){if(!response){return}$(".wcgwp-prompt-wrapper").show();if(response.data.hide){$(".wcgwp-prompt-wrapper").hide()}}});if(settings.url.includes("remove_item=")){const url=new URL(settings.url);const params=new URLSearchParams(url.search);if(params){const cart_item=params.get("remove_item");if(cart_item){$('[data-key="'+cart_item+'"]').prop("checked",false)}}}}})});