"use strict";(globalThis.webpackChunkmailerpress=globalThis.webpackChunkmailerpress||[]).push([[973],{38973:(e,t,r)=>{r.r(t),r.d(t,{createMJMLLinter:()=>w,default:()=>C});var a=r(51609),n=r(30287),i=r(86087),s=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),b=r(14936),E=r(1455),S=r.n(E),k=r(21478);const w=(e=[])=>(0,h.bu)(t=>{const r=[],a=t.state.doc.lines;for(const n of e){const{line:e,message:i}=n;if(e<1||e>a)continue;const s=t.state.doc.line(e);r.push({from:s.from,to:s.to,severity:"error",message:i})}return r}),C=()=>{const e=(0,i.useRef)(null),{hasCapability:t}=(0,k.E)(),[r,m]=(0,i.useState)(window.jsVars.user_preferences?.codeEditorTheme||"light"),[E,C]=(0,i.useState)(""),[L,M]=(0,i.useState)(""),[T,A]=(0,i.useState)([]),{replaceContent:B,toggleCodeEditor:D}=(0,l.useDispatch)(o.Ui),{data:U}=(0,l.useSelect)(e=>({data:e(o.Ui).getBlocks()}),[]),I=(0,i.useMemo)(()=>"dark"===r?x.bM:[],[r]),P=(0,i.useMemo)(()=>{if(!L.trim())return!1;try{return 0===p()(L,{validationLevel:"strict"}).errors.length&&/^<mjml[\s>]/.test(L.trim())}catch{return!1}},[L,T]),z=(0,i.useMemo)(()=>[(0,s.qy)(),(0,h.pJ)(),w(T),b.W2({scroll:()=>{}})],[T]);(0,i.useEffect)(()=>{let e=!0;return(async()=>{const t=(0,c.o)(U,"live");if(!t.trim()){if(!e)return;return C(""),M(""),void A([])}let r=t;try{r=await d.Ay.format(t,{parser:"html",plugins:[u.Ay],htmlWhitespaceSensitivity:"ignore"})}catch(e){}if(e){C(r),M(r);try{const t=p()(r,{validationLevel:"strict"});if(!e)return;A(t.errors||[])}catch(t){if(!e)return;A(t?.errors||[])}}})(),()=>{e=!1}},[U]);const R=(0,i.useCallback)((0,f.debounce)(e=>{M(e);try{const t=p()(e,{validationLevel:"strict"});A(t.errors||[])}catch(e){A(e?.errors||[])}},350),[]);return t(k.W.PUBLISH_CAMPAIGNS)?(0,a.createElement)("div",{style:{display:"flex",height:"calc(100vh - 90px)"}},(0,a.createElement)("div",{style:{flex:1,overflow:"auto",borderRight:"1px solid #e0e0e0"}},(0,a.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,a.createElement)(v.__experimentalHStack,null,0===T.length&&(0,a.createElement)(v.__experimentalText,{variant:"muted"},(0,y.__)("No error found","mailerpress")),T.length>0&&(0,a.createElement)(v.__experimentalText,{weight:"bold",isDestructive:!0},(0,y.sprintf)((0,y._n)("%d error found","%d errors found",T.length,"mailerpress"),T.length)),(0,a.createElement)("div",{style:{display:"flex",alignItems:"center",gap:8}},(0,a.createElement)(v.Button,{__next40pxDefaultSize:!0,variant:"secondary",onClick:async()=>{const e="light"===r?"dark":"light";m(e),await S()({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,a.createElement)(v.Button,{__next40pxDefaultSize:!0,variant:"primary",onClick:()=>{try{const e=p()(L,{validationLevel:"strict"});A(e.errors||[]);const t=(0,g.e)(L),r=new URLSearchParams(window.location.search).get("edit");if(null!=r)return(0,l.dispatch)(o.Ui).setIsSaving(!0),S()({path:`/mailerpress/v1/campaign/save-content/${r}`,method:"PUT",data:{content:t}}).then(()=>{window.location.reload()})}catch(e){A(e?.errors||[])}},disabled:!P},(0,y.__)("Apply","mailerpress")),(0,a.createElement)(v.Button,{__next40pxDefaultSize:!0,icon:_.A,onClick:D})))),(0,a.createElement)(n.default,{theme:I,value:L,extensions:z,onChange:e=>R(e),onCreateEditor:t=>{e.current=t}}))):null}}}]);