import{s as u}from"../../../common/index.CPcBO1Os.js";/* empty css                   */function P(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}const r=window.saaiProductUpsellsParams;((f,h,a)=>{const{__:v}=f.wp.i18n,c=a("#linked_product_data"),o=a(".saai-generate-upsells-container"),t=o.find("#saai-generate-product-upsells"),l=t.next(".spinner");o.on("click","#saai-generate-product-upsells",g),m();function m(){!c.length||!o.length||c.find(".options_group:last").append(o)}function g(s){s.preventDefault();const i=t.data("product-id");i&&confirm(r.confirmSaveChanges)&&(t.prop("disabled",!0),l.addClass("is-active"),t.find("span").html(r.generating),a.ajax({url:u().productUpsellsRestUrl+"generate",type:"POST",beforeSend:e=>{e.setRequestHeader("X-WP-Nonce",u().wpNonce)},data:{product_id:i},success:function(e){var n;e.success?(d("#upsell_ids",e.upsell_ids||[]),d("#crosssell_ids",e.cross_sell_ids||[])):p((n=e.data)==null?void 0:n.message)},error:function(e){var n;p((n=e.responseJSON)==null?void 0:n.message)}}).always(()=>{t.find("span").html(r.buttonText),t.prop("disabled",!1),l.removeClass("is-active")}))}function d(s,i){const e=a(s);!e.length||!i.length||(e.empty(),i.forEach(n=>{const _=a("<option></option>").attr("value",n.id).text(n.name).prop("selected",!0);e.append(_)}),e.trigger("change"))}function p(s){t.prop("disabled",!1),l.removeClass("is-active"),t.find("span").html(r.error),s&&alert(s),setTimeout(function(){t.find("span").html(r.buttonText)},3e3)}})(window,document,jQuery);export{P as __vite_legacy_guard};
