import{s as v}from"../../../common/index.CPcBO1Os.js";import{c as d,s as f}from"../../../common/credit-toast.DauYY3RS.js";/* empty css                   */import"../../../common/modal.BiaPupKG.js";function g(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}((u,r,e)=>{const{__:o}=u.wp.i18n;e(r).on("click","#saai-review-summary-add-key-takeaway-button",l),e(r).on("click",".saai-review-summary-metabox__key-takeaways__item .dashicons-minus",w),e(r).on("click","#saai-review-summary-generate-button",_);function l(){const a=e(".saai-review-summary-metabox__key-takeaways ul"),t=a.children().length;a.append(m("",t-1)),c()}function w(){e(this).parent().remove(),c()}function c(){e(".saai-review-summary-metabox__key-takeaways__item").each(function(a){const t=e(this).find("input"),n=e(this).find("select");t.attr("name","saai_review[key_takeaways][".concat(a,"][content]")),n.attr("name","saai_review[key_takeaways][".concat(a,"][sentiment]"))})}async function _(){var n,i,y;if(!d())return;const a=e(this),t=a.siblings(".spinner");if(confirm(o("WARNING: This will delete the existing review summary and any changes you've made. Are you sure you want to continue?","storeagent-ai-for-woocommerce"))){a.prop("disabled",!0),t.addClass("is-active");try{const s=await e.post(ajaxurl,{action:"saai_regenerate_review_summary",nonce:v().nonce,product_id:parseInt(e("#post_ID").val())});e(".saai-review-summary-metabox__summary__textarea").val(s.data.summary),e(".saai-review-summary-metabox__key-takeaways ul").html(""),((i=(n=s.data)==null?void 0:n.key_takeaways)==null?void 0:i.length)>0?s.data.key_takeaways.forEach((p,k)=>{e(".saai-review-summary-metabox__key-takeaways ul").append(m(p,k))}):e(".saai-review-summary-metabox__key-takeaways ul").append(m("",0)),(y=s.data)!=null&&y.usage&&f(s.data.usage)}catch(s){console.error(s),alert(s.message)}finally{a.prop("disabled",!1),t.removeClass("is-active")}}}function m(a,t){const i=typeof a=="string"?{content:"",sentiment:"positive"}:a;return'<li class="saai-review-summary-metabox__key-takeaways__item">\n      <select name="saai_review[key_takeaways]['.concat(t,'][sentiment]">\n        <option value="positive" ').concat(i.sentiment==="positive"?"selected":"",">").concat(o("Positive","storeagent-ai-for-woocommerce"),'</option>\n        <option value="neutral" ').concat(i.sentiment==="neutral"?"selected":"",">").concat(o("Neutral","storeagent-ai-for-woocommerce"),'</option>\n        <option value="negative" ').concat(i.sentiment==="negative"?"selected":"",">").concat(o("Negative","storeagent-ai-for-woocommerce"),'</option>\n      </select>\n      <input type="text" name="saai_review[key_takeaways][').concat(t,'][content]" value="').concat(i.content,'">\n      <i class="dashicons-before dashicons-minus"></i>\n    </li>')}})(window,document,jQuery);export{g as __vite_legacy_guard};
