jQuery(function(e){"use strict";var a=e("body"),t=function(e){(function(e){return e.is(".processing")||e.parents(".processing").length})(e)||e.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})};e(document).on("click",".ywpar-button-message",function(a){a.preventDefault();var t=e(this);t.hasClass("ywpar-button-percentage-discount")?t.next().find("form").submit():e(".ywpar_apply_discounts_container").slideToggle()}),e(document).on("click","#ywpar_apply_discounts",function(a){a.preventDefault();var r=e(this),o=e("#ywpar-points-max"),n=o.attr("min"),i=o.val(),c=e(".ywpar_min_reedem_value_error"),s=r.parents("form");if(parseFloat(i)<parseFloat(n))return c.show(),!1;c.css("opacity","0"),e("#ywpar_input_points_check").val(1),yith_ywpar_general.redeem_uses_ajax?function(a){t(e("#yith-par-message-reward-cart"));var r={ywpar_points_max:a.find("input[name=ywpar_points_max]").val(),ywpar_max_discount:a.find("input[name=ywpar_max_discount]").val(),ywpar_rate_method:a.find("input[name=ywpar_rate_method]").val(),ywpar_input_points_nonce:a.find("#ywpar_input_points_nonce").val(),ywpar_input_points:a.find("#ywpar-points-max").val(),ywpar_input_points_check:a.find("#ywpar_input_points_check").val()};e.ajax({type:"POST",url:yith_ywpar_general.wc_ajax_url.toString().replace("%%endpoint%%","ywpar_apply_points"),data:r,dataType:"html",success:function(e){console.log("ywpar_applied")},complete:function(){"cart"===yith_ywpar_general.cart_or_checkout?(e(".woocommerce-cart-form button[name=update_cart]").removeAttr("disabled"),e(".woocommerce-cart-form button[name=update_cart]").click()):e("body").trigger("update_checkout")}})}(s):s.submit()}),e.fn.yith_ywpar_variations=function(a){var t=(a=e(".variations_form:not(.in_loop)")).closest(".product").find(".yith-par-message"),r=a.closest(".product").find(".yith-par-message-variation");t.length||(t=e(".product").find(".yith-par-message"),r=e(".product").find(".yith-par-message-variation")),t.length||(t=e(".yith-par-message"),r=e(".yith-par-message-variation"));var n=r.find(".product_point"),i=r.find(".product-point-conversion");a.on("found_variation",function(a,c){let s=e(".single-product form.cart .qty").val();t.addClass("hide"),r.removeClass("hide"),0==c.variation_points&&r.addClass("hide"),c.variation_points&&(n.text(Math.floor(c.variation_points)*s),n.data("basepoints",Math.floor(c.variation_points))),c.variation_price_discount_fixed_conversion&&i.html(c.variation_price_discount_fixed_conversion),o(s)}),a.on("reset_data",function(){r.addClass("hide"),t.removeClass("hide"),o(e(".single-product form.cart .qty").val())}),a.find("select").first().trigger("change")},a.hasClass("single-product")&&e.fn.yith_ywpar_variations(),e(document).on("qv_loader_stop",function(){e.fn.yith_ywpar_variations()}),e(document.body).on("updated_cart_totals added_to_cart updated_checkout update_shipping_method",function(a){if("updated_checkout"===a.type||"updated_cart_totals"===a.type){var t=e("#yith-par-message-cart");t.length>0&&e.ajax({url:yith_ywpar_general.wc_ajax_url.toString().replace("%%endpoint%%","ywpar_update_cart_messages")+"&cart_or_checkout="+yith_ywpar_general.cart_or_checkout,type:"POST",success:function(e){""!==e?t.show().html(e):t.hide()}})}else{e(".woocommerce > #yith-par-message-cart").remove(),e(".woocommerce-notices-wrapper > #yith-par-message-cart").length>1&&e(".woocommerce-notices-wrapper > #yith-par-message-cart:last-child").remove()}if("updated_checkout"===a.type||"updated_cart_totals"===a.type){if(0===e("#yith-par-message-reward-cart").length)e(yith_ywpar_general.default_container).after('<div id="yith-par-message-reward-cart" style="display:none" class="woocommerce-cart-notice woocommerce-cart-notice-minimum-amount woocommerce-info"></div>');e(document).find("#yith-par-message-reward-cart").length>0&&e.ajax({url:yith_ywpar_general.wc_ajax_url.toString().replace("%%endpoint%%","ywpar_update_cart_rewards_messages"),type:"POST",beforeSend:function(){},success:function(a){let t=e(document).find("#yith-par-message-reward-cart");t.addClass(yith_ywpar_general.reward_message_type),""!==a.trim()?(t.show().html(a),r()):t.hide()}})}else{e(".woocommerce > #yith-par-message-reward-cart").remove(),e(".woocommerce-notices-wrapper > #yith-par-message-reward-cart").length>1&&e(".woocommerce-notices-wrapper > #yith-par-message-reward-cart:last-child").remove()}});const r=function(){var a;e(document).on("keyup","#ywpar-points-max",function(r){clearTimeout(a);var o=e(this);a=setTimeout(function(){let a=o.val();""!==a&&e.isNumeric(a)||(a=0);var r={input_points:a,max_points:e("#yith-par-message-reward-cart input[name=ywpar_points_max], .wp-block-yith-par-message-reward-cart.default-layout input[name=ywpar_points_max]").val(),method:e("#yith-par-message-reward-cart input[name=ywpar_rate_method], .wp-block-yith-par-message-reward-cart.default-layout input[name=ywpar_rate_method]").val(),security:yith_ywpar_general.discount_value_nonce};e.ajax({url:yith_ywpar_general.wc_ajax_url.toString().replace("%%endpoint%%","ywpar_calc_discount_value"),type:"POST",data:r,dataType:"json",beforeSend:function(){t(e("#yith-par-message-reward-cart.default-layout .woocommerce-Price-amount, .wp-block-yith-par-message-reward-cart.default-layout .woocommerce-Price-amount"))},success:function(a){""!==a.to_redeem&&e("#yith-par-message-reward-cart .woocommerce-Price-amount, .wp-block-yith-par-message-reward-cart .woocommerce-Price-amount").html(a.to_redeem)},complete:function(){e("#yith-par-message-reward-cart.default-layout .woocommerce-Price-amount, .wp-block-yith-par-message-reward-cart").removeClass("processing").unblock()}})},500)})};function o(a){if("no"!==yith_ywpar_general.update_product_message){var t=e(".single-product .yith-par-message-variation").length?"variable":"simple",r=e(".single-product .yith-par-message-product .product_point"),o=r.data("basepoints"),n=e(".single-product .yith-par-message-product .product-point-conversion"),i=n.data("baseworthprice"),c=n.find(".amount bdi"),s=c.first().find(".woocommerce-Price-currencySymbol").text(),p=yith_ywpar_general.wc_currency_position;a=Number(a);if(o)if(o.toString().indexOf("-")>0){let e=o.split("-");e.forEach((t,r)=>{e[r]=Number(t)*a});let t=e.join("-");r.html(t)}else r.text(Number(o)*a);if(s&&i)if(i.toString().indexOf("-")>0){let e=i.split("-");e.forEach((t,r)=>{e[r]="left"===p?'<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">'+s+"</span>"+Number(t)*a+"</bdi></span>":'<span class="woocommerce-Price-amount amount"><bdi>'+Number(t)*a+'<span class="woocommerce-Price-currencySymbol">'+s+"</span></bdi></span>"});let t=e.join("-");n.html(t)}else{let e=(Number(i)*a).toFixed(2);"left"===p?c.html('<span class="woocommerce-Price-currencySymbol">'+s+"</span>"+e):c.html(e+'<span class="woocommerce-Price-currencySymbol">'+s+"</span>")}if("variable"===t){let t=e(".single-product .yith-par-message-variation").find(".product_point"),r=t.data("basepoints"),n=e(".single-product .yith-par-message-variation .product-point-conversion"),i=n.data("baseworthprice"),c=n.find(".amount bdi");if(r.toString().indexOf("-")>0){let e=o.split("-");e.forEach((t,r)=>{e[r]=Number(t)*a});let r=e.join("-");t.html(r)}else r&&t.text(Number(r)*a);if(void 0!==i&&i.toString().indexOf("-")>0){let e=i.split("-");e.forEach((t,r)=>{var o="";o="left"===p?'<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">'+s+"</span>"+Number(t)*a+"</bdi></span>":'<span class="woocommerce-Price-amount amount"><bdi>'+Number(t)*a+'<span class="woocommerce-Price-currencySymbol">'+s+"</span></bdi></span>",e[r]=o});let t=e.join("-");n.html(t)}else if(s&&i){let e=(Number(i)*a).toFixed(2);"left"===p?c.html('<span class="woocommerce-Price-currencySymbol">'+s+"</span>"+e):c.html(e+'<span class="woocommerce-Price-currencySymbol">'+s+"</span>")}}}}e(document).on("wc_fragments_refreshed",function(){r()}),r(),e('input[name="yith_birthday"]').length>0&&function(){let e=yith_ywpar_general.birthday_date_format.replace("yy","yyyy");new dtsel.DTS('input[name="yith_birthday"]',{dateFormat:e,localization:yith_ywpar_general.datepicker})}(),e(document).on("click",".ywpar_tabs_links",function(a){var t,r,o,n=e(this).closest("#ywpar_tabs");t=a,r=n,o=e(this).data("target"),r.find(".ywpar_tabcontent").each(function(){e(this).hide()}),r.find(".ywpar_tabs_links").each(function(){e(this).removeClass("active")}),r.find("#"+o).fadeIn("slow"),t.currentTarget.className+=" active"}),e(document).find(".ywpar_tabs_links.active").each(function(){e(this).click()}),e(document).on("change",".single-product form.cart .qty",function(){o(e(this).val())}),e(document).on("ywdpd_handle_quantity_changed",function(e,a){o(a)})});