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