import{s as a}from"../../../common/index.CPcBO1Os.js";import{c as f,s as h}from"../../../common/credit-toast.DauYY3RS.js";/* empty css                   */import"../../../common/modal.BiaPupKG.js";function b(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}((m,w,t)=>{const{__:o}=m.wp.i18n;t(()=>{g()});function g(){const i=t("#woocommerce-coupon-description");if(!i.length)return;const r=t("<button />",{type:"button",class:"saai-button saai-generate-coupon-description-btn saai-button-main saai-button-left-icon",text:o("Generate description with AI","storeagent-ai-for-woocommerce")}).css({display:"inline-flex",height:"30px",float:"right"});r.prepend(t("<img />",{width:"16",height:"16",alt:o("AI icon","storeagent-ai-for-woocommerce"),src:a().pluginDirUrl+"static/images/ai-icon.svg"}));const c=t(".generate-coupon-code");c.length?c.after(r):i.before(r),r.on("click",d)}function d(i){if(i.preventDefault(),!f())return;const r=t("#woocommerce-coupon-description");if(r.val().trim()!==""&&!confirm(o("This will overwrite the existing description. Are you sure you want to continue?","storeagent-ai-for-woocommerce")))return;const l=t("#post_ID").val();if(!l){alert(o("Please save the coupon first.","storeagent-ai-for-woocommerce"));return}const n=t(i.currentTarget),u=n.html();n.empty().append(t("<img />",{src:a().pluginDirUrl+"static/images/sparkles-loader-80.gif",alt:o("Generating...","storeagent-ai-for-woocommerce"),width:"16",height:"16"})).append(" ".concat(o("Generating description...","storeagent-ai-for-woocommerce"))).prop("disabled",!0),t.ajax({url:"".concat(a().couponDescriptionRestUrl).concat(l),type:"POST",beforeSend:e=>{e.setRequestHeader("X-WP-Nonce",a().wpNonce)},success:e=>{const s=(e==null?void 0:e.description)||"";r.val(s),n.html(u).prop("disabled",!1),e!=null&&e.usage&&h(e.usage)},error:e=>{var p;const s=((p=e.responseJSON)==null?void 0:p.message)||o("An error occurred while generating the coupon description.","storeagent-ai-for-woocommerce");alert(s),n.html(u).prop("disabled",!1)}})}})(window,document,jQuery);export{b as __vite_legacy_guard};
