import{s as g}from"../../../common/index.CPcBO1Os.js";import{c as v,s as h}from"../../../common/credit-toast.DauYY3RS.js";/* empty css                   */import"../../../common/modal.BiaPupKG.js";function w(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}((l,T,s)=>{const{__:b}=l.wp.i18n,d=s("#tagsdiv-product_tag .inside"),o=s(".saai-generate-tags-container"),a=o.find("#saai-generate-product-tags"),c=a.next(".spinner");o.on("click","#saai-generate-product-tags",f),p();function p(){!d.length||!o.length||d.append(o)}function f(e){if(e.preventDefault(),!v())return;const n=a.data("product-id");n&&confirm(r.confirmSaveChanges)&&(a.prop("disabled",!0),c.addClass("is-active"),a.find("span").html(r.generating),s.ajax({url:g().productTagsGeneratorRestUrl+"generate",type:"POST",beforeSend:t=>{t.setRequestHeader("X-WP-Nonce",g().wpNonce)},data:{product_id:n},success:function(t){var i;a.prop("disabled",!1),c.removeClass("is-active"),t.success&&t.tags?(m(t.tags),t.usage&&h(t.usage)):u((i=t.data)==null?void 0:i.message)},error:function(t){var i;u((i=t.responseJSON)==null?void 0:i.message)}}).always(()=>{a.find("span").html(r.buttonText),a.prop("disabled",!1),c.removeClass("is-active")}))}function u(e){a.prop("disabled",!1),c.removeClass("is-active"),a.html(r.error),e&&alert(e),setTimeout(function(){a.html(r.buttonText)},3e3)}function m(e){if(!e||!e.length)return;const n=s("#new-tag-product_tag"),t=n.next(".tagadd");n.val(e.join(", ")),t.trigger("click"),n.trigger("blur"),d.find("input.newtag").val("")}})(window,document,jQuery);const r=window.saaiProductTagsParams;export{w as __vite_legacy_guard};
