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