import{c as f,s as q}from"../../../common/modal.BiaPupKG.js";/* empty css                              */function k(){import.meta.url,import("_").catch(()=>1),async function*(){}().next()}((g,c,a)=>{const{__:u}=g.wp.i18n,n={init:()=>{a(c).on("click",".saai-ask-question-btn",n.initPopup),a(c).on("click",".saai-ask-question-widget",n.initPopup),a(c).on("click",".saai-qa-ask-btn",n.askQuestion),a(c).on("click",".saai-qa-reset-btn",n.askAnother),a(c).on("click",".saai-qa-close-btn",n.closePopup),a(c).on("keyup","textarea.saai-user-question",n.countTextCharacters),n.maybeForceShowQuestionsTab(),n.injectWidget()},injectWidget:()=>{if(!window.saaiPqObj||!window.saaiPqObj.widgetEnabled||window.saaiPqObj.widgetEnabled!=="yes")return;const i=window.saaiPqObj.widgetPosition||"bottom-right";let e="";i==="bottom-right"?e='\n          <div class="saai-ask-question-widget saai-ask-question-btn bottom-right">\n            <svg fill="#000000" width="34px" height="34px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M8 .5A7.77 7.77 0 0 0 0 8a7.77 7.77 0 0 0 8 7.5A7.77 7.77 0 0 0 16 8 7.77 7.77 0 0 0 8 .5zm0 13.75A6.52 6.52 0 0 1 1.25 8 6.52 6.52 0 0 1 8 1.75 6.52 6.52 0 0 1 14.75 8 6.52 6.52 0 0 1 8 14.25z"/><circle cx="7.98" cy="10.95" r=".76"/><path d="M9.73 4.75A2.72 2.72 0 0 0 8 4.19a2.28 2.28 0 0 0-2.41 2.17v.11h1.24v-.1A1.12 1.12 0 0 1 8 5.33a1 1 0 0 1 1.12 1c0 .35-.24.73-.78 1.11a2 2 0 0 0-1 1.46v.36h1.24V9a.76.76 0 0 1 .23-.51A3.92 3.92 0 0 1 9.33 8l.17-.14a2 2 0 0 0 .91-1.67 1.85 1.85 0 0 0-.68-1.44z"/></svg>\n            <span class="saai-widget-tooltip">'.concat(u("Ask a Question","storeagent-ai-for-woocommerce"),"</span>\n          </div>\n        "):e='\n          <div class="saai-ask-question-widget saai-ask-question-btn mid-right">\n            <span>'.concat(u("Ask a Question","storeagent-ai-for-woocommerce"),"</span>\n          </div>\n        "),a("body").append(e)},initPopup:()=>{q({id:"saai-qa-modal",content:a("#tmpl-saai-qa").html()||"",width:960,height:300,flexCenter:!0})},resizeTextArea:i=>{i.addClass("sent");const e=i.val().split("\n"),t=g.getComputedStyle(i[0]),d=parseInt(t.lineHeight||"0"),l=parseInt((t==null?void 0:t.paddingTop)||"0"),s=parseInt((t==null?void 0:t.paddingBottom)||"0"),w=parseInt((t==null?void 0:t.paddingLeft)||"0"),p=parseInt((t==null?void 0:t.paddingRight)||"0");let r=0;e.forEach(m=>{const h=m.length*d,b=i[0].clientWidth-w-p;r+=Math.ceil(h/b)});const o=r*d+l+s;i.animate({height:"".concat(o,"px")},500)},askAnother:i=>{const e=a(i.target).closest(".qa-form"),t=e.find(".user-question");t.animate({height:"150px"},500),t.prop("readonly",!1),t.removeClass("sent"),e.find(".submit-btn-container").show(),e.find(".submit-btn-container button").prop("disabled",!0),e.find(".reset-btn-container").hide(),e.find(".close-btn-container").hide(),e.find(".ai-answer").html("")},closePopup:i=>{a(i.target).closest(".qa-form").find(".saai-qa-reset-btn").trigger("click"),f("saai-qa-modal")},askQuestion:i=>{i.preventDefault();const e=a(i.target).closest(".qa-form"),t=e.find(".user-question"),d=e.find(".submit-btn-container"),l=e.find(".reset-btn-container"),s=e.find(".close-btn-container"),w=t.val(),p=e.find(".loading");p.addClass("show"),n.resizeTextArea(t),t.prop("readonly",!0),d.hide(),a.ajax({url:window.saaiPqObj.restUrl,type:"POST",beforeSend:r=>{r.setRequestHeader("X-WP-Nonce",window.saaiPqObj.wpNonce)},data:{question:w},success:({answer:r})=>{const o=r?'<div class="answer-text">'.concat(r,"</div>"):'<p class="error">'.concat(u("An error occurred","storeagent-ai-for-woocommerce"),"</p>");e.find(".ai-answer").html('<p class="answer-label">'.concat(u("Answer:","storeagent-ai-for-woocommerce"),"</p>").concat(o)),p.removeClass("show"),l.show(),s.show()},error:r=>{const o=JSON.parse(r.responseText);console.log((o==null?void 0:o.message)||"An error occurred"),(o==null?void 0:o.message)!=null&&e.find(".ai-answer").html('<p class="error">'.concat(o==null?void 0:o.message,"</p>")),p.removeClass("show"),l.show(),s.show()}})},maybeForceShowQuestionsTab:()=>{window.location.href.includes("questions-page")&&a(".woocommerce-tabs #tab-title-product_questions a").trigger("click")},countTextCharacters:i=>{const e=a(i.target),t=a(".user-question-field-wrap .character-count .current-count"),d=e.closest(".qa-form").find(".saai-qa-ask-btn"),l=e.val(),s=l.length;t.text(s!=null?s:0),d.prop("disabled",!s)}};a(()=>{n.init()})})(window,document,window.jQuery);export{k as __vite_legacy_guard};
