@objectstack/console 9.5.1 → 9.6.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-BrKPQ1rE.js → AdapterProvider-o2n9dY2j.js} +1 -1
- package/dist/assets/{AiPendingActionsPage-BcncanbT.js → AiPendingActionsPage-DGAL-HJ9.js} +1 -1
- package/dist/assets/{ApiConsolePage-C6tVqeCx.js → ApiConsolePage-DNuInlzy.js} +1 -1
- package/dist/assets/{AppDocsIndex-D--pdm0E.js → AppDocsIndex-DtACBq8P.js} +1 -1
- package/dist/assets/{AppManagementPage-B66TgUPL.js → AppManagementPage-BSgP2T9T.js} +1 -1
- package/dist/assets/{ApprovalsInboxPage-C8mv1Yo5.js → ApprovalsInboxPage-jrTqrLxX.js} +1 -1
- package/dist/assets/{AuditLogPage-CS-Jundr.js → AuditLogPage-B_gxba-u.js} +1 -1
- package/dist/assets/{ComponentNavView-Br-wa130.js → ComponentNavView-BSV-rPCq.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-B1xDv7X-.js +1 -0
- package/dist/assets/DashboardView-BNUhTJ8Y.js +1 -0
- package/dist/assets/{DashboardWidgetInspector-Cr6cJ0BC.js → DashboardWidgetInspector-CNmycNmj.js} +1 -1
- package/dist/assets/{DeveloperHubPage-B3I-35Xy.js → DeveloperHubPage-YvUkG7Lt.js} +1 -1
- package/dist/assets/{ExpressionProvider-CqfGEBur.js → ExpressionProvider-Cuv0RaiR.js} +1 -1
- package/dist/assets/{FlowRunsPage-CATcsy8B.js → FlowRunsPage-DdjGSDw1.js} +1 -1
- package/dist/assets/{IntegrationsPage-Cq1qq5jk.js → IntegrationsPage-C8k36Ie_.js} +1 -1
- package/dist/assets/{InterfaceListPage-OHu23CRA.js → InterfaceListPage-DTHEyaKG.js} +1 -1
- package/dist/assets/{ManagedByBadge-BodEaDXN.js → ManagedByBadge-B60ZX6y9.js} +1 -1
- package/dist/assets/{MarketplaceInstalledPage-B5oYOVdC.js → MarketplaceInstalledPage-DJN3P4aw.js} +1 -1
- package/dist/assets/{MarketplacePackagePage-DnmqDFCq.js → MarketplacePackagePage-BUrsYfA7.js} +1 -1
- package/dist/assets/{MarketplacePage-C5lziiq9.js → MarketplacePage-q23E8dYU.js} +1 -1
- package/dist/assets/{MetadataInspector-BMHaVCoM.js → MetadataInspector-zJtxyFau.js} +1 -1
- package/dist/assets/{MetadataProvider-Cvue7gQ0.js → MetadataProvider-BagIop6q.js} +1 -1
- package/dist/assets/PageView-M09zUJqv.js +1 -0
- package/dist/assets/{ProfilePage-BBeI_CPu.js → ProfilePage-0yyBZHjT.js} +1 -1
- package/dist/assets/PublicFormsPage-BPEDFiNo.js +1 -0
- package/dist/assets/{RecentItemsProvider-gLV-GFpQ.js → RecentItemsProvider-B76qldBH.js} +1 -1
- package/dist/assets/RecordDetailView-cj45YVH-.js +1 -0
- package/dist/assets/RecordFormPage-DqFdHPz8.js +1 -0
- package/dist/assets/{ReportDefaultInspector-CmSJUILm.js → ReportDefaultInspector-D5dIioUJ.js} +1 -1
- package/dist/assets/{ReportView-_NBbKT5l.js → ReportView-Cx-qFxJZ.js} +1 -1
- package/dist/assets/{RuntimeDraftBar-DroTFTnx.js → RuntimeDraftBar-Be6SQ4g6.js} +1 -1
- package/dist/assets/{SearchResultsPage-D9HdE2xf.js → SearchResultsPage-DkQMPMlE.js} +1 -1
- package/dist/assets/{SettingsHub-Ca4TQg_Q.js → SettingsHub-el09ZPJP.js} +1 -1
- package/dist/assets/{SettingsView-6GSnMLNA.js → SettingsView-BiYeb1nb.js} +1 -1
- package/dist/assets/{SystemHubPage-maebng1S.js → SystemHubPage-QSk3FL5a.js} +1 -1
- package/dist/assets/{data-adapter-SqbPGFBI.js → data-adapter-BtpuYbBh.js} +1 -1
- package/dist/assets/{framework-CVigpa4L.js → framework-ZJouI0cJ.js} +6 -6
- package/dist/assets/{highlighted-body-OFNGDK62-B0SlzSfX.js → highlighted-body-OFNGDK62-DfdyR_41.js} +1 -1
- package/dist/assets/index-B99f8h8i.js +4 -0
- package/dist/assets/index-BXu9hpEZ.css +2 -0
- package/dist/assets/infrastructure-CJNwTVno.js +3 -0
- package/dist/assets/{marketplaceApi-Cw1CUgrg.js → marketplaceApi-DCvJ2C6u.js} +1 -1
- package/dist/assets/{mergeServerFields-DKhjl-pc.js → mergeServerFields-DPrTk8u4.js} +2 -2
- package/dist/assets/mermaid-GHXKKRXX-BF-AoOMn.js +1 -0
- package/dist/assets/metadata-admin-DT8BohcC.js +19 -0
- package/dist/assets/{plugin-calendar-BWXBFRkE.js → plugin-calendar-CwYuZf8c.js} +1 -1
- package/dist/assets/plugin-charts-DhlEvpuy.js +7 -0
- package/dist/assets/{plugin-chatbot-CBg5Zd15.js → plugin-chatbot-CJsfoGAD.js} +45 -45
- package/dist/assets/plugin-dashboard-CGRjBe2V.js +5 -0
- package/dist/assets/plugin-form-C5yl9byI.js +1 -0
- package/dist/assets/plugin-gantt-C5hIQDHF.js +23 -0
- package/dist/assets/{plugin-grid-BsA9XQ8Q.js → plugin-grid-2QHjCxCx.js} +4 -4
- package/dist/assets/{plugin-kanban-DTWtfUzv.js → plugin-kanban-LtqKit9T.js} +1 -1
- package/dist/assets/{plugin-map-B-PDDoET.js → plugin-map-Cz9tJHoZ.js} +1 -1
- package/dist/assets/{plugin-markdown--e1MOP0x.js → plugin-markdown-_H-xFg2t.js} +1 -1
- package/dist/assets/{plugin-report-BTvuqkOa.js → plugin-report-DA6bVPuW.js} +2 -2
- package/dist/assets/{plugin-timeline-Dmqt8jd_.js → plugin-timeline-DjngAdR-.js} +1 -1
- package/dist/assets/plugin-view-BUsWmCh-.js +1 -0
- package/dist/assets/plugins-views-yfd0iHKg.js +4 -0
- package/dist/assets/resolveActionParams-ergReBd1.js +9 -0
- package/dist/assets/{skeletons-D42JPA2I.js → skeletons-BRDBm95C.js} +1 -1
- package/dist/assets/{src-B-bY4wJT.js → src-B5JRlZgC.js} +1 -1
- package/dist/assets/{types-HYNWZWMw.js → types-fX7qb4I3.js} +1 -1
- package/dist/assets/ui-components-Bs-DxYrW.js +42 -0
- package/dist/assets/{ui-layout-DM7b0Gu1.js → ui-layout-CswtJjnW.js} +1 -1
- package/dist/assets/{useActionModal-DcFjU7Dq.js → useActionModal-d8GNl1HP.js} +1 -1
- package/dist/assets/{vendor-markdown-DIJxJfmj.js → vendor-markdown-CyAGIM8D.js} +2 -2
- package/dist/assets/vendor-objectstack-BNd856rx.js +96 -0
- package/dist/assets/{vendor-sentry-Cv_7Tgs6.js → vendor-sentry-BIOhD5Kg.js} +14 -14
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/dist/assets/ConsoleFloatingChatbot-CIsrrZv4.js +0 -1
- package/dist/assets/DashboardView-HNhMjAZZ.js +0 -1
- package/dist/assets/PageView-H7j3JwJI.js +0 -1
- package/dist/assets/PublicFormsPage-Bhp5KfIY.js +0 -1
- package/dist/assets/RecordDetailView-CGxfnls1.js +0 -1
- package/dist/assets/RecordFormPage-B8sjq5K3.js +0 -1
- package/dist/assets/index-TlmJdKxQ.js +0 -4
- package/dist/assets/index-mrmp6qU6.css +0 -2
- package/dist/assets/infrastructure-ckitl7Ev.js +0 -3
- package/dist/assets/mermaid-GHXKKRXX-DOu_26de.js +0 -1
- package/dist/assets/metadata-admin-2GXysZST.js +0 -19
- package/dist/assets/plugin-charts-Ck5EMx6H.js +0 -7
- package/dist/assets/plugin-dashboard-DJturdHm.js +0 -5
- package/dist/assets/plugin-form-CM6RvRf2.js +0 -1
- package/dist/assets/plugin-gantt-DO7NQ-4h.js +0 -23
- package/dist/assets/plugin-view-CmAdMV7R.js +0 -1
- package/dist/assets/plugins-views-BP1sk9hy.js +0 -4
- package/dist/assets/resolveActionParams-CWIOgcoF.js +0 -9
- package/dist/assets/ui-components-BK0FqwOC.js +0 -42
- package/dist/assets/vendor-objectstack-RB3xvhcR.js +0 -102
|
@@ -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-ckitl7Ev.js";import{$ as A,A as j,B as M,F as N,I as P,N as F,O as ee,T as I,U as te,V as ne,a as L,at as R,b as re,it as z,j as ie,mt as B,n as ae,o as oe,r as V,st as se,w as ce}from"./framework-CVigpa4L.js";import{$i as le,$n as ue,$o as de,$r as fe,$s as H,$t as pe,Aa as U,Ai as me,An as he,Ar as ge,As as _e,Ba as ve,Bn as ye,Bs as be,Bt as xe,Cs as Se,Ct as Ce,Da as we,Do as Te,Ds as Ee,Dt as De,Ea as Oe,Es as W,F as G,Fn as ke,Fo as Ae,Fr as je,Ft as Me,Ga as Ne,Gt as Pe,H as Fe,Hi as Ie,Hn as Le,Ho as Re,Hs as ze,Ht as Be,I as Ve,Ia as He,Ii as Ue,In as We,Io as Ge,Ir as Ke,It as qe,Jn as Je,Jo as Ye,Ks as Xe,La as Ze,Ln as Qe,Lr as $e,Lt as et,Mn as tt,Mr as nt,Na as rt,Nn as it,No as at,Ns as ot,O as st,Oa as ct,Oo as lt,Pa as ut,Pi as dt,Pn as ft,Po as pt,Pr as mt,Pt as ht,Qa as gt,Qi as _t,Qr as vt,R as yt,Ra as bt,Rn as xt,Rr as St,Rt as Ct,Si as wt,So as Tt,Sr as Et,Ss as Dt,St as Ot,Ta as kt,To as At,Tr as jt,Tt as Mt,Uo as Nt,Ur as Pt,Ut as Ft,Va as It,Vn as Lt,Vr as Rt,Vt as zt,Wi as Bt,Ws as Vt,Wt as Ht,Xa as Ut,Xn as Wt,Xo as Gt,Xs as Kt,Yi as qt,Yn as Jt,Zn as Yt,Zo as Xt,Zr as Zt,_ as Qt,_i as $t,_s as en,_t as tn,aa as nn,ao as rn,at as an,b as on,bi as sn,bs as cn,bt as ln,cc as un,ci as dn,cn as fn,co as pn,cr as mn,dc as hn,di as gn,dn as _n,dr as vn,ei as yn,en as bn,eo as xn,er as Sn,es as Cn,fn as wn,fr as Tn,ga as En,gi as Dn,gn as On,go as kn,gt as An,ha as jn,hr as K,hs as Mn,ht as Nn,ia as Pn,ic as Fn,ii as In,io as Ln,is as Rn,it as zn,ja as q,jn as Bn,jr as Vn,js as Hn,ka as Un,ki as Wn,lc as J,li as Gn,ln as Kn,lr as qn,mt as Jn,na as Yn,ni as Xn,nn as Y,nr as Zn,ns as Qn,nt as $n,oi as er,on as tr,or as nr,pa as rr,pr as ir,qa as ar,qi as or,qn as sr,ra as cr,rc as lr,ri as ur,ro as dr,rt as fr,sa as pr,si as mr,sn as hr,so as gr,sr as _r,ss as vr,ta as yr,tn as br,tr as xr,ts as Sr,tt as Cr,ua as wr,un as Tr,uo as Er,ur as Dr,us as Or,v as kr,va as Ar,vi as jr,vr as Mr,vt as Nr,w as Pr,wa as Fr,ws as Ir,wt as Lr,xa as Rr,xs as zr,y as Br,yo as Vr,yr as Hr,yt as Ur,z as Wr,za as Gr,zn as Kr,zo as qr,zr as Jr,zt as Yr}from"./ui-components-BK0FqwOC.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-SqbPGFBI.js";import{t as ei}from"./AdapterProvider-BrKPQ1rE.js";import{n as ti,r as ni}from"./plugin-form-CM6RvRf2.js";import{a as ri,c as ii,l as ai,s as oi,t as si,u as ci}from"./MetadataProvider-Cvue7gQ0.js";import{n as li,r as ui,t as di}from"./ExpressionProvider-CqfGEBur.js";import{n as fi,o as pi,r as mi,t as hi}from"./RecentItemsProvider-gLV-GFpQ.js";import{i as gi,r as _i,t as vi}from"./useActionModal-DcFjU7Dq.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-CGxfnls1.js";import{n as Di,r as Oi,t as ki}from"./ui-layout-DM7b0Gu1.js";import{a as Ai,d as ji,f as Mi,i as Ni,t as Pi,u as Fi}from"./plugin-chatbot-CBg5Zd15.js";import{C as Ii,r as Li}from"./mergeServerFields-DKhjl-pc.js";import{n as Ri,t as zi}from"./appRoute-D5vwtoc_.js";import{a as Bi,c as Vi,i as Hi,l as Ui,n as Wi,o as Gi,r as Ki,s as qi}from"./metadata-admin-2GXysZST.js";import{a as Ji,n as Yi,o as Xi,r as Zi,s as Qi,t as $i}from"./utils-bipVuqQL.js";import{n as ea,r as ta,t as na}from"./MetadataInspector-BMHaVCoM.js";import{a as ra,i as ia,n as aa,r as oa}from"./runtime-config-BeHVOPm3.js";import{n as sa,r as ca}from"./InterfaceListPage-OHu23CRA.js";import{c as la}from"./plugins-views-BP1sk9hy.js";import{i as ua,r as da}from"./plugin-grid-BsA9XQ8Q.js";import{a as fa,c as pa,i as ma,l as ha,n as ga,o as _a,r as va,s as ya,t as ba,u as xa}from"./plugin-view-CmAdMV7R.js";import{n as Sa,r as Ca,t as wa}from"./RuntimeDraftBar-DroTFTnx.js";import{t as Ta}from"./ManagedByBadge-BodEaDXN.js";import"./resolveActionParams-CWIOgcoF.js";import{n as Ea}from"./PageView-H7j3JwJI.js";import"./RecordFormPage-B8sjq5K3.js";import"./DashboardView-HNhMjAZZ.js";import"./ReportView-_NBbKT5l.js";import"./SearchResultsPage-D9HdE2xf.js";import"./MarketplacePage-C5lziiq9.js";import"./MarketplacePackagePage-DnmqDFCq.js";import"./MarketplaceInstalledPage-B5oYOVdC.js";import{r as Da,t as Oa}from"./plugin-markdown--e1MOP0x.js";var Z=e(n(),1),ka=e(s(),1),Q=g(),Aa={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`}]}]},ja=()=>(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)(M,{schema:Aa})]}),Ma={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`}]}},Na={type:`element:repeater`,properties:{object:`showcase_category`,titleField:`name`,fields:[`color`],limit:10,emptyText:`No categories`}},Pa=()=>(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)(M,{schema:Ma})})]}),(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)(M,{schema:Na})})]})]});function Fa({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i,onConfirm:a,onToast:s}){let c=_(),{appName:l}=o(),{t:u}=V(),d=`/apps/${l}`,{execute:f,loading:p,error:m,runner:h}=P({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 Ia=(0,Z.createContext)({theme:`system`,setTheme:()=>null});function La({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)(Ia.Provider,{...r,value:o,children:e})}var Ra=()=>{let e=(0,Z.useContext)(Ia);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function za(){return(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function Ba({children:e}){return(0,Q.jsx)(La,{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)(za,{}),children:e})})})})})})}function Va({children:e}){return(0,Q.jsx)(ei,{children:(0,Q.jsx)(ii,{children:(0,Q.jsx)(Ha,{children:e})})})}function Ha({children:e}){let t=ce(),{language:n}=V(),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)(Ua,{}),e]},n)}):(0,Q.jsx)(za,{})}function Ua(){let{user:e}=x(),t=ce(),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 Wa({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:i}=x();return i?(0,Q.jsx)(za,{}):((n??[]).length>0||t)&&!t?(0,Q.jsx)(r,{to:`/organizations`,replace:!0}):(0,Q.jsx)(Q.Fragment,{children:e})}function Ga(){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 Ka=(0,Z.lazy)(()=>u(()=>import(`./ConsoleFloatingChatbot-CIsrrZv4.js`),__vite__mapDeps([0]),import.meta.url)),qa=()=>{u(()=>import(`./ConsoleFloatingChatbot-CIsrrZv4.js`),__vite__mapDeps([0]),import.meta.url)};function Ja(e){let[t,n]=(0,Z.useState)(!1),{t:r}=V(),{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)(Ka,{...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:qa,onFocus:qa,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 Ya(e){let t=Ii(),[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 Xa(){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 Za(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 Qa({open:e,onOpenChange:t}){let{t:n}=V(),[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 Xa();i(e);let t=[...new Set(e.map(e=>e.type))];await Promise.all(t.map(async e=>{let t=null;try{t=await Za(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)(ht,{open:e,onOpenChange:t,children:(0,Q.jsxs)(Me,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`draft-changes-panel`,children:[(0,Q.jsxs)(et,{children:[(0,Q.jsx)(Ct,{children:n(`preview.changes.title`,{defaultValue:`Pending changes`})}),(0,Q.jsx)(qe,{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)(Te,{className:`h-3.5 w-3.5 shrink-0 text-emerald-600`}):e.kind===`update`?(0,Q.jsx)(lt,{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 $a(){let e=ci(),t=l(),n=_(),{t:r}=V(),{publishAll:i,publishing:a}=Ya(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)(at,{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)(K,{size:`sm`,variant:`outline`,onClick:()=>s(!0),"data-testid":`draft-preview-changes`,children:[(0,Q.jsx)(gr,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.changes`,{defaultValue:`Changes`}),typeof c==`number`?` (${c})`:``]}),(0,Q.jsxs)(K,{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)(me,{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)(Qa,{open:o,onOpenChange:s}),(0,Q.jsxs)(K,{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 eo(){let e=ci(),{appName:t}=o(),n=l(),{apps:r,refresh:i}=I(),{t:a}=V(),[s,c]=(0,Z.useState)(!1);if(e)return null;let u=t??n.pathname.match(/\/apps\/([^/?#]+)/)?.[1];if(!u)return null;let d=Ri(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)(pt,{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)(K,{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)(me,{className:`mr-1 h-3.5 w-3.5`}),s?a(`preview.unpublishedBar.publishing`,{defaultValue:`Publishing…`}):a(`preview.unpublishedBar.publish`,{defaultValue:`Publish`})]})]})}var to=20;function no(e,t=``){let{href:n,external:r}=Di(e,t);return r?n:!n||n===`#`?``:n}function ro(e){return`nav:${e}`}function io(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=gi(),a=(0,Z.useCallback)((e,i,a,o)=>{let s=ro(e);i?(a&&t({id:s,label:a.label,href:no(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<to;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 ao=`__all__`;function oo(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function so(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 co(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=oo(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 lo(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=so(s),l=[],u=new Set;for(let e of c){if(!co(e,o))continue;let t=oo(e,i);if(t==null||typeof t!=`string`||u.has(t))continue;u.add(t);let n=oo(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 uo(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===ao?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)(fo,{def:e,value:c[e.id],onChange:t=>s(e,t),t:n},e.id))})}}function fo({def:e,value:t,onChange:n,t:r}){let i=lo(e),a=Ui(e.icon),o=Zi(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)(xe,{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)(Be,{value:e.value,children:e.label},e.value))})]})}var po=Z.forwardRef(({className:e,onClick:t,"aria-label":n,title:r,...i},a)=>{let{toggleSidebar:o}=De(),{t:s}=V(),c=String(n||r||s(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`}));return(0,Q.jsxs)(K,{ref:a,"data-sidebar":`trigger`,variant:`ghost`,size:`icon`,className:J(`h-7 w-7`,e),"aria-label":c,title:c,onClick:e=>{t?.(e),o()},...i,children:[(0,Q.jsx)(Yn,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:c})]})});po.displayName=`LocalizedSidebarTrigger`;function mo(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 ho(e){return e.componentRef===`metadata:directory`}function go(e){return e.componentRef===`developer:packages`}function _o(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 vo({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=De(),r=l(),{t:i}=V(),{objectLabel:a,dashboardLabel:o,navGroupLabel:s,viewLabel:c}=hn(),{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}=I(),S=v||[],C=S.filter(e=>e.active!==!1&&e.hidden!==!0),T=Ri(S.filter(e=>e.active!==!1),e||d)||C[0],{applyOrder:E,handleReorder:D}=mo(T?.name||`home`),{togglePin:O,applyPins:k}=io(),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:F}=uo(T?.name||`home`,T?.contextSelectors,i),ee=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]),te=u===`home`?ee:N,ne=u===`app`&&T?`/apps/${zi(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 te;let e=i(`sidebar.packageManagement`,{defaultValue:`Package management`}),t=n=>n.flatMap(n=>{if(ho(n))return[];let r=n.children?.length?t(n.children):n.children;return n.type===`group`&&r?.length===0?[]:go(n)?[{...n,type:`url`,label:e,url:`${ne}/component/developer/packages${R}`,children:r}]:r===n.children?[n]:[{...n,children:r}]});return t(te).flatMap(e=>_o(e)?e.children??[]:[e])},[T?.name,ne,u,te,R,i]),z=Z.useMemo(()=>k(E(re)),[re,E,k]),[ie,B]=Z.useState(!1),{evaluator:ae}=ui(),oe=Z.useCallback(e=>li(e,ae),[ae]),{can:se}=w(),ce=Z.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return se(n,r)}),[se]),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)(Jn,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&u===`app`&&(0,Q.jsx)(ln,{className:`border-b p-1.5`,children:(0,Q.jsx)(Ot,{children:(0,Q.jsx)(Mt,{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)(gt,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Q.jsx)(Nn,{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:[F&&(0,Q.jsx)(tn,{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)(Nr,{children:F})})}),L&&(0,Q.jsx)(tn,{children:(0,Q.jsx)(Nr,{children:(0,Q.jsx)(Ot,{children:(0,Q.jsx)(Mt,{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)(gt,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})})}),A.length>1&&(0,Q.jsxs)(tn,{children:[(0,Q.jsxs)(Ur,{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)(Nr,{children:(0,Q.jsx)(Ot,{children:A.map(e=>{let t=Ui(e.icon);return(0,Q.jsx)(Mt,{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:oe,checkPermission:ce,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)(tn,{children:[(0,Q.jsxs)(Ur,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>B(e=>!e),children:[(0,Q.jsx)(zr,{className:`h-3 w-3 transition-transform duration-150 ${ie?`rotate-90`:``}`}),(0,Q.jsx)(Qn,{className:`h-3.5 w-3.5`}),i(`sidebar.recent`,{defaultValue:`Recent`})]}),ie&&(0,Q.jsx)(Nr,{children:(0,Q.jsx)(Ot,{children:h.slice(0,5).map(e=>(0,Q.jsx)(Mt,{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)(tn,{children:[(0,Q.jsxs)(Ur,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(Xn,{className:`h-3.5 w-3.5`}),i(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Q.jsx)(Nr,{children:(0,Q.jsx)(Ot,{children:g.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Q.jsxs)(Mt,{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)(Ce,{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)(ur,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(tn,{children:(0,Q.jsx)(Nr,{children:(0,Q.jsx)(Ot,{children:ee.map(e=>{let t=Ui(e.icon),n=r.pathname===e.url;return(0,Q.jsx)(Mt,{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)(tn,{children:[(0,Q.jsxs)(Ur,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(Xn,{className:`h-3.5 w-3.5`}),i(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Q.jsx)(Nr,{children:(0,Q.jsx)(Ot,{children:g.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Q.jsxs)(Mt,{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)(Ce,{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)(ur,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Q.jsx)(An,{className:`border-t p-1`,children:(0,Q.jsx)(po,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function yo(){let{theme:e,setTheme:t}=Ra(),{t:n}=V();return(0,Q.jsxs)(hr,{children:[(0,Q.jsx)(On,{asChild:!0,children:(0,Q.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(fe,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Q.jsx)(jn,{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)(fn,{align:`end`,children:[(0,Q.jsxs)(Tr,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Q.jsx)(fe,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(Tr,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Q.jsx)(jn,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(Tr,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Q.jsx)(En,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}var bo=[{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 xo(){let{t:e,language:t,changeLanguage:n}=V();return(0,Q.jsxs)(hr,{children:[(0,Q.jsx)(On,{asChild:!0,children:(0,Q.jsxs)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(rn,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Q.jsx)(fn,{align:`end`,className:`max-h-72 overflow-y-auto`,children:bo.map(e=>(0,Q.jsxs)(Tr,{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 So={connected:{labelKey:`topbar.connection.connected`,defaultValue:`Connected`,color:`text-green-500`,icon:Mn},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:jt},error:{labelKey:`topbar.connection.error`,defaultValue:`Connection Error`,color:`text-destructive`,icon:jt}};function Co({state:e,className:t}){let n=So[e],{t:r}=V(),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:J(`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:J(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:i})]})}function wo(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 To({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:a}){let{t:s}=V(),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)(pe,{open:d,onOpenChange:f,children:[(0,Q.jsx)(br,{asChild:!0,children:(0,Q.jsxs)(K,{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)(Xe,{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)(bn,{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)($n,{value:p,onValueChange:e=>m(e),className:`w-full`,children:[(0,Q.jsxs)(zn,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Q.jsxs)(an,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(Xe,{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)(an,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(mr,{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)(an,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(un,{className:`h-3.5 w-3.5`}),s(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Q.jsxs)(fr,{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:wo(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)(fr,{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)(mr,{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)(K,{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)(fr,{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:[wo(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 Eo({activeAppName:e,onAppChange:t}){let{apps:n}=I(),{t:r}=V(),{appLabel:i}=hn(),a=n||[],o=a.filter(e=>e.active!==!1&&e.hidden!==!0),s=Ri(o,e)||Ri(a.filter(e=>e.active!==!1),e)||o[0];return s?(0,Q.jsxs)(hr,{children:[(0,Q.jsx)(On,{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:Zi(s.label,r)})}),(0,Q.jsx)(Se,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Q.jsxs)(fn,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Q.jsx)(_n,{className:`text-xs text-muted-foreground font-normal`,children:r(`layout.appSwitcher.switchApplication`,{defaultValue:`Switch Application`})}),(0,Q.jsx)(wn,{}),o.map(e=>{let n=Ui(e.icon),a=i({name:e.name,label:Zi(e.label,r)}),o=s.name===e.name;return(0,Q.jsxs)(Tr,{onClick:()=>t(zi(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)(Ir,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var Do=(0,Z.createContext)(null);function Oo({children:e}){let[t,n]=(0,Z.useState)(null),r=(0,Z.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Q.jsx)(Do.Provider,{value:r,children:e})}function ko(){return(0,Z.useContext)(Do)?.value??null}function Ao(e){let t=(0,Z.useContext)(Do),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 jo(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),[]);Ao((0,Z.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}function Mo(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function No(){return(0,Q.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var Po=[];function Fo({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=ce(),{t:D}=V(),{objectLabel:O,dashboardLabel:k,pageLabel:A,reportLabel:j,viewLabel:M,appLabel:N}=hn(),{apps:P,dashboards:F,pages:ee,reports:te}=I(),{currentAppName:ne,recordTitle:L}=Si(),R=ko(),[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,oe]=(0,Z.useState)(null),[se,le]=(0,Z.useState)([]),ue=(0,Z.useRef)(!1),de=(0,Z.useRef)(!1),fe=(0,Z.useRef)(!0);(0,Z.useEffect)(()=>(fe.current=!0,()=>{fe.current=!1}),[]);let H=(0,Z.useRef)(!1),pe=(0,Z.useRef)(!1),me=(0,Z.useRef)(!1),[he,ge]=(0,Z.useState)(0),_e=(0,Z.useRef)(!1),ve=(0,Z.useCallback)(async()=>{if(!E||!d)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!ue.current&&!me.current){me.current=!0;try{let t=await E.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(ue.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`);e.length&&oe(e)}}catch{}finally{me.current=!1}}},[E,d]);(0,Z.useEffect)(()=>{ve()},[ve]),(0,Z.useEffect)(()=>{if(!E||!d||!v?.id||de.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(!H.current){H.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(!fe.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)})}le(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)){de.current=!0;return}r=Math.min(r*2,12e4)}finally{H.current=!1}}},s=()=>{if(e||de.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||_e.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&&!pe.current){pe.current=!0;try{let n=new URLSearchParams({status:`pending`,approverId:t.join(`,`)}),r=await fetch(`${e}?${n}`,{credentials:`include`});if(r.status===404){_e.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);fe.current&&ge(a.size)}catch{}finally{pe.current=!1}}},a=()=>{n||_e.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[d,v?.id]);let ye=se.reduce((e,t)=>e+ +!t.is_read,0),xe=(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]),Ce=(0,Z.useCallback)(async e=>{let t=se.find(t=>t.id===e);if(le(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),t)try{await xe(t,new Date().toISOString())}catch{}},[se,xe]),we=(0,Z.useCallback)(async()=>{let e=se.filter(e=>!e.is_read);if(!e.length)return;le(e=>e.map(e=>({...e,is_read:!0})));let t=new Date().toISOString();await Promise.all(e.map(e=>xe(e,t).catch(()=>{})))},[se,xe]),Te=xi(),Ee=i??(Te.length>0?Te:Po),De=a??ae??[],Oe=w||(S??[]).length>0||!!C,W=f.pathname.split(`/`).filter(Boolean),G=p.appName||W[1],ke=W[2],je=`/apps/${G}`,Me=n??[],Ne=Ri(P||[],s||ne||G),Pe=new Set,Fe=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&Pe.add(t.objectName),t.children&&Fe(t.children)};Fe(Ne?.navigation||[]);for(let e of Ne?.areas||[])Fe(e.navigation||[]);let Ie=Pe.size>0?Me.filter(e=>Pe.has(e.name)):Me.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`)),Le=Ne?._packageId,Re=Le?(re??[]).filter(e=>e._packageId===Le):[],Be=Ie.map(e=>({label:O(e),href:`${je}/${e.name}`})),Ve=[];if(d){if(ke===`dashboard`){if(Ve.push({label:D(`console.breadcrumb.dashboards`),href:je}),W[3]){let e=W[3],t=ta(F,e,Ne?._packageId)?.label||Mo(e);Ve.push({label:k({name:e,label:t})})}}else if(ke===`page`){if(Ve.push({label:D(`console.breadcrumb.pages`),href:je}),W[3]){let e=W[3],t=ta(ee,e,Ne?._packageId)?.label||Mo(e);Ve.push({label:A({name:e,label:t})})}}else if(ke===`report`){if(Ve.push({label:D(`console.breadcrumb.reports`),href:je}),W[3]){let e=W[3],t=ta(te,e,Ne?._packageId)?.label||Mo(e);Ve.push({label:j({name:e,label:t})})}}else if(ke===`system`)Ve.push({label:D(`console.breadcrumb.system`)}),W[3]&&Ve.push({label:Mo(W[3])});else if(ke){let e=Me.find(e=>e.name===ke);if(e){if(Ve.push({label:O(e),href:`${je}/${ke}`,siblings:Be}),W[3]===`record`&&W[4]){let e=W[4].length>12?`${W[4].slice(0,8)}…`:W[4],t=L?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;Ve.push({label:n||`#${e}`})}else if(W[3]===`view`&&W[4]){let t=W[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||Mo(t),i=M(e.name,t,r);Ve.push({label:i})}}}}let He=Ve[Ve.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:J(`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:aa(),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:aa()}),u===`orgs`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(No,{}),(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)(po,{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)(No,{})}),(0,Q.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(Eo,{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)(No,{})}),(0,Q.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,Ve.map((e,t)=>{let n=t===Ve.length-1;return(0,Q.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,Q.jsx)(No,{}),e.siblings&&e.siblings.length>1?(0,Q.jsxs)(hr,{children:[(0,Q.jsxs)(On,{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)(Se,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Q.jsxs)(fn,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Q.jsx)(_n,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,Q.jsx)(wn,{}),e.siblings.map(e=>(0,Q.jsx)(Tr,{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)(hr,{children:[(0,Q.jsx)(On,{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??He}),(0,Q.jsx)(Se,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Q.jsx)(fn,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:R.views.map(e=>{let t=e.id===R.activeViewId;return(0,Q.jsxs)(Tr,{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)(U,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Q.jsx)(Ir,{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:He})]})]}),(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)(Co,{state:r}),d&&Ee.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:Ee,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)(wt,{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)(K,{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)(wt,{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)(To,{notifications:se,unreadCount:ye,pendingApprovalsCount:he,activities:De,onMarkAllRead:we,onMarkRead:Ce}),(0,Q.jsx)(K,{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)(ze,{className:`h-4 w-4`})})}),(0,Q.jsxs)(hr,{onOpenChange:e=>{e&&B()},children:[(0,Q.jsx)(On,{asChild:!0,children:(0,Q.jsx)(K,{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)(Or,{className:`h-4 w-4`})})}),(0,Q.jsxs)(fn,{align:`end`,className:`min-w-56 rounded-lg`,sideOffset:4,children:[Re.length>0&&Le?(0,Q.jsxs)(Tr,{className:`cursor-pointer`,onClick:()=>h(Re.length===1?`/apps/${Le}/docs/${Re[0].name}`:`/apps/${Le}/docs`),children:[(0,Q.jsx)(Vt,{className:`mr-2 h-4 w-4`}),D(`help.appDocs`,{defaultValue:`This app's docs`})]}):null,(0,Q.jsxs)(Tr,{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)(wn,{}),(0,Q.jsx)(Tr,{asChild:!0,className:`cursor-pointer`,children:(0,Q.jsxs)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,Q.jsx)(Ae,{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)(hr,{children:[(0,Q.jsx)(On,{asChild:!0,children:(0,Q.jsx)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,Q.jsxs)(Sn,{className:`h-7 w-7 rounded-full`,children:[(0,Q.jsx)(Zn,{src:v?.image,alt:v?.name??`User`}),(0,Q.jsx)(xr,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:T(v)})]})})}),(0,Q.jsxs)(fn,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Q.jsx)(_n,{className:`p-0 font-normal`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,Q.jsxs)(Sn,{className:`h-8 w-8 rounded-lg`,children:[(0,Q.jsx)(Zn,{src:v?.image,alt:v?.name??`User`}),(0,Q.jsx)(xr,{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)(wn,{}),(0,Q.jsxs)(Kn,{children:[(0,Q.jsxs)(Tr,{onClick:()=>h(`/apps/account/component/account/profile_card`),className:`cursor-pointer`,children:[(0,Q.jsx)(Vn,{className:`mr-2 h-4 w-4`}),D(`user.profile`,{defaultValue:`Profile`})]}),Oe&&(0,Q.jsxs)(Tr,{onClick:()=>h(`/organizations`),className:`cursor-pointer`,children:[(0,Q.jsx)(be,{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=Ui(e.icon),n=N({name:e.name,label:Zi(e.label,D)});return(0,Q.jsxs)(Tr,{onClick:()=>h(`/apps/${zi(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)(wn,{}),(0,Q.jsx)(_n,{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)(yo,{})]}),(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)(xo,{})]}),b&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(wn,{}),(0,Q.jsxs)(Tr,{className:`text-destructive focus:text-destructive`,onClick:()=>y(),children:[(0,Q.jsx)(Un,{className:`mr-2 h-4 w-4`}),D(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var Io=768,Lo=1024;function Ro(){let{setOpen:e,isMobile:t}=De(),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>=Io&&t<Lo;r&&!e&&n.current(!1),e=r}return r(),window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r)},[t])}function zo({children:e}){return Ro(),(0,Q.jsx)(Q.Fragment,{children:e})}function Bo({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=Zi(n?.label)||t,{isAiEnabled:c}=F(),l=c||!1,u=ia().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)(Oo,{children:(0,Q.jsxs)(Oi,{sidebar:(0,Q.jsx)(vo,{activeAppName:t,onAppChange:r}),navbar:(0,Q.jsx)(Fo,{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?`${Zi(n.label)} — ${aa()}`:void 0}:void 0,children:[(0,Q.jsxs)(zo,{children:[(0,Q.jsx)($a,{}),(0,Q.jsx)(eo,{}),e]}),l&&(0,Q.jsx)(Ja,{appLabel:s,appName:t,defaultAgent:u,objects:i,userId:o})]})})}function Vo({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:J(`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:J(`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 Ho({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}=Ra(),{evaluator:p}=ui(),{t:m}=V();(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||zi(t)}`,{user:g}=x(),v=(0,Z.useMemo)(()=>({currentUserId:g?.id??null}),[g?.id]),y=(0,Z.useCallback)(e=>{s(!1),e()},[]),b=Uo(t?.navigation||[]).filter(e=>li(e.visible??e.visibleOn,p)),{results:S,isSearching:C}=re({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:Yi}),{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)(he,{open:a,onOpenChange:s,children:[(0,Q.jsx)(it,{placeholder:m(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,Q.jsxs)(ke,{children:[(0,Q.jsx)(Bn,{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)(tt,{heading:m(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:T.map(e=>(0,Q.jsxs)(ft,{value:`recent ${e.label} ${e.id}`,onSelect:()=>y(()=>u(e.href)),children:[(0,Q.jsx)(wt,{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)(tt,{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=Ui(e.icon);return(0,Q.jsxs)(ft,{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)(tt,{heading:m(`console.commandPalette.objects`),children:b.filter(e=>e.type===`object`).map(e=>{let t=Ui(e.icon);return(0,Q.jsxs)(ft,{value:`object ${Zi(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:Zi(e.label,m)})]},e.id)})}),b.filter(e=>e.type===`dashboard`).length>0&&(0,Q.jsx)(tt,{heading:m(`console.commandPalette.dashboards`),children:b.filter(e=>e.type===`dashboard`).map(e=>(0,Q.jsxs)(ft,{value:`dashboard ${Zi(e.label,m)} ${e.dashboardName}`,onSelect:()=>y(()=>u(Di(e,h,v).href)),children:[(0,Q.jsx)(ve,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Zi(e.label,m)})]},e.id))}),b.filter(e=>e.type===`page`).length>0&&(0,Q.jsx)(tt,{heading:m(`console.commandPalette.pages`),children:b.filter(e=>e.type===`page`).map(e=>(0,Q.jsxs)(ft,{value:`page ${Zi(e.label,m)} ${e.pageName}`,onSelect:()=>y(()=>u(Di(e,h,v).href)),children:[(0,Q.jsx)(Tt,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Zi(e.label,m)})]},e.id))}),b.filter(e=>e.type===`report`).length>0&&(0,Q.jsx)(tt,{heading:m(`console.commandPalette.reports`),children:b.filter(e=>e.type===`report`).map(e=>(0,Q.jsxs)(ft,{value:`report ${Zi(e.label,m)} ${e.reportName}`,onSelect:()=>y(()=>u(Di(e,h,v).href)),children:[(0,Q.jsx)(Hn,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Zi(e.label,m)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(We,{}),(0,Q.jsx)(tt,{heading:m(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=Ui(e.icon);return(0,Q.jsxs)(ft,{value:`app ${Zi(e.label,m)} ${e.name}`,onSelect:()=>y(()=>r(zi(e)??e.name)),children:[(0,Q.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Zi(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)(We,{}),(0,Q.jsxs)(tt,{heading:m(`console.commandPalette.preferences`),children:[(0,Q.jsxs)(ft,{value:`theme light`,onSelect:()=>y(()=>f(`light`)),children:[(0,Q.jsx)(fe,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.lightTheme`)})]}),(0,Q.jsxs)(ft,{value:`theme dark`,onSelect:()=>y(()=>f(`dark`)),children:[(0,Q.jsx)(jn,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.darkTheme`)})]}),(0,Q.jsxs)(ft,{value:`theme system`,onSelect:()=>y(()=>f(`system`)),children:[(0,Q.jsx)(En,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.systemTheme`)})]})]}),(0,Q.jsx)(We,{}),(0,Q.jsx)(tt,{heading:m(`console.commandPalette.actions`),children:(0,Q.jsxs)(ft,{value:`search all results full page`,onSelect:()=>y(()=>u(`${h}/search`)),children:[(0,Q.jsx)(wt,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:m(`console.commandPalette.openFullSearch`)})]})})]})]})}function Uo(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Uo(n.children)):t.push(n);return t}function Wo(){let{t:e}=V(),[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)(Qe,{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)(Le,{children:e(`console.shortcuts.title`)}),(0,Q.jsx)(Kr,{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 Go(){return null}function Ko(){return typeof document<`u`&&document.documentElement.lang?.startsWith(`zh`)||typeof navigator<`u`&&navigator.language?.startsWith(`zh`)?L.console:oe.console}function qo({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,Z.useState)(0),o=Ko(),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)(Nt,{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:aa()}),(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)(en,{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)(K,{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)(dt,{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)(Mn,{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 Jo(e){let{theme:t=`system`}=Ra(),{t:n}=V();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)(Mn,{className:`h-4 w-4`}),info:(0,Q.jsx)(ar,{className:`h-4 w-4`}),warning:(0,Q.jsx)(St,{className:`h-4 w-4`}),error:(0,Q.jsx)(wr,{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 Yo=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function Xo({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(...Yo),e.offsetWidth,e.classList.add(...Yo))},[n.pathname]),(0,Q.jsx)(`div`,{ref:r,className:[...Yo,t??``].filter(Boolean).join(` `),children:e})}var Zo=null,Qo=null;function $o(){return Qo||(Qo=(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-Cv_7Tgs6.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=ts(e.data.url)),e}}),Zo=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),Qo)}function es(e,t){if(Zo)try{Zo.captureException(e,t?{extra:t}:void 0)}catch{}}function ts(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 ns({error:e,onReset:t}){let{t:n}=V();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)(Fe,{children:n(`console.errors.somethingWentWrong`)}),(0,Q.jsx)(Wr,{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)(K,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,Q.jsx)(Wn,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,Q.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,Q.jsx)(gt,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var rs=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),es(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)(ns,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}},is=new Set([`form`,`detail`]);function as(e){return typeof e==`string`&&is.has(e)}function os(e,t){let n=e.type||`grid`,r=as(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 ss(e){let t=e.config??{},n={...t};return delete n.data,{...n,id:e.name,label:e.label??t.label}}function cs(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 ls({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s,metadataClient:c,onAfterChange:l}){let{t:u}=V(),d=(0,Z.useRef)(null),f=(0,Z.useMemo)(()=>Li(),[]),[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)(()=>os(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)(()=>cs(i),[i.fields]),T=Vi(g.viewKind)?`form`:`list`,E=(0,Z.useCallback)(e=>{let t={...S.current,...e};if(S.current=t,_(t),y(!0),a){let e=ss(t);for(let[t,n]of Object.entries(e))t!==`id`&&a(t,n)}},[a]),D=(0,Z.useCallback)(()=>{let e=ss(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=os(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)(qi,{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)(wa,{type:`view`,name:r.id,metadataClient:c,dirty:v,onResume:k,savedSignal:b,onAfterChange:l}),(0,Q.jsx)(K,{variant:`ghost`,size:`sm`,onClick:O,"data-testid":`view-config-discard`,children:u(`console.objectView.discard`)}),(0,Q.jsx)(K,{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 us(e){return[{type:`grid`,icon:Gr,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:er,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:ot,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:Qn,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:dn,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:kt,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:Hn,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)}]}function ds(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var fs={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:ga}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:va},{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:va},{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:va},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:ba},{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=>_a(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&fa(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&fa(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:ga},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}]};function ps({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=V(),s=(0,Z.useMemo)(()=>us(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?ma(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(ds(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=fs[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=(fs[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=ya(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)(Qe,{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)(Le,{children:o(`console.objectView.createView`)}),(0,Q.jsx)(Kr,{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:J(`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:J(`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:J(`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)(en,{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)(ye,{className:`mt-2`,children:[(0,Q.jsx)(K,{type:`button`,variant:`outline`,onClick:()=>t(!1),"data-testid":`create-view-cancel`,children:o(`console.objectView.cancel`)}),(0,Q.jsx)(K,{type:`button`,disabled:!D,onClick:O,"data-testid":`create-view-submit`,children:o(`console.objectView.create`)})]})]})})}function ms(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 hs=(0,Z.lazy)(()=>u(()=>import(`./plugin-charts-Ck5EMx6H.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),gs=(0,Z.lazy)(()=>u(()=>import(`./plugin-grid-BsA9XQ8Q.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),_s={grid:Zt,kanban:er,calendar:ot,gallery:Gr,timeline:un,gantt:Ee,map:Oe,chart:Hn},vs={id:`current-user`,name:`Demo User`};function ys(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 bs({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let{objectName:i}=o(),{t:a}=V();return t.find(e=>e.name===i)?(0,Q.jsx)(xs,{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)(Zt,{className:`h-6 w-6 text-muted-foreground`})}),(0,Q.jsx)(Fe,{children:a(`console.objectView.objectNotFound`)}),(0,Q.jsxs)(Wr,{children:[a(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,a(`console.objectView.objectNotFoundHint`)]})]})})}function xs({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let i=_(),{appName:a,objectName:s,viewId:c}=o(),[u,d]=p(),f=l(),{showDebug:m}=ea(),{t:h}=V(),{objectLabel:g,objectDescription:v,viewLabel:y,viewEmptyState:b,actionLabel:S,actionConfirm:C,actionSuccess:T,actionParamText:E,fieldLabel:D,fieldOptionLabel:O}=hn(),{isFavorite:k,toggleFavorite:A}=gi(),j=Ii(),[P,F]=(0,Z.useState)(!1),[I,te]=(0,Z.useState)(`edit`),[ne,L]=(0,Z.useState)(!1),[R,re]=(0,Z.useState)(!1),[z,ie]=(0,Z.useState)(null),B=(0,Z.useRef)({}),ae=(0,Z.useRef)({}),oe=(0,Z.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!s||!t)return;let i=ae.current[t]||{};ae.current[t]={...i,...r};let a=B.current[t];a&&clearTimeout(a),B.current[t]=setTimeout(()=>{let r=ae.current[t]||{};delete ae.current[t],delete B.current[t],Promise.resolve(e.updateViewConfig(s,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,s]),se=(0,Z.useCallback)(e=>{ie(e),he(e=>e+1);let t=e.id;j&&t?Ca(`view`,t,e,{metadataClient:j}).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing metadataClient or viewId.`)},[j]),ce=(0,Z.useCallback)(async e=>{try{let n;if(j){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 Sa(`view`,String(e?.name??e?.id??c?.id??``),c,{metadataClient:j})}F(!1),te(`edit`),he(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,j]),[le,ue]=(0,Z.useState)(void 0),{user:de,activeOrganization:fe}=x(),H=de?.role===`admin`,{can:pe}=w(),U=t.find(e=>e.name===s),[me,he]=(0,Z.useState)(0),ge=Ea({dataSource:e,objects:t,objectName:U.name,onRefresh:()=>he(e=>e+1)}),{confirmHandler:_e,toastHandler:ve}=ge,ye=(0,Z.useMemo)(()=>wi(U),[U]);(0,Z.useEffect)(()=>{r===void 0||r===0||he(e=>e+1)},[r]);let[be,xe]=(0,Z.useState)(!1),[Se,Ce]=(0,Z.useState)([]);(0,Z.useEffect)(()=>{let t=!1;if(!s){Ce([]);return}return typeof e?.listViews==`function`?(e.listViews(s).then(e=>{t||Ce((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||Ce([])}),()=>{t=!0}):(Ce([]),()=>{t=!0})},[e,s,me]);let[we,Te]=(0,Z.useState)({});(0,Z.useEffect)(()=>{let t=!1;if(!e||!s){Te({});return}let n=U.listViews||U.list_views||{},r=Object.keys(n),i=U.list;if(i&&typeof i==`object`){let e=i.name||`list`;r.includes(e)||r.unshift(e)}if(r.length===0){Te({});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||Te(e)}),()=>{t=!0}},[e,s,U.listViews,U.list_views,U.list,me]);let Ee=(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(U.compactLayout)&&U.compactLayout.length>0?U.compactLayout.filter(e=>U.fields?.[e]):U.fields?Object.entries(U.fields).filter(([t,n])=>!(!n||n.hidden||e.has(t))).map(([e])=>e).slice(0,5):[],n=U.listViews||U.list_views||{},r=Object.entries(n).map(([e,t])=>{let n=we[e];return{id:e,...t,...n||{},type:n?.type||t.type||`grid`}}),i=U.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=we[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 Se){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:${U.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=Se.find(t=>(t.id||t._id)===e.id),a=Se.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},[U,Se,we,h]),De=(0,Z.useMemo)(()=>Ee.find(e=>e.isDefault)?.id,[Ee]),Oe=c||u.get(`view`)||De||Ee[0]?.id,W=Ee.find(e=>e.id===Oe)||Ee[0],G=z&&z.id===W?.id?{...W,...z}:W,ke=(0,Z.useCallback)((e,t)=>{ie(n=>({...n||{},id:W?.id,[e]:t}))},[W?.id]),Ae=e=>{let t=Ee.find(t=>t.id===e);t&&(t.id!==Oe&&F(!1),c?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},je=(0,Z.useMemo)(()=>(Ee||[]).map(e=>{let t=_s[e.type];return{id:e.id,label:y(U.name,e.name||e.id,e.label||e.name||e.id),icon:t?(0,Q.jsx)(t,{className:`h-4 w-4`}):void 0}}),[Ee,U.name,y]);jo({views:je,activeViewId:Oe??``,onChange:Ae,enabled:je.length>0&&!!Oe});let Me=(0,Z.useCallback)(()=>{L(!0)},[]),Ne=(0,Z.useCallback)((e,t)=>{if(e===`settings`){let e=Ee.find(e=>e.type===t);e&&Ae(e.id),te(`edit`),F(!0)}},[Ee,Ae]),Pe=(0,Z.useCallback)(e=>Se.some(t=>(t.id||t._id)===e),[Se]),Fe=(0,Z.useCallback)(async(t,n)=>{if(!Pe(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}),he(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),X.error(h(`objectViewActions.renameFailed`))}},[e,s,Pe,h]),Le=(0,Z.useCallback)(async t=>{if(!e)return;if(!Pe(t)){X.error(h(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=Ee.find(e=>e.id===t)?.label||t;if(await _e(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===Oe){let e=Ee.find(e=>e.id!==t);e&&i(c?`../${e.id}`:`view/${e.id}`,c?{relative:`path`}:void 0)}he(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),X.error(h(`objectViewActions.deleteFailed`))}},[e,Pe,Oe,Ee,c,i,h,_e]),Re=(0,Z.useCallback)(async(t,n)=>{if(e){if(!Pe(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}),he(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,s,Pe,h]),ze=(0,Z.useCallback)(async t=>{if(e){if(!Pe(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=Se.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),he(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),X.error(`Failed to set default view`)}}},[e,s,Se,Pe,h]),Be=(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(Se.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)}}he(e=>e+1)},[e,Se,s]),He=(0,Z.useCallback)(e=>{if(!Pe(e)){X.error(h(`console.objectView.cannotEditMetaView`)||`System view — it cannot be edited.`);return}e!==Oe&&Ae(e),te(`edit`),F(!0)},[Oe,Ae,Pe,h]),Ue=(0,Z.useCallback)(()=>{L(!0)},[]),We=de?{id:de.id,name:de.name,avatar:de.image}:vs,Ge=Fa({objectName:U.name,objectLabel:U.label,dataSource:e,onEdit:n,onRefresh:()=>he(e=>e+1),onConfirm:_e,onToast:ve}),{lastMessage:Ke}=Ti({channel:`object:${U.name}`}),{hasConflicts:qe,resolveAllConflicts:Je}=Ci(U.name?`user-${U.name}`:`current-user`);(0,Z.useEffect)(()=>{Ke&&(qe&&Je(`remote`),he(e=>e+1))},[Ke,qe,Je]),(0,Z.useEffect)(()=>{e?.find&&U.name&&e.find(U.name,{limit:0}).then(e=>{typeof e?.total==`number`?ue(e.total):Array.isArray(e?.data)?ue(e.data.length):Array.isArray(e)&&ue(e.length)}).catch(()=>{})},[e,U.name,me]);let Ye=(0,Z.useMemo)(()=>G?.navigation??U.navigation??{mode:`drawer`,width:`min(92vw, 1280px)`},[G?.navigation,U.navigation]),Xe=u.get(`recordId`),Ze=Array.from(u.entries()).filter(([e])=>e.startsWith(`filter[`)).map(([e,t])=>`${e}=${t}`).join(`&`),Qe=(0,Z.useMemo)(()=>{let e=[];return new URLSearchParams(Ze).forEach((t,n)=>{let r=/^filter\[(.+)\]$/.exec(n);r&&r[1]&&t!==``&&e.push([r[1],`=`,t])}),e},[Ze]),[$e]=(0,Z.useState)(()=>ca(new URLSearchParams(window.location.search))),et=(0,Z.useCallback)(e=>{d(t=>sa(t,e),{replace:!0})},[d]),tt=(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(U.name,G?.name??``,G?.label??``)||g(U)}};c?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):i(`record/${encodeURIComponent(String(e))}`,{state:n})},[i,c,f.pathname,f.search,U,G?.name,G?.label,y,g]),nt=N({navigation:Ye,objectName:U.name,onNavigate:tt}),rt=()=>{nt.close();let e=new URLSearchParams(u);e.delete(`recordId`),d(e)},it=(0,Z.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){nt.handleClick(e,t);return}if(nt.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(u);e.set(`recordId`,String(t)),d(e);return}}nt.handleClick(e,t)},[nt,u,d]),at=(0,Z.useCallback)(()=>{let e=nt.selectedRecord,t=e&&(e.id??e._id);t!=null&&(rt(),tt(t))},[nt.selectedRecord,tt]);(0,Z.useEffect)(()=>{Xe&&!nt.isOpen?nt.open({id:Xe}):!Xe&&nt.isOpen&&nt.close()},[Xe]);let ot=(0,Z.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=me+(i||0),o=`${s}-${G.id}-${a}`,c=G;if(c.type===`chart`){let e=c.chart||{},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)(hs,{dataSource:t,schema:{type:`object-chart`,objectName:U.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)(la,{schema:{...e,rowHeight:c.rowHeight??e.rowHeight,densityMode:c.densityMode??e.densityMode,sort:c.sort??e.sort,filter:(()=>{let t=ys(c.filter??e.filter,We.id);return Qe.length?[...Array.isArray(t)?t:[],...Qe]:t})(),hiddenFields:c.hiddenFields??e.hiddenFields,columnState:c.columnState??e.columnState,onDensityChange:e=>{oe(c.id,c,{densityMode:e})},onSortChange:e=>{oe(c.id,c,{sort:e})},onFilterChange:e=>{oe(c.id,c,{filter:e})},onHiddenFieldsChange:e=>{oe(c.id,c,{hiddenFields:e})},onColumnStateChange:e=>{oe(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(U?.actions)?U.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)).map(e=>({...e,label:S(U.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:C(U.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:T(U.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(U.name,c.name||c.id||``,c.emptyState??e.emptyState??ms(U?.managedBy,h)),aria:c.aria??e.aria,tabs:c.tabs??e.tabs,...(()=>{let e=ys([...Array.isArray(c.filter)?c.filter:[],...Qe],We.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||U.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||U.titleField||`name`,descriptionField:c.timeline?.descriptionField},map:{locationField:c.map?.locationField,titleField:c.map?.titleField||U.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||U.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&&Ge.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&Ge.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)=>{it(e,t)},onSortChange:e=>{oe(c.id,c,{sort:e})},onFilterChange:e=>{oe(c.id,c,{filter:e})},onHiddenFieldsChange:e=>{oe(c.id,c,{hiddenFields:e})},onColumnStateChange:e=>{oe(c.id,c,{columnState:e})},userFilterSelections:$e,onUserFilterSelectionsChange:et,dataSource:t},o)},[G,U,s,me,nt,Ge,oe,Qe,$e,et]),st=(0,Z.useMemo)(()=>Ee.map(e=>e.id===Oe&&z&&z.id===e.id?{...e,...z}:e),[Ee,Oe,z]),ct=(0,Z.useMemo)(()=>({type:`object-view`,objectName:U.name,layout:`page`,showSearch:G?.showSearch!==!1,showFilters:G?.showFilters!==!1,showSort:G?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:H,viewActions:H?[{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(U.name,G?.name??``,G?.label??``)||g(U)}};c?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[U,n,G?.showSearch,G?.showFilters,G?.showSort,G?.name,G?.label,i,c,H,f.pathname,f.search,y,g]);return(0,Q.jsxs)(ee,{...ge.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)(Vo,{title:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:g(U)}),(0,Q.jsx)(Ta,{managedBy:U?.managedBy})]}),description:U.description?v(U):void 0,icon:(0,Q.jsx)(Ui(U?.icon),{className:`h-4 w-4`}),actions:(0,Q.jsxs)(Q.Fragment,{children:[s&&(0,Q.jsx)(K,{size:`sm`,variant:`ghost`,onClick:()=>A({id:`object:${s}`,label:g(U),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)(Xn,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Q.jsx)(ur,{className:`h-4 w-4`})}),ye.create&&pe(U.name,`create`)&&(0,Q.jsxs)(K,{size:`sm`,onClick:Ge.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Q.jsx)(Ie,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.new`)})]}),ye.import&&pe(U.name,`create`)&&(0,Q.jsxs)(K,{size:`sm`,variant:`outline`,onClick:()=>xe(!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)(mt,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.import`)})]}),U.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(0,Q.jsx)(M,{schema:{type:`action:bar`,location:`list_toolbar`,actions:(U.actions||[]).map(e=>({...e,label:S(U.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:C(U.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:T(U.name,e.name,e.successMessage)}})),size:`sm`,variant:`outline`,mobileMaxVisible:0}})]})})}),ye.create&&pe(U.name,`create`)&&(0,Q.jsx)(`button`,{type:`button`,onClick:Ge.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)(Ie,{className:`h-5 w-5`})}),be&&(0,Q.jsx)(Z.Suspense,{fallback:null,children:(0,Q.jsx)(gs,{open:be,onOpenChange:xe,objectName:U.name,objectLabel:g(U),fields:Object.entries(U.fields||{}).map(([e,t])=>({name:e,label:t?.label||e,type:t?.type||`text`,required:!!t?.required})),dataSource:e,onComplete:e=>{he(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}))}})}),Ee.length>=1&&(()=>{let e=Ee.map(e=>{let t=Se.find(t=>(t.id||t._id)===e.id),n=!t;return{id:e.id,label:y(U.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)(ha,{views:e,activeViewId:Oe,onViewChange:Ae,viewTypeIcons:_s,config:{reorderable:!1,showAddButton:H,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:H?Ue:void 0,onRenameView:H?Fe:void 0,onDeleteView:H?Le:void 0,onPinView:H?Re:void 0,onSetDefaultView:H?ze:void 0,onConfigView:H?He:void 0,onManageViews:H?()=>re(!0):void 0}),H&&(0,Q.jsx)(pa,{open:R,onOpenChange:re,views:e,activeViewId:Oe,viewTypeIcons:_s,onRename:Fe,onDelete:Le,onSetDefault:ze,onSetPinned:Re,onReorder:Be,onAddView:Ue,onConfigView:He})]})})})(),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[nt.mode===`split`&&nt.isOpen?(0,Q.jsx)(Ve,{...nt,setIsOpen:e=>{e||rt()},title:g(U),onExpand:at,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${U.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)(xa,{schema:ct,dataSource:e,views:st,activeViewId:Oe,onViewChange:Ae,onEdit:e=>n?.(e),onRowClick:(e,t)=>{it(e,t)},renderListView:ot,onCreateView:Me,onViewAction:Ne})})}),typeof le==`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:le})})]}),children:r=>{let i=r.id||r._id;return(0,Q.jsx)(Ei,{dataSource:e,objects:t,onEdit:n,objectNameOverride:U.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)(xa,{schema:ct,dataSource:e,views:st,activeViewId:Oe,onViewChange:Ae,onEdit:e=>n?.(e),onRowClick:(e,t)=>{it(e,t)},renderListView:ot,onCreateView:Me,onViewAction:Ne})})})}),(0,Q.jsx)(na,{open:m&&H,sections:[{title:`View Configuration`,data:G},{title:`Object Definition`,data:U}]}),(0,Q.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${P&&H?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,Q.jsx)(ls,{open:P&&H,onClose:()=>{F(!1),te(`edit`)},mode:I,activeView:G,objectDef:U,recordCount:le,onSave:se,onViewUpdate:ke,onCreate:ce,metadataClient:j,onAfterChange:()=>he(e=>e+1)})}),(0,Q.jsx)(ps,{open:ne&&H,onOpenChange:L,existingLabels:Ee.map(e=>e.label).filter(Boolean),objectDef:U,onCreate:e=>ce(e)})]}),nt.mode!==`split`&&(0,Q.jsx)(Ve,{...nt,setIsOpen:e=>{e||rt()},title:g(U),onExpand:at,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${U.name}`,children:r=>{let i=r.id||r._id;return(0,Q.jsx)(Ei,{dataSource:e,objects:t,onEdit:n,objectNameOverride:U.name,recordIdOverride:i,embedded:!0})}})]}),ge.dialogs]})}function Ss(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 Cs(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 ws=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=Ss(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(Cs)};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 Ts(){let e=ce();return(0,Z.useMemo)(()=>e?new ws(e):null,[e])}var Es=0;function Ds(e=`nav`){return`${e}_${Date.now()}_${++Es}`}function Os(e,t){return[...e,t]}function ks(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:ks(e.children,t,n)}:e)}function As(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:As(i.children,t,n,r)}:i})}function js(e,t){return e.length===t.length?e===t?!0:JSON.stringify(e)===JSON.stringify(t):!1}function Ms(e){return typeof e==`string`&&e.startsWith(`sys_`)}function Ns(e){if(!e||typeof e!=`object`)return!1;let t=e;return t._packageId!=null||t._provenance===`package`?!0:Ms(t.name)}function Ps(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t._lock??t.protection?.lock;return n!==`full`&&n!==`no-overlay`}function Fs(){let e=ce(),{apps:t,refresh:n}=I(),{t:r}=V(),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=>Ri(t,e),[t]),c=(0,Z.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Os(a,{id:Ds(`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=Os(a,{id:Ds(`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=ks(i,`page`,t);if(js(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=ks(i,`dashboard`,t);if(js(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=As(a,`page`,t,n);if(js(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=As(a,`dashboard`,t,n);if(js(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||!Ps(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||!Ps(r)||await l(t,e,n)}},[t,l]),syncPageDeletedAllApps:(0,Z.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!Ps(n)||await u(t,e)}},[t,u]),syncDashboardDeletedAllApps:(0,Z.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!Ps(n)||await d(t,e)}},[t,d]),syncPageRenamedAllApps:(0,Z.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!Ps(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||!Ps(r)||await p(t,e,n)}},[t,p])}}function Is(){let{pages:e,dashboards:t,apps:n,getTypeStatus:r}=I(),i=ce(),a=(0,Z.useRef)(i);a.current=i;let o=ci(),{syncPageCreated:s,syncDashboardCreated:c,syncPageDeleted:l,syncDashboardDeleted:u}=Fs(),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=>!Ns(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||!Ps(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 Ls=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function Rs(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function zs(e){try{return decodeURIComponent(e)}catch{return e}}function Bs({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}:${zs(t)}`,label:zs(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!Ls.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:Rs(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:Rs(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:Rs(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}var Vs=`objectstack:ai-chat-conversation-id`,Hs=`objectstack:ai-chat-messages`;function Us(e,t){return t?`${Vs}:${e}:${t}`:`${Vs}:${e}`}function Ws(e){try{return localStorage.getItem(e)??void 0}catch{return}}function Gs(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function Ks(e){return`${Hs}:${e}`}function qs(e){try{let t=localStorage.getItem(Ks(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 Js(e,t){if(e)try{if(t.length===0){localStorage.removeItem(Ks(e));return}localStorage.setItem(Ks(e),JSON.stringify(t))}catch{}}function Ys(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 Xs(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)?Xs(e.parts):[]}function Zs(e){if(!e)return[];let t=[];return e.forEach((e,n)=>{let r=e.role;if(r!==`user`&&r!==`assistant`&&r!==`system`)return;let i=Xs(e.content);i.length!==0&&t.push({id:e.id??`msg-${n}`,role:r,parts:i})}),t}async function Qs(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 $s(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 ec(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function tc(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=Us(t,n);return!i&&a&&(s(void 0),l([])),d(!0),(async()=>{try{if(i){let n=await Qs(r,i);if(e)return;if(n){Gs(c,n.id),s(n.id);let e=Zs(n.messages);l(e.length>0?e:qs(n.id)),p.current=t;return}Gs(c,void 0),Js(i,[])}else if(!a){let n=Ws(c);if(n){let i=await Qs(r,n);if(e)return;if(i){s(i.id);let e=Zs(i.messages);l(e.length>0?e:qs(i.id)),p.current=t;return}Gs(c,void 0),Js(n,[])}}let n=await $s(r);if(e)return;Gs(c,n.id),s(n.id),l(Zs(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=Us(t,n);d(!0);try{o&&await ec(r,o),Js(o,[]),Gs(e,void 0);let t=await $s(r);if(Gs(e,t.id),Js(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 nc=new Set([`new chat`,`new conversation`,`untitled`,`新对话`]);function rc(e){let t=e?.trim().toLowerCase();return!t||nc.has(t)}function ic(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=ac(n.content);if(e)return e}}let n=t[t.length-1];return ac(n?.content)}function ac(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 ac(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 oc(e){let t=e.title?.trim(),n=ic(e)??ac(e.preview);return{id:e.id,title:rc(t)?void 0:t,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:n}}async function sc(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(!n.ok)return;let r=await n.json();return oc(`conversation`in r&&r.conversation?r.conversation:r)}function cc(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(oc).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=>sc(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 lc({appName:e,error:t,onRetry:n}){let{t:r}=V(),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)(at,{className:`h-8 w-8`})}),(0,Q.jsx)(Fe,{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)(Wr,{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)(K,{variant:`outline`,onClick:n,"data-testid":`preview-draft-retry`,children:[(0,Q.jsx)(dt,{className:`mr-1.5 h-3.5 w-3.5`}),r(`preview.empty.retry`,{defaultValue:`Retry`})]})})]})})}var uc=(0,Z.lazy)(()=>u(()=>import(`./RecordDetailView-CGxfnls1.js`).then(e=>e.n).then(e=>({default:e.RecordDetailView})),__vite__mapDeps([0]),import.meta.url)),dc=(0,Z.lazy)(()=>u(()=>import(`./DashboardView-HNhMjAZZ.js`).then(e=>e.t).then(e=>({default:e.DashboardView})),__vite__mapDeps([0,1]),import.meta.url)),fc=(0,Z.lazy)(()=>u(()=>import(`./PageView-H7j3JwJI.js`).then(e=>e.t).then(e=>({default:e.PageView})),__vite__mapDeps([0]),import.meta.url)),pc=(0,Z.lazy)(()=>u(()=>import(`./ReportView-_NBbKT5l.js`).then(e=>e.t).then(e=>({default:e.ReportView})),__vite__mapDeps([0]),import.meta.url)),mc=(0,Z.lazy)(()=>u(()=>import(`./SearchResultsPage-D9HdE2xf.js`).then(e=>e.t).then(e=>({default:e.SearchResultsPage})),__vite__mapDeps([0]),import.meta.url)),hc=(0,Z.lazy)(()=>u(()=>import(`./RecordFormPage-B8sjq5K3.js`).then(e=>e.t).then(e=>({default:e.RecordFormPage})),__vite__mapDeps([0]),import.meta.url)),gc=(0,Z.lazy)(()=>u(()=>import(`./ComponentNavView-Br-wa130.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),_c=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-2GXysZST.js`).then(e=>e.t).then(e=>({default:e.MetadataDirectoryPage})),__vite__mapDeps([0]),import.meta.url)),vc=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-2GXysZST.js`).then(e=>e.t).then(e=>({default:e.StudioHomePage})),__vite__mapDeps([0]),import.meta.url)),yc=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-2GXysZST.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceListPage})),__vite__mapDeps([0]),import.meta.url)),bc=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-2GXysZST.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceEditPage})),__vite__mapDeps([0]),import.meta.url)),xc=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-2GXysZST.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceHistoryPage})),__vite__mapDeps([0]),import.meta.url)),Sc=(0,Z.lazy)(()=>u(()=>import(`./metadata-admin-2GXysZST.js`).then(e=>e.t).then(e=>({default:e.MetadataDiagnosticsPage})),__vite__mapDeps([0]),import.meta.url)),Cc=(0,Z.lazy)(()=>u(()=>Promise.resolve().then(()=>Np).then(e=>({default:e.CreateAppPage})),void 0,import.meta.url)),wc=(0,Z.lazy)(()=>u(()=>Promise.resolve().then(()=>Np).then(e=>({default:e.EditAppPage})),void 0,import.meta.url)),Tc=(0,Z.lazy)(()=>u(()=>Promise.resolve().then(()=>Np).then(e=>({default:e.DashboardDesignPage})),void 0,import.meta.url)),Ec=(0,Z.lazy)(()=>u(()=>import(`./MarketplacePage-C5lziiq9.js`).then(e=>e.t).then(e=>({default:e.MarketplacePage})),__vite__mapDeps([0]),import.meta.url)),Dc=(0,Z.lazy)(()=>u(()=>import(`./MarketplacePackagePage-DnmqDFCq.js`).then(e=>e.t).then(e=>({default:e.MarketplacePackagePage})),__vite__mapDeps([0]),import.meta.url)),Oc=(0,Z.lazy)(()=>u(()=>import(`./MarketplaceInstalledPage-B5oYOVdC.js`).then(e=>e.t).then(e=>({default:e.MarketplaceInstalledPage})),__vite__mapDeps([0]),import.meta.url));function kc({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 Ac({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,a]=(0,Z.useState)(`disconnected`),{user:s,getAuthConfig:c}=x(),u=ce(),[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}=I(),T=ci(),{t:E}=V(),{objectLabel:D}=hn(),[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 A=v.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),M=m.pathname.endsWith(`/create-app`),N=m.pathname.includes(`/system`),F=m.pathname.includes(`/metadata`),ee=m.pathname===`/apps/setup`||m.pathname.startsWith(`/apps/setup/`),te=M||N||F||ee,ne=Ri(v,g),L=ne||(!g||te?A.find(e=>e.isDefault===!0)||A[0]:void 0),R=!!g&&!ne&&!te,[re,z]=(0,Z.useState)(`idle`);(0,Z.useEffect)(()=>{if(!R){re!==`idle`&&z(`idle`);return}re===`idle`&&!b&&!T&&(z(`checking`),Promise.resolve(w()).finally(()=>z(`done`)))},[R,b,T,re,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,B]=(0,Z.useState)(!1),[ae,oe]=(0,Z.useState)(null),[le,ue]=(0,Z.useState)(0),{execute:de,runner:fe}=P();j({dataSource:u??void 0,onUndo:e=>{X.info(`Undo: ${e.description}`,{duration:4e3}),ue(e=>e+1)},onRedo:e=>{X.info(`Redo: ${e.description}`,{duration:3e3}),ue(e=>e+1)}}),(0,Z.useEffect)(()=>{fe.registerHandler(`crud_success`,async e=>(B(!1),ue(e=>e+1),X.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),fe.registerHandler(`dialog_cancel`,async()=>(B(!1),{success:!0})),fe.registerHandler(`navigate_create`,async e=>{let t=Ji({action:e,context:fe.getContext?.()??{},defaultBaseUrl:`/apps/${g??``}`});return t.success?(p(t.url),{success:!0}):t}),fe.registerHandler(`navigate_edit`,async e=>{let t=Xi({action:e,context:fe.getContext?.()??{},defaultBaseUrl:`/apps/${g??``}`});return t.success?(p(t.url),{success:!0}):t})},[fe,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 H=m.pathname.split(`/`).filter(Boolean)[2];(H===`view`||H===`record`||H===`page`||H===`dashboard`||H===`design`)&&(H=``);let pe=y.find(e=>e.name===H),U=(0,Z.useCallback)(()=>{let e=pe?D(pe):E(`common.record`,{defaultValue:`Record`});de({type:`crud_success`,params:{message:ae?E(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):E(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[de,ae,pe,D,E]),me=(0,Z.useCallback)(()=>{de({type:`dialog_cancel`})},[de]);Bs({pathname:m.pathname,appName:L?.name,objects:y});let he=e=>{let t=Qi({objectDef:pe,baseUrl:g?`/apps/${g}`:L?.name?`/apps/${L.name}`:``,record:e});if(t.kind===`page`){p(t.url);return}oe(e),B(!0)},ge=e=>{p(`/apps/${e}`)},_e=(0,Z.useMemo)(()=>new se({user:s?{name:s.name,email:s.email,role:s.role??`user`}:{},app:L||{},data:ae||{}}),[s,L,ae]);return!u||b||!O?(0,Q.jsx)(qo,{}):T&&(R||!L)?(0,Q.jsx)(lc,{appName:g,error:C,onRetry:()=>void w()}):R?re===`done`?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(Fe,{children:E(`empty.appNotAvailable`,{defaultValue:`App not available`})}),(0,Q.jsx)(Wr,{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)(K,{onClick:()=>z(`idle`),"data-testid":`app-not-available-retry`,children:E(`common.retry`,{defaultValue:`Retry`})})})]})}):(0,Q.jsx)(qo,{}):!L&&!M&&!N&&!F?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(Fe,{children:E(`empty.noAppsConfigured`)}),(0,Q.jsx)(Wr,{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)(K,{onClick:()=>p(`/create-app`),"data-testid":`create-first-app-btn`,children:E(`empty.createFirstApp`)}),(0,Q.jsx)(K,{variant:`outline`,onClick:()=>p(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:E(`empty.systemSettings`)})]})]})}):!L&&(M||N||F)?(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsxs)(i,{children:[(0,Q.jsx)(h,{path:`create-app`,element:(0,Q.jsx)(Cc,{})}),(0,Q.jsx)(h,{path:`system/marketplace`,element:(0,Q.jsx)(Ec,{})}),(0,Q.jsx)(h,{path:`system/marketplace/installed`,element:(0,Q.jsx)(Oc,{})}),(0,Q.jsx)(h,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(Dc,{})}),(0,Q.jsx)(h,{path:`metadata`,element:(0,Q.jsx)(_c,{})}),(0,Q.jsx)(h,{path:`metadata/_diagnostics`,element:(0,Q.jsx)(Sc,{})}),(0,Q.jsx)(h,{path:`metadata/:type`,element:(0,Q.jsx)(yc,{})}),(0,Q.jsx)(h,{path:`metadata/:type/new`,element:(0,Q.jsx)(bc,{createMode:!0})}),(0,Q.jsx)(h,{path:`metadata/:type/:name`,element:(0,Q.jsx)(bc,{})}),(0,Q.jsx)(h,{path:`metadata/:type/:name/history`,element:(0,Q.jsx)(xc,{})}),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)(Is,{}),(0,Q.jsxs)(Bo,{activeAppName:L.name,activeApp:L,onAppChange:ge,objects:y,connectionState:n,userId:s?.id,children:[(0,Q.jsx)(Ho,{apps:v,activeApp:L,objects:y,onAppChange:ge,dataSource:u}),(0,Q.jsx)(Wo,{}),(0,Q.jsx)(Go,{}),(0,Q.jsx)(kc,{appName:g}),(0,Q.jsx)(rs,{children:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(Xo,{className:`h-full`,children:(0,Q.jsxs)(i,{children:[(0,Q.jsx)(h,{path:`/`,element:(()=>{let e=Pc(L,{currentUserId:s?.id??null});return e?(0,Q.jsx)(r,{to:e,replace:!0}):(0,Q.jsx)(vc,{})})()}),(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)(_c,{})}),(0,Q.jsx)(h,{path:`_diagnostics`,element:(0,Q.jsx)(Sc,{})}),(0,Q.jsx)(h,{path:`:type`,element:(0,Q.jsx)(yc,{})}),(0,Q.jsx)(h,{path:`:type/new`,element:(0,Q.jsx)(bc,{createMode:!0})}),(0,Q.jsx)(h,{path:`:type/:name`,element:(0,Q.jsx)(bc,{})}),(0,Q.jsx)(h,{path:`:type/:name/history`,element:(0,Q.jsx)(xc,{})})]}),(0,Q.jsx)(h,{path:`:objectName`,element:(0,Q.jsx)(bs,{dataSource:u,objects:y,onEdit:he,externalRefreshKey:le})}),(0,Q.jsx)(h,{path:`:objectName/new`,element:(0,Q.jsx)(hc,{mode:`create`})}),(0,Q.jsx)(h,{path:`:objectName/view/:viewId`,element:(0,Q.jsx)(bs,{dataSource:u,objects:y,onEdit:he,externalRefreshKey:le})}),(0,Q.jsx)(h,{path:`:objectName/record/:recordId`,element:(0,Q.jsx)(uc,{dataSource:u,objects:y,onEdit:he},le)}),(0,Q.jsx)(h,{path:`:objectName/record/:recordId/edit`,element:(0,Q.jsx)(hc,{mode:`edit`})}),(0,Q.jsx)(h,{path:`dashboard/:dashboardName`,element:(0,Q.jsx)(dc,{dataSource:u})}),(0,Q.jsx)(h,{path:`report/:reportName`,element:(0,Q.jsx)(pc,{dataSource:u})}),(0,Q.jsx)(h,{path:`page/:pageName`,element:(0,Q.jsx)(fc,{})}),(0,Q.jsx)(h,{path:`component/:ns/:name/*`,element:(0,Q.jsx)(gc,{})}),(0,Q.jsx)(h,{path:`component/metadata/directory`,element:(0,Q.jsx)(Lc,{mode:`directory`})}),(0,Q.jsx)(h,{path:`component/metadata/resource/*`,element:(0,Q.jsx)(Lc,{mode:`resource`})}),(0,Q.jsx)(h,{path:`design/dashboard/:dashboardName`,element:(0,Q.jsx)(Tc,{})}),(0,Q.jsx)(h,{path:`search`,element:(0,Q.jsx)(mc,{})}),(0,Q.jsx)(h,{path:`create-app`,element:(0,Q.jsx)(Cc,{})}),(0,Q.jsx)(h,{path:`edit-app/:editAppName`,element:(0,Q.jsx)(wc,{})}),(0,Q.jsx)(h,{path:`system/marketplace`,element:(0,Q.jsx)(Ec,{})}),(0,Q.jsx)(h,{path:`system/marketplace/installed`,element:(0,Q.jsx)(Oc,{})}),(0,Q.jsx)(h,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(Dc,{})}),e,(0,Q.jsx)(h,{path:`:objectName/:maybeRecordId`,element:(0,Q.jsx)(Rc,{})}),(0,Q.jsx)(h,{path:`*`,element:(0,Q.jsx)(zc,{})})]})})})}),pe&&(0,Q.jsx)(ti,{schema:{type:`object-form`,formType:`modal`,objectName:pe.name,mode:ae?`edit`:`create`,recordId:ae?.id,subforms:pe.form?.subforms??pe.formViews?.default?.subforms,title:E(ae?`form.editTitle`:`form.createTitle`,{object:D(pe)}),description:E(ae?`form.editDescription`:`form.createDescription`,{object:D(pe)}),open:ie,onOpenChange:B,layout:`vertical`,fields:pe.fields?Array.isArray(pe.fields)?pe.fields.filter(e=>typeof e==`string`?!0:li(e.visible,_e)).map(e=>typeof e==`string`?e:e.name):Object.entries(pe.fields).filter(([e,t])=>li(t.visible,_e)).map(([e])=>e):[],onSuccess:U,onCancel:me,showSubmit:!0,showCancel:!0,submitText:ae?E(`form.update`,{defaultValue:E(`common.save`,{defaultValue:`Save`})}):E(`form.create`,{defaultValue:E(`common.create`,{defaultValue:`Create`})}),cancelText:E(`common.cancel`)},dataSource:u},ae?.id||`new`)]})]})}function jc(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=Mc(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=jc(n.children,t);if(e!==``)return e}}return``}function Mc(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 Nc(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=Nc(n.children,t);if(e)return e}}}function Pc(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=Mc(Nc(r,n),t);if(e)return e}return jc(r,t)}var Fc=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function Ic(e){return!e||Fc.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function Lc({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 Rc(){let{objectName:e,maybeRecordId:t}=o(),n=l();return e&&Ic(t)?(0,Q.jsx)(r,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,Q.jsx)(zc,{})}function zc(){let e=_(),{t}=V();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)(Fe,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Q.jsx)(Wr,{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)(K,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function Bc({children:e,userId:t}){let{setContext:n}=Si(),{isAiEnabled:r}=F(),{t:i}=V(),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)(Fo,{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)(Ja,{appLabel:i(`workspace.default`,{defaultValue:`Workspace`}),objects:[],userId:t})]})}var Vc=[{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 Hc(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function Uc({app:e,onClick:t,isFavorite:n,index:r=0}){let{t:i}=V(),{appLabel:a,appDescription:o}=hn(),{toggleFavorite:s}=gi(),c=Ui(e.icon),l=a({name:e.name,label:Zi(e.label,i)}),u=o({name:e.name,description:Zi(e.description,i)}),d=Vc[(Hc(e.name)+r)%Vc.length];return(0,Q.jsxs)(sr,{className:J(`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:J(`absolute inset-x-0 top-0 h-1`,d.solid)}),(0,Q.jsx)(`div`,{"aria-hidden":!0,className:J(`absolute inset-0 bg-gradient-to-br opacity-0 transition-opacity duration-300 group-hover:opacity-100`,d.from,d.to)}),(0,Q.jsxs)(Je,{className:`relative p-5`,children:[(0,Q.jsx)(K,{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/${zi(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)(Xn,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Q.jsx)(ur,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:J(`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:J(`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:J(`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)(H,{className:`h-3.5 w-3.5 transition-transform duration-200 group-hover:translate-x-0.5 group-hover:-translate-y-0.5`})]})})]})]})}var Wc={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`},Gc={object:Nt,record:Tt,dashboard:ve,page:Vr};function Kc({items:e}){let t=_(),{t:n}=V();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)(Qn,{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=Gc[e.type]||Nt,i=n(`home.recentApps.itemType.${e.type}`,{defaultValue:$i(e.type)}),a=Wc[e.type]||Wc.object;return(0,Q.jsx)(sr,{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)(Je,{className:`p-3.5`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:J(`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)(H,{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 qc={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`},Jc={object:Nt,record:Tt,dashboard:ve,page:Vr};function Yc({items:e}){let t=_(),{t:n}=V();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)(Xn,{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=Jc[e.type]||Nt,i=qc[e.type]||qc.object,a=n(`home.recentApps.itemType.${e.type}`,{defaultValue:$i(e.type)});return(0,Q.jsx)(sr,{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)(Je,{className:`p-3.5`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:J(`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)(H,{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 Xc(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function Zc({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)(Xn,{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)(Qn,{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)(Fn,{className:`h-3.5 w-3.5`})]})]})})}function Qc({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 $c({t:e}){let t=Ii(),[n,r]=(0,Z.useState)([]),{publishAll:i,publishing:a}=Ya(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)(Cn,{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)(K,{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 el({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)($t,{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)(K,{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 tl(){let e=_(),{t}=V(),{apps:n,loading:r}=I(),{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(Xc(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)($c,{t}),(0,Q.jsx)(el,{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)(Fe,{children:t(`home.welcome`,{defaultValue:`Welcome to ObjectUI`})}),(0,Q.jsx)(Wr,{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)(K,{onClick:()=>e(`/ai?agent=metadata_assistant`),"data-testid":`build-with-ai-btn`,children:[(0,Q.jsx)(Gn,{className:`mr-2 h-4 w-4`}),t(`home.buildWithAI`,{defaultValue:`Build with AI`})]})})]}):(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(Fe,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,Q.jsx)(Wr,{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)($c,{t}),(0,Q.jsx)(el,{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)(Gn,{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)(K,{onClick:()=>e(`/ai?agent=metadata_assistant`),"data-testid":`home-build-with-ai`,children:[(0,Q.jsx)(Gn,{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)(Qc,{icon:Gr,tone:`text-indigo-600 dark:text-indigo-400`,value:c.length,label:t(`home.stats.apps`,{defaultValue:`Applications`})}),i.length>0&&(0,Q.jsx)(Qc,{icon:Qn,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)(Qc,{icon:Xn,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)(Zc,{t}),u.length>0&&(0,Q.jsx)(Yc,{items:u}),l.length>0&&(0,Q.jsx)(Kc,{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)(Gr,{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)(K,{variant:`outline`,onClick:()=>e(`/apps/setup/system/marketplace`),"data-testid":`browse-marketplace-btn`,children:[(0,Q.jsx)(yn,{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)(Uc,{app:t,index:n,onClick:()=>e(`/apps/${zi(t)??t.name}`),isFavorite:a.some(e=>e.id===`app:${t.name}`)},t.name))})]})]})})]})}function nl({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)(Fo,{variant:`orgs`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}function rl(e){return e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48)}function il({open:e,onOpenChange:t,onCreated:n}){let{t:r}=V(),{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(rl(o))},[o,u]),(0,Z.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,Q.jsx)(Qe,{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)(Le,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Q.jsx)(Kr,{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)(tr,{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)(tr,{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)(ye,{children:[(0,Q.jsx)(K,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(K,{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 al(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 ol(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function sl(){let{t:e}=V(),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=al()}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)(wt,{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)(K,{onClick:()=>u(!0),"data-testid":`organizations-new`,children:[(0,Q.jsx)(Ie,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),h.length===0?(0,Q.jsxs)(yt,{children:[(0,Q.jsx)(Fe,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,Q.jsx)(Wr,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),p&&(0,Q.jsxs)(K,{className:`mt-6`,onClick:()=>u(!0),children:[(0,Q.jsx)(Ie,{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)(Sn,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Q.jsx)(Zn,{src:n.logo,alt:n.name}),(0,Q.jsx)(xr,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:ol(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)(il,{open:l,onOpenChange:u,onCreated:y})]})}function cl(){let{t:e}=V(),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)(K,{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)(Fo,{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)(lr,{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 ll(){return a()}function ul(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function dl({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=V(),{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=ul(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)(Qe,{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)(Le,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Q.jsx)(Kr,{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)(tr,{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:ul(m.id),className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,Q.jsx)(K,{type:`button`,variant:`outline`,size:`icon`,onClick:y,"aria-label":`Copy`,children:g?(0,Q.jsx)(Ir,{className:`h-4 w-4`}):(0,Q.jsx)(Ye,{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)(ye,{children:(0,Q.jsx)(K,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Q.jsxs)(`form`,{onSubmit:v,children:[(0,Q.jsxs)(Lt,{children:[(0,Q.jsx)(Le,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Q.jsx)(Kr,{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)(tr,{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)(tr,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,Q.jsxs)(xe,{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)(Be,{value:`member`,children:i(`organization.roles.member`,{defaultValue:`Member`})}),(0,Q.jsx)(Be,{value:`admin`,children:i(`organization.roles.admin`,{defaultValue:`Admin`})}),(0,Q.jsx)(Be,{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)(ye,{children:[(0,Q.jsx)(K,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:u,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(K,{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 fl(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function pl(){let{t:e}=V(),{org:t}=ll(),{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)(K,{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)(K,{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)(Sn,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,Q.jsx)(Zn,{src:t.user.image,alt:t.user.name}),(0,Q.jsx)(xr,{className:`text-xs font-medium`,children:fl(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)(hr,{children:[(0,Q.jsx)(On,{asChild:!0,children:(0,Q.jsx)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Member actions`,children:(0,Q.jsx)(Ge,{className:`h-4 w-4`})})}),(0,Q.jsxs)(fn,{align:`end`,children:[(0,Q.jsxs)(Tr,{onClick:()=>g(t,`owner`),disabled:t.role===`owner`,children:[(0,Q.jsx)(Dn,{className:`mr-2 h-4 w-4`}),e(`organization.roles.owner`,{defaultValue:`Owner`})]}),(0,Q.jsxs)(Tr,{onClick:()=>g(t,`admin`),disabled:t.role===`admin`,children:[(0,Q.jsx)(Dn,{className:`mr-2 h-4 w-4`}),e(`organization.roles.admin`,{defaultValue:`Admin`})]}),(0,Q.jsxs)(Tr,{onClick:()=>g(t,`member`),disabled:t.role===`member`,children:[(0,Q.jsx)(Dn,{className:`mr-2 h-4 w-4`}),e(`organization.roles.member`,{defaultValue:`Member`})]}),(0,Q.jsxs)(Tr,{className:`text-destructive focus:text-destructive`,onClick:()=>m(t),children:[(0,Q.jsx)(nt,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,Q.jsx)(nr,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,Q.jsxs)(qn,{children:[(0,Q.jsxs)(Tn,{children:[(0,Q.jsx)(ir,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Q.jsx)(Dr,{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)(vn,{children:[(0,Q.jsx)(mn,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(_r,{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)(dl,{organizationId:t.id,open:d,onOpenChange:f,onInvited:()=>h()})]})}function ml(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function hl(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function gl(){let{t:e}=V(),{org:t}=ll(),{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=ml(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)(K,{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)(Sn,{className:`h-9 w-9 shrink-0`,children:(0,Q.jsx)(xr,{className:`text-xs`,children:(0,Q.jsx)(we,{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:hl(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)(K,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>_(t),"aria-label":`Copy invitation link`,children:m===t.id?(0,Q.jsx)(Ir,{className:`h-4 w-4 text-green-600`}):(0,Q.jsx)(Ye,{className:`h-4 w-4`})}),(0,Q.jsx)(K,{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)(nr,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,Q.jsxs)(qn,{children:[(0,Q.jsxs)(Tn,{children:[(0,Q.jsx)(ir,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Q.jsx)(Dr,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,Q.jsxs)(vn,{children:[(0,Q.jsx)(mn,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(_r,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:v,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function _l(){let{t:e}=V(),{org:t}=ll(),{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}=on(),[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)(tr,{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)(tr,{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)(tr,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(Sn,{className:`size-16 rounded-md`,children:[f?(0,Q.jsx)(Zn,{src:f,alt:c,className:`object-cover`}):null,(0,Q.jsx)(xr,{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)(K,{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)(mt,{className:`mr-2 h-4 w-4`}),f?e(`organization.settings.logoReplace`,{defaultValue:`Replace`}):e(`organization.settings.logoUpload`,{defaultValue:`Upload`})]}),f&&(0,Q.jsxs)(K,{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)(K,{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)(K,{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)(K,{variant:`destructive`,size:`sm`,onClick:()=>{j(``),k(!0)},disabled:!S,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,Q.jsx)(nr,{open:E,onOpenChange:D,children:(0,Q.jsxs)(qn,{children:[(0,Q.jsxs)(Tn,{children:[(0,Q.jsx)(ir,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Q.jsx)(Dr,{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)(vn,{children:[(0,Q.jsx)(mn,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(_r,{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)(nr,{open:O,onOpenChange:e=>{k(e),e||j(``)},children:(0,Q.jsxs)(qn,{children:[(0,Q.jsxs)(Tn,{children:[(0,Q.jsx)(ir,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Q.jsx)(Dr,{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)(tr,{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)(vn,{children:[(0,Q.jsx)(mn,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(_r,{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 vl(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 yl(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 bl(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString()}var xl=[`today`,`yesterday`,`previous7Days`,`previous30Days`,`older`],Sl={today:`Today`,yesterday:`Yesterday`,previous7Days:`Previous 7 days`,previous30Days:`Previous 30 days`,older:`Older`};function Cl(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 xl.filter(e=>o[e].length>0).map(e=>({key:e,items:o[e]}))}function wl({userId:e,apiBase:t,className:n,refreshKey:r,titleHints:i,onNavigate:a}){let{t:s}=V(),c=_(),{conversationId:l}=o(),{conversations:u,isLoading:d,error:f,remove:p,rename:m}=cc({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:J(`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)(K,{size:`sm`,variant:`outline`,onClick:S,"data-testid":`ai-new-chat`,children:[(0,Q.jsx)(Ie,{className:`h-3.5 w-3.5`}),s(`console.ai.newChat`)]})]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(wt,{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)(Pe,{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)(Rr,{className:`h-8 w-8 text-muted-foreground`}),(0,Q.jsx)(Fe,{children:s(`console.ai.noChatsYet`)}),(0,Q.jsx)(Wr,{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:Cl(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:Sl[e.key]})}),(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.items.map(e=>(0,Q.jsx)(El,{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 Tl(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 El({conversation:e,query:t,active:n,renaming:r,onSelect:i,onDelete:a,onStartRename:o,onCancelRename:s,onSubmitRename:c}){let{t:l}=V(),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:J(`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)(K,{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)(Ir,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(K,{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:J(`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:Tl(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:Tl(e.preview,t)}):null,(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[10px] text-muted-foreground`,title:bl(e.updatedAt??e.createdAt),children:yl(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)(K,{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)(qt,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(K,{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 Dl(){return typeof window>`u`?``:window.location.pathname.startsWith(`/_console`)?`/_console`:``}function Ol(e,t){let n=`${Dl()}/apps/${encodeURIComponent(e)}`;return t?n:`${n}?preview=draft`}function kl({appName:e,materialized:t=!1,refreshKey:n,onClose:r}){let{t:i}=V(),a=(0,Z.useRef)(null);return(0,Z.useEffect)(()=>{if(!a.current)return;let n=Ol(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)(at,{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)(K,{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:Ol(e,t),className:`h-full w-full flex-1 border-0 bg-background`,"data-testid":`live-canvas-frame`})]})}var Al=`/api/v1/ai`;function jl(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function Ml(e){let t=jl(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 Nl(e){return e.map(e=>{let t=[],n=e.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``);if(e.role===`assistant`)for(let n of e.parts){if(!n.type.startsWith(`tool-`))continue;let r=jl(n,`toolName`)??n.type.slice(5),i=jl(n,`toolCallId`)??`${e.id}-${r}`,a=Ml(n);t.push({toolCallId:i,toolName:r,...a?{state:a}:{},...n.errorText?{errorText:String(n.errorText)}:{}})}return{id:e.id,role:e.role,content:n,...t.length>0?{toolInvocations:t}:{}}})}function Pl(e){return e.find(e=>e.role===`user`)?.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``).trim()||void 0}var Fl={data_chat:{key:`console.ai.agentLabels.dataChat`,defaultValue:`Assistant`},metadata_assistant:{key:`console.ai.agentLabels.metadataAssistant`,defaultValue:`Metadata Assistant`}};function Il(e,t,n){let r=t?Fl[t]:void 0;return r?e(r.key,{defaultValue:r.defaultValue}):n}function Ll(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(/\/$/,``)}${Al}`}var Rl=`ai-chats-collapsed`;function zl(){let[e,t]=(0,Z.useState)(()=>{try{return localStorage.getItem(Rl)===`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(Rl,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 Bl=`ai-chat-pane-width`,Vl=480,Hl=360,Ul=420,Wl=24;function Gl(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 Kl(e){let t=(0,Z.useRef)(null),[n,r]=(0,Z.useState)(()=>{try{let e=Number(localStorage.getItem(Bl));return Number.isFinite(e)&&e>0?e:Vl}catch{return Vl}}),[i,a]=(0,Z.useState)(!1),o=(0,Z.useCallback)(e=>Gl(e,{min:Hl,previewMin:Ul,containerWidth:t.current?.clientWidth??0}),[]),s=(0,Z.useCallback)(e=>{try{localStorage.setItem(Bl,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`?Wl:0;t&&(e.preventDefault(),r(e=>{let n=o(e+t);return s(n),n}))},[o,s]),reset:(0,Z.useCallback)(()=>{let e=o(Vl);r(e),s(e)},[o,s])}}function ql(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 Jl({apiBase:e,defaultAgent:t}={}){let{user:n}=x(),{t:r}=V(),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)(()=>Ll(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=Fi(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}=tc({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:F}=zl();(0,Z.useEffect)(()=>{let e=e=>{let t=ql(e);t&&(e.preventDefault(),t===`toggle-list`?P():u(`/ai?new=1`))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[P,u]);let ee=(0,Z.useMemo)(()=>f.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[f]),I=(0,Z.useRef)(null);l?I.current===null&&(I.current={id:C}):I.current=null,(0,Z.useEffect)(()=>{if(!a&&C){if(I.current&&I.current.id===C)return;u(`/ai/${C}`,{replace:!0})}},[a,C,u]);let te=(0,Z.useRef)(new Set);(0,Z.useEffect)(()=>{C&&w.length>0&&te.current.add(C)},[C,w.length]),(0,Z.useEffect)(()=>{if(!C)return;let e=Pl(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||te.current.has(C))return;te.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)(K,{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)(Yn,{className:`h-4 w-4`})}),(0,Q.jsx)(K,{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)(Pn,{className:`h-4 w-4`}):(0,Q.jsx)(nn,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(Fo,{variant:`home`})})]}),(0,Q.jsx)(ht,{open:j,onOpenChange:M,children:(0,Q.jsxs)(Me,{side:`left`,className:`w-[320px] p-0 sm:max-w-[360px]`,"data-testid":`ai-chat-mobile-sidebar`,children:[(0,Q.jsxs)(et,{className:`sr-only`,children:[(0,Q.jsx)(Ct,{children:r(`console.ai.chats`)}),(0,Q.jsx)(qe,{children:r(`console.ai.chatsDescription`)})]}),(0,Q.jsx)(wl,{userId:i,apiBase:f,refreshKey:T,titleHints:D,className:`h-full border-r-0`,onNavigate:()=>M(!1)})]})}),C&&(0,Q.jsx)(Pr,{open:k,onOpenChange:A,objectName:`ai_conversations`,recordId:C,recordLabel:`this conversation`,apiBase:ee}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 w-full bg-muted/20`,children:[!N&&(0,Q.jsx)(wl,{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)(Yl,{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:F},`${S??`local`}:${C??`pending`}`)})]})]})}function Yl({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}=V(),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=Kl(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)(()=>Il(p,i,e.find(e=>e.name===i)?.label??i??p(`console.ai.assistant`)),[e,i,p]),E=(0,Z.useMemo)(()=>Nl(l),[l]),D=(0,Z.useMemo)(()=>{if(!(E.length>0))return $l(i,T,p)},[E.length,i,T,p]),{messages:O,isLoading:k,error:A,sendMessage:j,stop:M,reload:N,clear:P}=Mi({api:o,conversationId:c,body:{context:{activeApp:`AI`,agentName:i,autoPublishAiBuilds:ia().features.autoPublishAiBuilds}},initialMessages:E,autoResponse:!o,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600});(0,Z.useEffect)(()=>{Js(c,Ys(O))},[c,O]);let F=Pi({messages:O,apiBase:s,continueConversation:e=>{j(e)}}),ee=(0,Z.useCallback)((e,t)=>{j(e,t),u(e)},[j,u]),I=(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)(xe,{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)(Be,{value:e.name,className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:Il(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)(K,{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)(jr,{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`,surface:`plain`,maxHeight:`100%`,headerSlot:I,messages:O,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:ee,onClear:P,hideClearBar:!0,onStop:k?M:void 0,onReload:N,isLoading:k,error:A,enableMarkdown:!0,onToolApprove:F.decide,toolDecisions:F.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:vl,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:ia().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:J(`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:J(`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)(kl,{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 Xl(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 Zl(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 Ql(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 $l(e,t,n){if(e===`data_chat`)return Xl(n);if(e===`metadata_assistant`)return Zl(n);let r=(e??t).toLowerCase();return r.includes(`data`)?Xl(n):r.includes(`metadata`)?Zl(n):Ql(n)}var eu=new Map;function tu(e){eu.set(e.ref,e)}function nu(e){return eu.get(e)}function ru(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function iu(e){return!ru(e)||e.viewKind?!1:!!(e.list||e.form||e.listViews||e.formViews)}function au(e){if(!ru(e))return;let t=e.config;if(ru(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`}tu({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:Gi}),tu({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:Ki}),tu({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:Bi}),Hi({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`}]}),Hi({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`}]}),Hi({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:Wi,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`}]}),Hi({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)=>au(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!iu(e)}),Hi({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`}]}),Hi({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 ou=`/api/v1/cloud-connection`;async function su(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 cu(){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 su(`${ou}/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 su(`${ou}/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 su(`${ou}/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 su(`${ou}/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)(en,{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)(Ae,{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)(Ye,{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)(Ae,{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)(Mn,{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)(je,{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)(Sr,{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)(de,{className:`h-4 w-4`,"aria-hidden":`true`}),`Connect`]})]})}B.register(`cloud-connection:panel`,()=>(0,Q.jsx)(cu,{}),{namespace:`app-shell`,label:`Cloud Connection Panel`,category:`plugin`,inputs:[]});var lu={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`}]}},uu=()=>{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)(K,{"data-testid":`open-center`,onClick:()=>e({placement:`center`,size:`lg`,title:`Center modal`,content:lu}),children:`Center`}),(0,Q.jsx)(K,{"data-testid":`open-side`,variant:`outline`,onClick:()=>e({placement:`side`,title:`Side drawer`,content:lu}),children:`Side drawer`}),(0,Q.jsx)(K,{"data-testid":`open-bottom`,variant:`outline`,onClick:()=>e({placement:`bottom`,title:`Bottom sheet`,content:lu}),children:`Bottom sheet`}),(0,Q.jsx)(K,{"data-testid":`open-fullscreen`,variant:`outline`,onClick:()=>e({placement:`fullscreen`,title:`Fullscreen`,content:lu}),children:`Fullscreen`})]}),t]})},du=()=>{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)})]})},fu=(0,Z.lazy)(()=>u(()=>import(`./SystemHubPage-maebng1S.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]),import.meta.url)),pu=(0,Z.lazy)(()=>u(()=>import(`./AppManagementPage-B66TgUPL.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),mu=(0,Z.lazy)(()=>u(()=>import(`./ProfilePage-BBeI_CPu.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),hu=(0,Z.lazy)(()=>u(()=>import(`./ApprovalsInboxPage-C8mv1Yo5.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),gu=(0,Z.lazy)(()=>u(()=>import(`./AiPendingActionsPage-BcncanbT.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),_u=(0,Z.lazy)(()=>u(()=>import(`./AuditLogPage-CS-Jundr.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),vu=(0,Z.lazy)(()=>u(()=>import(`./SettingsHub-Ca4TQg_Q.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),yu=(0,Z.lazy)(()=>u(()=>import(`./SettingsView-6GSnMLNA.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),bu=(0,Z.lazy)(()=>u(()=>import(`./DeveloperHubPage-B3I-35Xy.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),xu=(0,Z.lazy)(()=>u(()=>import(`./ApiConsolePage-C6tVqeCx.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),Su=(0,Z.lazy)(()=>u(()=>import(`./FlowRunsPage-CATcsy8B.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),Cu=(0,Z.lazy)(()=>u(()=>import(`./PublicFormsPage-Bhp5KfIY.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url)),wu=(0,Z.lazy)(()=>u(()=>import(`./IntegrationsPage-Cq1qq5jk.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([0]),import.meta.url)),Tu=(0,Z.lazy)(()=>u(()=>Promise.resolve().then(()=>nd),void 0,import.meta.url)),Eu=(0,Z.lazy)(()=>u(()=>import(`./AppDocsIndex-D--pdm0E.js`),__vite__mapDeps([0]),import.meta.url));function Du(){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 Ou(){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 ku=(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{path:`system`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(fu,{})})}),(0,Q.jsx)(h,{path:`system/apps`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(pu,{})})}),(0,Q.jsx)(h,{path:`system/profile`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(mu,{})})}),(0,Q.jsx)(h,{path:`system/approvals`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(hu,{})})}),(0,Q.jsx)(h,{path:`system/ai-approvals`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(gu,{})})}),(0,Q.jsx)(h,{path:`system/audit-log`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(_u,{})})}),(0,Q.jsx)(h,{path:`system/settings`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(vu,{})})}),(0,Q.jsx)(h,{path:`system/settings/:namespace`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(yu,{})})}),(0,Q.jsx)(h,{path:`developer`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(bu,{})})}),(0,Q.jsx)(h,{path:`developer/api-console`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(xu,{})})}),(0,Q.jsx)(h,{path:`developer/flow-runs`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(Su,{})})}),(0,Q.jsx)(h,{path:`developer/public-forms`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(Cu,{})})}),(0,Q.jsx)(h,{path:`developer/integrations`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(wu,{})})}),(0,Q.jsx)(h,{path:`docs`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(Eu,{})})}),(0,Q.jsx)(h,{path:`docs/:name`,element:(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(Tu,{})})}),(0,Q.jsx)(h,{path:`system/objects`,element:(0,Q.jsx)(Du,{})}),(0,Q.jsx)(h,{path:`system/objects/:objectName`,element:(0,Q.jsx)(Du,{})}),(0,Q.jsx)(h,{path:`system/metadata`,element:(0,Q.jsx)(Ou,{})}),(0,Q.jsx)(h,{path:`system/metadata/:metadataType`,element:(0,Q.jsx)(Ou,{})}),(0,Q.jsx)(h,{path:`system/metadata/:metadataType/:itemName`,element:(0,Q.jsx)(Ou,{})})]});function Au(){let e=(0,Z.useMemo)(()=>Br({baseUrl:``}),[``]);return(0,Q.jsx)(D,{endpoint:`/api/v1/auth/me/permissions`,loadingFallback:(0,Q.jsx)(qo,{}),children:(0,Q.jsx)(kr,{adapter:e,children:(0,Q.jsx)(Ac,{extraRoutes:ku,extraRoutesNoApp:ku})})})}var ju=[`cloud_control`];function Mu(){let{apps:e,loading:t}=I();if(t)return(0,Q.jsx)(za,{});let n=new Set((e??[]).map(e=>e?.name).filter(Boolean));for(let e of ju)if(n.has(e))return(0,Q.jsx)(r,{to:`/apps/${e}`,replace:!0});return(0,Q.jsx)(r,{to:`/home`,replace:!0})}var Nu=`/api/v1`;function Pu(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function Fu(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 Iu(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=Pu(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:Fu(i.options),maxLength:i.maxLength,colSpan:e.colSpan??1})}return{label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,fields:n}})}function Lu(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 Ru(e,t){return fetch(`${Nu}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function zu(e){let t=await Ru(`/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 Bu(e){let t=await Ru(`/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 Ru(`/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 Vu(e,t){let n=await Ru(`/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 Hu(e,t){let n=await Ru(`/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 Uu=`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 Wu({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:Uu},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 Gu({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`?zu(r):Bu(r)).then(e=>{t||(u(e),f(Lu(Iu(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?Iu(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 Vu(r,d):await Hu(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(Lu(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)(Wu,{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 Ku({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 qu(){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 Ju(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 Yu(){let{token:e}=o(),t=`${(0,Z.useMemo)(()=>qu(),[])}/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)(He,{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)(tr,{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)(K,{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)(Rr,{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=Ju(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 Xu=/(^```[^\n]*\n[\s\S]*?\n```[ \t]*$|^~~~[^\n]*\n[\s\S]*?\n~~~[ \t]*$)/m,Zu=/(`[^`\n]+`)/,Qu=/\]\((?:\.\/)?([a-z][a-z0-9_]*)\.md(#[^)\s]*)?\)/g;function $u(e){return e.split(Zu).map((e,t)=>t%2==1?e:e.replace(Qu,`](/docs/$1$2)`)).join(``)}function ed(e){let t=[],n=e;for(;;){let e=Xu.exec(n);if(!e||e.index===void 0)return t.push($u(n)),t.join(``);t.push($u(n.slice(0,e.index)),e[0]),n=n.slice(e.index+e[0].length)}}function td({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)(Vt,{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 nd=t({default:()=>rd});function rd(){let{name:e,appName:t}=o(),n=_(),r=ce(),{t:i}=V(),[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)(()=>Da(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)(td,{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)(At,{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)(td,{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)(en,{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)(td,{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)(Oa,{schema:{type:`markdown`,content:ed(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 id(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 ad(){let e=ce(),[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(id(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)(en,{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)(td,{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)(Vt,{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)(Vt,{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 od(e){let t=e.split(`:`)[0].toLowerCase();return/^cloud\./.test(t)}function sd(e){let t=e.split(`:`)[0].toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.local`)}function cd(){return typeof window>`u`?null:window.location.host||null}function ld(){let e=aa();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 ud({children:e,formWidth:t=`sm`}){let{t:n}=V(),r=t===`md`?`max-w-md`:`max-w-sm`,i=cd(),a=!!i&&!od(i)&&!sd(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:J(`flex w-full flex-col gap-5`,r),children:[(0,Q.jsx)(ld,{}),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 dd(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function fd(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function pd(e){return(0,Q.jsx)(m,{to:e.href,className:e.className,children:e.children})}function md(){let{t:e}=V(),[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(fd(dd(n)?n:`/`));return}window.location.assign(fd(`/organizations`));return}f||window.location.assign(fd(dd(n)?n:`/`))}},[r,s,a,o,f,n,c]),i&&!h||r)return(0,Q.jsx)(ud,{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)(ud,{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)(sr,{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)(hd,{registerUrl:u?void 0:v,redirect:n})})]})})}function hd({registerUrl:e,redirect:t}){let{t:n}=V(),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:pd,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 gd(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function _d(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function vd(e){return(0,Q.jsx)(m,{to:e.href,className:e.className,children:e.children})}function yd(){let{t:e}=V(),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(_d(gd(r)?r:`/`));return}window.location.assign(_d(`/organizations`));return}m||window.location.assign(_d(gd(r)?r:`/`))}},[i,c,o,s,m,r,l]),d===null||a&&!g||i)return(0,Q.jsx)(ud,{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)(ud,{formWidth:`md`,children:(0,Q.jsx)(sr,{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:vd,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 bd(e){return(0,Q.jsx)(m,{to:e.href,className:e.className,children:e.children})}function xd(){let{t:e}=V();return(0,Q.jsx)(ud,{formWidth:`md`,children:(0,Q.jsx)(sr,{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:bd,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 Sd(){let{t:e}=V(),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)(ud,{children:(0,Q.jsxs)(sr,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Q.jsxs)(Wt,{className:`text-center`,children:[(0,Q.jsx)(Yt,{className:`text-xl tracking-tight`,children:e(`auth.resetPassword.title`,{defaultValue:`Set a new password`})}),(0,Q.jsx)(Jt,{children:e(`auth.resetPassword.description`,{defaultValue:`Choose a password you have not used before.`})})]}),(0,Q.jsx)(Je,{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)(tr,{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)(tr,{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)(K,{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 Cd(e){return e&&e.startsWith(`/`)&&!e.startsWith(`//`)?e:`/`}function wd(){let{t:e}=V(),t=_(),[n]=p(),r=Cd(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)(ud,{children:(0,Q.jsxs)(sr,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Q.jsxs)(Wt,{className:`text-center`,children:[(0,Q.jsx)(Yt,{className:`text-xl tracking-tight`,children:e(`auth.setPassword.title`,{defaultValue:`Set a recovery password`})}),(0,Q.jsx)(Jt,{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)(Je,{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)(tr,{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)(tr,{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)(tr,{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)(K,{type:`submit`,className:`w-full`,disabled:d,children:d?e(`auth.setPassword.submitting`,{defaultValue:`Saving…`}):e(`auth.setPassword.submit`,{defaultValue:`Set password`})})]})})]})})}var Td=`/api/v1/auth`;function Ed(){let{t:e}=V(),[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(`${Td}/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)(ud,{children:(0,Q.jsxs)(sr,{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)(Wt,{className:`text-center`,children:[(0,Q.jsx)(Yt,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.verifyingTitle`,{defaultValue:`Verifying…`})}),(0,Q.jsx)(Jt,{children:e(`auth.verifyEmail.verifyingDescription`,{defaultValue:`Hang tight while we confirm your email.`})})]}),(0,Q.jsx)(Je,{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)(Wt,{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)(Mn,{className:`size-6`})}),(0,Q.jsx)(Yt,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.successTitle`,{defaultValue:`Email verified`})}),(0,Q.jsx)(Jt,{children:e(`auth.verifyEmail.successDescription`,{defaultValue:`Your email is confirmed. You can now sign in.`})})]}),(0,Q.jsx)(Je,{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)(Wt,{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)(vr,{className:`size-6`})}),(0,Q.jsx)(Yt,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.errorTitle`,{defaultValue:`Verification failed`})}),(0,Q.jsx)(Jt,{children:a||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})})]}),(0,Q.jsx)(Je,{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 Dd(){let{t:e}=V(),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)(ud,{children:(0,Q.jsxs)(sr,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,Q.jsxs)(Wt,{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)(ct,{className:`size-8 text-primary`})}),(0,Q.jsx)(Yt,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.title`,{defaultValue:`Verify your email address`})}),(0,Q.jsx)(Jt,{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)(Je,{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)(K,{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)(dt,{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)(dt,{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)(K,{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 Od=`/api/v1/auth`;function kd(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function Ad(){let{t:e}=V(),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(`${Od}/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)(sr,{children:[(0,Q.jsxs)(Wt,{className:`text-center`,children:[(0,Q.jsx)(Yt,{children:e(`auth.setup.welcomeTitle`,{defaultValue:`Welcome to ObjectStack`})}),(0,Q.jsx)(Jt,{children:e(`auth.setup.description`,{defaultValue:`Create the first owner account to finish setting up this deployment.`})})]}),(0,Q.jsx)(Je,{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:kd(e)}),n=t.id):n=(await s({name:e,slug:kd(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)(tr,{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)(tr,{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)(tr,{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)(tr,{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)(K,{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 jd=`/api/v1/auth`;function Md(){let{t:e}=V(),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(`${jd}/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(`${jd}/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)(sr,{className:`w-full max-w-md`,children:[(0,Q.jsxs)(Wt,{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)(Ne,{className:`h-7 w-7 text-muted-foreground`})}),(0,Q.jsx)(Yt,{className:`text-xl`,children:e(`oauth.consent.title`,{appName:h,defaultValue:`${h} wants to access your account`})}),(0,Q.jsx)(Jt,{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)(Je,{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)(Ir,{className:`mt-0.5 h-4 w-4 text-green-600 dark:text-green-400`}),(0,Q.jsx)(`span`,{children:Nd(t,e)})]},t))})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-2`,children:[(0,Q.jsxs)(K,{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)(K,{onClick:()=>m(!0),disabled:i,children:[(0,Q.jsx)(Ir,{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 Nd(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 Pd=`/api/v1/auth`;function Fd({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)(Er,{className:`size-4`})}),`ObjectStack`]}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-6`,children:e})]})})}function Id(){let{t:e}=V(),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)(Fd,{children:(0,Q.jsx)(sr,{children:(0,Q.jsxs)(Wt,{className:`text-center`,children:[(0,Q.jsx)(Yt,{children:e(`auth.device.invalidTitle`,{defaultValue:`Invalid device link`})}),(0,Q.jsx)(Jt,{children:e(`auth.device.invalidDescription`,{defaultValue:`No device code was provided in the URL.`})})]})})});if(c)return(0,Q.jsx)(Fd,{children:(0,Q.jsx)(sr,{children:(0,Q.jsx)(Wt,{className:`text-center`,children:(0,Q.jsx)(Jt,{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)(Fd,{children:(0,Q.jsx)(sr,{children:(0,Q.jsxs)(Wt,{className:`text-center`,children:[(0,Q.jsx)(Mn,{className:`mx-auto mb-2 h-10 w-10 text-green-500`}),(0,Q.jsx)(Yt,{children:e(`auth.device.approvedTitle`,{defaultValue:`Device authorized`})}),(0,Q.jsx)(Jt,{children:e(`auth.device.approvedDescription`,{defaultValue:`You can return to the device — it should sign in shortly.`})})]})})});if(y)return(0,Q.jsx)(Fd,{children:(0,Q.jsx)(sr,{children:(0,Q.jsxs)(Wt,{className:`text-center`,children:[(0,Q.jsx)(Yt,{children:e(`auth.device.deniedTitle`,{defaultValue:`Access denied`})}),(0,Q.jsx)(Jt,{children:e(`auth.device.deniedDescription`,{defaultValue:`The device will not be granted access.`})})]})})});let w=async()=>{await fetch(`${Pd}/device?user_code=${encodeURIComponent(i)}`,{credentials:`include`}).catch(()=>{})};return(0,Q.jsx)(Fd,{children:(0,Q.jsxs)(sr,{children:[(0,Q.jsxs)(Wt,{className:`text-center`,children:[(0,Q.jsx)(Yt,{children:e(`auth.device.title`,{defaultValue:`Authorize new device`})}),(0,Q.jsx)(Jt,{children:e(`auth.device.subtitle`,{email:s.email,defaultValue:`Approve this device to sign in as ${s.email}.`})})]}),(0,Q.jsxs)(Je,{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)(K,{onClick:async()=>{C(``),f(!0);try{await w();let t=await fetch(`${Pd}/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)(K,{onClick:async()=>{C(``),h(!0);try{await w(),await fetch(`${Pd}/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 Ld(){let{t:e}=V(),{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)(sr,{children:[(0,Q.jsxs)(Wt,{className:`text-center`,children:[(0,Q.jsx)(Yt,{className:`text-xl`,children:e(`acceptInvitation.title`,{defaultValue:`Accept organization invitation`})}),(0,Q.jsx)(Jt,{children:e(`acceptInvitation.description`,{defaultValue:`You've been invited to join an organization.`})})]}),(0,Q.jsxs)(Je,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(K,{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)(K,{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)(sr,{className:`w-full max-w-sm`,children:(0,Q.jsxs)(Wt,{className:`text-center`,children:[(0,Q.jsx)(Yt,{className:`text-xl`,children:e(`acceptInvitation.invalidTitle`,{defaultValue:`Invalid invitation link`})}),(0,Q.jsx)(Jt,{children:e(`acceptInvitation.invalidDescription`,{defaultValue:`The invitation id is missing from the URL.`})})]})})})}var Rd=`/api/v1/auth`;function zd(){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 Bd=zd();function Vd(){let e=l(),t=e.pathname+e.search;return(0,Q.jsx)(r,{to:`/login${t&&t!==`/`?`?redirect=${encodeURIComponent(t)}`:``}`,replace:!0})}function Hd({children:e,requireOrganization:t=!0}){return(0,Q.jsx)(k,{fallback:(0,Q.jsx)(Vd,{}),loadingFallback:(0,Q.jsx)(za,{}),children:(0,Q.jsx)(Va,{children:t?(0,Q.jsx)(Wa,{children:e}):e})})}function Ud(){let{user:e}=x();return(0,Q.jsx)(Bc,{userId:e?.id,children:(0,Q.jsx)(tl,{})})}function Wd(){return(0,Q.jsxs)(E,{authUrl:Rd,children:[(0,Q.jsx)(Jo,{position:`bottom-right`}),(0,Q.jsx)(Ku,{}),(0,Q.jsx)(d,{basename:Bd,children:(0,Q.jsx)(Ba,{children:(0,Q.jsxs)(i,{children:[(0,Q.jsx)(h,{path:`/login`,element:(0,Q.jsx)(md,{})}),(0,Q.jsx)(h,{path:`/register`,element:(0,Q.jsx)(yd,{})}),(0,Q.jsx)(h,{path:`/forgot-password`,element:(0,Q.jsx)(xd,{})}),(0,Q.jsx)(h,{path:`/reset-password`,element:(0,Q.jsx)(Sd,{})}),(0,Q.jsx)(h,{path:`/set-password`,element:(0,Q.jsx)(wd,{})}),(0,Q.jsx)(h,{path:`/verify-email`,element:(0,Q.jsx)(Ed,{})}),(0,Q.jsx)(h,{path:`/verify-email-prompt`,element:(0,Q.jsx)(Dd,{})}),(0,Q.jsx)(h,{path:`/setup`,element:(0,Q.jsx)(Ad,{})}),(0,Q.jsx)(h,{path:`/oauth/consent`,element:(0,Q.jsx)(Md,{})}),(0,Q.jsx)(h,{path:`/auth/device`,element:(0,Q.jsx)(Id,{})}),(0,Q.jsx)(h,{path:`/accept-invitation/:invitationId`,element:(0,Q.jsx)(Ld,{})}),(0,Q.jsx)(h,{path:`/f/:slug`,element:(0,Q.jsx)(Gu,{mode:`public`})}),(0,Q.jsx)(h,{path:`/s/:token`,element:(0,Q.jsx)(Yu,{})}),(0,Q.jsx)(h,{path:`/forms/:name`,element:(0,Q.jsx)(Hd,{children:(0,Q.jsx)(Gu,{mode:`internal`})})}),(0,Q.jsx)(h,{path:`/docs`,element:(0,Q.jsx)(Hd,{children:(0,Q.jsx)(ad,{})})}),(0,Q.jsx)(h,{path:`/docs/:name`,element:(0,Q.jsx)(Hd,{children:(0,Q.jsx)(rd,{})})}),(0,Q.jsx)(h,{path:`/home`,element:(0,Q.jsx)(Hd,{children:(0,Q.jsx)(Ud,{})})}),(0,Q.jsx)(h,{path:`/dev/master-detail`,element:(0,Q.jsx)(Hd,{children:(0,Q.jsx)(ja,{})})}),(0,Q.jsx)(h,{path:`/dev/lists`,element:(0,Q.jsx)(Hd,{children:(0,Q.jsx)(Pa,{})})}),(0,Q.jsx)(h,{path:`/dev/modal`,element:(0,Q.jsx)(Hd,{children:(0,Q.jsx)(uu,{})})}),(0,Q.jsx)(h,{path:`/dev/lookup`,element:(0,Q.jsx)(Hd,{children:(0,Q.jsx)(du,{})})}),(0,Q.jsx)(h,{path:`/organizations`,element:(0,Q.jsx)(Hd,{requireOrganization:!1,children:(0,Q.jsx)(nl,{children:(0,Q.jsx)(sl,{})})})}),(0,Q.jsxs)(h,{path:`/organizations/:slug`,element:(0,Q.jsx)(Hd,{requireOrganization:!1,children:(0,Q.jsx)(cl,{})}),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)(pl,{})}),(0,Q.jsx)(h,{path:`invitations`,element:(0,Q.jsx)(gl,{})}),(0,Q.jsx)(h,{path:`settings`,element:(0,Q.jsx)(_l,{})})]}),(0,Q.jsx)(h,{path:`/system/*`,element:(0,Q.jsx)(Ga,{})}),(0,Q.jsx)(h,{path:`/ai`,element:(0,Q.jsx)(Hd,{children:(0,Q.jsx)(Jl,{})})}),(0,Q.jsx)(h,{path:`/ai/:conversationId`,element:(0,Q.jsx)(Hd,{children:(0,Q.jsx)(Jl,{})})}),(0,Q.jsx)(h,{path:`/apps/:appName/*`,element:(0,Q.jsx)(Hd,{children:(0,Q.jsx)(Au,{})})}),(0,Q.jsx)(h,{path:`/`,element:(0,Q.jsx)(Va,{children:(0,Q.jsx)(Mu,{})})}),(0,Q.jsx)(h,{path:`*`,element:(0,Q.jsx)(r,{to:`/`,replace:!0})})]})})})]})}async function Gd(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 Kd=`auth-session-token`,qd=`auth-active-organization-id`;async function Jd(e){if(typeof window>`u`)return;let t=null;try{t=localStorage.getItem(Kd)}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(Kd),localStorage.removeItem(qd)}catch{}}function Yd(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 Xd(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 Zd(e){let{objects:t}=I(),n=(0,Z.useMemo)(()=>(t||[]).find(t=>t.name===e),[t,e]);return{object:(0,Z.useMemo)(()=>n?Yd(n,0):null,[n]),fields:(0,Z.useMemo)(()=>n?(Array.isArray(n.fields)?n.fields:Object.values(n.fields||{})).map(Xd):[],[n]),metadataObject:n}}function Qd({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)(Cr,{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)(Ir,{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)(qt,{className:`h-3 w-3`})})]})})]})}function $d({schema:e}){let t=e.objectName,{object:n,fields:r,metadataObject:i}=Zd(t),{refresh:a}=I(),o=Ts(),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)(Qd,{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)(Qd,{label:`复数名称`,value:n.pluralLabel||``,onSave:e=>s(`pluralLabel`,e),placeholder:`例如:客户们`,disabled:c}),(0,Q.jsx)(Qd,{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)(Qd,{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 ef=[{label:`一对多`,value:`one-to-many`},{label:`多对多`,value:`many-to-many`},{label:`一对一`,value:`one-to-one`},{label:`多对一`,value:`many-to-one`}];function tf({schema:e}){let t=e.objectName,{object:n,metadataObject:r}=Zd(t),{refresh:i}=I(),a=Ts(),[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)(K,{size:`sm`,variant:`outline`,onClick:()=>s(e=>!e),className:`h-7 text-xs`,children:[(0,Q.jsx)(Ie,{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:ef.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)(K,{size:`sm`,variant:`ghost`,className:`h-7 text-xs`,onClick:()=>s(!1),disabled:c,children:`取消`}),(0,Q.jsxs)(K,{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:ef.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)(He,{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)(K,{size:`sm`,variant:`outline`,className:`mt-3 h-7 text-xs`,onClick:()=>s(!0),children:[(0,Q.jsx)(Ie,{className:`h-3 w-3 mr-1`}),`添加关联`]})]})]})})}function nf({schema:e}){let t=e.objectName,{fields:n}=Zd(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)(Ne,{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 rf(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)(le,{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)(bt,{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)(Hn,{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 af({schema:e}){let t=e.objectName,{object:n}=Zd(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)(Zt,{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 of(e){return e||(typeof window<`u`&&window.sessionStorage?window.sessionStorage:null)}function sf(e,t={}){let{maxHistory:n=50,persistKey:r,storage:i}=t,a=of(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 cf(){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 lf(){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 uf(){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 df(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 ff(...e){return Xr(Qr(e))}function pf({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:ff(`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 mf(...e){return Xr(Qr(e))}function hf({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:mf(`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)(zr,{className:`h-3 w-3`}):(0,Q.jsx)(Se,{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)(gf,{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 gf({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 _f(...e){return Xr(Qr(e))}function vf({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:_f(`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 yf=(0,Z.createContext)(null);yf.displayName=`CollaborationContext`;function bf(){return(0,Z.useContext)(yf)}function xf(...e){return Xr(Qr(e))}function Sf({canvas:e={width:1200,height:800,gridSize:8,showGrid:!0,snapToGrid:!0},components:t=[],palette:n=Cf,showComponentTree:r=!0,undoRedo:i=!0,propertyEditor:a=!0,readOnly:o=!1,showMinimap:s=!1,onChange:c,className:l}){let u=sf(t),d=u.current,f=(0,Z.useCallback)(e=>{u.push(e),c?.(e)},[u,c]),p=df({initialZoom:e.zoom??1}),{zoom:m}=p,h=lf(),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=uf(),y=cf(),b=bf(),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]),F=(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]),ee=(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]),I=(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]),te=(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(),F();return}if(n&&e.key===`v`&&!o){e.preventDefault(),ee();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,F,ee,d]),(0,Q.jsxs)(`div`,{ref:k,tabIndex:0,className:xf(`flex h-full w-full border rounded-lg overflow-hidden bg-background`,l),children:[!o&&(0,Q.jsx)(`div`,{className:xf(`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)(Ie,{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)(nn,{className:xf(`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:xf(`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)(Ke,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{className:xf(`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)(Ue,{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:xf(`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:F,children:(0,Q.jsx)(Ye,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{className:xf(`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:ee,children:(0,Q.jsx)(Rn,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!o&&(0,Q.jsx)(`button`,{className:xf(`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)(at,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{className:xf(`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)(kt,{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)(Ar,{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)(Ie,{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)(Fr,{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)(cr,{className:xf(`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:te,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=>I(t,e),className:xf(`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)(dr,{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)(vf,{items:R,canvasWidth:e.width,canvasHeight:e.height})]})})]}),r&&(0,Q.jsx)(`div`,{className:xf(`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:xf(`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)(hf,{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)(pf,{isOpen:y.isOpen,title:y.title,message:y.message,onConfirm:y.onConfirm,onCancel:y.onCancel})]})}var Cf=[{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 wf(e,t={}){return sf(e,t)}function Tf(...e){return Xr(Qr(e))}var Ef=[`text`,`number`,`boolean`,`date`,`datetime`,`uuid`,`email`,`url`,`phone`,`json`,`integer`,`float`,`decimal`,`currency`,`percent`,`textarea`,`select`,`multiselect`,`lookup`,`attachment`,`formula`,`autonumber`];function Df(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 Of({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=wf({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=cf(),m=lf(),h=m.count>0?Array.from(m.selectedIds)[0]:null,g=uf(),_=df({minZoom:.25,maxZoom:3,zoomStep:.1}),v=bf(),[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]),F=(0,Z.useCallback)(()=>{if(i)return;let e=l.current;f({entities:Df(e.entities),relationships:e.relationships})},[i,l,f]),ee=(0,Z.useCallback)(()=>{let e=u.filter(e=>m.isSelected(e.id));e.length>0&&g.copy(e)},[u,m,g]),I=(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]),te=(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]),ie=(0,Z.useCallback)(()=>{O(null)},[]),B=(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]),oe=(0,Z.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),V=(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]),se=h?u.find(e=>e.id===h):null,ce=se?[{name:`name`,label:`Name`,type:`text`,value:se.name,group:`General`},{name:`label`,label:`Label`,type:`text`,value:se.label,group:`General`},{name:`description`,label:`Description`,type:`textarea`,value:se.description??``,group:`General`},{name:`color`,label:`Color`,type:`color`,value:se.color??`#3b82f6`,group:`Appearance`},{name:`position.x`,label:`X Position`,type:`number`,value:se.position.x,group:`Position`},{name:`position.y`,label:`Y Position`,type:`number`,value:se.position.y,group:`Position`}]:[],le=(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(),ee()):n&&e.key===`v`?(e.preventDefault(),I()):(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,ee,I,P,m]);let ue=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:Tf(`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)(Nt,{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)(Ke,{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)(Ue,{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)(Mr,{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)(Wn,{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:ee,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)(Ye,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{onClick:I,disabled:!g.hasContent,"aria-label":`Paste`,title:`Paste (Ctrl+V)`,className:`p-1 rounded hover:bg-accent disabled:opacity-40`,children:(0,Q.jsx)(Rn,{className:`h-3.5 w-3.5`})})]}),!i&&(0,Q.jsxs)(`button`,{onClick:F,"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)(Ln,{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)(ge,{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)(Ie,{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)(He,{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:oe,onDrop:V,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:Tf(`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)(Nt,{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`&&ie()},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:Tf(`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(),B(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:Ef.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(),te(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)(Ie,{className:`h-3 w-3`}),` Add Field`]})})]},e.id))]}),x&&u.length>0&&(0,Q.jsx)(vf,{items:ue,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)(Se,{className:`h-3 w-3`}):(0,Q.jsx)(zr,{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)(hf,{title:se?se.label:`Properties`,fields:ce,onChange:le})})]}),(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)(Se,{className:`h-3 w-3`}):(0,Q.jsx)(zr,{className:`h-3 w-3`}),`Minimap`]})})]}),(0,Q.jsx)(pf,{isOpen:p.isOpen,title:p.title,message:p.message,onConfirm:p.onConfirm,onCancel:p.onCancel,destructive:!0})]})}function kf(...e){return Xr(Qr(e))}var Af=120,jf=50;function Mf(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 Nf({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=sf({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=cf(),g=lf(),_=uf(),v=df({initialZoom:1}),y=bf(),[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),F=(0,Z.useRef)(c),ee=(0,Z.useRef)(l);F.current=c,ee.current=l,(0,Z.useEffect)(()=>{F.current?.(f),ee.current?.(p)},[d.current]);let I=(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]),te=(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]),ie=(0,Z.useCallback)(()=>{s||f.length===0||m(Mf(f,p),p)},[f,p,s,m]),B=(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]),oe=(0,Z.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),V=(0,Z.useMemo)(()=>f.find(e=>e.id===b)??null,[f,b]),se=(0,Z.useMemo)(()=>V?[{name:`label`,label:`Name`,type:`text`,value:V.label,group:`General`},{name:`type`,label:`Type`,type:`select`,value:V.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:V.description??``,group:`General`}]:[],[V]),ce=(0,Z.useCallback)((e,t)=>{s||!b||m(f.map(n=>n.id===b?{...n,[e]:t}:n),p)},[s,b,f,p,m]),le=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:Af,height:jf,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(),te(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,te,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:kf(`flex flex-col h-full w-full border rounded-lg overflow-hidden bg-background`,u),children:[(0,Q.jsx)(pf,{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)(pn,{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)(Ke,{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)(Ue,{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)(Ye,{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)(Rn,{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:kf(`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)(ut,{className:`h-3 w-3`}),` Connect`]}),(0,Q.jsxs)(`button`,{onClick:ie,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)(_t,{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)(Mr,{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)(Wn,{className:`h-3 w-3`})}),(0,Q.jsx)(`div`,{className:`w-px h-4 bg-border mx-1`}),(0,Q.jsxs)(`button`,{onClick:()=>I(`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)(Bt,{className:`h-3 w-3 text-green-600`}),` Start`]}),(0,Q.jsxs)(`button`,{onClick:()=>I(`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)(In,{className:`h-3 w-3 text-blue-600`}),` Task`]}),(0,Q.jsxs)(`button`,{onClick:()=>I(`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)(Re,{className:`h-3 w-3 text-yellow-600`}),` Gateway`]}),(0,Q.jsxs)(`button`,{onClick:()=>I(`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)(In,{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)(cr,{className:`h-3 w-3`}):(0,Q.jsx)(yr,{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:oe,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+Af/2;let r=t.position.y+jf/2;n.position.x+Af/2;let i=n.position.y+jf/2,a=t.position.x+Af,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=>B(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:kf(`flex items-center justify-center border-2 min-w-[120px] min-h-[50px] px-3 py-2 transition-shadow`,le(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:kf(`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:jf/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:jf/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:Af/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:Af/2-6,bottom:-6},title:`Port`,onClick:t=>{t.stopPropagation(),z(e.id)}})]}),!s&&t&&!S&&(0,Q.jsx)(`button`,{onClick:t=>{t.stopPropagation(),te(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)(vf,{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)(hf,{title:V?`Properties: ${V.label}`:`Properties`,fields:se,onChange:ce})})]})]})}function Pf(...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`},Ff={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}},If=[{type:`header`,height:80,elements:[]},{type:`detail`,height:400,elements:[],repeat:!0},{type:`footer`,height:60,elements:[]}];function Lf({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=sf(a.length>0?a:If),f=d.current,p=(0,Z.useCallback)(e=>{d.push(e),l?.(e)},[d,l]),m=lf(),h=(0,Z.useMemo)(()=>{let e=Array.from(m.selectedIds);return e.length>0?e[0]:null},[m.selectedIds]),g=uf(),_=cf(),v=bf(),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=Ff[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]),F=(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]),ee=(0,Z.useCallback)(e=>{e.preventDefault(),e.dataTransfer.dropEffect=`move`},[]),I=(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]),te=(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:Pf(`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)(Tt,{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:Pf(`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)(Ke,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{className:Pf(`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)(Ue,{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:Pf(`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)(Ye,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{className:Pf(`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)(Rn,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`w-px h-5 bg-border mx-1`})]}),!c&&(0,Q.jsx)(`button`,{className:Pf(`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)(cr,{className:Pf(`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:ee,onDrop:e=>I(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)($e,{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)(Ie,{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)(Hn,{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=>F(n,e,t),className:Pf(`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:Pf(`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)(hf,{title:`${$.properties} – ${O.type}`,fields:te,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)(pf,{isOpen:_.isOpen,title:_.title,message:_.message,onConfirm:_.onConfirm,onCancel:_.onCancel})]})}var Rf={"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 zf(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 Bf(){try{let e=V();return e.t(`appDesigner.basicInfo`)===`appDesigner.basicInfo`?{t:zf(Rf)}:{t:e.t}}catch{return{t:zf(Rf)}}}function Vf(...e){return Xr(Qr(e))}var Hf={name:``,title:``,description:``,icon:``,template:``,layout:`sidebar`,objects:[],navigation:[],branding:{logo:``,primaryColor:`#3b82f6`,favicon:``}};function Uf(e){return e.filter(e=>e.selected).map(e=>({id:e.name,type:`object`,label:e.label,icon:e.icon,objectName:e.name}))}var Wf=0;function Gf(e){return Wf+=1,`${e}_${Date.now()}_${Wf}`}function Kf({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:Vf(`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:Vf(`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:Vf(`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)(Ir,{className:`h-4 w-4`}):r+1}),(0,Q.jsx)(`span`,{className:Vf(`text-xs font-medium`,a?`text-blue-600`:`text-gray-500`),children:e.label})]})]},e.id)})})}function qf({draft:e,templates:t,readOnly:n,onChange:r,t:i}){let a=e.name.length>0&&!z(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:Vf(`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:Yn},{value:`header`,labelKey:`appDesigner.layoutHeader`,Icon:_t},{value:`empty`,labelKey:`appDesigner.layoutEmpty`,Icon:Ze}].map(({value:t,labelKey:a,Icon:o})=>(0,Q.jsxs)(`label`,{"data-testid":`app-layout-${t}`,className:Vf(`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 Jf({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)(wt,{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:Vf(`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:Vf(`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)(Ir,{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 Yf={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 Xf({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)(kn,{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)(ut,{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)(Ar,{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`):ne(n.label)}),(0,Q.jsx)(`span`,{className:Vf(`rounded-full px-2 py-0.5 text-[10px] font-medium`,Yf[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)(cn,{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)(Se,{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 Zf({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)(pr,{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)(rn,{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 Qf({availableObjects:e=[],templates:t=[],initialDraft:n,onComplete:r,onCancel:i,onSaveDraft:a,readOnly:o=!1,className:s}){let{t:c}=Bf(),l=cf(),[u,d]=(0,Z.useState)(0),[f,p]=(0,Z.useState)(``),[m,h]=(0,Z.useState)(()=>({...Hf,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&&z(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:Gf(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:Uf(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:Uf(e.objects)})),d(e))},[u,b]);return(0,Q.jsxs)(`div`,{className:Vf(`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)(Kf,{steps:g,currentIndex:u,onStepClick:N})}),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-y-auto p-6`,children:[u===0&&(0,Q.jsx)(qf,{draft:m,templates:t,readOnly:o,onChange:x,t:c}),u===1&&(0,Q.jsx)(Jf,{objects:m.objects,readOnly:o,onToggle:C,onToggleAll:w,search:f,onSearchChange:p,t:c}),u===2&&(0,Q.jsx)(Xf,{items:m.navigation,readOnly:o,onAdd:T,onRemove:E,onReorder:D,t:c}),u===3&&(0,Q.jsx)(Zf,{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)(Dt,{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)(Ir,{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)(zr,{className:`h-4 w-4`})]})]})]})]})}function $f(...e){return Xr(Qr(e))}var ep=0;function tp(e){return ep+=1,`${e}_${Date.now()}_${ep}`}var np={object:{labelKey:`appDesigner.navTypeObject`,color:`bg-green-100 text-green-700`,Icon:Nt},dashboard:{labelKey:`appDesigner.navTypeDashboard`,color:`bg-amber-100 text-amber-700`,Icon:ve},page:{labelKey:`appDesigner.navTypePage`,color:`bg-teal-100 text-teal-700`,Icon:Tt},report:{labelKey:`appDesigner.navTypeReport`,color:`bg-rose-100 text-rose-700`,Icon:Hn},url:{labelKey:`appDesigner.navTypeUrl`,color:`bg-sky-100 text-sky-700`,Icon:ut},group:{labelKey:`appDesigner.navTypeGroup`,color:`bg-purple-100 text-purple-700`,Icon:kn},separator:{labelKey:`appDesigner.navTypeSeparator`,color:`bg-gray-100 text-gray-600`,Icon:Ar},action:{labelKey:`appDesigner.navTypeAction`,color:`bg-orange-100 text-orange-700`,Icon:rr}},rp=[{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 ip({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)(ne(e.label)??``),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(e.icon||``),C=np[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(ne(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:$f(`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)(dr,{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)(Se,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(zr,{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)(qt,{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(ne(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:$f(`flex-1 truncate text-sm text-gray-800`,!i&&`cursor-text`),onDoubleClick:()=>{!i&&e.type!==`separator`&&(v(ne(e.label)??``),g(!0))},children:ne(e.label)}),(0,Q.jsx)(`span`,{className:$f(`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)(pt,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(at,{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)(Ie,{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)(cn,{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)(Se,{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)(ip,{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 ap({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)(op,{item:e,depth:0},e.id))})]})}function op({item:e,depth:t}){let n=np[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:ne(e.label)})]}),e.type===`group`&&e.children?.map(e=>(0,Q.jsx)(op,{item:e,depth:t+1},e.id))]})}function sp({items:e,onChange:t,readOnly:n=!1,showPreview:r=!0,className:i,onExport:a,onImport:o}){let{t:s}=Bf(),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:tp(r),type:r,label:r===`separator`?``:`New ${s(np[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:tp(n),type:n,label:n===`separator`?``:`New ${s(np[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:$f(`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:[rp.map(({type:e,labelKey:t})=>{let{Icon:r,color:i}=np[e];return(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`nav-designer-add-${e}`,onClick:()=>_(e),disabled:n,className:$f(`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)(Ie,{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)(qr,{className:`h-3 w-3`}),s(`appDesigner.navExportSchema`)]}),(0,Q.jsxs)(`label`,{"data-testid":`nav-designer-import`,className:$f(`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)(mt,{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)(ip,{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)(ap,{items:e,t:s})]})}function cp(...e){return Xr(Qr(e))}var lp=[{type:`metric`,label:`KPI Metric`,Icon:Jr},{type:`bar`,label:`Bar Chart`,Icon:Hn},{type:`line`,label:`Line Chart`,Icon:_e},{type:`pie`,label:`Pie Chart`,Icon:W},{type:`table`,label:`Table`,Icon:vt},{type:`grid`,label:`Grid`,Icon:Gr}],up=0;function dp(){return up+=1,`widget_${Date.now()}_${up}`}function fp({widget:e,index:t,total:n,selected:r,readOnly:i,onSelect:a,onRemove:o,onMoveUp:s,onMoveDown:c}){let l=e.type||`metric`,u=lp.find(e=>e.type===l)||lp[0];return(0,Q.jsxs)(`div`,{"data-testid":`dashboard-widget-${e.id}`,onClick:a,className:cp(`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)(dr,{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)(cn,{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)(Se,{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 pp({widget:e,readOnly:t,onChange:n,onClose:r}){let{t:i}=Bf();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:lp.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 mp({schema:e}){let{t}=Bf(),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=lp.find(t=>t.type===(e.type||`metric`))||lp[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 hp({schema:e,onChange:t,readOnly:n=!1,className:r,onExport:i,onImport:a,selectedWidgetId:o,onWidgetSelect:s}){let{t:c}=Bf(),[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}=sf(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=dp(),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:cp(`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)(pp,{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`),`:`]}),lp.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)(Ke,{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)(Ue,{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)(qr,{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)(mt,{className:`h-4 w-4`})}),(0,Q.jsx)(`button`,{type:`button`,"data-testid":`dashboard-preview-toggle`,onClick:()=>f(e=>!e),className:cp(`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)(pt,{className:`h-4 w-4`}):(0,Q.jsx)(at,{className:`h-4 w-4`})})]})]}),d?(0,Q.jsx)(mp,{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)(fp,{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 gp(...e){return Xr(Qr(e))}var _p=[{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`}],vp=[`Inter`,`Roboto`,`Open Sans`,`Lato`,`Montserrat`,`Poppins`,`Source Sans Pro`,`Noto Sans`,`system-ui`];function yp({branding:e,onChange:t,appTitle:n=`My App`,readOnly:r=!1,className:i,onExport:a,onImport:o}){let{t:s}=Bf(),[c,l]=(0,Z.useState)(`light`),{current:u,push:d,canUndo:f,canRedo:p,undo:m,redo:h}=sf(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:gp(`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:gp(`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)(Ke,{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:gp(`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)(Ue,{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)(qr,{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:gp(`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)(mt,{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)(pr,{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:_p.map(e=>(0,Q.jsx)(`button`,{"data-testid":`branding-swatch-${e.hex.slice(1)}`,type:`button`,onClick:()=>!r&&_({primaryColor:e.hex}),disabled:r,className:gp(`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)(rn,{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)($e,{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`)}),vp.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:gp(`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)(fe,{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:gp(`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)(jn,{className:`h-3.5 w-3.5`}),s(`appDesigner.modeDark`)]})]})]}),(0,Q.jsxs)(`div`,{"data-testid":`branding-preview`,className:gp(`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:gp(`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:gp(`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:gp(`text-xs`,S?`text-gray-400`:`text-gray-500`),children:`Favicon`})]}),u.fontFamily&&(0,Q.jsxs)(`div`,{className:gp(`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:gp(`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:gp(`h-2 w-3/4 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Q.jsx)(`div`,{className:gp(`h-2 w-1/2 rounded`,S?`bg-gray-700`:`bg-gray-200`)}),(0,Q.jsx)(`div`,{className:gp(`h-2 w-2/3 rounded`,S?`bg-gray-700`:`bg-gray-200`)})]})]})]})]})]})}function bp(...e){return Xr(Qr(e))}var xp=[`Custom Objects`,`System Objects`,`Integration`,`Analytics`],Sp=[`Box`,`Database`,`Users`,`FileText`,`Settings`,`ShoppingCart`,`Calendar`,`Mail`,`Briefcase`,`Building`,`Globe`,`Heart`,`Star`,`Tag`,`Bookmark`,`Folder`,`Archive`,`Package`,`Truck`,`CreditCard`];function Cp({objects:e,onObjectsChange:t,onSelectObject:n,showSystemObjects:r=!0,readOnly:i=!1,className:a}){let{t:o}=Bf(),s=cf(),[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 A({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:Sp.map(e=>({label:e,value:e})),disabled:i},{name:`group`,label:o(`appDesigner.objectManager.group`),type:`select`,options:xp.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:bp(`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)(Nt,{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)(da,{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)(pf,{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 wp(...e){return Xr(Qr(e))}var Tp={text:{label:`Text`,Icon:$e},textarea:{label:`Text Area`,Icon:Tt},number:{label:`Number`,Icon:xn},boolean:{label:`Checkbox`,Icon:Pt},date:{label:`Date`,Icon:ot},datetime:{label:`Date/Time`,Icon:ot},time:{label:`Time`,Icon:ot},select:{label:`Picklist`,Icon:rt},email:{label:`Email`,Icon:Kt},phone:{label:`Phone`,Icon:or},url:{label:`URL`,Icon:rn},password:{label:`Password`,Icon:U},currency:{label:`Currency`,Icon:xn},percent:{label:`Percent`,Icon:xn},lookup:{label:`Lookup`,Icon:He},formula:{label:`Formula`,Icon:Xt},autonumber:{label:`Auto Number`,Icon:xn},file:{label:`File`,Icon:Tt},image:{label:`Image`,Icon:Ut},markdown:{label:`Markdown`,Icon:Tt},html:{label:`Rich Text`,Icon:Tt},color:{label:`Color`,Icon:pr},code:{label:`Code`,Icon:Xt},location:{label:`Location`,Icon:Oe},address:{label:`Address`,Icon:Oe},rating:{label:`Rating`,Icon:Xn},slider:{label:`Slider`,Icon:gn}},Ep={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`]},Dp=[`text`,`number`,`date`,`choice`,`relation`,`advanced`];function Op({objectName:e,fields:t,onFieldsChange:n,readOnly:r=!1,className:i}){let{t:a}=Bf(),o=cf(),[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 A({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)(()=>Dp.map(e=>({category:e,label:a(`appDesigner.fieldDesigner.typeCategory.${e}`),options:Ep[e].map(e=>({label:Tp[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:wp(`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)(Gt,{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)(da,{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)(pf,{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 kp=`objectui-app-wizard-draft`;function Ap(){let e=_(),{appName:t}=o(),{objects:n,refresh:r}=I(),i=ce(),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(kp);if(e)return JSON.parse(e)}catch{}},[]),c=(0,Z.useCallback)(async t=>{try{let n=R(t),a=i?.getClient();a&&await a.meta.saveItem(`app`,t.name,n),localStorage.removeItem(kp),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(kp,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)(Qf,{availableObjects:a,initialDraft:s(),onComplete:c,onCancel:l,onSaveDraft:u})})}function jp(){let e=_(),{appName:t,editAppName:n}=o(),{apps:r,objects:i,refresh:a}=I(),s=ce(),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=R(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)(Qf,{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 Mp(){let e=_(),{dashboardName:t}=o(),n=ce(),{dashboards:r,refresh:i}=I(),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)(lr,{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)(hp,{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 Np=t({AppCreationWizard:()=>Qf,BrandingEditor:()=>yp,CreateAppPage:()=>Ap,DashboardDesignPage:()=>Mp,DashboardEditor:()=>hp,DataModelDesigner:()=>Of,EditAppPage:()=>jp,FieldDesigner:()=>Op,NavigationDesigner:()=>sp,ObjectManager:()=>Cp,PageDesigner:()=>Sf,ProcessDesigner:()=>Nf,ReportDesigner:()=>Lf});B.register(`page-designer`,Sf,{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`,Of,{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`,Nf,{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`,Lf,{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`,Qf,{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`,sp,{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`,hp,{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`,yp,{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`,Cp,{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`,Op,{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 Pp(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 Fp(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 Ip=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=Pp(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(Fp)};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 Lp({schema:e}){let t=e.objectName,{objects:n,refresh:r}=I(),i=Ts(),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(Xd):[],[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=Ip.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)(en,{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)(Op,{objectName:t,fields:d,onFieldsChange:p})]})}function Rp({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)($n,{value:n,onValueChange:r,className:`w-full`,children:[(0,Q.jsxs)(zn,{className:`w-full justify-start border-b rounded-none bg-transparent p-0 h-auto`,children:[(0,Q.jsxs)(an,{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)(sn,{className:`h-4 w-4 mr-2`}),`详情`]}),(0,Q.jsxs)(an,{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)(Gt,{className:`h-4 w-4 mr-2`}),`字段`]}),(0,Q.jsxs)(an,{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)(He,{className:`h-4 w-4 mr-2`}),`关联关系`]}),(0,Q.jsxs)(an,{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)(Zt,{className:`h-4 w-4 mr-2`}),`数据`]})]}),(0,Q.jsx)(fr,{value:`details`,className:`mt-6`,children:(0,Q.jsx)(`div`,{className:`space-y-6`,children:(0,Q.jsx)(M,{schema:i})})}),(0,Q.jsx)(fr,{value:`fields`,className:`mt-6`,children:(0,Q.jsx)(`div`,{className:`space-y-6`,children:(0,Q.jsx)(M,{schema:a})})}),(0,Q.jsx)(fr,{value:`relationships`,className:`mt-6`,children:(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsx)(M,{schema:o}),(0,Q.jsx)(M,{schema:s})]})}),(0,Q.jsx)(fr,{value:`data`,className:`mt-6`,children:(0,Q.jsxs)(`div`,{className:`space-y-6`,children:[(0,Q.jsx)(M,{schema:l}),(0,Q.jsx)(M,{schema:c})]})})]})})}var zp={namespace:`console`,category:`system`};B.register(`object-detail-tabs`,Rp,{...zp,label:`Object Detail Tabs`,icon:`LayoutDashboard`}),B.register(`object-properties`,$d,{...zp,label:`Object Properties`,icon:`Settings2`}),B.register(`object-relationships`,tf,{...zp,label:`Object Relationships`,icon:`Link2`}),B.register(`object-keys`,nf,{...zp,label:`Object Keys`,icon:`KeyRound`}),B.register(`object-data-experience`,rf,{...zp,label:`Data Experience`,icon:`LayoutList`}),B.register(`object-data-preview`,af,{...zp,label:`Data Preview`,icon:`Table`}),B.register(`object-field-designer`,Lp,{...zp,label:`Field Designer`,icon:`Columns`});var Bp=(0,Z.lazy)(()=>u(()=>import(`./ApiConsolePage-C6tVqeCx.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),Vp=(0,Z.lazy)(()=>u(()=>import(`./FlowRunsPage-CATcsy8B.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),Hp=(0,Z.lazy)(()=>u(()=>import(`./PublicFormsPage-Bhp5KfIY.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function Up({label:e}){return(0,Q.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}tu({ref:`developer:api-console`,label:`API Console`,source:`@objectstack/console`,component:e=>(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Up,{label:`API console`}),children:(0,Q.jsx)(Bp,{...e})})}),tu({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@objectstack/console`,component:e=>(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Up,{label:`flow runs`}),children:(0,Q.jsx)(Vp,{...e})})}),tu({ref:`developer:public-forms`,label:`Public Forms`,source:`@objectstack/console`,component:e=>(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Up,{label:`public forms`}),children:(0,Q.jsx)(Hp,{...e})})});var Wp=(0,Z.lazy)(()=>u(()=>import(`./ProfilePage-BBeI_CPu.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function Gp({label:e}){return(0,Q.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}tu({ref:`account:profile_card`,label:`My Profile`,source:`@objectstack/console`,component:e=>(0,Q.jsx)(Z.Suspense,{fallback:(0,Q.jsx)(Gp,{label:`profile`}),children:(0,Q.jsx)(Wp,{...e})})});var Kp=`/api/v1/auth`;$o(),B.registerLazy(`object-map`,()=>u(()=>import(`./plugin-map-B-PDDoET.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),B.registerLazy(`map`,()=>u(()=>import(`./plugin-map-B-PDDoET.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-DJturdHm.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});B.registerLazy(`chart`,()=>u(()=>import(`./plugin-charts-Ck5EMx6H.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-Ck5EMx6H.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});B.registerLazy(`object-gantt`,()=>u(()=>import(`./plugin-gantt-DO7NQ-4h.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),B.registerLazy(`gantt`,()=>u(()=>import(`./plugin-gantt-DO7NQ-4h.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),B.registerLazy(`markdown`,()=>u(()=>import(`./plugin-markdown--e1MOP0x.js`).then(e=>e.n),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),B.registerLazy(`object-timeline`,()=>u(()=>import(`./plugin-timeline-Dmqt8jd_.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),B.registerLazy(`timeline`,()=>u(()=>import(`./plugin-timeline-Dmqt8jd_.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),B.registerLazy(`object-calendar`,()=>u(()=>import(`./plugin-calendar-BWXBFRkE.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),B.registerLazy(`calendar`,()=>u(()=>import(`./plugin-calendar-BWXBFRkE.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),B.registerLazy(`calendar-view`,()=>u(()=>import(`./plugin-calendar-BWXBFRkE.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),B.registerLazy(`object-kanban`,()=>u(()=>import(`./plugin-kanban-DTWtfUzv.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),B.registerLazy(`kanban`,()=>u(()=>import(`./plugin-kanban-DTWtfUzv.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-DTWtfUzv.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});B.registerLazy(`report`,()=>u(()=>import(`./plugin-report-BTvuqkOa.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-BTvuqkOa.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});st();var qp=``.replace(/\/+$/,``);Promise.all([ra(qp),Jd(Kp)]).finally(()=>{ka.createRoot(document.getElementById(`root`)).render((0,Q.jsx)(Z.StrictMode,{children:(0,Q.jsx)(ua,{pwa:{enabled:!0,name:aa(),shortName:oa()},children:(0,Q.jsx)(ae,{loadLanguage:Gd,children:(0,Q.jsx)(Wd,{})})})}))});export{tc as a,Ys as i,nu as n,Js as o,vl as r,td as t};
|