(()=>{"use strict";function t(a){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(a)}function a(t,a){for(var r=0;r<a.length;r++){var e=a[r];e.enumerable=e.enumerable||!1,e.configurable=!0,"value"in e&&(e.writable=!0),Object.defineProperty(t,n(e.key),e)}}function n(a){var n=function(a,n){if("object"!=t(a)||!a)return a;var r=a[Symbol.toPrimitive];if(void 0!==r){var e=r.call(a,n||"default");if("object"!=t(e))return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(a)}(a,"string");return"symbol"==t(n)?n:n+""}var r=window.jQuery;const e=function(){function t(){!function(t,a){if(!(t instanceof a))throw new TypeError("Cannot call a class as a function")}(this,t)}return n=t,i=[{key:"init",value:function(t,a){this.$table=t,this.settings=a,this.bindEvents()}},{key:"bindEvents",value:function(){this.bindVariationChange(),this.bindQuantity(),this.bindAddToCart()}},{key:"getNewUrl",value:function(t,a,n){var r=new URL(t);return r.searchParams.set("item_id",a),r.searchParams.set("quantity",n),r.toString()}},{key:"bindVariationChange",value:function(){this.$table.on("change",".nt_fct_variations_select",function(a){var n=r(this),e=n.find(":selected"),i=n.closest("tr"),o=n.closest(".nt_fct_variations_wrapper").data("product_id"),c=e.data("variation_id")||0,d=e.data("formatted_price")||"",_=e.data("compared_price")||"",l=e.data("image_src")||"",s=e.data("stock")||0,u=n.closest(".nt_fct_variations_wrapper").data("product_type")||"",p=i.data("is_compare_row")||!1,f=i.data("row_id")||!1,v=function(t){var a=i.find(t);return a.length?a:i.parent().find(t)},b=v(".nt_fct_product_price_wrapper");p&&(b=v('[data-pid="'+o+'"] .nt_fct_product_price_wrapper')),b.find(".nt_fct_product_price").text(d);var y=b.find(".nt-fct-compared-price");_?y.text(_).show():y.hide();var m=v(".fct_product_image");f?m=v('[data-row_id="'.concat(i.data("row_id"),'"] .fct_product_image')):p&&(m=v('[data-pid="'.concat(o,'"] .fct_product_image'))),l&&m&&m.attr("src",l);var g=v(".nt_fct_product_stock");p&&(g=v('[data-pid="'+o+'"] .nt_fct_product_stock')),g.length&&g.attr("data-product_stock",s).text(s);var h=v(".nt_fct_add_to_cart_".concat(o));if(h.attr("data-variation_id",c),"digital"===u){(h=v(".nt_fct_buy_now_".concat(o))).attr("data-variation_id",c);var w=i.find(".nt_fct_add_cart_wrapper a"),j=w.data("quantity")||1,k=t.getNewUrl(w.attr("href"),c,j);w.attr("href",k)}})}},{key:"bindQuantity",value:function(){this.$table.on("change",".nt_fct_quantity",function(){var a=r(this),n=a.data("product_type"),e=a.data("product_id"),i=Math.max(1,parseInt(a.val(),10)||1);a.val(i);var o=t.$table.find(".nt_fct_add_to_cart_".concat(e));"digital"===n&&(o=t.$table.find(".nt_fct_buy_now_".concat(e))),o.attr("data-quantity",i);var c=o.data("variation_id");if("digital"===n){var d=t.getNewUrl(o.attr("href"),c,i);o.attr("href",d)}})}},{key:"bindAddToCart",value:function(){this.$table.on("click",'[class*="nt_fct_add_to_cart_"]:not(.loading)',function(a){var n;a.preventDefault();var e=r(this),i=e.parent();if(!e.data("processing")){e.data("processing",!0),i.addClass("loading"),e.prop("disabled",!0);var o=null===(n=a.target)||void 0===n?void 0:n.dataset;if(o){var c={product_id:o.product_id,variation_id:parseInt(o.variation_id),quantity:o.quantity};t._ajaxAdd([c],e,i)}}})}},{key:"_ajaxAdd",value:function(t,a,n,e){var i=window.ninja_footables||{},o=i.ajax_url,c=i.ninja_table_public_nonce;r.post(o,{action:"ninja_table_wp_fct_add_to_cart",nonce:c,table_id:(null==e?void 0:e.table_id)||this.settings.table_id,products:t}).done(function(t){null!=t&&t.success&&t.cart_html?(r(".ninjatable_cart_wrapper.fluent-cart").length?r(".ninjatable_cart_wrapper.fluent-cart").replaceWith(t.cart_html):r(".ninja_table_wrapper").append(t.cart_html),n&&n.addClass("added").removeClass("loading"),setTimeout(function(){n&&n.removeClass("loading"),a&&a.prop("disabled",!1).removeData("processing")},1e3)):(n&&n.removeClass("loading"),a&&a.prop("disabled",!1).removeData("processing"))}).fail(function(){n&&n.removeClass("loading"),a&&a.prop("disabled",!1).removeData("processing")})}}],(e=null)&&a(n.prototype,e),i&&a(n,i),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,e,i}();jQuery(document).ready(function(t){t(document).on("ninja_table_loaded",function(t,a,n){"wp_fct"===n.provider&&e.init(a,n)})})})();