System.register(["../../../common/index-legacy.sLMPZLm9.js","./style.scss-legacy.D5kNhLS8.js"],(function(e,s){"use strict";var t;return{setters:[e=>{t=e.s},null],execute:function(){const e=window.saaiProductUpsellsParams;((s,n,a)=>{const{__:o}=s.wp.i18n,i=a("#linked_product_data"),r=a(".saai-generate-upsells-container"),l=r.find("#saai-generate-product-upsells"),c=l.next(".spinner");function d(e,s){const t=a(e);t.length&&s.length&&(t.empty(),s.forEach((e=>{const s=a("<option></option>").attr("value",e.id).text(e.name).prop("selected",!0);t.append(s)})),t.trigger("change"))}function p(s){l.prop("disabled",!1),c.removeClass("is-active"),l.find("span").html(e.error),s&&alert(s),setTimeout((function(){l.find("span").html(e.buttonText)}),3e3)}r.on("click","#saai-generate-product-upsells",(function(s){s.preventDefault();const n=l.data("product-id");n&&confirm(e.confirmSaveChanges)&&(l.prop("disabled",!0),c.addClass("is-active"),l.find("span").html(e.generating),a.ajax({url:t().productUpsellsRestUrl+"generate",type:"POST",beforeSend:e=>{e.setRequestHeader("X-WP-Nonce",t().wpNonce)},data:{product_id:n},success:function(e){var s;e.success?(d("#upsell_ids",e.upsell_ids||[]),d("#crosssell_ids",e.cross_sell_ids||[])):p(null===(s=e.data)||void 0===s?void 0:s.message)},error:function(e){var s;p(null===(s=e.responseJSON)||void 0===s?void 0:s.message)}}).always((()=>{l.find("span").html(e.buttonText),l.prop("disabled",!1),c.removeClass("is-active")})))})),i.length&&r.length&&i.find(".options_group:last").append(r)})(window,document,jQuery)}}}));
