@objectstack/console 12.3.0 → 12.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/dist/.objectui-sha +1 -1
  2. package/dist/assets/{AdapterProvider-_4c7hk3d.js → AdapterProvider-qwVfmAEk.js} +1 -1
  3. package/dist/assets/{AiPendingActionsPage-Gc2Wh8Kh.js → AiPendingActionsPage-BRZ9smBE.js} +1 -1
  4. package/dist/assets/ApiConsolePage-V6XcLsX4.js +1 -0
  5. package/dist/assets/AppDocsIndex-C4IIeN6V.js +1 -0
  6. package/dist/assets/AppManagementPage-WCLo2V17.js +1 -0
  7. package/dist/assets/ApprovalsInboxPage-Cm6RlF50.js +1 -0
  8. package/dist/assets/{AuditLogPage-C-rDSpPt.js → AuditLogPage-BUapxa-t.js} +1 -1
  9. package/dist/assets/{ComponentNavView-DX23dzZd.js → ComponentNavView-CV-L0t8o.js} +1 -1
  10. package/dist/assets/ConsoleFloatingChatbot-mf-pVd3G.js +1 -0
  11. package/dist/assets/CreateViewDialog-CMNLzv6j.js +1 -0
  12. package/dist/assets/DashboardView-CPFt6TBZ.js +1 -0
  13. package/dist/assets/DashboardWidgetInspector-DknOds9r.js +1 -0
  14. package/dist/assets/DeveloperHubPage-CigDAiDQ.js +1 -0
  15. package/dist/assets/{ExpressionProvider-w-HoWEV1.js → ExpressionProvider-ODpzkcN3.js} +1 -1
  16. package/dist/assets/FlowRunsPage-QMVLQvu7.js +1 -0
  17. package/dist/assets/{IntegrationsPage-COvUlRq2.js → IntegrationsPage-D8453O8m.js} +2 -2
  18. package/dist/assets/InterfaceListPage-Dbt7lZbl.js +1 -0
  19. package/dist/assets/{ManagedByBadge-BZofhfqM.js → ManagedByBadge-BGSB7vGi.js} +1 -1
  20. package/dist/assets/MarketplaceAccessDenied-CAuxNcMw.js +1 -0
  21. package/dist/assets/MarketplaceInstalledPage-DIKAvmEt.js +1 -0
  22. package/dist/assets/MarketplacePackagePage-CiRyU-vK.js +4 -0
  23. package/dist/assets/MarketplacePage-SkUEdd3B.js +1 -0
  24. package/dist/assets/{MetadataInspector-CpceGXDL.js → MetadataInspector-RvnQ-QOT.js} +1 -1
  25. package/dist/assets/MetadataProvider-DKJsxrNu.js +1 -0
  26. package/dist/assets/{MonacoImpl-DoDns4Vj.js → MonacoImpl-nyLaER8_.js} +1 -1
  27. package/dist/assets/ObjectDataPage-CAJf6Pu3.js +1 -0
  28. package/dist/assets/PageView-GYrk78oW.js +1 -0
  29. package/dist/assets/ProfilePage-7etuxYZk.js +1 -0
  30. package/dist/assets/PublicFormsPage-DmpEEcq4.js +1 -0
  31. package/dist/assets/RecordDetailView-CzR6BAUv.js +9 -0
  32. package/dist/assets/{RecordFormPage-CbvOD5UT.js → RecordFormPage-DadWkJyX.js} +1 -1
  33. package/dist/assets/ReportDefaultInspector-CJGXWwWN.js +11 -0
  34. package/dist/assets/ReportView-CIZjxMSJ.js +2 -0
  35. package/dist/assets/{SearchResultsPage-D0nbmFox.js → SearchResultsPage-BPDjxMw8.js} +1 -1
  36. package/dist/assets/{SettingsHub-BsZee-2C.js → SettingsHub-ZMQjBQwP.js} +1 -1
  37. package/dist/assets/SettingsView-eCnpX1vu.js +1 -0
  38. package/dist/assets/SystemHubPage-2aGKeHcn.js +1 -0
  39. package/dist/assets/{abnfDiagram-VRR7QNED-DWrainSQ.js → abnfDiagram-VRR7QNED-o_fBNeYD.js} +1 -1
  40. package/dist/assets/architecture-TIHT7OUA-BF_0SrOH.js +1 -0
  41. package/dist/assets/{architectureDiagram-ZJ3FMSHR-BqIfH_cZ.js → architectureDiagram-ZJ3FMSHR-Bk_LES5L.js} +1 -1
  42. package/dist/assets/{assistantBus-DosfPCbN.js → assistantBus-BFk4fCbM.js} +1 -1
  43. package/dist/assets/{blockDiagram-677ZJIJ3-BDhRO3KX.js → blockDiagram-677ZJIJ3-BmONypzo.js} +1 -1
  44. package/dist/assets/{c4Diagram-LMCZKHZV-DBmvkEa3.js → c4Diagram-LMCZKHZV-DqIiaVjm.js} +1 -1
  45. package/dist/assets/channel-CvRTB8GE.js +1 -0
  46. package/dist/assets/{chunk-32BRIVSS-1_aHOdgh.js → chunk-32BRIVSS-BbTX8O4m.js} +1 -1
  47. package/dist/assets/{chunk-52WLFC77-C-mFgIG6.js → chunk-52WLFC77-DkgICN4F.js} +1 -1
  48. package/dist/assets/{chunk-C7G6YPKG-DvvI9WqY.js → chunk-C7G6YPKG-UMP_bNDd.js} +1 -1
  49. package/dist/assets/{chunk-EX3LRPZG-BaKE258M.js → chunk-EX3LRPZG-B0dJ64Ff.js} +1 -1
  50. package/dist/assets/{chunk-FWX5IMBZ-BZ1KYToN.js → chunk-FWX5IMBZ-B8cCL4T7.js} +1 -1
  51. package/dist/assets/{chunk-HOUHSVGY-BjQmUg1D.js → chunk-HOUHSVGY-B5nScni0.js} +1 -1
  52. package/dist/assets/{chunk-ICXQ74PX-DGFLQjwm.js → chunk-ICXQ74PX-zJg8KmvA.js} +1 -1
  53. package/dist/assets/{chunk-KEIR6QF5-MVybfwhZ.js → chunk-KEIR6QF5-CxDrFr0l.js} +3 -3
  54. package/dist/assets/{chunk-MOJQB5TN-aPZk6pC8.js → chunk-MOJQB5TN-DBKCpvOi.js} +1 -1
  55. package/dist/assets/{chunk-OGEWGWER-C_9e4OS0.js → chunk-OGEWGWER-bKk51Nxt.js} +1 -1
  56. package/dist/assets/{chunk-PUDLZKDR-c0kZKR-G.js → chunk-PUDLZKDR-CKn_9iXM.js} +1 -1
  57. package/dist/assets/{chunk-Q4XR5HBZ-o24M5lkF.js → chunk-Q4XR5HBZ-BP9atbVx.js} +1 -1
  58. package/dist/assets/{chunk-RYQCIY6F-DUMnfbFk.js → chunk-RYQCIY6F-B5RR1tIz.js} +1 -1
  59. package/dist/assets/{chunk-V7JOEXUC-BP0RE3_V.js → chunk-V7JOEXUC-DTerDTcg.js} +1 -1
  60. package/dist/assets/chunk-VAUOI2AC-BrcFPe7Z.js +1 -0
  61. package/dist/assets/{chunk-VR4S4FIN-DykLEeqy.js → chunk-VR4S4FIN-jB_W-MHs.js} +1 -1
  62. package/dist/assets/chunk-WYO6CB5R-Cndg0Yo5.js +127 -0
  63. package/dist/assets/chunk-XXDRQBXY-DGANY6E3.js +1 -0
  64. package/dist/assets/{chunk-ZGVPDNZ5-DQH9cJwj.js → chunk-ZGVPDNZ5-BUUSzPje.js} +1 -1
  65. package/dist/assets/classDiagram-OUVF2IWQ-BGL42sFI.js +1 -0
  66. package/dist/assets/classDiagram-v2-EOCWNBFH-BGL42sFI.js +1 -0
  67. package/dist/assets/{cose-bilkent-JH36ORCC-CDWwyRUu.js → cose-bilkent-JH36ORCC-DJ-X6wmF.js} +1 -1
  68. package/dist/assets/cynefin-VYW2F7L2-CXt4AgYW.js +1 -0
  69. package/dist/assets/{cynefinDiagram-TSTJHNR4-Dn83Cn2D.js → cynefinDiagram-TSTJHNR4-C5mKt5aU.js} +1 -1
  70. package/dist/assets/{cytoscape.esm-Djp6vQyU.js → cytoscape.esm-B3I8pqwA.js} +1 -1
  71. package/dist/assets/{dagre-VKFMJZFB-DYKhgtL2.js → dagre-VKFMJZFB-Crs38V5P.js} +2 -2
  72. package/dist/assets/data-adapter-Bm8GGtft.js +7 -0
  73. package/dist/assets/{diagram-FQU43EPY-84kGXmcJ.js → diagram-FQU43EPY-Bkx8ccpS.js} +1 -1
  74. package/dist/assets/{diagram-G47NLZAW-FzYRzXJF.js → diagram-G47NLZAW-CSNJrWDK.js} +1 -1
  75. package/dist/assets/{diagram-NH7WQ7WH-D2_7Upma.js → diagram-NH7WQ7WH-PaRAbfdR.js} +1 -1
  76. package/dist/assets/{diagram-OA4YK3LP-uqOHgtNB.js → diagram-OA4YK3LP-C2A07yOA.js} +1 -1
  77. package/dist/assets/{diagram-WEI45ONY-BoLpoJXF.js → diagram-WEI45ONY-BEyyGNpU.js} +1 -1
  78. package/dist/assets/{dist-CfcbLQde.js → dist-YwlXXOlT.js} +1 -1
  79. package/dist/assets/{ebnfDiagram-CCIWWBDH-DLYgN3Ab.js → ebnfDiagram-CCIWWBDH-CtfwkNuv.js} +1 -1
  80. package/dist/assets/{erDiagram-Q63AITRT-BmagGyFR.js → erDiagram-Q63AITRT-DjK6P1sf.js} +1 -1
  81. package/dist/assets/eventmodeling-45OFAUF4-Dmacb12o.js +1 -0
  82. package/dist/assets/{exceljs.min-DIyttv_G.js → exceljs.min-Dpb6mnud.js} +2 -2
  83. package/dist/assets/flowDiagram-23GEKE2U-DfQvGNQk.js +1 -0
  84. package/dist/assets/framework-B3O15Lsq.js +36 -0
  85. package/dist/assets/{ganttDiagram-NO4QXBWP-DdGzwLRB.js → ganttDiagram-NO4QXBWP-UPhpWlEd.js} +1 -1
  86. package/dist/assets/getIcon-B5xaQx5N.js +1 -0
  87. package/dist/assets/gitGraph-TEB2WS4Q-ChM6j6Bd.js +1 -0
  88. package/dist/assets/{gitGraphDiagram-IHSO6WYX-Dv8qb0qh.js → gitGraphDiagram-IHSO6WYX-B6Qcltd9.js} +2 -2
  89. package/dist/assets/{highlighted-body-OFNGDK62-CLUabCIi.js → highlighted-body-OFNGDK62-B_roNkgm.js} +1 -1
  90. package/dist/assets/index-BXgUF5nO.css +2 -0
  91. package/dist/assets/index-PrzZHiAk.js +2 -0
  92. package/dist/assets/info-DKCQHKI2-C0RTkygr.js +1 -0
  93. package/dist/assets/{infoDiagram-FWYZ7A6U-BnI8Gbdt.js → infoDiagram-FWYZ7A6U-CgEoZeWY.js} +1 -1
  94. package/dist/assets/infrastructure-Bcx6-8du.js +3 -0
  95. package/dist/assets/{ishikawaDiagram-FXEZZL3T-BfpmvVA0.js → ishikawaDiagram-FXEZZL3T-DvmRhm8H.js} +1 -1
  96. package/dist/assets/{journeyDiagram-5HDEW3XC-8UQvh7pY.js → journeyDiagram-5HDEW3XC-DFf6bjOX.js} +2 -2
  97. package/dist/assets/{kanban-definition-HUTT4EX6-CFX7QbbK.js → kanban-definition-HUTT4EX6-DLK5X8Ol.js} +1 -1
  98. package/dist/assets/maplibre-gl-R0DO2NBr.js +748 -0
  99. package/dist/assets/{marketplaceApi-BLyDDfGk.js → marketplaceApi-zYQofLEk.js} +1 -1
  100. package/dist/assets/mermaid-GHXKKRXX-B7uCX_yo.js +1 -0
  101. package/dist/assets/{mermaid-parser.core-qFqgm_H6.js → mermaid-parser.core-DV_Ys_OF.js} +2 -2
  102. package/dist/assets/{mermaid.core-T8rJXbMH.js → mermaid.core-D3axazyv.js} +2 -2
  103. package/dist/assets/metadata-admin-CleGXds3.js +22 -0
  104. package/dist/assets/{mindmap-definition-LN4V7U3C-BmcygCh7.js → mindmap-definition-LN4V7U3C-DwbonLR_.js} +1 -1
  105. package/dist/assets/packet-7NZHBO7P-DSHvkxBR.js +1 -0
  106. package/dist/assets/{pegDiagram-2B236MQR-D3IbyQE9.js → pegDiagram-2B236MQR-B4IMkAIV.js} +1 -1
  107. package/dist/assets/pie-RZYD4A2V-DjNUdL88.js +1 -0
  108. package/dist/assets/{pieDiagram-ENE6RG2P-BZteOl-k.js → pieDiagram-ENE6RG2P-D8jBhNXT.js} +1 -1
  109. package/dist/assets/plugin-calendar-BKbWgkod.js +1 -0
  110. package/dist/assets/plugin-charts-BZo5ApEF.js +7 -0
  111. package/dist/assets/plugin-chatbot-D2Uv-hn9.js +120 -0
  112. package/dist/assets/plugin-dashboard-CRFZp7gC.js +6 -0
  113. package/dist/assets/plugin-form-FeZEoC2R.js +1 -0
  114. package/dist/assets/plugin-gantt-D9YRdBGD.js +93 -0
  115. package/dist/assets/plugin-grid-eiIl2HN_.js +8 -0
  116. package/dist/assets/plugin-kanban-3rFMGC21.js +1 -0
  117. package/dist/assets/plugin-map-BHQrQ_Wu.js +1 -0
  118. package/dist/assets/{plugin-markdown-CWbusz5W.js → plugin-markdown-DesFSRDB.js} +1 -1
  119. package/dist/assets/{plugin-report-Cy6FwNfk.js → plugin-report-BKD6SOp5.js} +4 -4
  120. package/dist/assets/plugin-timeline-BrkABjqu.js +1 -0
  121. package/dist/assets/{plugin-tree-CtakCCIf.js → plugin-tree-CKck3lEJ.js} +1 -1
  122. package/dist/assets/plugin-view-BJ9uLrnO.js +1 -0
  123. package/dist/assets/plugins-views-CibWNUsP.js +4 -0
  124. package/dist/assets/{quadrantDiagram-ABIIQ3AL-DPVvulM5.js → quadrantDiagram-ABIIQ3AL-Do3adYzz.js} +1 -1
  125. package/dist/assets/radar-I7S5WNFK-qO0bWLwF.js +1 -0
  126. package/dist/assets/railroad-3IZDKUUU-CAj9esX-.js +1 -0
  127. package/dist/assets/railroad-abnf-AHOZXSZD-Ci_Yg729.js +1 -0
  128. package/dist/assets/railroad-ebnf-EBAXGLYW-Tz7H2Jrw.js +1 -0
  129. package/dist/assets/railroad-peg-LSFZ7HO6-BJIalSaK.js +1 -0
  130. package/dist/assets/{railroadDiagram-RFXS5EU6-CgLSy8wn.js → railroadDiagram-RFXS5EU6-DDA7XtKq.js} +1 -1
  131. package/dist/assets/{requirementDiagram-TGXJPOKE-DYX2pMfn.js → requirementDiagram-TGXJPOKE-CClkXauU.js} +1 -1
  132. package/dist/assets/{sankeyDiagram-HTMAVEWB-amvhkMhz.js → sankeyDiagram-HTMAVEWB-DlUFch6E.js} +1 -1
  133. package/dist/assets/{sequenceDiagram-DBY2YBRQ-CPxWMCbb.js → sequenceDiagram-DBY2YBRQ-BEDTwji4.js} +1 -1
  134. package/dist/assets/{skeletons-BK6x7CYd.js → skeletons-CzC0fiXD.js} +1 -1
  135. package/dist/assets/src-BBieSqPB.js +16 -0
  136. package/dist/assets/{src-BPEDMjfw.js → src-BeTFx9-N.js} +1 -1
  137. package/dist/assets/{src-BvIm_4jD.js → src-CSRoqdRD.js} +1 -1
  138. package/dist/assets/{src-6rOMKMLU.js → src-D0ZYDfff.js} +1 -1
  139. package/dist/assets/{stateDiagram-2N3HPSRC-DkFPpTq2.js → stateDiagram-2N3HPSRC-BN6M4MGy.js} +1 -1
  140. package/dist/assets/stateDiagram-v2-6OUMAXLB-DCaXJLPh.js +1 -0
  141. package/dist/assets/{swimlanes-5IMT3BWC-DMPnpahc.js → swimlanes-5IMT3BWC-Bycq06w3.js} +1 -1
  142. package/dist/assets/swimlanesDiagram-G3AALYLV-DWFAvAh7.js +8 -0
  143. package/dist/assets/{timeline-definition-FHXFAJF6-DMhg5ZmV.js → timeline-definition-FHXFAJF6-B6Oiv_gP.js} +1 -1
  144. package/dist/assets/treeView-QDETBFTQ-Cc2FYETg.js +1 -0
  145. package/dist/assets/treemap-6X3UGDF4-a4EjGpO3.js +1 -0
  146. package/dist/assets/{types-X8W-qTHJ.js → types-UYoEctl-.js} +1 -1
  147. package/dist/assets/ui-components-rkvkkTxO.js +42 -0
  148. package/dist/assets/{ui-layout-BdFgfR9C.js → ui-layout-CAjjF5_S.js} +1 -1
  149. package/dist/assets/{useMetadata-DAEfn7ks.js → useMetadata-Ily0JuNR.js} +1 -1
  150. package/dist/assets/useOpenRecordList-tyj2_1bm.js +1 -0
  151. package/dist/assets/{usePackageL10n-CasuagU5.js → usePackageL10n-CiFMHfKe.js} +1 -1
  152. package/dist/assets/{useReconcileOnError-CtvIPgmD.js → useReconcileOnError-_XnUvYJA.js} +1 -1
  153. package/dist/assets/{useRecordApprovals-BHkgfYJW.js → useRecordApprovals-obyIj2_8.js} +1 -1
  154. package/dist/assets/vendor-charts-D_CNNxD5.js +67 -0
  155. package/dist/assets/vendor-dndkit-CzBh0_98.js +5 -0
  156. package/dist/assets/vendor-i18n-B6GOGCem.js +1 -0
  157. package/dist/assets/{vendor-icons-core-CPQTXONm.js → vendor-icons-core-DvLgTVYc.js} +1 -1
  158. package/dist/assets/{vendor-markdown-Cbritblm.js → vendor-markdown-BJvgKhXw.js} +18 -18
  159. package/dist/assets/vendor-objectstack-Bw0HRuFa.js +95 -0
  160. package/dist/assets/vendor-radix-DCTEpigg.js +46 -0
  161. package/dist/assets/vendor-react-BGDDiZfJ.js +13 -0
  162. package/dist/assets/vendor-sentry-CHRc7_3y.js +501 -0
  163. package/dist/assets/{vendor-ui-utils-C1OpMExs.js → vendor-ui-utils-BzQBRdq3.js} +1 -1
  164. package/dist/assets/{vennDiagram-L72KCM5P-BCn9MNWT.js → vennDiagram-L72KCM5P-DqRcgOxS.js} +1 -1
  165. package/dist/assets/wardley-OPB4EBWU-CuNyH0xZ.js +1 -0
  166. package/dist/assets/{wardleyDiagram-EHGQE667-ShqmBgOZ.js → wardleyDiagram-EHGQE667-BDyIMWfB.js} +1 -1
  167. package/dist/assets/{xychartDiagram-FW5EYKEG-D1hShMP_.js → xychartDiagram-FW5EYKEG-BRNQk20I.js} +1 -1
  168. package/dist/index.html +6 -6
  169. package/package.json +1 -1
  170. package/dist/assets/ApiConsolePage-CmiLmtuU.js +0 -1
  171. package/dist/assets/AppDocsIndex-CG7e4V2y.js +0 -1
  172. package/dist/assets/AppManagementPage-C7T-9Exg.js +0 -1
  173. package/dist/assets/ApprovalsInboxPage-D9PFFxKD.js +0 -1
  174. package/dist/assets/ConsoleFloatingChatbot-CmLazUxX.js +0 -1
  175. package/dist/assets/CreateViewDialog-6JmiAMxS.js +0 -1
  176. package/dist/assets/DashboardView-Al7ce4gm.js +0 -1
  177. package/dist/assets/DashboardWidgetInspector-BmIMgSGO.js +0 -1
  178. package/dist/assets/DeveloperHubPage-D8eYekI9.js +0 -1
  179. package/dist/assets/FlowRunsPage-Hs5i7s3C.js +0 -1
  180. package/dist/assets/InterfaceListPage-JNxR3qlQ.js +0 -1
  181. package/dist/assets/MarketplaceAccessDenied-Cur1UQ0U.js +0 -1
  182. package/dist/assets/MarketplaceInstalledPage-D9ow2tlx.js +0 -1
  183. package/dist/assets/MarketplacePackagePage-0AKyKbMD.js +0 -4
  184. package/dist/assets/MarketplacePage-DUzZZa8D.js +0 -1
  185. package/dist/assets/MetadataProvider-MNkZn-bR.js +0 -1
  186. package/dist/assets/ObjectDataPage-CUJksP8e.js +0 -1
  187. package/dist/assets/PageView-AS6xg5z-.js +0 -1
  188. package/dist/assets/ProfilePage-iJeMD7FK.js +0 -1
  189. package/dist/assets/PublicFormsPage-C-wbtEXG.js +0 -1
  190. package/dist/assets/RecordDetailView-Ba0xool8.js +0 -9
  191. package/dist/assets/ReportDefaultInspector-OSqdhKEL.js +0 -11
  192. package/dist/assets/ReportView-Df7cdlQo.js +0 -2
  193. package/dist/assets/SettingsView-CSBwd4YP.js +0 -1
  194. package/dist/assets/SystemHubPage-n41ly_cC.js +0 -1
  195. package/dist/assets/architecture-TIHT7OUA-D3WxD8aQ.js +0 -1
  196. package/dist/assets/channel-MM6d7ooS.js +0 -1
  197. package/dist/assets/chunk-VAUOI2AC-Bgyec1On.js +0 -1
  198. package/dist/assets/chunk-WYO6CB5R-BBbafnWJ.js +0 -127
  199. package/dist/assets/chunk-XXDRQBXY-V26l8fww.js +0 -1
  200. package/dist/assets/classDiagram-OUVF2IWQ-BOtUpfWB.js +0 -1
  201. package/dist/assets/classDiagram-v2-EOCWNBFH-BOtUpfWB.js +0 -1
  202. package/dist/assets/cynefin-VYW2F7L2-v0nc1IZv.js +0 -1
  203. package/dist/assets/data-adapter-W6WwA2ln.js +0 -7
  204. package/dist/assets/eventmodeling-45OFAUF4-CHsG6T7D.js +0 -1
  205. package/dist/assets/flowDiagram-23GEKE2U-BZtO2Jjx.js +0 -1
  206. package/dist/assets/framework-B9PMswdm.js +0 -36
  207. package/dist/assets/getIcon-DkcFniPV.js +0 -1
  208. package/dist/assets/gitGraph-TEB2WS4Q-DEB3Nljf.js +0 -1
  209. package/dist/assets/index-Oki50z-M.js +0 -2
  210. package/dist/assets/index-rbBh03NP.css +0 -2
  211. package/dist/assets/info-DKCQHKI2-BMNzABlv.js +0 -1
  212. package/dist/assets/infrastructure-BnbfcrX8.js +0 -3
  213. package/dist/assets/maplibre-gl-DGbvC0OV.js +0 -748
  214. package/dist/assets/mermaid-GHXKKRXX-Df_DEhBm.js +0 -1
  215. package/dist/assets/metadata-admin-DiOg8Tx8.js +0 -22
  216. package/dist/assets/packet-7NZHBO7P-CVEX3X_K.js +0 -1
  217. package/dist/assets/pie-RZYD4A2V-VzBvughO.js +0 -1
  218. package/dist/assets/plugin-calendar-CVeG5Hhb.js +0 -1
  219. package/dist/assets/plugin-charts-BTfOaZVx.js +0 -7
  220. package/dist/assets/plugin-chatbot-COpsZSy4.js +0 -120
  221. package/dist/assets/plugin-dashboard-Bi5WrqPG.js +0 -6
  222. package/dist/assets/plugin-form-CzotVFc-.js +0 -1
  223. package/dist/assets/plugin-gantt-BUcqVYxX.js +0 -93
  224. package/dist/assets/plugin-grid-BXfwTczT.js +0 -8
  225. package/dist/assets/plugin-kanban-Dw_QTU-e.js +0 -1
  226. package/dist/assets/plugin-map-D89OX2_H.js +0 -1
  227. package/dist/assets/plugin-timeline-BAImk_4t.js +0 -1
  228. package/dist/assets/plugin-view-DZC_ZJtv.js +0 -1
  229. package/dist/assets/plugins-views-CxFTNQJ7.js +0 -4
  230. package/dist/assets/radar-I7S5WNFK-BvMfKOT_.js +0 -1
  231. package/dist/assets/railroad-3IZDKUUU-DfKQD3PJ.js +0 -1
  232. package/dist/assets/railroad-abnf-AHOZXSZD-DVyrJPzV.js +0 -1
  233. package/dist/assets/railroad-ebnf-EBAXGLYW-Cri8VQ5d.js +0 -1
  234. package/dist/assets/railroad-peg-LSFZ7HO6-Bmvxxxt6.js +0 -1
  235. package/dist/assets/src-CCztNT-4.js +0 -15
  236. package/dist/assets/stateDiagram-v2-6OUMAXLB-C_tQckF_.js +0 -1
  237. package/dist/assets/swimlanesDiagram-G3AALYLV-BLVdl7Q4.js +0 -8
  238. package/dist/assets/treeView-QDETBFTQ-Cz0fwXom.js +0 -1
  239. package/dist/assets/treemap-6X3UGDF4-BlqJD81v.js +0 -1
  240. package/dist/assets/ui-components-DsYvPIox.js +0 -42
  241. package/dist/assets/useOpenRecordList-DL3H_OJi.js +0 -1
  242. package/dist/assets/vendor-charts-DVOdzzh2.js +0 -67
  243. package/dist/assets/vendor-dndkit-0M_nRjzm.js +0 -5
  244. package/dist/assets/vendor-i18n-sU23bKX1.js +0 -1
  245. package/dist/assets/vendor-objectstack-sPlD8LgO.js +0 -95
  246. package/dist/assets/vendor-radix-DniuRzL-.js +0 -46
  247. package/dist/assets/vendor-react-slxo-5GC.js +0 -11
  248. package/dist/assets/vendor-sentry-BnfuR4xu.js +0 -501
  249. package/dist/assets/wardley-OPB4EBWU-DdYQ8RHK.js +0 -1
