const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-Dv78M4Xq.js","assets/framework-BM176iet.js","assets/vendor-react-9M-xu2bR.js","assets/vendor-objectstack-YKtcdalX.js","assets/vendor-zod-DxQVy2_o.js","assets/ui-components-BxvihT61.js","assets/vendor-ui-utils-3tkeUVaX.js","assets/vendor-icons-ndICq8DC.js","assets/vendor-radix-C6qchjxv.js","assets/vendor-i18n-E3-WitRV.js","assets/vendor-charts-BLNOCZWl.js","assets/infrastructure-n1j_TN6w.js","assets/ui-components-CRV2BvKI.css"])))=>i.map(i=>d[i]);
import{S as w,h as v,i as j,j as b,k as y,b7 as S,b8 as E,b9 as N,ap as k}from"./ui-components-BxvihT61.js";import{r,j as e,i as D,k as P}from"./vendor-react-9M-xu2bR.js";import{S as C}from"./framework-BM176iet.js";import{b as _}from"./vendor-ui-utils-3tkeUVaX.js";import{a as O,u as R,b as T,M as L}from"./index-CTBPkbPG.js";import{ak as M,at as $}from"./vendor-icons-ndICq8DC.js";import"./vendor-radix-C6qchjxv.js";import"./vendor-i18n-E3-WitRV.js";import"./vendor-charts-BLNOCZWl.js";import"./infrastructure-n1j_TN6w.js";import"./vendor-objectstack-YKtcdalX.js";import"./vendor-zod-DxQVy2_o.js";import"./plugins-core-qwgXbAqa.js";import"./vendor-dndkit-CX1oDZqy.js";import"./plugins-views-CveFN6PV.js";import"./data-adapter-rvE3xy2B.js";import"./ui-layout-C6KWQtRO.js";function A({open:a,onOpenChange:x,title:o,description:m,schema:i,onSchemaChange:p,collection:s,recordName:l,children:h}){const u=O(),f=r.useRef(i);f.current=i;const c=r.useCallback(async t=>{try{if(u)return await u.update(s,l,t),!0}catch(n){console.warn("[DesignDrawer] Auto-save failed:",n)}return!1},[u,s,l]),d=r.useCallback(async t=>{p(t),await c(t)},[p,c]);return r.useEffect(()=>{if(!a)return;const t=n=>{(n.ctrlKey||n.metaKey)&&n.key==="s"&&(n.preventDefault(),c(f.current).then(g=>{g&&_.success(`${o} saved`)}))};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[a,c,o]),e.jsx(w,{open:a,onOpenChange:x,modal:!1,children:e.jsxs(v,{side:"right",hideOverlay:!0,className:"w-full sm:w-[540px] sm:max-w-[540px] lg:w-[640px] lg:max-w-[640px] p-0 flex flex-col","data-testid":"design-drawer",children:[e.jsxs(j,{className:"px-4 py-3 border-b shrink-0",children:[e.jsx(b,{children:o}),e.jsx(y,{className:m?"":"sr-only",children:m||`Visual editor — configure and preview ${o}`})]}),e.jsx("div",{className:"flex-1 overflow-auto p-4",children:h(i,d)})]})})}const I=r.lazy(()=>k(()=>import("./index-Dv78M4Xq.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12])).then(a=>({default:a.PageCanvasEditor})));function ae(){const{pageName:a}=D(),[x]=P(),{showDebug:o}=R(),[m,i]=r.useState(!1),{pages:p}=T(),s=p?.find(t=>t.name===a),[l,h]=r.useState(null),u=r.useCallback(()=>{h(s),i(!0)},[s]),f=r.useCallback(t=>{i(t)},[]);if(!s)return e.jsx("div",{className:"h-full flex items-center justify-center p-8",children:e.jsxs(S,{children:[e.jsx("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted",children:e.jsx(M,{className:"h-6 w-6 text-muted-foreground"})}),e.jsx(E,{children:"Page Not Found"}),e.jsxs(N,{children:['The page "',a,'" could not be found. It may have been removed or renamed.']})]})});const c=Object.fromEntries(x.entries()),d=m&&l?l:s;return e.jsxs("div",{className:"flex flex-row h-full w-full overflow-hidden relative",children:[e.jsxs("div",{className:"flex-1 overflow-auto h-full relative group",children:[e.jsx("div",{className:`absolute top-1.5 sm:top-2 right-1.5 sm:right-2 z-50 flex items-center gap-1.5 transition-opacity ${o?"opacity-100":"opacity-0 group-hover:opacity-100"}`,children:e.jsxs("button",{type:"button",onClick:u,className:"inline-flex items-center gap-1.5 rounded-md border border-input bg-background px-2.5 py-1.5 text-xs font-medium text-muted-foreground shadow-sm hover:bg-accent hover:text-accent-foreground","data-testid":"page-edit-button",children:[e.jsx($,{className:"h-3.5 w-3.5"}),"Edit"]})}),e.jsx(C,{schema:{...d,type:d.type||"page",context:{...d.context,params:c}}})]}),e.jsx(L,{open:o,sections:[{title:"Page Configuration",data:d}]}),e.jsx(A,{open:m,onOpenChange:f,title:`Edit Page: ${s.label||s.title||a}`,schema:l||s,onSchemaChange:h,collection:"sys_page",recordName:a,children:(t,n)=>e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"p-4 text-muted-foreground",children:"Loading editor…"}),children:e.jsx(I,{schema:t,onChange:n})})})]})}export{ae as PageView};
