import{a as h}from"../../../common/index.BA7kDUNA.js";import{s as y}from"../../../common/index.CPcBO1Os.js";import{c as b,s as x}from"../../../common/credit-toast.DauYY3RS.js";import"../../../common/modal.BiaPupKG.js";function w(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}((t,f,o)=>{const{__:a}=t.wp.i18n,m={buttonHtml:null,init:()=>{const n=o("#excerpt-html").closest(".wp-editor-tools").find(".wp-media-buttons");if(n.length){const r='<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="'.concat(y().pluginDirUrl,'static/images/ai-icon.svg" alt="').concat(a("AI icon","storeagent-ai-for-woocommerce"),'" style="width: 16px; height: 16px; padding: 0" />\n            <span class="saai-button-text">').concat(a("Generate with AI","storeagent-ai-for-woocommerce"),"</span>\n          </button>\n        </div>");n.append(r),o(".generate-summary-button").on("click",m.generateSummary)}},generateSummary:n=>{if(!b()||t.wp.editor.getContent("excerpt")!==""&&!confirm(a("This will overwrite the existing summary. Are you sure you want to continue?","storeagent-ai-for-woocommerce")))return;const r=t.wp.url.getQueryArg(t.location.href,"post"),i=o(n.target),c=i.html();i.html('<img src="'.concat(y().pluginDirUrl,'static/images/sparkles-loader-80.gif" alt="').concat(a("Sending request...","storeagent-ai-for-woocommerce"),'" style="width: 16px; height: 16px;" /> ').concat(a("Generating summary...","storeagent-ai-for-woocommerce"))),h().post("".concat(r,"/generate")).then(e=>{var g,p,d;const{summary:l}=e.data,s="excerpt",u=f.getElementById(s);((g=t==null?void 0:t.tinyMCE)==null?void 0:g.get(s))!=null&&((p=t.tinyMCE.get(s))==null||p.setContent(l)),u&&(u.value=l),(d=e.data)!=null&&d.usage&&x(e.data.usage),i.html(c)}).catch(({error:e})=>{console.log(e),alert(e.message),i.html(c)})}};o(()=>{m.init()})})(window,document,jQuery);export{w as __vite_legacy_guard};