@@ -0,0 +1,16 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css","./index-BXgUF5nO.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-BGDDiZfJ.js";import{d as g,f as _,m as v,n as y,o as b}from"./infrastructure-Bcx6-8du.js";import{H as x,J as S,Kt as C,L as w,R as T,Vt as E,Y as D,_ as O,a as k,b as A,ct as j,d as M,f as N,it as P,l as F,n as I,q as ee,x as te}from"./framework-B3O15Lsq.js";import{d as L,u as ne}from"./vendor-objectstack-Bw0HRuFa.js";import{$a as re,$s as ie,Ar as ae,At as oe,B as se,Bn as R,Bo as ce,Br as z,Bs as le,Bt as B,Ca as V,Cc as ue,Ci as de,Ct as fe,Dr as pe,Ei as me,Eo as H,Es as he,Et as ge,Fa as U,Fc as _e,Fo as ve,G as W,Gn as ye,Gt as be,Hn as xe,Hr as Se,Hs as Ce,Ht as we,Ii as Te,In as Ee,Ir as De,Is as Oe,J as ke,Jn as Ae,Jo as je,Jt as G,Kn as Me,Ko as Ne,Kt as Pe,La as Fe,Li as Ie,Ln as Le,Lr as Re,Mo as K,Mr as ze,N as Be,Nt as Ve,Oa as He,Oc as Ue,Oi as We,Or as Ge,Ot as Ke,Pa as qe,Pi as Je,Ps as Ye,Ra as Xe,Rn as Ze,Rr as Qe,Rt as $e,Sa as et,Si as tt,Ss as nt,St as rt,Ti as it,Ts as at,Tt as ot,Un as st,Us as q,Ut as ct,V as lt,Vi as ut,Vn as dt,Vo as ft,Vr as pt,Vt as mt,W as ht,Wn as gt,Wr as _t,Ws as vt,Wt as yt,Xa as bt,Xt as xt,Ya as St,Yi as Ct,Yo as wt,Yt as Tt,Za as Et,Zs as Dt,Zt as Ot,_a as kt,_i as At,_n as jt,_r as Mt,ai as Nt,an as Pt,ar as Ft,bi as It,bo as Lt,bt as Rt,cc as zt,ci as Bt,cr as Vt,cs as Ht,ct as Ut,da as Wt,dn as Gt,do as Kt,ds as qt,dt as Jt,fa as Yt,fc as Xt,fi as Zt,fn as Qt,fr as $t,gn as en,go as tn,gr as nn,gs as rn,hi as an,hn as on,hr as sn,hs as cn,ii as ln,in as un,io as dn,ja as fn,ji as pn,jr as mn,js as hn,jt as gn,k as _n,ka as vn,kc as yn,kt as bn,la as xn,li as Sn,lo as Cn,ls as wn,lt as Tn,mn as En,mo as Dn,mr as On,ms as kn,na as An,nc as jn,ns as Mn,oc as Nn,oi as Pn,on as Fn,or as In,pi as Ln,pn as Rn,pr as zn,ps as Bn,qa as Vn,qn as Hn,qo as Un,qr as Wn,qs as Gn,qt as Kn,ri as qn,sn as Jn,sr as Yn,uc as Xn,ut as Zn,vo as Qn,vr as $n,w as er,wi as tr,wt as nr,xa as rr,xc as ir,xn as ar,xo as or,xr as J,xt as sr,yr as cr,za as Y,zn as lr,zs as ur,zt as dr}from"./ui-components-rkvkkTxO.js";import{n as fr,r as X}from"./vendor-ui-utils-BzQBRdq3.js";import{r as pr}from"./data-adapter-Bm8GGtft.js";import{t as mr}from"./AdapterProvider-qwVfmAEk.js";import{n as hr,t as gr}from"./plugin-form-FeZEoC2R.js";import{a as _r,i as vr,n as yr,r as br,t as xr}from"./MetadataProvider-DKJsxrNu.js";import{n as Sr,s as Cr}from"./assistantBus-BFk4fCbM.js";import{n as wr,r as Tr,t as Er}from"./ExpressionProvider-ODpzkcN3.js";import{a as Dr,c as Or,d as kr,g as Ar,h as jr,l as Mr,m as Nr,n as Pr,o as Fr,p as Ir,r as Lr,t as Rr,u as zr}from"./useReconcileOnError-_XnUvYJA.js";import{a as Br,c as Vr,i as Hr,n as Ur,o as Wr,r as Gr,s as Kr}from"./useRecordApprovals-obyIj2_8.js";import{a as qr,i as Jr,n as Yr,r as Xr,t as Zr}from"./recordFormNavigation-8nEYNxNo.js";import{S as Qr,_ as $r,a as ei,b as ti,d as ni,f as ri,g as ii,h as ai,i as oi,m as si,p as ci,t as li,u as ui,v as di,x as fi,y as pi}from"./plugin-chatbot-D2Uv-hn9.js";import{C as mi,S as hi,_ as gi,a as _i,b as vi,c as yi,d as bi,f as xi,g as Si,h as Ci,i as wi,l as Ti,m as Ei,n as Di,o as Oi,p as ki,r as Ai,s as ji,u as Mi,v as Ni,w as Pi,x as Fi,y as Ii}from"./metadata-admin-CleGXds3.js";import{C as Li,D as Ri,E as zi,S as Bi,T as Vi,_ as Hi,b as Ui,d as Wi,f as Gi,g as Ki,h as qi,m as Ji,p as Yi,t as Xi,v as Zi,w as Qi,x as $i,y as ea}from"./RecordDetailView-CzR6BAUv.js";import{n as ta,v as na,x as ra,y as ia}from"./marketplaceApi-zYQofLEk.js";import{n as aa,r as oa,t as sa}from"./ui-layout-CAjjF5_S.js";import{_ as ca,a as la,c as ua,d as da,g as fa,h as pa,l as ma,n as ha,o as ga,s as _a,t as va,u as ya,v as ba,y as xa}from"./vendor-dndkit-CzBh0_98.js";import{r as Sa}from"./useMetadata-Ily0JuNR.js";import{G as Ca,H as wa,J as Ta,K as Ea,L as Da,R as Oa,U as ka,W as Aa,X as ja,Y as Ma,b as Na,h as Pa,q as Fa,v as Ia,w as La,y as Z,z as Ra}from"./ReportDefaultInspector-CJGXWwWN.js";import{n as za,r as Ba,t as Va}from"./appRoute-CbCiASix.js";import{t as Ha}from"./getIcon-B5xaQx5N.js";import{t as Ua}from"./utils-Bixzg6Bz.js";import{n as Wa,r as Ga,t as Ka}from"./MetadataInspector-RvnQ-QOT.js";import{n as qa,t as Ja}from"./CreateViewDialog-CMNLzv6j.js";import{o as Ya,s as Xa}from"./InterfaceListPage-Dbt7lZbl.js";import{l as Za}from"./plugins-views-CibWNUsP.js";import{c as Qa,d as $a,l as eo,u as to}from"./plugin-view-BJ9uLrnO.js";import{r as no,t as ro}from"./runtime-metadata-persistence-D1KKivGr.js";import{n as io}from"./useOpenRecordList-tyj2_1bm.js";import{t as ao}from"./ManagedByBadge-BGSB7vGi.js";import{a as oo,i as so,n as co,r as lo}from"./PageView-GYrk78oW.js";import"./RecordFormPage-DadWkJyX.js";import"./DashboardView-CPFt6TBZ.js";import"./ReportView-CIZjxMSJ.js";import"./SearchResultsPage-BPDjxMw8.js";import"./MarketplacePage-SkUEdd3B.js";import"./MarketplacePackagePage-CiRyU-vK.js";import"./MarketplaceInstalledPage-DIKAvmEt.js";import{n as uo}from"./componentRegistry-ByxoJqMW.js";var Q=f(),$=e(h(),1),fo=(0,$.createContext)({theme:`system`,setTheme:()=>null});function po({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)(fo.Provider,{...r,value:o,children:e})}var mo=()=>{let e=(0,$.useContext)(fo);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function ho(){return typeof document<`u`&&document.documentElement.lang?.startsWith(`zh`)||typeof navigator<`u`&&navigator.language?.startsWith(`zh`)?M.console:N.console}function go({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,$.useState)(0),o=ho(),s=(0,$.useMemo)(()=>[o.loadingSteps.connecting,o.loadingSteps.loadingConfig,o.loadingSteps.preparingWorkspace],[o]);return(0,$.useEffect)(()=>{if(e||t)return;let n=setInterval(()=>{a(e=>Math.min(e+1,s.length-1))},1200);return()=>clearInterval(n)},[e,t,s.length]),(0,Q.jsx)(`div`,{className:`flex flex-col items-center justify-center h-screen bg-background`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-6`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-primary/20 rounded-2xl blur-xl animate-pulse`}),(0,Q.jsx)(`div`,{className:`relative bg-linear-to-br from-primary to-primary/80 p-4 rounded-2xl shadow-lg`,children:(0,Q.jsx)(Mn,{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:ia()}),(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)(Ye,{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)(ut,{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)(se,{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)(hn,{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 _o=Vi();function vo(){let{remediationRequired:e}=_();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)(bo,{message:e.message}):(0,Q.jsx)(So,{message:e.message})})}):null}function yo(){let{signOut:e}=_();return(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{e()},className:`mt-4 w-full text-center text-xs text-muted-foreground hover:text-foreground hover:underline`,children:`Sign out instead`})}function bo({message:e}){let{changePassword:t,setRemediationRequired:n}=_(),[r,i]=(0,$.useState)(``),[a,o]=(0,$.useState)(``),[s,c]=(0,$.useState)(``),[l,u]=(0,$.useState)(!1),[d,f]=(0,$.useState)(null);return(0,Q.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),f(null),a!==s){f(`New passwords do not match.`);return}u(!0);try{await t(r,a),n(null),window.location.reload()}catch(e){f(e instanceof Error?e.message:`Could not change password.`),u(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Your password has expired`}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||`Please set a new password to continue.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Gt,{htmlFor:`rem-cur`,children:`Current password`}),(0,Q.jsx)(Jn,{id:`rem-cur`,type:`password`,autoComplete:`current-password`,value:r,onChange:e=>i(e.target.value),required:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Gt,{htmlFor:`rem-new`,children:`New password`}),(0,Q.jsx)(Jn,{id:`rem-new`,type:`password`,autoComplete:`new-password`,value:a,onChange:e=>o(e.target.value),required:!0})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Gt,{htmlFor:`rem-conf`,children:`Confirm new password`}),(0,Q.jsx)(Jn,{id:`rem-conf`,type:`password`,autoComplete:`new-password`,value:s,onChange:e=>c(e.target.value),required:!0})]}),d?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:d}):null,(0,Q.jsx)(J,{type:`submit`,className:`w-full`,disabled:l,children:l?`Updating…`:`Change password & continue`}),(0,Q.jsx)(yo,{})]})}function xo({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,_o.toCanvas)(t,e,{width:184,margin:1},e=>{e&&n(e.message)})}})})}function So({message:e}){let{enrollTotp:t,verifyTotp:n,setRemediationRequired:r}=_(),[i,a]=(0,$.useState)(`password`),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(``),[u,d]=(0,$.useState)(``),[f,p]=(0,$.useState)([]),[m,h]=(0,$.useState)(!1),[g,v]=(0,$.useState)(null);return i===`password`?(0,Q.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),h(!0);try{let{totpURI:e,backupCodes:n}=await t(o);d(e),p(n??[]),a(`verify`)}catch(e){v(e instanceof Error?e.message:`Could not start enrollment.`)}finally{h(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Set up two-factor authentication`}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||`Your organization requires an authenticator app to continue.`})]}),(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Gt,{htmlFor:`rem-pw`,children:`Confirm your password`}),(0,Q.jsx)(Jn,{id:`rem-pw`,type:`password`,autoComplete:`current-password`,value:o,onChange:e=>s(e.target.value),required:!0})]}),g?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:g}):null,(0,Q.jsx)(J,{type:`submit`,className:`w-full`,disabled:m,children:m?`Preparing…`:`Continue`}),(0,Q.jsx)(yo,{})]}):(0,Q.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),h(!0);try{await n(c.trim()),r(null),window.location.reload()}catch(e){v(e instanceof Error?e.message:`Invalid code. Try again.`),h(!1)}},className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-lg font-semibold`,children:`Scan with your authenticator`}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Scan this QR code with Google Authenticator, 1Password, Authy, etc., then enter the 6-digit code.`})]}),u?(0,Q.jsx)(xo,{uri:u}):null,f.length>0?(0,Q.jsxs)(`details`,{className:`rounded-md border bg-muted/40 p-3 text-xs`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer font-medium`,children:`Save your backup codes`}),(0,Q.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:`Store these somewhere safe — each can be used once if you lose your device.`}),(0,Q.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 font-mono`,children:f.map(e=>(0,Q.jsx)(`span`,{children:e},e))})]}):null,(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[(0,Q.jsx)(Gt,{htmlFor:`rem-code`,children:`6-digit code`}),(0,Q.jsx)(Jn,{id:`rem-code`,inputMode:`numeric`,autoComplete:`one-time-code`,maxLength:8,placeholder:`123456`,value:c,onChange:e=>l(e.target.value),required:!0})]}),g?(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,children:g}):null,(0,Q.jsx)(J,{type:`submit`,className:`w-full`,disabled:m,children:m?`Verifying…`:`Verify & continue`}),(0,Q.jsx)(yo,{})]})}function Co(){return(0,Q.jsx)(go,{})}function wo({dataSource:e,children:t}){let{modalHandler:n,modalElement:r}=Hr(e);return(0,Q.jsxs)(x,{onModal:n,children:[t,r]})}function To({children:e}){return(0,Q.jsx)(po,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,Q.jsx)(zi,{children:(0,Q.jsx)(Kr,{children:(0,Q.jsx)(Ur,{children:(0,Q.jsxs)(Br,{children:[(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(Co,{}),children:e}),(0,Q.jsx)(vo,{})]})})})})})}function Eo({children:e}){return(0,Q.jsx)(mr,{children:(0,Q.jsx)(br,{children:(0,Q.jsx)(Do,{children:e})})})}function Do({children:e}){let t=w(),{language:n}=F(),r=(0,$.useRef)(null);return t&&r.current!==null&&r.current!==n&&t.clearCache?.(),t&&(r.current=n),t?(0,Q.jsx)(P,{dataSource:t,children:(0,Q.jsxs)(xr,{adapter:t,children:[(0,Q.jsx)(Oo,{}),(0,Q.jsx)(wo,{dataSource:t,children:e})]},n)}):(0,Q.jsx)(Co,{})}function Oo(){let{user:e}=_(),t=w(),n=Vr();return(0,$.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null);return}let r=pr({dataSource:t,userId:e.id,key:`ui.favorites`}),i=pr({dataSource:t,userId:e.id,key:`ui.recent`});return n(`favorites`,r),n(`recent`,i),()=>{n(`favorites`,null),n(`recent`,null)}},[e?.id,t,n]),null}function ko({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r,getAuthConfig:i}=_(),[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)(Co,{});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)(Co,{});if(a)return(0,Q.jsx)(p,{to:`/organizations`,replace:!0})}return(0,Q.jsx)(Q.Fragment,{children:e})}function Ao({children:e,redirectTo:t=`/home`}){let{enabled:n,isLoading:r}=Pi();return r?(0,Q.jsx)(Co,{}):n?(0,Q.jsx)(Q.Fragment,{children:e}):(0,Q.jsx)(p,{to:t,replace:!0})}function jo(){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})}var Mo=(0,$.lazy)(()=>o(()=>import(`./ConsoleFloatingChatbot-mf-pVd3G.js`),__vite__mapDeps([0]),import.meta.url)),No=()=>{o(()=>import(`./ConsoleFloatingChatbot-mf-pVd3G.js`),__vite__mapDeps([0]),import.meta.url)};function Po(e){let[t,n]=(0,$.useState)(!1),{t:r}=F(),{openSeq:i}=Cr(),a=(0,$.useRef)(i);return(0,$.useEffect)(()=>{i!==a.current&&(a.current=i,n(!0))},[i]),t?(0,Q.jsx)($.Suspense,{fallback:null,children:(0,Q.jsx)(Mo,{...e,defaultOpen:!0})}):(0,Q.jsx)(`button`,{type:`button`,"aria-label":r(`topbar.openAssistant`,{defaultValue:`Open {{name}} assistant`,name:e.appLabel}),onClick:()=>n(!0),onMouseEnter:No,onFocus:No,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 Fo(e){let t=Sa(),[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=[...new Set(n.map(e=>e.packageId).filter(e=>e!==null))],i=n.filter(e=>e.packageId===null),a=[],o=[],s=0,c=e=>{if(e){e.seedError&&a.push(e.seedError),typeof e.seededRows==`number`&&(s+=e.seededRows);for(let t of e.issues??[])t.severity===`error`&&o.push(t.message)}};for(let e of r){let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);c(ei(n))}let l=[...i.filter(e=>e.type!==`seed`),...i.filter(e=>e.type===`seed`)];for(let e of l){let n=(await t.publishDraft(e.type,e.name))?.seedApplied;n&&n.success===!1&&a.push(n.error??`${e.name}: sample data failed to load`)}return o.length>0?X.warning(e(`home.pendingDrafts.probeWarn`,{defaultValue:`Published, but verification found problems.`}),{description:o[0]}):a.length>0?X.warning(e(`home.pendingDrafts.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:a[0]}):X.success(s>0?e(`home.pendingDrafts.publishedVerified`,{count:s,defaultValue:`Published & verified — {{count}} sample row(s) live.`}):e(`home.pendingDrafts.published`,{defaultValue:`Published! Your changes are live.`})),{ok:!0,attempted:n.length}}catch(t){return X.error(`${e(`home.pendingDrafts.publishFailed`,{defaultValue:`Publish failed`})}: ${t.message}`),{ok:!1,attempted:0}}finally{r(!1)}},[t,e]),publishing:n}}async function Io(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 Lo(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 Ro(e){if(!e||typeof e!=`object`)return null;let t=e;return t.item&&typeof t.item==`object`?t.item:t}async function zo(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 Ro(await a.json())}function Bo(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}function Vo(e,t){let n=e??{},r=t??{},i=null;if(n.fields!=null||r.fields!=null){let e=Ra(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=>!Bo(n[e],r[e])).sort();return{fields:i,changedKeys:o}}function Ho({entry:e}){let{t}=F(),[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([zo(e.type,e.name,{packageId:e.packageId}),zo(e.type,e.name,{draft:!0,packageId:e.packageId})]);t||r(Vo(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 Uo({open:e,onOpenChange:t,packageId:n,onPublish:r,publishing:i=!1}){let{t:a}=F(),[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 Io(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 Lo(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)(B,{open:e,onOpenChange:t,children:(0,Q.jsxs)(mt,{side:`right`,className:`flex w-[420px] flex-col sm:max-w-[420px]`,"data-testid":`draft-changes-panel`,children:[(0,Q.jsxs)(ct,{children:[(0,Q.jsx)(yt,{children:a(`preview.changes.title`,{defaultValue:`Pending changes`})}),(0,Q.jsx)(we,{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)(Ce,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,Q.jsx)(le,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),e.kind===`new`?(0,Q.jsx)(ce,{className:`h-3.5 w-3.5 shrink-0 text-emerald-600`}):e.kind===`update`?(0,Q.jsx)(ft,{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)(Ft,{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)(Ho,{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)(Ie,{className:`mr-1.5 h-3.5 w-3.5`}),a(`preview.changes.publishConfirm`,{defaultValue:`Publish all`})]})]})]})})}function Wo(){let e=_r(),t=i(),n=a(),{t:r}=F(),{publishAll:o,publishing:s}=Fo(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=()=>{vr();let e=new URLSearchParams(t.search);e.delete(yr);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:yn(`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)(Ne,{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)(Lt,{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)(Ge,{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)(an,{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)(Ie,{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)(Uo,{open:c,onOpenChange:l})]})]})}async function Go(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 Ko(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 qo(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 Jo({open:e,onOpenChange:t,packageId:n,onReverted:r}){let{t:i}=F(),[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 Go(n))}catch(e){c(e.message)}},[n]);(0,$.useEffect)(()=>{e&&d()},[e,d]);let f=async e=>{u(e);try{await Ko(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)(B,{open:e,onOpenChange:t,children:(0,Q.jsxs)(mt,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`commit-timeline-panel`,children:[(0,Q.jsxs)(ct,{children:[(0,Q.jsx)(yt,{children:i(`preview.history.title`,{defaultValue:`Build history`})}),(0,Q.jsx)(we,{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)(or,{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)(Ft,{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:[`· `,qo(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)(Se,{className:`mr-1 h-3.5 w-3.5`}),i(`preview.history.revertAction`,{defaultValue:`Revert`})]})}):null]},e.id))})]})})}function Yo(){let e=_r(),{appName:t}=l(),n=i(),{apps:r,refresh:a}=T(),{t:o}=F(),[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=Ba(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)(Un,{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)(Kt,{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)(Ie,{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)(Jo,{open:u,onOpenChange:d,packageId:m,onReverted:a}):null]})}var Xo=`__all__`;function Zo(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function Qo(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 $o(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=Zo(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 es(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=Qo(await e.json()),s=[],c=new Set;for(let e of t){if(!$o(e,o))continue;let t=Zo(e,i);if(t==null||typeof t!=`string`||c.has(t))continue;c.add(t);let n=Zo(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 ts(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===Xo?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)(ns,{def:e,value:u[e.id],onChange:t=>l(e,t),t:n},e.id))})}}function ns({def:e,value:t,onChange:n,t:r}){let{options:i,refetch:a}=es(e),o=Ha(e.icon),s=Ua(e.label,r)||e.id,c=s===`Package`?r?.(`common.package`,{defaultValue:s})??s:s,l=r?.(`actionDialog.selectPlaceholder`,{label:c,defaultValue:`Select ${c}…`})??`Select ${c}…`,u=!!t&&t!==(e.allValue??``);return $.useEffect(()=>{u||i.length>0&&n(i[0].value)},[u,n,i]),(0,Q.jsxs)(Pe,{value:u?t:``,onValueChange:n,onOpenChange:e=>{e&&a()},children:[(0,Q.jsx)(Tt,{"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)(xt,{placeholder:l,className:`truncate`})]})}),(0,Q.jsx)(Kn,{className:`w-[var(--radix-select-trigger-width)]`,children:i.map(e=>(0,Q.jsx)(G,{value:e.value,children:e.label},e.value))})]})}var rs=$.forwardRef(({className:e,onClick:t,"aria-label":n,title:r,...i},a)=>{let{toggleSidebar:o}=Ve(),{t:s}=F(),c=String(n||r||s(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`}));return(0,Q.jsxs)(J,{ref:a,"data-sidebar":`trigger`,variant:`ghost`,size:`icon`,className:yn(`h-7 w-7`,e),"aria-label":c,title:c,onClick:e=>{t?.(e),o()},...i,children:[(0,Q.jsx)(xn,{}),(0,Q.jsx)(`span`,{className:`sr-only`,children:c})]})});rs.displayName=`LocalizedSidebarTrigger`;function is(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 as(e){return e.componentRef===`metadata:directory`}function os(e){return e.componentRef===`developer:packages`}function ss(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 cs({activeAppName:e}){let{isMobile:t,setOpenMobile:r}=Ve(),a=i(),{t:o}=F(),{objectLabel:s,dashboardLabel:c,navGroupLabel:l,viewLabel:u}=_e(),{context:d,currentAppName:f}=Ri(),{user:p}=_(),m=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:h}=Wr(),{favorites:v,removeFavorite:b}=Gr(),{apps:x,objects:S}=T(),C=x||[],w=C.filter(e=>e.active!==!1&&e.hidden!==!0),E=Ba(C.filter(e=>e.active!==!1),e||f)||w[0],{applyOrder:D,handleReorder:O}=is(E?.name||`home`),{togglePin:k,applyPins:A}=Nr(),j=E?.areas||[],[M,N]=$.useState(()=>j.length>0?j[0].id:null);$.useEffect(()=>{j.length>0?N(e=>j.some(t=>t.id===e)?e:j[0].id):N(null)},[E?.name,j.length]);let P=j.find(e=>e.id===M)?.navigation||E?.navigation||[],{contextValues:I,element:ee}=ts(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(m){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,m]),L=d===`home`?te:P,ne=d===`app`&&E?`/apps/${Va(E)}`:``,re=d===`app`&&E?.name===`studio`,ie=$.useMemo(()=>{if(!re)return``;let e=new URLSearchParams(a.search).get(`package`)||I.active_package;return e?`?package=${encodeURIComponent(e)}`:``},[I.active_package,re,a.search]),ae=$.useMemo(()=>{if(d!==`app`||E?.name!==`studio`)return L;let e=o(`sidebar.packageManagement`,{defaultValue:`Package management`}),t=n=>n.flatMap(n=>{if(as(n))return[];let r=n.children?.length?t(n.children):n.children;return n.type===`group`&&r?.length===0?[]:os(n)?[{...n,type:`url`,label:e,url:`${ne}/component/developer/packages${ie}`,children:r}]:r===n.children?[n]:[{...n,children:r}]});return t(L).flatMap(e=>ss(e)?e.children??[]:[e])},[E?.name,ne,d,L,ie,o]),se=$.useMemo(()=>{let e=D(ae);return A(e)},[ae,D,A]),[R,ce]=$.useState(!1),{evaluator:z}=Tr(),B=$.useCallback(e=>wr(e,z),[z]),{can:V}=y(),ue=$.useCallback(e=>e.every(e=>{let t=e.split(`:`),[n,r]=t.length>=2?[t[0],t[1]]:[e,`read`];return V(n,r)}),[V]),de=$.useMemo(()=>new Set((S||[]).map(e=>e?.name).filter(Boolean)),[S]),pe=$.useCallback((e,t)=>e===`object`?de.size===0?!0:de.has(t):!0,[de]),me=re&&a.pathname.replace(/\/+$/,``)===ne;return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)(Rt,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&d===`app`&&(0,Q.jsx)(ge,{className:`border-b p-1.5`,children:(0,Q.jsx)(Ke,{children:(0,Q.jsx)(gn,{children:(0,Q.jsx)(oe,{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)(Cn,{className:`h-5 w-5`}),(0,Q.jsx)(`span`,{children:o(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,Q.jsx)(sr,{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:[ee&&(0,Q.jsx)(fe,{className:`group-data-[state=collapsed]:hidden px-2 pb-1`,children:(0,Q.jsx)(`div`,{className:`rounded-lg border border-sidebar-border/70 bg-sidebar-accent/25 p-1.5 shadow-xs`,children:(0,Q.jsx)(nr,{children:ee})})}),re&&(0,Q.jsx)(fe,{children:(0,Q.jsx)(nr,{children:(0,Q.jsx)(Ke,{children:(0,Q.jsx)(gn,{children:(0,Q.jsx)(oe,{asChild:!0,isActive:me,tooltip:o(`home.nav`,{defaultValue:`Home`}),children:(0,Q.jsxs)(n,{to:{pathname:ne,search:ie},children:[(0,Q.jsx)(Cn,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:o(`home.nav`,{defaultValue:`Home`})})]})})})})})}),j.length>1&&(0,Q.jsxs)(fe,{children:[(0,Q.jsxs)(ot,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(Et,{className:`h-3.5 w-3.5`}),o(`sidebar.area`,{defaultValue:`Area`})]}),(0,Q.jsx)(nr,{children:(0,Q.jsx)(Ke,{children:j.map(e=>{let t=Ha(e.icon);return(0,Q.jsx)(gn,{children:(0,Q.jsxs)(oe,{isActive:e.id===M,tooltip:e.label,onClick:()=>N(e.id),children:[(0,Q.jsx)(t,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:e.label})]})},e.id)})})})]}),(0,Q.jsx)(sa,{items:se,basePath:ne,evaluateVisibility:B,checkPermission:ue,checkCapability:pe,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,contextValues:I}}),h.length>0&&(0,Q.jsxs)(fe,{children:[(0,Q.jsxs)(ot,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>ce(e=>!e),children:[(0,Q.jsx)(le,{className:`h-3 w-3 transition-transform duration-150 ${R?`rotate-90`:``}`}),(0,Q.jsx)(rn,{className:`h-3.5 w-3.5`}),o(`sidebar.recent`,{defaultValue:`Recent`})]}),R&&(0,Q.jsx)(nr,{children:(0,Q.jsx)(Ke,{children:h.slice(0,5).map(e=>(0,Q.jsx)(gn,{children:(0,Q.jsx)(oe,{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)(fe,{children:[(0,Q.jsxs)(ot,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(Bt,{className:`h-3.5 w-3.5`}),o(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,Q.jsx)(nr,{children:(0,Q.jsx)(Ke,{children:v.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,Q.jsxs)(gn,{children:[(0,Q.jsx)(oe,{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)(bn,{showOnHover:!0,onClick:t=>{t.stopPropagation(),b(e.id)},"aria-label":o(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(Sn,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(fe,{children:(0,Q.jsx)(nr,{children:(0,Q.jsx)(Ke,{children:te.map(e=>{let t=Ha(e.icon),r=a.pathname===e.url;return(0,Q.jsx)(gn,{children:(0,Q.jsx)(oe,{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)(fe,{children:[(0,Q.jsxs)(ot,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(Bt,{className:`h-3.5 w-3.5`}),o(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,Q.jsx)(nr,{children:(0,Q.jsx)(Ke,{children:v.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,Q.jsxs)(gn,{children:[(0,Q.jsx)(oe,{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)(bn,{showOnHover:!0,onClick:t=>{t.stopPropagation(),b(e.id)},"aria-label":o(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,Q.jsx)(Sn,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,Q.jsx)(rt,{className:`border-t p-1`,children:(0,Q.jsx)(rs,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function ls(){let{theme:e,setTheme:t}=mo(),{t:n}=F();return(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(ar,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(Nt,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,Q.jsx)(et,{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)(Rn,{align:`end`,children:[(0,Q.jsxs)(on,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,Q.jsx)(Nt,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(on,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,Q.jsx)(et,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,Q.jsxs)(on,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,Q.jsx)(V,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,Q.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}function us(){let e=document.querySelector(`base`)?.getAttribute(`href`);return e?new URL(e,window.location.origin):new URL(`/`,window.location.origin)}function ds(e){return e===void 0?us().toString():new URL(`.`,e).toString()}function fs(e,t){return new URL(e.replace(/^\//,``),ds(t)).toString()}function ps(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function ms({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:ps(e)})}function hs(){let{t:e}=F(),t=a(),{organizations:n,activeOrganization:r,switchOrganization:i,getAuthConfig:o}=_(),[s,c]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=!1;return o?.().then(t=>{e||c(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[o]);let l=n??[],u=r??l[0]??null;if(!u||l.length<=1)return null;let d=async e=>{if(e.id!==u.id)try{await i(e.id),window.location.href=ds()}catch(e){console.error(`[WorkspaceSwitcher] switch failed`,e)}};return(0,Q.jsxs)(Qt,{children:[(0,Q.jsxs)(ar,{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)(ms,{name:u.name}),(0,Q.jsx)(`span`,{className:`hidden truncate sm:inline`,children:u.name}),(0,Q.jsx)(Oe,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]}),(0,Q.jsxs)(Rn,{align:`start`,className:`w-60`,children:[(0,Q.jsx)(en,{className:`text-xs text-muted-foreground`,children:e(`organization.switcher.label`,{defaultValue:`Switch organization`})}),l.map(e=>(0,Q.jsxs)(on,{onClick:()=>d(e),className:`cursor-pointer gap-2`,children:[(0,Q.jsx)(ms,{name:e.name}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.id===u.id&&(0,Q.jsx)(q,{className:`h-4 w-4 shrink-0`})]},e.id)),(0,Q.jsx)(jt,{}),(0,Q.jsxs)(on,{onClick:()=>t(`/organizations/${u.slug}/members`),className:`cursor-pointer gap-2`,"data-testid":`workspace-manage-members`,children:[(0,Q.jsx)(De,{className:`h-4 w-4`}),e(`organization.switcher.manageMembers`,{defaultValue:`Manage members`})]}),!s&&(0,Q.jsxs)(on,{onClick:()=>t(`/organizations?create=1`),className:`cursor-pointer gap-2`,"data-testid":`workspace-create`,children:[(0,Q.jsx)(Ct,{className:`h-4 w-4`}),e(`organizations.create`,{defaultValue:`Create workspace`})]})]})]})}var gs=[{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 _s(){let{t:e,language:t,changeLanguage:n}=F();return(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(ar,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,Q.jsx)(Qn,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,Q.jsx)(Rn,{align:`end`,className:`max-h-72 overflow-y-auto`,children:gs.map(e=>(0,Q.jsxs)(on,{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 vs={connected:{labelKey:`topbar.connection.connected`,defaultValue:`Connected`,color:`text-green-500`,icon:hn},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:mn},error:{labelKey:`topbar.connection.error`,defaultValue:`Connection Error`,color:`text-destructive`,icon:mn}};function ys({state:e,className:t}){let n=vs[e],{t:r}=F(),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:yn(`flex items-center gap-1.5 text-xs font-medium px-2 py-1 rounded-md transition-opacity duration-300`,n.color,e===`connected`&&`bg-green-500/10`,e===`error`&&`bg-destructive/10`,e===`reconnecting`&&`bg-yellow-500/10`,t),title:i,children:[(0,Q.jsx)(a,{className:yn(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:i})]})}function bs(e){if(!e)return``;let t=new Date(e).getTime();if(Number.isNaN(t))return``;let n=(Date.now()-t)/1e3;return n<60?`${Math.max(1,Math.floor(n))}s`:n<3600?`${Math.floor(n/60)}m`:n<86400?`${Math.floor(n/3600)}h`:`${Math.floor(n/86400)}d`}function xs({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:o}){let{t:s}=F(),c=a(),u=l(),{currentAppName:d}=Ri(),[f,p]=(0,$.useState)(!1),[m,h]=(0,$.useState)(`notifications`),[g,_]=(0,$.useState)(`unread`),v=t+n,y=s(`sidebar.inboxAriaLabel`,{defaultValue:`Open inbox`}),b=(0,$.useRef)(null),[x,S]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=b.current;if(e!==null&&v>e){S(!0);let e=window.setTimeout(()=>S(!1),1200);return()=>window.clearTimeout(e)}b.current=v},[v]),(0,$.useEffect)(()=>{x||(b.current=v)},[x,v]);let C=()=>{p(!1);let e=d??u.appName;c(e?`/apps/${e}/system/approvals`:`/apps/setup/system/approvals`)},w=()=>{p(!1),c(`/apps/setup/sys_inbox_message?view=mine`)},T=()=>{p(!1),c(`/apps/setup/sys_activity`)},E=e=>{o(e.id);let t=d??u.appName;if(e.action_url){p(!1);let n=e.action_url;if(/^https?:\/\//i.test(n)){window.open(n,`_blank`,`noopener,noreferrer`);return}if(n.startsWith(`/apps/`)){c(n);return}let r=n.startsWith(`/`)?n:`/${n}`;c(t?`/apps/${t}${r}`:r);return}if(e.source_object&&e.source_id){p(!1);let n=t?`/apps/${t}/${e.source_object}/${e.source_id}`:`/objects/${e.source_object}/${e.source_id}`;c(n)}};return(0,Q.jsxs)(un,{open:f,onOpenChange:p,children:[(0,Q.jsx)(Fn,{asChild:!0,children:(0,Q.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 relative shrink-0 ${x?`motion-safe:animate-bounce`:``}`,"aria-label":y,title:s(`sidebar.inbox`,{defaultValue:`Inbox`}),children:[(0,Q.jsx)(Xt,{className:`h-4 w-4`}),v>0&&(0,Q.jsx)(`span`,{className:`absolute -top-0.5 -right-0.5 h-4 min-w-[16px] rounded-full bg-red-500 text-[10px] leading-4 text-white text-center px-1 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:fade-in-0 motion-safe:duration-200`,children:v>9?`9+`:v},v)]})}),(0,Q.jsxs)(Pt,{align:`end`,sideOffset:8,className:`w-96 p-0`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between px-3 pt-3 pb-1`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-semibold`,children:s(`sidebar.inbox`,{defaultValue:`Inbox`})}),m===`notifications`&&t>0&&(0,Q.jsx)(`button`,{type:`button`,onClick:i,className:`text-xs text-muted-foreground hover:text-foreground`,children:s(`notifications.markAllRead`,{defaultValue:`Mark all read`})})]}),(0,Q.jsxs)(Ut,{value:m,onValueChange:e=>h(e),className:`w-full`,children:[(0,Q.jsxs)(Zn,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,Q.jsxs)(Jt,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(Xt,{className:`h-3.5 w-3.5`}),s(`sidebar.notifications`,{defaultValue:`Notifications`}),t>0&&(0,Q.jsx)(`span`,{className:`ml-0.5 inline-flex h-4 min-w-[16px] items-center justify-center rounded-full bg-red-500 px-1 text-[10px] text-white motion-safe:animate-in motion-safe:zoom-in-75 motion-safe:duration-200`,children:t>9?`9+`:t},`notif-${t}`)]}),(0,Q.jsxs)(Jt,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(Ln,{className:`h-3.5 w-3.5`}),s(`sidebar.approvals`,{defaultValue:`Approvals`}),n>0&&(0,Q.jsx)(`span`,{className:`ml-0.5 inline-flex h-4 min-w-[16px] items-center justify-center rounded-full bg-amber-500 px-1 text-[10px] text-white motion-safe:animate-in motion-safe:zoom-in-75 motion-safe:duration-200`,children:n>9?`9+`:n},`appr-${n}`)]}),(0,Q.jsxs)(Jt,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,Q.jsx)(Ue,{className:`h-3.5 w-3.5`}),s(`sidebar.activityFeed`,{defaultValue:`Activity`})]})]}),(0,Q.jsxs)(Tn,{value:`notifications`,className:`m-0 max-h-80 overflow-auto`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-2 py-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>_(`unread`),className:`text-xs px-2 py-1 rounded-md transition-colors ${g===`unread`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:[s(`notifications.filterUnread`,{defaultValue:`Unread`}),t>0&&(0,Q.jsx)(`span`,{className:`ml-1 text-[10px] opacity-70`,children:t})]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>_(`all`),className:`text-xs px-2 py-1 rounded-md transition-colors ${g===`all`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:s(`notifications.filterAll`,{defaultValue:`All`})})]}),(()=>{let t=g===`unread`?e.filter(e=>!e.is_read):e;return t.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-8 text-sm text-muted-foreground text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:g===`unread`?s(`notifications.emptyUnread`,{defaultValue:`You're all caught up`}):s(`notifications.empty`,{defaultValue:`No notifications`})}):(0,Q.jsx)(`ul`,{className:`divide-y`,children:t.map((e,t)=>(0,Q.jsx)(`li`,{className:`motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-top-1 motion-safe:duration-200`,style:{animationDelay:`${Math.min(t,6)*20}ms`},children:(0,Q.jsx)(`button`,{type:`button`,onClick:()=>E(e),className:`w-full text-left px-3 py-2.5 hover:bg-accent transition-colors duration-150 ${e.is_read?``:`bg-accent/40`}`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`span`,{className:`mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full bg-primary transition-opacity duration-200 ${e.is_read?`opacity-0`:`opacity-100`}`,"aria-hidden":!0}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium leading-tight truncate`,children:e.title}),e.body&&(0,Q.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-2 mt-0.5`,children:e.body}),(0,Q.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:bs(e.created_at)})]})]})})},e.id))})})(),(0,Q.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:w,className:`text-xs text-primary hover:underline`,children:s(`notifications.viewAll`,{defaultValue:`View all notifications`})})})]}),(0,Q.jsx)(Tn,{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)(Ln,{className:`mx-auto h-6 w-6 text-amber-500 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:duration-300`}),(0,Q.jsx)(`div`,{className:`mt-2 text-sm font-medium`,children:s(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:n})}),(0,Q.jsx)(J,{size:`sm`,className:`mt-3`,onClick:C,children:s(`notifications.viewApprovals`,{defaultValue:`View approvals`})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:s(`notifications.noPendingApprovals`,{defaultValue:`No pending approvals`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:C,className:`mt-2 text-xs text-primary hover:underline`,children:s(`notifications.openApprovalsInbox`,{defaultValue:`Open Approvals Inbox`})})]})})}),(0,Q.jsxs)(Tn,{value:`activity`,className:`m-0 max-h-80 overflow-auto`,children:[r.length===0?(0,Q.jsx)(`div`,{className:`px-3 py-8 text-sm text-muted-foreground text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:s(`layout.activityFeed.empty`,{defaultValue:`No recent activity`})}):(0,Q.jsx)(`ul`,{className:`divide-y`,children:r.slice(0,20).map((e,t)=>(0,Q.jsxs)(`li`,{className:`px-3 py-2.5 motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-top-1 motion-safe:duration-200`,style:{animationDelay:`${Math.min(t,6)*20}ms`},children:[(0,Q.jsxs)(`div`,{className:`text-sm leading-tight truncate`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]}),(0,Q.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:[bs(e.timestamp),` · `,e.objectName]})]},e.id))}),(0,Q.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,Q.jsx)(`button`,{type:`button`,onClick:T,className:`text-xs text-primary hover:underline`,children:s(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`})})})]})]})]})]})}function Ss({activeAppName:e,onAppChange:t}){let{apps:n}=T(),{t:r}=F(),{appLabel:i}=_e(),a=n||[],o=a.filter(e=>e.active!==!1&&e.hidden!==!0),s=Ba(o,e)||Ba(a.filter(e=>e.active!==!1),e)||o[0];return s?(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(ar,{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:Ua(s.label,r)})}),(0,Q.jsx)(Ce,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,Q.jsxs)(Rn,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,Q.jsx)(en,{className:`text-xs text-muted-foreground font-normal`,children:r(`layout.appSwitcher.switchApplication`,{defaultValue:`Switch Application`})}),(0,Q.jsx)(jt,{}),o.map(e=>{let n=Ha(e.icon),a=i({name:e.name,label:Ua(e.label,r)}),o=s.name===e.name;return(0,Q.jsxs)(on,{onClick:()=>t(Va(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)(q,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]}):null}var Cs=(0,$.createContext)(null);function ws({children:e}){let[t,n]=(0,$.useState)(null),r=(0,$.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,Q.jsx)(Cs.Provider,{value:r,children:e})}function Ts(){return(0,$.useContext)(Cs)?.value??null}function Es(e){let t=(0,$.useContext)(Cs),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 Ds(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),[]);Es((0,$.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}var Os=(0,$.createContext)(null);function ks({children:e}){let{open:t,setOpen:n,openOverlay:r,closeOverlay:i,toggleOverlay:a}=jr(Gi,{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)(Os.Provider,{value:o,children:e})}function As(){return(0,$.useContext)(Os)||{open:!1,openCommandPalette:()=>{},closeCommandPalette:()=>{},toggleCommandPalette:()=>{},setOpen:()=>{}}}function js(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Ms(){return(0,Q.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var Ns=[];function Ps({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(),v=a(),{isOnline:y}=te(),{openCommandPalette:x}=As(),{openOverlay:S}=jr(Yi),{user:C,signOut:E,isAuthEnabled:D,organizations:O,activeOrganization:k,isOrganizationsLoading:A,getAuthConfig:j}=_(),M=w(),{enabled:N}=Pi(),P=g(),{t:I}=F(),{objectLabel:ee,dashboardLabel:L,pageLabel:ne,reportLabel:ie,viewLabel:ae,appLabel:oe}=_e(),{apps:se,dashboards:R,pages:ce,reports:z}=T(),{currentAppName:le,recordTitle:B}=Ri(),V=Ts(),[ue,de]=(0,$.useState)(null),fe=(0,$.useCallback)(async()=>{if(ue===null)try{let e=M?.getClient?.();if(!e?.meta?.getItems){de([]);return}let t=await e.meta.getItems(`doc`),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,M]),[pe,me]=(0,$.useState)(null),[H,ge]=(0,$.useState)([]),U=(0,$.useRef)(!1),ve=(0,$.useRef)(!1),W=(0,$.useRef)(!0);(0,$.useEffect)(()=>(W.current=!0,()=>{W.current=!1}),[]);let ye=(0,$.useRef)(!1),be=(0,$.useRef)(!1),xe=(0,$.useRef)(!1),[Se,we]=(0,$.useState)(0),Te=(0,$.useRef)(!1),Ee=(0,$.useCallback)(async()=>{if(!M||!p)return;let e=e=>e?.httpStatus===404||e?.status===404||e?.code===`object_not_found`;if(!U.current&&!xe.current){xe.current=!0;try{let t=await M.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20}).catch(t=>(e(t)&&(U.current=!0),{data:[]}));if(t.data?.length){let e=t.data.filter(e=>typeof e.type==`string`);e.length&&me(e)}}catch{}finally{xe.current=!1}}},[M,p]);(0,$.useEffect)(()=>{Ee()},[Ee]),(0,$.useEffect)(()=>{if(!M||!p||!C?.id||ve.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([M.find(`sys_inbox_message`,{$filter:{user_id:C.id},$orderby:{created_at:`desc`},$top:20}),M.find(`sys_notification_receipt`,{$filter:{user_id:C.id,channel:`inbox`},$top:200}).catch(()=>({data:[]}))]);if(!W.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}});ge(c),r=n}catch(e){if(i(e)){ve.current=!0;return}r=Math.min(r*2,12e4)}finally{ye.current=!1}}},s=()=>{if(e||ve.current)return;let n=typeof document<`u`&&document.hidden?6e4:r;t=setTimeout(async()=>{await o(),s()},n)},c=()=>{e||typeof document>`u`||document.hidden||(t&&=(clearTimeout(t),null),r=n,o().finally(s))};return o().finally(s),typeof document<`u`&&document.addEventListener(`visibilitychange`,c),()=>{e=!0,t&&clearTimeout(t),typeof document<`u`&&document.removeEventListener(`visibilitychange`,c)}},[M,p,C?.id]),(0,$.useEffect)(()=>{if(!p||!C?.id||Te.current)return;let e=`${``.replace(/\/$/,``)}/api/v1/approvals/requests`,t=[];C.id&&t.push(C.id),C.email&&t.push(C.email);for(let e of C.roles||[])e&&t.push(`role:${e}`);let n=!1,r=null,i=async()=>{if(t.length!==0&&!be.current){be.current=!0;try{let n=new URLSearchParams({status:`pending`,approverId:t.join(`,`)}),r=await fetch(`${e}?${n}`,{credentials:`include`});if(r.status===404){Te.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);W.current&&we(a.size)}catch{}finally{be.current=!1}}},a=()=>{n||Te.current||(r=setTimeout(async()=>{await i(),a()},3e4))};return i().finally(a),()=>{n=!0,r&&clearTimeout(r)}},[p,C?.id]);let De=H.reduce((e,t)=>e+ +!t.is_read,0),Oe=(0,$.useCallback)(async(e,t)=>{!M||!e.notification_id||(e.receipt_id?await M.update(`sys_notification_receipt`,e.receipt_id,{state:`read`,at:t}):await M.create(`sys_notification_receipt`,{notification_id:e.notification_id,user_id:C?.id,channel:`inbox`,state:`read`,at:t,created_at:t}))},[M,C?.id]),ke=(0,$.useCallback)(async e=>{let t=H.find(t=>t.id===e);if(ge(t=>t.map(t=>t.id===e?{...t,is_read:!0}:t)),t)try{await Oe(t,new Date().toISOString())}catch{}},[H,Oe]),Ae=(0,$.useCallback)(async()=>{let e=H.filter(e=>!e.is_read);if(!e.length)return;ge(e=>e.map(e=>({...e,is_read:!0})));let t=new Date().toISOString();await Promise.all(e.map(e=>Oe(e,t).catch(()=>{})))},[H,Oe]),G=$i(),Me=s??(G.length>0?G:Ns),Ne=c??pe??[],Pe=A||(O??[]).length>0||!!k,[Ie,Le]=(0,$.useState)(!1);(0,$.useEffect)(()=>{let e=!1;return j?.().then(t=>{e||Le(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[j]);let K=m.pathname.split(`/`).filter(Boolean),ze=h.appName||K[1],Be=K[2],Ve=`/apps/${ze}`,He=r??[],Ue=Ba(se||[],u||le||ze),Ge=new Set,Ke=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&Ge.add(t.objectName),t.children&&Ke(t.children)};Ke(Ue?.navigation||[]);for(let e of Ue?.areas||[])Ke(e.navigation||[]);let qe=Ge.size>0?He.filter(e=>Ge.has(e.name)):He.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`)),Je=Ue?._packageId,Ye=Je?(ue??[]).filter(e=>e._packageId===Je):[],Ze=p?za(Ue,P):null,Qe=qe.map(e=>({label:ee(e),href:`${Ve}/${e.name}`})),$e=[];if(p){if(Be===`dashboard`){if($e.push({label:I(`console.breadcrumb.dashboards`),href:Ve}),K[3]){let e=K[3],t=Ga(R,e,Ue?._packageId)?.label||js(e);$e.push({label:L({name:e,label:t})})}}else if(Be===`page`){if($e.push({label:I(`console.breadcrumb.pages`),href:Ve}),K[3]){let e=K[3],t=Ga(ce,e,Ue?._packageId)?.label||js(e);$e.push({label:ne({name:e,label:t})})}}else if(Be===`report`){if($e.push({label:I(`console.breadcrumb.reports`),href:Ve}),K[3]){let e=K[3],t=Ga(z,e,Ue?._packageId)?.label||js(e);$e.push({label:ie({name:e,label:t})})}}else if(Be===`system`)$e.push({label:I(`console.breadcrumb.system`)}),K[3]&&$e.push({label:js(K[3])});else if(Be){let e=He.find(e=>e.name===Be);if(e){if(K[3]===`record`&&K[4]){let e=Ui(new URLSearchParams(m.search).get(Zi));e.forEach((t,n)=>{let r=He.find(e=>e.name===t.o);$e.push({label:r?ee(r):js(t.o),href:`${Ve}/${t.o}`});let i=t.i.length>12?`${t.i.slice(0,8)}…`:t.i;$e.push({label:t.t||`#${i}`,href:ea(Ve,t,e.slice(0,n))})})}if($e.push({label:ee(e),href:`${Ve}/${Be}`,siblings:Qe}),K[3]===`record`&&K[4]){let e=K[4].length>12?`${K[4].slice(0,8)}…`:K[4],t=B?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;$e.push({label:n||`#${e}`})}else if(K[3]===`view`&&K[4]){let t=K[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||js(t),i=ae(e.name,t,r);$e.push({label:i})}}}}let et=$e[$e.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:yn(`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors`,p&&`hidden sm:flex`),title:ia(),children:(0,Q.jsx)(Et,{className:`h-4 w-4`})}),f===`home`&&(0,Q.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:ia()}),(0,Q.jsx)(hs,{}),f===`orgs`&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ms,{}),(0,Q.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:I(`organizations.title`,{defaultValue:`Organizations`})})]}),p&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(rs,{className:`lg:hidden shrink-0 ml-1`,"aria-label":I(`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)(Ms,{})}),(0,Q.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,Q.jsx)(Ss,{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)(Ms,{})}),(0,Q.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,$e.map((e,t)=>{let r=t===$e.length-1;return(0,Q.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,Q.jsx)(Ms,{}),e.siblings&&e.siblings.length>1?(0,Q.jsxs)(Qt,{children:[(0,Q.jsxs)(ar,{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)(Ce,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,Q.jsxs)(Rn,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,Q.jsx)(en,{className:`text-xs text-muted-foreground font-normal`,children:`Switch Object`}),(0,Q.jsx)(jt,{}),e.siblings.map(e=>(0,Q.jsx)(on,{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)}),V&&V.views.length>0?V.views.length>1?(0,Q.jsxs)(Qt,{children:[(0,Q.jsx)(ar,{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":I(`topbar.switchView`,{defaultValue:`Switch view`}),children:[(0,Q.jsx)(`span`,{className:`truncate max-w-[180px]`,children:V.triggerLabel??V.views.find(e=>e.id===V.activeViewId)?.label??et}),(0,Q.jsx)(Ce,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,Q.jsx)(Rn,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:V.views.map(e=>{let t=e.id===V.activeViewId;return(0,Q.jsxs)(on,{onSelect:()=>{t||V.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)(Xe,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,Q.jsx)(q,{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:V.triggerLabel??V.views[0].label}):(0,Q.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:et})]})]}),(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:[!y&&(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`}),I(`topbar.offline`,{defaultValue:`Offline`})]}),p&&o&&(0,Q.jsx)(ys,{state:o}),p&&Me.length>0&&(0,Q.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:I(`topbar.usersOnline`,{defaultValue:`Users currently online`}),children:(0,Q.jsx)(Bi,{users:Me,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":I(`console.search`,{defaultValue:`Search…`}),"aria-keyshortcuts":`Meta+K Control+K`,onClick:x,className:`hidden lg:flex relative items-center gap-2 w-48 xl:w-64 h-8 px-3 text-sm rounded-md border bg-muted/50 text-muted-foreground hover:bg-muted transition-colors`,children:[(0,Q.jsx)(We,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:I(`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:x,"aria-label":I(`console.search`,{defaultValue:`Search…`}),children:(0,Q.jsx)(We,{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)(xs,{notifications:H,unreadCount:De,pendingApprovalsCount:Se,activities:Ne,onMarkAllRead:Ae,onMarkRead:ke}),Ze&&(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":I(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),title:I(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),children:(0,Q.jsx)(n,{to:Ze,children:(0,Q.jsx)(Dn,{className:`h-4 w-4`})})}),N&&(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"aria-label":I(`topbar.aiAssistant`,{defaultValue:`AI Assistant`}),children:(0,Q.jsx)(n,{to:`/ai`,children:(0,Q.jsx)(zt,{className:`h-4 w-4`})})}),(0,Q.jsxs)(Qt,{onOpenChange:e=>{e&&fe()},children:[(0,Q.jsx)(ar,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 hidden md:flex shrink-0`,"aria-label":I(`sidebar.helpTooltip`,{defaultValue:`Help & Documentation`}),children:(0,Q.jsx)(he,{className:`h-4 w-4`})})}),(0,Q.jsxs)(Rn,{align:`end`,className:`min-w-56 rounded-lg`,sideOffset:4,children:[Ye.length>0&&Je?(0,Q.jsxs)(on,{className:`cursor-pointer`,onClick:()=>v(Ye.length===1?`/apps/${Je}/docs/${Ye[0].name}`:`/apps/${Je}/docs`),children:[(0,Q.jsx)(Xn,{className:`mr-2 h-4 w-4`}),I(`help.appDocs`,{defaultValue:`This app's docs`})]}):null,(0,Q.jsxs)(on,{className:`cursor-pointer`,onClick:()=>v(`/docs`),children:[(0,Q.jsx)(Et,{className:`mr-2 h-4 w-4`}),I(`help.allDocs`,{defaultValue:`All documentation`})]}),p?(0,Q.jsxs)(on,{className:`cursor-pointer`,"data-testid":`action:keyboard-shortcuts:open`,onClick:S,children:[(0,Q.jsx)(re,{className:`mr-2 h-4 w-4`}),I(`help.keyboardShortcuts`,{defaultValue:`Keyboard shortcuts`})]}):null,(0,Q.jsx)(jt,{}),(0,Q.jsx)(on,{asChild:!0,className:`cursor-pointer`,children:(0,Q.jsxs)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,Q.jsx)(je,{className:`mr-2 h-4 w-4`}),I(`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)(Qt,{children:[(0,Q.jsx)(ar,{asChild:!0,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,Q.jsxs)(In,{className:`h-7 w-7 rounded-full`,children:[(0,Q.jsx)(Vt,{src:C?.image,alt:C?.name??`User`}),(0,Q.jsx)(Yn,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:b(C)})]})})}),(0,Q.jsxs)(Rn,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,Q.jsx)(en,{className:`p-0 font-normal`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,Q.jsxs)(In,{className:`h-8 w-8 rounded-lg`,children:[(0,Q.jsx)(Vt,{src:C?.image,alt:C?.name??`User`}),(0,Q.jsx)(Yn,{className:`rounded-lg bg-primary text-primary-foreground`,children:b(C)})]}),(0,Q.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,Q.jsx)(`span`,{className:`truncate font-semibold`,children:C?.name??`User`}),(0,Q.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:C?.email??``})]})]})}),(0,Q.jsx)(jt,{}),(0,Q.jsxs)(En,{children:[(0,Q.jsxs)(on,{onClick:()=>v(`/apps/account/component/account/profile_card`),className:`cursor-pointer`,children:[(0,Q.jsx)(Re,{className:`mr-2 h-4 w-4`}),I(`user.profile`,{defaultValue:`Profile`})]}),Pe&&!Ie&&(0,Q.jsxs)(on,{onClick:()=>v(`/organizations?create=1`),className:`cursor-pointer`,"data-testid":`header-create-workspace`,children:[(0,Q.jsx)(Ct,{className:`mr-2 h-4 w-4`}),I(`organizations.create`,{defaultValue:`Create workspace`})]}),(se||[]).filter(e=>e.active!==!1&&e.hidden===!0&&e.name!==`account`).map(e=>{let t=Ha(e.icon),n=oe({name:e.name,label:Ua(e.label,I)});return(0,Q.jsxs)(on,{onClick:()=>v(`/apps/${Va(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)(jt,{}),(0,Q.jsx)(en,{className:`text-[11px] font-normal text-muted-foreground uppercase tracking-wide px-2`,children:I(`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:I(`user.theme`,{defaultValue:`Theme`})}),(0,Q.jsx)(ls,{})]}),(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:I(`user.language`,{defaultValue:`Language`})}),(0,Q.jsx)(_s,{})]}),D&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(jt,{}),(0,Q.jsxs)(on,{className:`text-destructive focus:text-destructive`,onClick:()=>E(),children:[(0,Q.jsx)(Fe,{className:`mr-2 h-4 w-4`}),I(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}function Fs({children:e}){return Ir(),(0,Q.jsx)(Q.Fragment,{children:e})}function Is({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:o}){let s=Ua(n?.label)||t,{enabled:c}=Pi(),l=ra().features.aiStudio===!1&&ii(n?.defaultAgent)?void 0:n?.defaultAgent,{setContext:u,setCurrentAppName:d}=Ri();return(0,$.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,Q.jsx)(ks,{children:(0,Q.jsx)(ws,{children:(0,Q.jsxs)(oa,{sidebar:(0,Q.jsx)(cs,{activeAppName:t,onAppChange:r}),navbar:(0,Q.jsx)(Ps,{variant:`app`,appName:s,objects:i,connectionState:a,activeAppName:t,onAppChange:r}),className:`!p-0 overflow-y-auto overflow-x-hidden bg-muted/5`,branding:n?.branding?{primaryColor:n.branding.primaryColor,accentColor:n.branding.accentColor,favicon:n.branding.favicon,logo:n.branding.logo,title:n.label?`${Ua(n.label)} — ${ia()}`:void 0}:void 0,children:[(0,Q.jsxs)(Fs,{children:[(0,Q.jsx)(Wo,{}),(0,Q.jsx)(Yo,{}),e]}),c&&(0,Q.jsx)(Po,{appLabel:s,appName:t,defaultAgent:l,objects:i,userId:o})]})})})}function Ls({apps:e,activeApp:t,objects:n,onAppChange:r,dataSource:i}){let{open:o,setOpen:s}=As(),[c,u]=(0,$.useState)(``),d=a(),{appName:f}=l(),{setTheme:p}=mo(),{evaluator:m}=Tr(),{t:h}=F();(0,$.useEffect)(()=>{o||u(``)},[o]);let g=`/apps/${f||Va(t)}`,{user:v}=_(),y=(0,$.useMemo)(()=>({currentUserId:v?.id??null}),[v?.id]),b=(0,$.useCallback)(e=>{s(!1),e()},[]),x=Rs(t?.navigation||[]).filter(e=>wr(e.visible??e.visibleOn,m)),{results:S,isSearching:C}=O({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:j}),{recentItems:w}=Wr(),T=(0,$.useMemo)(()=>w.filter(e=>e.type===`record`).slice(0,5),[w]),E=o&&c.trim().length===0&&T.length>0;return(0,Q.jsxs)(Ee,{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)(lr,{placeholder:h(`console.commandPalette.placeholder`),value:c,onValueChange:u}),(0,Q.jsxs)(dt,{children:[(0,Q.jsx)(Le,{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`)}),E&&(0,Q.jsx)(Ze,{heading:h(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:T.map(e=>(0,Q.jsxs)(R,{value:`recent ${e.label} ${e.id}`,onSelect:()=>b(()=>d(e.href)),children:[(0,Q.jsx)(We,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.label})]},`recent:${e.id}`))}),S.length>0&&(0,Q.jsx)(Ze,{heading:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[h(`console.commandPalette.records`,{defaultValue:`Records`}),C&&(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`inline-block h-1.5 w-1.5 rounded-full bg-primary motion-safe:animate-pulse`})]}),children:S.map(e=>{let t=Ha(e.icon);return(0,Q.jsxs)(R,{value:`record ${c} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>b(()=>d(`${g}/${e.objectName}/record/${e.recordId}`)),children:[(0,Q.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{className:`truncate`,children:e.display}),(0,Q.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:e.objectLabel})]},`${e.objectName}:${e.recordId}`)})}),x.filter(e=>e.type===`object`).length>0&&(0,Q.jsx)(Ze,{heading:h(`console.commandPalette.objects`),children:x.filter(e=>e.type===`object`).map(e=>{let t=Ha(e.icon);return(0,Q.jsxs)(R,{value:`object ${Ua(e.label,h)} ${e.objectName}`,onSelect:()=>b(()=>d(aa(e,g,y).href)),children:[(0,Q.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Ua(e.label,h)})]},e.id)})}),x.filter(e=>e.type===`dashboard`).length>0&&(0,Q.jsx)(Ze,{heading:h(`console.commandPalette.dashboards`),children:x.filter(e=>e.type===`dashboard`).map(e=>(0,Q.jsxs)(R,{value:`dashboard ${Ua(e.label,h)} ${e.dashboardName}`,onSelect:()=>b(()=>d(aa(e,g,y).href)),children:[(0,Q.jsx)(bt,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Ua(e.label,h)})]},e.id))}),x.filter(e=>e.type===`page`).length>0&&(0,Q.jsx)(Ze,{heading:h(`console.commandPalette.pages`),children:x.filter(e=>e.type===`page`).map(e=>(0,Q.jsxs)(R,{value:`page ${Ua(e.label,h)} ${e.pageName}`,onSelect:()=>b(()=>d(aa(e,g,y).href)),children:[(0,Q.jsx)(ve,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Ua(e.label,h)})]},e.id))}),x.filter(e=>e.type===`report`).length>0&&(0,Q.jsx)(Ze,{heading:h(`console.commandPalette.reports`),children:x.filter(e=>e.type===`report`).map(e=>(0,Q.jsxs)(R,{value:`report ${Ua(e.label,h)} ${e.reportName}`,onSelect:()=>b(()=>d(aa(e,g,y).href)),children:[(0,Q.jsx)(Dt,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Ua(e.label,h)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(xe,{}),(0,Q.jsx)(Ze,{heading:h(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=Ha(e.icon);return(0,Q.jsxs)(R,{value:`app ${Ua(e.label,h)} ${e.name}`,onSelect:()=>b(()=>r(Va(e)??e.name)),children:[(0,Q.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:Ua(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)(xe,{}),(0,Q.jsxs)(Ze,{heading:h(`console.commandPalette.preferences`),children:[(0,Q.jsxs)(R,{value:`theme light`,onSelect:()=>b(()=>p(`light`)),children:[(0,Q.jsx)(Nt,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.lightTheme`)})]}),(0,Q.jsxs)(R,{value:`theme dark`,onSelect:()=>b(()=>p(`dark`)),children:[(0,Q.jsx)(et,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.darkTheme`)})]}),(0,Q.jsxs)(R,{value:`theme system`,onSelect:()=>b(()=>p(`system`)),children:[(0,Q.jsx)(V,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.systemTheme`)})]})]}),(0,Q.jsx)(xe,{}),(0,Q.jsx)(Ze,{heading:h(`console.commandPalette.actions`),children:(0,Q.jsxs)(R,{value:`search all results full page`,onSelect:()=>b(()=>d(`${g}/search`)),children:[(0,Q.jsx)(We,{className:`mr-2 h-4 w-4`}),(0,Q.jsx)(`span`,{children:h(`console.commandPalette.openFullSearch`)})]})})]})]})}function Rs(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Rs(n.children)):t.push(n);return t}function zs(){let{t:e}=F(),{open:t,setOpen:n,toggleOverlay:r}=jr(Yi),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)(st,{open:t,onOpenChange:n,children:(0,Q.jsxs)(gt,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,"data-testid":`overlay:keyboard-shortcuts`,children:[(0,Q.jsxs)(Hn,{children:[(0,Q.jsx)(Ae,{children:e(`console.shortcuts.title`)}),(0,Q.jsx)(ye,{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 Bs(){return null}function Vs(e){let{theme:t=`system`}=mo(),{t:n}=F();return(0,Q.jsx)(fr,{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)(hn,{className:`h-4 w-4`}),info:(0,Q.jsx)(dn,{className:`h-4 w-4`}),warning:(0,Q.jsx)(_t,{className:`h-4 w-4`}),error:(0,Q.jsx)(kt,{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 Hs=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function Us({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(...Hs),e.offsetWidth,e.classList.add(...Hs))},[n.pathname]),(0,Q.jsx)(`div`,{ref:r,className:[...Hs,t??``].filter(Boolean).join(` `),children:e})}var Ws=null,Gs=null;function Ks(){return Gs||(Gs=(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-CHRc7_3y.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=Js(e.data.url)),e}}),Ws=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),Gs)}function qs(e,t){if(Ws)try{Ws.captureException(e,t?{extra:t}:void 0)}catch{}}function Js(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 Ys({error:e,onReset:t}){let{t:n}=F();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)(ht,{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)(_t,{className:`h-6 w-6 text-destructive`})}),(0,Q.jsx)(ke,{children:n(`console.errors.somethingWentWrong`)}),(0,Q.jsx)(W,{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)(Te,{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)(Cn,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var Xs=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),qs(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)(Ys,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}},Zs=`list-filters`;function Qs(e,t,n){if(!(!t||!n))return`${Zs}:${e||`anon`}:${t}:${n}`}function $s(e){return!e||!Array.isArray(e.conditions)||e.conditions.length===0}function ec(e){return $s(e.filters)&&!(e.search&&e.search.length>0)}function tc(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 nc={},rc={};function ic(e,t){!e||typeof localStorage>`u`||(nc[e]={...nc[e]??tc(e)??{},...t},rc[e]&&clearTimeout(rc[e]),rc[e]=setTimeout(()=>{let t=nc[e]??{};delete nc[e],delete rc[e];try{ec(t)?localStorage.removeItem(e):localStorage.setItem(e,JSON.stringify(t))}catch{}},300))}var ac=new Set([`form`,`detail`]);function oc(e){return typeof e==`string`&&ac.has(e)}function sc(e,t){let n=e.type||`grid`,r=oc(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 cc(e){let t=e.config??{},n={...t};return delete n.data,{...n,id:e.name,label:e.label??t.label}}function lc(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 uc({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s,metadataClient:c,onAfterChange:l}){let{t:u}=F(),d=(0,$.useRef)(null),f=(0,$.useMemo)(()=>Ia(),[]),[p]=(0,$.useState)(()=>`view_${Date.now()}`),m=(0,$.useMemo)(()=>({id:p,label:u(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[]}),[]),h=(0,$.useMemo)(()=>sc(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)(()=>lc(i),[i.fields]),T=hi(g.viewKind)?`form`:`list`,E=(0,$.useCallback)(e=>{let t={...S.current,...e};if(S.current=t,_(t),y(!0),a){let e=cc(t);for(let[t,n]of Object.entries(e))t!==`id`&&a(t,n)}},[a]),D=(0,$.useCallback)(()=>{let e=cc(g);n===`create`?s?.(e):(o?.(e),x(e=>e+1)),y(!1)},[g,o,s,n]),O=(0,$.useCallback)(()=>{if(n===`create`){t();return}_(h),y(!1)},[h,n,t]),k=(0,$.useCallback)(e=>{let t=sc(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)(Fi,{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)(io,{type:`view`,name:r.id,metadataClient:c,dirty:v,onResume:k,savedSignal:b,onAfterChange:l}),(0,Q.jsx)(J,{variant:`ghost`,size:`sm`,onClick:O,"data-testid":`view-config-discard`,children:u(`console.objectView.discard`)}),(0,Q.jsx)(J,{size:`sm`,onClick:D,disabled:n===`edit`&&!v,"data-testid":`view-config-save`,children:u(`console.objectView.save`)})]})]}):(0,Q.jsx)(`div`,{ref:d,tabIndex:-1,"data-testid":`view-config-panel`,"aria-hidden":!0})}function dc(e,t,n){switch(e){case`system`:return{icon:`Lock`,title:t(`list.managedBy.system.title`,{defaultValue:`Nothing here yet`}),message:t(`list.managedBy.system.message`,{defaultValue:`Entries appear automatically when their source action runs (e.g. Submit for Approval, Share, Invite). Trigger one of those on a source record to create a row.`})};case`append-only`:return{icon:`Archive`,title:t(`list.managedBy.appendOnly.title`,{defaultValue:`No events recorded`}),message:t(`list.managedBy.appendOnly.message`,{defaultValue:`This is an immutable audit log. Rows are written by the platform when events occur — you can export the history but cannot create entries from here.`})};case`better-auth`:return n===`sys_user`?{icon:`ShieldAlert`,title:t(`list.managedBy.betterAuthUser.title`,{defaultValue:`No users yet`}),message:t(`list.managedBy.betterAuthUser.message`,{defaultValue:`User accounts are provisioned by the authentication provider, not created here. Invite teammates to your organization and they appear automatically on first sign-in (SSO just-in-time provisioning). App end-users arrive when they sign up through your app.`})}:{icon:`ShieldAlert`,title:t(`list.managedBy.betterAuth.title`,{defaultValue:`No identity records`}),message:t(`list.managedBy.betterAuth.message`,{defaultValue:`These records are created by the authentication provider — through sign-in, provisioning, and security flows — not added by hand here.`})};default:return}}function fc(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 pc=new Set;function mc(e,t,n,r){let i=[`userFilters`,`quickFilters`].filter(e=>(n?.[e]??r?.[e])!=null);if(i.length===0)return!1;let a=`${e}.${t}`;return pc.has(a)||(pc.add(a),console.warn(`[ObjectView] View "${t}" on object "${e}" defines ${i.join(` and `)}, which are ignored on an object list view (ADR-0053 "views" mode — the view switcher is the only nav control here). Move them to a page list (InterfaceListPage "filters" mode).`)),!0}var hc=new Set([`archived`,`failed`]);function gc(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 _c(e){let{enabled:t,dataSource:n,authFetch:r,apiBase:i,refreshKey:a}=e,{activeOrganization:o}=_(),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=>!hc.has(String(e?.status??``))).some(e=>gc(e)===`production`),canCreateDevelopmentEnv:void 0,upgradeUrl:lo,source:`derived`}}catch{return{ready:!1,hasProductionEnv:!1,canCreateDevelopmentEnv:void 0,upgradeUrl:lo,source:`unknown`}}};return(async()=>{let t=await a()??await o();e||l(t)})(),()=>{e=!0}},[t,s,i,r,n,a]),c}var vc=`create_environment`;function yc({actions:e,entitlements:t,onUpgrade:n}){let r=(e||[]).filter(e=>e?.locations?.includes(`list_toolbar`));if(r.length===0)return null;let i=t?.ready?so(t):null;if(i===`upgrade_for_development`){let e=r.filter(e=>e?.name!==vc);return(0,Q.jsxs)(Q.Fragment,{children:[e.length>0&&(0,Q.jsx)(D,{schema:{type:`action:bar`,location:`list_toolbar`,actions:e,size:`sm`,variant:`outline`}}),(0,Q.jsxs)(J,{size:`sm`,onClick:()=>n(oo(t)),className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,"data-testid":`environment-add-upgrade`,children:[(0,Q.jsx)(Ct,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{children:`Add environment`})]})]})}return(0,Q.jsx)(D,{schema:{type:`action:bar`,location:`list_toolbar`,actions:r.map(e=>e?.name!==vc||i==null?e:i===`setup_production`?{...e,label:`Set up your production environment`,variant:`primary`}:{...e,label:`Add development environment`}),size:`sm`,variant:`outline`}})}var bc=(0,$.lazy)(()=>o(()=>import(`./plugin-charts-BZo5ApEF.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),xc=(0,$.lazy)(()=>o(()=>import(`./plugin-grid-eiIl2HN_.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),Sc={grid:qn,kanban:Zt,calendar:ie,gallery:St,timeline:Ue,gantt:Gn,map:qe,chart:Dt},Cc={id:`current-user`,name:`Demo User`};function wc(e,t){if(!Array.isArray(e))return e;let n=e=>{if(typeof e==`string`)return e===`{current_user_id}`?t??e:e;if(Array.isArray(e))return e.map(n);if(e&&typeof e==`object`){let t={};for(let r of Object.keys(e))t[r]=n(e[r]);return t}return e};return e.map(n)}function Tc({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let{objectName:i}=l(),{t:a}=F();return t.find(e=>e.name===i)?(0,Q.jsx)(Ec,{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)(ht,{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)(qn,{className:`h-6 w-6 text-muted-foreground`})}),(0,Q.jsx)(ke,{children:a(`console.objectView.objectNotFound`)}),(0,Q.jsxs)(W,{children:[a(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,a(`console.objectView.objectNotFoundHint`)]})]})})}function Ec({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}=Wa(),{t:v}=F(),{objectLabel:b,objectDescription:S,viewLabel:C,viewEmptyState:w,actionLabel:T,actionConfirm:E,actionSuccess:O,actionParamText:k,fieldLabel:A,fieldOptionLabel:j}=_e(),{isFavorite:M,toggleFavorite:N}=Gr(),P=Sa(),[I,te]=(0,$.useState)(!1),[ne,re]=(0,$.useState)(`edit`),[ie,ae]=(0,$.useState)(!1),[oe,se]=(0,$.useState)(!1),[R,ce]=(0,$.useState)(null),le=(0,$.useRef)({}),B=(0,$.useRef)({}),V=(0,$.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!u||!t)return;let i=B.current[t]||{};B.current[t]={...i,...r};let a=le.current[t];a&&clearTimeout(a),le.current[t]=setTimeout(()=>{let r=B.current[t]||{};delete B.current[t],delete le.current[t],Promise.resolve(e.updateViewConfig(u,t,{...n,...r})).catch(e=>{console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,u]),ue=(0,$.useCallback)(e=>{ce(e),W(e=>e+1);let t=e.id;P&&t?no(`view`,t,e,{metadataClient:P}).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing metadataClient or viewId.`)},[P]),de=(0,$.useCallback)(async e=>{try{let n;if(P){let r=t?.find?.(e=>e.name===u),i=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),a=[],o=r?.highlightFields;Array.isArray(o)&&o.length>0?a=o.filter(e=>r.fields?.[e]):r?.fields&&(a=Object.entries(r.fields).filter(([e,t])=>t&&!t.hidden&&!i.has(e)).map(([e])=>e).slice(0,5));let s=Array.isArray(e.columns)&&e.columns.length>0?e.columns:a,c={...e,columns:s};if(e.type===`kanban`)c.kanban={...c.kanban||{},columns:s};else if(e.type===`gallery`){let e=c.gallery||{};(!Array.isArray(e.visibleFields)||e.visibleFields.length===0)&&(c.gallery={...e,visibleFields:s})}n=await ro(`view`,String(e?.name??e?.id??c?.id??``),c,{metadataClient:P})}te(!1),re(`edit`),W(e=>e+1),n&&(d?o(`../${n}`,{relative:`path`}):o(`view/${n}`))}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,u,t,o,d,P]),[fe,pe]=(0,$.useState)(void 0),{user:me,activeOrganization:H}=_(),he=g(),{can:ge}=y(),U=t.find(e=>e.name===u),[ve,W]=(0,$.useState)(0),ye=co({dataSource:e,objects:t,objectName:U.name,onRefresh:()=>W(e=>e+1)}),{confirmHandler:be,toastHandler:xe}=ye,Se=U.name===`sys_environment`,Ce=_c({enabled:Se,dataSource:e,authFetch:ye.authFetch,apiBase:``,refreshKey:ve}),we=(0,$.useMemo)(()=>(U.actions||[]).map(e=>({...e,label:T(U.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:E(U.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:O(U.name,e.name,e.successMessage)}})),[U,T,E,O]),Te=(0,$.useMemo)(()=>Wi(U),[U]);(0,$.useEffect)(()=>{r===void 0||r===0||W(e=>e+1)},[r]);let[Ee,De]=(0,$.useState)(!1),[Oe,ke]=(0,$.useState)([]);(0,$.useEffect)(()=>{let t=!1;if(!u){ke([]);return}return typeof e?.listViews==`function`?(e.listViews(u).then(e=>{if(t)return;let n=(e||[]).map(e=>({...e,id:e.name||e.id,objectName:e.objectName||e.object||u}));ke(n)}).catch(e=>{console.error(`[ObjectView] Failed to load overlay views:`,e),t||ke([])}),()=>{t=!0}):(ke([]),()=>{t=!0})},[e,u,ve]);let[Ae,je]=(0,$.useState)({});(0,$.useEffect)(()=>{let t=!1;if(!e||!u){je({});return}let n=U.listViews||U.list_views||{},r=Object.keys(n),i=U.list;if(i&&typeof i==`object`){let e=i.name||`list`;r.includes(e)||r.unshift(e)}if(r.length===0){je({});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||je(e)}),()=>{t=!0}},[e,u,U.listViews,U.list_views,U.list,ve]);let G=(0,$.useMemo)(()=>{let e=new Set([`id`,`created_at`,`createdAt`,`updated_at`,`updatedAt`,`deleted_at`,`deletedAt`,`created_by`,`createdBy`,`updated_by`,`updatedBy`,`_version`,`_rev`]),t=()=>{let t=U.highlightFields;return Array.isArray(t)&&t.length>0?t.filter(e=>U.fields?.[e]):U.fields?Object.entries(U.fields).filter(([t,n])=>!(!n||n.hidden||e.has(t))).map(([e])=>e).slice(0,5):[]},n=U.listViews||U.list_views||{},r=Object.entries(n).map(([e,t])=>{let n=Ae[e];return{id:e,...t,...n||{},type:n?.type||t.type||`grid`}}),i=U.list;if(i&&typeof i==`object`){let e=i.name||`list`,t=r.findIndex(t=>t.id===e);if(t>=0){let[e]=r.splice(t,1);r.unshift({...e,isDefault:!0})}else{let t=Ae[e];r.unshift({id:e,...i,...t||{},type:t?.type||i.type||`grid`,isDefault:!0})}}r.length===0&&r.push({id:`all`,label:v(`console.objectView.allRecords`),type:`grid`,columns:t()});let a=new Set(r.map(e=>e.id));for(let e of Oe){let t=e.id||e._id;if(!t)continue;let n={label:e.label||e.name||t,type:e.type||`grid`,columns:e.columns,filter:e.filter,sort:e.sort,showSearch:e.showSearch,showFilters:e.showFilters,showSort:e.showSort,isPinned:e.isPinned,isDefault:e.isDefault,visibility:e.visibility,sortOrder:e.sortOrder,...e,id:t},i={};for(let[e,t]of Object.entries(n))t!==void 0&&(i[e]=t);if(a.has(t)){let e=r.findIndex(e=>e.id===t);r[e]={...r[e],...i}}else r.push(i)}let o=new Set([`grid`,`list`,`table`]);for(let e of r)o.has(e.type)&&(!Array.isArray(e.columns)||e.columns.length===0)&&(e.columns=t());let s=new Map(r.map((e,t)=>[e.id,t])),c=[];try{let e=typeof window<`u`?window.localStorage?.getItem(`viewOrder:${U.name}`):null;e&&(c=JSON.parse(e))}catch{}let l=new Map(c.map((e,t)=>[e,t]));return r.sort((e,t)=>{let n=l.get(e.id),r=l.get(t.id);if(n!==void 0&&r!==void 0)return n-r;if(n!==void 0)return-1;if(r!==void 0)return 1;let i=Oe.find(t=>(t.id||t._id)===e.id),a=Oe.find(e=>(e.id||e._id)===t.id),o=i&&typeof i.sortOrder==`number`,c=a&&typeof a.sortOrder==`number`;return o&&c?i.sortOrder===a.sortOrder?(i.created_at||``).localeCompare(a.created_at||``):i.sortOrder-a.sortOrder:o?-1:c?1:(s.get(e.id)??0)-(s.get(t.id)??0)}),r},[U,Oe,Ae,v]),Me=(0,$.useMemo)(()=>G.find(e=>e.isDefault)?.id,[G]),Ne=d||f.get(`view`)||void 0,Pe=(0,$.useMemo)(()=>fc(Ne,G.map(e=>e.id),U.name),[Ne,G,U.name]);(0,$.useEffect)(()=>{Ne&&!Pe&&console.warn(`[ObjectView] Requested view "${Ne}" not found on object "${U.name}"; falling back to the default view. Known views: ${G.map(e=>e.id).join(`, `)}`)},[Ne,Pe,U.name,G]);let Fe=Pe||Me||G[0]?.id,Ie=G.find(e=>e.id===Fe)||G[0],Le=R&&R.id===Ie?.id?{...Ie,...R}:Ie,Re=(0,$.useCallback)((e,t)=>{ce(n=>({...n||{},id:Ie?.id,[e]:t}))},[Ie?.id]),K=e=>{let t=G.find(t=>t.id===e);t&&(t.id!==Fe&&te(!1),d?o(`../${t.id}`,{relative:`path`}):o(`view/${t.id}`))},ze=(0,$.useMemo)(()=>(G||[]).map(e=>{let t=Sc[e.type];return{id:e.id,label:C(U.name,e.name||e.id,e.label||e.name||e.id),icon:t?(0,Q.jsx)(t,{className:`h-4 w-4`}):void 0}}),[G,U.name,C]);Ds({views:ze,activeViewId:Fe??``,onChange:K,enabled:ze.length>0&&!!Fe});let Be=(0,$.useCallback)(()=>{ae(!0)},[]),Ve=(0,$.useCallback)((e,t)=>{if(e===`settings`){let e=G.find(e=>e.type===t);e&&K(e.id),re(`edit`),te(!0)}},[G,K]),He=(0,$.useCallback)(e=>Oe.some(t=>(t.id||t._id)===e),[Oe]),Ue=(0,$.useCallback)(async(t,n)=>{if(!He(t)){X.error(v(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be renamed.`);return}try{typeof e?.updateView==`function`&&await e.updateView(u,t,{label:n}),W(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),X.error(v(`objectViewActions.renameFailed`))}},[e,u,He,v]),We=(0,$.useCallback)(async t=>{if(!e)return;if(!He(t)){X.error(v(`console.objectView.cannotDeleteMetaView`)||`Built-in views cannot be deleted.`);return}let n=G.find(e=>e.id===t)?.label||t;if(await be(v(`console.objectView.deleteViewConfirm`,{name:n})||`Are you sure you want to delete the view "${n}"? This cannot be undone.`,{title:v(`console.objectView.deleteViewTitle`)||`Delete view`,confirmText:v(`console.objectView.delete`)||`Delete`,cancelText:v(`console.objectView.cancel`)||`Cancel`}))try{if(typeof e?.deleteView==`function`&&await e.deleteView(u,t),t===Fe){let e=G.find(e=>e.id!==t);e&&o(d?`../${e.id}`:`view/${e.id}`,d?{relative:`path`}:void 0)}W(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),X.error(v(`objectViewActions.deleteFailed`))}},[e,He,Fe,G,d,o,v,be]),Ge=(0,$.useCallback)(async(t,n)=>{if(e){if(!He(t)){X.error(v(`console.objectView.cannotEditMetaView`)||`Built-in views cannot be pinned.`);return}try{typeof e?.updateView==`function`&&await e.updateView(u,t,{isPinned:n}),W(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,u,He,v]),Ke=(0,$.useCallback)(async t=>{if(e){if(!He(t)){X.error(v(`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=Oe.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),W(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),X.error(`Failed to set default view`)}}},[e,u,Oe,He,v]),qe=(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(Oe.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)}}W(e=>e+1)},[e,Oe,u]),Je=(0,$.useCallback)(e=>{if(!He(e)){X.error(v(`console.objectView.cannotEditMetaView`)||`System view — it cannot be edited.`);return}e!==Fe&&K(e),re(`edit`),te(!0)},[Fe,K,He,v]),Ye=(0,$.useCallback)(()=>{ae(!0)},[]),Xe=me?{id:me.id,name:me.name,avatar:me.image}:Cc,Ze=Ar({objectName:U.name,objectLabel:U.label,dataSource:e,onEdit:n,onRefresh:()=>W(e=>e+1),onConfirm:be,onToast:xe}),{lastMessage:Qe}=Qi({channel:`object:${U.name}`}),{hasConflicts:$e,resolveAllConflicts:et}=Li(U.name?`user-${U.name}`:`current-user`);(0,$.useEffect)(()=>{Qe&&($e&&et(`remote`),W(e=>e+1))},[Qe,$e,et]),(0,$.useEffect)(()=>{e?.find&&U.name&&e.find(U.name,{limit:0}).then(e=>{typeof e?.total==`number`?pe(e.total):Array.isArray(e?.data)?pe(e.data.length):Array.isArray(e)&&pe(e.length)}).catch(()=>{})},[e,U.name,ve]);let tt=(0,$.useMemo)(()=>{let e=Le?.navigation??U.navigation;return e?e.mode===`page`?e:{...e,width:e.width??$a(e.size,U)}:L(U)===`page`?{mode:`page`}:{mode:`drawer`,width:$a(`auto`,U)}},[Le?.navigation,U]),nt=f.get(Ji),rt=Array.from(f.entries()).filter(([e])=>e.startsWith(`filter[`)).map(([e,t])=>`${e}=${t}`).join(`&`),it=(0,$.useMemo)(()=>{let e=[];return new URLSearchParams(rt).forEach((t,n)=>{let r=/^filter\[(.+)\]$/.exec(n);r&&r[1]&&t!==``&&e.push([r[1],`=`,t])}),e},[rt]),[at]=(0,$.useState)(()=>Xa(new URLSearchParams(window.location.search))),ot=(0,$.useCallback)(e=>{p(t=>Ya(t,e),{replace:!0})},[p]),st=(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:C(U.name,Le?.name??``,Le?.label??``)||b(U)}};d?o(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):o(`record/${encodeURIComponent(String(e))}`,{state:n})},[o,d,m.pathname,m.search,U,Le?.name,Le?.label,C,b]),q=ee({navigation:tt,objectName:U.name,onNavigate:st}),ct=()=>{q.close();let e=new URLSearchParams(f);e.delete(Ji),p(e)},ut=(0,$.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){q.handleClick(e,t);return}if(q.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(f);e.set(Ji,String(t)),p(e);return}}q.handleClick(e,t)},[q,f,p]),dt=(0,$.useCallback)(()=>{let e=q.selectedRecord,t=e&&(e.id??e._id);t!=null&&(ct(),st(t))},[q.selectedRecord,st]);(0,$.useEffect)(()=>{nt&&!q.isOpen?q.open({id:nt}):!nt&&q.isOpen&&q.close()},[nt]);let ft=(0,$.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=ve+(i||0),o=`${u}-${Le.id}-${a}`,s=Le,c=Qs(me?.id,u,Le.id),l=tc(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)(bc,{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)(bc,{dataSource:t,schema:{type:`object-chart`,objectName:U.name,chartType:e.chartType||`bar`,aggregate:{field:r,function:i,groupBy:n},xAxisKey:n,series:a,config:e.config,filter:e.filter,className:`h-[400px] w-full`}})},o)}return mc(U.name,s.id||s.name||``,s,e),(0,Q.jsx)(Za,{schema:{...e,rowHeight:s.rowHeight??e.rowHeight,densityMode:s.densityMode??e.densityMode,sort:s.sort??e.sort,filter:(()=>{let t=wc(s.filter??e.filter,Xe.id);return it.length?[...Array.isArray(t)?t:[],...it]:t})(),hiddenFields:s.hiddenFields??e.hiddenFields,columnState:s.columnState??e.columnState,onDensityChange:e=>{V(s.id,s,{densityMode:e})},onSortChange:e=>{V(s.id,s,{sort:e})},onFilterChange:e=>{V(s.id,s,{filter:e})},onHiddenFieldsChange:e=>{V(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{V(s.id,s,{columnState:e})},inlineEdit:s.inlineEdit??s.editRecordsInline??e.inlineEdit,appearance:s.appearance?s.showDescription==null?s.appearance:{...s.appearance,showDescription:s.showDescription}:s.showDescription==null?e.appearance:{showDescription:s.showDescription},showViewSwitcher:((s.appearance??e.appearance)?.allowedVisualizations?.length??0)>1,showSearch:s.showSearch??e.showSearch,showSort:s.showSort??e.showSort,showFilters:s.showFilters??e.showFilters,showHideFields:s.showHideFields??e.showHideFields,showGroup:s.showGroup??e.showGroup,showColor:s.showColor??e.showColor,showDensity:s.showDensity??e.showDensity,allowExport:s.allowExport??e.allowExport,exportOptions:s.allowExport===!1?void 0:s.exportOptions??e.exportOptions,striped:s.striped??e.striped,bordered:s.bordered??e.bordered,color:s.color??e.color,wrapHeaders:s.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:s.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:s.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:s.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:s.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:s.fieldTextColor??e.fieldTextColor,prefixField:s.prefixField??e.prefixField,showDescription:s.showDescription??e.showDescription,navigation:s.navigation??e.navigation,selection:s.selection??e.selection,pagination:s.pagination??e.pagination,searchableFields:s.searchableFields??e.searchableFields,filterableFields:s.filterableFields??e.filterableFields,resizable:s.resizable??e.resizable,rowActions:s.rowActions??e.rowActions,rowActionDefs:Array.isArray(U?.actions)?U.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)).map(e=>({...e,label:T(U.name,e.name,e.label||e.name),...e.confirmText!==void 0&&{confirmText:E(U.name,e.name,e.confirmText)},...e.successMessage!==void 0&&{successMessage:O(U.name,e.name,e.successMessage)}})):[],bulkActions:s.bulkActions??e.bulkActions,bulkActionDefs:s.bulkActionDefs??e.bulkActionDefs,sharing:s.sharing??e.sharing,addRecord:s.addRecord??e.addRecord,conditionalFormatting:s.conditionalFormatting??e.conditionalFormatting,quickFilters:void 0,userFilters:void 0,showRecordCount:s.showRecordCount??e.showRecordCount,allowPrinting:s.allowPrinting??e.allowPrinting,virtualScroll:s.virtualScroll??e.virtualScroll,emptyState:w(U.name,s.name||s.id||``,s.emptyState??e.emptyState??dc(U?.managedBy,v,U.name)),aria:s.aria??e.aria,...(()=>{let e=wc([...Array.isArray(s.filter)?s.filter:[],...it],Xe.id);return Array.isArray(e)&&e.length?{filters:e}:{}})(),...s.sort?.length?{sort:s.sort}:{},options:{kanban:{groupBy:s.kanban?.groupByField||s.kanban?.groupField||`status`,groupField:s.kanban?.groupByField||s.kanban?.groupField||`status`,titleField:s.kanban?.titleField||U.titleField||`name`,cardFields:s.kanban?.columns},calendar:{startDateField:s.calendar?.startDateField||`due_date`,endDateField:s.calendar?.endDateField,titleField:s.calendar?.titleField||`name`,colorField:s.calendar?.colorField,allDayField:s.calendar?.allDayField,defaultView:s.calendar?.defaultView},timeline:{dateField:s.timeline?.dateField||`due_date`,titleField:s.timeline?.titleField||U.titleField||`name`,descriptionField:s.timeline?.descriptionField},map:{locationField:s.map?.locationField,titleField:s.map?.titleField||U.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||U.titleField||`name`,subtitleField:s.gallery?.subtitleField},gantt:{...s.gantt||{},startDateField:s.gantt?.startDateField||`start_date`,endDateField:s.gantt?.endDateField||`end_date`,titleField:s.gantt?.titleField||`name`},tree:{...s.tree||{},labelField:s.tree?.labelField||s.tree?.titleField||U.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&&Ze.deleteRecord(String(e.id))},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&Ze.execute({type:`delete`,confirmText:v(`console.objectView.bulkDeleteConfirm`,{count:t.length,defaultValue:`Delete ${t.length} selected records? This cannot be undone.`}),params:{records:t}})},onRowClick:(e,t)=>{ut(e,t)},onSortChange:e=>{V(s.id,s,{sort:e})},onFilterChange:e=>{V(s.id,s,{filter:e}),ic(c,{filters:e})},onSearchChange:e=>{ic(c,{search:e})},onHiddenFieldsChange:e=>{V(s.id,s,{hiddenFields:e})},onInlineEditChange:e=>{V(s.id,s,{inlineEdit:e})},onColumnStateChange:e=>{V(s.id,s,{columnState:e})},userFilterSelections:at,onUserFilterSelectionsChange:ot,initialFilters:l?.filters,initialSearchTerm:l?.search,dataSource:t},o)},[Le,U,u,ve,q,Ze,V,it,at,ot,me?.id]),pt=(0,$.useMemo)(()=>G.map(e=>e.id===Fe&&R&&R.id===e.id?{...e,...R}:e),[G,Fe,R]),mt=(0,$.useMemo)(()=>({type:`object-view`,objectName:U.name,layout:`page`,showSearch:Le?.showSearch!==!1,showFilters:Le?.showFilters!==!1,showSort:Le?.showSort!==!1,showCreate:!1,showRefresh:!0,allowCreateView:he,viewActions:he?[{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:C(U.name,Le?.name??``,Le?.label??``)||b(U)}};d?o(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):o(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[U,n,Le?.showSearch,Le?.showFilters,Le?.showSort,Le?.name,Le?.label,o,d,he,m.pathname,m.search,C,b]);return(0,Q.jsxs)(x,{...ye.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)(qa,{title:(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:b(U)}),(0,Q.jsx)(ao,{managedBy:U?.managedBy})]}),description:U.description?S(U):void 0,icon:(0,Q.jsx)(Ha(U?.icon),{className:`h-4 w-4`}),actions:(0,Q.jsxs)(Q.Fragment,{children:[u&&(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,onClick:()=>N({id:`object:${u}`,label:b(U),href:`/apps/${c}/${u}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":M(`object:${u}`),"aria-label":M(`object:${u}`)?v(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):v(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${u}`,children:M(`object:${u}`)?(0,Q.jsx)(Bt,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,Q.jsx)(Sn,{className:`h-4 w-4`})}),Te.create&&ge(U.name,`create`)&&(0,Q.jsxs)(J,{size:`sm`,onClick:Ze.create,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,children:[(0,Q.jsx)(Ct,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:v(`console.objectView.new`)})]}),Te.import&&ge(U.name,`create`)&&(0,Q.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>De(!0),className:`hidden sm:inline-flex shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,title:v(`console.objectView.importTitle`),"data-testid":`object-view-import-button`,children:[(0,Q.jsx)(z,{className:`h-4 w-4`}),(0,Q.jsx)(`span`,{className:`hidden sm:inline`,children:v(`console.objectView.import`)})]}),U.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(Se?(0,Q.jsx)(yc,{actions:we,entitlements:Ce,onUpgrade:ye.openEntitlementDialog}):(0,Q.jsx)(D,{schema:{type:`action:bar`,location:`list_toolbar`,actions:we,size:`sm`,variant:`outline`,mobileMaxVisible:0}}))]})})}),Te.create&&ge(U.name,`create`)&&(0,Q.jsx)(`button`,{type:`button`,onClick:Ze.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":v(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,Q.jsx)(Ct,{className:`h-5 w-5`})}),Ee&&(0,Q.jsx)($.Suspense,{fallback:null,children:(0,Q.jsx)(xc,{open:Ee,onOpenChange:De,objectName:U.name,objectLabel:b(U),fields:Object.entries(U.fields||{}).filter(([,e])=>![`formula`,`summary`,`autonumber`].includes(e?.type)&&!e?.readonly&&e?.permissions?.write!==!1).map(([e,t])=>({name:e,label:t?.label||e,type:t?.type||`text`,required:!!t?.required,...t?.options?{options:t.options}:{}})),dataSource:e,onComplete:e=>{W(e=>e+1);let t=e.importedRows,n=e.skippedRows;n>0?X.warning(v(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&X.success(v(`console.objectView.importedToast`,{count:t}))}})}),G.length>=1&&(()=>{let e=G.map(e=>{let t=Oe.find(t=>(t.id||t._id)===e.id),n=!t;return{id:e.id,label:C(U.name,e.name||e.id,e.label||e.name||e.id),type:e.type,hasActiveFilters:Array.isArray(e.filter)&&e.filter.length>0,hasActiveSort:Array.isArray(e.sort)&&e.sort.length>0,isDefault:!!(t?.isDefault??e.isDefault),isPinned:!!(t?.isPinned??e.isPinned),visibility:t?.visibility??e.visibility,readonly:n,readonlyReason:n?v(`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)(eo,{views:e,activeViewId:Fe,onViewChange:K,viewTypeIcons:Sc,config:{reorderable:!1,showAddButton:he,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:he?Ye:void 0,onRenameView:he?Ue:void 0,onDeleteView:he?We:void 0,onPinView:he?Ge:void 0,onSetDefaultView:he?Ke:void 0,onConfigView:he?Je:void 0,onManageViews:he?()=>se(!0):void 0}),he&&(0,Q.jsx)(Qa,{open:oe,onOpenChange:se,views:e,activeViewId:Fe,viewTypeIcons:Sc,onRename:Ue,onDelete:We,onSetDefault:Ke,onSetPinned:Ge,onReorder:qe,onAddView:Ye,onConfigView:Je})]})})})(),(0,Q.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[q.mode===`split`&&q.isOpen?(0,Q.jsx)(lt,{...q,setIsOpen:e=>{e||ct()},title:b(U),onExpand:dt,expandLabel:v(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${U.name}`,mainContent:(0,Q.jsxs)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:[(0,Q.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,Q.jsx)(to,{schema:mt,dataSource:e,views:pt,activeViewId:Fe,onViewChange:K,onEdit:e=>n?.(e),onRowClick:(e,t)=>{ut(e,t)},renderListView:ft,onCreateView:Be,hideNamedViewTabs:!0,onViewAction:Ve})})}),typeof fe==`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:v(`console.objectView.recordCount`,{count:fe})})]}),children:r=>{let i=r.id||r._id;return(0,Q.jsx)(Xi,{dataSource:e,objects:t,onEdit:n,objectNameOverride:U.name,recordIdOverride:i,embedded:!0})}}):(0,Q.jsx)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:(0,Q.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,Q.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,Q.jsx)(to,{schema:mt,dataSource:e,views:pt,activeViewId:Fe,onViewChange:K,onEdit:e=>n?.(e),onRowClick:(e,t)=>{ut(e,t)},renderListView:ft,onCreateView:Be,hideNamedViewTabs:!0,onViewAction:Ve})})})}),(0,Q.jsx)(Ka,{open:h&&he,sections:[{title:`View Configuration`,data:Le},{title:`Object Definition`,data:U}]}),(0,Q.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${I&&he?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,Q.jsx)(uc,{open:I&&he,onClose:()=>{te(!1),re(`edit`)},mode:ne,activeView:Le,objectDef:U,recordCount:fe,onSave:ue,onViewUpdate:Re,onCreate:de,metadataClient:P,onAfterChange:()=>W(e=>e+1)})}),(0,Q.jsx)(Ja,{open:ie&&he,onOpenChange:ae,existingLabels:G.map(e=>e.label).filter(Boolean),objectDef:U,onCreate:e=>de(e)})]}),q.mode!==`split`&&(0,Q.jsx)(lt,{...q,setIsOpen:e=>{e||ct()},title:b(U),onExpand:dt,expandLabel:v(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${U.name}`,children:r=>{let i=r.id||r._id;return(0,Q.jsx)(Xi,{dataSource:e,objects:t,onEdit:n,objectNameOverride:U.name,recordIdOverride:i,embedded:!0})}})]}),ye.dialogs]})}function Dc({appName:e,error:t,onRetry:n}){let{t:r}=F(),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)(ht,{children:[(0,Q.jsx)(`div`,{className:`mb-2 flex justify-center text-muted-foreground`,"aria-hidden":`true`,children:i?(0,Q.jsx)(_t,{className:`h-8 w-8`}):(0,Q.jsx)(Ne,{className:`h-8 w-8`})}),(0,Q.jsx)(ke,{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)(W,{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)(ut,{className:`mr-1.5 h-3.5 w-3.5`}),r(`preview.empty.retry`,{defaultValue:`Retry`})]})})]})})}var Oc=(0,$.lazy)(()=>o(()=>import(`./RecordDetailView-CzR6BAUv.js`).then(e=>e.n).then(e=>({default:e.RecordDetailView})),__vite__mapDeps([0]),import.meta.url)),kc=(0,$.lazy)(()=>o(()=>import(`./DashboardView-CPFt6TBZ.js`).then(e=>e.t).then(e=>({default:e.DashboardView})),__vite__mapDeps([0,1]),import.meta.url)),Ac=(0,$.lazy)(()=>o(()=>import(`./PageView-GYrk78oW.js`).then(e=>e.t).then(e=>({default:e.PageView})),__vite__mapDeps([0]),import.meta.url)),jc=(0,$.lazy)(()=>o(()=>import(`./ReportView-CIZjxMSJ.js`).then(e=>e.t).then(e=>({default:e.ReportView})),__vite__mapDeps([0,1]),import.meta.url)),Mc=(0,$.lazy)(()=>o(()=>import(`./SearchResultsPage-BPDjxMw8.js`).then(e=>e.t).then(e=>({default:e.SearchResultsPage})),__vite__mapDeps([0]),import.meta.url)),Nc=(0,$.lazy)(()=>o(()=>import(`./RecordFormPage-DadWkJyX.js`).then(e=>e.t).then(e=>({default:e.RecordFormPage})),__vite__mapDeps([0]),import.meta.url)),Pc=(0,$.lazy)(()=>o(()=>import(`./ComponentNavView-CV-L0t8o.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),Fc=(0,$.lazy)(()=>o(()=>import(`./ObjectDataPage-CAJf6Pu3.js`).then(e=>({default:e.ObjectDataPage})),__vite__mapDeps([0]),import.meta.url)),Ic=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CleGXds3.js`).then(e=>e.t).then(e=>({default:e.MetadataDirectoryPage})),__vite__mapDeps([0]),import.meta.url)),Lc=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CleGXds3.js`).then(e=>e.t).then(e=>({default:e.StudioHomePage})),__vite__mapDeps([0]),import.meta.url)),Rc=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CleGXds3.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceListPage})),__vite__mapDeps([0]),import.meta.url)),zc=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CleGXds3.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceEditPage})),__vite__mapDeps([0]),import.meta.url)),Bc=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CleGXds3.js`).then(e=>e.t).then(e=>({default:e.MetadataResourceHistoryPage})),__vite__mapDeps([0]),import.meta.url)),Vc=(0,$.lazy)(()=>o(()=>import(`./metadata-admin-CleGXds3.js`).then(e=>e.t).then(e=>({default:e.MetadataDiagnosticsPage})),__vite__mapDeps([0]),import.meta.url)),Hc=(0,$.lazy)(()=>o(()=>import(`./index-PrzZHiAk.js`).then(e=>e.t).then(e=>({default:e.CreateAppPage})),__vite__mapDeps([0,2]),import.meta.url)),Uc=(0,$.lazy)(()=>o(()=>import(`./index-PrzZHiAk.js`).then(e=>e.t).then(e=>({default:e.EditAppPage})),__vite__mapDeps([0,2]),import.meta.url)),Wc=(0,$.lazy)(()=>o(()=>import(`./index-PrzZHiAk.js`).then(e=>e.t).then(e=>({default:e.DashboardDesignPage})),__vite__mapDeps([0,2]),import.meta.url)),Gc=(0,$.lazy)(()=>o(()=>import(`./MarketplacePage-SkUEdd3B.js`).then(e=>e.t).then(e=>({default:e.MarketplacePage})),__vite__mapDeps([0]),import.meta.url)),Kc=(0,$.lazy)(()=>o(()=>import(`./MarketplacePackagePage-CiRyU-vK.js`).then(e=>e.t).then(e=>({default:e.MarketplacePackagePage})),__vite__mapDeps([0]),import.meta.url)),qc=(0,$.lazy)(()=>o(()=>import(`./MarketplaceInstalledPage-DIKAvmEt.js`).then(e=>e.t).then(e=>({default:e.MarketplaceInstalledPage})),__vite__mapDeps([0]),import.meta.url));function Jc({appName:e}){let{reviewSeq:t,reviewTarget:n}=Cr(),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 Yc({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,r]=(0,$.useState)(`disconnected`),{user:o,getAuthConfig:u}=_(),d=w(),[f,h]=(0,$.useState)({});(0,$.useEffect)(()=>{let e=!1;return u().then(t=>{e||h(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[u]);let g=a(),v=i(),{appName:y}=l(),{apps:b,objects:x,loading:C,ensureType:D,error:O,refresh:j}=T(),M=_r(),{t:N}=F(),{objectLabel:P}=_e(),[ee,te]=(0,$.useState)(!D);(0,$.useEffect)(()=>{if(!D){te(!0);return}let e=!1;return Promise.all([D(`object`),D(`dashboard`),D(`report`),D(`page`)]).finally(()=>{e||te(!0)}),()=>{e=!0}},[D]);let re=b.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),ie=v.pathname.endsWith(`/create-app`),ae=v.pathname.includes(`/system`),oe=v.pathname.includes(`/metadata`),se=v.pathname===`/apps/setup`||v.pathname.startsWith(`/apps/setup/`),R=ie||ae||oe||se,ce=Ba(b,y),z=ce||(!y||R?re.find(e=>e.isDefault===!0)||re[0]:void 0),le=!!y&&!ce&&!R,[B,V]=(0,$.useState)(`idle`);(0,$.useEffect)(()=>{if(!le){B!==`idle`&&V(`idle`);return}B===`idle`&&!C&&!M&&(V(`checking`),Promise.resolve(j()).finally(()=>V(`done`)))},[le,C,M,B,j]),(0,$.useEffect)(()=>{if(!z?.name)return;let e=y??z.name,t=`/apps/${e}/metadata/package`;(v.pathname===t||v.pathname.startsWith(`${t}/`))&&g(`/apps/${e}/component/developer/packages`,{replace:!0})},[z?.name,y,v.pathname,g]);let[ue,de]=s(),fe=ue.get(Hi),pe=ue.get(Ki),me=ue.get(qi),H=(0,$.useMemo)(()=>fe&&fe!==`new`?{id:fe}:null,[fe]),he=(0,$.useMemo)(()=>{if(!me)return;let e=me.indexOf(`:`);if(!(e<=0))return{[me.slice(0,e)]:me.slice(e+1)}},[me]),[ge,U]=(0,$.useState)(0),ve=!!fe,ye=(0,$.useCallback)(()=>{let e=new URLSearchParams(window.location.search);!e.has(`form`)&&!e.has(`formObject`)&&!e.has(`formLink`)||(e.delete(Hi),e.delete(Ki),e.delete(qi),de(e,{replace:!0}))},[de]),{execute:be,runner:xe}=S();k(d),A({dataSource:d??void 0,onUndo:e=>{X.info(`Undo: ${e.description}`,{duration:4e3}),U(e=>e+1),e?.objectName&&I({objectName:e.objectName,recordId:e.recordId})},onRedo:e=>{X.info(`Redo: ${e.description}`,{duration:3e3}),U(e=>e+1),e?.objectName&&I({objectName:e.objectName,recordId:e.recordId})}}),(0,$.useEffect)(()=>{xe.registerHandler(`crud_success`,async e=>(ye(),U(e=>e+1),X.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),xe.registerHandler(`dialog_cancel`,async()=>(ye(),{success:!0})),xe.registerHandler(`navigate_create`,async e=>{let t=Yr({action:e,context:xe.getContext?.()??{},defaultBaseUrl:`/apps/${y??``}`});return t.success?(g(t.url),{success:!0}):t}),xe.registerHandler(`navigate_edit`,async e=>{let t=Xr({action:e,context:xe.getContext?.()??{},defaultBaseUrl:`/apps/${y??``}`});return t.success?(g(t.url),{success:!0}):t})},[xe,g,y,ye]),(0,$.useEffect)(()=>{if(!d)return;let e=d.onConnectionStateChange(e=>{r(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return r(d.getConnectionState()),e},[d]);let Se=v.pathname.split(`/`).filter(Boolean)[2];(Se===`view`||Se===`record`||Se===`page`||Se===`dashboard`||Se===`design`)&&(Se=``);let Ce=x.find(e=>e.name===Se),we=pe?x.find(e=>e.name===pe):Ce,Te=!!pe&&pe!==Ce?.name,Ee=(0,$.useCallback)(()=>{let e=we?P(we):N(`common.record`,{defaultValue:`Record`});be({type:`crud_success`,params:{message:H?N(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):N(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[be,H,we,P,N]),De=(0,$.useCallback)(()=>{be({type:`dialog_cancel`})},[be]),Oe=(0,$.useCallback)(async e=>{if(Te){let e=we?P(we):N(`common.record`,{defaultValue:`Record`});X.success(H?N(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):N(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})),ye();return}if(Ee(),H||!Ce)return;let t=Jr({objectName:Ce.name,baseUrl:y?`/apps/${y}`:z?.name?`/apps/${z.name}`:``,pathname:v.pathname,search:window.location.search,surface:L(Ce),recordId:e?.id??e?._id});if(t.kind!==`none`){if(t.kind===`detail-page`){let e=new URLSearchParams(window.location.search);e.delete(Hi),e.delete(Ki),e.delete(qi);let n=e.toString(),r=`${v.pathname}${n?`?${n}`:``}`,i=P(Ce);g(t.url,{replace:!0,state:i?{from:{pathname:r,label:i}}:void 0});return}g(t.url,{replace:!0})}},[Ee,Te,we,H,Ce,y,z?.name,v.pathname,g,ye,P,N]);zr({pathname:v.pathname,appName:z?.name,objects:x});let Ae=e=>{let t=qr({objectDef:Ce,baseUrl:y?`/apps/${y}`:z?.name?`/apps/${z.name}`:``,record:e});if(t.kind===`page`){g(t.url);return}let n=e?.id??e?._id,r=new URLSearchParams(window.location.search);r.set(Hi,n!=null&&n!==``?String(n):`new`),r.delete(Ki),r.delete(qi),de(r)},je=e=>{g(`/apps/${e}`)},G=(0,$.useMemo)(()=>new E({user:o?{name:o.name,email:o.email,role:o.role??`user`}:{},app:z||{},data:H||{}}),[o,z,H]);return!d||C||!ee?(0,Q.jsx)(go,{}):M&&(le||!z)?(0,Q.jsx)(Dc,{appName:y,error:O,onRetry:()=>void j()}):le?B===`done`?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(ht,{children:[(0,Q.jsx)(ke,{children:N(`empty.appNotAvailable`,{defaultValue:`App not available`})}),(0,Q.jsx)(W,{children:N(`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:()=>V(`idle`),"data-testid":`app-not-available-retry`,children:N(`common.retry`,{defaultValue:`Retry`})})})]})}):(0,Q.jsx)(go,{}):!z&&!ie&&!ae&&!oe?(0,Q.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,Q.jsxs)(ht,{children:[(0,Q.jsx)(ke,{children:N(`empty.noAppsConfigured`)}),(0,Q.jsx)(W,{children:N(`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:()=>g(`/create-app`),"data-testid":`create-first-app-btn`,children:N(`empty.createFirstApp`)}),(0,Q.jsx)(J,{variant:`outline`,onClick:()=>g(`/apps/setup`),"data-testid":`go-to-settings-btn`,children:N(`empty.systemSettings`)})]})]})}):!z&&(ie||ae||oe)?(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(go,{}),children:(0,Q.jsxs)(m,{children:[(0,Q.jsx)(c,{path:`create-app`,element:(0,Q.jsx)(Hc,{})}),(0,Q.jsx)(c,{path:`system/marketplace`,element:(0,Q.jsx)(Gc,{})}),(0,Q.jsx)(c,{path:`system/marketplace/installed`,element:(0,Q.jsx)(qc,{})}),(0,Q.jsx)(c,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(Kc,{})}),(0,Q.jsx)(c,{path:`metadata`,element:(0,Q.jsx)(Ic,{})}),(0,Q.jsx)(c,{path:`metadata/_diagnostics`,element:(0,Q.jsx)(Vc,{})}),(0,Q.jsx)(c,{path:`metadata/:type`,element:(0,Q.jsx)(Rc,{})}),(0,Q.jsx)(c,{path:`metadata/:type/new`,element:(0,Q.jsx)(zc,{createMode:!0})}),(0,Q.jsx)(c,{path:`metadata/:type/:name`,element:(0,Q.jsx)(zc,{})}),(0,Q.jsx)(c,{path:`metadata/:type/:name/history`,element:(0,Q.jsx)(Bc,{})}),t]})}):(0,Q.jsxs)(Er,{user:o?{id:o.id,name:o.name,email:o.email,role:o.role??`user`,roles:o.roles,isPlatformAdmin:o.isPlatformAdmin??!1}:{name:`Anonymous`,email:``,role:`guest`,isPlatformAdmin:!1},app:z,data:{},features:f,children:[(0,Q.jsx)(kr,{}),(0,Q.jsxs)(Is,{activeAppName:z.name,activeApp:z,onAppChange:je,objects:x,connectionState:n,userId:o?.id,children:[(0,Q.jsx)(Ls,{apps:b,activeApp:z,objects:x,onAppChange:je,dataSource:d}),(0,Q.jsx)(zs,{}),(0,Q.jsx)(Bs,{}),(0,Q.jsx)(Jc,{appName:y}),(0,Q.jsx)(Xs,{children:(0,Q.jsx)($.Suspense,{fallback:(0,Q.jsx)(go,{}),children:(0,Q.jsx)(Us,{className:`h-full`,children:(0,Q.jsxs)(m,{children:[(0,Q.jsx)(c,{path:`/`,element:(()=>{let e=$c(z,{currentUserId:o?.id??null});return e?(0,Q.jsx)(p,{to:e,replace:!0}):(0,Q.jsx)(Lc,{})})()}),(0,Q.jsx)(c,{path:`metadata/package/*`,element:(0,Q.jsx)(p,{to:`/apps/${y??z.name}/component/developer/packages`,replace:!0})}),(0,Q.jsxs)(c,{path:`metadata`,children:[(0,Q.jsx)(c,{index:!0,element:(0,Q.jsx)(Ic,{})}),(0,Q.jsx)(c,{path:`_diagnostics`,element:(0,Q.jsx)(Vc,{})}),(0,Q.jsx)(c,{path:`:type`,element:(0,Q.jsx)(Rc,{})}),(0,Q.jsx)(c,{path:`:type/new`,element:(0,Q.jsx)(zc,{createMode:!0})}),(0,Q.jsx)(c,{path:`:type/:name`,element:(0,Q.jsx)(zc,{})}),(0,Q.jsx)(c,{path:`:type/:name/history`,element:(0,Q.jsx)(Bc,{})})]}),(0,Q.jsx)(c,{path:`:objectName`,element:(0,Q.jsx)(Tc,{dataSource:d,objects:x,onEdit:Ae,externalRefreshKey:ge})}),(0,Q.jsx)(c,{path:`:objectName/new`,element:(0,Q.jsx)(Nc,{mode:`create`})}),(0,Q.jsx)(c,{path:`:objectName/view/:viewId`,element:(0,Q.jsx)(Tc,{dataSource:d,objects:x,onEdit:Ae,externalRefreshKey:ge})}),(0,Q.jsx)(c,{path:`:objectName/data`,element:(0,Q.jsx)(Fc,{dataSource:d,objects:x})}),(0,Q.jsx)(c,{path:`:objectName/record/:recordId`,element:(0,Q.jsx)(Oc,{dataSource:d,objects:x,onEdit:Ae})}),(0,Q.jsx)(c,{path:`:objectName/record/:recordId/edit`,element:(0,Q.jsx)(Nc,{mode:`edit`})}),(0,Q.jsx)(c,{path:`dashboard/:dashboardName`,element:(0,Q.jsx)(kc,{dataSource:d})}),(0,Q.jsx)(c,{path:`report/:reportName`,element:(0,Q.jsx)(jc,{dataSource:d})}),(0,Q.jsx)(c,{path:`page/:pageName`,element:(0,Q.jsx)(Ac,{})}),(0,Q.jsx)(c,{path:`component/:ns/:name/*`,element:(0,Q.jsx)(Pc,{})}),(0,Q.jsx)(c,{path:`component/metadata/directory`,element:(0,Q.jsx)(nl,{mode:`directory`})}),(0,Q.jsx)(c,{path:`component/metadata/resource/*`,element:(0,Q.jsx)(nl,{mode:`resource`})}),(0,Q.jsx)(c,{path:`design/dashboard/:dashboardName`,element:(0,Q.jsx)(Wc,{})}),(0,Q.jsx)(c,{path:`search`,element:(0,Q.jsx)(Mc,{})}),(0,Q.jsx)(c,{path:`create-app`,element:(0,Q.jsx)(Hc,{})}),(0,Q.jsx)(c,{path:`edit-app/:editAppName`,element:(0,Q.jsx)(Uc,{})}),(0,Q.jsx)(c,{path:`system/marketplace`,element:(0,Q.jsx)(Gc,{})}),(0,Q.jsx)(c,{path:`system/marketplace/installed`,element:(0,Q.jsx)(qc,{})}),(0,Q.jsx)(c,{path:`system/marketplace/:packageId`,element:(0,Q.jsx)(Kc,{})}),e,(0,Q.jsx)(c,{path:`:objectName/:maybeRecordId`,element:(0,Q.jsx)(rl,{})}),(0,Q.jsx)(c,{path:`*`,element:(0,Q.jsx)(il,{})})]})})})}),we&&(0,Q.jsx)(hr,{schema:{type:`object-form`,formType:`modal`,objectName:we.name,mode:H?`edit`:`create`,recordId:H?.id,...he&&!H?{initialValues:he}:{},...ne(we,Te?H?`child-edit`:`child-create`:H?`edit`:`create`).size===`full`?{modalSize:`full`}:{},...Zr(we),title:N(H?`form.editTitle`:`form.createTitle`,{object:P(we)}),description:N(H?`form.editDescription`:`form.createDescription`,{object:P(we)}),open:ve,onOpenChange:e=>{e||ye()},layout:`vertical`,fields:we.fields?Array.isArray(we.fields)?we.fields.filter(e=>typeof e==`string`?!0:wr(e.visible,G)).map(e=>typeof e==`string`?e:e.name):Object.entries(we.fields).filter(([e,t])=>wr(t.visible,G)).map(([e])=>e):[],onSuccess:Oe,onCancel:De,showSubmit:!0,showCancel:!0,submitText:H?N(`form.update`,{defaultValue:N(`common.save`,{defaultValue:`Save`})}):N(`form.create`,{defaultValue:N(`common.create`,{defaultValue:`Create`})}),cancelText:N(`common.cancel`)},dataSource:d},`${we.name}:${H?.id||`new`}`)]})]})}function Xc(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=Zc(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=Xc(n.children,t);if(e!==``)return e}}return``}function Zc(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=aa(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function Qc(e,t){if(e)for(let n of e){if(n.id===t)return n;if(n.type===`group`&&n.children){let e=Qc(n.children,t);if(e)return e}}}function $c(e,t){let n=e?.homePageId,r=e?.navigation||[];if(n){let e=Zc(Qc(r,n),t);if(e)return e}return Xc(r,t)}var el=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function tl(e){return!e||el.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function nl({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 rl(){let{objectName:e,maybeRecordId:t}=l(),n=i();return e&&tl(t)?(0,Q.jsx)(p,{to:`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`,replace:!0}):(0,Q.jsx)(il,{})}function il(){let e=a(),{t}=F();return(0,Q.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,Q.jsxs)(ht,{children:[(0,Q.jsx)(ke,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,Q.jsx)(W,{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 al({children:e,userId:t}){let{setContext:n}=Ri(),{t:r}=F(),{enabled:i}=Pi();return(0,$.useEffect)(()=>{n(`home`)},[n]),(0,Q.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`home-layout`,children:[(0,Q.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,Q.jsx)(Ps,{variant:`home`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),i&&(0,Q.jsx)(Po,{appLabel:r(`workspace.default`,{defaultValue:`Workspace`}),objects:[],userId:t})]})}var ol=19,sl=[`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`],cl=`shadow-[0_4px_10px_-2px_rgb(0_0_0/0.25),inset_0_1px_0_0_rgb(255_255_255/0.45)]`;function ll(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function ul({apps:e,favorites:t,onOpen:n,onBrowseMarketplace:r,isAdmin:i}){let{t:a}=F(),{appLabel:o}=_e(),[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-ol,f=s?u:u.slice(0,ol);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)(St,{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)(Pn,{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=Ha(e.icon),r=o({name:e.name,label:Ua(e.label,a)}),i=l.has(e.name),s=sl[ll(e.name)%sl.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:yn(`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`,cl,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)(Bt,{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 dl(e){if(!e)return``;let t=new Date(e).getTime();if(Number.isNaN(t))return``;let n=(Date.now()-t)/1e3;return n<60?`${Math.max(1,Math.floor(n))}s`:n<3600?`${Math.floor(n/60)}m`:n<86400?`${Math.floor(n/3600)}h`:`${Math.floor(n/86400)}d`}function fl({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 pl({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 ml({pendingApprovalsCount:e,notifications:t,onOpenApprovals:n,onOpenNotification:r,t:i}){let a=e+t.length;return(0,Q.jsx)(fl,{icon:Ln,accent:!0,count:a,title:i(`home.actionCenter.title`,{defaultValue:`Needs your attention`}),children:a===0?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(vt,{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)(pl,{icon:Ln,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)(ir,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),onClick:n,testId:`home-action-approvals`}),t.map(e=>(0,Q.jsx)(pl,{icon:Xt,iconClass:`bg-primary/10 text-primary`,label:e.title,meta:dl(e.createdAt),onClick:()=>r(e)},e.id))]})})}var hl={object:Mn,record:ve,dashboard:bt,page:K},gl={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 _l({items:e,onOpen:t,t:n}){return(0,Q.jsx)(fl,{icon:rn,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)(pl,{icon:hl[e.type]||ve,iconClass:gl[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 vl({items:e,onViewAll:t,t:n}){return(0,Q.jsxs)(fl,{icon:Ue,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:[dl(e.timestamp),` · `,e.objectName]})]},e.id))}),(0,Q.jsxs)(`button`,{type:`button`,onClick:t,className:`mt-3 inline-flex items-center gap-1 text-xs text-primary hover:underline`,children:[n(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`}),(0,Q.jsx)(ir,{className:`h-3 w-3`})]})]})}function yl(e=5){let t=w(),{user:n}=_(),[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`}).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 bl(){let{agents:e}=ri({apiBase:(0,$.useMemo)(()=>mi(),[])});return{aiEnabled:e.length>0,askAvailable:e.some(e=>ai(e.name)),buildAvailable:e.some(e=>ii(e.name))}}function xl({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)(an,{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)(vn,{className:`mr-2 h-4 w-4`}),r(`home.askAI`,{defaultValue:`Ask AI`})]})]})}function Sl(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function Cl({t:e}){let t=Sa(),[n,r]=(0,$.useState)([]),{publishAll:i,publishing:a}=Fo(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)(kn,{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 wl({t:e}){let t=a(),{hasLocalPassword:n,getAuthConfig:r}=_(),[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)(de,{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)(Ge,{className:`h-4 w-4`})})]})})}):null}function Tl(){let e=a(),{t}=F(),{apps:n,loading:r}=T(),{recentItems:i}=Wr(),{favorites:o}=Gr(),{user:s}=_(),c=g(),{pendingApprovalsCount:l,notifications:u,activities:d}=yl(),{askAvailable:f,buildAvailable:p}=bl(),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),v=(0,$.useMemo)(()=>t(Sl(new Date().getHours()),{defaultValue:`Welcome`}),[t]),y=(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)(Cl,{t}),(0,Q.jsx)(wl,{t}),(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:c?(0,Q.jsxs)(ht,{children:[(0,Q.jsx)(ke,{children:t(`home.welcome`,{product:ra().branding.productName,defaultValue:`Welcome to {{product}}`})}),(0,Q.jsx)(W,{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)(xl,{askAvailable:f,buildAvailable:p,navigate:e,t,layout:`stack`})]}):(0,Q.jsxs)(ht,{children:[(0,Q.jsx)(ke,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,Q.jsx)(W,{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)(Cl,{t}),(0,Q.jsx)(wl,{t}),(0,Q.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-8 pb-16`,children:(0,Q.jsxs)(`div`,{className:`max-w-7xl mx-auto`,children:[(0,Q.jsxs)(`div`,{className:`mb-7 flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight text-pretty`,children:[(0,Q.jsxs)(`span`,{className:`text-foreground`,children:[v,y?`, `:``]}),y&&(0,Q.jsx)(`span`,{className:`text-primary`,children:y}),(0,Q.jsx)(`span`,{className:`text-foreground/40`,children:`.`})]}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm sm:text-base text-muted-foreground`,children:t(`home.heroTagline`,{defaultValue:`Pick up where you left off, or explore something new.`})})]}),(0,Q.jsx)(xl,{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)(Dn,{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)(Vn,{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)(ul,{apps:m,favorites:o,onOpen:t=>e(`/apps/${Va(t)??t.name}`),onBrowseMarketplace:()=>e(`/apps/setup/system/marketplace`),isAdmin:c}),(0,Q.jsx)(`div`,{className:`mb-6`,children:(0,Q.jsx)(ml,{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)(_l,{items:h,onOpen:t=>e(t),t}),(0,Q.jsx)(vl,{items:d,onViewAll:()=>e(`/apps/setup/sys_activity`),t})]})]})})]})}function El({children:e}){let{setContext:t}=Ri();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)(Ps,{variant:`orgs`})}),(0,Q.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}async function Dl(e){let t=await v()(`${na()}/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 Ol(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 kl({open:e,onOpenChange:t,onCreated:n}){let{t:r}=F(),{createOrganization:i,getAuthConfig:a}=_(),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(``),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(!1),[m,h]=(0,$.useState)(null),[g,v]=(0,$.useState)(!1);return(0,$.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||v(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,$.useEffect)(()=>{u||l(Ol(o))},[o,u]),(0,$.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]),(0,Q.jsx)(st,{open:e,onOpenChange:t,children:(0,Q.jsx)(gt,{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 Dl({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)(Hn,{children:[(0,Q.jsx)(Ae,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,Q.jsx)(ye,{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)(Gt,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,Q.jsx)(Jn,{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)(Gt,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,Q.jsx)(Jn,{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)(Me,{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 Al(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function jl(){let{t:e}=F(),t=a(),[n]=s(),r=n.get(`manage`)===`1`,i=n.get(`create`)===`1`,{organizations:o,activeOrganization:c,isOrganizationsLoading:l,switchOrganization:u,getAuthConfig:d}=_(),[f,p]=(0,$.useState)(``),[m,h]=(0,$.useState)(!1),[g,v]=(0,$.useState)(null),[y,b]=(0,$.useState)(!0);(0,$.useEffect)(()=>{let e=!1;return d().then(t=>{e||t?.features?.multiOrgEnabled===!1&&b(!1)}).catch(()=>{}),()=>{e=!0}},[d]);let x=o??[],S=(0,$.useMemo)(()=>{let e=f.trim().toLowerCase();return e?x.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):x},[x,f]),C=async e=>{v(e.id);try{e.id!==c?.id&&await u(e.id),window.location.href=ds()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),v(null)}},w=e=>{h(!1),C(e)},T=(0,$.useRef)(!1);(0,$.useEffect)(()=>{T.current||l||i||x.length===1&&(T.current=!0,r?t(`/organizations/${x[0].slug}/members`,{replace:!0}):C(x[0]))},[l,x.length,r,i]);let E=(0,$.useRef)(!1);(0,$.useEffect)(()=>{if(l)return;let e=x.length===0&&y;(i||e)&&!E.current&&(E.current=!0,h(!0))},[i,x.length,y,l]);let D=!i&&!l&&x.length===1,O=!l&&x.length===0&&y&&!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)(We,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(Jn,{value:f,onChange:e=>p(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for an organization`}),className:`pl-9`,"data-testid":`organizations-search`})]}),y&&(0,Q.jsxs)(J,{onClick:()=>h(!0),"data-testid":`organizations-new`,children:[(0,Q.jsx)(Ct,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}),x.length===0?(0,Q.jsxs)(ht,{children:[(0,Q.jsx)(ke,{children:e(`organizations.emptyTitle`,{defaultValue:`No organizations yet`})}),(0,Q.jsx)(W,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first organization to get started.`})}),y&&(0,Q.jsxs)(J,{className:`mt-6`,onClick:()=>h(!0),children:[(0,Q.jsx)(Ct,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New organization`})]})]}):S.length===0?(0,Q.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organizations.noMatches`,{defaultValue:`No organizations match your search.`})}):(0,Q.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:S.map(n=>{let r=n.id===c?.id,i=g===n.id;return(0,Q.jsxs)(`button`,{onClick:()=>C(n),disabled:i,className:`group flex items-center gap-3 rounded-lg border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60`,"data-testid":`organization-card-${n.slug}`,children:[(0,Q.jsxs)(In,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,Q.jsx)(Vt,{src:n.logo,alt:n.name}),(0,Q.jsx)(Yn,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:Al(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)(kl,{open:m,onOpenChange:h,onCreated:w})]})}function Ml(){let{t:e}=F(),t=a(),{slug:n}=l(),{organizations:i,activeOrganization:o,isOrganizationsLoading:s,switchOrganization:c}=_(),{setContext:d}=Ri();(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)(Ps,{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)(ue,{className:`h-3.5 w-3.5`}),e(`organization.backToList`,{defaultValue:`Back to organizations`})]}),(0,Q.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`h1`,{className:`truncate text-2xl font-bold tracking-tight`,children: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 Nl(){return d()}function Pl(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function Fl({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=F(),{inviteMember:a}=_(),[o,s]=(0,$.useState)(``),[c,l]=(0,$.useState)(`member`),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(null),[m,h]=(0,$.useState)(null),[g,v]=(0,$.useState)(!1);(0,$.useEffect)(()=>{t&&(s(``),l(`member`),p(null),h(null),v(!1))},[t]);let y=(0,$.useCallback)(async t=>{if(t.preventDefault(),o.trim()){d(!0),p(null);try{let t=await a({organizationId:e,email:o.trim(),role:c});h(t),r?.(t)}catch(e){p(e instanceof Error?e.message:`Failed to invite member`)}finally{d(!1)}}},[o,c,e,a,r]),b=(0,$.useCallback)(async()=>{if(!m)return;let e=Pl(m.id);try{await navigator.clipboard.writeText(e),v(!0),X.success(i(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>v(!1),2e3)}catch{X.error(i(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},[m,i]);return(0,Q.jsx)(st,{open:t,onOpenChange:n,children:(0,Q.jsx)(gt,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:m?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(Hn,{children:[(0,Q.jsx)(Ae,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,Q.jsx)(ye,{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)(Gt,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(Jn,{readOnly:!0,value:Pl(m.id),className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,Q.jsx)(J,{type:`button`,variant:`outline`,size:`icon`,onClick:b,"aria-label":`Copy`,children:g?(0,Q.jsx)(q,{className:`h-4 w-4`}):(0,Q.jsx)(Ht,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`organization.invitations.invitedAs`,{defaultValue:`{{email}} invited as {{role}}`,email:m.email,role:m.role})})]}),(0,Q.jsx)(Me,{children:(0,Q.jsx)(J,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,Q.jsxs)(`form`,{onSubmit:y,children:[(0,Q.jsxs)(Hn,{children:[(0,Q.jsx)(Ae,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,Q.jsx)(ye,{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)(Gt,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,Q.jsx)(Jn,{id:`invite-email`,type:`email`,required:!0,placeholder:`user@example.com`,value:o,onChange:e=>s(e.target.value),autoFocus:!0,"data-testid":`invite-email-input`})]}),(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(Gt,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,Q.jsxs)(Pe,{value:c,onValueChange:e=>l(e),children:[(0,Q.jsx)(Tt,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,Q.jsx)(xt,{})}),(0,Q.jsxs)(Kn,{children:[(0,Q.jsx)(G,{value:`member`,children:i(`organization.roles.member`,{defaultValue:`Member`})}),(0,Q.jsx)(G,{value:`admin`,children:i(`organization.roles.admin`,{defaultValue:`Admin`})}),(0,Q.jsx)(G,{value:`owner`,children:i(`organization.roles.owner`,{defaultValue:`Owner`})})]})]})]}),f&&(0,Q.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`invite-error`,children:f})]}),(0,Q.jsxs)(Me,{children:[(0,Q.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:u,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(J,{type:`submit`,disabled:u||!o.trim(),"data-testid":`invite-submit`,children:[u&&(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}function Il(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function Ll(){let{t:e}=F(),{org:t}=Nl(),{getMembers:n,removeMember:r,updateMemberRole:i}=_(),[a,o]=(0,$.useState)([]),[s,c]=(0,$.useState)(!0),[l,u]=(0,$.useState)(null),[d,f]=(0,$.useState)(!1),[p,m]=(0,$.useState)(null),h=(0,$.useCallback)(async()=>{c(!0),u(null);try{let e=await n(t.id);o(e)}catch(e){u(e instanceof Error?e.message:`Failed to load members`)}finally{c(!1)}},[t.id,n]);(0,$.useEffect)(()=>{h()},[h]);let g=async(n,r)=>{try{await i({organizationId:t.id,memberId:n.id,role:r}),X.success(e(`organization.members.roleUpdated`,{defaultValue:`Role updated`})),h()}catch(t){X.error(t instanceof Error?t.message:e(`organization.members.roleUpdateFailed`,{defaultValue:`Failed to update role`}))}};return s?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):l?(0,Q.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[l,(0,Q.jsx)(J,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:h,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,Q.jsxs)(`div`,{className:`space-y-4`,"data-testid":`members-page`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Q.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[e(`organization.members.title`,{defaultValue:`Members`}),` (`,a.length,`)`]}),(0,Q.jsx)(J,{onClick:()=>f(!0),"data-testid":`invite-member-btn`,children:e(`organization.members.inviteMember`,{defaultValue:`Invite member`})})]}),(0,Q.jsx)(be,{}),(0,Q.jsx)(`div`,{className:`space-y-2`,children:a.map(t=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`member-row-${t.id}`,children:[(0,Q.jsxs)(In,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,Q.jsx)(Vt,{src:t.user.image,alt:t.user.name}),(0,Q.jsx)(Yn,{className:`text-xs font-medium`,children:Il(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)(Ft,{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)(Qt,{children:[(0,Q.jsx)(ar,{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)(wt,{className:`h-4 w-4`})})}),(0,Q.jsxs)(Rn,{align:`end`,children:[(0,Q.jsxs)(on,{onClick:()=>g(t,`owner`),disabled:t.role===`owner`,children:[(0,Q.jsx)(tt,{className:`mr-2 h-4 w-4`}),e(`organization.roles.owner`,{defaultValue:`Owner`})]}),(0,Q.jsxs)(on,{onClick:()=>g(t,`admin`),disabled:t.role===`admin`,children:[(0,Q.jsx)(tt,{className:`mr-2 h-4 w-4`}),e(`organization.roles.admin`,{defaultValue:`Admin`})]}),(0,Q.jsxs)(on,{onClick:()=>g(t,`member`),disabled:t.role===`member`,children:[(0,Q.jsx)(tt,{className:`mr-2 h-4 w-4`}),e(`organization.roles.member`,{defaultValue:`Member`})]}),(0,Q.jsxs)(on,{className:`text-destructive focus:text-destructive`,onClick:()=>m(t),children:[(0,Q.jsx)(Qe,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id))}),(0,Q.jsx)($t,{open:!!p,onOpenChange:e=>!e&&m(null),children:(0,Q.jsxs)(sn,{children:[(0,Q.jsxs)($n,{children:[(0,Q.jsx)(cr,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,Q.jsx)(nn,{children:e(`organization.members.removeConfirmDescription`,{defaultValue:`This will remove {{name}} from the organization. They will lose access immediately.`,name:p?.user?.name??p?.userId??``})})]}),(0,Q.jsxs)(Mt,{children:[(0,Q.jsx)(On,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(zn,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{if(p)try{await r({organizationId:t.id,memberIdOrUserId:p.id}),X.success(e(`organization.members.memberRemoved`,{defaultValue:`Member removed`})),m(null),h()}catch(t){X.error(t instanceof Error?t.message:e(`organization.members.removeFailed`,{defaultValue:`Failed to remove member`}))}},children:e(`organization.members.removeConfirmAction`,{defaultValue:`Remove`})})]})]})}),(0,Q.jsx)(Fl,{organizationId:t.id,open:d,onOpenChange:f,onInvited:()=>h()})]})}function Rl(e){let t=`./`.endsWith(`/`)?`./`:`.//`;return`${window.location.origin}${t}accept-invitation/${e}`}function zl(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`;default:return`secondary`}}function Bl(){let{t:e}=F(),{org:t}=Nl(),{listInvitations:n,cancelInvitation:r}=_(),[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 v=async t=>{let n=Rl(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`}))}},y=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`}))}},b=u===`all`?i:i.filter(e=>e.status===u),x={all:i.length,pending:i.filter(e=>e.status===`pending`).length,accepted:i.filter(e=>e.status===`accepted`).length,rejected:i.filter(e=>e.status===`rejected`).length,canceled:i.filter(e=>e.status===`canceled`).length};return o?(0,Q.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,Q.jsx)(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}),x[t]>0&&(0,Q.jsx)(`span`,{className:`ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs`,children:x[t]})]},t))}),(0,Q.jsx)(be,{}),b.length===0?(0,Q.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organization.invitations.empty`,{defaultValue:`No invitations found.`})}):(0,Q.jsx)(`div`,{className:`space-y-2`,children:b.map(t=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`invitation-row-${t.id}`,children:[(0,Q.jsx)(In,{className:`h-9 w-9 shrink-0`,children:(0,Q.jsx)(Yn,{className:`text-xs`,children:(0,Q.jsx)(U,{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)(Ft,{variant:`outline`,className:`shrink-0 capitalize`,children:t.role}),(0,Q.jsx)(Ft,{variant:zl(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:()=>v(t),"aria-label":`Copy invitation link`,children:m===t.id?(0,Q.jsx)(q,{className:`h-4 w-4 text-green-600`}):(0,Q.jsx)(Ht,{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)(Ge,{className:`h-4 w-4`})})]})]},t.id))}),(0,Q.jsx)($t,{open:!!f,onOpenChange:e=>!e&&p(null),children:(0,Q.jsxs)(sn,{children:[(0,Q.jsxs)($n,{children:[(0,Q.jsx)(cr,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,Q.jsx)(nn,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:f?.email??``})})]}),(0,Q.jsxs)(Mt,{children:[(0,Q.jsx)(On,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsx)(zn,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:y,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function Vl(){let{t:e}=F(),{org:t}=Nl(),{user:n,getMembers:r,updateOrganization:i,deleteOrganization:o,leaveOrganization:s}=_(),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,y]=(0,$.useState)(!1),b=(0,$.useRef)(null),{upload:x}=er(),[S,C]=(0,$.useState)(null),[w,T]=(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 T(!0),r(t.id).then(t=>{if(e)return;let r=t.find(e=>e.userId===n?.id);C(r?.role===`owner`)}).catch(()=>{e||C(!1)}).finally(()=>{e||T(!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 w?(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)(be,{className:`my-4`}),S?(0,Q.jsxs)(`form`,{onSubmit:P,className:`space-y-4 max-w-md`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-2`,children:[(0,Q.jsx)(Gt,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,Q.jsx)(Jn,{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)(Gt,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,Q.jsx)(Jn,{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)(Gt,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsxs)(In,{className:`size-16 rounded-md`,children:[p?(0,Q.jsx)(Vt,{src:p,alt:l,className:`object-cover`}):null,(0,Q.jsx)(Yn,{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:b,type:`file`,accept:`image/*`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(b.current&&(b.current.value=``),n){y(!0);try{let t=await x(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{y(!1)}}},"data-testid":`settings-logo-file`}),(0,Q.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:v,onClick:()=>b.current?.click(),"data-testid":`settings-logo-upload-btn`,children:[v?(0,Q.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}):(0,Q.jsx)(z,{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)(Ge,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,Q.jsx)(Jn,{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)(be,{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)(be,{}),(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.deleteTitle`,{defaultValue:`Delete organization`})}),(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.deleteDescription`,{defaultValue:`Permanently delete this organization and all its data.`})})]}),(0,Q.jsx)(J,{variant:`destructive`,size:`sm`,onClick:()=>{j(``),k(!0)},disabled:!S,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,Q.jsx)($t,{open:E,onOpenChange:D,children:(0,Q.jsxs)(sn,{children:[(0,Q.jsxs)($n,{children:[(0,Q.jsx)(cr,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,Q.jsx)(nn,{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)(Mt,{children:[(0,Q.jsx)(On,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(zn,{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)($t,{open:O,onOpenChange:e=>{k(e),e||j(``)},children:(0,Q.jsxs)(sn,{children:[(0,Q.jsxs)($n,{children:[(0,Q.jsx)(cr,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,Q.jsx)(nn,{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)(Gt,{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)(Jn,{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)(Mt,{children:[(0,Q.jsx)(On,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,Q.jsxs)(zn,{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 Hl(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 Ul(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString()}var Wl=[`today`,`yesterday`,`previous7Days`,`previous30Days`,`older`],Gl={today:`Today`,yesterday:`Yesterday`,previous7Days:`Previous 7 days`,previous30Days:`Previous 30 days`,older:`Older`};function Kl(e,t=Date.now()){let n=new Date(t);n.setHours(0,0,0,0);let r=n.getTime(),i=1440*60*1e3,a=e=>{let t=new Date(e.updatedAt??e.createdAt??0).getTime();return Number.isNaN(t)?0:t},o={today:[],yesterday:[],previous7Days:[],previous30Days:[],older:[]};for(let t of[...e].sort((e,t)=>a(t)-a(e))){let e=a(t);e>=r?o.today.push(t):e>=r-i?o.yesterday.push(t):e>=r-7*i?o.previous7Days.push(t):e>=r-30*i?o.previous30Days.push(t):o.older.push(t)}return Wl.filter(e=>o[e].length>0).map(e=>({key:e,items:o[e]}))}function ql({userId:e,apiBase:t,activeAgent:n,className:r,refreshKey:i,titleHints:o,onNavigate:s}){let{t:c}=F(),u=a(),{conversationId:d}=l(),{conversations:f,isLoading:p,error:m,remove:h,rename:g}=Lr({userId:e,apiBase:t,refreshKey:i}),[_,v]=(0,$.useState)(``),[y,b]=(0,$.useState)(void 0),x=n?si(n):void 0,S=(0,$.useMemo)(()=>n?new Set(ci(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?si(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:yn(`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)(Ct,{className:`h-3.5 w-3.5`}),c(`console.ai.newChat`)]})]}),(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(We,{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)(Jn,{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)(Ot,{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)(ht,{className:`px-3 py-8`,children:[(0,Q.jsx)(He,{className:`h-8 w-8 text-muted-foreground`}),(0,Q.jsx)(ke,{children:c(`console.ai.noChatsYet`)}),(0,Q.jsx)(W,{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:Kl(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:Gl[e.key]})}),(0,Q.jsx)(`ul`,{className:`flex flex-col`,children:e.items.map(e=>(0,Q.jsx)(Yl,{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 Jl(e,t){if(!e)return e??null;let n=t?.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase(),i=[],a=0,o=0;for(;;){let t=r.indexOf(n,a);if(t===-1){i.push(e.slice(a));break}t>a&&i.push(e.slice(a,t)),i.push((0,Q.jsx)(`mark`,{className:`rounded-[2px] bg-primary/20 px-0.5 text-foreground`,children:e.slice(t,t+n.length)},o++)),a=t+n.length}return i}function Yl({conversation:e,query:t,active:n,renaming:r,onSelect:i,onDelete:a,onStartRename:o,onCancelRename:s,onSubmitRename:c}){let{t:l}=F(),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:yn(`flex w-full items-center gap-1 border-l-2 px-3 py-2`,n?`border-primary bg-accent`:`border-transparent`),"data-testid":`ai-conversation-rename-row-${e.id}`,children:[(0,Q.jsx)(Jn,{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)(q,{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)(Ge,{className:`h-3.5 w-3.5`})})]})}):(0,Q.jsx)(`li`,{children:(0,Q.jsxs)(`div`,{className:yn(`group flex w-full items-start gap-2 border-l-2 border-transparent px-3 py-2 text-sm transition-colors hover:bg-accent/50`,n&&`border-primary bg-accent`),"data-testid":`ai-conversation-row-${e.id}`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:i,className:`min-w-0 flex-1 text-left`,"data-testid":`ai-conversation-select-${e.id}`,children:[(0,Q.jsx)(`span`,{className:`line-clamp-1 font-medium`,children:Jl(u,t)}),e.preview&&e.preview!==u?(0,Q.jsx)(`span`,{className:`mt-0.5 block line-clamp-1 text-xs text-muted-foreground`,children:Jl(e.preview,t)}):null,(0,Q.jsx)(`span`,{className:`mt-0.5 block text-[10px] text-muted-foreground`,title:Ul(e.updatedAt??e.createdAt),children:Hl(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)(An,{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)(Wn,{className:`h-3.5 w-3.5`})})]})]})})}function Xl(){return typeof window>`u`?``:window.location.pathname.startsWith(`/_console`)?`/_console`:``}function Zl(e,t){let n=`${Xl()}/apps/${encodeURIComponent(e)}`;return t?n:`${n}?preview=draft`}function Ql({appName:e,appSegment:t,materialized:n=!1,refreshKey:r,onClose:i}){let{t:a}=F(),o=(0,$.useRef)(null),s=t&&t.length?t:e;return(0,$.useEffect)(()=>{if(!o.current)return;let e=Zl(s,n);try{o.current.getAttribute(`src`)!==e&&o.current.setAttribute(`src`,e)}catch{}},[s,n]),(0,$.useEffect)(()=>{if(r>0)try{o.current?.contentWindow?.location.reload()}catch{}},[r]),(0,Q.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col border-l`,"data-testid":`live-canvas`,children:[(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b bg-muted/30 px-3 py-1.5 text-xs text-muted-foreground`,children:[(0,Q.jsx)(Ne,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n?a(`console.ai.liveCanvasUnlisted`,{app:e,defaultValue:`Live app — {{app}} (unlisted until published)`}):a(`console.ai.liveCanvas`,{app:e,defaultValue:`Live preview — {{app}} (draft)`})}),(0,Q.jsx)(J,{size:`sm`,variant:`ghost`,onClick:i,"data-testid":`live-canvas-close`,children:(0,Q.jsx)(Ge,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`iframe`,{ref:o,title:`Draft preview: ${e}`,src:Zl(s,n),className:`h-full w-full flex-1 border-0 bg-background`,"data-testid":`live-canvas-frame`})]})}async function $l(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 eu({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),$l(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)(B,{open:n,onOpenChange:r,children:(0,Q.jsxs)(mt,{side:`right`,className:`w-full overflow-y-auto sm:max-w-xl`,children:[(0,Q.jsxs)(ct,{children:[(0,Q.jsxs)(yt,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(jn,{className:`h-4 w-4`}),` Build Doctor`]}),(0,Q.jsx)(we,{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)(hn,{className:`h-4 w-4`}):(0,Q.jsx)(_t,{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)(tu,{icon:(0,Q.jsx)(at,{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)(tu,{icon:(0,Q.jsx)(_t,{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)(tu,{icon:(0,Q.jsx)(nt,{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)(nu,{entry:e},t))})]})]})]})]})})}function tu({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 nu({entry:e}){return e.kind===`user`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 👤 `,e.text]}):e.kind===`assistant-text`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 🤖 `,e.text]}):e.kind===`assistant-calls`?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 🤖 →`,` `,e.calls.map(e=>e.name).join(`, `)]}):(0,Q.jsxs)(`div`,{className:e.isError?`text-destructive`:``,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` ↳ `,e.name,e.status?` (${e.status})`:``]})}var ru=`/api/v1/ai`;function iu(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function au(e){let t=iu(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 ou(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=iu(r,`toolName`)??r.type.slice(5),a=iu(r,`toolCallId`)??`${e.id}-${i}`,o=au(r),s=r.output??r.result,c=fi(s),l=Qr(s);if(t.push({toolCallId:a,toolName:i,...o?{state:o}:{},...s===void 0?{}:{result:s},...c?{draftReview:c}:{},...l?{proposedPlan:l}:{},...r.errorText?{errorText:String(r.errorText)}:{}}),!n){let e=ti(c);e&&(n=e)}}return{id:e.id,role:e.role,content:r,...t.length>0?{toolInvocations:t}:{},...n?{buildProgress:n}:{}}})}function su(e){return e.find(e=>e.role===`user`)?.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``).trim()||void 0}var cu={ask:{key:`console.ai.agentLabels.ask`,defaultValue:`Ask`},build:{key:`console.ai.agentLabels.build`,defaultValue:`Build`}};function lu(e,t,n){let r=t?cu[si(t)]:void 0;return r?e(r.key,{defaultValue:r.defaultValue}):n}function uu(e,t){return ii(t)?{title:e(`console.ai.empty.build.title`,{defaultValue:`Build with AI`}),description:e(`console.ai.empty.build.description`,{defaultValue:`Describe an app or workflow in plain language — I draft the objects, screens and automations, then you review and publish.`})}:ai(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 du(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(/\/$/,``)}${ru}`}var fu=`ai-chats-collapsed`;function pu(){let[e,t]=(0,$.useState)(()=>{try{return localStorage.getItem(fu)===`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(fu,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 mu=`ai-chat-pane-width`,hu=480,gu=360,_u=420,vu=24;function yu(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 bu(e){let t=(0,$.useRef)(null),[n,r]=(0,$.useState)(()=>{try{let e=Number(localStorage.getItem(mu));return Number.isFinite(e)&&e>0?e:hu}catch{return hu}}),[i,a]=(0,$.useState)(!1),o=(0,$.useCallback)(e=>yu(e,{min:gu,previewMin:_u,containerWidth:t.current?.clientWidth??0}),[]),s=(0,$.useCallback)(e=>{try{localStorage.setItem(mu,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`?vu:0;t&&(e.preventDefault(),r(e=>{let n=o(e+t);return s(n),n}))},[o,s]),reset:(0,$.useCallback)(()=>{let e=o(hu);r(e),s(e)},[o,s])}}function xu(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 Su(e){let{chatApi:t,conversationId:n,pendingRef:r,doSend:i}=e,a=!!t;return(0,$.useEffect)(()=>{if(!a||!n)return;let e=r.current;e&&(r.current=null,i(e.content,e.files))},[a,n,r,i]),(0,$.useCallback)((e,t)=>{if(a&&!n){r.current={content:e,files:t};return}i(e,t)},[a,n,r,i])}function Cu({apiBase:e,defaultAgent:t}={}){let{user:n}=_(),{t:r}=F(),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=a(),{setContext:h}=Ri();(0,$.useEffect)(()=>{h(`home`)},[h]);let g=(0,$.useMemo)(()=>du(e),[e]),v={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_AI_DEFAULT_AGENT,{agents:y,isLoading:b,error:x,refetch:S}=ri({apiBase:g}),C=(0,$.useMemo)(()=>y.map(e=>e.name),[y]),w=!b&&y.length===0,T=(0,$.useMemo)(()=>{if(!o)return!1;if(y.length!==0)return di(o,C)!==void 0},[o,y.length,C]),E=o?void 0:u.get(`agent`)??void 0,D=(0,$.useMemo)(()=>ni(y,E??t??v),[y,E,t,v]),O=(0,$.useMemo)(()=>{if(y.length!==0)return o&&T?di(o,C):D},[y.length,o,T,C,D]),k=O?si(O):void 0,A=!!(o&&T===!1&&$r(o)),j=o&&T===!1&&!A?o:void 0,M=O?`${g}/agents/${encodeURIComponent(O)}/chat`:void 0,{conversationId:N,conversationScope:P,initialMessages:I}=Or({userId:O?i:void 0,scope:O,apiBase:g,activeId:c??j,forceNew:f});(0,$.useEffect)(()=>{if(y.length===0||!O)return;let e=si(O),t=new URLSearchParams(d);t.delete(`agent`);let n=t.toString()?`?${t.toString()}`:``;if(!o){m(`/ai/${e}${n}`,{replace:!0});return}if(A){m(`/ai/${e}${n}`,{replace:!0});return}if(T&&o!==e){let t=c?`/${encodeURIComponent(c)}`:``;m(`/ai/${e}${t}${n}`,{replace:!0})}},[y.length,O,o,T,A,c,d,m]),(0,$.useEffect)(()=>{if(j===void 0)return;let e=!1;return(async()=>{let t;try{t=(await Dr(g,j))?.agentId??void 0}catch{}if(e)return;let n=si(di(t??``,C)??O??`ask`);m(`/ai/${n}/${encodeURIComponent(j)}`,{replace:!0})})(),()=>{e=!0}},[j,g,C,O,m]);let[ee,te]=(0,$.useState)(0),[L,ne]=(0,$.useState)({}),[re,ie]=(0,$.useState)(!1),[ae,oe]=(0,$.useState)(!1),[se,R]=(0,$.useState)(!1),{collapsed:ce,toggle:z,handleCanvasOpenChange:le}=pu();(0,$.useEffect)(()=>{let e=e=>{let t=xu(e);t&&(e.preventDefault(),t===`toggle-list`?z():m(k?`/ai/${k}?new=1`:`/ai?new=1`))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[z,m,k]);let V=(0,$.useMemo)(()=>g.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[g]),ue=(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`},[]),de=(0,$.useRef)(null);f?de.current===null&&(de.current={id:N}):de.current=null,(0,$.useEffect)(()=>{!T||c||!N||!k||de.current&&de.current.id===N||P===O&&m(`/ai/${k}/${N}`,{replace:!0})},[T,c,N,P,O,k,m]);let fe=(0,$.useRef)(new Set);(0,$.useEffect)(()=>{N&&I.length>0&&fe.current.add(N)},[N,I.length]),(0,$.useEffect)(()=>{if(!N)return;let e=su(I);e&&ne(t=>t[N]===e?t:{...t,[N]:e})},[N,I]);let pe=(0,$.useRef)(null),me=(0,$.useCallback)(e=>{if(te(e=>e+1),e&&N&&ne(t=>({...t,[N]:e})),!e||!N||fe.current.has(N))return;fe.current.add(N);let t=()=>te(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[N]);return(0,Q.jsxs)(`div`,{className:`flex h-svh w-full flex-col bg-background`,"data-testid":`ai-chat-page`,children:[(0,Q.jsxs)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background/95 px-2 backdrop-blur sm:px-4`,children:[!w&&(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 md:hidden`,onClick:()=>R(!0),"aria-label":r(`console.ai.openChats`),"data-testid":`ai-chat-mobile-sidebar-trigger`,children:(0,Q.jsx)(xn,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(Ps,{variant:`home`})})]}),w?(0,Q.jsx)(wu,{hasError:!!x,onRetry:S,onHome:()=>m(`/home`),t:r}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(B,{open:se,onOpenChange:R,children:(0,Q.jsxs)(mt,{side:`left`,className:`w-[320px] p-0 sm:max-w-[360px]`,"data-testid":`ai-chat-mobile-sidebar`,children:[(0,Q.jsxs)(ct,{className:`sr-only`,children:[(0,Q.jsx)(yt,{children:r(`console.ai.chats`)}),(0,Q.jsx)(we,{children:r(`console.ai.chatsDescription`)})]}),(0,Q.jsx)(ql,{userId:i,apiBase:g,activeAgent:O,refreshKey:ee,titleHints:L,className:`h-full border-r-0`,onNavigate:()=>R(!1)})]})}),N&&(0,Q.jsx)(_n,{open:re,onOpenChange:ie,objectName:`ai_conversations`,recordId:N,recordLabel:`this conversation`,apiBase:V,publicBaseUrl:ue}),N&&ii(O)&&(0,Q.jsx)(eu,{apiBase:g,conversationId:N,open:ae,onOpenChange:oe}),(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:[!ce&&(0,Q.jsx)(ql,{userId:i,apiBase:g,activeAgent:O,refreshKey:ee,titleHints:L,className:`w-72 min-h-0 flex-1 border-r-0`}),(0,Q.jsx)(`div`,{className:yn(`mt-auto p-2`,ce?`w-12`:`w-72 border-t`),children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:z,"aria-label":ce?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),title:ce?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),"data-testid":`ai-chat-collapse-sidebar-trigger`,"aria-pressed":ce,children:ce?(0,Q.jsx)(Wt,{className:`h-4 w-4`}):(0,Q.jsx)(Yt,{className:`h-4 w-4`})})})]}),(0,Q.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:(0,Q.jsx)(Tu,{agents:y,agentsLoading:b,agentsError:x,activeAgent:O,chatApi:M,apiBase:g,conversationId:N,editPackageId:p,initialMessages:I,pendingFirstMessageRef:pe,onSent:me,onShare:()=>ie(!0),onDebug:()=>oe(!0),showDebug:ii(O),onCanvasOpenChange:le},`${M??`local`}:${N??`pending`}`)})]})]})]})}function wu({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)(ht,{children:[(0,Q.jsx)(ke,{children:r(`console.ai.unavailableTitle`,{defaultValue:`AI assistant unavailable`})}),(0,Q.jsx)(W,{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 Tu({agents:e,agentsLoading:t,agentsError:n,activeAgent:r,chatApi:i,apiBase:o,conversationId:s,editPackageId:c,initialMessages:l,pendingFirstMessageRef:u,onSent:d,onShare:f,onDebug:p,showDebug:m,onCanvasOpenChange:h}){let{t:g}=F(),_=a(),v=e.length>1,[y,b]=(0,$.useState)(null),[x,S]=(0,$.useState)(0),C=(0,$.useRef)(null);(0,$.useEffect)(()=>()=>{C.current&&window.clearTimeout(C.current)},[]);let w=y!==null;(0,$.useEffect)(()=>{h?.(w)},[w,h]);let T=bu(w),E=(0,$.useCallback)((e,t)=>{let n=e.find(e=>e.type===`app`);n&&b(e=>e??{name:n.name,segment:t,materialized:!1}),C.current&&window.clearTimeout(C.current),C.current=window.setTimeout(()=>S(e=>e+1),800)},[]),D=(0,$.useCallback)(e=>{b(t=>t&&t.name===e&&!t.materialized?{...t,materialized:!0}:t??{name:e,materialized:!0})},[]);(0,$.useEffect)(()=>{b(null)},[s]);let O=(0,$.useMemo)(()=>{let t=e.find(e=>e.name===r);return lu(g,r,t?.label??r??g(`console.ai.assistant`))},[e,r,g]),k=(0,$.useMemo)(()=>ou(l),[l]),A=(0,$.useMemo)(()=>{if(!(k.length>0))return ku(r,O,g)},[k.length,r,O,g]),j=(0,$.useMemo)(()=>uu(g,r),[g,r]),{errorSuppressed:M,handleChatError:N,setMessagesRef:P,resetSuppression:I}=Rr({chatApi:i,conversationId:s}),{models:ee,defaultModelId:te}=ui({apiBase:o}),[L,ne]=(0,$.useState)(void 0),re=L??te,{messages:ie,isLoading:ae,error:oe,sendMessage:se,stop:R,reload:ce,clear:z,setMessages:le}=pi({api:i,conversationId:s,model:re,onError:N,body:{context:{activeApp:`AI`,agentName:r,autoPublishAiBuilds:ra().features.autoPublishAiBuilds,...c?{packageId:c}:{}}},initialMessages:k,autoResponse:!i,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600});(0,$.useEffect)(()=>{P.current=le},[le]),(0,$.useEffect)(()=>{Mr(s,Fr(ie))},[s,ie]);let B=(0,$.useRef)(!1);(0,$.useEffect)(()=>{B.current&&!ae&&y&&S(e=>e+1),B.current=ae},[ae,y]);let V=li({messages:ie,apiBase:o,continueConversation:e=>{se(e)}}),ue=Su({chatApi:i,conversationId:s,pendingRef:u,doSend:(0,$.useCallback)((e,t)=>{I(),se(e,t),d(e)},[I,se,d])}),de=(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border/50 px-4 pb-2 pt-3 sm:px-6`,children:[(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:v?e.length<=3?(0,Q.jsx)(Ut,{value:r,onValueChange:e=>_(`/ai/${si(e)}`),children:(0,Q.jsx)(Zn,{className:`h-7 gap-0.5 p-0.5`,"data-testid":`ai-chat-agent-picker`,"aria-label":g(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:e.map(e=>(0,Q.jsx)(Jt,{value:e.name,disabled:t,title:e.description||void 0,className:`h-6 px-2.5 text-xs`,children:lu(g,e.name,e.label)},e.name))})}):(0,Q.jsxs)(Pe,{value:r,onValueChange:e=>_(`/ai/${si(e)}`),disabled:t,children:[(0,Q.jsx)(Tt,{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":g(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:(0,Q.jsx)(xt,{placeholder:g(`console.ai.chooseAgent`,{defaultValue:`Choose assistant…`})})}),(0,Q.jsx)(Kn,{align:`start`,children:e.map(e=>(0,Q.jsxs)(G,{value:e.name,className:`text-xs`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:lu(g,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:O})}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[m&&p?(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:p,disabled:!s,"aria-label":`Build Doctor`,"data-testid":`ai-chat-debug-button`,title:s?`Build Doctor — what actually landed?`:`Send a message first`,children:(0,Q.jsx)(jn,{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:f,disabled:!s,"aria-label":g(`console.ai.share`),"data-testid":`ai-chat-share-button`,title:g(s?`console.ai.shareTitle`:`console.ai.shareDisabledTitle`),children:(0,Q.jsx)(tr,{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:g(`console.ai.offlineDemoMode`)}):null]});return(0,Q.jsxs)(`div`,{ref:T.containerRef,className:`relative flex min-h-0 flex-1 px-0`,children:[(0,Q.jsx)(`div`,{"data-chat-column":!0,className:y?`flex min-h-0 shrink-0 justify-center`:`flex min-h-0 flex-1 justify-center`,style:y?{width:T.width}:void 0,children:(0,Q.jsx)(oi,{className:`min-h-0 flex-1 bg-background md:max-w-5xl`,onUpgrade:()=>window.open(ta(),`_blank`,`noopener,noreferrer`),surface:`plain`,maxHeight:`100%`,headerSlot:de,messages:ie,placeholder:r?si(r)===`ask`?g(`console.ai.askAnything`):g(`console.ai.askAgent`,{agent:O}):g(t?`console.ai.loadingAgents`:`console.ai.askAnything`),labels:{emptyTitle:j.title,emptyDescription:j.description,clear:g(`console.ai.clearConversation`),sendHint:g(`console.ai.sendHint`),agentActivity:g(`console.ai.agentActivity`),toolCompleted:g(`console.ai.toolCompleted`),toolRunning:g(`console.ai.toolRunning`),toolAwaitingApproval:g(`console.ai.toolAwaitingApproval`),toolFailed:g(`console.ai.toolFailed`),connectionWaiting:g(`console.ai.connectionWaiting`,{defaultValue:`Waiting for server…`}),connectionStalledLabel:g(`console.ai.connectionStalled`,{defaultValue:`Still working…`}),connectionOfflineLabel:g(`console.ai.connectionOffline`,{defaultValue:`Connection lost — reconnecting…`}),designingPlanLabel:g(`console.ai.designingPlan`,{defaultValue:`Designing your app…`}),designingPlanHints:[g(`console.ai.designingPlanHint.data`,{defaultValue:`Mapping out the data you’ll track…`}),g(`console.ai.designingPlanHint.objects`,{defaultValue:`Shaping objects and their fields…`}),g(`console.ai.designingPlanHint.relations`,{defaultValue:`Connecting related records…`}),g(`console.ai.designingPlanHint.lookups`,{defaultValue:`Setting up relationships and lookups…`}),g(`console.ai.designingPlanHint.views`,{defaultValue:`Planning the screens and views…`}),g(`console.ai.designingPlanHint.forms`,{defaultValue:`Laying out forms and lists…`}),g(`console.ai.designingPlanHint.defaults`,{defaultValue:`Adding sensible defaults and validations…`}),g(`console.ai.designingPlanHint.dashboard`,{defaultValue:`Sketching a dashboard to track it…`}),g(`console.ai.designingPlanHint.review`,{defaultValue:`Double-checking the structure hangs together…`}),g(`console.ai.designingPlanHint.finalize`,{defaultValue:`Pulling the plan together…`})],toolDetailsHidden:g(`console.ai.toolDetailsHidden`),copy:g(`console.ai.copy`),copied:g(`console.ai.copied`),regenerate:g(`console.ai.regenerate`),model:g(`console.ai.model`),submit:g(`console.ai.submit`),uploadFiles:g(`console.ai.uploadFiles`),stopResponse:g(`console.ai.stopResponse`),sendFailedRateLimited:g(`console.ai.sendFailedRateLimited`,{defaultValue:`You're sending messages too quickly. Your message is kept below — wait a moment and try again.`}),sendFailedGeneric:g(`console.ai.sendFailedGeneric`,{defaultValue:`Couldn't send your message. It's kept below — please try again.`}),trace:g(`console.ai.trace`),viewTrace:g(`console.ai.viewTrace`)},models:ee,selectedModelId:re,onModelChange:ne,suggestions:A,onSendMessage:ue,onClear:z,hideClearBar:!0,onStop:ae?R:void 0,onReload:ce,isLoading:ae,error:M?void 0:oe,enableMarkdown:!0,onToolApprove:V.decide,toolDecisions:V.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onOpenBuiltApp:(e,t)=>_(`/apps/${encodeURIComponent(t??e)}`),openBuiltAppLabel:g(`console.ai.openBuiltApp`,{defaultValue:`Open app`}),fetchPendingDraftCount:Pr,onPublishDrafts:async e=>{try{let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);let r=n?.data?.failedCount??n?.failedCount??0;if(r)throw Error(String(r));let i=n?.data?.seedApplied??n?.seedApplied;return i&&i.success===!1?X.warning(g(`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(g(`console.ai.publishOk`,{defaultValue:`Published — objects are now live.`})),Sr(),{ok:!0,health:ei(n)}}catch(e){return X.error(g(`console.ai.publishFailed`,{defaultValue:`Publish failed`}),{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:g(`console.ai.publishDrafts`,{defaultValue:`Publish`}),publishedLabel:g(`console.ai.published`,{defaultValue:`Published`}),nextStepsLabel:g(`console.ai.nextSteps`,{defaultValue:`What's next`}),planTitleLabel:g(`console.ai.planTitle`,{defaultValue:`Proposed plan`}),planQuestionsLabel:g(`console.ai.planQuestions`,{defaultValue:`Confirm before building`}),planAssumptionsLabel:g(`console.ai.planAssumptions`,{defaultValue:`Assumptions`}),planDeferredLabel:g(`console.ai.planDeferred`,{defaultValue:`Not yet built`}),planApproveHintLabel:g(`console.ai.planApproveHint`,{defaultValue:`Reply to approve or adjust this plan.`}),planApproveLabel:g(`console.ai.planApprove`,{defaultValue:`Build it`}),planAdjustLabel:g(`console.ai.planAdjust`,{defaultValue:`Adjust`}),planBuiltLabel:g(`console.ai.planBuilt`,{defaultValue:`Built`}),planReadyLabel:g(`console.ai.planReady`,{defaultValue:`The plan is ready. Build it now, or tell me what to adjust.`}),planApproveMessage:g(`console.ai.planApproveMessage`,{defaultValue:`Looks good — build it as proposed.`}),planApproveDefaultsMessage:g(`console.ai.planApproveDefaultsMessage`,{defaultValue:`Build it with your best assumptions; use sensible defaults for the open questions.`}),planAnswerMessage:(e,t)=>g(`console.ai.planAnswerMessage`,{question:e,option:t,defaultValue:`For "{{question}}", go with: {{option}}.`}),autoPublishDrafts:ra().features.autoPublishAiBuilds,onDraftArtifacts:E,onPreviewDraftApp:(e,t)=>b({name:e,segment:t?.appSegment,materialized:t?.materialized===!0}),onBuildMaterialized:D,previewDraftLabel:g(`console.ai.previewDraft`,{defaultValue:`Preview`}),"data-testid":`ai-chat-panel`})}),y?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":g(`console.ai.resizeSplit`,{defaultValue:`Resize chat and preview`}),tabIndex:0,onPointerDown:T.onHandlePointerDown,onKeyDown:T.onHandleKeyDown,onDoubleClick:T.reset,"data-testid":`ai-chat-split-handle`,className:yn(`group relative hidden w-1.5 shrink-0 cursor-col-resize touch-none select-none md:block`,`focus:outline-none`),children:[(0,Q.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 -left-1.5 -right-1.5`}),(0,Q.jsx)(`span`,{"aria-hidden":!0,className:yn(`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border transition-colors`,`group-hover:bg-primary/60 group-focus-visible:bg-primary`,T.dragging&&`bg-primary`)})]}),(0,Q.jsx)(Ql,{appName:y.name,appSegment:y.segment,materialized:y.materialized,refreshKey:x,onClose:()=>b(null)}),T.dragging?(0,Q.jsx)(`div`,{className:`fixed inset-0 z-50 cursor-col-resize`,"data-testid":`ai-chat-split-overlay`}):null]}):null]})}function Eu(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 Du(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 Ou(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 ku(e,t,n){if(ai(e))return Eu(n);if(ii(e))return Du(n);let r=(e??t).toLowerCase();return r.includes(`data`)?Eu(n):r.includes(`metadata`)?Du(n):Ou(n)}function Au(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function ju(e){return!Au(e)||e.viewKind?!1:!!(e.list||e.form||e.listViews||e.formViews)}function Mu(e){if(!Au(e))return;let t=e.config;if(Au(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`}uo({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:vi}),uo({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:_i}),uo({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:Ii}),Si({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`}]}),Si({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`}]}),Si({type:`permission`,label:`Permission sets`,description:`Object-level CRUD + VAMA + lifecycle permissions, and field-level R/W. Profiles are permission sets with isProfile=true.`,domain:`security`,EditPage:wi,searchableFields:[`name`,`label`],listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`isProfile`,label:`Type`,width:`15%`,render:e=>e?`Profile`:`Permission set`}]}),Si({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)=>Mu(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!ju(e)}),Si({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`}]}),Si({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`}]}),Si({type:`book`,label:`Documentation Books`,description:`Documentation navigation spine — ordered groups with membership derived over docs (glob/tag rules), plus an explicit pages override for curated order.`,domain:`system`,searchableFields:[`name`,`label`,`description`,`slug`],listColumns:[{key:`name`,label:`Name`,width:`25%`},{key:`label`,label:`Label`,width:`25%`},{key:`audience`,label:`Audience`,width:`12%`,render:e=>e==null?`org`:typeof e==`object`&&e&&`profile`in e?`profile: ${e.profile}`:String(e)},{key:`groups`,label:`Groups`,width:`10%`,render:e=>Array.isArray(e)?String(e.length):`0`},{key:`description`,label:`Description`}]});var Nu=`/api/v1/cloud-connection`;async function Pu(e,t){let n=await fetch(e,{credentials:`same-origin`,headers:{"Content-Type":`application/json`},...t}),r=await n.json().catch(()=>({}));if(!n.ok&&r?.success!==!0){let e=r?.error?.message??r?.error?.code??r?.error??`HTTP ${n.status}`;throw Error(typeof e==`string`?e:JSON.stringify(e))}return r}function Fu(){let[e,t]=(0,$.useState)({kind:`loading`}),[n,r]=(0,$.useState)(!1),[i,a]=(0,$.useState)(!1),o=(0,$.useRef)(null),s=(0,$.useCallback)(()=>{o.current&&=(clearTimeout(o.current),null)},[]),c=(0,$.useCallback)(async()=>{try{let e=(await Pu(`${Nu}/status`))?.data??{environmentId:null,bound:!1,connection:null};t(e.bound?{kind:`bound`,status:e}:{kind:`unbound`})}catch(e){t({kind:`error`,message:e?.message??String(e)})}},[]);(0,$.useEffect)(()=>(c(),s),[c,s]);let l=(0,$.useCallback)((e,n)=>{let r=Math.max(e.interval,2)*1e3,i=async()=>{if(Date.now()-n>e.expires_in*1e3){t({kind:`error`,message:`The request expired before it was approved. Start again.`});return}try{let n=await Pu(`${Nu}/bind/poll`,{method:`POST`,body:JSON.stringify({device_code:e.device_code})});if(n?.data?.pending){o.current=setTimeout(i,r);return}if(n?.data?.bound||n?.success){await c();return}t({kind:`error`,message:n?.error?.code??`Binding failed.`})}catch(e){t({kind:`error`,message:e?.message??String(e)})}};o.current=setTimeout(i,r)},[c]),u=(0,$.useCallback)(async()=>{r(!0);try{let e=(await Pu(`${Nu}/bind/start`,{method:`POST`,body:`{}`}))?.data;if(!e?.device_code||!e?.user_code)throw Error(`Device code request failed.`);let n=e.verification_uri_complete??e.verification_uri,r=!1;if(n)try{r=!!window.open(n,`_blank`,`noopener,width=520,height=720`)}catch{}t({kind:`waiting`,code:e,popupOpened:r}),l(e,Date.now())}catch(e){t({kind:`error`,message:e?.message??String(e)})}finally{r(!1)}},[l]),d=(0,$.useCallback)(async()=>{r(!0);try{await Pu(`${Nu}/unbind`,{method:`POST`,body:`{}`}),await c()}catch(e){t({kind:`error`,message:e?.message??String(e)})}finally{r(!1)}},[c]),f=(0,$.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),a(!0),setTimeout(()=>a(!1),1500)}catch{}},[]);if(e.kind===`loading`)return(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border p-6 text-sm text-muted-foreground`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),` Checking connection…`]});if(e.kind===`error`)return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-destructive/40 bg-destructive/5 p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-destructive`,children:[(0,Q.jsx)(Ye,{className:`h-4 w-4`,"aria-hidden":`true`}),` `,e.message]}),(0,Q.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{s(),c()},children:`Try again`})]});if(e.kind===`waiting`){let t=e.code.verification_uri_complete??e.code.verification_uri;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),e.popupOpened?`Approve the connection in the window that just opened — this page updates by itself.`:`Waiting for approval in the cloud console…`]}),!e.popupOpened&&t?(0,Q.jsxs)(`a`,{className:`inline-flex items-center gap-1.5 self-start rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90`,href:t,target:`_blank`,rel:`noreferrer`,children:[`Open the approval page `,(0,Q.jsx)(je,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})]}):null,(0,Q.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Q.jsx)(`code`,{className:`rounded-md bg-muted px-4 py-2 text-2xl font-semibold tracking-[0.25em]`,children:e.code.user_code}),(0,Q.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>void f(e.code.user_code),children:[(0,Q.jsx)(Ht,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` `,i?`Copied`:`Copy`]})]}),(0,Q.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`The code is pre-filled on the approval page`,e.popupOpened&&t?(0,Q.jsxs)(Q.Fragment,{children:[` `,`— if the window did not appear,`,` `,(0,Q.jsxs)(`a`,{className:`inline-flex items-center gap-1 text-primary underline-offset-2 hover:underline`,href:t,target:`_blank`,rel:`noreferrer`,children:[`open it here `,(0,Q.jsx)(je,{className:`h-3 w-3`,"aria-hidden":`true`})]}),`.`]}):`.`]}),(0,Q.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{s(),c()},children:`Cancel`})]})}if(e.kind===`bound`){let t=e.status.connection??{},r=t.runtime_id??e.status.runtimeId;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(hn,{className:`h-5 w-5 text-emerald-600`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:`Connected to ObjectStack Cloud`})]}),(0,Q.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-6 gap-y-1.5 text-sm`,children:[t.name?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Runtime`}),(0,Q.jsx)(`dd`,{children:t.name})]}):null,t.organization_id?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Organization`}),(0,Q.jsx)(`dd`,{className:`font-mono`,children:t.organization_id})]}):null,t.account_email?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Approved by`}),(0,Q.jsx)(`dd`,{children:t.account_email})]}):null,r?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Runtime ID`}),(0,Q.jsx)(`dd`,{className:`font-mono text-xs`,children:r})]}):null,e.status.environmentId?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Environment`}),(0,Q.jsx)(`dd`,{className:`font-mono`,children:e.status.environmentId})]}):null,t.bound_at?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`dt`,{className:`text-muted-foreground`,children:`Since`}),(0,Q.jsx)(`dd`,{children:new Date(t.bound_at).toLocaleString()})]}):null]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Your organization's private packages now appear in the Marketplace under “Your organization”.`}),(0,Q.jsxs)(`button`,{type:`button`,disabled:n,className:`inline-flex items-center gap-1.5 self-start rounded-md border border-destructive/40 px-3 py-1.5 text-sm text-destructive hover:bg-destructive/5 disabled:opacity-50`,onClick:()=>void d(),children:[(0,Q.jsx)(pt,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` Disconnect`]})]})}return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(cn,{className:`h-5 w-5 text-muted-foreground`,"aria-hidden":`true`}),(0,Q.jsx)(`span`,{className:`font-medium`,children:`Not connected`})]}),(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Connect this runtime to an ObjectStack control plane to browse your organization's private packages and install them here. Approval is a single click in your cloud account — no ids or credentials are typed into this page.`}),(0,Q.jsxs)(`button`,{type:`button`,disabled:n,className:`inline-flex items-center gap-1.5 self-start rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,onClick:()=>void u(),children:[n?(0,Q.jsx)(Y,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}):(0,Q.jsx)(Bn,{className:`h-4 w-4`,"aria-hidden":`true`}),`Connect`]})]})}C.register(`cloud-connection:panel`,()=>(0,Q.jsx)(Fu,{}),{namespace:`app-shell`,label:`Cloud Connection Panel`,category:`plugin`,inputs:[]});var Iu=`/api/v1/cloud/environments/production/sso-open`,Lu=`/apps/cloud_control/sys_environment`;function Ru(e){return(typeof document<`u`&&document.documentElement.getAttribute(`lang`)||`en`).toLowerCase().startsWith(`zh`)?e.zh:e.en}function zu(e){let{activeOrganization:t}=_(),n=t?.id,r=(0,$.useMemo)(()=>v(),[]),[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 Bu(e){window.location.href=e}function Vu({properties:e}){let t=a(),n=zu(e?.warmUrl),r=e?.openProductionUrl||Iu,i=e?.environmentsRoute||Lu;if(n.phase===`loading`)return(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,"data-onboarding":`loading`,children:[(0,Q.jsx)($e,{className:`h-11 w-44 rounded-md`}),(0,Q.jsx)($e,{className:`h-11 w-44 rounded-md`})]});let o=n.phase===`ready`&&!n.hasProductionEnv?{en:`Spin up your first environment — a private workspace with its own URL, database, and plan. Building happens inside it.`,zh:`创建你的第一个环境——一个独立的工作区,有自己的网址、数据库和套餐。应用的搭建在里面进行。`}:{en:`Your production environment is ready. Open it to build and run your apps — that all happens inside the environment.`,zh:`你的生产环境已就绪。打开它来搭建和运行应用——这些都在环境内部进行。`},s=n.phase===`ready`&&!n.hasProductionEnv;return(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,"data-onboarding":n.phase,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,children:[s?(0,Q.jsxs)(J,{size:`lg`,onClick:()=>t(i),children:[(0,Q.jsx)(Ct,{className:`mr-2 h-4 w-4`}),Ru({en:`Create your environment`,zh:`创建你的环境`})]}):(0,Q.jsxs)(J,{size:`lg`,onClick:()=>Bu(r),children:[(0,Q.jsx)(Ie,{className:`mr-2 h-4 w-4`}),Ru({en:`Open Production`,zh:`打开生产环境`})]}),(0,Q.jsxs)(J,{size:`lg`,variant:`secondary`,onClick:()=>t(i),children:[(0,Q.jsx)(me,{className:`mr-2 h-4 w-4`}),Ru({en:`Manage environments`,zh:`管理环境`})]})]}),(0,Q.jsx)(`p`,{className:`max-w-xl text-center text-sm text-muted-foreground`,children:Ru(o)})]})}C.register(`cloud:onboarding-next`,e=>(0,Q.jsx)(Vu,{...e}),{namespace:`app-shell`,label:`Cloud Onboarding Next-Step`,category:`plugin`,inputs:[]});function Hu({packageId:e,locale:t}){let n=(t??``).toLowerCase().startsWith(`zh`),{user:r}=_(),i=r?.id,a=$.useMemo(()=>du(),[]),[o,s]=$.useState(!1),{agents:c,isLoading:l,error:u}=ri({apiBase:a}),d=$.useMemo(()=>{if(c.length!==0)return c.find(e=>ii(e.name))?.name??ni(c,void 0)},[c]),f=d?`${a}/agents/${encodeURIComponent(d)}/chat`:void 0,{conversationId:p,initialMessages:m}=Or({userId:d?i:void 0,scope:d?`studio:${e}:${d}`:void 0,apiBase:a,activeId:void 0,forceNew:!1}),h=$.useRef(null);return!l&&c.length===0?null:o?(0,Q.jsx)(`aside`,{className:`flex w-10 shrink-0 flex-col items-center gap-2 border-r bg-muted/40 py-2`,children:(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,onClick:()=>s(!1),title:n?`展开 AI 副驾`:`Expand AI copilot`,"aria-label":n?`展开 AI 副驾`:`Expand AI copilot`,children:(0,Q.jsx)(an,{className:`h-4 w-4`})})}):(0,Q.jsxs)(`aside`,{className:`flex w-96 shrink-0 flex-col overflow-hidden border-r bg-muted/30`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,Q.jsx)(an,{className:`h-4 w-4 text-primary`}),n?`AI 副驾`:`AI copilot`]}),(0,Q.jsx)(J,{variant:`ghost`,size:`icon`,onClick:()=>s(!0),title:n?`收起`:`Collapse`,"aria-label":n?`收起 AI 副驾`:`Collapse AI copilot`,children:(0,Q.jsx)(Yt,{className:`h-4 w-4`})})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,Q.jsx)(Tu,{agents:c,agentsLoading:l,agentsError:u,activeAgent:d,chatApi:f,apiBase:a,conversationId:p,editPackageId:e,initialMessages:m,pendingFirstMessageRef:h,onSent:()=>{},onShare:()=>{},showDebug:!1},`${f??`local`}:${p??`pending`}`)})]})}function Uu(e){let t=e?.issues;return Array.isArray(t)?t:[]}function Wu(e){return`• ${e.path&&e.path.length>0?e.path:`(root)`} — ${e.message}`}function Gu(e){let t=Uu(e);return t.length>0?t.map(Wu).join(`
3
+ `):e?.message??String(e)}function Ku(e){return e.map(e=>[`${e.type}/${e.name}: ${e.error}`,...(Array.isArray(e.issues)?e.issues:[]).map(e=>` ${Wu(e)}`)].join(`
4
+ `)).join(`
5
+ `)}async function qu(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 Ju(e,t,n){return{name:e,label:t,fields:{name:{type:`text`,label:n}}}}function Yu(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 Xu(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 Zu(e,t){return{name:e,label:t,objects:{},fields:{}}}function Qu({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=Ta((_.trim()||h).trim()),S=!!h.trim()&&!!x&&x!==`field`,C=()=>{!S||u||m({label:h.trim(),name:x})};return(0,Q.jsx)(st,{open:e,onOpenChange:t,children:(0,Q.jsxs)(gt,{children:[(0,Q.jsxs)(Hn,{children:[(0,Q.jsx)(Ae,{children:n}),r&&(0,Q.jsx)(ye,{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)(Gt,{children:i}),(0,Q.jsx)(Jn,{autoFocus:!0,value:h,onChange:e=>{g(e.target.value),y||v(Ma(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&C()},placeholder:a})]}),(0,Q.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Q.jsx)(Gt,{children:o}),(0,Q.jsx)(Jn,{className:`font-mono`,value:_,onChange:e=>{b(!0),v(Ma(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)(Me,{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 $u=`__ungrouped__`,ed=e=>`g:${e}`,td=e=>`f:${e}`,nd=e=>e.slice(2),rd=e=>e.slice(2);function id({type:e}){let t=La(),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 ad({entry:e,selected:t,onSelect:n}){let r=La(),{attributes:i,listeners:a,setNodeRef:o,transform:s,transition:c,isDragging:l}=ga({id:td(e.name)}),u=String(e.def.type??`text`),d=String(e.def.label??e.name),f=!!e.def.required;return(0,Q.jsxs)(`div`,{ref:o,style:{transform:xa.Transform.toString(s),transition:c},onClick:n,...i,...a,"aria-label":Na(`engine.studio.designer.fieldAria`,r,{label:d}),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 `+(t?`ring-2 ring-primary`:`hover:border-foreground/25`)+(l?` opacity-40`:``),children:[(0,Q.jsx)(`span`,{className:`mt-0.5 text-muted-foreground opacity-0 group-hover:opacity-100`,children:(0,Q.jsx)(tn,{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:d}),f&&(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:u})]}),(0,Q.jsx)(id,{type:u})]})]})}function od({containerId:e,title:t,fieldIds:n,isDeclared:r,canMoveUp:i,canMoveDown:a,entryByName:o,selectedField:s,onSelectField:c,onRename:l,onDelete:u,onMove:d,readOnly:f=!1}){let p=La(),{setNodeRef:m,isOver:h}=fa({id:e});return(0,Q.jsxs)(`div`,{className:`rounded-lg border `+(h?`border-primary bg-primary/5`:`bg-muted/20`),children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-3 py-1.5`,children:[r&&!f?(0,Q.jsx)(`input`,{defaultValue:t,onBlur:e=>e.target.value.trim()&&e.target.value!==t&&l(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}),r&&!f&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`button`,{type:`button`,disabled:!i,onClick:()=>d(-1),"aria-label":Z(`engine.studio.designer.groupUp`,p),className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(ur,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,disabled:!a,onClick:()=>d(1),"aria-label":Z(`engine.studio.designer.groupDown`,p),className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,Q.jsx)(Ce,{className:`h-3.5 w-3.5`})}),(0,Q.jsx)(`button`,{type:`button`,onClick:u,"aria-label":Z(`engine.studio.designer.groupDelete`,p),title:Z(`engine.studio.designer.groupDeleteTitle`,p),className:`rounded p-0.5 text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,children:(0,Q.jsx)(Wn,{className:`h-3.5 w-3.5`})})]})]}),(0,Q.jsx)(va,{items:n,strategy:_a,children:(0,Q.jsxs)(`div`,{ref:m,className:`grid min-h-[52px] grid-cols-2 gap-2 p-2.5`,children:[n.length===0&&(0,Q.jsx)(`div`,{className:`col-span-2 flex items-center justify-center rounded-md border border-dashed py-3 text-[11px] text-muted-foreground`,children:Z(`engine.studio.designer.dropHere`,p)}),n.map(e=>{let t=rd(e),n=o.get(t);return n?(0,Q.jsx)(ad,{entry:n,selected:s===t,onSelect:()=>c(t)},e):null})]})})]})}function sd({draft:e,systemFieldNames:t,onChange:n,selectedField:r,onSelectField:i,onAddField:a,readOnly:o=!1}){let s=La(),c=$.useMemo(()=>Aa(e.fields),[e.fields]),l=$.useMemo(()=>Ca(e.fieldGroups),[e.fieldGroups]),u=$.useMemo(()=>new Map(c.entries.map(e=>[e.name,e])),[c]),d=$.useMemo(()=>[...l.map(e=>ed(e.key)),ed($u)],[l]),f=$.useMemo(()=>{let e=new Map;for(let t of l)e.set(ed(t.key),t.label||t.key);return e.set(ed($u),Z(`engine.studio.designer.ungrouped`,s)),e},[l,s]),p=$.useMemo(()=>{let e={};for(let t of d)e[t]=[];for(let n of c.entries){if(t.has(n.name))continue;let r=typeof n.def.group==`string`?n.def.group:``;e[r&&e[ed(r)]?ed(r):ed($u)].push(td(n.name))}return e},[c.entries,d,t]),[m,h]=$.useState(p),[g,_]=$.useState(null);$.useEffect(()=>{g||h(p)},[p,g]);let v=$.useRef(m);$.useEffect(()=>{v.current=m},[m]);let y=ba(ca(da,{activationConstraint:{distance:4}}),ca(ya,{coordinateGetter:la})),b=$.useCallback(e=>e.startsWith(`g:`)?e:Object.keys(m).find(t=>m[t].includes(e)),[m]),x=$.useCallback(e=>{let r=[];for(let t of d){let n=nd(t);for(let i of e[t]??[]){let e=u.get(rd(i));if(!e)continue;let t={...e.def};n===$u?delete t.group:t.group=n,r.push({name:e.name,def:t})}}let i=c.entries.filter(e=>t.has(e.name));n({fields:ja({shape:c.shape,entries:[...i,...r]})})},[d,u,c,t,n]),S=e=>_(String(e.active.id)),C=e=>{let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=b(t),i=b(n);!r||!i||r===i||h(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)]}})},w=e=>{_(null);let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=v.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){x(r);return}s={...r,[a]:ha(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)]}}h(s),x(s)},T=()=>n({fieldGroups:Da(l,Z(`engine.studio.designer.newGroup`,s))}),E=(e,t)=>n({fieldGroups:Fa(l,e,t)}),D=(e,t)=>n({fieldGroups:wa(l,e,t)}),O=e=>n({fieldGroups:Ea(l,e),fields:ja(Oa(c,e))}),k=g&&!g.startsWith(`g:`)?u.get(rd(g)):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)(Je,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.designer.hint`,s)]}),!o&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:T,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)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.designer.addGroup`,s)]}),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)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.addField`,s)]})]})]}),(0,Q.jsxs)(ua,{sensors:o?[]:y,collisionDetection:pa,onDragStart:S,onDragOver:C,onDragEnd:w,onDragCancel:()=>_(null),children:[(0,Q.jsx)(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-3`,children:d.map(e=>{let t=e===ed($u);if(t&&(m[e]?.length??0)===0&&l.length>0)return null;let n=l.findIndex(t=>ed(t.key)===e);return(0,Q.jsx)(od,{containerId:e,title:f.get(e)??Z(`engine.studio.designer.ungrouped`,s),fieldIds:m[e]??[],isDeclared:!t,canMoveUp:n>0,canMoveDown:n>=0&&n<l.length-1,entryByName:u,selectedField:r,onSelectField:i,onRename:t=>E(nd(e),t),onDelete:()=>O(nd(e)),onMove:t=>D(nd(e),t),readOnly:o},e)})}),(0,Q.jsx)(ma,{children:k?(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)(tn,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:String(k.def.label??k.name)})]}):null})]})]})}function cd(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`):[]}function ld(e){let t=e.length+1,n=`validation_${t}`,r=new Set(e);for(;r.has(n);)n=`validation_${++t}`;return n}function ud({draft:e,onPatch:t,disabled:n}){let r=La(),i=$.useMemo(()=>cd(e.validations),[e.validations]),[a,o]=$.useState(null),s=i.some(e=>e.name===a)?a:i[0]?.name??null,c=$.useMemo(()=>Aa(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]),l=e=>t({validations:e}),u=(e,t)=>l(i.map(n=>n.name===e?{...n,...t}:n)),d=()=>{let e=ld(i.map(e=>e.name??``));l([...i,{type:`script`,name:e,message:``,condition:`false`,severity:`error`}]),o(e)},f=e=>{l(i.filter(t=>t.name!==e)),a===e&&o(null)},p=i.find(e=>e.name===s)??null;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)(de,{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)(`button`,{type:`button`,onClick:d,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)(Ct,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,r)]})]}),(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] `+(s===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 px-1.5 py-0.5 text-[10px] `+(e.type===`script`?`bg-primary/10 text-primary`:`bg-muted text-muted-foreground`),children:e.type??`script`})]},e.name))})]}),(0,Q.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col rounded-lg border`,children:p?p.type===`script`?(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.nameLabel`,r)}),(0,Q.jsx)(`input`,{value:p.name??``,disabled:n,onChange:e=>{let t=e.target.value;u(p.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.messageLabel`,r)}),(0,Q.jsx)(`input`,{value:p.message??``,disabled:n,onChange:e=>u(p.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.jsxs)(`div`,{children:[(0,Q.jsxs)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:[Z(`engine.studio.rules.celPre`,r),(0,Q.jsx)(`b`,{children:Z(`engine.studio.rules.celTrue`,r)}),Z(`engine.studio.rules.celMid`,r),(0,Q.jsx)(`code`,{className:`rounded bg-muted px-1`,children:`false`}),Z(`engine.studio.rules.celPost`,r)]}),(0,Q.jsx)(Pa,{value:typeof p.condition==`string`?p.condition:``,onCommit:e=>u(p.name,{condition:e}),fields:c,disabled:n})]}),(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:p.severity??`error`,disabled:n,onChange:e=>u(p.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)(`input`,{type:`checkbox`,checked:p.active!==!1,disabled:n,onChange:e=>u(p.name,{active:e.target.checked})}),Z(`engine.studio.rules.enabled`,r)]}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>f(p.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)(Wn,{className:`h-3 w-3`}),` `,Z(`engine.studio.rules.delete`,r)]})]})]}):(0,Q.jsxs)(`div`,{className:`flex flex-1 flex-col gap-2 p-4`,children:[(0,Q.jsxs)(`p`,{className:`text-[13px] font-medium`,children:[p.label||p.name,(0,Q.jsx)(`span`,{className:`ml-2 rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:p.type})]}),(0,Q.jsx)(`p`,{className:`text-[12px] leading-5 text-muted-foreground`,children:Na(`engine.studio.rules.structured`,r,{type:String(p.type),message:p.message||Z(`engine.studio.rules.none2`,r)})}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>f(p.name),className:`mt-auto inline-flex w-fit 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)(Wn,{className:`h-3 w-3`}),` `,Z(`engine.studio.rules.deleteRule`,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 dd({name:e,draft:t,onPatch:n,disabled:r,locale:i}){let a=Oi(`object`),o=$.useMemo(()=>Aa(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));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)(me,{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)(an,{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":Na(`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)(Ge,{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)})]})]})]})]})]})}var fd={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 pd(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 md(e){let t=Aa(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]=pd(t.type),Object.keys(r).length>=8))break}return r}function hd({name:e,draft:t}){let n=La(),[r,i]=$.useState(null),a=typeof window<`u`?window.location.origin:`https://your-host`,o=`/api/v1/data/${e}`,s=$.useMemo(()=>md(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(` \\
6
+ `)},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 `+fd[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)(q,{className:`h-3 w-3 text-emerald-500`}):(0,Q.jsx)(Ht,{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 gd(e){if(!e)return``;if(typeof e==`string`)return e;if(typeof e==`object`){let t=e.source;if(typeof t==`string`)return t}return``}function _d(e,t){let n=e.object;return n===`*`?!0:typeof n==`string`?n===t:Array.isArray(n)?n.includes(t)||n.includes(`*`):!1}function vd({objectName:e,packageId:t}){let n=La(),r=Sa(),[i,a]=$.useState([]),[o,s]=$.useState(!0),[c,l]=$.useState(null);return $.useEffect(()=>{let n=!1;return s(!0),l(null),(async()=>{try{let i=await r.list(`hook`,{packageId:t});if(n)return;a((i||[]).filter(t=>_d(t,e)))}catch(e){n||l(Gu(e))}finally{n||s(!1)}})(),()=>{n=!0}},[r,t,e]),(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.hooks.explain`,n)}),c&&(0,Q.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive`,children:c}),o?(0,Q.jsx)(`p`,{className:`px-1 py-6 text-center text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,n)}):i.length===0?(0,Q.jsx)(`p`,{className:`px-3 py-8 text-center text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.hooks.none`,n)}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:i.map(e=>(0,Q.jsxs)(`div`,{className:`rounded-lg border px-3 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(ze,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] font-medium`,children:e.label||e.name}),e.object===`*`&&(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:Z(`engine.studio.hooks.wildcard`,n)}),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`,n)})]}),Array.isArray(e.events)&&e.events.length>0&&(0,Q.jsx)(`div`,{className:`mt-1.5 flex flex-wrap gap-1`,children:e.events.map(e=>(0,Q.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground`,children:e},e))}),gd(e.condition)&&(0,Q.jsxs)(`p`,{className:`mt-1.5 text-[11px] text-muted-foreground`,children:[Z(`engine.studio.hooks.condition`,n),` `,(0,Q.jsx)(`code`,{className:`rounded bg-muted px-1`,children:gd(e.condition)})]}),(0,Q.jsxs)(`p`,{className:`mt-1.5 text-[10px] text-muted-foreground`,children:[Na(`engine.studio.hooks.meta`,n,{priority:e.priority??100}),` · `,Z(`engine.studio.hooks.code`,n)]})]},e.name))})]})}function yd(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`):[]}function bd(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 xd(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 Sd({draft:e,onPatch:t,disabled:n}){let r=La(),i=$.useMemo(()=>yd(e.actions),[e.actions]),[a,o]=$.useState(null),s=i.some(e=>e.name===a)?a:i[0]?.name??null,c=i.find(e=>e.name===s)??null,l=Oi(`action`),u=$.useCallback(e=>{c&&(t({actions:i.map(t=>t.name===c.name?{...t,...e}:t)}),typeof e.name==`string`&&e.name!==c.name&&o(e.name))},[i,c,t]),d=typeof e.name==`string`?e.name:``,f=$.useCallback(()=>{let e=bd(d,i.map(e=>String(e.name??``))),n={name:e,label:Z(`engine.studio.actions.newLabel`,r),type:`script`,objectName:d,body:{language:`js`,source:`return { ok: true };`}};t({actions:[...i,n]}),o(e)},[i,d,t,r]),p=$.useCallback(e=>{t({actions:i.filter(t=>t.name!==e)}),o(null)},[i,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)(pe,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.data.tab.actions`,r)}),(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,i.length,`)`]}),!n&&(0,Q.jsxs)(`button`,{type:`button`,onClick:f,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)(Ct,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,r)]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:i.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`,r)}):i.map(e=>{let t=Ha(typeof e.icon==`string`?e.icon:void 0),n=typeof e.type==`string`?e.type:``;return(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>o(e.name??null),className:`flex w-full items-center gap-2 border-b px-3 py-2 text-left text-[12px] `+(s===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:xd(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:c?l?(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:()=>p(c.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)(Wn,{className:`h-3 w-3`}),` `,Z(`engine.studio.actions.delete`,r)]})}),(0,Q.jsx)(l,{type:`action`,name:String(c.name??``),draft:c,onPatch:u,readOnly:!!n,locale:r})]}):(0,Q.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:xd(c.label,String(c.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`,r)})})]})}function Cd(e){let t=e?.data??e,n=Array.isArray(t)?t:t?.packages??[],r=[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=e.manifest??{},n=String(t.id??e.id??``);if(!n)continue;let i=typeof t.scope==`string`?t.scope:``;i===`system`||i===`cloud`||r.push({id:n,name:String(t.name??n),writable:i!==`project`})}return r}async function wd(){let e=await fetch(`/api/v1/packages`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);return Cd(await e.json())}async function Td(e,t){let n=await fetch(`/api/v1/packages`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({id:e,name:t})}),r=await n.json().catch(()=>null);if(!n.ok||r?.success===!1)throw Error(r?.error?.message||`HTTP ${n.status}`)}async function Ed(e,t,n){let r=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/duplicate`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({targetPackageId:t,...n?{targetName:n}:{}})}),i=await r.json().catch(()=>null);if(!r.ok||i?.success===!1)throw Error(i?.error?.message||`HTTP ${r.status}`)}var Dd=/^[a-z][a-z0-9_.-]*(\.[a-z0-9_-]+)+$/;function Od(e){let t=e.toLowerCase().replace(/[^a-z0-9_.-]/g,``);return{value:t,stripped:t.length!==e.length}}var kd=[{key:`data`,label:`Data`,Icon:Mn},{key:`automations`,label:`Automations`,Icon:ae},{key:`interfaces`,label:`Interfaces`,Icon:bt},{key:`access`,label:`Access`,Icon:It}],Ad={group:H,page:ve,object:Mn,dashboard:bt,report:Dt,view:ln},jd=e=>Ad[e??``]??wn;function Md(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 Nd(e,t){for(let n of e)if(n.type===`group`||n.children?.length){let e=Nd(n.children??[],t);if(e)return e}else{let e=Md(n);if(e&&e.type===t.type&&e.name===t.name)return e}return null}function Pd(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 Fd({packageId:e,tab:t}){let n=a(),r=La(),[i,o]=$.useState(!1),[s,c]=$.useState(null),[l,u]=$.useState(!1),[d,f]=$.useState(null),[p,m]=$.useState(!1),[h,g]=$.useState(!1);$.useEffect(()=>{let e=!1;return wd().then(t=>{e||c(t)}).catch(()=>{}),()=>{e=!0}},[e]);let _=s?.find(t=>t.id===e)??null,v=$.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},[]),y=$.useCallback(async e=>{o(!1),g(!0);try{f(await v(e)),m(!0)}catch(e){X.error(Gu(e))}finally{g(!1)}},[v]),b=$.useCallback(async()=>{let r=[];try{r=await wd(),c(r)}catch{}let i=d?.manifest.id;if(i){if(!r.some(e=>e.id===i)){if(i===e){let e=r[0];n(e?`/studio/${encodeURIComponent(e.id)}/${t}`:`/home`)}return}try{let e=await v(i);e&&f(e)}catch{}}},[d,e,t,n,v]);return(0,Q.jsxs)(un,{open:i,onOpenChange:o,children:[(0,Q.jsx)(Fn,{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`,r),children:[(0,Q.jsx)(Nn,{className:`h-4 w-4`}),` `,_?.name??e,_&&!_.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)(Xe,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,r)]}),(0,Q.jsx)(Ce,{className:`h-3.5 w-3.5 text-muted-foreground`})]})}),(0,Q.jsxs)(Pt,{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`,r)}),(0,Q.jsxs)(`div`,{className:`max-h-64 overflow-auto`,children:[s===null&&(0,Q.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,r)}),s?.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.pkg.none`,r)}),s?.map(i=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{o(!1),n(`/studio/${encodeURIComponent(i.id)}/${t}`)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(i.id===e?`bg-muted font-medium`:`hover:bg-muted/60`),children:[(0,Q.jsx)(Nn,{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:i.name}),(0,Q.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:i.id})]}),i.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`,r)}):(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)(Xe,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,r)]})]},i.id))]}),(0,Q.jsxs)(`div`,{className:`mt-1 space-y-0.5 border-t pt-1.5`,children:[_&&(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void y(e),disabled:h,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:[h?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(it,{className:`h-3.5 w-3.5`}),Z(`engine.studio.pkg.manage`,r)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{o(!1),u(!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)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.pkg.new`,r)]})]})]}),(0,Q.jsx)(gi,{open:l,onOpenChange:u,onCreated:e=>n(`/studio/${encodeURIComponent(e)}/data`)}),(0,Q.jsx)(Ni,{pkg:d,open:p,onOpenChange:m,onChanged:b})]})}function Id({aiSlot:e}){let t=l(),r=t.packageId??`com.example.showcase`,i=t.tab??`interfaces`,o=La(),[s,c]=$.useState(null);$.useEffect(()=>{let e=!1;return c(null),wd().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,m]=$.useState(null),[h,g]=$.useState(!1),[_,v]=$.useState(0),[y,b]=$.useState(0),x=$.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 m(null);let t=await e.json(),n=Array.isArray(t)?t:t?.drafts??[];m(n.length)}catch{m(null)}},[r]);$.useEffect(()=>{x()},[x,_,y]);let S=$.useCallback(async()=>{g(!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(Ku(n)):(X.success(Z(`engine.studio.publishedAll`,o)),f(!1)),v(e=>e+1)}catch(e){X.error(Gu(e))}finally{g(!1)}await x()},[r,x]),C=$.useCallback(()=>b(e=>e+1),[]),w=(p??0)>0,T=a(),E=Sa(),[D,O]=$.useState(null),[k,A]=$.useState(!1),[j,M]=$.useState(!1),[N,P]=$.useState(null),[F,I]=$.useState(null),[ee,te]=$.useState(!0),L=$.useCallback(async()=>{let[e,t]=await Promise.all([E.list(`object`,{packageId:r}),E.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},[E,r]),ne=$.useCallback(async(e,t)=>{M(!0),P(null);try{let n=ee?await L().catch(()=>[]):[];await E.save(`app`,t,Xu(t,e,n),{mode:`draft`,packageId:r}),X.success(Na(`engine.studio.app.savedDraft`,o,{label:e})),I(e),A(!1),b(e=>e+1)}catch(e){P(Gu(e))}finally{M(!1)}},[ee,L,E,r,o]);return $.useEffect(()=>{let e=!1;return(async()=>{try{let t=(await E.list(`app`,{packageId:r})||[]).map(e=>({name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name)[0];e||O(t??null)}catch{e||O(null)}})(),()=>{e=!0}},[E,r,_]),(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}):(0,Q.jsx)(Hu,{packageId:r,locale:o}),(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:()=>T(`/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)(Cn,{className:`h-4 w-4`})}),(0,Q.jsx)(`div`,{className:`shrink-0`,children:(0,Q.jsx)(Fd,{packageId:r,tab:i})}),(0,Q.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:`·`}),(0,Q.jsx)(`nav`,{className:`flex shrink-0 gap-1`,children:kd.map(e=>(0,Q.jsxs)(n,{to:`/studio/${r}/${e.key}`,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:[D?(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>window.open(fs(`apps/${encodeURIComponent(D.name)}`),`_blank`),title:Na(`engine.studio.app.openTitle`,o,{label:D.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)(je,{className:`h-3.5 w-3.5`}),Z(`engine.studio.app.open`,o)]}):F?(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:Na(`engine.studio.app.pending`,o,{label:F})}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>A(!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)(Ct,{className:`h-3.5 w-3.5`}),Z(`engine.studio.app.create`,o)]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>f(!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)(or,{className:`h-3.5 w-3.5`}),Z(`engine.studio.changes`,o),w?` · ${p}`:``]}),(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>f(!0),disabled:h||!w||u,title:Z(u?`engine.studio.pkg.readonlyHint`:w?`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:[h?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(Ie,{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)(Ud,{packageId:r,publishNonce:_,onDraftSaved:C,readOnly:u}):i===`automations`?(0,Q.jsx)(Gd,{packageId:r,publishNonce:_,onDraftSaved:C,readOnly:u}):i===`access`?(0,Q.jsx)(Kd,{packageId:r,publishNonce:_,onDraftSaved:C,readOnly:u}):(0,Q.jsx)(zd,{packageId:r,publishNonce:_,draftNonce:y,onDraftSaved:C,onCreateApp:u?void 0:()=>A(!0),readOnly:u})})]}),(0,Q.jsx)(Uo,{open:d,onOpenChange:f,packageId:r,onPublish:u?void 0:S,publishing:h}),(0,Q.jsx)(Qu,{open:k,onOpenChange:A,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:j,error:N,locale:o,onSubmit:({label:e,name:t})=>void ne(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:ee,onChange:e=>te(e.target.checked),className:`h-3.5 w-3.5 accent-primary`}),Z(`engine.studio.app.scaffoldNav`,o)]})})]})}function Ld({nodes:e,active:t,onPick:n}){return(0,Q.jsx)(Q.Fragment,{children:e.map((e,r)=>{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)(H,{className:`h-3 w-3`}),` `,e.label]}),(0,Q.jsx)(`div`,{className:`pl-1.5`,children:(0,Q.jsx)(Ld,{nodes:e.children??[],active:t,onPick:n})})]},e.id??r);let i=Md(e),a=jd(e.type),o=!!i&&t?.type===i.type&&t?.name===i.name;return(0,Q.jsxs)(`button`,{onClick:()=>i&&n(i),disabled:!i,title:i?`${i.type} · ${i.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 `+(o?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(a,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),i&&i.type!==`page`&&(0,Q.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/60`,children:i.type})]},e.id??r)})})}function Rd({navId:e,appDraft:t,objects:n,onNavPatch:r,onClear:i}){let a=La(),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 zd({packageId:e,publishNonce:t=0,draftNonce:n=0,onDraftSaved:r,onCreateApp:i,readOnly:a=!1}){let o=Sa(),c=La(),l=dr(),[u,d]=$.useState(!1),[f,p]=$.useState(e),[m,h]=$.useState(null),[g,_]=$.useState({}),v=$.useMemo(()=>Array.isArray(g.navigation)?g.navigation:[],[g]),[y,b]=$.useState(!1),[x,S]=$.useState(null),[C,w]=s(),T=Ei(C.get(`sel`)),E=$.useRef(Ci(C.get(Ti))),O=$.useRef(null);$.useEffect(()=>{if(!T||v.length===0||O.current===T)return;let e=Mi({navigation:v},T);e&&(O.current=T,b(!0),S({kind:`nav`,id:e.selectionId}))},[T,v]),$.useEffect(()=>{let e=x?ki({navigation:v},x.id):null;w(t=>{let n=new URLSearchParams(t);return e?n.set(`sel`,bi(e)):n.delete(`sel`),n},{replace:!0})},[x]);let[k,A]=$.useState(!1),[j,M]=$.useState(!1),[N,P]=$.useState(!1),[F,I]=$.useState(null);$.useEffect(()=>{F&&w(e=>{let t=new URLSearchParams(e);return t.set(Ti,xi(F)),t},{replace:!0})},[F]);let[ee,te]=$.useState(`source`),[L,ne]=$.useState({}),[re,ie]=$.useState(null),[ae,oe]=$.useState(!1),[se,R]=$.useState(!1),[ce,z]=$.useState(!1),[le,B]=$.useState(null),[V,ue]=$.useState(`loading`),[de,fe]=$.useState([]);$.useEffect(()=>{let t=!1;return(async()=>{try{let[n,r]=await Promise.all([o.list(`object`,{packageId:e}),o.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)})}fe([...i.values()])}catch{}})(),()=>{t=!0}},[o,e,t,n]),$.useEffect(()=>{let t=!1;return ue(`loading`),(async()=>{try{let n=await o.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 o.listDrafts({packageId:e,type:`app`});if(t)return;let a=n?.[0];a?.name&&(r=String(a.name),i=String(a.name))}if(!r){ue(`missing`);return}p(i),h(r);let[a,s]=await Promise.all([o.layered(`app`,r),o.getDraft(`app`,r).catch(()=>null)]);if(t)return;let c=a,l=c.effective??c.code??{},u=Pd(s),d=u?{...l,...u}:l;(typeof d.label==`string`||typeof d.name==`string`)&&p(String(d.label??d.name??i)),_(d),M(!!u),ue(`ready`);let f=Array.isArray(d.navigation)?d.navigation:[],m=(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=Md(n);if(e)return e}return null})(f),g=E.current?Nd(f,E.current):null;I(e=>e??g??m)}catch(e){t||(B(Gu(e)),ue(`missing`))}})(),()=>{t=!0}},[o,e,t,n]);let pe=yi(F?.type??``),me=ji(F?.type??``),H=Oi(F?.type??``),he=!!pe&&F?.type!==`object`,ge=F?.type===`page`?L?.kind:void 0,U=ge===`html`||ge===`react`;$.useEffect(()=>{if(!F||!he){ne({}),z(!1);return}let e=!1;return oe(!0),B(null),ie(null),(async()=>{try{let[t,n]=await Promise.all([o.layered(F.type,F.name),o.getDraft(F.type,F.name).catch(()=>null)]);if(e)return;let r=t.effective??t.code??{},i=Pd(n);ne(i?{...r,...i}:r),z(!!i)}catch(t){e||B(Gu(t))}finally{e||oe(!1)}})(),()=>{e=!0}},[o,F,he,t]);let _e=$.useCallback(e=>ne(t=>({...t,...e})),[]),ve=$.useCallback(async()=>{if(F){R(`draft`);try{await o.save(F.type,F.name,L,{mode:`draft`,packageId:e}),z(!0),r?.()}catch(e){B(Gu(e))}finally{R(!1)}}},[o,F,L,r]),W=$.useCallback(e=>{_(t=>({...t,...e})),A(!0)},[]),ye=$.useCallback(async()=>{if(m){P(`draft`);try{let t=(Array.isArray(g.navigation)?g.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 o.save(`app`,m,{...g,navigation:t},{mode:`draft`,packageId:e}),M(!0),A(!1),r?.()}catch(e){B(Gu(e))}finally{P(!1)}}},[o,m,g,r]);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:()=>d(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,c),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,Q.jsx)(fn,{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`,c)}),ce&&(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`,c)}),(0,Q.jsxs)(`button`,{onClick:ve,disabled:!F||!he||!!se||a,title:a?Z(`engine.studio.pkg.readonlyHint`,c):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:[se===`draft`?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(pn,{className:`h-3.5 w-3.5`}),Z(`engine.studio.saveDraft`,c)]})]}),(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:yn((y?`w-72`:`w-52`)+` flex 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 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:Na(`engine.studio.if.navHeading`,c,{app:f})}),V===`ready`&&!a&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>{b(e=>!e),S(null)},title:Z(y?`engine.studio.if.doneEditTitle`:`engine.studio.if.editNavTitle`,c),className:`inline-flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[10px] `+(y?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted`),children:y?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(q,{className:`h-3 w-3`}),` `,Z(`engine.studio.done`,c)]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(An,{className:`h-3 w-3`}),` `,Z(`engine.studio.edit`,c)]})})]}),y&&(0,Q.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[j&&(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`,c)}),(0,Q.jsxs)(`button`,{onClick:ye,disabled:!k||!!N,className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] hover:bg-muted disabled:opacity-50`,children:[N===`draft`?(0,Q.jsx)(Y,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(pn,{className:`h-3 w-3`}),Z(`engine.studio.saveDraft`,c)]})]})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:V===`missing`&&!le?(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`,c)}),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)(Ct,{className:`h-3 w-3`}),` `,Z(`engine.studio.app.create`,c)]})]}):y?(0,Q.jsx)(Di,{draft:g,rootKey:`navigation`,onPatch:W,selection:x,onSelectionChange:e=>S(e?{kind:e.kind,id:e.id}:null)}):v.length===0?(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(le?`engine.studio.loadFailed`:V===`loading`?`engine.studio.loading`:`engine.studio.if.noNavItems`,c)}):(0,Q.jsx)(Ld,{nodes:v,active:F,onPick:e=>{I(e),l&&d(!1)}})})]}),(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)(Ne,{className:`h-3 w-3`}),` `,Z(`engine.studio.if.previewIsRuntime`,c)]}),F&&(0,Q.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[F.type,` · `,F.name]})]}),le&&(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:le}),(0,Q.jsx)(`div`,{className:yn(U?`min-h-0 flex-1 overflow-hidden`:`rounded-lg border bg-background p-4`),children:V===`missing`&&!le?(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)(bt,{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`,c)}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:Z(`engine.studio.if.noAppHint`,c)})]}),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)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.app.create`,c)]})]}):F?ae?(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`,c)]}):F.type===`object`?(0,Q.jsx)(D,{schema:{type:`object-view`,objectName:F.name}}):U?(0,Q.jsx)(Ai,{mode:`preview`,draft:L,readOnly:!0}):pe?(0,Q.jsx)(pe,{type:F.type,name:F.name,draft:L,editing:!0,selection:re,onSelectionChange:ie,onPatch:_e,locale:c}):(0,Q.jsx)(`div`,{className:`py-12 text-center text-xs text-muted-foreground`,children:Na(`engine.studio.if.readonlyPreview`,c,{type:F.type})}):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.if.pickLeft`,c)})}),!he&&F?.type===`object`?(0,Q.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Mn,{className:`h-3 w-3`}),` `,Z(`engine.studio.if.objectHintPre`,c),(0,Q.jsx)(`span`,{className:`font-medium`,children:`Data`}),Z(`engine.studio.if.objectHintPost`,c)]}):null]}),(0,Q.jsxs)(`aside`,{className:yn(`flex shrink-0 flex-col overflow-hidden border-l`,U&&!(re&&me&&F)&&!(y&&x)?`w-[24rem] xl:w-[30rem] 2xl:w-[36rem]`:`w-72`),children:[(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)(At,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.inspector.props`,c)}),re&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ie(null),className:`ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.deselect`,c),children:(0,Q.jsx)(Ge,{className:`h-3.5 w-3.5`})})]}),y&&x?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,Q.jsx)(Rd,{navId:x.id,appDraft:g,objects:de,onNavPatch:W,onClear:()=>S(null)})}):re&&me&&F?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,Q.jsx)(me,{type:F.type,name:F.name,draft:L,selection:re,onPatch:_e,onClearSelection:()=>ie(null),onSelectionChange:ie,readOnly:!1,locale:c})}):U?(0,Q.jsxs)(Ut,{value:ee,onValueChange:e=>te(e===`props`?`props`:`source`),className:`flex min-h-0 flex-1 flex-col`,children:[(0,Q.jsxs)(Zn,{className:`mx-3 mt-2 shrink-0 self-start`,children:[(0,Q.jsxs)(Jt,{value:`source`,className:`gap-1 text-xs`,children:[(0,Q.jsx)(qt,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.inspector.tabSource`,c)]}),(0,Q.jsx)(Jt,{value:`props`,className:`text-xs`,children:Z(`engine.studio.inspector.tabProps`,c)})]}),(0,Q.jsx)(Tn,{value:`source`,className:`mt-2 min-h-0 flex-1 border-t`,children:(0,Q.jsx)(Ai,{mode:`editor`,draft:L,onPatch:_e})}),(0,Q.jsx)(Tn,{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)(qt,{className:`h-5 w-5`}),Na(`engine.studio.inspector.sourcePageLine1`,c,{kind:ge}),(0,Q.jsx)(`br`,{}),Z(`engine.studio.inspector.sourcePageLine2`,c)]})})]}):H&&F&&he?(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,Q.jsx)(H,{type:F.type,name:F.name,draft:L,onPatch:_e,onSelectionChange:ie,readOnly:!1,locale:c})}):(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)(rr,{className:`h-5 w-5`}),Z(`engine.studio.inspector.emptyLine1`,c),(0,Q.jsx)(`br`,{}),Z(`engine.studio.inspector.emptyLine2`,c)]})})]})]})]})}function Bd(e){let t=e.length+1,n=`field_${t}`;for(;e.includes(n);)n=`field_${++t}`;return n}var Vd=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 Hd(e){let{schema:t,dataSource:n,onEdit:r,className:i,refreshKey:a,onAddRecord:o}=e;return(0,Q.jsx)(Za,{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 Ud({packageId:e,publishNonce:t=0,onDraftSaved:n,readOnly:r=!1}){let i=Sa(),a=w(),o=La(),s=dr(),[c,l]=$.useState(!1),[u,d]=$.useState([]),[f,p]=$.useState(!1),[m,h]=$.useState(null),[g,_]=$.useState({}),[v,y]=$.useState(!1),[b,x]=$.useState(null),[S,C]=$.useState(null),[T,E]=$.useState(!1),[D,O]=$.useState(!1),[k,A]=$.useState(!1),[j,M]=$.useState(null),[N,F]=$.useState(0),[I,ee]=$.useState(`grid`),[te,L]=$.useState(`layout`),ne=$.useRef(null),[re,ie]=$.useState(``),[ae,oe]=$.useState(!1),[se,R]=$.useState(!1),[ce,z]=$.useState(!0);$.useEffect(()=>{let t=!1;return(async()=>{try{let[n,a]=await Promise.all([i.list(`object`,{packageId:e}),i.listDrafts({packageId:e,type:`object`}).catch(()=>[])]);if(t)return;let o=(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),s=new Set(o.map(e=>e.name));for(let e of a)e.name&&!s.has(e.name)&&o.push({type:`object`,name:e.name,label:e.name,icon:void 0});d(o),h(e=>e??o[0]??null),o.length===0&&!r&&oe(!0)}catch(e){t||x(Gu(e))}finally{t||p(!0)}})(),()=>{t=!0}},[i,e,r]),$.useEffect(()=>{if(!m)return;let e=`${m.name}#${t}`;if(ne.current===e)return;ne.current=e;let n=!1;return y(!0),x(null),C(null),E(!1),(async()=>{try{let[e,t]=await Promise.all([i.layered(`object`,m.name),i.getDraft(`object`,m.name).catch(()=>null)]);if(n)return;let r=e,a=r.effective??r.code??{},o=Pd(t);_(o?{...a,...o}:a),O(!!o),z(!!(r.effective??r.code))}catch(e){n||x(Gu(e))}finally{n||y(!1)}})(),()=>{n=!0}},[i,m,t]);let le=$.useMemo(()=>Aa(g.fields).entries.length,[g]),B=$.useCallback(e=>{_(t=>({...t,...e})),E(!0)},[]),V=$.useCallback(()=>{if(r)return;let e=Aa(g.fields),t=Bd(e.entries.map(e=>e.name));e.entries.push(ka(t,`text`,Z(`engine.studio.data.newFieldLabel`,o))),_(t=>({...t,fields:ja(e)})),E(!0),C({kind:`field`,id:t})},[g,r]),ue=$.useCallback(async(t,a)=>{if(!r){if(u.some(e=>e.name===a)){x(Na(`engine.studio.data.idExists`,o,{name:a}));return}R(!0),x(null);try{let r=Ju(a,t,Z(`engine.studio.data.nameFieldLabel`,o));await i.save(`object`,a,r,{mode:`draft`,packageId:e});let s={type:`object`,name:a,label:t};d(e=>[...e,s]),h(s),ee(`form`),L(`layout`),oe(!1),n?.()}catch(e){x(Gu(e))}finally{R(!1)}}},[u,i,e,n,r,o]),de=$.useCallback(async()=>{if(m){A(`draft`),x(null);try{await i.save(`object`,m.name,g,{mode:`draft`,packageId:e}),O(!0),E(!1),M(new Date),X.success(Na(`engine.studio.data.savedDraft`,o,{label:m.label})),n?.()}catch(e){x(Gu(e))}finally{A(!1)}}},[i,m,g,n,e,o]),fe=$.useCallback(async t=>{if(!m)return;let r=Aa(g.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={...g,fields:ja({...r,entries:c})};_(l),A(`draft`),x(null);try{await i.save(`object`,m.name,l,{mode:`draft`,packageId:e}),O(!0),E(!1),n?.(),F(e=>e+1)}catch(e){x(Gu(e))}finally{A(!1)}},[i,m,g,n]),pe=ji(`object`),me=[{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)}],H=Ha(typeof g.icon==`string`?g.icon:m?.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:()=>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)(fn,{className:`h-4 w-4`})}),m?(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Q.jsx)(H,{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:m.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:m.name}),(0,Q.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:Na(`engine.studio.data.fieldCount`,o,{count:le})})]}):(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,o)}),D&&(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)}),j&&!T&&(0,Q.jsx)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,"data-testid":`data-saved-at`,children:Na(`engine.studio.data.lastSaved`,o,{time:j.toLocaleTimeString(o,{hour:`2-digit`,minute:`2-digit`})})}),(0,Q.jsxs)(`button`,{onClick:de,disabled:!m||!T||!!k||r,title:r?Z(`engine.studio.pkg.readonlyHint`,o):void 0,className:(j&&!T?``:`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:[k===`draft`?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(pn,{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:[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:yn(`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.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:re,onChange:e=>ie(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:[u.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(b?`engine.studio.loadFailed`:f?`engine.studio.data.noObjects`:`engine.studio.loading`,o)}),u.filter(e=>!re.trim()||e.label.toLowerCase().includes(re.trim().toLowerCase())||e.name.toLowerCase().includes(re.trim().toLowerCase())).map(e=>{let t=Ha(e.icon);return(0,Q.jsxs)(`button`,{onClick:()=>{h(e),s&&l(!1)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(m?.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)(Xe,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,o)]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{x(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)(Ct,{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:m?(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:me.map(e=>(0,Q.jsx)(`button`,{type:`button`,onClick:()=>ee(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:V,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)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.addField`,o)]})]}),b&&(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:b}),I===`rules`?(0,Q.jsx)(ud,{draft:g,onPatch:B,disabled:r}):I===`settings`?(0,Q.jsx)(dd,{name:m.name,draft:g,onPatch:B,locale:o,disabled:r}):I===`hooks`?(0,Q.jsx)(vd,{objectName:m.name,packageId:e}):I===`actions`?(0,Q.jsx)(Sd,{draft:g,onPatch:B,disabled:r}):I===`api`?(0,Q.jsx)(hd,{name:m.name,draft:g}):I===`grid`&&!ce?(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:()=>{ee(`form`),L(`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)(Be,{value:{...r?{}:{onAddColumn:V,addColumnLabel:Z(`engine.studio.data.addField`,o),onReorderFields:fe},onEditColumn:e=>{Aa(g.fields).entries.some(t=>t.name===e)&&C({kind:`field`,id:e})},editColumnLabel:Z(`engine.studio.data.editFieldProps`,o)},children:(0,Q.jsx)(P,{dataSource:a,children:(0,Q.jsx)(to,{schema:{type:`object-view`,objectName:m.name,showCreate:!1,table:{fields:Aa(g.fields).entries.map(e=>e.name).filter(e=>!Vd.has(e)&&e!==`actions`)}},dataSource:a,renderListView:Hd},`${m.name}:${N}`)})})})}):(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:()=>L(`layout`),"aria-pressed":te===`layout`,className:`rounded-md px-2.5 py-0.5 text-[12px] transition-all `+(te===`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:()=>L(`preview`),"aria-pressed":te===`preview`,className:`rounded-md px-2.5 py-0.5 text-[12px] transition-all `+(te===`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(te===`layout`?`engine.studio.data.form.layoutBadge`:`engine.studio.data.form.previewBadge`,o)}),te===`preview`&&(T||D)&&(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)})]}),te===`layout`?(0,Q.jsx)(sd,{draft:g,systemFieldNames:Vd,onChange:B,selectedField:S?.kind===`field`?S.id:null,onSelectField:e=>C({kind:`field`,id:e}),onAddField:V,readOnly:r}):ce?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`style`,{children:`
7
+ /* Design preview: the form is a click-to-select canvas, not a data-entry
8
+ * form. Disable interaction on field contents so a click anywhere on a
9
+ * field routes to its [data-field] wrapper (→ select), and neutralize the
10
+ * create/cancel footer so nothing is submittable here. */
11
+ .os-form-authoring [data-field]{border-radius:8px;cursor:pointer;transition:box-shadow .12s;padding:8px;margin:-8px 0;}
12
+ .os-form-authoring [data-field] *{pointer-events:none;}
13
+ .os-form-authoring [data-field]:hover{box-shadow:0 0 0 1px hsl(var(--border));}
14
+ .os-form-authoring form > div:last-child:has(button){display:none;}
15
+ ${S?.kind===`field`?`.os-form-authoring [data-field="${String(S.id).replace(/[^\w-]/g,``)}"]{box-shadow:0 0 0 2px hsl(var(--primary));}`:``}
16
+ `}),(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-2xl`,onClick:e=>{let t=e.target.closest(`[data-field]`)?.getAttribute(`data-field`);t&&Aa(g.fields).entries.some(e=>e.name===t)&&C({kind:`field`,id:t})},children:(0,Q.jsx)(P,{dataSource:a,children:(0,Q.jsx)(gr,{schema:{type:`object-form`,objectName:m.name,mode:`create`,fields:Aa(g.fields).entries.map(e=>e.name).filter(e=>!Vd.has(e))},dataSource:a},`${m.name}:${N}: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)})]})]})]}):f&&u.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)})]}):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,o)})}),m&&S&&pe&&(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)(At,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.data.fieldProps`,o)}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>C(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)(Ge,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:$.createElement(pe,{type:`object`,name:m.name,draft:g,selection:S,onPatch:B,onClearSelection:()=>C(null),onSelectionChange:C,readOnly:r,locale:o})})]})]}),(0,Q.jsx)(Qu,{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:b,locale:o,onSubmit:({label:e,name:t})=>void ue(e,t)})]})}function Wd({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 Gd({packageId:e,publishNonce:t=0,onDraftSaved:n,readOnly:r=!1}){let i=Sa(),a=La(),o=dr(),[s,c]=$.useState(!1),[l,u]=$.useState([]),[d,f]=$.useState(null),[p,m]=$.useState({}),[h,g]=$.useState(null),[_,v]=$.useState(!1),[y,b]=$.useState(!1),[x,S]=$.useState(!1),[C,w]=$.useState(null),[T,E]=$.useState(!1),[D,O]=$.useState(!1),[k,A]=$.useState(!1),j=yi(d?.type??``),M=ji(`flow`),N=!!j,[P,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 qu(i,`flow`,e);if(t)return;u(n),f(e=>e??n[0]??null)}catch(e){t||w(Gu(e))}finally{t||E(!0)}})(),()=>{t=!0}},[i,e,t]);let I=$.useCallback(async(t,r)=>{A(!0),w(null);try{let o=Yu(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),S(!0),O(!1),n?.(),X.success(Na(`engine.studio.auto.savedDraft`,a,{label:t}))}catch(e){w(Gu(e))}finally{A(!1)}},[i,e,n,a]);$.useEffect(()=>{if(!d)return;let e=!1;return v(!0),w(null),g(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=Pd(n);m(o?{...a,...o}:a),S(!!o)}catch(t){e||w(Gu(t))}finally{e||v(!1)}})(),()=>{e=!0}},[i,d,t]);let ee=$.useCallback(e=>m(t=>({...t,...e})),[]),te=$.useCallback(async()=>{if(d){b(`draft`),w(null);try{await i.save(`flow`,d.name,p,{mode:`draft`,packageId:e}),S(!0),n?.()}catch(e){w(Gu(e))}finally{b(!1)}}},[i,d,p,n]),L=p.status!==`obsolete`&&p.status!==`invalid`,ne=$.useCallback(async()=>{if(!d)return;let t=!(p.status!==`obsolete`&&p.status!==`invalid`),r={...p,status:t?`active`:`obsolete`};m(r),b(`draft`),w(null);try{await i.save(`flow`,d.name,r,{mode:`draft`,packageId:e}),S(!0),n?.(),X.success(Z(t?`engine.studio.auto.enabledToast`:`engine.studio.auto.disabledToast`,a))}catch(e){w(Gu(e))}finally{b(!1)}},[i,d,p,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)(fn,{className:`h-4 w-4`})}),(0,Q.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.auto.defaultOff`,a)}),x&&(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":L,onClick:ne,disabled:!N||!!y,title:Z(L?`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 `+(L?`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 `+(L?`translate-x-3`:`translate-x-0.5`)})}),Z(L?`engine.studio.auto.enabled`:`engine.studio.auto.disabled`,a)]}),(0,Q.jsxs)(`button`,{onClick:te,disabled:!d||!N||!!y||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:[y===`draft`?(0,Q.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,Q.jsx)(pn,{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:yn(`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:()=>{w(null),O(!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)(Ct,{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)(ae,{className:`h-3.5 w-3.5 shrink-0`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),(0,Q.jsx)(Wd,{state:P[e.name],locale:a})]},e.name)),l.length===0&&!D&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(C?`engine.studio.loadFailed`:T?`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)(ae,{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]})]}),C&&(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:C}),(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 rounded-lg border bg-background p-4`,children:d?_?(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)]}):j?$.createElement(j,{type:d.type,name:d.name,draft:p,editing:!0,selection:h,onSelectionChange:g,onPatch:ee,locale:a}):(0,Q.jsx)(`pre`,{className:`overflow-auto text-[11px] text-muted-foreground`,children:JSON.stringify(p,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)(At,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.auto.config`,a)}),h&&(0,Q.jsx)(`button`,{type:`button`,onClick:()=>g(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)(Ge,{className:`h-3.5 w-3.5`})})]}),(0,Q.jsx)(`div`,{className:`p-3`,children:h&&M&&d?$.createElement(M,{type:`flow`,name:d.name,draft:p,selection:h,onPatch:ee,onClearSelection:()=>g(null),onSelectionChange:g,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)(rr,{className:`h-5 w-5`}),Z(`engine.studio.auto.emptyLine1`,a),(0,Q.jsx)(`br`,{}),Z(`engine.studio.auto.emptyLine2`,a)]})})]})]}),(0,Q.jsx)(Qu,{open:D,onOpenChange:O,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:k,error:C,locale:a,onSubmit:({label:e,name:t})=>void I(e,t)})]})}function Kd({packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r=!1}){let i=Sa(),a=La(),o=dr(),[s,c]=$.useState(!1),[l,u]=$.useState([]),[d,f]=$.useState(!1),[p,m]=$.useState(null),[h,g]=$.useState(null),[_,v]=$.useState(``),[y,b]=$.useState(!1),[x,S]=$.useState(null),[C,w]=$.useState(!1),T=$.useCallback(async()=>{try{let[t,n]=await Promise.all([i.list(`permission`,{packageId:e}),i.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??``),isProfile:!!e.isProfile})}for(let e of n||[]){let t=String(e?.name??``);!t||r.has(t)||r.set(t,{name:t,label:t})}let a=[...r.values()];u(a),g(e=>e??a[0]?.name??null)}catch(e){m(Gu(e))}finally{f(!0)}},[i,e]);$.useEffect(()=>{T()},[T,t]);let E=$.useCallback(async(t,r)=>{w(!0),S(null);try{await i.save(`permission`,r,Zu(r,t),{mode:`draft`,packageId:e}),X.success(Na(`engine.studio.access.created`,a,{label:t})),b(!1),n?.(),await T(),g(r)}catch(e){S(Gu(e))}finally{w(!1)}},[i,T,e,n,a]),D=l.filter(e=>!_.trim()||e.label.toLowerCase().includes(_.trim().toLowerCase())||e.name.toLowerCase().includes(_.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:()=>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)(fn,{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)(It,{className:`h-3.5 w-3.5`}),(0,Q.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:Z(`engine.studio.access.title`,a)}),(0,Q.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:Z(`engine.studio.access.subtitle`,a)})]}),(0,Q.jsx)(`span`,{title:Z(`engine.studio.access.bannerTitle`,a),className:`ml-auto 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`,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:yn(`flex w-52 shrink-0 flex-col border-r bg-background`,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:`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`,a)}),(0,Q.jsx)(`input`,{value:_,onChange:e=>v(e.target.value),placeholder:Z(`engine.studio.access.search`,a),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:[l.length===0&&(0,Q.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(p?`engine.studio.loadFailed`:d?`engine.studio.access.none`:`engine.studio.loading`,a)}),D.map(e=>(0,Q.jsxs)(`button`,{onClick:()=>{g(e.name),o&&c(!1)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(h===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,Q.jsx)(It,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.isProfile&&(0,Q.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/60`,children:`profile`})]},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`,a),className:`flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[(0,Q.jsx)(Xe,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,a)]}):(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>{S(null),b(!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)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.access.new`,a)]})})]}),(0,Q.jsx)(`main`,{className:`min-w-0 flex-1 overflow-auto`,children:h?(0,Q.jsx)(wi,{type:`permission`,name:h,packageId:e,publishNonce:t,onDraftSaved:n},h):(0,Q.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:d&&l.length===0?Z(`engine.studio.access.emptyMain`,a):Z(`engine.studio.access.pick`,a)})})]}),(0,Q.jsx)(Qu,{open:y,onOpenChange:b,title:Z(`engine.studio.access.new`,a),labelFieldLabel:Z(`engine.studio.access.nameLabel`,a),labelPlaceholder:Z(`engine.studio.access.labelPlaceholder`,a),idFieldLabel:Z(`engine.studio.access.idLabel`,a),idPlaceholder:Z(`engine.studio.access.idPlaceholder`,a),submitLabel:Z(`engine.studio.create`,a),submittingLabel:Z(`engine.studio.creating`,a),busy:C,error:x,locale:a,onSubmit:({label:e,name:t})=>void E(e,t)})]})}function qd({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&&!Dd.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}=Od(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 Jd({show:e,locale:t}){return e?(0,Q.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,"data-testid":`pkg-id-manual-hint`,children:Z(`engine.studio.pkg.idFromNameUnavailable`,t)}):null}function Yd(){let e=a(),t=La(),[n,r]=$.useState(null),[i,o]=$.useState(null),[s,c]=$.useState(!1),[l,u]=$.useState(``),[d,f]=$.useState(``),[p,m]=$.useState(!1),[h,g]=$.useState(!1);$.useEffect(()=>{let e=!1;return wd().then(t=>{e||r(t)}).catch(t=>{e||o(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let _=t=>e(`/studio/${encodeURIComponent(t)}/data`),v=async()=>{let e=l.trim(),t=d.trim();if(!(!e||!Dd.test(t))){g(!0),o(null);try{await Td(t,e),_(t)}catch(e){o(e instanceof Error?e.message:String(e))}finally{g(!1)}}},y=n?.filter(e=>e.writable)??[],b=n?.filter(e=>!e.writable)??[],[x,S]=$.useState(null),[C,w]=$.useState(``),[T,E]=$.useState(``),[D,O]=$.useState(!1),[k,A]=$.useState(null),j=e=>{S(e.id),w(Na(`engine.studio.landing.dupDefaultName`,t,{name:e.name})),E(`${e.id}-copy`),A(null)},M=async()=>{if(!x)return;let e=T.trim(),n=C.trim();if(!(!Dd.test(e)||!n)){O(!0),A(null);try{await Ed(x,e,n),X.success(Na(`engine.studio.landing.dupCreated`,t,{name:n})),_(e)}catch(e){A(e instanceof Error?e.message:String(e))}finally{O(!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)(Dn,{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&&y.length===0&&(0,Q.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.landing.noneWritable`,t)}),y.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:()=>_(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)(Nn,{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:()=>x===e.id?S(null):j(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)(Ht,{className:`h-3 w-3`}),` `,Z(`engine.studio.landing.dup`,t)]})]}),x===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:C,onChange:e=>w(e.target.value),onKeyDown:e=>{e.key===`Enter`&&M(),e.key===`Escape`&&S(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)(qd,{value:T,onChange:E,onEnter:()=>void M(),onEscape:()=>S(null),placeholder:Z(`engine.studio.landing.dupIdPlaceholder`,t),locale:t,testId:`pkg-dup-id-input`}),k&&(0,Q.jsx)(`p`,{className:`text-[10px] text-destructive`,children:k}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void M(),disabled:D||!C.trim()||!Dd.test(T.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:[D?(0,Q.jsx)(Y,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Ht,{className:`h-3 w-3`}),Z(`engine.studio.landing.dupGo`,t)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>S(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)),s?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 rounded-lg border border-dashed bg-muted/20 px-3 py-2.5`,children:[(0,Q.jsx)(`input`,{autoFocus:!0,value:l,onChange:e=>{if(u(e.target.value),!p){let t=Ma(e.target.value).replace(/_/g,`-`);f(t?`com.example.${t}`:``)}},onKeyDown:e=>{e.key===`Enter`&&v(),e.key===`Escape`&&c(!1)},placeholder:Z(`engine.studio.pkg.namePlaceholder`,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)(Jd,{show:!p&&!!l.trim()&&!d,locale:t}),(0,Q.jsx)(qd,{value:d,onChange:e=>{m(!0),f(e)},onEnter:()=>void v(),onEscape:()=>c(!1),placeholder:Z(`engine.studio.pkg.idPlaceholder`,t),locale:t,testId:`pkg-landing-id-input`}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>void v(),disabled:h||!l.trim()||!Dd.test(d.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:[h?(0,Q.jsx)(Y,{className:`h-3 w-3 animate-spin`}):(0,Q.jsx)(Ct,{className:`h-3 w-3`}),Z(`engine.studio.landing.createGo`,t)]}),(0,Q.jsx)(`button`,{type:`button`,onClick:()=>c(!1),className:`rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,children:Z(`engine.studio.cancel`,t)})]})]}):(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)(Ct,{className:`h-4 w-4`}),` `,Z(`engine.studio.pkg.new`,t)]})]}),b.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:b.map(e=>(0,Q.jsxs)(`button`,{type:`button`,onClick:()=>_(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)(Nn,{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)(Xe,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,t)]})]},e.id))})]})]})}var Xd=t({BuilderLanding:()=>Yd});export{go as C,jo as S,Eo as _,ou as a,Ao as b,Ll as c,El as d,Tl as f,Vs as g,Ks as h,Cu as i,Ml as l,Yc as m,Yd as n,Vl as o,al as p,Id as r,Bl as s,Xd as t,jl as u,To as v,ko as x,Co as y};