System.register(["../../../common/index-legacy.sLMPZLm9.js","../../../common/credit-toast-legacy.BMoKCCCk.js","./style.scss-legacy.C4ni-eBG.js","../../../common/modal-legacy.DcruUX9x.js"],(function(e,o){"use strict";var t,n,r;return{setters:[e=>{t=e.s},e=>{n=e.c,r=e.s},null,null],execute:function(){((e,o,i)=>{const{__:s}=e.wp.i18n;function c(e){if(e.preventDefault(),!n())return;const o=i("#woocommerce-coupon-description");if(""!==o.val().trim()&&!confirm(s("This will overwrite the existing description. Are you sure you want to continue?","storeagent-ai-for-woocommerce")))return;const c=i("#post_ID").val();if(!c)return void alert(s("Please save the coupon first.","storeagent-ai-for-woocommerce"));const a=i(e.currentTarget),l=a.html();a.empty().append(i("<img />",{src:t().pluginDirUrl+"static/images/sparkles-loader-80.gif",alt:s("Generating...","storeagent-ai-for-woocommerce"),width:"16",height:"16"})).append(` ${s("Generating description...","storeagent-ai-for-woocommerce")}`).prop("disabled",!0),i.ajax({url:`${t().couponDescriptionRestUrl}${c}`,type:"POST",beforeSend:e=>{e.setRequestHeader("X-WP-Nonce",t().wpNonce)},success:e=>{const t=(null==e?void 0:e.description)||"";o.val(t),a.html(l).prop("disabled",!1),null!=e&&e.usage&&r(e.usage)},error:e=>{var o;const t=(null===(o=e.responseJSON)||void 0===o?void 0:o.message)||s("An error occurred while generating the coupon description.","storeagent-ai-for-woocommerce");alert(t),a.html(l).prop("disabled",!1)}})}i((()=>{!function(){const e=i("#woocommerce-coupon-description");if(!e.length)return;const o=i("<button />",{type:"button",class:"saai-button saai-generate-coupon-description-btn saai-button-main saai-button-left-icon",text:s("Generate description with AI","storeagent-ai-for-woocommerce")}).css({display:"inline-flex",height:"30px",float:"right"});o.prepend(i("<img />",{width:"16",height:"16",alt:s("AI icon","storeagent-ai-for-woocommerce"),src:t().pluginDirUrl+"static/images/ai-icon.svg"}));const n=i(".generate-coupon-code");n.length?n.after(o):e.before(o),o.on("click",c)}()}))})(window,document,jQuery)}}}));
