@objectstack/console 17.0.0-rc.0 → 17.0.0-rc.1

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 (190) hide show
  1. package/CHANGELOG.md +1096 -0
  2. package/README.md +8 -3
  3. package/dist/.objectui-sha +1 -1
  4. package/dist/assets/{AdapterProvider-ClCj6PTd.js → AdapterProvider-DCL4oNgv.js} +1 -1
  5. package/dist/assets/{AiPendingActionsPage-bedYcbz0.js → AiPendingActionsPage-BvvDIWEC.js} +1 -1
  6. package/dist/assets/{ApiConsolePage-DdUlsQNo.js → ApiConsolePage-Dvr5-g2X.js} +1 -1
  7. package/dist/assets/{AppDocsIndex-DySIC06n.js → AppDocsIndex-Ohwtpos8.js} +1 -1
  8. package/dist/assets/{AppManagementPage-8S-uDSdv.js → AppManagementPage-DhsvWTeZ.js} +1 -1
  9. package/dist/assets/ApprovalsInboxPage-BfaGtcxV.js +1 -0
  10. package/dist/assets/AuditLogPage-D_09WrLX.js +1 -0
  11. package/dist/assets/{ComponentNavView-BOxZS4Hn.js → ComponentNavView-C6J3w2IE.js} +1 -1
  12. package/dist/assets/CreateViewDialog-R7kwDoaF.js +1 -0
  13. package/dist/assets/{DashboardView-Co21jHAg.js → DashboardView-B-5HkqOl.js} +1 -1
  14. package/dist/assets/{DeveloperHubPage-B3CL_2_R.js → DeveloperHubPage-p9oQnZuU.js} +1 -1
  15. package/dist/assets/{DocShell-Bswx8gyj.js → DocShell-B8d7-ARz.js} +1 -1
  16. package/dist/assets/ExpressionProvider-BLhGrCBw.js +1 -0
  17. package/dist/assets/FlowRunsPage-DzZmtrDe.js +1 -0
  18. package/dist/assets/{IntegrationsPage-DwRFenrv.js → IntegrationsPage-DzBKAEgn.js} +2 -2
  19. package/dist/assets/InterfaceListPage-C_M0U8ns.js +1 -0
  20. package/dist/assets/{ManagedByBadge-BuKzVw4f.js → ManagedByBadge-DWtOXcFq.js} +1 -1
  21. package/dist/assets/MarketplaceAccessDenied-C4Yrv4Q7.js +1 -0
  22. package/dist/assets/{MarketplaceInstalledPage-zxinYFxx.js → MarketplaceInstalledPage-B6cbDzf8.js} +1 -1
  23. package/dist/assets/MarketplacePackagePage-D0dT7D3x.js +4 -0
  24. package/dist/assets/{MarketplacePage-C2tmfrC4.js → MarketplacePage-CtvxvBmw.js} +1 -1
  25. package/dist/assets/{MetadataInspector-BT_WB0Z2.js → MetadataInspector-9pMeoWpd.js} +1 -1
  26. package/dist/assets/{MetadataProvider-CaobQzBK.js → MetadataProvider-Y0oNNDXh.js} +1 -1
  27. package/dist/assets/ObjectDataPage-B8pGSNRJ.js +1 -0
  28. package/dist/assets/PageView-BBJl1RzL.js +1 -0
  29. package/dist/assets/ProfilePage-BL4aVTUO.js +1 -0
  30. package/dist/assets/PublicFormsPage-C-BWDI8O.js +1 -0
  31. package/dist/assets/RecordDetailView-BYYpDJSj.js +9 -0
  32. package/dist/assets/RecordFormPage-SLtEal-m.js +1 -0
  33. package/dist/assets/ReportDefaultInspector-B3KEMC9M.js +3 -0
  34. package/dist/assets/{ReportView-BPnukjAJ.js → ReportView-B3kMHgHe.js} +1 -1
  35. package/dist/assets/{SearchResultsPage-BrU2uBVw.js → SearchResultsPage-0eeyyaj-.js} +1 -1
  36. package/dist/assets/{SettingsHub-Be1x-xx5.js → SettingsHub-BVhaidAC.js} +1 -1
  37. package/dist/assets/SettingsView-D2klvVKS.js +1 -0
  38. package/dist/assets/{SystemHubPage-C7E2MVCX.js → SystemHubPage-CHcrvd-n.js} +1 -1
  39. package/dist/assets/{abnfDiagram-VRR7QNED-Hg1RYCKu.js → abnfDiagram-VRR7QNED-D2Rn6aHa.js} +1 -1
  40. package/dist/assets/{architectureDiagram-ZJ3FMSHR-DwfUOkLv.js → architectureDiagram-ZJ3FMSHR-DX6q2vGN.js} +1 -1
  41. package/dist/assets/{blockDiagram-677ZJIJ3-BDc1qSIS.js → blockDiagram-677ZJIJ3-T2IDNrvJ.js} +1 -1
  42. package/dist/assets/{c4Diagram-LMCZKHZV-B3uEgabN.js → c4Diagram-LMCZKHZV-B98pIIbx.js} +1 -1
  43. package/dist/assets/channel-BovwC1_7.js +1 -0
  44. package/dist/assets/{chunk-32BRIVSS-BX7QYsQG.js → chunk-32BRIVSS-CYNomNWc.js} +1 -1
  45. package/dist/assets/{chunk-52WLFC77-Cx4AaJIv.js → chunk-52WLFC77-DtGIB0uV.js} +2 -2
  46. package/dist/assets/{chunk-C7G6YPKG-HNW9cqtI.js → chunk-C7G6YPKG-yJXKQ2Sz.js} +1 -1
  47. package/dist/assets/{chunk-EX3LRPZG-CBmf4uVW.js → chunk-EX3LRPZG-BtAjfq6C.js} +1 -1
  48. package/dist/assets/{chunk-FWX5IMBZ-Dt6Lwztc.js → chunk-FWX5IMBZ-C4k19ShS.js} +1 -1
  49. package/dist/assets/{chunk-HOUHSVGY-BiLG0Jtx.js → chunk-HOUHSVGY-BuKclK6G.js} +1 -1
  50. package/dist/assets/{chunk-ICXQ74PX-V7Gv_S2c.js → chunk-ICXQ74PX-OP102czk.js} +1 -1
  51. package/dist/assets/{chunk-MOJQB5TN-zlBuobC7.js → chunk-MOJQB5TN-CToOzrGu.js} +1 -1
  52. package/dist/assets/{chunk-OGEWGWER-D9fNq6KM.js → chunk-OGEWGWER-9rMC3Zdz.js} +1 -1
  53. package/dist/assets/{chunk-PUDLZKDR-BufZGozB.js → chunk-PUDLZKDR-Bte-Y5BM.js} +1 -1
  54. package/dist/assets/{chunk-Q4XR5HBZ-C1v9xwSj.js → chunk-Q4XR5HBZ-B1-bRF4T.js} +1 -1
  55. package/dist/assets/{chunk-RYQCIY6F-Cuf3Er4p.js → chunk-RYQCIY6F-DX0uHAt-.js} +1 -1
  56. package/dist/assets/{chunk-V7JOEXUC-Bsulk3KW.js → chunk-V7JOEXUC-3Qai_qvf.js} +1 -1
  57. package/dist/assets/chunk-VAUOI2AC-B2LdZG5j.js +1 -0
  58. package/dist/assets/{chunk-VR4S4FIN-Cxz-AOSl.js → chunk-VR4S4FIN-C8tYB3zk.js} +1 -1
  59. package/dist/assets/{chunk-WYO6CB5R-BBCHPFWt.js → chunk-WYO6CB5R-chyhiVml.js} +1 -1
  60. package/dist/assets/chunk-XXDRQBXY-mZd7tFTQ.js +1 -0
  61. package/dist/assets/{chunk-ZGVPDNZ5-0VawavzG.js → chunk-ZGVPDNZ5-BHJQa9Yh.js} +1 -1
  62. package/dist/assets/classDiagram-OUVF2IWQ-opUQX7yT.js +1 -0
  63. package/dist/assets/classDiagram-v2-EOCWNBFH-opUQX7yT.js +1 -0
  64. package/dist/assets/{cose-bilkent-JH36ORCC-zGun_nYq.js → cose-bilkent-JH36ORCC-wNn6_7gi.js} +1 -1
  65. package/dist/assets/{createDerive-DGPok8w-.js → createDerive-DDuw-xzg.js} +1 -1
  66. package/dist/assets/{cynefinDiagram-TSTJHNR4-DAMk8Cyg.js → cynefinDiagram-TSTJHNR4-BpiN-sI9.js} +1 -1
  67. package/dist/assets/{dagre-VKFMJZFB-CcgN1PqH.js → dagre-VKFMJZFB-D4jpVOw8.js} +1 -1
  68. package/dist/assets/data-adapter-DJl5PvjF.js +17 -0
  69. package/dist/assets/{diagram-FQU43EPY-CQVlA0TA.js → diagram-FQU43EPY-DnGyLgYE.js} +1 -1
  70. package/dist/assets/{diagram-G47NLZAW-0UcUFyIH.js → diagram-G47NLZAW-BSDChPeN.js} +1 -1
  71. package/dist/assets/{diagram-NH7WQ7WH-B8E52D9k.js → diagram-NH7WQ7WH-Jir-M8yF.js} +1 -1
  72. package/dist/assets/{diagram-OA4YK3LP-CAJcB6Ez.js → diagram-OA4YK3LP-DG1np1W1.js} +1 -1
  73. package/dist/assets/{diagram-WEI45ONY-DWe95hfc.js → diagram-WEI45ONY-DRm_SlrH.js} +1 -1
  74. package/dist/assets/{ebnfDiagram-CCIWWBDH-vV-mO9pC.js → ebnfDiagram-CCIWWBDH-twfLoKY3.js} +1 -1
  75. package/dist/assets/{erDiagram-Q63AITRT-C37YlMu-.js → erDiagram-Q63AITRT-CABXVpgy.js} +1 -1
  76. package/dist/assets/flowDiagram-23GEKE2U-DxGbSmxA.js +1 -0
  77. package/dist/assets/framework-xOBpLspS.js +8 -0
  78. package/dist/assets/{ganttDiagram-NO4QXBWP-BbLQFz0H.js → ganttDiagram-NO4QXBWP-DRXGi_1T.js} +2 -2
  79. package/dist/assets/getIcon-yTDDbwhX.js +1 -0
  80. package/dist/assets/{gitGraphDiagram-IHSO6WYX-B4EJMjM2.js → gitGraphDiagram-IHSO6WYX-BtlNUS9M.js} +1 -1
  81. package/dist/assets/{highlighted-body-OFNGDK62-BURNftRE.js → highlighted-body-OFNGDK62-BNY8_Ou8.js} +1 -1
  82. package/dist/assets/{i18n-B4M18fi2.js → i18n-CWXRbuYk.js} +2 -2
  83. package/dist/assets/index-ByFHLPS0.js +2 -0
  84. package/dist/assets/index-QgmPkr95.css +2 -0
  85. package/dist/assets/{infoDiagram-FWYZ7A6U-ChMO4rou.js → infoDiagram-FWYZ7A6U-CrCNJ5GX.js} +1 -1
  86. package/dist/assets/infrastructure-EMqAhl6J.js +3 -0
  87. package/dist/assets/{ishikawaDiagram-FXEZZL3T-B5_tQUWs.js → ishikawaDiagram-FXEZZL3T-aBCt2dnS.js} +1 -1
  88. package/dist/assets/{journeyDiagram-5HDEW3XC-MxmpMgQO.js → journeyDiagram-5HDEW3XC-CQrIuFhF.js} +1 -1
  89. package/dist/assets/{kanban-definition-HUTT4EX6-x1u6yhTC.js → kanban-definition-HUTT4EX6-Bm4snCw1.js} +1 -1
  90. package/dist/assets/mermaid-GHXKKRXX-BN2PjcSK.js +1 -0
  91. package/dist/assets/{mermaid.core-Bo862wyf.js → mermaid.core-C5ZaZqXX.js} +2 -2
  92. package/dist/assets/metadata-admin-lW4yChcf.js +25 -0
  93. package/dist/assets/{mindmap-definition-LN4V7U3C-gv5cgZkr.js → mindmap-definition-LN4V7U3C-CzSOJVqY.js} +1 -1
  94. package/dist/assets/{pegDiagram-2B236MQR-BUvOaGez.js → pegDiagram-2B236MQR-DPkw74l3.js} +1 -1
  95. package/dist/assets/{pieDiagram-ENE6RG2P-CYsklKtm.js → pieDiagram-ENE6RG2P-Bnny8SeQ.js} +1 -1
  96. package/dist/assets/plugin-calendar-Dikj_A8Y.js +1 -0
  97. package/dist/assets/plugin-charts-_11K-vFF.js +7 -0
  98. package/dist/assets/plugin-chatbot-D5bVXJ_O.js +120 -0
  99. package/dist/assets/plugin-dashboard-QnlQx94Y.js +6 -0
  100. package/dist/assets/plugin-form-C8ibDrVW.js +1 -0
  101. package/dist/assets/plugin-gantt-ION4WU11.js +63 -0
  102. package/dist/assets/plugin-grid-BbCjdxhg.js +8 -0
  103. package/dist/assets/plugin-kanban-DMXe4mrr.js +1 -0
  104. package/dist/assets/plugin-map-ZzwBPooc.js +1 -0
  105. package/dist/assets/{plugin-markdown-CwKhoguC.js → plugin-markdown-DWlAZYfS.js} +1 -1
  106. package/dist/assets/plugin-report-4ufmhN37.js +59 -0
  107. package/dist/assets/plugin-timeline-CxuwO6Sj.js +1 -0
  108. package/dist/assets/plugin-tree-CqFsNYBt.js +1 -0
  109. package/dist/assets/plugin-view-BtrrVg8d.js +1 -0
  110. package/dist/assets/plugins-views-DuVwtJw-.js +4 -0
  111. package/dist/assets/{quadrantDiagram-ABIIQ3AL-DkdTo6wC.js → quadrantDiagram-ABIIQ3AL-DUB4EjfP.js} +1 -1
  112. package/dist/assets/{railroadDiagram-RFXS5EU6-CIvl_CtD.js → railroadDiagram-RFXS5EU6-DSfLwOL9.js} +1 -1
  113. package/dist/assets/{requirementDiagram-TGXJPOKE-BrmGcoHH.js → requirementDiagram-TGXJPOKE-BUoxthLY.js} +1 -1
  114. package/dist/assets/{runtime-metadata-persistence-C6n6ChsE.js → runtime-metadata-persistence-D0qPKjRP.js} +1 -1
  115. package/dist/assets/{sankeyDiagram-HTMAVEWB-DAhnVEku.js → sankeyDiagram-HTMAVEWB-CkjIusFl.js} +2 -2
  116. package/dist/assets/{sequenceDiagram-DBY2YBRQ-CmnHwkE8.js → sequenceDiagram-DBY2YBRQ-DlUPbsBe.js} +1 -1
  117. package/dist/assets/{skeletons-D3Ug_cFP.js → skeletons-DBVC-R2R.js} +1 -1
  118. package/dist/assets/{src-BGaMRjVN.js → src-CEjEbVE_.js} +1 -1
  119. package/dist/assets/src-CLs1ObAx.js +19 -0
  120. package/dist/assets/{src-DmkSCLdx.js → src-CQ-hf48v.js} +1 -1
  121. package/dist/assets/src-Cz3xMnYk.js +1 -0
  122. package/dist/assets/{src-BvgQ2BWs.js → src-DMTCYJgx.js} +1 -1
  123. package/dist/assets/{stateDiagram-2N3HPSRC-C4fJzxRx.js → stateDiagram-2N3HPSRC-vPDzyRlO.js} +1 -1
  124. package/dist/assets/stateDiagram-v2-6OUMAXLB-USH3Z7UN.js +1 -0
  125. package/dist/assets/{swimlanes-5IMT3BWC-DlIs3eSd.js → swimlanes-5IMT3BWC-mtpJqEnb.js} +1 -1
  126. package/dist/assets/swimlanesDiagram-G3AALYLV-CJNfyMoX.js +8 -0
  127. package/dist/assets/{timeline-definition-FHXFAJF6-B6xJ_8dh.js → timeline-definition-FHXFAJF6-vFc3MiyA.js} +1 -1
  128. package/dist/assets/ui-components-C5rSjsFE.js +72 -0
  129. package/dist/assets/{ui-layout-fGjoW3uv.js → ui-layout-D13CmhwI.js} +1 -1
  130. package/dist/assets/{use-book-data-BHNW-mtj.js → use-book-data-BJgo-RvZ.js} +1 -1
  131. package/dist/assets/useSettingsLabel-BJ1_MAmi.js +1 -0
  132. package/dist/assets/{vendor-charts-C9Rg4sGZ.js → vendor-charts-BbCFozUm.js} +3 -3
  133. package/dist/assets/{vendor-i18n-CJQUqRO0.js → vendor-i18n-ign3ofvT.js} +1 -1
  134. package/dist/assets/vendor-objectstack-ChpQDQzo.js +160 -0
  135. package/dist/assets/{vennDiagram-L72KCM5P-CL2kA9j_.js → vennDiagram-L72KCM5P-NYy-CpuJ.js} +1 -1
  136. package/dist/assets/{wardleyDiagram-EHGQE667-C2amdvDW.js → wardleyDiagram-EHGQE667-CB-LOOnu.js} +1 -1
  137. package/dist/assets/{xychartDiagram-FW5EYKEG-BgaF79Q6.js → xychartDiagram-FW5EYKEG-C04Hz7Q2.js} +2 -2
  138. package/dist/index.html +4 -4
  139. package/package.json +3 -2
  140. package/dist/assets/ApprovalsInboxPage-BezeS0Ba.js +0 -1
  141. package/dist/assets/AuditLogPage-BU6pDzCM.js +0 -1
  142. package/dist/assets/CreateViewDialog-CbODG8cr.js +0 -1
  143. package/dist/assets/ExpressionProvider-rrd8nTWz.js +0 -1
  144. package/dist/assets/FlowRunsPage-BUoUJIcB.js +0 -1
  145. package/dist/assets/InterfaceListPage-MefSdQ3L.js +0 -1
  146. package/dist/assets/MarketplaceAccessDenied-CXpRKhbs.js +0 -1
  147. package/dist/assets/MarketplacePackagePage-CfD4P1wE.js +0 -4
  148. package/dist/assets/ObjectDataPage-wTA2HFI2.js +0 -1
  149. package/dist/assets/PageView-C9Hwdfsl.js +0 -1
  150. package/dist/assets/ProfilePage-BQwxaOB7.js +0 -1
  151. package/dist/assets/PublicFormsPage-geV1om2C.js +0 -1
  152. package/dist/assets/RecordDetailView-BzGkapku.js +0 -9
  153. package/dist/assets/RecordFormPage-DBo0eZ72.js +0 -1
  154. package/dist/assets/ReportDefaultInspector-B7Nn-A6p.js +0 -3
  155. package/dist/assets/SettingsView-CrgWUS7G.js +0 -1
  156. package/dist/assets/channel-DWZQ9vnS.js +0 -1
  157. package/dist/assets/chunk-VAUOI2AC-C6BaCKWp.js +0 -1
  158. package/dist/assets/chunk-XXDRQBXY-DzukX8IV.js +0 -1
  159. package/dist/assets/classDiagram-OUVF2IWQ-DSs52z7w.js +0 -1
  160. package/dist/assets/classDiagram-v2-EOCWNBFH-DSs52z7w.js +0 -1
  161. package/dist/assets/data-adapter-ZwwuAvBG.js +0 -15
  162. package/dist/assets/flowDiagram-23GEKE2U-DkFOQ3_z.js +0 -1
  163. package/dist/assets/framework-DAbnem-u.js +0 -8
  164. package/dist/assets/getIcon-BLwvtaQI.js +0 -1
  165. package/dist/assets/index-BOGrThXK.css +0 -2
  166. package/dist/assets/index-C-dRvT9u.js +0 -2
  167. package/dist/assets/infrastructure-VRE-mbZZ.js +0 -3
  168. package/dist/assets/mermaid-GHXKKRXX-cZg7E0Lp.js +0 -1
  169. package/dist/assets/metadata-admin-CKjub8vw.js +0 -25
  170. package/dist/assets/plugin-calendar-DJdKEkjk.js +0 -1
  171. package/dist/assets/plugin-charts-DHSgUtpJ.js +0 -7
  172. package/dist/assets/plugin-chatbot-BjhIyyNM.js +0 -120
  173. package/dist/assets/plugin-dashboard-CjPCmbr_.js +0 -6
  174. package/dist/assets/plugin-form-BZooMe4v.js +0 -1
  175. package/dist/assets/plugin-gantt-C90gyywF.js +0 -63
  176. package/dist/assets/plugin-grid-UMSBKycd.js +0 -8
  177. package/dist/assets/plugin-kanban-CTnqV9IW.js +0 -1
  178. package/dist/assets/plugin-map-DjnC4ang.js +0 -1
  179. package/dist/assets/plugin-report-BgaatGo3.js +0 -59
  180. package/dist/assets/plugin-timeline-CqKcdOFC.js +0 -1
  181. package/dist/assets/plugin-tree-D73sSC3j.js +0 -1
  182. package/dist/assets/plugin-view-DG76zFsz.js +0 -1
  183. package/dist/assets/plugins-views-UwSroJxp.js +0 -4
  184. package/dist/assets/src-DTHo8Eqq.js +0 -1
  185. package/dist/assets/src-DjmHjms3.js +0 -19
  186. package/dist/assets/stateDiagram-v2-6OUMAXLB-CCWWu2-O.js +0 -1
  187. package/dist/assets/swimlanesDiagram-G3AALYLV-C8YV1J6I.js +0 -8
  188. package/dist/assets/ui-components-Xu43SW6A.js +0 -72
  189. package/dist/assets/useSettingsLabel-CgY3RtGh.js +0 -1
  190. package/dist/assets/vendor-objectstack-Bs6C4qGH.js +0 -122
@@ -1,19 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css"])))=>i.map(i=>d[i]);
2
- import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{a as n,c as r,d as i,f as a,g as o,h as s,l as c,m as l,o as u,p as d,r as f,s as p,u as m,y as h}from"./vendor-react-20ydC9aZ.js";import{_ as g,b as _,c as v,d as y,l as b,n as x,o as S,s as C,u as w,v as T,x as E}from"./infrastructure-VRE-mbZZ.js";import{$ as D,H as O,K as k,L as A,M as j,N as M,Pt as N,Q as P,R as ee,U as F,W as I,Xt as te,Zt as L,c as R,d as z,f as ne,i as re,j as ie,ot as ae,pn as oe,pt as se,rn as ce,rt as le,s as ue,un as de}from"./framework-DAbnem-u.js";import{h as fe,m as pe}from"./vendor-objectstack-Bs6C4qGH.js";import{$ as me,$n as B,$o as he,$r as ge,$s as _e,$t as ve,Aa as ye,Ao as be,Ar as xe,Ba as V,Br as Se,Bs as Ce,Bt as we,Ca as H,Cn as U,Co as Te,Cs as Ee,Ct as De,Dc as Oe,Di as ke,Dn as Ae,Dr as je,En as Me,Eo as Ne,Er as Pe,Fa as Fe,Fi as Ie,Fs as Le,Ft as W,G as Re,Ga as ze,Gt as Be,Ha as Ve,Hr as He,Ht as Ue,I as We,Ia as Ge,Ic as Ke,Ii as qe,It as Je,Ja as Ye,Jc as G,Jn as K,Jr as Xe,Js as Ze,Kc as Qe,Ki as $e,Lc as q,Li as et,Lo as tt,Lt as nt,Mi as rt,Mo as it,Mt as at,Nn as ot,No as st,Nr as J,Nt as ct,On as lt,Oo as ut,Or as dt,Pa as ft,Pi as pt,Ps as mt,Pt as ht,Q as gt,Qa as Y,Qn as _t,Qo as vt,Qr as yt,Qs as bt,Qt as xt,Ri as St,Rr as Ct,Rt as wt,Sa as Tt,Ss as Et,St as Dt,Ta as Ot,Ti as kt,Tn as At,Tr as jt,Ts as Mt,Uc as Nt,Ur as Pt,Us as Ft,Ut as It,V as Lt,Va as Rt,Vi as zt,Vt as Bt,Wa as Vt,Wi as Ht,Wo as Ut,Wr as Wt,Ws as Gt,Xa as Kt,Xc as qt,Xi as Jt,Xn as Yt,Xr as Xt,Xt as Zt,Yc as Qt,Yi as $t,Yn as en,Yr as tn,Ys as nn,Za as rn,Zn as an,Zs as on,Zt as sn,_c as cn,_i as ln,_n as un,_o as dn,_r as fn,_s as pn,ai as mn,an as hn,ar as gn,as as _n,ba as vn,bi as yn,br as bn,bt as xn,ca as Sn,cc as Cn,cn as wn,co as Tn,dc as En,dr as Dn,ea as On,ei as kn,en as An,er as jn,fo as Mn,fr as Nn,gi as Pn,gn as Fn,ha as In,hc as Ln,hi as Rn,hr as zn,in as Bn,ir as Vn,is as Hn,j as Un,jc as Wn,jr as Gn,js as Kn,ka as qn,kc as Jn,ki as Yn,kn as Xn,kr as Zn,ln as Qn,lo as $n,mo as er,mr as tr,ms as nr,ni as rr,nn as ir,nr as ar,nt as or,oc as sr,oi as cr,on as lr,oo as ur,or as dr,os as fr,ot as pr,qa as mr,qo as hr,rn as gr,rr as _r,rt as vr,sn as yr,ss as br,tc as xr,tn as Sr,tr as Cr,uo as wr,us as Tr,vi as Er,vn as Dr,vr as Or,vs as kr,wa as Ar,wi as jr,wn as Mr,wr as Nr,ws as Pr,xc as Fr,xi as Ir,xo as Lr,xs as Rr,xt as zr,yc as Br,yn as Vr,yr as Hr,zi as Ur}from"./ui-components-Xu43SW6A.js";import{n as Wr,r as X}from"./vendor-ui-utils-CDPjN0GN.js";import{n as Gr}from"./data-adapter-ZwwuAvBG.js";import{n as Kr,t as qr}from"./AdapterProvider-ClCj6PTd.js";import{a as Jr,n as Yr,o as Xr,s as Zr,t as Qr}from"./plugin-form-BZooMe4v.js";import{a as $r,i as ei,o as ti,r as ni,s as ri,t as ii}from"./MetadataProvider-CaobQzBK.js";import{a as ai,t as oi}from"./assistantBus-BqJT7SGk.js";import{n as si,r as ci,t as li}from"./ExpressionProvider-rrd8nTWz.js";import{F as ui,H as di,I as fi,L as pi,M as mi,N as hi,O as gi,P as _i,R as vi,_ as yi,a as bi,b as xi,c as Si,d as Ci,f as wi,g as Ti,h as Ei,i as Di,j as Oi,l as ki,m as Ai,o as ji,p as Mi,r as Ni,s as Pi,t as Fi,u as Ii,v as Li,y as Ri,z as zi}from"./RecordDetailView-BzGkapku.js";import{a as Bi,i as Vi,n as Hi,r as Ui}from"./PageView-C9Hwdfsl.js";import{C as Wi,S as Gi,T as Ki,_ as qi,b as Ji,d as Yi,f as Xi,g as Zi,h as Qi,i as $i,l as ea,m as ta,p as na,r as ra,t as ia,u as aa,v as oa,w as sa,x as ca,y as la}from"./plugin-chatbot-BjhIyyNM.js";import{A as ua,C as da,D as fa,E as pa,O as ma,S as ha,T as ga,_ as _a,a as va,b as ya,c as ba,d as xa,f as Sa,g as Ca,h as wa,i as Ta,j as Ea,k as Da,l as Oa,m as ka,n as Aa,o as ja,p as Ma,r as Na,s as Pa,u as Fa,v as Ia,w as La,x as Ra,y as za}from"./metadata-admin-CKjub8vw.js";import{C as Ba,D as Va,S as Ha,r as Ua,x as Wa,y as Ga}from"./MarketplaceAccessDenied-CXpRKhbs.js";import{n as Ka,r as qa,t as Ja}from"./ui-layout-fGjoW3uv.js";import{_ as Ya,a as Xa,c as Za,d as Qa,g as $a,h as eo,l as to,n as no,o as ro,s as io,t as ao,u as oo,v as so,y as co}from"./vendor-dndkit-CJ2SkGrK.js";import{t as lo}from"./preferLocal-CKqyhTP9.js";import{i as uo,n as fo,r as po,t as mo}from"./utils-CFdPTF34.js";import{n as ho}from"./plugin-grid-UMSBKycd.js";import{c as go,o as _o,s as vo}from"./InterfaceListPage-MefSdQ3L.js";import{t as yo}from"./getIcon-BLwvtaQI.js";import{h as bo,i as xo,r as Z}from"./i18n-B4M18fi2.js";import{o as So,s as Co}from"./createDerive-DGPok8w-.js";import{B as wo,E as To,G as Eo,H as Do,K as Oo,L as ko,M as Ao,N as jo,P as Mo,R as No,T as Po,U as Fo,V as Io,W as Lo,b as Ro,d as zo,m as Bo,w as Vo,z as Ho}from"./ReportDefaultInspector-B7Nn-A6p.js";import{n as Uo,t as Wo}from"./CreateViewDialog-CbODG8cr.js";import{d as Go}from"./plugins-views-UwSroJxp.js";import{c as Ko,d as qo,l as Jo,u as Yo}from"./plugin-view-DG76zFsz.js";import{n as Xo,t as Zo}from"./MetadataInspector-BT_WB0Z2.js";import{o as Qo,r as $o,t as es}from"./runtime-metadata-persistence-C6n6ChsE.js";import{n as ts}from"./ReportView-BPnukjAJ.js";import{t as ns}from"./ManagedByBadge-BuKzVw4f.js";import"./RecordFormPage-DBo0eZ72.js";import"./DashboardView-Co21jHAg.js";import"./SearchResultsPage-BrU2uBVw.js";import"./MarketplacePage-C2tmfrC4.js";import{n as rs}from"./MarketplacePackagePage-CfD4P1wE.js";import"./MarketplaceInstalledPage-zxinYFxx.js";import{n as is}from"./componentRegistry-ByxoJqMW.js";var Q=f(),$=e(h(),1);function as({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i,onConfirm:o,onToast:s}){let c=a(),{appName:u}=l(),{t:d}=G(),f=`/apps/${u}`,{execute:p,loading:m,error:h,runner:g}=F({context:{objectName:e,objectLabel:t||e,baseUrl:f},onConfirm:o,onToast:s});return(0,$.useEffect)(()=>{g.registerHandler(`create`,async()=>(r?.(null),{success:!0})),g.registerHandler(`delete`,async r=>{let a=Array.isArray(r.params?.records)?r.params.records.filter(e=>e?.id!=null):null;if(a&&a.length>1){let r=await Promise.allSettled(a.map(t=>n.delete(e,t.id))),o=r.filter(e=>e.status===`rejected`).length,s=r.length-o;return i?.(),o===0?(X.success(d(`objectActions.bulkDeleteSuccess`,{count:s,label:t||e,defaultValue:`Deleted ${s} ${t||e} records`})),{success:!0,reload:!0,silent:!0}):(X.error(d(`objectActions.bulkDeletePartial`,{succeeded:s,failed:o,defaultValue:`${s} deleted, ${o} failed`})),{success:!1})}let o=r.params?.recordId??r.params?.record?.id??a?.[0]?.id??r.recordId;if(!o)return{success:!1,error:d(`objectActions.noRecordId`)};let s=!1;if(e===`sys_permission_set`)try{s=(r.params?.record?.managed_by===void 0?await n.findOne(e,o):r.params.record)?.managed_by===`package`}catch{}try{return await n.delete(e,o),i?.(),X.success(s?d(`objectActions.resetPackageSetSuccess`,{label:t||e,defaultValue:`Permission set reset to its shipped baseline`}):d(`objectActions.deleteSuccess`,{label:t||e})),{success:!0,reload:!0,silent:!0}}catch(n){return X.error(d(`objectActions.deleteFailed`,{label:t||e}),{description:n.message}),{success:!1}}}),g.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&c(t.startsWith(`/`)?t:`${f}/${t}`),{success:!0}}),g.registerHandler(`refresh`,async()=>(i?.(),{success:!0,reload:!0}))},[g,e,n,r,i,c,f,d,t]),{execute:p,create:(0,$.useCallback)(()=>{r?.(null)},[r]),deleteRecord:(0,$.useCallback)(async(t,n)=>{let r=e===`sys_permission_set`&&n?.managed_by===`package`;return p({type:`delete`,confirmText:r?d(`objectActions.resetPackageSetConfirm`,{defaultValue:`This permission set ships with an installed package and cannot be removed. Deleting resets it to the shipped baseline and discards your environment customization. Continue?`}):d(`objectActions.deleteConfirm`),params:n?{recordId:t,record:n}:{recordId:t}})},[p,d,e]),navigateToView:(0,$.useCallback)(t=>{c(`${f}/${e}/view/${t}`)},[c,f,e]),navigateToRecord:(0,$.useCallback)(t=>{c(`${f}/${e}/record/${encodeURIComponent(t)}`)},[c,f,e]),loading:m,error:h}}function os(e){return e==null?[]:Array.isArray(e)?e:[e]}function ss(e,t){let{alias:n,value:r=`1`,replace:i=!0}=t??{},[a,o]=s(),c=(0,$.useMemo)(()=>os(n),[n]),l=(0,$.useCallback)(t=>t.get(e)===r||c.some(e=>t.get(e)===r),[e,r,c]),u=l(a),d=(0,$.useCallback)(t=>{if(t===l(a))return;let n=new URLSearchParams(a);if(t){n.set(e,r);for(let e of c)n.delete(e)}else{n.delete(e);for(let e of c)n.delete(e)}o(n,{replace:i})},[l,a,o,e,r,c,i]);return{open:u,setOpen:d,openOverlay:(0,$.useCallback)(()=>d(!0),[d]),closeOverlay:(0,$.useCallback)(()=>d(!1),[d]),toggleOverlay:(0,$.useCallback)(()=>{o(t=>{let n=new URLSearchParams(t);if(l(n)){n.delete(e);for(let e of c)n.delete(e)}else{n.set(e,r);for(let e of c)n.delete(e)}return n},{replace:i})},[o,l,e,r,c,i])}}var cs=(0,$.createContext)({theme:`system`,setTheme:()=>null});function ls({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)(cs.Provider,{...r,value:o,children:e})}var us=()=>{let e=(0,$.useContext)(cs);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function ds(){let e=Qt[((typeof document<`u`?document.documentElement.lang:``)||(typeof navigator<`u`?navigator.language:``)||`en`).toLowerCase().split(`-`)[0]]?.console;return!e||e===qt.console?qt.console:{...qt.console,...e,loadingSteps:{...qt.console.loadingSteps,...e.loadingSteps},error:{...qt.console.error,...e.error},actions:{...qt.console.actions,...e.actions}}}function fs({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,$.useState)(0),o=ds(),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:Wa()?(0,Q.jsx)(`img`,{src:Wa(),alt:Ba(),className:`h-10 w-10 object-contain`}):(0,Q.jsx)(nr,{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:Ba()}),(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)(Ft,{className:`h-5 w-5 shrink-0`}),(0,Q.jsx)(`span`,{className:`text-sm font-semibold`,children:o.error.connectionFailed})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground text-center break-words`,children:t}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:o.error.checkServer})]}),n&&(0,Q.jsx)(J,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`}),o.actions.retrying]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(On,{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)(gt,{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)(Ce,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,Q.jsx)(Y,{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})]})]})})}var ps=gi();function ms(){let{remediationRequired:e}=T();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)(gs,{message:e.message}):(0,Q.jsx)(vs,{message:e.message})})}):null}function hs(){let{signOut:e}=T(),{t}=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:t(`auth.remediation.signOut`)})}function gs({message:e}){let{changePassword:t,setRemediationRequired:n}=T(),{t:r}=G(),[i,a]=(0,$.useState)(``),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(``),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(null);return(0,Q.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),p(null),o!==c){p(r(`auth.remediation.password.mismatch`));return}d(!0);try{await t(i,o),n(null),window.location.reload()}catch(e){p(e instanceof Error?e.message:r(`auth.remediation.password.failed`)),d(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:r(`auth.remediation.password.title`)}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||r(`auth.remediation.password.fallbackMessage`)})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(U,{htmlFor:`rem-cur`,children:r(`auth.remediation.password.current`)}),(0,Q.jsx)(Vr,{id:`rem-cur`,type:`password`,autoComplete:`current-password`,value:i,onChange:e=>a(e.target.value),required:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(U,{htmlFor:`rem-new`,children:r(`auth.remediation.password.next`)}),(0,Q.jsx)(Vr,{id:`rem-new`,type:`password`,autoComplete:`new-password`,value:o,onChange:e=>s(e.target.value),required:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(U,{htmlFor:`rem-conf`,children:r(`auth.remediation.password.confirm`)}),(0,Q.jsx)(Vr,{id:`rem-conf`,type:`password`,autoComplete:`new-password`,value:c,onChange:e=>l(e.target.value),required:!0})]}),f?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:f}):null,(0,Q.jsx)(J,{type:`submit`,className:`w-full`,disabled:u,children:r(u?`auth.remediation.password.submitting`:`auth.remediation.password.submit`)}),(0,Q.jsx)(hs,{})]})}function _s({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,ps.toCanvas)(t,e,{width:184,margin:1},e=>{e&&n(e.message)})}})})}function vs({message:e}){let{enrollTotp:t,verifyTotp:n,setRemediationRequired:r}=T(),{t:i}=G(),[a,o]=(0,$.useState)(`password`),[s,c]=(0,$.useState)(``),[l,u]=(0,$.useState)(``),[d,f]=(0,$.useState)(``),[p,m]=(0,$.useState)([]),[h,g]=(0,$.useState)(!1),[_,v]=(0,$.useState)(null);return a===`password`?(0,Q.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),g(!0);try{let{totpURI:e,backupCodes:n}=await t(s);f(e),m(n??[]),o(`verify`)}catch(e){v(e instanceof Error?e.message:i(`auth.remediation.mfa.enrollFailed`))}finally{g(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:i(`auth.remediation.mfa.title`)}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||i(`auth.remediation.mfa.fallbackMessage`)})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(U,{htmlFor:`rem-pw`,children:i(`auth.remediation.mfa.confirmPassword`)}),(0,Q.jsx)(Vr,{id:`rem-pw`,type:`password`,autoComplete:`current-password`,value:s,onChange:e=>c(e.target.value),required:!0})]}),_?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:_}):null,(0,Q.jsx)(J,{type:`submit`,className:`w-full`,disabled:h,children:i(h?`auth.remediation.mfa.preparing`:`auth.remediation.mfa.continue`)}),(0,Q.jsx)(hs,{})]}):(0,Q.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),g(!0);try{await n(l.trim()),r(null),window.location.reload()}catch(e){v(e instanceof Error?e.message:i(`auth.remediation.mfa.invalidCode`)),g(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:i(`auth.remediation.mfa.scanTitle`)}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:i(`auth.remediation.mfa.scanBody`)})]}),d?(0,Q.jsx)(_s,{uri:d}):null,p.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:i(`auth.remediation.mfa.backupTitle`)}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:i(`auth.remediation.mfa.backupBody`)}),(0,Q.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 font-mono`,children:p.map(e=>(0,Q.jsx)(`span`,{children:e},e))})]}):null,(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(U,{htmlFor:`rem-code`,children:i(`auth.remediation.mfa.codeLabel`)}),(0,Q.jsx)(Vr,{id:`rem-code`,inputMode:`numeric`,autoComplete:`one-time-code`,maxLength:8,placeholder:`123456`,value:l,onChange:e=>u(e.target.value),required:!0})]}),_?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:_}):null,(0,Q.jsx)(J,{type:`submit`,className:`w-full`,disabled:h,children:i(h?`auth.remediation.mfa.verifying`:`auth.remediation.mfa.verify`)}),(0,Q.jsx)(hs,{})]})}function ys(){return(0,Q.jsx)(fs,{})}function bs({dataSource:e,children:t}){let{modalHandler:n,modalElement:r}=Oi(e),i=Hi({dataSource:e});return(0,Q.jsxs)(A,{context:i.actionProviderProps.context,onConfirm:i.actionProviderProps.onConfirm,onToast:i.actionProviderProps.onToast,onNavigate:i.actionProviderProps.onNavigate,onParamCollection:i.actionProviderProps.onParamCollection,onResultDialog:i.actionProviderProps.onResultDialog,onModal:n,handlers:{api:i.apiHandler,flow:i.flowHandler,script:i.serverActionHandler},children:[t,i.dialogs,r]})}function xs({children:e}){return(0,Q.jsx)(ls,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Q.jsx)(Ri,{children:(0,Q.jsx)(zi,{children:(0,Q.jsx)(yi,{children:(0,Q.jsx)(pi,{children:(0,Q.jsxs)(Da,{children:[(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(ys,{}),children:e}),(0,Q.jsx)(ms,{})]})})})})})})}function Ss({children:e}){return(0,Q.jsx)(qr,{children:(0,Q.jsx)($r,{children:(0,Q.jsx)(ws,{children:e})})})}var Cs=Kr(_({sameOriginOnly:!0}));function ws({children:e}){let t=ie(),{language:n}=G(),r=(0,$.useRef)(null);return t&&r.current!==null&&r.current!==n&&t.clearCache?.(),t&&(r.current=n),t?(0,Q.jsx)(le,{dataSource:t,apiFetch:Cs,children:(0,Q.jsxs)(ii,{adapter:t,children:[(0,Q.jsx)(Ts,{}),(0,Q.jsx)(bs,{dataSource:t,children:e})]},n)}):(0,Q.jsx)(ys,{})}function Ts(){let{user:e}=T(),t=ie(),n=di();return(0,$.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null),n(`flowPaletteRecents`,null);return}let r=Gr({dataSource:t,userId:e.id,key:`ui.favorites`}),i=Gr({dataSource:t,userId:e.id,key:`ui.recent`}),a=Gr({dataSource:t,userId:e.id,key:`ui.flow.palette.recents`});return n(`favorites`,r),n(`recent`,i),n(`flowPaletteRecents`,a),()=>{n(`favorites`,null),n(`recent`,null),n(`flowPaletteRecents`,null)}},[e?.id,t,n]),null}function Es({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r,getAuthConfig:i}=T(),[a,o]=(0,$.useState)(null);if((0,$.useEffect)(()=>{let e=!1;return i().then(t=>{e||o(t?.features?.multiOrgEnabled!==!1)}).catch(()=>{e||o(!1)}),()=>{e=!0}},[i]),r)return(0,Q.jsx)(ys,{});let s=n??[];if((s.length>0||t)&&!t)return(0,Q.jsx)(p,{to:`/organizations`,replace:!0});if(s.length===0&&!t){if(a===null)return(0,Q.jsx)(ys,{});if(a)return(0,Q.jsx)(p,{to:`/organizations`,replace:!0})}return(0,Q.jsx)(Q.Fragment,{children:e})}function Ds({children:e,redirectTo:t=`/home`}){let{enabled:n,isLoading:r}=Ea();return r?(0,Q.jsx)(ys,{}):n?(0,Q.jsx)(Q.Fragment,{children:e}):(0,Q.jsx)(p,{to:t,replace:!0})}function Os(){let e=i(),t=e.pathname.replace(/^\/system/,``);return(0,Q.jsx)(p,{to:`${t?`/apps/setup/system${t}`:`/apps/setup`}${e.search}${e.hash}`,replace:!0})}function ks({appLabel:e,onOpenDock:t}){let{t:n}=G(),{openSeq:r}=ai(),i=(0,$.useRef)(r);return(0,$.useEffect)(()=>{r!==i.current&&(i.current=r,t())},[r,t]),(0,Q.jsx)(`button`,{type:`button`,"aria-label":n(`topbar.openAssistant`,{defaultValue:`Open {{name}} assistant`,name:e}),onClick:t,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 As(e){let t=e?.issues;return Array.isArray(t)?t:[]}function js(e){return`• ${e.path&&e.path.length>0?e.path:`(root)`} — ${e.message}`}function Ms(e){let t=As(e);return t.length>0?t.map(js).join(`
3
- `):e?.message??String(e)}var Ns=`batch_aborted`;function Ps(e){let t=e=>[`${e.type}/${e.name}: ${e.error}`,...(Array.isArray(e.issues)?e.issues:[]).map(e=>` ${js(e)}`)].join(`
4
- `),n=e.filter(e=>e.code===Ns);if(n.length>0){let r=e.filter(e=>e.code!==Ns);return[`Nothing was published — the batch rolled back (all-or-nothing).`,...r.length>0?r.map(t):n.slice(0,1).map(t),`(${n.length} other draft${n.length===1?``:`s`} aborted with it — fix the cause and publish again.)`].join(`
5
- `)}return e.map(t).join(`
6
- `)}var Fs=[`sys_`,`ai_`,`cloud_`],Is=[`formula`,`summary`,`autonumber`];function Ls(e){let t=e?.fields??e?.data?.fields??e?.item?.fields??{};return(Array.isArray(t)?t.map(e=>[e?.name,e]):Object.entries(t)).map(([e,t])=>({name:t?.name??e,label:t?.label??t?.name??e,type:t?.type??`text`,required:!!t?.required,options:t?.options})).filter(e=>e.name&&!Is.includes(e.type))}function Rs({file:e,dataSource:t,defaultObjectName:n,onDone:r}){let{t:i}=G(),a=(0,$.useMemo)(()=>_(),[]),[o,s]=(0,$.useState)(null),[c,l]=(0,$.useState)(n??``),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(null),[m,h]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=!1,t=``.replace(/\/+$/,``);return(async()=>{try{let r=await a(`${t}/api/v1/meta/object`,{method:`GET`,credentials:`include`});if(!r.ok)throw Error(String(r.status));let i=await r.json().catch(()=>null),o=i?.data?.items??i?.items??i?.data??(Array.isArray(i)?i:[]),u=(Array.isArray(o)?o:[]).map(e=>({name:e?.name,label:e?.label||e?.name})).filter(e=>e.name&&!Fs.some(t=>e.name.startsWith(t)));if(e)return;if(s(u),!c&&u.length){let e=n&&u.find(e=>e.name===n);l(e?n:u[0].name)}}catch{e||s([])}})(),()=>{e=!0}},[a,n]);async function g(){if(c){d(!0);try{let e=Ls(await t.getObjectSchema(c));if(!e.length){X.error(i(`excelImport.noImportableFields`));return}p(e),h(!0)}catch{X.error(i(`excelImport.schemaReadFailed`))}finally{d(!1)}}}let v=o?.find(e=>e.name===c)?.label??c;return m&&f?(0,Q.jsx)(ho,{open:m,onOpenChange:e=>{h(e),e||r()},objectName:c,objectLabel:v,fields:f,dataSource:t,initialFile:e,onComplete:e=>{X.success(i(`excelImport.imported`,{count:e.importedRows,object:v}))}}):(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-muted/40 px-3 py-2 text-sm`,"data-excel-import-bar":!0,children:[(0,Q.jsx)(fn,{variant:`secondary`,children:`CSV / Excel`}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:i(`excelImport.importFrom`)}),(0,Q.jsx)(`code`,{className:`font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:i(`excelImport.into`)}),(0,Q.jsx)(`select`,{className:`h-8 rounded-md border border-input bg-background px-2 text-sm`,value:c,onChange:e=>l(e.target.value),disabled:!o||o.length===0,children:(o??[]).map(e=>(0,Q.jsx)(`option`,{value:e.name,children:e.label},e.name))}),(0,Q.jsx)(J,{size:`sm`,onClick:g,disabled:!c||u,children:i(u?`excelImport.opening`:`excelImport.importAction`)}),(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,onClick:r,children:i(`excelImport.dismiss`)})]})}function zs(){let{theme:e,setTheme:t}=us(),{t:n}=G();return(0,Q.jsxs)(Mr,{children:[(0,Q.jsx)(ot,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(ln,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Q.jsx)(Fe,{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)(At,{align:`end`,children:[(0,Q.jsxs)(Ae,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Q.jsx)(ln,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(Ae,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Q.jsx)(Fe,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(Ae,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Q.jsx)(Ge,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}function Bs(){let e=document.querySelector(`base`)?.getAttribute(`href`);return e?new URL(e,window.location.origin):new URL(`/`,window.location.origin)}function Vs(e){return e===void 0?Bs().toString():new URL(`.`,e).toString()}function Hs(e,t){return new URL(e.replace(/^\//,``),Vs(t)).toString()}function Us(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Ws({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:Us(e)})}function Gs(){let{t:e}=G(),t=a(),{organizations:n,activeOrganization:r,switchOrganization:i,getAuthConfig:o}=T(),[s,c]=(0,$.useState)(!1),l=go()===`group`;(0,$.useEffect)(()=>{let e=!1;return o?.().then(t=>{e||c(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[o]);let u=n??[],d=r??u[0]??null;if(!d||u.length<=1)return null;let f=async e=>{if(e.id!==d.id)try{await i(e.id),window.location.href=Vs()}catch(e){console.error(`[WorkspaceSwitcher] switch failed`,e)}};return(0,Q.jsxs)(Mr,{children:[(0,Q.jsxs)(ot,{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)(Ws,{name:d.name}),(0,Q.jsx)(`span`,{className:`hidden truncate sm:inline`,children:d.name}),(0,Q.jsx)(Gt,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]}),(0,Q.jsxs)(At,{align:`start`,className:`w-60`,children:[(0,Q.jsx)(lt,{className:`text-xs text-muted-foreground`,children:l?e(`organization.switcher.groupLabel`,{defaultValue:`Working organization`}):e(`organization.switcher.label`,{defaultValue:`Switch organization`})}),l&&(0,Q.jsx)(`p`,{className:`px-2 pb-1.5 text-xs font-normal leading-snug text-muted-foreground`,"data-testid":`workspace-switcher-group-hint`,children:e(`organization.switcher.groupHint`,{defaultValue:`New records are created here. Views show data from all your organizations.`})}),u.map(e=>(0,Q.jsxs)(Ae,{onClick:()=>f(e),className:`cursor-pointer gap-2`,children:[(0,Q.jsx)(Ws,{name:e.name}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.id===d.id&&(0,Q.jsx)(bt,{className:`h-4 w-4 shrink-0`})]},e.id)),(0,Q.jsx)(Xn,{}),(0,Q.jsxs)(Ae,{onClick:()=>t(`/organizations/${d.slug}/members`),className:`cursor-pointer gap-2`,"data-testid":`workspace-manage-members`,children:[(0,Q.jsx)(Xe,{className:`h-4 w-4`}),e(`organization.switcher.manageMembers`,{defaultValue:`Manage members`})]}),!s&&(0,Q.jsxs)(Ae,{onClick:()=>t(`/organizations?create=1`),className:`cursor-pointer gap-2`,"data-testid":`workspace-create`,children:[(0,Q.jsx)(Sn,{className:`h-4 w-4`}),e(`organizations.create`,{defaultValue:`Create workspace`})]})]})]})}var Ks=[{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 qs(){let{t:e,language:t,changeLanguage:n}=G();return(0,Q.jsxs)(Mr,{children:[(0,Q.jsx)(ot,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(be,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Q.jsx)(At,{align:`end`,className:`max-h-72 overflow-y-auto`,children:Ks.map(e=>(0,Q.jsxs)(Ae,{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 Js={connected:{labelKey:`topbar.connection.connected`,defaultValue:`Connected`,color:`text-green-500`,icon:Ce},connecting:{labelKey:`topbar.connection.connecting`,defaultValue:`Connecting...`,color:`text-yellow-500`,icon:Y},reconnecting:{labelKey:`topbar.connection.reconnecting`,defaultValue:`Reconnecting...`,color:`text-yellow-500`,icon:Y},disconnected:{labelKey:`topbar.connection.disconnected`,defaultValue:`Disconnected`,color:`text-muted-foreground`,icon:Pt},error:{labelKey:`topbar.connection.error`,defaultValue:`Connection Error`,color:`text-destructive`,icon:Pt}};function Ys({state:e,className:t}){let n=Js[e],{t:r}=G(),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:q(`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:q(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:i})]})}function Xs(e,t){if(!e)return``;let n=new Date(e).getTime();return Number.isNaN(n)?``:S(n,t)}function Zs(e){let t=[],n=new Map;for(let r of e){let e=(r.type??``).trim(),i=(r.title??``).trim(),a=e||i?`${e}\u0000${i}`:`__row__${r.id}`,o=n.get(a);o||(o={key:a,type:r.type,title:r.title,items:[],unreadCount:0,latestCreatedAt:r.created_at},n.set(a,o),t.push(o)),o.items.push(r),r.is_read||(o.unreadCount+=1),r.created_at&&(!o.latestCreatedAt||r.created_at>o.latestCreatedAt)&&(o.latestCreatedAt=r.created_at)}return t}function Qs({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:o,onMarkManyRead:s}){let{t:c,language:u}=G(),d=a(),f=l(),{currentAppName:p}=xi(),[m,h]=(0,$.useState)(!1),[g,_]=(0,$.useState)(`notifications`),[v,y]=(0,$.useState)(`unread`),[b,x]=(0,$.useState)(()=>new Set),S=(0,$.useMemo)(()=>Zs(e),[e]).reduce((e,t)=>e+ +(t.unreadCount>0),0),C=S+n,w=c(`sidebar.inboxAriaLabel`,{defaultValue:`Open inbox`}),T=(0,$.useRef)(null),[E,D]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=T.current;if(e!==null&&C>e){D(!0);let e=window.setTimeout(()=>D(!1),1200);return()=>window.clearTimeout(e)}T.current=C},[C]),(0,$.useEffect)(()=>{E||(T.current=C)},[E,C]);let O=()=>{h(!1);let e=p??f.appName;d(e?`/apps/${e}/system/approvals`:`/apps/setup/system/approvals`)},k=()=>{h(!1),d(`/apps/setup/sys_inbox_message?view=mine`)},A=()=>{h(!1),d(`/apps/setup/sys_activity`)},j=e=>{o(e.id);let t=p??f.appName;if(e.action_url){h(!1);let n=e.action_url;if(/^https?:\/\//i.test(n)){window.open(n,`_blank`,`noopener,noreferrer`);return}if(n.startsWith(`/apps/`)){d(n);return}let r=n.startsWith(`/`)?n:`/${n}`;d(t?`/apps/${t}${r}`:r);return}if(e.source_object&&e.source_id){h(!1);let n=t?`/apps/${t}/${e.source_object}/${e.source_id}`:`/objects/${e.source_object}/${e.source_id}`;d(n)}},M=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},N=e=>{let t=e.items.filter(e=>!e.is_read).map(e=>e.id);t.length!==0&&(s?s(t):t.forEach(o))},P=(e,t)=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>j(e),className:`w-full text-left ${t?`pl-9 pr-3 py-2`:`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:Xs(e.created_at,u)})]})]})});return(0,Q.jsxs)(Fn,{open:m,onOpenChange:h,children:[(0,Q.jsx)(Dr,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 relative shrink-0 ${E?`motion-safe:animate-bounce`:``}`,"aria-label":w,title:c(`sidebar.inbox`,{defaultValue:`Inbox`}),children:[(0,Q.jsx)(Fr,{className:`h-4 w-4`}),C>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:C>9?`9+`:C},C)]})}),(0,Q.jsxs)(un,{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:c(`sidebar.inbox`,{defaultValue:`Inbox`})}),g===`notifications`&&t>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:`text-xs text-muted-foreground hover:text-foreground`,children:c(`notifications.markAllRead`,{defaultValue:`Mark all read`})})]}),(0,Q.jsxs)(xn,{value:g,onValueChange:e=>_(e),className:`w-full`,children:[(0,Q.jsxs)(Dt,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Q.jsxs)(De,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(Fr,{className:`h-3.5 w-3.5`}),c(`sidebar.notifications`,{defaultValue:`Notifications`}),S>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:S>9?`9+`:S},`notif-${S}`)]}),(0,Q.jsxs)(De,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(kt,{className:`h-3.5 w-3.5`}),c(`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)(De,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(Ke,{className:`h-3.5 w-3.5`}),c(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Q.jsxs)(zr,{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:()=>y(`unread`),className:`text-xs px-2 py-1 rounded-md transition-colors ${v===`unread`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:[c(`notifications.filterUnread`,{defaultValue:`Unread`}),S>0&&(0,Q.jsx)(`span`,{className:`ml-1 text-[10px] opacity-70`,children:S})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>y(`all`),className:`text-xs px-2 py-1 rounded-md transition-colors ${v===`all`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:c(`notifications.filterAll`,{defaultValue:`All`})})]}),(()=>{let t=v===`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:v===`unread`?c(`notifications.emptyUnread`,{defaultValue:`You're all caught up`}):c(`notifications.empty`,{defaultValue:`No notifications`})}):(0,Q.jsx)(`ul`,{className:`divide-y`,children:Zs(t).map((e,t)=>{let n={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`}};if(e.items.length===1)return(0,Q.jsx)(`li`,{...n,children:P(e.items[0],!1)},e.key);let r=b.has(e.key);return(0,Q.jsxs)(`li`,{...n,children:[(0,Q.jsxs)(`div`,{className:`flex items-stretch`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>M(e.key),"aria-expanded":r,className:`flex-1 min-w-0 text-left px-3 py-2.5 hover:bg-accent transition-colors duration-150 ${e.unreadCount>0?`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.unreadCount>0?`opacity-100`:`opacity-0`}`,"aria-hidden":!0}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium leading-tight truncate`,children:e.title}),(0,Q.jsxs)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 text-[10px] font-medium leading-4 text-muted-foreground`,"aria-label":c(`notifications.groupCount`,{defaultValue:`{{count}} notifications`,count:e.items.length}),children:[`×`,e.items.length]})]}),e.items[0].body&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-1 mt-0.5`,children:e.items[0].body}),(0,Q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[Xs(e.latestCreatedAt,u),e.unreadCount>0&&(0,Q.jsxs)(`span`,{className:`ml-1`,children:[`·`,` `,c(`notifications.groupUnread`,{defaultValue:`{{count}} unread`,count:e.unreadCount})]})]})]}),(0,Q.jsx)(nn,{className:`mt-1 h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200 ${r?`rotate-90`:``}`,"aria-hidden":!0})]})}),e.unreadCount>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>N(e),className:`shrink-0 px-2 text-[10px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l`,title:c(`notifications.groupMarkReadTitle`,{defaultValue:`Mark all of this type read`}),children:c(`notifications.groupMarkRead`,{defaultValue:`Mark read`})})]}),r&&(0,Q.jsx)(`ul`,{className:`divide-y border-t bg-muted/20`,children:e.items.map(e=>(0,Q.jsx)(`li`,{children:P(e,!0)},e.id))})]},e.key)})})})(),(0,Q.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:k,className:`text-xs text-primary hover:underline`,children:c(`notifications.viewAll`,{defaultValue:`View all notifications`})})})]}),(0,Q.jsx)(zr,{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)(kt,{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:c(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:n})}),(0,Q.jsx)(J,{size:`sm`,className:`mt-3`,onClick:O,children:c(`notifications.viewApprovals`,{defaultValue:`View approvals`})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:c(`notifications.noPendingApprovals`,{defaultValue:`No pending approvals`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:O,className:`mt-2 text-xs text-primary hover:underline`,children:c(`notifications.openApprovalsInbox`,{defaultValue:`Open Approvals Inbox`})})]})})}),(0,Q.jsxs)(zr,{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:c(`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:[Xs(e.timestamp,u),` · `,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:A,className:`text-xs text-primary hover:underline`,children:c(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`})})})]})]})]})]})}function $s({activeAppName:e,onAppChange:t}){let{apps:n}=j(),{t:r}=G(),{appLabel:i}=Nt(),a=n||[],o=a.filter(e=>e.active!==!1&&e.hidden!==!0),s=uo(o,e)||uo(a.filter(e=>e.active!==!1),e)||o[0];return s?(0,Q.jsxs)(Mr,{children:[(0,Q.jsx)(ot,{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:mo(s.label,r)})}),(0,Q.jsx)(on,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Q.jsxs)(At,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Q.jsx)(lt,{className:`text-xs text-muted-foreground font-normal`,children:r(`layout.appSwitcher.switchApplication`,{defaultValue:`Switch Application`})}),(0,Q.jsx)(Xn,{}),o.map(e=>{let n=yo(e.icon),a=i({name:e.name,label:mo(e.label,r)}),o=s.name===e.name;return(0,Q.jsxs)(Ae,{onClick:()=>t(fo(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)(bt,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var ec=(0,$.createContext)(null);function tc({children:e}){let[t,n]=(0,$.useState)(null),r=(0,$.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Q.jsx)(ec.Provider,{value:r,children:e})}function nc(){return(0,$.useContext)(ec)?.value??null}function rc(e){let t=(0,$.useContext)(ec),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 ic(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),[]);rc((0,$.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}var ac=(0,$.createContext)(null);function oc({children:e}){let{open:t,setOpen:n,openOverlay:r,closeOverlay:i,toggleOverlay:a}=ss(Ni,{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)(ac.Provider,{value:o,children:e})}function sc(){return(0,$.useContext)(ac)||{open:!1,openCommandPalette:()=>{},closeCommandPalette:()=>{},toggleCommandPalette:()=>{},setOpen:()=>{}}}var cc=$.forwardRef(({className:e,onClick:t,"aria-label":n,title:r,...i},a)=>{let{toggleSidebar:o}=Be(),{t:s}=G(),c=String(n||r||s(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`}));return(0,Q.jsxs)(J,{ref:a,"data-sidebar":`trigger`,variant:`ghost`,size:`icon`,className:q(`h-7 w-7`,e),"aria-label":c,title:c,onClick:e=>{t?.(e),o()},...i,children:[(0,Q.jsx)(H,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:c})]})});cc.displayName=`LocalizedSidebarTrigger`;function lc({className:e}){let{t}=G(),n=Ha();if(n!==`preview`&&n!==`beta`)return null;let r=n===`beta`?t(`topbar.stage.beta`,{defaultValue:`Beta`}):t(`topbar.stage.preview`,{defaultValue:`Preview`}),i=t(`topbar.stage.tooltip`,{defaultValue:`This platform is in preview — features may change.`});return(0,Q.jsx)(fn,{variant:`secondary`,title:i,"aria-label":i,"data-testid":`platform-preview-badge`,className:q(`shrink-0 cursor-default select-none rounded-md px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide`,e),children:r})}function uc(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function dc(){return(0,Q.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var fc=[];function pc({variant:e,appName:t,objects:r,connectionState:o,presenceUsers:s,activities:c,activeAppName:u,onAppChange:d}){let f=e??(t?`app`:`home`),p=f===`app`,m=i(),h=l(),_=a(),{isOnline:v}=ne(),{openCommandPalette:b}=sc(),{openOverlay:x}=ss(Di),{user:S,signOut:C,isAuthEnabled:w,organizations:E,activeOrganization:D,isOrganizationsLoading:O,getAuthConfig:k}=T(),A=ie(),{enabled:M}=Ea(),N=g(),{t:P}=G(),{objectLabel:ee,dashboardLabel:F,pageLabel:I,reportLabel:te,viewLabel:L,appLabel:R}=Nt(),{apps:z,dashboards:re,pages:ae,reports:oe}=j(),{currentAppName:se,recordTitle:ce}=xi(),le=nc(),[ue,de]=(0,$.useState)(null),fe=(0,$.useCallback)(async()=>{if(ue===null)try{let e=A?.getClient?.();if(!e?.meta?.getItems){de([]);return}let t=await e.meta.getItems(`doc`),n=Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[];de(n.map(e=>({name:e?.name,label:e?.label,_packageId:e?._packageId})).filter(e=>e.name))}catch{de([])}},[ue,A]),[pe,me]=(0,$.useState)(null),[B,he]=(0,$.useState)([]),ge=(0,$.useRef)(!1),_e=(0,$.useRef)(!1),ve=(0,$.useRef)(!0);(0,$.useEffect)(()=>(ve.current=!0,()=>{ve.current=!1}),[]);let ye=(0,$.useRef)(!1),be=(0,$.useRef)(!1),xe=(0,$.useRef)(!1),[V,Se]=(0,$.useState)(0),Ce=(0,$.useRef)(!1),we=(0,$.useCallback)(async()=>{if(!A||!p)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!ge.current&&!xe.current){xe.current=!0;try{let t=await A.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(ge.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`&&String(e.summary??``).trim()).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??``,description:e.summary??``,timestamp:t??``}});e.length&&me(e)}}catch{}finally{xe.current=!1}}},[A,p]);(0,$.useEffect)(()=>{we()},[we]),(0,$.useEffect)(()=>{if(!A||!p||!S?.id||_e.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(!ye.current){ye.current=!0;try{let[e,t]=await Promise.all([A.find(`sys_inbox_message`,{$filter:{user_id:S.id},$orderby:{created_at:`desc`},$top:20}),A.find(`sys_notification_receipt`,{$filter:{user_id:S.id,channel:`inbox`},$top:200}).catch(()=>({data:[]}))]);if(!ve.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)})}let c=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}});he(c),r=n}catch(e){if(i(e)){_e.current=!0;return}r=Math.min(r*2,12e4)}finally{ye.current=!1}}},s=()=>{if(e||_e.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)}},[A,p,S?.id]),(0,$.useEffect)(()=>{if(!p||!S?.id||Ce.current)return;let e=`${``.replace(/\/$/,``)}/api/v1/approvals/requests`,t=[];S.id&&t.push(S.id),S.email&&t.push(S.email);for(let e of S.roles||[])e&&t.push(`role:${e}`);let n=!1,r=null,i=async()=>{if(t.length!==0&&!be.current){be.current=!0;try{let n=new URLSearchParams({status:`pending`,approverId:t.join(`,`)}),r=await fetch(`${e}?${n}`,{credentials:`include`,headers:wi()});if(r.status===404){Ce.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);ve.current&&Se(a.size)}catch{}finally{be.current=!1}}},a=()=>{n||Ce.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[p,S?.id]);let H=B.reduce((e,t)=>e+ +!t.is_read,0),U=(0,$.useCallback)(async(e,t)=>{let n=``.replace(/\/$/,``);await fetch(`${n}/api/v1/notifications/${e}`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,...wi()},body:JSON.stringify(t?{ids:t}:{})})},[]),Te=(0,$.useCallback)(async e=>{let t=B.find(t=>t.id===e);if(he(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),t?.notification_id)try{await U(`read`,[t.notification_id])}catch{}},[B,U]),Ee=(0,$.useCallback)(async()=>{if(B.filter(e=>!e.is_read).length){he(e=>e.map(e=>({...e,is_read:!0})));try{await U(`read/all`)}catch{}}},[B,U]),De=(0,$.useCallback)(async e=>{let t=new Set(e),n=B.filter(e=>t.has(e.id)&&!e.is_read).map(e=>e.notification_id).filter(e=>!!e);if(he(e=>e.map(e=>t.has(e.id)?{...e,is_read:!0}:e)),n.length)try{await U(`read`,n)}catch{}},[B,U]),Oe=Mi(),ke=s??(Oe.length>0?Oe:fc),je=c??pe??[],Pe=O||(E??[]).length>0||!!D,[Fe,Ie]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=!1;return k?.().then(t=>{e||Ie(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[k]);let W=m.pathname.split(`/`).filter(Boolean),Re=h.appName||W[1],ze=W[2],Be=`/apps/${Re}`,Ve=r??[],He=uo(z||[],u||se||Re),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_`)),Ke=He?._packageId,qe=Ke?(ue??[]).filter(e=>e._packageId===Ke):[],Je=p?po(He,N,{type:ze,name:W[3]}):null,Ye=Ge.map(e=>({label:ee(e),href:`${Be}/${e.name}`})),K=[];if(p){if(ze===`dashboard`){if(K.push({label:P(`console.breadcrumb.dashboards`),href:Be}),W[3]){let e=W[3],t=lo(re,e,He?._packageId)?.label||uc(e);K.push({label:F({name:e,label:t})})}}else if(ze===`page`){if(K.push({label:P(`console.breadcrumb.pages`),href:Be}),W[3]){let e=W[3],t=lo(ae,e,He?._packageId)?.label||uc(e);K.push({label:I({name:e,label:t})})}}else if(ze===`report`){if(K.push({label:P(`console.breadcrumb.reports`),href:Be}),W[3]){let e=W[3],t=lo(oe,e,He?._packageId)?.label||uc(e);K.push({label:te({name:e,label:t})})}}else if(ze===`system`)K.push({label:P(`console.breadcrumb.system`)}),W[3]&&K.push({label:uc(W[3])});else if(ze){let e=Ve.find(e=>e.name===ze);if(e){if(W[3]===`record`&&W[4]){let e=Ci(new URLSearchParams(m.search).get(ki));e.forEach((t,n)=>{let r=Ve.find(e=>e.name===t.o);K.push({label:r?ee(r):uc(t.o),href:`${Be}/${t.o}`});let i=t.i.length>12?`${t.i.slice(0,8)}…`:t.i;K.push({label:t.t||`#${i}`,href:Ii(Be,t,e.slice(0,n))})})}if(K.push({label:ee(e),href:`${Be}/${ze}`,siblings:Ye}),W[3]===`record`&&W[4]){let e=W[4].length>12?`${W[4].slice(0,8)}…`:W[4],t=ce?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;K.push({label:n||`#${e}`})}else if(W[3]===`view`&&W[4]){let t=W[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||uc(t),i=L(e.name,t,r);K.push({label:i})}}}}let Xe=K[K.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)(n,{to:`/home`,className:q(`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors overflow-hidden`,p&&`hidden sm:flex`),title:Ba(),children:Wa()?(0,Q.jsx)(`img`,{src:Wa(),alt:Ba(),className:`h-full w-full object-contain`}):(0,Q.jsx)(wr,{className:`h-4 w-4`})}),f===`home`&&(0,Q.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:Ba()}),(0,Q.jsx)(lc,{className:`ml-2 hidden sm:inline-flex`}),(0,Q.jsx)(Gs,{}),f===`orgs`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(dc,{}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:P(`organizations.title`,{defaultValue:`Organizations`})})]}),p&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(cc,{className:`lg:hidden shrink-0 ml-1`,"aria-label":P(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`})}),u&&d?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(dc,{})}),(0,Q.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)($s,{activeAppName:u,onAppChange:d})})]}):t?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(dc,{})}),(0,Q.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,K.map((e,t)=>{let r=t===K.length-1;return(0,Q.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,Q.jsx)(dc,{}),e.siblings&&e.siblings.length>1?(0,Q.jsxs)(Mr,{children:[(0,Q.jsxs)(ot,{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 ${r?`text-foreground/80`:`text-foreground/60`}`,children:[e.label,(0,Q.jsx)(on,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Q.jsxs)(At,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Q.jsx)(lt,{className:`text-xs text-muted-foreground font-normal`,children:P(`topbar.switchObject`,{defaultValue:`Switch Object`})}),(0,Q.jsx)(Xn,{}),e.siblings.map(e=>(0,Q.jsx)(Ae,{asChild:!0,children:(0,Q.jsx)(n,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,Q.jsx)(n,{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] ${r?`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] ${r?`text-foreground/80`:`text-foreground/60`}`,children:e.label})]},t)}),le&&le.views.length>0?le.views.length>1?(0,Q.jsxs)(Mr,{children:[(0,Q.jsx)(ot,{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:le.triggerLabel??le.views.find(e=>e.id===le.activeViewId)?.label??Xe}),(0,Q.jsx)(on,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Q.jsx)(At,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:le.views.map(e=>{let t=e.id===le.activeViewId;return(0,Q.jsxs)(Ae,{onSelect:()=>{t||le.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)(rn,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Q.jsx)(bt,{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:le.triggerLabel??le.views[0].label}):(0,Q.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:Xe})]})]}),(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`})]}),p&&o&&(0,Q.jsx)(Ys,{state:o}),p&&ke.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)(Ai,{users:ke,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:b,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)(zt,{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)(J,{variant:`ghost`,size:`icon`,className:`lg:hidden h-8 w-8 shrink-0`,"data-testid":`action:command-palette:open-mobile`,onClick:b,"aria-label":P(`console.search`,{defaultValue:`Search…`}),children:(0,Q.jsx)(zt,{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)(Qs,{notifications:B,unreadCount:H,pendingApprovalsCount:V,activities:je,onMarkAllRead:Ee,onMarkRead:Te,onMarkManyRead:De}),Je&&(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"data-testid":`app-design-in-studio-button`,"aria-label":P(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),title:P(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),children:(0,Q.jsx)(n,{to:Je,children:(0,Q.jsx)(Ne,{className:`h-4 w-4`})})}),M&&(0,Q.jsx)(J,{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)(n,{to:`/ai`,children:(0,Q.jsx)(cn,{className:`h-4 w-4`})})}),(0,Q.jsxs)(Mr,{onOpenChange:e=>{e&&fe()},children:[(0,Q.jsx)(ot,{asChild:!0,children:(0,Q.jsx)(J,{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)(Le,{className:`h-4 w-4`})})}),(0,Q.jsxs)(At,{align:`end`,className:`min-w-56 rounded-lg`,sideOffset:4,children:[qe.length>0&&Ke?(0,Q.jsxs)(Ae,{className:`cursor-pointer`,onClick:()=>_(qe.length===1?`/apps/${Ke}/docs/${qe[0].name}`:`/apps/${Ke}/docs`),children:[(0,Q.jsx)(Br,{className:`mr-2 h-4 w-4`}),P(`help.appDocs`,{defaultValue:`This app's docs`})]}):null,(0,Q.jsxs)(Ae,{className:`cursor-pointer`,onClick:()=>_(`/docs`),children:[(0,Q.jsx)(wr,{className:`mr-2 h-4 w-4`}),P(`help.allDocs`,{defaultValue:`All documentation`})]}),p?(0,Q.jsxs)(Ae,{className:`cursor-pointer`,"data-testid":`action:keyboard-shortcuts:open`,onClick:x,children:[(0,Q.jsx)(Mn,{className:`mr-2 h-4 w-4`}),P(`help.keyboardShortcuts`,{defaultValue:`Keyboard shortcuts`})]}):null,(0,Q.jsx)(Xn,{}),(0,Q.jsx)(Ae,{asChild:!0,className:`cursor-pointer`,children:(0,Q.jsxs)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,Q.jsx)(fr,{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)(Mr,{children:[(0,Q.jsx)(ot,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,Q.jsxs)(Or,{className:`h-7 w-7 rounded-full`,children:[(0,Q.jsx)(bn,{src:S?.image,alt:S?.name??`User`}),(0,Q.jsx)(Hr,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:y(S)})]})})}),(0,Q.jsxs)(At,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Q.jsx)(lt,{className:`p-0 font-normal`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,Q.jsxs)(Or,{className:`h-8 w-8 rounded-lg`,children:[(0,Q.jsx)(bn,{src:S?.image,alt:S?.name??`User`}),(0,Q.jsx)(Hr,{className:`rounded-lg bg-primary text-primary-foreground`,children:y(S)})]}),(0,Q.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,Q.jsx)(`span`,{className:`truncate font-semibold`,children:S?.name??`User`}),(0,Q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:S?.email??``})]})]})}),(0,Q.jsx)(Xn,{}),(0,Q.jsxs)(Me,{children:[(0,Q.jsxs)(Ae,{onClick:()=>_(`/apps/account/component/account/profile_card`),className:`cursor-pointer`,children:[(0,Q.jsx)(tn,{className:`mr-2 h-4 w-4`}),P(`user.profile`,{defaultValue:`Profile`})]}),Pe&&!Fe&&(0,Q.jsxs)(Ae,{onClick:()=>_(`/organizations?create=1`),className:`cursor-pointer`,"data-testid":`header-create-workspace`,children:[(0,Q.jsx)(Sn,{className:`mr-2 h-4 w-4`}),P(`organizations.create`,{defaultValue:`Create workspace`})]}),(z||[]).filter(e=>e.active!==!1&&e.hidden===!0&&e.name!==`account`).map(e=>{let t=yo(e.icon),n=R({name:e.name,label:mo(e.label,P)});return(0,Q.jsxs)(Ae,{onClick:()=>_(`/apps/${fo(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)(Xn,{}),(0,Q.jsx)(lt,{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)(zs,{})]}),(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)(qs,{})]}),w&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Xn,{}),(0,Q.jsxs)(Ae,{className:`text-destructive focus:text-destructive`,onClick:()=>C(),children:[(0,Q.jsx)(Kt,{className:`mr-2 h-4 w-4`}),P(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var mc=`ai-chat-dock-width`,hc=`ai-chat-dock-expanded`,gc=`ai-chat-studio-dock-expanded`,_c=`ai-chat-studio-dock-width`;function vc(e,t){let n=t>0?Math.max(340,t-520):1/0;return Math.min(Math.max(e,340),n)}function yc(e){return vc(e,e)}function bc(e){return e===`1`||e!==`0`&&null}function xc(e,t){try{let n=bc(window.sessionStorage.getItem(e));return n===null?t:n}catch{return t}}function Sc(e,t){try{window.sessionStorage.setItem(e,t?`1`:`0`)}catch{}}function Cc(){Sc(hc,!0)}var wc=`ai-chat-dock-return-to`;function Tc(e){try{window.sessionStorage.setItem(wc,e)}catch{}}function Ec(){try{let e=window.sessionStorage.getItem(wc);return e&&e.startsWith(`/`)&&!e.startsWith(`//`)?e:void 0}catch{return}}function Dc(e){return!(e.metaKey||e.ctrlKey)||!e.shiftKey||e.altKey?null:e.key.toLowerCase()===`i`?`toggle`:null}async function Oc(e){let t=await fetch(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(e)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`_drafts HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.drafts??n?.data?.drafts??[];return Array.isArray(r)?r.length:0}function kc(e){return{status:`drafted`,drafted:e.items,...e.summary?{summary:e.summary}:{},...e.packageId?{packageId:e.packageId}:{},...e.autoPublishable?{autoPublishable:!0}:{},...e.failedCount?{failed:Array.from({length:e.failedCount},()=>null)}:{},...e.materialized?{materialized:!0}:{},...e.verification?{verification:e.verification}:{},...e.issues&&e.issues.length?{issues:e.issues}:{},...e.nextSteps&&e.nextSteps.length?{nextSteps:e.nextSteps}:{}}}function Ac(e){return{status:`blueprint_proposed`,...e.summary?{summary:e.summary}:{},counts:e.counts,questions:e.questions,...e.targetApp?{targetApp:e.targetApp}:{},blueprint:{objects:e.objects.map(e=>({name:e.name,...e.label?{label:e.label}:{},fields:Array.from({length:e.fieldCount},()=>null)})),assumptions:e.assumptions}}}var jc=`objectstack:ai-chat-conversation-id`,Mc=`objectstack:ai-chat-messages`;function Nc(e,t){return t?`${jc}:${e}:${t}`:`${jc}:${e}`}function Pc(e){try{return localStorage.getItem(e)??void 0}catch{return}}function Fc(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function Ic(e){return`${Mc}:${e}`}function Lc(){try{let e=[];for(let t=0;t<localStorage.length;t+=1){let n=localStorage.key(t);n&&(n.startsWith(jc)||n.startsWith(Mc))&&e.push(n)}e.forEach(e=>localStorage.removeItem(e))}catch{}}function Rc(e){try{let t=localStorage.getItem(Ic(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`&&(e.role===`user`||e.role===`assistant`||e.role===`system`)&&Array.isArray(e.parts)):[]}catch{return[]}}function zc(e,t){if(e)try{if(t.length===0){localStorage.removeItem(Ic(e));return}localStorage.setItem(Ic(e),JSON.stringify(t))}catch{}}function Bc(e){return e.map(e=>{let t=[];if(e.content&&t.push({type:`text`,text:e.content}),e.role===`assistant`)for(let n of e.toolInvocations??[]){let e=n.draftReview?kc(n.draftReview):n.proposedPlan?Ac(n.proposedPlan):void 0;t.push({type:`tool-${n.toolName}`,toolCallId:n.toolCallId,toolName:n.toolName,state:n.state??(n.errorText?`output-error`:`output-available`),...n.errorText?{errorText:n.errorText}:{},...e===void 0?{}:{output:e}})}if(t.length!==0)return{id:e.id,role:e.role,parts:t}}).filter(e=>!!e)}function Vc(e){return typeof e==`string`?e?[{type:`text`,text:e}]:[]:Array.isArray(e)?e.map(e=>{if(typeof e==`string`)return e?{type:`text`,text:e}:void 0;if(e&&typeof e==`object`&&`type`in e&&typeof e.type==`string`)return e;if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return{type:`text`,text:e.text}}).filter(e=>!!e):e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts)?Vc(e.parts):[]}function Hc(e,t){for(let n of Vc(e)){let e=typeof n.toolCallId==`string`?n.toolCallId:void 0;if(!e)continue;let r=t.get(e);if(!r)continue;let i=n.output??n.result;if(i===void 0)continue;r.output=i;let a=n.errorText;r.state=n.isError||typeof a==`string`?`output-error`:`output-available`,typeof a==`string`&&(r.errorText=a)}}function Uc(e){if(!e)return[];let t=[],n=new Map;return e.forEach((e,r)=>{let i=e.role;if(i===`tool`){Hc(e.content,n);return}if(i!==`user`&&i!==`assistant`&&i!==`system`)return;let a=Vc(e.content);if(a.length!==0){if(i===`assistant`)for(let e of a){e.type===`tool-call`&&typeof e.toolName==`string`&&e.toolName&&(e.type=`tool-${e.toolName}`);let t=typeof e.toolCallId==`string`?e.toolCallId:void 0;t&&(e.type===`tool-call`||e.type.startsWith(`tool-`))&&n.set(t,e)}t.push({id:e.id??`msg-${r}`,role:i,parts:a})}}),t}function Wc(e){if(!(typeof e!=`string`||!e))try{let t=JSON.parse(e);return Array.isArray(t)?t:void 0}catch{return}}function Gc(e){return e?e.map(e=>{let t=e.id,n=typeof e.content==`string`?e.content:``;if(e.role===`assistant`){let r=Wc(e.tool_calls);if(r&&r.length>0){let e=[];return n&&e.push({type:`text`,text:n}),e.push(...r),{id:t,role:`assistant`,content:e}}return{id:t,role:`assistant`,content:n}}if(e.role===`tool`){let r=Wc(e.content);return r&&r.length>0&&r[0]?.type===`tool-result`?{id:t,role:`tool`,content:r}:{id:t,role:`tool`,content:[{type:`tool-result`,toolCallId:e.tool_call_id??``,toolName:`unknown`,output:{type:`text`,value:n}}]}}return{id:t,role:e.role,content:n}}):[]}async function Kc(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(n.status===404||n.status===403)return null;if(!n.ok)throw Error(`GET conversation failed: ${n.status}`);return await n.json()}async function qc(e){let t=await fetch(`${e}/conversations`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:`{}`});if(!t.ok)throw Error(`POST conversation failed: ${t.status}`);return await t.json()}async function Jc(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function Yc(e){let{userId:t,scope:n,apiBase:r,activeId:i,forceNew:a,resumeMode:o=`resume`,legacyScope:s,adoptLegacy:c}=e,l=(0,$.useRef)(c);l.current=c;let[u,d]=(0,$.useState)(void 0),[f,p]=(0,$.useState)([]),[m,h]=(0,$.useState)(!!t),g=(0,$.useRef)(!0),_=(0,$.useRef)(void 0),v=(0,$.useRef)(void 0),y=(0,$.useRef)(t);(0,$.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,$.useEffect)(()=>{let e=y.current;y.current=t,e&&e!==t&&Lc()},[t]),(0,$.useEffect)(()=>{if(!t){d(void 0),p([]),h(!1),_.current=void 0,v.current=void 0;return}let e=v.current!==n;if(!i&&!a&&!e&&_.current===t&&u)return;let c=!1,f=Nc(t,n);return!i&&(a||e&&_.current===t)&&(d(void 0),p([])),h(!0),(async()=>{try{if(i){let e=await Kc(r,i);if(c)return;if(e){Fc(f,e.id),d(e.id);let r=Uc(e.messages),i=r.length>0?r:Rc(e.id);(i.length>0||e.id!==u)&&p(i),_.current=t,v.current=n;return}Fc(f,void 0),zc(i,[])}else if(!a){let e=Pc(f);if(!e&&s&&l.current){let e=Pc(Nc(t,s));if(e){try{let i=await Kc(r,e);if(c)return;if(i){let e=Uc(i.messages),r=e.length>0?e:Rc(i.id);if(l.current?.(r)){Fc(f,i.id),d(i.id),p(r),_.current=t,v.current=n;return}}}catch{}if(c)return}}if(e){let i=await Kc(r,e);if(c)return;if(i){let e=Uc(i.messages);if(o!==`fresh`||e.length===0){d(i.id),p(o===`fresh`?[]:e.length>0?e:Rc(i.id)),_.current=t,v.current=n;return}}else Fc(f,void 0),zc(e,[])}}let e=await qc(r);if(c)return;Fc(f,e.id),d(e.id),p(Uc(e.messages)),_.current=t,v.current=n}catch{c||(d(void 0),p([]))}finally{c||h(!1)}})(),()=>{c=!0}},[t,n,r,i,a,o,s]);let b=(0,$.useCallback)(async()=>{if(!t)return;let e=Nc(t,n);h(!0);try{u&&await Jc(r,u),zc(u,[]),Fc(e,void 0);let t=await qc(r);if(Fc(e,t.id),zc(t.id,[]),!g.current)return;d(t.id),p([])}catch{g.current&&(d(void 0),p([]))}finally{g.current&&h(!1)}},[u,t,n,r]),x=(0,$.useCallback)(async()=>{if(!t)return;let e=Nc(t,n);h(!0);try{let i=await qc(r);if(Fc(e,i.id),zc(i.id,[]),!g.current)return;d(i.id),p([]),_.current=t,v.current=n}catch{}finally{g.current&&h(!1)}},[t,n,r]),S=(0,$.useCallback)(e=>{!t||!u||(Fc(Nc(t,e),u),_.current=t,v.current=e)},[t,u]);return{conversationId:u,conversationScope:v.current,initialMessages:f,isLoading:m,reset:b,startNew:x,rekeyScope:S}}function Xc(e){if(!e||e.length===0)return!1;let t=e[e.length-1];return!t||t.role!==`assistant`?!1:t.parts.some(e=>e.type===`text`&&String(e.text??``).trim().length>0)}function Zc(e){let{chatApi:t,conversationId:n}=e,[r,i]=(0,$.useState)(!1),a=(0,$.useRef)(void 0);return{errorSuppressed:r,handleChatError:(0,$.useCallback)(async e=>{if(e?.notSent){i(!1);return}let r=t?.replace(/\/agents\/[^/]+\/chat$/,``);if(!n||!r){i(!1);return}try{let e=Uc((await Kc(r,n))?.messages);if(Xc(e)&&a.current){a.current(e),i(!0);return}}catch{}i(!1)},[n,t]),setMessagesRef:a,resetSuppression:(0,$.useCallback)(()=>i(!1),[])}}function Qc(e){return e&&Zi(e)?`build`:`ask`}function $c({appId:e,product:t}){return e?`app:${e}:${t}`:t}var el=new Set([`new chat`,`new conversation`,`untitled`,`新对话`]);function tl(e){let t=e?.trim().toLowerCase();return!t||el.has(t)}function nl(e){let t=e.messages;if(!t||t.length===0)return;for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.role===`user`){let e=rl(n.content);if(e)return e}}let n=t[t.length-1];return rl(n?.content)}function rl(e){if(typeof e==`string`)return e.slice(0,140);if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return e.text.slice(0,140);if(e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts))return rl(e.parts);if(Array.isArray(e)){let t=e.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`?e.text:``).join(``);return t?t.slice(0,140):void 0}}function il(e){let t=e.title?.trim(),n=nl(e)??rl(e.preview);return{id:e.id,title:tl(t)?void 0:t,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:n}}async function al(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(!n.ok)return;let r=await n.json();return il(`conversation`in r&&r.conversation?r.conversation:r)}function ol(e){let{userId:t,apiBase:n,limit:r=50,refreshKey:i}=e,[a,o]=(0,$.useState)([]),[s,c]=(0,$.useState)(!!t),[l,u]=(0,$.useState)(void 0),[d,f]=(0,$.useState)(0),p=(0,$.useCallback)(async()=>{f(e=>e+1)},[]),m=(0,$.useCallback)(async e=>{try{await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`})}finally{o(t=>t.filter(t=>t.id!==e))}},[n]),h=(0,$.useCallback)(async(e,t)=>{let r=t.trim();o(t=>t.map(t=>t.id===e?{...t,title:r||void 0}:t));let i=await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:r})});if(!i.ok)throw f(e=>e+1),Error(`PATCH conversation failed: ${i.status}`)},[n]);return(0,$.useEffect)(()=>{if(!t){o([]),c(!1),u(void 0);return}let e=!1;return c(!0),u(void 0),(async()=>{try{let t=await fetch(`${n}/conversations?limit=${encodeURIComponent(String(r))}`,{credentials:`include`});if(!t.ok)throw Error(`GET conversations failed: ${t.status}`);let i=await t.json(),a=Array.isArray(i)?i:i.conversations??i.items??[];if(e)return;let s=a.map(il).sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));o(s);let c=s.filter(e=>!e.title&&!e.preview).slice(0,20);if(c.length>0){let t=await Promise.all(c.map(e=>al(n,e.id).catch(()=>void 0)));if(e)return;let r=new Map(t.filter(e=>!!(e?.preview||e?.title)).map(e=>[e.id,e]));r.size>0&&o(e=>e.map(e=>{let t=r.get(e.id);return t?{...e,title:e.title??t.title,preview:e.preview??t.preview}:e}))}}catch(t){if(e)return;u(t instanceof Error?t:Error(String(t))),o([])}finally{e||c(!1)}})(),()=>{e=!0}},[t,n,r,d,i]),{conversations:a,isLoading:s,error:l,refetch:p,remove:m,rename:h}}function sl(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 cl(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString()}var ll=[`today`,`yesterday`,`previous7Days`,`previous30Days`,`older`],ul={today:`Today`,yesterday:`Yesterday`,previous7Days:`Previous 7 days`,previous30Days:`Previous 30 days`,older:`Older`};function dl(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 ll.filter(e=>o[e].length>0).map(e=>({key:e,items:o[e]}))}function fl({userId:e,apiBase:t,activeAgent:n,className:r,refreshKey:i,titleHints:o,onNavigate:s}){let{t:c}=G(),u=a(),{conversationId:d}=l(),{conversations:f,isLoading:p,error:m,remove:h,rename:g}=ol({userId:e,apiBase:t,refreshKey:i}),[_,v]=(0,$.useState)(``),[y,b]=(0,$.useState)(void 0),x=n?ta(n):void 0,S=(0,$.useMemo)(()=>n?new Set(na(n)):void 0,[n]),C=(0,$.useMemo)(()=>f.map(e=>{let t=o?.[e.id]?.trim();return!t||e.title?.trim()||e.preview?.trim()?e:{...e,preview:t}}),[f,o]),w=(0,$.useMemo)(()=>S?C.filter(e=>!e.agentId||S.has(e.agentId)||e.id===d):C,[C,S,d]),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?ta(e.agentId):x;return t?`/ai/${t}/${e.id}`:`/ai/${e.id}`},[x]),D=(0,$.useCallback)(()=>{u(x?`/ai/${x}?new=1`:`/ai?new=1`),s?.()},[u,x,s]),O=(0,$.useCallback)(async(e,t)=>{e.stopPropagation(),await h(t),t===d&&(u(x?`/ai/${x}`:`/ai`,{replace:!0}),s?.())},[h,d,u,x,s]),k=(0,$.useCallback)(async(e,t)=>{b(void 0);try{await g(e,t)}catch{}},[g]);return(0,Q.jsxs)(`aside`,{className:q(`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)(J,{size:`sm`,variant:`outline`,onClick:D,"data-testid":`ai-new-chat`,children:[(0,Q.jsx)(Sn,{className:`h-3.5 w-3.5`}),c(`console.ai.newChat`)]})]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(zt,{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)(Vr,{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)(Qn,{className:`flex-1 min-h-0`,children:p&&f.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:c(`common.loading`)}):m?(0,Q.jsx)(`div`,{className:`px-3 py-4 text-xs text-destructive`,children:m.message}):w.length===0?(0,Q.jsxs)(or,{className:`px-3 py-8`,children:[(0,Q.jsx)(Rt,{className:`h-8 w-8 text-muted-foreground`}),(0,Q.jsx)(pr,{children:c(`console.ai.noChatsYet`)}),(0,Q.jsx)(vr,{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:dl(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:ul[e.key]})}),(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.items.map(e=>(0,Q.jsx)(ml,{conversation:e,query:_.trim(),active:e.id===d,renaming:e.id===y,onSelect:()=>{u(E(e)),s?.()},onDelete:t=>O(t,e.id),onStartRename:()=>b(e.id),onCancelRename:()=>b(void 0),onSubmitRename:t=>k(e.id,t)},e.id))})]},e.key))})})]})}function pl(e,t){if(!e)return e??null;let n=t?.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase(),i=[],a=0,o=0;for(;;){let t=r.indexOf(n,a);if(t===-1){i.push(e.slice(a));break}t>a&&i.push(e.slice(a,t)),i.push((0,Q.jsx)(`mark`,{className:`rounded-[2px] bg-primary/20 px-0.5 text-foreground`,children:e.slice(t,t+n.length)},o++)),a=t+n.length}return i}function ml({conversation:e,query:t,active:n,renaming:r,onSelect:i,onDelete:a,onStartRename:o,onCancelRename:s,onSubmitRename:c}){let{t:l}=G(),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:q(`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)(Vr,{ref:p,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),c(d)):e.key===`Escape`&&(e.preventDefault(),s())},className:`h-7 flex-1 text-sm`,"data-testid":`ai-conversation-rename-input-${e.id}`,"aria-label":l(`console.ai.renameConversation`)}),(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>c(d),"data-testid":`ai-conversation-rename-confirm-${e.id}`,"aria-label":l(`console.ai.saveRename`),children:(0,Q.jsx)(bt,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:s,"aria-label":l(`console.ai.cancelRename`),children:(0,Q.jsx)(Se,{className:`h-3.5 w-3.5`})})]})}):(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`div`,{className:q(`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:pl(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:pl(e.preview,t)}):null,(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[10px] text-muted-foreground`,title:cl(e.updatedAt??e.createdAt),children:sl(e.updatedAt??e.createdAt,l)})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100`,children:[(0,Q.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 hover:text-primary`,onClick:o,"data-testid":`ai-conversation-rename-${e.id}`,"aria-label":l(`console.ai.renameConversation`),children:(0,Q.jsx)(In,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 hover:text-destructive`,onClick:a,"data-testid":`ai-conversation-delete-${e.id}`,"aria-label":l(`console.ai.deleteConversation`),children:(0,Q.jsx)(mn,{className:`h-3.5 w-3.5`})})]})]})})}function hl(){return typeof window>`u`?``:window.location.pathname.startsWith(`/_console`)?`/_console`:``}function gl(e,t){let n=`${hl()}/apps/${encodeURIComponent(e)}`;return t?n:`${n}?preview=draft`}function _l({appName:e,appSegment:t,materialized:n=!1,refreshKey:r,onClose:i}){let{t:o}=G(),s=a(),c=(0,$.useRef)(null),l=t&&t.length?t:e;return(0,$.useEffect)(()=>{if(!c.current)return;let e=gl(l,n);try{c.current.getAttribute(`src`)!==e&&c.current.setAttribute(`src`,e)}catch{}},[l,n]),(0,$.useEffect)(()=>{if(r>0)try{c.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)(Hn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n?o(`console.ai.liveCanvasUnlisted`,{app:e,defaultValue:`Live app — {{app}} (unlisted until published)`}):o(`console.ai.liveCanvas`,{app:e,defaultValue:`Live preview — {{app}} (draft)`})}),t&&(0,Q.jsxs)(J,{size:`sm`,variant:`ghost`,onClick:()=>s(`/studio/${t}/interfaces`),"data-testid":`live-canvas-open-designer`,className:`gap-1.5`,title:o(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),"aria-label":o(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),children:[(0,Q.jsx)(Ne,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:o(`topbar.designInStudio`,{defaultValue:`Design in Studio`})})]}),(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,onClick:i,"data-testid":`live-canvas-close`,children:(0,Q.jsx)(Se,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`iframe`,{ref:c,title:`Draft preview: ${e}`,src:gl(l,n),className:`h-full w-full flex-1 border-0 bg-background`,"data-testid":`live-canvas-frame`})]})}function vl(e,t,n){let r=`/studio/${encodeURIComponent(e)}/${t}`;return n?`${r}?${ha}=${encodeURIComponent(ga(n))}`:r}function yl(e,t){if(!e)return null;let n=t.name?.trim();if(!n)return null;switch(t.type){case`object`:return vl(e,`data`,{type:`object`,name:n});case`flow`:return vl(e,`automations`,{type:`flow`,name:n});case`dashboard`:return vl(e,`interfaces`,{type:`dashboard`,name:n});case`page`:return vl(e,`interfaces`,{type:`page`,name:n});case`view`:{let t=n.indexOf(`.`);return vl(e,`interfaces`,{type:`object`,name:t>0?n.slice(0,t):n})}case`app`:return vl(e,`interfaces`);default:return null}}async function bl(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 xl({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),bl(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)(xt,{open:n,onOpenChange:r,children:(0,Q.jsxs)(ve,{side:`right`,className:`w-full overflow-y-auto sm:max-w-xl`,children:[(0,Q.jsxs)(Sr,{children:[(0,Q.jsxs)(ir,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(En,{className:`h-4 w-4`}),` Build Doctor`]}),(0,Q.jsx)(An,{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)(Y,{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)(Ce,{className:`h-4 w-4`}):(0,Q.jsx)(rr,{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)(Sl,{icon:(0,Q.jsx)(mt,{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)(Sl,{icon:(0,Q.jsx)(rr,{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)(Sl,{icon:(0,Q.jsx)(Kn,{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)(Cl,{entry:e},t))})]})]})]})]})})}function Sl({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 Cl({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})`:``]})}function wl(e){if(typeof e.content==`string`)return e.content;let t=e.parts;return Array.isArray(t)?t.map(e=>e&&typeof e==`object`&&e.type===`text`?String(e.text??``):``).join(` `):``}function Tl(e){if(Array.isArray(e))for(let t=e.length-1;t>=0;t--){let n=e[t];if(!n||n.role!==`user`)continue;let r=wl(n);if(r.trim())return/[一-鿿]/.test(r)?`zh-CN`:void 0}}function El(e){return(Tl(e)??``).toLowerCase().startsWith(`zh`)}var Dl=`/api/v1/ai`;function Ol(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function kl(e){let t=Ol(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 Al(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=Ol(r,`toolName`)??r.type.slice(5),a=Ol(r,`toolCallId`)??`${e.id}-${i}`,o=kl(r),s=r.output??r.result,c=Wi(s),l=Ki(s),u=Gi(s),d=sa(s);if(t.push({toolCallId:a,toolName:i,...o?{state:o}:{},...s===void 0?{}:{result:s},...c?{draftReview:c}:{},...l?{proposedPlan:l}:{},...u?{builderHandoff:u}:{},...d?{proposedChanges:d}:{},...r.errorText?{errorText:String(r.errorText)}:{}}),!n){let e=ca(c);e&&(n=e)}}return{id:e.id,role:e.role,content:r,...t.length>0?{toolInvocations:t}:{},...n?{buildProgress:n}:{}}})}function jl(e,t){if(t)return t;let n;for(let t of e)for(let e of t.toolInvocations??[]){let t=e.draftReview?.packageId||e.builderHandoff?.packageId;t&&(n=t)}return n}var Ml=`com.objectstack.`;function Nl(e){return typeof e._packageId==`string`&&e._packageId.startsWith(Ml)}function Pl(e){return e.find(e=>e.role===`user`)?.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``).trim()||void 0}var Fl={ask:{key:`console.ai.agentLabels.ask`,defaultValue:`Ask`},build:{key:`console.ai.agentLabels.build`,defaultValue:`Build`}};function Il(e,t,n){let r=t?Fl[ta(t)]:void 0;return r?e(r.key,{defaultValue:r.defaultValue}):n}function Ll(e,t,n){return Zi(t)?n?{title:n.appLabel?e(`console.ai.empty.editApp.title`,{defaultValue:`Editing “{{app}}”`,app:n.appLabel}):e(`console.ai.empty.editApp.titleGeneric`,{defaultValue:`Edit this app`}),description:e(`console.ai.empty.editApp.description`,{defaultValue:`What would you like to change? I’ll modify this app in place — add a field, object, view or automation, or adjust what’s already there.`})}:{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.`})}:Qi(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 Rl(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(/\/$/,``)}${Dl}`}var zl=`ai-chats-collapsed`;function Bl(){let[e,t]=(0,$.useState)(()=>{try{return localStorage.getItem(zl)===`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(zl,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 Vl=`ai-chat-pane-width`,Hl=480,Ul=360,Wl=420,Gl=24;function Kl(e,t){let n=t.containerWidth>0?Math.max(t.min,t.containerWidth-t.previewMin):1/0;return Math.min(Math.max(e,t.min),n)}function ql(e){let t=(0,$.useRef)(null),[n,r]=(0,$.useState)(()=>{try{let e=Number(localStorage.getItem(Vl));return Number.isFinite(e)&&e>0?e:Hl}catch{return Hl}}),[i,a]=(0,$.useState)(!1),o=(0,$.useCallback)(e=>Kl(e,{min:Ul,previewMin:Wl,containerWidth:t.current?.clientWidth??0}),[]),s=(0,$.useCallback)(e=>{try{localStorage.setItem(Vl,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`?Gl:0;t&&(e.preventDefault(),r(e=>{let n=o(e+t);return s(n),n}))},[o,s]),reset:(0,$.useCallback)(()=>{let e=o(Hl);r(e),s(e)},[o,s])}}function Jl(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 Yl(e,t){return t||(typeof e==`number`&&e>0?-1:`/home`)}var Xl=[];function Zl(e){let{chatApi:t,conversationId:n,pendingRef:r,doSend:i,pendingSignal:a,agentRoute:o}=e,s=!!t;return(0,$.useEffect)(()=>{if(!s||!n)return;let e=r.current;e&&(e.targetAgentRoute&&e.targetAgentRoute!==o||(r.current=null,i(e.content,e.files)))},[s,n,r,i,a,o]),(0,$.useCallback)((e,t)=>{if(s&&!n){r.current={content:e,files:t};return}i(e,t)},[s,n,r,i])}function Ql({apiBase:e,defaultAgent:t}={}){let{user:n}=T(),{t:r}=G(),i=n?.id,{agent:o,conversationId:c}=l(),[u]=s(),d=u.toString(),f=u.get(`new`)!==null,p=u.get(`package`)?.trim()||void 0,m=u.get(`handoffPrompt`)?.trim()||void 0,h=u.get(`parentConversationId`)?.trim()||void 0,g=a(),{setContext:_}=xi();(0,$.useEffect)(()=>{_(`home`)},[_]);let v=(0,$.useMemo)(()=>Rl(e),[e]),y={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:b,isLoading:x,error:S,refetch:C}=Xi({apiBase:v}),w=(0,$.useMemo)(()=>b.map(e=>e.name),[b]),E=!x&&b.length===0,D=(0,$.useMemo)(()=>{if(!o)return!1;if(b.length!==0)return oa(o,w)!==void 0},[o,b.length,w]),O=o?void 0:u.get(`agent`)??void 0,k=(0,$.useMemo)(()=>Yi(b,O??t??y),[b,O,t,y]),A=(0,$.useMemo)(()=>{if(b.length!==0)return o&&D?oa(o,w):k},[b.length,o,D,w,k]),j=A?ta(A):void 0,M=!!(o&&D===!1&&qi(o)),N=o&&D===!1&&!M?o:void 0,P=A?`${v}/agents/${encodeURIComponent(A)}/chat`:void 0,ee=A?$c({appId:p,product:Qc(A)}):void 0,F=A?Qc(A):void 0,I=p&&F===`build`&&ee!==F?F:void 0,te=(0,$.useCallback)(e=>!!p&&jl(Al(e),void 0)===p,[p]),{conversationId:L,conversationScope:R,initialMessages:z,rekeyScope:ne}=Yc({userId:A?i:void 0,scope:ee,apiBase:v,activeId:c??N,forceNew:f,legacyScope:I,adoptLegacy:I?te:void 0}),re=R===ee,ie=re?L:void 0,ae=re?z:Xl;(0,$.useEffect)(()=>{if(b.length===0||!A)return;let e=ta(A),t=new URLSearchParams(d);t.delete(`agent`);let n=t.toString()?`?${t.toString()}`:``;if(!o){g(`/ai/${e}${n}`,{replace:!0});return}if(M){g(`/ai/${e}${n}`,{replace:!0});return}if(D&&o!==e){let t=c?`/${encodeURIComponent(c)}`:``;g(`/ai/${e}${t}${n}`,{replace:!0})}},[b.length,A,o,D,M,c,d,g]),(0,$.useEffect)(()=>{if(N===void 0)return;let e=!1;return(async()=>{let t;try{t=(await Kc(v,N))?.agentId??void 0}catch{}if(e)return;let n=ta(oa(t??``,w)??A??`ask`);g(`/ai/${n}/${encodeURIComponent(N)}`,{replace:!0})})(),()=>{e=!0}},[N,v,w,A,g]);let[oe,se]=(0,$.useState)(0),[ce,le]=(0,$.useState)({}),[ue,de]=(0,$.useState)(!1),[fe,pe]=(0,$.useState)(!1),[me,B]=(0,$.useState)(!1),{collapsed:he,toggle:ge,handleCanvasOpenChange:_e}=Bl();(0,$.useEffect)(()=>{let e=e=>{let t=Jl(e);t&&(e.preventDefault(),t===`toggle-list`?ge():g(j?`/ai/${j}?new=1`:`/ai?new=1`))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[ge,g,j]);let ye=(0,$.useMemo)(()=>v.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[v]),be=(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`},[]),xe=(0,$.useRef)(null);f?xe.current===null&&(xe.current={id:L}):xe.current=null,(0,$.useEffect)(()=>{if(!D||c||!L||!j||xe.current&&xe.current.id===L||R!==ee)return;let e=p?`?package=${encodeURIComponent(p)}`:``;g(`/ai/${j}/${L}${e}`,{replace:!0})},[D,c,L,R,ee,j,p,g]);let V=(0,$.useCallback)(e=>{!e||p||F!==`build`||!j||ee!==F||R!==ee||!L||c!==L||(ne($c({appId:e,product:F})),g(`/ai/${j}/${encodeURIComponent(L)}?package=${encodeURIComponent(e)}`,{replace:!0}))},[p,F,j,ee,R,L,c,ne,g]),Se=(0,$.useRef)(new Set);(0,$.useEffect)(()=>{L&&z.length>0&&Se.current.add(L)},[L,z.length]),(0,$.useEffect)(()=>{if(!L)return;let e=Pl(z);e&&le(t=>t[L]===e?t:{...t,[L]:e})},[L,z]);let Ce=(0,$.useRef)(null),[we,U]=(0,$.useState)(0),Te=(0,$.useCallback)(e=>{Ce.current=e,U(e=>e+1)},[]),Ee=(0,$.useRef)(null);(0,$.useEffect)(()=>{!m||o!==`build`||Ee.current!==m&&(Ee.current=m,Te({content:m,targetAgentRoute:`build`}))},[m,o,Te]);let De=(0,$.useCallback)(e=>{if(se(e=>e+1),e&&L&&le(t=>({...t,[L]:e})),!e||!L||Se.current.has(L))return;Se.current.add(L);let t=()=>se(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[L]);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:[!E&&(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 md:hidden`,onClick:()=>B(!0),"aria-label":r(`console.ai.openChats`),"data-testid":`ai-chat-mobile-sidebar-trigger`,children:(0,Q.jsx)(H,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(pc,{variant:`home`})}),!E&&(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"data-testid":`ai-chat-collapse-to-dock`,"aria-label":r(`console.ai.collapseToDock`,{defaultValue:`Collapse to side panel`}),title:r(`console.ai.collapseToDock`,{defaultValue:`Collapse to side panel`}),onClick:()=>{Cc();let e=Yl(window.history.state?.idx,Ec());g(e===-1?-1:e)},children:(0,Q.jsx)(vn,{className:`h-4 w-4`})})]}),E?(0,Q.jsx)($l,{hasError:!!S,onRetry:C,onHome:()=>g(`/home`),t:r}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(xt,{open:me,onOpenChange:B,children:(0,Q.jsxs)(ve,{side:`left`,className:`w-[320px] p-0 sm:max-w-[360px]`,"data-testid":`ai-chat-mobile-sidebar`,children:[(0,Q.jsxs)(Sr,{className:`sr-only`,children:[(0,Q.jsx)(ir,{children:r(`console.ai.chats`)}),(0,Q.jsx)(An,{children:r(`console.ai.chatsDescription`)})]}),(0,Q.jsx)(fl,{userId:i,apiBase:v,activeAgent:A,refreshKey:oe,titleHints:ce,className:`h-full border-r-0`,onNavigate:()=>B(!1)})]})}),L&&(0,Q.jsx)(Lt,{open:ue,onOpenChange:de,objectName:`ai_conversations`,recordId:L,recordLabel:`this conversation`,apiBase:ye,publicBaseUrl:be}),L&&aa(b,A,`debug`)&&(0,Q.jsx)(xl,{apiBase:v,conversationId:L,open:fe,onOpenChange:pe}),(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 w-full bg-background`,children:[(0,Q.jsxs)(`div`,{className:`hidden shrink-0 flex-col border-r md:flex`,children:[!he&&(0,Q.jsx)(fl,{userId:i,apiBase:v,activeAgent:A,refreshKey:oe,titleHints:ce,className:`w-72 min-h-0 flex-1 border-r-0`}),(0,Q.jsx)(`div`,{className:q(`mt-auto p-2`,he?`w-12`:`w-72 border-t`),children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:ge,"aria-label":he?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),title:he?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),"data-testid":`ai-chat-collapse-sidebar-trigger`,"aria-pressed":he,children:he?(0,Q.jsx)(Ar,{className:`h-4 w-4`}):(0,Q.jsx)(Ot,{className:`h-4 w-4`})})})]}),(0,Q.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:(0,Q.jsx)(eu,{agents:b,agentsLoading:x,agentsError:S,activeAgent:A,chatApi:P,apiBase:v,conversationId:ie,editPackageId:p,onPackageBound:V,canBind:!!c,parentHandoffConversationId:h,initialMessages:ae,pendingFirstMessageRef:Ce,pendingFirstMessageSeq:we,onSent:De,onShare:()=>de(!0),onDebug:()=>pe(!0),showDebug:aa(b,A,`debug`),onCanvasOpenChange:_e},`${P??`local`}:${ie??`pending`}`)})]})]})]})}function $l({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)(or,{children:[(0,Q.jsx)(pr,{children:r(`console.ai.unavailableTitle`,{defaultValue:`AI assistant unavailable`})}),(0,Q.jsx)(vr,{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)(J,{variant:`outline`,onClick:t,"data-testid":`ai-unavailable-retry`,children:r(`console.ai.unavailableRetry`,{defaultValue:`Try again`})}),(0,Q.jsx)(J,{onClick:n,"data-testid":`ai-unavailable-home`,children:r(`console.ai.unavailableHome`,{defaultValue:`Back to home`})})]})]})})}function eu({agents:e,agentsLoading:t,agentsError:n,activeAgent:r,chatApi:i,apiBase:s,conversationId:c,editPackageId:l,onPackageBound:u,canBind:d,parentHandoffConversationId:f,initialMessages:p,pendingFirstMessageRef:m,pendingFirstMessageSeq:h,onSent:g,onShare:_,onDebug:v,showDebug:y,onCanvasOpenChange:b}){let{t:x}=G(),S=a(),C=e.length>1,w=(0,$.useCallback)(e=>{let t=new URLSearchParams,n=e.packageId||l;n&&t.set(`package`,n),e.prompt&&t.set(`handoffPrompt`,e.prompt),c&&t.set(`parentConversationId`,c);let r=t.toString();S(`/ai/build${r?`?${r}`:``}`)},[S,l,c]),[T,E]=(0,$.useState)(null),[D,O]=(0,$.useState)(0),k=sn(),[A,M]=(0,$.useState)(!1);(0,$.useEffect)(()=>{T||M(!1)},[T]);let N=ie(),[P,ee]=(0,$.useState)(null),F=(0,$.useRef)(null);(0,$.useEffect)(()=>()=>{F.current&&window.clearTimeout(F.current)},[]);let I=T!==null;(0,$.useEffect)(()=>{b?.(I)},[I,b]);let te=ql(I),L=(0,$.useCallback)((e,t)=>{let n=e.find(e=>e.type===`app`);n&&E(e=>e??{name:n.name,segment:t,materialized:!1}),F.current&&window.clearTimeout(F.current),F.current=window.setTimeout(()=>O(e=>e+1),800)},[]),R=(0,$.useCallback)(e=>{E(t=>t&&t.name===e&&!t.materialized?{...t,materialized:!0}:t??{name:e,materialized:!0})},[]);(0,$.useEffect)(()=>{E(null)},[c]);let z=(0,$.useMemo)(()=>{let t=e.find(e=>e.name===r);return Il(x,r,t?.label??r??x(`console.ai.assistant`))},[e,r,x]),ne=(0,$.useMemo)(()=>Al(p),[p]),{errorSuppressed:re,handleChatError:ae,setMessagesRef:oe,resetSuppression:se}=Zc({chatApi:i,conversationId:c}),{models:ce,defaultModelId:le}=ea({apiBase:s}),[ue,de]=(0,$.useState)(void 0),fe=ue??le,{messages:pe,isLoading:me,error:B,sendMessage:he,stop:ge,reload:_e,clear:ve,setMessages:ye}=Ji({api:i,conversationId:c,parentConversationId:f,model:fe,onError:ae,body:{context:{activeApp:`AI`,agentName:r,autoPublishAiBuilds:Va().features.autoPublishAiBuilds,...l?{packageId:l}:{}}},initialMessages:ne,autoResponse:!i,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600});(0,$.useEffect)(()=>{oe.current=ye},[ye]),(0,$.useEffect)(()=>{zc(c,Bc(pe))},[c,pe]);let be=(0,$.useMemo)(()=>El(pe)||El(p),[pe,p]),xe=be?`确认,开始搭建。`:x(`console.ai.planApproveMessage`,{defaultValue:`Looks good — build it as proposed.`}),V=be?`确认搭建,未决问题按你的合理假设和默认处理。`:x(`console.ai.planApproveDefaultsMessage`,{defaultValue:`Build it with your best assumptions; use sensible defaults for the open questions.`}),Se=be?`确认修改,应用你刚才提议的改动。`:x(`console.ai.changesConfirmMessage`,{defaultValue:`Confirm — apply the change you just proposed.`}),Ce=(0,$.useMemo)(()=>({create_object:x(`console.ai.changeVerb.createObject`,{defaultValue:`Create object`}),add_field:x(`console.ai.changeVerb.addField`,{defaultValue:`Add field`}),modify_field:x(`console.ai.changeVerb.modifyField`,{defaultValue:`Modify field`}),delete_field:x(`console.ai.changeVerb.deleteField`,{defaultValue:`Delete field`}),create_metadata:x(`console.ai.changeVerb.createMetadata`,{defaultValue:`Create`}),update_metadata:x(`console.ai.changeVerb.updateMetadata`,{defaultValue:`Modify`}),create_seed:x(`console.ai.changeVerb.createSeed`,{defaultValue:`Generate sample data`}),create_package:x(`console.ai.changeVerb.createPackage`,{defaultValue:`Create app package`})}),[x]),we=(0,$.useRef)(!1);(0,$.useEffect)(()=>{we.current&&!me&&T&&O(e=>e+1),we.current=me},[me,T]);let H=ia({messages:pe,apiBase:s,continueConversation:e=>{he(e)}}),U=Zl({chatApi:i,conversationId:c,pendingRef:m,doSend:(0,$.useCallback)((e,t)=>{se();let n=(t??[]).filter(e=>/\.(xlsx|xlsm|csv|tsv|txt)$/i.test(e.name));if(!n.length){if(t?.length){he(`${e}\n\n(用户上传了 ${t.length} 个附件:${t.map(e=>e.name).join(`、`)} — 当前仅支持读取表格类附件(Excel/CSV),这些文件的内容我没有读取。)`),g(e);return}he(e),g(e);return}ee(n[0]),(async()=>{let r=e=>e.length>40?`${e.slice(0,40)}…`:e,i=e=>e.slice(0,12).map(e=>r(String(e??``)).replace(/\s+/g,` `)).join(` | `),a=e;for(let e of n.slice(0,2))try{let{parseSpreadsheetFile:t}=await o(async()=>{let{parseSpreadsheetFile:e}=await import(`./plugin-grid-UMSBKycd.js`).then(e=>e.t);return{parseSpreadsheetFile:e}},__vite__mapDeps([0]),import.meta.url),n=await t(e),r=n[0]??[],s=n.slice(1,4);a+=[`\n\n[附件表格 ${e.name} — ${Math.max(0,n.length-1)} 数据行 × ${r.length} 列(控制台已在本地解析,文件本体未上传)]`,`表头: ${i(r)}`,...s.map((e,t)=>`样例${t+1}: ${i(e)}`)].join(`
7
- `)}catch(t){a+=`\n\n[附件表格 ${e.name}] 解析失败(${t instanceof Error?t.message:`unknown`})— 请引导用户改用对象列表的 Import 上传该文件。`}n.length>2&&(a+=`\n\n(另有 ${n.length-2} 个表格附件未读取 — 一次最多读取 2 个。)`);let s=(t??[]).length-n.length;s>0&&(a+=`\n\n(另有 ${s} 个非表格附件,内容未读取。)`),he(a),g(a)})()},[se,he,g]),pendingSignal:h,agentRoute:r?ta(r):void 0}),Te=r?ta(r)===`build`:!1,{apps:Ee}=j(),Oe=Ee,{appLabel:je}=Nt(),Me=(0,$.useMemo)(()=>jl(pe,l),[pe,l]),Ne=(0,$.useMemo)(()=>{if(!Me)return;let e=(Oe??[]).find(e=>e._packageId===Me);return e?je({name:e.name,label:mo(e.label,x)}):Me},[Me,Oe,je,x]),Pe=(0,$.useMemo)(()=>{if(!l)return;let e=(Oe??[]).find(e=>e._packageId===l);return e?je({name:e.name,label:mo(e.label,x)}):void 0},[l,Oe,je,x]),Fe=Te&&!!l,Ie=(0,$.useMemo)(()=>{if(!(ne.length>0))return au(r,z,x,Fe)},[ne.length,r,z,x,Fe]),Le=(0,$.useMemo)(()=>Ll(x,r,Fe?{appLabel:Pe}:void 0),[x,r,Fe,Pe]);(0,$.useEffect)(()=>{!Te||!d||!Me||l||me||u?.(Me)},[Te,d,Me,l,me,u]);let W=(0,$.useMemo)(()=>{let e=new Map;for(let t of Oe??[]){let n=t._packageId;!n||e.has(n)||Nl(t)||e.set(n,je({name:t.name,label:mo(t.label,x)}))}return Array.from(e,([e,t])=>({id:e,label:t}))},[Oe,je,x]),Re=(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.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[C?e.length<=3?(0,Q.jsx)(xn,{value:r,onValueChange:e=>S(`/ai/${ta(e)}`),children:(0,Q.jsx)(Dt,{className:`h-7 gap-0.5 p-0.5`,"data-testid":`ai-chat-agent-picker`,"aria-label":x(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:e.map(e=>(0,Q.jsx)(De,{value:e.name,disabled:t,title:e.description||void 0,className:`h-6 px-2.5 text-xs`,children:Il(x,e.name,e.label)},e.name))})}):(0,Q.jsxs)(Bn,{value:r,onValueChange:e=>S(`/ai/${ta(e)}`),disabled:t,children:[(0,Q.jsx)(yr,{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":x(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:(0,Q.jsx)(wn,{placeholder:x(`console.ai.chooseAgent`,{defaultValue:`Choose assistant…`})})}),(0,Q.jsx)(hn,{align:`start`,children:e.map(e=>(0,Q.jsxs)(lr,{value:e.name,className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:Il(x,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:z}),Te?(0,Q.jsxs)(Mr,{children:[(0,Q.jsxs)(ot,{"data-testid":`ai-build-package-chip`,title:Me,"aria-label":x(`console.ai.switchApp`,{defaultValue:`Switch app`}),className:q(`inline-flex min-w-0 items-center gap-1 rounded-md border px-2 py-0.5 text-xs hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border/80`,Me?`bg-muted/40 text-foreground/80`:`border-dashed text-muted-foreground`),children:[Me?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(qn,{className:`size-3 shrink-0`}),(0,Q.jsx)(`span`,{className:`max-w-[10rem] truncate`,children:Ne})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(ke,{className:`size-3 shrink-0`}),x(`console.ai.newApp`,{defaultValue:`New app`})]}),(0,Q.jsx)(on,{className:`size-3 shrink-0 opacity-60`})]}),(0,Q.jsxs)(At,{align:`start`,className:`max-h-72 w-56 overflow-y-auto`,children:[(0,Q.jsx)(lt,{className:`text-xs text-muted-foreground`,children:x(`console.ai.switchAppLabel`,{defaultValue:`Build conversations by app`})}),W.map(e=>(0,Q.jsxs)(Ae,{"data-testid":`ai-build-package-option-${e.id}`,className:`text-xs`,onSelect:()=>{e.id!==Me&&S(`/ai/build?package=${encodeURIComponent(e.id)}`)},children:[(0,Q.jsx)(qn,{className:`size-3 shrink-0`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),e.id===Me?(0,Q.jsx)(bt,{className:`size-3 shrink-0`}):null]},e.id)),W.length>0?(0,Q.jsx)(Xn,{}):null,(0,Q.jsxs)(Ae,{"data-testid":`ai-build-package-option-new`,className:`text-xs`,onSelect:()=>S(`/ai/build?new=1`),children:[(0,Q.jsx)(ke,{className:`size-3 shrink-0`}),x(`console.ai.newApp`,{defaultValue:`New app`})]})]})]}):null]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[y&&v?(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:v,disabled:!c,"aria-label":`Build Doctor`,"data-testid":`ai-chat-debug-button`,title:c?`Build Doctor — what actually landed?`:`Send a message first`,children:(0,Q.jsx)(En,{className:`h-3.5 w-3.5`})}):null,(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:_,disabled:!c,"aria-label":x(`console.ai.share`),"data-testid":`ai-chat-share-button`,title:x(c?`console.ai.shareTitle`:`console.ai.shareDisabledTitle`),children:(0,Q.jsx)(et,{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:x(`console.ai.offlineDemoMode`)}):null]}),ze=T!==null&&!k;return(0,Q.jsxs)(`div`,{ref:te.containerRef,className:`relative flex min-h-0 flex-1 px-0`,children:[P&&N?(0,Q.jsx)(`div`,{className:`pointer-events-none absolute top-2 left-0 right-0 z-20 flex justify-center px-4`,children:(0,Q.jsx)(`div`,{className:`pointer-events-auto w-full max-w-3xl`,children:(0,Q.jsx)(Rs,{file:P,dataSource:N,defaultObjectName:T?.name,onDone:()=>ee(null)})})}):null,(0,Q.jsx)(`div`,{"data-chat-column":!0,className:ze?`flex min-h-0 shrink-0 justify-center`:`flex min-h-0 flex-1 justify-center`,style:ze?{width:te.width}:void 0,children:(0,Q.jsx)(ra,{className:`min-h-0 flex-1 bg-background md:max-w-5xl`,onUpgrade:()=>window.open(Ua(),`_blank`,`noopener,noreferrer`),onOpenBuilder:w,surface:`plain`,maxHeight:`100%`,headerSlot:Re,messages:pe,placeholder:r?ta(r)===`ask`?x(`console.ai.askAnything`):x(`console.ai.askAgent`,{agent:z}):x(t?`console.ai.loadingAgents`:`console.ai.askAnything`),labels:{emptyTitle:Le.title,emptyDescription:Le.description,clear:x(`console.ai.clearConversation`),sendHint:x(`console.ai.sendHint`),agentActivity:x(`console.ai.agentActivity`),toolCompleted:x(`console.ai.toolCompleted`),toolRunning:x(`console.ai.toolRunning`),toolAwaitingApproval:x(`console.ai.toolAwaitingApproval`),toolFailed:x(`console.ai.toolFailed`),connectionWaiting:x(`console.ai.connectionWaiting`,{defaultValue:`Waiting for server…`}),connectionStalledLabel:x(`console.ai.connectionStalled`,{defaultValue:`Still working…`}),connectionOfflineLabel:x(`console.ai.connectionOffline`,{defaultValue:`Connection lost — reconnecting…`}),designingPlanLabel:x(`console.ai.designingPlan`,{defaultValue:`Designing your app…`}),designingPlanHints:[x(`console.ai.designingPlanHint.data`,{defaultValue:`Mapping out the data you’ll track…`}),x(`console.ai.designingPlanHint.objects`,{defaultValue:`Shaping objects and their fields…`}),x(`console.ai.designingPlanHint.relations`,{defaultValue:`Connecting related records…`}),x(`console.ai.designingPlanHint.lookups`,{defaultValue:`Setting up relationships and lookups…`}),x(`console.ai.designingPlanHint.views`,{defaultValue:`Planning the screens and views…`}),x(`console.ai.designingPlanHint.forms`,{defaultValue:`Laying out forms and lists…`}),x(`console.ai.designingPlanHint.defaults`,{defaultValue:`Adding sensible defaults and validations…`}),x(`console.ai.designingPlanHint.dashboard`,{defaultValue:`Sketching a dashboard to track it…`}),x(`console.ai.designingPlanHint.review`,{defaultValue:`Double-checking the structure hangs together…`}),x(`console.ai.designingPlanHint.finalize`,{defaultValue:`Pulling the plan together…`})],toolDetailsHidden:x(`console.ai.toolDetailsHidden`),copy:x(`console.ai.copy`),copied:x(`console.ai.copied`),regenerate:x(`console.ai.regenerate`),model:x(`console.ai.model`),submit:x(`console.ai.submit`),uploadFiles:x(`console.ai.uploadFiles`),stopResponse:x(`console.ai.stopResponse`),sendFailedRateLimited:x(`console.ai.sendFailedRateLimited`,{defaultValue:`You're sending messages too quickly. Your message is kept below — wait a moment and try again.`}),sendFailedGeneric:x(`console.ai.sendFailedGeneric`,{defaultValue:`Couldn't send your message. It's kept below — please try again.`}),trace:x(`console.ai.trace`),viewTrace:x(`console.ai.viewTrace`)},models:ce,selectedModelId:fe,onModelChange:de,suggestions:Ie,onSendMessage:U,onClear:ve,hideClearBar:!0,onStop:me?ge:void 0,onReload:_e,isLoading:me,error:re?void 0:B,enableMarkdown:!0,onToolApprove:H.decide,toolDecisions:H.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onOpenBuiltApp:(e,t)=>S(`/apps/${encodeURIComponent(t??e)}`),openBuiltAppLabel:x(`console.ai.openBuiltApp`,{defaultValue:`Open app`}),onDesignBuiltApp:(e,t)=>{let n=t??T?.segment;n&&S(`/studio/${encodeURIComponent(n)}/interfaces`)},designBuiltAppLabel:x(`console.ai.designBuiltApp`,{defaultValue:`Design in Studio`}),getArtifactAction:(e,t)=>{let n=yl(t??T?.segment,e);return n?()=>S(n):null},fetchPendingDraftCount:Oc,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){let e=n?.data?.failed??n?.failed??[];throw Error(e.length>0?Ps(e):String(r))}let i=n?.data?.seedApplied??n?.seedApplied;return i&&i.success===!1?X.warning(x(`console.ai.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:i.error??(Array.isArray(i.errors)&&i.errors.length?String(i.errors[0]):void 0)}):X.success(x(`console.ai.publishOk`,{defaultValue:`Published — objects are now live.`})),oi(),{ok:!0,health:$i(n)}}catch(e){return X.error(x(`console.ai.publishFailed`,{defaultValue:`Publish failed`}),{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:x(`console.ai.publishDrafts`,{defaultValue:`Publish`}),publishedLabel:x(`console.ai.published`,{defaultValue:`Published`}),nextStepsLabel:x(`console.ai.nextSteps`,{defaultValue:`What's next`}),planTitleLabel:x(`console.ai.planTitle`,{defaultValue:`Proposed plan`}),planQuestionsLabel:x(`console.ai.planQuestions`,{defaultValue:`Confirm before building`}),planAssumptionsLabel:x(`console.ai.planAssumptions`,{defaultValue:`Assumptions`}),planDeferredLabel:x(`console.ai.planDeferred`,{defaultValue:`Not yet built`}),planApproveHintLabel:x(`console.ai.planApproveHint`,{defaultValue:`Reply to approve or adjust this plan.`}),planApproveLabel:x(`console.ai.planApprove`,{defaultValue:`Build it`}),planAdjustLabel:x(`console.ai.planAdjust`,{defaultValue:`Adjust`}),planBuiltLabel:x(`console.ai.planBuilt`,{defaultValue:`Built`}),planBuildingLabel:be?`正在搭建…`:x(`console.ai.planBuilding`,{defaultValue:`Building…`}),planReadyLabel:x(`console.ai.planReady`,{defaultValue:`The plan is ready. Build it now, or tell me what to adjust.`}),planApproveMessage:xe,planApproveDefaultsMessage:V,changesTitleLabel:x(`console.ai.changesTitle`,{defaultValue:`Confirm changes`}),changesConfirmedLabel:x(`console.ai.changesConfirmed`,{defaultValue:`Confirmed`}),changesConfirmLabel:x(`console.ai.changesConfirm`,{defaultValue:`Confirm`}),changesConfirmHintLabel:x(`console.ai.changesConfirmHint`,{defaultValue:`Reply to confirm or adjust this change.`}),changesConfirmMessage:Se,changeVerbLabels:Ce,planAnswerMessage:(e,t)=>x(`console.ai.planAnswerMessage`,{question:e,option:t,defaultValue:`For "{{question}}", go with: {{option}}.`}),autoPublishDrafts:Va().features.autoPublishAiBuilds,onDraftArtifacts:L,onPreviewDraftApp:(e,t)=>{E({name:e,segment:t?.appSegment,materialized:t?.materialized===!0}),k&&M(!0)},onBuildMaterialized:R,previewDraftLabel:x(`console.ai.previewDraft`,{defaultValue:`Preview`}),"data-testid":`ai-chat-panel`})}),ze?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":x(`console.ai.resizeSplit`,{defaultValue:`Resize chat and preview`}),tabIndex:0,onPointerDown:te.onHandlePointerDown,onKeyDown:te.onHandleKeyDown,onDoubleClick:te.reset,"data-testid":`ai-chat-split-handle`,className:q(`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:q(`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`,te.dragging&&`bg-primary`)})]}),(0,Q.jsx)(_l,{appName:T.name,appSegment:T.segment,materialized:T.materialized,refreshKey:D,onClose:()=>E(null)}),te.dragging?(0,Q.jsx)(`div`,{className:`fixed inset-0 z-50 cursor-col-resize`,"data-testid":`ai-chat-split-overlay`}):null]}):null,T&&k?(0,Q.jsx)(Q.Fragment,{children:A?(0,Q.jsx)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-background`,"data-testid":`ai-chat-mobile-canvas`,children:(0,Q.jsx)(_l,{appName:T.name,appSegment:T.segment,materialized:T.materialized,refreshKey:D,onClose:()=>M(!1)})}):(0,Q.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-24 z-20 flex justify-center px-4`,children:(0,Q.jsxs)(J,{size:`sm`,onClick:()=>M(!0),"data-testid":`ai-chat-mobile-preview-open`,className:`pointer-events-auto gap-1.5 rounded-full shadow-lg`,children:[(0,Q.jsx)(Hn,{className:`h-4 w-4`}),x(`console.ai.previewApp`,{defaultValue:`Preview app`})]})})}):null]})}function tu(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 nu(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 ru(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 iu(e){return[e(`console.ai.suggestions.editApp.addField`,{defaultValue:`Add a field to one of the objects.`}),e(`console.ai.suggestions.editApp.addObject`,{defaultValue:`Add a new object and relate it to an existing one.`}),e(`console.ai.suggestions.editApp.addDashboard`,{defaultValue:`Add a dashboard for the key metrics.`}),e(`console.ai.suggestions.editApp.addAutomation`,{defaultValue:`Add an automation — an approval, a status flow, or a notification.`})]}function au(e,t,n,r=!1){if(Qi(e))return tu(n);if(Zi(e))return r?iu(n):nu(n);let i=(e??t).toLowerCase();return i.includes(`data`)?tu(n):i.includes(`metadata`)?nu(n):ru(n)}function ou(e){return!!e&&typeof e==`object`&&`fraction`in e}function su(e){let t=e?.meters;return!t||!ou(t.build)||!ou(t.dataChat)?null:{meters:{build:t.build,dataChat:t.dataChat}}}function cu(e={}){let{apiBase:t,enabled:n=!0}=e,[r,i]=$.useState(null),[a,o]=$.useState(!1),[s,c]=$.useState(void 0),[l,u]=$.useState(0),d=$.useCallback(()=>u(e=>e+1),[]),f=n&&!!t;return $.useEffect(()=>{if(!f){i(null),c(void 0),o(!1);return}if(typeof fetch!=`function`)return;let e=!1,n=`${t.replace(/\/$/,``)}/usage`;return o(!0),fetch(n,{method:`GET`,headers:{Accept:`application/json`},credentials:`include`}).then(async e=>{if(!e.ok)throw Error(`Failed to load AI usage (${e.status})`);return e.json()}).then(t=>{e||(i(su(t)),c(void 0))}).catch(t=>{e||(i(null),c(t instanceof Error?t:Error(String(t))))}).finally(()=>{e||o(!1)}),()=>{e=!0}},[f,t,l]),$.useEffect(()=>{if(!f||typeof window>`u`)return;let e=()=>d(),t=()=>{document.visibilityState===`visible`&&d()};return window.addEventListener(la,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(la,e),document.removeEventListener(`visibilitychange`,t)}},[f,d]),{usage:r,loading:a,error:s,refetch:d}}function lu(e){return e>=1?`full`:e>=.8?`low`:`ok`}function uu(e){return e===`full`?`text-destructive`:e===`low`?`text-amber-500`:`text-primary`}function du({fraction:e,tone:t,size:n=16}){let r=(n-2)/2,i=2*Math.PI*r,a=i*Math.min(1,Math.max(0,e)),o=n/2;return(0,Q.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 ${n} ${n}`,className:uu(t),"aria-hidden":`true`,focusable:`false`,children:[(0,Q.jsx)(`circle`,{cx:o,cy:o,r,fill:`none`,strokeWidth:2,className:`stroke-muted-foreground/25`}),(0,Q.jsx)(`circle`,{cx:o,cy:o,r,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeDasharray:`${a} ${i}`,transform:`rotate(-90 ${o} ${o})`})]})}function fu({apiBase:e,enabled:t=!0,className:n}){let{t:r}=G(),{usage:i}=cu({apiBase:e,enabled:t}),a=$.useMemo(()=>{if(!i)return[];let e=[];return[`build`,`dataChat`].forEach(t=>{let n=i.meters[t];if(!n||n.unmetered||n.fraction==null)return;let r=n.fraction;e.push({key:t,meter:n,fraction:r,tone:lu(r)})}),e},[i]);if(!t||a.length===0)return null;let o=e=>e===`build`?r(`console.ai.usage.meterBuild`,{defaultValue:`Build`}):r(`console.ai.usage.meterAsk`,{defaultValue:`Ask`}),s=e=>e===`full`?r(`console.ai.usage.statusFull`,{defaultValue:`Limit reached`}):e===`low`?r(`console.ai.usage.statusLow`,{defaultValue:`Running low`}):r(`console.ai.usage.statusOk`,{defaultValue:`Plenty left`}),c=e=>e.resetKind===`daily`?r(`console.ai.usage.resetsDaily`,{defaultValue:`Resets tonight`}):r(`console.ai.usage.resetsMonthly`,{defaultValue:`Resets next cycle`}),l=a.reduce((e,t)=>t.fraction>e.fraction?t:e),u=l.tone!==`ok`;return(0,Q.jsxs)(Fn,{children:[(0,Q.jsx)(Dr,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`sm`,"data-testid":`ai-usage-indicator`,className:q(`h-7 gap-1.5 px-1.5 text-muted-foreground hover:text-foreground`,n),"aria-label":r(`console.ai.usage.ariaLabel`,{defaultValue:`AI usage: {{status}}`,status:s(l.tone)}),children:[(0,Q.jsx)(`span`,{className:`flex items-center gap-1`,children:a.map(e=>(0,Q.jsx)(du,{fraction:e.fraction,tone:e.tone},e.key))}),u?(0,Q.jsx)(`span`,{className:q(`hidden text-xs font-medium sm:inline`,l.tone===`full`?`text-destructive`:`text-amber-600 dark:text-amber-500`),children:s(l.tone)}):null]})}),(0,Q.jsxs)(un,{align:`end`,className:`w-64 p-3`,"data-testid":`ai-usage-popover`,children:[(0,Q.jsx)(`div`,{className:`mb-2 text-xs font-semibold text-foreground/80`,children:r(`console.ai.usage.title`,{defaultValue:`AI usage`})}),(0,Q.jsx)(`ul`,{className:`space-y-3`,children:a.map(({key:e,meter:t,fraction:n,tone:i})=>{let a=i!==`ok`&&(t.upgrade||t.topUp);return(0,Q.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,Q.jsx)(du,{fraction:n,tone:i,size:22}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:o(e)}),(0,Q.jsx)(`span`,{className:q(`text-xs`,i===`full`?`text-destructive`:i===`low`?`text-amber-600 dark:text-amber-500`:`text-muted-foreground`),children:s(i)})]}),(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:c(t)}),a?(0,Q.jsx)(J,{variant:`link`,size:`sm`,className:`mt-1 h-auto p-0 text-xs`,"data-testid":`ai-usage-cta-${e}`,onClick:()=>window.open(Ua(),`_blank`,`noopener,noreferrer`),children:t.upgrade?r(`console.ai.usage.ctaUpgrade`,{defaultValue:`Upgrade to keep going`}):r(`console.ai.usage.ctaTopUp`,{defaultValue:`Add credits to continue`})}):null]})]},e)})})]})]})}function pu(e,t){return{name:e.name,label:e.label,pluralLabel:e.pluralLabel,description:e.description,icon:e.icon,group:e.group,sortOrder:e.sortOrder,fields:t,relationships:e.relationships}}function mu(e){return{name:e.name,label:e.label,type:e.type,group:e.group,description:e.description,required:e.required,unique:e.unique,readonly:e.readonly,hidden:e.hidden,defaultValue:e.defaultValue,placeholder:e.placeholder,options:e.options,externalId:e.externalId,trackHistory:e.trackHistory,indexed:e.indexed,referenceTo:e.referenceTo,formula:e.formula,sortOrder:e.sortOrder}}var hu=class{adapter;constructor(e){this.adapter=e}async getItems(e){let t=await this.adapter.getClient().meta.getItems(e);return t&&typeof t==`object`&&`items`in t&&Array.isArray(t.items)?t.items:[]}async saveMetadataItem(e,t,n){await this.adapter.getClient().meta.saveItem(e,t,n),this.adapter.invalidateCache(`${e}:${t}`)}async deleteMetadataItem(e,t){await this.adapter.getClient().meta.saveItem(e,t,{name:t,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`${e}:${t}`)}async saveObject(e,t){let n=this.adapter.getClient(),r=pu(e,t);await n.meta.saveItem(`object`,e.name,r),this.adapter.invalidateCache(`object:${e.name}`)}async deleteObject(e){await this.adapter.getClient().meta.saveItem(`object`,e,{name:e,enabled:!1,_deleted:!0}),this.adapter.invalidateCache(`object:${e}`)}async saveFields(e,t){let n=this.adapter.getClient(),r={};try{let t=await n.meta.getItem(`object`,e);r=t?.item??t??{}}catch{}let i={...r,name:e,fields:t.map(mu)};await n.meta.saveItem(`object`,e,i),this.adapter.invalidateCache(`object:${e}`)}static diffObjects(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,object:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,object:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,object:t}}return null}static diffFields(e,t){let n=new Map(e.map(e=>[e.id,e])),r=new Map(t.map(e=>[e.id,e]));for(let[e,t]of r)if(!n.has(e))return{type:`create`,field:t};for(let[e,t]of n)if(!r.has(e))return{type:`delete`,field:t};for(let[e,t]of r){let r=n.get(e);if(r&&JSON.stringify(r)!==JSON.stringify(t))return{type:`update`,field:t}}return null}};function gu(){let e=ie();return(0,$.useMemo)(()=>e?new hu(e):null,[e])}var _u=20;function vu(e,t=``){let{href:n,external:r}=Ka(e,t);return r?n:!n||n===`#`?``:n}function yu(e){return`nav:${e}`}function bu(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=Li(),a=(0,$.useCallback)((e,i,a,o)=>{let s=yu(e);i?(a&&t({id:s,label:a.label,href:vu(a,o??``),type:`nav`,navId:e,pinned:!0}),r(s,!0)):n(s)},[t,n,r]),o=(0,$.useCallback)(e=>i.has(e),[i]),s=(0,$.useCallback)(e=>{if(i.size===0){let t=!1;for(let n of e)if(n.pinned){t=!0;break}if(!t)return e}let t=0,n=e=>e.map(e=>{let r=i.has(e.id)&&t<_u;r&&t++;let a=e.children?.length?n(e.children):e.children;return r!==(e.pinned??!1)||a!==e.children?{...e,pinned:r,children:a}:e});return n(e)},[i]),c=(0,$.useCallback)(()=>{for(let t of e)t.type===`nav`&&n(t.id)},[e,n]);return{pinnedIds:(0,$.useMemo)(()=>Array.from(i),[i]),togglePin:a,isPinned:o,applyPins:s,clearPins:c}}var xu=0;function Su(e=`nav`){return`${e}_${Date.now()}_${++xu}`}function Cu(e,t){return[...e,t]}function wu(e,t,n){return e.filter(e=>!(e.type===t&&(t===`page`&&e.pageName===n||t===`dashboard`&&e.dashboardName===n))).map(e=>e.children&&e.children.length>0?{...e,children:wu(e.children,t,n)}:e)}function Tu(e,t,n,r){return e.map(e=>{let i=e;return t===`page`&&e.type===`page`&&e.pageName===n?i={...e,pageName:r}:t===`dashboard`&&e.type===`dashboard`&&e.dashboardName===n&&(i={...e,dashboardName:r}),i.children&&i.children.length>0?{...i,children:Tu(i.children,t,n,r)}:i})}function Eu(e,t){return e.length===t.length?e===t||JSON.stringify(e)===JSON.stringify(t):!1}function Du(e){return typeof e==`string`&&e.startsWith(`sys_`)}function Ou(e){if(!e||typeof e!=`object`)return!1;let t=e;return t._packageId!=null||t._provenance===`package`||Du(t.name)}function ku(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t._lock??t.protection?.lock;return n!==`full`&&n!==`no-overlay`}function Au(){let e=ie(),{apps:t,refresh:n}=j(),{t:r}=G(),i=(0,$.useRef)(e);i.current=e;let a=(0,$.useRef)(n);a.current=n;let o=(0,$.useCallback)(async(e,t)=>{let n=i.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await a.current?.()},[]),s=(0,$.useCallback)(e=>uo(t,e),[t]),c=(0,$.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Cu(a,{id:Su(`nav_page`),type:`page`,label:n||t,pageName:t,icon:`FileText`}),l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.addedPage`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),l=(0,$.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Cu(a,{id:Su(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),u=(0,$.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=wu(i,`page`,t);if(Eu(a,i))return;let c={...n,navigation:a};try{await o(e,c),X.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),d=(0,$.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=wu(i,`dashboard`,t);if(Eu(a,i))return;let c={...n,navigation:a};try{await o(e,c),X.success(r(`navigationSync.removedDashboard`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),f=(0,$.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Tu(a,`page`,t,n);if(Eu(c,a))return;let l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.renamedPage`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),p=(0,$.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Tu(a,`dashboard`,t,n);if(Eu(c,a))return;let l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.renamedDashboard`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),m=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return{syncPageCreated:c,syncDashboardCreated:l,syncPageDeleted:u,syncDashboardDeleted:d,syncPageRenamed:f,syncDashboardRenamed:p,syncPageCreatedAllApps:(0,$.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!ku(r)||await c(t,e,n)}},[t,c]),syncDashboardCreatedAllApps:(0,$.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!ku(r)||await l(t,e,n)}},[t,l]),syncPageDeletedAllApps:(0,$.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!ku(n)||await u(t,e)}},[t,u]),syncDashboardDeletedAllApps:(0,$.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!ku(n)||await d(t,e)}},[t,d]),syncPageRenamedAllApps:(0,$.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!ku(r)||await f(t,e,n)}},[t,f]),syncDashboardRenamedAllApps:(0,$.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!ku(r)||await p(t,e,n)}},[t,p])}}function ju(){let{pages:e,dashboards:t,apps:n,getTypeStatus:r}=j(),i=ie(),a=(0,$.useRef)(i);a.current=i;let o=ri(),{syncPageCreated:s,syncDashboardCreated:c,syncPageDeleted:l,syncDashboardDeleted:u}=Au(),d=(0,$.useRef)(null),f=(0,$.useRef)(null),p=(0,$.useRef)(0),m=(0,$.useRef)(!1),h=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,$.useEffect)(()=>{if(m.current)return;if(o){d.current=null,f.current=null;return}if(r&&(r(`page`)!==`ready`||r(`dashboard`)!==`ready`))return;let i=e=>new Set(e.filter(e=>!Ou(e)).map(e=>e?.name).filter(e=>typeof e==`string`&&e.length>0)),a=i(e??[]),g=i(t??[]),_=d.current,v=f.current;if(_===null||v===null){d.current=a,f.current=g;return}let y=[...a].filter(e=>!_.has(e)),b=[..._].filter(e=>!a.has(e)),x=[...g].filter(e=>!v.has(e)),S=[...v].filter(e=>!g.has(e));if(y.length===0&&b.length===0&&x.length===0&&S.length===0){d.current=a,f.current=g;return}let C=++p.current;m.current=!0;let w=!1;return(async()=>{try{for(let e of n){if(w||p.current!==C)break;let t=h(e);if(!(!t||!ku(e))){for(let e of y){if(w)break;await s(t,e)}for(let e of b){if(w)break;await l(t,e)}for(let e of x){if(w)break;await c(t,e)}for(let e of S){if(w)break;await u(t,e)}}}}finally{p.current===C&&(d.current=a,f.current=g,m.current=!1)}})(),()=>{w=!0}},[e,t,n,o,r,s,c,l,u]),null}var Mu=768,Nu=1024;function Pu(){let{setOpen:e,isMobile:t}=Be(),n=(0,$.useRef)(e);(0,$.useEffect)(()=>{n.current=e},[e]),(0,$.useEffect)(()=>{if(t)return;let e=!1;function r(){let t=window.innerWidth,r=t>=Mu&&t<Nu;r&&!e&&n.current(!1),e=r}return r(),window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r)},[t])}var Fu=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function Iu(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Lu(e){try{return decodeURIComponent(e)}catch{return e}}function Ru({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=vi(),o=(0,$.useRef)(n);o.current=n,(0,$.useEffect)(()=>{if(i||!t)return;let n=e.split(`/`).filter(Boolean);if(n[0]!==r||n[1]!==t)return;let s=n[2],c=n[3],l=`/${r}/${t}`;if(s===`metadata`){let e=n[3],t=n[4];e&&t&&t!==`new`&&a({id:`metadata:${e}:${Lu(t)}`,label:Lu(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!Fu.has(s)){let e=o.current.find(e=>e.name===s);e&&a({id:`object:${e.name}`,label:e.label||e.name,href:`${l}/${e.name}`,type:`object`});return}if(c)switch(s){case`dashboard`:a({id:`dashboard:${c}`,label:Iu(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:Iu(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:Iu(c),href:`${l}/report/${c}`,type:`report`});break;default:break}},[e,t,r,i])}var zu={"studio-build":`build`,default:`ask`};function Bu(e,{agents:t,appDefaultAgent:n,aiStudioEnabled:r=!0}){let i=t.map(e=>e.name),a=(qi(n)?n:void 0)??zu[e]??zu.default;return oa(!r&&Zi(a)?`ask`:a,i)??Yi(t)}function Vu(e){try{let t=window.localStorage.getItem(e),n=t?Number.parseInt(t,10):NaN;return Number.isFinite(n)&&n>0?n:420}catch{return 420}}function Hu(e){let{defaultExpanded:t=!1,persistExpandedKey:n,persistWidthKey:r=mc}=e??{},[i,a]=$.useState(()=>n?xc(n,t):t),[o,s]=$.useState(()=>Vu(r)),[c,l]=$.useState(!1),[u,d]=$.useState(!1),f=$.useRef(!1),p=$.useRef(null),m=$.useRef(o);m.current=o;let h=$.useCallback(e=>{a(t=>{let r=e(t);return n&&Sc(n,r),r})},[n]),g=$.useCallback(e=>{e.preventDefault(),f.current=!1,p.current=null,d(!1);let t=e.clientX,n=o;l(!0);let i=e=>{let r=vc(n+(t-e.clientX),window.innerWidth);s(r)},a=e=>{let o=vc(n+(t-e.clientX),window.innerWidth);try{window.localStorage.setItem(r,String(Math.round(o)))}catch{}l(!1),window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a)},[o]),_=$.useCallback(()=>{f.current||(f.current=!0,p.current=m.current,s(yc(window.innerWidth)),d(!0))},[]),v=$.useCallback(()=>{f.current&&(f.current=!1,s(p.current??Vu(r)),p.current=null,d(!1))},[r]);return{expanded:i,width:o,dragging:c,maximized:u,toggle:$.useCallback(()=>h(e=>!e),[h]),expand:$.useCallback(()=>h(()=>!0),[h]),collapse:$.useCallback(()=>h(()=>!1),[h]),maximize:_,restore:v,onResizePointerDown:g}}function Uu({userId:e,apiBase:t,defaultAgent:n,onCanvasOpenChange:r}){let{agents:i,isLoading:a,error:o}=Xi({apiBase:t}),s=$.useMemo(()=>Bu(`default`,{agents:i,appDefaultAgent:n,aiStudioEnabled:Va().features.aiStudio!==!1}),[i,n]),c=s?`${t}/agents/${encodeURIComponent(s)}/chat`:void 0,l=s?$c({appId:void 0,product:Qc(s)}):void 0,{conversationId:u,initialMessages:d}=Yc({userId:s?e:void 0,scope:l,apiBase:t,activeId:void 0,forceNew:!1}),f=$.useRef(null);return!a&&i.length===0?null:(0,Q.jsx)(eu,{agents:i,agentsLoading:a,agentsError:o,activeAgent:s,chatApi:c,apiBase:t,conversationId:u,initialMessages:d,pendingFirstMessageRef:f,onSent:()=>{},onShare:()=>{},showDebug:!1,onCanvasOpenChange:r},`${c??`local`}:${u??`pending`}`)}function Wu({dock:e,userId:t,apiBase:n,defaultAgent:r,title:i,onMaximize:a,children:o}){let{t:s}=G(),c=$.useMemo(()=>Rl(n),[n]),l=$.useCallback(t=>t?e.maximize():e.restore(),[e.maximize,e.restore]);return(0,Q.jsxs)(`aside`,{"data-testid":`chat-dock-panel`,style:{width:e.width},className:q(`relative hidden h-full shrink-0 flex-col border-l bg-background md:flex`,!e.dragging&&`transition-[width] duration-200 ease-out`),children:[(0,Q.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":s(`console.ai.dock.resize`,{defaultValue:`Resize chat`}),onPointerDown:e.onResizePointerDown,className:q(`absolute left-0 top-0 z-10 h-full w-1 cursor-col-resize transition-colors hover:bg-primary/40`,e.dragging&&`bg-primary/50`)}),(0,Q.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center justify-between border-b px-3`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-semibold text-foreground/80`,children:[(0,Q.jsx)(V,{className:`size-3.5`}),i??s(`console.ai.dock.title`,{defaultValue:`Assistant`})]}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,Q.jsx)(fu,{apiBase:c}),a?(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:a,"aria-label":s(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),title:s(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),"data-testid":`chat-dock-maximize`,children:(0,Q.jsx)(ze,{className:`h-3.5 w-3.5`})}):null,(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:e.collapse,"aria-label":s(`console.ai.dock.collapse`,{defaultValue:`Collapse chat`}),"data-testid":`chat-dock-collapse`,children:(0,Q.jsx)(Tt,{className:`h-4 w-4`})})]})]}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:o??(0,Q.jsx)(Uu,{userId:t,apiBase:c,defaultAgent:r,onCanvasOpenChange:l})})]})}function Gu({open:e,onOpenChange:t,userId:n,apiBase:r,defaultAgent:i,title:a,onMaximize:o,children:s}){let{t:c}=G(),l=$.useMemo(()=>Rl(r),[r]),u=$.useRef(!1);return $.useEffect(()=>{!e&&u.current&&(u.current=!1,o?.())},[e,o]),(0,Q.jsx)(xt,{open:e,onOpenChange:t,children:(0,Q.jsxs)(ve,{side:`bottom`,className:`flex h-[85svh] flex-col gap-0 p-0 md:hidden`,"data-testid":`chat-dock-mobile-sheet`,children:[(0,Q.jsxs)(Sr,{className:`shrink-0 border-b px-4 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 pr-8`,children:[(0,Q.jsxs)(ir,{className:`inline-flex items-center gap-1.5 text-sm font-semibold`,children:[(0,Q.jsx)(V,{className:`size-4`}),a??c(`console.ai.dock.title`,{defaultValue:`Assistant`})]}),(0,Q.jsx)(fu,{apiBase:l}),o?(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-9 w-9 text-muted-foreground hover:text-foreground`,onClick:()=>{u.current=!0,t(!1)},"aria-label":c(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),"data-testid":`chat-dock-mobile-maximize`,children:(0,Q.jsx)(ze,{className:`h-4 w-4`})}):null]}),(0,Q.jsx)(An,{className:`sr-only`,children:c(`console.ai.dock.description`,{defaultValue:`AI assistant chat`})})]}),(0,Q.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:s??(0,Q.jsx)(Uu,{userId:n,apiBase:l,defaultAgent:i})})]})})}function Ku({onExpand:e,className:t}){let{t:n}=G();return(0,Q.jsx)(J,{variant:`outline`,size:`icon`,onClick:e,"data-testid":`chat-dock-launcher`,"aria-label":n(`console.ai.dock.open`,{defaultValue:`Open assistant`}),title:n(`console.ai.dock.open`,{defaultValue:`Open assistant (⌘⇧I)`}),className:q(`fixed right-0 top-1/2 z-40 hidden h-16 w-7 -translate-y-1/2 rounded-l-md rounded-r-none border-r-0 bg-background shadow-md md:inline-flex`,t),children:(0,Q.jsx)(V,{className:`size-4`})})}var qu=new Set([`object`,`app`,`action`]);async function Ju(){try{let e=await o(()=>import(`./vendor-objectstack-Bs6C4qGH.js`).then(e=>e.a),[],import.meta.url);return typeof e?.validateCapabilityReferences==`function`?e.validateCapabilityReferences:null}catch{return null}}async function Yu(e,t,n){try{let r=n===void 0?await Ju():n;if(!r)return[];let i=t.filter(e=>qu.has(e.type));if(i.length===0)return[];let a=e=>{let t=e?.item??e;return t&&typeof t==`object`?t:null},o=await Promise.all(i.map(t=>e.getDraft?.(t.type,t.name,t.packageId?{packageId:t.packageId}:void 0).then(a).catch(()=>null)??Promise.resolve(null))),s=await(e.list?.(`permission`,{}))?.then(e=>Array.isArray(e)?e.map(a).filter(Boolean):[]).catch(()=>[])??[],c=await Promise.all(t.filter(e=>e.type===`permission`).map(t=>e.getDraft?.(t.type,t.name,t.packageId?{packageId:t.packageId}:void 0).then(a).catch(()=>null)??Promise.resolve(null)));return r({objects:o.filter((e,t)=>e&&i[t].type===`object`),apps:o.filter((e,t)=>e&&i[t].type===`app`),actions:o.filter((e,t)=>e&&i[t].type===`action`),permissions:[...s,...c.filter(Boolean)]}).filter(e=>e&&e.severity===`warning`).map(e=>`${e.where}: ${e.message}`)}catch{return[]}}function Xu(e){let t=So(),[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 X.info(e(`home.pendingDrafts.nothing`,{defaultValue:`Nothing to publish.`})),{ok:!0,attempted:0};let r=await Yu(t,n),i=[...new Set(n.map(e=>e.packageId).filter(e=>e!==null))],a=n.filter(e=>e.packageId===null),o=[],s=[],c=0,l=e=>{if(e){e.seedError&&o.push(e.seedError),typeof e.seededRows==`number`&&(c+=e.seededRows);for(let t of e.issues??[])t.severity===`error`&&s.push(t.message)}};for(let e of i){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}`);l($i(n))}let u=[...a.filter(e=>e.type!==`seed`),...a.filter(e=>e.type===`seed`)];for(let e of u){let n=(await t.publishDraft(e.type,e.name))?.seedApplied;n&&n.success===!1&&o.push(n.error??`${e.name}: sample data failed to load`)}return s.length>0?X.warning(e(`home.pendingDrafts.probeWarn`,{defaultValue:`Published, but verification found problems.`}),{description:s[0]}):o.length>0?X.warning(e(`home.pendingDrafts.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:o[0]}):X.success(c>0?e(`home.pendingDrafts.publishedVerified`,{count:c,defaultValue:`Published & verified — {{count}} sample row(s) live.`}):e(`home.pendingDrafts.published`,{defaultValue:`Published! Your changes are live.`})),r.length>0&&X.warning(e(`home.pendingDrafts.capabilityWarn`,{count:r.length,defaultValue:`Authoring check: {{count}} capability reference(s) resolve nowhere.`}),{description:r[0],duration:1e4}),{ok:!0,attempted:n.length}}catch(t){return X.error(`${e(`home.pendingDrafts.publishFailed`,{defaultValue:`Publish failed`})}: ${t.message}`),{ok:!1,attempted:0}}finally{r(!1)}},[t,e]),publishing:n}}async function Zu(e){let t=e?`?packageId=${encodeURIComponent(e)}`:``,n=await fetch(`/api/v1/meta/_drafts${t}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!n.ok)throw Error(`_drafts HTTP ${n.status}`);let r=await n.json();return(Array.isArray(r)?r:r?.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 Qu(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 $u(e){if(!e||typeof e!=`object`)return null;let t=e;return t.item&&typeof t.item==`object`?t.item:t}async function ed(e,t,n={}){let r=[];n.draft&&r.push(`state=draft`),n.packageId&&r.push(`package=${encodeURIComponent(n.packageId)}`);let i=r.length?`?${r.join(`&`)}`:``,a=await fetch(`/api/v1/meta/${encodeURIComponent(e)}/${encodeURIComponent(t)}${i}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(a.status===404)return null;if(!a.ok)throw Error(`HTTP ${a.status}`);return $u(await a.json())}function td(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}function nd(e,t){let n=e??{},r=t??{},i=null;if(n.fields!=null||r.fields!=null){let e=Mo(n.fields,r.fields);i={added:Object.values(e.byName).filter(e=>e.status===`added`).map(e=>e.name).sort(),changed:Object.values(e.byName).filter(e=>e.status===`changed`).map(e=>({name:e.name,keys:e.changedKeys})).sort((e,t)=>e.name.localeCompare(t.name)),removed:e.removed.map(e=>e.name).sort()}}let a=new Set([...Object.keys(n),...Object.keys(r)]);a.delete(`fields`);let o=[...a].filter(e=>!td(n[e],r[e])).sort();return{fields:i,changedKeys:o}}function rd({entry:e}){let{t}=G(),[n,r]=(0,$.useState)(null),[i,a]=(0,$.useState)(null);if((0,$.useEffect)(()=>{let t=!1;return(async()=>{try{let[n,i]=await Promise.all([ed(e.type,e.name,{packageId:e.packageId}),ed(e.type,e.name,{draft:!0,packageId:e.packageId})]);t||r(nd(n,i))}catch(e){t||a(e.message)}})(),()=>{t=!0}},[e.type,e.name,e.packageId]),i)return(0,Q.jsxs)(`p`,{className:`px-2 py-1 text-xs text-destructive`,children:[t(`preview.changes.detailLoadFailed`,{defaultValue:`Could not load change detail:`}),` `,i]});if(!n)return(0,Q.jsxs)(`p`,{className:`flex items-center gap-1.5 px-2 py-1 text-xs text-muted-foreground`,children:[(0,Q.jsx)(Y,{className:`h-3 w-3 animate-spin`}),t(`preview.changes.detailLoading`,{defaultValue:`Loading detail…`})]});let{fields:o,changedKeys:s}=n;return!(o&&(o.added.length>0||o.changed.length>0||o.removed.length>0))&&s.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-1 text-xs text-muted-foreground`,children:t(`preview.changes.detailNone`,{defaultValue:`No differences detected — the draft matches the published version.`})}):(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 px-2 py-1`,"data-testid":`draft-entry-detail`,children:[o?.added.map(e=>(0,Q.jsxs)(`p`,{className:`font-mono text-xs text-emerald-700 dark:text-emerald-400`,children:[`+ `,e]},`+${e}`)),o?.changed.map(e=>(0,Q.jsxs)(`p`,{className:`font-mono text-xs text-amber-700 dark:text-amber-400`,children:[`~ `,e.name,e.keys.length>0&&(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.keys.join(`, `)]})]},`~${e.name}`)),o?.removed.map(e=>(0,Q.jsxs)(`p`,{className:`font-mono text-xs text-red-700 line-through dark:text-red-400`,children:[`− `,e]},`-${e}`)),s.length>0&&(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[t(`preview.changes.detailChangedKeys`,{defaultValue:`Also changed:`}),` `,(0,Q.jsx)(`span`,{className:`font-mono`,children:s.join(`, `)})]})]})}function id({open:e,onOpenChange:t,packageId:n,onPublish:r,publishing:i=!1}){let{t:a}=G(),[o,s]=(0,$.useState)(null),[c,l]=(0,$.useState)(null),[u,d]=(0,$.useState)(new Set),f=(0,$.useCallback)(e=>{d(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),p=(0,$.useCallback)(async()=>{s(null),l(null);try{let e=await Zu(n);s(e);let t=[...new Set(e.map(e=>e.type))];await Promise.all(t.map(async e=>{let t=null;try{t=await Qu(e)}catch{return}s(n=>n&&n.map(n=>n.type===e?{...n,kind:t.has(n.name)?`update`:`new`}:n))}))}catch(e){l(e.message)}},[n]);(0,$.useEffect)(()=>{e&&p()},[e,p]);let m=new Map;for(let e of o??[]){let t=m.get(e.type)??[];t.push(e),m.set(e.type,t)}return(0,Q.jsx)(xt,{open:e,onOpenChange:t,children:(0,Q.jsxs)(ve,{side:`right`,className:`flex w-[420px] flex-col sm:max-w-[420px]`,"data-testid":`draft-changes-panel`,children:[(0,Q.jsxs)(Sr,{children:[(0,Q.jsx)(ir,{children:a(`preview.changes.title`,{defaultValue:`Pending changes`})}),(0,Q.jsx)(An,{children:a(`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 min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-4 pb-6`,children:c?(0,Q.jsxs)(`p`,{className:`text-sm text-destructive`,children:[a(`preview.changes.loadFailed`,{defaultValue:`Could not load pending changes:`}),` `,c]}):o===null?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`}),a(`preview.changes.loading`,{defaultValue:`Loading pending changes…`})]}):o.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:a(`preview.changes.empty`,{defaultValue:`Nothing pending — every draft has been published.`})}):[...m.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=>{let t=`${e.type}:${e.name}`,n=u.has(t);return(0,Q.jsxs)(`li`,{className:`rounded-md border text-sm`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>f(t),"aria-expanded":n,className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left hover:bg-muted/50`,"data-testid":`draft-entry-toggle`,children:[n?(0,Q.jsx)(on,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,Q.jsx)(nn,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),e.kind===`new`?(0,Q.jsx)(vt,{className:`h-3.5 w-3.5 shrink-0 text-emerald-600`}):e.kind===`update`?(0,Q.jsx)(he,{className:`h-3.5 w-3.5 shrink-0 text-amber-600`}):(0,Q.jsx)(Y,{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)(fn,{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`?a(`preview.changes.kindNew`,{defaultValue:`New`}):a(`preview.changes.kindUpdate`,{defaultValue:`Update`})}):null]}),n&&(0,Q.jsx)(`div`,{className:`border-t bg-muted/20`,children:(0,Q.jsx)(rd,{entry:e})})]},t)})})]},e))}),r&&(o?.length??0)>0&&!c&&(0,Q.jsxs)(`div`,{className:`mt-auto flex flex-col gap-2 border-t px-4 py-3`,children:[(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a(`preview.changes.confirmNote`,{count:o.length,defaultValue:`Publishing releases all {{count}} pending drafts of this package atomically.`})}),(0,Q.jsxs)(J,{size:`sm`,onClick:()=>void r(),disabled:i,"data-testid":`draft-changes-publish`,children:[i?(0,Q.jsx)(Y,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Jt,{className:`mr-1.5 h-3.5 w-3.5`}),a(`preview.changes.publishConfirm`,{defaultValue:`Publish all`})]})]})]})})}function ad(){let e=ri(),t=i(),n=a(),{t:r}=G(),{publishAll:o,publishing:s}=Xu(r),[c,l]=(0,$.useState)(!1),[u,d]=(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??[];d(Array.isArray(n)?n.length:null)}).catch(()=>{}),()=>{t=!0}},[e,t.pathname]),!e)return null;let f=()=>{ti();let e=new URLSearchParams(t.search);e.delete(ni);let r=e.toString();n(`${t.pathname}${r?`?${r}`:``}${t.hash}`,{replace:!0})},p=async()=>{(await o()).ok&&(f(),setTimeout(()=>{try{window.location.reload()}catch{}},300))},m=u===0;return(0,Q.jsxs)(`div`,{className:q(`sticky top-0 z-40 border-b`,m?`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)(Hn,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:m?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.`})}),!m&&(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>l(!0),"data-testid":`draft-preview-changes`,children:[(0,Q.jsx)(it,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.changes`,{defaultValue:`Changes`}),typeof u==`number`?` (${u})`:``]}),(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:f,"data-testid":`draft-preview-exit`,children:[(0,Q.jsx)(Se,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.exit`,{defaultValue:`Exit preview`})]})]}),!m&&(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)(ke,{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)(J,{onClick:p,disabled:s,"data-testid":`draft-preview-publish`,className:`shrink-0 shadow-sm`,children:[(0,Q.jsx)(Jt,{className:`mr-1.5 h-4 w-4`}),s?r(`preview.draftBar.publishing`,{defaultValue:`Publishing…`}):r(`preview.draftBar.publishCta`,{defaultValue:`Publish to see it live`})]})]}),(0,Q.jsx)(id,{open:c,onOpenChange:l})]})]})}async function od(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 sd(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 cd(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 ld({open:e,onOpenChange:t,packageId:n,onReverted:r}){let{t:i}=G(),[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 od(n))}catch(e){c(e.message)}},[n]);(0,$.useEffect)(()=>{e&&d()},[e,d]);let f=async e=>{u(e);try{await sd(n,e),X.success(i(`preview.history.reverted`,{defaultValue:`Reverted — the change has been undone.`})),r?.(),await d()}catch(e){X.error(`${i(`preview.history.revertFailed`,{defaultValue:`Revert failed`})}: ${e.message}`)}finally{u(null)}};return(0,Q.jsx)(xt,{open:e,onOpenChange:t,children:(0,Q.jsxs)(ve,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`commit-timeline-panel`,children:[(0,Q.jsxs)(Sr,{children:[(0,Q.jsx)(ir,{children:i(`preview.history.title`,{defaultValue:`Build history`})}),(0,Q.jsx)(An,{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)(Y,{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)(st,{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)(fn,{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:[`· `,cd(e.createdAt)]}):null]})]}),e.operation===`apply`?(0,Q.jsx)(J,{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)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(kn,{className:`mr-1 h-3.5 w-3.5`}),i(`preview.history.revertAction`,{defaultValue:`Revert`})]})}):null]},e.id))})]})})}function ud(){let e=ri(),{appName:t}=l(),n=i(),{apps:r,refresh:a}=j(),{t:o}=G(),[s,c]=(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=uo(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)(_n,{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)(J,{size:`sm`,variant:`outline`,onClick:()=>d(!0),"data-testid":`unpublished-app-history`,children:[(0,Q.jsx)(Te,{className:`mr-1 h-3.5 w-3.5`}),o(`preview.history.button`,{defaultValue:`History`})]}):null,(0,Q.jsxs)(J,{size:`sm`,onClick:async()=>{c(!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}`)}X.success(o(`preview.unpublishedBar.published`,{defaultValue:`Published! The app is now visible to your users.`})),a?.()}catch(e){X.error(`${o(`preview.unpublishedBar.publishFailed`,{defaultValue:`Publish failed`})}: ${e.message}`)}finally{c(!1)}},disabled:s,"data-testid":`unpublished-app-publish`,children:[(0,Q.jsx)(Jt,{className:`mr-1 h-3.5 w-3.5`}),s?o(`preview.unpublishedBar.publishing`,{defaultValue:`Publishing…`}):o(`preview.unpublishedBar.publish`,{defaultValue:`Publish`})]})]}),m?(0,Q.jsx)(ld,{open:u,onOpenChange:d,packageId:m,onReverted:a}):null]})}var dd=`__all__`;function fd(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function pd(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 md(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=fd(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 hd(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=pd(await e.json()),s=[],c=new Set;for(let e of t){if(!md(e,o))continue;let t=fd(e,i);if(t==null||typeof t!=`string`||c.has(t))continue;c.add(t);let n=fd(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 gd(e,t,n){let r=Array.isArray(t)?t:[],o=a(),s=i(),c=new URLSearchParams(s.search);$.useEffect(()=>{let t=new URLSearchParams(s.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&&o({pathname:s.pathname,search:t.toString()},{replace:!0})},[e,r,s.pathname,s.search,o]);let l=$.useCallback((t,n)=>{let r=n===dd?t.allValue??``:n;try{let n=`objectui-ctx-${e}-${t.id}`;r?sessionStorage.setItem(n,r):sessionStorage.removeItem(n)}catch{}let i=new URLSearchParams(s.search);r?i.set(`package`,r):i.delete(`package`),o({pathname:s.pathname,search:i.toString()},{replace:!0})},[e,s.pathname,s.search,o]),u={};for(let t of r){let n=``;try{n=sessionStorage.getItem(`objectui-ctx-${e}-${t.id}`)??``}catch{}u[t.id]=(c.get(`package`)??n)||(t.allValue??``)}return{contextValues:u,element:r.length===0?null:(0,Q.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(e=>(0,Q.jsx)(_d,{def:e,value:u[e.id],onChange:t=>l(e,t),t:n},e.id))})}}function _d({def:e,value:t,onChange:n,t:r}){let{options:i,refetch:a}=hd(e),o=yo(e.icon),s=mo(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)(Bn,{value:u?t:``,onValueChange:n,onOpenChange:e=>{e&&a()},children:[(0,Q.jsx)(yr,{"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)(wn,{placeholder:l,className:`truncate`})]})}),(0,Q.jsx)(hn,{className:`w-[var(--radix-select-trigger-width)]`,children:i.map(e=>(0,Q.jsx)(lr,{value:e.value,children:e.label},e.value))})]})}function vd(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 yd(e){return e.componentRef===`metadata:directory`}function bd(e){return e.componentRef===`developer:packages`}function xd(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 Sd({activeAppName:e}){let{isMobile:t,setOpenMobile:r}=Be(),a=i(),{t:o}=G(),{objectLabel:s,dashboardLabel:c,navGroupLabel:l,viewLabel:u}=Nt(),{context:d,currentAppName:f}=xi(),{user:p,activeOrganization:m}=T(),h=g();$.useEffect(()=>{let e=0,n=t=>{e=t.touches[0].clientX},i=n=>{let i=n.changedTouches[0].clientX-e;e<30&&i>50&&t&&r(!0)};return document.addEventListener(`touchstart`,n,{passive:!0}),document.addEventListener(`touchend`,i,{passive:!0}),()=>{document.removeEventListener(`touchstart`,n),document.removeEventListener(`touchend`,i)}},[t,r]);let{recentItems:_}=vi(),{favorites:v,removeFavorite:y}=Li(),{apps:b,objects:S}=j(),C=b||[],w=C.filter(e=>e.active!==!1&&e.hidden!==!0),E=uo(C.filter(e=>e.active!==!1),e||f)||w[0],{applyOrder:D,handleReorder:O}=vd(E?.name||`home`),{togglePin:k,applyPins:A}=bu(),M=E?.areas||[],[N,P]=$.useState(()=>M.length>0?M[0].id:null);$.useEffect(()=>{M.length>0?P(e=>M.some(t=>t.id===e)?e:M[0].id):P(null)},[E?.name,M.length]);let ee=M.find(e=>e.id===N)?.navigation||E?.navigation||[],{contextValues:F,element:I}=gd(E?.name||`home`,E?.contextSelectors,o),te=$.useMemo(()=>{let e=[{id:`home-dashboard`,label:o(`home.nav`,{defaultValue:`Home`}),type:`url`,url:`/home`,icon:`home`},{id:`docs`,label:o(`layout.systemNav.documentation`,{defaultValue:`Documentation`}),type:`url`,url:`/docs`,icon:`book-open`}];if(h){let t=[{id:`sys-settings`,label:o(`layout.systemNav.systemSettings`,{defaultValue:`System Settings`}),type:`url`,url:`/apps/setup`,icon:`settings`},{id:`sys-apps`,label:o(`layout.systemNav.applications`,{defaultValue:`Applications`}),type:`url`,url:`/apps/setup/system/apps`,icon:`layout-grid`},{id:`sys-marketplace`,label:o(`layout.systemNav.appMarketplace`,{defaultValue:`App Marketplace`}),type:`url`,url:`/apps/setup/system/marketplace`,icon:`store`},{id:`sys-objects`,label:o(`layout.systemNav.objectManager`,{defaultValue:`Object Manager`}),type:`url`,url:`/apps/setup/system/metadata/object`,icon:`database`},{id:`sys-datasources`,label:o(`layout.systemNav.datasources`,{defaultValue:`Datasources`}),type:`url`,url:`/apps/setup/component/metadata/resource?type=datasource`,icon:`database`},{id:`sys-users`,label:o(`layout.systemNav.users`,{defaultValue:`Users`}),type:`url`,url:`/apps/setup/system/users`,icon:`users`},{id:`sys-orgs`,label:o(`layout.systemNav.organizations`,{defaultValue:`Organizations`}),type:`url`,url:`/apps/setup/system/organizations`,icon:`building-2`},{id:`sys-roles`,label:o(`layout.systemNav.roles`,{defaultValue:`Roles`}),type:`url`,url:`/apps/setup/system/roles`,icon:`shield`},{id:`sys-config`,label:o(`layout.systemNav.configuration`,{defaultValue:`Configuration`}),type:`url`,url:`/apps/setup/system/settings`,icon:`sliders-horizontal`}];e.push({id:`sys-administration`,label:o(`layout.systemNav.administration`,{defaultValue:`Administration`}),type:`group`,icon:`shield`,children:t})}return e},[o,h]),L=d===`home`?te:ee,R=d===`app`&&E?`/apps/${fo(E)}`:``,z=d===`app`&&E?.name===`studio`,ne=$.useMemo(()=>{if(!z)return``;let e=new URLSearchParams(a.search).get(`package`)||F.active_package;return e?`?package=${encodeURIComponent(e)}`:``},[F.active_package,z,a.search]),re=$.useMemo(()=>{if(d!==`app`||E?.name!==`studio`)return L;let e=o(`sidebar.packageManagement`,{defaultValue:`Package management`}),t=n=>n.flatMap(n=>{if(yd(n))return[];let r=n.children?.length?t(n.children):n.children;return n.type===`group`&&r?.length===0?[]:bd(n)?[{...n,type:`url`,label:e,url:`${R}/component/developer/packages${ne}`,children:r}]:r===n.children?[n]:[{...n,children:r}]});return t(L).flatMap(e=>xd(e)?e.children??[]:[e])},[E?.name,R,d,L,ne,o]),ie=$.useMemo(()=>{let e=D(re);return A(e)},[re,D,A]),[ae,oe]=$.useState(!1),{evaluator:se}=ci(),ce=$.useCallback(e=>si(e,se),[se]),{can:le}=x(),ue=$.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return le(n,r)}),[le]),de=$.useMemo(()=>new Set((S||[]).map(e=>e?.name).filter(Boolean)),[S]),fe=$.useCallback((e,t)=>e!==`object`||de.size===0||de.has(t),[de]),pe=z&&a.pathname.replace(/\/+$/,``)===R;return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(at,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&d===`app`&&(0,Q.jsx)(wt,{className:`border-b p-1.5`,children:(0,Q.jsx)(we,{children:(0,Q.jsx)(It,{children:(0,Q.jsx)(Ue,{asChild:!0,className:`min-h-[44px] text-[15px] font-medium rounded-xl`,children:(0,Q.jsxs)(n,{to:`/home`,onClick:()=>r(!1),"data-testid":`mobile-sidebar-home`,children:[(0,Q.jsx)(Lr,{className:`h-5 w-5`}),(0,Q.jsx)(`span`,{children:o(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Q.jsx)(ct,{className:`pt-2`,children:(0,Q.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:d===`app`&&E?(0,Q.jsxs)(Q.Fragment,{children:[I&&(0,Q.jsx)(W,{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)(Je,{children:I})})}),z&&(0,Q.jsx)(W,{children:(0,Q.jsx)(Je,{children:(0,Q.jsx)(we,{children:(0,Q.jsx)(It,{children:(0,Q.jsx)(Ue,{asChild:!0,isActive:pe,tooltip:o(`home.nav`,{defaultValue:`Home`}),children:(0,Q.jsxs)(n,{to:{pathname:R,search:ne},children:[(0,Q.jsx)(Lr,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:o(`home.nav`,{defaultValue:`Home`})})]})})})})})}),M.length>1&&(0,Q.jsxs)(W,{children:[(0,Q.jsxs)(nt,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(wr,{className:`h-3.5 w-3.5`}),o(`sidebar.area`,{defaultValue:`Area`})]}),(0,Q.jsx)(Je,{children:(0,Q.jsx)(we,{children:M.map(e=>{let t=yo(e.icon);return(0,Q.jsx)(It,{children:(0,Q.jsxs)(Ue,{isActive:e.id===N,tooltip:e.label,onClick:()=>P(e.id),children:[(0,Q.jsx)(t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,Q.jsx)(Ja,{items:ie,basePath:R,evaluateVisibility:ce,checkPermission:ue,checkCapability:fe,enablePinning:!t,onPinToggle:k,enableReorder:!t,onReorder:O,resolveObjectLabel:(e,t)=>s({name:e,label:t}),resolveDashboardLabel:(e,t)=>c({name:e,label:t}),resolveGroupLabel:E?(e,t)=>l(E.name,e,t):void 0,resolveItemLabel:E?(e,t)=>E.name===`studio`&&t===o(`sidebar.packageManagement`,{defaultValue:`Package management`})?t:l(E.name,e,t):void 0,resolveViewLabel:(e,t,n)=>u(e,t,n),t:o,templateContext:{currentUserId:p?.id??null,currentOrgId:m?.id??null,contextValues:F}}),_.length>0&&(0,Q.jsxs)(W,{children:[(0,Q.jsxs)(nt,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>oe(e=>!e),children:[(0,Q.jsx)(nn,{className:`h-3 w-3 transition-transform duration-150 ${ae?`rotate-90`:``}`}),(0,Q.jsx)(Mt,{className:`h-3.5 w-3.5`}),o(`sidebar.recent`,{defaultValue:`Recent`})]}),ae&&(0,Q.jsx)(Je,{children:(0,Q.jsx)(we,{children:_.slice(0,5).map(e=>(0,Q.jsx)(It,{children:(0,Q.jsx)(Ue,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(n,{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))})})]}),v.some(e=>e.type!==`nav`)&&(0,Q.jsxs)(W,{children:[(0,Q.jsxs)(nt,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(yn,{className:`h-3.5 w-3.5`}),o(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Q.jsx)(Je,{children:(0,Q.jsx)(we,{children:v.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Q.jsxs)(It,{children:[(0,Q.jsx)(Ue,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(n,{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)(Bt,{showOnHover:!0,onClick:t=>{t.stopPropagation(),y(e.id)},"aria-label":o(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(Ir,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(W,{children:(0,Q.jsx)(Je,{children:(0,Q.jsx)(we,{children:te.map(e=>{let t=yo(e.icon),r=a.pathname===e.url;return(0,Q.jsx)(It,{children:(0,Q.jsx)(Ue,{asChild:!0,tooltip:e.label,isActive:r,children:(0,Q.jsxs)(n,{to:e.url||`/home`,children:[(0,Q.jsx)(t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:e.label})]})})},e.id)})})})}),v.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,Q.jsxs)(W,{children:[(0,Q.jsxs)(nt,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(yn,{className:`h-3.5 w-3.5`}),o(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Q.jsx)(Je,{children:(0,Q.jsx)(we,{children:v.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Q.jsxs)(It,{children:[(0,Q.jsx)(Ue,{asChild:!0,tooltip:e.label,children:(0,Q.jsxs)(n,{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)(Bt,{showOnHover:!0,onClick:t=>{t.stopPropagation(),y(e.id)},"aria-label":o(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(Ir,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Q.jsx)(ht,{className:`border-t p-1`,children:(0,Q.jsx)(cc,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function Cd({children:e}){return Pu(),(0,Q.jsx)(Q.Fragment,{children:e})}function wd({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:o,connectionState:s,userId:c}){let l=mo(n?.label)||t,{enabled:u}=Ea(),{setContext:d,setCurrentAppName:f}=xi(),p=Hu({persistExpandedKey:hc}),m=u,h=a(),g=i(),_=sn(),v=(0,$.useCallback)(()=>{Tc(`${g.pathname}${g.search}`),h(`/ai`)},[g.pathname,g.search,h]);return(0,$.useEffect)(()=>{d(`app`),f(t)},[d,f,t]),(0,$.useEffect)(()=>{if(!m)return;let e=e=>{Dc(e)===`toggle`&&(e.preventDefault(),p.toggle())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[m,p]),(0,Q.jsx)(oc,{children:(0,Q.jsx)(tc,{children:(0,Q.jsxs)(qa,{sidebar:(0,Q.jsx)(Sd,{activeAppName:t,onAppChange:r}),navbar:(0,Q.jsx)(pc,{variant:`app`,appName:l,objects:o,connectionState:s,activeAppName:t,onAppChange:r}),className:`!p-0 overflow-y-auto overflow-x-hidden bg-muted/5`,rightRail:m&&p.expanded&&!_?(0,Q.jsx)(Wu,{dock:p,userId:c,defaultAgent:n?.defaultAgent,onMaximize:v}):void 0,branding:n?.branding?{primaryColor:n.branding.primaryColor,accentColor:n.branding.accentColor,favicon:n.branding.favicon,logo:n.branding.logo,title:n.label?`${mo(n.label)} — ${Ba()}`:void 0}:void 0,children:[(0,Q.jsxs)(Cd,{children:[(0,Q.jsx)(ad,{}),(0,Q.jsx)(ud,{}),e]}),u&&(0,Q.jsx)(ks,{appLabel:l,onOpenDock:p.expand}),m&&_&&(0,Q.jsx)(Gu,{open:p.expanded,onOpenChange:e=>e?p.expand():p.collapse(),userId:c,defaultAgent:n?.defaultAgent,onMaximize:v})]})})})}function Td({apps:e,activeApp:t,objects:n,onAppChange:r,dataSource:i}){let{open:o,setOpen:s}=sc(),[c,u]=(0,$.useState)(``),d=a(),{appName:f}=l(),{setTheme:p}=us(),{evaluator:m}=ci(),{t:h}=G();(0,$.useEffect)(()=>{o||u(``)},[o]);let g=`/apps/${f||fo(t)}`,{user:_,activeOrganization:v}=T(),y=(0,$.useMemo)(()=>({currentUserId:_?.id??null,currentOrgId:v?.id??null}),[_?.id,v?.id]),b=(0,$.useCallback)(e=>{s(!1),e()},[]),x=Ed(t?.navigation||[]).filter(e=>si(e.visible??e.visibleOn,m)),{results:S,isSearching:C}=R({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:se}),{recentItems:w}=vi(),E=(0,$.useMemo)(()=>w.filter(e=>e.type===`record`).slice(0,5),[w]),D=o&&c.trim().length===0&&E.length>0,O=(0,$.useMemo)(()=>{let e=new Map;for(let t of n||[])typeof t?.name==`string`&&e.set(t.name,t);return e},[n]),k=(0,$.useMemo)(()=>{let e=[],t=new Map;for(let n of S){let r=t.get(n.objectName);r||(r={objectLabel:mo(O.get(n.objectName)?.label,h)||n.objectLabel,icon:n.icon,hits:[]},t.set(n.objectName,r),e.push(n.objectName)),r.hits.push(n)}return e.map(e=>({objectName:e,...t.get(e)}))},[S,O,h]);return(0,Q.jsxs)(K,{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)(an,{placeholder:h(`console.commandPalette.placeholder`),value:c,onValueChange:u}),(0,Q.jsxs)(B,{children:[(0,Q.jsx)(en,{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)(Yt,{heading:h(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:E.map(e=>(0,Q.jsxs)(_t,{value:`recent ${e.label} ${e.id}`,onSelect:()=>b(()=>d(e.href)),children:[(0,Q.jsx)(zt,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]},`recent:${e.id}`))}),k.map((e,t)=>{let n=yo(e.icon);return(0,Q.jsx)(Yt,{heading:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e.objectLabel,C&&t===0&&(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:e.hits.map(e=>(0,Q.jsxs)(_t,{value:`record ${c} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>b(()=>d(`${g}/${e.objectName}/record/${e.recordId}`)),children:[(0,Q.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.display}),e.subtitle&&(0,Q.jsx)(`span`,{className:`ml-auto max-w-[45%] truncate text-xs text-muted-foreground`,children:e.subtitle})]},`${e.objectName}:${e.recordId}`))},`records:${e.objectName}`)}),x.filter(e=>e.type===`object`).length>0&&(0,Q.jsx)(Yt,{heading:h(`console.commandPalette.objects`),children:x.filter(e=>e.type===`object`).map(e=>{let t=yo(e.icon);return(0,Q.jsxs)(_t,{value:`object ${mo(e.label,h)} ${e.objectName}`,onSelect:()=>b(()=>d(Ka(e,g,y).href)),children:[(0,Q.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:mo(e.label,h)})]},e.id)})}),x.filter(e=>e.type===`dashboard`).length>0&&(0,Q.jsx)(Yt,{heading:h(`console.commandPalette.dashboards`),children:x.filter(e=>e.type===`dashboard`).map(e=>(0,Q.jsxs)(_t,{value:`dashboard ${mo(e.label,h)} ${e.dashboardName}`,onSelect:()=>b(()=>d(Ka(e,g,y).href)),children:[(0,Q.jsx)($n,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:mo(e.label,h)})]},e.id))}),x.filter(e=>e.type===`page`).length>0&&(0,Q.jsx)(Yt,{heading:h(`console.commandPalette.pages`),children:x.filter(e=>e.type===`page`).map(e=>(0,Q.jsxs)(_t,{value:`page ${mo(e.label,h)} ${e.pageName}`,onSelect:()=>b(()=>d(Ka(e,g,y).href)),children:[(0,Q.jsx)(hr,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:mo(e.label,h)})]},e.id))}),x.filter(e=>e.type===`report`).length>0&&(0,Q.jsx)(Yt,{heading:h(`console.commandPalette.reports`),children:x.filter(e=>e.type===`report`).map(e=>(0,Q.jsxs)(_t,{value:`report ${mo(e.label,h)} ${e.reportName}`,onSelect:()=>b(()=>d(Ka(e,g,y).href)),children:[(0,Q.jsx)(sr,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:mo(e.label,h)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(jn,{}),(0,Q.jsx)(Yt,{heading:h(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=yo(e.icon);return(0,Q.jsxs)(_t,{value:`app ${mo(e.label,h)} ${e.name}`,onSelect:()=>b(()=>r(fo(e)??e.name)),children:[(0,Q.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:mo(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)(jn,{}),(0,Q.jsxs)(Yt,{heading:h(`console.commandPalette.preferences`),children:[(0,Q.jsxs)(_t,{value:`theme light`,onSelect:()=>b(()=>p(`light`)),children:[(0,Q.jsx)(ln,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.lightTheme`)})]}),(0,Q.jsxs)(_t,{value:`theme dark`,onSelect:()=>b(()=>p(`dark`)),children:[(0,Q.jsx)(Fe,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.darkTheme`)})]}),(0,Q.jsxs)(_t,{value:`theme system`,onSelect:()=>b(()=>p(`system`)),children:[(0,Q.jsx)(Ge,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.systemTheme`)})]})]}),(0,Q.jsx)(jn,{}),(0,Q.jsx)(Yt,{heading:h(`console.commandPalette.actions`),children:(0,Q.jsxs)(_t,{value:`search all results full page`,onSelect:()=>b(()=>d(`${g}/search`)),children:[(0,Q.jsx)(zt,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.openFullSearch`)})]})})]})]})}function Ed(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Ed(n.children)):t.push(n);return t}function Dd(){let{t:e}=G(),{open:t,setOpen:n,toggleOverlay:r}=ss(Di),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)(Cr,{open:t,onOpenChange:n,children:(0,Q.jsxs)(ar,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,"data-testid":`overlay:keyboard-shortcuts`,children:[(0,Q.jsxs)(gn,{children:[(0,Q.jsx)(dr,{children:e(`console.shortcuts.title`)}),(0,Q.jsx)(_r,{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 Od(){return null}function kd(e){let{theme:t=`system`}=us(),{t:n}=G();return(0,Q.jsx)(Wr,{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)(Ce,{className:`h-4 w-4`}),info:(0,Q.jsx)(dn,{className:`h-4 w-4`}),warning:(0,Q.jsx)(rr,{className:`h-4 w-4`}),error:(0,Q.jsx)(ye,{className:`h-4 w-4`}),loading:(0,Q.jsx)(Y,{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 Ad=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function jd({children:e,className:t}){let n=i(),r=$.useRef(null),a=$.useRef(n.pathname);return $.useLayoutEffect(()=>{if(a.current===n.pathname)return;a.current=n.pathname;let e=r.current;e&&(e.classList.remove(...Ad),e.offsetWidth,e.classList.add(...Ad))},[n.pathname]),(0,Q.jsx)(`div`,{ref:r,className:[...Ad,t??``].filter(Boolean).join(` `),children:e})}var Md=null,Nd=null;function Pd(){return Nd||(Nd=(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||e.VITE_SENTRY_ENABLED===`false`)return!1;try{let n=await o(()=>import(`./vendor-sentry-BwxF-feC.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=Id(e.data.url)),e}}),Md=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),Nd)}function Fd(e,t){if(Md)try{Md.captureException(e,t?{extra:t}:void 0)}catch{}}function Id(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 Ld({error:e,onReset:t}){let{t:n}=G();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)(or,{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)(rr,{className:`h-6 w-6 text-destructive`})}),(0,Q.jsx)(pr,{children:n(`console.errors.somethingWentWrong`)}),(0,Q.jsx)(vr,{className:`mb-4`,children:e.message||n(`console.errors.unexpectedError`)}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,Q.jsxs)(J,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,Q.jsx)($t,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,Q.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,Q.jsx)(Lr,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var Rd=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),Fd(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)(Ld,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}},zd=`list-filters`;function Bd(e,t,n){if(!(!t||!n))return`${zd}:${e||`anon`}:${t}:${n}`}function Vd(e){return!e||!Array.isArray(e.conditions)||e.conditions.length===0}function Hd(e){return Vd(e.filters)&&!(e.search&&e.search.length>0)}function Ud(e){if(!(!e||typeof localStorage>`u`))try{let t=localStorage.getItem(e);if(!t)return;let n=JSON.parse(t);return!n||typeof n!=`object`?void 0:n}catch{return}}var Wd={},Gd={};function Kd(e,t){!e||typeof localStorage>`u`||(Wd[e]={...Wd[e]??Ud(e)??{},...t},Gd[e]&&clearTimeout(Gd[e]),Gd[e]=setTimeout(()=>{let t=Wd[e]??{};delete Wd[e],delete Gd[e];try{Hd(t)?localStorage.removeItem(e):localStorage.setItem(e,JSON.stringify(t))}catch{}},300))}var qd=new Set([`form`,`detail`]);function Jd(e){return typeof e==`string`&&qd.has(e)}function Yd(e,t){let n=e.type||`grid`,r=Jd(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 Xd(e){let t=e.config??{},n={...t};return delete n.data,{...n,id:e.name,label:e.label??t.label}}function Zd(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 Qd({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s,metadataClient:c,onAfterChange:l}){let{t:u}=G(),d=(0,$.useRef)(null),f=bo(),[p]=(0,$.useState)(()=>`view_${Date.now()}`),m=(0,$.useMemo)(()=>({id:p,label:u(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[]}),[]),h=(0,$.useMemo)(()=>Yd(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)(()=>Zd(i),[i.fields]),T=Ra(g.viewKind)?`form`:`list`,E=(0,$.useCallback)(e=>{let t={...S.current,...e};if(S.current=t,_(t),y(!0),a){let e=Xd(t);for(let[t,n]of Object.entries(e))t!==`id`&&a(t,n)}},[a]),D=(0,$.useCallback)(()=>{let e=Xd(g);n===`create`?s?.(e):(o?.(e),x(e=>e+1)),y(!1)},[g,o,s,n]),O=(0,$.useCallback)(()=>{if(n===`edit`){if(a){let e=Xd(h),t=Xd(S.current),n=new Set([...Object.keys(t),...Object.keys(e)]);for(let t of n)t!==`id`&&a(t,e[t])}S.current=h,_(h),y(!1)}t()},[h,n,t,a]),k=(0,$.useCallback)(e=>{let t=Yd(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)(ya,{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)(ts,{type:`view`,name:r.id,metadataClient:c,dirty:v,onResume:k,savedSignal:b,onAfterChange:l}),(0,Q.jsx)(J,{variant:`ghost`,size:`sm`,onClick:O,"data-testid":`view-config-discard`,children:u(`console.objectView.discard`)}),(0,Q.jsx)(J,{size:`sm`,onClick:D,disabled:n===`edit`&&!v,"data-testid":`view-config-save`,children:u(`console.objectView.save`)})]})]}):(0,Q.jsx)(`div`,{ref:d,tabIndex:-1,"data-testid":`view-config-panel`,"aria-hidden":!0})}var $d=`sys_user`;function ef(e,t=500){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function tf(e){let t=e.writeMode??`insert`;if(t===`update`)throw Error(`Identity import supports the insert and upsert write modes only.`);if(t===`insert`)return{mode:`insert`};let n=(e.matchFields??[])[0];if(n===`email`)return{mode:`upsert`,matchBy:`email`};if(n===`phone_number`)return{mode:`upsert`,matchBy:`phone`};throw Error(`Identity import matches existing users by "email" or "phone_number" only.`)}function nf(e,t,n){let r=0,i=0,a=0,o=0,s=0,c=[],l=0;for(let n=0;n<e.length;n++){let{summary:u,rows:d}=e[n],f=t[n]??[];r+=u.total,i+=u.created,a+=u.updated,o+=u.skipped,s+=u.errors;for(let e of d){if(!e)continue;let t=f[e.row-1],n=[t?.email,t?.phone_number,t?.phoneNumber,t?.phone].find(e=>typeof e==`string`&&e.trim().length>0);c.push({row:l+e.row,ok:e.ok,action:e.action,...e.id?{id:e.id}:{},...e.field?{field:e.field}:{},...e.code?{code:e.code}:{},...e.error?{error:e.error}:{},...e.temporaryPassword?{temporaryPassword:e.temporaryPassword}:{},...n?{identity:n.trim()}:{}})}l+=f.length||u.total}return{object:$d,dryRun:n.dryRun,writeMode:n.writeMode,total:r,ok:r-s,errors:s,created:i,updated:a,skipped:o,results:c}}function rf(e){let{base:t,authFetch:n,baseUrl:r,getPasswordPolicy:i}=e,a=async(e,t)=>{let{mode:a,matchBy:o}=tf(t),s=i(),c=Array.isArray(t.rows)?t.rows:[];if(c.length===0)throw Error(`Identity import needs mapped rows (rows[]) — file uploads are parsed client-side.`);let l=ef(c),u=[];for(let e of l){let i=await n(`${r}/api/v1/auth/admin/import-users`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({format:`json`,rows:e,mode:a,...o?{matchBy:o}:{},passwordPolicy:s,...t.dryRun?{dryRun:!0}:{},...t.mappingName?{mappingName:t.mappingName}:{},...t.trimWhitespace===void 0?{}:{trimWhitespace:t.trimWhitespace},...t.nullValues?{nullValues:t.nullValues}:{}})}),c=await i.json().catch(()=>null);if(!i.ok||!c?.success||!c.data){let e=c?.error?.message??`Identity import failed with status ${i.status}`;throw Error(e)}u.push(c.data)}return nf(u,l,{dryRun:t.dryRun===!0,writeMode:a})};return{...t,importRecords:a,createImportJob:void 0,getImportJobProgress:void 0,getImportJobResults:void 0,listImportJobs:void 0,cancelImportJob:void 0,undoImportJob:void 0}}function af(e){if(!e?.results)return[];let t=[];for(let n of e.results)n?.temporaryPassword&&t.push({row:n.row,identity:n.identity??`#${n.row}`,temporaryPassword:n.temporaryPassword});return t}function of(e){let t=e=>/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e,n=[`row,identity,temporary_password`];for(let r of e)n.push(`${r.row},${t(r.identity)},${t(r.temporaryPassword)}`);return n.join(`
8
- `)}var sf={auto:{label:`Automatic (recommended)`,hint:`Reachable users get an invitation (email or SMS); anyone we can't reach gets a one-time password, shown ONCE on the result screen. Works with or without an email/SMS service.`},invite:{label:`Send invitations`,hint:`Every created user gets a set-your-password email (or an invitation SMS for phone-only rows). Requires a configured email/SMS service — unreachable rows fail.`},temporary:{label:`Temporary passwords`,hint:`For deployments without email/SMS: every created user gets a one-time password, shown ONCE on the result screen. First sign-in forces a change.`},none:{label:`No password (identity only)`,hint:`Users first sign in with a phone OTP, magic link, or password-reset link, then set their own password.`}};function cf({policy:e,onPolicyChange:t}){let n=Qe();return(0,Q.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 rounded-md border border-border p-3`,"data-testid":`identity-import-options`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(er,{className:`h-4 w-4 text-muted-foreground`}),(0,Q.jsx)(U,{className:`text-xs font-medium`,children:n(`console.identityImport.policyTitle`,`Sign-in setup for imported users`)})]}),(0,Q.jsxs)(Bn,{value:e,onValueChange:e=>t(e),children:[(0,Q.jsx)(yr,{className:`h-8 w-full sm:w-80`,"data-testid":`identity-import-policy`,children:(0,Q.jsx)(wn,{})}),(0,Q.jsx)(hn,{children:Object.keys(sf).map(e=>(0,Q.jsx)(lr,{value:e,children:n(`console.identityImport.policy.${e}`,sf[e].label)},e))})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`console.identityImport.policyHint.${e}`,sf[e].hint)})]})}function lf({serverResult:e}){let t=Qe(),n=(0,$.useMemo)(()=>af(e),[e]);return n.length===0?null:(0,Q.jsxs)(`div`,{className:`mt-2 flex w-full flex-col gap-2 rounded-md border border-amber-500/50 bg-amber-500/5 p-3`,"data-testid":`identity-import-passwords`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-amber-700 dark:text-amber-400`,children:[(0,Q.jsx)(qe,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`p`,{className:`text-xs font-medium`,children:t(`console.identityImport.passwordsNote`,`Temporary passwords — shown once, never stored. Save them now; each user must change theirs at first sign-in.`)})]}),(0,Q.jsxs)(`div`,{className:`max-h-40 overflow-auto rounded border bg-background p-2 font-mono text-xs`,children:[n.slice(0,50).map(e=>(0,Q.jsxs)(`p`,{"data-testid":`identity-import-password-row-${e.row}`,children:[e.identity,`: `,e.temporaryPassword]},e.row)),n.length>50&&(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:t(`console.identityImport.passwordsMore`,`More entries omitted — use the download.`)})]}),(0,Q.jsx)(`div`,{children:(0,Q.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>{let e=of(n),t=new Blob([e],{type:`text/csv;charset=utf-8`}),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=`temporary-passwords.csv`,i.click(),URL.revokeObjectURL(r)},"data-testid":`identity-import-passwords-download`,children:[(0,Q.jsx)(Tr,{className:`mr-1 h-4 w-4`}),t(`console.identityImport.passwordsDownload`,`Download CSV`),` (`,n.length,`)`]})})]})}function uf(e){let t=(t,n)=>e?.[t]?.label||n;return[{name:`email`,label:t(`email`,`Email`),type:`text`},{name:`phone_number`,label:t(`phone_number`,`Phone Number`),type:`text`},{name:`name`,label:t(`name`,`Name`),type:`text`},{name:`role`,label:t(`role`,`Platform Role`),type:`text`}]}function df(e,t,n,r){switch(e){case`engine-owned`:case`system`:return de({managedBy:e,userActions:r}).create?void 0:{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.`})}:n===`sys_team`?{icon:`Users`,title:t(`list.managedBy.betterAuthTeam.title`,{defaultValue:`No teams yet`}),message:t(`list.managedBy.betterAuthTeam.message`,{defaultValue:`Teams group members within an organization. Create one with “Create Team”, or they arrive through your auth provider’s organization and SSO provisioning flows.`})}:{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}}function ff(e,t,n){if(!e)return;let r=e=>t.includes(e);if(r(e))return e;let i=`${n}.`;if(!e.includes(`.`)&&r(i+e))return i+e;if(e.startsWith(i)&&r(e.slice(i.length)))return e.slice(i.length)}var pf=new Set;function mf(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.element===`tabs`||t.tabs!=null}function hf(e,t,n,r){let i=[];if((n?.quickFilters??r?.quickFilters)!=null&&i.push(`quickFilters`),mf(n?.userFilters??r?.userFilters)&&i.push(`userFilters (element: "tabs")`),i.length===0)return!1;let a=`${e}.${t}`;return pf.has(a)||(pf.add(a),console.warn(`[ObjectView] View "${t}" on object "${e}" defines ${i.join(` and `)}, which are ignored on an object list view (ADR-0047 "views" mode — the view switcher owns the tab bar here). Use \`listViews\` for named presets, \`element: "dropdown"\` for value chips, or move them to a page list (InterfaceListPage "filters" mode).`)),!0}var gf=new Set([`archived`,`failed`]);function _f(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 vf(e){let{enabled:t,dataSource:n,authFetch:r,apiBase:i,refreshKey:a}=e,{activeOrganization:o}=T(),s=o?.id,[c,l]=(0,$.useState)(null);return(0,$.useEffect)(()=>{if(!t){l(null);return}let e=!1,a=async()=>{try{let e=(i||``).replace(/\/+$/,``),t=s?`?organizationId=${encodeURIComponent(s)}`:``,n=await r(`${e}/api/v1/cloud/environment-entitlements${t}`,{method:`GET`,credentials:`include`});if(!n.ok)return null;let a=await n.json().catch(()=>null),o=a?.data??a;return!o||typeof o!=`object`?null:{ready:!0,hasProductionEnv:o.hasProductionEnv===!0,canCreateDevelopmentEnv:o.development?.canCreate,plan:o.plan,upgradeUrl:o.upgradeUrl||`/settings/billing`,contactSalesUrl:o.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=>!gf.has(String(e?.status??``))).some(e=>_f(e)===`production`),canCreateDevelopmentEnv:void 0,upgradeUrl:Ui,source:`derived`}}catch{return{ready:!1,hasProductionEnv:!1,canCreateDevelopmentEnv:void 0,upgradeUrl:Ui,source:`unknown`}}};return(async()=>{let t=await a()??await o();e||l(t)})(),()=>{e=!0}},[t,s,i,r,n,a]),c}var yf=`create_environment`;function bf(e){let[t]=(0,$.useState)(()=>{try{return new URLSearchParams(window.location.search).get(`runAction`)===yf}catch{return!1}}),n=(0,$.useRef)(!1),r=t&&!n.current&&e!=null;return(0,$.useEffect)(()=>{if(r){n.current=!0;try{let e=new URL(window.location.href);e.searchParams.delete(`runAction`),window.history.replaceState(window.history.state,``,e)}catch{}}},[r]),r}function xf({actions:e,entitlements:t,onUpgrade:n}){let{t:r}=G(),i=(e||[]).filter(e=>e?.locations?.includes(`list_toolbar`)),a=t?.ready?Vi(t):null,o=bf(i.length>0?a:null);if((0,$.useEffect)(()=>{o&&a===`upgrade_for_development`&&t&&n(Bi(t))},[o,a]),i.length===0)return null;if(a===`upgrade_for_development`){let e=i.filter(e=>e?.name!==yf);return(0,Q.jsxs)(Q.Fragment,{children:[e.length>0&&(0,Q.jsx)(k,{schema:{type:`action:bar`,location:`list_toolbar`,actions:e,size:`sm`,variant:`outline`}}),(0,Q.jsxs)(J,{size:`sm`,onClick:()=>n(Bi(t)),className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,"data-testid":`environment-add-upgrade`,children:[(0,Q.jsx)(Sn,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:r(`environment.addEnvironment`)})]})]})}return(0,Q.jsx)(k,{schema:{type:`action:bar`,location:`list_toolbar`,actions:i.map(e=>e?.name!==yf||a==null?e:a===`setup_production`?{...e,label:r(`environment.setUpProduction`),variant:`primary`,...o?{autoTrigger:!0}:{}}:{...e,label:r(`environment.addDevelopment`),...o?{autoTrigger:!0}:{}}),size:`sm`,variant:`outline`}})}var Sf=(0,$.lazy)(()=>o(()=>import(`./plugin-charts-DHSgUtpJ.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),Cf=(0,$.lazy)(()=>o(()=>import(`./plugin-grid-UMSBKycd.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),wf={grid:Rn,kanban:jr,calendar:Cn,gallery:Tn,timeline:Ke,gantt:xr,map:mr,chart:sr},Tf={id:`current-user`,name:`Demo User`};function Ef(e,t){return N(e,t)}function Df(e,t=5,n){let r=t=>n?.orgAttribution&&e?.fields?.organization_id&&!t.includes(`organization_id`)?[...t,`organization_id`]:t,i=e?.highlightFields;if(Array.isArray(i)&&i.length>0)return r(i.filter(t=>e?.fields?.[t]));let a=e?.fields;return a&&typeof a==`object`?r(Object.entries(a).filter(([e,t])=>t&&!t.hidden&&!te(e,t)).map(([e])=>e).slice(0,t)):[]}function Of({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let{objectName:i}=l(),{t:a}=G();return t.find(e=>e.name===i)?(0,Q.jsx)(kf,{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)(or,{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)(Rn,{className:`h-6 w-6 text-muted-foreground`})}),(0,Q.jsx)(pr,{children:a(`console.objectView.objectNotFound`)}),(0,Q.jsxs)(vr,{children:[a(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,a(`console.objectView.objectNotFoundHint`)]})]})})}function kf({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let o=a(),{appName:c,objectName:u,viewId:d}=l(),[f,p]=s(),m=i(),{showDebug:h}=Xo(),{t:_}=G(),{objectLabel:v,objectDescription:y,viewLabel:b,viewEmptyState:S,actionLabel:C,actionConfirm:w,actionSuccess:E,actionParamText:D,fieldLabel:j,fieldOptionLabel:M}=Nt(),{isFavorite:N,toggleFavorite:P}=Li(),ee=go()===`group`,F=So(),I=ri(),[te,R]=(0,$.useState)(!1),[z,ne]=(0,$.useState)(`edit`),[re,ie]=(0,$.useState)(!1),[oe,se]=(0,$.useState)(!1),[ce,le]=(0,$.useState)(null),ue=(0,$.useRef)({}),pe=(0,$.useRef)({}),B=(0,$.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!u||!t)return;let i=pe.current[t]||{};pe.current[t]={...i,...r};let a=ue.current[t];a&&clearTimeout(a),ue.current[t]=setTimeout(()=>{let r=pe.current[t]||{};delete pe.current[t],delete ue.current[t],Promise.resolve(e.updateViewConfig(u,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,u]),he=(0,$.useCallback)(e=>{le(e),Te(e=>e+1);let t=e.id;F&&t?$o(`view`,t,e,{metadataClient:F}).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing metadataClient or viewId.`)},[F]),_e=(0,$.useCallback)(async e=>{try{let n;if(F){let r=t?.find?.(e=>e.name===u),i=Df(r,5),a=Array.isArray(e.columns)&&e.columns.length>0?e.columns:i,o={...e,columns:a};if(e.type===`kanban`)o.kanban={...o.kanban||{},columns:a};else if(e.type===`gallery`){let e=o.gallery||{};(!Array.isArray(e.visibleFields)||e.visibleFields.length===0)&&(o.gallery={...e,visibleFields:a})}let s=Qo(u,o,{name:e?.name,label:e.label});n=await es(`view`,s.name,s,{metadataClient:F})}if(R(!1),ne(`edit`),Te(e=>e+1),n){let e=I?``:`?${ni}=${ei}`;d?o(`../${n}${e}`,{relative:`path`}):o(`view/${n}${e}`)}}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,u,t,o,d,F,I]),[ve,ye]=(0,$.useState)(void 0),{user:be,activeOrganization:xe}=T(),V=g(),Se=x(),{can:Ce,getObjectApiOperations:we}=Se,H=t.find(e=>e.name===u),[U,Te]=(0,$.useState)(0),Ee=Hi({dataSource:e,objects:t,objectName:H.name,onRefresh:()=>Te(e=>e+1)}),{confirmHandler:De,toastHandler:Oe}=Ee,ke=H.name===`sys_environment`,Ae=vf({enabled:ke,dataSource:e,authFetch:Ee.authFetch,apiBase:``,refreshKey:U}),je=(0,$.useMemo)(()=>(H.actions||[]).map(e=>({...e,label:C(H.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:w(H.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:E(H.name,e.name,e.successMessage)}})),[H,C,w,E]),Me=(0,$.useMemo)(()=>de(H,we(H.name)),[H,we]);(0,$.useEffect)(()=>{r===void 0||r===0||Te(e=>e+1)},[r]);let[Ne,Pe]=(0,$.useState)(!1),{features:Fe}=ci(),Ie=H.name===`sys_user`&&Fe?.admin===!0&&V,[Le,W]=(0,$.useState)(`auto`),Re=(0,$.useRef)(`auto`);Re.current=Le;let ze=(0,$.useMemo)(()=>Ie?rf({base:e,authFetch:Ee.authFetch,baseUrl:``,getPasswordPolicy:()=>Re.current}):void 0,[Ie,e,Ee.authFetch]),[Be,Ve]=(0,$.useState)([]);(0,$.useEffect)(()=>{let t=!1;if(!u){Ve([]);return}return typeof e?.listViews==`function`?(e.listViews(u,{previewDrafts:I}).then(e=>{if(t)return;let n=(e||[]).map(e=>({...e,id:e.name||e.id,objectName:e.objectName||e.object||u}));Ve(n)}).catch(e=>{console.error(`[ObjectView] Failed to load overlay views:`,e),t||Ve([])}),()=>{t=!0}):(Ve([]),()=>{t=!0})},[e,u,U,I]);let[He,Ue]=(0,$.useState)({});(0,$.useEffect)(()=>{let t=!1;if(!e||!u){Ue({});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){Ue({});return}return(async()=>{if(typeof e.listViewOverrides==`function`)try{let t=await e.listViewOverrides(u);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(u,t)]}catch{return[t,null]}})),n={};for(let[e,r]of t)r&&typeof r==`object`&&(n[e]=r);return n})().then(e=>{t||Ue(e)}),()=>{t=!0}},[e,u,H.listViews,H.list_views,H.list,U]);let We=(0,$.useMemo)(()=>{let e=()=>Df(H,5,{orgAttribution:ee}),t=H.listViews||H.list_views||{},n=Object.entries(t).map(([e,t])=>{let n=He[e];return{id:e,...t,...n||{},type:n?.type||t.type||`grid`}}),r=H.list;if(r&&typeof r==`object`){let e=r.name||`list`,t=n.findIndex(t=>t.id===e);if(t>=0){let[e]=n.splice(t,1);n.unshift({...e,isDefault:!0})}else{let t=He[e];n.unshift({id:e,...r,...t||{},type:t?.type||r.type||`grid`,isDefault:!0})}}n.length===0&&n.push({id:`all`,label:_(`console.objectView.allRecords`),type:`grid`,columns:e()});let i=new Set(n.map(e=>e.id));for(let e of Be){let t=e.id||e._id;if(!t)continue;let r={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},a={};for(let[e,t]of Object.entries(r))t!==void 0&&(a[e]=t);if(i.has(t)){let e=n.findIndex(e=>e.id===t);n[e]={...n[e],...a}}else n.push(a)}let a=new Set([`grid`,`list`,`table`]);for(let t of n)a.has(t.type)&&(!Array.isArray(t.columns)||t.columns.length===0)&&(t.columns=e());let o=new Map(n.map((e,t)=>[e.id,t])),s=[];try{let e=typeof window<`u`?window.localStorage?.getItem(`viewOrder:${H.name}`):null;e&&(s=JSON.parse(e))}catch{}let c=new Map(s.map((e,t)=>[e,t]));return n.sort((e,t)=>{let n=c.get(e.id),r=c.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=Be.find(t=>(t.id||t._id)===e.id),a=Be.find(e=>(e.id||e._id)===t.id),s=i&&typeof i.sortOrder==`number`,l=a&&typeof a.sortOrder==`number`;return s&&l?i.sortOrder===a.sortOrder?(i.created_at||``).localeCompare(a.created_at||``):i.sortOrder-a.sortOrder:s?-1:l?1:(o.get(e.id)??0)-(o.get(t.id)??0)}),n},[H,Be,He,_,ee]),Ge=(0,$.useMemo)(()=>We.find(e=>e.isDefault)?.id,[We]),Ke=d||f.get(`view`)||void 0,qe=(0,$.useMemo)(()=>ff(Ke,We.map(e=>e.id),H.name),[Ke,We,H.name]);(0,$.useEffect)(()=>{Ke&&!qe&&console.warn(`[ObjectView] Requested view "${Ke}" not found on object "${H.name}"; falling back to the default view. Known views: ${We.map(e=>e.id).join(`, `)}`)},[Ke,qe,H.name,We]);let Je=qe||Ge||We[0]?.id,Ye=We.find(e=>e.id===Je)||We[0],K=ce&&ce.id===Ye?.id?{...Ye,...ce}:Ye,Xe=(0,$.useCallback)((e,t)=>{le(n=>({...n||{},id:Ye?.id,[e]:t}))},[Ye?.id]),Ze=e=>{let t=We.find(t=>t.id===e);t&&(t.id!==Je&&R(!1),d?o(`../${t.id}`,{relative:`path`}):o(`view/${t.id}`))},Qe=(0,$.useMemo)(()=>(We||[]).map(e=>{let t=wf[e.type];return{id:e.id,label:b(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}}),[We,H.name,b]);ic({views:Qe,activeViewId:Je??``,onChange:Ze,enabled:Qe.length>0&&!!Je});let $e=(0,$.useCallback)(()=>{ie(!0)},[]),q=(0,$.useCallback)((e,t)=>{if(e===`settings`){let e=We.find(e=>e.type===t);e&&Ze(e.id),ne(`edit`),R(!0)}},[We,Ze]),et=(0,$.useCallback)(e=>Be.some(t=>(t.id||t._id)===e),[Be]),tt=(0,$.useCallback)(async(t,n)=>{if(!et(t)){X.error(_(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be renamed.`);return}try{typeof e?.updateView==`function`&&await e.updateView(u,t,{label:n}),Te(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),X.error(_(`objectViewActions.renameFailed`))}},[e,u,et,_]),nt=(0,$.useCallback)(async t=>{if(!e)return;if(!et(t)){X.error(_(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=We.find(e=>e.id===t)?.label||t;if(await De(_(`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(u,t),t===Je){let e=We.find(e=>e.id!==t);e&&o(d?`../${e.id}`:`view/${e.id}`,d?{relative:`path`}:void 0)}Te(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),X.error(_(`objectViewActions.deleteFailed`))}},[e,et,Je,We,d,o,_,De]),rt=(0,$.useCallback)(async(t,n)=>{if(e){if(!et(t)){X.error(_(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be pinned.`);return}try{typeof e?.updateView==`function`&&await e.updateView(u,t,{isPinned:n}),Te(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,u,et,_]),it=(0,$.useCallback)(async t=>{if(e){if(!et(t)){X.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=Be.filter(e=>(e.id||e._id)!==t&&e.isDefault).map(e=>n(u,e.id||e._id,{isDefault:!1}));r.push(n(u,t,{isDefault:!0})),await Promise.all(r),Te(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),X.error(`Failed to set default view`)}}},[e,u,Be,et,_]),at=(0,$.useCallback)(async t=>{try{typeof window<`u`&&window.localStorage?.setItem(`viewOrder:${u}`,JSON.stringify(t))}catch{}if(typeof e?.updateView==`function`){let n=e.updateView,r=new Set(Be.map(e=>e.id||e._id)),i=t.filter(e=>r.has(e)).map((e,t)=>n(u,e,{sortOrder:t}));try{await Promise.all(i)}catch(e){console.error(`[ViewTabBar] Failed to reorder views:`,e)}}Te(e=>e+1)},[e,Be,u]),ot=(0,$.useCallback)(e=>{if(!et(e)){X.error(_(`console.objectView.cannotEditMetaView`)||`System view — it cannot be edited.`);return}e!==Je&&Ze(e),ne(`edit`),R(!0)},[Je,Ze,et,_]),st=(0,$.useCallback)(()=>{ie(!0)},[]),ct=be?{id:be.id,name:be.name,avatar:be.image}:Tf,lt=(0,$.useMemo)(()=>({currentUserId:ct.id,currentOrgId:xe?.id??null}),[ct.id,xe?.id]),ut=as({objectName:H.name,objectLabel:H.label,dataSource:e,onEdit:n,onRefresh:()=>Te(e=>e+1),onConfirm:De,onToast:Oe}),{lastMessage:dt}=Ti({channel:`object:${H.name}`}),{hasConflicts:ft,resolveAllConflicts:pt}=Ei(H.name?`user-${H.name}`:`current-user`);(0,$.useEffect)(()=>{dt&&(ft&&pt(`remote`),Te(e=>e+1))},[dt,ft,pt]),(0,$.useEffect)(()=>{e?.find&&H.name&&e.find(H.name,{limit:0}).then(e=>{typeof e?.total==`number`?ye(e.total):Array.isArray(e?.data)?ye(e.data.length):Array.isArray(e)&&ye(e.length)}).catch(()=>{})},[e,H.name,U]);let mt=(0,$.useMemo)(()=>{let e=K?.navigation??H.navigation;return e?e.mode===`page`?e:{...e,width:e.width??qo(e.size,H)}:fe(H)===`page`?{mode:`page`}:{mode:`drawer`,width:qo(`auto`,H)}},[K?.navigation,H]),ht=f.get(bi),gt=Array.from(f.entries()).filter(([e])=>e.startsWith(`filter[`)).map(([e,t])=>`${e}=${t}`).join(`&`),Y=(0,$.useMemo)(()=>{let e=[];return new URLSearchParams(gt).forEach((t,n)=>{let r=/^filter\[(.+)\]$/.exec(n);r&&r[1]&&t!==``&&e.push([r[1],`=`,t])}),e},[gt]),[_t]=(0,$.useState)(()=>vo(new URLSearchParams(window.location.search))),vt=(0,$.useCallback)(e=>{p(t=>_o(t,e),{replace:!0})},[p]),yt=(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:m.pathname+(m.search||``),label:b(H.name,K?.name??``,K?.label??``)||v(H)}};d?o(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):o(`record/${encodeURIComponent(String(e))}`,{state:n})},[o,d,m.pathname,m.search,H,K?.name,K?.label,b,v]),bt=O({navigation:mt,objectName:H.name,onNavigate:yt}),xt=()=>{bt.close();let e=new URLSearchParams(f);e.delete(bi),p(e)},St=(0,$.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){bt.handleClick(e,t);return}if(bt.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(f);e.set(bi,String(t)),p(e);return}}bt.handleClick(e,t)},[bt,f,p]),Ct=(0,$.useCallback)(()=>{let e=bt.selectedRecord,t=e&&(e.id??e._id);t!=null&&(xt(),yt(t))},[bt.selectedRecord,yt]);(0,$.useEffect)(()=>{ht&&!bt.isOpen?bt.open({id:ht}):!ht&&bt.isOpen&&bt.close()},[ht]);let wt=(0,$.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=U+(i||0),o=`${u}-${K.id}-${a}`,s=K,c=Bd(be?.id,u,K.id),l=Ud(c);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)(Sf,{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)(Sf,{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 hf(H.name,s.id||s.name||``,s,e),(0,Q.jsx)(Go,{schema:{...e,label:s.label??e.label,rowHeight:s.rowHeight??e.rowHeight,densityMode:s.densityMode??e.densityMode,sort:s.sort??e.sort,filter:(()=>{let t=s.filter??e.filter,n=Array.isArray(t)?t:t?[t]:[];return Ef(Y.length?[...n,...Y]:t,lt)})(),hiddenFields:s.hiddenFields??e.hiddenFields,columnState:s.columnState??e.columnState,onDensityChange:e=>{B(s.id,s,{rowHeight:ae[e]})},onSortChange:e=>{B(s.id,s,{sort:e})},onFilterChange:e=>{B(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{B(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{B(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,data:s.data??e.data,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:C(H.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:w(H.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:E(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:(()=>{let t=s.userFilters??e.userFilters;return t&&t.element!==`tabs`&&t.tabs==null?t:void 0})(),showRecordCount:s.showRecordCount??e.showRecordCount,allowPrinting:s.allowPrinting??e.allowPrinting,virtualScroll:s.virtualScroll??e.virtualScroll,emptyState:S(H.name,s.name||s.id||``,s.emptyState??e.emptyState??df(H?.managedBy,_,H.name,H?.userActions)),aria:s.aria??e.aria,...s.sort?.length?{sort:s.sort}:{},options:{kanban:{...(()=>{let e=s.kanban?.groupByField||s.kanban?.groupField||L(H)||void 0;return e?{groupBy:e,groupField:e}:{}})(),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:{...s.timeline||{},startDateField:s.timeline?.startDateField||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`},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&&ut.deleteRecord(String(e.id),e)},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&ut.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)=>{St(e,t)},onSortChange:e=>{B(s.id,s,{sort:e})},onFilterChange:e=>{B(s.id,s,{filter:e}),Kd(c,{filters:e})},onSearchChange:e=>{Kd(c,{search:e})},onHiddenFieldsChange:e=>{B(s.id,s,{hiddenFields:e})},onInlineEditChange:e=>{B(s.id,s,{inlineEdit:e})},onColumnStateChange:e=>{B(s.id,s,{columnState:e})},userFilterSelections:_t,onUserFilterSelectionsChange:vt,initialFilters:l?.filters,initialSearchTerm:l?.search,dataSource:t},o)},[K,H,u,U,bt,ut,B,Y,_t,vt,be?.id]),Tt=(0,$.useMemo)(()=>We.map(e=>e.id===Je&&ce&&ce.id===e.id?{...e,...ce}:e),[We,Je,ce]),Et=(0,$.useMemo)(()=>({type:`object-view`,objectName:H.name,layout:`page`,showSearch:K?.showSearch!==!1,showFilters:K?.showFilters!==!1,showSort:K?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:V,viewActions:V?[{type:`settings`},{type:`share`},{type:`delete`}]:[],onNavigate:(e,t)=>{if(t===`edit`)n?.({id:e});else if(t===`view`){let t={from:{pathname:m.pathname+(m.search||``),label:b(H.name,K?.name??``,K?.label??``)||v(H)}};d?o(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):o(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[H,n,K?.showSearch,K?.showFilters,K?.showSort,K?.name,K?.label,o,d,V,m.pathname,m.search,b,v]);return(0,Q.jsxs)(A,{...Ee.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)(Uo,{title:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:v(H)}),(0,Q.jsx)(ns,{managedBy:H?.managedBy,userActions:H?.userActions})]}),description:H.description?y(H):void 0,icon:(0,Q.jsx)(yo(H?.icon),{className:`h-4 w-4`}),actions:(0,Q.jsxs)(Q.Fragment,{children:[u&&(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,onClick:()=>P({id:`object:${u}`,label:v(H),href:`/apps/${c}/${u}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":N(`object:${u}`),"aria-label":N(`object:${u}`)?_(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):_(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${u}`,children:N(`object:${u}`)?(0,Q.jsx)(yn,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Q.jsx)(Ir,{className:`h-4 w-4`})}),Me.create&&Ce(H.name,`create`)&&(0,Q.jsxs)(J,{size:`sm`,onClick:ut.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Q.jsx)(Sn,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:_(`console.objectView.new`)})]}),(Ie||Me.import&&Ce(H.name,`create`))&&(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>Pe(!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)(ge,{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`))&&(ke?(0,Q.jsx)(xf,{actions:je,entitlements:Ae,onUpgrade:Ee.openEntitlementDialog}):(0,Q.jsx)(k,{schema:{type:`action:bar`,location:`list_toolbar`,actions:je,size:`sm`,variant:`outline`,mobileMaxVisible:0}}))]})})}),Me.create&&Ce(H.name,`create`)&&(0,Q.jsx)(`button`,{type:`button`,onClick:ut.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)(Sn,{className:`h-5 w-5`})}),Ne&&(0,Q.jsx)($.Suspense,{fallback:null,children:(0,Q.jsx)(Cf,{open:Ne,onOpenChange:Pe,objectName:H.name,objectLabel:v(H),fields:Ie?uf(H.fields):Object.entries(H.fields||{}).filter(([e,t])=>![`formula`,`summary`,`autonumber`].includes(t?.type)&&!t?.readonly&&(!Se?.isLoaded||Se.checkField(H.name,e,`write`))).map(([e,t])=>({name:e,label:t?.label||e,type:t?.type||`text`,required:!!t?.required,...t?.options?{options:t.options}:{}})),dataSource:ze??e,...Ie?{extraOptionsContent:(0,Q.jsx)(cf,{policy:Le,onPolicyChange:W}),renderResultExtra:e=>(0,Q.jsx)(lf,{serverResult:e?.serverResult})}:{},onComplete:e=>{Te(e=>e+1);let t=e.importedRows,n=e.skippedRows;n>0?X.warning(_(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&X.success(_(`console.objectView.importedToast`,{count:t}))}})}),We.length>=1&&(()=>{let e=We.map(e=>{let t=Be.find(t=>(t.id||t._id)===e.id),n=!t;return{id:e.id,label:b(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)(Jo,{views:e,activeViewId:Je,onViewChange:Ze,viewTypeIcons:wf,config:{reorderable:!1,showAddButton:V,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:V?st:void 0,onRenameView:V?tt:void 0,onDeleteView:V?nt:void 0,onPinView:V?rt:void 0,onSetDefaultView:V?it:void 0,onConfigView:V?ot:void 0,onManageViews:V?()=>se(!0):void 0}),V&&(0,Q.jsx)(Ko,{open:oe,onOpenChange:se,views:e,activeViewId:Je,viewTypeIcons:wf,onRename:tt,onDelete:nt,onSetDefault:it,onSetPinned:rt,onReorder:at,onAddView:st,onConfigView:ot})]})})})(),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[bt.mode===`split`&&bt.isOpen?(0,Q.jsx)(me,{...bt,setIsOpen:e=>{e||xt()},title:v(H),onExpand:Ct,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)(Yo,{schema:Et,dataSource:e,views:Tt,activeViewId:Je,onViewChange:Ze,onEdit:e=>n?.(e),onRowClick:(e,t)=>{St(e,t)},renderListView:wt,onCreateView:$e,hideNamedViewTabs:!0,onViewAction:q})})}),typeof ve==`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:ve})})]}),children:r=>{let i=r.id||r._id;return(0,Q.jsx)(Fi,{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)(Yo,{schema:Et,dataSource:e,views:Tt,activeViewId:Je,onViewChange:Ze,onEdit:e=>n?.(e),onRowClick:(e,t)=>{St(e,t)},renderListView:wt,onCreateView:$e,hideNamedViewTabs:!0,onViewAction:q})})})}),(0,Q.jsx)(Zo,{open:h&&V,sections:[{title:`View Configuration`,data:K},{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 ${te&&V?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,Q.jsx)(Qd,{open:te&&V,onClose:()=>{R(!1),ne(`edit`)},mode:z,activeView:K,objectDef:H,recordCount:ve,onSave:he,onViewUpdate:Xe,onCreate:_e,metadataClient:F,onAfterChange:()=>Te(e=>e+1)})}),(0,Q.jsx)(Wo,{open:re&&V,onOpenChange:ie,existingLabels:We.map(e=>e.label).filter(Boolean),objectDef:H,onCreate:e=>_e(e)})]}),bt.mode!==`split`&&(0,Q.jsx)(me,{...bt,setIsOpen:e=>{e||xt()},title:v(H),onExpand:Ct,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)(Fi,{dataSource:e,objects:t,onEdit:n,objectNameOverride:H.name,recordIdOverride:i,embedded:!0})}})]}),Ee.dialogs]})}var Af=({action:e,objectName:t,record:n})=>{let{execute:r}=ee(),[i,a]=(0,$.useState)(!1),{actionLabel:o,actionConfirm:s,actionSuccess:c}=Nt(),{t:l}=G(),u=typeof n==`object`&&n?n:{},d=D(P(e.visible),u,{throwOnError:!0,label:`declared action "${e.name??e.label??`action`}" (visible)`}),f=D(P(e.disabled),u),p=(0,$.useCallback)(async()=>{if(!i){a(!0);try{let{params:i,...a}=e,d=/\/(approve|reject)$/.test(String(e.target??``)),f=d&&Array.isArray(u.decision_output_defs)&&u.decision_output_defs.length?u.decision_output_defs:d&&Array.isArray(u.decision_outputs)?u.decision_outputs.map(e=>({key:String(e)})):[],p={department:`sys_business_unit`,position:`sys_position`,team:`sys_team`},m=f.filter(e=>e.key).map(e=>{let t=e.label??e.key.split(/[_-]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `),n={name:`outputs.${e.key}`,label:t,required:!1};if(e.type===`user`)return{...n,type:`user`,multiple:e.multiple===!0,helpText:l(`actions.decisionOutput.help`)};let r=e.type?p[e.type]:void 0;return r?{...n,type:`lookup`,referenceTo:r,multiple:e.multiple===!0,helpText:l(`actions.decisionOutput.help`)}:{...n,type:`text`,helpText:l(`actions.decisionOutput.helpMultiValue`)}}),h={...a,...e.name&&{label:o(t,e.name,e.label||e.name),...a.confirmText!==void 0&&{confirmText:s(t,e.name,a.confirmText)},...a.successMessage!==void 0&&{successMessage:c(t,e.name,a.successMessage)}},objectName:t,params:{_rowRecord:n}},g=Array.isArray(i)?i:[];(g.length>0||m.length>0)&&(h.actionParams=[...g,...m]),await r(h)}finally{a(!1)}}},[e,r,i,t,n,o,s,c,l]);if(e.visible&&!d)return null;let m=typeof e.icon==`string`?e.icon:void 0,h=e.variant,g=h===`primary`?`default`:h===`danger`?`destructive`:h||`outline`,_=e.label||e.name||``,v=e.name?o(t,e.name,_):_;return(0,Q.jsxs)(J,{type:`button`,size:`sm`,variant:g,disabled:e.disabled!=null&&f||i,onClick:p,"data-testid":`declared-action-${e.name}`,children:[i&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),!i&&m?$.createElement(yo(m),{className:q(`h-4 w-4`,v&&`mr-2`)}):null,v]})};function jf({objectName:e,record:t,location:n,onDone:r,actions:i,exclude:a,className:o,label:s}){let c=ie(),{t:l}=G(),{item:u}=M(`object`,i?void 0:e),d=(0,$.useMemo)(()=>i??u?.actions??[],[i,u]),f=(0,$.useMemo)(()=>{let e=a&&a.length?new Set(a):null;return d.filter(t=>Array.isArray(t?.locations)&&t.locations.includes(n)&&!(e&&e.has(t?.name)))},[d,n,a]),p=Hi({dataSource:c,objects:u?[u]:[],objectName:e,onRefresh:r});return f.length===0?null:(0,Q.jsxs)(A,{...p.actionProviderProps,children:[(0,Q.jsxs)(`div`,{className:q(`space-y-2`,o),children:[s&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(gr,{}),(0,Q.jsx)(`div`,{className:`text-xs font-medium text-muted-foreground`,children:s})]}),(0,Q.jsx)(`div`,{role:`toolbar`,"aria-label":s||l(`common.actions`),className:`flex flex-row flex-wrap items-center gap-2`,children:f.map(n=>(0,Q.jsx)(Af,{action:n,objectName:e,record:t},n.name))})]}),p.dialogs]})}function Mf({appName:e,error:t,onRetry:n}){let{t:r}=G(),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)(or,{children:[(0,Q.jsx)(`div`,{className:`mb-2 flex justify-center text-muted-foreground`,"aria-hidden":`true`,children:i?(0,Q.jsx)(rr,{className:`h-8 w-8`}):(0,Q.jsx)(Hn,{className:`h-8 w-8`})}),(0,Q.jsx)(pr,{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)(vr,{children:i?r(`preview.empty.loadFailedDescription`,{defaultValue:`The draft overlay could not be read. Retry, or check your connection.`}):r(`preview.empty.notReadyDescription`,{defaultValue:`The build may still be running, or it may have failed before this app was staged. Check the conversation for the build status — this pane refreshes as drafts land.`})}),(0,Q.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,Q.jsxs)(J,{variant:`outline`,onClick:n,"data-testid":`preview-draft-retry`,children:[(0,Q.jsx)(On,{className:`mr-1.5 h-3.5 w-3.5`}),r(`preview.empty.retry`,{defaultValue:`Retry`})]})})]})})}var Nf=(0,$.lazy)(()=>o(()=>import(`./RecordDetailView-BzGkapku.js`).then(e=>e.n).then(e=>({default:e.RecordDetailView})),__vite__mapDeps([0]),import.meta.url)),Pf=(0,$.lazy)(()=>o(()=>import(`./DashboardView-Co21jHAg.js`).then(e=>e.t).then(e=>({default:e.DashboardView})),__vite__mapDeps([0,1]),import.meta.url)),Ff=(0,$.lazy)(()=>o(()=>import(`./PageView-C9Hwdfsl.js`).then(e=>e.t).then(e=>({default:e.PageView})),__vite__mapDeps([0]),import.meta.url)),If=(0,$.lazy)(()=>o(()=>import(`./ReportView-BPnukjAJ.js`).then(e=>e.t).then(e=>({default:e.ReportView})),__vite__mapDeps([0,1]),import.meta.url)),Lf=(0,$.lazy)(()=>o(()=>import(`./SearchResultsPage-BrU2uBVw.js`).then(e=>e.t).then(e=>({default:e.SearchResultsPage})),__vite__mapDeps([0]),import.meta.url)),Rf=(0,$.lazy)(()=>o(()=>import(`./RecordFormPage-DBo0eZ72.js`).then(e=>e.t).then(e=>({default:e.RecordFormPage})),__vite__mapDeps([0]),import.meta.url)),zf=(0,$.lazy)(()=>o(()=>import(`./ComponentNavView-BOxZS4Hn.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),Bf=(0,$.lazy)(()=>o(()=>import(`./ObjectDataPage-wTA2HFI2.js`).then(e=>({default:e.ObjectDataPage})),__vite__mapDeps([0]),import.meta.url)),Vf=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CKjub8vw.js`).then(e=>e.t).then(e=>({default:e.MetadataDirectoryPage})),__vite__mapDeps([0]),import.meta.url)),Hf=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CKjub8vw.js`).then(e=>e.t).then(e=>({default:e.StudioHomePage})),__vite__mapDeps([0]),import.meta.url)),Uf=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CKjub8vw.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceListPage})),__vite__mapDeps([0]),import.meta.url)),Wf=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CKjub8vw.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceEditPage})),__vite__mapDeps([0]),import.meta.url)),Gf=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CKjub8vw.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceHistoryPage})),__vite__mapDeps([0]),import.meta.url)),Kf=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CKjub8vw.js`).then(e=>e.t).then(e=>({default:e.MetadataDiagnosticsPage})),__vite__mapDeps([0]),import.meta.url)),qf=(0,$.lazy)(()=>o(()=>import(`./src-DTHo8Eqq.js`).then(e=>e.t).then(e=>({default:e.CreateAppPage})),__vite__mapDeps([0]),import.meta.url)),Jf=(0,$.lazy)(()=>o(()=>import(`./src-DTHo8Eqq.js`).then(e=>e.t).then(e=>({default:e.EditAppPage})),__vite__mapDeps([0]),import.meta.url)),Yf=(0,$.lazy)(()=>o(()=>import(`./src-DTHo8Eqq.js`).then(e=>e.t).then(e=>({default:e.DashboardDesignPage})),__vite__mapDeps([0]),import.meta.url)),Xf=(0,$.lazy)(()=>o(()=>import(`./MarketplacePage-C2tmfrC4.js`).then(e=>e.t).then(e=>({default:e.MarketplacePage})),__vite__mapDeps([0]),import.meta.url)),Zf=(0,$.lazy)(()=>o(()=>import(`./MarketplacePackagePage-CfD4P1wE.js`).then(e=>e.t).then(e=>({default:e.MarketplacePackagePage})),__vite__mapDeps([0]),import.meta.url)),Qf=(0,$.lazy)(()=>o(()=>import(`./MarketplaceInstalledPage-zxinYFxx.js`).then(e=>e.t).then(e=>({default:e.MarketplaceInstalledPage})),__vite__mapDeps([0]),import.meta.url));function $f({appName:e}){let{reviewSeq:t,reviewTarget:n}=ai(),r=a(),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 ep({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,r]=(0,$.useState)(`disconnected`),{user:o,getAuthConfig:u,activeOrganization:d}=T(),f=ie(),[h,g]=(0,$.useState)({});(0,$.useEffect)(()=>{let e=!1;return u().then(t=>{e||g(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[u]);let _=a(),v=i(),{appName:y}=l(),{apps:b,objects:x,loading:S,ensureType:C,error:w,refresh:E}=j(),D=ri(),{t:O}=G(),{objectLabel:k}=Nt(),[A,M]=(0,$.useState)(!C);(0,$.useEffect)(()=>{if(!C){M(!0);return}let e=!1;return Promise.all([C(`object`),C(`dashboard`),C(`report`),C(`page`)]).finally(()=>{e||M(!0)}),()=>{e=!0}},[C]);let N=b.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),P=v.pathname.endsWith(`/create-app`),ee=v.pathname.includes(`/system`),te=v.pathname.includes(`/metadata`),L=v.pathname===`/apps/setup`||v.pathname.startsWith(`/apps/setup/`),R=P||ee||te||L,ne=uo(b,y),ae=ne||(!y||R?N.find(e=>e.isDefault===!0)||N[0]:void 0),oe=!!y&&!ne&&!R,[se,le]=(0,$.useState)(`idle`);(0,$.useEffect)(()=>{if(!oe){se!==`idle`&&le(`idle`);return}se===`idle`&&!S&&!D&&(le(`checking`),Promise.resolve(E()).finally(()=>le(`done`)))},[oe,S,D,se,E]),(0,$.useEffect)(()=>{if(!ae?.name)return;let e=y??ae.name,t=`/apps/${e}/metadata/package`;(v.pathname===t||v.pathname.startsWith(`${t}/`))&&_(`/apps/${e}/component/developer/packages`,{replace:!0})},[ae?.name,y,v.pathname,_]);let[de,me]=s(),B=de.get(Si),he=de.get(Pi),ge=de.get(ji),_e=(0,$.useMemo)(()=>B&&B!==`new`?{id:B}:null,[B]),ve=(0,$.useMemo)(()=>{if(!ge)return;let e=ge.indexOf(`:`);if(!(e<=0))return{[ge.slice(0,e)]:ge.slice(e+1)}},[ge]),[ye,be]=(0,$.useState)(0),xe=!!B,V=(0,$.useCallback)(()=>{let e=new URLSearchParams(window.location.search);!e.has(`form`)&&!e.has(`formObject`)&&!e.has(`formLink`)||(e.delete(Si),e.delete(Pi),e.delete(ji),me(e,{replace:!0}))},[me]),{execute:Se,runner:Ce}=F();ue(f),z({dataSource:f??void 0,onUndo:e=>{X.info(`Undo: ${e.description}`,{duration:4e3}),be(e=>e+1),e?.objectName&&re({objectName:e.objectName,recordId:e.recordId})},onRedo:e=>{X.info(`Redo: ${e.description}`,{duration:3e3}),be(e=>e+1),e?.objectName&&re({objectName:e.objectName,recordId:e.recordId})}}),(0,$.useEffect)(()=>{Ce.registerHandler(`crud_success`,async e=>(V(),be(e=>e+1),X.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),Ce.registerHandler(`dialog_cancel`,async()=>(V(),{success:!0})),Ce.registerHandler(`navigate_create`,async e=>{let t=hi({action:e,context:Ce.getContext?.()??{},defaultBaseUrl:`/apps/${y??``}`});return t.success?(_(t.url),{success:!0}):t}),Ce.registerHandler(`navigate_edit`,async e=>{let t=_i({action:e,context:Ce.getContext?.()??{},defaultBaseUrl:`/apps/${y??``}`});return t.success?(_(t.url),{success:!0}):t})},[Ce,_,y,V]),(0,$.useEffect)(()=>{if(!f)return;let e=f.onConnectionStateChange(e=>{r(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return r(f.getConnectionState()),e},[f]);let we=v.pathname.split(`/`).filter(Boolean)[2];(we===`view`||we===`record`||we===`page`||we===`dashboard`||we===`design`)&&(we=``);let H=x.find(e=>e.name===we),U=he?x.find(e=>e.name===he):H,Te=!!he&&he!==H?.name,Ee=(0,$.useCallback)(()=>{let e=U?k(U):O(`common.record`,{defaultValue:`Record`});Se({type:`crud_success`,params:{message:_e?O(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):O(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[Se,_e,U,k,O]),De=(0,$.useCallback)(()=>{Se({type:`dialog_cancel`})},[Se]),Oe=(0,$.useCallback)(async e=>{if(Te){let e=U?k(U):O(`common.record`,{defaultValue:`Record`});X.success(_e?O(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):O(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})),V();return}if(Ee(),_e||!H)return;let t=ui({objectName:H.name,baseUrl:y?`/apps/${y}`:ae?.name?`/apps/${ae.name}`:``,pathname:v.pathname,search:window.location.search,surface:fe(H),recordId:e?.id??e?._id});if(t.kind!==`none`){if(t.kind===`detail-page`){let e=new URLSearchParams(window.location.search);e.delete(Si),e.delete(Pi),e.delete(ji);let n=e.toString(),r=`${v.pathname}${n?`?${n}`:``}`,i=k(H);_(t.url,{replace:!0,state:i?{from:{pathname:r,label:i}}:void 0});return}_(t.url,{replace:!0})}},[Ee,Te,U,_e,H,y,ae?.name,v.pathname,_,V,k,O]);Ru({pathname:v.pathname,appName:ae?.name,objects:x});let ke=e=>{let t=fi({objectDef:H,baseUrl:y?`/apps/${y}`:ae?.name?`/apps/${ae.name}`:``,record:e});if(t.kind===`page`){_(t.url);return}let n=e?.id??e?._id,r=new URLSearchParams(window.location.search);r.set(Si,n!=null&&n!==``?String(n):`new`),r.delete(Pi),r.delete(ji),me(r)},Ae=e=>{_(`/apps/${e}`)},je=(0,$.useMemo)(()=>new ce({user:o?{name:o.name,email:o.email,role:o.role??`user`}:{},app:ae||{},data:_e||{}}),[o,ae,_e]);return!f||S||!A?(0,Q.jsx)(fs,{}):D&&(oe||!ae)?(0,Q.jsx)(Mf,{appName:y,error:w,onRetry:()=>void E()}):oe?se===`done`?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(or,{children:[(0,Q.jsx)(pr,{children:O(`empty.appNotAvailable`,{defaultValue:`App not available`})}),(0,Q.jsx)(vr,{children:O(`empty.appNotAvailableDescription`,{defaultValue:`This app is not available yet — it may still be publishing. Try again in a moment.`})}),(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsx)(J,{onClick:()=>le(`idle`),"data-testid":`app-not-available-retry`,children:O(`common.retry`,{defaultValue:`Retry`})})})]})}):(0,Q.jsx)(fs,{}):!ae&&!P&&!ee&&!te?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(or,{children:[(0,Q.jsx)(pr,{children:O(`empty.noAppsConfigured`)}),(0,Q.jsx)(vr,{children:O(`empty.noAppsConfiguredDescription`)}),(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,Q.jsx)(J,{onClick:()=>_(`/create-app`),"data-testid":`create-first-app-btn`,children:O(`empty.createFirstApp`)}),(0,Q.jsx)(J,{variant:`outline`,onClick:()=>_(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:O(`empty.systemSettings`)})]})]})}):!ae&&(P||ee||te)?(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(fs,{}),children:(0,Q.jsxs)(m,{children:[(0,Q.jsx)(c,{path:`create-app`,element:(0,Q.jsx)(qf,{})}),(0,Q.jsx)(c,{path:`system/marketplace`,element:(0,Q.jsx)(Xf,{})}),(0,Q.jsx)(c,{path:`system/marketplace/installed`,element:(0,Q.jsx)(Qf,{})}),(0,Q.jsx)(c,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(Zf,{})}),(0,Q.jsx)(c,{path:`metadata`,element:(0,Q.jsx)(Vf,{})}),(0,Q.jsx)(c,{path:`metadata/_diagnostics`,element:(0,Q.jsx)(Kf,{})}),(0,Q.jsx)(c,{path:`metadata/:type`,element:(0,Q.jsx)(Uf,{})}),(0,Q.jsx)(c,{path:`metadata/:type/new`,element:(0,Q.jsx)(Wf,{createMode:!0})}),(0,Q.jsx)(c,{path:`metadata/:type/:name`,element:(0,Q.jsx)(Wf,{})}),(0,Q.jsx)(c,{path:`metadata/:type/:name/history`,element:(0,Q.jsx)(Gf,{})}),t]})}):(0,Q.jsx)(li,{user:o?{id:o.id,name:o.name,email:o.email,role:o.role??`user`,roles:o.roles,isPlatformAdmin:o.isPlatformAdmin??!1,positions:o.positions??[]}:{name:`Anonymous`,email:``,role:`guest`,isPlatformAdmin:!1,positions:[]},app:ae,data:{},features:h,children:(0,Q.jsxs)(I,{currentUserId:o?.id??null,currentOrgId:d?.id??null,children:[(0,Q.jsx)(ju,{}),(0,Q.jsxs)(wd,{activeAppName:ae.name,activeApp:ae,onAppChange:Ae,objects:x,connectionState:n,userId:o?.id,children:[(0,Q.jsx)(Td,{apps:b,activeApp:ae,objects:x,onAppChange:Ae,dataSource:f}),(0,Q.jsx)(Dd,{}),(0,Q.jsx)(Od,{}),(0,Q.jsx)($f,{appName:y}),(0,Q.jsx)(Rd,{children:(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(fs,{}),children:(0,Q.jsx)(jd,{className:`h-full`,children:(0,Q.jsxs)(m,{children:[(0,Q.jsx)(c,{path:`/`,element:(()=>{let e=ip(ae,{currentUserId:o?.id??null});return e?(0,Q.jsx)(p,{to:e,replace:!0}):(0,Q.jsx)(Hf,{})})()}),(0,Q.jsx)(c,{path:`metadata/package/*`,element:(0,Q.jsx)(p,{to:`/apps/${y??ae.name}/component/developer/packages`,replace:!0})}),(0,Q.jsxs)(c,{path:`metadata`,children:[(0,Q.jsx)(c,{index:!0,element:(0,Q.jsx)(Vf,{})}),(0,Q.jsx)(c,{path:`_diagnostics`,element:(0,Q.jsx)(Kf,{})}),(0,Q.jsx)(c,{path:`:type`,element:(0,Q.jsx)(Uf,{})}),(0,Q.jsx)(c,{path:`:type/new`,element:(0,Q.jsx)(Wf,{createMode:!0})}),(0,Q.jsx)(c,{path:`:type/:name`,element:(0,Q.jsx)(Wf,{})}),(0,Q.jsx)(c,{path:`:type/:name/history`,element:(0,Q.jsx)(Gf,{})})]}),(0,Q.jsx)(c,{path:`:objectName`,element:(0,Q.jsx)(Of,{dataSource:f,objects:x,onEdit:ke,externalRefreshKey:ye})}),(0,Q.jsx)(c,{path:`:objectName/new`,element:(0,Q.jsx)(Rf,{mode:`create`})}),(0,Q.jsx)(c,{path:`:objectName/view/:viewId`,element:(0,Q.jsx)(Of,{dataSource:f,objects:x,onEdit:ke,externalRefreshKey:ye})}),(0,Q.jsx)(c,{path:`:objectName/data`,element:(0,Q.jsx)(Bf,{dataSource:f,objects:x})}),(0,Q.jsx)(c,{path:`:objectName/record/:recordId`,element:(0,Q.jsx)(Nf,{dataSource:f,objects:x,onEdit:ke})}),(0,Q.jsx)(c,{path:`:objectName/record/:recordId/edit`,element:(0,Q.jsx)(Rf,{mode:`edit`})}),(0,Q.jsx)(c,{path:`dashboard/:dashboardName`,element:(0,Q.jsx)(Pf,{dataSource:f})}),(0,Q.jsx)(c,{path:`report/:reportName`,element:(0,Q.jsx)(If,{dataSource:f})}),(0,Q.jsx)(c,{path:`page/:pageName`,element:(0,Q.jsx)(Ff,{})}),(0,Q.jsx)(c,{path:`component/:ns/:name/*`,element:(0,Q.jsx)(zf,{})}),(0,Q.jsx)(c,{path:`component/metadata/directory`,element:(0,Q.jsx)(sp,{mode:`directory`})}),(0,Q.jsx)(c,{path:`component/metadata/resource/*`,element:(0,Q.jsx)(sp,{mode:`resource`})}),(0,Q.jsx)(c,{path:`design/dashboard/:dashboardName`,element:(0,Q.jsx)(Yf,{})}),(0,Q.jsx)(c,{path:`search`,element:(0,Q.jsx)(Lf,{})}),(0,Q.jsx)(c,{path:`create-app`,element:(0,Q.jsx)(qf,{})}),(0,Q.jsx)(c,{path:`edit-app/:editAppName`,element:(0,Q.jsx)(Jf,{})}),(0,Q.jsx)(c,{path:`system/marketplace`,element:(0,Q.jsx)(Xf,{})}),(0,Q.jsx)(c,{path:`system/marketplace/installed`,element:(0,Q.jsx)(Qf,{})}),(0,Q.jsx)(c,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(Zf,{})}),e,(0,Q.jsx)(c,{path:`:objectName/:maybeRecordId`,element:(0,Q.jsx)(cp,{})}),(0,Q.jsx)(c,{path:`*`,element:(0,Q.jsx)(lp,{})})]})})})}),U&&(0,Q.jsx)(Yr,{schema:{type:`object-form`,formType:`modal`,objectName:U.name,mode:_e?`edit`:`create`,recordId:_e?.id,...ve&&!_e?{initialValues:ve}:{},...pe(U,Te?_e?`child-edit`:`child-create`:_e?`edit`:`create`).size===`full`?{modalSize:`full`}:{},...mi(U),title:O(_e?`form.editTitle`:`form.createTitle`,{object:k(U)}),description:O(_e?`form.editDescription`:`form.createDescription`,{object:k(U)}),open:xe,onOpenChange:e=>{e||V()},layout:`vertical`,fields:U.fields?Array.isArray(U.fields)?U.fields.filter(e=>typeof e==`string`||si(e.visible,je)).map(e=>typeof e==`string`?e:e.name):Object.entries(U.fields).filter(([e,t])=>si(t.visible,je)).map(([e])=>e):[],onSuccess:Oe,onCancel:De,showSubmit:!0,showCancel:!0,submitText:_e?O(`form.update`,{defaultValue:O(`common.save`,{defaultValue:`Save`})}):O(`form.create`,{defaultValue:O(`common.create`,{defaultValue:`Create`})}),cancelText:O(`common.cancel`)},dataSource:f},`${U.name}:${_e?.id||`new`}`)]})]})})}function tp(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=np(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=tp(n.children,t);if(e!==``)return e}}return``}function np(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=Ka(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function rp(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=rp(n.children,t);if(e)return e}}}function ip(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=np(rp(r,n),t);if(e)return e}return tp(r,t)}var ap=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function op(e){return!e||ap.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function sp({mode:e}){let t=i(),n=t.pathname.replace(/\/component\/metadata\/.*$/,``);if(e===`directory`)return(0,Q.jsx)(p,{to:`${n}/metadata${t.search}${t.hash}`,replace:!0});let r=new URLSearchParams(t.search).get(`type`)??``,a=t.pathname.match(/\/component\/metadata\/resource(\/.*)?$/)?.[1]??``;return(0,Q.jsx)(p,{to:r?`${n}/metadata/${encodeURIComponent(r)}${a}${t.hash}`:`${n}/metadata${t.hash}`,replace:!0})}function cp(){let{objectName:e,maybeRecordId:t}=l(),n=i();return e&&op(t)?(0,Q.jsx)(p,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,Q.jsx)(lp,{})}function lp(){let e=a(),{t}=G();return(0,Q.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,Q.jsxs)(or,{children:[(0,Q.jsx)(pr,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Q.jsx)(vr,{children:t(`console.notFound.description`,{defaultValue:`The URL you followed does not match any view in this app.`})}),(0,Q.jsx)(`div`,{className:`mt-4`,children:(0,Q.jsx)(J,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function up({children:e}){let{setContext:t}=xi(),{t:n}=G(),r=a(),o=i(),s=(0,$.useCallback)(()=>{Tc(`${o.pathname}${o.search}`),r(`/ai`)},[o.pathname,o.search,r]),{enabled:c}=Ea();return(0,$.useEffect)(()=>{t(`home`)},[t]),(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)(pc,{variant:`home`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),c&&(0,Q.jsx)(ks,{appLabel:n(`workspace.default`,{defaultValue:`Workspace`}),onOpenDock:s})]})}var dp=19,fp=[`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`],pp=`shadow-[0_4px_10px_-2px_rgb(0_0_0/0.25),inset_0_1px_0_0_rgb(255_255_255/0.45)]`;function mp(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function hp({apps:e,favorites:t,onOpen:n,onBrowseMarketplace:r,isAdmin:i}){let{t:a}=G(),{appLabel:o}=Nt(),[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-dp,f=s?u:u.slice(0,dp);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)(Tn,{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)(J,{variant:`ghost`,size:`sm`,className:`ml-auto h-8 text-muted-foreground`,onClick:r,"data-testid":`browse-marketplace-btn`,children:[(0,Q.jsx)(Er,{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=yo(e.icon),r=o({name:e.name,label:mo(e.label,a)}),i=l.has(e.name),s=fp[mp(e.name)%fp.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:q(`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`,pp,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)(yn,{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 gp({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 _p({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 vp({pendingApprovalsCount:e,notifications:t,onOpenApprovals:n,onOpenNotification:r,t:i}){let{language:a}=G(),o=e+t.length;return(0,Q.jsx)(gp,{icon:kt,accent:!0,count:o,title:i(`home.actionCenter.title`,{defaultValue:`Needs your attention`}),children:o===0?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(_e,{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)(_p,{icon:kt,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)(Jn,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),onClick:n,testId:`home-action-approvals`}),t.map(e=>(0,Q.jsx)(_p,{icon:Fr,iconClass:`bg-primary/10 text-primary`,label:e.title,meta:Xs(e.createdAt,a),onClick:()=>r(e)},e.id))]})})}var yp={object:nr,record:hr,dashboard:$n,page:Ut},bp={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 xp({items:e,onOpen:t,t:n}){return(0,Q.jsx)(gp,{icon:Mt,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)(_p,{icon:yp[e.type]||hr,iconClass:bp[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 Sp({items:e,onViewAll:t,t:n}){let{language:r}=G();return(0,Q.jsxs)(gp,{icon:Ke,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:[Xs(e.timestamp,r),` · `,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)(Jn,{className:`h-3 w-3`})]})]})}function Cp(e=5){let t=ie(),{user:n}=T(),[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=>{if(n||!l.current)return;let r=(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);c(r)}).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,i=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));o(i)}).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`,headers:wi()}).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 wp(){let{agents:e}=Xi({apiBase:(0,$.useMemo)(()=>ua(),[])});return{aiEnabled:e.length>0,askAvailable:e.some(e=>Qi(e.name)),buildAvailable:e.some(t=>aa(e,t.name,`authoring`))}}function Tp({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)(J,{onClick:()=>n(`/ai/build`),"data-testid":`home-build-with-ai`,children:[(0,Q.jsx)(ke,{className:`mr-2 h-4 w-4`}),r(`home.buildWithAI`,{defaultValue:`Build with AI`})]}),e&&(0,Q.jsxs)(J,{variant:t?`outline`:`default`,onClick:()=>n(`/ai/ask`),"data-testid":`home-ask-ai`,children:[(0,Q.jsx)(Ve,{className:`mr-2 h-4 w-4`}),r(`home.askAI`,{defaultValue:`Ask AI`})]})]})}function Ep(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function Dp({t:e}){let t=So(),[n,r]=(0,$.useState)([]),{publishAll:i,publishing:a}=Xu(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)(Ee,{className:`h-5 w-5 shrink-0 text-indigo-600 dark:text-indigo-400`}),(0,Q.jsx)(`p`,{className:`flex-1 min-w-0 text-sm text-indigo-900 dark:text-indigo-200`,children:e(`home.pendingDrafts.message`,{count:o,defaultValue:`You have {{count}} unpublished change(s) — publish to make them live.`})}),(0,Q.jsx)(J,{size:`sm`,onClick:async()=>{(await i()).ok&&(r([]),setTimeout(()=>{try{window.location.reload()}catch{}},700))},disabled:a,"data-testid":`pending-drafts-publish`,children:a?e(`home.pendingDrafts.publishing`,{defaultValue:`Publishing…`}):e(`home.pendingDrafts.cta`,{defaultValue:`Publish`})})]})})})}function Op({t:e}){let t=a(),{hasLocalPassword:n,getAuthConfig:r}=T(),[i,o]=(0,$.useState)(!1);return(0,$.useEffect)(()=>{if(typeof localStorage<`u`&&localStorage.getItem(`os:recovery-pw-dismissed`)===`1`)return;if(typeof localStorage<`u`&&localStorage.getItem(`os:recovery-pw-first-seen`)!==`1`){try{localStorage.setItem(`os:recovery-pw-first-seen`,`1`)}catch{}return}let e=!1;return Promise.all([Promise.resolve(n?.()),Promise.resolve(r?.()).catch(()=>null)]).then(([t,n])=>{if(e)return;let r=n?.features?.ssoEnforced===!0||n?.emailPassword?.enabled===!1;t===!1&&!r&&o(!0)}).catch(()=>{}),()=>{e=!0}},[n,r]),i?(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)(qe,{className:`h-5 w-5 shrink-0 text-amber-600 dark:text-amber-400`}),(0,Q.jsx)(`p`,{className:`flex-1 min-w-0 text-sm text-amber-900 dark:text-amber-200`,children:e(`home.recoveryReminder.message`,{defaultValue:`Set a recovery password so you can still sign in if single sign-on is ever unavailable.`})}),(0,Q.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>t(`/set-password`),"data-testid":`recovery-pw-set`,children:e(`home.recoveryReminder.cta`,{defaultValue:`Set password`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{try{localStorage.setItem(`os:recovery-pw-dismissed`,`1`)}catch{}o(!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)(Se,{className:`h-4 w-4`})})]})})}):null}function kp(){let e=a(),{t}=G(),{apps:n,loading:r}=j(),{recentItems:i}=vi(),{favorites:o}=Li(),{user:s}=T(),c=g(),{pendingApprovalsCount:l,notifications:u,activities:d}=Cp(),{askAvailable:f,buildAvailable:p}=wp(),m=n.filter(e=>e.active!==!1&&e.hidden!==!0),h=i.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,6),_=(0,$.useMemo)(()=>t(Ep(new Date().getHours()),{defaultValue:`Welcome`}),[t]),v=(s?.name?.trim()||s?.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…`})})}):m.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col flex-1`,children:[(0,Q.jsx)(Dp,{t}),(0,Q.jsx)(Op,{t}),(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:c?(0,Q.jsxs)(or,{children:[(0,Q.jsx)(pr,{children:t(`home.welcome`,{product:Va().branding.productName,defaultValue:`Welcome to {{product}}`})}),(0,Q.jsx)(vr,{children:p?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.`}):f?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)(Tp,{askAvailable:f,buildAvailable:p,navigate:e,t,layout:`stack`})]}):(0,Q.jsxs)(or,{children:[(0,Q.jsx)(pr,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,Q.jsx)(vr,{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)(Dp,{t}),(0,Q.jsx)(Op,{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?`, `:``]}),v&&(0,Q.jsx)(`span`,{className:`text-primary`,children:v}),(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)(Tp,{askAvailable:f,buildAvailable:p,navigate:e,t})]}),c&&(0,Q.jsxs)(`div`,{className:`mb-6 grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>e(`/studio`),className:`flex items-start gap-3 rounded-xl border bg-card px-4 py-3.5 text-left transition-colors hover:border-primary/50 hover:bg-muted/40`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,Q.jsx)(Ne,{className:`h-4.5 w-4.5`})}),(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block text-sm font-semibold`,children:t(`home.build.title`,{defaultValue:`Build an app`})}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:t(`home.build.subtitle`,{defaultValue:`Start from scratch — design objects, forms, automations and interfaces.`})})]})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>e(`/apps/setup/system/marketplace`),className:`flex items-start gap-3 rounded-xl border bg-card px-4 py-3.5 text-left transition-colors hover:border-primary/50 hover:bg-muted/40`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,Q.jsx)(ur,{className:`h-4.5 w-4.5`})}),(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block text-sm font-semibold`,children:t(`home.template.title`,{defaultValue:`Start with a template`})}),(0,Q.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:t(`home.template.subtitle`,{defaultValue:`Install a template app from the marketplace and customize it.`})})]})]})]}),(0,Q.jsx)(hp,{apps:m,favorites:o,onOpen:t=>e(`/apps/${fo(t)??t.name}`),onBrowseMarketplace:()=>e(`/apps/setup/system/marketplace`),isAdmin:c}),(0,Q.jsx)(`div`,{className:`mb-6`,children:(0,Q.jsx)(vp,{pendingApprovalsCount:l,notifications:u,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)(xp,{items:h,onOpen:t=>e(t),t}),(0,Q.jsx)(Sp,{items:d,onViewAll:()=>e(`/apps/setup/sys_activity`),t})]})]})})]})}function Ap({children:e}){let{setContext:t}=xi();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)(pc,{variant:`orgs`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}async function jp(e){let t=await _()(`${Ga()}/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 Mp(e){let t=e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48);if(t)return t;let n=e.trim();if(!n)return``;let r=0;for(let e of n)r=Math.imul(r,31)+e.charCodeAt(0)>>>0;return`workspace-${r.toString(36).slice(0,6)}`}function Np({open:e,onOpenChange:t,onCreated:n}){let{t:r}=G(),{createOrganization:i,getAuthConfig:a}=T(),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(``),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(!1),[m,h]=(0,$.useState)(null),[g,_]=(0,$.useState)(!1);return(0,$.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||_(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,$.useEffect)(()=>{u||l(Mp(o))},[o,u]),(0,$.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,Q.jsx)(Cr,{open:e,onOpenChange:t,children:(0,Q.jsx)(ar,{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(g){h(r(`workspace.multiOrgDisabled`,{defaultValue:`Creating new organizations is disabled on this instance.`}));return}p(!0),h(null);try{let e=await i({name:o.trim(),slug:c.trim()});try{await jp({organizationId:e.id,displayName:o.trim()})}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,g,r,i,n]),children:[(0,Q.jsxs)(gn,{children:[(0,Q.jsx)(dr,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Q.jsx)(_r,{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)(U,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,Q.jsx)(Vr,{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)(U,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,Q.jsx)(Vr,{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)(Vn,{children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(J,{type:`submit`,disabled:f||!o.trim()||!c.trim(),"data-testid":`workspace-create-submit`,children:[f&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function Pp(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function Fp(){let{t:e}=G(),t=a(),[n]=s(),r=n.get(`manage`)===`1`,i=n.get(`create`)===`1`,{organizations:o,activeOrganization:c,isOrganizationsLoading:l,switchOrganization:u,getAuthConfig:d}=T(),[f,p]=(0,$.useState)(``),[m,h]=(0,$.useState)(!1),[g,_]=(0,$.useState)(null),[v,y]=(0,$.useState)(!0);(0,$.useEffect)(()=>{let e=!1;return d().then(t=>{e||t?.features?.multiOrgEnabled===!1&&y(!1)}).catch(()=>{}),()=>{e=!0}},[d]);let b=o??[],x=(0,$.useMemo)(()=>{let e=f.trim().toLowerCase();return e?b.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):b},[b,f]),S=async e=>{_(e.id);try{e.id!==c?.id&&await u(e.id),window.location.href=Vs()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),_(null)}},C=e=>{h(!1),S(e)},w=(0,$.useRef)(!1);(0,$.useEffect)(()=>{w.current||l||i||b.length===1&&(w.current=!0,r?t(`/organizations/${b[0].slug}/members`,{replace:!0}):S(b[0]))},[l,b.length,r,i]);let E=(0,$.useRef)(!1);(0,$.useEffect)(()=>{if(l)return;let e=b.length===0&&v;(i||e)&&!E.current&&(E.current=!0,h(!0))},[i,b.length,v,l]);let D=!i&&!l&&b.length===1,O=!l&&b.length===0&&v&&!E.current;return l||D||O?(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,Q.jsx)(Y,{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)(zt,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(Vr,{value:f,onChange:e=>p(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for an organization`}),className:`pl-9`,"data-testid":`organizations-search`})]}),v&&(0,Q.jsxs)(J,{onClick:()=>h(!0),"data-testid":`organizations-new`,children:[(0,Q.jsx)(Sn,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),b.length===0?(0,Q.jsxs)(or,{children:[(0,Q.jsx)(pr,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,Q.jsx)(vr,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),v&&(0,Q.jsxs)(J,{className:`mt-6`,onClick:()=>h(!0),children:[(0,Q.jsx)(Sn,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}):x.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:x.map(n=>{let r=n.id===c?.id,i=g===n.id;return(0,Q.jsxs)(`button`,{onClick:()=>S(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)(Or,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Q.jsx)(bn,{src:n.logo,alt:n.name}),(0,Q.jsx)(Hr,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:Pp(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)(Y,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,Q.jsx)(Np,{open:m,onOpenChange:h,onCreated:C})]})}function Ip(){let{t:e}=G(),t=a(),{slug:n}=l(),{organizations:i,activeOrganization:o,isOrganizationsLoading:s,switchOrganization:c}=T(),{setContext:d}=xi();(0,$.useEffect)(()=>{d(`home`)},[d]);let f=(0,$.useMemo)(()=>(i??[]).find(e=>e.slug===n)??null,[i,n]);if((0,$.useEffect)(()=>{f&&o?.id!==f.id&&c(f.id).catch(e=>{console.error(`[OrganizationLayout] switch failed`,e)})},[f,o,c]),s)return(0,Q.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center`,children:(0,Q.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})});if(!f)return(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-12 text-center`,children:[(0,Q.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.notFound`,{defaultValue:`Organization not found`})}),(0,Q.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e(`organization.notFoundDescription`,{defaultValue:`This organization does not exist or you do not have access.`})}),(0,Q.jsx)(J,{className:`mt-6`,onClick:()=>t(`/organizations`),children:e(`organization.backToList`,{defaultValue:`Back to organizations`})})]});let p=[{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)(pc,{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:[(i??[]).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)(Wn,{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:f.name}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:f.slug})]})}),(0,Q.jsx)(`nav`,{className:`mt-4 flex gap-1 -mb-px`,children:p.map(e=>(0,Q.jsx)(u,{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)(r,{context:{org:f}})})})]})}function Lp(){return d()}function Rp(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function zp({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=G(),{inviteMember:a,describeDelegableScope:o,activeMember:s}=T(),c=w(s?.role),[l,u]=(0,$.useState)(``),[d,f]=(0,$.useState)(v),[p,m]=(0,$.useState)(!1),[h,g]=(0,$.useState)(null),[_,y]=(0,$.useState)(null),[b,x]=(0,$.useState)(!1),[S,E]=(0,$.useState)(null),[D,O]=(0,$.useState)(``),[k,A]=(0,$.useState)([]);(0,$.useEffect)(()=>{t&&(u(``),f(v),g(null),y(null),x(!1),O(``),A([]))},[t]),(0,$.useEffect)(()=>{if(!t)return;let e=!1;return o?.().then(t=>{e||E(t)}).catch(()=>{}),()=>{e=!0}},[t,o]);let j=!!S&&S.placeableBusinessUnitIds.length>0&&S.assignablePositions.length>0,M=(0,$.useCallback)(async t=>{if(t.preventDefault(),l.trim()){m(!0),g(null);try{let t=await a({organizationId:e,email:l.trim(),role:d,...j&&D&&k.length>0?{businessUnitId:D,positions:k}:{}});y(t),r?.(t)}catch(e){g(e instanceof Error?e.message:`Failed to invite member`)}finally{m(!1)}}},[l,d,e,a,r,j,D,k]),N=(0,$.useCallback)(async()=>{if(!_)return;let e=Rp(_.id);try{await navigator.clipboard.writeText(e),x(!0),X.success(i(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>x(!1),2e3)}catch{X.error(i(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},[_,i]);return(0,Q.jsx)(Cr,{open:t,onOpenChange:n,children:(0,Q.jsx)(ar,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:_?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(gn,{children:[(0,Q.jsx)(dr,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Q.jsx)(_r,{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)(U,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Vr,{readOnly:!0,value:Rp(_.id),className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,Q.jsx)(J,{type:`button`,variant:`outline`,size:`icon`,onClick:N,"aria-label":`Copy`,children:b?(0,Q.jsx)(bt,{className:`h-4 w-4`}):(0,Q.jsx)(pn,{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:_.email,role:_.role})})]}),(0,Q.jsx)(Vn,{children:(0,Q.jsx)(J,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Q.jsxs)(`form`,{onSubmit:M,children:[(0,Q.jsxs)(gn,{children:[(0,Q.jsx)(dr,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Q.jsx)(_r,{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)(U,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,Q.jsx)(Vr,{id:`invite-email`,type:`email`,required:!0,placeholder:`user@example.com`,value:l,onChange:e=>u(e.target.value),autoFocus:!0,"data-testid":`invite-email-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(U,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,Q.jsxs)(Bn,{value:d,onValueChange:e=>f(e),children:[(0,Q.jsx)(yr,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,Q.jsx)(wn,{})}),(0,Q.jsx)(hn,{children:c.map(e=>(0,Q.jsx)(lr,{value:e,"data-testid":`invite-role-${e}`,children:i(C[e].key,{defaultValue:C[e].defaultValue})},e))})]})]}),j&&(0,Q.jsxs)(`div`,{className:`grid gap-3 rounded-md border border-dashed p-3`,"data-testid":`invite-placement-section`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-1`,children:[(0,Q.jsx)(U,{className:`text-sm`,children:i(`organization.invitations.placementLabel`,{defaultValue:`Placement (optional)`})}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`organization.invitations.placementDescription`,{defaultValue:`Applied when the invitation is accepted. Only units and positions you may delegate are listed.`})})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(U,{htmlFor:`invite-business-unit`,className:`text-xs`,children:i(`organization.invitations.businessUnitLabel`,{defaultValue:`Business unit`})}),(0,Q.jsxs)(Bn,{value:D,onValueChange:O,children:[(0,Q.jsx)(yr,{id:`invite-business-unit`,"data-testid":`invite-business-unit-select`,children:(0,Q.jsx)(wn,{placeholder:i(`organization.invitations.businessUnitPlaceholder`,{defaultValue:`No placement`})})}),(0,Q.jsx)(hn,{children:S.placeableBusinessUnitIds.map(e=>(0,Q.jsx)(lr,{value:e,children:e},e))})]})]}),D&&(0,Q.jsxs)(`div`,{className:`grid gap-2`,"data-testid":`invite-positions`,children:[(0,Q.jsx)(U,{className:`text-xs`,children:i(`organization.invitations.positionsLabel`,{defaultValue:`Positions`})}),(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:S.assignablePositions.map(e=>{let t=k.includes(e);return(0,Q.jsx)(J,{type:`button`,size:`sm`,variant:t?`default`:`outline`,"data-testid":`invite-position-${e}`,"aria-pressed":t,onClick:()=>A(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),children:e},e)})})]})]}),h&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`invite-error`,children:h})]}),(0,Q.jsxs)(Vn,{children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:p,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(J,{type:`submit`,disabled:p||!l.trim(),"data-testid":`invite-submit`,children:[p&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}function Bp(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function Vp(){let{t:e}=G(),{org:t}=Lp(),{getMembers:n,removeMember:r,updateMemberRole:i,activeMember:a}=T(),[o,s]=(0,$.useState)([]),[c,l]=(0,$.useState)(!0),[u,d]=(0,$.useState)(null),[f,p]=(0,$.useState)(!1),[m,h]=(0,$.useState)(null),g=(0,$.useCallback)(async()=>{l(!0),d(null);try{let e=await n(t.id);s(e)}catch(e){d(e instanceof Error?e.message:`Failed to load members`)}finally{l(!1)}},[t.id,n]);(0,$.useEffect)(()=>{g()},[g]);let _=async(n,r)=>{try{await i({organizationId:t.id,memberId:n.id,role:r}),X.success(e(`organization.members.roleUpdated`,{defaultValue:`Role updated`})),g()}catch(t){X.error(t instanceof Error?t.message:e(`organization.members.roleUpdateFailed`,{defaultValue:`Failed to update role`}))}};return c?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):u?(0,Q.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[u,(0,Q.jsx)(J,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:g,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,Q.jsxs)(`div`,{className:`space-y-4`,"data-testid":`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`}),` (`,o.length,`)`]}),(0,Q.jsx)(J,{onClick:()=>p(!0),"data-testid":`invite-member-btn`,children:e(`organization.members.inviteMember`,{defaultValue:`Invite member`})})]}),(0,Q.jsx)(gr,{}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:o.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)(Or,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,Q.jsx)(bn,{src:t.user.image,alt:t.user.name}),(0,Q.jsx)(Hr,{className:`text-xs font-medium`,children:Bp(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)(fn,{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)(Mr,{children:[(0,Q.jsx)(ot,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":`Member actions`,children:(0,Q.jsx)(br,{className:`h-4 w-4`})})}),(0,Q.jsxs)(At,{align:`end`,children:[b(a?.role,t.role).map(n=>(0,Q.jsxs)(Ae,{onClick:()=>_(t,n),disabled:t.role===n,"data-testid":`member-role-${n}`,children:[(0,Q.jsx)(Ie,{className:`mr-2 h-4 w-4`}),e(C[n].key,{defaultValue:C[n].defaultValue})]},n)),(0,Q.jsxs)(Ae,{className:`text-destructive focus:text-destructive`,onClick:()=>h(t),children:[(0,Q.jsx)(Xt,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,Q.jsx)(Nr,{open:!!m,onOpenChange:e=>!e&&h(null),children:(0,Q.jsxs)(je,{children:[(0,Q.jsxs)(xe,{children:[(0,Q.jsx)(Gn,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Q.jsx)(dt,{children:e(`organization.members.removeConfirmDescription`,{defaultValue:`This will remove {{name}} from the organization. They will lose access immediately.`,name:m?.user?.name??m?.userId??``})})]}),(0,Q.jsxs)(Zn,{children:[(0,Q.jsx)(Pe,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(jt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{if(m)try{await r({organizationId:t.id,memberIdOrUserId:m.id}),X.success(e(`organization.members.memberRemoved`,{defaultValue:`Member removed`})),h(null),g()}catch(t){X.error(t instanceof Error?t.message:e(`organization.members.removeFailed`,{defaultValue:`Failed to remove member`}))}},children:e(`organization.members.removeConfirmAction`,{defaultValue:`Remove`})})]})]})}),(0,Q.jsx)(zp,{organizationId:t.id,open:f,onOpenChange:p,onInvited:()=>g()})]})}function Hp(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function Up(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function Wp(){let{t:e}=G(),{org:t}=Lp(),{listInvitations:n,cancelInvitation:r}=T(),[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),g=(0,$.useCallback)(async()=>{s(!0),l(null);try{let e=await n(t.id);a(e)}catch(e){l(e instanceof Error?e.message:`Failed to load invitations`)}finally{s(!1)}},[t.id,n]);(0,$.useEffect)(()=>{g()},[g]);let _=async t=>{let n=Hp(t.id);try{await navigator.clipboard.writeText(n),h(t.id),X.success(e(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>h(null),2e3)}catch{X.error(e(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},v=async()=>{if(f)try{await r(f.id),X.success(e(`organization.invitations.canceled`,{defaultValue:`Invitation canceled`})),p(null),g()}catch(t){X.error(t instanceof Error?t.message:e(`organization.invitations.cancelFailed`,{defaultValue:`Failed to cancel invitation`}))}},y=u===`all`?i:i.filter(e=>e.status===u),b={all:i.length,pending:i.filter(e=>e.status===`pending`).length,accepted:i.filter(e=>e.status===`accepted`).length,rejected:i.filter(e=>e.status===`rejected`).length,canceled:i.filter(e=>e.status===`canceled`).length};return o?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):c?(0,Q.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[c,(0,Q.jsx)(J,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:g,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,Q.jsxs)(`div`,{className:`space-y-4`,"data-testid":`invitations-page`,children:[(0,Q.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.invitations.title`,{defaultValue:`Invitations`})})}),(0,Q.jsx)(`div`,{className:`flex gap-1 border-b`,children:[`all`,`pending`,`accepted`,`rejected`,`canceled`].map(t=>(0,Q.jsxs)(`button`,{onClick:()=>d(t),className:`px-3 py-2 text-sm font-medium border-b-2 transition-colors capitalize ${u===t?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[e(`organization.invitations.status.${t}`,{defaultValue:t}),b[t]>0&&(0,Q.jsx)(`span`,{className:`ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs`,children:b[t]})]},t))}),(0,Q.jsx)(gr,{}),y.length===0?(0,Q.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organization.invitations.empty`,{defaultValue:`No invitations found.`})}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:y.map(t=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`invitation-row-${t.id}`,children:[(0,Q.jsx)(Or,{className:`h-9 w-9 shrink-0`,children:(0,Q.jsx)(Hr,{className:`text-xs`,children:(0,Q.jsx)(Ye,{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)(fn,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),(0,Q.jsx)(fn,{variant:Up(t.status),className:`shrink-0 capitalize`,children:e(`organization.invitations.status.${t.status}`,{defaultValue:t.status})}),t.status===`pending`&&(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>_(t),"aria-label":`Copy invitation link`,children:m===t.id?(0,Q.jsx)(bt,{className:`h-4 w-4 text-green-600`}):(0,Q.jsx)(pn,{className:`h-4 w-4`})}),(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,onClick:()=>p(t),"aria-label":`Cancel invitation`,children:(0,Q.jsx)(Se,{className:`h-4 w-4`})})]})]},t.id))}),(0,Q.jsx)(Nr,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,Q.jsxs)(je,{children:[(0,Q.jsxs)(xe,{children:[(0,Q.jsx)(Gn,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Q.jsx)(dt,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,Q.jsxs)(Zn,{children:[(0,Q.jsx)(Pe,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(jt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:v,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function Gp(){let{t:e}=G(),{org:t}=Lp(),{user:n,getMembers:r,updateOrganization:i,deleteOrganization:o,leaveOrganization:s}=T(),c=a(),[l,u]=(0,$.useState)(t.name),[d,f]=(0,$.useState)(t.slug??``),[p,m]=(0,$.useState)(t.logo??``),[h,g]=(0,$.useState)(!1),[_,v]=(0,$.useState)(!1),y=(0,$.useRef)(null),{upload:b}=Un(),[x,S]=(0,$.useState)(null),[C,w]=(0,$.useState)(!0),[E,D]=(0,$.useState)(!1),[O,k]=(0,$.useState)(!1),[A,j]=(0,$.useState)(``),[M,N]=(0,$.useState)(!1);(0,$.useEffect)(()=>{u(t.name),f(t.slug??``),m(t.logo??``)},[t]),(0,$.useEffect)(()=>{let e=!1;return w(!0),r(t.id).then(t=>{if(e)return;let r=t.find(e=>e.userId===n?.id);S(r?.role===`owner`)}).catch(()=>{e||S(!1)}).finally(()=>{e||w(!1)}),()=>{e=!0}},[t.id,n?.id,r]);let P=(0,$.useCallback)(async n=>{n.preventDefault(),g(!0);try{await i(t.id,{name:l.trim(),slug:d.trim()||void 0,logo:p.trim()||void 0}),X.success(e(`organization.settings.saved`,{defaultValue:`Settings saved`}))}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.saveFailed`,{defaultValue:`Failed to save settings`}))}finally{g(!1)}},[t.id,l,d,p,i,e]);return C?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(Y,{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)(gr,{className:`my-4`}),x?(0,Q.jsxs)(`form`,{onSubmit:P,className:`space-y-4 max-w-md`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(U,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,Q.jsx)(Vr,{id:`org-name`,value:l,onChange:e=>u(e.target.value),required:!0,"data-testid":`settings-name-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(U,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,Q.jsx)(Vr,{id:`org-slug`,value:d,onChange:e=>f(e.target.value),"data-testid":`settings-slug-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(U,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(Or,{className:`size-16 rounded-md`,children:[p?(0,Q.jsx)(bn,{src:p,alt:l,className:`object-cover`}):null,(0,Q.jsx)(Hr,{className:`rounded-md text-base`,children:(l||`O`).slice(0,2).toUpperCase()})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`input`,{ref:y,type:`file`,accept:`image/*`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(y.current&&(y.current.value=``),n){v(!0);try{let t=await b(n);m(t.url),X.success(e(`organization.settings.logoUploaded`,{defaultValue:`Logo uploaded — save to apply`}))}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.logoUploadFailed`,{defaultValue:`Failed to upload logo`}))}finally{v(!1)}}},"data-testid":`settings-logo-file`}),(0,Q.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:_,onClick:()=>y.current?.click(),"data-testid":`settings-logo-upload-btn`,children:[_?(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Q.jsx)(ge,{className:`mr-2 h-4 w-4`}),p?e(`organization.settings.logoReplace`,{defaultValue:`Replace`}):e(`organization.settings.logoUpload`,{defaultValue:`Upload`})]}),p&&(0,Q.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>m(``),"data-testid":`settings-logo-clear-btn`,children:[(0,Q.jsx)(Se,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,Q.jsx)(Vr,{id:`org-logo`,type:`url`,value:p,onChange:e=>m(e.target.value),placeholder:`https://example.com/logo.png`,className:`text-xs`,"data-testid":`settings-logo-input`})]})]})]}),(0,Q.jsxs)(J,{type:`submit`,disabled:h,"data-testid":`settings-save-btn`,children:[h&&(0,Q.jsx)(Y,{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)(gr,{className:`my-4`}),(0,Q.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-destructive/50 bg-destructive/5 p-4`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.leaveTitle`,{defaultValue:`Leave organization`})}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.leaveDescription`,{defaultValue:`You will lose access to this organization.`})})]}),(0,Q.jsx)(J,{variant:`destructive`,size:`sm`,onClick:()=>D(!0),children:e(`organization.settings.leaveAction`,{defaultValue:`Leave`})})]}),(0,Q.jsx)(gr,{}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.deleteTitle`,{defaultValue:`Delete organization`})}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.deleteDescription`,{defaultValue:`Permanently delete this organization and all its data.`})})]}),(0,Q.jsx)(J,{variant:`destructive`,size:`sm`,onClick:()=>{j(``),k(!0)},disabled:!x,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,Q.jsx)(Nr,{open:E,onOpenChange:D,children:(0,Q.jsxs)(je,{children:[(0,Q.jsxs)(xe,{children:[(0,Q.jsx)(Gn,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Q.jsx)(dt,{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)(Zn,{children:[(0,Q.jsx)(Pe,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(jt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{N(!0);try{await s(t.id),X.success(e(`organization.settings.leftOrg`,{defaultValue:`You have left the organization`})),c(`/organizations`)}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.leaveFailed`,{defaultValue:`Failed to leave organization`}))}finally{N(!1)}},disabled:M,children:[M&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,Q.jsx)(Nr,{open:O,onOpenChange:e=>{k(e),e||j(``)},children:(0,Q.jsxs)(je,{children:[(0,Q.jsxs)(xe,{children:[(0,Q.jsx)(Gn,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Q.jsx)(dt,{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)(U,{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)(Vr,{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)(Zn,{children:[(0,Q.jsx)(Pe,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(jt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{N(!0);try{await o(t.id),X.success(e(`organization.settings.deleted`,{defaultValue:`Organization deleted`})),c(`/organizations`)}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.deleteFailed`,{defaultValue:`Failed to delete organization`}))}finally{N(!1)}},disabled:M||A!==t.slug,children:[M&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}function Kp(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function qp(e){return!Kp(e)||e.viewKind?!1:!!(e.list||e.form||e.listViews||e.formViews)}function Jp(e){if(!Kp(e))return;let t=e.config;if(Kp(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`}is({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:za}),is({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:va}),is({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:Sa}),Oa({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`}]}),Oa({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`}]}),Oa({type:`permission`,label:`Permission sets`,description:`Object-level CRUD + VAMA + lifecycle permissions, and field-level R/W. The only capability container (ADR-0090); distributed to users via positions.`,domain:`security`,EditPage:Ta,searchableFields:[`name`,`label`],listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`managedBy`,label:`Source`,width:`15%`,render:e=>e===`package`?`Package`:`Custom`}]}),Oa({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)=>Jp(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!qp(e)}),Oa({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`}]}),Oa({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`}]}),Oa({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&&`permissionSet`in e?`permission set: ${e.permissionSet}`:String(e)},{key:`groups`,label:`Groups`,width:`10%`,render:e=>Array.isArray(e)?String(e.length):`0`},{key:`description`,label:`Description`}]});var Yp=`/api/v1/cloud-connection`;async function Xp(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 Zp(){let{t:e,language:t}=G(),[n,r]=(0,$.useState)({kind:`loading`}),[i,a]=(0,$.useState)(!1),[o,s]=(0,$.useState)(!1),c=(0,$.useRef)(null),l=(0,$.useCallback)(()=>{c.current&&=(clearTimeout(c.current),null)},[]),u=(0,$.useCallback)(async()=>{try{let e=(await Xp(`${Yp}/status`))?.data??{environmentId:null,bound:!1,connection:null};r(e.bound?{kind:`bound`,status:e}:{kind:`unbound`})}catch(e){r({kind:`error`,message:e?.message??String(e)})}},[]);(0,$.useEffect)(()=>(u(),l),[u,l]);let d=(0,$.useCallback)((t,n)=>{let i=Math.max(t.interval,2)*1e3,a=async()=>{if(Date.now()-n>t.expires_in*1e3){r({kind:`error`,message:e(`cloudConnection.errors.expired`)});return}try{let n=await Xp(`${Yp}/bind/poll`,{method:`POST`,body:JSON.stringify({device_code:t.device_code})});if(n?.data?.pending){c.current=setTimeout(a,i);return}if(n?.data?.bound||n?.success){await u();return}r({kind:`error`,message:n?.error?.code??e(`cloudConnection.errors.bindFailed`)})}catch(e){r({kind:`error`,message:e?.message??String(e)})}};c.current=setTimeout(a,i)},[u,e]),f=(0,$.useCallback)(async()=>{a(!0);try{let t=(await Xp(`${Yp}/bind/start`,{method:`POST`,body:`{}`}))?.data;if(!t?.device_code||!t?.user_code)throw Error(e(`cloudConnection.errors.deviceCodeFailed`));let n=t.verification_uri_complete??t.verification_uri,i=!1;if(n)try{i=!!window.open(n,`_blank`,`noopener,width=520,height=720`)}catch{}r({kind:`waiting`,code:t,popupOpened:i}),d(t,Date.now())}catch(e){r({kind:`error`,message:e?.message??String(e)})}finally{a(!1)}},[d,e]),p=(0,$.useCallback)(async()=>{a(!0);try{await Xp(`${Yp}/unbind`,{method:`POST`,body:`{}`}),await u()}catch(e){r({kind:`error`,message:e?.message??String(e)})}finally{a(!1)}},[u]),m=(0,$.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),1500)}catch{}},[]);if(n.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)(Y,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),` `,e(`cloudConnection.checking`)]});if(n.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)(Ft,{className:`h-4 w-4`,"aria-hidden":`true`}),` `,n.message]}),(0,Q.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{l(),u()},children:e(`cloudConnection.retry`)})]});if(n.kind===`waiting`){let t=n.code.verification_uri_complete??n.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)(Y,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),n.popupOpened?e(`cloudConnection.waiting.popupOpened`):e(`cloudConnection.waiting.polling`)]}),!n.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:[e(`cloudConnection.waiting.openApproval`),` `,(0,Q.jsx)(fr,{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:n.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 m(n.code.user_code),children:[(0,Q.jsx)(pn,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e(o?`cloudConnection.waiting.copied`:`cloudConnection.waiting.copy`)]})]}),(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[e(`cloudConnection.waiting.codePrefilled`),n.popupOpened&&t?(0,Q.jsxs)(Q.Fragment,{children:[` `,(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:[e(`cloudConnection.waiting.openItHere`),` `,(0,Q.jsx)(fr,{className:`h-3 w-3`,"aria-hidden":`true`})]})]}):null]}),(0,Q.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{l(),u()},children:e(`cloudConnection.waiting.cancel`)})]})}if(n.kind===`bound`){let r=n.status.connection??{},a=r.runtime_id??n.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)(Ce,{className:`h-5 w-5 text-emerald-600`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:e(`cloudConnection.bound.title`)})]}),(0,Q.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-6 gap-y-1.5 text-sm`,children:[r.name?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.runtime`)}),(0,Q.jsx)(`dd`,{children:r.name})]}):null,r.organization_id?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.organization`)}),(0,Q.jsx)(`dd`,{className:`font-mono`,children:r.organization_id})]}):null,r.account_email?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.approvedBy`)}),(0,Q.jsx)(`dd`,{children:r.account_email})]}):null,a?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.runtimeId`)}),(0,Q.jsx)(`dd`,{className:`font-mono text-xs`,children:a})]}):null,n.status.environmentId?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.environment`)}),(0,Q.jsx)(`dd`,{className:`font-mono`,children:n.status.environmentId})]}):null,r.bound_at?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.since`)}),(0,Q.jsx)(`dd`,{children:new Date(r.bound_at).toLocaleString(t)})]}):null]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`cloudConnection.bound.privatePackages`)}),(0,Q.jsxs)(`button`,{type:`button`,disabled:i,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 p(),children:[(0,Q.jsx)(yt,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` `,e(`cloudConnection.bound.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)(Pr,{className:`h-5 w-5 text-muted-foreground`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:e(`cloudConnection.unbound.title`)})]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`cloudConnection.unbound.body`)}),(0,Q.jsxs)(`button`,{type:`button`,disabled:i,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 f(),children:[i?(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}):(0,Q.jsx)(Et,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`cloudConnection.unbound.connect`)]})]})}oe.register(`cloud-connection:panel`,()=>(0,Q.jsx)(Zp,{}),{namespace:`app-shell`,label:`Cloud Connection Panel`,category:`plugin`,inputs:[]});var Qp=``.replace(/\/$/,``);function $p(e){let t=E.get();return t?{...e,Authorization:`Bearer ${t}`}:e}function em(e){let t=Qp||(typeof window<`u`?window.location.origin:``);try{return new URL(e,t||void 0).toString()}catch{return e}}function tm({text:e,label:t}){let[n,r]=(0,$.useState)(!1);return(0,Q.jsxs)(J,{variant:`outline`,size:`sm`,onClick:async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),1500)}catch{}},children:[n?(0,Q.jsx)(bt,{className:`h-3.5 w-3.5`}):(0,Q.jsx)(pn,{className:`h-3.5 w-3.5`}),t?(0,Q.jsx)(`span`,{className:`ml-1`,children:t}):null]})}function nm({text:e}){return(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`pre`,{className:`flex-1 overflow-x-auto rounded-md bg-muted px-3 py-2 text-xs leading-relaxed`,children:(0,Q.jsx)(`code`,{children:e})}),(0,Q.jsx)(tm,{text:e})]})}function rm(){let{t:e}=G(),[t,n]=(0,$.useState)(!0),[r,i]=(0,$.useState)(null),[a,o]=(0,$.useState)(null),[s,c]=(0,$.useState)(``),[l,u]=(0,$.useState)(!1),[d,f]=(0,$.useState)(null),[p,m]=(0,$.useState)(null);(0,$.useEffect)(()=>{(async()=>{try{let e=await(await fetch(`${Qp}/api/v1/discovery`,{credentials:`include`})).json().catch(()=>({})),t=(e?.data??e)?.routes??{};i(typeof t.mcp==`string`?em(t.mcp):null)}catch(e){o(e?.message??String(e))}finally{n(!1)}})()},[]);let h=r?`${r}/skill`:null,g=(0,$.useMemo)(()=>{if(!r)return null;let e=btoa(JSON.stringify({url:r}));return`cursor://anysphere.cursor-deeplink/mcp/install?name=objectstack&config=${encodeURIComponent(e)}`},[r]);return t?(0,Q.jsxs)(`div`,{className:`space-y-3 p-1`,children:[(0,Q.jsx)(Zt,{className:`h-10 w-full`}),(0,Q.jsx)(Zt,{className:`h-40 w-full`})]}):r?(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(Dn,{children:[(0,Q.jsx)(tr,{className:`pb-2`,children:(0,Q.jsxs)(zn,{className:`flex items-center gap-2 text-base`,children:[(0,Q.jsx)(cn,{className:`h-4 w-4`}),e(`connectAgent.url.title`)]})}),(0,Q.jsxs)(Nn,{className:`space-y-3`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`connectAgent.url.body`)}),(0,Q.jsx)(nm,{text:r}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[h&&(0,Q.jsx)(J,{variant:`outline`,size:`sm`,asChild:!0,children:(0,Q.jsxs)(`a`,{href:h,download:`SKILL.md`,children:[(0,Q.jsx)(Tr,{className:`mr-1 h-3.5 w-3.5`}),e(`connectAgent.url.downloadSkill`)]})}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`connectAgent.url.skillHint`)})]})]})]}),(0,Q.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,Q.jsxs)(Dn,{children:[(0,Q.jsx)(tr,{className:`pb-2`,children:(0,Q.jsx)(zn,{className:`text-base`,children:`Claude (claude.ai / Desktop)`})}),(0,Q.jsxs)(Nn,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.claude.body`)}),(0,Q.jsx)(nm,{text:r}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`connectAgent.claude.reachability`)})]})]}),(0,Q.jsxs)(Dn,{children:[(0,Q.jsx)(tr,{className:`pb-2`,children:(0,Q.jsx)(zn,{className:`text-base`,children:`Claude Code`})}),(0,Q.jsxs)(Nn,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.claudeCode.body`)}),(0,Q.jsx)(nm,{text:`claude mcp add --transport http objectstack ${r}`}),(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.claudeCode.plugin`)}),(0,Q.jsx)(nm,{text:`claude plugin marketplace add objectstack-ai/claude-plugin`})]})]}),(0,Q.jsxs)(Dn,{children:[(0,Q.jsx)(tr,{className:`pb-2`,children:(0,Q.jsxs)(zn,{className:`flex items-center justify-between text-base`,children:[`Cursor`,g&&(0,Q.jsx)(J,{variant:`outline`,size:`sm`,asChild:!0,children:(0,Q.jsxs)(`a`,{href:g,children:[(0,Q.jsx)(fr,{className:`mr-1 h-3.5 w-3.5`}),e(`connectAgent.cursor.addButton`)]})})]})}),(0,Q.jsxs)(Nn,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.cursor.body`)}),(0,Q.jsx)(nm,{text:JSON.stringify({mcpServers:{objectstack:{url:r}}},null,2)})]})]}),(0,Q.jsxs)(Dn,{children:[(0,Q.jsx)(tr,{className:`pb-2`,children:(0,Q.jsx)(zn,{className:`text-base`,children:`VS Code / Copilot`})}),(0,Q.jsxs)(Nn,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.vscode.body`)}),(0,Q.jsx)(nm,{text:JSON.stringify({servers:{objectstack:{type:`http`,url:r}}},null,2)})]})]}),(0,Q.jsxs)(Dn,{children:[(0,Q.jsx)(tr,{className:`pb-2`,children:(0,Q.jsx)(zn,{className:`text-base`,children:`Codex CLI`})}),(0,Q.jsxs)(Nn,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.codex.body`)}),(0,Q.jsx)(nm,{text:`[mcp_servers.objectstack]\nurl = "${r}"`})]})]}),(0,Q.jsxs)(Dn,{children:[(0,Q.jsx)(tr,{className:`pb-2`,children:(0,Q.jsxs)(zn,{className:`flex items-center gap-2 text-base`,children:[(0,Q.jsx)(er,{className:`h-4 w-4`}),e(`connectAgent.apiKey.title`),(0,Q.jsx)(fn,{variant:`secondary`,children:e(`connectAgent.apiKey.badge`)})]})}),(0,Q.jsxs)(Nn,{className:`space-y-2 text-sm`,children:[(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.apiKey.body`)}),d?(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`p`,{className:`text-xs font-medium text-amber-600 dark:text-amber-400`,children:e(`connectAgent.apiKey.showOnce`,{name:d.name})}),(0,Q.jsx)(nm,{text:d.key}),(0,Q.jsx)(nm,{text:`x-api-key: ${d.key}`}),(0,Q.jsx)(J,{variant:`outline`,size:`sm`,onClick:()=>f(null),children:e(`connectAgent.apiKey.done`)})]}):(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Vr,{value:s,onChange:e=>c(e.target.value),placeholder:e(`connectAgent.apiKey.namePlaceholder`),className:`h-8 max-w-56`}),(0,Q.jsx)(J,{size:`sm`,onClick:async()=>{u(!0),m(null);try{let e=await fetch(`${Qp}/api/v1/keys`,{method:`POST`,credentials:`include`,headers:$p({"content-type":`application/json`}),body:JSON.stringify({name:s.trim()||`agent-key`})}),t=await e.json().catch(()=>({}));if(!e.ok||t?.success===!1)throw Error(t?.error?.message??t?.error??`HTTP ${e.status}`);let n=t?.data??t;f({name:n?.name??s,key:n?.key??``}),c(``)}catch(e){m(e?.message??String(e))}finally{u(!1)}},disabled:l,children:e(l?`connectAgent.apiKey.minting`:`connectAgent.apiKey.mint`)})]}),p&&(0,Q.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-destructive`,children:[(0,Q.jsx)(Ft,{className:`h-3.5 w-3.5`}),` `,p]})]})]})]})]}):(0,Q.jsx)(Dn,{children:(0,Q.jsxs)(Nn,{className:`flex items-center gap-3 py-8 text-muted-foreground`,children:[(0,Q.jsx)(Ft,{className:`h-5 w-5 shrink-0`}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`font-medium text-foreground`,children:e(`connectAgent.disabled.title`)}),(0,Q.jsx)(`div`,{className:`text-sm`,children:a||e(`connectAgent.disabled.body`)})]})]})})}oe.register(`mcp:connect-agent`,()=>(0,Q.jsx)(rm,{}),{namespace:`app-shell`,label:`Connect an Agent`,category:`plugin`,inputs:[]});var im=`/api/v1/cloud/environments/production/sso-open`,am=`/apps/cloud_control/sys_environment`;function om(e){let{activeOrganization:t}=T(),n=t?.id,r=(0,$.useMemo)(()=>_(),[]),[i,a]=(0,$.useState)({phase:`loading`});return(0,$.useEffect)(()=>{let t=!1,i=``.replace(/\/+$/,``),o=n?`?organizationId=${encodeURIComponent(n)}`:``;return(async()=>{try{let n=await r(`${i}/api/v1/cloud/environment-entitlements${o}`,{method:`GET`,credentials:`include`});if(!n.ok)throw Error(`entitlements ${n.status}`);let s=await n.json().catch(()=>null),c=s?.data??s;if(t)return;if(!c||typeof c!=`object`){a({phase:`unknown`});return}let l=c.hasProductionEnv===!0;a({phase:`ready`,hasProductionEnv:l}),l&&e&&r(`${i}${e}`,{method:`GET`,credentials:`include`}).catch(()=>{})}catch{t||a({phase:`unknown`})}})(),()=>{t=!0}},[r,n,e]),i}function sm(e){window.location.href=e}function cm({properties:e}){let{t}=G(),n=a(),r=om(e?.warmUrl),i=e?.openProductionUrl||im,o=e?.environmentsRoute||am;if(r.phase===`loading`)return(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,"data-onboarding":`loading`,children:[(0,Q.jsx)(Zt,{className:`h-11 w-44 rounded-md`}),(0,Q.jsx)(Zt,{className:`h-11 w-44 rounded-md`})]});let s=r.phase===`ready`&&!r.hasProductionEnv?t(`cloudOnboarding.hintCreate`):t(`cloudOnboarding.hintReady`),c=r.phase===`ready`&&!r.hasProductionEnv;return(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,"data-onboarding":r.phase,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,children:[c?(0,Q.jsxs)(J,{size:`lg`,onClick:()=>n(`${o}?runAction=create_environment`),children:[(0,Q.jsx)(Sn,{className:`mr-2 h-4 w-4`}),t(`cloudOnboarding.createEnvironment`)]}):(0,Q.jsxs)(J,{size:`lg`,onClick:()=>sm(i),children:[(0,Q.jsx)(Jt,{className:`mr-2 h-4 w-4`}),t(`cloudOnboarding.openProduction`)]}),(0,Q.jsxs)(J,{size:`lg`,variant:`secondary`,onClick:()=>n(o),children:[(0,Q.jsx)(Ur,{className:`mr-2 h-4 w-4`}),t(`cloudOnboarding.manageEnvironments`)]})]}),(0,Q.jsx)(`p`,{className:`max-w-xl text-center text-sm text-muted-foreground`,children:s})]})}oe.register(`cloud:onboarding-next`,e=>(0,Q.jsx)(cm,{...e}),{namespace:`app-shell`,label:`Cloud Onboarding Next-Step`,category:`plugin`,inputs:[]});var lm=`/api/v1/ai/effective-model`;function um(e,t){return e===`code-default`?t(`aiModelStatus.sourceCodeDefault`):e===`inherits-conversational`?t(`aiModelStatus.sourceInherits`):e.startsWith(`env:`)?t(`aiModelStatus.sourcePinned`,{source:e.slice(4)}):e===`unknown`?t(`aiModelStatus.sourceUnknown`):e}function dm(e){return e.startsWith(`env:`)?`default`:`secondary`}function fm(e){let t=(0,$.useMemo)(()=>_(),[]),[n,r]=(0,$.useState)({phase:`loading`});return(0,$.useEffect)(()=>{let n=!1,i=``.replace(/\/+$/,``);return(async()=>{try{let a=await t(`${i}${e}`,{method:`GET`,credentials:`include`});if(!a.ok){n||r({phase:`error`,status:a.status});return}let o=await a.json().catch(()=>null),s=o?.data??o;if(n)return;if(!s||typeof s!=`object`||!s.conversational){r({phase:`error`});return}r({phase:`ready`,report:s})}catch{n||r({phase:`error`})}})(),()=>{n=!0}},[t,e]),n}function pm({label:e,model:t,source:n,t:r}){return(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 py-2 border-b border-border last:border-b-0`,children:[(0,Q.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`code`,{className:`text-sm font-medium`,children:t??`—`}),(0,Q.jsx)(fn,{variant:dm(n),children:um(n,r)})]})]})}function mm({properties:e}){let{t}=G(),n=fm(e?.effectiveModelUrl||lm);if(n.phase===`loading`)return(0,Q.jsxs)(`div`,{className:`space-y-2`,"data-ai-model-status":`loading`,children:[(0,Q.jsx)(Zt,{className:`h-5 w-3/4 rounded`}),(0,Q.jsx)(Zt,{className:`h-10 w-full rounded`}),(0,Q.jsx)(Zt,{className:`h-10 w-full rounded`})]});if(n.phase===`error`)return(0,Q.jsx)(`div`,{className:`text-sm text-muted-foreground`,"data-ai-model-status":`error`,children:n.status?t(`aiModelStatus.readFailedWithStatus`,{status:n.status}):t(`aiModelStatus.readFailed`)});let{report:r}=n,i=Object.entries(r.overrides).filter(([,e])=>e!=null),a=t(`aiModelStatus.modelUnknown`);return(0,Q.jsxs)(`div`,{className:`space-y-4`,"data-ai-model-status":`ready`,children:[(0,Q.jsxs)(`p`,{className:`text-sm text-foreground`,"data-testid":`ai-model-summary`,children:[t(`aiModelStatus.summary`,{conversational:r.conversational.model??a,conversationalSource:um(r.conversational.source,t),structured:r.structured.model??a,structuredSource:um(r.structured.source,t)}),r.routing?(0,Q.jsxs)(Q.Fragment,{children:[` `,t(`aiModelStatus.summaryRouting`,{free:r.routing.free,paid:r.routing.paid})]}):null]}),(0,Q.jsxs)(`div`,{className:`rounded-md border border-border px-3`,children:[(0,Q.jsx)(pm,{label:t(`aiModelStatus.rowConversational`),t,model:r.conversational.model,source:r.conversational.source}),(0,Q.jsx)(pm,{label:t(`aiModelStatus.rowStructured`),t,model:r.structured.model,source:r.structured.source}),(0,Q.jsx)(pm,{label:t(`aiModelStatus.rowReasoning`),t,model:r.reasoningEffort.effective,source:r.reasoningEffort.source})]}),(0,Q.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:t(`aiModelStatus.overridesInEffect`)}),i.length===0?(0,Q.jsx)(`span`,{children:t(`aiModelStatus.noOverrides`)}):(0,Q.jsx)(`code`,{children:i.map(([e,t])=>`${e}=${t}`).join(` · `)})]}),(0,Q.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[t(`aiModelStatus.adapter`),(0,Q.jsxs)(`code`,{children:[r.adapter,r.provider?` / ${r.provider}`:``]})]})]})}oe.register(`cloud:ai-model-status`,e=>(0,Q.jsx)(mm,{...e}),{namespace:`app-shell`,label:`Cloud AI Model Status`,category:`plugin`,inputs:[]});function hm({packageId:e,onCanvasOpenChange:t}){let{user:n}=T(),r=n?.id,i=$.useMemo(()=>Rl(),[]),{agents:a,isLoading:o,error:s}=Xi({apiBase:i}),c=$.useMemo(()=>Bu(`studio-build`,{agents:a}),[a]),l=c?`${i}/agents/${encodeURIComponent(c)}/chat`:void 0,{conversationId:u,initialMessages:d}=Yc({userId:c?r:void 0,scope:c?$c({appId:e,product:Qc(c)}):void 0,apiBase:i,activeId:void 0,forceNew:!1}),f=$.useRef(null);return!o&&a.length===0?null:(0,Q.jsx)(eu,{agents:a,agentsLoading:o,agentsError:s,activeAgent:c,chatApi:l,apiBase:i,conversationId:u,editPackageId:e,initialMessages:d,pendingFirstMessageRef:f,onSent:()=>{},onShare:()=>{},showDebug:!1,onCanvasOpenChange:t},`${l??`local`}:${u??`pending`}`)}function gm({packageId:e,locale:t}){let n=a(),r=i(),o=$.useMemo(()=>Rl(),[]),s=Hu({defaultExpanded:!0,persistExpandedKey:gc,persistWidthKey:_c}),c=sn(),[l,u]=$.useState(!1),{agents:d,isLoading:f}=Xi({apiBase:o}),p=$.useCallback(e=>e?s.maximize():s.restore(),[s.maximize,s.restore]),m=$.useCallback(()=>{Tc(`${r.pathname}${r.search}`),n(`/ai/build?package=${encodeURIComponent(e)}`)},[r.pathname,r.search,n,e]);return!f&&d.length===0?null:c?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ku,{onExpand:()=>u(!0),className:`inline-flex md:hidden`}),(0,Q.jsx)(Gu,{open:l,onOpenChange:u,title:Z(`engine.studio.aiCopilot`,t),onMaximize:m,children:(0,Q.jsx)(hm,{packageId:e})})]}):s.expanded?(0,Q.jsx)(Wu,{dock:s,title:Z(`engine.studio.aiCopilot`,t),onMaximize:m,children:(0,Q.jsx)(hm,{packageId:e,onCanvasOpenChange:p})}):(0,Q.jsx)(Ku,{onExpand:s.expand})}function _m(e,t,n){return!t&&n?`properties`:t&&!n?`canvas`:e}var vm=new Map;function ym(e,t){vm.set(e,t)}function bm(e){return vm.get(e)}function xm({name:e}){return(0,Q.jsx)(k,{schema:{type:`object-view`,objectName:e}})}ym(`object`,xm);var Sm=[`read`,`create`,`update`,`delete`,`transfer`,`restore`,`purge`],Cm={grants:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,denies:`border-destructive/40 bg-destructive/10 text-destructive`,narrows:`border-amber-400/50 bg-amber-400/10 text-amber-700 dark:text-amber-300`,widens:`border-sky-400/50 bg-sky-400/10 text-sky-700 dark:text-sky-300`,neutral:`border-border bg-muted/40 text-muted-foreground`,not_applicable:`border-border bg-transparent text-muted-foreground/60`},wm={admitted:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,excluded:`border-destructive/40 bg-destructive/10 text-destructive`,not_evaluated:`border-border bg-transparent text-muted-foreground/60`},Tm={admits:`bg-emerald-500`,excludes:`bg-destructive`,neutral:`bg-muted-foreground/40`},Em=e=>{let t=e??{};return String(t.full_name||t.name||t.display_name||t.email||t.id||``)};function Dm({open:e,onOpenChange:t,defaultObject:n,packageId:r}){let i=bo(),a=ie(),o=So(),s=$.useMemo(()=>_(),[]),[c,l]=$.useState(null);$.useEffect(()=>{if(!e||!r){l(null);return}let t=!1;return(async()=>{try{let e=(await o.list(`object`,{packageId:r})??[]).map(e=>{let t=e?.item??e;return{name:String(t?.name??``),label:t?.label}}).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));t||l(e)}catch{t||l(null)}})(),()=>{t=!0}},[e,r,o]);let[u,d]=$.useState(n??``),[f,p]=$.useState(`read`),[m,h]=$.useState(null),[g,v]=$.useState(``),[y,b]=$.useState(!1),[x,S]=$.useState(!1),[C,w]=$.useState(!1),[T,E]=$.useState(null),[D,O]=$.useState(null);$.useEffect(()=>{n&&d(e=>e||n)},[n]);let k=$.useCallback(async()=>{let e=u.trim();if(e){w(!0),E(null),O(null);try{let t=``.replace(/\/+$/,``),n=await s(`${t}/api/v1/security/explain`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({object:e,operation:f,...m?{userId:m.id}:{},...g.trim()?{recordId:g.trim()}:{}})}),r=null;try{r=await n.json()}catch{}if(n.status===403){E(Z(`engine.studio.access.explain.forbidden`,i));return}if(!n.ok){let e=r?.message||r?.error||`HTTP ${n.status} ${n.statusText}`.trim();E(e);return}O(r)}catch(e){E(e?.message??String(e))}finally{w(!1)}}},[s,u,f,m,g,i]),A=e=>Z(`engine.studio.access.explain.op.${e}`,i);return(0,Q.jsx)(xt,{open:e,onOpenChange:t,children:(0,Q.jsxs)(ve,{side:`right`,className:`w-full overflow-y-auto sm:max-w-xl`,children:[(0,Q.jsxs)(Sr,{children:[(0,Q.jsxs)(ir,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(pt,{className:`h-4 w-4`}),` `,Z(`engine.studio.access.explain.title`,i)]}),(0,Q.jsx)(An,{children:Z(`engine.studio.access.explain.description`,i)})]}),(0,Q.jsxs)(`div`,{className:`mt-4 space-y-3 text-sm`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.user`,i)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>b(!0),className:`flex h-8 min-w-0 flex-1 items-center gap-2 rounded-md border bg-background px-2 text-left text-xs hover:bg-muted/60`,children:[(0,Q.jsx)(tn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:m?m.label:Z(`engine.studio.access.explain.self`,i)}),(0,Q.jsx)(Gt,{className:`h-3 w-3 shrink-0 text-muted-foreground/70`})]}),m&&(0,Q.jsx)(J,{variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>h(null),"aria-label":Z(`engine.studio.access.explain.clearUser`,i),title:Z(`engine.studio.access.explain.clearUser`,i),children:(0,Q.jsx)(Se,{className:`h-4 w-4`})})]})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`explain-object`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.object`,i)}),c&&c.length>0?(0,Q.jsxs)(`select`,{id:`explain-object`,value:u,onChange:e=>d(e.target.value),className:`h-8 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-1 focus:ring-primary`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.access.explain.objectSelect`,i)}),c.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name},e.name))]}):(0,Q.jsx)(Vr,{id:`explain-object`,value:u,onChange:e=>d(e.target.value),placeholder:Z(`engine.studio.access.explain.objectPlaceholder`,i),className:`h-8 text-xs`})]}),(0,Q.jsxs)(`div`,{className:`w-32 shrink-0 space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`explain-operation`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.operation`,i)}),(0,Q.jsx)(`select`,{id:`explain-operation`,value:f,onChange:e=>p(e.target.value),className:`h-8 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-1 focus:ring-primary`,children:Sm.map(e=>(0,Q.jsx)(`option`,{value:e,children:A(e)},e))})]})]}),(0,Q.jsxs)(`div`,{className:`space-y-1`,children:[(0,Q.jsx)(`label`,{htmlFor:`explain-record`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.record`,i)}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Vr,{id:`explain-record`,value:g,onChange:e=>v(e.target.value),placeholder:Z(`engine.studio.access.explain.recordPlaceholder`,i),className:`h-8 min-w-0 flex-1 text-xs`}),(0,Q.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,className:`h-8 shrink-0 gap-1 text-xs`,disabled:!u.trim(),onClick:()=>S(!0),title:Z(`engine.studio.access.explain.pickRecord`,i),children:[(0,Q.jsx)(Gt,{className:`h-3 w-3`}),Z(`engine.studio.access.explain.pickRecord`,i)]}),g&&(0,Q.jsx)(J,{variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>v(``),"aria-label":Z(`engine.studio.access.explain.clearRecord`,i),title:Z(`engine.studio.access.explain.clearRecord`,i),children:(0,Q.jsx)(Se,{className:`h-4 w-4`})})]})]}),(0,Q.jsxs)(J,{size:`sm`,className:`h-8 gap-1.5 text-xs`,disabled:C||!u.trim(),onClick:()=>void k(),children:[C?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Le,{className:`h-3.5 w-3.5`}),Z(C?`engine.studio.access.explain.running`:`engine.studio.access.explain.run`,i)]})]}),(0,Q.jsxs)(`div`,{className:`mt-5 space-y-4 text-sm`,children:[T&&!C&&(0,Q.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 p-3 text-xs text-destructive`,children:[(0,Q.jsx)(rr,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:Z(`engine.studio.access.explain.failed`,i)}),` — `,T]})]}),!D&&!T&&!C&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Z(`engine.studio.access.explain.empty`,i)}),D&&!C&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{"data-testid":`explain-verdict`,className:D.allowed?`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:[D.allowed?(0,Q.jsx)(Ce,{className:`h-4 w-4 shrink-0`}):(0,Q.jsx)(Kn,{className:`h-4 w-4 shrink-0`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:xo(D.allowed?`engine.studio.access.explain.allowedLine`:`engine.studio.access.explain.deniedLine`,i,{operation:A(D.operation),object:D.object})})]}),D.record&&(0,Q.jsxs)(`div`,{"data-testid":`explain-record-verdict`,className:D.record.visible?`flex items-start gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 p-3 text-emerald-700 dark:text-emerald-400`:`flex items-start gap-2 rounded-md border border-destructive/30 bg-destructive/5 p-3 text-destructive`,children:[D.record.visible?(0,Q.jsx)(Ce,{className:`mt-0.5 h-4 w-4 shrink-0`}):(0,Q.jsx)(Kn,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Q.jsxs)(`div`,{className:`min-w-0 text-xs`,children:[(0,Q.jsx)(`div`,{className:`font-medium`,children:xo(D.record.visible?`engine.studio.access.explain.recordVisibleLine`:`engine.studio.access.explain.recordHiddenLine`,i,{recordId:D.record.recordId})}),D.record.decidedBy&&(0,Q.jsxs)(`div`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.decidedBy`,i),`:`,` `,(0,Q.jsx)(`span`,{className:`font-medium text-foreground`,children:Z(`engine.studio.access.explain.layer.${D.record.decidedBy}`,i)})]})]})]}),(0,Q.jsxs)(`div`,{className:`rounded-md border bg-muted/30 p-3`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.principal`,i)}),D.principal.posture&&(0,Q.jsx)(fn,{variant:`outline`,"data-testid":`explain-posture`,className:`px-1.5 py-0 text-[10px] font-medium`,title:Z(`engine.studio.access.explain.postureHint`,i),children:Z(`engine.studio.access.explain.posture.${D.principal.posture}`,i)})]}),(0,Q.jsxs)(`p`,{className:`mt-1 truncate font-mono text-xs text-foreground`,children:[D.principal.userId??`(anonymous)`,D.principal.onBehalfOf?.userId?` ⇄ ${D.principal.onBehalfOf.userId}`:``]}),(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.positions`,i),`:`]}),(D.principal.positions??[]).map(e=>(0,Q.jsx)(fn,{variant:`outline`,className:`px-1.5 py-0 text-[10px] font-normal`,children:e},e))]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.permissionSets`,i),`:`]}),(D.principal.permissionSets??[]).map(e=>(0,Q.jsx)(fn,{variant:`secondary`,className:`px-1.5 py-0 text-[10px] font-normal`,children:e},e))]})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-2 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.layers`,i)}),(0,Q.jsx)(`ol`,{className:`space-y-2`,children:D.layers.map(e=>(0,Q.jsxs)(`li`,{className:`rounded-md border p-2.5`,"data-testid":`explain-layer-${e.layer}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium`,children:Z(`engine.studio.access.explain.layer.${e.layer}`,i)}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none ${Cm[e.verdict]??Cm.neutral}`,children:Z(`engine.studio.access.explain.verdict.${e.verdict}`,i)}),e.kernelTier&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded border border-border bg-muted/40 px-1.5 py-0.5 text-[9px] uppercase leading-none text-muted-foreground`,title:Z(`engine.studio.access.explain.kernelTierHint`,i),children:Z(`engine.studio.access.explain.kernelTier.${e.kernelTier}`,i)})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-muted-foreground`,children:e.detail}),(e.contributors??[]).length>0&&(0,Q.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1`,children:[(0,Q.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:[Z(`engine.studio.access.explain.contributors`,i),`:`]}),(e.contributors??[]).map((e,t)=>(0,Q.jsx)(fn,{variant:e.kind===`position`?`outline`:`secondary`,className:`px-1.5 py-0 text-[10px] font-normal`,title:e.via?`${e.kind} · via ${e.via}`:e.kind,children:e.name},`${e.kind}:${e.name}:${t}`))]}),e.record&&(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded border border-dashed border-border/70 bg-muted/20 p-2`,"data-testid":`explain-record-${e.layer}`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-[10px] font-medium uppercase text-muted-foreground/70`,children:Z(`engine.studio.access.explain.recordOutcome`,i)}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none ${wm[e.record.outcome]??wm.not_evaluated}`,children:Z(`engine.studio.access.explain.outcome.${e.record.outcome}`,i)}),e.record.matchesRecord!=null&&(0,Q.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:Z(e.record.matchesRecord?`engine.studio.access.explain.matches`:`engine.studio.access.explain.noMatch`,i)})]}),e.record.detail&&(0,Q.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:e.record.detail}),(e.record.rules??[]).length>0&&(0,Q.jsx)(`ul`,{className:`space-y-1`,children:(e.record.rules??[]).map((e,t)=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Tm[e.effect]??Tm.neutral}`,title:e.effect}),(0,Q.jsx)(`span`,{className:`font-medium text-foreground`,children:Z(`engine.studio.access.explain.ruleKind.${e.kind}`,i)}),(0,Q.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,title:e.name,children:e.name}),e.grants&&(0,Q.jsx)(fn,{variant:`secondary`,className:`px-1 py-0 text-[9px] font-normal`,children:e.grants}),e.via&&(0,Q.jsxs)(`span`,{className:`min-w-0 truncate text-[10px] text-muted-foreground/70`,children:[`· `,e.via]})]},`${e.kind}:${e.name}:${t}`))}),e.record.rowFilter!==void 0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-[10px] font-medium text-muted-foreground/70`,children:Z(`engine.studio.access.explain.effectiveRowFilter`,i)}),(0,Q.jsx)(`pre`,{className:`mt-0.5 overflow-x-auto rounded border bg-background/60 p-1.5 font-mono text-[10px] leading-snug`,children:JSON.stringify(e.record.rowFilter,null,2)})]})]})]},e.layer))})]}),D.operation===`read`&&D.readFilter!==void 0&&(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`mb-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.readFilter`,i)}),(0,Q.jsx)(`pre`,{className:`overflow-x-auto rounded-md border bg-muted/30 p-2 font-mono text-[11px] leading-snug`,children:JSON.stringify(D.readFilter,null,2)})]})]})]}),(0,Q.jsx)(We,{open:y,onOpenChange:e=>b(e),dataSource:a,objectName:`sys_user`,title:Z(`engine.studio.access.explain.pickUserTitle`,i),onSelect:()=>{},onSelectRecords:e=>{let t=e?.[0];t?.id!=null&&h({id:String(t.id),label:Em(t)}),b(!1)}}),u.trim()&&(0,Q.jsx)(We,{open:x,onOpenChange:e=>S(e),dataSource:a,objectName:u.trim(),title:Z(`engine.studio.access.explain.pickRecordTitle`,i),onSelect:()=>{},onSelectRecords:e=>{let t=e?.[0];t?.id!=null&&v(String(t.id)),S(!1)}})]})})}async function Om(e,t,n){let[r,i]=await Promise.all([e.list(t,{packageId:n}),e.listDrafts({packageId:n,type:t}).catch(()=>[])]),a=(r||[]).map(e=>({type:t,name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name),o=new Set(a.map(e=>e.name));for(let e of i||[]){let n=String(e?.name??``);n&&!o.has(n)&&(a.push({type:t,name:n,label:n}),o.add(n))}return a}function km(e){let[t,n]=s(),r=$.useRef(ma(t.get(ha))),i=e?.type,a=e?.name;return $.useEffect(()=>{!i||!a||n(e=>{let t=new URLSearchParams(e);return t.set(ha,ga({type:i,name:a})),t},{replace:!0})},[i,a]),r.current}function Am(e,t,n){if(!(!t||t.type!==n))return e.find(e=>e.name===t.name)}function jm(e,t,n){return{name:e,label:t,fields:{name:{type:`text`,label:n}}}}function Mm(e,t,n,r){return{name:e,label:t,type:`autolaunched`,nodes:[{id:`start`,type:`start`,label:n},{id:`end`,type:`end`,label:r}],edges:[{id:`e1`,source:`start`,target:`end`}]}}function Nm(e,t,n=[]){return{name:e,label:t,active:!0,navigation:n.map(e=>({id:`nav_${e.name}`,type:`object`,label:e.label,objectName:e.name}))}}function Pm(e,t){return{name:e,label:t,objects:{},fields:{}}}function Fm({open:e,onOpenChange:t,title:n,description:r,labelFieldLabel:i,labelPlaceholder:a,idFieldLabel:o,idPlaceholder:s,submitLabel:c,submittingLabel:l,busy:u=!1,error:d,locale:f,extra:p,onSubmit:m}){let[h,g]=$.useState(``),[_,v]=$.useState(``),[y,b]=$.useState(!1);$.useEffect(()=>{e&&(g(``),v(``),b(!1))},[e]);let x=Fo((_.trim()||h).trim()),S=!!h.trim()&&!!x&&x!==`field`,C=()=>{!S||u||m({label:h.trim(),name:x})};return(0,Q.jsx)(Cr,{open:e,onOpenChange:t,children:(0,Q.jsxs)(ar,{children:[(0,Q.jsxs)(gn,{children:[(0,Q.jsx)(dr,{children:n}),r&&(0,Q.jsx)(_r,{children:r})]}),(0,Q.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(U,{children:i}),(0,Q.jsx)(Vr,{autoFocus:!0,value:h,onChange:e=>{g(e.target.value),y||v(Lo(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&C()},placeholder:a})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(U,{children:o}),(0,Q.jsx)(Vr,{className:`font-mono`,value:_,onChange:e=>{b(!0),v(Lo(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&C()},placeholder:s})]}),p,d&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:d})]}),(0,Q.jsxs)(Vn,{children:[(0,Q.jsx)(J,{variant:`outline`,onClick:()=>t(!1),disabled:u,children:Z(`engine.studio.cancel`,f)}),(0,Q.jsx)(J,{onClick:C,disabled:!S||u,children:u?l??c:c})]})]})})}var Im=`__ungrouped__`,Lm=e=>`g:${e}`,Rm=e=>`f:${e}`,zm=e=>e.slice(2),Bm=e=>e.slice(2);function Vm({type:e}){let t=bo(),n=`mt-1 flex items-center rounded-md border bg-muted/30 px-2 text-[11px] text-muted-foreground`;switch(e){case`select`:case`radio`:case`lookup`:case`reference`:case`user`:case`multiselect`:return(0,Q.jsxs)(`div`,{className:`${n} h-7 justify-between`,children:[(0,Q.jsx)(`span`,{children:Z(e===`lookup`||e===`reference`||e===`user`?`engine.studio.designer.search`:`engine.studio.designer.select`,t)}),(0,Q.jsx)(`span`,{children:`▾`})]});case`textarea`:case`html`:case`markdown`:case`json`:case`code`:return(0,Q.jsx)(`div`,{className:`${n} h-14 items-start pt-1.5`,children:`…`});case`boolean`:case`checkbox`:case`switch`:return(0,Q.jsx)(`div`,{className:`mt-1 flex items-center`,children:(0,Q.jsx)(`span`,{className:`h-4 w-7 rounded-full bg-muted`})});case`number`:case`currency`:case`percent`:return(0,Q.jsx)(`div`,{className:`${n} h-7`,children:`0.00`});case`date`:case`datetime`:case`time`:return(0,Q.jsx)(`div`,{className:`${n} h-7`,children:Z(`engine.studio.designer.pickDate`,t)});default:return(0,Q.jsx)(`div`,{className:`${n} h-7`,children:`\xA0`})}}function Hm({entry:e,columns:t,selected:n,onSelect:r}){let i=bo(),{attributes:a,listeners:o,setNodeRef:s,transform:c,transition:l,isDragging:u}=ro({id:Rm(e.name)}),d=String(e.def.type??`text`),f=String(e.def.label??e.name),p=!!e.def.required,m=t>1&&Zr(d);return(0,Q.jsxs)(`div`,{ref:s,style:{transform:co.Transform.toString(c),transition:l},onClick:r,...a,...o,"aria-label":xo(`engine.studio.designer.fieldAria`,i,{label:f}),className:`group relative flex cursor-grab touch-none select-none items-start gap-1.5 rounded-md border bg-background px-2 py-2 active:cursor-grabbing `+(m?`col-span-full `:``)+(n?`ring-2 ring-primary`:`hover:border-foreground/25`)+(u?` opacity-40`:``),children:[(0,Q.jsx)(`span`,{className:`mt-0.5 text-muted-foreground opacity-0 group-hover:opacity-100`,children:(0,Q.jsx)(ut,{className:`h-3.5 w-3.5`})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 text-xs font-medium`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:f}),p&&(0,Q.jsx)(`span`,{className:`text-destructive`,children:`*`}),(0,Q.jsx)(`span`,{className:`ml-1 text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:d})]}),(0,Q.jsx)(Vm,{type:d})]})]})}function Um({containerId:e,title:t,fieldIds:n,columns:r,isDeclared:i,canMoveUp:a,canMoveDown:o,entryByName:s,selectedField:c,onSelectField:l,selected:u=!1,onSelect:d,onRename:f,onDelete:p,onMove:m,readOnly:h=!1}){let g=bo(),{setNodeRef:_,isOver:v}=$a({id:e});return(0,Q.jsxs)(`div`,{className:`@container rounded-lg border `+(v?`border-primary bg-primary/5`:u?`border-primary/50 bg-primary/5 ring-2 ring-primary`:`bg-muted/20`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-3 py-1.5`,children:[i&&!h?(0,Q.jsx)(`input`,{defaultValue:t,onBlur:e=>e.target.value.trim()&&e.target.value!==t&&f(e.target.value),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},className:`min-w-0 flex-1 rounded bg-transparent px-1 py-0.5 text-[13px] font-medium outline-none hover:bg-muted focus:bg-background focus:ring-1 focus:ring-primary`}):(0,Q.jsx)(`span`,{className:`flex-1 px-1 text-[13px] font-medium text-muted-foreground`,children:t}),i&&d&&(0,Q.jsx)(`button`,{type:`button`,onClick:d,"aria-label":Z(`engine.studio.designer.group.settings`,g),title:Z(`engine.studio.designer.group.settings`,g),className:`rounded p-0.5 hover:bg-muted `+(u?`text-primary`:`text-muted-foreground hover:text-foreground`),children:(0,Q.jsx)(Ur,{className:`h-3.5 w-3.5`})}),i&&!h&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,disabled:!a,onClick:()=>m(-1),"aria-label":Z(`engine.studio.designer.groupUp`,g),className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(Ze,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,disabled:!o,onClick:()=>m(1),"aria-label":Z(`engine.studio.designer.groupDown`,g),className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(on,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:p,"aria-label":Z(`engine.studio.designer.groupDelete`,g),title:Z(`engine.studio.designer.groupDeleteTitle`,g),className:`rounded p-0.5 text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,children:(0,Q.jsx)(mn,{className:`h-3.5 w-3.5`})})]})]}),(0,Q.jsx)(ao,{items:n,strategy:io,children:(0,Q.jsxs)(`div`,{ref:_,className:`min-h-[52px] p-2.5 `+(Jr(r)??`grid grid-cols-1 gap-4`),children:[n.length===0&&(0,Q.jsx)(`div`,{className:`col-span-full flex items-center justify-center rounded-md border border-dashed py-3 text-[11px] text-muted-foreground`,children:Z(`engine.studio.designer.dropHere`,g)}),n.map(e=>{let t=Bm(e),n=s.get(t);return n?(0,Q.jsx)(Hm,{entry:n,columns:r,selected:c===t,onSelect:()=>l(t)},e):null})]})})]})}function Wm({draft:e,systemFieldNames:t,onChange:n,selectedField:r,onSelectField:i,onAddField:a,selectedGroup:o,onSelectGroup:s,readOnly:c=!1}){let l=bo(),u=$.useMemo(()=>Ho(e.fields),[e.fields]),d=$.useMemo(()=>wo(e.fieldGroups),[e.fieldGroups]),f=$.useMemo(()=>new Map(u.entries.map(e=>[e.name,e])),[u]),p=$.useMemo(()=>Xr(u.entries.filter(e=>!t.has(e.name)).length),[u.entries,t]),m=$.useMemo(()=>[...d.map(e=>Lm(e.key)),Lm(Im)],[d]),h=$.useMemo(()=>{let e=new Map;for(let t of d)e.set(Lm(t.key),t.label||t.key);return e.set(Lm(Im),Z(`engine.studio.designer.ungrouped`,l)),e},[d,l]),g=$.useMemo(()=>{let e={};for(let t of m)e[t]=[];for(let n of u.entries){if(t.has(n.name))continue;let r=typeof n.def.group==`string`?n.def.group:``;e[r&&e[Lm(r)]?Lm(r):Lm(Im)].push(Rm(n.name))}return e},[u.entries,m,t]),[_,v]=$.useState(g),[y,b]=$.useState(null);$.useEffect(()=>{y||v(g)},[g,y]);let x=$.useRef(_);$.useEffect(()=>{x.current=_},[_]);let S=so(Ya(Qa,{activationConstraint:{distance:4}}),Ya(oo,{coordinateGetter:Xa})),C=$.useCallback(e=>e.startsWith(`g:`)?e:Object.keys(_).find(t=>_[t].includes(e)),[_]),w=$.useCallback(e=>{let r=[];for(let t of m){let n=zm(t);for(let i of e[t]??[]){let e=f.get(Bm(i));if(!e)continue;let t={...e.def};n===Im?delete t.group:t.group=n,r.push({name:e.name,def:t})}}let i=u.entries.filter(e=>t.has(e.name));n({fields:Oo({shape:u.shape,entries:[...i,...r]})})},[m,f,u,t,n]),T=e=>b(String(e.active.id)),E=e=>{let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=C(t),i=C(n);!r||!i||r===i||v(e=>{let a=e[r]??[],o=e[i]??[],s=n.startsWith(`g:`)?o.length:o.indexOf(n),c=s<0?o.length:s;return{...e,[r]:a.filter(e=>e!==t),[i]:[...o.slice(0,c),t,...o.slice(c)]}})},D=e=>{b(null);let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=x.current,i=e=>e.startsWith(`g:`)&&e in r?e:Object.keys(r).find(t=>r[t].includes(e)),a=i(t),o=i(n);if(!a||!o)return;let s;if(a===o){let e=r[a],i=e.indexOf(t),o=n.startsWith(`g:`)?e.length-1:e.indexOf(n);if(i<0||o<0||i===o){w(r);return}s={...r,[a]:no(e,i,o)}}else{let e=r[a].filter(e=>e!==t),i=r[o],c=n.startsWith(`g:`)?i.length:i.indexOf(n),l=c<0?i.length:c;s={...r,[a]:e,[o]:[...i.slice(0,l),t,...i.slice(l)]}}v(s),w(s)},O=()=>n({fieldGroups:Ao(d,Z(`engine.studio.designer.newGroup`,l))}),k=(e,t)=>n({fieldGroups:Do(d,e,t)}),A=(e,t)=>n({fieldGroups:ko(d,e,t)}),j=e=>n({fieldGroups:Io(d,e),fields:Oo(jo(u,e))}),M=y&&!y.startsWith(`g:`)?f.get(Bm(y)):null;return(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)($e,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.designer.hint`,l)]}),!c&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:O,className:`ml-auto inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Sn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.designer.addGroup`,l)]}),a&&(0,Q.jsxs)(`button`,{type:`button`,onClick:a,className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Sn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.addField`,l)]})]})]}),(0,Q.jsxs)(Za,{sensors:c?[]:S,collisionDetection:eo,onDragStart:T,onDragOver:E,onDragEnd:D,onDragCancel:()=>b(null),children:[(0,Q.jsx)(`div`,{className:`mx-auto flex max-w-6xl flex-col gap-3`,children:m.map(e=>{let t=e===Lm(Im);if(t&&(_[e]?.length??0)===0&&d.length>0)return null;let n=d.findIndex(t=>Lm(t.key)===e);return(0,Q.jsx)(Um,{containerId:e,title:h.get(e)??Z(`engine.studio.designer.ungrouped`,l),fieldIds:_[e]??[],columns:p,isDeclared:!t,canMoveUp:n>0,canMoveDown:n>=0&&n<d.length-1,entryByName:f,selectedField:r,onSelectField:i,selected:!t&&o===zm(e),onSelect:!t&&s?()=>s(zm(e)):void 0,onRename:t=>k(zm(e),t),onDelete:()=>j(zm(e)),onMove:t=>A(zm(e),t),readOnly:c},e)})}),(0,Q.jsx)(to,{children:M?(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border bg-background px-2 py-2 shadow-lg`,children:[(0,Q.jsx)(ut,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:String(M.def.label??M.name)})]}):null})]})]})}function Gm({draft:e,groupKey:t,onPatch:n,onClose:r,readOnly:i=!1,locale:a}){let o=$.useCallback(e=>Z(e,a),[a]),s=$.useMemo(()=>wo(e.fieldGroups),[e.fieldGroups]),c=s.find(e=>e.key===t);if(!c)return(0,Q.jsx)(Po,{kindLabel:o(`engine.studio.designer.group.kind`),title:t,onClose:r,closeLabel:o(`engine.studio.close`),children:(0,Q.jsx)(Ro,{message:o(`engine.studio.designer.group.missing`)})});let l=c.collapse??(c.collapsed?`collapsed`:c.collapsible?`expanded`:`none`),u=e=>n({fieldGroups:Eo(s,c.key,{collapse:e===`none`?void 0:e,collapsible:void 0,collapsed:void 0,defaultExpanded:void 0})});return(0,Q.jsxs)(Po,{kindLabel:o(`engine.studio.designer.group.kind`),title:c.label||c.key,onClose:r,closeLabel:o(`engine.studio.close`),children:[(0,Q.jsx)(To,{label:o(`engine.studio.designer.group.nameLabel`),value:c.label,onCommit:e=>n({fieldGroups:Eo(s,c.key,{label:e})}),disabled:i,testId:`group-label`}),(0,Q.jsx)(Vo,{label:o(`engine.studio.designer.group.collapseLabel`),value:l,onCommit:e=>u(e||`none`),disabled:i,options:[{value:`none`,label:o(`engine.studio.designer.group.collapseNone`)},{value:`expanded`,label:o(`engine.studio.designer.group.collapseExpanded`)},{value:`collapsed`,label:o(`engine.studio.designer.group.collapseCollapsed`)}]}),(0,Q.jsx)(`p`,{className:`text-[11px] leading-4 text-muted-foreground`,children:o(`engine.studio.designer.group.collapseHint`)})]})}var Km=[{value:`script`,labelKey:`engine.studio.rules.typeScript`},{value:`cross_field`,labelKey:`engine.studio.rules.typeCrossField`},{value:`state_machine`,labelKey:`engine.studio.rules.typeStateMachine`},{value:`format`,labelKey:`engine.studio.rules.typeFormat`},{value:`json_schema`,labelKey:`engine.studio.rules.typeJsonSchema`},{value:`conditional`,labelKey:`engine.studio.rules.typeConditional`}],qm=[`insert`,`update`,`delete`],Jm=[``,`url`,`email`,`phone`,`json`];function Ym(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`):[]}function Xm(e){let t=e.length+1,n=`validation_${t}`,r=new Set(e);for(;r.has(n);)n=`validation_${++t}`;return n}function Zm(e,t,n){let r={name:t,message:``,severity:`error`,active:!0};switch(e){case`script`:return{...r,type:e,condition:`false`};case`cross_field`:return{...r,type:e,condition:`false`,fields:n?[n]:[]};case`state_machine`:return{...r,type:e,field:n??``,transitions:{}};case`format`:return{...r,type:e,field:n??``};case`json_schema`:return{...r,type:e,field:n??``,schema:{}};case`conditional`:return{...r,type:e,condition:`false`,then:{type:`script`,name:`${t}_then`,message:``,condition:`false`,severity:`error`}}}}function Qm({label:e,value:t,onCommit:n,disabled:r,locale:i}){let a=$.useMemo(()=>{if(t==null)return``;try{return JSON.stringify(t,null,2)}catch{return``}},[t]),[o,s]=$.useState(a),[c,l]=$.useState(null);return $.useEffect(()=>{s(a),l(null)},[a]),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:e}),(0,Q.jsx)(`textarea`,{value:o,disabled:r,spellCheck:!1,rows:5,onChange:e=>s(e.target.value),onBlur:()=>{let e=o.trim();if(!e){l(null),n(void 0);return}try{n(JSON.parse(e)),l(null)}catch{l(Z(`engine.studio.rules.invalidJson`,i))}},className:`w-full rounded border bg-background px-2 py-1 font-mono text-[11px]`}),c&&(0,Q.jsx)(`span`,{className:`mt-1 block text-[11px] text-destructive`,children:c})]})}function $m({transitions:e,onCommit:t,disabled:n,locale:r}){let i=Object.entries(e),a=(e,n,r)=>{let a={};i.forEach(([t,i],o)=>{o===e?n&&(a[n]=r):a[t]=i}),t(a)};return(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.transitions`,r)}),i.map(([e,t],i)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`input`,{value:e,disabled:n,placeholder:Z(`engine.studio.rules.transitionFrom`,r),onChange:e=>a(i,e.target.value,t),className:`w-32 rounded border bg-background px-2 py-1 text-[12px]`}),(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,Q.jsx)(`input`,{value:t.join(`, `),disabled:n,placeholder:Z(`engine.studio.rules.transitionTo`,r),onChange:t=>a(i,e,t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)),className:`min-w-0 flex-1 rounded border bg-background px-2 py-1 text-[12px]`}),!n&&(0,Q.jsx)(`button`,{type:`button`,"aria-label":Z(`engine.studio.rules.delete`,r),onClick:()=>a(i,``,[]),className:`rounded border border-destructive/40 p-1 text-destructive hover:bg-destructive/10`,children:(0,Q.jsx)(mn,{className:`h-3 w-3`})})]},i)),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>t({...e,"":[]}),disabled:``in e,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[(0,Q.jsx)(Sn,{className:`h-3 w-3`}),` `,Z(`engine.studio.rules.addTransition`,r)]})]})}function eh({rule:e,fields:t,patch:n,disabled:r,locale:i}){let a=(e,n,a)=>(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:e}),(0,Q.jsxs)(`select`,{value:n??``,disabled:r,onChange:e=>a(e.target.value),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.rules.pickField`,i)}),t.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name},e.name))]})]}),o=(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:[Z(`engine.studio.rules.celPre`,i),(0,Q.jsx)(`b`,{children:Z(`engine.studio.rules.celTrue`,i)}),Z(`engine.studio.rules.celMid`,i),(0,Q.jsx)(`code`,{className:`rounded bg-muted px-1`,children:`false`}),Z(`engine.studio.rules.celPost`,i)]}),(0,Q.jsx)(Bo,{value:typeof e.condition==`string`?e.condition:``,onCommit:e=>n({condition:e}),fields:t,disabled:r})]});switch(e.type){case`script`:return o;case`cross_field`:{let a=Array.isArray(e.fields)?e.fields:[],s=(e,t)=>n({fields:t?[...new Set([...a,e])]:a.filter(t=>t!==e)});return(0,Q.jsxs)(Q.Fragment,{children:[o,(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.fields`,i)}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2 rounded border p-2`,children:[t.length===0&&(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.noFields`,i)}),t.map(e=>(0,Q.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px]`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:a.includes(e.name),disabled:r,onChange:t=>s(e.name,t.target.checked)}),e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name]},e.name))]})]})]})}case`state_machine`:return(0,Q.jsxs)(Q.Fragment,{children:[a(Z(`engine.studio.rules.statusField`,i),e.field,e=>n({field:e})),(0,Q.jsx)($m,{transitions:e.transitions&&typeof e.transitions==`object`?e.transitions:{},onCommit:e=>n({transitions:e}),disabled:r,locale:i})]});case`format`:return(0,Q.jsxs)(Q.Fragment,{children:[a(Z(`engine.studio.rules.field`,i),e.field,e=>n({field:e})),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.format`,i)}),(0,Q.jsx)(`select`,{value:typeof e.format==`string`?e.format:``,disabled:r,onChange:e=>n({format:e.target.value||void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:Jm.map(e=>(0,Q.jsx)(`option`,{value:e,children:e||Z(`engine.studio.rules.formatNone`,i)},e||`none`))})]}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.regex`,i)}),(0,Q.jsx)(`input`,{value:typeof e.regex==`string`?e.regex:``,disabled:r,placeholder:`^[A-Z]{2}\\\\d{4}$`,onChange:e=>n({regex:e.target.value||void 0}),className:`w-full rounded border bg-background px-2 py-1 font-mono text-[12px]`})]})]});case`json_schema`:return(0,Q.jsxs)(Q.Fragment,{children:[a(Z(`engine.studio.rules.field`,i),e.field,e=>n({field:e})),(0,Q.jsx)(Qm,{label:Z(`engine.studio.rules.jsonSchema`,i),value:e.schema,onCommit:e=>n({schema:e??{}}),disabled:r,locale:i})]});case`conditional`:return(0,Q.jsxs)(Q.Fragment,{children:[o,(0,Q.jsx)(Qm,{label:Z(`engine.studio.rules.then`,i),value:e.then,onCommit:e=>n({then:e}),disabled:r,locale:i}),(0,Q.jsx)(Qm,{label:Z(`engine.studio.rules.otherwise`,i),value:e.otherwise,onCommit:e=>n({otherwise:e}),disabled:r,locale:i})]});default:return null}}function th({draft:e,onPatch:t,disabled:n}){let r=bo(),i=$.useMemo(()=>Ym(e.validations),[e.validations]),[a,o]=$.useState(null),[s,c]=$.useState(!1),l=i.some(e=>e.name===a)?a:i[0]?.name??null,u=$.useMemo(()=>Ho(e.fields).entries.map(e=>({name:e.name,label:typeof e.def.label==`string`?e.def.label:void 0,hidden:e.def.hidden===!0})),[e.fields]),d=u.find(e=>!e.hidden)?.name??u[0]?.name,f=e=>t({validations:e}),p=(e,t)=>f(i.map(n=>n.name===e?{...n,...t}:n)),m=e=>{let t=Xm(i.map(e=>e.name??``));f([...i,Zm(e,t,d)]),o(t)},h=e=>{f(i.filter(t=>t.name!==e)),a===e&&o(null)},g=i.find(e=>e.name===l)??null,_=typeof g?.type==`string`?g.type:`script`,v=(e,t)=>{let n=i.find(t=>t.name===e);if(!n)return;let r=Zm(t,e,d);(t===`script`||t===`cross_field`||t===`conditional`)&&typeof n.condition==`string`&&(r.condition=n.condition);for(let e of[`label`,`description`,`message`,`severity`,`active`,`events`,`priority`])n[e]!==void 0&&(r[e]=n[e]);f(i.map(t=>t.name===e?r:t))};return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col rounded-lg border`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Q.jsx)(qe,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.rules.title`,r)}),(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,i.length,`)`]}),!n&&(0,Q.jsxs)(Fn,{open:s,onOpenChange:c,children:[(0,Q.jsx)(Dr,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,className:`ml-auto inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[(0,Q.jsx)(Sn,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,r),(0,Q.jsx)(on,{className:`h-3 w-3 text-muted-foreground`})]})}),(0,Q.jsxs)(un,{align:`end`,sideOffset:4,className:`w-56 p-1`,children:[(0,Q.jsx)(`p`,{className:`px-2 pb-1 pt-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.rules.newType`,r)}),Km.map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{m(e.value),c(!1)},className:`flex w-full items-center rounded-md px-2 py-1.5 text-left text-[12px] hover:bg-muted`,children:Z(e.labelKey,r)},e.value))]})]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:i.length===0?(0,Q.jsxs)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:[Z(`engine.studio.rules.none`,r),(0,Q.jsx)(`br`,{}),Z(`engine.studio.rules.explain`,r)]}):i.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(e.name??null),className:`flex w-full items-start gap-2 border-b px-3 py-2 text-left text-[12px] `+(l===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate font-medium`,children:e.label||e.name}),(0,Q.jsx)(`span`,{className:`block truncate text-[11px] text-muted-foreground`,children:e.message||Z(`engine.studio.rules.noMessage`,r)})]}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] text-primary`,children:e.type??`script`})]},e.name))})]}),(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col rounded-lg border`,children:g?(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-auto p-4`,children:[(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.type`,r)}),(0,Q.jsx)(`select`,{value:_,disabled:n,onChange:e=>v(g.name,e.target.value),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:Km.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:Z(e.labelKey,r)},e.value))})]}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.nameLabel`,r)}),(0,Q.jsx)(`input`,{value:g.name??``,disabled:n,onChange:e=>{let t=e.target.value;p(g.name,{name:t}),o(t)},className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.label`,r)}),(0,Q.jsx)(`input`,{value:g.label??``,disabled:n,onChange:e=>p(g.name,{label:e.target.value||void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.messageLabel`,r)}),(0,Q.jsx)(`input`,{value:g.message??``,disabled:n,onChange:e=>p(g.name,{message:e.target.value}),placeholder:Z(`engine.studio.rules.messagePlaceholder`,r),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,Q.jsx)(eh,{rule:g,fields:u,patch:e=>p(g.name,e),disabled:n,locale:r}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.events`,r)}),(0,Q.jsx)(`div`,{className:`flex items-center gap-4`,children:qm.map(e=>(0,Q.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:Array.isArray(g.events)?g.events.includes(e):!1,disabled:n,onChange:t=>{let n=Array.isArray(g.events)?g.events:[],r=t.target.checked?[...new Set([...n,e])]:n.filter(t=>t!==e);p(g.name,{events:r})}}),Z(`engine.studio.rules.event.${e}`,r)]},e))})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,Q.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:Z(`engine.studio.rules.severity`,r)}),(0,Q.jsxs)(`select`,{value:g.severity??`error`,disabled:n,onChange:e=>p(g.name,{severity:e.target.value}),className:`rounded border bg-background px-1.5 py-0.5 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:`error`,children:Z(`engine.studio.rules.severityError`,r)}),(0,Q.jsx)(`option`,{value:`warning`,children:`warning`}),(0,Q.jsx)(`option`,{value:`info`,children:`info`})]})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:Z(`engine.studio.rules.priority`,r)}),(0,Q.jsx)(`input`,{type:`number`,value:typeof g.priority==`number`?g.priority:``,disabled:n,onChange:e=>p(g.name,{priority:e.target.value===``?void 0:Number(e.target.value)}),className:`w-20 rounded border bg-background px-1.5 py-0.5 text-[12px]`})]}),(0,Q.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:g.active!==!1,disabled:n,onChange:e=>p(g.name,{active:e.target.checked})}),Z(`engine.studio.rules.enabled`,r)]}),!n&&(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`rule-delete`,onClick:()=>h(g.name),className:`ml-auto inline-flex items-center gap-1 rounded border border-destructive/40 px-2 py-1 text-[11px] text-destructive hover:bg-destructive/10`,children:[(0,Q.jsx)(mn,{className:`h-3 w-3`}),` `,Z(`engine.studio.rules.delete`,r)]})]})]}):(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:Z(`engine.studio.rules.pick`,r)})})]})}function nh({name:e,draft:t,onPatch:n,disabled:r,locale:i}){let a=ja(`object`),o=$.useMemo(()=>Ho(t.fields).entries,[t.fields]),s=o.filter(e=>(e.def.type??`text`)===`select`),c=typeof t.nameField==`string`?t.nameField:``,l=t.stageField,u=Array.isArray(t.highlightFields)?t.highlightFields.filter(e=>typeof e==`string`):[],d=o.filter(e=>e.def.hidden!==!0&&!u.includes(e.name)),f=typeof t.sharingModel==`string`?t.sharingModel:``,p=f===`private`?`engine.studio.settings.sharingDescPrivate`:f===`public_read`?`engine.studio.settings.sharingDescPublicRead`:f===`public_read_write`?`engine.studio.settings.sharingDescPublicReadWrite`:f===`controlled_by_parent`?`engine.studio.settings.sharingDescControlledByParent`:`engine.studio.settings.sharingDescUnset`,m=t.enable&&typeof t.enable==`object`?t.enable:{},h=(e,t)=>n({enable:{...m,[e]:t}}),g=[{key:`trackHistory`,optIn:!0,labelKey:`engine.studio.settings.capTrackHistory`,descKey:`engine.studio.settings.capTrackHistoryDesc`},{key:`files`,optIn:!0,labelKey:`engine.studio.settings.capFiles`,descKey:`engine.studio.settings.capFilesDesc`},{key:`feeds`,optIn:!1,labelKey:`engine.studio.settings.capFeeds`,descKey:`engine.studio.settings.capFeedsDesc`},{key:`activities`,optIn:!1,labelKey:`engine.studio.settings.capActivities`,descKey:`engine.studio.settings.capActivitiesDesc`},{key:`searchable`,optIn:!1,labelKey:`engine.studio.settings.capSearchable`,descKey:`engine.studio.settings.capSearchableDesc`},{key:`clone`,optIn:!1,labelKey:`engine.studio.settings.capClone`,descKey:`engine.studio.settings.capCloneDesc`}],_=typeof t.externalSharingModel==`string`?t.externalSharingModel:``,v={private:0,public_read:1,public_read_write:2},y=_ in v&&f in v&&v[_]>v[f];return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-auto`,children:[(0,Q.jsxs)(`section`,{className:`rounded-lg border`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Q.jsx)(Ur,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.basics`,i)})]}),(0,Q.jsx)(`div`,{className:`max-w-xl p-3`,children:a?(0,Q.jsx)(a,{type:`object`,name:e,draft:t,onPatch:n,readOnly:!!r,locale:i}):(0,Q.jsx)(`p`,{className:`text-[12px] text-muted-foreground`,children:Z(`engine.studio.settings.noInspector`,i)})})]}),(0,Q.jsxs)(`section`,{className:`rounded-lg border`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Q.jsx)(Ie,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.sharing`,i)}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingHint`,i)})]}),(0,Q.jsxs)(`div`,{className:`grid max-w-xl gap-2 p-3`,children:[(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingModel`,i)}),(0,Q.jsxs)(`select`,{value:f,disabled:r,"data-testid":`owd-internal-select`,onChange:e=>n(e.target.value?{sharingModel:e.target.value}:{sharingModel:void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingUnset`,i)}),(0,Q.jsx)(`option`,{value:`private`,children:Z(`engine.studio.settings.sharingPrivate`,i)}),(0,Q.jsx)(`option`,{value:`public_read`,children:Z(`engine.studio.settings.sharingPublicRead`,i)}),(0,Q.jsx)(`option`,{value:`public_read_write`,children:Z(`engine.studio.settings.sharingPublicReadWrite`,i)}),(0,Q.jsx)(`option`,{value:`controlled_by_parent`,children:Z(`engine.studio.settings.sharingControlledByParent`,i)})]})]}),(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(p,i)}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingExternal`,i)}),(0,Q.jsxs)(`select`,{value:_,disabled:r,"data-testid":`owd-external-select`,onChange:e=>n(e.target.value?{externalSharingModel:e.target.value}:{externalSharingModel:void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingExternalUnset`,i)}),(0,Q.jsx)(`option`,{value:`private`,children:Z(`engine.studio.settings.sharingPrivate`,i)}),(0,Q.jsx)(`option`,{value:`public_read`,children:Z(`engine.studio.settings.sharingPublicRead`,i)}),(0,Q.jsx)(`option`,{value:`public_read_write`,children:Z(`engine.studio.settings.sharingPublicReadWrite`,i)}),(0,Q.jsx)(`option`,{value:`controlled_by_parent`,children:Z(`engine.studio.settings.sharingControlledByParent`,i)})]})]}),(0,Q.jsx)(`p`,{"data-testid":`owd-external-desc`,className:y?`text-[11px] text-amber-600 dark:text-amber-500`:`text-[11px] text-muted-foreground`,children:Z(y?`engine.studio.settings.sharingExternalWider`:`engine.studio.settings.sharingExternalDesc`,i)})]})]}),(0,Q.jsxs)(`section`,{className:`rounded-lg border`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Q.jsx)(ke,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.semanticRoles`,i)}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.semanticHint`,i)})]}),(0,Q.jsxs)(`div`,{className:`grid max-w-xl gap-4 p-3`,children:[(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.nameField`,i)}),(0,Q.jsxs)(`select`,{value:c,disabled:r,onChange:e=>n(e.target.value?{nameField:e.target.value}:{nameField:void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.autoDerive`,i)}),o.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]})]}),(0,Q.jsxs)(`label`,{className:`block`,children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.stageField`,i)}),(0,Q.jsxs)(`select`,{value:l===!1?`__none__`:l??``,disabled:r,onChange:e=>{let t=e.target.value;n({stageField:t===`__none__`?!1:t===``?void 0:t})},className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.autoDetect`,i)}),(0,Q.jsx)(`option`,{value:`__none__`,children:Z(`engine.studio.settings.stageNone`,i)}),s.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.highlightFields`,i)}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[u.map(e=>(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[11px] text-primary`,children:[e,!r&&(0,Q.jsx)(`button`,{type:`button`,"aria-label":xo(`engine.studio.settings.removeField`,i,{field:e}),onClick:()=>n({highlightFields:u.filter(t=>t!==e)}),className:`rounded-full hover:bg-primary/20`,children:(0,Q.jsx)(Se,{className:`h-3 w-3`})})]},e)),!r&&d.length>0&&(0,Q.jsxs)(`select`,{value:``,onChange:e=>{e.target.value&&n({highlightFields:[...u,e.target.value]})},className:`rounded border bg-background px-1.5 py-0.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.addFieldOption`,i)}),d.map(e=>(0,Q.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]}),u.length===0&&(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.undeclared`,i)})]})]})]})]}),(0,Q.jsxs)(`section`,{className:`rounded-lg border`,"data-testid":`capabilities-section`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Q.jsx)(cr,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.capabilities`,i)}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.capabilitiesHint`,i)})]}),(0,Q.jsx)(`div`,{className:`grid max-w-xl gap-3 p-3`,children:g.map(({key:e,optIn:t,labelKey:n,descKey:a})=>{let o=m[e];return(0,Q.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:t?o===!0:o!==!1,disabled:r,"data-testid":`cap-${e}`,onChange:t=>h(e,t.target.checked),className:`mt-0.5`}),(0,Q.jsxs)(`span`,{className:`min-w-0`,children:[(0,Q.jsx)(`span`,{className:`block text-[12px]`,children:Z(n,i)}),(0,Q.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:Z(a,i)})]})]},e)})})]})]})}var rh={private:0,public_read:1,public_read_write:2};function ih(e,t){return!!t&&t in rh&&!!e&&e in rh&&rh[t]>rh[e]}function ah(e){for(let t of Ho(e).entries)if((t.def.type??``)===`master_detail`){let e=t.def.reference;if(typeof e==`string`&&e)return e}}function oh(e){if(!e||typeof e!=`object`)return null;let t=e;if(!(`item`in t))return null;let n=t.item;return!n||typeof n!=`object`?null:Object.keys(n).length>0?n:null}var sh=[{value:`private`,key:`engine.studio.settings.sharingPrivate`},{value:`public_read`,key:`engine.studio.settings.sharingPublicRead`},{value:`public_read_write`,key:`engine.studio.settings.sharingPublicReadWrite`},{value:`controlled_by_parent`,key:`engine.studio.settings.sharingControlledByParent`}];function ch(e,t){if(!e)return Z(`engine.studio.settings.sharingUnset`,t);let n=sh.find(t=>t.value===e);return n?Z(n.key,t):e}function lh({client:e,packageId:t,publishNonce:n=0,onDraftSaved:r,readOnly:i=!1,locale:a,highlightObject:o,onDirtyChange:s}){let[c,l]=$.useState([]),[u,d]=$.useState({}),[f,p]=$.useState(!1),[m,h]=$.useState(null),[g,_]=$.useState(!1),[v,y]=$.useState(null),b=$.useCallback(async()=>{p(!1),h(null);try{let[n,r]=await Promise.all([e.list(`object`,{packageId:t}),e.listDrafts({packageId:t,type:`object`}).catch(()=>[])]),i=new Map,a=[],o=new Set;for(let e of n||[]){let t=e.item??e,n=String(t.name??``);!n||o.has(n)||(o.add(n),a.push(n),i.set(n,String(t.label??n)))}for(let e of r||[]){let t=String(e?.name??``);!t||o.has(t)||(o.add(t),a.push(t))}let s=await Promise.all(a.map(async t=>{let[n,r]=await Promise.all([e.layered(`object`,t).catch(()=>null),e.getDraft(`object`,t).catch(()=>null)]),a=n??{},o=a.effective??a.code??{},s=oh(r),c=s?{...o,...s}:o,l=typeof c.sharingModel==`string`?c.sharingModel:``;return{name:t,label:String(c.label??i.get(t)??t),internal:l,external:typeof c.externalSharingModel==`string`?c.externalSharingModel:``,master:l===`controlled_by_parent`?ah(c.fields):void 0,hasDraft:!!s}}));s.sort((e,t)=>e.label.localeCompare(t.label)||e.name.localeCompare(t.name)),l(s),d(Object.fromEntries(s.map(e=>[e.name,{internal:e.internal,external:e.external}])))}catch(e){h(Ms(e))}finally{p(!0)}},[e,t]);$.useEffect(()=>{b()},[b,n]);let x=$.useRef({});$.useEffect(()=>{if(!o||!f)return;let e=x.current[o];e&&e.scrollIntoView({block:`center`,behavior:`smooth`})},[o,f]);let S=$.useCallback((e,t)=>{d(n=>({...n,[e]:{...n[e],...t}}))},[]),C=$.useMemo(()=>c.map(e=>{let t=u[e.name]??{internal:e.internal,external:e.external};return{row:e,edit:t,dirty:t.internal!==e.internal||t.external!==e.external,invalid:ih(t.internal,t.external)}}),[c,u]),w=C.filter(e=>e.dirty).length,T=C.some(e=>e.invalid),E=w>0,D=$.useRef(s);$.useEffect(()=>{D.current=s}),$.useEffect(()=>{D.current?.(E)},[E]),$.useEffect(()=>()=>{D.current?.(!1)},[]);let O=$.useCallback(async()=>{let n=C.filter(e=>e.dirty&&!e.invalid);if(n.length!==0){_(!0),y(null);try{for(let r of n){let[n,i]=await Promise.all([e.layered(`object`,r.row.name).catch(()=>null),e.getDraft(`object`,r.row.name).catch(()=>null)]),a=n??{},o=a.effective??a.code??{},s=oh(i),c={...o,...s??{}};r.edit.internal?c.sharingModel=r.edit.internal:delete c.sharingModel,r.edit.external?c.externalSharingModel=r.edit.external:delete c.externalSharingModel,await e.save(`object`,r.row.name,c,{mode:`draft`,packageId:t})}X.success(xo(`engine.studio.owd.saved`,a,{count:n.length})),r?.(),await b()}catch(e){y(Ms(e))}finally{_(!1)}}},[C,e,t,r,b,a]),k=!i&&!g&&w>0&&!T;return(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,"data-testid":`owd-overview`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-4 py-2.5`,children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(Ie,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`truncate text-[15px] font-semibold leading-none text-foreground`,children:Z(`engine.studio.owd.title`,a)}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[11px] text-muted-foreground`,children:Z(`engine.studio.owd.subtitle`,a)})]}),i?(0,Q.jsxs)(`span`,{title:Z(`engine.studio.pkg.readonlyHint`,a),className:`ml-auto flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(rn,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,a)]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void O(),disabled:!k,"data-testid":`owd-save`,className:`ml-auto inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[g?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Ht,{className:`h-3.5 w-3.5`}),w>0?xo(`engine.studio.owd.save`,a,{count:w}):Z(`engine.studio.owd.saveNone`,a)]})]}),(0,Q.jsx)(`p`,{className:`border-b px-4 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.owd.description`,a)}),T&&(0,Q.jsxs)(`p`,{"data-testid":`owd-invalid-banner`,className:`flex items-center gap-1.5 border-b bg-amber-400/10 px-4 py-2 text-[11px] text-amber-600 dark:text-amber-400`,children:[(0,Q.jsx)(rr,{className:`h-3.5 w-3.5 shrink-0`}),Z(`engine.studio.owd.blockedSave`,a)]}),v&&(0,Q.jsx)(`p`,{className:`border-b bg-destructive/10 px-4 py-2 text-[11px] text-destructive`,children:v}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:f?m?(0,Q.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.owd.loadFailed`,a)}):c.length===0?(0,Q.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.owd.none`,a)}):(0,Q.jsxs)(`table`,{className:`w-full border-collapse text-[12px]`,children:[(0,Q.jsx)(`thead`,{children:(0,Q.jsxs)(`tr`,{className:`border-b text-left text-[11px] uppercase tracking-wide text-muted-foreground`,children:[(0,Q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colObject`,a)}),(0,Q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colInternal`,a)}),(0,Q.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colExternal`,a)})]})}),(0,Q.jsx)(`tbody`,{children:C.map(({row:e,edit:t,dirty:n,invalid:r})=>{let s=t.internal===`controlled_by_parent`;return(0,Q.jsxs)(`tr`,{ref:t=>{x.current[e.name]=t},"data-testid":`owd-row-${e.name}`,className:`border-b align-top `+(o===e.name?`bg-primary/5`:``),children:[(0,Q.jsx)(`td`,{className:`px-2 py-2`,children:(0,Q.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),n&&(0,Q.jsx)(`span`,{"data-testid":`owd-dirty-${e.name}`,className:`rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.owd.unsaved`,a)}),e.hasDraft&&!n&&(0,Q.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:Z(`engine.studio.unpublishedDraft`,a)})]}),(0,Q.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.name})]})}),(0,Q.jsx)(`td`,{className:`px-2 py-2`,children:i?(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:ch(t.internal,a)}):(0,Q.jsxs)(`select`,{value:t.internal,"data-testid":`owd-internal-${e.name}`,onChange:t=>S(e.name,{internal:t.target.value}),className:`w-full min-w-[13rem] rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingUnset`,a)}),sh.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:Z(e.key,a)},e.value))]})}),(0,Q.jsx)(`td`,{className:`px-2 py-2`,children:s?(0,Q.jsxs)(`span`,{"data-testid":`owd-master-${e.name}`,title:Z(`engine.studio.owd.masterTip`,a),className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Q.jsx)(Oe,{className:`h-3.5 w-3.5`}),e.master?xo(`engine.studio.owd.byParent`,a,{master:e.master}):Z(`engine.studio.owd.byParentUnknown`,a)]}):i?(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:ch(t.external,a)}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`select`,{value:t.external,"data-testid":`owd-external-${e.name}`,onChange:t=>S(e.name,{external:t.target.value}),className:`w-full min-w-[13rem] rounded border bg-background px-2 py-1 text-[12px] `+(r?`border-amber-500`:``),children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingExternalUnset`,a)}),sh.filter(e=>e.value!==`controlled_by_parent`).map(e=>(0,Q.jsx)(`option`,{value:e.value,children:Z(e.key,a)},e.value))]}),r&&(0,Q.jsx)(`span`,{"data-testid":`owd-error-${e.name}`,className:`mt-1 block text-[11px] text-amber-600 dark:text-amber-500`,children:Z(`engine.studio.owd.widerError`,a)})]})})]},e.name)})})]}):(0,Q.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.loading`,a)})})]})}var uh={GET:`bg-emerald-500/15 text-emerald-600 dark:text-emerald-300`,POST:`bg-sky-500/15 text-sky-600 dark:text-sky-300`,PATCH:`bg-amber-500/15 text-amber-600 dark:text-amber-300`,DELETE:`bg-destructive/15 text-destructive`};function dh(e){switch(e){case`number`:case`currency`:case`percent`:return 0;case`boolean`:return!0;case`date`:return`2024-01-01`;case`datetime`:return`2024-01-01T00:00:00Z`;case`lookup`:case`master_detail`:return`related_record_id`;default:return`string`}}function fh(e){let t=Ho(e).entries,n=new Set([`autonumber`,`formula`,`summary`]),r={};for(let e of t){let t=e.def;if(!n.has(String(t.type))&&!(t.readonly===!0||t.hidden===!0)&&(r[e.name]=dh(t.type),Object.keys(r).length>=8))break}return r}function ph({name:e,draft:t}){let n=bo(),[r,i]=$.useState(null),a=typeof window<`u`?window.location.origin:`https://your-host`,o=`/api/v1/data/${e}`,s=$.useMemo(()=>fh(t.fields),[t.fields]),c=JSON.stringify(s,null,2),l=[{id:`list`,method:`GET`,path:o,desc:Z(`engine.studio.api.list`,n)},{id:`create`,method:`POST`,path:o,desc:Z(`engine.studio.api.create`,n),body:!0},{id:`get`,method:`GET`,path:`${o}/{id}`,desc:Z(`engine.studio.api.get`,n)},{id:`update`,method:`PATCH`,path:`${o}/{id}`,desc:Z(`engine.studio.api.update`,n),body:!0},{id:`delete`,method:`DELETE`,path:`${o}/{id}`,desc:Z(`engine.studio.api.delete`,n)}],u=e=>{let t=[`curl -X ${e.method} '${a}${e.path}'`,` -H 'Authorization: Bearer <token>'`];return e.body&&(t.push(` -H 'Content-Type: application/json'`),t.push(` -d '${JSON.stringify(s)}'`)),t.join(` \\
9
- `)},d=(e,t)=>{navigator.clipboard?.writeText(t).then(()=>{i(e),setTimeout(()=>i(t=>t===e?null:t),1500)})};return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-auto`,children:[(0,Q.jsx)(`p`,{className:`text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.api.subtitle`,n)}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>(0,Q.jsx)(`div`,{className:`rounded-lg border`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,Q.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold `+uh[e.method],children:e.method}),(0,Q.jsx)(`code`,{className:`min-w-0 flex-1 truncate text-[12px]`,children:e.path}),(0,Q.jsx)(`span`,{className:`hidden shrink-0 text-[11px] text-muted-foreground sm:inline`,children:e.desc}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>d(e.id,u(e)),title:Z(`engine.studio.api.copyCurl`,n),className:`inline-flex shrink-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[r===e.id?(0,Q.jsx)(bt,{className:`h-3 w-3 text-emerald-500`}):(0,Q.jsx)(pn,{className:`h-3 w-3`}),r===e.id?Z(`engine.studio.api.copied`,n):`cURL`]})]})},e.id))}),Object.keys(s).length>0&&(0,Q.jsxs)(`div`,{className:`rounded-lg border`,children:[(0,Q.jsx)(`header`,{className:`border-b px-3 py-1.5 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.api.body`,n)}),(0,Q.jsx)(`pre`,{className:`overflow-auto px-3 py-2 text-[11px] leading-5`,children:c})]})]})}function mh(e){if(!e||typeof e!=`object`||!(`item`in e))return null;let t=e.item;return t&&typeof t==`object`&&Object.keys(t).length>0?t:null}function hh(e,t){let n=e.object;return n===`*`?!0:typeof n==`string`?n===t:Array.isArray(n)?n.includes(t)||n.includes(`*`):!1}function gh(e,t){let n=(e||`hook`).replace(/[^a-z0-9_]/gi,`_`).toLowerCase(),r=new Set(t),i=t.length+1,a=`${n}_hook_${i}`;for(;r.has(a);)a=`${n}_hook_${++i}`;return a}function _h({objectName:e,packageId:t,disabled:n,hookSchema:r}){let i=bo(),a=So(),o=ja(`hook`),[s,c]=$.useState([]),[l,u]=$.useState(!0),[d,f]=$.useState(null),[p,m]=$.useState(null),[h,g]=$.useState(null),[_,v]=$.useState(!1),[y,b]=$.useState(!1),[x,S]=$.useState(0);$.useEffect(()=>{let n=!1;return u(!0),f(null),(async()=>{try{let[r,i]=await Promise.all([a.list(`hook`,{packageId:t}),a.listDrafts({packageId:t,type:`hook`}).catch(()=>[])]),o=(i||[]).map(e=>String(e.name??``)).filter(Boolean),s=await Promise.all(o.map(e=>a.getDraft(`hook`,e).then(mh).catch(()=>null)));if(n)return;let l=new Map;for(let t of r||[])t?.name&&hh(t,e)&&l.set(String(t.name),t);o.forEach((t,n)=>{let r=s[n];r&&hh(r,e)&&l.set(t,r)}),c([...l.values()])}catch(e){n||f(Ms(e))}finally{n||u(!1)}})(),()=>{n=!0}},[a,t,e,x]),$.useEffect(()=>{let e=s.find(e=>e.name===p)??null;g(e?{...e}:null),v(!1)},[p,s]);let C=$.useCallback(async()=>{if(h?.name){b(!0),f(null);try{await a.save(`hook`,String(h.name),h,{mode:`draft`,packageId:t}),X.success(xo(`engine.studio.hooks.saved`,i,{label:String(h.label||h.name)})),v(!1),S(e=>e+1)}catch(e){f(Ms(e))}finally{b(!1)}}},[a,h,t,i]),w=$.useCallback(async()=>{let n=gh(e,s.map(e=>String(e.name??``))),r={name:n,label:Z(`engine.studio.hooks.newLabel`,i),object:e,events:[`beforeInsert`],body:{language:`js`,source:`return;`},priority:100,async:!1};b(!0),f(null);try{await a.save(`hook`,n,r,{mode:`draft`,packageId:t}),S(e=>e+1),m(n)}catch(e){f(Ms(e))}finally{b(!1)}},[a,e,s,t,i]);return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col rounded-lg border`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Q.jsx)(Wt,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.data.tab.hooks`,i)}),(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,s.length,`)`]}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:w,disabled:y,className:`ml-auto inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[(0,Q.jsx)(Sn,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,i)]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:l?(0,Q.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,i)}):s.length===0?(0,Q.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.hooks.none`,i)}):s.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>m(e.name??null),className:`flex w-full items-center gap-2 border-b px-3 py-2 text-left text-[12px] `+(p===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,Q.jsx)(Wt,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.label||e.name}),e.async&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] text-primary`,children:Z(`engine.studio.hooks.async`,i)})]},String(e.name)))})]}),(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden rounded-lg border`,children:[d&&(0,Q.jsx)(`div`,{className:`border-b border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive whitespace-pre-line`,children:d}),h?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b px-3 py-1.5`,children:[(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[12px] font-medium`,children:String(h.label||h.name)}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:C,disabled:!_||y,className:`inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[y?(0,Q.jsx)(Y,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Ht,{className:`h-3 w-3`}),Z(`engine.studio.hooks.save`,i)]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:o?(0,Q.jsx)(o,{type:`hook`,name:String(h.name??``),draft:h,onPatch:e=>{g(t=>({...t,...e})),v(!0)},readOnly:!!n,locale:i,serverSchema:r}):(0,Q.jsx)(`div`,{className:`p-3`,children:(0,Q.jsx)(zo,{schema:r,value:h,onChange:e=>{g(e),v(!0)},readOnly:!!n})})})]}):(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:Z(`engine.studio.hooks.pick`,i)})]})]})}function vh(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`):[]}function yh(e,t){let n=(e||`action`).replace(/[^a-z0-9_]/gi,`_`).toLowerCase(),r=new Set(t),i=t.length+1,a=`${n}_action_${i}`;for(;r.has(a);)a=`${n}_action_${++i}`;return a}function bh(e,t){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e;for(let e of[`default`,`en-US`,`en`,`zh-CN`])if(typeof t[e]==`string`)return t[e];let n=Object.values(t).find(e=>typeof e==`string`);if(typeof n==`string`)return n}return t}function xh({draft:e,onPatch:t,disabled:n,actionSchema:r}){let i=bo(),a=$.useMemo(()=>vh(e.actions),[e.actions]),[o,s]=$.useState(null),c=a.some(e=>e.name===o)?o:a[0]?.name??null,l=a.find(e=>e.name===c)??null,u=ja(`action`),d=$.useCallback(e=>{l&&(t({actions:a.map(t=>t.name===l.name?{...t,...e}:t)}),typeof e.name==`string`&&e.name!==l.name&&s(e.name))},[a,l,t]),f=typeof e.name==`string`?e.name:``,p=$.useCallback(()=>{let e=yh(f,a.map(e=>String(e.name??``))),n={name:e,label:Z(`engine.studio.actions.newLabel`,i),type:`script`,objectName:f,body:{language:`js`,source:`return { ok: true };`}};t({actions:[...a,n]}),s(e)},[a,f,t,i]),m=$.useCallback(e=>{t({actions:a.filter(t=>t.name!==e)}),s(null)},[a,t]);return(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,Q.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col rounded-lg border`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,Q.jsx)(Ct,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.data.tab.actions`,i)}),(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,a.length,`)`]}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:p,className:`ml-auto inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[(0,Q.jsx)(Sn,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,i)]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:a.length===0?(0,Q.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.actions.none`,i)}):a.map(e=>{let t=yo(typeof e.icon==`string`?e.icon:void 0),n=typeof e.type==`string`?e.type:``;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name??null),className:`flex w-full items-center gap-2 border-b px-3 py-2 text-left text-[12px] `+(c===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,Q.jsx)(t,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:bh(e.label,String(e.name??``))}),n&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-muted-foreground`,children:n})]},String(e.name))})})]}),(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col overflow-auto rounded-lg border`,children:l?u?(0,Q.jsxs)(Q.Fragment,{children:[!n&&(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center justify-end border-b px-2 py-1`,children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>m(l.name),className:`inline-flex items-center gap-1 rounded border border-destructive/40 px-2 py-0.5 text-[11px] text-destructive hover:bg-destructive/10`,children:[(0,Q.jsx)(mn,{className:`h-3 w-3`}),` `,Z(`engine.studio.actions.delete`,i)]})}),(0,Q.jsx)(u,{type:`action`,name:String(l.name??``),draft:l,onPatch:d,readOnly:!!n,locale:i,serverSchema:r})]}):(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:bh(l.label,String(l.name??``))}):(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:Z(`engine.studio.actions.pick`,i)})})]})}var Sh=1280;function Ch(){let[e,t]=$.useState(void 0);return $.useEffect(()=>{let e=window.matchMedia(`(min-width: ${Sh}px)`),n=()=>t(window.innerWidth>=Sh);return e.addEventListener(`change`,n),t(window.innerWidth>=Sh),()=>e.removeEventListener(`change`,n)},[]),!!e}var wh=[{key:`data`,label:`Data`,Icon:nr},{key:`automations`,label:`Automations`,Icon:He},{key:`interfaces`,label:`Interfaces`,Icon:$n},{key:`access`,label:`Access`,Icon:rt}],Th={group:tt,page:hr,object:nr,dashboard:$n,report:sr,view:Pn},Eh=e=>Th[e??``]??kr;function Dh(e){let t=String(e.label??``);switch(e.type){case`page`:return e.pageName||e.page?{type:`page`,name:String(e.pageName||e.page),label:t}:null;case`object`:return e.objectName||e.object?{type:`object`,name:String(e.objectName||e.object),label:t}:null;case`dashboard`:return e.dashboardName||e.dashboard?{type:`dashboard`,name:String(e.dashboardName||e.dashboard),label:t}:null;case`report`:return e.reportName||e.report?{type:`report`,name:String(e.reportName||e.report),label:t}:null;case`view`:return e.viewName||e.view?{type:`view`,name:String(e.viewName||e.view),label:t}:null;default:return null}}function Oh(e,t){for(let n of e)if(n.type===`group`||n.children?.length){let e=Oh(n.children??[],t);if(e)return e}else{let e=Dh(n);if(e&&e.type===t.type&&e.name===t.name)return e}return null}function kh(e){if(!e||typeof e!=`object`)return null;let t=e;if(!(`item`in t))return null;let n=t.item;return!n||typeof n!=`object`?null:Object.keys(n).length>0?n:null}function Ah({packageId:e,tab:t,beforeNavigate:n}){let r=a(),i=bo(),[o,s]=$.useState(!1),[c,l]=$.useState(null),[u,d]=$.useState(!1),[f,p]=$.useState(null),[m,h]=$.useState(!1),[g,_]=$.useState(!1);$.useEffect(()=>{let e=!1,t=()=>{Ca().then(t=>{e||l(t)}).catch(()=>{})};return t(),window.addEventListener(`objectui:packages-changed`,t),()=>{e=!0,window.removeEventListener(`objectui:packages-changed`,t)}},[e]);let v=c?.find(t=>t.id===e)??null,y=$.useCallback(async e=>{let t=await(await fetch(`/api/v1/packages`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`})).json(),n=t?.data??t;return(Array.isArray(n)?n:n?.packages??[]).find(t=>(t?.manifest?.id??t?.id)===e)??null},[]),b=$.useCallback(async e=>{s(!1),_(!0);try{p(await y(e)),h(!0)}catch(e){X.error(Ms(e))}finally{_(!1)}},[y]),x=$.useCallback(async()=>{let n=[];try{n=await Ca(),l(n)}catch{}let i=f?.manifest.id;if(i){if(!n.some(e=>e.id===i)){if(i===e){let e=n[0];r(e?`/studio/${encodeURIComponent(e.id)}/${t}`:`/home`)}return}try{let e=await y(i);e&&p(e)}catch{}}},[f,e,t,r,y]);return(0,Q.jsxs)(Fn,{open:o,onOpenChange:s,children:[(0,Q.jsx)(Dr,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 whitespace-nowrap rounded-md px-1.5 py-0.5 text-[13px] font-medium hover:bg-muted`,title:Z(`engine.studio.pkg.switchTitle`,i),children:[(0,Q.jsx)(Ln,{className:`h-4 w-4`}),` `,v?.name??e,v&&!v.writable&&(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] font-normal text-amber-600 dark:text-amber-300`,children:[(0,Q.jsx)(rn,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,i)]}),(0,Q.jsx)(on,{className:`h-3.5 w-3.5 text-muted-foreground`})]})}),(0,Q.jsxs)(un,{align:`start`,sideOffset:6,className:`w-80 rounded-lg p-1.5`,children:[(0,Q.jsx)(`p`,{className:`px-2 pb-1 pt-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.pkg.heading`,i)}),(0,Q.jsxs)(`div`,{className:`max-h-64 overflow-auto`,children:[c===null&&(0,Q.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,i)}),c?.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.pkg.none`,i)}),c?.map(a=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{s(!1),a.id!==e&&(n&&!n()||r(`/studio/${encodeURIComponent(a.id)}/${t}`))},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(a.id===e?`bg-muted font-medium`:`hover:bg-muted/60`),children:[(0,Q.jsx)(Ln,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate`,children:a.name}),(0,Q.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:a.id})]}),a.writable?(0,Q.jsx)(`span`,{className:`rounded bg-emerald-400/15 px-1.5 py-0.5 text-[10px] text-emerald-600 dark:text-emerald-300`,children:Z(`engine.studio.pkg.writable`,i)}):(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:[(0,Q.jsx)(rn,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,i)]})]},a.id))]}),(0,Q.jsxs)(`div`,{className:`mt-1 space-y-0.5 border-t pt-1.5`,children:[v&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void b(e),disabled:g,className:`flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50`,children:[g?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(St,{className:`h-3.5 w-3.5`}),Z(`engine.studio.pkg.manage`,i)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{s(!1),d(!0)},className:`flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Sn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.pkg.new`,i)]})]})]}),(0,Q.jsx)(Fa,{open:u,onOpenChange:d,onCreated:e=>{n&&!n()||r(`/studio/${encodeURIComponent(e)}/data`)}}),(0,Q.jsx)(xa,{pkg:f,open:m,onOpenChange:h,onChanged:x})]})}function jh({aiSlot:e}){let t=l(),r=t.packageId??`com.example.showcase`,i=t.tab??`interfaces`,o=bo(),[s,c]=$.useState(null);$.useEffect(()=>{let e=!1;return c(null),Ca().then(t=>{e||c(t.find(e=>e.id===r)?.writable??null)}).catch(()=>{}),()=>{e=!0}},[r]);let u=s===!1,[d,f]=$.useState(!1),p=$.useCallback(()=>!d||window.confirm(Z(`engine.edit.unsavedLeaveConfirm`,o)),[d,o]);$.useEffect(()=>{if(!d)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[d]);let[m,h]=$.useState(!1),[g,_]=$.useState(null),[v,y]=$.useState(!1),[b,x]=$.useState(0),[S,C]=$.useState(0),w=$.useCallback(async()=>{try{let e=await fetch(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(r)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!e.ok)return _(null);let t=await e.json(),n=Array.isArray(t)?t:t?.drafts??[];_(n.length)}catch{_(null)}},[r]);$.useEffect(()=>{w()},[w,b,S]);let T=$.useCallback(async()=>{y(!0);try{let e=await fetch(`/api/v1/packages/${encodeURIComponent(r)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),t=await e.json().catch(()=>null);if(!e.ok||t?.success===!1)throw Object.assign(Error(t?.error?.message||`HTTP ${e.status}`),{issues:t?.error?.details?.issues});let n=t?.data?.failed??[];n.length>0?X.error(Ps(n)):(X.success(Z(`engine.studio.publishedAll`,o)),h(!1)),x(e=>e+1)}catch(e){X.error(Ms(e))}finally{y(!1)}await w()},[r,w]),E=$.useCallback(()=>C(e=>e+1),[]),D=(g??0)>0,O=a(),k=So(),[A,j]=$.useState(null),[M,N]=$.useState(!1),[P,ee]=$.useState(!1),[F,I]=$.useState(null),[te,L]=$.useState(null),[R,z]=$.useState(!0),ne=$.useCallback(async()=>{let[e,t]=await Promise.all([k.list(`object`,{packageId:r}),k.listDrafts({packageId:r,type:`object`}).catch(()=>[])]),n=(e||[]).map(e=>({name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name),i=new Set(n.map(e=>e.name));for(let e of t)e.name&&!i.has(e.name)&&n.push({name:e.name,label:e.name});return n},[k,r]),re=$.useCallback(async(e,t)=>{ee(!0),I(null);try{let n=R?await ne().catch(()=>[]):[];await k.save(`app`,t,Nm(t,e,n),{mode:`draft`,packageId:r}),X.success(xo(`engine.studio.app.savedDraft`,o,{label:e})),L(e),N(!1),C(e=>e+1)}catch(e){I(Ms(e))}finally{ee(!1)}},[R,ne,k,r,o]);$.useEffect(()=>{let e=!1;return(async()=>{try{let t=(await k.list(`app`,{packageId:r})||[]).map(e=>({name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name)[0];e||j(t??null)}catch{e||j(null)}})(),()=>{e=!0}},[k,r,b]);let ie=!e;return(0,Q.jsxs)(`div`,{className:`flex h-screen w-full overflow-hidden bg-background text-foreground`,children:[e?(0,Q.jsx)(`aside`,{className:`w-64 shrink-0 overflow-auto border-r bg-muted/40`,children:e}):null,(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,Q.jsxs)(`header`,{className:`flex items-center gap-3 overflow-x-auto border-b px-3 py-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{p()&&O(`/home`)},title:Z(`engine.studio.home`,o),className:`shrink-0 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,Q.jsx)(Lr,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`shrink-0`,children:(0,Q.jsx)(Ah,{packageId:r,tab:i,beforeNavigate:p})}),(0,Q.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:`·`}),(0,Q.jsx)(`nav`,{className:`flex shrink-0 gap-1`,children:wh.map(e=>(0,Q.jsxs)(n,{to:`/studio/${r}/${e.key}`,onClick:t=>{i!==e.key&&(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||t.button!==0||p()||t.preventDefault())},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-colors `+(i===e.key?`bg-primary/10 font-medium text-primary`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:[(0,Q.jsx)(e.Icon,{className:`h-3.5 w-3.5`}),Z(`engine.studio.pillar.${e.key}`,o)]},e.key))}),(0,Q.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[A?(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>window.open(Hs(`apps/${encodeURIComponent(A.name)}`),`_blank`),title:xo(`engine.studio.app.openTitle`,o,{label:A.label}),className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(fr,{className:`h-3.5 w-3.5`}),Z(`engine.studio.app.open`,o)]}):te?(0,Q.jsx)(`span`,{title:Z(`engine.studio.app.willOpenAfterPublish`,o),className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:xo(`engine.studio.app.pending`,o,{label:te})}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>N(!0),disabled:u,title:Z(u?`engine.studio.pkg.readonlyHint`:`engine.studio.app.noneTitle`,o),className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,children:[(0,Q.jsx)(Sn,{className:`h-3.5 w-3.5`}),Z(`engine.studio.app.create`,o)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>h(!0),className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(st,{className:`h-3.5 w-3.5`}),Z(`engine.studio.changes`,o),D?` · ${g}`:``]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>h(!0),disabled:v||!D||u,title:Z(u?`engine.studio.pkg.readonlyHint`:D?`engine.studio.publishTitle`:`engine.studio.publishNoneTitle`,o),className:`inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[v?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Jt,{className:`h-3.5 w-3.5`}),Z(`engine.studio.publish`,o)]})]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:i===`data`?(0,Q.jsx)(Rh,{packageId:r,publishNonce:b,onDraftSaved:E,readOnly:u}):i===`automations`?(0,Q.jsx)(Bh,{packageId:r,publishNonce:b,onDraftSaved:E,readOnly:u}):i===`access`?(0,Q.jsx)(Vh,{packageId:r,publishNonce:b,onDraftSaved:E,readOnly:u,onDirtyChange:f}):(0,Q.jsx)(Ph,{packageId:r,publishNonce:b,draftNonce:S,onDraftSaved:E,onCreateApp:u?void 0:()=>N(!0),readOnly:u,foldInspector:ie,onDirtyChange:f})})]}),ie&&(0,Q.jsx)(gm,{packageId:r,locale:o}),(0,Q.jsx)(id,{open:m,onOpenChange:h,packageId:r,onPublish:u?void 0:T,publishing:v}),(0,Q.jsx)(Fm,{open:M,onOpenChange:N,title:Z(`engine.studio.app.create`,o),labelFieldLabel:Z(`engine.studio.app.nameLabel`,o),labelPlaceholder:Z(`engine.studio.app.namePlaceholder`,o),idFieldLabel:Z(`engine.studio.app.idLabel`,o),idPlaceholder:Z(`engine.studio.app.idPlaceholder`,o),submitLabel:Z(`engine.studio.createDraft`,o),submittingLabel:Z(`engine.studio.creating`,o),busy:P,error:F,locale:o,onSubmit:({label:e,name:t})=>void re(e,t),extra:(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,checked:R,onChange:e=>z(e.target.checked),className:`h-3.5 w-3.5 accent-primary`}),Z(`engine.studio.app.scaffoldNav`,o)]})})]})}function Mh({nodes:e,active:t,onPick:n,objectIcons:r}){return(0,Q.jsx)(Q.Fragment,{children:e.map((e,i)=>{if(e.type===`group`||Array.isArray(e.children)&&e.children.length)return(0,Q.jsxs)(`div`,{className:`mb-1`,children:[(0,Q.jsxs)(`p`,{className:`flex items-center gap-1 px-2 pb-1 pt-3 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(tt,{className:`h-3 w-3`}),` `,e.label]}),(0,Q.jsx)(`div`,{className:`pl-1.5`,children:(0,Q.jsx)(Mh,{nodes:e.children??[],active:t,onPick:n,objectIcons:r})})]},e.id??i);let a=Dh(e),o=a?.type===`object`?r?.[a.name]:void 0,s=e.icon?yo(e.icon):o?yo(o):Eh(e.type),c=!!a&&t?.type===a.type&&t?.name===a.name;return(0,Q.jsxs)(`button`,{onClick:()=>a&&n(a),disabled:!a,title:a?`${a.type} · ${a.name}`:e.label,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs disabled:opacity-40 `+(c?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(s,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),a&&a.type!==`page`&&(0,Q.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/60`,children:a.type})]},e.id??i)})})}function Nh({navId:e,appDraft:t,objects:n,onNavPatch:r,onClear:i}){let a=bo(),o=$.useMemo(()=>{let t=/^navigation\[(\d+)\]$/.exec(e);return t?Number(t[1]):-1},[e]),s=$.useMemo(()=>Array.isArray(t.navigation)?t.navigation:[],[t]),c=o>=0?s[o]:null;if(!c)return(0,Q.jsx)(`div`,{className:`px-2 py-10 text-center text-xs text-muted-foreground`,children:Z(`engine.studio.nav.selectItem`,a)});let l=e=>{r({navigation:s.map((t,n)=>n===o?{...t,...e}:t)})},u=String(c.object??c.objectName??``),d=String(c.label??c.title??c.name??``),f=!d||d===`New item`||d===Z(`engine.appNav.newItem`,a);return(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.nav.label`,a)}),(0,Q.jsx)(`input`,{value:d,onChange:e=>l({label:e.target.value}),placeholder:Z(`engine.studio.nav.labelPlaceholder`,a),className:`w-full rounded border bg-background px-2 py-1 text-xs`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.nav.linkObject`,a)}),(0,Q.jsxs)(`select`,{value:u,onChange:e=>{let t=e.target.value,r=n.find(e=>e.name===t);if(!t){l({type:void 0,objectName:void 0,object:void 0});return}l({id:c.id||`nav_${t}`,type:`object`,objectName:t,object:void 0,path:void 0,label:f&&r?r.label:d})},className:`w-full rounded border bg-background px-2 py-1 text-xs`,children:[(0,Q.jsx)(`option`,{value:``,children:Z(`engine.studio.nav.chooseObject`,a)}),n.map(e=>(0,Q.jsxs)(`option`,{value:e.name,children:[e.label,` (`,e.name,`)`]},e.name))]}),(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:Z(u?`engine.studio.nav.boundHint`:`engine.studio.nav.unboundHint`,a)}),n.length===0&&(0,Q.jsx)(`p`,{className:`mt-1 text-[11px] text-amber-600 dark:text-amber-400`,children:Z(`engine.studio.nav.noObjects`,a)})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:`text-[11px] text-muted-foreground underline-offset-2 hover:underline`,children:Z(`engine.studio.deselect`,a)})]})}function Ph({packageId:e,publishNonce:t=0,draftNonce:n=0,onDraftSaved:r,onCreateApp:i,readOnly:a=!1,foldInspector:o=!1,onDirtyChange:c}){let l=So(),u=bo(),d=sn(),[f,p]=$.useState(!1),[m,h]=$.useState(e),[g,_]=$.useState(null),[v,y]=$.useState({}),b=$.useMemo(()=>Array.isArray(v.navigation)?v.navigation:[],[v]),[x,S]=$.useState(!1),[C,w]=$.useState(null),[T,E]=s(),D=fa(T.get(`sel`)),O=$.useRef(null);$.useEffect(()=>{if(!D||b.length===0||O.current===D)return;let e=da({navigation:b},D);e&&(O.current=D,S(!0),w({kind:`nav`,id:e.selectionId}))},[D,b]),$.useEffect(()=>{let e=C?pa({navigation:b},C.id):null;E(t=>{let n=new URLSearchParams(t);return e?n.set(`sel`,La(e)):n.delete(`sel`),n},{replace:!0})},[C]);let[k,A]=$.useState(!1),j=$.useRef(c);$.useEffect(()=>{j.current=c}),$.useEffect(()=>{j.current?.(k)},[k]),$.useEffect(()=>()=>{j.current?.(!1)},[]);let[M,N]=$.useState(!1),[P,ee]=$.useState(!1),[F,I]=$.useState(null),te=km(F),[L,R]=$.useState(`source`),[z,ne]=$.useState({}),[re,ie]=$.useState(null),[ae,oe]=$.useState(`canvas`),se=Ch(),ce=o&&!se,[le,ue]=$.useState(!1),de=!ce,fe=!!(x&&C||re),pe=$.useRef(fe);$.useEffect(()=>{if(!ce)return;let e=pe.current;pe.current=fe,oe(t=>_m(t,e,fe))},[ce,fe]);let[me,B]=$.useState(!1),[he,ge]=$.useState(!1),[_e,ve]=$.useState(!1),[ye,be]=$.useState(null),[xe,V]=$.useState(`loading`),[Ce,we]=$.useState([]),H=$.useMemo(()=>Object.fromEntries(Ce.map(e=>[e.name,e.icon])),[Ce]);$.useEffect(()=>{let t=!1;return(async()=>{try{let[n,r]=await Promise.all([l.list(`object`,{packageId:e}),l.listDrafts({packageId:e,type:`object`}).catch(()=>[])]);if(t)return;let i=new Map;for(let e of[...n||[],...r||[]]){let t=e,n=String(t.name??``);!n||i.has(n)||i.set(n,{name:n,label:String(t.label??t.name??n),icon:t.icon?String(t.icon):void 0})}we([...i.values()])}catch{}})(),()=>{t=!0}},[l,e,t,n]),$.useEffect(()=>{let t=!1;return V(`loading`),(async()=>{try{let n=await l.list(`app`,{packageId:e});if(t)return;let r=n?.[0]?.name?String(n[0].name):null,i=n?.[0]?String(n[0].label??n[0].name??e):e;if(!r){let n=await l.listDrafts({packageId:e,type:`app`});if(t)return;let a=n?.[0];a?.name&&(r=String(a.name),i=String(a.name))}if(!r){V(`missing`);return}h(i),_(r);let[a,o]=await Promise.all([l.layered(`app`,r),l.getDraft(`app`,r).catch(()=>null)]);if(t)return;let s=a,c=s.effective??s.code??{},u=kh(o),d=u?{...c,...u}:c;(typeof d.label==`string`||typeof d.name==`string`)&&h(String(d.label??d.name??i)),y(d),N(!!u),V(`ready`);let f=Array.isArray(d.navigation)?d.navigation:[],p=(function e(t){for(let n of t)if(n.type===`group`||n.children?.length){let t=e(n.children??[]);if(t)return t}else{let e=Dh(n);if(e)return e}return null})(f),m=te?Oh(f,te):null;I(e=>e??m??p)}catch(e){t||(be(Ms(e)),V(`missing`))}})(),()=>{t=!0}},[l,e,t,n]);let U=ba(F?.type??``),Te=bm(F?.type??``),Ee=Pa(F?.type??``),Oe=ja(F?.type??``),ke=!!U&&!Te,Ae=F?.type===`page`?z?.kind:void 0,je=Ae===`html`||Ae===`react`;$.useEffect(()=>{if(!F||!ke){ne({}),ve(!1);return}let e=!1;return B(!0),be(null),ie(null),(async()=>{try{let[t,n]=await Promise.all([l.layered(F.type,F.name),l.getDraft(F.type,F.name).catch(()=>null)]);if(e)return;let r=t.effective??t.code??{},i=kh(n);ne(i?{...r,...i}:r),ve(!!i)}catch(t){e||be(Ms(t))}finally{e||B(!1)}})(),()=>{e=!0}},[l,F,ke,t]);let Me=$.useCallback(e=>ne(t=>({...t,...e})),[]),Ne=$.useCallback(async()=>{if(F){ge(`draft`);try{await l.save(F.type,F.name,z,{mode:`draft`,packageId:e}),ve(!0),r?.()}catch(e){be(Ms(e))}finally{ge(!1)}}},[l,F,z,r]),Pe=$.useCallback(e=>{y(t=>({...t,...e})),A(!0)},[]),Fe=$.useCallback(async()=>{if(g){ee(`draft`);try{let t=(Array.isArray(v.navigation)?v.navigation:[]).filter(e=>e&&typeof e.type==`string`).map((e,t)=>{let n=e;return typeof n.id==`string`&&n.id?n:{...n,id:`nav_item_${t+1}`}});await l.save(`app`,g,{...v,navigation:t},{mode:`draft`,packageId:e}),N(!0),A(!1),r?.()}catch(e){be(Ms(e))}finally{ee(!1)}}},[l,g,v,r]),Ie=(0,Q.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-auto bg-muted/30 p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex shrink-0 items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[11px] text-primary`,children:[(0,Q.jsx)(Hn,{className:`h-3 w-3`}),` `,Z(`engine.studio.if.previewIsRuntime`,u)]}),F&&(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[F.type,` · `,F.name]})]}),ye&&(0,Q.jsx)(`div`,{className:`mb-3 shrink-0 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line`,children:ye}),(0,Q.jsx)(`div`,{className:q(je?`min-h-0 flex-1 overflow-hidden`:`rounded-lg border bg-background p-4`),children:xe===`missing`&&!ye?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 py-16 text-center`,children:[(0,Q.jsx)(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,Q.jsx)($n,{className:`h-6 w-6 text-muted-foreground`})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.if.noAppTitle`,u)}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:Z(`engine.studio.if.noAppHint`,u)})]}),i&&(0,Q.jsxs)(`button`,{type:`button`,onClick:i,className:`inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground`,children:[(0,Q.jsx)(Sn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.app.create`,u)]})]}):F?me?(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`}),` `,Z(`engine.studio.loading`,u)]}):Te?(0,Q.jsx)(Te,{type:F.type,name:F.name,draft:z,locale:u}):je?(0,Q.jsx)(Na,{mode:`preview`,draft:z,readOnly:!0}):U?(0,Q.jsx)(U,{type:F.type,name:F.name,draft:z,editing:!0,selection:re,onSelectionChange:ie,onPatch:Me,locale:u}):(0,Q.jsx)(`div`,{className:`py-12 text-center text-xs text-muted-foreground`,children:xo(`engine.studio.if.readonlyPreview`,u,{type:F.type})}):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.if.pickLeft`,u)})}),!ke&&F?.type===`object`?(0,Q.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(nr,{className:`h-3 w-3`}),` `,Z(`engine.studio.if.objectHintPre`,u),(0,Q.jsx)(`span`,{className:`font-medium`,children:`Data`}),Z(`engine.studio.if.objectHintPost`,u)]}):null]}),Le=(0,Q.jsxs)(`header`,{className:`flex shrink-0 items-center gap-2 border-b bg-background/95 px-3 py-2`,children:[(0,Q.jsx)(Yn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.inspector.props`,u)}),(0,Q.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5`,children:[re&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ie(null),className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.deselect`,u),children:(0,Q.jsx)(Se,{className:`h-3.5 w-3.5`})}),de&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ue(!0),className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.inspector.collapse`,u),title:Z(`engine.studio.inspector.collapse`,u),children:(0,Q.jsx)(Tt,{className:`h-3.5 w-3.5`})})]})]}),W=(0,Q.jsxs)(`aside`,{className:`flex w-9 shrink-0 flex-col items-center gap-1.5 border-l bg-background py-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ue(!1),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.inspector.expand`,u),title:Z(`engine.studio.inspector.props`,u),children:(0,Q.jsx)(vn,{className:`h-4 w-4`})}),(0,Q.jsx)(Yn,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),Re=x&&C?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,Q.jsx)(Nh,{navId:C.id,appDraft:v,objects:Ce,onNavPatch:Pe,onClear:()=>w(null)})}):re&&Ee&&F?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,Q.jsx)(Ee,{type:F.type,name:F.name,draft:z,selection:re,onPatch:Me,onClearSelection:()=>ie(null),onSelectionChange:ie,readOnly:!1,locale:u})}):je?ce?(0,Q.jsx)(`div`,{className:`mt-2 min-h-0 flex-1 border-t`,children:(0,Q.jsx)(Na,{mode:`editor`,draft:z,onPatch:Me})}):(0,Q.jsxs)(xn,{value:L,onValueChange:e=>R(e===`props`?`props`:`source`),className:`flex min-h-0 flex-1 flex-col`,children:[(0,Q.jsxs)(Dt,{className:`mx-3 mt-2 shrink-0 self-start`,children:[(0,Q.jsxs)(De,{value:`source`,className:`gap-1 text-xs`,children:[(0,Q.jsx)(Rr,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.inspector.tabSource`,u)]}),(0,Q.jsx)(De,{value:`props`,className:`text-xs`,children:Z(`engine.studio.inspector.tabProps`,u)})]}),(0,Q.jsx)(zr,{value:`source`,className:`mt-2 min-h-0 flex-1 border-t`,children:(0,Q.jsx)(Na,{mode:`editor`,draft:z,onPatch:Me})}),(0,Q.jsx)(zr,{value:`props`,className:`mt-0 min-h-0 flex-1 overflow-auto p-3`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,Q.jsx)(Rr,{className:`h-5 w-5`}),xo(`engine.studio.inspector.sourcePageLine1`,u,{kind:Ae}),(0,Q.jsx)(`br`,{}),Z(`engine.studio.inspector.sourcePageLine2`,u)]})})]}):Oe&&F&&ke?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,Q.jsx)(Oe,{type:F.type,name:F.name,draft:z,onPatch:Me,onSelectionChange:ie,readOnly:!1,locale:u})}):(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,Q.jsx)(ft,{className:`h-5 w-5`}),Z(`engine.studio.inspector.emptyLine1`,u),(0,Q.jsx)(`br`,{}),Z(`engine.studio.inspector.emptyLine2`,u)]})});return(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>p(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,u),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,Q.jsx)(Vt,{className:`h-4 w-4`})}),F?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:F.label}),(0,Q.jsxs)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:[F.type,` · `,F.name]})]}):(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.if.pickLeft`,u)}),_e&&(0,Q.jsx)(`span`,{className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublishedDraft`,u)}),(0,Q.jsxs)(`button`,{onClick:Ne,disabled:!F||!ke||!!he||a,title:a?Z(`engine.studio.pkg.readonlyHint`,u):void 0,className:`ml-auto inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs hover:bg-muted disabled:opacity-50`,children:[he===`draft`?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Ht,{className:`h-3.5 w-3.5`}),Z(`engine.studio.saveDraft`,u)]})]}),(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[d&&f&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>p(!1),"aria-hidden":`true`}),(0,Q.jsxs)(`nav`,{className:q((x?`w-72`:`w-52`)+` flex shrink-0 flex-col border-r bg-background`,d&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,d&&!f&&`-translate-x-full`),children:[(0,Q.jsxs)(`div`,{className:`shrink-0 border-b px-2 py-1.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-1`,children:[(0,Q.jsx)(`p`,{className:`truncate text-[11px] font-medium text-muted-foreground`,children:xo(`engine.studio.if.navHeading`,u,{app:m})}),xe===`ready`&&!a&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{S(e=>!e),w(null)},title:Z(x?`engine.studio.if.doneEditTitle`:`engine.studio.if.editNavTitle`,u),className:`inline-flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[10px] `+(x?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted`),children:x?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(bt,{className:`h-3 w-3`}),` `,Z(`engine.studio.done`,u)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(In,{className:`h-3 w-3`}),` `,Z(`engine.studio.edit`,u)]})})]}),x&&(0,Q.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[M&&(0,Q.jsx)(`span`,{className:`rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublished`,u)}),(0,Q.jsxs)(`button`,{onClick:Fe,disabled:!k||!!P,className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] hover:bg-muted disabled:opacity-50`,children:[P===`draft`?(0,Q.jsx)(Y,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Ht,{className:`h-3 w-3`}),Z(`engine.studio.saveDraft`,u)]})]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:xe===`missing`&&!ye?(0,Q.jsxs)(`div`,{className:`px-2 py-3`,children:[(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.if.noApp`,u)}),i&&(0,Q.jsxs)(`button`,{type:`button`,onClick:i,className:`mt-2 inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] hover:bg-muted`,children:[(0,Q.jsx)(Sn,{className:`h-3 w-3`}),` `,Z(`engine.studio.app.create`,u)]})]}):x?(0,Q.jsx)(Aa,{draft:v,rootKey:`navigation`,onPatch:Pe,selection:C,onSelectionChange:e=>w(e?{kind:e.kind,id:e.id}:null)}):b.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(ye?`engine.studio.loadFailed`:xe===`loading`?`engine.studio.loading`:`engine.studio.if.noNavItems`,u)}):(0,Q.jsx)(Mh,{nodes:b,active:F,objectIcons:H,onPick:e=>{I(e),d&&p(!1)}})})]}),o?se?(0,Q.jsxs)(Q.Fragment,{children:[Ie,le?W:(0,Q.jsxs)(`aside`,{"data-testid":`studio-folded-inspector`,className:q(`flex shrink-0 flex-col overflow-hidden border-l`,je&&!(re&&Ee&&F)&&!(x&&C)?`w-[22rem] 2xl:w-[28rem]`:`w-72 2xl:w-80`),children:[Le,Re]})]}):(0,Q.jsxs)(xn,{value:ae,onValueChange:e=>oe(e===`properties`?`properties`:`canvas`),className:`flex min-w-0 flex-1 flex-col`,"data-testid":`studio-center-tabs`,children:[(0,Q.jsxs)(Dt,{className:`mx-3 mt-2 shrink-0 self-start`,children:[(0,Q.jsxs)(De,{value:`canvas`,className:`gap-1 text-xs`,children:[(0,Q.jsx)(Hn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.if.tabCanvas`,u)]}),(0,Q.jsxs)(De,{value:`properties`,className:`gap-1 text-xs`,children:[(0,Q.jsx)(Yn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.inspector.props`,u)]})]}),(0,Q.jsx)(zr,{forceMount:!0,value:`canvas`,className:`mt-0 flex min-h-0 flex-1 flex-col data-[state=inactive]:hidden`,children:Ie}),(0,Q.jsxs)(zr,{value:`properties`,className:`mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:[Le,Re]})]}):(0,Q.jsxs)(Q.Fragment,{children:[Ie,le?W:(0,Q.jsxs)(`aside`,{className:q(`flex shrink-0 flex-col overflow-hidden border-l`,je&&!(re&&Ee&&F)&&!(x&&C)?`w-[24rem] xl:w-[30rem] 2xl:w-[36rem]`:`w-72`),children:[Le,Re]})]})]})]})}function Fh(e){let t=e.length+1,n=`field_${t}`;for(;e.includes(n);)n=`field_${++t}`;return n}var Ih=new Set([`_id`,`id`,`organization_id`,`org_id`,`space_id`,`created_at`,`created_by`,`updated_at`,`updated_by`,`modified_at`,`modified_by`,`created_time`,`modified_time`,`updated_time`,`deleted_at`,`deleted_by`]);function Lh(e){let{schema:t,dataSource:n,onEdit:r,className:i,refreshKey:a,onAddRecord:o}=e;return(0,Q.jsx)(Go,{schema:{...t,viewType:`grid`,showSearch:!0,showSort:!0,showFilters:!0,showGroup:!0,showHideFields:!0,inlineEdit:!0,addDeleteRecordsInline:!0,addRecord:{enabled:!0}},dataSource:n,onEdit:r,onAddRecord:o,className:i,refreshKey:a})}function Rh({packageId:e,publishNonce:t=0,onDraftSaved:n,readOnly:r=!1}){let i=So(),a=ie(),o=bo(),{entries:s}=Co(i),c=$.useMemo(()=>{let e={};for(let t of s)e[t.type]=t.schema;return e},[s]),l=sn(),[u,d]=$.useState(!1),[f,p]=$.useState([]),[m,h]=$.useState(!1),[g,_]=$.useState(null),v=km(g),[y,b]=$.useState({}),[x,S]=$.useState(!1),[C,w]=$.useState(null),[T,E]=$.useState(null),[D,O]=$.useState(!1),[k,A]=$.useState(!1),[j,M]=$.useState(!1),[N,P]=$.useState(null),[ee,F]=$.useState(0),[I,te]=$.useState(`grid`),[L,R]=$.useState(`layout`),z=$.useRef(null),[ne,re]=$.useState(``),[ae,oe]=$.useState(!1),[se,ce]=$.useState(!1),[ue,de]=$.useState(!0),[fe,pe]=$.useState(null);$.useEffect(()=>{let t=!1;return Ca().then(n=>{t||pe(n.find(t=>t.id===e)?.namespace??null)}).catch(()=>{}),()=>{t=!0}},[e]),$.useEffect(()=>{let t=!1;return(async()=>{try{let[n,r]=await Promise.all([i.list(`object`,{packageId:e}),i.listDrafts({packageId:e,type:`object`}).catch(()=>[])]);if(t)return;let a=(n||[]).map(e=>({type:`object`,name:String(e.name??``),label:String(e.label??e.name??``),icon:e.icon?String(e.icon):void 0})).filter(e=>e.name),o=new Set(a.map(e=>e.name));for(let e of r)e.name&&!o.has(e.name)&&a.push({type:`object`,name:e.name,label:e.name,icon:void 0});p(a);let s=Am(a,v,`object`);_(e=>e??s??a[0]??null)}catch(e){t||w(Ms(e))}finally{t||h(!0)}})(),()=>{t=!0}},[i,e,r]),$.useEffect(()=>{if(!g)return;let e=`${g.name}#${t}`;if(z.current===e)return;z.current=e;let n=!1;return S(!0),w(null),E(null),O(!1),(async()=>{try{let[e,t]=await Promise.all([i.layered(`object`,g.name),i.getDraft(`object`,g.name).catch(()=>null)]);if(n)return;let r=e,a=r.effective??r.code??{},o=kh(t);b(o?{...a,...o}:a),A(!!o),de(!!(r.effective??r.code))}catch(e){n||w(Ms(e))}finally{n||S(!1)}})(),()=>{n=!0}},[i,g,t]);let me=$.useMemo(()=>Ho(y.fields).entries.length,[y]),B=$.useCallback(e=>{b(t=>({...t,...e})),O(!0)},[]),he=$.useCallback(()=>{if(r)return;let e=Ho(y.fields),t=Fh(e.entries.map(e=>e.name));e.entries.push(No(t,`text`,Z(`engine.studio.data.newFieldLabel`,o))),b(t=>({...t,fields:Oo(e)})),O(!0),E({kind:`field`,id:t})},[y,r]),ge=$.useCallback(async(t,a)=>{if(r)return;let s=_a(a,fe);if(f.some(e=>e.name===s)){w(xo(`engine.studio.data.idExists`,o,{name:s}));return}ce(!0),w(null);try{let r=jm(s,t,Z(`engine.studio.data.nameFieldLabel`,o));await i.save(`object`,s,r,{mode:`draft`,packageId:e});let a={type:`object`,name:s,label:t};p(e=>[...e,a]),_(a),te(`form`),R(`layout`),oe(!1),n?.()}catch(e){w(Ms(e))}finally{ce(!1)}},[f,i,e,n,r,o,fe]),_e=$.useCallback(async()=>{if(g){M(`draft`),w(null);try{await i.save(`object`,g.name,y,{mode:`draft`,packageId:e}),A(!0),O(!1),P(new Date),X.success(xo(`engine.studio.data.savedDraft`,o,{label:g.label})),n?.()}catch(e){w(Ms(e))}finally{M(!1)}}},[i,g,y,n,e,o]),ve=$.useCallback(async t=>{if(!g)return;let r=Ho(y.fields),a=new Set(t),o=t.map(e=>r.entries.find(t=>t.name===e)).filter(e=>!!e),s=0,c=r.entries.map(e=>a.has(e.name)?o[s++]:e),l={...y,fields:Oo({...r,entries:c})};b(l),M(`draft`),w(null);try{await i.save(`object`,g.name,l,{mode:`draft`,packageId:e}),A(!0),O(!1),n?.(),F(e=>e+1)}catch(e){w(Ms(e))}finally{M(!1)}},[i,g,y,n]),ye=Pa(`object`),be=[{key:`grid`,label:Z(`engine.studio.data.tab.records`,o)},{key:`form`,label:Z(`engine.studio.data.tab.form`,o)},{key:`rules`,label:Z(`engine.studio.data.tab.rules`,o)},{key:`hooks`,label:Z(`engine.studio.data.tab.hooks`,o)},{key:`actions`,label:Z(`engine.studio.data.tab.actions`,o)},{key:`api`,label:Z(`engine.studio.data.tab.api`,o)},{key:`settings`,label:Z(`engine.studio.data.tab.settings`,o)}],xe=yo(typeof y.icon==`string`?y.icon:g?.icon);return(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-3 py-2`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,o),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,Q.jsx)(Vt,{className:`h-4 w-4`})}),g?(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(xe,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`truncate text-[15px] font-semibold leading-none text-foreground`,children:g.label}),(0,Q.jsx)(`span`,{className:`shrink-0 rounded bg-muted/70 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground`,children:g.name}),(0,Q.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:xo(`engine.studio.data.fieldCount`,o,{count:me})})]}):(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,o)}),k&&(0,Q.jsx)(`span`,{className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublishedDraft`,o)}),N&&!D&&(0,Q.jsx)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,"data-testid":`data-saved-at`,children:xo(`engine.studio.data.lastSaved`,o,{time:N.toLocaleTimeString(o,{hour:`2-digit`,minute:`2-digit`})})}),(0,Q.jsxs)(`button`,{onClick:_e,disabled:!g||!D||!!j||r,title:r?Z(`engine.studio.pkg.readonlyHint`,o):void 0,className:(N&&!D?``:`ml-auto `)+`inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs hover:bg-muted disabled:opacity-50`,children:[j===`draft`?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Ht,{className:`h-3.5 w-3.5`}),Z(`engine.studio.saveDraft`,o)]})]}),(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[l&&u&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>d(!1),"aria-hidden":`true`}),(0,Q.jsxs)(`nav`,{className:q(`flex w-52 shrink-0 flex-col border-r bg-background`,l&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,l&&!u&&`-translate-x-full`),children:[(0,Q.jsxs)(`div`,{className:`shrink-0 p-2 pb-1`,children:[(0,Q.jsx)(`p`,{className:`px-2 pb-1 pt-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.data.objects`,o)}),(0,Q.jsx)(`input`,{value:ne,onChange:e=>re(e.target.value),placeholder:Z(`engine.studio.data.searchObjects`,o),className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none placeholder:text-muted-foreground/70 focus:ring-1 focus:ring-primary`})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2 pt-1`,children:[f.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(C?`engine.studio.loadFailed`:m?`engine.studio.data.noObjects`:`engine.studio.loading`,o)}),f.filter(e=>!ne.trim()||e.label.toLowerCase().includes(ne.trim().toLowerCase())||e.name.toLowerCase().includes(ne.trim().toLowerCase())).map(e=>{let t=yo(e.icon);return(0,Q.jsxs)(`button`,{onClick:()=>{_(e),l&&d(!1)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(g?.name===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(t,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label})]},e.name)})]}),(0,Q.jsx)(`div`,{className:`shrink-0 border-t p-2`,children:r?(0,Q.jsxs)(`p`,{title:Z(`engine.studio.pkg.readonlyHint`,o),className:`flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(rn,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,o)]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{w(null),oe(!0)},className:`inline-flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Sn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.newObject`,o)]})})]}),(0,Q.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden p-4`,children:g?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`mb-4 flex shrink-0 items-center gap-3`,children:[(0,Q.jsx)(`div`,{className:`inline-flex items-center gap-0.5 rounded-lg bg-muted p-1`,children:be.map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>te(e.key),"aria-pressed":I===e.key,className:`rounded-md px-3 py-1 text-[13px] transition-all `+(I===e.key?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:e.label},e.key))}),(I===`grid`||I===`form`)&&!r&&(0,Q.jsxs)(`button`,{type:`button`,onClick:he,title:Z(`engine.studio.data.addFieldTitle`,o),className:`ml-auto inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Sn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.addField`,o)]})]}),C&&(0,Q.jsx)(`div`,{className:`mb-2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive whitespace-pre-line`,children:C}),I===`rules`?(0,Q.jsx)(th,{draft:y,onPatch:B,disabled:r}):I===`settings`?(0,Q.jsx)(nh,{name:g.name,draft:y,onPatch:B,locale:o,disabled:r}):I===`hooks`?(0,Q.jsx)(_h,{objectName:g.name,packageId:e,disabled:r,hookSchema:c.hook}):I===`actions`?(0,Q.jsx)(xh,{draft:y,onPatch:B,disabled:r,actionSchema:c.action}):I===`api`?(0,Q.jsx)(ph,{name:g.name,draft:y}):I===`grid`&&!ue?(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-2 rounded-lg border border-dashed bg-muted/20 text-center`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.draftObjectTitle`,o)}),(0,Q.jsx)(`p`,{className:`max-w-md text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.draftObjectHint`,o)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{te(`form`),R(`layout`)},className:`mt-1 inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs hover:bg-muted`,children:Z(`engine.studio.data.goDesignFields`,o)})]}):I===`grid`?(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background`,children:(0,Q.jsx)(Re,{value:{...r?{}:{onAddColumn:he,addColumnLabel:Z(`engine.studio.data.addField`,o),onReorderFields:ve},onEditColumn:e=>{Ho(y.fields).entries.some(t=>t.name===e)&&E({kind:`field`,id:e})},editColumnLabel:Z(`engine.studio.data.editFieldProps`,o)},children:(0,Q.jsx)(le,{dataSource:a,children:(0,Q.jsx)(Yo,{schema:{type:`object-view`,objectName:g.name,showCreate:!1,table:{fields:Ho(y.fields).entries.map(e=>e.name).filter(e=>!Ih.has(e)&&e!==`actions`)}},dataSource:a,renderListView:Lh},`${g.name}:${ee}`)})})})}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,Q.jsxs)(`div`,{className:`inline-flex items-center gap-0.5 rounded-lg bg-muted p-0.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>R(`layout`),"aria-pressed":L===`layout`,className:`rounded-md px-2.5 py-0.5 text-[12px] transition-all `+(L===`layout`?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.form.layout`,o)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>R(`preview`),"aria-pressed":L===`preview`,className:`rounded-md px-2.5 py-0.5 text-[12px] transition-all `+(L===`preview`?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.form.preview`,o)})]}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(L===`layout`?`engine.studio.data.form.layoutBadge`:`engine.studio.data.form.previewBadge`,o)}),L===`preview`&&(D||k)&&(0,Q.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.data.form.previewWarn`,o)})]}),L===`layout`?(0,Q.jsx)(Wm,{draft:y,systemFieldNames:Ih,onChange:B,selectedField:T?.kind===`field`?T.id:null,onSelectField:e=>E({kind:`field`,id:e}),selectedGroup:T?.kind===`group`?T.id:null,onSelectGroup:e=>E({kind:`group`,id:e}),onAddField:he,readOnly:r}):ue?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`style`,{children:`
10
- /* Design preview: the form is a click-to-select canvas, not a data-entry
11
- * form. Disable interaction on field contents so a click anywhere on a
12
- * field routes to its [data-field] wrapper (→ select), and neutralize the
13
- * create/cancel footer so nothing is submittable here. */
14
- .os-form-authoring [data-field]{border-radius:8px;cursor:pointer;transition:box-shadow .12s;padding:8px;margin:-8px 0;}
15
- .os-form-authoring [data-field] *{pointer-events:none;}
16
- .os-form-authoring [data-field]:hover{box-shadow:0 0 0 1px hsl(var(--border));}
17
- .os-form-authoring form > div:last-child:has(button){display:none;}
18
- ${T?.kind===`field`?`.os-form-authoring [data-field="${String(T.id).replace(/[^\w-]/g,``)}"]{box-shadow:0 0 0 2px hsl(var(--primary));}`:``}
19
- `}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background p-6`,children:(0,Q.jsx)(`div`,{className:`os-form-authoring mx-auto max-w-6xl`,onClick:e=>{let t=e.target.closest(`[data-field]`)?.getAttribute(`data-field`);t&&Ho(y.fields).entries.some(e=>e.name===t)&&E({kind:`field`,id:t})},children:(0,Q.jsx)(le,{dataSource:a,children:(0,Q.jsx)(Qr,{schema:{type:`object-form`,objectName:g.name,mode:`create`,fields:Ho(y.fields).entries.map(e=>e.name).filter(e=>!Ih.has(e))},dataSource:a},`${g.name}:${ee}:form`)})})})]}):(0,Q.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-2 rounded-lg border border-dashed bg-muted/20 text-center`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.form.noPublishedTitle`,o)}),(0,Q.jsx)(`p`,{className:`max-w-md text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.form.noPublishedHint`,o)})]})]})]}):m&&f.length===0?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-16 text-center`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.firstObjectTitle`,o)}),(0,Q.jsx)(`p`,{className:`max-w-sm text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.firstObjectHint`,o)}),!r&&(0,Q.jsxs)(`button`,{type:`button`,"data-testid":`empty-state-new-object`,onClick:()=>{w(null),oe(!0)},className:`mt-2 inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[(0,Q.jsx)(Sn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.newObject`,o)]})]}):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,o)})}),g&&T&&(T.kind===`group`||ye)&&(0,Q.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-l`,children:[(0,Q.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 px-3 py-2 backdrop-blur`,children:[(0,Q.jsx)(Yn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(T.kind===`group`?`engine.studio.data.groupProps`:`engine.studio.data.fieldProps`,o)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>E(null),className:`ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.close`,o),children:(0,Q.jsx)(Se,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:T.kind===`group`?(0,Q.jsx)(Gm,{draft:y,groupKey:T.id,onPatch:B,onClose:()=>E(null),readOnly:r,locale:o}):ye&&$.createElement(ye,{type:`object`,name:g.name,draft:y,selection:T,onPatch:B,onClearSelection:()=>E(null),onSelectionChange:E,readOnly:r,locale:o})})]})]}),(0,Q.jsx)(Fm,{open:ae,onOpenChange:oe,title:Z(`engine.studio.data.newObject`,o),labelFieldLabel:Z(`engine.studio.data.nameLabel`,o),labelPlaceholder:Z(`engine.studio.data.labelPlaceholder`,o),idFieldLabel:Z(`engine.studio.data.idLabel`,o),idPlaceholder:Z(`engine.studio.data.idPlaceholder`,o),submitLabel:Z(`engine.studio.createDraft`,o),submittingLabel:Z(`engine.studio.creating`,o),busy:se,error:C,locale:o,onSubmit:({label:e,name:t})=>void ge(e,t)})]})}function zh({state:e,locale:t}){if(!e)return null;let{enabled:n,bound:r}=e;return(0,Q.jsxs)(`span`,{title:Z(n?r?`engine.studio.auto.onBound`:`engine.studio.auto.onUnbound`:`engine.studio.auto.offTitle`,t),className:`inline-flex shrink-0 items-center gap-1`,children:[(0,Q.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full `+(n?`bg-emerald-500`:`bg-muted-foreground/40`)}),(0,Q.jsx)(`span`,{className:`text-[10px] `+(n?`text-emerald-600 dark:text-emerald-400`:`text-muted-foreground`),children:Z(n?`engine.studio.auto.on`:`engine.studio.auto.off`,t)})]})}function Bh({packageId:e,publishNonce:t=0,onDraftSaved:n,readOnly:r=!1}){let i=So(),a=bo(),o=sn(),[s,c]=$.useState(!1),[l,u]=$.useState([]),[d,f]=$.useState(null),p=km(d),[m,h]=$.useState({}),[g,_]=$.useState(null),[v,y]=$.useState(!1),[b,x]=$.useState(!1),[S,C]=$.useState(!1),[w,T]=$.useState(null),[E,D]=$.useState(!1),[O,k]=$.useState(!1),[A,j]=$.useState(!1),M=ba(d?.type??``),N=Pa(`flow`),P=!!M,[ee,F]=$.useState({});$.useEffect(()=>{let e=!1;return(async()=>{try{let t=await fetch(`/api/v1/automation/_status`,{credentials:`include`,headers:{Accept:`application/json`}});if(!t.ok)return;let n=await t.json().catch(()=>null),r=n?.data?.flows??n?.flows??[];if(e||!Array.isArray(r))return;let i={};for(let e of r)e?.name&&(i[e.name]={enabled:e.enabled!==!1,bound:!!e.bound});F(i)}catch{}})(),()=>{e=!0}},[t]),$.useEffect(()=>{let t=!1;return(async()=>{try{let n=await Om(i,`flow`,e);if(t)return;u(n);let r=Am(n,p,`flow`);f(e=>e??r??n[0]??null)}catch(e){t||T(Ms(e))}finally{t||D(!0)}})(),()=>{t=!0}},[i,e,t]);let I=$.useCallback(async(t,r)=>{j(!0),T(null);try{let o=Mm(r,t,Z(`engine.studio.auto.nodeStart`,a),Z(`engine.studio.auto.nodeEnd`,a));await i.save(`flow`,r,o,{mode:`draft`,packageId:e});let s={type:`flow`,name:r,label:t};u(e=>[...e.filter(e=>e.name!==r),s]),f(s),C(!0),k(!1),n?.(),X.success(xo(`engine.studio.auto.savedDraft`,a,{label:t}))}catch(e){T(Ms(e))}finally{j(!1)}},[i,e,n,a]);$.useEffect(()=>{if(!d)return;let e=!1;return y(!0),T(null),_(null),(async()=>{try{let[t,n]=await Promise.all([i.layered(`flow`,d.name),i.getDraft(`flow`,d.name).catch(()=>null)]);if(e)return;let r=t,a=r.effective??r.code??{},o=kh(n);h(o?{...a,...o}:a),C(!!o)}catch(t){e||T(Ms(t))}finally{e||y(!1)}})(),()=>{e=!0}},[i,d,t]);let te=$.useCallback(e=>h(t=>({...t,...e})),[]),L=$.useCallback(async()=>{if(d){x(`draft`),T(null);try{await i.save(`flow`,d.name,m,{mode:`draft`,packageId:e}),C(!0),n?.()}catch(e){T(Ms(e))}finally{x(!1)}}},[i,d,m,n]),R=m.status!==`obsolete`&&m.status!==`invalid`,z=$.useCallback(async()=>{if(!d)return;let t=!(m.status!==`obsolete`&&m.status!==`invalid`),r={...m,status:t?`active`:`obsolete`};h(r),x(`draft`),T(null);try{await i.save(`flow`,d.name,r,{mode:`draft`,packageId:e}),C(!0),n?.(),X.success(Z(t?`engine.studio.auto.enabledToast`:`engine.studio.auto.disabledToast`,a))}catch(e){T(Ms(e))}finally{x(!1)}},[i,d,m,e,n,a]);return(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,a),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,Q.jsx)(Vt,{className:`h-4 w-4`})}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.auto.defaultOff`,a)}),S&&(0,Q.jsx)(`span`,{className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublishedDraft`,a)}),d&&(0,Q.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":R,onClick:z,disabled:!P||!!b,title:Z(R?`engine.studio.auto.disableTitle`:`engine.studio.auto.enableTitle`,a),className:`inline-flex items-center gap-1.5 rounded-md border px-2 py-1 text-[11px] hover:bg-muted disabled:opacity-50`,children:[(0,Q.jsx)(`span`,{className:`relative inline-flex h-3.5 w-6 shrink-0 items-center rounded-full transition-colors `+(R?`bg-emerald-500`:`bg-muted-foreground/40`),children:(0,Q.jsx)(`span`,{className:`inline-block h-2.5 w-2.5 rounded-full bg-white transition-transform `+(R?`translate-x-3`:`translate-x-0.5`)})}),Z(R?`engine.studio.auto.enabled`:`engine.studio.auto.disabled`,a)]}),(0,Q.jsxs)(`button`,{onClick:L,disabled:!d||!P||!!b||r,title:r?Z(`engine.studio.pkg.readonlyHint`,a):void 0,className:`ml-auto inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs hover:bg-muted disabled:opacity-50`,children:[b===`draft`?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Ht,{className:`h-3.5 w-3.5`}),Z(`engine.studio.saveDraft`,a)]})]}),(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[o&&s&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>c(!1),"aria-hidden":`true`}),(0,Q.jsxs)(`nav`,{className:q(`flex w-52 shrink-0 flex-col overflow-auto border-r bg-background p-2`,o&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,o&&!s&&`-translate-x-full`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pb-1 pt-1`,children:[(0,Q.jsx)(`p`,{className:`flex-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.auto.heading`,a)}),!r&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{T(null),k(!0)},title:Z(`engine.studio.auto.newTitle`,a),className:`inline-flex items-center gap-0.5 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[(0,Q.jsx)(Sn,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,a)]})]}),l.length>0&&l.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>{f(e),o&&c(!1)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(d?.name===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(He,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),(0,Q.jsx)(zh,{state:ee[e.name],locale:a})]},e.name)),l.length===0&&!O&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(w?`engine.studio.loadFailed`:E?`engine.studio.auto.none`:`engine.studio.loading`,a)})]}),(0,Q.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-auto bg-muted/30 p-4`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex shrink-0 items-center gap-2`,children:[(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[11px] text-primary`,children:[(0,Q.jsx)(He,{className:`h-3 w-3`}),` `,Z(`engine.studio.auto.canvasHint`,a)]}),d&&(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`flow · `,d.name]})]}),w&&(0,Q.jsx)(`div`,{className:`mb-3 shrink-0 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line`,children:w}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 rounded-lg border bg-background p-4`,children:d?v?(0,Q.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`}),` `,Z(`engine.studio.loading`,a)]}):M?$.createElement(M,{type:d.type,name:d.name,draft:m,editing:!0,selection:g,onSelectionChange:_,onPatch:te,locale:a}):(0,Q.jsx)(`pre`,{className:`overflow-auto text-[11px] text-muted-foreground`,children:JSON.stringify(m,null,2)}):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.auto.pick`,a)})})]}),(0,Q.jsxs)(`aside`,{className:`w-72 shrink-0 overflow-auto border-l`,children:[(0,Q.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 px-3 py-2 backdrop-blur`,children:[(0,Q.jsx)(Yn,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.auto.config`,a)}),g&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>_(null),className:`ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.deselect`,a),children:(0,Q.jsx)(Se,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`div`,{className:`p-3`,children:g&&N&&d?$.createElement(N,{type:`flow`,name:d.name,draft:m,selection:g,onPatch:te,onClearSelection:()=>_(null),onSelectionChange:_,readOnly:!1,locale:a}):(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,Q.jsx)(ft,{className:`h-5 w-5`}),Z(`engine.studio.auto.emptyLine1`,a),(0,Q.jsx)(`br`,{}),Z(`engine.studio.auto.emptyLine2`,a)]})})]})]}),(0,Q.jsx)(Fm,{open:O,onOpenChange:k,title:Z(`engine.studio.auto.newTitle`,a),labelFieldLabel:Z(`engine.studio.auto.nameLabel`,a),labelPlaceholder:Z(`engine.studio.auto.namePlaceholder`,a),idFieldLabel:Z(`engine.studio.auto.idLabel`,a),idPlaceholder:Z(`engine.studio.auto.idPlaceholder`,a),submitLabel:Z(`engine.studio.createDraft`,a),submittingLabel:Z(`engine.studio.creating`,a),busy:A,error:w,locale:a,onSubmit:({label:e,name:t})=>void I(e,t)})]})}function Vh({packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r=!1,onDirtyChange:i}){let a=So(),o=bo(),s=sn(),[c,l]=$.useState(!1),[u,d]=$.useState([]),[f,p]=$.useState(!1),[m,h]=$.useState(null),[g,_]=$.useState(null),[v,y]=$.useState(!1),[b,x]=$.useState(null),S=$.useRef(!1),C=km($.useMemo(()=>v?{type:`owd`,name:`overview`}:g?{type:`permission`,name:g}:null,[v,g])),[w,T]=$.useState(``),[E,D]=$.useState(!1),[O,k]=$.useState(null),[A,j]=$.useState(!1),[M,N]=$.useState(!1),[P,ee]=$.useState(!1),[F,I]=$.useState(!1),te=P||F,L=$.useRef(i);$.useEffect(()=>{L.current=i}),$.useEffect(()=>{L.current?.(te)},[te]),$.useEffect(()=>()=>{L.current?.(!1)},[]);let R=$.useCallback(()=>!te||window.confirm(Z(`engine.edit.unsavedLeaveConfirm`,o)),[te,o]),z=$.useCallback(async()=>{try{let[t,n]=await Promise.all([a.list(`permission`,{packageId:e}),a.listDrafts({packageId:e,type:`permission`}).catch(()=>[])]),r=new Map;for(let e of t||[]){let t=String(e.name??e.id??``);t&&r.set(t,{name:t,label:String(e.label??e.name??``),isDefault:!!e.isDefault})}for(let e of n||[]){let t=String(e?.name??``);!t||r.has(t)||r.set(t,{name:t,label:t})}let i=[...r.values()];d(i),!S.current&&C?.type===`owd`&&(S.current=!0,y(!0));let o=Am(i,C,`permission`);_(e=>e??o?.name??i[0]?.name??null)}catch(e){h(Ms(e))}finally{p(!0)}},[a,e]);$.useEffect(()=>{z()},[z,t]);let ne=$.useCallback(async(t,r)=>{j(!0),k(null);try{await a.save(`permission`,r,Pm(r,t),{mode:`draft`,packageId:e}),X.success(xo(`engine.studio.access.created`,o,{label:t})),D(!1),n?.(),await z(),y(!1),_(r)}catch(e){k(Ms(e))}finally{j(!1)}},[a,z,e,n,o]),re=u.filter(e=>!w.trim()||e.label.toLowerCase().includes(w.trim().toLowerCase())||e.name.toLowerCase().includes(w.trim().toLowerCase()));return(0,Q.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,Q.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,o),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,Q.jsx)(Vt,{className:`h-4 w-4`})}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(rt,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:Z(`engine.studio.access.title`,o)}),(0,Q.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:Z(`engine.studio.access.subtitle`,o)})]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>N(!0),className:`ml-auto flex items-center gap-1.5 rounded-md border px-2 py-0.5 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(pt,{className:`h-3.5 w-3.5`}),Z(`engine.studio.access.explain.open`,o)]}),(0,Q.jsx)(`span`,{title:Z(`engine.studio.access.bannerTitle`,o),className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.access.banner`,o)})]}),!r&&(0,Q.jsx)(rs,{packageId:e,className:`mx-3 mt-2`,strings:{describe:e=>xo(e.anchor===`guest`?`engine.studio.access.suggestPromptGuest`:`engine.studio.access.suggestPromptEveryone`,o,{set:e.permission_set_name}),confirm:Z(`engine.studio.access.suggestConfirm`,o),confirming:Z(`engine.studio.access.suggestConfirming`,o),dismiss:Z(`engine.studio.access.suggestDismiss`,o),confirmedToast:e=>xo(`engine.studio.access.suggestConfirmedToast`,o,{set:e.permission_set_name,anchor:e.anchor}),dismissedToast:e=>xo(`engine.studio.access.suggestDismissedToast`,o,{set:e.permission_set_name})}}),(0,Q.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[s&&c&&(0,Q.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>l(!1),"aria-hidden":`true`}),(0,Q.jsxs)(`nav`,{className:q(`flex w-52 shrink-0 flex-col border-r bg-background`,s&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,s&&!c&&`-translate-x-full`),children:[(0,Q.jsx)(`div`,{className:`border-b p-2 pb-2`,children:(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{if(v){x(null),s&&l(!1);return}R()&&(y(!0),x(null),s&&l(!1))},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(v?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(Ie,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:Z(`engine.studio.owd.railLabel`,o)})]})}),(0,Q.jsxs)(`div`,{className:`p-2 pb-0`,children:[(0,Q.jsx)(`p`,{className:`px-2 pb-1 pt-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.heading`,o)}),(0,Q.jsx)(`input`,{value:w,onChange:e=>T(e.target.value),placeholder:Z(`engine.studio.access.search`,o),className:`mb-1 h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`})]}),(0,Q.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2 pt-1`,children:[u.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(m?`engine.studio.loadFailed`:f?`engine.studio.access.none`:`engine.studio.loading`,o)}),re.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>{if(!v&&g===e.name){s&&l(!1);return}R()&&(y(!1),_(e.name),s&&l(!1))},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(!v&&g===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(rt,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.isDefault&&(0,Q.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/60`,children:`default`})]},e.name))]}),(0,Q.jsx)(`div`,{className:`shrink-0 border-t p-2`,children:r?(0,Q.jsxs)(`p`,{title:Z(`engine.studio.pkg.readonlyHint`,o),className:`flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(rn,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,o)]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{R()&&(k(null),D(!0))},className:`flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(Sn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.access.new`,o)]})})]}),(0,Q.jsx)(`main`,{className:`min-w-0 flex-1 overflow-auto`,children:v?(0,Q.jsx)(lh,{client:a,packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r,locale:o,highlightObject:b,onDirtyChange:I}):g?(0,Q.jsx)(Ta,{type:`permission`,name:g,packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r,onDirtyChange:ee,embedded:!0,onOpenOwd:e=>{R()&&(x(e||null),y(!0))}},g):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:f&&u.length===0?Z(`engine.studio.access.emptyMain`,o):Z(`engine.studio.access.pick`,o)})})]}),(0,Q.jsx)(Dm,{open:M,onOpenChange:N,packageId:e}),(0,Q.jsx)(Fm,{open:E,onOpenChange:D,title:Z(`engine.studio.access.new`,o),labelFieldLabel:Z(`engine.studio.access.nameLabel`,o),labelPlaceholder:Z(`engine.studio.access.labelPlaceholder`,o),idFieldLabel:Z(`engine.studio.access.idLabel`,o),idPlaceholder:Z(`engine.studio.access.idPlaceholder`,o),submitLabel:Z(`engine.studio.create`,o),submittingLabel:Z(`engine.studio.creating`,o),busy:A,error:O,locale:o,onSubmit:({label:e,name:t})=>void ne(e,t)})]})}function Hh({value:e,onChange:t,onEnter:n,onEscape:r,placeholder:i,autoFocus:a,locale:o,testId:s}){let[c,l]=$.useState(!1),u=e.trim().length>0&&!ka.test(e.trim());return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`input`,{autoFocus:a,value:e,onChange:e=>{let{value:n,stripped:r}=Ia(e.target.value);l(r),t(n)},onKeyDown:e=>{e.key===`Enter`&&n?.(),e.key===`Escape`&&r?.()},placeholder:i,"data-testid":s,className:`h-7 w-full rounded-md border bg-background px-2 font-mono text-[11px] outline-none focus:ring-1 focus:ring-primary`}),c&&(0,Q.jsx)(`p`,{className:`text-[10px] text-amber-600 dark:text-amber-400`,"data-testid":`pkg-id-stripped`,children:Z(`engine.studio.pkg.idStrippedNotice`,o)}),u&&(0,Q.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,"data-testid":`pkg-id-format-hint`,children:Z(`engine.studio.pkg.idFormatHint`,o)})]})}function Uh(){let e=a(),t=bo(),[n,r]=$.useState(null),[i,o]=$.useState(null),[s,c]=$.useState(!1);$.useEffect(()=>{let e=!1;return Ca().then(t=>{e||r(t)}).catch(t=>{e||o(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let l=t=>e(`/studio/${encodeURIComponent(t)}/data`),u=n?.filter(e=>e.writable)??[],d=n?.filter(e=>!e.writable)??[],[f,p]=$.useState(null),[m,h]=$.useState(``),[g,_]=$.useState(``),[v,y]=$.useState(!1),[b,x]=$.useState(null),S=e=>{p(e.id),h(xo(`engine.studio.landing.dupDefaultName`,t,{name:e.name})),_(`${e.id}-copy`),x(null)},C=async()=>{if(!f)return;let e=g.trim(),n=m.trim();if(!(!ka.test(e)||!n)){y(!0),x(null);try{await wa(f,e,n),X.success(xo(`engine.studio.landing.dupCreated`,t,{name:n})),l(e)}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(!1)}}};return(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl p-6`,children:[(0,Q.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,Q.jsx)(Ne,{className:`h-4.5 w-4.5`})}),(0,Q.jsx)(`h1`,{className:`text-lg font-semibold`,children:Z(`engine.studio.landing.title`,t)})]}),(0,Q.jsx)(`p`,{className:`mb-5 max-w-2xl text-xs leading-5 text-muted-foreground`,children:Z(`engine.studio.landing.description`,t)}),i&&(0,Q.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive`,children:i}),(0,Q.jsx)(`h2`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.landing.mineHeading`,t)}),(0,Q.jsxs)(`div`,{className:`mb-6 grid grid-cols-1 gap-2.5 sm:grid-cols-2 lg:grid-cols-3`,children:[n===null&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,t)}),n!==null&&u.length===0&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.landing.noneWritable`,t)}),u.map(e=>(0,Q.jsxs)(`div`,{className:`rounded-lg border bg-background`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l(e.id),className:`flex min-w-0 flex-1 items-center gap-2.5 text-left`,children:[(0,Q.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,Q.jsx)(Ln,{className:`h-4 w-4`})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate text-[13px] font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:e.id})]})]}),(0,Q.jsx)(`span`,{className:`rounded bg-emerald-400/15 px-1.5 py-0.5 text-[10px] text-emerald-600 dark:text-emerald-300`,children:Z(`engine.studio.pkg.writable`,t)}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>f===e.id?p(null):S(e),title:Z(`engine.studio.landing.dupTitle`,t),className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[10px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,Q.jsx)(pn,{className:`h-3 w-3`}),` `,Z(`engine.studio.landing.dup`,t)]})]}),f===e.id&&(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 border-t px-3 py-2.5`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&C(),e.key===`Escape`&&p(null)},placeholder:Z(`engine.studio.landing.dupNamePlaceholder`,t),className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,Q.jsx)(Hh,{value:g,onChange:_,onEnter:()=>void C(),onEscape:()=>p(null),placeholder:Z(`engine.studio.landing.dupIdPlaceholder`,t),locale:t,testId:`pkg-dup-id-input`}),b&&(0,Q.jsx)(`p`,{className:`text-[10px] text-destructive`,children:b}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void C(),disabled:v||!m.trim()||!ka.test(g.trim()),className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[v?(0,Q.jsx)(Y,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(pn,{className:`h-3 w-3`}),Z(`engine.studio.landing.dupGo`,t)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>p(null),className:`rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,children:Z(`engine.studio.cancel`,t)})]})]})]},e.id)),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>c(!0),className:`flex items-center justify-center gap-1.5 rounded-lg border border-dashed px-3 py-2.5 text-xs text-muted-foreground hover:border-primary/50 hover:text-foreground`,children:[(0,Q.jsx)(Sn,{className:`h-4 w-4`}),` `,Z(`engine.studio.pkg.new`,t)]})]}),(0,Q.jsx)(Ma,{mode:`create`,open:s,onOpenChange:c,onSaved:e=>l(e.id)}),d.length>0&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`h2`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.landing.installedHeading`,t)}),(0,Q.jsx)(`div`,{className:`grid grid-cols-1 gap-2.5 sm:grid-cols-2 lg:grid-cols-3`,children:d.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>l(e.id),className:`flex items-center gap-2.5 rounded-lg border bg-muted/20 px-3 py-2.5 text-left hover:bg-muted/40`,children:[(0,Q.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground`,children:(0,Q.jsx)(Ln,{className:`h-4 w-4`})}),(0,Q.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`span`,{className:`block truncate text-[13px]`,children:e.name}),(0,Q.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:e.id})]}),(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:[(0,Q.jsx)(rn,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,t)]})]},e.id))})]})]})}var Wh=t({BuilderLanding:()=>Uh});export{ys as C,fs as D,Os as E,xs as S,Es as T,Ql as _,Wp as a,Uc as b,Fp as c,up as d,ep as f,gu as g,kd as h,Gp as i,Ap as l,Pd as m,Uh as n,Vp as o,jf as p,jh as r,Ip as s,Wh as t,kp as u,Al as v,Ds as w,Ss as x,Gc as y};