(()=>{"use strict";var e={n:t=>{var a=t&&t.__esModule?()=>t.default:()=>t;return e.d(a,{a}),a},d:(t,a)=>{for(var n in a)e.o(a,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:a[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.React,a=window.wp.richText,n=window.wp.blockEditor,l=window.wp.components,i=window.wp.element,o=window.wp.i18n,r=window.wp.apiFetch;var m=e.n(r);const s=[{id:"improve",label:(0,o.__)("Improve writing","antimanual")},{id:"fix_grammar",label:(0,o.__)("Fix grammar & spelling","antimanual")},{id:"shorten",label:(0,o.__)("Make shorter","antimanual")},{id:"lengthen",label:(0,o.__)("Make longer","antimanual")},{id:"simplify",label:(0,o.__)("Simplify","antimanual")},{id:"professional",label:(0,o.__)("Professional tone","antimanual")},{id:"translate",label:(0,o.__)("Translate…","antimanual")},{id:"custom",label:(0,o.__)("Custom instruction…","antimanual")}],c="undefined"!=typeof window?window.antimanualCopilot:void 0,u=(0,t.createElement)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true"},(0,t.createElement)("path",{d:"M9 4.5a.75.75 0 0 1 .72.54l.69 2.42a3 3 0 0 0 2.08 2.08l2.42.69a.75.75 0 0 1 0 1.44l-2.42.69a3 3 0 0 0-2.08 2.08l-.69 2.42a.75.75 0 0 1-1.44 0l-.69-2.42a3 3 0 0 0-2.08-2.08l-2.42-.69a.75.75 0 0 1 0-1.44l2.42-.69A3 3 0 0 0 7.59 7.46l.69-2.42A.75.75 0 0 1 9 4.5Zm9-3a.75.75 0 0 1 .72.55l.22.86c.16.62.64 1.1 1.26 1.26l.86.22a.75.75 0 0 1 0 1.46l-.86.22c-.62.16-1.1.64-1.26 1.26l-.22.86a.75.75 0 0 1-1.46 0l-.22-.86a1.75 1.75 0 0 0-1.26-1.26l-.86-.22a.75.75 0 0 1 0-1.46l.86-.22c.62-.16 1.1-.64 1.26-1.26l.22-.86A.75.75 0 0 1 18 1.5Z"}));(0,a.registerFormatType)("antimanual/copilot",{name:"antimanual/copilot",title:(0,o.__)("Antimanual AI Copilot","antimanual"),tagName:"span",className:"atml-copilot-marker",interactive:!1,object:!1,edit:function({value:e,onChange:r}){const[d,p]=(0,i.useState)(!1),[_,g]=(0,i.useState)(!1),[h,v]=(0,i.useState)(""),[w,y]=(0,i.useState)(null),[f,b]=(0,i.useState)("Spanish"),[E,x]=(0,i.useState)(""),C="number"==typeof e?.start?e.start:void 0,k="number"==typeof e?.end?e.end:void 0,A=void 0!==C&&void 0!==k&&k>C,T=()=>{p(!1),y(null),v(""),x(""),g(!1)},S=async t=>{if(!A)return void v((0,o.__)("Select some text first, then choose an action.","antimanual"));const n=(0,a.toHTMLString)({value:(0,a.slice)(e,C,k)});g(!0),v("");try{const l=await m()({path:"/antimanual/v1/copilot",method:"POST",data:{action:t,text:n,language:"translate"===t?f:void 0,prompt:"custom"===t?E:void 0}}),i=l?.data?.text;if(!i)throw new Error(l?.message||(0,o.__)("Empty result.","antimanual"));const s=(0,a.create)({html:i});r((0,a.insert)(e,s,C,k)),T()}catch(e){v(e?.message||(0,o.__)("The AI request failed. Please try again.","antimanual")),g(!1)}};return(0,t.createElement)(t.Fragment,null,(0,t.createElement)(n.RichTextToolbarButton,{icon:u,title:(0,o.__)("Antimanual AI Copilot","antimanual"),onClick:()=>p(!0)}),d&&(0,t.createElement)(l.Modal,{title:(0,o.__)("Antimanual AI Copilot","antimanual"),onRequestClose:T,className:"atml-copilot-modal"},c&&!c.hasKey&&(0,t.createElement)(l.Notice,{status:"warning",isDismissible:!1},(0,o.__)("No AI provider is connected. Add an API key in Antimanual → Configuration.","antimanual")),!A&&(0,t.createElement)(l.Notice,{status:"info",isDismissible:!1},(0,o.__)("Select some text in the editor, then choose an action below.","antimanual")),h&&(0,t.createElement)(l.Notice,{status:"error",onRemove:()=>v("")},h),_?(0,t.createElement)("p",{style:{display:"flex",alignItems:"center",gap:8}},(0,t.createElement)(l.Spinner,null),(0,o.__)("Working on it…","antimanual")):"translate"===w?(0,t.createElement)("div",null,(0,t.createElement)(l.TextControl,{label:(0,o.__)("Target language","antimanual"),value:f,onChange:b,__nextHasNoMarginBottom:!0}),(0,t.createElement)("div",{style:{display:"flex",gap:8,marginTop:8}},(0,t.createElement)(l.Button,{variant:"primary",onClick:()=>S("translate"),disabled:!f.trim()},(0,o.__)("Translate","antimanual")),(0,t.createElement)(l.Button,{variant:"tertiary",onClick:()=>y(null)},(0,o.__)("Back","antimanual")))):"custom"===w?(0,t.createElement)("div",null,(0,t.createElement)(l.TextareaControl,{label:(0,o.__)("Instruction","antimanual"),help:(0,o.__)("Describe how the selected text should change.","antimanual"),value:E,onChange:x,__nextHasNoMarginBottom:!0}),(0,t.createElement)("div",{style:{display:"flex",gap:8,marginTop:8}},(0,t.createElement)(l.Button,{variant:"primary",onClick:()=>S("custom"),disabled:!E.trim()},(0,o.__)("Apply","antimanual")),(0,t.createElement)(l.Button,{variant:"tertiary",onClick:()=>y(null)},(0,o.__)("Back","antimanual")))):(0,t.createElement)("div",{style:{display:"flex",flexDirection:"column",gap:4}},s.map(e=>(0,t.createElement)(l.Button,{key:e.id,variant:"tertiary",disabled:!A,style:{justifyContent:"flex-start",height:36},onClick:()=>{"translate"===e.id?y("translate"):"custom"===e.id?y("custom"):S(e.id)}},e.label)))))}})})();