import{h as v,i as y,r as s,j as a}from"./vendor-react-9M-xu2bR.js";import{PageCanvasEditor as j}from"./index-Dv78M4Xq.js";import{b as d}from"./vendor-ui-utils-3tkeUVaX.js";import{a as w,b as k}from"./index-CTBPkbPG.js";import{A as E}from"./vendor-icons-ndICq8DC.js";import"./framework-BM176iet.js";import"./vendor-objectstack-YKtcdalX.js";import"./vendor-zod-DxQVy2_o.js";import"./ui-components-BxvihT61.js";import"./vendor-radix-C6qchjxv.js";import"./vendor-i18n-E3-WitRV.js";import"./vendor-charts-BLNOCZWl.js";import"./infrastructure-n1j_TN6w.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 q(){const f=v(),{pageName:t}=y(),i=w(),{pages:g}=k(),r=g?.find(e=>e.name===t),[l,h]=s.useState(()=>r||{type:"page",name:t??"",title:t??"",children:[]}),u=s.useRef(l);u.current=l;const n=s.useCallback(async e=>{try{if(i)return await i.update("sys_page",t,e),!0}catch{}return!1},[i,t]),m=s.useCallback(async e=>{h(e),await n(e)},[n]);s.useEffect(()=>{const e=o=>{(o.ctrlKey||o.metaKey)&&o.key==="s"&&(o.preventDefault(),n(u.current).then(c=>{c&&d.success("Page saved")}))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[n]);const x=s.useCallback(e=>{const o=new Blob([JSON.stringify(e,null,2)],{type:"application/json"}),c=URL.createObjectURL(o),p=document.createElement("a");p.href=c,p.download=`${t||"page"}.json`,p.click(),URL.revokeObjectURL(c),d.success("Page schema exported")},[t]),b=s.useCallback(e=>{d.success("Page schema imported"),m(e)},[m]);return r?a.jsxs("div",{className:"h-full flex flex-col","data-testid":"page-design-page",children:[a.jsxs("div",{className:"flex items-center gap-3 border-b px-4 py-3 sm:px-6",children:[a.jsx("button",{type:"button",onClick:()=>f(-1),className:"rounded p-1.5 text-muted-foreground hover:text-foreground","aria-label":"Go back","data-testid":"page-design-back",children:a.jsx(E,{className:"h-4 w-4"})}),a.jsxs("h1",{className:"text-lg font-semibold tracking-tight truncate",children:["Edit Page: ",r.label||r.title||t]})]}),a.jsx("div",{className:"flex-1 overflow-auto p-4 sm:p-6",children:a.jsx(j,{schema:l,onChange:m,onExport:x,onImport:b})})]}):a.jsxs("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:['Page "',t,'" not found']})}export{q as PageDesignPage};
