System.register(["../../../common/index-legacy.NSn_Zdym.js","../../../common/index-legacy.sLMPZLm9.js","../../../common/credit-toast-legacy.BMoKCCCk.js","../../../common/modal-legacy.DcruUX9x.js"],(function(t,e){"use strict";var n,o,a,i;return{setters:[t=>{n=t.a},t=>{o=t.s},t=>{a=t.c,i=t.s},null],execute:function(){((t,e,r)=>{const{__:s}=t.wp.i18n,l={buttonHtml:null,init:()=>{const t=r("#excerpt-html").closest(".wp-editor-tools").find(".wp-media-buttons");if(t.length){const e=`<div class="saai-generate-summary-button-container" style="display: inline-block; margin-left: 5px;">\n          <button type="button" class="saai-button generate-summary-button saai-generate-summary-btn saai-button-main saai-button-left-icon" style="padding: 5px 15px 5px 5px;">\n            <img src="${o().pluginDirUrl}static/images/ai-icon.svg" alt="${s("AI icon","storeagent-ai-for-woocommerce")}" style="width: 16px; height: 16px; padding: 0" />\n            <span class="saai-button-text">${s("Generate with AI","storeagent-ai-for-woocommerce")}</span>\n          </button>\n        </div>`;t.append(e),r(".generate-summary-button").on("click",l.generateSummary)}},generateSummary:l=>{if(!a())return;if(""!==t.wp.editor.getContent("excerpt")&&!confirm(s("This will overwrite the existing summary. Are you sure you want to continue?","storeagent-ai-for-woocommerce")))return;const m=t.wp.url.getQueryArg(t.location.href,"post"),c=r(l.target),u=c.html();c.html(`<img src="${o().pluginDirUrl}static/images/sparkles-loader-80.gif" alt="${s("Sending request...","storeagent-ai-for-woocommerce")}" style="width: 16px; height: 16px;" /> ${s("Generating summary...","storeagent-ai-for-woocommerce")}`),n().post(`${m}/generate`).then((n=>{var o,a;const{summary:r}=n.data,s="excerpt",l=e.getElementById(s);var m;null!=(null==t||null===(o=t.tinyMCE)||void 0===o?void 0:o.get(s))&&(null===(m=t.tinyMCE.get(s))||void 0===m||m.setContent(r)),l&&(l.value=r),null!==(a=n.data)&&void 0!==a&&a.usage&&i(n.data.usage),c.html(u)})).catch((({error:t})=>{console.log(t),alert(t.message),c.html(u)}))}};r((()=>{l.init()}))})(window,document,jQuery)}}}));
