(()=>{(function(){"use strict";function i(e,r){let o=e.selection.getContent({format:"text"});if(!o){e.windowManager.alert("Please select some text to process.");return}e.setProgressState(!0);let s=window.aipkit_post_enhancer?.nonce_process_text;if(!s){console.error("AIPKit Enhancer: Nonce not found for text processing."),e.setProgressState(!1),e.windowManager.alert("An error occurred: Security token missing.");return}let t=r.replace("%s",o),n={_ajax_nonce:s,text_to_process:o,final_prompt:t};if(typeof window.aipkit_apiRequest!="function"){console.error("AIPKit Enhancer: aipkit_apiRequest function not available."),e.setProgressState(!1),e.windowManager.alert("An error occurred: API function missing.");return}window.aipkit_apiRequest("aipkit_process_enhancer_text",n).then(a=>{if(a.text)e.selection.setContent(a.text);else throw new Error("AI did not return any text.")}).catch(a=>{console.error("AIPKit Enhancer: Error during AI processing action.",a),e.windowManager.alert(`An error occurred: ${a.message||"Request failed."}`)}).finally(()=>{e.setProgressState(!1)})}tinymce.PluginManager.add("aipkit_assistant",function(e,r){e.addButton("aipkit_assistant_button",{text:"\u270D\uFE0F AIP Content Assistant",icon:!1,type:"menubutton",classes:"aipkit-tinymce-assistant-button",menu:function(){let s=(window.aipkit_post_enhancer||{}).actions||[],t=[];return t.push({text:"\u270D\uFE0F AIP CONTENT ASSISTANT",classes:"aipkit-tinymce-menu-header",disabled:!0}),s.length>0&&t.push({text:"-"}),s.forEach(n=>{n.label&&n.prompt&&t.push({text:n.label,classes:"aipkit-tinymce-menu-item",onclick:function(){i(e,n.prompt)}})}),t}()})})})();})();
