@objectstack/console 9.8.0 → 9.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AdapterProvider-CGofnJBf.js → AdapterProvider-DJb3ZVmJ.js} +1 -1
- package/dist/assets/{AiPendingActionsPage-CaJCvm5D.js → AiPendingActionsPage-BI-QQNee.js} +1 -1
- package/dist/assets/ApiConsolePage-CPV6vWpt.js +1 -0
- package/dist/assets/AppDocsIndex-D4Y3i2rM.js +1 -0
- package/dist/assets/AppManagementPage-CLiHbNPr.js +1 -0
- package/dist/assets/{ApprovalsInboxPage-BbvtY-xj.js → ApprovalsInboxPage-CAyznoRP.js} +1 -1
- package/dist/assets/{AuditLogPage-ffz9xeHl.js → AuditLogPage-BeEqEy4g.js} +1 -1
- package/dist/assets/ComponentNavView-DmALsugj.js +1 -0
- package/dist/assets/ConsoleFloatingChatbot-CXwRB3yg.js +1 -0
- package/dist/assets/{DashboardView-CsknMwAh.js → DashboardView-BF0o0wgx.js} +1 -1
- package/dist/assets/{DashboardWidgetInspector-DSLIsQS9.js → DashboardWidgetInspector-DIMge0qc.js} +1 -1
- package/dist/assets/{DeveloperHubPage-DZyjalsK.js → DeveloperHubPage-DbQwi1EV.js} +1 -1
- package/dist/assets/{ExpressionProvider-wi1dJ2tN.js → ExpressionProvider-DKFCgLsJ.js} +1 -1
- package/dist/assets/FlowRunsPage-CJDL4g0k.js +1 -0
- package/dist/assets/{IntegrationsPage-Dfl35fAT.js → IntegrationsPage-DU_wvj4-.js} +2 -2
- package/dist/assets/{InterfaceListPage-DAJiEE0k.js → InterfaceListPage-DZpFSsQf.js} +1 -1
- package/dist/assets/{ManagedByBadge-BAL_PuGz.js → ManagedByBadge-Difq_L_A.js} +1 -1
- package/dist/assets/{MarketplaceAccessDenied-BBUl4uOo.js → MarketplaceAccessDenied-CXUE33gy.js} +1 -1
- package/dist/assets/{MarketplaceInstalledPage-CaN54GxZ.js → MarketplaceInstalledPage-CBfcARvX.js} +1 -1
- package/dist/assets/{MarketplacePackagePage-SKgqOj7g.js → MarketplacePackagePage-BWCVUz3e.js} +2 -2
- package/dist/assets/{MarketplacePage-CoigR7d_.js → MarketplacePage-BT-WkhAG.js} +1 -1
- package/dist/assets/{MetadataInspector-BGWYqUse.js → MetadataInspector-BRICMLXW.js} +1 -1
- package/dist/assets/{MetadataProvider-_6IU7cWK.js → MetadataProvider-CEw2X-qL.js} +1 -1
- package/dist/assets/PageView-CP-3dRzz.js +1 -0
- package/dist/assets/{ProfilePage-C11r_2xN.js → ProfilePage-BAtKSxuK.js} +1 -1
- package/dist/assets/PublicFormsPage-D7D2WWL7.js +1 -0
- package/dist/assets/RecordDetailView-BdQK61l2.js +1 -0
- package/dist/assets/{RecordFormPage-1zrrumdr.js → RecordFormPage-lFVOsTl0.js} +1 -1
- package/dist/assets/{ReportDefaultInspector--SQsifZI.js → ReportDefaultInspector-GD1EQSTh.js} +1 -1
- package/dist/assets/{ReportView-q3jNGyaI.js → ReportView-BHtzV5eK.js} +1 -1
- package/dist/assets/{RuntimeDraftBar-DaYAgW5v.js → RuntimeDraftBar-DXwH4Hvd.js} +1 -1
- package/dist/assets/{SearchResultsPage-BRnB7VD4.js → SearchResultsPage-CE_LTSSU.js} +1 -1
- package/dist/assets/{SettingsHub-CUCcntU9.js → SettingsHub-BLEC_8Ao.js} +1 -1
- package/dist/assets/{SettingsView-DRjJrXF9.js → SettingsView-BEjR60F6.js} +1 -1
- package/dist/assets/SystemHubPage-DjNBraYu.js +1 -0
- package/dist/assets/componentRegistry-ByxoJqMW.js +1 -0
- package/dist/assets/{data-adapter-CzKUUIgi.js → data-adapter-CCidkDs3.js} +1 -1
- package/dist/assets/framework-BLEk-ou3.js +34 -0
- package/dist/assets/{highlighted-body-OFNGDK62-JYK0hMjr.js → highlighted-body-OFNGDK62-DiT7C6XW.js} +1 -1
- package/dist/assets/index-CJe1zUD0.css +2 -0
- package/dist/assets/index-DdQV1cqi.js +4 -0
- package/dist/assets/{mergeServerFields-CM4cY1zR.js → mergeServerFields-djmY7AgR.js} +2 -2
- package/dist/assets/mermaid-GHXKKRXX-CK-9EMhD.js +1 -0
- package/dist/assets/metadata-admin-BbJpmVQm.js +19 -0
- package/dist/assets/{plugin-calendar-DCCbdIpj.js → plugin-calendar-DQC9zdKq.js} +1 -1
- package/dist/assets/{plugin-charts-Do3qrshN.js → plugin-charts-AMObsZz3.js} +1 -1
- package/dist/assets/plugin-chatbot-Ch8YIyYL.js +120 -0
- package/dist/assets/plugin-dashboard-C7fxXXeO.js +5 -0
- package/dist/assets/plugin-form-gQDKenio.js +1 -0
- package/dist/assets/plugin-gantt-BHmpu6VX.js +23 -0
- package/dist/assets/plugin-grid-boi_rkH3.js +6 -0
- package/dist/assets/{plugin-kanban-CYKs5Fuv.js → plugin-kanban-DOsTOpJz.js} +1 -1
- package/dist/assets/{plugin-map-DuGG00x5.js → plugin-map-Bid9UXOR.js} +1 -1
- package/dist/assets/{plugin-markdown-Du1ajwhj.js → plugin-markdown-BUQOG31j.js} +13 -1
- package/dist/assets/{plugin-report-D0COS83c.js → plugin-report-FxG9jOvy.js} +1 -1
- package/dist/assets/plugin-timeline-DDrFKEb8.js +1 -0
- package/dist/assets/plugin-view-DhNkNfUe.js +1 -0
- package/dist/assets/plugins-views-DUKPQNs8.js +4 -0
- package/dist/assets/resolveActionParams-C_x4GXvS.js +9 -0
- package/dist/assets/{skeletons-Cdt8ttDk.js → skeletons-B_SNEnMn.js} +1 -1
- package/dist/assets/src-Bzm5L_v8.js +2 -0
- package/dist/assets/{src-BPf-hjw2.js → src-DbxuLwqh.js} +1 -1
- package/dist/assets/{types-DjNzBgbB.js → types-CosU35As.js} +1 -1
- package/dist/assets/ui-components-CrPYFyEM.js +42 -0
- package/dist/assets/{ui-layout-D19iPz4K.js → ui-layout-DAWxaQvy.js} +1 -1
- package/dist/assets/{useActionModal-BKaoxO40.js → useActionModal-DDu3wUOI.js} +1 -1
- package/dist/assets/useReconcileOnError-Agbi2njU.js +1 -0
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/dist/assets/ApiConsolePage-DGCgQ6RS.js +0 -1
- package/dist/assets/AppDocsIndex-B_hZ36LW.js +0 -1
- package/dist/assets/AppManagementPage-DN-u3YQP.js +0 -1
- package/dist/assets/ComponentNavView-B6LSKpd-.js +0 -1
- package/dist/assets/ConsoleFloatingChatbot-CsiQ_KDu.js +0 -1
- package/dist/assets/FlowRunsPage-DcT6ntvZ.js +0 -1
- package/dist/assets/PageView-CxOhEFic.js +0 -1
- package/dist/assets/PublicFormsPage-N0Wofan4.js +0 -1
- package/dist/assets/RecordDetailView-Bh6I2k3c.js +0 -1
- package/dist/assets/SystemHubPage-_i5E_SOC.js +0 -1
- package/dist/assets/framework-DLckRGJs.js +0 -34
- package/dist/assets/index-DGuFGryh.css +0 -2
- package/dist/assets/index-JrHkY-wh.js +0 -4
- package/dist/assets/mermaid-GHXKKRXX-Bg8PoWKD.js +0 -1
- package/dist/assets/metadata-admin-B5WWi7HS.js +0 -19
- package/dist/assets/plugin-chatbot-DF5LNhQ2.js +0 -120
- package/dist/assets/plugin-dashboard-BQ3awX8y.js +0 -5
- package/dist/assets/plugin-form-FmgnWzcl.js +0 -1
- package/dist/assets/plugin-gantt-CWw13thv.js +0 -23
- package/dist/assets/plugin-grid-Cd-2qFJP.js +0 -6
- package/dist/assets/plugin-timeline-BBYlrrgQ.js +0 -1
- package/dist/assets/plugin-view-BhoDHK4P.js +0 -1
- package/dist/assets/plugins-views-gs7PYt1Y.js +0 -4
- package/dist/assets/resolveActionParams-DjRjW-gD.js +0 -9
- package/dist/assets/ui-components-B2CBE2Rs.js +0 -42
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css","./plugin-map-CsMXqW6n.css"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{o as e,r as t}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as n,a as r,c as i,d as a,f as o,h as s,i as c,l,m as u,n as d,o as f,p,r as m,s as h,t as g,u as _}from"./vendor-react-DR370ovB.js";import{a as v,c as y,d as b,f as x,i as S,l as C,n as w,o as T,p as E,r as D,s as O,u as k}from"./infrastructure-CJNwTVno.js";import{A,B as j,F as M,I as N,N as P,O as ee,T as F,U as te,V as I,a as ne,at as L,b as R,ct as re,et as z,ht as B,j as ie,n as ae,o as V,ot as oe,r as H,w as se}from"./framework-DLckRGJs.js";import{$a as ce,$i as le,$n as ue,$r as de,$t as U,Aa as fe,Ai as W,An as pe,Ar as me,Ba as he,Bn as ge,Bo as _e,Bt as ve,Co as ye,Cs as be,Ct as xe,Da as Se,Dt as Ce,Ea as we,Eo as Te,Es as Ee,F as G,Fi as De,Fn as K,Fo as Oe,Fr as ke,Fs as Ae,Ft as je,Gi as Me,Gt as Ne,H as Pe,Ha as Fe,Hn as Ie,Hs as Le,Ht as Re,I as ze,Ia as Be,In as Ve,Io as He,Ir as Ue,It as We,Ja as Ge,Ji as Ke,Jn as qe,Js as Je,Ka as Ye,Ks as Xe,La as Ze,Li as Qe,Ln as $e,Lo as et,Lr as tt,Lt as nt,Ma as q,Mn as rt,Mr as it,Ms as at,Nn as ot,Ns as st,O as ct,Oa as lt,Oo as ut,Os as dt,Pa as ft,Pn as pt,Po as mt,Pr as ht,Pt as gt,Qo as _t,Qr as vt,R as yt,Ra as bt,Rn as xt,Rr as St,Rt as Ct,Sa as wt,Si as Tt,Sr as Et,St as Dt,Ta as Ot,Tr as kt,Ts as At,Tt as jt,Ui as Mt,Uo as Nt,Ur as Pt,Ut as Ft,Va as It,Vn as Lt,Vr as Rt,Vt as zt,Wo as Bt,Ws as Vt,Wt as Ht,Xa as Ut,Xi as Wt,Xn as Gt,Yn as Kt,Yo as qt,Zn as Jt,Zo as Yt,Zr as Xt,Zs as Zt,_ as Qt,_a as $t,_i as en,_o as tn,_t as nn,aa as rn,ac as an,ao as on,as as sn,at as cn,b as ln,bo as un,bt as dn,ca as fn,ci as pn,cn as mn,co as hn,cr as gn,cs as _n,da as vn,dc as yn,di as bn,dn as xn,do as Sn,dr as Cn,ds as wn,ea as Tn,ei as En,en as Dn,er as On,es as kn,fn as An,fr as jn,ga as Mn,gi as Nn,gn as Pn,gs as Fn,gt as In,hr as J,ht as Ln,ia as Rn,ii as zn,io as Bn,it as Vn,ja as Hn,ji as Un,jn as Wn,jr as Gn,ka as Kn,ko as qn,ks as Jn,li as Yn,ln as Xn,lo as Zn,lr as Qn,ma as $n,mc as er,mt as tr,na as nr,ni as rr,nn as Y,nr as ir,ns as ar,nt as or,oa as sr,oc as cr,oi as lr,on as ur,oo as dr,or as fr,pr,qn as mr,ra as hr,ri as gr,rs as _r,rt as vr,si as yr,sn as br,sr as xr,tc as Sr,tn as Cr,to as wr,tr as Tr,ts as Er,tt as Dr,uc as Or,un as kr,ur as Ar,v as jr,vi as Mr,vr as Nr,vt as Pr,w as Fr,ws as Ir,wt as Lr,xs as Rr,y as zr,ya as Br,yi as Vr,yr as Hr,ys as Ur,yt as Wr,z as Gr,za as Kr,zn as qr,zr as Jr,zt as Yr}from"./ui-components-B2CBE2Rs.js";import{a as Xr,n as Zr,o as Qr,r as X}from"./vendor-ui-utils-rQOI1gAo.js";import{r as $r}from"./data-adapter-CzKUUIgi.js";import{t as ei}from"./AdapterProvider-CGofnJBf.js";import{n as ti,r as ni}from"./plugin-form-FmgnWzcl.js";import{a as ri,c as ii,l as ai,s as oi,t as si,u as ci}from"./MetadataProvider-_6IU7cWK.js";import{n as li,r as ui,t as di}from"./ExpressionProvider-wi1dJ2tN.js";import{n as fi,o as pi,r as mi,t as hi}from"./RecentItemsProvider-B76qldBH.js";import{i as gi,r as _i,t as vi}from"./useActionModal-BKaoxO40.js";import{a as yi,c as bi,i as xi,l as Si,o as Ci,r as wi,s as Ti,t as Ei}from"./RecordDetailView-Bh6I2k3c.js";import{n as Di,r as Oi,t as ki}from"./ui-layout-D19iPz4K.js";import{a as Ai,d as ji,f as Mi,i as Ni,m as Pi,p as Fi,t as Ii,u as Li}from"./plugin-chatbot-DF5LNhQ2.js";import{C as Ri,r as zi}from"./mergeServerFields-CM4cY1zR.js";import{n as Bi,t as Vi}from"./appRoute-D5vwtoc_.js";import{a as Hi,c as Ui,i as Wi,l as Gi,n as Ki,o as qi,r as Ji,s as Yi}from"./metadata-admin-B5WWi7HS.js";import{a as Xi,n as Zi,o as Qi,r as $i,s as ea,t as ta}from"./utils-bipVuqQL.js";import{n as na,r as ra,t as ia}from"./MetadataInspector-BGWYqUse.js";import{b as aa,n as oa,v as sa,x as ca,y as la}from"./marketplaceApi-CucX7DD9.js";import{n as ua,r as da}from"./InterfaceListPage-DAJiEE0k.js";import{c as fa}from"./plugins-views-gs7PYt1Y.js";import{i as pa,r as ma}from"./plugin-grid-Cd-2qFJP.js";import{a as ha,c as ga,i as _a,l as va,n as ya,o as ba,r as xa,s as Sa,t as Ca,u as wa}from"./plugin-view-BhoDHK4P.js";import{n as Ta,r as Ea,t as Da}from"./RuntimeDraftBar-DaYAgW5v.js";import{t as Oa}from"./ManagedByBadge-BAL_PuGz.js";import"./resolveActionParams-DjRjW-gD.js";import{n as ka}from"./PageView-CxOhEFic.js";import"./RecordFormPage-1zrrumdr.js";import"./DashboardView-CsknMwAh.js";import"./ReportView-q3jNGyaI.js";import"./SearchResultsPage-BRnB7VD4.js";import"./MarketplacePage-CoigR7d_.js";import"./MarketplacePackagePage-SKgqOj7g.js";import"./MarketplaceInstalledPage-CaN54GxZ.js";import{r as Aa,t as ja}from"./plugin-markdown-Du1ajwhj.js";var Z=e(n(),1),Ma=e(s(),1),Q=g(),Na={type:`object-master-detail-form`,objectName:`expense_claim`,mode:`create`,formType:`simple`,title:`New Expense Claim`,submitText:`Create Claim`,fields:[`title`,`applicant`,`department`,`reason`,`currency`,`claim_status`,`payment_status`,`remarks`],details:[{title:`Expense Lines`,childObject:`expense_line`,relationshipField:`expense_claim`,amountField:`amount`,totalField:`total_amount`,columns:[{field:`expense_date`,label:`Date`,type:`date`},{field:`category`,label:`Category`,type:`select`,options:[{label:`Travel & Transport`,value:`travel_transport`},{label:`Lodging`,value:`lodging`},{label:`Meals & Entertainment`,value:`meals_entertainment`},{label:`Office Supplies`,value:`office_supplies`},{label:`Communications`,value:`communications`},{label:`Training & Conference`,value:`training_conference`},{label:`Client / Project`,value:`client_project`},{label:`Other`,value:`other`}]},{field:`description`,label:`Description`,type:`text`},{field:`merchant_vendor`,label:`Merchant`,type:`text`},{field:`amount`,label:`Amount`,type:`currency`}]}]},Pa=()=>(0,Q.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6`,children:[(0,Q.jsx)(`h1`,{className:`mb-4 text-lg font-semibold`,children:`Dev · Master-Detail Form (ADR-0001)`}),(0,Q.jsx)(j,{schema:Na})]}),Fa={type:`element:definition-list`,properties:{columns:2,items:[{term:`Status`,description:`Active`},{term:`Owner`,description:`Ada Lovelace`},{term:`Plan`,description:`Enterprise`},{term:`Renewal`,description:`2026-12-01`}]}},Ia={type:`element:repeater`,properties:{object:`showcase_category`,titleField:`name`,fields:[`color`],limit:10,emptyText:`No categories`}},La=()=>(0,Q.jsxs)(`div`,{className:`mx-auto max-w-2xl space-y-8 p-6`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`mb-3 text-lg font-semibold`,children:`Dev · element:definition-list`}),(0,Q.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,Q.jsx)(j,{schema:Fa})})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`mb-3 text-lg font-semibold`,children:`Dev · element:repeater (showcase_category)`}),(0,Q.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,Q.jsx)(j,{schema:Ia})})]})]});function Ra({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i,onConfirm:a,onToast:s}){let c=_(),{appName:l}=o(),{t:u}=H(),d=`/apps/${l}`,{execute:f,loading:p,error:m,runner:h}=N({context:{objectName:e,objectLabel:t||e,baseUrl:d},onConfirm:a,onToast:s});return(0,Z.useEffect)(()=>{h.registerHandler(`create`,async()=>(r?.(null),{success:!0})),h.registerHandler(`delete`,async r=>{let a=Array.isArray(r.params?.records)?r.params.records.filter(e=>e?.id!=null):null;if(a&&a.length>1){let r=await Promise.allSettled(a.map(t=>n.delete(e,t.id))),o=r.filter(e=>e.status===`rejected`).length,s=r.length-o;return i?.(),o===0?(X.success(u(`objectActions.bulkDeleteSuccess`,{count:s,label:t||e,defaultValue:`Deleted ${s} ${t||e} records`})),{success:!0,reload:!0}):(X.error(u(`objectActions.bulkDeletePartial`,{succeeded:s,failed:o,defaultValue:`${s} deleted, ${o} failed`})),{success:!1,error:`${o} failed`})}let o=r.params?.recordId??r.params?.record?.id??a?.[0]?.id??r.recordId;if(!o)return{success:!1,error:u(`objectActions.noRecordId`)};try{return await n.delete(e,o),i?.(),X.success(u(`objectActions.deleteSuccess`,{label:t||e})),{success:!0,reload:!0}}catch(n){return X.error(u(`objectActions.deleteFailed`,{label:t||e}),{description:n.message}),{success:!1,error:n.message}}}),h.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&c(t.startsWith(`/`)?t:`${d}/${t}`),{success:!0}}),h.registerHandler(`refresh`,async()=>(i?.(),{success:!0,reload:!0}))},[h,e,n,r,i,c,d,u,t]),{execute:f,create:(0,Z.useCallback)(()=>{r?.(null)},[r]),deleteRecord:(0,Z.useCallback)(async e=>f({type:`delete`,confirmText:u(`objectActions.deleteConfirm`),params:{recordId:e}}),[f,u]),navigateToView:(0,Z.useCallback)(t=>{c(`${d}/${e}/view/${t}`)},[c,d,e]),navigateToRecord:(0,Z.useCallback)(t=>{c(`${d}/${e}/record/${encodeURIComponent(t)}`)},[c,d,e]),loading:p,error:m}}var za=(0,Z.createContext)({theme:`system`,setTheme:()=>null});function Ba({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`,...r}){let[i,a]=(0,Z.useState)(()=>localStorage.getItem(n)||t);(0,Z.useEffect)(()=>{let e=window.document.documentElement;if(e.classList.remove(`light`,`dark`),i===`system`){let t=window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`;e.classList.add(t);return}e.classList.add(i)},[i]);let o={theme:i,setTheme:e=>{localStorage.setItem(n,e),a(e)}};return(0,Q.jsx)(za.Provider,{...r,value:o,children:e})}var Va=()=>{let e=(0,Z.useContext)(za);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function Ha(){return(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function Ua({children:e}){return(0,Q.jsx)(Ba,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Q.jsx)(bi,{children:(0,Q.jsx)(mi,{children:(0,Q.jsx)(_i,{children:(0,Q.jsx)(hi,{children:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Ha,{}),children:e})})})})})})}function Wa({children:e}){return(0,Q.jsx)(ei,{children:(0,Q.jsx)(ii,{children:(0,Q.jsx)(Ga,{children:e})})})}function Ga({children:e}){let t=se(),{language:n}=H(),r=(0,Z.useRef)(null);return t&&r.current!==null&&r.current!==n&&t.clearCache?.(),t&&(r.current=n),t?(0,Q.jsx)(te,{dataSource:t,children:(0,Q.jsxs)(si,{adapter:t,children:[(0,Q.jsx)(Ka,{}),e]},n)}):(0,Q.jsx)(Ha,{})}function Ka(){let{user:e}=x(),t=se(),n=pi();return(0,Z.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null);return}let r=$r({dataSource:t,userId:e.id,key:`ui.favorites`}),i=$r({dataSource:t,userId:e.id,key:`ui.recent`});return n(`favorites`,r),n(`recent`,i),()=>{n(`favorites`,null),n(`recent`,null)}},[e?.id,t,n]),null}function qa({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:i}=x();return i?(0,Q.jsx)(Ha,{}):((n??[]).length>0||t)&&!t?(0,Q.jsx)(r,{to:`/organizations`,replace:!0}):(0,Q.jsx)(Q.Fragment,{children:e})}function Ja(){let e=l(),t=e.pathname.replace(/^\/system/,``);return(0,Q.jsx)(r,{to:`${t?`/apps/setup/system${t}`:`/apps/setup`}${e.search}${e.hash}`,replace:!0})}var Ya=(0,Z.lazy)(()=>u(()=>import(`./ConsoleFloatingChatbot-CsiQ_KDu.js`),__vite__mapDeps([0]),import.meta.url)),Xa=()=>{u(()=>import(`./ConsoleFloatingChatbot-CsiQ_KDu.js`),__vite__mapDeps([0]),import.meta.url)};function Za(e){let[t,n]=(0,Z.useState)(!1),{t:r}=H(),{openSeq:i}=ri(),a=(0,Z.useRef)(i);return(0,Z.useEffect)(()=>{i!==a.current&&(a.current=i,n(!0))},[i]),t?(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(Ya,{...e,defaultOpen:!0})}):(0,Q.jsx)(`button`,{type:`button`,"aria-label":r(`topbar.openAssistant`,{defaultValue:`Open {{name}} assistant`,name:e.appLabel}),onClick:()=>n(!0),onMouseEnter:Xa,onFocus:Xa,className:`fixed bottom-20 right-6 z-50 flex h-14 w-14 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg ring-1 ring-primary/20 transition-transform hover:scale-105 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 sm:bottom-6`,"data-testid":`console-chatbot-fab`,children:(0,Q.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,Q.jsx)(`path`,{d:`M12 3v3`}),(0,Q.jsx)(`path`,{d:`M12 18v3`}),(0,Q.jsx)(`path`,{d:`M5.6 5.6l2.1 2.1`}),(0,Q.jsx)(`path`,{d:`M16.3 16.3l2.1 2.1`}),(0,Q.jsx)(`path`,{d:`M3 12h3`}),(0,Q.jsx)(`path`,{d:`M18 12h3`}),(0,Q.jsx)(`path`,{d:`M5.6 18.4l2.1-2.1`}),(0,Q.jsx)(`path`,{d:`M16.3 7.7l2.1-2.1`}),(0,Q.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})})}function Qa(e){let t=Ri(),[n,r]=(0,Z.useState)(!1);return{publishAll:(0,Z.useCallback)(async()=>{r(!0);try{let n=(await t.listDrafts?.({})||[]).filter(e=>e&&typeof e.type==`string`&&typeof e.name==`string`).map(e=>({type:e.type,name:e.name,packageId:typeof e.packageId==`string`&&e.packageId?e.packageId:null}));if(n.length===0)return X.info(e(`home.pendingDrafts.nothing`,{defaultValue:`Nothing to publish.`})),{ok:!0,attempted:0};let r=[...new Set(n.map(e=>e.packageId).filter(e=>e!==null))],i=n.filter(e=>e.packageId===null),a=[],o=[],s=0,c=e=>{if(e){e.seedError&&a.push(e.seedError),typeof e.seededRows==`number`&&(s+=e.seededRows);for(let t of e.issues??[])t.severity===`error`&&o.push(t.message)}};for(let e of r){let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);c(Ai(n))}let l=[...i.filter(e=>e.type!==`seed`),...i.filter(e=>e.type===`seed`)];for(let e of l){let n=(await t.publishDraft(e.type,e.name))?.seedApplied;n&&n.success===!1&&a.push(n.error??`${e.name}: sample data failed to load`)}return o.length>0?X.warning(e(`home.pendingDrafts.probeWarn`,{defaultValue:`Published, but verification found problems.`}),{description:o[0]}):a.length>0?X.warning(e(`home.pendingDrafts.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:a[0]}):X.success(s>0?e(`home.pendingDrafts.publishedVerified`,{count:s,defaultValue:`Published & verified — {{count}} sample row(s) live.`}):e(`home.pendingDrafts.published`,{defaultValue:`Published! Your changes are live.`})),{ok:!0,attempted:n.length}}catch(t){return X.error(`${e(`home.pendingDrafts.publishFailed`,{defaultValue:`Publish failed`})}: ${t.message}`),{ok:!1,attempted:0}}finally{r(!1)}},[t,e]),publishing:n}}async function $a(){let e=await fetch(`/api/v1/meta/_drafts`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!e.ok)throw Error(`_drafts HTTP ${e.status}`);let t=await e.json();return(Array.isArray(t)?t:t?.drafts??[]).filter(e=>typeof e?.type==`string`&&typeof e?.name==`string`).map(e=>({type:e.type,name:e.name,packageId:typeof e.packageId==`string`&&e.packageId?e.packageId:null}))}async function eo(e){let t=await fetch(`/api/v1/meta/${encodeURIComponent(e)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`published list HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.items??[];return new Set(r.map(e=>typeof e?.name==`string`?e.name:null).filter(e=>e!==null))}function to({open:e,onOpenChange:t}){let{t:n}=H(),[r,i]=(0,Z.useState)(null),[a,o]=(0,Z.useState)(null),s=(0,Z.useCallback)(async()=>{i(null),o(null);try{let e=await $a();i(e);let t=[...new Set(e.map(e=>e.type))];await Promise.all(t.map(async e=>{let t=null;try{t=await eo(e)}catch{return}i(n=>n&&n.map(n=>n.type===e?{...n,kind:t.has(n.name)?`update`:`new`}:n))}))}catch(e){o(e.message)}},[]);(0,Z.useEffect)(()=>{e&&s()},[e,s]);let c=new Map;for(let e of r??[]){let t=c.get(e.type)??[];t.push(e),c.set(e.type,t)}return(0,Q.jsx)(gt,{open:e,onOpenChange:t,children:(0,Q.jsxs)(je,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`draft-changes-panel`,children:[(0,Q.jsxs)(nt,{children:[(0,Q.jsx)(Ct,{children:n(`preview.changes.title`,{defaultValue:`Pending changes`})}),(0,Q.jsx)(We,{children:n(`preview.changes.description`,{defaultValue:`What publishing will change. New items are added; updates overwrite the live version.`})})]}),(0,Q.jsx)(`div`,{className:`mt-4 flex flex-col gap-4 overflow-y-auto px-4 pb-6`,children:a?(0,Q.jsxs)(`p`,{className:`text-sm text-destructive`,children:[n(`preview.changes.loadFailed`,{defaultValue:`Could not load pending changes:`}),` `,a]}):r===null?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(q,{className:`h-4 w-4 animate-spin`}),n(`preview.changes.loading`,{defaultValue:`Loading pending changes…`})]}):r.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`preview.changes.empty`,{defaultValue:`Nothing pending — every draft has been published.`})}):[...c.entries()].map(([e,t])=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`h4`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:[e,` · `,t.length]}),(0,Q.jsx)(`ul`,{className:`flex flex-col gap-1`,children:t.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-2 rounded-md border px-2.5 py-1.5 text-sm`,children:[e.kind===`new`?(0,Q.jsx)(ut,{className:`h-3.5 w-3.5 shrink-0 text-emerald-600`}):e.kind===`update`?(0,Q.jsx)(qn,{className:`h-3.5 w-3.5 shrink-0 text-amber-600`}):(0,Q.jsx)(q,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs`,children:e.name}),e.kind?(0,Q.jsx)(ue,{variant:`outline`,className:e.kind===`new`?`border-emerald-200 bg-emerald-50 text-emerald-700`:`border-amber-200 bg-amber-50 text-amber-700`,children:e.kind===`new`?n(`preview.changes.kindNew`,{defaultValue:`New`}):n(`preview.changes.kindUpdate`,{defaultValue:`Update`})}):null]},`${e.type}:${e.name}`))})]},e))})]})})}function no(){let e=ci(),t=l(),n=_(),{t:r}=H(),{publishAll:i,publishing:a}=Qa(r),[o,s]=(0,Z.useState)(!1),[c,u]=(0,Z.useState)(null);if((0,Z.useEffect)(()=>{if(!e)return;let t=!1;return fetch(`/api/v1/meta/_drafts`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`}).then(e=>e.ok?e.json():null).then(e=>{if(t||!e)return;let n=Array.isArray(e)?e:e?.drafts??[];u(Array.isArray(n)?n.length:null)}).catch(()=>{}),()=>{t=!0}},[e,t.pathname]),!e)return null;let d=()=>{ai();let e=new URLSearchParams(t.search);e.delete(oi);let r=e.toString();n(`${t.pathname}${r?`?${r}`:``}${t.hash}`,{replace:!0})};return(0,Q.jsxs)(`div`,{className:`sticky top-0 z-40 flex items-center gap-3 border-b border-amber-300/70 bg-amber-50 px-4 py-2 text-sm text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/40 dark:text-amber-200`,"data-testid":`draft-preview-bar`,children:[(0,Q.jsx)(mt,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:r(`preview.draftBar.message`,{defaultValue:`Draft preview — you are seeing unpublished changes. Nothing here is live until you publish.`})}),(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>s(!0),"data-testid":`draft-preview-changes`,children:[(0,Q.jsx)(hn,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.changes`,{defaultValue:`Changes`}),typeof c==`number`?` (${c})`:``]}),(0,Q.jsxs)(J,{size:`sm`,onClick:async()=>{(await i()).ok&&(d(),setTimeout(()=>{try{window.location.reload()}catch{}},300))},disabled:a,"data-testid":`draft-preview-publish`,children:[(0,Q.jsx)(Un,{className:`mr-1 h-3.5 w-3.5`}),a?r(`preview.draftBar.publishing`,{defaultValue:`Publishing…`}):r(`preview.draftBar.publish`,{defaultValue:`Publish`})]}),(0,Q.jsx)(to,{open:o,onOpenChange:s}),(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:d,"data-testid":`draft-preview-exit`,children:[(0,Q.jsx)(Et,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.exit`,{defaultValue:`Exit preview`})]})]})}function ro(){let e=ci(),{appName:t}=o(),n=l(),{apps:r,refresh:i}=F(),{t:a}=H(),[s,c]=(0,Z.useState)(!1);if(e)return null;let u=t??n.pathname.match(/\/apps\/([^/?#]+)/)?.[1];if(!u)return null;let d=Bi(r??[],u);return!d||d.hidden!==!0?null:(0,Q.jsxs)(`div`,{className:`sticky top-0 z-40 flex items-center gap-3 border-b border-amber-300/70 bg-amber-50 px-4 py-2 text-sm text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/40 dark:text-amber-200`,"data-testid":`unpublished-app-bar`,children:[(0,Q.jsx)(Oe,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:a(`preview.unpublishedBar.message`,{defaultValue:`Unpublished app — fully functional, but only builders can see it. Publish to make it visible to your users.`})}),(0,Q.jsxs)(J,{size:`sm`,onClick:async()=>{c(!0);try{let e=await fetch(`/api/v1/meta/app/${encodeURIComponent(u)}`,{method:`PUT`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({...d,hidden:!1})});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message??t?.error??`HTTP ${e.status}`)}X.success(a(`preview.unpublishedBar.published`,{defaultValue:`Published! The app is now visible to your users.`})),i?.()}catch(e){X.error(`${a(`preview.unpublishedBar.publishFailed`,{defaultValue:`Publish failed`})}: ${e.message}`)}finally{c(!1)}},disabled:s,"data-testid":`unpublished-app-publish`,children:[(0,Q.jsx)(Un,{className:`mr-1 h-3.5 w-3.5`}),s?a(`preview.unpublishedBar.publishing`,{defaultValue:`Publishing…`}):a(`preview.unpublishedBar.publish`,{defaultValue:`Publish`})]})]})}var io=20;function ao(e,t=``){let{href:n,external:r}=Di(e,t);return r?n:!n||n===`#`?``:n}function oo(e){return`nav:${e}`}function so(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=gi(),a=(0,Z.useCallback)((e,i,a,o)=>{let s=oo(e);i?(a&&t({id:s,label:a.label,href:ao(a,o??``),type:`nav`,navId:e,pinned:!0}),r(s,!0)):n(s)},[t,n,r]),o=(0,Z.useCallback)(e=>i.has(e),[i]),s=(0,Z.useCallback)(e=>{if(i.size===0){let t=!1;for(let n of e)if(n.pinned){t=!0;break}if(!t)return e}let t=0,n=e=>e.map(e=>{let r=i.has(e.id)&&t<io;r&&t++;let a=e.children?.length?n(e.children):e.children;return r!==(e.pinned??!1)||a!==e.children?{...e,pinned:r,children:a}:e});return n(e)},[i]),c=(0,Z.useCallback)(()=>{for(let t of e)t.type===`nav`&&n(t.id)},[e,n]);return{pinnedIds:(0,Z.useMemo)(()=>Array.from(i),[i]),togglePin:a,isPinned:o,applyPins:s,clearPins:c}}var co=`__all__`;function lo(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function uo(e){if(Array.isArray(e))return e;let t=e?.data??e;return Array.isArray(t)?t:Array.isArray(t?.packages)?t.packages:Array.isArray(t?.items)?t.items:Array.isArray(e?.items)?e.items:[]}function fo(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=lo(e,n.key),r=n.op??`eq`,i=Array.isArray(n.value)?n.value:[n.value];switch(r){case`eq`:if(t!==n.value)return!1;break;case`ne`:if(t===n.value)return!1;break;case`in`:if(!i.includes(t))return!1;break;case`nin`:if(i.includes(t))return!1;break}}return!0}function po(e){let[t,n]=Z.useState([]),r=e.optionsSource.endpoint,i=e.optionsSource.valueKey||`id`,a=e.optionsSource.labelKey||`name`,o=e.optionsSource.filter,s=JSON.stringify(o??[]);return Z.useEffect(()=>{let e=!1;return(async()=>{try{let t=await fetch(r,{credentials:`include`,headers:{Accept:`application/json`}});if(!t.ok)return;let s=await t.json();if(e)return;let c=uo(s),l=[],u=new Set;for(let e of c){if(!fo(e,o))continue;let t=lo(e,i);if(t==null||typeof t!=`string`||u.has(t))continue;u.add(t);let n=lo(e,a);l.push({value:t,label:typeof n==`string`&&n?n:t})}l.sort((e,t)=>e.label.localeCompare(t.label)),n(l)}catch{}})(),()=>{e=!0}},[r,i,a,s]),t}function mo(e,t,n){let r=Array.isArray(t)?t:[],i=_(),a=l(),o=new URLSearchParams(a.search);Z.useEffect(()=>{let t=new URLSearchParams(a.search),n=!1;for(let i of r)if(i.persist!==`none`&&!t.get(`package`))try{let r=sessionStorage.getItem(`objectui-ctx-${e}-${i.id}`);r&&(t.set(`package`,r),n=!0)}catch{}n&&i({pathname:a.pathname,search:t.toString()},{replace:!0})},[e,r,a.pathname,a.search,i]);let s=Z.useCallback((t,n)=>{let r=n===co?t.allValue??``:n;try{let n=`objectui-ctx-${e}-${t.id}`;r?sessionStorage.setItem(n,r):sessionStorage.removeItem(n)}catch{}let o=new URLSearchParams(a.search);r?o.set(`package`,r):o.delete(`package`),i({pathname:a.pathname,search:o.toString()},{replace:!0})},[e,a.pathname,a.search,i]),c={};for(let t of r){let n=``;try{n=sessionStorage.getItem(`objectui-ctx-${e}-${t.id}`)??``}catch{}c[t.id]=(o.get(`package`)??n)||(t.allValue??``)}return{contextValues:c,element:r.length===0?null:(0,Q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(e=>(0,Q.jsx)(ho,{def:e,value:c[e.id],onChange:t=>s(e,t),t:n},e.id))})}}function ho({def:e,value:t,onChange:n,t:r}){let i=po(e),a=Gi(e.icon),o=$i(e.label,r)||e.id,s=o===`Package`?r?.(`common.package`,{defaultValue:o})??o:o,c=r?.(`actionDialog.selectPlaceholder`,{label:s,defaultValue:`Select ${s}…`})??`Select ${s}…`,l=!!t&&t!==(e.allValue??``);return Z.useEffect(()=>{l||i.length>0&&n(i[0].value)},[l,n,i]),(0,Q.jsxs)(ve,{value:l?t:``,onValueChange:n,children:[(0,Q.jsx)(Ft,{"aria-label":s,className:`h-9 w-full gap-2 rounded-md border-sidebar-border/70 bg-sidebar/80 px-2 text-xs font-medium text-sidebar-foreground shadow-none transition-colors hover:bg-sidebar-accent focus:ring-1 focus:ring-sidebar-ring data-[state=open]:bg-sidebar-accent [&>svg]:h-3.5 [&>svg]:w-3.5 [&>svg]:shrink-0`,children:(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2 overflow-hidden`,children:[(0,Q.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded border border-sidebar-border/70 bg-sidebar-accent text-sidebar-foreground/70`,children:(0,Q.jsx)(a,{className:`h-3 w-3`})}),(0,Q.jsx)(Ht,{placeholder:c,className:`truncate`})]})}),(0,Q.jsx)(zt,{className:`w-[var(--radix-select-trigger-width)]`,children:i.map(e=>(0,Q.jsx)(Re,{value:e.value,children:e.label},e.value))})]})}var go=Z.forwardRef(({className:e,onClick:t,"aria-label":n,title:r,...i},a)=>{let{toggleSidebar:o}=Ce(),{t:s}=H(),c=String(n||r||s(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`}));return(0,Q.jsxs)(J,{ref:a,"data-sidebar":`trigger`,variant:`ghost`,size:`icon`,className:yn(`h-7 w-7`,e),"aria-label":c,title:c,onClick:e=>{t?.(e),o()},...i,children:[(0,Q.jsx)(Rn,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:c})]})});go.displayName=`LocalizedSidebarTrigger`;function _o(e){let t=`objectui-nav-order-${e}`,[n,r]=Z.useState(()=>{try{let e=localStorage.getItem(t);if(!e)return{};let n=JSON.parse(e);if(typeof n!=`object`||!n||Array.isArray(n))return{};let r={};for(let[e,t]of Object.entries(n))Array.isArray(t)&&t.every(e=>typeof e==`string`)&&(r[e]=t);return r}catch{return{}}}),i=Z.useCallback(e=>{r(e);try{localStorage.setItem(t,JSON.stringify(e))}catch{}},[t]);return{applyOrder:Z.useCallback(e=>{let t=n.__root__;if(!t)return e;let r=new Map(e.map(e=>[e.id,e])),i=[];for(let e of t){let t=r.get(e);t&&(i.push(t),r.delete(e))}return r.forEach(e=>i.push(e)),i},[n]),handleReorder:Z.useCallback(e=>{let t=e.map(e=>e.id);i({...n,__root__:t})},[n,i])}}function vo(e){return e.componentRef===`metadata:directory`}function yo(e){return e.componentRef===`developer:packages`}function bo(e){if(e.type!==`group`)return!1;let t=String(e.id??``).toLowerCase(),n=typeof e.label==`string`?e.label.toLowerCase():``;return t===`overview`||n===`overview`}function xo({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=Ce(),r=l(),{t:i}=H(),{objectLabel:a,dashboardLabel:o,navGroupLabel:s,viewLabel:c}=er(),{context:u,currentAppName:d}=Si(),{user:f}=x(),p=b();Z.useEffect(()=>{let e=0,n=t=>{e=t.touches[0].clientX},r=n=>{let r=n.changedTouches[0].clientX-e;e<30&&r>50&&t&&document.querySelector(`[data-sidebar="trigger"]`)?.dispatchEvent(new MouseEvent(`click`,{bubbles:!0}))};return document.addEventListener(`touchstart`,n,{passive:!0}),document.addEventListener(`touchend`,r,{passive:!0}),()=>{document.removeEventListener(`touchstart`,n),document.removeEventListener(`touchend`,r)}},[t]);let{recentItems:h}=fi(),{favorites:g,removeFavorite:_}=gi(),{apps:v,objects:y}=F(),S=v||[],C=S.filter(e=>e.active!==!1&&e.hidden!==!0),T=Bi(S.filter(e=>e.active!==!1),e||d)||C[0],{applyOrder:E,handleReorder:D}=_o(T?.name||`home`),{togglePin:O,applyPins:k}=so(),A=T?.areas||[],[j,M]=Z.useState(()=>A.length>0?A[0].id:null);Z.useEffect(()=>{A.length>0?M(e=>A.some(t=>t.id===e)?e:A[0].id):M(null)},[T?.name,A.length]);let N=A.find(e=>e.id===j)?.navigation||T?.navigation||[],{contextValues:P,element:ee}=mo(T?.name||`home`,T?.contextSelectors,i),te=Z.useMemo(()=>{let e=[{id:`home-dashboard`,label:i(`home.nav`,{defaultValue:`Home`}),type:`url`,url:`/home`,icon:`home`},{id:`docs`,label:i(`layout.systemNav.documentation`,{defaultValue:`Documentation`}),type:`url`,url:`/docs`,icon:`book-open`}];if(p){let t=[{id:`sys-settings`,label:i(`layout.systemNav.systemSettings`,{defaultValue:`System Settings`}),type:`url`,url:`/apps/setup`,icon:`settings`},{id:`sys-apps`,label:i(`layout.systemNav.applications`,{defaultValue:`Applications`}),type:`url`,url:`/apps/setup/system/apps`,icon:`layout-grid`},{id:`sys-marketplace`,label:i(`layout.systemNav.appMarketplace`,{defaultValue:`App Marketplace`}),type:`url`,url:`/apps/setup/system/marketplace`,icon:`store`},{id:`sys-objects`,label:i(`layout.systemNav.objectManager`,{defaultValue:`Object Manager`}),type:`url`,url:`/apps/setup/system/metadata/object`,icon:`database`},{id:`sys-users`,label:i(`layout.systemNav.users`,{defaultValue:`Users`}),type:`url`,url:`/apps/setup/system/users`,icon:`users`},{id:`sys-orgs`,label:i(`layout.systemNav.organizations`,{defaultValue:`Organizations`}),type:`url`,url:`/apps/setup/system/organizations`,icon:`building-2`},{id:`sys-roles`,label:i(`layout.systemNav.roles`,{defaultValue:`Roles`}),type:`url`,url:`/apps/setup/system/roles`,icon:`shield`},{id:`sys-config`,label:i(`layout.systemNav.configuration`,{defaultValue:`Configuration`}),type:`url`,url:`/apps/setup/system/settings`,icon:`sliders-horizontal`}];e.push({id:`sys-administration`,label:i(`layout.systemNav.administration`,{defaultValue:`Administration`}),type:`group`,icon:`shield`,children:t})}return e},[i,p]),I=u===`home`?te:N,ne=u===`app`&&T?`/apps/${Vi(T)}`:``,L=u===`app`&&T?.name===`studio`,R=Z.useMemo(()=>{if(!L)return``;let e=new URLSearchParams(r.search).get(`package`)||P.active_package;return e?`?package=${encodeURIComponent(e)}`:``},[P.active_package,L,r.search]),re=Z.useMemo(()=>{if(u!==`app`||T?.name!==`studio`)return I;let e=i(`sidebar.packageManagement`,{defaultValue:`Package management`}),t=n=>n.flatMap(n=>{if(vo(n))return[];let r=n.children?.length?t(n.children):n.children;return n.type===`group`&&r?.length===0?[]:yo(n)?[{...n,type:`url`,label:e,url:`${ne}/component/developer/packages${R}`,children:r}]:r===n.children?[n]:[{...n,children:r}]});return t(I).flatMap(e=>bo(e)?e.children??[]:[e])},[T?.name,ne,u,I,R,i]),z=Z.useMemo(()=>k(E(re)),[re,E,k]),[B,ie]=Z.useState(!1),{evaluator:ae}=ui(),V=Z.useCallback(e=>li(e,ae),[ae]),{can:oe}=w(),se=Z.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return oe(n,r)}),[oe]),le=Z.useMemo(()=>new Set((y||[]).map(e=>e?.name).filter(Boolean)),[y]),ue=Z.useCallback((e,t)=>e===`object`?le.size===0?!0:le.has(t):!0,[le]),de=L&&r.pathname.replace(/\/+$/,``)===ne;return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(tr,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&u===`app`&&(0,Q.jsx)(dn,{className:`border-b p-1.5`,children:(0,Q.jsx)(Dt,{children:(0,Q.jsx)(jt,{children:(0,Q.jsx)(Lr,{asChild:!0,className:`h-9 text-sm font-medium`,children:(0,Q.jsxs)(m,{to:`/home`,onClick:()=>n(!1),"data-testid":`mobile-sidebar-home`,children:[(0,Q.jsx)(ce,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Q.jsx)(Ln,{className:`pt-2`,children:(0,Q.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:u===`app`&&T?(0,Q.jsxs)(Q.Fragment,{children:[ee&&(0,Q.jsx)(nn,{className:`group-data-[state=collapsed]:hidden px-2 pb-1`,children:(0,Q.jsx)(`div`,{className:`rounded-lg border border-sidebar-border/70 bg-sidebar-accent/25 p-1.5 shadow-xs`,children:(0,Q.jsx)(Pr,{children:ee})})}),L&&(0,Q.jsx)(nn,{children:(0,Q.jsx)(Pr,{children:(0,Q.jsx)(Dt,{children:(0,Q.jsx)(jt,{children:(0,Q.jsx)(Lr,{asChild:!0,isActive:de,tooltip:i(`home.nav`,{defaultValue:`Home`}),children:(0,Q.jsxs)(m,{to:{pathname:ne,search:R},children:[(0,Q.jsx)(ce,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})})}),A.length>1&&(0,Q.jsxs)(nn,{children:[(0,Q.jsxs)(Wr,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(It,{className:`h-3.5 w-3.5`}),i(`sidebar.area`,{defaultValue:`Area`})]}),(0,Q.jsx)(Pr,{children:(0,Q.jsx)(Dt,{children:A.map(e=>{let t=Gi(e.icon);return(0,Q.jsx)(jt,{children:(0,Q.jsxs)(Lr,{isActive:e.id===j,tooltip:e.label,onClick:()=>M(e.id),children:[(0,Q.jsx)(t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,Q.jsx)(ki,{items:z,basePath:ne,evaluateVisibility:V,checkPermission:se,checkCapability:ue,enablePinning:!t,onPinToggle:O,enableReorder:!t,onReorder:D,resolveObjectLabel:(e,t)=>a({name:e,label:t}),resolveDashboardLabel:(e,t)=>o({name:e,label:t}),resolveGroupLabel:T?(e,t)=>s(T.name,e,t):void 0,resolveItemLabel:T?(e,t)=>T.name===`studio`&&t===i(`sidebar.packageManagement`,{defaultValue:`Package management`})?t:s(T.name,e,t):void 0,resolveViewLabel:(e,t,n)=>c(e,t,n),t:i,templateContext:{currentUserId:f?.id??null,contextValues:P}}),h.length>0&&(0,Q.jsxs)(nn,{children:[(0,Q.jsxs)(Wr,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>ie(e=>!e),children:[(0,Q.jsx)(be,{className:`h-3 w-3 transition-transform duration-150 ${B?`rotate-90`:``}`}),(0,Q.jsx)(_r,{className:`h-3.5 w-3.5`}),i(`sidebar.recent`,{defaultValue:`Recent`})]}),B&&(0,Q.jsx)(Pr,{children:(0,Q.jsx)(Dt,{children:h.slice(0,5).map(e=>(0,Q.jsx)(jt,{children:(0,Q.jsx)(Lr,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(m,{to:e.href,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:`📄`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]})})},e.id))})})]}),g.some(e=>e.type!==`nav`)&&(0,Q.jsxs)(nn,{children:[(0,Q.jsxs)(Wr,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(rr,{className:`h-3.5 w-3.5`}),i(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Q.jsx)(Pr,{children:(0,Q.jsx)(Dt,{children:g.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Q.jsxs)(jt,{children:[(0,Q.jsx)(Lr,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(m,{to:e.href,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:e.type===`page`?`📄`:`📋`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,Q.jsx)(xe,{showOnHover:!0,onClick:t=>{t.stopPropagation(),_(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(gr,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(nn,{children:(0,Q.jsx)(Pr,{children:(0,Q.jsx)(Dt,{children:te.map(e=>{let t=Gi(e.icon),n=r.pathname===e.url;return(0,Q.jsx)(jt,{children:(0,Q.jsx)(Lr,{asChild:!0,tooltip:e.label,isActive:n,children:(0,Q.jsxs)(m,{to:e.url||`/home`,children:[(0,Q.jsx)(t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:e.label})]})})},e.id)})})})}),g.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,Q.jsxs)(nn,{children:[(0,Q.jsxs)(Wr,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(rr,{className:`h-3.5 w-3.5`}),i(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Q.jsx)(Pr,{children:(0,Q.jsx)(Dt,{children:g.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Q.jsxs)(jt,{children:[(0,Q.jsx)(Lr,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(m,{to:e.href,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`page`?`📄`:`📋`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,Q.jsx)(xe,{showOnHover:!0,onClick:t=>{t.stopPropagation(),_(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(gr,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Q.jsx)(In,{className:`border-t p-1`,children:(0,Q.jsx)(go,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function So(){let{theme:e,setTheme:t}=Va(),{t:n}=H();return(0,Q.jsxs)(br,{children:[(0,Q.jsx)(Pn,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(de,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Q.jsx)(Mn,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:n(`console.theme.toggle`)})]})}),(0,Q.jsxs)(mn,{align:`end`,children:[(0,Q.jsxs)(kr,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Q.jsx)(de,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(kr,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Q.jsx)(Mn,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(kr,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Q.jsx)($t,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}var Co=[{code:`en`,label:`English`},{code:`zh`,label:`中文`},{code:`ja`,label:`日本語`},{code:`ko`,label:`한국어`},{code:`de`,label:`Deutsch`},{code:`fr`,label:`Français`},{code:`es`,label:`Español`},{code:`pt`,label:`Português`},{code:`ru`,label:`Русский`},{code:`ar`,label:`العربية`}];function wo(){let{t:e,language:t,changeLanguage:n}=H();return(0,Q.jsxs)(br,{children:[(0,Q.jsx)(Pn,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(dr,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Q.jsx)(mn,{align:`end`,className:`max-h-72 overflow-y-auto`,children:Co.map(e=>(0,Q.jsxs)(kr,{onClick:()=>n(e.code),className:`gap-2`,children:[e.label,t===e.code&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]},e.code))})]})}var To={connected:{labelKey:`topbar.connection.connected`,defaultValue:`Connected`,color:`text-green-500`,icon:Fn},connecting:{labelKey:`topbar.connection.connecting`,defaultValue:`Connecting...`,color:`text-yellow-500`,icon:q},reconnecting:{labelKey:`topbar.connection.reconnecting`,defaultValue:`Reconnecting...`,color:`text-yellow-500`,icon:q},disconnected:{labelKey:`topbar.connection.disconnected`,defaultValue:`Disconnected`,color:`text-muted-foreground`,icon:kt},error:{labelKey:`topbar.connection.error`,defaultValue:`Connection Error`,color:`text-destructive`,icon:kt}};function Eo({state:e,className:t}){let n=To[e],{t:r}=H(),i=r(n.labelKey,{defaultValue:n.defaultValue}),a=n.icon,[o,s]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(e===`connected`){s(!0);let e=setTimeout(()=>s(!1),2e3);return()=>clearTimeout(e)}s(!1)},[e]),e===`connected`&&!o?null:(0,Q.jsxs)(`div`,{className:yn(`flex items-center gap-1.5 text-xs font-medium px-2 py-1 rounded-md transition-opacity duration-300`,n.color,e===`connected`&&`bg-green-500/10`,e===`error`&&`bg-destructive/10`,e===`reconnecting`&&`bg-yellow-500/10`,t),title:i,children:[(0,Q.jsx)(a,{className:yn(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:i})]})}function Do(e){if(!e)return``;let t=new Date(e).getTime();if(Number.isNaN(t))return``;let n=(Date.now()-t)/1e3;return n<60?`${Math.max(1,Math.floor(n))}s`:n<3600?`${Math.floor(n/60)}m`:n<86400?`${Math.floor(n/3600)}h`:`${Math.floor(n/86400)}d`}function Oo({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:a}){let{t:s}=H(),c=_(),l=o(),{currentAppName:u}=Si(),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(`notifications`),[h,g]=(0,Z.useState)(`unread`),v=t+n,y=s(`sidebar.inboxAriaLabel`,{defaultValue:`Open inbox`}),b=(0,Z.useRef)(null),[x,S]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{let e=b.current;if(e!==null&&v>e){S(!0);let e=window.setTimeout(()=>S(!1),1200);return()=>window.clearTimeout(e)}b.current=v},[v]),(0,Z.useEffect)(()=>{x||(b.current=v)},[x,v]);let C=()=>{f(!1);let e=u??l.appName;c(e?`/apps/${e}/system/approvals`:`/apps/setup/system/approvals`)},w=()=>{f(!1),c(`/apps/setup/sys_inbox_message?view=mine`)},T=()=>{f(!1),c(`/apps/setup/sys_activity`)},E=e=>{a(e.id);let t=u??l.appName;if(e.action_url){f(!1);let n=e.action_url;if(/^https?:\/\//i.test(n)){window.open(n,`_blank`,`noopener,noreferrer`);return}if(n.startsWith(`/apps/`)){c(n);return}let r=n.startsWith(`/`)?n:`/${n}`;c(t?`/apps/${t}${r}`:r);return}e.source_object&&e.source_id&&(f(!1),c(t?`/apps/${t}/${e.source_object}/${e.source_id}`:`/objects/${e.source_object}/${e.source_id}`))};return(0,Q.jsxs)(U,{open:d,onOpenChange:f,children:[(0,Q.jsx)(Cr,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 relative shrink-0 ${x?`motion-safe:animate-bounce`:``}`,"aria-label":y,title:s(`sidebar.inbox`,{defaultValue:`Inbox`}),children:[(0,Q.jsx)(Je,{className:`h-4 w-4`}),v>0&&(0,Q.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 h-4 min-w-[16px] rounded-full bg-red-500 text-[10px] leading-4 text-white text-center px-1 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:fade-in-0 motion-safe:duration-200`,children:v>9?`9+`:v},v)]})}),(0,Q.jsxs)(Dn,{align:`end`,sideOffset:8,className:`w-96 p-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-3 pt-3 pb-1`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-semibold`,children:s(`sidebar.inbox`,{defaultValue:`Inbox`})}),p===`notifications`&&t>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:`text-xs text-muted-foreground hover:text-foreground`,children:s(`notifications.markAllRead`,{defaultValue:`Mark all read`})})]}),(0,Q.jsxs)(or,{value:p,onValueChange:e=>m(e),className:`w-full`,children:[(0,Q.jsxs)(Vn,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Q.jsxs)(cn,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(Je,{className:`h-3.5 w-3.5`}),s(`sidebar.notifications`,{defaultValue:`Notifications`}),t>0&&(0,Q.jsx)(`span`,{className:`ml-0.5 inline-flex h-4 min-w-[16px] items-center justify-center rounded-full bg-red-500 px-1 text-[10px] text-white motion-safe:animate-in motion-safe:zoom-in-75 motion-safe:duration-200`,children:t>9?`9+`:t},`notif-${t}`)]}),(0,Q.jsxs)(cn,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(yr,{className:`h-3.5 w-3.5`}),s(`sidebar.approvals`,{defaultValue:`Approvals`}),n>0&&(0,Q.jsx)(`span`,{className:`ml-0.5 inline-flex h-4 min-w-[16px] items-center justify-center rounded-full bg-amber-500 px-1 text-[10px] text-white motion-safe:animate-in motion-safe:zoom-in-75 motion-safe:duration-200`,children:n>9?`9+`:n},`appr-${n}`)]}),(0,Q.jsxs)(cn,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(Or,{className:`h-3.5 w-3.5`}),s(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Q.jsxs)(vr,{value:`notifications`,className:`m-0 max-h-80 overflow-auto`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-2 py-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>g(`unread`),className:`text-xs px-2 py-1 rounded-md transition-colors ${h===`unread`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:[s(`notifications.filterUnread`,{defaultValue:`Unread`}),t>0&&(0,Q.jsx)(`span`,{className:`ml-1 text-[10px] opacity-70`,children:t})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>g(`all`),className:`text-xs px-2 py-1 rounded-md transition-colors ${h===`all`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:s(`notifications.filterAll`,{defaultValue:`All`})})]}),(()=>{let t=h===`unread`?e.filter(e=>!e.is_read):e;return t.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-8 text-sm text-muted-foreground text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:h===`unread`?s(`notifications.emptyUnread`,{defaultValue:`You're all caught up`}):s(`notifications.empty`,{defaultValue:`No notifications`})}):(0,Q.jsx)(`ul`,{className:`divide-y`,children:t.map((e,t)=>(0,Q.jsx)(`li`,{className:`motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-top-1 motion-safe:duration-200`,style:{animationDelay:`${Math.min(t,6)*20}ms`},children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>E(e),className:`w-full text-left px-3 py-2.5 hover:bg-accent transition-colors duration-150 ${e.is_read?``:`bg-accent/40`}`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`span`,{className:`mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full bg-primary transition-opacity duration-200 ${e.is_read?`opacity-0`:`opacity-100`}`,"aria-hidden":!0}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium leading-tight truncate`,children:e.title}),e.body&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-2 mt-0.5`,children:e.body}),(0,Q.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:Do(e.created_at)})]})]})})},e.id))})})(),(0,Q.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:w,className:`text-xs text-primary hover:underline`,children:s(`notifications.viewAll`,{defaultValue:`View all notifications`})})})]}),(0,Q.jsx)(vr,{value:`approvals`,className:`m-0 max-h-80 overflow-auto`,children:(0,Q.jsx)(`div`,{className:`px-3 py-6 text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:n>0?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(yr,{className:`mx-auto h-6 w-6 text-amber-500 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:duration-300`}),(0,Q.jsx)(`div`,{className:`mt-2 text-sm font-medium`,children:s(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:n})}),(0,Q.jsx)(J,{size:`sm`,className:`mt-3`,onClick:C,children:s(`notifications.viewApprovals`,{defaultValue:`View approvals`})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:s(`notifications.noPendingApprovals`,{defaultValue:`No pending approvals`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:C,className:`mt-2 text-xs text-primary hover:underline`,children:s(`notifications.openApprovalsInbox`,{defaultValue:`Open Approvals Inbox`})})]})})}),(0,Q.jsxs)(vr,{value:`activity`,className:`m-0 max-h-80 overflow-auto`,children:[r.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-8 text-sm text-muted-foreground text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:s(`layout.activityFeed.empty`,{defaultValue:`No recent activity`})}):(0,Q.jsx)(`ul`,{className:`divide-y`,children:r.slice(0,20).map((e,t)=>(0,Q.jsxs)(`li`,{className:`px-3 py-2.5 motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-top-1 motion-safe:duration-200`,style:{animationDelay:`${Math.min(t,6)*20}ms`},children:[(0,Q.jsxs)(`div`,{className:`text-sm leading-tight truncate`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]}),(0,Q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:[Do(e.timestamp),` · `,e.objectName]})]},e.id))}),(0,Q.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:T,className:`text-xs text-primary hover:underline`,children:s(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`})})})]})]})]})]})}function ko({activeAppName:e,onAppChange:t}){let{apps:n}=F(),{t:r}=H(),{appLabel:i}=er(),a=n||[],o=a.filter(e=>e.active!==!1&&e.hidden!==!0),s=Bi(o,e)||Bi(a.filter(e=>e.active!==!1),e)||o[0];return s?(0,Q.jsxs)(br,{children:[(0,Q.jsx)(Pn,{asChild:!0,children:(0,Q.jsxs)(`button`,{className:`flex items-center gap-1 rounded-md px-1.5 py-1 text-sm font-medium text-foreground/80 hover:bg-accent hover:text-foreground transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring max-w-[40vw] sm:max-w-none`,children:[(0,Q.jsx)(`span`,{className:`truncate whitespace-nowrap`,children:i({name:s.name,label:$i(s.label,r)})}),(0,Q.jsx)(At,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Q.jsxs)(mn,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Q.jsx)(xn,{className:`text-xs text-muted-foreground font-normal`,children:r(`layout.appSwitcher.switchApplication`,{defaultValue:`Switch Application`})}),(0,Q.jsx)(An,{}),o.map(e=>{let n=Gi(e.icon),a=i({name:e.name,label:$i(e.label,r)}),o=s.name===e.name;return(0,Q.jsxs)(kr,{onClick:()=>t(Vi(e)??e.name),className:`flex items-center gap-2.5 py-2`,children:[(0,Q.jsx)(`div`,{className:`flex size-5 shrink-0 items-center justify-center rounded border bg-muted text-muted-foreground`,children:(0,Q.jsx)(n,{className:`size-3`})}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:a}),o&&(0,Q.jsx)(Ee,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var Ao=(0,Z.createContext)(null);function jo({children:e}){let[t,n]=(0,Z.useState)(null),r=(0,Z.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Q.jsx)(Ao.Provider,{value:r,children:e})}function Mo(){return(0,Z.useContext)(Ao)?.value??null}function No(e){let t=(0,Z.useContext)(Ao),n=(0,Z.useRef)(null);(0,Z.useEffect)(()=>{if(!t)return;let r=e??null;return t.setValue(r),n.current=r,()=>{t.setValue(null)}},[t,e])}function Po(e){let{views:t,activeViewId:n,onChange:r,triggerLabel:i,enabled:a=!0}=e,o=(0,Z.useRef)(r);o.current=r;let s=(0,Z.useCallback)(e=>o.current(e),[]);No((0,Z.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}function Fo(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Io(){return(0,Q.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var Lo=[];function Ro({variant:e,appName:t,objects:n,connectionState:r,presenceUsers:i,activities:a,activeAppName:s,onAppChange:c}){let u=e??(t?`app`:`home`),d=u===`app`,f=l(),p=o(),h=_(),{isOnline:g}=ie(),{user:v,signOut:y,isAuthEnabled:b,organizations:S,activeOrganization:C,isOrganizationsLoading:w}=x(),E=se(),{t:D}=H(),{objectLabel:O,dashboardLabel:k,pageLabel:A,reportLabel:j,viewLabel:M,appLabel:N}=er(),{apps:P,dashboards:ee,pages:te,reports:I}=F(),{currentAppName:ne,recordTitle:L}=Si(),R=Mo(),[re,z]=(0,Z.useState)(null),B=(0,Z.useCallback)(async()=>{if(re===null)try{let e=E?.getClient?.();if(!e?.meta?.getItems){z([]);return}let t=await e.meta.getItems(`doc`);z((Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[]).map(e=>({name:e?.name,label:e?.label,_packageId:e?._packageId})).filter(e=>e.name))}catch{z([])}},[re,E]),[ae,V]=(0,Z.useState)(null),[oe,ce]=(0,Z.useState)([]),le=(0,Z.useRef)(!1),ue=(0,Z.useRef)(!1),de=(0,Z.useRef)(!0);(0,Z.useEffect)(()=>(de.current=!0,()=>{de.current=!1}),[]);let U=(0,Z.useRef)(!1),W=(0,Z.useRef)(!1),pe=(0,Z.useRef)(!1),[me,he]=(0,Z.useState)(0),ge=(0,Z.useRef)(!1),_e=(0,Z.useCallback)(async()=>{if(!E||!d)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!le.current&&!pe.current){pe.current=!0;try{let t=await E.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(le.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`);e.length&&V(e)}}catch{}finally{pe.current=!1}}},[E,d]);(0,Z.useEffect)(()=>{_e()},[_e]),(0,Z.useEffect)(()=>{if(!E||!d||!v?.id||ue.current)return;let e=!1,t=null,n=1e4,r=n,i=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`,a=new Set([`read`,`clicked`,`dismissed`]),o=async()=>{if(!U.current){U.current=!0;try{let[e,t]=await Promise.all([E.find(`sys_inbox_message`,{$filter:{user_id:v.id},$orderby:{created_at:`desc`},$top:20}),E.find(`sys_notification_receipt`,{$filter:{user_id:v.id,channel:`inbox`},$top:200}).catch(()=>({data:[]}))]);if(!de.current)return;let i=Array.isArray(e?.data)?e.data:[],o=Array.isArray(t?.data)?t.data:[],s=new Map;for(let e of o){let t=e?.notification_id==null?``:String(e.notification_id);if(!t)continue;let n=s.get(t);(!n||!a.has(n.state)&&a.has(e.state))&&s.set(t,{id:String(e.id),state:String(e.state)})}ce(i.map(e=>{let t=e?.notification_id==null?null:String(e.notification_id),n=t?s.get(t):void 0;return{id:String(e.id),notification_id:t,receipt_id:n?.id??null,type:e.topic??`notification`,title:e.title??``,body:e.body_md??null,action_url:e.action_url??null,is_read:n?a.has(n.state):!1,created_at:e.created_at}})),r=n}catch(e){if(i(e)){ue.current=!0;return}r=Math.min(r*2,12e4)}finally{U.current=!1}}},s=()=>{if(e||ue.current)return;let n=typeof document<`u`&&document.hidden?6e4:r;t=setTimeout(async()=>{await o(),s()},n)},c=()=>{e||typeof document>`u`||document.hidden||(t&&=(clearTimeout(t),null),r=n,o().finally(s))};return o().finally(s),typeof document<`u`&&document.addEventListener(`visibilitychange`,c),()=>{e=!0,t&&clearTimeout(t),typeof document<`u`&&document.removeEventListener(`visibilitychange`,c)}},[E,d,v?.id]),(0,Z.useEffect)(()=>{if(!d||!v?.id||ge.current)return;let e=`${``.replace(/\/$/,``)}/api/v1/approvals/requests`,t=[];v.id&&t.push(v.id),v.email&&t.push(v.email);for(let e of v.roles||[])e&&t.push(`role:${e}`);let n=!1,r=null,i=async()=>{if(t.length!==0&&!W.current){W.current=!0;try{let n=new URLSearchParams({status:`pending`,approverId:t.join(`,`)}),r=await fetch(`${e}?${n}`,{credentials:`include`});if(r.status===404){ge.current=!0;return}if(!r.ok)return;let i=await r.json().catch(()=>null),a=new Set;for(let e of i?.data||[])a.add(e.id);de.current&&he(a.size)}catch{}finally{W.current=!1}}},a=()=>{n||ge.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[d,v?.id]);let ve=oe.reduce((e,t)=>e+ +!t.is_read,0),ye=(0,Z.useCallback)(async(e,t)=>{!E||!e.notification_id||(e.receipt_id?await E.update(`sys_notification_receipt`,e.receipt_id,{state:`read`,at:t}):await E.create(`sys_notification_receipt`,{notification_id:e.notification_id,user_id:v?.id,channel:`inbox`,state:`read`,at:t,created_at:t}))},[E,v?.id]),be=(0,Z.useCallback)(async e=>{let t=oe.find(t=>t.id===e);if(ce(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),t)try{await ye(t,new Date().toISOString())}catch{}},[oe,ye]),xe=(0,Z.useCallback)(async()=>{let e=oe.filter(e=>!e.is_read);if(!e.length)return;ce(e=>e.map(e=>({...e,is_read:!0})));let t=new Date().toISOString();await Promise.all(e.map(e=>ye(e,t).catch(()=>{})))},[oe,ye]),Se=xi(),Ce=i??(Se.length>0?Se:Lo),we=a??ae??[],Te=w||(S??[]).length>0||!!C,G=f.pathname.split(`/`).filter(Boolean),De=p.appName||G[1],K=G[2],Oe=`/apps/${De}`,ke=n??[],Ae=Bi(P||[],s||ne||De),je=new Set,Me=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&je.add(t.objectName),t.children&&Me(t.children)};Me(Ae?.navigation||[]);for(let e of Ae?.areas||[])Me(e.navigation||[]);let Ne=je.size>0?ke.filter(e=>je.has(e.name)):ke.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`)),Pe=Ae?._packageId,Fe=Pe?(re??[]).filter(e=>e._packageId===Pe):[],Ie=Ne.map(e=>({label:O(e),href:`${Oe}/${e.name}`})),Re=[];if(d){if(K===`dashboard`){if(Re.push({label:D(`console.breadcrumb.dashboards`),href:Oe}),G[3]){let e=G[3],t=ra(ee,e,Ae?._packageId)?.label||Fo(e);Re.push({label:k({name:e,label:t})})}}else if(K===`page`){if(Re.push({label:D(`console.breadcrumb.pages`),href:Oe}),G[3]){let e=G[3],t=ra(te,e,Ae?._packageId)?.label||Fo(e);Re.push({label:A({name:e,label:t})})}}else if(K===`report`){if(Re.push({label:D(`console.breadcrumb.reports`),href:Oe}),G[3]){let e=G[3],t=ra(I,e,Ae?._packageId)?.label||Fo(e);Re.push({label:j({name:e,label:t})})}}else if(K===`system`)Re.push({label:D(`console.breadcrumb.system`)}),G[3]&&Re.push({label:Fo(G[3])});else if(K){let e=ke.find(e=>e.name===K);if(e){if(Re.push({label:O(e),href:`${Oe}/${K}`,siblings:Ie}),G[3]===`record`&&G[4]){let e=G[4].length>12?`${G[4].slice(0,8)}…`:G[4],t=L?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;Re.push({label:n||`#${e}`})}else if(G[3]===`view`&&G[4]){let t=G[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||Fo(t),i=M(e.name,t,r);Re.push({label:i})}}}}let ze=Re[Re.length-1]?.label||t||``;return(0,Q.jsxs)(`div`,{className:`flex items-center justify-between w-full h-full`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center min-w-0 flex-1`,children:[(0,Q.jsx)(m,{to:`/home`,className:yn(`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,d&&`hidden sm:flex`),title:sa(),children:(0,Q.jsx)(It,{className:`h-4 w-4`})}),u===`home`&&(0,Q.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:sa()}),u===`orgs`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Io,{}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:D(`organizations.title`,{defaultValue:`Organizations`})})]}),d&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(go,{className:`lg:hidden shrink-0 ml-1`,"aria-label":D(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`})}),s&&c?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(Io,{})}),(0,Q.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(ko,{activeAppName:s,onAppChange:c})})]}):t?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(Io,{})}),(0,Q.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,Re.map((e,t)=>{let n=t===Re.length-1;return(0,Q.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,Q.jsx)(Io,{}),e.siblings&&e.siblings.length>1?(0,Q.jsxs)(br,{children:[(0,Q.jsxs)(Pn,{className:`flex items-center gap-1 rounded-md px-1.5 py-1 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring hover:bg-accent hover:text-foreground ${n?`text-foreground/80`:`text-foreground/60`}`,children:[e.label,(0,Q.jsx)(At,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Q.jsxs)(mn,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Q.jsx)(xn,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,Q.jsx)(An,{}),e.siblings.map(e=>(0,Q.jsx)(kr,{asChild:!0,children:(0,Q.jsx)(m,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,Q.jsx)(m,{to:e.href,className:`rounded-md px-1.5 py-1 text-sm font-medium transition-colors hover:bg-accent hover:text-foreground truncate max-w-[160px] ${n?`text-foreground/80`:`text-foreground/60`}`,children:e.label}):(0,Q.jsx)(`span`,{className:`px-1.5 py-1 text-sm font-medium truncate max-w-[160px] ${n?`text-foreground/80`:`text-foreground/60`}`,children:e.label})]},t)}),R&&R.views.length>0?R.views.length>1?(0,Q.jsxs)(br,{children:[(0,Q.jsx)(Pn,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,className:`sm:hidden flex items-center gap-0.5 min-w-0 ml-1 rounded-md px-1.5 py-1 text-sm font-medium hover:bg-accent active:bg-accent/80 transition-colors`,"aria-label":D(`topbar.switchView`,{defaultValue:`Switch view`}),children:[(0,Q.jsx)(`span`,{className:`truncate max-w-[180px]`,children:R.triggerLabel??R.views.find(e=>e.id===R.activeViewId)?.label??ze}),(0,Q.jsx)(At,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Q.jsx)(mn,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:R.views.map(e=>{let t=e.id===R.activeViewId;return(0,Q.jsxs)(kr,{onSelect:()=>{t||R.onChange(e.id)},className:`gap-2`,children:[e.icon?(0,Q.jsx)(`span`,{className:`shrink-0 text-muted-foreground [&>svg]:h-4 [&>svg]:w-4`,children:e.icon}):null,(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.locked?(0,Q.jsx)(Hn,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Q.jsx)(Ee,{className:`h-4 w-4 shrink-0 text-foreground`,"aria-hidden":!0}):null]},e.id)})})]}):(0,Q.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:R.triggerLabel??R.views[0].label}):(0,Q.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:ze})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1 shrink-0 [&>*+*[data-topbar-group]]:ml-1 [&>[data-topbar-group]+[data-topbar-group]]:border-l [&>[data-topbar-group]+[data-topbar-group]]:border-border/60 [&>[data-topbar-group]+[data-topbar-group]]:pl-1 sm:[&>[data-topbar-group]+[data-topbar-group]]:pl-2 sm:[&>[data-topbar-group]+[data-topbar-group]]:ml-2`,children:[!g&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 rounded-full bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 text-xs font-medium`,children:[(0,Q.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-yellow-500 animate-pulse`}),D(`topbar.offline`,{defaultValue:`Offline`})]}),d&&r&&(0,Q.jsx)(Eo,{state:r}),d&&Ce.length>0&&(0,Q.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:D(`topbar.usersOnline`,{defaultValue:`Users currently online`}),children:(0,Q.jsx)(yi,{users:Ce,size:`sm`,maxVisible:3,showStatus:!0})}),(0,Q.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 sm:gap-1 shrink-0`,children:[(0,Q.jsxs)(`button`,{onClick:()=>document.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0})),className:`hidden lg:flex relative items-center gap-2 w-48 xl:w-64 h-8 px-3 text-sm rounded-md border bg-muted/50 text-muted-foreground hover:bg-muted transition-colors`,children:[(0,Q.jsx)(Tt,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:D(`console.search`,{defaultValue:`Search…`})}),(0,Q.jsxs)(`kbd`,{className:`pointer-events-none inline-flex h-5 items-center gap-0.5 rounded border bg-background px-1.5 text-[10px] font-medium text-muted-foreground`,children:[(0,Q.jsx)(`span`,{className:`text-xs`,children:`⌘`}),`K`]})]}),(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`lg:hidden h-8 w-8 shrink-0`,onClick:()=>document.dispatchEvent(new KeyboardEvent(`keydown`,{key:`k`,metaKey:!0})),"aria-label":D(`console.search`,{defaultValue:`Search…`}),children:(0,Q.jsx)(Tt,{className:`h-4 w-4`})})]}),(0,Q.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[(0,Q.jsx)(Oo,{notifications:oe,unreadCount:ve,pendingApprovalsCount:me,activities:we,onMarkAllRead:xe,onMarkRead:be}),(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"aria-label":D(`topbar.aiAssistant`,{defaultValue:`AI Assistant`}),children:(0,Q.jsx)(m,{to:`/ai`,children:(0,Q.jsx)(Vt,{className:`h-4 w-4`})})}),(0,Q.jsxs)(br,{onOpenChange:e=>{e&&B()},children:[(0,Q.jsx)(Pn,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 hidden md:flex shrink-0`,"aria-label":D(`sidebar.helpTooltip`,{defaultValue:`Help & Documentation`}),children:(0,Q.jsx)(wn,{className:`h-4 w-4`})})}),(0,Q.jsxs)(mn,{align:`end`,className:`min-w-56 rounded-lg`,sideOffset:4,children:[Fe.length>0&&Pe?(0,Q.jsxs)(kr,{className:`cursor-pointer`,onClick:()=>h(Fe.length===1?`/apps/${Pe}/docs/${Fe[0].name}`:`/apps/${Pe}/docs`),children:[(0,Q.jsx)(Xe,{className:`mr-2 h-4 w-4`}),D(`help.appDocs`,{defaultValue:`This app's docs`})]}):null,(0,Q.jsxs)(kr,{className:`cursor-pointer`,onClick:()=>h(`/docs`),children:[(0,Q.jsx)(It,{className:`mr-2 h-4 w-4`}),D(`help.allDocs`,{defaultValue:`All documentation`})]}),(0,Q.jsx)(An,{}),(0,Q.jsx)(kr,{asChild:!0,className:`cursor-pointer`,children:(0,Q.jsxs)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,Q.jsx)(He,{className:`mr-2 h-4 w-4`}),D(`help.onlineDocs`,{defaultValue:`Online documentation`})]})})]})]})]}),(0,Q.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[` `,(0,Q.jsxs)(br,{children:[(0,Q.jsx)(Pn,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,Q.jsxs)(On,{className:`h-7 w-7 rounded-full`,children:[(0,Q.jsx)(ir,{src:v?.image,alt:v?.name??`User`}),(0,Q.jsx)(Tr,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:T(v)})]})})}),(0,Q.jsxs)(mn,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Q.jsx)(xn,{className:`p-0 font-normal`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,Q.jsxs)(On,{className:`h-8 w-8 rounded-lg`,children:[(0,Q.jsx)(ir,{src:v?.image,alt:v?.name??`User`}),(0,Q.jsx)(Tr,{className:`rounded-lg bg-primary text-primary-foreground`,children:T(v)})]}),(0,Q.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,Q.jsx)(`span`,{className:`truncate font-semibold`,children:v?.name??`User`}),(0,Q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:v?.email??``})]})]})}),(0,Q.jsx)(An,{}),(0,Q.jsxs)(Xn,{children:[(0,Q.jsxs)(kr,{onClick:()=>h(`/apps/account/component/account/profile_card`),className:`cursor-pointer`,children:[(0,Q.jsx)(Gn,{className:`mr-2 h-4 w-4`}),D(`user.profile`,{defaultValue:`Profile`})]}),Te&&(0,Q.jsxs)(kr,{onClick:()=>h(`/organizations`),className:`cursor-pointer`,children:[(0,Q.jsx)(Le,{className:`mr-2 h-4 w-4`}),D(`organizations.mine`,{defaultValue:`My Organizations`})]}),(P||[]).filter(e=>e.active!==!1&&e.hidden===!0&&e.name!==`account`).map(e=>{let t=Gi(e.icon),n=N({name:e.name,label:$i(e.label,D)});return(0,Q.jsxs)(kr,{onClick:()=>h(`/apps/${Vi(e)??e.name}`),className:`cursor-pointer`,children:[(0,Q.jsx)(t,{className:`mr-2 h-4 w-4`}),n]},`hidden_app_${e.name}`)})]}),(0,Q.jsx)(An,{}),(0,Q.jsx)(xn,{className:`text-[11px] font-normal text-muted-foreground uppercase tracking-wide px-2`,children:D(`user.preferences`,{defaultValue:`Preferences`})}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-foreground/80`,children:D(`user.theme`,{defaultValue:`Theme`})}),(0,Q.jsx)(So,{})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,Q.jsx)(`span`,{className:`text-foreground/80`,children:D(`user.language`,{defaultValue:`Language`})}),(0,Q.jsx)(wo,{})]}),b&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(An,{}),(0,Q.jsxs)(kr,{className:`text-destructive focus:text-destructive`,onClick:()=>y(),children:[(0,Q.jsx)(fe,{className:`mr-2 h-4 w-4`}),D(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var zo=768,Bo=1024;function Vo(){let{setOpen:e,isMobile:t}=Ce(),n=(0,Z.useRef)(e);(0,Z.useEffect)(()=>{n.current=e},[e]),(0,Z.useEffect)(()=>{if(t)return;let e=!1;function r(){let t=window.innerWidth,r=t>=zo&&t<Bo;r&&!e&&n.current(!1),e=r}return r(),window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r)},[t])}function Ho({children:e}){return Vo(),(0,Q.jsx)(Q.Fragment,{children:e})}function Uo({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=$i(n?.label)||t,{isAiEnabled:c}=P(),l=c||!1,u=aa().features.aiStudio===!1&&n?.defaultAgent===`metadata_assistant`?void 0:n?.defaultAgent,{setContext:d,setCurrentAppName:f}=Si();return(0,Z.useEffect)(()=>{d(`app`),f(t)},[d,f,t]),(0,Q.jsx)(jo,{children:(0,Q.jsxs)(Oi,{sidebar:(0,Q.jsx)(xo,{activeAppName:t,onAppChange:r}),navbar:(0,Q.jsx)(Ro,{variant:`app`,appName:s,objects:i,connectionState:a,activeAppName:t,onAppChange:r}),className:`!p-0 overflow-y-auto overflow-x-hidden bg-muted/5`,branding:n?.branding?{primaryColor:n.branding.primaryColor,accentColor:n.branding.accentColor,favicon:n.branding.favicon,logo:n.branding.logo,title:n.label?`${$i(n.label)} — ${sa()}`:void 0}:void 0,children:[(0,Q.jsxs)(Ho,{children:[(0,Q.jsx)(no,{}),(0,Q.jsx)(ro,{}),e]}),l&&(0,Q.jsx)(Za,{appLabel:s,appName:t,defaultAgent:u,objects:i,userId:o})]})})}function Wo({title:e,description:t,icon:n,actions:r,accentColor:i,sticky:a=!1,className:o,"data-testid":s}){return(0,Q.jsxs)(`div`,{style:{"--page-header-accent":i||`hsl(var(--primary))`},className:yn(`relative shrink-0 border-b bg-background z-10`,a&&`sticky top-0 bg-background/85 backdrop-blur supports-[backdrop-filter]:bg-background/75`,o),"data-testid":s??`page-header`,children:[(0,Q.jsx)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-x-0 top-0 h-[2px] opacity-80`,style:{background:`linear-gradient(90deg, transparent, var(--page-header-accent), transparent)`}}),(0,Q.jsxs)(`div`,{className:`flex justify-between items-center gap-3 py-2.5 sm:py-3 px-4 sm:px-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[n&&(0,Q.jsx)(`div`,{className:yn(`shrink-0 inline-flex items-center justify-center rounded-lg`,`h-9 w-9 sm:h-10 sm:w-10`,`[&_svg]:h-[18px] [&_svg]:w-[18px] sm:[&_svg]:h-5 sm:[&_svg]:w-5`),style:{color:`var(--page-header-accent)`,background:`linear-gradient(135deg, color-mix(in srgb, var(--page-header-accent) 18%, transparent), color-mix(in srgb, var(--page-header-accent) 6%, transparent))`,boxShadow:`inset 0 0 0 1px color-mix(in srgb, var(--page-header-accent) 22%, transparent)`},children:n}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`h1`,{className:`text-base sm:text-lg lg:text-xl font-semibold tracking-tight text-foreground truncate leading-tight`,children:e}),t&&(0,Q.jsx)(`p`,{className:`text-xs sm:text-sm text-muted-foreground truncate hidden sm:block max-w-xl mt-0.5`,children:t})]})]}),r&&(0,Q.jsx)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0`,children:r})]})]})}function Go({apps:e,activeApp:t,objects:n,onAppChange:r,dataSource:i}){let[a,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(``),u=_(),{appName:d}=o(),{setTheme:f}=Va(),{evaluator:p}=ui(),{t:m}=H();(0,Z.useEffect)(()=>{let e=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),s(e=>!e))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[]),(0,Z.useEffect)(()=>{a||l(``)},[a]);let h=`/apps/${d||Vi(t)}`,{user:g}=x(),v=(0,Z.useMemo)(()=>({currentUserId:g?.id??null}),[g?.id]),y=(0,Z.useCallback)(e=>{s(!1),e()},[]),b=Ko(t?.navigation||[]).filter(e=>li(e.visible??e.visibleOn,p)),{results:S,isSearching:C}=R({query:c,objects:n,dataSource:i,objectNames:(0,Z.useMemo)(()=>b.filter(e=>e.type===`object`&&typeof e.objectName==`string`).map(e=>e.objectName),[t?.name,b.map(e=>e.objectName||``).join(`|`)]),enabled:a&&!!i,getDisplayName:Zi}),{recentItems:w}=fi(),T=(0,Z.useMemo)(()=>w.filter(e=>e.type===`record`).slice(0,5),[w]),E=a&&c.trim().length===0&&T.length>0;return(0,Q.jsxs)(pe,{open:a,onOpenChange:s,children:[(0,Q.jsx)(ot,{placeholder:m(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,Q.jsxs)(K,{children:[(0,Q.jsx)(Wn,{children:C?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-muted-foreground`,children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`inline-block h-1.5 w-1.5 rounded-full bg-primary motion-safe:animate-pulse`}),m(`console.commandPalette.searching`,{defaultValue:`Searching…`})]}):m(`console.commandPalette.noResults`)}),E&&(0,Q.jsx)(rt,{heading:m(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:T.map(e=>(0,Q.jsxs)(pt,{value:`recent ${e.label} ${e.id}`,onSelect:()=>y(()=>u(e.href)),children:[(0,Q.jsx)(Tt,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]},`recent:${e.id}`))}),S.length>0&&(0,Q.jsx)(rt,{heading:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[m(`console.commandPalette.records`,{defaultValue:`Records`}),C&&(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`inline-block h-1.5 w-1.5 rounded-full bg-primary motion-safe:animate-pulse`})]}),children:S.map(e=>{let t=Gi(e.icon);return(0,Q.jsxs)(pt,{value:`record ${c} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>y(()=>u(`${h}/${e.objectName}/record/${e.recordId}`)),children:[(0,Q.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.display}),(0,Q.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:e.objectLabel})]},`${e.objectName}:${e.recordId}`)})}),b.filter(e=>e.type===`object`).length>0&&(0,Q.jsx)(rt,{heading:m(`console.commandPalette.objects`),children:b.filter(e=>e.type===`object`).map(e=>{let t=Gi(e.icon);return(0,Q.jsxs)(pt,{value:`object ${$i(e.label,m)} ${e.objectName}`,onSelect:()=>y(()=>u(Di(e,h,v).href)),children:[(0,Q.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:$i(e.label,m)})]},e.id)})}),b.filter(e=>e.type===`dashboard`).length>0&&(0,Q.jsx)(rt,{heading:m(`console.commandPalette.dashboards`),children:b.filter(e=>e.type===`dashboard`).map(e=>(0,Q.jsxs)(pt,{value:`dashboard ${$i(e.label,m)} ${e.dashboardName}`,onSelect:()=>y(()=>u(Di(e,h,v).href)),children:[(0,Q.jsx)(Fe,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:$i(e.label,m)})]},e.id))}),b.filter(e=>e.type===`page`).length>0&&(0,Q.jsx)(rt,{heading:m(`console.commandPalette.pages`),children:b.filter(e=>e.type===`page`).map(e=>(0,Q.jsxs)(pt,{value:`page ${$i(e.label,m)} ${e.pageName}`,onSelect:()=>y(()=>u(Di(e,h,v).href)),children:[(0,Q.jsx)(ye,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:$i(e.label,m)})]},e.id))}),b.filter(e=>e.type===`report`).length>0&&(0,Q.jsx)(rt,{heading:m(`console.commandPalette.reports`),children:b.filter(e=>e.type===`report`).map(e=>(0,Q.jsxs)(pt,{value:`report ${$i(e.label,m)} ${e.reportName}`,onSelect:()=>y(()=>u(Di(e,h,v).href)),children:[(0,Q.jsx)(st,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:$i(e.label,m)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ve,{}),(0,Q.jsx)(rt,{heading:m(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=Gi(e.icon);return(0,Q.jsxs)(pt,{value:`app ${$i(e.label,m)} ${e.name}`,onSelect:()=>y(()=>r(Vi(e)??e.name)),children:[(0,Q.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:$i(e.label,m)}),e.name===t?.name&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:m(`console.commandPalette.current`)})]},e.name)})})]}),(0,Q.jsx)(Ve,{}),(0,Q.jsxs)(rt,{heading:m(`console.commandPalette.preferences`),children:[(0,Q.jsxs)(pt,{value:`theme light`,onSelect:()=>y(()=>f(`light`)),children:[(0,Q.jsx)(de,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.lightTheme`)})]}),(0,Q.jsxs)(pt,{value:`theme dark`,onSelect:()=>y(()=>f(`dark`)),children:[(0,Q.jsx)(Mn,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.darkTheme`)})]}),(0,Q.jsxs)(pt,{value:`theme system`,onSelect:()=>y(()=>f(`system`)),children:[(0,Q.jsx)($t,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.systemTheme`)})]})]}),(0,Q.jsx)(Ve,{}),(0,Q.jsx)(rt,{heading:m(`console.commandPalette.actions`),children:(0,Q.jsxs)(pt,{value:`search all results full page`,onSelect:()=>y(()=>u(`${h}/search`)),children:[(0,Q.jsx)(Tt,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.openFullSearch`)})]})})]})]})}function Ko(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Ko(n.children)):t.push(n);return t}function qo(){let{t:e}=H(),[t,n]=(0,Z.useState)(!1),r=(0,Z.useMemo)(()=>[{title:e(`console.shortcuts.groups.general`),shortcuts:[{keys:[`⌘`,`K`],description:e(`console.shortcuts.openCommandPalette`)},{keys:[`?`],description:e(`console.shortcuts.showShortcuts`)},{keys:[`Esc`],description:e(`console.shortcuts.closeDialog`)}]},{title:e(`console.shortcuts.groups.navigation`),shortcuts:[{keys:[`B`],description:e(`console.shortcuts.toggleSidebar`)},{keys:[`⌘`,`/`],description:e(`console.shortcuts.focusSearch`)}]},{title:e(`console.shortcuts.groups.dataViews`),shortcuts:[{keys:[`N`],description:e(`console.shortcuts.createRecord`)},{keys:[`R`],description:e(`console.shortcuts.refreshData`)},{keys:[`⌘`,`E`],description:e(`console.shortcuts.editRecord`)}]},{title:e(`console.shortcuts.groups.aiChat`,{defaultValue:`AI assistant`}),shortcuts:[{keys:[`⌘`,`⇧`,`O`],description:e(`console.shortcuts.newChat`,{defaultValue:`New chat`})},{keys:[`⌘`,`⇧`,`S`],description:e(`console.shortcuts.toggleChatsList`,{defaultValue:`Toggle conversations list`})}]},{title:e(`console.shortcuts.groups.preferences`),shortcuts:[{keys:[`⌘`,`D`],description:e(`console.shortcuts.toggleDarkMode`)}]}],[e]);return(0,Z.useEffect)(()=>{function e(e){let t=e.target;t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable||e.key===`?`&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&(e.preventDefault(),n(e=>!e))}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[]),(0,Q.jsx)($e,{open:t,onOpenChange:n,children:(0,Q.jsxs)(xt,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,children:[(0,Q.jsxs)(Lt,{children:[(0,Q.jsx)(Ie,{children:e(`console.shortcuts.title`)}),(0,Q.jsx)(qr,{children:e(`console.shortcuts.description`)})]}),(0,Q.jsx)(`div`,{className:`space-y-6 pt-2`,children:r.map(e=>(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground mb-3`,children:e.title}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:e.shortcuts.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm`,children:e.description}),(0,Q.jsx)(`div`,{className:`flex items-center gap-1`,children:e.keys.map((e,t)=>(0,Q.jsx)(`kbd`,{className:`inline-flex h-6 min-w-[24px] items-center justify-center rounded border bg-muted px-1.5 text-xs font-medium text-muted-foreground`,children:e},t))})]},t))})]},e.title))})]})})}function Jo(){return null}function Yo(){return typeof document<`u`&&document.documentElement.lang?.startsWith(`zh`)||typeof navigator<`u`&&navigator.language?.startsWith(`zh`)?ne.console:V.console}function Xo({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,Z.useState)(0),o=Yo(),s=(0,Z.useMemo)(()=>[o.loadingSteps.connecting,o.loadingSteps.loadingConfig,o.loadingSteps.preparingWorkspace],[o]);return(0,Z.useEffect)(()=>{if(e||t)return;let n=setInterval(()=>{a(e=>Math.min(e+1,s.length-1))},1200);return()=>clearInterval(n)},[e,t,s.length]),(0,Q.jsx)(`div`,{className:`flex flex-col items-center justify-center h-screen bg-background`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-6`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-primary/20 rounded-2xl blur-xl animate-pulse`}),(0,Q.jsx)(`div`,{className:`relative bg-linear-to-br from-primary to-primary/80 p-4 rounded-2xl shadow-lg`,children:(0,Q.jsx)(Bt,{className:`h-10 w-10 text-primary-foreground`})})]}),(0,Q.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,Q.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:sa()}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o.initializing})]}),t?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-4 max-w-md w-full px-6`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3 p-5 rounded-lg border border-destructive/30 bg-destructive/5 w-full`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-destructive`,children:[(0,Q.jsx)(Ur,{className:`h-5 w-5 shrink-0`}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:o.error.connectionFailed})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground text-center break-words`,children:t}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:o.error.checkServer})]}),n&&(0,Q.jsx)(J,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(q,{className:`h-4 w-4 animate-spin`}),o.actions.retrying]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(De,{className:`h-4 w-4`}),o.actions.retry]})})]}):e?(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 bg-muted/50 rounded-full`,children:[(0,Q.jsx)(G,{className:`h-4 w-4 text-primary`}),(0,Q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e})]}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2 w-64`,children:s.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 text-sm transition-opacity duration-300`,style:{opacity:t<=i?1:.3},children:[t<i?(0,Q.jsx)(Fn,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,Q.jsx)(q,{className:`h-4 w-4 text-primary shrink-0 animate-spin`}):(0,Q.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-muted-foreground/30 shrink-0`}),(0,Q.jsx)(`span`,{className:t<=i?`text-foreground`:`text-muted-foreground`,children:e})]},e))})]})})}function Zo(e){let{theme:t=`system`}=Va(),{t:n}=H();return(0,Q.jsx)(Zr,{theme:t,className:`toaster group`,position:`top-right`,closeButton:!0,richColors:!0,expand:!0,visibleToasts:4,containerAriaLabel:n(`notifications.regionLabel`,{defaultValue:`Notifications`}),icons:{success:(0,Q.jsx)(Fn,{className:`h-4 w-4`}),info:(0,Q.jsx)(Ge,{className:`h-4 w-4`}),warning:(0,Q.jsx)(St,{className:`h-4 w-4`}),error:(0,Q.jsx)(vn,{className:`h-4 w-4`}),loading:(0,Q.jsx)(q,{className:`h-4 w-4 animate-spin`})},toastOptions:{duration:4e3,classNames:{toast:`group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg`,description:`group-[.toast]:text-muted-foreground`,actionButton:`group-[.toast]:bg-primary group-[.toast]:text-primary-foreground`,cancelButton:`group-[.toast]:bg-muted group-[.toast]:text-muted-foreground`}},...e})}var Qo=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function $o({children:e,className:t}){let n=l(),r=Z.useRef(null),i=Z.useRef(n.pathname);return Z.useLayoutEffect(()=>{if(i.current===n.pathname)return;i.current=n.pathname;let e=r.current;e&&(e.classList.remove(...Qo),e.offsetWidth,e.classList.add(...Qo))},[n.pathname]),(0,Q.jsx)(`div`,{ref:r,className:[...Qo,t??``].filter(Boolean).join(` `),children:e})}var es=null,ts=null;function ns(){return ts||(ts=(async()=>{let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},t=e.VITE_SENTRY_DSN;if(!t)return!1;try{let n=await u(()=>import(`./vendor-sentry-BIOhD5Kg.js`).then(e=>e.t),[],import.meta.url),r=Number(e.VITE_SENTRY_TRACES_SAMPLE_RATE??`0.1`);return n.init({dsn:t,environment:e.VITE_SENTRY_ENVIRONMENT||e.MODE||`production`,release:e.VITE_SENTRY_RELEASE||e.VITE_APP_VERSION||`unknown`,tracesSampleRate:Number.isFinite(r)?r:.1,sendDefaultPii:e.VITE_SENTRY_SEND_DEFAULT_PII!==`false`,replaysSessionSampleRate:0,replaysOnErrorSampleRate:e.VITE_SENTRY_REPLAY===`true`?.1:0,integrations:[n.browserTracingIntegration()],beforeBreadcrumb(e){return(e.category===`fetch`||e.category===`xhr`)&&e.data?.url&&typeof e.data.url==`string`&&(e.data.url=is(e.data.url)),e}}),es=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),ts)}function rs(e,t){if(es)try{es.captureException(e,t?{extra:t}:void 0)}catch{}}function is(e){try{let t=new URL(e,`http://localhost`);for(let e of[`token`,`access_token`,`id_token`,`apiKey`,`api_key`,`password`])t.searchParams.has(e)&&t.searchParams.set(e,`[redacted]`);return t.pathname+(t.searchParams.toString()?`?`+t.searchParams.toString():``)}catch{return e}}function as({error:e,onReset:t}){let{t:n}=H();return(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-8`,children:(0,Q.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10`,children:(0,Q.jsx)(St,{className:`h-6 w-6 text-destructive`})}),(0,Q.jsx)(Pe,{children:n(`console.errors.somethingWentWrong`)}),(0,Q.jsx)(Gr,{className:`mb-4`,children:e.message||n(`console.errors.unexpectedError`)}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Q.jsxs)(J,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,Q.jsx)(W,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,Q.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,Q.jsx)(ce,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var os=class extends Z.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary] Caught error:`,e,t),rs(e,{componentStack:t.componentStack}),this.props.onError?.(e,t)}resetErrorBoundary=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?typeof this.props.fallback==`function`?this.props.fallback({error:this.state.error,reset:this.resetErrorBoundary}):this.props.fallback:(0,Q.jsx)(as,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}},ss=new Set([`form`,`detail`]);function cs(e){return typeof e==`string`&&ss.has(e)}function ls(e,t){let n=e.type||`grid`,r=cs(n)?`form`:`list`,i=e.label,a=e.data&&typeof e.data==`object`?e.data:void 0;return{name:e.id,object:t,viewKind:r,label:i,config:{...e,type:n,label:i,columns:Array.isArray(e.columns)?e.columns:[],data:{...a,object:t}}}}function us(e){let t=e.config??{},n={...t};return delete n.data,{...n,id:e.name,label:e.label??t.label}}function ds(e){let t=e.fields;return!t||typeof t!=`object`?[]:Object.entries(t).map(([e,t])=>{let n=t??{};return{name:e,label:typeof n.label==`string`&&n.label?n.label:e,type:typeof n.type==`string`?n.type:`text`,hidden:n.hidden===!0}})}function fs({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s,metadataClient:c,onAfterChange:l}){let{t:u}=H(),d=(0,Z.useRef)(null),f=(0,Z.useMemo)(()=>zi(),[]),[p]=(0,Z.useState)(()=>`view_${Date.now()}`),m=(0,Z.useMemo)(()=>({id:p,label:u(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[]}),[]),h=(0,Z.useMemo)(()=>ls(n===`create`?m:r,i.name),[n===`create`?`create`:r.id,i.name]),[g,_]=(0,Z.useState)(h),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(0),S=(0,Z.useRef)(g),C=(0,Z.useRef)(h);C.current!==h&&(C.current=h,S.current=h,_(h),y(!1)),(0,Z.useEffect)(()=>{S.current=g},[g]),(0,Z.useEffect)(()=>{e&&d.current&&d.current.focus()},[e]);let w=(0,Z.useMemo)(()=>ds(i),[i.fields]),T=Ui(g.viewKind)?`form`:`list`,E=(0,Z.useCallback)(e=>{let t={...S.current,...e};if(S.current=t,_(t),y(!0),a){let e=us(t);for(let[t,n]of Object.entries(e))t!==`id`&&a(t,n)}},[a]),D=(0,Z.useCallback)(()=>{let e=us(g);n===`create`?s?.(e):(o?.(e),x(e=>e+1)),y(!1)},[g,o,s,n]),O=(0,Z.useCallback)(()=>{if(n===`create`){t();return}_(h),y(!1)},[h,n,t]),k=(0,Z.useCallback)(e=>{let t=ls(e,i.name);S.current=t,_(t),y(!1)},[i.name]),A=u(n===`create`?`console.objectView.createView`:`console.objectView.configureView`);return e?(0,Q.jsxs)(`div`,{ref:d,tabIndex:-1,role:`complementary`,"aria-label":A,"data-testid":`view-config-panel`,className:`flex h-full flex-col`,children:[(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,Q.jsx)(Yi,{type:`view`,name:g.name,draft:g,variantKey:`config`,familyKey:T,isHome:!0,readOnly:!1,locale:f,objectFieldsOverride:w,onPatch:E})}),(0,Q.jsxs)(`div`,{"data-testid":`view-config-footer`,className:`flex items-center justify-end gap-2 border-t px-4 py-2.5`,children:[n===`edit`&&(0,Q.jsx)(Da,{type:`view`,name:r.id,metadataClient:c,dirty:v,onResume:k,savedSignal:b,onAfterChange:l}),(0,Q.jsx)(J,{variant:`ghost`,size:`sm`,onClick:O,"data-testid":`view-config-discard`,children:u(`console.objectView.discard`)}),(0,Q.jsx)(J,{size:`sm`,onClick:D,disabled:n===`edit`&&!v,"data-testid":`view-config-save`,children:u(`console.objectView.save`)})]})]}):(0,Q.jsx)(`div`,{ref:d,tabIndex:-1,"data-testid":`view-config-panel`,"aria-hidden":!0})}function ps(e){return[{type:`grid`,icon:Kr,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:lr,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:Ae,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:Ut,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:_r,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:pn,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:we,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:st,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)}]}function ms(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var hs={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:ya}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:xa},{key:`titleField`,i18nKey:`console.objectView.titleField`,helpI18nKey:`console.objectView.titleFieldHelp`,filter:e=>e.type===`text`}],timeline:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.timelineDateFieldHelp`,filter:e=>e.type===`date`,preferred:xa},{key:`titleField`,i18nKey:`console.objectView.titleField`,helpI18nKey:`console.objectView.titleFieldHelp`,filter:e=>e.type===`text`}],gantt:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.ganttStartDateFieldHelp`,filter:e=>e.type===`date`,preferred:xa},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:Ca},{key:`titleField`,i18nKey:`console.objectView.titleField`,helpI18nKey:`console.objectView.titleFieldHelp`,filter:e=>e.type===`text`}],gallery:[{key:`coverField`,i18nKey:`console.objectView.imageField`,helpI18nKey:`console.objectView.imageFieldHelp`,filter:e=>ba(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&ha(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&ha(e,`longitude`)}],chart:[{key:`chartType`,i18nKey:`console.objectView.chartType`,helpI18nKey:`console.objectView.chartTypeHelp`,kind:`enum`,enumOptions:[{value:`bar`,i18nKey:`console.objectView.chartTypeBar`},{value:`line`,i18nKey:`console.objectView.chartTypeLine`},{value:`pie`,i18nKey:`console.objectView.chartTypePie`},{value:`area`,i18nKey:`console.objectView.chartTypeArea`},{value:`scatter`,i18nKey:`console.objectView.chartTypeScatter`}],defaultValue:`bar`},{key:`xAxisField`,i18nKey:`console.objectView.xAxisField`,helpI18nKey:`console.objectView.xAxisFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`||e.type===`date`||e.type===`text`,preferred:ya},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}]};function gs({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=H(),s=(0,Z.useMemo)(()=>ps(o),[o]),c=(0,Z.useMemo)(()=>i&&i.length>0?s.filter(e=>i.includes(e.type)):s,[s,i]),l=(0,Z.useMemo)(()=>new Set(r??[]),[(r??[]).join(`\0`)]),u=(0,Z.useMemo)(()=>a?_a(a):[],[a]),[d,f]=(0,Z.useState)(c[0]?.type??`grid`),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)({});(0,Z.useEffect)(()=>{e&&(f(c[0]?.type??`grid`),g(!1),v({}))},[e,c]),(0,Z.useEffect)(()=>{h||m(ms(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=hs[d]??[],b=e=>e.kind===`enum`?(e.enumOptions?.length??0)>0:a?(e.filter?u.filter(e.filter):u).length>0:!0,x=(0,Z.useMemo)(()=>{let e={};return c.forEach(t=>{let n=(hs[t.type]??[]).find(e=>!b(e));e[t.type]=n??null}),e},[c,u,a]),S=e=>_[`${d}.${e}`]??``,C=(e,t)=>v(n=>({...n,[`${d}.${e}`]:t})),w=p.trim(),T=w.length>0&&l.has(w),E=y.every(e=>S(e.key).length>0),D=w.length>0&&!T&&E;(0,Z.useEffect)(()=>{y.length!==0&&y.forEach(e=>{if(S(e.key).length>0)return;if(e.kind===`enum`){e.defaultValue&&C(e.key,e.defaultValue);return}let t=e.filter?u.filter(e.filter):u;if(t.length===0)return;if(t.length===1){C(e.key,t[0].value);return}let n=Sa(t,e.preferred??[]);n&&C(e.key,n)})},[d,u]);let O=()=>{if(!D)return;let e={};y.forEach(t=>{let n=S(t.key);n&&(e[t.key]=t.key===`yAxisFields`?[n]:n)});let r={type:d,label:w};Object.keys(e).length>0&&(r[d]=e),n(r),t(!1)};return(0,Q.jsx)($e,{open:e,onOpenChange:t,children:(0,Q.jsxs)(xt,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,Q.jsxs)(Lt,{children:[(0,Q.jsx)(Ie,{children:o(`console.objectView.createView`)}),(0,Q.jsx)(qr,{children:o(`console.objectView.createViewDesc`)})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-4 gap-2 py-2`,"data-testid":`create-view-type-grid`,children:c.map(({type:e,label:t,description:n,icon:r})=>{let i=e===d,a=x[e],s=!!a,c=s?o(`console.objectView.viewTypeUnavailable`,{field:o(a.i18nKey)}):void 0;return(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`create-view-type-${e}`,"aria-pressed":i,"aria-disabled":s,disabled:s,title:c,onClick:()=>{s||f(e)},className:yn(`group flex flex-col items-start gap-1 rounded-lg border bg-background p-3 text-left transition-colors`,!s&&`hover:border-primary/60 hover:bg-accent/40`,i&&!s?`border-primary ring-2 ring-primary/30 bg-accent/40`:`border-border`,s&&`opacity-50 cursor-not-allowed`),children:[(0,Q.jsx)(r,{className:yn(`h-5 w-5`,i&&!s?`text-primary`:`text-muted-foreground group-hover:text-foreground`)}),(0,Q.jsx)(`div`,{className:`text-xs font-medium leading-tight`,children:t}),(0,Q.jsx)(`div`,{className:`text-[10px] leading-tight text-muted-foreground line-clamp-2`,children:s?o(`console.objectView.viewTypeUnavailableShort`):n})]},e)})}),y.length>0&&(0,Q.jsx)(`div`,{className:`space-y-3 rounded-md border border-dashed bg-muted/30 p-3`,"data-testid":`create-view-required-fields`,children:y.map(e=>{let t=S(e.key),n=e.kind===`enum`,r=n?[]:e.filter?u.filter(e.filter):u,i=!n&&u.length>0&&r.length===0;return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`label`,{htmlFor:`create-view-required-${e.key}`,className:`text-xs font-medium`,children:[o(e.i18nKey),(0,Q.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,Q.jsxs)(`select`,{id:`create-view-required-${e.key}`,"data-testid":`create-view-required-${e.key}`,value:t,onChange:t=>C(e.key,t.target.value),disabled:i,className:yn(`h-9 w-full rounded-md border bg-background px-2 text-xs`,`border-input`),children:[(0,Q.jsx)(`option`,{value:``,children:o(n?`console.objectView.selectOption`:`console.objectView.selectField`)}),n?e.enumOptions.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:o(e.i18nKey)},e.value)):r.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),e.helpI18nKey&&!i&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(e.helpI18nKey)}),i&&(0,Q.jsxs)(`p`,{className:`flex items-center gap-1 text-[11px] text-destructive`,"data-testid":`create-view-error-no-field-${e.key}`,children:[(0,Q.jsx)(Ur,{className:`h-3 w-3`}),o(`console.objectView.noEligibleFieldForType`)]})]},e.key)})}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsxs)(`label`,{htmlFor:`create-view-name-input`,className:`text-xs font-medium`,children:[o(`console.objectView.title`),(0,Q.jsx)(`span`,{className:`ml-1 text-destructive`,children:`*`})]}),(0,Q.jsx)(Y,{id:`create-view-name-input`,"data-testid":`create-view-name-input`,autoFocus:!0,value:p,onChange:e=>{m(e.target.value),g(!0)},onKeyDown:e=>{e.key===`Enter`&&D&&O()},placeholder:o(`console.objectView.newView`),className:`h-9`}),T&&(0,Q.jsx)(`p`,{className:`text-[11px] text-destructive`,"data-testid":`create-view-error-duplicate`,children:o(`console.objectView.duplicateViewName`)})]}),(0,Q.jsxs)(ge,{className:`mt-2`,children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>t(!1),"data-testid":`create-view-cancel`,children:o(`console.objectView.cancel`)}),(0,Q.jsx)(J,{type:`button`,disabled:!D,onClick:O,"data-testid":`create-view-submit`,children:o(`console.objectView.create`)})]})]})})}function _s(e,t){switch(e){case`system`:return{icon:`Lock`,title:t(`list.managedBy.system.title`,{defaultValue:`Nothing here yet`}),message:t(`list.managedBy.system.message`,{defaultValue:`Entries appear automatically when their source action runs (e.g. Submit for Approval, Share, Invite). Trigger one of those on a source record to create a row.`})};case`append-only`:return{icon:`Archive`,title:t(`list.managedBy.appendOnly.title`,{defaultValue:`No events recorded`}),message:t(`list.managedBy.appendOnly.message`,{defaultValue:`This is an immutable audit log. Rows are written by the platform when events occur — you can export the history but cannot create entries from here.`})};case`better-auth`:return{icon:`ShieldAlert`,title:t(`list.managedBy.betterAuth.title`,{defaultValue:`No identity records`}),message:t(`list.managedBy.betterAuth.message`,{defaultValue:`Identity rows are managed by the authentication provider. Use the dedicated identity workflows (Invite User, Reset Password, …) to create new entries.`})};default:return}}var vs=(0,Z.lazy)(()=>u(()=>import(`./plugin-charts-Do3qrshN.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),ys=(0,Z.lazy)(()=>u(()=>import(`./plugin-grid-Cd-2qFJP.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),bs={grid:Xt,kanban:lr,calendar:Ae,gallery:Kr,timeline:Or,gantt:Jn,map:Se,chart:st},xs={id:`current-user`,name:`Demo User`};function Ss(e,t){if(!Array.isArray(e))return e;let n=e=>{if(typeof e==`string`)return e===`{current_user_id}`?t??e:e;if(Array.isArray(e))return e.map(n);if(e&&typeof e==`object`){let t={};for(let r of Object.keys(e))t[r]=n(e[r]);return t}return e};return e.map(n)}function Cs({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let{objectName:i}=o(),{t:a}=H();return t.find(e=>e.name===i)?(0,Q.jsx)(ws,{dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}):(0,Q.jsx)(`div`,{className:`h-full p-4 flex items-center justify-center`,children:(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Q.jsx)(Xt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Q.jsx)(Pe,{children:a(`console.objectView.objectNotFound`)}),(0,Q.jsxs)(Gr,{children:[a(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,a(`console.objectView.objectNotFoundHint`)]})]})})}function ws({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let i=_(),{appName:a,objectName:s,viewId:c}=o(),[u,d]=p(),f=l(),{showDebug:m}=na(),{t:h}=H(),{objectLabel:g,objectDescription:v,viewLabel:y,viewEmptyState:b,actionLabel:S,actionConfirm:C,actionSuccess:T,actionParamText:E,fieldLabel:D,fieldOptionLabel:O}=er(),{isFavorite:k,toggleFavorite:A}=gi(),N=Ri(),[P,F]=(0,Z.useState)(!1),[te,I]=(0,Z.useState)(`edit`),[ne,L]=(0,Z.useState)(!1),[R,re]=(0,Z.useState)(!1),[z,B]=(0,Z.useState)(null),ie=(0,Z.useRef)({}),ae=(0,Z.useRef)({}),V=(0,Z.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!s||!t)return;let i=ae.current[t]||{};ae.current[t]={...i,...r};let a=ie.current[t];a&&clearTimeout(a),ie.current[t]=setTimeout(()=>{let r=ae.current[t]||{};delete ae.current[t],delete ie.current[t],Promise.resolve(e.updateViewConfig(s,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,s]),oe=(0,Z.useCallback)(e=>{B(e),me(e=>e+1);let t=e.id;N&&t?Ea(`view`,t,e,{metadataClient:N}).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing metadataClient or viewId.`)},[N]),se=(0,Z.useCallback)(async e=>{try{let n;if(N){let r=t?.find?.(e=>e.name===s),i=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),a=[];Array.isArray(r?.compactLayout)&&r.compactLayout.length>0?a=r.compactLayout.filter(e=>r.fields?.[e]):r?.fields&&(a=Object.entries(r.fields).filter(([e,t])=>t&&!t.hidden&&!i.has(e)).map(([e])=>e).slice(0,5));let o=Array.isArray(e.columns)&&e.columns.length>0?e.columns:a,c={...e,columns:o};if(e.type===`kanban`)c.kanban={...c.kanban||{},columns:o};else if(e.type===`gallery`){let e=c.gallery||{};(!Array.isArray(e.visibleFields)||e.visibleFields.length===0)&&(c.gallery={...e,visibleFields:o})}n=await Ta(`view`,String(e?.name??e?.id??c?.id??``),c,{metadataClient:N})}F(!1),I(`edit`),me(e=>e+1),n&&(c?i(`../${n}`,{relative:`path`}):i(`view/${n}`))}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,s,t,i,c,N]),[ce,le]=(0,Z.useState)(void 0),{user:ue,activeOrganization:de}=x(),U=ue?.role===`admin`,{can:fe}=w(),W=t.find(e=>e.name===s),[pe,me]=(0,Z.useState)(0),he=ka({dataSource:e,objects:t,objectName:W.name,onRefresh:()=>me(e=>e+1)}),{confirmHandler:ge,toastHandler:_e}=he,ve=(0,Z.useMemo)(()=>wi(W),[W]);(0,Z.useEffect)(()=>{r===void 0||r===0||me(e=>e+1)},[r]);let[ye,be]=(0,Z.useState)(!1),[xe,Se]=(0,Z.useState)([]);(0,Z.useEffect)(()=>{let t=!1;if(!s){Se([]);return}return typeof e?.listViews==`function`?(e.listViews(s).then(e=>{t||Se((e||[]).map(e=>({...e,id:e.name||e.id,objectName:e.objectName||e.object||s})))}).catch(e=>{console.error(`[ObjectView] Failed to load overlay views:`,e),t||Se([])}),()=>{t=!0}):(Se([]),()=>{t=!0})},[e,s,pe]);let[Ce,we]=(0,Z.useState)({});(0,Z.useEffect)(()=>{let t=!1;if(!e||!s){we({});return}let n=W.listViews||W.list_views||{},r=Object.keys(n),i=W.list;if(i&&typeof i==`object`){let e=i.name||`list`;r.includes(e)||r.unshift(e)}if(r.length===0){we({});return}return(async()=>{if(typeof e.listViewOverrides==`function`)try{let t=await e.listViewOverrides(s);if(t&&typeof t==`object`){let e={};for(let n of r)t[n]&&(e[n]=t[n]);return e}}catch{}if(typeof e.getView!=`function`)return{};let t=await Promise.all(r.map(async t=>{try{return[t,await e.getView(s,t)]}catch{return[t,null]}})),n={};for(let[e,r]of t)r&&typeof r==`object`&&(n[e]=r);return n})().then(e=>{t||we(e)}),()=>{t=!0}},[e,s,W.listViews,W.list_views,W.list,pe]);let Te=(0,Z.useMemo)(()=>{let e=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),t=()=>Array.isArray(W.compactLayout)&&W.compactLayout.length>0?W.compactLayout.filter(e=>W.fields?.[e]):W.fields?Object.entries(W.fields).filter(([t,n])=>!(!n||n.hidden||e.has(t))).map(([e])=>e).slice(0,5):[],n=W.listViews||W.list_views||{},r=Object.entries(n).map(([e,t])=>{let n=Ce[e];return{id:e,...t,...n||{},type:n?.type||t.type||`grid`}}),i=W.list;if(i&&typeof i==`object`){let e=i.name||`list`,t=r.findIndex(t=>t.id===e);if(t>=0){let[e]=r.splice(t,1);r.unshift({...e,isDefault:!0})}else{let t=Ce[e];r.unshift({id:e,...i,...t||{},type:t?.type||i.type||`grid`,isDefault:!0})}}r.length===0&&r.push({id:`all`,label:h(`console.objectView.allRecords`),type:`grid`,columns:t()});let a=new Set(r.map(e=>e.id));for(let e of xe){let t=e.id||e._id;if(!t)continue;let n={label:e.label||e.name||t,type:e.type||`grid`,columns:e.columns,filter:e.filter,sort:e.sort,showSearch:e.showSearch,showFilters:e.showFilters,showSort:e.showSort,isPinned:e.isPinned,isDefault:e.isDefault,visibility:e.visibility,sortOrder:e.sortOrder,...e,id:t},i={};for(let[e,t]of Object.entries(n))t!==void 0&&(i[e]=t);if(a.has(t)){let e=r.findIndex(e=>e.id===t);r[e]={...r[e],...i}}else r.push(i)}let o=new Set([`grid`,`list`,`table`]);for(let e of r)o.has(e.type)&&(!Array.isArray(e.columns)||e.columns.length===0)&&(e.columns=t());let s=new Map(r.map((e,t)=>[e.id,t])),c=[];try{let e=typeof window<`u`?window.localStorage?.getItem(`viewOrder:${W.name}`):null;e&&(c=JSON.parse(e))}catch{}let l=new Map(c.map((e,t)=>[e,t]));return r.sort((e,t)=>{let n=l.get(e.id),r=l.get(t.id);if(n!==void 0&&r!==void 0)return n-r;if(n!==void 0)return-1;if(r!==void 0)return 1;let i=xe.find(t=>(t.id||t._id)===e.id),a=xe.find(e=>(e.id||e._id)===t.id),o=i&&typeof i.sortOrder==`number`,c=a&&typeof a.sortOrder==`number`;return o&&c?i.sortOrder===a.sortOrder?(i.created_at||``).localeCompare(a.created_at||``):i.sortOrder-a.sortOrder:o?-1:c?1:(s.get(e.id)??0)-(s.get(t.id)??0)}),r},[W,xe,Ce,h]),Ee=(0,Z.useMemo)(()=>Te.find(e=>e.isDefault)?.id,[Te]),G=c||u.get(`view`)||Ee||Te[0]?.id,De=Te.find(e=>e.id===G)||Te[0],K=z&&z.id===De?.id?{...De,...z}:De,Oe=(0,Z.useCallback)((e,t)=>{B(n=>({...n||{},id:De?.id,[e]:t}))},[De?.id]),ke=e=>{let t=Te.find(t=>t.id===e);t&&(t.id!==G&&F(!1),c?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},Ae=(0,Z.useMemo)(()=>(Te||[]).map(e=>{let t=bs[e.type];return{id:e.id,label:y(W.name,e.name||e.id,e.label||e.name||e.id),icon:t?(0,Q.jsx)(t,{className:`h-4 w-4`}):void 0}}),[Te,W.name,y]);Po({views:Ae,activeViewId:G??``,onChange:ke,enabled:Ae.length>0&&!!G});let je=(0,Z.useCallback)(()=>{L(!0)},[]),Me=(0,Z.useCallback)((e,t)=>{if(e===`settings`){let e=Te.find(e=>e.type===t);e&&ke(e.id),I(`edit`),F(!0)}},[Te,ke]),Ne=(0,Z.useCallback)(e=>xe.some(t=>(t.id||t._id)===e),[xe]),Pe=(0,Z.useCallback)(async(t,n)=>{if(!Ne(t)){X.error(h(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be renamed.`);return}try{typeof e?.updateView==`function`&&await e.updateView(s,t,{label:n}),me(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),X.error(h(`objectViewActions.renameFailed`))}},[e,s,Ne,h]),Fe=(0,Z.useCallback)(async t=>{if(!e)return;if(!Ne(t)){X.error(h(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=Te.find(e=>e.id===t)?.label||t;if(await ge(h(`console.objectView.deleteViewConfirm`,{name:n})||`Are you sure you want to delete the view "${n}"? This cannot be undone.`,{title:h(`console.objectView.deleteViewTitle`)||`Delete view`,confirmText:h(`console.objectView.delete`)||`Delete`,cancelText:h(`console.objectView.cancel`)||`Cancel`}))try{if(typeof e?.deleteView==`function`&&await e.deleteView(s,t),t===G){let e=Te.find(e=>e.id!==t);e&&i(c?`../${e.id}`:`view/${e.id}`,c?{relative:`path`}:void 0)}me(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),X.error(h(`objectViewActions.deleteFailed`))}},[e,Ne,G,Te,c,i,h,ge]),Ie=(0,Z.useCallback)(async(t,n)=>{if(e){if(!Ne(t)){X.error(h(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be pinned.`);return}try{typeof e?.updateView==`function`&&await e.updateView(s,t,{isPinned:n}),me(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,s,Ne,h]),Le=(0,Z.useCallback)(async t=>{if(e){if(!Ne(t)){X.error(h(`console.objectView.cannotEditMetaView`)||`System view — it cannot be set as a default.`);return}try{if(typeof e?.updateView!=`function`)return;let n=e.updateView,r=xe.filter(e=>(e.id||e._id)!==t&&e.isDefault).map(e=>n(s,e.id||e._id,{isDefault:!1}));r.push(n(s,t,{isDefault:!0})),await Promise.all(r),me(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),X.error(`Failed to set default view`)}}},[e,s,xe,Ne,h]),Re=(0,Z.useCallback)(async t=>{try{typeof window<`u`&&window.localStorage?.setItem(`viewOrder:${s}`,JSON.stringify(t))}catch{}if(typeof e?.updateView==`function`){let n=e.updateView,r=new Set(xe.map(e=>e.id||e._id)),i=t.filter(e=>r.has(e)).map((e,t)=>n(s,e,{sortOrder:t}));try{await Promise.all(i)}catch(e){console.error(`[ViewTabBar] Failed to reorder views:`,e)}}me(e=>e+1)},[e,xe,s]),Be=(0,Z.useCallback)(e=>{if(!Ne(e)){X.error(h(`console.objectView.cannotEditMetaView`)||`System view — it cannot be edited.`);return}e!==G&&ke(e),I(`edit`),F(!0)},[G,ke,Ne,h]),Ve=(0,Z.useCallback)(()=>{L(!0)},[]),He=ue?{id:ue.id,name:ue.name,avatar:ue.image}:xs,Ue=Ra({objectName:W.name,objectLabel:W.label,dataSource:e,onEdit:n,onRefresh:()=>me(e=>e+1),onConfirm:ge,onToast:_e}),{lastMessage:We}=Ti({channel:`object:${W.name}`}),{hasConflicts:Ge,resolveAllConflicts:Ke}=Ci(W.name?`user-${W.name}`:`current-user`);(0,Z.useEffect)(()=>{We&&(Ge&&Ke(`remote`),me(e=>e+1))},[We,Ge,Ke]),(0,Z.useEffect)(()=>{e?.find&&W.name&&e.find(W.name,{limit:0}).then(e=>{typeof e?.total==`number`?le(e.total):Array.isArray(e?.data)?le(e.data.length):Array.isArray(e)&&le(e.length)}).catch(()=>{})},[e,W.name,pe]);let qe=(0,Z.useMemo)(()=>K?.navigation??W.navigation??{mode:`drawer`,width:`min(92vw, 1280px)`},[K?.navigation,W.navigation]),Je=u.get(`recordId`),Ye=Array.from(u.entries()).filter(([e])=>e.startsWith(`filter[`)).map(([e,t])=>`${e}=${t}`).join(`&`),Xe=(0,Z.useMemo)(()=>{let e=[];return new URLSearchParams(Ye).forEach((t,n)=>{let r=/^filter\[(.+)\]$/.exec(n);r&&r[1]&&t!==``&&e.push([r[1],`=`,t])}),e},[Ye]),[Ze]=(0,Z.useState)(()=>da(new URLSearchParams(window.location.search))),Qe=(0,Z.useCallback)(e=>{d(t=>ua(t,e),{replace:!0})},[d]),$e=(0,Z.useCallback)((e,t)=>{if(t===`new_window`){let t=window.location.pathname.replace(/\/view\/.*$/,``);window.open(`${t}/record/${encodeURIComponent(String(e))}`,`_blank`);return}let n={from:{pathname:f.pathname+(f.search||``),label:y(W.name,K?.name??``,K?.label??``)||g(W)}};c?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):i(`record/${encodeURIComponent(String(e))}`,{state:n})},[i,c,f.pathname,f.search,W,K?.name,K?.label,y,g]),et=M({navigation:qe,objectName:W.name,onNavigate:$e}),tt=()=>{et.close();let e=new URLSearchParams(u);e.delete(`recordId`),d(e)},nt=(0,Z.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){et.handleClick(e,t);return}if(et.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(u);e.set(`recordId`,String(t)),d(e);return}}et.handleClick(e,t)},[et,u,d]),q=(0,Z.useCallback)(()=>{let e=et.selectedRecord,t=e&&(e.id??e._id);t!=null&&(tt(),$e(t))},[et.selectedRecord,$e]);(0,Z.useEffect)(()=>{Je&&!et.isOpen?et.open({id:Je}):!Je&&et.isOpen&&et.close()},[Je]);let rt=(0,Z.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=pe+(i||0),o=`${s}-${K.id}-${a}`,c=K;if(c.type===`chart`){let e=c.chart||{};if(e.dataset){let n=Array.isArray(e.dimensions)?e.dimensions:[],r=Array.isArray(e.values)?e.values:[];return(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,Q.jsx)(vs,{dataSource:t,schema:{type:`object-chart`,dataset:e.dataset,dimensions:n,values:r,chartType:e.chartType||`bar`,xAxisKey:n[0],series:r.map(e=>({dataKey:e,label:e})),config:e.config,className:`h-[400px] w-full`}})},o)}let n=e.xAxisField||`name`,r=Array.isArray(e.yAxisFields)&&e.yAxisFields[0]||`value`,i=e.aggregation||`count`,a=e.series&&e.series.length>0?e.series:[{dataKey:r,label:r}];return(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,Q.jsx)(vs,{dataSource:t,schema:{type:`object-chart`,objectName:W.name,chartType:e.chartType||`bar`,aggregate:{field:r,function:i,groupBy:n},xAxisKey:n,series:a,config:e.config,filter:e.filter,className:`h-[400px] w-full`}})},o)}return(0,Q.jsx)(fa,{schema:{...e,rowHeight:c.rowHeight??e.rowHeight,densityMode:c.densityMode??e.densityMode,sort:c.sort??e.sort,filter:(()=>{let t=Ss(c.filter??e.filter,He.id);return Xe.length?[...Array.isArray(t)?t:[],...Xe]:t})(),hiddenFields:c.hiddenFields??e.hiddenFields,columnState:c.columnState??e.columnState,onDensityChange:e=>{V(c.id,c,{densityMode:e})},onSortChange:e=>{V(c.id,c,{sort:e})},onFilterChange:e=>{V(c.id,c,{filter:e})},onHiddenFieldsChange:e=>{V(c.id,c,{hiddenFields:e})},onColumnStateChange:e=>{V(c.id,c,{columnState:e})},inlineEdit:c.inlineEdit??c.editRecordsInline??e.inlineEdit,appearance:c.appearance?c.showDescription==null?c.appearance:{...c.appearance,showDescription:c.showDescription}:c.showDescription==null?e.appearance:{showDescription:c.showDescription},showViewSwitcher:((c.appearance??e.appearance)?.allowedVisualizations?.length??0)>1,showSearch:c.showSearch??e.showSearch,showSort:c.showSort??e.showSort,showFilters:c.showFilters??e.showFilters,showHideFields:c.showHideFields??e.showHideFields,showGroup:c.showGroup??e.showGroup,showColor:c.showColor??e.showColor,showDensity:c.showDensity??e.showDensity,allowExport:c.allowExport??e.allowExport,exportOptions:c.allowExport===!1?void 0:c.exportOptions??e.exportOptions,striped:c.striped??e.striped,bordered:c.bordered??e.bordered,color:c.color??e.color,wrapHeaders:c.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:c.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:c.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:c.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:c.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:c.fieldTextColor??e.fieldTextColor,prefixField:c.prefixField??e.prefixField,showDescription:c.showDescription??e.showDescription,navigation:c.navigation??e.navigation,selection:c.selection??e.selection,pagination:c.pagination??e.pagination,searchableFields:c.searchableFields??e.searchableFields,filterableFields:c.filterableFields??e.filterableFields,resizable:c.resizable??e.resizable,rowActions:c.rowActions??e.rowActions,rowActionDefs:Array.isArray(W?.actions)?W.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)).map(e=>({...e,label:S(W.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:C(W.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:T(W.name,e.name,e.successMessage)}})):[],bulkActions:c.bulkActions??e.bulkActions,bulkActionDefs:c.bulkActionDefs??e.bulkActionDefs,sharing:c.sharing??e.sharing,addRecord:c.addRecord??e.addRecord,conditionalFormatting:c.conditionalFormatting??e.conditionalFormatting,quickFilters:c.quickFilters??e.quickFilters,userFilters:c.userFilters??e.userFilters,showRecordCount:c.showRecordCount??e.showRecordCount,allowPrinting:c.allowPrinting??e.allowPrinting,virtualScroll:c.virtualScroll??e.virtualScroll,emptyState:b(W.name,c.name||c.id||``,c.emptyState??e.emptyState??_s(W?.managedBy,h)),aria:c.aria??e.aria,tabs:c.tabs??e.tabs,...(()=>{let e=Ss([...Array.isArray(c.filter)?c.filter:[],...Xe],He.id);return Array.isArray(e)&&e.length?{filters:e}:{}})(),...c.sort?.length?{sort:c.sort}:{},options:{kanban:{groupBy:c.kanban?.groupByField||c.kanban?.groupField||`status`,groupField:c.kanban?.groupByField||c.kanban?.groupField||`status`,titleField:c.kanban?.titleField||W.titleField||`name`,cardFields:c.kanban?.columns},calendar:{startDateField:c.calendar?.startDateField||`due_date`,endDateField:c.calendar?.endDateField,titleField:c.calendar?.titleField||`name`,colorField:c.calendar?.colorField,allDayField:c.calendar?.allDayField,defaultView:c.calendar?.defaultView},timeline:{dateField:c.timeline?.dateField||`due_date`,titleField:c.timeline?.titleField||W.titleField||`name`,descriptionField:c.timeline?.descriptionField},map:{locationField:c.map?.locationField,titleField:c.map?.titleField||W.titleField||`name`,latitudeField:c.map?.latitudeField,longitudeField:c.map?.longitudeField,zoom:c.map?.zoom,center:c.map?.center},gallery:{...c.gallery||{},imageField:c.gallery?.imageField||c.gallery?.coverField||`image`,coverField:c.gallery?.coverField||c.gallery?.imageField,titleField:c.gallery?.titleField||W.titleField||`name`,subtitleField:c.gallery?.subtitleField},gantt:{startDateField:c.gantt?.startDateField||`start_date`,endDateField:c.gantt?.endDateField||`end_date`,titleField:c.gantt?.titleField||`name`,progressField:c.gantt?.progressField,dependenciesField:c.gantt?.dependenciesField,colorField:c.gantt?.colorField},chart:{chartType:c.chart?.chartType,xAxisField:c.chart?.xAxisField,yAxisFields:c.chart?.yAxisFields,aggregation:c.chart?.aggregation,series:c.chart?.series,config:c.chart?.config}}},className:r,onEdit:n,onDelete:e=>{e?.id!=null&&Ue.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&Ue.execute({type:`delete`,confirmText:h(`console.objectView.bulkDeleteConfirm`,{count:t.length,defaultValue:`Delete ${t.length} selected records? This cannot be undone.`}),params:{records:t}})},onRowClick:(e,t)=>{nt(e,t)},onSortChange:e=>{V(c.id,c,{sort:e})},onFilterChange:e=>{V(c.id,c,{filter:e})},onHiddenFieldsChange:e=>{V(c.id,c,{hiddenFields:e})},onColumnStateChange:e=>{V(c.id,c,{columnState:e})},userFilterSelections:Ze,onUserFilterSelectionsChange:Qe,dataSource:t},o)},[K,W,s,pe,et,Ue,V,Xe,Ze,Qe]),it=(0,Z.useMemo)(()=>Te.map(e=>e.id===G&&z&&z.id===e.id?{...e,...z}:e),[Te,G,z]),at=(0,Z.useMemo)(()=>({type:`object-view`,objectName:W.name,layout:`page`,showSearch:K?.showSearch!==!1,showFilters:K?.showFilters!==!1,showSort:K?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:U,viewActions:U?[{type:`settings`},{type:`share`},{type:`delete`}]:[],onNavigate:(e,t)=>{if(t===`edit`)n?.({id:e});else if(t===`view`){let t={from:{pathname:f.pathname+(f.search||``),label:y(W.name,K?.name??``,K?.label??``)||g(W)}};c?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[W,n,K?.showSearch,K?.showFilters,K?.showSort,K?.name,K?.label,i,c,U,f.pathname,f.search,y,g]);return(0,Q.jsxs)(ee,{...he.actionProviderProps,children:[(0,Q.jsxs)(`div`,{className:`h-full flex flex-col bg-background min-w-0 overflow-hidden`,children:[(0,Q.jsx)(`div`,{className:`hidden sm:block`,children:(0,Q.jsx)(Wo,{title:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:g(W)}),(0,Q.jsx)(Oa,{managedBy:W?.managedBy})]}),description:W.description?v(W):void 0,icon:(0,Q.jsx)(Gi(W?.icon),{className:`h-4 w-4`}),actions:(0,Q.jsxs)(Q.Fragment,{children:[s&&(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,onClick:()=>A({id:`object:${s}`,label:g(W),href:`/apps/${a}/${s}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":k(`object:${s}`),"aria-label":k(`object:${s}`)?h(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):h(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${s}`,children:k(`object:${s}`)?(0,Q.jsx)(rr,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Q.jsx)(gr,{className:`h-4 w-4`})}),ve.create&&fe(W.name,`create`)&&(0,Q.jsxs)(J,{size:`sm`,onClick:Ue.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Q.jsx)(Mt,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.new`)})]}),ve.import&&fe(W.name,`create`)&&(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>be(!0),className:`hidden sm:inline-flex shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,title:h(`console.objectView.importTitle`),"data-testid":`object-view-import-button`,children:[(0,Q.jsx)(ht,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.import`)})]}),W.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(0,Q.jsx)(j,{schema:{type:`action:bar`,location:`list_toolbar`,actions:(W.actions||[]).map(e=>({...e,label:S(W.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:C(W.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:T(W.name,e.name,e.successMessage)}})),size:`sm`,variant:`outline`,mobileMaxVisible:0}})]})})}),ve.create&&fe(W.name,`create`)&&(0,Q.jsx)(`button`,{type:`button`,onClick:Ue.create,className:`sm:hidden fixed right-4 bottom-36 z-40 h-12 w-12 rounded-full bg-primary text-primary-foreground shadow-lg active:scale-95 transition-transform inline-flex items-center justify-center`,"aria-label":h(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,Q.jsx)(Mt,{className:`h-5 w-5`})}),ye&&(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(ys,{open:ye,onOpenChange:be,objectName:W.name,objectLabel:g(W),fields:Object.entries(W.fields||{}).map(([e,t])=>({name:e,label:t?.label||e,type:t?.type||`text`,required:!!t?.required})),dataSource:e,onComplete:e=>{me(e=>e+1);let t=e.importedRows,n=e.skippedRows;n>0?X.warning(h(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&X.success(h(`console.objectView.importedToast`,{count:t}))}})}),Te.length>=1&&(()=>{let e=Te.map(e=>{let t=xe.find(t=>(t.id||t._id)===e.id),n=!t;return{id:e.id,label:y(W.name,e.name||e.id,e.label||e.name||e.id),type:e.type,hasActiveFilters:Array.isArray(e.filter)&&e.filter.length>0,hasActiveSort:Array.isArray(e.sort)&&e.sort.length>0,isDefault:!!(t?.isDefault??e.isDefault),isPinned:!!(t?.isPinned??e.isPinned),visibility:t?.visibility??e.visibility,readonly:n,readonlyReason:n?h(`console.objectView.systemViewReadonly`)||`System view defined in code — read-only.`:void 0}});return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(`div`,{className:`hidden sm:block border-b px-3 sm:px-4 bg-background overflow-x-auto shrink-0`,children:[(0,Q.jsx)(va,{views:e,activeViewId:G,onViewChange:ke,viewTypeIcons:bs,config:{reorderable:!1,showAddButton:U,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:U?Ve:void 0,onRenameView:U?Pe:void 0,onDeleteView:U?Fe:void 0,onPinView:U?Ie:void 0,onSetDefaultView:U?Le:void 0,onConfigView:U?Be:void 0,onManageViews:U?()=>re(!0):void 0}),U&&(0,Q.jsx)(ga,{open:R,onOpenChange:re,views:e,activeViewId:G,viewTypeIcons:bs,onRename:Pe,onDelete:Fe,onSetDefault:Le,onSetPinned:Ie,onReorder:Re,onAddView:Ve,onConfigView:Be})]})})})(),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[et.mode===`split`&&et.isOpen?(0,Q.jsx)(ze,{...et,setIsOpen:e=>{e||tt()},title:g(W),onExpand:q,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${W.name}`,mainContent:(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:[(0,Q.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,Q.jsx)(wa,{schema:at,dataSource:e,views:it,activeViewId:G,onViewChange:ke,onEdit:e=>n?.(e),onRowClick:(e,t)=>{nt(e,t)},renderListView:rt,onCreateView:je,onViewAction:Me})})}),typeof ce==`number`&&(0,Q.jsx)(`div`,{"data-testid":`record-count-footer`,className:`border-t px-3 sm:px-4 py-1.5 text-xs text-muted-foreground bg-muted/5 shrink-0`,children:h(`console.objectView.recordCount`,{count:ce})})]}),children:r=>{let i=r.id||r._id;return(0,Q.jsx)(Ei,{dataSource:e,objects:t,onEdit:n,objectNameOverride:W.name,recordIdOverride:i,embedded:!0})}}):(0,Q.jsx)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:(0,Q.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,Q.jsx)(wa,{schema:at,dataSource:e,views:it,activeViewId:G,onViewChange:ke,onEdit:e=>n?.(e),onRowClick:(e,t)=>{nt(e,t)},renderListView:rt,onCreateView:je,onViewAction:Me})})})}),(0,Q.jsx)(ia,{open:m&&U,sections:[{title:`View Configuration`,data:K},{title:`Object Definition`,data:W}]}),(0,Q.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${P&&U?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,Q.jsx)(fs,{open:P&&U,onClose:()=>{F(!1),I(`edit`)},mode:te,activeView:K,objectDef:W,recordCount:ce,onSave:oe,onViewUpdate:Oe,onCreate:se,metadataClient:N,onAfterChange:()=>me(e=>e+1)})}),(0,Q.jsx)(gs,{open:ne&&U,onOpenChange:L,existingLabels:Te.map(e=>e.label).filter(Boolean),objectDef:W,onCreate:e=>se(e)})]}),et.mode!==`split`&&(0,Q.jsx)(ze,{...et,setIsOpen:e=>{e||tt()},title:g(W),onExpand:q,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${W.name}`,children:r=>{let i=r.id||r._id;return(0,Q.jsx)(Ei,{dataSource:e,objects:t,onEdit:n,objectNameOverride:W.name,recordIdOverride:i,embedded:!0})}})]}),he.dialogs]})}function Ts(e,t){return{name:e.name,label:e.label,pluralLabel:e.pluralLabel,description:e.description,icon:e.icon,group:e.group,sortOrder:e.sortOrder,enabled:e.enabled,fields:t,relationships:e.relationships}}function Es(e){return{name:e.name,label:e.label,type:e.type,group:e.group,description:e.description,required:e.required,unique:e.unique,readonly:e.readonly,hidden:e.hidden,defaultValue:e.defaultValue,placeholder:e.placeholder,options:e.options,externalId:e.externalId,trackHistory:e.trackHistory,indexed:e.indexed,referenceTo:e.referenceTo,formula:e.formula,sortOrder:e.sortOrder}}var Ds=class{adapter;constructor(e){this.adapter=e}async getItems(e){let t=await this.adapter.getClient().meta.getItems(e);return t&&typeof t==`object`&&`items`in t&&Array.isArray(t.items)?t.items:[]}async saveMetadataItem(e,t,n){await this.adapter.getClient().meta.saveItem(e,t,n),this.adapter.invalidateCache(`${e}:${t}`)}async deleteMetadataItem(e,t){await this.adapter.getClient().meta.saveItem(e,t,{name:t,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`${e}:${t}`)}async saveObject(e,t){let n=this.adapter.getClient(),r=Ts(e,t);await n.meta.saveItem(`object`,e.name,r),this.adapter.invalidateCache(`object:${e.name}`)}async deleteObject(e){await this.adapter.getClient().meta.saveItem(`object`,e,{name:e,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`object:${e}`)}async saveFields(e,t){let n=this.adapter.getClient(),r={};try{let t=await n.meta.getItem(`object`,e);r=t?.item??t??{}}catch{}let i={...r,name:e,fields:t.map(Es)};await n.meta.saveItem(`object`,e,i),this.adapter.invalidateCache(`object:${e}`)}static diffObjects(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,object:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,object:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,object:t}}return null}static diffFields(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,field:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,field:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,field:t}}return null}};function Os(){let e=se();return(0,Z.useMemo)(()=>e?new Ds(e):null,[e])}var ks=0;function As(e=`nav`){return`${e}_${Date.now()}_${++ks}`}function js(e,t){return[...e,t]}function Ms(e,t,n){return e.filter(e=>!(e.type===t&&(t===`page`&&e.pageName===n||t===`dashboard`&&e.dashboardName===n))).map(e=>e.children&&e.children.length>0?{...e,children:Ms(e.children,t,n)}:e)}function Ns(e,t,n,r){return e.map(e=>{let i=e;return t===`page`&&e.type===`page`&&e.pageName===n?i={...e,pageName:r}:t===`dashboard`&&e.type===`dashboard`&&e.dashboardName===n&&(i={...e,dashboardName:r}),i.children&&i.children.length>0?{...i,children:Ns(i.children,t,n,r)}:i})}function Ps(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function Fs(e){return typeof e==`string`&&e.startsWith(`sys_`)}function Is(e){if(!e||typeof e!=`object`)return!1;let t=e;return t._packageId!=null||t._provenance===`package`?!0:Fs(t.name)}function Ls(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t._lock??t.protection?.lock;return n!==`full`&&n!==`no-overlay`}function Rs(){let e=se(),{apps:t,refresh:n}=F(),{t:r}=H(),i=(0,Z.useRef)(e);i.current=e;let a=(0,Z.useRef)(n);a.current=n;let o=(0,Z.useCallback)(async(e,t)=>{let n=i.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await a.current?.()},[]),s=(0,Z.useCallback)(e=>Bi(t,e),[t]),c=(0,Z.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=js(a,{id:As(`nav_page`),type:`page`,label:n||t,pageName:t,icon:`FileText`}),l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.addedPage`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),l=(0,Z.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=js(a,{id:As(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),u=(0,Z.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=Ms(i,`page`,t);if(Ps(a,i))return;let c={...n,navigation:a};try{await o(e,c),X.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),d=(0,Z.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=Ms(i,`dashboard`,t);if(Ps(a,i))return;let c={...n,navigation:a};try{await o(e,c),X.success(r(`navigationSync.removedDashboard`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),f=(0,Z.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Ns(a,`page`,t,n);if(Ps(c,a))return;let l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.renamedPage`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),p=(0,Z.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Ns(a,`dashboard`,t,n);if(Ps(c,a))return;let l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.renamedDashboard`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),m=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return{syncPageCreated:c,syncDashboardCreated:l,syncPageDeleted:u,syncDashboardDeleted:d,syncPageRenamed:f,syncDashboardRenamed:p,syncPageCreatedAllApps:(0,Z.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!Ls(r)||await c(t,e,n)}},[t,c]),syncDashboardCreatedAllApps:(0,Z.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!Ls(r)||await l(t,e,n)}},[t,l]),syncPageDeletedAllApps:(0,Z.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!Ls(n)||await u(t,e)}},[t,u]),syncDashboardDeletedAllApps:(0,Z.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!Ls(n)||await d(t,e)}},[t,d]),syncPageRenamedAllApps:(0,Z.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!Ls(r)||await f(t,e,n)}},[t,f]),syncDashboardRenamedAllApps:(0,Z.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!Ls(r)||await p(t,e,n)}},[t,p])}}function zs(){let{pages:e,dashboards:t,apps:n,getTypeStatus:r}=F(),i=se(),a=(0,Z.useRef)(i);a.current=i;let o=ci(),{syncPageCreated:s,syncDashboardCreated:c,syncPageDeleted:l,syncDashboardDeleted:u}=Rs(),d=(0,Z.useRef)(null),f=(0,Z.useRef)(null),p=(0,Z.useRef)(0),m=(0,Z.useRef)(!1),h=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,Z.useEffect)(()=>{if(m.current)return;if(o){d.current=null,f.current=null;return}if(r&&(r(`page`)!==`ready`||r(`dashboard`)!==`ready`))return;let i=e=>new Set(e.filter(e=>!Is(e)).map(e=>e?.name).filter(e=>typeof e==`string`&&e.length>0)),a=i(e??[]),g=i(t??[]),_=d.current,v=f.current;if(_===null||v===null){d.current=a,f.current=g;return}let y=[...a].filter(e=>!_.has(e)),b=[..._].filter(e=>!a.has(e)),x=[...g].filter(e=>!v.has(e)),S=[...v].filter(e=>!g.has(e));if(y.length===0&&b.length===0&&x.length===0&&S.length===0){d.current=a,f.current=g;return}let C=++p.current;m.current=!0;let w=!1;return(async()=>{try{for(let e of n){if(w||p.current!==C)break;let t=h(e);if(!(!t||!Ls(e))){for(let e of y){if(w)break;await s(t,e)}for(let e of b){if(w)break;await l(t,e)}for(let e of x){if(w)break;await c(t,e)}for(let e of S){if(w)break;await u(t,e)}}}}finally{p.current===C&&(d.current=a,f.current=g,m.current=!1)}})(),()=>{w=!0}},[e,t,n,o,r,s,c,l,u]),null}var Bs=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function Vs(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Hs(e){try{return decodeURIComponent(e)}catch{return e}}function Us({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=fi(),o=(0,Z.useRef)(n);o.current=n,(0,Z.useEffect)(()=>{if(i||!t)return;let n=e.split(`/`).filter(Boolean);if(n[0]!==r||n[1]!==t)return;let s=n[2],c=n[3],l=`/${r}/${t}`;if(s===`metadata`){let e=n[3],t=n[4];e&&t&&t!==`new`&&a({id:`metadata:${e}:${Hs(t)}`,label:Hs(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!Bs.has(s)){let e=o.current.find(e=>e.name===s);e&&a({id:`object:${e.name}`,label:e.label||e.name,href:`${l}/${e.name}`,type:`object`});return}if(c)switch(s){case`dashboard`:a({id:`dashboard:${c}`,label:Vs(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:Vs(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:Vs(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}var Ws=`objectstack:ai-chat-conversation-id`,Gs=`objectstack:ai-chat-messages`;function Ks(e,t){return t?`${Ws}:${e}:${t}`:`${Ws}:${e}`}function qs(e){try{return localStorage.getItem(e)??void 0}catch{return}}function Js(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function Ys(e){return`${Gs}:${e}`}function Xs(e){try{let t=localStorage.getItem(Ys(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`&&(e.role===`user`||e.role===`assistant`||e.role===`system`)&&Array.isArray(e.parts)):[]}catch{return[]}}function Zs(e,t){if(e)try{if(t.length===0){localStorage.removeItem(Ys(e));return}localStorage.setItem(Ys(e),JSON.stringify(t))}catch{}}function Qs(e){return e.map(e=>{let t=[];if(e.content&&t.push({type:`text`,text:e.content}),e.role===`assistant`)for(let n of e.toolInvocations??[])t.push({type:`tool-${n.toolName}`,toolCallId:n.toolCallId,toolName:n.toolName,state:n.state??(n.errorText?`output-error`:`output-available`),...n.errorText?{errorText:n.errorText}:{}});if(t.length!==0)return{id:e.id,role:e.role,parts:t}}).filter(e=>!!e)}function $s(e){return typeof e==`string`?e?[{type:`text`,text:e}]:[]:Array.isArray(e)?e.map(e=>{if(typeof e==`string`)return e?{type:`text`,text:e}:void 0;if(e&&typeof e==`object`&&`type`in e&&typeof e.type==`string`)return e;if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return{type:`text`,text:e.text}}).filter(e=>!!e):e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts)?$s(e.parts):[]}function ec(e,t){for(let n of $s(e)){let e=typeof n.toolCallId==`string`?n.toolCallId:void 0;if(!e)continue;let r=t.get(e);if(!r)continue;let i=n.output??n.result;if(i===void 0)continue;r.output=i;let a=n.errorText;r.state=n.isError||typeof a==`string`?`output-error`:`output-available`,typeof a==`string`&&(r.errorText=a)}}function tc(e){if(!e)return[];let t=[],n=new Map;return e.forEach((e,r)=>{let i=e.role;if(i===`tool`){ec(e.content,n);return}if(i!==`user`&&i!==`assistant`&&i!==`system`)return;let a=$s(e.content);if(a.length!==0){if(i===`assistant`)for(let e of a){let t=typeof e.toolCallId==`string`?e.toolCallId:void 0;t&&(e.type===`tool-call`||e.type.startsWith(`tool-`))&&n.set(t,e)}t.push({id:e.id??`msg-${r}`,role:i,parts:a})}}),t}async function nc(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(n.status===404||n.status===403)return null;if(!n.ok)throw Error(`GET conversation failed: ${n.status}`);return await n.json()}async function rc(e){let t=await fetch(`${e}/conversations`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:`{}`});if(!t.ok)throw Error(`POST conversation failed: ${t.status}`);return await t.json()}async function ic(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function ac(e){let{userId:t,scope:n,apiBase:r,activeId:i,forceNew:a}=e,[o,s]=(0,Z.useState)(void 0),[c,l]=(0,Z.useState)([]),[u,d]=(0,Z.useState)(!!t),f=(0,Z.useRef)(!0),p=(0,Z.useRef)(void 0);return(0,Z.useEffect)(()=>(f.current=!0,()=>{f.current=!1}),[]),(0,Z.useEffect)(()=>{if(!t){s(void 0),l([]),d(!1),p.current=void 0;return}if(!i&&!a&&p.current===t&&o)return;let e=!1,c=Ks(t,n);return!i&&a&&(s(void 0),l([])),d(!0),(async()=>{try{if(i){let n=await nc(r,i);if(e)return;if(n){Js(c,n.id),s(n.id);let e=tc(n.messages);l(e.length>0?e:Xs(n.id)),p.current=t;return}Js(c,void 0),Zs(i,[])}else if(!a){let n=qs(c);if(n){let i=await nc(r,n);if(e)return;if(i){s(i.id);let e=tc(i.messages);l(e.length>0?e:Xs(i.id)),p.current=t;return}Js(c,void 0),Zs(n,[])}}let n=await rc(r);if(e)return;Js(c,n.id),s(n.id),l(tc(n.messages)),p.current=t}catch{e||(s(void 0),l([]))}finally{e||d(!1)}})(),()=>{e=!0}},[t,n,r,i,a]),{conversationId:o,initialMessages:c,isLoading:u,reset:(0,Z.useCallback)(async()=>{if(!t)return;let e=Ks(t,n);d(!0);try{o&&await ic(r,o),Zs(o,[]),Js(e,void 0);let t=await rc(r);if(Js(e,t.id),Zs(t.id,[]),!f.current)return;s(t.id),l([])}catch{f.current&&(s(void 0),l([]))}finally{f.current&&d(!1)}},[o,t,n,r])}}var oc=new Set([`new chat`,`new conversation`,`untitled`,`新对话`]);function sc(e){let t=e?.trim().toLowerCase();return!t||oc.has(t)}function cc(e){let t=e.messages;if(!t||t.length===0)return;for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.role===`user`){let e=lc(n.content);if(e)return e}}let n=t[t.length-1];return lc(n?.content)}function lc(e){if(typeof e==`string`)return e.slice(0,140);if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return e.text.slice(0,140);if(e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts))return lc(e.parts);if(Array.isArray(e)){let t=e.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`?e.text:``).join(``);return t?t.slice(0,140):void 0}}function uc(e){let t=e.title?.trim(),n=cc(e)??lc(e.preview);return{id:e.id,title:sc(t)?void 0:t,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:n}}async function dc(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(!n.ok)return;let r=await n.json();return uc(`conversation`in r&&r.conversation?r.conversation:r)}function fc(e){let{userId:t,apiBase:n,limit:r=50,refreshKey:i}=e,[a,o]=(0,Z.useState)([]),[s,c]=(0,Z.useState)(!!t),[l,u]=(0,Z.useState)(void 0),[d,f]=(0,Z.useState)(0),p=(0,Z.useCallback)(async()=>{f(e=>e+1)},[]),m=(0,Z.useCallback)(async e=>{try{await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`})}finally{o(t=>t.filter(t=>t.id!==e))}},[n]),h=(0,Z.useCallback)(async(e,t)=>{let r=t.trim();o(t=>t.map(t=>t.id===e?{...t,title:r||void 0}:t));let i=await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:r})});if(!i.ok)throw f(e=>e+1),Error(`PATCH conversation failed: ${i.status}`)},[n]);return(0,Z.useEffect)(()=>{if(!t){o([]),c(!1),u(void 0);return}let e=!1;return c(!0),u(void 0),(async()=>{try{let t=await fetch(`${n}/conversations?limit=${encodeURIComponent(String(r))}`,{credentials:`include`});if(!t.ok)throw Error(`GET conversations failed: ${t.status}`);let i=await t.json(),a=Array.isArray(i)?i:i.conversations??i.items??[];if(e)return;let s=a.map(uc).sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));o(s);let c=s.filter(e=>!e.title&&!e.preview).slice(0,20);if(c.length>0){let t=await Promise.all(c.map(e=>dc(n,e.id).catch(()=>void 0)));if(e)return;let r=new Map(t.filter(e=>!!(e?.preview||e?.title)).map(e=>[e.id,e]));r.size>0&&o(e=>e.map(e=>{let t=r.get(e.id);return t?{...e,title:e.title??t.title,preview:e.preview??t.preview}:e}))}}catch(t){if(e)return;u(t instanceof Error?t:Error(String(t))),o([])}finally{e||c(!1)}})(),()=>{e=!0}},[t,n,r,d,i]),{conversations:a,isLoading:s,error:l,refetch:p,remove:m,rename:h}}function pc({appName:e,error:t,onRetry:n}){let{t:r}=H(),i=!!t;return(0,Q.jsx)(`div`,{className:`flex h-screen items-center justify-center`,"data-testid":`preview-draft-empty-state`,children:(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(`div`,{className:`mb-2 flex justify-center text-muted-foreground`,"aria-hidden":`true`,children:i?(0,Q.jsx)(St,{className:`h-8 w-8`}):(0,Q.jsx)(mt,{className:`h-8 w-8`})}),(0,Q.jsx)(Pe,{children:i?r(`preview.empty.loadFailedTitle`,{defaultValue:`Draft preview failed to load`}):e?r(`preview.empty.notReadyTitle`,{app:e,defaultValue:`“{{app}}” isn’t in the draft yet`}):r(`preview.empty.nothingTitle`,{defaultValue:`Nothing to preview yet`})}),(0,Q.jsx)(Gr,{children:i?r(`preview.empty.loadFailedDescription`,{defaultValue:`The draft overlay could not be read. Retry, or check your connection.`}):r(`preview.empty.notReadyDescription`,{defaultValue:`The build may still be running, or it may have failed before this app was staged. Check the conversation for the build status — this pane refreshes as drafts land.`})}),(0,Q.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,Q.jsxs)(J,{variant:`outline`,onClick:n,"data-testid":`preview-draft-retry`,children:[(0,Q.jsx)(De,{className:`mr-1.5 h-3.5 w-3.5`}),r(`preview.empty.retry`,{defaultValue:`Retry`})]})})]})})}var mc=(0,Z.lazy)(()=>u(()=>import(`./RecordDetailView-Bh6I2k3c.js`).then(e=>e.n).then(e=>({default:e.RecordDetailView})),__vite__mapDeps([0]),import.meta.url)),hc=(0,Z.lazy)(()=>u(()=>import(`./DashboardView-CsknMwAh.js`).then(e=>e.t).then(e=>({default:e.DashboardView})),__vite__mapDeps([0,1]),import.meta.url)),gc=(0,Z.lazy)(()=>u(()=>import(`./PageView-CxOhEFic.js`).then(e=>e.t).then(e=>({default:e.PageView})),__vite__mapDeps([0]),import.meta.url)),_c=(0,Z.lazy)(()=>u(()=>import(`./ReportView-q3jNGyaI.js`).then(e=>e.t).then(e=>({default:e.ReportView})),__vite__mapDeps([0]),import.meta.url)),vc=(0,Z.lazy)(()=>u(()=>import(`./SearchResultsPage-BRnB7VD4.js`).then(e=>e.t).then(e=>({default:e.SearchResultsPage})),__vite__mapDeps([0]),import.meta.url)),yc=(0,Z.lazy)(()=>u(()=>import(`./RecordFormPage-1zrrumdr.js`).then(e=>e.t).then(e=>({default:e.RecordFormPage})),__vite__mapDeps([0]),import.meta.url)),bc=(0,Z.lazy)(()=>u(()=>import(`./ComponentNavView-B6LSKpd-.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),xc=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-B5WWi7HS.js`).then(e=>e.t).then(e=>({default:e.MetadataDirectoryPage})),__vite__mapDeps([0]),import.meta.url)),Sc=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-B5WWi7HS.js`).then(e=>e.t).then(e=>({default:e.StudioHomePage})),__vite__mapDeps([0]),import.meta.url)),Cc=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-B5WWi7HS.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceListPage})),__vite__mapDeps([0]),import.meta.url)),wc=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-B5WWi7HS.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceEditPage})),__vite__mapDeps([0]),import.meta.url)),Tc=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-B5WWi7HS.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceHistoryPage})),__vite__mapDeps([0]),import.meta.url)),Ec=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-B5WWi7HS.js`).then(e=>e.t).then(e=>({default:e.MetadataDiagnosticsPage})),__vite__mapDeps([0]),import.meta.url)),Dc=(0,Z.lazy)(()=>u(()=>Promise.resolve().then(()=>zp).then(e=>({default:e.CreateAppPage})),void 0,import.meta.url)),Oc=(0,Z.lazy)(()=>u(()=>Promise.resolve().then(()=>zp).then(e=>({default:e.EditAppPage})),void 0,import.meta.url)),kc=(0,Z.lazy)(()=>u(()=>Promise.resolve().then(()=>zp).then(e=>({default:e.DashboardDesignPage})),void 0,import.meta.url)),Ac=(0,Z.lazy)(()=>u(()=>import(`./MarketplacePage-CoigR7d_.js`).then(e=>e.t).then(e=>({default:e.MarketplacePage})),__vite__mapDeps([0]),import.meta.url)),jc=(0,Z.lazy)(()=>u(()=>import(`./MarketplacePackagePage-SKgqOj7g.js`).then(e=>e.t).then(e=>({default:e.MarketplacePackagePage})),__vite__mapDeps([0]),import.meta.url)),Mc=(0,Z.lazy)(()=>u(()=>import(`./MarketplaceInstalledPage-CaN54GxZ.js`).then(e=>e.t).then(e=>({default:e.MarketplaceInstalledPage})),__vite__mapDeps([0]),import.meta.url));function Nc({appName:e}){let{reviewSeq:t,reviewTarget:n}=ri(),r=_(),i=(0,Z.useRef)(t);return(0,Z.useEffect)(()=>{if(t===i.current||!n||!e)return;i.current=t;let{type:a,name:o}=n;r(`/apps/${e}/metadata/${encodeURIComponent(a)}/${encodeURIComponent(o)}?review=1`)},[t,n,e,r]),null}function Pc({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,a]=(0,Z.useState)(`disconnected`),{user:s,getAuthConfig:c}=x(),u=se(),[d,f]=(0,Z.useState)({});(0,Z.useEffect)(()=>{let e=!1;return c().then(t=>{e||f(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[c]);let p=_(),m=l(),{appName:g}=o(),{apps:v,objects:y,loading:b,ensureType:S,error:C,refresh:w}=F(),T=ci(),{t:E}=H(),{objectLabel:D}=er(),[O,k]=(0,Z.useState)(!S);(0,Z.useEffect)(()=>{if(!S){k(!0);return}let e=!1;return Promise.all([S(`object`),S(`dashboard`),S(`report`),S(`page`)]).finally(()=>{e||k(!0)}),()=>{e=!0}},[S]);let j=v.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),M=m.pathname.endsWith(`/create-app`),P=m.pathname.includes(`/system`),ee=m.pathname.includes(`/metadata`),te=m.pathname===`/apps/setup`||m.pathname.startsWith(`/apps/setup/`),I=M||P||ee||te,ne=Bi(v,g),L=ne||(!g||I?j.find(e=>e.isDefault===!0)||j[0]:void 0),R=!!g&&!ne&&!I,[z,B]=(0,Z.useState)(`idle`);(0,Z.useEffect)(()=>{if(!R){z!==`idle`&&B(`idle`);return}z===`idle`&&!b&&!T&&(B(`checking`),Promise.resolve(w()).finally(()=>B(`done`)))},[R,b,T,z,w]),(0,Z.useEffect)(()=>{if(!L?.name)return;let e=g??L.name,t=`/apps/${e}/metadata/package`;(m.pathname===t||m.pathname.startsWith(`${t}/`))&&p(`/apps/${e}/component/developer/packages`,{replace:!0})},[L?.name,g,m.pathname,p]);let[ie,ae]=(0,Z.useState)(!1),[V,oe]=(0,Z.useState)(null),[ce,le]=(0,Z.useState)(0),{execute:ue,runner:de}=N();A({dataSource:u??void 0,onUndo:e=>{X.info(`Undo: ${e.description}`,{duration:4e3}),le(e=>e+1)},onRedo:e=>{X.info(`Redo: ${e.description}`,{duration:3e3}),le(e=>e+1)}}),(0,Z.useEffect)(()=>{de.registerHandler(`crud_success`,async e=>(ae(!1),le(e=>e+1),X.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),de.registerHandler(`dialog_cancel`,async()=>(ae(!1),{success:!0})),de.registerHandler(`navigate_create`,async e=>{let t=Xi({action:e,context:de.getContext?.()??{},defaultBaseUrl:`/apps/${g??``}`});return t.success?(p(t.url),{success:!0}):t}),de.registerHandler(`navigate_edit`,async e=>{let t=Qi({action:e,context:de.getContext?.()??{},defaultBaseUrl:`/apps/${g??``}`});return t.success?(p(t.url),{success:!0}):t})},[de,p,g]),(0,Z.useEffect)(()=>{if(!u)return;let e=u.onConnectionStateChange(e=>{a(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return a(u.getConnectionState()),e},[u]);let U=m.pathname.split(`/`).filter(Boolean)[2];(U===`view`||U===`record`||U===`page`||U===`dashboard`||U===`design`)&&(U=``);let fe=y.find(e=>e.name===U),W=(0,Z.useCallback)(()=>{let e=fe?D(fe):E(`common.record`,{defaultValue:`Record`});ue({type:`crud_success`,params:{message:V?E(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):E(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[ue,V,fe,D,E]),pe=(0,Z.useCallback)(()=>{ue({type:`dialog_cancel`})},[ue]);Us({pathname:m.pathname,appName:L?.name,objects:y});let me=e=>{let t=ea({objectDef:fe,baseUrl:g?`/apps/${g}`:L?.name?`/apps/${L.name}`:``,record:e});if(t.kind===`page`){p(t.url);return}oe(e),ae(!0)},he=e=>{p(`/apps/${e}`)},ge=(0,Z.useMemo)(()=>new re({user:s?{name:s.name,email:s.email,role:s.role??`user`}:{},app:L||{},data:V||{}}),[s,L,V]);return!u||b||!O?(0,Q.jsx)(Xo,{}):T&&(R||!L)?(0,Q.jsx)(pc,{appName:g,error:C,onRetry:()=>void w()}):R?z===`done`?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(Pe,{children:E(`empty.appNotAvailable`,{defaultValue:`App not available`})}),(0,Q.jsx)(Gr,{children:E(`empty.appNotAvailableDescription`,{defaultValue:`This app is not available yet — it may still be publishing. Try again in a moment.`})}),(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsx)(J,{onClick:()=>B(`idle`),"data-testid":`app-not-available-retry`,children:E(`common.retry`,{defaultValue:`Retry`})})})]})}):(0,Q.jsx)(Xo,{}):!L&&!M&&!P&&!ee?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(Pe,{children:E(`empty.noAppsConfigured`)}),(0,Q.jsx)(Gr,{children:E(`empty.noAppsConfiguredDescription`)}),(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,Q.jsx)(J,{onClick:()=>p(`/create-app`),"data-testid":`create-first-app-btn`,children:E(`empty.createFirstApp`)}),(0,Q.jsx)(J,{variant:`outline`,onClick:()=>p(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:E(`empty.systemSettings`)})]})]})}):!L&&(M||P||ee)?(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsxs)(i,{children:[(0,Q.jsx)(h,{path:`create-app`,element:(0,Q.jsx)(Dc,{})}),(0,Q.jsx)(h,{path:`system/marketplace`,element:(0,Q.jsx)(Ac,{})}),(0,Q.jsx)(h,{path:`system/marketplace/installed`,element:(0,Q.jsx)(Mc,{})}),(0,Q.jsx)(h,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(jc,{})}),(0,Q.jsx)(h,{path:`metadata`,element:(0,Q.jsx)(xc,{})}),(0,Q.jsx)(h,{path:`metadata/_diagnostics`,element:(0,Q.jsx)(Ec,{})}),(0,Q.jsx)(h,{path:`metadata/:type`,element:(0,Q.jsx)(Cc,{})}),(0,Q.jsx)(h,{path:`metadata/:type/new`,element:(0,Q.jsx)(wc,{createMode:!0})}),(0,Q.jsx)(h,{path:`metadata/:type/:name`,element:(0,Q.jsx)(wc,{})}),(0,Q.jsx)(h,{path:`metadata/:type/:name/history`,element:(0,Q.jsx)(Tc,{})}),t]})}):(0,Q.jsxs)(di,{user:s?{name:s.name,email:s.email,role:s.role??`user`}:{name:`Anonymous`,email:``,role:`guest`},app:L,data:{},features:d,children:[(0,Q.jsx)(zs,{}),(0,Q.jsxs)(Uo,{activeAppName:L.name,activeApp:L,onAppChange:he,objects:y,connectionState:n,userId:s?.id,children:[(0,Q.jsx)(Go,{apps:v,activeApp:L,objects:y,onAppChange:he,dataSource:u}),(0,Q.jsx)(qo,{}),(0,Q.jsx)(Jo,{}),(0,Q.jsx)(Nc,{appName:g}),(0,Q.jsx)(os,{children:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)($o,{className:`h-full`,children:(0,Q.jsxs)(i,{children:[(0,Q.jsx)(h,{path:`/`,element:(()=>{let e=Rc(L,{currentUserId:s?.id??null});return e?(0,Q.jsx)(r,{to:e,replace:!0}):(0,Q.jsx)(Sc,{})})()}),(0,Q.jsx)(h,{path:`metadata/package/*`,element:(0,Q.jsx)(r,{to:`/apps/${g??L.name}/component/developer/packages`,replace:!0})}),(0,Q.jsxs)(h,{path:`metadata`,children:[(0,Q.jsx)(h,{index:!0,element:(0,Q.jsx)(xc,{})}),(0,Q.jsx)(h,{path:`_diagnostics`,element:(0,Q.jsx)(Ec,{})}),(0,Q.jsx)(h,{path:`:type`,element:(0,Q.jsx)(Cc,{})}),(0,Q.jsx)(h,{path:`:type/new`,element:(0,Q.jsx)(wc,{createMode:!0})}),(0,Q.jsx)(h,{path:`:type/:name`,element:(0,Q.jsx)(wc,{})}),(0,Q.jsx)(h,{path:`:type/:name/history`,element:(0,Q.jsx)(Tc,{})})]}),(0,Q.jsx)(h,{path:`:objectName`,element:(0,Q.jsx)(Cs,{dataSource:u,objects:y,onEdit:me,externalRefreshKey:ce})}),(0,Q.jsx)(h,{path:`:objectName/new`,element:(0,Q.jsx)(yc,{mode:`create`})}),(0,Q.jsx)(h,{path:`:objectName/view/:viewId`,element:(0,Q.jsx)(Cs,{dataSource:u,objects:y,onEdit:me,externalRefreshKey:ce})}),(0,Q.jsx)(h,{path:`:objectName/record/:recordId`,element:(0,Q.jsx)(mc,{dataSource:u,objects:y,onEdit:me},ce)}),(0,Q.jsx)(h,{path:`:objectName/record/:recordId/edit`,element:(0,Q.jsx)(yc,{mode:`edit`})}),(0,Q.jsx)(h,{path:`dashboard/:dashboardName`,element:(0,Q.jsx)(hc,{dataSource:u})}),(0,Q.jsx)(h,{path:`report/:reportName`,element:(0,Q.jsx)(_c,{dataSource:u})}),(0,Q.jsx)(h,{path:`page/:pageName`,element:(0,Q.jsx)(gc,{})}),(0,Q.jsx)(h,{path:`component/:ns/:name/*`,element:(0,Q.jsx)(bc,{})}),(0,Q.jsx)(h,{path:`component/metadata/directory`,element:(0,Q.jsx)(Vc,{mode:`directory`})}),(0,Q.jsx)(h,{path:`component/metadata/resource/*`,element:(0,Q.jsx)(Vc,{mode:`resource`})}),(0,Q.jsx)(h,{path:`design/dashboard/:dashboardName`,element:(0,Q.jsx)(kc,{})}),(0,Q.jsx)(h,{path:`search`,element:(0,Q.jsx)(vc,{})}),(0,Q.jsx)(h,{path:`create-app`,element:(0,Q.jsx)(Dc,{})}),(0,Q.jsx)(h,{path:`edit-app/:editAppName`,element:(0,Q.jsx)(Oc,{})}),(0,Q.jsx)(h,{path:`system/marketplace`,element:(0,Q.jsx)(Ac,{})}),(0,Q.jsx)(h,{path:`system/marketplace/installed`,element:(0,Q.jsx)(Mc,{})}),(0,Q.jsx)(h,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(jc,{})}),e,(0,Q.jsx)(h,{path:`:objectName/:maybeRecordId`,element:(0,Q.jsx)(Hc,{})}),(0,Q.jsx)(h,{path:`*`,element:(0,Q.jsx)(Uc,{})})]})})})}),fe&&(0,Q.jsx)(ti,{schema:{type:`object-form`,formType:`modal`,objectName:fe.name,mode:V?`edit`:`create`,recordId:V?.id,subforms:fe.form?.subforms??fe.formViews?.default?.subforms,...(()=>{let e=fe.form??fe.formViews?.default;return e?.type===`tabbed`&&Array.isArray(e?.sections)?{contentLayout:`tabbed`,sections:e.sections}:{}})(),title:E(V?`form.editTitle`:`form.createTitle`,{object:D(fe)}),description:E(V?`form.editDescription`:`form.createDescription`,{object:D(fe)}),open:ie,onOpenChange:ae,layout:`vertical`,fields:fe.fields?Array.isArray(fe.fields)?fe.fields.filter(e=>typeof e==`string`?!0:li(e.visible,ge)).map(e=>typeof e==`string`?e:e.name):Object.entries(fe.fields).filter(([e,t])=>li(t.visible,ge)).map(([e])=>e):[],onSuccess:W,onCancel:pe,showSubmit:!0,showCancel:!0,submitText:V?E(`form.update`,{defaultValue:E(`common.save`,{defaultValue:`Save`})}):E(`form.create`,{defaultValue:E(`common.create`,{defaultValue:`Create`})}),cancelText:E(`common.cancel`)},dataSource:u},V?.id||`new`)]})]})}function Fc(e,t){if(!e||e.length===0)return``;for(let n of e){if(n.type===`object`||n.type===`page`||n.type===`dashboard`||n.type===`report`){let e=Ic(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=Fc(n.children,t);if(e!==``)return e}}return``}function Ic(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=Di(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function Lc(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=Lc(n.children,t);if(e)return e}}}function Rc(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=Ic(Lc(r,n),t);if(e)return e}return Fc(r,t)}var zc=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function Bc(e){return!e||zc.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function Vc({mode:e}){let t=l(),n=t.pathname.replace(/\/component\/metadata\/.*$/,``);if(e===`directory`)return(0,Q.jsx)(r,{to:`${n}/metadata${t.search}${t.hash}`,replace:!0});let i=new URLSearchParams(t.search).get(`type`)??``,a=t.pathname.match(/\/component\/metadata\/resource(\/.*)?$/)?.[1]??``;return(0,Q.jsx)(r,{to:i?`${n}/metadata/${encodeURIComponent(i)}${a}${t.hash}`:`${n}/metadata${t.hash}`,replace:!0})}function Hc(){let{objectName:e,maybeRecordId:t}=o(),n=l();return e&&Bc(t)?(0,Q.jsx)(r,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,Q.jsx)(Uc,{})}function Uc(){let e=_(),{t}=H();return(0,Q.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(Pe,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Q.jsx)(Gr,{children:t(`console.notFound.description`,{defaultValue:`The URL you followed does not match any view in this app.`})}),(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsx)(J,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function Wc({children:e,userId:t}){let{setContext:n}=Si(),{isAiEnabled:r}=P(),{t:i}=H(),a=r||!1;return(0,Z.useEffect)(()=>{n(`home`)},[n]),(0,Q.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`home-layout`,children:[(0,Q.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,Q.jsx)(Ro,{variant:`home`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),a&&(0,Q.jsx)(Za,{appLabel:i(`workspace.default`,{defaultValue:`Workspace`}),objects:[],userId:t})]})}var Gc=[{from:`from-blue-500/15`,to:`to-indigo-500/10`,text:`text-blue-600 dark:text-blue-400`,ring:`group-hover:border-blue-500/40`,solid:`bg-blue-500`},{from:`from-emerald-500/15`,to:`to-teal-500/10`,text:`text-emerald-600 dark:text-emerald-400`,ring:`group-hover:border-emerald-500/40`,solid:`bg-emerald-500`},{from:`from-fuchsia-500/15`,to:`to-pink-500/10`,text:`text-fuchsia-600 dark:text-fuchsia-400`,ring:`group-hover:border-fuchsia-500/40`,solid:`bg-fuchsia-500`},{from:`from-amber-500/15`,to:`to-orange-500/10`,text:`text-amber-600 dark:text-amber-400`,ring:`group-hover:border-amber-500/40`,solid:`bg-amber-500`},{from:`from-sky-500/15`,to:`to-cyan-500/10`,text:`text-sky-600 dark:text-sky-400`,ring:`group-hover:border-sky-500/40`,solid:`bg-sky-500`},{from:`from-violet-500/15`,to:`to-purple-500/10`,text:`text-violet-600 dark:text-violet-400`,ring:`group-hover:border-violet-500/40`,solid:`bg-violet-500`},{from:`from-rose-500/15`,to:`to-red-500/10`,text:`text-rose-600 dark:text-rose-400`,ring:`group-hover:border-rose-500/40`,solid:`bg-rose-500`}];function Kc(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function qc({app:e,onClick:t,isFavorite:n,index:r=0}){let{t:i}=H(),{appLabel:a,appDescription:o}=er(),{toggleFavorite:s}=gi(),c=Gi(e.icon),l=a({name:e.name,label:$i(e.label,i)}),u=o({name:e.name,description:$i(e.description,i)}),d=Gc[(Kc(e.name)+r)%Gc.length];return(0,Q.jsxs)(mr,{className:yn(`group relative overflow-hidden border border-border/70 bg-card/80 backdrop-blur-sm`,`transition-[transform,box-shadow,border-color] duration-200 hover:-translate-y-0.5 hover:shadow-lg`,`motion-reduce:transition-none motion-reduce:hover:transform-none`,d.ring),"data-testid":`app-card-${e.name}`,children:[(0,Q.jsx)(`button`,{type:`button`,"aria-label":l,className:`absolute inset-0 z-10 rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,onClick:t,"data-testid":`app-card-open-${e.name}`}),(0,Q.jsx)(`div`,{"aria-hidden":!0,className:yn(`absolute inset-x-0 top-0 h-1`,d.solid)}),(0,Q.jsx)(`div`,{"aria-hidden":!0,className:yn(`absolute inset-0 bg-gradient-to-br opacity-0 transition-opacity duration-300 group-hover:opacity-100`,d.from,d.to)}),(0,Q.jsxs)(qe,{className:`relative p-5`,children:[(0,Q.jsx)(J,{variant:`ghost`,size:`sm`,className:`absolute top-2 right-2 z-20 h-8 w-8 p-0 opacity-0 transition-opacity group-hover:opacity-100 focus-visible:opacity-100`,onClick:t=>{t.stopPropagation(),s({id:`app:${e.name}`,label:l,href:`/apps/${Vi(e)??e.name}`,type:`object`})},"aria-label":n?i(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`})+` — ${l}`:i(`common.addToFavorites`,{defaultValue:`Add to favorites`})+` — ${l}`,"aria-pressed":n,"data-testid":`favorite-btn-${e.name}`,children:n?(0,Q.jsx)(rr,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Q.jsx)(gr,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:yn(`inline-flex h-14 w-14 items-center justify-center rounded-xl mb-4 ring-1 ring-inset`,`bg-gradient-to-br ring-border/40`,d.from,d.to),children:(0,Q.jsx)(c,{className:yn(`h-7 w-7`,d.text)})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`h3`,{className:`font-semibold text-base sm:text-lg leading-tight truncate`,children:l}),e.isDefault&&(0,Q.jsx)(ue,{variant:`secondary`,className:`shrink-0 text-[10px] px-1.5 py-0`,children:i(`home.appCard.default`,{defaultValue:`Default`})})]}),(0,Q.jsx)(`p`,{className:yn(`text-sm text-muted-foreground mt-1.5 line-clamp-2 min-h-[2.5rem]`,!u&&`italic`),children:u||i(`home.appCard.noDescription`,{defaultValue:`No description`})})]}),(0,Q.jsx)(`div`,{className:`mt-4 flex items-center justify-between text-xs font-medium`,children:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground transition-colors group-hover:text-foreground`,children:[i(`home.open`,{defaultValue:`Open`}),(0,Q.jsx)(Sr,{className:`h-3.5 w-3.5 transition-transform duration-200 group-hover:translate-x-0.5 group-hover:-translate-y-0.5`})]})})]})]})}var Jc={object:`bg-blue-500/10 text-blue-600 dark:text-blue-400 ring-blue-500/20`,dashboard:`bg-violet-500/10 text-violet-600 dark:text-violet-400 ring-violet-500/20`,page:`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 ring-emerald-500/20`,record:`bg-amber-500/10 text-amber-600 dark:text-amber-400 ring-amber-500/20`},Yc={object:Bt,record:ye,dashboard:Fe,page:un};function Xc({items:e}){let t=_(),{t:n}=H();return e.length===0?null:(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,Q.jsx)(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-lg bg-sky-500/10 ring-1 ring-sky-500/20 text-sky-600 dark:text-sky-400`,children:(0,Q.jsx)(_r,{className:`h-4 w-4`})}),(0,Q.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.recentApps.title`,{defaultValue:`Recently Accessed`})})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>{let r=Yc[e.type]||Bt,i=n(`home.recentApps.itemType.${e.type}`,{defaultValue:ta(e.type)}),a=Jc[e.type]||Jc.object;return(0,Q.jsx)(mr,{className:`group cursor-pointer border border-border/70 bg-card/80 backdrop-blur-sm transition-[transform,box-shadow,border-color] duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-foreground/20 motion-reduce:transition-none motion-reduce:hover:transform-none`,onClick:()=>t(e.href),"data-testid":`recent-item-${e.id}`,role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e.href))},children:(0,Q.jsx)(qe,{className:`p-3.5`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:yn(`inline-flex h-10 w-10 items-center justify-center rounded-lg ring-1 shrink-0`,a),children:(0,Q.jsx)(r,{className:`h-5 w-5`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i})]}),(0,Q.jsx)(Sr,{className:`h-4 w-4 text-muted-foreground opacity-0 -translate-x-1 transition-[opacity,transform] duration-200 group-hover:opacity-100 group-hover:translate-x-0`})]})})},e.id)})})]})}var Zc={object:`bg-blue-500/10 text-blue-600 dark:text-blue-400 ring-blue-500/20`,dashboard:`bg-violet-500/10 text-violet-600 dark:text-violet-400 ring-violet-500/20`,page:`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 ring-emerald-500/20`,record:`bg-amber-500/10 text-amber-600 dark:text-amber-400 ring-amber-500/20`},Qc={object:Bt,record:ye,dashboard:Fe,page:un};function $c({items:e}){let t=_(),{t:n}=H();return e.length===0?null:(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 mb-5`,children:[(0,Q.jsx)(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-lg bg-amber-500/10 ring-1 ring-amber-500/20 text-amber-600 dark:text-amber-400`,children:(0,Q.jsx)(rr,{className:`h-4 w-4 fill-current`})}),(0,Q.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:n(`home.starredApps.title`,{defaultValue:`Starred`})})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-3`,children:e.map(e=>{let r=Qc[e.type]||Bt,i=Zc[e.type]||Zc.object,a=n(`home.recentApps.itemType.${e.type}`,{defaultValue:ta(e.type)});return(0,Q.jsx)(mr,{className:`group cursor-pointer border border-border/70 bg-card/80 backdrop-blur-sm transition-[transform,box-shadow,border-color] duration-200 hover:-translate-y-0.5 hover:shadow-md hover:border-foreground/20 motion-reduce:transition-none motion-reduce:hover:transform-none`,onClick:()=>t(e.href),"data-testid":`starred-item-${e.id}`,role:`link`,tabIndex:0,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),t(e.href))},children:(0,Q.jsx)(qe,{className:`p-3.5`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:yn(`inline-flex h-10 w-10 items-center justify-center rounded-lg ring-1 shrink-0`,i),children:(0,Q.jsx)(r,{className:`h-5 w-5`})}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`h3`,{className:`font-medium text-sm truncate`,children:e.label}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a})]}),(0,Q.jsx)(Sr,{className:`h-4 w-4 text-muted-foreground opacity-0 -translate-x-1 transition-[opacity,transform] duration-200 group-hover:opacity-100 group-hover:translate-x-0`})]})})},e.id)})})]})}function el(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function tl({t:e}){return(0,Q.jsx)(`section`,{"data-testid":`home-getting-started`,className:`rounded-2xl border border-border bg-card p-6 sm:p-8 shadow-sm`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center gap-5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,Q.jsx)(`span`,{className:`inline-flex h-10 w-10 items-center justify-center rounded-lg bg-amber-500/10 ring-1 ring-amber-500/20 text-amber-600 dark:text-amber-400`,children:(0,Q.jsx)(rr,{className:`h-5 w-5`})}),(0,Q.jsx)(`span`,{className:`inline-flex h-10 w-10 items-center justify-center rounded-lg bg-emerald-500/10 ring-1 ring-emerald-500/20 text-emerald-600 dark:text-emerald-400`,children:(0,Q.jsx)(_r,{className:`h-5 w-5`})})]}),(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:e(`home.gettingStarted.title`,{defaultValue:`Make this home yours`})}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-xl`,children:e(`home.gettingStarted.description`,{defaultValue:`Star an app to pin it here for one-click access. Anything you open will show up under Recently Accessed automatically.`})})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground`,children:[(0,Q.jsx)(`span`,{children:e(`home.gettingStarted.cta`,{defaultValue:`Browse all applications`})}),(0,Q.jsx)(cr,{className:`h-3.5 w-3.5`})]})]})})}function nl({icon:e,value:t,label:n,tone:r}){return(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2 rounded-full border border-border bg-card px-3 py-1.5 text-sm shadow-sm`,children:[(0,Q.jsx)(e,{className:`h-4 w-4 ${r}`}),(0,Q.jsx)(`span`,{className:`font-semibold tabular-nums`,children:t}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:n})]})}function rl({t:e}){let t=Ri(),[n,r]=(0,Z.useState)([]),{publishAll:i,publishing:a}=Qa(e),o=n.length;return(0,Z.useEffect)(()=>{let e=!1;return Promise.resolve(t.listDrafts?.({})).then(t=>{e||!Array.isArray(t)||r(t.filter(e=>e&&typeof e.type==`string`&&typeof e.name==`string`).map(e=>({type:e.type,name:e.name})))}).catch(()=>{}),()=>{e=!0}},[t]),o<=0?null:(0,Q.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-4`,children:(0,Q.jsx)(`div`,{className:`max-w-7xl mx-auto`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-indigo-300/60 dark:border-indigo-700/50 bg-indigo-50 dark:bg-indigo-950/30 px-4 py-3`,children:[(0,Q.jsx)(Er,{className:`h-5 w-5 shrink-0 text-indigo-600 dark:text-indigo-400`}),(0,Q.jsx)(`p`,{className:`flex-1 min-w-0 text-sm text-indigo-900 dark:text-indigo-200`,children:e(`home.pendingDrafts.message`,{count:o,defaultValue:`You have {{count}} unpublished change(s) — publish to make them live.`})}),(0,Q.jsx)(J,{size:`sm`,onClick:async()=>{(await i()).ok&&(r([]),setTimeout(()=>{try{window.location.reload()}catch{}},700))},disabled:a,"data-testid":`pending-drafts-publish`,children:a?e(`home.pendingDrafts.publishing`,{defaultValue:`Publishing…`}):e(`home.pendingDrafts.cta`,{defaultValue:`Publish`})})]})})})}function il({t:e}){let t=_(),{hasLocalPassword:n}=x(),[r,i]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(typeof localStorage<`u`&&localStorage.getItem(`os:recovery-pw-dismissed`)===`1`)return;let e=!1;return Promise.resolve(n?.()).then(t=>{!e&&t===!1&&i(!0)}).catch(()=>{}),()=>{e=!0}},[n]),r?(0,Q.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-4`,children:(0,Q.jsx)(`div`,{className:`max-w-7xl mx-auto`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-amber-300/60 dark:border-amber-700/50 bg-amber-50 dark:bg-amber-950/30 px-4 py-3`,children:[(0,Q.jsx)(en,{className:`h-5 w-5 shrink-0 text-amber-600 dark:text-amber-400`}),(0,Q.jsx)(`p`,{className:`flex-1 min-w-0 text-sm text-amber-900 dark:text-amber-200`,children:e(`home.recoveryReminder.message`,{defaultValue:`Set a recovery password so you can still sign in if single sign-on is ever unavailable.`})}),(0,Q.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>t(`/set-password`),"data-testid":`recovery-pw-set`,children:e(`home.recoveryReminder.cta`,{defaultValue:`Set password`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{try{localStorage.setItem(`os:recovery-pw-dismissed`,`1`)}catch{}i(!1)},"aria-label":e(`home.recoveryReminder.dismiss`,{defaultValue:`Dismiss`}),className:`shrink-0 rounded-md p-1 text-amber-700/70 hover:text-amber-900 dark:text-amber-300/70 dark:hover:text-amber-100`,children:(0,Q.jsx)(Et,{className:`h-4 w-4`})})]})})}):null}function al(){let e=_(),{t}=H(),{apps:n,loading:r}=F(),{recentItems:i}=fi(),{favorites:a}=gi(),{user:o}=x(),s=b(),c=n.filter(e=>e.active!==!1&&e.hidden!==!0),l=i.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,6),u=a.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,8),d=(0,Z.useMemo)(()=>t(el(new Date().getHours()),{defaultValue:`Welcome`}),[t]),f=(o?.name?.trim()||o?.email?.split(`@`)[0]||``).trim();return r?(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,Q.jsx)(`div`,{className:`text-muted-foreground`,children:t(`home.loading`,{defaultValue:`Loading workspace…`})})}):c.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col flex-1`,children:[(0,Q.jsx)(rl,{t}),(0,Q.jsx)(il,{t}),(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:s?(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(Pe,{children:t(`home.welcome`,{defaultValue:`Welcome to ObjectUI`})}),(0,Q.jsx)(Gr,{children:t(`home.welcomeAdminDescription`,{defaultValue:`Describe your business in one sentence — AI generates the objects, screens, APIs and agent tools. Or set things up yourself from the Administration menu on the left.`})}),(0,Q.jsx)(`div`,{className:`mt-6 flex flex-col sm:flex-row items-center gap-3`,children:(0,Q.jsxs)(J,{onClick:()=>e(`/ai?agent=metadata_assistant`),"data-testid":`build-with-ai-btn`,children:[(0,Q.jsx)(Yn,{className:`mr-2 h-4 w-4`}),t(`home.buildWithAI`,{defaultValue:`Build with AI`})]})})]}):(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(Pe,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,Q.jsx)(Gr,{children:t(`home.noAppsDescription`,{defaultValue:`There are no applications available to you yet. Please contact your workspace administrator.`})})]})})]}):(0,Q.jsxs)(`div`,{className:`relative min-h-full bg-background`,children:[(0,Q.jsx)(rl,{t}),(0,Q.jsx)(il,{t}),(0,Q.jsx)(`section`,{className:`px-4 sm:px-6 lg:px-8 pt-10 pb-6`,children:(0,Q.jsxs)(`div`,{className:`max-w-7xl mx-auto`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-muted-foreground mb-3`,children:[(0,Q.jsx)(Yn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`uppercase tracking-wider`,children:t(`home.title`,{defaultValue:`Home`})})]}),(0,Q.jsxs)(`h1`,{className:`text-3xl sm:text-4xl lg:text-5xl font-bold tracking-tight text-pretty`,children:[(0,Q.jsxs)(`span`,{className:`text-foreground`,children:[d,f?`, `:``]}),f&&(0,Q.jsx)(`span`,{className:`bg-gradient-to-r from-indigo-600 via-violet-600 to-fuchsia-600 bg-clip-text text-transparent dark:from-indigo-400 dark:via-violet-400 dark:to-fuchsia-400`,children:f}),(0,Q.jsx)(`span`,{className:`text-foreground/40`,children:`.`})]}),(0,Q.jsx)(`p`,{className:`text-base sm:text-lg text-muted-foreground mt-2 max-w-2xl`,children:t(`home.heroTagline`,{defaultValue:`Pick up where you left off, or explore something new.`})}),(0,Q.jsx)(`div`,{className:`mt-5`,children:(0,Q.jsxs)(J,{onClick:()=>e(`/ai?agent=metadata_assistant`),"data-testid":`home-build-with-ai`,children:[(0,Q.jsx)(Yn,{className:`mr-2 h-4 w-4`}),t(`home.buildWithAI`,{defaultValue:`Build with AI`})]})}),(0,Q.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,Q.jsx)(nl,{icon:Kr,tone:`text-indigo-600 dark:text-indigo-400`,value:c.length,label:t(`home.stats.apps`,{defaultValue:`Applications`})}),i.length>0&&(0,Q.jsx)(nl,{icon:_r,tone:`text-sky-600 dark:text-sky-400`,value:i.length,label:t(`home.recentApps.title`,{defaultValue:`Recently Accessed`})}),a.length>0&&(0,Q.jsx)(nl,{icon:rr,tone:`text-amber-500 dark:text-amber-400`,value:a.length,label:t(`home.starredApps.title`,{defaultValue:`Starred`})})]})]})}),(0,Q.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pb-16`,children:(0,Q.jsxs)(`div`,{className:`max-w-7xl mx-auto space-y-10`,children:[u.length===0&&l.length===0&&(0,Q.jsx)(tl,{t}),u.length>0&&(0,Q.jsx)($c,{items:u}),l.length>0&&(0,Q.jsx)(Xc,{items:l}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-end justify-between mb-5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,Q.jsx)(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-lg border border-border bg-muted text-muted-foreground`,children:(0,Q.jsx)(Kr,{className:`h-4 w-4`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-2xl font-semibold tracking-tight`,children:t(`home.allApps`,{defaultValue:`All Applications`})}),(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground mt-0.5`,children:[c.length,` · `,t(`home.stats.apps`,{defaultValue:`Applications`})]})]})]}),s&&(0,Q.jsxs)(J,{variant:`outline`,onClick:()=>e(`/apps/setup/system/marketplace`),"data-testid":`browse-marketplace-btn`,children:[(0,Q.jsx)(En,{className:`mr-2 h-4 w-4`}),t(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]})]}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4`,children:c.map((t,n)=>(0,Q.jsx)(qc,{app:t,index:n,onClick:()=>e(`/apps/${Vi(t)??t.name}`),isFavorite:a.some(e=>e.id===`app:${t.name}`)},t.name))})]})]})})]})}function ol({children:e}){let{setContext:t}=Si();return(0,Z.useEffect)(()=>{t(`home`)},[t]),(0,Q.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organizations-layout`,children:[(0,Q.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,Q.jsx)(Ro,{variant:`orgs`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}function sl(e){return e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48)}function cl({open:e,onOpenChange:t,onCreated:n}){let{t:r}=H(),{createOrganization:i,getAuthConfig:a}=x(),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(``),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||_(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,Z.useEffect)(()=>{u||l(sl(o))},[o,u]),(0,Z.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,Q.jsx)($e,{open:e,onOpenChange:t,children:(0,Q.jsx)(xt,{className:`sm:max-w-[425px]`,"data-testid":`create-workspace-dialog`,children:(0,Q.jsxs)(`form`,{onSubmit:(0,Z.useCallback)(async e=>{if(e.preventDefault(),!(!o.trim()||!c.trim())){if(g){h(r(`workspace.multiOrgDisabled`,{defaultValue:`Creating new organizations is disabled on this instance.`}));return}p(!0),h(null);try{let e=await i({name:o.trim(),slug:c.trim()});n?.(e)}catch(e){h(e instanceof Error?e.message:`Failed to create workspace`)}finally{p(!1)}}},[o,c,i,n]),children:[(0,Q.jsxs)(Lt,{children:[(0,Q.jsx)(Ie,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Q.jsx)(qr,{children:r(`workspace.createDescription`,{defaultValue:`A workspace is a shared space for your team to collaborate.`})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,Q.jsx)(Y,{id:`workspace-name`,placeholder:r(`workspace.namePlaceholder`,{defaultValue:`e.g., Acme Inc`}),value:o,onChange:e=>s(e.target.value),autoFocus:!0,"data-testid":`workspace-name-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,Q.jsx)(Y,{id:`workspace-slug`,placeholder:`acme-inc`,value:c,onChange:e=>{l(e.target.value),d(!0)},"data-testid":`workspace-slug-input`}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`workspace.slugHint`,{defaultValue:`Used in URLs. Only lowercase letters, numbers, and hyphens.`})})]}),m&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`workspace-create-error`,children:m})]}),(0,Q.jsxs)(ge,{children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(J,{type:`submit`,disabled:f||!o.trim()||!c.trim(),"data-testid":`workspace-create-submit`,children:[f&&(0,Q.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function ll(e){if(e!==void 0)return new URL(`home`,e).toString();let t=document.querySelector(`base`)?.getAttribute(`href`),n=t?new URL(t,window.location.origin):new URL(`/`,window.location.origin);return new URL(`home`,n).toString()}function ul(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function dl(){let{t:e}=H(),t=_(),{organizations:n,activeOrganization:r,isOrganizationsLoading:i,switchOrganization:a,getAuthConfig:o}=x(),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(null),[p,m]=(0,Z.useState)(!0);(0,Z.useEffect)(()=>{let e=!1;return o().then(t=>{e||t?.features?.multiOrgEnabled===!1&&m(!1)}).catch(()=>{}),()=>{e=!0}},[o]);let h=n??[],g=(0,Z.useMemo)(()=>{let e=s.trim().toLowerCase();return e?h.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):h},[h,s]),v=async e=>{f(e.id);try{e.id!==r?.id&&await a(e.id),window.location.href=ll()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),f(null)}},y=e=>{u(!1),v(e)},b=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{b.current||i||h.length===1&&(b.current=!0,v(h[0]))},[i,h.length]);let S=!i&&h.length===1;return i||S?(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,Q.jsx)(q,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-8 sm:py-12`,children:[(0,Q.jsxs)(`div`,{className:`mb-8`,children:[(0,Q.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:e(`organizations.heading`,{defaultValue:`Your Organizations`})}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organizations.subtitle`,{defaultValue:`Select an organization to continue, or create a new one.`})})]}),(0,Q.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`relative w-full sm:max-w-sm`,children:[(0,Q.jsx)(Tt,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(Y,{value:s,onChange:e=>c(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for an organization`}),className:`pl-9`,"data-testid":`organizations-search`})]}),p&&(0,Q.jsxs)(J,{onClick:()=>u(!0),"data-testid":`organizations-new`,children:[(0,Q.jsx)(Mt,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),h.length===0?(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(Pe,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,Q.jsx)(Gr,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),p&&(0,Q.jsxs)(J,{className:`mt-6`,onClick:()=>u(!0),children:[(0,Q.jsx)(Mt,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}):g.length===0?(0,Q.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organizations.noMatches`,{defaultValue:`No organizations match your search.`})}):(0,Q.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:g.map(n=>{let i=n.id===r?.id,a=d===n.id;return(0,Q.jsxs)(`button`,{onClick:()=>v(n),disabled:a,className:`group flex items-center gap-3 rounded-lg border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60`,"data-testid":`organization-card-${n.slug}`,children:[(0,Q.jsxs)(On,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Q.jsx)(ir,{src:n.logo,alt:n.name}),(0,Q.jsx)(Tr,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:ul(n.name)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate font-medium`,children:n.name}),(0,Q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:i?e(`organizations.current`,{defaultValue:`Current organization`}):n.slug})]}),(0,Q.jsx)(`span`,{className:`text-xs text-primary underline-offset-4 hover:underline shrink-0`,onClick:e=>{e.stopPropagation(),t(`/organizations/${n.slug}/members`)},children:e(`organizations.manage`,{defaultValue:`Manage`})}),a&&(0,Q.jsx)(q,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,Q.jsx)(cl,{open:l,onOpenChange:u,onCreated:y})]})}function fl(){let{t:e}=H(),t=_(),{slug:n}=o(),{organizations:r,activeOrganization:i,isOrganizationsLoading:a,switchOrganization:s}=x(),{setContext:l}=Si();(0,Z.useEffect)(()=>{l(`home`)},[l]);let u=(0,Z.useMemo)(()=>(r??[]).find(e=>e.slug===n)??null,[r,n]);if((0,Z.useEffect)(()=>{u&&i?.id!==u.id&&s(u.id).catch(e=>{console.error(`[OrganizationLayout] switch failed`,e)})},[u,i,s]),a)return(0,Q.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center`,children:(0,Q.jsx)(q,{className:`h-5 w-5 animate-spin text-muted-foreground`})});if(!u)return(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-12 text-center`,children:[(0,Q.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.notFound`,{defaultValue:`Organization not found`})}),(0,Q.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e(`organization.notFoundDescription`,{defaultValue:`This organization does not exist or you do not have access.`})}),(0,Q.jsx)(J,{className:`mt-6`,onClick:()=>t(`/organizations`),children:e(`organization.backToList`,{defaultValue:`Back to organizations`})})]});let d=[{to:`members`,label:e(`organization.tabs.members`,{defaultValue:`Members`})},{to:`invitations`,label:e(`organization.tabs.invitations`,{defaultValue:`Invitations`})},{to:`settings`,label:e(`organization.tabs.settings`,{defaultValue:`Settings`})}];return(0,Q.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organization-layout`,children:[(0,Q.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,Q.jsx)(Ro,{variant:`orgs`})}),(0,Q.jsx)(`div`,{className:`border-b`,children:(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 pt-6`,children:[(0,Q.jsxs)(`button`,{onClick:()=>t(`/organizations`),className:`mb-3 inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground`,children:[(0,Q.jsx)(an,{className:`h-3.5 w-3.5`}),e(`organization.backToList`,{defaultValue:`Back to organizations`})]}),(0,Q.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`h1`,{className:`truncate text-2xl font-bold tracking-tight`,children:u.name}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:u.slug})]})}),(0,Q.jsx)(`nav`,{className:`mt-4 flex gap-1 -mb-px`,children:d.map(e=>(0,Q.jsx)(c,{to:e.to,end:!0,className:({isActive:e})=>`border-b-2 px-3 py-2 text-sm font-medium transition-colors ${e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e.label},e.to))})]})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:(0,Q.jsx)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-6`,children:(0,Q.jsx)(f,{context:{org:u}})})})]})}function pl(){return a()}function ml(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function hl({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=H(),{inviteMember:a}=x(),[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(`member`),[u,d]=(0,Z.useState)(!1),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{t&&(s(``),l(`member`),p(null),h(null),_(!1))},[t]);let v=(0,Z.useCallback)(async t=>{if(t.preventDefault(),o.trim()){d(!0),p(null);try{let t=await a({organizationId:e,email:o.trim(),role:c});h(t),r?.(t)}catch(e){p(e instanceof Error?e.message:`Failed to invite member`)}finally{d(!1)}}},[o,c,e,a,r]),y=(0,Z.useCallback)(async()=>{if(!m)return;let e=ml(m.id);try{await navigator.clipboard.writeText(e),_(!0),X.success(i(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>_(!1),2e3)}catch{X.error(i(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},[m,i]);return(0,Q.jsx)($e,{open:t,onOpenChange:n,children:(0,Q.jsx)(xt,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:m?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(Lt,{children:[(0,Q.jsx)(Ie,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Q.jsx)(qr,{children:i(`organization.invitations.sentDescription`,{defaultValue:`Share the link below with the invitee. They will need to sign in to accept.`})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-3 py-4`,children:[(0,Q.jsx)(ur,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Y,{readOnly:!0,value:ml(m.id),className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,Q.jsx)(J,{type:`button`,variant:`outline`,size:`icon`,onClick:y,"aria-label":`Copy`,children:g?(0,Q.jsx)(Ee,{className:`h-4 w-4`}):(0,Q.jsx)(qt,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`organization.invitations.invitedAs`,{defaultValue:`{{email}} invited as {{role}}`,email:m.email,role:m.role})})]}),(0,Q.jsx)(ge,{children:(0,Q.jsx)(J,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Q.jsxs)(`form`,{onSubmit:v,children:[(0,Q.jsxs)(Lt,{children:[(0,Q.jsx)(Ie,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Q.jsx)(qr,{children:i(`organization.invitations.inviteDescription`,{defaultValue:`They will receive an invitation to join this organization.`})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,Q.jsx)(Y,{id:`invite-email`,type:`email`,required:!0,placeholder:`user@example.com`,value:o,onChange:e=>s(e.target.value),autoFocus:!0,"data-testid":`invite-email-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,Q.jsxs)(ve,{value:c,onValueChange:e=>l(e),children:[(0,Q.jsx)(Ft,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,Q.jsx)(Ht,{})}),(0,Q.jsxs)(zt,{children:[(0,Q.jsx)(Re,{value:`member`,children:i(`organization.roles.member`,{defaultValue:`Member`})}),(0,Q.jsx)(Re,{value:`admin`,children:i(`organization.roles.admin`,{defaultValue:`Admin`})}),(0,Q.jsx)(Re,{value:`owner`,children:i(`organization.roles.owner`,{defaultValue:`Owner`})})]})]})]}),f&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`invite-error`,children:f})]}),(0,Q.jsxs)(ge,{children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:u,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(J,{type:`submit`,disabled:u||!o.trim(),"data-testid":`invite-submit`,children:[u&&(0,Q.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}function gl(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function _l(){let{t:e}=H(),{org:t}=pl(),{getMembers:n,removeMember:r,updateMemberRole:i}=x(),[a,o]=(0,Z.useState)([]),[s,c]=(0,Z.useState)(!0),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(null),h=(0,Z.useCallback)(async()=>{c(!0),u(null);try{o(await n(t.id))}catch(e){u(e instanceof Error?e.message:`Failed to load members`)}finally{c(!1)}},[t.id,n]);(0,Z.useEffect)(()=>{h()},[h]);let g=async(n,r)=>{try{await i({organizationId:t.id,memberId:n.id,role:r}),X.success(e(`organization.members.roleUpdated`,{defaultValue:`Role updated`})),h()}catch(t){X.error(t instanceof Error?t.message:e(`organization.members.roleUpdateFailed`,{defaultValue:`Failed to update role`}))}};return s?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(q,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):l?(0,Q.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[l,(0,Q.jsx)(J,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:h,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,Q.jsxs)(`div`,{className:`space-y-4`,"data-testid":`members-page`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[e(`organization.members.title`,{defaultValue:`Members`}),` (`,a.length,`)`]}),(0,Q.jsx)(J,{onClick:()=>f(!0),"data-testid":`invite-member-btn`,children:e(`organization.members.inviteMember`,{defaultValue:`Invite member`})})]}),(0,Q.jsx)(Yr,{}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:a.map(t=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`member-row-${t.id}`,children:[(0,Q.jsxs)(On,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,Q.jsx)(ir,{src:t.user.image,alt:t.user.name}),(0,Q.jsx)(Tr,{className:`text-xs font-medium`,children:gl(t.user?.name)})]}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.user?.name??`—`}),(0,Q.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:t.user?.email??`—`})]}),(0,Q.jsx)(ue,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),t.createdAt&&(0,Q.jsx)(`span`,{className:`hidden shrink-0 text-xs text-muted-foreground sm:block`,children:new Date(t.createdAt).toLocaleDateString()}),(0,Q.jsxs)(br,{children:[(0,Q.jsx)(Pn,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Member actions`,children:(0,Q.jsx)(et,{className:`h-4 w-4`})})}),(0,Q.jsxs)(mn,{align:`end`,children:[(0,Q.jsxs)(kr,{onClick:()=>g(t,`owner`),disabled:t.role===`owner`,children:[(0,Q.jsx)(Nn,{className:`mr-2 h-4 w-4`}),e(`organization.roles.owner`,{defaultValue:`Owner`})]}),(0,Q.jsxs)(kr,{onClick:()=>g(t,`admin`),disabled:t.role===`admin`,children:[(0,Q.jsx)(Nn,{className:`mr-2 h-4 w-4`}),e(`organization.roles.admin`,{defaultValue:`Admin`})]}),(0,Q.jsxs)(kr,{onClick:()=>g(t,`member`),disabled:t.role===`member`,children:[(0,Q.jsx)(Nn,{className:`mr-2 h-4 w-4`}),e(`organization.roles.member`,{defaultValue:`Member`})]}),(0,Q.jsxs)(kr,{className:`text-destructive focus:text-destructive`,onClick:()=>m(t),children:[(0,Q.jsx)(it,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,Q.jsx)(fr,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,Q.jsxs)(Qn,{children:[(0,Q.jsxs)(jn,{children:[(0,Q.jsx)(pr,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Q.jsx)(Ar,{children:e(`organization.members.removeConfirmDescription`,{defaultValue:`This will remove {{name}} from the organization. They will lose access immediately.`,name:p?.user?.name??p?.userId??``})})]}),(0,Q.jsxs)(Cn,{children:[(0,Q.jsx)(gn,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(xr,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{if(p)try{await r({organizationId:t.id,memberIdOrUserId:p.id}),X.success(e(`organization.members.memberRemoved`,{defaultValue:`Member removed`})),m(null),h()}catch(t){X.error(t instanceof Error?t.message:e(`organization.members.removeFailed`,{defaultValue:`Failed to remove member`}))}},children:e(`organization.members.removeConfirmAction`,{defaultValue:`Remove`})})]})]})}),(0,Q.jsx)(hl,{organizationId:t.id,open:d,onOpenChange:f,onInvited:()=>h()})]})}function vl(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function yl(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function bl(){let{t:e}=H(),{org:t}=pl(),{listInvitations:n,cancelInvitation:r}=x(),[i,a]=(0,Z.useState)([]),[o,s]=(0,Z.useState)(!0),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(`all`),[f,p]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(null),g=(0,Z.useCallback)(async()=>{s(!0),l(null);try{a(await n(t.id))}catch(e){l(e instanceof Error?e.message:`Failed to load invitations`)}finally{s(!1)}},[t.id,n]);(0,Z.useEffect)(()=>{g()},[g]);let _=async t=>{let n=vl(t.id);try{await navigator.clipboard.writeText(n),h(t.id),X.success(e(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>h(null),2e3)}catch{X.error(e(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},v=async()=>{if(f)try{await r(f.id),X.success(e(`organization.invitations.canceled`,{defaultValue:`Invitation canceled`})),p(null),g()}catch(t){X.error(t instanceof Error?t.message:e(`organization.invitations.cancelFailed`,{defaultValue:`Failed to cancel invitation`}))}},y=u===`all`?i:i.filter(e=>e.status===u),b={all:i.length,pending:i.filter(e=>e.status===`pending`).length,accepted:i.filter(e=>e.status===`accepted`).length,rejected:i.filter(e=>e.status===`rejected`).length,canceled:i.filter(e=>e.status===`canceled`).length};return o?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(q,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):c?(0,Q.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[c,(0,Q.jsx)(J,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:g,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,Q.jsxs)(`div`,{className:`space-y-4`,"data-testid":`invitations-page`,children:[(0,Q.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.invitations.title`,{defaultValue:`Invitations`})})}),(0,Q.jsx)(`div`,{className:`flex gap-1 border-b`,children:[`all`,`pending`,`accepted`,`rejected`,`canceled`].map(t=>(0,Q.jsxs)(`button`,{onClick:()=>d(t),className:`px-3 py-2 text-sm font-medium border-b-2 transition-colors capitalize ${u===t?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[e(`organization.invitations.status.${t}`,{defaultValue:t}),b[t]>0&&(0,Q.jsx)(`span`,{className:`ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs`,children:b[t]})]},t))}),(0,Q.jsx)(Yr,{}),y.length===0?(0,Q.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organization.invitations.empty`,{defaultValue:`No invitations found.`})}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:y.map(t=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`invitation-row-${t.id}`,children:[(0,Q.jsx)(On,{className:`h-9 w-9 shrink-0`,children:(0,Q.jsx)(Tr,{className:`text-xs`,children:(0,Q.jsx)(lt,{className:`h-4 w-4`})})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.email}),t.expiresAt&&(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e(`organization.invitations.expiresAt`,{defaultValue:`Expires`}),` `,new Date(t.expiresAt).toLocaleDateString()]})]}),(0,Q.jsx)(ue,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),(0,Q.jsx)(ue,{variant:yl(t.status),className:`shrink-0 capitalize`,children:e(`organization.invitations.status.${t.status}`,{defaultValue:t.status})}),t.status===`pending`&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>_(t),"aria-label":`Copy invitation link`,children:m===t.id?(0,Q.jsx)(Ee,{className:`h-4 w-4 text-green-600`}):(0,Q.jsx)(qt,{className:`h-4 w-4`})}),(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,onClick:()=>p(t),"aria-label":`Cancel invitation`,children:(0,Q.jsx)(Et,{className:`h-4 w-4`})})]})]},t.id))}),(0,Q.jsx)(fr,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,Q.jsxs)(Qn,{children:[(0,Q.jsxs)(jn,{children:[(0,Q.jsx)(pr,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Q.jsx)(Ar,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,Q.jsxs)(Cn,{children:[(0,Q.jsx)(gn,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(xr,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:v,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function xl(){let{t:e}=H(),{org:t}=pl(),{user:n,getMembers:r,updateOrganization:i,deleteOrganization:a,leaveOrganization:o}=x(),s=_(),[c,l]=(0,Z.useState)(t.name),[u,d]=(0,Z.useState)(t.slug??``),[f,p]=(0,Z.useState)(t.logo??``),[m,h]=(0,Z.useState)(!1),[g,v]=(0,Z.useState)(!1),y=(0,Z.useRef)(null),{upload:b}=ln(),[S,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(!0),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(``),[M,N]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{l(t.name),d(t.slug??``),p(t.logo??``)},[t]),(0,Z.useEffect)(()=>{let e=!1;return T(!0),r(t.id).then(t=>{e||C(t.find(e=>e.userId===n?.id)?.role===`owner`)}).catch(()=>{e||C(!1)}).finally(()=>{e||T(!1)}),()=>{e=!0}},[t.id,n?.id,r]);let P=(0,Z.useCallback)(async n=>{n.preventDefault(),h(!0);try{await i(t.id,{name:c.trim(),slug:u.trim()||void 0,logo:f.trim()||void 0}),X.success(e(`organization.settings.saved`,{defaultValue:`Settings saved`}))}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.saveFailed`,{defaultValue:`Failed to save settings`}))}finally{h(!1)}},[t.id,c,u,f,i,e]);return w?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(q,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,Q.jsxs)(`div`,{className:`space-y-8`,"data-testid":`settings-page`,children:[(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.settings.generalTitle`,{defaultValue:`General`})}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organization.settings.generalDescription`,{defaultValue:`Update your organization information.`})}),(0,Q.jsx)(Yr,{className:`my-4`}),S?(0,Q.jsxs)(`form`,{onSubmit:P,className:`space-y-4 max-w-md`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,Q.jsx)(Y,{id:`org-name`,value:c,onChange:e=>l(e.target.value),required:!0,"data-testid":`settings-name-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,Q.jsx)(Y,{id:`org-slug`,value:u,onChange:e=>d(e.target.value),"data-testid":`settings-slug-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(ur,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(On,{className:`size-16 rounded-md`,children:[f?(0,Q.jsx)(ir,{src:f,alt:c,className:`object-cover`}):null,(0,Q.jsx)(Tr,{className:`rounded-md text-base`,children:(c||`O`).slice(0,2).toUpperCase()})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`input`,{ref:y,type:`file`,accept:`image/*`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(y.current&&(y.current.value=``),n){v(!0);try{p((await b(n)).url),X.success(e(`organization.settings.logoUploaded`,{defaultValue:`Logo uploaded — save to apply`}))}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.logoUploadFailed`,{defaultValue:`Failed to upload logo`}))}finally{v(!1)}}},"data-testid":`settings-logo-file`}),(0,Q.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:g,onClick:()=>y.current?.click(),"data-testid":`settings-logo-upload-btn`,children:[g?(0,Q.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Q.jsx)(ht,{className:`mr-2 h-4 w-4`}),f?e(`organization.settings.logoReplace`,{defaultValue:`Replace`}):e(`organization.settings.logoUpload`,{defaultValue:`Upload`})]}),f&&(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(``),"data-testid":`settings-logo-clear-btn`,children:[(0,Q.jsx)(Et,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,Q.jsx)(Y,{id:`org-logo`,type:`url`,value:f,onChange:e=>p(e.target.value),placeholder:`https://example.com/logo.png`,className:`text-xs`,"data-testid":`settings-logo-input`})]})]})]}),(0,Q.jsxs)(J,{type:`submit`,disabled:m,"data-testid":`settings-save-btn`,children:[m&&(0,Q.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.save`,{defaultValue:`Save changes`})]})]}):(0,Q.jsx)(`div`,{className:`rounded-lg border bg-muted/50 p-4 text-sm text-muted-foreground`,children:e(`organization.settings.readOnlyNote`,{defaultValue:`Only owners can change settings.`})})]}),(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold text-destructive`,children:e(`organization.settings.dangerZone`,{defaultValue:`Danger zone`})}),(0,Q.jsx)(Yr,{className:`my-4`}),(0,Q.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-destructive/50 bg-destructive/5 p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.leaveTitle`,{defaultValue:`Leave organization`})}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.leaveDescription`,{defaultValue:`You will lose access to this organization.`})})]}),(0,Q.jsx)(J,{variant:`destructive`,size:`sm`,onClick:()=>D(!0),children:e(`organization.settings.leaveAction`,{defaultValue:`Leave`})})]}),(0,Q.jsx)(Yr,{}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.deleteTitle`,{defaultValue:`Delete organization`})}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.deleteDescription`,{defaultValue:`Permanently delete this organization and all its data.`})})]}),(0,Q.jsx)(J,{variant:`destructive`,size:`sm`,onClick:()=>{j(``),k(!0)},disabled:!S,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,Q.jsx)(fr,{open:E,onOpenChange:D,children:(0,Q.jsxs)(Qn,{children:[(0,Q.jsxs)(jn,{children:[(0,Q.jsx)(pr,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Q.jsx)(Ar,{children:e(`organization.settings.leaveConfirmDescription`,{defaultValue:`Are you sure you want to leave {{name}}? You will lose access immediately.`,name:t.name})})]}),(0,Q.jsxs)(Cn,{children:[(0,Q.jsx)(gn,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(xr,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{N(!0);try{await o(t.id),X.success(e(`organization.settings.leftOrg`,{defaultValue:`You have left the organization`})),s(`/organizations`)}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.leaveFailed`,{defaultValue:`Failed to leave organization`}))}finally{N(!1)}},disabled:M,children:[M&&(0,Q.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,Q.jsx)(fr,{open:O,onOpenChange:e=>{k(e),e||j(``)},children:(0,Q.jsxs)(Qn,{children:[(0,Q.jsxs)(jn,{children:[(0,Q.jsx)(pr,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Q.jsx)(Ar,{children:e(`organization.settings.deleteConfirmDescription`,{defaultValue:`This action is irreversible. All data will be permanently deleted. Type the organization slug to confirm.`})})]}),(0,Q.jsxs)(`div`,{className:`px-6 pb-2`,children:[(0,Q.jsx)(ur,{htmlFor:`delete-confirm-slug`,className:`text-sm font-medium`,children:e(`organization.settings.deleteConfirmSlugLabel`,{defaultValue:`Type "{{slug}}" to confirm`,slug:t.slug})}),(0,Q.jsx)(Y,{id:`delete-confirm-slug`,className:`mt-2`,value:A,onChange:e=>j(e.target.value),placeholder:t.slug,"data-testid":`delete-confirm-slug-input`})]}),(0,Q.jsxs)(Cn,{children:[(0,Q.jsx)(gn,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(xr,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{N(!0);try{await a(t.id),X.success(e(`organization.settings.deleted`,{defaultValue:`Organization deleted`})),s(`/organizations`)}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.deleteFailed`,{defaultValue:`Failed to delete organization`}))}finally{N(!1)}},disabled:M||A!==t.slug,children:[M&&(0,Q.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}async function Sl(e){let t=await fetch(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(e)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`_drafts HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.drafts??n?.data?.drafts??[];return Array.isArray(r)?r.length:0}function Cl(e){if(!e||e.length===0)return!1;let t=e[e.length-1];return!t||t.role!==`assistant`?!1:t.parts.some(e=>e.type===`text`&&String(e.text??``).trim().length>0)}function wl(e){let{chatApi:t,conversationId:n}=e,[r,i]=(0,Z.useState)(!1),a=(0,Z.useRef)(void 0);return{errorSuppressed:r,handleChatError:(0,Z.useCallback)(async e=>{let r=t?.replace(/\/agents\/[^/]+\/chat$/,``);if(!n||!r){i(!1);return}try{let e=tc((await nc(r,n))?.messages);if(Cl(e)&&a.current){a.current(e),i(!0);return}}catch{}i(!1)},[n,t]),setMessagesRef:a,resetSuppression:(0,Z.useCallback)(()=>i(!1),[])}}function Tl(e,t){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=Date.now()-n.getTime(),i=60*1e3,a=60*i,o=24*a;return r<i?t(`console.ai.justNow`):r<a?t(`console.ai.minutesAgo`,{count:Math.floor(r/i)}):r<o?t(`console.ai.hoursAgo`,{count:Math.floor(r/a)}):r<7*o?t(`console.ai.daysAgo`,{count:Math.floor(r/o)}):n.toLocaleDateString()}function El(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString()}var Dl=[`today`,`yesterday`,`previous7Days`,`previous30Days`,`older`],Ol={today:`Today`,yesterday:`Yesterday`,previous7Days:`Previous 7 days`,previous30Days:`Previous 30 days`,older:`Older`};function kl(e,t=Date.now()){let n=new Date(t);n.setHours(0,0,0,0);let r=n.getTime(),i=1440*60*1e3,a=e=>{let t=new Date(e.updatedAt??e.createdAt??0).getTime();return Number.isNaN(t)?0:t},o={today:[],yesterday:[],previous7Days:[],previous30Days:[],older:[]};for(let t of[...e].sort((e,t)=>a(t)-a(e))){let e=a(t);e>=r?o.today.push(t):e>=r-i?o.yesterday.push(t):e>=r-7*i?o.previous7Days.push(t):e>=r-30*i?o.previous30Days.push(t):o.older.push(t)}return Dl.filter(e=>o[e].length>0).map(e=>({key:e,items:o[e]}))}function Al({userId:e,apiBase:t,className:n,refreshKey:r,titleHints:i,onNavigate:a}){let{t:s}=H(),c=_(),{conversationId:l}=o(),{conversations:u,isLoading:d,error:f,remove:p,rename:m}=fc({userId:e,apiBase:t,refreshKey:r}),[h,g]=(0,Z.useState)(``),[v,y]=(0,Z.useState)(void 0),b=(0,Z.useMemo)(()=>u.map(e=>{let t=i?.[e.id]?.trim();return!t||e.title?.trim()||e.preview?.trim()?e:{...e,preview:t}}),[u,i]),x=(0,Z.useMemo)(()=>{let e=h.trim().toLowerCase();return e?b.filter(t=>`${t.title??``} ${t.preview??``}`.toLowerCase().includes(e)):b},[b,h]),S=(0,Z.useCallback)(()=>{c(`/ai?new=1`),a?.()},[c,a]),C=(0,Z.useCallback)(async(e,t)=>{e.stopPropagation(),await p(t),t===l&&(c(`/ai`,{replace:!0}),a?.())},[p,l,c,a]),w=(0,Z.useCallback)(async(e,t)=>{y(void 0);try{await m(e,t)}catch{}},[m]);return(0,Q.jsxs)(`aside`,{className:yn(`flex h-full min-h-0 flex-col bg-muted/30`,n),"data-testid":`ai-conversations-sidebar`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium`,children:s(`console.ai.chats`)}),(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:S,"data-testid":`ai-new-chat`,children:[(0,Q.jsx)(Mt,{className:`h-3.5 w-3.5`}),s(`console.ai.newChat`)]})]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(Tt,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(Y,{value:h,onChange:e=>g(e.target.value),placeholder:s(`console.ai.searchChats`),className:`h-7 pl-7 text-xs`,"data-testid":`ai-conversations-search`})]})]}),(0,Q.jsx)(Ne,{className:`flex-1 min-h-0`,children:d&&u.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:s(`common.loading`)}):f?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-destructive`,children:f.message}):u.length===0?(0,Q.jsxs)(yt,{className:`px-3 py-8`,children:[(0,Q.jsx)(wt,{className:`h-8 w-8 text-muted-foreground`}),(0,Q.jsx)(Pe,{children:s(`console.ai.noChatsYet`)}),(0,Q.jsx)(Gr,{children:s(`console.ai.noChatsDescription`)})]}):x.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:s(`console.ai.noMatchingChats`)}):(0,Q.jsx)(`div`,{className:`flex flex-col py-1`,children:kl(x).map(e=>(0,Q.jsxs)(`section`,{"data-testid":`ai-conversation-group-${e.key}`,children:[(0,Q.jsx)(`h3`,{className:`px-3 pb-1 pt-3 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:s(`console.ai.group.${e.key}`,{defaultValue:Ol[e.key]})}),(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.items.map(e=>(0,Q.jsx)(Ml,{conversation:e,query:h.trim(),active:e.id===l,renaming:e.id===v,onSelect:()=>{c(`/ai/${e.id}`),a?.()},onDelete:t=>C(t,e.id),onStartRename:()=>y(e.id),onCancelRename:()=>y(void 0),onSubmitRename:t=>w(e.id,t)},e.id))})]},e.key))})})]})}function jl(e,t){if(!e)return e??null;let n=t?.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase(),i=[],a=0,o=0;for(;;){let t=r.indexOf(n,a);if(t===-1){i.push(e.slice(a));break}t>a&&i.push(e.slice(a,t)),i.push((0,Q.jsx)(`mark`,{className:`rounded-[2px] bg-primary/20 px-0.5 text-foreground`,children:e.slice(t,t+n.length)},o++)),a=t+n.length}return i}function Ml({conversation:e,query:t,active:n,renaming:r,onSelect:i,onDelete:a,onStartRename:o,onCancelRename:s,onSubmitRename:c}){let{t:l}=H(),u=e.title?.trim()||e.preview?.trim()||l(`console.ai.newConversation`),[d,f]=(0,Z.useState)(u),p=(0,Z.useRef)(null);return(0,Z.useEffect)(()=>{r&&(f(e.title?.trim()||e.preview?.trim()||``),setTimeout(()=>p.current?.select(),0))},[r,e.title,e.preview]),r?(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`div`,{className:yn(`flex w-full items-center gap-1 border-l-2 px-3 py-2`,n?`border-primary bg-accent`:`border-transparent`),"data-testid":`ai-conversation-rename-row-${e.id}`,children:[(0,Q.jsx)(Y,{ref:p,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),c(d)):e.key===`Escape`&&(e.preventDefault(),s())},className:`h-7 flex-1 text-sm`,"data-testid":`ai-conversation-rename-input-${e.id}`,"aria-label":l(`console.ai.renameConversation`)}),(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>c(d),"data-testid":`ai-conversation-rename-confirm-${e.id}`,"aria-label":l(`console.ai.saveRename`),children:(0,Q.jsx)(Ee,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:s,"aria-label":l(`console.ai.cancelRename`),children:(0,Q.jsx)(Et,{className:`h-3.5 w-3.5`})})]})}):(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`div`,{className:yn(`group flex w-full items-start gap-2 border-l-2 border-transparent px-3 py-2 text-sm transition-colors hover:bg-accent/50`,n&&`border-primary bg-accent`),"data-testid":`ai-conversation-row-${e.id}`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:i,className:`min-w-0 flex-1 text-left`,"data-testid":`ai-conversation-select-${e.id}`,children:[(0,Q.jsx)(`span`,{className:`line-clamp-1 font-medium`,children:jl(u,t)}),e.preview&&e.preview!==u?(0,Q.jsx)(`span`,{className:`mt-0.5 block line-clamp-1 text-xs text-muted-foreground`,children:jl(e.preview,t)}):null,(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[10px] text-muted-foreground`,title:El(e.updatedAt??e.createdAt),children:Tl(e.updatedAt??e.createdAt,l)})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100`,children:[(0,Q.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 hover:text-primary`,onClick:o,"data-testid":`ai-conversation-rename-${e.id}`,"aria-label":l(`console.ai.renameConversation`),children:(0,Q.jsx)(Wt,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 hover:text-destructive`,onClick:a,"data-testid":`ai-conversation-delete-${e.id}`,"aria-label":l(`console.ai.deleteConversation`),children:(0,Q.jsx)(Rt,{className:`h-3.5 w-3.5`})})]})]})})}function Nl(){return typeof window>`u`?``:window.location.pathname.startsWith(`/_console`)?`/_console`:``}function Pl(e,t){let n=`${Nl()}/apps/${encodeURIComponent(e)}`;return t?n:`${n}?preview=draft`}function Fl({appName:e,materialized:t=!1,refreshKey:n,onClose:r}){let{t:i}=H(),a=(0,Z.useRef)(null);return(0,Z.useEffect)(()=>{if(!a.current)return;let n=Pl(e,t);try{a.current.getAttribute(`src`)!==n&&a.current.setAttribute(`src`,n)}catch{}},[e,t]),(0,Z.useEffect)(()=>{if(n>0)try{a.current?.contentWindow?.location.reload()}catch{}},[n]),(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col border-l`,"data-testid":`live-canvas`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b bg-muted/30 px-3 py-1.5 text-xs text-muted-foreground`,children:[(0,Q.jsx)(mt,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:t?i(`console.ai.liveCanvasUnlisted`,{app:e,defaultValue:`Live app — {{app}} (unlisted until published)`}):i(`console.ai.liveCanvas`,{app:e,defaultValue:`Live preview — {{app}} (draft)`})}),(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,onClick:r,"data-testid":`live-canvas-close`,children:(0,Q.jsx)(Et,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`iframe`,{ref:a,title:`Draft preview: ${e}`,src:Pl(e,t),className:`h-full w-full flex-1 border-0 bg-background`,"data-testid":`live-canvas-frame`})]})}var Il=`/api/v1/ai`;function Ll(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function Rl(e){let t=Ll(e,`state`);switch(t){case`input-streaming`:case`input-available`:return`output-available`;case`approval-requested`:case`approval-responded`:case`output-available`:case`output-error`:case`output-denied`:return t;default:return`output-available`}}function zl(e){return e.map(e=>{let t=[],n,r=e.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``);if(e.role===`assistant`)for(let r of e.parts){if(!r.type.startsWith(`tool-`))continue;let i=Ll(r,`toolName`)??r.type.slice(5),a=Ll(r,`toolCallId`)??`${e.id}-${i}`,o=Rl(r),s=r.output??r.result,c=Pi(s);if(t.push({toolCallId:a,toolName:i,...o?{state:o}:{},...s===void 0?{}:{result:s},...c?{draftReview:c}:{},...r.errorText?{errorText:String(r.errorText)}:{}}),!n){let e=Fi(c);e&&(n=e)}}return{id:e.id,role:e.role,content:r,...t.length>0?{toolInvocations:t}:{},...n?{buildProgress:n}:{}}})}function Bl(e){return e.find(e=>e.role===`user`)?.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``).trim()||void 0}var Vl={data_chat:{key:`console.ai.agentLabels.dataChat`,defaultValue:`Assistant`},metadata_assistant:{key:`console.ai.agentLabels.metadataAssistant`,defaultValue:`Metadata Assistant`}};function Hl(e,t,n){let r=t?Vl[t]:void 0;return r?e(r.key,{defaultValue:r.defaultValue}):n}function Ul(e){if(e)return e.replace(/\/$/,``);let t={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},n=t.VITE_AI_BASE_URL;return n?n.replace(/\/$/,``):`${(t.VITE_SERVER_URL??``).replace(/\/$/,``)}${Il}`}var Wl=`ai-chats-collapsed`;function Gl(){let[e,t]=(0,Z.useState)(()=>{try{return localStorage.getItem(Wl)===`1`}catch{return!1}}),n=(0,Z.useRef)(!1);return{collapsed:e,toggle:(0,Z.useCallback)(()=>{n.current=!1,t(e=>{let t=!e;try{localStorage.setItem(Wl,t?`1`:`0`)}catch{}return t})},[]),handleCanvasOpenChange:(0,Z.useCallback)(e=>{e?t(e=>e||(n.current=!0,!0)):n.current&&(n.current=!1,t(!1))},[])}}var Kl=`ai-chat-pane-width`,ql=480,Jl=360,Yl=420,Xl=24;function Zl(e,t){let n=t.containerWidth>0?Math.max(t.min,t.containerWidth-t.previewMin):1/0;return Math.min(Math.max(e,t.min),n)}function Ql(e){let t=(0,Z.useRef)(null),[n,r]=(0,Z.useState)(()=>{try{let e=Number(localStorage.getItem(Kl));return Number.isFinite(e)&&e>0?e:ql}catch{return ql}}),[i,a]=(0,Z.useState)(!1),o=(0,Z.useCallback)(e=>Zl(e,{min:Jl,previewMin:Yl,containerWidth:t.current?.clientWidth??0}),[]),s=(0,Z.useCallback)(e=>{try{localStorage.setItem(Kl,String(Math.round(e)))}catch{}},[]);return(0,Z.useEffect)(()=>{if(!e)return;let n=t.current;if(!n||typeof ResizeObserver>`u`)return;let i=new ResizeObserver(()=>r(e=>o(e)));return i.observe(n),()=>i.disconnect()},[e,o]),{width:n,dragging:i,containerRef:t,onHandlePointerDown:(0,Z.useCallback)(e=>{e.preventDefault();let t=e.clientX,i=n;a(!0);let c=e=>r(o(i+(e.clientX-t))),l=e=>{let n=o(i+(e.clientX-t));r(n),s(n),a(!1),window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l)};window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l)},[o,s,n]),onHandleKeyDown:(0,Z.useCallback)(e=>{let t=e.key===`ArrowLeft`?-24:e.key===`ArrowRight`?Xl:0;t&&(e.preventDefault(),r(e=>{let n=o(e+t);return s(n),n}))},[o,s]),reset:(0,Z.useCallback)(()=>{let e=o(ql);r(e),s(e)},[o,s])}}function $l(e){if(!(e.metaKey||e.ctrlKey)||!e.shiftKey||e.altKey)return null;switch(e.key.toLowerCase()){case`o`:return`new-chat`;case`s`:return`toggle-list`;default:return null}}function eu({apiBase:e,defaultAgent:t}={}){let{user:n}=x(),{t:r}=H(),i=n?.id,{conversationId:a}=o(),[s]=p(),[c]=(0,Z.useState)(()=>s.get(`agent`)??void 0),l=s.get(`new`)!==null,u=_(),{setContext:d}=Si();(0,Z.useEffect)(()=>{d(`home`)},[d]);let f=(0,Z.useMemo)(()=>Ul(e),[e]),m={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_AI_DEFAULT_AGENT,{agents:h,isLoading:g,error:v}=ji({apiBase:f}),[y,b]=(0,Z.useState)(void 0);(0,Z.useEffect)(()=>{if(!y&&h.length>0){let e=Li(h,c??t??m);e&&b(e)}},[h,y,c,t,m]);let S=y?`${f}/agents/${encodeURIComponent(y)}/chat`:void 0,{conversationId:C,initialMessages:w}=ac({userId:i,scope:y,apiBase:f,activeId:a,forceNew:l}),[T,E]=(0,Z.useState)(0),[D,O]=(0,Z.useState)({}),[k,A]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)(!1),{collapsed:N,toggle:P,handleCanvasOpenChange:ee}=Gl();(0,Z.useEffect)(()=>{let e=e=>{let t=$l(e);t&&(e.preventDefault(),t===`toggle-list`?P():u(`/ai?new=1`))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[P,u]);let F=(0,Z.useMemo)(()=>f.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[f]),te=(0,Z.useRef)(null);l?te.current===null&&(te.current={id:C}):te.current=null,(0,Z.useEffect)(()=>{if(!a&&C){if(te.current&&te.current.id===C)return;u(`/ai/${C}`,{replace:!0})}},[a,C,u]);let I=(0,Z.useRef)(new Set);(0,Z.useEffect)(()=>{C&&w.length>0&&I.current.add(C)},[C,w.length]),(0,Z.useEffect)(()=>{if(!C)return;let e=Bl(w);e&&O(t=>t[C]===e?t:{...t,[C]:e})},[C,w]);let ne=(0,Z.useCallback)(e=>{if(E(e=>e+1),e&&C&&O(t=>({...t,[C]:e})),!e||!C||I.current.has(C))return;I.current.add(C);let t=()=>E(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[C]);return(0,Q.jsxs)(`div`,{className:`flex h-svh w-full flex-col bg-background`,"data-testid":`ai-chat-page`,children:[(0,Q.jsxs)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background/95 px-2 backdrop-blur sm:px-4`,children:[(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 md:hidden`,onClick:()=>M(!0),"aria-label":r(`console.ai.openChats`),"data-testid":`ai-chat-mobile-sidebar-trigger`,children:(0,Q.jsx)(Rn,{className:`h-4 w-4`})}),(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`hidden h-8 w-8 shrink-0 md:inline-flex`,onClick:P,"aria-label":N?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),title:N?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),"data-testid":`ai-chat-collapse-sidebar-trigger`,"aria-pressed":N,children:N?(0,Q.jsx)(rn,{className:`h-4 w-4`}):(0,Q.jsx)(sr,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(Ro,{variant:`home`})})]}),(0,Q.jsx)(gt,{open:j,onOpenChange:M,children:(0,Q.jsxs)(je,{side:`left`,className:`w-[320px] p-0 sm:max-w-[360px]`,"data-testid":`ai-chat-mobile-sidebar`,children:[(0,Q.jsxs)(nt,{className:`sr-only`,children:[(0,Q.jsx)(Ct,{children:r(`console.ai.chats`)}),(0,Q.jsx)(We,{children:r(`console.ai.chatsDescription`)})]}),(0,Q.jsx)(Al,{userId:i,apiBase:f,refreshKey:T,titleHints:D,className:`h-full border-r-0`,onNavigate:()=>M(!1)})]})}),C&&(0,Q.jsx)(Fr,{open:k,onOpenChange:A,objectName:`ai_conversations`,recordId:C,recordLabel:`this conversation`,apiBase:F}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 w-full bg-muted/20`,children:[!N&&(0,Q.jsx)(Al,{userId:i,apiBase:f,refreshKey:T,titleHints:D,className:`hidden w-72 shrink-0 border-r md:flex`}),(0,Q.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:(0,Q.jsx)(tu,{agents:h,agentsLoading:g,agentsError:v,activeAgent:y,onAgentChange:b,showAgentPicker:!!c,chatApi:S,apiBase:f,conversationId:C,initialMessages:w,onSent:ne,onShare:()=>A(!0),onCanvasOpenChange:ee},`${S??`local`}:${C??`pending`}`)})]})]})}function tu({agents:e,agentsLoading:t,showAgentPicker:n,agentsError:r,activeAgent:i,onAgentChange:a,chatApi:o,apiBase:s,conversationId:c,initialMessages:l,onSent:u,onShare:d,onCanvasOpenChange:f}){let{t:p}=H(),m=_(),[h,g]=(0,Z.useState)(null),[v,y]=(0,Z.useState)(0),b=(0,Z.useRef)(null);(0,Z.useEffect)(()=>()=>{b.current&&window.clearTimeout(b.current)},[]);let x=h!==null;(0,Z.useEffect)(()=>{f?.(x)},[x,f]);let S=Ql(x),C=(0,Z.useCallback)(e=>{let t=e.find(e=>e.type===`app`);t&&g(e=>e??{name:t.name,materialized:!1}),b.current&&window.clearTimeout(b.current),b.current=window.setTimeout(()=>y(e=>e+1),800)},[]),w=(0,Z.useCallback)(e=>{g(t=>t&&t.name===e&&!t.materialized?{name:e,materialized:!0}:t??{name:e,materialized:!0})},[]);(0,Z.useEffect)(()=>{g(null)},[c]);let T=(0,Z.useMemo)(()=>Hl(p,i,e.find(e=>e.name===i)?.label??i??p(`console.ai.assistant`)),[e,i,p]),E=(0,Z.useMemo)(()=>zl(l),[l]),D=(0,Z.useMemo)(()=>{if(!(E.length>0))return au(i,T,p)},[E.length,i,T,p]),{errorSuppressed:O,handleChatError:k,setMessagesRef:A,resetSuppression:j}=wl({chatApi:o,conversationId:c}),{messages:M,isLoading:N,error:P,sendMessage:ee,stop:F,reload:te,clear:I,setMessages:ne}=Mi({api:o,conversationId:c,onError:k,body:{context:{activeApp:`AI`,agentName:i,autoPublishAiBuilds:aa().features.autoPublishAiBuilds}},initialMessages:E,autoResponse:!o,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600});(0,Z.useEffect)(()=>{A.current=ne},[ne]),(0,Z.useEffect)(()=>{Zs(c,Qs(M))},[c,M]);let L=(0,Z.useRef)(!1);(0,Z.useEffect)(()=>{L.current&&!N&&h&&y(e=>e+1),L.current=N},[N,h]);let R=Ii({messages:M,apiBase:s,continueConversation:e=>{ee(e)}}),re=(0,Z.useCallback)((e,t)=>{j(),ee(e,t),u(e)},[ee,u]),z=(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border/50 px-4 pb-2 pt-3 sm:px-6`,children:[(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:n&&e.length>0?(0,Q.jsxs)(ve,{value:i,onValueChange:a,disabled:t,children:[(0,Q.jsx)(Ft,{className:`h-7 w-auto min-w-0 border-0 bg-transparent px-1.5 text-xs shadow-none hover:bg-accent focus:ring-0 focus:ring-offset-0 focus-visible:ring-1 focus-visible:ring-border/80 focus-visible:ring-offset-0 sm:min-w-[160px]`,"data-testid":`ai-chat-agent-picker`,children:(0,Q.jsx)(Ht,{placeholder:`Choose agent...`})}),(0,Q.jsx)(zt,{align:`start`,children:e.map(e=>(0,Q.jsxs)(Re,{value:e.name,className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:Hl(p,e.name,e.label)}),e.description?(0,Q.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[260px]`,children:e.description}):null]},e.name))})]}):(0,Q.jsx)(`span`,{className:`truncate text-xs font-medium text-foreground/85`,children:T})}),(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:d,disabled:!c,"aria-label":p(`console.ai.share`),"data-testid":`ai-chat-share-button`,title:p(c?`console.ai.shareTitle`:`console.ai.shareDisabledTitle`),children:(0,Q.jsx)(Mr,{className:`h-3.5 w-3.5`})})}),r?(0,Q.jsx)(`span`,{className:`basis-full text-[10px] text-amber-700 dark:text-amber-400`,title:r.message,children:p(`console.ai.offlineDemoMode`)}):null]});return(0,Q.jsxs)(`div`,{ref:S.containerRef,className:`relative flex min-h-0 flex-1 px-0`,children:[(0,Q.jsx)(`div`,{"data-chat-column":!0,className:h?`flex min-h-0 shrink-0 justify-center`:`flex min-h-0 flex-1 justify-center`,style:h?{width:S.width}:void 0,children:(0,Q.jsx)(Ni,{className:`min-h-0 flex-1 bg-background md:max-w-5xl`,onUpgrade:()=>window.open(oa(),`_blank`,`noopener,noreferrer`),surface:`plain`,maxHeight:`100%`,headerSlot:z,messages:M,placeholder:i?p(`console.ai.askAgent`,{agent:T}):p(t?`console.ai.loadingAgents`:`console.ai.askAnything`),labels:{emptyTitle:p(`console.ai.emptyTitle`),emptyDescription:p(`console.ai.emptyDescription`),clear:p(`console.ai.clearConversation`),sendHint:p(`console.ai.sendHint`),agentActivity:p(`console.ai.agentActivity`),toolCompleted:p(`console.ai.toolCompleted`),toolRunning:p(`console.ai.toolRunning`),toolAwaitingApproval:p(`console.ai.toolAwaitingApproval`),toolFailed:p(`console.ai.toolFailed`),toolDetailsHidden:p(`console.ai.toolDetailsHidden`),copy:p(`console.ai.copy`),copied:p(`console.ai.copied`),regenerate:p(`console.ai.regenerate`),model:p(`console.ai.model`),submit:p(`console.ai.submit`),uploadFiles:p(`console.ai.uploadFiles`),stopResponse:p(`console.ai.stopResponse`),trace:p(`console.ai.trace`),viewTrace:p(`console.ai.viewTrace`)},suggestions:D,onSendMessage:re,onClear:I,hideClearBar:!0,onStop:N?F:void 0,onReload:te,isLoading:N,error:O?void 0:P,enableMarkdown:!0,onToolApprove:R.decide,toolDecisions:R.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onOpenBuiltApp:e=>m(`/apps/${encodeURIComponent(e)}`),openBuiltAppLabel:p(`console.ai.openBuiltApp`,{defaultValue:`Open app`}),fetchPendingDraftCount:Sl,onPublishDrafts:async e=>{try{let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);let r=n?.data?.failedCount??n?.failedCount??0;if(r)throw Error(String(r));let i=n?.data?.seedApplied??n?.seedApplied;return i&&i.success===!1?X.warning(p(`console.ai.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:i.error??(Array.isArray(i.errors)&&i.errors.length?String(i.errors[0]):void 0)}):X.success(p(`console.ai.publishOk`,{defaultValue:`Published — objects are now live.`})),{ok:!0,health:Ai(n)}}catch(e){return X.error(p(`console.ai.publishFailed`,{defaultValue:`Publish failed`}),{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:p(`console.ai.publishDrafts`,{defaultValue:`Publish`}),publishedLabel:p(`console.ai.published`,{defaultValue:`Published`}),autoPublishDrafts:aa().features.autoPublishAiBuilds,onDraftArtifacts:C,onPreviewDraftApp:(e,t)=>g({name:e,materialized:t?.materialized===!0}),onBuildMaterialized:w,previewDraftLabel:p(`console.ai.previewDraft`,{defaultValue:`Preview`}),"data-testid":`ai-chat-panel`})}),h?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":p(`console.ai.resizeSplit`,{defaultValue:`Resize chat and preview`}),tabIndex:0,onPointerDown:S.onHandlePointerDown,onKeyDown:S.onHandleKeyDown,onDoubleClick:S.reset,"data-testid":`ai-chat-split-handle`,className:yn(`group relative hidden w-1.5 shrink-0 cursor-col-resize touch-none select-none md:block`,`focus:outline-none`),children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 -left-1.5 -right-1.5`}),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:yn(`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border transition-colors`,`group-hover:bg-primary/60 group-focus-visible:bg-primary`,S.dragging&&`bg-primary`)})]}),(0,Q.jsx)(Fl,{appName:h.name,materialized:h.materialized,refreshKey:v,onClose:()=>g(null)}),S.dragging?(0,Q.jsx)(`div`,{className:`fixed inset-0 z-50 cursor-col-resize`,"data-testid":`ai-chat-split-overlay`}):null]}):null]})}function nu(e){return[e(`console.ai.suggestions.dataChat.userCount`,{defaultValue:`How many users are in the system? List their emails.`}),e(`console.ai.suggestions.dataChat.recentRecords`,{defaultValue:`List the 5 most recently created records.`}),e(`console.ai.suggestions.dataChat.recordCounts`,{defaultValue:`Count records for each object.`})]}function ru(e){return[e(`console.ai.suggestions.metadataAssistant.buildCrm`,{defaultValue:`Build a CRM: customers, contacts and opportunities, with relationships.`}),e(`console.ai.suggestions.metadataAssistant.buildApp`,{defaultValue:`Create a project management app: projects, tasks and members.`}),e(`console.ai.suggestions.metadataAssistant.buildFlow`,{defaultValue:`Design a ticketing system: tickets, priority and a status flow.`})]}function iu(e){return[e(`console.ai.suggestions.generic.help`,{defaultValue:`What can you help me with?`}),e(`console.ai.suggestions.generic.availableObjects`,{defaultValue:`List the available data objects.`}),e(`console.ai.suggestions.generic.recentActivity`,{defaultValue:`Summarize my recent activity.`})]}function au(e,t,n){if(e===`data_chat`)return nu(n);if(e===`metadata_assistant`)return ru(n);let r=(e??t).toLowerCase();return r.includes(`data`)?nu(n):r.includes(`metadata`)?ru(n):iu(n)}var ou=new Map;function su(e){ou.set(e.ref,e)}function cu(e){return ou.get(e)}function lu(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function uu(e){return!lu(e)||e.viewKind?!1:!!(e.list||e.form||e.listViews||e.formViews)}function du(e){if(!lu(e))return;let t=e.config;if(lu(t)&&typeof t.type==`string`)return t.type;if(typeof e.type==`string`)return e.type;if(e.viewKind===`form`)return`form`;if(e.viewKind===`list`)return`list`}su({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:qi}),su({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:Ji}),su({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:Hi}),Wi({type:`object`,label:`Objects`,description:`Domain entities — tables in the data model. Each object owns its fields, relationships, validations, and lifecycle hooks.`,domain:`data`,searchableFields:[`name`,`label`,`description`],listColumns:[{key:`name`,label:`Name`,width:`25%`},{key:`label`,label:`Label`,width:`25%`},{key:`description`,label:`Description`}]}),Wi({type:`field`,label:`Fields`,description:`Columns attached to objects — name, type, validation, and storage settings.`,domain:`data`,searchableFields:[`name`,`label`,`object`,`type`],listColumns:[{key:`name`,label:`Name`,width:`25%`},{key:`object`,label:`Object`,width:`20%`},{key:`type`,label:`Type`,width:`15%`},{key:`label`,label:`Label`}]}),Wi({type:`permission`,label:`Permission sets`,description:`Object-level CRUD + VAMA + lifecycle permissions, and field-level R/W. Profiles are permission sets with isProfile=true.`,domain:`security`,EditPage:Ki,searchableFields:[`name`,`label`],listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`isProfile`,label:`Type`,width:`15%`,render:e=>e?`Profile`:`Permission set`}]}),Wi({type:`view`,label:`Views`,description:`Saved list / kanban / calendar / gantt configurations on top of an object.`,domain:`ui`,listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`object`,label:`Object`,width:`20%`},{key:`type`,label:`Type`,width:`15%`,render:(e,t)=>du(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!uu(e)}),Wi({type:`dashboard`,label:`Dashboards`,description:`Composed dashboards with charts, KPIs, and tables.`,domain:`ui`,listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}),Wi({type:`page`,label:`Pages`,description:`Visual page layouts authored as JSON metadata.`,domain:`ui`,listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`route`,label:`Route`}]});var fu=`/api/v1/cloud-connection`;async function pu(e,t){let n=await fetch(e,{credentials:`same-origin`,headers:{"Content-Type":`application/json`},...t}),r=await n.json().catch(()=>({}));if(!n.ok&&r?.success!==!0){let e=r?.error?.message??r?.error?.code??r?.error??`HTTP ${n.status}`;throw Error(typeof e==`string`?e:JSON.stringify(e))}return r}function mu(){let[e,t]=(0,Z.useState)({kind:`loading`}),[n,r]=(0,Z.useState)(!1),[i,a]=(0,Z.useState)(!1),o=(0,Z.useRef)(null),s=(0,Z.useCallback)(()=>{o.current&&=(clearTimeout(o.current),null)},[]),c=(0,Z.useCallback)(async()=>{try{let e=(await pu(`${fu}/status`))?.data??{environmentId:null,bound:!1,connection:null};t(e.bound?{kind:`bound`,status:e}:{kind:`unbound`})}catch(e){t({kind:`error`,message:e?.message??String(e)})}},[]);(0,Z.useEffect)(()=>(c(),s),[c,s]);let l=(0,Z.useCallback)((e,n)=>{let r=Math.max(e.interval,2)*1e3,i=async()=>{if(Date.now()-n>e.expires_in*1e3){t({kind:`error`,message:`The request expired before it was approved. Start again.`});return}try{let n=await pu(`${fu}/bind/poll`,{method:`POST`,body:JSON.stringify({device_code:e.device_code})});if(n?.data?.pending){o.current=setTimeout(i,r);return}if(n?.data?.bound||n?.success){await c();return}t({kind:`error`,message:n?.error?.code??`Binding failed.`})}catch(e){t({kind:`error`,message:e?.message??String(e)})}};o.current=setTimeout(i,r)},[c]),u=(0,Z.useCallback)(async()=>{r(!0);try{let e=(await pu(`${fu}/bind/start`,{method:`POST`,body:`{}`}))?.data;if(!e?.device_code||!e?.user_code)throw Error(`Device code request failed.`);let n=e.verification_uri_complete??e.verification_uri,r=!1;if(n)try{r=!!window.open(n,`_blank`,`noopener,width=520,height=720`)}catch{}t({kind:`waiting`,code:e,popupOpened:r}),l(e,Date.now())}catch(e){t({kind:`error`,message:e?.message??String(e)})}finally{r(!1)}},[l]),d=(0,Z.useCallback)(async()=>{r(!0);try{await pu(`${fu}/unbind`,{method:`POST`,body:`{}`}),await c()}catch(e){t({kind:`error`,message:e?.message??String(e)})}finally{r(!1)}},[c]),f=(0,Z.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),a(!0),setTimeout(()=>a(!1),1500)}catch{}},[]);if(e.kind===`loading`)return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border p-6 text-sm text-muted-foreground`,children:[(0,Q.jsx)(q,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),` Checking connection…`]});if(e.kind===`error`)return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-destructive/40 bg-destructive/5 p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-destructive`,children:[(0,Q.jsx)(Ur,{className:`h-4 w-4`,"aria-hidden":`true`}),` `,e.message]}),(0,Q.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{s(),c()},children:`Try again`})]});if(e.kind===`waiting`){let t=e.code.verification_uri_complete??e.code.verification_uri;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(q,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),e.popupOpened?`Approve the connection in the window that just opened — this page updates by itself.`:`Waiting for approval in the cloud console…`]}),!e.popupOpened&&t?(0,Q.jsxs)(`a`,{className:`inline-flex items-center gap-1.5 self-start rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90`,href:t,target:`_blank`,rel:`noreferrer`,children:[`Open the approval page `,(0,Q.jsx)(He,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})]}):null,(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`code`,{className:`rounded-md bg-muted px-4 py-2 text-2xl font-semibold tracking-[0.25em]`,children:e.code.user_code}),(0,Q.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>void f(e.code.user_code),children:[(0,Q.jsx)(qt,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` `,i?`Copied`:`Copy`]})]}),(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`The code is pre-filled on the approval page`,e.popupOpened&&t?(0,Q.jsxs)(Q.Fragment,{children:[` `,`— if the window did not appear,`,` `,(0,Q.jsxs)(`a`,{className:`inline-flex items-center gap-1 text-primary underline-offset-2 hover:underline`,href:t,target:`_blank`,rel:`noreferrer`,children:[`open it here `,(0,Q.jsx)(He,{className:`h-3 w-3`,"aria-hidden":`true`})]}),`.`]}):`.`]}),(0,Q.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{s(),c()},children:`Cancel`})]})}if(e.kind===`bound`){let t=e.status.connection??{},r=t.runtime_id??e.status.runtimeId;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Fn,{className:`h-5 w-5 text-emerald-600`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:`Connected to ObjectStack Cloud`})]}),(0,Q.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-6 gap-y-1.5 text-sm`,children:[t.name?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Runtime`}),(0,Q.jsx)(`dd`,{children:t.name})]}):null,t.organization_id?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Organization`}),(0,Q.jsx)(`dd`,{className:`font-mono`,children:t.organization_id})]}):null,t.account_email?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Approved by`}),(0,Q.jsx)(`dd`,{children:t.account_email})]}):null,r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Runtime ID`}),(0,Q.jsx)(`dd`,{className:`font-mono text-xs`,children:r})]}):null,e.status.environmentId?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Environment`}),(0,Q.jsx)(`dd`,{className:`font-mono`,children:e.status.environmentId})]}):null,t.bound_at?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Since`}),(0,Q.jsx)(`dd`,{children:new Date(t.bound_at).toLocaleString()})]}):null]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Your organization's private packages now appear in the Marketplace under “Your organization”.`}),(0,Q.jsxs)(`button`,{type:`button`,disabled:n,className:`inline-flex items-center gap-1.5 self-start rounded-md border border-destructive/40 px-3 py-1.5 text-sm text-destructive hover:bg-destructive/5 disabled:opacity-50`,onClick:()=>void d(),children:[(0,Q.jsx)(ke,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` Disconnect`]})]})}return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(ar,{className:`h-5 w-5 text-muted-foreground`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:`Not connected`})]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Connect this runtime to an ObjectStack control plane to browse your organization's private packages and install them here. Approval is a single click in your cloud account — no ids or credentials are typed into this page.`}),(0,Q.jsxs)(`button`,{type:`button`,disabled:n,className:`inline-flex items-center gap-1.5 self-start rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,onClick:()=>void u(),children:[n?(0,Q.jsx)(q,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}):(0,Q.jsx)(kn,{className:`h-4 w-4`,"aria-hidden":`true`}),`Connect`]})]})}B.register(`cloud-connection:panel`,()=>(0,Q.jsx)(mu,{}),{namespace:`app-shell`,label:`Cloud Connection Panel`,category:`plugin`,inputs:[]});var hu={type:`element:definition-list`,properties:{columns:2,items:[{term:`Status`,description:`Active`},{term:`Owner`,description:`Ada Lovelace`},{term:`Plan`,description:`Enterprise`},{term:`Renewal`,description:`2026-12-01`}]}},gu=()=>{let{modalHandler:e,modalElement:t}=vi();return(0,Q.jsxs)(`div`,{className:`space-y-4 p-6`,children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Action modal transport`}),(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`One `,(0,Q.jsx)(`code`,{children:`onModal`}),` handler, four placements, arbitrary SchemaNode content.`]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(J,{"data-testid":`open-center`,onClick:()=>e({placement:`center`,size:`lg`,title:`Center modal`,content:hu}),children:`Center`}),(0,Q.jsx)(J,{"data-testid":`open-side`,variant:`outline`,onClick:()=>e({placement:`side`,title:`Side drawer`,content:hu}),children:`Side drawer`}),(0,Q.jsx)(J,{"data-testid":`open-bottom`,variant:`outline`,onClick:()=>e({placement:`bottom`,title:`Bottom sheet`,content:hu}),children:`Bottom sheet`}),(0,Q.jsx)(J,{"data-testid":`open-fullscreen`,variant:`outline`,onClick:()=>e({placement:`fullscreen`,title:`Fullscreen`,content:hu}),children:`Fullscreen`})]}),t]})},_u=()=>{let[e,t]=Z.useState([{},{}]);return(0,Q.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-4 p-6`,children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Line-item grid with a lookup cell`}),(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`The `,(0,Q.jsx)(`code`,{children:`Account`}),` column is a real lookup picker bound to live `,(0,Q.jsx)(`code`,{children:`showcase_account`}),`.`]}),(0,Q.jsx)(Qt,{value:e,onChange:t,field:{columns:[{field:`account`,label:`Account`,type:`lookup`,reference:`showcase_account`,displayField:`name`},{field:`note`,label:`Note`,type:`text`},{field:`amount`,label:`Amount`,type:`currency`}],total_field:`amount`}}),(0,Q.jsx)(`pre`,{className:`rounded bg-muted p-3 text-xs`,"data-testid":`rows-json`,children:JSON.stringify(e)})]})},vu=(0,Z.lazy)(()=>u(()=>import(`./SystemHubPage-_i5E_SOC.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]),import.meta.url)),yu=(0,Z.lazy)(()=>u(()=>import(`./AppManagementPage-DN-u3YQP.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),bu=(0,Z.lazy)(()=>u(()=>import(`./ProfilePage-C11r_2xN.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),xu=(0,Z.lazy)(()=>u(()=>import(`./ApprovalsInboxPage-BbvtY-xj.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),Su=(0,Z.lazy)(()=>u(()=>import(`./AiPendingActionsPage-CaJCvm5D.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),Cu=(0,Z.lazy)(()=>u(()=>import(`./AuditLogPage-ffz9xeHl.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),wu=(0,Z.lazy)(()=>u(()=>import(`./SettingsHub-CUCcntU9.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),Tu=(0,Z.lazy)(()=>u(()=>import(`./SettingsView-DRjJrXF9.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),Eu=(0,Z.lazy)(()=>u(()=>import(`./DeveloperHubPage-DZyjalsK.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),Du=(0,Z.lazy)(()=>u(()=>import(`./ApiConsolePage-DGCgQ6RS.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),Ou=(0,Z.lazy)(()=>u(()=>import(`./FlowRunsPage-DcT6ntvZ.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),ku=(0,Z.lazy)(()=>u(()=>import(`./PublicFormsPage-N0Wofan4.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url)),Au=(0,Z.lazy)(()=>u(()=>import(`./IntegrationsPage-Dfl35fAT.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([0]),import.meta.url)),ju=(0,Z.lazy)(()=>u(()=>Promise.resolve().then(()=>cd),void 0,import.meta.url)),Mu=(0,Z.lazy)(()=>u(()=>import(`./AppDocsIndex-B_hZ36LW.js`),__vite__mapDeps([0]),import.meta.url));function Nu(){let{objectName:e}=o(),t=l().pathname.replace(/\/objects(\/.*)?$/,``);return(0,Q.jsx)(r,{to:e?`${t}/component/metadata/resource/${e}?type=object`:`${t}/component/metadata/resource?type=object`,replace:!0})}function Pu(){let{metadataType:e,itemName:t}=o(),n=l().pathname.replace(/\/metadata(\/.*)?$/,``),i=`${n}/component/metadata/resource`;return(0,Q.jsx)(r,{to:e?t?`${i}/${t}?type=${e}`:`${i}?type=${e}`:`${n}/component/metadata/directory`,replace:!0})}var Fu=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{path:`system`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(vu,{})})}),(0,Q.jsx)(h,{path:`system/apps`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(yu,{})})}),(0,Q.jsx)(h,{path:`system/profile`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(bu,{})})}),(0,Q.jsx)(h,{path:`system/approvals`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(xu,{})})}),(0,Q.jsx)(h,{path:`system/ai-approvals`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(Su,{})})}),(0,Q.jsx)(h,{path:`system/audit-log`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(Cu,{})})}),(0,Q.jsx)(h,{path:`system/settings`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(wu,{})})}),(0,Q.jsx)(h,{path:`system/settings/:namespace`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(Tu,{})})}),(0,Q.jsx)(h,{path:`developer`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(Eu,{})})}),(0,Q.jsx)(h,{path:`developer/api-console`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(Du,{})})}),(0,Q.jsx)(h,{path:`developer/flow-runs`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(Ou,{})})}),(0,Q.jsx)(h,{path:`developer/public-forms`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(ku,{})})}),(0,Q.jsx)(h,{path:`developer/integrations`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(Au,{})})}),(0,Q.jsx)(h,{path:`docs`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(Mu,{})})}),(0,Q.jsx)(h,{path:`docs/:name`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(ju,{})})}),(0,Q.jsx)(h,{path:`system/objects`,element:(0,Q.jsx)(Nu,{})}),(0,Q.jsx)(h,{path:`system/objects/:objectName`,element:(0,Q.jsx)(Nu,{})}),(0,Q.jsx)(h,{path:`system/metadata`,element:(0,Q.jsx)(Pu,{})}),(0,Q.jsx)(h,{path:`system/metadata/:metadataType`,element:(0,Q.jsx)(Pu,{})}),(0,Q.jsx)(h,{path:`system/metadata/:metadataType/:itemName`,element:(0,Q.jsx)(Pu,{})})]});function Iu(){let e=(0,Z.useMemo)(()=>zr({baseUrl:``}),[``]);return(0,Q.jsx)(D,{endpoint:`/api/v1/auth/me/permissions`,loadingFallback:(0,Q.jsx)(Xo,{}),children:(0,Q.jsx)(jr,{adapter:e,children:(0,Q.jsx)(Pc,{extraRoutes:Fu,extraRoutesNoApp:Fu})})})}var Lu=[`cloud_control`];function Ru(){let{apps:e,loading:t}=F();if(t)return(0,Q.jsx)(Ha,{});let n=new Set((e??[]).map(e=>e?.name).filter(Boolean));for(let e of Lu)if(n.has(e))return(0,Q.jsx)(r,{to:`/apps/${e}`,replace:!0});return(0,Q.jsx)(r,{to:`/home`,replace:!0})}var zu=`/api/v1`;function Bu(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function Vu(e){if(Array.isArray(e))return e.map(e=>{if(typeof e==`string`)return{value:e,label:e};if(e&&typeof e==`object`){let t=String(e.value??e.id??``);return{value:t,label:String(e.label??e.name??t)}}return{value:String(e),label:String(e)}})}function Hu(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=Bu(e.columns),n=[];for(let t of e.fields??[]){let e=typeof t==`string`?{field:t}:{...t},i=r[e.field]??{type:`text`};n.push({name:e.field,label:e.label??i.label??e.field,type:i.type??`text`,required:e.required??i.required??!1,readonly:e.readonly??!1,hidden:e.hidden??!1,placeholder:e.placeholder??i.placeholder,helpText:e.helpText??i.helpText,defaultValue:i.defaultValue,options:Vu(i.options),maxLength:i.maxLength,colSpan:e.colSpan??1})}return{label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,fields:n}})}function Uu(e,t){let n={};for(let r of e){r.defaultValue!==void 0&&(n[r.name]=r.defaultValue);let e=t.get(`prefill_${r.name}`);e!==null&&(n[r.name]=e)}return n}async function Wu(e,t){return fetch(`${zu}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function Gu(e){let t=await Wu(`/forms/${encodeURIComponent(e)}`);if(!t.ok){let e=await t.text().catch(()=>``);throw Error(`Failed to load form (${t.status}): ${e||t.statusText}`)}let n=await t.json();return{label:n.label??n.form?.label??n.object,object:n.object,form:n.form,objectSchema:n.objectSchema}}async function Ku(e){let t=await Wu(`/meta/view/${encodeURIComponent(e)}`);if(!t.ok)throw Error(`Form metadata not found: view/${e}`);let n=await t.json(),r=n?.item??n,i=r?.spec??r,a=i?.object;if(!a)throw Error(`FormView "${e}" is missing an "object" target`);let o=null;try{let e=await Wu(`/meta/object/${encodeURIComponent(a)}`);if(e.ok){let t=await e.json(),n=t?.item??t,r=n?.spec??n;r?.fields&&typeof r.fields==`object`&&(o={name:r.name??a,label:r.label,fields:r.fields})}}catch{}return{label:i?.label??e,object:a,form:i,objectSchema:o}}async function qu(e,t){let n=await Wu(`/forms/${encodeURIComponent(e)}/submit`,{method:`POST`,body:JSON.stringify(t)});if(!n.ok){let e=await n.text().catch(()=>``);throw Error(`Submit failed (${n.status}): ${e||n.statusText}`)}return n.json().catch(()=>({}))}async function Ju(e,t){let n=await Wu(`/data/${encodeURIComponent(e)}`,{method:`POST`,body:JSON.stringify(t)});if(!n.ok){let e=await n.text().catch(()=>``);throw Error(`Create failed (${n.status}): ${e||n.statusText}`)}return n.json().catch(()=>({}))}var Yu=`w-full rounded-md border border-input bg-background px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`;function Xu({field:e,value:t,onChange:n}){let r={id:`f_${e.name}`,name:e.name,required:e.required,disabled:e.readonly,placeholder:e.placeholder,className:Yu},i=t??``;switch(e.type){case`textarea`:case`paragraph`:case`long_text`:return(0,Q.jsx)(`textarea`,{...r,rows:5,maxLength:e.maxLength,value:String(i),onChange:e=>n(e.target.value)});case`number`:case`integer`:case`decimal`:case`currency`:return(0,Q.jsx)(`input`,{...r,type:`number`,value:i===``?``:Number(i),onChange:e=>n(e.target.value===``?null:Number(e.target.value))});case`email`:return(0,Q.jsx)(`input`,{...r,type:`email`,value:String(i),onChange:e=>n(e.target.value)});case`url`:return(0,Q.jsx)(`input`,{...r,type:`url`,value:String(i),onChange:e=>n(e.target.value)});case`password`:return(0,Q.jsx)(`input`,{...r,type:`password`,value:String(i),onChange:e=>n(e.target.value)});case`date`:return(0,Q.jsx)(`input`,{...r,type:`date`,value:String(i),onChange:e=>n(e.target.value)});case`time`:return(0,Q.jsx)(`input`,{...r,type:`time`,value:String(i),onChange:e=>n(e.target.value)});case`datetime`:case`timestamp`:return(0,Q.jsx)(`input`,{...r,type:`datetime-local`,value:String(i),onChange:e=>n(e.target.value)});case`boolean`:case`toggle`:case`checkbox`:return(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-sm`,children:[(0,Q.jsx)(`input`,{id:r.id,name:r.name,type:`checkbox`,disabled:e.readonly,checked:!!i,onChange:e=>n(e.target.checked),className:`h-4 w-4 rounded border-input`}),(0,Q.jsx)(`span`,{children:e.placeholder??e.label})]});case`select`:case`picklist`:case`enum`:{let t=e.options??[];return(0,Q.jsxs)(`select`,{...r,value:String(i),onChange:e=>n(e.target.value),children:[(0,Q.jsx)(`option`,{value:``,disabled:e.required,children:e.placeholder??`— Select —`}),t.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))]})}case`radio`:return(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:(e.options??[]).map(t=>(0,Q.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,Q.jsx)(`input`,{type:`radio`,name:e.name,value:t.value,checked:String(i)===t.value,disabled:e.readonly,onChange:()=>n(t.value)}),(0,Q.jsx)(`span`,{children:t.label})]},t.value))});default:return(0,Q.jsx)(`input`,{...r,type:`text`,maxLength:e.maxLength,value:String(i),onChange:e=>n(e.target.value)})}}function Zu({mode:e}){let t=o(),[n]=p(),r=(e===`public`?t.slug:t.name)??``,[i,a]=(0,Z.useState)(!0),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)({}),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(!1);(0,Z.useEffect)(()=>{let t=!1;return a(!0),c(null),(e===`public`?Gu(r):Ku(r)).then(e=>{t||(u(e),f(Uu(Hu(e.form,e.objectSchema).flatMap(e=>e.fields),n)))}).catch(e=>{t||c(e?.message??String(e))}).finally(()=>{t||a(!1)}),()=>{t=!0}},[e,r,n]);let v=(0,Z.useMemo)(()=>l?Hu(l.form,l.objectSchema):[],[l]),y=l?.form?.submitBehavior??{kind:`thank-you`};return i?(0,Q.jsx)(`div`,{className:`flex min-h-[60vh] items-center justify-center`,children:(0,Q.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Loading…`})}):s&&!l?(0,Q.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,Q.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:s})}):l?g&&y.kind===`thank-you`?(0,Q.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,Q.jsxs)(`div`,{className:`rounded-md border bg-card p-6 text-center`,children:[(0,Q.jsx)(`h2`,{className:`mb-2 text-lg font-semibold`,children:y.title??`Thanks!`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:y.message??`Your submission has been received.`})]})}):g&&y.kind===`redirect`?(0,Q.jsx)(`div`,{className:`mx-auto max-w-2xl p-6 text-center text-sm text-muted-foreground`,children:`Redirecting…`}):(0,Q.jsxs)(`div`,{className:`mx-auto max-w-2xl p-4 sm:p-6`,children:[(0,Q.jsxs)(`header`,{className:`mb-6`,children:[(0,Q.jsx)(`h1`,{className:`text-xl font-semibold`,children:l.label}),l.form?.label&&l.form.label!==l.label&&(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:l.form.label})]}),(0,Q.jsxs)(`form`,{onSubmit:async t=>{if(t.preventDefault(),l){h(!0),c(null);try{switch(e===`public`?await qu(r,d):await Ju(l.object,d),X.success(`Submitted`),y.kind){case`redirect`:{let e=y.delayMs??0;setTimeout(()=>window.location.assign(y.url),e),_(!0);break}case`continue`:f(Uu(v.flatMap(e=>e.fields),n));break;default:_(!0);break}}catch(e){let t=e?.message??String(e);c(t),X.error(t)}finally{h(!1)}}},className:`space-y-6`,children:[v.map((e,t)=>(0,Q.jsxs)(`section`,{className:`rounded-md border bg-card p-4 sm:p-5`,children:[e.label&&(0,Q.jsx)(`h2`,{className:`mb-3 text-sm font-medium`,children:e.label}),(0,Q.jsx)(`div`,{className:e.columns===1?`grid grid-cols-1 gap-4`:e.columns===2?`grid grid-cols-1 gap-4 sm:grid-cols-2`:e.columns===3?`grid grid-cols-1 gap-4 sm:grid-cols-3`:`grid grid-cols-1 gap-4 sm:grid-cols-4`,children:e.fields.filter(e=>!e.hidden).map(e=>(0,Q.jsxs)(`div`,{className:e.colSpan===2?`sm:col-span-2`:e.colSpan===3?`sm:col-span-3`:e.colSpan===4?`sm:col-span-4`:``,children:[(0,Q.jsxs)(`label`,{htmlFor:`f_${e.name}`,className:`mb-1 block text-xs font-medium text-foreground`,children:[e.label,e.required&&(0,Q.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`})]}),(0,Q.jsx)(Xu,{field:e,value:d[e.name],onChange:t=>f(n=>({...n,[e.name]:t}))}),e.helpText&&(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:e.helpText})]},e.name))})]},t)),s&&(0,Q.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:s}),(0,Q.jsx)(`div`,{className:`flex justify-end gap-2`,children:(0,Q.jsx)(`button`,{type:`submit`,disabled:m,className:`rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow-sm hover:bg-primary/90 disabled:opacity-50`,children:m?`Submitting…`:`Submit`})})]})]}):null}function Qu({enabled:e=!1,url:t=`/api/v1/dev/metadata-events`,debounceMs:n=400,reconnectDelayMs:r=2e3}){let i=(0,Z.useRef)(null);return(0,Z.useEffect)(()=>{if(!e||typeof window>`u`||typeof EventSource>`u`)return;let a=null,o=null,s=!1,c=e=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{try{X.info(`Metadata changed (${e}) — reloading…`,{duration:800})}catch{}setTimeout(()=>{try{window.location.reload()}catch{}},150)},n)},l=e=>{try{let t=JSON.parse(e.data);c(t?.name?`${t.metadataType??`metadata`}:${t.name}`:`metadata`)}catch{c(`change`)}},u=e=>{let t=`rebuild`;try{t=JSON.parse(e.data)?.reason??t}catch{}c(t)},d=()=>{if(!s)try{a=new EventSource(t),a.addEventListener(`metadata-change`,l),a.addEventListener(`reload`,u),a.addEventListener(`error`,()=>{s||a?.readyState===EventSource.CLOSED&&(a=null,o=setTimeout(d,r))})}catch{o=setTimeout(d,r)}};return d(),()=>{if(s=!0,o&&clearTimeout(o),i.current&&clearTimeout(i.current),a)try{a.close()}catch{}}},[e,t,n,r]),null}function $u(){let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_SERVER_URL??``;return e?e.replace(/\/$/,``):typeof window<`u`?window.location.origin:``}function ed(e){return typeof e.content==`string`&&e.content.trim()?e.content:Array.isArray(e.parts)?e.parts.map(e=>e.text??e.content??``).filter(Boolean).join(`
|
|
3
|
-
|
|
4
|
-
`):``}function td(){let{token:e}=o(),t=`${(0,Z.useMemo)(()=>$u(),[])}/api/v1`,[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(null),[s,c]=(0,Z.useState)(!0),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(null),h=(0,Z.useCallback)(async n=>{if(e){c(!0),a(null);try{let i=new URL(`${t}/share-links/${encodeURIComponent(e)}/resolve`);n&&i.searchParams.set(`password`,n);let o=await fetch(i.toString(),{headers:{Accept:`application/json`}});if(o.status===401){u(!0),a(n?`Wrong password.`:null),c(!1);return}if(o.status===404){a(`This link is invalid or no longer available.`),c(!1);return}if(o.status===410){a(`This link has expired or was revoked.`),c(!1);return}if(!o.ok){a((await o.json().catch(()=>null))?.error?.message??`Failed to load (HTTP ${o.status}).`),c(!1);return}let s=await o.json();r(`data`in s?s.data:{record:s.record,link:s.link,redactedFields:s.redactFields}),u(!1)}catch(e){a(e?.message??`Failed to load shared content.`)}finally{c(!1)}}},[t,e]);if((0,Z.useEffect)(()=>{h()},[h]),(0,Z.useEffect)(()=>{if(!n||n.link.object_name!==`ai_conversations`)return;let e=`${t}/share-links/${encodeURIComponent(n.link.token)}/messages`;fetch(e,{headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(e=>m(e?.data??[])).catch(()=>m([]))},[t,n]),s)return(0,Q.jsxs)(`div`,{className:`flex h-svh w-full items-center justify-center bg-background text-muted-foreground`,children:[(0,Q.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading…`]});if(l)return(0,Q.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-md flex-col items-center justify-center gap-4 px-4 text-center`,children:[(0,Q.jsx)(Be,{className:`h-8 w-8 text-muted-foreground`}),(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Password required`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The owner protected this link with a password.`}),(0,Q.jsxs)(`form`,{className:`flex w-full flex-col gap-2`,onSubmit:e=>{e.preventDefault(),h(d)},children:[(0,Q.jsx)(ur,{htmlFor:`share-pw`,className:`sr-only`,children:`Password`}),(0,Q.jsx)(Y,{id:`share-pw`,type:`password`,value:d,onChange:e=>f(e.target.value),autoFocus:!0,placeholder:`Enter password`}),i&&(0,Q.jsx)(`p`,{className:`text-xs text-destructive`,children:i}),(0,Q.jsx)(J,{type:`submit`,size:`sm`,children:`Continue`})]})]});if(i)return(0,Q.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-md flex-col items-center justify-center gap-3 px-4 text-center`,children:[(0,Q.jsx)(St,{className:`h-8 w-8 text-amber-500`}),(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Can't open this link`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i})]});if(!n)return null;if(n.link.object_name===`ai_conversations`){let e=n.record;return(0,Q.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,Q.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background px-4 py-3`,children:[(0,Q.jsx)(wt,{className:`h-5 w-5 text-muted-foreground`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`h1`,{className:`truncate text-sm font-semibold`,children:e.title??`Shared conversation`}),(0,Q.jsx)(`p`,{className:`truncate text-[11px] text-muted-foreground`,children:`Read-only · Shared via ObjectStack`})]}),(0,Q.jsx)(ue,{variant:`outline`,className:`text-[10px] capitalize`,children:n.link.permission})]}),(0,Q.jsxs)(`main`,{className:`flex-1 overflow-y-auto px-4 py-6`,children:[p==null&&(0,Q.jsxs)(`div`,{className:`flex items-center justify-center py-12 text-sm text-muted-foreground`,children:[(0,Q.jsx)(q,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading messages…`]}),p&&p.length===0&&(0,Q.jsx)(`p`,{className:`py-12 text-center text-sm text-muted-foreground`,children:`This conversation has no messages yet.`}),(0,Q.jsx)(`ul`,{className:`space-y-4`,children:p?.map(e=>{let t=ed(e);if(!t)return null;let n=e.role===`user`;return(0,Q.jsx)(`li`,{className:`flex ${n?`justify-end`:`justify-start`}`,children:(0,Q.jsx)(`div`,{className:`max-w-[85%] rounded-lg px-3 py-2 text-sm leading-relaxed ${n?`bg-primary text-primary-foreground`:`bg-muted text-foreground`}`,children:n?(0,Q.jsx)(`p`,{className:`whitespace-pre-wrap`,children:t}):(0,Q.jsx)(`pre`,{className:`whitespace-pre-wrap font-sans text-sm leading-relaxed`,children:t})})},e.id)})})]}),(0,Q.jsx)(`footer`,{className:`border-t bg-muted/30 px-4 py-2 text-center text-[11px] text-muted-foreground`,children:`Powered by ObjectStack`})]})}return(0,Q.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,Q.jsx)(`header`,{className:`border-b px-4 py-3`,children:(0,Q.jsxs)(`h1`,{className:`text-sm font-semibold`,children:[`Shared `,n.link.object_name]})}),(0,Q.jsxs)(`main`,{className:`flex-1 overflow-y-auto p-4`,children:[(0,Q.jsx)(`pre`,{className:`overflow-x-auto rounded-md border bg-muted/30 p-3 text-[12px]`,children:JSON.stringify(n.record,null,2)}),n.redactedFields&&n.redactedFields.length>0&&(0,Q.jsxs)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:[`Some fields are hidden by the owner: `,n.redactedFields.join(`, `)]})]})]})}var nd=/(^```[^\n]*\n[\s\S]*?\n```[ \t]*$|^~~~[^\n]*\n[\s\S]*?\n~~~[ \t]*$)/m,rd=/(`[^`\n]+`)/,id=/\]\((?:\.\/)?([a-z][a-z0-9_]*)\.md(#[^)\s]*)?\)/g;function ad(e){return e.split(rd).map((e,t)=>t%2==1?e:e.replace(id,`](/docs/$1$2)`)).join(``)}function od(e){let t=[],n=e;for(;;){let e=nd.exec(n);if(!e||e.index===void 0)return t.push(ad(n)),t.join(``);t.push(ad(n.slice(0,e.index)),e[0]),n=n.slice(e.index+e[0].length)}}function sd({breadcrumb:e,children:t}){return(0,Q.jsxs)(`div`,{className:`min-h-full`,children:[(0,Q.jsx)(`header`,{className:`sticky top-0 z-10 border-b border-border bg-background/80 backdrop-blur supports-[backdrop-filter]:bg-background/60`,children:(0,Q.jsxs)(`div`,{className:`mx-auto flex max-w-3xl items-center gap-2 px-4 py-3 sm:px-6`,children:[(0,Q.jsxs)(m,{to:`/docs`,className:`flex items-center gap-2 text-sm font-semibold hover:opacity-80`,children:[(0,Q.jsx)(Xe,{className:`h-4 w-4 text-muted-foreground`}),(0,Q.jsx)(`span`,{children:`Documentation`})]}),e?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground/60`,"aria-hidden":!0,children:`/`}),(0,Q.jsx)(`span`,{className:`truncate text-sm text-muted-foreground`,children:e})]}):null]})}),t]})}var cd=t({default:()=>ld});function ld(){let{name:e,appName:t}=o(),n=_(),r=se(),{t:i}=H(),[a,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(`loading`),[u,d]=(0,Z.useState)(``);(0,Z.useEffect)(()=>{let n=!1;async function i(){if(!(!e||!r)){l(`loading`);try{let i=await r.getClient().meta.getItem(`doc`,e,t?{packageId:t}:void 0),a=i?.item??i?.data??i;if(n)return;a&&typeof a.content==`string`?(s({name:e,label:a.label,content:a.content}),l(`ready`)):l(`missing`)}catch(e){if(n)return;(e?.status??e?.response?.status)===404||/not found/i.test(e?.message??``)?l(`missing`):(d(e?.message??`Failed to load documentation`),l(`error`))}}}return i(),()=>{n=!0}},[e,t,r]);let f=(0,Z.useCallback)(e=>{if(e.defaultPrevented||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||e.button!==0)return;let t=e.target.closest(`a`)?.getAttribute(`href`);t&&t.startsWith(`/docs/`)&&(e.preventDefault(),n(t))},[n]),p=(0,Z.useMemo)(()=>Aa(a?.content??``),[a?.content]),m=i(`help.onThisPage`,{defaultValue:`On this page`});return c===`loading`?(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-10 text-muted-foreground`,children:(0,Q.jsx)(q,{className:`h-5 w-5 animate-spin`,"aria-label":`Loading documentation`})}):c===`missing`?(0,Q.jsx)(sd,{breadcrumb:e,children:(0,Q.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col items-center gap-3 p-10 text-center`,children:[(0,Q.jsx)(Te,{className:`h-10 w-10 text-muted-foreground`}),(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Documentation not found`}),(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`No document named `,(0,Q.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5`,children:e}),` is installed. It may belong to a package that is not installed, or it was removed in a newer version.`]})]})}):c===`error`?(0,Q.jsx)(sd,{breadcrumb:e,children:(0,Q.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col items-center gap-3 p-10 text-center`,children:[(0,Q.jsx)(Ur,{className:`h-10 w-10 text-destructive`}),(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Failed to load documentation`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:u})]})}):(0,Q.jsx)(sd,{breadcrumb:a?.label??e,children:(0,Q.jsxs)(`div`,{className:`mx-auto flex max-w-5xl gap-8 p-4 sm:p-6`,children:[(0,Q.jsx)(`article`,{className:`min-w-0 max-w-3xl flex-1 [&_h1]:scroll-mt-24 [&_h2]:scroll-mt-24 [&_h3]:scroll-mt-24`,onClick:f,children:(0,Q.jsx)(ja,{schema:{type:`markdown`,content:od(a?.content??``)}})}),p.length>=3?(0,Q.jsx)(`aside`,{className:`hidden xl:block w-56 shrink-0`,children:(0,Q.jsxs)(`nav`,{"aria-label":m,className:`sticky top-20 max-h-[calc(100vh-6rem)] overflow-auto`,children:[(0,Q.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:m}),(0,Q.jsx)(`ul`,{className:`border-l border-border text-sm`,children:p.map(e=>(0,Q.jsx)(`li`,{style:{paddingLeft:(e.depth-2)*12},children:(0,Q.jsx)(`a`,{href:`#${e.id}`,className:`-ml-px block border-l border-transparent py-0.5 pl-3 text-muted-foreground hover:border-primary hover:text-foreground`,children:e.text})},e.id))})]})}):null]})})}function ud(e){let t=new Map;for(let n of e){if(!n||typeof n.name!=`string`||!n.name)continue;let e=n.name.indexOf(`_`),r=e>0?n.name.slice(0,e):n.name,i=t.get(r);i?i.push(n):t.set(r,[n])}return Array.from(t.keys()).sort((e,t)=>e.localeCompare(t)).map(e=>({pkg:e,docs:t.get(e).slice().sort((e,t)=>(e.label??e.name).localeCompare(t.label??t.name))}))}function dd(){let e=se(),[t,n]=(0,Z.useState)([]),[r,i]=(0,Z.useState)(`loading`),[a,o]=(0,Z.useState)(``);return(0,Z.useEffect)(()=>{let t=!1;async function r(){if(!e)return;let r=e.getClient();if(!r?.meta?.getItems){o(`meta.getItems is not available on this client`),i(`error`);return}i(`loading`);try{let e=await r.meta.getItems(`doc`),a=Array.isArray(e)?e:Array.isArray(e?.items)?e.items:Array.isArray(e?.value)?e.value:[];if(t)return;n(ud(a.map(e=>({name:e?.name,label:e?.label,description:e?.description,packageId:e?._packageId})))),i(`ready`)}catch(e){if(t)return;o(e?.message??`Failed to load documentation`),i(`error`)}}return r(),()=>{t=!0}},[e]),r===`loading`?(0,Q.jsx)(`div`,{className:`flex h-full items-center justify-center p-10 text-muted-foreground`,children:(0,Q.jsx)(q,{className:`h-5 w-5 animate-spin`,"aria-label":`Loading documentation`})}):r===`error`?(0,Q.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col items-center gap-3 p-10 text-center`,children:[(0,Q.jsx)(Ur,{className:`h-10 w-10 text-destructive`}),(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Failed to load documentation`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:a})]}):(0,Q.jsx)(sd,{children:(0,Q.jsx)(`div`,{className:`mx-auto max-w-3xl p-4 sm:p-6`,children:t.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-16 text-center text-muted-foreground`,children:[(0,Q.jsx)(Xe,{className:`h-10 w-10`}),(0,Q.jsxs)(`p`,{className:`text-sm`,children:[`No documentation is installed. Packages ship docs as flat`,(0,Q.jsx)(`code`,{className:`mx-1 rounded bg-muted px-1 py-0.5`,children:`src/docs/*.md`}),`files (ADR-0046).`]})]}):(0,Q.jsx)(`div`,{className:`space-y-8`,children:t.map(e=>(0,Q.jsxs)(`section`,{children:[(0,Q.jsx)(`h2`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:e.pkg}),(0,Q.jsx)(`ul`,{className:`divide-y divide-border rounded-md border border-border`,children:e.docs.map(e=>(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(m,{to:e.packageId?`/apps/${e.packageId}/docs/${e.name}`:`/docs/${e.name}`,className:`flex items-start gap-3 px-3 py-3 hover:bg-muted/50`,children:[(0,Q.jsx)(Xe,{className:`mt-0.5 h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium`,children:e.label??e.name}),e.description?(0,Q.jsx)(`div`,{className:`mt-0.5 line-clamp-2 text-xs text-muted-foreground`,children:e.description}):null]})]})},e.name))})]},e.pkg))})})})}function fd(e){let t=e.split(`:`)[0].toLowerCase();return/^cloud\./.test(t)}function pd(e){let t=e.split(`:`)[0].toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.local`)}function md(){return typeof window>`u`?null:window.location.host||null}function hd(){let e=sa();return(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 select-none`,children:[(0,Q.jsx)(`span`,{className:`inline-flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br from-indigo-500 to-indigo-600 text-white shadow-sm shadow-indigo-500/30`,children:(0,Q.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,Q.jsx)(`path`,{d:`M12 2 2 7l10 5 10-5-10-5Z`}),(0,Q.jsx)(`path`,{d:`m2 17 10 5 10-5`}),(0,Q.jsx)(`path`,{d:`m2 12 10 5 10-5`})]})}),(0,Q.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-foreground`,children:e})]})}function gd({children:e,formWidth:t=`sm`}){let{t:n}=H(),r=t===`md`?`max-w-md`:`max-w-sm`,i=md(),a=!!i&&!fd(i)&&!pd(i);return(0,Z.useEffect)(()=>{if(typeof document>`u`||!i)return;let e=document.title;return a&&(document.title=i),()=>{document.title=e}},[i,a]),(0,Q.jsxs)(`div`,{className:`relative flex min-h-svh w-full items-center justify-center overflow-hidden bg-background p-6`,children:[(0,Q.jsxs)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 -z-10`,children:[(0,Q.jsx)(`div`,{className:`absolute inset-0 opacity-[0.35] dark:opacity-[0.25] [mask-image:radial-gradient(ellipse_at_center,black,transparent_72%)] [-webkit-mask-image:radial-gradient(ellipse_at_center,black,transparent_72%)]`,style:{backgroundImage:`radial-gradient(hsl(var(--border)) 1px, transparent 1px)`,backgroundSize:`22px 22px`}}),(0,Q.jsx)(`div`,{className:`absolute left-1/2 top-1/2 h-[34rem] w-[34rem] -translate-x-1/2 -translate-y-1/2 rounded-full bg-gradient-to-br from-indigo-500/10 to-indigo-600/10 blur-3xl dark:from-indigo-500/10 dark:to-indigo-600/10`})]}),(0,Q.jsxs)(`div`,{className:yn(`flex w-full flex-col gap-5`,r),children:[(0,Q.jsx)(hd,{}),a?(0,Q.jsx)(`div`,{className:`flex justify-center`,children:(0,Q.jsx)(`span`,{className:`rounded-full border border-border/60 bg-background/60 px-2 py-0.5 font-mono text-[10px] uppercase tracking-wide text-muted-foreground`,title:n(`auth.shell.tenantHostHint`,{defaultValue:`You are signing in to this workspace`}),children:i})}):null,e]})]})}function _d(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function vd(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function yd(e){return(0,Q.jsx)(m,{to:e.href,className:e.className,children:e.children})}function bd(){let{t:e}=H(),[t]=p(),n=t.get(`redirect`),{user:r,isLoading:i,organizations:a,isOrganizationsLoading:o,activeOrganization:s,switchOrganization:c,getAuthConfig:l}=x(),[u,d]=(0,Z.useState)(!1),[f,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(!1);(0,Z.useLayoutEffect)(()=>{i||g(!0)},[i]);let _=(0,Z.useMemo)(()=>{if(typeof window>`u`)return null;let e=new URLSearchParams(window.location.search),t=e.get(`redirect_uri`);if(!e.has(`client_id`)||!t)return null;try{return new URL(t).host}catch{return null}},[]);if((0,Z.useEffect)(()=>{let e=!1;return l().then(t=>{e||d(t?.emailPassword?.disableSignUp===!0)}).catch(()=>{}),()=>{e=!0}},[l]),(0,Z.useEffect)(()=>{if(r){if(typeof window<`u`){let e=new URLSearchParams(window.location.search);if(e.has(`client_id`)&&e.has(`redirect_uri`)){window.location.assign(`/api/v1/auth/oauth2/authorize${window.location.search}`);return}}if(!s){if(o||f)return;if(a.length===1){m(!0),c(a[0].id).catch(()=>void 0).finally(()=>m(!1));return}if(a.length===0){window.location.assign(vd(_d(n)?n:`/`));return}window.location.assign(vd(`/organizations`));return}f||window.location.assign(vd(_d(n)?n:`/`))}},[r,s,a,o,f,n,c]),i&&!h||r)return(0,Q.jsx)(gd,{children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:[(0,Q.jsx)(`div`,{className:`size-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent`}),(0,Q.jsx)(`span`,{children:e(`auth.login.signingIn`,{defaultValue:`Signing you in…`})})]})});let v=n?`/register?redirect=${encodeURIComponent(n)}`:`/register`;return(0,Q.jsx)(gd,{formWidth:`md`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[_?(0,Q.jsxs)(`div`,{role:`status`,className:`flex items-start gap-3 rounded-md border border-primary/30 bg-primary/5 px-4 py-3 text-sm text-foreground`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 inline-block size-2 shrink-0 rounded-full bg-primary`}),(0,Q.jsx)(`span`,{children:e(`auth.login.ssoHandoff`,{target:_,defaultValue:`Continue to ${_}`})})]}):null,(0,Q.jsx)(mr,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Q.jsx)(xd,{registerUrl:u?void 0:v,redirect:n})})]})})}function xd({registerUrl:e,redirect:t}){let{t:n}=H(),r=_(),i=(0,Z.useRef)(``);return(0,Z.useEffect)(()=>{let e=e=>{let t=e.target;t?.id===`login-email`&&(i.current=t.value)};return document.addEventListener(`input`,e,!0),()=>document.removeEventListener(`input`,e,!0)},[]),(0,Q.jsx)(C,{onError:e=>{let n=e.message||``,a=e.code,o=n.toLowerCase();if(a===`EMAIL_NOT_VERIFIED`||o.includes(`email`)&&(o.includes(`verif`)||o.includes(`not verified`))){let e=new URLSearchParams;i.current&&e.set(`email`,i.current),t&&e.set(`redirect`,t),r(`/verify-email-prompt?${e.toString()}`)}},title:n(`auth.login.title`,{defaultValue:`Sign in to your account`}),description:n(`auth.login.description`,{defaultValue:`Enter your email and password to continue`}),registerUrl:e,forgotPasswordUrl:`/forgot-password`,linkComponent:yd,errorMessages:{INVALID_EMAIL_OR_PASSWORD:n(`auth.login.errors.invalidCredentials`,{defaultValue:`Invalid email or password`}),EMAIL_NOT_VERIFIED:n(`auth.login.errors.emailNotVerified`,{defaultValue:`Please verify your email address before signing in.`})},labels:{emailLabel:n(`auth.login.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:n(`auth.login.emailPlaceholder`,{defaultValue:`name@example.com`}),passwordLabel:n(`auth.login.passwordLabel`,{defaultValue:`Password`}),passwordPlaceholder:n(`auth.login.passwordPlaceholder`,{defaultValue:`Enter your password`}),forgotPasswordText:n(`auth.login.forgotPasswordText`,{defaultValue:`Forgot password?`}),submitButton:n(`auth.login.submitButton`,{defaultValue:`Sign In`}),submittingButton:n(`auth.login.submittingButton`,{defaultValue:`Signing in…`}),noAccountText:n(`auth.login.noAccountText`,{defaultValue:`Don't have an account?`}),signUpText:n(`auth.login.signUpText`,{defaultValue:`Sign up`})}})}function Sd(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function Cd(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function wd(e){return(0,Q.jsx)(m,{to:e.href,className:e.className,children:e.children})}function Td(){let{t:e}=H(),t=_(),[n]=p(),r=n.get(`redirect`),{user:i,isLoading:a,organizations:o,isOrganizationsLoading:s,activeOrganization:c,switchOrganization:l,getAuthConfig:u}=x(),[d,f]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),[g,v]=(0,Z.useState)(!1);if((0,Z.useLayoutEffect)(()=>{a||v(!0)},[a]),(0,Z.useEffect)(()=>{let e=!1;return u().then(n=>{if(e)return;let i=n?.emailPassword?.disableSignUp===!0;f(i),i&&t(`/login${r?`?redirect=${encodeURIComponent(r)}`:``}`,{replace:!0})}).catch(()=>{e||f(!1)}),()=>{e=!0}},[u,t,r]),(0,Z.useEffect)(()=>{if(i){if(typeof window<`u`){let e=new URLSearchParams(window.location.search);if(e.has(`client_id`)&&e.has(`redirect_uri`)){window.location.assign(`/api/v1/auth/oauth2/authorize${window.location.search}`);return}}if(!c){if(s||m)return;if(o.length===1){h(!0),l(o[0].id).catch(()=>void 0).finally(()=>h(!1));return}if(o.length===0){window.location.assign(Cd(Sd(r)?r:`/`));return}window.location.assign(Cd(`/organizations`));return}m||window.location.assign(Cd(Sd(r)?r:`/`))}},[i,c,o,s,m,r,l]),d===null||a&&!g||i)return(0,Q.jsx)(gd,{children:(0,Q.jsx)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:(0,Q.jsx)(`div`,{className:`size-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent`})})});let b=r?`/login?redirect=${encodeURIComponent(r)}`:`/login`;return(0,Q.jsx)(gd,{formWidth:`md`,children:(0,Q.jsx)(mr,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Q.jsx)(y,{title:e(`auth.register.title`,{defaultValue:`Create your account`}),description:e(`auth.register.description`,{defaultValue:`Sign up to get started`}),loginUrl:b,linkComponent:wd,errorMessages:{USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:e(`auth.register.errors.userExists`,{defaultValue:`An account with this email already exists. Try signing in instead.`}),USER_ALREADY_EXISTS:e(`auth.register.errors.userExists`,{defaultValue:`An account with this email already exists. Try signing in instead.`})},onVerificationRequired:e=>{let n=new URLSearchParams;n.set(`email`,e),r&&n.set(`redirect`,r),t(`/verify-email-prompt?${n.toString()}`,{replace:!0})},labels:{nameLabel:e(`auth.register.nameLabel`,{defaultValue:`Name`}),namePlaceholder:e(`auth.register.namePlaceholder`,{defaultValue:`John Doe`}),emailLabel:e(`auth.register.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:e(`auth.register.emailPlaceholder`,{defaultValue:`name@example.com`}),passwordLabel:e(`auth.register.passwordLabel`,{defaultValue:`Password`}),passwordPlaceholder:e(`auth.register.passwordPlaceholder`,{defaultValue:`Create a password (min. 8 characters)`}),confirmPasswordLabel:e(`auth.register.confirmPasswordLabel`,{defaultValue:`Confirm password`}),confirmPasswordPlaceholder:e(`auth.register.confirmPasswordPlaceholder`,{defaultValue:`Confirm your password`}),passwordMismatchError:e(`auth.register.passwordMismatchError`,{defaultValue:`Passwords do not match`}),passwordTooShortError:e(`auth.register.passwordTooShortError`,{defaultValue:`Password must be at least 8 characters`}),submitButton:e(`auth.register.submitButton`,{defaultValue:`Create account`}),submittingButton:e(`auth.register.submittingButton`,{defaultValue:`Creating account…`}),hasAccountText:e(`auth.register.hasAccountText`,{defaultValue:`Already have an account?`}),signInText:e(`auth.register.signInText`,{defaultValue:`Sign in`})}})})})}function Ed(e){return(0,Q.jsx)(m,{to:e.href,className:e.className,children:e.children})}function Dd(){let{t:e}=H();return(0,Q.jsx)(gd,{formWidth:`md`,children:(0,Q.jsx)(mr,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,Q.jsx)(O,{loginUrl:`/login`,linkComponent:Ed,title:e(`auth.forgotPassword.title`,{defaultValue:`Reset your password`}),description:e(`auth.forgotPassword.description`,{defaultValue:`Enter your email and we'll send you a reset link.`}),labels:{emailLabel:e(`auth.forgotPassword.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:e(`auth.forgotPassword.emailPlaceholder`,{defaultValue:`name@example.com`}),submitButton:e(`auth.forgotPassword.submitButton`,{defaultValue:`Send reset link`}),submittingButton:e(`auth.forgotPassword.submittingButton`,{defaultValue:`Sending…`}),successTitle:e(`auth.forgotPassword.successTitle`,{defaultValue:`Check your email`}),successDescription:e(`auth.forgotPassword.successDescription`,{defaultValue:`If an account exists, a reset link has been sent.`}),backToSignInText:e(`auth.forgotPassword.backToSignInText`,{defaultValue:`Back to sign in`}),rememberPasswordText:e(`auth.forgotPassword.rememberPasswordText`,{defaultValue:`Remember your password?`}),signInText:e(`auth.forgotPassword.signInText`,{defaultValue:`Sign in`})}})})})}function Od(){let{t:e}=H(),t=_(),[n]=p(),r=n.get(`token`),{resetPassword:i}=x(),[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(!1);return(0,Q.jsx)(gd,{children:(0,Q.jsxs)(mr,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(Jt,{className:`text-xl tracking-tight`,children:e(`auth.resetPassword.title`,{defaultValue:`Set a new password`})}),(0,Q.jsx)(Kt,{children:e(`auth.resetPassword.description`,{defaultValue:`Choose a password you have not used before.`})})]}),(0,Q.jsx)(qe,{children:r?(0,Q.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),a!==s){X.error(e(`auth.resetPassword.passwordsMismatch`,{defaultValue:`Passwords do not match`}));return}if(!r){X.error(e(`auth.resetPassword.missingToken`,{defaultValue:`Reset link is missing or expired`}));return}u(!0);try{await i(r,a),X.success(e(`auth.resetPassword.success`,{defaultValue:`Password updated`})),t(`/login`)}catch(t){X.error(e(`auth.resetPassword.failed`,{defaultValue:`Reset failed`}),{description:t.message})}finally{u(!1)}},className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`new-password`,children:e(`auth.resetPassword.newPassword`,{defaultValue:`New password`})}),(0,Q.jsx)(Y,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:a,onChange:e=>o(e.target.value)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`confirm-password`,children:e(`auth.resetPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,Q.jsx)(Y,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:s,onChange:e=>c(e.target.value)})]}),(0,Q.jsx)(J,{type:`submit`,className:`w-full`,disabled:l,children:l?e(`auth.resetPassword.submitting`,{defaultValue:`Updating…`}):e(`auth.resetPassword.submit`,{defaultValue:`Update password`})})]}):(0,Q.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.resetPassword.invalidToken`,{defaultValue:`This reset link is invalid or has expired.`}),` `,(0,Q.jsx)(m,{to:`/forgot-password`,className:`font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.resetPassword.requestNewLink`,{defaultValue:`Request a new link`})})]})})]})})}function kd(e){return e&&e.startsWith(`/`)&&!e.startsWith(`//`)?e:`/`}function Ad(){let{t:e}=H(),t=_(),[n]=p(),r=kd(n.get(`next`)),{user:i,isLoading:a,setInitialPassword:o}=x(),[s,c]=(0,Z.useState)(``),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(!1);return(0,Q.jsx)(gd,{children:(0,Q.jsxs)(mr,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(Jt,{className:`text-xl tracking-tight`,children:e(`auth.setPassword.title`,{defaultValue:`Set a recovery password`})}),(0,Q.jsx)(Kt,{children:e(`auth.setPassword.description`,{defaultValue:`You signed in via single sign-on. Set a local password so you can still sign in to this environment directly if SSO ever becomes unavailable.`})})]}),(0,Q.jsx)(qe,{children:!a&&!i?(0,Q.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.setPassword.noSession`,{defaultValue:`Your session has expired.`}),` `,(0,Q.jsx)(m,{to:`/login`,className:`font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.setPassword.backToSignIn`,{defaultValue:`Sign in again`})})]}):(0,Q.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),s!==l){X.error(e(`auth.setPassword.passwordsMismatch`,{defaultValue:`Passwords do not match`}));return}f(!0);try{await o(s),X.success(e(`auth.setPassword.success`,{defaultValue:`Local password set`})),t(r)}catch(t){X.error(e(`auth.setPassword.failed`,{defaultValue:`Could not set password`}),{description:t.message})}finally{f(!1)}},className:`flex flex-col gap-4`,children:[i?.email?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`set-password-email`,children:e(`auth.setPassword.email`,{defaultValue:`Email`})}),(0,Q.jsx)(Y,{id:`set-password-email`,type:`email`,autoComplete:`username`,value:i.email,disabled:!0,className:`bg-muted text-muted-foreground`})]}):null,(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`new-password`,children:e(`auth.setPassword.newPassword`,{defaultValue:`New password`})}),(0,Q.jsx)(Y,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:s,onChange:e=>c(e.target.value)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`confirm-password`,children:e(`auth.setPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,Q.jsx)(Y,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:l,onChange:e=>u(e.target.value)})]}),(0,Q.jsx)(J,{type:`submit`,className:`w-full`,disabled:d,children:d?e(`auth.setPassword.submitting`,{defaultValue:`Saving…`}):e(`auth.setPassword.submit`,{defaultValue:`Set password`})})]})})]})})}var jd=`/api/v1/auth`;function Md(){let{t:e}=H(),[t]=p(),n=t.get(`token`),[r,i]=(0,Z.useState)(`loading`),[a,o]=(0,Z.useState)(``);return(0,Z.useEffect)(()=>{if(!n){i(`error`),o(e(`auth.verifyEmail.missingToken`,{defaultValue:`Verification link is missing a token.`}));return}let t=!1;return(async()=>{try{let e=await fetch(`${jd}/verify-email`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({token:n})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t?.message||`Verification failed: ${e.status}`)}t||i(`success`)}catch(n){t||(i(`error`),o(n.message||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})))}})(),()=>{t=!0}},[n,e]),(0,Q.jsx)(gd,{children:(0,Q.jsxs)(mr,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[r===`loading`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(Jt,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.verifyingTitle`,{defaultValue:`Verifying…`})}),(0,Q.jsx)(Kt,{children:e(`auth.verifyEmail.verifyingDescription`,{defaultValue:`Hang tight while we confirm your email.`})})]}),(0,Q.jsx)(qe,{className:`flex justify-center py-6`,children:(0,Q.jsx)(`div`,{className:`h-10 w-10 animate-spin rounded-full border-4 border-muted border-t-primary`})})]}),r===`success`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(`div`,{className:`mx-auto mb-2 flex size-12 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-500 ring-1 ring-emerald-500/30`,children:(0,Q.jsx)(Fn,{className:`size-6`})}),(0,Q.jsx)(Jt,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.successTitle`,{defaultValue:`Email verified`})}),(0,Q.jsx)(Kt,{children:e(`auth.verifyEmail.successDescription`,{defaultValue:`Your email is confirmed. You can now sign in.`})})]}),(0,Q.jsx)(qe,{className:`text-center`,children:(0,Q.jsx)(m,{to:`/login`,className:`text-sm font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.verifyEmail.signInLink`,{defaultValue:`Go to sign in`})})})]}),r===`error`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(`div`,{className:`mx-auto mb-2 flex size-12 items-center justify-center rounded-full bg-destructive/10 text-destructive ring-1 ring-destructive/30`,children:(0,Q.jsx)(_n,{className:`size-6`})}),(0,Q.jsx)(Jt,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.errorTitle`,{defaultValue:`Verification failed`})}),(0,Q.jsx)(Kt,{children:a||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})})]}),(0,Q.jsx)(qe,{className:`text-center`,children:(0,Q.jsx)(m,{to:`/login`,className:`text-sm font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.verifyEmail.backToSignIn`,{defaultValue:`Back to sign in`})})})]})]})})}function Nd(){let{t:e}=H(),t=_(),[n]=p(),r=n.get(`email`)??``,i=n.get(`redirect`)??``,{sendVerificationEmail:a}=x(),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1);return(0,Q.jsx)(gd,{children:(0,Q.jsxs)(mr,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(`div`,{className:`mx-auto mb-4 flex size-16 items-center justify-center rounded-full bg-primary/10`,children:(0,Q.jsx)(Kn,{className:`size-8 text-primary`})}),(0,Q.jsx)(Jt,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.title`,{defaultValue:`Verify your email address`})}),(0,Q.jsx)(Kt,{children:e(`auth.verifyEmail.description`,{defaultValue:`We sent a verification link to your email address. Please click the link to verify your account.`})})]}),(0,Q.jsx)(qe,{children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r?(0,Q.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.verifyEmail.sentTo`,{defaultValue:`Sent to:`}),` `,(0,Q.jsx)(`span`,{className:`font-medium text-foreground`,children:r})]}):null,(0,Q.jsx)(J,{onClick:async()=>{if(!r){X.error(e(`auth.verifyEmail.resendFailed`,{defaultValue:`Cannot resend verification email`}),{description:e(`auth.verifyEmail.emailMissing`,{defaultValue:`Email address is missing`})});return}s(!0);try{await a(r,i||`/`),l(!0),X.success(e(`auth.verifyEmail.resentSuccess`,{defaultValue:`Verification email sent!`}),{description:e(`auth.verifyEmail.resentDescription`,{defaultValue:`Please check your inbox and click the verification link.`})})}catch(t){X.error(e(`auth.verifyEmail.resendFailed`,{defaultValue:`Failed to resend verification email`}),{description:t.message})}finally{s(!1)}},disabled:o||c,className:`w-full`,variant:c?`outline`:`default`,children:o?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(De,{className:`mr-2 size-4 animate-spin`}),e(`auth.verifyEmail.resending`,{defaultValue:`Sending…`})]}):c?e(`auth.verifyEmail.resent`,{defaultValue:`Email sent! Check your inbox`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(De,{className:`mr-2 size-4`}),e(`auth.verifyEmail.resendButton`,{defaultValue:`Resend verification email`})]})}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,Q.jsx)(`span`,{className:`w-full border-t`})}),(0,Q.jsx)(`div`,{className:`relative flex justify-center text-xs uppercase`,children:(0,Q.jsx)(`span`,{className:`bg-card px-2 text-muted-foreground`,children:e(`auth.verifyEmail.or`,{defaultValue:`Or`})})})]}),(0,Q.jsx)(J,{onClick:()=>{t(`/login${i?`?redirect=${encodeURIComponent(i)}`:``}`)},variant:`ghost`,className:`w-full`,children:e(`auth.verifyEmail.backToLogin`,{defaultValue:`Back to login`})}),(0,Q.jsx)(`p`,{className:`text-center text-xs text-muted-foreground`,children:e(`auth.verifyEmail.checkSpam`,{defaultValue:`Didn't receive the email? Check your spam folder or contact support.`})})]})})]})})}var Pd=`/api/v1/auth`;function Fd(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function Id(){let{t:e}=H(),t=_(),{user:n,signUp:r,organizations:i,refreshOrganizations:a,updateOrganization:o,createOrganization:s,switchOrganization:c}=x(),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(``),[v,y]=(0,Z.useState)(!1),[b,S]=(0,Z.useState)(null);return(0,Z.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await fetch(`${Pd}/bootstrap-status`,{credentials:`include`}),n=t.ok?await t.json().catch(()=>({})):{};e||S(n.hasOwner===!0)}catch{e||S(!1)}})(),()=>{e=!0}},[]),(0,Z.useEffect)(()=>{b===!0&&!n&&t(`/login`,{replace:!0})},[b,n,t]),(0,Z.useEffect)(()=>{n&&window.location.assign(`/`)},[n]),b===null?(0,Q.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted`,children:(0,Q.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-muted-foreground/20 border-t-primary`})}):(0,Q.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted p-6`,children:(0,Q.jsx)(`div`,{className:`flex w-full max-w-md flex-col gap-6`,children:(0,Q.jsxs)(mr,{children:[(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(Jt,{children:e(`auth.setup.welcomeTitle`,{defaultValue:`Welcome to ObjectStack`})}),(0,Q.jsx)(Kt,{children:e(`auth.setup.description`,{defaultValue:`Create the first owner account to finish setting up this deployment.`})})]}),(0,Q.jsx)(qe,{children:(0,Q.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),y(!0);try{await r(l,d,p);let e=h.trim();if(e)try{await a();let t=i[0],n;t?.id?(await o(t.id,{name:e,slug:Fd(e)}),n=t.id):n=(await s({name:e,slug:Fd(e)}))?.id,n&&await c(n).catch(()=>void 0)}catch(e){console.warn(`[setup] organization rename/create failed`,e)}window.location.assign(`/`)}catch(t){X.error(e(`auth.setup.failed`,{defaultValue:`Setup failed`}),{description:t.message})}finally{y(!1)}},className:`flex flex-col gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`name`,children:e(`auth.setup.yourName`,{defaultValue:`Your name`})}),(0,Q.jsx)(Y,{id:`name`,autoComplete:`name`,required:!0,value:l,onChange:e=>u(e.target.value)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`orgName`,children:e(`auth.setup.orgName`,{defaultValue:`Organization name`})}),(0,Q.jsx)(Y,{id:`orgName`,required:!0,placeholder:e(`auth.setup.orgNamePlaceholder`,{defaultValue:`Acme Inc.`}),value:h,onChange:e=>g(e.target.value)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`email`,children:e(`auth.setup.emailLabel`,{defaultValue:`Email`})}),(0,Q.jsx)(Y,{id:`email`,type:`email`,placeholder:e(`auth.setup.emailPlaceholder`,{defaultValue:`name@example.com`}),autoComplete:`email`,required:!0,value:d,onChange:e=>f(e.target.value)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(ur,{htmlFor:`password`,children:e(`auth.setup.passwordLabel`,{defaultValue:`Password`})}),(0,Q.jsx)(Y,{id:`password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,placeholder:e(`auth.setup.passwordHint`,{defaultValue:`Minimum 8 characters`}),value:p,onChange:e=>m(e.target.value)})]}),(0,Q.jsx)(J,{type:`submit`,className:`mt-2 w-full`,disabled:v,children:v?e(`auth.setup.submitting`,{defaultValue:`Setting up…`}):e(`auth.setup.submit`,{defaultValue:`Create owner account`})})]})})]})})})}var Ld=`/api/v1/auth`;function Rd(){let{t:e}=H(),t=_(),{user:n,isLoading:r}=x(),[i,a]=(0,Z.useState)(!1),[o,s]=(0,Z.useState)(null),c=typeof window<`u`?window.location.search:``,l=c.startsWith(`?`)?c.slice(1):c,u=new URLSearchParams(l),d=u.get(`client_id`)??void 0,f=u.get(`scope`)??``;(0,Z.useEffect)(()=>{if(!r&&!n){let e=window.location.pathname+window.location.search;t(`/login?redirect=${encodeURIComponent(e)}`,{replace:!0})}},[n,r,t]),(0,Z.useEffect)(()=>{if(!d)return;let e=!1;return fetch(`${Ld}/oauth2/applications/${encodeURIComponent(d)}/public`,{credentials:`include`}).then(async t=>{if(!t.ok)return;let n=await t.json().catch(()=>({}));e||s(n?.data??n)}).catch(()=>{}),()=>{e=!0}},[d]);let p=f.split(/\s+/).filter(Boolean),m=async t=>{a(!0);try{let n=await fetch(`${Ld}/oauth2/consent`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({accept:t,oauth_query:l})}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r?.message||`Consent failed: ${n.status}`);let i=r.redirect_uri??r.redirectURI??r.url;if(i){window.location.href=i;return}X(t?e(`oauth.consent.granted`,{defaultValue:`Access granted`}):e(`oauth.consent.denied`,{defaultValue:`Access denied`}),{description:e(`oauth.consent.noRedirect`,{defaultValue:`No redirect URL returned by the server.`})})}catch(t){X.error(e(`oauth.consent.failed`,{defaultValue:`Consent failed`}),{description:t.message})}finally{a(!1)}},h=o?.name??o?.client_name??d??e(`oauth.consent.unknownApp`,{defaultValue:`an application`});return(0,Q.jsx)(`div`,{className:`flex min-h-svh w-full flex-1 items-center justify-center bg-background px-4`,children:(0,Q.jsxs)(mr,{className:`w-full max-w-md`,children:[(0,Q.jsxs)(Gt,{className:`items-center text-center`,children:[(0,Q.jsx)(`div`,{className:`mb-3 rounded-full border bg-muted p-3`,children:o?.icon||o?.logo_uri?(0,Q.jsx)(`img`,{src:o.icon||o.logo_uri,alt:``,className:`h-8 w-8 rounded`,onError:e=>{e.currentTarget.style.display=`none`}}):(0,Q.jsx)(Ye,{className:`h-7 w-7 text-muted-foreground`})}),(0,Q.jsx)(Jt,{className:`text-xl`,children:e(`oauth.consent.title`,{appName:h,defaultValue:`${h} wants to access your account`})}),(0,Q.jsx)(Kt,{children:e(`oauth.consent.request`,{appName:h,suffix:n?.email?` (${n.email})`:``,defaultValue:`${h} is requesting permission${n?.email?` for ${n.email}`:``}.`})})]}),(0,Q.jsxs)(qe,{className:`space-y-4`,children:[p.length>0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:e(`oauth.consent.willAllow`,{defaultValue:`This app will be able to:`})}),(0,Q.jsx)(`ul`,{className:`space-y-1.5 rounded-md border bg-muted/40 p-3 text-sm`,children:p.map(t=>(0,Q.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(Ee,{className:`mt-0.5 h-4 w-4 text-green-600 dark:text-green-400`}),(0,Q.jsx)(`span`,{children:zd(t,e)})]},t))})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-2`,children:[(0,Q.jsxs)(J,{variant:`outline`,onClick:()=>m(!1),disabled:i,children:[(0,Q.jsx)(Et,{className:`mr-2 h-4 w-4`}),e(`oauth.consent.deny`,{defaultValue:`Deny`})]}),(0,Q.jsxs)(J,{onClick:()=>m(!0),disabled:i,children:[(0,Q.jsx)(Ee,{className:`mr-2 h-4 w-4`}),i?e(`oauth.consent.submitting`,{defaultValue:`Authorizing…`}):e(`oauth.consent.authorize`,{defaultValue:`Authorize`})]})]}),(0,Q.jsx)(`p`,{className:`pt-2 text-center text-xs text-muted-foreground`,children:e(`oauth.consent.footer`,{defaultValue:`You can revoke access at any time from your account settings.`})})]})]})})}function zd(e,t){switch(e){case`openid`:return t(`oauth.consent.scope.openid`,{defaultValue:`Confirm your identity`});case`profile`:return t(`oauth.consent.scope.profile`,{defaultValue:`Read your basic profile (name, picture)`});case`email`:return t(`oauth.consent.scope.email`,{defaultValue:`Read your email address`});case`offline_access`:return t(`oauth.consent.scope.offlineAccess`,{defaultValue:`Stay signed in (refresh access)`});default:return e}}var Bd=`/api/v1/auth`;function Vd({children:e}){return(0,Q.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center gap-6 bg-muted p-6 md:p-10`,children:(0,Q.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col gap-6`,children:[(0,Q.jsxs)(`a`,{href:`#`,className:`flex items-center gap-2 self-center font-medium`,children:[(0,Q.jsx)(`div`,{className:`flex size-6 items-center justify-center rounded-md bg-primary text-primary-foreground`,children:(0,Q.jsx)(Sn,{className:`size-4`})}),`ObjectStack`]}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-6`,children:e})]})})}function Hd(){let{t:e}=H(),t=l(),[n]=p(),i=n.get(`user_code`)??n.get(`code`)??``,a=n.get(`runtime_name`)??``,o=n.get(`runtime_version`)??``,{user:s,isLoading:c}=x(),u=_(),[d,f]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(!1),[g,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(``);if(!i)return(0,Q.jsx)(Vd,{children:(0,Q.jsx)(mr,{children:(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(Jt,{children:e(`auth.device.invalidTitle`,{defaultValue:`Invalid device link`})}),(0,Q.jsx)(Kt,{children:e(`auth.device.invalidDescription`,{defaultValue:`No device code was provided in the URL.`})})]})})});if(c)return(0,Q.jsx)(Vd,{children:(0,Q.jsx)(mr,{children:(0,Q.jsx)(Gt,{className:`text-center`,children:(0,Q.jsx)(Kt,{children:e(`auth.device.loading`,{defaultValue:`Loading…`})})})})});if(!s)return(0,Q.jsx)(r,{to:`/login?redirect=${encodeURIComponent(`/auth/device${t.search}`)}`,replace:!0});if(g)return(0,Q.jsx)(Vd,{children:(0,Q.jsx)(mr,{children:(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(Fn,{className:`mx-auto mb-2 h-10 w-10 text-green-500`}),(0,Q.jsx)(Jt,{children:e(`auth.device.approvedTitle`,{defaultValue:`Device authorized`})}),(0,Q.jsx)(Kt,{children:e(`auth.device.approvedDescription`,{defaultValue:`You can return to the device — it should sign in shortly.`})})]})})});if(y)return(0,Q.jsx)(Vd,{children:(0,Q.jsx)(mr,{children:(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(Jt,{children:e(`auth.device.deniedTitle`,{defaultValue:`Access denied`})}),(0,Q.jsx)(Kt,{children:e(`auth.device.deniedDescription`,{defaultValue:`The device will not be granted access.`})})]})})});let w=async()=>{await fetch(`${Bd}/device?user_code=${encodeURIComponent(i)}`,{credentials:`include`}).catch(()=>{})};return(0,Q.jsx)(Vd,{children:(0,Q.jsxs)(mr,{children:[(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(Jt,{children:e(`auth.device.title`,{defaultValue:`Authorize new device`})}),(0,Q.jsx)(Kt,{children:e(`auth.device.subtitle`,{email:s.email,defaultValue:`Approve this device to sign in as ${s.email}.`})})]}),(0,Q.jsxs)(qe,{className:`space-y-4`,children:[a?(0,Q.jsxs)(`div`,{className:`rounded-md border bg-background px-4 py-3 text-center`,children:[(0,Q.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e(`auth.device.requesterLabel`,{defaultValue:`Connection request from`})}),(0,Q.jsx)(`p`,{className:`font-medium`,children:a}),o?(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`objectos `,o]}):null]}):null,(0,Q.jsxs)(`div`,{className:`rounded-md border bg-background px-4 py-3 text-center`,children:[(0,Q.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e(`auth.device.userCodeLabel`,{defaultValue:`Device code`})}),(0,Q.jsx)(`p`,{className:`font-mono text-lg font-semibold tracking-widest`,children:i})]}),(0,Q.jsx)(`p`,{className:`text-center text-xs text-muted-foreground`,children:e(`auth.device.approveWarning`,{defaultValue:`Only approve if you started this connection yourself a moment ago. Once approved, this runtime can access your organization's private packages.`})}),(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(`p`,{className:`text-center text-sm text-muted-foreground`,children:e(`auth.device.loggedInAs`,{email:s.email,defaultValue:`Signed in as ${s.email}`})}),S&&(0,Q.jsx)(`p`,{className:`text-center text-sm text-destructive`,children:S}),(0,Q.jsx)(J,{onClick:async()=>{C(``),f(!0);try{await w();let t=await fetch(`${Bd}/device/approve`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({userCode:i})});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n?.message??n?.error?.message??e(`auth.device.approveFailed`,{defaultValue:`Approval failed`}))}v(!0),X.success(e(`auth.device.approveSuccess`,{defaultValue:`Device authorized`}),{description:e(`auth.device.approveSuccessDescription`,{defaultValue:`You can close this window.`})})}catch(t){C(t?.message??e(`auth.device.approveFailed`,{defaultValue:`Approval failed`}))}finally{f(!1)}},className:`w-full`,disabled:d||m,children:d?e(`auth.device.approving`,{defaultValue:`Approving…`}):e(`auth.device.approve`,{defaultValue:`Approve device`})}),(0,Q.jsx)(J,{onClick:async()=>{C(``),h(!0);try{await w(),await fetch(`${Bd}/device/deny`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({userCode:i})}),b(!0)}catch(t){C(t?.message??e(`auth.device.denyFailed`,{defaultValue:`Failed to deny request`}))}finally{h(!1)}},variant:`outline`,className:`w-full`,disabled:d||m,children:m?e(`auth.device.denying`,{defaultValue:`Denying…`}):e(`auth.device.deny`,{defaultValue:`Deny request`})}),(0,Q.jsx)(`div`,{className:`text-center`,children:(0,Q.jsx)(`button`,{type:`button`,className:`text-sm text-muted-foreground underline-offset-4 hover:underline`,onClick:()=>u(`/`),children:e(`auth.device.cancel`,{defaultValue:`Cancel`})})})]})]})]})})}function Ud(){let{t:e}=H(),{invitationId:t}=o(),n=_(),{user:r,isLoading:i,acceptInvitation:a,rejectInvitation:s,refreshOrganizations:c}=x(),[l,u]=(0,Z.useState)(!1),[d,f]=(0,Z.useState)(!1);return(0,Z.useEffect)(()=>{if(!i&&!r&&t){let e=`/accept-invitation/${t}`;n(`/login?redirect=${encodeURIComponent(e)}`,{replace:!0})}},[i,r,t,n]),t?(0,Q.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center gap-6 bg-muted p-6 md:p-10`,children:(0,Q.jsx)(`div`,{className:`flex w-full max-w-sm flex-col gap-6`,children:(0,Q.jsxs)(mr,{children:[(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(Jt,{className:`text-xl`,children:e(`acceptInvitation.title`,{defaultValue:`Accept organization invitation`})}),(0,Q.jsx)(Kt,{children:e(`acceptInvitation.description`,{defaultValue:`You've been invited to join an organization.`})})]}),(0,Q.jsxs)(qe,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(J,{className:`w-full`,onClick:async()=>{u(!0);try{await a(t),await c().catch(()=>void 0),X.success(e(`acceptInvitation.accepted`,{defaultValue:`Invitation accepted`})),n(`/organizations`)}catch(t){X.error(e(`acceptInvitation.acceptFailed`,{defaultValue:`Could not accept`}),{description:t.message})}finally{u(!1)}},disabled:l||d,children:l?e(`acceptInvitation.accepting`,{defaultValue:`Accepting…`}):e(`acceptInvitation.accept`,{defaultValue:`Accept invitation`})}),(0,Q.jsx)(J,{variant:`outline`,className:`w-full`,onClick:async()=>{f(!0);try{await s(t),X.success(e(`acceptInvitation.declined`,{defaultValue:`Invitation declined`})),n(`/organizations`)}catch(t){X.error(e(`acceptInvitation.declineFailed`,{defaultValue:`Could not decline`}),{description:t.message})}finally{f(!1)}},disabled:l||d,children:d?e(`acceptInvitation.declining`,{defaultValue:`Declining…`}):e(`acceptInvitation.decline`,{defaultValue:`Decline`})})]})]})})}):(0,Q.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center bg-muted p-6`,children:(0,Q.jsx)(mr,{className:`w-full max-w-sm`,children:(0,Q.jsxs)(Gt,{className:`text-center`,children:[(0,Q.jsx)(Jt,{className:`text-xl`,children:e(`acceptInvitation.invalidTitle`,{defaultValue:`Invalid invitation link`})}),(0,Q.jsx)(Kt,{children:e(`acceptInvitation.invalidDescription`,{defaultValue:`The invitation id is missing from the URL.`})})]})})})}var Wd=`/api/v1/auth`;function Gd(){try{if(typeof document>`u`)return`/`;let e=document.querySelector(`base`)?.getAttribute(`href`);return e&&new URL(e,window.location.origin).pathname.replace(/\/$/,``)||`/`}catch{return`/`}}var Kd=Gd();function qd(){let e=l(),t=e.pathname+e.search;return(0,Q.jsx)(r,{to:`/login${t&&t!==`/`?`?redirect=${encodeURIComponent(t)}`:``}`,replace:!0})}function Jd({children:e,requireOrganization:t=!0}){return(0,Q.jsx)(k,{fallback:(0,Q.jsx)(qd,{}),loadingFallback:(0,Q.jsx)(Ha,{}),children:(0,Q.jsx)(Wa,{children:t?(0,Q.jsx)(qa,{children:e}):e})})}function Yd(){let{user:e}=x();return(0,Q.jsx)(Wc,{userId:e?.id,children:(0,Q.jsx)(al,{})})}function Xd(){return(0,Q.jsxs)(E,{authUrl:Wd,children:[(0,Q.jsx)(Zo,{position:`bottom-right`}),(0,Q.jsx)(Qu,{}),(0,Q.jsx)(d,{basename:Kd,children:(0,Q.jsx)(Ua,{children:(0,Q.jsxs)(i,{children:[(0,Q.jsx)(h,{path:`/login`,element:(0,Q.jsx)(bd,{})}),(0,Q.jsx)(h,{path:`/register`,element:(0,Q.jsx)(Td,{})}),(0,Q.jsx)(h,{path:`/forgot-password`,element:(0,Q.jsx)(Dd,{})}),(0,Q.jsx)(h,{path:`/reset-password`,element:(0,Q.jsx)(Od,{})}),(0,Q.jsx)(h,{path:`/set-password`,element:(0,Q.jsx)(Ad,{})}),(0,Q.jsx)(h,{path:`/verify-email`,element:(0,Q.jsx)(Md,{})}),(0,Q.jsx)(h,{path:`/verify-email-prompt`,element:(0,Q.jsx)(Nd,{})}),(0,Q.jsx)(h,{path:`/setup`,element:(0,Q.jsx)(Id,{})}),(0,Q.jsx)(h,{path:`/oauth/consent`,element:(0,Q.jsx)(Rd,{})}),(0,Q.jsx)(h,{path:`/auth/device`,element:(0,Q.jsx)(Hd,{})}),(0,Q.jsx)(h,{path:`/accept-invitation/:invitationId`,element:(0,Q.jsx)(Ud,{})}),(0,Q.jsx)(h,{path:`/f/:slug`,element:(0,Q.jsx)(Zu,{mode:`public`})}),(0,Q.jsx)(h,{path:`/s/:token`,element:(0,Q.jsx)(td,{})}),(0,Q.jsx)(h,{path:`/forms/:name`,element:(0,Q.jsx)(Jd,{children:(0,Q.jsx)(Zu,{mode:`internal`})})}),(0,Q.jsx)(h,{path:`/docs`,element:(0,Q.jsx)(Jd,{children:(0,Q.jsx)(dd,{})})}),(0,Q.jsx)(h,{path:`/docs/:name`,element:(0,Q.jsx)(Jd,{children:(0,Q.jsx)(ld,{})})}),(0,Q.jsx)(h,{path:`/home`,element:(0,Q.jsx)(Jd,{children:(0,Q.jsx)(Yd,{})})}),(0,Q.jsx)(h,{path:`/dev/master-detail`,element:(0,Q.jsx)(Jd,{children:(0,Q.jsx)(Pa,{})})}),(0,Q.jsx)(h,{path:`/dev/lists`,element:(0,Q.jsx)(Jd,{children:(0,Q.jsx)(La,{})})}),(0,Q.jsx)(h,{path:`/dev/modal`,element:(0,Q.jsx)(Jd,{children:(0,Q.jsx)(gu,{})})}),(0,Q.jsx)(h,{path:`/dev/lookup`,element:(0,Q.jsx)(Jd,{children:(0,Q.jsx)(_u,{})})}),(0,Q.jsx)(h,{path:`/organizations`,element:(0,Q.jsx)(Jd,{requireOrganization:!1,children:(0,Q.jsx)(ol,{children:(0,Q.jsx)(dl,{})})})}),(0,Q.jsxs)(h,{path:`/organizations/:slug`,element:(0,Q.jsx)(Jd,{requireOrganization:!1,children:(0,Q.jsx)(fl,{})}),children:[(0,Q.jsx)(h,{index:!0,element:(0,Q.jsx)(r,{to:`members`,replace:!0})}),(0,Q.jsx)(h,{path:`members`,element:(0,Q.jsx)(_l,{})}),(0,Q.jsx)(h,{path:`invitations`,element:(0,Q.jsx)(bl,{})}),(0,Q.jsx)(h,{path:`settings`,element:(0,Q.jsx)(xl,{})})]}),(0,Q.jsx)(h,{path:`/system/*`,element:(0,Q.jsx)(Ja,{})}),(0,Q.jsx)(h,{path:`/ai`,element:(0,Q.jsx)(Jd,{children:(0,Q.jsx)(eu,{})})}),(0,Q.jsx)(h,{path:`/ai/:conversationId`,element:(0,Q.jsx)(Jd,{children:(0,Q.jsx)(eu,{})})}),(0,Q.jsx)(h,{path:`/apps/:appName/*`,element:(0,Q.jsx)(Jd,{children:(0,Q.jsx)(Iu,{})})}),(0,Q.jsx)(h,{path:`/`,element:(0,Q.jsx)(Wa,{children:(0,Q.jsx)(Ru,{})})}),(0,Q.jsx)(h,{path:`*`,element:(0,Q.jsx)(r,{to:`/`,replace:!0})})]})})})]})}async function Zd(e){try{let t=await fetch(`/api/v1/i18n/translations/${e}`);if(!t.ok)return console.warn(`[i18n] Failed to load translations for '${e}': HTTP ${t.status}`),{};let n=await t.json(),r;return r=n?.data?.translations&&typeof n.data.translations==`object`?n.data.translations:n,S(r)?v(r):r}catch(t){return console.warn(`[i18n] Failed to load translations for '${e}':`,t),{}}}var Qd=`auth-session-token`,$d=`auth-active-organization-id`;async function ef(e){if(typeof window>`u`)return;let t=null;try{t=localStorage.getItem(Qd)}catch{return}if(t)try{let n=await fetch(`${e}/get-session`,{method:`GET`,credentials:`omit`,headers:{Authorization:`Bearer ${t}`,Accept:`application/json`}});if(n.ok){let e=await n.json().catch(()=>null);if(e?.user??e?.data?.user??null)return}localStorage.removeItem(Qd),localStorage.removeItem($d)}catch{}}function tf(e,t){let n=Array.isArray(e.fields)?e.fields:Object.values(e.fields||{});return{id:e.name||`obj_${t}`,name:e.name||``,label:typeof e.label==`object`?e.label.defaultValue||e.label.key||``:e.label||e.name||``,pluralLabel:e.pluralLabel||e.plural_label||void 0,description:typeof e.description==`object`?e.description.defaultValue:e.description||void 0,icon:e.icon||void 0,group:e.name?.startsWith(`sys_`)?`System Objects`:`Custom Objects`,sortOrder:t,isSystem:e.name?.startsWith(`sys_`)||!1,enabled:e.enabled!==!1,fieldCount:n.length,relationships:Array.isArray(e.relationships)?e.relationships.map(e=>({relatedObject:e.object||e.relatedObject||``,type:e.type||`one-to-many`,label:e.label||e.name||void 0,foreignKey:e.foreign_key||e.foreignKey||void 0})):void 0}}function nf(e,t){return{id:e.name||`fld_${t}`,name:e.name||``,label:typeof e.label==`object`?e.label.defaultValue||e.label.key||``:e.label||e.name||``,type:e.type||`text`,group:e.group||void 0,sortOrder:t,description:e.description||e.help||void 0,required:e.required||!1,unique:e.unique||!1,readonly:e.readonly||!1,hidden:e.hidden||!1,defaultValue:e.defaultValue||e.default_value||void 0,placeholder:e.placeholder||void 0,options:Array.isArray(e.options)?e.options.map(e=>typeof e==`string`?{label:e,value:e}:{label:e.label||e.value,value:e.value,color:e.color}):void 0,isSystem:e.readonly===!0&&(e.name===`id`||e.name===`createdAt`||e.name===`updatedAt`),externalId:e.externalId||!1,trackHistory:e.trackHistory||e.track_history||!1,indexed:e.indexed||!1,referenceTo:e.reference_to||e.referenceTo||void 0,formula:e.formula||void 0}}function rf(e){let{objects:t}=F(),n=(0,Z.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,Z.useMemo)(()=>n?tf(n,0):null,[n]),fields:(0,Z.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map(nf):[],[n]),metadataObject:n}}function af({label:e,value:t,onSave:n,multiline:r=!1,disabled:i=!1,placeholder:a}){let[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(t),[u,d]=(0,Z.useState)(!1),f=(0,Z.useRef)(null),p=()=>{l(t),s(!0),setTimeout(()=>f.current?.focus(),0)},m=(0,Z.useCallback)(async()=>{if(c===t){s(!1);return}d(!0);try{await n(c),s(!1)}catch{}finally{d(!1)}},[c,t,n]),h=()=>{l(t),s(!1)},g=e=>{e.key===`Enter`&&!r&&(e.preventDefault(),m()),e.key===`Escape`&&h()};return(0,Q.jsxs)(`div`,{className:`space-y-1.5 group`,children:[(0,Q.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:e}),(0,Q.jsx)(`dd`,{children:o?(0,Q.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[r?(0,Q.jsx)(Dr,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,rows:3,className:`text-sm flex-1 min-w-0`,disabled:u}):(0,Q.jsx)(Y,{ref:f,value:c,onChange:e=>l(e.target.value),onKeyDown:g,placeholder:a,className:`text-sm h-7 flex-1 min-w-0`,disabled:u}),(0,Q.jsx)(`button`,{onClick:()=>void m(),disabled:u,className:`mt-0.5 p-1 rounded text-green-600 hover:bg-green-50 disabled:opacity-50 shrink-0`,"aria-label":`Save`,children:u?(0,Q.jsx)(q,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Ee,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:h,disabled:u,className:`mt-0.5 p-1 rounded text-muted-foreground hover:bg-accent shrink-0`,"aria-label":`Cancel`,children:(0,Q.jsx)(Et,{className:`h-3.5 w-3.5`})})]}):(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 min-h-7`,children:[(0,Q.jsx)(`span`,{className:`text-sm flex-1 min-w-0 truncate`,children:t||(0,Q.jsx)(`span`,{className:`text-muted-foreground italic`,children:a||`—`})}),!i&&(0,Q.jsx)(`button`,{onClick:p,className:`p-1 rounded text-muted-foreground opacity-0 group-hover:opacity-100 hover:bg-accent transition-opacity shrink-0`,"aria-label":`Edit ${e}`,children:(0,Q.jsx)(Wt,{className:`h-3 w-3`})})]})})]})}function of({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=rf(t),{refresh:a}=F(),o=Os(),s=(0,Z.useCallback)(async(e,n)=>{if(!o||!i)return;let r={...i,[e]:n};try{await o.saveMetadataItem(`object`,t,r),await a(),X.success(`${e===`label`?`Display name`:`Field`} updated`)}catch(e){throw X.error(e?.message||`Failed to save`),e}},[o,i,t,a]);if(!n)return null;let c=n.isSystem;return(0,Q.jsxs)(`div`,{className:`space-y-6`,"data-testid":`object-properties`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`基本信息`}),(0,Q.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-5`,children:[(0,Q.jsx)(af,{label:`显示名称`,value:n.label,onSave:e=>s(`label`,e),placeholder:`输入显示名称`,disabled:c}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`API 名称`}),(0,Q.jsx)(`dd`,{className:`text-sm font-mono bg-muted/50 rounded px-2 py-1 inline-block`,children:n.name})]}),(0,Q.jsx)(af,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,Q.jsx)(af,{label:`分组`,value:n.group||``,onSave:e=>s(`group`,e),placeholder:`对象分组`,disabled:c}),(0,Q.jsx)(`div`,{className:`sm:col-span-2`,children:(0,Q.jsx)(af,{label:`描述`,value:n.description||``,onSave:e=>s(`description`,e),multiline:!0,placeholder:`输入对象描述`,disabled:c})})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`配置`}),(0,Q.jsxs)(`dl`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`状态`}),(0,Q.jsx)(`dd`,{children:(0,Q.jsx)(ue,{variant:n.enabled===!1?`secondary`:`default`,className:`font-normal`,children:n.enabled===!1?`已禁用`:`已启用`})})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`字段数量`}),(0,Q.jsxs)(`dd`,{className:`text-sm font-medium`,children:[n.fieldCount??r.length,` 个字段`]})]}),c&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:`类型`}),(0,Q.jsx)(`dd`,{children:(0,Q.jsx)(ue,{variant:`secondary`,className:`font-normal`,children:`系统对象`})})]})]})]})]})}var sf=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function cf({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=rf(t),{refresh:i}=F(),a=Os(),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``}),f=(0,Z.useCallback)(async()=>{if(!a||!r||!u.relatedObject.trim())return;let e={relatedObject:u.relatedObject.trim(),type:u.type,label:u.label.trim()||void 0,foreignKey:u.foreignKey.trim()||void 0},n={...r,relationships:[...Array.isArray(r.relationships)?r.relationships:[],e]};l(!0);try{await a.saveMetadataItem(`object`,t,n),await i(),X.success(`关联关系已添加`),s(!1),d({relatedObject:``,type:`one-to-many`,label:``,foreignKey:``})}catch(e){X.error(e?.message||`保存失败`)}finally{l(!1)}},[a,r,n,u,t,i]),p=(0,Z.useCallback)(async e=>{if(!a||!r)return;let n=Array.isArray(r.relationships)?[...r.relationships]:[];n.splice(e,1);let o={...r,relationships:n};l(!0);try{await a.saveMetadataItem(`object`,t,o),await i(),X.success(`关联关系已删除`)}catch(e){X.error(e?.message||`删除失败`)}finally{l(!1)}},[a,r,t,i]);if(!n)return null;let m=n.relationships&&n.relationships.length>0;return(0,Q.jsx)(`div`,{className:`space-y-4`,"data-testid":`relationships-section`,children:(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Q.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider`,children:`关联关系`}),!n.isSystem&&(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>s(e=>!e),className:`h-7 text-xs`,children:[(0,Q.jsx)(Mt,{className:`h-3 w-3 mr-1`}),`添加关联`]})]}),o&&(0,Q.jsxs)(`div`,{className:`mb-4 p-4 border rounded-lg bg-muted/30 space-y-3`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-medium`,children:`新建关联关系`}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联对象 *`}),(0,Q.jsx)(Y,{value:u.relatedObject,onChange:e=>d(t=>({...t,relatedObject:e.target.value})),placeholder:`例如:account`,className:`h-7 text-xs`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`关联类型`}),(0,Q.jsx)(`select`,{value:u.type,onChange:e=>d(t=>({...t,type:e.target.value})),className:`w-full h-7 text-xs rounded-md border border-input bg-background px-2`,children:sf.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`显示名称`}),(0,Q.jsx)(Y,{value:u.label,onChange:e=>d(t=>({...t,label:e.target.value})),placeholder:`可选`,className:`h-7 text-xs`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`text-xs text-muted-foreground block mb-1`,children:`外键字段`}),(0,Q.jsx)(Y,{value:u.foreignKey,onChange:e=>d(t=>({...t,foreignKey:e.target.value})),placeholder:`例如:account_id`,className:`h-7 text-xs`})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 justify-end`,children:[(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>s(!1),disabled:c,children:`取消`}),(0,Q.jsxs)(J,{size:`sm`,className:`h-7 text-xs`,onClick:()=>void f(),disabled:c||!u.relatedObject.trim(),children:[c?(0,Q.jsx)(q,{className:`h-3 w-3 animate-spin mr-1`}):null,`保存`]})]})]}),m?(0,Q.jsx)(`div`,{className:`space-y-2`,children:n.relationships?.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors group`,children:[(0,Q.jsx)(ue,{variant:`outline`,className:`text-xs shrink-0 mt-0.5`,children:sf.find(t=>t.value===e.type)?.label||e.type}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.relatedObject}),e.label&&e.label!==e.relatedObject&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`关联对象: `,(0,Q.jsx)(`span`,{className:`font-mono`,children:e.relatedObject})]}),e.foreignKey&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`外键: `,(0,Q.jsx)(`span`,{className:`font-mono`,children:e.foreignKey})]})]}),!n.isSystem&&(0,Q.jsx)(`button`,{onClick:()=>void p(t),disabled:c,className:`p-1 rounded text-muted-foreground opacity-0 group-hover:opacity-100 hover:text-destructive hover:bg-destructive/10 transition-all shrink-0`,"aria-label":`删除关联`,children:(0,Q.jsx)(Rt,{className:`h-3.5 w-3.5`})})]},t))}):!o&&(0,Q.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,Q.jsx)(Be,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无关联关系。`}),!n.isSystem&&(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,className:`mt-3 h-7 text-xs`,onClick:()=>s(!0),children:[(0,Q.jsx)(Mt,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function lf({schema:e}){let t=e.objectName,{fields:n}=rf(t),r=(0,Z.useMemo)(()=>n.filter(e=>e.unique||e.name===`id`||e.externalId),[n]);return(0,Q.jsx)(`div`,{className:`space-y-4`,"data-testid":`keys-section`,children:(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`唯一键`}),r.length>0?(0,Q.jsx)(`div`,{className:`space-y-2`,children:r.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-4 p-3 rounded-lg border bg-card hover:bg-accent/30 transition-colors`,children:[(0,Q.jsx)(ue,{variant:e.name===`id`?`default`:`outline`,className:`text-xs shrink-0 mt-0.5`,children:e.name===`id`?`主键`:e.externalId?`外部 ID`:`唯一`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`font-medium text-sm`,children:e.label||e.name}),(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-0.5`,children:[`类型: `,(0,Q.jsx)(`span`,{className:`font-mono`,children:e.type})]})]})]},e.name))}):(0,Q.jsxs)(`div`,{className:`text-center py-8 px-4 border border-dashed rounded-lg`,children:[(0,Q.jsx)(Ye,{className:`h-8 w-8 mx-auto mb-2 text-muted-foreground opacity-40`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`未找到唯一键或主键。`})]})]})})}function uf(e){return(0,Q.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-experience-section`,children:(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据体验`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`配置用户与此对象数据的交互方式`}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-forms`,children:[(0,Q.jsx)(Tn,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Q.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`表单`}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`设计数据录入表单`})]}),(0,Q.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-views`,children:[(0,Q.jsx)(he,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Q.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`视图`}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`配置列表和详情视图`})]}),(0,Q.jsxs)(`div`,{className:`rounded-lg border p-5 text-center hover:bg-accent/30 transition-colors cursor-pointer`,"data-testid":`data-experience-dashboards`,children:[(0,Q.jsx)(st,{className:`h-7 w-7 mx-auto mb-2.5 text-muted-foreground`}),(0,Q.jsx)(`p`,{className:`text-sm font-semibold mb-1`,children:`仪表盘`}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`构建可视化仪表盘`})]})]})]})})}function df({schema:e}){let t=e.objectName,{object:n}=rf(t);return(0,Q.jsx)(`div`,{className:`space-y-4`,"data-testid":`data-preview-section`,children:(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-4`,children:`数据预览`}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:`查看此对象的示例记录`}),(0,Q.jsxs)(`div`,{className:`rounded-lg border border-dashed p-12 text-center`,children:[(0,Q.jsx)(Xt,{className:`h-12 w-12 mx-auto mb-4 text-muted-foreground opacity-40`}),(0,Q.jsx)(`p`,{className:`text-sm font-medium mb-1`,children:`示例数据`}),(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`“`,n?.label||t,`” 的实时数据预览将在此处显示`]})]})]})})}function ff(e){return e||(typeof window<`u`&&window.sessionStorage?window.sessionStorage:null)}function pf(e,t={}){let{maxHistory:n=50,persistKey:r,storage:i}=t,a=ff(i),o=(()=>{if(!r||!a)return null;try{let e=a.getItem(r);if(!e)return null;let t=JSON.parse(e);if(t&&t.v===1&&Array.isArray(t.past)&&Array.isArray(t.future))return t}catch{}return null})(),[s,c]=(0,Z.useState)(o?.current??e),l=(0,Z.useRef)(o?.past??[]),u=(0,Z.useRef)(o?.future??[]),[,d]=(0,Z.useState)(0),f=(0,Z.useCallback)(()=>d(e=>e+1),[]);(0,Z.useEffect)(()=>{if(!(!r||!a))try{let e={v:1,past:l.current,current:s,future:u.current};a.setItem(r,JSON.stringify(e))}catch{}},[s,r,a]);let p=(0,Z.useCallback)(e=>{c(t=>(l.current=[...l.current.slice(-(n-1)),t],u.current=[],e)),f()},[n,f]),m=(0,Z.useCallback)(()=>{l.current.length!==0&&(c(e=>{let t=[...l.current],n=t.pop();return l.current=t,u.current=[e,...u.current],n}),f())},[f]),h=(0,Z.useCallback)(()=>{u.current.length!==0&&(c(e=>{let t=[...u.current],n=t.shift();return u.current=t,l.current=[...l.current,e],n}),f())},[f]),g=(0,Z.useCallback)(e=>{l.current=[],u.current=[],c(e),f()},[f]),_=(0,Z.useCallback)(()=>{if(!(!r||!a))try{a.removeItem(r)}catch{}},[r,a]),v=(0,Z.useCallback)(e=>{let t=l.current.length+1+u.current.length;e<0||e>=t||e!==l.current.length&&(c(t=>{let n=[...l.current,t,...u.current],r=n[e];return l.current=n.slice(0,e),u.current=n.slice(e+1),r}),f())},[f]);return{current:s,canUndo:l.current.length>0,canRedo:u.current.length>0,undoCount:l.current.length,redoCount:u.current.length,timeline:[...l.current,s,...u.current],currentIndex:l.current.length,push:p,undo:m,redo:h,reset:g,jumpTo:v,clearPersisted:_}}function mf(){let[e,t]=(0,Z.useState)(!1),[n,r]=(0,Z.useState)(``),[i,a]=(0,Z.useState)(``),o=(0,Z.useRef)(null);return{isOpen:e,title:n,message:i,confirm:(0,Z.useCallback)((e,n)=>(r(e),a(n),t(!0),new Promise(e=>{o.current=e})),[]),onConfirm:(0,Z.useCallback)(()=>{t(!1),o.current?.(!0),o.current=null},[]),onCancel:(0,Z.useCallback)(()=>{t(!1),o.current?.(!1),o.current=null},[])}}function hf(){let[e,t]=(0,Z.useState)(new Set);return{selectedIds:e,toggle:(0,Z.useCallback)((e,n=!1)=>{t(t=>{let r=new Set(n?t:[]);return t.has(e)&&n?r.delete(e):r.add(e),r})},[]),selectOne:(0,Z.useCallback)(e=>{t(new Set([e]))},[]),selectMany:(0,Z.useCallback)(e=>{t(new Set(e))},[]),clearSelection:(0,Z.useCallback)(()=>{t(new Set)},[]),isSelected:(0,Z.useCallback)(t=>e.has(t),[e]),count:e.size}}function gf(){let[e,t]=(0,Z.useState)(null);return{clipboard:e,copy:(0,Z.useCallback)(e=>{t(structuredClone(e))},[]),paste:(0,Z.useCallback)(()=>e?structuredClone(e):null,[e]),hasContent:e!==null}}function _f(e={}){let{minZoom:t=.25,maxZoom:n=3,zoomStep:r=.1,initialZoom:i=1}=e,[a,o]=(0,Z.useState)(i),[s,c]=(0,Z.useState)({x:0,y:0}),l=(0,Z.useRef)(!1),u=(0,Z.useRef)({x:0,y:0}),d=(0,Z.useCallback)(e=>Math.min(n,Math.max(t,+e.toFixed(2))),[t,n]);return{zoom:a,panOffset:s,zoomIn:(0,Z.useCallback)(()=>o(e=>d(e+r)),[d,r]),zoomOut:(0,Z.useCallback)(()=>o(e=>d(e-r)),[d,r]),resetZoom:(0,Z.useCallback)(()=>{o(1),c({x:0,y:0})},[]),setZoom:(0,Z.useCallback)(e=>o(d(e)),[d]),handleWheel:(0,Z.useCallback)(e=>{if(e.ctrlKey||e.metaKey){e.preventDefault();let t=e.deltaY>0?-r:r;o(e=>d(e+t))}},[d,r]),startPan:(0,Z.useCallback)(e=>{if(e.button===1||e.button===0&&e.altKey){e.preventDefault(),l.current=!0,u.current={x:e.clientX,y:e.clientY};let t=e=>{if(!l.current)return;let t=e.clientX-u.current.x,n=e.clientY-u.current.y;u.current={x:e.clientX,y:e.clientY},c(e=>({x:e.x+t,y:e.y+n}))},n=()=>{l.current=!1,document.removeEventListener(`mousemove`,t),document.removeEventListener(`mouseup`,n)};document.addEventListener(`mousemove`,t),document.addEventListener(`mouseup`,n)}},[]),transformStyle:{transform:`translate(${s.x}px, ${s.y}px) scale(${a})`,transformOrigin:`0 0`}}}function vf(...e){return Xr(Qr(e))}function yf({isOpen:e,title:t,message:n,confirmLabel:r=`Delete`,cancelLabel:i=`Cancel`,destructive:a=!0,onConfirm:o,onCancel:s}){let c=(0,Z.useRef)(null);return(0,Z.useEffect)(()=>{let t=c.current;t&&(e&&!t.open?t.showModal():!e&&t.open&&t.close())},[e]),e?(0,Q.jsx)(`dialog`,{ref:c,className:`fixed inset-0 z-50 m-auto rounded-lg border bg-background p-0 shadow-lg backdrop:bg-black/50`,onClose:s,"aria-labelledby":`confirm-title`,"aria-describedby":`confirm-message`,children:(0,Q.jsxs)(`div`,{className:`w-80 p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[a&&(0,Q.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-full bg-destructive/10`,children:(0,Q.jsx)(St,{className:`h-5 w-5 text-destructive`})}),(0,Q.jsx)(`h2`,{id:`confirm-title`,className:`text-lg font-semibold`,children:t})]}),(0,Q.jsx)(`p`,{id:`confirm-message`,className:`text-sm text-muted-foreground mb-6`,children:n}),(0,Q.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Q.jsx)(`button`,{onClick:s,className:`px-4 py-2 text-sm rounded-md border hover:bg-accent`,children:i}),(0,Q.jsx)(`button`,{onClick:o,className:vf(`px-4 py-2 text-sm rounded-md font-medium`,a?`bg-destructive text-destructive-foreground hover:bg-destructive/90`:`bg-primary text-primary-foreground hover:bg-primary/90`),autoFocus:!0,children:r})]})]})}):null}function bf(...e){return Xr(Qr(e))}function xf({title:e=`Properties`,fields:t,onChange:n,className:r}){let[i,a]=(0,Z.useState)(new Set),o=(0,Z.useCallback)(e=>{a(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),s=t.reduce((e,t)=>{let n=t.group??`General`;return e[n]||(e[n]=[]),e[n].push(t),e},{});return(0,Q.jsxs)(`div`,{className:bf(`flex flex-col`,r),role:`region`,"aria-label":e,children:[(0,Q.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:e}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[Object.entries(s).map(([e,t])=>(0,Q.jsxs)(`div`,{className:`border-b last:border-b-0`,children:[(0,Q.jsxs)(`button`,{onClick:()=>o(e),className:`w-full flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50`,children:[i.has(e)?(0,Q.jsx)(be,{className:`h-3 w-3`}):(0,Q.jsx)(At,{className:`h-3 w-3`}),e]}),!i.has(e)&&(0,Q.jsx)(`div`,{className:`px-3 pb-2 space-y-2`,children:t.map(e=>(0,Q.jsx)(Sf,{field:e,onChange:n},e.name))})]},e)),t.length===0&&(0,Q.jsx)(`div`,{className:`p-3 text-xs text-muted-foreground text-center`,children:`Select an element to edit its properties`})]})]})}function Sf({field:e,onChange:t}){let n=n=>{t(e.name,n)};return(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs text-muted-foreground`,children:e.label}),e.type===`text`&&(0,Q.jsx)(`input`,{type:`text`,value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background`}),e.type===`number`&&(0,Q.jsx)(`input`,{type:`number`,value:Number(e.value??0),onChange:e=>n(Number(e.target.value)),className:`w-full px-2 py-1 text-xs border rounded bg-background`}),e.type===`boolean`&&(0,Q.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:!!e.value,onChange:e=>n(e.target.checked),className:`rounded`}),(0,Q.jsx)(`span`,{className:`text-xs`,children:e.value?`Yes`:`No`})]}),e.type===`select`&&(0,Q.jsx)(`select`,{value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background`,children:e.options?.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))}),e.type===`color`&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{type:`color`,value:String(e.value??`#000000`),onChange:e=>n(e.target.value),className:`h-6 w-6 rounded border cursor-pointer`}),(0,Q.jsx)(`span`,{className:`text-xs font-mono`,children:String(e.value??`#000000`)})]}),e.type===`textarea`&&(0,Q.jsx)(`textarea`,{value:String(e.value??``),onChange:e=>n(e.target.value),className:`w-full px-2 py-1 text-xs border rounded bg-background resize-y`,rows:3}),e.description&&(0,Q.jsx)(`p`,{className:`text-[0.65rem] text-muted-foreground/70`,children:e.description})]})}function Cf(...e){return Xr(Qr(e))}function wf({items:e,canvasWidth:t,canvasHeight:n,position:r=`bottom-right`,size:i=150,className:a}){let o=Math.min(i/t,i/n),s=t*o,c=n*o;return(0,Q.jsx)(`div`,{className:Cf(`absolute border rounded bg-background/90 shadow-sm overflow-hidden`,{"top-left":`top-2 left-2`,"top-right":`top-2 right-2`,"bottom-left":`bottom-2 left-2`,"bottom-right":`bottom-2 right-2`}[r],a),role:`img`,"aria-label":`Canvas minimap`,children:(0,Q.jsxs)(`svg`,{width:s,height:c,viewBox:`0 0 ${t} ${n}`,children:[(0,Q.jsx)(`rect`,{width:t,height:n,fill:`hsl(var(--muted))`,opacity:`0.3`}),e.map(e=>(0,Q.jsx)(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,fill:e.selected?`hsl(var(--primary))`:e.color??`hsl(var(--foreground) / 0.3)`,rx:`2`},e.id))]})})}var Tf=(0,Z.createContext)(null);Tf.displayName=`CollaborationContext`;function Ef(){return(0,Z.useContext)(Tf)}function Df(...e){return Xr(Qr(e))}function Of({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:n=kf,showComponentTree:r=!0,undoRedo:i=!0,propertyEditor:a=!0,readOnly:o=!1,showMinimap:s=!1,onChange:c,className:l}){let u=pf(t),d=u.current,f=(0,Z.useCallback)(e=>{u.push(e),c?.(e)},[u,c]),p=_f({initialZoom:e.zoom??1}),{zoom:m}=p,h=hf(),g=(0,Z.useMemo)(()=>{let e=Array.from(h.selectedIds);return e.length>0?e[0]:null},[h.selectedIds]),_=(0,Z.useMemo)(()=>d.find(e=>e.id===g),[d,g]),v=gf(),y=mf(),b=Ef(),x=(0,Z.useCallback)(e=>{b&&b.sendOperation({...e,userId:b.currentUserId??``})},[b]),[S,C]=(0,Z.useState)(!0),[w,T]=(0,Z.useState)(!0),[E,D]=(0,Z.useState)(s),O=(0,Z.useRef)(null),k=(0,Z.useRef)(null),A=(0,Z.useCallback)(t=>!e.snapToGrid||!e.gridSize?t:Math.round(t/e.gridSize)*e.gridSize,[e.snapToGrid,e.gridSize]),j=(0,Z.useCallback)((e,t)=>{if(o)return;let r=n.flatMap(e=>e.items).find(t=>t.type===e),i=r?.defaultSize,a={id:`comp-${Date.now()}`,type:e,label:t,position:{x:100,y:100,width:i?.width??200,height:i?.height??100},props:r?.defaultProps??{}};f([...d,a]),h.selectOne(a.id),x({type:`insert`,elementId:a.id,data:{component:a}})},[d,o,n,f,h,x]),M=(0,Z.useCallback)(e=>{o||(f(d.filter(t=>t.id!==e)),h.isSelected(e)&&h.clearSelection(),x({type:`delete`,elementId:e,data:{}}))},[d,o,f,h,x]),N=(0,Z.useCallback)(async()=>{if(o||h.count===0||!await y.confirm(`Delete components`,`Are you sure you want to delete ${h.count} component${h.count>1?`s`:``}?`))return;let e=h.selectedIds;f(d.filter(t=>!e.has(t.id))),h.clearSelection(),e.forEach(e=>{x({type:`delete`,elementId:e,data:{}})})},[o,h,y,d,f,x]),P=(0,Z.useCallback)((e,t)=>{o||!g||(f(d.map(n=>n.id===g?e===`label`?{...n,label:String(t)}:e===`x`?{...n,position:{...n.position,x:Number(t)}}:e===`y`?{...n,position:{...n.position,y:Number(t)}}:e===`width`?{...n,position:{...n.position,width:Number(t)}}:e===`height`?{...n,position:{...n.position,height:Number(t)}}:{...n,props:{...n.props,[e]:t}}:n)),x({type:`update`,elementId:g,data:{[e]:t}}))},[o,g,d,f,x]),ee=(0,Z.useCallback)(()=>{let e=h.selectedIds;if(e.size===0)return;let t=d.filter(t=>e.has(t.id));v.copy(t)},[h,d,v]),F=(0,Z.useCallback)(()=>{if(o)return;let e=v.paste();if(!e||e.length===0)return;let t=0,n=e.map(e=>({...e,id:`comp-${Date.now()}-${++t}-${Math.random().toString(36).slice(2,7)}`,position:{...e.position,x:e.position.x+20,y:e.position.y+20}}));f([...d,...n]),h.selectMany(n.map(e=>e.id)),n.forEach(e=>{x({type:`insert`,elementId:e.id,data:{component:e}})})},[o,v,d,f,h,x]),te=(0,Z.useCallback)((e,t)=>{o||(O.current={id:t.id,startX:e.clientX,startY:e.clientY},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id))},[o]),I=(0,Z.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),ne=(0,Z.useCallback)(e=>{e.preventDefault();let t=O.current;if(!t||o)return;let n=(e.clientX-t.startX)/m,r=(e.clientY-t.startY)/m;f(d.map(e=>e.id===t.id?{...e,position:{...e.position,x:A(e.position.x+n),y:A(e.position.y+r)}}:e)),x({type:`move`,elementId:t.id,data:{}}),O.current=null},[o,m,d,f,A,x]),L=(0,Z.useMemo)(()=>_?[{name:`label`,label:`Label`,type:`text`,value:_.label??``,group:`General`},{name:`x`,label:`X`,type:`number`,value:_.position.x,group:`Position`},{name:`y`,label:`Y`,type:`number`,value:_.position.y,group:`Position`},{name:`width`,label:`Width`,type:`number`,value:_.position.width,group:`Size`},{name:`height`,label:`Height`,type:`number`,value:_.position.height,group:`Size`}]:[],[_]),R=(0,Z.useMemo)(()=>d.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:typeof e.position.width==`number`?e.position.width:100,height:typeof e.position.height==`number`?e.position.height:50,selected:h.isSelected(e.id)})),[d,h]);return(0,Z.useEffect)(()=>{let e=k.current;if(!e)return;let t=e=>{let t=[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName),n=e.ctrlKey||e.metaKey;if((e.key===`Delete`||e.key===`Backspace`)&&h.count>0&&!t){e.preventDefault(),N();return}if(e.key===`Escape`){h.clearSelection();return}if(!t){if(n&&e.key===`z`&&!e.shiftKey&&i&&!o){e.preventDefault(),u.undo();return}if(n&&(e.key===`z`&&e.shiftKey||e.key===`y`)&&i&&!o){e.preventDefault(),u.redo();return}if(n&&e.key===`c`){e.preventDefault(),ee();return}if(n&&e.key===`v`&&!o){e.preventDefault(),F();return}if(n&&e.key===`a`){e.preventDefault(),h.selectMany(d.map(e=>e.id));return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[h,N,i,o,u,ee,F,d]),(0,Q.jsxs)(`div`,{ref:k,tabIndex:0,className:Df(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[!o&&(0,Q.jsx)(`div`,{className:Df(`border-r bg-muted/30 flex flex-col transition-[width] duration-200`,S?`w-60`:`w-0 overflow-hidden`),role:`region`,"aria-label":`Component palette`,children:S&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:`Components`}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:n.map(e=>(0,Q.jsxs)(`div`,{className:`mb-3`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground px-2 py-1 uppercase`,children:e.label}),e.items.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>j(e.type,e.label),className:`w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded hover:bg-accent text-left`,children:[(0,Q.jsx)(Mt,{className:`h-3 w-3`}),e.label]},e.type))]},e.name))})]})}),(0,Q.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Designer toolbar`,children:[!o&&(0,Q.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:S?`Collapse palette`:`Expand palette`,"aria-label":S?`Collapse palette`:`Expand palette`,onClick:()=>C(e=>!e),children:(0,Q.jsx)(sr,{className:Df(`h-4 w-4`,!S&&`rotate-180`)})}),i&&!o&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,Q.jsx)(`button`,{className:Df(`p-1.5 rounded hover:bg-accent`,!u.canUndo&&`opacity-40 pointer-events-none`),title:`Undo (Ctrl+Z)`,"aria-label":`Undo`,disabled:!u.canUndo,onClick:()=>u.undo(),children:(0,Q.jsx)(Ue,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{className:Df(`p-1.5 rounded hover:bg-accent`,!u.canRedo&&`opacity-40 pointer-events-none`),title:`Redo (Ctrl+Shift+Z)`,"aria-label":`Redo`,disabled:!u.canRedo,onClick:()=>u.redo(),children:(0,Q.jsx)(Qe,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{className:Df(`p-1.5 rounded hover:bg-accent`,h.count===0&&`opacity-40 pointer-events-none`),title:`Copy (Ctrl+C)`,"aria-label":`Copy`,disabled:h.count===0,onClick:ee,children:(0,Q.jsx)(qt,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{className:Df(`p-1.5 rounded hover:bg-accent`,!v.hasContent&&`opacity-40 pointer-events-none`),title:`Paste (Ctrl+V)`,"aria-label":`Paste`,disabled:!v.hasContent,onClick:F,children:(0,Q.jsx)(sn,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Q.jsx)(`button`,{className:Df(`p-1.5 rounded hover:bg-accent`,h.count===0&&`opacity-40 pointer-events-none`),title:`Delete selected`,"aria-label":`Delete selected`,disabled:h.count===0,onClick:N,children:(0,Q.jsx)(Rt,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:`Preview`,"aria-label":`Preview`,children:(0,Q.jsx)(mt,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{className:Df(`p-1.5 rounded hover:bg-accent`,E&&`bg-accent`),title:`Toggle minimap`,"aria-label":`Toggle minimap`,onClick:()=>D(e=>!e),children:(0,Q.jsx)(we,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`flex-1`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom out`,onClick:p.zoomOut,children:(0,Q.jsx)(Br,{className:`h-3 w-3`})}),(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground w-10 text-center`,children:[Math.round(m*100),`%`]}),(0,Q.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Zoom in`,onClick:p.zoomIn,children:(0,Q.jsx)(Mt,{className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{className:`p-1 rounded hover:bg-accent text-xs`,"aria-label":`Reset zoom`,onClick:p.resetZoom,children:(0,Q.jsx)(Ot,{className:`h-3 w-3`})})]}),r&&(0,Q.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:w?`Collapse panel`:`Expand panel`,"aria-label":w?`Collapse panel`:`Expand panel`,onClick:()=>T(e=>!e),children:(0,Q.jsx)(hr,{className:Df(`h-4 w-4`,!w&&`rotate-180`)})})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-auto bg-muted/10 p-4 relative`,role:`region`,"aria-label":`Design canvas`,onWheel:p.handleWheel,onMouseDown:p.startPan,onDragOver:I,onDrop:ne,children:(0,Q.jsxs)(`div`,{className:`relative bg-background border rounded shadow-sm mx-auto`,style:{width:e.width*m,height:e.height*m,transform:`translate(${p.panOffset.x}px, ${p.panOffset.y}px)`,backgroundImage:e.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:e.showGrid&&e.gridSize?`${e.gridSize*m}px ${e.gridSize*m}px`:void 0},children:[d.map(e=>{let t=h.isSelected(e.id);return(0,Q.jsxs)(`div`,{draggable:!o,onDragStart:t=>te(t,e),className:Df(`absolute border rounded cursor-move select-none transition-shadow`,t?`border-primary ring-2 ring-primary/20 shadow-md`:`border-border hover:border-primary/50`),style:{left:e.position.x*m,top:e.position.y*m,width:typeof e.position.width==`number`?e.position.width*m:e.position.width,height:typeof e.position.height==`number`?e.position.height*m:e.position.height},onClick:t=>h.toggle(e.id,t.shiftKey),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 bg-muted/50 text-xs border-b`,children:[(0,Q.jsx)(Bn,{className:`h-3 w-3 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label??e.type}),!o&&(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),M(e.id)},className:`ml-auto p-0.5 rounded hover:bg-destructive/10`,"aria-label":`Delete ${e.label??e.type}`,children:(0,Q.jsx)(Rt,{className:`h-3 w-3 text-destructive`})})]}),(0,Q.jsx)(`div`,{className:`p-2 text-xs text-muted-foreground`,children:e.type})]},e.id)}),E&&(0,Q.jsx)(wf,{items:R,canvasWidth:e.width,canvasHeight:e.height})]})})]}),r&&(0,Q.jsx)(`div`,{className:Df(`border-l bg-muted/30 flex flex-col transition-[width] duration-200`,w?`w-60`:`w-0 overflow-hidden`),role:`region`,"aria-label":`Component tree`,children:w&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`p-3 border-b font-medium text-sm flex items-center gap-2`,children:[(0,Q.jsx)(It,{className:`h-4 w-4`}),`Component Tree`]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-2`,children:d.length===0?(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground text-center py-4`,children:`No components added yet. Click a component in the palette to add it to the canvas.`}):d.map(e=>(0,Q.jsx)(`button`,{onClick:t=>h.toggle(e.id,t.shiftKey),className:Df(`w-full flex items-center gap-2 px-2 py-1.5 text-sm rounded text-left`,h.isSelected(e.id)?`bg-accent`:`hover:bg-accent/50`),children:(0,Q.jsx)(`span`,{className:`truncate`,children:e.label??e.type})},e.id))}),a&&_?(0,Q.jsx)(`div`,{className:`border-t`,children:(0,Q.jsx)(xf,{title:`Properties – ${_.label??_.type}`,fields:L,onChange:P})}):_&&(0,Q.jsxs)(`div`,{className:`border-t p-3`,children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium mb-2`,children:`Properties`}),(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground space-y-1`,children:[(0,Q.jsxs)(`div`,{children:[`Type: `,_.type]}),(0,Q.jsxs)(`div`,{children:[`ID: `,_.id]}),(0,Q.jsxs)(`div`,{children:[`Position: `,_.position.x,`,`,` `,_.position.y]}),(0,Q.jsxs)(`div`,{children:[`Size: `,_.position.width,` ×`,` `,_.position.height]})]})]})]})}),(0,Q.jsx)(yf,{isOpen:y.isOpen,title:y.title,message:y.message,onConfirm:y.onConfirm,onCancel:y.onCancel})]})}var kf=[{name:`layout`,label:`Layout`,items:[{type:`container`,label:`Container`,defaultSize:{width:400,height:300}},{type:`flex`,label:`Flex`,defaultSize:{width:400,height:200}},{type:`grid`,label:`Grid`,defaultSize:{width:400,height:300}},{type:`card`,label:`Card`,defaultSize:{width:300,height:200}},{type:`tabs`,label:`Tabs`,defaultSize:{width:400,height:300}}]},{name:`form`,label:`Form`,items:[{type:`input`,label:`Input`,defaultSize:{width:300,height:60}},{type:`textarea`,label:`Textarea`,defaultSize:{width:300,height:120}},{type:`select`,label:`Select`,defaultSize:{width:300,height:60}},{type:`checkbox`,label:`Checkbox`,defaultSize:{width:200,height:40}},{type:`button`,label:`Button`,defaultSize:{width:120,height:40}}]},{name:`data`,label:`Data`,items:[{type:`table`,label:`Table`,defaultSize:{width:600,height:400}},{type:`chart`,label:`Chart`,defaultSize:{width:400,height:300}},{type:`list`,label:`List`,defaultSize:{width:300,height:400}},{type:`statistic`,label:`Statistic`,defaultSize:{width:200,height:100}}]}];function Af(e,t={}){return pf(e,t)}function jf(...e){return Xr(Qr(e))}var Mf=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function Nf(e,t=4,n=280,r=250,i=50,a=50){return e.map((e,o)=>({...e,position:{x:i+o%t*n,y:a+Math.floor(o/t)*r}}))}function Pf({entities:e=[],relationships:t=[],canvas:n={width:1200,height:800,showGrid:!0},showRelationshipLabels:r=!0,readOnly:i=!1,onEntitiesChange:a,onRelationshipsChange:o,className:s}){let c=(0,Z.useRef)(null),l=Af({entities:e,relationships:t},{maxHistory:50}),{entities:u,relationships:d}=l.current,f=(0,Z.useCallback)(e=>{l.push(e),a?.(e.entities),o?.(e.relationships)},[l,a,o]),p=mf(),m=hf(),h=m.count>0?Array.from(m.selectedIds)[0]:null,g=gf(),_=_f({minZoom:.25,maxZoom:3,zoomStep:.1}),v=Ef(),[y,b]=(0,Z.useState)(!0),[x,S]=(0,Z.useState)(!0),[C,w]=(0,Z.useState)(null),[T,E]=(0,Z.useState)(``),[D,O]=(0,Z.useState)(null),[k,A]=(0,Z.useState)(``),j=(0,Z.useRef)(null),M=(0,Z.useCallback)(()=>{if(i)return;let e=l.current,t={id:`entity-${Date.now()}`,name:`new_entity_${e.entities.length+1}`,label:`New Entity ${e.entities.length+1}`,fields:[{name:`id`,type:`uuid`,primaryKey:!0,required:!0},{name:`created_at`,type:`datetime`,required:!0},{name:`updated_at`,type:`datetime`,required:!0}],position:{x:50+e.entities.length%4*280,y:50+Math.floor(e.entities.length/4)*250}};f({entities:[...e.entities,t],relationships:e.relationships}),m.selectOne(t.id),v?.sendOperation({type:`insert`,userId:v?.currentUserId??``,elementId:t.id,data:{name:t.name,label:t.label}})},[i,l,f,m,v]),N=(0,Z.useCallback)(async e=>{if(i)return;let t=u.find(t=>t.id===e);if(!await p.confirm(`Delete Entity`,`Are you sure you want to delete "${t?.label??e}"? This action cannot be undone.`))return;let n=l.current;f({entities:n.entities.filter(t=>t.id!==e),relationships:n.relationships.filter(t=>t.sourceEntity!==e&&t.targetEntity!==e)}),m.isSelected(e)&&m.clearSelection(),v?.sendOperation({type:`delete`,userId:v?.currentUserId??``,elementId:e,data:{}})},[i,u,p,l,f,m,v]),P=(0,Z.useCallback)(async()=>{if(i||m.count===0)return;let e=Array.from(m.selectedIds);if(!await p.confirm(`Delete Entities`,`Are you sure you want to delete ${e.length} selected entity(s)? This action cannot be undone.`))return;let t=l.current,n=new Set(e);f({entities:t.entities.filter(e=>!n.has(e.id)),relationships:t.relationships.filter(e=>!n.has(e.sourceEntity)&&!n.has(e.targetEntity))}),m.clearSelection()},[i,m,p,l,f]),ee=(0,Z.useCallback)(()=>{if(i)return;let e=l.current;f({entities:Nf(e.entities),relationships:e.relationships})},[i,l,f]),F=(0,Z.useCallback)(()=>{let e=u.filter(e=>m.isSelected(e.id));e.length>0&&g.copy(e)},[u,m,g]),te=(0,Z.useCallback)(()=>{if(i)return;let e=g.paste();if(!e||e.length===0)return;let t=l.current,n=e.map((e,t)=>({...e,id:`entity-${Date.now()}-${t}`,name:`${e.name}_copy`,label:`${e.label} (Copy)`,position:{x:e.position.x+30,y:e.position.y+30}}));f({entities:[...t.entities,...n],relationships:t.relationships}),m.selectMany(n.map(e=>e.id))},[i,g,l,f,m]),I=(0,Z.useCallback)(e=>{if(i)return;let t=l.current;f({entities:t.entities.map(t=>{if(t.id!==e)return t;let n={name:`field_${t.fields.length+1}`,type:`text`,required:!1};return{...t,fields:[...t.fields,n]}}),relationships:t.relationships})},[i,l,f]),ne=(0,Z.useCallback)((e,t,n)=>{i||(w({entityId:e,fieldIndex:t}),E(n))},[i]),L=(0,Z.useCallback)(()=>{if(!C)return;let e=T.trim();if(e===``){w(null);return}let t=l.current;f({entities:t.entities.map(t=>{if(t.id!==C.entityId)return t;let n=t.fields.map((t,n)=>n===C.fieldIndex?{...t,name:e}:t);return{...t,fields:n}}),relationships:t.relationships}),w(null)},[C,T,l,f]),R=(0,Z.useCallback)(()=>{w(null)},[]),re=(0,Z.useCallback)((e,t)=>{i||(O(e),A(t))},[i]),z=(0,Z.useCallback)(()=>{if(!D)return;let e=k.trim();if(e===``){O(null);return}let t=l.current;f({entities:t.entities.map(t=>t.id===D?{...t,label:e}:t),relationships:t.relationships}),O(null)},[D,k,l,f]),B=(0,Z.useCallback)(()=>{O(null)},[]),ie=(0,Z.useCallback)((e,t,n)=>{if(i)return;let r=l.current;f({entities:r.entities.map(r=>{if(r.id!==e)return r;let i=r.fields.map((e,r)=>r===t?{...e,type:n}:e);return{...r,fields:i}}),relationships:r.relationships})},[i,l,f]),ae=(0,Z.useCallback)((e,t)=>{if(i||!u.find(e=>e.id===t))return;let n=e.target.getBoundingClientRect();j.current={entityId:t,offsetX:e.clientX-n.left,offsetY:e.clientY-n.top},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},[i,u]),V=(0,Z.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),oe=(0,Z.useCallback)(e=>{if(e.preventDefault(),!j.current)return;let t=e.currentTarget.getBoundingClientRect(),n=_.zoom,r=(e.clientX-t.left-_.panOffset.x)/n-j.current.offsetX,i=(e.clientY-t.top-_.panOffset.y)/n-j.current.offsetY,a=l.current;f({entities:a.entities.map(e=>e.id===j.current.entityId?{...e,position:{x:Math.max(0,Math.round(r)),y:Math.max(0,Math.round(i))}}:e),relationships:a.relationships}),j.current=null},[_.zoom,_.panOffset,l,f]),H=h?u.find(e=>e.id===h):null,se=H?[{name:`name`,label:`Name`,type:`text`,value:H.name,group:`General`},{name:`label`,label:`Label`,type:`text`,value:H.label,group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:H.description??``,group:`General`},{name:`color`,label:`Color`,type:`color`,value:H.color??`#3b82f6`,group:`Appearance`},{name:`position.x`,label:`X Position`,type:`number`,value:H.position.x,group:`Position`},{name:`position.y`,label:`Y Position`,type:`number`,value:H.position.y,group:`Position`}]:[],ce=(0,Z.useCallback)((e,t)=>{if(!h)return;let n=l.current;f({entities:n.entities.map(n=>n.id===h?e===`position.x`?{...n,position:{...n.position,x:Number(t)}}:e===`position.y`?{...n,position:{...n.position,y:Number(t)}}:{...n,[e]:t}:n),relationships:n.relationships})},[h,l,f]);(0,Z.useEffect)(()=>{let e=c.current;if(!e)return;let t=e=>{let t=e.target.tagName;if(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`)return;let n=e.ctrlKey||e.metaKey;n&&e.key===`z`?(e.preventDefault(),l.undo()):n&&(e.key===`y`||e.shiftKey&&e.key===`Z`)?(e.preventDefault(),l.redo()):n&&e.key===`c`?(e.preventDefault(),F()):n&&e.key===`v`?(e.preventDefault(),te()):(e.key===`Delete`||e.key===`Backspace`)&&m.count>0?(e.preventDefault(),P()):e.key===`Escape`&&(m.clearSelection(),w(null),O(null))};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[l,F,te,P,m]);let le=u.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:240,height:40+e.fields.length*24,color:e.color,selected:m.isSelected(e.id)}));return(0,Q.jsxs)(`div`,{ref:c,tabIndex:0,className:jf(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,s),children:[(0,Q.jsxs)(`div`,{className:`flex flex-col flex-1 min-w-0`,children:[(0,Q.jsxs)(`div`,{role:`toolbar`,"aria-label":`Designer toolbar`,className:`flex items-center gap-2 p-2 border-b bg-muted/20 flex-wrap`,children:[(0,Q.jsx)(Bt,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`font-medium text-sm`,children:`Data Model Designer`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 ml-2 border-l pl-2`,children:[(0,Q.jsx)(`button`,{onClick:()=>l.undo(),disabled:!l.canUndo,"aria-label":`Undo`,title:`Undo (Ctrl+Z)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Q.jsx)(Ue,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:()=>l.redo(),disabled:!l.canRedo,"aria-label":`Redo`,title:`Redo (Ctrl+Y)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Q.jsx)(Qe,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,Q.jsx)(`button`,{onClick:_.zoomOut,"aria-label":`Zoom Out`,title:`Zoom Out`,className:`p-1 rounded hover:bg-accent`,children:(0,Q.jsx)(Nr,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`span`,{className:`text-xs tabular-nums w-10 text-center`,children:[Math.round(_.zoom*100),`%`]}),(0,Q.jsx)(`button`,{onClick:_.zoomIn,"aria-label":`Zoom In`,title:`Zoom In`,className:`p-1 rounded hover:bg-accent`,children:(0,Q.jsx)(Hr,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:_.resetZoom,"aria-label":`Reset Zoom`,title:`Reset Zoom`,className:`p-1 rounded hover:bg-accent`,children:(0,Q.jsx)(W,{className:`h-3 w-3`})})]}),!i&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-l pl-2`,children:[(0,Q.jsx)(`button`,{onClick:F,disabled:m.count===0,"aria-label":`Copy`,title:`Copy (Ctrl+C)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Q.jsx)(qt,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:te,disabled:!g.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Q.jsx)(sn,{className:`h-3.5 w-3.5`})})]}),!i&&(0,Q.jsxs)(`button`,{onClick:ee,"aria-label":`Auto Layout`,title:`Auto Layout`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded border hover:bg-accent`,children:[(0,Q.jsx)(on,{className:`h-3 w-3`}),` Auto Layout`]}),(0,Q.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,Q.jsx)(me,{className:`h-3 w-3`}),(0,Q.jsxs)(`span`,{children:[v.users.length,` user`,v.users.length===1?``:`s`]})]}),m.count>1&&(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[m.count,` selected`]}),!i&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`button`,{onClick:M,"aria-label":`Add Entity`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90`,children:[(0,Q.jsx)(Mt,{className:`h-3 w-3`}),` Add Entity`]}),(0,Q.jsxs)(`button`,{"aria-label":`Add Relationship`,title:`Add Relationship (coming soon)`,className:`flex items-center gap-1 px-2 py-1 text-xs rounded bg-secondary text-secondary-foreground hover:bg-secondary/80`,children:[(0,Q.jsx)(Be,{className:`h-3 w-3`}),` Add Relationship`]})]})]}),(0,Q.jsxs)(`div`,{role:`region`,"aria-label":`Canvas`,className:`flex-1 overflow-auto bg-muted/10 p-4 relative`,onWheel:_.handleWheel,onMouseDown:_.startPan,onDragOver:V,onDrop:oe,children:[(0,Q.jsxs)(`div`,{className:`relative`,style:{width:n.width,minHeight:n.height,..._.transformStyle,backgroundImage:n.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:n.showGrid?`20px 20px`:void 0},children:[(0,Q.jsx)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:n.width,height:n.height,children:d.map(e=>{let t=u.find(t=>t.id===e.sourceEntity),n=u.find(t=>t.id===e.targetEntity);return!t||!n?null:(0,Q.jsxs)(`g`,{children:[(0,Q.jsx)(`line`,{x1:t.position.x+120,y1:t.position.y+50,x2:n.position.x+120,y2:n.position.y+50,stroke:`hsl(var(--primary))`,strokeWidth:`2`,strokeDasharray:e.type===`many-to-many`?`5,5`:void 0}),r&&e.label&&(0,Q.jsx)(`text`,{x:(t.position.x+n.position.x)/2+120,y:(t.position.y+n.position.y)/2+50-8,textAnchor:`middle`,className:`text-xs fill-muted-foreground`,children:e.label})]},e.id)})}),u.length===0&&(0,Q.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-muted-foreground text-sm`,children:`No entities in the model. Click 'Add Entity' to create your first entity.`}),u.map(e=>(0,Q.jsxs)(`div`,{role:`group`,"aria-label":e.label,draggable:!i,onDragStart:t=>ae(t,e.id),className:jf(`absolute rounded-lg border-2 bg-background shadow-sm w-60 select-none cursor-grab active:cursor-grabbing`,m.isSelected(e.id)?`border-primary ring-2 ring-primary/20`:`border-border hover:border-primary/50`),style:{left:e.position.x,top:e.position.y},onClick:t=>m.toggle(e.id,t.shiftKey),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 rounded-t-lg font-medium text-sm`,style:{backgroundColor:e.color??`hsl(var(--primary) / 0.1)`},children:[(0,Q.jsx)(Bt,{className:`h-3.5 w-3.5`}),D===e.id?(0,Q.jsx)(`input`,{type:`text`,value:k,onChange:e=>A(e.target.value),onBlur:z,onKeyDown:e=>{e.key===`Enter`&&z(),e.key===`Escape`&&B()},className:`text-sm font-medium px-1 py-0 border rounded bg-background w-32 focus:outline-none focus:ring-1 focus:ring-primary`,autoFocus:!0,onClick:e=>e.stopPropagation(),"data-testid":`entity-label-input-${e.id}`}):(0,Q.jsx)(`span`,{className:`truncate cursor-text`,onDoubleClick:t=>{t.stopPropagation(),re(e.id,e.label)},title:`Double-click to edit label`,"data-testid":`entity-label-${e.id}`,children:e.label}),!i&&(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),N(e.id)},"aria-label":`Delete ${e.label}`,className:`ml-auto p-0.5 rounded hover:bg-destructive/20`,children:(0,Q.jsx)(Rt,{className:`h-3 w-3 text-destructive`})})]}),(0,Q.jsx)(`div`,{className:`px-3 py-1 divide-y`,children:e.fields.map((t,n)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 py-1 text-xs`,children:[C&&C.entityId===e.id&&C.fieldIndex===n?(0,Q.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),onBlur:L,onKeyDown:e=>{e.key===`Enter`&&L(),e.key===`Escape`&&R()},className:`font-mono text-xs px-1 py-0 border rounded bg-background w-24 focus:outline-none focus:ring-1 focus:ring-primary`,autoFocus:!0,onClick:e=>e.stopPropagation()}):(0,Q.jsxs)(`span`,{className:jf(`font-mono cursor-text`,t.primaryKey&&`font-bold text-primary`),onClick:r=>{r.stopPropagation(),ne(e.id,n,t.name)},title:`Click to edit field name`,children:[t.primaryKey&&(0,Q.jsx)(`span`,{className:`text-[0.65rem] font-semibold text-primary mr-0.5`,children:`PK`}),t.name]}),i?(0,Q.jsx)(`span`,{className:`text-muted-foreground ml-auto`,children:t.type}):(0,Q.jsx)(`select`,{value:t.type,onChange:t=>{t.stopPropagation(),ie(e.id,n,t.target.value)},onClick:e=>e.stopPropagation(),className:`text-xs text-muted-foreground ml-auto bg-transparent border-none focus:ring-1 focus:ring-primary rounded cursor-pointer p-0`,"data-testid":`field-type-${e.id}-${n}`,children:Mf.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))}),t.required&&(0,Q.jsx)(`span`,{className:`text-destructive`,children:`*`})]},`${t.name}-${n}`))}),!i&&(0,Q.jsx)(`div`,{className:`px-3 py-1 border-t`,children:(0,Q.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),I(e.id)},"aria-label":`Add field to ${e.label}`,className:`flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground w-full py-0.5`,children:[(0,Q.jsx)(Mt,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),x&&u.length>0&&(0,Q.jsx)(wf,{items:le,canvasWidth:n.width,canvasHeight:n.height,position:`bottom-right`,size:150})]})]}),(0,Q.jsxs)(`div`,{className:`w-64 border-l flex flex-col bg-background shrink-0`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col flex-1 min-h-0`,children:[(0,Q.jsxs)(`button`,{onClick:()=>b(e=>!e),className:`flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 border-b`,"aria-expanded":y,"aria-controls":`property-editor-panel`,children:[y?(0,Q.jsx)(At,{className:`h-3 w-3`}):(0,Q.jsx)(be,{className:`h-3 w-3`}),`Properties`]}),y&&(0,Q.jsx)(`div`,{id:`property-editor-panel`,className:`flex-1 overflow-y-auto`,children:(0,Q.jsx)(xf,{title:H?H.label:`Properties`,fields:se,onChange:ce})})]}),(0,Q.jsx)(`div`,{className:`border-t`,children:(0,Q.jsxs)(`button`,{onClick:()=>S(e=>!e),className:`flex items-center gap-1 px-3 py-2 text-xs font-medium text-muted-foreground hover:bg-accent/50 w-full`,"aria-expanded":x,children:[x?(0,Q.jsx)(At,{className:`h-3 w-3`}):(0,Q.jsx)(be,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,Q.jsx)(yf,{isOpen:p.isOpen,title:p.title,message:p.message,onConfirm:p.onConfirm,onCancel:p.onCancel,destructive:!0})]})}function Ff(...e){return Xr(Qr(e))}var If=120,Lf=50;function Rf(e,t){if(e.length===0)return e;let n=new Map,r=new Map;for(let t of e)n.set(t.id,0),r.set(t.id,[]);for(let e of t)n.set(e.target,(n.get(e.target)??0)+1),r.get(e.source)?.push(e.target);let i=[],a=new Set,o=e.filter(e=>(n.get(e.id)??0)===0).map(e=>e.id);for(o.length===0&&(o=[e[0].id]);o.length>0;){i.push(o);for(let e of o)a.add(e);let e=new Set;for(let t of o)for(let n of r.get(t)??[])a.has(n)||e.add(n);o=Array.from(e)}let s=e.filter(e=>!a.has(e.id)).map(e=>e.id);s.length>0&&i.push(s);let c=new Map;for(let e=0;e<i.length;e++){let t=i[e];for(let n=0;n<t.length;n++)c.set(t[n],{x:80+e*200,y:80+n*100})}return e.map(e=>({...e,position:c.get(e.id)??e.position}))}function zf({processName:e=`New Process`,nodes:t=[],edges:n=[],lanes:r,canvas:i={width:1400,height:800,showGrid:!0},showMinimap:a=!0,showToolbar:o=!0,readOnly:s=!1,onNodesChange:c,onEdgesChange:l,className:u}){let d=pf({nodes:t,edges:n},{maxHistory:50}),f=d.current.nodes,p=d.current.edges,m=(0,Z.useCallback)((e,t)=>{d.push({nodes:e,edges:t}),c?.(e),l?.(t)},[d,c,l]),h=mf(),g=hf(),_=gf(),v=_f({initialZoom:1}),y=Ef(),[b,x]=(0,Z.useState)(null),[S,C]=(0,Z.useState)(!1),[w,T]=(0,Z.useState)(null),[E,D]=(0,Z.useState)(null),[O,k]=(0,Z.useState)(!0),[A,j]=(0,Z.useState)(null),[M,N]=(0,Z.useState)({x:0,y:0}),P=(0,Z.useRef)(null),ee=(0,Z.useRef)(c),F=(0,Z.useRef)(l);ee.current=c,F.current=l,(0,Z.useEffect)(()=>{ee.current?.(f),F.current?.(p)},[d.current]);let te=(0,Z.useCallback)((e,t)=>{if(s)return;let n={id:`node-${Date.now()}`,type:e,label:t,position:{x:200+f.length*160,y:200}};m([...f,n],p),x(n.id),g.selectOne(n.id),y?.sendOperation({type:`insert`,elementId:n.id,data:{label:t},userId:y.currentUserId??``})},[f,p,s,m,g,y]),I=(0,Z.useCallback)(async e=>{if(s)return;let t=f.find(t=>t.id===e);await h.confirm(`Delete Node`,`Are you sure you want to delete "${t?.label??e}"? This will also remove all connected edges.`)&&(m(f.filter(t=>t.id!==e),p.filter(t=>t.source!==e&&t.target!==e)),b===e&&x(null),g.clearSelection(),y?.sendOperation({type:`delete`,elementId:e,data:{},userId:y.currentUserId??``}))},[f,p,b,s,m,h,g,y]),ne=(0,Z.useCallback)(async()=>{if(s||g.count===0||!await h.confirm(`Delete Selected Nodes`,`Are you sure you want to delete ${g.count} selected node(s) and their connected edges?`))return;let e=g.selectedIds;m(f.filter(t=>!e.has(t.id)),p.filter(t=>!e.has(t.source)&&!e.has(t.target))),x(null),g.clearSelection()},[f,p,s,m,h,g]),L=(0,Z.useCallback)(()=>{let e=g.count>0?g.selectedIds:b?new Set([b]):new Set;if(e.size===0)return;let t=f.filter(t=>e.has(t.id));_.copy(t)},[f,b,g,_]),R=(0,Z.useCallback)(()=>{if(s)return;let e=_.paste();if(!e||e.length===0)return;let t=e.map(e=>({...e,id:`node-${Date.now()}-${Math.random().toString(36).slice(2,7)}`,position:{x:e.position.x+40,y:e.position.y+40}}));m([...f,...t],p),g.selectMany(t.map(e=>e.id)),x(t[0].id)},[s,f,p,_,m,g]),re=(0,Z.useCallback)(()=>{C(e=>e?(T(null),!1):!0)},[]),z=(0,Z.useCallback)(e=>{if(!S)return!1;if(!w)return T(e),!0;if(w===e)return!0;let t={id:`edge-${Date.now()}`,source:w,target:e};return m(f,[...p,t]),T(null),C(!1),y?.sendOperation({type:`insert`,elementId:t.id,data:{source:w,target:e},userId:y.currentUserId??``}),!0},[S,w,f,p,m,y]),B=(0,Z.useCallback)(()=>{s||f.length===0||m(Rf(f,p),p)},[f,p,s,m]),ie=(0,Z.useCallback)((e,t)=>{if(s||!f.find(e=>e.id===t))return;j(t);let n=e.target.getBoundingClientRect();N({x:e.clientX-n.left,y:e.clientY-n.top}),e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t)},[s,f]),ae=(0,Z.useCallback)(e=>{if(e.preventDefault(),s||!A)return;let t=e.currentTarget.getBoundingClientRect(),n=v.zoom,r=(e.clientX-t.left-v.panOffset.x)/n-M.x,i=(e.clientY-t.top-v.panOffset.y)/n-M.y,a=Math.max(0,Math.round(r/20)*20),o=Math.max(0,Math.round(i/20)*20);m(f.map(e=>e.id===A?{...e,position:{x:a,y:o}}:e),p),j(null)},[s,A,M,f,p,v.zoom,v.panOffset,m]),V=(0,Z.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),oe=(0,Z.useMemo)(()=>f.find(e=>e.id===b)??null,[f,b]),H=(0,Z.useMemo)(()=>oe?[{name:`label`,label:`Name`,type:`text`,value:oe.label,group:`General`},{name:`type`,label:`Type`,type:`select`,value:oe.type,options:[{label:`Start Event`,value:`start-event`},{label:`End Event`,value:`end-event`},{label:`User Task`,value:`user-task`},{label:`Service Task`,value:`service-task`},{label:`Script Task`,value:`script-task`},{label:`Exclusive Gateway`,value:`exclusive-gateway`},{label:`Parallel Gateway`,value:`parallel-gateway`},{label:`Inclusive Gateway`,value:`inclusive-gateway`}],group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:oe.description??``,group:`General`}]:[],[oe]),se=(0,Z.useCallback)((e,t)=>{s||!b||m(f.map(n=>n.id===b?{...n,[e]:t}:n),p)},[s,b,f,p,m]),ce=e=>{switch(e){case`start-event`:return`rounded-full bg-green-100 border-green-500 text-green-700`;case`end-event`:return`rounded-full bg-red-100 border-red-500 text-red-700`;case`exclusive-gateway`:case`parallel-gateway`:case`inclusive-gateway`:case`event-based-gateway`:return`rotate-45 bg-yellow-100 border-yellow-500 text-yellow-700`;case`user-task`:return`rounded bg-blue-100 border-blue-500 text-blue-700`;case`service-task`:case`script-task`:return`rounded bg-purple-100 border-purple-500 text-purple-700`;default:return`rounded bg-gray-100 border-gray-500 text-gray-700`}},ue=(0,Z.useMemo)(()=>f.map(e=>({id:e.id,x:e.position.x,y:e.position.y,width:If,height:Lf,selected:g.isSelected(e.id)||e.id===b})),[f,g,b]);(0,Z.useEffect)(()=>{let e=P.current;if(!e)return;let t=e=>{let t=e.target?.tagName;if(t===`INPUT`||t===`TEXTAREA`||t===`SELECT`)return;let n=e.ctrlKey||e.metaKey;if(n&&e.key===`z`&&!e.shiftKey){e.preventDefault(),d.undo();return}if(n&&e.key===`y`||n&&e.key===`z`&&e.shiftKey){e.preventDefault(),d.redo();return}if(n&&e.key===`c`){e.preventDefault(),L();return}if(n&&e.key===`v`){e.preventDefault(),R();return}if(e.key===`Delete`||e.key===`Backspace`){g.count>0?(e.preventDefault(),ne()):b&&(e.preventDefault(),I(b));return}if(e.key===`Escape`){S?(C(!1),T(null)):(x(null),g.clearSelection());return}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[b,S,g,d,L,R,I,ne]);let de=(0,Z.useCallback)(e=>{e.target===e.currentTarget&&(x(null),g.clearSelection(),S&&(C(!1),T(null)))},[S,g]);return(0,Q.jsxs)(`div`,{ref:P,tabIndex:0,className:Ff(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Q.jsx)(yf,{isOpen:h.isOpen,title:h.title,message:h.message,onConfirm:h.onConfirm,onCancel:h.onCancel,destructive:!0}),o&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 p-2 border-b bg-muted/20`,role:`toolbar`,"aria-label":`Process toolbar`,children:[(0,Q.jsx)(Zn,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`font-medium text-sm`,"aria-label":`Process name`,children:e}),y?.isConnected&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,role:`status`,"aria-label":`Collaboration active`,children:[(0,Q.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),y.users.length,` user`,y.users.length===1?``:`s`]}),(0,Q.jsx)(`div`,{className:`flex-1`}),!s&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(`button`,{onClick:()=>d.undo(),disabled:!d.canUndo,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Undo (Ctrl+Z)`,"aria-label":`Undo`,children:(0,Q.jsx)(Ue,{className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{onClick:()=>d.redo(),disabled:!d.canRedo,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Redo (Ctrl+Y)`,"aria-label":`Redo`,children:(0,Q.jsx)(Qe,{className:`h-3 w-3`})}),(0,Q.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Q.jsx)(`button`,{onClick:L,disabled:g.count===0&&!b,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Copy (Ctrl+C)`,"aria-label":`Copy`,children:(0,Q.jsx)(qt,{className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{onClick:R,disabled:!_.hasContent,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent disabled:opacity-40`,title:`Paste (Ctrl+V)`,"aria-label":`Paste`,children:(0,Q.jsx)(sn,{className:`h-3 w-3`})}),(0,Q.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Q.jsxs)(`button`,{onClick:re,className:Ff(`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,S&&`bg-primary text-primary-foreground`),title:`Connect nodes`,"aria-label":`Connect nodes`,"aria-pressed":S,children:[(0,Q.jsx)(Ze,{className:`h-3 w-3`}),` Connect`]}),(0,Q.jsxs)(`button`,{onClick:B,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Auto layout`,"aria-label":`Auto layout`,children:[(0,Q.jsx)(le,{className:`h-3 w-3`}),` Layout`]}),(0,Q.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Q.jsx)(`button`,{onClick:v.zoomIn,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Zoom in`,"aria-label":`Zoom in`,children:(0,Q.jsx)(Hr,{className:`h-3 w-3`})}),(0,Q.jsxs)(`span`,{className:`text-xs tabular-nums min-w-[3ch] text-center`,"aria-label":`Zoom level`,children:[Math.round(v.zoom*100),`%`]}),(0,Q.jsx)(`button`,{onClick:v.zoomOut,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Zoom out`,"aria-label":`Zoom out`,children:(0,Q.jsx)(Nr,{className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{onClick:v.resetZoom,className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Reset zoom`,"aria-label":`Reset zoom`,children:(0,Q.jsx)(W,{className:`h-3 w-3`})}),(0,Q.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Q.jsxs)(`button`,{onClick:()=>te(`start-event`,`Start`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Start Event`,"aria-label":`Add Start Event`,children:[(0,Q.jsx)(Me,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,Q.jsxs)(`button`,{onClick:()=>te(`user-task`,`User Task`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add User Task`,"aria-label":`Add User Task`,children:[(0,Q.jsx)(zn,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,Q.jsxs)(`button`,{onClick:()=>te(`exclusive-gateway`,`Decision`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add Gateway`,"aria-label":`Add Gateway`,children:[(0,Q.jsx)(Nt,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,Q.jsxs)(`button`,{onClick:()=>te(`end-event`,`End`),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:`Add End Event`,"aria-label":`Add End Event`,children:[(0,Q.jsx)(zn,{className:`h-3 w-3 text-red-600`}),` End`]}),(0,Q.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Q.jsx)(`button`,{onClick:()=>k(e=>!e),className:`flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-accent`,title:O?`Hide properties`:`Show properties`,"aria-label":O?`Hide property panel`:`Show property panel`,"aria-expanded":O,children:O?(0,Q.jsx)(hr,{className:`h-3 w-3`}):(0,Q.jsx)(nr,{className:`h-3 w-3`})})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-1 overflow-hidden`,children:[(0,Q.jsx)(`div`,{className:`flex-1 overflow-auto bg-muted/10 p-4`,role:`region`,"aria-label":`Process canvas`,onWheel:v.handleWheel,onMouseDown:v.startPan,children:(0,Q.jsxs)(`div`,{className:`relative`,style:{...v.transformStyle,width:i.width,minHeight:i.height,backgroundImage:i.showGrid?`radial-gradient(circle, hsl(var(--border)) 1px, transparent 1px)`:void 0,backgroundSize:i.showGrid?`20px 20px`:void 0},onClick:de,onDrop:ae,onDragOver:V,children:[(0,Q.jsxs)(`svg`,{className:`absolute inset-0 pointer-events-none`,width:i.width,height:i.height,children:[(0,Q.jsx)(`defs`,{children:(0,Q.jsx)(`marker`,{id:`arrowhead`,markerWidth:`10`,markerHeight:`7`,refX:`10`,refY:`3.5`,orient:`auto`,children:(0,Q.jsx)(`polygon`,{points:`0 0, 10 3.5, 0 7`,fill:`hsl(var(--foreground))`})})}),p.map(e=>{let t=f.find(t=>t.id===e.source),n=f.find(t=>t.id===e.target);if(!t||!n)return null;t.position.x+If/2;let r=t.position.y+Lf/2;n.position.x+If/2;let i=n.position.y+Lf/2,a=t.position.x+If,o=r,s=n.position.x,c=i;return(0,Q.jsxs)(`g`,{children:[(0,Q.jsx)(`path`,{d:`M ${a} ${o} Q ${(a+s)/2} ${o}, ${(a+s)/2} ${(o+c)/2} T ${s} ${c}`,fill:`none`,stroke:`hsl(var(--foreground) / 0.5)`,strokeWidth:`2`,markerEnd:`url(#arrowhead)`}),e.label&&(0,Q.jsx)(`text`,{x:(a+s)/2,y:(o+c)/2-8,textAnchor:`middle`,className:`text-[10px] fill-muted-foreground`,children:e.label})]},e.id)})]}),f.length===0&&(0,Q.jsx)(`div`,{className:`flex items-center justify-center h-full min-h-[200px] text-muted-foreground text-sm`,children:`No nodes in the process. Use the toolbar buttons to add start events, tasks, gateways, and end events.`}),f.map(e=>{let t=g.isSelected(e.id)||b===e.id,n=w===e.id,r=E===e.id,i=S||r;return(0,Q.jsxs)(`div`,{className:`absolute select-none`,style:{left:e.position.x,top:e.position.y},role:`group`,"aria-label":e.label,draggable:!s&&!S,onDragStart:t=>ie(t,e.id),onMouseEnter:()=>D(e.id),onMouseLeave:()=>D(null),onClick:t=>{z(e.id)||(t.shiftKey?g.toggle(e.id,!0):(x(e.id),g.selectOne(e.id)))},children:[(0,Q.jsx)(`div`,{className:Ff(`flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow`,ce(e.type),t&&`ring-2 ring-primary shadow-md`,n&&`ring-2 ring-blue-400 shadow-lg`,S&&!n&&`cursor-crosshair`),children:(0,Q.jsx)(`span`,{className:Ff(`text-xs font-medium`,(e.type===`exclusive-gateway`||e.type===`parallel-gateway`||e.type===`inclusive-gateway`||e.type===`event-based-gateway`)&&`-rotate-45`),children:e.label})}),i&&!s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{left:-6,top:Lf/2-6},title:`Input port`,onClick:t=>{t.stopPropagation(),z(e.id)}}),(0,Q.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-500 border-2 border-white shadow cursor-crosshair`,style:{right:-6,top:Lf/2-6},title:`Output port`,onClick:t=>{t.stopPropagation(),S?z(e.id):(C(!0),T(e.id))}}),(0,Q.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:If/2-6,top:-6},title:`Port`,onClick:t=>{t.stopPropagation(),z(e.id)}}),(0,Q.jsx)(`div`,{className:`absolute w-3 h-3 rounded-full bg-blue-400 border-2 border-white shadow cursor-crosshair`,style:{left:If/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),z(e.id)}})]}),!s&&t&&!S&&(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),I(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":`Delete node`,children:(0,Q.jsx)(Rt,{className:`h-3 w-3`})})]},e.id)}),a&&f.length>0&&(0,Q.jsx)(wf,{items:ue,canvasWidth:i.width??1400,canvasHeight:i.height??800,position:`bottom-right`})]})}),O&&!s&&(0,Q.jsx)(`div`,{className:`w-64 border-l bg-background overflow-y-auto shrink-0`,role:`complementary`,"aria-label":`Property panel`,children:(0,Q.jsx)(xf,{title:oe?`Properties: ${oe.label}`:`Properties`,fields:H,onChange:se})})]})]})}function Bf(...e){return Xr(Qr(e))}var $={untitledReport:`Untitled Report`,reportCanvas:`Report canvas`,properties:`Properties`,propertiesPanel:`Properties panel`,designerToolbar:`Report designer toolbar`,selectElementPrompt:`Select an element to edit its properties`,addElementsPrompt:`Add elements using the buttons above`,addText:`Add Text`,addField:`Add Field`,addImage:`Add Image`,addChart:`Add Chart`,addTable:`Add Table`,undo:`Undo`,undoShortcut:`Undo (Ctrl+Z)`,redo:`Redo`,redoShortcut:`Redo (Ctrl+Shift+Z)`,copy:`Copy`,copyShortcut:`Copy (Ctrl+C)`,paste:`Paste`,pasteShortcut:`Paste (Ctrl+V)`,deleteSelected:`Delete selected`,deleteElement:`Delete element`,deleteElementsTitle:`Delete elements`,deleteElementMessage:e=>`Are you sure you want to delete ${e} element${e>1?`s`:``}?`,collapsePanel:`Collapse panel`,expandPanel:`Expand panel`,collaborationConnected:`Connected`,sectionHeader:`Report Header`,sectionPageHeader:`Page Header`,sectionGroupHeader:`Group Header`,sectionDetail:`Detail`,sectionGroupFooter:`Group Footer`,sectionPageFooter:`Page Footer`,sectionFooter:`Report Footer`,elementText:`Text`,elementImage:`🖼 Image`,elementChart:`📊 Chart`,elementTable:`📋 Table`,propLabel:`Label`,propX:`X`,propY:`Y`,propWidth:`Width`,propHeight:`Height`,propText:`Text`,propField:`Field`,groupPosition:`Position`,groupSize:`Size`,groupContent:`Content`,groupGeneral:`General`},Vf={A4:{width:595,height:842},A3:{width:842,height:1191},Letter:{width:612,height:792},Legal:{width:612,height:1008},Tabloid:{width:792,height:1224}},Hf=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function Uf({reportName:e=$.untitledReport,objectName:t,pageSize:n=`A4`,orientation:r=`portrait`,margins:i={top:40,right:40,bottom:40,left:40},sections:a=[],showToolbar:o=!0,showPropertyPanel:s=!0,readOnly:c=!1,onSectionsChange:l,className:u}){let d=pf(a.length>0?a:Hf),f=d.current,p=(0,Z.useCallback)(e=>{d.push(e),l?.(e)},[d,l]),m=hf(),h=(0,Z.useMemo)(()=>{let e=Array.from(m.selectedIds);return e.length>0?e[0]:null},[m.selectedIds]),g=gf(),_=mf(),v=Ef(),y=(0,Z.useCallback)(e=>{v&&v.sendOperation({...e,userId:v.currentUserId??``})},[v]),[b,x]=(0,Z.useState)(!0),S=(0,Z.useRef)(null),C=(0,Z.useRef)(null),w=Vf[n],T=r===`landscape`?w.height:w.width,E=r===`landscape`?w.width:w.height,D=e=>{switch(e){case`header`:return $.sectionHeader;case`page-header`:return $.sectionPageHeader;case`group-header`:return $.sectionGroupHeader;case`detail`:return $.sectionDetail;case`group-footer`:return $.sectionGroupFooter;case`page-footer`:return $.sectionPageFooter;case`footer`:return $.sectionFooter;default:return e}},O=(0,Z.useMemo)(()=>h?f.flatMap(e=>e.elements).find(e=>e.id===h):null,[h,f]),k=(0,Z.useCallback)((e,t)=>{if(c)return;let n={id:`elem-${Date.now()}`,type:t,position:{x:i.left,y:10,width:200,height:30},properties:{text:t===`text`?`New Text`:void 0,field:t===`field`?`field_name`:void 0}};p(f.map((t,r)=>r===e?{...t,elements:[...t.elements,n]}:t)),m.selectOne(n.id),y({type:`insert`,elementId:n.id,data:{element:n}})},[f,i.left,c,p,m,y]),A=(0,Z.useCallback)(e=>{c||(p(f.map(t=>({...t,elements:t.elements.filter(t=>t.id!==e)}))),m.isSelected(e)&&m.clearSelection(),y({type:`delete`,elementId:e,data:{}}))},[f,c,p,m,y]),j=(0,Z.useCallback)(async()=>{if(c||m.count===0||!await _.confirm($.deleteElementsTitle,$.deleteElementMessage(m.count)))return;let e=m.selectedIds;p(f.map(t=>({...t,elements:t.elements.filter(t=>!e.has(t.id))}))),m.clearSelection(),e.forEach(e=>{y({type:`delete`,elementId:e,data:{}})})},[c,m,_,f,p,y]),M=(0,Z.useCallback)((e,t)=>{c||!h||(p(f.map(n=>({...n,elements:n.elements.map(n=>n.id===h?e===`x`?{...n,position:{...n.position,x:Number(t)}}:e===`y`?{...n,position:{...n.position,y:Number(t)}}:e===`width`?{...n,position:{...n.position,width:Number(t)}}:e===`height`?{...n,position:{...n.position,height:Number(t)}}:{...n,properties:{...n.properties,[e]:t}}:n)}))),y({type:`update`,elementId:h,data:{[e]:t}}))},[c,h,f,p,y]),N=(0,Z.useCallback)(()=>{let e=m.selectedIds;if(e.size===0)return;let t=f.flatMap(e=>e.elements).filter(t=>e.has(t.id));g.copy(t)},[m,f,g]),P=(0,Z.useCallback)(()=>{if(c)return;let e=g.paste();if(!e||e.length===0)return;let t=0,n=e.map(e=>({...e,id:`elem-${Date.now()}-${++t}-${Math.random().toString(36).slice(2,7)}`,position:{...e.position,x:e.position.x+20,y:e.position.y+20}})),r=f.findIndex(e=>e.type===`detail`),i=r>=0?r:0;p(f.map((e,t)=>t===i?{...e,elements:[...e.elements,...n]}:e)),m.selectMany(n.map(e=>e.id)),n.forEach(e=>{y({type:`insert`,elementId:e.id,data:{element:e}})})},[c,g,f,p,m,y]),ee=(0,Z.useCallback)((e,t,n)=>{c||(S.current={id:t.id,sectionIndex:n,startX:e.clientX,startY:e.clientY},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,t.id))},[c]),F=(0,Z.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),te=(0,Z.useCallback)((e,t)=>{e.preventDefault();let n=S.current;if(!n||c)return;let r=e.clientX-n.startX,i=e.clientY-n.startY;if(n.sectionIndex===t)p(f.map((e,a)=>a===t?{...e,elements:e.elements.map(e=>e.id===n.id?{...e,position:{...e.position,x:Math.max(0,e.position.x+r),y:Math.max(0,(typeof e.position.y==`number`?e.position.y:0)+i)}}:e)}:e));else{let e=null,i=f.map((t,i)=>{if(i!==n.sectionIndex)return t;let a=t.elements.find(e=>e.id===n.id);return a&&(e={...a,position:{...a.position,x:Math.max(0,a.position.x+r),y:10}}),{...t,elements:t.elements.filter(e=>e.id!==n.id)}});e&&p(i.map((n,r)=>r===t?{...n,elements:[...n.elements,e]}:n))}y({type:`move`,elementId:n.id,data:{}}),S.current=null},[c,f,p,y]),I=(0,Z.useMemo)(()=>{if(!O)return[];let e=[{name:`x`,label:$.propX,type:`number`,value:O.position.x,group:$.groupPosition},{name:`y`,label:$.propY,type:`number`,value:O.position.y,group:$.groupPosition},{name:`width`,label:$.propWidth,type:`number`,value:O.position.width,group:$.groupSize},{name:`height`,label:$.propHeight,type:`number`,value:O.position.height,group:$.groupSize}];return O.type===`text`&&e.push({name:`text`,label:$.propText,type:`text`,value:O.properties.text??``,group:$.groupContent}),O.type===`field`&&e.push({name:`field`,label:$.propField,type:`text`,value:O.properties.field??``,group:$.groupContent}),e},[O]);return(0,Z.useEffect)(()=>{let e=C.current;if(!e)return;let t=e=>{let t=[`INPUT`,`TEXTAREA`,`SELECT`].includes(e.target.tagName),n=e.ctrlKey||e.metaKey;if((e.key===`Delete`||e.key===`Backspace`)&&m.count>0&&!t){e.preventDefault(),j();return}if(e.key===`Escape`){m.clearSelection();return}if(!t){if(n&&e.key===`z`&&!e.shiftKey&&!c){e.preventDefault(),d.undo();return}if(n&&(e.key===`z`&&e.shiftKey||e.key===`y`)&&!c){e.preventDefault(),d.redo();return}if(n&&e.key===`c`){e.preventDefault(),N();return}if(n&&e.key===`v`&&!c){e.preventDefault(),P();return}if(n&&e.key===`a`){e.preventDefault();let t=f.flatMap(e=>e.elements).map(e=>e.id);m.selectMany(t);return}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[m,j,c,d,N,P,f]),(0,Q.jsxs)(`div`,{ref:C,tabIndex:0,className:Bf(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Q.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0`,children:[o&&(0,Q.jsxs)(`div`,{role:`toolbar`,"aria-label":$.designerToolbar,className:`flex items-center gap-2 p-2 border-b bg-muted/20`,children:[(0,Q.jsx)(ye,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`font-medium text-sm`,children:e}),t&&(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,t,`)`]}),!c&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`}),(0,Q.jsx)(`button`,{className:Bf(`p-1.5 rounded hover:bg-accent`,!d.canUndo&&`opacity-40 pointer-events-none`),title:$.undoShortcut,"aria-label":$.undo,disabled:!d.canUndo,onClick:()=>d.undo(),children:(0,Q.jsx)(Ue,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{className:Bf(`p-1.5 rounded hover:bg-accent`,!d.canRedo&&`opacity-40 pointer-events-none`),title:$.redoShortcut,"aria-label":$.redo,disabled:!d.canRedo,onClick:()=>d.redo(),children:(0,Q.jsx)(Qe,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{className:Bf(`p-1.5 rounded hover:bg-accent`,m.count===0&&`opacity-40 pointer-events-none`),title:$.copyShortcut,"aria-label":$.copy,disabled:m.count===0,onClick:N,children:(0,Q.jsx)(qt,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{className:Bf(`p-1.5 rounded hover:bg-accent`,!g.hasContent&&`opacity-40 pointer-events-none`),title:$.pasteShortcut,"aria-label":$.paste,disabled:!g.hasContent,onClick:P,children:(0,Q.jsx)(sn,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Q.jsx)(`button`,{className:Bf(`p-1.5 rounded hover:bg-accent`,m.count===0&&`opacity-40 pointer-events-none`),title:$.deleteSelected,"aria-label":$.deleteSelected,disabled:m.count===0,onClick:j,children:(0,Q.jsx)(Rt,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`flex-1`}),v?.isConnected&&(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`span`,{className:`inline-block h-2 w-2 rounded-full bg-green-500`}),$.collaborationConnected,v.users.length>1&&` (${v.users.length})`]}),(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[n,` `,r]}),s&&(0,Q.jsx)(`button`,{className:`p-1.5 rounded hover:bg-accent`,title:b?$.collapsePanel:$.expandPanel,"aria-label":b?$.collapsePanel:$.expandPanel,onClick:()=>x(e=>!e),children:(0,Q.jsx)(hr,{className:Bf(`h-4 w-4`,!b&&`rotate-180`)})})]}),(0,Q.jsx)(`div`,{role:`region`,"aria-label":$.reportCanvas,className:`flex-1 overflow-auto bg-muted/10 p-4 flex justify-center`,children:(0,Q.jsx)(`div`,{className:`bg-white shadow-lg border`,style:{width:T,minHeight:E},children:f.map((e,t)=>(0,Q.jsxs)(`div`,{className:`relative border-b border-dashed border-gray-300`,style:{minHeight:e.height},onDragOver:F,onDrop:e=>te(e,t),children:[(0,Q.jsxs)(`div`,{className:`absolute left-0 top-0 px-2 py-0.5 bg-muted text-xs text-muted-foreground border-r border-b rounded-br`,children:[D(e.type),e.repeat&&` ↻`]}),!c&&(0,Q.jsxs)(`div`,{className:`absolute right-1 top-0 flex items-center gap-0.5`,children:[(0,Q.jsx)(`button`,{onClick:()=>k(t,`text`),className:`p-0.5 rounded hover:bg-accent`,title:$.addText,"aria-label":$.addText,children:(0,Q.jsx)(tt,{className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{onClick:()=>k(t,`field`),className:`p-0.5 rounded hover:bg-accent`,title:$.addField,"aria-label":$.addField,children:(0,Q.jsx)(Mt,{className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{onClick:()=>k(t,`image`),className:`p-0.5 rounded hover:bg-accent`,title:$.addImage,"aria-label":$.addImage,children:(0,Q.jsx)(Ut,{className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{onClick:()=>k(t,`chart`),className:`p-0.5 rounded hover:bg-accent`,title:$.addChart,"aria-label":$.addChart,children:(0,Q.jsx)(st,{className:`h-3 w-3`})}),(0,Q.jsx)(`button`,{onClick:()=>k(t,`table`),className:`p-0.5 rounded hover:bg-accent`,title:$.addTable,"aria-label":$.addTable,children:(0,Q.jsx)(vt,{className:`h-3 w-3`})})]}),(0,Q.jsxs)(`div`,{className:`relative`,style:{minHeight:e.height,paddingTop:24},children:[e.elements.length===0&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground text-center pt-4`,children:$.addElementsPrompt}),e.elements.map(e=>{let n=m.isSelected(e.id);return(0,Q.jsxs)(`div`,{draggable:!c,onDragStart:n=>ee(n,e,t),className:Bf(`absolute border rounded px-2 py-1 text-xs cursor-pointer`,n?`border-primary ring-1 ring-primary/30 bg-primary/5`:`border-dashed border-gray-400 hover:border-primary/50`),style:{left:e.position.x,top:(typeof e.position.y==`number`?e.position.y:0)+24,width:e.position.width,height:e.position.height},onClick:t=>m.toggle(e.id,t.shiftKey),children:[(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.type===`text`&&(e.properties.text??$.elementText),e.type===`field`&&`{${e.properties.field??`field`}}`,e.type===`image`&&$.elementImage,e.type===`chart`&&$.elementChart,e.type===`table`&&$.elementTable]}),!c&&n&&(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),A(e.id)},className:`absolute -top-2 -right-2 p-0.5 rounded-full bg-destructive text-destructive-foreground shadow`,"aria-label":$.deleteElement,children:(0,Q.jsx)(Rt,{className:`h-2.5 w-2.5`})})]},e.id)})]})]},`${e.type}-${t}`))})})]}),s&&(0,Q.jsx)(`div`,{role:`region`,"aria-label":$.propertiesPanel,className:Bf(`border-l bg-muted/30 flex flex-col transition-[width] duration-200`,b?`w-56`:`w-0 overflow-hidden`),children:b&&(h&&O?(0,Q.jsx)(xf,{title:`${$.properties} – ${O.type}`,fields:I,onChange:M}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`p-3 border-b font-medium text-sm`,children:$.properties}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-y-auto p-3`,children:(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground text-center py-4`,children:$.selectElementPrompt})})]}))}),(0,Q.jsx)(yf,{isOpen:_.isOpen,title:_.title,message:_.message,onConfirm:_.onConfirm,onCancel:_.onCancel})]})}var Wf={"appDesigner.basicInfo":`Basic Info`,"appDesigner.objects":`Objects`,"appDesigner.navigation":`Navigation`,"appDesigner.branding":`Branding`,"appDesigner.stepBasicDesc":`Name, title, and layout`,"appDesigner.stepObjectsDesc":`Select business objects`,"appDesigner.stepNavigationDesc":`Build navigation tree`,"appDesigner.stepBrandingDesc":`Logo, colors, and favicon`,"appDesigner.appName":`App Name`,"appDesigner.appTitle":`Title`,"appDesigner.appDescription":`Description`,"appDesigner.appIcon":`Icon`,"appDesigner.template":`Template`,"appDesigner.layout":`Layout`,"appDesigner.layoutSidebar":`Sidebar`,"appDesigner.layoutHeader":`Header`,"appDesigner.layoutEmpty":`Empty`,"appDesigner.snakeCaseHint":`Must be snake_case (e.g. my_app)`,"appDesigner.searchObjects":`Search objects…`,"appDesigner.selectAll":`Select All`,"appDesigner.deselectAll":`Deselect All`,"appDesigner.noObjectsFound":`No objects found.`,"appDesigner.addGroup":`Add Group`,"appDesigner.addUrl":`Add URL`,"appDesigner.addSeparator":`Add Separator`,"appDesigner.noNavItemsHint":`No navigation items yet. Select objects in the previous step or add items manually.`,"appDesigner.separatorLabel":`— Separator —`,"appDesigner.newGroup":`New Group`,"appDesigner.newLink":`New Link`,"appDesigner.logoUrl":`Logo URL`,"appDesigner.primaryColor":`Primary Color`,"appDesigner.faviconUrl":`Favicon URL`,"appDesigner.preview":`Preview`,"common.cancel":`Cancel`,"common.back":`Back`,"common.next":`Next`,"common.close":`Close`,"appDesigner.complete":`Complete`,"appDesigner.saveDraft":`Save Draft`,"appDesigner.cancelConfirmTitle":`Discard changes?`,"appDesigner.cancelConfirmMessage":`You have unsaved changes. Are you sure you want to cancel?`,"appDesigner.confirmDiscard":`Discard`,"appDesigner.keepEditing":`Keep Editing`,"appDesigner.navNoItems":`No navigation items. Click buttons above to add items.`,"appDesigner.navNoPreviewItems":`No items`,"appDesigner.navLivePreview":`Live Preview`,"appDesigner.navCollapseGroup":`Collapse group`,"appDesigner.navExpandGroup":`Expand group`,"appDesigner.navAddChild":`Add child`,"appDesigner.navMoveUp":`Move up`,"appDesigner.navMoveDown":`Move down`,"appDesigner.navRemove":`Remove`,"appDesigner.navObjectPage":`Object Page`,"appDesigner.navDashboard":`Dashboard`,"appDesigner.navPage":`Page`,"appDesigner.navReport":`Report`,"appDesigner.navGroup":`Group`,"appDesigner.navUrl":`URL`,"appDesigner.navSeparator":`Separator`,"appDesigner.navTypeObject":`Object`,"appDesigner.navTypeDashboard":`Dashboard`,"appDesigner.navTypePage":`Page`,"appDesigner.navTypeReport":`Report`,"appDesigner.navTypeUrl":`URL`,"appDesigner.navTypeGroup":`Group`,"appDesigner.navTypeSeparator":`Separator`,"appDesigner.navTypeAction":`Action`,"appDesigner.navEditIcon":`Edit icon`,"appDesigner.navToggleVisible":`Toggle visibility`,"appDesigner.navHidden":`Hidden`,"appDesigner.navExportSchema":`Export JSON`,"appDesigner.navImportSchema":`Import JSON`,"appDesigner.navExportSuccess":`Navigation schema exported`,"appDesigner.navImportSuccess":`Navigation schema imported`,"appDesigner.navImportError":`Invalid navigation JSON`,"appDesigner.navIconPlaceholder":`Icon name (e.g. Users)`,"appDesigner.dashboardEditor":`Dashboard Editor`,"appDesigner.noWidgets":`No widgets. Click a button above to add one.`,"appDesigner.widgetLayoutSize":`Layout Size`,"appDesigner.widgetWidth":`Width`,"appDesigner.widgetHeight":`Height`,"appDesigner.dashboardPreview":`Dashboard Preview`,"appDesigner.noWidgetsPreview":`No widgets to preview`,"appDesigner.pageCanvasEditor":`Page Canvas Editor`,"appDesigner.emptyPage":`Empty page. Click a button above to add a component.`,"appDesigner.pagePreview":`Page Preview`,"appDesigner.noComponentsPreview":`No components to preview`,"appDesigner.modePage":`Page`,"appDesigner.modeDashboard":`Dashboard`,"appDesigner.undo":`Undo`,"appDesigner.redo":`Redo`,"appDesigner.brandingEditor":`Branding Editor`,"appDesigner.brandingExport":`Export JSON`,"appDesigner.brandingImport":`Import JSON`,"appDesigner.brandingPreview":`Preview`,"appDesigner.brandingSampleButton":`Sample Button`,"appDesigner.brandingSampleText":`This is how your brand theme will look.`,"appDesigner.colorPalette":`Color Palette`,"appDesigner.fontFamily":`Font Family`,"appDesigner.fontDefault":`Default (System)`,"appDesigner.modeLight":`Light`,"appDesigner.modeDark":`Dark`,"appDesigner.mobilePreview":`Mobile Preview`,"appDesigner.objectManager.title":`Object Manager`,"appDesigner.objectManager.addObject":`New Object`,"appDesigner.objectManager.searchPlaceholder":`Search objects…`,"appDesigner.objectManager.noObjects":`No objects found.`,"appDesigner.objectManager.objectName":`API Name`,"appDesigner.objectManager.objectLabel":`Label`,"appDesigner.objectManager.pluralLabel":`Plural Label`,"appDesigner.objectManager.icon":`Icon`,"appDesigner.objectManager.selectIcon":`Select icon…`,"appDesigner.objectManager.group":`Group`,"appDesigner.objectManager.noGroup":`No Group`,"appDesigner.objectManager.sortOrder":`Sort Order`,"appDesigner.objectManager.enabled":`Enabled`,"appDesigner.objectManager.relationships":`Relationships`,"appDesigner.objectManager.systemBadge":`System`,"appDesigner.objectManager.fieldCount":`{{count}} fields`,"appDesigner.objectManager.ungrouped":`Ungrouped`,"appDesigner.objectManager.deleteConfirmTitle":`Delete Object?`,"appDesigner.objectManager.deleteConfirmMessage":`This will permanently delete the object and all its fields. This action cannot be undone.`,"appDesigner.fieldDesigner.title":`Field Designer`,"appDesigner.fieldDesigner.addField":`New Field`,"appDesigner.fieldDesigner.searchPlaceholder":`Search fields…`,"appDesigner.fieldDesigner.allTypes":`All Types`,"appDesigner.fieldDesigner.noFields":`No fields found.`,"appDesigner.fieldDesigner.fieldName":`API Name`,"appDesigner.fieldDesigner.fieldLabel":`Label`,"appDesigner.fieldDesigner.fieldType":`Type`,"appDesigner.fieldDesigner.fieldGroup":`Group`,"appDesigner.fieldDesigner.description":`Description`,"appDesigner.fieldDesigner.required":`Required`,"appDesigner.fieldDesigner.unique":`Unique`,"appDesigner.fieldDesigner.readOnly":`Read Only`,"appDesigner.fieldDesigner.hidden":`Hidden`,"appDesigner.fieldDesigner.indexed":`Indexed`,"appDesigner.fieldDesigner.externalId":`External ID`,"appDesigner.fieldDesigner.trackHistory":`Track History`,"appDesigner.fieldDesigner.defaultValue":`Default Value`,"appDesigner.fieldDesigner.placeholder":`Placeholder`,"appDesigner.fieldDesigner.referenceTo":`Reference To`,"appDesigner.fieldDesigner.formula":`Formula`,"appDesigner.fieldDesigner.options":`Options`,"appDesigner.fieldDesigner.addOption":`Add Option`,"appDesigner.fieldDesigner.validationRules":`Validation Rules`,"appDesigner.fieldDesigner.addRule":`Add Rule`,"appDesigner.fieldDesigner.systemBadge":`System`,"appDesigner.fieldDesigner.ungrouped":`General`,"appDesigner.fieldDesigner.deleteConfirmTitle":`Delete Field?`,"appDesigner.fieldDesigner.deleteConfirmMessage":`This will permanently delete the field. Existing data in this field will be lost.`,"appDesigner.fieldDesigner.basicSection":`Basic`,"appDesigner.fieldDesigner.typeSpecificSection":`Type Settings`,"appDesigner.fieldDesigner.advancedSection":`Advanced`,"appDesigner.fieldDesigner.typeCategory.text":`Text`,"appDesigner.fieldDesigner.typeCategory.number":`Number`,"appDesigner.fieldDesigner.typeCategory.date":`Date & Time`,"appDesigner.fieldDesigner.typeCategory.choice":`Choice`,"appDesigner.fieldDesigner.typeCategory.relation":`Relation`,"appDesigner.fieldDesigner.typeCategory.advanced":`Advanced`,"common.edit":`Edit`};function Gf(e){return(t,n)=>{let r=e[t]||t;if(n)for(let[e,t]of Object.entries(n))r=r.replace(`{{${e}}}`,String(t));return r}}function Kf(){try{let e=H();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:Gf(Wf)}:{t:e.t}}catch{return{t:Gf(Wf)}}}function qf(...e){return Xr(Qr(e))}var Jf={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function Yf(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var Xf=0;function Zf(e){return Xf+=1,`${e}_${Date.now()}_${Xf}`}function Qf({steps:e,currentIndex:t,onStepClick:n}){return(0,Q.jsx)(`nav`,{className:`flex items-center justify-center gap-0 px-4 py-6`,children:e.map((e,r)=>{let i=r<t,a=r===t;return(0,Q.jsxs)(Z.Fragment,{children:[r>0&&(0,Q.jsx)(`div`,{className:qf(`h-0.5 w-12 sm:w-20`,i?`bg-blue-500`:`bg-gray-200`)}),(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`wizard-step-${e.id}`,onClick:()=>n(r),className:qf(`flex flex-col items-center gap-1 outline-none focus-visible:ring-2 focus-visible:ring-blue-400 rounded-lg px-2 py-1`,a&&`cursor-default`,!a&&`cursor-pointer`),children:[(0,Q.jsx)(`div`,{className:qf(`flex h-8 w-8 items-center justify-center rounded-full text-sm font-semibold transition-colors`,i&&`bg-blue-500 text-white`,a&&`bg-blue-600 text-white ring-2 ring-blue-300`,!i&&!a&&`bg-gray-200 text-gray-500`),children:i?(0,Q.jsx)(Ee,{className:`h-4 w-4`}):r+1}),(0,Q.jsx)(`span`,{className:qf(`text-xs font-medium`,a?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function $f({draft:e,templates:t,readOnly:n,onChange:r,t:i}){let a=e.name.length>0&&!L(e.name);return(0,Q.jsxs)(`div`,{"data-testid":`wizard-step-basic-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`label`,{htmlFor:`app-name`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appName`),` `,(0,Q.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,Q.jsx)(`input`,{id:`app-name`,"data-testid":`app-name-input`,type:`text`,value:e.name,onChange:e=>r({name:e.target.value}),placeholder:`my_app`,disabled:n,className:qf(`block w-full rounded-md border px-3 py-2 text-sm shadow-sm outline-none transition-colors`,`focus:border-blue-500 focus:ring-1 focus:ring-blue-500`,`disabled:cursor-not-allowed disabled:bg-gray-50`,a?`border-red-400`:`border-gray-300`)}),a&&(0,Q.jsx)(`p`,{className:`text-xs text-red-500`,children:i(`appDesigner.snakeCaseHint`)})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsxs)(`label`,{htmlFor:`app-title`,className:`block text-sm font-medium text-gray-700`,children:[i(`appDesigner.appTitle`),` `,(0,Q.jsx)(`span`,{className:`text-red-500`,children:`*`})]}),(0,Q.jsx)(`input`,{id:`app-title`,"data-testid":`app-title-input`,type:`text`,value:e.title,onChange:e=>r({title:e.target.value}),placeholder:`My Application`,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`app-description`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appDescription`)}),(0,Q.jsx)(`textarea`,{id:`app-description`,"data-testid":`app-description-input`,value:e.description??``,onChange:e=>r({description:e.target.value}),rows:3,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50 resize-none`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`app-icon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.appIcon`)}),(0,Q.jsx)(`input`,{id:`app-icon`,type:`text`,value:e.icon??``,onChange:e=>r({icon:e.target.value}),placeholder:`LayoutDashboard`,disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),t.length>0&&(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`app-template`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.template`)}),(0,Q.jsxs)(`select`,{id:`app-template`,value:e.template??``,onChange:e=>r({template:e.target.value}),disabled:n,className:`block w-full rounded-md border border-gray-300 px-3 py-2 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`,children:[(0,Q.jsx)(`option`,{value:``,children:`None`}),t.map(e=>(0,Q.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]}),(0,Q.jsxs)(`fieldset`,{className:`space-y-2`,children:[(0,Q.jsx)(`legend`,{className:`text-sm font-medium text-gray-700`,children:i(`appDesigner.layout`)}),(0,Q.jsx)(`div`,{className:`flex gap-3`,children:[{value:`sidebar`,labelKey:`appDesigner.layoutSidebar`,Icon:Rn},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:le},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:bt}].map(({value:t,labelKey:a,Icon:o})=>(0,Q.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:qf(`flex flex-1 cursor-pointer flex-col items-center gap-1.5 rounded-lg border-2 p-3 transition-colors`,e.layout===t?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`,n&&`pointer-events-none opacity-60`),children:[(0,Q.jsx)(o,{className:`h-5 w-5 text-gray-600`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium text-gray-700`,children:i(a)}),(0,Q.jsx)(`input`,{type:`radio`,name:`layout`,value:t,checked:e.layout===t,onChange:()=>r({layout:t}),disabled:n,className:`sr-only`})]},t))})]})]})}function ep({objects:e,readOnly:t,onToggle:n,onToggleAll:r,search:i,onSearchChange:a,t:o}){let s=(0,Z.useMemo)(()=>{if(!i)return e;let t=i.toLowerCase();return e.filter(e=>e.name.toLowerCase().includes(t)||e.label.toLowerCase().includes(t))},[e,i]),c=e.length>0&&e.every(e=>e.selected);return e.every(e=>!e.selected),(0,Q.jsxs)(`div`,{"data-testid":`wizard-step-objects-content`,className:`mx-auto max-w-2xl space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Q.jsx)(Tt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Q.jsx)(`input`,{"data-testid":`object-search`,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:o(`appDesigner.searchObjects`),className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500`})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r(!c),disabled:t,className:`rounded-md border border-gray-300 px-3 py-2 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:o(c?`appDesigner.deselectAll`:`appDesigner.selectAll`)})]}),s.length===0?(0,Q.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:o(`appDesigner.noObjectsFound`)}):(0,Q.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:s.map(e=>(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`object-card-${e.name}`,disabled:t,onClick:()=>n(e.name),className:qf(`flex flex-col items-start gap-1 rounded-lg border-2 p-3 text-left transition-colors`,e.selected?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`,t&&`pointer-events-none opacity-60`),children:[(0,Q.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.label}),(0,Q.jsx)(`div`,{className:qf(`flex h-5 w-5 items-center justify-center rounded border transition-colors`,e.selected?`border-blue-500 bg-blue-500 text-white`:`border-gray-300`),children:e.selected&&(0,Q.jsx)(Ee,{className:`h-3 w-3`})})]}),(0,Q.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.name}),e.icon&&(0,Q.jsx)(`span`,{className:`text-xs text-gray-400`,children:e.icon})]},e.name))})]})}var tp={object:`bg-green-100 text-green-700`,group:`bg-purple-100 text-purple-700`,url:`bg-sky-100 text-sky-700`,separator:`bg-gray-100 text-gray-600`,dashboard:`bg-amber-100 text-amber-700`,page:`bg-teal-100 text-teal-700`,report:`bg-rose-100 text-rose-700`,action:`bg-orange-100 text-orange-700`};function np({items:e,readOnly:t,onAdd:n,onRemove:r,onReorder:i,t:a}){return(0,Q.jsxs)(`div`,{"data-testid":`wizard-step-navigation-content`,className:`mx-auto max-w-lg space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`add-group-btn`,onClick:()=>n(`group`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Q.jsx)(tn,{className:`h-3.5 w-3.5`}),a(`appDesigner.addGroup`)]}),(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`add-url-btn`,onClick:()=>n(`url`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Q.jsx)(Ze,{className:`h-3.5 w-3.5`}),a(`appDesigner.addUrl`)]}),(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`add-separator-btn`,onClick:()=>n(`separator`),disabled:t,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-300 px-3 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Q.jsx)(Br,{className:`h-3.5 w-3.5`}),a(`appDesigner.addSeparator`)]})]}),e.length===0?(0,Q.jsx)(`p`,{className:`py-8 text-center text-sm text-gray-400`,children:a(`appDesigner.noNavItemsHint`)}):(0,Q.jsx)(`ul`,{className:`space-y-1.5`,children:e.map((n,o)=>(0,Q.jsxs)(`li`,{"data-testid":`nav-item-${n.id}`,className:`flex items-center gap-2 rounded-md border border-gray-200 bg-white px-3 py-2`,children:[n.icon&&(0,Q.jsx)(`span`,{className:`text-xs text-gray-400`,children:n.icon}),(0,Q.jsx)(`span`,{className:`flex-1 truncate text-sm text-gray-800`,children:n.type===`separator`?a(`appDesigner.separatorLabel`):I(n.label)}),(0,Q.jsx)(`span`,{className:qf(`rounded-full px-2 py-0.5 text-[10px] font-medium`,tp[n.type]??`bg-gray-100 text-gray-600`),children:n.type}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>i(n.id,`up`),disabled:t||o===0,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move up`,children:(0,Q.jsx)(Rr,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>i(n.id,`down`),disabled:t||o===e.length-1,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move down`,children:(0,Q.jsx)(At,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>r(n.id),disabled:t,className:`rounded p-0.5 text-gray-400 transition-colors hover:text-red-500 disabled:opacity-30`,"aria-label":`Remove`,children:(0,Q.jsx)(Rt,{className:`h-3.5 w-3.5`})})]})]},n.id))})]})}function rp({branding:e,title:t,readOnly:n,onChange:r,t:i}){return(0,Q.jsxs)(`div`,{"data-testid":`wizard-step-branding-content`,className:`mx-auto max-w-lg space-y-5`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`branding-logo`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.logoUrl`)}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(Ut,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Q.jsx)(`input`,{id:`branding-logo`,"data-testid":`branding-logo-input`,type:`text`,value:e.logo??``,onChange:e=>r({logo:e.target.value}),placeholder:`https://example.com/logo.svg`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`branding-color`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.primaryColor`)}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(fn,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Q.jsx)(`input`,{id:`branding-color`,"data-testid":`branding-color-input`,type:`text`,value:e.primaryColor??`#3b82f6`,onChange:e=>r({primaryColor:e.target.value}),placeholder:`#3b82f6`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`branding-favicon`,className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.faviconUrl`)}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(dr,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Q.jsx)(`input`,{id:`branding-favicon`,"data-testid":`branding-favicon-input`,type:`text`,value:e.favicon??``,onChange:e=>r({favicon:e.target.value}),placeholder:`https://example.com/favicon.ico`,disabled:n,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`span`,{className:`block text-sm font-medium text-gray-700`,children:i(`appDesigner.preview`)}),(0,Q.jsxs)(`div`,{className:`rounded-lg border border-gray-200 bg-white p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e.logo?(0,Q.jsx)(`img`,{src:e.logo,alt:`App logo`,className:`h-8 w-8 rounded object-contain`}):(0,Q.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-gray-100 text-xs text-gray-400`,children:`Logo`}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-gray-800`,children:t||i(`appDesigner.appTitle`)})]}),(0,Q.jsxs)(`div`,{className:`mt-3 flex items-center gap-2`,children:[(0,Q.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:e.primaryColor||`#3b82f6`}}),(0,Q.jsx)(`span`,{className:`text-xs text-gray-500`,children:e.primaryColor||`#3b82f6`})]}),e.favicon&&(0,Q.jsxs)(`div`,{className:`mt-2 flex items-center gap-2`,children:[(0,Q.jsx)(`img`,{src:e.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,Q.jsx)(`span`,{className:`text-xs text-gray-500`,children:`Favicon`})]})]})]})]})}function ip({availableObjects:e=[],templates:t=[],initialDraft:n,onComplete:r,onCancel:i,onSaveDraft:a,readOnly:o=!1,className:s}){let{t:c}=Kf(),l=mf(),[u,d]=(0,Z.useState)(0),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(()=>({...Jf,objects:e.map(e=>({...e})),...n})),g=(0,Z.useMemo)(()=>[{id:`basic`,label:c(`appDesigner.basicInfo`),description:c(`appDesigner.stepBasicDesc`),icon:`Settings`},{id:`objects`,label:c(`appDesigner.objects`),description:c(`appDesigner.stepObjectsDesc`),icon:`Database`},{id:`navigation`,label:c(`appDesigner.navigation`),description:c(`appDesigner.stepNavigationDesc`),icon:`Menu`},{id:`branding`,label:c(`appDesigner.branding`),description:c(`appDesigner.stepBrandingDesc`),icon:`Palette`}],[c]),_=u===0,v=u===g.length-1,y=(0,Z.useMemo)(()=>m.name.length>0&&L(m.name)&&m.title.trim().length>0,[m.name,m.title]),b=(0,Z.useMemo)(()=>u===0?y:!0,[u,y]),x=(0,Z.useCallback)(e=>{h(t=>({...t,...e}))},[]),S=(0,Z.useCallback)(e=>{h(t=>({...t,branding:{...t.branding,...e}}))},[]),C=(0,Z.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>t.name===e?{...t,selected:!t.selected}:t)}))},[]),w=(0,Z.useCallback)(e=>{h(t=>({...t,objects:t.objects.map(t=>({...t,selected:e}))}))},[]),T=(0,Z.useCallback)(e=>{let t={id:Zf(e),type:e,label:e===`separator`?``:e===`group`?`New Group`:`New Link`,...e===`group`?{children:[]}:{},...e===`url`?{url:``}:{}};h(e=>({...e,navigation:[...e.navigation,t]}))},[]),E=(0,Z.useCallback)(e=>{h(t=>({...t,navigation:t.navigation.filter(t=>t.id!==e)}))},[]),D=(0,Z.useCallback)((e,t)=>{h(n=>{let r=[...n.navigation],i=r.findIndex(t=>t.id===e);if(i<0)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,navigation:r})})},[]),O=(0,Z.useCallback)(()=>{v||(u===1&&h(e=>({...e,navigation:Yf(e.objects)})),d(e=>e+1))},[u,v]),k=(0,Z.useCallback)(()=>{_||d(e=>e-1)},[_]),A=(0,Z.useCallback)(()=>{r?.(m)},[m,r]),j=(0,Z.useCallback)(async()=>{(m.name.length>0||m.title.length>0)&&i?await l.confirm(c(`appDesigner.cancelConfirmTitle`),c(`appDesigner.cancelConfirmMessage`))&&i():i?.()},[m.name,m.title,i,l,c]),M=(0,Z.useCallback)(()=>{a?.(m)},[m,a]),N=(0,Z.useCallback)(e=>{e<=u?d(e):e===u+1&&b&&(u===1&&e===2&&h(e=>({...e,navigation:Yf(e.objects)})),d(e))},[u,b]);return(0,Q.jsxs)(`div`,{className:qf(`flex h-full flex-col rounded-xl border border-gray-200 bg-white shadow-sm`,s),children:[l.isOpen&&(0,Q.jsx)(`div`,{"data-testid":`cancel-confirm-dialog`,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/40`,role:`dialog`,"aria-modal":`true`,children:(0,Q.jsxs)(`div`,{className:`mx-4 w-full max-w-sm rounded-lg bg-white p-6 shadow-xl`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Q.jsx)(`h3`,{className:`text-base font-semibold text-gray-900`,children:l.title}),(0,Q.jsx)(`button`,{type:`button`,onClick:l.onCancel,className:`rounded p-1 text-gray-400 hover:text-gray-600`,"aria-label":c(`common.close`),children:(0,Q.jsx)(Et,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`p`,{className:`mt-2 text-sm text-gray-600`,children:l.message}),(0,Q.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,"data-testid":`cancel-confirm-keep`,onClick:l.onCancel,className:`rounded-md border border-gray-300 px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50`,children:c(`appDesigner.keepEditing`)}),(0,Q.jsx)(`button`,{type:`button`,"data-testid":`cancel-confirm-discard`,onClick:l.onConfirm,className:`rounded-md bg-red-600 px-3 py-1.5 text-sm font-medium text-white transition-colors hover:bg-red-700`,children:c(`appDesigner.confirmDiscard`)})]})]})}),(0,Q.jsx)(`div`,{className:`border-b border-gray-100`,children:(0,Q.jsx)(Qf,{steps:g,currentIndex:u,onStepClick:N})}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[u===0&&(0,Q.jsx)($f,{draft:m,templates:t,readOnly:o,onChange:x,t:c}),u===1&&(0,Q.jsx)(ep,{objects:m.objects,readOnly:o,onToggle:C,onToggleAll:w,search:f,onSearchChange:p,t:c}),u===2&&(0,Q.jsx)(np,{items:m.navigation,readOnly:o,onAdd:T,onRemove:E,onReorder:D,t:c}),u===3&&(0,Q.jsx)(rp,{branding:m.branding,title:m.title,readOnly:o,onChange:S,t:c})]}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between border-t border-gray-100 px-6 py-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`button`,{type:`button`,"data-testid":`wizard-cancel`,onClick:j,disabled:o,className:`rounded-md px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50`,children:c(`common.cancel`)}),a&&(0,Q.jsx)(`button`,{type:`button`,"data-testid":`wizard-save-draft`,onClick:M,disabled:o,className:`rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:c(`appDesigner.saveDraft`)})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!_&&(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`wizard-back`,onClick:k,disabled:o,className:`inline-flex items-center gap-1 rounded-md border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Q.jsx)(Ir,{className:`h-4 w-4`}),c(`common.back`)]}),v?(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`wizard-complete`,onClick:A,disabled:o||!b,className:`inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Q.jsx)(Ee,{className:`h-4 w-4`}),c(`appDesigner.complete`)]}):(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`wizard-next`,onClick:O,disabled:o||!b,className:`inline-flex items-center gap-1 rounded-md bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-50`,children:[c(`common.next`),(0,Q.jsx)(be,{className:`h-4 w-4`})]})]})]})]})}function ap(...e){return Xr(Qr(e))}var op=0;function sp(e){return op+=1,`${e}_${Date.now()}_${op}`}var cp={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:Bt},dashboard:{labelKey:`appDesigner.navTypeDashboard`,color:`bg-amber-100 text-amber-700`,Icon:Fe},page:{labelKey:`appDesigner.navTypePage`,color:`bg-teal-100 text-teal-700`,Icon:ye},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:st},url:{labelKey:`appDesigner.navTypeUrl`,color:`bg-sky-100 text-sky-700`,Icon:Ze},group:{labelKey:`appDesigner.navTypeGroup`,color:`bg-purple-100 text-purple-700`,Icon:tn},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:Br},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:$n}},lp=[{type:`object`,labelKey:`appDesigner.navObjectPage`},{type:`dashboard`,labelKey:`appDesigner.navDashboard`},{type:`page`,labelKey:`appDesigner.navPage`},{type:`report`,labelKey:`appDesigner.navReport`},{type:`group`,labelKey:`appDesigner.navGroup`},{type:`url`,labelKey:`appDesigner.navUrl`},{type:`separator`,labelKey:`appDesigner.navSeparator`}];function up({item:e,depth:t,index:n,total:r,readOnly:i,onRemove:a,onMoveUp:o,onMoveDown:s,onToggleExpand:c,onUpdateLabel:l,onUpdateIcon:u,onToggleVisible:d,onAddChild:f,expandedIds:p,t:m}){let[h,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(I(e.label)??``),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(e.icon||``),C=cp[e.type];e.type===`group`&&e.children&&e.children.length;let w=p.has(e.id),T=e.visible===!1,E=()=>{_.trim()?l(e.id,_.trim()):v(I(e.label)??``),g(!1)},D=()=>{u(e.id,x.trim()),b(!1)};return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`li`,{"data-testid":`nav-designer-item-${e.id}`,className:ap(`flex items-center gap-2 rounded-md border border-gray-200 bg-white px-2 py-1.5 transition-colors hover:bg-gray-50`,T&&`opacity-50`),style:{marginLeft:t*20},children:[(0,Q.jsx)(Bn,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-gray-300`}),e.type===`group`?(0,Q.jsx)(`button`,{type:`button`,onClick:()=>c(e.id),className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":m(w?`appDesigner.navCollapseGroup`:`appDesigner.navExpandGroup`),children:w?(0,Q.jsx)(At,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(be,{className:`h-3.5 w-3.5`})}):(0,Q.jsx)(`span`,{className:`w-5`}),y&&!i?(0,Q.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),onBlur:D,onKeyDown:t=>{t.key===`Enter`&&D(),t.key===`Escape`&&(S(e.icon||``),b(!1))},autoFocus:!0,placeholder:m(`appDesigner.navIconPlaceholder`),"data-testid":`nav-designer-icon-input-${e.id}`,className:`w-24 rounded border border-blue-300 px-1 py-0.5 text-xs outline-none focus:ring-1 focus:ring-blue-400`}):(0,Q.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,Q.jsx)(C.Icon,{className:`h-3.5 w-3.5 shrink-0 text-gray-500`}),!i&&e.type!==`separator`&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{S(e.icon||``),b(!0)},className:`rounded p-0.5 text-gray-300 hover:text-blue-500`,"aria-label":m(`appDesigner.navEditIcon`),"data-testid":`nav-designer-edit-icon-${e.id}`,children:(0,Q.jsx)(Wt,{className:`h-2.5 w-2.5`})})]}),e.type===`separator`?(0,Q.jsx)(`span`,{className:`flex-1 text-xs italic text-gray-400`,children:m(`appDesigner.separatorLabel`)}):h&&!i?(0,Q.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),onBlur:E,onKeyDown:t=>{t.key===`Enter`&&E(),t.key===`Escape`&&(v(I(e.label)??``),g(!1))},autoFocus:!0,className:`flex-1 rounded border border-blue-300 px-1.5 py-0.5 text-sm outline-none focus:ring-1 focus:ring-blue-400`}):(0,Q.jsx)(`span`,{className:ap(`flex-1 truncate text-sm text-gray-800`,!i&&`cursor-text`),onDoubleClick:()=>{!i&&e.type!==`separator`&&(v(I(e.label)??``),g(!0))},children:I(e.label)}),(0,Q.jsx)(`span`,{className:ap(`rounded-full px-2 py-0.5 text-[10px] font-medium`,C.color),children:m(C.labelKey)}),T&&(0,Q.jsx)(`span`,{className:`rounded-full bg-gray-200 px-1.5 py-0.5 text-[10px] font-medium text-gray-500`,"data-testid":`nav-designer-hidden-badge-${e.id}`,children:m(`appDesigner.navHidden`)}),!i&&e.type!==`separator`&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>d(e.id),className:`rounded p-0.5 text-gray-400 hover:text-gray-700`,"aria-label":m(`appDesigner.navToggleVisible`),"data-testid":`nav-designer-toggle-visible-${e.id}`,children:T?(0,Q.jsx)(Oe,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(mt,{className:`h-3.5 w-3.5`})}),e.type===`group`&&!i&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>f(e.id,`page`),className:`rounded p-0.5 text-gray-400 hover:text-blue-500`,"aria-label":m(`appDesigner.navAddChild`),"data-testid":`nav-designer-add-child-${e.id}`,children:(0,Q.jsx)(Mt,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>o(e.id),disabled:i||n===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":m(`appDesigner.navMoveUp`),children:(0,Q.jsx)(Rr,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>s(e.id),disabled:i||n===r-1,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":m(`appDesigner.navMoveDown`),children:(0,Q.jsx)(At,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>a(e.id),disabled:i,className:`rounded p-0.5 text-gray-400 hover:text-red-500 disabled:opacity-30`,"aria-label":m(`appDesigner.navRemove`),"data-testid":`nav-designer-remove-${e.id}`,children:(0,Q.jsx)(Rt,{className:`h-3.5 w-3.5`})})]}),e.type===`group`&&w&&e.children&&(0,Q.jsx)(Q.Fragment,{children:e.children.map((n,r)=>(0,Q.jsx)(up,{item:n,depth:t+1,index:r,total:e.children.length,readOnly:i,onRemove:a,onMoveUp:o,onMoveDown:s,onToggleExpand:c,onUpdateLabel:l,onUpdateIcon:u,onToggleVisible:d,onAddChild:f,expandedIds:p,t:m},n.id))})]})}function dp({items:e,t}){return(0,Q.jsxs)(`div`,{"data-testid":`nav-designer-preview`,className:`w-56 shrink-0 rounded-lg border border-gray-200 bg-gray-50 p-3`,children:[(0,Q.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase text-gray-500`,children:t(`appDesigner.navLivePreview`)}),e.length===0?(0,Q.jsx)(`p`,{className:`text-xs text-gray-400`,children:t(`appDesigner.navNoPreviewItems`)}):(0,Q.jsx)(`ul`,{className:`space-y-0.5`,children:e.map(e=>(0,Q.jsx)(fp,{item:e,depth:0},e.id))})]})}function fp({item:e,depth:t}){let n=cp[e.type];return e.type===`separator`?(0,Q.jsx)(`li`,{className:`my-1 border-t border-gray-200`,style:{marginLeft:t*12}}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`li`,{className:`flex items-center gap-1.5 rounded px-2 py-1 text-xs text-gray-700 hover:bg-gray-100`,style:{marginLeft:t*12},children:[(0,Q.jsx)(n.Icon,{className:`h-3 w-3 text-gray-400`}),(0,Q.jsx)(`span`,{className:`truncate`,children:I(e.label)})]}),e.type===`group`&&e.children?.map(e=>(0,Q.jsx)(fp,{item:e,depth:t+1},e.id))]})}function pp({items:e,onChange:t,readOnly:n=!1,showPreview:r=!0,className:i,onExport:a,onImport:o}){let{t:s}=Kf(),c=(0,Z.useRef)(null),[l,u]=(0,Z.useState)(()=>new Set(e.filter(e=>e.type===`group`).map(e=>e.id))),d=(0,Z.useCallback)(n=>{function r(e){return e.filter(e=>e.id!==n).map(e=>e.children?{...e,children:r(e.children)}:e)}t(r(e))},[e,t]),f=(0,Z.useCallback)((n,r)=>{function i(e){let t=e.findIndex(e=>e.id===n);if(t>=0){let n=r===`up`?t-1:t+1;if(n>=0&&n<e.length){let r=[...e];return[r[t],r[n]]=[r[n],r[t]],r}return e}return e.map(e=>e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),p=(0,Z.useCallback)((n,r)=>{function i(e){return e.map(e=>e.id===n?{...e,label:r}:e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),m=(0,Z.useCallback)((n,r)=>{function i(e){return e.map(e=>e.id===n?{...e,icon:r||void 0}:e.children?{...e,children:i(e.children)}:e)}t(i(e))},[e,t]),h=(0,Z.useCallback)(n=>{function r(e){return e.map(e=>e.id===n?{...e,visible:e.visible===!1}:e.children?{...e,children:r(e.children)}:e)}t(r(e))},[e,t]),g=(0,Z.useCallback)((n,r)=>{let i={id:sp(r),type:r,label:r===`separator`?``:`New ${s(cp[r].labelKey)}`,...r===`group`?{children:[]}:{},...r===`url`?{url:``}:{}};function a(e){return e.map(e=>e.id===n&&e.type===`group`?{...e,children:[...e.children||[],i]}:e.children?{...e,children:a(e.children)}:e)}t(a(e)),u(e=>new Set(e).add(n))},[e,t]),_=(0,Z.useCallback)(n=>{let r={id:sp(n),type:n,label:n===`separator`?``:`New ${s(cp[n].labelKey)}`,...n===`group`?{children:[]}:{},...n===`url`?{url:``}:{}};t([...e,r])},[e,t,s]),v=(0,Z.useCallback)(e=>{u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),y=(0,Z.useCallback)(()=>{if(a)a(e);else{let t=JSON.stringify(e,null,2),n=new Blob([t],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`navigation-schema.json`,i.click(),URL.revokeObjectURL(r)}},[e,a]),b=(0,Z.useCallback)(e=>{let n=e.target.files?.[0];if(!n)return;let r=new FileReader;r.onload=e=>{try{let n=JSON.parse(e.target?.result);Array.isArray(n)&&(o?o(n):t(n))}catch{}},r.readAsText(n),c.current&&(c.current.value=``)},[t,o]);return(0,Q.jsxs)(`div`,{"data-testid":`navigation-designer`,className:ap(`flex flex-col gap-4 sm:flex-row`,i),children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[lp.map(({type:e,labelKey:t})=>{let{Icon:r,color:i}=cp[e];return(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>_(e),disabled:n,className:ap(`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`),children:[(0,Q.jsx)(Mt,{className:`h-3 w-3`}),s(t)]},e)}),(0,Q.jsx)(`span`,{className:`mx-1 hidden h-4 w-px bg-gray-200 sm:block`}),(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-export`,onClick:y,className:`inline-flex items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50`,children:[(0,Q.jsx)(_e,{className:`h-3 w-3`}),s(`appDesigner.navExportSchema`)]}),(0,Q.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:ap(`inline-flex cursor-pointer items-center gap-1 rounded-md border border-gray-200 px-2.5 py-1 text-xs font-medium transition-colors hover:bg-gray-50`,n&&`cursor-not-allowed opacity-50`),children:[(0,Q.jsx)(ht,{className:`h-3 w-3`}),s(`appDesigner.navImportSchema`),(0,Q.jsx)(`input`,{ref:c,type:`file`,accept:`.json`,className:`hidden`,onChange:b,disabled:n,"data-testid":`nav-designer-import-input`})]})]}),e.length===0?(0,Q.jsx)(`div`,{className:`py-8 text-center text-sm text-gray-400`,children:s(`appDesigner.navNoItems`)}):(0,Q.jsx)(`ul`,{className:`space-y-1`,"data-testid":`nav-designer-tree`,children:e.map((t,r)=>(0,Q.jsx)(up,{item:t,depth:0,index:r,total:e.length,readOnly:n,onRemove:d,onMoveUp:e=>f(e,`up`),onMoveDown:e=>f(e,`down`),onToggleExpand:v,onUpdateLabel:p,onUpdateIcon:m,onToggleVisible:h,onAddChild:g,expandedIds:l,t:s},t.id))})]}),r&&(0,Q.jsx)(dp,{items:e,t:s})]})}function mp(...e){return Xr(Qr(e))}var hp=[{type:`metric`,label:`KPI Metric`,Icon:Jr},{type:`bar`,label:`Bar Chart`,Icon:st},{type:`line`,label:`Line Chart`,Icon:at},{type:`pie`,label:`Pie Chart`,Icon:dt},{type:`table`,label:`Table`,Icon:vt},{type:`grid`,label:`Grid`,Icon:Kr}],gp=0;function _p(){return gp+=1,`widget_${Date.now()}_${gp}`}function vp({widget:e,index:t,total:n,selected:r,readOnly:i,onSelect:a,onRemove:o,onMoveUp:s,onMoveDown:c}){let l=e.type||`metric`,u=hp.find(e=>e.type===l)||hp[0];return(0,Q.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:a,className:mp(`group cursor-pointer rounded-lg border-2 p-3 transition-colors`,r?`border-blue-500 bg-blue-50`:`border-gray-200 hover:border-gray-300`),children:[(0,Q.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Bn,{className:`h-4 w-4 text-gray-300`}),(0,Q.jsx)(u.Icon,{className:`h-4 w-4 text-gray-500`}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-gray-800`,children:e.title||`Widget ${t+1}`})]}),!i&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),s()},disabled:t===0,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move up`,children:(0,Q.jsx)(Rr,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),c()},disabled:t===n-1,className:`rounded p-0.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":`Move down`,children:(0,Q.jsx)(At,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),o()},className:`rounded p-0.5 text-gray-400 hover:text-red-500`,"aria-label":`Remove widget`,"data-testid":`dashboard-widget-remove-${e.id}`,children:(0,Q.jsx)(Rt,{className:`h-3.5 w-3.5`})})]})]}),(0,Q.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`rounded-full bg-gray-100 px-2 py-0.5 text-[10px] font-medium text-gray-600`,children:u.label}),e.object&&(0,Q.jsx)(`span`,{className:`text-[10px] text-gray-400`,children:e.object})]})]})}function yp({widget:e,readOnly:t,onChange:n,onClose:r}){let{t:i}=Kf();return(0,Q.jsxs)(`div`,{"data-testid":`widget-property-panel`,className:`shrink-0 space-y-4 rounded-lg border border-gray-200 bg-white p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`h4`,{className:`text-sm font-semibold text-gray-800`,children:i(`appDesigner.widgetProperties`)}),(0,Q.jsx)(`button`,{type:`button`,onClick:r,className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,"aria-label":`Close`,children:(0,Q.jsx)(Et,{className:`h-4 w-4`})})]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`widget-title`,className:`text-xs font-medium text-gray-600`,children:`Title`}),(0,Q.jsx)(`input`,{id:`widget-title`,"data-testid":`widget-prop-title`,type:`text`,value:e.title??``,onChange:e=>n({title:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`widget-type`,className:`text-xs font-medium text-gray-600`,children:`Type`}),(0,Q.jsx)(`select`,{id:`widget-type`,"data-testid":`widget-prop-type`,value:e.type??`metric`,onChange:e=>n({type:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:hp.map(e=>(0,Q.jsx)(`option`,{value:e.type,children:e.label},e.type))})]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`widget-object`,className:`text-xs font-medium text-gray-600`,children:`Data Source (Object)`}),(0,Q.jsx)(`input`,{id:`widget-object`,"data-testid":`widget-prop-object`,type:`text`,value:e.object??``,onChange:e=>n({object:e.target.value}),disabled:t,placeholder:`e.g. orders`,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`widget-value-field`,className:`text-xs font-medium text-gray-600`,children:`Value Field`}),(0,Q.jsx)(`input`,{id:`widget-value-field`,"data-testid":`widget-prop-value-field`,type:`text`,value:e.valueField??``,onChange:e=>n({valueField:e.target.value}),disabled:t,placeholder:`e.g. amount`,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`widget-aggregate`,className:`text-xs font-medium text-gray-600`,children:`Aggregate`}),(0,Q.jsxs)(`select`,{id:`widget-aggregate`,"data-testid":`widget-prop-aggregate`,value:e.aggregate??`count`,onChange:e=>n({aggregate:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:[(0,Q.jsx)(`option`,{value:`count`,children:`Count`}),(0,Q.jsx)(`option`,{value:`sum`,children:`Sum`}),(0,Q.jsx)(`option`,{value:`avg`,children:`Average`}),(0,Q.jsx)(`option`,{value:`min`,children:`Min`}),(0,Q.jsx)(`option`,{value:`max`,children:`Max`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`widget-color`,className:`text-xs font-medium text-gray-600`,children:`Color Variant`}),(0,Q.jsxs)(`select`,{id:`widget-color`,"data-testid":`widget-prop-color`,value:e.colorVariant??`default`,onChange:e=>n({colorVariant:e.target.value}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2.5 py-1.5 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`,children:[(0,Q.jsx)(`option`,{value:`default`,children:`Default`}),(0,Q.jsx)(`option`,{value:`blue`,children:`Blue`}),(0,Q.jsx)(`option`,{value:`teal`,children:`Teal`}),(0,Q.jsx)(`option`,{value:`orange`,children:`Orange`}),(0,Q.jsx)(`option`,{value:`purple`,children:`Purple`}),(0,Q.jsx)(`option`,{value:`success`,children:`Success`}),(0,Q.jsx)(`option`,{value:`warning`,children:`Warning`}),(0,Q.jsx)(`option`,{value:`danger`,children:`Danger`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-medium text-gray-600`,children:i(`appDesigner.widgetLayoutSize`)}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`widget-width`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetWidth`)}),(0,Q.jsx)(`input`,{id:`widget-width`,"data-testid":`widget-prop-width`,type:`number`,min:1,value:e.layout?.w??1,onChange:t=>n({layout:{...e.layout,w:Number(t.target.value)||1}}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2 py-1 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]}),(0,Q.jsxs)(`div`,{className:`flex-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`widget-height`,className:`text-[10px] text-gray-400`,children:i(`appDesigner.widgetHeight`)}),(0,Q.jsx)(`input`,{id:`widget-height`,"data-testid":`widget-prop-height`,type:`number`,min:1,value:e.layout?.h??1,onChange:t=>n({layout:{...e.layout,h:Number(t.target.value)||1}}),disabled:t,className:`block w-full rounded-md border border-gray-300 px-2 py-1 text-sm outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:bg-gray-50`})]})]})]})]})}function bp({schema:e}){let{t}=Kf(),n=e.widgets||[];return(0,Q.jsxs)(`div`,{"data-testid":`dashboard-preview`,className:`rounded-lg border border-gray-200 bg-gray-50 p-4`,children:[(0,Q.jsx)(`h4`,{className:`mb-3 text-sm font-semibold text-gray-700`,children:e.title||t(`appDesigner.dashboardPreview`)}),n.length===0?(0,Q.jsx)(`div`,{className:`text-xs text-gray-400`,children:t(`appDesigner.noWidgetsPreview`)}):(0,Q.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(${e.columns??2}, 1fr)`},children:n.map(e=>{let t=hp.find(t=>t.type===(e.type||`metric`))||hp[0];return(0,Q.jsxs)(`div`,{className:`rounded-md border border-gray-200 bg-white p-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(t.Icon,{className:`h-3 w-3 text-gray-400`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium text-gray-600`,children:e.title||`Untitled`})]}),(0,Q.jsx)(`div`,{className:`mt-1 text-[10px] text-gray-400`,children:t.label})]},e.id)})})]})}function xp({schema:e,onChange:t,readOnly:n=!1,className:r,onExport:i,onImport:a,selectedWidgetId:o,onWidgetSelect:s}){let{t:c}=Kf(),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(!1),p=(0,Z.useRef)(null),m=(0,Z.useRef)(null),h=o!==void 0,g=h?o:l,_=(0,Z.useCallback)(e=>{s&&s(e),h||u(e)},[h,s,u]),{current:v,canUndo:y,canRedo:b,push:x,undo:S,redo:C}=pf(e),w=(0,Z.useCallback)(e=>{x(e),t(e)},[x,t]),T=v.widgets||[],E=T.find(e=>e.id===g),D=(0,Z.useCallback)(e=>{let t=_p(),n={id:t,title:``,type:e,layout:{x:0,y:T.length,w:v.columns??2,h:1}};w({...v,widgets:[...T,n]}),_(t)},[v,T,w,_]),O=(0,Z.useCallback)(e=>{w({...v,widgets:T.filter(t=>t.id!==e)}),g===e&&_(null)},[v,T,g,w,_]),k=(0,Z.useCallback)((e,t)=>{let n=T.findIndex(t=>t.id===e);if(n<0)return;let r=t===`up`?n-1:n+1;if(r<0||r>=T.length)return;let i=[...T];[i[n],i[r]]=[i[r],i[n]],w({...v,widgets:i})},[v,T,w]),A=(0,Z.useCallback)(e=>{g&&w({...v,widgets:T.map(t=>t.id===g?{...t,...e}:t)})},[v,T,g,w]);(0,Z.useEffect)(()=>{let e=p.current;if(!e)return;let t=e=>{if(!n){if((e.ctrlKey||e.metaKey)&&e.key===`z`&&!e.shiftKey){e.preventDefault(),S();return}if((e.ctrlKey||e.metaKey)&&(e.key===`y`||e.key===`z`&&e.shiftKey)){e.preventDefault(),C();return}if((e.key===`Delete`||e.key===`Backspace`)&&g){let t=e.target;if(t.tagName===`INPUT`||t.tagName===`SELECT`||t.tagName===`TEXTAREA`)return;e.preventDefault(),O(g)}}};return e.addEventListener(`keydown`,t),()=>e.removeEventListener(`keydown`,t)},[n,S,C,g,O]);let j=(0,Z.useCallback)(()=>{i&&i(v)},[v,i]),M=(0,Z.useCallback)(()=>{m.current?.click()},[]),N=(0,Z.useCallback)(e=>{let t=e.target.files?.[0];if(!t)return;let n=new FileReader;n.onload=()=>{try{let e=JSON.parse(n.result);e&&e.type===`dashboard`&&(w(e),a?.(e))}catch{}},n.readAsText(t),e.target.value=``},[w,a]);return(0,Q.jsxs)(`div`,{ref:p,tabIndex:0,"data-testid":`dashboard-editor`,className:mp(`flex flex-col gap-4 outline-none`,r),children:[(0,Q.jsx)(`input`,{ref:m,type:`file`,accept:`.json`,className:`hidden`,"data-testid":`dashboard-import-input`,onChange:N}),E&&!d&&(0,Q.jsx)(yp,{widget:E,readOnly:n,onChange:A,onClose:()=>_(null)}),(0,Q.jsxs)(`div`,{className:`flex-1 space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`text-sm font-medium text-gray-700`,children:[c(`appDesigner.addWidget`),`:`]}),hp.map(({type:e,label:t,Icon:r})=>(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-add-${e}`,onClick:()=>D(e),disabled:n||d,className:`inline-flex items-center gap-1.5 rounded-md border border-gray-200 px-2.5 py-1.5 text-xs font-medium text-gray-600 transition-colors hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50`,children:[(0,Q.jsx)(r,{className:`h-3.5 w-3.5`}),t]},e))]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!n&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,"data-testid":`dashboard-undo`,onClick:S,disabled:!y,className:`rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":c(`appDesigner.undo`),children:(0,Q.jsx)(Ue,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{type:`button`,"data-testid":`dashboard-redo`,onClick:C,disabled:!b,className:`rounded p-1.5 text-gray-400 hover:text-gray-700 disabled:opacity-30`,"aria-label":c(`appDesigner.redo`),children:(0,Q.jsx)(Qe,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`button`,{type:`button`,"data-testid":`dashboard-export`,onClick:j,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navExportSchema`),children:(0,Q.jsx)(_e,{className:`h-4 w-4`})}),!n&&(0,Q.jsx)(`button`,{type:`button`,"data-testid":`dashboard-import`,onClick:M,className:`rounded p-1.5 text-gray-400 hover:text-gray-700`,"aria-label":c(`appDesigner.navImportSchema`),children:(0,Q.jsx)(ht,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>f(e=>!e),className:mp(`rounded p-1.5 transition-colors`,d?`bg-blue-100 text-blue-600`:`text-gray-400 hover:text-gray-700`),"aria-label":c(d?`appDesigner.modeEdit`:`appDesigner.preview`),children:d?(0,Q.jsx)(Oe,{className:`h-4 w-4`}):(0,Q.jsx)(mt,{className:`h-4 w-4`})})]})]}),d?(0,Q.jsx)(bp,{schema:v}):T.length===0?(0,Q.jsx)(`div`,{className:`flex h-48 items-center justify-center rounded-lg border-2 border-dashed border-gray-200 text-sm text-gray-400`,children:c(`appDesigner.noWidgets`)}):(0,Q.jsx)(`div`,{className:`grid gap-3`,style:{gridTemplateColumns:`repeat(${v.columns??2}, 1fr)`},children:T.map((e,t)=>(0,Q.jsx)(vp,{widget:e,index:t,total:T.length,selected:e.id===g,readOnly:n,onSelect:()=>_(e.id??null),onRemove:()=>O(e.id),onMoveUp:()=>k(e.id,`up`),onMoveDown:()=>k(e.id,`down`)},e.id))})]})]})}function Sp(...e){return Xr(Qr(e))}var Cp=[{hex:`#3b82f6`,name:`Blue`},{hex:`#6366f1`,name:`Indigo`},{hex:`#8b5cf6`,name:`Violet`},{hex:`#a855f7`,name:`Purple`},{hex:`#ec4899`,name:`Pink`},{hex:`#ef4444`,name:`Red`},{hex:`#f97316`,name:`Orange`},{hex:`#f59e0b`,name:`Amber`},{hex:`#eab308`,name:`Yellow`},{hex:`#22c55e`,name:`Green`},{hex:`#14b8a6`,name:`Teal`},{hex:`#06b6d4`,name:`Cyan`},{hex:`#0ea5e9`,name:`Sky`},{hex:`#64748b`,name:`Slate`},{hex:`#1e293b`,name:`Dark`},{hex:`#0f172a`,name:`Navy`}],wp=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function Tp({branding:e,onChange:t,appTitle:n=`My App`,readOnly:r=!1,className:i,onExport:a,onImport:o}){let{t:s}=Kf(),[c,l]=(0,Z.useState)(`light`),{current:u,push:d,canUndo:f,canRedo:p,undo:m,redo:h}=pf(e),g=(0,Z.useRef)(!0);(0,Z.useEffect)(()=>{if(g.current){g.current=!1;return}t(u)},[u]);let _=(0,Z.useCallback)(e=>{let n={...u,...e};g.current=!0,d(n),t(n)},[u,d,t]),v=(0,Z.useCallback)(()=>{if(a){a(u);return}let e=new Blob([JSON.stringify(u,null,2)],{type:`application/json`}),t=URL.createObjectURL(e),n=document.createElement(`a`);n.href=t,n.download=`branding.json`,n.click(),URL.revokeObjectURL(t)},[u,a]),y=(0,Z.useCallback)(()=>{if(o){o(u);return}let e=document.createElement(`input`);e.type=`file`,e.accept=`.json`,e.onchange=e=>{let n=e.target.files?.[0];if(!n)return;let r=new FileReader;r.onload=e=>{try{let n=JSON.parse(e.target?.result);if(typeof n==`object`&&n){let e={...u,...n};d(e),t(e)}}catch{}},r.readAsText(n)},e.click()},[u,d,t,o]),b=(0,Z.useCallback)(e=>{r||((e.ctrlKey||e.metaKey)&&e.key===`z`&&(e.preventDefault(),e.shiftKey?h():m()),(e.ctrlKey||e.metaKey)&&e.key===`y`&&(e.preventDefault(),h()))},[r,m,h]),x=u.primaryColor||`#3b82f6`,S=c===`dark`;return(0,Q.jsxs)(`div`,{"data-testid":`branding-editor`,className:Sp(`flex flex-col gap-4 sm:gap-6`,i),onKeyDown:b,tabIndex:0,children:[(0,Q.jsxs)(`div`,{"data-testid":`branding-editor-toolbar`,className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold text-gray-800 mr-auto`,children:s(`appDesigner.brandingEditor`)}),(0,Q.jsxs)(`button`,{"data-testid":`branding-undo`,type:`button`,onClick:m,disabled:!f||r,className:Sp(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,f&&!r?`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`:`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`),title:s(`appDesigner.undo`),children:[(0,Q.jsx)(Ue,{className:`h-3.5 w-3.5`}),s(`appDesigner.undo`)]}),(0,Q.jsxs)(`button`,{"data-testid":`branding-redo`,type:`button`,onClick:h,disabled:!p||r,className:Sp(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,p&&!r?`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`:`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`),title:s(`appDesigner.redo`),children:[(0,Q.jsx)(Qe,{className:`h-3.5 w-3.5`}),s(`appDesigner.redo`)]}),(0,Q.jsxs)(`button`,{"data-testid":`branding-export`,type:`button`,onClick:v,className:`inline-flex items-center gap-1 rounded-md border border-gray-300 bg-white px-2.5 py-1.5 text-xs font-medium text-gray-700 shadow-sm transition-colors hover:bg-gray-50`,title:s(`appDesigner.brandingExport`),children:[(0,Q.jsx)(_e,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingExport`)]}),(0,Q.jsxs)(`button`,{"data-testid":`branding-import`,type:`button`,onClick:y,disabled:r,className:Sp(`inline-flex items-center gap-1 rounded-md border px-2.5 py-1.5 text-xs font-medium shadow-sm transition-colors`,r?`border-gray-200 bg-gray-50 text-gray-400 cursor-not-allowed`:`border-gray-300 bg-white text-gray-700 hover:bg-gray-50`),title:s(`appDesigner.brandingImport`),children:[(0,Q.jsx)(ht,{className:`h-3.5 w-3.5`}),s(`appDesigner.brandingImport`)]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:gap-6`,children:[(0,Q.jsxs)(`div`,{className:`flex-1 space-y-5`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`be-logo`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.logoUrl`)}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(Ut,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Q.jsx)(`input`,{id:`be-logo`,"data-testid":`branding-logo-input`,type:`text`,value:u.logo??``,onChange:e=>_({logo:e.target.value}),placeholder:`https://example.com/logo.svg`,disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`be-color`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.primaryColor`)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Q.jsx)(fn,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Q.jsx)(`input`,{id:`be-color`,"data-testid":`branding-color-input`,type:`text`,value:u.primaryColor??`#3b82f6`,onChange:e=>_({primaryColor:e.target.value}),placeholder:`#3b82f6`,disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]}),(0,Q.jsx)(`input`,{"data-testid":`branding-color-picker`,type:`color`,value:x,onChange:e=>_({primaryColor:e.target.value}),disabled:r,className:`h-9 w-9 cursor-pointer rounded-md border border-gray-300 p-0.5 disabled:cursor-not-allowed`})]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`span`,{className:`text-xs text-gray-500`,children:s(`appDesigner.colorPalette`)}),(0,Q.jsx)(`div`,{"data-testid":`branding-color-palette`,className:`flex flex-wrap gap-1.5`,children:Cp.map(e=>(0,Q.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!r&&_({primaryColor:e.hex}),disabled:r,className:Sp(`h-6 w-6 rounded-full border-2 transition-transform hover:scale-110 disabled:cursor-not-allowed`,x===e.hex?`border-gray-800 ring-2 ring-offset-1 ring-gray-400`:`border-transparent`),style:{backgroundColor:e.hex},title:e.name},e.hex))})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`be-favicon`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.faviconUrl`)}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(dr,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Q.jsx)(`input`,{id:`be-favicon`,"data-testid":`branding-favicon-input`,type:`text`,value:u.favicon??``,onChange:e=>_({favicon:e.target.value}),placeholder:`https://example.com/favicon.ico`,disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50`})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(`label`,{htmlFor:`be-font`,className:`block text-sm font-medium text-gray-700`,children:s(`appDesigner.fontFamily`)}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(tt,{className:`absolute left-2.5 top-2.5 h-4 w-4 text-gray-400`}),(0,Q.jsxs)(`select`,{id:`be-font`,"data-testid":`branding-font-select`,value:u.fontFamily??``,onChange:e=>_({fontFamily:e.target.value||void 0}),disabled:r,className:`block w-full rounded-md border border-gray-300 py-2 pl-9 pr-3 text-sm shadow-sm outline-none transition-colors focus:border-blue-500 focus:ring-1 focus:ring-blue-500 disabled:cursor-not-allowed disabled:bg-gray-50 appearance-none`,children:[(0,Q.jsx)(`option`,{value:``,children:s(`appDesigner.fontDefault`)}),wp.map(e=>(0,Q.jsx)(`option`,{value:e,children:e},e))]})]})]})]}),(0,Q.jsxs)(`div`,{className:`flex-1 space-y-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-gray-700`,children:s(`appDesigner.brandingPreview`)}),(0,Q.jsxs)(`div`,{"data-testid":`branding-mode-toggle`,className:`flex rounded-md border border-gray-300 overflow-hidden`,children:[(0,Q.jsxs)(`button`,{"data-testid":`branding-mode-light`,type:`button`,onClick:()=>l(`light`),className:Sp(`inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium transition-colors`,c===`light`?`bg-blue-50 text-blue-700`:`bg-white text-gray-600 hover:bg-gray-50`),children:[(0,Q.jsx)(de,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeLight`)]}),(0,Q.jsxs)(`button`,{"data-testid":`branding-mode-dark`,type:`button`,onClick:()=>l(`dark`),className:Sp(`inline-flex items-center gap-1 px-2.5 py-1 text-xs font-medium transition-colors`,c===`dark`?`bg-gray-800 text-gray-100`:`bg-white text-gray-600 hover:bg-gray-50`),children:[(0,Q.jsx)(Mn,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeDark`)]})]})]}),(0,Q.jsxs)(`div`,{"data-testid":`branding-preview`,className:Sp(`rounded-lg border p-4 transition-colors`,S?`border-gray-700 bg-gray-900 text-gray-100`:`border-gray-200 bg-white text-gray-800`),style:{fontFamily:u.fontFamily||`inherit`},children:[(0,Q.jsx)(`div`,{className:`rounded-md p-3 mb-3`,style:{backgroundColor:x},children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[u.logo?(0,Q.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-8 w-8 rounded object-contain bg-white/20`}):(0,Q.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-white/20 text-xs text-white`,children:`Logo`}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-white`,children:n})]})}),(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:`h-4 w-4 rounded-full border border-gray-200`,style:{backgroundColor:x}}),(0,Q.jsx)(`span`,{className:Sp(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:x})]}),(0,Q.jsx)(`button`,{type:`button`,className:`rounded-md px-3 py-1.5 text-xs font-medium text-white transition-colors`,style:{backgroundColor:x},tabIndex:-1,children:s(`appDesigner.brandingSampleButton`)}),(0,Q.jsx)(`p`,{className:Sp(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:s(`appDesigner.brandingSampleText`)}),u.favicon&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`img`,{src:u.favicon,alt:`Favicon`,className:`h-4 w-4 rounded object-contain`}),(0,Q.jsx)(`span`,{className:Sp(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),u.fontFamily&&(0,Q.jsxs)(`div`,{className:Sp(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:[s(`appDesigner.fontFamily`),`: `,u.fontFamily]})]})]}),(0,Q.jsxs)(`div`,{"data-testid":`branding-preview-mobile`,className:Sp(`mx-auto w-48 rounded-xl border-2 p-2 transition-colors`,S?`border-gray-700 bg-gray-900`:`border-gray-300 bg-white`),style:{fontFamily:u.fontFamily||`inherit`},children:[(0,Q.jsx)(`div`,{className:`text-center text-[10px] font-medium text-gray-400 mb-1`,children:s(`appDesigner.mobilePreview`)}),(0,Q.jsx)(`div`,{className:`rounded-md p-2 mb-1`,style:{backgroundColor:x},children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[u.logo?(0,Q.jsx)(`img`,{src:u.logo,alt:`Logo`,className:`h-4 w-4 rounded object-contain bg-white/20`}):(0,Q.jsx)(`div`,{className:`flex h-4 w-4 items-center justify-center rounded bg-white/20 text-[6px] text-white`,children:`L`}),(0,Q.jsx)(`span`,{className:`text-[9px] font-semibold text-white truncate`,children:n})]})}),(0,Q.jsxs)(`div`,{className:`space-y-1 px-1`,children:[(0,Q.jsx)(`div`,{className:Sp(`h-2 w-3/4 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Q.jsx)(`div`,{className:Sp(`h-2 w-1/2 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Q.jsx)(`div`,{className:Sp(`h-2 w-2/3 rounded`,S?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function Ep(...e){return Xr(Qr(e))}var Dp=[`Custom Objects`,`System Objects`,`Integration`,`Analytics`],Op=[`Box`,`Database`,`Users`,`FileText`,`Settings`,`ShoppingCart`,`Calendar`,`Mail`,`Briefcase`,`Building`,`Globe`,`Heart`,`Star`,`Tag`,`Bookmark`,`Folder`,`Archive`,`Package`,`Truck`,`CreditCard`];function kp({objects:e,onObjectsChange:t,onSelectObject:n,showSystemObjects:r=!0,readOnly:i=!1,className:a}){let{t:o}=Kf(),s=mf(),[c,l]=(0,Z.useState)(!1),[u,d]=(0,Z.useState)(null),f=(0,Z.useMemo)(()=>r?e:e.filter(e=>!e.isSystem),[e,r]),p=(0,Z.useMemo)(()=>new z({items:f}),[f]),m=(0,Z.useMemo)(()=>[{field:`name`,label:o(`appDesigner.objectManager.objectName`),width:160},{field:`label`,label:o(`appDesigner.objectManager.objectLabel`),width:160},{field:`group`,label:o(`appDesigner.objectManager.group`),width:130},{field:`fieldCount`,label:`Fields`,width:80},{field:`enabled`,label:o(`appDesigner.objectManager.enabled`),width:80}],[o]),h=(0,Z.useMemo)(()=>({type:`object-grid`,objectName:`object_definition`,columns:m,searchableFields:[`name`,`label`,`description`],showSearch:!0,operations:i?void 0:{create:!0,update:!0,delete:!0}}),[m,i]),g=(0,Z.useCallback)(t=>{let r=e.find(e=>e.name===t.name);r&&n?.(r)},[e,n]),_=(0,Z.useCallback)(t=>{let n=e.find(e=>e.name===t.name);n&&(d(n),l(!0))},[e]),v=(0,Z.useCallback)(async n=>{let r=e.find(e=>e.name===n.name);!r||r.isSystem||await s.confirm(o(`appDesigner.objectManager.deleteConfirmTitle`),o(`appDesigner.objectManager.deleteConfirmMessage`))&&t?.(e.filter(e=>e.id!==r.id))},[e,t,s,o]),y=(0,Z.useCallback)(()=>{d(null),l(!0)},[]),b=(0,Z.useCallback)(n=>{if(u){let r={...u,name:String(n.name||u.name),label:String(n.label||u.label),pluralLabel:n.pluralLabel?String(n.pluralLabel):void 0,description:n.description?String(n.description):void 0,icon:n.icon?String(n.icon):void 0,group:n.group?String(n.group):void 0,sortOrder:typeof n.sortOrder==`number`?n.sortOrder:void 0,enabled:n.enabled!==!1};t?.(e.map(e=>e.id===u.id?r:e))}else{let r={id:`obj_${Date.now()}`,name:String(n.name||`new_object_${e.length+1}`),label:String(n.label||`New Object ${e.length+1}`),pluralLabel:n.pluralLabel?String(n.pluralLabel):void 0,description:n.description?String(n.description):void 0,icon:n.icon?String(n.icon):void 0,group:n.group?String(n.group):void 0,sortOrder:typeof n.sortOrder==`number`?n.sortOrder:void 0,isSystem:!1,enabled:n.enabled!==!1,fieldCount:0};t?.([...e,r])}l(!1),d(null)},[u,e,t]),x=(0,Z.useCallback)(e=>{e||(l(!1),d(null))},[]),S=(0,Z.useMemo)(()=>({type:`object-form`,formType:`modal`,objectName:`object_definition`,mode:u?`edit`:`create`,title:u?`${o(`common.edit`)} — ${u.label}`:o(`appDesigner.objectManager.addObject`),open:c,onOpenChange:x,modalSize:`lg`,customFields:[{name:`name`,label:o(`appDesigner.objectManager.objectName`),type:`text`,required:!0,placeholder:`api_name`,disabled:i||(u?.isSystem??!1)},{name:`label`,label:o(`appDesigner.objectManager.objectLabel`),type:`text`,required:!0,placeholder:`Display Name`,disabled:i},{name:`pluralLabel`,label:o(`appDesigner.objectManager.pluralLabel`),type:`text`,placeholder:`Display Names`,disabled:i},{name:`description`,label:o(`appDesigner.appDescription`),type:`textarea`,disabled:i},{name:`icon`,label:o(`appDesigner.objectManager.icon`),type:`select`,options:Op.map(e=>({label:e,value:e})),disabled:i},{name:`group`,label:o(`appDesigner.objectManager.group`),type:`select`,options:Dp.map(e=>({label:e,value:e})),disabled:i},{name:`sortOrder`,label:o(`appDesigner.objectManager.sortOrder`),type:`number`,disabled:i},{name:`enabled`,label:o(`appDesigner.objectManager.enabled`),type:`boolean`,disabled:i}],initialValues:u?{name:u.name,label:u.label,pluralLabel:u.pluralLabel||``,description:u.description||``,icon:u.icon||``,group:u.group||``,sortOrder:u.sortOrder??0,enabled:u.enabled!==!1}:{enabled:!0},onSuccess:b,onCancel:()=>x(!1),readOnly:i}),[u,c,x,b,i,o]);return(0,Q.jsxs)(`div`,{"data-testid":`object-manager`,className:Ep(`w-full space-y-3`,a),children:[(0,Q.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Bt,{className:`h-4 w-4 text-primary`}),(0,Q.jsx)(`h2`,{className:`text-sm font-semibold`,children:o(`appDesigner.objectManager.title`)}),(0,Q.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:f.length})]})}),(0,Q.jsx)(ma,{schema:h,dataSource:p,onRowClick:g,onEdit:i?void 0:_,onDelete:i?void 0:v,onAddRecord:i?void 0:y}),c&&(0,Q.jsx)(ti,{schema:S}),(0,Q.jsx)(yf,{isOpen:s.isOpen,title:s.title,message:s.message,confirmLabel:o(`common.delete`),cancelLabel:o(`common.cancel`),onConfirm:s.onConfirm,onCancel:s.onCancel,destructive:!0})]})}function Ap(...e){return Xr(Qr(e))}var jp={text:{label:`Text`,Icon:tt},textarea:{label:`Text Area`,Icon:ye},number:{label:`Number`,Icon:wr},boolean:{label:`Checkbox`,Icon:Pt},date:{label:`Date`,Icon:Ae},datetime:{label:`Date/Time`,Icon:Ae},time:{label:`Time`,Icon:Ae},select:{label:`Picklist`,Icon:ft},email:{label:`Email`,Icon:Zt},phone:{label:`Phone`,Icon:Ke},url:{label:`URL`,Icon:dr},password:{label:`Password`,Icon:Hn},currency:{label:`Currency`,Icon:wr},percent:{label:`Percent`,Icon:wr},lookup:{label:`Lookup`,Icon:Be},formula:{label:`Formula`,Icon:_t},autonumber:{label:`Auto Number`,Icon:wr},file:{label:`File`,Icon:ye},image:{label:`Image`,Icon:Ut},markdown:{label:`Markdown`,Icon:ye},html:{label:`Rich Text`,Icon:ye},color:{label:`Color`,Icon:fn},code:{label:`Code`,Icon:_t},location:{label:`Location`,Icon:Se},address:{label:`Address`,Icon:Se},rating:{label:`Rating`,Icon:rr},slider:{label:`Slider`,Icon:bn}},Mp={text:[`text`,`textarea`,`email`,`phone`,`url`,`password`,`markdown`,`html`],number:[`number`,`currency`,`percent`,`autonumber`,`rating`,`slider`],date:[`date`,`datetime`,`time`],choice:[`boolean`,`select`],relation:[`lookup`],advanced:[`formula`,`file`,`image`,`color`,`code`,`location`,`address`]},Np=[`text`,`number`,`date`,`choice`,`relation`,`advanced`];function Pp({objectName:e,fields:t,onFieldsChange:n,readOnly:r=!1,className:i}){let{t:a}=Kf(),o=mf(),[s,c]=(0,Z.useState)(!1),[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(``),p=(0,Z.useMemo)(()=>d?t.filter(e=>e.type===d):t,[t,d]),m=(0,Z.useMemo)(()=>new z({items:p}),[p]),h=(0,Z.useMemo)(()=>[{field:`name`,label:a(`appDesigner.fieldDesigner.fieldName`),width:140},{field:`label`,label:a(`appDesigner.fieldDesigner.fieldLabel`),width:160},{field:`type`,label:a(`appDesigner.fieldDesigner.fieldType`),width:100},{field:`required`,label:a(`appDesigner.fieldDesigner.required`),width:80},{field:`unique`,label:a(`appDesigner.fieldDesigner.unique`),width:80},{field:`group`,label:a(`appDesigner.fieldDesigner.fieldGroup`),width:120}],[a]),g=(0,Z.useMemo)(()=>({type:`object-grid`,objectName:`field_definition`,columns:h,searchableFields:[`name`,`label`,`description`],showSearch:!0,operations:r?void 0:{create:!0,update:!0,delete:!0}}),[h,r]),_=(0,Z.useCallback)(e=>{let n=t.find(t=>t.name===e.name);n&&(u(n),c(!0))},[t]),v=(0,Z.useCallback)(async e=>{let r=t.find(t=>t.name===e.name);!r||r.isSystem||await o.confirm(a(`appDesigner.fieldDesigner.deleteConfirmTitle`),a(`appDesigner.fieldDesigner.deleteConfirmMessage`))&&n?.(t.filter(e=>e.id!==r.id))},[t,n,o,a]),y=(0,Z.useCallback)(()=>{u(null),c(!0)},[]),b=(0,Z.useCallback)(e=>{if(l){let r={...l,name:String(e.name||l.name),label:String(e.label||l.label),type:e.type||l.type,group:e.group?String(e.group):void 0,description:e.description?String(e.description):void 0,required:e.required===!0,unique:e.unique===!0,readonly:e.readonly===!0,hidden:e.hidden===!0,indexed:e.indexed===!0,externalId:e.externalId===!0,trackHistory:e.trackHistory===!0,defaultValue:e.defaultValue?String(e.defaultValue):void 0,placeholder:e.placeholder?String(e.placeholder):void 0,referenceTo:e.referenceTo?String(e.referenceTo):void 0,formula:e.formula?String(e.formula):void 0};n?.(t.map(e=>e.id===l.id?r:e))}else{let r={id:`fld_${Date.now()}`,name:String(e.name||`new_field_${t.length+1}`),label:String(e.label||`New Field ${t.length+1}`),type:e.type||`text`,group:e.group?String(e.group):void 0,description:e.description?String(e.description):void 0,required:e.required===!0,unique:e.unique===!0,readonly:e.readonly===!0,hidden:e.hidden===!0,indexed:e.indexed===!0,externalId:e.externalId===!0,trackHistory:e.trackHistory===!0,defaultValue:e.defaultValue?String(e.defaultValue):void 0,placeholder:e.placeholder?String(e.placeholder):void 0,referenceTo:e.referenceTo?String(e.referenceTo):void 0,formula:e.formula?String(e.formula):void 0,isSystem:!1};n?.([...t,r])}c(!1),u(null)},[l,t,n]),x=(0,Z.useCallback)(e=>{e||(c(!1),u(null))},[]),S=(0,Z.useMemo)(()=>Np.map(e=>({category:e,label:a(`appDesigner.fieldDesigner.typeCategory.${e}`),options:Mp[e].map(e=>({label:jp[e].label,value:e}))})),[a]),C=(0,Z.useMemo)(()=>S.flatMap(e=>e.options),[S]),w=(0,Z.useMemo)(()=>({type:`object-form`,formType:`drawer`,objectName:`field_definition`,mode:l?`edit`:`create`,title:l?`${a(`common.edit`)} — ${l.label}`:a(`appDesigner.fieldDesigner.addField`),open:s,onOpenChange:x,drawerSide:`right`,drawerWidth:`480px`,sections:[{name:`basic`,label:a(`appDesigner.fieldDesigner.basicSection`),fields:[{name:`name`,label:a(`appDesigner.fieldDesigner.fieldName`),type:`text`,required:!0,placeholder:`api_name`,disabled:r||(l?.isSystem??!1)},{name:`label`,label:a(`appDesigner.fieldDesigner.fieldLabel`),type:`text`,required:!0,placeholder:`Display Label`,disabled:r},{name:`type`,label:a(`appDesigner.fieldDesigner.fieldType`),type:`select`,required:!0,options:C,disabled:r||(l?.isSystem??!1)},{name:`required`,label:a(`appDesigner.fieldDesigner.required`),type:`boolean`,disabled:r},{name:`unique`,label:a(`appDesigner.fieldDesigner.unique`),type:`boolean`,disabled:r},{name:`description`,label:a(`appDesigner.fieldDesigner.description`),type:`textarea`,disabled:r}]},{name:`typeSpecific`,label:a(`appDesigner.fieldDesigner.typeSpecificSection`),fields:[{name:`referenceTo`,label:a(`appDesigner.fieldDesigner.referenceTo`),type:`text`,placeholder:`Referenced object`,disabled:r,condition:{field:`type`,equals:`lookup`}},{name:`formula`,label:a(`appDesigner.fieldDesigner.formula`),type:`textarea`,placeholder:`e.g. price * quantity`,disabled:r,condition:{field:`type`,equals:`formula`}},{name:`defaultValue`,label:a(`appDesigner.fieldDesigner.defaultValue`),type:`text`,placeholder:`Default value`,disabled:r},{name:`placeholder`,label:a(`appDesigner.fieldDesigner.placeholder`),type:`text`,placeholder:`Placeholder text`,disabled:r},{name:`group`,label:a(`appDesigner.fieldDesigner.fieldGroup`),type:`text`,placeholder:`Field Group`,disabled:r}]},{name:`advanced`,label:a(`appDesigner.fieldDesigner.advancedSection`),collapsible:!0,collapsed:!0,fields:[{name:`indexed`,label:a(`appDesigner.fieldDesigner.indexed`),type:`boolean`,disabled:r},{name:`externalId`,label:a(`appDesigner.fieldDesigner.externalId`),type:`boolean`,disabled:r},{name:`trackHistory`,label:a(`appDesigner.fieldDesigner.trackHistory`),type:`boolean`,disabled:r},{name:`readonly`,label:a(`appDesigner.fieldDesigner.readOnly`),type:`boolean`,disabled:r},{name:`hidden`,label:a(`appDesigner.fieldDesigner.hidden`),type:`boolean`,disabled:r}]}],initialValues:l?{name:l.name,label:l.label,type:l.type,group:l.group||``,description:l.description||``,required:l.required||!1,unique:l.unique||!1,readonly:l.readonly||!1,hidden:l.hidden||!1,indexed:l.indexed||!1,externalId:l.externalId||!1,trackHistory:l.trackHistory||!1,defaultValue:l.defaultValue==null?``:String(l.defaultValue),placeholder:l.placeholder||``,referenceTo:l.referenceTo||``,formula:l.formula||``}:{type:`text`,required:!1,unique:!1},onSuccess:b,onCancel:()=>x(!1),readOnly:r}),[l,s,x,b,C,r,a]);return(0,Q.jsxs)(`div`,{"data-testid":`field-designer`,className:Ap(`w-full space-y-3`,i),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)(Yt,{className:`h-4 w-4 text-primary`}),(0,Q.jsx)(`h2`,{className:`text-sm font-semibold`,children:a(`appDesigner.fieldDesigner.title`)}),e&&(0,Q.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`— `,e]}),(0,Q.jsx)(`span`,{className:`rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:p.length})]}),(0,Q.jsxs)(`select`,{value:d,onChange:e=>f(e.target.value),"data-testid":`field-designer-type-filter`,className:`rounded-md border border-input bg-background px-2 py-1 text-xs outline-none transition-colors focus:border-primary focus:ring-1 focus:ring-primary`,children:[(0,Q.jsx)(`option`,{value:``,children:a(`appDesigner.fieldDesigner.allTypes`)}),S.map(e=>(0,Q.jsx)(`optgroup`,{label:e.label,children:e.options.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value))},e.category))]})]}),(0,Q.jsx)(ma,{schema:g,dataSource:m,onEdit:r?void 0:_,onDelete:r?void 0:v,onAddRecord:r?void 0:y}),s&&(0,Q.jsx)(ni,{schema:w}),(0,Q.jsx)(yf,{isOpen:o.isOpen,title:o.title,message:o.message,confirmLabel:a(`common.delete`),cancelLabel:a(`common.cancel`),onConfirm:o.onConfirm,onCancel:o.onCancel,destructive:!0})]})}var Fp=`objectui-app-wizard-draft`;function Ip(){let e=_(),{appName:t}=o(),{objects:n,refresh:r}=F(),i=se(),a=(n||[]).map(e=>({name:e.name,label:e.label||e.name,icon:e.icon,selected:!1})),s=(0,Z.useCallback)(()=>{try{let e=localStorage.getItem(Fp);if(e)return JSON.parse(e)}catch{}},[]),c=(0,Z.useCallback)(async t=>{try{let n=oe(t),a=i?.getClient();a&&await a.meta.saveItem(`app`,t.name,n),localStorage.removeItem(Fp),X.success(`Application "${t.title}" created successfully`),await r?.(),e(`/apps/${t.name}`)}catch(e){X.error(e?.message||`Failed to create application`)}},[e,r,i]),l=(0,Z.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),u=(0,Z.useCallback)(e=>{try{localStorage.setItem(Fp,JSON.stringify(e)),X.info(`Draft saved`)}catch{}},[]);return(0,Q.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`create-app-page`,children:(0,Q.jsx)(ip,{availableObjects:a,initialDraft:s(),onComplete:c,onCancel:l,onSaveDraft:u})})}function Lp(){let e=_(),{appName:t,editAppName:n}=o(),{apps:r,objects:i,refresh:a}=F(),s=se(),c=n||t,l=r.find(e=>e.name===c),u=(i||[]).map(e=>({name:e.name,label:e.label||e.name,icon:e.icon,selected:l?.navigation?.some(t=>t.type===`object`&&t.objectName===e.name)??!1})),d=(0,Z.useMemo)(()=>{if(l)return{name:l.name,title:l.title||l.label||``,description:l.description||``,icon:l.icon||``,layout:l.layout||`sidebar`,navigation:l.navigation||[],branding:{logo:l.branding?.logo||l.logo||``,primaryColor:l.branding?.primaryColor||`#3b82f6`,favicon:l.branding?.favicon||l.favicon||``}}},[l]),f=(0,Z.useCallback)(async t=>{try{let n=oe(t),r={...l,...n},i=s?.getClient();i&&await i.meta.saveItem(`app`,t.name,r),X.success(`Application "${t.title}" updated successfully`),await a?.(),e(`/apps/${t.name}`)}catch(e){X.error(e?.message||`Failed to update application`)}},[e,a,s,l]),p=(0,Z.useCallback)(()=>{e(t?`/apps/${t}`:`/`)},[e,t]),m=(0,Z.useCallback)(e=>{try{localStorage.setItem(`objectui-edit-draft-${c}`,JSON.stringify(e)),X.info(`Draft saved`)}catch{}},[c]);return l?(0,Q.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4`,"data-testid":`edit-app-page`,children:(0,Q.jsx)(ip,{availableObjects:u,initialDraft:d,onComplete:f,onCancel:p,onSaveDraft:m})}):(0,Q.jsx)(`div`,{className:`mx-auto max-w-4xl py-8 px-4 text-center`,"data-testid":`edit-app-not-found`,children:(0,Q.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Application "`,c,`" not found.`]})})}function Rp(){let e=_(),{dashboardName:t}=o(),n=se(),{dashboards:r,refresh:i}=F(),a=r?.find(e=>e.name===t),[s,c]=(0,Z.useState)(()=>a||{type:`dashboard`,name:t??``,title:t??``,columns:2,widgets:[]}),l=(0,Z.useRef)(s);l.current=s;let u=(0,Z.useCallback)(async e=>{try{if(n)return await n.update(`sys_dashboard`,t,e),i().catch(()=>{}),!0}catch{}return!1},[n,t,i]),d=(0,Z.useCallback)(async e=>{c(e),await u(e)},[u]);(0,Z.useEffect)(()=>{let e=e=>{(e.ctrlKey||e.metaKey)&&e.key===`s`&&(e.preventDefault(),u(l.current).then(e=>{e&&X.success(`Dashboard saved`)}))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[u]);let f=(0,Z.useCallback)(e=>{let n=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${t||`dashboard`}.json`,i.click(),URL.revokeObjectURL(r),X.success(`Dashboard schema exported`)},[t]),p=(0,Z.useCallback)(e=>{X.success(`Dashboard schema imported`),d(e)},[d]);return a?(0,Q.jsxs)(`div`,{className:`h-full flex flex-col`,"data-testid":`dashboard-design-page`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-4 py-3 sm:px-6`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>e(-1),className:`rounded p-1.5 text-muted-foreground hover:text-foreground`,"aria-label":`Go back`,"data-testid":`dashboard-design-back`,children:(0,Q.jsx)(an,{className:`h-4 w-4`})}),(0,Q.jsxs)(`h1`,{className:`text-lg font-semibold tracking-tight truncate`,children:[`Edit Dashboard: `,a.label||a.title||t]})]}),(0,Q.jsx)(`div`,{className:`flex-1 overflow-auto p-4 sm:p-6`,children:(0,Q.jsx)(xp,{schema:s,onChange:d,onExport:f,onImport:p})})]}):(0,Q.jsxs)(`div`,{className:`h-full flex items-center justify-center text-muted-foreground`,children:[`Dashboard "`,t,`" not found`]})}var zp=t({AppCreationWizard:()=>ip,BrandingEditor:()=>Tp,CreateAppPage:()=>Ip,DashboardDesignPage:()=>Rp,DashboardEditor:()=>xp,DataModelDesigner:()=>Pf,EditAppPage:()=>Lp,FieldDesigner:()=>Pp,NavigationDesigner:()=>pp,ObjectManager:()=>kp,PageDesigner:()=>Of,ProcessDesigner:()=>zf,ReportDesigner:()=>Uf});B.register(`page-designer`,Of,{namespace:`plugin-designer`,label:`Page Designer`,category:`Designer`,inputs:[{name:`canvas`,type:`code`,label:`Canvas Configuration`},{name:`components`,type:`code`,label:`Components`},{name:`showComponentTree`,type:`boolean`,label:`Show Component Tree`,defaultValue:!0},{name:`undoRedo`,type:`boolean`,label:`Undo/Redo`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),B.register(`data-model-designer`,Pf,{namespace:`plugin-designer`,label:`Data Model Designer`,category:`Designer`,inputs:[{name:`entities`,type:`code`,label:`Entities`},{name:`relationships`,type:`code`,label:`Relationships`},{name:`autoLayout`,type:`boolean`,label:`Auto Layout`,defaultValue:!1},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),B.register(`process-designer`,zf,{namespace:`plugin-designer`,label:`Process Designer (BPMN)`,category:`Designer`,inputs:[{name:`processName`,type:`string`,label:`Process Name`},{name:`nodes`,type:`code`,label:`Nodes`},{name:`edges`,type:`code`,label:`Edges`},{name:`showMinimap`,type:`boolean`,label:`Show Minimap`,defaultValue:!1},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),B.register(`report-designer`,Uf,{namespace:`plugin-designer`,label:`Report Designer`,category:`Designer`,inputs:[{name:`reportName`,type:`string`,label:`Report Name`},{name:`objectName`,type:`string`,label:`Data Source Object`},{name:`sections`,type:`code`,label:`Sections`},{name:`showToolbar`,type:`boolean`,label:`Show Toolbar`,defaultValue:!0},{name:`showPropertyPanel`,type:`boolean`,label:`Show Property Panel`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),B.register(`app-creation-wizard`,ip,{namespace:`plugin-designer`,label:`App Creation Wizard`,category:`Designer`,inputs:[{name:`availableObjects`,type:`code`,label:`Available Objects`},{name:`templates`,type:`code`,label:`Templates`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),B.register(`navigation-designer`,pp,{namespace:`plugin-designer`,label:`Navigation Designer`,category:`Designer`,inputs:[{name:`items`,type:`code`,label:`Navigation Items`},{name:`showPreview`,type:`boolean`,label:`Show Preview`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),B.register(`dashboard-editor`,xp,{namespace:`plugin-designer`,label:`Dashboard Editor`,category:`Designer`,inputs:[{name:`schema`,type:`code`,label:`Dashboard Schema`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),B.register(`branding-editor`,Tp,{namespace:`plugin-designer`,label:`Branding Editor`,category:`Designer`,inputs:[{name:`branding`,type:`code`,label:`Branding Config`},{name:`appTitle`,type:`string`,label:`App Title`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),B.register(`object-manager`,kp,{namespace:`plugin-designer`,label:`Object Manager`,category:`Designer`,inputs:[{name:`objects`,type:`code`,label:`Object Definitions`},{name:`showSystemObjects`,type:`boolean`,label:`Show System Objects`,defaultValue:!0},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]}),B.register(`field-designer`,Pp,{namespace:`plugin-designer`,label:`Field Designer`,category:`Designer`,inputs:[{name:`objectName`,type:`string`,label:`Object Name`},{name:`fields`,type:`code`,label:`Field Definitions`},{name:`readOnly`,type:`boolean`,label:`Read Only`,defaultValue:!1}]});function Bp(e,t){return{name:e.name,label:e.label,pluralLabel:e.pluralLabel,description:e.description,icon:e.icon,group:e.group,sortOrder:e.sortOrder,enabled:e.enabled,fields:t,relationships:e.relationships}}function Vp(e){return{name:e.name,label:e.label,type:e.type,group:e.group,description:e.description,required:e.required,unique:e.unique,readonly:e.readonly,hidden:e.hidden,defaultValue:e.defaultValue,placeholder:e.placeholder,options:e.options,externalId:e.externalId,trackHistory:e.trackHistory,indexed:e.indexed,referenceTo:e.referenceTo,formula:e.formula,sortOrder:e.sortOrder}}var Hp=class{adapter;constructor(e){this.adapter=e}async getItems(e){let t=await this.adapter.getClient().meta.getItems(e);return t&&typeof t==`object`&&`items`in t&&Array.isArray(t.items)?t.items:[]}async saveMetadataItem(e,t,n){await this.adapter.getClient().meta.saveItem(e,t,n),this.adapter.invalidateCache(`${e}:${t}`)}async deleteMetadataItem(e,t){await this.adapter.getClient().meta.saveItem(e,t,{name:t,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`${e}:${t}`)}async saveObject(e,t){let n=this.adapter.getClient(),r=Bp(e,t);await n.meta.saveItem(`object`,e.name,r),this.adapter.invalidateCache(`object:${e.name}`)}async deleteObject(e){await this.adapter.getClient().meta.saveItem(`object`,e,{name:e,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`object:${e}`)}async saveFields(e,t){let n=this.adapter.getClient(),r={};try{let t=await n.meta.getItem(`object`,e);r=t?.item??t??{}}catch{}let i={...r,name:e,fields:t.map(Vp)};await n.meta.saveItem(`object`,e,i),this.adapter.invalidateCache(`object:${e}`)}static diffObjects(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,object:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,object:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,object:t}}return null}static diffFields(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,field:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,field:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,field:t}}return null}};function Up({schema:e}){let t=e.objectName,{objects:n,refresh:r}=F(),i=Os(),a=(0,Z.useMemo)(()=>(n||[]).find(e=>e.name===t),[n,t]),o=(0,Z.useMemo)(()=>a?(Array.isArray(a.fields)?a.fields:Object.values(a.fields||{})).map(nf):[],[a]),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(!1),d=s??o,f=(0,Z.useRef)(d),p=(0,Z.useCallback)(async e=>{let n=f.current;if(c(e),f.current=e,!i){X.error(`Service unavailable — changes saved locally only`);return}let a=Hp.diffFields(n,e),o=a?a.type===`create`?`Field "${a.field.label||a.field.name}" created`:a.type===`update`?`Field "${a.field.label||a.field.name}" updated`:`Field "${a.field.label||a.field.name}" deleted`:`Field configuration updated`;u(!0);try{await i.saveFields(t,e),await r(),X.success(o)}catch(e){c(n),f.current=n,X.error(e?.message||`Failed to save field changes`)}finally{u(!1)}},[i,t,r]);return(0,Q.jsxs)(`div`,{className:`space-y-3`,"data-testid":`field-management-section`,children:[l&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,"data-testid":`field-saving-indicator`,children:[(0,Q.jsx)(q,{className:`h-4 w-4 animate-spin`}),`Saving field changes…`]}),d.some(e=>e.isSystem)&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground bg-muted/50 rounded-md px-3 py-2`,"data-testid":`system-field-hint`,children:[(0,Q.jsx)(Ur,{className:`h-3.5 w-3.5 shrink-0`}),`System fields (e.g. id, createdAt, updatedAt) are read-only and cannot be edited or deleted.`]}),(0,Q.jsx)(Pp,{objectName:t,fields:d,onFieldsChange:p})]})}function Wp({schema:e}){let t=e.objectName,[n,r]=(0,Z.useState)(`details`),i={type:`object-properties`,id:`${t}-properties`,objectName:t},a={type:`object-field-designer`,id:`${t}-field-designer`,objectName:t},o={type:`object-relationships`,id:`${t}-relationships`,objectName:t},s={type:`object-keys`,id:`${t}-keys`,objectName:t},c={type:`object-data-experience`,id:`${t}-data-experience`,objectName:t},l={type:`object-data-preview`,id:`${t}-data-preview`,objectName:t};return(0,Q.jsx)(`div`,{className:`w-full`,"data-testid":`object-detail-tabs`,children:(0,Q.jsxs)(or,{value:n,onValueChange:r,className:`w-full`,children:[(0,Q.jsxs)(Vn,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,Q.jsxs)(cn,{value:`details`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,Q.jsx)(Vr,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,Q.jsxs)(cn,{value:`fields`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,Q.jsx)(Yt,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,Q.jsxs)(cn,{value:`relationships`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,Q.jsx)(Be,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,Q.jsxs)(cn,{value:`data`,className:`relative rounded-none border-b-2 border-transparent data-[state=active]:border-primary data-[state=active]:bg-transparent data-[state=active]:shadow-none`,children:[(0,Q.jsx)(Xt,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,Q.jsx)(vr,{value:`details`,className:`mt-6`,children:(0,Q.jsx)(`div`,{className:`space-y-6`,children:(0,Q.jsx)(j,{schema:i})})}),(0,Q.jsx)(vr,{value:`fields`,className:`mt-6`,children:(0,Q.jsx)(`div`,{className:`space-y-6`,children:(0,Q.jsx)(j,{schema:a})})}),(0,Q.jsx)(vr,{value:`relationships`,className:`mt-6`,children:(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsx)(j,{schema:o}),(0,Q.jsx)(j,{schema:s})]})}),(0,Q.jsx)(vr,{value:`data`,className:`mt-6`,children:(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsx)(j,{schema:l}),(0,Q.jsx)(j,{schema:c})]})})]})})}var Gp={namespace:`console`,category:`system`};B.register(`object-detail-tabs`,Wp,{...Gp,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),B.register(`object-properties`,of,{...Gp,label:`Object Properties`,icon:`Settings2`}),B.register(`object-relationships`,cf,{...Gp,label:`Object Relationships`,icon:`Link2`}),B.register(`object-keys`,lf,{...Gp,label:`Object Keys`,icon:`KeyRound`}),B.register(`object-data-experience`,uf,{...Gp,label:`Data Experience`,icon:`LayoutList`}),B.register(`object-data-preview`,df,{...Gp,label:`Data Preview`,icon:`Table`}),B.register(`object-field-designer`,Up,{...Gp,label:`Field Designer`,icon:`Columns`});var Kp=(0,Z.lazy)(()=>u(()=>import(`./ApiConsolePage-DGCgQ6RS.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),qp=(0,Z.lazy)(()=>u(()=>import(`./FlowRunsPage-DcT6ntvZ.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),Jp=(0,Z.lazy)(()=>u(()=>import(`./PublicFormsPage-N0Wofan4.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function Yp({label:e}){return(0,Q.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}su({ref:`developer:api-console`,label:`API Console`,source:`@objectstack/console`,component:e=>(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Yp,{label:`API console`}),children:(0,Q.jsx)(Kp,{...e})})}),su({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@objectstack/console`,component:e=>(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Yp,{label:`flow runs`}),children:(0,Q.jsx)(qp,{...e})})}),su({ref:`developer:public-forms`,label:`Public Forms`,source:`@objectstack/console`,component:e=>(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Yp,{label:`public forms`}),children:(0,Q.jsx)(Jp,{...e})})});var Xp=(0,Z.lazy)(()=>u(()=>import(`./ProfilePage-C11r_2xN.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function Zp({label:e}){return(0,Q.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}su({ref:`account:profile_card`,label:`My Profile`,source:`@objectstack/console`,component:e=>(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Zp,{label:`profile`}),children:(0,Q.jsx)(Xp,{...e})})});var Qp=`/api/v1/auth`;ns(),B.registerLazy(`object-map`,()=>u(()=>import(`./plugin-map-DuGG00x5.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),B.registerLazy(`map`,()=>u(()=>import(`./plugin-map-DuGG00x5.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`dashboard`,`metric`,`metric-card`,`object-metric`,`pivot`,`object-pivot`,`dashboard-grid`,`object-data-table`])B.registerLazy(e,()=>u(()=>import(`./plugin-dashboard-BQ3awX8y.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});B.registerLazy(`chart`,()=>u(()=>import(`./plugin-charts-Do3qrshN.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});for(let e of[`object-chart`,`bar-chart`,`pie-chart`,`donut-chart`,`radar-chart`,`scatter-chart`,`line-chart`,`area-chart`,`advanced-chart`,`chart:bar`])B.registerLazy(e,()=>u(()=>import(`./plugin-charts-Do3qrshN.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});B.registerLazy(`object-gantt`,()=>u(()=>import(`./plugin-gantt-CWw13thv.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),B.registerLazy(`gantt`,()=>u(()=>import(`./plugin-gantt-CWw13thv.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),B.registerLazy(`markdown`,()=>u(()=>import(`./plugin-markdown-Du1ajwhj.js`).then(e=>e.n),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),B.registerLazy(`object-timeline`,()=>u(()=>import(`./plugin-timeline-BBYlrrgQ.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),B.registerLazy(`timeline`,()=>u(()=>import(`./plugin-timeline-BBYlrrgQ.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),B.registerLazy(`object-calendar`,()=>u(()=>import(`./plugin-calendar-DCCbdIpj.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),B.registerLazy(`calendar`,()=>u(()=>import(`./plugin-calendar-DCCbdIpj.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),B.registerLazy(`calendar-view`,()=>u(()=>import(`./plugin-calendar-DCCbdIpj.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),B.registerLazy(`object-kanban`,()=>u(()=>import(`./plugin-kanban-CYKs5Fuv.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),B.registerLazy(`kanban`,()=>u(()=>import(`./plugin-kanban-CYKs5Fuv.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`kanban-ui`,`kanban-enhanced`])B.registerLazy(e,()=>u(()=>import(`./plugin-kanban-CYKs5Fuv.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});B.registerLazy(`report`,()=>u(()=>import(`./plugin-report-D0COS83c.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});for(let e of[`report-viewer`,`spec-report`])B.registerLazy(e,()=>u(()=>import(`./plugin-report-D0COS83c.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});ct();var $p=``.replace(/\/+$/,``);Promise.all([ca($p),ef(Qp)]).finally(()=>{Ma.createRoot(document.getElementById(`root`)).render((0,Q.jsx)(Z.StrictMode,{children:(0,Q.jsx)(pa,{pwa:{enabled:!0,name:sa(),shortName:la()},children:(0,Q.jsx)(ae,{loadLanguage:Zd,children:(0,Q.jsx)(Xd,{})})})}))});export{Qs as a,Sl as i,cu as n,ac as o,wl as r,Zs as s,sd as t};
|