@zenith-open/zenithcms-admin 1.0.0-beta.8 → 1.0.0-beta.9

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.
Files changed (35) hide show
  1. package/dist/assets/{ApiExplorerPage-DhdnjvFP.js → ApiExplorerPage-85UWt1EW.js} +1 -1
  2. package/dist/assets/{ApiExplorerPage-DhdnjvFP.js.map → ApiExplorerPage-85UWt1EW.js.map} +1 -1
  3. package/dist/assets/{AuditLogPage-TYWW1lG9.js → AuditLogPage-CwULx1tr.js} +1 -1
  4. package/dist/assets/{AuditLogPage-TYWW1lG9.js.map → AuditLogPage-CwULx1tr.js.map} +1 -1
  5. package/dist/assets/{BlockBuilderPage-CdheJ_nw.js → BlockBuilderPage-XD1IjOgx.js} +1 -1
  6. package/dist/assets/{BlockBuilderPage-CdheJ_nw.js.map → BlockBuilderPage-XD1IjOgx.js.map} +1 -1
  7. package/dist/assets/{CollectionHooksPage-CbnXaL4D.js → CollectionHooksPage-DIaSrKDj.js} +1 -1
  8. package/dist/assets/{CollectionHooksPage-CbnXaL4D.js.map → CollectionHooksPage-DIaSrKDj.js.map} +1 -1
  9. package/dist/assets/{CollectionsPage-PZFwuhHd.js → CollectionsPage-CL_t5JRI.js} +1 -1
  10. package/dist/assets/{CollectionsPage-PZFwuhHd.js.map → CollectionsPage-CL_t5JRI.js.map} +1 -1
  11. package/dist/assets/{ComponentBuilderPage-BC4Ea9AX.js → ComponentBuilderPage-C58Rr1cu.js} +1 -1
  12. package/dist/assets/{ComponentBuilderPage-BC4Ea9AX.js.map → ComponentBuilderPage-C58Rr1cu.js.map} +1 -1
  13. package/dist/assets/{DashboardBuilder-C9W1ggsK.js → DashboardBuilder-Chjyqyb7.js} +1 -1
  14. package/dist/assets/{DashboardBuilder-C9W1ggsK.js.map → DashboardBuilder-Chjyqyb7.js.map} +1 -1
  15. package/dist/assets/{PluginsPage-jOgKwIzK.js → PluginsPage-DAR4Fsz-.js} +1 -1
  16. package/dist/assets/{PluginsPage-jOgKwIzK.js.map → PluginsPage-DAR4Fsz-.js.map} +1 -1
  17. package/dist/assets/{RedirectsPage-CpZ6qVGA.js → RedirectsPage-DfMTJsac.js} +1 -1
  18. package/dist/assets/{RedirectsPage-CpZ6qVGA.js.map → RedirectsPage-DfMTJsac.js.map} +1 -1
  19. package/dist/assets/{SchemaBuilderPage-D6jCyURY.js → SchemaBuilderPage-BYprOkEv.js} +1 -1
  20. package/dist/assets/{SchemaBuilderPage-D6jCyURY.js.map → SchemaBuilderPage-BYprOkEv.js.map} +1 -1
  21. package/dist/assets/{SettingsPage-BZn_S20X.js → SettingsPage-B2r_uNVc.js} +1 -1
  22. package/dist/assets/{SettingsPage-BZn_S20X.js.map → SettingsPage-B2r_uNVc.js.map} +1 -1
  23. package/dist/assets/{SpatialEditor-PCM56yAC.js → SpatialEditor-BohlovfE.js} +1 -1
  24. package/dist/assets/{SpatialEditor-PCM56yAC.js.map → SpatialEditor-BohlovfE.js.map} +1 -1
  25. package/dist/assets/{TemplatesPage-CaZgoHEq.js → TemplatesPage-BplB2ksb.js} +1 -1
  26. package/dist/assets/{TemplatesPage-CaZgoHEq.js.map → TemplatesPage-BplB2ksb.js.map} +1 -1
  27. package/dist/assets/{TrashPage-BYiY8Xrn.js → TrashPage-BIhKrs5x.js} +1 -1
  28. package/dist/assets/{TrashPage-BYiY8Xrn.js.map → TrashPage-BIhKrs5x.js.map} +1 -1
  29. package/dist/assets/{index-BkjytCms.js → index-yE_3fruG.js} +3 -3
  30. package/dist/assets/index-yE_3fruG.js.map +1 -0
  31. package/dist/index.html +1 -1
  32. package/dist/sw.js +1 -1
  33. package/dist/sw.js.map +1 -1
  34. package/package.json +3 -3
  35. package/dist/assets/index-BkjytCms.js.map +0 -1
@@ -1,3 +1,3 @@
1
- import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{$ as t,$t as n,A as r,At as i,Bt as a,C as o,Dn as s,Dt as c,E as l,En as u,Et as d,Fn as f,G as p,Gt as m,H as h,In as g,It as _,J as v,Jn as y,Jt as b,K as x,Kn as S,Ln as C,Lt as w,M as T,Mt as E,On as D,Ot as O,P as k,Pn as A,Pt as j,Q as M,Qn as ee,Rn as N,Tn as P,Un as F,Ut as I,V as te,Vn as ne,Vt as re,Wt as L,Xn as ie,Y as ae,Z as oe,Zt as se,an as ce,at as le,b as ue,bn as R,br as de,c as fe,cn as z,ct as pe,d as B,dt as me,en as he,er as V,f as ge,fn as _e,gn as ve,gt as ye,h as be,hr as xe,ht as Se,in as Ce,ir as H,it as we,j as Te,jt as Ee,k as De,kn as Oe,l as U,ln as ke,mr as Ae,n as je,nn as Me,nr as Ne,o as W,on as Pe,or as Fe,ot as Ie,p as Le,pt as Re,q as ze,qn as Be,qt as Ve,r as He,rn as Ue,rr as G,sn as We,st as Ge,tn as Ke,tr as qe,u as Je,un as Ye,ut as Xe,vr as Ze,xn as Qe,xr as $e,xt as et,y as tt,z as nt}from"./vendor-react-DQVTOTFO.js";import{t as rt}from"./vendor-C-9IqjvY.js";import{a as K,n as it,o as q,r as at,s as J,t as Y}from"./utils-fgvbH6CB.js";import{a as ot,i as st,l as ct,m as lt,n as ut,o as X,r as dt,t as ft,u as pt,v as mt,y as ht}from"./index-BkjytCms.js";import{t as gt}from"./useUnsavedGuard-CMMKQT9a.js";import{t as _t}from"./EmptyState-X_SXKpQY.js";var Z=e($e(),1),Q=Ze(),vt=({x:e,y:t,theme:n,onClose:r,onDuplicate:i,onDelete:a,onAlign:c,onConvert:l})=>{let u=st(),d=(0,Z.useRef)(null),[f,p]=Z.useState(!1);(0,Z.useEffect)(()=>{let e=e=>{d.current&&!d.current.contains(e.target)&&r()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[r]);let[m,h]=Z.useState({top:t,left:e});return(0,Z.useEffect)(()=>{if(d.current){let n=d.current.getBoundingClientRect(),r={top:t,left:e};e+n.width>window.innerWidth&&(r.left=e-n.width),t+n.height>window.innerHeight&&(r.top=t-n.height),h(r)}},[e,t]),(0,Q.jsx)(`div`,{ref:d,style:{top:m.top,left:m.left},className:`fixed z-[999] w-56 select-none font-sans`,children:(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.95,y:-5},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:-5},transition:{duration:.15},className:Y(`p-1.5 border rounded-none-none shadow-2xl backdrop-blur-xl relative`,n===`dark`?`bg-app/95 border-z-border text-z-primary`:`bg-z-panel/95 border-z-border text-z-primary shadow-sm/50`),children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(`button`,{onMouseEnter:()=>p(!0),onClick:()=>p(!f),className:Y(`w-full flex items-center justify-between px-3 py-2 text-left text-xs font-semibold rounded-none-none transition-colors`,n===`dark`?`hover:bg-z-hover`:`hover:bg-[var(--z-bg-hover)]`),children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(v,{size:13,className:`text-z-secondary`}),`Convert to Layout`]}),(0,Q.jsx)(ce,{size:12,className:`opacity-50`})]}),f&&(0,Q.jsx)(`div`,{className:`absolute left-full top-0 ml-1 w-52 select-none`,onMouseLeave:()=>p(!1),children:(0,Q.jsx)(G.div,{initial:{opacity:0,x:-5},animate:{opacity:1,x:0},className:Y(`p-1.5 border rounded-none-none shadow-2xl backdrop-blur-xl max-h-72 overflow-y-auto custom-editor-scrollbar`,n===`dark`?`bg-app/95 border-z-border text-z-primary`:`bg-z-panel/95 border-z-border text-z-primary`),children:u.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>{l(e.type),r()},className:Y(`w-full flex items-center gap-2.5 px-2.5 py-1.5 text-left text-xs rounded-none-none transition-colors font-medium`,n===`dark`?`hover:bg-z-hover`:`hover:bg-[var(--z-bg-hover)]`),children:[e.icon&&(0,Q.jsx)(e.icon,{size:13,className:`text-z-secondary shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.title})]},e.type))})})]}),(0,Q.jsx)(`div`,{className:Y(`h-px my-1`,n===`dark`?`bg-z-hover`:`bg-[var(--z-bg-hover)]`)}),(0,Q.jsxs)(`button`,{onClick:()=>{i(),r()},className:Y(`w-full flex items-center gap-2 px-3 py-2 text-left text-xs font-semibold rounded-none-none transition-colors`,n===`dark`?`hover:bg-z-hover`:`hover:bg-[var(--z-bg-hover)]`),children:[(0,Q.jsx)(b,{size:13,className:`text-z-secondary`}),`Duplicate Section`]}),(0,Q.jsx)(`div`,{className:Y(`h-px my-1`,n===`dark`?`bg-z-hover`:`bg-[var(--z-bg-hover)]`)}),(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-semibold opacity-40`,children:`Alignment`}),(0,Q.jsxs)(`div`,{className:`flex gap-1 px-1.5 pb-1`,children:[(0,Q.jsx)(`button`,{onClick:()=>{c(`left`),r()},"aria-label":`Align left`,className:Y(`flex-1 flex items-center justify-center p-1.5 border rounded-none-none transition-all`,n===`dark`?`border-z-border hover:border-z-border/30 hover:bg-z-hover text-z-muted hover:text-z-secondary`:`border-z-border hover:border-z-border hover:bg-[var(--z-bg-input)] text-z-secondary hover:text-z-secondary`),children:(0,Q.jsx)(s,{size:13,"aria-hidden":`true`})}),(0,Q.jsx)(`button`,{onClick:()=>{c(`center`),r()},"aria-label":`Align center`,className:Y(`flex-1 flex items-center justify-center p-1.5 border rounded-none-none transition-all`,n===`dark`?`border-z-border hover:border-z-border/30 hover:bg-z-hover text-z-muted hover:text-z-secondary`:`border-z-border hover:border-z-border hover:bg-[var(--z-bg-input)] text-z-secondary hover:text-z-secondary`),children:(0,Q.jsx)(Oe,{size:13,"aria-hidden":`true`})}),(0,Q.jsx)(`button`,{onClick:()=>{c(`right`),r()},"aria-label":`Align right`,className:Y(`flex-1 flex items-center justify-center p-1.5 border rounded-none-none transition-all`,n===`dark`?`border-z-border hover:border-z-border/30 hover:bg-z-hover text-z-muted hover:text-z-secondary`:`border-z-border hover:border-z-border hover:bg-[var(--z-bg-input)] text-z-secondary hover:text-z-secondary`),children:(0,Q.jsx)(D,{size:13,"aria-hidden":`true`})})]}),(0,Q.jsx)(`div`,{className:Y(`h-px my-1`,n===`dark`?`bg-z-hover`:`bg-[var(--z-bg-hover)]`)}),(0,Q.jsxs)(`button`,{onClick:()=>{a(),r()},className:Y(`w-full flex items-center gap-2 px-3 py-2 text-left text-xs font-semibold rounded-none-none transition-colors`,n===`dark`?`hover:bg-rose-500/10 text-rose-400`:`hover:bg-rose-50 text-rose-600`),children:[(0,Q.jsx)(o,{size:13,className:`text-rose-500`}),`Delete Section`]})]})})},yt=`zenith_editor_state`,bt=1200,xt=()=>{try{let e=localStorage.getItem(yt);if(!e)return null;let t=JSON.parse(e);if(t&&typeof t==`object`)return{data:t.data||t,undoStack:Array.isArray(t.undoStack)?t.undoStack:[],redoStack:Array.isArray(t.redoStack)?t.redoStack:[]}}catch{}return null},St=e=>typeof structuredClone==`function`?structuredClone(e):JSON.parse(JSON.stringify(e)),Ct=0,wt=xt(),Tt=(e,t)=>({data:wt?wt.data:null,loading:!1,saving:!1,hasUnsavedChanges:!1,lastSavedAt:null,undoStack:wt?wt.undoStack:[],redoStack:wt?wt.redoStack:[],dirtySections:new Set,schemaFields:[],fieldSettings:{},fieldErrors:{},history:[],templates:[],topLevelFields:[],setData:t=>e({data:t}),setLoading:t=>e({loading:t}),setSaving:t=>e({saving:t}),setHasUnsavedChanges:t=>e({hasUnsavedChanges:t}),setLastSavedAt:t=>e({lastSavedAt:t}),setSchemaFields:t=>e({schemaFields:t}),setFieldSettings:t=>e({fieldSettings:t}),setFieldErrors:t=>e({fieldErrors:t}),setHistory:t=>e({history:t}),setTemplates:t=>e({templates:t}),setTopLevelFields:t=>e({topLevelFields:t}),updateData:n=>{let r=t().data;if(!r)return;let i=rt(r,e=>{let t=n(e);t!==void 0&&Object.assign(e,t)});e(e=>{let t=Date.now(),n=t-Ct>bt,a=n?[...e.undoStack.slice(-199),r]:e.undoStack;n&&(Ct=t);let o=new Set(e.dirtySections);return i.sections.forEach(e=>o.add(e.id)),{data:i,hasUnsavedChanges:!0,undoStack:a,redoStack:[],dirtySections:o}})},setField:(n,r,i)=>{let a;try{a=t().data}catch{return}if(!a)return;let o=Date.now(),s=o-Ct>bt,c=s?[...t().undoStack.slice(-199),St(a)]:t().undoStack;s&&(Ct=o);let l=a.sections.map(e=>e.id!==n||e.content[r]===i?e:{...e,content:{...e.content,[r]:i}}),u={...a,sections:l},d=new Set(t().dirtySections);d.add(n),e({data:u,hasUnsavedChanges:!0,undoStack:c,redoStack:[],dirtySections:d})},undo:()=>{let{data:n,undoStack:r,redoStack:i}=t();if(!n||r.length===0)return;let a=r[r.length-1],o=r.slice(0,-1),s=St(n);e({data:a,undoStack:o,redoStack:[...i.slice(-199),s],hasUnsavedChanges:!0})},redo:()=>{let{data:n,undoStack:r,redoStack:i}=t();if(!n||i.length===0)return;let a=i[i.length-1],o=i.slice(0,-1),s=St(n);e({data:a,undoStack:[...r.slice(-199),s],redoStack:o,hasUnsavedChanges:!0})},load:async(t,n,r)=>{e({data:null,loading:!0,undoStack:[],redoStack:[],hasUnsavedChanges:!1});try{let i=r?await q.get(`/globals/${n}`):await q.get(`/${t}/${n}`),a=(i.data.data.sections||[]).map((e,t)=>({...e,id:e.id||`node_${t+1}`,content:e.content||e.blockData})),o={...i.data.data,sections:a};return e({data:o,activeSection:`root`}),o}finally{e({loading:!1})}},save:async(n,r,i,a)=>{let{data:o}=t();if(o){e({saving:!0});try{let t=a(o),s=(i?await q.patch(`/globals/${r}`,t):await q.patch(`/${n}/${r}`,t)).data?.data?._version;e(s===void 0?{hasUnsavedChanges:!1,dirtySections:new Set}:{data:{...o,_version:s},hasUnsavedChanges:!1,dirtySections:new Set})}finally{e({saving:!1})}}}}),Et=e=>({activeSection:`root`,selectedField:null,selectedFieldId:null,setActiveSection:t=>e({activeSection:t}),setSelectedField:t=>e({selectedField:t}),setSelectedFieldId:t=>e({selectedFieldId:t})}),Dt=e=>({mediaAssets:[],mediaSearch:``,mediaTypeFilter:`all`,mediaLoading:!1,setMediaAssets:t=>e({mediaAssets:t}),setMediaSearch:t=>e({mediaSearch:t}),setMediaTypeFilter:t=>e({mediaTypeFilter:t}),setMediaLoading:t=>e({mediaLoading:t})}),Ot=e=>({relationsField:null,relationsSearch:``,relationResults:[],selectedRelations:new Set,availableCollections:[],setRelationsField:t=>e({relationsField:t}),setRelationsSearch:t=>e({relationsSearch:t}),setRelationResults:t=>e({relationResults:t}),setSelectedRelations:t=>e({selectedRelations:t}),setAvailableCollections:t=>e({availableCollections:t})}),$=Fe((e,t,n)=>({...Tt(e,t,n),...Et(e,t,n),...Dt(e,t,n),...Ot(e,t,n),reset:()=>{try{localStorage.removeItem(yt)}catch{}e({data:null,loading:!1,saving:!1,hasUnsavedChanges:!1,lastSavedAt:null,undoStack:[],redoStack:[],dirtySections:new Set,activeSection:`root`,selectedField:null,fieldErrors:{},relationsField:null,relationsSearch:``,relationResults:[],selectedRelations:new Set,mediaAssets:[],mediaSearch:``,mediaTypeFilter:`all`,mediaLoading:!1})}})),kt=Fe(e=>({leftOpen:!0,rightOpen:!0,leftWidth:300,rightWidth:420,activeRightTab:`preview`,viewMode:`visual`,previewMode:`desktop`,focusMode:!1,setLeftOpen:t=>e({leftOpen:t}),setRightOpen:t=>e({rightOpen:t}),setLeftWidth:t=>e({leftWidth:t}),setRightWidth:t=>e({rightWidth:t}),setActiveRightTab:t=>e({activeRightTab:t}),setViewMode:t=>e({viewMode:t}),setPreviewMode:t=>e({previewMode:t}),toggleFocusMode:()=>e(e=>({focusMode:!e.focusMode}))})),At=({isGlobal:e,resizingSide:t,startResizing:n,addBlock:r,setInjectionIndex:i,setBlockPickerOpen:a,removeSection:s})=>{let{theme:c}=K(),l=st(),[u,d]=(0,Z.useState)(``),{data:p,activeSection:m,setActiveSection:g,updateData:_}=$(W(e=>({data:e.data,activeSection:e.activeSection,setActiveSection:e.setActiveSection,updateData:e.updateData}))),{leftOpen:v,leftWidth:y,setLeftOpen:b,focusMode:x}=kt(W(e=>({leftOpen:e.leftOpen,leftWidth:e.leftWidth,setLeftOpen:e.setLeftOpen,focusMode:e.focusMode}))),S=m??`root`,C=u.trim().length>0,w=(0,Z.useMemo)(()=>{let e=p?.sections||[];if(!C)return e;let t=u.toLowerCase();return e.filter(e=>(e.blockName||e.title||X(e.blockType)).toLowerCase().includes(t)||e.blockType.toLowerCase().includes(t))},[p?.sections,u,C]),T=e=>{if(C)return;let t=new Set(p?.sections.map(e=>e.id));e.every(e=>t.has(e.id))&&_(t=>{t.sections=e})},E=e=>l.find(t=>t.type===e)?.icon||f,D=c===`dark`;return(0,Q.jsx)(H,{children:v&&!x&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:()=>b(!1),className:`md:hidden fixed inset-0 bg-app/50 backdrop-blur-sm z-[99]`}),(0,Q.jsxs)(G.aside,{initial:{x:`-100%`},animate:{x:0},exit:{x:`-100%`},transition:{type:`spring`,damping:25,stiffness:200},style:{width:y},className:Y(`border-r flex flex-col z-50 overflow-hidden shrink-0 h-full`,`md:relative fixed inset-y-0 left-0 max-md:!w-[280px] max-md:z-[100] max-md:shadow-2xl`,D?`bg-app border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsx)(`div`,{onMouseDown:n(`left`),className:Y(`absolute right-0 top-0 bottom-0 w-1 cursor-col-resize z-50 transition-colors`,t===`left`?`bg-z-border`:`bg-transparent hover:bg-z-hover`)}),(0,Q.jsxs)(`div`,{className:Y(`px-3 py-3 border-b flex items-center justify-between`,D?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-muted`,children:`Layers`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{onClick:()=>{i(0),a(!0)},className:Y(`p-1 rounded-none-none border transition-all text-z-muted hover:text-z-secondary `,D?`bg-z-hover border-z-border`:`bg-z-input border-z-border`),"aria-label":`Add new section`,title:`Add section`,children:(0,Q.jsx)(M,{size:14})}),(0,Q.jsx)(`button`,{onClick:()=>b(!1),className:`md:hidden p-1 rounded-none-none border transition-all text-z-muted hover:text-rose-500`,"aria-label":`Close layers panel`,children:(0,Q.jsx)(B,{size:14})})]})]}),(p?.sections?.length||0)>3&&(0,Q.jsx)(`div`,{className:`px-3 pt-2 pb-1`,children:(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(h,{size:11,className:Y(`absolute left-2.5 top-1/2 -translate-y-1/2`,D?`text-z-secondary`:`text-z-muted`)}),(0,Q.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:`Filter layers...`,className:Y(`w-full pl-7 pr-7 py-1.5 text-xs font-bold border rounded-none-none bg-transparent transition-all`,`border-z-border text-z-primary placeholder:text-z-muted focus:border-z-border/30`),"aria-label":`Filter layers`}),u&&(0,Q.jsx)(`button`,{onClick:()=>d(``),className:Y(`absolute right-2 top-1/2 -translate-y-1/2 p-0.5`,D?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`),"aria-label":`Clear filter`,children:(0,Q.jsx)(B,{size:10})})]})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto custom-editor-scrollbar px-2 pt-3 pb-4 space-y-2`,children:w.length===0?(0,Q.jsx)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-center px-4`,children:p?.sections?.length===0?(0,Q.jsx)(_t,{icon:f,title:`No sections yet`,message:`Add your first section to start building`}):(0,Q.jsx)(_t,{icon:h,title:`No matches`,message:`Try a different search term`})}):C?(0,Q.jsx)(`div`,{className:`space-y-1`,children:w.map(e=>{let t=E(e.blockType);return(0,Q.jsxs)(`button`,{onClick:()=>g(e.id),className:Y(`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-none-none border text-left transition-all`,S===e.id?D?`bg-z-panel border-z-border text-z-primary`:`bg-[var(--z-active-bg)] text-[var(--z-active-text)] border border-[var(--z-active-border)] shadow-sm`:D?`bg-z-hover border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`:`bg-z-panel border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)] hover:text-z-primary`),"aria-label":`Select section: ${e.blockName||e.title||X(e.blockType)}`,children:[(0,Q.jsx)(t,{size:12,className:Y(`shrink-0`,S===e.id?``:D?`text-z-muted/60`:`text-z-secondary/60`)}),(0,Q.jsx)(`span`,{className:`text-xs font-semibold truncate flex-1`,children:e.blockName||e.title||X(e.blockType)}),e.blockType!==X(e.blockType)&&(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold shrink-0`,S===e.id?`opacity-60`:D?`text-z-secondary`:`text-z-muted`),children:X(e.blockType)})]},e.id)})}):(0,Q.jsx)(qe,{axis:`y`,values:p?.sections||[],onReorder:T,className:`space-y-1`,as:`div`,children:(p?.sections||[]).map(e=>{let t=E(e.blockType);return(0,Q.jsx)(V,{value:e,as:`div`,children:(0,Q.jsx)(`div`,{className:`w-full flex items-center gap-0`,children:(0,Q.jsxs)(`div`,{onClick:()=>g(e.id),className:Y(`flex-1 flex items-center gap-2.5 px-2.5 py-2 rounded-none-none border text-left transition-all cursor-pointer`,S===e.id?D?`bg-z-panel border-z-border text-z-primary`:`bg-[var(--z-active-bg)] text-[var(--z-active-text)] border border-[var(--z-active-border)] shadow-sm`:D?`bg-z-hover border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`:`bg-z-panel border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)] hover:text-z-primary`),"aria-label":`Select section: ${e.blockName||e.title||X(e.blockType)}`,children:[(0,Q.jsx)(Ee,{size:12,className:`opacity-30 shrink-0 cursor-grab active:cursor-grabbing`,"aria-hidden":`true`}),(0,Q.jsx)(t,{size:12,className:Y(`shrink-0`,S===e.id?``:D?`text-z-muted/60`:`text-z-secondary/60`),"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`text-xs font-semibold truncate flex-1`,children:e.blockName||e.title||X(e.blockType)}),e.blockType!==X(e.blockType)&&(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold shrink-0`,S===e.id?D?`text-z-muted/80`:`text-z-secondary/80`:`text-z-muted`),children:X(e.blockType)}),(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),s(e.id)},className:Y(`p-1 shrink-0 rounded-none opacity-0 group-hover:opacity-100 transition-opacity ml-1`,D?`hover:bg-rose-500/20 text-rose-500/70 hover:text-rose-500`:`hover:bg-rose-100 text-rose-500/70 hover:text-rose-600`),"aria-label":`Delete layer`,children:(0,Q.jsx)(o,{size:12})})]})})},e.id)})})})]})]})})},jt={siteId:`activeSiteId`,siteSlug:`activeSiteSlug`,siteDomain:`activeSiteDomain`,workspaceId:`activeWorkspaceId`},Mt=[`/login`,`/select-site`,`/sites`,`/auth`];function Nt(){return typeof window>`u`?!0:Mt.some(e=>window.location.pathname.startsWith(e))}function Pt(){let{activeSiteId:e,activeWorkspaceId:t,setActiveSiteId:n,setActiveWorkspaceId:r}=mt(W(e=>({activeSiteId:e.activeSiteId,activeWorkspaceId:e.activeWorkspaceId,setActiveSiteId:e.setActiveSiteId,setActiveWorkspaceId:e.setActiveWorkspaceId}))),i=e=>{try{return localStorage.getItem(e)||``}catch{return``}},a=(e,t)=>{try{localStorage.setItem(e,t)}catch{}},o=e=>{try{localStorage.removeItem(e)}catch{}},s=e||i(jt.siteId);return{siteId:s,siteSlug:i(jt.siteSlug),siteDomain:i(jt.siteDomain),workspaceId:t||i(jt.workspaceId),requireSiteId:(0,Z.useCallback)(()=>{if(s)return s;if(Nt())return``;throw Object.assign(Error(`Tenant context is required but activeSiteId is missing. Navigate to Site Selection to choose an active site.`),{code:`ERR_NO_TENANT`})},[s]),setSite:(0,Z.useCallback)((e,t,r)=>{n(e),J.getState().setActiveSiteId(e),t&&a(jt.siteSlug,t),r&&a(jt.siteDomain,r)},[n]),clearSite:(0,Z.useCallback)(()=>{n(null),J.getState().setActiveSiteId(null),o(jt.siteSlug),o(jt.siteDomain)},[n]),setWorkspace:(0,Z.useCallback)(e=>{r(e)},[r])}}var Ft=Fe((e,t)=>({comments:[],loading:!1,posting:!1,activeCommentId:null,setActiveCommentId:t=>e({activeCommentId:t}),fetchComments:async(t,n)=>{e({comments:[],loading:!0});try{e({comments:(await q.get(`/comments`,{params:{collection:t,documentId:n}})).data.data||[]})}catch{e({comments:[]})}finally{e({loading:!1})}},createComment:async({collection:t,documentId:n,blockId:r,fieldKey:i,content:a})=>{e({posting:!0});try{let o=await q.post(`/comments`,{collection:t,documentId:n,blockId:r,fieldKey:i,content:a});e(e=>({comments:[o.data.data,...e.comments]}))}finally{e({posting:!1})}},replyToComment:async(t,n)=>{e({posting:!0});try{let r=await q.post(`/comments/${t}/reply`,{content:n});e(e=>({comments:e.comments.map(e=>e._id===t?r.data.data:e)}))}finally{e({posting:!1})}},resolveComment:async(t,n)=>{try{let r=await q.patch(`/comments/${t}`,{resolved:n});e(e=>({comments:e.comments.map(e=>e._id===t?r.data.data:e)}))}catch{U.error(`Failed to update comment`)}},deleteComment:async t=>{try{await q.delete(`/comments/${t}`),e(e=>({comments:e.comments.filter(e=>e._id!==t)}))}catch{U.error(`Failed to delete comment`)}}}));function It(e){let t=Date.now(),n=new Date(e).getTime(),r=Math.floor((t-n)/1e3);return r<60?`${r}s ago`:r<3600?`${Math.floor(r/60)}m ago`:r<86400?`${Math.floor(r/3600)}h ago`:`${Math.floor(r/86400)}d ago`}var Lt=({comment:e,onResolve:t,onReply:n,onDelete:r,posting:i,theme:a,currentUserId:s})=>{let[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(!0),m=e.authorId===s,h=()=>{u.trim()&&(n(e._id,u),d(``),l(!1))};return(0,Q.jsxs)(G.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-2},className:Y(`border rounded-none-none overflow-hidden`,e.resolved?a===`dark`?`border-z-border/10 bg-z-border/[0.03]`:`border-z-border bg-[var(--z-bg-input)]/50`:`border-z-border bg-z-panel`),children:[(0,Q.jsxs)(`div`,{className:`px-3 py-2.5 flex items-start gap-2.5`,children:[(0,Q.jsx)(`div`,{className:Y(`w-7 h-7 rounded-none-none flex items-center justify-center shrink-0 mt-0.5`,a===`dark`?`bg-z-panel border border-z-border/20`:`bg-[var(--z-bg-input)] border border-z-border`),children:(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:e.author?.[0]||`?`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:e.author}),(0,Q.jsx)(`span`,{className:`text-sm text-z-secondary font-bold`,children:It(e.createdAt)}),e.resolved&&(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold px-1.5 py-0.5 rounded-none-none`,a===`dark`?`bg-z-panel/5 text-z-secondary`:`bg-[var(--z-bg-hover)] text-z-secondary`),children:`Resolved`}),e.blockId&&(0,Q.jsxs)(`span`,{className:Y(`text-sm font-mono px-1 py-0.5 rounded-none-none`,a===`dark`?`bg-amber-500/10 text-amber-400`:`bg-amber-50 text-amber-600`),children:[`Block: `,e.blockId]})]}),(0,Q.jsx)(`p`,{className:Y(`text-xs leading-relaxed font-medium mt-1`,e.resolved?` text-z-secondary`:`text-z-secondary`),children:e.content})]})]}),e.replies?.length>0&&(0,Q.jsxs)(`div`,{className:Y(`border-t`,a===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsxs)(`button`,{onClick:()=>p(e=>!e),className:Y(`w-full flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold transition-colors`,a===`dark`?`text-z-secondary hover:text-z-secondary`:`text-z-muted hover:text-z-secondary`),children:[(0,Q.jsx)(Ve,{size:8}),e.replies.length,` `,e.replies.length===1?`reply`:`replies`,f?(0,Q.jsx)(Ce,{size:8,className:`ml-auto`}):(0,Q.jsx)(We,{size:8,className:`ml-auto`})]}),(0,Q.jsx)(H,{initial:!1,children:f&&(0,Q.jsx)(G.div,{initial:{height:0},animate:{height:`auto`},exit:{height:0},transition:{duration:.15},className:`overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`px-3 pb-2 space-y-2`,children:e.replies.map((e,t)=>(0,Q.jsx)(`div`,{className:Y(`flex gap-2 pl-3 border-l-2`,a===`dark`?`border-z-border/20`:`border-z-border`),children:(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-muted`,children:e.author}),(0,Q.jsx)(`span`,{className:`text-sm text-z-secondary`,children:It(e.createdAt)})]}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-medium`,children:e.content})]})},t))})})})]}),(0,Q.jsxs)(`div`,{className:Y(`px-3 py-1.5 border-t flex items-center gap-3`,a===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsxs)(`button`,{onClick:()=>l(e=>!e),className:Y(`flex items-center gap-1 text-xs font-semibold transition-colors`,a===`dark`?`text-z-secondary hover:text-z-secondary`:`text-z-muted hover:text-z-secondary`),children:[(0,Q.jsx)(Ve,{size:9}),`Reply`]}),(0,Q.jsxs)(`button`,{onClick:()=>t(e._id,!e.resolved),className:Y(`flex items-center gap-1 text-xs font-semibold transition-colors`,e.resolved?a===`dark`?`text-z-secondary hover:text-z-secondary`:`text-z-secondary hover:text-z-secondary`:a===`dark`?`text-z-muted/50 hover:text-z-secondary`:`text-z-secondary hover:text-z-secondary `),children:[e.resolved?(0,Q.jsx)(ke,{size:9}):(0,Q.jsx)(z,{size:9}),e.resolved?`Reopen`:`Resolve`]}),m&&(0,Q.jsxs)(`button`,{onClick:()=>r(e._id),className:Y(`flex items-center gap-1 text-xs font-semibold transition-colors ml-auto`,a===`dark`?`text-z-secondary hover:text-rose-400`:`text-z-muted hover:text-rose-500`),children:[(0,Q.jsx)(o,{size:9}),`Delete`]})]}),(0,Q.jsx)(H,{initial:!1,children:c&&(0,Q.jsx)(G.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:`overflow-hidden`,children:(0,Q.jsxs)(`div`,{className:Y(`px-3 py-2 border-t flex gap-2`,a===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`input`,{autoFocus:!0,type:`text`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>e.key===`Enter`&&h(),placeholder:`Write a reply...`,className:Y(`flex-1 px-2.5 py-1.5 text-xs rounded-none-none border transition-all`,a===`dark`?`bg-z-hover border-z-border text-z-primary placeholder:text-z-muted focus:border-z-border/50`:`bg-z-input border-z-border text-z-primary placeholder:text-z-muted focus:border-z-border-strong`)}),(0,Q.jsx)(`button`,{onClick:h,disabled:i||!u.trim(),"aria-label":`Send reply`,className:Y(`px-2.5 py-1.5 text-xs font-semibold border transition-all rounded-none-none disabled:opacity-50`,a===`dark`?`bg-z-hover border-z-border-strong border-z-border/20 text-z-secondary hover:bg-z-border/30`:`bg-z-input border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`),children:(0,Q.jsx)(te,{size:10,"aria-hidden":`true`})}),(0,Q.jsx)(`button`,{onClick:()=>{l(!1),d(``)},"aria-label":`Cancel reply`,className:Y(`px-2 py-1.5 text-xs font-semibold border rounded-none-none`,a===`dark`?`border-z-border text-z-secondary`:`border-z-border text-z-muted`),children:(0,Q.jsx)(B,{size:10,"aria-hidden":`true`})})]})})})]})},Rt=({collection:e,documentId:t,theme:n})=>{let{comments:r,loading:i,posting:a,fetchComments:o,createComment:s,replyToComment:c,resolveComment:l,deleteComment:u}=Ft(W(e=>({comments:e.comments,loading:e.loading,posting:e.posting,fetchComments:e.fetchComments,createComment:e.createComment,replyToComment:e.replyToComment,resolveComment:e.resolveComment,deleteComment:e.deleteComment}))),{user:d}=ht(W(e=>({user:e.user}))),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{o(e,t)},[e,t]);let g=()=>{f.trim()&&(s({collection:e,documentId:t,content:f}),p(``))};r.length;let _=m?r:r.filter(e=>!e.resolved);return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(pe,{size:11,className:`text-z-secondary`}),(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:`Review`}),(0,Q.jsxs)(`span`,{className:Y(`px-1.5 py-0.5 text-sm font-semibold rounded-none-none`,n===`dark`?`bg-z-hover text-z-secondary`:`bg-[var(--z-bg-hover)] text-z-secondary`),children:[r.filter(e=>!e.resolved).length,` open / `,r.length,` total`]})]}),(0,Q.jsx)(`button`,{onClick:()=>h(e=>!e),className:Y(`text-xs font-semibold transition-colors`,n===`dark`?`text-z-secondary hover:text-z-secondary`:`text-z-muted hover:text-z-secondary`),children:m?`Hide resolved`:`Show resolved`})]}),(0,Q.jsxs)(`div`,{className:Y(`border rounded-none-none p-2.5`,n===`dark`?`border-z-border bg-z-panel`:`border-z-border bg-[var(--z-bg-input)]/50`),children:[(0,Q.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&g()},placeholder:`Add a comment... (Cmd+Enter to submit)`,rows:2,className:Y(`w-full px-2 py-1.5 text-xs rounded-none-none border-none bg-transparent resize-none focus:outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black focus:ring-0 placeholder:text-z-muted`,n===`dark`?`text-z-secondary placeholder:text-z-muted`:`text-z-primary placeholder:text-z-muted`)}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mt-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm text-z-secondary font-bold`,children:`Cmd+Enter to submit`}),(0,Q.jsxs)(`button`,{onClick:g,disabled:a||!f.trim(),className:Y(`flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold border rounded-none-none transition-all disabled:opacity-50`,n===`dark`?`bg-z-hover border-z-border-strong border-z-border/30 text-z-secondary hover:bg-z-border/30 hover:border-z-border/50`:`bg-z-input border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)] hover:border-z-border-strong`),children:[(0,Q.jsx)(pe,{size:9}),`Comment`]})]})]}),i?(0,Q.jsxs)(`div`,{className:`text-center py-4`,children:[(0,Q.jsx)(`div`,{className:Y(`w-4 h-4 border-2 border-z-border border-t-transparent rounded-none-none animate-spin mx-auto mb-2`)}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-bold`,children:`Loading comments...`})]}):_.length===0?(0,Q.jsxs)(`div`,{className:Y(`py-5 text-center border border-dashed rounded-none-none`,`border-z-border`),children:[(0,Q.jsx)(pe,{size:16,className:`mx-auto text-z-secondary mb-1.5`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-bold`,children:`No comments yet`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary mt-0.5`,children:`Be the first to leave a review note`})]}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:(0,Q.jsx)(H,{initial:!1,children:_.map(e=>(0,Q.jsx)(Lt,{comment:e,onResolve:l,onReply:c,onDelete:u,posting:a,theme:n,currentUserId:d?.id},e._id))})})]})},zt={desktop:{width:1440,height:900,icon:le},tablet:{width:768,height:1024,icon:De},mobile:{width:375,height:812,icon:k}},Bt=({isGlobal:e=!1,resizingSide:t,startResizing:n,iframeRef:r,handleRestore:i,onCompareDiff:o})=>{let{id:s,slug:l}=xe(),u=s||l,{theme:d}=K(),{history:f,data:p,availableCollections:m}=$(W(e=>({history:e.history,data:e.data,availableCollections:e.availableCollections}))),{rightOpen:h,rightWidth:g,activeRightTab:_,setActiveRightTab:v,setRightOpen:y,previewMode:b,setPreviewMode:x,focusMode:S}=kt(W(e=>({rightOpen:e.rightOpen,rightWidth:e.rightWidth,activeRightTab:e.activeRightTab,setActiveRightTab:e.setActiveRightTab,setRightOpen:e.setRightOpen,previewMode:e.previewMode,setPreviewMode:e.setPreviewMode,focusMode:e.focusMode}))),{siteId:C,siteSlug:w,siteDomain:T}=Pt(),[E,D]=Z.useState([]),[O,k]=Z.useState(null),A=e?`globals`:l||`pages`;Z.useEffect(()=>{q.get(`/sites`).then(e=>{D(e.data?.data||[])}).catch(()=>{U.error(`Failed to load sites`)})},[]),Z.useEffect(()=>{(async()=>{if(!(!u||u===`new`)&&A!==`globals`)try{k((await q.post(`/${A}/${u}/preview-token`)).data.data?.token||null)}catch{}})()},[A,u]);let j=p?.siteId,M=j&&E.some(e=>(e._id||e.id)===j)?j:C||``,ee=E.find(e=>(e._id||e.id)===M),N=ee?ee.domain:`http://localhost:5177`,P=``;N&&N.trim()!==``&&(P=N.startsWith(`http`)?N:`http://${N}`);let F=(m?.find(e=>e.slug===A))?.admin?.previewUrl,I=``;typeof F==`string`?I=F.replace(/{{storefrontUrl}}/g,P).replace(/{{previewToken}}/g,O||``).replace(/{{id}}/g,u||``).replace(/{{slug}}/g,p?.slug||u||``).replace(/{{siteId}}/g,M).replace(/{{viewport}}/g,b).replace(/{{collection}}/g,A):P&&(I=`${P}${A===`posts`?`/post/preview`:``}?preview=true&token=${O||``}&collection=${A}&id=${u}&siteId=${M}&viewport=${b}`);let te=[{id:`preview`,icon:a,label:`Live`},{id:`history`,icon:c,label:`Versions`},{id:`comments`,icon:pe,label:`Review`}],ne=zt[b]||zt.desktop,re=b===`desktop`,L=d===`dark`;return(0,Q.jsx)(H,{initial:!1,children:h&&!S&&(0,Q.jsxs)(G.aside,{initial:{width:0,opacity:0},animate:{width:g,opacity:1},exit:{width:0,opacity:0},className:Y(`border-l flex flex-col z-50 overflow-hidden shrink-0`,`md:relative fixed inset-y-0 right-0 max-md:!w-[280px] max-md:z-[100] max-md:shadow-2xl`,L?`bg-app border-z-border`:`bg-z-panel border-z-border shadow-xl`),children:[(0,Q.jsx)(`div`,{onClick:()=>y(!1),className:`md:hidden fixed inset-0 bg-app/50 backdrop-blur-sm z-[99]`}),(0,Q.jsx)(`div`,{onMouseDown:n(`right`),className:Y(`absolute left-0 top-0 bottom-0 w-1 cursor-col-resize z-50 transition-colors`,t===`right`?`bg-z-border shadow-sm`:`bg-transparent hover:bg-z-hover`)}),(0,Q.jsxs)(`div`,{className:Y(`px-3 py-2 border-b flex items-center justify-between shrink-0`,L?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-4`,children:te.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>v(e.id),className:Y(`flex flex-col transition-all`,_===e.id?`opacity-100`:`opacity-40 hover:opacity-100`),"aria-label":e.label,children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-semibold `,_===e.id?`text-z-primary`:L?`text-z-secondary`:`text-z-muted`),children:e.label}),(0,Q.jsx)(`div`,{className:`h-0.5 w-full mt-1`,style:{backgroundColor:_===e.id?`var(--z-accent)`:`transparent`}})]},e.id))}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>y(!1),className:`p-1 hover:text-z-secondary transition-colors`,"aria-label":`Close panel`,children:(0,Q.jsx)(B,{size:16})})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-hidden relative custom-editor-scrollbar`,children:_===`preview`?(0,Q.jsxs)(`div`,{className:`w-full h-full flex flex-col`,children:[(0,Q.jsx)(`div`,{className:Y(`flex items-center justify-center gap-1 px-3 py-2 border-b shrink-0`,L?`border-z-border`:`border-z-border shadow-sm`),children:[`desktop`,`tablet`,`mobile`].map(e=>{let t=zt[e],n=t.icon;return(0,Q.jsxs)(`button`,{onClick:()=>x(e),className:Y(`flex items-center gap-1.5 px-2.5 py-1 rounded-none-none border text-sm font-semibold transition-all`,b===e?L?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-panel shadow-sm border border-z-border text-z-primary`:L?`bg-z-hover border-z-border text-z-secondary hover:text-z-secondary`:`bg-z-panel border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)] hover:text-z-primary`),"aria-label":`${e} preview`,title:`${e} (${t.width}×${t.height})`,children:[(0,Q.jsx)(n,{size:11}),e]},e)})}),(0,Q.jsx)(`div`,{className:`flex-1 flex items-center justify-center overflow-auto p-3`,children:I?(0,Q.jsx)(`div`,{className:Y(`transition-all duration-300 border overflow-hidden`,L?`border-z-border bg-[#030303] shadow-[0_0_40px_rgba(0,0,0,0.5)]`:`border-z-border bg-z-panel shadow-2xl`,re?`w-full h-full`:`rounded-none-none`),style:re?void 0:{width:Math.min(ne.width,g-40),height:ne.height},children:(0,Q.jsx)(`iframe`,{allow:`clipboard-read; clipboard-write`,ref:r,src:I,className:`w-full h-full border-none rounded-none-none`,title:`Live Preview`,sandbox:`allow-same-origin allow-scripts allow-forms`})}):(0,Q.jsxs)(`div`,{className:Y(`flex flex-col items-center justify-center h-full gap-3 text-center p-8`,L?`bg-[#0a0a0a]`:`bg-[var(--z-bg-input)]`),children:[(0,Q.jsx)(a,{size:28,className:`text-z-secondary`}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:Y(`text-xs font-semibold `,`text-z-secondary`),children:`Preview unavailable`}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-bold`,L?`text-z-primary`:`text-z-secondary`),children:P?`Preview URL is not configured for this collection.`:`Set VITE_STOREFRONT_URL to enable live preview`})]})]})})]}):_===`comments`?(0,Q.jsx)(`div`,{className:`w-full h-full p-3 overflow-y-auto custom-editor-scrollbar`,children:(0,Q.jsx)(Rt,{collection:e?`globals`:`pages`,documentId:u||``,theme:d})}):(0,Q.jsx)(`div`,{className:`w-full h-full p-3 overflow-y-auto custom-editor-scrollbar`,children:f.length===0?(0,Q.jsx)(`div`,{className:`flex flex-col h-full justify-center`,children:(0,Q.jsx)(_t,{icon:c,title:`No versions yet`,message:`Save your page to create a version snapshot`})}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:f.map((e,t)=>(0,Q.jsxs)(`div`,{className:Y(`group p-4 rounded-none-none border transition-all cursor-pointer space-y-2`,L?`bg-z-panel/5 border-z-border hover:bg-[var(--z-bg-hover)]`:`bg-z-input border-z-border hover:bg-[var(--z-bg-hover)]`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-semibold `,`text-z-primary`),children:t===0?`Current`:`V.${f.length-t}`}),(0,Q.jsx)(`span`,{className:`text-xs font-bold text-z-secondary`,children:new Date(e.createdAt).toLocaleDateString()})]}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-medium truncate`,children:e.changeLog||`Saved`}),t>0&&(0,Q.jsxs)(`div`,{className:`flex gap-1.5 opacity-0 group-hover:opacity-100 transition-all mt-1.5`,children:[(0,Q.jsx)(`button`,{onClick:n=>{n.stopPropagation(),o(e._id,f.length-t)},className:Y(`flex-1 py-1 border text-xs font-semibold text-center transition-all`,L?`bg-z-hover border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)] hover:text-z-primary`:`bg-[var(--z-bg-hover)] border-z-border text-z-primary hover:bg-[var(--z-border)] hover:text-z-primary`),children:`Compare`}),(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e._id)},className:`flex-1 py-1 bg-z-accent hover:bg-z-border text-z-primary text-xs font-semibold text-center transition-all`,children:`Restore`})]})]},e._id||e.id))})})})]})})},Vt=de(),Ht=({imageUrl:e,initialX:t=50,initialY:n=50,onSave:r})=>{let[i,a]=(0,Z.useState)({x:t,y:n}),o=(0,Z.useRef)(null);return(0,Q.jsxs)(`div`,{style:{backgroundColor:`rgba(17, 24, 39, 0.65)`,backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`,border:`1px solid rgba(255, 255, 255, 0.08)`,borderRadius:`12px`,boxShadow:`0 4px 30px rgba(0, 0, 0, 0.1)`,padding:`24px`,maxWidth:`500px`,width:`100%`,margin:`0 auto`,fontFamily:`'Inter', sans-serif`,color:`#F3F4F6`},children:[(0,Q.jsx)(`h3`,{style:{fontSize:`18px`,fontWeight:600,marginBottom:`8px`,color:`#F3F4F6`,letterSpacing:`-0.025em`},children:`AI Focal Point & Responsive Cropper`}),(0,Q.jsx)(`p`,{style:{fontSize:`13px`,color:`#9CA3AF`,marginBottom:`16px`,lineHeight:`1.4`},children:`Click anywhere on the image preview to set the focal focus coordinates. The storefront background positioning will dynamically scale around this center point.`}),(0,Q.jsxs)(`div`,{ref:o,onClick:e=>{if(!o.current)return;let t=o.current.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top,i=Math.round(n/t.width*100),s=Math.round(r/t.height*100);a({x:Math.max(0,Math.min(100,i)),y:Math.max(0,Math.min(100,s))})},style:{position:`relative`,width:`100%`,height:`260px`,borderRadius:`8px`,overflow:`hidden`,cursor:`crosshair`,border:`1.5px dashed rgba(255, 255, 255, 0.15)`,background:`#0B0F19`},children:[(0,Q.jsx)(`img`,{src:e,alt:`Salient Crop Preview`,style:{width:`100%`,height:`100%`,objectFit:`cover`,userSelect:`none`,opacity:.8}}),(0,Q.jsx)(`div`,{style:{position:`absolute`,left:`${i.x}%`,top:`${i.y}%`,transform:`translate(-50%, -50%)`,width:`28px`,height:`28px`,borderRadius:`50%`,border:`2.5px solid var(--z-accent)`,boxShadow:`0 0 12px var(--z-accent), inset 0 0 4px var(--z-accent)`,pointerEvents:`none`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`left 0.15s cubic-bezier(0.25, 0.8, 0.25, 1), top 0.15s cubic-bezier(0.25, 0.8, 0.25, 1)`},children:(0,Q.jsx)(`div`,{style:{width:`6px`,height:`6px`,borderRadius:`50%`,backgroundColor:`var(--z-accent)`}})})]}),(0,Q.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginTop:`16px`,fontSize:`12px`,color:`#9CA3AF`},children:[(0,Q.jsxs)(`div`,{children:[`Focus Position:`,` `,(0,Q.jsxs)(`span`,{style:{color:`var(--z-accent)`,fontWeight:600},children:[`X: `,i.x,`%, Y: `,i.y,`%`]})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{r&&r(i.x,i.y)},style:{backgroundColor:`var(--z-accent)`,color:`#FFFFFF`,border:`none`,padding:`8px 16px`,borderRadius:`6px`,fontWeight:600,cursor:`pointer`,boxShadow:`0 4px 10px rgba(139, 92, 246, 0.3)`,transition:`transform 0.1s ease`},onMouseDown:e=>e.currentTarget.style.transform=`scale(0.96)`,onMouseUp:e=>e.currentTarget.style.transform=`scale(1)`,children:`Confirm Focal Selection`})]})]})},Ut=({value:e,onChange:t,hasMany:n,disabled:r=!1,focalPoint:i=!1})=>{let{theme:a}=K(),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)([]),[u,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(``),[v,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{x(!0)},[]);let S=Array.isArray(e)?e:e?[e]:[],w=Z.useRef({}),T=Z.useRef(new Set),E=e=>e?e.startsWith(`http`)?e:w.current[e]||e:``;(0,Z.useEffect)(()=>{if(!c.length)return;let e=c.filter(e=>e.url&&!e.url.startsWith(`http`)&&!w.current[e.url]);e.length&&e.forEach(e=>{fetch(`${e.url}`,{credentials:`include`}).then(e=>e.blob()).then(t=>{let n=URL.createObjectURL(t);T.current.add(n),w.current[e.url]=n,D(e=>e+1)}).catch(()=>{})})},[c]);let[,D]=Z.useState(0);(0,Z.useEffect)(()=>()=>{T.current.forEach(e=>URL.revokeObjectURL(e))},[]);let O=async()=>{f(!0);try{l((await q.get(`/media`)).data.data||[])}catch{console.error(`Failed to fetch media`),fe.error(`Failed to load media library`)}finally{f(!1)}};(0,Z.useEffect)(()=>{if(o){let e=setTimeout(()=>O(),0);return()=>clearTimeout(e)}},[o]);let k=e=>{if(i&&!n){y(e);return}n?S.find(t=>t._id===e._id)?t(S.filter(t=>t._id!==e._id)):t([...S,e]):(t(e),s(!1))},A=async(e,n,r)=>{let i={...e,focalPoint:{x:n,y:r}};try{e._id&&await q.patch(`/media/${e._id}`,{focalPoint:{x:n,y:r}})}catch{console.error(`Failed to save focal point`),fe.error(`Failed to save focal point`)}t(i),y(null),s(!1)},j=async e=>{if(!e.target.files?.[0])return;let r=new FormData;r.append(`file`,e.target.files[0]);try{let e=(await q.post(`/upload`,r,{headers:{"Content-Type":`multipart/form-data`}})).data.data;if(l([e,...c]),i&&!n){y(e);return}n||(t(e),s(!1))}catch{console.error(`Upload failed`),fe.error(`Upload failed`)}},ee=()=>{if(!g.trim())return;let e={_id:Math.random().toString(36).substring(7),url:g.trim(),filename:g.trim().split(`/`).pop()||`External URL`};n?t([...S,e]):(t(e),s(!1)),_(``)};return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[S.map((e,i)=>(0,Q.jsxs)(`div`,{className:`relative w-20 h-20 rounded-none-none border border-z-border overflow-hidden group shadow-sm transition-all hover:scale-105 active:scale-95`,children:[(0,Q.jsx)(`img`,{src:E(e.url),className:`w-full h-full object-cover`,alt:``}),!r&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(n?S.filter((e,t)=>t!==i):null),className:`absolute top-1 right-1 p-1 bg-app/60 text-z-primary rounded-none-none opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,Q.jsx)(B,{size:10})})]},e._id||i)),!r&&(n||S.length===0)&&(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(!0)},className:`w-20 h-20 rounded-none-none border border-dashed border-z-border flex flex-col items-center justify-center gap-1.5 text-z-muted hover:border-z-border/50 hover:text-z-secondary hover:bg-z-hover transition-all group`,children:[(0,Q.jsx)(M,{size:18,strokeWidth:3,className:`group-hover:scale-110 transition-transform`}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:`Add_Media`})]})]}),b&&(0,Vt.createPortal)((0,Q.jsx)(H,{children:o&&(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`fixed inset-0 z-[1000] flex items-center justify-center bg-[var(--z-bg-modal)] backdrop-blur-sm p-4 md:p-12`,onClick:()=>s(!1),children:(0,Q.jsx)(G.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},transition:{type:`spring`,damping:25,stiffness:300},className:Y(`w-full max-w-5xl max-h-full border rounded-none-none shadow-2xl flex flex-col overflow-hidden`,a===`dark`?`bg-app/90 backdrop-blur-xl border-z-border`:`bg-z-popover border-z-border`),onClick:e=>e.stopPropagation(),children:(0,Q.jsxs)(`div`,{className:`flex flex-col p-4 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`h3`,{className:Y(`text-sm font-semibold `,`text-z-primary`),children:`Asset Registry`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(!1),className:Y(`p-1 rounded-none-none transition-colors`,a===`dark`?`text-z-muted hover:text-z-primary hover:bg-[var(--z-bg-hover)]`:`text-z-secondary hover:text-z-primary hover:bg-app/5`),children:(0,Q.jsx)(B,{size:14})})]}),(0,Q.jsx)(H,{mode:`wait`,children:v?(0,Q.jsxs)(G.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:`flex flex-col gap-4`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>y(null),className:`text-sm font-semibold text-z-muted hover:text-z-primary transition-colors border border-z-border px-3 py-1.5 rounded-none-none`,children:`← Back`})}),(0,Q.jsx)(`div`,{className:`flex-1 min-h-[300px] flex items-center justify-center`,children:(0,Q.jsx)(Ht,{imageUrl:E(v.url),initialX:v.focalPoint?.x??50,initialY:v.focalPoint?.y??50,onSave:(e,t)=>A(v,e,t)})})]},`focal-step`):(0,Q.jsxs)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex-[2] relative group`,children:[(0,Q.jsx)(h,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-z-secondary group-focus-within:text-z-secondary transition-colors`,size:14}),(0,Q.jsx)(`input`,{type:`text`,placeholder:`Search assets...`,value:p,onChange:e=>m(e.target.value),className:`w-full bg-z-hover border border-z-border rounded-none-none pl-9 pr-3 py-2 text-sm font-medium text-z-primary placeholder:text-z-secondary transition-all focus:bg-z-panel/10 focus:border-z-border/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black`})]}),(0,Q.jsxs)(`div`,{className:`flex-[2] relative flex gap-2`,children:[(0,Q.jsxs)(`div`,{className:`relative flex-1 group`,children:[(0,Q.jsx)(Se,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-z-secondary group-focus-within:text-z-secondary transition-colors`,size:14}),(0,Q.jsx)(`input`,{type:`url`,placeholder:`https://...`,value:g,onChange:e=>_(e.target.value),onKeyDown:e=>e.key===`Enter`&&ee(),className:`w-full bg-z-hover border border-z-border rounded-none-none pl-9 pr-3 py-2 text-sm font-medium text-z-primary placeholder:text-z-secondary transition-all focus:bg-z-panel/10 focus:border-z-border/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black`})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:ee,disabled:!g.trim(),className:`px-3 py-2 bg-z-hover border-z-border-strong text-z-secondary hover:bg-z-border/30 hover:text-z-primary rounded-none-none text-sm font-bold transition-all border border-z-border/30 disabled:opacity-50 disabled:cursor-not-allowed`,children:`Add`})]}),(0,Q.jsxs)(`label`,{className:`flex-1 flex items-center justify-center gap-2 px-4 py-2 bg-z-accent/20 hover:bg-z-accent/30 text-z-secondary rounded-none-none transition-all text-sm font-bold cursor-pointer border border-z-border/30`,children:[(0,Q.jsx)(F,{size:14}),(0,Q.jsx)(`span`,{children:`Upload`}),(0,Q.jsx)(`input`,{type:`file`,className:`hidden`,onChange:j})]})]}),(0,Q.jsx)(`div`,{className:`flex-1 min-h-[300px] max-h-[50vh] overflow-y-auto grid grid-cols-3 sm:grid-cols-4 lg:grid-cols-5 gap-3 pr-2 custom-scrollbar border border-z-border rounded-none-none p-3 bg-app/20`,children:u?(0,Q.jsxs)(`div`,{className:`col-span-full h-full flex flex-col items-center justify-center gap-4`,children:[(0,Q.jsx)(C,{className:`animate-spin text-z-secondary `,size:24}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-secondary animate-pulse`,children:`Syncing...`})]}):(()=>{let e=c.filter(e=>(e.alt||e.id||e.filename||``).toLowerCase().includes(p.toLowerCase()));return e.length===0?(0,Q.jsx)(`div`,{className:`col-span-full h-full flex flex-col justify-center py-6`,children:(0,Q.jsx)(_t,{icon:d,title:p?`No matches found`:`No media assets`,message:p?`Try a different search term`:`Upload an image to get started`})}):e.map(e=>{let t=S.some(t=>t._id===e._id);return(0,Q.jsxs)(`div`,{onClick:()=>k(e),className:Y(`group relative aspect-square rounded-none-none border overflow-hidden cursor-pointer transition-all`,t?`border-z-border shadow-sm scale-[0.98]`:`border-z-border hover:border-z-border/30`),children:[(0,Q.jsx)(`img`,{src:E(e.url),className:`w-full h-full object-cover transition-transform duration-700 group-hover:scale-110`,alt:``}),(0,Q.jsx)(`div`,{className:Y(`absolute inset-0 transition-all duration-300`,t?`bg-z-accent/10`:`bg-app/0 group-hover:bg-app/40`)}),(0,Q.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 p-2 opacity-0 group-hover:opacity-100 translate-y-2 group-hover:translate-y-0 transition-all bg-gradient-to-t from-[var(--z-bg-panel)] to-transparent`,children:(0,Q.jsx)(`p`,{className:`text-sm font-semibold text-z-primary truncate`,children:e.filename||`Untitled_Asset`})}),t&&(0,Q.jsx)(`div`,{className:`absolute top-2 right-2 bg-z-accent text-z-primary rounded-none-none p-1.5 shadow-xl animate-in zoom-in-50 duration-300`,children:(0,Q.jsx)(z,{size:10,strokeWidth:4})})]},e._id)})})()}),(0,Q.jsxs)(`div`,{className:`pt-2 border-t border-z-border flex items-center justify-end gap-3 mt-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{s(!1),y(null)},className:`px-4 py-2 text-sm font-bold text-z-muted hover:text-z-primary transition-colors`,children:`Cancel`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{s(!1),y(null)},className:`px-6 py-2 bg-z-hover border-z-border-strong text-z-secondary hover:bg-z-border/30 hover:text-z-primary rounded-none-none text-sm font-bold transition-all border border-z-border/30`,children:`Done`})]})]},`asset-grid`)})]})})},`media-picker-backdrop`)}),document.body)]})},Wt=({value:e,onChange:t,relationTo:n,hasMany:r,disabled:i=!1})=>{let{theme:a}=K(),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)([]),[f,p]=(0,Z.useState)(!1),[m,g]=(0,Z.useState)(``),[,_]=(0,Z.useState)(null),v=Array.isArray(e)?e:e?[e]:[],y=async()=>{p(!0);try{let e=await q.get(`/health`),t=e.data.data?.collections||[],r=e.data.data?.globals||[];_(t.find(e=>e.slug===n)||r.find(e=>e.slug===n)),d((await q.get(`/${n}`)).data.data||[])}catch{console.error(`Failed to fetch relation data`)}finally{p(!1)}};(0,Z.useEffect)(()=>{if(o){let e=setTimeout(()=>y(),0);return()=>clearTimeout(e)}},[o,n]);let b=e=>{r?v.find(t=>t._id===e._id)?t(v.filter(t=>t._id!==e._id)):t([...v,e]):(t(e),s(!1))},x=e=>e?typeof e==`string`?e:e.name||e.title||e.email||e.id||e._id:``;return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[v.map((e,n)=>(0,Q.jsxs)(`div`,{onClick:()=>l(e._id),className:`flex items-center gap-3 px-4 py-2 bg-z-active-bg/30 border border-z-active-border rounded-none-none group transition-all hover:border-z-active-border cursor-pointer hover:bg-z-active-bg`,children:[(0,Q.jsx)(ye,{size:12,className:`text-z-active-text`}),(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-primary`,children:x(e)}),!i&&(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),t(r?v.filter((e,t)=>t!==n):null)},className:`p-1 hover:bg-z-active-bg rounded-none-none text-z-muted hover:text-z-accent transition-colors`,children:(0,Q.jsx)(B,{size:10})})]},e._id||n)),!i&&(r||v.length===0)&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`flex items-center gap-2.5 px-4 py-2 rounded-xl border-2 border-dashed border-z-border text-z-muted hover:border-z-active-border hover:text-z-accent hover:bg-z-active-bg/20 transition-all group`,children:[(0,Q.jsx)(M,{size:14,strokeWidth:3}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:`Link Record`})]})]}),(0,Q.jsx)(kn,{isOpen:!!c,onClose:()=>l(null),collectionSlug:n,documentId:c||``,onSaved:e=>{t(r?v.map(t=>t._id===e._id?e:t):e)}}),(0,Q.jsx)(H,{children:o&&(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[1000] flex items-center justify-center p-4 md:p-10 bg-app/70 backdrop-blur-md`,children:(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.98,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.98,y:10},className:Y(`w-full max-w-2xl h-[70vh] flex flex-col shadow-2xl overflow-hidden rounded-xl border`,a===`dark`?`bg-app/65 backdrop-blur-xl border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-8 border-b flex items-center justify-between`,`border-z-border`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Q.jsx)(`div`,{className:`w-10 h-10 bg-indigo-500 rounded-lg flex items-center justify-center text-z-primary shadow-lg shadow-sm`,children:(0,Q.jsx)(L,{size:20})}),(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(`h3`,{className:Y(`text-lg font-semibold leading-none`,`text-z-primary`),children:`Select Relation`}),(0,Q.jsxs)(`p`,{className:`text-sm font-bold text-z-muted mt-1.5`,children:[`Targeting Collection: `,n.toUpperCase()]})]})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(!1),className:Y(`w-10 h-10 flex items-center justify-center rounded-lg transition-all`,a===`dark`?`bg-z-panel/5 hover:bg-[var(--z-bg-hover)] text-z-primary`:`bg-[var(--z-bg-input)] hover:bg-[var(--z-bg-hover)] text-z-muted`),children:(0,Q.jsx)(B,{size:18})})]}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col p-8 gap-6`,children:[(0,Q.jsxs)(`div`,{className:`relative group`,children:[(0,Q.jsx)(h,{className:`absolute left-4 top-1/2 -translate-y-1/2 text-z-muted group-focus-within:text-z-accent transition-colors`,size:16}),(0,Q.jsx)(`input`,{type:`text`,placeholder:`Search records...`,value:m,onChange:e=>g(e.target.value),className:Y(`w-full rounded-lg pl-12 pr-4 py-3 text-xs font-bold outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 border`,a===`dark`?`bg-app/20 border-z-border text-z-primary`:`bg-[var(--z-bg-input)] border-z-border text-z-primary`)})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 custom-scrollbar`,children:f?(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center gap-4`,children:[(0,Q.jsx)(C,{className:`animate-spin text-z-active-text`,size:24}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-muted animate-pulse`,children:`Syncing Records...`})]}):u.length===0?(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center gap-4 opacity-30`,children:[(0,Q.jsx)(L,{size:32,className:`text-z-primary`}),(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold`,`text-z-primary`),children:`No Records Found`})]}):u.filter(e=>x(e).toLowerCase().includes(m.toLowerCase())).map(e=>{let t=v.some(t=>t._id===e._id);return(0,Q.jsxs)(`div`,{onClick:()=>b(e),className:Y(`flex items-center justify-between p-4 rounded-lg border transition-all cursor-pointer group`,t?`bg-indigo-500 border-indigo-500 text-z-primary shadow-xl shadow-sm`:a===`dark`?`bg-app/20 border-z-border hover:border-z-border`:`bg-z-panel border-z-border hover:border-z-active-border hover:bg-z-active-bg/10`),children:[(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-semibold`,`text-z-primary`),children:x(e)}),(0,Q.jsxs)(`span`,{className:Y(`text-sm font-bold mt-1`,t?`text-z-primary/60`:`text-z-muted`),children:[`ID: `,e._id.slice(-8)]})]}),t&&(0,Q.jsx)(z,{size:16,strokeWidth:3})]},e._id)})})]}),(0,Q.jsx)(`div`,{className:Y(`p-8 border-t flex justify-end`,a===`dark`?`border-z-border bg-app/20`:`border-z-border bg-[var(--z-bg-input)]/50`),children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(!1),className:Y(`px-8 py-3 rounded-lg text-sm font-semibold shadow-xl transition-all`,a===`dark`?`bg-z-panel/10 text-z-primary hover:bg-z-panel/20`:`bg-z-accent text-z-primary shadow-[var(--z-border)] hover:brightness-110`),children:`Close Registry`})})]})})})]})};function Gt(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Kt(e,t){let n=Gt(e)?{...e}:{};return Gt(e)&&Gt(t)&&Object.entries(t).forEach(([t,r])=>{Gt(r)&&t in e?n[t]=Kt(e[t],r):Object.assign(n,{[t]:r})}),n}function qt(e,t){if(!t.includes(`.`))return e?.[t];let n=t.split(`.`),r=e;for(let e of n){if(!r||typeof r!=`object`)return;r=r[e]}return r}function Jt(e,t){if(!e)return!0;if(typeof e==`function`)try{return e(t)}catch{return!0}if(typeof e==`object`&&e){let n=e,r=n.field;if(!r)return!0;let i=t[r];if(n.equals!==void 0)return i===n.equals;if(n.notEquals!==void 0)return i!==n.notEquals;if(n.contains!==void 0)return Array.isArray(i)&&i.includes(n.contains)}return!0}function Yt(e,t){return e.localized?`${e.name}.${t}`:e.name}function Xt(e){if(e)return{textTransform:e}}var Zt=({field:e,value:t,onChange:n,disabled:r})=>{let{theme:i}=K(),a=e,o=Xt(a.casing);return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`input`,{type:[`date`,`password`,`color`,`email`].includes(a.type)?a.type:`text`,value:t||``,onChange:e=>{let t=e.target.value;a.casing===``?t=t.toUpperCase():a.casing===`lowercase`?t=t.toLowerCase():a.casing===`capitalize`&&(t=t.replace(/\b\w/g,e=>e.toUpperCase())),n(t)},maxLength:a.maxLength,style:o,disabled:r,className:Y(`w-full px-4 py-3 text-sm transition-all outline-none rounded-none-none border`,i===`dark`?`bg-z-base/65 backdrop-blur-md border-z-border text-z-primary placeholder:text-z-secondary focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`:`bg-z-panel/80 backdrop-blur-md border-z-border text-z-primary placeholder:text-z-muted focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`,a.type===`color`&&`h-11 p-1 cursor-pointer`,a.type===`uid`&&`font-mono text-z-active-text`,`disabled:opacity-60 disabled:cursor-not-allowed`),placeholder:`Enter ${a.name}...`}),a.maxLength&&a.type!==`date`&&(0,Q.jsxs)(`span`,{className:`absolute right-3 top-2.5 text-sm font-bold text-z-secondary font-mono pointer-events-none`,children:[(t||``).length,` / `,a.maxLength]})]})},Qt=({field:e,value:t,onChange:n,disabled:r})=>{let{theme:i}=K(),a=e;return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`textarea`,{value:t||``,onChange:e=>{let t=e.target.value;a.casing===``?t=t.toUpperCase():a.casing===`lowercase`?t=t.toLowerCase():a.casing===`capitalize`&&(t=t.replace(/\b\w/g,e=>e.toUpperCase())),n(t)},maxLength:a.maxLength,rows:8,style:Xt(a.casing),disabled:r,className:Y(`w-full px-4 py-3 text-sm transition-all outline-none rounded-none-none border min-h-[140px]`,i===`dark`?`bg-z-base/65 backdrop-blur-md border-z-border text-z-primary placeholder:text-z-secondary focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`:`bg-z-panel/80 backdrop-blur-md border-z-border text-z-primary placeholder:text-z-muted focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`,`disabled:opacity-60 disabled:cursor-not-allowed`),placeholder:`Enter ${a.name}...`}),a.maxLength&&(0,Q.jsxs)(`span`,{className:`absolute bottom-2 right-3 text-sm font-bold text-z-secondary font-mono`,children:[(t||``).length,` / `,a.maxLength]})]})},$t=({field:e,value:t,onChange:n,disabled:r})=>{let{theme:i}=K(),a=e,o=a.hasMany??!1;return o&&Array.isArray(t)&&t.map(String),(0,Q.jsxs)(`select`,{value:o?void 0:t||``,onChange:e=>{n(o?Array.from(e.target.selectedOptions,e=>e.value):e.target.value)},multiple:o,disabled:r,className:Y(`w-full px-4 py-3 text-sm transition-all duration-350 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black`,`backdrop-blur-md`,i===`dark`?`bg-z-base/65 backdrop-blur-md border-z-border text-z-primary focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`:`bg-z-panel/80 backdrop-blur-md border-z-border text-z-primary focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`,o?`rounded-none-none min-h-[120px]`:`rounded-none-none`,`disabled:opacity-60 disabled:cursor-not-allowed`),children:[!a.required&&!o&&(0,Q.jsx)(`option`,{value:``,children:`Select...`}),(a.options||[]).map(e=>{let t=typeof e==`string`?e:e.value||e,n=typeof e==`string`?e:e.label||e,r=String(t);return(0,Q.jsx)(`option`,{value:r,children:String(n)},r)})]})},en=({field:e,value:t,onChange:n,disabled:r})=>(0,Q.jsx)(`div`,{className:`flex items-center h-9`,children:(0,Q.jsx)(`input`,{type:`checkbox`,checked:!!t,onChange:e=>n(e.target.checked),disabled:r,className:`w-4 h-4 rounded-none-none border border-z-border bg-z-input backdrop-blur-md text-z-active-text focus:ring-z-active-border focus:ring-2 disabled:opacity-60 disabled:cursor-not-allowed transition-all`})}),tn=({field:e,value:t,onChange:n,disabled:r})=>(0,Q.jsx)(`input`,{type:`number`,value:t??``,onChange:e=>n(e.target.value===``?null:Number(e.target.value)),disabled:r,className:`w-full bg-z-base/65 backdrop-blur-md border border-z-border rounded-none-none px-4 py-3 text-sm focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border outline-none disabled:opacity-60 disabled:cursor-not-allowed text-z-primary placeholder:text-z-secondary transition-all font-mono`}),nn=({field:e,value:t,onChange:n,disabled:r})=>{let i=e;return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`textarea`,{value:t||``,onChange:e=>n(e.target.value),maxLength:i.maxLength,rows:10,disabled:r,spellCheck:!1,className:Y(`w-full bg-[#0d1117] backdrop-blur-md border border-z-border rounded-none-none px-4 py-3 text-sm font-mono`,`focus:border-z-accent/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black disabled:opacity-60 disabled:cursor-not-allowed`,`text-[#e6edf3] placeholder:text-z-secondary`),placeholder:`Enter ${i.language||`code`}...`}),(0,Q.jsxs)(`div`,{className:`absolute top-2 right-3 flex items-center gap-2`,children:[i.language&&(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-active-text/60 font-mono`,children:i.language}),i.maxLength&&(0,Q.jsxs)(`span`,{className:`text-sm font-bold text-z-secondary font-mono`,children:[(t||``).length,`/`,i.maxLength]})]})]})},rn=({field:e,value:t,onChange:n,disabled:r,renderField:i})=>{let a=e,[o,s]=Z.useState(!a.initCollapsed),c=a.fields||[];return(0,Q.jsxs)(`div`,{className:`border border-z-border rounded-none-none overflow-hidden`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(!o),className:`w-full flex items-center justify-between px-4 py-3 bg-z-hover hover:bg-z-panel/[0.06] transition-colors text-sm font-semibold text-z-primary`,children:(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`transition-transform duration-200 text-z-active-text ${o?`rotate-90`:``}`}),e.label||e.name]})}),o&&(0,Q.jsx)(`div`,{className:`p-4 grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-4 border-t border-z-border`,children:c.map(e=>(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`label`,{className:`text-xs font-semibold text-z-secondary capitalize`,children:[e.label||e.name,e.required&&(0,Q.jsx)(`span`,{className:`text-danger ml-1`,children:`*`})]}),i(e,t?.[e.name],r=>n({...t||{},[e.name]:r}))]},e.name))})]})},an=({field:e,value:t,onChange:n,disabled:r,renderField:i})=>{let a=t&&typeof t==`object`?t:{},o=e,s=o.fields||[];return(0,Q.jsxs)(`div`,{className:Y(`border border-z-border bg-z-panel backdrop-blur-md p-4 space-y-4`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 pb-3 border-b border-z-border`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-active-text`,children:e.label||e.name}),o.admin?.description&&(0,Q.jsx)(`span`,{className:`text-sm text-z-secondary italic`,children:o.admin.description})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-x-6 gap-y-5 pt-2`,children:s.map(e=>(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`label`,{className:`text-sm font-bold text-z-muted`,children:[e.label||e.name,e.required&&(0,Q.jsx)(`span`,{className:`text-danger ml-1`,children:`*`})]}),i(e,a[e.name],t=>n({...a,[e.name]:t}),r)]},e.name))})]})};function on(e){if(e==null||e===``)return null;let t=typeof e==`string`?e:JSON.stringify(e);try{return JSON.parse(t),!0}catch{return!1}}var sn=({value:e,onChange:t,disabled:n,rows:r=8})=>{let[i,a]=(0,Z.useState)(!1),o=on(e),s=typeof e==`string`?e:e==null?``:JSON.stringify(e,null,2),c=(0,Z.useCallback)(e=>{let n=e.target.value;t(n)},[t]),l=(0,Z.useCallback)(()=>{try{let n=JSON.parse(typeof e==`string`?e:JSON.stringify(e));t(JSON.stringify(n,null,2))}catch{}},[e,t]);return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`div`,{className:`absolute left-3 top-2.5 text-z-secondary pointer-events-none`,children:(0,Q.jsx)(se,{size:14})}),(0,Q.jsx)(`textarea`,{value:s,onChange:c,onFocus:()=>a(!0),onBlur:()=>a(!1),rows:r,disabled:n,spellCheck:!1,className:Y(`w-full bg-[#0d1117] backdrop-blur-md border rounded-none-none px-9 py-3 text-sm font-mono resize-y outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black transition-colors`,`text-[#e6edf3] placeholder:text-z-secondary disabled:opacity-60 disabled:cursor-not-allowed`,i?`border-z-accent/50`:o===!1?`border-red-500/40`:`border-z-border`),placeholder:`{"key": "value"}`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:Y(`inline-block w-1.5 h-1.5 rounded-none-full`,o===!0?`bg-z-accent shadow-sm`:o===!1?`bg-red-500 shadow-[0_0_6px_#ef4444]`:`bg-z-accent`)}),(0,Q.jsx)(`span`,{className:Y(`text-sm font-bold `,o===!0?`text-z-active-text`:o===!1?`text-red-400`:`text-z-secondary`),children:o===!0?`Valid JSON`:o===!1?`Invalid JSON`:`JSON`})]}),o===!0&&(0,Q.jsx)(`button`,{type:`button`,onClick:l,className:`text-sm font-bold text-z-secondary hover:text-z-active-text transition-colors`,children:`Format`})]})]})};function cn(e,t){if(!e)return``;try{let n=new Date(e);return isNaN(n.getTime())?typeof e==`string`?e:``:t===`datetime`?n.toISOString().slice(0,16):t===`time`?n.toISOString().slice(11,16):n.toISOString().slice(0,10)}catch{return typeof e==`string`?e:``}}function ln(e,t){if(!e)return``;if(t===`time`)return e;try{return new Date(e).toISOString()}catch{return e}}var un=({value:e,onChange:t,disabled:n,format:r=`date`})=>{let{theme:i}=K(),a=r===`datetime`?`datetime-local`:r===`time`?`time`:`date`;return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`div`,{className:Y(`absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`,i===`dark`?`text-z-primary/60`:`text-z-secondary`),children:(0,Q.jsx)(Ye,{size:14})}),(0,Q.jsx)(`input`,{type:a,value:cn(e,r),onChange:e=>t(ln(e.target.value,r)),disabled:n,style:{colorScheme:i===`dark`?`dark`:`light`},className:Y(`w-full pl-9 pr-4 py-3 text-sm transition-all outline-none rounded-none-none border`,i===`dark`?`bg-z-input backdrop-blur-md border-z-border text-z-primary placeholder:text-z-secondary focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`:`bg-z-panel/80 backdrop-blur-md border-z-border text-z-primary placeholder:text-z-muted focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`,`disabled:opacity-60 disabled:cursor-not-allowed font-mono`)})]})};function dn(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``)}var fn=({value:e,onChange:t,disabled:n,sourceField:r,formValues:i})=>{let a=(0,Z.useCallback)(()=>{if(r&&i){let e=i[r];typeof e==`string`&&e.trim()&&t(dn(e))}},[r,i,t]);return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`div`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-z-secondary pointer-events-none`,children:(0,Q.jsx)(Se,{size:14})}),(0,Q.jsx)(`input`,{type:`text`,value:e||``,onChange:e=>t(e.target.value),disabled:n,className:Y(`w-full bg-z-panel/[0.05] backdrop-blur-md border border-z-border rounded-none-none pl-9 pr-10 py-3 text-sm`,`focus:border-z-accent/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black disabled:opacity-60 disabled:cursor-not-allowed`,`text-z-active-text font-mono placeholder:text-z-secondary`),placeholder:`auto-generated-slug`}),r&&(0,Q.jsx)(`button`,{type:`button`,onClick:a,disabled:n,title:`Generate from ${r}`,className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-z-secondary hover:text-z-active-text disabled:opacity-30 transition-colors`,children:(0,Q.jsx)(v,{size:13})})]})};function pn(){return Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}var mn=({value:e,onChange:t,disabled:n})=>{let r=(0,Z.useCallback)(()=>{t(pn())},[t]);return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`div`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-z-secondary pointer-events-none`,children:(0,Q.jsx)(O,{size:14})}),(0,Q.jsx)(`input`,{type:`text`,value:e||``,onChange:e=>t(e.target.value),disabled:n,readOnly:!0,className:Y(`w-full bg-z-hover backdrop-blur-md border border-z-border rounded-none-none pl-9 pr-10 py-2 text-sm`,`focus:border-z-accent/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black disabled:opacity-60 disabled:cursor-not-allowed`,`text-z-active-text/80 font-mono`),placeholder:`auto-generated-uid`}),(0,Q.jsx)(`button`,{type:`button`,onClick:r,disabled:n,title:`Regenerate UID`,className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-z-secondary hover:text-z-active-text disabled:opacity-30 transition-colors`,children:(0,Q.jsx)(v,{size:13})})]})},hn=({field:e,value:t,onChange:n,disabled:r,renderField:i})=>{let a=e.tabs||[],[o,s]=(0,Z.useState)(0),c=t&&typeof t==`object`?t:{};if(a.length===0)return null;let l=a[o]?.fields||[];return(0,Q.jsxs)(`div`,{className:`border border-z-border bg-z-panel backdrop-blur-md`,children:[(0,Q.jsx)(`div`,{className:`flex border-b border-z-border`,children:a.map((e,t)=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:Y(`px-4 py-2.5 text-sm font-semibold transition-colors`,o===t?`text-z-active-text border-b-2 border-z-accent bg-z-hover`:`text-z-secondary hover:text-z-secondary`),children:e.label||e.name},e.name))}),l.length>0&&(0,Q.jsx)(`div`,{className:`p-4 space-y-3`,children:l.map(e=>(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`label`,{className:`text-sm font-bold text-z-muted`,children:[e.label||e.name,e.required&&(0,Q.jsx)(`span`,{className:`text-danger ml-1`,children:`*`})]}),i(e,c[e.name],t=>n({...c,[e.name]:t}),r)]},e.name))})]})},gn=({field:e,value:t,onChange:n,disabled:r})=>{let i=Array.isArray(t)&&t.length===2?t:[0,0];return(0,Q.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-sm font-bold text-z-secondary`,children:`Longitude`}),(0,Q.jsx)(`input`,{type:`number`,value:i[0],onChange:e=>n([Number(e.target.value),i[1]]),step:`any`,disabled:r,className:`w-full bg-z-panel/[0.05] backdrop-blur-md border border-z-border rounded-none-none px-3 py-3 text-sm focus:border-z-accent/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black disabled:opacity-60 disabled:cursor-not-allowed text-z-primary placeholder:text-z-secondary`,placeholder:`0.0`})]}),(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-sm font-bold text-z-secondary`,children:`Latitude`}),(0,Q.jsx)(`input`,{type:`number`,value:i[1],onChange:e=>n([i[0],Number(e.target.value)]),step:`any`,disabled:r,className:`w-full bg-z-panel/[0.05] backdrop-blur-md border border-z-border rounded-none-none px-3 py-3 text-sm focus:border-z-accent/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black disabled:opacity-60 disabled:cursor-not-allowed text-z-primary placeholder:text-z-secondary`,placeholder:`0.0`})]})]})},_n=({field:e,value:t,onChange:n,renderField:r})=>(0,Q.jsx)(`div`,{className:`flex gap-4 items-end`,children:(e.fields||[]).map(e=>(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,Q.jsxs)(`label`,{className:`text-xs font-semibold text-z-secondary capitalize`,children:[e.label||e.name,e.required&&(0,Q.jsx)(`span`,{className:`text-danger ml-1`,children:`*`})]}),r(e,t?.[e.name],r=>n({...t||{},[e.name]:r}))]},e.name))}),vn=({field:e})=>(0,Q.jsxs)(`div`,{className:`w-full bg-z-hover border border-z-border rounded-none-none px-4 py-3 text-sm text-z-muted italic flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-z-active-text`,children:`⧉`}),`Joined data from`,` `,(0,Q.jsx)(`span`,{className:`font-mono text-z-active-text text-xs`,children:e.collection}),` — read-only`]}),yn=({field:e,value:t,onChange:n,disabled:r})=>{let i=e;return(0,Q.jsx)(`div`,{className:Y(`flex gap-4`,i.layout===`horizontal`?`flex-row flex-wrap`:`flex-col gap-2`),children:(i.options||[]).map((i,a)=>{let o=typeof i==`string`?i:i.value||``,s=typeof i==`string`?i:i.label||o;return(0,Q.jsxs)(`label`,{className:`flex items-center gap-2.5 cursor-pointer group`,children:[(0,Q.jsx)(`input`,{type:`radio`,name:e.name,value:String(o),checked:t===o,onChange:e=>n(e.target.value),disabled:r,className:`w-4 h-4 border border-z-border text-z-active-text focus:ring-z-active-border disabled:opacity-60 accent-z-accent`}),(0,Q.jsx)(`span`,{className:`text-sm text-z-secondary group-hover:text-z-primary transition-colors`,children:String(s)})]},`${String(o)}-${a}`)})})},bn=e=>e.replace(/^root:/,``).replace(/([A-Z])/g,` $1`).replace(/^./,e=>e.toUpperCase()),xn={Star:T,Grid:f,BarChart4:ee,MessageSquare:pe,Mail:me,CreditCard:m,Zap:Je,FileText:w,Layout:f,Users:be,AlertCircle:ie,Code:se,Table:r,Puzzle:oe},Sn=e=>{let t=pt.find(t=>t.type===e),n=t?xn[t.iconName]:null;return n?Z.createElement(n,{size:16}):e===`plugin-node`?(0,Q.jsx)(oe,{size:16}):(0,Q.jsx)(_e,{size:16})},Cn={Layout:`from-z-accent to-transparent`,Content:`from-z-accent to-transparent`,Commerce:`from-z-accent to-transparent`,Media:`from-rose-900/60 to-pink-900/40`,Social:`from-amber-900/60 to-orange-900/40`,General:`from-[#1a1a2e]/80 to-[#16213e]/60`},wn=pt.map(e=>({slug:e.type,labels:{singular:e.title,plural:e.title+`s`},fields:e.fields.map(t=>({name:t.name,label:t.label||bn(t.name),type:t.type,required:t.required,defaultValue:e.defaultContent[t.name],options:t.options})),admin:{description:e.description,category:e.category}}));function Tn({block:e,index:t,total:n,blockDef:r,isExpanded:i,disabled:a,onToggle:s,onRemove:c,onDuplicate:l,onMoveUp:u,onMoveDown:d,renderField:f,onUpdate:p}){let m=(()=>{for(let t of[`headline`,`title`,`name`,`content`,`subheadline`])if(e[t]&&typeof e[t]==`string`)return e[t];return null})(),h=Cn[r?.admin?.category||``]??Cn.General;return(0,Q.jsxs)(V,{value:e,drag:a?!1:`y`,whileDrag:{scale:1.01,zIndex:50,boxShadow:`0 20px 40px rgba(0,0,0,0.4)`},className:Y(`group relative bg-app border rounded-none-none overflow-visible shadow-sm transition-colors duration-150`,i?`border-accent/60 shadow-sm`:`border-border hover:border-z-border`),children:[(0,Q.jsx)(`div`,{className:Y(`absolute -left-3.5 top-1/2 -translate-y-1/2 w-5 h-5 rounded-none-full flex items-center justify-center text-sm font-semibold border z-10 transition-all`,i?`bg-accent text-z-primary border-accent shadow-sm`:`bg-app text-z-muted border-border group-hover:border-accent/40 group-hover:text-accent`),children:t+1}),i&&(0,Q.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-[3px] bg-accent rounded-none-l`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-4 py-3 cursor-pointer`,onClick:s,children:[!a&&(0,Q.jsx)(`div`,{className:`p-1 text-z-muted/30 hover:text-z-muted cursor-grab active:cursor-grabbing flex-shrink-0`,onPointerDown:e=>e.stopPropagation(),children:(0,Q.jsx)(Ee,{size:13})}),(0,Q.jsx)(`div`,{className:Y(`w-7 h-7 rounded-none flex items-center justify-center flex-shrink-0 bg-gradient-to-br text-z-primary/70`,h),children:Sn(e.blockType)}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-primary truncate`,children:m||r?.labels?.singular||e.blockType}),(0,Q.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-px text-sm font-semibold text-z-muted bg-z-panel/[0.05] border border-border rounded-none`,children:e.blockType})]}),r?.admin?.description&&(0,Q.jsx)(`p`,{className:`text-sm text-z-muted/70 truncate mt-0.5`,children:r.admin.description})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0`,onClick:e=>e.stopPropagation(),children:[!a&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,onClick:u,disabled:t===0,title:`Move Up`,className:`p-1.5 text-z-muted hover:text-z-primary disabled:opacity-20 disabled:cursor-not-allowed transition-colors`,children:(0,Q.jsx)(ve,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:d,disabled:t===n-1,title:`Move Down`,className:`p-1.5 text-z-muted hover:text-z-primary disabled:opacity-20 disabled:cursor-not-allowed transition-colors`,children:(0,Q.jsx)(Qe,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:l,title:`Duplicate`,className:`p-1.5 text-z-muted hover:text-accent transition-colors`,children:(0,Q.jsx)(b,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:c,title:`Remove`,className:`p-1.5 text-z-muted hover:text-danger transition-colors`,children:(0,Q.jsx)(o,{size:11})})]}),(0,Q.jsx)(G.div,{animate:{rotate:i?180:0},transition:{duration:.2},className:`p-1.5 text-z-muted/50 ml-0.5`,children:(0,Q.jsx)(We,{size:13})})]})]}),(0,Q.jsx)(H,{initial:!1,children:i&&(0,Q.jsx)(G.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:[.4,0,.2,1]},className:`overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`px-5 pb-6 pt-4 border-t border-border bg-z-panel/[0.05]/40`,children:r?(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:r.fields.map(t=>(0,Q.jsxs)(`div`,{className:Y(`flex flex-col gap-1.5`,[`richtext`,`textarea`,`blocks`,`array`,`media`,`code`,`collapsible`].includes(t.type)&&`col-span-2`),children:[(0,Q.jsxs)(`label`,{className:`text-sm font-semibold text-z-muted flex items-center gap-1`,children:[t.label||t.name,t.required&&(0,Q.jsx)(`span`,{className:`text-danger`,children:`*`})]}),f?f(t,e[t.name],e=>p({[t.name]:e})):(0,Q.jsx)(`input`,{type:`text`,value:e[t.name]||``,onChange:e=>p({[t.name]:e.target.value}),placeholder:`Enter ${t.label||t.name}...`,className:`w-full bg-app border border-border px-3 py-2 text-sm focus:border-accent focus:ring-2 focus:ring-accent/10 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black transition-all rounded-none-none`})]},t.name))}):(0,Q.jsxs)(`p`,{className:`text-xs text-z-muted text-center py-4 italic`,children:[`Unknown block type: "`,e.blockType,`"`]})})})})]})}var En=({value:e,onChange:t,availableBlocks:n,renderField:r,disabled:i=!1})=>{let o=ct(),{openComponentPicker:s}=dt(),[c,l]=(0,Z.useState)({}),[u,d]=(0,Z.useState)(!1),f=`/preview`,p=n||[],m=p.length>0?p:o.length>0?o:wn,h=e||[],g=(0,Z.useCallback)(e=>{l(t=>({...t,[e]:!t[e]}))},[]),_=(0,Z.useCallback)(e=>{let n=m.find(t=>t.slug===e),r=`block_`+at(),i={blockType:e,_id:r,id:r};n?.fields.forEach(e=>{e.defaultValue!==void 0&&(i[e.name]=e.defaultValue)}),t([...h,i]),l(e=>({...e,[r]:!0}))},[h,m,t]),v=(0,Z.useCallback)(()=>{s(e=>_(e))},[s,_]),y=(0,Z.useCallback)(e=>{t(h.filter((t,n)=>n!==e))},[h,t]),b=(0,Z.useCallback)(e=>{let n=[...h],r=`block_`+at(),i={...h[e],_id:r,id:r};n.splice(e+1,0,i),t(n),l(e=>({...e,[r]:!0}))},[h,t]),x=(0,Z.useCallback)((e,n)=>{let r=[...h],i=n===`up`?e-1:e+1;i<0||i>=r.length||([r[e],r[i]]=[r[i],r[e]],t(r))},[h,t]),S=(0,Z.useCallback)((e,n)=>{let r=[...h];r[e]={...r[e],...n},t(r)},[h,t]),C=(0,Z.useCallback)(()=>{let e={};h.forEach((t,n)=>{let r=t._id||String(n);e[r]=!0}),l(e)},[h]),w=(0,Z.useCallback)(()=>{l({})},[]);return(0,Q.jsxs)(`div`,{className:Y(`select-none`,u?`grid grid-cols-2 gap-8`:`pl-5`),children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 w-full`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Q.jsx)(N,{size:16,className:`text-accent`}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-primary`,children:`Page Components`}),h.length>0&&(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 text-sm font-semibold bg-accent/15 text-accent border border-accent/25 rounded-none-full`,children:h.length})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>d(!u),className:Y(`flex items-center gap-1.5 px-3 py-1.5 text-sm font-semibold transition-all rounded-none-none border`,u?`bg-z-active-bg text-z-active-text border-z-active-border`:`bg-z-panel text-z-muted border-z-border hover:text-z-primary`),children:[u?(0,Q.jsx)(re,{size:12}):(0,Q.jsx)(a,{size:12}),u?`Close Preview`:`Live Preview`]}),h.length>0&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 border border-z-border bg-z-panel p-0.5 rounded-none-none mr-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:C,className:`px-2.5 py-1 text-sm font-semibold text-z-muted hover:text-z-primary transition-all hover:bg-z-panel/[0.05]`,children:`Expand All`}),(0,Q.jsx)(`div`,{className:`w-px h-3 bg-z-panel/10`}),(0,Q.jsx)(`button`,{type:`button`,onClick:w,className:`px-2.5 py-1 text-sm font-semibold text-z-muted hover:text-z-primary transition-all hover:bg-z-panel/[0.05]`,children:`Collapse All`})]}),!i&&(0,Q.jsxs)(`button`,{type:`button`,onClick:v,className:`flex items-center gap-1.5 px-3 py-1.5 bg-accent text-z-primary text-sm font-semibold hover:bg-accent/90 transition-all shadow-sm shadow-accent/20 rounded-none-none`,children:[(0,Q.jsx)(M,{size:11}),` Add Component`]})]})]}),h.length===0&&(0,Q.jsxs)(G.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},className:`border border-dashed border-border p-10 flex flex-col items-center gap-4 text-center bg-z-panel/[0.05]/20 rounded-none-none`,children:[(0,Q.jsx)(`div`,{className:`w-12 h-12 rounded-none-full bg-accent/10 border border-accent/20 flex items-center justify-center`,children:(0,Q.jsx)(N,{size:20,className:`text-accent/50`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-sm font-bold text-z-primary mb-1`,children:`No components yet`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-muted max-w-xs leading-relaxed`,children:`Build your page by stacking components — hero sections, feature grids, pricing tables and more.`})]}),!i&&(0,Q.jsxs)(`button`,{type:`button`,onClick:v,className:`flex items-center gap-2 px-4 py-2 bg-accent text-z-primary text-sm font-semibold hover:bg-accent/90 transition-all shadow-sm shadow-accent/20 mt-1 rounded-none-none`,children:[(0,Q.jsx)(M,{size:12}),` Add Your First Component`]})]}),(0,Q.jsx)(qe,{axis:`y`,values:h,onReorder:t,className:`space-y-3`,children:(0,Q.jsx)(H,{initial:!1,children:h.map((e,t)=>{let n=m.find(t=>t.slug===e.blockType),a=e._id||String(t);return(0,Q.jsx)(G.div,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},exit:{opacity:0,x:-8,height:0,marginTop:0},transition:{duration:.15},children:(0,Q.jsx)(Tn,{block:e,index:t,total:h.length,blockDef:n,isExpanded:!!c[a],disabled:i,onToggle:()=>g(a),onRemove:()=>y(t),onDuplicate:()=>b(t),onMoveUp:()=>x(t,`up`),onMoveDown:()=>x(t,`down`),renderField:r,onUpdate:e=>S(t,e)})},`block-${a}`)})})}),h.length>0&&!i&&(0,Q.jsxs)(G.button,{type:`button`,initial:{opacity:0},animate:{opacity:1},onClick:v,className:`flex items-center justify-center gap-2 w-full py-2.5 border border-dashed border-border text-z-muted/60 text-sm font-semibold hover:border-accent/50 hover:text-accent hover:bg-accent/5 transition-all rounded-none-none`,children:[(0,Q.jsx)(M,{size:11}),` Add Component`]})]}),u&&(0,Q.jsxs)(`div`,{className:`w-full h-full min-h-[700px] border border-z-border rounded-none-none overflow-hidden sticky top-4 bg-[#0B0F19] shadow-2xl flex flex-col`,children:[(0,Q.jsxs)(`div`,{className:`px-4 py-2 border-b border-z-border flex items-center justify-between shrink-0`,children:[(0,Q.jsxs)(`span`,{className:`text-sm font-semibold text-z-active-text italic flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`w-2 h-2 rounded-none-full bg-z-accent animate-pulse shadow-sm`}),`Live Preview Connected`]}),(0,Q.jsx)(`span`,{className:`text-sm font-mono text-z-secondary`,children:f})]}),(0,Q.jsx)(`iframe`,{src:f,className:`w-full flex-1 border-0 bg-z-panel`,title:`Live Preview`})]})]})},Dn=({value:e=[],onChange:t,fields:n,label:r,renderField:i,disabled:a=!1})=>{let[s,c]=(0,Z.useState)({}),l=Z.useMemo(()=>e.map((e,t)=>({...e,_id:e._id||`array_item_${at()}_${t}`})),[e]),u=e=>{c(t=>({...t,[e]:!t[e]}))},d=()=>{let e={};l.forEach(t=>{e[t._id]=!0}),c(e)},f=()=>{c({})},p=(0,Z.useCallback)(()=>{let r=`array_item_${at()}`,i={_id:r,id:r};n.forEach(e=>{e.defaultValue!==void 0&&(i[e.name]=e.defaultValue)}),t([...e,i]),c(e=>({...e,[r]:!0}))},[e,n,t]),m=(0,Z.useCallback)(n=>{let r=[...e];r.splice(n,1),t(r)},[e,t]),h=(0,Z.useCallback)(n=>{let r=[...e],i=`array_item_${at()}`,a={...e[n],_id:i,id:i};r.splice(n+1,0,a),t(r),c(e=>({...e,[i]:!0}))},[e,t]),g=(0,Z.useCallback)((n,r)=>{if(r===`up`&&n===0||r===`down`&&n===e.length-1)return;let i=[...e],a=r===`up`?n-1:n+1,o=i[n];i[n]=i[a],i[a]=o,t(i)},[e,t]),_=(0,Z.useCallback)((n,r)=>{let i=[...e];i[n]={...i[n],...r},t(i)},[e,t]);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 pl-5 select-none`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Q.jsx)(N,{size:16,strokeWidth:2,className:`text-z-secondary `}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-primary`,children:r}),(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 text-sm font-semibold bg-z-border/15 text-z-secondary border border-z-border/25 rounded-none-none`,children:e.length})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 border border-z-border bg-z-panel p-0.5 rounded-none-none mr-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:d,className:`px-2.5 py-1 text-sm font-semibold text-z-muted hover:text-z-primary transition-all hover:bg-z-panel/[0.05]`,children:`Expand All`}),(0,Q.jsx)(`div`,{className:`w-px h-3 bg-z-panel/10`}),(0,Q.jsx)(`button`,{type:`button`,onClick:f,className:`px-2.5 py-1 text-sm font-semibold text-z-muted hover:text-z-primary transition-all hover:bg-z-panel/[0.05]`,children:`Collapse All`})]}),!a&&(0,Q.jsxs)(`button`,{type:`button`,onClick:p,className:`flex items-center gap-1.5 px-3 py-1.5 bg-z-accent text-z-primary text-sm font-semibold hover:bg-z-border transition-all shadow-sm shadow-[var(--z-border)] rounded-none-none`,children:[(0,Q.jsx)(M,{size:11,strokeWidth:2}),` Add Component`]})]})]}),(0,Q.jsx)(qe,{axis:`y`,values:l,onReorder:e=>t(e.map(e=>{let{_id:t,...n}=e;return n})),className:`space-y-3`,children:(0,Q.jsx)(H,{initial:!1,children:l.map((e,t)=>{let r=e._id,c=!!s[r],d=(()=>{for(let t of n)if([`text`,`string`].includes(t.type)&&typeof e[t.name]==`string`)return e[t.name];return`Component ${t+1}`})();return(0,Q.jsx)(G.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:`auto`},exit:{opacity:0,height:0},transition:{duration:.2},children:(0,Q.jsxs)(V,{value:e,drag:a?!1:`y`,whileDrag:{scale:1.01,zIndex:50,boxShadow:`0 20px 40px rgba(0,0,0,0.4)`},className:Y(`group relative bg-app border rounded-none-none overflow-visible shadow-sm transition-colors duration-150`,c?`border-z-border/60 shadow-sm`:`border-border hover:border-z-border`),children:[(0,Q.jsx)(`div`,{className:Y(`absolute -left-3.5 top-1/2 -translate-y-1/2 w-5 h-5 rounded-none-none flex items-center justify-center text-sm font-semibold border z-10 transition-all`,c?`bg-z-border text-z-primary border-z-border shadow-sm`:`bg-app text-z-muted border-border group-hover:border-z-border/40 group-hover:text-z-secondary `),children:t+1}),c&&(0,Q.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-[3px] bg-z-border rounded-none-l`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-4 py-3 cursor-pointer`,onClick:()=>u(r),children:[!a&&(0,Q.jsx)(`div`,{className:`p-1 text-z-muted/30 hover:text-z-muted cursor-grab active:cursor-grabbing flex-shrink-0`,onPointerDown:e=>e.stopPropagation(),children:(0,Q.jsx)(Ee,{size:13})}),(0,Q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-primary truncate`,children:d})})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0`,onClick:e=>e.stopPropagation(),children:[!a&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>g(t,`up`),disabled:t===0,title:`Move Up`,className:`p-1.5 text-z-muted hover:text-z-primary disabled:opacity-20 disabled:cursor-not-allowed transition-colors`,children:(0,Q.jsx)(ve,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>g(t,`down`),disabled:t===l.length-1,title:`Move Down`,className:`p-1.5 text-z-muted hover:text-z-primary disabled:opacity-20 disabled:cursor-not-allowed transition-colors`,children:(0,Q.jsx)(Qe,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>h(t),title:`Duplicate`,className:`p-1.5 text-z-muted hover:text-z-secondary transition-colors`,children:(0,Q.jsx)(b,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>m(t),title:`Remove`,className:`p-1.5 text-z-muted hover:text-danger transition-colors`,children:(0,Q.jsx)(o,{size:11})})]}),(0,Q.jsx)(G.div,{animate:{rotate:c?180:0},transition:{duration:.2},className:`p-1.5 text-z-muted/50 ml-0.5`,children:(0,Q.jsx)(We,{size:13})})]})]}),(0,Q.jsx)(H,{initial:!1,children:c&&(0,Q.jsx)(G.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:[.4,0,.2,1]},className:`overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`px-5 pb-6 pt-4 border-t border-border bg-z-panel/[0.05]/40`,children:(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:n.map(n=>(0,Q.jsxs)(`div`,{className:Y(`flex flex-col gap-1.5`,[`richtext`,`textarea`,`blocks`,`array`,`media`,`code`,`collapsible`].includes(n.type)&&`col-span-2`),children:[(0,Q.jsxs)(`label`,{className:`text-sm font-semibold text-z-muted flex items-center gap-1`,children:[n.label||n.name,n.required&&(0,Q.jsx)(`span`,{className:`text-danger`,children:`*`})]}),i(n,e[n.name],e=>_(t,{[n.name]:e}))]},n.name))})})})})]})},r)})})}),!a&&(0,Q.jsxs)(G.button,{layout:!0,type:`button`,onClick:p,className:`flex items-center justify-center gap-2 w-full py-2.5 border border-dashed border-border text-z-muted/60 text-sm font-semibold hover:border-z-border/50 hover:text-z-secondary hover:bg-z-hover transition-all rounded-none-none`,children:[(0,Q.jsx)(M,{size:11,strokeWidth:2}),` Add `,r]})]})},On=({fields:e,initialData:t,onSubmit:n,onValuesChange:r,isSubmitting:i=!1,activeLocale:a,readOnlyLocale:o,hideSubmitButton:s=!1})=>{let{user:c}=ht(W(e=>({user:e.user}))),l=a||`en`,u=!!o,{handleSubmit:d,control:f,reset:p,watch:m,formState:{errors:h}}=He({defaultValues:t||{}});Z.useEffect(()=>{if(r){let e=m(e=>{r(e)});return()=>e.unsubscribe()}},[m,r]);let g=m(),_=Z.useRef(t);Z.useEffect(()=>{t&&t!==_.current&&(_.current=t,p(t))},[t,p]);let v=(e,t,n,r=!1)=>{if(e.type===`ui`){let i=e.admin?.components?.Field;return i?(0,Q.jsx)(i,{field:e,value:t,onChange:n,disabled:r}):null}return e.type===`collapsible`?(0,Q.jsx)(rn,{field:e,value:t,onChange:n,disabled:r,renderField:v}):e.type===`group`?(0,Q.jsx)(an,{field:e,value:t,onChange:n,disabled:r,renderField:v}):e.type===`tabs`?(0,Q.jsx)(hn,{field:e,value:t,onChange:n,disabled:r,renderField:v}):e.type===`row`?(0,Q.jsx)(_n,{field:e,value:t,onChange:n,disabled:r,renderField:v}):e.type===`richtext`||e.type===`lexical`?(0,Q.jsx)(Qt,{field:e,value:t,onChange:n,disabled:r}):e.type===`media`?(0,Q.jsx)(Ut,{value:t,onChange:n,hasMany:e.hasMany,disabled:r,focalPoint:e.admin?.focalPoint??!0}):e.type===`relation`||e.type===`relationship`?(0,Q.jsx)(Wt,{value:t,onChange:n,relationTo:e.relationTo,hasMany:e.hasMany,disabled:r}):e.type===`blocks`||e.type===`dz`?(0,Q.jsx)(En,{value:t,onChange:n,availableBlocks:e.blocks||[],renderField:(e,t,n)=>v(e,t,n,r),disabled:r}):e.type===`array`?(0,Q.jsx)(Dn,{value:t,onChange:n,fields:e.fields||[],label:e.label||e.name,renderField:(e,t,n)=>v(e,t,n,r),disabled:r}):e.type===`join`?(0,Q.jsx)(vn,{field:e}):e.type===`point`?(0,Q.jsx)(gn,{field:e,value:t,onChange:n,disabled:r}):e.type===`select`?(0,Q.jsx)($t,{field:e,value:t,onChange:n,disabled:r}):e.type===`boolean`||e.type===`checkbox`?(0,Q.jsx)(en,{field:e,value:t,onChange:n,disabled:r}):e.type===`number`?(0,Q.jsx)(tn,{field:e,value:t,onChange:n,disabled:r}):e.type===`textarea`?(0,Q.jsx)(Qt,{field:e,value:t,onChange:n,disabled:r}):e.type===`code`?(0,Q.jsx)(nn,{field:e,value:t,onChange:n,disabled:r}):e.type===`radio`?(0,Q.jsx)(yn,{field:e,value:t,onChange:n,disabled:r}):e.type===`json`?(0,Q.jsx)(sn,{value:t,onChange:n,disabled:r}):e.type===`date`?(0,Q.jsx)(un,{value:t,onChange:n,disabled:r,format:e.dateFormat||`date`}):e.type===`slug`?(0,Q.jsx)(fn,{value:t,onChange:n,disabled:r,sourceField:e.sourceField||`title`,formValues:g}):e.type===`uid`?(0,Q.jsx)(mn,{value:t,onChange:n,disabled:r}):(0,Q.jsx)(Zt,{field:e,value:t,onChange:n,disabled:r})},y=async e=>{n&&await n(Kt(t||{},e))},b=()=>(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-6`,children:e.map(e=>{if(e.name===`_status`||e.name===`id`)return null;let n=e.condition||e.admin?.condition;if(n&&!Jt(n,g))return null;let r=[`richtext`,`blocks`,`array`,`code`,`collapsible`,`group`,`tabs`,`json`].includes(e.type),i=Yt(e,l),a=u;if(c?.role!==`admin`){let t=e.admin?.readAccess;if(t&&t.length>0&&!t.includes(c.role))return null;let n=e.admin?.writeAccess;n&&n.length>0&&!n.includes(c.role)&&(a=!0)}return(0,Q.jsxs)(`div`,{"data-field":i,className:`space-y-2 ${r?`col-span-2`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`label`,{className:`text-sm font-semibold text-z-secondary flex items-center gap-2`,children:[e.label||e.name.replace(/([A-Z])/g,` $1`),e.required&&(0,Q.jsx)(`span`,{className:`text-rose-500`,children:`*`}),e.localized&&(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 text-sm font-semibold text-z-secondary bg-z-panel border border-z-border/20 rounded-none-none`,children:a&&o||l}),a&&!u&&(0,Q.jsx)(Re,{size:10,className:`text-z-secondary ml-1`})]}),e.admin?.description&&(0,Q.jsx)(`span`,{className:`text-sm text-z-muted`,children:e.admin.description})]}),a?v(e,e.localized?t?.[e.name]?.[o||l]??``:t?.[e.name]??``,()=>{},!0):(0,Q.jsx)(je,{name:i,control:f,render:({field:{onChange:t,value:n}})=>(0,Q.jsx)(Q.Fragment,{children:v(e,n,t)})}),!a&&!!qt(h,i)&&(0,Q.jsx)(`p`,{className:`text-xs text-danger mt-1 font-medium`,children:qt(h,i)?.message||`Required field`})]},e.name)})});return u?(0,Q.jsx)(`div`,{className:`space-y-8`,children:b()}):(0,Q.jsxs)(`form`,{onSubmit:n?d(y):void 0,className:`space-y-8`,children:[b(),!s&&(0,Q.jsxs)(`div`,{className:`mt-10 pt-6 border-t border-z-border shadow-sm flex items-center justify-between`,children:[(0,Q.jsxs)(`p`,{className:`text-xs text-z-muted`,children:[`Fields marked with `,(0,Q.jsx)(`span`,{className:`text-danger`,children:`*`}),` are required.`]}),(0,Q.jsx)(`div`,{className:`flex gap-3`,children:(0,Q.jsx)(`button`,{type:`submit`,disabled:i,className:`btn btn-primary min-w-[140px] h-11`,children:i?(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Q.jsx)(C,{size:16,className:`animate-spin`}),`Saving...`]}):`Save Changes`})})]})]})},kn=({isOpen:e,onClose:t,collectionSlug:n,documentId:r,onSaved:i})=>{let{theme:a}=K(),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!0),[f,p]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{!e||!r||(async()=>{d(!0);try{l(((await q.get(`/health`)).data.data?.collections||[]).find(e=>e.slug===n)),s((await q.get(`/${n}/${r}`)).data.data)}catch{U.error(`Failed to load document`)}finally{d(!1)}})()},[e,r,n]),e?(0,Q.jsx)(H,{children:(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[1100] flex items-center justify-center p-4 md:p-8 bg-app/60 backdrop-blur-md`,children:(0,Q.jsxs)(G.div,{initial:{opacity:0,y:10,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.98},className:Y(`w-full max-w-4xl border rounded-none-none overflow-hidden shadow-2xl flex flex-col h-[85vh]`,a===`dark`?`bg-app border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-center justify-between shrink-0`,a===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`h3`,{className:Y(`text-lg font-semibold leading-none`,`text-z-primary`),children:`Edit Record`}),(0,Q.jsx)(`button`,{type:`button`,onClick:t,"aria-label":`Close`,className:Y(`p-1 transition-colors`,a===`dark`?`text-z-muted hover:text-z-secondary `:`text-z-secondary hover:text-z-secondary`),children:(0,Q.jsx)(B,{size:18})})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-8 custom-scrollbar`,children:u?(0,Q.jsxs)(`div`,{className:`h-full flex items-center justify-center flex-col gap-4`,children:[(0,Q.jsx)(C,{className:`animate-spin text-z-secondary `,size:32}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-secondary`,children:`Loading Document...`})]}):c&&o?(0,Q.jsx)(On,{fields:c.fields,initialData:o,onSubmit:async e=>{p(!0);try{let a=await q.patch(`/${n}/${r}`,e);U.success(`Document updated`),i&&i(a.data.data),t()}catch{U.error(`Update failed`)}finally{p(!1)}},isSubmitting:f}):(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-z-secondary font-semibold text-xs`,children:`Failed to load schema or data.`})})]})})}):null},An=({blockId:e,fieldKey:t,value:n,onChange:r,theme:i,hasMany:a=!1,relationTo:o,anchorEl:s})=>{let[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)([]),[m,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(new Set(n?Array.isArray(n)?n:[n]:[])),x=(0,Z.useRef)(null),S=(0,Z.useRef)(null),w=typeof o==`string`?o:Array.isArray(o)?o[0]:null;(0,Z.useEffect)(()=>{b(new Set(n?Array.isArray(n)?n:[n]:[]))},[n]),(0,Z.useEffect)(()=>{if(!c)return;let e=e=>{x.current&&!x.current.contains(e.target)&&l(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[c]),(0,Z.useEffect)(()=>{c&&S.current&&S.current.focus()},[c]),(0,Z.useEffect)(()=>{c&&w&&T(w,``)},[c,w]);let T=async(e,t)=>{g(!0);try{let n={limit:20};t&&(n.search=t),p((await q.get(`/${e}`,{params:n})).data.data||[])}catch{p([]),U.error(`Failed to fetch relation entries`)}finally{g(!1)}},E=e=>{let t=new Set(y);t.has(e)?t.delete(e):(a||t.clear(),t.add(e)),b(t),r(a?Array.from(t):t.size>0?Array.from(t)[0]:null),a||l(!1)},D=()=>{l(!1),d(``)},O=()=>{b(new Set),r(a?[]:null)},[k,j]=(0,Z.useState)({top:0,left:0});(0,Z.useEffect)(()=>{if(c)if(s){let e=s.getBoundingClientRect();j({top:e.bottom+window.scrollY+4,left:Math.max(8,e.left+window.scrollX)})}else j({top:120,left:window.innerWidth/2-160})},[c,s]);let M=y.size,ee=!n||Array.isArray(n)&&n.length===0?`Manage Relations`:` ${Array.isArray(n)?`${n.length} linked`:`1 linked`}`;return(0,Q.jsxs)(`div`,{className:`relative`,ref:x,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l(!c),className:Y(`w-full px-4 py-3 flex items-center justify-between border text-xs font-bold transition-all rounded-none-none`,i===`dark`?`bg-z-panel/5 border-z-border text-z-secondary hover:bg-z-hover border-z-border-strong`:`bg-z-input border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`),children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(ye,{size:14}),ee]}),(0,Q.jsx)(`span`,{className:`text-xs opacity-60`,children:c?`Close ▲`:`Edit ▼`})]}),(0,Q.jsx)(H,{children:c&&(0,Q.jsxs)(G.div,{initial:{opacity:0,y:-6,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-6,scale:.98},transition:{duration:.15},style:{top:k.top,left:k.left},className:Y(`fixed z-[900] w-80 border rounded-none-none shadow-2xl overflow-hidden flex flex-col`,i===`dark`?`bg-app/98 backdrop-blur-xl border-z-border text-z-primary`:`bg-z-panel/98 backdrop-blur-xl border-z-border text-z-primary`),children:[(0,Q.jsxs)(`div`,{className:Y(`px-4 py-3 border-b flex items-center justify-between shrink-0`,i===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:`Content Relations`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[M>0&&(0,Q.jsxs)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:[M,` selected`]}),(0,Q.jsx)(`button`,{type:`button`,onClick:O,"aria-label":`Clear all selected relations`,className:Y(`p-1 transition-colors`,i===`dark`?`text-z-secondary hover:text-rose-400`:`text-z-muted hover:text-rose-500`),children:(0,Q.jsx)(B,{size:11,"aria-hidden":`true`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>l(!1),"aria-label":`Close relation picker`,className:Y(`p-1 transition-colors`,i===`dark`?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`),children:(0,Q.jsx)(B,{size:12,"aria-hidden":`true`})})]})]}),w?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`shrink-0 px-3 pt-3 pb-2`,children:(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(h,{size:11,className:`absolute left-3 top-1/2 -translate-y-1/2 text-z-secondary`}),(0,Q.jsx)(`input`,{ref:S,type:`text`,placeholder:`Search to link...`,value:u,onChange:e=>{d(e.target.value),T(w,e.target.value)},className:Y(`w-full rounded-none-none py-2 pl-9 pr-3 text-xs font-bold border transition-all`,i===`dark`?`bg-z-hover border-z-border text-z-primary placeholder:text-z-muted`:`bg-z-input border-z-border text-z-primary placeholder:text-z-muted`)})]})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto max-h-56 custom-editor-scrollbar px-2 pb-2 space-y-0.5`,children:m?(0,Q.jsxs)(`div`,{className:`flex items-center justify-center py-8 gap-2`,children:[(0,Q.jsx)(C,{size:14,className:`animate-spin text-z-secondary `}),(0,Q.jsx)(`span`,{className:`text-xs font-bold text-z-secondary animate-pulse`,children:`Searching...`})]}):f.length===0?(0,Q.jsxs)(`div`,{className:`py-8 text-center`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold text-z-secondary`,children:`No results found`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary mt-1`,children:`Try a different search term`})]}):f.map(e=>{let t=e._id||e.id,n=e.title||e.name||e.headline||t,r=y.has(t);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>E(t),className:Y(`w-full flex items-center gap-2.5 px-3 py-2 rounded-none-none text-left text-xs font-semibold transition-all border`,r?i===`dark`?`bg-z-border/15 border-z-border/20 text-z-secondary`:`bg-z-input border-z-border text-z-primary`:i===`dark`?`border-z-border text-z-secondary hover:bg-z-hover hover:border-z-border`:`border-transparent text-z-primary hover:bg-[var(--z-bg-input)] hover:border-z-border shadow-sm`),children:[(0,Q.jsx)(`div`,{className:Y(`w-4 h-4 rounded-none-none border flex items-center justify-center shrink-0 transition-all`,r?`bg-z-border border-z-border text-z-primary`:i===`dark`?`border-z-border bg-z-hover`:`border-z-border-strong bg-z-panel`),children:r&&(0,Q.jsx)(z,{size:9})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:`truncate font-semibold`,children:String(n)}),e._status&&(0,Q.jsx)(`span`,{className:Y(`text-sm font-bold `,e._status===`published`?`text-z-secondary `:`text-amber-500`),children:e._status})]}),a&&r&&(0,Q.jsx)(`div`,{className:`shrink-0 ml-1`,children:(0,Q.jsx)(Ge,{size:10,className:`text-z-secondary`})}),r&&(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v(t)},className:Y(`shrink-0 p-1.5 ml-2 transition-colors border`,`border-z-border hover:bg-[var(--z-bg-hover)] text-z-primary`),title:`Edit Document`,children:(0,Q.jsx)(A,{size:10})})]},t)})}),(0,Q.jsxs)(`div`,{className:Y(`px-3 py-2.5 border-t flex items-center gap-2 shrink-0`,i===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:O,className:Y(`flex-1 py-1.5 text-xs font-semibold border rounded-none-none transition-all`,i===`dark`?`border-z-border text-z-secondary hover:border-rose-500/20 hover:text-rose-400`:`border-z-border text-z-muted hover:border-rose-200 hover:text-rose-500`),children:`Clear`}),(0,Q.jsx)(`button`,{type:`button`,onClick:D,className:Y(`flex-1 py-1.5 text-xs font-semibold rounded-none-none transition-all bg-z-accent text-z-primary hover:bg-z-border`),children:`Done`})]})]}):(0,Q.jsxs)(`div`,{className:`p-6 text-center`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold text-z-secondary mb-1`,children:`No collection configured`}),(0,Q.jsxs)(`p`,{className:`text-xs text-z-secondary`,children:[`Set `,(0,Q.jsx)(`code`,{className:`text-xs`,children:`relationTo`}),` on the field to enable inline relation picker.`]})]})]})}),w&&(0,Q.jsx)(kn,{isOpen:!!_,onClose:()=>v(null),collectionSlug:w,documentId:_||``,onSaved:()=>{T(w,u)}})]})},jn=({item:e,idx:t,theme:n,dzId:r,isExpanded:i,toggleExpand:a,removeItem:s,def:c,blockId:l,fieldName:u,updateItem:d})=>{let p=Ne(),m=c?.title||X((e.__component||``).replace(/^content\./,``)),h=c?.icon||f;return(0,Q.jsxs)(V,{value:e,dragListener:!1,dragControls:p,initial:{opacity:0,height:0},animate:{opacity:1,height:`auto`},exit:{opacity:0,height:0},transition:{duration:.15},as:`div`,className:Y(`border rounded-none-none overflow-hidden`,n===`dark`?`bg-z-panel border-z-border`:`bg-z-input border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2.5 cursor-pointer select-none`,n===`dark`?`bg-z-panel hover:bg-z-hover`:`bg-[var(--z-bg-hover)]/50 hover:bg-[var(--z-bg-hover)]`),onClick:()=>a(r),children:[(0,Q.jsx)(`div`,{onPointerDown:e=>p.start(e),className:`shrink-0 cursor-grab active:cursor-grabbing p-1`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(Ee,{size:12,className:`text-z-secondary`})}),(0,Q.jsx)(`div`,{className:Y(`w-5 h-5 rounded-none-none flex items-center justify-center shrink-0`,n===`dark`?`bg-z-panel/5`:`bg-[var(--z-bg-input)]`),children:(0,Q.jsx)(h,{size:10,className:`text-z-secondary`})}),(0,Q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Q.jsx)(`p`,{className:`text-xs font-semibold text-z-secondary truncate`,children:m})}),(0,Q.jsxs)(`span`,{className:Y(`text-sm font-semibold shrink-0`,`text-z-secondary`),children:[`#`,t+1]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsx)(`button`,{onClick:()=>s(r),className:`p-1 text-z-secondary hover:text-rose-500 transition-colors`,children:(0,Q.jsx)(o,{size:12})}),(0,Q.jsx)(`button`,{onClick:()=>a(r),className:`p-1 text-z-secondary hover:text-z-secondary transition-colors`,children:i?(0,Q.jsx)(Ce,{size:12,className:`text-z-secondary`}):(0,Q.jsx)(We,{size:12,className:`text-z-muted`})})]})]}),(0,Q.jsx)(H,{initial:!1,children:i&&c&&(0,Q.jsx)(G.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:`overflow-hidden`,children:(0,Q.jsx)(`div`,{className:Y(`px-4 py-4 space-y-4 border-t`,`border-z-border`),children:c.fields.map(t=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:t.label||X(t.name)}),(0,Q.jsx)(zn,{blockId:`${l}:${u}:${r}`,field:t,value:e[t.name],onChange:e=>d(r,t.name,e),theme:n})]},t.name))})})})]})},Mn=({blockId:e,fieldName:t,value:n=[],onChange:r,theme:i,components:a})=>{let o=st(),{openComponentPicker:s}=dt(W(e=>({openComponentPicker:e.openComponentPicker}))),[c,l]=(0,Z.useState)(new Set),u=e=>{let t=e?.__component;if(t)return o.find(e=>e.type===t||e.type===t.replace(`content.`,``))},d=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},f=(0,Z.useCallback)(e=>{let t=o.find(t=>t.type===e),i={__component:`content.${e}`,...t?.defaultContent?JSON.parse(JSON.stringify(t.defaultContent)):{}},a=`dz_${Date.now()}_${Math.random().toString(36).slice(2)}`;i._dzId=a,r([...n,i]),l(e=>new Set([...e,a]))},[o,n,r]),p=(0,Z.useCallback)(()=>{s(e=>f(e))},[s,f]),m=e=>{r(n.filter(t=>t._dzId!==e))},h=(e,t,i)=>{r(n.map(n=>n._dzId===e?{...n,[t]:i}:n))},g=e=>{r(e)},_=a&&a.length>0?o.filter(e=>a.includes(e.type)):o;return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,Q.jsx)(N,{size:10,className:`text-z-secondary`}),(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:`Dynamic Zone`}),(0,Q.jsxs)(`span`,{className:`text-xs text-z-secondary`,children:[`— `,n.length,` component`,n.length===1?``:`s`]})]}),n.length===0?(0,Q.jsx)(`div`,{className:Y(`py-5 text-center border border-dashed rounded-none-none`,`border-z-border text-z-secondary`),children:(0,Q.jsx)(`p`,{className:`text-xs font-bold`,children:`No components — add one below`})}):(0,Q.jsx)(qe,{axis:`y`,values:n,onReorder:g,className:`space-y-2`,children:(0,Q.jsx)(H,{initial:!1,children:n.map((n,r)=>{let a=n._dzId||`dz_${r}`;return(0,Q.jsx)(jn,{item:n,idx:r,theme:i,dzId:a,isExpanded:c.has(a),toggleExpand:d,removeItem:m,def:u(n),blockId:e,fieldName:t,updateItem:h},a)})})}),(0,Q.jsxs)(`button`,{type:`button`,onClick:p,className:Y(`w-full flex items-center justify-center gap-2 py-2.5 border border-dashed rounded-none-none transition-all text-xs font-semibold `,i===`dark`?`border-z-border text-z-secondary hover:border-z-border/40 hover:text-z-secondary hover:bg-z-hover`:`border-z-border text-z-muted hover:border-z-border hover:text-z-secondary hover:bg-[var(--z-bg-input)]/50`),children:[(0,Q.jsx)(M,{size:12}),`Add Component`,_.length>0&&(0,Q.jsxs)(`span`,{className:Y(`text-sm font-semibold ml-1`,`text-z-secondary`),children:[`(`,_.length,` available)`]})]})]})},Nn=new Map;function Pn(e){return Nn.get(e)}function Fn(e,t){if(!e)return``;try{let n=new Date(e);return isNaN(n.getTime())?e:t===`datetime`?n.toISOString().slice(0,16):t===`time`?n.toISOString().slice(11,16):n.toISOString().slice(0,10)}catch{return e}}function In(e,t){if(!e)return``;if(t===`time`)return e;try{return new Date(e).toISOString()}catch{return e}}function Ln(e){if(e==null||e===``)return null;let t=typeof e==`string`?e:JSON.stringify(e);try{return JSON.parse(t),!0}catch{return!1}}var Rn=Z.memo(({item:e,idx:t,theme:n,onRemove:r,onChange:i,field:a,blockId:s})=>{let c=Ne();return(0,Q.jsx)(V,{value:e._id||t,dragListener:!1,dragControls:c,as:`div`,children:(0,Q.jsxs)(`div`,{className:Y(`p-3 border rounded-none-none relative transition-all group/item`,n===`dark`?`bg-z-panel/5 border-z-border hover:border-z-border`:`bg-[var(--z-bg-input)] border-z-border hover:border-z-border-strong shadow-sm`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Q.jsx)(`div`,{onPointerDown:e=>c.start(e),className:`cursor-grab`,children:(0,Q.jsx)(Ee,{size:12,className:Y(`opacity-30`,`text-z-secondary`)})}),(0,Q.jsxs)(`span`,{className:Y(`text-sm font-semibold `,`text-z-secondary`),children:[`#`,t+1]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r(t),"aria-label":`Remove item`,className:Y(`ml-auto p-1 transition-colors`,`opacity-0 group-hover/item:opacity-100`,n===`dark`?`text-red-500/50 hover:text-red-400`:`text-red-400/50 hover:text-red-600`),children:(0,Q.jsx)(o,{size:12})})]}),(0,Q.jsx)(`div`,{className:`space-y-3`,children:a.fields?.map(r=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:X(r.name)}),(0,Q.jsx)(zn,{blockId:`${s}-array-${t}`,field:r,value:e[r.name],onChange:e=>i(r.name,e),theme:n})]},r.name))})]})},e._id||t)}),zn=Z.memo(({blockId:e,field:t,value:n,onChange:r,onFieldSelect:i,theme:a,error:s,isSelected:c})=>{let{selectedFieldId:l,setSelectedFieldId:u,setSelectedField:d,data:f}=$(W(e=>({selectedFieldId:e.selectedFieldId,setSelectedFieldId:e.setSelectedFieldId,setSelectedField:e.setSelectedField,data:e.data}))),{openComponentPicker:p,showFieldIndicators:m}=dt(W(e=>({openComponentPicker:e.openComponentPicker,showFieldIndicators:e.showFieldIndicators}))),h=!!c||l===`${e}:${t.name}`;if(t.admin?.condition){let e=t.admin.condition,n=f?.[e.field],r=!1;switch(e.operator){case`equals`:r=n===e.value;break;case`not_equals`:r=n!==e.value;break;case`in`:r=Array.isArray(e.value)&&e.value.includes(n);break;case`not_in`:r=Array.isArray(e.value)&&!e.value.includes(n);break;case`contains`:r=typeof n==`string`&&n.includes(e.value);break;case`exists`:r=e.value?n!=null&&n!==``:n==null||n===``;break}if(!r)return null}let g=()=>{let e=Array.isArray(n)?[...n]:[],i={_id:at()};t.fields?.forEach(e=>{i[e.name]=e.type===`array`?[]:``}),e.push(i),r(e)},_=e=>{Array.isArray(n)&&r(n.filter((t,n)=>n!==e))};return(0,Q.jsxs)(`div`,{className:Y(`stega-field-wrapper relative transition-all duration-200`,m&&`group/field`,h&&`field-selected`),onClick:n=>{n.stopPropagation(),i?i(e,t.name):d({blockId:e,fieldKey:t.name}),$.getState().setActiveSection(e)},style:{padding:m?`2px`:0},children:[m&&(0,Q.jsx)(`div`,{className:`stega-field-indicator`,children:h?(0,Q.jsx)(nt,{size:10}):(0,Q.jsx)(`span`,{className:`text-sm`})}),t.description&&(0,Q.jsx)(`p`,{className:Y(`text-sm font-medium mt-0.5 mb-1`,`text-z-secondary`),children:t.description}),(()=>{let c=Pn(t.type);if(c)return(0,Q.jsx)(c,{blockId:e,field:t,value:n,onChange:r,onFieldSelect:i,theme:a,error:s,isSelected:h});switch(t.type){case`media`:return(0,Q.jsx)(Ut,{value:n,onChange:r,hasMany:t.hasMany});case`richtext`:case`lexical`:return(0,Q.jsx)(`textarea`,{value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter ${t.name}...`,className:Y(`w-full px-4 py-3 text-sm transition-all rounded-none-none min-h-[120px] resize-y`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`email`:return(0,Q.jsx)(`input`,{type:`email`,value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter email address...`,autoComplete:`email`,className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`password`:return(0,Q.jsx)(`input`,{type:`password`,value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter password...`,autoComplete:`new-password`,className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`uid`:{let[e,i]=Z.useState(!n),o=t.sourceField||`title`;return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{type:`text`,value:n||``,onChange:e=>{r(e.target.value),i(!1)},placeholder:t.placeholder||`Auto-generated from ${o}...`,className:Y(`flex-1 px-4 py-2.5 text-xs transition-all rounded-none-none font-mono`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>i(!e),className:Y(`px-2.5 py-2.5 text-sm font-semibold border rounded-none-none transition-all shrink-0`,e?`bg-z-panel border-z-border/30 text-z-secondary`:a===`dark`?`border-z-border text-z-secondary hover:text-z-secondary`:`border-z-border text-z-muted hover:text-z-secondary`),title:e?`Auto-generation enabled`:`Enable auto-generation`,children:e?` Auto`:`Manual`})]}),e&&(0,Q.jsxs)(`p`,{className:Y(`text-sm font-bold px-1`,`text-z-secondary`),children:[`Will be auto-generated from the "`,o,`" field`]})]})}case`color`:{let e=t.options||[`#000000`,`#ffffff`,`#ef4444`,`#f59e0b`,`var(--z-accent)`,`#3b82f6`,`var(--z-accent)`,`var(--z-accent)`,`#ec4899`];return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`relative`,children:(0,Q.jsx)(`input`,{type:`color`,value:n||`#000000`,onChange:e=>r(e.target.value),className:`w-10 h-10 rounded-none-none border cursor-pointer p-0.5`,style:{background:`transparent`}})}),(0,Q.jsx)(`input`,{type:`text`,value:n||``,onChange:e=>r(e.target.value),placeholder:`#000000`,className:Y(`flex-1 px-4 py-2.5 text-xs font-mono transition-all rounded-none-none `,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)})]}),e.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>{let t=typeof e==`string`?e:e.value,i=typeof e==`string`?e:e.label;return(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r(t),className:Y(`w-6 h-6 rounded-none-none border-2 transition-all`,n===t?`border-z-border scale-110`:`border-z-border hover:border-z-border`),style:{backgroundColor:t},title:i},t)})})]})}case`text`:return(0,Q.jsx)(`input`,{type:`text`,value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter ${X(t.name)}...`,className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`textarea`:return(0,Q.jsx)(`textarea`,{value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter ${X(t.name)}...`,rows:4,className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none resize-y`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`code`:return(0,Q.jsx)(`textarea`,{value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter ${t.language||`code`}...`,rows:8,spellCheck:!1,className:Y(`w-full px-4 py-2.5 text-xs font-mono transition-all rounded-none-none resize-y`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-[#e6edf3]`:`bg-z-accent border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`collapsible`:{let i=t.fields||[],o=n&&typeof n==`object`?n:{};return(0,Q.jsx)(`div`,{className:Y(`border-l-2 pl-3 space-y-2`,a===`dark`?`border-z-border/30`:`border-z-border-strong`),children:i.map(n=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:X(n.name)}),(0,Q.jsx)(zn,{blockId:`${e}:${t.name}`,field:n,value:o[n.name],onChange:e=>r({...o,[n.name]:e}),theme:a})]},n.name))})}case`join`:return(0,Q.jsx)(`div`,{className:Y(`w-full px-4 py-3 border text-xs rounded-none-none`,a===`dark`?`bg-z-hover border-z-border/20 text-z-secondary`:`bg-z-input border-z-border text-z-secondary`),children:`⧉ Joined data — read-only`});case`point`:{let e=Array.isArray(n)&&n.length===2&&!isNaN(n[0])&&!isNaN(n[1])?n:[0,0];return(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-secondary`,children:`Lng`}),(0,Q.jsx)(`input`,{type:`number`,value:e[0],onChange:t=>r([Number(t.target.value),e[1]]),step:`any`,className:Y(`w-full px-3 py-2 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)})]}),(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-secondary`,children:`Lat`}),(0,Q.jsx)(`input`,{type:`number`,value:e[1],onChange:t=>r([e[0],Number(t.target.value)]),step:`any`,className:Y(`w-full px-3 py-2 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)})]})]})}case`radio`:{let i=t.options||[];return(0,Q.jsx)(`div`,{className:Y(`flex gap-3`,t.layout===`horizontal`?`flex-row flex-wrap`:`flex-col gap-1.5`),children:i.map(i=>{let o=typeof i==`string`?i:i.value,s=typeof i==`string`?i:i.label;return(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`radio`,name:`${e}:${t.name}`,value:o,checked:n==o,onChange:e=>{r(typeof o==`number`?Number(e.target.value):e.target.value)},className:`w-3.5 h-3.5 accent-gray-500`}),(0,Q.jsx)(`span`,{className:Y(`text-xs`,a===`dark`?`text-z-secondary`:`text-z-primary`),children:s})]},o)})})}case`row`:{let i=t.fields||[],o=n&&typeof n==`object`?n:{};return(0,Q.jsx)(`div`,{className:`flex gap-2 items-end`,children:i.map(n=>(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:X(n.name)}),(0,Q.jsx)(zn,{blockId:`${e}:${t.name}`,field:n,value:o[n.name],onChange:e=>r({...o,[n.name]:e}),theme:a})]},n.name))})}case`ui`:{let e=t.admin?.components?.Field;return e?(0,Q.jsx)(e,{field:t,value:n,onChange:r}):null}case`number`:return(0,Q.jsx)(`input`,{type:`number`,value:n??``,onChange:e=>{r(e.target.value===``?``:Number(e.target.value))},placeholder:t.placeholder||`Enter ${X(t.name)}...`,className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`boolean`:case`checkbox`:return(0,Q.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer py-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:!!n,onChange:e=>r(e.target.checked),className:`w-4 h-4 rounded-none-none border border-z-border bg-z-hover checked:bg-[var(--z-bg-input)] checked:border-z-border transition-all accent-gray-500`}),(0,Q.jsx)(`span`,{className:Y(`text-xs font-medium`,a===`dark`?`text-z-secondary`:`text-z-primary`),children:X(t.name)})]});case`select`:{let e=t.options||[],i=!!t.hasMany,[o,s]=Z.useState(!1),c=Z.useRef(null),l=i?Array.isArray(n)?n:[]:n!=null&&n!==``?[n]:[],u=e=>typeof e==`string`?e:e.label,d=e=>typeof e==`string`?e:e.value,f=l.map(t=>u(e.find(e=>d(e)===t))||String(t)).join(`, `),p=e=>{if(i){let t=Array.isArray(n)?[...n]:[],i=t.indexOf(e);i>=0?t.splice(i,1):t.push(e),r(t)}else r(e),s(!1)};return Z.useEffect(()=>{if(!o)return;let e=e=>{c.current&&!c.current.contains(e.target)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[o]),(0,Q.jsxs)(`div`,{className:`relative`,ref:c,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(!o),className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none flex items-center justify-between gap-2`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`),children:[(0,Q.jsx)(`span`,{className:Y(`truncate`,!l.length&&`text-z-secondary`),children:f||`Select option...`}),(0,Q.jsx)(`svg`,{className:Y(`w-3 h-3 shrink-0 transition-transform`,o&&`rotate-180`,a===`dark`?`text-z-muted`:`text-z-secondary`),fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,Q.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 9l-7 7-7-7`})})]}),o&&(0,Q.jsxs)(`div`,{className:Y(`absolute z-50 left-0 right-0 mt-1 border shadow-xl max-h-60 overflow-y-auto`,a===`dark`?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),children:[i&&l.length>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r([]),className:Y(`w-full text-left px-3 py-1.5 text-sm font-semibold `,a===`dark`?`text-z-secondary hover:bg-z-hover`:`text-z-muted hover:bg-[var(--z-bg-input)]`),children:`Clear all`}),e.map(e=>{let t=u(e),n=d(e),r=l.includes(n);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>p(n),className:Y(`w-full text-left px-3 py-2 text-xs flex items-center gap-2 transition-colors`,r?a===`dark`?`bg-z-panel/5 text-z-secondary`:`bg-[var(--z-bg-input)] text-z-secondary`:a===`dark`?`text-z-secondary hover:bg-z-hover`:`text-z-primary hover:bg-[var(--z-bg-input)]`),children:[(0,Q.jsx)(`span`,{className:Y(`w-3.5 h-3.5 border shrink-0 flex items-center justify-center transition-all rounded-none-none`,r?`bg-z-border border-z-border`:a===`dark`?`border-z-border`:`border-z-border-strong`),children:r&&(0,Q.jsx)(`svg`,{className:`w-2.5 h-2.5 text-z-primary`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,Q.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:3,d:`M5 13l4 4L19 7`})})}),(0,Q.jsx)(`span`,{className:`font-bold truncate`,children:t})]},n)})]})]})}case`relation`:return(0,Q.jsx)(An,{blockId:e,fieldKey:t.name,value:n,onChange:r,theme:a,hasMany:t.hasMany,relationTo:t.relationTo,anchorEl:null});case`date`:{let e=t.dateFormat||`date`;return(0,Q.jsx)(`input`,{type:e===`datetime`?`datetime-local`:e===`time`?`time`:`date`,value:n?Fn(n,e):``,onChange:t=>r(t.target.value?In(t.target.value,e):``),className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)})}case`array`:{let i=Array.isArray(n)?n:[],o=e=>{let t=new Set(i.map((e,t)=>e._id??t));e.every((e,n)=>t.has(e._id??n))&&r(e)};return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:[i.length,` `,i.length===1?`Item`:`Items`]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:g,className:Y(`flex items-center gap-1 px-2.5 py-1 text-xs font-semibold transition-all border`,a===`dark`?`bg-z-panel/5 border-z-border text-z-secondary hover:bg-z-hover border-z-border-strong`:`bg-z-input border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`),children:[(0,Q.jsx)(M,{size:10}),` Add Item`]})]}),(0,Q.jsx)(qe,{axis:`y`,values:i.map((e,t)=>e._id||t),onReorder:e=>{let t=new Map(i.map((e,t)=>[e._id||t,e]));o(e.map(e=>t.get(e)).filter(Boolean))},className:`space-y-3`,children:i.map((n,o)=>(0,Q.jsx)(Rn,{item:n,idx:o,theme:a,onRemove:_,onChange:(e,t)=>{let n=[...i];n[o]={...n[o],[e]:t},r(n)},field:t,blockId:e,humanize:X},n._id||o))})]})}case`group`:{let i=n&&typeof n==`object`?n:{};return(0,Q.jsx)(`div`,{className:`border-l border-z-border/20 pl-3 space-y-3`,children:t.fields?.map(n=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:X(n.name)}),(0,Q.jsx)(zn,{blockId:`${e}:${t.name}`,field:n,value:i[n.name],onChange:e=>r({...i,[n.name]:e}),theme:a})]},n.name))})}case`json`:{let e=Ln(n);return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`textarea`,{value:typeof n==`string`?n:JSON.stringify(n,null,2)??``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter JSON...`,rows:8,spellCheck:!1,className:Y(`w-full px-4 py-2.5 text-xs font-mono transition-all rounded-none-none resize-y`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-[#e6edf3]`:`bg-z-accent border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:Y(`inline-block w-1.5 h-1.5 rounded-none-none`,e===!0?`bg-z-border shadow-sm`:e===!1?`bg-red-500 shadow-[0_0_6px_#ef4444]`:`bg-z-accent`)}),(0,Q.jsx)(`span`,{className:`text-xs font-bold`,style:{color:e===!0?`var(--z-accent)`:e===!1?`#ef4444`:`#6b7280`},children:e===!0?`Valid JSON`:e===!1?`Invalid JSON`:`JSON`})]})]})}case`blocks`:{let i=n&&Array.isArray(n)?n:[],s=t.blocks||[];return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[i.length>0&&(0,Q.jsx)(`div`,{className:`space-y-2`,children:i.map((n,c)=>{let l=n.blockType||n.__blockType,u=s.find(e=>e.slug===l),d=u?.fields||[];return(0,Q.jsxs)(`div`,{className:Y(`border rounded-none-none overflow-hidden`,a===`dark`?`bg-z-panel/5 border-z-border`:`bg-z-input border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2 border-b`,a===`dark`?`bg-z-panel/5 border-z-border`:`bg-[var(--z-bg-hover)]/50 border-z-border`),children:[(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold px-1.5 py-0.5 border rounded-none-none`,a===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-primary`),children:u?.labels?.singular||X(l||`block`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{r(i.filter((e,t)=>t!==c))},className:`ml-auto p-1 text-z-secondary hover:text-rose-500 transition-colors`,"aria-label":`Remove block`,children:(0,Q.jsx)(o,{size:10})})]}),(0,Q.jsx)(`div`,{className:`px-3 py-3 space-y-3`,children:d.map(o=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:o.label||X(o.name)}),(0,Q.jsx)(zn,{blockId:`${e}:${t.name}:${c}`,field:o,value:n[o.name],onChange:e=>{let t=[...i];t[c]={...t[c],[o.name]:e},r(t)},theme:a})]},o.name))})]},n._id||c)})}),(!t.maxRows||i.length<t.maxRows)&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{p(e=>{let t={blockType:e,_id:at()};r([...i,t])},s.length>0?s:void 0)},className:Y(`w-full py-2.5 border-2 border-dashed flex flex-col items-center justify-center gap-1.5 transition-all group rounded-none-none`,a===`dark`?`border-z-border hover:border-z-border/50 hover:bg-z-hover text-z-muted hover:text-z-secondary`:`border-z-border-strong hover:border-z-border hover:bg-[var(--z-bg-input)] text-z-secondary hover:text-z-secondary`),children:[(0,Q.jsx)(`div`,{className:Y(`p-1.5 rounded-none-none transition-colors`,a===`dark`?`bg-z-hover group-hover:bg-z-hover border-z-border-strong`:`bg-[var(--z-bg-hover)] group-hover:bg-[var(--z-bg-hover)]`),children:(0,Q.jsx)(M,{size:14,className:`stroke-[3]`})}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:`Add Block`})]})]})}case`tabs`:{let i=t.tabs||[],[o,s]=(0,Z.useState)(0),c=n&&typeof n==`object`?n:{};return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[i.length>1&&(0,Q.jsx)(`div`,{className:Y(`flex gap-0.5 p-0.5 rounded-none-none border`,`bg-z-panel border-z-border`),children:i.map((e,t)=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:Y(`px-3 py-1.5 text-sm font-semibold transition-all`,o===t?a===`dark`?`bg-z-hover text-z-primary`:`bg-z-panel text-z-primary shadow-sm`:a===`dark`?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`),children:e.label||`Tab ${t+1}`},e.label||t))}),i[o]&&(0,Q.jsx)(`div`,{className:`space-y-3`,children:i[o].fields?.map(n=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:n.label||X(n.name)}),(0,Q.jsx)(zn,{blockId:`${e}:${t.name}`,field:n,value:c[n.name],onChange:e=>r({...c,[n.name]:e}),theme:a})]},n.name))})]})}case`dz`:return(0,Q.jsx)(Mn,{blockId:e,fieldName:t.name,value:n||[],onChange:r,theme:a,components:t.components||[]});default:return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border border-dashed border-red-500/30 text-red-400 text-xs`,children:[(0,Q.jsx)(S,{size:14}),` Unsupported field type: `,t.type]})}})(),s&&(0,Q.jsx)(`p`,{className:`text-xs text-red-500 mt-1`,role:`alert`,"aria-live":`polite`,children:s})]})}),Bn=(e,t)=>{let n=e.toLowerCase();return n.includes(`image`)||n.includes(`photo`)||n.includes(`thumbnail`)||n.includes(`cover`)||n.includes(`banner`)||n.includes(`logo`)?`media`:n.includes(`content`)||n.includes(`description`)||n.includes(`bio`)||typeof t==`string`&&t.length>200?`richtext`:Array.isArray(t)?`array`:typeof t==`object`&&t?`group`:`text`},Vn=({section:e,index:t,totalSections:n,isActive:r,isMultiSelected:a=!1,onSelect:c,onDuplicate:l,onDelete:u,onAlign:d,onFieldChange:f,onToggleCollapse:p,onMoveUp:m,onMoveDown:h,onCopy:g,onPaste:_,onBlockNameChange:v,onFieldSelect:y,theme:x,showFieldIndicators:S,selectedField:C,schemaFields:w,fieldErrors:T={},i18nEnabled:E,currentLocale:O,getTranslatedValue:k,setTranslatedValue:j,onAddToDynamicZone:M,dragControls:ee,onContextMenu:N})=>{let P=st().find(t=>t.type===e.blockType),[F,I]=Z.useState(!1),te=Z.useRef(null),re=Z.useRef(null),[L,ie]=Z.useState(null),[ae,oe]=Z.useState(!1),se=Z.useRef(null),{undo:le,redo:ue}=$();Z.useEffect(()=>{if(!F)return;let e=e=>{re.current?.contains(e.target)||te.current&&!te.current.contains(e.target)&&I(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[F]);let R=(e,t)=>{f(e,t)},de=e.blockType===`callout`,fe=e.content?.type||`info`,z=de?{info:`border-l-4 border-l-sky-500 bg-sky-500/5`,warning:`border-l-4 border-l-amber-500 bg-amber-500/5`,success:`border-l-4 border-z-border bg-z-hover`,error:`border-l-4 border-l-rose-500 bg-rose-500/5`}[fe]||`border-l-4 border-l-sky-500 bg-sky-500/5`:``,pe=e.content?.theme||`default`,B=e.content?.paddingY||`medium`,me=e.content?.containerWidth||`boxed`,V=e.content?.anchorId||void 0,ge={default:``,light:`bg-z-panel/90 text-z-primary border-z-border shadow-sm`,dark:`bg-z-popover text-z-primary border-z-border shadow-lg`,"cyber-gray":`bg-gradient-to-br from-[var(--z-bg-panel)] via-[var(--z-bg-base)] to-[var(--z-bg-panel)] text-z-primary border-z-border/20 shadow-sm/5`,glassmorphic:`bg-z-input backdrop-blur-[12px] border-z-border shadow-sm text-z-primary`}[pe]||``,_e={none:`py-2 px-6`,small:`py-6 px-6`,medium:`py-12 px-6`,large:`py-20 px-8`}[B]||`py-6 px-6`,ye={boxed:`max-w-6xl mx-auto`,"full-width":`w-full`}[me]||``,be=Object.keys(T).filter(t=>t.startsWith(e.id+`:`)).length,xe=Z.useMemo(()=>P?.fields?P.fields:Object.keys(e.content||{}).map(t=>{let n=e.content[t];return{name:t,type:Bn(t,n),label:t.replace(/_/g,` `).replace(/([A-Z])/g,` $1`).replace(/^./,e=>e.toUpperCase()).trim()}}),[P,e.content]);Z.useMemo(()=>xe.filter(e=>e.name!==`content`&&e.name!==`description`&&e.name!==`bio`&&e.type!==`richtext`).length,[xe]);let Se=e.collapsed??!1;return(0,Q.jsxs)(`div`,{id:V||e.id,onClick:c,onContextMenu:N,className:Y(`rounded-none-none border transition-all duration-500 relative cursor-pointer`,z,ge||(x===`dark`?`bg-z-panel border-z-border hover:border-z-border`:`bg-z-panel border-z-border shadow-sm hover:border-z-border`),r&&`ring-2 ring-z-active-border scale-[1.005]`,a&&!r&&`ring-2 ring-amber-500/40`),children:[(0,Q.jsxs)(`div`,{className:Y(`flex items-center justify-between px-6 py-4 border-b select-none`,Se?`border-b-0`:``,x===`dark`?`border-z-border bg-z-panel`:`border-z-border shadow-sm bg-[var(--z-bg-input)]/50`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,Q.jsx)(`div`,{onPointerDown:e=>ee&&ee.start(e),title:`Drag to reorder`,role:`button`,"aria-label":`Drag to reorder section`,"aria-grabbed":`false`,tabIndex:-1,className:Y(`w-7 h-7 rounded-none-none border flex items-center justify-center cursor-grab active:cursor-grabbing shrink-0 transition-all`,x===`dark`?`bg-z-hover border-z-border text-z-muted/60 hover:bg-z-panel hover:border-z-border/30 hover:text-z-secondary`:`bg-[var(--z-bg-hover)] border-z-border text-z-secondary/60 hover:bg-[var(--z-bg-input)] hover:border-z-border-strong hover:text-z-secondary`),children:(0,Q.jsx)(i,{size:12,"aria-hidden":`true`})}),(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold leading-none w-5 text-center`,`text-z-secondary`),children:String(t+1).padStart(2,`0`)}),(0,Q.jsx)(`span`,{className:Y(`px-2 py-0.5 text-sm font-semibold border shrink-0`,x===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-primary`),children:X(e.blockType)}),ae?(0,Q.jsx)(`input`,{ref:se,autoFocus:!0,value:e.blockName||``,onChange:e=>v(e.target.value),onBlur:()=>oe(!1),onKeyDown:e=>{e.key===`Enter`&&oe(!1)},onClick:e=>e.stopPropagation(),className:Y(`text-xs font-semibold bg-transparent border-b px-1 min-w-[80px] max-w-[200px]`,x===`dark`?`text-z-primary border-z-border`:`text-z-primary border-z-border-strong`),placeholder:`Block name...`}):(0,Q.jsxs)(`span`,{onClick:e=>{e.stopPropagation(),oe(!0),setTimeout(()=>se.current?.focus(),0)},className:Y(`text-xs font-semibold truncate cursor-text px-1 flex items-center gap-1.5`,e.blockName?`text-z-primary`:`text-z-secondary`),children:[e.blockName||`Add name...`,(0,Q.jsx)(A,{size:10,className:`opacity-0 group-hover/item:opacity-40 transition-opacity`})]}),be>0&&(0,Q.jsxs)(`span`,{className:`px-1.5 py-0.5 text-sm font-semibold bg-rose-500/10 border border-rose-500/20 text-rose-500 shrink-0`,children:[be,` error`,be===1?``:`s`]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p()},className:Y(`p-1.5 rounded-none-none border transition-all`,x===`dark`?`text-z-secondary border-transparent hover:text-z-secondary`:`text-z-muted border-transparent hover:text-z-secondary `),title:Se?`Expand`:`Collapse`,children:Se?(0,Q.jsx)(ce,{size:12}):(0,Q.jsx)(We,{size:12})}),(0,Q.jsx)(`button`,{ref:re,onClick:e=>{if(e.stopPropagation(),!F&&re.current){let e=re.current.getBoundingClientRect();ie({top:e.bottom+4,left:e.right-160})}I(!F)},className:Y(`p-1.5 rounded-none-none border transition-all`,F?x===`dark`?`bg-z-hover border-z-border-strong border-z-border/30 text-z-secondary`:`bg-[var(--z-bg-hover)] border-z-border text-z-secondary`:x===`dark`?`text-z-secondary border-transparent hover:text-z-secondary`:`text-z-muted border-transparent hover:text-z-secondary `),title:`Actions`,children:(0,Q.jsx)(ne,{size:14})})]})]}),(0,Q.jsx)(H,{initial:!1,children:!Se&&(0,Q.jsx)(G.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:`overflow-visible`,children:(0,Q.jsxs)(`div`,{className:Y(`transition-all duration-300`,_e,ye),children:[(0,Q.jsxs)(`div`,{className:Y(`flex items-center justify-between -mx-6 -mt-6 mb-6 px-4 py-2 border-b`,x===`dark`?`bg-z-panel/5 border-z-border`:`bg-[var(--z-bg-input)]/50 border-z-border shadow-sm`),children:[(0,Q.jsx)(`div`,{className:Y(`flex items-center gap-0.5 p-0.5 rounded-none-none border`,x===`dark`?`bg-app/20 border-z-border`:`bg-z-panel border-z-border`),children:[`left`,`center`,`right`].map(t=>(0,Q.jsxs)(`button`,{"aria-label":`Align ${t}`,onClick:e=>{e.stopPropagation(),d(t)},className:Y(`p-1 transition-all`,e.align===t||!e.align&&t===`left`?x===`dark`?`bg-z-hover text-z-primary`:`bg-app text-z-primary shadow-sm`:`text-z-muted hover:text-z-secondary `),children:[t===`left`&&(0,Q.jsx)(s,{size:10}),t===`center`&&(0,Q.jsx)(Oe,{size:10}),t===`right`&&(0,Q.jsx)(D,{size:10})]},t))}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,Q.jsx)(`span`,{className:Y(`text-sm font-bold select-none`,x===`dark`?`text-z-primary`:`text-z-muted`),title:`Use Ctrl+Z / Ctrl+Y to undo or redo changes`,children:`Ctrl+Z / Ctrl+Y to undo/redo`})})]}),e.blockType===`code`&&(0,Q.jsxs)(`div`,{className:Y(`w-full px-4 py-2 border-b flex items-center justify-between -mx-6 -mt-6 mb-6`,x===`dark`?`bg-[#0F172A]/80 border-z-border`:`bg-[var(--z-bg-hover)] border-z-border`),children:[(0,Q.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-none-none bg-rose-500`}),(0,Q.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-none-none bg-amber-500`}),(0,Q.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-none-none bg-z-border`})]}),(0,Q.jsxs)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:[e.content?.language||`javascript`,` terminal`]})]}),e.blockType===`table`?(0,Q.jsx)(`div`,{className:`w-full overflow-x-auto border border-z-border bg-app/20 p-4 rounded-none-none`,children:(0,Q.jsx)(`div`,{className:`overflow-x-auto min-w-full pb-4`,children:(0,Q.jsxs)(`table`,{className:`w-full border-collapse text-left text-xs font-mono`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:Y(x===`dark`?`bg-z-hover border-b border-z-border`:`bg-[var(--z-bg-hover)] border-b border-z-border`),children:[(e.content?.headers||[]).map((t,n)=>(0,Q.jsx)(`th`,{className:`p-2.5`,children:(0,Q.jsx)(`input`,{type:`text`,value:t.text||``,onChange:t=>{let r=[...e.content.headers||[]];r[n]={...r[n],text:t.target.value},R(`headers`,r)},className:`bg-transparent border-none font-bold w-full focus:bg-z-hover focus-visible:ring-2 focus-visible:ring-z-active-border rounded-none px-1 text-xs`,placeholder:`Header ${n+1}`})},n)),(0,Q.jsx)(`th`,{className:`w-10`,children:(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation();let n=[...e.content.headers||[]];n.push({text:``}),R(`headers`,n),R(`rows`,(e.content.rows||[]).map(e=>({cells:[...e.cells||[],{text:``}]})))},className:`text-xs text-z-secondary font-bold hover:text-z-secondary`,children:`+ Col`})})]})}),(0,Q.jsxs)(`tbody`,{children:[(e.content?.rows||[]).map((t,n)=>(0,Q.jsxs)(`tr`,{className:Y(x===`dark`?`border-b border-z-border hover:bg-z-panel`:`border-b border-z-border hover:bg-[var(--z-bg-input)]`),children:[(t.cells||[]).map((t,r)=>(0,Q.jsx)(`td`,{className:`p-2`,children:(0,Q.jsx)(`input`,{type:`text`,value:t.text||``,onChange:t=>{let i=[...e.content.rows||[]],a=[...i[n].cells||[]];a[r]={...a[r],text:t.target.value},i[n]={...i[n],cells:a},R(`rows`,i)},className:`bg-transparent border-none w-full focus:bg-z-hover focus-visible:ring-2 focus-visible:ring-z-active-border rounded-none px-1`,placeholder:`Cell...`})},r)),(0,Q.jsx)(`td`,{className:`p-2`,children:(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),R(`rows`,(e.content.rows||[]).filter((e,t)=>t!==n))},className:`text-xs text-rose-500 font-bold hover:text-rose-400`,children:`Delete`})})]},n)),(0,Q.jsx)(`tr`,{children:(0,Q.jsx)(`td`,{colSpan:(e.content?.headers||[]).length+1,className:`p-2`,children:(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation();let n=[...e.content.rows||[]],r=(e.content?.headers||[]).length,i=Array.from({length:r},()=>({text:``}));n.push({cells:i}),R(`rows`,n)},className:`text-xs text-z-secondary font-bold hover:text-z-secondary flex items-center gap-1`,children:`+ Add Row`})})})]})]})})}):(0,Q.jsxs)(`div`,{className:`space-y-8`,children:[(0,Q.jsx)(`div`,{className:Y(`gap-8`,xe.filter(e=>![`anchorId`,`theme`,`paddingY`,`containerWidth`,`bgImage`].includes(e.name)&&e.name!==`content`&&e.name!==`description`&&e.name!==`bio`&&e.type!==`richtext`).length>=4?`grid grid-cols-1 md:grid-cols-2`:`space-y-6`,e.align===`center`&&`text-center`,e.align===`right`&&`text-right`),children:xe.filter(e=>![`anchorId`,`theme`,`paddingY`,`containerWidth`,`bgImage`].includes(e.name)).map(t=>{let n=e.content?.[t.name],r=E&&k?k(e.id,t.name,n):n,i=t.name===`content`||t.name===`description`||t.name===`bio`||t.type===`richtext`,a=`${e.id}:${t.name}`;return(0,Q.jsxs)(`div`,{className:Y(`space-y-2`,i&&`md:col-span-2`),children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`label`,{className:`text-sm font-semibold text-z-secondary px-1`,children:t.label||t.name}),(0,Q.jsx)(`span`,{className:Y(`px-2 py-0.5 text-[10px] uppercase tracking-wider font-bold rounded-none-none border`,x===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-[var(--z-bg-hover)] border-z-border text-z-muted`),children:t.type}),T[a]&&(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-rose-500 ml-auto`,children:T[a]})]}),t.description&&(0,Q.jsx)(`p`,{className:Y(`text-xs font-medium px-1.5 opacity-60`,x===`dark`?`text-z-muted`:`text-z-secondary`),children:t.description})]}),(0,Q.jsx)(zn,{blockId:e.id,field:t,value:r,onChange:n=>{E&&O!==`en`&&j?j(e.id,t.name,n):R(t.name,n)},onFieldSelect:y,theme:x,error:T[a],isSelected:C?.blockId===e.id&&C?.fieldKey===t.name})]},t.name)})}),xe.some(e=>[`anchorId`,`theme`,`paddingY`,`containerWidth`,`bgImage`].includes(e.name))&&(0,Q.jsxs)(`div`,{className:Y(`pt-6 mt-6 border-t`,`border-z-border`),children:[(0,Q.jsx)(`h4`,{className:`text-sm font-semibold text-z-secondary/50 mb-4 px-1`,children:`Layout & Styling`}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4`,children:xe.filter(e=>[`anchorId`,`theme`,`paddingY`,`containerWidth`,`bgImage`].includes(e.name)).map(t=>{let n=e.content?.[t.name],r=E&&k?k(e.id,t.name,n):n,i=`${e.id}:${t.name}`;return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Q.jsx)(`label`,{className:`text-sm font-semibold text-z-secondary px-1`,children:t.label||t.name})}),(0,Q.jsx)(zn,{blockId:e.id,field:t,value:r,onChange:n=>{E&&O!==`en`&&j?j(e.id,t.name,n):R(t.name,n)},onFieldSelect:y,theme:x,error:T[i],isSelected:C?.blockId===e.id&&C?.fieldKey===t.name})]},t.name)})})]})]})]})})}),F&&L&&(0,Vt.createPortal)((0,Q.jsx)(`div`,{ref:te,style:{position:`fixed`,top:L.top,left:L.left,zIndex:900},className:Y(`min-w-[160px] border shadow-xl rounded-none-none`,x===`dark`?`bg-app border-z-border`:`bg-z-panel border-z-border`),onClick:e=>e.stopPropagation(),children:(0,Q.jsxs)(`div`,{className:`py-1`,children:[t>0&&(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(ve,{size:12}),label:`Move Up`,onClick:()=>{m(),I(!1)},theme:x}),t<n-1&&(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(Qe,{size:12}),label:`Move Down`,onClick:()=>{h(),I(!1)},theme:x}),(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(b,{size:12}),label:`Duplicate`,onClick:()=>{l(),I(!1)},theme:x}),(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(he,{size:12}),label:`Copy`,onClick:()=>{g(),I(!1)},theme:x}),(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(Ke,{size:12}),label:`Paste`,onClick:()=>{_(),I(!1)},theme:x}),(0,Q.jsx)(`div`,{className:Y(`border-t my-1`,x===`dark`?`border-z-border`:`border-z-border shadow-sm`)}),(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(o,{size:12}),label:`Remove`,onClick:()=>{u(),I(!1)},theme:x,danger:!0})]})}),document.body)]})},Hn=({icon:e,label:t,onClick:n,theme:r,danger:i})=>(0,Q.jsxs)(`button`,{onClick:n,className:Y(`w-full flex items-center gap-3 px-3 py-2 text-sm font-semibold transition-all`,i?`text-rose-500 hover:bg-rose-500/10`:r===`dark`?`text-z-muted hover:bg-z-hover hover:text-z-primary`:`text-z-secondary hover:bg-[var(--z-bg-input)] hover:text-z-primary`),children:[(0,Q.jsx)(`span`,{className:`opacity-60`,children:e}),t]}),Un=({addBlock:e})=>{let{blockPickerOpen:t,setBlockPickerOpen:n,openComponentPicker:r}=dt(W(e=>({blockPickerOpen:e.blockPickerOpen,setBlockPickerOpen:e.setBlockPickerOpen,openComponentPicker:e.openComponentPicker})));return(0,Z.useEffect)(()=>{t&&(r(t=>{e(t)}),n(!1))},[t]),null},Wn=e=>(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:(0,Q.jsx)(`path`,{d:`M22 4s-.7 2.1-2 3.4c1.6 10-9.4 17.3-18 11.6 2.2.1 4.4-.6 6-2C3 15.5.5 9.6 3 5c2.2 2.6 5.6 4.1 9 4-.9-4.2 4-6.6 7-3.8 1.1 0 3-1.2 3-1.2z`})}),Gn=e=>(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:(0,Q.jsx)(`path`,{d:`M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z`})}),Kn=[`title`,`description`,`keywords`],qn=({onSave:e})=>{let{theme:t}=K(),{data:n,updateData:r}=$(),{seoOpen:i,setSeoOpen:a}=dt(W(e=>({seoOpen:e.seoOpen,setSeoOpen:e.setSeoOpen}))),o=localStorage.getItem(`activeSiteSlug`),[s,c]=(0,Z.useState)({title:``,description:``,keywords:``}),[l,u]=(0,Z.useState)(`google`),[d,f]=(0,Z.useState)({}),m=async e=>{f(t=>({...t,[e]:!0}));try{let t=it(n?.sections);if(!t)throw Error(`No content available to analyze`);let r;e===`description`?(r=await q.post(`/content-tools/ai/meta-description`,{title:s.title||n?.title||`Untitled`,content:t}),r.data?.data?.description&&(O(e,r.data.data.description),fe.success(`Generated description`))):e===`title`?(r=await q.post(`/content-tools/ai/generate`,{prompt:`Write a highly optimized, compelling SEO title (max 60 chars) for this page. The page content is: ${t}. Follow SEO best practices: include the primary keyword near the beginning if possible, keep it engaging but accurate, and avoid clickbait.`}),r.data?.data?.text&&(O(e,r.data.data.text.replace(/["']/g,``).trim()),fe.success(`Generated title`))):e===`keywords`&&(r=await q.post(`/content-tools/ai/generate`,{prompt:`Extract exactly 5 highly relevant SEO keywords as a simple comma-separated list from this content: ${t}. Ensure these are context-based, specific, and reflect the true topic of the page.`}),r.data?.data?.text&&(O(e,r.data.data.text.trim()),fe.success(`Generated keywords`)))}catch(e){fe.error(e?.response?.data?.error?.message||`Failed to generate content`)}finally{f(t=>({...t,[e]:!1}))}},h=o===`blog-demo`?`https://blog-demo.zenith.dev`:o===`storefront-glass`?`https://storefront.zenith.dev`:o===`demo`?`https://demo.zenith.dev`:`https://zenith.dev`,g=n?.title?`${h}/${n.title.toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``)}`:`${h}/page`,_=s.title||n?.title||`Page Title`,v=s.description||n?.heroDescription||`Your page description goes here. This is what search engines will display in search results.`,y=s.keywords||``,b=n?.meta?.ogImage||``,S=e=>e.length,w=(e,t)=>e.length>t?e.slice(0,t)+`…`:e;(0,Z.useEffect)(()=>{i&&c({title:n?.meta?.title||``,description:n?.meta?.description||``,keywords:n?.meta?.keywords||``})},[i,n]);let T=(0,Z.useRef)(null),D=`seo-modal-title`;ut(i,{onEscape:()=>a(!1),containerRef:T});let O=(e,t)=>{c(n=>({...n,[e]:t}))};return(0,Q.jsx)(H,{children:i&&(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[600] flex items-center justify-center p-6 bg-[var(--z-bg-modal)] backdrop-blur-sm`,children:(0,Q.jsxs)(G.div,{ref:T,role:`dialog`,"aria-modal":`true`,"aria-labelledby":D,initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:Y(`w-full max-w-lg border rounded-none-none overflow-hidden shadow-2xl flex flex-col max-h-[85vh]`,t===`dark`?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-center justify-between`,t===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`h3`,{id:D,className:Y(`text-lg font-semibold leading-none`,`text-z-primary`),children:`SEO Meta`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(!1),"aria-label":`Close`,className:`p-1 hover:text-z-secondary transition-colors`,children:(0,Q.jsx)(B,{size:18})})]}),(0,Q.jsxs)(`div`,{className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-1 p-1 border border-z-border bg-z-panel rounded-none-none shrink-0`,children:[{id:`google`,icon:E,label:`Google`},{id:`twitter`,icon:Wn,label:`Twitter / X`},{id:`facebook`,icon:Gn,label:`Facebook`}].map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>u(e.id),"aria-label":`${e.label} preview`,className:Y(`flex items-center gap-2 px-3 py-2 text-xs font-semibold transition-all border rounded-none-none flex-1 justify-center`,l===e.id?t===`dark`?`bg-z-panel/10 border-z-border text-z-primary`:`bg-z-panel border-z-border text-z-primary shadow-sm`:t===`dark`?`text-z-secondary border-transparent hover:text-z-secondary`:`text-z-muted border-transparent hover:text-z-secondary`),children:[(0,Q.jsx)(e.icon,{size:11,"aria-hidden":`true`}),e.label]},e.id))}),(0,Q.jsx)(`div`,{className:Y(`rounded-none-none border overflow-hidden transition-all min-h-[180px]`,t===`dark`?`bg-z-panel/5 border-z-border`:`bg-z-input border-z-border`),children:(0,Q.jsxs)(H,{mode:`wait`,children:[l===`google`&&(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`p-5`,children:(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`div`,{className:`text-xs text-z-secondary truncate`,children:g}),(0,Q.jsx)(`h2`,{className:`text-lg font-normal text-[#1a0dab] leading-5 truncate cursor-pointer hover:underline`,style:{fontFamily:`Arial, sans-serif`},children:_}),(0,Q.jsx)(`p`,{className:`text-[13px] text-z-primary leading-4`,style:{fontFamily:`Arial, sans-serif`},children:w(v,160)}),y&&(0,Q.jsx)(`div`,{className:`flex gap-1 flex-wrap mt-1.5`,children:y.split(`,`).slice(0,4).map((e,t)=>(0,Q.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 border border-z-border-strong rounded-none text-z-secondary`,children:e.trim()},t))})]})},`google`),l===`twitter`&&(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`p-5`,children:(0,Q.jsxs)(`div`,{className:Y(`border rounded-none shadow-sm overflow-hidden max-w-[400px]`,t===`dark`?`bg-[#15202b] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,Q.jsx)(`div`,{className:`w-8 h-8 rounded-none-none bg-z-border flex items-center justify-center text-z-primary text-xs font-semibold shrink-0`,children:`Z`}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold`,`text-z-primary`),children:`Zenith CMS`}),(0,Q.jsx)(`span`,{className:Y(`text-xs`,`text-z-secondary`),children:`@zenith·now`})]}),(0,Q.jsx)(`span`,{className:Y(`text-xs`,`text-z-secondary`),children:g})]})]}),(0,Q.jsx)(`div`,{className:Y(`px-3 pb-2 text-sm leading-4 font-normal`,`text-z-primary`),children:_}),(0,Q.jsx)(`div`,{className:`w-full bg-cover bg-center border-t border-b`,style:{backgroundImage:`url(${b})`,height:`157px`,borderColor:`var(--z-border)`}})]})},`twitter`),l===`facebook`&&(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`p-5`,children:(0,Q.jsxs)(`div`,{className:Y(`border rounded-none shadow-sm overflow-hidden max-w-[400px]`,t===`dark`?`bg-[#1c1e21] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsx)(`div`,{className:`w-full bg-cover bg-center`,style:{backgroundImage:`url(${b})`,height:`180px`}}),(0,Q.jsxs)(`div`,{className:Y(`p-3 border-t`,t===`dark`?`bg-[#242526] border-z-border`:`bg-z-input border-z-border`),children:[(0,Q.jsx)(`div`,{className:`text-xs font-semibold text-z-muted mb-1`,children:h.replace(/^https?:\/\//,``)}),(0,Q.jsx)(`div`,{className:Y(`text-[13px] font-bold leading-4 line-clamp-2 mb-1`,`text-z-primary`),style:{fontFamily:`Helvetica, Arial, sans-serif`},children:_}),(0,Q.jsx)(`div`,{className:Y(`text-sm leading-3 line-clamp-2`,t===`dark`?`text-z-muted`:`text-z-secondary`),style:{fontFamily:`Helvetica, Arial, sans-serif`},children:w(v,100)})]})]})},`facebook`)]})}),Kn.map(e=>(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`label`,{htmlFor:`seo-${e}`,className:`text-xs font-semibold text-z-secondary px-1`,children:X(e)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>m(e),disabled:d[e],title:`Auto-generate ${e} with AI`,className:`text-z-muted hover:text-indigo-500 transition-colors disabled:opacity-50`,children:d[e]?(0,Q.jsx)(C,{size:12,className:`animate-spin`}):(0,Q.jsx)(P,{size:12})})]}),e===`description`&&(0,Q.jsxs)(`span`,{className:Y(`text-xs font-semibold `,S(s.description)>155?`text-rose-500`:`text-z-secondary`),children:[S(s.description),` / 155`]}),e===`title`&&(0,Q.jsxs)(`span`,{className:Y(`text-xs font-semibold `,S(s.title)>60?`text-rose-500`:`text-z-secondary`),children:[S(s.title),` / 60`]})]}),e===`description`?(0,Q.jsx)(`textarea`,{id:`seo-${e}`,value:s[e],onChange:t=>O(e,t.target.value),className:Y(`w-full rounded-none-none py-3 px-4 text-xs font-semibold h-24 resize-none transition-all border`,t===`dark`?`bg-z-hover border-z-border text-z-primary focus-visible:border-z-border/30`:`bg-z-input border-z-border text-z-primary focus-visible:border-z-border/30`),placeholder:`Enter page description...`}):(0,Q.jsx)(`input`,{id:`seo-${e}`,type:`text`,value:s[e],onChange:t=>O(e,t.target.value),className:Y(`w-full rounded-none-none py-3 px-4 text-xs font-semibold transition-all border`,t===`dark`?`bg-z-hover border-z-border text-z-primary focus-visible:border-z-border/30`:`bg-z-input border-z-border text-z-primary focus-visible:border-z-border/30`),placeholder:e===`title`?`Enter SEO title...`:`Enter keywords (comma separated)...`})]},e))]}),(0,Q.jsxs)(`div`,{className:Y(`p-4 border-t flex items-center justify-between shrink-0`,t===`dark`?`border-z-border bg-z-panel`:`border-z-border shadow-sm bg-[var(--z-bg-input)]`),children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{c({title:``,description:``,keywords:``})},"aria-label":`Reset SEO fields`,className:Y(`flex items-center gap-2 px-4 py-2 text-xs font-semibold rounded-none-none border transition-all`,t===`dark`?`border-z-border text-z-muted hover:border-rose-500/20 hover:text-rose-400`:`border-z-border text-z-secondary hover:border-rose-200 hover:text-rose-500`),children:[(0,Q.jsx)(x,{size:12}),`Reset`]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(!1),"aria-label":`Cancel and close`,className:Y(`px-4 py-2 text-xs font-semibold rounded-none-none border transition-all`,t===`dark`?`border-z-border text-z-muted hover:border-z-border hover:text-z-primary`:`border-z-border text-z-secondary hover:border-z-border-strong hover:text-z-primary`),children:`Cancel`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{r(e=>({...e,meta:{...e.meta||{},...s}})),e&&await e(),a(!1)},"aria-label":`Save SEO and close`,className:`flex items-center gap-2 px-4 py-2 bg-z-accent text-z-primary text-xs font-semibold rounded-none-none hover:bg-z-border transition-all`,children:[(0,Q.jsx)(p,{size:12,"aria-hidden":`true`}),`Save & Close`]})]})]})]})})})},Jn=({selectedSections:e,setSelectedSections:t,applyTemplate:n,deleteTemplate:r,saveAsTemplate:i})=>{let{theme:a}=K(),{templates:s}=$(W(e=>({templates:e.templates}))),{templatesOpen:c,setTemplatesOpen:l}=dt(W(e=>({templatesOpen:e.templatesOpen,setTemplatesOpen:e.setTemplatesOpen}))),u=(0,Z.useRef)(null),d=`templates-modal-title`;return ut(c,{onEscape:()=>l(!1),containerRef:u}),(0,Q.jsx)(H,{children:c&&(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[600] flex items-center justify-center p-6 bg-[var(--z-bg-modal)] backdrop-blur-sm`,children:(0,Q.jsxs)(G.div,{ref:u,role:`dialog`,"aria-modal":`true`,"aria-labelledby":d,initial:{scale:.95,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},exit:{scale:.95,opacity:0},className:Y(`w-full max-w-2xl border rounded-none-none overflow-hidden shadow-2xl`,a===`dark`?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-center justify-between`,a===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`w-8 h-8 rounded-none-none bg-z-accent flex items-center justify-center text-z-primary`,children:(0,Q.jsx)(f,{size:16})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{id:d,className:`text-lg font-semibold leading-none text-z-secondary `,children:`Block Templates`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary`,children:`Save & reuse component combinations`})]})]}),(0,Q.jsx)(`button`,{onClick:()=>l(!1),"aria-label":`Close`,className:`p-1 hover:text-z-secondary transition-colors`,style:{color:a===`dark`?`#fff`:`#000`},children:(0,Q.jsx)(B,{size:18})})]}),(0,Q.jsx)(`div`,{className:`p-6 max-h-[60vh] overflow-y-auto custom-editor-scrollbar`,children:s.length===0?(0,Q.jsxs)(`div`,{className:`py-12 text-center`,children:[(0,Q.jsx)(f,{size:40,className:`mx-auto mb-4 text-z-secondary`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-semibold`,children:`No saved templates yet`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary mt-2`,children:`Select blocks, then save as template from the context menu`})]}):(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:s.map(e=>(0,Q.jsxs)(`div`,{className:Y(`p-4 border rounded-none-none space-y-3 relative group`,a===`dark`?`bg-z-panel border-z-border hover:border-z-border/30`:`bg-z-input border-z-border hover:border-z-border-strong`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:e.name}),(0,Q.jsxs)(`span`,{className:`text-xs text-z-secondary`,children:[e.content?.sections?.length||e.sections?.length||0,` blocks`]})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`button`,{onClick:()=>n(e),className:`flex-1 py-2 bg-z-accent text-z-primary text-xs font-semibold rounded-none-none hover:bg-z-border transition-colors`,children:`Apply`}),(0,Q.jsx)(`button`,{onClick:async()=>{await lt({message:`Delete template "${e.name}"? This cannot be undone.`})&&(r(e.id||e._id),l(!1),setTimeout(()=>l(!0),50))},"aria-label":`Delete template ${e.name}`,className:Y(`p-2 border rounded-none-none transition-colors`,a===`dark`?`border-z-border text-z-secondary hover:border-rose-500/30 hover:text-rose-500`:`border-z-border text-z-muted hover:border-rose-300 hover:text-rose-500`),children:(0,Q.jsx)(o,{size:12})})]})]},e.id||e._id))})}),e.size>0&&(0,Q.jsxs)(`div`,{className:Y(`p-4 border-t flex items-center justify-between`,a===`dark`?`border-z-border bg-z-panel`:`border-z-border shadow-sm bg-[var(--z-bg-input)]/50`),children:[(0,Q.jsxs)(`span`,{className:`text-xs text-z-secondary font-semibold`,children:[e.size,` block`,e.size>1?`s`:``,` selected`]}),(0,Q.jsxs)(`button`,{onClick:()=>{i(Array.from(e)),t(new Set)},"aria-label":`Save selection as template`,className:`flex items-center gap-2 px-4 py-2 bg-z-accent text-z-primary text-xs font-semibold rounded-none-none hover:bg-z-border transition-colors`,children:[(0,Q.jsx)(I,{size:12,"aria-hidden":`true`}),`Save as Template`]})]})]})})})},Yn=()=>{let{theme:e}=K(),{selectedRelations:t,setSelectedRelations:n,availableCollections:r,relationsSearch:i,setRelationsSearch:a,relationResults:o,setRelationResults:s,relationsField:c,fieldSettings:l,updateData:u}=$(W(e=>({selectedRelations:e.selectedRelations,setSelectedRelations:e.setSelectedRelations,availableCollections:e.availableCollections,relationsSearch:e.relationsSearch,setRelationsSearch:e.setRelationsSearch,relationResults:e.relationResults,setRelationResults:e.setRelationResults,relationsField:e.relationsField,fieldSettings:e.fieldSettings,updateData:e.updateData}))),{relationsModalOpen:d,setRelationsModalOpen:f}=dt(W(e=>({relationsModalOpen:e.relationsModalOpen,setRelationsModalOpen:e.setRelationsModalOpen}))),[p,m]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(``),v=(0,Z.useRef)(null),y=(0,Z.useCallback)(async(e,t)=>{try{let n={limit:20};t&&(n.search=t),s((await q.get(`/${e}`,{params:n})).data.data||[])}catch{U.error(`Failed to load relation entries`)}},[s]);(0,Z.useEffect)(()=>{if(!d)return;let e=Object.values(l).find(e=>!!e.relationTo)?.relationTo;if(e){let t=Array.isArray(e)?e[0]:e;m(t),y(t,g)}},[d]),(0,Z.useEffect)(()=>(v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{_(i),p&&y(p,i)},300),()=>{v.current&&clearTimeout(v.current)}),[i,p,y]);let b=e=>{m(e.slug),y(e.slug,g)},x=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},S=()=>{c&&(u(e=>{let n=[...e.sections],r=n.findIndex(e=>e.id===c.sectionId);return r!==-1&&(n[r].content[c.fieldKey]=Array.from(t)),{...e,sections:n}}),f(!1),U.success(`${t.size} items linked`))},C=(0,Z.useRef)(null),w=`relations-modal-title`;return ut(d,{onEscape:()=>f(!1),containerRef:C}),(0,Q.jsx)(H,{children:d&&(0,Q.jsxs)(`div`,{className:`fixed inset-0 z-[700]`,children:[(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:()=>f(!1),className:`absolute inset-0 bg-app/70 backdrop-blur-md`}),(0,Q.jsxs)(G.div,{ref:C,role:`dialog`,"aria-modal":`true`,"aria-labelledby":w,initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.9,opacity:0},className:Y(`absolute inset-4 md:inset-10 border rounded-xl shadow-2xl flex flex-col overflow-hidden`,e===`dark`?`bg-app/65 backdrop-blur-xl border-z-border`:`bg-z-panel/95 backdrop-blur-xl border-z-border shadow-2xl`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-start justify-between shrink-0`,`border-z-border`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:Y(`w-10 h-10 rounded-lg flex items-center justify-center border`,e===`dark`?`bg-z-panel/10 border-z-border`:`bg-[var(--z-bg-hover)] border-z-border`),children:(0,Q.jsx)(ye,{size:18,className:`text-z-primary`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{id:w,className:Y(`text-lg font-semibold`,`text-z-primary`),children:`Content Relations`}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-bold`,`text-z-muted`),children:`Connect entries from other collections`})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-xs text-z-muted font-mono`,children:[t.size,` selected`]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>f(!1),"aria-label":`Close`,className:Y(`p-2 rounded-xl border transition-all`,e===`dark`?`bg-z-panel/5 border-z-border text-z-primary hover:bg-[var(--z-bg-hover)]`:`bg-[var(--z-bg-input)] border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`),children:(0,Q.jsx)(B,{size:16})})]})]}),(0,Q.jsx)(`div`,{className:Y(`p-4 border-b flex gap-2 overflow-x-auto`,e===`dark`?`border-z-border bg-z-panel/5`:`border-z-border bg-[var(--z-bg-input)]/50`),children:r.map(t=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>b(t),className:Y(`px-3 py-1.5 text-xs font-semibold rounded-lg border shrink-0 transition-all`,p===t.slug?e===`dark`?`bg-z-panel/20 border-z-border text-z-primary`:`bg-[var(--z-border)] border-[var(--z-border-strong)] text-z-primary`:e===`dark`?`border-z-border text-z-muted hover:border-z-border hover:text-z-primary`:`border-z-border text-z-muted hover:border-[var(--z-border-strong)] hover:text-z-primary`),children:t.label||t.slug},t.slug))}),(0,Q.jsx)(`div`,{className:`p-4 shrink-0`,children:(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(h,{size:14,className:`absolute left-4 top-1/2 -translate-y-1/2 text-z-muted`}),(0,Q.jsx)(`input`,{type:`text`,"aria-label":`Search relation entries`,placeholder:`Search entries to link...`,value:i,onChange:e=>a(e.target.value),className:Y(`w-full rounded-lg py-3 pl-12 pr-4 text-xs font-bold border transition-colors`,e===`dark`?`bg-app/20 border-z-border text-z-primary focus-visible:border-z-border`:`bg-z-panel border-z-border text-z-primary focus-visible:border-z-border`)})]})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 custom-editor-scrollbar`,children:p?o.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4`,children:[(0,Q.jsx)(h,{size:32,className:Y(`opacity-20`,`text-z-primary`)}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-semibold text-center`,`text-z-muted`),children:g?`No entries match your search`:`No entries found in this collection`})]}):(0,Q.jsx)(`div`,{className:`space-y-1`,children:o.map(n=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>x(n.id||n._id),className:Y(`w-full flex items-center gap-3 p-3 rounded-lg border transition-all text-left`,t.has(n.id||n._id)?e===`dark`?`bg-z-panel/10 border-z-border`:`bg-[var(--z-bg-hover)] border-[var(--z-border-strong)]`:e===`dark`?`bg-app/20 border-z-border hover:border-z-border`:`bg-z-panel border-z-border hover:border-[var(--z-border-strong)]`),children:[(0,Q.jsx)(`div`,{className:Y(`w-5 h-5 rounded border-2 flex items-center justify-center shrink-0 transition-all`,t.has(n.id||n._id)?`bg-indigo-500 border-indigo-500`:e===`dark`?`border-z-border`:`border-[var(--z-border-strong)] bg-[var(--z-bg-input)]`),children:t.has(n.id||n._id)&&(0,Q.jsx)(z,{size:12,className:`text-z-primary`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:Y(`text-xs font-semibold truncate`,`text-z-primary`),children:n.title||n.name||n.headline||n.id}),(0,Q.jsxs)(`p`,{className:Y(`text-sm font-mono truncate`,`text-z-muted`),children:[`ID: `,n.id||n._id]})]}),(0,Q.jsx)(`span`,{className:Y(`text-sm font-mono shrink-0`,`text-z-muted`),children:n._status||n.status||`active`})]},n.id||n._id))}):(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4`,children:[(0,Q.jsx)(j,{size:40,className:Y(`opacity-20`,`text-z-primary`)}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-semibold text-center`,`text-z-muted`),children:`Select a collection above to view entries`})]})}),(0,Q.jsxs)(`div`,{className:Y(`p-4 border-t flex items-center justify-between`,e===`dark`?`border-z-border bg-app/20`:`border-z-border bg-[var(--z-bg-input)]/50`),children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-bold`,`text-z-muted`),children:`Click entries to select/deselect for relation`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>f(!1),className:Y(`px-4 py-2 text-xs font-semibold rounded-lg border transition-all`,e===`dark`?`border-z-border text-z-muted hover:border-z-border hover:text-z-primary`:`border-z-border text-z-secondary hover:border-z-border hover:text-z-primary`),children:`Cancel`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:S,disabled:t.size===0,className:`px-4 py-2 bg-z-accent text-z-logo-text text-xs font-semibold rounded-lg hover:opacity-80 transition-all disabled:opacity-50`,children:[`Link `,t.size,` items`]})]})]})]})]})})},Xn=e=>e.url?e.url.startsWith(`http`)?e.url:`${e.url}`:``,Zn=()=>{let{theme:e}=K(),{mediaLibraryOpen:t,setMediaLibraryOpen:n}=dt(W(e=>({mediaLibraryOpen:e.mediaLibraryOpen,setMediaLibraryOpen:e.setMediaLibraryOpen}))),{mediaAssets:r,setMediaAssets:i,mediaSearch:a,setMediaSearch:o,mediaTypeFilter:s,setMediaTypeFilter:c,mediaLoading:l,setMediaLoading:u}=$(W(e=>({mediaAssets:e.mediaAssets,setMediaAssets:e.setMediaAssets,mediaSearch:e.mediaSearch,setMediaSearch:e.setMediaSearch,mediaTypeFilter:e.mediaTypeFilter,setMediaTypeFilter:e.setMediaTypeFilter,mediaLoading:e.mediaLoading,setMediaLoading:e.setMediaLoading})));Z.useEffect(()=>{t&&(o(``),c(`all`),u(!0),q.get(`/media`).then(e=>{i(e.data.data||[])}).catch(()=>{}).finally(()=>{u(!1)}))},[t,i,u,o,c]);let f=(0,Z.useMemo)(()=>r.filter(e=>{let t=!a||e.name?.toLowerCase().includes(a.toLowerCase())||e.alt?.toLowerCase().includes(a.toLowerCase())||e.url?.toLowerCase().includes(a.toLowerCase()),n=e.mimetype||``,r=s===`all`||s===`image`&&n.startsWith(`image/`)||s===`video`&&n.startsWith(`video/`)||s===`audio`&&n.startsWith(`audio/`)||s===`application/pdf`&&n.includes(`pdf`)||s===`other`&&!n.startsWith(`image/`)&&!n.startsWith(`video/`)&&!n.startsWith(`audio/`)&&!n.includes(`pdf`);return t&&r}),[r,a,s]),p=(0,Z.useRef)(null),m=`media-library-modal-title`;return ut(t,{onEscape:()=>n(!1),containerRef:p}),(0,Q.jsx)(H,{children:t&&(0,Q.jsxs)(`div`,{className:`fixed inset-0 z-[900] flex items-center justify-center p-4 md:p-10`,children:[(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:()=>n(!1),className:`absolute inset-0 bg-[var(--z-bg-modal)] backdrop-blur-md`}),(0,Q.jsxs)(G.div,{ref:p,role:`dialog`,"aria-modal":`true`,"aria-labelledby":m,initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:Y(`w-full max-w-6xl border rounded-none-none overflow-hidden shadow-2xl flex flex-col h-[85vh]`,e===`dark`?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-center justify-between shrink-0`,e===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`h3`,{id:m,className:Y(`text-lg font-semibold leading-none`,`text-z-primary`),children:`Asset Registry`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>n(!1),"aria-label":`Close`,className:Y(`p-1 transition-colors`,e===`dark`?`text-z-muted hover:text-z-secondary `:`text-z-secondary hover:text-z-secondary`),children:(0,Q.jsx)(B,{size:18})})]}),(0,Q.jsxs)(`div`,{className:Y(`flex items-center gap-4 px-8 py-4 border-b shrink-0`,e===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsxs)(`div`,{className:`relative group flex-1`,children:[(0,Q.jsx)(h,{className:Y(`absolute left-4 top-1/2 -translate-y-1/2 transition-colors`,e===`dark`?`text-z-secondary group-focus-within:text-z-secondary`:`text-z-muted group-focus-within:text-z-secondary`),size:15}),(0,Q.jsx)(`input`,{type:`text`,"aria-label":`Search assets`,placeholder:`Search assets by name or type...`,value:a,onChange:e=>o(e.target.value),className:Y(`w-full rounded-none-none pl-12 pr-4 py-3 text-xs font-bold transition-all`,e===`dark`?`bg-z-hover border border-z-border text-z-primary placeholder:text-z-secondary focus-visible:border-z-border/40 focus-visible:bg-z-panel/[0.05]`:`bg-[var(--z-bg-input)] border border-z-border text-z-primary placeholder:text-z-muted focus-visible:border-z-border focus-visible:bg-z-panel`)})]}),(0,Q.jsxs)(`select`,{"aria-label":`Filter by file type`,value:s,onChange:e=>c(e.target.value),className:Y(`rounded-none-none border py-3 px-4 text-xs font-semibold transition-all`,e===`dark`?`bg-z-hover border-z-border text-z-muted focus-visible:border-z-border/40`:`bg-[var(--z-bg-hover)] border-z-border text-z-secondary focus-visible:border-z-border`),children:[(0,Q.jsx)(`option`,{value:`all`,children:`All Types`}),(0,Q.jsx)(`option`,{value:`image`,children:`Images`}),(0,Q.jsx)(`option`,{value:`video`,children:`Video`}),(0,Q.jsx)(`option`,{value:`audio`,children:`Audio`}),(0,Q.jsx)(`option`,{value:`application/pdf`,children:`PDF`}),(0,Q.jsx)(`option`,{value:`other`,children:`Other`})]}),(0,Q.jsxs)(`label`,{className:Y(`flex items-center gap-2 px-5 py-3 rounded-none-none border cursor-pointer transition-all text-xs font-semibold `,e===`dark`?`bg-z-accent/20 border-z-border/30 text-z-secondary hover:bg-z-accent/30 hover:border-z-border/50`:`bg-z-input border-z-border text-z-primary hover:bg-[var(--z-bg-hover)] hover:border-z-border-strong`),children:[(0,Q.jsx)(tt,{size:14}),`Ingest`,(0,Q.jsx)(`input`,{type:`file`,className:`hidden`,onChange:async e=>{let t=e.target.files?.[0];if(!t)return;let n=new FormData;n.append(`file`,t);try{i([(await q.post(`/upload`,n,{headers:{"Content-Type":`multipart/form-data`}})).data.data,...r]),U.success(`"${t.name}" ingested`)}catch{U.error(`Upload failed`)}}})]})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:l?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-5`,children:[(0,Q.jsx)(C,{size:36,className:`animate-spin text-z-secondary `}),(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary animate-pulse`,children:`Loading Registry...`})]}):r.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-center`,children:[(0,Q.jsx)(`div`,{className:Y(`w-16 h-16 rounded-none-none border-2 border-dashed flex items-center justify-center`,`border-z-border text-z-secondary`),children:(0,Q.jsx)(d,{size:28})}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-semibold `,`text-z-secondary`),children:`No assets in the registry`}),(0,Q.jsx)(`span`,{className:Y(`text-xs font-bold `,e===`dark`?`text-z-primary`:`text-z-secondary`),children:`Upload files using the ingest button above`})]}):f.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-40 gap-3`,children:[(0,Q.jsx)(h,{size:28,className:e===`dark`?`text-z-primary`:`text-z-secondary`}),(0,Q.jsx)(`span`,{className:Y(`text-xs font-semibold `,`text-z-secondary`),children:`No assets match your filter`})]}):(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-8 gap-4`,children:f.map((t,r)=>{let i=(t.mimetype||``).startsWith(`image/`),a=Xn(t);return(0,Q.jsxs)(G.div,{role:`button`,tabIndex:0,"aria-label":`Asset: ${t.name}${t.mimetype?`, ${t.mimetype.split(`/`)[1]?.toUpperCase()}`:``}. Press Enter to copy URL.`,initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{delay:Math.min(r*.015,1)},className:`group relative aspect-square border rounded-none-none overflow-hidden cursor-pointer transition-all hover:scale-[1.04] hover:z-10`,onClick:()=>{navigator.clipboard.writeText(a).catch(()=>{}),U.success(`URL copied to clipboard`)},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),navigator.clipboard.writeText(a).catch(()=>{}),U.success(`URL copied to clipboard`))},children:[i?(0,Q.jsx)(`img`,{src:a,alt:t.alt||t.name||``,className:`w-full h-full object-cover`,loading:`lazy`}):(0,Q.jsxs)(`div`,{className:Y(`w-full h-full flex flex-col items-center justify-center gap-2`,e===`dark`?`bg-z-hover`:`bg-[var(--z-bg-input)]`),children:[(0,Q.jsx)(_,{size:24,className:`text-z-secondary`}),(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold text-center px-1 truncate w-full`,`text-z-secondary`),children:(t.mimetype||`file`).split(`/`)[1]?.toUpperCase().slice(0,4)||`FILE`})]}),(0,Q.jsxs)(`div`,{className:Y(`absolute inset-0 flex flex-col items-start justify-end p-2 opacity-0 group-hover:opacity-100 transition-opacity`,`bg-gradient-to-t from-[var(--z-bg-panel)] via-[var(--z-bg-base)]`),children:[(0,Q.jsx)(`p`,{className:`text-z-primary text-xs font-semibold truncate w-full leading-tight`,children:t.name}),t.size&&(0,Q.jsxs)(`span`,{className:`text-z-primary/50 text-xs font-bold`,children:[(t.size/1024).toFixed(1),` KB`]}),(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(a),U.success(`URL copied`)},className:Y(`mt-1.5 px-2 py-1 rounded-none-none border text-xs font-semibold transition-all`,e===`dark`?`border-z-border text-z-primary/70 hover:border-z-border hover:text-z-primary bg-z-hover`:`border-z-border text-z-primary/80 hover:border-z-border0 hover:text-z-primary bg-z-panel/10`),children:`Copy URL`}),(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),window.dispatchEvent(new CustomEvent(`zenith:media-selected`,{detail:{url:a,alt:t.alt||t.name||``,mimeType:t.mimetype||`image/jpeg`,width:t.width,height:t.height}})),n(!1),U.success(`Media selected`)},className:Y(`mt-1 px-2 py-1 rounded-none-none border text-xs font-semibold transition-all`,`border-z-border/40 text-z-secondary hover:border-z-border hover:text-z-secondary bg-z-panel`),children:`Select`})]}),(0,Q.jsx)(`div`,{className:Y(`absolute top-1.5 left-1.5 px-1.5 py-0.5 text-sm font-semibold border rounded-none-none`,e===`dark`?`bg-app/60 border-z-border text-z-muted`:`bg-z-panel/80 border-z-border text-z-secondary`),children:(t.mimetype||`file`).split(`/`)[1]?.toUpperCase().slice(0,4)||`FILE`})]},t._id||r)})})}),(0,Q.jsxs)(`div`,{className:Y(`flex items-center justify-between px-8 py-3 border-t shrink-0`,e===`dark`?`border-z-border bg-z-panel/[0.015]`:`border-z-border shadow-sm bg-[var(--z-bg-input)]`),children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-bold `,e===`dark`?`text-z-secondary`:`text-z-muted`),children:`Click any asset to copy its URL • Supports images, video, audio, PDF`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>n(!1),"aria-label":`Close media library`,className:Y(`px-5 py-2 text-xs font-semibold rounded-none-none border transition-all`,e===`dark`?`border-z-border text-z-muted hover:border-z-border hover:text-z-primary`:`border-z-border text-z-secondary hover:border-z-border-strong hover:text-z-primary`),children:`Close`})]})]})]})})},Qn=({item:e,idx:t,theme:n,removeFromDynamicZone:r})=>{let i=Ne();return(0,Q.jsxs)(V,{value:e,dragListener:!1,dragControls:i,as:`div`,className:Y(`flex items-center gap-3 p-3 rounded-none-none border group`,n===`dark`?`bg-z-hover border-z-border hover:border-z-border/20`:`bg-z-input border-z-border hover:border-z-border`),children:[(0,Q.jsx)(`div`,{onPointerDown:e=>i.start(e),className:`cursor-grab active:cursor-grabbing shrink-0`,children:(0,Q.jsx)(Ee,{size:12,className:`text-z-secondary`})}),(0,Q.jsx)(`div`,{className:`w-6 h-6 rounded-none-none bg-z-panel flex items-center justify-center shrink-0`,children:(0,Q.jsx)(f,{size:12,className:`text-z-secondary`})}),(0,Q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Q.jsx)(`p`,{className:`text-xs font-semibold truncate`,children:X(e.__component?.replace(`content.`,``)||e.__component||`Component`)})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r(t),"aria-label":`Remove component ${t+1}`,className:`p-1 text-z-secondary hover:text-rose-500 transition-colors opacity-0 group-hover:opacity-100 shrink-0`,children:(0,Q.jsx)(o,{size:12,"aria-hidden":`true`})})]})},$n=({dynamicZoneModalOpen:e,setDynamicZoneModalOpen:t,activeDynamicZone:n,addToDynamicZone:r,removeFromDynamicZone:i,onReorder:a})=>{let{theme:o}=K(),{data:s}=$(W(e=>({data:e.data}))),c=s,l=st(),[u,d]=(0,Z.useState)(``),f=(0,Z.useRef)(null),p=`dynamic-zone-modal-title`;ut(e,{onEscape:()=>t(!1),containerRef:f});let m=(0,Z.useMemo)(()=>{if(!u.trim())return l;let e=u.toLowerCase();return l.filter(t=>t.title.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description.toLowerCase().includes(e))},[l,u]);return(0,Q.jsx)(H,{children:e&&(0,Q.jsxs)(`div`,{className:`fixed inset-0 z-[700]`,children:[(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:()=>t(!1),className:`absolute inset-0 bg-app/70 backdrop-blur-md`}),(0,Q.jsxs)(G.div,{ref:f,role:`dialog`,"aria-modal":`true`,"aria-labelledby":p,initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.9,opacity:0},className:Y(`absolute right-0 top-0 bottom-0 w-[450px] border-l shadow-2xl flex flex-col overflow-hidden`,o===`dark`?`bg-[#060606] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-center justify-between`,o===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`w-8 h-8 rounded-none-none bg-z-accent/20 border border-z-border/30 flex items-center justify-center`,children:(0,Q.jsx)(N,{size:16,className:`text-z-secondary`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{id:p,className:`text-base font-semibold text-z-secondary leading-none`,children:`Dynamic Zone`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-bold mt-1`,children:`Add/arrange component blocks`})]})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(!1),"aria-label":`Close`,className:Y(`p-1.5 rounded-none-none border transition-all`,o===`dark`?`bg-z-hover border-z-border hover:bg-z-panel hover:text-z-primary`:`bg-[var(--z-bg-hover)] border-z-border hover:bg-app hover:text-z-primary`),children:(0,Q.jsx)(B,{size:14})})]}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 custom-editor-scrollbar space-y-4`,children:[n&&(()=>{let e=(c?.sections?.find(e=>e.id===n.sectionId))?.content?.[n.fieldKey]||[];return e.length>0?(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs font-semibold text-z-secondary px-1`,children:[`Zone Contents (`,e.length,`)`]}),(0,Q.jsx)(qe,{axis:`y`,values:e,onReorder:e=>a?.(n.sectionId,n.fieldKey,e),className:`space-y-2`,children:e.map((e,t)=>(0,Q.jsx)(Qn,{item:e,idx:t,theme:o,removeFromDynamicZone:i},e.id||t))})]}):(0,Q.jsxs)(`div`,{className:`text-center py-6`,children:[(0,Q.jsx)(_e,{size:24,className:`mx-auto text-z-secondary mb-2`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-bold`,children:`Zone is empty — add components below`})]})})(),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold text-z-secondary px-1`,children:`Available Components`}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(h,{size:12,className:Y(`absolute left-3 top-1/2 -translate-y-1/2`,`text-z-secondary`)}),(0,Q.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:`Search components...`,className:Y(`w-full pl-8 pr-3 py-2 text-xs font-bold border rounded-none-none bg-transparent`,`border-z-border text-z-primary placeholder:text-z-muted focus:border-z-border/30`)})]}),(0,Q.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1.5 custom-editor-scrollbar`,children:m.length===0?(0,Q.jsx)(`p`,{className:Y(`text-xs font-bold text-center py-4`,`text-z-secondary`),children:`No components match your search`}):m.map(e=>{let t=e.icon;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>r(e.type),"aria-label":`Add ${e.title} to dynamic zone`,className:Y(`w-full flex items-center gap-3 p-3 rounded-none-none border transition-all text-left`,o===`dark`?`bg-z-panel border-z-border hover:border-z-border/30 hover:bg-z-hover`:`bg-z-input border-z-border hover:border-z-border-strong hover:bg-[var(--z-bg-input)]`),children:[(0,Q.jsx)(`div`,{className:`w-8 h-8 rounded-none-none bg-z-panel flex items-center justify-center shrink-0`,children:(0,Q.jsx)(t,{size:14,className:`text-z-secondary`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold truncate`,children:e.title}),(0,Q.jsx)(`p`,{className:Y(`text-sm font-bold truncate`,`text-z-secondary`),children:e.description})]}),(0,Q.jsx)(Be,{size:14,"aria-hidden":`true`,className:`text-z-secondary opacity-50 shrink-0`})]},e.type)})})]})]})]})]})})},er=Fe(e=>({workflowStatus:`draft`,publishStatus:`draft`,workflowReviewers:[],scheduledAt:``,workflowComments:[],releases:[],activeRelease:null,setWorkflowStatus:t=>e({workflowStatus:t}),setPublishStatus:t=>e({publishStatus:t}),setWorkflowReviewers:t=>e({workflowReviewers:t}),setScheduledAt:t=>e({scheduledAt:t}),setWorkflowComments:t=>e({workflowComments:t}),setReleases:t=>e({releases:t}),setActiveRelease:t=>e({activeRelease:t})})),tr=Fe((e,t)=>({i18nEnabled:!1,currentLocale:`en`,availableLocales:[{code:`en`,name:`English`,flag:``,default:!0},{code:`es`,name:`Español`,flag:``,default:!1},{code:`fr`,name:`Français`,flag:``,default:!1},{code:`de`,name:`Deutsch`,flag:``,default:!1},{code:`zh`,name:`中文`,flag:``,default:!1},{code:`ja`,name:`日本語`,flag:``,default:!1}],translations:{},setI18nEnabled:t=>e({i18nEnabled:t}),setCurrentLocale:t=>e({currentLocale:t}),setTranslations:t=>e({translations:t}),updateTranslation:(t,n,r)=>e(e=>({translations:{...e.translations,[t]:{...e.translations[t]||{},[n]:r}}})),importLegacyFormat:t=>e(()=>{let e={};for(let[n,r]of Object.entries(t))for(let[t,i]of Object.entries(r))e[t]||(e[t]={}),e[t][n]=i;return{translations:e}}),getLocalizedValue:e=>{let{translations:n,currentLocale:r,availableLocales:i}=t(),a=n[e];if(a)return a[r]??a[i.find(e=>e.default)?.code??`en`]}})),nr=()=>{let{saving:e,hasUnsavedChanges:t}=$(W(e=>({saving:e.saving,hasUnsavedChanges:e.hasUnsavedChanges}))),{theme:n}=K(),r=e?`saving`:t?`unsaved`:`saved`;return(0,Q.jsx)(`div`,{className:`flex items-center select-none font-sans`,children:(0,Q.jsxs)(H,{mode:`wait`,children:[r===`saving`&&(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},className:Y(`px-2.5 py-1 flex items-center gap-1.5 border text-xs font-semibold rounded-none-none`,n===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-secondary`),children:[(0,Q.jsx)(C,{size:11,className:`animate-spin`}),(0,Q.jsx)(`span`,{children:`Saving...`})]},`saving`),r===`unsaved`&&(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},className:Y(`px-2.5 py-1 flex items-center gap-1.5 border text-xs font-semibold rounded-none-none`,n===`dark`?`bg-amber-500/10 border-amber-500/20 text-amber-400`:`bg-amber-50 border-amber-200 text-amber-600`),children:[(0,Q.jsx)(ie,{size:11,className:`animate-pulse`}),(0,Q.jsx)(`span`,{children:`Unsaved`})]},`unsaved`),r===`saved`&&(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},className:Y(`px-2.5 py-1 flex items-center gap-1.5 border text-xs font-semibold rounded-none-none`,n===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-secondary`),children:[(0,Q.jsx)(z,{size:11,className:`text-z-secondary `}),(0,Q.jsx)(`span`,{children:`Saved`})]},`saved`)]})})},rr=({open:e,onClose:t})=>{let{theme:n}=K(),{scheduledAt:r,setScheduledAt:i}=er(W(e=>({scheduledAt:e.scheduledAt,setScheduledAt:e.setScheduledAt}))),[a,o]=(0,Z.useState)(``),s=(0,Z.useRef)(null);return(0,Z.useEffect)(()=>{if(e)if(r)o(new Date(r).toISOString().slice(0,16));else{let e=new Date;e.setDate(e.getDate()+1),e.setHours(9,0,0,0),o(e.toISOString().slice(0,16))}},[e,r]),(0,Z.useEffect)(()=>{if(!e)return;let n=e=>{s.current&&!s.current.contains(e.target)&&t()};return document.addEventListener(`mousedown`,n),()=>document.removeEventListener(`mousedown`,n)},[e,t]),e?(0,Q.jsxs)(`div`,{ref:s,className:Y(`absolute top-full mt-2 right-0 w-64 border shadow-2xl z-50 p-3`,n===`dark`?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),onClick:e=>e.stopPropagation(),children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-semibold `,n===`dark`?`text-z-muted`:`text-z-secondary`),children:`Schedule Publish`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,Q.jsx)(`button`,{onClick:()=>{i(``),t()},className:`text-xs font-semibold text-red-400 hover:text-red-300`,children:`Clear`}),(0,Q.jsx)(`button`,{onClick:t,"aria-label":`Close scheduler`,className:Y(`p-0.5`,n===`dark`?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`),children:(0,Q.jsx)(B,{size:12,"aria-hidden":`true`})})]})]}),(0,Q.jsx)(`input`,{type:`datetime-local`,value:a,onChange:e=>o(e.target.value),className:Y(`w-full px-2 py-1.5 rounded-none-none border text-xs font-mono`,n===`dark`?`bg-z-hover border-z-border text-z-primary`:`bg-z-input border-z-border text-z-primary`)}),(0,Q.jsxs)(`div`,{className:`flex gap-2 mt-2`,children:[(0,Q.jsx)(`button`,{onClick:t,className:Y(`flex-1 py-1.5 border text-xs font-semibold text-center transition-all`,n===`dark`?`border-z-border text-z-muted hover:bg-z-hover`:`border-z-border text-z-secondary hover:bg-[var(--z-bg-input)]`),children:`Cancel`}),(0,Q.jsx)(`button`,{onClick:()=>{if(!a)return;let e=new Date(a).toISOString();i(e),er.getState().setWorkflowStatus(`scheduled`),$.getState().setHasUnsavedChanges(!0),U.success(`Scheduled for ${new Date(e).toLocaleString()}`,{icon:`⏰`}),t()},disabled:!a,className:Y(`flex-1 py-1.5 text-xs font-semibold text-center transition-all disabled:opacity-40`,`bg-z-accent hover:bg-z-border text-z-primary`),children:`Apply`})]})]}):null},ir=({open:e,onConfirm:t,onCancel:n})=>{let{theme:r}=K();return(0,Vt.createPortal)((0,Q.jsx)(H,{children:e&&(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[800] flex items-center justify-center bg-[var(--z-bg-modal)] backdrop-blur-sm`,children:(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},transition:{duration:.15},className:Y(`w-full max-w-sm border rounded-none-none shadow-2xl p-6`,r===`dark`?`bg-app border-z-border text-z-primary`:`bg-z-panel border-z-border text-z-primary`),children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,Q.jsx)(`div`,{className:Y(`w-10 h-10 rounded-none-none border flex items-center justify-center shrink-0`,r===`dark`?`bg-amber-500/10 border-amber-500/20 text-amber-400`:`bg-amber-50 border-amber-200 text-amber-500`),children:(0,Q.jsx)(u,{size:18})}),(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Publish Document`}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-bold mt-2 leading-relaxed`,r===`dark`?`text-z-muted`:`text-z-secondary`),children:`This will make the content live and visible to all visitors. Are you sure you want to publish?`})]}),(0,Q.jsx)(`button`,{onClick:n,"aria-label":`Close`,className:Y(`shrink-0 p-1 transition-colors`,r===`dark`?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`),children:(0,Q.jsx)(B,{size:16})})]}),(0,Q.jsxs)(`div`,{className:`flex gap-3 mt-5`,children:[(0,Q.jsx)(`button`,{onClick:n,className:Y(`flex-1 py-2.5 text-xs font-semibold border rounded-none-none transition-all`,r===`dark`?`border-z-border text-z-muted hover:border-z-border hover:text-z-primary`:`border-z-border text-z-secondary hover:border-z-border-strong hover:text-z-primary`),children:`Cancel`}),(0,Q.jsxs)(`button`,{onClick:t,className:`flex-1 flex items-center justify-center gap-2 py-2.5 bg-z-accent text-z-primary text-xs font-semibold rounded-none-none hover:bg-z-border transition-all`,children:[(0,Q.jsx)(ze,{size:12}),`Publish Now`]})]})]})})}),document.body)},ar=({open:e,onClose:t})=>{let{theme:n}=K(),r=n===`dark`,{data:i,topLevelFields:a}=$(W(e=>({data:e.data,topLevelFields:e.topLevelFields}))),{availableLocales:o,translations:s,updateTranslation:c}=tr(),[l,u]=(0,Z.useState)(`en`),[d,f]=(0,Z.useState)(`es`),p=st(),m=(0,Z.useMemo)(()=>{let e=[];return a.forEach(t=>{[`text`,`richtext`,`textarea`,`lexical`].includes(t.type)&&e.push({sectionId:`root`,sectionName:`Document Data`,fieldName:t.name,fieldType:t.type,originalValue:i?.[t.name]})}),i?.sections&&i.sections.forEach(t=>{let n=p.find(e=>e.type===t.blockType);n&&n.fields.forEach(n=>{[`text`,`richtext`,`textarea`,`lexical`].includes(n.type)&&e.push({sectionId:t.id,sectionName:t.blockName||t.title||X(t.blockType),fieldName:n.name,fieldType:n.type,originalValue:t.content[n.name]})})}),e},[i,p,a]),h=(0,Z.useMemo)(()=>{if(m.length===0)return 0;let e=0;return m.forEach(t=>{let n=s[t.sectionId===`root`?t.fieldName:`${t.sectionId}.${t.fieldName}`]?.[d];n&&n.trim()!==``&&e++}),Math.round(e/m.length*100)},[m,s,d]);return(0,Vt.createPortal)((0,Q.jsx)(H,{children:e&&(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4 sm:p-6 bg-[var(--z-bg-modal)] backdrop-blur-sm`,children:(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.98,y:15},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.98,y:15},className:Y(`border rounded-none-none w-full max-w-6xl shadow-2xl flex flex-col overflow-hidden max-h-[90vh]`,r?`bg-app border-z-border text-z-primary`:`bg-z-panel border-z-border shadow-sm text-z-primary`),children:[(0,Q.jsxs)(`div`,{className:`p-6 border-b border-z-border dark:border-z-border flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Q.jsx)(`div`,{className:`w-10 h-10 bg-z-accent rounded-none-none flex items-center justify-center text-z-primary shadow-lg shrink-0`,children:(0,Q.jsx)(et,{size:18})}),(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Translation_Engine`}),(0,Q.jsx)(`p`,{className:`text-sm font-bold text-z-muted mt-1`,children:`Side-by-side content localization`})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 sm:flex-none`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-secondary`,children:`Reference:`}),(0,Q.jsx)(`select`,{value:l,onChange:e=>u(e.target.value),className:Y(`w-32 px-3 py-1.5 text-xs font-bold border rounded-none-none bg-transparent outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black transition-colors appearance-none cursor-pointer`,`border-z-border hover:border-z-border text-z-primary`),children:o.map(e=>(0,Q.jsxs)(`option`,{value:e.code,className:`text-z-primary bg-z-panel`,children:[e.flag,` `,e.name]},e.code))})]}),(0,Q.jsx)(`div`,{className:`text-z-muted`,children:(0,Q.jsx)(E,{size:14})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 sm:flex-none`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-secondary `,children:`Target:`}),(0,Q.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),className:Y(`w-32 px-3 py-1.5 text-xs font-bold border rounded-none-none dark:bg-z-panel/5 bg-z-panel outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black transition-colors appearance-none cursor-pointer`,`border-z-border/30 hover:border-z-border/60 text-z-secondary`),children:o.map(e=>(0,Q.jsxs)(`option`,{value:e.code,className:`text-z-primary bg-z-panel`,children:[e.flag,` `,e.name]},e.code))})]}),(0,Q.jsx)(`button`,{onClick:t,className:`ml-4 p-2 text-z-muted hover:text-z-primary transition-colors`,children:(0,Q.jsx)(B,{size:16})})]})]}),(0,Q.jsx)(`div`,{className:`h-1 bg-[var(--z-bg-hover)] dark:bg-z-hover w-full relative`,children:(0,Q.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 bg-z-border transition-all duration-500`,style:{width:`${h}%`}})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-6 space-y-12`,children:m.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-z-secondary`,children:[(0,Q.jsx)(ie,{size:48,className:`mb-4 opacity-20`}),(0,Q.jsx)(`p`,{className:`text-xs font-bold`,children:`No text fields found to translate.`})]}):m.map((e,t)=>{let r=e.sectionId===`root`?e.fieldName:`${e.sectionId}.${e.fieldName}`,i=s[r]?.[l]||(l===`en`?e.originalValue:``)||``,a=s[r]?.[d]||``;return(0,Q.jsxs)(`div`,{className:`space-y-4 relative`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`w-1.5 h-1.5 bg-z-border rounded-none-none`}),(0,Q.jsxs)(`h4`,{className:`text-sm font-semibold text-z-secondary`,children:[e.sectionName,` `,(0,Q.jsx)(`span`,{className:`text-z-secondary mx-1`,children:`>`}),` `,X(e.fieldName)]})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-8`,children:[(0,Q.jsxs)(`div`,{className:`opacity-70 pointer-events-none relative`,children:[(0,Q.jsxs)(`div`,{className:`absolute top-0 right-0 p-2 text-sm font-semibold text-z-muted z-10 bg-app/50 backdrop-blur-md`,children:[`Reference (`,l,`)`]}),(0,Q.jsx)(zn,{blockId:e.sectionId,field:{name:e.fieldName,type:e.fieldType,label:``},value:i,onChange:()=>{},theme:n})]}),(0,Q.jsxs)(`div`,{className:`relative border border-z-border/20 p-4 -m-4 bg-z-hover`,children:[(0,Q.jsxs)(`div`,{className:`absolute top-0 right-0 p-2 text-sm font-semibold text-z-secondary z-10 bg-app/50 backdrop-blur-md flex items-center gap-1.5`,children:[a?(0,Q.jsx)(z,{size:10,className:`text-z-secondary`}):null,`Target (`,d,`)`]}),(0,Q.jsx)(zn,{blockId:e.sectionId,field:{name:e.fieldName,type:e.fieldType,label:``},value:a,onChange:e=>c(r,d,e),theme:n})]})]})]},`${e.sectionId}-${e.fieldName}`)})})]})})}),document.body)},or=[`var(--z-accent)`,`var(--z-accent)`,`#ec4899`,`#f43f5e`,`#f97316`,`#84cc16`,`#14b8a6`,`#06b6d4`,`#3b82f6`,`#a855f7`];function sr(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)&65535;return or[t%or.length]}function cr(e,t){return e?e.slice(0,2).toUpperCase():t?t.slice(0,2).toUpperCase():`??`}function lr({collection:e,documentId:t,wsUrl:n,pollInterval:r=15e3,enabled:i=!0}){let{user:a}=ht(W(e=>({user:e.user}))),[o,s]=(0,Z.useState)([]),[c]=(0,Z.useState)(!1),[l]=(0,Z.useState)(null),u=(0,Z.useRef)(null),d={id:a?.id||`local`,email:a?.email||`local@example.com`,name:a?.name,color:sr(a?.id||`local`)};return(0,Z.useEffect)(()=>{if(!i)return;let n=async()=>{try{await q.post(`/presence/heartbeat`,{collection:e,documentId:t,userId:a?.id}).catch(()=>{}),s(((await q.get(`/presence/${e}/${t}`,{params:{collection:e,documentId:t}}).catch(()=>({data:{data:{activeUsers:[]}}}))).data?.data?.activeUsers||[]).map(e=>({id:e.id||e.userId||`?`,email:e.email||`?`,name:e.name,color:sr(e.id||e.userId||``)})))}catch{}};return n(),u.current=setInterval(n,r),()=>{u.current&&clearInterval(u.current)}},[n,c,e,t,r,i,a]),{collabUsers:o,localUser:d,doc:l,isConnected:c,broadcastCursor:(0,Z.useCallback)((e,t)=>{},[])}}var ur=5,dr=({users:e,localUser:t,isConnected:n,theme:r})=>{let[i,a]=(0,Z.useState)(!1),o=e.slice(0,ur),s=Math.max(0,e.length-ur),c={};return e.forEach(e=>{c[e.id]=e.color}),(0,Q.jsxs)(`div`,{className:`relative flex items-center gap-0`,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),children:[(0,Q.jsxs)(`div`,{className:Y(`flex items-center gap-1 px-2 py-1 rounded-none-none border text-sm font-semibold `,n?r===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-secondary`:r===`dark`?`bg-z-hover border-z-border text-z-secondary`:`bg-[var(--z-bg-hover)] border-z-border text-z-muted`),title:n?`Live collaboration active`:`Offline — changes saved locally`,children:[n?(0,Q.jsx)(ge,{size:8}):(0,Q.jsx)(Le,{size:8}),n?`Live`:`Local`]}),(0,Q.jsxs)(`div`,{className:`flex items-center ml-1.5`,children:[(0,Q.jsxs)(`div`,{className:`relative`,title:`${t.name||t.email} (you)`,children:[(0,Q.jsx)(G.div,{initial:{scale:0},animate:{scale:1},className:Y(`w-8 h-8 rounded-full flex items-center justify-center text-xs font-bold shadow-sm ring-2`,r===`dark`?`ring-[#050505]`:`ring-z-active-border`),style:{backgroundColor:t.color},children:cr(t.name,t.email)}),(0,Q.jsx)(G.div,{animate:{scale:[1,1.3,1],opacity:[1,.4,1]},transition:{duration:2,repeat:1/0},className:`absolute -bottom-0.5 -right-0.5`,children:(0,Q.jsx)(Me,{size:6,fill:t.color,stroke:`none`,className:`text-z-secondary`})})]}),o.filter(e=>e.id!==t.id).map((e,t)=>(0,Q.jsx)(G.div,{initial:{scale:0,x:-10},animate:{scale:1,x:0},transition:{delay:t*.05},className:Y(`relative -ml-2 w-8 h-8 rounded-full flex items-center justify-center text-xs font-bold shadow-sm ring-2`,r===`dark`?`ring-[#050505]`:`ring-z-active-border`),style:{backgroundColor:e.color,borderColor:`var(--z-border)`,zIndex:o.length-t},title:e.name||e.email,children:cr(e.name,e.email)},e.id)),s>0&&(0,Q.jsxs)(G.button,{type:`button`,initial:{scale:0},animate:{scale:1},onClick:()=>a(e=>!e),"aria-label":`${s} more users editing`,className:Y(`relative -ml-2 w-8 h-8 rounded-full flex items-center justify-center text-xs font-bold shadow-sm ring-2 transition-transform cursor-pointer`,r===`dark`?`bg-z-base text-z-secondary ring-[#050505] hover:scale-105`:`bg-[var(--z-border)] text-z-secondary ring-z-active-border hover:scale-105`),style:{zIndex:0},children:[`+`,s]})]}),(0,Q.jsx)(H,{children:i&&(0,Q.jsxs)(G.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.1},className:Y(`absolute top-full right-0 mt-2 z-[999] w-64 rounded-xl shadow-2xl p-4 border`,r===`dark`?`bg-[#111] border-z-border text-z-primary`:`bg-z-panel border-z-border text-z-primary shadow-[var(--z-border)]`),onClick:()=>a(!1),children:[(0,Q.jsxs)(`p`,{className:`text-xs font-semibold text-z-secondary mb-2`,children:[e.length,` `,e.length===1?`person`:`people`,` editing`]}),(0,Q.jsx)(`div`,{className:`space-y-1.5`,children:[t,...e.filter(e=>e.id!==t.id)].map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`w-6 h-6 rounded-full flex items-center justify-center text-[10px] font-bold text-z-primary shrink-0`,style:{backgroundColor:e.color},children:cr(e.name,e.email)}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold truncate`,children:e.name||e.email}),e.cursor?.fieldKey&&(0,Q.jsxs)(`p`,{className:`text-xs text-z-secondary truncate`,children:[`→ `,e.cursor.fieldKey]})]}),e.id===t.id&&(0,Q.jsx)(`span`,{className:`text-xs text-z-secondary`,children:`you`})]},e.id))})]})})]})},fr=({handleSave:e,handlePublish:r,handleUnpublish:i,isGlobal:a,onClose:o,collab:s})=>{let c=Ae(),{id:l,slug:u}=xe(),{theme:d,toggleTheme:f}=K(),m=()=>{o?o():c(a?`/`:`/collections/${u||`pages`}`)},{saving:h,undoStack:_,redoStack:v,undo:y,redo:b,lastSavedAt:x}=$(W(e=>({saving:e.saving,undoStack:e.undoStack,redoStack:e.redoStack,undo:e.undo,redo:e.redo,lastSavedAt:e.lastSavedAt}))),{viewMode:S,setViewMode:w,leftOpen:T,setLeftOpen:D,rightOpen:O,setRightOpen:k,focusMode:A,toggleFocusMode:j}=kt(W(e=>({viewMode:e.viewMode,setViewMode:e.setViewMode,leftOpen:e.leftOpen,setLeftOpen:e.setLeftOpen,rightOpen:e.rightOpen,setRightOpen:e.setRightOpen,focusMode:e.focusMode,toggleFocusMode:e.toggleFocusMode}))),{seoOpen:M,setSeoOpen:ee}=dt(W(e=>({seoOpen:e.seoOpen,setSeoOpen:e.setSeoOpen}))),{publishStatus:N,workflowStatus:P,scheduledAt:F}=er(W(e=>({publishStatus:e.publishStatus,workflowStatus:e.workflowStatus,scheduledAt:e.scheduledAt}))),{i18nEnabled:I,availableLocales:te,currentLocale:ne,setCurrentLocale:re,setI18nEnabled:L}=tr(),[ie,oe]=(0,Z.useState)(!1),[se,ce]=(0,Z.useState)(!1),[le,R]=(0,Z.useState)(!1),[de,fe]=(0,Z.useState)(!1),pe=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!se)return;let e=e=>{pe.current&&!pe.current.contains(e.target)&&ce(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[se]);let B=d===`dark`,me=Y(`w-8 h-8 rounded-none-none flex items-center justify-center border transition-all`,B?`bg-z-hover border-z-border`:`bg-z-panel border-z-border`),he=e=>e?B?`bg-z-panel/10 border-z-border text-z-primary`:`bg-[var(--z-active-bg)] text-[var(--z-active-text)] border border-[var(--z-active-border)] shadow-sm`:B?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`,V=e=>e?B?`bg-app/20 border-z-border text-z-primary/20 cursor-not-allowed`:`bg-z-input border-z-border shadow-sm text-z-secondary cursor-not-allowed`:B?`bg-z-hover border-z-border text-z-muted hover:text-z-secondary`:`bg-z-panel border-z-border text-z-secondary hover:bg-[var(--z-bg-input)]`,ge=x?`Saved ${new Date(x).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}`:null;return(0,Q.jsxs)(`header`,{className:Y(`h-14 border-b flex items-center justify-between px-4 z-[100] backdrop-blur-3xl transition-all gap-3 shrink-0 overflow-visible`,B?`bg-z-popover border-z-border`:`bg-z-panel border-z-border shadow-sm`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,Q.jsx)(`button`,{onClick:m,className:Y(me,B?`text-z-muted hover:text-z-primary`:`text-z-secondary hover:text-z-primary`),"aria-label":`Back to collection`,title:`Back`,children:(0,Q.jsx)(Pe,{size:16})}),(0,Q.jsx)(`div`,{className:Y(`h-4 w-px mx-1`,B?`bg-z-panel/10`:`bg-[var(--z-border)]`)}),(0,Q.jsxs)(`button`,{onClick:()=>ee(!M),className:Y(`px-2.5 py-1.5 rounded-none-none border text-xs font-semibold flex items-center gap-1.5 transition-all`,M?`bg-z-panel/5 border-z-border text-z-secondary`:B?`bg-z-hover border-z-border text-z-muted`:`bg-z-input border-z-border text-z-secondary`),"aria-label":M?`Close SEO panel`:`Open SEO panel`,title:`SEO`,children:[(0,Q.jsx)(E,{size:12}),`SEO`]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Q.jsxs)(`button`,{onClick:y,disabled:_.length===0,"aria-label":_.length>0?`Undo (${_.length} step${_.length===1?``:`s`} available)`:`Nothing to undo`,title:_.length>0?`Undo (${_.length} step${_.length===1?``:`s`})`:`Nothing to undo`,className:Y(me,V(_.length===0),`relative`),children:[(0,Q.jsx)(ue,{size:15}),_.length>0&&(0,Q.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 min-w-[14px] h-3.5 px-0.5 flex items-center justify-center text-sm font-semibold tabular-nums rounded-none-none bg-z-accent text-z-primary leading-none`,"aria-hidden":`true`,children:_.length>99?`99+`:_.length})]}),(0,Q.jsxs)(`button`,{onClick:b,disabled:v.length===0,"aria-label":v.length>0?`Redo (${v.length} step${v.length===1?``:`s`} available)`:`Nothing to redo`,title:v.length>0?`Redo (${v.length} step${v.length===1?``:`s`})`:`Nothing to redo`,className:Y(me,V(v.length===0),`relative`),children:[(0,Q.jsx)(ae,{size:15}),v.length>0&&(0,Q.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 min-w-[14px] h-3.5 px-0.5 flex items-center justify-center text-sm font-semibold tabular-nums rounded-none-none bg-z-accent/80 text-z-primary leading-none`,"aria-hidden":`true`,children:v.length>99?`99+`:v.length})]}),(0,Q.jsx)(`div`,{className:`w-px h-6 bg-z-hover mx-1`}),(0,Q.jsx)(`button`,{onClick:()=>D(!T),"aria-label":T?`Close layers panel`:`Open layers panel`,title:`Layers (Ctrl+\\\\)`,className:Y(me,he(T)),children:(0,Q.jsx)(g,{size:15})}),(0,Q.jsx)(`button`,{onClick:()=>k(!O),"aria-label":O?`Close preview panel`:`Open preview panel`,title:`Preview (Ctrl+P)`,className:Y(me,he(O)),children:(0,Q.jsx)(t,{size:15})}),(0,Q.jsx)(`button`,{onClick:j,"aria-label":A?`Exit focus mode`:`Enter focus mode`,title:`Focus Mode`,className:Y(me,he(A)),children:A?(0,Q.jsx)(Ie,{size:15}):(0,Q.jsx)(Xe,{size:15})}),(0,Q.jsx)(`div`,{className:`w-px h-6 bg-z-hover mx-1`}),(0,Q.jsx)(`button`,{onClick:f,"aria-label":B?`Switch to light mode`:`Switch to dark mode`,className:Y(me,B?`text-z-muted hover:text-z-primary`:`text-z-secondary hover:text-z-primary`),children:B?(0,Q.jsx)(Te,{size:15}):(0,Q.jsx)(we,{size:15})}),(0,Q.jsx)(`button`,{onClick:()=>L(!I),className:Y(me,he(I)),"aria-label":I?`Disable translations`:`Enable translations`,title:I?`Disable translations`:`Enable translations`,children:(0,Q.jsx)(et,{size:13})}),I&&(0,Q.jsx)(`button`,{onClick:()=>fe(!0),className:Y(me,`text-z-secondary hover:text-z-secondary`),title:`Translation Mode (Side-by-Side)`,"aria-label":`Open Translation Mode`,children:(0,Q.jsx)(E,{size:13})}),I&&(0,Q.jsxs)(`div`,{className:`relative`,ref:pe,children:[(0,Q.jsxs)(`button`,{onClick:()=>ce(!se),"aria-label":`Current language: ${ne.toUpperCase()}. Click to change.`,className:Y(`h-8 px-2 rounded-none-none border flex items-center gap-1.5 text-xs font-semibold transition-all`,B?`bg-z-hover border-z-border text-z-muted hover:text-z-primary`:`bg-z-panel border-z-border text-z-secondary hover:bg-[var(--z-bg-input)] hover:text-z-primary`),children:[(0,Q.jsx)(et,{size:13}),ne.toUpperCase()]}),se&&(0,Q.jsx)(`div`,{className:Y(`absolute top-full mt-2 w-36 border rounded-none-none shadow-2xl z-50 overflow-hidden`,B?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),children:te.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>{re(e.code),ce(!1)},className:Y(`w-full flex items-center gap-2 px-3 py-2 text-xs font-bold transition-colors`,ne===e.code?B?`bg-z-panel/5 text-z-secondary`:`bg-z-hover text-z-primary shadow-sm`:B?`text-z-muted hover:bg-z-hover`:`text-z-secondary hover:bg-[var(--z-bg-hover)] hover:text-z-primary`),children:[(0,Q.jsx)(`span`,{children:e.flag}),(0,Q.jsx)(`span`,{className:`flex-1 text-left`,children:e.name})]},e.code))})]}),(0,Q.jsx)(`div`,{className:`w-px h-6 bg-z-hover mx-1`}),(0,Q.jsxs)(`div`,{className:Y(`flex items-center gap-0.5 p-0.5 rounded-none-none border`,B?`bg-z-hover border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsx)(`button`,{onClick:()=>w(`visual`),className:Y(`px-2.5 py-1 rounded-none-none text-xs font-semibold transition-all`,S===`visual`?B?`bg-z-panel text-z-primary`:`bg-[var(--z-active-bg)] text-[var(--z-active-text)] border border-[var(--z-active-border)] shadow-sm`:B?`text-z-primary/50 hover:text-z-primary`:`text-z-secondary hover:text-z-primary`),children:`Visual`}),(0,Q.jsx)(`button`,{onClick:()=>w(`code`),className:Y(`px-2.5 py-1 rounded-none-none text-xs font-semibold transition-all`,S===`code`?B?`bg-z-panel text-z-primary`:`bg-[var(--z-active-bg)] text-[var(--z-active-text)] border border-[var(--z-active-border)] shadow-sm`:B?`text-z-primary/50 hover:text-z-primary`:`text-z-secondary hover:text-z-primary`),children:`JSON`})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsxs)(`button`,{onClick:i,disabled:N===`draft`,className:Y(`flex items-center gap-1 px-2.5 py-1.5 rounded-none-none border text-xs font-semibold transition-all`,N===`draft`&&P!==`scheduled`?B?`bg-amber-500/10 border-amber-500/20 text-amber-400`:`bg-amber-50 border-amber-200 text-amber-600`:B?`bg-z-hover border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-muted`),"aria-label":`Set as draft`,children:[(0,Q.jsx)(Me,{size:7,className:N===`draft`&&P!==`scheduled`||P===`scheduled`?`fill-current`:``}),P===`scheduled`?`Scheduled`:`Draft`]}),(0,Q.jsxs)(`button`,{onClick:()=>R(!0),disabled:N===`published`,className:Y(`flex items-center gap-1 px-2.5 py-1.5 rounded-none-none border text-xs font-semibold transition-all`,N===`published`?B?`bg-green-500/10 border-green-500/20 text-green-400`:`bg-green-50 border-green-200 text-green-600`:B?`bg-z-hover border-z-border text-z-secondary hover:text-z-primary`:`bg-z-input border-z-border text-z-muted hover:text-z-primary`),"aria-label":`Publish document`,children:[(0,Q.jsx)(z,{size:10}),`Publish`]})]}),(0,Q.jsx)(nr,{}),ge&&(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold `,B?`text-z-secondary`:`text-z-muted`),children:ge}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(`button`,{onClick:()=>oe(!ie),className:Y(`h-8 px-2.5 rounded-none-none border flex items-center gap-1.5 text-xs font-semibold transition-all`,F?B?`bg-amber-500/10 border-amber-500/20 text-amber-400`:`bg-amber-50 border-amber-200 text-amber-600`:B?`bg-z-hover border-z-border text-z-secondary hover:text-z-primary`:`bg-[var(--z-bg-hover)] border-z-border text-z-muted hover:text-z-primary`),title:F?`Scheduled: ${new Date(F).toLocaleString()}`:`Schedule publish`,"aria-label":F?`Scheduled for ${new Date(F).toLocaleDateString()}`:`Schedule publish`,children:[(0,Q.jsx)(n,{size:12}),F?new Date(F).toLocaleDateString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):`Schedule`]}),(0,Q.jsx)(rr,{open:ie,onClose:()=>oe(!1)})]}),s&&(0,Q.jsx)(`div`,{className:`mx-2`,children:(0,Q.jsx)(dr,{users:s.collabUsers,localUser:s.localUser,isConnected:s.isConnected,theme:d})}),(0,Q.jsxs)(`button`,{onClick:e,disabled:h,className:`flex items-center gap-1.5 px-4 py-1.5 rounded-none-none text-xs font-semibold bg-z-accent text-z-primary shadow-[0_0_16px_rgba(79,70,229,0.3)] hover:bg-z-border transition-all active:scale-95 disabled:opacity-50`,"aria-label":`Save document`,children:[h?(0,Q.jsx)(C,{size:13,className:`animate-spin`}):(0,Q.jsx)(p,{size:13}),h?`Saving...`:`Save`]})]}),(0,Q.jsx)(ir,{open:le,onConfirm:()=>{R(!1),r()},onCancel:()=>R(!1)}),(0,Q.jsx)(ar,{open:de,onClose:()=>fe(!1)})]})},pr=Z.memo(({section:e,index:t,totalSections:n,theme:r,showFieldIndicators:i,editorSelectedField:a,editorSchemaFields:o,editorFieldErrors:s,editorActiveSection:c,editorSetActiveSection:l,duplicateSection:u,removeSection:d,updateAlign:f,handleFieldChange:p,setSelectedField:m,i18nEnabled:h,currentLocale:g,getTranslatedValue:_,setTranslatedValue:v,setActiveDynamicZone:y,setDynamicZoneModalOpen:b,setInjectionIndex:x,setBlockPickerOpen:S,onOpenContextMenu:C,broadcastCursor:w,toggleCollapse:T,moveSection:E,copySection:D,pasteSection:O,handleBlockNameChange:k,selectedSections:A,onMultiSelect:j,collab:ee})=>{let N=Ne();return(0,Q.jsxs)(V,{value:e.id,dragListener:!1,dragControls:N,as:`div`,role:`article`,"aria-label":`Section block ${e.title||e.blockType}`,tabIndex:0,onKeyDown:t=>{if(t.key===`ArrowUp`&&(t.metaKey||t.ctrlKey)){t.preventDefault(),E(e.id,`up`);let n=document.getElementById(`editor-live-region`);n&&(n.innerText=`Moved ${e.title||e.blockType} up`)}if(t.key===`ArrowDown`&&(t.metaKey||t.ctrlKey)){t.preventDefault(),E(e.id,`down`);let n=document.getElementById(`editor-live-region`);n&&(n.innerText=`Moved ${e.title||e.blockType} down`)}},whileDrag:{scale:1.02,opacity:.9,boxShadow:`0 20px 60px rgba(0,0,0,0.3)`,zIndex:50,cursor:`grabbing`},className:`relative group/item focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:outline-none`,children:[(0,Q.jsx)(`div`,{className:`relative h-8 group/portal -mt-4`,children:(0,Q.jsx)(`button`,{onClick:()=>{x(t),S(!0)},className:`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 opacity-0 group-hover/item:opacity-60 hover:!opacity-100 transition-all z-20 px-3 py-1 rounded-none-none border-2 border-dashed border-z-border/40 hover:border-z-border/70 backdrop-blur-xl`,children:(0,Q.jsxs)(`span`,{className:Y(`text-sm font-semibold flex items-center gap-1.5 `,`text-z-primary/70`),children:[(0,Q.jsx)(M,{size:10,className:`text-z-secondary `}),` Insert`]})})}),(0,Q.jsx)(Vn,{section:e,index:t,totalSections:n,isActive:c===e.id,isMultiSelected:A.has(e.id),theme:r,showFieldIndicators:i,selectedField:a,schemaFields:o,fieldErrors:s,onSelect:t=>j(e.id,t?.shiftKey||!1),onDuplicate:()=>u(e.id),onDelete:()=>d(e.id),onAlign:t=>f(e.id,t),onFieldChange:(t,n)=>p(e.id,t,n),onFieldSelect:(e,t)=>{m({blockId:e,fieldKey:t}),w?.(e,t),l(e),j(e,!1)},i18nEnabled:h,currentLocale:g,getTranslatedValue:_,setTranslatedValue:v,onAddToDynamicZone:(e,t)=>{y({sectionId:e,fieldKey:t}),b(!0)},dragControls:N,onContextMenu:t=>C(t,e.id),onToggleCollapse:()=>T(e.id),onMoveUp:()=>E(e.id,`up`),onMoveDown:()=>E(e.id,`down`),onCopy:()=>D(e.id),onPaste:()=>O(e.id),onBlockNameChange:t=>k(e.id,t)})]},e.id)},(e,t)=>!(e.section!==t.section||e.index!==t.index||e.totalSections!==t.totalSections||e.theme!==t.theme||e.showFieldIndicators!==t.showFieldIndicators||e.editorActiveSection!==t.editorActiveSection||e.editorFieldErrors!==t.editorFieldErrors||e.editorSelectedField!==t.editorSelectedField||e.editorSchemaFields!==t.editorSchemaFields||e.i18nEnabled!==t.i18nEnabled||e.currentLocale!==t.currentLocale||e.broadcastCursor!==t.broadcastCursor||e.handleFieldChange!==t.handleFieldChange||e.selectedSections!==t.selectedSections||e.onMultiSelect!==t.onMultiSelect)),mr=class extends Z.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:{message:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0}}}componentDidCatch(e,t){this.setState({error:{message:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0,componentStack:t.componentStack}})}handleReset=()=>{this.setState({hasError:!1,error:null}),this.props.onReset?.()};handleCopyError=()=>{let{error:e}=this.state;if(!e)return;let t=[e instanceof Error?e.message:String(e),e instanceof Error?e.stack:void 0,e.componentStack].filter(Boolean).join(`
1
+ import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{$ as t,$t as n,A as r,At as i,Bt as a,C as o,Dn as s,Dt as c,E as l,En as u,Et as d,Fn as f,G as p,Gt as m,H as h,In as g,It as _,J as v,Jn as y,Jt as b,K as x,Kn as S,Ln as C,Lt as w,M as T,Mt as E,On as D,Ot as O,P as k,Pn as A,Pt as j,Q as M,Qn as ee,Rn as N,Tn as P,Un as F,Ut as I,V as te,Vn as ne,Vt as re,Wt as L,Xn as ie,Y as ae,Z as oe,Zt as se,an as ce,at as le,b as ue,bn as R,br as de,c as fe,cn as z,ct as pe,d as B,dt as me,en as he,er as V,f as ge,fn as _e,gn as ve,gt as ye,h as be,hr as xe,ht as Se,in as Ce,ir as H,it as we,j as Te,jt as Ee,k as De,kn as Oe,l as U,ln as ke,mr as Ae,n as je,nn as Me,nr as Ne,o as W,on as Pe,or as Fe,ot as Ie,p as Le,pt as Re,q as ze,qn as Be,qt as Ve,r as He,rn as Ue,rr as G,sn as We,st as Ge,tn as Ke,tr as qe,u as Je,un as Ye,ut as Xe,vr as Ze,xn as Qe,xr as $e,xt as et,y as tt,z as nt}from"./vendor-react-DQVTOTFO.js";import{t as rt}from"./vendor-C-9IqjvY.js";import{a as K,n as it,o as q,r as at,s as J,t as Y}from"./utils-fgvbH6CB.js";import{a as ot,i as st,l as ct,m as lt,n as ut,o as X,r as dt,t as ft,u as pt,v as mt,y as ht}from"./index-yE_3fruG.js";import{t as gt}from"./useUnsavedGuard-CMMKQT9a.js";import{t as _t}from"./EmptyState-X_SXKpQY.js";var Z=e($e(),1),Q=Ze(),vt=({x:e,y:t,theme:n,onClose:r,onDuplicate:i,onDelete:a,onAlign:c,onConvert:l})=>{let u=st(),d=(0,Z.useRef)(null),[f,p]=Z.useState(!1);(0,Z.useEffect)(()=>{let e=e=>{d.current&&!d.current.contains(e.target)&&r()};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[r]);let[m,h]=Z.useState({top:t,left:e});return(0,Z.useEffect)(()=>{if(d.current){let n=d.current.getBoundingClientRect(),r={top:t,left:e};e+n.width>window.innerWidth&&(r.left=e-n.width),t+n.height>window.innerHeight&&(r.top=t-n.height),h(r)}},[e,t]),(0,Q.jsx)(`div`,{ref:d,style:{top:m.top,left:m.left},className:`fixed z-[999] w-56 select-none font-sans`,children:(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.95,y:-5},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:-5},transition:{duration:.15},className:Y(`p-1.5 border rounded-none-none shadow-2xl backdrop-blur-xl relative`,n===`dark`?`bg-app/95 border-z-border text-z-primary`:`bg-z-panel/95 border-z-border text-z-primary shadow-sm/50`),children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(`button`,{onMouseEnter:()=>p(!0),onClick:()=>p(!f),className:Y(`w-full flex items-center justify-between px-3 py-2 text-left text-xs font-semibold rounded-none-none transition-colors`,n===`dark`?`hover:bg-z-hover`:`hover:bg-[var(--z-bg-hover)]`),children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(v,{size:13,className:`text-z-secondary`}),`Convert to Layout`]}),(0,Q.jsx)(ce,{size:12,className:`opacity-50`})]}),f&&(0,Q.jsx)(`div`,{className:`absolute left-full top-0 ml-1 w-52 select-none`,onMouseLeave:()=>p(!1),children:(0,Q.jsx)(G.div,{initial:{opacity:0,x:-5},animate:{opacity:1,x:0},className:Y(`p-1.5 border rounded-none-none shadow-2xl backdrop-blur-xl max-h-72 overflow-y-auto custom-editor-scrollbar`,n===`dark`?`bg-app/95 border-z-border text-z-primary`:`bg-z-panel/95 border-z-border text-z-primary`),children:u.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>{l(e.type),r()},className:Y(`w-full flex items-center gap-2.5 px-2.5 py-1.5 text-left text-xs rounded-none-none transition-colors font-medium`,n===`dark`?`hover:bg-z-hover`:`hover:bg-[var(--z-bg-hover)]`),children:[e.icon&&(0,Q.jsx)(e.icon,{size:13,className:`text-z-secondary shrink-0`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.title})]},e.type))})})]}),(0,Q.jsx)(`div`,{className:Y(`h-px my-1`,n===`dark`?`bg-z-hover`:`bg-[var(--z-bg-hover)]`)}),(0,Q.jsxs)(`button`,{onClick:()=>{i(),r()},className:Y(`w-full flex items-center gap-2 px-3 py-2 text-left text-xs font-semibold rounded-none-none transition-colors`,n===`dark`?`hover:bg-z-hover`:`hover:bg-[var(--z-bg-hover)]`),children:[(0,Q.jsx)(b,{size:13,className:`text-z-secondary`}),`Duplicate Section`]}),(0,Q.jsx)(`div`,{className:Y(`h-px my-1`,n===`dark`?`bg-z-hover`:`bg-[var(--z-bg-hover)]`)}),(0,Q.jsx)(`div`,{className:`px-3 py-1.5 text-xs font-semibold opacity-40`,children:`Alignment`}),(0,Q.jsxs)(`div`,{className:`flex gap-1 px-1.5 pb-1`,children:[(0,Q.jsx)(`button`,{onClick:()=>{c(`left`),r()},"aria-label":`Align left`,className:Y(`flex-1 flex items-center justify-center p-1.5 border rounded-none-none transition-all`,n===`dark`?`border-z-border hover:border-z-border/30 hover:bg-z-hover text-z-muted hover:text-z-secondary`:`border-z-border hover:border-z-border hover:bg-[var(--z-bg-input)] text-z-secondary hover:text-z-secondary`),children:(0,Q.jsx)(s,{size:13,"aria-hidden":`true`})}),(0,Q.jsx)(`button`,{onClick:()=>{c(`center`),r()},"aria-label":`Align center`,className:Y(`flex-1 flex items-center justify-center p-1.5 border rounded-none-none transition-all`,n===`dark`?`border-z-border hover:border-z-border/30 hover:bg-z-hover text-z-muted hover:text-z-secondary`:`border-z-border hover:border-z-border hover:bg-[var(--z-bg-input)] text-z-secondary hover:text-z-secondary`),children:(0,Q.jsx)(Oe,{size:13,"aria-hidden":`true`})}),(0,Q.jsx)(`button`,{onClick:()=>{c(`right`),r()},"aria-label":`Align right`,className:Y(`flex-1 flex items-center justify-center p-1.5 border rounded-none-none transition-all`,n===`dark`?`border-z-border hover:border-z-border/30 hover:bg-z-hover text-z-muted hover:text-z-secondary`:`border-z-border hover:border-z-border hover:bg-[var(--z-bg-input)] text-z-secondary hover:text-z-secondary`),children:(0,Q.jsx)(D,{size:13,"aria-hidden":`true`})})]}),(0,Q.jsx)(`div`,{className:Y(`h-px my-1`,n===`dark`?`bg-z-hover`:`bg-[var(--z-bg-hover)]`)}),(0,Q.jsxs)(`button`,{onClick:()=>{a(),r()},className:Y(`w-full flex items-center gap-2 px-3 py-2 text-left text-xs font-semibold rounded-none-none transition-colors`,n===`dark`?`hover:bg-rose-500/10 text-rose-400`:`hover:bg-rose-50 text-rose-600`),children:[(0,Q.jsx)(o,{size:13,className:`text-rose-500`}),`Delete Section`]})]})})},yt=`zenith_editor_state`,bt=1200,xt=()=>{try{let e=localStorage.getItem(yt);if(!e)return null;let t=JSON.parse(e);if(t&&typeof t==`object`)return{data:t.data||t,undoStack:Array.isArray(t.undoStack)?t.undoStack:[],redoStack:Array.isArray(t.redoStack)?t.redoStack:[]}}catch{}return null},St=e=>typeof structuredClone==`function`?structuredClone(e):JSON.parse(JSON.stringify(e)),Ct=0,wt=xt(),Tt=(e,t)=>({data:wt?wt.data:null,loading:!1,saving:!1,hasUnsavedChanges:!1,lastSavedAt:null,undoStack:wt?wt.undoStack:[],redoStack:wt?wt.redoStack:[],dirtySections:new Set,schemaFields:[],fieldSettings:{},fieldErrors:{},history:[],templates:[],topLevelFields:[],setData:t=>e({data:t}),setLoading:t=>e({loading:t}),setSaving:t=>e({saving:t}),setHasUnsavedChanges:t=>e({hasUnsavedChanges:t}),setLastSavedAt:t=>e({lastSavedAt:t}),setSchemaFields:t=>e({schemaFields:t}),setFieldSettings:t=>e({fieldSettings:t}),setFieldErrors:t=>e({fieldErrors:t}),setHistory:t=>e({history:t}),setTemplates:t=>e({templates:t}),setTopLevelFields:t=>e({topLevelFields:t}),updateData:n=>{let r=t().data;if(!r)return;let i=rt(r,e=>{let t=n(e);t!==void 0&&Object.assign(e,t)});e(e=>{let t=Date.now(),n=t-Ct>bt,a=n?[...e.undoStack.slice(-199),r]:e.undoStack;n&&(Ct=t);let o=new Set(e.dirtySections);return i.sections.forEach(e=>o.add(e.id)),{data:i,hasUnsavedChanges:!0,undoStack:a,redoStack:[],dirtySections:o}})},setField:(n,r,i)=>{let a;try{a=t().data}catch{return}if(!a)return;let o=Date.now(),s=o-Ct>bt,c=s?[...t().undoStack.slice(-199),St(a)]:t().undoStack;s&&(Ct=o);let l=a.sections.map(e=>e.id!==n||e.content[r]===i?e:{...e,content:{...e.content,[r]:i}}),u={...a,sections:l},d=new Set(t().dirtySections);d.add(n),e({data:u,hasUnsavedChanges:!0,undoStack:c,redoStack:[],dirtySections:d})},undo:()=>{let{data:n,undoStack:r,redoStack:i}=t();if(!n||r.length===0)return;let a=r[r.length-1],o=r.slice(0,-1),s=St(n);e({data:a,undoStack:o,redoStack:[...i.slice(-199),s],hasUnsavedChanges:!0})},redo:()=>{let{data:n,undoStack:r,redoStack:i}=t();if(!n||i.length===0)return;let a=i[i.length-1],o=i.slice(0,-1),s=St(n);e({data:a,undoStack:[...r.slice(-199),s],redoStack:o,hasUnsavedChanges:!0})},load:async(t,n,r)=>{e({data:null,loading:!0,undoStack:[],redoStack:[],hasUnsavedChanges:!1});try{let i=r?await q.get(`/globals/${n}`):await q.get(`/${t}/${n}`),a=(i.data.data.sections||[]).map((e,t)=>({...e,id:e.id||`node_${t+1}`,content:e.content||e.blockData})),o={...i.data.data,sections:a};return e({data:o,activeSection:`root`}),o}finally{e({loading:!1})}},save:async(n,r,i,a)=>{let{data:o}=t();if(o){e({saving:!0});try{let t=a(o),s=(i?await q.patch(`/globals/${r}`,t):await q.patch(`/${n}/${r}`,t)).data?.data?._version;e(s===void 0?{hasUnsavedChanges:!1,dirtySections:new Set}:{data:{...o,_version:s},hasUnsavedChanges:!1,dirtySections:new Set})}finally{e({saving:!1})}}}}),Et=e=>({activeSection:`root`,selectedField:null,selectedFieldId:null,setActiveSection:t=>e({activeSection:t}),setSelectedField:t=>e({selectedField:t}),setSelectedFieldId:t=>e({selectedFieldId:t})}),Dt=e=>({mediaAssets:[],mediaSearch:``,mediaTypeFilter:`all`,mediaLoading:!1,setMediaAssets:t=>e({mediaAssets:t}),setMediaSearch:t=>e({mediaSearch:t}),setMediaTypeFilter:t=>e({mediaTypeFilter:t}),setMediaLoading:t=>e({mediaLoading:t})}),Ot=e=>({relationsField:null,relationsSearch:``,relationResults:[],selectedRelations:new Set,availableCollections:[],setRelationsField:t=>e({relationsField:t}),setRelationsSearch:t=>e({relationsSearch:t}),setRelationResults:t=>e({relationResults:t}),setSelectedRelations:t=>e({selectedRelations:t}),setAvailableCollections:t=>e({availableCollections:t})}),$=Fe((e,t,n)=>({...Tt(e,t,n),...Et(e,t,n),...Dt(e,t,n),...Ot(e,t,n),reset:()=>{try{localStorage.removeItem(yt)}catch{}e({data:null,loading:!1,saving:!1,hasUnsavedChanges:!1,lastSavedAt:null,undoStack:[],redoStack:[],dirtySections:new Set,activeSection:`root`,selectedField:null,fieldErrors:{},relationsField:null,relationsSearch:``,relationResults:[],selectedRelations:new Set,mediaAssets:[],mediaSearch:``,mediaTypeFilter:`all`,mediaLoading:!1})}})),kt=Fe(e=>({leftOpen:!0,rightOpen:!0,leftWidth:300,rightWidth:420,activeRightTab:`preview`,viewMode:`visual`,previewMode:`desktop`,focusMode:!1,setLeftOpen:t=>e({leftOpen:t}),setRightOpen:t=>e({rightOpen:t}),setLeftWidth:t=>e({leftWidth:t}),setRightWidth:t=>e({rightWidth:t}),setActiveRightTab:t=>e({activeRightTab:t}),setViewMode:t=>e({viewMode:t}),setPreviewMode:t=>e({previewMode:t}),toggleFocusMode:()=>e(e=>({focusMode:!e.focusMode}))})),At=({isGlobal:e,resizingSide:t,startResizing:n,addBlock:r,setInjectionIndex:i,setBlockPickerOpen:a,removeSection:s})=>{let{theme:c}=K(),l=st(),[u,d]=(0,Z.useState)(``),{data:p,activeSection:m,setActiveSection:g,updateData:_}=$(W(e=>({data:e.data,activeSection:e.activeSection,setActiveSection:e.setActiveSection,updateData:e.updateData}))),{leftOpen:v,leftWidth:y,setLeftOpen:b,focusMode:x}=kt(W(e=>({leftOpen:e.leftOpen,leftWidth:e.leftWidth,setLeftOpen:e.setLeftOpen,focusMode:e.focusMode}))),S=m??`root`,C=u.trim().length>0,w=(0,Z.useMemo)(()=>{let e=p?.sections||[];if(!C)return e;let t=u.toLowerCase();return e.filter(e=>(e.blockName||e.title||X(e.blockType)).toLowerCase().includes(t)||e.blockType.toLowerCase().includes(t))},[p?.sections,u,C]),T=e=>{if(C)return;let t=new Set(p?.sections.map(e=>e.id));e.every(e=>t.has(e.id))&&_(t=>{t.sections=e})},E=e=>l.find(t=>t.type===e)?.icon||f,D=c===`dark`;return(0,Q.jsx)(H,{children:v&&!x&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:()=>b(!1),className:`md:hidden fixed inset-0 bg-app/50 backdrop-blur-sm z-[99]`}),(0,Q.jsxs)(G.aside,{initial:{x:`-100%`},animate:{x:0},exit:{x:`-100%`},transition:{type:`spring`,damping:25,stiffness:200},style:{width:y},className:Y(`border-r flex flex-col z-50 overflow-hidden shrink-0 h-full`,`md:relative fixed inset-y-0 left-0 max-md:!w-[280px] max-md:z-[100] max-md:shadow-2xl`,D?`bg-app border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsx)(`div`,{onMouseDown:n(`left`),className:Y(`absolute right-0 top-0 bottom-0 w-1 cursor-col-resize z-50 transition-colors`,t===`left`?`bg-z-border`:`bg-transparent hover:bg-z-hover`)}),(0,Q.jsxs)(`div`,{className:Y(`px-3 py-3 border-b flex items-center justify-between`,D?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-muted`,children:`Layers`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{onClick:()=>{i(0),a(!0)},className:Y(`p-1 rounded-none-none border transition-all text-z-muted hover:text-z-secondary `,D?`bg-z-hover border-z-border`:`bg-z-input border-z-border`),"aria-label":`Add new section`,title:`Add section`,children:(0,Q.jsx)(M,{size:14})}),(0,Q.jsx)(`button`,{onClick:()=>b(!1),className:`md:hidden p-1 rounded-none-none border transition-all text-z-muted hover:text-rose-500`,"aria-label":`Close layers panel`,children:(0,Q.jsx)(B,{size:14})})]})]}),(p?.sections?.length||0)>3&&(0,Q.jsx)(`div`,{className:`px-3 pt-2 pb-1`,children:(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(h,{size:11,className:Y(`absolute left-2.5 top-1/2 -translate-y-1/2`,D?`text-z-secondary`:`text-z-muted`)}),(0,Q.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:`Filter layers...`,className:Y(`w-full pl-7 pr-7 py-1.5 text-xs font-bold border rounded-none-none bg-transparent transition-all`,`border-z-border text-z-primary placeholder:text-z-muted focus:border-z-border/30`),"aria-label":`Filter layers`}),u&&(0,Q.jsx)(`button`,{onClick:()=>d(``),className:Y(`absolute right-2 top-1/2 -translate-y-1/2 p-0.5`,D?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`),"aria-label":`Clear filter`,children:(0,Q.jsx)(B,{size:10})})]})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto custom-editor-scrollbar px-2 pt-3 pb-4 space-y-2`,children:w.length===0?(0,Q.jsx)(`div`,{className:`flex flex-col items-center justify-center h-full gap-3 text-center px-4`,children:p?.sections?.length===0?(0,Q.jsx)(_t,{icon:f,title:`No sections yet`,message:`Add your first section to start building`}):(0,Q.jsx)(_t,{icon:h,title:`No matches`,message:`Try a different search term`})}):C?(0,Q.jsx)(`div`,{className:`space-y-1`,children:w.map(e=>{let t=E(e.blockType);return(0,Q.jsxs)(`button`,{onClick:()=>g(e.id),className:Y(`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-none-none border text-left transition-all`,S===e.id?D?`bg-z-panel border-z-border text-z-primary`:`bg-[var(--z-active-bg)] text-[var(--z-active-text)] border border-[var(--z-active-border)] shadow-sm`:D?`bg-z-hover border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`:`bg-z-panel border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)] hover:text-z-primary`),"aria-label":`Select section: ${e.blockName||e.title||X(e.blockType)}`,children:[(0,Q.jsx)(t,{size:12,className:Y(`shrink-0`,S===e.id?``:D?`text-z-muted/60`:`text-z-secondary/60`)}),(0,Q.jsx)(`span`,{className:`text-xs font-semibold truncate flex-1`,children:e.blockName||e.title||X(e.blockType)}),e.blockType!==X(e.blockType)&&(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold shrink-0`,S===e.id?`opacity-60`:D?`text-z-secondary`:`text-z-muted`),children:X(e.blockType)})]},e.id)})}):(0,Q.jsx)(qe,{axis:`y`,values:p?.sections||[],onReorder:T,className:`space-y-1`,as:`div`,children:(p?.sections||[]).map(e=>{let t=E(e.blockType);return(0,Q.jsx)(V,{value:e,as:`div`,children:(0,Q.jsx)(`div`,{className:`w-full flex items-center gap-0`,children:(0,Q.jsxs)(`div`,{onClick:()=>g(e.id),className:Y(`flex-1 flex items-center gap-2.5 px-2.5 py-2 rounded-none-none border text-left transition-all cursor-pointer`,S===e.id?D?`bg-z-panel border-z-border text-z-primary`:`bg-[var(--z-active-bg)] text-[var(--z-active-text)] border border-[var(--z-active-border)] shadow-sm`:D?`bg-z-hover border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`:`bg-z-panel border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)] hover:text-z-primary`),"aria-label":`Select section: ${e.blockName||e.title||X(e.blockType)}`,children:[(0,Q.jsx)(Ee,{size:12,className:`opacity-30 shrink-0 cursor-grab active:cursor-grabbing`,"aria-hidden":`true`}),(0,Q.jsx)(t,{size:12,className:Y(`shrink-0`,S===e.id?``:D?`text-z-muted/60`:`text-z-secondary/60`),"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`text-xs font-semibold truncate flex-1`,children:e.blockName||e.title||X(e.blockType)}),e.blockType!==X(e.blockType)&&(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold shrink-0`,S===e.id?D?`text-z-muted/80`:`text-z-secondary/80`:`text-z-muted`),children:X(e.blockType)}),(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),s(e.id)},className:Y(`p-1 shrink-0 rounded-none opacity-0 group-hover:opacity-100 transition-opacity ml-1`,D?`hover:bg-rose-500/20 text-rose-500/70 hover:text-rose-500`:`hover:bg-rose-100 text-rose-500/70 hover:text-rose-600`),"aria-label":`Delete layer`,children:(0,Q.jsx)(o,{size:12})})]})})},e.id)})})})]})]})})},jt={siteId:`activeSiteId`,siteSlug:`activeSiteSlug`,siteDomain:`activeSiteDomain`,workspaceId:`activeWorkspaceId`},Mt=[`/login`,`/select-site`,`/sites`,`/auth`];function Nt(){return typeof window>`u`?!0:Mt.some(e=>window.location.pathname.startsWith(e))}function Pt(){let{activeSiteId:e,activeWorkspaceId:t,setActiveSiteId:n,setActiveWorkspaceId:r}=mt(W(e=>({activeSiteId:e.activeSiteId,activeWorkspaceId:e.activeWorkspaceId,setActiveSiteId:e.setActiveSiteId,setActiveWorkspaceId:e.setActiveWorkspaceId}))),i=e=>{try{return localStorage.getItem(e)||``}catch{return``}},a=(e,t)=>{try{localStorage.setItem(e,t)}catch{}},o=e=>{try{localStorage.removeItem(e)}catch{}},s=e||i(jt.siteId);return{siteId:s,siteSlug:i(jt.siteSlug),siteDomain:i(jt.siteDomain),workspaceId:t||i(jt.workspaceId),requireSiteId:(0,Z.useCallback)(()=>{if(s)return s;if(Nt())return``;throw Object.assign(Error(`Tenant context is required but activeSiteId is missing. Navigate to Site Selection to choose an active site.`),{code:`ERR_NO_TENANT`})},[s]),setSite:(0,Z.useCallback)((e,t,r)=>{n(e),J.getState().setActiveSiteId(e),t&&a(jt.siteSlug,t),r&&a(jt.siteDomain,r)},[n]),clearSite:(0,Z.useCallback)(()=>{n(null),J.getState().setActiveSiteId(null),o(jt.siteSlug),o(jt.siteDomain)},[n]),setWorkspace:(0,Z.useCallback)(e=>{r(e)},[r])}}var Ft=Fe((e,t)=>({comments:[],loading:!1,posting:!1,activeCommentId:null,setActiveCommentId:t=>e({activeCommentId:t}),fetchComments:async(t,n)=>{e({comments:[],loading:!0});try{e({comments:(await q.get(`/comments`,{params:{collection:t,documentId:n}})).data.data||[]})}catch{e({comments:[]})}finally{e({loading:!1})}},createComment:async({collection:t,documentId:n,blockId:r,fieldKey:i,content:a})=>{e({posting:!0});try{let o=await q.post(`/comments`,{collection:t,documentId:n,blockId:r,fieldKey:i,content:a});e(e=>({comments:[o.data.data,...e.comments]}))}finally{e({posting:!1})}},replyToComment:async(t,n)=>{e({posting:!0});try{let r=await q.post(`/comments/${t}/reply`,{content:n});e(e=>({comments:e.comments.map(e=>e._id===t?r.data.data:e)}))}finally{e({posting:!1})}},resolveComment:async(t,n)=>{try{let r=await q.patch(`/comments/${t}`,{resolved:n});e(e=>({comments:e.comments.map(e=>e._id===t?r.data.data:e)}))}catch{U.error(`Failed to update comment`)}},deleteComment:async t=>{try{await q.delete(`/comments/${t}`),e(e=>({comments:e.comments.filter(e=>e._id!==t)}))}catch{U.error(`Failed to delete comment`)}}}));function It(e){let t=Date.now(),n=new Date(e).getTime(),r=Math.floor((t-n)/1e3);return r<60?`${r}s ago`:r<3600?`${Math.floor(r/60)}m ago`:r<86400?`${Math.floor(r/3600)}h ago`:`${Math.floor(r/86400)}d ago`}var Lt=({comment:e,onResolve:t,onReply:n,onDelete:r,posting:i,theme:a,currentUserId:s})=>{let[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(!0),m=e.authorId===s,h=()=>{u.trim()&&(n(e._id,u),d(``),l(!1))};return(0,Q.jsxs)(G.div,{initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-2},className:Y(`border rounded-none-none overflow-hidden`,e.resolved?a===`dark`?`border-z-border/10 bg-z-border/[0.03]`:`border-z-border bg-[var(--z-bg-input)]/50`:`border-z-border bg-z-panel`),children:[(0,Q.jsxs)(`div`,{className:`px-3 py-2.5 flex items-start gap-2.5`,children:[(0,Q.jsx)(`div`,{className:Y(`w-7 h-7 rounded-none-none flex items-center justify-center shrink-0 mt-0.5`,a===`dark`?`bg-z-panel border border-z-border/20`:`bg-[var(--z-bg-input)] border border-z-border`),children:(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:e.author?.[0]||`?`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:e.author}),(0,Q.jsx)(`span`,{className:`text-sm text-z-secondary font-bold`,children:It(e.createdAt)}),e.resolved&&(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold px-1.5 py-0.5 rounded-none-none`,a===`dark`?`bg-z-panel/5 text-z-secondary`:`bg-[var(--z-bg-hover)] text-z-secondary`),children:`Resolved`}),e.blockId&&(0,Q.jsxs)(`span`,{className:Y(`text-sm font-mono px-1 py-0.5 rounded-none-none`,a===`dark`?`bg-amber-500/10 text-amber-400`:`bg-amber-50 text-amber-600`),children:[`Block: `,e.blockId]})]}),(0,Q.jsx)(`p`,{className:Y(`text-xs leading-relaxed font-medium mt-1`,e.resolved?` text-z-secondary`:`text-z-secondary`),children:e.content})]})]}),e.replies?.length>0&&(0,Q.jsxs)(`div`,{className:Y(`border-t`,a===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsxs)(`button`,{onClick:()=>p(e=>!e),className:Y(`w-full flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold transition-colors`,a===`dark`?`text-z-secondary hover:text-z-secondary`:`text-z-muted hover:text-z-secondary`),children:[(0,Q.jsx)(Ve,{size:8}),e.replies.length,` `,e.replies.length===1?`reply`:`replies`,f?(0,Q.jsx)(Ce,{size:8,className:`ml-auto`}):(0,Q.jsx)(We,{size:8,className:`ml-auto`})]}),(0,Q.jsx)(H,{initial:!1,children:f&&(0,Q.jsx)(G.div,{initial:{height:0},animate:{height:`auto`},exit:{height:0},transition:{duration:.15},className:`overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`px-3 pb-2 space-y-2`,children:e.replies.map((e,t)=>(0,Q.jsx)(`div`,{className:Y(`flex gap-2 pl-3 border-l-2`,a===`dark`?`border-z-border/20`:`border-z-border`),children:(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-muted`,children:e.author}),(0,Q.jsx)(`span`,{className:`text-sm text-z-secondary`,children:It(e.createdAt)})]}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-medium`,children:e.content})]})},t))})})})]}),(0,Q.jsxs)(`div`,{className:Y(`px-3 py-1.5 border-t flex items-center gap-3`,a===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsxs)(`button`,{onClick:()=>l(e=>!e),className:Y(`flex items-center gap-1 text-xs font-semibold transition-colors`,a===`dark`?`text-z-secondary hover:text-z-secondary`:`text-z-muted hover:text-z-secondary`),children:[(0,Q.jsx)(Ve,{size:9}),`Reply`]}),(0,Q.jsxs)(`button`,{onClick:()=>t(e._id,!e.resolved),className:Y(`flex items-center gap-1 text-xs font-semibold transition-colors`,e.resolved?a===`dark`?`text-z-secondary hover:text-z-secondary`:`text-z-secondary hover:text-z-secondary`:a===`dark`?`text-z-muted/50 hover:text-z-secondary`:`text-z-secondary hover:text-z-secondary `),children:[e.resolved?(0,Q.jsx)(ke,{size:9}):(0,Q.jsx)(z,{size:9}),e.resolved?`Reopen`:`Resolve`]}),m&&(0,Q.jsxs)(`button`,{onClick:()=>r(e._id),className:Y(`flex items-center gap-1 text-xs font-semibold transition-colors ml-auto`,a===`dark`?`text-z-secondary hover:text-rose-400`:`text-z-muted hover:text-rose-500`),children:[(0,Q.jsx)(o,{size:9}),`Delete`]})]}),(0,Q.jsx)(H,{initial:!1,children:c&&(0,Q.jsx)(G.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:`overflow-hidden`,children:(0,Q.jsxs)(`div`,{className:Y(`px-3 py-2 border-t flex gap-2`,a===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`input`,{autoFocus:!0,type:`text`,value:u,onChange:e=>d(e.target.value),onKeyDown:e=>e.key===`Enter`&&h(),placeholder:`Write a reply...`,className:Y(`flex-1 px-2.5 py-1.5 text-xs rounded-none-none border transition-all`,a===`dark`?`bg-z-hover border-z-border text-z-primary placeholder:text-z-muted focus:border-z-border/50`:`bg-z-input border-z-border text-z-primary placeholder:text-z-muted focus:border-z-border-strong`)}),(0,Q.jsx)(`button`,{onClick:h,disabled:i||!u.trim(),"aria-label":`Send reply`,className:Y(`px-2.5 py-1.5 text-xs font-semibold border transition-all rounded-none-none disabled:opacity-50`,a===`dark`?`bg-z-hover border-z-border-strong border-z-border/20 text-z-secondary hover:bg-z-border/30`:`bg-z-input border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`),children:(0,Q.jsx)(te,{size:10,"aria-hidden":`true`})}),(0,Q.jsx)(`button`,{onClick:()=>{l(!1),d(``)},"aria-label":`Cancel reply`,className:Y(`px-2 py-1.5 text-xs font-semibold border rounded-none-none`,a===`dark`?`border-z-border text-z-secondary`:`border-z-border text-z-muted`),children:(0,Q.jsx)(B,{size:10,"aria-hidden":`true`})})]})})})]})},Rt=({collection:e,documentId:t,theme:n})=>{let{comments:r,loading:i,posting:a,fetchComments:o,createComment:s,replyToComment:c,resolveComment:l,deleteComment:u}=Ft(W(e=>({comments:e.comments,loading:e.loading,posting:e.posting,fetchComments:e.fetchComments,createComment:e.createComment,replyToComment:e.replyToComment,resolveComment:e.resolveComment,deleteComment:e.deleteComment}))),{user:d}=ht(W(e=>({user:e.user}))),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{o(e,t)},[e,t]);let g=()=>{f.trim()&&(s({collection:e,documentId:t,content:f}),p(``))};r.length;let _=m?r:r.filter(e=>!e.resolved);return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(pe,{size:11,className:`text-z-secondary`}),(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:`Review`}),(0,Q.jsxs)(`span`,{className:Y(`px-1.5 py-0.5 text-sm font-semibold rounded-none-none`,n===`dark`?`bg-z-hover text-z-secondary`:`bg-[var(--z-bg-hover)] text-z-secondary`),children:[r.filter(e=>!e.resolved).length,` open / `,r.length,` total`]})]}),(0,Q.jsx)(`button`,{onClick:()=>h(e=>!e),className:Y(`text-xs font-semibold transition-colors`,n===`dark`?`text-z-secondary hover:text-z-secondary`:`text-z-muted hover:text-z-secondary`),children:m?`Hide resolved`:`Show resolved`})]}),(0,Q.jsxs)(`div`,{className:Y(`border rounded-none-none p-2.5`,n===`dark`?`border-z-border bg-z-panel`:`border-z-border bg-[var(--z-bg-input)]/50`),children:[(0,Q.jsx)(`textarea`,{value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&g()},placeholder:`Add a comment... (Cmd+Enter to submit)`,rows:2,className:Y(`w-full px-2 py-1.5 text-xs rounded-none-none border-none bg-transparent resize-none focus:outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black focus:ring-0 placeholder:text-z-muted`,n===`dark`?`text-z-secondary placeholder:text-z-muted`:`text-z-primary placeholder:text-z-muted`)}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mt-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm text-z-secondary font-bold`,children:`Cmd+Enter to submit`}),(0,Q.jsxs)(`button`,{onClick:g,disabled:a||!f.trim(),className:Y(`flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold border rounded-none-none transition-all disabled:opacity-50`,n===`dark`?`bg-z-hover border-z-border-strong border-z-border/30 text-z-secondary hover:bg-z-border/30 hover:border-z-border/50`:`bg-z-input border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)] hover:border-z-border-strong`),children:[(0,Q.jsx)(pe,{size:9}),`Comment`]})]})]}),i?(0,Q.jsxs)(`div`,{className:`text-center py-4`,children:[(0,Q.jsx)(`div`,{className:Y(`w-4 h-4 border-2 border-z-border border-t-transparent rounded-none-none animate-spin mx-auto mb-2`)}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-bold`,children:`Loading comments...`})]}):_.length===0?(0,Q.jsxs)(`div`,{className:Y(`py-5 text-center border border-dashed rounded-none-none`,`border-z-border`),children:[(0,Q.jsx)(pe,{size:16,className:`mx-auto text-z-secondary mb-1.5`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-bold`,children:`No comments yet`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary mt-0.5`,children:`Be the first to leave a review note`})]}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:(0,Q.jsx)(H,{initial:!1,children:_.map(e=>(0,Q.jsx)(Lt,{comment:e,onResolve:l,onReply:c,onDelete:u,posting:a,theme:n,currentUserId:d?.id},e._id))})})]})},zt={desktop:{width:1440,height:900,icon:le},tablet:{width:768,height:1024,icon:De},mobile:{width:375,height:812,icon:k}},Bt=({isGlobal:e=!1,resizingSide:t,startResizing:n,iframeRef:r,handleRestore:i,onCompareDiff:o})=>{let{id:s,slug:l}=xe(),u=s||l,{theme:d}=K(),{history:f,data:p,availableCollections:m}=$(W(e=>({history:e.history,data:e.data,availableCollections:e.availableCollections}))),{rightOpen:h,rightWidth:g,activeRightTab:_,setActiveRightTab:v,setRightOpen:y,previewMode:b,setPreviewMode:x,focusMode:S}=kt(W(e=>({rightOpen:e.rightOpen,rightWidth:e.rightWidth,activeRightTab:e.activeRightTab,setActiveRightTab:e.setActiveRightTab,setRightOpen:e.setRightOpen,previewMode:e.previewMode,setPreviewMode:e.setPreviewMode,focusMode:e.focusMode}))),{siteId:C,siteSlug:w,siteDomain:T}=Pt(),[E,D]=Z.useState([]),[O,k]=Z.useState(null),A=e?`globals`:l||`pages`;Z.useEffect(()=>{q.get(`/sites`).then(e=>{D(e.data?.data||[])}).catch(()=>{U.error(`Failed to load sites`)})},[]),Z.useEffect(()=>{(async()=>{if(!(!u||u===`new`)&&A!==`globals`)try{k((await q.post(`/${A}/${u}/preview-token`)).data.data?.token||null)}catch{}})()},[A,u]);let j=p?.siteId,M=j&&E.some(e=>(e._id||e.id)===j)?j:C||``,ee=E.find(e=>(e._id||e.id)===M),N=ee?ee.domain:`http://localhost:5177`,P=``;N&&N.trim()!==``&&(P=N.startsWith(`http`)?N:`http://${N}`);let F=(m?.find(e=>e.slug===A))?.admin?.previewUrl,I=``;typeof F==`string`?I=F.replace(/{{storefrontUrl}}/g,P).replace(/{{previewToken}}/g,O||``).replace(/{{id}}/g,u||``).replace(/{{slug}}/g,p?.slug||u||``).replace(/{{siteId}}/g,M).replace(/{{viewport}}/g,b).replace(/{{collection}}/g,A):P&&(I=`${P}${A===`posts`?`/post/preview`:``}?preview=true&token=${O||``}&collection=${A}&id=${u}&siteId=${M}&viewport=${b}`);let te=[{id:`preview`,icon:a,label:`Live`},{id:`history`,icon:c,label:`Versions`},{id:`comments`,icon:pe,label:`Review`}],ne=zt[b]||zt.desktop,re=b===`desktop`,L=d===`dark`;return(0,Q.jsx)(H,{initial:!1,children:h&&!S&&(0,Q.jsxs)(G.aside,{initial:{width:0,opacity:0},animate:{width:g,opacity:1},exit:{width:0,opacity:0},className:Y(`border-l flex flex-col z-50 overflow-hidden shrink-0`,`md:relative fixed inset-y-0 right-0 max-md:!w-[280px] max-md:z-[100] max-md:shadow-2xl`,L?`bg-app border-z-border`:`bg-z-panel border-z-border shadow-xl`),children:[(0,Q.jsx)(`div`,{onClick:()=>y(!1),className:`md:hidden fixed inset-0 bg-app/50 backdrop-blur-sm z-[99]`}),(0,Q.jsx)(`div`,{onMouseDown:n(`right`),className:Y(`absolute left-0 top-0 bottom-0 w-1 cursor-col-resize z-50 transition-colors`,t===`right`?`bg-z-border shadow-sm`:`bg-transparent hover:bg-z-hover`)}),(0,Q.jsxs)(`div`,{className:Y(`px-3 py-2 border-b flex items-center justify-between shrink-0`,L?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-4`,children:te.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>v(e.id),className:Y(`flex flex-col transition-all`,_===e.id?`opacity-100`:`opacity-40 hover:opacity-100`),"aria-label":e.label,children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-semibold `,_===e.id?`text-z-primary`:L?`text-z-secondary`:`text-z-muted`),children:e.label}),(0,Q.jsx)(`div`,{className:`h-0.5 w-full mt-1`,style:{backgroundColor:_===e.id?`var(--z-accent)`:`transparent`}})]},e.id))}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>y(!1),className:`p-1 hover:text-z-secondary transition-colors`,"aria-label":`Close panel`,children:(0,Q.jsx)(B,{size:16})})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-hidden relative custom-editor-scrollbar`,children:_===`preview`?(0,Q.jsxs)(`div`,{className:`w-full h-full flex flex-col`,children:[(0,Q.jsx)(`div`,{className:Y(`flex items-center justify-center gap-1 px-3 py-2 border-b shrink-0`,L?`border-z-border`:`border-z-border shadow-sm`),children:[`desktop`,`tablet`,`mobile`].map(e=>{let t=zt[e],n=t.icon;return(0,Q.jsxs)(`button`,{onClick:()=>x(e),className:Y(`flex items-center gap-1.5 px-2.5 py-1 rounded-none-none border text-sm font-semibold transition-all`,b===e?L?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-panel shadow-sm border border-z-border text-z-primary`:L?`bg-z-hover border-z-border text-z-secondary hover:text-z-secondary`:`bg-z-panel border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)] hover:text-z-primary`),"aria-label":`${e} preview`,title:`${e} (${t.width}×${t.height})`,children:[(0,Q.jsx)(n,{size:11}),e]},e)})}),(0,Q.jsx)(`div`,{className:`flex-1 flex items-center justify-center overflow-auto p-3`,children:I?(0,Q.jsx)(`div`,{className:Y(`transition-all duration-300 border overflow-hidden`,L?`border-z-border bg-[#030303] shadow-[0_0_40px_rgba(0,0,0,0.5)]`:`border-z-border bg-z-panel shadow-2xl`,re?`w-full h-full`:`rounded-none-none`),style:re?void 0:{width:Math.min(ne.width,g-40),height:ne.height},children:(0,Q.jsx)(`iframe`,{allow:`clipboard-read; clipboard-write`,ref:r,src:I,className:`w-full h-full border-none rounded-none-none`,title:`Live Preview`,sandbox:`allow-same-origin allow-scripts allow-forms`})}):(0,Q.jsxs)(`div`,{className:Y(`flex flex-col items-center justify-center h-full gap-3 text-center p-8`,L?`bg-[#0a0a0a]`:`bg-[var(--z-bg-input)]`),children:[(0,Q.jsx)(a,{size:28,className:`text-z-secondary`}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:Y(`text-xs font-semibold `,`text-z-secondary`),children:`Preview unavailable`}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-bold`,L?`text-z-primary`:`text-z-secondary`),children:P?`Preview URL is not configured for this collection.`:`Set VITE_STOREFRONT_URL to enable live preview`})]})]})})]}):_===`comments`?(0,Q.jsx)(`div`,{className:`w-full h-full p-3 overflow-y-auto custom-editor-scrollbar`,children:(0,Q.jsx)(Rt,{collection:e?`globals`:`pages`,documentId:u||``,theme:d})}):(0,Q.jsx)(`div`,{className:`w-full h-full p-3 overflow-y-auto custom-editor-scrollbar`,children:f.length===0?(0,Q.jsx)(`div`,{className:`flex flex-col h-full justify-center`,children:(0,Q.jsx)(_t,{icon:c,title:`No versions yet`,message:`Save your page to create a version snapshot`})}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:f.map((e,t)=>(0,Q.jsxs)(`div`,{className:Y(`group p-4 rounded-none-none border transition-all cursor-pointer space-y-2`,L?`bg-z-panel/5 border-z-border hover:bg-[var(--z-bg-hover)]`:`bg-z-input border-z-border hover:bg-[var(--z-bg-hover)]`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-semibold `,`text-z-primary`),children:t===0?`Current`:`V.${f.length-t}`}),(0,Q.jsx)(`span`,{className:`text-xs font-bold text-z-secondary`,children:new Date(e.createdAt).toLocaleDateString()})]}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-medium truncate`,children:e.changeLog||`Saved`}),t>0&&(0,Q.jsxs)(`div`,{className:`flex gap-1.5 opacity-0 group-hover:opacity-100 transition-all mt-1.5`,children:[(0,Q.jsx)(`button`,{onClick:n=>{n.stopPropagation(),o(e._id,f.length-t)},className:Y(`flex-1 py-1 border text-xs font-semibold text-center transition-all`,L?`bg-z-hover border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)] hover:text-z-primary`:`bg-[var(--z-bg-hover)] border-z-border text-z-primary hover:bg-[var(--z-border)] hover:text-z-primary`),children:`Compare`}),(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),i(e._id)},className:`flex-1 py-1 bg-z-accent hover:bg-z-border text-z-primary text-xs font-semibold text-center transition-all`,children:`Restore`})]})]},e._id||e.id))})})})]})})},Vt=de(),Ht=({imageUrl:e,initialX:t=50,initialY:n=50,onSave:r})=>{let[i,a]=(0,Z.useState)({x:t,y:n}),o=(0,Z.useRef)(null);return(0,Q.jsxs)(`div`,{style:{backgroundColor:`rgba(17, 24, 39, 0.65)`,backdropFilter:`blur(12px)`,WebkitBackdropFilter:`blur(12px)`,border:`1px solid rgba(255, 255, 255, 0.08)`,borderRadius:`12px`,boxShadow:`0 4px 30px rgba(0, 0, 0, 0.1)`,padding:`24px`,maxWidth:`500px`,width:`100%`,margin:`0 auto`,fontFamily:`'Inter', sans-serif`,color:`#F3F4F6`},children:[(0,Q.jsx)(`h3`,{style:{fontSize:`18px`,fontWeight:600,marginBottom:`8px`,color:`#F3F4F6`,letterSpacing:`-0.025em`},children:`AI Focal Point & Responsive Cropper`}),(0,Q.jsx)(`p`,{style:{fontSize:`13px`,color:`#9CA3AF`,marginBottom:`16px`,lineHeight:`1.4`},children:`Click anywhere on the image preview to set the focal focus coordinates. The storefront background positioning will dynamically scale around this center point.`}),(0,Q.jsxs)(`div`,{ref:o,onClick:e=>{if(!o.current)return;let t=o.current.getBoundingClientRect(),n=e.clientX-t.left,r=e.clientY-t.top,i=Math.round(n/t.width*100),s=Math.round(r/t.height*100);a({x:Math.max(0,Math.min(100,i)),y:Math.max(0,Math.min(100,s))})},style:{position:`relative`,width:`100%`,height:`260px`,borderRadius:`8px`,overflow:`hidden`,cursor:`crosshair`,border:`1.5px dashed rgba(255, 255, 255, 0.15)`,background:`#0B0F19`},children:[(0,Q.jsx)(`img`,{src:e,alt:`Salient Crop Preview`,style:{width:`100%`,height:`100%`,objectFit:`cover`,userSelect:`none`,opacity:.8}}),(0,Q.jsx)(`div`,{style:{position:`absolute`,left:`${i.x}%`,top:`${i.y}%`,transform:`translate(-50%, -50%)`,width:`28px`,height:`28px`,borderRadius:`50%`,border:`2.5px solid var(--z-accent)`,boxShadow:`0 0 12px var(--z-accent), inset 0 0 4px var(--z-accent)`,pointerEvents:`none`,display:`flex`,alignItems:`center`,justifyContent:`center`,transition:`left 0.15s cubic-bezier(0.25, 0.8, 0.25, 1), top 0.15s cubic-bezier(0.25, 0.8, 0.25, 1)`},children:(0,Q.jsx)(`div`,{style:{width:`6px`,height:`6px`,borderRadius:`50%`,backgroundColor:`var(--z-accent)`}})})]}),(0,Q.jsxs)(`div`,{style:{display:`flex`,justifyContent:`space-between`,alignItems:`center`,marginTop:`16px`,fontSize:`12px`,color:`#9CA3AF`},children:[(0,Q.jsxs)(`div`,{children:[`Focus Position:`,` `,(0,Q.jsxs)(`span`,{style:{color:`var(--z-accent)`,fontWeight:600},children:[`X: `,i.x,`%, Y: `,i.y,`%`]})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{r&&r(i.x,i.y)},style:{backgroundColor:`var(--z-accent)`,color:`#FFFFFF`,border:`none`,padding:`8px 16px`,borderRadius:`6px`,fontWeight:600,cursor:`pointer`,boxShadow:`0 4px 10px rgba(139, 92, 246, 0.3)`,transition:`transform 0.1s ease`},onMouseDown:e=>e.currentTarget.style.transform=`scale(0.96)`,onMouseUp:e=>e.currentTarget.style.transform=`scale(1)`,children:`Confirm Focal Selection`})]})]})},Ut=({value:e,onChange:t,hasMany:n,disabled:r=!1,focalPoint:i=!1})=>{let{theme:a}=K(),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)([]),[u,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(``),[v,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{x(!0)},[]);let S=Array.isArray(e)?e:e?[e]:[],w=Z.useRef({}),T=Z.useRef(new Set),E=e=>e?e.startsWith(`http`)?e:w.current[e]||e:``;(0,Z.useEffect)(()=>{if(!c.length)return;let e=c.filter(e=>e.url&&!e.url.startsWith(`http`)&&!w.current[e.url]);e.length&&e.forEach(e=>{fetch(`${e.url}`,{credentials:`include`}).then(e=>e.blob()).then(t=>{let n=URL.createObjectURL(t);T.current.add(n),w.current[e.url]=n,D(e=>e+1)}).catch(()=>{})})},[c]);let[,D]=Z.useState(0);(0,Z.useEffect)(()=>()=>{T.current.forEach(e=>URL.revokeObjectURL(e))},[]);let O=async()=>{f(!0);try{l((await q.get(`/media`)).data.data||[])}catch{console.error(`Failed to fetch media`),fe.error(`Failed to load media library`)}finally{f(!1)}};(0,Z.useEffect)(()=>{if(o){let e=setTimeout(()=>O(),0);return()=>clearTimeout(e)}},[o]);let k=e=>{if(i&&!n){y(e);return}n?S.find(t=>t._id===e._id)?t(S.filter(t=>t._id!==e._id)):t([...S,e]):(t(e),s(!1))},A=async(e,n,r)=>{let i={...e,focalPoint:{x:n,y:r}};try{e._id&&await q.patch(`/media/${e._id}`,{focalPoint:{x:n,y:r}})}catch{console.error(`Failed to save focal point`),fe.error(`Failed to save focal point`)}t(i),y(null),s(!1)},j=async e=>{if(!e.target.files?.[0])return;let r=new FormData;r.append(`file`,e.target.files[0]);try{let e=(await q.post(`/upload`,r,{headers:{"Content-Type":`multipart/form-data`}})).data.data;if(l([e,...c]),i&&!n){y(e);return}n||(t(e),s(!1))}catch{console.error(`Upload failed`),fe.error(`Upload failed`)}},ee=()=>{if(!g.trim())return;let e={_id:Math.random().toString(36).substring(7),url:g.trim(),filename:g.trim().split(`/`).pop()||`External URL`};n?t([...S,e]):(t(e),s(!1)),_(``)};return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[S.map((e,i)=>(0,Q.jsxs)(`div`,{className:`relative w-20 h-20 rounded-none-none border border-z-border overflow-hidden group shadow-sm transition-all hover:scale-105 active:scale-95`,children:[(0,Q.jsx)(`img`,{src:E(e.url),className:`w-full h-full object-cover`,alt:``}),!r&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(n?S.filter((e,t)=>t!==i):null),className:`absolute top-1 right-1 p-1 bg-app/60 text-z-primary rounded-none-none opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,Q.jsx)(B,{size:10})})]},e._id||i)),!r&&(n||S.length===0)&&(0,Q.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s(!0)},className:`w-20 h-20 rounded-none-none border border-dashed border-z-border flex flex-col items-center justify-center gap-1.5 text-z-muted hover:border-z-border/50 hover:text-z-secondary hover:bg-z-hover transition-all group`,children:[(0,Q.jsx)(M,{size:18,strokeWidth:3,className:`group-hover:scale-110 transition-transform`}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:`Add_Media`})]})]}),b&&(0,Vt.createPortal)((0,Q.jsx)(H,{children:o&&(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`fixed inset-0 z-[1000] flex items-center justify-center bg-[var(--z-bg-modal)] backdrop-blur-sm p-4 md:p-12`,onClick:()=>s(!1),children:(0,Q.jsx)(G.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},transition:{type:`spring`,damping:25,stiffness:300},className:Y(`w-full max-w-5xl max-h-full border rounded-none-none shadow-2xl flex flex-col overflow-hidden`,a===`dark`?`bg-app/90 backdrop-blur-xl border-z-border`:`bg-z-popover border-z-border`),onClick:e=>e.stopPropagation(),children:(0,Q.jsxs)(`div`,{className:`flex flex-col p-4 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`h3`,{className:Y(`text-sm font-semibold `,`text-z-primary`),children:`Asset Registry`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(!1),className:Y(`p-1 rounded-none-none transition-colors`,a===`dark`?`text-z-muted hover:text-z-primary hover:bg-[var(--z-bg-hover)]`:`text-z-secondary hover:text-z-primary hover:bg-app/5`),children:(0,Q.jsx)(B,{size:14})})]}),(0,Q.jsx)(H,{mode:`wait`,children:v?(0,Q.jsxs)(G.div,{initial:{opacity:0,x:20},animate:{opacity:1,x:0},exit:{opacity:0,x:-20},className:`flex flex-col gap-4`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-3`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>y(null),className:`text-sm font-semibold text-z-muted hover:text-z-primary transition-colors border border-z-border px-3 py-1.5 rounded-none-none`,children:`← Back`})}),(0,Q.jsx)(`div`,{className:`flex-1 min-h-[300px] flex items-center justify-center`,children:(0,Q.jsx)(Ht,{imageUrl:E(v.url),initialX:v.focalPoint?.x??50,initialY:v.focalPoint?.y??50,onSave:(e,t)=>A(v,e,t)})})]},`focal-step`):(0,Q.jsxs)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col md:flex-row gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex-[2] relative group`,children:[(0,Q.jsx)(h,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-z-secondary group-focus-within:text-z-secondary transition-colors`,size:14}),(0,Q.jsx)(`input`,{type:`text`,placeholder:`Search assets...`,value:p,onChange:e=>m(e.target.value),className:`w-full bg-z-hover border border-z-border rounded-none-none pl-9 pr-3 py-2 text-sm font-medium text-z-primary placeholder:text-z-secondary transition-all focus:bg-z-panel/10 focus:border-z-border/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black`})]}),(0,Q.jsxs)(`div`,{className:`flex-[2] relative flex gap-2`,children:[(0,Q.jsxs)(`div`,{className:`relative flex-1 group`,children:[(0,Q.jsx)(Se,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-z-secondary group-focus-within:text-z-secondary transition-colors`,size:14}),(0,Q.jsx)(`input`,{type:`url`,placeholder:`https://...`,value:g,onChange:e=>_(e.target.value),onKeyDown:e=>e.key===`Enter`&&ee(),className:`w-full bg-z-hover border border-z-border rounded-none-none pl-9 pr-3 py-2 text-sm font-medium text-z-primary placeholder:text-z-secondary transition-all focus:bg-z-panel/10 focus:border-z-border/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black`})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:ee,disabled:!g.trim(),className:`px-3 py-2 bg-z-hover border-z-border-strong text-z-secondary hover:bg-z-border/30 hover:text-z-primary rounded-none-none text-sm font-bold transition-all border border-z-border/30 disabled:opacity-50 disabled:cursor-not-allowed`,children:`Add`})]}),(0,Q.jsxs)(`label`,{className:`flex-1 flex items-center justify-center gap-2 px-4 py-2 bg-z-accent/20 hover:bg-z-accent/30 text-z-secondary rounded-none-none transition-all text-sm font-bold cursor-pointer border border-z-border/30`,children:[(0,Q.jsx)(F,{size:14}),(0,Q.jsx)(`span`,{children:`Upload`}),(0,Q.jsx)(`input`,{type:`file`,className:`hidden`,onChange:j})]})]}),(0,Q.jsx)(`div`,{className:`flex-1 min-h-[300px] max-h-[50vh] overflow-y-auto grid grid-cols-3 sm:grid-cols-4 lg:grid-cols-5 gap-3 pr-2 custom-scrollbar border border-z-border rounded-none-none p-3 bg-app/20`,children:u?(0,Q.jsxs)(`div`,{className:`col-span-full h-full flex flex-col items-center justify-center gap-4`,children:[(0,Q.jsx)(C,{className:`animate-spin text-z-secondary `,size:24}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-secondary animate-pulse`,children:`Syncing...`})]}):(()=>{let e=c.filter(e=>(e.alt||e.id||e.filename||``).toLowerCase().includes(p.toLowerCase()));return e.length===0?(0,Q.jsx)(`div`,{className:`col-span-full h-full flex flex-col justify-center py-6`,children:(0,Q.jsx)(_t,{icon:d,title:p?`No matches found`:`No media assets`,message:p?`Try a different search term`:`Upload an image to get started`})}):e.map(e=>{let t=S.some(t=>t._id===e._id);return(0,Q.jsxs)(`div`,{onClick:()=>k(e),className:Y(`group relative aspect-square rounded-none-none border overflow-hidden cursor-pointer transition-all`,t?`border-z-border shadow-sm scale-[0.98]`:`border-z-border hover:border-z-border/30`),children:[(0,Q.jsx)(`img`,{src:E(e.url),className:`w-full h-full object-cover transition-transform duration-700 group-hover:scale-110`,alt:``}),(0,Q.jsx)(`div`,{className:Y(`absolute inset-0 transition-all duration-300`,t?`bg-z-accent/10`:`bg-app/0 group-hover:bg-app/40`)}),(0,Q.jsx)(`div`,{className:`absolute inset-x-0 bottom-0 p-2 opacity-0 group-hover:opacity-100 translate-y-2 group-hover:translate-y-0 transition-all bg-gradient-to-t from-[var(--z-bg-panel)] to-transparent`,children:(0,Q.jsx)(`p`,{className:`text-sm font-semibold text-z-primary truncate`,children:e.filename||`Untitled_Asset`})}),t&&(0,Q.jsx)(`div`,{className:`absolute top-2 right-2 bg-z-accent text-z-primary rounded-none-none p-1.5 shadow-xl animate-in zoom-in-50 duration-300`,children:(0,Q.jsx)(z,{size:10,strokeWidth:4})})]},e._id)})})()}),(0,Q.jsxs)(`div`,{className:`pt-2 border-t border-z-border flex items-center justify-end gap-3 mt-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{s(!1),y(null)},className:`px-4 py-2 text-sm font-bold text-z-muted hover:text-z-primary transition-colors`,children:`Cancel`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{s(!1),y(null)},className:`px-6 py-2 bg-z-hover border-z-border-strong text-z-secondary hover:bg-z-border/30 hover:text-z-primary rounded-none-none text-sm font-bold transition-all border border-z-border/30`,children:`Done`})]})]},`asset-grid`)})]})})},`media-picker-backdrop`)}),document.body)]})},Wt=({value:e,onChange:t,relationTo:n,hasMany:r,disabled:i=!1})=>{let{theme:a}=K(),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)([]),[f,p]=(0,Z.useState)(!1),[m,g]=(0,Z.useState)(``),[,_]=(0,Z.useState)(null),v=Array.isArray(e)?e:e?[e]:[],y=async()=>{p(!0);try{let e=await q.get(`/health`),t=e.data.data?.collections||[],r=e.data.data?.globals||[];_(t.find(e=>e.slug===n)||r.find(e=>e.slug===n)),d((await q.get(`/${n}`)).data.data||[])}catch{console.error(`Failed to fetch relation data`)}finally{p(!1)}};(0,Z.useEffect)(()=>{if(o){let e=setTimeout(()=>y(),0);return()=>clearTimeout(e)}},[o,n]);let b=e=>{r?v.find(t=>t._id===e._id)?t(v.filter(t=>t._id!==e._id)):t([...v,e]):(t(e),s(!1))},x=e=>e?typeof e==`string`?e:e.name||e.title||e.email||e.id||e._id:``;return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[v.map((e,n)=>(0,Q.jsxs)(`div`,{onClick:()=>l(e._id),className:`flex items-center gap-3 px-4 py-2 bg-z-active-bg/30 border border-z-active-border rounded-none-none group transition-all hover:border-z-active-border cursor-pointer hover:bg-z-active-bg`,children:[(0,Q.jsx)(ye,{size:12,className:`text-z-active-text`}),(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-primary`,children:x(e)}),!i&&(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),t(r?v.filter((e,t)=>t!==n):null)},className:`p-1 hover:bg-z-active-bg rounded-none-none text-z-muted hover:text-z-accent transition-colors`,children:(0,Q.jsx)(B,{size:10})})]},e._id||n)),!i&&(r||v.length===0)&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`flex items-center gap-2.5 px-4 py-2 rounded-xl border-2 border-dashed border-z-border text-z-muted hover:border-z-active-border hover:text-z-accent hover:bg-z-active-bg/20 transition-all group`,children:[(0,Q.jsx)(M,{size:14,strokeWidth:3}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:`Link Record`})]})]}),(0,Q.jsx)(kn,{isOpen:!!c,onClose:()=>l(null),collectionSlug:n,documentId:c||``,onSaved:e=>{t(r?v.map(t=>t._id===e._id?e:t):e)}}),(0,Q.jsx)(H,{children:o&&(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[1000] flex items-center justify-center p-4 md:p-10 bg-app/70 backdrop-blur-md`,children:(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.98,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.98,y:10},className:Y(`w-full max-w-2xl h-[70vh] flex flex-col shadow-2xl overflow-hidden rounded-xl border`,a===`dark`?`bg-app/65 backdrop-blur-xl border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-8 border-b flex items-center justify-between`,`border-z-border`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Q.jsx)(`div`,{className:`w-10 h-10 bg-indigo-500 rounded-lg flex items-center justify-center text-z-primary shadow-lg shadow-sm`,children:(0,Q.jsx)(L,{size:20})}),(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(`h3`,{className:Y(`text-lg font-semibold leading-none`,`text-z-primary`),children:`Select Relation`}),(0,Q.jsxs)(`p`,{className:`text-sm font-bold text-z-muted mt-1.5`,children:[`Targeting Collection: `,n.toUpperCase()]})]})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(!1),className:Y(`w-10 h-10 flex items-center justify-center rounded-lg transition-all`,a===`dark`?`bg-z-panel/5 hover:bg-[var(--z-bg-hover)] text-z-primary`:`bg-[var(--z-bg-input)] hover:bg-[var(--z-bg-hover)] text-z-muted`),children:(0,Q.jsx)(B,{size:18})})]}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-hidden flex flex-col p-8 gap-6`,children:[(0,Q.jsxs)(`div`,{className:`relative group`,children:[(0,Q.jsx)(h,{className:`absolute left-4 top-1/2 -translate-y-1/2 text-z-muted group-focus-within:text-z-accent transition-colors`,size:16}),(0,Q.jsx)(`input`,{type:`text`,placeholder:`Search records...`,value:m,onChange:e=>g(e.target.value),className:Y(`w-full rounded-lg pl-12 pr-4 py-3 text-xs font-bold outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 border`,a===`dark`?`bg-app/20 border-z-border text-z-primary`:`bg-[var(--z-bg-input)] border-z-border text-z-primary`)})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto space-y-2 pr-2 custom-scrollbar`,children:f?(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center gap-4`,children:[(0,Q.jsx)(C,{className:`animate-spin text-z-active-text`,size:24}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-muted animate-pulse`,children:`Syncing Records...`})]}):u.length===0?(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center gap-4 opacity-30`,children:[(0,Q.jsx)(L,{size:32,className:`text-z-primary`}),(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold`,`text-z-primary`),children:`No Records Found`})]}):u.filter(e=>x(e).toLowerCase().includes(m.toLowerCase())).map(e=>{let t=v.some(t=>t._id===e._id);return(0,Q.jsxs)(`div`,{onClick:()=>b(e),className:Y(`flex items-center justify-between p-4 rounded-lg border transition-all cursor-pointer group`,t?`bg-indigo-500 border-indigo-500 text-z-primary shadow-xl shadow-sm`:a===`dark`?`bg-app/20 border-z-border hover:border-z-border`:`bg-z-panel border-z-border hover:border-z-active-border hover:bg-z-active-bg/10`),children:[(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-semibold`,`text-z-primary`),children:x(e)}),(0,Q.jsxs)(`span`,{className:Y(`text-sm font-bold mt-1`,t?`text-z-primary/60`:`text-z-muted`),children:[`ID: `,e._id.slice(-8)]})]}),t&&(0,Q.jsx)(z,{size:16,strokeWidth:3})]},e._id)})})]}),(0,Q.jsx)(`div`,{className:Y(`p-8 border-t flex justify-end`,a===`dark`?`border-z-border bg-app/20`:`border-z-border bg-[var(--z-bg-input)]/50`),children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(!1),className:Y(`px-8 py-3 rounded-lg text-sm font-semibold shadow-xl transition-all`,a===`dark`?`bg-z-panel/10 text-z-primary hover:bg-z-panel/20`:`bg-z-accent text-z-primary shadow-[var(--z-border)] hover:brightness-110`),children:`Close Registry`})})]})})})]})};function Gt(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Kt(e,t){let n=Gt(e)?{...e}:{};return Gt(e)&&Gt(t)&&Object.entries(t).forEach(([t,r])=>{Gt(r)&&t in e?n[t]=Kt(e[t],r):Object.assign(n,{[t]:r})}),n}function qt(e,t){if(!t.includes(`.`))return e?.[t];let n=t.split(`.`),r=e;for(let e of n){if(!r||typeof r!=`object`)return;r=r[e]}return r}function Jt(e,t){if(!e)return!0;if(typeof e==`function`)try{return e(t)}catch{return!0}if(typeof e==`object`&&e){let n=e,r=n.field;if(!r)return!0;let i=t[r];if(n.equals!==void 0)return i===n.equals;if(n.notEquals!==void 0)return i!==n.notEquals;if(n.contains!==void 0)return Array.isArray(i)&&i.includes(n.contains)}return!0}function Yt(e,t){return e.localized?`${e.name}.${t}`:e.name}function Xt(e){if(e)return{textTransform:e}}var Zt=({field:e,value:t,onChange:n,disabled:r})=>{let{theme:i}=K(),a=e,o=Xt(a.casing);return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`input`,{type:[`date`,`password`,`color`,`email`].includes(a.type)?a.type:`text`,value:t||``,onChange:e=>{let t=e.target.value;a.casing===``?t=t.toUpperCase():a.casing===`lowercase`?t=t.toLowerCase():a.casing===`capitalize`&&(t=t.replace(/\b\w/g,e=>e.toUpperCase())),n(t)},maxLength:a.maxLength,style:o,disabled:r,className:Y(`w-full px-4 py-3 text-sm transition-all outline-none rounded-none-none border`,i===`dark`?`bg-z-base/65 backdrop-blur-md border-z-border text-z-primary placeholder:text-z-secondary focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`:`bg-z-panel/80 backdrop-blur-md border-z-border text-z-primary placeholder:text-z-muted focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`,a.type===`color`&&`h-11 p-1 cursor-pointer`,a.type===`uid`&&`font-mono text-z-active-text`,`disabled:opacity-60 disabled:cursor-not-allowed`),placeholder:`Enter ${a.name}...`}),a.maxLength&&a.type!==`date`&&(0,Q.jsxs)(`span`,{className:`absolute right-3 top-2.5 text-sm font-bold text-z-secondary font-mono pointer-events-none`,children:[(t||``).length,` / `,a.maxLength]})]})},Qt=({field:e,value:t,onChange:n,disabled:r})=>{let{theme:i}=K(),a=e;return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`textarea`,{value:t||``,onChange:e=>{let t=e.target.value;a.casing===``?t=t.toUpperCase():a.casing===`lowercase`?t=t.toLowerCase():a.casing===`capitalize`&&(t=t.replace(/\b\w/g,e=>e.toUpperCase())),n(t)},maxLength:a.maxLength,rows:8,style:Xt(a.casing),disabled:r,className:Y(`w-full px-4 py-3 text-sm transition-all outline-none rounded-none-none border min-h-[140px]`,i===`dark`?`bg-z-base/65 backdrop-blur-md border-z-border text-z-primary placeholder:text-z-secondary focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`:`bg-z-panel/80 backdrop-blur-md border-z-border text-z-primary placeholder:text-z-muted focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`,`disabled:opacity-60 disabled:cursor-not-allowed`),placeholder:`Enter ${a.name}...`}),a.maxLength&&(0,Q.jsxs)(`span`,{className:`absolute bottom-2 right-3 text-sm font-bold text-z-secondary font-mono`,children:[(t||``).length,` / `,a.maxLength]})]})},$t=({field:e,value:t,onChange:n,disabled:r})=>{let{theme:i}=K(),a=e,o=a.hasMany??!1;return o&&Array.isArray(t)&&t.map(String),(0,Q.jsxs)(`select`,{value:o?void 0:t||``,onChange:e=>{n(o?Array.from(e.target.selectedOptions,e=>e.value):e.target.value)},multiple:o,disabled:r,className:Y(`w-full px-4 py-3 text-sm transition-all duration-350 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black`,`backdrop-blur-md`,i===`dark`?`bg-z-base/65 backdrop-blur-md border-z-border text-z-primary focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`:`bg-z-panel/80 backdrop-blur-md border-z-border text-z-primary focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`,o?`rounded-none-none min-h-[120px]`:`rounded-none-none`,`disabled:opacity-60 disabled:cursor-not-allowed`),children:[!a.required&&!o&&(0,Q.jsx)(`option`,{value:``,children:`Select...`}),(a.options||[]).map(e=>{let t=typeof e==`string`?e:e.value||e,n=typeof e==`string`?e:e.label||e,r=String(t);return(0,Q.jsx)(`option`,{value:r,children:String(n)},r)})]})},en=({field:e,value:t,onChange:n,disabled:r})=>(0,Q.jsx)(`div`,{className:`flex items-center h-9`,children:(0,Q.jsx)(`input`,{type:`checkbox`,checked:!!t,onChange:e=>n(e.target.checked),disabled:r,className:`w-4 h-4 rounded-none-none border border-z-border bg-z-input backdrop-blur-md text-z-active-text focus:ring-z-active-border focus:ring-2 disabled:opacity-60 disabled:cursor-not-allowed transition-all`})}),tn=({field:e,value:t,onChange:n,disabled:r})=>(0,Q.jsx)(`input`,{type:`number`,value:t??``,onChange:e=>n(e.target.value===``?null:Number(e.target.value)),disabled:r,className:`w-full bg-z-base/65 backdrop-blur-md border border-z-border rounded-none-none px-4 py-3 text-sm focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border outline-none disabled:opacity-60 disabled:cursor-not-allowed text-z-primary placeholder:text-z-secondary transition-all font-mono`}),nn=({field:e,value:t,onChange:n,disabled:r})=>{let i=e;return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`textarea`,{value:t||``,onChange:e=>n(e.target.value),maxLength:i.maxLength,rows:10,disabled:r,spellCheck:!1,className:Y(`w-full bg-[#0d1117] backdrop-blur-md border border-z-border rounded-none-none px-4 py-3 text-sm font-mono`,`focus:border-z-accent/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black disabled:opacity-60 disabled:cursor-not-allowed`,`text-[#e6edf3] placeholder:text-z-secondary`),placeholder:`Enter ${i.language||`code`}...`}),(0,Q.jsxs)(`div`,{className:`absolute top-2 right-3 flex items-center gap-2`,children:[i.language&&(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-active-text/60 font-mono`,children:i.language}),i.maxLength&&(0,Q.jsxs)(`span`,{className:`text-sm font-bold text-z-secondary font-mono`,children:[(t||``).length,`/`,i.maxLength]})]})]})},rn=({field:e,value:t,onChange:n,disabled:r,renderField:i})=>{let a=e,[o,s]=Z.useState(!a.initCollapsed),c=a.fields||[];return(0,Q.jsxs)(`div`,{className:`border border-z-border rounded-none-none overflow-hidden`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(!o),className:`w-full flex items-center justify-between px-4 py-3 bg-z-hover hover:bg-z-panel/[0.06] transition-colors text-sm font-semibold text-z-primary`,children:(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`transition-transform duration-200 text-z-active-text ${o?`rotate-90`:``}`}),e.label||e.name]})}),o&&(0,Q.jsx)(`div`,{className:`p-4 grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-4 border-t border-z-border`,children:c.map(e=>(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`label`,{className:`text-xs font-semibold text-z-secondary capitalize`,children:[e.label||e.name,e.required&&(0,Q.jsx)(`span`,{className:`text-danger ml-1`,children:`*`})]}),i(e,t?.[e.name],r=>n({...t||{},[e.name]:r}))]},e.name))})]})},an=({field:e,value:t,onChange:n,disabled:r,renderField:i})=>{let a=t&&typeof t==`object`?t:{},o=e,s=o.fields||[];return(0,Q.jsxs)(`div`,{className:Y(`border border-z-border bg-z-panel backdrop-blur-md p-4 space-y-4`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 pb-3 border-b border-z-border`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-active-text`,children:e.label||e.name}),o.admin?.description&&(0,Q.jsx)(`span`,{className:`text-sm text-z-secondary italic`,children:o.admin.description})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-x-6 gap-y-5 pt-2`,children:s.map(e=>(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`label`,{className:`text-sm font-bold text-z-muted`,children:[e.label||e.name,e.required&&(0,Q.jsx)(`span`,{className:`text-danger ml-1`,children:`*`})]}),i(e,a[e.name],t=>n({...a,[e.name]:t}),r)]},e.name))})]})};function on(e){if(e==null||e===``)return null;let t=typeof e==`string`?e:JSON.stringify(e);try{return JSON.parse(t),!0}catch{return!1}}var sn=({value:e,onChange:t,disabled:n,rows:r=8})=>{let[i,a]=(0,Z.useState)(!1),o=on(e),s=typeof e==`string`?e:e==null?``:JSON.stringify(e,null,2),c=(0,Z.useCallback)(e=>{let n=e.target.value;t(n)},[t]),l=(0,Z.useCallback)(()=>{try{let n=JSON.parse(typeof e==`string`?e:JSON.stringify(e));t(JSON.stringify(n,null,2))}catch{}},[e,t]);return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`div`,{className:`absolute left-3 top-2.5 text-z-secondary pointer-events-none`,children:(0,Q.jsx)(se,{size:14})}),(0,Q.jsx)(`textarea`,{value:s,onChange:c,onFocus:()=>a(!0),onBlur:()=>a(!1),rows:r,disabled:n,spellCheck:!1,className:Y(`w-full bg-[#0d1117] backdrop-blur-md border rounded-none-none px-9 py-3 text-sm font-mono resize-y outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black transition-colors`,`text-[#e6edf3] placeholder:text-z-secondary disabled:opacity-60 disabled:cursor-not-allowed`,i?`border-z-accent/50`:o===!1?`border-red-500/40`:`border-z-border`),placeholder:`{"key": "value"}`})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:Y(`inline-block w-1.5 h-1.5 rounded-none-full`,o===!0?`bg-z-accent shadow-sm`:o===!1?`bg-red-500 shadow-[0_0_6px_#ef4444]`:`bg-z-accent`)}),(0,Q.jsx)(`span`,{className:Y(`text-sm font-bold `,o===!0?`text-z-active-text`:o===!1?`text-red-400`:`text-z-secondary`),children:o===!0?`Valid JSON`:o===!1?`Invalid JSON`:`JSON`})]}),o===!0&&(0,Q.jsx)(`button`,{type:`button`,onClick:l,className:`text-sm font-bold text-z-secondary hover:text-z-active-text transition-colors`,children:`Format`})]})]})};function cn(e,t){if(!e)return``;try{let n=new Date(e);return isNaN(n.getTime())?typeof e==`string`?e:``:t===`datetime`?n.toISOString().slice(0,16):t===`time`?n.toISOString().slice(11,16):n.toISOString().slice(0,10)}catch{return typeof e==`string`?e:``}}function ln(e,t){if(!e)return``;if(t===`time`)return e;try{return new Date(e).toISOString()}catch{return e}}var un=({value:e,onChange:t,disabled:n,format:r=`date`})=>{let{theme:i}=K(),a=r===`datetime`?`datetime-local`:r===`time`?`time`:`date`;return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`div`,{className:Y(`absolute left-3 top-1/2 -translate-y-1/2 pointer-events-none`,i===`dark`?`text-z-primary/60`:`text-z-secondary`),children:(0,Q.jsx)(Ye,{size:14})}),(0,Q.jsx)(`input`,{type:a,value:cn(e,r),onChange:e=>t(ln(e.target.value,r)),disabled:n,style:{colorScheme:i===`dark`?`dark`:`light`},className:Y(`w-full pl-9 pr-4 py-3 text-sm transition-all outline-none rounded-none-none border`,i===`dark`?`bg-z-input backdrop-blur-md border-z-border text-z-primary placeholder:text-z-secondary focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`:`bg-z-panel/80 backdrop-blur-md border-z-border text-z-primary placeholder:text-z-muted focus:border-z-accent/50 focus-visible:ring-2 focus-visible:ring-z-active-border`,`disabled:opacity-60 disabled:cursor-not-allowed font-mono`)})]})};function dn(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``)}var fn=({value:e,onChange:t,disabled:n,sourceField:r,formValues:i})=>{let a=(0,Z.useCallback)(()=>{if(r&&i){let e=i[r];typeof e==`string`&&e.trim()&&t(dn(e))}},[r,i,t]);return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`div`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-z-secondary pointer-events-none`,children:(0,Q.jsx)(Se,{size:14})}),(0,Q.jsx)(`input`,{type:`text`,value:e||``,onChange:e=>t(e.target.value),disabled:n,className:Y(`w-full bg-z-panel/[0.05] backdrop-blur-md border border-z-border rounded-none-none pl-9 pr-10 py-3 text-sm`,`focus:border-z-accent/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black disabled:opacity-60 disabled:cursor-not-allowed`,`text-z-active-text font-mono placeholder:text-z-secondary`),placeholder:`auto-generated-slug`}),r&&(0,Q.jsx)(`button`,{type:`button`,onClick:a,disabled:n,title:`Generate from ${r}`,className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-z-secondary hover:text-z-active-text disabled:opacity-30 transition-colors`,children:(0,Q.jsx)(v,{size:13})})]})};function pn(){return Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}var mn=({value:e,onChange:t,disabled:n})=>{let r=(0,Z.useCallback)(()=>{t(pn())},[t]);return(0,Q.jsxs)(`div`,{className:`relative w-full`,children:[(0,Q.jsx)(`div`,{className:`absolute left-3 top-1/2 -translate-y-1/2 text-z-secondary pointer-events-none`,children:(0,Q.jsx)(O,{size:14})}),(0,Q.jsx)(`input`,{type:`text`,value:e||``,onChange:e=>t(e.target.value),disabled:n,readOnly:!0,className:Y(`w-full bg-z-hover backdrop-blur-md border border-z-border rounded-none-none pl-9 pr-10 py-2 text-sm`,`focus:border-z-accent/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black disabled:opacity-60 disabled:cursor-not-allowed`,`text-z-active-text/80 font-mono`),placeholder:`auto-generated-uid`}),(0,Q.jsx)(`button`,{type:`button`,onClick:r,disabled:n,title:`Regenerate UID`,className:`absolute right-2 top-1/2 -translate-y-1/2 p-1 text-z-secondary hover:text-z-active-text disabled:opacity-30 transition-colors`,children:(0,Q.jsx)(v,{size:13})})]})},hn=({field:e,value:t,onChange:n,disabled:r,renderField:i})=>{let a=e.tabs||[],[o,s]=(0,Z.useState)(0),c=t&&typeof t==`object`?t:{};if(a.length===0)return null;let l=a[o]?.fields||[];return(0,Q.jsxs)(`div`,{className:`border border-z-border bg-z-panel backdrop-blur-md`,children:[(0,Q.jsx)(`div`,{className:`flex border-b border-z-border`,children:a.map((e,t)=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:Y(`px-4 py-2.5 text-sm font-semibold transition-colors`,o===t?`text-z-active-text border-b-2 border-z-accent bg-z-hover`:`text-z-secondary hover:text-z-secondary`),children:e.label||e.name},e.name))}),l.length>0&&(0,Q.jsx)(`div`,{className:`p-4 space-y-3`,children:l.map(e=>(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`label`,{className:`text-sm font-bold text-z-muted`,children:[e.label||e.name,e.required&&(0,Q.jsx)(`span`,{className:`text-danger ml-1`,children:`*`})]}),i(e,c[e.name],t=>n({...c,[e.name]:t}),r)]},e.name))})]})},gn=({field:e,value:t,onChange:n,disabled:r})=>{let i=Array.isArray(t)&&t.length===2?t:[0,0];return(0,Q.jsxs)(`div`,{className:`flex gap-3`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-sm font-bold text-z-secondary`,children:`Longitude`}),(0,Q.jsx)(`input`,{type:`number`,value:i[0],onChange:e=>n([Number(e.target.value),i[1]]),step:`any`,disabled:r,className:`w-full bg-z-panel/[0.05] backdrop-blur-md border border-z-border rounded-none-none px-3 py-3 text-sm focus:border-z-accent/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black disabled:opacity-60 disabled:cursor-not-allowed text-z-primary placeholder:text-z-secondary`,placeholder:`0.0`})]}),(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-sm font-bold text-z-secondary`,children:`Latitude`}),(0,Q.jsx)(`input`,{type:`number`,value:i[1],onChange:e=>n([i[0],Number(e.target.value)]),step:`any`,disabled:r,className:`w-full bg-z-panel/[0.05] backdrop-blur-md border border-z-border rounded-none-none px-3 py-3 text-sm focus:border-z-accent/50 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black disabled:opacity-60 disabled:cursor-not-allowed text-z-primary placeholder:text-z-secondary`,placeholder:`0.0`})]})]})},_n=({field:e,value:t,onChange:n,renderField:r})=>(0,Q.jsx)(`div`,{className:`flex gap-4 items-end`,children:(e.fields||[]).map(e=>(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1.5`,children:[(0,Q.jsxs)(`label`,{className:`text-xs font-semibold text-z-secondary capitalize`,children:[e.label||e.name,e.required&&(0,Q.jsx)(`span`,{className:`text-danger ml-1`,children:`*`})]}),r(e,t?.[e.name],r=>n({...t||{},[e.name]:r}))]},e.name))}),vn=({field:e})=>(0,Q.jsxs)(`div`,{className:`w-full bg-z-hover border border-z-border rounded-none-none px-4 py-3 text-sm text-z-muted italic flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-z-active-text`,children:`⧉`}),`Joined data from`,` `,(0,Q.jsx)(`span`,{className:`font-mono text-z-active-text text-xs`,children:e.collection}),` — read-only`]}),yn=({field:e,value:t,onChange:n,disabled:r})=>{let i=e;return(0,Q.jsx)(`div`,{className:Y(`flex gap-4`,i.layout===`horizontal`?`flex-row flex-wrap`:`flex-col gap-2`),children:(i.options||[]).map((i,a)=>{let o=typeof i==`string`?i:i.value||``,s=typeof i==`string`?i:i.label||o;return(0,Q.jsxs)(`label`,{className:`flex items-center gap-2.5 cursor-pointer group`,children:[(0,Q.jsx)(`input`,{type:`radio`,name:e.name,value:String(o),checked:t===o,onChange:e=>n(e.target.value),disabled:r,className:`w-4 h-4 border border-z-border text-z-active-text focus:ring-z-active-border disabled:opacity-60 accent-z-accent`}),(0,Q.jsx)(`span`,{className:`text-sm text-z-secondary group-hover:text-z-primary transition-colors`,children:String(s)})]},`${String(o)}-${a}`)})})},bn=e=>e.replace(/^root:/,``).replace(/([A-Z])/g,` $1`).replace(/^./,e=>e.toUpperCase()),xn={Star:T,Grid:f,BarChart4:ee,MessageSquare:pe,Mail:me,CreditCard:m,Zap:Je,FileText:w,Layout:f,Users:be,AlertCircle:ie,Code:se,Table:r,Puzzle:oe},Sn=e=>{let t=pt.find(t=>t.type===e),n=t?xn[t.iconName]:null;return n?Z.createElement(n,{size:16}):e===`plugin-node`?(0,Q.jsx)(oe,{size:16}):(0,Q.jsx)(_e,{size:16})},Cn={Layout:`from-z-accent to-transparent`,Content:`from-z-accent to-transparent`,Commerce:`from-z-accent to-transparent`,Media:`from-rose-900/60 to-pink-900/40`,Social:`from-amber-900/60 to-orange-900/40`,General:`from-[#1a1a2e]/80 to-[#16213e]/60`},wn=pt.map(e=>({slug:e.type,labels:{singular:e.title,plural:e.title+`s`},fields:e.fields.map(t=>({name:t.name,label:t.label||bn(t.name),type:t.type,required:t.required,defaultValue:e.defaultContent[t.name],options:t.options})),admin:{description:e.description,category:e.category}}));function Tn({block:e,index:t,total:n,blockDef:r,isExpanded:i,disabled:a,onToggle:s,onRemove:c,onDuplicate:l,onMoveUp:u,onMoveDown:d,renderField:f,onUpdate:p}){let m=(()=>{for(let t of[`headline`,`title`,`name`,`content`,`subheadline`])if(e[t]&&typeof e[t]==`string`)return e[t];return null})(),h=Cn[r?.admin?.category||``]??Cn.General;return(0,Q.jsxs)(V,{value:e,drag:a?!1:`y`,whileDrag:{scale:1.01,zIndex:50,boxShadow:`0 20px 40px rgba(0,0,0,0.4)`},className:Y(`group relative bg-app border rounded-none-none overflow-visible shadow-sm transition-colors duration-150`,i?`border-accent/60 shadow-sm`:`border-border hover:border-z-border`),children:[(0,Q.jsx)(`div`,{className:Y(`absolute -left-3.5 top-1/2 -translate-y-1/2 w-5 h-5 rounded-none-full flex items-center justify-center text-sm font-semibold border z-10 transition-all`,i?`bg-accent text-z-primary border-accent shadow-sm`:`bg-app text-z-muted border-border group-hover:border-accent/40 group-hover:text-accent`),children:t+1}),i&&(0,Q.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-[3px] bg-accent rounded-none-l`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-4 py-3 cursor-pointer`,onClick:s,children:[!a&&(0,Q.jsx)(`div`,{className:`p-1 text-z-muted/30 hover:text-z-muted cursor-grab active:cursor-grabbing flex-shrink-0`,onPointerDown:e=>e.stopPropagation(),children:(0,Q.jsx)(Ee,{size:13})}),(0,Q.jsx)(`div`,{className:Y(`w-7 h-7 rounded-none flex items-center justify-center flex-shrink-0 bg-gradient-to-br text-z-primary/70`,h),children:Sn(e.blockType)}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-primary truncate`,children:m||r?.labels?.singular||e.blockType}),(0,Q.jsx)(`span`,{className:`flex-shrink-0 px-1.5 py-px text-sm font-semibold text-z-muted bg-z-panel/[0.05] border border-border rounded-none`,children:e.blockType})]}),r?.admin?.description&&(0,Q.jsx)(`p`,{className:`text-sm text-z-muted/70 truncate mt-0.5`,children:r.admin.description})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0`,onClick:e=>e.stopPropagation(),children:[!a&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,onClick:u,disabled:t===0,title:`Move Up`,className:`p-1.5 text-z-muted hover:text-z-primary disabled:opacity-20 disabled:cursor-not-allowed transition-colors`,children:(0,Q.jsx)(ve,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:d,disabled:t===n-1,title:`Move Down`,className:`p-1.5 text-z-muted hover:text-z-primary disabled:opacity-20 disabled:cursor-not-allowed transition-colors`,children:(0,Q.jsx)(Qe,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:l,title:`Duplicate`,className:`p-1.5 text-z-muted hover:text-accent transition-colors`,children:(0,Q.jsx)(b,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:c,title:`Remove`,className:`p-1.5 text-z-muted hover:text-danger transition-colors`,children:(0,Q.jsx)(o,{size:11})})]}),(0,Q.jsx)(G.div,{animate:{rotate:i?180:0},transition:{duration:.2},className:`p-1.5 text-z-muted/50 ml-0.5`,children:(0,Q.jsx)(We,{size:13})})]})]}),(0,Q.jsx)(H,{initial:!1,children:i&&(0,Q.jsx)(G.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:[.4,0,.2,1]},className:`overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`px-5 pb-6 pt-4 border-t border-border bg-z-panel/[0.05]/40`,children:r?(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:r.fields.map(t=>(0,Q.jsxs)(`div`,{className:Y(`flex flex-col gap-1.5`,[`richtext`,`textarea`,`blocks`,`array`,`media`,`code`,`collapsible`].includes(t.type)&&`col-span-2`),children:[(0,Q.jsxs)(`label`,{className:`text-sm font-semibold text-z-muted flex items-center gap-1`,children:[t.label||t.name,t.required&&(0,Q.jsx)(`span`,{className:`text-danger`,children:`*`})]}),f?f(t,e[t.name],e=>p({[t.name]:e})):(0,Q.jsx)(`input`,{type:`text`,value:e[t.name]||``,onChange:e=>p({[t.name]:e.target.value}),placeholder:`Enter ${t.label||t.name}...`,className:`w-full bg-app border border-border px-3 py-2 text-sm focus:border-accent focus:ring-2 focus:ring-accent/10 outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black transition-all rounded-none-none`})]},t.name))}):(0,Q.jsxs)(`p`,{className:`text-xs text-z-muted text-center py-4 italic`,children:[`Unknown block type: "`,e.blockType,`"`]})})})})]})}var En=({value:e,onChange:t,availableBlocks:n,renderField:r,disabled:i=!1})=>{let o=ct(),{openComponentPicker:s}=dt(),[c,l]=(0,Z.useState)({}),[u,d]=(0,Z.useState)(!1),f=`/preview`,p=n||[],m=p.length>0?p:o.length>0?o:wn,h=e||[],g=(0,Z.useCallback)(e=>{l(t=>({...t,[e]:!t[e]}))},[]),_=(0,Z.useCallback)(e=>{let n=m.find(t=>t.slug===e),r=`block_`+at(),i={blockType:e,_id:r,id:r};n?.fields.forEach(e=>{e.defaultValue!==void 0&&(i[e.name]=e.defaultValue)}),t([...h,i]),l(e=>({...e,[r]:!0}))},[h,m,t]),v=(0,Z.useCallback)(()=>{s(e=>_(e))},[s,_]),y=(0,Z.useCallback)(e=>{t(h.filter((t,n)=>n!==e))},[h,t]),b=(0,Z.useCallback)(e=>{let n=[...h],r=`block_`+at(),i={...h[e],_id:r,id:r};n.splice(e+1,0,i),t(n),l(e=>({...e,[r]:!0}))},[h,t]),x=(0,Z.useCallback)((e,n)=>{let r=[...h],i=n===`up`?e-1:e+1;i<0||i>=r.length||([r[e],r[i]]=[r[i],r[e]],t(r))},[h,t]),S=(0,Z.useCallback)((e,n)=>{let r=[...h];r[e]={...r[e],...n},t(r)},[h,t]),C=(0,Z.useCallback)(()=>{let e={};h.forEach((t,n)=>{let r=t._id||String(n);e[r]=!0}),l(e)},[h]),w=(0,Z.useCallback)(()=>{l({})},[]);return(0,Q.jsxs)(`div`,{className:Y(`select-none`,u?`grid grid-cols-2 gap-8`:`pl-5`),children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 w-full`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Q.jsx)(N,{size:16,className:`text-accent`}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-primary`,children:`Page Components`}),h.length>0&&(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 text-sm font-semibold bg-accent/15 text-accent border border-accent/25 rounded-none-full`,children:h.length})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>d(!u),className:Y(`flex items-center gap-1.5 px-3 py-1.5 text-sm font-semibold transition-all rounded-none-none border`,u?`bg-z-active-bg text-z-active-text border-z-active-border`:`bg-z-panel text-z-muted border-z-border hover:text-z-primary`),children:[u?(0,Q.jsx)(re,{size:12}):(0,Q.jsx)(a,{size:12}),u?`Close Preview`:`Live Preview`]}),h.length>0&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 border border-z-border bg-z-panel p-0.5 rounded-none-none mr-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:C,className:`px-2.5 py-1 text-sm font-semibold text-z-muted hover:text-z-primary transition-all hover:bg-z-panel/[0.05]`,children:`Expand All`}),(0,Q.jsx)(`div`,{className:`w-px h-3 bg-z-panel/10`}),(0,Q.jsx)(`button`,{type:`button`,onClick:w,className:`px-2.5 py-1 text-sm font-semibold text-z-muted hover:text-z-primary transition-all hover:bg-z-panel/[0.05]`,children:`Collapse All`})]}),!i&&(0,Q.jsxs)(`button`,{type:`button`,onClick:v,className:`flex items-center gap-1.5 px-3 py-1.5 bg-accent text-z-primary text-sm font-semibold hover:bg-accent/90 transition-all shadow-sm shadow-accent/20 rounded-none-none`,children:[(0,Q.jsx)(M,{size:11}),` Add Component`]})]})]}),h.length===0&&(0,Q.jsxs)(G.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},className:`border border-dashed border-border p-10 flex flex-col items-center gap-4 text-center bg-z-panel/[0.05]/20 rounded-none-none`,children:[(0,Q.jsx)(`div`,{className:`w-12 h-12 rounded-none-full bg-accent/10 border border-accent/20 flex items-center justify-center`,children:(0,Q.jsx)(N,{size:20,className:`text-accent/50`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-sm font-bold text-z-primary mb-1`,children:`No components yet`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-muted max-w-xs leading-relaxed`,children:`Build your page by stacking components — hero sections, feature grids, pricing tables and more.`})]}),!i&&(0,Q.jsxs)(`button`,{type:`button`,onClick:v,className:`flex items-center gap-2 px-4 py-2 bg-accent text-z-primary text-sm font-semibold hover:bg-accent/90 transition-all shadow-sm shadow-accent/20 mt-1 rounded-none-none`,children:[(0,Q.jsx)(M,{size:12}),` Add Your First Component`]})]}),(0,Q.jsx)(qe,{axis:`y`,values:h,onReorder:t,className:`space-y-3`,children:(0,Q.jsx)(H,{initial:!1,children:h.map((e,t)=>{let n=m.find(t=>t.slug===e.blockType),a=e._id||String(t);return(0,Q.jsx)(G.div,{initial:{opacity:0,x:-8},animate:{opacity:1,x:0},exit:{opacity:0,x:-8,height:0,marginTop:0},transition:{duration:.15},children:(0,Q.jsx)(Tn,{block:e,index:t,total:h.length,blockDef:n,isExpanded:!!c[a],disabled:i,onToggle:()=>g(a),onRemove:()=>y(t),onDuplicate:()=>b(t),onMoveUp:()=>x(t,`up`),onMoveDown:()=>x(t,`down`),renderField:r,onUpdate:e=>S(t,e)})},`block-${a}`)})})}),h.length>0&&!i&&(0,Q.jsxs)(G.button,{type:`button`,initial:{opacity:0},animate:{opacity:1},onClick:v,className:`flex items-center justify-center gap-2 w-full py-2.5 border border-dashed border-border text-z-muted/60 text-sm font-semibold hover:border-accent/50 hover:text-accent hover:bg-accent/5 transition-all rounded-none-none`,children:[(0,Q.jsx)(M,{size:11}),` Add Component`]})]}),u&&(0,Q.jsxs)(`div`,{className:`w-full h-full min-h-[700px] border border-z-border rounded-none-none overflow-hidden sticky top-4 bg-[#0B0F19] shadow-2xl flex flex-col`,children:[(0,Q.jsxs)(`div`,{className:`px-4 py-2 border-b border-z-border flex items-center justify-between shrink-0`,children:[(0,Q.jsxs)(`span`,{className:`text-sm font-semibold text-z-active-text italic flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`w-2 h-2 rounded-none-full bg-z-accent animate-pulse shadow-sm`}),`Live Preview Connected`]}),(0,Q.jsx)(`span`,{className:`text-sm font-mono text-z-secondary`,children:f})]}),(0,Q.jsx)(`iframe`,{src:f,className:`w-full flex-1 border-0 bg-z-panel`,title:`Live Preview`})]})]})},Dn=({value:e=[],onChange:t,fields:n,label:r,renderField:i,disabled:a=!1})=>{let[s,c]=(0,Z.useState)({}),l=Z.useMemo(()=>e.map((e,t)=>({...e,_id:e._id||`array_item_${at()}_${t}`})),[e]),u=e=>{c(t=>({...t,[e]:!t[e]}))},d=()=>{let e={};l.forEach(t=>{e[t._id]=!0}),c(e)},f=()=>{c({})},p=(0,Z.useCallback)(()=>{let r=`array_item_${at()}`,i={_id:r,id:r};n.forEach(e=>{e.defaultValue!==void 0&&(i[e.name]=e.defaultValue)}),t([...e,i]),c(e=>({...e,[r]:!0}))},[e,n,t]),m=(0,Z.useCallback)(n=>{let r=[...e];r.splice(n,1),t(r)},[e,t]),h=(0,Z.useCallback)(n=>{let r=[...e],i=`array_item_${at()}`,a={...e[n],_id:i,id:i};r.splice(n+1,0,a),t(r),c(e=>({...e,[i]:!0}))},[e,t]),g=(0,Z.useCallback)((n,r)=>{if(r===`up`&&n===0||r===`down`&&n===e.length-1)return;let i=[...e],a=r===`up`?n-1:n+1,o=i[n];i[n]=i[a],i[a]=o,t(i)},[e,t]),_=(0,Z.useCallback)((n,r)=>{let i=[...e];i[n]={...i[n],...r},t(i)},[e,t]);return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 pl-5 select-none`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Q.jsx)(N,{size:16,strokeWidth:2,className:`text-z-secondary `}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-primary`,children:r}),(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 text-sm font-semibold bg-z-border/15 text-z-secondary border border-z-border/25 rounded-none-none`,children:e.length})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.length>0&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 border border-z-border bg-z-panel p-0.5 rounded-none-none mr-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:d,className:`px-2.5 py-1 text-sm font-semibold text-z-muted hover:text-z-primary transition-all hover:bg-z-panel/[0.05]`,children:`Expand All`}),(0,Q.jsx)(`div`,{className:`w-px h-3 bg-z-panel/10`}),(0,Q.jsx)(`button`,{type:`button`,onClick:f,className:`px-2.5 py-1 text-sm font-semibold text-z-muted hover:text-z-primary transition-all hover:bg-z-panel/[0.05]`,children:`Collapse All`})]}),!a&&(0,Q.jsxs)(`button`,{type:`button`,onClick:p,className:`flex items-center gap-1.5 px-3 py-1.5 bg-z-accent text-z-primary text-sm font-semibold hover:bg-z-border transition-all shadow-sm shadow-[var(--z-border)] rounded-none-none`,children:[(0,Q.jsx)(M,{size:11,strokeWidth:2}),` Add Component`]})]})]}),(0,Q.jsx)(qe,{axis:`y`,values:l,onReorder:e=>t(e.map(e=>{let{_id:t,...n}=e;return n})),className:`space-y-3`,children:(0,Q.jsx)(H,{initial:!1,children:l.map((e,t)=>{let r=e._id,c=!!s[r],d=(()=>{for(let t of n)if([`text`,`string`].includes(t.type)&&typeof e[t.name]==`string`)return e[t.name];return`Component ${t+1}`})();return(0,Q.jsx)(G.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:`auto`},exit:{opacity:0,height:0},transition:{duration:.2},children:(0,Q.jsxs)(V,{value:e,drag:a?!1:`y`,whileDrag:{scale:1.01,zIndex:50,boxShadow:`0 20px 40px rgba(0,0,0,0.4)`},className:Y(`group relative bg-app border rounded-none-none overflow-visible shadow-sm transition-colors duration-150`,c?`border-z-border/60 shadow-sm`:`border-border hover:border-z-border`),children:[(0,Q.jsx)(`div`,{className:Y(`absolute -left-3.5 top-1/2 -translate-y-1/2 w-5 h-5 rounded-none-none flex items-center justify-center text-sm font-semibold border z-10 transition-all`,c?`bg-z-border text-z-primary border-z-border shadow-sm`:`bg-app text-z-muted border-border group-hover:border-z-border/40 group-hover:text-z-secondary `),children:t+1}),c&&(0,Q.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 w-[3px] bg-z-border rounded-none-l`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-4 py-3 cursor-pointer`,onClick:()=>u(r),children:[!a&&(0,Q.jsx)(`div`,{className:`p-1 text-z-muted/30 hover:text-z-muted cursor-grab active:cursor-grabbing flex-shrink-0`,onPointerDown:e=>e.stopPropagation(),children:(0,Q.jsx)(Ee,{size:13})}),(0,Q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-primary truncate`,children:d})})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0`,onClick:e=>e.stopPropagation(),children:[!a&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>g(t,`up`),disabled:t===0,title:`Move Up`,className:`p-1.5 text-z-muted hover:text-z-primary disabled:opacity-20 disabled:cursor-not-allowed transition-colors`,children:(0,Q.jsx)(ve,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>g(t,`down`),disabled:t===l.length-1,title:`Move Down`,className:`p-1.5 text-z-muted hover:text-z-primary disabled:opacity-20 disabled:cursor-not-allowed transition-colors`,children:(0,Q.jsx)(Qe,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>h(t),title:`Duplicate`,className:`p-1.5 text-z-muted hover:text-z-secondary transition-colors`,children:(0,Q.jsx)(b,{size:11})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>m(t),title:`Remove`,className:`p-1.5 text-z-muted hover:text-danger transition-colors`,children:(0,Q.jsx)(o,{size:11})})]}),(0,Q.jsx)(G.div,{animate:{rotate:c?180:0},transition:{duration:.2},className:`p-1.5 text-z-muted/50 ml-0.5`,children:(0,Q.jsx)(We,{size:13})})]})]}),(0,Q.jsx)(H,{initial:!1,children:c&&(0,Q.jsx)(G.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:[.4,0,.2,1]},className:`overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`px-5 pb-6 pt-4 border-t border-border bg-z-panel/[0.05]/40`,children:(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:n.map(n=>(0,Q.jsxs)(`div`,{className:Y(`flex flex-col gap-1.5`,[`richtext`,`textarea`,`blocks`,`array`,`media`,`code`,`collapsible`].includes(n.type)&&`col-span-2`),children:[(0,Q.jsxs)(`label`,{className:`text-sm font-semibold text-z-muted flex items-center gap-1`,children:[n.label||n.name,n.required&&(0,Q.jsx)(`span`,{className:`text-danger`,children:`*`})]}),i(n,e[n.name],e=>_(t,{[n.name]:e}))]},n.name))})})})})]})},r)})})}),!a&&(0,Q.jsxs)(G.button,{layout:!0,type:`button`,onClick:p,className:`flex items-center justify-center gap-2 w-full py-2.5 border border-dashed border-border text-z-muted/60 text-sm font-semibold hover:border-z-border/50 hover:text-z-secondary hover:bg-z-hover transition-all rounded-none-none`,children:[(0,Q.jsx)(M,{size:11,strokeWidth:2}),` Add `,r]})]})},On=({fields:e,initialData:t,onSubmit:n,onValuesChange:r,isSubmitting:i=!1,activeLocale:a,readOnlyLocale:o,hideSubmitButton:s=!1})=>{let{user:c}=ht(W(e=>({user:e.user}))),l=a||`en`,u=!!o,{handleSubmit:d,control:f,reset:p,watch:m,formState:{errors:h}}=He({defaultValues:t||{}});Z.useEffect(()=>{if(r){let e=m(e=>{r(e)});return()=>e.unsubscribe()}},[m,r]);let g=m(),_=Z.useRef(t);Z.useEffect(()=>{t&&t!==_.current&&(_.current=t,p(t))},[t,p]);let v=(e,t,n,r=!1)=>{if(e.type===`ui`){let i=e.admin?.components?.Field;return i?(0,Q.jsx)(i,{field:e,value:t,onChange:n,disabled:r}):null}return e.type===`collapsible`?(0,Q.jsx)(rn,{field:e,value:t,onChange:n,disabled:r,renderField:v}):e.type===`group`?(0,Q.jsx)(an,{field:e,value:t,onChange:n,disabled:r,renderField:v}):e.type===`tabs`?(0,Q.jsx)(hn,{field:e,value:t,onChange:n,disabled:r,renderField:v}):e.type===`row`?(0,Q.jsx)(_n,{field:e,value:t,onChange:n,disabled:r,renderField:v}):e.type===`richtext`||e.type===`lexical`?(0,Q.jsx)(Qt,{field:e,value:t,onChange:n,disabled:r}):e.type===`media`?(0,Q.jsx)(Ut,{value:t,onChange:n,hasMany:e.hasMany,disabled:r,focalPoint:e.admin?.focalPoint??!0}):e.type===`relation`||e.type===`relationship`?(0,Q.jsx)(Wt,{value:t,onChange:n,relationTo:e.relationTo,hasMany:e.hasMany,disabled:r}):e.type===`blocks`||e.type===`dz`?(0,Q.jsx)(En,{value:t,onChange:n,availableBlocks:e.blocks||[],renderField:(e,t,n)=>v(e,t,n,r),disabled:r}):e.type===`array`?(0,Q.jsx)(Dn,{value:t,onChange:n,fields:e.fields||[],label:e.label||e.name,renderField:(e,t,n)=>v(e,t,n,r),disabled:r}):e.type===`join`?(0,Q.jsx)(vn,{field:e}):e.type===`point`?(0,Q.jsx)(gn,{field:e,value:t,onChange:n,disabled:r}):e.type===`select`?(0,Q.jsx)($t,{field:e,value:t,onChange:n,disabled:r}):e.type===`boolean`||e.type===`checkbox`?(0,Q.jsx)(en,{field:e,value:t,onChange:n,disabled:r}):e.type===`number`?(0,Q.jsx)(tn,{field:e,value:t,onChange:n,disabled:r}):e.type===`textarea`?(0,Q.jsx)(Qt,{field:e,value:t,onChange:n,disabled:r}):e.type===`code`?(0,Q.jsx)(nn,{field:e,value:t,onChange:n,disabled:r}):e.type===`radio`?(0,Q.jsx)(yn,{field:e,value:t,onChange:n,disabled:r}):e.type===`json`?(0,Q.jsx)(sn,{value:t,onChange:n,disabled:r}):e.type===`date`?(0,Q.jsx)(un,{value:t,onChange:n,disabled:r,format:e.dateFormat||`date`}):e.type===`slug`?(0,Q.jsx)(fn,{value:t,onChange:n,disabled:r,sourceField:e.sourceField||`title`,formValues:g}):e.type===`uid`?(0,Q.jsx)(mn,{value:t,onChange:n,disabled:r}):(0,Q.jsx)(Zt,{field:e,value:t,onChange:n,disabled:r})},y=async e=>{n&&await n(Kt(t||{},e))},b=()=>(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-6`,children:e.map(e=>{if(e.name===`_status`||e.name===`id`)return null;let n=e.condition||e.admin?.condition;if(n&&!Jt(n,g))return null;let r=[`richtext`,`blocks`,`array`,`code`,`collapsible`,`group`,`tabs`,`json`].includes(e.type),i=Yt(e,l),a=u;if(c?.role!==`admin`){let t=e.admin?.readAccess;if(t&&t.length>0&&!t.includes(c.role))return null;let n=e.admin?.writeAccess;n&&n.length>0&&!n.includes(c.role)&&(a=!0)}return(0,Q.jsxs)(`div`,{"data-field":i,className:`space-y-2 ${r?`col-span-2`:``}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`label`,{className:`text-sm font-semibold text-z-secondary flex items-center gap-2`,children:[e.label||e.name.replace(/([A-Z])/g,` $1`),e.required&&(0,Q.jsx)(`span`,{className:`text-rose-500`,children:`*`}),e.localized&&(0,Q.jsx)(`span`,{className:`px-1.5 py-0.5 text-sm font-semibold text-z-secondary bg-z-panel border border-z-border/20 rounded-none-none`,children:a&&o||l}),a&&!u&&(0,Q.jsx)(Re,{size:10,className:`text-z-secondary ml-1`})]}),e.admin?.description&&(0,Q.jsx)(`span`,{className:`text-sm text-z-muted`,children:e.admin.description})]}),a?v(e,e.localized?t?.[e.name]?.[o||l]??``:t?.[e.name]??``,()=>{},!0):(0,Q.jsx)(je,{name:i,control:f,render:({field:{onChange:t,value:n}})=>(0,Q.jsx)(Q.Fragment,{children:v(e,n,t)})}),!a&&!!qt(h,i)&&(0,Q.jsx)(`p`,{className:`text-xs text-danger mt-1 font-medium`,children:qt(h,i)?.message||`Required field`})]},e.name)})});return u?(0,Q.jsx)(`div`,{className:`space-y-8`,children:b()}):(0,Q.jsxs)(`form`,{onSubmit:n?d(y):void 0,className:`space-y-8`,children:[b(),!s&&(0,Q.jsxs)(`div`,{className:`mt-10 pt-6 border-t border-z-border shadow-sm flex items-center justify-between`,children:[(0,Q.jsxs)(`p`,{className:`text-xs text-z-muted`,children:[`Fields marked with `,(0,Q.jsx)(`span`,{className:`text-danger`,children:`*`}),` are required.`]}),(0,Q.jsx)(`div`,{className:`flex gap-3`,children:(0,Q.jsx)(`button`,{type:`submit`,disabled:i,className:`btn btn-primary min-w-[140px] h-11`,children:i?(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Q.jsx)(C,{size:16,className:`animate-spin`}),`Saving...`]}):`Save Changes`})})]})]})},kn=({isOpen:e,onClose:t,collectionSlug:n,documentId:r,onSaved:i})=>{let{theme:a}=K(),[o,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!0),[f,p]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{!e||!r||(async()=>{d(!0);try{l(((await q.get(`/health`)).data.data?.collections||[]).find(e=>e.slug===n)),s((await q.get(`/${n}/${r}`)).data.data)}catch{U.error(`Failed to load document`)}finally{d(!1)}})()},[e,r,n]),e?(0,Q.jsx)(H,{children:(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[1100] flex items-center justify-center p-4 md:p-8 bg-app/60 backdrop-blur-md`,children:(0,Q.jsxs)(G.div,{initial:{opacity:0,y:10,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.98},className:Y(`w-full max-w-4xl border rounded-none-none overflow-hidden shadow-2xl flex flex-col h-[85vh]`,a===`dark`?`bg-app border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-center justify-between shrink-0`,a===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`h3`,{className:Y(`text-lg font-semibold leading-none`,`text-z-primary`),children:`Edit Record`}),(0,Q.jsx)(`button`,{type:`button`,onClick:t,"aria-label":`Close`,className:Y(`p-1 transition-colors`,a===`dark`?`text-z-muted hover:text-z-secondary `:`text-z-secondary hover:text-z-secondary`),children:(0,Q.jsx)(B,{size:18})})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-8 custom-scrollbar`,children:u?(0,Q.jsxs)(`div`,{className:`h-full flex items-center justify-center flex-col gap-4`,children:[(0,Q.jsx)(C,{className:`animate-spin text-z-secondary `,size:32}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-z-secondary`,children:`Loading Document...`})]}):c&&o?(0,Q.jsx)(On,{fields:c.fields,initialData:o,onSubmit:async e=>{p(!0);try{let a=await q.patch(`/${n}/${r}`,e);U.success(`Document updated`),i&&i(a.data.data),t()}catch{U.error(`Update failed`)}finally{p(!1)}},isSubmitting:f}):(0,Q.jsx)(`div`,{className:`h-full flex items-center justify-center text-z-secondary font-semibold text-xs`,children:`Failed to load schema or data.`})})]})})}):null},An=({blockId:e,fieldKey:t,value:n,onChange:r,theme:i,hasMany:a=!1,relationTo:o,anchorEl:s})=>{let[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)([]),[m,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(new Set(n?Array.isArray(n)?n:[n]:[])),x=(0,Z.useRef)(null),S=(0,Z.useRef)(null),w=typeof o==`string`?o:Array.isArray(o)?o[0]:null;(0,Z.useEffect)(()=>{b(new Set(n?Array.isArray(n)?n:[n]:[]))},[n]),(0,Z.useEffect)(()=>{if(!c)return;let e=e=>{x.current&&!x.current.contains(e.target)&&l(!1)};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[c]),(0,Z.useEffect)(()=>{c&&S.current&&S.current.focus()},[c]),(0,Z.useEffect)(()=>{c&&w&&T(w,``)},[c,w]);let T=async(e,t)=>{g(!0);try{let n={limit:20};t&&(n.search=t),p((await q.get(`/${e}`,{params:n})).data.data||[])}catch{p([]),U.error(`Failed to fetch relation entries`)}finally{g(!1)}},E=e=>{let t=new Set(y);t.has(e)?t.delete(e):(a||t.clear(),t.add(e)),b(t),r(a?Array.from(t):t.size>0?Array.from(t)[0]:null),a||l(!1)},D=()=>{l(!1),d(``)},O=()=>{b(new Set),r(a?[]:null)},[k,j]=(0,Z.useState)({top:0,left:0});(0,Z.useEffect)(()=>{if(c)if(s){let e=s.getBoundingClientRect();j({top:e.bottom+window.scrollY+4,left:Math.max(8,e.left+window.scrollX)})}else j({top:120,left:window.innerWidth/2-160})},[c,s]);let M=y.size,ee=!n||Array.isArray(n)&&n.length===0?`Manage Relations`:` ${Array.isArray(n)?`${n.length} linked`:`1 linked`}`;return(0,Q.jsxs)(`div`,{className:`relative`,ref:x,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l(!c),className:Y(`w-full px-4 py-3 flex items-center justify-between border text-xs font-bold transition-all rounded-none-none`,i===`dark`?`bg-z-panel/5 border-z-border text-z-secondary hover:bg-z-hover border-z-border-strong`:`bg-z-input border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`),children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(ye,{size:14}),ee]}),(0,Q.jsx)(`span`,{className:`text-xs opacity-60`,children:c?`Close ▲`:`Edit ▼`})]}),(0,Q.jsx)(H,{children:c&&(0,Q.jsxs)(G.div,{initial:{opacity:0,y:-6,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-6,scale:.98},transition:{duration:.15},style:{top:k.top,left:k.left},className:Y(`fixed z-[900] w-80 border rounded-none-none shadow-2xl overflow-hidden flex flex-col`,i===`dark`?`bg-app/98 backdrop-blur-xl border-z-border text-z-primary`:`bg-z-panel/98 backdrop-blur-xl border-z-border text-z-primary`),children:[(0,Q.jsxs)(`div`,{className:Y(`px-4 py-3 border-b flex items-center justify-between shrink-0`,i===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:`Content Relations`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[M>0&&(0,Q.jsxs)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:[M,` selected`]}),(0,Q.jsx)(`button`,{type:`button`,onClick:O,"aria-label":`Clear all selected relations`,className:Y(`p-1 transition-colors`,i===`dark`?`text-z-secondary hover:text-rose-400`:`text-z-muted hover:text-rose-500`),children:(0,Q.jsx)(B,{size:11,"aria-hidden":`true`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>l(!1),"aria-label":`Close relation picker`,className:Y(`p-1 transition-colors`,i===`dark`?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`),children:(0,Q.jsx)(B,{size:12,"aria-hidden":`true`})})]})]}),w?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`shrink-0 px-3 pt-3 pb-2`,children:(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(h,{size:11,className:`absolute left-3 top-1/2 -translate-y-1/2 text-z-secondary`}),(0,Q.jsx)(`input`,{ref:S,type:`text`,placeholder:`Search to link...`,value:u,onChange:e=>{d(e.target.value),T(w,e.target.value)},className:Y(`w-full rounded-none-none py-2 pl-9 pr-3 text-xs font-bold border transition-all`,i===`dark`?`bg-z-hover border-z-border text-z-primary placeholder:text-z-muted`:`bg-z-input border-z-border text-z-primary placeholder:text-z-muted`)})]})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto max-h-56 custom-editor-scrollbar px-2 pb-2 space-y-0.5`,children:m?(0,Q.jsxs)(`div`,{className:`flex items-center justify-center py-8 gap-2`,children:[(0,Q.jsx)(C,{size:14,className:`animate-spin text-z-secondary `}),(0,Q.jsx)(`span`,{className:`text-xs font-bold text-z-secondary animate-pulse`,children:`Searching...`})]}):f.length===0?(0,Q.jsxs)(`div`,{className:`py-8 text-center`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold text-z-secondary`,children:`No results found`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary mt-1`,children:`Try a different search term`})]}):f.map(e=>{let t=e._id||e.id,n=e.title||e.name||e.headline||t,r=y.has(t);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>E(t),className:Y(`w-full flex items-center gap-2.5 px-3 py-2 rounded-none-none text-left text-xs font-semibold transition-all border`,r?i===`dark`?`bg-z-border/15 border-z-border/20 text-z-secondary`:`bg-z-input border-z-border text-z-primary`:i===`dark`?`border-z-border text-z-secondary hover:bg-z-hover hover:border-z-border`:`border-transparent text-z-primary hover:bg-[var(--z-bg-input)] hover:border-z-border shadow-sm`),children:[(0,Q.jsx)(`div`,{className:Y(`w-4 h-4 rounded-none-none border flex items-center justify-center shrink-0 transition-all`,r?`bg-z-border border-z-border text-z-primary`:i===`dark`?`border-z-border bg-z-hover`:`border-z-border-strong bg-z-panel`),children:r&&(0,Q.jsx)(z,{size:9})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:`truncate font-semibold`,children:String(n)}),e._status&&(0,Q.jsx)(`span`,{className:Y(`text-sm font-bold `,e._status===`published`?`text-z-secondary `:`text-amber-500`),children:e._status})]}),a&&r&&(0,Q.jsx)(`div`,{className:`shrink-0 ml-1`,children:(0,Q.jsx)(Ge,{size:10,className:`text-z-secondary`})}),r&&(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),v(t)},className:Y(`shrink-0 p-1.5 ml-2 transition-colors border`,`border-z-border hover:bg-[var(--z-bg-hover)] text-z-primary`),title:`Edit Document`,children:(0,Q.jsx)(A,{size:10})})]},t)})}),(0,Q.jsxs)(`div`,{className:Y(`px-3 py-2.5 border-t flex items-center gap-2 shrink-0`,i===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`button`,{type:`button`,onClick:O,className:Y(`flex-1 py-1.5 text-xs font-semibold border rounded-none-none transition-all`,i===`dark`?`border-z-border text-z-secondary hover:border-rose-500/20 hover:text-rose-400`:`border-z-border text-z-muted hover:border-rose-200 hover:text-rose-500`),children:`Clear`}),(0,Q.jsx)(`button`,{type:`button`,onClick:D,className:Y(`flex-1 py-1.5 text-xs font-semibold rounded-none-none transition-all bg-z-accent text-z-primary hover:bg-z-border`),children:`Done`})]})]}):(0,Q.jsxs)(`div`,{className:`p-6 text-center`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold text-z-secondary mb-1`,children:`No collection configured`}),(0,Q.jsxs)(`p`,{className:`text-xs text-z-secondary`,children:[`Set `,(0,Q.jsx)(`code`,{className:`text-xs`,children:`relationTo`}),` on the field to enable inline relation picker.`]})]})]})}),w&&(0,Q.jsx)(kn,{isOpen:!!_,onClose:()=>v(null),collectionSlug:w,documentId:_||``,onSaved:()=>{T(w,u)}})]})},jn=({item:e,idx:t,theme:n,dzId:r,isExpanded:i,toggleExpand:a,removeItem:s,def:c,blockId:l,fieldName:u,updateItem:d})=>{let p=Ne(),m=c?.title||X((e.__component||``).replace(/^content\./,``)),h=c?.icon||f;return(0,Q.jsxs)(V,{value:e,dragListener:!1,dragControls:p,initial:{opacity:0,height:0},animate:{opacity:1,height:`auto`},exit:{opacity:0,height:0},transition:{duration:.15},as:`div`,className:Y(`border rounded-none-none overflow-hidden`,n===`dark`?`bg-z-panel border-z-border`:`bg-z-input border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2.5 cursor-pointer select-none`,n===`dark`?`bg-z-panel hover:bg-z-hover`:`bg-[var(--z-bg-hover)]/50 hover:bg-[var(--z-bg-hover)]`),onClick:()=>a(r),children:[(0,Q.jsx)(`div`,{onPointerDown:e=>p.start(e),className:`shrink-0 cursor-grab active:cursor-grabbing p-1`,onClick:e=>e.stopPropagation(),children:(0,Q.jsx)(Ee,{size:12,className:`text-z-secondary`})}),(0,Q.jsx)(`div`,{className:Y(`w-5 h-5 rounded-none-none flex items-center justify-center shrink-0`,n===`dark`?`bg-z-panel/5`:`bg-[var(--z-bg-input)]`),children:(0,Q.jsx)(h,{size:10,className:`text-z-secondary`})}),(0,Q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Q.jsx)(`p`,{className:`text-xs font-semibold text-z-secondary truncate`,children:m})}),(0,Q.jsxs)(`span`,{className:Y(`text-sm font-semibold shrink-0`,`text-z-secondary`),children:[`#`,t+1]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,Q.jsx)(`button`,{onClick:()=>s(r),className:`p-1 text-z-secondary hover:text-rose-500 transition-colors`,children:(0,Q.jsx)(o,{size:12})}),(0,Q.jsx)(`button`,{onClick:()=>a(r),className:`p-1 text-z-secondary hover:text-z-secondary transition-colors`,children:i?(0,Q.jsx)(Ce,{size:12,className:`text-z-secondary`}):(0,Q.jsx)(We,{size:12,className:`text-z-muted`})})]})]}),(0,Q.jsx)(H,{initial:!1,children:i&&c&&(0,Q.jsx)(G.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:`overflow-hidden`,children:(0,Q.jsx)(`div`,{className:Y(`px-4 py-4 space-y-4 border-t`,`border-z-border`),children:c.fields.map(t=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:t.label||X(t.name)}),(0,Q.jsx)(zn,{blockId:`${l}:${u}:${r}`,field:t,value:e[t.name],onChange:e=>d(r,t.name,e),theme:n})]},t.name))})})})]})},Mn=({blockId:e,fieldName:t,value:n=[],onChange:r,theme:i,components:a})=>{let o=st(),{openComponentPicker:s}=dt(W(e=>({openComponentPicker:e.openComponentPicker}))),[c,l]=(0,Z.useState)(new Set),u=e=>{let t=e?.__component;if(t)return o.find(e=>e.type===t||e.type===t.replace(`content.`,``))},d=e=>{l(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},f=(0,Z.useCallback)(e=>{let t=o.find(t=>t.type===e),i={__component:`content.${e}`,...t?.defaultContent?JSON.parse(JSON.stringify(t.defaultContent)):{}},a=`dz_${Date.now()}_${Math.random().toString(36).slice(2)}`;i._dzId=a,r([...n,i]),l(e=>new Set([...e,a]))},[o,n,r]),p=(0,Z.useCallback)(()=>{s(e=>f(e))},[s,f]),m=e=>{r(n.filter(t=>t._dzId!==e))},h=(e,t,i)=>{r(n.map(n=>n._dzId===e?{...n,[t]:i}:n))},g=e=>{r(e)},_=a&&a.length>0?o.filter(e=>a.includes(e.type)):o;return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-1`,children:[(0,Q.jsx)(N,{size:10,className:`text-z-secondary`}),(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:`Dynamic Zone`}),(0,Q.jsxs)(`span`,{className:`text-xs text-z-secondary`,children:[`— `,n.length,` component`,n.length===1?``:`s`]})]}),n.length===0?(0,Q.jsx)(`div`,{className:Y(`py-5 text-center border border-dashed rounded-none-none`,`border-z-border text-z-secondary`),children:(0,Q.jsx)(`p`,{className:`text-xs font-bold`,children:`No components — add one below`})}):(0,Q.jsx)(qe,{axis:`y`,values:n,onReorder:g,className:`space-y-2`,children:(0,Q.jsx)(H,{initial:!1,children:n.map((n,r)=>{let a=n._dzId||`dz_${r}`;return(0,Q.jsx)(jn,{item:n,idx:r,theme:i,dzId:a,isExpanded:c.has(a),toggleExpand:d,removeItem:m,def:u(n),blockId:e,fieldName:t,updateItem:h},a)})})}),(0,Q.jsxs)(`button`,{type:`button`,onClick:p,className:Y(`w-full flex items-center justify-center gap-2 py-2.5 border border-dashed rounded-none-none transition-all text-xs font-semibold `,i===`dark`?`border-z-border text-z-secondary hover:border-z-border/40 hover:text-z-secondary hover:bg-z-hover`:`border-z-border text-z-muted hover:border-z-border hover:text-z-secondary hover:bg-[var(--z-bg-input)]/50`),children:[(0,Q.jsx)(M,{size:12}),`Add Component`,_.length>0&&(0,Q.jsxs)(`span`,{className:Y(`text-sm font-semibold ml-1`,`text-z-secondary`),children:[`(`,_.length,` available)`]})]})]})},Nn=new Map;function Pn(e){return Nn.get(e)}function Fn(e,t){if(!e)return``;try{let n=new Date(e);return isNaN(n.getTime())?e:t===`datetime`?n.toISOString().slice(0,16):t===`time`?n.toISOString().slice(11,16):n.toISOString().slice(0,10)}catch{return e}}function In(e,t){if(!e)return``;if(t===`time`)return e;try{return new Date(e).toISOString()}catch{return e}}function Ln(e){if(e==null||e===``)return null;let t=typeof e==`string`?e:JSON.stringify(e);try{return JSON.parse(t),!0}catch{return!1}}var Rn=Z.memo(({item:e,idx:t,theme:n,onRemove:r,onChange:i,field:a,blockId:s})=>{let c=Ne();return(0,Q.jsx)(V,{value:e._id||t,dragListener:!1,dragControls:c,as:`div`,children:(0,Q.jsxs)(`div`,{className:Y(`p-3 border rounded-none-none relative transition-all group/item`,n===`dark`?`bg-z-panel/5 border-z-border hover:border-z-border`:`bg-[var(--z-bg-input)] border-z-border hover:border-z-border-strong shadow-sm`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,Q.jsx)(`div`,{onPointerDown:e=>c.start(e),className:`cursor-grab`,children:(0,Q.jsx)(Ee,{size:12,className:Y(`opacity-30`,`text-z-secondary`)})}),(0,Q.jsxs)(`span`,{className:Y(`text-sm font-semibold `,`text-z-secondary`),children:[`#`,t+1]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r(t),"aria-label":`Remove item`,className:Y(`ml-auto p-1 transition-colors`,`opacity-0 group-hover/item:opacity-100`,n===`dark`?`text-red-500/50 hover:text-red-400`:`text-red-400/50 hover:text-red-600`),children:(0,Q.jsx)(o,{size:12})})]}),(0,Q.jsx)(`div`,{className:`space-y-3`,children:a.fields?.map(r=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:X(r.name)}),(0,Q.jsx)(zn,{blockId:`${s}-array-${t}`,field:r,value:e[r.name],onChange:e=>i(r.name,e),theme:n})]},r.name))})]})},e._id||t)}),zn=Z.memo(({blockId:e,field:t,value:n,onChange:r,onFieldSelect:i,theme:a,error:s,isSelected:c})=>{let{selectedFieldId:l,setSelectedFieldId:u,setSelectedField:d,data:f}=$(W(e=>({selectedFieldId:e.selectedFieldId,setSelectedFieldId:e.setSelectedFieldId,setSelectedField:e.setSelectedField,data:e.data}))),{openComponentPicker:p,showFieldIndicators:m}=dt(W(e=>({openComponentPicker:e.openComponentPicker,showFieldIndicators:e.showFieldIndicators}))),h=!!c||l===`${e}:${t.name}`;if(t.admin?.condition){let e=t.admin.condition,n=f?.[e.field],r=!1;switch(e.operator){case`equals`:r=n===e.value;break;case`not_equals`:r=n!==e.value;break;case`in`:r=Array.isArray(e.value)&&e.value.includes(n);break;case`not_in`:r=Array.isArray(e.value)&&!e.value.includes(n);break;case`contains`:r=typeof n==`string`&&n.includes(e.value);break;case`exists`:r=e.value?n!=null&&n!==``:n==null||n===``;break}if(!r)return null}let g=()=>{let e=Array.isArray(n)?[...n]:[],i={_id:at()};t.fields?.forEach(e=>{i[e.name]=e.type===`array`?[]:``}),e.push(i),r(e)},_=e=>{Array.isArray(n)&&r(n.filter((t,n)=>n!==e))};return(0,Q.jsxs)(`div`,{className:Y(`stega-field-wrapper relative transition-all duration-200`,m&&`group/field`,h&&`field-selected`),onClick:n=>{n.stopPropagation(),i?i(e,t.name):d({blockId:e,fieldKey:t.name}),$.getState().setActiveSection(e)},style:{padding:m?`2px`:0},children:[m&&(0,Q.jsx)(`div`,{className:`stega-field-indicator`,children:h?(0,Q.jsx)(nt,{size:10}):(0,Q.jsx)(`span`,{className:`text-sm`})}),t.description&&(0,Q.jsx)(`p`,{className:Y(`text-sm font-medium mt-0.5 mb-1`,`text-z-secondary`),children:t.description}),(()=>{let c=Pn(t.type);if(c)return(0,Q.jsx)(c,{blockId:e,field:t,value:n,onChange:r,onFieldSelect:i,theme:a,error:s,isSelected:h});switch(t.type){case`media`:return(0,Q.jsx)(Ut,{value:n,onChange:r,hasMany:t.hasMany});case`richtext`:case`lexical`:return(0,Q.jsx)(`textarea`,{value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter ${t.name}...`,className:Y(`w-full px-4 py-3 text-sm transition-all rounded-none-none min-h-[120px] resize-y`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`email`:return(0,Q.jsx)(`input`,{type:`email`,value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter email address...`,autoComplete:`email`,className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`password`:return(0,Q.jsx)(`input`,{type:`password`,value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter password...`,autoComplete:`new-password`,className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`uid`:{let[e,i]=Z.useState(!n),o=t.sourceField||`title`;return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{type:`text`,value:n||``,onChange:e=>{r(e.target.value),i(!1)},placeholder:t.placeholder||`Auto-generated from ${o}...`,className:Y(`flex-1 px-4 py-2.5 text-xs transition-all rounded-none-none font-mono`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>i(!e),className:Y(`px-2.5 py-2.5 text-sm font-semibold border rounded-none-none transition-all shrink-0`,e?`bg-z-panel border-z-border/30 text-z-secondary`:a===`dark`?`border-z-border text-z-secondary hover:text-z-secondary`:`border-z-border text-z-muted hover:text-z-secondary`),title:e?`Auto-generation enabled`:`Enable auto-generation`,children:e?` Auto`:`Manual`})]}),e&&(0,Q.jsxs)(`p`,{className:Y(`text-sm font-bold px-1`,`text-z-secondary`),children:[`Will be auto-generated from the "`,o,`" field`]})]})}case`color`:{let e=t.options||[`#000000`,`#ffffff`,`#ef4444`,`#f59e0b`,`var(--z-accent)`,`#3b82f6`,`var(--z-accent)`,`var(--z-accent)`,`#ec4899`];return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`relative`,children:(0,Q.jsx)(`input`,{type:`color`,value:n||`#000000`,onChange:e=>r(e.target.value),className:`w-10 h-10 rounded-none-none border cursor-pointer p-0.5`,style:{background:`transparent`}})}),(0,Q.jsx)(`input`,{type:`text`,value:n||``,onChange:e=>r(e.target.value),placeholder:`#000000`,className:Y(`flex-1 px-4 py-2.5 text-xs font-mono transition-all rounded-none-none `,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)})]}),e.length>0&&(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>{let t=typeof e==`string`?e:e.value,i=typeof e==`string`?e:e.label;return(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r(t),className:Y(`w-6 h-6 rounded-none-none border-2 transition-all`,n===t?`border-z-border scale-110`:`border-z-border hover:border-z-border`),style:{backgroundColor:t},title:i},t)})})]})}case`text`:return(0,Q.jsx)(`input`,{type:`text`,value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter ${X(t.name)}...`,className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`textarea`:return(0,Q.jsx)(`textarea`,{value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter ${X(t.name)}...`,rows:4,className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none resize-y`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`code`:return(0,Q.jsx)(`textarea`,{value:n||``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter ${t.language||`code`}...`,rows:8,spellCheck:!1,className:Y(`w-full px-4 py-2.5 text-xs font-mono transition-all rounded-none-none resize-y`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-[#e6edf3]`:`bg-z-accent border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`collapsible`:{let i=t.fields||[],o=n&&typeof n==`object`?n:{};return(0,Q.jsx)(`div`,{className:Y(`border-l-2 pl-3 space-y-2`,a===`dark`?`border-z-border/30`:`border-z-border-strong`),children:i.map(n=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:X(n.name)}),(0,Q.jsx)(zn,{blockId:`${e}:${t.name}`,field:n,value:o[n.name],onChange:e=>r({...o,[n.name]:e}),theme:a})]},n.name))})}case`join`:return(0,Q.jsx)(`div`,{className:Y(`w-full px-4 py-3 border text-xs rounded-none-none`,a===`dark`?`bg-z-hover border-z-border/20 text-z-secondary`:`bg-z-input border-z-border text-z-secondary`),children:`⧉ Joined data — read-only`});case`point`:{let e=Array.isArray(n)&&n.length===2&&!isNaN(n[0])&&!isNaN(n[1])?n:[0,0];return(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-secondary`,children:`Lng`}),(0,Q.jsx)(`input`,{type:`number`,value:e[0],onChange:t=>r([Number(t.target.value),e[1]]),step:`any`,className:Y(`w-full px-3 py-2 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)})]}),(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-secondary`,children:`Lat`}),(0,Q.jsx)(`input`,{type:`number`,value:e[1],onChange:t=>r([e[0],Number(t.target.value)]),step:`any`,className:Y(`w-full px-3 py-2 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)})]})]})}case`radio`:{let i=t.options||[];return(0,Q.jsx)(`div`,{className:Y(`flex gap-3`,t.layout===`horizontal`?`flex-row flex-wrap`:`flex-col gap-1.5`),children:i.map(i=>{let o=typeof i==`string`?i:i.value,s=typeof i==`string`?i:i.label;return(0,Q.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer`,children:[(0,Q.jsx)(`input`,{type:`radio`,name:`${e}:${t.name}`,value:o,checked:n==o,onChange:e=>{r(typeof o==`number`?Number(e.target.value):e.target.value)},className:`w-3.5 h-3.5 accent-gray-500`}),(0,Q.jsx)(`span`,{className:Y(`text-xs`,a===`dark`?`text-z-secondary`:`text-z-primary`),children:s})]},o)})})}case`row`:{let i=t.fields||[],o=n&&typeof n==`object`?n:{};return(0,Q.jsx)(`div`,{className:`flex gap-2 items-end`,children:i.map(n=>(0,Q.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:X(n.name)}),(0,Q.jsx)(zn,{blockId:`${e}:${t.name}`,field:n,value:o[n.name],onChange:e=>r({...o,[n.name]:e}),theme:a})]},n.name))})}case`ui`:{let e=t.admin?.components?.Field;return e?(0,Q.jsx)(e,{field:t,value:n,onChange:r}):null}case`number`:return(0,Q.jsx)(`input`,{type:`number`,value:n??``,onChange:e=>{r(e.target.value===``?``:Number(e.target.value))},placeholder:t.placeholder||`Enter ${X(t.name)}...`,className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)});case`boolean`:case`checkbox`:return(0,Q.jsxs)(`label`,{className:`flex items-center gap-3 cursor-pointer py-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:!!n,onChange:e=>r(e.target.checked),className:`w-4 h-4 rounded-none-none border border-z-border bg-z-hover checked:bg-[var(--z-bg-input)] checked:border-z-border transition-all accent-gray-500`}),(0,Q.jsx)(`span`,{className:Y(`text-xs font-medium`,a===`dark`?`text-z-secondary`:`text-z-primary`),children:X(t.name)})]});case`select`:{let e=t.options||[],i=!!t.hasMany,[o,s]=Z.useState(!1),c=Z.useRef(null),l=i?Array.isArray(n)?n:[]:n!=null&&n!==``?[n]:[],u=e=>typeof e==`string`?e:e.label,d=e=>typeof e==`string`?e:e.value,f=l.map(t=>u(e.find(e=>d(e)===t))||String(t)).join(`, `),p=e=>{if(i){let t=Array.isArray(n)?[...n]:[],i=t.indexOf(e);i>=0?t.splice(i,1):t.push(e),r(t)}else r(e),s(!1)};return Z.useEffect(()=>{if(!o)return;let e=e=>{c.current&&!c.current.contains(e.target)&&s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[o]),(0,Q.jsxs)(`div`,{className:`relative`,ref:c,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(!o),className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none flex items-center justify-between gap-2`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`),children:[(0,Q.jsx)(`span`,{className:Y(`truncate`,!l.length&&`text-z-secondary`),children:f||`Select option...`}),(0,Q.jsx)(`svg`,{className:Y(`w-3 h-3 shrink-0 transition-transform`,o&&`rotate-180`,a===`dark`?`text-z-muted`:`text-z-secondary`),fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,Q.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:2,d:`M19 9l-7 7-7-7`})})]}),o&&(0,Q.jsxs)(`div`,{className:Y(`absolute z-50 left-0 right-0 mt-1 border shadow-xl max-h-60 overflow-y-auto`,a===`dark`?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),children:[i&&l.length>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r([]),className:Y(`w-full text-left px-3 py-1.5 text-sm font-semibold `,a===`dark`?`text-z-secondary hover:bg-z-hover`:`text-z-muted hover:bg-[var(--z-bg-input)]`),children:`Clear all`}),e.map(e=>{let t=u(e),n=d(e),r=l.includes(n);return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>p(n),className:Y(`w-full text-left px-3 py-2 text-xs flex items-center gap-2 transition-colors`,r?a===`dark`?`bg-z-panel/5 text-z-secondary`:`bg-[var(--z-bg-input)] text-z-secondary`:a===`dark`?`text-z-secondary hover:bg-z-hover`:`text-z-primary hover:bg-[var(--z-bg-input)]`),children:[(0,Q.jsx)(`span`,{className:Y(`w-3.5 h-3.5 border shrink-0 flex items-center justify-center transition-all rounded-none-none`,r?`bg-z-border border-z-border`:a===`dark`?`border-z-border`:`border-z-border-strong`),children:r&&(0,Q.jsx)(`svg`,{className:`w-2.5 h-2.5 text-z-primary`,fill:`none`,viewBox:`0 0 24 24`,stroke:`currentColor`,children:(0,Q.jsx)(`path`,{strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:3,d:`M5 13l4 4L19 7`})})}),(0,Q.jsx)(`span`,{className:`font-bold truncate`,children:t})]},n)})]})]})}case`relation`:return(0,Q.jsx)(An,{blockId:e,fieldKey:t.name,value:n,onChange:r,theme:a,hasMany:t.hasMany,relationTo:t.relationTo,anchorEl:null});case`date`:{let e=t.dateFormat||`date`;return(0,Q.jsx)(`input`,{type:e===`datetime`?`datetime-local`:e===`time`?`time`:`date`,value:n?Fn(n,e):``,onChange:t=>r(t.target.value?In(t.target.value,e):``),className:Y(`w-full px-4 py-2.5 text-xs transition-all rounded-none-none`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-z-primary`:`bg-z-panel border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)})}case`array`:{let i=Array.isArray(n)?n:[],o=e=>{let t=new Set(i.map((e,t)=>e._id??t));e.every((e,n)=>t.has(e._id??n))&&r(e)};return(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:[i.length,` `,i.length===1?`Item`:`Items`]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:g,className:Y(`flex items-center gap-1 px-2.5 py-1 text-xs font-semibold transition-all border`,a===`dark`?`bg-z-panel/5 border-z-border text-z-secondary hover:bg-z-hover border-z-border-strong`:`bg-z-input border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`),children:[(0,Q.jsx)(M,{size:10}),` Add Item`]})]}),(0,Q.jsx)(qe,{axis:`y`,values:i.map((e,t)=>e._id||t),onReorder:e=>{let t=new Map(i.map((e,t)=>[e._id||t,e]));o(e.map(e=>t.get(e)).filter(Boolean))},className:`space-y-3`,children:i.map((n,o)=>(0,Q.jsx)(Rn,{item:n,idx:o,theme:a,onRemove:_,onChange:(e,t)=>{let n=[...i];n[o]={...n[o],[e]:t},r(n)},field:t,blockId:e,humanize:X},n._id||o))})]})}case`group`:{let i=n&&typeof n==`object`?n:{};return(0,Q.jsx)(`div`,{className:`border-l border-z-border/20 pl-3 space-y-3`,children:t.fields?.map(n=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:X(n.name)}),(0,Q.jsx)(zn,{blockId:`${e}:${t.name}`,field:n,value:i[n.name],onChange:e=>r({...i,[n.name]:e}),theme:a})]},n.name))})}case`json`:{let e=Ln(n);return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`textarea`,{value:typeof n==`string`?n:JSON.stringify(n,null,2)??``,onChange:e=>r(e.target.value),placeholder:t.placeholder||`Enter JSON...`,rows:8,spellCheck:!1,className:Y(`w-full px-4 py-2.5 text-xs font-mono transition-all rounded-none-none resize-y`,a===`dark`?`bg-z-base/65 backdrop-blur-md border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-accent/50 text-[#e6edf3]`:`bg-z-accent border border-z-border focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:border-z-border text-z-primary`)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:Y(`inline-block w-1.5 h-1.5 rounded-none-none`,e===!0?`bg-z-border shadow-sm`:e===!1?`bg-red-500 shadow-[0_0_6px_#ef4444]`:`bg-z-accent`)}),(0,Q.jsx)(`span`,{className:`text-xs font-bold`,style:{color:e===!0?`var(--z-accent)`:e===!1?`#ef4444`:`#6b7280`},children:e===!0?`Valid JSON`:e===!1?`Invalid JSON`:`JSON`})]})]})}case`blocks`:{let i=n&&Array.isArray(n)?n:[],s=t.blocks||[];return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[i.length>0&&(0,Q.jsx)(`div`,{className:`space-y-2`,children:i.map((n,c)=>{let l=n.blockType||n.__blockType,u=s.find(e=>e.slug===l),d=u?.fields||[];return(0,Q.jsxs)(`div`,{className:Y(`border rounded-none-none overflow-hidden`,a===`dark`?`bg-z-panel/5 border-z-border`:`bg-z-input border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`flex items-center gap-2 px-3 py-2 border-b`,a===`dark`?`bg-z-panel/5 border-z-border`:`bg-[var(--z-bg-hover)]/50 border-z-border`),children:[(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold px-1.5 py-0.5 border rounded-none-none`,a===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-primary`),children:u?.labels?.singular||X(l||`block`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{r(i.filter((e,t)=>t!==c))},className:`ml-auto p-1 text-z-secondary hover:text-rose-500 transition-colors`,"aria-label":`Remove block`,children:(0,Q.jsx)(o,{size:10})})]}),(0,Q.jsx)(`div`,{className:`px-3 py-3 space-y-3`,children:d.map(o=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:o.label||X(o.name)}),(0,Q.jsx)(zn,{blockId:`${e}:${t.name}:${c}`,field:o,value:n[o.name],onChange:e=>{let t=[...i];t[c]={...t[c],[o.name]:e},r(t)},theme:a})]},o.name))})]},n._id||c)})}),(!t.maxRows||i.length<t.maxRows)&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{p(e=>{let t={blockType:e,_id:at()};r([...i,t])},s.length>0?s:void 0)},className:Y(`w-full py-2.5 border-2 border-dashed flex flex-col items-center justify-center gap-1.5 transition-all group rounded-none-none`,a===`dark`?`border-z-border hover:border-z-border/50 hover:bg-z-hover text-z-muted hover:text-z-secondary`:`border-z-border-strong hover:border-z-border hover:bg-[var(--z-bg-input)] text-z-secondary hover:text-z-secondary`),children:[(0,Q.jsx)(`div`,{className:Y(`p-1.5 rounded-none-none transition-colors`,a===`dark`?`bg-z-hover group-hover:bg-z-hover border-z-border-strong`:`bg-[var(--z-bg-hover)] group-hover:bg-[var(--z-bg-hover)]`),children:(0,Q.jsx)(M,{size:14,className:`stroke-[3]`})}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:`Add Block`})]})]})}case`tabs`:{let i=t.tabs||[],[o,s]=(0,Z.useState)(0),c=n&&typeof n==`object`?n:{};return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[i.length>1&&(0,Q.jsx)(`div`,{className:Y(`flex gap-0.5 p-0.5 rounded-none-none border`,`bg-z-panel border-z-border`),children:i.map((e,t)=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(t),className:Y(`px-3 py-1.5 text-sm font-semibold transition-all`,o===t?a===`dark`?`bg-z-hover text-z-primary`:`bg-z-panel text-z-primary shadow-sm`:a===`dark`?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`),children:e.label||`Tab ${t+1}`},e.label||t))}),i[o]&&(0,Q.jsx)(`div`,{className:`space-y-3`,children:i[o].fields?.map(n=>(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-semibold text-z-muted block`,children:n.label||X(n.name)}),(0,Q.jsx)(zn,{blockId:`${e}:${t.name}`,field:n,value:c[n.name],onChange:e=>r({...c,[n.name]:e}),theme:a})]},n.name))})]})}case`dz`:return(0,Q.jsx)(Mn,{blockId:e,fieldName:t.name,value:n||[],onChange:r,theme:a,components:t.components||[]});default:return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border border-dashed border-red-500/30 text-red-400 text-xs`,children:[(0,Q.jsx)(S,{size:14}),` Unsupported field type: `,t.type]})}})(),s&&(0,Q.jsx)(`p`,{className:`text-xs text-red-500 mt-1`,role:`alert`,"aria-live":`polite`,children:s})]})}),Bn=(e,t)=>{let n=e.toLowerCase();return n.includes(`image`)||n.includes(`photo`)||n.includes(`thumbnail`)||n.includes(`cover`)||n.includes(`banner`)||n.includes(`logo`)?`media`:n.includes(`content`)||n.includes(`description`)||n.includes(`bio`)||typeof t==`string`&&t.length>200?`richtext`:Array.isArray(t)?`array`:typeof t==`object`&&t?`group`:`text`},Vn=({section:e,index:t,totalSections:n,isActive:r,isMultiSelected:a=!1,onSelect:c,onDuplicate:l,onDelete:u,onAlign:d,onFieldChange:f,onToggleCollapse:p,onMoveUp:m,onMoveDown:h,onCopy:g,onPaste:_,onBlockNameChange:v,onFieldSelect:y,theme:x,showFieldIndicators:S,selectedField:C,schemaFields:w,fieldErrors:T={},i18nEnabled:E,currentLocale:O,getTranslatedValue:k,setTranslatedValue:j,onAddToDynamicZone:M,dragControls:ee,onContextMenu:N})=>{let P=st().find(t=>t.type===e.blockType),[F,I]=Z.useState(!1),te=Z.useRef(null),re=Z.useRef(null),[L,ie]=Z.useState(null),[ae,oe]=Z.useState(!1),se=Z.useRef(null),{undo:le,redo:ue}=$();Z.useEffect(()=>{if(!F)return;let e=e=>{re.current?.contains(e.target)||te.current&&!te.current.contains(e.target)&&I(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[F]);let R=(e,t)=>{f(e,t)},de=e.blockType===`callout`,fe=e.content?.type||`info`,z=de?{info:`border-l-4 border-l-sky-500 bg-sky-500/5`,warning:`border-l-4 border-l-amber-500 bg-amber-500/5`,success:`border-l-4 border-z-border bg-z-hover`,error:`border-l-4 border-l-rose-500 bg-rose-500/5`}[fe]||`border-l-4 border-l-sky-500 bg-sky-500/5`:``,pe=e.content?.theme||`default`,B=e.content?.paddingY||`medium`,me=e.content?.containerWidth||`boxed`,V=e.content?.anchorId||void 0,ge={default:``,light:`bg-z-panel/90 text-z-primary border-z-border shadow-sm`,dark:`bg-z-popover text-z-primary border-z-border shadow-lg`,"cyber-gray":`bg-gradient-to-br from-[var(--z-bg-panel)] via-[var(--z-bg-base)] to-[var(--z-bg-panel)] text-z-primary border-z-border/20 shadow-sm/5`,glassmorphic:`bg-z-input backdrop-blur-[12px] border-z-border shadow-sm text-z-primary`}[pe]||``,_e={none:`py-2 px-6`,small:`py-6 px-6`,medium:`py-12 px-6`,large:`py-20 px-8`}[B]||`py-6 px-6`,ye={boxed:`max-w-6xl mx-auto`,"full-width":`w-full`}[me]||``,be=Object.keys(T).filter(t=>t.startsWith(e.id+`:`)).length,xe=Z.useMemo(()=>P?.fields?P.fields:Object.keys(e.content||{}).map(t=>{let n=e.content[t];return{name:t,type:Bn(t,n),label:t.replace(/_/g,` `).replace(/([A-Z])/g,` $1`).replace(/^./,e=>e.toUpperCase()).trim()}}),[P,e.content]);Z.useMemo(()=>xe.filter(e=>e.name!==`content`&&e.name!==`description`&&e.name!==`bio`&&e.type!==`richtext`).length,[xe]);let Se=e.collapsed??!1;return(0,Q.jsxs)(`div`,{id:V||e.id,onClick:c,onContextMenu:N,className:Y(`rounded-none-none border transition-all duration-500 relative cursor-pointer`,z,ge||(x===`dark`?`bg-z-panel border-z-border hover:border-z-border`:`bg-z-panel border-z-border shadow-sm hover:border-z-border`),r&&`ring-2 ring-z-active-border scale-[1.005]`,a&&!r&&`ring-2 ring-amber-500/40`),children:[(0,Q.jsxs)(`div`,{className:Y(`flex items-center justify-between px-6 py-4 border-b select-none`,Se?`border-b-0`:``,x===`dark`?`border-z-border bg-z-panel`:`border-z-border shadow-sm bg-[var(--z-bg-input)]/50`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,Q.jsx)(`div`,{onPointerDown:e=>ee&&ee.start(e),title:`Drag to reorder`,role:`button`,"aria-label":`Drag to reorder section`,"aria-grabbed":`false`,tabIndex:-1,className:Y(`w-7 h-7 rounded-none-none border flex items-center justify-center cursor-grab active:cursor-grabbing shrink-0 transition-all`,x===`dark`?`bg-z-hover border-z-border text-z-muted/60 hover:bg-z-panel hover:border-z-border/30 hover:text-z-secondary`:`bg-[var(--z-bg-hover)] border-z-border text-z-secondary/60 hover:bg-[var(--z-bg-input)] hover:border-z-border-strong hover:text-z-secondary`),children:(0,Q.jsx)(i,{size:12,"aria-hidden":`true`})}),(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold leading-none w-5 text-center`,`text-z-secondary`),children:String(t+1).padStart(2,`0`)}),(0,Q.jsx)(`span`,{className:Y(`px-2 py-0.5 text-sm font-semibold border shrink-0`,x===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-primary`),children:X(e.blockType)}),ae?(0,Q.jsx)(`input`,{ref:se,autoFocus:!0,value:e.blockName||``,onChange:e=>v(e.target.value),onBlur:()=>oe(!1),onKeyDown:e=>{e.key===`Enter`&&oe(!1)},onClick:e=>e.stopPropagation(),className:Y(`text-xs font-semibold bg-transparent border-b px-1 min-w-[80px] max-w-[200px]`,x===`dark`?`text-z-primary border-z-border`:`text-z-primary border-z-border-strong`),placeholder:`Block name...`}):(0,Q.jsxs)(`span`,{onClick:e=>{e.stopPropagation(),oe(!0),setTimeout(()=>se.current?.focus(),0)},className:Y(`text-xs font-semibold truncate cursor-text px-1 flex items-center gap-1.5`,e.blockName?`text-z-primary`:`text-z-secondary`),children:[e.blockName||`Add name...`,(0,Q.jsx)(A,{size:10,className:`opacity-0 group-hover/item:opacity-40 transition-opacity`})]}),be>0&&(0,Q.jsxs)(`span`,{className:`px-1.5 py-0.5 text-sm font-semibold bg-rose-500/10 border border-rose-500/20 text-rose-500 shrink-0`,children:[be,` error`,be===1?``:`s`]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5 shrink-0`,children:[(0,Q.jsx)(`button`,{onClick:e=>{e.stopPropagation(),p()},className:Y(`p-1.5 rounded-none-none border transition-all`,x===`dark`?`text-z-secondary border-transparent hover:text-z-secondary`:`text-z-muted border-transparent hover:text-z-secondary `),title:Se?`Expand`:`Collapse`,children:Se?(0,Q.jsx)(ce,{size:12}):(0,Q.jsx)(We,{size:12})}),(0,Q.jsx)(`button`,{ref:re,onClick:e=>{if(e.stopPropagation(),!F&&re.current){let e=re.current.getBoundingClientRect();ie({top:e.bottom+4,left:e.right-160})}I(!F)},className:Y(`p-1.5 rounded-none-none border transition-all`,F?x===`dark`?`bg-z-hover border-z-border-strong border-z-border/30 text-z-secondary`:`bg-[var(--z-bg-hover)] border-z-border text-z-secondary`:x===`dark`?`text-z-secondary border-transparent hover:text-z-secondary`:`text-z-muted border-transparent hover:text-z-secondary `),title:`Actions`,children:(0,Q.jsx)(ne,{size:14})})]})]}),(0,Q.jsx)(H,{initial:!1,children:!Se&&(0,Q.jsx)(G.div,{initial:{height:0,opacity:0},animate:{height:`auto`,opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:`overflow-visible`,children:(0,Q.jsxs)(`div`,{className:Y(`transition-all duration-300`,_e,ye),children:[(0,Q.jsxs)(`div`,{className:Y(`flex items-center justify-between -mx-6 -mt-6 mb-6 px-4 py-2 border-b`,x===`dark`?`bg-z-panel/5 border-z-border`:`bg-[var(--z-bg-input)]/50 border-z-border shadow-sm`),children:[(0,Q.jsx)(`div`,{className:Y(`flex items-center gap-0.5 p-0.5 rounded-none-none border`,x===`dark`?`bg-app/20 border-z-border`:`bg-z-panel border-z-border`),children:[`left`,`center`,`right`].map(t=>(0,Q.jsxs)(`button`,{"aria-label":`Align ${t}`,onClick:e=>{e.stopPropagation(),d(t)},className:Y(`p-1 transition-all`,e.align===t||!e.align&&t===`left`?x===`dark`?`bg-z-hover text-z-primary`:`bg-app text-z-primary shadow-sm`:`text-z-muted hover:text-z-secondary `),children:[t===`left`&&(0,Q.jsx)(s,{size:10}),t===`center`&&(0,Q.jsx)(Oe,{size:10}),t===`right`&&(0,Q.jsx)(D,{size:10})]},t))}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:(0,Q.jsx)(`span`,{className:Y(`text-sm font-bold select-none`,x===`dark`?`text-z-primary`:`text-z-muted`),title:`Use Ctrl+Z / Ctrl+Y to undo or redo changes`,children:`Ctrl+Z / Ctrl+Y to undo/redo`})})]}),e.blockType===`code`&&(0,Q.jsxs)(`div`,{className:Y(`w-full px-4 py-2 border-b flex items-center justify-between -mx-6 -mt-6 mb-6`,x===`dark`?`bg-[#0F172A]/80 border-z-border`:`bg-[var(--z-bg-hover)] border-z-border`),children:[(0,Q.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-none-none bg-rose-500`}),(0,Q.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-none-none bg-amber-500`}),(0,Q.jsx)(`span`,{className:`w-2.5 h-2.5 rounded-none-none bg-z-border`})]}),(0,Q.jsxs)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:[e.content?.language||`javascript`,` terminal`]})]}),e.blockType===`table`?(0,Q.jsx)(`div`,{className:`w-full overflow-x-auto border border-z-border bg-app/20 p-4 rounded-none-none`,children:(0,Q.jsx)(`div`,{className:`overflow-x-auto min-w-full pb-4`,children:(0,Q.jsxs)(`table`,{className:`w-full border-collapse text-left text-xs font-mono`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:Y(x===`dark`?`bg-z-hover border-b border-z-border`:`bg-[var(--z-bg-hover)] border-b border-z-border`),children:[(e.content?.headers||[]).map((t,n)=>(0,Q.jsx)(`th`,{className:`p-2.5`,children:(0,Q.jsx)(`input`,{type:`text`,value:t.text||``,onChange:t=>{let r=[...e.content.headers||[]];r[n]={...r[n],text:t.target.value},R(`headers`,r)},className:`bg-transparent border-none font-bold w-full focus:bg-z-hover focus-visible:ring-2 focus-visible:ring-z-active-border rounded-none px-1 text-xs`,placeholder:`Header ${n+1}`})},n)),(0,Q.jsx)(`th`,{className:`w-10`,children:(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation();let n=[...e.content.headers||[]];n.push({text:``}),R(`headers`,n),R(`rows`,(e.content.rows||[]).map(e=>({cells:[...e.cells||[],{text:``}]})))},className:`text-xs text-z-secondary font-bold hover:text-z-secondary`,children:`+ Col`})})]})}),(0,Q.jsxs)(`tbody`,{children:[(e.content?.rows||[]).map((t,n)=>(0,Q.jsxs)(`tr`,{className:Y(x===`dark`?`border-b border-z-border hover:bg-z-panel`:`border-b border-z-border hover:bg-[var(--z-bg-input)]`),children:[(t.cells||[]).map((t,r)=>(0,Q.jsx)(`td`,{className:`p-2`,children:(0,Q.jsx)(`input`,{type:`text`,value:t.text||``,onChange:t=>{let i=[...e.content.rows||[]],a=[...i[n].cells||[]];a[r]={...a[r],text:t.target.value},i[n]={...i[n],cells:a},R(`rows`,i)},className:`bg-transparent border-none w-full focus:bg-z-hover focus-visible:ring-2 focus-visible:ring-z-active-border rounded-none px-1`,placeholder:`Cell...`})},r)),(0,Q.jsx)(`td`,{className:`p-2`,children:(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),R(`rows`,(e.content.rows||[]).filter((e,t)=>t!==n))},className:`text-xs text-rose-500 font-bold hover:text-rose-400`,children:`Delete`})})]},n)),(0,Q.jsx)(`tr`,{children:(0,Q.jsx)(`td`,{colSpan:(e.content?.headers||[]).length+1,className:`p-2`,children:(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation();let n=[...e.content.rows||[]],r=(e.content?.headers||[]).length,i=Array.from({length:r},()=>({text:``}));n.push({cells:i}),R(`rows`,n)},className:`text-xs text-z-secondary font-bold hover:text-z-secondary flex items-center gap-1`,children:`+ Add Row`})})})]})]})})}):(0,Q.jsxs)(`div`,{className:`space-y-8`,children:[(0,Q.jsx)(`div`,{className:Y(`gap-8`,xe.filter(e=>![`anchorId`,`theme`,`paddingY`,`containerWidth`,`bgImage`].includes(e.name)&&e.name!==`content`&&e.name!==`description`&&e.name!==`bio`&&e.type!==`richtext`).length>=4?`grid grid-cols-1 md:grid-cols-2`:`space-y-6`,e.align===`center`&&`text-center`,e.align===`right`&&`text-right`),children:xe.filter(e=>![`anchorId`,`theme`,`paddingY`,`containerWidth`,`bgImage`].includes(e.name)).map(t=>{let n=e.content?.[t.name],r=E&&k?k(e.id,t.name,n):n,i=t.name===`content`||t.name===`description`||t.name===`bio`||t.type===`richtext`,a=`${e.id}:${t.name}`;return(0,Q.jsxs)(`div`,{className:Y(`space-y-2`,i&&`md:col-span-2`),children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`label`,{className:`text-sm font-semibold text-z-secondary px-1`,children:t.label||t.name}),(0,Q.jsx)(`span`,{className:Y(`px-2 py-0.5 text-[10px] uppercase tracking-wider font-bold rounded-none-none border`,x===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-[var(--z-bg-hover)] border-z-border text-z-muted`),children:t.type}),T[a]&&(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-rose-500 ml-auto`,children:T[a]})]}),t.description&&(0,Q.jsx)(`p`,{className:Y(`text-xs font-medium px-1.5 opacity-60`,x===`dark`?`text-z-muted`:`text-z-secondary`),children:t.description})]}),(0,Q.jsx)(zn,{blockId:e.id,field:t,value:r,onChange:n=>{E&&O!==`en`&&j?j(e.id,t.name,n):R(t.name,n)},onFieldSelect:y,theme:x,error:T[a],isSelected:C?.blockId===e.id&&C?.fieldKey===t.name})]},t.name)})}),xe.some(e=>[`anchorId`,`theme`,`paddingY`,`containerWidth`,`bgImage`].includes(e.name))&&(0,Q.jsxs)(`div`,{className:Y(`pt-6 mt-6 border-t`,`border-z-border`),children:[(0,Q.jsx)(`h4`,{className:`text-sm font-semibold text-z-secondary/50 mb-4 px-1`,children:`Layout & Styling`}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-4`,children:xe.filter(e=>[`anchorId`,`theme`,`paddingY`,`containerWidth`,`bgImage`].includes(e.name)).map(t=>{let n=e.content?.[t.name],r=E&&k?k(e.id,t.name,n):n,i=`${e.id}:${t.name}`;return(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,Q.jsx)(`label`,{className:`text-sm font-semibold text-z-secondary px-1`,children:t.label||t.name})}),(0,Q.jsx)(zn,{blockId:e.id,field:t,value:r,onChange:n=>{E&&O!==`en`&&j?j(e.id,t.name,n):R(t.name,n)},onFieldSelect:y,theme:x,error:T[i],isSelected:C?.blockId===e.id&&C?.fieldKey===t.name})]},t.name)})})]})]})]})})}),F&&L&&(0,Vt.createPortal)((0,Q.jsx)(`div`,{ref:te,style:{position:`fixed`,top:L.top,left:L.left,zIndex:900},className:Y(`min-w-[160px] border shadow-xl rounded-none-none`,x===`dark`?`bg-app border-z-border`:`bg-z-panel border-z-border`),onClick:e=>e.stopPropagation(),children:(0,Q.jsxs)(`div`,{className:`py-1`,children:[t>0&&(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(ve,{size:12}),label:`Move Up`,onClick:()=>{m(),I(!1)},theme:x}),t<n-1&&(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(Qe,{size:12}),label:`Move Down`,onClick:()=>{h(),I(!1)},theme:x}),(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(b,{size:12}),label:`Duplicate`,onClick:()=>{l(),I(!1)},theme:x}),(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(he,{size:12}),label:`Copy`,onClick:()=>{g(),I(!1)},theme:x}),(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(Ke,{size:12}),label:`Paste`,onClick:()=>{_(),I(!1)},theme:x}),(0,Q.jsx)(`div`,{className:Y(`border-t my-1`,x===`dark`?`border-z-border`:`border-z-border shadow-sm`)}),(0,Q.jsx)(Hn,{icon:(0,Q.jsx)(o,{size:12}),label:`Remove`,onClick:()=>{u(),I(!1)},theme:x,danger:!0})]})}),document.body)]})},Hn=({icon:e,label:t,onClick:n,theme:r,danger:i})=>(0,Q.jsxs)(`button`,{onClick:n,className:Y(`w-full flex items-center gap-3 px-3 py-2 text-sm font-semibold transition-all`,i?`text-rose-500 hover:bg-rose-500/10`:r===`dark`?`text-z-muted hover:bg-z-hover hover:text-z-primary`:`text-z-secondary hover:bg-[var(--z-bg-input)] hover:text-z-primary`),children:[(0,Q.jsx)(`span`,{className:`opacity-60`,children:e}),t]}),Un=({addBlock:e})=>{let{blockPickerOpen:t,setBlockPickerOpen:n,openComponentPicker:r}=dt(W(e=>({blockPickerOpen:e.blockPickerOpen,setBlockPickerOpen:e.setBlockPickerOpen,openComponentPicker:e.openComponentPicker})));return(0,Z.useEffect)(()=>{t&&(r(t=>{e(t)}),n(!1))},[t]),null},Wn=e=>(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:(0,Q.jsx)(`path`,{d:`M22 4s-.7 2.1-2 3.4c1.6 10-9.4 17.3-18 11.6 2.2.1 4.4-.6 6-2C3 15.5.5 9.6 3 5c2.2 2.6 5.6 4.1 9 4-.9-4.2 4-6.6 7-3.8 1.1 0 3-1.2 3-1.2z`})}),Gn=e=>(0,Q.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,stroke:`currentColor`,strokeWidth:`2`,fill:`none`,strokeLinecap:`round`,strokeLinejoin:`round`,...e,children:(0,Q.jsx)(`path`,{d:`M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z`})}),Kn=[`title`,`description`,`keywords`],qn=({onSave:e})=>{let{theme:t}=K(),{data:n,updateData:r}=$(),{seoOpen:i,setSeoOpen:a}=dt(W(e=>({seoOpen:e.seoOpen,setSeoOpen:e.setSeoOpen}))),o=localStorage.getItem(`activeSiteSlug`),[s,c]=(0,Z.useState)({title:``,description:``,keywords:``}),[l,u]=(0,Z.useState)(`google`),[d,f]=(0,Z.useState)({}),m=async e=>{f(t=>({...t,[e]:!0}));try{let t=it(n?.sections);if(!t)throw Error(`No content available to analyze`);let r;e===`description`?(r=await q.post(`/content-tools/ai/meta-description`,{title:s.title||n?.title||`Untitled`,content:t}),r.data?.data?.description&&(O(e,r.data.data.description),fe.success(`Generated description`))):e===`title`?(r=await q.post(`/content-tools/ai/generate`,{prompt:`Write a highly optimized, compelling SEO title (max 60 chars) for this page. The page content is: ${t}. Follow SEO best practices: include the primary keyword near the beginning if possible, keep it engaging but accurate, and avoid clickbait.`}),r.data?.data?.text&&(O(e,r.data.data.text.replace(/["']/g,``).trim()),fe.success(`Generated title`))):e===`keywords`&&(r=await q.post(`/content-tools/ai/generate`,{prompt:`Extract exactly 5 highly relevant SEO keywords as a simple comma-separated list from this content: ${t}. Ensure these are context-based, specific, and reflect the true topic of the page.`}),r.data?.data?.text&&(O(e,r.data.data.text.trim()),fe.success(`Generated keywords`)))}catch(e){fe.error(e?.response?.data?.error?.message||`Failed to generate content`)}finally{f(t=>({...t,[e]:!1}))}},h=o===`blog-demo`?`https://blog-demo.zenith.dev`:o===`storefront-glass`?`https://storefront.zenith.dev`:o===`demo`?`https://demo.zenith.dev`:`https://zenith.dev`,g=n?.title?`${h}/${n.title.toLowerCase().replace(/\s+/g,`-`).replace(/[^a-z0-9-]/g,``)}`:`${h}/page`,_=s.title||n?.title||`Page Title`,v=s.description||n?.heroDescription||`Your page description goes here. This is what search engines will display in search results.`,y=s.keywords||``,b=n?.meta?.ogImage||``,S=e=>e.length,w=(e,t)=>e.length>t?e.slice(0,t)+`…`:e;(0,Z.useEffect)(()=>{i&&c({title:n?.meta?.title||``,description:n?.meta?.description||``,keywords:n?.meta?.keywords||``})},[i,n]);let T=(0,Z.useRef)(null),D=`seo-modal-title`;ut(i,{onEscape:()=>a(!1),containerRef:T});let O=(e,t)=>{c(n=>({...n,[e]:t}))};return(0,Q.jsx)(H,{children:i&&(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[600] flex items-center justify-center p-6 bg-[var(--z-bg-modal)] backdrop-blur-sm`,children:(0,Q.jsxs)(G.div,{ref:T,role:`dialog`,"aria-modal":`true`,"aria-labelledby":D,initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:Y(`w-full max-w-lg border rounded-none-none overflow-hidden shadow-2xl flex flex-col max-h-[85vh]`,t===`dark`?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-center justify-between`,t===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`h3`,{id:D,className:Y(`text-lg font-semibold leading-none`,`text-z-primary`),children:`SEO Meta`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(!1),"aria-label":`Close`,className:`p-1 hover:text-z-secondary transition-colors`,children:(0,Q.jsx)(B,{size:18})})]}),(0,Q.jsxs)(`div`,{className:`p-6 space-y-4 overflow-y-auto flex-1`,children:[(0,Q.jsx)(`div`,{className:`flex items-center gap-1 p-1 border border-z-border bg-z-panel rounded-none-none shrink-0`,children:[{id:`google`,icon:E,label:`Google`},{id:`twitter`,icon:Wn,label:`Twitter / X`},{id:`facebook`,icon:Gn,label:`Facebook`}].map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>u(e.id),"aria-label":`${e.label} preview`,className:Y(`flex items-center gap-2 px-3 py-2 text-xs font-semibold transition-all border rounded-none-none flex-1 justify-center`,l===e.id?t===`dark`?`bg-z-panel/10 border-z-border text-z-primary`:`bg-z-panel border-z-border text-z-primary shadow-sm`:t===`dark`?`text-z-secondary border-transparent hover:text-z-secondary`:`text-z-muted border-transparent hover:text-z-secondary`),children:[(0,Q.jsx)(e.icon,{size:11,"aria-hidden":`true`}),e.label]},e.id))}),(0,Q.jsx)(`div`,{className:Y(`rounded-none-none border overflow-hidden transition-all min-h-[180px]`,t===`dark`?`bg-z-panel/5 border-z-border`:`bg-z-input border-z-border`),children:(0,Q.jsxs)(H,{mode:`wait`,children:[l===`google`&&(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`p-5`,children:(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`div`,{className:`text-xs text-z-secondary truncate`,children:g}),(0,Q.jsx)(`h2`,{className:`text-lg font-normal text-[#1a0dab] leading-5 truncate cursor-pointer hover:underline`,style:{fontFamily:`Arial, sans-serif`},children:_}),(0,Q.jsx)(`p`,{className:`text-[13px] text-z-primary leading-4`,style:{fontFamily:`Arial, sans-serif`},children:w(v,160)}),y&&(0,Q.jsx)(`div`,{className:`flex gap-1 flex-wrap mt-1.5`,children:y.split(`,`).slice(0,4).map((e,t)=>(0,Q.jsx)(`span`,{className:`text-xs px-1.5 py-0.5 border border-z-border-strong rounded-none text-z-secondary`,children:e.trim()},t))})]})},`google`),l===`twitter`&&(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`p-5`,children:(0,Q.jsxs)(`div`,{className:Y(`border rounded-none shadow-sm overflow-hidden max-w-[400px]`,t===`dark`?`bg-[#15202b] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,Q.jsx)(`div`,{className:`w-8 h-8 rounded-none-none bg-z-border flex items-center justify-center text-z-primary text-xs font-semibold shrink-0`,children:`Z`}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold`,`text-z-primary`),children:`Zenith CMS`}),(0,Q.jsx)(`span`,{className:Y(`text-xs`,`text-z-secondary`),children:`@zenith·now`})]}),(0,Q.jsx)(`span`,{className:Y(`text-xs`,`text-z-secondary`),children:g})]})]}),(0,Q.jsx)(`div`,{className:Y(`px-3 pb-2 text-sm leading-4 font-normal`,`text-z-primary`),children:_}),(0,Q.jsx)(`div`,{className:`w-full bg-cover bg-center border-t border-b`,style:{backgroundImage:`url(${b})`,height:`157px`,borderColor:`var(--z-border)`}})]})},`twitter`),l===`facebook`&&(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`p-5`,children:(0,Q.jsxs)(`div`,{className:Y(`border rounded-none shadow-sm overflow-hidden max-w-[400px]`,t===`dark`?`bg-[#1c1e21] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsx)(`div`,{className:`w-full bg-cover bg-center`,style:{backgroundImage:`url(${b})`,height:`180px`}}),(0,Q.jsxs)(`div`,{className:Y(`p-3 border-t`,t===`dark`?`bg-[#242526] border-z-border`:`bg-z-input border-z-border`),children:[(0,Q.jsx)(`div`,{className:`text-xs font-semibold text-z-muted mb-1`,children:h.replace(/^https?:\/\//,``)}),(0,Q.jsx)(`div`,{className:Y(`text-[13px] font-bold leading-4 line-clamp-2 mb-1`,`text-z-primary`),style:{fontFamily:`Helvetica, Arial, sans-serif`},children:_}),(0,Q.jsx)(`div`,{className:Y(`text-sm leading-3 line-clamp-2`,t===`dark`?`text-z-muted`:`text-z-secondary`),style:{fontFamily:`Helvetica, Arial, sans-serif`},children:w(v,100)})]})]})},`facebook`)]})}),Kn.map(e=>(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`label`,{htmlFor:`seo-${e}`,className:`text-xs font-semibold text-z-secondary px-1`,children:X(e)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>m(e),disabled:d[e],title:`Auto-generate ${e} with AI`,className:`text-z-muted hover:text-indigo-500 transition-colors disabled:opacity-50`,children:d[e]?(0,Q.jsx)(C,{size:12,className:`animate-spin`}):(0,Q.jsx)(P,{size:12})})]}),e===`description`&&(0,Q.jsxs)(`span`,{className:Y(`text-xs font-semibold `,S(s.description)>155?`text-rose-500`:`text-z-secondary`),children:[S(s.description),` / 155`]}),e===`title`&&(0,Q.jsxs)(`span`,{className:Y(`text-xs font-semibold `,S(s.title)>60?`text-rose-500`:`text-z-secondary`),children:[S(s.title),` / 60`]})]}),e===`description`?(0,Q.jsx)(`textarea`,{id:`seo-${e}`,value:s[e],onChange:t=>O(e,t.target.value),className:Y(`w-full rounded-none-none py-3 px-4 text-xs font-semibold h-24 resize-none transition-all border`,t===`dark`?`bg-z-hover border-z-border text-z-primary focus-visible:border-z-border/30`:`bg-z-input border-z-border text-z-primary focus-visible:border-z-border/30`),placeholder:`Enter page description...`}):(0,Q.jsx)(`input`,{id:`seo-${e}`,type:`text`,value:s[e],onChange:t=>O(e,t.target.value),className:Y(`w-full rounded-none-none py-3 px-4 text-xs font-semibold transition-all border`,t===`dark`?`bg-z-hover border-z-border text-z-primary focus-visible:border-z-border/30`:`bg-z-input border-z-border text-z-primary focus-visible:border-z-border/30`),placeholder:e===`title`?`Enter SEO title...`:`Enter keywords (comma separated)...`})]},e))]}),(0,Q.jsxs)(`div`,{className:Y(`p-4 border-t flex items-center justify-between shrink-0`,t===`dark`?`border-z-border bg-z-panel`:`border-z-border shadow-sm bg-[var(--z-bg-input)]`),children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{c({title:``,description:``,keywords:``})},"aria-label":`Reset SEO fields`,className:Y(`flex items-center gap-2 px-4 py-2 text-xs font-semibold rounded-none-none border transition-all`,t===`dark`?`border-z-border text-z-muted hover:border-rose-500/20 hover:text-rose-400`:`border-z-border text-z-secondary hover:border-rose-200 hover:text-rose-500`),children:[(0,Q.jsx)(x,{size:12}),`Reset`]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(!1),"aria-label":`Cancel and close`,className:Y(`px-4 py-2 text-xs font-semibold rounded-none-none border transition-all`,t===`dark`?`border-z-border text-z-muted hover:border-z-border hover:text-z-primary`:`border-z-border text-z-secondary hover:border-z-border-strong hover:text-z-primary`),children:`Cancel`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:async()=>{r(e=>({...e,meta:{...e.meta||{},...s}})),e&&await e(),a(!1)},"aria-label":`Save SEO and close`,className:`flex items-center gap-2 px-4 py-2 bg-z-accent text-z-primary text-xs font-semibold rounded-none-none hover:bg-z-border transition-all`,children:[(0,Q.jsx)(p,{size:12,"aria-hidden":`true`}),`Save & Close`]})]})]})]})})})},Jn=({selectedSections:e,setSelectedSections:t,applyTemplate:n,deleteTemplate:r,saveAsTemplate:i})=>{let{theme:a}=K(),{templates:s}=$(W(e=>({templates:e.templates}))),{templatesOpen:c,setTemplatesOpen:l}=dt(W(e=>({templatesOpen:e.templatesOpen,setTemplatesOpen:e.setTemplatesOpen}))),u=(0,Z.useRef)(null),d=`templates-modal-title`;return ut(c,{onEscape:()=>l(!1),containerRef:u}),(0,Q.jsx)(H,{children:c&&(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[600] flex items-center justify-center p-6 bg-[var(--z-bg-modal)] backdrop-blur-sm`,children:(0,Q.jsxs)(G.div,{ref:u,role:`dialog`,"aria-modal":`true`,"aria-labelledby":d,initial:{scale:.95,opacity:0,y:20},animate:{scale:1,opacity:1,y:0},exit:{scale:.95,opacity:0},className:Y(`w-full max-w-2xl border rounded-none-none overflow-hidden shadow-2xl`,a===`dark`?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-center justify-between`,a===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`w-8 h-8 rounded-none-none bg-z-accent flex items-center justify-center text-z-primary`,children:(0,Q.jsx)(f,{size:16})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{id:d,className:`text-lg font-semibold leading-none text-z-secondary `,children:`Block Templates`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary`,children:`Save & reuse component combinations`})]})]}),(0,Q.jsx)(`button`,{onClick:()=>l(!1),"aria-label":`Close`,className:`p-1 hover:text-z-secondary transition-colors`,style:{color:a===`dark`?`#fff`:`#000`},children:(0,Q.jsx)(B,{size:18})})]}),(0,Q.jsx)(`div`,{className:`p-6 max-h-[60vh] overflow-y-auto custom-editor-scrollbar`,children:s.length===0?(0,Q.jsxs)(`div`,{className:`py-12 text-center`,children:[(0,Q.jsx)(f,{size:40,className:`mx-auto mb-4 text-z-secondary`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-semibold`,children:`No saved templates yet`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary mt-2`,children:`Select blocks, then save as template from the context menu`})]}):(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:s.map(e=>(0,Q.jsxs)(`div`,{className:Y(`p-4 border rounded-none-none space-y-3 relative group`,a===`dark`?`bg-z-panel border-z-border hover:border-z-border/30`:`bg-z-input border-z-border hover:border-z-border-strong`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary`,children:e.name}),(0,Q.jsxs)(`span`,{className:`text-xs text-z-secondary`,children:[e.content?.sections?.length||e.sections?.length||0,` blocks`]})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`button`,{onClick:()=>n(e),className:`flex-1 py-2 bg-z-accent text-z-primary text-xs font-semibold rounded-none-none hover:bg-z-border transition-colors`,children:`Apply`}),(0,Q.jsx)(`button`,{onClick:async()=>{await lt({message:`Delete template "${e.name}"? This cannot be undone.`})&&(r(e.id||e._id),l(!1),setTimeout(()=>l(!0),50))},"aria-label":`Delete template ${e.name}`,className:Y(`p-2 border rounded-none-none transition-colors`,a===`dark`?`border-z-border text-z-secondary hover:border-rose-500/30 hover:text-rose-500`:`border-z-border text-z-muted hover:border-rose-300 hover:text-rose-500`),children:(0,Q.jsx)(o,{size:12})})]})]},e.id||e._id))})}),e.size>0&&(0,Q.jsxs)(`div`,{className:Y(`p-4 border-t flex items-center justify-between`,a===`dark`?`border-z-border bg-z-panel`:`border-z-border shadow-sm bg-[var(--z-bg-input)]/50`),children:[(0,Q.jsxs)(`span`,{className:`text-xs text-z-secondary font-semibold`,children:[e.size,` block`,e.size>1?`s`:``,` selected`]}),(0,Q.jsxs)(`button`,{onClick:()=>{i(Array.from(e)),t(new Set)},"aria-label":`Save selection as template`,className:`flex items-center gap-2 px-4 py-2 bg-z-accent text-z-primary text-xs font-semibold rounded-none-none hover:bg-z-border transition-colors`,children:[(0,Q.jsx)(I,{size:12,"aria-hidden":`true`}),`Save as Template`]})]})]})})})},Yn=()=>{let{theme:e}=K(),{selectedRelations:t,setSelectedRelations:n,availableCollections:r,relationsSearch:i,setRelationsSearch:a,relationResults:o,setRelationResults:s,relationsField:c,fieldSettings:l,updateData:u}=$(W(e=>({selectedRelations:e.selectedRelations,setSelectedRelations:e.setSelectedRelations,availableCollections:e.availableCollections,relationsSearch:e.relationsSearch,setRelationsSearch:e.setRelationsSearch,relationResults:e.relationResults,setRelationResults:e.setRelationResults,relationsField:e.relationsField,fieldSettings:e.fieldSettings,updateData:e.updateData}))),{relationsModalOpen:d,setRelationsModalOpen:f}=dt(W(e=>({relationsModalOpen:e.relationsModalOpen,setRelationsModalOpen:e.setRelationsModalOpen}))),[p,m]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(``),v=(0,Z.useRef)(null),y=(0,Z.useCallback)(async(e,t)=>{try{let n={limit:20};t&&(n.search=t),s((await q.get(`/${e}`,{params:n})).data.data||[])}catch{U.error(`Failed to load relation entries`)}},[s]);(0,Z.useEffect)(()=>{if(!d)return;let e=Object.values(l).find(e=>!!e.relationTo)?.relationTo;if(e){let t=Array.isArray(e)?e[0]:e;m(t),y(t,g)}},[d]),(0,Z.useEffect)(()=>(v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{_(i),p&&y(p,i)},300),()=>{v.current&&clearTimeout(v.current)}),[i,p,y]);let b=e=>{m(e.slug),y(e.slug,g)},x=e=>{let r=new Set(t);r.has(e)?r.delete(e):r.add(e),n(r)},S=()=>{c&&(u(e=>{let n=[...e.sections],r=n.findIndex(e=>e.id===c.sectionId);return r!==-1&&(n[r].content[c.fieldKey]=Array.from(t)),{...e,sections:n}}),f(!1),U.success(`${t.size} items linked`))},C=(0,Z.useRef)(null),w=`relations-modal-title`;return ut(d,{onEscape:()=>f(!1),containerRef:C}),(0,Q.jsx)(H,{children:d&&(0,Q.jsxs)(`div`,{className:`fixed inset-0 z-[700]`,children:[(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:()=>f(!1),className:`absolute inset-0 bg-app/70 backdrop-blur-md`}),(0,Q.jsxs)(G.div,{ref:C,role:`dialog`,"aria-modal":`true`,"aria-labelledby":w,initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.9,opacity:0},className:Y(`absolute inset-4 md:inset-10 border rounded-xl shadow-2xl flex flex-col overflow-hidden`,e===`dark`?`bg-app/65 backdrop-blur-xl border-z-border`:`bg-z-panel/95 backdrop-blur-xl border-z-border shadow-2xl`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-start justify-between shrink-0`,`border-z-border`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:Y(`w-10 h-10 rounded-lg flex items-center justify-center border`,e===`dark`?`bg-z-panel/10 border-z-border`:`bg-[var(--z-bg-hover)] border-z-border`),children:(0,Q.jsx)(ye,{size:18,className:`text-z-primary`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{id:w,className:Y(`text-lg font-semibold`,`text-z-primary`),children:`Content Relations`}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-bold`,`text-z-muted`),children:`Connect entries from other collections`})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-xs text-z-muted font-mono`,children:[t.size,` selected`]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>f(!1),"aria-label":`Close`,className:Y(`p-2 rounded-xl border transition-all`,e===`dark`?`bg-z-panel/5 border-z-border text-z-primary hover:bg-[var(--z-bg-hover)]`:`bg-[var(--z-bg-input)] border-z-border text-z-secondary hover:bg-[var(--z-bg-hover)]`),children:(0,Q.jsx)(B,{size:16})})]})]}),(0,Q.jsx)(`div`,{className:Y(`p-4 border-b flex gap-2 overflow-x-auto`,e===`dark`?`border-z-border bg-z-panel/5`:`border-z-border bg-[var(--z-bg-input)]/50`),children:r.map(t=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>b(t),className:Y(`px-3 py-1.5 text-xs font-semibold rounded-lg border shrink-0 transition-all`,p===t.slug?e===`dark`?`bg-z-panel/20 border-z-border text-z-primary`:`bg-[var(--z-border)] border-[var(--z-border-strong)] text-z-primary`:e===`dark`?`border-z-border text-z-muted hover:border-z-border hover:text-z-primary`:`border-z-border text-z-muted hover:border-[var(--z-border-strong)] hover:text-z-primary`),children:t.label||t.slug},t.slug))}),(0,Q.jsx)(`div`,{className:`p-4 shrink-0`,children:(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(h,{size:14,className:`absolute left-4 top-1/2 -translate-y-1/2 text-z-muted`}),(0,Q.jsx)(`input`,{type:`text`,"aria-label":`Search relation entries`,placeholder:`Search entries to link...`,value:i,onChange:e=>a(e.target.value),className:Y(`w-full rounded-lg py-3 pl-12 pr-4 text-xs font-bold border transition-colors`,e===`dark`?`bg-app/20 border-z-border text-z-primary focus-visible:border-z-border`:`bg-z-panel border-z-border text-z-primary focus-visible:border-z-border`)})]})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-4 custom-editor-scrollbar`,children:p?o.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4`,children:[(0,Q.jsx)(h,{size:32,className:Y(`opacity-20`,`text-z-primary`)}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-semibold text-center`,`text-z-muted`),children:g?`No entries match your search`:`No entries found in this collection`})]}):(0,Q.jsx)(`div`,{className:`space-y-1`,children:o.map(n=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>x(n.id||n._id),className:Y(`w-full flex items-center gap-3 p-3 rounded-lg border transition-all text-left`,t.has(n.id||n._id)?e===`dark`?`bg-z-panel/10 border-z-border`:`bg-[var(--z-bg-hover)] border-[var(--z-border-strong)]`:e===`dark`?`bg-app/20 border-z-border hover:border-z-border`:`bg-z-panel border-z-border hover:border-[var(--z-border-strong)]`),children:[(0,Q.jsx)(`div`,{className:Y(`w-5 h-5 rounded border-2 flex items-center justify-center shrink-0 transition-all`,t.has(n.id||n._id)?`bg-indigo-500 border-indigo-500`:e===`dark`?`border-z-border`:`border-[var(--z-border-strong)] bg-[var(--z-bg-input)]`),children:t.has(n.id||n._id)&&(0,Q.jsx)(z,{size:12,className:`text-z-primary`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:Y(`text-xs font-semibold truncate`,`text-z-primary`),children:n.title||n.name||n.headline||n.id}),(0,Q.jsxs)(`p`,{className:Y(`text-sm font-mono truncate`,`text-z-muted`),children:[`ID: `,n.id||n._id]})]}),(0,Q.jsx)(`span`,{className:Y(`text-sm font-mono shrink-0`,`text-z-muted`),children:n._status||n.status||`active`})]},n.id||n._id))}):(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4`,children:[(0,Q.jsx)(j,{size:40,className:Y(`opacity-20`,`text-z-primary`)}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-semibold text-center`,`text-z-muted`),children:`Select a collection above to view entries`})]})}),(0,Q.jsxs)(`div`,{className:Y(`p-4 border-t flex items-center justify-between`,e===`dark`?`border-z-border bg-app/20`:`border-z-border bg-[var(--z-bg-input)]/50`),children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-bold`,`text-z-muted`),children:`Click entries to select/deselect for relation`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>f(!1),className:Y(`px-4 py-2 text-xs font-semibold rounded-lg border transition-all`,e===`dark`?`border-z-border text-z-muted hover:border-z-border hover:text-z-primary`:`border-z-border text-z-secondary hover:border-z-border hover:text-z-primary`),children:`Cancel`}),(0,Q.jsxs)(`button`,{type:`button`,onClick:S,disabled:t.size===0,className:`px-4 py-2 bg-z-accent text-z-logo-text text-xs font-semibold rounded-lg hover:opacity-80 transition-all disabled:opacity-50`,children:[`Link `,t.size,` items`]})]})]})]})]})})},Xn=e=>e.url?e.url.startsWith(`http`)?e.url:`${e.url}`:``,Zn=()=>{let{theme:e}=K(),{mediaLibraryOpen:t,setMediaLibraryOpen:n}=dt(W(e=>({mediaLibraryOpen:e.mediaLibraryOpen,setMediaLibraryOpen:e.setMediaLibraryOpen}))),{mediaAssets:r,setMediaAssets:i,mediaSearch:a,setMediaSearch:o,mediaTypeFilter:s,setMediaTypeFilter:c,mediaLoading:l,setMediaLoading:u}=$(W(e=>({mediaAssets:e.mediaAssets,setMediaAssets:e.setMediaAssets,mediaSearch:e.mediaSearch,setMediaSearch:e.setMediaSearch,mediaTypeFilter:e.mediaTypeFilter,setMediaTypeFilter:e.setMediaTypeFilter,mediaLoading:e.mediaLoading,setMediaLoading:e.setMediaLoading})));Z.useEffect(()=>{t&&(o(``),c(`all`),u(!0),q.get(`/media`).then(e=>{i(e.data.data||[])}).catch(()=>{}).finally(()=>{u(!1)}))},[t,i,u,o,c]);let f=(0,Z.useMemo)(()=>r.filter(e=>{let t=!a||e.name?.toLowerCase().includes(a.toLowerCase())||e.alt?.toLowerCase().includes(a.toLowerCase())||e.url?.toLowerCase().includes(a.toLowerCase()),n=e.mimetype||``,r=s===`all`||s===`image`&&n.startsWith(`image/`)||s===`video`&&n.startsWith(`video/`)||s===`audio`&&n.startsWith(`audio/`)||s===`application/pdf`&&n.includes(`pdf`)||s===`other`&&!n.startsWith(`image/`)&&!n.startsWith(`video/`)&&!n.startsWith(`audio/`)&&!n.includes(`pdf`);return t&&r}),[r,a,s]),p=(0,Z.useRef)(null),m=`media-library-modal-title`;return ut(t,{onEscape:()=>n(!1),containerRef:p}),(0,Q.jsx)(H,{children:t&&(0,Q.jsxs)(`div`,{className:`fixed inset-0 z-[900] flex items-center justify-center p-4 md:p-10`,children:[(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:()=>n(!1),className:`absolute inset-0 bg-[var(--z-bg-modal)] backdrop-blur-md`}),(0,Q.jsxs)(G.div,{ref:p,role:`dialog`,"aria-modal":`true`,"aria-labelledby":m,initial:{scale:.95,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.95,opacity:0},className:Y(`w-full max-w-6xl border rounded-none-none overflow-hidden shadow-2xl flex flex-col h-[85vh]`,e===`dark`?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-center justify-between shrink-0`,e===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`h3`,{id:m,className:Y(`text-lg font-semibold leading-none`,`text-z-primary`),children:`Asset Registry`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>n(!1),"aria-label":`Close`,className:Y(`p-1 transition-colors`,e===`dark`?`text-z-muted hover:text-z-secondary `:`text-z-secondary hover:text-z-secondary`),children:(0,Q.jsx)(B,{size:18})})]}),(0,Q.jsxs)(`div`,{className:Y(`flex items-center gap-4 px-8 py-4 border-b shrink-0`,e===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsxs)(`div`,{className:`relative group flex-1`,children:[(0,Q.jsx)(h,{className:Y(`absolute left-4 top-1/2 -translate-y-1/2 transition-colors`,e===`dark`?`text-z-secondary group-focus-within:text-z-secondary`:`text-z-muted group-focus-within:text-z-secondary`),size:15}),(0,Q.jsx)(`input`,{type:`text`,"aria-label":`Search assets`,placeholder:`Search assets by name or type...`,value:a,onChange:e=>o(e.target.value),className:Y(`w-full rounded-none-none pl-12 pr-4 py-3 text-xs font-bold transition-all`,e===`dark`?`bg-z-hover border border-z-border text-z-primary placeholder:text-z-secondary focus-visible:border-z-border/40 focus-visible:bg-z-panel/[0.05]`:`bg-[var(--z-bg-input)] border border-z-border text-z-primary placeholder:text-z-muted focus-visible:border-z-border focus-visible:bg-z-panel`)})]}),(0,Q.jsxs)(`select`,{"aria-label":`Filter by file type`,value:s,onChange:e=>c(e.target.value),className:Y(`rounded-none-none border py-3 px-4 text-xs font-semibold transition-all`,e===`dark`?`bg-z-hover border-z-border text-z-muted focus-visible:border-z-border/40`:`bg-[var(--z-bg-hover)] border-z-border text-z-secondary focus-visible:border-z-border`),children:[(0,Q.jsx)(`option`,{value:`all`,children:`All Types`}),(0,Q.jsx)(`option`,{value:`image`,children:`Images`}),(0,Q.jsx)(`option`,{value:`video`,children:`Video`}),(0,Q.jsx)(`option`,{value:`audio`,children:`Audio`}),(0,Q.jsx)(`option`,{value:`application/pdf`,children:`PDF`}),(0,Q.jsx)(`option`,{value:`other`,children:`Other`})]}),(0,Q.jsxs)(`label`,{className:Y(`flex items-center gap-2 px-5 py-3 rounded-none-none border cursor-pointer transition-all text-xs font-semibold `,e===`dark`?`bg-z-accent/20 border-z-border/30 text-z-secondary hover:bg-z-accent/30 hover:border-z-border/50`:`bg-z-input border-z-border text-z-primary hover:bg-[var(--z-bg-hover)] hover:border-z-border-strong`),children:[(0,Q.jsx)(tt,{size:14}),`Ingest`,(0,Q.jsx)(`input`,{type:`file`,className:`hidden`,onChange:async e=>{let t=e.target.files?.[0];if(!t)return;let n=new FormData;n.append(`file`,t);try{i([(await q.post(`/upload`,n,{headers:{"Content-Type":`multipart/form-data`}})).data.data,...r]),U.success(`"${t.name}" ingested`)}catch{U.error(`Upload failed`)}}})]})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:l?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-5`,children:[(0,Q.jsx)(C,{size:36,className:`animate-spin text-z-secondary `}),(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary animate-pulse`,children:`Loading Registry...`})]}):r.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full gap-4 text-center`,children:[(0,Q.jsx)(`div`,{className:Y(`w-16 h-16 rounded-none-none border-2 border-dashed flex items-center justify-center`,`border-z-border text-z-secondary`),children:(0,Q.jsx)(d,{size:28})}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-semibold `,`text-z-secondary`),children:`No assets in the registry`}),(0,Q.jsx)(`span`,{className:Y(`text-xs font-bold `,e===`dark`?`text-z-primary`:`text-z-secondary`),children:`Upload files using the ingest button above`})]}):f.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-40 gap-3`,children:[(0,Q.jsx)(h,{size:28,className:e===`dark`?`text-z-primary`:`text-z-secondary`}),(0,Q.jsx)(`span`,{className:Y(`text-xs font-semibold `,`text-z-secondary`),children:`No assets match your filter`})]}):(0,Q.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 xl:grid-cols-8 gap-4`,children:f.map((t,r)=>{let i=(t.mimetype||``).startsWith(`image/`),a=Xn(t);return(0,Q.jsxs)(G.div,{role:`button`,tabIndex:0,"aria-label":`Asset: ${t.name}${t.mimetype?`, ${t.mimetype.split(`/`)[1]?.toUpperCase()}`:``}. Press Enter to copy URL.`,initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{delay:Math.min(r*.015,1)},className:`group relative aspect-square border rounded-none-none overflow-hidden cursor-pointer transition-all hover:scale-[1.04] hover:z-10`,onClick:()=>{navigator.clipboard.writeText(a).catch(()=>{}),U.success(`URL copied to clipboard`)},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),navigator.clipboard.writeText(a).catch(()=>{}),U.success(`URL copied to clipboard`))},children:[i?(0,Q.jsx)(`img`,{src:a,alt:t.alt||t.name||``,className:`w-full h-full object-cover`,loading:`lazy`}):(0,Q.jsxs)(`div`,{className:Y(`w-full h-full flex flex-col items-center justify-center gap-2`,e===`dark`?`bg-z-hover`:`bg-[var(--z-bg-input)]`),children:[(0,Q.jsx)(_,{size:24,className:`text-z-secondary`}),(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold text-center px-1 truncate w-full`,`text-z-secondary`),children:(t.mimetype||`file`).split(`/`)[1]?.toUpperCase().slice(0,4)||`FILE`})]}),(0,Q.jsxs)(`div`,{className:Y(`absolute inset-0 flex flex-col items-start justify-end p-2 opacity-0 group-hover:opacity-100 transition-opacity`,`bg-gradient-to-t from-[var(--z-bg-panel)] via-[var(--z-bg-base)]`),children:[(0,Q.jsx)(`p`,{className:`text-z-primary text-xs font-semibold truncate w-full leading-tight`,children:t.name}),t.size&&(0,Q.jsxs)(`span`,{className:`text-z-primary/50 text-xs font-bold`,children:[(t.size/1024).toFixed(1),` KB`]}),(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),navigator.clipboard.writeText(a),U.success(`URL copied`)},className:Y(`mt-1.5 px-2 py-1 rounded-none-none border text-xs font-semibold transition-all`,e===`dark`?`border-z-border text-z-primary/70 hover:border-z-border hover:text-z-primary bg-z-hover`:`border-z-border text-z-primary/80 hover:border-z-border0 hover:text-z-primary bg-z-panel/10`),children:`Copy URL`}),(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),window.dispatchEvent(new CustomEvent(`zenith:media-selected`,{detail:{url:a,alt:t.alt||t.name||``,mimeType:t.mimetype||`image/jpeg`,width:t.width,height:t.height}})),n(!1),U.success(`Media selected`)},className:Y(`mt-1 px-2 py-1 rounded-none-none border text-xs font-semibold transition-all`,`border-z-border/40 text-z-secondary hover:border-z-border hover:text-z-secondary bg-z-panel`),children:`Select`})]}),(0,Q.jsx)(`div`,{className:Y(`absolute top-1.5 left-1.5 px-1.5 py-0.5 text-sm font-semibold border rounded-none-none`,e===`dark`?`bg-app/60 border-z-border text-z-muted`:`bg-z-panel/80 border-z-border text-z-secondary`),children:(t.mimetype||`file`).split(`/`)[1]?.toUpperCase().slice(0,4)||`FILE`})]},t._id||r)})})}),(0,Q.jsxs)(`div`,{className:Y(`flex items-center justify-between px-8 py-3 border-t shrink-0`,e===`dark`?`border-z-border bg-z-panel/[0.015]`:`border-z-border shadow-sm bg-[var(--z-bg-input)]`),children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-bold `,e===`dark`?`text-z-secondary`:`text-z-muted`),children:`Click any asset to copy its URL • Supports images, video, audio, PDF`}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>n(!1),"aria-label":`Close media library`,className:Y(`px-5 py-2 text-xs font-semibold rounded-none-none border transition-all`,e===`dark`?`border-z-border text-z-muted hover:border-z-border hover:text-z-primary`:`border-z-border text-z-secondary hover:border-z-border-strong hover:text-z-primary`),children:`Close`})]})]})]})})},Qn=({item:e,idx:t,theme:n,removeFromDynamicZone:r})=>{let i=Ne();return(0,Q.jsxs)(V,{value:e,dragListener:!1,dragControls:i,as:`div`,className:Y(`flex items-center gap-3 p-3 rounded-none-none border group`,n===`dark`?`bg-z-hover border-z-border hover:border-z-border/20`:`bg-z-input border-z-border hover:border-z-border`),children:[(0,Q.jsx)(`div`,{onPointerDown:e=>i.start(e),className:`cursor-grab active:cursor-grabbing shrink-0`,children:(0,Q.jsx)(Ee,{size:12,className:`text-z-secondary`})}),(0,Q.jsx)(`div`,{className:`w-6 h-6 rounded-none-none bg-z-panel flex items-center justify-center shrink-0`,children:(0,Q.jsx)(f,{size:12,className:`text-z-secondary`})}),(0,Q.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,Q.jsx)(`p`,{className:`text-xs font-semibold truncate`,children:X(e.__component?.replace(`content.`,``)||e.__component||`Component`)})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r(t),"aria-label":`Remove component ${t+1}`,className:`p-1 text-z-secondary hover:text-rose-500 transition-colors opacity-0 group-hover:opacity-100 shrink-0`,children:(0,Q.jsx)(o,{size:12,"aria-hidden":`true`})})]})},$n=({dynamicZoneModalOpen:e,setDynamicZoneModalOpen:t,activeDynamicZone:n,addToDynamicZone:r,removeFromDynamicZone:i,onReorder:a})=>{let{theme:o}=K(),{data:s}=$(W(e=>({data:e.data}))),c=s,l=st(),[u,d]=(0,Z.useState)(``),f=(0,Z.useRef)(null),p=`dynamic-zone-modal-title`;ut(e,{onEscape:()=>t(!1),containerRef:f});let m=(0,Z.useMemo)(()=>{if(!u.trim())return l;let e=u.toLowerCase();return l.filter(t=>t.title.toLowerCase().includes(e)||t.type.toLowerCase().includes(e)||t.description.toLowerCase().includes(e))},[l,u]);return(0,Q.jsx)(H,{children:e&&(0,Q.jsxs)(`div`,{className:`fixed inset-0 z-[700]`,children:[(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},onClick:()=>t(!1),className:`absolute inset-0 bg-app/70 backdrop-blur-md`}),(0,Q.jsxs)(G.div,{ref:f,role:`dialog`,"aria-modal":`true`,"aria-labelledby":p,initial:{scale:.9,opacity:0},animate:{scale:1,opacity:1},exit:{scale:.9,opacity:0},className:Y(`absolute right-0 top-0 bottom-0 w-[450px] border-l shadow-2xl flex flex-col overflow-hidden`,o===`dark`?`bg-[#060606] border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsxs)(`div`,{className:Y(`p-6 border-b flex items-center justify-between`,o===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`w-8 h-8 rounded-none-none bg-z-accent/20 border border-z-border/30 flex items-center justify-center`,children:(0,Q.jsx)(N,{size:16,className:`text-z-secondary`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{id:p,className:`text-base font-semibold text-z-secondary leading-none`,children:`Dynamic Zone`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-bold mt-1`,children:`Add/arrange component blocks`})]})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>t(!1),"aria-label":`Close`,className:Y(`p-1.5 rounded-none-none border transition-all`,o===`dark`?`bg-z-hover border-z-border hover:bg-z-panel hover:text-z-primary`:`bg-[var(--z-bg-hover)] border-z-border hover:bg-app hover:text-z-primary`),children:(0,Q.jsx)(B,{size:14})})]}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-4 custom-editor-scrollbar space-y-4`,children:[n&&(()=>{let e=(c?.sections?.find(e=>e.id===n.sectionId))?.content?.[n.fieldKey]||[];return e.length>0?(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsxs)(`p`,{className:`text-xs font-semibold text-z-secondary px-1`,children:[`Zone Contents (`,e.length,`)`]}),(0,Q.jsx)(qe,{axis:`y`,values:e,onReorder:e=>a?.(n.sectionId,n.fieldKey,e),className:`space-y-2`,children:e.map((e,t)=>(0,Q.jsx)(Qn,{item:e,idx:t,theme:o,removeFromDynamicZone:i},e.id||t))})]}):(0,Q.jsxs)(`div`,{className:`text-center py-6`,children:[(0,Q.jsx)(_e,{size:24,className:`mx-auto text-z-secondary mb-2`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary font-bold`,children:`Zone is empty — add components below`})]})})(),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold text-z-secondary px-1`,children:`Available Components`}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(h,{size:12,className:Y(`absolute left-3 top-1/2 -translate-y-1/2`,`text-z-secondary`)}),(0,Q.jsx)(`input`,{type:`text`,value:u,onChange:e=>d(e.target.value),placeholder:`Search components...`,className:Y(`w-full pl-8 pr-3 py-2 text-xs font-bold border rounded-none-none bg-transparent`,`border-z-border text-z-primary placeholder:text-z-muted focus:border-z-border/30`)})]}),(0,Q.jsx)(`div`,{className:`max-h-64 overflow-y-auto space-y-1.5 custom-editor-scrollbar`,children:m.length===0?(0,Q.jsx)(`p`,{className:Y(`text-xs font-bold text-center py-4`,`text-z-secondary`),children:`No components match your search`}):m.map(e=>{let t=e.icon;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>r(e.type),"aria-label":`Add ${e.title} to dynamic zone`,className:Y(`w-full flex items-center gap-3 p-3 rounded-none-none border transition-all text-left`,o===`dark`?`bg-z-panel border-z-border hover:border-z-border/30 hover:bg-z-hover`:`bg-z-input border-z-border hover:border-z-border-strong hover:bg-[var(--z-bg-input)]`),children:[(0,Q.jsx)(`div`,{className:`w-8 h-8 rounded-none-none bg-z-panel flex items-center justify-center shrink-0`,children:(0,Q.jsx)(t,{size:14,className:`text-z-secondary`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold truncate`,children:e.title}),(0,Q.jsx)(`p`,{className:Y(`text-sm font-bold truncate`,`text-z-secondary`),children:e.description})]}),(0,Q.jsx)(Be,{size:14,"aria-hidden":`true`,className:`text-z-secondary opacity-50 shrink-0`})]},e.type)})})]})]})]})]})})},er=Fe(e=>({workflowStatus:`draft`,publishStatus:`draft`,workflowReviewers:[],scheduledAt:``,workflowComments:[],releases:[],activeRelease:null,setWorkflowStatus:t=>e({workflowStatus:t}),setPublishStatus:t=>e({publishStatus:t}),setWorkflowReviewers:t=>e({workflowReviewers:t}),setScheduledAt:t=>e({scheduledAt:t}),setWorkflowComments:t=>e({workflowComments:t}),setReleases:t=>e({releases:t}),setActiveRelease:t=>e({activeRelease:t})})),tr=Fe((e,t)=>({i18nEnabled:!1,currentLocale:`en`,availableLocales:[{code:`en`,name:`English`,flag:``,default:!0},{code:`es`,name:`Español`,flag:``,default:!1},{code:`fr`,name:`Français`,flag:``,default:!1},{code:`de`,name:`Deutsch`,flag:``,default:!1},{code:`zh`,name:`中文`,flag:``,default:!1},{code:`ja`,name:`日本語`,flag:``,default:!1}],translations:{},setI18nEnabled:t=>e({i18nEnabled:t}),setCurrentLocale:t=>e({currentLocale:t}),setTranslations:t=>e({translations:t}),updateTranslation:(t,n,r)=>e(e=>({translations:{...e.translations,[t]:{...e.translations[t]||{},[n]:r}}})),importLegacyFormat:t=>e(()=>{let e={};for(let[n,r]of Object.entries(t))for(let[t,i]of Object.entries(r))e[t]||(e[t]={}),e[t][n]=i;return{translations:e}}),getLocalizedValue:e=>{let{translations:n,currentLocale:r,availableLocales:i}=t(),a=n[e];if(a)return a[r]??a[i.find(e=>e.default)?.code??`en`]}})),nr=()=>{let{saving:e,hasUnsavedChanges:t}=$(W(e=>({saving:e.saving,hasUnsavedChanges:e.hasUnsavedChanges}))),{theme:n}=K(),r=e?`saving`:t?`unsaved`:`saved`;return(0,Q.jsx)(`div`,{className:`flex items-center select-none font-sans`,children:(0,Q.jsxs)(H,{mode:`wait`,children:[r===`saving`&&(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},className:Y(`px-2.5 py-1 flex items-center gap-1.5 border text-xs font-semibold rounded-none-none`,n===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-secondary`),children:[(0,Q.jsx)(C,{size:11,className:`animate-spin`}),(0,Q.jsx)(`span`,{children:`Saving...`})]},`saving`),r===`unsaved`&&(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},className:Y(`px-2.5 py-1 flex items-center gap-1.5 border text-xs font-semibold rounded-none-none`,n===`dark`?`bg-amber-500/10 border-amber-500/20 text-amber-400`:`bg-amber-50 border-amber-200 text-amber-600`),children:[(0,Q.jsx)(ie,{size:11,className:`animate-pulse`}),(0,Q.jsx)(`span`,{children:`Unsaved`})]},`unsaved`),r===`saved`&&(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.9},className:Y(`px-2.5 py-1 flex items-center gap-1.5 border text-xs font-semibold rounded-none-none`,n===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-secondary`),children:[(0,Q.jsx)(z,{size:11,className:`text-z-secondary `}),(0,Q.jsx)(`span`,{children:`Saved`})]},`saved`)]})})},rr=({open:e,onClose:t})=>{let{theme:n}=K(),{scheduledAt:r,setScheduledAt:i}=er(W(e=>({scheduledAt:e.scheduledAt,setScheduledAt:e.setScheduledAt}))),[a,o]=(0,Z.useState)(``),s=(0,Z.useRef)(null);return(0,Z.useEffect)(()=>{if(e)if(r)o(new Date(r).toISOString().slice(0,16));else{let e=new Date;e.setDate(e.getDate()+1),e.setHours(9,0,0,0),o(e.toISOString().slice(0,16))}},[e,r]),(0,Z.useEffect)(()=>{if(!e)return;let n=e=>{s.current&&!s.current.contains(e.target)&&t()};return document.addEventListener(`mousedown`,n),()=>document.removeEventListener(`mousedown`,n)},[e,t]),e?(0,Q.jsxs)(`div`,{ref:s,className:Y(`absolute top-full mt-2 right-0 w-64 border shadow-2xl z-50 p-3`,n===`dark`?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),onClick:e=>e.stopPropagation(),children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,Q.jsx)(`span`,{className:Y(`text-xs font-semibold `,n===`dark`?`text-z-muted`:`text-z-secondary`),children:`Schedule Publish`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[r&&(0,Q.jsx)(`button`,{onClick:()=>{i(``),t()},className:`text-xs font-semibold text-red-400 hover:text-red-300`,children:`Clear`}),(0,Q.jsx)(`button`,{onClick:t,"aria-label":`Close scheduler`,className:Y(`p-0.5`,n===`dark`?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`),children:(0,Q.jsx)(B,{size:12,"aria-hidden":`true`})})]})]}),(0,Q.jsx)(`input`,{type:`datetime-local`,value:a,onChange:e=>o(e.target.value),className:Y(`w-full px-2 py-1.5 rounded-none-none border text-xs font-mono`,n===`dark`?`bg-z-hover border-z-border text-z-primary`:`bg-z-input border-z-border text-z-primary`)}),(0,Q.jsxs)(`div`,{className:`flex gap-2 mt-2`,children:[(0,Q.jsx)(`button`,{onClick:t,className:Y(`flex-1 py-1.5 border text-xs font-semibold text-center transition-all`,n===`dark`?`border-z-border text-z-muted hover:bg-z-hover`:`border-z-border text-z-secondary hover:bg-[var(--z-bg-input)]`),children:`Cancel`}),(0,Q.jsx)(`button`,{onClick:()=>{if(!a)return;let e=new Date(a).toISOString();i(e),er.getState().setWorkflowStatus(`scheduled`),$.getState().setHasUnsavedChanges(!0),U.success(`Scheduled for ${new Date(e).toLocaleString()}`,{icon:`⏰`}),t()},disabled:!a,className:Y(`flex-1 py-1.5 text-xs font-semibold text-center transition-all disabled:opacity-40`,`bg-z-accent hover:bg-z-border text-z-primary`),children:`Apply`})]})]}):null},ir=({open:e,onConfirm:t,onCancel:n})=>{let{theme:r}=K();return(0,Vt.createPortal)((0,Q.jsx)(H,{children:e&&(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[800] flex items-center justify-center bg-[var(--z-bg-modal)] backdrop-blur-sm`,children:(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},transition:{duration:.15},className:Y(`w-full max-w-sm border rounded-none-none shadow-2xl p-6`,r===`dark`?`bg-app border-z-border text-z-primary`:`bg-z-panel border-z-border text-z-primary`),children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,Q.jsx)(`div`,{className:Y(`w-10 h-10 rounded-none-none border flex items-center justify-center shrink-0`,r===`dark`?`bg-amber-500/10 border-amber-500/20 text-amber-400`:`bg-amber-50 border-amber-200 text-amber-500`),children:(0,Q.jsx)(u,{size:18})}),(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Publish Document`}),(0,Q.jsx)(`p`,{className:Y(`text-xs font-bold mt-2 leading-relaxed`,r===`dark`?`text-z-muted`:`text-z-secondary`),children:`This will make the content live and visible to all visitors. Are you sure you want to publish?`})]}),(0,Q.jsx)(`button`,{onClick:n,"aria-label":`Close`,className:Y(`shrink-0 p-1 transition-colors`,r===`dark`?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`),children:(0,Q.jsx)(B,{size:16})})]}),(0,Q.jsxs)(`div`,{className:`flex gap-3 mt-5`,children:[(0,Q.jsx)(`button`,{onClick:n,className:Y(`flex-1 py-2.5 text-xs font-semibold border rounded-none-none transition-all`,r===`dark`?`border-z-border text-z-muted hover:border-z-border hover:text-z-primary`:`border-z-border text-z-secondary hover:border-z-border-strong hover:text-z-primary`),children:`Cancel`}),(0,Q.jsxs)(`button`,{onClick:t,className:`flex-1 flex items-center justify-center gap-2 py-2.5 bg-z-accent text-z-primary text-xs font-semibold rounded-none-none hover:bg-z-border transition-all`,children:[(0,Q.jsx)(ze,{size:12}),`Publish Now`]})]})]})})}),document.body)},ar=({open:e,onClose:t})=>{let{theme:n}=K(),r=n===`dark`,{data:i,topLevelFields:a}=$(W(e=>({data:e.data,topLevelFields:e.topLevelFields}))),{availableLocales:o,translations:s,updateTranslation:c}=tr(),[l,u]=(0,Z.useState)(`en`),[d,f]=(0,Z.useState)(`es`),p=st(),m=(0,Z.useMemo)(()=>{let e=[];return a.forEach(t=>{[`text`,`richtext`,`textarea`,`lexical`].includes(t.type)&&e.push({sectionId:`root`,sectionName:`Document Data`,fieldName:t.name,fieldType:t.type,originalValue:i?.[t.name]})}),i?.sections&&i.sections.forEach(t=>{let n=p.find(e=>e.type===t.blockType);n&&n.fields.forEach(n=>{[`text`,`richtext`,`textarea`,`lexical`].includes(n.type)&&e.push({sectionId:t.id,sectionName:t.blockName||t.title||X(t.blockType),fieldName:n.name,fieldType:n.type,originalValue:t.content[n.name]})})}),e},[i,p,a]),h=(0,Z.useMemo)(()=>{if(m.length===0)return 0;let e=0;return m.forEach(t=>{let n=s[t.sectionId===`root`?t.fieldName:`${t.sectionId}.${t.fieldName}`]?.[d];n&&n.trim()!==``&&e++}),Math.round(e/m.length*100)},[m,s,d]);return(0,Vt.createPortal)((0,Q.jsx)(H,{children:e&&(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center p-4 sm:p-6 bg-[var(--z-bg-modal)] backdrop-blur-sm`,children:(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.98,y:15},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.98,y:15},className:Y(`border rounded-none-none w-full max-w-6xl shadow-2xl flex flex-col overflow-hidden max-h-[90vh]`,r?`bg-app border-z-border text-z-primary`:`bg-z-panel border-z-border shadow-sm text-z-primary`),children:[(0,Q.jsxs)(`div`,{className:`p-6 border-b border-z-border dark:border-z-border flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Q.jsx)(`div`,{className:`w-10 h-10 bg-z-accent rounded-none-none flex items-center justify-center text-z-primary shadow-lg shrink-0`,children:(0,Q.jsx)(et,{size:18})}),(0,Q.jsxs)(`div`,{className:`flex flex-col`,children:[(0,Q.jsx)(`h3`,{className:`text-sm font-semibold`,children:`Translation_Engine`}),(0,Q.jsx)(`p`,{className:`text-sm font-bold text-z-muted mt-1`,children:`Side-by-side content localization`})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 w-full sm:w-auto`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 sm:flex-none`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-secondary`,children:`Reference:`}),(0,Q.jsx)(`select`,{value:l,onChange:e=>u(e.target.value),className:Y(`w-32 px-3 py-1.5 text-xs font-bold border rounded-none-none bg-transparent outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black transition-colors appearance-none cursor-pointer`,`border-z-border hover:border-z-border text-z-primary`),children:o.map(e=>(0,Q.jsxs)(`option`,{value:e.code,className:`text-z-primary bg-z-panel`,children:[e.flag,` `,e.name]},e.code))})]}),(0,Q.jsx)(`div`,{className:`text-z-muted`,children:(0,Q.jsx)(E,{size:14})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 flex-1 sm:flex-none`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-bold text-z-secondary `,children:`Target:`}),(0,Q.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),className:Y(`w-32 px-3 py-1.5 text-xs font-bold border rounded-none-none dark:bg-z-panel/5 bg-z-panel outline-none focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:ring-offset-1 focus-visible:ring-offset-black transition-colors appearance-none cursor-pointer`,`border-z-border/30 hover:border-z-border/60 text-z-secondary`),children:o.map(e=>(0,Q.jsxs)(`option`,{value:e.code,className:`text-z-primary bg-z-panel`,children:[e.flag,` `,e.name]},e.code))})]}),(0,Q.jsx)(`button`,{onClick:t,className:`ml-4 p-2 text-z-muted hover:text-z-primary transition-colors`,children:(0,Q.jsx)(B,{size:16})})]})]}),(0,Q.jsx)(`div`,{className:`h-1 bg-[var(--z-bg-hover)] dark:bg-z-hover w-full relative`,children:(0,Q.jsx)(`div`,{className:`absolute left-0 top-0 bottom-0 bg-z-border transition-all duration-500`,style:{width:`${h}%`}})}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-6 space-y-12`,children:m.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-20 text-z-secondary`,children:[(0,Q.jsx)(ie,{size:48,className:`mb-4 opacity-20`}),(0,Q.jsx)(`p`,{className:`text-xs font-bold`,children:`No text fields found to translate.`})]}):m.map((e,t)=>{let r=e.sectionId===`root`?e.fieldName:`${e.sectionId}.${e.fieldName}`,i=s[r]?.[l]||(l===`en`?e.originalValue:``)||``,a=s[r]?.[d]||``;return(0,Q.jsxs)(`div`,{className:`space-y-4 relative`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`w-1.5 h-1.5 bg-z-border rounded-none-none`}),(0,Q.jsxs)(`h4`,{className:`text-sm font-semibold text-z-secondary`,children:[e.sectionName,` `,(0,Q.jsx)(`span`,{className:`text-z-secondary mx-1`,children:`>`}),` `,X(e.fieldName)]})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-8`,children:[(0,Q.jsxs)(`div`,{className:`opacity-70 pointer-events-none relative`,children:[(0,Q.jsxs)(`div`,{className:`absolute top-0 right-0 p-2 text-sm font-semibold text-z-muted z-10 bg-app/50 backdrop-blur-md`,children:[`Reference (`,l,`)`]}),(0,Q.jsx)(zn,{blockId:e.sectionId,field:{name:e.fieldName,type:e.fieldType,label:``},value:i,onChange:()=>{},theme:n})]}),(0,Q.jsxs)(`div`,{className:`relative border border-z-border/20 p-4 -m-4 bg-z-hover`,children:[(0,Q.jsxs)(`div`,{className:`absolute top-0 right-0 p-2 text-sm font-semibold text-z-secondary z-10 bg-app/50 backdrop-blur-md flex items-center gap-1.5`,children:[a?(0,Q.jsx)(z,{size:10,className:`text-z-secondary`}):null,`Target (`,d,`)`]}),(0,Q.jsx)(zn,{blockId:e.sectionId,field:{name:e.fieldName,type:e.fieldType,label:``},value:a,onChange:e=>c(r,d,e),theme:n})]})]})]},`${e.sectionId}-${e.fieldName}`)})})]})})}),document.body)},or=[`var(--z-accent)`,`var(--z-accent)`,`#ec4899`,`#f43f5e`,`#f97316`,`#84cc16`,`#14b8a6`,`#06b6d4`,`#3b82f6`,`#a855f7`];function sr(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)&65535;return or[t%or.length]}function cr(e,t){return e?e.slice(0,2).toUpperCase():t?t.slice(0,2).toUpperCase():`??`}function lr({collection:e,documentId:t,wsUrl:n,pollInterval:r=15e3,enabled:i=!0}){let{user:a}=ht(W(e=>({user:e.user}))),[o,s]=(0,Z.useState)([]),[c]=(0,Z.useState)(!1),[l]=(0,Z.useState)(null),u=(0,Z.useRef)(null),d={id:a?.id||`local`,email:a?.email||`local@example.com`,name:a?.name,color:sr(a?.id||`local`)};return(0,Z.useEffect)(()=>{if(!i)return;let n=async()=>{try{await q.post(`/presence/heartbeat`,{collection:e,documentId:t,userId:a?.id}).catch(()=>{}),s(((await q.get(`/presence/${e}/${t}`,{params:{collection:e,documentId:t}}).catch(()=>({data:{data:{activeUsers:[]}}}))).data?.data?.activeUsers||[]).map(e=>({id:e.id||e.userId||`?`,email:e.email||`?`,name:e.name,color:sr(e.id||e.userId||``)})))}catch{}};return n(),u.current=setInterval(n,r),()=>{u.current&&clearInterval(u.current)}},[n,c,e,t,r,i,a]),{collabUsers:o,localUser:d,doc:l,isConnected:c,broadcastCursor:(0,Z.useCallback)((e,t)=>{},[])}}var ur=5,dr=({users:e,localUser:t,isConnected:n,theme:r})=>{let[i,a]=(0,Z.useState)(!1),o=e.slice(0,ur),s=Math.max(0,e.length-ur),c={};return e.forEach(e=>{c[e.id]=e.color}),(0,Q.jsxs)(`div`,{className:`relative flex items-center gap-0`,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),children:[(0,Q.jsxs)(`div`,{className:Y(`flex items-center gap-1 px-2 py-1 rounded-none-none border text-sm font-semibold `,n?r===`dark`?`bg-z-panel/5 border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-secondary`:r===`dark`?`bg-z-hover border-z-border text-z-secondary`:`bg-[var(--z-bg-hover)] border-z-border text-z-muted`),title:n?`Live collaboration active`:`Offline — changes saved locally`,children:[n?(0,Q.jsx)(ge,{size:8}):(0,Q.jsx)(Le,{size:8}),n?`Live`:`Local`]}),(0,Q.jsxs)(`div`,{className:`flex items-center ml-1.5`,children:[(0,Q.jsxs)(`div`,{className:`relative`,title:`${t.name||t.email} (you)`,children:[(0,Q.jsx)(G.div,{initial:{scale:0},animate:{scale:1},className:Y(`w-8 h-8 rounded-full flex items-center justify-center text-xs font-bold shadow-sm ring-2`,r===`dark`?`ring-[#050505]`:`ring-z-active-border`),style:{backgroundColor:t.color},children:cr(t.name,t.email)}),(0,Q.jsx)(G.div,{animate:{scale:[1,1.3,1],opacity:[1,.4,1]},transition:{duration:2,repeat:1/0},className:`absolute -bottom-0.5 -right-0.5`,children:(0,Q.jsx)(Me,{size:6,fill:t.color,stroke:`none`,className:`text-z-secondary`})})]}),o.filter(e=>e.id!==t.id).map((e,t)=>(0,Q.jsx)(G.div,{initial:{scale:0,x:-10},animate:{scale:1,x:0},transition:{delay:t*.05},className:Y(`relative -ml-2 w-8 h-8 rounded-full flex items-center justify-center text-xs font-bold shadow-sm ring-2`,r===`dark`?`ring-[#050505]`:`ring-z-active-border`),style:{backgroundColor:e.color,borderColor:`var(--z-border)`,zIndex:o.length-t},title:e.name||e.email,children:cr(e.name,e.email)},e.id)),s>0&&(0,Q.jsxs)(G.button,{type:`button`,initial:{scale:0},animate:{scale:1},onClick:()=>a(e=>!e),"aria-label":`${s} more users editing`,className:Y(`relative -ml-2 w-8 h-8 rounded-full flex items-center justify-center text-xs font-bold shadow-sm ring-2 transition-transform cursor-pointer`,r===`dark`?`bg-z-base text-z-secondary ring-[#050505] hover:scale-105`:`bg-[var(--z-border)] text-z-secondary ring-z-active-border hover:scale-105`),style:{zIndex:0},children:[`+`,s]})]}),(0,Q.jsx)(H,{children:i&&(0,Q.jsxs)(G.div,{initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.1},className:Y(`absolute top-full right-0 mt-2 z-[999] w-64 rounded-xl shadow-2xl p-4 border`,r===`dark`?`bg-[#111] border-z-border text-z-primary`:`bg-z-panel border-z-border text-z-primary shadow-[var(--z-border)]`),onClick:()=>a(!1),children:[(0,Q.jsxs)(`p`,{className:`text-xs font-semibold text-z-secondary mb-2`,children:[e.length,` `,e.length===1?`person`:`people`,` editing`]}),(0,Q.jsx)(`div`,{className:`space-y-1.5`,children:[t,...e.filter(e=>e.id!==t.id)].map(e=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`w-6 h-6 rounded-full flex items-center justify-center text-[10px] font-bold text-z-primary shrink-0`,style:{backgroundColor:e.color},children:cr(e.name,e.email)}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-semibold truncate`,children:e.name||e.email}),e.cursor?.fieldKey&&(0,Q.jsxs)(`p`,{className:`text-xs text-z-secondary truncate`,children:[`→ `,e.cursor.fieldKey]})]}),e.id===t.id&&(0,Q.jsx)(`span`,{className:`text-xs text-z-secondary`,children:`you`})]},e.id))})]})})]})},fr=({handleSave:e,handlePublish:r,handleUnpublish:i,isGlobal:a,onClose:o,collab:s})=>{let c=Ae(),{id:l,slug:u}=xe(),{theme:d,toggleTheme:f}=K(),m=()=>{o?o():c(a?`/`:`/collections/${u||`pages`}`)},{saving:h,undoStack:_,redoStack:v,undo:y,redo:b,lastSavedAt:x}=$(W(e=>({saving:e.saving,undoStack:e.undoStack,redoStack:e.redoStack,undo:e.undo,redo:e.redo,lastSavedAt:e.lastSavedAt}))),{viewMode:S,setViewMode:w,leftOpen:T,setLeftOpen:D,rightOpen:O,setRightOpen:k,focusMode:A,toggleFocusMode:j}=kt(W(e=>({viewMode:e.viewMode,setViewMode:e.setViewMode,leftOpen:e.leftOpen,setLeftOpen:e.setLeftOpen,rightOpen:e.rightOpen,setRightOpen:e.setRightOpen,focusMode:e.focusMode,toggleFocusMode:e.toggleFocusMode}))),{seoOpen:M,setSeoOpen:ee}=dt(W(e=>({seoOpen:e.seoOpen,setSeoOpen:e.setSeoOpen}))),{publishStatus:N,workflowStatus:P,scheduledAt:F}=er(W(e=>({publishStatus:e.publishStatus,workflowStatus:e.workflowStatus,scheduledAt:e.scheduledAt}))),{i18nEnabled:I,availableLocales:te,currentLocale:ne,setCurrentLocale:re,setI18nEnabled:L}=tr(),[ie,oe]=(0,Z.useState)(!1),[se,ce]=(0,Z.useState)(!1),[le,R]=(0,Z.useState)(!1),[de,fe]=(0,Z.useState)(!1),pe=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!se)return;let e=e=>{pe.current&&!pe.current.contains(e.target)&&ce(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[se]);let B=d===`dark`,me=Y(`w-8 h-8 rounded-none-none flex items-center justify-center border transition-all`,B?`bg-z-hover border-z-border`:`bg-z-panel border-z-border`),he=e=>e?B?`bg-z-panel/10 border-z-border text-z-primary`:`bg-[var(--z-active-bg)] text-[var(--z-active-text)] border border-[var(--z-active-border)] shadow-sm`:B?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`,V=e=>e?B?`bg-app/20 border-z-border text-z-primary/20 cursor-not-allowed`:`bg-z-input border-z-border shadow-sm text-z-secondary cursor-not-allowed`:B?`bg-z-hover border-z-border text-z-muted hover:text-z-secondary`:`bg-z-panel border-z-border text-z-secondary hover:bg-[var(--z-bg-input)]`,ge=x?`Saved ${new Date(x).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}`:null;return(0,Q.jsxs)(`header`,{className:Y(`h-14 border-b flex items-center justify-between px-4 z-[100] backdrop-blur-3xl transition-all gap-3 shrink-0 overflow-visible`,B?`bg-z-popover border-z-border`:`bg-z-panel border-z-border shadow-sm`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,Q.jsx)(`button`,{onClick:m,className:Y(me,B?`text-z-muted hover:text-z-primary`:`text-z-secondary hover:text-z-primary`),"aria-label":`Back to collection`,title:`Back`,children:(0,Q.jsx)(Pe,{size:16})}),(0,Q.jsx)(`div`,{className:Y(`h-4 w-px mx-1`,B?`bg-z-panel/10`:`bg-[var(--z-border)]`)}),(0,Q.jsxs)(`button`,{onClick:()=>ee(!M),className:Y(`px-2.5 py-1.5 rounded-none-none border text-xs font-semibold flex items-center gap-1.5 transition-all`,M?`bg-z-panel/5 border-z-border text-z-secondary`:B?`bg-z-hover border-z-border text-z-muted`:`bg-z-input border-z-border text-z-secondary`),"aria-label":M?`Close SEO panel`:`Open SEO panel`,title:`SEO`,children:[(0,Q.jsx)(E,{size:12}),`SEO`]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Q.jsxs)(`button`,{onClick:y,disabled:_.length===0,"aria-label":_.length>0?`Undo (${_.length} step${_.length===1?``:`s`} available)`:`Nothing to undo`,title:_.length>0?`Undo (${_.length} step${_.length===1?``:`s`})`:`Nothing to undo`,className:Y(me,V(_.length===0),`relative`),children:[(0,Q.jsx)(ue,{size:15}),_.length>0&&(0,Q.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 min-w-[14px] h-3.5 px-0.5 flex items-center justify-center text-sm font-semibold tabular-nums rounded-none-none bg-z-accent text-z-primary leading-none`,"aria-hidden":`true`,children:_.length>99?`99+`:_.length})]}),(0,Q.jsxs)(`button`,{onClick:b,disabled:v.length===0,"aria-label":v.length>0?`Redo (${v.length} step${v.length===1?``:`s`} available)`:`Nothing to redo`,title:v.length>0?`Redo (${v.length} step${v.length===1?``:`s`})`:`Nothing to redo`,className:Y(me,V(v.length===0),`relative`),children:[(0,Q.jsx)(ae,{size:15}),v.length>0&&(0,Q.jsx)(`span`,{className:`absolute -top-1.5 -right-1.5 min-w-[14px] h-3.5 px-0.5 flex items-center justify-center text-sm font-semibold tabular-nums rounded-none-none bg-z-accent/80 text-z-primary leading-none`,"aria-hidden":`true`,children:v.length>99?`99+`:v.length})]}),(0,Q.jsx)(`div`,{className:`w-px h-6 bg-z-hover mx-1`}),(0,Q.jsx)(`button`,{onClick:()=>D(!T),"aria-label":T?`Close layers panel`:`Open layers panel`,title:`Layers (Ctrl+\\\\)`,className:Y(me,he(T)),children:(0,Q.jsx)(g,{size:15})}),(0,Q.jsx)(`button`,{onClick:()=>k(!O),"aria-label":O?`Close preview panel`:`Open preview panel`,title:`Preview (Ctrl+P)`,className:Y(me,he(O)),children:(0,Q.jsx)(t,{size:15})}),(0,Q.jsx)(`button`,{onClick:j,"aria-label":A?`Exit focus mode`:`Enter focus mode`,title:`Focus Mode`,className:Y(me,he(A)),children:A?(0,Q.jsx)(Ie,{size:15}):(0,Q.jsx)(Xe,{size:15})}),(0,Q.jsx)(`div`,{className:`w-px h-6 bg-z-hover mx-1`}),(0,Q.jsx)(`button`,{onClick:f,"aria-label":B?`Switch to light mode`:`Switch to dark mode`,className:Y(me,B?`text-z-muted hover:text-z-primary`:`text-z-secondary hover:text-z-primary`),children:B?(0,Q.jsx)(Te,{size:15}):(0,Q.jsx)(we,{size:15})}),(0,Q.jsx)(`button`,{onClick:()=>L(!I),className:Y(me,he(I)),"aria-label":I?`Disable translations`:`Enable translations`,title:I?`Disable translations`:`Enable translations`,children:(0,Q.jsx)(et,{size:13})}),I&&(0,Q.jsx)(`button`,{onClick:()=>fe(!0),className:Y(me,`text-z-secondary hover:text-z-secondary`),title:`Translation Mode (Side-by-Side)`,"aria-label":`Open Translation Mode`,children:(0,Q.jsx)(E,{size:13})}),I&&(0,Q.jsxs)(`div`,{className:`relative`,ref:pe,children:[(0,Q.jsxs)(`button`,{onClick:()=>ce(!se),"aria-label":`Current language: ${ne.toUpperCase()}. Click to change.`,className:Y(`h-8 px-2 rounded-none-none border flex items-center gap-1.5 text-xs font-semibold transition-all`,B?`bg-z-hover border-z-border text-z-muted hover:text-z-primary`:`bg-z-panel border-z-border text-z-secondary hover:bg-[var(--z-bg-input)] hover:text-z-primary`),children:[(0,Q.jsx)(et,{size:13}),ne.toUpperCase()]}),se&&(0,Q.jsx)(`div`,{className:Y(`absolute top-full mt-2 w-36 border rounded-none-none shadow-2xl z-50 overflow-hidden`,B?`bg-[#0a0a0a] border-z-border`:`bg-z-panel border-z-border`),children:te.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>{re(e.code),ce(!1)},className:Y(`w-full flex items-center gap-2 px-3 py-2 text-xs font-bold transition-colors`,ne===e.code?B?`bg-z-panel/5 text-z-secondary`:`bg-z-hover text-z-primary shadow-sm`:B?`text-z-muted hover:bg-z-hover`:`text-z-secondary hover:bg-[var(--z-bg-hover)] hover:text-z-primary`),children:[(0,Q.jsx)(`span`,{children:e.flag}),(0,Q.jsx)(`span`,{className:`flex-1 text-left`,children:e.name})]},e.code))})]}),(0,Q.jsx)(`div`,{className:`w-px h-6 bg-z-hover mx-1`}),(0,Q.jsxs)(`div`,{className:Y(`flex items-center gap-0.5 p-0.5 rounded-none-none border`,B?`bg-z-hover border-z-border`:`bg-z-panel border-z-border`),children:[(0,Q.jsx)(`button`,{onClick:()=>w(`visual`),className:Y(`px-2.5 py-1 rounded-none-none text-xs font-semibold transition-all`,S===`visual`?B?`bg-z-panel text-z-primary`:`bg-[var(--z-active-bg)] text-[var(--z-active-text)] border border-[var(--z-active-border)] shadow-sm`:B?`text-z-primary/50 hover:text-z-primary`:`text-z-secondary hover:text-z-primary`),children:`Visual`}),(0,Q.jsx)(`button`,{onClick:()=>w(`code`),className:Y(`px-2.5 py-1 rounded-none-none text-xs font-semibold transition-all`,S===`code`?B?`bg-z-panel text-z-primary`:`bg-[var(--z-active-bg)] text-[var(--z-active-text)] border border-[var(--z-active-border)] shadow-sm`:B?`text-z-primary/50 hover:text-z-primary`:`text-z-secondary hover:text-z-primary`),children:`JSON`})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsxs)(`button`,{onClick:i,disabled:N===`draft`,className:Y(`flex items-center gap-1 px-2.5 py-1.5 rounded-none-none border text-xs font-semibold transition-all`,N===`draft`&&P!==`scheduled`?B?`bg-amber-500/10 border-amber-500/20 text-amber-400`:`bg-amber-50 border-amber-200 text-amber-600`:B?`bg-z-hover border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-muted`),"aria-label":`Set as draft`,children:[(0,Q.jsx)(Me,{size:7,className:N===`draft`&&P!==`scheduled`||P===`scheduled`?`fill-current`:``}),P===`scheduled`?`Scheduled`:`Draft`]}),(0,Q.jsxs)(`button`,{onClick:()=>R(!0),disabled:N===`published`,className:Y(`flex items-center gap-1 px-2.5 py-1.5 rounded-none-none border text-xs font-semibold transition-all`,N===`published`?B?`bg-green-500/10 border-green-500/20 text-green-400`:`bg-green-50 border-green-200 text-green-600`:B?`bg-z-hover border-z-border text-z-secondary hover:text-z-primary`:`bg-z-input border-z-border text-z-muted hover:text-z-primary`),"aria-label":`Publish document`,children:[(0,Q.jsx)(z,{size:10}),`Publish`]})]}),(0,Q.jsx)(nr,{}),ge&&(0,Q.jsx)(`span`,{className:Y(`text-sm font-semibold `,B?`text-z-secondary`:`text-z-muted`),children:ge}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsxs)(`button`,{onClick:()=>oe(!ie),className:Y(`h-8 px-2.5 rounded-none-none border flex items-center gap-1.5 text-xs font-semibold transition-all`,F?B?`bg-amber-500/10 border-amber-500/20 text-amber-400`:`bg-amber-50 border-amber-200 text-amber-600`:B?`bg-z-hover border-z-border text-z-secondary hover:text-z-primary`:`bg-[var(--z-bg-hover)] border-z-border text-z-muted hover:text-z-primary`),title:F?`Scheduled: ${new Date(F).toLocaleString()}`:`Schedule publish`,"aria-label":F?`Scheduled for ${new Date(F).toLocaleDateString()}`:`Schedule publish`,children:[(0,Q.jsx)(n,{size:12}),F?new Date(F).toLocaleDateString(void 0,{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):`Schedule`]}),(0,Q.jsx)(rr,{open:ie,onClose:()=>oe(!1)})]}),s&&(0,Q.jsx)(`div`,{className:`mx-2`,children:(0,Q.jsx)(dr,{users:s.collabUsers,localUser:s.localUser,isConnected:s.isConnected,theme:d})}),(0,Q.jsxs)(`button`,{onClick:e,disabled:h,className:`flex items-center gap-1.5 px-4 py-1.5 rounded-none-none text-xs font-semibold bg-z-accent text-z-primary shadow-[0_0_16px_rgba(79,70,229,0.3)] hover:bg-z-border transition-all active:scale-95 disabled:opacity-50`,"aria-label":`Save document`,children:[h?(0,Q.jsx)(C,{size:13,className:`animate-spin`}):(0,Q.jsx)(p,{size:13}),h?`Saving...`:`Save`]})]}),(0,Q.jsx)(ir,{open:le,onConfirm:()=>{R(!1),r()},onCancel:()=>R(!1)}),(0,Q.jsx)(ar,{open:de,onClose:()=>fe(!1)})]})},pr=Z.memo(({section:e,index:t,totalSections:n,theme:r,showFieldIndicators:i,editorSelectedField:a,editorSchemaFields:o,editorFieldErrors:s,editorActiveSection:c,editorSetActiveSection:l,duplicateSection:u,removeSection:d,updateAlign:f,handleFieldChange:p,setSelectedField:m,i18nEnabled:h,currentLocale:g,getTranslatedValue:_,setTranslatedValue:v,setActiveDynamicZone:y,setDynamicZoneModalOpen:b,setInjectionIndex:x,setBlockPickerOpen:S,onOpenContextMenu:C,broadcastCursor:w,toggleCollapse:T,moveSection:E,copySection:D,pasteSection:O,handleBlockNameChange:k,selectedSections:A,onMultiSelect:j,collab:ee})=>{let N=Ne();return(0,Q.jsxs)(V,{value:e.id,dragListener:!1,dragControls:N,as:`div`,role:`article`,"aria-label":`Section block ${e.title||e.blockType}`,tabIndex:0,onKeyDown:t=>{if(t.key===`ArrowUp`&&(t.metaKey||t.ctrlKey)){t.preventDefault(),E(e.id,`up`);let n=document.getElementById(`editor-live-region`);n&&(n.innerText=`Moved ${e.title||e.blockType} up`)}if(t.key===`ArrowDown`&&(t.metaKey||t.ctrlKey)){t.preventDefault(),E(e.id,`down`);let n=document.getElementById(`editor-live-region`);n&&(n.innerText=`Moved ${e.title||e.blockType} down`)}},whileDrag:{scale:1.02,opacity:.9,boxShadow:`0 20px 60px rgba(0,0,0,0.3)`,zIndex:50,cursor:`grabbing`},className:`relative group/item focus-visible:ring-2 focus-visible:ring-z-active-border focus-visible:outline-none`,children:[(0,Q.jsx)(`div`,{className:`relative h-8 group/portal -mt-4`,children:(0,Q.jsx)(`button`,{onClick:()=>{x(t),S(!0)},className:`absolute left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 opacity-0 group-hover/item:opacity-60 hover:!opacity-100 transition-all z-20 px-3 py-1 rounded-none-none border-2 border-dashed border-z-border/40 hover:border-z-border/70 backdrop-blur-xl`,children:(0,Q.jsxs)(`span`,{className:Y(`text-sm font-semibold flex items-center gap-1.5 `,`text-z-primary/70`),children:[(0,Q.jsx)(M,{size:10,className:`text-z-secondary `}),` Insert`]})})}),(0,Q.jsx)(Vn,{section:e,index:t,totalSections:n,isActive:c===e.id,isMultiSelected:A.has(e.id),theme:r,showFieldIndicators:i,selectedField:a,schemaFields:o,fieldErrors:s,onSelect:t=>j(e.id,t?.shiftKey||!1),onDuplicate:()=>u(e.id),onDelete:()=>d(e.id),onAlign:t=>f(e.id,t),onFieldChange:(t,n)=>p(e.id,t,n),onFieldSelect:(e,t)=>{m({blockId:e,fieldKey:t}),w?.(e,t),l(e),j(e,!1)},i18nEnabled:h,currentLocale:g,getTranslatedValue:_,setTranslatedValue:v,onAddToDynamicZone:(e,t)=>{y({sectionId:e,fieldKey:t}),b(!0)},dragControls:N,onContextMenu:t=>C(t,e.id),onToggleCollapse:()=>T(e.id),onMoveUp:()=>E(e.id,`up`),onMoveDown:()=>E(e.id,`down`),onCopy:()=>D(e.id),onPaste:()=>O(e.id),onBlockNameChange:t=>k(e.id,t)})]},e.id)},(e,t)=>!(e.section!==t.section||e.index!==t.index||e.totalSections!==t.totalSections||e.theme!==t.theme||e.showFieldIndicators!==t.showFieldIndicators||e.editorActiveSection!==t.editorActiveSection||e.editorFieldErrors!==t.editorFieldErrors||e.editorSelectedField!==t.editorSelectedField||e.editorSchemaFields!==t.editorSchemaFields||e.i18nEnabled!==t.i18nEnabled||e.currentLocale!==t.currentLocale||e.broadcastCursor!==t.broadcastCursor||e.handleFieldChange!==t.handleFieldChange||e.selectedSections!==t.selectedSections||e.onMultiSelect!==t.onMultiSelect)),mr=class extends Z.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:{message:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0}}}componentDidCatch(e,t){this.setState({error:{message:e instanceof Error?e.message:String(e),stack:e instanceof Error?e.stack:void 0,componentStack:t.componentStack}})}handleReset=()=>{this.setState({hasError:!1,error:null}),this.props.onReset?.()};handleCopyError=()=>{let{error:e}=this.state;if(!e)return;let t=[e instanceof Error?e.message:String(e),e instanceof Error?e.stack:void 0,e.componentStack].filter(Boolean).join(`
2
2
 
3
3
  `);navigator.clipboard.writeText(t).catch(()=>{})};render(){return this.state.hasError&&this.state.error?(0,Q.jsx)(hr,{error:this.state.error,onReset:this.handleReset,onCopy:this.handleCopyError}):this.props.children}},hr=({error:e,onReset:t,onCopy:n})=>{let{theme:r}=K();return(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center h-full min-h-64 gap-6 p-8`,children:[(0,Q.jsx)(`div`,{className:Y(`w-14 h-14 rounded-none-none flex items-center justify-center border-2`,r===`dark`?`bg-rose-500/10 border-rose-500/20`:`bg-rose-50 border-rose-200`),children:(0,Q.jsx)(u,{size:24,className:r===`dark`?`text-rose-400`:`text-rose-500`})}),(0,Q.jsxs)(`div`,{className:`text-center max-w-md`,children:[(0,Q.jsx)(`h2`,{className:Y(`text-sm font-semibold mb-2`,`text-z-primary`),children:`Something went wrong`}),(0,Q.jsx)(`p`,{className:Y(`text-xs leading-relaxed font-mono px-3 py-2 border rounded-none-none`,r===`dark`?`text-rose-400 bg-rose-500/5 border-rose-500/10`:`text-rose-600 bg-rose-50 border-rose-200`),children:e instanceof Error?e.message:String(e)})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(`button`,{onClick:t,className:Y(`flex items-center gap-2 px-4 py-2 text-xs font-semibold border rounded-none-none transition-all`,`bg-z-accent hover:bg-z-border text-z-primary border-z-border`),children:[(0,Q.jsx)(v,{size:12}),`Try Again`]}),(0,Q.jsxs)(`button`,{onClick:n,className:Y(`flex items-center gap-2 px-3 py-2 text-xs font-semibold border rounded-none-none transition-all`,r===`dark`?`border-z-border text-z-muted hover:bg-z-hover`:`border-z-border text-z-secondary hover:bg-[var(--z-bg-input)]`),children:[(0,Q.jsx)(b,{size:11}),`Copy Error`]})]}),e.componentStack&&(0,Q.jsxs)(`details`,{className:`w-full max-w-2xl`,children:[(0,Q.jsx)(`summary`,{className:Y(`text-sm font-semibold cursor-pointer mb-1`,`text-z-secondary`),children:`Component Stack`}),(0,Q.jsx)(`pre`,{className:Y(`w-full text-sm font-mono p-3 border rounded-none-none overflow-x-auto max-h-48`,r===`dark`?`bg-z-hover border-z-border text-z-secondary`:`bg-z-input border-z-border text-z-secondary`),children:e.componentStack})]})]})},gr=({versionId:e,versionNumber:t,collection:n,documentId:r,onClose:i,onRestoreSuccess:a})=>{let{theme:o}=K(),[s,c]=(0,Z.useState)(!0),[l,u]=(0,Z.useState)([]),[d,f]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{e&&(c(!0),q.get(`/versions/${n}/${r}/${e}/diff`).then(e=>{u(e.data?.data?.diffs||[])}).catch(()=>{U.error(`Failed to load version differences`),i()}).finally(()=>{c(!1)}))},[e,n,r,i]);let p=async t=>{if(e){f(t);try{let i=await q.post(`/versions/${n}/${r}/${e}/rollback-fields`,{fields:[t]});U.success(`Successfully rolled back field: ${t.toUpperCase()}`),i.data?.data?.document&&a(i.data.data.document),u(e=>e.filter(e=>e.field!==t))}catch{U.error(`Failed to rollback field: ${t}`)}finally{f(null)}}},m=e=>{if(e==null)return(0,Q.jsx)(`span`,{className:`text-z-secondary text-xs`,children:`None / Empty`});if(typeof e==`object`)return(0,Q.jsx)(`pre`,{className:`text-xs font-mono whitespace-pre-wrap leading-relaxed opacity-85`,children:JSON.stringify(e,null,2)});let t=String(e);return t.startsWith(`<`)&&t.endsWith(`>`)?(0,Q.jsx)(`span`,{className:`text-sm leading-relaxed`,children:t.replace(/<\/?[^>]+(>|$)/g,``)}):(0,Q.jsx)(`span`,{className:`text-sm leading-relaxed`,children:t})},h=o===`dark`;return(0,Q.jsx)(H,{children:e&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[110] bg-app/50 backdrop-blur-md`,onClick:i}),(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.95,y:15},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:15},transition:{type:`spring`,damping:25,stiffness:250},className:Y(`fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 z-[120] w-[85vw] max-w-[1100px] h-[80vh] flex flex-col border shadow-2xl overflow-hidden font-sans`,h?`bg-app border-z-border text-z-primary`:`bg-z-panel border-z-border text-z-primary`),children:[(0,Q.jsxs)(`div`,{className:`p-6 border-b border-z-border flex items-center justify-between shrink-0 bg-gradient-to-r from-[var(--z-bg-panel)] to-transparent`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`w-9 h-9 border flex items-center justify-center text-z-secondary`,children:(0,Q.jsx)(R,{size:16})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`h3`,{className:`text-base font-semibold`,children:[`Compare Differences — V.`,t]}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary mt-0.5`,children:`Compare historical version snapshot with current working draft`})]})]}),(0,Q.jsx)(`button`,{onClick:i,"aria-label":`Close diff view`,className:Y(`p-2 rounded-none-none transition-colors`,h?`hover:bg-z-hover text-z-muted hover:text-z-primary`:`hover:bg-[var(--z-bg-hover)] text-z-secondary hover:text-z-primary`),children:(0,Q.jsx)(B,{size:15,"aria-hidden":`true`})})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-6 space-y-6 custom-editor-scrollbar`,children:s?(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center gap-4`,children:[(0,Q.jsx)(C,{size:32,className:`animate-spin text-z-secondary `}),(0,Q.jsx)(`p`,{className:`text-xs font-semibold text-z-secondary animate-pulse`,children:`Analyzing delta changes...`})]}):l.length===0?(0,Q.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center gap-3 text-center`,children:[(0,Q.jsx)(y,{size:36,className:`text-z-secondary `}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h4`,{className:`text-xs font-semibold`,children:`No Differences Detected`}),(0,Q.jsx)(`p`,{className:`text-xs text-z-secondary mt-1`,children:`This version snapshot matches the current working copy exactly.`})]})]}):(0,Q.jsx)(`div`,{className:`space-y-8`,children:l.map(e=>(0,Q.jsxs)(`div`,{className:Y(`border rounded-none-none overflow-hidden`,h?`border-z-border bg-app/10`:`border-z-border bg-[var(--z-bg-input)]/50`),children:[(0,Q.jsxs)(`div`,{className:Y(`px-4 py-2.5 border-b flex items-center justify-between`,h?`bg-z-panel border-z-border`:`bg-[var(--z-bg-hover)] border-z-border`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(w,{size:13,className:`text-z-secondary`}),(0,Q.jsx)(`span`,{className:`text-xs font-semibold`,children:e.field.replace(`:`,` `).toUpperCase()})]}),(0,Q.jsxs)(`button`,{onClick:()=>p(e.field),disabled:d===e.field,className:`flex items-center gap-1.5 px-2.5 py-1 text-xs font-semibold bg-z-accent/10 hover:bg-z-accent border border-z-border/20 hover:border-z-border text-z-secondary hover:text-z-primary transition-all disabled:opacity-50`,children:[d===e.field?(0,Q.jsx)(C,{size:10,className:`animate-spin`}):(0,Q.jsx)(x,{size:10}),`Rollback Field`]})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 divide-y md:divide-y-0 md:divide-x divide-z-border`,children:[(0,Q.jsxs)(`div`,{className:`p-4 bg-red-500/[0.01] flex flex-col gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-xs font-semibold text-rose-500 block`,children:[`Previous Value (V.`,t,`)`]}),(0,Q.jsx)(`div`,{className:`flex-1 bg-red-500/[0.03] border border-red-500/10 rounded-none p-3 text-red-100/90 min-h-16 overflow-x-auto custom-editor-scrollbar`,children:m(e.from)})]}),(0,Q.jsxs)(`div`,{className:`p-4 bg-z-border/[0.01] flex flex-col gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-semibold text-z-secondary block`,children:`Current Value`}),(0,Q.jsx)(`div`,{className:`flex-1 bg-z-border/[0.03] border border-z-border/10 rounded-none p-3 text-z-primary/90 min-h-16 overflow-x-auto custom-editor-scrollbar`,children:m(e.to)})]})]})]},e.field))})}),(0,Q.jsx)(`div`,{className:`p-4 border-t border-z-border flex items-center justify-end bg-gradient-to-r from-transparent to-[var(--z-bg-panel)]`,children:(0,Q.jsx)(`button`,{onClick:i,className:`px-5 py-2 border border-z-border hover:border-z-border text-xs font-semibold hover:bg-z-hover transition-all text-z-muted hover:text-z-primary`,children:`Close Comparison`})})]})]})})},_r=({open:e,onClose:t,onReload:n,onForceSave:r,conflictMessage:i,serverVersion:a,localVersion:o,theme:s})=>{let[c,l]=(0,Z.useState)(!1);return(0,Q.jsx)(H,{children:e&&(0,Q.jsx)(G.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:`fixed inset-0 z-[1000] flex items-center justify-center bg-app/70 backdrop-blur-sm`,onClick:e=>{e.target===e.currentTarget&&t()},children:(0,Q.jsxs)(G.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},transition:{duration:.15},className:Y(`w-full max-w-md border rounded-none-none shadow-2xl`,s===`dark`?`bg-app border-rose-500/20 text-z-primary`:`bg-z-panel border-rose-200 text-z-primary`),children:[(0,Q.jsxs)(`div`,{className:Y(`px-6 py-5 border-b flex items-start gap-4`,s===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsx)(`div`,{className:Y(`w-10 h-10 rounded-none-none border flex items-center justify-center shrink-0`,s===`dark`?`bg-rose-500/10 border-rose-500/20 text-rose-400`:`bg-rose-50 border-rose-200 text-rose-500`),children:(0,Q.jsx)(u,{size:18})}),(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`h2`,{className:`text-xs font-semibold text-rose-400`,children:`Conflict Detected`}),(0,Q.jsxs)(`p`,{className:`text-xs font-bold text-z-secondary mt-1 leading-relaxed`,children:[`Another editor saved changes to this document while you were editing.`,(0,Q.jsx)(`br`,{}),`Version mismatch: you had `,(0,Q.jsxs)(`span`,{className:`font-semibold text-z-secondary`,children:[`v`,o??`?`]}),`, server now at `,(0,Q.jsxs)(`span`,{className:`font-semibold text-amber-400`,children:[`v`,a??`?`]}),`.`]}),i&&(0,Q.jsx)(`p`,{className:`text-xs font-bold text-rose-400/70 mt-1.5 tracking-wide`,children:i})]}),(0,Q.jsx)(`button`,{onClick:t,className:Y(`shrink-0 p-1 transition-colors`,s===`dark`?`text-z-secondary hover:text-z-primary`:`text-z-muted hover:text-z-primary`),children:(0,Q.jsx)(B,{size:16})})]}),(0,Q.jsxs)(`div`,{className:`px-6 py-5 space-y-4`,children:[(0,Q.jsxs)(`div`,{className:Y(`p-4 border rounded-none-none text-xs font-bold tracking-wide leading-relaxed`,s===`dark`?`bg-z-panel/3 border-z-border text-z-muted`:`bg-z-input border-z-border shadow-sm text-z-secondary`),children:[(0,Q.jsxs)(`p`,{children:[`Choose `,(0,Q.jsx)(`span`,{className:`font-semibold text-z-primary`,children:`"Use Their Version"`}),` to discard your unsaved changes and reload the server's latest content.`]}),(0,Q.jsxs)(`p`,{className:`mt-2`,children:[`Choose `,(0,Q.jsx)(`span`,{className:`font-semibold text-z-primary`,children:`"Keep My Changes"`}),` to overwrite the server's changes with yours (the server will update its version to match).`]})]}),(0,Q.jsxs)(`div`,{className:Y(`grid grid-cols-1 md:grid-cols-2 gap-3 p-3 border border-dashed rounded-none-none`,`border-z-border`),children:[(0,Q.jsxs)(`div`,{className:`text-center`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-semibold text-z-secondary mb-1`,children:`Your Version`}),(0,Q.jsxs)(`p`,{className:`text-lg font-semibold text-z-secondary`,children:[`v`,o??`?`]})]}),(0,Q.jsxs)(`div`,{className:`text-center`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-semibold text-z-secondary mb-1`,children:`Server Version`}),(0,Q.jsxs)(`p`,{className:`text-lg font-semibold text-amber-400`,children:[`v`,a??`?`]})]})]})]}),(0,Q.jsxs)(`div`,{className:Y(`px-6 py-4 border-t flex gap-3`,s===`dark`?`border-z-border`:`border-z-border shadow-sm`),children:[(0,Q.jsxs)(`button`,{type:`button`,disabled:c,onClick:async()=>{l(!0);try{await n()}finally{l(!1),t()}},className:Y(`flex-1 flex items-center justify-center gap-2 py-3 text-xs font-semibold border rounded-none-none transition-all`,s===`dark`?`border-amber-500/30 text-amber-400 hover:bg-amber-500/10 hover:border-amber-500/50`:`border-amber-300 text-amber-600 hover:bg-amber-50 hover:border-amber-400`,c&&`opacity-50 cursor-not-allowed`),children:[(0,Q.jsx)(v,{size:11,className:c?`animate-spin`:``}),`Use Their Version`]}),(0,Q.jsxs)(`button`,{type:`button`,disabled:c,onClick:async()=>{l(!0);try{await r()}finally{l(!1),t()}},className:Y(`flex-1 flex items-center justify-center gap-2 py-3 text-xs font-semibold rounded-none-none transition-all bg-z-accent text-z-primary hover:bg-z-border border border-z-border`,c&&`opacity-50 cursor-not-allowed`),children:[(0,Q.jsx)(z,{size:11,className:c?`animate-spin`:``}),`Keep My Changes`]})]})]})})})},vr=()=>{let{theme:e}=K(),t=$(e=>e.data),n=(0,Z.useMemo)(()=>{if(!t)return{words:0,chars:0,blocks:0};let e=[];t.title&&e.push(t.title),t.heroDescription&&e.push(typeof t.heroDescription==`string`?t.heroDescription:String(t.heroDescription)),(t.sections||[]).forEach(t=>{Object.values(t.content||{}).forEach(t=>{if(typeof t==`string`)e.push(t);else if(typeof t==`object`)try{let n=JSON.stringify(t);if(!n.startsWith(`[{`)&&!n.startsWith(`{`)){let t=n.replace(/<[^>]+>/g,` `).trim();t&&e.push(t)}}catch{}})});let n=e.join(` `);return{words:n.trim()?n.trim().split(/\s+/).length:0,chars:n.replace(/\s+/g,``).length,blocks:(t.sections||[]).length}},[t]);return(0,Q.jsxs)(`div`,{className:Y(`h-7 border-t flex items-center justify-between px-5 shrink-0 select-none`,e===`dark`?`bg-z-popover border-z-border text-z-secondary`:`bg-z-panel/90 border-z-border shadow-sm text-z-muted`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 text-xs font-semibold`,children:[(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`span`,{className:`font-semibold`,children:n.words.toLocaleString()}),` `,(0,Q.jsx)(`span`,{className:n.words===0?`text-rose-500/50`:``,children:`words`})]}),(0,Q.jsx)(`span`,{className:`w-px h-3 bg-z-panel/10`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`span`,{className:`font-semibold`,children:n.chars.toLocaleString()}),` `,(0,Q.jsx)(`span`,{className:n.chars===0?`text-rose-500/50`:``,children:`chars`})]}),(0,Q.jsx)(`span`,{className:`w-px h-3 bg-z-panel/10`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`span`,{className:`font-semibold`,children:n.blocks}),` `,n.blocks===1?`block`:`blocks`]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-4 text-xs font-semibold text-z-secondary/50`,children:[(0,Q.jsx)(`span`,{children:`ZENITH EDITOR`}),(0,Q.jsx)(`span`,{children:`v0.2`})]})]})},yr=(e,t)=>{let n,r=(...r)=>{clearTimeout(n),n=setTimeout(()=>e(...r),t)};return r.cancel=()=>clearTimeout(n),r};function br(e){if(!e)return``;try{return JSON.stringify(e)}catch{return String(Date.now())}}function xr(e,t,n=300){let r=(0,Z.useRef)(``),i=(0,Z.useRef)(null);(0,Z.useEffect)(()=>(i.current=yr(t=>{let n=br(t);if(n===r.current)return;r.current=n;let i=e.current?.contentWindow;if(!i)return;let a=e.current?.src,o=`*`;if(a)try{o=new URL(a).origin}catch{}i.postMessage({type:`ZENITH_DATA_UPDATE`,data:t},o)},n),()=>{i.current&&i.current.cancel()}),[n,e]);let a=(0,Z.useRef)(t);(0,Z.useEffect)(()=>{a.current=t},[t]),(0,Z.useEffect)(()=>{let e=i.current;t&&e&&e(t)},[t]),(0,Z.useEffect)(()=>{let t=e.current;if(!t)return;let n=()=>{r.current=``;let e=i.current;e&&a.current&&e(a.current)};return t.addEventListener(`load`,n),()=>t.removeEventListener(`load`,n)},[e])}function Sr(e,t){if(!e?.sections?.length)return[];let n=[];for(let r of e.sections){let e=t.find(e=>e.slug===r.blockType);if(e?.fields)for(let t of e.fields){let e=r.content?.[t.name];if(t.required&&e==null){n.push({sectionId:r.id??r.blockType??`unknown`,fieldName:t.name,message:`${t.label??t.name} is required`});continue}typeof e==`string`&&(t.maxLength&&e.length>t.maxLength&&n.push({sectionId:r.id??r.blockType??`unknown`,fieldName:t.name,message:`${t.label??t.name} exceeds ${t.maxLength} characters (current: ${e.length})`}),t.minLength&&e.length<t.minLength&&n.push({sectionId:r.id??r.blockType??`unknown`,fieldName:t.name,message:`${t.label??t.name} must be at least ${t.minLength} characters`})),typeof e==`number`&&(t.min!==void 0&&e<t.min&&n.push({sectionId:r.id??r.blockType??`unknown`,fieldName:t.name,message:`${t.label??t.name} must be at least ${t.min}`}),t.max!==void 0&&e>t.max&&n.push({sectionId:r.id??r.blockType??`unknown`,fieldName:t.name,message:`${t.label??t.name} must be at most ${t.max}`}))}}return n}function Cr(e){return(0,Z.useCallback)(t=>Sr(t,e),[e])}function wr({isGlobal:e,isNewDoc:t,id:n,data:r,dataRef:i,hasUnsavedChanges:a,saving:o,validate:s,publishStatusRef:c,workflowStatusRef:l,workflowReviewersRef:u,workflowCommentsRef:d,scheduledAtRef:f,translationsRef:p,fieldSettingsRef:m,publishStatus:h,workflowStatus:g,workflowReviewers:_,workflowComments:v,scheduledAt:y,translations:b,editorFieldSettings:x,setConflictData:S,conflictData:C}){let w=Ae(),T=xe(),E=(0,Z.useRef)(null),D=(0,Z.useRef)(!1),O=$(e=>e.setSaving),k=$(e=>e.setHasUnsavedChanges),A=$(e=>e.setFieldErrors),j=$(e=>e.updateData),M=$(e=>e.setData),ee=$(e=>e.setHistory),N=$(e=>e.undo),P=$(e=>e.redo),F=er(e=>e.setPublishStatus),I=er(e=>e.setScheduledAt);er(e=>e.setWorkflowStatus);let te=(0,Z.useRef)({data:null,publishStatus:`draft`,workflowStatus:`draft`,workflowReviewers:[],workflowComments:[],scheduledAt:``,translations:{},fieldSettings:{}});(0,Z.useEffect)(()=>{te.current={data:r,publishStatus:h,workflowStatus:g,workflowReviewers:_,workflowComments:v,scheduledAt:y,translations:b,fieldSettings:x}},[r,h,g,_,v,y,b,x]),(0,Z.useEffect)(()=>{if(!(!a||o))return E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{let r=te.current;r.data&&(async()=>{if(!r.data)return;let i=s(r.data);if(i.length>0){let e={};i.forEach(t=>{let n=`${t.sectionId}:${t.fieldName}`;e[n]=t instanceof Error?t.message:String(t)}),A(e),U.error(`${i.length} validation error(s) found. Please fix the errors.`);return}A({}),O(!0);try{let i=(r.data?.sections||[]).find(e=>e.blockType===`pageTitle`),a=(r.data?.sections||[]).find(e=>e.blockType===`pageDescription`),o={...r.data,title:i?.content?.title??r.data?.title,heroDescription:a?.content?.description??r.data?.heroDescription,sections:(r.data?.sections||[]).map(e=>{let{id:t,content:n,...r}=e;return{...r,...ne(n||{})}})||[],_status:r.publishStatus,workflowStatus:r.workflowStatus,reviewers:r.workflowReviewers,comments:r.workflowComments,scheduledAt:r.scheduledAt||void 0,publishedAt:r.publishStatus===`published`?r.data.publishedAt||new Date().toISOString():null,i18n:r.translations,_fieldSettings:r.fieldSettings};if(e)await q.patch(`/globals/${n}`,o);else if(t){let e=await q.post(`/${T.slug||`pages`}`,o),t=e.data?.data?._id||e.data?.data?.id;t&&w(`/collections/${T.slug||`pages`}/${t}`,{replace:!0})}else await q.patch(`/${T.slug||`pages`}/${n}`,o);k(!1),$.getState().setLastSavedAt(new Date().toISOString())}catch{U.error(`Auto-save failed`,{icon:`️`,duration:3e3})}finally{O(!1)}})()},3e4),()=>{E.current&&clearTimeout(E.current)}},[r,a,o,e,n,s]);let ne=e=>{let t={};for(let[n,r]of Object.entries(e))r===``||r==null||Array.isArray(r)&&r.length===0||typeof r==`object`&&!Array.isArray(r)&&Object.keys(r).length===0||(t[n]=r);return t},re=async()=>{if(D.current)return;D.current=!0;let r=i.current;if(!r){D.current=!1;return}let a=s(r);if(a.length>0){let e={};a.forEach(t=>{let n=`${t.sectionId}:${t.fieldName}`;e[n]=t instanceof Error?t.message:String(t)}),A(e),U.error(`${a.length} validation error(s) found. Please fix the errors before saving.`),D.current=!1;return}A({}),E.current&&clearTimeout(E.current),O(!0);let o;try{let i=c.current,a=(r.sections||[]).find(e=>e.blockType===`pageTitle`),s=(r.sections||[]).find(e=>e.blockType===`pageDescription`),h={...r,title:a?.content?.title??r.title,heroDescription:s?.content?.description??r.heroDescription,sections:(r.sections||[]).map(e=>{let{id:t,content:n,...r}=e;return{...r,...ne(n||{})}})||[],_status:i,workflowStatus:l.current,reviewers:u.current,comments:d.current,scheduledAt:f.current||void 0,publishedAt:i===`published`?r.publishedAt||new Date().toISOString():null,i18n:p.current,_fieldSettings:m.current},g;g=e?await q.patch(`/globals/${n}`,h):t?await q.post(`/${T.slug||`pages`}`,h):await q.patch(`/${T.slug||`pages`}/${n}`,h),o=g.data.data?._version;let _=g.data?.data?._id||g.data?.data?.id;k(!1),$.getState().setLastSavedAt(new Date().toISOString()),U.success(i===`published`?` Published!`:` Saved as Draft`,{}),t&&_&&w(`/collections/${T.slug||`pages`}/${_}`,{replace:!0})}catch(e){if(e?.response?.status===409){let t=e?.response?.data?.error?.message||``,n=t.match(/current\s+(\d+)/i);S({open:!0,message:t,serverVersion:n?parseInt(n[1]):e?.response?.data?.data?.currentVersion??void 0,localVersion:r._version??void 0}),O(!1),D.current=!1;return}U.error(e?.response?.data?.error?.message||e?.response?.data?.message||`Failed to save changes`),O(!1),D.current=!1;return}if(O(!1),D.current=!1,o!==void 0){j(e=>{e._version=o});let t=e?`globals`:T.slug||`pages`;q.get(`/versions/${t}/${n}`).then(e=>ee(e.data.data||[])).catch(()=>{})}};return{handleSave:re,handleUndo:()=>{N(),U.success(`Undone`,{icon:`↩️`})},handleRedo:()=>{P(),U.success(`Redone`,{icon:`↪️`})},handleReload:async()=>{U.loading(`Reloading server version...`,{id:`conflict`});try{let t=T.slug||`pages`,r=(e?await q.get(`/globals/${n}`):await q.get(`/${t}/${n}`)).data.data;M({...r,sections:(r.sections||[]).map(e=>({...e,id:e.id||at(),content:e.content||e.blockData||{}}))}),k(!1),S({open:!1}),U.success(`Reloaded server version`,{id:`conflict`})}catch{U.error(`Failed to reload`,{id:`conflict`})}},handleForceSave:async()=>{let r=i.current;if(r){U.loading(`Force-saving your version...`,{id:`conflict`});try{let i=(r.sections||[]).find(e=>e.blockType===`pageTitle`),a=(r.sections||[]).find(e=>e.blockType===`pageDescription`),o={...r,title:i?.content?.title??r.title,heroDescription:a?.content?.description??r.heroDescription,sections:(r.sections||[]).map(e=>{let{id:t,content:n,...r}=e;return{...r,...ne(n||{})}})||[],_version:C.serverVersion===void 0?r._version:C.serverVersion,_status:c.current,workflowStatus:l.current,reviewers:u.current,comments:d.current,scheduledAt:f.current||void 0,publishedAt:c.current===`published`?r.publishedAt||new Date().toISOString():null,i18n:p.current,_fieldSettings:m.current},s;s=e?await q.patch(`/globals/${n}`,o):t?await q.post(`/${T.slug||`pages`}`,o):await q.patch(`/${T.slug||`pages`}/${n}`,o);let h=s.data.data?._version,g=s.data?.data?._id||s.data?.data?.id;h!==void 0&&M({...r,_version:h}),k(!1),$.getState().setLastSavedAt(new Date().toISOString()),S({open:!1}),U.success(`Force-saved your version`,{id:`conflict`}),t&&g&&w(`/collections/${T.slug||`pages`}/${g}`,{replace:!0})}catch(e){let t=e?.response?.data?.error?.message||e?.response?.data?.message||`Force-save failed`;U.error(t,{id:`conflict`})}}},handlePublish:async()=>{F(`published`),await re()},handleUnpublish:async()=>{F(`draft`),I(``),er.getState().setWorkflowStatus(`draft`),U.success(`Unpublished - now visible only to editors`)}}}var Tr=({isGlobal:e,id:t,focusedSectionId:n,onClose:r})=>{let i=xe();Ae();let a=!e&&!i.id,o=t||i.id||(e?i.slug:`new`),{theme:c}=K(),u=(0,Z.useRef)(null),d=st(),{data:f,setData:p,setLoading:m,setSaving:h,setHasUnsavedChanges:g,updateData:_,undo:v,redo:y,activeSection:b,selectedField:x,schemaFields:S,fieldSettings:w,fieldErrors:T,topLevelFields:E,setHistory:O,setSelectedField:k,setSchemaFields:A,setTopLevelFields:j,setFieldSettings:ee,setFieldErrors:N,setAvailableCollections:P,setActiveSection:F}=$(W(e=>({data:e.data,setData:e.setData,setLoading:e.setLoading,setSaving:e.setSaving,setHasUnsavedChanges:e.setHasUnsavedChanges,updateData:e.updateData,undo:e.undo,redo:e.redo,activeSection:e.activeSection,selectedField:e.selectedField,schemaFields:e.schemaFields,fieldSettings:e.fieldSettings,fieldErrors:e.fieldErrors,topLevelFields:e.topLevelFields,setHistory:e.setHistory,setSelectedField:e.setSelectedField,setSchemaFields:e.setSchemaFields,setTopLevelFields:e.setTopLevelFields,setFieldSettings:e.setFieldSettings,setFieldErrors:e.setFieldErrors,setAvailableCollections:e.setAvailableCollections,setActiveSection:e.setActiveSection}))),{viewMode:I}=kt(W(e=>({viewMode:e.viewMode}))),{templatesOpen:te,setTemplatesOpen:ne,setSeoOpen:re,showFieldIndicators:L,blockPickerOpen:ie,setBlockPickerOpen:ae}=dt(W(e=>({templatesOpen:e.templatesOpen,setTemplatesOpen:e.setTemplatesOpen,setSeoOpen:e.setSeoOpen,showFieldIndicators:e.showFieldIndicators,blockPickerOpen:e.blockPickerOpen,setBlockPickerOpen:e.setBlockPickerOpen}))),{workflowStatus:oe,setWorkflowStatus:se,publishStatus:ce,setPublishStatus:le,workflowReviewers:ue,setWorkflowReviewers:R,workflowComments:de,setWorkflowComments:fe,scheduledAt:z,setScheduledAt:pe,setReleases:B,setActiveRelease:me}=er(W(e=>({workflowStatus:e.workflowStatus,setWorkflowStatus:e.setWorkflowStatus,publishStatus:e.publishStatus,setPublishStatus:e.setPublishStatus,workflowReviewers:e.workflowReviewers,setWorkflowReviewers:e.setWorkflowReviewers,workflowComments:e.workflowComments,setWorkflowComments:e.setWorkflowComments,scheduledAt:e.scheduledAt,setScheduledAt:e.setScheduledAt,setReleases:e.setReleases,setActiveRelease:e.setActiveRelease}))),{i18nEnabled:he,currentLocale:V,translations:ge,setTranslations:_e,updateTranslation:ve}=tr(),ye=ht(e=>e.siteId),be=$(e=>e.loading),Se=$(e=>e.saving),Ce=$(e=>e.hasUnsavedChanges),H=f,[we,Te]=(0,Z.useState)(null),[Ee,De]=(0,Z.useState)(new Set),[ke,je]=(0,Z.useState)(!1),[Me,Ne]=(0,Z.useState)(null),[Pe,Fe]=(0,Z.useState)(null),[Ie,Le]=(0,Z.useState)(null),[Re,ze]=(0,Z.useState)(null),Be=Z.useMemo(()=>E.some(e=>e.type===`blocks`||e.name===`layout`||e.name===`sections`),[E]);Z.useMemo(()=>f?.sections?.map(e=>e.id)||[],[f?.sections?.length]);let[Ve,He]=(0,Z.useState)({open:!1}),[G,We]=(0,Z.useState)({open:!1,sectionId:null});xr(u,H,300),gt({hasUnsavedChanges:Ce});let Ge=lr({collection:e?`globals`:`pages`,documentId:o||``,wsUrl:void 0,enabled:!0}),Ke=Cr(d.map(e=>({slug:e.type,label:e.title,fields:e.fields||[],defaultContent:e.defaultContent}))),Je=(0,Z.useRef)(H);(0,Z.useEffect)(()=>{Je.current=H},[H]);let Ye=(0,Z.useRef)(ce),Xe=(0,Z.useRef)(oe),Ze=(0,Z.useRef)(ue),Qe=(0,Z.useRef)(de),$e=(0,Z.useRef)(z),et=(0,Z.useRef)(ge),tt=(0,Z.useRef)(w);(0,Z.useEffect)(()=>{Ye.current=ce},[ce]),(0,Z.useEffect)(()=>{Xe.current=oe},[oe]),(0,Z.useEffect)(()=>{Ze.current=ue},[ue]),(0,Z.useEffect)(()=>{Qe.current=de},[de]),(0,Z.useEffect)(()=>{$e.current=z},[z]),(0,Z.useEffect)(()=>{et.current=ge},[ge]),(0,Z.useEffect)(()=>{tt.current=w},[w]);let nt=(0,Z.useRef)(!0);(0,Z.useEffect)(()=>(nt.current=!0,()=>{nt.current=!1}),[]);let rt=(0,Z.useRef)(o),it=(0,Z.useRef)(null),J=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>(J.current=!1,()=>{J.current=!0}),[o,e,ye]);let ct=(0,Z.useRef)(0),lt=e=>{try{return structuredClone(e)}catch{return JSON.parse(JSON.stringify(e))}},ut=(e,t,n)=>!he||V===`en`?n:ge[`${e}:${t}`]?.[V]||n,pt=(e,t,n)=>{ve(`${e}:${t}`,V,n),g(!0)},mt=(e,t)=>{e.preventDefault(),Le({x:e.clientX,y:e.clientY,sectionId:t})},_t=(0,Z.useCallback)(e=>()=>Te(e),[]),yt=(0,Z.useCallback)(()=>Te(null),[]),bt=(0,Z.useCallback)(e=>{if(we===`left`){let t=e.clientX;t>=200&&t<=500&&kt.getState().setLeftWidth(t)}else if(we===`right`){let t=window.innerWidth-e.clientX;t>=200&&t<=700&&kt.getState().setRightWidth(t)}},[we]);(0,Z.useEffect)(()=>(we&&(window.addEventListener(`mousemove`,bt),window.addEventListener(`mouseup`,yt)),()=>{window.removeEventListener(`mousemove`,bt),window.removeEventListener(`mouseup`,yt)}),[we,bt,yt]),(0,Z.useEffect)(()=>{u.current?.contentWindow&&b&&u.current.contentWindow.postMessage({type:`ZENITH_PARENT_SELECT`,sectionId:b,id:b},`*`)},[b]),(0,Z.useEffect)(()=>{let e=e=>{let t=e.target,n=t.getAttribute(`name`)||t.getAttribute(`data-field`)||t.closest(`[data-field]`)?.getAttribute(`data-field`);n&&u.current?.contentWindow&&u.current.contentWindow.postMessage({type:`ZENITH_PARENT_SELECT`,id:n},`*`)};return document.addEventListener(`focusin`,e),()=>document.removeEventListener(`focusin`,e)},[]),(0,Z.useEffect)(()=>{let e=e=>{let t=window.location.origin;if(!(t!==`*`&&e.origin!==t&&e.origin!==window.location.origin))switch(e.data?.type){case`ZENITH_IFRAME_READY`:b&&u.current?.contentWindow?.postMessage({type:`ZENITH_PARENT_SELECT`,sectionId:b,id:b},`*`);break;case`ZENITH_SECTION_SELECT`:{let t=e.data.sectionId||e.data.id;t&&(F(t),De(new Set([t])));break}default:break}};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[F]);let xt=(0,Z.useRef)({editorActiveSection:b,selectedSections:Ee});(0,Z.useEffect)(()=>{xt.current={editorActiveSection:b,selectedSections:Ee}},[b,Ee]),(0,Z.useEffect)(()=>{let e=e=>{let t=e.target?.tagName,n=t===`INPUT`||t===`TEXTAREA`||e.target?.isContentEditable,r=e.metaKey||e.ctrlKey;if(r&&e.key===`s`){e.preventDefault(),St();return}if(r&&e.key===`z`&&!e.shiftKey){e.preventDefault(),Ct();return}if(r&&(e.key===`z`&&e.shiftKey||e.key===`y`)){e.preventDefault(),wt();return}if(r&&e.key===`\\`){e.preventDefault();let t=kt.getState();t.setLeftOpen(!t.leftOpen);return}if(r&&e.key===`p`){e.preventDefault();let t=kt.getState();t.setRightOpen(!t.rightOpen);return}if(n)return;let{editorActiveSection:i,selectedSections:a}=xt.current;if(r&&e.key===`d`&&i&&i!==`root`){e.preventDefault(),Nt(i);return}if((e.key===`Backspace`||e.key===`Delete`)&&a.size>0){e.preventDefault(),a.forEach(e=>Pt(e)),De(new Set);return}if(e.key===`Escape`){De(new Set),F(null),ae(!1),re(!1),ne(!1);return}e.key===`/`&&ae(!0)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]);let{handleSave:St,handleUndo:Ct,handleRedo:wt,handleReload:Tt,handleForceSave:Et,handlePublish:Dt,handleUnpublish:Ot}=wr({isGlobal:e,isNewDoc:a,id:o,data:H,dataRef:Je,hasUnsavedChanges:Ce,saving:Se,validate:Ke,publishStatusRef:Ye,workflowStatusRef:Xe,workflowReviewersRef:Ze,workflowCommentsRef:Qe,scheduledAtRef:$e,translationsRef:et,fieldSettingsRef:tt,publishStatus:ce,workflowStatus:oe,workflowReviewers:ue,workflowComments:de,scheduledAt:z,translations:ge,editorFieldSettings:w,setConflictData:He,conflictData:Ve});(0,Z.useEffect)(()=>{if(!te)return;let e=++ct.current;q.get(`/templates`).then(t=>{e===ct.current&&$.getState().setTemplates(t.data.data||[])}).catch(()=>{})},[te]),(0,Z.useEffect)(()=>{rt.current&&rt.current!==o&&$.setState({undoStack:[],redoStack:[]}),rt.current=o,(async()=>{m(!0);try{let t=i.slug||`pages`,n={sections:[]};if(!a){let r=e?await q.get(`/globals/${o}`):await q.get(`/${t}/${o}`);r.data?.data&&(n=r.data.data)}if(J.current)return;let r=n,s=(r.sections||[]).map(e=>{let{id:t,blockType:n,align:r,blockName:i,collapsed:a,content:o,blockData:s,...c}=e,l=o&&Object.keys(o).length>0,u=s&&Object.keys(s).length>0;return{id:t||at(),blockType:n,align:r,blockName:i,collapsed:a,content:l?o:u?s:c}});if(p({...r,sections:s}),J.current)return;s.length>0&&F(s[0].id);let c=e?`globals`:i.slug||`pages`,l=o;if(!a){let e=await q.get(`/versions/${c}/${l}`);J.current||O(e.data.data||[])}if(le(r._status||r.status||`draft`),se(r.workflowStatus||`draft`),R(r.reviewers||[]),fe(r.comments||[]),pe(r.scheduledAt||``),_e(r.i18n||{}),J.current)return;try{let e=await q.get(`/releases`);if(J.current)return;B(e.data.data||[]),me(e.data.data?.find(e=>e.status===`pending`)||null)}catch{J.current||U.error(`Failed to load releases`)}try{let t=await q.get(`/health`);if(J.current)return;let n=t?.data?.data||{};P(n.collections||[]),j((e?n.globals||[]:n.collections||[]).find(e=>e.slug===(i.slug||`pages`))?.fields||[])}catch{J.current||U.error(`Failed to load collections`)}let u={};s.forEach(e=>{Object.keys(e.content||{}).forEach(t=>{let n=`${e.id}:${t}`;u[n]={required:!1,unique:!1,maxLength:null,minLength:null,private:!1,relation:null,...r._fieldSettings?.[n]}})}),ee(u);let d=[];s.forEach(e=>{Object.keys(e.content||{}).forEach(t=>{d.push({id:`${e.id}:${t}`,name:t,blockId:e.id,blockType:e.blockType,type:ot(t,e.content[t]),label:X(t),required:!1,unique:!1,sortable:!0,filterable:!0,private:!1})})}),A(d)}catch{J.current||U.error(`Failed to sync editor`,{icon:`️`,duration:5e3})}finally{J.current||setTimeout(()=>m(!1),500)}})()},[o,e,ye]);let jt=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{jt.current=!1},[o]),(0,Z.useEffect)(()=>{if(H?.sections?.length&&!jt.current)if(n)H.sections.some(e=>e.id===n)&&(F(n),De(new Set([n])),jt.current=!0);else{let e=H.sections[0].id;F(e),De(new Set([e])),jt.current=!0}},[n,H?.sections?.length]),(0,Z.useEffect)(()=>{if(!b)return;let e=document.getElementById(b);e&&(e.scrollIntoView({behavior:`smooth`,block:`center`}),e.classList.add(`ring-2`,`ring-[var(--z-accent)]`,`ring-offset-2`,`ring-offset-[#0B0F19]`,`transition-all`,`duration-500`),setTimeout(()=>{e.classList.remove(`ring-2`,`ring-[var(--z-accent)]`,`ring-offset-2`,`ring-offset-[#0B0F19]`)},1e3))},[b]),(0,Z.useEffect)(()=>{ie===!1&&Fe(null)},[ie]);let Mt=e=>{let t=d.find(t=>t.type===e);if(!t)return;let n=at(),r=`${t.type}-${n.slice(0,4)}`,i={id:n,blockType:t.type,title:t.title,content:{...t.defaultContent,anchorId:r}};_(e=>{let t=[...e?.sections||[]];return Pe===null?t.push(i):t.splice(Pe,0,i),{...e,sections:t}}),F(i.id),ae(!1),Fe(null),U.success(`Section added: ${e.toUpperCase()}`,{icon:``})},Nt=(0,Z.useCallback)(e=>{let t=Je.current;if(!t)return;let n=t.sections.find(t=>t.id===e);if(!n)return;let r=at(),i=`${n.blockType}-${r.slice(0,4)}`,a={...n,id:r,title:`${n.title} (Copy)`,content:{...lt(n.content),anchorId:i}};_(t=>{let n=t.sections.findIndex(t=>t.id===e),r=[...t.sections];return r.splice(n+1,0,a),{...t,sections:r}}),F(a.id),U.success(`Section duplicated`,{icon:``})},[Je,_,F]),Pt=(0,Z.useCallback)(e=>{Je.current?.sections?.find(t=>t.id===e)&&We({open:!0,sectionId:e})},[Je]),Ft=()=>{let e=G.sectionId;if(!e)return;let t=Je.current?.sections?.find(t=>t.id===e);if(We({open:!1,sectionId:null}),_(t=>({...t,sections:t.sections.filter(t=>t.id!==e)})),b===e&&F(null),Ee.has(e)){let t=new Set(Ee);t.delete(e),De(t)}U.error(`Section "${t?.title||t?.blockType}" removed`)},It=(e,t)=>{let n=d.find(e=>e.type===t);n&&(_(r=>{if(!r)return r;let i=[...r.sections||[]],a=i.findIndex(t=>t.id===e);if(a!==-1){let e=i[a],r=e.content||{},o={...n.defaultContent},s=[`title`,`heading`,`headline`,`name`],c=[`content`,`description`,`bio`,`body`,`subheadline`],l=Object.entries(r).find(([e])=>s.some(t=>e.toLowerCase().includes(t)))?.[1],u=Object.entries(r).find(([e])=>c.some(t=>e.toLowerCase().includes(t)))?.[1];Object.keys(o).forEach(e=>{let t=e.toLowerCase();s.some(e=>t.includes(e))&&l!==void 0?o[e]=l:c.some(e=>t.includes(e))&&u!==void 0?o[e]=u:r[e]!==void 0&&(o[e]=r[e])}),i[a]={...e,blockType:t,title:n.title,content:o}}return{...r,sections:i}}),g(!0),U.success(`Converted block layout to: ${n.title}`,{icon:``}))},Lt=(0,Z.useCallback)(e=>{_(t=>{let n=[...t.sections],r=n.findIndex(t=>t.id===e);return r!==-1&&(n[r]={...n[r],collapsed:!n[r].collapsed}),{...t,sections:n}}),g(!0)},[_,g]),Rt=(e,t)=>{_(n=>{let r=[...n.sections],i=r.findIndex(t=>t.id===e);if(i===-1)return n;let a=t===`up`?i-1:i+1;return a<0||a>=r.length?n:([r[i],r[a]]=[r[a],r[i]],{...n,sections:r})}),g(!0)},zt=e=>{let t=Je.current;if(!t)return;let n=t.sections.find(t=>t.id===e);if(n){try{navigator.clipboard.writeText(JSON.stringify({type:`zenith-section`,section:n}))}catch{it.current=n}U.success(`Section copied`,{icon:``})}},Vt=(e,t)=>{let n={...e,id:at(),title:`${e.title} (Copied)`,content:lt(e.content)};_(e=>{let r=[...e.sections];if(t){let e=r.findIndex(e=>e.id===t);r.splice(e+1,0,n)}else r.push(n);return{...e,sections:r}}),F(n.id),g(!0),U.success(`Section pasted`,{icon:``})},Ht=e=>{navigator.clipboard.readText().then(t=>{try{let n=JSON.parse(t);if(n.type===`zenith-section`){Vt(n.section,e);return}}catch{}it.current?Vt(it.current,e):U.error(`No copied section found`,{icon:`️`})}).catch(()=>{it.current?Vt(it.current,e):U.error(`No copied section found`,{icon:`️`})})},Ut=(0,Z.useCallback)((e,t)=>{_(n=>{let r=[...n.sections],i=r.findIndex(t=>t.id===e);return i!==-1&&(r[i]={...r[i],blockName:t}),{...n,sections:r}}),g(!0)},[_,g]),Wt=()=>{let e=Je.current;if(!e)return;let t=e.sections.every(e=>e.collapsed);_(e=>({...e,sections:e.sections.map(e=>({...e,collapsed:!t}))})),g(!0),U.success(t?`All sections expanded`:`All sections collapsed`,{icon:``})},Gt=(0,Z.useCallback)((e,t)=>{_(n=>{let r=[...n.sections],i=r.findIndex(t=>t.id===e);return i!==-1&&(r[i].align=t),{...n,sections:r}})},[_]),Kt=e=>{_(t=>{let n=new Map((t?.sections||[]).map(e=>[e.id,e])),r=e.map(e=>n.get(e)).filter(Boolean);return{...t,sections:r}})},qt=(e,t,n)=>{_(r=>{let i=[...r.sections],a=i.findIndex(t=>t.id===e);return a!==-1&&(i[a].content[t]=n),{...r,sections:i}})},Jt=(0,Z.useCallback)((e,t,n)=>{$.getState().setField(e,t,n);let r=`${e}:${t}`;if($.getState().fieldErrors[r]){let e={...$.getState().fieldErrors};delete e[r],$.getState().setFieldErrors(e)}},[]);return be?(0,Q.jsxs)(`div`,{className:Y(`h-screen w-full flex flex-col items-center justify-center gap-6`,c===`dark`?`bg-app`:`bg-[#fafafa]`),children:[(0,Q.jsxs)(`div`,{className:`relative flex items-center justify-center w-24 h-24`,children:[(0,Q.jsx)(`div`,{className:Y(`absolute inset-0 rounded-full border-2`,`border-z-border border-z-border`,`animate-spin`)}),(0,Q.jsx)(C,{size:32,className:Y(`animate-spin opacity-50`,`text-z-primary`),strokeWidth:1,style:{animationDuration:`3s`}}),(0,Q.jsx)(`div`,{className:Y(`absolute inset-0 blur-3xl animate-pulse`,c===`dark`?`bg-z-panel/5`:`bg-app/5`)})]}),(0,Q.jsx)(`p`,{className:Y(`text-sm font-semibold tracking-widest uppercase`,`text-z-primary/40`),children:`Loading`})]}):(0,Q.jsxs)(`div`,{className:Y(`h-screen flex flex-col overflow-hidden transition-colors duration-500`,c===`dark`?`bg-app text-z-primary`:`bg-z-panel text-z-primary`),children:[(0,Q.jsx)(fr,{handleSave:St,handlePublish:Dt,handleUnpublish:Ot,isGlobal:e,onClose:r,collab:Ge}),(0,Q.jsx)(`div`,{"aria-live":`polite`,"aria-atomic":`true`,className:`sr-only`,id:`editor-live-region`}),(0,Q.jsx)(mr,{children:(0,Q.jsxs)(`div`,{className:`flex-1 flex overflow-hidden relative`,children:[Be&&(0,Q.jsx)(At,{isGlobal:e,resizingSide:we,startResizing:_t,addBlock:Mt,removeSection:Pt,setInjectionIndex:Fe,setBlockPickerOpen:ae}),(0,Q.jsx)(`main`,{className:Y(`flex-1 relative flex flex-col overflow-hidden transition-colors`,c===`dark`?`bg-[#030303]`:`bg-[var(--z-bg-input)]`),children:(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto px-4 sm:px-6 lg:px-10 pt-6 lg:pt-10 pb-20 no-scrollbar scroll-smooth relative z-10 custom-editor-scrollbar`,children:(0,Q.jsxs)(`div`,{className:`max-w-[1400px] mx-auto min-h-screen flex flex-col`,children:[I===`visual`?(0,Q.jsxs)(`div`,{className:`flex-1 space-y-12`,children:[(0,Q.jsx)(`div`,{id:`document-kernel`,className:Y(`space-y-6 transition-all duration-500`,H?.align===`center`&&`text-center`,H?.align===`right`&&`text-right`),children:(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`div`,{className:Y(`flex items-center gap-0.5 p-0.5 rounded-none-none border`,c===`dark`?`bg-z-hover border-z-border`:`bg-[var(--z-bg-hover)] border-z-border`),children:[`left`,`center`,`right`].map(e=>(0,Q.jsxs)(`button`,{onClick:()=>H&&p({...H,align:e}),className:Y(`p-1 transition-all`,H?.align===e||!H?.align&&e===`left`?c===`dark`?`bg-z-accent/20 text-z-accent dark:text-z-active-text`:`bg-z-active-bg text-z-active-text shadow-sm border border-z-active-border`:`text-z-muted hover:text-z-primary hover:bg-[var(--z-bg-hover)] rounded dark:text-z-active-text`),children:[e===`left`&&(0,Q.jsx)(s,{size:12}),` `,e===`center`&&(0,Q.jsx)(Oe,{size:12}),` `,e===`right`&&(0,Q.jsx)(D,{size:12})]},e))}),(0,Q.jsxs)(`button`,{onClick:Wt,className:Y(`flex items-center gap-1.5 px-2 py-1 text-sm font-semibold rounded-none-none border transition-all`,c===`dark`?`border-z-border text-z-secondary hover:text-z-accent dark:text-z-active-text hover:border-z-accent/20`:`border-z-border text-z-muted hover:text-z-accent hover:border-z-active-border`),title:`Collapse / Expand All`,children:[(0,Q.jsx)(Ue,{size:10}),`Collapse All`]})]})}),Be&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(qe,{axis:`y`,values:H?.sections?.map(e=>e.id)||[],onReorder:Kt,className:`space-y-8`,children:H?.sections?.map((e,t)=>(0,Q.jsx)(pr,{section:e,index:t,totalSections:H?.sections?.length||0,theme:c,showFieldIndicators:L||!1,editorSelectedField:x,editorSchemaFields:S,editorFieldErrors:T,editorActiveSection:b,editorSetActiveSection:F,duplicateSection:Nt,removeSection:Pt,updateAlign:Gt,handleFieldChange:Jt,setSelectedField:k,i18nEnabled:he,currentLocale:V,getTranslatedValue:ut,setTranslatedValue:pt,setActiveDynamicZone:Ne,setDynamicZoneModalOpen:je,setInjectionIndex:Fe,setBlockPickerOpen:ae,onOpenContextMenu:mt,collab:Ge,broadcastCursor:Ge.broadcastCursor,toggleCollapse:Lt,moveSection:Rt,copySection:zt,pasteSection:Ht,handleBlockNameChange:Ut,selectedSections:Ee,onMultiSelect:(e,t)=>{t?De(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}):(F(e),De(new Set([e])))}},e.id))}),(0,Q.jsxs)(`button`,{onClick:()=>{Fe(null),ae(!0)},className:Y(`w-full py-10 rounded-none-none border-2 border-dashed transition-all flex flex-col items-center gap-4 group`,c===`dark`?`border-z-border hover:border-z-accent/40 hover:opacity-90/5`:`border-z-border hover:border-z-active-border hover:bg-z-active-bg`),children:[(0,Q.jsx)(`div`,{className:Y(`w-12 h-12 rounded-none-none border-2 border-dashed flex items-center justify-center group-hover:scale-110 transition-all`,c===`dark`?`border-z-active-border bg-z-accent/5`:`border-z-active-border bg-z-active-bg/50`),children:(0,Q.jsx)(M,{size:22,className:`text-z-accent dark:text-z-active-text`})}),(0,Q.jsx)(`p`,{className:`text-sm font-semibold text-z-secondary group-hover:text-z-accent dark:text-z-active-text transition-colors`,children:`Append Section`})]})]}),E.length>0&&(0,Q.jsxs)(`div`,{className:Y(`border rounded-none-none p-10 shadow-sm relative overflow-hidden transition-colors`,c===`dark`?`bg-app border-z-border`:`bg-z-panel border-z-border shadow-sm`),children:[(0,Q.jsx)(`div`,{className:`absolute top-0 right-0 p-10 opacity-[0.01] pointer-events-none`,children:(0,Q.jsx)(l,{size:180,strokeWidth:.5})}),(0,Q.jsx)(`div`,{className:`relative z-10`,children:(0,Q.jsx)(On,{fields:E,initialData:H,onValuesChange:e=>{_(t=>{let n={},r=!1;return E.forEach(i=>{e[i.name]!==void 0&&JSON.stringify(t[i.name])!==JSON.stringify(e[i.name])&&(n[i.name]=e[i.name],r=!0)}),r?{...t,...n}:t})},hideSubmitButton:!0})})]})]}):(0,Q.jsx)(`div`,{className:`flex-1 flex flex-col pt-10`,children:(0,Q.jsx)(`div`,{className:Y(`flex-1 p-10 font-mono text-sm overflow-auto rounded-none-none border`,c===`dark`?`bg-app/50 border-z-border text-z-active-text`:`bg-[var(--z-bg-hover)] border-z-border text-z-accent`),children:(0,Q.jsx)(`pre`,{className:`no-scrollbar`,children:JSON.stringify(H,null,3)})})}),(0,Q.jsx)(vr,{})]})})}),(0,Q.jsx)(Bt,{isGlobal:e,resizingSide:we,startResizing:_t,iframeRef:u,handleRestore:async t=>{let n=e?`globals`:`pages`,r=o;h(!0);try{let e=await q.post(`/versions/${n}/${r}/${t}/restore`);_(()=>e.data.data.document),U.success(`Version restored`)}catch{U.error(`Restore failed`)}finally{h(!1)}},onCompareDiff:(e,t)=>ze({id:e,num:t})})]})}),(0,Q.jsx)(Un,{addBlock:Mt}),(0,Q.jsx)(qn,{onSave:St}),(0,Q.jsx)(Jn,{selectedSections:Ee,setSelectedSections:De,applyTemplate:async e=>{_(t=>({...t,sections:[...t.sections||[],...(e.sections||[]).map(e=>({...e,id:at()}))]})),ne(!1),U.success(`${e.name} applied!`,{icon:``})},deleteTemplate:async e=>{try{await q.delete(`/templates/${e}`),U.success(`Template deleted`)}catch{U.error(`Failed to delete template`,{icon:`️`,duration:5e3})}},saveAsTemplate:async e=>{let t=H?.sections.filter(t=>e.includes(t.id))||[];if(t.length!==0)try{await q.post(`/templates`,{name:`Template ${new Date().toLocaleTimeString()}`,content:{sections:t}}),ne(!1),U.success(`Template saved to server!`,{icon:``})}catch{U.error(`Failed to save template`,{icon:`️`,duration:5e3})}}}),(0,Q.jsx)(Yn,{}),(0,Q.jsx)(Zn,{}),(0,Q.jsx)($n,{dynamicZoneModalOpen:ke,setDynamicZoneModalOpen:je,activeDynamicZone:Me,addToDynamicZone:e=>{if(!Me)return;let t=d.find(t=>t.type===e);t&&(_(n=>{let r=[...n.sections],i=r.findIndex(e=>e.id===Me.sectionId);if(i!==-1){let n=r[i].content[Me.fieldKey]||[];r[i].content[Me.fieldKey]=[...n,{__component:`content.${e}`,...t.defaultContent,id:`dz_${Date.now()}`}]}return{...n,sections:r}}),U.success(`${t.title} added to zone`))},removeFromDynamicZone:e=>{Me&&_(t=>{let n=[...t.sections],r=n.findIndex(e=>e.id===Me.sectionId);if(r!==-1){let t=[...n[r].content[Me.fieldKey]||[]];t.splice(e,1),n[r].content[Me.fieldKey]=t}return{...t,sections:n}})},onReorder:qt}),Ie&&(0,Q.jsx)(vt,{x:Ie.x,y:Ie.y,theme:c,onClose:()=>Le(null),onDuplicate:()=>Nt(Ie.sectionId),onDelete:()=>Pt(Ie.sectionId),onAlign:e=>Gt(Ie.sectionId,e),onConvert:e=>It(Ie.sectionId,e)}),Re&&(0,Q.jsx)(gr,{versionId:Re.id,versionNumber:Re.num,collection:e?`globals`:`pages`,documentId:o||``,onClose:()=>ze(null),onRestoreSuccess:t=>{_(()=>t);let n=e?`globals`:i.slug||`pages`,r=o||``;q.get(`/versions/${n}/${r}`).then(e=>O(e.data.data||[])).catch(()=>{})}}),(0,Q.jsx)(_r,{open:Ve.open,onClose:()=>He({open:!1}),onReload:Tt,onForceSave:Et,conflictMessage:Ve.message,serverVersion:Ve.serverVersion,localVersion:Ve.localVersion,theme:c}),(0,Q.jsx)(ft,{open:G.open,title:`Delete Section`,message:`Are you sure you want to delete "${H?.sections?.find(e=>e.id===G.sectionId)?.title||`this section`}"? This action cannot be undone.`,confirmLabel:`Delete`,danger:!0,onConfirm:Ft,onCancel:()=>We({open:!1,sectionId:null})})]})};export{Tr as default};