import{h as C,i as N,r,j as s}from"./vendor-react-9M-xu2bR.js";import{AppCreationWizard as A}from"./index-Dv78M4Xq.js";import{z as j}from"./framework-BM176iet.js";import"./vendor-objectstack-YKtcdalX.js";import{b as S,a as w}from"./index-CTBPkbPG.js";import{b as p}from"./vendor-ui-utils-3tkeUVaX.js";import"./vendor-icons-ndICq8DC.js";import"./infrastructure-n1j_TN6w.js";import"./vendor-i18n-E3-WitRV.js";import"./vendor-zod-DxQVy2_o.js";import"./ui-components-BxvihT61.js";import"./vendor-radix-C6qchjxv.js";import"./vendor-charts-BLNOCZWl.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 K(){const o=C(),{appName:i,editAppName:d}=N(),{apps:u,objects:f,refresh:m}=S(),c=w(),n=d||i,a=u.find(t=>t.name===n),g=(f||[]).map(t=>({name:t.name,label:t.label||t.name,icon:t.icon,selected:a?.navigation?.some(e=>e.type==="object"&&e.objectName===t.name)??!1})),x=r.useMemo(()=>{if(a)return{name:a.name,title:a.title||a.label||"",description:a.description||"",icon:a.icon||"",layout:a.layout||"sidebar",navigation:a.navigation||[],branding:{logo:a.branding?.logo||a.logo||"",primaryColor:a.branding?.primaryColor||"#3b82f6",favicon:a.branding?.favicon||a.favicon||""}}},[a]),b=r.useCallback(async t=>{try{const e=j(t),y={...a,...e},l=c?.getClient();l&&await l.meta.saveItem("app",t.name,y),p.success(`Application "${t.title}" updated successfully`),await m?.(),o(`/apps/${t.name}`)}catch(e){p.error(e?.message||"Failed to update application")}},[o,m,c,a]),v=r.useCallback(()=>{o(i?`/apps/${i}`:"/")},[o,i]),h=r.useCallback(t=>{try{localStorage.setItem(`objectui-edit-draft-${n}`,JSON.stringify(t)),p.info("Draft saved")}catch{}},[n]);return a?s.jsx("div",{className:"mx-auto max-w-4xl py-8 px-4","data-testid":"edit-app-page",children:s.jsx(A,{availableObjects:g,initialDraft:x,onComplete:b,onCancel:v,onSaveDraft:h})}):s.jsx("div",{className:"mx-auto max-w-4xl py-8 px-4 text-center","data-testid":"edit-app-not-found",children:s.jsxs("p",{className:"text-muted-foreground",children:['Application "',n,'" not found.']})})}export{K as EditAppPage};
