@objectstack/console 10.3.0 → 11.1.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.
Files changed (116) hide show
  1. package/dist/assets/{AdapterProvider-BNg96rLB.js → AdapterProvider-BTAMdG2T.js} +1 -1
  2. package/dist/assets/{AiPendingActionsPage-DX6zBTm5.js → AiPendingActionsPage-BtiQFQw8.js} +1 -1
  3. package/dist/assets/ApiConsolePage-CQJbzAsw.js +1 -0
  4. package/dist/assets/{AppDocsIndex-CFievvEN.js → AppDocsIndex-CbHC6KGX.js} +1 -1
  5. package/dist/assets/AppManagementPage-DOoQrTPO.js +1 -0
  6. package/dist/assets/ApprovalsInboxPage-D6eWYxCu.js +1 -0
  7. package/dist/assets/AuditLogPage-F85cQBBY.js +1 -0
  8. package/dist/assets/{ComponentNavView-BlIradDc.js → ComponentNavView-g9qw3mhW.js} +1 -1
  9. package/dist/assets/ConsoleFloatingChatbot-Cy-Ny_TS.js +1 -0
  10. package/dist/assets/DashboardView-mIWO-jW_.js +1 -0
  11. package/dist/assets/DashboardWidgetInspector-DOnyBhGN.js +1 -0
  12. package/dist/assets/{DeveloperHubPage-CQ2_nCOl.js → DeveloperHubPage-Ci0wA8GZ.js} +1 -1
  13. package/dist/assets/ExpressionProvider-NqLS0ljf.js +1 -0
  14. package/dist/assets/FlowRunsPage-CNz2_VFK.js +1 -0
  15. package/dist/assets/{IntegrationsPage-Ch5OmIKz.js → IntegrationsPage-CAZ3nsKJ.js} +2 -2
  16. package/dist/assets/{InterfaceListPage-B5-dEiYQ.js → InterfaceListPage-D1BbH0Iy.js} +1 -1
  17. package/dist/assets/{ManagedByBadge-DdytxDlp.js → ManagedByBadge-6DwSVsdr.js} +1 -1
  18. package/dist/assets/{MarketplaceAccessDenied-BRaR8_1a.js → MarketplaceAccessDenied-Cyx7lSjy.js} +1 -1
  19. package/dist/assets/{MarketplaceInstalledPage-BtW9YVL_.js → MarketplaceInstalledPage-C41H1YlB.js} +1 -1
  20. package/dist/assets/MarketplacePackagePage-Bihb2q1b.js +4 -0
  21. package/dist/assets/MarketplacePage-C2B6TMNM.js +1 -0
  22. package/dist/assets/MetadataInspector-COEBMw6y.js +1 -0
  23. package/dist/assets/{MetadataProvider-QdHbK1P5.js → MetadataProvider-D234gTjV.js} +1 -1
  24. package/dist/assets/PageView-DuiaqvzN.js +1 -0
  25. package/dist/assets/ProfilePage-B1oCou0F.js +1 -0
  26. package/dist/assets/{PublicFormsPage-Dc2X36T6.js → PublicFormsPage-C2prdsH6.js} +1 -1
  27. package/dist/assets/RecordDetailView-B-AuOKPI.js +9 -0
  28. package/dist/assets/{RecordFormPage-Hs6Ml27g.js → RecordFormPage-CpKMoOCj.js} +1 -1
  29. package/dist/assets/ReportDefaultInspector-DxP-Ac7I.js +11 -0
  30. package/dist/assets/{ReportView-BM3Ai6gG.js → ReportView-Cw9Ompki.js} +1 -1
  31. package/dist/assets/{SearchResultsPage-CmNe7LEF.js → SearchResultsPage-CZ038ncU.js} +1 -1
  32. package/dist/assets/{SettingsHub-E8tuZ4eC.js → SettingsHub-BXe-fVlJ.js} +1 -1
  33. package/dist/assets/{SettingsView-Zy-v0lBl.js → SettingsView-DxPgTnlF.js} +1 -1
  34. package/dist/assets/{SystemHubPage-BAzCcy5f.js → SystemHubPage-CJq_1ITt.js} +1 -1
  35. package/dist/assets/{data-adapter-dGnCpoPP.js → data-adapter-02g96tfY.js} +1 -1
  36. package/dist/assets/exceljs.min-HZhgX9lC.js +28 -0
  37. package/dist/assets/framework-h98DIM1k.js +35 -0
  38. package/dist/assets/{highlighted-body-OFNGDK62-DQgrzYjA.js → highlighted-body-OFNGDK62-DO9p_wSr.js} +1 -1
  39. package/dist/assets/index-BQhiWf8_.js +2 -0
  40. package/dist/assets/index-WhD62Q-7.css +2 -0
  41. package/dist/assets/infrastructure-B1z73d-r.js +3 -0
  42. package/dist/assets/{marketplaceApi-BEwXWaVr.js → marketplaceApi-B_Gmytip.js} +1 -1
  43. package/dist/assets/mermaid-GHXKKRXX-DEmtnxCC.js +1 -0
  44. package/dist/assets/metadata-admin-DStYGsRM.js +22 -0
  45. package/dist/assets/plugin-calendar-BYmYEyQk.js +1 -0
  46. package/dist/assets/plugin-charts-BDFf0TCn.js +7 -0
  47. package/dist/assets/plugin-chatbot-CnuZn8AC.js +120 -0
  48. package/dist/assets/plugin-dashboard-CuwYQhsg.js +6 -0
  49. package/dist/assets/plugin-form-CH8ruD9E.js +1 -0
  50. package/dist/assets/plugin-gantt-BB8ZeREv.js +93 -0
  51. package/dist/assets/plugin-grid-D414NLNP.js +6 -0
  52. package/dist/assets/plugin-kanban-BRFJEEAA.js +1 -0
  53. package/dist/assets/plugin-map-rEWoyyKa.js +1 -0
  54. package/dist/assets/{plugin-markdown-4BcL1bu0.js → plugin-markdown-BgV76qm3.js} +1 -1
  55. package/dist/assets/plugin-report-C-YPOtvZ.js +59 -0
  56. package/dist/assets/{plugin-timeline-C2lZtCO1.js → plugin-timeline-CC91-fmI.js} +1 -1
  57. package/dist/assets/plugin-tree-D2QWz1x1.js +1 -0
  58. package/dist/assets/plugin-view-C6iEzx93.js +1 -0
  59. package/dist/assets/plugins-views-CcoNygsH.js +4 -0
  60. package/dist/assets/recordFormNavigation-CXt3jCB4.js +1 -0
  61. package/dist/assets/{skeletons-B4Te484-.js → skeletons-BQ5aRDUn.js} +1 -1
  62. package/dist/assets/{src-Bw-Pk_Bz.js → src-C4OnKiir.js} +1 -1
  63. package/dist/assets/src-CKHT6scJ.js +2 -0
  64. package/dist/assets/types-BUZu4QOP.js +1 -0
  65. package/dist/assets/ui-components-C9egdVxV.js +42 -0
  66. package/dist/assets/ui-layout-BwokMuBv.js +1 -0
  67. package/dist/assets/useActionModal-ChUaxcEW.js +1 -0
  68. package/dist/assets/{useOpenRecordList-D2EZK86D.js → useOpenRecordList-BkSEs2q6.js} +1 -1
  69. package/dist/assets/{useReconcileOnError-CGxw9vPi.js → useReconcileOnError-FPUCNTHc.js} +1 -1
  70. package/dist/assets/utils-6HhVlFkm.js +1 -0
  71. package/dist/assets/vendor-objectstack-BTQLr7T3.js +96 -0
  72. package/dist/index.html +4 -4
  73. package/package.json +1 -1
  74. package/LICENSE.apache +0 -202
  75. package/dist/assets/ApiConsolePage-BV6fdN_d.js +0 -1
  76. package/dist/assets/AppManagementPage-BwMda0Jw.js +0 -1
  77. package/dist/assets/ApprovalsInboxPage-CLB_n_w1.js +0 -1
  78. package/dist/assets/AuditLogPage-B5jAkCIM.js +0 -1
  79. package/dist/assets/ConsoleFloatingChatbot-Bn99Z39a.js +0 -1
  80. package/dist/assets/DashboardView-BQ1jDkNk.js +0 -1
  81. package/dist/assets/DashboardWidgetInspector-BR98NQH8.js +0 -1
  82. package/dist/assets/ExpressionProvider-Tm4jr_3p.js +0 -1
  83. package/dist/assets/FlowRunsPage-B179CDQR.js +0 -1
  84. package/dist/assets/MarketplacePackagePage-CHWrggYQ.js +0 -4
  85. package/dist/assets/MarketplacePage-D9egwY6W.js +0 -1
  86. package/dist/assets/MetadataInspector-Cx8ePTT_.js +0 -1
  87. package/dist/assets/PageView-Cz5sZQ5t.js +0 -1
  88. package/dist/assets/ProfilePage-COEmwLJ3.js +0 -1
  89. package/dist/assets/RecordDetailView-BgaxhKDF.js +0 -9
  90. package/dist/assets/ReportDefaultInspector-CoX9gMMh.js +0 -7
  91. package/dist/assets/framework-D5XqsLzE.js +0 -35
  92. package/dist/assets/index-DOshzaoZ.css +0 -2
  93. package/dist/assets/index-DnQZFTk9.js +0 -2
  94. package/dist/assets/infrastructure-HR_Bc4bJ.js +0 -3
  95. package/dist/assets/mermaid-GHXKKRXX-BhYOzfYs.js +0 -1
  96. package/dist/assets/metadata-admin-B-J5LjrF.js +0 -21
  97. package/dist/assets/plugin-calendar-BRaVMiNC.js +0 -1
  98. package/dist/assets/plugin-charts-lC1nlc8y.js +0 -7
  99. package/dist/assets/plugin-chatbot-DiZuqXNz.js +0 -120
  100. package/dist/assets/plugin-dashboard-Bru0NpLD.js +0 -6
  101. package/dist/assets/plugin-form-CnIr9O51.js +0 -1
  102. package/dist/assets/plugin-gantt-DjNJ3XF1.js +0 -93
  103. package/dist/assets/plugin-grid-CLR5UBO-.js +0 -6
  104. package/dist/assets/plugin-kanban-C_oukMvw.js +0 -1
  105. package/dist/assets/plugin-map-7UTNE-o1.js +0 -1
  106. package/dist/assets/plugin-report-DnFF3lpC.js +0 -59
  107. package/dist/assets/plugin-tree-Ch_JGKmm.js +0 -1
  108. package/dist/assets/plugin-view-XyXvMY2E.js +0 -1
  109. package/dist/assets/plugins-views-Ck67hsjt.js +0 -4
  110. package/dist/assets/src-DzwWvy9u.js +0 -2
  111. package/dist/assets/types-aLjHZGFr.js +0 -1
  112. package/dist/assets/ui-components-DiLX53DV.js +0 -42
  113. package/dist/assets/ui-layout-s7dWTKAK.js +0 -1
  114. package/dist/assets/useActionModal-DjfU9Nzh.js +0 -1
  115. package/dist/assets/utils-29quoGQV.js +0 -1
  116. package/dist/assets/vendor-objectstack-C1teU2a6.js +0 -96
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css","./index-WhD62Q-7.css"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,a as n,c as r,d as i,f as a,i as o,l as s,m as c,o as l,p as u,r as d,s as f,t as p,u as m}from"./vendor-react-ClIa1CJA.js";import{d as h,f as g,m as _,n as v,o as y}from"./infrastructure-B1z73d-r.js";import{A as b,B as x,F as S,V as C,X as w,f as T,g as E,h as D,i as O,j as k,kt as ee,o as A,s as j,wt as M,z as N}from"./framework-h98DIM1k.js";import{$a as te,As as P,At as ne,B as re,Bn as F,Bo as ie,Bt as ae,Ca as oe,Ci as I,Ct as L,D as se,Dc as ce,Dt as le,Fa as R,Fs as z,Gn as ue,Go as de,Gr as fe,Gt as pe,Hn as me,Hr as B,Hs as V,Ht as H,Ii as he,In as U,Ir as ge,Ja as _e,Jn as ve,Jo as ye,Jt as be,Kn as xe,Ko as Se,Ks as Ce,Kt as we,La as Te,Li as Ee,Ln as De,Lr as Oe,Mt as W,Na as ke,Ns as Ae,Oa as je,Oc as G,Oi as Me,Or as Ne,Ot as Pe,Pa as Fe,Pc as Ie,Po as K,Qs as Le,Ra as Re,Rn as ze,Rr as Be,S as Ve,Sa as He,Sc as Ue,Si as We,St as Ge,Ts as Ke,Tt as qe,U as Je,Un as Ye,Us as Xe,Ut as Ze,V as Qe,Va as $e,Vi as et,Vn as tt,Vr as nt,Vs as rt,Vt as q,W as it,Wn as at,Wt as ot,Xa as st,Xs as ct,Xt as lt,Yi as ut,Yt as dt,Za as ft,_a as pt,_n as mt,_o as ht,_r as gt,ai as _t,an as vt,ar as yt,bc as bt,bo as xt,bt as St,ci as Ct,cr as wt,ct as Tt,da as Et,dc as Dt,dn as Ot,do as kt,fa as At,fi as jt,fn as Mt,fr as Nt,fs as Pt,gn as Ft,gr as It,hi as Lt,hn as J,hr as Rt,hs as zt,in as Bt,io as Vt,jo as Ht,jr as Ut,ka as Wt,kt as Gt,la as Kt,lc as qt,li as Jt,lo as Yt,lt as Xt,mi as Zt,mn as Qt,mr as $t,ms as en,na as tn,oi as nn,on as rn,or as an,pi as on,pn as sn,pr as cn,ps as ln,q as un,qn as dn,qo as fn,qr as pn,qt as mn,ri as hn,sc as gn,sn as _n,so as vn,sr as yn,ss as bn,st as xn,tc as Sn,ts as Cn,ut as wn,vr as Tn,wi as En,ws as Dn,wt as On,xn as kn,xr as Y,xs as An,xt as jn,yo as Mn,yr as Nn,yt as Pn,za as X,zn as Fn,zo as In,zr as Ln,zs as Rn,zt as zn}from"./ui-components-C9egdVxV.js";import{n as Bn,r as Z}from"./vendor-ui-utils-C92Fl7BT.js";import{r as Vn}from"./data-adapter-02g96tfY.js";import{t as Hn}from"./AdapterProvider-BTAMdG2T.js";import{n as Un}from"./plugin-form-CH8ruD9E.js";import{a as Wn,i as Gn,n as Kn,r as qn,t as Jn}from"./MetadataProvider-D234gTjV.js";import{n as Yn,s as Xn}from"./assistantBus-BMrg1uLy.js";import{n as Zn,r as Qn,t as $n}from"./ExpressionProvider-NqLS0ljf.js";import{a as er,c as tr,d as nr,g as rr,h as ir,l as ar,m as or,n as sr,o as cr,p as lr,r as ur,t as dr,u as fr}from"./useReconcileOnError-FPUCNTHc.js";import{a as pr,c as mr,i as hr,o as gr,r as _r,s as vr}from"./useActionModal-ChUaxcEW.js";import{S as yr,_ as br,a as xr,b as Sr,d as Cr,f as wr,g as Tr,h as Er,i as Dr,m as Or,p as kr,t as Ar,u as jr,v as Mr,x as Nr,y as Pr}from"./plugin-chatbot-CnuZn8AC.js";import{a as Fr,c as Ir,d as Lr,i as Rr,l as zr,n as Br,o as Vr,r as Hr,s as Ur,u as Wr}from"./metadata-admin-DStYGsRM.js";import{_ as Gr,d as Kr,f as qr,g as Jr,h as Yr,m as Xr,p as Zr,t as Qr,v as $r}from"./RecordDetailView-B-AuOKPI.js";import{n as ei,r as ti,t as ni}from"./ui-layout-BwokMuBv.js";import{Q as ri,v as ii}from"./ReportDefaultInspector-DxP-Ac7I.js";import{n as ai,t as oi}from"./appRoute-D5vwtoc_.js";import{i as si,n as ci,r as li,t as ui}from"./recordFormNavigation-CXt3jCB4.js";import{n as di,t as fi}from"./utils-6HhVlFkm.js";import{n as pi,r as mi,t as hi}from"./MetadataInspector-COEBMw6y.js";import{n as gi,v as _i,x as vi,y as yi}from"./marketplaceApi-B_Gmytip.js";import{n as bi,r as xi}from"./InterfaceListPage-D1BbH0Iy.js";import{c as Si}from"./plugins-views-CcoNygsH.js";import{a as Ci,c as wi,i as Ti,l as Ei,n as Di,o as Oi,r as ki,s as Ai,t as ji,u as Mi}from"./plugin-view-C6iEzx93.js";import{i as Ni,n as Pi,r as Fi}from"./useOpenRecordList-BkSEs2q6.js";import{t as Ii}from"./ManagedByBadge-6DwSVsdr.js";import{a as Li,i as Ri,n as zi,r as Bi}from"./PageView-DuiaqvzN.js";import"./RecordFormPage-CpKMoOCj.js";import"./DashboardView-mIWO-jW_.js";import"./ReportView-Cw9Ompki.js";import"./SearchResultsPage-CZ038ncU.js";import"./MarketplacePage-C2B6TMNM.js";import"./MarketplacePackagePage-Bihb2q1b.js";import"./MarketplaceInstalledPage-C41H1YlB.js";import{n as Vi}from"./componentRegistry-ByxoJqMW.js";var Q=p(),$=e(t(),1),Hi=(0,$.createContext)({theme:`system`,setTheme:()=>null});function Ui({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`,...r}){let[i,a]=(0,$.useState)(()=>localStorage.getItem(n)||t);(0,$.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)(Hi.Provider,{...r,value:o,children:e})}var Wi=()=>{let e=(0,$.useContext)(Hi);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e},Gi=Jr();function Ki(){let{remediationRequired:e}=g();return e?(0,Q.jsx)(`div`,{className:`fixed inset-0 z-[200] flex items-center justify-center bg-background/95 p-4 backdrop-blur-sm`,children:(0,Q.jsx)(`div`,{className:`w-full max-w-md rounded-xl border bg-card p-6 shadow-xl`,children:e.code===`PASSWORD_EXPIRED`?(0,Q.jsx)(Ji,{message:e.message}):(0,Q.jsx)(Xi,{message:e.message})})}):null}function qi(){let{signOut:e}=g();return(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{e()},className:`mt-4 w-full text-center text-xs text-muted-foreground hover:text-foreground hover:underline`,children:`Sign out instead`})}function Ji({message:e}){let{changePassword:t,setRemediationRequired:n}=g(),[r,i]=(0,$.useState)(``),[a,o]=(0,$.useState)(``),[s,c]=(0,$.useState)(``),[l,u]=(0,$.useState)(!1),[d,f]=(0,$.useState)(null);return(0,Q.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),f(null),a!==s){f(`New passwords do not match.`);return}u(!0);try{await t(r,a),n(null),window.location.reload()}catch(e){f(e instanceof Error?e.message:`Could not change password.`),u(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Your password has expired`}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||`Please set a new password to continue.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Ot,{htmlFor:`rem-cur`,children:`Current password`}),(0,Q.jsx)(_n,{id:`rem-cur`,type:`password`,autoComplete:`current-password`,value:r,onChange:e=>i(e.target.value),required:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Ot,{htmlFor:`rem-new`,children:`New password`}),(0,Q.jsx)(_n,{id:`rem-new`,type:`password`,autoComplete:`new-password`,value:a,onChange:e=>o(e.target.value),required:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Ot,{htmlFor:`rem-conf`,children:`Confirm new password`}),(0,Q.jsx)(_n,{id:`rem-conf`,type:`password`,autoComplete:`new-password`,value:s,onChange:e=>c(e.target.value),required:!0})]}),d?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:d}):null,(0,Q.jsx)(Y,{type:`submit`,className:`w-full`,disabled:l,children:l?`Updating…`:`Change password & continue`}),(0,Q.jsx)(qi,{})]})}function Yi({uri:e}){let[t,n]=(0,$.useState)(null);return(0,Q.jsx)(`div`,{className:`flex justify-center rounded-md border bg-white p-3`,children:t?(0,Q.jsx)(`span`,{className:`text-sm text-destructive`,children:t}):(0,Q.jsx)(`canvas`,{ref:t=>{!t||!e||(0,Gi.toCanvas)(t,e,{width:184,margin:1},e=>{e&&n(e.message)})}})})}function Xi({message:e}){let{enrollTotp:t,verifyTotp:n,setRemediationRequired:r}=g(),[i,a]=(0,$.useState)(`password`),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(``),[u,d]=(0,$.useState)(``),[f,p]=(0,$.useState)([]),[m,h]=(0,$.useState)(!1),[_,v]=(0,$.useState)(null);return i===`password`?(0,Q.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),h(!0);try{let{totpURI:e,backupCodes:n}=await t(o);d(e),p(n??[]),a(`verify`)}catch(e){v(e instanceof Error?e.message:`Could not start enrollment.`)}finally{h(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Set up two-factor authentication`}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||`Your organization requires an authenticator app to continue.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Ot,{htmlFor:`rem-pw`,children:`Confirm your password`}),(0,Q.jsx)(_n,{id:`rem-pw`,type:`password`,autoComplete:`current-password`,value:o,onChange:e=>s(e.target.value),required:!0})]}),_?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:_}):null,(0,Q.jsx)(Y,{type:`submit`,className:`w-full`,disabled:m,children:m?`Preparing…`:`Continue`}),(0,Q.jsx)(qi,{})]}):(0,Q.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),h(!0);try{await n(c.trim()),r(null),window.location.reload()}catch(e){v(e instanceof Error?e.message:`Invalid code. Try again.`),h(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Scan with your authenticator`}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Scan this QR code with Google Authenticator, 1Password, Authy, etc., then enter the 6-digit code.`})]}),u?(0,Q.jsx)(Yi,{uri:u}):null,f.length>0?(0,Q.jsxs)(`details`,{className:`rounded-md border bg-muted/40 p-3 text-xs`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer font-medium`,children:`Save your backup codes`}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`Store these somewhere safe — each can be used once if you lose your device.`}),(0,Q.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 font-mono`,children:f.map(e=>(0,Q.jsx)(`span`,{children:e},e))})]}):null,(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Ot,{htmlFor:`rem-code`,children:`6-digit code`}),(0,Q.jsx)(_n,{id:`rem-code`,inputMode:`numeric`,autoComplete:`one-time-code`,maxLength:8,placeholder:`123456`,value:c,onChange:e=>l(e.target.value),required:!0})]}),_?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:_}):null,(0,Q.jsx)(Y,{type:`submit`,className:`w-full`,disabled:m,children:m?`Verifying…`:`Verify & continue`}),(0,Q.jsx)(qi,{})]})}function Zi(){return(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center text-sm text-muted-foreground`,children:`Loading…`})}function Qi({children:e}){return(0,Q.jsx)(Ui,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Q.jsx)(Gr,{children:(0,Q.jsx)(vr,{children:(0,Q.jsx)(_r,{children:(0,Q.jsxs)(pr,{children:[(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(Zi,{}),children:e}),(0,Q.jsx)(Ki,{})]})})})})})}function $i({children:e}){return(0,Q.jsx)(Hn,{children:(0,Q.jsx)(qn,{children:(0,Q.jsx)(ea,{children:e})})})}function ea({children:e}){let t=b(),{language:n}=O(),r=(0,$.useRef)(null);return t&&r.current!==null&&r.current!==n&&t.clearCache?.(),t&&(r.current=n),t?(0,Q.jsx)(w,{dataSource:t,children:(0,Q.jsxs)(Jn,{adapter:t,children:[(0,Q.jsx)(ta,{}),e]},n)}):(0,Q.jsx)(Zi,{})}function ta(){let{user:e}=g(),t=b(),n=mr();return(0,$.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null);return}let r=Vn({dataSource:t,userId:e.id,key:`ui.favorites`}),i=Vn({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 na({children:e}){let{activeOrganization:t,organizations:r,isOrganizationsLoading:i,getAuthConfig:a}=g(),[o,s]=(0,$.useState)(null);if((0,$.useEffect)(()=>{let e=!1;return a().then(t=>{e||s(t?.features?.multiOrgEnabled!==!1)}).catch(()=>{e||s(!1)}),()=>{e=!0}},[a]),i)return(0,Q.jsx)(Zi,{});let c=r??[];if((c.length>0||t)&&!t)return(0,Q.jsx)(n,{to:`/organizations`,replace:!0});if(c.length===0&&!t){if(o===null)return(0,Q.jsx)(Zi,{});if(o)return(0,Q.jsx)(n,{to:`/organizations`,replace:!0})}return(0,Q.jsx)(Q.Fragment,{children:e})}function ra({children:e,redirectTo:t=`/home`}){let{enabled:r,isLoading:i}=Lr();return i?(0,Q.jsx)(Zi,{}):r?(0,Q.jsx)(Q.Fragment,{children:e}):(0,Q.jsx)(n,{to:t,replace:!0})}function ia(){let e=s(),t=e.pathname.replace(/^\/system/,``);return(0,Q.jsx)(n,{to:`${t?`/apps/setup/system${t}`:`/apps/setup`}${e.search}${e.hash}`,replace:!0})}var aa=(0,$.lazy)(()=>c(()=>import(`./ConsoleFloatingChatbot-Cy-Ny_TS.js`),__vite__mapDeps([0]),import.meta.url)),oa=()=>{c(()=>import(`./ConsoleFloatingChatbot-Cy-Ny_TS.js`),__vite__mapDeps([0]),import.meta.url)};function sa(e){let[t,n]=(0,$.useState)(!1),{t:r}=O(),{openSeq:i}=Xn(),a=(0,$.useRef)(i);return(0,$.useEffect)(()=>{i!==a.current&&(a.current=i,n(!0))},[i]),t?(0,Q.jsx)($.Suspense,{fallback:null,children:(0,Q.jsx)(aa,{...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:oa,onFocus:oa,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 ca(e){let t=ri(),[n,r]=(0,$.useState)(!1);return{publishAll:(0,$.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 Z.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(xr(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?Z.warning(e(`home.pendingDrafts.probeWarn`,{defaultValue:`Published, but verification found problems.`}),{description:o[0]}):a.length>0?Z.warning(e(`home.pendingDrafts.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:a[0]}):Z.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 Z.error(`${e(`home.pendingDrafts.publishFailed`,{defaultValue:`Publish failed`})}: ${t.message}`),{ok:!1,attempted:0}}finally{r(!1)}},[t,e]),publishing:n}}async function la(){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 ua(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 da({open:e,onOpenChange:t}){let{t:n}=O(),[r,i]=(0,$.useState)(null),[a,o]=(0,$.useState)(null),s=(0,$.useCallback)(async()=>{i(null),o(null);try{let e=await la();i(e);let t=[...new Set(e.map(e=>e.type))];await Promise.all(t.map(async e=>{let t=null;try{t=await ua(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,$.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)(zn,{open:e,onOpenChange:t,children:(0,Q.jsxs)(ae,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`draft-changes-panel`,children:[(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ze,{children:n(`preview.changes.title`,{defaultValue:`Pending changes`})}),(0,Q.jsx)(q,{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)(X,{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)(In,{className:`h-3.5 w-3.5 shrink-0 text-emerald-600`}):e.kind===`update`?(0,Q.jsx)(ie,{className:`h-3.5 w-3.5 shrink-0 text-amber-600`}):(0,Q.jsx)(X,{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)(yt,{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 fa(){let e=Wn(),t=s(),n=m(),{t:r}=O(),{publishAll:i,publishing:a}=ca(r),[o,c]=(0,$.useState)(!1),[l,u]=(0,$.useState)(null);if((0,$.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=()=>{Gn();let e=new URLSearchParams(t.search);e.delete(Kn);let r=e.toString();n(`${t.pathname}${r?`?${r}`:``}${t.hash}`,{replace:!0})},f=async()=>{(await i()).ok&&(d(),setTimeout(()=>{try{window.location.reload()}catch{}},300))},p=l===0;return(0,Q.jsxs)(`div`,{className:G(`sticky top-0 z-40 border-b`,p?`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-700/60 dark:bg-slate-900/40 dark:text-slate-300`:`border-amber-300/70 bg-amber-50 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.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 text-sm`,children:[(0,Q.jsx)(de,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:p?r(`preview.draftBar.messageClean`,{defaultValue:`Draft preview — no unpublished changes; everything here is already live.`}):r(`preview.draftBar.message`,{defaultValue:`Draft preview — you are seeing unpublished changes. Nothing here is live until you publish.`})}),!p&&(0,Q.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>c(!0),"data-testid":`draft-preview-changes`,children:[(0,Q.jsx)(Mn,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.changes`,{defaultValue:`Changes`}),typeof l==`number`?` (${l})`:``]}),(0,Q.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:d,"data-testid":`draft-preview-exit`,children:[(0,Q.jsx)(Ne,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.exit`,{defaultValue:`Exit preview`})]})]}),!p&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 border-t border-amber-300/50 px-4 py-2.5 dark:border-amber-700/40`,"data-testid":`draft-preview-sample-hint`,children:[(0,Q.jsx)(Lt,{className:`h-5 w-5 shrink-0 text-amber-600 dark:text-amber-300`,"aria-hidden":`true`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-semibold leading-tight`,children:r(`preview.draftBar.sampleDataTitle`,{defaultValue:`Sample data appears once you publish`})}),(0,Q.jsx)(`p`,{className:`text-xs leading-snug text-amber-800/80 dark:text-amber-200/70`,children:r(`preview.draftBar.sampleDataBody`,{defaultValue:`You’re previewing your app’s structure. Publish to load example records and make it live.`})})]}),(0,Q.jsxs)(Y,{onClick:f,disabled:a,"data-testid":`draft-preview-publish`,className:`shrink-0 shadow-sm`,children:[(0,Q.jsx)(Ee,{className:`mr-1.5 h-4 w-4`}),a?r(`preview.draftBar.publishing`,{defaultValue:`Publishing…`}):r(`preview.draftBar.publishCta`,{defaultValue:`Publish to see it live`})]})]}),(0,Q.jsx)(da,{open:o,onOpenChange:c})]})]})}async function pa(e){let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/commits`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`commits HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.commits??n?.data?.commits??[];return(Array.isArray(r)?r:[]).map(e=>{let t=e;return{id:String(t.id),operation:t.operation===`revert`?`revert`:`apply`,message:typeof t.message==`string`?t.message:void 0,actor:typeof t.actor==`string`?t.actor:void 0,aiModel:typeof t.aiModel==`string`?t.aiModel:void 0,itemCount:typeof t.itemCount==`number`?t.itemCount:0,createdAt:typeof t.createdAt==`string`?t.createdAt:void 0}})}async function ma(e,t){let n=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/commits/${encodeURIComponent(t)}/revert`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),r=await n.json().catch(()=>null),i=r?.data??r??void 0;if(!n.ok||i?.success===!1){let e=r?.error;throw Error((typeof e==`object`?e?.message:e)??`HTTP ${n.status}`)}}function ha(e){if(!e)return``;let t=Date.parse(e);if(Number.isNaN(t))return``;let n=Math.max(0,Math.round((Date.now()-t)/1e3));if(n<60)return`${n}s`;let r=Math.round(n/60);if(r<60)return`${r}m`;let i=Math.round(r/60);return i<24?`${i}h`:`${Math.round(i/24)}d`}function ga({open:e,onOpenChange:t,packageId:n,onReverted:r}){let{t:i}=O(),[a,o]=(0,$.useState)(null),[s,c]=(0,$.useState)(null),[l,u]=(0,$.useState)(null),d=(0,$.useCallback)(async()=>{o(null),c(null);try{o(await pa(n))}catch(e){c(e.message)}},[n]);(0,$.useEffect)(()=>{e&&d()},[e,d]);let f=async e=>{u(e);try{await ma(n,e),Z.success(i(`preview.history.reverted`,{defaultValue:`Reverted — the change has been undone.`})),r?.(),await d()}catch(e){Z.error(`${i(`preview.history.revertFailed`,{defaultValue:`Revert failed`})}: ${e.message}`)}finally{u(null)}};return(0,Q.jsx)(zn,{open:e,onOpenChange:t,children:(0,Q.jsxs)(ae,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`commit-timeline-panel`,children:[(0,Q.jsxs)(H,{children:[(0,Q.jsx)(Ze,{children:i(`preview.history.title`,{defaultValue:`Build history`})}),(0,Q.jsx)(q,{children:i(`preview.history.description`,{defaultValue:`Every change to this app, newest first. Revert any step to undo it — no publish confirmation needed.`})})]}),(0,Q.jsx)(`div`,{className:`mt-4 flex flex-col gap-2 overflow-y-auto px-4 pb-6`,children:s?(0,Q.jsxs)(`p`,{className:`text-sm text-destructive`,children:[i(`preview.history.loadFailed`,{defaultValue:`Could not load history:`}),` `,s]}):a===null?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(X,{className:`h-4 w-4 animate-spin`}),i(`preview.history.loading`,{defaultValue:`Loading history…`})]}):a.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`preview.history.empty`,{defaultValue:`No history yet for this app.`})}):a.map(e=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded-md border px-2.5 py-2 text-sm`,"data-testid":`commit-row`,children:[(0,Q.jsx)(xt,{className:`mt-0.5 h-4 w-4 shrink-0 ${e.operation===`revert`?`text-muted-foreground`:`text-primary`}`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`truncate font-medium`,children:e.message??(e.operation===`revert`?i(`preview.history.revertLabel`,{defaultValue:`Reverted a change`}):i(`preview.history.applyLabel`,{defaultValue:`Build change`}))}),(0,Q.jsxs)(`p`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[e.operation===`revert`?(0,Q.jsx)(yt,{variant:`outline`,className:`border-muted-foreground/30`,children:i(`preview.history.revert`,{defaultValue:`revert`})}):null,(0,Q.jsxs)(`span`,{children:[e.itemCount,` `,i(`preview.history.items`,{defaultValue:`item(s)`})]}),e.actor?(0,Q.jsxs)(`span`,{children:[`· `,e.actor]}):null,e.createdAt?(0,Q.jsxs)(`span`,{children:[`· `,ha(e.createdAt)]}):null]})]}),e.operation===`apply`?(0,Q.jsx)(Y,{size:`sm`,variant:`ghost`,className:`shrink-0`,disabled:l!==null,onClick:()=>f(e.id),"data-testid":`commit-revert`,children:l===e.id?(0,Q.jsx)(X,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(B,{className:`mr-1 h-3.5 w-3.5`}),i(`preview.history.revertAction`,{defaultValue:`Revert`})]})}):null]},e.id))})]})})}function _a(){let e=Wn(),{appName:t}=a(),n=s(),{apps:r,refresh:i}=k(),{t:o}=O(),[c,l]=(0,$.useState)(!1),[u,d]=(0,$.useState)(!1);if(e)return null;let f=t??n.pathname.match(/\/apps\/([^/?#]+)/)?.[1];if(!f)return null;let p=ai(r??[],f);if(!p||p.hidden!==!0)return null;let m=p?.packageId??p?._packageId??null;return(0,Q.jsxs)(Q.Fragment,{children:[(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)(Se,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:o(`preview.unpublishedBar.message`,{defaultValue:`Unpublished app — fully functional, but only builders can see it. Publish to make it visible to your users.`})}),m?(0,Q.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>d(!0),"data-testid":`unpublished-app-history`,children:[(0,Q.jsx)(kt,{className:`mr-1 h-3.5 w-3.5`}),o(`preview.history.button`,{defaultValue:`History`})]}):null,(0,Q.jsxs)(Y,{size:`sm`,onClick:async()=>{l(!0);try{let e=await fetch(`/api/v1/meta/app/${encodeURIComponent(f)}`,{method:`PUT`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({...p,hidden:!1})});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message??t?.error??`HTTP ${e.status}`)}Z.success(o(`preview.unpublishedBar.published`,{defaultValue:`Published! The app is now visible to your users.`})),i?.()}catch(e){Z.error(`${o(`preview.unpublishedBar.publishFailed`,{defaultValue:`Publish failed`})}: ${e.message}`)}finally{l(!1)}},disabled:c,"data-testid":`unpublished-app-publish`,children:[(0,Q.jsx)(Ee,{className:`mr-1 h-3.5 w-3.5`}),c?o(`preview.unpublishedBar.publishing`,{defaultValue:`Publishing…`}):o(`preview.unpublishedBar.publish`,{defaultValue:`Publish`})]})]}),m?(0,Q.jsx)(ga,{open:u,onOpenChange:d,packageId:m,onReverted:i}):null]})}var va=`__all__`;function ya(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function ba(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 xa(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=ya(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 Sa(e){let[t,n]=$.useState([]),r=e.optionsSource.endpoint,i=e.optionsSource.valueKey||`id`,a=e.optionsSource.labelKey||`name`,o=e.optionsSource.filter,s=JSON.stringify(o??[]),c=$.useCallback(async()=>{try{let e=await fetch(r,{credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return;let t=ba(await e.json()),s=[],c=new Set;for(let e of t){if(!xa(e,o))continue;let t=ya(e,i);if(t==null||typeof t!=`string`||c.has(t))continue;c.add(t);let n=ya(e,a);s.push({value:t,label:typeof n==`string`&&n?n:t})}s.sort((e,t)=>e.label.localeCompare(t.label)),n(s)}catch{}},[r,i,a,s]);return $.useEffect(()=>{c();let e=()=>{c()};return window.addEventListener(`objectui:packages-changed`,e),()=>window.removeEventListener(`objectui:packages-changed`,e)},[c]),{options:t,refetch:c}}function Ca(e,t,n){let r=Array.isArray(t)?t:[],i=m(),a=s(),o=new URLSearchParams(a.search);$.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 c=$.useCallback((t,n)=>{let r=n===va?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]),l={};for(let t of r){let n=``;try{n=sessionStorage.getItem(`objectui-ctx-${e}-${t.id}`)??``}catch{}l[t.id]=(o.get(`package`)??n)||(t.allValue??``)}return{contextValues:l,element:r.length===0?null:(0,Q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(e=>(0,Q.jsx)(wa,{def:e,value:l[e.id],onChange:t=>c(e,t),t:n},e.id))})}}function wa({def:e,value:t,onChange:n,t:r}){let{options:i,refetch:a}=Sa(e),o=zr(e.icon),s=di(e.label,r)||e.id,c=s===`Package`?r?.(`common.package`,{defaultValue:s})??s:s,l=r?.(`actionDialog.selectPlaceholder`,{label:c,defaultValue:`Select ${c}…`})??`Select ${c}…`,u=!!t&&t!==(e.allValue??``);return $.useEffect(()=>{u||i.length>0&&n(i[0].value)},[u,n,i]),(0,Q.jsxs)(pe,{value:u?t:``,onValueChange:n,onOpenChange:e=>{e&&a()},children:[(0,Q.jsx)(be,{"aria-label":c,"data-testid":`package-switcher`,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)(o,{className:`h-3 w-3`})}),(0,Q.jsx)(dt,{placeholder:l,className:`truncate`})]})}),(0,Q.jsx)(we,{className:`w-[var(--radix-select-trigger-width)]`,children:i.map(e=>(0,Q.jsx)(mn,{value:e.value,children:e.label},e.value))})]})}var Ta=$.forwardRef(({className:e,onClick:t,"aria-label":n,title:r,...i},a)=>{let{toggleSidebar:o}=W(),{t:s}=O(),c=String(n||r||s(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`}));return(0,Q.jsxs)(Y,{ref:a,"data-sidebar":`trigger`,variant:`ghost`,size:`icon`,className:G(`h-7 w-7`,e),"aria-label":c,title:c,onClick:e=>{t?.(e),o()},...i,children:[(0,Q.jsx)(Kt,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:c})]})});Ta.displayName=`LocalizedSidebarTrigger`;function Ea(e){let t=`objectui-nav-order-${e}`,[n,r]=$.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=$.useCallback(e=>{r(e);try{localStorage.setItem(t,JSON.stringify(e))}catch{}},[t]);return{applyOrder:$.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:$.useCallback(e=>{let t=e.map(e=>e.id);i({...n,__root__:t})},[n,i])}}function Da(e){return e.componentRef===`metadata:directory`}function Oa(e){return e.componentRef===`developer:packages`}function ka(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 Aa({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=W(),r=s(),{t:i}=O(),{objectLabel:a,dashboardLabel:o,navGroupLabel:c,viewLabel:l}=Ie(),{context:u,currentAppName:f}=$r(),{user:p}=g(),m=h();$.useEffect(()=>{let e=0,r=t=>{e=t.touches[0].clientX},i=r=>{let i=r.changedTouches[0].clientX-e;e<30&&i>50&&t&&n(!0)};return document.addEventListener(`touchstart`,r,{passive:!0}),document.addEventListener(`touchend`,i,{passive:!0}),()=>{document.removeEventListener(`touchstart`,r),document.removeEventListener(`touchend`,i)}},[t,n]);let{recentItems:_}=gr(),{favorites:y,removeFavorite:b}=hr(),{apps:x,objects:S}=k(),C=x||[],w=C.filter(e=>e.active!==!1&&e.hidden!==!0),T=ai(C.filter(e=>e.active!==!1),e||f)||w[0],{applyOrder:E,handleReorder:D}=Ea(T?.name||`home`),{togglePin:ee,applyPins:A}=or(),j=T?.areas||[],[M,N]=$.useState(()=>j.length>0?j[0].id:null);$.useEffect(()=>{j.length>0?N(e=>j.some(t=>t.id===e)?e:j[0].id):N(null)},[T?.name,j.length]);let te=j.find(e=>e.id===M)?.navigation||T?.navigation||[],{contextValues:P,element:re}=Ca(T?.name||`home`,T?.contextSelectors,i),F=$.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(m){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-datasources`,label:i(`layout.systemNav.datasources`,{defaultValue:`Datasources`}),type:`url`,url:`/apps/setup/component/metadata/resource?type=datasource`,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,m]),ie=u===`home`?F:te,ae=u===`app`&&T?`/apps/${oi(T)}`:``,oe=u===`app`&&T?.name===`studio`,I=$.useMemo(()=>{if(!oe)return``;let e=new URLSearchParams(r.search).get(`package`)||P.active_package;return e?`?package=${encodeURIComponent(e)}`:``},[P.active_package,oe,r.search]),se=$.useMemo(()=>{if(u!==`app`||T?.name!==`studio`)return ie;let e=i(`sidebar.packageManagement`,{defaultValue:`Package management`}),t=n=>n.flatMap(n=>{if(Da(n))return[];let r=n.children?.length?t(n.children):n.children;return n.type===`group`&&r?.length===0?[]:Oa(n)?[{...n,type:`url`,label:e,url:`${ae}/component/developer/packages${I}`,children:r}]:r===n.children?[n]:[{...n,children:r}]});return t(ie).flatMap(e=>ka(e)?e.children??[]:[e])},[T?.name,ae,u,ie,I,i]),ce=$.useMemo(()=>A(E(se)),[se,E,A]),[R,z]=$.useState(!1),{evaluator:ue}=Qn(),de=$.useCallback(e=>Zn(e,ue),[ue]),{can:fe}=v(),pe=$.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return fe(n,r)}),[fe]),me=$.useMemo(()=>new Set((S||[]).map(e=>e?.name).filter(Boolean)),[S]),B=$.useCallback((e,t)=>e===`object`?me.size===0?!0:me.has(t):!0,[me]),V=oe&&r.pathname.replace(/\/+$/,``)===ae;return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(Pn,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&u===`app`&&(0,Q.jsx)(qe,{className:`border-b p-1.5`,children:(0,Q.jsx)(le,{children:(0,Q.jsx)(ne,{children:(0,Q.jsx)(Gt,{asChild:!0,className:`min-h-[44px] text-[15px] font-medium rounded-xl`,children:(0,Q.jsxs)(d,{to:`/home`,onClick:()=>n(!1),"data-testid":`mobile-sidebar-home`,children:[(0,Q.jsx)(Yt,{className:`h-5 w-5`}),(0,Q.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Q.jsx)(St,{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:[re&&(0,Q.jsx)(Ge,{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)(L,{children:re})})}),oe&&(0,Q.jsx)(Ge,{children:(0,Q.jsx)(L,{children:(0,Q.jsx)(le,{children:(0,Q.jsx)(ne,{children:(0,Q.jsx)(Gt,{asChild:!0,isActive:V,tooltip:i(`home.nav`,{defaultValue:`Home`}),children:(0,Q.jsxs)(d,{to:{pathname:ae,search:I},children:[(0,Q.jsx)(Yt,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})})}),j.length>1&&(0,Q.jsxs)(Ge,{children:[(0,Q.jsxs)(On,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(ft,{className:`h-3.5 w-3.5`}),i(`sidebar.area`,{defaultValue:`Area`})]}),(0,Q.jsx)(L,{children:(0,Q.jsx)(le,{children:j.map(e=>{let t=zr(e.icon);return(0,Q.jsx)(ne,{children:(0,Q.jsxs)(Gt,{isActive:e.id===M,tooltip:e.label,onClick:()=>N(e.id),children:[(0,Q.jsx)(t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,Q.jsx)(ni,{items:ce,basePath:ae,evaluateVisibility:de,checkPermission:pe,checkCapability:B,enablePinning:!t,onPinToggle:ee,enableReorder:!t,onReorder:D,resolveObjectLabel:(e,t)=>a({name:e,label:t}),resolveDashboardLabel:(e,t)=>o({name:e,label:t}),resolveGroupLabel:T?(e,t)=>c(T.name,e,t):void 0,resolveItemLabel:T?(e,t)=>T.name===`studio`&&t===i(`sidebar.packageManagement`,{defaultValue:`Package management`})?t:c(T.name,e,t):void 0,resolveViewLabel:(e,t,n)=>l(e,t,n),t:i,templateContext:{currentUserId:p?.id??null,contextValues:P}}),_.length>0&&(0,Q.jsxs)(Ge,{children:[(0,Q.jsxs)(On,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>z(e=>!e),children:[(0,Q.jsx)(Rn,{className:`h-3 w-3 transition-transform duration-150 ${R?`rotate-90`:``}`}),(0,Q.jsx)(zt,{className:`h-3.5 w-3.5`}),i(`sidebar.recent`,{defaultValue:`Recent`})]}),R&&(0,Q.jsx)(L,{children:(0,Q.jsx)(le,{children:_.slice(0,5).map(e=>(0,Q.jsx)(ne,{children:(0,Q.jsx)(Gt,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(d,{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))})})]}),y.some(e=>e.type!==`nav`)&&(0,Q.jsxs)(Ge,{children:[(0,Q.jsxs)(On,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(Ct,{className:`h-3.5 w-3.5`}),i(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Q.jsx)(L,{children:(0,Q.jsx)(le,{children:y.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Q.jsxs)(ne,{children:[(0,Q.jsx)(Gt,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(d,{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)(Pe,{showOnHover:!0,onClick:t=>{t.stopPropagation(),b(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(Jt,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ge,{children:(0,Q.jsx)(L,{children:(0,Q.jsx)(le,{children:F.map(e=>{let t=zr(e.icon),n=r.pathname===e.url;return(0,Q.jsx)(ne,{children:(0,Q.jsx)(Gt,{asChild:!0,tooltip:e.label,isActive:n,children:(0,Q.jsxs)(d,{to:e.url||`/home`,children:[(0,Q.jsx)(t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:e.label})]})})},e.id)})})})}),y.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,Q.jsxs)(Ge,{children:[(0,Q.jsxs)(On,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(Ct,{className:`h-3.5 w-3.5`}),i(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Q.jsx)(L,{children:(0,Q.jsx)(le,{children:y.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Q.jsxs)(ne,{children:[(0,Q.jsx)(Gt,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(d,{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)(Pe,{showOnHover:!0,onClick:t=>{t.stopPropagation(),b(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(Jt,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Q.jsx)(jn,{className:`border-t p-1`,children:(0,Q.jsx)(Ta,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function ja(){let{theme:e,setTheme:t}=Wi(),{t:n}=O();return(0,Q.jsxs)(Mt,{children:[(0,Q.jsx)(kn,{asChild:!0,children:(0,Q.jsxs)(Y,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(_t,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Q.jsx)(He,{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)(sn,{align:`end`,children:[(0,Q.jsxs)(J,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Q.jsx)(_t,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(J,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Q.jsx)(He,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(J,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Q.jsx)(oe,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}function Ma(){let e=document.querySelector(`base`)?.getAttribute(`href`);return e?new URL(e,window.location.origin):new URL(`/`,window.location.origin)}function Na(e){return e===void 0?Ma().toString():new URL(`.`,e).toString()}function Pa(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Fa({name:e}){return(0,Q.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded bg-muted text-[10px] font-semibold text-muted-foreground`,children:Pa(e)})}function Ia(){let{t:e}=O(),t=m(),{organizations:n,activeOrganization:r,switchOrganization:i,getAuthConfig:a}=g(),[o,s]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=!1;return a?.().then(t=>{e||s(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[a]);let c=n??[],l=r??c[0]??null;if(!l)return null;if(c.length<=1)return(0,Q.jsxs)(`span`,{className:`ml-2 hidden max-w-[12rem] items-center gap-1.5 sm:inline-flex`,"data-testid":`workspace-name`,children:[(0,Q.jsx)(Fa,{name:l.name}),(0,Q.jsx)(`span`,{className:`truncate text-sm font-medium text-foreground/80`,children:l.name})]});let u=async e=>{if(e.id!==l.id)try{await i(e.id),window.location.href=Na()}catch(e){console.error(`[WorkspaceSwitcher] switch failed`,e)}};return(0,Q.jsxs)(Mt,{children:[(0,Q.jsxs)(kn,{className:`ml-2 inline-flex max-w-[14rem] items-center gap-1.5 rounded-md px-1.5 py-1 text-sm font-medium text-foreground/80 transition-colors hover:bg-accent hover:text-foreground`,"data-testid":`workspace-switcher`,children:[(0,Q.jsx)(Fa,{name:l.name}),(0,Q.jsx)(`span`,{className:`hidden truncate sm:inline`,children:l.name}),(0,Q.jsx)(z,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]}),(0,Q.jsxs)(sn,{align:`start`,className:`w-60`,children:[(0,Q.jsx)(Ft,{className:`text-xs text-muted-foreground`,children:e(`organization.switcher.label`,{defaultValue:`Switch organization`})}),c.map(e=>(0,Q.jsxs)(J,{onClick:()=>u(e),className:`cursor-pointer gap-2`,children:[(0,Q.jsx)(Fa,{name:e.name}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.id===l.id&&(0,Q.jsx)(V,{className:`h-4 w-4 shrink-0`})]},e.id)),(0,Q.jsx)(mt,{}),(0,Q.jsxs)(J,{onClick:()=>t(`/organizations/${l.slug}/members`),className:`cursor-pointer gap-2`,"data-testid":`workspace-manage-members`,children:[(0,Q.jsx)(ge,{className:`h-4 w-4`}),e(`organization.switcher.manageMembers`,{defaultValue:`Manage members`})]}),!o&&(0,Q.jsxs)(J,{onClick:()=>t(`/organizations?create=1`),className:`cursor-pointer gap-2`,"data-testid":`workspace-create`,children:[(0,Q.jsx)(ut,{className:`h-4 w-4`}),e(`organizations.create`,{defaultValue:`Create workspace`})]})]})]})}var La=[{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 Ra(){let{t:e,language:t,changeLanguage:n}=O();return(0,Q.jsxs)(Mt,{children:[(0,Q.jsx)(kn,{asChild:!0,children:(0,Q.jsxs)(Y,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(ht,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Q.jsx)(sn,{align:`end`,className:`max-h-72 overflow-y-auto`,children:La.map(e=>(0,Q.jsxs)(J,{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 za={connected:{labelKey:`topbar.connection.connected`,defaultValue:`Connected`,color:`text-green-500`,icon:P},connecting:{labelKey:`topbar.connection.connecting`,defaultValue:`Connecting...`,color:`text-yellow-500`,icon:X},reconnecting:{labelKey:`topbar.connection.reconnecting`,defaultValue:`Reconnecting...`,color:`text-yellow-500`,icon:X},disconnected:{labelKey:`topbar.connection.disconnected`,defaultValue:`Disconnected`,color:`text-muted-foreground`,icon:Ut},error:{labelKey:`topbar.connection.error`,defaultValue:`Connection Error`,color:`text-destructive`,icon:Ut}};function Ba({state:e,className:t}){let n=za[e],{t:r}=O(),i=r(n.labelKey,{defaultValue:n.defaultValue}),a=n.icon,[o,s]=(0,$.useState)(!1);return(0,$.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:G(`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:G(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:i})]})}function Va(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 Ha({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:o}){let{t:s}=O(),c=m(),l=a(),{currentAppName:u}=$r(),[d,f]=(0,$.useState)(!1),[p,h]=(0,$.useState)(`notifications`),[g,_]=(0,$.useState)(`unread`),v=t+n,y=s(`sidebar.inboxAriaLabel`,{defaultValue:`Open inbox`}),b=(0,$.useRef)(null),[x,S]=(0,$.useState)(!1);(0,$.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,$.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=>{o(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)(Bt,{open:d,onOpenChange:f,children:[(0,Q.jsx)(rn,{asChild:!0,children:(0,Q.jsxs)(Y,{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)(Dt,{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)(vt,{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)(xn,{value:p,onValueChange:e=>h(e),className:`w-full`,children:[(0,Q.jsxs)(Xt,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Q.jsxs)(wn,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(Dt,{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)(wn,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(Zt,{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)(wn,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(ce,{className:`h-3.5 w-3.5`}),s(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Q.jsxs)(Tt,{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:()=>_(`unread`),className:`text-xs px-2 py-1 rounded-md transition-colors ${g===`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:()=>_(`all`),className:`text-xs px-2 py-1 rounded-md transition-colors ${g===`all`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:s(`notifications.filterAll`,{defaultValue:`All`})})]}),(()=>{let t=g===`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:g===`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:Va(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)(Tt,{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)(Zt,{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)(Y,{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)(Tt,{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:[Va(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 Ua({activeAppName:e,onAppChange:t}){let{apps:n}=k(),{t:r}=O(),{appLabel:i}=Ie(),a=n||[],o=a.filter(e=>e.active!==!1&&e.hidden!==!0),s=ai(o,e)||ai(a.filter(e=>e.active!==!1),e)||o[0];return s?(0,Q.jsxs)(Mt,{children:[(0,Q.jsx)(kn,{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:di(s.label,r)})}),(0,Q.jsx)(rt,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Q.jsxs)(sn,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Q.jsx)(Ft,{className:`text-xs text-muted-foreground font-normal`,children:r(`layout.appSwitcher.switchApplication`,{defaultValue:`Switch Application`})}),(0,Q.jsx)(mt,{}),o.map(e=>{let n=zr(e.icon),a=i({name:e.name,label:di(e.label,r)}),o=s.name===e.name;return(0,Q.jsxs)(J,{onClick:()=>t(oi(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)(V,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var Wa=(0,$.createContext)(null);function Ga({children:e}){let[t,n]=(0,$.useState)(null),r=(0,$.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Q.jsx)(Wa.Provider,{value:r,children:e})}function Ka(){return(0,$.useContext)(Wa)?.value??null}function qa(e){let t=(0,$.useContext)(Wa),n=(0,$.useRef)(null);(0,$.useEffect)(()=>{if(!t)return;let r=e??null;return t.setValue(r),n.current=r,()=>{t.setValue(null)}},[t,e])}function Ja(e){let{views:t,activeViewId:n,onChange:r,triggerLabel:i,enabled:a=!0}=e,o=(0,$.useRef)(r);o.current=r;let s=(0,$.useCallback)(e=>o.current(e),[]);qa((0,$.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}var Ya=(0,$.createContext)(null);function Xa({children:e}){let{open:t,setOpen:n,openOverlay:r,closeOverlay:i,toggleOverlay:a}=ir(`palette`,{alias:`cmdk`});(0,$.useEffect)(()=>{let e=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),a())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[a]);let o=(0,$.useMemo)(()=>({open:t,openCommandPalette:r,closeCommandPalette:i,toggleCommandPalette:a,setOpen:n}),[t,r,i,a,n]);return(0,Q.jsx)(Ya.Provider,{value:o,children:e})}function Za(){return(0,$.useContext)(Ya)||{open:!1,openCommandPalette:()=>{},closeCommandPalette:()=>{},toggleCommandPalette:()=>{},setOpen:()=>{}}}function Qa(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function $a(){return(0,Q.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var eo=[];function to({variant:e,appName:t,objects:n,connectionState:r,presenceUsers:i,activities:o,activeAppName:c,onAppChange:l}){let u=e??(t?`app`:`home`),f=u===`app`,p=s(),h=a(),_=m(),{isOnline:v}=E(),{openCommandPalette:x}=Za(),{openOverlay:S}=ir(`shortcuts`),{user:C,signOut:w,isAuthEnabled:T,organizations:D,activeOrganization:ee,isOrganizationsLoading:A,getAuthConfig:j}=g(),M=b(),{enabled:N}=Lr(),{t:P}=O(),{objectLabel:ne,dashboardLabel:re,pageLabel:F,reportLabel:ie,viewLabel:ae,appLabel:oe}=Ie(),{apps:I,dashboards:L,pages:se,reports:ce}=k(),{currentAppName:le,recordTitle:R}=$r(),z=Ka(),[ue,de]=(0,$.useState)(null),fe=(0,$.useCallback)(async()=>{if(ue===null)try{let e=M?.getClient?.();if(!e?.meta?.getItems){de([]);return}let t=await e.meta.getItems(`doc`);de((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{de([])}},[ue,M]),[pe,me]=(0,$.useState)(null),[B,H]=(0,$.useState)([]),he=(0,$.useRef)(!1),U=(0,$.useRef)(!1),ge=(0,$.useRef)(!0);(0,$.useEffect)(()=>(ge.current=!0,()=>{ge.current=!1}),[]);let _e=(0,$.useRef)(!1),ve=(0,$.useRef)(!1),ye=(0,$.useRef)(!1),[be,xe]=(0,$.useState)(0),Se=(0,$.useRef)(!1),Ce=(0,$.useCallback)(async()=>{if(!M||!f)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!he.current&&!ye.current){ye.current=!0;try{let t=await M.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(he.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`);e.length&&me(e)}}catch{}finally{ye.current=!1}}},[M,f]);(0,$.useEffect)(()=>{Ce()},[Ce]),(0,$.useEffect)(()=>{if(!M||!f||!C?.id||U.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(!_e.current){_e.current=!0;try{let[e,t]=await Promise.all([M.find(`sys_inbox_message`,{$filter:{user_id:C.id},$orderby:{created_at:`desc`},$top:20}),M.find(`sys_notification_receipt`,{$filter:{user_id:C.id,channel:`inbox`},$top:200}).catch(()=>({data:[]}))]);if(!ge.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)})}H(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)){U.current=!0;return}r=Math.min(r*2,12e4)}finally{_e.current=!1}}},s=()=>{if(e||U.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)}},[M,f,C?.id]),(0,$.useEffect)(()=>{if(!f||!C?.id||Se.current)return;let e=`${``.replace(/\/$/,``)}/api/v1/approvals/requests`,t=[];C.id&&t.push(C.id),C.email&&t.push(C.email);for(let e of C.roles||[])e&&t.push(`role:${e}`);let n=!1,r=null,i=async()=>{if(t.length!==0&&!ve.current){ve.current=!0;try{let n=new URLSearchParams({status:`pending`,approverId:t.join(`,`)}),r=await fetch(`${e}?${n}`,{credentials:`include`});if(r.status===404){Se.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);ge.current&&xe(a.size)}catch{}finally{ve.current=!1}}},a=()=>{n||Se.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[f,C?.id]);let we=B.reduce((e,t)=>e+ +!t.is_read,0),Ee=(0,$.useCallback)(async(e,t)=>{!M||!e.notification_id||(e.receipt_id?await M.update(`sys_notification_receipt`,e.receipt_id,{state:`read`,at:t}):await M.create(`sys_notification_receipt`,{notification_id:e.notification_id,user_id:C?.id,channel:`inbox`,state:`read`,at:t,created_at:t}))},[M,C?.id]),De=(0,$.useCallback)(async e=>{let t=B.find(t=>t.id===e);if(H(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),t)try{await Ee(t,new Date().toISOString())}catch{}},[B,Ee]),W=(0,$.useCallback)(async()=>{let e=B.filter(e=>!e.is_read);if(!e.length)return;H(e=>e.map(e=>({...e,is_read:!0})));let t=new Date().toISOString();await Promise.all(e.map(e=>Ee(e,t).catch(()=>{})))},[B,Ee]),ke=qr(),Ae=i??(ke.length>0?ke:eo),je=o??pe??[],Ne=A||(D??[]).length>0||!!ee,[Pe,Fe]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=!1;return j?.().then(t=>{e||Fe(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[j]);let K=p.pathname.split(`/`).filter(Boolean),Le=h.appName||K[1],ze=K[2],Be=`/apps/${Le}`,Ve=n??[],He=ai(I||[],c||le||Le),Ue=new Set,We=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&Ue.add(t.objectName),t.children&&We(t.children)};We(He?.navigation||[]);for(let e of He?.areas||[])We(e.navigation||[]);let Ge=Ue.size>0?Ve.filter(e=>Ue.has(e.name)):Ve.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`)),qe=He?._packageId,Je=qe?(ue??[]).filter(e=>e._packageId===qe):[],Ye=Ge.map(e=>({label:ne(e),href:`${Be}/${e.name}`})),Xe=[];if(f){if(ze===`dashboard`){if(Xe.push({label:P(`console.breadcrumb.dashboards`),href:Be}),K[3]){let e=K[3],t=mi(L,e,He?._packageId)?.label||Qa(e);Xe.push({label:re({name:e,label:t})})}}else if(ze===`page`){if(Xe.push({label:P(`console.breadcrumb.pages`),href:Be}),K[3]){let e=K[3],t=mi(se,e,He?._packageId)?.label||Qa(e);Xe.push({label:F({name:e,label:t})})}}else if(ze===`report`){if(Xe.push({label:P(`console.breadcrumb.reports`),href:Be}),K[3]){let e=K[3],t=mi(ce,e,He?._packageId)?.label||Qa(e);Xe.push({label:ie({name:e,label:t})})}}else if(ze===`system`)Xe.push({label:P(`console.breadcrumb.system`)}),K[3]&&Xe.push({label:Qa(K[3])});else if(ze){let e=Ve.find(e=>e.name===ze);if(e){if(Xe.push({label:ne(e),href:`${Be}/${ze}`,siblings:Ye}),K[3]===`record`&&K[4]){let e=K[4].length>12?`${K[4].slice(0,8)}…`:K[4],t=R?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;Xe.push({label:n||`#${e}`})}else if(K[3]===`view`&&K[4]){let t=K[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||Qa(t),i=ae(e.name,t,r);Xe.push({label:i})}}}}let Ze=Xe[Xe.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)(d,{to:`/home`,className:G(`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,f&&`hidden sm:flex`),title:yi(),children:(0,Q.jsx)(ft,{className:`h-4 w-4`})}),u===`home`&&(0,Q.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:yi()}),(0,Q.jsx)(Ia,{}),u===`orgs`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)($a,{}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:P(`organizations.title`,{defaultValue:`Organizations`})})]}),f&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ta,{className:`lg:hidden shrink-0 ml-1`,"aria-label":P(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`})}),c&&l?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)($a,{})}),(0,Q.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(Ua,{activeAppName:c,onAppChange:l})})]}):t?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)($a,{})}),(0,Q.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,Xe.map((e,t)=>{let n=t===Xe.length-1;return(0,Q.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,Q.jsx)($a,{}),e.siblings&&e.siblings.length>1?(0,Q.jsxs)(Mt,{children:[(0,Q.jsxs)(kn,{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)(rt,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Q.jsxs)(sn,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Q.jsx)(Ft,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,Q.jsx)(mt,{}),e.siblings.map(e=>(0,Q.jsx)(J,{asChild:!0,children:(0,Q.jsx)(d,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,Q.jsx)(d,{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)}),z&&z.views.length>0?z.views.length>1?(0,Q.jsxs)(Mt,{children:[(0,Q.jsx)(kn,{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":P(`topbar.switchView`,{defaultValue:`Switch view`}),children:[(0,Q.jsx)(`span`,{className:`truncate max-w-[180px]`,children:z.triggerLabel??z.views.find(e=>e.id===z.activeViewId)?.label??Ze}),(0,Q.jsx)(rt,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Q.jsx)(sn,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:z.views.map(e=>{let t=e.id===z.activeViewId;return(0,Q.jsxs)(J,{onSelect:()=>{t||z.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)(Re,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Q.jsx)(V,{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:z.triggerLabel??z.views[0].label}):(0,Q.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:Ze})]})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1 shrink-0 [&>*+*[data-topbar-group]]:ml-1 [&>[data-topbar-group]+[data-topbar-group]]:border-l [&>[data-topbar-group]+[data-topbar-group]]:border-border/60 [&>[data-topbar-group]+[data-topbar-group]]:pl-1 sm:[&>[data-topbar-group]+[data-topbar-group]]:pl-2 sm:[&>[data-topbar-group]+[data-topbar-group]]:ml-2`,children:[!v&&(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`}),P(`topbar.offline`,{defaultValue:`Offline`})]}),f&&r&&(0,Q.jsx)(Ba,{state:r}),f&&Ae.length>0&&(0,Q.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:P(`topbar.usersOnline`,{defaultValue:`Users currently online`}),children:(0,Q.jsx)(Zr,{users:Ae,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`,{type:`button`,"data-testid":`action:command-palette:open`,"aria-label":P(`console.search`,{defaultValue:`Search…`}),"aria-keyshortcuts":`Meta+K Control+K`,onClick:x,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)(Me,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:P(`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)(Y,{variant:`ghost`,size:`icon`,className:`lg:hidden h-8 w-8 shrink-0`,"data-testid":`action:command-palette:open-mobile`,onClick:x,"aria-label":P(`console.search`,{defaultValue:`Search…`}),children:(0,Q.jsx)(Me,{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)(Ha,{notifications:B,unreadCount:we,pendingApprovalsCount:be,activities:je,onMarkAllRead:W,onMarkRead:De}),N&&(0,Q.jsx)(Y,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"aria-label":P(`topbar.aiAssistant`,{defaultValue:`AI Assistant`}),children:(0,Q.jsx)(d,{to:`/ai`,children:(0,Q.jsx)(gn,{className:`h-4 w-4`})})}),(0,Q.jsxs)(Mt,{onOpenChange:e=>{e&&fe()},children:[(0,Q.jsx)(kn,{asChild:!0,children:(0,Q.jsx)(Y,{variant:`ghost`,size:`icon`,className:`h-8 w-8 hidden md:flex shrink-0`,"aria-label":P(`sidebar.helpTooltip`,{defaultValue:`Help & Documentation`}),children:(0,Q.jsx)(Ke,{className:`h-4 w-4`})})}),(0,Q.jsxs)(sn,{align:`end`,className:`min-w-56 rounded-lg`,sideOffset:4,children:[Je.length>0&&qe?(0,Q.jsxs)(J,{className:`cursor-pointer`,onClick:()=>_(Je.length===1?`/apps/${qe}/docs/${Je[0].name}`:`/apps/${qe}/docs`),children:[(0,Q.jsx)(qt,{className:`mr-2 h-4 w-4`}),P(`help.appDocs`,{defaultValue:`This app's docs`})]}):null,(0,Q.jsxs)(J,{className:`cursor-pointer`,onClick:()=>_(`/docs`),children:[(0,Q.jsx)(ft,{className:`mr-2 h-4 w-4`}),P(`help.allDocs`,{defaultValue:`All documentation`})]}),f?(0,Q.jsxs)(J,{className:`cursor-pointer`,"data-testid":`action:keyboard-shortcuts:open`,onClick:S,children:[(0,Q.jsx)(te,{className:`mr-2 h-4 w-4`}),P(`help.keyboardShortcuts`,{defaultValue:`Keyboard shortcuts`})]}):null,(0,Q.jsx)(mt,{}),(0,Q.jsx)(J,{asChild:!0,className:`cursor-pointer`,children:(0,Q.jsxs)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,Q.jsx)(fn,{className:`mr-2 h-4 w-4`}),P(`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)(Mt,{children:[(0,Q.jsx)(kn,{asChild:!0,children:(0,Q.jsx)(Y,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,Q.jsxs)(an,{className:`h-7 w-7 rounded-full`,children:[(0,Q.jsx)(wt,{src:C?.image,alt:C?.name??`User`}),(0,Q.jsx)(yn,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:y(C)})]})})}),(0,Q.jsxs)(sn,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Q.jsx)(Ft,{className:`p-0 font-normal`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,Q.jsxs)(an,{className:`h-8 w-8 rounded-lg`,children:[(0,Q.jsx)(wt,{src:C?.image,alt:C?.name??`User`}),(0,Q.jsx)(yn,{className:`rounded-lg bg-primary text-primary-foreground`,children:y(C)})]}),(0,Q.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,Q.jsx)(`span`,{className:`truncate font-semibold`,children:C?.name??`User`}),(0,Q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:C?.email??``})]})]})}),(0,Q.jsx)(mt,{}),(0,Q.jsxs)(Qt,{children:[(0,Q.jsxs)(J,{onClick:()=>_(`/apps/account/component/account/profile_card`),className:`cursor-pointer`,children:[(0,Q.jsx)(Oe,{className:`mr-2 h-4 w-4`}),P(`user.profile`,{defaultValue:`Profile`})]}),Ne&&!Pe&&(0,Q.jsxs)(J,{onClick:()=>_(`/organizations?create=1`),className:`cursor-pointer`,"data-testid":`header-create-workspace`,children:[(0,Q.jsx)(ut,{className:`mr-2 h-4 w-4`}),P(`organizations.create`,{defaultValue:`Create workspace`})]}),(I||[]).filter(e=>e.active!==!1&&e.hidden===!0&&e.name!==`account`).map(e=>{let t=zr(e.icon),n=oe({name:e.name,label:di(e.label,P)});return(0,Q.jsxs)(J,{onClick:()=>_(`/apps/${oi(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)(mt,{}),(0,Q.jsx)(Ft,{className:`text-[11px] font-normal text-muted-foreground uppercase tracking-wide px-2`,children:P(`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:P(`user.theme`,{defaultValue:`Theme`})}),(0,Q.jsx)(ja,{})]}),(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:P(`user.language`,{defaultValue:`Language`})}),(0,Q.jsx)(Ra,{})]}),T&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(mt,{}),(0,Q.jsxs)(J,{className:`text-destructive focus:text-destructive`,onClick:()=>w(),children:[(0,Q.jsx)(Te,{className:`mr-2 h-4 w-4`}),P(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}function no({children:e}){return lr(),(0,Q.jsx)(Q.Fragment,{children:e})}function ro({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=di(n?.label)||t,{enabled:c}=Lr(),l=vi().features.aiStudio===!1&&Tr(n?.defaultAgent)?void 0:n?.defaultAgent,{setContext:u,setCurrentAppName:d}=$r();return(0,$.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,Q.jsx)(Xa,{children:(0,Q.jsx)(Ga,{children:(0,Q.jsxs)(ti,{sidebar:(0,Q.jsx)(Aa,{activeAppName:t,onAppChange:r}),navbar:(0,Q.jsx)(to,{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?`${di(n.label)} — ${yi()}`:void 0}:void 0,children:[(0,Q.jsxs)(no,{children:[(0,Q.jsx)(fa,{}),(0,Q.jsx)(_a,{}),e]}),c&&(0,Q.jsx)(sa,{appLabel:s,appName:t,defaultAgent:l,objects:i,userId:o})]})})})}function io({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:G(`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:G(`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 ao({apps:e,activeApp:t,objects:n,onAppChange:r,dataSource:i}){let{open:o,setOpen:s}=Za(),[c,l]=(0,$.useState)(``),u=m(),{appName:d}=a(),{setTheme:f}=Wi(),{evaluator:p}=Qn(),{t:h}=O();(0,$.useEffect)(()=>{o||l(``)},[o]);let _=`/apps/${d||oi(t)}`,{user:v}=g(),y=(0,$.useMemo)(()=>({currentUserId:v?.id??null}),[v?.id]),b=(0,$.useCallback)(e=>{s(!1),e()},[]),x=oo(t?.navigation||[]).filter(e=>Zn(e.visible??e.visibleOn,p)),{results:S,isSearching:C}=T({query:c,objects:n,dataSource:i,objectNames:(0,$.useMemo)(()=>x.filter(e=>e.type===`object`&&typeof e.objectName==`string`).map(e=>e.objectName),[t?.name,x.map(e=>e.objectName||``).join(`|`)]),enabled:o&&!!i,getDisplayName:fi}),{recentItems:w}=gr(),E=(0,$.useMemo)(()=>w.filter(e=>e.type===`record`).slice(0,5),[w]),D=o&&c.trim().length===0&&E.length>0;return(0,Q.jsxs)(U,{open:o,onOpenChange:s,title:h(`console.commandPalette.title`,{defaultValue:`Command palette`}),description:h(`console.commandPalette.placeholder`),contentProps:{"data-testid":`overlay:command-palette`},children:[(0,Q.jsx)(Fn,{placeholder:h(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,Q.jsxs)(tt,{children:[(0,Q.jsx)(De,{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`}),h(`console.commandPalette.searching`,{defaultValue:`Searching…`})]}):h(`console.commandPalette.noResults`)}),D&&(0,Q.jsx)(ze,{heading:h(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:E.map(e=>(0,Q.jsxs)(F,{value:`recent ${e.label} ${e.id}`,onSelect:()=>b(()=>u(e.href)),children:[(0,Q.jsx)(Me,{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)(ze,{heading:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[h(`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=zr(e.icon);return(0,Q.jsxs)(F,{value:`record ${c} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>b(()=>u(`${_}/${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}`)})}),x.filter(e=>e.type===`object`).length>0&&(0,Q.jsx)(ze,{heading:h(`console.commandPalette.objects`),children:x.filter(e=>e.type===`object`).map(e=>{let t=zr(e.icon);return(0,Q.jsxs)(F,{value:`object ${di(e.label,h)} ${e.objectName}`,onSelect:()=>b(()=>u(ei(e,_,y).href)),children:[(0,Q.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:di(e.label,h)})]},e.id)})}),x.filter(e=>e.type===`dashboard`).length>0&&(0,Q.jsx)(ze,{heading:h(`console.commandPalette.dashboards`),children:x.filter(e=>e.type===`dashboard`).map(e=>(0,Q.jsxs)(F,{value:`dashboard ${di(e.label,h)} ${e.dashboardName}`,onSelect:()=>b(()=>u(ei(e,_,y).href)),children:[(0,Q.jsx)(st,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:di(e.label,h)})]},e.id))}),x.filter(e=>e.type===`page`).length>0&&(0,Q.jsx)(ze,{heading:h(`console.commandPalette.pages`),children:x.filter(e=>e.type===`page`).map(e=>(0,Q.jsxs)(F,{value:`page ${di(e.label,h)} ${e.pageName}`,onSelect:()=>b(()=>u(ei(e,_,y).href)),children:[(0,Q.jsx)(K,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:di(e.label,h)})]},e.id))}),x.filter(e=>e.type===`report`).length>0&&(0,Q.jsx)(ze,{heading:h(`console.commandPalette.reports`),children:x.filter(e=>e.type===`report`).map(e=>(0,Q.jsxs)(F,{value:`report ${di(e.label,h)} ${e.reportName}`,onSelect:()=>b(()=>u(ei(e,_,y).href)),children:[(0,Q.jsx)(ct,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:di(e.label,h)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(me,{}),(0,Q.jsx)(ze,{heading:h(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=zr(e.icon);return(0,Q.jsxs)(F,{value:`app ${di(e.label,h)} ${e.name}`,onSelect:()=>b(()=>r(oi(e)??e.name)),children:[(0,Q.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:di(e.label,h)}),e.name===t?.name&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:h(`console.commandPalette.current`)})]},e.name)})})]}),(0,Q.jsx)(me,{}),(0,Q.jsxs)(ze,{heading:h(`console.commandPalette.preferences`),children:[(0,Q.jsxs)(F,{value:`theme light`,onSelect:()=>b(()=>f(`light`)),children:[(0,Q.jsx)(_t,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.lightTheme`)})]}),(0,Q.jsxs)(F,{value:`theme dark`,onSelect:()=>b(()=>f(`dark`)),children:[(0,Q.jsx)(He,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.darkTheme`)})]}),(0,Q.jsxs)(F,{value:`theme system`,onSelect:()=>b(()=>f(`system`)),children:[(0,Q.jsx)(oe,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.systemTheme`)})]})]}),(0,Q.jsx)(me,{}),(0,Q.jsx)(ze,{heading:h(`console.commandPalette.actions`),children:(0,Q.jsxs)(F,{value:`search all results full page`,onSelect:()=>b(()=>u(`${_}/search`)),children:[(0,Q.jsx)(Me,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.openFullSearch`)})]})})]})]})}function oo(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...oo(n.children)):t.push(n);return t}function so(){let{t:e}=O(),{open:t,setOpen:n,toggleOverlay:r}=ir(`shortcuts`),i=(0,$.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,$.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(),r())}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[r]),(0,Q.jsx)(Ye,{open:t,onOpenChange:n,children:(0,Q.jsxs)(at,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,"data-testid":`overlay:keyboard-shortcuts`,children:[(0,Q.jsxs)(dn,{children:[(0,Q.jsx)(ve,{children:e(`console.shortcuts.title`)}),(0,Q.jsx)(ue,{children:e(`console.shortcuts.description`)})]}),(0,Q.jsx)(`div`,{className:`space-y-6 pt-2`,children:i.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 co(){return null}function lo(){return typeof document<`u`&&document.documentElement.lang?.startsWith(`zh`)||typeof navigator<`u`&&navigator.language?.startsWith(`zh`)?A.console:j.console}function uo({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,$.useState)(0),o=lo(),s=(0,$.useMemo)(()=>[o.loadingSteps.connecting,o.loadingSteps.loadingConfig,o.loadingSteps.preparingWorkspace],[o]);return(0,$.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)(Cn,{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:yi()}),(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)(Ae,{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)(Y,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(X,{className:`h-4 w-4 animate-spin`}),o.actions.retrying]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(et,{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)(re,{className:`h-4 w-4 text-primary`}),(0,Q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e})]}):(0,Q.jsxs)(`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)(P,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,Q.jsx)(X,{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)),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:o.loadingHint})]})]})})}function fo(e){let{theme:t=`system`}=Wi(),{t:n}=O();return(0,Q.jsx)(Bn,{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)(P,{className:`h-4 w-4`}),info:(0,Q.jsx)(Vt,{className:`h-4 w-4`}),warning:(0,Q.jsx)(fe,{className:`h-4 w-4`}),error:(0,Q.jsx)(pt,{className:`h-4 w-4`}),loading:(0,Q.jsx)(X,{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 po=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function mo({children:e,className:t}){let n=s(),r=$.useRef(null),i=$.useRef(n.pathname);return $.useLayoutEffect(()=>{if(i.current===n.pathname)return;i.current=n.pathname;let e=r.current;e&&(e.classList.remove(...po),e.offsetWidth,e.classList.add(...po))},[n.pathname]),(0,Q.jsx)(`div`,{ref:r,className:[...po,t??``].filter(Boolean).join(` `),children:e})}var ho=null,go=null;function _o(){return go||(go=(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 c(()=>import(`./vendor-sentry-DUcsR3Vf.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=yo(e.data.url)),e}}),ho=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),go)}function vo(e,t){if(ho)try{ho.captureException(e,t?{extra:t}:void 0)}catch{}}function yo(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 bo({error:e,onReset:t}){let{t:n}=O();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)(Je,{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)(fe,{className:`h-6 w-6 text-destructive`})}),(0,Q.jsx)(un,{children:n(`console.errors.somethingWentWrong`)}),(0,Q.jsx)(it,{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)(Y,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,Q.jsx)(he,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,Q.jsxs)(Y,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,Q.jsx)(Yt,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var xo=class extends $.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),vo(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)(bo,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}},So=new Set([`form`,`detail`]);function Co(e){return typeof e==`string`&&So.has(e)}function wo(e,t){let n=e.type||`grid`,r=Co(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 To(e){let t=e.config??{},n={...t};return delete n.data,{...n,id:e.name,label:e.label??t.label}}function Eo(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 Do({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s,metadataClient:c,onAfterChange:l}){let{t:u}=O(),d=(0,$.useRef)(null),f=(0,$.useMemo)(()=>ii(),[]),[p]=(0,$.useState)(()=>`view_${Date.now()}`),m=(0,$.useMemo)(()=>({id:p,label:u(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[]}),[]),h=(0,$.useMemo)(()=>wo(n===`create`?m:r,i.name),[n===`create`?`create`:r.id,i.name]),[g,_]=(0,$.useState)(h),[v,y]=(0,$.useState)(!1),[b,x]=(0,$.useState)(0),S=(0,$.useRef)(g),C=(0,$.useRef)(h);C.current!==h&&(C.current=h,S.current=h,_(h),y(!1)),(0,$.useEffect)(()=>{S.current=g},[g]),(0,$.useEffect)(()=>{e&&d.current&&d.current.focus()},[e]);let w=(0,$.useMemo)(()=>Eo(i),[i.fields]),T=Ir(g.viewKind)?`form`:`list`,E=(0,$.useCallback)(e=>{let t={...S.current,...e};if(S.current=t,_(t),y(!0),a){let e=To(t);for(let[t,n]of Object.entries(e))t!==`id`&&a(t,n)}},[a]),D=(0,$.useCallback)(()=>{let e=To(g);n===`create`?s?.(e):(o?.(e),x(e=>e+1)),y(!1)},[g,o,s,n]),k=(0,$.useCallback)(()=>{if(n===`create`){t();return}_(h),y(!1)},[h,n,t]),ee=(0,$.useCallback)(e=>{let t=wo(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)(Ur,{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)(Pi,{type:`view`,name:r.id,metadataClient:c,dirty:v,onResume:ee,savedSignal:b,onAfterChange:l}),(0,Q.jsx)(Y,{variant:`ghost`,size:`sm`,onClick:k,"data-testid":`view-config-discard`,children:u(`console.objectView.discard`)}),(0,Q.jsx)(Y,{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 Oo(e){return[{type:`grid`,icon:_e,label:e(`console.objectView.viewTypeGrid`),description:e(`console.objectView.viewTypeGridDesc`)},{type:`kanban`,icon:jt,label:e(`console.objectView.viewTypeKanban`),description:e(`console.objectView.viewTypeKanbanDesc`)},{type:`calendar`,icon:Le,label:e(`console.objectView.viewTypeCalendar`),description:e(`console.objectView.viewTypeCalendarDesc`)},{type:`gallery`,icon:vn,label:e(`console.objectView.viewTypeGallery`),description:e(`console.objectView.viewTypeGalleryDesc`)},{type:`timeline`,icon:zt,label:e(`console.objectView.viewTypeTimeline`),description:e(`console.objectView.viewTypeTimelineDesc`)},{type:`gantt`,icon:on,label:e(`console.objectView.viewTypeGantt`),description:e(`console.objectView.viewTypeGanttDesc`)},{type:`map`,icon:ke,label:e(`console.objectView.viewTypeMap`),description:e(`console.objectView.viewTypeMapDesc`)},{type:`chart`,icon:ct,label:e(`console.objectView.viewTypeChart`),description:e(`console.objectView.viewTypeChartDesc`)},{type:`tree`,icon:$e,label:e(`console.objectView.viewTypeTree`),description:e(`console.objectView.viewTypeTreeDesc`)}]}function ko(e,t){for(let n=1;n<1e3;n++){let r=`${e} ${n}`;if(!t.has(r))return r}return e}var Ao={kanban:[{key:`groupByField`,i18nKey:`console.objectView.groupByField`,helpI18nKey:`console.objectView.groupByFieldHelp`,filter:e=>e.type===`select`||e.type===`boolean`,preferred:Di}],calendar:[{key:`startDateField`,i18nKey:`console.objectView.startDateField`,helpI18nKey:`console.objectView.startDateFieldHelp`,filter:e=>e.type===`date`,preferred:ki},{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:ki},{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:ki},{key:`endDateField`,i18nKey:`console.objectView.endDateField`,helpI18nKey:`console.objectView.ganttEndDateFieldHelp`,filter:e=>e.type===`date`,preferred:ji},{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=>Oi(e)}],map:[{key:`latitudeField`,i18nKey:`console.objectView.latitudeField`,helpI18nKey:`console.objectView.latitudeFieldHelp`,filter:e=>e.type===`number`&&Ci(e,`latitude`)},{key:`longitudeField`,i18nKey:`console.objectView.longitudeField`,helpI18nKey:`console.objectView.longitudeFieldHelp`,filter:e=>e.type===`number`&&Ci(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:Di},{key:`yAxisFields`,i18nKey:`console.objectView.yAxisField`,helpI18nKey:`console.objectView.yAxisFieldHelp`,filter:e=>e.type===`number`}],tree:[{key:`parentField`,i18nKey:`console.objectView.parentField`,helpI18nKey:`console.objectView.parentFieldHelp`,filter:e=>e.rawType===`tree`||e.rawType===`lookup`||e.rawType===`master_detail`}]};function jo({open:e,onOpenChange:t,onCreate:n,existingLabels:r,availableTypes:i,objectDef:a}){let{t:o}=O(),s=(0,$.useMemo)(()=>Oo(o),[o]),c=(0,$.useMemo)(()=>i&&i.length>0?s.filter(e=>i.includes(e.type)):s,[s,i]),l=(0,$.useMemo)(()=>new Set(r??[]),[(r??[]).join(`\0`)]),u=(0,$.useMemo)(()=>a?Ti(a):[],[a]),[d,f]=(0,$.useState)(c[0]?.type??`grid`),[p,m]=(0,$.useState)(``),[h,g]=(0,$.useState)(!1),[_,v]=(0,$.useState)({});(0,$.useEffect)(()=>{e&&(f(c[0]?.type??`grid`),g(!1),v({}))},[e,c]),(0,$.useEffect)(()=>{h||m(ko(c.find(e=>e.type===d)?.label??`View`,l))},[d,h,c,l]);let y=Ao[d]??[],b=e=>e.kind===`enum`?(e.enumOptions?.length??0)>0:a?(e.filter?u.filter(e.filter):u).length>0:!0,x=(0,$.useMemo)(()=>{let e={};return c.forEach(t=>{let n=(Ao[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,$.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=Ai(t,e.preferred??[]);n&&C(e.key,n)})},[d,u]);let k=()=>{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)(Ye,{open:e,onOpenChange:t,children:(0,Q.jsxs)(at,{className:`sm:max-w-[560px]`,"data-testid":`create-view-dialog`,children:[(0,Q.jsxs)(dn,{children:[(0,Q.jsx)(ve,{children:o(`console.objectView.createView`)}),(0,Q.jsx)(ue,{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:G(`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:G(`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:G(`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)(Ae,{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)(_n,{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&&k()},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)(xe,{className:`mt-2`,children:[(0,Q.jsx)(Y,{type:`button`,variant:`outline`,onClick:()=>t(!1),"data-testid":`create-view-cancel`,children:o(`console.objectView.cancel`)}),(0,Q.jsx)(Y,{type:`button`,disabled:!D,onClick:k,"data-testid":`create-view-submit`,children:o(`console.objectView.create`)})]})]})})}function Mo(e,t,n){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 n===`sys_user`?{icon:`ShieldAlert`,title:t(`list.managedBy.betterAuthUser.title`,{defaultValue:`No users yet`}),message:t(`list.managedBy.betterAuthUser.message`,{defaultValue:`User accounts are provisioned by the authentication provider, not created here. Invite teammates to your organization and they appear automatically on first sign-in (SSO just-in-time provisioning). App end-users arrive when they sign up through your app.`})}:{icon:`ShieldAlert`,title:t(`list.managedBy.betterAuth.title`,{defaultValue:`No identity records`}),message:t(`list.managedBy.betterAuth.message`,{defaultValue:`These records are created by the authentication provider — through sign-in, provisioning, and security flows — not added by hand here.`})};default:return}}var No=new Set([`archived`,`failed`]);function Po(e){let t=String(e?.environment_type??``).trim().toLowerCase();return t===`production`||t===`prod`?`production`:t?`development`:e?.is_default===!0||e?.is_default===1?`production`:`development`}function Fo(e){let{enabled:t,dataSource:n,authFetch:r,apiBase:i,refreshKey:a}=e,{activeOrganization:o}=g(),s=o?.id,[c,l]=(0,$.useState)(null);return(0,$.useEffect)(()=>{if(!t){l(null);return}let e=!1,a=async()=>{try{let e=await r(`${(i||``).replace(/\/+$/,``)}/api/v1/cloud/environment-entitlements${s?`?organizationId=${encodeURIComponent(s)}`:``}`,{method:`GET`,credentials:`include`});if(!e.ok)return null;let t=await e.json().catch(()=>null),n=t?.data??t;return!n||typeof n!=`object`?null:{ready:!0,hasProductionEnv:n.hasProductionEnv===!0,canCreateDevelopmentEnv:n.development?.canCreate,plan:n.plan,upgradeUrl:n.upgradeUrl||`/settings/billing`,contactSalesUrl:n.contactSalesUrl,source:`summary`}}catch{return null}},o=async()=>{try{let e={$top:200};s&&(e.$filter={organization_id:s});let t=await n.find(`sys_environment`,e);return{ready:!0,hasProductionEnv:(Array.isArray(t)?t:t?.data??[]).filter(e=>!No.has(String(e?.status??``))).some(e=>Po(e)===`production`),canCreateDevelopmentEnv:void 0,upgradeUrl:Bi,source:`derived`}}catch{return{ready:!1,hasProductionEnv:!1,canCreateDevelopmentEnv:void 0,upgradeUrl:Bi,source:`unknown`}}};return(async()=>{let t=await a()??await o();e||l(t)})(),()=>{e=!0}},[t,s,i,r,n,a]),c}var Io=`create_environment`;function Lo({actions:e,entitlements:t,onUpgrade:n}){let r=(e||[]).filter(e=>e?.locations?.includes(`list_toolbar`));if(r.length===0)return null;let i=t?.ready?Ri(t):null;if(i===`upgrade_for_development`){let e=r.filter(e=>e?.name!==Io);return(0,Q.jsxs)(Q.Fragment,{children:[e.length>0&&(0,Q.jsx)(C,{schema:{type:`action:bar`,location:`list_toolbar`,actions:e,size:`sm`,variant:`outline`}}),(0,Q.jsxs)(Y,{size:`sm`,onClick:()=>n(Li(t)),className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,"data-testid":`environment-add-upgrade`,children:[(0,Q.jsx)(ut,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:`Add environment`})]})]})}return(0,Q.jsx)(C,{schema:{type:`action:bar`,location:`list_toolbar`,actions:r.map(e=>e?.name!==Io||i==null?e:i===`setup_production`?{...e,label:`Set up your production environment`,variant:`primary`}:{...e,label:`Add development environment`}),size:`sm`,variant:`outline`}})}var Ro=(0,$.lazy)(()=>c(()=>import(`./plugin-charts-BDFf0TCn.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),zo=(0,$.lazy)(()=>c(()=>import(`./plugin-grid-D414NLNP.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),Bo={grid:hn,kanban:jt,calendar:Le,gallery:_e,timeline:ce,gantt:Ce,map:Fe,chart:ct},Vo={id:`current-user`,name:`Demo User`};function Ho(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 Uo({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let{objectName:i}=a(),{t:o}=O();return t.find(e=>e.name===i)?(0,Q.jsx)(Wo,{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)(Je,{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)(hn,{className:`h-6 w-6 text-muted-foreground`})}),(0,Q.jsx)(un,{children:o(`console.objectView.objectNotFound`)}),(0,Q.jsxs)(it,{children:[o(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,o(`console.objectView.objectNotFoundHint`)]})]})})}function Wo({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let i=m(),{appName:o,objectName:c,viewId:l}=a(),[d,f]=u(),p=s(),{showDebug:h}=pi(),{t:_}=O(),{objectLabel:y,objectDescription:b,viewLabel:x,viewEmptyState:w,actionLabel:T,actionConfirm:E,actionSuccess:D,actionParamText:k,fieldLabel:ee,fieldOptionLabel:A}=Ie(),{isFavorite:j,toggleFavorite:M}=hr(),te=ri(),[P,ne]=(0,$.useState)(!1),[re,F]=(0,$.useState)(`edit`),[ie,ae]=(0,$.useState)(!1),[oe,I]=(0,$.useState)(!1),[L,se]=(0,$.useState)(null),ce=(0,$.useRef)({}),le=(0,$.useRef)({}),R=(0,$.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!c||!t)return;let i=le.current[t]||{};le.current[t]={...i,...r};let a=ce.current[t];a&&clearTimeout(a),ce.current[t]=setTimeout(()=>{let r=le.current[t]||{};delete le.current[t],delete ce.current[t],Promise.resolve(e.updateViewConfig(c,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,c]),z=(0,$.useCallback)(e=>{se(e),U(e=>e+1);let t=e.id;te&&t?Ni(`view`,t,e,{metadataClient:te}).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing metadataClient or viewId.`)},[te]),ue=(0,$.useCallback)(async e=>{try{let n;if(te){let r=t?.find?.(e=>e.name===c),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,s={...e,columns:o};if(e.type===`kanban`)s.kanban={...s.kanban||{},columns:o};else if(e.type===`gallery`){let e=s.gallery||{};(!Array.isArray(e.visibleFields)||e.visibleFields.length===0)&&(s.gallery={...e,visibleFields:o})}n=await Fi(`view`,String(e?.name??e?.id??s?.id??``),s,{metadataClient:te})}ne(!1),F(`edit`),U(e=>e+1),n&&(l?i(`../${n}`,{relative:`path`}):i(`view/${n}`))}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,c,t,i,l,te]),[de,fe]=(0,$.useState)(void 0),{user:pe,activeOrganization:me}=g(),B=pe?.role===`admin`,{can:V}=v(),H=t.find(e=>e.name===c),[he,U]=(0,$.useState)(0),ge=zi({dataSource:e,objects:t,objectName:H.name,onRefresh:()=>U(e=>e+1)}),{confirmHandler:_e,toastHandler:ve}=ge,ye=H.name===`sys_environment`,be=Fo({enabled:ye,dataSource:e,authFetch:ge.authFetch,apiBase:``,refreshKey:he}),xe=(0,$.useMemo)(()=>(H.actions||[]).map(e=>({...e,label:T(H.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:E(H.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:D(H.name,e.name,e.successMessage)}})),[H,T,E,D]),Se=(0,$.useMemo)(()=>Kr(H),[H]);(0,$.useEffect)(()=>{r===void 0||r===0||U(e=>e+1)},[r]);let[Ce,we]=(0,$.useState)(!1),[Te,Ee]=(0,$.useState)([]);(0,$.useEffect)(()=>{let t=!1;if(!c){Ee([]);return}return typeof e?.listViews==`function`?(e.listViews(c).then(e=>{t||Ee((e||[]).map(e=>({...e,id:e.name||e.id,objectName:e.objectName||e.object||c})))}).catch(e=>{console.error(`[ObjectView] Failed to load overlay views:`,e),t||Ee([])}),()=>{t=!0}):(Ee([]),()=>{t=!0})},[e,c,he]);let[De,Oe]=(0,$.useState)({});(0,$.useEffect)(()=>{let t=!1;if(!e||!c){Oe({});return}let n=H.listViews||H.list_views||{},r=Object.keys(n),i=H.list;if(i&&typeof i==`object`){let e=i.name||`list`;r.includes(e)||r.unshift(e)}if(r.length===0){Oe({});return}return(async()=>{if(typeof e.listViewOverrides==`function`)try{let t=await e.listViewOverrides(c);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(c,t)]}catch{return[t,null]}})),n={};for(let[e,r]of t)r&&typeof r==`object`&&(n[e]=r);return n})().then(e=>{t||Oe(e)}),()=>{t=!0}},[e,c,H.listViews,H.list_views,H.list,he]);let W=(0,$.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(H.compactLayout)&&H.compactLayout.length>0?H.compactLayout.filter(e=>H.fields?.[e]):H.fields?Object.entries(H.fields).filter(([t,n])=>!(!n||n.hidden||e.has(t))).map(([e])=>e).slice(0,5):[],n=H.listViews||H.list_views||{},r=Object.entries(n).map(([e,t])=>{let n=De[e];return{id:e,...t,...n||{},type:n?.type||t.type||`grid`}}),i=H.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=De[e];r.unshift({id:e,...i,...t||{},type:t?.type||i.type||`grid`,isDefault:!0})}}r.length===0&&r.push({id:`all`,label:_(`console.objectView.allRecords`),type:`grid`,columns:t()});let a=new Set(r.map(e=>e.id));for(let e of Te){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:${H.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=Te.find(t=>(t.id||t._id)===e.id),a=Te.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},[H,Te,De,_]),ke=(0,$.useMemo)(()=>W.find(e=>e.isDefault)?.id,[W]),Ae=l||d.get(`view`)||ke||W[0]?.id,je=W.find(e=>e.id===Ae)||W[0],G=L&&L.id===je?.id?{...je,...L}:je,Me=(0,$.useCallback)((e,t)=>{se(n=>({...n||{},id:je?.id,[e]:t}))},[je?.id]),Ne=e=>{let t=W.find(t=>t.id===e);t&&(t.id!==Ae&&ne(!1),l?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},Pe=(0,$.useMemo)(()=>(W||[]).map(e=>{let t=Bo[e.type];return{id:e.id,label:x(H.name,e.name||e.id,e.label||e.name||e.id),icon:t?(0,Q.jsx)(t,{className:`h-4 w-4`}):void 0}}),[W,H.name,x]);Ja({views:Pe,activeViewId:Ae??``,onChange:Ne,enabled:Pe.length>0&&!!Ae});let Fe=(0,$.useCallback)(()=>{ae(!0)},[]),K=(0,$.useCallback)((e,t)=>{if(e===`settings`){let e=W.find(e=>e.type===t);e&&Ne(e.id),F(`edit`),ne(!0)}},[W,Ne]),Le=(0,$.useCallback)(e=>Te.some(t=>(t.id||t._id)===e),[Te]),Re=(0,$.useCallback)(async(t,n)=>{if(!Le(t)){Z.error(_(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be renamed.`);return}try{typeof e?.updateView==`function`&&await e.updateView(c,t,{label:n}),U(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),Z.error(_(`objectViewActions.renameFailed`))}},[e,c,Le,_]),ze=(0,$.useCallback)(async t=>{if(!e)return;if(!Le(t)){Z.error(_(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=W.find(e=>e.id===t)?.label||t;if(await _e(_(`console.objectView.deleteViewConfirm`,{name:n})||`Are you sure you want to delete the view "${n}"? This cannot be undone.`,{title:_(`console.objectView.deleteViewTitle`)||`Delete view`,confirmText:_(`console.objectView.delete`)||`Delete`,cancelText:_(`console.objectView.cancel`)||`Cancel`}))try{if(typeof e?.deleteView==`function`&&await e.deleteView(c,t),t===Ae){let e=W.find(e=>e.id!==t);e&&i(l?`../${e.id}`:`view/${e.id}`,l?{relative:`path`}:void 0)}U(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),Z.error(_(`objectViewActions.deleteFailed`))}},[e,Le,Ae,W,l,i,_,_e]),Be=(0,$.useCallback)(async(t,n)=>{if(e){if(!Le(t)){Z.error(_(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be pinned.`);return}try{typeof e?.updateView==`function`&&await e.updateView(c,t,{isPinned:n}),U(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,c,Le,_]),Ve=(0,$.useCallback)(async t=>{if(e){if(!Le(t)){Z.error(_(`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=Te.filter(e=>(e.id||e._id)!==t&&e.isDefault).map(e=>n(c,e.id||e._id,{isDefault:!1}));r.push(n(c,t,{isDefault:!0})),await Promise.all(r),U(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),Z.error(`Failed to set default view`)}}},[e,c,Te,Le,_]),He=(0,$.useCallback)(async t=>{try{typeof window<`u`&&window.localStorage?.setItem(`viewOrder:${c}`,JSON.stringify(t))}catch{}if(typeof e?.updateView==`function`){let n=e.updateView,r=new Set(Te.map(e=>e.id||e._id)),i=t.filter(e=>r.has(e)).map((e,t)=>n(c,e,{sortOrder:t}));try{await Promise.all(i)}catch(e){console.error(`[ViewTabBar] Failed to reorder views:`,e)}}U(e=>e+1)},[e,Te,c]),Ue=(0,$.useCallback)(e=>{if(!Le(e)){Z.error(_(`console.objectView.cannotEditMetaView`)||`System view — it cannot be edited.`);return}e!==Ae&&Ne(e),F(`edit`),ne(!0)},[Ae,Ne,Le,_]),We=(0,$.useCallback)(()=>{ae(!0)},[]),Ge=pe?{id:pe.id,name:pe.name,avatar:pe.image}:Vo,Ke=rr({objectName:H.name,objectLabel:H.label,dataSource:e,onEdit:n,onRefresh:()=>U(e=>e+1),onConfirm:_e,onToast:ve}),{lastMessage:qe}=Yr({channel:`object:${H.name}`}),{hasConflicts:Je,resolveAllConflicts:Ye}=Xr(H.name?`user-${H.name}`:`current-user`);(0,$.useEffect)(()=>{qe&&(Je&&Ye(`remote`),U(e=>e+1))},[qe,Je,Ye]),(0,$.useEffect)(()=>{e?.find&&H.name&&e.find(H.name,{limit:0}).then(e=>{typeof e?.total==`number`?fe(e.total):Array.isArray(e?.data)?fe(e.data.length):Array.isArray(e)&&fe(e.length)}).catch(()=>{})},[e,H.name,he]);let Xe=(0,$.useMemo)(()=>G?.navigation??H.navigation??{mode:`drawer`,width:`min(92vw, 1280px)`},[G?.navigation,H.navigation]),Ze=d.get(`recordId`),$e=Array.from(d.entries()).filter(([e])=>e.startsWith(`filter[`)).map(([e,t])=>`${e}=${t}`).join(`&`),et=(0,$.useMemo)(()=>{let e=[];return new URLSearchParams($e).forEach((t,n)=>{let r=/^filter\[(.+)\]$/.exec(n);r&&r[1]&&t!==``&&e.push([r[1],`=`,t])}),e},[$e]),[tt]=(0,$.useState)(()=>xi(new URLSearchParams(window.location.search))),nt=(0,$.useCallback)(e=>{f(t=>bi(t,e),{replace:!0})},[f]),rt=(0,$.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:p.pathname+(p.search||``),label:x(H.name,G?.name??``,G?.label??``)||y(H)}};l?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):i(`record/${encodeURIComponent(String(e))}`,{state:n})},[i,l,p.pathname,p.search,H,G?.name,G?.label,x,y]),q=N({navigation:Xe,objectName:H.name,onNavigate:rt}),it=()=>{q.close();let e=new URLSearchParams(d);e.delete(`recordId`),f(e)},at=(0,$.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){q.handleClick(e,t);return}if(q.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(d);e.set(`recordId`,String(t)),f(e);return}}q.handleClick(e,t)},[q,d,f]),ot=(0,$.useCallback)(()=>{let e=q.selectedRecord,t=e&&(e.id??e._id);t!=null&&(it(),rt(t))},[q.selectedRecord,rt]);(0,$.useEffect)(()=>{Ze&&!q.isOpen?q.open({id:Ze}):!Ze&&q.isOpen&&q.close()},[Ze]);let st=(0,$.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=he+(i||0),o=`${c}-${G.id}-${a}`,s=G;if(s.type===`chart`){let e=s.chart||{};if(e.dataset){let n=Array.isArray(e.dimensions)?e.dimensions:[],r=Array.isArray(e.values)?e.values:[];return(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,Q.jsx)(Ro,{dataSource:t,schema:{type:`object-chart`,dataset:e.dataset,dimensions:n,values:r,chartType:e.chartType||`bar`,xAxisKey:n[0],series:r.map(e=>({dataKey:e,label:e})),config:e.config,className:`h-[400px] w-full`}})},o)}let n=e.xAxisField||`name`,r=Array.isArray(e.yAxisFields)&&e.yAxisFields[0]||`value`,i=e.aggregation||`count`,a=e.series&&e.series.length>0?e.series:[{dataKey:r,label:r}];return(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,Q.jsx)(Ro,{dataSource:t,schema:{type:`object-chart`,objectName:H.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)(Si,{schema:{...e,rowHeight:s.rowHeight??e.rowHeight,densityMode:s.densityMode??e.densityMode,sort:s.sort??e.sort,filter:(()=>{let t=Ho(s.filter??e.filter,Ge.id);return et.length?[...Array.isArray(t)?t:[],...et]:t})(),hiddenFields:s.hiddenFields??e.hiddenFields,columnState:s.columnState??e.columnState,onDensityChange:e=>{R(s.id,s,{densityMode:e})},onSortChange:e=>{R(s.id,s,{sort:e})},onFilterChange:e=>{R(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{R(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{R(s.id,s,{columnState:e})},inlineEdit:s.inlineEdit??s.editRecordsInline??e.inlineEdit,appearance:s.appearance?s.showDescription==null?s.appearance:{...s.appearance,showDescription:s.showDescription}:s.showDescription==null?e.appearance:{showDescription:s.showDescription},showViewSwitcher:((s.appearance??e.appearance)?.allowedVisualizations?.length??0)>1,showSearch:s.showSearch??e.showSearch,showSort:s.showSort??e.showSort,showFilters:s.showFilters??e.showFilters,showHideFields:s.showHideFields??e.showHideFields,showGroup:s.showGroup??e.showGroup,showColor:s.showColor??e.showColor,showDensity:s.showDensity??e.showDensity,allowExport:s.allowExport??e.allowExport,exportOptions:s.allowExport===!1?void 0:s.exportOptions??e.exportOptions,striped:s.striped??e.striped,bordered:s.bordered??e.bordered,color:s.color??e.color,wrapHeaders:s.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:s.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:s.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:s.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:s.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:s.fieldTextColor??e.fieldTextColor,prefixField:s.prefixField??e.prefixField,showDescription:s.showDescription??e.showDescription,navigation:s.navigation??e.navigation,selection:s.selection??e.selection,pagination:s.pagination??e.pagination,searchableFields:s.searchableFields??e.searchableFields,filterableFields:s.filterableFields??e.filterableFields,resizable:s.resizable??e.resizable,rowActions:s.rowActions??e.rowActions,rowActionDefs:Array.isArray(H?.actions)?H.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)).map(e=>({...e,label:T(H.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:E(H.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:D(H.name,e.name,e.successMessage)}})):[],bulkActions:s.bulkActions??e.bulkActions,bulkActionDefs:s.bulkActionDefs??e.bulkActionDefs,sharing:s.sharing??e.sharing,addRecord:s.addRecord??e.addRecord,conditionalFormatting:s.conditionalFormatting??e.conditionalFormatting,quickFilters:void 0,userFilters:void 0,showRecordCount:s.showRecordCount??e.showRecordCount,allowPrinting:s.allowPrinting??e.allowPrinting,virtualScroll:s.virtualScroll??e.virtualScroll,emptyState:w(H.name,s.name||s.id||``,s.emptyState??e.emptyState??Mo(H?.managedBy,_,H.name)),aria:s.aria??e.aria,...(()=>{let e=Ho([...Array.isArray(s.filter)?s.filter:[],...et],Ge.id);return Array.isArray(e)&&e.length?{filters:e}:{}})(),...s.sort?.length?{sort:s.sort}:{},options:{kanban:{groupBy:s.kanban?.groupByField||s.kanban?.groupField||`status`,groupField:s.kanban?.groupByField||s.kanban?.groupField||`status`,titleField:s.kanban?.titleField||H.titleField||`name`,cardFields:s.kanban?.columns},calendar:{startDateField:s.calendar?.startDateField||`due_date`,endDateField:s.calendar?.endDateField,titleField:s.calendar?.titleField||`name`,colorField:s.calendar?.colorField,allDayField:s.calendar?.allDayField,defaultView:s.calendar?.defaultView},timeline:{dateField:s.timeline?.dateField||`due_date`,titleField:s.timeline?.titleField||H.titleField||`name`,descriptionField:s.timeline?.descriptionField},map:{locationField:s.map?.locationField,titleField:s.map?.titleField||H.titleField||`name`,latitudeField:s.map?.latitudeField,longitudeField:s.map?.longitudeField,zoom:s.map?.zoom,center:s.map?.center},gallery:{...s.gallery||{},imageField:s.gallery?.imageField||s.gallery?.coverField||`image`,coverField:s.gallery?.coverField||s.gallery?.imageField,titleField:s.gallery?.titleField||H.titleField||`name`,subtitleField:s.gallery?.subtitleField},gantt:{...s.gantt||{},startDateField:s.gantt?.startDateField||`start_date`,endDateField:s.gantt?.endDateField||`end_date`,titleField:s.gantt?.titleField||`name`},tree:{...s.tree||{},labelField:s.tree?.labelField||s.tree?.titleField||H.titleField||`name`},chart:{chartType:s.chart?.chartType,xAxisField:s.chart?.xAxisField,yAxisFields:s.chart?.yAxisFields,aggregation:s.chart?.aggregation,series:s.chart?.series,config:s.chart?.config}}},className:r,onEdit:n,onDelete:e=>{e?.id!=null&&Ke.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&Ke.execute({type:`delete`,confirmText:_(`console.objectView.bulkDeleteConfirm`,{count:t.length,defaultValue:`Delete ${t.length} selected records? This cannot be undone.`}),params:{records:t}})},onRowClick:(e,t)=>{at(e,t)},onSortChange:e=>{R(s.id,s,{sort:e})},onFilterChange:e=>{R(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{R(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{R(s.id,s,{columnState:e})},userFilterSelections:tt,onUserFilterSelectionsChange:nt,dataSource:t},o)},[G,H,c,he,q,Ke,R,et,tt,nt]),ct=(0,$.useMemo)(()=>W.map(e=>e.id===Ae&&L&&L.id===e.id?{...e,...L}:e),[W,Ae,L]),lt=(0,$.useMemo)(()=>({type:`object-view`,objectName:H.name,layout:`page`,showSearch:G?.showSearch!==!1,showFilters:G?.showFilters!==!1,showSort:G?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:B,viewActions:B?[{type:`settings`},{type:`share`},{type:`delete`}]:[],onNavigate:(e,t)=>{if(t===`edit`)n?.({id:e});else if(t===`view`){let t={from:{pathname:p.pathname+(p.search||``),label:x(H.name,G?.name??``,G?.label??``)||y(H)}};l?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[H,n,G?.showSearch,G?.showFilters,G?.showSort,G?.name,G?.label,i,l,B,p.pathname,p.search,x,y]);return(0,Q.jsxs)(S,{...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)(io,{title:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:y(H)}),(0,Q.jsx)(Ii,{managedBy:H?.managedBy})]}),description:H.description?b(H):void 0,icon:(0,Q.jsx)(zr(H?.icon),{className:`h-4 w-4`}),actions:(0,Q.jsxs)(Q.Fragment,{children:[c&&(0,Q.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:()=>M({id:`object:${c}`,label:y(H),href:`/apps/${o}/${c}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":j(`object:${c}`),"aria-label":j(`object:${c}`)?_(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):_(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${c}`,children:j(`object:${c}`)?(0,Q.jsx)(Ct,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Q.jsx)(Jt,{className:`h-4 w-4`})}),Se.create&&V(H.name,`create`)&&(0,Q.jsxs)(Y,{size:`sm`,onClick:Ke.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Q.jsx)(ut,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:_(`console.objectView.new`)})]}),Se.import&&V(H.name,`create`)&&(0,Q.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:()=>we(!0),className:`hidden sm:inline-flex shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,title:_(`console.objectView.importTitle`),"data-testid":`object-view-import-button`,children:[(0,Q.jsx)(Ln,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:_(`console.objectView.import`)})]}),H.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(ye?(0,Q.jsx)(Lo,{actions:xe,entitlements:be,onUpgrade:ge.openEntitlementDialog}):(0,Q.jsx)(C,{schema:{type:`action:bar`,location:`list_toolbar`,actions:xe,size:`sm`,variant:`outline`,mobileMaxVisible:0}}))]})})}),Se.create&&V(H.name,`create`)&&(0,Q.jsx)(`button`,{type:`button`,onClick:Ke.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":_(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,Q.jsx)(ut,{className:`h-5 w-5`})}),Ce&&(0,Q.jsx)($.Suspense,{fallback:null,children:(0,Q.jsx)(zo,{open:Ce,onOpenChange:we,objectName:H.name,objectLabel:y(H),fields:Object.entries(H.fields||{}).map(([e,t])=>({name:e,label:t?.label||e,type:t?.type||`text`,required:!!t?.required})),dataSource:e,onComplete:e=>{U(e=>e+1);let t=e.importedRows,n=e.skippedRows;n>0?Z.warning(_(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&Z.success(_(`console.objectView.importedToast`,{count:t}))}})}),W.length>=1&&(()=>{let e=W.map(e=>{let t=Te.find(t=>(t.id||t._id)===e.id),n=!t;return{id:e.id,label:x(H.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?_(`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)(Ei,{views:e,activeViewId:Ae,onViewChange:Ne,viewTypeIcons:Bo,config:{reorderable:!1,showAddButton:B,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:B?We:void 0,onRenameView:B?Re:void 0,onDeleteView:B?ze:void 0,onPinView:B?Be:void 0,onSetDefaultView:B?Ve:void 0,onConfigView:B?Ue:void 0,onManageViews:B?()=>I(!0):void 0}),B&&(0,Q.jsx)(wi,{open:oe,onOpenChange:I,views:e,activeViewId:Ae,viewTypeIcons:Bo,onRename:Re,onDelete:ze,onSetDefault:Ve,onSetPinned:Be,onReorder:He,onAddView:We,onConfigView:Ue})]})})})(),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[q.mode===`split`&&q.isOpen?(0,Q.jsx)(Qe,{...q,setIsOpen:e=>{e||it()},title:y(H),onExpand:ot,expandLabel:_(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${H.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)(Mi,{schema:lt,dataSource:e,views:ct,activeViewId:Ae,onViewChange:Ne,onEdit:e=>n?.(e),onRowClick:(e,t)=>{at(e,t)},renderListView:st,onCreateView:Fe,hideNamedViewTabs:!0,onViewAction:K})})}),typeof de==`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:_(`console.objectView.recordCount`,{count:de})})]}),children:r=>{let i=r.id||r._id;return(0,Q.jsx)(Qr,{dataSource:e,objects:t,onEdit:n,objectNameOverride:H.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)(Mi,{schema:lt,dataSource:e,views:ct,activeViewId:Ae,onViewChange:Ne,onEdit:e=>n?.(e),onRowClick:(e,t)=>{at(e,t)},renderListView:st,onCreateView:Fe,hideNamedViewTabs:!0,onViewAction:K})})})}),(0,Q.jsx)(hi,{open:h&&B,sections:[{title:`View Configuration`,data:G},{title:`Object Definition`,data:H}]}),(0,Q.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${P&&B?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,Q.jsx)(Do,{open:P&&B,onClose:()=>{ne(!1),F(`edit`)},mode:re,activeView:G,objectDef:H,recordCount:de,onSave:z,onViewUpdate:Me,onCreate:ue,metadataClient:te,onAfterChange:()=>U(e=>e+1)})}),(0,Q.jsx)(jo,{open:ie&&B,onOpenChange:ae,existingLabels:W.map(e=>e.label).filter(Boolean),objectDef:H,onCreate:e=>ue(e)})]}),q.mode!==`split`&&(0,Q.jsx)(Qe,{...q,setIsOpen:e=>{e||it()},title:y(H),onExpand:ot,expandLabel:_(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${H.name}`,children:r=>{let i=r.id||r._id;return(0,Q.jsx)(Qr,{dataSource:e,objects:t,onEdit:n,objectNameOverride:H.name,recordIdOverride:i,embedded:!0})}})]}),ge.dialogs]})}function Go({appName:e,error:t,onRetry:n}){let{t:r}=O(),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)(Je,{children:[(0,Q.jsx)(`div`,{className:`mb-2 flex justify-center text-muted-foreground`,"aria-hidden":`true`,children:i?(0,Q.jsx)(fe,{className:`h-8 w-8`}):(0,Q.jsx)(de,{className:`h-8 w-8`})}),(0,Q.jsx)(un,{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)(it,{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)(Y,{variant:`outline`,onClick:n,"data-testid":`preview-draft-retry`,children:[(0,Q.jsx)(et,{className:`mr-1.5 h-3.5 w-3.5`}),r(`preview.empty.retry`,{defaultValue:`Retry`})]})})]})})}var Ko=(0,$.lazy)(()=>c(()=>import(`./RecordDetailView-B-AuOKPI.js`).then(e=>e.n).then(e=>({default:e.RecordDetailView})),__vite__mapDeps([0]),import.meta.url)),qo=(0,$.lazy)(()=>c(()=>import(`./DashboardView-mIWO-jW_.js`).then(e=>e.t).then(e=>({default:e.DashboardView})),__vite__mapDeps([0,1]),import.meta.url)),Jo=(0,$.lazy)(()=>c(()=>import(`./PageView-DuiaqvzN.js`).then(e=>e.t).then(e=>({default:e.PageView})),__vite__mapDeps([0]),import.meta.url)),Yo=(0,$.lazy)(()=>c(()=>import(`./ReportView-Cw9Ompki.js`).then(e=>e.t).then(e=>({default:e.ReportView})),__vite__mapDeps([0,1]),import.meta.url)),Xo=(0,$.lazy)(()=>c(()=>import(`./SearchResultsPage-CZ038ncU.js`).then(e=>e.t).then(e=>({default:e.SearchResultsPage})),__vite__mapDeps([0]),import.meta.url)),Zo=(0,$.lazy)(()=>c(()=>import(`./RecordFormPage-CpKMoOCj.js`).then(e=>e.t).then(e=>({default:e.RecordFormPage})),__vite__mapDeps([0]),import.meta.url)),Qo=(0,$.lazy)(()=>c(()=>import(`./ComponentNavView-g9qw3mhW.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),$o=(0,$.lazy)(()=>c(()=>import(`./metadata-admin-DStYGsRM.js`).then(e=>e.t).then(e=>({default:e.MetadataDirectoryPage})),__vite__mapDeps([0]),import.meta.url)),es=(0,$.lazy)(()=>c(()=>import(`./metadata-admin-DStYGsRM.js`).then(e=>e.t).then(e=>({default:e.StudioHomePage})),__vite__mapDeps([0]),import.meta.url)),ts=(0,$.lazy)(()=>c(()=>import(`./metadata-admin-DStYGsRM.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceListPage})),__vite__mapDeps([0]),import.meta.url)),ns=(0,$.lazy)(()=>c(()=>import(`./metadata-admin-DStYGsRM.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceEditPage})),__vite__mapDeps([0]),import.meta.url)),rs=(0,$.lazy)(()=>c(()=>import(`./metadata-admin-DStYGsRM.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceHistoryPage})),__vite__mapDeps([0]),import.meta.url)),is=(0,$.lazy)(()=>c(()=>import(`./metadata-admin-DStYGsRM.js`).then(e=>e.t).then(e=>({default:e.MetadataDiagnosticsPage})),__vite__mapDeps([0]),import.meta.url)),as=(0,$.lazy)(()=>c(()=>import(`./index-BQhiWf8_.js`).then(e=>e.t).then(e=>({default:e.CreateAppPage})),__vite__mapDeps([0,2]),import.meta.url)),os=(0,$.lazy)(()=>c(()=>import(`./index-BQhiWf8_.js`).then(e=>e.t).then(e=>({default:e.EditAppPage})),__vite__mapDeps([0,2]),import.meta.url)),ss=(0,$.lazy)(()=>c(()=>import(`./index-BQhiWf8_.js`).then(e=>e.t).then(e=>({default:e.DashboardDesignPage})),__vite__mapDeps([0,2]),import.meta.url)),cs=(0,$.lazy)(()=>c(()=>import(`./MarketplacePage-C2B6TMNM.js`).then(e=>e.t).then(e=>({default:e.MarketplacePage})),__vite__mapDeps([0]),import.meta.url)),ls=(0,$.lazy)(()=>c(()=>import(`./MarketplacePackagePage-Bihb2q1b.js`).then(e=>e.t).then(e=>({default:e.MarketplacePackagePage})),__vite__mapDeps([0]),import.meta.url)),us=(0,$.lazy)(()=>c(()=>import(`./MarketplaceInstalledPage-C41H1YlB.js`).then(e=>e.t).then(e=>({default:e.MarketplaceInstalledPage})),__vite__mapDeps([0]),import.meta.url));function ds({appName:e}){let{reviewSeq:t,reviewTarget:n}=Xn(),r=m(),i=(0,$.useRef)(t);return(0,$.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 fs({extraRoutes:e,extraRoutesNoApp:t}={}){let[i,o]=(0,$.useState)(`disconnected`),{user:c,getAuthConfig:l}=g(),u=b(),[d,p]=(0,$.useState)({});(0,$.useEffect)(()=>{let e=!1;return l().then(t=>{e||p(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[l]);let h=m(),_=s(),{appName:v}=a(),{apps:y,objects:S,loading:C,ensureType:w,error:T,refresh:E}=k(),ee=Wn(),{t:A}=O(),{objectLabel:j}=Ie(),[N,te]=(0,$.useState)(!w);(0,$.useEffect)(()=>{if(!w){te(!0);return}let e=!1;return Promise.all([w(`object`),w(`dashboard`),w(`report`),w(`page`)]).finally(()=>{e||te(!0)}),()=>{e=!0}},[w]);let P=y.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),ne=_.pathname.endsWith(`/create-app`),re=_.pathname.includes(`/system`),F=_.pathname.includes(`/metadata`),ie=_.pathname===`/apps/setup`||_.pathname.startsWith(`/apps/setup/`),ae=ne||re||F||ie,oe=ai(y,v),I=oe||(!v||ae?P.find(e=>e.isDefault===!0)||P[0]:void 0),L=!!v&&!oe&&!ae,[se,ce]=(0,$.useState)(`idle`);(0,$.useEffect)(()=>{if(!L){se!==`idle`&&ce(`idle`);return}se===`idle`&&!C&&!ee&&(ce(`checking`),Promise.resolve(E()).finally(()=>ce(`done`)))},[L,C,ee,se,E]),(0,$.useEffect)(()=>{if(!I?.name)return;let e=v??I.name,t=`/apps/${e}/metadata/package`;(_.pathname===t||_.pathname.startsWith(`${t}/`))&&h(`/apps/${e}/component/developer/packages`,{replace:!0})},[I?.name,v,_.pathname,h]);let[le,R]=(0,$.useState)(!1),[z,ue]=(0,$.useState)(null),[de,fe]=(0,$.useState)(0),{execute:pe,runner:me}=x();D({dataSource:u??void 0,onUndo:e=>{Z.info(`Undo: ${e.description}`,{duration:4e3}),fe(e=>e+1)},onRedo:e=>{Z.info(`Redo: ${e.description}`,{duration:3e3}),fe(e=>e+1)}}),(0,$.useEffect)(()=>{me.registerHandler(`crud_success`,async e=>(R(!1),fe(e=>e+1),Z.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),me.registerHandler(`dialog_cancel`,async()=>(R(!1),{success:!0})),me.registerHandler(`navigate_create`,async e=>{let t=ci({action:e,context:me.getContext?.()??{},defaultBaseUrl:`/apps/${v??``}`});return t.success?(h(t.url),{success:!0}):t}),me.registerHandler(`navigate_edit`,async e=>{let t=li({action:e,context:me.getContext?.()??{},defaultBaseUrl:`/apps/${v??``}`});return t.success?(h(t.url),{success:!0}):t})},[me,h,v]),(0,$.useEffect)(()=>{if(!u)return;let e=u.onConnectionStateChange(e=>{o(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return o(u.getConnectionState()),e},[u]);let B=_.pathname.split(`/`).filter(Boolean)[2];(B===`view`||B===`record`||B===`page`||B===`dashboard`||B===`design`)&&(B=``);let V=S.find(e=>e.name===B),H=(0,$.useCallback)(()=>{let e=V?j(V):A(`common.record`,{defaultValue:`Record`});pe({type:`crud_success`,params:{message:z?A(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):A(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[pe,z,V,j,A]),he=(0,$.useCallback)(()=>{pe({type:`dialog_cancel`})},[pe]);fr({pathname:_.pathname,appName:I?.name,objects:S});let U=e=>{let t=si({objectDef:V,baseUrl:v?`/apps/${v}`:I?.name?`/apps/${I.name}`:``,record:e});if(t.kind===`page`){h(t.url);return}ue(e),R(!0)},ge=e=>{h(`/apps/${e}`)},_e=(0,$.useMemo)(()=>new M({user:c?{name:c.name,email:c.email,role:c.role??`user`}:{},app:I||{},data:z||{}}),[c,I,z]);return!u||C||!N?(0,Q.jsx)(uo,{}):ee&&(L||!I)?(0,Q.jsx)(Go,{appName:v,error:T,onRetry:()=>void E()}):L?se===`done`?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(Je,{children:[(0,Q.jsx)(un,{children:A(`empty.appNotAvailable`,{defaultValue:`App not available`})}),(0,Q.jsx)(it,{children:A(`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)(Y,{onClick:()=>ce(`idle`),"data-testid":`app-not-available-retry`,children:A(`common.retry`,{defaultValue:`Retry`})})})]})}):(0,Q.jsx)(uo,{}):!I&&!ne&&!re&&!F?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(Je,{children:[(0,Q.jsx)(un,{children:A(`empty.noAppsConfigured`)}),(0,Q.jsx)(it,{children:A(`empty.noAppsConfiguredDescription`)}),(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,Q.jsx)(Y,{onClick:()=>h(`/create-app`),"data-testid":`create-first-app-btn`,children:A(`empty.createFirstApp`)}),(0,Q.jsx)(Y,{variant:`outline`,onClick:()=>h(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:A(`empty.systemSettings`)})]})]})}):!I&&(ne||re||F)?(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(uo,{}),children:(0,Q.jsxs)(r,{children:[(0,Q.jsx)(f,{path:`create-app`,element:(0,Q.jsx)(as,{})}),(0,Q.jsx)(f,{path:`system/marketplace`,element:(0,Q.jsx)(cs,{})}),(0,Q.jsx)(f,{path:`system/marketplace/installed`,element:(0,Q.jsx)(us,{})}),(0,Q.jsx)(f,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(ls,{})}),(0,Q.jsx)(f,{path:`metadata`,element:(0,Q.jsx)($o,{})}),(0,Q.jsx)(f,{path:`metadata/_diagnostics`,element:(0,Q.jsx)(is,{})}),(0,Q.jsx)(f,{path:`metadata/:type`,element:(0,Q.jsx)(ts,{})}),(0,Q.jsx)(f,{path:`metadata/:type/new`,element:(0,Q.jsx)(ns,{createMode:!0})}),(0,Q.jsx)(f,{path:`metadata/:type/:name`,element:(0,Q.jsx)(ns,{})}),(0,Q.jsx)(f,{path:`metadata/:type/:name/history`,element:(0,Q.jsx)(rs,{})}),t]})}):(0,Q.jsxs)($n,{user:c?{id:c.id,name:c.name,email:c.email,role:c.role??`user`,roles:c.roles,isPlatformAdmin:c.isPlatformAdmin??!1}:{name:`Anonymous`,email:``,role:`guest`,isPlatformAdmin:!1},app:I,data:{},features:d,children:[(0,Q.jsx)(nr,{}),(0,Q.jsxs)(ro,{activeAppName:I.name,activeApp:I,onAppChange:ge,objects:S,connectionState:i,userId:c?.id,children:[(0,Q.jsx)(ao,{apps:y,activeApp:I,objects:S,onAppChange:ge,dataSource:u}),(0,Q.jsx)(so,{}),(0,Q.jsx)(co,{}),(0,Q.jsx)(ds,{appName:v}),(0,Q.jsx)(xo,{children:(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(uo,{}),children:(0,Q.jsx)(mo,{className:`h-full`,children:(0,Q.jsxs)(r,{children:[(0,Q.jsx)(f,{path:`/`,element:(()=>{let e=gs(I,{currentUserId:c?.id??null});return e?(0,Q.jsx)(n,{to:e,replace:!0}):(0,Q.jsx)(es,{})})()}),(0,Q.jsx)(f,{path:`metadata/package/*`,element:(0,Q.jsx)(n,{to:`/apps/${v??I.name}/component/developer/packages`,replace:!0})}),(0,Q.jsxs)(f,{path:`metadata`,children:[(0,Q.jsx)(f,{index:!0,element:(0,Q.jsx)($o,{})}),(0,Q.jsx)(f,{path:`_diagnostics`,element:(0,Q.jsx)(is,{})}),(0,Q.jsx)(f,{path:`:type`,element:(0,Q.jsx)(ts,{})}),(0,Q.jsx)(f,{path:`:type/new`,element:(0,Q.jsx)(ns,{createMode:!0})}),(0,Q.jsx)(f,{path:`:type/:name`,element:(0,Q.jsx)(ns,{})}),(0,Q.jsx)(f,{path:`:type/:name/history`,element:(0,Q.jsx)(rs,{})})]}),(0,Q.jsx)(f,{path:`:objectName`,element:(0,Q.jsx)(Uo,{dataSource:u,objects:S,onEdit:U,externalRefreshKey:de})}),(0,Q.jsx)(f,{path:`:objectName/new`,element:(0,Q.jsx)(Zo,{mode:`create`})}),(0,Q.jsx)(f,{path:`:objectName/view/:viewId`,element:(0,Q.jsx)(Uo,{dataSource:u,objects:S,onEdit:U,externalRefreshKey:de})}),(0,Q.jsx)(f,{path:`:objectName/record/:recordId`,element:(0,Q.jsx)(Ko,{dataSource:u,objects:S,onEdit:U},de)}),(0,Q.jsx)(f,{path:`:objectName/record/:recordId/edit`,element:(0,Q.jsx)(Zo,{mode:`edit`})}),(0,Q.jsx)(f,{path:`dashboard/:dashboardName`,element:(0,Q.jsx)(qo,{dataSource:u})}),(0,Q.jsx)(f,{path:`report/:reportName`,element:(0,Q.jsx)(Yo,{dataSource:u})}),(0,Q.jsx)(f,{path:`page/:pageName`,element:(0,Q.jsx)(Jo,{})}),(0,Q.jsx)(f,{path:`component/:ns/:name/*`,element:(0,Q.jsx)(Qo,{})}),(0,Q.jsx)(f,{path:`component/metadata/directory`,element:(0,Q.jsx)(ys,{mode:`directory`})}),(0,Q.jsx)(f,{path:`component/metadata/resource/*`,element:(0,Q.jsx)(ys,{mode:`resource`})}),(0,Q.jsx)(f,{path:`design/dashboard/:dashboardName`,element:(0,Q.jsx)(ss,{})}),(0,Q.jsx)(f,{path:`search`,element:(0,Q.jsx)(Xo,{})}),(0,Q.jsx)(f,{path:`create-app`,element:(0,Q.jsx)(as,{})}),(0,Q.jsx)(f,{path:`edit-app/:editAppName`,element:(0,Q.jsx)(os,{})}),(0,Q.jsx)(f,{path:`system/marketplace`,element:(0,Q.jsx)(cs,{})}),(0,Q.jsx)(f,{path:`system/marketplace/installed`,element:(0,Q.jsx)(us,{})}),(0,Q.jsx)(f,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(ls,{})}),e,(0,Q.jsx)(f,{path:`:objectName/:maybeRecordId`,element:(0,Q.jsx)(bs,{})}),(0,Q.jsx)(f,{path:`*`,element:(0,Q.jsx)(xs,{})})]})})})}),V&&(0,Q.jsx)(Un,{schema:{type:`object-form`,formType:`modal`,objectName:V.name,mode:z?`edit`:`create`,recordId:z?.id,...ui(V),title:A(z?`form.editTitle`:`form.createTitle`,{object:j(V)}),description:A(z?`form.editDescription`:`form.createDescription`,{object:j(V)}),open:le,onOpenChange:R,layout:`vertical`,fields:V.fields?Array.isArray(V.fields)?V.fields.filter(e=>typeof e==`string`?!0:Zn(e.visible,_e)).map(e=>typeof e==`string`?e:e.name):Object.entries(V.fields).filter(([e,t])=>Zn(t.visible,_e)).map(([e])=>e):[],onSuccess:H,onCancel:he,showSubmit:!0,showCancel:!0,submitText:z?A(`form.update`,{defaultValue:A(`common.save`,{defaultValue:`Save`})}):A(`form.create`,{defaultValue:A(`common.create`,{defaultValue:`Create`})}),cancelText:A(`common.cancel`)},dataSource:u},z?.id||`new`)]})]})}function ps(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=ms(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=ps(n.children,t);if(e!==``)return e}}return``}function ms(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=ei(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function hs(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=hs(n.children,t);if(e)return e}}}function gs(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=ms(hs(r,n),t);if(e)return e}return ps(r,t)}var _s=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function vs(e){return!e||_s.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function ys({mode:e}){let t=s(),r=t.pathname.replace(/\/component\/metadata\/.*$/,``);if(e===`directory`)return(0,Q.jsx)(n,{to:`${r}/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)(n,{to:i?`${r}/metadata/${encodeURIComponent(i)}${a}${t.hash}`:`${r}/metadata${t.hash}`,replace:!0})}function bs(){let{objectName:e,maybeRecordId:t}=a(),r=s();return e&&vs(t)?(0,Q.jsx)(n,{to:`${r.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${r.search}${r.hash}`,replace:!0}):(0,Q.jsx)(xs,{})}function xs(){let e=m(),{t}=O();return(0,Q.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,Q.jsxs)(Je,{children:[(0,Q.jsx)(un,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Q.jsx)(it,{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)(Y,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function Ss({children:e,userId:t}){let{setContext:n}=$r(),{t:r}=O(),{enabled:i}=Lr();return(0,$.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)(to,{variant:`home`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),i&&(0,Q.jsx)(sa,{appLabel:r(`workspace.default`,{defaultValue:`Workspace`}),objects:[],userId:t})]})}var Cs=19,ws=[`from-blue-500 to-indigo-600`,`from-violet-500 to-purple-600`,`from-pink-500 to-rose-600`,`from-amber-400 to-orange-500`,`from-emerald-500 to-teal-600`,`from-sky-500 to-cyan-600`,`from-fuchsia-500 to-pink-600`,`from-orange-500 to-red-600`,`from-indigo-500 to-blue-600`,`from-teal-500 to-green-600`],Ts=`shadow-[0_4px_10px_-2px_rgb(0_0_0/0.25),inset_0_1px_0_0_rgb(255_255_255/0.45)]`;function Es(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function Ds({apps:e,favorites:t,onOpen:n,onBrowseMarketplace:r,isAdmin:i}){let{t:a}=O(),{appLabel:o}=Ie(),[s,c]=(0,$.useState)(!1),l=(0,$.useMemo)(()=>new Set(t.filter(e=>e.id.startsWith(`app:`)).map(e=>e.id.slice(4))),[t]),u=(0,$.useMemo)(()=>[...e].sort((e,t)=>!!l.has(t.name)-+!!l.has(e.name)),[e,l]),d=u.length-Cs,f=s?u:u.slice(0,Cs);return(0,Q.jsxs)(`section`,{className:`mb-6`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2.5`,children:[(0,Q.jsx)(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-xl border border-border bg-muted text-muted-foreground`,children:(0,Q.jsx)(_e,{className:`h-4 w-4`})}),(0,Q.jsx)(`h2`,{className:`text-base font-semibold tracking-tight`,children:a(`home.yourApps`,{defaultValue:`Your apps`})}),(0,Q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:u.length}),i&&(0,Q.jsxs)(Y,{variant:`ghost`,size:`sm`,className:`ml-auto h-8 text-muted-foreground`,onClick:r,"data-testid":`browse-marketplace-btn`,children:[(0,Q.jsx)(nn,{className:`mr-1.5 h-4 w-4`}),a(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]})]}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-4 gap-1 sm:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10`,children:[f.map(e=>{let t=zr(e.icon),r=o({name:e.name,label:di(e.label,a)}),i=l.has(e.name),s=ws[Es(e.name)%ws.length];return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:`group relative flex flex-col items-center gap-2 rounded-xl p-2.5 text-center transition hover:bg-muted/40 active:scale-[0.96]`,"data-testid":`app-tile-${e.name}`,children:[(0,Q.jsxs)(`span`,{className:G(`relative inline-flex h-12 w-12 items-center justify-center rounded-[13px]`,`bg-gradient-to-br text-white transition-transform group-hover:scale-105`,Ts,s),children:[(0,Q.jsx)(t,{className:`h-6 w-6`}),i&&(0,Q.jsx)(`span`,{className:`absolute -right-1 -top-1 inline-flex h-4 w-4 items-center justify-center rounded-full bg-amber-400 ring-2 ring-background`,children:(0,Q.jsx)(Ct,{className:`h-2.5 w-2.5 fill-white text-white`})})]}),(0,Q.jsx)(`span`,{className:`w-full truncate text-xs font-medium`,children:r})]},e.name)}),!s&&d>0&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>c(!0),className:`group flex flex-col items-center gap-2 rounded-xl p-2.5 text-center transition hover:bg-muted/40 active:scale-[0.96]`,"data-testid":`apps-show-all`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex h-12 w-12 items-center justify-center rounded-[13px] border border-dashed border-border text-sm font-medium text-muted-foreground transition-colors group-hover:border-foreground/30 group-hover:text-foreground`,children:[`+`,d]}),(0,Q.jsx)(`span`,{className:`w-full truncate text-xs text-muted-foreground`,children:a(`home.showMoreApps`,{defaultValue:`More`})})]})]}),s&&d>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>c(!1),className:`mt-2.5 text-xs text-primary hover:underline`,children:a(`home.showLess`,{defaultValue:`Show less`})})]})}function Os(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 ks({icon:e,title:t,count:n,accent:r,children:i}){return(0,Q.jsxs)(`section`,{className:`rounded-2xl bg-card/80 backdrop-blur-sm p-4 `+(r?`border border-primary/30`:`border border-border/70`),children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,Q.jsx)(e,{className:`h-4 w-4 `+(r?`text-primary`:`text-muted-foreground`)}),(0,Q.jsx)(`h2`,{className:`flex-1 text-sm font-semibold tracking-tight`,children:t}),typeof n==`number`&&n>0&&(0,Q.jsx)(`span`,{className:`inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-[11px] font-medium text-primary-foreground tabular-nums`,children:n})]}),i]})}function As({icon:e,iconClass:t,label:n,meta:r,trailing:i,onClick:a,testId:o}){return(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`button`,{type:`button`,onClick:a,"data-testid":o,className:`flex w-full items-center gap-3 rounded-lg px-2 py-2 text-left transition hover:bg-muted/60 active:scale-[0.99]`,children:[(0,Q.jsx)(`span`,{className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-lg `+t,children:(0,Q.jsx)(e,{className:`h-4 w-4`})}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,children:n}),r&&(0,Q.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:r}),i]})})}function js({pendingApprovalsCount:e,notifications:t,onOpenApprovals:n,onOpenNotification:r,t:i}){let a=e+t.length;return(0,Q.jsx)(ks,{icon:Zt,accent:!0,count:a,title:i(`home.actionCenter.title`,{defaultValue:`Needs your attention`}),children:a===0?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(Xe,{className:`h-4 w-4 text-emerald-500`}),i(`home.actionCenter.empty`,{defaultValue:`You're all caught up`})]}):(0,Q.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[e>0&&(0,Q.jsx)(As,{icon:Zt,iconClass:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:i(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:e}),trailing:(0,Q.jsx)(bt,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),onClick:n,testId:`home-action-approvals`}),t.map(e=>(0,Q.jsx)(As,{icon:Dt,iconClass:`bg-primary/10 text-primary`,label:e.title,meta:Os(e.createdAt),onClick:()=>r(e)},e.id))]})})}var Ms={object:Cn,record:K,dashboard:st,page:Ht},Ns={object:`bg-blue-500/10 text-blue-600 dark:text-blue-400`,record:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,dashboard:`bg-violet-500/10 text-violet-600 dark:text-violet-400`,page:`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`};function Ps({items:e,onOpen:t,t:n}){return(0,Q.jsx)(ks,{icon:zt,title:n(`home.recentApps.title`,{defaultValue:`Recently Accessed`}),children:e.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`home.continueEmpty`,{defaultValue:`Items you open will show up here.`})}):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:e.map(e=>(0,Q.jsx)(As,{icon:Ms[e.type]||K,iconClass:Ns[e.type]||`bg-muted text-muted-foreground`,label:e.label,meta:n(`home.recentApps.itemType.${e.type}`,{defaultValue:e.type}),onClick:()=>t(e.href)},e.id))})})}function Fs({items:e,onViewAll:t,t:n}){return(0,Q.jsxs)(ks,{icon:ce,title:n(`sidebar.activityFeed`,{defaultValue:`Activity`}),children:[e.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`layout.activityFeed.empty`,{defaultValue:`No recent activity`})}):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:e.slice(0,5).map(e=>(0,Q.jsxs)(`li`,{className:`text-sm leading-snug`,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:`mt-0.5 text-[11px] text-muted-foreground`,children:[Os(e.timestamp),` · `,e.objectName]})]},e.id))}),(0,Q.jsxs)(`button`,{type:`button`,onClick:t,className:`mt-3 inline-flex items-center gap-1 text-xs text-primary hover:underline`,children:[n(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`}),(0,Q.jsx)(bt,{className:`h-3 w-3`})]})]})}function Is(e=5){let t=b(),{user:n}=g(),[r,i]=(0,$.useState)(0),[a,o]=(0,$.useState)([]),[s,c]=(0,$.useState)([]),l=(0,$.useRef)(!0);return(0,$.useEffect)(()=>(l.current=!0,()=>{l.current=!1}),[]),(0,$.useEffect)(()=>{if(!t)return;let n=!1;return Promise.resolve(t.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20})).then(t=>{n||!l.current||c((Array.isArray(t?.data)?t.data:[]).filter(e=>{if(!e||typeof e.type!=`string`||!(e.summary??``).toString().trim())return!1;let t=String(e.actor_name??``).trim();return t.length>0&&t.toLowerCase()!==`system`}).map(e=>{let t=e.timestamp;(!t||t===`NOW()`||Number.isNaN(Date.parse(t)))&&(t=e.created_at);let n=String(e.type),r=n===`commented`||n===`mentioned`?`comment`:n===`deleted`?`delete`:n===`created`?`create`:`update`;return{id:String(e.id),type:r,objectName:e.object_name??``,recordId:e.record_id??void 0,user:e.actor_name??`System`,description:e.summary??``,timestamp:t??``}}).slice(0,e))}).catch(()=>{}),()=>{n=!0}},[t,e]),(0,$.useEffect)(()=>{if(!t||!n?.id)return;let r=!1;return Promise.resolve(t.find(`sys_inbox_message`,{$filter:{user_id:n.id},$orderby:{created_at:`desc`},$top:e})).then(e=>{if(r||!l.current)return;let t=Array.isArray(e?.data)?e.data:[],n=new Set;o(t.filter(e=>e&&(e.title??``).toString().trim()).map(e=>({id:String(e.id),title:String(e.title),actionUrl:e.action_url??void 0,createdAt:e.created_at??void 0})).filter(e=>n.has(e.title)?!1:(n.add(e.title),!0)))}).catch(()=>{}),()=>{r=!0}},[t,n?.id,e]),(0,$.useEffect)(()=>{if(!n?.id)return;let e=``.replace(/\/$/,``),t=[];n.id&&t.push(n.id),n.email&&t.push(n.email);for(let e of n.roles||[])e&&t.push(`role:${e}`);if(t.length===0)return;let r=!1,a=new URLSearchParams({status:`pending`,approverId:t.join(`,`)});return fetch(`${e}/api/v1/approvals/requests?${a}`,{credentials:`include`}).then(async e=>{if(!e.ok)return;let t=await e.json().catch(()=>null),n=new Set;for(let e of t?.data||[])n.add(e.id);!r&&l.current&&i(n.size)}).catch(()=>{}),()=>{r=!0}},[n?.id]),{pendingApprovalsCount:r,notifications:a,activities:s}}function Ls(){let{agents:e}=wr({apiBase:(0,$.useMemo)(()=>Wr(),[])});return{aiEnabled:e.length>0,askAvailable:e.some(e=>Er(e.name)),buildAvailable:e.some(e=>Tr(e.name))}}function Rs({askAvailable:e,buildAvailable:t,navigate:n,t:r,layout:i=`row`}){return!e&&!t?null:(0,Q.jsxs)(`div`,{className:i===`stack`?`mt-6 flex flex-col sm:flex-row items-center gap-3`:`flex shrink-0 items-center gap-2`,children:[t&&(0,Q.jsxs)(Y,{onClick:()=>n(`/ai/build`),"data-testid":`home-build-with-ai`,children:[(0,Q.jsx)(Lt,{className:`mr-2 h-4 w-4`}),r(`home.buildWithAI`,{defaultValue:`Build with AI`})]}),e&&(0,Q.jsxs)(Y,{variant:t?`outline`:`default`,onClick:()=>n(`/ai/ask`),"data-testid":`home-ask-ai`,children:[(0,Q.jsx)(Wt,{className:`mr-2 h-4 w-4`}),r(`home.askAI`,{defaultValue:`Ask AI`})]})]})}function zs(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function Bs({t:e}){let t=ri(),[n,r]=(0,$.useState)([]),{publishAll:i,publishing:a}=ca(e),o=n.length;return(0,$.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)(Pt,{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)(Y,{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 Vs({t:e}){let t=m(),{hasLocalPassword:n}=g(),[r,i]=(0,$.useState)(!1);return(0,$.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)(I,{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)(Y,{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)(Ne,{className:`h-4 w-4`})})]})})}):null}function Hs(){let e=m(),{t}=O(),{apps:n,loading:r}=k(),{recentItems:i}=gr(),{favorites:a}=hr(),{user:o}=g(),s=h(),{pendingApprovalsCount:c,notifications:l,activities:u}=Is(),{askAvailable:d,buildAvailable:f}=Ls(),p=n.filter(e=>e.active!==!1&&e.hidden!==!0),_=i.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,6),v=(0,$.useMemo)(()=>t(zs(new Date().getHours()),{defaultValue:`Welcome`}),[t]),y=(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…`})})}):p.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col flex-1`,children:[(0,Q.jsx)(Bs,{t}),(0,Q.jsx)(Vs,{t}),(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:s?(0,Q.jsxs)(Je,{children:[(0,Q.jsx)(un,{children:t(`home.welcome`,{product:vi().branding.productName,defaultValue:`Welcome to {{product}}`})}),(0,Q.jsx)(it,{children:f?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.`}):d?t(`home.welcomeAdminDescriptionNoBuild`,{defaultValue:`Set up your first application from the Administration menu on the left. Once you have data, the AI assistant can help you explore it.`}):t(`home.welcomeAdminDescriptionNoAi`,{defaultValue:`Set up your first application from the Administration menu on the left.`})}),(0,Q.jsx)(Rs,{askAvailable:d,buildAvailable:f,navigate:e,t,layout:`stack`})]}):(0,Q.jsxs)(Je,{children:[(0,Q.jsx)(un,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,Q.jsx)(it,{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)(Bs,{t}),(0,Q.jsx)(Vs,{t}),(0,Q.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-8 pb-16`,children:(0,Q.jsxs)(`div`,{className:`max-w-7xl mx-auto`,children:[(0,Q.jsxs)(`div`,{className:`mb-7 flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight text-pretty`,children:[(0,Q.jsxs)(`span`,{className:`text-foreground`,children:[v,y?`, `:``]}),y&&(0,Q.jsx)(`span`,{className:`text-primary`,children:y}),(0,Q.jsx)(`span`,{className:`text-foreground/40`,children:`.`})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm sm:text-base text-muted-foreground`,children:t(`home.heroTagline`,{defaultValue:`Pick up where you left off, or explore something new.`})})]}),(0,Q.jsx)(Rs,{askAvailable:d,buildAvailable:f,navigate:e,t})]}),(0,Q.jsx)(Ds,{apps:p,favorites:a,onOpen:t=>e(`/apps/${oi(t)??t.name}`),onBrowseMarketplace:()=>e(`/apps/setup/system/marketplace`),isAdmin:s}),(0,Q.jsx)(`div`,{className:`mb-6`,children:(0,Q.jsx)(js,{pendingApprovalsCount:c,notifications:l,onOpenApprovals:()=>e(`/apps/setup/system/approvals`),onOpenNotification:t=>e(t.actionUrl||`/apps/setup/sys_inbox_message?view=mine`),t})}),(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,Q.jsx)(Ps,{items:_,onOpen:t=>e(t),t}),(0,Q.jsx)(Fs,{items:u,onViewAll:()=>e(`/apps/setup/sys_activity`),t})]})]})})]})}function Us({children:e}){let{setContext:t}=$r();return(0,$.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)(to,{variant:`orgs`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}async function Ws(e){let t=await _()(`${_i()}/api/v1/cloud/environments`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({displayName:e.displayName??`Production`,organizationId:e.organizationId})});if(!t.ok){if(t.status===403||t.status===409)return{alreadyProvisioned:!0};throw Error(`Failed to provision production environment (status ${t.status})`)}let n=await t.json().catch(()=>({}));return n&&typeof n==`object`&&`data`in n&&n.data?n.data:n??{}}function Gs(e){return e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48)}function Ks({open:e,onOpenChange:t,onCreated:n}){let{t:r}=O(),{createOrganization:i,getAuthConfig:a}=g(),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(``),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(!1),[m,h]=(0,$.useState)(null),[_,v]=(0,$.useState)(!1);return(0,$.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||v(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,$.useEffect)(()=>{u||l(Gs(o))},[o,u]),(0,$.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,Q.jsx)(Ye,{open:e,onOpenChange:t,children:(0,Q.jsx)(at,{className:`sm:max-w-[425px]`,"data-testid":`create-workspace-dialog`,children:(0,Q.jsxs)(`form`,{onSubmit:(0,$.useCallback)(async e=>{if(e.preventDefault(),!(!o.trim()||!c.trim())){if(_){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()});try{await Ws({organizationId:e.id})}catch(e){console.warn(`[CreateWorkspace] eager env provision failed; onboarding gate will provision lazily`,e)}n?.(e)}catch(e){h(e instanceof Error?e.message:`Failed to create workspace`)}finally{p(!1)}}},[o,c,_,r,i,n]),children:[(0,Q.jsxs)(dn,{children:[(0,Q.jsx)(ve,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Q.jsx)(ue,{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)(Ot,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,Q.jsx)(_n,{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)(Ot,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,Q.jsx)(_n,{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)(xe,{children:[(0,Q.jsx)(Y,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(Y,{type:`submit`,disabled:f||!o.trim()||!c.trim(),"data-testid":`workspace-create-submit`,children:[f&&(0,Q.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function qs(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Js(){let{t:e}=O(),t=m(),[n]=u(),r=n.get(`manage`)===`1`,i=n.get(`create`)===`1`,{organizations:a,activeOrganization:o,isOrganizationsLoading:s,switchOrganization:c,getAuthConfig:l}=g(),[d,f]=(0,$.useState)(``),[p,h]=(0,$.useState)(!1),[_,v]=(0,$.useState)(null),[y,b]=(0,$.useState)(!0);(0,$.useEffect)(()=>{let e=!1;return l().then(t=>{e||t?.features?.multiOrgEnabled===!1&&b(!1)}).catch(()=>{}),()=>{e=!0}},[l]);let x=a??[],S=(0,$.useMemo)(()=>{let e=d.trim().toLowerCase();return e?x.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):x},[x,d]),C=async e=>{v(e.id);try{e.id!==o?.id&&await c(e.id),window.location.href=Na()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),v(null)}},w=e=>{h(!1),C(e)},T=(0,$.useRef)(!1);(0,$.useEffect)(()=>{T.current||s||i||x.length===1&&(T.current=!0,r?t(`/organizations/${x[0].slug}/members`,{replace:!0}):C(x[0]))},[s,x.length,r,i]);let E=(0,$.useRef)(!1);(0,$.useEffect)(()=>{i&&!E.current&&(E.current=!0,h(!0))},[i]);let D=!i&&!s&&x.length===1;return s||D?(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,Q.jsx)(X,{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)(Me,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(_n,{value:d,onChange:e=>f(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for an organization`}),className:`pl-9`,"data-testid":`organizations-search`})]}),y&&(0,Q.jsxs)(Y,{onClick:()=>h(!0),"data-testid":`organizations-new`,children:[(0,Q.jsx)(ut,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),x.length===0?(0,Q.jsxs)(Je,{children:[(0,Q.jsx)(un,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,Q.jsx)(it,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),y&&(0,Q.jsxs)(Y,{className:`mt-6`,onClick:()=>h(!0),children:[(0,Q.jsx)(ut,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}):S.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:S.map(n=>{let r=n.id===o?.id,i=_===n.id;return(0,Q.jsxs)(`button`,{onClick:()=>C(n),disabled:i,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)(an,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Q.jsx)(wt,{src:n.logo,alt:n.name}),(0,Q.jsx)(yn,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:qs(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:r?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`})}),i&&(0,Q.jsx)(X,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,Q.jsx)(Ks,{open:p,onOpenChange:h,onCreated:w})]})}function Ys(){let{t:e}=O(),t=m(),{slug:n}=a(),{organizations:r,activeOrganization:i,isOrganizationsLoading:s,switchOrganization:c}=g(),{setContext:u}=$r();(0,$.useEffect)(()=>{u(`home`)},[u]);let d=(0,$.useMemo)(()=>(r??[]).find(e=>e.slug===n)??null,[r,n]);if((0,$.useEffect)(()=>{d&&i?.id!==d.id&&c(d.id).catch(e=>{console.error(`[OrganizationLayout] switch failed`,e)})},[d,i,c]),s)return(0,Q.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center`,children:(0,Q.jsx)(X,{className:`h-5 w-5 animate-spin text-muted-foreground`})});if(!d)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)(Y,{className:`mt-6`,onClick:()=>t(`/organizations`),children:e(`organization.backToList`,{defaultValue:`Back to organizations`})})]});let f=[{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)(to,{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:[(r??[]).length>1&&(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)(Ue,{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:d.name}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:d.slug})]})}),(0,Q.jsx)(`nav`,{className:`mt-4 flex gap-1 -mb-px`,children:f.map(e=>(0,Q.jsx)(o,{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)(l,{context:{org:d}})})})]})}function Xs(){return i()}function Zs(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function Qs({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=O(),{inviteMember:a}=g(),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(`member`),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(null),[m,h]=(0,$.useState)(null),[_,v]=(0,$.useState)(!1);(0,$.useEffect)(()=>{t&&(s(``),l(`member`),p(null),h(null),v(!1))},[t]);let y=(0,$.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]),b=(0,$.useCallback)(async()=>{if(!m)return;let e=Zs(m.id);try{await navigator.clipboard.writeText(e),v(!0),Z.success(i(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>v(!1),2e3)}catch{Z.error(i(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},[m,i]);return(0,Q.jsx)(Ye,{open:t,onOpenChange:n,children:(0,Q.jsx)(at,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:m?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(dn,{children:[(0,Q.jsx)(ve,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Q.jsx)(ue,{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)(Ot,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(_n,{readOnly:!0,value:Zs(m.id),className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,Q.jsx)(Y,{type:`button`,variant:`outline`,size:`icon`,onClick:b,"aria-label":`Copy`,children:_?(0,Q.jsx)(V,{className:`h-4 w-4`}):(0,Q.jsx)(bn,{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)(xe,{children:(0,Q.jsx)(Y,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Q.jsxs)(`form`,{onSubmit:y,children:[(0,Q.jsxs)(dn,{children:[(0,Q.jsx)(ve,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Q.jsx)(ue,{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)(Ot,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,Q.jsx)(_n,{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)(Ot,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,Q.jsxs)(pe,{value:c,onValueChange:e=>l(e),children:[(0,Q.jsx)(be,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,Q.jsx)(dt,{})}),(0,Q.jsxs)(we,{children:[(0,Q.jsx)(mn,{value:`member`,children:i(`organization.roles.member`,{defaultValue:`Member`})}),(0,Q.jsx)(mn,{value:`admin`,children:i(`organization.roles.admin`,{defaultValue:`Admin`})}),(0,Q.jsx)(mn,{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)(xe,{children:[(0,Q.jsx)(Y,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:u,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(Y,{type:`submit`,disabled:u||!o.trim(),"data-testid":`invite-submit`,children:[u&&(0,Q.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}function $s(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function ec(){let{t:e}=O(),{org:t}=Xs(),{getMembers:n,removeMember:r,updateMemberRole:i}=g(),[a,o]=(0,$.useState)([]),[s,c]=(0,$.useState)(!0),[l,u]=(0,$.useState)(null),[d,f]=(0,$.useState)(!1),[p,m]=(0,$.useState)(null),h=(0,$.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,$.useEffect)(()=>{h()},[h]);let _=async(n,r)=>{try{await i({organizationId:t.id,memberId:n.id,role:r}),Z.success(e(`organization.members.roleUpdated`,{defaultValue:`Role updated`})),h()}catch(t){Z.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)(X,{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)(Y,{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)(Y,{onClick:()=>f(!0),"data-testid":`invite-member-btn`,children:e(`organization.members.inviteMember`,{defaultValue:`Invite member`})})]}),(0,Q.jsx)(ot,{}),(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)(an,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,Q.jsx)(wt,{src:t.user.image,alt:t.user.name}),(0,Q.jsx)(yn,{className:`text-xs font-medium`,children:$s(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)(yt,{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)(Mt,{children:[(0,Q.jsx)(kn,{asChild:!0,children:(0,Q.jsx)(Y,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Member actions`,children:(0,Q.jsx)(ye,{className:`h-4 w-4`})})}),(0,Q.jsxs)(sn,{align:`end`,children:[(0,Q.jsxs)(J,{onClick:()=>_(t,`owner`),disabled:t.role===`owner`,children:[(0,Q.jsx)(We,{className:`mr-2 h-4 w-4`}),e(`organization.roles.owner`,{defaultValue:`Owner`})]}),(0,Q.jsxs)(J,{onClick:()=>_(t,`admin`),disabled:t.role===`admin`,children:[(0,Q.jsx)(We,{className:`mr-2 h-4 w-4`}),e(`organization.roles.admin`,{defaultValue:`Admin`})]}),(0,Q.jsxs)(J,{onClick:()=>_(t,`member`),disabled:t.role===`member`,children:[(0,Q.jsx)(We,{className:`mr-2 h-4 w-4`}),e(`organization.roles.member`,{defaultValue:`Member`})]}),(0,Q.jsxs)(J,{className:`text-destructive focus:text-destructive`,onClick:()=>m(t),children:[(0,Q.jsx)(Be,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,Q.jsx)(Nt,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,Q.jsxs)(Rt,{children:[(0,Q.jsxs)(Tn,{children:[(0,Q.jsx)(Nn,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Q.jsx)(It,{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)(gt,{children:[(0,Q.jsx)($t,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(cn,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{if(p)try{await r({organizationId:t.id,memberIdOrUserId:p.id}),Z.success(e(`organization.members.memberRemoved`,{defaultValue:`Member removed`})),m(null),h()}catch(t){Z.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)(Qs,{organizationId:t.id,open:d,onOpenChange:f,onInvited:()=>h()})]})}function tc(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function nc(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function rc(){let{t:e}=O(),{org:t}=Xs(),{listInvitations:n,cancelInvitation:r}=g(),[i,a]=(0,$.useState)([]),[o,s]=(0,$.useState)(!0),[c,l]=(0,$.useState)(null),[u,d]=(0,$.useState)(`all`),[f,p]=(0,$.useState)(null),[m,h]=(0,$.useState)(null),_=(0,$.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,$.useEffect)(()=>{_()},[_]);let v=async t=>{let n=tc(t.id);try{await navigator.clipboard.writeText(n),h(t.id),Z.success(e(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>h(null),2e3)}catch{Z.error(e(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},y=async()=>{if(f)try{await r(f.id),Z.success(e(`organization.invitations.canceled`,{defaultValue:`Invitation canceled`})),p(null),_()}catch(t){Z.error(t instanceof Error?t.message:e(`organization.invitations.cancelFailed`,{defaultValue:`Failed to cancel invitation`}))}},b=u===`all`?i:i.filter(e=>e.status===u),x={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)(X,{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)(Y,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:_,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}),x[t]>0&&(0,Q.jsx)(`span`,{className:`ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs`,children:x[t]})]},t))}),(0,Q.jsx)(ot,{}),b.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:b.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)(an,{className:`h-9 w-9 shrink-0`,children:(0,Q.jsx)(yn,{className:`text-xs`,children:(0,Q.jsx)(R,{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)(yt,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),(0,Q.jsx)(yt,{variant:nc(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)(Y,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>v(t),"aria-label":`Copy invitation link`,children:m===t.id?(0,Q.jsx)(V,{className:`h-4 w-4 text-green-600`}):(0,Q.jsx)(bn,{className:`h-4 w-4`})}),(0,Q.jsx)(Y,{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)(Ne,{className:`h-4 w-4`})})]})]},t.id))}),(0,Q.jsx)(Nt,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,Q.jsxs)(Rt,{children:[(0,Q.jsxs)(Tn,{children:[(0,Q.jsx)(Nn,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Q.jsx)(It,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,Q.jsxs)(gt,{children:[(0,Q.jsx)($t,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(cn,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:y,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function ic(){let{t:e}=O(),{org:t}=Xs(),{user:n,getMembers:r,updateOrganization:i,deleteOrganization:a,leaveOrganization:o}=g(),s=m(),[c,l]=(0,$.useState)(t.name),[u,d]=(0,$.useState)(t.slug??``),[f,p]=(0,$.useState)(t.logo??``),[h,_]=(0,$.useState)(!1),[v,y]=(0,$.useState)(!1),b=(0,$.useRef)(null),{upload:x}=Ve(),[S,C]=(0,$.useState)(null),[w,T]=(0,$.useState)(!0),[E,D]=(0,$.useState)(!1),[k,ee]=(0,$.useState)(!1),[A,j]=(0,$.useState)(``),[M,N]=(0,$.useState)(!1);(0,$.useEffect)(()=>{l(t.name),d(t.slug??``),p(t.logo??``)},[t]),(0,$.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 te=(0,$.useCallback)(async n=>{n.preventDefault(),_(!0);try{await i(t.id,{name:c.trim(),slug:u.trim()||void 0,logo:f.trim()||void 0}),Z.success(e(`organization.settings.saved`,{defaultValue:`Settings saved`}))}catch(t){Z.error(t instanceof Error?t.message:e(`organization.settings.saveFailed`,{defaultValue:`Failed to save settings`}))}finally{_(!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)(X,{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)(ot,{className:`my-4`}),S?(0,Q.jsxs)(`form`,{onSubmit:te,className:`space-y-4 max-w-md`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(Ot,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,Q.jsx)(_n,{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)(Ot,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,Q.jsx)(_n,{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)(Ot,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(an,{className:`size-16 rounded-md`,children:[f?(0,Q.jsx)(wt,{src:f,alt:c,className:`object-cover`}):null,(0,Q.jsx)(yn,{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:b,type:`file`,accept:`image/*`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(b.current&&(b.current.value=``),n){y(!0);try{p((await x(n)).url),Z.success(e(`organization.settings.logoUploaded`,{defaultValue:`Logo uploaded — save to apply`}))}catch(t){Z.error(t instanceof Error?t.message:e(`organization.settings.logoUploadFailed`,{defaultValue:`Failed to upload logo`}))}finally{y(!1)}}},"data-testid":`settings-logo-file`}),(0,Q.jsxs)(Y,{type:`button`,variant:`outline`,size:`sm`,disabled:v,onClick:()=>b.current?.click(),"data-testid":`settings-logo-upload-btn`,children:[v?(0,Q.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Q.jsx)(Ln,{className:`mr-2 h-4 w-4`}),f?e(`organization.settings.logoReplace`,{defaultValue:`Replace`}):e(`organization.settings.logoUpload`,{defaultValue:`Upload`})]}),f&&(0,Q.jsxs)(Y,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>p(``),"data-testid":`settings-logo-clear-btn`,children:[(0,Q.jsx)(Ne,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,Q.jsx)(_n,{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)(Y,{type:`submit`,disabled:h,"data-testid":`settings-save-btn`,children:[h&&(0,Q.jsx)(X,{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)(ot,{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)(Y,{variant:`destructive`,size:`sm`,onClick:()=>D(!0),children:e(`organization.settings.leaveAction`,{defaultValue:`Leave`})})]}),(0,Q.jsx)(ot,{}),(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)(Y,{variant:`destructive`,size:`sm`,onClick:()=>{j(``),ee(!0)},disabled:!S,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,Q.jsx)(Nt,{open:E,onOpenChange:D,children:(0,Q.jsxs)(Rt,{children:[(0,Q.jsxs)(Tn,{children:[(0,Q.jsx)(Nn,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Q.jsx)(It,{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)(gt,{children:[(0,Q.jsx)($t,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(cn,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{N(!0);try{await o(t.id),Z.success(e(`organization.settings.leftOrg`,{defaultValue:`You have left the organization`})),s(`/organizations`)}catch(t){Z.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)(X,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,Q.jsx)(Nt,{open:k,onOpenChange:e=>{ee(e),e||j(``)},children:(0,Q.jsxs)(Rt,{children:[(0,Q.jsxs)(Tn,{children:[(0,Q.jsx)(Nn,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Q.jsx)(It,{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)(Ot,{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)(_n,{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)(gt,{children:[(0,Q.jsx)($t,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(cn,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{N(!0);try{await a(t.id),Z.success(e(`organization.settings.deleted`,{defaultValue:`Organization deleted`})),s(`/organizations`)}catch(t){Z.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)(X,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}function ac(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 oc(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString()}var sc=[`today`,`yesterday`,`previous7Days`,`previous30Days`,`older`],cc={today:`Today`,yesterday:`Yesterday`,previous7Days:`Previous 7 days`,previous30Days:`Previous 30 days`,older:`Older`};function lc(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 sc.filter(e=>o[e].length>0).map(e=>({key:e,items:o[e]}))}function uc({userId:e,apiBase:t,activeAgent:n,className:r,refreshKey:i,titleHints:o,onNavigate:s}){let{t:c}=O(),l=m(),{conversationId:u}=a(),{conversations:d,isLoading:f,error:p,remove:h,rename:g}=ur({userId:e,apiBase:t,refreshKey:i}),[_,v]=(0,$.useState)(``),[y,b]=(0,$.useState)(void 0),x=n?Or(n):void 0,S=(0,$.useMemo)(()=>n?new Set(kr(n)):void 0,[n]),C=(0,$.useMemo)(()=>d.map(e=>{let t=o?.[e.id]?.trim();return!t||e.title?.trim()||e.preview?.trim()?e:{...e,preview:t}}),[d,o]),w=(0,$.useMemo)(()=>S?C.filter(e=>!e.agentId||S.has(e.agentId)||e.id===u):C,[C,S,u]),T=(0,$.useMemo)(()=>{let e=_.trim().toLowerCase();return e?w.filter(t=>`${t.title??``} ${t.preview??``}`.toLowerCase().includes(e)):w},[w,_]),E=(0,$.useCallback)(e=>{let t=e.agentId?Or(e.agentId):x;return t?`/ai/${t}/${e.id}`:`/ai/${e.id}`},[x]),D=(0,$.useCallback)(()=>{l(x?`/ai/${x}?new=1`:`/ai?new=1`),s?.()},[l,x,s]),k=(0,$.useCallback)(async(e,t)=>{e.stopPropagation(),await h(t),t===u&&(l(x?`/ai/${x}`:`/ai`,{replace:!0}),s?.())},[h,u,l,x,s]),ee=(0,$.useCallback)(async(e,t)=>{b(void 0);try{await g(e,t)}catch{}},[g]);return(0,Q.jsxs)(`aside`,{className:G(`flex h-full min-h-0 flex-col bg-muted/30`,r),"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:c(`console.ai.chats`)}),(0,Q.jsxs)(Y,{size:`sm`,variant:`outline`,onClick:D,"data-testid":`ai-new-chat`,children:[(0,Q.jsx)(ut,{className:`h-3.5 w-3.5`}),c(`console.ai.newChat`)]})]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(Me,{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)(_n,{value:_,onChange:e=>v(e.target.value),placeholder:c(`console.ai.searchChats`),className:`h-7 pl-7 text-xs`,"data-testid":`ai-conversations-search`})]})]}),(0,Q.jsx)(lt,{className:`flex-1 min-h-0`,children:f&&d.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:c(`common.loading`)}):p?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-destructive`,children:p.message}):w.length===0?(0,Q.jsxs)(Je,{className:`px-3 py-8`,children:[(0,Q.jsx)(je,{className:`h-8 w-8 text-muted-foreground`}),(0,Q.jsx)(un,{children:c(`console.ai.noChatsYet`)}),(0,Q.jsx)(it,{children:c(`console.ai.noChatsDescription`)})]}):T.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:c(`console.ai.noMatchingChats`)}):(0,Q.jsx)(`div`,{className:`flex flex-col py-1`,children:lc(T).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:c(`console.ai.group.${e.key}`,{defaultValue:cc[e.key]})}),(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.items.map(e=>(0,Q.jsx)(fc,{conversation:e,query:_.trim(),active:e.id===u,renaming:e.id===y,onSelect:()=>{l(E(e)),s?.()},onDelete:t=>k(t,e.id),onStartRename:()=>b(e.id),onCancelRename:()=>b(void 0),onSubmitRename:t=>ee(e.id,t)},e.id))})]},e.key))})})]})}function dc(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 fc({conversation:e,query:t,active:n,renaming:r,onSelect:i,onDelete:a,onStartRename:o,onCancelRename:s,onSubmitRename:c}){let{t:l}=O(),u=e.title?.trim()||e.preview?.trim()||l(`console.ai.newConversation`),[d,f]=(0,$.useState)(u),p=(0,$.useRef)(null);return(0,$.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:G(`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)(_n,{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)(Y,{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)(V,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(Y,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:s,"aria-label":l(`console.ai.cancelRename`),children:(0,Q.jsx)(Ne,{className:`h-3.5 w-3.5`})})]})}):(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`div`,{className:G(`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:dc(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:dc(e.preview,t)}):null,(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[10px] text-muted-foreground`,title:oc(e.updatedAt??e.createdAt),children:ac(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)(Y,{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)(tn,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(Y,{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)(pn,{className:`h-3.5 w-3.5`})})]})]})})}function pc(){return typeof window>`u`?``:window.location.pathname.startsWith(`/_console`)?`/_console`:``}function mc(e,t){let n=`${pc()}/apps/${encodeURIComponent(e)}`;return t?n:`${n}?preview=draft`}function hc({appName:e,appSegment:t,materialized:n=!1,refreshKey:r,onClose:i}){let{t:a}=O(),o=(0,$.useRef)(null),s=t&&t.length?t:e;return(0,$.useEffect)(()=>{if(!o.current)return;let e=mc(s,n);try{o.current.getAttribute(`src`)!==e&&o.current.setAttribute(`src`,e)}catch{}},[s,n]),(0,$.useEffect)(()=>{if(r>0)try{o.current?.contentWindow?.location.reload()}catch{}},[r]),(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)(de,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n?a(`console.ai.liveCanvasUnlisted`,{app:e,defaultValue:`Live app — {{app}} (unlisted until published)`}):a(`console.ai.liveCanvas`,{app:e,defaultValue:`Live preview — {{app}} (draft)`})}),(0,Q.jsx)(Y,{size:`sm`,variant:`ghost`,onClick:i,"data-testid":`live-canvas-close`,children:(0,Q.jsx)(Ne,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`iframe`,{ref:o,title:`Draft preview: ${e}`,src:mc(s,n),className:`h-full w-full flex-1 border-0 bg-background`,"data-testid":`live-canvas-frame`})]})}async function gc(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}/debug`,{credentials:`include`});if(n.status===404||n.status===403||n.status===401)return null;if(!n.ok)throw Error(`GET build debug failed: ${n.status}`);return await n.json()}function _c({apiBase:e,conversationId:t,open:n,onOpenChange:r}){let[i,a]=(0,$.useState)(null),[o,s]=(0,$.useState)(!1),[c,l]=(0,$.useState)(null);(0,$.useEffect)(()=>{if(!n||!t)return;let r=!1;return s(!0),l(null),a(null),gc(e,t).then(e=>{r||(e?a(e):l(`Not available — the conversation was not found or you are not authorized.`))}).catch(e=>{r||l(e instanceof Error?e.message:String(e))}).finally(()=>{r||s(!1)}),()=>{r=!0}},[n,t,e]);let u=i?.reconciliation,d=u?u.orphaned.length+u.missing.length+u.errors.length:0;return(0,Q.jsx)(zn,{open:n,onOpenChange:r,children:(0,Q.jsxs)(ae,{side:`right`,className:`w-full overflow-y-auto sm:max-w-xl`,children:[(0,Q.jsxs)(H,{children:[(0,Q.jsxs)(Ze,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Sn,{className:`h-4 w-4`}),` Build Doctor`]}),(0,Q.jsx)(q,{children:`What the agent claimed vs what is actually live. Read-only diagnostic.`})]}),(0,Q.jsxs)(`div`,{className:`mt-4 space-y-4 text-sm`,children:[o&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,Q.jsx)(X,{className:`h-4 w-4 animate-spin`}),` Reconciling…`]}),c&&!o&&(0,Q.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive`,children:c}),i&&!o&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`rounded-md border bg-muted/30 p-3 text-xs text-muted-foreground`,children:[(0,Q.jsx)(`div`,{className:`font-medium text-foreground`,children:i.title??`(untitled)`}),(0,Q.jsxs)(`div`,{className:`mt-1`,children:[i.summary.userTurns,` turn(s) · `,i.summary.messages,` msgs ·`,` `,i.summary.totalTokens.toLocaleString(),` tok ·`,` `,(i.summary.llmMs/1e3).toFixed(1),`s LLM`,i.summary.models.length?` · ${i.summary.models.join(`, `)}`:``]})]}),u&&(0,Q.jsxs)(`div`,{className:u.ok?`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/10 p-3 text-emerald-700 dark:text-emerald-400`:`flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive`,children:[u.ok?(0,Q.jsx)(P,{className:`h-4 w-4`}):(0,Q.jsx)(fe,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:u.ok?`All ${u.liveCount} attempted change(s) are live — nothing evaporated.`:`${d} discrepancy(ies) — what the chat said doesn't match what's live.`})]}),u&&u.orphaned.length>0&&(0,Q.jsx)(vc,{icon:(0,Q.jsx)(Dn,{className:`h-4 w-4 text-destructive`}),title:`Proposed but never applied`,hint:`A confirm card the agent proposed but no later turn applied — the change silently evaporated.`,findings:u.orphaned,tone:`destructive`}),u&&u.missing.length>0&&(0,Q.jsx)(vc,{icon:(0,Q.jsx)(fe,{className:`h-4 w-4 text-amber-600`}),title:`Claimed but missing`,hint:`A tool result said it was applied, but the artifact isn't live in sys_metadata.`,findings:u.missing,tone:`amber`}),u&&u.errors.length>0&&(0,Q.jsx)(vc,{icon:(0,Q.jsx)(An,{className:`h-4 w-4 text-destructive`}),title:`Tool errors`,hint:`Tool calls that returned an error during the build.`,findings:u.errors,tone:`destructive`}),i.verify&&(0,Q.jsxs)(`div`,{className:`rounded-md border p-3 text-xs`,children:[(0,Q.jsx)(`div`,{className:`font-medium text-foreground`,children:`Build check (verify_build)`}),(0,Q.jsxs)(`div`,{className:`mt-1 text-muted-foreground`,children:[`Your app:`,` `,i.verify.userIssues.length===0?(0,Q.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:`0 issues`}):(0,Q.jsxs)(`span`,{className:`text-destructive`,children:[i.verify.userIssues.length,` issue(s)`]}),i.verify.platformNoise>0?` · ${i.verify.platformNoise} platform sys_* finding(s) hidden`:``]}),i.verify.userIssues.map((e,t)=>(0,Q.jsxs)(`div`,{className:`mt-1 text-destructive`,children:[`[`,e.severity,`] `,e.code,` `,e.artifact?`${e.artifact.type}:${e.artifact.name}`:``]},t))]}),i.pendingActions.length>0&&(0,Q.jsxs)(`div`,{className:`rounded-md border p-3 text-xs`,children:[(0,Q.jsx)(`div`,{className:`font-medium text-foreground`,children:`Pending actions`}),i.pendingActions.map((e,t)=>(0,Q.jsxs)(`div`,{className:`mt-1 text-muted-foreground`,children:[e.tool??`?`,` · `,e.object??`-`,` · `,(0,Q.jsx)(`span`,{className:`font-mono`,children:e.status??`-`})]},t))]}),(0,Q.jsxs)(`details`,{className:`rounded-md border p-3 text-xs`,children:[(0,Q.jsxs)(`summary`,{className:`cursor-pointer font-medium text-foreground`,children:[`Timeline (`,i.timeline.length,`)`]}),(0,Q.jsx)(`div`,{className:`mt-2 space-y-1 font-mono text-[11px] leading-relaxed`,children:i.timeline.map((e,t)=>(0,Q.jsx)(yc,{entry:e},t))})]})]})]})]})})}function vc({icon:e,title:t,hint:n,findings:r,tone:i}){return(0,Q.jsxs)(`div`,{className:`rounded-md border ${i===`destructive`?`border-destructive/30`:`border-amber-500/30`} p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-foreground`,children:[e,` `,t,` (`,r.length,`)`]}),(0,Q.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:n}),(0,Q.jsx)(`div`,{className:`mt-2 space-y-1`,children:r.map((e,t)=>(0,Q.jsxs)(`div`,{className:`font-mono text-xs`,children:[e.t?`${e.t} · `:``,e.tool,` → `,e.artifact.type,`:`,e.artifact.name,(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (`,e.status,`)`]})]},t))})]})}function yc({entry:e}){return e.kind===`user`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 👤 `,e.text]}):e.kind===`assistant-text`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 🤖 `,e.text]}):e.kind===`assistant-calls`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 🤖 →`,` `,e.calls.map(e=>e.name).join(`, `)]}):(0,Q.jsxs)(`div`,{className:e.isError?`text-destructive`:``,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` ↳ `,e.name,e.status?` (${e.status})`:``]})}var bc=`/api/v1/ai`;function xc(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function Sc(e){let t=xc(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 Cc(e){return e.map(e=>{let t=[],n,r=e.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``);if(e.role===`assistant`)for(let r of e.parts){if(!r.type.startsWith(`tool-`))continue;let i=xc(r,`toolName`)??r.type.slice(5),a=xc(r,`toolCallId`)??`${e.id}-${i}`,o=Sc(r),s=r.output??r.result,c=Nr(s),l=yr(s);if(t.push({toolCallId:a,toolName:i,...o?{state:o}:{},...s===void 0?{}:{result:s},...c?{draftReview:c}:{},...l?{proposedPlan:l}:{},...r.errorText?{errorText:String(r.errorText)}:{}}),!n){let e=Sr(c);e&&(n=e)}}return{id:e.id,role:e.role,content:r,...t.length>0?{toolInvocations:t}:{},...n?{buildProgress:n}:{}}})}function wc(e){return e.find(e=>e.role===`user`)?.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``).trim()||void 0}var Tc={ask:{key:`console.ai.agentLabels.ask`,defaultValue:`Ask`},build:{key:`console.ai.agentLabels.build`,defaultValue:`Build`}};function Ec(e,t,n){let r=t?Tc[Or(t)]:void 0;return r?e(r.key,{defaultValue:r.defaultValue}):n}function Dc(e,t){return Tr(t)?{title:e(`console.ai.empty.build.title`,{defaultValue:`Build with AI`}),description:e(`console.ai.empty.build.description`,{defaultValue:`Describe an app or workflow in plain language — I draft the objects, screens and automations, then you review and publish.`})}:Er(t)?{title:e(`console.ai.empty.ask.title`,{defaultValue:`Ask your data`}),description:e(`console.ai.empty.ask.description`,{defaultValue:`Ask questions about your records — counts, lists, and summaries across the data you can access.`})}:{title:e(`console.ai.emptyTitle`,{defaultValue:`Start a conversation`}),description:e(`console.ai.emptyDescription`,{defaultValue:`Ask anything — the assistant has access to your current app context.`})}}function Oc(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(/\/$/,``)}${bc}`}var kc=`ai-chats-collapsed`;function Ac(){let[e,t]=(0,$.useState)(()=>{try{return localStorage.getItem(kc)===`1`}catch{return!1}}),n=(0,$.useRef)(!1);return{collapsed:e,toggle:(0,$.useCallback)(()=>{n.current=!1,t(e=>{let t=!e;try{localStorage.setItem(kc,t?`1`:`0`)}catch{}return t})},[]),handleCanvasOpenChange:(0,$.useCallback)(e=>{e?t(e=>e||(n.current=!0,!0)):n.current&&(n.current=!1,t(!1))},[])}}var jc=`ai-chat-pane-width`,Mc=480,Nc=360,Pc=420,Fc=24;function Ic(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 Lc(e){let t=(0,$.useRef)(null),[n,r]=(0,$.useState)(()=>{try{let e=Number(localStorage.getItem(jc));return Number.isFinite(e)&&e>0?e:Mc}catch{return Mc}}),[i,a]=(0,$.useState)(!1),o=(0,$.useCallback)(e=>Ic(e,{min:Nc,previewMin:Pc,containerWidth:t.current?.clientWidth??0}),[]),s=(0,$.useCallback)(e=>{try{localStorage.setItem(jc,String(Math.round(e)))}catch{}},[]);return(0,$.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,$.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,$.useCallback)(e=>{let t=e.key===`ArrowLeft`?-24:e.key===`ArrowRight`?Fc:0;t&&(e.preventDefault(),r(e=>{let n=o(e+t);return s(n),n}))},[o,s]),reset:(0,$.useCallback)(()=>{let e=o(Mc);r(e),s(e)},[o,s])}}function Rc(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 zc({apiBase:e,defaultAgent:t}={}){let{user:n}=g(),{t:r}=O(),i=n?.id,{agent:o,conversationId:s}=a(),[c]=u(),l=c.toString(),d=c.get(`new`)!==null,f=c.get(`package`)?.trim()||void 0,p=m(),{setContext:h}=$r();(0,$.useEffect)(()=>{h(`home`)},[h]);let _=(0,$.useMemo)(()=>Oc(e),[e]),v={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:y,isLoading:b,error:x,refetch:S}=wr({apiBase:_}),C=(0,$.useMemo)(()=>y.map(e=>e.name),[y]),w=!b&&y.length===0,T=(0,$.useMemo)(()=>{if(!o)return!1;if(y.length!==0)return Mr(o,C)!==void 0},[o,y.length,C]),E=o?void 0:c.get(`agent`)??void 0,D=(0,$.useMemo)(()=>Cr(y,E??t??v),[y,E,t,v]),k=(0,$.useMemo)(()=>{if(y.length!==0)return o&&T?Mr(o,C):D},[y.length,o,T,C,D]),ee=k?Or(k):void 0,A=!!(o&&T===!1&&br(o)),j=o&&T===!1&&!A?o:void 0,M=k?`${_}/agents/${encodeURIComponent(k)}/chat`:void 0,{conversationId:N,conversationScope:te,initialMessages:P}=tr({userId:k?i:void 0,scope:k,apiBase:_,activeId:s??j,forceNew:d});(0,$.useEffect)(()=>{if(y.length===0||!k)return;let e=Or(k),t=new URLSearchParams(l);t.delete(`agent`);let n=t.toString()?`?${t.toString()}`:``;if(!o){p(`/ai/${e}${n}`,{replace:!0});return}if(A){p(`/ai/${e}${n}`,{replace:!0});return}T&&o!==e&&p(`/ai/${e}${s?`/${encodeURIComponent(s)}`:``}${n}`,{replace:!0})},[y.length,k,o,T,A,s,l,p]),(0,$.useEffect)(()=>{if(j===void 0)return;let e=!1;return(async()=>{let t;try{t=(await er(_,j))?.agentId??void 0}catch{}e||p(`/ai/${Or(Mr(t??``,C)??k??`ask`)}/${encodeURIComponent(j)}`,{replace:!0})})(),()=>{e=!0}},[j,_,C,k,p]);let[ne,re]=(0,$.useState)(0),[F,ie]=(0,$.useState)({}),[oe,I]=(0,$.useState)(!1),[L,ce]=(0,$.useState)(!1),[le,R]=(0,$.useState)(!1),{collapsed:z,toggle:ue,handleCanvasOpenChange:de}=Ac();(0,$.useEffect)(()=>{let e=e=>{let t=Rc(e);t&&(e.preventDefault(),t===`toggle-list`?ue():p(ee?`/ai/${ee}?new=1`:`/ai?new=1`))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[ue,p,ee]);let fe=(0,$.useMemo)(()=>_.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[_]),pe=(0,$.useMemo)(()=>{if(typeof window>`u`||typeof document>`u`)return;let e=``;try{let t=document.querySelector(`base`)?.getAttribute(`href`);t&&(e=new URL(t,window.location.origin).pathname.replace(/\/+$/,``))}catch{}return`${window.location.origin}${e}/s`},[]),me=(0,$.useRef)(null);d?me.current===null&&(me.current={id:N}):me.current=null,(0,$.useEffect)(()=>{!T||s||!N||!ee||me.current&&me.current.id===N||te===k&&p(`/ai/${ee}/${N}`,{replace:!0})},[T,s,N,te,k,ee,p]);let B=(0,$.useRef)(new Set);(0,$.useEffect)(()=>{N&&P.length>0&&B.current.add(N)},[N,P.length]),(0,$.useEffect)(()=>{if(!N)return;let e=wc(P);e&&ie(t=>t[N]===e?t:{...t,[N]:e})},[N,P]);let V=(0,$.useCallback)(e=>{if(re(e=>e+1),e&&N&&ie(t=>({...t,[N]:e})),!e||!N||B.current.has(N))return;B.current.add(N);let t=()=>re(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[N]);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:[!w&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Y,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 md:hidden`,onClick:()=>R(!0),"aria-label":r(`console.ai.openChats`),"data-testid":`ai-chat-mobile-sidebar-trigger`,children:(0,Q.jsx)(Kt,{className:`h-4 w-4`})}),(0,Q.jsx)(Y,{variant:`ghost`,size:`icon`,className:`hidden h-8 w-8 shrink-0 md:inline-flex`,onClick:ue,"aria-label":z?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),title:z?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),"data-testid":`ai-chat-collapse-sidebar-trigger`,"aria-pressed":z,children:z?(0,Q.jsx)(Et,{className:`h-4 w-4`}):(0,Q.jsx)(At,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(to,{variant:`home`})})]}),w?(0,Q.jsx)(Bc,{hasError:!!x,onRetry:S,onHome:()=>p(`/home`),t:r}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(zn,{open:le,onOpenChange:R,children:(0,Q.jsxs)(ae,{side:`left`,className:`w-[320px] p-0 sm:max-w-[360px]`,"data-testid":`ai-chat-mobile-sidebar`,children:[(0,Q.jsxs)(H,{className:`sr-only`,children:[(0,Q.jsx)(Ze,{children:r(`console.ai.chats`)}),(0,Q.jsx)(q,{children:r(`console.ai.chatsDescription`)})]}),(0,Q.jsx)(uc,{userId:i,apiBase:_,activeAgent:k,refreshKey:ne,titleHints:F,className:`h-full border-r-0`,onNavigate:()=>R(!1)})]})}),N&&(0,Q.jsx)(se,{open:oe,onOpenChange:I,objectName:`ai_conversations`,recordId:N,recordLabel:`this conversation`,apiBase:fe,publicBaseUrl:pe}),N&&Tr(k)&&(0,Q.jsx)(_c,{apiBase:_,conversationId:N,open:L,onOpenChange:ce}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 w-full bg-muted/20`,children:[!z&&(0,Q.jsx)(uc,{userId:i,apiBase:_,activeAgent:k,refreshKey:ne,titleHints:F,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)(Vc,{agents:y,agentsLoading:b,agentsError:x,activeAgent:k,chatApi:M,apiBase:_,conversationId:N,editPackageId:f,initialMessages:P,onSent:V,onShare:()=>I(!0),onDebug:()=>ce(!0),showDebug:Tr(k),onCanvasOpenChange:de},`${M??`local`}:${N??`pending`}`)})]})]})]})}function Bc({hasError:e,onRetry:t,onHome:n,t:r}){return(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,"data-testid":`ai-unavailable`,children:(0,Q.jsxs)(Je,{children:[(0,Q.jsx)(un,{children:r(`console.ai.unavailableTitle`,{defaultValue:`AI assistant unavailable`})}),(0,Q.jsx)(it,{children:e?r(`console.ai.unavailableError`,{defaultValue:`Couldn't reach the AI service. It may be temporarily offline — try again, or head back home.`}):r(`console.ai.unavailableDescription`,{defaultValue:`This deployment doesn't have an AI assistant enabled. Everything else works as usual.`})}),(0,Q.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-3 sm:flex-row`,children:[e&&(0,Q.jsx)(Y,{variant:`outline`,onClick:t,"data-testid":`ai-unavailable-retry`,children:r(`console.ai.unavailableRetry`,{defaultValue:`Try again`})}),(0,Q.jsx)(Y,{onClick:n,"data-testid":`ai-unavailable-home`,children:r(`console.ai.unavailableHome`,{defaultValue:`Back to home`})})]})]})})}function Vc({agents:e,agentsLoading:t,agentsError:n,activeAgent:r,chatApi:i,apiBase:a,conversationId:o,editPackageId:s,initialMessages:c,onSent:l,onShare:u,onDebug:d,showDebug:f,onCanvasOpenChange:p}){let{t:h}=O(),g=m(),_=e.length>1,[v,y]=(0,$.useState)(null),[b,x]=(0,$.useState)(0),S=(0,$.useRef)(null);(0,$.useEffect)(()=>()=>{S.current&&window.clearTimeout(S.current)},[]);let C=v!==null;(0,$.useEffect)(()=>{p?.(C)},[C,p]);let w=Lc(C),T=(0,$.useCallback)((e,t)=>{let n=e.find(e=>e.type===`app`);n&&y(e=>e??{name:n.name,segment:t,materialized:!1}),S.current&&window.clearTimeout(S.current),S.current=window.setTimeout(()=>x(e=>e+1),800)},[]),E=(0,$.useCallback)(e=>{y(t=>t&&t.name===e&&!t.materialized?{...t,materialized:!0}:t??{name:e,materialized:!0})},[]);(0,$.useEffect)(()=>{y(null)},[o]);let D=(0,$.useMemo)(()=>Ec(h,r,e.find(e=>e.name===r)?.label??r??h(`console.ai.assistant`)),[e,r,h]),k=(0,$.useMemo)(()=>Cc(c),[c]),ee=(0,$.useMemo)(()=>{if(!(k.length>0))return Gc(r,D,h)},[k.length,r,D,h]),A=(0,$.useMemo)(()=>Dc(h,r),[h,r]),{errorSuppressed:j,handleChatError:M,setMessagesRef:N,resetSuppression:te}=dr({chatApi:i,conversationId:o}),{models:P,defaultModelId:ne}=jr({apiBase:a}),[re,F]=(0,$.useState)(void 0),ie=re??ne,{messages:ae,isLoading:oe,error:I,sendMessage:L,stop:se,reload:ce,clear:le,setMessages:R}=Pr({api:i,conversationId:o,model:ie,onError:M,body:{context:{activeApp:`AI`,agentName:r,autoPublishAiBuilds:vi().features.autoPublishAiBuilds,...s?{packageId:s}:{}}},initialMessages:k,autoResponse:!i,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600});(0,$.useEffect)(()=>{N.current=R},[R]),(0,$.useEffect)(()=>{ar(o,cr(ae))},[o,ae]);let z=(0,$.useRef)(!1);(0,$.useEffect)(()=>{z.current&&!oe&&v&&x(e=>e+1),z.current=oe},[oe,v]);let ue=Ar({messages:ae,apiBase:a,continueConversation:e=>{L(e)}}),de=(0,$.useCallback)((e,t)=>{te(),L(e,t),l(e)},[L,l]),fe=(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:_?(0,Q.jsxs)(pe,{value:r,onValueChange:e=>g(`/ai/${Or(e)}`),disabled:t,children:[(0,Q.jsx)(be,{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`,"aria-label":h(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:(0,Q.jsx)(dt,{placeholder:h(`console.ai.chooseAgent`,{defaultValue:`Choose assistant…`})})}),(0,Q.jsx)(we,{align:`start`,children:e.map(e=>(0,Q.jsxs)(mn,{value:e.name,className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:Ec(h,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:D})}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[f&&d?(0,Q.jsx)(Y,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:d,disabled:!o,"aria-label":`Build Doctor`,"data-testid":`ai-chat-debug-button`,title:o?`Build Doctor — what actually landed?`:`Send a message first`,children:(0,Q.jsx)(Sn,{className:`h-3.5 w-3.5`})}):null,(0,Q.jsx)(Y,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:u,disabled:!o,"aria-label":h(`console.ai.share`),"data-testid":`ai-chat-share-button`,title:h(o?`console.ai.shareTitle`:`console.ai.shareDisabledTitle`),children:(0,Q.jsx)(En,{className:`h-3.5 w-3.5`})})]}),n?(0,Q.jsx)(`span`,{className:`basis-full text-[10px] text-amber-700 dark:text-amber-400`,title:n.message,children:h(`console.ai.offlineDemoMode`)}):null]});return(0,Q.jsxs)(`div`,{ref:w.containerRef,className:`relative flex min-h-0 flex-1 px-0`,children:[(0,Q.jsx)(`div`,{"data-chat-column":!0,className:v?`flex min-h-0 shrink-0 justify-center`:`flex min-h-0 flex-1 justify-center`,style:v?{width:w.width}:void 0,children:(0,Q.jsx)(Dr,{className:`min-h-0 flex-1 bg-background md:max-w-5xl`,onUpgrade:()=>window.open(gi(),`_blank`,`noopener,noreferrer`),surface:`plain`,maxHeight:`100%`,headerSlot:fe,messages:ae,placeholder:r?Or(r)===`ask`?h(`console.ai.askAnything`):h(`console.ai.askAgent`,{agent:D}):h(t?`console.ai.loadingAgents`:`console.ai.askAnything`),labels:{emptyTitle:A.title,emptyDescription:A.description,clear:h(`console.ai.clearConversation`),sendHint:h(`console.ai.sendHint`),agentActivity:h(`console.ai.agentActivity`),toolCompleted:h(`console.ai.toolCompleted`),toolRunning:h(`console.ai.toolRunning`),toolAwaitingApproval:h(`console.ai.toolAwaitingApproval`),toolFailed:h(`console.ai.toolFailed`),connectionWaiting:h(`console.ai.connectionWaiting`,{defaultValue:`Waiting for server…`}),connectionStalledLabel:h(`console.ai.connectionStalled`,{defaultValue:`Still working…`}),connectionOfflineLabel:h(`console.ai.connectionOffline`,{defaultValue:`Connection lost — reconnecting…`}),designingPlanLabel:h(`console.ai.designingPlan`,{defaultValue:`Designing your app…`}),designingPlanHints:[h(`console.ai.designingPlanHint.data`,{defaultValue:`Mapping out the data you’ll track…`}),h(`console.ai.designingPlanHint.objects`,{defaultValue:`Shaping objects and their fields…`}),h(`console.ai.designingPlanHint.relations`,{defaultValue:`Connecting related records…`}),h(`console.ai.designingPlanHint.lookups`,{defaultValue:`Setting up relationships and lookups…`}),h(`console.ai.designingPlanHint.views`,{defaultValue:`Planning the screens and views…`}),h(`console.ai.designingPlanHint.forms`,{defaultValue:`Laying out forms and lists…`}),h(`console.ai.designingPlanHint.defaults`,{defaultValue:`Adding sensible defaults and validations…`}),h(`console.ai.designingPlanHint.dashboard`,{defaultValue:`Sketching a dashboard to track it…`}),h(`console.ai.designingPlanHint.review`,{defaultValue:`Double-checking the structure hangs together…`}),h(`console.ai.designingPlanHint.finalize`,{defaultValue:`Pulling the plan together…`})],toolDetailsHidden:h(`console.ai.toolDetailsHidden`),copy:h(`console.ai.copy`),copied:h(`console.ai.copied`),regenerate:h(`console.ai.regenerate`),model:h(`console.ai.model`),submit:h(`console.ai.submit`),uploadFiles:h(`console.ai.uploadFiles`),stopResponse:h(`console.ai.stopResponse`),sendFailedRateLimited:h(`console.ai.sendFailedRateLimited`,{defaultValue:`You're sending messages too quickly. Your message is kept below — wait a moment and try again.`}),sendFailedGeneric:h(`console.ai.sendFailedGeneric`,{defaultValue:`Couldn't send your message. It's kept below — please try again.`}),trace:h(`console.ai.trace`),viewTrace:h(`console.ai.viewTrace`)},models:P,selectedModelId:ie,onModelChange:F,suggestions:ee,onSendMessage:de,onClear:le,hideClearBar:!0,onStop:oe?se:void 0,onReload:ce,isLoading:oe,error:j?void 0:I,enableMarkdown:!0,onToolApprove:ue.decide,toolDecisions:ue.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onOpenBuiltApp:(e,t)=>g(`/apps/${encodeURIComponent(t??e)}`),openBuiltAppLabel:h(`console.ai.openBuiltApp`,{defaultValue:`Open app`}),fetchPendingDraftCount:sr,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?Z.warning(h(`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)}):Z.success(h(`console.ai.publishOk`,{defaultValue:`Published — objects are now live.`})),Yn(),{ok:!0,health:xr(n)}}catch(e){return Z.error(h(`console.ai.publishFailed`,{defaultValue:`Publish failed`}),{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:h(`console.ai.publishDrafts`,{defaultValue:`Publish`}),publishedLabel:h(`console.ai.published`,{defaultValue:`Published`}),nextStepsLabel:h(`console.ai.nextSteps`,{defaultValue:`What's next`}),planTitleLabel:h(`console.ai.planTitle`,{defaultValue:`Proposed plan`}),planQuestionsLabel:h(`console.ai.planQuestions`,{defaultValue:`Confirm before building`}),planAssumptionsLabel:h(`console.ai.planAssumptions`,{defaultValue:`Assumptions`}),planDeferredLabel:h(`console.ai.planDeferred`,{defaultValue:`Not yet built`}),planApproveHintLabel:h(`console.ai.planApproveHint`,{defaultValue:`Reply to approve or adjust this plan.`}),planApproveLabel:h(`console.ai.planApprove`,{defaultValue:`Build it`}),planAdjustLabel:h(`console.ai.planAdjust`,{defaultValue:`Adjust`}),planBuiltLabel:h(`console.ai.planBuilt`,{defaultValue:`Built`}),planReadyLabel:h(`console.ai.planReady`,{defaultValue:`The plan is ready. Build it now, or tell me what to adjust.`}),planApproveMessage:h(`console.ai.planApproveMessage`,{defaultValue:`Looks good — build it as proposed.`}),planApproveDefaultsMessage:h(`console.ai.planApproveDefaultsMessage`,{defaultValue:`Build it with your best assumptions; use sensible defaults for the open questions.`}),planAnswerMessage:(e,t)=>h(`console.ai.planAnswerMessage`,{question:e,option:t,defaultValue:`For "{{question}}", go with: {{option}}.`}),autoPublishDrafts:vi().features.autoPublishAiBuilds,onDraftArtifacts:T,onPreviewDraftApp:(e,t)=>y({name:e,segment:t?.appSegment,materialized:t?.materialized===!0}),onBuildMaterialized:E,previewDraftLabel:h(`console.ai.previewDraft`,{defaultValue:`Preview`}),"data-testid":`ai-chat-panel`})}),v?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":h(`console.ai.resizeSplit`,{defaultValue:`Resize chat and preview`}),tabIndex:0,onPointerDown:w.onHandlePointerDown,onKeyDown:w.onHandleKeyDown,onDoubleClick:w.reset,"data-testid":`ai-chat-split-handle`,className:G(`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:G(`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`,w.dragging&&`bg-primary`)})]}),(0,Q.jsx)(hc,{appName:v.name,appSegment:v.segment,materialized:v.materialized,refreshKey:b,onClose:()=>y(null)}),w.dragging?(0,Q.jsx)(`div`,{className:`fixed inset-0 z-50 cursor-col-resize`,"data-testid":`ai-chat-split-overlay`}):null]}):null]})}function Hc(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 Uc(e){return[e(`console.ai.suggestions.metadataAssistant.buildCrm`,{defaultValue:`Build a sales CRM — customers, contacts, and a deal pipeline I can total by stage.`}),e(`console.ai.suggestions.metadataAssistant.buildApp`,{defaultValue:`Create a project tracker — projects, tasks with owners and due dates, and a board by status.`}),e(`console.ai.suggestions.metadataAssistant.buildFlow`,{defaultValue:`Design a support desk — tickets with priority, a status workflow, and customer links.`}),e(`console.ai.suggestions.metadataAssistant.buildInventory`,{defaultValue:`Build an inventory app — products, stock levels, suppliers, and low-stock visibility.`}),e(`console.ai.suggestions.metadataAssistant.buildRecruiting`,{defaultValue:`Make an applicant tracker — candidates, open roles, interview stages, and notes.`})]}function Wc(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 Gc(e,t,n){if(Er(e))return Hc(n);if(Tr(e))return Uc(n);let r=(e??t).toLowerCase();return r.includes(`data`)?Hc(n):r.includes(`metadata`)?Uc(n):Wc(n)}function Kc(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function qc(e){return!Kc(e)||e.viewKind?!1:!!(e.list||e.form||e.listViews||e.formViews)}function Jc(e){if(!Kc(e))return;let t=e.config;if(Kc(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`}Vi({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:Vr}),Vi({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:Hr}),Vi({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:Fr}),Rr({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`}]}),Rr({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`}]}),Rr({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:Br,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`}]}),Rr({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)=>Jc(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!qc(e)}),Rr({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`}]}),Rr({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`}]}),Rr({type:`book`,label:`Documentation Books`,description:`Documentation navigation spine — ordered groups with membership derived over docs (glob/tag rules), plus an explicit pages override for curated order.`,domain:`system`,searchableFields:[`name`,`label`,`description`,`slug`],listColumns:[{key:`name`,label:`Name`,width:`25%`},{key:`label`,label:`Label`,width:`25%`},{key:`audience`,label:`Audience`,width:`12%`,render:e=>e==null?`org`:typeof e==`object`&&e&&`profile`in e?`profile: ${e.profile}`:String(e)},{key:`groups`,label:`Groups`,width:`10%`,render:e=>Array.isArray(e)?String(e.length):`0`},{key:`description`,label:`Description`}]});var Yc=`/api/v1/cloud-connection`;async function Xc(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 Zc(){let[e,t]=(0,$.useState)({kind:`loading`}),[n,r]=(0,$.useState)(!1),[i,a]=(0,$.useState)(!1),o=(0,$.useRef)(null),s=(0,$.useCallback)(()=>{o.current&&=(clearTimeout(o.current),null)},[]),c=(0,$.useCallback)(async()=>{try{let e=(await Xc(`${Yc}/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,$.useEffect)(()=>(c(),s),[c,s]);let l=(0,$.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 Xc(`${Yc}/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,$.useCallback)(async()=>{r(!0);try{let e=(await Xc(`${Yc}/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,$.useCallback)(async()=>{r(!0);try{await Xc(`${Yc}/unbind`,{method:`POST`,body:`{}`}),await c()}catch(e){t({kind:`error`,message:e?.message??String(e)})}finally{r(!1)}},[c]),f=(0,$.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)(X,{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)(Ae,{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)(X,{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)(fn,{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)(bn,{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)(fn,{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)(P,{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)(nt,{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)(en,{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)(X,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}):(0,Q.jsx)(ln,{className:`h-4 w-4`,"aria-hidden":`true`}),`Connect`]})]})}ee.register(`cloud-connection:panel`,()=>(0,Q.jsx)(Zc,{}),{namespace:`app-shell`,label:`Cloud Connection Panel`,category:`plugin`,inputs:[]});export{Zi as _,ec as a,ia as b,Us as c,fs as d,_o as f,Qi as g,$i as h,rc as i,Hs as l,uo as m,Cc as n,Ys as o,fo as p,ic as r,Js as s,zc as t,Ss as u,ra as v,na as y};