"use strict";(globalThis.webpackChunkmailerpress=globalThis.webpackChunkmailerpress||[]).push([[973],{38973:(e,t,r)=>{r.r(t),r.d(t,{createMJMLLinter:()=>C,default:()=>w});var s=r(51609),a=r(30287),n=r(86087),i=r(62112),o=r(49411),l=r(47143),c=r(99479),d=r(36645),u=r(79688),m=r(73285),p=r.n(m),h=r(87878),f=r(66087),g=r(37587),v=r(56427),y=r(27723),_=r(52144),x=r(23081),E=r(14936),b=r(1455),k=r.n(b),S=r(21478);const C=(e=[])=>(0,h.bu)(t=>{const r=[],s=t.state.doc.lines;for(const a of e){const{line:e,message:n}=a;if(e<1||e>s)continue;const i=t.state.doc.line(e);r.push({from:i.from,to:i.to,severity:"error",message:n})}return r}),w=()=>{const e=(0,n.useRef)(null),{hasCapability:t}=(0,S.E)(),[r,m]=(0,n.useState)(window.jsVars.user_preferences?.codeEditorTheme||"light"),[b,w]=(0,n.useState)(""),[M,A]=(0,n.useState)(""),[L,T]=(0,n.useState)([]),{replaceContent:B,toggleCodeEditor:D}=(0,l.useDispatch)(o.Ui),{data:z}=(0,l.useSelect)(e=>({data:e(o.Ui).getBlocks()}),[]),I=(0,n.useMemo)(()=>"dark"===r?x.bM:[],[r]),U=(0,n.useMemo)(()=>{if(!M.trim())return!1;try{return p()(M,{validationLevel:"soft"}),/^<mjml[\s>]/i.test(M.trim())}catch{return!1}},[M,L]),P=(0,n.useMemo)(()=>[(0,i.qy)(),(0,h.pJ)(),C(L),E.W2({scroll:()=>{}})],[L]);(0,n.useEffect)(()=>{let e=!0;return(async()=>{const t=(0,c.o)(z,"live");if(!t.trim()){if(!e)return;return w(""),A(""),void T([])}let r=t;try{r=await d.Ay.format(t,{parser:"html",plugins:[u.Ay],htmlWhitespaceSensitivity:"ignore"})}catch(e){}if(e){w(r),A(r);try{const t=p()(r,{validationLevel:"strict"});if(!e)return;T(t.errors||[])}catch(t){if(!e)return;T(t?.errors||[])}}})(),()=>{e=!1}},[z]);const W=(0,n.useCallback)((0,f.debounce)(e=>{A(e);try{const t=p()(e,{validationLevel:"strict"});T(t.errors||[])}catch(e){T(e?.errors||[])}},350),[]);return t(S.W.PUBLISH_CAMPAIGNS)?(0,s.createElement)("div",{style:{display:"flex",height:"calc(100vh - 90px)"}},(0,s.createElement)("div",{style:{flex:1,overflow:"auto",borderRight:"1px solid #e0e0e0"}},(0,s.createElement)("div",{style:{position:"sticky",top:0,padding:"8px 16px",borderBottom:"1px solid #e0e0e0",zIndex:1040,background:"rgb(255 255 255 / 75%)",backdropFilter:"blur(6px)"}},(0,s.createElement)(v.__experimentalHStack,null,0===L.length&&(0,s.createElement)(v.__experimentalText,{variant:"muted"},(0,y.__)("No error found","mailerpress")),L.length>0&&(0,s.createElement)(v.__experimentalText,{weight:"bold",isDestructive:!0},(0,y.sprintf)((0,y._n)("%d error found","%d errors found",L.length,"mailerpress"),L.length)),(0,s.createElement)("div",{style:{display:"flex",alignItems:"center",gap:8}},(0,s.createElement)(v.Button,{__next40pxDefaultSize:!0,variant:"secondary",onClick:async()=>{const e="light"===r?"dark":"light";m(e),await k()({path:"/mailerpress/v1/save-user-preferences",method:"POST",data:{codeEditorTheme:e}})}},"light"===r?(0,y.__)("Switch to Dark Mode","mailerpress"):(0,y.__)("Switch to Light Mode","mailerpress")),(0,s.createElement)(v.Button,{__next40pxDefaultSize:!0,variant:"primary",onClick:()=>{try{const e=(0,g.e)(M);B(e),D()}catch(e){console.error("[CodeEditor] Apply failed:",e),T(e?.errors?.length?e.errors:[{line:1,message:e?.message||"Unknown error"}])}},disabled:!U},(0,y.__)("Apply","mailerpress")),(0,s.createElement)(v.Button,{__next40pxDefaultSize:!0,icon:_.A,onClick:D})))),(0,s.createElement)(a.default,{theme:I,value:M,extensions:P,onChange:e=>W(e),onCreateEditor:t=>{e.current=t}}))):null}}}]);