@avocadostudio-ai/cli 0.17.1 → 0.18.0

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.
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PuckPrototypeRoute-4PdBTH7w.js","assets/PuckPrototypeRoute-Bn1rE5xN.css"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/PuckPrototypeRoute-CrrOmaf8.js","assets/PuckPrototypeRoute-Bn1rE5xN.css"])))=>i.map(i=>d[i]);
2
2
  var xB=Object.defineProperty;var vB=(e,t,n)=>t in e?xB(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Te=(e,t,n)=>vB(e,typeof t!="symbol"?t+"":t,n);function kB(e,t){for(var n=0;n<t.length;n++){const r=t[n];if(typeof r!="string"&&!Array.isArray(r)){for(const i in r)if(i!=="default"&&!(i in e)){const s=Object.getOwnPropertyDescriptor(r,i);s&&Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:()=>r[i]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))r(i);new MutationObserver(i=>{for(const s of i)if(s.type==="childList")for(const o of s.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&r(o)}).observe(document,{childList:!0,subtree:!0});function n(i){const s={};return i.integrity&&(s.integrity=i.integrity),i.referrerPolicy&&(s.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?s.credentials="include":i.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function r(i){if(i.ep)return;i.ep=!0;const s=n(i);fetch(i.href,s)}})();function Bd(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ux={exports:{}},Bf={};/**
3
3
  * @license React
4
4
  * react-jsx-runtime.production.js
@@ -765,7 +765,7 @@ ${n.innerHTML}
765
765
  `);return}},parse:{}}}}}),Ixe=dn.create({name:"heading"}),Oxe=Ixe.extend({addStorage(){return{markdown:{serialize:Ko.nodes.heading,parse:{}}}}}),Pxe=dn.create({name:"horizontalRule"}),zxe=Pxe.extend({addStorage(){return{markdown:{serialize:Ko.nodes.horizontal_rule,parse:{}}}}}),Lxe=dn.create({name:"image"}),Bxe=Lxe.extend({addStorage(){return{markdown:{serialize:Ko.nodes.image,parse:{}}}}}),Fxe=dn.create({name:"listItem"}),$xe=Fxe.extend({addStorage(){return{markdown:{serialize:Ko.nodes.list_item,parse:{}}}}}),Uxe=dn.create({name:"orderedList"});function Hxe(e,t,n){let r=0;for(;n-r>0&&t.child(n-r-1).type.name===e.type.name;r++);return r}const Vxe=Uxe.extend({addStorage(){return{markdown:{serialize(e,t,n,r){const i=t.attrs.start||1,s=String(i+t.childCount-1).length,o=e.repeat(" ",s+2),u=Hxe(t,n,r)%2?") ":". ";e.renderList(t,o,d=>{const f=String(i+d);return e.repeat(" ",s-f.length)+f+u})},parse:{}}}}}),qxe=dn.create({name:"paragraph"}),Kxe=qxe.extend({addStorage(){return{markdown:{serialize:Ko.nodes.paragraph,parse:{}}}}});function ik(e){var t,n;return(t=e==null||(n=e.content)===null||n===void 0?void 0:n.content)!==null&&t!==void 0?t:[]}const Gxe=dn.create({name:"table"}),Wxe=Gxe.extend({addStorage(){return{markdown:{serialize(e,t,n){if(!Zxe(t)){oy.storage.markdown.serialize.call(this,e,t,n);return}e.inTable=!0,t.forEach((r,i,s)=>{if(e.write("| "),r.forEach((o,a,u)=>{u&&e.write(" | ");const d=o.firstChild;d.textContent.trim()&&e.renderInline(d)}),e.write(" |"),e.ensureNewLine(),!s){const o=Array.from({length:r.childCount}).map(()=>"---").join(" | ");e.write(`| ${o} |`),e.ensureNewLine()}}),e.closeBlock(t),e.inTable=!1},parse:{}}}}});function JD(e){return e.attrs.colspan>1||e.attrs.rowspan>1}function Zxe(e){const t=ik(e),n=t[0],r=t.slice(1);return!(ik(n).some(i=>i.type.name!=="tableHeader"||JD(i)||i.childCount>1)||r.some(i=>ik(i).some(s=>s.type.name==="tableHeader"||JD(s)||s.childCount>1)))}const Yxe=dn.create({name:"taskItem"}),Jxe=Yxe.extend({addStorage(){return{markdown:{serialize(e,t){const n=t.attrs.checked?"[x]":"[ ]";e.write(`${n} `),e.renderContent(t)},parse:{updateDOM(e){[...e.querySelectorAll(".task-list-item")].forEach(t=>{const n=t.querySelector("input");t.setAttribute("data-type","taskItem"),n&&(t.setAttribute("data-checked",n.checked),n.remove())})}}}}}}),Xxe=dn.create({name:"taskList"}),Qxe=Xxe.extend({addStorage(){return{markdown:{serialize:zL.storage.markdown.serialize,parse:{setup(e){e.use(mxe)},updateDOM(e){[...e.querySelectorAll(".contains-task-list")].forEach(t=>{t.setAttribute("data-type","taskList")})}}}}}}),eve=dn.create({name:"text"}),tve=eve.extend({addStorage(){return{markdown:{serialize(e,t){e.text(wxe(t.text))},parse:{}}}}}),nve=gi.create({name:"bold"}),rve=nve.extend({addStorage(){return{markdown:{serialize:Ko.marks.strong,parse:{}}}}}),ive=gi.create({name:"code"}),sve=ive.extend({addStorage(){return{markdown:{serialize:Ko.marks.code,parse:{}}}}}),ove=gi.create({name:"italic"}),ave=ove.extend({addStorage(){return{markdown:{serialize:Ko.marks.em,parse:{}}}}}),lve=gi.create({name:"link"}),uve=lve.extend({addStorage(){return{markdown:{serialize:Ko.marks.link,parse:{}}}}}),cve=gi.create({name:"strike"}),dve=cve.extend({addStorage(){return{markdown:{serialize:{open:"~~",close:"~~",expelEnclosingWhitespace:!0},parse:{}}}}}),fve=[Nxe,zL,Rxe,LL,Oxe,zxe,oy,Bxe,$xe,Vxe,Kxe,Wxe,Jxe,Qxe,tve,rve,sve,PL,ave,uve,dve];function db(e){var t,n;const r=(t=e.storage)===null||t===void 0?void 0:t.markdown,i=(n=fve.find(s=>s.name===e.name))===null||n===void 0?void 0:n.storage.markdown;return r||i?{...i,...r}:null}class hve{constructor(t){cb(this,"editor",null),this.editor=t}serialize(t){const n=new Sxe(this.nodes,this.marks,{hardBreakNodeName:LL.name});return n.renderContent(t),n.out}get nodes(){var t;return{...Object.fromEntries(Object.keys(this.editor.schema.nodes).map(n=>[n,this.serializeNode(oy)])),...Object.fromEntries((t=this.editor.extensionManager.extensions.filter(n=>n.type==="node"&&this.serializeNode(n)).map(n=>[n.name,this.serializeNode(n)]))!==null&&t!==void 0?t:[])}}get marks(){var t;return{...Object.fromEntries(Object.keys(this.editor.schema.marks).map(n=>[n,this.serializeMark(PL)])),...Object.fromEntries((t=this.editor.extensionManager.extensions.filter(n=>n.type==="mark"&&this.serializeMark(n)).map(n=>[n.name,this.serializeMark(n)]))!==null&&t!==void 0?t:[])}}serializeNode(t){var n;return(n=db(t))===null||n===void 0||(n=n.serialize)===null||n===void 0?void 0:n.bind({editor:this.editor,options:t.options})}serializeMark(t){var n;const r=(n=db(t))===null||n===void 0?void 0:n.serialize;return r?{...r,open:typeof r.open=="function"?r.open.bind({editor:this.editor,options:t.options}):r.open,close:typeof r.close=="function"?r.close.bind({editor:this.editor,options:t.options}):r.close}:null}}class pve{constructor(t,n){cb(this,"editor",null),cb(this,"md",null);let{html:r,linkify:i,breaks:s}=n;this.editor=t,this.md=this.withPatchedRenderer(Vi({html:r,linkify:i,breaks:s}))}parse(t){let{inline:n}=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{};if(typeof t=="string"){this.editor.extensionManager.extensions.forEach(s=>{var o;return(o=db(s))===null||o===void 0||(o=o.parse)===null||o===void 0||(o=o.setup)===null||o===void 0?void 0:o.call({editor:this.editor,options:s.options},this.md)});const r=this.md.render(t),i=fC(r);return this.editor.extensionManager.extensions.forEach(s=>{var o;return(o=db(s))===null||o===void 0||(o=o.parse)===null||o===void 0||(o=o.updateDOM)===null||o===void 0?void 0:o.call({editor:this.editor,options:s.options},i)}),this.normalizeDOM(i,{inline:n,content:t}),i.innerHTML}return t}normalizeDOM(t,n){let{inline:r,content:i}=n;return this.normalizeBlocks(t),t.querySelectorAll("*").forEach(s=>{var o;((o=s.nextSibling)===null||o===void 0?void 0:o.nodeType)===Node.TEXT_NODE&&!s.closest("pre")&&(s.nextSibling.textContent=s.nextSibling.textContent.replace(/^\n/,""))}),r&&this.normalizeInline(t,i),t}normalizeBlocks(t){const r=Object.values(this.editor.schema.nodes).filter(i=>i.isBlock).map(i=>{var s;return(s=i.spec.parseDOM)===null||s===void 0?void 0:s.map(o=>o.tag)}).flat().filter(Boolean).join(",");r&&[...t.querySelectorAll(r)].forEach(i=>{i.parentElement.matches("p")&&Cxe(i)})}normalizeInline(t,n){var r;if((r=t.firstElementChild)!==null&&r!==void 0&&r.matches("p")){var i,s,o,a;const u=t.firstElementChild,{nextElementSibling:d}=u,f=(i=(s=n.match(/^\s+/))===null||s===void 0?void 0:s[0])!==null&&i!==void 0?i:"",m=d?"":(o=(a=n.match(/\s+$/))===null||a===void 0?void 0:a[0])!==null&&o!==void 0?o:"";if(n.match(/^\n\n/)){u.innerHTML=`${u.innerHTML}${m}`;return}Exe(u),t.innerHTML=`${f}${t.innerHTML}${m}`}}withPatchedRenderer(t){const n=r=>function(){const i=r(...arguments);return i===`
766
766
  `?i:i[i.length-1]===`
767
767
  `?i.slice(0,-1):i};return t.renderer.rules.hardbreak=n(t.renderer.rules.hardbreak),t.renderer.rules.softbreak=n(t.renderer.rules.softbreak),t.renderer.rules.fence=n(t.renderer.rules.fence),t.renderer.rules.code_block=n(t.renderer.rules.code_block),t.renderer.renderToken=n(t.renderer.renderToken.bind(t.renderer)),t}}const mve=Pn.create({name:"markdownClipboard",addOptions(){return{transformPastedText:!1,transformCopiedText:!1}},addProseMirrorPlugins(){return[new Qn({key:new _r("markdownClipboard"),props:{clipboardTextParser:(e,t,n)=>{if(n||!this.options.transformPastedText)return null;const r=this.editor.storage.markdown.parser.parse(e,{inline:!0});return ka.fromSchema(this.editor.schema).parseSlice(fC(r),{preserveWhitespace:!0,context:t})},clipboardTextSerializer:e=>this.options.transformCopiedText?this.editor.storage.markdown.serializer.serialize(e.content):null}})]}}),gve=Pn.create({name:"markdown",priority:50,addOptions(){return{html:!0,tightLists:!0,tightListClass:"tight",bulletListMarker:"-",linkify:!1,breaks:!1,transformPastedText:!1,transformCopiedText:!1}},addCommands(){const e=gz.Commands.config.addCommands();return{setContent:(t,n)=>r=>e.setContent(r.editor.storage.markdown.parser.parse(t),n)(r),insertContentAt:(t,n,r)=>i=>e.insertContentAt(t,i.editor.storage.markdown.parser.parse(n,{inline:!0}),r)(i)}},onBeforeCreate(){this.editor.storage.markdown={options:{...this.options},parser:new pve(this.editor,this.options),serializer:new hve(this.editor),getMarkdown:()=>this.editor.storage.markdown.serializer.serialize(this.editor.state.doc)},this.editor.options.initialContent=this.editor.options.content,this.editor.options.content=this.editor.storage.markdown.parser.parse(this.editor.options.content)},onCreate(){this.editor.options.content=this.editor.options.initialContent,delete this.editor.options.initialContent},addStorage(){return{}},addExtensions(){return[yxe.configure({tight:this.options.tightLists,tightClass:this.options.tightListClass}),mve.configure({transformPastedText:this.options.transformPastedText,transformCopiedText:this.options.transformCopiedText})]}}),BL=Kz.extend({addAttributes(){var e;return{...(e=this.parent)==null?void 0:e.call(this),anchor:{default:null},uuid:{default:null},linktype:{default:null}}}}).configure({openOnClick:!1}),FL=gi.create({name:"textStyle",addAttributes(){return{color:{default:null}}},parseHTML(){return[{tag:"span",getAttrs:e=>{var t;return(t=e.style)!=null&&t.color?{}:!1}}]},renderHTML({HTMLAttributes:e}){return["span",Zn(e),0]}}),$L=Pn.create({name:"avocadoBlockKeys",addGlobalAttributes(){return[{types:["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock"],attributes:{_key:{default:null,rendered:!1}}}]}});function bve(e){if(e&&typeof e=="object"){const t=e;for(const n of["_type","nodeType","type"])if(typeof t[n]=="string")return t[n]}return"Embedded content"}const yve=dn.create({name:"avocadoUnknownBlock",group:"block",atom:!0,selectable:!0,draggable:!0,addAttributes(){return{data:{default:null,rendered:!1},_key:{default:null,rendered:!1}}},parseHTML(){return[{tag:"div[data-avocado-unknown-block]"}]},renderHTML({node:e,HTMLAttributes:t}){return["div",Zn(t,{"data-avocado-unknown-block":"",class:"rte-unknown-block"}),bve(e.attrs.data)]}}),UL=gi.create({name:"avocadoUnknownHtml",addAttributes(){return{tag:{default:"span",rendered:!1},attributes:{default:null,rendered:!1}}},parseHTML(){return[{tag:"span[data-avocado-unknown-html]"}]},renderHTML({HTMLAttributes:e}){return["span",Zn(e,{"data-avocado-unknown-html":"",class:"rte-unknown-html"}),0]}}),HL=dn.create({name:"avocadoUnknownInline",group:"inline",inline:!0,atom:!0,selectable:!0,addAttributes(){return{data:{default:null,rendered:!1}}},parseHTML(){return[{tag:"span[data-avocado-unknown-inline]"}]},renderHTML({HTMLAttributes:e}){return["span",Zn(e,{"data-avocado-unknown-inline":"",class:"rte-unknown-inline"})]}}),VL=Pn.create({name:"avocadoHtmlAttributes",addGlobalAttributes(){return[{types:["paragraph","heading","bulletList","orderedList","listItem","blockquote","codeBlock","horizontalRule","bold","italic","strike","code"],attributes:{htmlAttributes:{default:null,rendered:!1}}}]}}),xve=[rC.configure({heading:{levels:[1,2,3,4,5,6]},link:!1}),BL,FL,$L,VL,yve,HL,UL],vve=dn.create({name:"doc",topNode:!0,content:"paragraph"}),kve=[rC.configure({document:!1,heading:!1,bulletList:!1,orderedList:!1,listItem:!1,blockquote:!1,codeBlock:!1,horizontalRule:!1,link:!1}),vve,BL,FL,$L,VL,HL,UL],Sve=new Set(["bold","italic","strike","code","underline","link","textStyle","avocadoUnknownHtml"]);function wve(e){return gi.create({name:e,parseHTML(){return[{tag:`span[data-decorator="${e}"]`}]},renderHTML(){return["span",{"data-decorator":e,class:"rte-decorator"},0]}})}function Cve(e=[],t={}){const n=new Set(Sve),r=[];for(const s of e){const o=s==null?void 0:s.name;typeof o!="string"||o.length===0||n.has(o)||(n.add(o),r.push(wve(o)))}const i=t.inline?kve:xve;return r.length>0?[...i,...r]:i}const XD=340,Eve=340,_ve=Aq().map(e=>`.${e}`).join(",");function Tve(e){return e==null||!Number.isFinite(e)||e<=0?"":e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Ave(e){var i;const t=(i=e.contentType)==null?void 0:i.split("/").pop(),n=e.path.split(".").pop(),r=t&&t!=="octet-stream"?t:n;return r&&r.length<=5?r.toUpperCase():""}function Nve({anchorRef:e,initialValue:t,canUpload:n,onCommit:r,onCancel:i}){const{t:s}=Mn(),o=fe(O=>O.availablePages),a=fe(O=>O.availableFiles),u=fe(O=>O.filesStatus),d=fe(O=>O.setAvailableFiles),f=fe(O=>O.setFilesStatus);E.useEffect(()=>{m2()},[]);const[m,g]=E.useState(null);E.useLayoutEffect(()=>{const O=()=>{var $;const U=($=e.current)==null?void 0:$.getBoundingClientRect();if(!U)return;const le=window.innerHeight-U.bottom>=XD?U.bottom+6:Math.max(8,U.top-XD-6),I=Math.min(Math.max(8,U.left),Math.max(8,window.innerWidth-Eve-8));g({top:le,left:I})};return O(),window.addEventListener("resize",O),window.addEventListener("scroll",O,!0),()=>{window.removeEventListener("resize",O),window.removeEventListener("scroll",O,!0)}},[e]);const[y,x]=E.useState(t),[v,S]=E.useState(!1),[w,T]=E.useState(null),[A,M]=E.useState(!1),j=E.useRef(null),D=E.useRef(null),P=E.useRef(null);E.useEffect(()=>{var O,U;(O=j.current)==null||O.focus(),(U=j.current)==null||U.select()},[]),E.useEffect(()=>{const O=U=>{var le,I;const Q=U.target;(le=P.current)!=null&&le.contains(Q)||(I=e.current)!=null&&I.contains(Q)||i()};return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[e,i]);const R=y.trim(),L=cw(R,o,a),{pages:F,files:q}=E.useMemo(()=>bj(R,{pages:o,files:a,limit:6,browseFiles:!0}),[o,a,R]),W=L.kind==="file"&&u==="loading",K=L.kind==="file"&&u==="unavailable",Y=O=>r(O),V=async O=>{S(!0),T(null);try{const U=await Jue(O),Q={path:U.url??"",...U.name?{name:U.name}:{},...U.contentType?{contentType:U.contentType}:{},...U.size!=null?{size:U.size}:{}};if(Q.path){d([...(a??[]).filter(le=>le.path!==Q.path),Q]),f("ready"),Y(Q.path);return}T(s("linkPicker.uploadNoUrl"))}catch(U){T(U instanceof Error?U.message:String(U))}finally{S(!1)}};return m?qd.createPortal(p.jsxs("div",{ref:P,className:`link-picker${A?" is-dropping":""}`,role:"dialog","aria-label":s("linkPicker.title"),style:{top:m.top,left:m.left},onDragOver:n?O=>{O.dataTransfer.types.includes("Files")&&(O.preventDefault(),O.dataTransfer.dropEffect="copy",M(!0))}:void 0,onDragLeave:n?O=>{O.currentTarget.contains(O.relatedTarget)||M(!1)}:void 0,onDrop:n?O=>{var Q;O.preventDefault(),M(!1);const U=(Q=O.dataTransfer.files)==null?void 0:Q[0];U&&V(U)}:void 0,children:[A?p.jsxs("div",{className:"link-picker-drop","aria-hidden":"true",children:[p.jsx(Ug,{size:16})," ",s("linkPicker.dropHere")]}):null,p.jsxs("div",{className:"link-picker-head",children:[p.jsx("span",{className:"link-picker-title",children:s("linkPicker.title")}),p.jsx("button",{type:"button",className:"link-picker-close",onClick:i,"aria-label":s("common.cancel"),children:p.jsx(bs,{size:13,"aria-hidden":"true"})})]}),p.jsx("input",{ref:j,type:"text",className:"link-picker-input",placeholder:s("linkPicker.placeholder"),value:y,title:y,spellCheck:!1,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",onChange:O=>x(O.target.value),onKeyDown:O=>{O.key==="Escape"&&(O.stopPropagation(),i()),O.key==="Enter"&&(O.preventDefault(),Y(R))}}),R!==""&&L.missing===!0?p.jsxs("div",{className:"link-picker-warn",children:[p.jsx(XS,{size:11,"aria-hidden":"true"})," ",s(L.kind==="file"?"linkPicker.noFile":"linkPicker.noPage")]}):null,K?p.jsx("div",{className:"link-picker-note",children:s("linkPicker.filesUnavailable",{orchestrator:Be})}):null,p.jsxs("div",{className:"link-picker-list",role:"listbox",children:[F.map(O=>{var U;return p.jsxs("button",{type:"button",role:"option","aria-selected":((U=L.page)==null?void 0:U.slug)===O.slug,className:"link-picker-option",onMouseDown:Q=>Q.preventDefault(),onClick:()=>Y(O.path??O.slug),children:[p.jsx(fb,{size:12,"aria-hidden":"true"}),p.jsx("span",{className:"link-picker-option-title",children:O.title||O.slug}),p.jsx("span",{className:"link-picker-option-path",title:O.path??O.slug,children:O.path??O.slug})]},`p:${O.slug}`)}),q.map(O=>{var U;return p.jsxs("button",{type:"button",role:"option","aria-selected":((U=L.file)==null?void 0:U.path)===O.path,className:"link-picker-option",onMouseDown:Q=>Q.preventDefault(),title:O.path,onClick:()=>Y(O.path),children:[p.jsx(hb,{size:12,"aria-hidden":"true"}),p.jsx("span",{className:"link-picker-option-title",children:O.name??O.path.split("/").pop()}),p.jsx("span",{className:"link-picker-option-meta",children:[Ave(O),Tve(O.size)].filter(Boolean).join(" · ")})]},`f:${O.path}`)}),W&&q.length===0?p.jsxs("div",{className:"link-picker-empty",children:[p.jsx(fk,{size:12,className:"link-picker-spin","aria-hidden":"true"})," ",s("linkPicker.loadingFiles")]}):null,!W&&F.length===0&&q.length===0?p.jsx("div",{className:"link-picker-empty",children:L.kind==="external"?p.jsxs(p.Fragment,{children:[p.jsx($g,{size:12,"aria-hidden":"true"})," ",s("linkPicker.externalHint")]}):L.kind==="email"?s("linkPicker.emailHint"):L.kind==="phone"?s("linkPicker.phoneHint"):L.kind==="anchor"?s("linkPicker.anchorHint"):s("linkPicker.noMatches")}):null]}),w?p.jsx("div",{className:"link-picker-warn",children:w}):null,p.jsxs("div",{className:"link-picker-foot",children:[n?p.jsxs(p.Fragment,{children:[p.jsx("input",{ref:D,type:"file",hidden:!0,accept:_ve,onChange:O=>{var Q;const U=(Q=O.target.files)==null?void 0:Q[0];O.target.value="",U&&V(U)}}),p.jsxs("button",{type:"button",className:"link-picker-upload",disabled:v,title:s("linkPicker.uploadHint"),onClick:()=>{var O;return(O=D.current)==null?void 0:O.click()},children:[v?p.jsx(fk,{size:12,className:"link-picker-spin","aria-hidden":"true"}):p.jsx(Ug,{size:12,"aria-hidden":"true"})," ",s(v?"linkPicker.uploading":"linkPicker.upload")]})]}):p.jsx("span",{}),p.jsxs("div",{className:"link-picker-actions",children:[t!==""?p.jsx("button",{type:"button",className:"link-picker-remove",onClick:()=>Y(""),children:s("linkPicker.remove")}):null,p.jsx("button",{type:"button",className:"link-picker-apply",onClick:()=>Y(R),children:s("linkPicker.apply")})]})]})]}),document.body):null}const ga=14,Mve=[rC.configure({heading:{levels:[2,3,4,5,6]},link:!1,underline:!1}),Kz.configure({openOnClick:!1}),gve.configure({html:!1,transformPastedText:!0,transformCopiedText:!0})];function Dve(e){var n,r;const t=(r=(n=e.storage.markdown)==null?void 0:n.getMarkdown)==null?void 0:r.call(n);return typeof t=="string"?t:""}function To({active:e,onClick:t,title:n,className:r,children:i}){return p.jsx("button",{type:"button",className:`rte-toolbar-btn${e?" is-active":""}${r?` ${r}`:""}`,onClick:t,title:n,onMouseDown:s=>s.preventDefault(),children:i})}function qL({editor:e,trailing:t,decorators:n,inline:r}){const[i,s]=E.useState(!1),o=E.useRef(null),a=fe(f=>f.canUploadFiles),u=e.getAttributes("link").href??"",d=E.useCallback(f=>{if(s(!1),f===""){e.chain().focus().extendMarkRange("link").unsetLink().run();return}e.chain().focus().extendMarkRange("link").setLink({href:f}).run()},[e]);return p.jsxs("div",{className:`rte-toolbar${t?" rte-toolbar--with-trailing":""}`,children:[p.jsx(To,{active:e.isActive("bold"),onClick:()=>e.chain().focus().toggleBold().run(),title:"Bold",children:p.jsx(QB,{size:ga})}),p.jsx(To,{active:e.isActive("italic"),onClick:()=>e.chain().focus().toggleItalic().run(),title:"Italic",children:p.jsx($9,{size:ga})}),p.jsx(To,{active:e.isActive("strike"),onClick:()=>e.chain().focus().toggleStrike().run(),title:"Strikethrough",children:p.jsx(kF,{size:ga})}),!r&&p.jsx("span",{className:"rte-toolbar-sep"}),!r&&p.jsx(To,{active:e.isActive("heading",{level:2}),onClick:()=>e.chain().focus().toggleHeading({level:2}).run(),title:"Heading 2",children:p.jsx(N9,{size:ga})}),!r&&p.jsx(To,{active:e.isActive("heading",{level:3}),onClick:()=>e.chain().focus().toggleHeading({level:3}).run(),title:"Heading 3",children:p.jsx(j9,{size:ga})}),!r&&p.jsx(To,{active:e.isActive("heading",{level:4}),onClick:()=>e.chain().focus().toggleHeading({level:4}).run(),title:"Heading 4",children:p.jsx(D9,{size:ga})}),!r&&p.jsx("span",{className:"rte-toolbar-sep"}),!r&&p.jsx(To,{active:e.isActive("bulletList"),onClick:()=>e.chain().focus().toggleBulletList().run(),title:"Bullet list",children:p.jsx(K9,{size:ga})}),!r&&p.jsx(To,{active:e.isActive("orderedList"),onClick:()=>e.chain().focus().toggleOrderedList().run(),title:"Ordered list",children:p.jsx(V9,{size:ga})}),p.jsx("span",{className:"rte-toolbar-sep"}),p.jsxs("span",{className:"rte-link-anchor",ref:o,children:[p.jsx(To,{active:e.isActive("link"),onClick:()=>s(f=>!f),title:"Link",children:p.jsx(dR,{size:ga})}),i?p.jsx(Nve,{anchorRef:o,initialValue:u,canUpload:a,onCommit:d,onCancel:()=>s(!1)}):null]}),(n??[]).map(f=>p.jsx(To,{className:"rte-toolbar-btn--tag",active:e.isActive(f.name),onClick:()=>e.chain().focus().toggleMark(f.name).run(),title:f.title??f.name,children:f.title??f.name},f.name)),t?p.jsx("div",{className:"rte-toolbar-trailing",children:t}):null]})}function Rve({value:e,onChange:t,onFocus:n,onBlur:r,trailing:i}){const s=E.useRef(!1),o=E.useRef(e),a=Rz({extensions:Mve,content:bA(e),onUpdate:({editor:u})=>{if(s.current)return;const d=Dve(u);o.current=d,t(d)},onFocus:()=>n==null?void 0:n(),onBlur:()=>r==null?void 0:r()});return E.useEffect(()=>{if(!a||a.isDestroyed||e===o.current)return;o.current=e,s.current=!0;const{from:u,to:d}=a.state.selection;a.commands.setContent(bA(e));const f=a.state.doc.content.size,m=Math.min(u,f),g=Math.min(d,f);try{a.commands.setTextSelection({from:m,to:g})}catch{}s.current=!1},[e,a]),a?p.jsxs("div",{className:"rte-wrap",children:[p.jsx(qL,{editor:a,trailing:i}),p.jsx(V2,{editor:a,className:"rte-content"})]}):null}function KL({value:e,onChange:t,onFocus:n,onBlur:r,decorators:i,inline:s}){const o=E.useRef(!1),a=E.useRef(JSON.stringify(e)),u=`${s?"inline":"block"}:${(i??[]).map(m=>m.name).join(",")}`,d=E.useMemo(()=>Cve(i??[],{inline:s}),[u]),f=Rz({extensions:d,content:e,onUpdate:({editor:m})=>{if(o.current)return;const g=m.getJSON();a.current=JSON.stringify(g),t(g)},onFocus:()=>n==null?void 0:n(),onBlur:()=>r==null?void 0:r()},[u]);return E.useEffect(()=>{if(!f||f.isDestroyed)return;const m=JSON.stringify(e);if(m===a.current)return;a.current=m,o.current=!0;const{from:g,to:y}=f.state.selection;f.commands.setContent(e);const x=f.state.doc.content.size;try{f.commands.setTextSelection({from:Math.min(g,x),to:Math.min(y,x)})}catch{}o.current=!1},[e,f]),f?p.jsxs("div",{className:`rte-wrap${s?" rte-wrap--inline":""}`,children:[p.jsx(qL,{editor:f,decorators:i,inline:s}),p.jsx(V2,{editor:f,className:"rte-content"})]}):null}const QD=new Set(["text","richtext","imageAlt"]),jve=()=>{};function hC(e,t){const n=E.useRef(null),r=E.useRef(void 0);return E.useEffect(()=>{if(!e||!t||t!==e){r.current=t;return}if(r.current===t)return;const i=r.current;r.current=t;const s=n.current;if(!s)return;s.scrollIntoView({behavior:"smooth",block:"nearest"}),s.classList.add("property-field--flash");const o=setTimeout(()=>s.classList.remove("property-field--flash"),1800);return()=>{clearTimeout(o),s.classList.remove("property-field--flash"),r.current=i}},[e,t]),n}const Ive=qn.memo(function({style:t,blockId:n,blockType:r,props:i,status:s,failure:o,failedSlug:a,failedOrigin:u,onRetry:d,onFieldChange:f,onImageClick:m,onAiAssist:g,slug:y,pageName:x,navLabel:v,onNavLabelChange:S,pageMeta:w,onPageMetaChange:T,onDeselectBlock:A,onPageAiAssist:M,onAiQuickAction:j,onPageAiQuickAction:D,aiLoading:P,aiLoadingPath:R,onAddListItem:L,onRemoveListItem:F,highlightPath:q,manifestByType:W,siteOrigin:K,onClose:Y}){const V=fe(ve=>ve.activeBlockId),O=fe(ve=>ve.activeBlockType),U=fe(ve=>ve.slug),Q=fe(ve=>ve.isLoading),le=fe(ve=>ve.activeEditablePath),I=n??V,$=r??O,X=y??U,z=P??Q,Z=R??le,se=q??le,{t:ee}=Mn(),ne=Y?p.jsx("button",{type:"button",className:"property-panel-context-close",onClick:Y,"aria-label":ee("propertyPanel.close"),title:ee("propertyPanel.close"),children:p.jsx(bs,{size:16})}):null,Ae=p.jsxs("div",{className:"property-panel-context property-panel-context--page",children:[p.jsxs("svg",{className:"property-panel-context-icon",viewBox:"0 0 16 16",width:"16",height:"16",fill:"none","aria-hidden":"true",children:[p.jsx("path",{d:"M3.5 1.5h6L13 5v9a.5.5 0 0 1-.5.5h-9a.5.5 0 0 1-.5-.5v-12a.5.5 0 0 1 .5-.5Z",stroke:"currentColor",strokeWidth:"1.2",strokeLinejoin:"round"}),p.jsx("path",{d:"M9.5 1.5V5h3.5",stroke:"currentColor",strokeWidth:"1.2",strokeLinejoin:"round"})]}),p.jsx("div",{className:"property-panel-context-text",children:p.jsx("span",{className:"property-panel-context-breadcrumb",children:p.jsx("span",{className:"property-panel-context-breadcrumb-current",children:ee("propertyPanel.page")})})}),ne]});if(!I||!$)return p.jsxs("div",{className:"property-panel",style:t,children:[Ae,p.jsxs("div",{className:"property-panel-fields",children:[X&&X!=="/"&&S?p.jsx(Kve,{slug:X,navLabel:v??"",onNavLabelChange:S,onAiAssist:M,onAiQuickAction:D,aiLoading:z,fieldShimmer:z===!0&&Z==="Nav label"}):null,X&&T?p.jsx(Gve,{pageMeta:w??{},onPageMetaChange:T,onAiAssist:M,onAiQuickAction:D,aiLoading:z,aiLoadingPath:Z}):null]})]});const _e=Au(),ze=W==null?void 0:W.get($),ce=ze?Sq(ze,_e[$]):_e[$];return ce?p.jsxs("div",{className:"property-panel",style:t,children:[p.jsxs("div",{className:"property-panel-context property-panel-context--component",children:[p.jsxs("svg",{className:"property-panel-context-icon",viewBox:"0 0 16 16",width:"16",height:"16",fill:"none","aria-hidden":"true",children:[p.jsx("rect",{x:"1.5",y:"1.5",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.2"}),p.jsx("rect",{x:"9.5",y:"1.5",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.2"}),p.jsx("rect",{x:"1.5",y:"9.5",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.2"}),p.jsx("rect",{x:"9.5",y:"9.5",width:"5",height:"5",rx:"1",stroke:"currentColor",strokeWidth:"1.2"})]}),p.jsx("div",{className:"property-panel-context-text",children:p.jsxs("span",{className:"property-panel-context-breadcrumb",children:[p.jsx("button",{type:"button",className:"property-panel-context-breadcrumb-link",onClick:A,children:ee("propertyPanel.page")}),p.jsx("span",{className:"property-panel-context-breadcrumb-sep","aria-hidden":"true",children:"›"}),p.jsx("span",{className:"property-panel-context-breadcrumb-current",children:ce.displayName})]})}),ne]}),(s==="loading"||s==="idle"&&!i)&&!i?p.jsx("div",{className:"property-panel-empty",children:ee("propertyPanel.loading")}):s==="error"?p.jsx(Ove,{failure:o??"unreachable",slug:a??X,origin:u,onRetry:d}):i?p.jsxs("div",{className:"property-panel-fields",children:[Object.keys(ce.fields).length>0?p.jsx(ay,{id:`block:${$}:fields`,title:ee("propertyPanel.content"),count:Object.keys(ce.fields).length,children:GL(Object.entries(ce.fields),i,"",$,f,m,g,j,z,Z,se,K)}):null,ce.listFields?Object.entries(ce.listFields).map(([ve,Oe])=>{const oe=Array.isArray(i[ve])?i[ve]:[];return p.jsx(Uve,{listKey:ve,listField:Oe,items:oe,blockType:$,onFieldChange:f,onImageClick:m,onAiAssist:g,onAiQuickAction:j,aiLoading:z,aiLoadingPath:Z,highlightPath:se,onAddItem:L?()=>L(ve):void 0,onRemoveItem:F?He=>F(ve,He):void 0,siteOrigin:K},ve)}):null]}):null]}):p.jsxs("div",{className:"property-panel",style:t,children:[Ae,p.jsxs("div",{className:"property-panel-empty",children:[ee("propertyPanel.unknownBlock"),": ",$]})]})});function ay({id:e,title:t,count:n,headerExtra:r,children:i}){const[s,o]=f6(e);return p.jsxs("div",{className:`property-section${s?" is-collapsed":""}`,children:[p.jsxs("div",{className:"property-section-header",children:[p.jsxs("button",{type:"button",className:"property-section-toggle",onClick:o,"aria-expanded":!s,children:[p.jsx("span",{className:"property-section-chevron","aria-hidden":"true"}),p.jsx("span",{className:"property-section-title",children:t}),typeof n=="number"?p.jsx("span",{className:"property-section-count",children:n}):null]}),r]}),s?null:p.jsx("div",{className:"property-section-body",children:i})]})}function Ove({failure:e,slug:t,origin:n,onRetry:r}){const{t:i}=Mn(),s=i(e==="blockMissing"?"propertyPanel.loadFailedMissing":e==="pageMissing"?"propertyPanel.loadFailedNoPage":"propertyPanel.loadFailed"),o=i(e==="blockMissing"?"propertyPanel.loadFailedMissingHint":e==="pageMissing"?"propertyPanel.loadFailedNoPageHint":"propertyPanel.loadFailedUnreachableHint");return p.jsxs("div",{className:"property-panel-empty",children:[s,p.jsx("div",{className:"sites-form-hint",style:{marginTop:8},children:o}),e!=="unreachable"||n?p.jsxs("div",{className:"sites-form-hint",style:{marginTop:8},children:[p.jsx("code",{children:t}),n?p.jsxs(p.Fragment,{children:[" · ",p.jsx("code",{children:n})]}):null]}):null,r?p.jsx("button",{type:"button",className:"property-panel-retry",onClick:r,style:{marginTop:12},children:i("propertyPanel.retry")}):null]})}function eR(e,t){return!!(e==="imageUrl"&&t==="imageAlt"||e==="src"&&t==="alt"||e.endsWith(".src")&&t===e.replace(/\.src$/,".alt"))}function tR(e){try{const n=new URL(e,"http://localhost").pathname.split("/").pop()||"";return n.length>30?n.slice(0,27)+"...":n||"(image)"}catch{return e.length>30?e.slice(0,27)+"...":e||"(empty)"}}function GL(e,t,n,r,i,s,o,a,u,d,f,m){const g=new Set,y=new Set,x=new Set(e.map(([S])=>S));for(let S=0;S<e.length;S++){const[w,T]=e[S];if(T.kind==="image")for(const[A,M]of e)M.kind==="imageAlt"&&eR(w,A)&&g.add(A);if(T.kind==="link"||T.kind==="file"){const A=mA(w);x.has(A)&&y.add(A)}}const v=[];for(const[S,w]of e)if(!w.internal&&!g.has(S)&&!y.has(S))if(w.kind==="stringList"){const T=t[S];v.push(p.jsx(Fve,{label:w.label??S,values:Array.isArray(T)?T.map(A=>A==null?"":String(A)):[],basePath:n+S,onFieldChange:i},S))}else if(w.kind==="imageList"){const T=t[S];v.push(p.jsx($ve,{label:w.label??S,rows:Array.isArray(T)?T:[],basePath:n+S,blockType:r,siteOrigin:m,onFieldChange:i,onImageClick:s},S))}else if(w.kind==="image"){const T=e.find(([j,D])=>D.kind==="imageAlt"&&eR(S,j)),A=T==null?void 0:T[0],M=A?t[A]==null?"":String(t[A]):void 0;v.push(p.jsx(ZL,{label:w.label??S,blockType:r,imageUrl:t[S]==null?"":String(t[S]),altText:M,onChangeClick:()=>s==null?void 0:s(n+S,t[S]==null?"":String(t[S])),onRemove:()=>{i(n+S,""),A&&i(n+A,"")},onAltCommit:A?j=>i(n+A,j):void 0,onAltAiAssist:A&&o?()=>o(n+A,"Alt text","imageAlt",M??""):void 0,onAltAiQuickAction:A&&a?j=>a(n+A,"Alt text","imageAlt",M??"",j):void 0,fieldPath:n+S,...A?{altFieldPath:n+A}:{},highlightPath:f,aiLoading:u,fieldShimmer:u===!0&&A!=null&&d===n+A,siteOrigin:m},S))}else if(w.kind==="link"||w.kind==="file"){const T=mA(S),A=y.has(T);v.push(p.jsx(Lve,{label:w.label??S,required:w.required,value:t[S]==null?"":String(t[S]),newTab:A?t[T]===!0:void 0,onCommit:M=>i(n+S,M),onNewTabCommit:A?M=>i(n+T,M):void 0,fieldPath:n+S,highlightPath:f,siteOrigin:m},S))}else v.push(p.jsx(qve,{fieldKey:S,field:w,value:t[S],blockType:r,onCommit:T=>i(n+S,T),onAiAssist:QD.has(w.kind)&&o?()=>o(n+S,w.label??S,w.kind,t[S]==null?"":String(t[S])):void 0,onAiQuickAction:QD.has(w.kind)&&a?T=>a(n+S,w.label??S,w.kind,t[S]==null?"":String(t[S]),T):void 0,aiLoading:u,fieldShimmer:u===!0&&d===n+S,highlightPath:f,fieldPath:n+S},S));return v}const Pve={empty:dR,page:fb,file:hb,external:$g,email:Z9,phone:iF,anchor:T9},zve=8;function sk(e){var n;const t=(n=e.title)==null?void 0:n.trim();return t&&t.length>0?t:e.slug}function Lve({label:e,required:t,value:n,newTab:r,onCommit:i,onNewTabCommit:s,fieldPath:o,highlightPath:a,siteOrigin:u}){const{t:d}=Mn(),f=fe(U=>U.availablePages),m=fe(U=>U.availableFiles),g=a!=null&&a===o,y=hC(g?a:void 0,a),[x,v]=E.useState(!1),[S,w]=E.useState(n),[T,A]=E.useState(!1),M=E.useRef(null),{debouncedCommit:j,flushCommit:D}=Yd(i,400),P=T?S:n,R=cw(n,f,m),L=Pve[R.kind],F=R.kind==="external"?Pq(n,u):void 0,{pages:q,files:W}=E.useMemo(()=>bj(T?S:"",{pages:f,files:m,limit:zve}),[f,m,S,T]),K=E.useMemo(()=>T?void 0:Oq(n,f),[n,f,T]);E.useEffect(()=>{if(!x)return;const U=Q=>{var le;(le=M.current)!=null&&le.contains(Q.target)||v(!1)};return document.addEventListener("mousedown",U),()=>document.removeEventListener("mousedown",U)},[x]);const Y=U=>{const Q=U.path??U.slug;w(Q),D(),i(Q),v(!1)},V=U=>{w(U.path),D(),i(U.path),v(!1)},O=s!=null&&R.kind==="external";return p.jsxs("div",{className:`property-field${g?" is-targeted":""}`,ref:y,children:[p.jsx("div",{className:"property-field-label",children:p.jsxs("span",{children:[e,t&&p.jsx("span",{className:"property-field-required",children:"*"})]})}),p.jsxs("div",{className:"property-field-link",ref:M,children:[p.jsxs("div",{className:"property-field-link-input-wrap",children:[p.jsx(L,{size:13,className:"property-field-link-icon","aria-hidden":"true"}),p.jsx("input",{type:"text",className:"property-field-input property-field-link-input",placeholder:d("propertyPanel.linkPlaceholder"),value:P,onFocus:()=>{m2(),w(n),A(!0),v(!0)},onChange:U=>{w(U.target.value),v(!0),j(U.target.value)},onBlur:()=>{A(!1),D()},onKeyDown:U=>{if(U.key==="Escape"&&x&&(U.stopPropagation(),v(!1)),U.key==="Enter"&&x){const Q=q[0];Q&&S.trim()!==""&&S!==n?(U.preventDefault(),Y(Q)):v(!1)}}}),p.jsx("button",{type:"button",className:"property-field-link-toggle","aria-label":d("propertyPanel.linkBrowsePages"),"aria-expanded":x,onClick:()=>v(U=>!U),children:p.jsx(Na,{size:13,"aria-hidden":"true"})})]}),!T&&R.kind==="page"&&R.page?p.jsx("div",{className:"property-field-link-note",children:sk(R.page)}):null,!T&&R.kind==="file"&&R.file?p.jsx("div",{className:"property-field-link-note",children:R.file.name??tR(R.file.path)}):null,R.missing===!0?p.jsxs("div",{className:"property-field-link-note property-field-link-note--warn",children:[p.jsx(XS,{size:11,"aria-hidden":"true"})," ",d(R.kind==="file"?"propertyPanel.linkNoFile":"propertyPanel.linkNoPage")]}):null,K?p.jsx("button",{type:"button",className:"property-field-link-convert",onClick:()=>{const U=K.path??K.slug;w(U),i(U)},children:d("propertyPanel.linkDidYouMean",{page:sk(K)})}):null,F?p.jsx("button",{type:"button",className:"property-field-link-convert",onClick:()=>{w(F),i(F)},children:d("propertyPanel.linkUseInternal",{path:F})}):null,O?p.jsxs("label",{className:"property-field-link-newtab",children:[p.jsx("input",{type:"checkbox",checked:r===!0,onChange:U=>s==null?void 0:s(U.target.checked)}),p.jsx("span",{children:d("propertyPanel.linkNewTab")})]}):null,x?p.jsxs("div",{className:"property-field-link-menu",role:"listbox",children:[q.map(U=>{var Q,le;return p.jsxs("button",{type:"button",role:"option","aria-selected":((Q=R.page)==null?void 0:Q.slug)===U.slug,className:`property-field-link-option${((le=R.page)==null?void 0:le.slug)===U.slug?" is-current":""}`,onMouseDown:I=>I.preventDefault(),onClick:()=>Y(U),children:[p.jsx(fb,{size:12,"aria-hidden":"true"}),p.jsx("span",{className:"property-field-link-option-title",children:sk(U)}),p.jsx("span",{className:"property-field-link-option-slug",children:U.path??U.slug})]},U.slug)}),W.map(U=>{var Q,le;return p.jsxs("button",{type:"button",role:"option","aria-selected":((Q=R.file)==null?void 0:Q.path)===U.path,className:`property-field-link-option${((le=R.file)==null?void 0:le.path)===U.path?" is-current":""}`,onMouseDown:I=>I.preventDefault(),onClick:()=>V(U),children:[p.jsx(hb,{size:12,"aria-hidden":"true"}),p.jsx("span",{className:"property-field-link-option-title",children:U.name??tR(U.path)}),p.jsx("span",{className:"property-field-link-option-slug",children:U.path})]},U.path)}),q.length===0&&W.length===0?p.jsx("div",{className:"property-field-link-empty",children:d("propertyPanel.linkNoMatches")}):null]}):null]})]})}function lp({onClick:e,fieldKind:t,fieldLabel:n,blockType:r,currentValue:i,onQuickAction:s,onCustomPrompt:o,aiLoading:a,variant:u="overlay"}){const[d,f]=E.useState(null);if(fe(x=>x.plannerBadgeState)==="demo")return null;const g=x=>{s&&t&&n&&r!==void 0?f(x.currentTarget.getBoundingClientRect()):e()},y=u==="toolbar"?"rte-toolbar-ai-btn":"property-field-ai-btn";return p.jsxs(p.Fragment,{children:[p.jsx("button",{type:"button",className:`${y}${a?` ${y}--loading`:""}`,onClick:g,onMouseDown:x=>x.preventDefault(),title:"AI suggestions",children:a?p.jsx(jh,{size:14,"aria-hidden":"true"}):p.jsx(fR,{size:14,"aria-hidden":"true"})}),d&&t&&n&&r!==void 0&&p.jsx(Bve,{anchorRect:d,fieldKind:t,fieldLabel:n,blockType:r,currentValue:i??"",aiLoading:a,onSelect:x=>{f(null),s==null||s(x)},onCustomPrompt:()=>{f(null),(o??e)()},onDismiss:()=>f(null)})]})}function Bve({anchorRect:e,fieldKind:t,fieldLabel:n,blockType:r,currentValue:i,aiLoading:s,onSelect:o,onCustomPrompt:a,onDismiss:u}){const d=Ace(t,n,r,i),m=window.innerHeight-e.bottom<160,g=m?void 0:e.bottom+4,y=m?window.innerHeight-e.top+4:void 0,x=window.innerWidth-e.right;return E.useEffect(()=>{const v=S=>{S.key==="Escape"&&u()};return window.addEventListener("keydown",v),()=>window.removeEventListener("keydown",v)},[u]),p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"ai-quick-actions-backdrop",onClick:u}),p.jsxs("div",{className:"ai-quick-actions-menu",style:{top:g,bottom:y,right:x},children:[d.map(v=>p.jsxs("button",{type:"button",className:"ai-quick-actions-item",disabled:s,onClick:()=>o(v),children:[p.jsx(fR,{size:12,"aria-hidden":"true"}),v]},v)),p.jsx("div",{className:"ai-quick-actions-divider"}),p.jsxs("button",{type:"button",className:"ai-quick-actions-item ai-quick-actions-item--custom",onClick:a,children:[p.jsx(nF,{size:12,"aria-hidden":"true"}),"Custom prompt..."]})]})]})}function WL(e,t){return!e||!t||/^https?:\/\//i.test(e)?e:e.startsWith("/")?`${t}${e}`:e}function Fve({label:e,values:t,basePath:n,onFieldChange:r}){const{t:i}=Mn();return p.jsxs("div",{className:"property-field property-field--list",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:e})}),p.jsx("div",{className:"property-list-rows",children:t.map((s,o)=>p.jsxs("div",{className:"property-list-row",children:[p.jsx("input",{className:"property-field-input",value:s,onChange:a=>r(`${n}[${o}]`,a.target.value)}),p.jsx("button",{type:"button",className:"property-list-item-remove-btn",title:i("propertyPanel.removeItem"),onClick:()=>r(n,t.filter((a,u)=>u!==o)),children:"×"})]},`${n}-${o}`))}),p.jsx("button",{type:"button",className:"property-list-add-btn",onClick:()=>r(n,[...t,""]),children:i("propertyPanel.addItem")})]})}function $ve({label:e,rows:t,basePath:n,blockType:r,siteOrigin:i,onFieldChange:s,onImageClick:o}){const{t:a}=Mn(),u=t.find(m=>m&&typeof m=="object")??{},d=["url","imageUrl","src","image"].find(m=>m in u)??"url",f=["alt","imageAlt","image_alt"].find(m=>m in u)??"alt";return p.jsxs("div",{className:"property-field property-field--list",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:e})}),p.jsx("div",{className:"property-list-rows",children:t.map((m,g)=>{const y=`${n}[${g}]`,x=(m==null?void 0:m[d])==null?"":String(m[d]),v=(m==null?void 0:m[f])==null?"":String(m[f]);return p.jsx(ZL,{label:`${e} ${g+1}`,blockType:r,imageUrl:x,altText:v,fieldPath:`${y}.${d}`,altFieldPath:`${y}.${f}`,onChangeClick:()=>o==null?void 0:o(`${y}.${d}`,x),onRemove:()=>s(n,t.filter((S,w)=>w!==g)),onAltCommit:S=>s(`${y}.${f}`,S),siteOrigin:i},y)})}),p.jsx("button",{type:"button",className:"property-list-add-btn",onClick:()=>s(n,[...t,{[d]:"",[f]:""}]),children:a("propertyPanel.addItem")})]})}function ZL({label:e,blockType:t,imageUrl:n,altText:r,fieldPath:i,altFieldPath:s,highlightPath:o,onChangeClick:a,onRemove:u,onAltCommit:d,onAltAiAssist:f,onAltAiQuickAction:m,aiLoading:g,fieldShimmer:y,siteOrigin:x}){const{t:v}=Mn(),S=o&&(o===i||o===s),w=hC(S?o:void 0,o),T=S&&o===s,A=`property-field${S?" is-targeted":""}`,[M,j]=E.useState(r??""),[D,P]=E.useState(!1),[R,L]=E.useState(!1),F=D?M:r??"",{debouncedCommit:q,flushCommit:W}=Yd(d??jve,400);return p.jsxs("div",{className:A,ref:w,children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:e})}),p.jsxs("div",{className:"property-field-image-widget",children:[n&&!R?p.jsxs("div",{className:"property-field-image-preview",children:[p.jsx("img",{className:"property-field-image-thumb",src:WL(n,x),alt:"",onError:()=>L(!0)}),p.jsxs("div",{className:"property-field-image-actions",children:[p.jsxs("button",{type:"button",className:"property-field-image-change",onClick:a,children:[p.jsx(dF,{size:13})," ",v("propertyPanel.change")]}),u?p.jsxs("button",{type:"button",className:"property-field-image-remove",onClick:u,children:[p.jsx(JS,{size:13})," ",v("propertyPanel.remove")]}):null]})]}):p.jsxs("button",{type:"button",className:"property-field-image-empty",onClick:a,children:[p.jsx(O9,{size:18,"aria-hidden":"true"}),p.jsx("span",{children:v("propertyPanel.chooseImage")})]}),d!==void 0&&p.jsxs("div",{className:"property-field-image-alt-group",children:[p.jsx("div",{className:"property-field-image-alt-label",children:p.jsx("span",{children:v("propertyPanel.altText")})}),p.jsxs("div",{className:`property-field-input-wrap${y?" property-field-input-wrap--ai-loading":""}`,children:[p.jsx("input",{type:"text",className:`property-field-image-alt${T?" is-targeted":""}`,placeholder:v("propertyPanel.altPlaceholder"),value:F,onFocus:()=>{j(r??""),P(!0)},onChange:K=>{j(K.target.value),q(K.target.value)},onBlur:()=>{P(!1),W()}}),f?p.jsx(lp,{onClick:f,fieldKind:"imageAlt",fieldLabel:v("propertyPanel.altText"),blockType:t??"",currentValue:r??"",onQuickAction:m,onCustomPrompt:f,aiLoading:y}):null]})]})]})]})}function Uve({listKey:e,listField:t,items:n,blockType:r,onFieldChange:i,onImageClick:s,onAiAssist:o,onAiQuickAction:a,aiLoading:u,aiLoadingPath:d,highlightPath:f,onAddItem:m,onRemoveItem:g,siteOrigin:y}){const[x,v]=E.useState(null),S=t.label??e;return E.useEffect(()=>{if(!f)return;const w=`${e}[`;if(!f.startsWith(w))return;const T=f.slice(w.length),A=T.indexOf("]");if(A<0)return;const M=Number(T.slice(0,A));!Number.isNaN(M)&&M>=0&&M<n.length&&v(M)},[f,e,n.length]),p.jsxs(ay,{id:`list:${r}:${e}`,title:S,count:n.length,children:[n.map((w,T)=>{const A=x===T,{fields:M,discriminantValue:j}=wq(t,w),D=Object.keys(M).find(W=>M[W].kind==="image"),P=D&&w[D]!=null?String(w[D]):"",L=Cq(M,w,T,{...t.discriminator?{discriminator:t.discriminator}:{}}).label,F=j?`[${j}] ${L}`:L,q=F.length>40?F.slice(0,40)+"...":F;return p.jsxs("div",{className:"property-list-item",children:[p.jsxs("button",{type:"button",className:`property-list-item-toggle ${A?"is-expanded":""}`,onClick:()=>v(A?null:T),children:[p.jsx("span",{className:"property-list-item-chevron","aria-hidden":"true"}),P?p.jsx("img",{className:"property-list-item-thumb",src:WL(P,y),alt:"",loading:"lazy"}):null,p.jsx("span",{className:"property-list-item-preview",children:q})]}),A?p.jsxs("div",{className:"property-list-item-fields",children:[GL(Object.entries(M),w,`${e}[${T}].`,r,i,s,o,a,u,d,f,y),g?p.jsxs("button",{type:"button",className:"property-list-item-remove-btn",onClick:()=>g(T),children:[p.jsx("svg",{viewBox:"0 0 16 16",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:p.jsx("path",{d:"M2.5 4h11M6 4V2.5h4V4M5 4l.5 9h5l.5-9M6.5 6.5v4M9.5 6.5v4"})}),"Remove item"]}):null]}):null]},T)}),m?p.jsxs("button",{type:"button",className:"property-list-add-btn",onClick:m,children:[p.jsx("svg",{viewBox:"0 0 16 16",width:"14",height:"14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round","aria-hidden":"true",children:p.jsx("path",{d:"M8 3v10M3 8h10"})}),"Add"]}):null]})}const Hve={h1:"H1 — Page title",h2:"H2 — Section",h3:"H3 — Subsection",h4:"H4",h5:"H5",h6:"H6"};function Vve({value:e,onCommit:t,onFocus:n,onBlur:r,inline:i}){const s=E.useRef(null),[o,a]=E.useState(()=>xA(e)),{debouncedCommit:u,flushCommit:d}=Yd(t,400);return E.useEffect(()=>{e!==s.current&&(s.current=null,a(xA(e)))},[e]),p.jsx(KL,{value:o,onChange:f=>{a(f);const m=aK(f);s.current=m,u(m)},onFocus:n,onBlur:()=>{d(),r==null||r()},inline:i})}function qve({fieldKey:e,field:t,value:n,blockType:r,onCommit:i,onAiAssist:s,onAiQuickAction:o,aiLoading:a,fieldShimmer:u,highlightPath:d,fieldPath:f}){const m=Nce(n),g=m?m.text:n==null?"":String(n),[y,x]=E.useState(g),[v,S]=E.useState(!1),{debouncedCommit:w,flushCommit:T}=Yd(i,400),A=hC(f,d),M=`property-field${f&&f===d?" is-targeted":""}`,j=v?y:g,D=t.label??e,P=()=>{x(g),S(!0)},R=()=>{S(!1),T()};if(t.kind==="reference"){const W=BV(n,t.referenceLabelKey);return p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:D})}),p.jsxs("div",{className:"property-field-reference",title:W?`${W} — managed in the CMS`:"No reference set",children:[p.jsx("span",{className:"property-field-reference-target",children:W||"(not set)"}),p.jsx("span",{className:"property-field-reference-note",children:"CMS"})]})]})}if(m)return p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsxs("span",{children:[D,t.required&&p.jsx("span",{className:"property-field-required",children:"*"})]})}),p.jsx("div",{className:"property-field-input-wrap",children:p.jsx("textarea",{className:"property-field-textarea",rows:Math.min(8,Math.max(3,g.split(`
768
- `).length)),readOnly:!m.editable,value:j,onFocus:m.editable?P:void 0,onBlur:m.editable?R:void 0,onChange:m.editable?W=>{x(W.target.value),w(Mce(W.target.value))}:void 0})})]});if(t.kind==="headingLevel"){const W=(r&&sj[r])??"h2",K=g&&/^h[1-6]$/.test(g)?g:"";return p.jsxs("div",{className:"property-field",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:D})}),p.jsxs("select",{className:"property-field-input property-field-select",value:K,onChange:Y=>i(Y.target.value),children:[p.jsxs("option",{value:"",children:["Auto (",W.toUpperCase(),")"]}),["h1","h2","h3","h4","h5","h6"].map(Y=>p.jsx("option",{value:Y,children:Hve[Y]},Y))]})]})}if(t.kind==="image")return p.jsxs("div",{className:"property-field",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:D})}),p.jsx("div",{className:"property-field-image-url",title:g,children:g||"(empty)"})]});if(t.kind==="enum"&&t.options){const W=t.options.includes(g);return p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:D})}),p.jsxs("select",{className:"property-field-input property-field-select",value:g,onChange:K=>i(K.target.value),children:[!W&&p.jsx("option",{value:g,children:g||"—"}),t.options.map(K=>p.jsx("option",{value:K,children:K},K))]})]})}if(t.kind==="boolean"){const W=g==="true"||g==="1";return p.jsx("div",{className:`${M} property-field--inline`,ref:A,children:p.jsxs("div",{className:"property-field-label",children:[p.jsxs("span",{children:[D,t.required&&p.jsx("span",{className:"property-field-required",children:"*"})]}),p.jsx("button",{type:"button",role:"switch","aria-checked":W,"aria-label":D,className:`property-field-switch${W?" is-on":""}`,onClick:()=>i(W?"false":"true"),children:p.jsx("span",{className:"property-field-switch-knob","aria-hidden":"true"})})]})})}if(t.kind==="color")return p.jsxs("div",{className:"property-field",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:D})}),p.jsx("input",{type:"color",className:"property-field-color",value:g||"#000000",onChange:W=>i(W.target.value)})]});if(t.kind==="html")return p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsxs("span",{children:[D,t.required&&p.jsx("span",{className:"property-field-required",children:"*"})]})}),p.jsx("div",{className:"property-field-input-wrap",children:p.jsx(Vve,{value:g,onCommit:W=>i(W),onFocus:P,onBlur:R,inline:t.inline})})]});if(t.kind==="richtext")return n!==null&&typeof n=="object"?p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsxs("span",{children:[D,t.required&&p.jsx("span",{className:"property-field-required",children:"*"})]})}),p.jsx("div",{className:"property-field-input-wrap",children:p.jsx(KL,{value:n,onChange:W=>w(W),onFocus:P,onBlur:R,decorators:t.decorators,inline:t.inline})})]}):p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsxs("span",{children:[D,t.required&&p.jsx("span",{className:"property-field-required",children:"*"})]})}),p.jsx("div",{className:`property-field-input-wrap${u?" property-field-input-wrap--ai-loading":""}`,children:p.jsx(Rve,{value:g,onChange:W=>{x(W),w(W)},onFocus:P,onBlur:R,trailing:s?p.jsx(lp,{variant:"toolbar",onClick:s,fieldKind:t.kind,fieldLabel:t.label??e,blockType:r??"",currentValue:g,onQuickAction:o,onCustomPrompt:s,aiLoading:u}):null})})]});const L=t.multiline===!0,F=t.kind==="number"?"number":t.kind==="url"?"url":"text",q={value:j,onFocus:P,onChange:W=>{x(W.target.value),w(W.target.value)},onBlur:R};return p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsxs("span",{children:[D,t.required&&p.jsx("span",{className:"property-field-required",children:"*"})]})}),p.jsxs("div",{className:`property-field-input-wrap${u?" property-field-input-wrap--ai-loading":""}`,children:[L?p.jsx("textarea",{className:"property-field-textarea",rows:3,...q}):p.jsx("input",{type:F,className:"property-field-input",...q}),s?p.jsx(lp,{onClick:s,fieldKind:t.kind,fieldLabel:t.label??e,blockType:r??"",currentValue:g,onQuickAction:o,onCustomPrompt:s,aiLoading:u}):null]})]})}function Kve({slug:e,navLabel:t,onNavLabelChange:n,onAiAssist:r,onAiQuickAction:i,aiLoading:s,fieldShimmer:o}){const{t:a}=Mn(),[u,d]=E.useState(t),[f,m]=E.useState(!1),g=f?u:t,{debouncedCommit:y,flushCommit:x}=Yd(v=>n(e,v),400);return p.jsx(ay,{id:"page:nav",title:a("propertyPanel.navigation"),count:1,children:p.jsxs("div",{className:"property-field",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:a("propertyPanel.navLabel")})}),p.jsxs("div",{className:`property-field-input-wrap${o?" property-field-input-wrap--ai-loading":""}`,children:[p.jsx("input",{type:"text",className:"property-field-input",placeholder:a("propertyPanel.navPlaceholder"),value:g,onFocus:()=>{d(t),m(!0)},onChange:v=>{d(v.target.value),y(v.target.value)},onBlur:()=>{m(!1),x()}}),r?p.jsx(lp,{onClick:()=>r("Nav label","text",t),fieldKind:"text",fieldLabel:"Nav label",blockType:"Page",currentValue:t,onQuickAction:i?v=>i("Nav label","text",t,v):void 0,onCustomPrompt:()=>r("Nav label","text",t),aiLoading:o}):null]})]})})}function Gve({pageMeta:e,onPageMetaChange:t,onAiAssist:n,onAiQuickAction:r,aiLoading:i,aiLoadingPath:s}){const{t:o}=Mn();return p.jsxs(ay,{id:"page:seo",title:o("propertyPanel.seo"),count:3,children:[p.jsx(ok,{label:o("propertyPanel.seoTitle"),fieldKind:"text",blockType:"Page",value:e.title??"",placeholder:o("propertyPanel.seoTitlePlaceholder"),multiline:!0,autosizeRows:{min:2,max:2},recommendedMax:60,onCommit:a=>t("title",a),onAiAssist:n?()=>n("SEO title","text",e.title??""):void 0,onAiQuickAction:r?a=>r("SEO title","text",e.title??"",a):void 0,aiLoading:i,fieldShimmer:i===!0&&s==="SEO title"}),p.jsx(ok,{label:o("propertyPanel.metaDescription"),fieldKind:"richtext",blockType:"Page",value:e.description??"",placeholder:o("propertyPanel.metaDescPlaceholder"),multiline:!0,autosizeRows:{min:3,max:6},recommendedMax:160,onCommit:a=>t("description",a),onAiAssist:n?()=>n("Meta description","richtext",e.description??""):void 0,onAiQuickAction:r?a=>r("Meta description","richtext",e.description??"",a):void 0,aiLoading:i,fieldShimmer:i===!0&&s==="Meta description"}),p.jsx(ok,{label:o("propertyPanel.ogImage"),fieldKind:"url",blockType:"Page",value:e.ogImage??"",placeholder:"https://...",onCommit:a=>t("ogImage",a)})]})}function ok({label:e,fieldKind:t,blockType:n,value:r,placeholder:i,multiline:s,autosizeRows:o,recommendedMax:a,onCommit:u,onAiAssist:d,onAiQuickAction:f,aiLoading:m,fieldShimmer:g}){const[y,x]=E.useState(r),[v,S]=E.useState(!1),w=E.useRef(null),T=v?y:r,{debouncedCommit:A,flushCommit:M}=Yd(u,400),j=s===!0&&o!=null,D=E.useCallback(()=>{if(!j||!w.current||!o)return;const L=w.current,F=getComputedStyle(L),q=Number.parseFloat(F.lineHeight),W=Number.parseFloat(F.fontSize)||15,K=Number.isFinite(q)?q:W*1.2,Y=(Number.parseFloat(F.paddingTop)||0)+(Number.parseFloat(F.paddingBottom)||0),V=(Number.parseFloat(F.borderTopWidth)||0)+(Number.parseFloat(F.borderBottomWidth)||0),O=o.min*K+Y+V,U=o.max*K+Y+V;L.style.height="0px";const Q=L.scrollHeight,le=Math.max(O,Math.min(U,Q));L.style.height=`${le}px`,L.style.overflowY=Q>U?"auto":"hidden"},[j,o]);E.useLayoutEffect(()=>{D()},[D,T,v,r]),E.useEffect(()=>{if(!j)return;const L=()=>D();return window.addEventListener("resize",L),()=>window.removeEventListener("resize",L)},[j,D]);const P={placeholder:i,value:T,onFocus:()=>{x(r),S(!0)},onChange:L=>{x(L.target.value),A(L.target.value)},onBlur:()=>{S(!1),M()}},R=(v?y:r).length;return p.jsxs("div",{className:"property-field",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:e})}),p.jsxs("div",{className:`property-field-input-wrap${g?" property-field-input-wrap--ai-loading":""}`,children:[s?p.jsx("textarea",{ref:j?w:void 0,className:`property-field-textarea${j?" property-field-textarea--autosize":""}`,rows:(o==null?void 0:o.min)??3,...P}):p.jsx("input",{type:"text",className:"property-field-input",...P}),d?p.jsx(lp,{onClick:d,fieldKind:t,fieldLabel:e,blockType:n,currentValue:v?y:r,onQuickAction:f,onCustomPrompt:d,aiLoading:g}):null]}),a!=null&&p.jsxs("span",{className:`property-field-char-count${R>a?" property-field-char-count--over":""}`,children:[R," / ",a]})]})}class ak extends E.Component{constructor(){super(...arguments);Te(this,"state",{error:null});Te(this,"reset",()=>{var n,r;(r=(n=this.props).onReset)==null||r.call(n),this.setState({error:null})})}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n,r){var i,s;console.error("[editor] Uncaught error in component tree:",n,r.componentStack),(s=(i=this.props).onError)==null||s.call(i,n,r)}render(){return this.state.error?p.jsxs("div",{style:this.props.style,className:"flex flex-col items-center justify-center gap-3 p-6 text-center text-sm text-muted-foreground h-full",children:[p.jsx("p",{className:"font-medium text-foreground",children:this.props.fallbackLabel??"Something went wrong"}),p.jsx("p",{className:"max-w-xs opacity-70 text-xs",children:this.state.error.message}),p.jsx("button",{type:"button",onClick:this.reset,className:"rounded-md border px-3 py-1.5 text-xs hover:bg-accent transition-colors",children:"Try again"})]}):this.props.children}}function Wve({siteId:e,orchestratorUrl:t,hostedIds:n,siteOwnOrchestrator:r}){const{t:i}=Mn(),s=()=>{uce(e),window.location.href=cce(window.location.href)},o=()=>{r&&(lce(e,r),window.location.reload())};return r?p.jsxs("div",{className:"orchestrator-mismatch",role:"alert",children:[p.jsxs("div",{className:"orchestrator-mismatch-body",children:[p.jsx("strong",{children:i("orchestratorMismatch.ownTitle")}),p.jsx("span",{children:i("orchestratorMismatch.ownDetail",{orchestrator:t,siteOrchestrator:r})})]}),p.jsx("button",{type:"button",className:"orchestrator-mismatch-action",onClick:o,children:i("orchestratorMismatch.useSiteOwn")})]}):p.jsxs("div",{className:"orchestrator-mismatch",role:"alert",children:[p.jsxs("div",{className:"orchestrator-mismatch-body",children:[p.jsx("strong",{children:i("orchestratorMismatch.title")}),p.jsx("span",{children:n.length>0?i("orchestratorMismatch.detailHosts",{orchestrator:t,hosted:n.join(", ")}):i("orchestratorMismatch.detail",{orchestrator:t})})]}),p.jsx("button",{type:"button",className:"orchestrator-mismatch-action",onClick:s,children:i("orchestratorMismatch.useDefault")})]})}const Ag=3e3;function Zve(e){const[t,n]=E.useState({status:"loading",blocks:[],manifest:null});E.useEffect(()=>{let i=!0,s=null;const o=async()=>{try{const u=await fetch(`${e||Vd}/api/editor/blocks`);if(!u.ok){if(!i)return;n({status:"degraded",blocks:[],manifest:null,reason:`Manifest endpoint returned ${u.status}`}),s=setTimeout(()=>{i&&o()},Ag);return}const d=await u.json(),f=lj.safeParse(d);if(!f.success){if(!i)return;n({status:"degraded",blocks:[],manifest:null,reason:"Manifest response shape is invalid"}),s=setTimeout(()=>{i&&o()},Ag);return}const m=fj(f.data.blocks);if(m){if(!i)return;n({status:"degraded",blocks:[],manifest:null,reason:m}),s=setTimeout(()=>{i&&o()},Ag);return}if(!i)return;n({status:"ready",blocks:f.data.blocks,version:f.data.version,manifest:f.data})}catch(a){if(!i)return;n({status:"degraded",blocks:[],manifest:null,reason:a instanceof Error?a.message:"Manifest fetch failed"}),s=setTimeout(()=>{i&&o()},Ag)}};return o(),()=>{i=!1,s&&clearTimeout(s)}},[e]);const r=E.useMemo(()=>{const i=new Map;for(const s of t.blocks)i.set(s.type,s);return i},[t.blocks]);return{...t,byType:r,siteCapabilities:{allowStructuralEdits:t.status==="ready",manifestStatus:t.status,reason:t.reason,manifestVersion:t.version,blockCount:t.blocks.length,checkedAt:new Date().toISOString()},allowStructuralEdits:t.status==="ready"}}function Yve(e){const[t,n]=E.useState(void 0);return E.useEffect(()=>{if($k)return;let r=!1;return ace(e).then(i=>{r||!i||i.replace(/\/+$/,"")!==Be.replace(/\/+$/,"")&&n(i)}),()=>{r=!0}},[e]),t}function Jve(e){const t=e==null?void 0:e.trim().toLowerCase();return t?t==="text"?"text":t==="legacy"||t==="sparkle"||t==="dots"||t==="sparkle-dots"?"legacy":null:null}function Xve(){const e=Jve(Ni().VITE_STREAMING_INDICATOR_STYLE);return e||"text"}const Qve=/^[a-z]{2}(?:-[a-z0-9]{2,8})?$/i,Ol="default",eke=2;let th;function tke(e){if(!Qve.test(e))return!1;if(th===void 0)try{th=new Intl.DisplayNames(["en"],{type:"language",fallback:"none"})}catch{th=null}if(!th)return!1;try{return typeof th.of(e)=="string"}catch{return!1}}function ly(e){return e.split("/").filter(Boolean)}function tc(e){const t=ly(e);return t.length===0?"/":`/${t.join("/")}`}function nke(e){const t={},n=[];for(const u of e){const d=ly(u)[0];if(d&&tke(d)){const f=d.toLowerCase();(t[f]||(t[f]=[])).push(u)}else n.push(u)}const r=Object.keys(t).sort();if(r.length<2)return null;const i=new Map;for(const u of r)for(const d of new Set(t[u].map(f=>pC(f,u))))i.set(d,(i.get(d)??0)+1);if(![...i.values()].some(u=>u>=2))return null;const o=n.filter(u=>i.has(tc(u))).length>=eke,a=o?[]:n;o&&(t[Ol]=n,r.unshift(Ol));for(const u of r){const d=u===Ol?"/":`/${u}`;t[u].sort((f,m)=>f===d?-1:m===d?1:0)}return{locales:r,byLocale:t,shared:a}}function YL(e,t){var i;const n=(i=ly(e)[0])==null?void 0:i.toLowerCase();if(n&&t.byLocale[n])return n;const r=t.byLocale[Ol];return r!=null&&r.some(s=>tc(s)===tc(e))?Ol:void 0}function pC(e,t){var i;if(!t||t===Ol)return tc(e);const n=ly(e);if(((i=n[0])==null?void 0:i.toLowerCase())!==t.toLowerCase())return tc(e);const r=n.slice(1);return r.length===0?"/":`/${r.join("/")}`}function rke(e,t){return`${V4(pC(e,t))} (${e})`}function ike(e,t,n){const r=n.byLocale[t];if(!r||r.length===0)return e;const i=pC(e,YL(e,n)),s=t===Ol?i:i==="/"?`/${t}`:`/${t}${i}`;return r.find(a=>tc(a)===tc(s))??r[0]}function ske(e){try{const t=new Intl.DisplayNames([e],{type:"language"}).of(e);if(t&&t.toLowerCase()!==e.toLowerCase())return t.charAt(0).toUpperCase()+t.slice(1)}catch{}return e.toUpperCase()}const nR=Xve(),oke=!1,ake=dd||oke,lke=xG(),uke=E.lazy(()=>HB(()=>import("./PuckPrototypeRoute-4PdBTH7w.js").then(e=>e.P),__vite__mapDeps([0,1])).then(e=>({default:e.PuckPrototypeRoute}))),cke=new Set(["/editor/puck","/editor/puck/"]),dke=3e4,JL="site-reachable-v1:",fke=5e3;function XL(e){if(typeof sessionStorage>"u")return null;try{const t=sessionStorage.getItem(JL+e);if(!t)return null;const n=JSON.parse(t);return Date.now()-n.ts>dke?null:n.ok}catch{return null}}function rR(e,t){if(!(typeof sessionStorage>"u"))try{sessionStorage.setItem(JL+e,JSON.stringify({ok:t,ts:Date.now()}))}catch{}}function hke({name:e,origin:t,statusClass:n,active:r,dimmed:i,onSelect:s}){const o=t.replace(/^https?:\/\//,"");return p.jsxs("button",{type:"button",role:"menuitem",className:`site-switcher-item${r?" is-active":""}${i?" is-dimmed":""}`,onClick:s,title:t,children:[p.jsx("span",{className:`site-switcher-item-dot site-switcher-item-dot-${n}`,"aria-hidden":"true"}),p.jsxs("span",{className:"site-switcher-item-body",children:[p.jsx("span",{className:"site-switcher-item-name",children:e}),p.jsx("span",{className:"site-switcher-item-origin",children:o})]}),r?p.jsx(Fd,{size:12,"aria-hidden":"true"}):null]})}function iR(e){if(typeof sessionStorage>"u")return null;const t=new Set;let n=!1;for(const r of e){const i=XL(r);i!==null&&(n=!0,i&&t.add(r))}return n?t:null}function pke(e,t){if(e===t)return!0;if(!e||!t||e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function mke(){const e=typeof window<"u"?window.location.pathname:"/",t=e==="/"||e==="/editor"||e==="/editor/",n=cke.has(e),r=e==="/sites"||e==="/sites/";fe(d=>d.chatDarkMode);const i=fe(d=>d.setChatDarkMode),s=E.useMemo(()=>Iw(),[]),o=E.useMemo(()=>Q4(),[]),a=E.useRef(!1);a.current||(a.current=!0,zG({sessionId:s,siteId:o}));const u=fce(o,s);return E.useEffect(()=>{if(typeof window>"u")return;const d=window.matchMedia("(prefers-color-scheme: dark)"),f=m=>{pw()===null&&i(m.matches,{persist:!1})};return d.addEventListener("change",f),()=>d.removeEventListener("change",f)},[i]),n?p.jsx(E.Suspense,{fallback:p.jsx("div",{style:{height:"100vh",display:"grid",placeItems:"center"},children:"Loading prototype…"}),children:p.jsx(uke,{})}):r?p.jsx(RN,{sites:u,session:s}):t?p.jsx(bke,{sites:u}):p.jsx(RN,{sites:u,session:s})}function gke(e){return e.split(".").map(t=>{const n=t.match(/^([a-zA-Z_]+)\[(\d+)\]$/);return n?`${sR(n[1])} ${Number(n[2])+1}`:sR(t)}).join(" · ")}function sR(e){const n=e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/\s*url\s*$/i,"").trim();return n?n.charAt(0).toUpperCase()+n.slice(1):e}function bke({sites:e}){var sf,of,fc;const{t}=Mn(),n=Bi(),r=Fi(),i=fe(_=>_.chatDarkMode),s=fe(_=>_.chatThemePreference),o=fe(_=>_.setChatThemePreference),{activeSiteConfig:a}=e,u=E.useMemo(()=>Pu(a),[a]),d=Zve(u),f=typeof window<"u"?window.location.origin:"http://localhost:4100",m=Yve(u),g=e.siteHosting==="notHosted"||m!=null,y=fe(_=>_.slug),x=fe(_=>_.setSlug),v=fe(_=>_.availableSlugs);fe(_=>_.setAvailableSlugs);const S=fe(_=>_.isLoadingSlugs),w=fe(_=>_.modelKey),T=fe(_=>_.setModelKey),A=fe(_=>_.provider),M=fe(_=>_.setProvider),j=fe(_=>_.availableProviders),D=fe(_=>_.setAvailableProviders),[P,R]=E.useState(""),L=fe(_=>_.activeBlockId),F=fe(_=>_.activeBlockType),q=fe(_=>_.activeEditablePath),W=_=>fe.getState().setActiveBlock(_),K=_=>{const G=fe.getState();G.setActiveBlock(G.activeBlockId,_)},Y=(_,G)=>fe.getState().setActiveBlock(_,G),V=fe(_=>_.setActiveEditablePath),O=fe(_=>_.useStreaming),U=fe(_=>_.setUseStreaming),Q=fe(_=>_.autoScrollTrackingEnabled),le=fe(_=>_.setAutoScrollTrackingEnabled),I=fe(_=>_.autoOpenPropertiesEnabled),$=fe(_=>_.setAutoOpenPropertiesEnabled),[X,z]=E.useState(!1),[Z,se]=E.useState(lke),ee=E.useCallback(_=>{se(_);try{window.localStorage.setItem(wk,_?"1":"0")}catch{}},[]),ne=E.useMemo(()=>!dd||new URLSearchParams(window.location.search).has("dev"),[]),Ae=ne&&Z,[_e,ze]=E.useState(!1),[ce,ve]=E.useState(0),Oe=E.useCallback(()=>ve(_=>_+1),[]),oe=fe(_=>_.showSettingsModal),He=fe(_=>_.setShowSettingsModal),$e=fe(_=>_.showDebugDetails),bt=fe(_=>_.setShowDebugDetails),Gt=fe(_=>_.composerHeight),Ct=fe(_=>_.setComposerHeight),ct=fe(_=>_.addBlockPicker),Xt=fe(_=>_.setAddBlockPicker),kt=fe(_=>_.addBlockSearch),St=fe(_=>_.setAddBlockSearch),nt=fe(_=>_.isAddingBlock),gn=fe(_=>_.setIsAddingBlock),he=fe(_=>_.copiedDebugEntryId),me=fe(_=>_.setCopiedDebugEntryId),Fe=fe(_=>_.feedbackNoteEntryId),et=fe(_=>_.setFeedbackNoteEntryId),ft=fe(_=>_.feedbackNoteText),Ot=fe(_=>_.setFeedbackNoteText),cr=fe(_=>_.selectedVariationId),fn=fe(_=>_.setSelectedVariationId),Nt=fe(_=>_.imagePickerTarget),zn=fe(_=>_.setImagePickerTarget),tn=Nt!==null,Tr=fe(_=>_.backendFeatures),Ar=fe(_=>_.setBackendFeatures),ke=fe(_=>_.setBackendSite),Ue=fe(_=>_.selectionModeEnabled),ge=fe(_=>_.setSelectionModeEnabled),je=fe(_=>_.anchorRect),Le=fe(_=>_.setAnchorRect),Pe=fe(_=>_.anchoredExpanded),tt=fe(_=>_.setAnchoredExpanded),Ke=fe(_=>_.activeTab),ht=fe(_=>_.setActiveTab),[Bt,Wt]=E.useState(!1),[wn,Ln]=E.useState(!1),nr=E.useRef(null);E.useEffect(()=>{if(!wn)return;const _=ie=>{nr.current&&!nr.current.contains(ie.target)&&Ln(!1)},G=ie=>{ie.key==="Escape"&&Ln(!1)};return document.addEventListener("mousedown",_),document.addEventListener("keydown",G),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",G)}},[wn]);const[Gi,Gs]=E.useState(()=>iR(e.siteList.map(_=>_.id))),qr=E.useCallback(_=>{Gs(G=>pke(G,_)?G:_)},[]);E.useEffect(()=>{if(!wn)return;qr(iR(e.siteList.map(ie=>ie.id)));let _=!0;return(async()=>{let ie=!0;const Ce=await Promise.all(e.siteList.map(async De=>{const Ve=XL(De.id);if(Ve!==null)return{id:De.id,ok:Ve};ie=!1;const Qe=Pu(De);try{const pn=await fetch(`${Qe}/api/editor/blocks?siteId=${encodeURIComponent(De.id)}`,{signal:AbortSignal.timeout(2500)});return rR(De.id,pn.ok),{id:De.id,ok:pn.ok}}catch{return rR(De.id,!1),{id:De.id,ok:!1}}}));_&&!ie&&qr(new Set(Ce.filter(De=>De.ok).map(De=>De.id)))})(),()=>{_=!1}},[wn,e.siteList,qr]);const Kr=E.useMemo(()=>{const _=Gi===null;return e.siteList.map(G=>{const ie=_||G.id===r||Gi.has(G.id);return{site:G,origin:Pu(G),online:ie,probing:_}}).sort((G,ie)=>G.site.id===r?-1:ie.site.id===r?1:G.online!==ie.online?G.online?-1:1:G.site.name.localeCompare(ie.site.name))},[Gi,e.siteList,r]),{onlineEntries:Ws,activeEntry:Nr}=E.useMemo(()=>({onlineEntries:Kr.filter(_=>_.online),activeEntry:Kr.find(_=>_.site.id===r)}),[Kr,r]),jt=E.useRef(null),Bn=E.useRef(null),jr=E.useRef(!0),ks=E.useRef(!1),Ss=E.useRef(null),bi=E.useRef(void 0),mr=E.useRef(!1),Wi=E.useRef(null),Zi=E.useRef(!1),si=E.useRef(0),oi=E.useRef(null),Fn=E.useRef(null),an=fe(_=>_.chatWidth),Mt=fe(_=>_.setChatWidth),ws=fe(_=>_.propsWidth),Gr=fe(_=>_.setPropsWidth),gr=E.useRef(null),Wr=E.useRef(null),[Yi,Go]=E.useState(1),Cs=E.useRef(null),go=E.useRef(null),Ji=E.useRef(!1),Es=E.useRef(!1);E.useEffect(()=>{if(!Es.current&&!(S||v.length===0)){if(y!=="/"||v.includes("/")){Es.current=!0;return}Es.current=!0,mr.current=!1,x(v[0])}},[v,S,y,x]);const Ir=E.useMemo(()=>{const _=Array.from(new Set([...v,y].filter(Boolean)));return _.includes("/")?["/",..._.filter(G=>G!=="/")]:_},[v,y]),hn=E.useMemo(()=>nke(Ir),[Ir]),Or=hn?YL(y,hn)??hn.locales[0]:void 0,Wo=E.useMemo(()=>!hn||!Or?Ir:hn.byLocale[Or]??[],[hn,Or,Ir]),Xi=E.useMemo(()=>{if(!d.allowStructuralEdits)return[];if(d.blocks.length>0)return d.blocks.map(G=>({type:G.type,label:G.displayName??G.type,category:"content"})).sort((G,ie)=>G.label.localeCompare(ie.label));const _=Au();return[...bk].map(G=>{var ie,Ce;return{type:G,label:((ie=_[G])==null?void 0:ie.displayName)??G,category:((Ce=_[G])==null?void 0:Ce.category)??"content"}}).sort((G,ie)=>G.label.localeCompare(ie.label))},[d.allowStructuralEdits,d.blocks]),ja=E.useMemo(()=>{const _=kt.trim().toLowerCase(),G=_?Xi.filter(De=>De.label.toLowerCase().includes(_)||De.type.toLowerCase().includes(_)):Xi,ie=new Map;for(const De of G){const Ve=De.category||"content",Qe=ie.get(Ve);Qe?Qe.push(De):ie.set(Ve,[De])}const Ce=["content","layout","conversion","navigation","media"];return[...ie.entries()].sort((De,Ve)=>{const Qe=Ce.indexOf(De[0]),pn=Ce.indexOf(Ve[0]),rr=Qe===-1?Number.MAX_SAFE_INTEGER:Qe,En=pn===-1?Number.MAX_SAFE_INTEGER:pn;return rr!==En?rr-En:De[0].localeCompare(Ve[0])}).map(([De,Ve])=>({category:De,options:Ve}))},[kt,Xi]),Mi=()=>{const _=Date.now();_-si.current<1200||(si.current=_,Ge.pushAssistantFromResult({status:"needs_clarification",summary:t("streamError.structuralDisabled"),changes:SP(d.reason)}))},eu=E.useRef(()=>{}),Cn=E.useCallback(_=>{fe.getState().slug!==_&&(Zi.current=!0,x(_))},[x]),Zs=E.useMemo(()=>({onBlockClicked:(_,G,ie,Ce,De,Ve)=>{Cn(_),Y(G,ie),V(Ce),Le(G?Ve:null);const Qe=fe.getState();G?Qe.autoOpenPropertiesEnabled&&Qe.setActiveTab("properties"):Qe.setActiveTab("chat")},onRouteChanged:_=>{fe.getState().slug!==_&&Y(void 0,void 0),Cn(_),V(void 0),Le(null),yi.current("setSelectionMode",{enabled:fe.getState().selectionModeEnabled}),eu.current(_)},onBlockReordered:(_,G,ie)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),V(void 0),Ge.reorderBlock(_,G,ie)},onBlockDeleteRequested:(_,G)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),V(void 0),Ge.deleteBlock(_,G)},onBlockAddRequested:(_,G)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),!(!G.afterBlockId&&!G.beforeBlockId)&&Xt({slug:_,afterBlockId:G.afterBlockId,beforeBlockId:G.beforeBlockId})},onListItemAddRequested:(_,G,ie,Ce,De)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),V(void 0),Ge.addListItem(_,G,ie,Ce,De)},onListItemRemoveRequested:(_,G,ie,Ce,De)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),V(void 0),Ge.removeListItem(_,G,ie,Ce,De)},onListItemMoveRequested:(_,G,ie,Ce,De,Ve)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),V(void 0),Ge.moveListItem(_,G,ie,Ce,De,Ve)},onOpenImagePicker:(_,G,ie,Ce,De)=>{zn({slug:_,blockId:G,editablePath:ie,currentUrl:Ce,blockType:De??(G===L?F:void 0)})},onEditBlockRequested:(_,G)=>{tt(!0)},onInlineTextCommitted:(_,G,ie,Ce)=>{_!==y&&Cn(_),ie&&V(ie),Ge.inlineEditCommit(_,G,ie,Ce)},onIframeScrolled:()=>{Le(null),fe.getState().isLoading&&fe.getState().setAutoScrollSuppressed(!0)}}),[d.allowStructuralEdits,Cn,y]),Ia=E.useCallback(async()=>{var _;try{const G=`${Be}/draft/pages?session=${encodeURIComponent(n)}&siteId=${encodeURIComponent(r)}&slug=${encodeURIComponent(y)}`,ie=await fetch(G,{cache:"no-store"});if(!ie.ok)return;const De=((await ie.json()).blocks??[]).find(Ve=>Ve.type==="Hero");if(!De)return;Y(De.id,De.type),zn({slug:y,blockId:De.id,editablePath:"imageUrl",currentUrl:typeof((_=De.props)==null?void 0:_.imageUrl)=="string"?De.props.imageUrl:void 0,blockType:De.type})}catch{}},[n,r,y,zn]),Qt=hce(y,Zs,u),yi=E.useRef(Qt.postToSite);E.useEffect(()=>{yi.current=Qt.postToSite},[Qt.postToSite]);const Ys=E.useCallback(_=>{const G=_??!Ue;ge(G),Qt.postToSite("setSelectionMode",{enabled:G})},[Ue,Qt]);E.useEffect(()=>{const _=G=>{G.key==="Escape"&&Ue&&Ys(!1)};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[Ue,Ys]),E.useEffect(()=>{if(Ke!=="history")return;const _=G=>{G.key==="Escape"&&fe.getState().setActiveTab("chat")};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[Ke]);const Zo=E.useCallback((_,G)=>{(_==="draftUpdated"||_==="liveDraft")&&Oe(),Qt.postToSite(_,G)},[Qt,Oe]),xi=E.useCallback((_,G,ie,Ce)=>(Oe(),Qt.postPatchToSite(_,G,ie,Ce)),[Qt,Oe]),Ge=xce({activeSiteConfig:a,siteRegistryChecked:e.siteRegistryChecked,postToSite:Zo,postPatchToSite:xi,componentManifest:d.manifest,siteCapabilities:d.siteCapabilities,allowStructuralEdits:d.allowStructuralEdits,getBlockDefaultProps:_=>{var G;return((G=d.byType.get(_))==null?void 0:G.defaultProps)??null},onApplied:()=>{var _;(_=bi.current)==null||_.call(bi)},agentModeEnabled:Tr.agentMode??!1}),ai=fe(_=>_.chatLog),Oa=fe(_=>_.chatAttachments),bo=fe(_=>_.setChatAttachments),Kn=fe(_=>_.isLoading),br=fe(_=>_.streamStatus),Js=fe(_=>_.streamingText),Qi=fe(_=>_.streamingChanges),tu=fe(_=>_.streamSteps),Xs=fe(_=>_.streamTokenCount),es=fe(_=>_.latestStreamFocusBlockId),Pr=fe(_=>_.imageProgress),Di=fe(_=>_.plannerBadgeState),[yo,_s]=E.useState(!1),Qs=fe(_=>_.setPlannerBadgeState),dt=fe(_=>_.pendingPlanId),mt=fe(_=>_.variationModal),we=fe(_=>_.isApplyingVariation),Pt=fe(_=>_.setVariationModal),Ri=fe(_=>_.continuationChainId),vi=fe(_=>_.fieldDraftDebugEnabled),li=fe(_=>_.setFieldDraftDebugEnabled),zr=fe(_=>_.fieldDraftDebug);E.useEffect(()=>{X4.has(r)||(T("balanced"),Ge.clearChat())},[r]);function it(_){var G,ie;typeof _.navigateToSlug=="string"&&_.navigateToSlug.length>0&&_.navigateToSlug!==y&&x(_.navigateToSlug),typeof _.canUndo=="boolean"&&((G=Ge.setCanUndoServer)==null||G.call(Ge,_.canUndo)),typeof _.canRedo=="boolean"&&((ie=Ge.setCanRedoServer)==null||ie.call(Ge,_.canRedo)),Qt.postToSite("draftUpdated",{focusBlockId:null}),Oe()}async function xt(_){Wt(!0);try{const ie=await(await fetch(`${Be}/history/restore`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session:n,siteId:r,targetVersion:_})})).json();ie.status==="applied"&&it(ie)}catch{}finally{Wt(!1)}}const _t=Sce(n,r,u,ce),Vt=kce(n,r,Kn,Ge.pushAssistantFromResult,u,()=>{Qt.postToSite("draftUpdated",{focusBlockId:null}),_t.markPublished()}),dr=_t.summary?_t.summary.total>0:!0,zt=wce(),bn=Ke==="properties"&&Ge.hasBootstrapped,ln=_ce(n,r,y,L,bn),nn=Tce(n,r,y,bn);E.useEffect(()=>{!L||F||!ln.blockType||K(ln.blockType)},[L,F,ln.blockType]);const Mr=$ee(n,r,!!n),nu=Uee(Mr.findings),Zr=E.useRef(null),eo=E.useCallback((_,G,ie)=>{Y(_,G),V(ie),Le(null),fe.getState().selectionModeEnabled||(fe.getState().setSelectionModeEnabled(!0),yi.current("setSelectionMode",{enabled:!0})),yi.current("highlightBlock",{blockId:_,editablePath:ie??null,scrollIntoView:!0})},[]),xo=E.useCallback(_=>{const G=Zr.current;!G||G.slug!==_||(Zr.current=null,!(G.expiresAt!==void 0&&Date.now()>G.expiresAt)&&eo(G.blockId,G.blockType,G.path))},[eo]);E.useEffect(()=>{if(!Zr.current)return;const _=setTimeout(()=>xo(y),400);return()=>clearTimeout(_)},[y,xo]),E.useEffect(()=>{eu.current=xo},[xo]);const uy=E.useCallback((_,G,ie,Ce)=>{if(!G){_!==fe.getState().slug&&x(_),Y(void 0,void 0),V(void 0),ht("properties");return}if(_!==fe.getState().slug){Zr.current={slug:_,blockId:G,blockType:ie,path:Ce},x(_),ht("properties");return}ht("properties"),Zr.current={slug:_,blockId:G,...ie?{blockType:ie}:{},...Ce?{path:Ce}:{},expiresAt:Date.now()+fke},eo(G,ie,Ce)},[eo]);bi.current=()=>{ln.refetch(),nn.refetch(),Oe()};const[cc,cy]=E.useState(()=>Uk(y,{session:n,siteId:r,editorOrigin:f},u)),[dy,Tp]=E.useState(!1);E.useEffect(()=>{Tp(!1)},[cc]),E.useEffect(()=>{Wi.current!==u&&(Wi.current=u,mr.current=!1);const _={session:n,siteId:r,editorOrigin:f};if(Zi.current){Zi.current=!1;return}if(e0&&mr.current){Qt.postToSite("navigate",{href:Hk(y,_)});return}const G=Uk(y,_,u);cy(ie=>ie===G?ie:G)},[u,f,n,r,y]);const Ap=E.useMemo(()=>{var ie;const _=(ie=a.vercelProductionUrl)==null?void 0:ie.trim(),G=_&&/^https?:\/\//i.test(_)?_:u;try{const Ce=new URL(G);return Ce.origin===u?xee(y,{},u):(Ce.pathname=y==="/"?"/":y,Ce.search="",Ce.hash="",Ce.toString())}catch{return}},[a.vercelProductionUrl,u,y]),Np=E.useMemo(()=>u?`${u}${Hk(y,{session:n,siteId:r,editorOrigin:f,immersive:"1"})}`:void 0,[u,f,n,r,y]);E.useEffect(()=>{let _=!0;const G=async()=>{const Ce=[`${Be}/status/planner`];Be.includes("localhost")&&Ce.push(`${Be.replace("localhost","127.0.0.1")}/status/planner`);try{for(const De of Ce){const Ve=await fetch(De);if(!Ve.ok)continue;const Qe=await Ve.json();if(!_)return;if(Qe.features&&Ar(Qe.features),Qe.site&&ke(Qe.site),Array.isArray(Qe.availableProviders)&&Qe.availableProviders.length>0&&(D(Qe.availableProviders),(!Qe.availableProviders.includes(A)||A!=="anthropic"&&Qe.availableProviders.includes("anthropic"))&&M(Qe.availableProviders.includes("anthropic")?"anthropic":Qe.availableProviders[0])),typeof Qe.keyFilePath=="string"&&Qe.keyFilePath.length>0&&fe.getState().setKeyFilePath(Qe.keyFilePath),Qe.plannerSource==="openai"||Qe.plannerSource==="anthropic"||Qe.plannerSource==="gemini"||Qe.plannerSource==="demo"){Qs(Qe.plannerSource);return}}_&&Qs("error")}catch{_&&Qs("error")}};G();const ie=window.setInterval(()=>{G()},1e4);return()=>{_=!1,window.clearInterval(ie)}},[]);const Qd=E.useRef(0),Mp=E.useRef(0);E.useEffect(()=>{const _=Bn.current;if(!_)return;const G=()=>{const ie=Math.abs(_.scrollHeight-_.scrollTop-_.clientHeight)<2||_.scrollHeight<=_.clientHeight;!ie&&_.scrollTop<Qd.current?jr.current=!1:ie&&(jr.current=!0),Qd.current=_.scrollTop};return _.addEventListener("scroll",G,{passive:!0}),()=>{_.removeEventListener("scroll",G)}},[]),E.useEffect(()=>{const _=Bn.current;if(!_||!(ai.length>0||!!br||!!Js))return;const ie=ai.reduce((pn,rr)=>rr.role==="user"?pn+1:pn,0);ie>Mp.current&&(jr.current=!0),Mp.current=ie;const Ce=!ks.current,De=ai.some(pn=>pn.role==="user");if(Ce&&!De&&!br&&!Js){ks.current=!0,jr.current=!1;return}if(!Ce&&!jr.current)return;const Qe=window.requestAnimationFrame(()=>{_.scrollTop=_.scrollHeight,jr.current=!0,ks.current=!0});return()=>window.cancelAnimationFrame(Qe)},[ai.length,br,Js,tu.length,Qi.length]),E.useEffect(()=>{Qt.postToSite("setNestedLabelsVisibility",{visible:X})},[X]),E.useEffect(()=>{const _=yi.current;if(!Kn){Ji.current&&_("aiFieldLoading",{blockId:"",active:!1}),go.current=null,Ji.current=!1;return}const G=es??L??"",Ce=G&&G===(L??"")?q??"":"";_("aiFieldLoading",{blockId:G,editablePath:Ce,active:!0}),go.current={blockId:G,editablePath:Ce},Ji.current=!0},[Kn,es,L,q]),E.useEffect(()=>{if(!Kn)return;const _=window.setInterval(()=>{const G=go.current;G&&yi.current("aiFieldLoading",{blockId:G.blockId,editablePath:G.editablePath,active:!0})},1200);return()=>window.clearInterval(_)},[Kn]),E.useEffect(()=>{L&&Qt.postToSite("highlightBlock",{blockId:L,editablePath:q??null})},[L,q]),E.useEffect(()=>{Ge.clearFieldAiContext()},[L]),E.useEffect(()=>{L||Le(null)},[L]),E.useEffect(()=>{tt(!1)},[je]),E.useEffect(()=>{const _=()=>Le(null);return window.addEventListener("resize",_),()=>window.removeEventListener("resize",_)},[]);const fy=RG(),Pa=E.useMemo(()=>{if(!fy||!je||!Ue||!L||typeof window>"u"||window.innerWidth<=1040)return null;const _=Qt.iframeRef.current;if(!_)return null;const G=_.getBoundingClientRect(),ie=380,Ce=36,De=26,Ve=8,Qe=G.top+je.top*Yi;if(Qe+je.height*Yi<G.top||Qe>G.bottom)return null;const rr=Qe+Ve-(Ce-De)/2;let En=G.left+(je.left+je.width)*Yi-Ce-Ve;return En=Math.max(G.left+Ve,Math.min(En,G.right-Ce-Ve)),{top:rr,left:En,width:ie}},[je,Ue,L,Qt.iframeRef,Yi]);E.useEffect(()=>{Pa&&Pe&&requestAnimationFrame(()=>{var _,G;(G=(_=Cs.current)==null?void 0:_.querySelector("textarea"))==null||G.focus()})},[!!Pa,Pe]);const hy=E.useCallback((_,G,ie,Ce)=>{var rr;if(!L||!F)return;const Ve=((rr=Au()[F])==null?void 0:rr.displayName)??F;V(_);const Qe=dS(ie,G,F,Ce),pn={id:`field-ai-${Date.now()}`,role:"assistant",text:`Editing: ${Ve} → ${G}`,fieldAiContext:{blockId:L,blockType:F,fieldPath:_,fieldLabel:G,blockDisplayName:Ve},suggestions:Qe};Ge.setFieldAiContext(pn)},[L,F]),ef=E.useCallback((_,G,ie)=>{const Ce=dS(G,_,"Page",ie),De={id:`field-ai-${Date.now()}`,role:"assistant",text:`Editing: Page → ${_}`,fieldAiContext:{blockId:"__page__",blockType:"__page__",fieldPath:_,fieldLabel:_,blockDisplayName:"Page"},suggestions:Ce};Ge.setFieldAiContext(De)},[]),py=E.useCallback((_,G,ie,Ce,De)=>{var rr;if(!L||!F)return;const Qe=((rr=Au()[F])==null?void 0:rr.displayName)??F;V(_),Qt.postToSite("aiFieldLoading",{blockId:L,editablePath:_,active:!0}),go.current={blockId:L,editablePath:_},Ji.current=!0;const pn={id:`field-ai-${Date.now()}`,role:"assistant",text:`Editing: ${Qe} → ${G}`,fieldAiContext:{blockId:L,blockType:F,fieldPath:_,fieldLabel:G,blockDisplayName:Qe}};Ge.setFieldAiContext(pn),Ge.submitChat(De)},[L,F]),my=E.useCallback((_,G,ie,Ce)=>{V(_);const De={id:`field-ai-${Date.now()}`,role:"assistant",text:`Editing: Page → ${_}`,fieldAiContext:{blockId:"__page__",blockType:"__page__",fieldPath:_,fieldLabel:_,blockDisplayName:"Page"}};Ge.setFieldAiContext(De),Ge.submitChat(Ce)},[]);E.useEffect(()=>{Ge.refreshRouteSlugs()},[n,r,e.siteRegistryChecked]);const tf=_=>{const ie=jt.current,Ce=Bn.current;if(!ie||!Ce)return Math.max(56,_);const De=120,Ve=10,Qe=Ce.offsetTop,pn=Math.max(56,ie.clientHeight-Qe-Ve-De);return Math.min(pn,Math.max(56,_))},Dp=E.useCallback(_=>{Ct(G=>{const ie=tf(_);return ie===G?G:ie})},[]);E.useEffect(()=>{const _=ie=>{const Ce=oi.current;if(Ce){const Ve=ie.clientY-Ce.y,Qe=tf(Ce.composerHeight-Ve);Ct(Qe)}const De=Fn.current;if(De){const Ve=ie.clientX-De.x;De.target==="chat"?Mt(_k(De.width+Ve)):Gr(Tk(De.width-Ve))}},G=()=>{const ie=!!Fn.current;oi.current=null,Fn.current=null,document.body.style.userSelect="",ie&&document.body.classList.remove("panel-resizing")};return window.addEventListener("pointermove",_),window.addEventListener("pointerup",G),()=>{window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",G),document.body.style.userSelect="",document.body.classList.remove("panel-resizing")}},[]),E.useEffect(()=>{const _=()=>{Ct(G=>tf(G)),Mt(G=>G&&_k(G)),Gr(G=>G&&Tk(G))};return window.addEventListener("resize",_),()=>window.removeEventListener("resize",_)},[Mt,Gr]),E.useEffect(()=>{if(!mt)return;const _=G=>{G.key==="Escape"&&!we&&Pt(null)};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[mt,we]),E.useEffect(()=>{mt!=null&&mt.options.length?fn(mt.options[0].id):fn(null)},[mt]),E.useEffect(()=>{ct||St("")},[ct]),E.useEffect(()=>{if(!ct)return;const _=G=>{G.key==="Escape"&&!nt&&Xt(null)};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[ct,nt]);const nf=br?/failed|error/i.test(br):!1,[Rp,jp]=E.useState(0),gy=Pr==null?void 0:Pr.stage;E.useEffect(()=>{if(jp(0),!Kn)return;const _=window.setInterval(()=>jp(G=>G+1),1e3);return()=>window.clearInterval(_)},[Kn,br,gy]);const Ip=Kn&&!nf&&Rp>=5?` · ${Rp}s`:"",by=(Pr?Pr.stage:br??(Xs>0?t("stream.shapingUpdate"):t("stream.gettingReady")))+Ip,Op=(Pr?Pr.stage:br??(Xs>0?t("stream.updating"):t("stream.thinking")))+Ip,to=(br==null?void 0:br.match(/reconnecting(?:\s+agent\s+stream)?(?:\s+\((\d+)\/(\d+)\))?/i))??null,Pp=to!=null&&to[1]?Number(to[1]):null,dc=to!=null&&to[2]?Number(to[2]):null,vo=to?Pp&&dc?`Reconnect ${Pp}/${dc}`:"Reconnecting":null,zp=`field_draft ${zr.eventsPerSecond}/s · chars ${zr.charsPerSecond}/s · lag ${zr.typingLagChars}`,Lp={"--composer-height":`${Gt}px`},ko=Ke==="properties",za=Ke==="history",ru=Ke==="health",rf=E.useCallback(()=>{W(void 0),K(void 0),ht("chat")},[]);E.useLayoutEffect(()=>{const _=Wr.current,G=Qt.iframeRef.current;if(!_||!G)return;const ie=Ve=>{var ts;if(Ve?G.classList.remove("preview-iframe-no-transition"):G.classList.add("preview-iframe-no-transition"),!ko){G.style.removeProperty("width"),G.style.removeProperty("height"),G.style.removeProperty("transform"),Go(Ts=>Ts===1?Ts:1);return}const Qe=_.offsetWidth,pn=((ts=gr.current)==null?void 0:ts.offsetWidth)??0;if(Qe<=0||pn<=0)return;const rr=Qe+pn,En=Qe/rr;G.style.width=`${rr}px`,G.style.height=`${100/En}%`,G.style.transform=`scale(${En})`,Go(Ts=>Math.abs(Ts-En)<5e-4?Ts:En)};ie(!0);const Ce=new ResizeObserver(()=>ie(!1)),De=window.setTimeout(()=>{Ce.observe(_);const Ve=gr.current;Ve&&Ce.observe(Ve)},240);return()=>{window.clearTimeout(De),G.classList.remove("preview-iframe-no-transition"),Ce.disconnect()}},[ko,Qt.iframeRef]);const La={...an?{"--chat-width":`${an}px`}:{},...ws?{"--props-width":`${ws}px`}:{}},Bp=ai.some(_=>_.role==="user"),Fp=E.useCallback(_=>{const G=[];_.text&&G.push(_.text),_.status&&!_.canUndo&&_.status!=="needs_clarification"&&_.status!=="plan_ready"&&G.push(`status: ${_.status}`);const ie=(_.changes??[]).filter(Ce=>!q4(_.text,Ce));if(ie.length>0&&G.push(`changes: ${ie.join(`
768
+ `).length)),readOnly:!m.editable,value:j,onFocus:m.editable?P:void 0,onBlur:m.editable?R:void 0,onChange:m.editable?W=>{x(W.target.value),w(Mce(W.target.value))}:void 0})})]});if(t.kind==="headingLevel"){const W=(r&&sj[r])??"h2",K=g&&/^h[1-6]$/.test(g)?g:"";return p.jsxs("div",{className:"property-field",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:D})}),p.jsxs("select",{className:"property-field-input property-field-select",value:K,onChange:Y=>i(Y.target.value),children:[p.jsxs("option",{value:"",children:["Auto (",W.toUpperCase(),")"]}),["h1","h2","h3","h4","h5","h6"].map(Y=>p.jsx("option",{value:Y,children:Hve[Y]},Y))]})]})}if(t.kind==="image")return p.jsxs("div",{className:"property-field",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:D})}),p.jsx("div",{className:"property-field-image-url",title:g,children:g||"(empty)"})]});if(t.kind==="enum"&&t.options){const W=t.options.includes(g);return p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:D})}),p.jsxs("select",{className:"property-field-input property-field-select",value:g,onChange:K=>i(K.target.value),children:[!W&&p.jsx("option",{value:g,children:g||"—"}),t.options.map(K=>p.jsx("option",{value:K,children:K},K))]})]})}if(t.kind==="boolean"){const W=g==="true"||g==="1";return p.jsx("div",{className:`${M} property-field--inline`,ref:A,children:p.jsxs("div",{className:"property-field-label",children:[p.jsxs("span",{children:[D,t.required&&p.jsx("span",{className:"property-field-required",children:"*"})]}),p.jsx("button",{type:"button",role:"switch","aria-checked":W,"aria-label":D,className:`property-field-switch${W?" is-on":""}`,onClick:()=>i(W?"false":"true"),children:p.jsx("span",{className:"property-field-switch-knob","aria-hidden":"true"})})]})})}if(t.kind==="color")return p.jsxs("div",{className:"property-field",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:D})}),p.jsx("input",{type:"color",className:"property-field-color",value:g||"#000000",onChange:W=>i(W.target.value)})]});if(t.kind==="html")return p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsxs("span",{children:[D,t.required&&p.jsx("span",{className:"property-field-required",children:"*"})]})}),p.jsx("div",{className:"property-field-input-wrap",children:p.jsx(Vve,{value:g,onCommit:W=>i(W),onFocus:P,onBlur:R,inline:t.inline})})]});if(t.kind==="richtext")return n!==null&&typeof n=="object"?p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsxs("span",{children:[D,t.required&&p.jsx("span",{className:"property-field-required",children:"*"})]})}),p.jsx("div",{className:"property-field-input-wrap",children:p.jsx(KL,{value:n,onChange:W=>w(W),onFocus:P,onBlur:R,decorators:t.decorators,inline:t.inline})})]}):p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsxs("span",{children:[D,t.required&&p.jsx("span",{className:"property-field-required",children:"*"})]})}),p.jsx("div",{className:`property-field-input-wrap${u?" property-field-input-wrap--ai-loading":""}`,children:p.jsx(Rve,{value:g,onChange:W=>{x(W),w(W)},onFocus:P,onBlur:R,trailing:s?p.jsx(lp,{variant:"toolbar",onClick:s,fieldKind:t.kind,fieldLabel:t.label??e,blockType:r??"",currentValue:g,onQuickAction:o,onCustomPrompt:s,aiLoading:u}):null})})]});const L=t.multiline===!0,F=t.kind==="number"?"number":t.kind==="url"?"url":"text",q={value:j,onFocus:P,onChange:W=>{x(W.target.value),w(W.target.value)},onBlur:R};return p.jsxs("div",{className:M,ref:A,children:[p.jsx("div",{className:"property-field-label",children:p.jsxs("span",{children:[D,t.required&&p.jsx("span",{className:"property-field-required",children:"*"})]})}),p.jsxs("div",{className:`property-field-input-wrap${u?" property-field-input-wrap--ai-loading":""}`,children:[L?p.jsx("textarea",{className:"property-field-textarea",rows:3,...q}):p.jsx("input",{type:F,className:"property-field-input",...q}),s?p.jsx(lp,{onClick:s,fieldKind:t.kind,fieldLabel:t.label??e,blockType:r??"",currentValue:g,onQuickAction:o,onCustomPrompt:s,aiLoading:u}):null]})]})}function Kve({slug:e,navLabel:t,onNavLabelChange:n,onAiAssist:r,onAiQuickAction:i,aiLoading:s,fieldShimmer:o}){const{t:a}=Mn(),[u,d]=E.useState(t),[f,m]=E.useState(!1),g=f?u:t,{debouncedCommit:y,flushCommit:x}=Yd(v=>n(e,v),400);return p.jsx(ay,{id:"page:nav",title:a("propertyPanel.navigation"),count:1,children:p.jsxs("div",{className:"property-field",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:a("propertyPanel.navLabel")})}),p.jsxs("div",{className:`property-field-input-wrap${o?" property-field-input-wrap--ai-loading":""}`,children:[p.jsx("input",{type:"text",className:"property-field-input",placeholder:a("propertyPanel.navPlaceholder"),value:g,onFocus:()=>{d(t),m(!0)},onChange:v=>{d(v.target.value),y(v.target.value)},onBlur:()=>{m(!1),x()}}),r?p.jsx(lp,{onClick:()=>r("Nav label","text",t),fieldKind:"text",fieldLabel:"Nav label",blockType:"Page",currentValue:t,onQuickAction:i?v=>i("Nav label","text",t,v):void 0,onCustomPrompt:()=>r("Nav label","text",t),aiLoading:o}):null]})]})})}function Gve({pageMeta:e,onPageMetaChange:t,onAiAssist:n,onAiQuickAction:r,aiLoading:i,aiLoadingPath:s}){const{t:o}=Mn();return p.jsxs(ay,{id:"page:seo",title:o("propertyPanel.seo"),count:3,children:[p.jsx(ok,{label:o("propertyPanel.seoTitle"),fieldKind:"text",blockType:"Page",value:e.title??"",placeholder:o("propertyPanel.seoTitlePlaceholder"),multiline:!0,autosizeRows:{min:2,max:2},recommendedMax:60,onCommit:a=>t("title",a),onAiAssist:n?()=>n("SEO title","text",e.title??""):void 0,onAiQuickAction:r?a=>r("SEO title","text",e.title??"",a):void 0,aiLoading:i,fieldShimmer:i===!0&&s==="SEO title"}),p.jsx(ok,{label:o("propertyPanel.metaDescription"),fieldKind:"richtext",blockType:"Page",value:e.description??"",placeholder:o("propertyPanel.metaDescPlaceholder"),multiline:!0,autosizeRows:{min:3,max:6},recommendedMax:160,onCommit:a=>t("description",a),onAiAssist:n?()=>n("Meta description","richtext",e.description??""):void 0,onAiQuickAction:r?a=>r("Meta description","richtext",e.description??"",a):void 0,aiLoading:i,fieldShimmer:i===!0&&s==="Meta description"}),p.jsx(ok,{label:o("propertyPanel.ogImage"),fieldKind:"url",blockType:"Page",value:e.ogImage??"",placeholder:"https://...",onCommit:a=>t("ogImage",a)})]})}function ok({label:e,fieldKind:t,blockType:n,value:r,placeholder:i,multiline:s,autosizeRows:o,recommendedMax:a,onCommit:u,onAiAssist:d,onAiQuickAction:f,aiLoading:m,fieldShimmer:g}){const[y,x]=E.useState(r),[v,S]=E.useState(!1),w=E.useRef(null),T=v?y:r,{debouncedCommit:A,flushCommit:M}=Yd(u,400),j=s===!0&&o!=null,D=E.useCallback(()=>{if(!j||!w.current||!o)return;const L=w.current,F=getComputedStyle(L),q=Number.parseFloat(F.lineHeight),W=Number.parseFloat(F.fontSize)||15,K=Number.isFinite(q)?q:W*1.2,Y=(Number.parseFloat(F.paddingTop)||0)+(Number.parseFloat(F.paddingBottom)||0),V=(Number.parseFloat(F.borderTopWidth)||0)+(Number.parseFloat(F.borderBottomWidth)||0),O=o.min*K+Y+V,U=o.max*K+Y+V;L.style.height="0px";const Q=L.scrollHeight,le=Math.max(O,Math.min(U,Q));L.style.height=`${le}px`,L.style.overflowY=Q>U?"auto":"hidden"},[j,o]);E.useLayoutEffect(()=>{D()},[D,T,v,r]),E.useEffect(()=>{if(!j)return;const L=()=>D();return window.addEventListener("resize",L),()=>window.removeEventListener("resize",L)},[j,D]);const P={placeholder:i,value:T,onFocus:()=>{x(r),S(!0)},onChange:L=>{x(L.target.value),A(L.target.value)},onBlur:()=>{S(!1),M()}},R=(v?y:r).length;return p.jsxs("div",{className:"property-field",children:[p.jsx("div",{className:"property-field-label",children:p.jsx("span",{children:e})}),p.jsxs("div",{className:`property-field-input-wrap${g?" property-field-input-wrap--ai-loading":""}`,children:[s?p.jsx("textarea",{ref:j?w:void 0,className:`property-field-textarea${j?" property-field-textarea--autosize":""}`,rows:(o==null?void 0:o.min)??3,...P}):p.jsx("input",{type:"text",className:"property-field-input",...P}),d?p.jsx(lp,{onClick:d,fieldKind:t,fieldLabel:e,blockType:n,currentValue:v?y:r,onQuickAction:f,onCustomPrompt:d,aiLoading:g}):null]}),a!=null&&p.jsxs("span",{className:`property-field-char-count${R>a?" property-field-char-count--over":""}`,children:[R," / ",a]})]})}class ak extends E.Component{constructor(){super(...arguments);Te(this,"state",{error:null});Te(this,"reset",()=>{var n,r;(r=(n=this.props).onReset)==null||r.call(n),this.setState({error:null})})}static getDerivedStateFromError(n){return{error:n}}componentDidCatch(n,r){var i,s;console.error("[editor] Uncaught error in component tree:",n,r.componentStack),(s=(i=this.props).onError)==null||s.call(i,n,r)}render(){return this.state.error?p.jsxs("div",{style:this.props.style,className:"flex flex-col items-center justify-center gap-3 p-6 text-center text-sm text-muted-foreground h-full",children:[p.jsx("p",{className:"font-medium text-foreground",children:this.props.fallbackLabel??"Something went wrong"}),p.jsx("p",{className:"max-w-xs opacity-70 text-xs",children:this.state.error.message}),p.jsx("button",{type:"button",onClick:this.reset,className:"rounded-md border px-3 py-1.5 text-xs hover:bg-accent transition-colors",children:"Try again"})]}):this.props.children}}function Wve({siteId:e,orchestratorUrl:t,hostedIds:n,siteOwnOrchestrator:r}){const{t:i}=Mn(),s=()=>{uce(e),window.location.href=cce(window.location.href)},o=()=>{r&&(lce(e,r),window.location.reload())};return r?p.jsxs("div",{className:"orchestrator-mismatch",role:"alert",children:[p.jsxs("div",{className:"orchestrator-mismatch-body",children:[p.jsx("strong",{children:i("orchestratorMismatch.ownTitle")}),p.jsx("span",{children:i("orchestratorMismatch.ownDetail",{orchestrator:t,siteOrchestrator:r})})]}),p.jsx("button",{type:"button",className:"orchestrator-mismatch-action",onClick:o,children:i("orchestratorMismatch.useSiteOwn")})]}):p.jsxs("div",{className:"orchestrator-mismatch",role:"alert",children:[p.jsxs("div",{className:"orchestrator-mismatch-body",children:[p.jsx("strong",{children:i("orchestratorMismatch.title")}),p.jsx("span",{children:n.length>0?i("orchestratorMismatch.detailHosts",{orchestrator:t,hosted:n.join(", ")}):i("orchestratorMismatch.detail",{orchestrator:t})})]}),p.jsx("button",{type:"button",className:"orchestrator-mismatch-action",onClick:s,children:i("orchestratorMismatch.useDefault")})]})}const Ag=3e3;function Zve(e){const[t,n]=E.useState({status:"loading",blocks:[],manifest:null});E.useEffect(()=>{let i=!0,s=null;const o=async()=>{try{const u=await fetch(`${e||Vd}/api/editor/blocks`);if(!u.ok){if(!i)return;n({status:"degraded",blocks:[],manifest:null,reason:`Manifest endpoint returned ${u.status}`}),s=setTimeout(()=>{i&&o()},Ag);return}const d=await u.json(),f=lj.safeParse(d);if(!f.success){if(!i)return;n({status:"degraded",blocks:[],manifest:null,reason:"Manifest response shape is invalid"}),s=setTimeout(()=>{i&&o()},Ag);return}const m=fj(f.data.blocks);if(m){if(!i)return;n({status:"degraded",blocks:[],manifest:null,reason:m}),s=setTimeout(()=>{i&&o()},Ag);return}if(!i)return;n({status:"ready",blocks:f.data.blocks,version:f.data.version,manifest:f.data})}catch(a){if(!i)return;n({status:"degraded",blocks:[],manifest:null,reason:a instanceof Error?a.message:"Manifest fetch failed"}),s=setTimeout(()=>{i&&o()},Ag)}};return o(),()=>{i=!1,s&&clearTimeout(s)}},[e]);const r=E.useMemo(()=>{const i=new Map;for(const s of t.blocks)i.set(s.type,s);return i},[t.blocks]);return{...t,byType:r,siteCapabilities:{allowStructuralEdits:t.status==="ready",manifestStatus:t.status,reason:t.reason,manifestVersion:t.version,blockCount:t.blocks.length,checkedAt:new Date().toISOString()},allowStructuralEdits:t.status==="ready"}}function Yve(e){const[t,n]=E.useState(void 0);return E.useEffect(()=>{if($k)return;let r=!1;return ace(e).then(i=>{r||!i||i.replace(/\/+$/,"")!==Be.replace(/\/+$/,"")&&n(i)}),()=>{r=!0}},[e]),t}function Jve(e){const t=e==null?void 0:e.trim().toLowerCase();return t?t==="text"?"text":t==="legacy"||t==="sparkle"||t==="dots"||t==="sparkle-dots"?"legacy":null:null}function Xve(){const e=Jve(Ni().VITE_STREAMING_INDICATOR_STYLE);return e||"text"}const Qve=/^[a-z]{2}(?:-[a-z0-9]{2,8})?$/i,Ol="default",eke=2;let th;function tke(e){if(!Qve.test(e))return!1;if(th===void 0)try{th=new Intl.DisplayNames(["en"],{type:"language",fallback:"none"})}catch{th=null}if(!th)return!1;try{return typeof th.of(e)=="string"}catch{return!1}}function ly(e){return e.split("/").filter(Boolean)}function tc(e){const t=ly(e);return t.length===0?"/":`/${t.join("/")}`}function nke(e){const t={},n=[];for(const u of e){const d=ly(u)[0];if(d&&tke(d)){const f=d.toLowerCase();(t[f]||(t[f]=[])).push(u)}else n.push(u)}const r=Object.keys(t).sort();if(r.length<2)return null;const i=new Map;for(const u of r)for(const d of new Set(t[u].map(f=>pC(f,u))))i.set(d,(i.get(d)??0)+1);if(![...i.values()].some(u=>u>=2))return null;const o=n.filter(u=>i.has(tc(u))).length>=eke,a=o?[]:n;o&&(t[Ol]=n,r.unshift(Ol));for(const u of r){const d=u===Ol?"/":`/${u}`;t[u].sort((f,m)=>f===d?-1:m===d?1:0)}return{locales:r,byLocale:t,shared:a}}function YL(e,t){var i;const n=(i=ly(e)[0])==null?void 0:i.toLowerCase();if(n&&t.byLocale[n])return n;const r=t.byLocale[Ol];return r!=null&&r.some(s=>tc(s)===tc(e))?Ol:void 0}function pC(e,t){var i;if(!t||t===Ol)return tc(e);const n=ly(e);if(((i=n[0])==null?void 0:i.toLowerCase())!==t.toLowerCase())return tc(e);const r=n.slice(1);return r.length===0?"/":`/${r.join("/")}`}function rke(e,t){return`${V4(pC(e,t))} (${e})`}function ike(e,t,n){const r=n.byLocale[t];if(!r||r.length===0)return e;const i=pC(e,YL(e,n)),s=t===Ol?i:i==="/"?`/${t}`:`/${t}${i}`;return r.find(a=>tc(a)===tc(s))??r[0]}function ske(e){try{const t=new Intl.DisplayNames([e],{type:"language"}).of(e);if(t&&t.toLowerCase()!==e.toLowerCase())return t.charAt(0).toUpperCase()+t.slice(1)}catch{}return e.toUpperCase()}const nR=Xve(),oke=!1,ake=dd||oke,lke=xG(),uke=E.lazy(()=>HB(()=>import("./PuckPrototypeRoute-CrrOmaf8.js").then(e=>e.P),__vite__mapDeps([0,1])).then(e=>({default:e.PuckPrototypeRoute}))),cke=new Set(["/editor/puck","/editor/puck/"]),dke=3e4,JL="site-reachable-v1:",fke=5e3;function XL(e){if(typeof sessionStorage>"u")return null;try{const t=sessionStorage.getItem(JL+e);if(!t)return null;const n=JSON.parse(t);return Date.now()-n.ts>dke?null:n.ok}catch{return null}}function rR(e,t){if(!(typeof sessionStorage>"u"))try{sessionStorage.setItem(JL+e,JSON.stringify({ok:t,ts:Date.now()}))}catch{}}function hke({name:e,origin:t,statusClass:n,active:r,dimmed:i,onSelect:s}){const o=t.replace(/^https?:\/\//,"");return p.jsxs("button",{type:"button",role:"menuitem",className:`site-switcher-item${r?" is-active":""}${i?" is-dimmed":""}`,onClick:s,title:t,children:[p.jsx("span",{className:`site-switcher-item-dot site-switcher-item-dot-${n}`,"aria-hidden":"true"}),p.jsxs("span",{className:"site-switcher-item-body",children:[p.jsx("span",{className:"site-switcher-item-name",children:e}),p.jsx("span",{className:"site-switcher-item-origin",children:o})]}),r?p.jsx(Fd,{size:12,"aria-hidden":"true"}):null]})}function iR(e){if(typeof sessionStorage>"u")return null;const t=new Set;let n=!1;for(const r of e){const i=XL(r);i!==null&&(n=!0,i&&t.add(r))}return n?t:null}function pke(e,t){if(e===t)return!0;if(!e||!t||e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function mke(){const e=typeof window<"u"?window.location.pathname:"/",t=e==="/"||e==="/editor"||e==="/editor/",n=cke.has(e),r=e==="/sites"||e==="/sites/";fe(d=>d.chatDarkMode);const i=fe(d=>d.setChatDarkMode),s=E.useMemo(()=>Iw(),[]),o=E.useMemo(()=>Q4(),[]),a=E.useRef(!1);a.current||(a.current=!0,zG({sessionId:s,siteId:o}));const u=fce(o,s);return E.useEffect(()=>{if(typeof window>"u")return;const d=window.matchMedia("(prefers-color-scheme: dark)"),f=m=>{pw()===null&&i(m.matches,{persist:!1})};return d.addEventListener("change",f),()=>d.removeEventListener("change",f)},[i]),n?p.jsx(E.Suspense,{fallback:p.jsx("div",{style:{height:"100vh",display:"grid",placeItems:"center"},children:"Loading prototype…"}),children:p.jsx(uke,{})}):r?p.jsx(RN,{sites:u,session:s}):t?p.jsx(bke,{sites:u}):p.jsx(RN,{sites:u,session:s})}function gke(e){return e.split(".").map(t=>{const n=t.match(/^([a-zA-Z_]+)\[(\d+)\]$/);return n?`${sR(n[1])} ${Number(n[2])+1}`:sR(t)}).join(" · ")}function sR(e){const n=e.replace(/([a-z])([A-Z])/g,"$1 $2").replace(/[_-]+/g," ").replace(/\s*url\s*$/i,"").trim();return n?n.charAt(0).toUpperCase()+n.slice(1):e}function bke({sites:e}){var sf,of,fc;const{t}=Mn(),n=Bi(),r=Fi(),i=fe(_=>_.chatDarkMode),s=fe(_=>_.chatThemePreference),o=fe(_=>_.setChatThemePreference),{activeSiteConfig:a}=e,u=E.useMemo(()=>Pu(a),[a]),d=Zve(u),f=typeof window<"u"?window.location.origin:"http://localhost:4100",m=Yve(u),g=e.siteHosting==="notHosted"||m!=null,y=fe(_=>_.slug),x=fe(_=>_.setSlug),v=fe(_=>_.availableSlugs);fe(_=>_.setAvailableSlugs);const S=fe(_=>_.isLoadingSlugs),w=fe(_=>_.modelKey),T=fe(_=>_.setModelKey),A=fe(_=>_.provider),M=fe(_=>_.setProvider),j=fe(_=>_.availableProviders),D=fe(_=>_.setAvailableProviders),[P,R]=E.useState(""),L=fe(_=>_.activeBlockId),F=fe(_=>_.activeBlockType),q=fe(_=>_.activeEditablePath),W=_=>fe.getState().setActiveBlock(_),K=_=>{const G=fe.getState();G.setActiveBlock(G.activeBlockId,_)},Y=(_,G)=>fe.getState().setActiveBlock(_,G),V=fe(_=>_.setActiveEditablePath),O=fe(_=>_.useStreaming),U=fe(_=>_.setUseStreaming),Q=fe(_=>_.autoScrollTrackingEnabled),le=fe(_=>_.setAutoScrollTrackingEnabled),I=fe(_=>_.autoOpenPropertiesEnabled),$=fe(_=>_.setAutoOpenPropertiesEnabled),[X,z]=E.useState(!1),[Z,se]=E.useState(lke),ee=E.useCallback(_=>{se(_);try{window.localStorage.setItem(wk,_?"1":"0")}catch{}},[]),ne=E.useMemo(()=>!dd||new URLSearchParams(window.location.search).has("dev"),[]),Ae=ne&&Z,[_e,ze]=E.useState(!1),[ce,ve]=E.useState(0),Oe=E.useCallback(()=>ve(_=>_+1),[]),oe=fe(_=>_.showSettingsModal),He=fe(_=>_.setShowSettingsModal),$e=fe(_=>_.showDebugDetails),bt=fe(_=>_.setShowDebugDetails),Gt=fe(_=>_.composerHeight),Ct=fe(_=>_.setComposerHeight),ct=fe(_=>_.addBlockPicker),Xt=fe(_=>_.setAddBlockPicker),kt=fe(_=>_.addBlockSearch),St=fe(_=>_.setAddBlockSearch),nt=fe(_=>_.isAddingBlock),gn=fe(_=>_.setIsAddingBlock),he=fe(_=>_.copiedDebugEntryId),me=fe(_=>_.setCopiedDebugEntryId),Fe=fe(_=>_.feedbackNoteEntryId),et=fe(_=>_.setFeedbackNoteEntryId),ft=fe(_=>_.feedbackNoteText),Ot=fe(_=>_.setFeedbackNoteText),cr=fe(_=>_.selectedVariationId),fn=fe(_=>_.setSelectedVariationId),Nt=fe(_=>_.imagePickerTarget),zn=fe(_=>_.setImagePickerTarget),tn=Nt!==null,Tr=fe(_=>_.backendFeatures),Ar=fe(_=>_.setBackendFeatures),ke=fe(_=>_.setBackendSite),Ue=fe(_=>_.selectionModeEnabled),ge=fe(_=>_.setSelectionModeEnabled),je=fe(_=>_.anchorRect),Le=fe(_=>_.setAnchorRect),Pe=fe(_=>_.anchoredExpanded),tt=fe(_=>_.setAnchoredExpanded),Ke=fe(_=>_.activeTab),ht=fe(_=>_.setActiveTab),[Bt,Wt]=E.useState(!1),[wn,Ln]=E.useState(!1),nr=E.useRef(null);E.useEffect(()=>{if(!wn)return;const _=ie=>{nr.current&&!nr.current.contains(ie.target)&&Ln(!1)},G=ie=>{ie.key==="Escape"&&Ln(!1)};return document.addEventListener("mousedown",_),document.addEventListener("keydown",G),()=>{document.removeEventListener("mousedown",_),document.removeEventListener("keydown",G)}},[wn]);const[Gi,Gs]=E.useState(()=>iR(e.siteList.map(_=>_.id))),qr=E.useCallback(_=>{Gs(G=>pke(G,_)?G:_)},[]);E.useEffect(()=>{if(!wn)return;qr(iR(e.siteList.map(ie=>ie.id)));let _=!0;return(async()=>{let ie=!0;const Ce=await Promise.all(e.siteList.map(async De=>{const Ve=XL(De.id);if(Ve!==null)return{id:De.id,ok:Ve};ie=!1;const Qe=Pu(De);try{const pn=await fetch(`${Qe}/api/editor/blocks?siteId=${encodeURIComponent(De.id)}`,{signal:AbortSignal.timeout(2500)});return rR(De.id,pn.ok),{id:De.id,ok:pn.ok}}catch{return rR(De.id,!1),{id:De.id,ok:!1}}}));_&&!ie&&qr(new Set(Ce.filter(De=>De.ok).map(De=>De.id)))})(),()=>{_=!1}},[wn,e.siteList,qr]);const Kr=E.useMemo(()=>{const _=Gi===null;return e.siteList.map(G=>{const ie=_||G.id===r||Gi.has(G.id);return{site:G,origin:Pu(G),online:ie,probing:_}}).sort((G,ie)=>G.site.id===r?-1:ie.site.id===r?1:G.online!==ie.online?G.online?-1:1:G.site.name.localeCompare(ie.site.name))},[Gi,e.siteList,r]),{onlineEntries:Ws,activeEntry:Nr}=E.useMemo(()=>({onlineEntries:Kr.filter(_=>_.online),activeEntry:Kr.find(_=>_.site.id===r)}),[Kr,r]),jt=E.useRef(null),Bn=E.useRef(null),jr=E.useRef(!0),ks=E.useRef(!1),Ss=E.useRef(null),bi=E.useRef(void 0),mr=E.useRef(!1),Wi=E.useRef(null),Zi=E.useRef(!1),si=E.useRef(0),oi=E.useRef(null),Fn=E.useRef(null),an=fe(_=>_.chatWidth),Mt=fe(_=>_.setChatWidth),ws=fe(_=>_.propsWidth),Gr=fe(_=>_.setPropsWidth),gr=E.useRef(null),Wr=E.useRef(null),[Yi,Go]=E.useState(1),Cs=E.useRef(null),go=E.useRef(null),Ji=E.useRef(!1),Es=E.useRef(!1);E.useEffect(()=>{if(!Es.current&&!(S||v.length===0)){if(y!=="/"||v.includes("/")){Es.current=!0;return}Es.current=!0,mr.current=!1,x(v[0])}},[v,S,y,x]);const Ir=E.useMemo(()=>{const _=Array.from(new Set([...v,y].filter(Boolean)));return _.includes("/")?["/",..._.filter(G=>G!=="/")]:_},[v,y]),hn=E.useMemo(()=>nke(Ir),[Ir]),Or=hn?YL(y,hn)??hn.locales[0]:void 0,Wo=E.useMemo(()=>!hn||!Or?Ir:hn.byLocale[Or]??[],[hn,Or,Ir]),Xi=E.useMemo(()=>{if(!d.allowStructuralEdits)return[];if(d.blocks.length>0)return d.blocks.map(G=>({type:G.type,label:G.displayName??G.type,category:"content"})).sort((G,ie)=>G.label.localeCompare(ie.label));const _=Au();return[...bk].map(G=>{var ie,Ce;return{type:G,label:((ie=_[G])==null?void 0:ie.displayName)??G,category:((Ce=_[G])==null?void 0:Ce.category)??"content"}}).sort((G,ie)=>G.label.localeCompare(ie.label))},[d.allowStructuralEdits,d.blocks]),ja=E.useMemo(()=>{const _=kt.trim().toLowerCase(),G=_?Xi.filter(De=>De.label.toLowerCase().includes(_)||De.type.toLowerCase().includes(_)):Xi,ie=new Map;for(const De of G){const Ve=De.category||"content",Qe=ie.get(Ve);Qe?Qe.push(De):ie.set(Ve,[De])}const Ce=["content","layout","conversion","navigation","media"];return[...ie.entries()].sort((De,Ve)=>{const Qe=Ce.indexOf(De[0]),pn=Ce.indexOf(Ve[0]),rr=Qe===-1?Number.MAX_SAFE_INTEGER:Qe,En=pn===-1?Number.MAX_SAFE_INTEGER:pn;return rr!==En?rr-En:De[0].localeCompare(Ve[0])}).map(([De,Ve])=>({category:De,options:Ve}))},[kt,Xi]),Mi=()=>{const _=Date.now();_-si.current<1200||(si.current=_,Ge.pushAssistantFromResult({status:"needs_clarification",summary:t("streamError.structuralDisabled"),changes:SP(d.reason)}))},eu=E.useRef(()=>{}),Cn=E.useCallback(_=>{fe.getState().slug!==_&&(Zi.current=!0,x(_))},[x]),Zs=E.useMemo(()=>({onBlockClicked:(_,G,ie,Ce,De,Ve)=>{Cn(_),Y(G,ie),V(Ce),Le(G?Ve:null);const Qe=fe.getState();G?Qe.autoOpenPropertiesEnabled&&Qe.setActiveTab("properties"):Qe.setActiveTab("chat")},onRouteChanged:_=>{fe.getState().slug!==_&&Y(void 0,void 0),Cn(_),V(void 0),Le(null),yi.current("setSelectionMode",{enabled:fe.getState().selectionModeEnabled}),eu.current(_)},onBlockReordered:(_,G,ie)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),V(void 0),Ge.reorderBlock(_,G,ie)},onBlockDeleteRequested:(_,G)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),V(void 0),Ge.deleteBlock(_,G)},onBlockAddRequested:(_,G)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),!(!G.afterBlockId&&!G.beforeBlockId)&&Xt({slug:_,afterBlockId:G.afterBlockId,beforeBlockId:G.beforeBlockId})},onListItemAddRequested:(_,G,ie,Ce,De)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),V(void 0),Ge.addListItem(_,G,ie,Ce,De)},onListItemRemoveRequested:(_,G,ie,Ce,De)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),V(void 0),Ge.removeListItem(_,G,ie,Ce,De)},onListItemMoveRequested:(_,G,ie,Ce,De,Ve)=>{if(!d.allowStructuralEdits){Mi();return}_!==y&&Cn(_),V(void 0),Ge.moveListItem(_,G,ie,Ce,De,Ve)},onOpenImagePicker:(_,G,ie,Ce,De)=>{zn({slug:_,blockId:G,editablePath:ie,currentUrl:Ce,blockType:De??(G===L?F:void 0)})},onEditBlockRequested:(_,G)=>{tt(!0)},onInlineTextCommitted:(_,G,ie,Ce)=>{_!==y&&Cn(_),ie&&V(ie),Ge.inlineEditCommit(_,G,ie,Ce)},onIframeScrolled:()=>{Le(null),fe.getState().isLoading&&fe.getState().setAutoScrollSuppressed(!0)}}),[d.allowStructuralEdits,Cn,y]),Ia=E.useCallback(async()=>{var _;try{const G=`${Be}/draft/pages?session=${encodeURIComponent(n)}&siteId=${encodeURIComponent(r)}&slug=${encodeURIComponent(y)}`,ie=await fetch(G,{cache:"no-store"});if(!ie.ok)return;const De=((await ie.json()).blocks??[]).find(Ve=>Ve.type==="Hero");if(!De)return;Y(De.id,De.type),zn({slug:y,blockId:De.id,editablePath:"imageUrl",currentUrl:typeof((_=De.props)==null?void 0:_.imageUrl)=="string"?De.props.imageUrl:void 0,blockType:De.type})}catch{}},[n,r,y,zn]),Qt=hce(y,Zs,u),yi=E.useRef(Qt.postToSite);E.useEffect(()=>{yi.current=Qt.postToSite},[Qt.postToSite]);const Ys=E.useCallback(_=>{const G=_??!Ue;ge(G),Qt.postToSite("setSelectionMode",{enabled:G})},[Ue,Qt]);E.useEffect(()=>{const _=G=>{G.key==="Escape"&&Ue&&Ys(!1)};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[Ue,Ys]),E.useEffect(()=>{if(Ke!=="history")return;const _=G=>{G.key==="Escape"&&fe.getState().setActiveTab("chat")};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[Ke]);const Zo=E.useCallback((_,G)=>{(_==="draftUpdated"||_==="liveDraft")&&Oe(),Qt.postToSite(_,G)},[Qt,Oe]),xi=E.useCallback((_,G,ie,Ce)=>(Oe(),Qt.postPatchToSite(_,G,ie,Ce)),[Qt,Oe]),Ge=xce({activeSiteConfig:a,siteRegistryChecked:e.siteRegistryChecked,postToSite:Zo,postPatchToSite:xi,componentManifest:d.manifest,siteCapabilities:d.siteCapabilities,allowStructuralEdits:d.allowStructuralEdits,getBlockDefaultProps:_=>{var G;return((G=d.byType.get(_))==null?void 0:G.defaultProps)??null},onApplied:()=>{var _;(_=bi.current)==null||_.call(bi)},agentModeEnabled:Tr.agentMode??!1}),ai=fe(_=>_.chatLog),Oa=fe(_=>_.chatAttachments),bo=fe(_=>_.setChatAttachments),Kn=fe(_=>_.isLoading),br=fe(_=>_.streamStatus),Js=fe(_=>_.streamingText),Qi=fe(_=>_.streamingChanges),tu=fe(_=>_.streamSteps),Xs=fe(_=>_.streamTokenCount),es=fe(_=>_.latestStreamFocusBlockId),Pr=fe(_=>_.imageProgress),Di=fe(_=>_.plannerBadgeState),[yo,_s]=E.useState(!1),Qs=fe(_=>_.setPlannerBadgeState),dt=fe(_=>_.pendingPlanId),mt=fe(_=>_.variationModal),we=fe(_=>_.isApplyingVariation),Pt=fe(_=>_.setVariationModal),Ri=fe(_=>_.continuationChainId),vi=fe(_=>_.fieldDraftDebugEnabled),li=fe(_=>_.setFieldDraftDebugEnabled),zr=fe(_=>_.fieldDraftDebug);E.useEffect(()=>{X4.has(r)||(T("balanced"),Ge.clearChat())},[r]);function it(_){var G,ie;typeof _.navigateToSlug=="string"&&_.navigateToSlug.length>0&&_.navigateToSlug!==y&&x(_.navigateToSlug),typeof _.canUndo=="boolean"&&((G=Ge.setCanUndoServer)==null||G.call(Ge,_.canUndo)),typeof _.canRedo=="boolean"&&((ie=Ge.setCanRedoServer)==null||ie.call(Ge,_.canRedo)),Qt.postToSite("draftUpdated",{focusBlockId:null}),Oe()}async function xt(_){Wt(!0);try{const ie=await(await fetch(`${Be}/history/restore`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session:n,siteId:r,targetVersion:_})})).json();ie.status==="applied"&&it(ie)}catch{}finally{Wt(!1)}}const _t=Sce(n,r,u,ce),Vt=kce(n,r,Kn,Ge.pushAssistantFromResult,u,()=>{Qt.postToSite("draftUpdated",{focusBlockId:null}),_t.markPublished()}),dr=_t.summary?_t.summary.total>0:!0,zt=wce(),bn=Ke==="properties"&&Ge.hasBootstrapped,ln=_ce(n,r,y,L,bn),nn=Tce(n,r,y,bn);E.useEffect(()=>{!L||F||!ln.blockType||K(ln.blockType)},[L,F,ln.blockType]);const Mr=$ee(n,r,!!n),nu=Uee(Mr.findings),Zr=E.useRef(null),eo=E.useCallback((_,G,ie)=>{Y(_,G),V(ie),Le(null),fe.getState().selectionModeEnabled||(fe.getState().setSelectionModeEnabled(!0),yi.current("setSelectionMode",{enabled:!0})),yi.current("highlightBlock",{blockId:_,editablePath:ie??null,scrollIntoView:!0})},[]),xo=E.useCallback(_=>{const G=Zr.current;!G||G.slug!==_||(Zr.current=null,!(G.expiresAt!==void 0&&Date.now()>G.expiresAt)&&eo(G.blockId,G.blockType,G.path))},[eo]);E.useEffect(()=>{if(!Zr.current)return;const _=setTimeout(()=>xo(y),400);return()=>clearTimeout(_)},[y,xo]),E.useEffect(()=>{eu.current=xo},[xo]);const uy=E.useCallback((_,G,ie,Ce)=>{if(!G){_!==fe.getState().slug&&x(_),Y(void 0,void 0),V(void 0),ht("properties");return}if(_!==fe.getState().slug){Zr.current={slug:_,blockId:G,blockType:ie,path:Ce},x(_),ht("properties");return}ht("properties"),Zr.current={slug:_,blockId:G,...ie?{blockType:ie}:{},...Ce?{path:Ce}:{},expiresAt:Date.now()+fke},eo(G,ie,Ce)},[eo]);bi.current=()=>{ln.refetch(),nn.refetch(),Oe()};const[cc,cy]=E.useState(()=>Uk(y,{session:n,siteId:r,editorOrigin:f},u)),[dy,Tp]=E.useState(!1);E.useEffect(()=>{Tp(!1)},[cc]),E.useEffect(()=>{Wi.current!==u&&(Wi.current=u,mr.current=!1);const _={session:n,siteId:r,editorOrigin:f};if(Zi.current){Zi.current=!1;return}if(e0&&mr.current){Qt.postToSite("navigate",{href:Hk(y,_)});return}const G=Uk(y,_,u);cy(ie=>ie===G?ie:G)},[u,f,n,r,y]);const Ap=E.useMemo(()=>{var ie;const _=(ie=a.vercelProductionUrl)==null?void 0:ie.trim(),G=_&&/^https?:\/\//i.test(_)?_:u;try{const Ce=new URL(G);return Ce.origin===u?xee(y,{},u):(Ce.pathname=y==="/"?"/":y,Ce.search="",Ce.hash="",Ce.toString())}catch{return}},[a.vercelProductionUrl,u,y]),Np=E.useMemo(()=>u?`${u}${Hk(y,{session:n,siteId:r,editorOrigin:f,immersive:"1"})}`:void 0,[u,f,n,r,y]);E.useEffect(()=>{let _=!0;const G=async()=>{const Ce=[`${Be}/status/planner`];Be.includes("localhost")&&Ce.push(`${Be.replace("localhost","127.0.0.1")}/status/planner`);try{for(const De of Ce){const Ve=await fetch(De);if(!Ve.ok)continue;const Qe=await Ve.json();if(!_)return;if(Qe.features&&Ar(Qe.features),Qe.site&&ke(Qe.site),Array.isArray(Qe.availableProviders)&&Qe.availableProviders.length>0&&(D(Qe.availableProviders),(!Qe.availableProviders.includes(A)||A!=="anthropic"&&Qe.availableProviders.includes("anthropic"))&&M(Qe.availableProviders.includes("anthropic")?"anthropic":Qe.availableProviders[0])),typeof Qe.keyFilePath=="string"&&Qe.keyFilePath.length>0&&fe.getState().setKeyFilePath(Qe.keyFilePath),Qe.plannerSource==="openai"||Qe.plannerSource==="anthropic"||Qe.plannerSource==="gemini"||Qe.plannerSource==="demo"){Qs(Qe.plannerSource);return}}_&&Qs("error")}catch{_&&Qs("error")}};G();const ie=window.setInterval(()=>{G()},1e4);return()=>{_=!1,window.clearInterval(ie)}},[]);const Qd=E.useRef(0),Mp=E.useRef(0);E.useEffect(()=>{const _=Bn.current;if(!_)return;const G=()=>{const ie=Math.abs(_.scrollHeight-_.scrollTop-_.clientHeight)<2||_.scrollHeight<=_.clientHeight;!ie&&_.scrollTop<Qd.current?jr.current=!1:ie&&(jr.current=!0),Qd.current=_.scrollTop};return _.addEventListener("scroll",G,{passive:!0}),()=>{_.removeEventListener("scroll",G)}},[]),E.useEffect(()=>{const _=Bn.current;if(!_||!(ai.length>0||!!br||!!Js))return;const ie=ai.reduce((pn,rr)=>rr.role==="user"?pn+1:pn,0);ie>Mp.current&&(jr.current=!0),Mp.current=ie;const Ce=!ks.current,De=ai.some(pn=>pn.role==="user");if(Ce&&!De&&!br&&!Js){ks.current=!0,jr.current=!1;return}if(!Ce&&!jr.current)return;const Qe=window.requestAnimationFrame(()=>{_.scrollTop=_.scrollHeight,jr.current=!0,ks.current=!0});return()=>window.cancelAnimationFrame(Qe)},[ai.length,br,Js,tu.length,Qi.length]),E.useEffect(()=>{Qt.postToSite("setNestedLabelsVisibility",{visible:X})},[X]),E.useEffect(()=>{const _=yi.current;if(!Kn){Ji.current&&_("aiFieldLoading",{blockId:"",active:!1}),go.current=null,Ji.current=!1;return}const G=es??L??"",Ce=G&&G===(L??"")?q??"":"";_("aiFieldLoading",{blockId:G,editablePath:Ce,active:!0}),go.current={blockId:G,editablePath:Ce},Ji.current=!0},[Kn,es,L,q]),E.useEffect(()=>{if(!Kn)return;const _=window.setInterval(()=>{const G=go.current;G&&yi.current("aiFieldLoading",{blockId:G.blockId,editablePath:G.editablePath,active:!0})},1200);return()=>window.clearInterval(_)},[Kn]),E.useEffect(()=>{L&&Qt.postToSite("highlightBlock",{blockId:L,editablePath:q??null})},[L,q]),E.useEffect(()=>{Ge.clearFieldAiContext()},[L]),E.useEffect(()=>{L||Le(null)},[L]),E.useEffect(()=>{tt(!1)},[je]),E.useEffect(()=>{const _=()=>Le(null);return window.addEventListener("resize",_),()=>window.removeEventListener("resize",_)},[]);const fy=RG(),Pa=E.useMemo(()=>{if(!fy||!je||!Ue||!L||typeof window>"u"||window.innerWidth<=1040)return null;const _=Qt.iframeRef.current;if(!_)return null;const G=_.getBoundingClientRect(),ie=380,Ce=36,De=26,Ve=8,Qe=G.top+je.top*Yi;if(Qe+je.height*Yi<G.top||Qe>G.bottom)return null;const rr=Qe+Ve-(Ce-De)/2;let En=G.left+(je.left+je.width)*Yi-Ce-Ve;return En=Math.max(G.left+Ve,Math.min(En,G.right-Ce-Ve)),{top:rr,left:En,width:ie}},[je,Ue,L,Qt.iframeRef,Yi]);E.useEffect(()=>{Pa&&Pe&&requestAnimationFrame(()=>{var _,G;(G=(_=Cs.current)==null?void 0:_.querySelector("textarea"))==null||G.focus()})},[!!Pa,Pe]);const hy=E.useCallback((_,G,ie,Ce)=>{var rr;if(!L||!F)return;const Ve=((rr=Au()[F])==null?void 0:rr.displayName)??F;V(_);const Qe=dS(ie,G,F,Ce),pn={id:`field-ai-${Date.now()}`,role:"assistant",text:`Editing: ${Ve} → ${G}`,fieldAiContext:{blockId:L,blockType:F,fieldPath:_,fieldLabel:G,blockDisplayName:Ve},suggestions:Qe};Ge.setFieldAiContext(pn)},[L,F]),ef=E.useCallback((_,G,ie)=>{const Ce=dS(G,_,"Page",ie),De={id:`field-ai-${Date.now()}`,role:"assistant",text:`Editing: Page → ${_}`,fieldAiContext:{blockId:"__page__",blockType:"__page__",fieldPath:_,fieldLabel:_,blockDisplayName:"Page"},suggestions:Ce};Ge.setFieldAiContext(De)},[]),py=E.useCallback((_,G,ie,Ce,De)=>{var rr;if(!L||!F)return;const Qe=((rr=Au()[F])==null?void 0:rr.displayName)??F;V(_),Qt.postToSite("aiFieldLoading",{blockId:L,editablePath:_,active:!0}),go.current={blockId:L,editablePath:_},Ji.current=!0;const pn={id:`field-ai-${Date.now()}`,role:"assistant",text:`Editing: ${Qe} → ${G}`,fieldAiContext:{blockId:L,blockType:F,fieldPath:_,fieldLabel:G,blockDisplayName:Qe}};Ge.setFieldAiContext(pn),Ge.submitChat(De)},[L,F]),my=E.useCallback((_,G,ie,Ce)=>{V(_);const De={id:`field-ai-${Date.now()}`,role:"assistant",text:`Editing: Page → ${_}`,fieldAiContext:{blockId:"__page__",blockType:"__page__",fieldPath:_,fieldLabel:_,blockDisplayName:"Page"}};Ge.setFieldAiContext(De),Ge.submitChat(Ce)},[]);E.useEffect(()=>{Ge.refreshRouteSlugs()},[n,r,e.siteRegistryChecked]);const tf=_=>{const ie=jt.current,Ce=Bn.current;if(!ie||!Ce)return Math.max(56,_);const De=120,Ve=10,Qe=Ce.offsetTop,pn=Math.max(56,ie.clientHeight-Qe-Ve-De);return Math.min(pn,Math.max(56,_))},Dp=E.useCallback(_=>{Ct(G=>{const ie=tf(_);return ie===G?G:ie})},[]);E.useEffect(()=>{const _=ie=>{const Ce=oi.current;if(Ce){const Ve=ie.clientY-Ce.y,Qe=tf(Ce.composerHeight-Ve);Ct(Qe)}const De=Fn.current;if(De){const Ve=ie.clientX-De.x;De.target==="chat"?Mt(_k(De.width+Ve)):Gr(Tk(De.width-Ve))}},G=()=>{const ie=!!Fn.current;oi.current=null,Fn.current=null,document.body.style.userSelect="",ie&&document.body.classList.remove("panel-resizing")};return window.addEventListener("pointermove",_),window.addEventListener("pointerup",G),()=>{window.removeEventListener("pointermove",_),window.removeEventListener("pointerup",G),document.body.style.userSelect="",document.body.classList.remove("panel-resizing")}},[]),E.useEffect(()=>{const _=()=>{Ct(G=>tf(G)),Mt(G=>G&&_k(G)),Gr(G=>G&&Tk(G))};return window.addEventListener("resize",_),()=>window.removeEventListener("resize",_)},[Mt,Gr]),E.useEffect(()=>{if(!mt)return;const _=G=>{G.key==="Escape"&&!we&&Pt(null)};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[mt,we]),E.useEffect(()=>{mt!=null&&mt.options.length?fn(mt.options[0].id):fn(null)},[mt]),E.useEffect(()=>{ct||St("")},[ct]),E.useEffect(()=>{if(!ct)return;const _=G=>{G.key==="Escape"&&!nt&&Xt(null)};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[ct,nt]);const nf=br?/failed|error/i.test(br):!1,[Rp,jp]=E.useState(0),gy=Pr==null?void 0:Pr.stage;E.useEffect(()=>{if(jp(0),!Kn)return;const _=window.setInterval(()=>jp(G=>G+1),1e3);return()=>window.clearInterval(_)},[Kn,br,gy]);const Ip=Kn&&!nf&&Rp>=5?` · ${Rp}s`:"",by=(Pr?Pr.stage:br??(Xs>0?t("stream.shapingUpdate"):t("stream.gettingReady")))+Ip,Op=(Pr?Pr.stage:br??(Xs>0?t("stream.updating"):t("stream.thinking")))+Ip,to=(br==null?void 0:br.match(/reconnecting(?:\s+agent\s+stream)?(?:\s+\((\d+)\/(\d+)\))?/i))??null,Pp=to!=null&&to[1]?Number(to[1]):null,dc=to!=null&&to[2]?Number(to[2]):null,vo=to?Pp&&dc?`Reconnect ${Pp}/${dc}`:"Reconnecting":null,zp=`field_draft ${zr.eventsPerSecond}/s · chars ${zr.charsPerSecond}/s · lag ${zr.typingLagChars}`,Lp={"--composer-height":`${Gt}px`},ko=Ke==="properties",za=Ke==="history",ru=Ke==="health",rf=E.useCallback(()=>{W(void 0),K(void 0),ht("chat")},[]);E.useLayoutEffect(()=>{const _=Wr.current,G=Qt.iframeRef.current;if(!_||!G)return;const ie=Ve=>{var ts;if(Ve?G.classList.remove("preview-iframe-no-transition"):G.classList.add("preview-iframe-no-transition"),!ko){G.style.removeProperty("width"),G.style.removeProperty("height"),G.style.removeProperty("transform"),Go(Ts=>Ts===1?Ts:1);return}const Qe=_.offsetWidth,pn=((ts=gr.current)==null?void 0:ts.offsetWidth)??0;if(Qe<=0||pn<=0)return;const rr=Qe+pn,En=Qe/rr;G.style.width=`${rr}px`,G.style.height=`${100/En}%`,G.style.transform=`scale(${En})`,Go(Ts=>Math.abs(Ts-En)<5e-4?Ts:En)};ie(!0);const Ce=new ResizeObserver(()=>ie(!1)),De=window.setTimeout(()=>{Ce.observe(_);const Ve=gr.current;Ve&&Ce.observe(Ve)},240);return()=>{window.clearTimeout(De),G.classList.remove("preview-iframe-no-transition"),Ce.disconnect()}},[ko,Qt.iframeRef]);const La={...an?{"--chat-width":`${an}px`}:{},...ws?{"--props-width":`${ws}px`}:{}},Bp=ai.some(_=>_.role==="user"),Fp=E.useCallback(_=>{const G=[];_.text&&G.push(_.text),_.status&&!_.canUndo&&_.status!=="needs_clarification"&&_.status!=="plan_ready"&&G.push(`status: ${_.status}`);const ie=(_.changes??[]).filter(Ce=>!q4(_.text,Ce));if(ie.length>0&&G.push(`changes: ${ie.join(`
769
769
  `)}`),(_.errors??[]).length>0&&G.push(`errors: ${(_.errors??[]).join(`
770
770
  `)}`),_.debug){if(G.push(""),G.push("Debug"),_.debug.traceId&&G.push(`traceId: ${_.debug.traceId}`),_.debug.promptHash&&G.push(`promptHash: ${_.debug.promptHash}`),_.debug.outcome&&G.push(`outcome: ${_.debug.outcome}`),_.debug.reasonCategory&&G.push(`reason: ${_.debug.reasonCategory}`),_.debug.reason&&_.debug.reason!==_.debug.reasonCategory&&G.push(`reasonDetail: ${_.debug.reason}`),_.debug.intent&&G.push(`intent: ${_.debug.intent}`),_.debug.plannerTier&&G.push(`plannerTier: ${_.debug.plannerTier}`),_.debug.modelUsed&&G.push(`model: ${_.debug.modelUsed}${_.debug.plannerSource?` (${_.debug.plannerSource})`:""}`),typeof _.debug.planningAttempts=="number"&&_.debug.planningAttempts>1&&G.push(`planningAttempts: ${_.debug.planningAttempts}`),typeof _.debug.opCount=="number"&&G.push(`opCount: ${_.debug.opCount}`),Array.isArray(_.debug.skippedOps)&&_.debug.skippedOps.length>0){const De=_.debug.skippedOps.map(Ve=>`[${Ve.index}] ${Ve.op} ${Ve.pageSlug??""}${Ve.blockId?"#"+Ve.blockId:""}: ${Ve.reason}`).join(", ");G.push(`skippedOps: ${De}`)}else typeof _.debug.skippedOpCount=="number"&&_.debug.skippedOpCount>0&&G.push(`skippedOps: ${_.debug.skippedOpCount}`);if(Array.isArray(_.debug.opTypes)&&_.debug.opTypes.length>0&&G.push(`ops: ${_.debug.opTypes.join(", ")}`),typeof _.debug.totalTokens=="number"&&G.push(`tokens: in:${_.debug.inputTokens??"?"} out:${_.debug.outputTokens??"?"} total:${_.debug.totalTokens}`),typeof _.debug.estimatedUsd=="number"&&G.push(`cost: $${_.debug.estimatedUsd.toFixed(4)}`),Array.isArray(_.debug.timeline)&&_.debug.timeline.length>0){const De=_.debug.timeline.map(Ve=>`${Ve.stage}:${Ve.atMs}ms`).join(" -> ");G.push(`timeline: ${De}`)}_.debug.promptExcerpt&&G.push(`prompt: ${_.debug.promptExcerpt}`);const Ce=[];_.debug.currentPage&&Ce.push(`page: ${_.debug.currentPage}`),_.debug.siteId&&Ce.push(`site: ${_.debug.siteId}`),_.debug.activeBlockId&&Ce.push(`block: ${_.debug.activeBlockId}`),_.debug.activeEditablePath&&Ce.push(`path: ${_.debug.activeEditablePath}`),Ce.length>0&&G.push(`context: ${Ce.join(", ")}`)}return G.join(`
771
771
  `)},[]),yy=E.useCallback(async _=>{const G=Fp(_);if(G.trim())try{await navigator.clipboard.writeText(G),me(_.id),window.setTimeout(()=>{fe.getState().copiedDebugEntryId===_.id&&me(null)},1400)}catch{}},[Fp]),$p=E.useCallback(_=>{var ie;if(!_.debug)return t("chat.expandDetails");const G=[];if(_.debug.outcome&&G.push(_.debug.outcome.replace(/_/g," ")),typeof _.debug.opCount=="number"){const Ce=_.debug.opCount;G.push(`${Ce} op${Ce===1?"":"s"}`)}if(_.debug.intent&&G.push(`intent: ${_.debug.intent.replace(/_/g," ")}`),_.debug.plannerTier&&G.push(_.debug.plannerTier.replace(/_/g," ")),Array.isArray(_.debug.timeline)&&_.debug.timeline.length>0){const Ce=(ie=_.debug.timeline[_.debug.timeline.length-1])==null?void 0:ie.atMs;typeof Ce=="number"&&G.push(`${Ce}ms`)}return G.join(" · ")||t("chat.expandDetails")},[t]),So=Mr.findings.length,Ba=So===1?t("health.issueCount",{count:String(So)}):t("health.issueCountPlural",{count:String(So)}),iu=So>0?`${t("health.tooltip")}, ${Ba}`:t("health.tooltip"),xy=So>0?`${t("health.tooltip")}: ${Ba}`:t("health.tooltip"),su=p.jsxs("div",{className:"chat-header-slug-actions",children:[p.jsx("button",{type:"button",className:`chat-header-icon-btn${ko?" is-active":""}`,"aria-label":t("tabs.properties"),"data-tooltip":t("tabs.properties"),"aria-pressed":ko,onClick:()=>{ko?rf():(W(void 0),K(void 0),ht("properties"))},children:p.jsx(bF,{size:14,"aria-hidden":"true"})}),p.jsx("button",{type:"button",className:`chat-header-icon-btn${za?" is-active":""}`,"aria-label":t("history.tooltip"),"data-tooltip":t("history.tooltip"),"aria-pressed":za,onClick:()=>ht(za?"chat":"history"),children:p.jsx(c9,{size:14,"aria-hidden":"true"})}),p.jsxs("button",{type:"button",className:`chat-header-icon-btn${ru?" is-active":""}`,"aria-label":iu,"data-tooltip":xy,"aria-pressed":ru,onClick:()=>ht(ru?"chat":"health"),children:[p.jsx(YB,{size:14,"aria-hidden":"true"}),So>0?p.jsx("span",{className:`health-badge health-badge--${nu??"info"}`,"aria-hidden":"true",children:So}):null]}),Np?p.jsx("a",{className:"chat-header-icon-btn",href:Np,target:"_blank",rel:"noreferrer","aria-label":t("header.openImmersive"),"data-tooltip":t("header.openImmersive"),children:p.jsx(w9,{size:14,"aria-hidden":"true"})}):null,ne?p.jsx("button",{type:"button",className:"chat-header-icon-btn","aria-label":t("header.moreOptions"),"data-tooltip":t("header.moreOptions"),onClick:()=>He(!0),children:p.jsx(m9,{size:14,"aria-hidden":"true"})}):null]});return p.jsxs("div",{className:`layout${ko?" layout--props-open":""}${g?" layout--banner":""}`,style:La,children:[g?p.jsx(Wve,{siteId:r,orchestratorUrl:Be,hostedIds:e.hostedSiteIds??[],...e.siteHosting==="notHosted"?{}:{siteOwnOrchestrator:m}}):null,p.jsxs("aside",{className:"chat-panel",ref:jt,style:Lp,children:[p.jsxs("header",{className:"chat-header",children:[p.jsxs("div",{className:"chat-header-top",children:[p.jsxs("div",{className:"chat-header-site-name",ref:nr,children:[e.siteList.length>1?p.jsxs("button",{type:"button",className:`site-switcher-trigger${wn?" is-open":""}`,onClick:()=>Ln(_=>!_),"aria-expanded":wn,"aria-haspopup":"menu",children:[p.jsx("span",{className:`site-switcher-item-dot site-switcher-item-dot-${Nr!=null&&Nr.probing?"probing":Nr!=null&&Nr.online?"online":"offline"}`,"aria-hidden":"true"}),p.jsx("span",{className:"site-switcher-trigger-label",children:a.name}),p.jsx(Na,{size:12,className:`site-switcher-chevron${wn?" is-open":""}`,"aria-hidden":"true"})]}):p.jsx("span",{className:"site-switcher-trigger-label",children:a.name}),wn&&p.jsxs("div",{className:"site-switcher-dropdown",role:"menu","aria-label":t("header.allSites"),children:[p.jsxs("div",{className:"site-switcher-header",children:[p.jsx("span",{children:t("header.allSites")}),p.jsxs("a",{href:"/sites",className:"site-switcher-add-link",onClick:()=>Ln(!1),children:["+ ",t("sites.addSite")]})]}),p.jsx("div",{className:"site-switcher-list",children:Ws.map(_=>p.jsx(hke,{name:_.site.name,origin:_.origin,statusClass:_.probing?"probing":"online",active:_.site.id===r,onSelect:()=>{_.site.id!==r&&e.openEditorForSite(_.site.id),Ln(!1)}},_.site.id))}),p.jsxs("div",{className:"site-switcher-actions",role:"group",children:[p.jsxs("button",{type:"button",role:"menuitem",className:"site-switcher-action",onClick:()=>{Ln(!1),e.setConfigSiteId(r)},children:[p.jsx(mF,{size:14,"aria-hidden":"true"}),p.jsx("span",{children:t("header.siteSettings")})]}),Ge.siteHasCmsContent!==!1&&p.jsxs("button",{type:"button",role:"menuitem",className:"site-switcher-action",title:t("header.syncFromSiteTitle"),disabled:Kn,onClick:async()=>{Ln(!1);const _=await Ge.syncFromSite();_.ok&&_.count>0?Ge.pushAssistantFromResult({status:"applied",summary:_.count===1?t("header.syncedPage"):t("header.syncedPages",{count:_.count}),changes:[]}):_.ok||Ge.pushAssistantFromResult({status:"error",summary:_.reason==="network"?t("header.syncFailedNetwork"):t("header.syncFailedEmpty"),changes:[]})},children:[p.jsx(ZS,{size:14,"aria-hidden":"true"}),p.jsx("span",{children:t("header.syncFromSite")})]})]}),p.jsxs("a",{href:"/sites",className:"site-switcher-footer",onClick:()=>Ln(!1),children:[t("header.viewAllSites"),p.jsx($g,{size:11,"aria-hidden":"true"})]})]})]}),p.jsxs("div",{className:"chat-header-right",children:[d.status==="degraded"?p.jsx("span",{className:"planner-badge",title:d.reason??"Components unavailable",children:t("header.limited")}):null,!dd&&(dr||Vt.publishInProgress)?p.jsxs("button",{type:"button",className:"publish-preview-btn",onClick:()=>ze(!0),disabled:Kn||Vt.isPublishing,title:_t.summary&&_t.summary.total>0?t("header.unpublishedTooltip",{count:String(_t.summary.total)}):void 0,children:[Vt.publishInProgress?p.jsx("span",{className:"publish-spinner","aria-hidden":"true"}):null,Vt.publishInProgress?t("header.publishing"):t("header.publish"),_t.summary&&_t.summary.total>0?p.jsx("span",{className:"publish-preview-badge","aria-hidden":"true",children:_t.summary.total}):null]}):null,!dd&&Vt.publishStatus?p.jsxs(p.Fragment,{children:[Vt.publishStatus.inspectUrl?p.jsx("a",{className:"publish-view-link",href:Vt.publishStatus.inspectUrl,target:"_blank",rel:"noreferrer",children:t("header.viewDeploy")}):null,Ap?p.jsx("a",{className:"live-site-icon-btn",href:Ap,target:"_blank",rel:"noreferrer","aria-label":t("header.openLiveSite"),title:t("header.openLiveSite"),children:p.jsx($g,{size:16,"aria-hidden":"true"})}):null]}):null]})]}),hn&&Or?p.jsxs("div",{className:"chat-header-lang-row",children:[p.jsx("label",{className:"chat-header-lang",children:p.jsx("select",{value:Or,"aria-label":t("header.language"),title:t("header.language"),onChange:_=>x(ike(y,_.target.value,hn)),disabled:S,children:hn.locales.map(_=>p.jsx("option",{value:_,children:_===Ol?t("header.defaultLanguage"):ske(_)},_))})}),su]}):null,p.jsxs("div",{className:"chat-header-slug-row",children:[p.jsx("label",{className:"chat-header-slug",children:p.jsx("select",{value:y,"aria-label":t("header.page"),onChange:_=>x(_.target.value||"/"),disabled:S,children:hn&&Or?p.jsxs(p.Fragment,{children:[Wo.map(_=>p.jsx("option",{value:_,children:rke(_,Or)},_)),hn.shared.length>0?p.jsx("optgroup",{label:t("header.pagesWithoutLanguage"),children:hn.shared.map(_=>p.jsx("option",{value:_,children:Lx(_)},_))}):null]}):Ir.map(_=>p.jsx("option",{value:_,children:Lx(_)},_))})}),hn&&Or?null:su]})]}),p.jsxs("div",{className:"chat-thread-region",children:[hw?p.jsxs("div",{className:"demo-banner",role:"note","aria-label":"Demo mode notice",children:[p.jsx("div",{className:"demo-banner-title",children:t("demo.bannerTitle")}),p.jsx("div",{className:"demo-banner-body",children:t("demo.bannerBody")}),p.jsxs("div",{className:"demo-banner-examples",children:[p.jsx("button",{type:"button",className:"demo-banner-example",disabled:Kn,onClick:()=>void Ge.submitChat(t("demo.tryExample1")),children:t("demo.tryExample1")}),p.jsx("button",{type:"button",className:"demo-banner-example",disabled:Kn,onClick:()=>void Ge.submitChat(t("demo.tryExample2")),children:t("demo.tryExample2")}),p.jsx("button",{type:"button",className:"demo-banner-example",disabled:Kn,onClick:()=>void Ge.submitChat(t("demo.tryExample3")),children:t("demo.tryExample3")})]})]}):null,p.jsx(ak,{fallbackLabel:"Chat unavailable — try refreshing",onReset:()=>window.location.reload(),children:p.jsx(vee,{ref:Bn,className:"chat-thread",streamStatusLabel:Op,undoInFlightEntryId:Ge.undoInFlightEntryId,onSuggestionClick:(_,G)=>void Ge.submitChat(_,void 0,{clickedSuggestionId:G}),onUndo:_=>void Ge.applyUndoHistory(_),undoLabel:t("chat.undo"),undoneLabel:t("chat.undone"),appliedDraftLabel:t("chat.appliedDraft"),keepLabel:t("chat.keep"),revertLabel:t("chat.revert"),revertedLabel:t("chat.reverted"),keptLabel:t("chat.kept"),renderEntryExtras:_=>{var G;return p.jsxs(p.Fragment,{children:[_.variations&&Array.isArray(_.variations.options)&&_.variations.options.length>0?p.jsx("div",{className:"msg-variations",children:_.variations.options.map((ie,Ce)=>p.jsxs("button",{type:"button",className:"msg-variation-card",disabled:Kn,onClick:async()=>{const De=_.variations;try{(await fetch(`${Be}/ops`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session:n,siteId:r,ops:[{op:"update_props",pageSlug:De.pageSlug,blockId:De.blockId,patch:ie.patch}]})})).ok&&(Qt.postToSite("draftUpdated",{focusBlockId:De.blockId}),Oe(),Ge.pushAssistantFromResult({status:"applied",summary:`Applied variation: ${ie.title}`,changes:[ie.summary]}))}catch{}},children:[p.jsx("div",{className:"msg-variation-preview-wrap",children:p.jsx(kN,{block:{id:_.variations.blockId,type:_.variations.blockType,props:{..._.variations.baseProps,...ie.patch}},virtualWidth:1280})}),p.jsxs("div",{className:"msg-variation-meta",children:[p.jsx("span",{className:"msg-variation-badge",children:String.fromCharCode(65+Ce)}),p.jsxs("div",{className:"msg-variation-content",children:[p.jsx("span",{className:"msg-variation-title",children:ie.title}),p.jsx("span",{className:"msg-variation-summary",children:ie.summary})]})]})]},ie.id??`${_.id}-v-${Ce}`))}):null,_.status==="plan_ready"&&_.pendingPlanId?p.jsxs("div",{className:"msg-plan-actions",children:[_.planPreview?p.jsx(Qse,{preview:_.planPreview}):null,_.destructiveReasons&&_.destructiveReasons.length>0?p.jsx("div",{className:"msg-destructive-warning",role:"alert",children:_.destructiveReasons.map((ie,Ce)=>p.jsxs("div",{className:"msg-destructive-warning-line",children:["⚠ ",ie]},Ce))}):null,(()=>{var pn;const ie=_.pendingPlanId,Ce=Kn||dt!==ie,De=!!(_.destructiveReasons&&_.destructiveReasons.length>0),Ve=((pn=_.planPreview)==null?void 0:pn.diff.pages.filter(rr=>rr.status==="removed").length)??0,Qe=Ve===1?t("plan.deletePage"):Ve>1?t("plan.deletePages",{count:Ve}):t(De?"plan.applyDestructive":"plan.apply");return p.jsxs("div",{className:"msg-plan-btn-row",children:[p.jsx("button",{type:"button",className:`primary-btn msg-plan-btn${De?" is-destructive":""}`,onClick:()=>void Ge.approvePendingPlan(ie),disabled:Ce,children:Qe}),p.jsx("button",{type:"button",className:"secondary-btn msg-plan-btn",onClick:()=>void Ge.stopPendingPlan(ie),disabled:Ce,children:t("plan.discard")})]})})()]}):null,_.imageSwap?(()=>{const ie=_.imageSwap,Ce=/^image$/i.test((ie.fieldLabel??"").trim()),De=ie.fieldLabel&&!(ie.blockDisplayName&&Ce),Ve=ie.blockDisplayName??(De?ie.fieldLabel:null),Qe=ie.blockDisplayName&&De?ie.fieldLabel:null;return p.jsxs("button",{type:"button",className:"msg-image-swap-card",onClick:()=>{zn({slug:ie.slug,blockId:ie.blockId,editablePath:ie.editablePath,currentUrl:ie.imageUrl,blockType:L===ie.blockId?F:void 0})},title:t("ops.imageSwap.pickAnother"),children:[p.jsx("img",{src:ie.imageUrl,alt:ie.altText??""}),p.jsxs("div",{className:"msg-image-swap-meta",children:[Ve?p.jsx("span",{className:"msg-image-swap-block",children:Ve}):null,Qe?p.jsx("span",{className:"msg-image-swap-field",children:Qe}):null,p.jsx("span",{className:"msg-image-swap-action",children:t("ops.imageSwap.pickAnother")})]})]})})():null,_.continuation?p.jsx("div",{className:"msg-plan-actions",children:p.jsxs("button",{type:"button",className:"primary-btn msg-plan-btn",onClick:()=>void Ge.continueChain(_.continuation.chainId),disabled:Kn||Ri!==_.continuation.chainId,children:["Continue: ",_.continuation.nextStepLabel," (",_.continuation.currentStep," of ",_.continuation.totalSteps,")"]})}):null,(()=>{if(_.wasUndone)return null;const ie=(_.mentionedSlugs??[]).filter(Ce=>Ce!==y);return ie.length===0?null:p.jsx("div",{className:"msg-suggestions msg-page-links",children:ie.map((Ce,De)=>p.jsxs("button",{type:"button",className:"msg-suggestion msg-page-link",onClick:()=>{x(Ce)},disabled:Kn,children:["Open ",Ce]},`${_.id}-route-${De}`))})})(),(_.errors??[]).length>0?p.jsx("ul",{className:"msg-errors",children:(G=_.errors)==null?void 0:G.map((ie,Ce)=>p.jsx("li",{children:ie},Ce))}):null,$e&&_.role==="assistant"&&_.debug?p.jsxs("div",{className:"msg-debug-shell",children:[p.jsxs("details",{className:"msg-debug-details",children:[p.jsxs("summary",{className:"msg-debug-summary",children:[p.jsxs("span",{className:"msg-debug-summary-left",children:[p.jsx("span",{className:"msg-debug-title",children:"Debug"}),p.jsx("span",{className:"msg-debug-summary-text",children:$p(_)})]}),p.jsx("span",{className:"msg-debug-chevron","aria-hidden":"true"})]}),p.jsx("div",{className:"msg-debug",children:p.jsxs("ul",{children:[_.debug.traceId?p.jsxs("li",{children:["traceId: ",_.debug.traceId]}):null,_.debug.promptHash?p.jsxs("li",{children:["promptHash: ",_.debug.promptHash]}):null,_.debug.outcome?p.jsxs("li",{children:["outcome: ",_.debug.outcome]}):null,_.debug.reasonCategory?p.jsxs("li",{children:["reason: ",_.debug.reasonCategory]}):null,_.debug.reason&&_.debug.reason!==_.debug.reasonCategory?p.jsxs("li",{children:["reasonDetail: ",_.debug.reason]}):null,_.debug.intent?p.jsxs("li",{children:["intent: ",_.debug.intent]}):null,_.debug.plannerTier?p.jsxs("li",{children:["plannerTier: ",_.debug.plannerTier]}):null,_.debug.modelUsed?p.jsxs("li",{children:["model: ",_.debug.modelUsed,_.debug.plannerSource?` (${_.debug.plannerSource})`:""]}):null,typeof _.debug.planningAttempts=="number"&&_.debug.planningAttempts>1?p.jsxs("li",{children:["planningAttempts: ",_.debug.planningAttempts]}):null,typeof _.debug.opCount=="number"?p.jsxs("li",{children:["opCount: ",_.debug.opCount]}):null,Array.isArray(_.debug.skippedOps)&&_.debug.skippedOps.length>0?p.jsxs("li",{children:["skippedOps: ",_.debug.skippedOps.map(ie=>`[${ie.index}] ${ie.op} ${ie.pageSlug??""}${ie.blockId?"#"+ie.blockId:""}: ${ie.reason}`).join(", ")]}):typeof _.debug.skippedOpCount=="number"&&_.debug.skippedOpCount>0?p.jsxs("li",{children:["skippedOps: ",_.debug.skippedOpCount]}):null,Array.isArray(_.debug.opTypes)&&_.debug.opTypes.length>0?p.jsxs("li",{children:["ops: ",_.debug.opTypes.join(", ")]}):null,typeof _.debug.totalTokens=="number"?p.jsxs("li",{children:["tokens: in:",_.debug.inputTokens??"?"," out:",_.debug.outputTokens??"?"," total:",_.debug.totalTokens]}):null,typeof _.debug.estimatedUsd=="number"?p.jsxs("li",{children:["cost: $",_.debug.estimatedUsd.toFixed(4)]}):null,Array.isArray(_.debug.timeline)&&_.debug.timeline.length>0?p.jsxs("li",{children:["timeline: ",_.debug.timeline.map(ie=>`${ie.stage}:${ie.atMs}ms`).join(" -> ")]}):null,_.debug.promptExcerpt?p.jsxs("li",{children:["prompt: ",_.debug.promptExcerpt]}):null,_.debug.currentPage||_.debug.siteId||_.debug.activeBlockId||_.debug.activeEditablePath?p.jsxs("li",{children:["context: ",[_.debug.currentPage?`page: ${_.debug.currentPage}`:null,_.debug.siteId?`site: ${_.debug.siteId}`:null,_.debug.activeBlockId?`block: ${_.debug.activeBlockId}`:null,_.debug.activeEditablePath?`path: ${_.debug.activeEditablePath}`:null].filter(Boolean).join(", ")]}):null]})})]}),p.jsx("button",{type:"button",className:"msg-debug-copy-btn",onClick:()=>void yy(_),"aria-label":he===_.id?t("chat.copied"):t("chat.copyDebug"),title:he===_.id?t("chat.copied"):t("chat.copy"),children:he===_.id?p.jsx(Fd,{"aria-hidden":"true",size:14}):p.jsx(WS,{"aria-hidden":"true",size:14})})]}):null]})},renderEntryActions:(_,G)=>{var ie,Ce,De;return G&&_.role==="assistant"&&((ie=_.debug)!=null&&ie.traceId)&&_.id!=="welcome"?p.jsxs(p.Fragment,{children:[p.jsx("button",{type:"button",className:`msg-feedback-btn ${((Ce=_.feedback)==null?void 0:Ce.rating)==="up"?"msg-feedback-btn--active":""}`,onClick:()=>{_.feedback||Ge.submitFeedback(_.id,"up")},disabled:!!_.feedback,title:t("chat.goodResponse"),children:p.jsx(EF,{"aria-hidden":"true",size:13})}),p.jsx("button",{type:"button",className:`msg-feedback-btn ${((De=_.feedback)==null?void 0:De.rating)==="down"?"msg-feedback-btn--active":""}`,onClick:()=>{_.feedback||(et(Fe===_.id?null:_.id),Ot(""))},disabled:!!_.feedback,title:t("chat.badResponse"),children:p.jsx(wF,{"aria-hidden":"true",size:13})}),_.feedback?p.jsxs("span",{className:"msg-feedback-label",children:[_.feedback.rating==="up"?t("chat.feedbackThanks"):t("chat.feedbackNoted"),_.feedback.note?` — "${_.feedback.note}"`:""]}):null,Fe===_.id&&!_.feedback?p.jsxs("form",{className:"msg-feedback-note-form",onSubmit:Ve=>{Ve.preventDefault(),Ge.submitFeedback(_.id,"down",ft||void 0),et(null),Ot("")},children:[p.jsx("input",{className:"msg-feedback-note-input",placeholder:t("chat.feedbackPlaceholder"),value:ft,onChange:Ve=>Ot(Ve.target.value),autoFocus:!0}),p.jsx("button",{type:"submit",className:"msg-feedback-note-submit",children:t("chat.feedbackSend")})]}):null]}):null},renderStreamingExtras:()=>p.jsxs(p.Fragment,{children:[vo?p.jsx("span",{className:"stream-reconnect-badge stream-reconnect-badge-inline",title:br??void 0,children:vo}):null,$e&&vi?p.jsx("div",{className:"streaming-debug-inline",children:zp}):null]}),renderStreamStatusFallback:()=>p.jsxs("div",{className:`streaming-pill ${nf?"is-error":"is-active"} ${nR==="text"?"is-text":"is-legacy"}`,children:[nR==="text"?p.jsx("span",{className:"streaming-pill-status streaming-pill-status-text",children:Op}):p.jsxs(p.Fragment,{children:[p.jsx("span",{className:"streaming-pill-title",children:p.jsx("span",{className:"streaming-pill-sparkle",children:"✦"})}),p.jsx("span",{className:"streaming-pill-status",children:by}),nf?null:p.jsxs("span",{className:"streaming-dots","aria-hidden":"true",children:[p.jsx("i",{}),p.jsx("i",{}),p.jsx("i",{})]})]}),vo?p.jsx("span",{className:"stream-reconnect-badge",title:br??void 0,children:vo}):null,Pr?p.jsx("div",{className:"image-gen-progress",children:p.jsx("div",{className:"image-gen-progress-fill",style:{width:`${Pr.percent}%`}})}):null,es?p.jsx("button",{type:"button",className:"streaming-jump-btn",onClick:()=>Qt.postToSite("highlightBlock",{blockId:es,editablePath:null,scrollIntoView:!0}),children:"Jump to latest change"}):null,$e&&vi?p.jsx("div",{className:"streaming-debug-inline",children:zp}):null]})})})]}),p.jsx("div",{ref:Ss,className:"composer-splitter",role:"separator","aria-orientation":"horizontal","aria-label":t("resize.inputPanel"),onPointerDown:_=>{oi.current={y:_.clientY,composerHeight:Gt},document.body.style.userSelect="none"}}),Di==="demo"?p.jsx(Kse,{collapsed:yo,onToggle:()=>_s(_=>!_)}):null,p.jsx(kee,{className:"composer",message:P,isLoading:Kn,hasUserEntry:Bp,onMessageChange:R,onSubmit:_=>{R(""),Ge.submitChat(_,P)},onTranscribeAudio:zt.transcribeAudio,onUploadAttachment:zt.uploadAttachment,attachments:Oa,onAttachmentsChange:bo,onCancel:Ge.cancelChat,onAutoHeightChange:Dp,selectionModeEnabled:Ue,onToggleSelectionMode:()=>Ys(),canUndoServer:Ge.canUndoServer,canRedoServer:Ge.canRedoServer,onGlobalUndo:()=>void Ge.applyGlobalUndo(),onGlobalRedo:()=>void Ge.applyGlobalRedo(),undoTooltip:t("chat.undoTooltip"),redoTooltip:t("chat.redoTooltip"),contextChip:L&&F?{label:t("chatInput.editingBlock",{block:((sf=Au()[F])==null?void 0:sf.displayName)??F}),clearLabel:t("chatInput.clearSelection"),onClear:()=>{W(void 0),K(void 0)}}:null})]}),p.jsx("div",{className:"panel-splitter",role:"separator","aria-orientation":"vertical","aria-label":t("resize.chatPanel"),onPointerDown:_=>{const G=jt.current;G&&(Fn.current={x:_.clientX,width:G.offsetWidth,target:"chat"},document.body.style.userSelect="none",document.body.classList.add("panel-resizing"))}}),p.jsx("div",{className:"preview",children:p.jsxs("div",{className:"preview-canvas",ref:Wr,children:[dy?null:p.jsx("div",{className:"preview-loading",role:"status","aria-label":t("preview.loading"),children:p.jsx("span",{className:"preview-loading-spinner","aria-hidden":"true"})}),p.jsx("iframe",{ref:Qt.iframeRef,title:t("preview.title"),src:cc,style:{colorScheme:"light dark"},onLoad:()=>{Tp(!0),e0&&!mr.current&&(mr.current=!0,Wi.current=u),Qt.postToSite("setNestedLabelsVisibility",{visible:X})}})]})}),ko?p.jsxs(p.Fragment,{children:[p.jsx("div",{className:"panel-splitter panel-splitter--props",role:"separator","aria-orientation":"vertical","aria-label":t("resize.chatPanel"),onPointerDown:_=>{const G=gr.current;G&&(Fn.current={x:_.clientX,width:G.offsetWidth,target:"props"},document.body.style.userSelect="none",document.body.classList.add("panel-resizing"))}}),p.jsx("aside",{className:"props-panel",ref:gr,children:p.jsx(ak,{fallbackLabel:"Properties panel unavailable — try refreshing",children:p.jsx(Ive,{props:ln.props,status:ln.status,failure:ln.failure,failedSlug:ln.failedSlug,failedOrigin:ln.failedOrigin,onRetry:ln.retry,pageName:Lx(y),onDeselectBlock:()=>{W(void 0),K(void 0)},onClose:rf,navLabel:((of=e.headerConfig.navLabels)==null?void 0:of[y])??"",onNavLabelChange:(_,G)=>{e.updateHeaderConfig({navLabels:{[_]:G}}),Qt.postToSite("draftUpdated",{}),Oe()},pageMeta:nn.meta,onPageMetaChange:(_,G)=>{const ie={...nn.meta,[_]:G};nn.setMeta(ie),(async()=>{try{const Ce=await fetch(`${Be}/ops`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({session:n,siteId:r,ops:[{op:"update_page_meta",pageSlug:y,patch:{[_]:G}}]})}),De=await Ce.json();if(!Ce.ok||De.status!=="applied"){nn.refetch();return}Qt.postToSite("draftUpdated",{}),Oe()}catch{nn.refetch()}})()},onFieldChange:async(_,G)=>{await Ge.inlineEditCommit(y,L,_,G,{silent:!0}),ln.refetch()},onImageClick:(_,G)=>{L&&zn({slug:y,blockId:L,editablePath:_,currentUrl:G,blockType:F})},onAiAssist:hy,onPageAiAssist:ef,onAiQuickAction:py,onPageAiQuickAction:my,onAddListItem:L&&F?_=>{Ge.addListItem(y,L,F,_).then(()=>ln.refetch())}:void 0,onRemoveListItem:L&&F?(_,G)=>{Ge.removeListItem(y,L,F,_,G).then(()=>ln.refetch())}:void 0,manifestByType:d.byType,siteOrigin:u})})})]}):null,ru?p.jsx("div",{className:"history-drawer-backdrop",onClick:()=>ht("chat"),children:p.jsx("aside",{className:"history-drawer",role:"dialog","aria-label":t("health.title"),onClick:_=>_.stopPropagation(),children:p.jsx(ak,{children:p.jsx(Lee,{findings:Mr.findings,isLoading:Mr.isLoading,isRunning:Mr.isRunning,error:Mr.error,durable:Mr.durable,onRun:()=>void Mr.run(),onDismiss:_=>void Mr.setStatus(_,"dismissed"),onSnooze:_=>void Mr.setStatus(_,"snoozed"),onGoTo:uy,onClose:()=>ht("chat")})})})}):null,za?p.jsx("div",{className:"history-drawer-backdrop",onClick:()=>ht("chat"),children:p.jsx("aside",{className:"history-drawer",role:"dialog","aria-label":t("history.title"),onClick:_=>_.stopPropagation(),children:p.jsx(Mee,{session:n,siteId:r,slug:y,visible:za,onRestore:xt,isRestoring:Bt,onDiscarded:it,onClose:()=>ht("chat")})})}):null,Pa&&Pe?p.jsx("div",{ref:Cs,className:"composer--anchored is-expanded",style:{top:Pa.top,left:Pa.left,width:Pa.width},children:p.jsx(Ij,{message:P,isLoading:Kn,hasUserEntry:Bp,onMessageChange:R,onSubmit:_=>{R(""),Ge.submitChat(_,P)},onTranscribeAudio:zt.transcribeAudio,onUploadAttachment:zt.uploadAttachment,attachments:Oa,onAttachmentsChange:bo,onCancel:Ge.cancelChat,onAutoHeightChange:()=>{},compact:!0})}):null,mt?(()=>{const _=mt,G=_.options.find(ie=>ie.id===cr)??null;return p.jsx("div",{className:"variation-modal-backdrop",onClick:()=>{we||Pt(null)},children:p.jsxs("div",{className:"variation-modal",role:"dialog","aria-modal":"true","aria-label":t("variation.title"),onClick:ie=>ie.stopPropagation(),children:[p.jsxs("div",{className:"variation-modal-header",children:[p.jsx("h2",{children:"Choose a Variation"}),p.jsx("button",{type:"button",className:"settings-close-btn","aria-label":t("variation.close"),onClick:()=>Pt(null),disabled:we,children:"×"})]}),p.jsx("div",{className:"variation-modal-body",children:_.options.map((ie,Ce)=>p.jsxs("article",{className:`variation-card${ie.id===cr?" is-selected":""}`,onClick:()=>fn(ie.id),children:[p.jsxs("div",{className:"variation-card-preview-wrap",children:[p.jsx("span",{className:"variation-card-badge",children:String.fromCharCode(65+Ce)}),p.jsx(kN,{virtualWidth:vG.desktop,block:{id:_.blockId,type:_.blockType,props:jG(_.baseProps,ie.patch)}}),ie.imagePending?p.jsxs("div",{className:"variation-card-image-pending","aria-live":"polite",children:[p.jsx("span",{className:"variation-card-image-pending-spinner","aria-hidden":"true"}),p.jsx("span",{className:"variation-card-image-pending-label",children:"Generating image…"})]}):null]}),p.jsx("h3",{className:"variation-card-title",children:ie.title}),p.jsx("p",{className:"variation-card-summary",children:ie.summary})]},ie.id))}),p.jsx("div",{className:"variation-modal-footer",children:p.jsx("button",{type:"button",className:"publish-preview-btn variation-apply-btn",onClick:()=>{G&&Ge.applyVariation(G)},disabled:we||!G,children:we?t("variation.applying"):t("variation.apply",{title:(G==null?void 0:G.title)??""})})})]})})})():null,ct?p.jsx("div",{className:"add-block-modal-backdrop",onClick:()=>{nt||Xt(null)},children:p.jsxs("div",{className:"add-block-modal",role:"dialog","aria-modal":"true","aria-label":t("addBlock.title"),onClick:_=>_.stopPropagation(),children:[p.jsxs("div",{className:"add-block-modal-header",children:[p.jsx("h2",{children:"Add block"}),p.jsx("p",{children:ct.beforeBlockId&&!ct.afterBlockId?t("addBlock.insertAbove"):t("addBlock.insertBelow")}),p.jsx("button",{type:"button",className:"settings-close-btn","aria-label":t("addBlock.close"),onClick:()=>Xt(null),disabled:nt,children:"×"})]}),p.jsxs("div",{className:"add-block-modal-body",children:[p.jsx("label",{className:"add-block-search",children:p.jsx("input",{type:"search",value:kt,onChange:_=>St(_.target.value),placeholder:t("addBlock.searchPlaceholder"),disabled:nt})}),ja.length===0?p.jsx("p",{className:"add-block-empty",children:"No block types match your search."}):p.jsx("div",{className:"add-block-flat-list",children:ja.flatMap(_=>_.options).map(_=>p.jsxs("button",{type:"button",className:"add-block-option",disabled:nt,onClick:async()=>{var Ce;if(!ct||nt)return;gn(!0);const G=(Ce=d.byType.get(_.type))==null?void 0:Ce.defaultProps,ie=await Ge.addBlockAfter(ct.slug,ct.afterBlockId,_.type,ct.beforeBlockId,G);gn(!1),ie&&Xt(null)},children:[p.jsx("span",{className:"add-block-option-label",children:_.label}),p.jsx("span",{className:"add-block-option-actions","aria-hidden":"true",children:p.jsx("span",{className:"add-block-option-plus",children:"+"})})]},_.type))})]})]})}):null,p.jsx(Tse,{open:oe,onOpenChange:He,useStreaming:O,onStreamingChange:U,showNestedLabels:X,onNestedLabelsChange:z,chatDarkMode:i,chatThemePreference:s,onChatThemePreferenceChange:o,showDebugDetails:$e,onDebugDetailsChange:bt,fieldDraftDebugEnabled:vi,onFieldDraftDebugChange:li,autoScrollTrackingEnabled:Q,onAutoScrollTrackingChange:le,autoOpenPropertiesEnabled:I,onAutoOpenPropertiesChange:$,provider:A,modelKey:w,availableProviders:j,onModelChange:(_,G)=>{M(_),T(G)},onClearChat:Ge.clearChat,agentModeEnabled:Tr.agentMode??!1,showDevOptions:Ae,onShowDevOptionsChange:ne?ee:void 0}),p.jsx(qse,{open:_e,onOpenChange:ze,onConfirm:_=>void Vt.publishSite(_),chatLog:ai,isPublishing:Vt.isPublishing,session:n,siteId:r,siteOrigin:u}),p.jsx(_O,{sites:e,onPreviewRefresh:()=>{Qt.postToSite("draftUpdated",{}),Oe()}}),p.jsx(tce,{open:tn,features:{...Tr,googleDrive:Tr.googleDrive||!!((fc=a.gdriveFolderId)!=null&&fc.trim())},currentUrl:Nt==null?void 0:Nt.currentUrl,gdriveFolderId:a.gdriveFolderId,cmsMedia:a.cmsMedia,siteOrigin:u,onClose:()=>zn(null),onSelect:(_,G)=>{var mc;if(!Nt)return;const{slug:ie,blockId:Ce,editablePath:De,currentUrl:Ve,blockType:Qe}=Nt,pn=qF(De),rr=De.match(/^([a-zA-Z_]+)\[(\d+)\]\.(.+)$/),En=pn!==De?pn.match(/^([a-zA-Z_]+)\[(\d+)\]\.(.+)$/):null;let ts,Ts;if(rr){const[,ns,rs,gc]=rr,Fa={[gc]:_};En&&(Fa[En[3]]=G),ts=[{op:"update_item",pageSlug:ie,blockId:Ce,listKey:ns,index:Number(rs),patch:Fa}],Ts=`${ns}[${rs}].${gc}`}else{const ns={[De]:_};pn!==De&&(ns[pn]=G),ts=[{op:"update_props",pageSlug:ie,blockId:Ce,patch:ns}],Ts=De}const hc=Qe??(Ce===L?F:void 0)??(Ce===L&&ln.blockType?ln.blockType:void 0),Up=hc?((mc=Au()[hc])==null?void 0:mc.displayName)??hc:void 0,pc={imageUrl:_,previousUrl:Ve,altText:G,slug:ie,blockId:Ce,editablePath:De,blockDisplayName:Up,fieldLabel:gke(Ts)};(async()=>{try{const ns=await fetch(`${Be}/ops`,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(Ls({session:n,siteId:r,ops:ts},d.manifest))}),rs=await ns.json();ns.ok&&rs.status==="applied"?(Qt.postToSite("draftUpdated",{focusBlockId:Ce}),Oe(),Ge.pushAssistantFromResult({status:"applied",summary:t("ops.changedImage")},{canUndo:!0,imageSwap:pc}),ln.refetch()):(console.error("[ImagePicker] ops failed:",ns.status,rs.error,rs.details??"","ops:",JSON.stringify(ts)),Ge.pushAssistantFromResult({status:"error",summary:t("ops.imageChangeFailed")},{imageSwap:{...pc,imageUrl:Ve??_}}))}catch(ns){console.error("[ImagePicker] ops failed:",ns),Ge.pushAssistantFromResult({status:"error",summary:t("ops.imageChangeFailed")},{imageSwap:{...pc,imageUrl:Ve??_}})}})()}}),ake?p.jsx(_ee,{onTry:_=>void Ge.submitChat(_),onAction:_=>{_==="heroImage"&&Ia()}}):null]})}const Ng=Be,lk={position:"fixed",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"#0a0a0a",fontFamily:"system-ui, sans-serif",zIndex:99999},uk={display:"flex",flexDirection:"column",gap:12,width:320,padding:32,borderRadius:12,background:"#18181b",border:"1px solid #27272a"},ck={padding:"10px 16px",borderRadius:8,border:"none",background:"#3b82f6",color:"#fff",fontSize:14,fontWeight:500,cursor:"pointer"};function yke({children:e}){const{t}=Mn(),[n,r]=E.useState("checking"),[i,s]=E.useState(""),[o,a]=E.useState(!1),[u,d]=E.useState(""),[f,m]=E.useState(!1),[g,y]=E.useState(0),v=Math.min(15e3,1500*2**Math.max(0,g-1));E.useEffect(()=>{let w=!0;return r("checking"),fetch(`${Ng}/auth/status`).then(T=>{if(!T.ok)throw new Error(`auth/status ${T.status}`);return T.json()}).then(T=>{if(w){if(T.mode==="closed"){lg(),d(typeof T.reason=="string"?T.reason:""),r("closed");return}if(!T.gateEnabled)lg(),r("open");else{const A=!!localStorage.getItem(sS),M=r2().length>0;r(A&&M?"open":"locked")}}}).catch(()=>{w&&r("unreachable")}),()=>{w=!1}},[g]),E.useEffect(()=>{if(n!=="unreachable")return;const w=setTimeout(()=>y(T=>T+1),v);return()=>clearTimeout(w)},[n,g,v]);const S=async w=>{w.preventDefault(),m(!0),a(!1);try{const T=await fetch(`${Ng}/auth/verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({password:i.trim()})}),A=await T.json().catch(()=>({}));T.ok?(localStorage.setItem(sS,"1"),Qoe(A.accessToken??""),r("open")):(lg(),a(!0))}catch{lg(),a(!0)}m(!1)};return n==="checking"?null:n==="open"?p.jsx(p.Fragment,{children:e}):n==="closed"?p.jsx("div",{style:lk,children:p.jsxs("div",{style:{...uk,width:420},children:[p.jsx("h2",{style:{margin:0,color:"#fafafa",fontSize:18},children:t("password.closedTitle")}),p.jsx("p",{style:{margin:0,color:"#a1a1aa",fontSize:13,lineHeight:1.5},children:u||t("password.closedBody")}),p.jsx("p",{style:{margin:0,color:"#a1a1aa",fontSize:13,lineHeight:1.5},children:t("password.closedFix")}),p.jsxs("code",{style:{color:"#71717a",fontSize:12,wordBreak:"break-all"},children:[Ng,"/auth/status"]}),p.jsx("button",{type:"button",onClick:()=>y(w=>w+1),style:ck,children:t("password.retry")})]})}):n==="unreachable"?p.jsx("div",{style:lk,children:p.jsxs("div",{style:{...uk,width:380},children:[p.jsx("h2",{style:{margin:0,color:"#fafafa",fontSize:18},children:t("password.unreachableTitle")}),p.jsx("p",{style:{margin:0,color:"#a1a1aa",fontSize:13,lineHeight:1.5},children:t("password.unreachableBody")}),p.jsxs("code",{style:{color:"#71717a",fontSize:12,wordBreak:"break-all"},children:[Ng,"/auth/status"]}),p.jsx("button",{type:"button",onClick:()=>y(w=>w+1),style:ck,children:t("password.retry")}),p.jsx("p",{style:{margin:0,color:"#71717a",fontSize:12},"aria-live":"polite",children:t("password.retryingIn",{seconds:String(Math.round(v/1e3))})})]})}):p.jsx("div",{style:lk,children:p.jsxs("form",{onSubmit:S,style:uk,children:[p.jsx("h2",{style:{margin:0,color:"#fafafa",fontSize:18},children:t("password.title")}),p.jsx("input",{type:"password",value:i,onChange:w=>s(w.target.value),placeholder:t("password.placeholder"),autoFocus:!0,style:{padding:"10px 12px",borderRadius:8,border:o?"1px solid #ef4444":"1px solid #3f3f46",background:"#09090b",color:"#fafafa",fontSize:14,outline:"none"}}),o&&p.jsx("span",{style:{color:"#ef4444",fontSize:13},children:t("password.incorrect")}),p.jsx("button",{type:"submit",disabled:f||!i.trim(),style:{...ck,opacity:f||!i.trim()?.5:1},children:t(f?"password.checking":"password.continue")})]})})}nae();MB.createRoot(document.getElementById("root")).render(p.jsx(E.StrictMode,{children:p.jsxs(zF,{children:[p.jsx(yke,{children:p.jsx(mke,{})}),p.jsx(FB,{})]})}));export{kke as $,Pre as A,wke as B,zre as C,Pw as D,Au as E,zw as F,lF as G,U4 as H,mp as I,wce as J,kee as K,tce as L,Be as M,Uh as N,Q4 as O,kn as P,Lx as Q,Ore as R,Noe as S,Vd as T,NF as U,Mee as V,Cb as W,EG as X,CG as Y,r6 as Z,HB as _,hd as a,Fk as a0,fe as a1,xce as a2,kce as a3,ka as a4,Dl as a5,lc as a6,Qn as a7,_r as a8,vt as a9,a5 as aA,Ub as aB,_de as aC,Tde as aD,Mde as aE,d5 as aF,Ude as aG,u5 as aH,gs as aI,s5 as aJ,l5 as aK,Ide as aL,zde as aM,Pde as aN,mM as aO,qde as aP,Sa as aQ,qe as aR,Lde as aS,Bde as aT,$r as aU,Hr as aV,Rt as aa,ut as ab,S0e as ac,bD as ad,Q2 as ae,Vz as af,J6 as ag,Cge as ah,kge as ai,h6 as aj,x2 as ak,Jl as al,g2 as am,QP as an,ld as ao,W5 as ap,Ohe as aq,lo as ar,Ne as as,Jd as at,c5 as au,k2 as av,Dde as aw,Ade as ax,Nde as ay,r5 as az,Wn as b,st as c,on as d,Eb as e,Lw as f,hI as g,N6 as h,Bw as i,p as j,gp as k,Ed as l,v6 as m,Lre as n,qn as o,Bd as p,FF as q,E as r,yR as s,UF as t,t0 as u,qd as v,LF as w,kq as x,xj as y,yj as z};