@samva/vite 0.17.0 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,4 +36,4 @@ Error generating stack: `+e.message+`
36
36
  `)?``:`
37
37
  `}${t}`},IV=(e,t)=>{if(e===void 0)return{kind:`pending`};let n=t?.find(({isDefault:e})=>e)??null;if(e===null)return{kind:`none`,defaultBrand:n};if(t===null)return{kind:`pending`};let r=e.slug===null?n:t.find(({slug:t})=>t===e.slug);return r==null?{kind:`missing`,slug:e.slug}:{kind:`brand`,brand:r}},LV=new Set([`p`,`h1`,`h2`,`h3`,`h4`,`h5`,`h6`,`span`,`a`,`li`,`strong`,`em`,`Link`,`Button`,`Text`,`Heading`]),RV=new Set([`Section`,`Container`,`Column`,`Row`,`div`,`td`,`table`,`Box`,`Card`]),zV=[`0`,`1`,`2`,`3`,`4`,`5`,`6`,`8`,`10`,`12`,`16`],BV=[{value:`font-normal`,label:`Regular`},{value:`font-medium`,label:`Medium`},{value:`font-semibold`,label:`Semibold`},{value:`font-bold`,label:`Bold`}],VV=/^text-(\[\d+(?:\.\d+)?px\]|xs|sm|base|lg|xl|[2-9]xl)$/,HV=[`xs`,`sm`,`base`,`lg`,`xl`,`2xl`,`3xl`,`4xl`,`5xl`,`6xl`],UV=/^text-(left|center|right|justify)$/,WV=/^font-(thin|extralight|light|normal|medium|semibold|bold|extrabold|black)$/,GV=e=>e.filter(e=>!e.includes(`:`));function KV(e){let t=Q(e=>e.lifecycleCapability),[n,r]=(0,W.useState)(null);return(0,W.useEffect)(()=>{if(t?.status!==`ready`)return;let e=!1;return t.api.inspect().then(t=>{let n=t.files.find(e=>e.path===bV);!e&&n?.content!=null&&r(rL(n.content))},()=>{}),()=>{e=!0}},[t]),n!==null&&n.length>0?n:aL(e).map(e=>({name:e,value:void 0}))}function qV({label:e,children:t,hint:n,value:r}){return(0,Z.jsxs)(`div`,{"data-slot":`editor-design-field`,className:`flex flex-col gap-1.5`,children:[(0,Z.jsxs)(`span`,{className:`flex items-baseline justify-between gap-2 text-xs`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:e}),r!==void 0&&(0,Z.jsx)(`span`,{"data-slot":`editor-design-field-value`,className:`text-foreground truncate font-mono text-[11px]`,children:r})]}),t,n!==void 0&&(0,Z.jsx)(`span`,{className:`text-muted-foreground text-[11px]`,children:n})]})}function JV({title:e,children:t}){return(0,Z.jsxs)(`section`,{"data-slot":`editor-design-group`,"aria-label":e,className:`border-border/70 flex flex-col gap-3 border-b py-3.5`,children:[(0,Z.jsx)(ZB,{children:e}),t]})}function YV({value:e,onCommit:t,testId:n,ariaLabel:r,type:i=`text`,disabled:a,placeholder:o,className:s}){let[c,l]=(0,W.useState)(e),u=()=>{c!==e&&t(c)};return(0,Z.jsx)(BB,{type:i,"aria-label":r,"data-testid":n,value:c,disabled:a,placeholder:o,onChange:e=>l(e.target.value),onBlur:u,onKeyDown:e=>{e.key===`Enter`&&u()},className:$(`h-8 text-[13px] md:text-[13px]`,s)})}var XV=e=>{let t=e.trim();if(t===``||/^\{\s*(["'`])\s*\1\s*\}$/.test(t)||/^\{\s*" "\s*\}$/.test(t))return null;let n=/^<([A-Za-z][\w.]*)/.exec(t)?.[1];if(n!==void 0)return n;let r=t.replace(/^\{|\}$/g,``).trim();return r.split(`.`).at(-1)??r},ZV=(e,t,n)=>{let r=t.properties.filter(e=>e.syntax===`child`&&(e.name===`children`||e.name.startsWith(`text.`))).toSorted((e,t)=>e.start-t.start),i=t.contentStart,a=t.contentEnd;if(i===null||a===null)return r.map(e=>e.kind===`literal`?{kind:`text`,field:e}:{kind:`chip`,label:XV(`{${e.value}}`)??e.value});let o=[],s=i,c=t=>{let r=e.slice(s,t),i=n?/\{[^{}]*\}|<[A-Za-z][\s\S]*?(?:\/>|<\/[^>]+>)/g:/\{[^{}]*\}/g;for(let e of r.match(i)??[]){let t=XV(e);t!==null&&o.push({kind:`chip`,label:t})}};for(let e of r)c(e.start),o.push(e.kind===`literal`?{kind:`text`,field:e}:{kind:`chip`,label:XV(`{${e.value}}`)??e.value}),s=e.end;return c(a),o};function QV({source:e,entrySource:t,target:n,available:r,commit:i,onRefused:a}){let o=KV(t),s=n.tag,c=LV.has(s),l=RV.has(s),u=s===`img`||s===`Image`,d=n.properties.find(e=>e.name===`className`),f=!n.hasSpread&&(d===void 0||d.kind===`literal`&&d.literalType===`string`),p=GV(oL(d?.kind===`literal`?d.value:``)),m=oL(d?.kind===`literal`?d.value:``),h=new Set(o.map(e=>e.name)),g=o.toSorted((e,t)=>eH(e.name)-eH(t.name)),_=(t,r)=>{let o=H_(e,n,{kind:`set`,value:t.join(` `)});o.ok?o.edits.length>0&&i(o.edits,r):a(o.reason)},v=(e,t,n)=>_([...m.filter(t=>t.includes(`:`)||!e(t)),...t],n),y=(t,n,r)=>{let o=M_(e,t,n);o===null?a(`That value doesn't fit ${sL(t.name)}.`):i([o],r)},b=ZV(e,n,c),x=e=>n.properties.find(t=>t.name===e),S=n.properties.filter(e=>e.syntax!==`child`&&e.name!==`className`&&!(u&&[`alt`,`width`,`height`,`src`].includes(e.name))),C=e=>p.find(t=>t.startsWith(`${e}-`)&&h.has(t.slice(e.length+1))),w=e=>p.find(t=>RegExp(`^${e}-\\[#`).test(t)),T=e=>t=>t.startsWith(`${e}-`)&&h.has(t.slice(e.length+1))||RegExp(`^${e}-\\[#`).test(t),E=[...new Set([...[...t.matchAll(/text-\[(\d+(?:\.\d+)?)px\]/g)].map(e=>`text-[${e[1]}px]`),...HV.filter(e=>RegExp(`(?:^|[\\s"'\`])text-${e}(?=[\\s"'\`])`).test(t)).map(e=>`text-${e}`)])].toSorted((e,t)=>tH(e)-tH(t)),D=p.find(e=>VV.test(e)),O=p.find(e=>WV.test(e)),k=p.find(e=>UV.test(e))?.slice(5)??`left`,A=(e,t)=>{let n=e=>p.find(t=>t.startsWith(`${e}-`))?.slice(e.length+1);if(t===`t`||t===`b`)return n(`${e}${t}`)??n(`${e}y`)??n(e)??``;let[r,i]=t===`x`?[`l`,`r`]:[`t`,`b`],a=n(`${e}${t}`)??n(e);if(a!==void 0)return a;let o=n(`${e}${r}`);return o!==void 0&&o===n(`${e}${i}`)?o:``},j=(e,t,n,r)=>{let i={x:[`${e}x`,`${e}l`,`${e}r`],y:[`${e}y`,`${e}t`,`${e}b`],t:[`${e}t`],b:[`${e}b`]}[t],a=m.filter(e=>e.includes(`:`)||!i.some(t=>e.startsWith(`${t}-`))),o=a.find(t=>t.startsWith(`${e}-`)),s=(t===`y`||t===`t`||t===`b`?`y`:`x`)==`x`?`y`:`x`,c=(e,t)=>{a.some(t=>t.startsWith(`${e}-`))||a.push(`${e}-${t}`)};if(o!==void 0){let n=o.slice(e.length+1);a=a.filter(e=>e!==o),c(`${e}${s}`,n),t===`t`&&c(`${e}b`,n),t===`b`&&c(`${e}t`,n)}let l=a.find(t=>t.startsWith(`${e}y-`));if((t===`t`||t===`b`)&&l!==void 0){let n=l.slice(e.length+2);a=a.filter(e=>e!==l),c(`${e}${t===`t`?`b`:`t`}`,n)}n!==``&&a.push(`${e}${t}-${n}`),_(a,r)},M=(e,t,n,i)=>{let a=A(e,t),o=zV.includes(a)||a===``?zV:[a,...zV];return(0,Z.jsx)(qV,{label:n,children:(0,Z.jsxs)(vV,{size:`sm`,"aria-label":n,"data-testid":i,value:a,disabled:!r,onChange:r=>j(e,t,r.target.value,`Change ${n.toLowerCase()}`),className:`w-full`,children:[(0,Z.jsx)(yV,{value:``,children:`None`}),o.map(e=>(0,Z.jsx)(yV,{value:e,children:rH(e)},e))]})})},N=(e,t,n)=>{let i=C(e),o=w(e);return(0,Z.jsxs)(qV,{label:t,value:i===void 0?o===void 0?`Not set`:o.slice(e.length+2,-1):i.slice(e.length+1),children:[(0,Z.jsx)(`div`,{"data-slot":`editor-design-swatches`,"data-testid":n,className:`flex flex-wrap items-center gap-2 py-0.5`,children:[{name:``,value:void 0},...g].map(a=>{let s=a.name===``?null:`${e}-${a.name}`,c=s===null?i===void 0&&o===void 0:i===s,l=s===null?`Not set`:a.name;return(0,Z.jsx)($B,{label:l,side:`top`,children:(0,Z.jsx)(UB,{"aria-label":`${t}: ${l}`,pressed:c,"data-testid":`${n}.${s===null?`none`:a.name}`,disabled:!r,onPressedChange:()=>{c||v(T(e),s===null?[]:[s],`Change ${t.toLowerCase()}`)},className:`ring-offset-background aria-pressed:ring-ring size-5 min-w-0 rounded-full p-0 hover:bg-transparent aria-pressed:bg-transparent aria-pressed:ring-2 aria-pressed:ring-offset-2`,children:(0,Z.jsx)(`span`,{"aria-hidden":!0,className:$(`size-5 rounded-full border border-black/15 dark:border-white/20`,s===null&&`border-muted-foreground/60 border-dashed`),style:{background:s===null?`linear-gradient(135deg, transparent 44%, var(--muted-foreground) 44%, var(--muted-foreground) 56%, transparent 56%)`:a.value??`repeating-linear-gradient(45deg, var(--muted), var(--muted) 3px, transparent 3px, transparent 6px)`}})})},l)})}),(0,Z.jsxs)(fV,{children:[(0,Z.jsxs)(pV,{"data-testid":`${n}.custom-toggle`,className:`text-muted-foreground hover:text-foreground group/custom flex items-center gap-1 text-[11px] outline-none`,children:[(0,Z.jsx)(_R,{className:`size-3 transition-transform group-data-[panel-open]/custom:rotate-90`}),`Custom color`]}),(0,Z.jsx)(mV,{className:`pt-1.5`,children:(0,Z.jsx)(YV,{ariaLabel:`${t} hex`,testId:`${n}.custom`,value:o?.slice(e.length+2,-1)??``,placeholder:`#b4532a`,disabled:!r,onCommit:n=>{let r=n.trim();if(r!==``&&!/^#[0-9a-f]{3,8}$/i.test(r)){a(`A custom color is a hex value such as #b4532a.`);return}v(T(e),r===``?[]:[`${e}-[${r}]`],`Change ${t.toLowerCase()}`)}})})]})]})},P=b.some(e=>e.kind===`text`);return(0,Z.jsxs)(`div`,{"data-slot":`editor-design-properties-controls`,"data-testid":`design-properties`,className:`flex flex-col`,children:[(c||b.some(e=>e.kind===`text`))&&b.length>0&&(0,Z.jsx)(JV,{title:`Content`,children:(0,Z.jsxs)(`div`,{"data-testid":`design-properties.content`,className:`flex flex-wrap items-center gap-1.5`,children:[b.map((e,t)=>e.kind===`chip`?(0,Z.jsx)($B,{label:`Filled in from the data each send. Change it in Source.`,children:(0,Z.jsx)(zB,{variant:`secondary`,"data-testid":`design-properties.binding`,className:`w-fit rounded-md font-mono text-[11px] font-normal`,children:e.label})},`chip-${t}`):(0,Z.jsx)(YV,{ariaLabel:`Text`,testId:`design-properties.text.${e.field.name}`,value:e.field.value,disabled:!r,onCommit:t=>y(e.field,t,`Edit text`),className:`min-w-40 flex-1`},`${e.field.name}`)),!P&&(0,Z.jsx)(`span`,{className:`text-muted-foreground text-[11px]`,children:`This content comes from the data. Change how it's written in Source.`})]})}),u&&(0,Z.jsxs)(JV,{title:`Image`,children:[x(`alt`)?.kind===`literal`&&(0,Z.jsx)(qV,{label:`Description`,hint:`Read aloud, and shown when images are off.`,children:(0,Z.jsx)(YV,{ariaLabel:`Image description`,testId:`design-properties.alt`,value:x(`alt`)?.value??``,disabled:!r,onCommit:e=>y(x(`alt`),e,`Edit image description`)})}),(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:[`width`,`height`].map(e=>{let t=x(e);return t?.kind===`literal`?(0,Z.jsx)(qV,{label:`${sL(e)} (px)`,children:(0,Z.jsx)(YV,{type:`number`,ariaLabel:sL(e),testId:`design-properties.${e}`,value:t.value,disabled:!r,onCommit:n=>y(t,n,`Change image ${e}`)})},e):null})})]}),S.length>0&&(0,Z.jsx)(JV,{title:`Settings`,children:(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:S.map(e=>e.kind===`literal`?(0,Z.jsx)(qV,{label:$V(e),children:(0,Z.jsx)(YV,{type:e.literalType===`number`?`number`:`text`,ariaLabel:sL(e.name),testId:`design-properties.prop.${e.name}`,value:e.value,disabled:!r,onCommit:t=>y(e,t,`Change ${sL(e.name).toLowerCase()}`)})},e.name):(0,Z.jsx)(qV,{label:$V(e),children:(0,Z.jsx)(zB,{variant:`secondary`,className:`w-fit rounded-md font-mono text-[11px] font-normal`,children:XV(`{${e.value}}`)??e.value})},e.name))})}),(c||l)&&!f&&(0,Z.jsx)(`p`,{"data-testid":`design-properties.computed`,className:`text-muted-foreground py-3 text-xs`,children:`This element's styles are worked out in the template, so they're changed in Source.`}),(c||l)&&f&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(JV,{title:`Color`,children:[N(`text`,`Text color`,`design-properties.color.text`),l&&N(`bg`,`Background`,`design-properties.color.bg`)]}),c&&(0,Z.jsx)(JV,{title:`Type`,children:(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Z.jsx)(qV,{label:`Size`,children:(0,Z.jsxs)(vV,{size:`sm`,"aria-label":`Size`,"data-testid":`design-properties.size`,value:D??``,disabled:!r,onChange:e=>v(e=>VV.test(e),e.target.value===``?[]:[e.target.value],`Change text size`),className:`w-full`,children:[(0,Z.jsx)(yV,{value:``,children:`Default`}),[...new Set([...D===void 0?[]:[D],...E])].map(e=>(0,Z.jsx)(yV,{value:e,children:nH(e)},e))]})}),(0,Z.jsx)(qV,{label:`Weight`,children:(0,Z.jsxs)(vV,{size:`sm`,"aria-label":`Weight`,"data-testid":`design-properties.weight`,value:O??``,disabled:!r,onChange:e=>v(e=>WV.test(e),e.target.value===``?[]:[e.target.value],`Change text weight`),className:`w-full`,children:[(0,Z.jsx)(yV,{value:``,children:`Default`}),BV.map(e=>(0,Z.jsx)(yV,{value:e.value,children:e.label},e.value))]})})]})}),(0,Z.jsxs)(JV,{title:`Layout`,children:[(0,Z.jsx)(qV,{label:`Alignment`,children:(0,Z.jsx)(eV,{ariaLabel:`Alignment`,testId:`design-properties.align`,size:`sm`,value:k,onChange:e=>r&&v(e=>UV.test(e),[`text-${e}`],`Change alignment`),options:[{value:`left`,title:`Align left`,label:(0,Z.jsx)(oz,{className:`size-3.5`}),testId:`design-properties.align.left`},{value:`center`,title:`Align center`,label:(0,Z.jsx)(az,{className:`size-3.5`}),testId:`design-properties.align.center`},{value:`right`,title:`Align right`,label:(0,Z.jsx)(sz,{className:`size-3.5`}),testId:`design-properties.align.right`}]})}),(0,Z.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:l?(0,Z.jsxs)(Z.Fragment,{children:[M(`p`,`x`,`Padding sides`,`design-properties.padding-x`),M(`p`,`y`,`Padding top and bottom`,`design-properties.padding-y`)]}):(0,Z.jsxs)(Z.Fragment,{children:[M(`m`,`t`,`Space above`,`design-properties.margin-top`),M(`m`,`b`,`Space below`,`design-properties.margin-bottom`)]})})]})]})]})}var $V=e=>e.literalType===`number`&&/width|height|padding|radius|size|margin|gap/i.test(e.name)?`${sL(e.name)} (px)`:sL(e.name),eH=e=>{let t=e.replace(/-foreground$/,``);return[`background`,`foreground`,`card`,`popover`,`muted`].includes(t)?0:[`primary`,`secondary`,`accent`,`destructive`].includes(t)?1:[`border`,`input`,`ring`].includes(t)?2:3},tH=e=>{let t=/\[(\d+(?:\.\d+)?)px\]/.exec(e)?.[1];return t===void 0?{xs:12,sm:14,base:16,lg:18,xl:20,"2xl":24,"3xl":30,"4xl":36,"5xl":48,"6xl":60}[e.slice(5)]??0:Number(t)},nH=e=>`${tH(e)} px`,rH=e=>{let t=/^\[(.+)\]$/.exec(e)?.[1];if(t!==void 0)return t;let n=Number(e);return Number.isFinite(n)?`${n*4} px`:e},iH=$(`border-border bg-background text-foreground w-full rounded border px-2 py-1.5 text-xs`,Cz),aH=$(`border-border hover:bg-muted rounded border px-2 py-1 text-xs disabled:opacity-50`,Cz);function oH({field:e,source:t,propose:n,apply:r}){let i=`Edit ${sH(e.name).toLowerCase()}`,a=()=>{let n=M_(t,e,o);n!==null&&r(n,i)},[o,s]=(0,W.useState)(e.value),[c,l]=(0,W.useState)(e.kind===`literal`&&e.literalType===`string`?JSON.stringify(e.value):e.value);return(0,Z.jsxs)(`div`,{className:`mt-3 space-y-1.5`,children:[(0,Z.jsxs)(`label`,{className:`block text-xs`,children:[sH(e.name),` · `,e.kind,e.kind===`literal`?(0,Z.jsx)(`input`,{"aria-label":`${e.name} literal`,"data-testid":`source.property.${e.name}.literal`,type:e.literalType===`number`?`number`:`text`,className:iH,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{e.key===`Enter`&&a()}}):(0,Z.jsx)(`code`,{className:`bg-muted mt-1 block rounded p-2 break-all`,children:e.value})]}),e.kind===`literal`&&(0,Z.jsx)(`button`,{"data-testid":`source.property.${e.name}.apply`,type:`button`,className:aH,disabled:M_(t,e,o)===null,onClick:a,children:`Update`}),(0,Z.jsxs)(`details`,{children:[(0,Z.jsx)(`summary`,{"data-testid":`source.property.${e.name}.expression-toggle`,className:`cursor-pointer text-xs`,children:e.kind===`literal`?`Change to a binding or expression`:`Review a binding or expression change`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground my-1 text-xs`,children:`This changes template logic. Fixture values are edited separately.`}),(0,Z.jsx)(`textarea`,{"aria-label":`${e.name} expression`,"data-testid":`source.property.${e.name}.expression`,className:iH,value:c,onChange:e=>l(e.target.value)}),(0,Z.jsx)(`button`,{"data-testid":`source.property.${e.name}.review`,type:`button`,className:aH,onClick:()=>n(N_(t,e,c)),children:`Review expression diff`})]})]})}var sH=e=>e===`children`||e.startsWith(`text.`)?`Text`:e===`className`?`Style classes`:e,cH=e=>e instanceof Error&&e.message!==``?e.message:`The host could not save this.`;function lH(e){let t=Q(e=>e.lifecycleCapability),{flushSaves:n}=Q(e=>e.actions),[r,i]=(0,W.useState)(null);return(0,W.useEffect)(()=>{if(e===null||t?.status!==`ready`)return;let r=!1;return n().then(()=>t.api.inspect()).then(e=>{if(r)return;let t={};for(let n of e.files)n.binary!==!0&&n.status!==`deleted`&&n.content!==null&&(t[n.path]=n.content);i(t)}).catch(()=>{r||i(`failed`)}),()=>{r=!0}},[e,t,n]),e===null?{status:`entry`}:t?.status===`ready`?r===null?{status:`loading`}:r===`failed`?{status:`unavailable`}:{status:`ready`,files:r,api:t.api}:{status:`unavailable`}}function uH(e){return e.assistant?`Edits wait for the assistant to finish.`:e.busy?`Waiting for the latest source to render.`:e.file!==null&&e.project===`loading`?`Reading ${e.file}.`:e.file!==null&&e.project===`unavailable`?`This element is written in ${e.file}, outside the template entry, and this host cannot edit project files from here. Open Source or ask the agent.`:e.resolved?`This source is read-only.`:`This origin cannot be resolved in its file. Open its source or ask the agent.`}function dH(e,t){return`${e.occurrences>1?`This element renders ${e.occurrences} times here (a loop or a repeated component), so one edit changes all ${e.occurrences}.`:`This changes this element.`}${t?` It is written in a partial, so every template that uses the partial changes too.`:``} Fixture items remain separate data.`}function fH({selection:e}){let{doc:t,pending:n,revision:r,editable:i,storeError:a,lifecycleBusy:o,hostBusy:s}=Q(kk(e=>({doc:e.doc,pending:e.pendingAuthoredSource,revision:e.render?.revision,editable:e.sourceEditable,storeError:e.sourceEditError,lifecycleBusy:e.lifecycleBusy,hostBusy:e.hostBusy}))),{applySourceEdit:c,openSource:l,requestSourceAssistance:u,beginLifecycle:d,endLifecycle:f}=Q(e=>e.actions),{flushSaves:p}=Q(e=>e.actions),m=gz(`rail.assistant`)!==void 0,[h,g]=(0,W.useState)(0),[_,v]=(0,W.useState)(null),[y,b]=(0,W.useState)(null),[x,S]=(0,W.useState)(!1),[C,w]=(0,W.useState)(``),[T,E]=(0,W.useState)(`<p>New content</p>`),[D,O]=(0,W.useState)(``),[k,A]=(0,W.useState)(null),[j,M]=(0,W.useState)(null),N=e.origins[h],P=t?.origin.file,F=N!==void 0&&N.fileName!==P,I=lH(F?N.fileName:null);if(t===null||P===void 0)return null;let L=t.origin.authoredSource,R=F&&N!==void 0?I.status===`ready`?I.files[N.fileName]??null:null:L,z=N===void 0||R===null?null:A_(R,N.fileName,N),B=F?{entry:P,file:N.fileName,files:{...I.status===`ready`?I.files:{},[P]:L}}:{entry:P},ee=i&&n===null&&!o&&!s&&!x&&r===t.rev&&z!==null&&R!==null,te=(e,t)=>{let n=F_(R??``,e,{profile:B});return{edits:e,label:t,refusal:n.ok?null:n.reason}},ne=(e,t)=>{if(R===null)return;if(b(null),v(null),!F){c({revision:r??``,source:R,edits:e,design:{label:t}});return}let n=F_(R,e,{profile:B});if(!n.ok){b(n.reason);return}I.status===`ready`&&d()&&(S(!0),p().then(e=>I.api.updateFile({path:N.fileName,baseRev:e,content:n.source})).catch(e=>b(cH(e))).finally(()=>{f(),S(!1)}))},V=(e,t)=>{ne([e],t),M(null)},re=y??a,ie=z?.properties.find(e=>e.name===`className`),ae=z===null||R===null||ie?.kind===`literal`?null:(()=>{let e=H_(R,z,{kind:`add`,tokens:`x`});return e.ok?null:e.reason})(),oe=e.origins.length>1;return(0,Z.jsxs)(`div`,{"data-slot":`editor-element-controls`,className:`pb-3`,children:[F&&(0,Z.jsxs)(`p`,{"data-testid":`source.partial-warning`,className:`border-border bg-muted text-foreground mt-3 rounded-lg border p-2.5 text-xs`,children:[`This is written in a shared part (`,N.fileName,`). Edits here save straight away and change every template that uses it.`]}),(e.occurrences>1||oe&&h>0)&&(0,Z.jsx)(`p`,{"data-testid":`source.scope-note`,className:`text-muted-foreground mt-3 text-xs`,children:oe&&h>0?`Changes this call site, including every loop iteration it produces. Fixture items remain separate data.`:dH(e,F)}),ee?(0,Z.jsx)(QV,{source:R,entrySource:L,target:z,available:ee,commit:ne,onRefused:b},`${h}`):(0,Z.jsx)(`p`,{"data-testid":`source.unavailable`,className:`text-muted-foreground mt-3 text-xs`,children:uH({assistant:s,busy:n!==null||x||o,file:F?N.fileName:null,project:I.status,resolved:z!==null})}),(0,Z.jsxs)(fV,{"data-testid":`source.advanced`,className:`border-border/70 border-b`,children:[(0,Z.jsxs)(pV,{"data-testid":`source.advanced-toggle`,className:`text-muted-foreground hover:text-foreground group/advanced flex w-full items-center gap-1.5 py-3 font-mono text-[10.5px] font-medium tracking-[0.08em] uppercase outline-none`,children:[(0,Z.jsx)(_R,{className:`size-3 transition-transform group-data-[panel-open]/advanced:rotate-90`}),`Advanced`]}),(0,Z.jsxs)(mV,{keepMounted:!0,className:`pb-3 data-[closed]:hidden`,children:[(0,Z.jsx)(`p`,{className:`text-muted-foreground mb-2 text-xs`,children:`The element's raw props and classes. The whole template is in Source.`}),oe&&(0,Z.jsxs)(`label`,{className:`block text-xs`,children:[`Edit scope`,(0,Z.jsx)(`select`,{"aria-label":`Edit scope`,"data-testid":`source.scope`,className:iH,value:h,onChange:e=>{g(Number(e.target.value)),M(null)},children:e.origins.map((e,t)=>(0,Z.jsxs)(`option`,{value:t,children:[t===0?`Element`:`Call site ${t}`,` · `,VI(e)]},t))})]}),ee?(0,Z.jsxs)(Z.Fragment,{children:[z.properties.length===0&&(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-2 text-xs`,children:`No unambiguous scalar properties here. Use source or the agent for this shape.`}),z.hasSpread&&(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-2 text-xs`,children:`Spread properties can override attributes here. Edit attributes in Source or ask the agent.`}),z.properties.filter(e=>!z.hasSpread||e.syntax===`child`).map(e=>(0,Z.jsx)(oH,{field:e,source:R,apply:V,propose:t=>M(te([t],`Edit ${sH(e.name).toLowerCase()} expression`))},`${t.rev}:${R}:${h}:${e.name}`)),ae!==null&&(0,Z.jsx)(`p`,{"data-testid":`source.class-refusal`,className:`text-muted-foreground mt-3 text-xs`,children:ae}),ae===null&&(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsxs)(`label`,{className:`block text-xs`,children:[ie===void 0?`Style classes · literal`:`Add style classes`,(0,Z.jsx)(`input`,{"aria-label":`Style classes`,"data-testid":`source.classes`,className:iH,value:C,onChange:e=>w(e.target.value)})]}),(0,Z.jsx)(`button`,{"data-testid":`source.classes-add`,type:`button`,className:aH,disabled:C.trim()===``,onClick:()=>{let e=H_(R,z,{kind:`add`,tokens:C});e.ok?ne(e.edits,`Add style classes`):b(e.reason),w(``)},children:ie===void 0?`Add styles`:`Add classes`})]}),(0,Z.jsxs)(`details`,{className:`mt-3`,children:[(0,Z.jsx)(`summary`,{"data-testid":`source.structure-toggle`,className:`cursor-pointer text-xs`,children:`Structure · authored block`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground my-2 text-xs`,children:`This changes the whole source block at the scope above. A rendered loop instance has no independent source block. Change fixture items separately; edit loop or conditional logic in Source.`}),(0,Z.jsx)(`textarea`,{"aria-label":`Insert TSX`,"data-testid":`source.insert`,value:T,className:iH,onChange:e=>E(e.target.value)}),(0,Z.jsx)(`button`,{"data-testid":`source.review-insert`,type:`button`,className:aH,disabled:z.contentEnd===null,onClick:()=>{let e=R_(R,z,{kind:`insert`,tsx:T});A(e===null?null:te(e,`Insert content`))},children:`Review insert`}),` `,(0,Z.jsx)(`button`,{"data-testid":`source.review-delete`,type:`button`,className:aH,disabled:!z.structural,onClick:()=>{let e=R_(R,z,{kind:`delete`});A(e===null?null:te(e,`Delete block`))},children:`Review delete`}),` `,(0,Z.jsx)(`button`,{"data-testid":`source.review-duplicate`,type:`button`,className:aH,disabled:!z.structural,onClick:()=>{let e=R_(R,z,{kind:`duplicate`});A(e===null?null:te(e,`Duplicate block`))},children:`Review duplicate`}),` `,(0,Z.jsx)(`button`,{"data-testid":`source.review-move-up`,type:`button`,className:aH,disabled:z.previous===null,onClick:()=>{let e=R_(R,z,{kind:`reorder`,direction:`before`});A(e===null?null:te(e,`Move block earlier`))},children:`Move earlier`}),` `,(0,Z.jsx)(`button`,{"data-testid":`source.review-move-down`,type:`button`,className:aH,disabled:z.next===null,onClick:()=>{let e=R_(R,z,{kind:`reorder`,direction:`after`});A(e===null?null:te(e,`Move block later`))},children:`Move later`}),!F&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`label`,{className:`mt-2 block text-xs`,children:[`Move into shared source container`,(0,Z.jsxs)(`select`,{"aria-label":`Move destination`,"data-testid":`source.destination`,value:D,className:iH,onChange:e=>O(e.target.value),children:[(0,Z.jsx)(`option`,{value:``,children:`Choose destination`}),t.channel===`email`&&t.render?.selections.filter(e=>e.authored&&e.tag!==`html`).map(e=>(0,Z.jsxs)(`option`,{value:e.instancePath,children:[XI(e,L),e.origins[0]===void 0?``:` · line ${e.origins[0].lineNumber}`]},e.instancePath))]})]}),(0,Z.jsx)(`button`,{"data-testid":`source.review-move`,type:`button`,className:aH,disabled:!z.structural||D===``,onClick:()=>{let e=(t.channel===`email`?t.render?.selections.find(e=>e.instancePath===D):void 0)?.origins[0],n=e===void 0?null:A_(R,P,e),r=n===null?null:R_(R,z,{kind:`move`,destination:n});A(r===null?null:te(r,`Move block`)),v(r===null?`This destination cannot accept the selected block. Choose another source container or use Source.`:null)},children:`Review move`})]}),_!==null&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-status-error text-xs`,children:_}),k!==null&&(0,Z.jsxs)(`div`,{role:`region`,"aria-label":`Structural source diff`,className:`mt-2`,children:[(0,Z.jsx)(`pre`,{className:`bg-muted overflow-auto p-2 text-xs`,children:k.edits.map(e=>`- ${e.before}\n+ ${e.after}`).join(`
38
38
  `)}),k.refusal!==null&&(0,Z.jsx)(`p`,{"data-testid":`source.structure-refusal`,className:`text-status-error text-xs`,children:k.refusal}),(0,Z.jsx)(`button`,{"data-testid":`source.apply-structure`,type:`button`,className:aH,disabled:k.refusal!==null,onClick:()=>{ne(k.edits,k.label),A(null)},children:`Use this change`}),` `,(0,Z.jsx)(`button`,{type:`button`,className:aH,onClick:()=>A(null),children:`Cancel`})]})]}),j!==null&&(0,Z.jsxs)(`div`,{role:`region`,"aria-label":`Proposed source diff`,className:`mt-3 space-y-2`,children:[(0,Z.jsx)(`p`,{className:`text-xs`,children:`Review the exact source change`}),(0,Z.jsx)(`pre`,{className:`bg-muted overflow-auto p-2 text-xs`,children:j.edits.map(e=>`- ${e.before}\n+ ${e.after}`).join(`
39
- `)}),j.refusal!==null&&(0,Z.jsx)(`p`,{"data-testid":`source.proposal-refusal`,className:`text-status-error text-xs`,children:j.refusal}),(0,Z.jsx)(`button`,{"data-testid":`source.apply-reviewed`,type:`button`,className:aH,disabled:j.refusal!==null,onClick:()=>{ne(j.edits,j.label),M(null)},children:`Use this change`}),` `,(0,Z.jsx)(`button`,{type:`button`,className:aH,onClick:()=>M(null),children:`Cancel`})]})]}):null]})]}),re!==null&&(0,Z.jsx)(`p`,{"data-testid":`source.edit-error`,className:`text-status-error mt-2 text-xs`,children:re}),(0,Z.jsxs)(`div`,{className:`mt-3 flex gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,className:aH,onClick:l,children:`Open source`}),m&&(0,Z.jsx)(`button`,{type:`button`,className:aH,onClick:()=>u(h),children:`Ask agent`})]})]})}function pH(){let{undo:e,redo:t,error:n,editable:r}=Q(kk(e=>({undo:e.undoHistory.length+(e.designDraft?.edits.length??0),redo:e.redoHistory.length+(e.designDraft?.undone.length??0),error:e.sourceEditError,editable:e.sourceEditable}))),i=Q(e=>e.actions);return(0,Z.jsxs)(`div`,{className:`border-border border-b px-3 py-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`button`,{"data-testid":`source.undo`,type:`button`,className:aH,disabled:!r||e===0,onClick:i.undo,children:`Undo`}),(0,Z.jsx)(`button`,{"data-testid":`source.redo`,type:`button`,className:aH,disabled:!r||t===0,onClick:i.redo,children:`Redo`})]}),n!==null&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-status-error mt-1 text-xs`,children:n})]})}function mH(){let e=Q(e=>e.doc),t=Q(e=>e.pendingAuthoredSource),n=Q(e=>e.sourceEditable),{applySourceEdit:r,openSource:i}=Q(e=>e.actions),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(!1);if(e?.channel!==`email`)return null;let l=B_(e.origin.authoredSource).find(t=>t.name===e.fixture);return(0,Z.jsxs)(`div`,{className:`border-border-subtle border-b py-3`,children:[(0,Z.jsxs)(ZB,{children:[`Fixture data · `,e.fixture]}),(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Example input for this fixture. Changes do not replace template bindings or change other fixtures.`}),l===void 0?(0,Z.jsx)(`button`,{type:`button`,className:aH,onClick:i,children:`Open fixture source`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`textarea`,{"aria-label":`Fixture data source`,"data-testid":`source.fixture-data`,className:iH,value:a??l.source,onChange:e=>{o(e.target.value),c(!1)},disabled:!n||t!==null}),(0,Z.jsx)(`button`,{"data-testid":`source.fixture-review`,type:`button`,className:aH,disabled:!n||t!==null||a===null,onClick:()=>c(!0),children:`Review fixture change`}),s&&a!==null&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`pre`,{className:`bg-muted overflow-auto p-2 text-xs`,children:`- ${l.source}\n+ ${a}`}),(0,Z.jsx)(`button`,{"data-testid":`source.fixture-apply`,type:`button`,className:aH,onClick:()=>{r({revision:e.rev,source:e.origin.authoredSource,edits:[{start:l.start,end:l.end,before:l.source,after:a}],design:{label:`Edit fixture data`}}),o(null),c(!1)},children:`Use this change`}),` `,(0,Z.jsx)(`button`,{type:`button`,className:aH,onClick:()=>{o(null),c(!1)},children:`Cancel`})]})]})]})}function hH({selection:e}){let t=Q(e=>`${e.doc?.rev}:${e.doc?.origin.authoredSource}:${e.doc?.channel===`email`?e.doc.fixture:``}`);return(0,Z.jsx)(fH,{selection:e},t)}function gH(){let e=Q(e=>`${e.doc?.rev}:${e.doc?.origin.authoredSource}:${e.doc?.channel===`email`?e.doc.fixture:``}`);return(0,Z.jsx)(mH,{},e)}var _H=[],vH=[],yH=[];function bH({label:e,title:t,children:n}){return(0,Z.jsxs)(`div`,{title:t,className:`mt-1.5 flex items-center justify-between gap-2 first:mt-0`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:e}),n]})}function xH(){let e=Q(e=>e.doc?.variables??vH);return e.length===0?null:(0,Z.jsxs)(`div`,{className:`border-border-subtle border-b py-3`,children:[(0,Z.jsx)(ZB,{children:`Variables`}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,Z.jsx)(XB,{name:e.name,className:`shrink-0`}),(0,Z.jsx)(`span`,{className:`text-placeholder ml-auto text-[11px]`,children:e.required?`required`:`optional`})]},e.name))}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-2.5 text-[11.5px]`,children:`The preview shows the values of the fixture selected above it.`})]})}function SH(){return(0,Z.jsx)(`div`,{className:`py-3`,children:(0,Z.jsx)(_V,{})})}function CH({checks:e}){let{deviceWidth:t,entryFile:n,fixture:r,fixtures:i}=Q(kk(e=>({deviceWidth:NL[e.previewDevice],entryFile:e.doc?.origin.file??null,fixture:e.doc?.channel===`email`?e.doc.fixture:null,fixtures:e.doc?.channel===`email`?e.doc.fixtures:_H})));return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`border-border-subtle border-b py-3`,children:[(0,Z.jsx)(ZB,{children:`Document`}),(0,Z.jsx)(bH,{label:`Width`,children:(0,Z.jsxs)(QB,{children:[t,` `,(0,Z.jsx)(`span`,{className:`text-placeholder text-[10.5px]`,children:`px`})]})}),n!==null&&(0,Z.jsx)(bH,{label:`Entry`,children:(0,Z.jsx)(QB,{children:n})}),r!==null&&(0,Z.jsx)(bH,{label:`Fixture`,title:`${i.length} declared`,children:(0,Z.jsx)(QB,{children:r})})]}),(0,Z.jsx)(gH,{},`${r}:${n}`),(0,Z.jsx)(xH,{}),e&&(0,Z.jsx)(SH,{})]})}function wH({value:e,onChange:t,onCommit:n,placeholder:r,type:i=`text`,testId:a}){return(0,Z.jsx)(`input`,{type:i,value:e,placeholder:r,"data-testid":a,spellCheck:!1,onChange:e=>t(e.target.value),onBlur:n,onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:$(`border-border bg-background text-foreground placeholder:text-placeholder h-7 max-w-none min-w-0 flex-1 rounded-[5px] border px-2.5 text-xs outline-none`,Cz)})}function TH(){let e=Q(e=>e.doc),t=Q(e=>e.metadataError),{saveMetadata:n}=Q(e=>e.actions),r=e?.metadata.fromDefault,[i,a]=(0,W.useState)(r?.name??``),[o,s]=(0,W.useState)(r?.email??``),[c,l]=(0,W.useState)((e?.metadata.replyToDefault??[]).join(`, `)),u=()=>{let e=o.trim();n({fromDefault:e.length===0?null:{email:e,name:i.trim()||void 0}})};return(0,Z.jsxs)(`div`,{className:`py-3`,children:[(0,Z.jsx)(ZB,{children:`Defaults · per send`}),(0,Z.jsx)(bH,{label:`From name`,children:(0,Z.jsx)(wH,{value:i,onChange:a,onCommit:u,placeholder:`Sender name`})}),(0,Z.jsx)(bH,{label:`From email`,children:(0,Z.jsx)(wH,{type:`email`,value:o,onChange:s,onCommit:u,placeholder:`you@domain.com`,testId:`inspector.envelope.from-email`})}),(0,Z.jsx)(bH,{label:`Reply-To`,children:(0,Z.jsx)(wH,{type:`email`,value:c,onChange:l,onCommit:()=>{let e=c.split(`,`).map(e=>e.trim()).filter(e=>e.length>0);n({replyToDefault:e.length===0?null:e})},placeholder:`Comma-separated`})}),t!==null&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-status-error mt-2 text-[11.5px]`,children:t})]})}function EH(){let e=Q(e=>e.metadataEditable),t=Q(e=>e.render);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`border-border-subtle text-muted-foreground border-b py-2.5 text-[11px] leading-relaxed`,children:`Subject and preview text come from the template code and the fixture on screen. From / Reply-To are template defaults, overridden per send.`}),(0,Z.jsxs)(`div`,{className:`border-border-subtle border-b py-3`,children:[(0,Z.jsx)(ZB,{children:`Rendered`}),(0,Z.jsx)(bH,{label:`Subject`,children:(0,Z.jsx)(QB,{children:t?.subject??`No subject`})}),(0,Z.jsx)(bH,{label:`Preview`,children:(0,Z.jsx)(QB,{children:t?.preheader??`No preview text`})})]}),e?(0,Z.jsx)(TH,{}):(0,Z.jsx)(`p`,{className:`text-muted-foreground py-3 text-xs`,children:`This host does not edit sender defaults.`})]})}function DH({selection:e}){let t=Q(e=>e.render?.selections??yH),n=Q(e=>e.render?.html??``),{select:r}=Q(e=>e.actions),i=e.origins[0],a=e.origins.slice(1),o=lc(t,e),s=uc(t,e);return(0,Z.jsxs)(`div`,{"data-slot":`editor-element-inspector`,"data-instance-path":e.instancePath,children:[o.length>1&&(0,Z.jsxs)(`div`,{"data-slot":`editor-element-copies`,className:`border-border/70 border-b py-3`,children:[(0,Z.jsx)(ZB,{children:`Copies`}),(0,Z.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-0.5 p-0`,children:o.map((t,i)=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(aB,{variant:`ghost`,size:`sm`,"data-testid":`inspector.iteration.${t.instancePath}`,"aria-current":t.instancePath===e.instancePath||void 0,onClick:()=>r(t.instancePath),className:$(`w-full justify-start gap-2 px-2 text-left text-[12.5px] font-normal`,t.instancePath===e.instancePath&&`bg-muted text-foreground font-medium`),children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground w-4 tabular-nums`,children:i+1}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:WI(t,n)??`Copy ${i+1}`})]})},t.instancePath))})]}),(0,Z.jsx)(hH,{selection:e},`${e.instancePath}:${e.start}:${e.end}`),(0,Z.jsxs)(fV,{"data-slot":`editor-element-details`,className:`py-1`,children:[(0,Z.jsxs)(pV,{"data-testid":`inspector.details-toggle`,className:`text-muted-foreground hover:text-foreground group/details flex w-full items-center gap-1.5 py-2 font-mono text-[10.5px] font-medium tracking-[0.08em] uppercase outline-none`,children:[(0,Z.jsx)(_R,{className:`size-3 transition-transform group-data-[panel-open]/details:rotate-90`}),`Where it's written`]}),(0,Z.jsxs)(mV,{keepMounted:!0,className:`pb-3 data-[closed]:hidden`,children:[i===void 0?(0,Z.jsx)(`p`,{className:`text-muted-foreground text-[11.5px]`,children:`The renderer produced this element with no authoring on the stack, so nothing in the template points at it.`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(bH,{label:`Written at`,children:(0,Z.jsx)(QB,{testId:`inspector.authoring.origin`,children:VI(i)})}),(0,Z.jsx)(bH,{label:`Kind`,title:e.authored?`This element was written in the template.`:`A compiler primitive produced this element; the authoring above is the call that asked for it.`,children:(0,Z.jsx)(QB,{testId:`inspector.element.provenance`,children:e.authored?`Authored`:`Generated`})}),(0,Z.jsx)(bH,{label:`Rendered as`,children:(0,Z.jsx)(QB,{testId:`inspector.element.tag`,children:e.tag})}),(0,Z.jsx)(`p`,{"data-testid":`inspector.authoring.occurrence`,className:`text-muted-foreground mt-2 text-[11.5px]`,children:e.occurrences>1?`This authoring renders ${e.occurrences} elements here; this is number ${e.occurrence}.`:`This authoring renders one element here.`}),s.length>o.length&&(0,Z.jsxs)(`p`,{"data-testid":`inspector.authoring.definition-scope`,className:`text-muted-foreground mt-1 text-[11.5px]`,children:[s.length,` elements across the whole render come from it, through more than one call site.`]})]}),a.length>0&&(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Inside, innermost first`}),(0,Z.jsx)(`ol`,{className:`m-0 mt-1 flex list-none flex-col gap-1 p-0`,children:a.map((e,t)=>(0,Z.jsx)(`li`,{"data-testid":`inspector.call-site.${t}`,className:`text-foreground font-mono text-[11.5px] break-all`,children:VI(e)},`${VI(e)}:${t}`))})]})]})]})]})}function OH({embedded:e=!1,checks:t=!0}={}){let{outline:n,selection:r,rightCollapsed:i,rightWidth:a,layoutMode:o}=Q(kk(e=>({outline:e.outline,selection:e.selection,rightCollapsed:e.rightCollapsed,rightWidth:e.rightWidth,layoutMode:e.layoutMode}))),{select:s,selectDocument:c,toggleRight:l}=Q(e=>e.actions),u=r.kind===`element`?n?.index.get(r.instancePath)??null:null,d=r.kind===`envelope`?`envelope`:u===null?`document`:`element`,f=Q(e=>e.doc?.origin.authoredSource??``),p=u===null||n===null?[]:tL(n,u.instancePath).slice(-2).map(e=>({instancePath:e.instancePath,label:XI(e,f)})),m=u===null?void 0:ZI(u),h=!e&&(o===`compact`||o===`narrow`);return(0,Z.jsx)(`aside`,{"aria-label":`Inspector`,"data-testid":`inspector`,"aria-hidden":!e&&i?!0:void 0,inert:!e&&i?!0:void 0,"data-editor-rail":`right`,style:{width:e?`100%`:i?0:a,maxWidth:h?`calc(100% - 48px)`:void 0},className:$(`flex h-full shrink-0 flex-col overflow-hidden bg-background transition-[width,transform,box-shadow] duration-180 ease-out`,!e&&`border-l border-border`,h&&`absolute inset-y-0 right-0 z-40 shadow-[var(--shadow-floating)]`,!e&&i&&`border-l-0`),children:(0,Z.jsxs)(`div`,{className:`flex h-full min-w-0 flex-col`,style:{width:e?`100%`:a,maxWidth:`100%`},children:[(0,Z.jsx)(`div`,{className:`border-border bg-background/95 sticky top-0 z-10 border-b backdrop-blur-md`,children:(0,Z.jsxs)(`div`,{className:`flex min-h-10 items-center gap-2 px-3 py-2`,children:[(0,Z.jsx)(`div`,{className:`text-muted-foreground flex min-w-0 flex-1 items-center gap-0.5 overflow-hidden text-xs`,children:d===`document`?(0,Z.jsx)(`span`,{className:`text-foreground truncate px-1 font-semibold`,children:`Document`}):d===`envelope`?(0,Z.jsx)(`span`,{className:`text-foreground truncate px-1 font-semibold`,children:`Envelope`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(aB,{variant:`ghost`,size:`xs`,onClick:c,"data-testid":`inspector.document`,className:`text-muted-foreground shrink-0 px-1 font-normal`,children:`Email`}),p.map(e=>(0,Z.jsxs)(`span`,{className:`contents`,children:[(0,Z.jsx)(_R,{className:`text-placeholder size-3 shrink-0`}),(0,Z.jsx)(aB,{variant:`ghost`,size:`xs`,onClick:()=>s(e.instancePath),className:`text-muted-foreground max-w-[88px] truncate px-1 font-normal`,children:e.label})]},e.instancePath)),(0,Z.jsx)(_R,{className:`text-placeholder size-3 shrink-0`}),(0,Z.jsx)(`span`,{"data-testid":`inspector.element-name`,className:`text-foreground truncate px-1 font-semibold`,children:u===null?``:XI(u,f)})]})}),u!==null&&(m!==void 0||!u.authored)&&(0,Z.jsx)(`span`,{"data-testid":`inspector.selection-badge`,className:`bg-muted text-muted-foreground shrink-0 rounded-md px-1.5 py-0.5 text-[10.5px] font-medium tabular-nums`,children:u.authored?m:`Generated`}),!e&&(0,Z.jsx)($B,{label:`Collapse inspector`,side:`bottom`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Collapse inspector`,"data-testid":`inspector.collapse`,onClick:l,className:`text-muted-foreground ml-auto`,children:(0,Z.jsx)(FR,{})})})]})}),(0,Z.jsxs)(RM,{"data-samva-scroll-area":`inspector`,className:`relative min-h-0 flex-1`,children:[(0,Z.jsx)(XM,{className:`size-full`,children:(0,Z.jsxs)(`div`,{className:`samva-inspector-content pb-4`,children:[d===`document`&&(0,Z.jsx)(CH,{checks:t}),d===`envelope`&&(0,Z.jsx)(EH,{}),u!==null&&(0,Z.jsx)(DH,{selection:u})]})}),(0,Z.jsx)(nN,{orientation:`vertical`,className:`absolute top-0 right-0 bottom-0 flex w-2.5 touch-none p-0.5 select-none`,children:(0,Z.jsx)(rN,{className:`relative flex-1 rounded-full bg-[var(--editor-scrollbar-thumb)] hover:bg-[var(--editor-scrollbar-thumb-hover)]`})})]})]})})}var kH=$(`samva-editor-context-item`,`grid min-h-8 grid-cols-[1fr_auto] items-center gap-5 rounded-md px-2.5 text-[12.5px] text-foreground outline-none`,`data-[highlighted]:bg-sel-soft data-[highlighted]:text-accent-email`);function AH({children:e,ancestors:t,onSelect:n,onOpenChange:r,portalContainer:i,open:a,anchor:o}){return(0,Z.jsxs)(sP,{open:a,onOpenChange:r,children:[(0,Z.jsx)(lP,{render:e}),(0,Z.jsx)(UN,{container:i,children:(0,Z.jsx)(uP,{anchor:o,sideOffset:2,children:(0,Z.jsxs)(BN,{"aria-label":`Select element`,"data-testid":`node-context-menu.popup`,className:`samva-editor-context-popup samva-editor-shell border-border bg-surface-elevated z-50 min-w-52 rounded-lg border p-1 shadow-[var(--shadow-lg)] outline-none`,children:[(0,Z.jsx)(`div`,{className:`text-muted-foreground px-2.5 py-1 text-[11px]`,children:`Select`}),t.map(e=>(0,Z.jsxs)(zN,{className:kH,"data-testid":`node-context-menu.item.${e.instancePath}`,onClick:()=>n(e.instancePath),children:[(0,Z.jsx)(`span`,{children:e.label}),e.generated?(0,Z.jsx)(`span`,{className:`text-muted-foreground text-[11px]`,children:`generated`}):null]},e.instancePath))]})})})]})}function jH({...e}){return(0,Z.jsx)($N,{"data-slot":`dropdown-menu`,...e})}function MH({...e}){return(0,Z.jsx)(iP,{"data-slot":`dropdown-menu-trigger`,...e})}function NH({align:e=`start`,alignOffset:t=0,side:n=`bottom`,sideOffset:r=4,className:i,...a}){let o=kz();return(0,Z.jsx)(UN,{container:o,children:(0,Z.jsx)(WN,{className:`isolate z-50 outline-none`,align:e,alignOffset:t,side:n,sideOffset:r,children:(0,Z.jsx)(BN,{"data-slot":`dropdown-menu-content`,className:$(`data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 bg-popover text-popover-foreground min-w-32 rounded-lg p-1 shadow-md ring-1 duration-100 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 z-50 max-h-(--available-height) w-(--anchor-width) origin-(--transform-origin) overflow-x-hidden overflow-y-auto outline-none data-closed:overflow-hidden`,i),...a})})})}function PH({...e}){return(0,Z.jsx)(LN,{"data-slot":`dropdown-menu-group`,...e})}function FH({className:e,inset:t,...n}){return(0,Z.jsx)(RN,{"data-slot":`dropdown-menu-label`,"data-inset":t,className:$(`text-muted-foreground px-1.5 py-1 text-xs font-medium data-inset:pl-7`,e),...n})}function IH({className:e,inset:t,variant:n=`default`,...r}){return(0,Z.jsx)(zN,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:$(`focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:text-destructive not-data-[variant=destructive]:focus:**:text-accent-foreground gap-1.5 rounded-md px-1.5 py-1 text-sm data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4 group/dropdown-menu-item relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0`,e),...r})}function LH({className:e,...t}){return(0,Z.jsx)(Ej,{"data-slot":`dropdown-menu-separator`,className:$(`bg-border -mx-1 my-1 h-px`,e),...t})}var RH=(0,W.createContext)({hostBusy:!1,openInNewTab:void 0,showChecks:void 0}),zH=RH.Provider,BH=()=>(0,W.useContext)(RH);function VH({...e}){return(0,Z.jsx)(dP,{"data-slot":`alert-dialog`,...e})}function HH({container:e,...t}){let n=kz();return(0,Z.jsx)(hN,{"data-slot":`alert-dialog-portal`,container:e??n,...t})}function UH({className:e,...t}){return(0,Z.jsx)(oN,{"data-slot":`alert-dialog-overlay`,className:$(`data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs fixed inset-0 isolate z-50`,e),...t})}function WH({className:e,size:t=`default`,...n}){return(0,Z.jsxs)(HH,{children:[(0,Z.jsx)(UH,{}),(0,Z.jsx)(mN,{"data-slot":`alert-dialog-content`,"data-size":t,className:$(`data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 bg-popover text-popover-foreground ring-foreground/10 gap-4 rounded-xl p-4 ring-1 duration-100 data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 outline-none`,e),...n})]})}function GH({className:e,...t}){return(0,Z.jsx)(`div`,{"data-slot":`alert-dialog-header`,className:$(`grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]`,e),...t})}function KH({className:e,...t}){return(0,Z.jsx)(`div`,{"data-slot":`alert-dialog-footer`,className:$(`bg-muted/50 -mx-4 -mb-4 rounded-b-xl border-t p-4 flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end`,e),...t})}function qH({className:e,...t}){return(0,Z.jsx)(wN,{"data-slot":`alert-dialog-title`,className:$(`text-base font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2 font-heading`,e),...t})}function JH({className:e,...t}){return(0,Z.jsx)(cN,{"data-slot":`alert-dialog-description`,className:$(`text-muted-foreground *:[a]:hover:text-foreground text-sm text-balance md:text-pretty *:[a]:underline *:[a]:underline-offset-3`,e),...t})}function YH({className:e,variant:t=`outline`,size:n=`default`,...r}){return(0,Z.jsx)(sN,{"data-slot":`alert-dialog-cancel`,className:$(``,e),render:(0,Z.jsx)(aB,{variant:t,size:n}),...r})}function XH({...e}){return(0,Z.jsx)(yP,{"data-slot":`popover`,...e})}function ZH({...e}){return(0,Z.jsx)(SP,{"data-slot":`popover-trigger`,...e})}function QH({className:e,align:t=`center`,alignOffset:n=0,side:r=`bottom`,sideOffset:i=4,...a}){let o=kz();return(0,Z.jsx)(TP,{container:o,children:(0,Z.jsx)(OP,{align:t,alignOffset:n,side:r,sideOffset:i,className:`isolate z-50`,children:(0,Z.jsx)(jP,{"data-slot":`popover-content`,className:$(`bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 flex flex-col gap-2.5 rounded-lg p-2.5 text-sm shadow-md ring-1 duration-100 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 z-50 w-72 origin-(--transform-origin) outline-hidden`,e),...a})})})}var $H=e=>j(e,`reason`)&&typeof e.reason==`string`?e.reason:e instanceof Error?e.message:String(e),eU=e=>e.toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}),tU=`hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground relative flex w-full cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-left text-sm outline-none select-none`,nU=({children:e,testId:t})=>(0,Z.jsx)(`p`,{"data-testid":t,className:`text-muted-foreground px-1.5 py-2 text-[12.5px]`,children:e});function rU({testId:e,title:t,detail:n,marked:r,hint:i,onSelect:a}){return(0,Z.jsx)(`div`,{className:`group/row relative`,children:(0,Z.jsxs)(`button`,{type:`button`,"data-testid":e,"data-editor-control":``,onClick:a,className:tU,children:[(0,Z.jsx)(`span`,{className:`flex size-3.5 shrink-0 items-center justify-center`,children:r?(0,Z.jsx)(zR,{className:`size-3.5`}):null}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col items-start`,children:[(0,Z.jsx)(`span`,{className:`w-full truncate text-[13px]`,children:t}),(0,Z.jsx)(`span`,{className:`text-muted-foreground w-full truncate text-[11.5px]`,children:n})]}),i?(0,Z.jsx)(`span`,{"aria-hidden":!0,className:$(`text-muted-foreground pointer-events-none shrink-0 text-[11.5px]`,Dz),children:`Restore`}):null]})})}function iU(){let e=Q(e=>e.lifecycleCapability),t=Q(e=>e.doc!==null),n=Q(e=>e.editable),{beginLifecycle:r,endLifecycle:i,flushSaves:a,adoptLifecycleSnapshot:o}=Q(e=>e.actions),[s,c]=(0,W.useState)(!1),l=(0,W.useRef)(0),[u,d]=(0,W.useState)({status:`loading`}),[f,p]=(0,W.useState)(``),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(null),b=e?.status===`ready`?e.api:null;if(b===null||!t)return null;let x=u.status===`ready`?u.state:null,S=x?.dirty??!1,C=()=>{let e=++l.current;d({status:`loading`}),a().then(()=>b.inspect()).then(t=>{l.current===e&&d({status:`ready`,state:t})}).catch(t=>{l.current===e&&d({status:`failed`,message:$H(t)})})},w=e=>{c(e),e?(p(``),C()):l.current++},T=e=>{c(!1),x!==null&&(e.commit!==x.baseCommit||x.dirty)&&(y(null),h({commit:e.commit,message:e.message,blocked:x.dirty||x.conflicts.length>0}))},E=()=>{m===null||m.blocked||g||!n||r()&&(_(!0),y(null),a().then(async e=>{let t=await b.inspect();if(t.dirty||t.conflicts.length>0){d({status:`ready`,state:t}),h({...m,blocked:!0});return}o(await b.restore({commit:m.commit,baseRev:e})),h(null)}).catch(e=>y($H(e))).finally(()=>{i(),_(!1)}))},D=f.trim().toLowerCase(),O=x?.commits.filter(({message:e})=>e.toLowerCase().includes(D)),k=D===``||`latest`.includes(D);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(XH,{open:s,onOpenChange:w,children:[(0,Z.jsx)($B,{label:`Versions`,children:(0,Z.jsx)(ZH,{"data-slot":`editor-version-picker`,render:(0,Z.jsx)(aB,{variant:`ghost`,size:`sm`,"aria-label":`Versions`,"data-testid":`preview-bar.versions`,"data-editor-control":``,disabled:g,className:`text-muted-foreground shrink-0 gap-1 px-2`}),children:g?`Restoring…`:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 @max-[28rem]/preview-bar:hidden`,children:[`Latest`,(0,Z.jsx)(hR,{})]}),(0,Z.jsx)(VR,{className:`hidden size-3.5 @max-[28rem]/preview-bar:inline-flex`})]})})}),(0,Z.jsxs)(QH,{side:`bottom`,align:`start`,sideOffset:6,"data-testid":`preview-bar.versions-popup`,className:`w-72 gap-0 p-1`,children:[(0,Z.jsxs)(`label`,{className:`border-border flex items-center gap-2 border-b px-2 pb-1.5`,children:[(0,Z.jsx)(YR,{className:`text-muted-foreground size-3.5 shrink-0`}),(0,Z.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.currentTarget.value),placeholder:`Search versions`,"aria-label":`Search versions`,"data-testid":`preview-bar.versions-search`,"data-editor-control":``,className:`placeholder:text-muted-foreground h-7 w-full min-w-0 bg-transparent text-sm outline-none`})]}),(0,Z.jsxs)(`div`,{className:`samva-editor-scroll max-h-72 overflow-y-auto pt-1`,children:[u.status===`loading`?(0,Z.jsx)(nU,{children:`Loading versions…`}):null,u.status===`failed`?(0,Z.jsxs)(`div`,{className:`flex flex-col items-start gap-2 px-1.5 py-2`,children:[(0,Z.jsx)(`p`,{role:`alert`,className:`text-destructive text-sm`,children:u.message}),(0,Z.jsx)(aB,{variant:`outline`,size:`sm`,"data-testid":`preview-bar.versions-retry`,"data-editor-control":``,onClick:C,children:`Try again`})]}):null,x!==null&&O!==void 0?(0,Z.jsxs)(Z.Fragment,{children:[k?(0,Z.jsx)(rU,{testId:`preview-bar.version-latest`,title:`Latest`,detail:S?`Unsaved changes`:`Saved`,marked:!0,hint:!1,onSelect:()=>c(!1)}):null,O.map(e=>{let t=e.commit===x.baseCommit,n=[t?`Current`:null,eU(e.committedAt),e.isPublished?`Published`:null].filter(e=>e!==null).join(` · `);return(0,Z.jsx)(rU,{testId:`preview-bar.version.${e.commit}`,title:e.message,detail:n,marked:!1,hint:!(t&&!x.dirty),onSelect:()=>T(e)},e.commit)}),!k&&O.length===0?(0,Z.jsx)(nU,{testId:`preview-bar.versions-empty`,children:`No versions match`}):null]}):null]})]})]}),(0,Z.jsx)(VH,{open:m!==null,onOpenChange:e=>{!e&&!g&&h(null)},children:(0,Z.jsxs)(WH,{"data-testid":`preview-bar.restore-dialog`,children:[(0,Z.jsxs)(GH,{children:[(0,Z.jsx)(qH,{children:`Restore this version?`}),(0,Z.jsx)(JH,{children:`“${m?.message??``}” replaces the draft. Newer versions stay in the list, so you can restore them again.`}),n?null:(0,Z.jsx)(JH,{"data-testid":`preview-bar.restore-readonly`,children:`This template is read-only, so its versions can be viewed but not restored.`}),n&&m?.blocked?(0,Z.jsx)(JH,{children:`Save a version first, so your unsaved changes stay in the list.`}):null,v===null?null:(0,Z.jsx)(`p`,{role:`alert`,className:`text-destructive text-sm`,children:v})]}),(0,Z.jsxs)(KH,{children:[(0,Z.jsx)(YH,{"data-testid":`preview-bar.restore-cancel`,"data-editor-control":``,disabled:g,children:`Cancel`}),(0,Z.jsx)(aB,{"data-testid":`preview-bar.restore-confirm`,"data-editor-control":``,disabled:g||!n||m?.blocked===!0,onClick:E,children:g?`Restoring…`:`Restore`})]})]})})]})}var aU=[];function oU({testId:e,className:t}){let{fixtures:n,fixture:r,busy:i,available:a}=Q(kk(e=>({fixtures:e.doc?.fixtures??aU,fixture:e.doc?.fixture??null,busy:e.fixtureBusy,available:e.fixtureCapability?.status===`ready`}))),{viewFixture:o}=Q(e=>e.actions);return!a||r===null||n.length<2?null:(0,Z.jsx)($B,{label:`Sample data the preview shows`,children:(0,Z.jsx)(`span`,{"data-editor-control":``,className:`inline-flex min-w-0`,children:(0,Z.jsx)(vV,{size:`sm`,"aria-label":`Fixture`,"data-slot":`editor-fixture-select`,"data-testid":e,value:r,disabled:i,onChange:e=>o(e.target.value),className:$(`max-w-40 min-w-0 [&_select]:text-xs [&_select]:font-medium`,t),children:n.map(e=>(0,Z.jsx)(yV,{value:e,children:e},e))})})})}function sU(){let{sizeKb:e,sizeSource:t,deviceWidth:n,rendered:r}=Q(kk(e=>({sizeKb:e.sizeKb,sizeSource:e.sizeSource,deviceWidth:NL[e.previewDevice],rendered:e.render!==null})));return r?t===`sent`?{text:`${n} px · ${e} KB`,help:`Width shown, and the size of the email as sent`}:{text:`${n} px · ${e} KB preview`,help:`Width shown, and the size of this preview. The email as sent can be smaller.`}:{text:`${n} px`,help:`Width shown`}}function cU({viewMenu:e,...t}){let{device:n,working:r,canRefresh:i}=Q(kk(e=>({device:e.previewDevice,working:e.fixtureBusy||e.pendingAuthoredSource!==null||e.previewRefreshing,canRefresh:e.doc!==null&&e.pendingAuthoredSource===null&&!e.metadataSaving&&!e.conflict&&!e.lifecycleBusy}))),{setPreviewDevice:a,refreshPreview:o}=Q(e=>e.actions),{hostBusy:s,openInNewTab:c}=BH(),l=sU(),u=r||s;return dz(`editor-preview-bar`,{"data-testid":`preview-bar`,...t},{state:{busy:u},className:`border-border bg-background @container/preview-bar relative flex h-11 shrink-0 items-center gap-1.5 border-b px-2`,props:{children:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(iU,{}),(0,Z.jsxs)(`div`,{"data-slot":`editor-preview-bar-center`,className:`flex min-w-0 flex-1 items-center justify-center gap-1.5`,children:[(0,Z.jsx)(eV,{ariaLabel:`Preview width`,value:n,onChange:a,size:`sm`,options:[{value:`desktop`,title:`Desktop width`,testId:`canvas.device.desktop`,label:(0,Z.jsx)(kR,{className:`size-3.5`})},{value:`mobile`,title:`Phone width`,testId:`canvas.device.mobile`,label:(0,Z.jsx)(OR,{className:`size-3.5`})}]}),(0,Z.jsx)(oU,{testId:`preview-bar.fixture`})]}),(0,Z.jsx)(iV,{}),(0,Z.jsx)($B,{label:l.help,children:(0,Z.jsx)(`span`,{tabIndex:0,"data-slot":`editor-preview-bar-size`,"data-testid":`preview-bar.size`,className:`text-muted-foreground focus-visible:ring-ring/50 shrink-0 rounded-md px-1.5 text-xs leading-7 tabular-nums outline-none focus-visible:ring-3 @max-[28rem]/preview-bar:hidden`,children:l.text})}),c!==void 0&&(0,Z.jsx)(`span`,{className:`inline-flex @max-[28rem]/preview-bar:hidden`,children:(0,Z.jsx)($B,{label:`Open in a new tab`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Open in a new tab`,"data-testid":`preview-bar.open`,"data-editor-control":``,onClick:c,className:`text-muted-foreground`,children:(0,Z.jsx)(KR,{})})})}),(0,Z.jsx)($B,{label:i?`Refresh the preview`:`Refresh waits for your latest edit`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Refresh the preview`,"data-testid":`preview-bar.refresh`,"data-editor-control":``,disabled:!i,onClick:o,className:`text-muted-foreground`,children:(0,Z.jsx)(JR,{})})}),(0,Z.jsx)(`span`,{className:$(`inline-flex`,e===void 0&&`hidden @max-[28rem]/preview-bar:inline-flex`),children:(0,Z.jsxs)(jH,{children:[(0,Z.jsx)(MH,{render:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`More preview options`,"data-testid":`preview-bar.more`,"data-editor-control":``,className:`text-muted-foreground`}),children:(0,Z.jsx)(GR,{})}),(0,Z.jsxs)(NH,{align:`end`,className:`w-60`,children:[(0,Z.jsxs)(PH,{children:[(0,Z.jsx)(FH,{children:`Preview`}),(0,Z.jsx)(`div`,{className:`text-muted-foreground px-1.5 pb-1.5 text-xs tabular-nums`,children:l.text}),c!==void 0&&(0,Z.jsxs)(IH,{"data-editor-control":``,onClick:c,children:[(0,Z.jsx)(KR,{}),`Open in a new tab`]})]}),e!==void 0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(LH,{}),e]})]})]})}),u&&(0,Z.jsx)(`span`,{role:`progressbar`,"aria-label":`Updating the preview`,"data-slot":`editor-preview-bar-progress`,"data-testid":`preview-bar.progress`,className:`pointer-events-none absolute inset-x-0 -bottom-px h-0.5 overflow-hidden`,children:(0,Z.jsx)(`span`,{className:`samva-editor-progress bg-primary absolute inset-y-0 w-2/5`})})]})}})}function lU(){let{stale:e,fixtureError:t}=Q(kk(e=>({stale:e.doc?.channel===`email`&&e.doc.preview.status===`stale`?e.doc.preview.reason:null,fixtureError:e.fixtureError}))),{showChecks:n}=BH(),r=e===null?t:`Showing the last preview that worked. Your latest edit has a problem: ${e}`;return r===null?null:(0,Z.jsxs)(`div`,{role:`status`,"data-slot":`editor-preview-notice`,"data-testid":e===null?`canvas.fixture-error`:`canvas.preview-stale`,className:`border-status-warning/35 bg-status-warning/10 text-foreground flex min-h-9 shrink-0 items-center gap-2 border-b px-3 py-1.5 text-xs`,children:[(0,Z.jsx)(`span`,{className:`bg-status-warning size-1.5 shrink-0 rounded-full`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:r}),e!==null&&n!==void 0&&(0,Z.jsx)(aB,{variant:`outline`,size:`sm`,onClick:n,"data-testid":`canvas.preview-stale.checks`,"data-editor-control":``,className:`bg-background shrink-0`,children:`Show checks`})]})}function uU({embedded:e=!1}={}){let{checks:t,doc:n,readonlyReason:r,rightCollapsed:i,rightWidth:a}=Q(kk(e=>({checks:e.checks,doc:e.doc,readonlyReason:e.readonlyReason,rightCollapsed:e.rightCollapsed,rightWidth:e.rightWidth}))),{toggleRight:o}=Q(e=>e.actions);return!e&&i?null:(0,Z.jsxs)(`aside`,{"data-editor-rail":`right`,style:{width:e?`100%`:a},className:e?`bg-background flex h-full shrink-0 flex-col overflow-hidden`:`border-border bg-background flex h-full shrink-0 flex-col overflow-hidden border-l`,children:[(0,Z.jsxs)(`div`,{className:`border-border-subtle flex h-11 items-center border-b px-3`,children:[(0,Z.jsx)(`span`,{className:`text-[12.5px] font-medium`,children:`Template details`}),!e&&(0,Z.jsx)($B,{label:`Collapse inspector`,side:`bottom`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Collapse inspector`,onClick:o,className:`text-muted-foreground ml-auto`,children:(0,Z.jsx)(FR,{})})})]}),(0,Z.jsxs)(`div`,{className:`samva-editor-scroll min-h-0 flex-1 overflow-y-auto p-4 text-[12.5px]`,children:[(0,Z.jsx)(`p`,{className:`font-medium`,children:`Read-only`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-1`,children:r}),n!==null&&(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-3 font-mono text-[11.5px] break-all`,children:n.origin.file}),(0,Z.jsx)(`div`,{className:`border-border-subtle mt-5 border-t pt-4`,children:(0,Z.jsx)(hV,{checks:t})})]})]})}var dU=()=>typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform)?`⌘`:`Ctrl+`;function fU({percent:e,...t}){let n=Q(e=>e.canvasZoom===`fit`),{setCanvasZoom:r}=Q(e=>e.actions),i=dU(),a=Math.round(e);return dz(`editor-zoom-control`,{role:`group`,"aria-label":`Zoom`,"data-testid":`canvas.zoom-control`,...t},{state:{fit:n,percent:a},className:`bg-popover text-popover-foreground ring-foreground/10 absolute bottom-3 left-1/2 z-20 flex -translate-x-1/2 items-center gap-0.5 rounded-lg p-1 shadow-md ring-1`,props:{children:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($B,{label:`Zoom out`,shortcut:`${i}−`,side:`top`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Zoom out`,"data-testid":`canvas.zoom-out`,"data-editor-control":``,disabled:a<=50,onClick:()=>r(mB(e)),children:(0,Z.jsx)(WR,{})})}),(0,Z.jsx)($B,{label:`Actual size`,shortcut:`${i}0`,side:`top`,children:(0,Z.jsxs)(aB,{variant:`ghost`,size:`sm`,"aria-label":`Zoom ${a}%. Show at actual size`,"data-testid":`canvas.zoom-value`,"data-editor-control":``,onClick:()=>r(100),className:`min-w-13 px-1.5 font-normal tabular-nums`,children:[a,`%`]})}),(0,Z.jsx)($B,{label:`Zoom in`,shortcut:`${i}+`,side:`top`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Zoom in`,"data-testid":`canvas.zoom-in`,"data-editor-control":``,disabled:a>=200,onClick:()=>r(pB(e)),children:(0,Z.jsx)(qR,{})})}),(0,Z.jsx)(VB,{orientation:`vertical`,className:`mx-0.5 h-4!`}),(0,Z.jsx)($B,{label:`Fit the email to the pane`,side:`top`,children:(0,Z.jsx)(UB,{size:`sm`,pressed:n,onPressedChange:e=>{e&&r(`fit`)},"data-testid":`canvas.zoom`,"data-editor-control":``,className:`px-2 text-xs`,children:`Fit`})})]})}})}function pU({pointing:e=!1,active:t=!0,viewMenu:n,...r}){let{doc:i,render:a,outline:o,selection:s,previewDevice:c,canvasZoom:l,previewEpoch:u,canvasMode:d,beforeEdits:f,pins:p,sourceEditable:m}=Q(kk(e=>({doc:e.doc,render:e.render,outline:e.outline,selection:e.selection,previewDevice:e.previewDevice,canvasZoom:e.canvasZoom,previewEpoch:e.previewEpoch,canvasMode:e.canvasMode,beforeEdits:e.designCompare?e.designDraft?.baseRender??null:null,pins:e.pins,sourceEditable:e.sourceEditable}))),h=BI(),{select:g,selectDocument:_,setHovered:v,setCanvasZoom:y}=Q(e=>e.actions),b=Q(e=>e.hoveredCandidatePath===null?null:e.outline?.index.get(e.hoveredCandidatePath)??null),x=kz(),S=_z(`canvas.overlay`),C=(0,W.useRef)(null),[w,T]=(0,W.useState)(1),[E,D]=(0,W.useState)([]),[O,k]=(0,W.useState)(!1),[A,j]=(0,W.useState)(null),M=s.kind===`element`?o?.index.get(s.instancePath)??null:null,N=d===`design`,P=(0,W.useCallback)(e=>{let{canvasMode:t,actions:n,outline:r}=h.getState(),i=t===`point`||e===null||r===null?e:nL(r,e)?.instancePath??e;t===`pin`?i!==null&&n.addPin(i):n.select(i)},[h]),F=i?.channel===`email`?i.fixture:null,I=a?.revision??null,L=(0,W.useMemo)(()=>p.filter(e=>e.fixture===F&&e.revision===I).map(e=>({number:e.number,instancePath:e.instancePath})),[p,F,I]),R=c===`mobile`?375:600;(0,W.useLayoutEffect)(()=>{let e=C.current;if(e===null||typeof ResizeObserver>`u`)return;let t=()=>{let t=Math.max(240,e.clientWidth-80);T(Math.min(1,Math.max(.5,t/R)))};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[R]);let z=l===`fit`?w:l/100,B=z*100,ee=(0,W.useRef)(B);(0,W.useLayoutEffect)(()=>{ee.current=B},[B]);let te=(0,W.useCallback)(e=>{let t=ee.current;e.kind===`wheel`?y(hB(t,e.deltaY)):e.direction===`in`?y(pB(t)):e.direction===`out`?y(mB(t)):y(100)},[y]);(0,W.useEffect)(()=>{let e=C.current;if(e===null||!t)return;let n=e=>{_B(e)&&(e.preventDefault(),te({kind:`wheel`,deltaY:e.deltaY}))};return e.addEventListener(`wheel`,n,{passive:!1}),()=>e.removeEventListener(`wheel`,n)},[t,te]),(0,W.useEffect)(()=>{if(!t)return;let e=C.current?.closest(`[data-samva-editor-theme]`);if(e==null)return;let n=t=>{let n=gB(t);n!==null&&t.target instanceof Node&&e.contains(t.target)&&(t.preventDefault(),te({kind:`key`,direction:n}))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[t,te]);let ne=(0,W.useCallback)(t=>{if(e||h.getState().canvasMode===`pin`||o===null||t.instancePath===null){k(!1);return}let n=[...qI(o,t.instancePath),t.instancePath].toReversed().flatMap(e=>{let t=o.index.get(e);return t===void 0?[]:[{instancePath:e,label:HI(t),generated:!t.authored}]});if(n.length===0){k(!1);return}g(t.instancePath),D(n);let{clientX:r,clientY:i}=t;j({getBoundingClientRect:()=>DOMRect.fromRect({x:r,y:i})}),queueMicrotask(()=>k(!0))},[o,e,g,h]),V=f===null?a===null?null:(0,Z.jsx)(kB,{html:a.html,width:R,epoch:u,onSelect:P,onHover:v,onZoomGesture:t?te:void 0,onContextMenu:e?void 0:ne,overlay:(0,Z.jsx)(NB,{renderRevision:a.revision,selected:d===`pin`?null:M,hovered:b,toolbar:N&&M!==null?(0,Z.jsx)(sV,{selection:M}):void 0,pins:L})}):(0,Z.jsx)(kB,{html:f.html,width:R,epoch:u}),re=(0,Z.jsxs)(Z.Fragment,{children:[i!==null&&i.channel===`email`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(cU,{viewMenu:n}),(0,Z.jsx)(lU,{})]}),(0,Z.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{"data-canvas-mode":d,className:`samva-editor-workspace relative flex min-h-0 min-w-0 flex-1 flex-col`,children:[S.length>0&&(0,Z.jsx)(`div`,{"data-samva-canvas-status":!0,className:`pointer-events-none absolute inset-x-0 top-3 z-10 flex justify-center`,children:S.map(e=>(0,Z.jsx)(W.Fragment,{children:e.render()},e.id))}),(0,Z.jsx)(`div`,{ref:C,"data-samva-canvas-viewport":!0,className:$(`samva-editor-scroll relative flex-1 [scrollbar-gutter:stable] overflow-auto px-10 pt-10 pb-24 [overflow-anchor:none]`,(p.length>0||d===`pin`)&&`pb-64`),onClick:_,children:i===null?(0,Z.jsx)(`div`,{className:`text-muted-foreground grid h-full place-items-center text-[12.5px]`,children:`Loading document…`}):(0,Z.jsxs)(`div`,{className:`mx-auto`,"data-canvas-zoom":l===`fit`?`fit`:String(l),style:{width:R,zoom:z},onClick:e=>e.stopPropagation(),children:[(0,Z.jsx)(dV,{}),V===null?(0,Z.jsx)(mU,{}):e?V:(0,Z.jsx)(AH,{ancestors:E,onSelect:g,portalContainer:x,anchor:A??void 0,open:O,onOpenChange:e=>k(e&&E.length>0),children:V})]})}),f!==null&&(0,Z.jsx)(`div`,{"data-testid":`canvas.compare-badge`,className:`pointer-events-none absolute inset-x-0 top-3 z-10 flex justify-center`,children:(0,Z.jsx)(`span`,{className:`bg-popover text-popover-foreground ring-foreground/10 rounded-lg px-3 py-1 text-xs font-medium shadow-md ring-1`,children:`Before your edits`})}),i!==null&&(p.length>0||d===`pin`)&&(0,Z.jsx)(`div`,{className:$(`pointer-events-none absolute inset-x-0 z-20 flex flex-col items-center gap-2 px-3`,N?`bottom-16`:`bottom-15`),children:(0,Z.jsx)(oV,{})}),i!==null&&!N&&(0,Z.jsx)(fU,{percent:B}),i!==null&&N&&(0,Z.jsxs)(`div`,{"data-slot":`editor-design-bar`,className:`border-border bg-background @container/design-bar flex h-11 shrink-0 items-center justify-between gap-2 border-t px-2`,children:[(0,Z.jsx)(fU,{percent:B,className:`static translate-x-0 rounded-none bg-transparent p-0 shadow-none ring-0 @max-[34rem]/design-bar:hidden`}),(0,Z.jsx)(aV,{})]})]}),e&&N&&(0,Z.jsx)(`div`,{"data-slot":`editor-design-properties`,"data-testid":`canvas.design-properties`,className:`border-border hidden w-[300px] shrink-0 border-l @min-[44rem]/work-pane:flex`,children:m?(0,Z.jsx)(OH,{embedded:!0,checks:!1}):(0,Z.jsx)(uU,{embedded:!0})})]})]});return dz(`editor-canvas`,{...r},{state:{zoom:l===`fit`?`fit`:String(l),device:c},className:`flex min-h-0 min-w-0 flex-1 flex-col`,props:{children:re}})}function mU(){let e=Q(kk(e=>e.checks.filter(e=>e.severity===`error`))),t=e.length>0;return(0,Z.jsxs)(`div`,{"data-testid":`canvas.unbuilt`,"data-unbuilt-reason":t?`failed`:`not-built`,className:`border-border bg-surface-inset text-foreground rounded-xl border border-dashed p-6 text-[12.5px]`,children:[(0,Z.jsx)(`p`,{className:`font-medium`,children:t?`No preview`:`No preview yet`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-1`,children:t?`The current draft broke the preview. Fix the source and it will come back.`:`Nothing has run this entry yet. The next pass puts the preview here.`}),t&&(0,Z.jsx)(`ul`,{className:`mt-4 space-y-2`,children:e.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsx)(LB,{check:e,actions:(0,Z.jsx)(FB,{check:e})})},e.id))})]})}var hU={body:xR,div:CR,table:wR,tbody:wR,tr:wR,td:LR,th:LR,h1:TR,h2:TR,h3:TR,h4:TR,h5:TR,h6:TR,p:jR,span:jR,a:uz,button:mR,img:ER,hr:yR,br:fR,ul:pR,ol:pR,li:pR},gU=e=>hU[e.toLowerCase()]??CR,_U={Section:wR,Container:wR,Spacer:lz,Divider:cz,Button:mR,Columns:LR,Column:LR,Link:uz},vU=(e,t)=>_U[e]??gU(t),yU=(e,t)=>{let n=WI(e,t)?.replace(/\u200b|\u00ad|\u034f/g,``).trim();if(n===void 0||n===``)return;let r=n.length/2,i=n.slice(0,Math.floor(r)).trim();return i!==``&&n.slice(Math.ceil(r)).trim().startsWith(i.slice(0,12))?i:n};function bU({node:e,depth:t}){let{selectedPath:n,collapsedLayers:r,authoredSource:i,html:a}=Q(kk(e=>({selectedPath:e.selection.kind===`element`?e.selection.instancePath:null,collapsedLayers:e.collapsedLayers,authoredSource:e.doc?.origin.authoredSource??``,html:e.render?.html??``}))),{select:o,toggleLayerExpand:s,setHovered:c}=Q(e=>e.actions),l=e.children.length>0,u=!r.has(e.instancePath),d=n===e.instancePath,{selection:f}=e,p=XI(f,i),m=e.copies>1?`×${e.copies}`:void 0,h=l&&u?void 0:yU(f,a);return(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(`div`,{className:`group relative`,style:{paddingLeft:t*12},onMouseEnter:()=>c(e.instancePath),onMouseLeave:()=>c(null),children:(0,Z.jsxs)(`div`,{"data-slot":`editor-layer`,"data-selected":d||void 0,className:$(`flex h-[30px] w-full items-center gap-1.5 rounded-md pr-2 pl-1 text-left transition-colors`,d?`bg-muted text-foreground`:`text-foreground hover:bg-muted/60`),children:[l?(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-xs`,"aria-expanded":u,"data-testid":`left-rail.layer.toggle`,"aria-label":`${u?`Collapse`:`Expand`} ${p}`,className:$(`text-muted-foreground size-5 shrink-0 transition-transform hover:bg-transparent`,u&&`rotate-90`),onClick:t=>{t.stopPropagation(),s(e.instancePath)},children:(0,Z.jsx)(_R,{className:`size-3`})}):(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`size-5 shrink-0`}),(0,Z.jsxs)(aB,{variant:`ghost`,size:`sm`,"data-layer-instance-path":e.instancePath,"data-layer-name":p,"data-testid":`layers.node.${e.instancePath}`,onClick:()=>o(e.instancePath),className:`h-full min-w-0 flex-1 justify-start gap-2 rounded-md px-1 text-left font-normal hover:bg-transparent dark:hover:bg-transparent`,children:[(0,W.createElement)(vU(p,f.tag),{className:$(`size-[15px] shrink-0`,d?`text-foreground`:`text-muted-foreground`)}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[12.5px] font-medium`,children:p}),h!==void 0&&(0,Z.jsx)(`span`,{className:`text-muted-foreground min-w-0 flex-1 truncate text-[12px]`,children:h}),m!==void 0&&(0,Z.jsx)(`span`,{className:`text-muted-foreground ml-auto shrink-0 text-[11px] tabular-nums`,children:m})]})]})}),l&&u&&(0,Z.jsx)(`ul`,{className:`m-0 list-none p-0`,children:e.children.map(e=>(0,Z.jsx)(bU,{node:e,depth:t+1},e.instancePath))})]})}function xU(){let e=Q(e=>e.outline),t=(0,W.useMemo)(()=>e===null?[]:eL(e),[e]);if(e===null)return(0,Z.jsx)(`div`,{className:`text-placeholder px-3 py-8 text-center text-xs`,children:`There is no preview yet, so there are no layers to show.`});let n=t.length===1&&t[0]?.selection.tag===`html`?t[0].children:t;return(0,Z.jsx)(`ul`,{className:`m-0 list-none p-0`,children:n.map(e=>(0,Z.jsx)(bU,{node:e,depth:0},e.instancePath))})}function SU(){let{leftCollapsed:e,leftWidth:t,layoutMode:n}=Q(kk(e=>({leftCollapsed:e.leftCollapsed,leftWidth:e.leftWidth,layoutMode:e.layoutMode}))),{toggleLeft:r}=Q(e=>e.actions),i=n===`compact`||n===`narrow`;return(0,Z.jsx)(`aside`,{"aria-label":`Layers`,"aria-hidden":e||void 0,inert:e||void 0,"data-editor-rail":`left`,style:{width:e?0:t,maxWidth:i?`calc(100% - 48px)`:void 0},className:$(`flex h-full shrink-0 flex-col overflow-hidden border-r border-border bg-background transition-[width,transform,box-shadow] duration-180 ease-out`,i&&`absolute inset-y-0 left-0 z-40 shadow-[var(--shadow-floating)]`,e&&`border-r-0`),children:(0,Z.jsxs)(`div`,{className:`flex h-full min-w-0 flex-col`,style:{width:t,maxWidth:`100%`},children:[(0,Z.jsxs)(`div`,{className:`border-border-subtle flex items-center gap-0.5 border-b px-3 py-2`,children:[(0,Z.jsx)(`span`,{className:`text-foreground text-[12.5px] font-medium`,children:`Layers`}),(0,Z.jsx)($B,{label:`Collapse layers`,side:`bottom`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Collapse layers`,"data-testid":`left-rail.collapse`,onClick:r,className:`text-muted-foreground ml-auto`,children:(0,Z.jsx)(NR,{})})})]}),(0,Z.jsxs)(RM,{"data-samva-scroll-area":`layers`,className:`relative min-h-0 flex-1`,children:[(0,Z.jsx)(XM,{className:`size-full`,children:(0,Z.jsx)(`div`,{className:`px-2 pt-2.5 pb-5`,children:(0,Z.jsx)(xU,{})})}),(0,Z.jsx)(nN,{orientation:`vertical`,className:`absolute top-0 right-0 bottom-0 flex w-2.5 touch-none p-0.5 select-none`,children:(0,Z.jsx)(rN,{className:`relative flex-1 rounded-full bg-[var(--editor-scrollbar-thumb)] hover:bg-[var(--editor-scrollbar-thumb-hover)]`})})]})]})})}var CU=8,wU=24,TU=0,EU=1e4,DU={assistant:`Resize chat`,left:`Resize layers panel`,right:`Resize inspector`},OU={assistant:`agent-column.resize`,left:`left-rail.resize`,right:`inspector.resize`},kU=()=>{document.body.style.cursor=``,document.body.style.userSelect=``};function AU({side:e,...t}){let n=BI(),r=Q(t=>e===`assistant`?t.assistantWidth:e===`left`?t.leftWidth:t.rightWidth),{setAssistantWidth:i,setChatCollapsed:a,setLeftWidth:o,setRightWidth:s}=Q(e=>e.actions),c=(0,W.useRef)(!1),[l,u]=(0,W.useState)(!1),d=(0,W.useCallback)(()=>{c.current&&(c.current=!1,u(!1),kU())},[]);(0,W.useEffect)(()=>()=>{c.current&&kU()},[]);let f=t=>{if(e===`assistant`){let{chatCollapsed:e}=n.getState();if(t<140){a(!0);return}e&&a(!1),i(t)}else e===`left`?o(t):s(t)},p=e=>{(e.pointerType!==`mouse`||e.button===0)&&(e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),c.current=!0,u(!0),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`)},m=t=>{if(!c.current)return;let n=t.currentTarget.parentElement;if(n===null)return;let r=n.getBoundingClientRect();f(e===`right`?r.right-t.clientX:t.clientX-r.left)},h=t=>{let n=t.shiftKey?wU:CU,i=e===`right`?`ArrowLeft`:`ArrowRight`,a=e===`right`?`ArrowRight`:`ArrowLeft`,o;if(t.key===i)o=r+n;else if(t.key===a)o=r-n;else if(t.key===`Home`)o=e===`assistant`?280:TU;else if(t.key===`End`)o=e===`assistant`?640:EU;else return;t.preventDefault(),f(o)};return dz(`editor-divider`,{...t},{state:{side:e,dragging:l},className:$(`relative z-10 -mx-1.5 w-3 shrink-0 cursor-col-resize touch-none outline-none`,`before:absolute before:inset-y-0 before:left-1/2 before:w-px before:-translate-x-1/2 before:bg-border before:transition-colors`,`hover:before:w-0.5 hover:before:bg-accent-email`,`data-[dragging]:before:w-0.5 data-[dragging]:before:bg-accent-email`,`focus-visible:before:w-0.5 focus-visible:before:bg-accent-email`,Cz),props:{"data-editor-resize":e,role:`separator`,"aria-orientation":`vertical`,"aria-label":DU[e],"aria-valuenow":r,"aria-valuemin":e===`assistant`?280:void 0,"aria-valuemax":e===`assistant`?640:void 0,"data-testid":OU[e],tabIndex:0,onPointerDown:p,onPointerMove:m,onPointerUp:d,onPointerCancel:d,onLostPointerCapture:d,onKeyDown:h}})}var jU=(0,W.createContext)(null),MU=jU.Provider,NU=()=>{let e=(0,W.useContext)(jU);if(e===null)throw Error(`Editor chrome parts must be rendered inside EditorRoot`);return e};function PU(){let e=Q(e=>e.sourceEditable);return(0,Z.jsx)(`div`,{"data-slot":`editor-design-panel`,"data-testid":`design-panel`,className:`@container/design flex min-h-0 min-w-0 flex-1`,children:(0,Z.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col @min-[36rem]/design:flex-row`,children:[(0,Z.jsxs)(`section`,{"aria-label":`Layers`,"data-slot":`editor-layers`,className:`border-border flex max-h-[40%] min-h-0 shrink-0 flex-col border-b @min-[36rem]/design:max-h-none @min-[36rem]/design:w-72 @min-[36rem]/design:border-r @min-[36rem]/design:border-b-0`,children:[(0,Z.jsx)(`h2`,{className:`text-muted-foreground px-3 pt-3 pb-1 font-mono text-[10.5px] font-medium tracking-[0.08em] uppercase`,children:`Layers`}),(0,Z.jsxs)(RM,{"data-samva-scroll-area":`layers`,className:`relative min-h-0 flex-1`,children:[(0,Z.jsx)(XM,{className:`size-full`,children:(0,Z.jsx)(`div`,{className:`px-2 pb-4`,children:(0,Z.jsx)(xU,{})})}),(0,Z.jsx)(nN,{orientation:`vertical`,className:`absolute top-0 right-0 bottom-0 flex w-2.5 touch-none p-0.5 select-none`,children:(0,Z.jsx)(rN,{className:`relative flex-1 rounded-full bg-[var(--editor-scrollbar-thumb)] hover:bg-[var(--editor-scrollbar-thumb-hover)]`})})]})]}),(0,Z.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1`,children:e?(0,Z.jsx)(OH,{embedded:!0,checks:!1}):(0,Z.jsx)(uU,{embedded:!0})})]})})}var FU={preview:{label:`Preview`,hint:`The email`,Icon:SR},source:{label:`Source`,hint:`The template's code`,Icon:HR},design:{label:`Design`,hint:`Layers and properties`,Icon:DR},review:{label:`Review`,hint:`Changes to look over`,Icon:UR},checks:{label:`Checks`,hint:`Clients, size and links`,Icon:BR}};function IU(){let{errorCount:e,warnCount:t}=Q(kk(e=>{let t=OL(e.checks);return{errorCount:t.errorCount,warnCount:t.warnCount}})),n=e+t;return n===0?null:(0,Z.jsx)(zB,{variant:e>0?`destructive`:`secondary`,"data-testid":`work-pane.checks-badge`,className:`h-4 min-w-4 px-1 tabular-nums`,children:n})}function LU(){let e=Q(e=>e.workTabs),t=Q(e=>e.actions.openWorkTab),n=gz(`rail.review`)??null;return(0,Z.jsxs)(PH,{children:[(0,Z.jsx)(FH,{children:`Open a view`}),ML.filter(e=>e!==`review`||n!==null).map(n=>{let{label:r,hint:i,Icon:a}=FU[n];return(0,Z.jsxs)(IH,{"data-testid":`work-pane.add.${n}`,"data-editor-control":``,onClick:()=>t(n),className:`py-1.5`,children:[(0,Z.jsx)(a,{className:`text-muted-foreground`}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Z.jsx)(`span`,{children:r}),(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:i})]}),e.includes(n)&&(0,Z.jsx)(zR,{className:`text-muted-foreground`})]},n)})]})}var RU=$(iB({variant:`ghost`,size:`sm`}),`text-muted-foreground data-active:bg-muted data-active:text-foreground shrink-0 text-[13px]`);function zU({split:e,visible:t=!0,...n}){let{workTabs:r,activeWorkTab:i,chatCollapsed:a,narrow:o}=Q(kk(e=>({workTabs:e.workTabs,activeWorkTab:e.activeWorkTab,chatCollapsed:e.chatCollapsed,narrow:e.layoutMode===`narrow`}))),{openWorkTab:s,closeWorkTab:c,setChatCollapsed:l}=Q(e=>e.actions),u=gz(`rail.review`)??null,d=r.filter(e=>e!==`review`||u!==null),f=i!==`preview`&&!d.includes(i)?`preview`:i,p=a?`Show chat`:`Collapse chat`,m=o&&d.length===0;return dz(`editor-work-pane`,{"aria-label":`Work pane`,"data-testid":`work-pane`,...n},{state:{tab:f,split:e},tag:`section`,className:`bg-background @container/work-pane flex min-h-0 min-w-0 flex-1 flex-col`,props:{children:(0,Z.jsxs)(IP,{value:f,onValueChange:e=>{(e===`preview`||ML.some(t=>t===e))&&s(e)},className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[!m&&(0,Z.jsxs)(`div`,{"data-slot":`editor-work-pane-header`,className:`border-border flex h-11 shrink-0 items-center gap-1 border-b px-2`,children:[e&&(0,Z.jsx)($B,{label:p,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":p,"aria-pressed":a,"data-testid":`work-pane.toggle-chat`,"data-editor-control":``,onClick:()=>l(!a),className:`text-muted-foreground mr-0.5`,children:a?(0,Z.jsx)(MR,{}):(0,Z.jsx)(NR,{})})}),(0,Z.jsxs)(KP,{"data-slot":`editor-work-pane-tabs`,"aria-label":`Work pane views`,className:$(`samva-editor-scroll-hidden flex h-full min-w-0 items-center gap-1 overflow-x-auto`,o&&`px-2`),children:[(0,Z.jsxs)(VP,{value:`preview`,"data-slot":`editor-work-pane-tab`,"data-testid":`work-pane.tab.preview`,"data-editor-control":``,"aria-label":o?`Preview`:void 0,className:$(RU,o&&`px-2`),children:[(0,Z.jsx)(SR,{}),o?null:`Preview`]}),d.map(e=>{let{label:t,Icon:n}=FU[e];return(0,Z.jsxs)(`span`,{"data-slot":`editor-work-pane-tab-group`,className:`group/row relative inline-flex shrink-0 items-center`,children:[(0,Z.jsxs)(VP,{value:e,"data-slot":`editor-work-pane-tab`,"data-testid":`work-pane.tab.${e}`,"data-editor-control":``,"aria-label":o?t:void 0,className:$(RU,o?`px-2`:`pr-7`),children:[(0,Z.jsx)(n,{}),o?null:t,e===`review`&&u?.badge,e===`checks`&&(0,Z.jsx)(IU,{})]}),(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-xs`,"aria-label":`Close ${t}`,"data-slot":`editor-work-pane-tab-close`,"data-testid":`work-pane.close.${e}`,"data-editor-control":``,onClick:()=>c(e),className:$(`text-muted-foreground size-5 rounded-sm`,o?`relative`:`absolute right-1`,Dz,`group-has-[[data-active]]/row:opacity-100`),children:(0,Z.jsx)(RR,{className:`size-3`})})]},e)})]}),(0,Z.jsxs)(jH,{children:[(0,Z.jsx)($B,{label:`Add a view`,children:(0,Z.jsx)(MH,{"data-slot":`editor-work-pane-add`,render:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Add a view`,"data-testid":`work-pane.add`,"data-editor-control":``,className:`text-muted-foreground`}),children:(0,Z.jsx)(qR,{})})}),(0,Z.jsx)(NH,{"data-testid":`work-pane.add-menu`,className:`w-60`,children:(0,Z.jsx)(LU,{})})]})]}),(0,Z.jsx)(GP,{value:`preview`,keepMounted:!0,"data-slot":`editor-work-pane-panel`,"data-testid":`work-pane.panel.preview`,className:`flex min-h-0 min-w-0 flex-1 outline-none`,children:(0,Z.jsx)(pU,{pointing:!0,active:t&&f===`preview`,viewMenu:m?(0,Z.jsx)(LU,{}):void 0})}),f===`source`&&(0,Z.jsx)(GP,{value:`source`,"data-slot":`editor-work-pane-panel`,className:`flex min-h-0 min-w-0 flex-1 outline-none`,children:(0,Z.jsx)(jz,{})}),f===`design`&&(0,Z.jsx)(GP,{value:`design`,"data-slot":`editor-work-pane-panel`,className:`flex min-h-0 min-w-0 flex-1 outline-none`,children:(0,Z.jsx)(PU,{})}),f===`review`&&u!==null&&(0,Z.jsx)(GP,{value:`review`,"data-slot":`editor-work-pane-panel`,"data-testid":`work-pane.panel.review`,className:`samva-editor-scroll min-h-0 flex-1 overflow-y-auto px-4 pt-4 pb-6 outline-none`,children:u.content}),f===`checks`&&(0,Z.jsx)(GP,{value:`checks`,"data-slot":`editor-work-pane-panel`,"data-testid":`work-pane.panel.checks`,className:`samva-editor-scroll min-h-0 flex-1 overflow-y-auto outline-none`,children:(0,Z.jsx)(`div`,{className:`max-w-2xl px-4 pt-4 pb-8`,children:(0,Z.jsx)(_V,{})})})]})}})}function BU(){let e=Q(e=>e.sourceEditable),t=Q(e=>e.leftCollapsed),n=Q(e=>e.rightCollapsed),r=Q(e=>e.layoutMode),i=Q(e=>e.chatCollapsed),a=Q(e=>e.focusedPane),o=gz(`rail.assistant`)!==void 0,s=Q(e=>e.workspaceView),c=BI(),l=e=>c.setState({workspaceView:e}),{idBase:u}=NU();if(o){let e=r!==`wide`,t=e?a!==`assistant`:i;return(0,Z.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1`,"data-agent-workspace-layout":e?`focused`:`split`,children:[(0,Z.jsx)(`div`,{id:`${u}-pane-assistant`,role:e?`tabpanel`:void 0,"aria-labelledby":e?`${u}-tab-assistant`:void 0,hidden:t,className:$(!e&&`contents`,e&&`flex h-full min-h-0 min-w-0 flex-1`),children:(0,Z.jsx)(xz,{hidden:t})}),!e&&!i&&(0,Z.jsx)(AU,{side:`assistant`}),(0,Z.jsx)(`div`,{id:`${u}-pane-preview`,role:e?`tabpanel`:void 0,"aria-labelledby":e?`${u}-tab-preview`:void 0,hidden:e&&a!==`preview`,className:`flex min-h-0 min-w-0 flex-1`,children:(0,Z.jsx)(zU,{split:!e,visible:!e||a===`preview`})})]})})}return(0,Z.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,Z.jsx)(pH,{}),(0,Z.jsx)(Fz,{value:s,onChange:l,children:s===`source`?(0,Z.jsx)(jz,{}):(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1`,children:[(0,Z.jsx)(SU,{}),!t&&(0,Z.jsx)(AU,{side:`left`}),(0,Z.jsx)(pU,{}),!n&&(0,Z.jsx)(AU,{side:`right`}),e?(0,Z.jsx)(OH,{}):(0,Z.jsx)(uU,{})]})})]})}var VU=RegExp(`\\s${ac}="[^"]*"`,`g`),HU=e=>e.replace(VU,``),UU=e=>{let t=e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return t===``?`email`:t},WU=(e,t)=>{let n=new Blob([HU(e)],{type:`text/html;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${UU(t)}.html`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)},GU=`image/png,image/jpeg,image/gif,image/webp,.woff2`,KU=1048576,qU=(e,t)=>{let n=e?.lastIndexOf(`/`)??-1;return`${e===void 0||n<0?``:e.slice(0,n+1)}assets/${t}`},JU=e=>{let t=e.lastIndexOf(`.`);return t>e.lastIndexOf(`/`)?e.slice(t):``},YU=e=>j(e,`_tag`)&&e._tag===`ProjectFileExists`,XU=e=>j(e,`reason`)&&typeof e.reason==`string`?e.reason:`The template project operation failed.`,ZU=e=>e.isPublished?`Published`:e.isHead?`Current saved version`:`Saved version`;function QU({file:e,content:t,busy:n,onChange:r,onApply:i,onReplace:a}){let o=e.status===`conflicted`;return(0,Z.jsxs)(`div`,{className:`border-border space-y-3 rounded-lg border p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`h4`,{className:`truncate font-mono text-xs font-semibold`,children:e.path}),(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:e.status})]}),e.binary===!0?(0,Z.jsx)(`div`,{className:`space-y-3`,"data-testid":`lifecycle-sheet.binary-file`,children:e.status===`deleted`?(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Removed from the draft. Save a version to keep this change.`}):(0,Z.jsxs)(Z.Fragment,{children:[(e.status===`added`||e.status===`modified`)&&(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Unsaved until you save a version.`}),(0,Z.jsx)(`button`,{type:`button`,disabled:n,"data-testid":`lifecycle-sheet.replace-file`,onClick:a,className:$(`border-border hover:bg-muted rounded-md border px-3 py-2 text-xs disabled:opacity-50`,Cz),children:`Replace file`})]})}):o?(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Resolve this file below before editing its workspace source.`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`textarea`,{"aria-label":`Project source for ${e.path}`,"data-testid":`lifecycle-sheet.file-source.${e.path}`,value:t,onChange:e=>r(e.target.value),disabled:n,spellCheck:!1,className:`border-border bg-surface-inset text-foreground min-h-52 w-full resize-y rounded-md border p-3 font-mono text-xs outline-none disabled:opacity-60`}),(0,Z.jsx)(`button`,{type:`button`,disabled:n||t===e.content,"data-testid":`lifecycle-sheet.apply-file.${e.path}`,onClick:()=>i(t),className:$(`bg-primary text-primary-foreground rounded-md px-3 py-2 text-xs font-medium disabled:opacity-50`,Cz),children:`Apply file`})]})]})}function $U({conflict:e,busy:t,onResolve:n}){let[r,i]=(0,W.useState)(e.draft??e.main??``);return(0,Z.jsxs)(`article`,{className:`border-status-warning/45 space-y-3 rounded-lg border p-4`,children:[(0,Z.jsx)(`h4`,{className:`font-mono text-xs font-semibold`,children:e.path}),(0,Z.jsxs)(`details`,{className:`border-border rounded-md border`,children:[(0,Z.jsx)(`summary`,{className:`hover:bg-muted cursor-pointer px-3 py-2 text-xs font-medium`,children:`Compare base, draft, and main`}),(0,Z.jsx)(`div`,{className:`divide-border border-border divide-y border-t`,children:[[`Base`,e.base],[`Draft`,e.draft],[`Latest saved version`,e.main]].map(([e,t])=>(0,Z.jsxs)(`div`,{className:`space-y-1 p-3`,children:[(0,Z.jsx)(`p`,{className:`text-muted-foreground text-[11px] font-medium`,children:e}),(0,Z.jsx)(`pre`,{className:`samva-editor-scroll max-h-32 overflow-auto font-mono text-xs whitespace-pre-wrap`,children:t??`File does not exist`})]},e))})]}),(0,Z.jsx)(`textarea`,{"aria-label":`Resolved source for ${e.path}`,"data-testid":`lifecycle-sheet.conflict-source.${e.path}`,value:r,onChange:e=>i(e.target.value),spellCheck:!1,className:`border-border bg-surface-inset text-foreground min-h-40 w-full resize-y rounded-md border p-3 font-mono text-xs outline-none`}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>n(`draft`),"data-testid":`lifecycle-sheet.keep-draft`,className:$(`border-border hover:bg-muted rounded-md border px-3 py-2 text-xs`,Cz),children:`Keep draft`}),(0,Z.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>n(`main`),className:$(`border-border hover:bg-muted rounded-md border px-3 py-2 text-xs`,Cz),children:`Use saved version`}),(0,Z.jsx)(`button`,{type:`button`,disabled:t,"data-testid":`lifecycle-sheet.resolve-edited.${e.path}`,onClick:()=>n({content:r}),className:$(`bg-primary text-primary-foreground rounded-md px-3 py-2 text-xs font-medium`,Cz),children:`Use edited source`})]})]})}function eW({open:e,onClose:t,onLockedAction:n}){return e?(0,Z.jsx)(tW,{onClose:t,onLockedAction:n}):null}function tW({onClose:e,onLockedAction:t}){let n=kz(),r=Q(e=>e.doc),i=Q(e=>e.lifecycleCapability),{beginLifecycle:a,endLifecycle:o,flushSaves:s,adoptLifecycleSnapshot:c}=Q(e=>e.actions),l=r!==null&&i?.status===`ready`,[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)({}),[v,y]=(0,W.useState)(()=>l?`loading`:null),b=(0,W.useRef)(null),x=(0,W.useRef)(null),[S,C]=(0,W.useState)(null),[w,T]=(0,W.useState)(null),[E,D]=(0,W.useState)(null),[O,k]=(0,W.useState)(l);if(l!==O&&(k(l),l&&(y(`loading`),d(null),T(null),D(null),p(null),h(null),_({}),C(null))),(0,W.useEffect)(()=>{if(i?.status!==`ready`)return;let e=!1;return s().then(()=>i.api.inspect()).then(t=>{if(e)return;d(t);let n=r?.origin.kind===`tsx`?r.origin.file:void 0;h(e=>e!==null&&t.files.some(({path:t})=>t===e)?e:n!==void 0&&t.files.some(({path:e})=>e===n)?n:t.files[0]?.path??null)}).catch(t=>{e||T(XU(t))}).finally(()=>{e||y(null)}),()=>{e=!0}},[r,s,i]),i===void 0)return null;if(i.status===`locked`)return(0,Z.jsx)(SN,{open:!0,onOpenChange:t=>!t&&e(),children:(0,Z.jsxs)(hN,{container:n,children:[(0,Z.jsx)(oN,{className:`fixed inset-0 z-[110] bg-[var(--editor-backdrop,rgb(0_0_0/0.28))]`}),(0,Z.jsx)(CN,{className:`fixed inset-0 z-[111] grid place-items-center p-4`,children:(0,Z.jsxs)(mN,{className:`border-border bg-popover w-full max-w-lg rounded-xl border p-5 shadow-[var(--shadow-floating)]`,children:[(0,Z.jsx)(wN,{className:`text-base font-semibold`,children:`Publishing is unavailable`}),(0,Z.jsx)(cN,{className:`text-muted-foreground mt-2 text-sm`,"data-testid":`lifecycle-sheet.locked-reason`,children:i.upsell.reason}),(0,Z.jsx)(`a`,{"data-testid":`lifecycle-sheet.upsell-cta`,className:$(`bg-primary text-primary-foreground mt-4 inline-flex rounded-md px-3 py-2 text-sm font-medium`,Cz),href:i.upsell.cta.href,onClick:e=>{t!==void 0&&(e.preventDefault(),t())},children:i.upsell.cta.label}),(0,Z.jsx)(sN,{className:$(`border-border hover:bg-muted mt-4 ml-2 inline-flex rounded-md border px-3 py-2 text-sm font-medium`,Cz),children:`Close`})]})})]})});let A=u?.commits.find(({commit:e})=>e===f),j=u?.files.find(({path:e})=>e===m),M=j?.content??``,N=j===void 0?void 0:g[j.path],P=N?.baseContent===M?N.content:M,F=u?.files.some(e=>{let t=g[e.path],n=e.content??``;return t?.baseContent===n&&t.content!==n})??!1,I=u!==null&&!u.dirty&&u.conflicts.length===0&&!F,L=u?.commits.find(({commit:e})=>e===u.baseCommit),R=I&&u?.baseCommit===u.remoteHead,z=async()=>d(await i.api.inspect()),B=()=>{u!==null&&R&&v===null&&a()&&(y(`publish`),T(null),i.api.publish({baseRev:u.rev,commit:u.baseCommit}).then(async()=>{await z(),D(`Published the current saved version.`)}).catch(e=>T(XU(e))).finally(()=>{o(),y(null)}))},ee=()=>{u!==null&&A!==void 0&&!A.isHead&&I&&v===null&&a()&&(y(`restore`),T(null),s().then(e=>i.api.restore({commit:A.commit,baseRev:e})).then(async e=>{c(e),await z(),p(null),D(`Restored the saved version to the draft. Save a version to keep this restore.`)}).catch(e=>T(XU(e))).finally(()=>{o(),y(null)}))},te=(e,t)=>{u!==null&&v===null&&a()&&(y(`resolve`),T(null),s().then(n=>i.api.resolveConflict({path:e.path,baseRev:n,resolution:t})).then(t=>{d(t),D(`Resolved ${e.path}.`)}).catch(e=>T(XU(e))).finally(()=>{o(),y(null)}))},ne=(e,t)=>{u!==null&&v===null&&(y(`file`),T(null),i.api.updateFile({path:e.path,baseRev:u.rev,content:t}).then(t=>{d(t),_(t=>{let{[e.path]:n,...r}=t;return r}),D(`Updated ${e.path}.`)}).catch(e=>T(XU(e))).finally(()=>y(null)))},V=(e,t,n)=>{u!==null&&v===null&&(y(`file`),T(null),D(null),C(null),i.api.putAsset({path:e,baseRev:u.rev,bytes:t,replace:n}).then(t=>{d(t),h(e),D(`${n?`Replaced`:`Added`} ${e}. Save a version to keep this change.`)}).catch(n=>{YU(n)?C({path:e,bytes:t}):T(XU(n))}).finally(()=>y(null)))},re=e=>{let t=b.current;t!==null&&(x.current=e===null?null:{replacePath:e},t.accept=e===null?GU:JU(e),t.value=``,t.click())},ie=e=>{let t=x.current;if(x.current=null,e===void 0||u===null)return;if(e.size>KU){D(null),T(`${e.name} is larger than 1 MB. Choose a smaller file.`);return}let n=r?.origin.kind===`tsx`?r.origin.file:void 0,i=t?.replacePath??qU(n,e.name);e.arrayBuffer().then(e=>{let n=new Uint8Array(e);if(t===null&&u.files.some(e=>e.path===i)){T(null),D(null),C({path:i,bytes:n});return}V(i,n,t!==null)}).catch(e=>T(XU(e)))};return(0,Z.jsx)(OF,{open:!0,onOpenChange:t=>!t&&e(),swipeDirection:`right`,children:(0,Z.jsxs)(TF,{container:n,children:[(0,Z.jsx)(tF,{className:`fixed inset-0 z-[110] bg-[var(--editor-backdrop,rgb(0_0_0/0.28))]`}),(0,Z.jsx)(pI,{className:`pointer-events-none fixed inset-0 z-[111] flex justify-end`,children:(0,Z.jsxs)(wF,{className:`border-border bg-popover pointer-events-auto flex h-full w-full max-w-2xl flex-col border-l shadow-[var(--shadow-floating)]`,children:[(0,Z.jsxs)(`header`,{className:`border-border flex items-center justify-between border-b px-5 py-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(XF,{className:`text-base font-semibold`,children:`Publish and saved versions`}),(0,Z.jsx)(iF,{className:`text-muted-foreground mt-0.5 text-xs`,children:`Save keeps a named version. Restore brings an older version into your draft.`})]}),(0,Z.jsx)(nF,{"data-testid":`lifecycle-sheet.close`,className:$(`hover:bg-muted rounded-md px-2 py-1 text-sm`,Cz),children:`Close`})]}),(0,Z.jsxs)(`div`,{className:`samva-editor-scroll min-h-0 flex-1 space-y-6 overflow-y-auto p-5`,children:[v===`loading`&&(0,Z.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Loading saved versions…`}),w!==null&&(0,Z.jsx)(`p`,{className:`text-status-error text-sm`,role:`alert`,children:w}),E!==null&&(0,Z.jsx)(`p`,{className:`text-status-success text-sm`,role:`status`,"data-testid":`lifecycle-sheet.notice`,children:E}),u!==null&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`section`,{className:`border-border bg-muted/30 space-y-3 rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Current saved version`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:L?.message??`Current saved version`})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:B,disabled:!R||v!==null,"data-testid":`lifecycle-sheet.confirm-publish`,className:$(`bg-primary text-primary-foreground rounded-md px-3 py-2 text-sm font-medium disabled:opacity-50`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:v===`publish`?`Publishing…`:`Publish saved version`})]}),!I&&(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,"data-testid":`lifecycle-sheet.cleanliness-warning`,children:u.conflicts.length>0?`Resolve workspace conflicts before Save or Publish.`:`The draft has unsaved changes. Save a version before publishing or restoring.`}),I&&u.baseCommit!==u.remoteHead&&(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`The saved version changed elsewhere. Refresh before publishing.`})]}),(0,Z.jsxs)(`section`,{className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Project files`}),(0,Z.jsx)(`button`,{type:`button`,disabled:v!==null,"data-testid":`lifecycle-sheet.add-file`,onClick:()=>re(null),className:$(`border-border hover:bg-muted rounded-md border px-3 py-1.5 text-xs disabled:opacity-50`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:`Add file`}),(0,Z.jsx)(`input`,{ref:b,type:`file`,accept:GU,hidden:!0,"data-testid":`lifecycle-sheet.add-file-input`,onChange:e=>ie(e.target.files?.[0])})]}),(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Add PNG, JPEG, GIF, or WebP images and WOFF2 fonts up to 1 MB.`}),S!==null&&(0,Z.jsxs)(`div`,{className:`border-status-warning/45 space-y-3 rounded-lg border p-3`,"data-testid":`lifecycle-sheet.replace-prompt`,children:[(0,Z.jsxs)(`p`,{className:`text-xs`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:S.path}),` already exists. Replace it with the file you chose?`]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:v!==null,"data-testid":`lifecycle-sheet.confirm-replace`,onClick:()=>V(S.path,S.bytes,!0),className:$(`bg-primary text-primary-foreground rounded-md px-3 py-2 text-xs font-medium disabled:opacity-50`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:`Replace file`}),(0,Z.jsx)(`button`,{type:`button`,disabled:v!==null,onClick:()=>C(null),className:$(`border-border hover:bg-muted rounded-md border px-3 py-2 text-xs`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:`Cancel`})]})]}),(0,Z.jsx)(`div`,{className:`border-border divide-border divide-y rounded-lg border`,children:u.files.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`lifecycle-sheet.file.${e.path}`,onClick:()=>h(e.path),className:$(`hover:bg-muted flex w-full items-center justify-between gap-4 px-3 py-2 text-left`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`,m===e.path&&`bg-muted`),children:[(0,Z.jsx)(`span`,{className:`truncate font-mono text-xs`,children:e.path}),(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:e.status})]},e.path))}),j!==void 0&&(0,Z.jsx)(QU,{file:j,content:P,busy:v!==null,onChange:e=>_(t=>{if(e===M){let{[j.path]:e,...n}=t;return n}return{...t,[j.path]:{baseContent:M,content:e}}}),onApply:e=>ne(j,e),onReplace:()=>re(j.path)},`${j.path}:${j.content??``}`)]}),u.conflicts.length>0&&(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Resolve conflicts`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:`Choose either side or edit the final file. Save remains blocked until every path is resolved.`})]}),u.conflicts.map(e=>(0,Z.jsx)($U,{conflict:e,busy:v!==null,onResolve:t=>te(e,t)},e.path))]}),(0,Z.jsxs)(`section`,{className:`space-y-2`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Saved versions`}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:u.commits.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`lifecycle-sheet.commit.${e.commit}`,onClick:()=>p(e.commit),className:$(`border-border hover:bg-muted flex w-full items-start justify-between gap-4 rounded-lg border p-3 text-left`,f===e.commit&&`ring-primary ring-2`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:[(0,Z.jsxs)(`span`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.message}),(0,Z.jsx)(`span`,{className:`text-muted-foreground mt-1 block text-xs`,children:e.committedAt.toLocaleString()})]}),(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:ZU(e)})]},e.commit))})]}),A!==void 0&&!A.isHead&&(0,Z.jsxs)(`section`,{className:`border-border space-y-3 rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Restore saved version`}),(0,Z.jsxs)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:[`Bring “`,A.message,`” into the current draft. Save a version when you want to keep the restored draft.`]})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:ee,disabled:!I||v!==null,"data-testid":`lifecycle-sheet.restore`,className:$(`border-border hover:bg-muted rounded-md border px-3 py-2 text-sm`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:v===`restore`?`Restoring…`:`Restore this version`})]})]})]})]})})]})})}function nW({container:e,children:t}){return(0,Z.jsx)(Oz,{value:e,children:t})}var rW={desktop:600,mobile:375},iW=`▤`,aW=`Copy code`;function oW({open:e,onClose:t}){return e?(0,Z.jsx)(sW,{onClose:t}):null}function sW({onClose:e}){let t=kz(),{doc:n,render:r,checks:i,previewDevice:a}=Q(kk(e=>({doc:e.doc,render:e.render,checks:e.checks,previewDevice:e.previewDevice}))),[o,s]=(0,W.useState)(`preview`),[c,l]=(0,W.useState)(a),[u,d]=(0,W.useState)(`light`),[f,p]=(0,W.useState)(n?.channel);n?.channel!==f&&(p(n?.channel),s(`preview`));let[m,h]=(0,W.useState)(a);if(a!==m&&(h(a),s(`preview`),l(a),d(`light`)),n===null)return null;let g=n.metadata.fromDefault,_=(e,t)=>({value:e,label:t,testId:`preview-overlay.view.${e}`}),v=n.channel===`email`?[_(`preview`,`Preview`),_(`html`,`HTML`),_(`text`,`Text`),_(`source`,`TSX`)]:n.channel===`sms`?[_(`preview`,`Preview`),_(`text`,`Text`),_(`source`,`TSX`)]:[_(`preview`,`Preview`),_(`payload`,`Payload`),_(`source`,`TSX`)],y=o===`source`?n.origin.authoredSource:o===`html`&&r!==null?r.html:o===`text`&&r!==null?r.text:o===`text`&&n.channel===`sms`&&n.render!==null?n.render.text:o===`payload`&&n.channel===`whatsapp`&&n.render!==null?JSON.stringify(n.render,null,2):``;return(0,Z.jsx)(SN,{open:!0,onOpenChange:t=>!t&&e(),children:(0,Z.jsx)(hN,{container:t,children:(0,Z.jsxs)(mN,{className:`samva-editor-shell fixed inset-0 z-[100] flex flex-col bg-[var(--editor-canvas-bg)] outline-none`,children:[(0,Z.jsx)(wN,{className:`sr-only`,children:`Template preview`}),(0,Z.jsx)(cN,{className:`sr-only`,children:`Preview the rendered template and inspect its generated output.`}),(0,Z.jsxs)(`div`,{"data-testid":`preview-overlay.toolbar`,className:`border-border-subtle flex shrink-0 flex-wrap items-center gap-2 border-b px-3 py-2.5 sm:gap-2.5 sm:px-4`,children:[(0,Z.jsx)(`span`,{className:`text-[13px] font-semibold`,children:`Preview`}),(0,Z.jsx)(`span`,{className:`text-muted-foreground hidden text-xs sm:inline`,children:`rendered message, exactly what ships`}),(0,Z.jsx)(eV,{ariaLabel:`Preview format`,testId:`preview-overlay.format-group`,value:o,onChange:e=>s(e),options:v}),(0,Z.jsx)(`span`,{className:`hidden flex-1 sm:block`}),n.channel===`email`&&o===`preview`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(eV,{ariaLabel:`Preview width`,testId:`preview-overlay.width-group`,value:c,onChange:e=>l(e),options:[{value:`desktop`,label:`Desktop`,testId:`preview-overlay.device.desktop`},{value:`mobile`,label:`Mobile`,testId:`preview-overlay.device.mobile`}]}),(0,Z.jsx)(eV,{ariaLabel:`Preview color scheme`,testId:`preview-overlay.color-scheme-group`,value:u,onChange:e=>d(e),options:[{value:`light`,label:`Light`,testId:`preview-overlay.scheme.light`},{value:`dark`,label:`Dark`,testId:`preview-overlay.scheme.dark`}]}),(0,Z.jsx)(gV,{checks:i})]}),(0,Z.jsxs)(sN,{"data-testid":`preview-overlay.close`,className:`border-border text-foreground hover:bg-muted focus-visible:border-ring focus-visible:ring-ring/50 ml-auto inline-flex h-[30px] items-center gap-1.5 rounded-[7px] border px-2.5 outline-none focus-visible:ring-[3px]`,children:[`Close`,(0,Z.jsx)(`kbd`,{className:`text-muted-foreground text-[10px]`,children:`⎋`})]})]}),o===`preview`?n.channel===`email`?(0,Z.jsxs)(`div`,{className:`samva-editor-scroll flex-1 overflow-auto px-6 pt-3 pb-12`,children:[(0,Z.jsxs)(`div`,{"data-testid":`preview-overlay.device-frame`,className:$(`mx-auto mb-3.5 max-w-full truncate text-[12.5px] text-muted-foreground transition-[width] duration-180`,c===`mobile`?`w-[375px]`:`w-[600px]`),children:[g!==void 0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`b`,{className:`text-foreground font-semibold`,children:g.name??g.email}),g.name===void 0?null:(0,Z.jsxs)(Z.Fragment,{children:[` <`,g.email,`>`]}),` ·`,` `]}),(0,Z.jsx)(`b`,{className:`text-foreground font-semibold`,children:r?.subject??``}),r?.preheader!==void 0&&(0,Z.jsxs)(`span`,{className:`opacity-70`,children:[` — `,r.preheader]})]}),(0,Z.jsx)(`div`,{className:$(`mx-auto h-[calc(100%-2rem)] max-w-full transition-[width] duration-180 ease-out`,c===`mobile`?`w-[375px]`:`w-[600px]`),children:r===null?(0,Z.jsx)(`pre`,{className:`border-status-error/40 bg-background text-status-error rounded-lg border p-4 font-mono text-xs whitespace-pre-wrap`,children:`The current draft did not build, so there is nothing to preview.`}):(0,Z.jsx)(kB,{html:r.html,width:rW[c],forceColorScheme:u})})]}):(0,Z.jsx)(`div`,{className:`samva-editor-scroll flex-1 overflow-auto p-8`,children:(0,Z.jsx)(`div`,{className:`border-border bg-background mx-auto max-w-[460px] rounded-[28px] border p-5 shadow-[var(--shadow-lg)]`,children:n.channel===`sms`&&n.render!==null?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{"data-testid":`preview-overlay.sms-body`,className:`bg-muted rounded-[18px] px-4 py-3 text-[14px] whitespace-pre-wrap`,children:n.render.text}),(0,Z.jsx)(Vz,{text:n.render.text,className:`mt-4 text-center text-xs`})]}):n.channel===`whatsapp`&&n.render!==null?(0,Z.jsxs)(`div`,{className:`bg-surface-inset rounded-xl p-3.5`,children:[n.render.header!==void 0&&n.render.header.text!==``&&(0,Z.jsx)(`p`,{className:`mb-1 font-semibold`,children:n.render.header.text}),(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap`,children:n.render.body}),n.render.footer!==void 0&&n.render.footer!==``&&(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-2 text-xs`,children:n.render.footer}),n.render.buttons.map((e,t)=>(0,Z.jsx)(`div`,{className:`border-border-subtle text-accent-email mt-2 border-t pt-2 text-center text-xs`,children:e.type===`copy-code`?aW:e.type===`flow`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`span`,{"aria-hidden":`true`,children:[iW,` `]}),e.text]}):e.text},`${e.type}-${t}`))]}):(0,Z.jsx)(`pre`,{className:`text-status-error whitespace-pre-wrap`,children:`The current draft did not build, so there is nothing to preview.`})})}):(0,Z.jsx)(`div`,{className:`samva-editor-scroll flex-1 overflow-auto p-6`,children:(0,Z.jsx)(`pre`,{className:`border-border bg-background text-foreground mx-auto min-h-full max-w-[1100px] rounded-lg border p-5 font-mono text-[12px] leading-5 whitespace-pre-wrap`,children:y})})]})})})}function cW({saveVersionStatus:e,saveVersionState:t,onSaveVersion:n,saveVersionBusy:r,saveVersionBlocked:i,guestHeadline:a,part:o}){let{doc:s,checks:c,sizeKb:l,layoutMode:u,assistantWidth:d,chatCollapsed:f}=Q(kk(e=>({doc:e.doc,checks:e.checks,sizeKb:e.sizeKb,layoutMode:e.layoutMode,assistantWidth:e.assistantWidth,chatCollapsed:e.chatCollapsed}))),p=gz(`rail.assistant`)!==void 0,{selectDocument:m}=Q(e=>e.actions),h=Q(e=>e.sourceEditable),g=Q(e=>e.pendingAuthoredSource),_=Q(kk(e=>({storageError:e.storageError,conflict:e.conflict}))),[v,y]=(0,W.useState)(!1),{errorCount:b,warnCount:x}=OL(c),S=u===`narrow`,C=p&&u===`wide`&&!f,w=c.filter(e=>e.diagnostics?.some(e=>e.compatibility?.assessment===`unverified`)).length,T=`No known risks found`;w>0&&(T=`No known risks · ${w} need verification`),x>0&&(T=`${x} warning${x>1?`s`:``}`),b>0&&(T=`${b} check${b>1?`s`:``} failing`),c.length===0&&(T=`No checks yet`);let E=t===`error`||_.storageError!==null||_.conflict?`Couldn't save version`:g!==null||r===!0?`Saving…`:void 0;return dz(`editor-status-bar`,{...o},{state:{layout:u,save:t??`unavailable`},tag:`footer`,className:`border-border bg-background text-muted-foreground z-30 flex h-8 shrink-0 items-stretch border-t text-xs whitespace-nowrap`,props:{children:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{"data-slot":`editor-status-bar-start`,style:C?{width:d}:void 0,className:$(`flex min-w-0 shrink-0 items-center gap-3 px-2`,C&&`pr-3`),children:[(0,Z.jsxs)(XH,{open:v,onOpenChange:y,children:[(0,Z.jsxs)(ZH,{render:(0,Z.jsx)(aB,{variant:`ghost`,size:`xs`,"data-testid":`statusbar.checks-trigger`,"data-editor-control":``,"aria-label":S?T:void 0,onClick:()=>m(),className:`text-muted-foreground font-normal`}),children:[(0,Z.jsx)(`span`,{className:$(`size-1.5 shrink-0 rounded-full`,b>0?`bg-status-error`:x>0?`bg-status-warning`:`bg-muted-foreground`)}),a===void 0&&!S?T:null]}),(0,Z.jsx)(QH,{side:`top`,align:`start`,sideOffset:8,"data-testid":`statusbar.checks-popup`,className:`max-h-[min(560px,70vh)] w-[360px] overflow-y-auto p-3.5`,children:(0,Z.jsx)(hV,{checks:c,editable:h})})]}),a===void 0?!S&&(0,Z.jsx)(`span`,{children:s===null?`Loading…`:`Draft`}):(0,Z.jsx)(`span`,{"data-testid":`statusbar.guest`,className:`min-w-0 truncate`,children:E??a})]}),!C&&(0,Z.jsx)(VB,{orientation:`vertical`,className:`my-2.5`}),(0,Z.jsxs)(`div`,{"data-slot":`editor-status-bar-end`,className:`flex min-w-0 flex-1 items-center gap-1 px-2`,children:[a===void 0?(0,Z.jsx)(`span`,{"aria-live":`polite`,"data-testid":`statusbar.save-version`,"data-save-version-state":t??`unavailable`,className:`px-1`,children:e??`Autosaved just now`}):(0,Z.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"data-testid":`statusbar.save-version`,"data-save-version-state":t??`unavailable`,children:E??e??a}),n!==void 0&&(0,Z.jsx)(aB,{variant:`ghost`,size:`xs`,onClick:n,disabled:r===!0||i===!0,"data-testid":`topbar.save-version`,"data-editor-control":``,"aria-label":`Save the current draft as a version`,title:`Save this draft as a version (⌘/Ctrl+S)`,className:`text-foreground`,children:r===!0?`Saving…`:e===`Couldn’t save version`?`Retry`:`Save version`}),(0,Z.jsx)(`span`,{className:`flex-1`}),!S&&s!==null&&s.channel!==`email`&&(0,Z.jsxs)(`span`,{className:`px-1`,children:[l,` KB · `,s.channel.toUpperCase()]})]})]})}})}var lW=$(`border-border-subtle bg-surface-inset text-muted-foreground inline-flex h-[22px] min-w-0 max-w-[180px] items-center gap-1 rounded-md border px-2 text-[11.5px] font-medium outline-none`,Cz),uW=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey;function dW({source:e,onUseDefault:t}){let n=Q(e=>e.doc?.rev??null),r=Q(e=>e.editable&&e.lifecycleCapability?.status===`ready`),i=(0,W.useRef)(e.readTheme);(0,W.useEffect)(()=>{i.current=e.readTheme});let[a,o]=(0,W.useState)(void 0),[s,c]=(0,W.useState)(`idle`);(0,W.useEffect)(()=>{if(n===null)return;let e=!1;return i.current().then(t=>{e||o(PV(t.theme??``))},()=>void 0),()=>{e=!0}},[n]);let l=IV(a,e.brands);if(l.kind===`pending`)return e.status??null;let u;if(l.kind===`brand`){let{name:t,slug:n}=l.brand,r=e.brandLink(n);u=(0,Z.jsxs)(`a`,{href:r.href,"aria-label":`Brand: ${t}`,title:`Open ${t}`,"data-testid":`topbar.brand`,onClick:e=>{r.navigate!==void 0&&uW(e)&&(e.preventDefault(),r.navigate())},className:$(lW,`hover:bg-muted hover:text-foreground`),children:[(0,Z.jsx)(AR,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:t})]})}else if(l.kind===`missing`)u=(0,Z.jsxs)(`span`,{"data-testid":`topbar.brand-missing`,title:l.slug===null?`This organization has no default brand.`:`This organization has no brand “${l.slug}”.`,className:$(lW,`text-status-warning`),children:[(0,Z.jsx)(AR,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:`Brand not found`})]});else{let e=l.defaultBrand,n=r&&t!==void 0&&e!==null?()=>{c(`busy`),t().then(()=>c(`idle`),()=>c(`error`))}:void 0;u=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`span`,{"data-testid":`topbar.brand-none`,className:lW,children:[(0,Z.jsx)(AR,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:`No brand`})]}),n!==void 0&&e!==null&&(0,Z.jsx)(`button`,{type:`button`,"data-testid":`topbar.brand-use`,onClick:n,disabled:s===`busy`,"aria-busy":s===`busy`,title:`Theme this template with ${e.name}`,className:$(`text-foreground hover:bg-muted inline-flex h-[22px] max-w-[180px] items-center rounded-md px-1.5 text-[11.5px] font-medium outline-none disabled:opacity-50`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:(0,Z.jsxs)(`span`,{className:`truncate`,children:[`Use `,e.name]})}),s===`error`&&e!==null&&(0,Z.jsxs)(`span`,{role:`alert`,className:`text-status-error truncate text-[11.5px]`,children:[`Couldn’t use `,e.name]})]})}return(0,Z.jsxs)(`div`,{className:`flex min-w-0 shrink items-center gap-1`,children:[u,e.status]})}var fW=[`assistant`,`preview`];function pW({compact:e=!1,...t}){let{focusedPane:n,previewUnseen:r}=Q(kk(e=>({focusedPane:e.focusedPane,previewUnseen:e.previewUnseen}))),i=Q(e=>e.actions.setFocusedPane),{idBase:a}=NU(),o=r&&n!==`preview`;return dz(`editor-pane-switch`,{...t},{state:{pane:n,unseen:o},className:`flex min-w-0`,props:{children:(0,Z.jsx)(KB,{role:`tablist`,"aria-label":`Editor pane`,value:[n],spacing:0,onValueChange:e=>{let t=fW.find(t=>t===e[0]);t!==void 0&&i(t)},className:$(Tz,`grid h-8 w-full grid-cols-2`,e&&`w-auto`),children:fW.map(t=>(0,Z.jsxs)(qB,{value:t,id:`${a}-tab-${t}`,role:`tab`,"aria-selected":n===t,"aria-controls":`${a}-pane-${t}`,"aria-pressed":void 0,"aria-label":e?t===`assistant`?`Chat`:`Preview`:void 0,"data-pressed":n===t?``:void 0,"data-testid":`agent-workspace.tab.${t}`,"data-editor-control":``,className:$(Ez,e?`px-2.5`:`gap-1.5 px-3 text-[13px]`,`aria-selected:bg-background aria-selected:text-foreground aria-selected:shadow-sm dark:aria-selected:border-input dark:aria-selected:bg-input/30`),children:[t===`assistant`?(0,Z.jsx)(XR,{className:`size-3.5`}):(0,Z.jsx)(SR,{className:`size-3.5`}),e?null:t===`assistant`?`Chat`:`Preview`,t===`preview`&&o&&(0,Z.jsx)(`span`,{"data-testid":`agent-workspace.preview-updated`,className:`bg-primary size-1.5 rounded-full`,children:(0,Z.jsx)(`span`,{className:`sr-only`,children:`, updated`})})]},t))})}})}function mW({leading:e,extraActions:t,onBack:n,onUndo:r,onRedo:i,canUndo:a=!1,canRedo:o=!1,onPreview:s,onLifecycle:c,channelSwitcher:l,exportEnabled:u,onExport:d,renameEnabled:f=!0,brand:p,onUseDefaultBrand:m,part:h}){let{doc:g,render:_,pendingAuthoredSource:v,lifecycleCapability:y,editable:b,readonlyReason:x,renameActive:S,metadataError:C,layoutMode:w}=Q(kk(e=>({doc:e.doc,render:e.render,pendingAuthoredSource:e.pendingAuthoredSource,lifecycleCapability:e.lifecycleCapability,editable:e.editable,readonlyReason:e.readonlyReason,renameActive:e.renameActive,metadataError:e.metadataError,layoutMode:e.layoutMode}))),{rename:T,setRenameActive:E}=Q(e=>e.actions),D=(0,W.useRef)(null),O=g?.name??`Untitled template`;(0,W.useEffect)(()=>{if(S&&D.current){D.current.focus();let e=document.createRange();e.selectNodeContents(D.current);let t=window.getSelection();t?.removeAllRanges(),t?.addRange(e)}},[S]);let k=u===!0&&g?.channel===`email`&&_!==null&&v===null,A=w===`compact`||w===`narrow`,j=w===`standard`,M=g!==null&&g.channel!==`email`,N=()=>{k&&g!==null&&_!==null&&(WU(_.html,g.name),d?.())},P=gz(`rail.assistant`)!==void 0,F=w===`narrow`,I=A,L=b&&y!==void 0?(0,Z.jsx)($B,{label:y.status===`locked`?y.upsell.reason:`Publish and view history`,children:(0,Z.jsx)(aB,{size:`sm`,onClick:c,"data-testid":`topbar.publish`,"data-editor-control":``,children:`Publish`})}):null;return dz(`editor-top-bar`,{...h},{state:{layout:w},tag:`header`,className:`border-border bg-background z-30 flex h-12 min-w-0 shrink-0 items-center gap-2 border-b px-3`,props:{children:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{"data-slot":`editor-top-bar-title`,className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[e!==void 0&&(0,Z.jsx)(`div`,{className:`shrink-0`,children:e}),n!==void 0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($B,{label:`Back to templates`,children:(0,Z.jsxs)(aB,{variant:`ghost`,size:F?`icon-sm`:`sm`,onClick:n,"aria-label":`Back to templates`,"data-testid":`topbar.back`,"data-editor-control":``,className:`text-muted-foreground`,children:[(0,Z.jsx)(gR,{}),F?null:`Templates`]})}),(0,Z.jsx)(VB,{orientation:`vertical`,className:`mx-0.5 h-4!`})]}),(0,Z.jsx)(`span`,{ref:D,"data-testid":`topbar.name`,"data-slot":`editor-top-bar-name`,contentEditable:b&&f,suppressContentEditableWarning:!0,spellCheck:!1,title:b&&f?`Click to rename`:x??`This template name is fixed.`,className:$(`min-w-0 truncate rounded-md px-1.5 py-1 text-sm font-medium whitespace-nowrap outline-none`,F?`max-w-full`:`max-w-72 min-w-24`,`hover:bg-muted focus-visible:ring-ring/50 focus-visible:bg-background focus-visible:ring-3`),onFocus:()=>{b&&f&&E(!0)},onBlur:e=>{b&&f&&(E(!1),T(e.currentTarget.textContent??``))},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur()),e.key===`Escape`&&(e.currentTarget.textContent=O,e.currentTarget.blur())},children:O}),C!==null&&(0,Z.jsx)(`span`,{role:`alert`,className:`text-destructive truncate text-xs`,children:C}),F?null:l===void 0?(0,Z.jsx)(zB,{variant:`outline`,className:`text-muted-foreground font-mono uppercase`,children:g?.channel??`Template`}):(0,Z.jsx)(`div`,{className:$(`min-w-0 shrink-0`,A&&`[&_[data-channel-button]]:px-1.5 [&_[data-channel-label]]:hidden`),children:l}),!b&&g!==null&&(0,Z.jsx)(zB,{variant:`secondary`,title:x??`This template is read-only.`,"data-testid":`topbar.readonly-badge`,children:`Read-only`}),p!==void 0&&g?.channel===`email`&&!F&&(0,Z.jsx)(dW,{source:p,onUseDefault:m})]}),P&&w!==`wide`&&g?.channel===`email`&&(0,Z.jsx)(pW,{compact:F,className:F?`shrink-0`:`w-56 shrink-0`}),(0,Z.jsxs)(`div`,{"data-slot":`editor-top-bar-actions`,className:$(`flex shrink-0 items-center justify-end gap-1`,!I&&`flex-1`),children:[!I&&r!==void 0&&(0,Z.jsx)(aB,{variant:`ghost`,size:`sm`,"data-testid":`topbar.undo`,"data-editor-control":``,onClick:r,disabled:!a,children:`Undo`}),!I&&i!==void 0&&(0,Z.jsx)(aB,{variant:`ghost`,size:`sm`,"data-testid":`topbar.redo`,"data-editor-control":``,onClick:i,disabled:!o,children:`Redo`}),!I&&M&&(0,Z.jsx)(oU,{testId:`topbar.fixture`}),!I&&(0,Z.jsx)(VB,{orientation:`vertical`,className:`mx-1 h-4!`}),!F&&(0,Z.jsx)($B,{label:`Preview template`,children:(0,Z.jsxs)(aB,{variant:`ghost`,size:j||I?`icon-sm`:`sm`,"aria-label":`Preview template`,"data-testid":`topbar.preview`,"data-editor-control":``,onClick:s,children:[(0,Z.jsx)(SR,{}),j||I?null:`Preview`]})}),!I&&u===!0&&(0,Z.jsx)($B,{label:k?`Export rendered HTML`:`Export waits for the latest render`,children:(0,Z.jsxs)(aB,{variant:`ghost`,size:j?`icon-sm`:`sm`,"aria-label":`Export HTML`,"data-testid":`topbar.export`,"data-editor-control":``,onClick:N,disabled:!k,children:[(0,Z.jsx)(bR,{}),j?null:`Export HTML`]})}),!F&&t,I&&M&&(0,Z.jsx)(oU,{testId:`topbar.fixture`}),I&&(0,Z.jsxs)(jH,{children:[(0,Z.jsx)(MH,{render:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`More actions`,"data-testid":`topbar.more`,"data-editor-control":``}),children:(0,Z.jsx)(GR,{})}),(0,Z.jsxs)(NH,{align:`end`,className:`w-48`,children:[r!==void 0&&(0,Z.jsx)(IH,{"data-testid":`topbar.undo`,"data-editor-control":``,disabled:!a,onClick:r,children:`Undo`}),i!==void 0&&(0,Z.jsx)(IH,{"data-testid":`topbar.redo`,"data-editor-control":``,disabled:!o,onClick:i,children:`Redo`}),F&&(0,Z.jsx)(LH,{}),F&&(0,Z.jsxs)(IH,{"data-testid":`topbar.preview`,onClick:s,children:[(0,Z.jsx)(SR,{}),`Preview template`]}),u===!0&&(0,Z.jsxs)(IH,{"data-testid":`topbar.export`,"data-editor-control":``,disabled:!k,onClick:N,children:[(0,Z.jsx)(bR,{}),`Export HTML`]})]})]}),F&&t,L]})]})}})}var hW=[],gW=e=>e>=1280?`wide`:e>=980?`standard`:e>=720?`compact`:`narrow`;function _W(){let e=Q(e=>e.conflict),{reload:t}=Q(e=>e.actions);return!Q(e=>e.editable)||!e?null:(0,Z.jsxs)(`div`,{className:`border-border bg-surface-elevated text-foreground absolute inset-x-0 top-3 z-30 mx-auto flex w-fit items-center gap-3 rounded-lg border px-3.5 py-2 text-[13px] shadow-[var(--shadow-md)]`,children:[(0,Z.jsx)(`span`,{children:`Document changed elsewhere — your recent edits weren’t saved.`}),(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`bg-primary text-primary-foreground rounded-md px-2.5 py-1 font-medium transition-opacity hover:opacity-90`,children:`Reload`})]})}function vW(){let e=Q(e=>e.storageError),t=Q(e=>e.conflict),{retrySave:n}=Q(e=>e.actions);return!Q(e=>e.editable)||e===null||t?null:(0,Z.jsxs)(`div`,{className:`border-status-warning/45 bg-surface-elevated text-foreground absolute inset-x-0 top-3 z-30 mx-auto flex w-fit items-center gap-3 rounded-lg border px-3.5 py-2 text-[13px] shadow-[var(--shadow-md)]`,children:[(0,Z.jsxs)(`span`,{children:[e,` Your work is kept here; export a copy or retry.`]}),(0,Z.jsx)(`button`,{type:`button`,onClick:n,className:`border-border hover:bg-muted rounded-md border px-2.5 py-1 font-medium transition-colors`,children:`Retry`})]})}function yW(){let e=Q(e=>e.doc);return e===null||e.channel===`email`?(0,Z.jsx)(BU,{}):e.channel===`sms`?(0,Z.jsx)(Kz,{}):(0,Z.jsx)(rB,{})}function bW({height:e=`100dvh`,contributions:t=hW,brand:n,onBack:r,exportable:i,renameEnabled:a,onLockedLifecycle:o,previewBusy:s=!1,onOpenPreview:c,children:l,...u}){let d=Q(e=>e.leftCollapsed),f=Q(e=>e.rightCollapsed),p=Q(e=>e.layoutMode),m=Q(e=>e.doc?.rev??null),h=Q(e=>e.undoHistory.length+(e.designDraft?.edits.length??0)),g=Q(e=>e.redoHistory.length+(e.designDraft?.undone.length??0)),_=Q(e=>e.sourceEditable),v=Q(e=>e.doc),y=Q(e=>e.render),b=Q(e=>e.pendingAuthoredSource),x=Q(e=>e.lifecycleBusy),S=Q(e=>e.conflict),C=Q(e=>e.storageError),w=(0,W.useMemo)(()=>pz(t),[t]),T=w.one(`frame.start`),E=w.one(`statusbar.headline`),D=w.one(`rail.assistant`)!==void 0,{flushSaves:O,beginLifecycle:k,endLifecycle:A,adoptLifecycleSnapshot:j,toggleLeft:M,toggleRight:N,setLayoutMode:P,undo:F,redo:I,openWorkTab:L,setFocusedPane:R,setHostBusy:z}=Q(e=>e.actions);(0,W.useEffect)(()=>z(s),[s,z]);let B=Q(e=>e.versionsCapability),ee=Q(e=>e.telemetry),te=B?.status===`ready`?B.api:void 0,ne=(0,W.useMemo)(()=>te===void 0?void 0:e=>te.save(e),[te]),V=(0,W.useMemo)(()=>te===void 0?void 0:()=>te.savedRevision(),[te]),re=()=>ee?.({name:`preview`}),ie=()=>ee?.({name:`export`}),[ae,oe]=(0,W.useState)(!1),[se,ce]=(0,W.useState)(!1),[H,le]=(0,W.useState)(`idle`),[ue,de]=(0,W.useState)(null),[fe,U]=(0,W.useState)(null),pe=BI(),me=(0,W.useId)();(0,W.useEffect)(()=>{if(V===void 0||m===null)return;let e=!0;return V().then(t=>{e&&U(t===m?t:null)}).catch(()=>{e&&U(null)}),()=>{e=!1}},[m,V]);let he=(0,W.useRef)(null),ge=(0,W.useRef)(()=>{}),_e=(0,W.useRef)(null),ve=(0,W.useRef)(null),ye=i===!0&&v?.channel===`email`&&y!==null&&b===null,be=()=>{ye&&v!==null&&y!==null&&(WU(y.html,v.name),ie?.())},xe=()=>{if(ne===void 0)return Promise.resolve();if(ZL(pe.getState())>0)return pe.getState().actions.applyDesign(),Promise.resolve();if(he.current!==null)return he.current;if(!k())return Promise.resolve();let e=()=>{},t=new Promise(t=>{e=t});return he.current=t,le(`saving`),pe.getState().actions.flushSaves().then(async e=>{let t=pe.getState().doc,n=await ne(e),r=pe.getState().doc;t!==null&&(r?.rev===e||r?.rev===n)&&r.origin.authoredSource===t.origin.authoredSource&&pe.getState().actions.adoptLifecycleSnapshot({rev:n,authoredSource:t.origin.authoredSource}),de(n),le(`idle`)}).catch(()=>le(`error`)).finally(()=>{A(),he.current===t&&(he.current=null),e()}),t};(0,W.useEffect)(()=>{ge.current=xe});let Se=n===void 0||ne===void 0?void 0:async()=>{let e=pe.getState().lifecycleCapability;if(e?.status!==`ready`)return;let t=await pe.getState().actions.flushSaves(),r=await n.readTheme(),i=FV(r);i!==r.theme&&await e.api.updateFile({path:bV,baseRev:t,content:i}),await xe()},Ce=`idle`;H===`saving`?Ce=`saving`:H===`error`?Ce=`error`:m!==null&&(ue===m||fe===m)&&b===null&&!S&&C===null&&(Ce=`saved`);let we;ne!==void 0&&(we=`Unsaved changes`,Ce===`saving`?we=`Saving version…`:Ce===`saved`?we=`Saved version`:Ce===`error`&&(we=`Couldn’t save version`));let Te={flushSaves:O,beginLifecycle:k,endLifecycle:A,adoptLifecycleSnapshot:j,undo:F,redo:I,canUndo:_&&h>0,canRedo:_&&g>0,preview:()=>{oe(!0),re?.()},exportHtml:be,canExport:ye},Ee=(0,W.useMemo)(()=>({hostBusy:s,openInNewTab:c,showChecks:D?()=>{L(`checks`),R(`preview`)}:void 0}),[D,c,L,s,R]),De=w.all(`toolbar.leading`).map(e=>(0,Z.jsx)(W.Fragment,{children:e.render()},e.id)),Oe=w.all(`toolbar.actions`).map(e=>(0,Z.jsx)(W.Fragment,{children:e.render(Te)},e.id)),ke=w.one(`document.switcher`)?.render(Te);(0,W.useEffect)(()=>{if(ne===void 0)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`&&e.target instanceof HTMLElement&&e.target.closest(`[data-samva-editor-theme]`)!==null&&e.target.closest(`[role="menu"], [role="dialog"], [data-base-ui-portal]`)===null&&(e.preventDefault(),ge.current())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[ne]),(0,W.useLayoutEffect)(()=>{let e=_e.current;if(e===null||typeof ResizeObserver>`u`)return;let t,n=e=>{let n=gW(e);n!==t&&(t=n,P(n))};n(e.getBoundingClientRect().width);let r=new ResizeObserver(([e])=>{e!==void 0&&n(e.contentRect.width)});return r.observe(e),()=>r.disconnect()},[P]);let Ae=(p===`compact`||p===`narrow`)&&(!d||!f);(0,W.useEffect)(()=>{if(!Ae)return;let e=e=>{e.key===`Escape`&&(d||M(),f||N())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[d,Ae,f,M,N]);let je={leading:De.length===0?void 0:De,extraActions:Oe.length===0?void 0:Oe,onBack:T===void 0?r:void 0,onPreview:()=>{oe(!0),re?.()},onLifecycle:()=>ce(!0),onUndo:F,onRedo:I,canUndo:_&&h>0,canRedo:_&&g>0,channelSwitcher:ke,exportEnabled:i,renameEnabled:a,onExport:ie,brand:n,onUseDefaultBrand:Se},Me=E===void 0||E.saveVersion,Ne={saveVersionStatus:Me?we:void 0,saveVersionState:ne===void 0?void 0:Ce,onSaveVersion:Me&&ne!==void 0?xe:void 0,saveVersionBusy:Ce===`saving`,saveVersionBlocked:x,guestHeadline:E?.headline},Pe=dz(`editor`,{...u},{state:{layout:p,docked:D,busy:x},className:`samva-editor-shell flex min-w-0 flex-1 flex-col overflow-hidden`,props:{"data-samva-editor-theme":`host`,inert:x,"aria-busy":x,children:l}});return(0,Z.jsx)(hz,{value:w,children:(0,Z.jsx)(yz,{value:{exportHtml:be,canExport:ye,saveVersionStatus:ne===void 0?`unavailable`:Ce},children:(0,Z.jsx)(zH,{value:Ee,children:(0,Z.jsx)(MU,{value:{topBar:je,statusBar:Ne,overlayOpen:Ae,idBase:me},children:(0,Z.jsx)(nW,{container:ve,children:(0,Z.jsxs)(`div`,{ref:_e,className:`samva-editor-frame flex`,style:{height:e},children:[T?.render(),Pe,(0,Z.jsx)(oW,{open:ae,onClose:()=>oe(!1)}),(0,Z.jsx)(eW,{open:se,onClose:()=>ce(!1),onLockedAction:o}),(0,Z.jsx)(`div`,{ref:ve,"data-samva-editor-portal-root":!0,className:`samva-editor-shell`})]})})})})})})}function xW(e){let t=Q(e=>e.layoutMode),n=Q(e=>e.leftCollapsed),r=Q(e=>e.rightCollapsed),i=gz(`rail.assistant`)!==void 0,{toggleLeft:a,toggleRight:o}=Q(e=>e.actions),{overlayOpen:s}=NU();return dz(`editor-workspace`,{...e},{state:{layout:t},className:`samva-editor-body relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,props:{children:(0,Z.jsxs)(Z.Fragment,{children:[s&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close editor panel`,className:`bg-background/45 absolute inset-0 z-30 cursor-default backdrop-blur-[1px]`,onClick:()=>{n||a(),r||o()}}),n&&!i&&(0,Z.jsx)(SW,{label:`Show layers and blocks`,testId:`shell.show-left`,side:`left`,onClick:a}),r&&!i&&(0,Z.jsx)(SW,{label:`Show inspector`,testId:`shell.show-right`,side:`right`,onClick:o}),(0,Z.jsx)(yW,{}),(0,Z.jsx)(_W,{}),(0,Z.jsx)(vW,{})]})}})}function SW({label:e,testId:t,side:n,onClick:r}){let i=n===`left`?MR:PR;return(0,Z.jsx)($B,{label:e,side:n===`left`?`right`:`left`,children:(0,Z.jsx)(aB,{variant:`outline`,size:`icon-sm`,"aria-label":e,"data-testid":t,onClick:r,className:$(`absolute top-3 z-20 shadow-sm`,n===`left`?`left-3`:`right-3`),children:(0,Z.jsx)(i,{className:`size-4`})})})}function CW(e){let{topBar:t}=NU();return(0,Z.jsx)(mW,{...t,part:e})}function wW(e){let{statusBar:t}=NU();return(0,Z.jsx)(cW,{...t,part:e})}function TW(e){return(0,Z.jsxs)(bW,{...e,children:[(0,Z.jsx)(CW,{}),(0,Z.jsx)(xW,{}),(0,Z.jsx)(wW,{})]})}function EW({name:e,className:t}){let n=LI()[e];return(0,Z.jsx)(n,{...t===void 0?{}:{className:t}})}function DW({label:e,icon:t,title:n,upsell:r,onAction:i,testId:a}){let[o,s]=(0,W.useState)(!1),c=kz();return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($B,{label:r.reason,children:(0,Z.jsxs)(aB,{variant:`ghost`,size:`sm`,"aria-label":e,"data-testid":a,"data-editor-control":``,onClick:()=>s(!0),children:[t,e]})}),(0,Z.jsx)(OF,{open:o,onOpenChange:s,swipeDirection:`right`,children:(0,Z.jsxs)(TF,{container:c,children:[(0,Z.jsx)(tF,{className:`fixed inset-0 z-[110] bg-[var(--editor-backdrop,rgb(0_0_0/0.28))]`}),(0,Z.jsx)(pI,{className:`pointer-events-none fixed inset-0 z-[111] flex justify-end`,children:(0,Z.jsxs)(wF,{className:`samva-editor-shell border-border bg-background pointer-events-auto flex h-full w-[420px] max-w-[92vw] flex-col border-l shadow-[var(--shadow-floating)] outline-none`,children:[(0,Z.jsx)(iF,{className:`sr-only`,children:r.reason}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-4 pb-3`,children:[(0,Z.jsx)(XF,{className:`text-[15px] font-semibold`,children:n}),(0,Z.jsx)(nF,{type:`button`,"aria-label":`Close ${e.toLowerCase()} panel`,"data-testid":a===void 0?void 0:`${a}.close`,className:`text-muted-foreground hover:bg-muted hover:text-foreground rounded-md p-1.5`,children:(0,Z.jsx)(RR,{className:`size-[15px]`})})]}),(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-start gap-4 px-5 pt-6 pb-8`,children:[(0,Z.jsx)(`div`,{className:`border-border-subtle bg-surface-inset text-muted-foreground rounded-lg border px-3.5 py-3 text-[13px]`,children:r.reason}),(0,Z.jsx)(`a`,{href:r.cta.href,onClick:e=>{i!==void 0&&(e.preventDefault(),i())},"data-testid":a===void 0?void 0:`${a}.cta`,className:iB(),children:r.cta.label})]})]})})]})})]})}var OW=`2026-10-03.1`,kW=class extends Hn(`DocumentConflict`){},AW=class extends Hn(`DocumentUnavailable`){};Hn(`LifecycleUnavailable`),Hn(`ProjectFileExists`);var jW=(e,t)=>{let n=new URL(`api/${e}`,window.location.href);for(let[e,r]of Object.entries(t))n.searchParams.set(e,r);return n.toString()},MW=e=>e.fixture,NW=(e,t,n,r)=>({rev:t,origin:n,...r===void 0?{}:{authoredSource:r},...e}),PW=(e,t,n)=>ca(function*(){let r=yield*Fa(),i=new EventSource(jW(`events`,{id:e,client:t}));yield*ha(()=>aa(()=>i.close())),i.addEventListener(`samva:change`,t=>{let i=JSON.parse(t.data);i.id===e&&(n.rev=i.rev,n.fixture=MW(i),i.authoredSource!==void 0&&(n.authoredSource=i.authoredSource),Ia(r,NW(i,i.rev,i.origin,i.authoredSource)))});let a=()=>fetch(jW(`document`,{id:e,client:t})).then(e=>e.ok?e.json():void 0).then(e=>{if(e===void 0)return;let t=e.origin.authoredSource;(e.rev!==n.rev||t!==n.authoredSource||MW(e)!==n.fixture)&&(n.rev=e.rev,n.authoredSource=t,n.fixture=MW(e),Ia(r,NW(e,e.rev,`external`,t)))}).catch(()=>{}),o=!1,s;i.addEventListener(`open`,()=>{if(!o){o=!0,s?.(oa);return}a()}),i.addEventListener(`error`,()=>{!o&&i.readyState!==EventSource.OPEN&&s?.(new AW({reason:`editor event stream failed to open`}))}),yield*sa(e=>{if(i.readyState===EventSource.OPEN)return o=!0,e(oa);s=e});let c=yield*na({try:()=>fetch(jW(`document`,{id:e,client:t})),catch:e=>new AW({reason:String(e)})});if(!c.ok)return yield*new AW({reason:`open failed (${c.status})`});let l=yield*na({try:()=>c.json(),catch:e=>new AW({reason:String(e)})});return n.rev=l.rev,n.authoredSource=l.origin.authoredSource,n.fixture=MW(l),{initial:l,changes:oo(r)}}),FW=(e,t)=>({view:n=>ca(function*(){let r=yield*na({try:()=>fetch(jW(`fixture`,{id:e,client:t}),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({fixture:n})}),catch:e=>new AW({reason:String(e)})});if(r.ok)return;let i=`view fixture failed (${r.status})`;return yield*new AW({reason:yield*na({try:()=>r.json(),catch:()=>new AW({reason:i})}).pipe(fa(e=>e.error??i))})})}),IW=(e,t)=>({save:n=>ca(function*(){if(n.kind!==`authoredSource`)return yield*new AW({reason:`Local metadata is declared in source.`});let r=yield*na({try:()=>fetch(jW(`document`,{id:e,client:t}),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),catch:e=>new AW({reason:String(e)})}),i=yield*na({try:()=>r.json(),catch:e=>new AW({reason:String(e)})});return r.status===409?yield*new kW({expectedRev:n.baseRev,actualRev:i.actualRev??n.baseRev}):!r.ok||i.rev===void 0?yield*new AW({reason:i.error??`Local source save failed.`}):{rev:i.rev}})}),LW=({id:e})=>{let t=crypto.randomUUID();return{contractVersion:OW,access:`editable`,sourceAccess:`editable`,metadataAccess:`readonly`,writer:IW(e,t),document:{open:PW(e,t,{rev:``})},fixtures:{status:`ready`,api:FW(e,t)}}},RW=e=>new URL(`api/${e}`,window.location.href).toString(),zW=async e=>{let t=await fetch(RW(e));if(!t.ok)throw Error(`${e} failed (${t.status})`);return t.json()},BW=()=>{let[e,t]=(0,W.useState)(()=>typeof window<`u`&&window.matchMedia(`(prefers-color-scheme: dark)`).matches);return(0,W.useEffect)(()=>{document.documentElement.classList.toggle(`dark`,e)},[e]),()=>t(e=>!e)};function VW({onBack:e,onToggleTheme:t}){return(0,Z.jsxs)(`nav`,{"aria-label":`Samva editor`,className:`border-border bg-background z-30 flex w-12 flex-none flex-col items-center gap-1 border-r py-3`,children:[(0,Z.jsx)(`span`,{className:`bg-primary text-primary-foreground mb-2 grid size-7 place-items-center rounded-lg text-[13px] font-bold`,children:`S`}),e?(0,Z.jsx)(`button`,{type:`button`,title:`Back to templates`,onClick:e,className:`text-muted-foreground hover:bg-muted hover:text-foreground grid size-8 place-items-center rounded-lg transition-colors`,children:(0,Z.jsx)(EW,{name:`arrowLeft`,className:`size-[16px]`})}):null,(0,Z.jsx)(`div`,{className:`flex-1`}),(0,Z.jsx)(`button`,{type:`button`,title:`Toggle theme`,onClick:t,className:`text-muted-foreground hover:bg-muted hover:text-foreground grid size-8 place-items-center rounded-lg transition-colors dark:hidden`,children:(0,Z.jsx)(EW,{name:`moon`,className:`size-[16px]`})}),(0,Z.jsx)(`button`,{type:`button`,title:`Toggle theme`,onClick:t,className:`text-muted-foreground hover:bg-muted hover:text-foreground hidden size-8 place-items-center rounded-lg transition-colors dark:grid`,children:(0,Z.jsx)(EW,{name:`sun`,className:`size-[16px]`})})]})}var HW={authenticatedLabel:`Authenticated`,authenticatedTitle:`The host provides authenticated capabilities.`};function UW({template:e,authenticated:t,editorAffordances:n,onBack:r,onToggleTheme:i}){let a=n.publishingInstructions,o=(0,W.useMemo)(()=>fo(LW({id:e.id})),[e.id]);return(0,Z.jsx)(uR,{host:o,children:(0,Z.jsx)(`div`,{className:`relative h-dvh`,children:(0,Z.jsx)(TW,{contributions:[{slot:`frame.start`,id:`project-rail`,render:()=>(0,Z.jsx)(VW,{onBack:r,onToggleTheme:i})},...t&&a!==void 0?[{slot:`toolbar.actions`,id:`send`,render:()=>(0,Z.jsx)(DW,{label:`Send`,title:`Send “${e.name}”`,upsell:a,testId:`vite-editor.send`})}]:[]],onBack:r,renameEnabled:!1})})},`${e.id}:${e.channel}`)}var WW={email:{icon:`envelope`,label:`Email`,className:`bg-sel-soft text-accent-email`},sms:{icon:`message`,label:`SMS`,className:`bg-muted text-primary`},whatsapp:{icon:`chatBubble`,label:`WhatsApp`,className:`bg-status-success/10 text-status-success`}};function GW({catalog:e,authenticated:t,editorAffordances:n,onOpen:r,onToggleTheme:i}){return(0,Z.jsxs)(`div`,{className:`flex h-dvh`,children:[(0,Z.jsx)(VW,{onToggleTheme:i}),(0,Z.jsx)(`div`,{className:`bg-surface-inset min-w-0 flex-1 overflow-y-auto`,children:(0,Z.jsxs)(`div`,{className:`mx-auto max-w-[720px] px-6 py-16`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h1`,{className:`text-foreground text-lg font-semibold`,children:`Templates`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-1 text-[13px]`,children:`Preview your templates and fixtures. Source edits save to your project.`})]}),(0,Z.jsx)(`span`,{className:t?`bg-status-success/12 text-status-success rounded-full px-2.5 py-1 text-[11px] font-medium`:`bg-muted text-muted-foreground rounded-full px-2.5 py-1 text-[11px] font-medium`,title:t?n.authenticatedTitle:`Local editing only.`,children:t?n.authenticatedLabel:`Local only`})]}),e.diagnostics.length>0?(0,Z.jsx)(`section`,{"aria-label":`Catalog diagnostics`,className:`border-border bg-surface-elevated mt-6 overflow-hidden rounded-xl border`,children:e.diagnostics.map((e,t)=>(0,Z.jsxs)(`div`,{className:`px-4 py-3 text-[12px]`+(t>0?` border-border-subtle border-t`:``),children:[(0,Z.jsxs)(`p`,{className:e.severity===`error`?`text-status-error`:`text-status-warning`,children:[e.file,` · `,e.code]}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:e.message})]},`${e.file}:${e.code}:${t}`))}):null,(0,Z.jsxs)(`ul`,{className:`border-border bg-surface-elevated mt-8 overflow-hidden rounded-xl border shadow-md`,children:[e.templates.length===0?(0,Z.jsxs)(`li`,{className:`text-muted-foreground px-4 py-10 text-center text-[13px]`,children:[`No valid templates found. Add a `,(0,Z.jsx)(`code`,{className:`text-foreground`,children:`.tsx`}),` file with a Samva template as its default export.`]}):null,e.templates.map((e,t)=>{let n=WW[e.channel];return(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>r(e),"data-testid":`template-card.${e.id}`,className:`hover:bg-muted flex w-full items-center gap-3 px-4 py-3 text-left transition-colors`+(t>0?` border-border-subtle border-t`:``),children:[(0,Z.jsx)(`span`,{className:`grid size-8 flex-none place-items-center rounded-lg ${n.className}`,children:(0,Z.jsx)(EW,{name:n.icon,className:`size-[16px]`})}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`text-foreground block truncate text-[13px] font-medium`,children:e.name}),(0,Z.jsx)(`span`,{className:`text-muted-foreground block truncate text-[12px]`,children:e.id})]}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground text-right text-[11px]`,children:[(0,Z.jsx)(`span`,{className:`block`,children:n.label}),(0,Z.jsx)(`span`,{className:`block`,children:`Editable source`})]})]})},e.id)})]})]})})]})}function KW(){let e=BW(),[t,n]=(0,W.useState)(!1),[r,i]=(0,W.useState)(HW),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(null);(0,W.useEffect)(()=>{let e=!0,t=()=>zW(`templates`).then(t=>{e&&(o(t),c(null))});Promise.all([zW(`capabilities`).then(t=>{e&&(n(!!t.authenticated),i(t.editorAffordances??HW))}),t()]).catch(t=>{e&&c(String(t))});let r=new EventSource(RW(`catalog-events`));return r.addEventListener(`samva:catalog`,()=>{t().catch(t=>{e&&c(String(t))})}),()=>{e=!1,r.close()}},[]);let d=a?.templates.find(e=>e.id===l)??null;return l!==null&&a!==null&&d===null&&u(null),s===null?a===null?(0,Z.jsx)(`div`,{className:`text-muted-foreground grid h-dvh place-items-center text-[13px]`,children:`Loading templates…`}):d===null?(0,Z.jsx)(GW,{catalog:a,authenticated:t,editorAffordances:r,onOpen:e=>u(e.id),onToggleTheme:e}):(0,Z.jsx)(UW,{template:d,authenticated:t,editorAffordances:r,onBack:()=>u(null),onToggleTheme:e}):(0,Z.jsxs)(`div`,{className:`text-status-error grid h-dvh place-items-center px-6 text-center text-[13px]`,children:[`Couldn’t reach the Samva editor dev server: `,s]})}(0,co.createRoot)(document.getElementById(`root`)).render((0,Z.jsx)(W.StrictMode,{children:(0,Z.jsx)(KW,{})}));
39
+ `)}),j.refusal!==null&&(0,Z.jsx)(`p`,{"data-testid":`source.proposal-refusal`,className:`text-status-error text-xs`,children:j.refusal}),(0,Z.jsx)(`button`,{"data-testid":`source.apply-reviewed`,type:`button`,className:aH,disabled:j.refusal!==null,onClick:()=>{ne(j.edits,j.label),M(null)},children:`Use this change`}),` `,(0,Z.jsx)(`button`,{type:`button`,className:aH,onClick:()=>M(null),children:`Cancel`})]})]}):null]})]}),re!==null&&(0,Z.jsx)(`p`,{"data-testid":`source.edit-error`,className:`text-status-error mt-2 text-xs`,children:re}),(0,Z.jsxs)(`div`,{className:`mt-3 flex gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,className:aH,onClick:l,children:`Open source`}),m&&(0,Z.jsx)(`button`,{type:`button`,className:aH,onClick:()=>u(h),children:`Ask agent`})]})]})}function pH(){let{undo:e,redo:t,error:n,editable:r}=Q(kk(e=>({undo:e.undoHistory.length+(e.designDraft?.edits.length??0),redo:e.redoHistory.length+(e.designDraft?.undone.length??0),error:e.sourceEditError,editable:e.sourceEditable}))),i=Q(e=>e.actions);return(0,Z.jsxs)(`div`,{className:`border-border border-b px-3 py-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`button`,{"data-testid":`source.undo`,type:`button`,className:aH,disabled:!r||e===0,onClick:i.undo,children:`Undo`}),(0,Z.jsx)(`button`,{"data-testid":`source.redo`,type:`button`,className:aH,disabled:!r||t===0,onClick:i.redo,children:`Redo`})]}),n!==null&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-status-error mt-1 text-xs`,children:n})]})}function mH(){let e=Q(e=>e.doc),t=Q(e=>e.pendingAuthoredSource),n=Q(e=>e.sourceEditable),{applySourceEdit:r,openSource:i}=Q(e=>e.actions),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(!1);if(e?.channel!==`email`)return null;let l=B_(e.origin.authoredSource).find(t=>t.name===e.fixture);return(0,Z.jsxs)(`div`,{className:`border-border-subtle border-b py-3`,children:[(0,Z.jsxs)(ZB,{children:[`Fixture data · `,e.fixture]}),(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Example input for this fixture. Changes do not replace template bindings or change other fixtures.`}),l===void 0?(0,Z.jsx)(`button`,{type:`button`,className:aH,onClick:i,children:`Open fixture source`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`textarea`,{"aria-label":`Fixture data source`,"data-testid":`source.fixture-data`,className:iH,value:a??l.source,onChange:e=>{o(e.target.value),c(!1)},disabled:!n||t!==null}),(0,Z.jsx)(`button`,{"data-testid":`source.fixture-review`,type:`button`,className:aH,disabled:!n||t!==null||a===null,onClick:()=>c(!0),children:`Review fixture change`}),s&&a!==null&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`pre`,{className:`bg-muted overflow-auto p-2 text-xs`,children:`- ${l.source}\n+ ${a}`}),(0,Z.jsx)(`button`,{"data-testid":`source.fixture-apply`,type:`button`,className:aH,onClick:()=>{r({revision:e.rev,source:e.origin.authoredSource,edits:[{start:l.start,end:l.end,before:l.source,after:a}],design:{label:`Edit fixture data`}}),o(null),c(!1)},children:`Use this change`}),` `,(0,Z.jsx)(`button`,{type:`button`,className:aH,onClick:()=>{o(null),c(!1)},children:`Cancel`})]})]})]})}function hH({selection:e}){let t=Q(e=>`${e.doc?.rev}:${e.doc?.origin.authoredSource}:${e.doc?.channel===`email`?e.doc.fixture:``}`);return(0,Z.jsx)(fH,{selection:e},t)}function gH(){let e=Q(e=>`${e.doc?.rev}:${e.doc?.origin.authoredSource}:${e.doc?.channel===`email`?e.doc.fixture:``}`);return(0,Z.jsx)(mH,{},e)}var _H=[],vH=[],yH=[];function bH({label:e,title:t,children:n}){return(0,Z.jsxs)(`div`,{title:t,className:`mt-1.5 flex items-center justify-between gap-2 first:mt-0`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:e}),n]})}function xH(){let e=Q(e=>e.doc?.variables??vH);return e.length===0?null:(0,Z.jsxs)(`div`,{className:`border-border-subtle border-b py-3`,children:[(0,Z.jsx)(ZB,{children:`Variables`}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-2`,children:e.map(e=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-[12.5px]`,children:[(0,Z.jsx)(XB,{name:e.name,className:`shrink-0`}),(0,Z.jsx)(`span`,{className:`text-placeholder ml-auto text-[11px]`,children:e.required?`required`:`optional`})]},e.name))}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-2.5 text-[11.5px]`,children:`The preview shows the values of the fixture selected above it.`})]})}function SH(){return(0,Z.jsx)(`div`,{className:`py-3`,children:(0,Z.jsx)(_V,{})})}function CH({checks:e}){let{deviceWidth:t,entryFile:n,fixture:r,fixtures:i}=Q(kk(e=>({deviceWidth:NL[e.previewDevice],entryFile:e.doc?.origin.file??null,fixture:e.doc?.channel===`email`?e.doc.fixture:null,fixtures:e.doc?.channel===`email`?e.doc.fixtures:_H})));return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{className:`border-border-subtle border-b py-3`,children:[(0,Z.jsx)(ZB,{children:`Document`}),(0,Z.jsx)(bH,{label:`Width`,children:(0,Z.jsxs)(QB,{children:[t,` `,(0,Z.jsx)(`span`,{className:`text-placeholder text-[10.5px]`,children:`px`})]})}),n!==null&&(0,Z.jsx)(bH,{label:`Entry`,children:(0,Z.jsx)(QB,{children:n})}),r!==null&&(0,Z.jsx)(bH,{label:`Fixture`,title:`${i.length} declared`,children:(0,Z.jsx)(QB,{children:r})})]}),(0,Z.jsx)(gH,{},`${r}:${n}`),(0,Z.jsx)(xH,{}),e&&(0,Z.jsx)(SH,{})]})}function wH({value:e,onChange:t,onCommit:n,placeholder:r,type:i=`text`,testId:a}){return(0,Z.jsx)(`input`,{type:i,value:e,placeholder:r,"data-testid":a,spellCheck:!1,onChange:e=>t(e.target.value),onBlur:n,onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()},className:$(`border-border bg-background text-foreground placeholder:text-placeholder h-7 max-w-none min-w-0 flex-1 rounded-[5px] border px-2.5 text-xs outline-none`,Cz)})}function TH(){let e=Q(e=>e.doc),t=Q(e=>e.metadataError),{saveMetadata:n}=Q(e=>e.actions),r=e?.metadata.fromDefault,[i,a]=(0,W.useState)(r?.name??``),[o,s]=(0,W.useState)(r?.email??``),[c,l]=(0,W.useState)((e?.metadata.replyToDefault??[]).join(`, `)),u=()=>{let e=o.trim();n({fromDefault:e.length===0?null:{email:e,name:i.trim()||void 0}})};return(0,Z.jsxs)(`div`,{className:`py-3`,children:[(0,Z.jsx)(ZB,{children:`Defaults · per send`}),(0,Z.jsx)(bH,{label:`From name`,children:(0,Z.jsx)(wH,{value:i,onChange:a,onCommit:u,placeholder:`Sender name`})}),(0,Z.jsx)(bH,{label:`From email`,children:(0,Z.jsx)(wH,{type:`email`,value:o,onChange:s,onCommit:u,placeholder:`you@domain.com`,testId:`inspector.envelope.from-email`})}),(0,Z.jsx)(bH,{label:`Reply-To`,children:(0,Z.jsx)(wH,{type:`email`,value:c,onChange:l,onCommit:()=>{let e=c.split(`,`).map(e=>e.trim()).filter(e=>e.length>0);n({replyToDefault:e.length===0?null:e})},placeholder:`Comma-separated`})}),t!==null&&(0,Z.jsx)(`p`,{role:`alert`,className:`text-status-error mt-2 text-[11.5px]`,children:t})]})}function EH(){let e=Q(e=>e.metadataEditable),t=Q(e=>e.render);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`border-border-subtle text-muted-foreground border-b py-2.5 text-[11px] leading-relaxed`,children:`Subject and preview text come from the template code and the fixture on screen. From / Reply-To are template defaults, overridden per send.`}),(0,Z.jsxs)(`div`,{className:`border-border-subtle border-b py-3`,children:[(0,Z.jsx)(ZB,{children:`Rendered`}),(0,Z.jsx)(bH,{label:`Subject`,children:(0,Z.jsx)(QB,{children:t?.subject??`No subject`})}),(0,Z.jsx)(bH,{label:`Preview`,children:(0,Z.jsx)(QB,{children:t?.preheader??`No preview text`})})]}),e?(0,Z.jsx)(TH,{}):(0,Z.jsx)(`p`,{className:`text-muted-foreground py-3 text-xs`,children:`This host does not edit sender defaults.`})]})}function DH({selection:e}){let t=Q(e=>e.render?.selections??yH),n=Q(e=>e.render?.html??``),{select:r}=Q(e=>e.actions),i=e.origins[0],a=e.origins.slice(1),o=lc(t,e),s=uc(t,e);return(0,Z.jsxs)(`div`,{"data-slot":`editor-element-inspector`,"data-instance-path":e.instancePath,children:[o.length>1&&(0,Z.jsxs)(`div`,{"data-slot":`editor-element-copies`,className:`border-border/70 border-b py-3`,children:[(0,Z.jsx)(ZB,{children:`Copies`}),(0,Z.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-0.5 p-0`,children:o.map((t,i)=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(aB,{variant:`ghost`,size:`sm`,"data-testid":`inspector.iteration.${t.instancePath}`,"aria-current":t.instancePath===e.instancePath||void 0,onClick:()=>r(t.instancePath),className:$(`w-full justify-start gap-2 px-2 text-left text-[12.5px] font-normal`,t.instancePath===e.instancePath&&`bg-muted text-foreground font-medium`),children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground w-4 tabular-nums`,children:i+1}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:WI(t,n)??`Copy ${i+1}`})]})},t.instancePath))})]}),(0,Z.jsx)(hH,{selection:e},`${e.instancePath}:${e.start}:${e.end}`),(0,Z.jsxs)(fV,{"data-slot":`editor-element-details`,className:`py-1`,children:[(0,Z.jsxs)(pV,{"data-testid":`inspector.details-toggle`,className:`text-muted-foreground hover:text-foreground group/details flex w-full items-center gap-1.5 py-2 font-mono text-[10.5px] font-medium tracking-[0.08em] uppercase outline-none`,children:[(0,Z.jsx)(_R,{className:`size-3 transition-transform group-data-[panel-open]/details:rotate-90`}),`Where it's written`]}),(0,Z.jsxs)(mV,{keepMounted:!0,className:`pb-3 data-[closed]:hidden`,children:[i===void 0?(0,Z.jsx)(`p`,{className:`text-muted-foreground text-[11.5px]`,children:`The renderer produced this element with no authoring on the stack, so nothing in the template points at it.`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(bH,{label:`Written at`,children:(0,Z.jsx)(QB,{testId:`inspector.authoring.origin`,children:VI(i)})}),(0,Z.jsx)(bH,{label:`Kind`,title:e.authored?`This element was written in the template.`:`A compiler primitive produced this element; the authoring above is the call that asked for it.`,children:(0,Z.jsx)(QB,{testId:`inspector.element.provenance`,children:e.authored?`Authored`:`Generated`})}),(0,Z.jsx)(bH,{label:`Rendered as`,children:(0,Z.jsx)(QB,{testId:`inspector.element.tag`,children:e.tag})}),(0,Z.jsx)(`p`,{"data-testid":`inspector.authoring.occurrence`,className:`text-muted-foreground mt-2 text-[11.5px]`,children:e.occurrences>1?`This authoring renders ${e.occurrences} elements here; this is number ${e.occurrence}.`:`This authoring renders one element here.`}),s.length>o.length&&(0,Z.jsxs)(`p`,{"data-testid":`inspector.authoring.definition-scope`,className:`text-muted-foreground mt-1 text-[11.5px]`,children:[s.length,` elements across the whole render come from it, through more than one call site.`]})]}),a.length>0&&(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`Inside, innermost first`}),(0,Z.jsx)(`ol`,{className:`m-0 mt-1 flex list-none flex-col gap-1 p-0`,children:a.map((e,t)=>(0,Z.jsx)(`li`,{"data-testid":`inspector.call-site.${t}`,className:`text-foreground font-mono text-[11.5px] break-all`,children:VI(e)},`${VI(e)}:${t}`))})]})]})]})]})}function OH({embedded:e=!1,checks:t=!0}={}){let{outline:n,selection:r,rightCollapsed:i,rightWidth:a,layoutMode:o}=Q(kk(e=>({outline:e.outline,selection:e.selection,rightCollapsed:e.rightCollapsed,rightWidth:e.rightWidth,layoutMode:e.layoutMode}))),{select:s,selectDocument:c,toggleRight:l}=Q(e=>e.actions),u=r.kind===`element`?n?.index.get(r.instancePath)??null:null,d=r.kind===`envelope`?`envelope`:u===null?`document`:`element`,f=Q(e=>e.doc?.origin.authoredSource??``),p=u===null||n===null?[]:tL(n,u.instancePath).slice(-2).map(e=>({instancePath:e.instancePath,label:XI(e,f)})),m=u===null?void 0:ZI(u),h=!e&&(o===`compact`||o===`narrow`);return(0,Z.jsx)(`aside`,{"aria-label":`Inspector`,"data-testid":`inspector`,"aria-hidden":!e&&i?!0:void 0,inert:!e&&i?!0:void 0,"data-editor-rail":`right`,style:{width:e?`100%`:i?0:a,maxWidth:h?`calc(100% - 48px)`:void 0},className:$(`flex h-full shrink-0 flex-col overflow-hidden bg-background transition-[width,transform,box-shadow] duration-180 ease-out`,!e&&`border-l border-border`,h&&`absolute inset-y-0 right-0 z-40 shadow-[var(--shadow-floating)]`,!e&&i&&`border-l-0`),children:(0,Z.jsxs)(`div`,{className:`flex h-full min-w-0 flex-col`,style:{width:e?`100%`:a,maxWidth:`100%`},children:[(0,Z.jsx)(`div`,{className:`border-border bg-background/95 sticky top-0 z-10 border-b backdrop-blur-md`,children:(0,Z.jsxs)(`div`,{className:`flex min-h-10 items-center gap-2 px-3 py-2`,children:[(0,Z.jsx)(`div`,{className:`text-muted-foreground flex min-w-0 flex-1 items-center gap-0.5 overflow-hidden text-xs`,children:d===`document`?(0,Z.jsx)(`span`,{className:`text-foreground truncate px-1 font-semibold`,children:`Document`}):d===`envelope`?(0,Z.jsx)(`span`,{className:`text-foreground truncate px-1 font-semibold`,children:`Envelope`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(aB,{variant:`ghost`,size:`xs`,onClick:c,"data-testid":`inspector.document`,className:`text-muted-foreground shrink-0 px-1 font-normal`,children:`Email`}),p.map(e=>(0,Z.jsxs)(`span`,{className:`contents`,children:[(0,Z.jsx)(_R,{className:`text-placeholder size-3 shrink-0`}),(0,Z.jsx)(aB,{variant:`ghost`,size:`xs`,onClick:()=>s(e.instancePath),className:`text-muted-foreground max-w-[88px] truncate px-1 font-normal`,children:e.label})]},e.instancePath)),(0,Z.jsx)(_R,{className:`text-placeholder size-3 shrink-0`}),(0,Z.jsx)(`span`,{"data-testid":`inspector.element-name`,className:`text-foreground truncate px-1 font-semibold`,children:u===null?``:XI(u,f)})]})}),u!==null&&(m!==void 0||!u.authored)&&(0,Z.jsx)(`span`,{"data-testid":`inspector.selection-badge`,className:`bg-muted text-muted-foreground shrink-0 rounded-md px-1.5 py-0.5 text-[10.5px] font-medium tabular-nums`,children:u.authored?m:`Generated`}),!e&&(0,Z.jsx)($B,{label:`Collapse inspector`,side:`bottom`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Collapse inspector`,"data-testid":`inspector.collapse`,onClick:l,className:`text-muted-foreground ml-auto`,children:(0,Z.jsx)(FR,{})})})]})}),(0,Z.jsxs)(RM,{"data-samva-scroll-area":`inspector`,className:`relative min-h-0 flex-1`,children:[(0,Z.jsx)(XM,{className:`size-full`,children:(0,Z.jsxs)(`div`,{className:`samva-inspector-content pb-4`,children:[d===`document`&&(0,Z.jsx)(CH,{checks:t}),d===`envelope`&&(0,Z.jsx)(EH,{}),u!==null&&(0,Z.jsx)(DH,{selection:u})]})}),(0,Z.jsx)(nN,{orientation:`vertical`,className:`absolute top-0 right-0 bottom-0 flex w-2.5 touch-none p-0.5 select-none`,children:(0,Z.jsx)(rN,{className:`relative flex-1 rounded-full bg-[var(--editor-scrollbar-thumb)] hover:bg-[var(--editor-scrollbar-thumb-hover)]`})})]})]})})}var kH=$(`samva-editor-context-item`,`grid min-h-8 grid-cols-[1fr_auto] items-center gap-5 rounded-md px-2.5 text-[12.5px] text-foreground outline-none`,`data-[highlighted]:bg-sel-soft data-[highlighted]:text-accent-email`);function AH({children:e,ancestors:t,onSelect:n,onOpenChange:r,portalContainer:i,open:a,anchor:o}){return(0,Z.jsxs)(sP,{open:a,onOpenChange:r,children:[(0,Z.jsx)(lP,{render:e}),(0,Z.jsx)(UN,{container:i,children:(0,Z.jsx)(uP,{anchor:o,sideOffset:2,children:(0,Z.jsxs)(BN,{"aria-label":`Select element`,"data-testid":`node-context-menu.popup`,className:`samva-editor-context-popup samva-editor-shell border-border bg-surface-elevated z-50 min-w-52 rounded-lg border p-1 shadow-[var(--shadow-lg)] outline-none`,children:[(0,Z.jsx)(`div`,{className:`text-muted-foreground px-2.5 py-1 text-[11px]`,children:`Select`}),t.map(e=>(0,Z.jsxs)(zN,{className:kH,"data-testid":`node-context-menu.item.${e.instancePath}`,onClick:()=>n(e.instancePath),children:[(0,Z.jsx)(`span`,{children:e.label}),e.generated?(0,Z.jsx)(`span`,{className:`text-muted-foreground text-[11px]`,children:`generated`}):null]},e.instancePath))]})})})]})}function jH({...e}){return(0,Z.jsx)($N,{"data-slot":`dropdown-menu`,...e})}function MH({...e}){return(0,Z.jsx)(iP,{"data-slot":`dropdown-menu-trigger`,...e})}function NH({align:e=`start`,alignOffset:t=0,side:n=`bottom`,sideOffset:r=4,className:i,...a}){let o=kz();return(0,Z.jsx)(UN,{container:o,children:(0,Z.jsx)(WN,{className:`isolate z-50 outline-none`,align:e,alignOffset:t,side:n,sideOffset:r,children:(0,Z.jsx)(BN,{"data-slot":`dropdown-menu-content`,className:$(`data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 bg-popover text-popover-foreground min-w-32 rounded-lg p-1 shadow-md ring-1 duration-100 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 z-50 max-h-(--available-height) w-(--anchor-width) origin-(--transform-origin) overflow-x-hidden overflow-y-auto outline-none data-closed:overflow-hidden`,i),...a})})})}function PH({...e}){return(0,Z.jsx)(LN,{"data-slot":`dropdown-menu-group`,...e})}function FH({className:e,inset:t,...n}){return(0,Z.jsx)(RN,{"data-slot":`dropdown-menu-label`,"data-inset":t,className:$(`text-muted-foreground px-1.5 py-1 text-xs font-medium data-inset:pl-7`,e),...n})}function IH({className:e,inset:t,variant:n=`default`,...r}){return(0,Z.jsx)(zN,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:$(`focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:text-destructive not-data-[variant=destructive]:focus:**:text-accent-foreground gap-1.5 rounded-md px-1.5 py-1 text-sm data-inset:pl-7 [&_svg:not([class*='size-'])]:size-4 group/dropdown-menu-item relative flex cursor-default items-center outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0`,e),...r})}function LH({className:e,...t}){return(0,Z.jsx)(Ej,{"data-slot":`dropdown-menu-separator`,className:$(`bg-border -mx-1 my-1 h-px`,e),...t})}var RH=(0,W.createContext)({hostBusy:!1,openInNewTab:void 0,showChecks:void 0}),zH=RH.Provider,BH=()=>(0,W.useContext)(RH);function VH({...e}){return(0,Z.jsx)(dP,{"data-slot":`alert-dialog`,...e})}function HH({container:e,...t}){let n=kz();return(0,Z.jsx)(hN,{"data-slot":`alert-dialog-portal`,container:e??n,...t})}function UH({className:e,...t}){return(0,Z.jsx)(oN,{"data-slot":`alert-dialog-overlay`,className:$(`data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs fixed inset-0 isolate z-50`,e),...t})}function WH({className:e,size:t=`default`,...n}){return(0,Z.jsxs)(HH,{children:[(0,Z.jsx)(UH,{}),(0,Z.jsx)(mN,{"data-slot":`alert-dialog-content`,"data-size":t,className:$(`data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 bg-popover text-popover-foreground ring-foreground/10 gap-4 rounded-xl p-4 ring-1 duration-100 data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 outline-none`,e),...n})]})}function GH({className:e,...t}){return(0,Z.jsx)(`div`,{"data-slot":`alert-dialog-header`,className:$(`grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]`,e),...t})}function KH({className:e,...t}){return(0,Z.jsx)(`div`,{"data-slot":`alert-dialog-footer`,className:$(`bg-muted/50 -mx-4 -mb-4 rounded-b-xl border-t p-4 flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end`,e),...t})}function qH({className:e,...t}){return(0,Z.jsx)(wN,{"data-slot":`alert-dialog-title`,className:$(`text-base font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2 font-heading`,e),...t})}function JH({className:e,...t}){return(0,Z.jsx)(cN,{"data-slot":`alert-dialog-description`,className:$(`text-muted-foreground *:[a]:hover:text-foreground text-sm text-balance md:text-pretty *:[a]:underline *:[a]:underline-offset-3`,e),...t})}function YH({className:e,variant:t=`outline`,size:n=`default`,...r}){return(0,Z.jsx)(sN,{"data-slot":`alert-dialog-cancel`,className:$(``,e),render:(0,Z.jsx)(aB,{variant:t,size:n}),...r})}function XH({...e}){return(0,Z.jsx)(yP,{"data-slot":`popover`,...e})}function ZH({...e}){return(0,Z.jsx)(SP,{"data-slot":`popover-trigger`,...e})}function QH({className:e,align:t=`center`,alignOffset:n=0,side:r=`bottom`,sideOffset:i=4,...a}){let o=kz();return(0,Z.jsx)(TP,{container:o,children:(0,Z.jsx)(OP,{align:t,alignOffset:n,side:r,sideOffset:i,className:`isolate z-50`,children:(0,Z.jsx)(jP,{"data-slot":`popover-content`,className:$(`bg-popover text-popover-foreground data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 ring-foreground/10 flex flex-col gap-2.5 rounded-lg p-2.5 text-sm shadow-md ring-1 duration-100 data-[side=inline-start]:slide-in-from-right-2 data-[side=inline-end]:slide-in-from-left-2 z-50 w-72 origin-(--transform-origin) outline-hidden`,e),...a})})})}var $H=e=>j(e,`reason`)&&typeof e.reason==`string`?e.reason:e instanceof Error?e.message:String(e),eU=e=>e.toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}),tU=`hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground relative flex w-full cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-left text-sm outline-none select-none`,nU=({children:e,testId:t})=>(0,Z.jsx)(`p`,{"data-testid":t,className:`text-muted-foreground px-1.5 py-2 text-[12.5px]`,children:e});function rU({testId:e,title:t,detail:n,marked:r,hint:i,onSelect:a}){return(0,Z.jsx)(`div`,{className:`group/row relative`,children:(0,Z.jsxs)(`button`,{type:`button`,"data-testid":e,"data-editor-control":``,onClick:a,className:tU,children:[(0,Z.jsx)(`span`,{className:`flex size-3.5 shrink-0 items-center justify-center`,children:r?(0,Z.jsx)(zR,{className:`size-3.5`}):null}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col items-start`,children:[(0,Z.jsx)(`span`,{className:`w-full truncate text-[13px]`,children:t}),(0,Z.jsx)(`span`,{className:`text-muted-foreground w-full truncate text-[11.5px]`,children:n})]}),i?(0,Z.jsx)(`span`,{"aria-hidden":!0,className:$(`text-muted-foreground pointer-events-none shrink-0 text-[11.5px]`,Dz),children:`Restore`}):null]})})}function iU(){let e=Q(e=>e.lifecycleCapability),t=Q(e=>e.doc!==null),n=Q(e=>e.editable),{beginLifecycle:r,endLifecycle:i,flushSaves:a,adoptLifecycleSnapshot:o}=Q(e=>e.actions),[s,c]=(0,W.useState)(!1),l=(0,W.useRef)(0),[u,d]=(0,W.useState)({status:`loading`}),[f,p]=(0,W.useState)(``),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)(!1),[v,y]=(0,W.useState)(null),b=e?.status===`ready`?e.api:null;if(b===null||!t)return null;let x=u.status===`ready`?u.state:null,S=x?.dirty??!1,C=()=>{let e=++l.current;d({status:`loading`}),a().then(()=>b.inspect()).then(t=>{l.current===e&&d({status:`ready`,state:t})}).catch(t=>{l.current===e&&d({status:`failed`,message:$H(t)})})},w=e=>{c(e),e?(p(``),C()):l.current++},T=e=>{c(!1),x!==null&&(e.commit!==x.baseCommit||x.dirty)&&(y(null),h({commit:e.commit,message:e.message,blocked:x.dirty||x.conflicts.length>0}))},E=()=>{m===null||m.blocked||g||!n||r()&&(_(!0),y(null),a().then(async e=>{let t=await b.inspect();if(t.dirty||t.conflicts.length>0){d({status:`ready`,state:t}),h({...m,blocked:!0});return}o(await b.restore({commit:m.commit,baseRev:e})),h(null)}).catch(e=>y($H(e))).finally(()=>{i(),_(!1)}))},D=f.trim().toLowerCase(),O=x?.commits.filter(({message:e})=>e.toLowerCase().includes(D)),k=D===``||`latest`.includes(D);return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(XH,{open:s,onOpenChange:w,children:[(0,Z.jsx)($B,{label:`Versions`,children:(0,Z.jsx)(ZH,{"data-slot":`editor-version-picker`,render:(0,Z.jsx)(aB,{variant:`ghost`,size:`sm`,"aria-label":`Versions`,"data-testid":`preview-bar.versions`,"data-editor-control":``,disabled:g,className:`text-muted-foreground shrink-0 gap-1 px-2`}),children:g?`Restoring…`:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-1 @max-[28rem]/preview-bar:hidden`,children:[`Latest`,(0,Z.jsx)(hR,{})]}),(0,Z.jsx)(VR,{className:`hidden size-3.5 @max-[28rem]/preview-bar:inline-flex`})]})})}),(0,Z.jsxs)(QH,{side:`bottom`,align:`start`,sideOffset:6,"data-testid":`preview-bar.versions-popup`,className:`w-72 gap-0 p-1`,children:[(0,Z.jsxs)(`label`,{className:`border-border flex items-center gap-2 border-b px-2 pb-1.5`,children:[(0,Z.jsx)(YR,{className:`text-muted-foreground size-3.5 shrink-0`}),(0,Z.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.currentTarget.value),placeholder:`Search versions`,"aria-label":`Search versions`,"data-testid":`preview-bar.versions-search`,"data-editor-control":``,className:`placeholder:text-muted-foreground h-7 w-full min-w-0 bg-transparent text-sm outline-none`})]}),(0,Z.jsxs)(`div`,{className:`samva-editor-scroll max-h-72 overflow-y-auto pt-1`,children:[u.status===`loading`?(0,Z.jsx)(nU,{children:`Loading versions…`}):null,u.status===`failed`?(0,Z.jsxs)(`div`,{className:`flex flex-col items-start gap-2 px-1.5 py-2`,children:[(0,Z.jsx)(`p`,{role:`alert`,className:`text-destructive text-sm`,children:u.message}),(0,Z.jsx)(aB,{variant:`outline`,size:`sm`,"data-testid":`preview-bar.versions-retry`,"data-editor-control":``,onClick:C,children:`Try again`})]}):null,x!==null&&O!==void 0?(0,Z.jsxs)(Z.Fragment,{children:[k?(0,Z.jsx)(rU,{testId:`preview-bar.version-latest`,title:`Latest`,detail:S?`Unsaved changes`:`Saved`,marked:!0,hint:!1,onSelect:()=>c(!1)}):null,O.map(e=>{let t=e.commit===x.baseCommit,n=[t?`Current`:null,eU(e.committedAt),e.isPublished?`Published`:null].filter(e=>e!==null).join(` · `);return(0,Z.jsx)(rU,{testId:`preview-bar.version.${e.commit}`,title:e.message,detail:n,marked:!1,hint:!(t&&!x.dirty),onSelect:()=>T(e)},e.commit)}),!k&&O.length===0?(0,Z.jsx)(nU,{testId:`preview-bar.versions-empty`,children:`No versions match`}):null]}):null]})]})]}),(0,Z.jsx)(VH,{open:m!==null,onOpenChange:e=>{!e&&!g&&h(null)},children:(0,Z.jsxs)(WH,{"data-testid":`preview-bar.restore-dialog`,children:[(0,Z.jsxs)(GH,{children:[(0,Z.jsx)(qH,{children:`Restore this version?`}),(0,Z.jsx)(JH,{children:`“${m?.message??``}” replaces the draft. Newer versions stay in the list, so you can restore them again.`}),n?null:(0,Z.jsx)(JH,{"data-testid":`preview-bar.restore-readonly`,children:`This template is read-only, so its versions can be viewed but not restored.`}),n&&m?.blocked?(0,Z.jsx)(JH,{children:`Save a version first, so your unsaved changes stay in the list.`}):null,v===null?null:(0,Z.jsx)(`p`,{role:`alert`,className:`text-destructive text-sm`,children:v})]}),(0,Z.jsxs)(KH,{children:[(0,Z.jsx)(YH,{"data-testid":`preview-bar.restore-cancel`,"data-editor-control":``,disabled:g,children:`Cancel`}),(0,Z.jsx)(aB,{"data-testid":`preview-bar.restore-confirm`,"data-editor-control":``,disabled:g||!n||m?.blocked===!0,onClick:E,children:g?`Restoring…`:`Restore`})]})]})})]})}var aU=[];function oU({testId:e,className:t}){let{fixtures:n,fixture:r,busy:i,available:a}=Q(kk(e=>({fixtures:e.doc?.fixtures??aU,fixture:e.doc?.fixture??null,busy:e.fixtureBusy,available:e.fixtureCapability?.status===`ready`}))),{viewFixture:o}=Q(e=>e.actions);return!a||r===null||n.length<2?null:(0,Z.jsx)($B,{label:`Sample data the preview shows`,children:(0,Z.jsx)(`span`,{"data-editor-control":``,className:`inline-flex min-w-0`,children:(0,Z.jsx)(vV,{size:`sm`,"aria-label":`Fixture`,"data-slot":`editor-fixture-select`,"data-testid":e,value:r,disabled:i,onChange:e=>o(e.target.value),className:$(`max-w-40 min-w-0 [&_select]:text-xs [&_select]:font-medium`,t),children:n.map(e=>(0,Z.jsx)(yV,{value:e,children:e},e))})})})}function sU(){let{sizeKb:e,sizeSource:t,deviceWidth:n,rendered:r}=Q(kk(e=>({sizeKb:e.sizeKb,sizeSource:e.sizeSource,deviceWidth:NL[e.previewDevice],rendered:e.render!==null})));return r?t===`sent`?{text:`${n} px · ${e} KB`,help:`Width shown, and the size of the email as sent`}:{text:`${n} px · ${e} KB preview`,help:`Width shown, and the size of this preview. The email as sent can be smaller.`}:{text:`${n} px`,help:`Width shown`}}function cU({viewMenu:e,...t}){let{device:n,working:r,canRefresh:i}=Q(kk(e=>({device:e.previewDevice,working:e.fixtureBusy||e.pendingAuthoredSource!==null||e.previewRefreshing,canRefresh:e.doc!==null&&e.pendingAuthoredSource===null&&!e.metadataSaving&&!e.conflict&&!e.lifecycleBusy}))),{setPreviewDevice:a,refreshPreview:o}=Q(e=>e.actions),{hostBusy:s,openInNewTab:c}=BH(),l=sU(),u=r||s;return dz(`editor-preview-bar`,{"data-testid":`preview-bar`,...t},{state:{busy:u},className:`border-border bg-background @container/preview-bar relative flex h-11 shrink-0 items-center gap-1.5 border-b px-2`,props:{children:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(iU,{}),(0,Z.jsxs)(`div`,{"data-slot":`editor-preview-bar-center`,className:`flex min-w-0 flex-1 items-center justify-center gap-1.5`,children:[(0,Z.jsx)(eV,{ariaLabel:`Preview width`,value:n,onChange:a,size:`sm`,options:[{value:`desktop`,title:`Desktop width`,testId:`canvas.device.desktop`,label:(0,Z.jsx)(kR,{className:`size-3.5`})},{value:`mobile`,title:`Phone width`,testId:`canvas.device.mobile`,label:(0,Z.jsx)(OR,{className:`size-3.5`})}]}),(0,Z.jsx)(oU,{testId:`preview-bar.fixture`})]}),(0,Z.jsx)(iV,{}),(0,Z.jsx)($B,{label:l.help,children:(0,Z.jsx)(`span`,{tabIndex:0,"data-slot":`editor-preview-bar-size`,"data-testid":`preview-bar.size`,className:`text-muted-foreground focus-visible:ring-ring/50 shrink-0 rounded-md px-1.5 text-xs leading-7 tabular-nums outline-none focus-visible:ring-3 @max-[28rem]/preview-bar:hidden`,children:l.text})}),c!==void 0&&(0,Z.jsx)(`span`,{className:`inline-flex @max-[28rem]/preview-bar:hidden`,children:(0,Z.jsx)($B,{label:`Open in a new tab`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Open in a new tab`,"data-testid":`preview-bar.open`,"data-editor-control":``,onClick:c,className:`text-muted-foreground`,children:(0,Z.jsx)(KR,{})})})}),(0,Z.jsx)($B,{label:i?`Refresh the preview`:`Refresh waits for your latest edit`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Refresh the preview`,"data-testid":`preview-bar.refresh`,"data-editor-control":``,disabled:!i,onClick:o,className:`text-muted-foreground`,children:(0,Z.jsx)(JR,{})})}),(0,Z.jsx)(`span`,{className:$(`inline-flex`,e===void 0&&`hidden @max-[28rem]/preview-bar:inline-flex`),children:(0,Z.jsxs)(jH,{children:[(0,Z.jsx)(MH,{render:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`More preview options`,"data-testid":`preview-bar.more`,"data-editor-control":``,className:`text-muted-foreground`}),children:(0,Z.jsx)(GR,{})}),(0,Z.jsxs)(NH,{align:`end`,className:`w-60`,children:[(0,Z.jsxs)(PH,{children:[(0,Z.jsx)(FH,{children:`Preview`}),(0,Z.jsx)(`div`,{className:`text-muted-foreground px-1.5 pb-1.5 text-xs tabular-nums`,children:l.text}),c!==void 0&&(0,Z.jsxs)(IH,{"data-editor-control":``,onClick:c,children:[(0,Z.jsx)(KR,{}),`Open in a new tab`]})]}),e!==void 0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(LH,{}),e]})]})]})}),u&&(0,Z.jsx)(`span`,{role:`progressbar`,"aria-label":`Updating the preview`,"data-slot":`editor-preview-bar-progress`,"data-testid":`preview-bar.progress`,className:`pointer-events-none absolute inset-x-0 -bottom-px h-0.5 overflow-hidden`,children:(0,Z.jsx)(`span`,{className:`samva-editor-progress bg-primary absolute inset-y-0 w-2/5`})})]})}})}function lU(){let{stale:e,fixtureError:t}=Q(kk(e=>({stale:e.doc?.channel===`email`&&e.doc.preview.status===`stale`?e.doc.preview.reason:null,fixtureError:e.fixtureError}))),{showChecks:n}=BH(),r=e===null?t:`Showing the last preview that worked. Your latest edit has a problem: ${e}`;return r===null?null:(0,Z.jsxs)(`div`,{role:`status`,"data-slot":`editor-preview-notice`,"data-testid":e===null?`canvas.fixture-error`:`canvas.preview-stale`,className:`border-status-warning/35 bg-status-warning/10 text-foreground flex min-h-9 shrink-0 items-center gap-2 border-b px-3 py-1.5 text-xs`,children:[(0,Z.jsx)(`span`,{className:`bg-status-warning size-1.5 shrink-0 rounded-full`}),(0,Z.jsx)(`span`,{className:`min-w-0 flex-1`,children:r}),e!==null&&n!==void 0&&(0,Z.jsx)(aB,{variant:`outline`,size:`sm`,onClick:n,"data-testid":`canvas.preview-stale.checks`,"data-editor-control":``,className:`bg-background shrink-0`,children:`Show checks`})]})}function uU({embedded:e=!1}={}){let{checks:t,doc:n,readonlyReason:r,rightCollapsed:i,rightWidth:a}=Q(kk(e=>({checks:e.checks,doc:e.doc,readonlyReason:e.readonlyReason,rightCollapsed:e.rightCollapsed,rightWidth:e.rightWidth}))),{toggleRight:o}=Q(e=>e.actions);return!e&&i?null:(0,Z.jsxs)(`aside`,{"data-editor-rail":`right`,style:{width:e?`100%`:a},className:e?`bg-background flex h-full shrink-0 flex-col overflow-hidden`:`border-border bg-background flex h-full shrink-0 flex-col overflow-hidden border-l`,children:[(0,Z.jsxs)(`div`,{className:`border-border-subtle flex h-11 items-center border-b px-3`,children:[(0,Z.jsx)(`span`,{className:`text-[12.5px] font-medium`,children:`Template details`}),!e&&(0,Z.jsx)($B,{label:`Collapse inspector`,side:`bottom`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Collapse inspector`,onClick:o,className:`text-muted-foreground ml-auto`,children:(0,Z.jsx)(FR,{})})})]}),(0,Z.jsxs)(`div`,{className:`samva-editor-scroll min-h-0 flex-1 overflow-y-auto p-4 text-[12.5px]`,children:[(0,Z.jsx)(`p`,{className:`font-medium`,children:`Read-only`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-1`,children:r}),n!==null&&(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-3 font-mono text-[11.5px] break-all`,children:n.origin.file}),(0,Z.jsx)(`div`,{className:`border-border-subtle mt-5 border-t pt-4`,children:(0,Z.jsx)(hV,{checks:t})})]})]})}var dU=()=>typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform)?`⌘`:`Ctrl+`;function fU({percent:e,...t}){let n=Q(e=>e.canvasZoom===`fit`),{setCanvasZoom:r}=Q(e=>e.actions),i=dU(),a=Math.round(e);return dz(`editor-zoom-control`,{role:`group`,"aria-label":`Zoom`,"data-testid":`canvas.zoom-control`,...t},{state:{fit:n,percent:a},className:`bg-popover text-popover-foreground ring-foreground/10 absolute bottom-3 left-1/2 z-20 flex -translate-x-1/2 items-center gap-0.5 rounded-lg p-1 shadow-md ring-1`,props:{children:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($B,{label:`Zoom out`,shortcut:`${i}−`,side:`top`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Zoom out`,"data-testid":`canvas.zoom-out`,"data-editor-control":``,disabled:a<=50,onClick:()=>r(mB(e)),children:(0,Z.jsx)(WR,{})})}),(0,Z.jsx)($B,{label:`Actual size`,shortcut:`${i}0`,side:`top`,children:(0,Z.jsxs)(aB,{variant:`ghost`,size:`sm`,"aria-label":`Zoom ${a}%. Show at actual size`,"data-testid":`canvas.zoom-value`,"data-editor-control":``,onClick:()=>r(100),className:`min-w-13 px-1.5 font-normal tabular-nums`,children:[a,`%`]})}),(0,Z.jsx)($B,{label:`Zoom in`,shortcut:`${i}+`,side:`top`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Zoom in`,"data-testid":`canvas.zoom-in`,"data-editor-control":``,disabled:a>=200,onClick:()=>r(pB(e)),children:(0,Z.jsx)(qR,{})})}),(0,Z.jsx)(VB,{orientation:`vertical`,className:`mx-0.5 h-4!`}),(0,Z.jsx)($B,{label:`Fit the email to the pane`,side:`top`,children:(0,Z.jsx)(UB,{size:`sm`,pressed:n,onPressedChange:e=>{e&&r(`fit`)},"data-testid":`canvas.zoom`,"data-editor-control":``,className:`px-2 text-xs`,children:`Fit`})})]})}})}function pU({pointing:e=!1,active:t=!0,viewMenu:n,...r}){let{doc:i,render:a,outline:o,selection:s,previewDevice:c,canvasZoom:l,previewEpoch:u,canvasMode:d,beforeEdits:f,pins:p,sourceEditable:m}=Q(kk(e=>({doc:e.doc,render:e.render,outline:e.outline,selection:e.selection,previewDevice:e.previewDevice,canvasZoom:e.canvasZoom,previewEpoch:e.previewEpoch,canvasMode:e.canvasMode,beforeEdits:e.designCompare?e.designDraft?.baseRender??null:null,pins:e.pins,sourceEditable:e.sourceEditable}))),h=BI(),{select:g,selectDocument:_,setHovered:v,setCanvasZoom:y}=Q(e=>e.actions),b=Q(e=>e.hoveredCandidatePath===null?null:e.outline?.index.get(e.hoveredCandidatePath)??null),x=kz(),S=_z(`canvas.overlay`),C=(0,W.useRef)(null),[w,T]=(0,W.useState)(1),[E,D]=(0,W.useState)([]),[O,k]=(0,W.useState)(!1),[A,j]=(0,W.useState)(null),M=s.kind===`element`?o?.index.get(s.instancePath)??null:null,N=d===`design`,P=(0,W.useCallback)(e=>{let{canvasMode:t,actions:n,outline:r}=h.getState(),i=t===`point`||e===null||r===null?e:nL(r,e)?.instancePath??e;t===`pin`?i!==null&&n.addPin(i):n.select(i)},[h]),F=i?.channel===`email`?i.fixture:null,I=a?.revision??null,L=(0,W.useMemo)(()=>p.filter(e=>e.fixture===F&&e.revision===I).map(e=>({number:e.number,instancePath:e.instancePath})),[p,F,I]),R=c===`mobile`?375:600;(0,W.useLayoutEffect)(()=>{let e=C.current;if(e===null||typeof ResizeObserver>`u`)return;let t=()=>{let t=Math.max(240,e.clientWidth-80);T(Math.min(1,Math.max(.5,t/R)))};t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[R]);let z=l===`fit`?w:l/100,B=z*100,ee=(0,W.useRef)(B);(0,W.useLayoutEffect)(()=>{ee.current=B},[B]);let te=(0,W.useCallback)(e=>{let t=ee.current;e.kind===`wheel`?y(hB(t,e.deltaY)):e.direction===`in`?y(pB(t)):e.direction===`out`?y(mB(t)):y(100)},[y]);(0,W.useEffect)(()=>{let e=C.current;if(e===null||!t)return;let n=e=>{_B(e)&&(e.preventDefault(),te({kind:`wheel`,deltaY:e.deltaY}))};return e.addEventListener(`wheel`,n,{passive:!1}),()=>e.removeEventListener(`wheel`,n)},[t,te]),(0,W.useEffect)(()=>{if(!t)return;let e=C.current?.closest(`[data-samva-editor-theme]`);if(e==null)return;let n=t=>{let n=gB(t);n!==null&&t.target instanceof Node&&e.contains(t.target)&&(t.preventDefault(),te({kind:`key`,direction:n}))};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[t,te]);let ne=(0,W.useCallback)(t=>{if(e||h.getState().canvasMode===`pin`||o===null||t.instancePath===null){k(!1);return}let n=[...qI(o,t.instancePath),t.instancePath].toReversed().flatMap(e=>{let t=o.index.get(e);return t===void 0?[]:[{instancePath:e,label:HI(t),generated:!t.authored}]});if(n.length===0){k(!1);return}g(t.instancePath),D(n);let{clientX:r,clientY:i}=t;j({getBoundingClientRect:()=>DOMRect.fromRect({x:r,y:i})}),queueMicrotask(()=>k(!0))},[o,e,g,h]),V=f===null?a===null?null:(0,Z.jsx)(kB,{html:a.html,width:R,epoch:u,onSelect:P,onHover:v,onZoomGesture:t?te:void 0,onContextMenu:e?void 0:ne,overlay:(0,Z.jsx)(NB,{renderRevision:a.revision,selected:d===`pin`?null:M,hovered:b,toolbar:N&&M!==null?(0,Z.jsx)(sV,{selection:M}):void 0,pins:L})}):(0,Z.jsx)(kB,{html:f.html,width:R,epoch:u}),re=(0,Z.jsxs)(Z.Fragment,{children:[(i===null||i.channel===`email`)&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(cU,{viewMenu:n}),(0,Z.jsx)(lU,{})]}),(0,Z.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1`,children:[(0,Z.jsxs)(`div`,{"data-canvas-mode":d,className:`samva-editor-workspace relative flex min-h-0 min-w-0 flex-1 flex-col`,children:[S.length>0&&(0,Z.jsx)(`div`,{"data-samva-canvas-status":!0,className:`pointer-events-none absolute inset-x-0 top-3 z-10 flex justify-center`,children:S.map(e=>(0,Z.jsx)(W.Fragment,{children:e.render()},e.id))}),(0,Z.jsx)(`div`,{ref:C,"data-samva-canvas-viewport":!0,className:$(`samva-editor-scroll relative flex-1 [scrollbar-gutter:stable] overflow-auto px-10 pt-10 pb-24 [overflow-anchor:none]`,(p.length>0||d===`pin`)&&`pb-64`),onClick:_,children:i===null?(0,Z.jsx)(`div`,{className:`text-muted-foreground grid h-full place-items-center text-[12.5px]`,children:`Loading document…`}):(0,Z.jsxs)(`div`,{className:`mx-auto`,"data-canvas-zoom":l===`fit`?`fit`:String(l),style:{width:R,zoom:z},onClick:e=>e.stopPropagation(),children:[(0,Z.jsx)(dV,{}),V===null?(0,Z.jsx)(mU,{}):e?V:(0,Z.jsx)(AH,{ancestors:E,onSelect:g,portalContainer:x,anchor:A??void 0,open:O,onOpenChange:e=>k(e&&E.length>0),children:V})]})}),f!==null&&(0,Z.jsx)(`div`,{"data-testid":`canvas.compare-badge`,className:`pointer-events-none absolute inset-x-0 top-3 z-10 flex justify-center`,children:(0,Z.jsx)(`span`,{className:`bg-popover text-popover-foreground ring-foreground/10 rounded-lg px-3 py-1 text-xs font-medium shadow-md ring-1`,children:`Before your edits`})}),i!==null&&(p.length>0||d===`pin`)&&(0,Z.jsx)(`div`,{className:$(`pointer-events-none absolute inset-x-0 z-20 flex flex-col items-center gap-2 px-3`,N?`bottom-16`:`bottom-15`),children:(0,Z.jsx)(oV,{})}),i!==null&&!N&&(0,Z.jsx)(fU,{percent:B}),i!==null&&N&&(0,Z.jsxs)(`div`,{"data-slot":`editor-design-bar`,className:`border-border bg-background @container/design-bar flex h-11 shrink-0 items-center justify-between gap-2 border-t px-2`,children:[(0,Z.jsx)(fU,{percent:B,className:`static translate-x-0 rounded-none bg-transparent p-0 shadow-none ring-0 @max-[34rem]/design-bar:hidden`}),(0,Z.jsx)(aV,{})]})]}),e&&N&&(0,Z.jsx)(`div`,{"data-slot":`editor-design-properties`,"data-testid":`canvas.design-properties`,className:`border-border hidden w-[300px] shrink-0 border-l @min-[44rem]/work-pane:flex`,children:m?(0,Z.jsx)(OH,{embedded:!0,checks:!1}):(0,Z.jsx)(uU,{embedded:!0})})]})]});return dz(`editor-canvas`,{...r},{state:{zoom:l===`fit`?`fit`:String(l),device:c},className:`flex min-h-0 min-w-0 flex-1 flex-col`,props:{children:re}})}function mU(){let e=Q(kk(e=>e.checks.filter(e=>e.severity===`error`))),t=e.length>0;return(0,Z.jsxs)(`div`,{"data-testid":`canvas.unbuilt`,"data-unbuilt-reason":t?`failed`:`not-built`,className:`border-border bg-surface-inset text-foreground rounded-xl border border-dashed p-6 text-[12.5px]`,children:[(0,Z.jsx)(`p`,{className:`font-medium`,children:t?`No preview`:`No preview yet`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-1`,children:t?`The current draft broke the preview. Fix the source and it will come back.`:`Nothing has run this entry yet. The next pass puts the preview here.`}),t&&(0,Z.jsx)(`ul`,{className:`mt-4 space-y-2`,children:e.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsx)(LB,{check:e,actions:(0,Z.jsx)(FB,{check:e})})},e.id))})]})}var hU={body:xR,div:CR,table:wR,tbody:wR,tr:wR,td:LR,th:LR,h1:TR,h2:TR,h3:TR,h4:TR,h5:TR,h6:TR,p:jR,span:jR,a:uz,button:mR,img:ER,hr:yR,br:fR,ul:pR,ol:pR,li:pR},gU=e=>hU[e.toLowerCase()]??CR,_U={Section:wR,Container:wR,Spacer:lz,Divider:cz,Button:mR,Columns:LR,Column:LR,Link:uz},vU=(e,t)=>_U[e]??gU(t),yU=(e,t)=>{let n=WI(e,t)?.replace(/\u200b|\u00ad|\u034f/g,``).trim();if(n===void 0||n===``)return;let r=n.length/2,i=n.slice(0,Math.floor(r)).trim();return i!==``&&n.slice(Math.ceil(r)).trim().startsWith(i.slice(0,12))?i:n};function bU({node:e,depth:t}){let{selectedPath:n,collapsedLayers:r,authoredSource:i,html:a}=Q(kk(e=>({selectedPath:e.selection.kind===`element`?e.selection.instancePath:null,collapsedLayers:e.collapsedLayers,authoredSource:e.doc?.origin.authoredSource??``,html:e.render?.html??``}))),{select:o,toggleLayerExpand:s,setHovered:c}=Q(e=>e.actions),l=e.children.length>0,u=!r.has(e.instancePath),d=n===e.instancePath,{selection:f}=e,p=XI(f,i),m=e.copies>1?`×${e.copies}`:void 0,h=l&&u?void 0:yU(f,a);return(0,Z.jsxs)(`li`,{children:[(0,Z.jsx)(`div`,{className:`group relative`,style:{paddingLeft:t*12},onMouseEnter:()=>c(e.instancePath),onMouseLeave:()=>c(null),children:(0,Z.jsxs)(`div`,{"data-slot":`editor-layer`,"data-selected":d||void 0,className:$(`flex h-[30px] w-full items-center gap-1.5 rounded-md pr-2 pl-1 text-left transition-colors`,d?`bg-muted text-foreground`:`text-foreground hover:bg-muted/60`),children:[l?(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-xs`,"aria-expanded":u,"data-testid":`left-rail.layer.toggle`,"aria-label":`${u?`Collapse`:`Expand`} ${p}`,className:$(`text-muted-foreground size-5 shrink-0 transition-transform hover:bg-transparent`,u&&`rotate-90`),onClick:t=>{t.stopPropagation(),s(e.instancePath)},children:(0,Z.jsx)(_R,{className:`size-3`})}):(0,Z.jsx)(`span`,{"aria-hidden":!0,className:`size-5 shrink-0`}),(0,Z.jsxs)(aB,{variant:`ghost`,size:`sm`,"data-layer-instance-path":e.instancePath,"data-layer-name":p,"data-testid":`layers.node.${e.instancePath}`,onClick:()=>o(e.instancePath),className:`h-full min-w-0 flex-1 justify-start gap-2 rounded-md px-1 text-left font-normal hover:bg-transparent dark:hover:bg-transparent`,children:[(0,W.createElement)(vU(p,f.tag),{className:$(`size-[15px] shrink-0`,d?`text-foreground`:`text-muted-foreground`)}),(0,Z.jsx)(`span`,{className:`shrink-0 text-[12.5px] font-medium`,children:p}),h!==void 0&&(0,Z.jsx)(`span`,{className:`text-muted-foreground min-w-0 flex-1 truncate text-[12px]`,children:h}),m!==void 0&&(0,Z.jsx)(`span`,{className:`text-muted-foreground ml-auto shrink-0 text-[11px] tabular-nums`,children:m})]})]})}),l&&u&&(0,Z.jsx)(`ul`,{className:`m-0 list-none p-0`,children:e.children.map(e=>(0,Z.jsx)(bU,{node:e,depth:t+1},e.instancePath))})]})}function xU(){let e=Q(e=>e.outline),t=(0,W.useMemo)(()=>e===null?[]:eL(e),[e]);if(e===null)return(0,Z.jsx)(`div`,{className:`text-placeholder px-3 py-8 text-center text-xs`,children:`There is no preview yet, so there are no layers to show.`});let n=t.length===1&&t[0]?.selection.tag===`html`?t[0].children:t;return(0,Z.jsx)(`ul`,{className:`m-0 list-none p-0`,children:n.map(e=>(0,Z.jsx)(bU,{node:e,depth:0},e.instancePath))})}function SU(){let{leftCollapsed:e,leftWidth:t,layoutMode:n}=Q(kk(e=>({leftCollapsed:e.leftCollapsed,leftWidth:e.leftWidth,layoutMode:e.layoutMode}))),{toggleLeft:r}=Q(e=>e.actions),i=n===`compact`||n===`narrow`;return(0,Z.jsx)(`aside`,{"aria-label":`Layers`,"aria-hidden":e||void 0,inert:e||void 0,"data-editor-rail":`left`,style:{width:e?0:t,maxWidth:i?`calc(100% - 48px)`:void 0},className:$(`flex h-full shrink-0 flex-col overflow-hidden border-r border-border bg-background transition-[width,transform,box-shadow] duration-180 ease-out`,i&&`absolute inset-y-0 left-0 z-40 shadow-[var(--shadow-floating)]`,e&&`border-r-0`),children:(0,Z.jsxs)(`div`,{className:`flex h-full min-w-0 flex-col`,style:{width:t,maxWidth:`100%`},children:[(0,Z.jsxs)(`div`,{className:`border-border-subtle flex items-center gap-0.5 border-b px-3 py-2`,children:[(0,Z.jsx)(`span`,{className:`text-foreground text-[12.5px] font-medium`,children:`Layers`}),(0,Z.jsx)($B,{label:`Collapse layers`,side:`bottom`,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Collapse layers`,"data-testid":`left-rail.collapse`,onClick:r,className:`text-muted-foreground ml-auto`,children:(0,Z.jsx)(NR,{})})})]}),(0,Z.jsxs)(RM,{"data-samva-scroll-area":`layers`,className:`relative min-h-0 flex-1`,children:[(0,Z.jsx)(XM,{className:`size-full`,children:(0,Z.jsx)(`div`,{className:`px-2 pt-2.5 pb-5`,children:(0,Z.jsx)(xU,{})})}),(0,Z.jsx)(nN,{orientation:`vertical`,className:`absolute top-0 right-0 bottom-0 flex w-2.5 touch-none p-0.5 select-none`,children:(0,Z.jsx)(rN,{className:`relative flex-1 rounded-full bg-[var(--editor-scrollbar-thumb)] hover:bg-[var(--editor-scrollbar-thumb-hover)]`})})]})]})})}var CU=8,wU=24,TU=0,EU=1e4,DU={assistant:`Resize chat`,left:`Resize layers panel`,right:`Resize inspector`},OU={assistant:`agent-column.resize`,left:`left-rail.resize`,right:`inspector.resize`},kU=()=>{document.body.style.cursor=``,document.body.style.userSelect=``};function AU({side:e,...t}){let n=BI(),r=Q(t=>e===`assistant`?t.assistantWidth:e===`left`?t.leftWidth:t.rightWidth),{setAssistantWidth:i,setChatCollapsed:a,setLeftWidth:o,setRightWidth:s}=Q(e=>e.actions),c=(0,W.useRef)(!1),[l,u]=(0,W.useState)(!1),d=(0,W.useCallback)(()=>{c.current&&(c.current=!1,u(!1),kU())},[]);(0,W.useEffect)(()=>()=>{c.current&&kU()},[]);let f=t=>{if(e===`assistant`){let{chatCollapsed:e}=n.getState();if(t<140){a(!0);return}e&&a(!1),i(t)}else e===`left`?o(t):s(t)},p=e=>{(e.pointerType!==`mouse`||e.button===0)&&(e.preventDefault(),e.currentTarget.setPointerCapture?.(e.pointerId),c.current=!0,u(!0),document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`)},m=t=>{if(!c.current)return;let n=t.currentTarget.parentElement;if(n===null)return;let r=n.getBoundingClientRect();f(e===`right`?r.right-t.clientX:t.clientX-r.left)},h=t=>{let n=t.shiftKey?wU:CU,i=e===`right`?`ArrowLeft`:`ArrowRight`,a=e===`right`?`ArrowRight`:`ArrowLeft`,o;if(t.key===i)o=r+n;else if(t.key===a)o=r-n;else if(t.key===`Home`)o=e===`assistant`?280:TU;else if(t.key===`End`)o=e===`assistant`?640:EU;else return;t.preventDefault(),f(o)};return dz(`editor-divider`,{...t},{state:{side:e,dragging:l},className:$(`relative z-10 -mx-1.5 w-3 shrink-0 cursor-col-resize touch-none outline-none`,`before:absolute before:inset-y-0 before:left-1/2 before:w-px before:-translate-x-1/2 before:bg-border before:transition-colors`,`hover:before:w-0.5 hover:before:bg-accent-email`,`data-[dragging]:before:w-0.5 data-[dragging]:before:bg-accent-email`,`focus-visible:before:w-0.5 focus-visible:before:bg-accent-email`,Cz),props:{"data-editor-resize":e,role:`separator`,"aria-orientation":`vertical`,"aria-label":DU[e],"aria-valuenow":r,"aria-valuemin":e===`assistant`?280:void 0,"aria-valuemax":e===`assistant`?640:void 0,"data-testid":OU[e],tabIndex:0,onPointerDown:p,onPointerMove:m,onPointerUp:d,onPointerCancel:d,onLostPointerCapture:d,onKeyDown:h}})}var jU=(0,W.createContext)(null),MU=jU.Provider,NU=()=>{let e=(0,W.useContext)(jU);if(e===null)throw Error(`Editor chrome parts must be rendered inside EditorRoot`);return e};function PU(){let e=Q(e=>e.sourceEditable);return(0,Z.jsx)(`div`,{"data-slot":`editor-design-panel`,"data-testid":`design-panel`,className:`@container/design flex min-h-0 min-w-0 flex-1`,children:(0,Z.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col @min-[36rem]/design:flex-row`,children:[(0,Z.jsxs)(`section`,{"aria-label":`Layers`,"data-slot":`editor-layers`,className:`border-border flex max-h-[40%] min-h-0 shrink-0 flex-col border-b @min-[36rem]/design:max-h-none @min-[36rem]/design:w-72 @min-[36rem]/design:border-r @min-[36rem]/design:border-b-0`,children:[(0,Z.jsx)(`h2`,{className:`text-muted-foreground px-3 pt-3 pb-1 font-mono text-[10.5px] font-medium tracking-[0.08em] uppercase`,children:`Layers`}),(0,Z.jsxs)(RM,{"data-samva-scroll-area":`layers`,className:`relative min-h-0 flex-1`,children:[(0,Z.jsx)(XM,{className:`size-full`,children:(0,Z.jsx)(`div`,{className:`px-2 pb-4`,children:(0,Z.jsx)(xU,{})})}),(0,Z.jsx)(nN,{orientation:`vertical`,className:`absolute top-0 right-0 bottom-0 flex w-2.5 touch-none p-0.5 select-none`,children:(0,Z.jsx)(rN,{className:`relative flex-1 rounded-full bg-[var(--editor-scrollbar-thumb)] hover:bg-[var(--editor-scrollbar-thumb-hover)]`})})]})]}),(0,Z.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1`,children:e?(0,Z.jsx)(OH,{embedded:!0,checks:!1}):(0,Z.jsx)(uU,{embedded:!0})})]})})}var FU={preview:{label:`Preview`,hint:`The email`,Icon:SR},source:{label:`Source`,hint:`The template's code`,Icon:HR},design:{label:`Design`,hint:`Layers and properties`,Icon:DR},review:{label:`Review`,hint:`Changes to look over`,Icon:UR},checks:{label:`Checks`,hint:`Clients, size and links`,Icon:BR}};function IU(){let{errorCount:e,warnCount:t}=Q(kk(e=>{let t=OL(e.checks);return{errorCount:t.errorCount,warnCount:t.warnCount}})),n=e+t;return n===0?null:(0,Z.jsx)(zB,{variant:e>0?`destructive`:`secondary`,"data-testid":`work-pane.checks-badge`,className:`h-4 min-w-4 px-1 tabular-nums`,children:n})}function LU(){let e=Q(e=>e.workTabs),t=Q(e=>e.actions.openWorkTab),n=gz(`rail.review`)??null;return(0,Z.jsxs)(PH,{children:[(0,Z.jsx)(FH,{children:`Open a view`}),ML.filter(e=>e!==`review`||n!==null).map(n=>{let{label:r,hint:i,Icon:a}=FU[n];return(0,Z.jsxs)(IH,{"data-testid":`work-pane.add.${n}`,"data-editor-control":``,onClick:()=>t(n),className:`py-1.5`,children:[(0,Z.jsx)(a,{className:`text-muted-foreground`}),(0,Z.jsxs)(`span`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Z.jsx)(`span`,{children:r}),(0,Z.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:i})]}),e.includes(n)&&(0,Z.jsx)(zR,{className:`text-muted-foreground`})]},n)})]})}var RU=$(iB({variant:`ghost`,size:`sm`}),`text-muted-foreground data-active:bg-muted data-active:text-foreground shrink-0 text-[13px]`);function zU({split:e,visible:t=!0,...n}){let{workTabs:r,activeWorkTab:i,chatCollapsed:a,narrow:o}=Q(kk(e=>({workTabs:e.workTabs,activeWorkTab:e.activeWorkTab,chatCollapsed:e.chatCollapsed,narrow:e.layoutMode===`narrow`}))),{openWorkTab:s,closeWorkTab:c,setChatCollapsed:l}=Q(e=>e.actions),u=gz(`rail.review`)??null,d=r.filter(e=>e!==`review`||u!==null),f=i!==`preview`&&!d.includes(i)?`preview`:i,p=a?`Show chat`:`Collapse chat`,m=o&&d.length===0;return dz(`editor-work-pane`,{"aria-label":`Work pane`,"data-testid":`work-pane`,...n},{state:{tab:f,split:e},tag:`section`,className:`bg-background @container/work-pane flex min-h-0 min-w-0 flex-1 flex-col`,props:{children:(0,Z.jsxs)(IP,{value:f,onValueChange:e=>{(e===`preview`||ML.some(t=>t===e))&&s(e)},className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[!m&&(0,Z.jsxs)(`div`,{"data-slot":`editor-work-pane-header`,className:`border-border flex h-11 shrink-0 items-center gap-1 border-b px-2`,children:[e&&(0,Z.jsx)($B,{label:p,children:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":p,"aria-pressed":a,"data-testid":`work-pane.toggle-chat`,"data-editor-control":``,onClick:()=>l(!a),className:`text-muted-foreground mr-0.5`,children:a?(0,Z.jsx)(MR,{}):(0,Z.jsx)(NR,{})})}),(0,Z.jsxs)(KP,{"data-slot":`editor-work-pane-tabs`,"aria-label":`Work pane views`,className:$(`samva-editor-scroll-hidden flex h-full min-w-0 items-center gap-1 overflow-x-auto`,o&&`px-2`),children:[(0,Z.jsxs)(VP,{value:`preview`,"data-slot":`editor-work-pane-tab`,"data-testid":`work-pane.tab.preview`,"data-editor-control":``,"aria-label":o?`Preview`:void 0,className:$(RU,o&&`px-2`),children:[(0,Z.jsx)(SR,{}),o?null:`Preview`]}),d.map(e=>{let{label:t,Icon:n}=FU[e];return(0,Z.jsxs)(`span`,{"data-slot":`editor-work-pane-tab-group`,className:`group/row relative inline-flex shrink-0 items-center`,children:[(0,Z.jsxs)(VP,{value:e,"data-slot":`editor-work-pane-tab`,"data-testid":`work-pane.tab.${e}`,"data-editor-control":``,"aria-label":o?t:void 0,className:$(RU,o?`px-2`:`pr-7`),children:[(0,Z.jsx)(n,{}),o?null:t,e===`review`&&u?.badge,e===`checks`&&(0,Z.jsx)(IU,{})]}),(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-xs`,"aria-label":`Close ${t}`,"data-slot":`editor-work-pane-tab-close`,"data-testid":`work-pane.close.${e}`,"data-editor-control":``,onClick:()=>c(e),className:$(`text-muted-foreground size-5 rounded-sm`,o?`relative`:`absolute right-1`,Dz,`group-has-[[data-active]]/row:opacity-100`),children:(0,Z.jsx)(RR,{className:`size-3`})})]},e)})]}),(0,Z.jsxs)(jH,{children:[(0,Z.jsx)($B,{label:`Add a view`,children:(0,Z.jsx)(MH,{"data-slot":`editor-work-pane-add`,render:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`Add a view`,"data-testid":`work-pane.add`,"data-editor-control":``,className:`text-muted-foreground`}),children:(0,Z.jsx)(qR,{})})}),(0,Z.jsx)(NH,{"data-testid":`work-pane.add-menu`,className:`w-60`,children:(0,Z.jsx)(LU,{})})]})]}),(0,Z.jsx)(GP,{value:`preview`,keepMounted:!0,"data-slot":`editor-work-pane-panel`,"data-testid":`work-pane.panel.preview`,className:`flex min-h-0 min-w-0 flex-1 outline-none`,children:(0,Z.jsx)(pU,{pointing:!0,active:t&&f===`preview`,viewMenu:m?(0,Z.jsx)(LU,{}):void 0})}),f===`source`&&(0,Z.jsx)(GP,{value:`source`,"data-slot":`editor-work-pane-panel`,className:`flex min-h-0 min-w-0 flex-1 outline-none`,children:(0,Z.jsx)(jz,{})}),f===`design`&&(0,Z.jsx)(GP,{value:`design`,"data-slot":`editor-work-pane-panel`,className:`flex min-h-0 min-w-0 flex-1 outline-none`,children:(0,Z.jsx)(PU,{})}),f===`review`&&u!==null&&(0,Z.jsx)(GP,{value:`review`,"data-slot":`editor-work-pane-panel`,"data-testid":`work-pane.panel.review`,className:`samva-editor-scroll min-h-0 flex-1 overflow-y-auto px-4 pt-4 pb-6 outline-none`,children:u.content}),f===`checks`&&(0,Z.jsx)(GP,{value:`checks`,"data-slot":`editor-work-pane-panel`,"data-testid":`work-pane.panel.checks`,className:`samva-editor-scroll min-h-0 flex-1 overflow-y-auto outline-none`,children:(0,Z.jsx)(`div`,{className:`max-w-2xl px-4 pt-4 pb-8`,children:(0,Z.jsx)(_V,{})})})]})}})}function BU(){let e=Q(e=>e.sourceEditable),t=Q(e=>e.leftCollapsed),n=Q(e=>e.rightCollapsed),r=Q(e=>e.layoutMode),i=Q(e=>e.chatCollapsed),a=Q(e=>e.focusedPane),o=gz(`rail.assistant`)!==void 0,s=Q(e=>e.workspaceView),c=BI(),l=e=>c.setState({workspaceView:e}),{idBase:u}=NU();if(o){let e=r!==`wide`,t=e?a!==`assistant`:i;return(0,Z.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1`,"data-agent-workspace-layout":e?`focused`:`split`,children:[(0,Z.jsx)(`div`,{id:`${u}-pane-assistant`,role:e?`tabpanel`:void 0,"aria-labelledby":e?`${u}-tab-assistant`:void 0,hidden:t,className:$(!e&&`contents`,e&&`flex h-full min-h-0 min-w-0 flex-1`),children:(0,Z.jsx)(xz,{hidden:t})}),!e&&!i&&(0,Z.jsx)(AU,{side:`assistant`}),(0,Z.jsx)(`div`,{id:`${u}-pane-preview`,role:e?`tabpanel`:void 0,"aria-labelledby":e?`${u}-tab-preview`:void 0,hidden:e&&a!==`preview`,className:`flex min-h-0 min-w-0 flex-1`,children:(0,Z.jsx)(zU,{split:!e,visible:!e||a===`preview`})})]})})}return(0,Z.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,Z.jsx)(pH,{}),(0,Z.jsx)(Fz,{value:s,onChange:l,children:s===`source`?(0,Z.jsx)(jz,{}):(0,Z.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1`,children:[(0,Z.jsx)(SU,{}),!t&&(0,Z.jsx)(AU,{side:`left`}),(0,Z.jsx)(pU,{}),!n&&(0,Z.jsx)(AU,{side:`right`}),e?(0,Z.jsx)(OH,{}):(0,Z.jsx)(uU,{})]})})]})}var VU=RegExp(`\\s${ac}="[^"]*"`,`g`),HU=e=>e.replace(VU,``),UU=e=>{let t=e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``);return t===``?`email`:t},WU=(e,t)=>{let n=new Blob([HU(e)],{type:`text/html;charset=utf-8`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${UU(t)}.html`,document.body.appendChild(i),i.click(),i.remove(),URL.revokeObjectURL(r)},GU=`image/png,image/jpeg,image/gif,image/webp,.woff2`,KU=1048576,qU=(e,t)=>{let n=e?.lastIndexOf(`/`)??-1;return`${e===void 0||n<0?``:e.slice(0,n+1)}assets/${t}`},JU=e=>{let t=e.lastIndexOf(`.`);return t>e.lastIndexOf(`/`)?e.slice(t):``},YU=e=>j(e,`_tag`)&&e._tag===`ProjectFileExists`,XU=e=>j(e,`reason`)&&typeof e.reason==`string`?e.reason:`The template project operation failed.`,ZU=e=>e.isPublished?`Published`:e.isHead?`Current saved version`:`Saved version`;function QU({file:e,content:t,busy:n,onChange:r,onApply:i,onReplace:a}){let o=e.status===`conflicted`;return(0,Z.jsxs)(`div`,{className:`border-border space-y-3 rounded-lg border p-3`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`h4`,{className:`truncate font-mono text-xs font-semibold`,children:e.path}),(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:e.status})]}),e.binary===!0?(0,Z.jsx)(`div`,{className:`space-y-3`,"data-testid":`lifecycle-sheet.binary-file`,children:e.status===`deleted`?(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Removed from the draft. Save a version to keep this change.`}):(0,Z.jsxs)(Z.Fragment,{children:[(e.status===`added`||e.status===`modified`)&&(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Unsaved until you save a version.`}),(0,Z.jsx)(`button`,{type:`button`,disabled:n,"data-testid":`lifecycle-sheet.replace-file`,onClick:a,className:$(`border-border hover:bg-muted rounded-md border px-3 py-2 text-xs disabled:opacity-50`,Cz),children:`Replace file`})]})}):o?(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Resolve this file below before editing its workspace source.`}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`textarea`,{"aria-label":`Project source for ${e.path}`,"data-testid":`lifecycle-sheet.file-source.${e.path}`,value:t,onChange:e=>r(e.target.value),disabled:n,spellCheck:!1,className:`border-border bg-surface-inset text-foreground min-h-52 w-full resize-y rounded-md border p-3 font-mono text-xs outline-none disabled:opacity-60`}),(0,Z.jsx)(`button`,{type:`button`,disabled:n||t===e.content,"data-testid":`lifecycle-sheet.apply-file.${e.path}`,onClick:()=>i(t),className:$(`bg-primary text-primary-foreground rounded-md px-3 py-2 text-xs font-medium disabled:opacity-50`,Cz),children:`Apply file`})]})]})}function $U({conflict:e,busy:t,onResolve:n}){let[r,i]=(0,W.useState)(e.draft??e.main??``);return(0,Z.jsxs)(`article`,{className:`border-status-warning/45 space-y-3 rounded-lg border p-4`,children:[(0,Z.jsx)(`h4`,{className:`font-mono text-xs font-semibold`,children:e.path}),(0,Z.jsxs)(`details`,{className:`border-border rounded-md border`,children:[(0,Z.jsx)(`summary`,{className:`hover:bg-muted cursor-pointer px-3 py-2 text-xs font-medium`,children:`Compare base, draft, and main`}),(0,Z.jsx)(`div`,{className:`divide-border border-border divide-y border-t`,children:[[`Base`,e.base],[`Draft`,e.draft],[`Latest saved version`,e.main]].map(([e,t])=>(0,Z.jsxs)(`div`,{className:`space-y-1 p-3`,children:[(0,Z.jsx)(`p`,{className:`text-muted-foreground text-[11px] font-medium`,children:e}),(0,Z.jsx)(`pre`,{className:`samva-editor-scroll max-h-32 overflow-auto font-mono text-xs whitespace-pre-wrap`,children:t??`File does not exist`})]},e))})]}),(0,Z.jsx)(`textarea`,{"aria-label":`Resolved source for ${e.path}`,"data-testid":`lifecycle-sheet.conflict-source.${e.path}`,value:r,onChange:e=>i(e.target.value),spellCheck:!1,className:`border-border bg-surface-inset text-foreground min-h-40 w-full resize-y rounded-md border p-3 font-mono text-xs outline-none`}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>n(`draft`),"data-testid":`lifecycle-sheet.keep-draft`,className:$(`border-border hover:bg-muted rounded-md border px-3 py-2 text-xs`,Cz),children:`Keep draft`}),(0,Z.jsx)(`button`,{type:`button`,disabled:t,onClick:()=>n(`main`),className:$(`border-border hover:bg-muted rounded-md border px-3 py-2 text-xs`,Cz),children:`Use saved version`}),(0,Z.jsx)(`button`,{type:`button`,disabled:t,"data-testid":`lifecycle-sheet.resolve-edited.${e.path}`,onClick:()=>n({content:r}),className:$(`bg-primary text-primary-foreground rounded-md px-3 py-2 text-xs font-medium`,Cz),children:`Use edited source`})]})]})}function eW({open:e,onClose:t,onLockedAction:n}){return e?(0,Z.jsx)(tW,{onClose:t,onLockedAction:n}):null}function tW({onClose:e,onLockedAction:t}){let n=kz(),r=Q(e=>e.doc),i=Q(e=>e.lifecycleCapability),{beginLifecycle:a,endLifecycle:o,flushSaves:s,adoptLifecycleSnapshot:c}=Q(e=>e.actions),l=r!==null&&i?.status===`ready`,[u,d]=(0,W.useState)(null),[f,p]=(0,W.useState)(null),[m,h]=(0,W.useState)(null),[g,_]=(0,W.useState)({}),[v,y]=(0,W.useState)(()=>l?`loading`:null),b=(0,W.useRef)(null),x=(0,W.useRef)(null),[S,C]=(0,W.useState)(null),[w,T]=(0,W.useState)(null),[E,D]=(0,W.useState)(null),[O,k]=(0,W.useState)(l);if(l!==O&&(k(l),l&&(y(`loading`),d(null),T(null),D(null),p(null),h(null),_({}),C(null))),(0,W.useEffect)(()=>{if(i?.status!==`ready`)return;let e=!1;return s().then(()=>i.api.inspect()).then(t=>{if(e)return;d(t);let n=r?.origin.kind===`tsx`?r.origin.file:void 0;h(e=>e!==null&&t.files.some(({path:t})=>t===e)?e:n!==void 0&&t.files.some(({path:e})=>e===n)?n:t.files[0]?.path??null)}).catch(t=>{e||T(XU(t))}).finally(()=>{e||y(null)}),()=>{e=!0}},[r,s,i]),i===void 0)return null;if(i.status===`locked`)return(0,Z.jsx)(SN,{open:!0,onOpenChange:t=>!t&&e(),children:(0,Z.jsxs)(hN,{container:n,children:[(0,Z.jsx)(oN,{className:`fixed inset-0 z-[110] bg-[var(--editor-backdrop,rgb(0_0_0/0.28))]`}),(0,Z.jsx)(CN,{className:`fixed inset-0 z-[111] grid place-items-center p-4`,children:(0,Z.jsxs)(mN,{className:`border-border bg-popover w-full max-w-lg rounded-xl border p-5 shadow-[var(--shadow-floating)]`,children:[(0,Z.jsx)(wN,{className:`text-base font-semibold`,children:`Publishing is unavailable`}),(0,Z.jsx)(cN,{className:`text-muted-foreground mt-2 text-sm`,"data-testid":`lifecycle-sheet.locked-reason`,children:i.upsell.reason}),(0,Z.jsx)(`a`,{"data-testid":`lifecycle-sheet.upsell-cta`,className:$(`bg-primary text-primary-foreground mt-4 inline-flex rounded-md px-3 py-2 text-sm font-medium`,Cz),href:i.upsell.cta.href,onClick:e=>{t!==void 0&&(e.preventDefault(),t())},children:i.upsell.cta.label}),(0,Z.jsx)(sN,{className:$(`border-border hover:bg-muted mt-4 ml-2 inline-flex rounded-md border px-3 py-2 text-sm font-medium`,Cz),children:`Close`})]})})]})});let A=u?.commits.find(({commit:e})=>e===f),j=u?.files.find(({path:e})=>e===m),M=j?.content??``,N=j===void 0?void 0:g[j.path],P=N?.baseContent===M?N.content:M,F=u?.files.some(e=>{let t=g[e.path],n=e.content??``;return t?.baseContent===n&&t.content!==n})??!1,I=u!==null&&!u.dirty&&u.conflicts.length===0&&!F,L=u?.commits.find(({commit:e})=>e===u.baseCommit),R=I&&u?.baseCommit===u.remoteHead,z=async()=>d(await i.api.inspect()),B=()=>{u!==null&&R&&v===null&&a()&&(y(`publish`),T(null),i.api.publish({baseRev:u.rev,commit:u.baseCommit}).then(async()=>{await z(),D(`Published the current saved version.`)}).catch(e=>T(XU(e))).finally(()=>{o(),y(null)}))},ee=()=>{u!==null&&A!==void 0&&!A.isHead&&I&&v===null&&a()&&(y(`restore`),T(null),s().then(e=>i.api.restore({commit:A.commit,baseRev:e})).then(async e=>{c(e),await z(),p(null),D(`Restored the saved version to the draft. Save a version to keep this restore.`)}).catch(e=>T(XU(e))).finally(()=>{o(),y(null)}))},te=(e,t)=>{u!==null&&v===null&&a()&&(y(`resolve`),T(null),s().then(n=>i.api.resolveConflict({path:e.path,baseRev:n,resolution:t})).then(t=>{d(t),D(`Resolved ${e.path}.`)}).catch(e=>T(XU(e))).finally(()=>{o(),y(null)}))},ne=(e,t)=>{u!==null&&v===null&&(y(`file`),T(null),i.api.updateFile({path:e.path,baseRev:u.rev,content:t}).then(t=>{d(t),_(t=>{let{[e.path]:n,...r}=t;return r}),D(`Updated ${e.path}.`)}).catch(e=>T(XU(e))).finally(()=>y(null)))},V=(e,t,n)=>{u!==null&&v===null&&(y(`file`),T(null),D(null),C(null),i.api.putAsset({path:e,baseRev:u.rev,bytes:t,replace:n}).then(t=>{d(t),h(e),D(`${n?`Replaced`:`Added`} ${e}. Save a version to keep this change.`)}).catch(n=>{YU(n)?C({path:e,bytes:t}):T(XU(n))}).finally(()=>y(null)))},re=e=>{let t=b.current;t!==null&&(x.current=e===null?null:{replacePath:e},t.accept=e===null?GU:JU(e),t.value=``,t.click())},ie=e=>{let t=x.current;if(x.current=null,e===void 0||u===null)return;if(e.size>KU){D(null),T(`${e.name} is larger than 1 MB. Choose a smaller file.`);return}let n=r?.origin.kind===`tsx`?r.origin.file:void 0,i=t?.replacePath??qU(n,e.name);e.arrayBuffer().then(e=>{let n=new Uint8Array(e);if(t===null&&u.files.some(e=>e.path===i)){T(null),D(null),C({path:i,bytes:n});return}V(i,n,t!==null)}).catch(e=>T(XU(e)))};return(0,Z.jsx)(OF,{open:!0,onOpenChange:t=>!t&&e(),swipeDirection:`right`,children:(0,Z.jsxs)(TF,{container:n,children:[(0,Z.jsx)(tF,{className:`fixed inset-0 z-[110] bg-[var(--editor-backdrop,rgb(0_0_0/0.28))]`}),(0,Z.jsx)(pI,{className:`pointer-events-none fixed inset-0 z-[111] flex justify-end`,children:(0,Z.jsxs)(wF,{className:`border-border bg-popover pointer-events-auto flex h-full w-full max-w-2xl flex-col border-l shadow-[var(--shadow-floating)]`,children:[(0,Z.jsxs)(`header`,{className:`border-border flex items-center justify-between border-b px-5 py-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(XF,{className:`text-base font-semibold`,children:`Publish and saved versions`}),(0,Z.jsx)(iF,{className:`text-muted-foreground mt-0.5 text-xs`,children:`Save keeps a named version. Restore brings an older version into your draft.`})]}),(0,Z.jsx)(nF,{"data-testid":`lifecycle-sheet.close`,className:$(`hover:bg-muted rounded-md px-2 py-1 text-sm`,Cz),children:`Close`})]}),(0,Z.jsxs)(`div`,{className:`samva-editor-scroll min-h-0 flex-1 space-y-6 overflow-y-auto p-5`,children:[v===`loading`&&(0,Z.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Loading saved versions…`}),w!==null&&(0,Z.jsx)(`p`,{className:`text-status-error text-sm`,role:`alert`,children:w}),E!==null&&(0,Z.jsx)(`p`,{className:`text-status-success text-sm`,role:`status`,"data-testid":`lifecycle-sheet.notice`,children:E}),u!==null&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`section`,{className:`border-border bg-muted/30 space-y-3 rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Current saved version`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:L?.message??`Current saved version`})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:B,disabled:!R||v!==null,"data-testid":`lifecycle-sheet.confirm-publish`,className:$(`bg-primary text-primary-foreground rounded-md px-3 py-2 text-sm font-medium disabled:opacity-50`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:v===`publish`?`Publishing…`:`Publish saved version`})]}),!I&&(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,"data-testid":`lifecycle-sheet.cleanliness-warning`,children:u.conflicts.length>0?`Resolve workspace conflicts before Save or Publish.`:`The draft has unsaved changes. Save a version before publishing or restoring.`}),I&&u.baseCommit!==u.remoteHead&&(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`The saved version changed elsewhere. Refresh before publishing.`})]}),(0,Z.jsxs)(`section`,{className:`space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Project files`}),(0,Z.jsx)(`button`,{type:`button`,disabled:v!==null,"data-testid":`lifecycle-sheet.add-file`,onClick:()=>re(null),className:$(`border-border hover:bg-muted rounded-md border px-3 py-1.5 text-xs disabled:opacity-50`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:`Add file`}),(0,Z.jsx)(`input`,{ref:b,type:`file`,accept:GU,hidden:!0,"data-testid":`lifecycle-sheet.add-file-input`,onChange:e=>ie(e.target.files?.[0])})]}),(0,Z.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Add PNG, JPEG, GIF, or WebP images and WOFF2 fonts up to 1 MB.`}),S!==null&&(0,Z.jsxs)(`div`,{className:`border-status-warning/45 space-y-3 rounded-lg border p-3`,"data-testid":`lifecycle-sheet.replace-prompt`,children:[(0,Z.jsxs)(`p`,{className:`text-xs`,children:[(0,Z.jsx)(`span`,{className:`font-mono`,children:S.path}),` already exists. Replace it with the file you chose?`]}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(`button`,{type:`button`,disabled:v!==null,"data-testid":`lifecycle-sheet.confirm-replace`,onClick:()=>V(S.path,S.bytes,!0),className:$(`bg-primary text-primary-foreground rounded-md px-3 py-2 text-xs font-medium disabled:opacity-50`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:`Replace file`}),(0,Z.jsx)(`button`,{type:`button`,disabled:v!==null,onClick:()=>C(null),className:$(`border-border hover:bg-muted rounded-md border px-3 py-2 text-xs`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:`Cancel`})]})]}),(0,Z.jsx)(`div`,{className:`border-border divide-border divide-y rounded-lg border`,children:u.files.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`lifecycle-sheet.file.${e.path}`,onClick:()=>h(e.path),className:$(`hover:bg-muted flex w-full items-center justify-between gap-4 px-3 py-2 text-left`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`,m===e.path&&`bg-muted`),children:[(0,Z.jsx)(`span`,{className:`truncate font-mono text-xs`,children:e.path}),(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:e.status})]},e.path))}),j!==void 0&&(0,Z.jsx)(QU,{file:j,content:P,busy:v!==null,onChange:e=>_(t=>{if(e===M){let{[j.path]:e,...n}=t;return n}return{...t,[j.path]:{baseContent:M,content:e}}}),onApply:e=>ne(j,e),onReplace:()=>re(j.path)},`${j.path}:${j.content??``}`)]}),u.conflicts.length>0&&(0,Z.jsxs)(`section`,{className:`space-y-3`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Resolve conflicts`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:`Choose either side or edit the final file. Save remains blocked until every path is resolved.`})]}),u.conflicts.map(e=>(0,Z.jsx)($U,{conflict:e,busy:v!==null,onResolve:t=>te(e,t)},e.path))]}),(0,Z.jsxs)(`section`,{className:`space-y-2`,children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Saved versions`}),(0,Z.jsx)(`div`,{className:`space-y-2`,children:u.commits.map(e=>(0,Z.jsxs)(`button`,{type:`button`,"data-testid":`lifecycle-sheet.commit.${e.commit}`,onClick:()=>p(e.commit),className:$(`border-border hover:bg-muted flex w-full items-start justify-between gap-4 rounded-lg border p-3 text-left`,f===e.commit&&`ring-primary ring-2`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:[(0,Z.jsxs)(`span`,{className:`min-w-0`,children:[(0,Z.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.message}),(0,Z.jsx)(`span`,{className:`text-muted-foreground mt-1 block text-xs`,children:e.committedAt.toLocaleString()})]}),(0,Z.jsx)(`span`,{className:`text-muted-foreground shrink-0 text-xs`,children:ZU(e)})]},e.commit))})]}),A!==void 0&&!A.isHead&&(0,Z.jsxs)(`section`,{className:`border-border space-y-3 rounded-lg border p-4`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Restore saved version`}),(0,Z.jsxs)(`p`,{className:`text-muted-foreground mt-1 text-xs`,children:[`Bring “`,A.message,`” into the current draft. Save a version when you want to keep the restored draft.`]})]}),(0,Z.jsx)(`button`,{type:`button`,onClick:ee,disabled:!I||v!==null,"data-testid":`lifecycle-sheet.restore`,className:$(`border-border hover:bg-muted rounded-md border px-3 py-2 text-sm`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:v===`restore`?`Restoring…`:`Restore this version`})]})]})]})]})})]})})}function nW({container:e,children:t}){return(0,Z.jsx)(Oz,{value:e,children:t})}var rW={desktop:600,mobile:375},iW=`▤`,aW=`Copy code`;function oW({open:e,onClose:t}){return e?(0,Z.jsx)(sW,{onClose:t}):null}function sW({onClose:e}){let t=kz(),{doc:n,render:r,checks:i,previewDevice:a}=Q(kk(e=>({doc:e.doc,render:e.render,checks:e.checks,previewDevice:e.previewDevice}))),[o,s]=(0,W.useState)(`preview`),[c,l]=(0,W.useState)(a),[u,d]=(0,W.useState)(`light`),[f,p]=(0,W.useState)(n?.channel);n?.channel!==f&&(p(n?.channel),s(`preview`));let[m,h]=(0,W.useState)(a);if(a!==m&&(h(a),s(`preview`),l(a),d(`light`)),n===null)return null;let g=n.metadata.fromDefault,_=(e,t)=>({value:e,label:t,testId:`preview-overlay.view.${e}`}),v=n.channel===`email`?[_(`preview`,`Preview`),_(`html`,`HTML`),_(`text`,`Text`),_(`source`,`TSX`)]:n.channel===`sms`?[_(`preview`,`Preview`),_(`text`,`Text`),_(`source`,`TSX`)]:[_(`preview`,`Preview`),_(`payload`,`Payload`),_(`source`,`TSX`)],y=o===`source`?n.origin.authoredSource:o===`html`&&r!==null?r.html:o===`text`&&r!==null?r.text:o===`text`&&n.channel===`sms`&&n.render!==null?n.render.text:o===`payload`&&n.channel===`whatsapp`&&n.render!==null?JSON.stringify(n.render,null,2):``;return(0,Z.jsx)(SN,{open:!0,onOpenChange:t=>!t&&e(),children:(0,Z.jsx)(hN,{container:t,children:(0,Z.jsxs)(mN,{className:`samva-editor-shell fixed inset-0 z-[100] flex flex-col bg-[var(--editor-canvas-bg)] outline-none`,children:[(0,Z.jsx)(wN,{className:`sr-only`,children:`Template preview`}),(0,Z.jsx)(cN,{className:`sr-only`,children:`Preview the rendered template and inspect its generated output.`}),(0,Z.jsxs)(`div`,{"data-testid":`preview-overlay.toolbar`,className:`border-border-subtle flex shrink-0 flex-wrap items-center gap-2 border-b px-3 py-2.5 sm:gap-2.5 sm:px-4`,children:[(0,Z.jsx)(`span`,{className:`text-[13px] font-semibold`,children:`Preview`}),(0,Z.jsx)(`span`,{className:`text-muted-foreground hidden text-xs sm:inline`,children:`rendered message, exactly what ships`}),(0,Z.jsx)(eV,{ariaLabel:`Preview format`,testId:`preview-overlay.format-group`,value:o,onChange:e=>s(e),options:v}),(0,Z.jsx)(`span`,{className:`hidden flex-1 sm:block`}),n.channel===`email`&&o===`preview`&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(eV,{ariaLabel:`Preview width`,testId:`preview-overlay.width-group`,value:c,onChange:e=>l(e),options:[{value:`desktop`,label:`Desktop`,testId:`preview-overlay.device.desktop`},{value:`mobile`,label:`Mobile`,testId:`preview-overlay.device.mobile`}]}),(0,Z.jsx)(eV,{ariaLabel:`Preview color scheme`,testId:`preview-overlay.color-scheme-group`,value:u,onChange:e=>d(e),options:[{value:`light`,label:`Light`,testId:`preview-overlay.scheme.light`},{value:`dark`,label:`Dark`,testId:`preview-overlay.scheme.dark`}]}),(0,Z.jsx)(gV,{checks:i})]}),(0,Z.jsxs)(sN,{"data-testid":`preview-overlay.close`,className:`border-border text-foreground hover:bg-muted focus-visible:border-ring focus-visible:ring-ring/50 ml-auto inline-flex h-[30px] items-center gap-1.5 rounded-[7px] border px-2.5 outline-none focus-visible:ring-[3px]`,children:[`Close`,(0,Z.jsx)(`kbd`,{className:`text-muted-foreground text-[10px]`,children:`⎋`})]})]}),o===`preview`?n.channel===`email`?(0,Z.jsxs)(`div`,{className:`samva-editor-scroll flex-1 overflow-auto px-6 pt-3 pb-12`,children:[(0,Z.jsxs)(`div`,{"data-testid":`preview-overlay.device-frame`,className:$(`mx-auto mb-3.5 max-w-full truncate text-[12.5px] text-muted-foreground transition-[width] duration-180`,c===`mobile`?`w-[375px]`:`w-[600px]`),children:[g!==void 0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`b`,{className:`text-foreground font-semibold`,children:g.name??g.email}),g.name===void 0?null:(0,Z.jsxs)(Z.Fragment,{children:[` <`,g.email,`>`]}),` ·`,` `]}),(0,Z.jsx)(`b`,{className:`text-foreground font-semibold`,children:r?.subject??``}),r?.preheader!==void 0&&(0,Z.jsxs)(`span`,{className:`opacity-70`,children:[` — `,r.preheader]})]}),(0,Z.jsx)(`div`,{className:$(`mx-auto h-[calc(100%-2rem)] max-w-full transition-[width] duration-180 ease-out`,c===`mobile`?`w-[375px]`:`w-[600px]`),children:r===null?(0,Z.jsx)(`pre`,{className:`border-status-error/40 bg-background text-status-error rounded-lg border p-4 font-mono text-xs whitespace-pre-wrap`,children:`The current draft did not build, so there is nothing to preview.`}):(0,Z.jsx)(kB,{html:r.html,width:rW[c],forceColorScheme:u})})]}):(0,Z.jsx)(`div`,{className:`samva-editor-scroll flex-1 overflow-auto p-8`,children:(0,Z.jsx)(`div`,{className:`border-border bg-background mx-auto max-w-[460px] rounded-[28px] border p-5 shadow-[var(--shadow-lg)]`,children:n.channel===`sms`&&n.render!==null?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{"data-testid":`preview-overlay.sms-body`,className:`bg-muted rounded-[18px] px-4 py-3 text-[14px] whitespace-pre-wrap`,children:n.render.text}),(0,Z.jsx)(Vz,{text:n.render.text,className:`mt-4 text-center text-xs`})]}):n.channel===`whatsapp`&&n.render!==null?(0,Z.jsxs)(`div`,{className:`bg-surface-inset rounded-xl p-3.5`,children:[n.render.header!==void 0&&n.render.header.text!==``&&(0,Z.jsx)(`p`,{className:`mb-1 font-semibold`,children:n.render.header.text}),(0,Z.jsx)(`p`,{className:`whitespace-pre-wrap`,children:n.render.body}),n.render.footer!==void 0&&n.render.footer!==``&&(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-2 text-xs`,children:n.render.footer}),n.render.buttons.map((e,t)=>(0,Z.jsx)(`div`,{className:`border-border-subtle text-accent-email mt-2 border-t pt-2 text-center text-xs`,children:e.type===`copy-code`?aW:e.type===`flow`?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`span`,{"aria-hidden":`true`,children:[iW,` `]}),e.text]}):e.text},`${e.type}-${t}`))]}):(0,Z.jsx)(`pre`,{className:`text-status-error whitespace-pre-wrap`,children:`The current draft did not build, so there is nothing to preview.`})})}):(0,Z.jsx)(`div`,{className:`samva-editor-scroll flex-1 overflow-auto p-6`,children:(0,Z.jsx)(`pre`,{className:`border-border bg-background text-foreground mx-auto min-h-full max-w-[1100px] rounded-lg border p-5 font-mono text-[12px] leading-5 whitespace-pre-wrap`,children:y})})]})})})}function cW({saveVersionStatus:e,saveVersionState:t,onSaveVersion:n,saveVersionBusy:r,saveVersionBlocked:i,guestHeadline:a,part:o}){let{doc:s,checks:c,sizeKb:l,layoutMode:u,assistantWidth:d,chatCollapsed:f}=Q(kk(e=>({doc:e.doc,checks:e.checks,sizeKb:e.sizeKb,layoutMode:e.layoutMode,assistantWidth:e.assistantWidth,chatCollapsed:e.chatCollapsed}))),p=gz(`rail.assistant`)!==void 0,{selectDocument:m}=Q(e=>e.actions),h=Q(e=>e.sourceEditable),g=Q(e=>e.pendingAuthoredSource),_=Q(kk(e=>({storageError:e.storageError,conflict:e.conflict}))),[v,y]=(0,W.useState)(!1),{errorCount:b,warnCount:x}=OL(c),S=u===`narrow`,C=p&&u===`wide`&&!f,w=c.filter(e=>e.diagnostics?.some(e=>e.compatibility?.assessment===`unverified`)).length,T=`No known risks found`;w>0&&(T=`No known risks · ${w} need verification`),x>0&&(T=`${x} warning${x>1?`s`:``}`),b>0&&(T=`${b} check${b>1?`s`:``} failing`),c.length===0&&(T=`No checks yet`);let E=t===`error`||_.storageError!==null||_.conflict?`Couldn't save version`:g!==null||r===!0?`Saving…`:void 0;return dz(`editor-status-bar`,{...o},{state:{layout:u,save:t??`unavailable`},tag:`footer`,className:`border-border bg-background text-muted-foreground z-30 flex h-8 shrink-0 items-stretch border-t text-xs whitespace-nowrap`,props:{children:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{"data-slot":`editor-status-bar-start`,style:C?{width:d}:void 0,className:$(`flex min-w-0 shrink-0 items-center gap-3 px-2`,C&&`pr-3`),children:[(0,Z.jsxs)(XH,{open:v,onOpenChange:y,children:[(0,Z.jsxs)(ZH,{render:(0,Z.jsx)(aB,{variant:`ghost`,size:`xs`,"data-testid":`statusbar.checks-trigger`,"data-editor-control":``,"aria-label":S?T:void 0,onClick:()=>m(),className:`text-muted-foreground font-normal`}),children:[(0,Z.jsx)(`span`,{className:$(`size-1.5 shrink-0 rounded-full`,b>0?`bg-status-error`:x>0?`bg-status-warning`:`bg-muted-foreground`)}),a===void 0&&!S?T:null]}),(0,Z.jsx)(QH,{side:`top`,align:`start`,sideOffset:8,"data-testid":`statusbar.checks-popup`,className:`max-h-[min(560px,70vh)] w-[360px] overflow-y-auto p-3.5`,children:(0,Z.jsx)(hV,{checks:c,editable:h})})]}),a===void 0?!S&&(0,Z.jsx)(`span`,{children:s===null?`Loading…`:`Draft`}):(0,Z.jsx)(`span`,{"data-testid":`statusbar.guest`,className:`min-w-0 truncate`,children:E??a})]}),!C&&(0,Z.jsx)(VB,{orientation:`vertical`,className:`my-2.5`}),(0,Z.jsxs)(`div`,{"data-slot":`editor-status-bar-end`,className:`flex min-w-0 flex-1 items-center gap-1 px-2`,children:[a===void 0?(0,Z.jsx)(`span`,{"aria-live":`polite`,"data-testid":`statusbar.save-version`,"data-save-version-state":t??`unavailable`,className:`px-1`,children:e??`Autosaved just now`}):(0,Z.jsx)(`span`,{className:`sr-only`,"aria-live":`polite`,"data-testid":`statusbar.save-version`,"data-save-version-state":t??`unavailable`,children:E??e??a}),n!==void 0&&(0,Z.jsx)(aB,{variant:`ghost`,size:`xs`,onClick:n,disabled:r===!0||i===!0,"data-testid":`topbar.save-version`,"data-editor-control":``,"aria-label":`Save the current draft as a version`,title:`Save this draft as a version (⌘/Ctrl+S)`,className:`text-foreground`,children:r===!0?`Saving…`:e===`Couldn’t save version`?`Retry`:`Save version`}),(0,Z.jsx)(`span`,{className:`flex-1`}),!S&&s!==null&&s.channel!==`email`&&(0,Z.jsxs)(`span`,{className:`px-1`,children:[l,` KB · `,s.channel.toUpperCase()]})]})]})}})}var lW=$(`border-border-subtle bg-surface-inset text-muted-foreground inline-flex h-[22px] min-w-0 max-w-[180px] items-center gap-1 rounded-md border px-2 text-[11.5px] font-medium outline-none`,Cz),uW=e=>e.button===0&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey;function dW({source:e,onUseDefault:t}){let n=Q(e=>e.doc?.rev??null),r=Q(e=>e.editable&&e.lifecycleCapability?.status===`ready`),i=(0,W.useRef)(e.readTheme);(0,W.useEffect)(()=>{i.current=e.readTheme});let[a,o]=(0,W.useState)(void 0),[s,c]=(0,W.useState)(`idle`);(0,W.useEffect)(()=>{if(n===null)return;let e=!1;return i.current().then(t=>{e||o(PV(t.theme??``))},()=>void 0),()=>{e=!0}},[n]);let l=IV(a,e.brands),u;if(l.kind===`pending`)u=(0,Z.jsxs)(`span`,{"data-testid":`topbar.brand-pending`,"aria-busy":`true`,className:lW,children:[(0,Z.jsx)(AR,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:`Brand`})]});else if(l.kind===`brand`){let{name:t,slug:n}=l.brand,r=e.brandLink(n);u=(0,Z.jsxs)(`a`,{href:r.href,"aria-label":`Brand: ${t}`,title:`Open ${t}`,"data-testid":`topbar.brand`,onClick:e=>{r.navigate!==void 0&&uW(e)&&(e.preventDefault(),r.navigate())},className:$(lW,`hover:bg-muted hover:text-foreground`),children:[(0,Z.jsx)(AR,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:t})]})}else if(l.kind===`missing`)u=(0,Z.jsxs)(`span`,{"data-testid":`topbar.brand-missing`,title:l.slug===null?`This organization has no default brand.`:`This organization has no brand “${l.slug}”.`,className:$(lW,`text-status-warning`),children:[(0,Z.jsx)(AR,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:`Brand not found`})]});else{let e=l.defaultBrand,n=r&&t!==void 0&&e!==null?()=>{c(`busy`),t().then(()=>c(`idle`),()=>c(`error`))}:void 0;u=(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`span`,{"data-testid":`topbar.brand-none`,className:lW,children:[(0,Z.jsx)(AR,{className:`size-3.5 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:`No brand`})]}),n!==void 0&&e!==null&&(0,Z.jsx)(`button`,{type:`button`,"data-testid":`topbar.brand-use`,onClick:n,disabled:s===`busy`,"aria-busy":s===`busy`,title:`Theme this template with ${e.name}`,className:$(`text-foreground hover:bg-muted inline-flex h-[22px] max-w-[180px] items-center rounded-md px-1.5 text-[11.5px] font-medium outline-none disabled:opacity-50`,`focus-visible:border-ring focus-visible:ring-ring/50 outline-none focus-visible:ring-3`),children:(0,Z.jsxs)(`span`,{className:`truncate`,children:[`Use `,e.name]})}),s===`error`&&e!==null&&(0,Z.jsxs)(`span`,{role:`alert`,className:`text-status-error truncate text-[11.5px]`,children:[`Couldn’t use `,e.name]})]})}return(0,Z.jsxs)(`div`,{className:`flex min-w-0 shrink items-center gap-1`,children:[u,e.status]})}var fW=[`assistant`,`preview`];function pW({compact:e=!1,...t}){let{focusedPane:n,previewUnseen:r}=Q(kk(e=>({focusedPane:e.focusedPane,previewUnseen:e.previewUnseen}))),i=Q(e=>e.actions.setFocusedPane),{idBase:a}=NU(),o=r&&n!==`preview`;return dz(`editor-pane-switch`,{...t},{state:{pane:n,unseen:o},className:`flex min-w-0`,props:{children:(0,Z.jsx)(KB,{role:`tablist`,"aria-label":`Editor pane`,value:[n],spacing:0,onValueChange:e=>{let t=fW.find(t=>t===e[0]);t!==void 0&&i(t)},className:$(Tz,`grid h-8 w-full grid-cols-2`,e&&`w-auto`),children:fW.map(t=>(0,Z.jsxs)(qB,{value:t,id:`${a}-tab-${t}`,role:`tab`,"aria-selected":n===t,"aria-controls":`${a}-pane-${t}`,"aria-pressed":void 0,"aria-label":e?t===`assistant`?`Chat`:`Preview`:void 0,"data-pressed":n===t?``:void 0,"data-testid":`agent-workspace.tab.${t}`,"data-editor-control":``,className:$(Ez,e?`px-2.5`:`gap-1.5 px-3 text-[13px]`,`aria-selected:bg-background aria-selected:text-foreground aria-selected:shadow-sm dark:aria-selected:border-input dark:aria-selected:bg-input/30`),children:[t===`assistant`?(0,Z.jsx)(XR,{className:`size-3.5`}):(0,Z.jsx)(SR,{className:`size-3.5`}),e?null:t===`assistant`?`Chat`:`Preview`,t===`preview`&&o&&(0,Z.jsx)(`span`,{"data-testid":`agent-workspace.preview-updated`,className:`bg-primary size-1.5 rounded-full`,children:(0,Z.jsx)(`span`,{className:`sr-only`,children:`, updated`})})]},t))})}})}function mW({leading:e,extraActions:t,onBack:n,onUndo:r,onRedo:i,canUndo:a=!1,canRedo:o=!1,onPreview:s,onLifecycle:c,channelSwitcher:l,exportEnabled:u,onExport:d,renameEnabled:f=!0,brand:p,onUseDefaultBrand:m,part:h}){let{doc:g,render:_,pendingAuthoredSource:v,lifecycleCapability:y,editable:b,readonlyReason:x,renameActive:S,metadataError:C,layoutMode:w}=Q(kk(e=>({doc:e.doc,render:e.render,pendingAuthoredSource:e.pendingAuthoredSource,lifecycleCapability:e.lifecycleCapability,editable:e.editable,readonlyReason:e.readonlyReason,renameActive:e.renameActive,metadataError:e.metadataError,layoutMode:e.layoutMode}))),{rename:T,setRenameActive:E}=Q(e=>e.actions),D=(0,W.useRef)(null),O=g?.name??`Untitled template`;(0,W.useEffect)(()=>{if(S&&D.current){D.current.focus();let e=document.createRange();e.selectNodeContents(D.current);let t=window.getSelection();t?.removeAllRanges(),t?.addRange(e)}},[S]);let k=u===!0&&g?.channel===`email`&&_!==null&&v===null,A=w===`compact`||w===`narrow`,j=w===`standard`,M=g!==null&&g.channel!==`email`,N=!M,P=()=>{k&&g!==null&&_!==null&&(WU(_.html,g.name),d?.())},F=gz(`rail.assistant`)!==void 0,I=w===`narrow`,L=A,R=b&&y!==void 0?(0,Z.jsx)($B,{label:y.status===`locked`?y.upsell.reason:`Publish and view history`,children:(0,Z.jsx)(aB,{size:`sm`,onClick:c,"data-testid":`topbar.publish`,"data-editor-control":``,children:`Publish`})}):null;return dz(`editor-top-bar`,{...h},{state:{layout:w},tag:`header`,className:`border-border bg-background z-30 flex h-12 min-w-0 shrink-0 items-center gap-2 border-b px-3`,props:{children:(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`div`,{"data-slot":`editor-top-bar-title`,className:`flex min-w-0 flex-1 items-center gap-1.5`,children:[e!==void 0&&(0,Z.jsx)(`div`,{className:`shrink-0`,children:e}),n!==void 0&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($B,{label:`Back to templates`,children:(0,Z.jsxs)(aB,{variant:`ghost`,size:I?`icon-sm`:`sm`,onClick:n,"aria-label":`Back to templates`,"data-testid":`topbar.back`,"data-editor-control":``,className:`text-muted-foreground`,children:[(0,Z.jsx)(gR,{}),I?null:`Templates`]})}),(0,Z.jsx)(VB,{orientation:`vertical`,className:`mx-0.5 h-4!`})]}),(0,Z.jsx)(`span`,{ref:D,"data-testid":`topbar.name`,"data-slot":`editor-top-bar-name`,contentEditable:b&&f,suppressContentEditableWarning:!0,spellCheck:!1,title:b&&f?`Click to rename`:x??`This template name is fixed.`,className:$(`min-w-0 truncate rounded-md px-1.5 py-1 text-sm font-medium whitespace-nowrap outline-none`,I?`max-w-full`:`max-w-72 min-w-24`,`hover:bg-muted focus-visible:ring-ring/50 focus-visible:bg-background focus-visible:ring-3`),onFocus:()=>{b&&f&&E(!0)},onBlur:e=>{b&&f&&(E(!1),T(e.currentTarget.textContent??``))},onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),e.currentTarget.blur()),e.key===`Escape`&&(e.currentTarget.textContent=O,e.currentTarget.blur())},children:O}),C!==null&&(0,Z.jsx)(`span`,{role:`alert`,className:`text-destructive truncate text-xs`,children:C}),I?null:l===void 0?(0,Z.jsx)(zB,{variant:`outline`,className:`text-muted-foreground font-mono uppercase`,children:g?.channel??`email`}):(0,Z.jsx)(`div`,{className:$(`min-w-0 shrink-0`,A&&`[&_[data-channel-button]]:px-1.5 [&_[data-channel-label]]:hidden`),children:l}),!b&&g!==null&&(0,Z.jsx)(zB,{variant:`secondary`,title:x??`This template is read-only.`,"data-testid":`topbar.readonly-badge`,children:`Read-only`}),p!==void 0&&N&&!I&&(0,Z.jsx)(dW,{source:p,onUseDefault:m})]}),F&&w!==`wide`&&N&&(0,Z.jsx)(pW,{compact:I,className:I?`shrink-0`:`w-56 shrink-0`}),(0,Z.jsxs)(`div`,{"data-slot":`editor-top-bar-actions`,className:$(`flex shrink-0 items-center justify-end gap-1`,!L&&`flex-1`),children:[!L&&r!==void 0&&(0,Z.jsx)(aB,{variant:`ghost`,size:`sm`,"data-testid":`topbar.undo`,"data-editor-control":``,onClick:r,disabled:!a,children:`Undo`}),!L&&i!==void 0&&(0,Z.jsx)(aB,{variant:`ghost`,size:`sm`,"data-testid":`topbar.redo`,"data-editor-control":``,onClick:i,disabled:!o,children:`Redo`}),!L&&M&&(0,Z.jsx)(oU,{testId:`topbar.fixture`}),!L&&(0,Z.jsx)(VB,{orientation:`vertical`,className:`mx-1 h-4!`}),!I&&(0,Z.jsx)($B,{label:`Preview template`,children:(0,Z.jsxs)(aB,{variant:`ghost`,size:j||L?`icon-sm`:`sm`,"aria-label":`Preview template`,"data-testid":`topbar.preview`,"data-editor-control":``,onClick:s,children:[(0,Z.jsx)(SR,{}),j||L?null:`Preview`]})}),!L&&u===!0&&(0,Z.jsx)($B,{label:k?`Export rendered HTML`:`Export waits for the latest render`,children:(0,Z.jsxs)(aB,{variant:`ghost`,size:j?`icon-sm`:`sm`,"aria-label":`Export HTML`,"data-testid":`topbar.export`,"data-editor-control":``,onClick:P,disabled:!k,children:[(0,Z.jsx)(bR,{}),j?null:`Export HTML`]})}),!I&&t,L&&M&&(0,Z.jsx)(oU,{testId:`topbar.fixture`}),L&&(0,Z.jsxs)(jH,{children:[(0,Z.jsx)(MH,{render:(0,Z.jsx)(aB,{variant:`ghost`,size:`icon-sm`,"aria-label":`More actions`,"data-testid":`topbar.more`,"data-editor-control":``}),children:(0,Z.jsx)(GR,{})}),(0,Z.jsxs)(NH,{align:`end`,className:`w-48`,children:[r!==void 0&&(0,Z.jsx)(IH,{"data-testid":`topbar.undo`,"data-editor-control":``,disabled:!a,onClick:r,children:`Undo`}),i!==void 0&&(0,Z.jsx)(IH,{"data-testid":`topbar.redo`,"data-editor-control":``,disabled:!o,onClick:i,children:`Redo`}),I&&(0,Z.jsx)(LH,{}),I&&(0,Z.jsxs)(IH,{"data-testid":`topbar.preview`,onClick:s,children:[(0,Z.jsx)(SR,{}),`Preview template`]}),u===!0&&(0,Z.jsxs)(IH,{"data-testid":`topbar.export`,"data-editor-control":``,disabled:!k,onClick:P,children:[(0,Z.jsx)(bR,{}),`Export HTML`]})]})]}),I&&t,R]})]})}})}var hW=[],gW=e=>e>=1280?`wide`:e>=980?`standard`:e>=720?`compact`:`narrow`;function _W(){let e=Q(e=>e.conflict),{reload:t}=Q(e=>e.actions);return!Q(e=>e.editable)||!e?null:(0,Z.jsxs)(`div`,{className:`border-border bg-surface-elevated text-foreground absolute inset-x-0 top-3 z-30 mx-auto flex w-fit items-center gap-3 rounded-lg border px-3.5 py-2 text-[13px] shadow-[var(--shadow-md)]`,children:[(0,Z.jsx)(`span`,{children:`Document changed elsewhere — your recent edits weren’t saved.`}),(0,Z.jsx)(`button`,{type:`button`,onClick:t,className:`bg-primary text-primary-foreground rounded-md px-2.5 py-1 font-medium transition-opacity hover:opacity-90`,children:`Reload`})]})}function vW(){let e=Q(e=>e.storageError),t=Q(e=>e.conflict),{retrySave:n}=Q(e=>e.actions);return!Q(e=>e.editable)||e===null||t?null:(0,Z.jsxs)(`div`,{className:`border-status-warning/45 bg-surface-elevated text-foreground absolute inset-x-0 top-3 z-30 mx-auto flex w-fit items-center gap-3 rounded-lg border px-3.5 py-2 text-[13px] shadow-[var(--shadow-md)]`,children:[(0,Z.jsxs)(`span`,{children:[e,` Your work is kept here; export a copy or retry.`]}),(0,Z.jsx)(`button`,{type:`button`,onClick:n,className:`border-border hover:bg-muted rounded-md border px-2.5 py-1 font-medium transition-colors`,children:`Retry`})]})}function yW(){let e=Q(e=>e.doc);return e===null||e.channel===`email`?(0,Z.jsx)(BU,{}):e.channel===`sms`?(0,Z.jsx)(Kz,{}):(0,Z.jsx)(rB,{})}function bW({height:e=`100dvh`,contributions:t=hW,brand:n,onBack:r,exportable:i,renameEnabled:a,onLockedLifecycle:o,previewBusy:s=!1,onOpenPreview:c,children:l,...u}){let d=Q(e=>e.leftCollapsed),f=Q(e=>e.rightCollapsed),p=Q(e=>e.layoutMode),m=Q(e=>e.doc?.rev??null),h=Q(e=>e.undoHistory.length+(e.designDraft?.edits.length??0)),g=Q(e=>e.redoHistory.length+(e.designDraft?.undone.length??0)),_=Q(e=>e.sourceEditable),v=Q(e=>e.doc),y=Q(e=>e.render),b=Q(e=>e.pendingAuthoredSource),x=Q(e=>e.lifecycleBusy),S=Q(e=>e.conflict),C=Q(e=>e.storageError),w=(0,W.useMemo)(()=>pz(t),[t]),T=w.one(`frame.start`),E=w.one(`statusbar.headline`),D=w.one(`rail.assistant`)!==void 0,{flushSaves:O,beginLifecycle:k,endLifecycle:A,adoptLifecycleSnapshot:j,toggleLeft:M,toggleRight:N,setLayoutMode:P,undo:F,redo:I,openWorkTab:L,setFocusedPane:R,setHostBusy:z}=Q(e=>e.actions);(0,W.useEffect)(()=>z(s),[s,z]);let B=Q(e=>e.versionsCapability),ee=Q(e=>e.telemetry),te=B?.status===`ready`?B.api:void 0,ne=(0,W.useMemo)(()=>te===void 0?void 0:e=>te.save(e),[te]),V=(0,W.useMemo)(()=>te===void 0?void 0:()=>te.savedRevision(),[te]),re=()=>ee?.({name:`preview`}),ie=()=>ee?.({name:`export`}),[ae,oe]=(0,W.useState)(!1),[se,ce]=(0,W.useState)(!1),[H,le]=(0,W.useState)(`idle`),[ue,de]=(0,W.useState)(null),[fe,U]=(0,W.useState)(null),pe=BI(),me=(0,W.useId)();(0,W.useEffect)(()=>{if(V===void 0||m===null)return;let e=!0;return V().then(t=>{e&&U(t===m?t:null)}).catch(()=>{e&&U(null)}),()=>{e=!1}},[m,V]);let he=(0,W.useRef)(null),ge=(0,W.useRef)(()=>{}),_e=(0,W.useRef)(null),ve=(0,W.useRef)(null),ye=i===!0&&v?.channel===`email`&&y!==null&&b===null,be=()=>{ye&&v!==null&&y!==null&&(WU(y.html,v.name),ie?.())},xe=()=>{if(ne===void 0)return Promise.resolve();if(ZL(pe.getState())>0)return pe.getState().actions.applyDesign(),Promise.resolve();if(he.current!==null)return he.current;if(!k())return Promise.resolve();let e=()=>{},t=new Promise(t=>{e=t});return he.current=t,le(`saving`),pe.getState().actions.flushSaves().then(async e=>{let t=pe.getState().doc,n=await ne(e),r=pe.getState().doc;t!==null&&(r?.rev===e||r?.rev===n)&&r.origin.authoredSource===t.origin.authoredSource&&pe.getState().actions.adoptLifecycleSnapshot({rev:n,authoredSource:t.origin.authoredSource}),de(n),le(`idle`)}).catch(()=>le(`error`)).finally(()=>{A(),he.current===t&&(he.current=null),e()}),t};(0,W.useEffect)(()=>{ge.current=xe});let Se=n===void 0||ne===void 0?void 0:async()=>{let e=pe.getState().lifecycleCapability;if(e?.status!==`ready`)return;let t=await pe.getState().actions.flushSaves(),r=await n.readTheme(),i=FV(r);i!==r.theme&&await e.api.updateFile({path:bV,baseRev:t,content:i}),await xe()},Ce=`idle`;H===`saving`?Ce=`saving`:H===`error`?Ce=`error`:m!==null&&(ue===m||fe===m)&&b===null&&!S&&C===null&&(Ce=`saved`);let we;ne!==void 0&&(we=`Unsaved changes`,Ce===`saving`?we=`Saving version…`:Ce===`saved`?we=`Saved version`:Ce===`error`&&(we=`Couldn’t save version`));let Te={flushSaves:O,beginLifecycle:k,endLifecycle:A,adoptLifecycleSnapshot:j,undo:F,redo:I,canUndo:_&&h>0,canRedo:_&&g>0,preview:()=>{oe(!0),re?.()},exportHtml:be,canExport:ye},Ee=(0,W.useMemo)(()=>({hostBusy:s,openInNewTab:c,showChecks:D?()=>{L(`checks`),R(`preview`)}:void 0}),[D,c,L,s,R]),De=w.all(`toolbar.leading`).map(e=>(0,Z.jsx)(W.Fragment,{children:e.render()},e.id)),Oe=w.all(`toolbar.actions`).map(e=>(0,Z.jsx)(W.Fragment,{children:e.render(Te)},e.id)),ke=w.one(`document.switcher`)?.render(Te);(0,W.useEffect)(()=>{if(ne===void 0)return;let e=e=>{(e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`&&e.target instanceof HTMLElement&&e.target.closest(`[data-samva-editor-theme]`)!==null&&e.target.closest(`[role="menu"], [role="dialog"], [data-base-ui-portal]`)===null&&(e.preventDefault(),ge.current())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[ne]),(0,W.useLayoutEffect)(()=>{let e=_e.current;if(e===null||typeof ResizeObserver>`u`)return;let t,n=e=>{let n=gW(e);n!==t&&(t=n,P(n))};n(e.getBoundingClientRect().width);let r=new ResizeObserver(([e])=>{e!==void 0&&n(e.contentRect.width)});return r.observe(e),()=>r.disconnect()},[P]);let Ae=(p===`compact`||p===`narrow`)&&(!d||!f);(0,W.useEffect)(()=>{if(!Ae)return;let e=e=>{e.key===`Escape`&&(d||M(),f||N())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[d,Ae,f,M,N]);let je={leading:De.length===0?void 0:De,extraActions:Oe.length===0?void 0:Oe,onBack:T===void 0?r:void 0,onPreview:()=>{oe(!0),re?.()},onLifecycle:()=>ce(!0),onUndo:F,onRedo:I,canUndo:_&&h>0,canRedo:_&&g>0,channelSwitcher:ke,exportEnabled:i,renameEnabled:a,onExport:ie,brand:n,onUseDefaultBrand:Se},Me=E===void 0||E.saveVersion,Ne={saveVersionStatus:Me?we:void 0,saveVersionState:ne===void 0?void 0:Ce,onSaveVersion:Me&&ne!==void 0?xe:void 0,saveVersionBusy:Ce===`saving`,saveVersionBlocked:x,guestHeadline:E?.headline},Pe=dz(`editor`,{...u},{state:{layout:p,docked:D,busy:x},className:`samva-editor-shell flex min-w-0 flex-1 flex-col overflow-hidden`,props:{"data-samva-editor-theme":`host`,inert:x,"aria-busy":x,children:l}});return(0,Z.jsx)(hz,{value:w,children:(0,Z.jsx)(yz,{value:{exportHtml:be,canExport:ye,saveVersionStatus:ne===void 0?`unavailable`:Ce},children:(0,Z.jsx)(zH,{value:Ee,children:(0,Z.jsx)(MU,{value:{topBar:je,statusBar:Ne,overlayOpen:Ae,idBase:me},children:(0,Z.jsx)(nW,{container:ve,children:(0,Z.jsxs)(`div`,{ref:_e,className:`samva-editor-frame flex`,style:{height:e},children:[T?.render(),Pe,(0,Z.jsx)(oW,{open:ae,onClose:()=>oe(!1)}),(0,Z.jsx)(eW,{open:se,onClose:()=>ce(!1),onLockedAction:o}),(0,Z.jsx)(`div`,{ref:ve,"data-samva-editor-portal-root":!0,className:`samva-editor-shell`})]})})})})})})}function xW(e){let t=Q(e=>e.layoutMode),n=Q(e=>e.leftCollapsed),r=Q(e=>e.rightCollapsed),i=gz(`rail.assistant`)!==void 0,{toggleLeft:a,toggleRight:o}=Q(e=>e.actions),{overlayOpen:s}=NU();return dz(`editor-workspace`,{...e},{state:{layout:t},className:`samva-editor-body relative flex min-h-0 min-w-0 flex-1 overflow-hidden`,props:{children:(0,Z.jsxs)(Z.Fragment,{children:[s&&(0,Z.jsx)(`button`,{type:`button`,"aria-label":`Close editor panel`,className:`bg-background/45 absolute inset-0 z-30 cursor-default backdrop-blur-[1px]`,onClick:()=>{n||a(),r||o()}}),n&&!i&&(0,Z.jsx)(SW,{label:`Show layers and blocks`,testId:`shell.show-left`,side:`left`,onClick:a}),r&&!i&&(0,Z.jsx)(SW,{label:`Show inspector`,testId:`shell.show-right`,side:`right`,onClick:o}),(0,Z.jsx)(yW,{}),(0,Z.jsx)(_W,{}),(0,Z.jsx)(vW,{})]})}})}function SW({label:e,testId:t,side:n,onClick:r}){let i=n===`left`?MR:PR;return(0,Z.jsx)($B,{label:e,side:n===`left`?`right`:`left`,children:(0,Z.jsx)(aB,{variant:`outline`,size:`icon-sm`,"aria-label":e,"data-testid":t,onClick:r,className:$(`absolute top-3 z-20 shadow-sm`,n===`left`?`left-3`:`right-3`),children:(0,Z.jsx)(i,{className:`size-4`})})})}function CW(e){let{topBar:t}=NU();return(0,Z.jsx)(mW,{...t,part:e})}function wW(e){let{statusBar:t}=NU();return(0,Z.jsx)(cW,{...t,part:e})}function TW(e){return(0,Z.jsxs)(bW,{...e,children:[(0,Z.jsx)(CW,{}),(0,Z.jsx)(xW,{}),(0,Z.jsx)(wW,{})]})}function EW({name:e,className:t}){let n=LI()[e];return(0,Z.jsx)(n,{...t===void 0?{}:{className:t}})}function DW({label:e,icon:t,title:n,upsell:r,onAction:i,testId:a}){let[o,s]=(0,W.useState)(!1),c=kz();return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)($B,{label:r.reason,children:(0,Z.jsxs)(aB,{variant:`ghost`,size:`sm`,"aria-label":e,"data-testid":a,"data-editor-control":``,onClick:()=>s(!0),children:[t,e]})}),(0,Z.jsx)(OF,{open:o,onOpenChange:s,swipeDirection:`right`,children:(0,Z.jsxs)(TF,{container:c,children:[(0,Z.jsx)(tF,{className:`fixed inset-0 z-[110] bg-[var(--editor-backdrop,rgb(0_0_0/0.28))]`}),(0,Z.jsx)(pI,{className:`pointer-events-none fixed inset-0 z-[111] flex justify-end`,children:(0,Z.jsxs)(wF,{className:`samva-editor-shell border-border bg-background pointer-events-auto flex h-full w-[420px] max-w-[92vw] flex-col border-l shadow-[var(--shadow-floating)] outline-none`,children:[(0,Z.jsx)(iF,{className:`sr-only`,children:r.reason}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-5 pt-4 pb-3`,children:[(0,Z.jsx)(XF,{className:`text-[15px] font-semibold`,children:n}),(0,Z.jsx)(nF,{type:`button`,"aria-label":`Close ${e.toLowerCase()} panel`,"data-testid":a===void 0?void 0:`${a}.close`,className:`text-muted-foreground hover:bg-muted hover:text-foreground rounded-md p-1.5`,children:(0,Z.jsx)(RR,{className:`size-[15px]`})})]}),(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-start gap-4 px-5 pt-6 pb-8`,children:[(0,Z.jsx)(`div`,{className:`border-border-subtle bg-surface-inset text-muted-foreground rounded-lg border px-3.5 py-3 text-[13px]`,children:r.reason}),(0,Z.jsx)(`a`,{href:r.cta.href,onClick:e=>{i!==void 0&&(e.preventDefault(),i())},"data-testid":a===void 0?void 0:`${a}.cta`,className:iB(),children:r.cta.label})]})]})})]})})]})}var OW=`2026-10-03.1`,kW=class extends Hn(`DocumentConflict`){},AW=class extends Hn(`DocumentUnavailable`){};Hn(`LifecycleUnavailable`),Hn(`ProjectFileExists`);var jW=(e,t)=>{let n=new URL(`api/${e}`,window.location.href);for(let[e,r]of Object.entries(t))n.searchParams.set(e,r);return n.toString()},MW=e=>e.fixture,NW=(e,t,n,r)=>({rev:t,origin:n,...r===void 0?{}:{authoredSource:r},...e}),PW=(e,t,n)=>ca(function*(){let r=yield*Fa(),i=new EventSource(jW(`events`,{id:e,client:t}));yield*ha(()=>aa(()=>i.close())),i.addEventListener(`samva:change`,t=>{let i=JSON.parse(t.data);i.id===e&&(n.rev=i.rev,n.fixture=MW(i),i.authoredSource!==void 0&&(n.authoredSource=i.authoredSource),Ia(r,NW(i,i.rev,i.origin,i.authoredSource)))});let a=()=>fetch(jW(`document`,{id:e,client:t})).then(e=>e.ok?e.json():void 0).then(e=>{if(e===void 0)return;let t=e.origin.authoredSource;(e.rev!==n.rev||t!==n.authoredSource||MW(e)!==n.fixture)&&(n.rev=e.rev,n.authoredSource=t,n.fixture=MW(e),Ia(r,NW(e,e.rev,`external`,t)))}).catch(()=>{}),o=!1,s;i.addEventListener(`open`,()=>{if(!o){o=!0,s?.(oa);return}a()}),i.addEventListener(`error`,()=>{!o&&i.readyState!==EventSource.OPEN&&s?.(new AW({reason:`editor event stream failed to open`}))}),yield*sa(e=>{if(i.readyState===EventSource.OPEN)return o=!0,e(oa);s=e});let c=yield*na({try:()=>fetch(jW(`document`,{id:e,client:t})),catch:e=>new AW({reason:String(e)})});if(!c.ok)return yield*new AW({reason:`open failed (${c.status})`});let l=yield*na({try:()=>c.json(),catch:e=>new AW({reason:String(e)})});return n.rev=l.rev,n.authoredSource=l.origin.authoredSource,n.fixture=MW(l),{initial:l,changes:oo(r)}}),FW=(e,t)=>({view:n=>ca(function*(){let r=yield*na({try:()=>fetch(jW(`fixture`,{id:e,client:t}),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({fixture:n})}),catch:e=>new AW({reason:String(e)})});if(r.ok)return;let i=`view fixture failed (${r.status})`;return yield*new AW({reason:yield*na({try:()=>r.json(),catch:()=>new AW({reason:i})}).pipe(fa(e=>e.error??i))})})}),IW=(e,t)=>({save:n=>ca(function*(){if(n.kind!==`authoredSource`)return yield*new AW({reason:`Local metadata is declared in source.`});let r=yield*na({try:()=>fetch(jW(`document`,{id:e,client:t}),{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(n)}),catch:e=>new AW({reason:String(e)})}),i=yield*na({try:()=>r.json(),catch:e=>new AW({reason:String(e)})});return r.status===409?yield*new kW({expectedRev:n.baseRev,actualRev:i.actualRev??n.baseRev}):!r.ok||i.rev===void 0?yield*new AW({reason:i.error??`Local source save failed.`}):{rev:i.rev}})}),LW=({id:e})=>{let t=crypto.randomUUID();return{contractVersion:OW,access:`editable`,sourceAccess:`editable`,metadataAccess:`readonly`,writer:IW(e,t),document:{open:PW(e,t,{rev:``})},fixtures:{status:`ready`,api:FW(e,t)}}},RW=e=>new URL(`api/${e}`,window.location.href).toString(),zW=async e=>{let t=await fetch(RW(e));if(!t.ok)throw Error(`${e} failed (${t.status})`);return t.json()},BW=()=>{let[e,t]=(0,W.useState)(()=>typeof window<`u`&&window.matchMedia(`(prefers-color-scheme: dark)`).matches);return(0,W.useEffect)(()=>{document.documentElement.classList.toggle(`dark`,e)},[e]),()=>t(e=>!e)};function VW({onBack:e,onToggleTheme:t}){return(0,Z.jsxs)(`nav`,{"aria-label":`Samva editor`,className:`border-border bg-background z-30 flex w-12 flex-none flex-col items-center gap-1 border-r py-3`,children:[(0,Z.jsx)(`span`,{className:`bg-primary text-primary-foreground mb-2 grid size-7 place-items-center rounded-lg text-[13px] font-bold`,children:`S`}),e?(0,Z.jsx)(`button`,{type:`button`,title:`Back to templates`,onClick:e,className:`text-muted-foreground hover:bg-muted hover:text-foreground grid size-8 place-items-center rounded-lg transition-colors`,children:(0,Z.jsx)(EW,{name:`arrowLeft`,className:`size-[16px]`})}):null,(0,Z.jsx)(`div`,{className:`flex-1`}),(0,Z.jsx)(`button`,{type:`button`,title:`Toggle theme`,onClick:t,className:`text-muted-foreground hover:bg-muted hover:text-foreground grid size-8 place-items-center rounded-lg transition-colors dark:hidden`,children:(0,Z.jsx)(EW,{name:`moon`,className:`size-[16px]`})}),(0,Z.jsx)(`button`,{type:`button`,title:`Toggle theme`,onClick:t,className:`text-muted-foreground hover:bg-muted hover:text-foreground hidden size-8 place-items-center rounded-lg transition-colors dark:grid`,children:(0,Z.jsx)(EW,{name:`sun`,className:`size-[16px]`})})]})}var HW={authenticatedLabel:`Authenticated`,authenticatedTitle:`The host provides authenticated capabilities.`};function UW({template:e,authenticated:t,editorAffordances:n,onBack:r,onToggleTheme:i}){let a=n.publishingInstructions,o=(0,W.useMemo)(()=>fo(LW({id:e.id})),[e.id]);return(0,Z.jsx)(uR,{host:o,children:(0,Z.jsx)(`div`,{className:`relative h-dvh`,children:(0,Z.jsx)(TW,{contributions:[{slot:`frame.start`,id:`project-rail`,render:()=>(0,Z.jsx)(VW,{onBack:r,onToggleTheme:i})},...t&&a!==void 0?[{slot:`toolbar.actions`,id:`send`,render:()=>(0,Z.jsx)(DW,{label:`Send`,title:`Send “${e.name}”`,upsell:a,testId:`vite-editor.send`})}]:[]],onBack:r,renameEnabled:!1})})},`${e.id}:${e.channel}`)}var WW={email:{icon:`envelope`,label:`Email`,className:`bg-sel-soft text-accent-email`},sms:{icon:`message`,label:`SMS`,className:`bg-muted text-primary`},whatsapp:{icon:`chatBubble`,label:`WhatsApp`,className:`bg-status-success/10 text-status-success`}};function GW({catalog:e,authenticated:t,editorAffordances:n,onOpen:r,onToggleTheme:i}){return(0,Z.jsxs)(`div`,{className:`flex h-dvh`,children:[(0,Z.jsx)(VW,{onToggleTheme:i}),(0,Z.jsx)(`div`,{className:`bg-surface-inset min-w-0 flex-1 overflow-y-auto`,children:(0,Z.jsxs)(`div`,{className:`mx-auto max-w-[720px] px-6 py-16`,children:[(0,Z.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h1`,{className:`text-foreground text-lg font-semibold`,children:`Templates`}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-1 text-[13px]`,children:`Preview your templates and fixtures. Source edits save to your project.`})]}),(0,Z.jsx)(`span`,{className:t?`bg-status-success/12 text-status-success rounded-full px-2.5 py-1 text-[11px] font-medium`:`bg-muted text-muted-foreground rounded-full px-2.5 py-1 text-[11px] font-medium`,title:t?n.authenticatedTitle:`Local editing only.`,children:t?n.authenticatedLabel:`Local only`})]}),e.diagnostics.length>0?(0,Z.jsx)(`section`,{"aria-label":`Catalog diagnostics`,className:`border-border bg-surface-elevated mt-6 overflow-hidden rounded-xl border`,children:e.diagnostics.map((e,t)=>(0,Z.jsxs)(`div`,{className:`px-4 py-3 text-[12px]`+(t>0?` border-border-subtle border-t`:``),children:[(0,Z.jsxs)(`p`,{className:e.severity===`error`?`text-status-error`:`text-status-warning`,children:[e.file,` · `,e.code]}),(0,Z.jsx)(`p`,{className:`text-muted-foreground mt-0.5`,children:e.message})]},`${e.file}:${e.code}:${t}`))}):null,(0,Z.jsxs)(`ul`,{className:`border-border bg-surface-elevated mt-8 overflow-hidden rounded-xl border shadow-md`,children:[e.templates.length===0?(0,Z.jsxs)(`li`,{className:`text-muted-foreground px-4 py-10 text-center text-[13px]`,children:[`No valid templates found. Add a `,(0,Z.jsx)(`code`,{className:`text-foreground`,children:`.tsx`}),` file with a Samva template as its default export.`]}):null,e.templates.map((e,t)=>{let n=WW[e.channel];return(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>r(e),"data-testid":`template-card.${e.id}`,className:`hover:bg-muted flex w-full items-center gap-3 px-4 py-3 text-left transition-colors`+(t>0?` border-border-subtle border-t`:``),children:[(0,Z.jsx)(`span`,{className:`grid size-8 flex-none place-items-center rounded-lg ${n.className}`,children:(0,Z.jsx)(EW,{name:n.icon,className:`size-[16px]`})}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`text-foreground block truncate text-[13px] font-medium`,children:e.name}),(0,Z.jsx)(`span`,{className:`text-muted-foreground block truncate text-[12px]`,children:e.id})]}),(0,Z.jsxs)(`span`,{className:`text-muted-foreground text-right text-[11px]`,children:[(0,Z.jsx)(`span`,{className:`block`,children:n.label}),(0,Z.jsx)(`span`,{className:`block`,children:`Editable source`})]})]})},e.id)})]})]})})]})}function KW(){let e=BW(),[t,n]=(0,W.useState)(!1),[r,i]=(0,W.useState)(HW),[a,o]=(0,W.useState)(null),[s,c]=(0,W.useState)(null),[l,u]=(0,W.useState)(null);(0,W.useEffect)(()=>{let e=!0,t=()=>zW(`templates`).then(t=>{e&&(o(t),c(null))});Promise.all([zW(`capabilities`).then(t=>{e&&(n(!!t.authenticated),i(t.editorAffordances??HW))}),t()]).catch(t=>{e&&c(String(t))});let r=new EventSource(RW(`catalog-events`));return r.addEventListener(`samva:catalog`,()=>{t().catch(t=>{e&&c(String(t))})}),()=>{e=!1,r.close()}},[]);let d=a?.templates.find(e=>e.id===l)??null;return l!==null&&a!==null&&d===null&&u(null),s===null?a===null?(0,Z.jsx)(`div`,{className:`text-muted-foreground grid h-dvh place-items-center text-[13px]`,children:`Loading templates…`}):d===null?(0,Z.jsx)(GW,{catalog:a,authenticated:t,editorAffordances:r,onOpen:e=>u(e.id),onToggleTheme:e}):(0,Z.jsx)(UW,{template:d,authenticated:t,editorAffordances:r,onBack:()=>u(null),onToggleTheme:e}):(0,Z.jsxs)(`div`,{className:`text-status-error grid h-dvh place-items-center px-6 text-center text-[13px]`,children:[`Couldn’t reach the Samva editor dev server: `,s]})}(0,co.createRoot)(document.getElementById(`root`)).render((0,Z.jsx)(W.StrictMode,{children:(0,Z.jsx)(KW,{})}));
@@ -4,7 +4,7 @@
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1" />
6
6
  <title>Samva editor</title>
7
- <script type="module" crossorigin src="./assets/index-dN1d5iXd.js"></script>
7
+ <script type="module" crossorigin src="./assets/index-DUnuBcHY.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="./assets/index-D7IQkVQz.css">
9
9
  </head>
10
10
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samva/vite",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "Local editor, dev server and build for Samva email, SMS and WhatsApp templates",
5
5
  "keywords": [
6
6
  "email",
@@ -70,12 +70,12 @@
70
70
  "test:browser:cross": "bun run build:dependencies && bun run build && playwright test --config playwright.config.ts"
71
71
  },
72
72
  "dependencies": {
73
- "@samva/markup": "^0.17.0"
73
+ "@samva/markup": "^0.17.1"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@effect/vitest": "4.0.0",
77
77
  "@playwright/test": "1.63.0",
78
- "@samva/editor": "^0.17.0",
78
+ "@samva/editor": "^0.17.1",
79
79
  "@types/node": "^26.6.2",
80
80
  "tsdown": "^0.22.13",
81
81
  "typescript": "^7.0.2",