(()=>{"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 i=a[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,n(i.key),i)}}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 i=r.call(a,n||"default");if("object"!=t(i))return i;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 i=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,e=[{key:"init",value:function(t,a){this.$table=t,this.settings=a,this.bindEvents(t,a)}},{key:"bindEvents",value:function(t,a){this.bindVariationChange(t),this.bindQuantity(t),this.bindAddToCart(t,a)}},{key:"bindEventsFor",value:function(t,a){this.bindEvents(t,a)}},{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(a){a.on("change",".nt_fct_variations_select",function(a){var n=r(this),i=n.find(":selected"),e=n.closest("tr"),o=n.closest(".nt_fct_variations_wrapper").data("product_id"),c=i.data("variation_id")||0,d=i.data("formatted_price")||"",_=i.data("compared_price")||"",u=i.data("image_src")||"",s=i.data("stock")||0,l=n.closest(".nt_fct_variations_wrapper").data("product_type")||"",p=e.data("is_compare_row")||!1,f=e.data("row_id")||!1,v=function(t){var a=e.find(t);return a.length?a:e.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(e.data("row_id"),'"] .fct_product_image')):p&&(m=v('[data-pid="'.concat(o,'"] .fct_product_image'))),u&&m&&m.attr("src",u);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"===l){(h=v(".nt_fct_buy_now_".concat(o))).attr("data-variation_id",c);var w=e.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(a){a.on("change",".nt_fct_quantity",function(){var n=r(this),i=n.data("product_type"),e=n.data("product_id"),o=Math.max(1,parseInt(n.val(),10)||1);n.val(o);var c=a.find(".nt_fct_add_to_cart_".concat(e));"digital"===i&&(c=a.find(".nt_fct_buy_now_".concat(e))),c.attr("data-quantity",o);var d=c.data("variation_id");if("digital"===i){var _=t.getNewUrl(c.attr("href"),d,o);c.attr("href",_)}})}},{key:"bindAddToCart",value:function(a,n){a.on("click",'[class*="nt_fct_add_to_cart_"]:not(.loading)',function(a){var i;a.preventDefault();var e=r(this),o=e.parent();if(!e.data("processing")){e.data("processing",!0),o.addClass("loading"),e.prop("disabled",!0);var c=null===(i=a.target)||void 0===i?void 0:i.dataset;if(c){var d={product_id:c.product_id,variation_id:parseInt(c.variation_id),quantity:c.quantity};t._ajaxAdd([d],e,o,n)}}})}},{key:"_ajaxAdd",value:function(t,a,n,i){var e=window.ninja_footables||{},o=e.ajax_url,c=e.ninja_table_public_nonce;r.post(o,{action:"ninja_table_wp_fct_add_to_cart",nonce:c,table_id:(null==i?void 0:i.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")})}}],(i=null)&&a(n.prototype,i),e&&a(n,e),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,i,e}();jQuery(document).ready(function(t){t(document).on("ninja_table_loaded",function(t,a,n){"wp_fct"===n.provider&&i.init(a,n)})})})();