System.register(["../../../common/index-legacy.sLMPZLm9.js","../../../common/credit-toast-legacy.BMoKCCCk.js","./style.scss-legacy.Dz9P5F8a.js","../../../common/modal-legacy.DcruUX9x.js"],(function(e,t){"use strict";var a,n,s;return{setters:[e=>{a=e.s},e=>{n=e.c,s=e.s},null,null],execute:function(){((t,r,i)=>{const{__:o}=t.wp.i18n,c=i("#tagsdiv-product_tag .inside"),d=i(".saai-generate-tags-container"),l=d.find("#saai-generate-product-tags"),u=l.next(".spinner");function g(t){l.prop("disabled",!1),u.removeClass("is-active"),l.html(e.error),t&&alert(t),setTimeout((function(){l.html(e.buttonText)}),3e3)}d.on("click","#saai-generate-product-tags",(function(t){if(t.preventDefault(),!n())return;const r=l.data("product-id");r&&confirm(e.confirmSaveChanges)&&(l.prop("disabled",!0),u.addClass("is-active"),l.find("span").html(e.generating),i.ajax({url:a().productTagsGeneratorRestUrl+"generate",type:"POST",beforeSend:e=>{e.setRequestHeader("X-WP-Nonce",a().wpNonce)},data:{product_id:r},success:function(e){var t;l.prop("disabled",!1),u.removeClass("is-active"),e.success&&e.tags?(function(e){if(!e||!e.length)return;const t=i("#new-tag-product_tag"),a=t.next(".tagadd");t.val(e.join(", ")),a.trigger("click"),t.trigger("blur"),c.find("input.newtag").val("")}(e.tags),e.usage&&s(e.usage)):g(null===(t=e.data)||void 0===t?void 0:t.message)},error:function(e){var t;g(null===(t=e.responseJSON)||void 0===t?void 0:t.message)}}).always((()=>{l.find("span").html(e.buttonText),l.prop("disabled",!1),u.removeClass("is-active")})))})),c.length&&d.length&&c.append(d)})(window,document,jQuery);const e=window.saaiProductTagsParams}}}));
