System.register(["../../../common/index-legacy.sLMPZLm9.js","../../../common/credit-toast-legacy.BMoKCCCk.js","./index.scss-legacy.BipAp9jZ.js","../../../common/modal-legacy.DcruUX9x.js"],(function(e,a){"use strict";var t,n,s;return{setters:[e=>{t=e.s},e=>{n=e.c,s=e.s},null,null],execute:function(){((e,a,i)=>{const{__:o}=e.wp.i18n;function r(){i(".saai-review-summary-metabox__key-takeaways__item").each((function(e){const a=i(this).find("input"),t=i(this).find("select");a.attr("name",`saai_review[key_takeaways][${e}][content]`),t.attr("name",`saai_review[key_takeaways][${e}][sentiment]`)}))}function m(e,a){const t="string"==typeof e?{content:"",sentiment:"positive"}:e;return`<li class="saai-review-summary-metabox__key-takeaways__item">\n      <select name="saai_review[key_takeaways][${a}][sentiment]">\n        <option value="positive" ${"positive"===t.sentiment?"selected":""}>${o("Positive","storeagent-ai-for-woocommerce")}</option>\n        <option value="neutral" ${"neutral"===t.sentiment?"selected":""}>${o("Neutral","storeagent-ai-for-woocommerce")}</option>\n        <option value="negative" ${"negative"===t.sentiment?"selected":""}>${o("Negative","storeagent-ai-for-woocommerce")}</option>\n      </select>\n      <input type="text" name="saai_review[key_takeaways][${a}][content]" value="${t.content}">\n      <i class="dashicons-before dashicons-minus"></i>\n    </li>`}i(a).on("click","#saai-review-summary-add-key-takeaway-button",(function(){const e=i(".saai-review-summary-metabox__key-takeaways ul"),a=e.children().length;e.append(m("",a-1)),r()})),i(a).on("click",".saai-review-summary-metabox__key-takeaways__item .dashicons-minus",(function(){i(this).parent().remove(),r()})),i(a).on("click","#saai-review-summary-generate-button",(async function(){if(!n())return;const e=i(this),a=e.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"))){e.prop("disabled",!0),a.addClass("is-active");try{var r,c;const e=await i.post(ajaxurl,{action:"saai_regenerate_review_summary",nonce:t().nonce,product_id:parseInt(i("#post_ID").val())});i(".saai-review-summary-metabox__summary__textarea").val(e.data.summary),i(".saai-review-summary-metabox__key-takeaways ul").html(""),(null===(r=e.data)||void 0===r||null===(r=r.key_takeaways)||void 0===r?void 0:r.length)>0?e.data.key_takeaways.forEach(((e,a)=>{i(".saai-review-summary-metabox__key-takeaways ul").append(m(e,a))})):i(".saai-review-summary-metabox__key-takeaways ul").append(m("",0)),null!==(c=e.data)&&void 0!==c&&c.usage&&s(e.data.usage)}catch(u){console.error(u),alert(u.message)}finally{e.prop("disabled",!1),a.removeClass("is-active")}}}))})(window,document,jQuery)}}}));
