(()=>{(function(){"use strict";let e=window.wp;if(!e||!e.richText||!e.components||!e.element||!e.i18n||!e.blockEditor||!e.data){console.error("AIPKit Block Editor Enhancer: One or more required WordPress script dependencies are missing.");return}let{registerFormatType:g,insert:u,getTextContent:p,slice:d}=e.richText,{ToolbarGroup:h,ToolbarDropdownMenu:_}=e.components,{BlockControls:f}=e.blockEditor,{__:n}=e.i18n,{createElement:o,Fragment:k}=e.element;async function A(s,a,m){let i=p(d(s));if(!i){e.data.dispatch("core/notices").createNotice("warning",n("Please select some text to process.","gpt3-ai-content-generator"),{isDismissible:!0});return}let r="aipkit-enhancer-processing";e.data.dispatch("core/notices").createNotice("info",n("Processing...","gpt3-ai-content-generator"),{id:r,isDismissible:!1});let c=window.aipkit_post_enhancer?.nonce_process_text;if(!c){e.data.dispatch("core/notices").removeNotice(r),e.data.dispatch("core/notices").createNotice("error",n("An error occurred: Security token missing.","gpt3-ai-content-generator"),{isDismissible:!0});return}let l=m.replace("%s",i);try{let t=await window.aipkit_apiRequest("aipkit_process_enhancer_text",{_ajax_nonce:c,text_to_process:i,final_prompt:l});if(t.text)a(u(s,t.text)),e.data.dispatch("core/notices").createNotice("success",n("Text enhanced successfully!","gpt3-ai-content-generator"),{isDismissible:!0});else throw new Error("AI did not return any text.")}catch(t){console.error("AIPKit Block Editor Enhancer Error:",t),e.data.dispatch("core/notices").createNotice("error",n("An error occurred:","gpt3-ai-content-generator")+" "+t.message,{isDismissible:!0})}finally{e.data.dispatch("core/notices").removeNotice(r)}}g("aipkit/assistant-format",{title:n("Content Assistant","gpt3-ai-content-generator"),tagName:"span",className:"aipkit-assistant-placeholder-format",edit:({value:s,onChange:a,isActive:m})=>{let c=((window.aipkit_post_enhancer||{}).actions||[]).filter(t=>t.label&&t.prompt).map(t=>({title:n(t.label,"gpt3-ai-content-generator"),onClick:()=>{A(s,a,t.prompt)}})),l=[{title:"AIP Content Assistant",isDisabled:!0,className:"aipkit-menu-header"},...c];return o(k,null,o(f,null,o(h,null,o(_,{icon:()=>o("span",{style:{fontSize:"16px",display:"inline-block",lineHeight:"1"}},"\u270D\uFE0F"),label:n("AIP Content Assistant","gpt3-ai-content-generator"),controls:l,isDisabled:!p(d(s)),className:"aipkit-content-assistant-menu"}))))}})})();})();
