@objectstack/console 17.5.0 → 17.7.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 (282) hide show
  1. package/CHANGELOG.md +806 -0
  2. package/dist/.objectstack-injection.json +2 -2
  3. package/dist/.objectui-sha +1 -1
  4. package/dist/assets/{ActionResultDialog-CLdIyOW6.js → ActionResultDialog-ChYnuROr.js} +3 -3
  5. package/dist/assets/{AiPendingActionsPage-OKYz66yR.js → AiPendingActionsPage-Dh3-i4BB.js} +1 -1
  6. package/dist/assets/{ApiConsolePage-CcrKovu8.js → ApiConsolePage-CKYEqlMs.js} +1 -1
  7. package/dist/assets/AppDocsIndex-B5Tky2xg.js +1 -0
  8. package/dist/assets/{AppManagementPage-D_xz8cTZ.js → AppManagementPage-ZwyvnHpM.js} +1 -1
  9. package/dist/assets/ApprovalsInboxPage-DD4fe0Em.js +1 -0
  10. package/dist/assets/{AuditLogPage-CoghqsZb.js → AuditLogPage-Sed6iMqP.js} +1 -1
  11. package/dist/assets/BookPage-DYjUsQIc.js +1 -0
  12. package/dist/assets/{ComponentNavView-BxsixSU9.js → ComponentNavView-DrlxM4SY.js} +1 -1
  13. package/dist/assets/CreateViewDialog-Cp72x_O7.js +1 -0
  14. package/dist/assets/DashboardView-juicRxcP.js +1 -0
  15. package/dist/assets/DocPage-CxJaQ-pC.js +1 -0
  16. package/dist/assets/{DocsIndex-B2zw_HAp.js → DocsIndex-LALVtIVR.js} +1 -1
  17. package/dist/assets/{DocsLayout-DezZ8x7_.js → DocsLayout-BAwlJQQf.js} +1 -1
  18. package/dist/assets/DocsSlug-CkF1E-Zs.js +1 -0
  19. package/dist/assets/ExpressionProvider-Dr0e99r1.js +1 -0
  20. package/dist/assets/FlowRunsPage-R3W3t2s4.js +1 -0
  21. package/dist/assets/{IntegrationsPage-2leVkVDH.js → IntegrationsPage-DIuFLEbF.js} +2 -2
  22. package/dist/assets/InterfaceListPage-BfoCldGu.js +1 -0
  23. package/dist/assets/{MarketplaceInstalledPage-EPPHSitW.js → MarketplaceInstalledPage-DyjhcUNB.js} +1 -1
  24. package/dist/assets/MarketplacePackagePage-BbO27Pgs.js +4 -0
  25. package/dist/assets/{MarketplacePage-BnQKykgv.js → MarketplacePage-DO2_b64U.js} +1 -1
  26. package/dist/assets/{MetadataInspector-BWxLkr0O.js → MetadataInspector-BQyu9pOE.js} +1 -1
  27. package/dist/assets/ObjectDataPage-DIY-yefK.js +1 -0
  28. package/dist/assets/PageView-C-qWu3Jw.js +1 -0
  29. package/dist/assets/ProfilePage-Qp8DL8CF.js +1 -0
  30. package/dist/assets/{PublicFormsPage-DlE6tck_.js → PublicFormsPage-D3AT2EH9.js} +1 -1
  31. package/dist/assets/RecordDetailView-B3XBEgk2.js +3 -0
  32. package/dist/assets/RecordFormPage-CcoZfUJ3.js +1 -0
  33. package/dist/assets/ReportDefaultInspector-DVcWM6sh.js +1 -0
  34. package/dist/assets/ReportView-pJCFptzp.js +2 -0
  35. package/dist/assets/RuntimeDraftBar-DObTyFu2.js +1 -0
  36. package/dist/assets/SchemaForm-BWSWYMLE.js +3 -0
  37. package/dist/assets/SearchResultsPage-ChVIzFob.js +1 -0
  38. package/dist/assets/{SettingsHub-BGKIj-Zq.js → SettingsHub-CPP9FDe8.js} +1 -1
  39. package/dist/assets/SettingsView-CrHAROu9.js +1 -0
  40. package/dist/assets/{SkeletonDetail-C8fMI-Mu.js → SkeletonDetail-CP-35B8x.js} +1 -1
  41. package/dist/assets/{af-BfSmLD34.js → af-Bhbso4Pg.js} +1 -1
  42. package/dist/assets/ai-BAPiCsNk.js +3 -0
  43. package/dist/assets/app-shell-eager-leaves-D9tgfJOe.js +1 -0
  44. package/dist/assets/{ar-B9ttrM75.js → ar-DG8TAFtm.js} +1 -1
  45. package/dist/assets/{ar-DZ-C1rn-cyl.js → ar-DZ-BtSien-d.js} +1 -1
  46. package/dist/assets/{ar-EG-BaDxKP_o.js → ar-EG-DpXC0zoY.js} +1 -1
  47. package/dist/assets/{ar-MA-DbxNEcmd.js → ar-MA-D1qVJLyE.js} +1 -1
  48. package/dist/assets/{ar-SA-DeC5LXcX.js → ar-SA-BIYKNgv8.js} +1 -1
  49. package/dist/assets/{ar-TN-C9KpTFJz.js → ar-TN-mUR5Mq3s.js} +1 -1
  50. package/dist/assets/{az-cMerDwRO.js → az-B7IqwHGK.js} +1 -1
  51. package/dist/assets/{be-ZTSbszQh.js → be-CnZyPaSX.js} +1 -1
  52. package/dist/assets/{be-tarask-BXZEUrgX.js → be-tarask--uMMCC7l.js} +1 -1
  53. package/dist/assets/{bg-BDogpmn5.js → bg-CZwuirtY.js} +1 -1
  54. package/dist/assets/{bn-Cz04uxmh.js → bn-BbOX0r-z.js} +1 -1
  55. package/dist/assets/{bs-CpFnCl-j.js → bs-B5W75cYR.js} +1 -1
  56. package/dist/assets/{ca-CHC4M52Z.js → ca-Be69LdIM.js} +1 -1
  57. package/dist/assets/{ckb-Dxw-RNm8.js → ckb-B-nKM1Vn.js} +1 -1
  58. package/dist/assets/contracts-DieHW666.js +1 -0
  59. package/dist/assets/{createDerive-DvA_JGNq.js → createDerive-CynsXU-B.js} +1 -1
  60. package/dist/assets/{cs-DsFaJ5Z7.js → cs-qHngxH7l.js} +1 -1
  61. package/dist/assets/{cy-FH4JFDTs.js → cy-DscO2Pgf.js} +1 -1
  62. package/dist/assets/{da-D1pVjaAq.js → da-vibkaLMF.js} +1 -1
  63. package/dist/assets/data-adapter-BDsrq0TX.js +2 -0
  64. package/dist/assets/{de-AT-DUMQCisj.js → de-AT--JneEuBw.js} +1 -1
  65. package/dist/assets/{de-DKrxSvnP.js → de-BCT78XYW.js} +1 -1
  66. package/dist/assets/default-inspector-registry-Dktr6x_q.js +1 -0
  67. package/dist/assets/dist-yh3dYtHt.js +14 -0
  68. package/dist/assets/drillUrlFilters-N0RngQg6.js +1 -0
  69. package/dist/assets/{el-l3-bHySV.js → el-Cl0y9T2b.js} +1 -1
  70. package/dist/assets/en-AU-By42tTB7.js +1 -0
  71. package/dist/assets/{en-CA-DGH5NF0a.js → en-CA-BqEEoj-Y.js} +1 -1
  72. package/dist/assets/en-GB-Cx8B9nkB.js +1 -0
  73. package/dist/assets/en-IE-CX9nv6uO.js +1 -0
  74. package/dist/assets/en-IN-ByGSBHa4.js +1 -0
  75. package/dist/assets/en-NZ-BPMwa2ZN.js +1 -0
  76. package/dist/assets/en-ZA-lj_N4R6c.js +1 -0
  77. package/dist/assets/{eo-CL6CXHZx.js → eo-oOXROuhF.js} +1 -1
  78. package/dist/assets/{es-BIJ0rksI.js → es-EudscwjH.js} +1 -1
  79. package/dist/assets/{et-BGgMzjm1.js → et-CB-5LLh6.js} +1 -1
  80. package/dist/assets/{eu-CqvAoRrX.js → eu-B4-hcseX.js} +1 -1
  81. package/dist/assets/{fa-IR-DNz3oA1-.js → fa-IR-CogavcMJ.js} +1 -1
  82. package/dist/assets/{fi-DNSfKWuW.js → fi-CIBE0mYa.js} +1 -1
  83. package/dist/assets/{formatLong-CHb9WA3O.js → formatLong-qqgm7lV1.js} +1 -1
  84. package/dist/assets/{fr-CA-CotiswPx.js → fr-CA-BugXMutW.js} +1 -1
  85. package/dist/assets/{fr-DYRJCirJ.js → fr-CDReXYWW.js} +1 -1
  86. package/dist/assets/{fr-CH-CpiEYWpc.js → fr-CH-fiTiB6X1.js} +1 -1
  87. package/dist/assets/framework-CAuH4h0L.js +35 -0
  88. package/dist/assets/{fy-B69yM3FE.js → fy-t_GzIAg_.js} +1 -1
  89. package/dist/assets/{gd-BAy8AsX6.js → gd-CSncIxtN.js} +1 -1
  90. package/dist/assets/{getIcon-BEVyC4y3.js → getIcon-BDkBRQFw.js} +1 -1
  91. package/dist/assets/{gl-soLn_weL.js → gl-_138Mj2S.js} +1 -1
  92. package/dist/assets/{gu-B19Yo9yC.js → gu-COfH-YUT.js} +1 -1
  93. package/dist/assets/{he-DYTPo33p.js → he-BXL4lOKY.js} +1 -1
  94. package/dist/assets/{hi-D2dIK7Oy.js → hi-kXuYI0TJ.js} +1 -1
  95. package/dist/assets/{highlighted-body-OFNGDK62-CExufvVt.js → highlighted-body-OFNGDK62-CK7x7Gzm.js} +1 -1
  96. package/dist/assets/{hr-BV-VOPMu.js → hr-DAOsQWzI.js} +1 -1
  97. package/dist/assets/{ht-C7MM4qkS.js → ht-Ch8SKz8p.js} +1 -1
  98. package/dist/assets/{hu-Rha1m2Ym.js → hu-q6W_rWPT.js} +1 -1
  99. package/dist/assets/{hy-CiTNgbdV.js → hy-0M8OmwnM.js} +1 -1
  100. package/dist/assets/i18n-DTfZonAM.js +17 -0
  101. package/dist/assets/i18n-locale-ar-O6rs-Cir.js +4 -0
  102. package/dist/assets/i18n-locale-de-CMc1jk4a.js +4 -0
  103. package/dist/assets/i18n-locale-en-CbRQO81h.js +4 -0
  104. package/dist/assets/i18n-locale-es-t47nyoCX.js +4 -0
  105. package/dist/assets/i18n-locale-fr-E425EqJM.js +4 -0
  106. package/dist/assets/i18n-locale-ja-y_fk77fz.js +4 -0
  107. package/dist/assets/i18n-locale-ko-CdnY2uCg.js +4 -0
  108. package/dist/assets/i18n-locale-pt-BaUOXS6y.js +4 -0
  109. package/dist/assets/i18n-locale-ru-pFlhX9wg.js +4 -0
  110. package/dist/assets/i18n-locale-zh-Dkj4ROTN.js +4 -0
  111. package/dist/assets/i18n-runtime-CdWyaiOD.js +1 -0
  112. package/dist/assets/{id-Cijsfjt-.js → id-BM_H1_jv.js} +1 -1
  113. package/dist/assets/index-ocmkyCt6.js +19 -0
  114. package/dist/assets/index-v2Ijn9Gr.css +2 -0
  115. package/dist/assets/{infrastructure-BHSync5f.js → infrastructure-CSnL6ntj.js} +2 -2
  116. package/dist/assets/integration-7NqwVHuJ.js +1 -0
  117. package/dist/assets/{is-xS1WTyeC.js → is-B_7jXZfS.js} +1 -1
  118. package/dist/assets/isSameWeek-D90tBsli.js +1 -0
  119. package/dist/assets/{it-C2i_c9sd.js → it-CBM0J9cD.js} +1 -1
  120. package/dist/assets/{it-CH-l516ZNXj.js → it-CH-BQltCNsR.js} +1 -1
  121. package/dist/assets/{ja-D9_ewLny.js → ja-DBjnsx21.js} +1 -1
  122. package/dist/assets/{ja-Hira-D_6ExgHw.js → ja-Hira-BZfSmj1i.js} +1 -1
  123. package/dist/assets/{ka-BYHGyees.js → ka-HwpuKgUY.js} +1 -1
  124. package/dist/assets/{kk-CbTFtuqb.js → kk-DLKA9paj.js} +1 -1
  125. package/dist/assets/{km-Dr2gwhIn.js → km-BU5kermq.js} +1 -1
  126. package/dist/assets/{kn-CprH8JD7.js → kn-BNFqbCoi.js} +1 -1
  127. package/dist/assets/{ko-CsFS2u5i.js → ko-D8n4uMqQ.js} +1 -1
  128. package/dist/assets/{lb-CbFKN7Ob.js → lb-B1empQ7m.js} +1 -1
  129. package/dist/assets/{lt-Bq0xkLp0.js → lt-gMukpK3G.js} +1 -1
  130. package/dist/assets/{lv-Cj6vg6Qo.js → lv-D2O5AnsZ.js} +1 -1
  131. package/dist/assets/{match-CiPp9BME.js → match-BTF6WqJh.js} +1 -1
  132. package/dist/assets/{match-C_jFGO9e.js → match-Cyum2eeW.js} +1 -1
  133. package/dist/assets/{match-Co4ivumx.js → match-ScHH8kYk.js} +1 -1
  134. package/dist/assets/mermaid-GHXKKRXX-D4H6EVJQ.js +1 -0
  135. package/dist/assets/metadata-admin-CEhVmXFv.js +9 -0
  136. package/dist/assets/{mk-MXFM99YL.js → mk-D-Zl0xVN.js} +1 -1
  137. package/dist/assets/{mn-D5Q9B6Jt.js → mn-jJbTslgD.js} +1 -1
  138. package/dist/assets/{ms-CCzPRldx.js → ms-CUuJHLA4.js} +1 -1
  139. package/dist/assets/{mt-mjJpN6xW.js → mt-yIcbfxKY.js} +1 -1
  140. package/dist/assets/{nb-BIlNqdEb.js → nb-D9WNypoj.js} +1 -1
  141. package/dist/assets/{nl-BE-FwXjQsmV.js → nl-BE-B1vKiw2h.js} +1 -1
  142. package/dist/assets/{nl-D2uBtIxG.js → nl-DC7b5e90.js} +1 -1
  143. package/dist/assets/{nn-B0loJ7SV.js → nn-uP4yJ9s0.js} +1 -1
  144. package/dist/assets/{oc-U7-yH1sO.js → oc-DHTqadJI.js} +1 -1
  145. package/dist/assets/{pl-mTy0JYgi.js → pl-Bxnnizf5.js} +1 -1
  146. package/dist/assets/plugin-calendar-b7C35ANT.js +1 -0
  147. package/dist/assets/plugin-charts-b-yVtmdI.js +7 -0
  148. package/dist/assets/plugin-chatbot-D1KW_oIO.js +122 -0
  149. package/dist/assets/plugin-dashboard-DTkPoPEb.js +6 -0
  150. package/dist/assets/plugin-form-UIRm-FpQ.js +1 -0
  151. package/dist/assets/plugin-gantt-9dtc8zzX.js +63 -0
  152. package/dist/assets/plugin-grid-Cp4RKtMJ.js +10 -0
  153. package/dist/assets/plugin-kanban-B2JOPZIJ.js +1 -0
  154. package/dist/assets/plugin-map-CBJcVJYk.js +1 -0
  155. package/dist/assets/{plugin-markdown-D1nTQc1T.js → plugin-markdown-CNlDzqP-.js} +1 -1
  156. package/dist/assets/plugin-report-IZzgQb-Q.js +59 -0
  157. package/dist/assets/plugin-timeline-DsmtjcJ3.js +1 -0
  158. package/dist/assets/plugin-tree-DTRPBdhe.js +1 -0
  159. package/dist/assets/plugin-view-D9ixsNDG.js +1 -0
  160. package/dist/assets/plugins-views-CnvkdSJK.js +3 -0
  161. package/dist/assets/{pt-BR-2KtO5Js1.js → pt-BR-D416seHT.js} +1 -1
  162. package/dist/assets/{pt-Bet5OOQf.js → pt-DwHBy9_c.js} +1 -1
  163. package/dist/assets/{ro-37U6sgzi.js → ro-DDf1X3Np.js} +1 -1
  164. package/dist/assets/{ru-CyuAY-5E.js → ru-8eM3mcgK.js} +1 -1
  165. package/dist/assets/{runtime-metadata-persistence-afAW-MeD.js → runtime-metadata-persistence-DX29lQ62.js} +1 -1
  166. package/dist/assets/{se-DeJabuC6.js → se-D4JvQeRX.js} +1 -1
  167. package/dist/assets/{sk-DWEpjfkR.js → sk-DvpgttGI.js} +1 -1
  168. package/dist/assets/{sl-4oSvNhIR.js → sl-B3gCZ-_a.js} +1 -1
  169. package/dist/assets/{sq-BjkBCaXW.js → sq-CVaTmL0V.js} +1 -1
  170. package/dist/assets/{sr-Dxm1DsRS.js → sr-CnH5Ffyz.js} +1 -1
  171. package/dist/assets/{sr-Latn-Dawg6oP2.js → sr-Latn-Dw9w61q6.js} +1 -1
  172. package/dist/assets/src-BUry7633.js +2 -0
  173. package/dist/assets/{src-C8NYjdVm.js → src-DMDT5a27.js} +1 -1
  174. package/dist/assets/src-ZxH3AOCu.js +16 -0
  175. package/dist/assets/{studioEntry-nXQP3iL0.js → studioEntry-DAqcBFtr.js} +1 -1
  176. package/dist/assets/{submitRedirect-jK-cEIbP.js → submitRedirect-iy0oOi7I.js} +1 -1
  177. package/dist/assets/{sv-CROOGJGz.js → sv-CU7wdxyK.js} +1 -1
  178. package/dist/assets/{ta-BZnTmFI_.js → ta-DPH6q0HR.js} +1 -1
  179. package/dist/assets/{te-BN0v0x5t.js → te-BSaThkGV.js} +1 -1
  180. package/dist/assets/{th-CBjKhp_U.js → th-NXP8_Qb8.js} +1 -1
  181. package/dist/assets/{tr-x0Ne4N4H.js → tr-DDXoH663.js} +1 -1
  182. package/dist/assets/types-zod-ChJ30y25.js +1 -0
  183. package/dist/assets/{ug-sgzNhsKo.js → ug-Guus6pPe.js} +1 -1
  184. package/dist/assets/ui-components-D8wcRNrt.js +37 -0
  185. package/dist/assets/ui-layout-BYO3rRIl.js +1 -0
  186. package/dist/assets/{uk-o_DQ5VHJ.js → uk-uiy4vsp8.js} +1 -1
  187. package/dist/assets/use-book-data-DFTswcKm.js +1 -0
  188. package/dist/assets/{useActionModal-CSvbHkQ7.js → useActionModal-h52Z5Pkl.js} +1 -1
  189. package/dist/assets/useCanAuthorMetadata-TDrVrYGB.js +1 -0
  190. package/dist/assets/useDatasetCatalog-BOd0Ybr1.js +1 -0
  191. package/dist/assets/useNavSelDeepLink-67Y4qCNO.js +1 -0
  192. package/dist/assets/useNavTargetLabel-D8lRdb6O.js +1 -0
  193. package/dist/assets/useOpenRecordList-C7oqUD3F.js +1 -0
  194. package/dist/assets/{usePackageL10n-CMx66am-.js → usePackageL10n-Jl2XiF2F.js} +1 -1
  195. package/dist/assets/{useSettingsLabel-Kkr2q0Oo.js → useSettingsLabel-CSpBDTdy.js} +1 -1
  196. package/dist/assets/{uz-Cyrl-DbtkQtz_.js → uz-Cyrl-Cmb5bvbf.js} +1 -1
  197. package/dist/assets/{uz-Be41d4jl.js → uz-DJWxoTz4.js} +1 -1
  198. package/dist/assets/vendor-objectstack-C4eD5dbT.js +139 -0
  199. package/dist/assets/{vi-84mZmklk.js → vi-Bb3QoIJC.js} +1 -1
  200. package/dist/assets/{zh-CN-DD1reegJ.js → zh-CN-C-Hts1ZR.js} +1 -1
  201. package/dist/assets/{zh-HK-B05u30WI.js → zh-HK-CtBAZ_ZS.js} +1 -1
  202. package/dist/assets/{zh-TW-Bb-WimPD.js → zh-TW-B7DDahD-.js} +1 -1
  203. package/dist/chunk-membership.json +116 -104
  204. package/dist/eager-closure.json +126 -120
  205. package/dist/index.html +4 -4
  206. package/dist/sdui.manifest.json +998 -115
  207. package/package.json +1 -1
  208. package/dist/assets/AppDocsIndex-F4zDq2zz.js +0 -1
  209. package/dist/assets/ApprovalsInboxPage-DrEUmaDb.js +0 -1
  210. package/dist/assets/CreateViewDialog-xyKlpLEW.js +0 -1
  211. package/dist/assets/DashboardView-CGC-_Om8.js +0 -1
  212. package/dist/assets/DocPage-CIZE5kdj.js +0 -1
  213. package/dist/assets/DocsSlug-DXdFdwlS.js +0 -1
  214. package/dist/assets/ExpressionProvider-DZfMwyMs.js +0 -1
  215. package/dist/assets/FlowRunsPage-CvY3nJMF.js +0 -1
  216. package/dist/assets/InterfaceListPage-BdECC_i3.js +0 -1
  217. package/dist/assets/MarketplacePackagePage-C7NOu2Ir.js +0 -4
  218. package/dist/assets/ObjectDataPage-BIzp65Mo.js +0 -1
  219. package/dist/assets/PageView-CVLgCRSF.js +0 -1
  220. package/dist/assets/ProfilePage-D2qGgxPK.js +0 -1
  221. package/dist/assets/RecordDetailView-DQKydU7X.js +0 -3
  222. package/dist/assets/RecordFormPage-BTjwxJIA.js +0 -1
  223. package/dist/assets/ReportDefaultInspector-DdsQAkd7.js +0 -1
  224. package/dist/assets/ReportView-GIdKJdOt.js +0 -2
  225. package/dist/assets/RuntimeDraftBar-BbMdi3Kp.js +0 -1
  226. package/dist/assets/SchemaForm-C8X1ve4p.js +0 -3
  227. package/dist/assets/SearchResultsPage-Jwhqsdyo.js +0 -1
  228. package/dist/assets/SettingsView-D8SMKdrc.js +0 -1
  229. package/dist/assets/app-shell-eager-leaves-CDVclng4.js +0 -1
  230. package/dist/assets/appRoute-DbnWDEa1.js +0 -1
  231. package/dist/assets/data-adapter-DMbe6Njk.js +0 -1
  232. package/dist/assets/default-inspector-registry-CpL3fFhl.js +0 -1
  233. package/dist/assets/dist-BXrEV1ag.js +0 -13
  234. package/dist/assets/drillUrlFilters-hi-2d3DW.js +0 -1
  235. package/dist/assets/en-AU-C6x7mDhH.js +0 -1
  236. package/dist/assets/en-GB-0-nho2eK.js +0 -1
  237. package/dist/assets/en-IE-2fC3BkfV.js +0 -1
  238. package/dist/assets/en-IN-C1QcFhxn.js +0 -1
  239. package/dist/assets/en-NZ-C80ptZT7.js +0 -1
  240. package/dist/assets/en-ZA-ByZDrjeb.js +0 -1
  241. package/dist/assets/framework-DcWkeiND.js +0 -35
  242. package/dist/assets/i18n-CEKxYdmD.js +0 -9
  243. package/dist/assets/i18n-locale-ar-DN7sl3GF.js +0 -4
  244. package/dist/assets/i18n-locale-de-C40JErvb.js +0 -4
  245. package/dist/assets/i18n-locale-en-CITPDIHy.js +0 -4
  246. package/dist/assets/i18n-locale-es-C8DdWN6c.js +0 -4
  247. package/dist/assets/i18n-locale-fr-COIdEZZl.js +0 -4
  248. package/dist/assets/i18n-locale-ja-DYF_rU_s.js +0 -4
  249. package/dist/assets/i18n-locale-ko-B-ODYAtX.js +0 -4
  250. package/dist/assets/i18n-locale-pt-CK1SyBIm.js +0 -4
  251. package/dist/assets/i18n-locale-ru-jLzvShMO.js +0 -4
  252. package/dist/assets/i18n-locale-zh-Bf9Gbbvl.js +0 -4
  253. package/dist/assets/i18n-runtime-CTgAQF4N.js +0 -1
  254. package/dist/assets/index-CLyvpiGc.css +0 -2
  255. package/dist/assets/index-CfnfGw5W.js +0 -20
  256. package/dist/assets/isSameWeek-DWYeNyh8.js +0 -1
  257. package/dist/assets/mermaid-GHXKKRXX-DVLc_uym.js +0 -1
  258. package/dist/assets/metadata-admin-CybaOCdO.js +0 -9
  259. package/dist/assets/nav-selection-Dzm_mA3C.js +0 -1
  260. package/dist/assets/plugin-calendar-CKRBcML7.js +0 -1
  261. package/dist/assets/plugin-charts-DGTJxXCB.js +0 -7
  262. package/dist/assets/plugin-chatbot-DwtwNA-y.js +0 -122
  263. package/dist/assets/plugin-dashboard-C1AYKmGX.js +0 -6
  264. package/dist/assets/plugin-form-CV8ZY04-.js +0 -1
  265. package/dist/assets/plugin-gantt-BRIb2_8G.js +0 -63
  266. package/dist/assets/plugin-grid-C9h7mRVv.js +0 -11
  267. package/dist/assets/plugin-kanban-BcJ0Dhys.js +0 -1
  268. package/dist/assets/plugin-map-D24ZUOUj.js +0 -1
  269. package/dist/assets/plugin-report-BfGintAq.js +0 -59
  270. package/dist/assets/plugin-timeline-CbBRq_qt.js +0 -1
  271. package/dist/assets/plugin-tree-BNX2A5J5.js +0 -1
  272. package/dist/assets/plugin-view-DzWQWYyH.js +0 -1
  273. package/dist/assets/plugins-views-DraK4xz0.js +0 -3
  274. package/dist/assets/src-B8lv0plz.js +0 -18
  275. package/dist/assets/src-DoDvT77T.js +0 -1
  276. package/dist/assets/types-zod-Y2RwUUeJ.js +0 -1
  277. package/dist/assets/ui-components-BTB1NkUW.js +0 -37
  278. package/dist/assets/ui-layout-bZfafwJa.js +0 -1
  279. package/dist/assets/use-book-data-C3eyZJSG.js +0 -1
  280. package/dist/assets/useOpenRecordList-B5-qaFUx.js +0 -1
  281. package/dist/assets/vendor-objectstack-XuWC71M9.js +0 -266
  282. package/dist/assets/vendor-zod-CHLW1iCr.js +0 -64
@@ -0,0 +1,19 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css","./plugin-map-PxdK6UrK.css"])))=>i.map(i=>d[i]);
2
+ import{o as e}from"./rolldown-runtime-C0FnF6B9.js";import{a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,u as g,v as _}from"./vendor-react-BggL7APJ.js";import{_ as v,a as y,c as b,d as x,f as S,g as C,h as w,i as T,l as E,m as D,n as O,o as k,p as A,r as j,s as M,t as N,u as ee,v as P}from"./infrastructure-CSnL6ntj.js";import{Br as F,I as te,Ki as I,Oi as ne,Zi as re,_n as L,aa as ie,it as ae,oa as oe,sa as R,ta as se,vn as ce,xn as le}from"./vendor-objectstack-C4eD5dbT.js";import{$n as z,$t as ue,An as de,Ar as fe,At as pe,Bn as B,Di as me,Dr as he,Dt as ge,Ei as _e,Er as V,Et as ve,Fn as H,Fr as U,G as ye,Gr as be,Hn as xe,Hr as W,In as Se,Ir as Ce,Jn as we,Kn as Te,L as Ee,Ln as De,Lt as Oe,Mn as ke,Mr as Ae,Nn as je,Nr as Me,Or as Ne,Pn as G,Pr as Pe,Qt as Fe,Rn as Ie,Si as Le,Sn as Re,Ti as ze,Tr as Be,Ur as Ve,Vn as He,Vr as Ue,Wr as We,Yn as K,_ as Ge,_i as Ke,ai as qe,ar as Je,at as Ye,b as Xe,bi as q,bn as Ze,bt as Qe,cn as $e,ct as et,di as tt,dn as nt,en as rt,er as it,et as at,f as ot,fi as st,fn as ct,gi as lt,gn as ut,hi as dt,hn as ft,ii as pt,ir as mt,jn as ht,jr as gt,kn as _t,kr as vt,lr as yt,mi as bt,mn as xt,nr as St,nt as Ct,oi as wt,ot as Tt,pi as Et,pn as Dt,qn as Ot,rr as kt,si as At,st as jt,t as Mt,tn as Nt,tr as Pt,tt as Ft,un as It,ut as Lt,vi as Rt,wn as zt,wr as Bt,xn as Vt,yn as Ht,yt as Ut,zn as Wt}from"./ui-components-D8wcRNrt.js";import{E as Gt,Fi as Kt,Fr as qt,Ft as Jt,G as Yt,Gi as Xt,H as Zt,Ir as Qt,It as $t,Jr as en,O as tn,P as nn,Qi as rn,T as an,Ti as on,U as sn,Un as cn,Vt as ln,W as un,Wt as dn,Xi as fn,Y as pn,Yi as mn,Z as hn,Zi as gn,_ as _n,_i as vn,b as yn,bi as bn,ct as xn,di as Sn,dr as Cn,fi as wn,ft as Tn,gi as En,gt as Dn,h as On,hi as kn,ii as An,k as jn,kt as Mn,mn as Nn,nt as Pn,o as Fn,st as In,ta as Ln,tn as Rn,tr as zn,ut as Bn,v as Vn,vi as Hn}from"./framework-CAuH4h0L.js";import{t as Un}from"./i18n-locale-en-CbRQO81h.js";import{C as Wn,S as Gn,T as Kn,_ as qn,b as Jn,c as Yn,f as Xn,g as Zn,l as Qn,p as $n,r as er,t as tr,u as nr,v as rr,w as J,x as ir,y as ar}from"./i18n-runtime-CdWyaiOD.js";import{a as or,c as sr,i as cr,o as lr,r as ur,s as dr,t as fr}from"./data-adapter-BDsrq0TX.js";import{n as pr,r as Y}from"./vendor-ui-utils-DIUdEYii.js";import{t as mr}from"./vendor-icon-activity-CkniytwY.js";import{t as hr}from"./vendor-icon-arrow-left-DmGEbpkA.js";import{t as gr}from"./vendor-icon-arrow-right-RqsZZ458.js";import{t as _r}from"./vendor-icon-arrow-up-right-BQsRTUUI.js";import{t as vr}from"./vendor-icon-ban-BptIEC14.js";import{t as yr}from"./vendor-icon-bell-6t8He8Wt.js";import{t as br}from"./vendor-icon-book-open-DKPXYwQK.js";import{t as xr}from"./vendor-icon-bot-B9KkwkON.js";import{t as Sr}from"./vendor-icon-boxes-D-Ov3dJw.js";import{t as Cr}from"./vendor-icon-bug-BdoY1KRy.js";import{t as wr}from"./vendor-icon-building-2-GgGvlXZt.js";import{t as Tr}from"./vendor-icon-calendar-BsoUBIef.js";import{t as Er}from"./vendor-icon-chart-column-DicJIApF.js";import{t as Dr}from"./vendor-icon-chart-no-axes-gantt-_tk8gYAt.js";import{t as Or}from"./vendor-icon-check-check-lFjYh3sO.js";import{t as kr}from"./vendor-icon-check-vpu9Zukp.js";import{t as Ar}from"./vendor-icon-chevron-down-BEf_jTEE.js";import{t as jr}from"./vendor-icon-chevron-right-DbnKwHYQ.js";import{t as Mr}from"./vendor-icon-chevron-up-C-6o_0je.js";import{t as Nr}from"./vendor-icon-chevrons-up-down-CbDukqtA.js";import{t as Pr}from"./vendor-icon-circle-alert-D1XTr_X9.js";import{t as Fr}from"./vendor-icon-circle-check-big-MHBAycKk.js";import{t as Ir}from"./vendor-icon-circle-check-Bq3OcFQN.js";import{t as Lr}from"./vendor-icon-circle-question-mark-LshNGnQH.js";import{t as Rr}from"./vendor-icon-circle-slash-Cfaa-djL.js";import{t as zr}from"./vendor-icon-circle-x-Nkh1Yr7N.js";import{t as Br}from"./vendor-icon-clock-CTLnah0r.js";import{t as Vr}from"./vendor-icon-cloud-upload-Bg3lE2SH.js";import{t as Hr}from"./vendor-icon-code-xml-C9EWHSC8.js";import{t as Ur}from"./vendor-icon-compass-CXq7Xl5b.js";import{t as Wr}from"./vendor-icon-copy-B5M-KdZo.js";import{t as Gr}from"./vendor-icon-database-C8JGjSkn.js";import{t as Kr}from"./vendor-icon-download-C3csYSaD.js";import{t as qr}from"./vendor-icon-ellipsis-BjiiCS3N.js";import{t as Jr}from"./vendor-icon-external-link-SBKz5x6R.js";import{t as Yr}from"./vendor-icon-eye-off-Dy3GIcvl.js";import{t as Xr}from"./vendor-icon-eye-C3HaEGOo.js";import{t as Zr}from"./vendor-icon-file-pen-l-DSznsL.js";import{t as Qr}from"./vendor-icon-file-plus-corner-qwq-iw5D.js";import{t as $r}from"./vendor-icon-file-text-7BKAVNof.js";import{t as ei}from"./vendor-icon-file-CTChzdTZ.js";import{t as ti}from"./vendor-icon-folder-GbhohOfU.js";import{t as ni}from"./vendor-icon-git-branch-CpQpJlYB.js";import{t as ri}from"./vendor-icon-git-compare-arrows-BAqrva2j.js";import{t as ii}from"./vendor-icon-globe-BaOanPH5.js";import{t as ai}from"./vendor-icon-grip-vertical-B01-ovq0.js";import{t as oi}from"./vendor-icon-hammer-Dt0J1nzU.js";import{t as si}from"./vendor-icon-hard-drive-DhSx4UAI.js";import{t as ci}from"./vendor-icon-house-DKkSNU01.js";import{t as li}from"./vendor-icon-info-DBwRTfSE.js";import{t as ui}from"./vendor-icon-key-round-hQwGYgPA.js";import{t as di}from"./vendor-icon-keyboard-D_x9_32f.js";import{t as fi}from"./vendor-icon-layers-DXBEefR1.js";import{t as pi}from"./vendor-icon-layout-dashboard-wba2hvZp.js";import{t as mi}from"./vendor-icon-layout-grid-B3quJ1GF.js";import{t as hi}from"./vendor-icon-layout-template-BSsyv3fX.js";import{t as gi}from"./vendor-icon-link-2-EAo0juhN.js";import{t as X}from"./vendor-icon-loader-circle-D3PsuVaD.js";import{t as _i}from"./vendor-icon-lock-B_psRnly.js";import{t as vi}from"./vendor-icon-log-out-CecmgsZQ.js";import{t as yi}from"./vendor-icon-mail-check-D2N7yV1m.js";import{t as bi}from"./vendor-icon-mail-BfkRvgNr.js";import{t as xi}from"./vendor-icon-map-pin-BS-hHv53.js";import{t as Si}from"./vendor-icon-maximize-2-C215UtMO.js";import{t as Ci}from"./vendor-icon-menu-9YHQR0RT.js";import{t as wi}from"./vendor-icon-message-square-text-DuNOT3Hq.js";import{t as Ti}from"./vendor-icon-message-square-BObk9Jes.js";import{t as Ei}from"./vendor-icon-messages-square-C3r_dZCQ.js";import{t as Di}from"./vendor-icon-monitor-C4Tawzob.js";import{t as Oi}from"./vendor-icon-moon-C1ZitaV0.js";import{t as ki}from"./vendor-icon-mouse-pointer-2-BK7MBFPs.js";import{t as Ai}from"./vendor-icon-octagon-x-DJaJymPi.js";import{t as ji}from"./vendor-icon-package-B6zAlWd3.js";import{t as Mi}from"./vendor-icon-panel-left-close-CrofkR7D.js";import{t as Ni}from"./vendor-icon-panel-left-open-DXRZV0DR.js";import{t as Pi}from"./vendor-icon-panel-left-Cml87N0K.js";import{t as Fi}from"./vendor-icon-panel-right-close-B1IgPiA5.js";import{t as Ii}from"./vendor-icon-panel-right-open-DRcsA0VE.js";import{t as Li}from"./vendor-icon-pencil-CMubUBjW.js";import{t as Ri}from"./vendor-icon-plus-BlfcDDsa.js";import{t as zi}from"./vendor-icon-refresh-cw-BGjSPEfJ.js";import{t as Bi}from"./vendor-icon-rocket-9sBBTCrW.js";import{t as Vi}from"./vendor-icon-rotate-ccw-clock-DyTX5-aX.js";import{t as Hi}from"./vendor-icon-rotate-ccw-lr5YKsxC.js";import{t as Ui}from"./vendor-icon-rows-3-Bl0iGPg_.js";import{t as Wi}from"./vendor-icon-save-CuavGNuU.js";import{t as Gi}from"./vendor-icon-search-B2Uqtp_W.js";import{t as Ki}from"./vendor-icon-settings-2-BHIWdy1J.js";import{t as qi}from"./vendor-icon-settings-CYQ7xc_F.js";import{t as Ji}from"./vendor-icon-share-2-D3bdPyHy.js";import{t as Yi}from"./vendor-icon-shield-alert-CJYtPI9w.js";import{t as Xi}from"./vendor-icon-shield-check-CdDzbial.js";import{t as Zi}from"./vendor-icon-shield-question-mark-CmNmL1kO.js";import{t as Qi}from"./vendor-icon-shield-DsNraEeY.js";import{t as $i}from"./vendor-icon-sliders-horizontal-BsnKXU0c.js";import{t as ea}from"./vendor-icon-sparkles-RGpJ39Rc.js";import{t as ta}from"./vendor-icon-square-check-big-B4UVzWzR.js";import{t as na}from"./vendor-icon-square-kanban-ZFRnbY0T.js";import{t as ra}from"./vendor-icon-star-off-C_igmr5w.js";import{t as ia}from"./vendor-icon-star-DfusowFE.js";import{t as aa}from"./vendor-icon-sun-D1JMEG8e.js";import{t as oa}from"./vendor-icon-table-2-DMQ6UahM.js";import{t as sa}from"./vendor-icon-table-CeQhi8NL.js";import{t as ca}from"./vendor-icon-toggle-right-55ersX99.js";import{t as la}from"./vendor-icon-trash-BLsWkwB9.js";import{t as ua}from"./vendor-icon-triangle-alert-D5n0T3q_.js";import{t as da}from"./vendor-icon-undo-2-C9MbW2Vb.js";import{t as fa}from"./vendor-icon-upload-BZ3rElxe.js";import{t as pa}from"./vendor-icon-user-cog-CxEO2E4A.js";import{t as ma}from"./vendor-icon-user-minus-BDwGdstz.js";import{t as ha}from"./vendor-icon-user-IWwlLQut.js";import{t as ga}from"./vendor-icon-users-Db5uTXC8.js";import{t as _a}from"./vendor-icon-webhook-B43SyK1w.js";import{t as va}from"./vendor-icon-wifi-off-BnMfEHbG.js";import{t as ya}from"./vendor-icon-workflow-B9ASq0nN.js";import{t as ba}from"./vendor-icon-x-CcLtgRNL.js";import{t as xa}from"./vendor-icon-zap-3ulAPCbu.js";import{c as Sa,d as Ca,f as wa,l as Ta,m as Ea,o as Da,p as Oa,s as ka,u as Aa}from"./createDerive-CynsXU-B.js";import{a as ja,c as Ma,l as Na,n as Pa,o as Fa,r as Ia,s as La,t as Ra}from"./plugin-form-UIRm-FpQ.js";import{a as za,i as Ba,r as Va,t as Ha}from"./assistantBus-DoNtw1Tf.js";import{a as Ua,i as Wa,n as Ga,o as Ka,r as qa,t as Ja}from"./ExpressionProvider-Dr0e99r1.js";import{t as Ya}from"./expressionUser-CASszt1z.js";import{c as Xa,d as Za,n as Qa,o as $a,s as eo}from"./ActionResultDialog-ChYnuROr.js";import{A as to,C as no,D as ro,E as io,O as ao,S as oo,T as so,_ as co,a as lo,b as uo,c as fo,d as po,f as mo,g as ho,h as go,i as _o,k as vo,l as yo,m as bo,n as xo,o as So,p as Co,r as wo,s as To,t as Eo,u as Do,v as Oo,w as ko,x as Ao,y as jo}from"./src-ZxH3AOCu.js";import{a as Mo,i as No,o as Po,r as Fo,s as Io,t as Lo}from"./useActionModal-h52Z5Pkl.js";import{C as Ro,D as zo,E as Bo,S as Vo,T as Ho,_ as Uo,b as Wo,c as Go,d as Ko,f as qo,g as Jo,h as Yo,l as Xo,m as Zo,o as Qo,p as $o,s as es,t as ts,u as ns,v as rs,x as is}from"./RecordDetailView-B3XBEgk2.js";import{a as as,i as os,n as ss,o as cs,r as ls,s as us,t as ds}from"./useNavTargetLabel-D8lRdb6O.js";import{A as fs,C as ps,D as ms,E as hs,O as gs,S as _s,T as vs,_ as ys,b as bs,d as xs,f as Ss,g as Cs,h as ws,i as Ts,k as Es,l as Ds,m as Os,p as ks,r as As,t as js,u as Ms,v as Ns,w as Ps,x as Fs,y as Is}from"./plugin-chatbot-D1KW_oIO.js";import{A as Ls,C as Rs,D as zs,E as Bs,M as Vs,N as Hs,O as Us,S as Ws,T as Gs,b as Ks,i as qs,j as Js,k as Ys,n as Xs,w as Zs,x as Qs}from"./app-shell-eager-leaves-D9tgfJOe.js";import{t as $s}from"./preferLocal-DEJV3KIq.js";import{n as ec,t as tc}from"./utils-MjUhYVsx.js";import{C as nc,D as rc,_ as ic,c as ac,d as oc,g as sc,h as cc,i as lc,m as uc,p as dc,r as fc,s as pc,t as mc,u as hc,v as gc}from"./default-inspector-registry-Dktr6x_q.js";import{a as _c,n as vc,o as yc,r as bc,s as xc}from"./ui-layout-BYO3rRIl.js";import{_ as Sc,a as Cc,c as wc,d as Tc,g as Ec,h as Dc,l as Oc,n as kc,o as Ac,s as jc,t as Mc,u as Nc,v as Pc,y as Fc}from"./vendor-dndkit-CqQIoA27.js";import{_ as Ic,g as Lc,n as Rc,r as zc}from"./plugin-grid-Cp4RKtMJ.js";import{c as Bc,l as Vc,o as Hc,s as Uc}from"./InterfaceListPage-BfoCldGu.js";import{t as Wc}from"./getIcon-BDkBRQFw.js";import{t as Gc}from"./useCanAuthorMetadata-TDrVrYGB.js";import{i as Kc,n as qc,r as Jc,t as Yc}from"./useNavSelDeepLink-67Y4qCNO.js";import{$ as Xc,G as Zc,K as Qc,L as $c,Q as el,R as tl,W as nl,X as rl,Z as il,at as al,b as ol,et as sl,it as cl,nt as ll,q as ul,r as dl,rt as fl,tt as pl,y as ml}from"./SchemaForm-BWSWYMLE.js";import{n as hl,r as gl,t as _l}from"./CreateViewDialog-Cp72x_O7.js";import{i as vl}from"./drillUrlFilters-N0RngQg6.js";import{t as yl}from"./plugins-views-CnvkdSJK.js";import{c as bl,d as xl,l as Sl,u as Cl}from"./plugin-view-D9ixsNDG.js";import{n as wl,t as Tl}from"./MetadataInspector-BQyu9pOE.js";import{g as El,i as Dl,r as Z,u as Ol}from"./i18n-DTfZonAM.js";import{_ as kl,f as Al,g as jl,v as Ml}from"./ReportDefaultInspector-DVcWM6sh.js";import{o as Nl,r as Pl,t as Fl}from"./runtime-metadata-persistence-DX29lQ62.js";import{t as Il}from"./RuntimeDraftBar-DObTyFu2.js";import{n as Ll}from"./SkeletonDetail-CP-35B8x.js";import{r as Rl}from"./componentRegistry-DlSbJucP.js";import{n as zl,t as Bl}from"./studioEntry-DAqcBFtr.js";import{n as Vl}from"./submitRedirect-iy0oOi7I.js";var Q=e(_(),1),Hl=e(a(),1),$=h(),Ul={type:`object-master-detail-form`,objectName:`expense_claim`,mode:`create`,formType:`simple`,title:`New Expense Claim`,submitText:`Create Claim`,fields:[`title`,`applicant`,`department`,`reason`,`currency`,`claim_status`,`payment_status`,`remarks`],details:[{title:`Expense Lines`,childObject:`expense_line`,relationshipField:`expense_claim`,amountField:`amount`,totalField:`total_amount`,columns:[{name:`expense_date`,label:`Date`,type:`date`},{name:`category`,label:`Category`,type:`select`,options:[{label:`Travel & Transport`,value:`travel_transport`},{label:`Lodging`,value:`lodging`},{label:`Meals & Entertainment`,value:`meals_entertainment`},{label:`Office Supplies`,value:`office_supplies`},{label:`Communications`,value:`communications`},{label:`Training & Conference`,value:`training_conference`},{label:`Client / Project`,value:`client_project`},{label:`Other`,value:`other`}]},{name:`description`,label:`Description`,type:`text`},{name:`merchant_vendor`,label:`Merchant`,type:`text`},{name:`amount`,label:`Amount`,type:`currency`}]}]},Wl=()=>(0,$.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6`,children:[(0,$.jsx)(`h1`,{className:`mb-4 text-lg font-semibold`,children:`Dev · Master-Detail Form (ADR-0001)`}),(0,$.jsx)(Dn,{schema:Ul})]}),Gl={type:`element:definition-list`,properties:{columns:2,items:[{term:`Status`,description:`Active`},{term:`Owner`,description:`Ada Lovelace`},{term:`Plan`,description:`Enterprise`},{term:`Renewal`,description:`2026-12-01`}]}},Kl={type:`element:repeater`,properties:{object:`showcase_category`,titleField:`name`,fields:[`color`],limit:10,emptyText:`No categories`}},ql=()=>(0,$.jsxs)(`div`,{className:`mx-auto max-w-2xl space-y-8 p-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`mb-3 text-lg font-semibold`,children:`Dev · element:definition-list`}),(0,$.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,$.jsx)(Dn,{schema:Gl})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`mb-3 text-lg font-semibold`,children:`Dev · element:repeater (showcase_category)`}),(0,$.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,$.jsx)(Dn,{schema:Kl})})]})]}),Jl=0,Yl=new Set,Xl=[];function Zl(){for(let e of Yl)try{e(Jl)}catch{}if(Jl===0&&Xl.length>0){let e=Xl;Xl=[];for(let t of e)try{t()}catch{}}}function Ql(){Jl+=1,Zl()}function $l(){Jl=Math.max(0,Jl-1),Zl()}function eu(){return Jl}function tu(){return Jl===0}function nu(e){return Yl.add(e),()=>{Yl.delete(e)}}function ru(e=1e4){return Jl===0?Promise.resolve():new Promise(t=>{let n=!1,r=()=>{n||(n=!0,t())};Xl.push(r),e>0&&typeof setTimeout<`u`&&setTimeout(r,e)})}function iu(e){return(async(...t)=>{Ql();try{return await e(...t)}finally{$l()}})}function au(){if(typeof window>`u`)return;let e=window,t=e.__objectui??={};Object.defineProperty(t,"pendingRequests",{get:eu,configurable:!0}),Object.defineProperty(t,"idle",{get:tu,configurable:!0}),t.whenIdle=ru,t.subscribe=nu}async function ou(e,t,n){let r;try{r=(await e.getObjectSchema(t))?.fields}catch{}return e=>n(t,e,r?.[e]?.label||e)}var su={readonly:(e,t)=>e(`detail.writeStrippedReadonly`,{fields:t,defaultValue:`Read-only, so it did not take effect: {{fields}}`}),readonly_when:(e,t)=>e(`detail.writeStrippedByState`,{fields:t,defaultValue:`Not editable in this record's current state, so it did not take effect: {{fields}}`}),primary_key:(e,t)=>e(`detail.writeStrippedPrimaryKey`,{fields:t,defaultValue:`The record's identifier cannot be changed by a save, so it did not take effect: {{fields}}`}),computed:(e,t)=>e(`detail.writeStrippedComputed`,{fields:t,defaultValue:`Calculated by the server from a formula, so the value sent did not take effect: {{fields}}`})},cu=(e,t)=>e(`detail.writeStrippedUnknownReason`,{fields:t,defaultValue:`Not applied by the server: {{fields}}`});function lu(e){return su[e]??cu}async function uu(e,t,n,r,i){let a=new Map;for(let t of e.droppedFields){let e=a.get(t.reason)??[];for(let n of t.fields)e.includes(n)||e.push(n);a.set(t.reason,e)}if(a.size===0)return;let o=n&&e.resource?await ou(n,e.resource,r):e=>e,s=[];for(let[e,n]of a){if(n.length===0)continue;let r=n.map(o).join(`, `);s.push(lu(e)(t,r))}s.length!==0&&i.warning(t(`detail.writeStrippedTitle`,{defaultValue:`Saved — but some fields did not take effect`}),{description:s.join(`
3
+ `)})}var du=1e4;function fu(e,t){switch(e){case`refused`:return t(`console.importMappingsRefused`,{defaultValue:`The server refused this request, so this list is empty because it could not be read — not because nothing is registered. Sign in again, or ask an administrator for access.`});case`unreadable`:return t(`console.importMappingsUnreadable`,{defaultValue:`This list is empty because it could not be read, not because nothing is registered. Try again, and report this if it keeps happening.`});default:throw Error(`metadataReadWarningToast: no remedy for reason ${JSON.stringify(e)}`)}}function pu(e,t){switch(e){case`refused`:return t(`console.savedViewsRefused`,{defaultValue:`The server refused this request, so this list is empty because it could not be read — not because this object has no saved views. Sign in again, or ask an administrator for access.`});case`unreadable`:return t(`console.savedViewsUnreadable`,{defaultValue:`This list is empty because it could not be read, not because this object has no saved views. Try again, and report this if it keeps happening.`});default:throw Error(`metadataReadWarningToast: no remedy for reason ${JSON.stringify(e)}`)}}function mu(e,t){switch(e.operation){case`listImportMappings`:return fu(e.reason,t);case`listViews`:return pu(e.reason,t);default:{let t=e.operation;throw Error(`metadataReadWarningToast: no remedy for operation ${JSON.stringify(t)}`)}}}function hu(e,t){switch(e.operation){case`listImportMappings`:return t(`console.importMappingsUnavailable`,{object:e.objectName,defaultValue:`Saved import mappings for {{object}} could not be loaded`});case`listViews`:return t(`console.savedViewsUnavailable`,{object:e.objectName,defaultValue:`Saved views for {{object}} could not be loaded`});default:{let t=e.operation;throw Error(`metadataReadWarningToast: no title for operation ${JSON.stringify(t)}`)}}}function gu(e){let t=[[e.code,e.status===void 0?void 0:`HTTP ${e.status}`].filter(e=>typeof e==`string`&&e.length>0).join(` · `),e.message].filter(e=>typeof e==`string`&&e.length>0);return t.length>0?t.join(` — `):void 0}function _u(e,t,n){let r=gu(e);n.warning(hu(e,t),{description:r?`${mu(e,t)}\n${r}`:mu(e,t),duration:du})}function vu({children:e,adapter:t}){let[n,r]=(0,Q.useState)(t??null),{t:i}=J(),a=(0,Q.useRef)(i);a.current=i;let{fieldLabel:o}=$n(),s=(0,Q.useRef)(o);return s.current=o,(0,Q.useEffect)(()=>{if(t){r(t);return}let e=!1,n,i,o;au();async function c(){try{let t=new fr({baseUrl:``,fetch:iu(y()),autoReconnect:!0,maxReconnectAttempts:5,reconnectDelay:1e3,cache:{maxSize:50,ttl:3e5}});n=t.onWriteWarning(e=>{uu(e,a.current,t,s.current,Y)}),i=t.onSaveAdvisory(e=>{Ea(e,a.current,Y)}),o=t.onMetadataReadWarning(e=>{_u(e,a.current,Y)}),await t.connect(),e||r(t)}catch(t){e||console.error(`[Console] Failed to initialize:`,t)}}return c(),()=>{e=!0,n?.(),i?.(),o?.()}},[t]),(0,$.jsx)(Zt.Provider,{value:n,children:e})}var yu=3e5,bu=[`app`,`view`],xu=1e3,Su={apps:`app`,objects:`object`,dashboards:`dashboard`,reports:`report`,pages:`page`},Cu=`objectui:metadata:`,wu=`@none`;function Tu(){try{return w.get()||wu}catch{return wu}}var Eu=`@anon`;function Du(e){let t=2166136261,n=3266489909;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);t=Math.imul(t^i,16777619),n=Math.imul(n^i,2246822507)}t=Math.imul(t^t>>>15,625341585),n=Math.imul(n^n>>>13,668265263);let r=e=>(e>>>0).toString(36).padStart(7,`0`);return`${r(t)}${r(n)}`}function Ou(){let e=null;try{e=P.get()}catch{}return e?Du(e):Eu}function ku(e,t){return`${Cu}${e}:${t}:${Ou()}`}function Au(e){return ku(e,Tu())}function ju(){if(!(typeof sessionStorage>`u`))try{let e=`:${Ou()}`;for(let t of Object.keys(sessionStorage))t.startsWith(Cu)&&!t.endsWith(e)&&sessionStorage.removeItem(t)}catch{}}function Mu(){try{let e=import.meta;if(e&&e.env&&typeof e.env.MODE==`string`)return e.env.MODE!==`production`}catch{}return!1}var Nu=Mu();function Pu(...e){Nu&&console.debug(`[MetadataProvider]`,...e)}function Fu(e){return Array.isArray(e)?e:e&&typeof e==`object`&&`items`in e&&Array.isArray(e.items)?e.items:[]}function Iu(e){return e==null?null:typeof e==`object`&&`item`in e?e.item??null:e}function Lu(e){return!!e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`}function Ru(e){return!!e&&typeof e==`object`&&!!e.viewKind&&!!e.object}function zu(e){return e.config&&typeof e.config==`object`?e.config:e}function Bu(e,t){let n=t.name||`${t.object}.${t.viewKind}`,r=zu(t),i={...r,name:n,label:t.label??r.label,isDefault:!!t.isDefault};t.viewKind===`form`?(e.formViews[n]=i,t.isDefault&&(e.form=i)):(e.listViews[n]=i,t.isDefault&&(e.primary=i))}function Vu(e,t){if(!e.length||!t.length)return e;let n={},r=new Set;for(let e of t)Ru(e)&&r.add(e.object);for(let e of t){if(Ru(e)){Bu(n[e.object]||={listViews:{},formViews:{}},e);continue}let t=e?.name||e?.list?.data?.object||e?.form?.data?.object;if(!t||r.has(t))continue;let i=n[t]||={listViews:{},formViews:{}};for(let n of I(t,e))Bu(i,n)}return e.map(e=>{let t=n[e.name];if(!t)return e;let r=e.listViews||e.list_views||{},i=e.formViews||e.form_views||{},a={...e,listViews:{...t.listViews,...r}};return(Object.keys(t.formViews).length||Object.keys(i).length)&&(a.formViews={...t.formViews,...i}),t.primary&&!e.list&&(a.list=t.primary),t.form&&!e.form&&(a.form=t.form),a})}function Hu(e){if(!e?.length)return e;let t={};for(let n of e){let e=n?.fields;if(!e)continue;let r=Array.isArray(e)?e.map(e=>[e?.name,e]):Object.entries(e);for(let[e,i]of r){let r=i;if(!e||!r?.inlineEdit||r.type!==`master_detail`&&r.type!==`lookup`)continue;let a=r.reference;a&&(t[a]||=[]).push({childObject:n.name,relationshipField:e,inlineMode:ja(n,r.inlineEdit,{relationshipField:e}),...r.inlineTitle?{title:r.inlineTitle}:{},...Array.isArray(r.inlineColumns)?{columns:r.inlineColumns}:{},...typeof r.inlineAmountField==`string`?{amountField:r.inlineAmountField}:{}})}}return Object.keys(t).length?e.map(e=>{let n=t[e.name];if(!n?.length)return e;let r={...e.form||{type:`simple`}},i=Array.isArray(r.subforms)?r.subforms:[],a=new Set(i.map(e=>e.childObject));r.subforms=[...n.filter(e=>!a.has(e.childObject)),...i];let o={...e,form:r};return e.formViews?.default&&(o.formViews={...e.formViews,default:{...e.formViews.default,subforms:r.subforms}}),o}):e}function Uu(){return{status:`idle`,items:[],byName:new Map,error:null,fetchedAt:0,promise:null}}function Wu(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(Au(e));if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function Gu(e,t,n=Tu()){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(ku(e,n),JSON.stringify(t))}catch{}}function Ku(e){if(!(typeof sessionStorage>`u`))try{sessionStorage.removeItem(ku(e,wu))}catch{}}function qu({children:e,adapter:t,ttlMs:n=yu}){let r=(0,Q.useRef)(new Map),i=(0,Q.useRef)(new Map),a=(0,Q.useRef)(new Set),o=(0,Q.useRef)(t);o.current=t;let s=Oa(),c=(0,Q.useMemo)(()=>s?Sa({previewDrafts:!0}):null,[s]),l=(0,Q.useRef)(c);l.current=c;let[u,d]=(0,Q.useState)(0),f=(0,Q.useCallback)(()=>{typeof queueMicrotask==`function`?queueMicrotask(()=>d(e=>e+1)):Promise.resolve().then(()=>d(e=>e+1))},[]),p=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(!p.current){p.current=!0;return}r.current.clear(),i.current.clear(),f()},[s,f]);let m=(0,Q.useCallback)(e=>{let t=r.current.get(e);return t||(t=Uu(),r.current.set(e,t)),t},[]),h=(0,Q.useCallback)(e=>{let t=m(e);if(t.promise)return t.promise;if(t.status===`ready`&&Date.now()-t.fetchedAt<n)return Pu(`cache hit (fresh) type=${e} items=${t.items.length}`),Promise.resolve(t.items);if(t.status===`error`&&Date.now()-t.fetchedAt<xu)return Pu(`cache hit (recent failure) type=${e}`),Promise.resolve(t.items);let r=Date.now();t.status=`loading`,t.error=null;let i=l.current,s=(i?i.list(e):o.current.getClient().meta.getItems(e)).then(n=>{let o=Fu(n);if(e===`object`)for(let e of o)Rn(e);t.items=o,t.status=`ready`,t.error=null,t.fetchedAt=Date.now(),t.promise=null,t.byName.clear();for(let e of o)Lu(e)&&t.byName.set(e.name,e);if(e===`app`&&!i){let t=Tu();Gu(e,o,t),t===wu?a.current.add(e):a.current.delete(e)}return Pu(`fetched type=${e} items=${o.length} in ${Date.now()-r}ms`),f(),o}).catch(n=>{let r=n instanceof Error?n:Error(String(n));return t.status=`error`,t.error=r,t.promise=null,t.fetchedAt=Date.now(),Pu(`fetch failed type=${e}`,r),f(),[]});return t.promise=s,s},[f,m,n]),g=(0,Q.useCallback)((e,t)=>{let n=m(e);if(n.byName.has(t))return Pu(`item cache hit type=${e} name=${t}`),Promise.resolve(n.byName.get(t)??null);let r=i.current.get(e);r||(r=new Map,i.current.set(e,r));let a=r.get(t);if(a)return a;let s=Date.now(),c=l.current,u=(c?c.get(e,t):o.current.getClient().meta.getItem(e,t)).then(i=>{let a=Iu(i);return e===`object`&&a&&Rn(a),a&&n.byName.set(t,a),Pu(`fetched item type=${e} name=${t} in ${Date.now()-s}ms`),r.delete(t),a}).catch(n=>(r.delete(t),Pu(`fetch item failed type=${e} name=${t}`,n),null));return r.set(t,u),u},[m]),_=(0,Q.useCallback)(async e=>{if(e){let t=m(e);t.fetchedAt=0,t.byName.clear(),await h(e);return}let t=Array.from(r.current.keys()).filter(e=>r.current.get(e).status!==`idle`);await Promise.all(t.map(e=>{let t=r.current.get(e);return t.fetchedAt=0,t.byName.clear(),h(e)}))},[h,m]),v=(0,Q.useCallback)((e,t)=>{let n=r.current.get(e);n&&(t?(n.byName.delete(t),n.items=n.items.filter(e=>e?.name!==t),Pu(`invalidated type=${e} name=${t}`)):(n.status=`idle`,n.items=[],n.byName.clear(),n.error=null,n.fetchedAt=0,Pu(`invalidated type=${e}`)),f())},[f]);(0,Q.useEffect)(()=>{if(s)return Va(({type:e})=>{v(e)})},[s,v]),(0,Q.useEffect)(()=>Ba(()=>{try{o.current?.clearCache?.()}catch{}_()}),[_]);let[y,b]=(0,Q.useState)(!0),[x,S]=(0,Q.useState)(null),{activeOrganization:C}=A(),w=C?.id??null,T=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=T.current;if(T.current=w,e===null||e===w){if(e===null&&w&&a.current.size>0){for(let e of a.current){let t=r.current.get(e);t&&t.status===`ready`&&t.items.length>0&&Gu(e,t.items,w),Ku(e)}a.current.clear()}return}let t=!1;return r.current.clear(),i.current.clear(),b(!0),h(`app`).finally(()=>{t||b(!1)}),f(),()=>{t=!0}},[w,f,h]),(0,Q.useEffect)(()=>{let e=!1,t=s?null:Wu(`app`);if(ju(),t&&t.length>0){let e=m(`app`);e.items=t,e.status=`ready`,e.fetchedAt=0;for(let n of t)Lu(n)&&e.byName.set(n.name,n);f(),b(!1)}return(async()=>{for(let t of bu)try{await h(t),e||S(null)}catch(t){e||S(t instanceof Error?t:Error(String(t)))}e||b(!1)})(),()=>{e=!0}},[t,h,m,f,s]);let E=(0,Q.useMemo)(()=>{let e=e=>{let t=m(e);return t.status===`idle`&&h(e),t.items};return{apps:m(`app`).items,get objects(){let t=e(Su.objects),n=e(`view`);return Hu(n.length?Vu(t,n):t)},get dashboards(){return e(Su.dashboards)},get reports(){return e(Su.reports)},get pages(){return e(Su.pages)},loading:y,error:x??m(`app`).error,refresh:_,invalidate:v,ensureType:h,getItem:g,getItemsByType:t=>e(t),getTypeStatus:e=>m(e).status}},[u,y,x,h,g,m,_,v]);return(0,$.jsx)(sn.Provider,{value:E,children:e})}function Ju({objectName:e,objectLabel:t,dataSource:n,onEdit:i,onRefresh:a,onConfirm:o,onToast:s}){let c=r(),{appName:l}=f(),{t:u}=J(),d=`/apps/${l}`,{execute:p,loading:m,error:h,runner:g}=Bn({context:{objectName:e,objectLabel:t||e,baseUrl:d},onConfirm:o,onToast:s});return(0,Q.useEffect)(()=>{g.registerHandler(`create`,async()=>(i?.(null),{success:!0})),g.registerHandler(`delete`,r=>zn.run({objectName:e,label:t||e,dataSource:n,t:u,toast:Y,onRefresh:a},r)),g.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&c(t.startsWith(`/`)?t:`${d}/${t}`),{success:!0}}),g.registerHandler(`refresh`,async()=>(a?.(),{success:!0,reload:!0}))},[g,e,n,i,a,c,d,u,t]),{execute:p,create:(0,Q.useCallback)(()=>{i?.(null)},[i]),deleteRecord:(0,Q.useCallback)(async(t,n)=>p({type:`delete`,confirmText:zn.confirmText({objectName:e,t:u},n),params:n?{recordId:t,record:n}:{recordId:t}}),[p,u,e]),navigateToView:(0,Q.useCallback)(t=>{c(`${d}/${e}/view/${t}`)},[c,d,e]),navigateToRecord:(0,Q.useCallback)(t=>{c(`${d}/${e}/record/${encodeURIComponent(t)}`)},[c,d,e]),loading:m,error:h}}function Yu(e){return e==null?[]:Array.isArray(e)?e:[e]}function Xu(e,t){let{alias:n,value:r=`1`,replace:i=!0}=t??{},[a,o]=l(),s=(0,Q.useMemo)(()=>Yu(n),[n]),c=(0,Q.useCallback)(t=>t.get(e)===r||s.some(e=>t.get(e)===r),[e,r,s]),u=c(a),d=(0,Q.useCallback)(t=>{if(t===c(a))return;let n=new URLSearchParams(a);if(t){n.set(e,r);for(let e of s)n.delete(e)}else{n.delete(e);for(let e of s)n.delete(e)}o(n,{replace:i})},[c,a,o,e,r,s,i]);return{open:u,setOpen:d,openOverlay:(0,Q.useCallback)(()=>d(!0),[d]),closeOverlay:(0,Q.useCallback)(()=>d(!1),[d]),toggleOverlay:(0,Q.useCallback)(()=>{o(t=>{let n=new URLSearchParams(t);if(c(n)){n.delete(e);for(let e of s)n.delete(e)}else{n.set(e,r);for(let e of s)n.delete(e)}return n},{replace:i})},[o,c,e,r,s,i])}}function Zu(e){let t=(e??[]).find(e=>e?.isDefault===!0&&!!e?.name);return t?`/apps/${t.name}`:null}function Qu(){let{apps:e}=Yt();return Zu(e)??`/home`}var $u=(0,Q.createContext)({theme:`system`,setTheme:()=>null});function ed({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`,...r}){let[i,a]=(0,Q.useState)(()=>localStorage.getItem(n)||t);(0,Q.useEffect)(()=>{let e=window.document.documentElement;if(e.classList.remove(`light`,`dark`),i===`auto`||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,$.jsx)($u.Provider,{...r,value:o,children:e})}var td=()=>{let e=(0,Q.useContext)($u);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function nd(){let e=((typeof document<`u`?document.documentElement.lang:``)||(typeof navigator<`u`?navigator.language:``)||`en`).toLowerCase().split(`-`)[0],t=Kn()[e]?.console;return!t||t===Un.console?Un.console:{...Un.console,...t,loadingSteps:{...Un.console.loadingSteps,...t.loadingSteps},error:{...Un.console.error,...t.error},actions:{...Un.console.actions,...t.actions}}}function rd({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,Q.useState)(0),o=nd(),s=(0,Q.useMemo)(()=>[o.loadingSteps.connecting,o.loadingSteps.loadingConfig,o.loadingSteps.preparingWorkspace],[o]);return(0,Q.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,$.jsx)(`div`,{className:`flex flex-col items-center justify-center h-screen bg-background`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-primary/20 rounded-2xl blur-xl animate-pulse`}),(0,$.jsx)(`div`,{className:`relative bg-linear-to-br from-primary to-primary/80 p-4 rounded-2xl shadow-lg`,children:Rs()?(0,$.jsx)(`img`,{src:Rs(),alt:Gs(),className:`h-10 w-10 object-contain`}):(0,$.jsx)(Gr,{className:`h-10 w-10 text-primary-foreground`})})]}),(0,$.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,$.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:Gs()}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o.initializing})]}),t?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-4 max-w-md w-full px-6`,children:[(0,$.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,$.jsxs)(`div`,{className:`flex items-center gap-2 text-destructive`,children:[(0,$.jsx)(Pr,{className:`h-5 w-5 shrink-0`}),(0,$.jsx)(`span`,{className:`text-sm font-semibold`,children:o.error.connectionFailed})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground text-center break-words`,children:t}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:o.error.checkServer})]}),n&&(0,$.jsx)(q,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(X,{className:`h-4 w-4 animate-spin`}),o.actions.retrying]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(zi,{className:`h-4 w-4`}),o.actions.retry]})})]}):e?(0,$.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 bg-muted/50 rounded-full`,children:[(0,$.jsx)(Ut,{className:`h-4 w-4 text-primary`}),(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 w-64`,children:[s.map((e,t)=>(0,$.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,$.jsx)(Ir,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,$.jsx)(X,{className:`h-4 w-4 text-primary shrink-0 animate-spin`}):(0,$.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-muted-foreground/30 shrink-0`}),(0,$.jsx)(`span`,{className:t<=i?`text-foreground`:`text-muted-foreground`,children:e})]},e)),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:o.loadingHint})]})]})})}function id({to:e,replace:n}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(rd,{}),(0,$.jsx)(t,{to:e,replace:n})]})}var ad=Qa();function od(){let{remediationRequired:e}=A();return e?(0,$.jsx)(`div`,{className:`fixed inset-0 z-[200] flex items-center justify-center bg-background/95 p-4 backdrop-blur-sm`,children:(0,$.jsx)(`div`,{className:`w-full max-w-md rounded-xl border bg-card p-6 shadow-xl`,children:e.code===`PASSWORD_EXPIRED`?(0,$.jsx)(cd,{message:e.message}):(0,$.jsx)(ud,{message:e.message})})}):null}function sd(){let{signOut:e}=A(),{t}=J();return(0,$.jsx)(`button`,{type:`button`,onClick:()=>{e()},className:`mt-4 w-full text-center text-xs text-muted-foreground hover:text-foreground hover:underline`,children:t(`auth.remediation.signOut`)})}function cd({message:e}){let{changePassword:t,setRemediationRequired:n}=A(),{t:r}=J(),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(null);return(0,$.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),p(null),o!==c){p(r(`auth.remediation.password.mismatch`));return}d(!0);try{await t(i,o),n(null),window.location.reload()}catch(e){p(e instanceof Error?e.message:r(`auth.remediation.password.failed`)),d(!1)}},className:`space-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:r(`auth.remediation.password.title`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||r(`auth.remediation.password.fallbackMessage`)})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(z,{htmlFor:`rem-cur`,children:r(`auth.remediation.password.current`)}),(0,$.jsx)(K,{id:`rem-cur`,type:`password`,autoComplete:`current-password`,value:i,onChange:e=>a(e.target.value),required:!0})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(z,{htmlFor:`rem-new`,children:r(`auth.remediation.password.next`)}),(0,$.jsx)(K,{id:`rem-new`,type:`password`,autoComplete:`new-password`,value:o,onChange:e=>s(e.target.value),required:!0})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(z,{htmlFor:`rem-conf`,children:r(`auth.remediation.password.confirm`)}),(0,$.jsx)(K,{id:`rem-conf`,type:`password`,autoComplete:`new-password`,value:c,onChange:e=>l(e.target.value),required:!0})]}),f?(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:f}):null,(0,$.jsx)(q,{type:`submit`,className:`w-full`,disabled:u,children:r(u?`auth.remediation.password.submitting`:`auth.remediation.password.submit`)}),(0,$.jsx)(sd,{})]})}function ld({uri:e}){let[t,n]=(0,Q.useState)(null);return(0,$.jsx)(`div`,{className:`flex justify-center rounded-md border bg-white p-3`,children:t?(0,$.jsx)(`span`,{className:`text-sm text-destructive`,children:t}):(0,$.jsx)(`canvas`,{ref:t=>{t&&e&&(0,ad.toCanvas)(t,e,{width:184,margin:1},e=>{e&&n(e.message)})}})})}function ud({message:e}){let{enrollTotp:t,verifyTotp:n,setRemediationRequired:r}=A(),{t:i}=J(),[a,o]=(0,Q.useState)(`password`),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(null);return a===`password`?(0,$.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),g(!0);try{let{totpURI:e,backupCodes:n}=await t(s);f(e),m(n??[]),o(`verify`)}catch(e){v(e instanceof Error?e.message:i(`auth.remediation.mfa.enrollFailed`))}finally{g(!1)}},className:`space-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:i(`auth.remediation.mfa.title`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||i(`auth.remediation.mfa.fallbackMessage`)})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(z,{htmlFor:`rem-pw`,children:i(`auth.remediation.mfa.confirmPassword`)}),(0,$.jsx)(K,{id:`rem-pw`,type:`password`,autoComplete:`current-password`,value:s,onChange:e=>c(e.target.value),required:!0})]}),_?(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:_}):null,(0,$.jsx)(q,{type:`submit`,className:`w-full`,disabled:h,children:i(h?`auth.remediation.mfa.preparing`:`auth.remediation.mfa.continue`)}),(0,$.jsx)(sd,{})]}):(0,$.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),g(!0);try{await n(l.trim()),r(null),window.location.reload()}catch(e){v(e instanceof Error?e.message:i(`auth.remediation.mfa.invalidCode`)),g(!1)}},className:`space-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:i(`auth.remediation.mfa.scanTitle`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:i(`auth.remediation.mfa.scanBody`)})]}),d?(0,$.jsx)(ld,{uri:d}):null,p.length>0?(0,$.jsxs)(`details`,{className:`rounded-md border bg-muted/40 p-3 text-xs`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer font-medium`,children:i(`auth.remediation.mfa.backupTitle`)}),(0,$.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:i(`auth.remediation.mfa.backupBody`)}),(0,$.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 font-mono`,children:p.map(e=>(0,$.jsx)(`span`,{children:e},e))})]}):null,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(z,{htmlFor:`rem-code`,children:i(`auth.remediation.mfa.codeLabel`)}),(0,$.jsx)(K,{id:`rem-code`,inputMode:`numeric`,autoComplete:`one-time-code`,maxLength:8,placeholder:`123456`,value:l,onChange:e=>u(e.target.value),required:!0})]}),_?(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:_}):null,(0,$.jsx)(q,{type:`submit`,className:`w-full`,disabled:h,children:i(h?`auth.remediation.mfa.verifying`:`auth.remediation.mfa.verify`)}),(0,$.jsx)(sd,{})]})}function dd({children:e}){return c()?(0,$.jsx)(fd,{children:e}):(0,$.jsx)($.Fragment,{children:e})}function fd({children:e}){let t=r(),n=(0,Q.useMemo)(()=>({navigate:(e,n)=>t(e,{replace:n?.replace??!1})}),[t]);return(0,$.jsx)(nn,{value:n,children:e})}function pd(){let{user:e,session:t,refreshSession:n}=A(),{t:r}=J(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(!1),u=(0,Q.useMemo)(()=>y(),[]),d=t?.impersonatedBy,f=(0,Q.useCallback)(async()=>{a(!0),s(null);try{let e=await u(`/api/v1/auth/admin/stop-impersonating`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:`{}`});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message??t?.message??`HTTP ${e.status}`)}await n()}catch(e){let t=e instanceof Error?e.message:String(e);s(t),Y.error(r(`impersonation.banner.stopFailed`,{defaultValue:`Could not stop impersonating: {{reason}}`,reason:t}))}finally{l(!0),a(!1)}},[u,n,r]);if(!d)return null;let p=e?.name||e?.email||e?.id||``,m=c&&!i&&!o;return(0,$.jsxs)(`div`,{role:`status`,"data-testid":`impersonation-banner`,className:`sticky top-0 z-50 flex flex-wrap items-center gap-x-3 gap-y-1 border-b border-red-300/70 bg-red-50 px-4 py-2 text-sm text-red-900 dark:border-red-800/60 dark:bg-red-950/50 dark:text-red-100`,children:[(0,$.jsx)(pa,{className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),(0,$.jsxs)(`p`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:r(`impersonation.banner.message`,{defaultValue:`You are impersonating {{user}} — every action is recorded as them.`,user:p})}),` `,(0,$.jsx)(`span`,{className:`opacity-80`,children:r(`impersonation.banner.startedBy`,{defaultValue:`Started by administrator {{admin}}.`,admin:d})})]}),(0,$.jsx)(q,{size:`sm`,variant:`outline`,onClick:f,disabled:i,"data-testid":`impersonation-stop`,children:i?r(`impersonation.banner.stopping`,{defaultValue:`Stopping…`}):r(`impersonation.banner.stop`,{defaultValue:`Stop impersonating`})}),o?(0,$.jsx)(`p`,{role:`alert`,"data-testid":`impersonation-stop-error`,className:`w-full font-medium`,children:r(`impersonation.banner.stopFailed`,{defaultValue:`Could not stop impersonating: {{reason}}`,reason:o})}):null,m?(0,$.jsx)(`p`,{role:`alert`,"data-testid":`impersonation-not-restored`,className:`w-full font-medium`,children:r(`impersonation.banner.notRestored`,{defaultValue:`The server accepted the request but did not restore your administrator session — you are still impersonating {{user}}. Sign out and sign in again to end it.`,user:p})}):null]})}pd.displayName=`ImpersonationBanner`;function md(e){return e?e.replace(/\/$/,``):`${({BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_SERVER_URL??``).replace(/\/$/,``)}/api/v1`}var hd=new Map;function gd(e){let t=`${e}/usage/storage`,n=hd.get(t);if(n)return n;let r=y()(t,{method:`GET`,headers:{Accept:`application/json`},credentials:`include`}).then(async e=>{if(!e.ok)throw Error(`Failed to load storage usage (${e.status})`);return e.json()}).finally(()=>{hd.delete(t)});return hd.set(t,r),r}function _d(e){return e.status===`measured`?e.reading.state===`ok`?`ok`:e.reading.readsPerWrite===void 0?`anomalous-no-writes`:`anomalous-ratio`:e.status===`unavailable`?`unavailable`:e.status===`unmeasured`?`unmeasured`:`pending`}var vd=Symbol(`no readRate on the response`);function yd(e){if(!e||typeof e!=`object`)return null;let t=e.readRate;if(t==null)return vd;if(typeof t!=`object`)return null;let{state:n,readsPerWrite:r,ratioThreshold:i}=t;return n!==`ok`&&n!==`anomalous`||typeof i!=`number`||!Number.isFinite(i)?null:r==null?{state:n,ratioThreshold:i}:typeof r!=`number`||!Number.isFinite(r)||r<0?null:{state:n,readsPerWrite:r,ratioThreshold:i}}function bd(e={}){let{apiBase:t,enabled:n=!0}=e,[r,i]=Q.useState({status:`idle`,reading:null}),[a,o]=Q.useState(0),s=Q.useCallback(()=>o(e=>e+1),[]),c=Q.useMemo(()=>md(t),[t]);Q.useEffect(()=>{if(!n||typeof fetch!=`function`)return;let e=!1;return i({status:`loading`,reading:null}),gd(c).then(t=>{if(e)return;let n=yd(t);i(n===vd?{status:`unmeasured`,reading:null}:n===null?{status:`unavailable`,reading:null}:{status:`measured`,reading:n})}).catch(()=>{e||i({status:`unavailable`,reading:null})}),()=>{e=!0}},[n,c,a]);let l=n?r:{status:`idle`,reading:null};return l.status===`measured`?{status:`measured`,reading:l.reading,refetch:s}:{status:l.status,reading:null,refetch:s}}function xd({apiBase:e,className:t}){let{t:n}=J(),r=tr(),{isAdmin:i}=S(),a=bd({apiBase:e,enabled:i&&Hs()}),o=_d(a),s=a.status===`measured`?a.reading:null;if(!s||o!==`anomalous-no-writes`&&o!==`anomalous-ratio`)return null;let{readsPerWrite:c}=s,l=c===void 0,u=Nn(s.ratioThreshold,{locale:r,maximumFractionDigits:1}),d=l?n(`console.readRate.noWritesTitle`,{defaultValue:`Reads with no writes at all in this environment`}):n(`console.readRate.ratioTitle`,{defaultValue:`Unusual read volume in this environment`}),f=l?n(`console.readRate.noWrites`,{defaultValue:`Rows are being read while none at all are being written, so the read rate has no upper bound. This is the most severe reading. The platform flags anything above {{threshold}}. Nothing is limited or blocked; this is a report so the read pattern can be reviewed.`,threshold:u}):n(`console.readRate.ratio`,{defaultValue:`Reads are running at {{ratio}} rows for every row written. The platform flags anything above {{threshold}}. Nothing is limited or blocked; this is a report so the read pattern can be reviewed.`,ratio:Nn(c,{locale:r,maximumFractionDigits:1}),threshold:u});return(0,$.jsxs)(`div`,{role:`status`,"data-testid":`read-rate-banner`,"data-read-rate-case":o,className:Le(`flex flex-wrap items-start gap-x-3 gap-y-1 border-b px-4 py-2 text-sm`,l?`border-red-300/70 bg-red-50 text-red-900 dark:border-red-800/60 dark:bg-red-950/50 dark:text-red-100`:`border-amber-300/70 bg-amber-50 text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/50 dark:text-amber-100`,t),children:[(0,$.jsx)(ua,{className:`mt-0.5 h-4 w-4 shrink-0`,"aria-hidden":`true`}),(0,$.jsxs)(`p`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:d}),` `,(0,$.jsx)(`span`,{className:`opacity-90`,children:f})]})]})}xd.displayName=`ReadRateBanner`;var Sd=new Set([`ok`,`warning`,`exhausted`,`unlimited`,`unknown`]);function Cd(e){return Sd.has(e)}function wd(e){if(e.status!==`answered`)return e.status===`unavailable`?{case:`unavailable`}:{case:`pending`};let{state:t,warn:n,blocked:r,usedMb:i,limitMb:a}=e.reading;return!r&&!n?{case:`none`,state:t}:i===void 0||a===void 0?{case:`unavailable`}:r?{case:`blocked`,usedMb:i,limitMb:a}:{case:`warning`,usedMb:i,limitMb:a}}var Td=Symbol(`off-contract megabyte figure`);function Ed(e){if(e!==void 0)return typeof e!=`number`||!Number.isFinite(e)||e<0?Td:e}function Dd(e){if(!e||typeof e!=`object`)return null;let{state:t,warn:n,blocked:r,usedMb:i,limitMb:a}=e;if(!Cd(t)||typeof n!=`boolean`||typeof r!=`boolean`)return null;let o=Ed(i),s=Ed(a);return o===Td||s===Td||(n||r)&&(o===void 0||s===void 0)?null:{state:t,warn:n,blocked:r,...o===void 0?{}:{usedMb:o},...s===void 0?{}:{limitMb:s}}}function Od(e={}){let{apiBase:t,enabled:n=!0}=e,[r,i]=Q.useState({status:`idle`,reading:null}),[a,o]=Q.useState(0),s=Q.useCallback(()=>o(e=>e+1),[]),c=Q.useMemo(()=>md(t),[t]);Q.useEffect(()=>{if(!n||typeof fetch!=`function`)return;let e=!1;return i({status:`loading`,reading:null}),gd(c).then(t=>{if(e)return;let n=Dd(t);i(n?{status:`answered`,reading:n}:{status:`unavailable`,reading:null})}).catch(()=>{e||i({status:`unavailable`,reading:null})}),()=>{e=!0}},[n,c,a]);let l=n?r:{status:`idle`,reading:null};return l.status===`answered`?{status:`answered`,reading:l.reading,refetch:s}:{status:l.status,reading:null,refetch:s}}function kd({apiBase:e,className:t}){let{t:n}=J(),r=tr(),{isAdmin:i}=S(),a=wd(Od({apiBase:e,enabled:i&&Hs()}));if(a.case!==`warning`&&a.case!==`blocked`)return null;let o=a.case===`blocked`,s=Nn(a.usedMb,{locale:r,maximumFractionDigits:1}),c=Nn(a.limitMb,{locale:r,maximumFractionDigits:1}),l=o?qs():``,u=o?n(`console.storageUsage.blockedTitle`,{defaultValue:`Storage is full: uploads and imports are paused`}):n(`console.storageUsage.warningTitle`,{defaultValue:`Storage is filling up`}),d=o?n(`console.storageUsage.blocked`,{defaultValue:`{{used}} MB of {{limit}} MB used. Existing data is untouched, and reading, exporting and editing single records still work.`,used:s,limit:c}):n(`console.storageUsage.warning`,{defaultValue:`{{used}} MB of {{limit}} MB used. Uploads and imports pause once storage is full.`,used:s,limit:c});return(0,$.jsxs)(`div`,{role:`status`,"data-testid":`storage-usage-banner`,"data-storage-usage-case":a.case,className:Le(`flex flex-wrap items-start gap-x-3 gap-y-1 border-b px-4 py-2 text-sm`,o?`border-red-300/70 bg-red-50 text-red-900 dark:border-red-800/60 dark:bg-red-950/50 dark:text-red-100`:`border-amber-300/70 bg-amber-50 text-amber-900 dark:border-amber-800/60 dark:bg-amber-950/50 dark:text-amber-100`,t),children:[(0,$.jsx)(si,{className:`mt-0.5 h-4 w-4 shrink-0`,"aria-hidden":`true`}),(0,$.jsxs)(`p`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:u}),` `,(0,$.jsx)(`span`,{className:`opacity-90`,children:d})]}),l?(0,$.jsx)(`a`,{href:l,target:`_blank`,rel:`noopener noreferrer`,"data-testid":`storage-usage-upgrade`,className:`shrink-0 font-medium underline underline-offset-2 hover:no-underline`,children:n(`console.storageUsage.upgrade`,{defaultValue:`Upgrade to continue`})}):null]})}kd.displayName=`StorageUsageBanner`;function Ad(){return(0,$.jsx)(rd,{})}function jd({dataSource:e,children:t}){let{modalHandler:n,modalElement:r}=Lo(e),i=Ho({dataSource:e});return(0,$.jsxs)(Pn,{context:i.actionProviderProps.context,onConfirm:i.actionProviderProps.onConfirm,onToast:i.actionProviderProps.onToast,onNavigate:i.actionProviderProps.onNavigate,onParamCollection:i.actionProviderProps.onParamCollection,onResultDialog:i.actionProviderProps.onResultDialog,onModal:n,handlers:{api:i.apiHandler,flow:i.flowHandler,script:i.serverActionHandler},children:[t,i.dialogs,r]})}function Md({children:e}){return(0,$.jsx)(dd,{children:(0,$.jsx)(Nd,{children:e})})}function Nd({children:e}){return(0,$.jsx)(ed,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,$.jsx)(pn,{config:{defaultDuration:4e3,maxVisible:4},onToast:to,children:(0,$.jsx)(Vo,{children:(0,$.jsx)(Xa,{children:(0,$.jsx)(Wo,{children:(0,$.jsx)($a,{children:(0,$.jsxs)(ro,{children:[(0,$.jsx)(pd,{}),(0,$.jsx)(xd,{}),(0,$.jsx)(kd,{}),(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Ad,{}),children:e}),(0,$.jsx)(od,{}),(0,$.jsx)(Tt,{}),(0,$.jsx)(Ye,{})]})})})})})})})}function Pd({children:e}){return(0,$.jsx)(vu,{children:(0,$.jsx)(Ca,{children:(0,$.jsx)(Id,{children:e})})})}var Fd=iu(y({sameOriginOnly:!0}));function Id({children:e}){let t=un(),{language:n}=J(),{isLoading:r}=A(),i=(0,Q.useRef)(null);return t&&i.current!==null&&i.current!==n&&t.clearCache?.(),t&&(i.current=n),!t||r?(0,$.jsx)(Ad,{}):(0,$.jsx)(Mn,{dataSource:t,apiFetch:Fd,children:(0,$.jsxs)(qu,{adapter:t,children:[(0,$.jsx)(Ld,{}),(0,$.jsx)(jd,{dataSource:t,children:e})]},n)})}function Ld(){let{user:e}=A(),t=un(),n=Za();return(0,Q.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null),n(`flowPaletteRecents`,null);return}let r=sr({dataSource:t,userId:e.id,key:`ui.favorites`}),i=sr({dataSource:t,userId:e.id,key:`ui.recent`}),a=sr({dataSource:t,userId:e.id,key:`ui.flow.palette.recents`});return n(`favorites`,r),n(`recent`,i),n(`flowPaletteRecents`,a),()=>{n(`favorites`,null),n(`recent`,null),n(`flowPaletteRecents`,null)}},[e?.id,t,n]),null}function Rd({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r,getAuthConfig:i}=A(),[a,o]=(0,Q.useState)(null);if((0,Q.useEffect)(()=>{let e=!1;return i().then(t=>{e||o(t?.features?.multiOrgEnabled!==!1)}).catch(()=>{e||o(!1)}),()=>{e=!0}},[i]),r)return(0,$.jsx)(Ad,{});let s=n??[];if((s.length>0||t)&&!t)return(0,$.jsx)(id,{to:`/organizations`,replace:!0});if(s.length===0&&!t){if(a===null)return(0,$.jsx)(Ad,{});if(a)return(0,$.jsx)(id,{to:`/organizations`,replace:!0})}return(0,$.jsx)($.Fragment,{children:e})}function zd({children:e,redirectTo:t}){let n=Qu(),{enabled:r,isLoading:i}=vo();return i?(0,$.jsx)(Ad,{}):r?(0,$.jsx)($.Fragment,{children:e}):(0,$.jsx)(id,{to:t??n,replace:!0})}function Bd(){let e=g(),n=e.pathname.replace(/^\/system/,``),r=n?`/apps/setup/system${n}`:`/apps/setup/system`;return(0,$.jsx)(t,{to:`${r}${e.search}${e.hash}`,replace:!0})}function Vd(e){let t=e??[],n=t.find(e=>e?._packageId===`com.objectstack.setup`)??t.find(e=>e?.name===`setup`);return`/apps/${ss(n)??`com.objectstack.setup`}`}function Hd(){let{apps:e,loading:t}=Yt(),n=g();if(t)return(0,$.jsx)(Ad,{});let r=Vd(e);return(0,$.jsx)(id,{to:`${r}${n.search}${n.hash}`,replace:!0})}function Ud({appLabel:e,onOpenDock:t}){let{t:n}=J(),{openSeq:r}=za(),i=(0,Q.useRef)(r);return(0,Q.useEffect)(()=>{r!==i.current&&(i.current=r,t())},[r,t]),(0,$.jsx)(`button`,{type:`button`,"aria-label":n(`topbar.openAssistant`,{defaultValue:`Open {{name}} assistant`,name:e}),onClick:t,className:`fixed bottom-20 right-6 z-50 flex h-14 w-14 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg ring-1 ring-primary/20 transition-transform hover:scale-105 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 sm:bottom-6`,"data-testid":`console-chatbot-fab`,children:(0,$.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,$.jsx)(`path`,{d:`M12 3v3`}),(0,$.jsx)(`path`,{d:`M12 18v3`}),(0,$.jsx)(`path`,{d:`M5.6 5.6l2.1 2.1`}),(0,$.jsx)(`path`,{d:`M16.3 16.3l2.1 2.1`}),(0,$.jsx)(`path`,{d:`M3 12h3`}),(0,$.jsx)(`path`,{d:`M18 12h3`}),(0,$.jsx)(`path`,{d:`M5.6 18.4l2.1-2.1`}),(0,$.jsx)(`path`,{d:`M16.3 7.7l2.1-2.1`}),(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})})}var Wd=`batch_aborted`;function Gd(e){let t=e=>[`${e.type}/${e.name}: ${e.error}`,...(Array.isArray(e.issues)?e.issues:[]).map(e=>` ${lr(e)}`)].join(`
4
+ `),n=e.filter(e=>e.code===Wd);if(n.length>0){let r=e.filter(e=>e.code!==Wd);return[`Nothing was published — the batch rolled back (all-or-nothing).`,...r.length>0?r.map(t):n.slice(0,1).map(t),`(${n.length} other draft${n.length===1?``:`s`} aborted with it — fix the cause and publish again.)`].join(`
5
+ `)}return e.map(t).join(`
6
+ `)}function Kd(){let e=document.querySelector(`base`)?.getAttribute(`href`);return e?new URL(e,window.location.origin):new URL(`/`,window.location.origin)}function qd(e){return e===void 0?Kd().toString():new URL(`.`,e).toString()}function Jd(e,t){return new URL(e.replace(/^\//,``),qd(t)).toString()}function Yd(){if(!(typeof window>`u`||typeof document>`u`))return Jd(`s`)}var Xd=[`sys_`,`ai_`,`cloud_`],Zd=[`formula`,`summary`,`autonumber`];function Qd(e){let t=e?.fields??e?.data?.fields??e?.item?.fields??{};return(Array.isArray(t)?t.map(e=>[e?.name,e]):Object.entries(t)).map(([e,t])=>({name:t?.name??e,label:t?.label??t?.name??e,type:t?.type??`text`,required:!!t?.required,options:t?.options})).filter(e=>e.name&&!Zd.includes(e.type))}function $d({file:e,dataSource:t,defaultObjectName:n,onDone:r}){let{t:i}=J(),a=(0,Q.useMemo)(()=>y(),[]),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(n??``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=!1,t=``.replace(/\/+$/,``);return(async()=>{try{let r=await a(`${t}/api/v1/meta/object`,{method:`GET`,credentials:`include`});if(!r.ok)throw Error(String(r.status));let i=await r.json().catch(()=>null),o=i?.data?.items??i?.items??i?.data??(Array.isArray(i)?i:[]),u=(Array.isArray(o)?o:[]).map(e=>({name:e?.name,label:e?.label||e?.name})).filter(e=>e.name&&!Xd.some(t=>e.name.startsWith(t)));if(e)return;if(s(u),!c&&u.length){let e=n&&u.find(e=>e.name===n);l(e?n:u[0].name)}}catch{e||s([])}})(),()=>{e=!0}},[a,n]);async function g(){if(c){d(!0);try{let e=Qd(await t.getObjectSchema(c));if(!e.length){Y.error(i(`excelImport.noImportableFields`));return}p(e),h(!0)}catch{Y.error(i(`excelImport.schemaReadFailed`))}finally{d(!1)}}}let _=o?.find(e=>e.name===c)?.label??c;return m&&f?(0,$.jsx)(Rc,{open:m,onOpenChange:e=>{h(e),e||r()},objectName:c,objectLabel:_,fields:f,dataSource:t,initialFile:e,onComplete:e=>{Y.success(i(`excelImport.imported`,{count:e.importedRows,object:_}))}}):(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-muted/40 px-3 py-2 text-sm`,"data-excel-import-bar":!0,children:[(0,$.jsx)(pt,{variant:`secondary`,children:`CSV / Excel`}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i(`excelImport.importFrom`)}),(0,$.jsx)(`code`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i(`excelImport.into`)}),(0,$.jsx)(`select`,{className:`h-8 rounded-md border border-input bg-background px-2 text-sm`,value:c,onChange:e=>l(e.target.value),disabled:!o||o.length===0,children:(o??[]).map(e=>(0,$.jsx)(`option`,{value:e.name,children:e.label},e.name))}),(0,$.jsx)(q,{size:`sm`,onClick:g,disabled:!c||u,children:i(u?`excelImport.opening`:`excelImport.importAction`)}),(0,$.jsx)(q,{size:`sm`,variant:`ghost`,onClick:r,children:i(`excelImport.dismiss`)})]})}async function ef(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(),i=Array.isArray(r)?r:r?.drafts??r?.data?.drafts??[];return(Array.isArray(i)?i:[]).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}))}function tf(e={}){let{packageId:t,enabled:n=!0}=e,[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(null),s=(0,Q.useRef)(0),c=(0,Q.useCallback)(async()=>{if(!n)return;let e=++s.current;try{let n=await ef(t);if(s.current!==e)return;i(n),o(n.length)}catch{if(s.current!==e)return;i([]),o(null)}},[t,n]);return(0,Q.useEffect)(()=>{if(!n){s.current++,i([]),o(null);return}return c(),Ba(()=>{c()})},[c,n]),{count:a,entries:r,refresh:c}}function nf({packageId:e,idle:t}){let{refresh:n}=Yt(),r=Da(),{t:i}=J(),[a,o]=(0,Q.useState)(!1),{count:s,refresh:c}=tf({packageId:e,enabled:!!e});(0,Q.useEffect)(()=>{e&&t&&c()},[t,e,c]);let l=(0,Q.useCallback)(async()=>{if(e&&!a){o(!0);try{let t;try{t=await r.publishPackageDrafts(e)}catch(e){let t=rc(e?.body)||(e instanceof Error&&e.message?e.message:``)||i(`console.ai.pendingDrafts.failed`,{defaultValue:`Publish failed.`});Y.error(t);return}let a=Ts(t),o=(a?.issues??[]).filter(e=>e.severity===`error`);a?.seedError||o.length>0?Y.warning(i(`console.ai.pendingDrafts.publishedWithFindings`,{defaultValue:`Published, but the runtime probes reported problems: {{detail}}`,detail:[a?.seedError,...o.map(e=>e.message)].filter(Boolean).join(`; `)})):Y.success(i(`console.ai.pendingDrafts.published`,{defaultValue:`All pending changes are live.`}));try{await n?.()}catch{}Ha()}finally{o(!1)}}},[r,e,a,n,i]);return!e||(s??0)<=0?null:(0,$.jsxs)(`div`,{"data-testid":`pending-drafts-bar`,className:`pointer-events-auto flex w-full max-w-3xl items-center justify-between gap-3 rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-sm shadow-sm backdrop-blur`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:i(`console.ai.pendingDrafts.count`,{defaultValue:`{{count}} change(s) are not published yet — users cannot see them.`,count:s})}),(0,$.jsxs)(q,{size:`sm`,onClick:()=>void l(),disabled:a,className:`shrink-0`,children:[a?(0,$.jsx)(X,{className:`mr-1 h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Vr,{className:`mr-1 h-3.5 w-3.5`}),i(`console.ai.pendingDrafts.publish`,{defaultValue:`Publish`})]})]})}function rf(){let{theme:e,setTheme:t}=td(),{t:n}=J();return(0,$.jsxs)(it,{children:[(0,$.jsx)(yt,{asChild:!0,children:(0,$.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,$.jsx)(aa,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,$.jsx)(Oi,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),(0,$.jsx)(`span`,{className:`sr-only`,children:n(`console.theme.toggle`)})]})}),(0,$.jsxs)(Pt,{align:`end`,children:[(0,$.jsxs)(kt,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,$.jsx)(aa,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,$.jsxs)(kt,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,$.jsx)(Oi,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,$.jsxs)(kt,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,$.jsx)(Di,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}function af(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function of({name:e}){return(0,$.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:af(e)})}function sf(){let{t:e}=J(),t=r(),{organizations:n,activeOrganization:i,switchOrganization:a,getAuthConfig:o}=A(),[s,c]=(0,Q.useState)(!1),l=Vc()===`group`;(0,Q.useEffect)(()=>{let e=!1;return o?.().then(t=>{e||c(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[o]);let u=n??[],d=i??u[0]??null;if(!d||u.length<=1)return null;let f=async e=>{if(e.id!==d.id)try{await a(e.id),window.location.href=qd()}catch(e){console.error(`[WorkspaceSwitcher] switch failed`,e)}};return(0,$.jsxs)(it,{children:[(0,$.jsxs)(yt,{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,$.jsx)(of,{name:d.name}),(0,$.jsx)(`span`,{className:`hidden truncate sm:inline`,children:d.name}),(0,$.jsx)(Nr,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]}),(0,$.jsxs)(Pt,{align:`start`,className:`w-60`,children:[(0,$.jsx)(mt,{className:`text-xs text-muted-foreground`,children:l?e(`organization.switcher.groupLabel`,{defaultValue:`Working organization`}):e(`organization.switcher.label`,{defaultValue:`Switch organization`})}),l&&(0,$.jsx)(`p`,{className:`px-2 pb-1.5 text-xs font-normal leading-snug text-muted-foreground`,"data-testid":`workspace-switcher-group-hint`,children:e(`organization.switcher.groupHint`,{defaultValue:`New records are created here. Views show data from all your organizations.`})}),u.map(e=>(0,$.jsxs)(kt,{onClick:()=>f(e),className:`cursor-pointer gap-2`,children:[(0,$.jsx)(of,{name:e.name}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.id===d.id&&(0,$.jsx)(kr,{className:`h-4 w-4 shrink-0`})]},e.id)),(0,$.jsx)(Je,{}),(0,$.jsxs)(kt,{onClick:()=>t(`/organizations/${d.slug}/members`),className:`cursor-pointer gap-2`,"data-testid":`workspace-manage-members`,children:[(0,$.jsx)(ga,{className:`h-4 w-4`}),e(`organization.switcher.manageMembers`,{defaultValue:`Manage members`})]}),!s&&(0,$.jsxs)(kt,{onClick:()=>t(`/organizations?create=1`),className:`cursor-pointer gap-2`,"data-testid":`workspace-create`,children:[(0,$.jsx)(Ri,{className:`h-4 w-4`}),e(`organizations.create`,{defaultValue:`Create workspace`})]})]})]})}function cf(){let{t:e}=J(),{organizations:t,activeOrganization:n}=A(),r=Vc();if(!Bc(r))return null;let i=t??[];if(i.length!==1)return null;let a=n??i[0]??null;if(!a)return null;let o=e(`organization.current.label`,{defaultValue:`Current organization`});return(0,$.jsxs)(`span`,{"data-testid":`current-organization-indicator`,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`,title:`${o}: ${a.name}`,children:[(0,$.jsx)(of,{name:a.name}),(0,$.jsx)(`span`,{className:`sr-only`,children:o}),(0,$.jsx)(`span`,{className:`hidden truncate sm:inline`,children:a.name})]})}var lf=0;function uf(){let e=(0,Q.useRef)(Promise.resolve()),t=(0,Q.useRef)(!1);return{enqueue:(0,Q.useCallback)(t=>{e.current=e.current.then(t).catch(e=>{console.warn(`[app-shell] A language switch failed:`,e)})},[]),resetPending:t}}function df({enqueue:e,resetPending:t}){let n=(0,Q.useSyncExternalStore)(v,C,C),{i18n:r,changeLanguage:i}=J(),a=(0,Q.useRef)(i);a.current=i;let o=(0,Q.useRef)(r);return o.current=r,(0,Q.useEffect)(()=>{n<=lf||(lf=n,t.current=!0,e(async()=>{try{let e=Wn();if((o.current.language||``)===e||(await a.current(e),(o.current.language||``)!==e)||Gn()!==e)return;try{window.localStorage.removeItem(rr)}catch{}}finally{t.current=!1}}))},[n,e,t]),n}var ff=`sys_user`,pf=`locale`;function mf(e,t){if(!t)return null;if(t.includes(e))return e;let n=e.split(`-`)[0];return n&&n!==e&&t.includes(n)?n:null}function hf(){let{user:e}=A(),t=un(),{i18n:n,changeLanguage:r,offerableLanguages:i}=J(),a=uf(),{enqueue:o,resetPending:s}=a,c=df(a),l=e?.id?String(e.id):null,u=_n(ff,l??void 0),[d,f]=(0,Q.useState)({seq:0,column:null});(0,Q.useEffect)(()=>{if(!t||!l)return;let e=!1;return(async()=>{try{let n=await t.findOne(ff,l);if(e)return;let r=n?.locale,i=typeof r==`string`&&r.length>0?r:null;f(e=>({seq:e.seq+1,column:i}))}catch(e){console.warn("[app-shell] Could not read your language from `sys_user.locale`:",e)}})(),()=>{e=!0}},[t,l,u,c]);let p=(0,Q.useRef)(r);p.current=r;let m=(0,Q.useRef)(n);m.current=n;let h=i?i.join(`,`):null;(0,Q.useEffect)(()=>{if(!d.column)return;let e=h===null?null:h.split(`,`),t=mf(d.column,e);t&&(s.current||(m.current.language||``)!==t)&&o(async()=>{(m.current.language||``)!==t&&await p.current(t)})},[d,h,o,s])}function gf(){let{user:e}=A(),t=un(),{t:n,changeLanguage:r}=J(),i=e?.id?String(e.id):null,a=(0,Q.useRef)(r);a.current=r;let o=(0,Q.useRef)(n);return o.current=n,(0,Q.useCallback)(async e=>{if(await a.current(e),t&&i)try{await t.update(ff,i,{[pf]:e})}catch(e){let t=Fn(e)??(e instanceof Error?e.message:String(e));Y.error(o.current(`form.saveError`,{defaultValue:`Failed to save`}),{description:t}),console.warn("[app-shell] Could not save your language to `sys_user.locale`:",e)}},[t,i])}var _f=new Map([[`en`,`English`],[`zh`,`中文`],[`ja`,`日本語`],[`ko`,`한국어`],[`de`,`Deutsch`],[`fr`,`Français`],[`es`,`Español`],[`pt`,`Português`],[`ru`,`Русский`],[`ar`,`العربية`]]);function vf(e){let t=_f.get(e);if(t)return t;try{let t=new Intl.DisplayNames([e],{type:`language`}).of(e);return!t||t===e?e:t.charAt(0).toLocaleUpperCase(e)+t.slice(1)}catch{return e}}function yf(){let{t:e,language:t,offerableLanguages:n}=J(),r=gf();return n===null?null:(0,$.jsxs)(it,{children:[(0,$.jsx)(yt,{asChild:!0,children:(0,$.jsxs)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,$.jsx)(ii,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,$.jsx)(Pt,{align:`end`,className:`max-h-72 overflow-y-auto`,children:n.map(e=>(0,$.jsxs)(kt,{onClick:()=>void r(e),className:`gap-2`,children:[vf(e),t===e&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]},e))})]})}function bf(){let{t:e}=J(),{preferences:t,desktopPermission:n,desktopSupported:r,setToastEnabled:i,enableDesktop:a,disableDesktop:o}=io(),s=n===`denied`,c=!r||s,l=r?s?e(`notifications.desktopBlocked`,{defaultValue:`Blocked. Allow notifications for this site in your browser settings.`}):null:e(`notifications.desktopUnsupported`,{defaultValue:`This browser does not support desktop notifications.`});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-2 py-1.5 text-sm`,children:[(0,$.jsx)(`span`,{className:`text-foreground/80`,children:e(`notifications.toastEnabled`,{defaultValue:`In-app alerts`})}),(0,$.jsx)($e,{checked:t.toast,onCheckedChange:i,"data-testid":`notification-toast-toggle`,"aria-label":e(`notifications.toastEnabled`,{defaultValue:`In-app alerts`})})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3 px-2 py-1.5 text-sm`,children:[(0,$.jsx)(`span`,{className:c?`text-muted-foreground`:`text-foreground/80`,children:e(`notifications.desktopEnabled`,{defaultValue:`Desktop notifications`})}),(0,$.jsx)($e,{checked:t.desktop&&n===`granted`,disabled:c,onCheckedChange:e=>{e?a():o()},"data-testid":`notification-desktop-toggle`,"aria-label":e(`notifications.desktopEnabled`,{defaultValue:`Desktop notifications`})})]}),l&&(0,$.jsx)(`p`,{className:`px-2 pb-1.5 text-xs text-muted-foreground`,"data-testid":`notification-desktop-hint`,children:l})]})}var xf={connected:{labelKey:`topbar.connection.connected`,defaultValue:`Connected`,color:`text-green-500`,icon:Ir},connecting:{labelKey:`topbar.connection.connecting`,defaultValue:`Connecting…`,color:`text-yellow-500`,icon:X},reconnecting:{labelKey:`topbar.connection.reconnecting`,defaultValue:`Reconnecting…`,color:`text-yellow-500`,icon:X},disconnected:{labelKey:`topbar.connection.disconnected`,defaultValue:`Disconnected`,color:`text-muted-foreground`,icon:va},error:{labelKey:`topbar.connection.error`,defaultValue:`Connection Error`,color:`text-destructive`,icon:va}};function Sf({state:e,className:t}){let n=xf[e],{t:r}=J(),i=r(n.labelKey,{defaultValue:n.defaultValue}),a=n.icon,[o,s]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{if(e===`connected`){s(!0);let e=setTimeout(()=>s(!1),2e3);return()=>clearTimeout(e)}s(!1)},[e]),e===`connected`&&!o?null:(0,$.jsxs)(`div`,{className:Le(`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,$.jsx)(a,{className:Le(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:i})]})}function Cf({activeAppName:e,onAppChange:t}){let{apps:n}=Yt(),{t:r}=J(),{appLabel:i}=Xn(),a=n||[],o=a.filter(e=>e.active!==!1&&e.hidden!==!0),s=as(o,e)||as(a.filter(e=>e.active!==!1),e)||o[0];if(!s)return null;let c=i({name:s.name,label:ec(s.label,r)});return(0,$.jsxs)(it,{children:[(0,$.jsx)(yt,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`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,$.jsx)(`span`,{className:`truncate whitespace-nowrap`,children:c}),(0,$.jsx)(Ar,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,$.jsxs)(Pt,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,$.jsx)(mt,{className:`text-xs text-muted-foreground font-normal`,children:r(`layout.appSwitcher.switchApplication`,{defaultValue:`Switch Application`})}),(0,$.jsx)(Je,{}),o.map(e=>{let n=Wc(e.icon),a=i({name:e.name,label:ec(e.label,r)}),o=s.name===e.name;return(0,$.jsxs)(kt,{onClick:()=>t(ss(e)??e.name),className:`flex items-center gap-2.5 py-2`,children:[(0,$.jsx)(`div`,{className:`flex size-5 shrink-0 items-center justify-center rounded border bg-muted text-muted-foreground`,children:(0,$.jsx)(n,{className:`size-3`})}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:a}),o&&(0,$.jsx)(kr,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]})}var wf=(0,Q.createContext)(null);function Tf({children:e}){let[t,n]=(0,Q.useState)(null),r=(0,Q.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,$.jsx)(wf.Provider,{value:r,children:e})}function Ef(){return(0,Q.useContext)(wf)?.value??null}function Df(e){let t=(0,Q.useContext)(wf),n=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!t)return;let r=e??null;return t.setValue(r),n.current=r,()=>{t.setValue(null)}},[t,e])}function Of(e){let{views:t,activeViewId:n,onChange:r,triggerLabel:i,enabled:a=!0}=e,o=(0,Q.useRef)(r);o.current=r;let s=(0,Q.useCallback)(e=>o.current(e),[]);Df((0,Q.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}var kf=(0,Q.createContext)(null);function Af({children:e}){let{open:t,setOpen:n,openOverlay:r,closeOverlay:i,toggleOverlay:a}=Xu(Qo,{alias:`cmdk`});(0,Q.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,Q.useMemo)(()=>({open:t,openCommandPalette:r,closeCommandPalette:i,toggleCommandPalette:a,setOpen:n}),[t,r,i,a,n]);return(0,$.jsx)(kf.Provider,{value:o,children:e})}function jf(){return(0,Q.useContext)(kf)||{open:!1,openCommandPalette:()=>{},closeCommandPalette:()=>{},toggleCommandPalette:()=>{},setOpen:()=>{}}}var Mf=Object.freeze([]),Nf=new WeakMap;function Pf(e,t){let n=Nf.get(e);n||(n=new WeakMap,Nf.set(e,n));let r=n.get(t);return r||(r=Object.freeze({views:e,objects:t}),n.set(t,r)),r}function Ff(e){return Array.isArray(e)&&e.length>0?e:Mf}function If(){let e=Yt();return Pf(Ff(e.getItemsByType(`view`)),Ff(e.getItemsByType(`object`)))}function Lf(e){return!!e&&typeof e==`object`}function Rf(e,t,n){if(!n)return!1;if(e.views.some(e=>Lf(e)&&e.name===n))return!0;if(!t)return!1;let r=e.objects.find(e=>Lf(e)&&e.name===t),i=Lf(r)?r.listViews:void 0;return Lf(i)&&Object.prototype.hasOwnProperty.call(i,n)&&Lf(i[n])}var zf=Q.forwardRef(({className:e,onClick:t,"aria-label":n,title:r,...i},a)=>{let{toggleSidebar:o}=zt(),{t:s}=J(),c=String(n||r||s(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`}));return(0,$.jsxs)(q,{ref:a,"data-sidebar":`trigger`,variant:`ghost`,size:`icon`,className:Le(`h-7 w-7`,e),"aria-label":c,title:c,onClick:e=>{t?.(e),o()},...i,children:[(0,$.jsx)(Pi,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:c})]})});zf.displayName=`LocalizedSidebarTrigger`;function Bf({className:e}){let{t}=J(),n=Zs();if(n!==`preview`&&n!==`beta`)return null;let r=n===`beta`?t(`topbar.stage.beta`,{defaultValue:`Beta`}):t(`topbar.stage.preview`,{defaultValue:`Preview`}),i=t(`topbar.stage.tooltip`,{defaultValue:`This platform is in preview — features may change.`});return(0,$.jsx)(pt,{variant:`secondary`,title:i,"aria-label":i,"data-testid":`platform-preview-badge`,className:Le(`shrink-0 cursor-default select-none rounded-md px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide`,e),children:r})}function Vf(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Hf(e,t){switch(e){case`marketplace`:return t(`console.breadcrumb.marketplace`);case`settings`:return t(`console.breadcrumb.settings`);case`apps`:return t(`console.breadcrumb.apps`);case`profile`:return t(`console.breadcrumb.profile`);case`approvals`:return t(`console.breadcrumb.approvals`);case`ai-approvals`:return t(`console.breadcrumb.aiApprovals`);case`audit-log`:return t(`console.breadcrumb.auditLog`);default:return}}function Uf(){return(0,$.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var Wf=[];function Gf({variant:e,appName:t,objects:n,connectionState:i,presenceUsers:a,activities:o,activeAppName:s,onAppChange:c}){let l=e??(t?`app`:`home`),u=l===`app`,d=g(),m=f(),h=r(),_=Qu(),{isOnline:v}=jn(),{openCommandPalette:y}=jf(),{openOverlay:b}=Xu(es),{user:x,signOut:C,isAuthEnabled:w,organizations:T,activeOrganization:E,isOrganizationsLoading:D,getAuthConfig:O}=A(),j=un(),{enabled:M}=vo(),{isAdmin:N}=S(),ee=Gc(),{t:P}=J(),{objectLabel:F,dashboardLabel:te,pageLabel:I,reportLabel:ne,viewLabel:re,appLabel:L}=Xn(),{apps:ie,dashboards:ae,pages:oe,reports:R}=Yt(),se=If(),{currentAppName:ce,recordTitle:le}=Ro(),z=Ef(),[ue,de]=(0,Q.useState)(null),fe=(0,Q.useCallback)(async()=>{if(ue===null)try{let e=j?.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:[];de(n.map(e=>({name:e?.name,label:e?.label,_packageId:e?._packageId})).filter(e=>e.name))}catch{de([])}},[ue,j]),pe=uo(),{notifications:B,unreadCount:me,pendingApprovalsCount:he,markAllRead:ge,markRead:_e,markManyRead:V}=Oo(),ve=Yo(),H=a??(ve.length>0?ve:Wf),U=o??pe,ye=D||(T??[]).length>0||!!E,[be,xe]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=!1;return O?.().then(t=>{e||xe(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[O]);let W=d.pathname.split(`/`).filter(Boolean),Se=m.appName||W[1],Ce=W[2],we=`/apps/${Se}`,Te=n??[],Ee=as(ie||[],s||ce||Se),De=new Set,Oe=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&De.add(t.objectName),t.children&&Oe(t.children)};Oe(Ee?.navigation||[]);for(let e of Ee?.areas||[])Oe(e.navigation||[]);let ke=De.size>0?Te.filter(e=>De.has(e.name)):Te.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`)),Ae=Ee?._packageId,je=Ae?(ue??[]).filter(e=>e._packageId===Ae):[],Me=u?ls(Ee,N&&ee,{type:Ce,name:W[3]}):null,Ne=ke.map(e=>({label:F(e),href:`${we}/${e.name}`})),G=[];if(u){if(Ce===`dashboard`){if(G.push({label:P(`console.breadcrumb.dashboards`),href:we}),W[3]){let e=W[3],t=$s(ae,e,Ee?._packageId);G.push({label:t?.label||te({name:e,label:Vf(e)})})}}else if(Ce===`page`){if(G.push({label:P(`console.breadcrumb.pages`),href:we}),W[3]){let e=W[3],t=$s(oe,e,Ee?._packageId)?.label||Vf(e);G.push({label:I({name:e,label:t})})}}else if(Ce===`report`){if(G.push({label:P(`console.breadcrumb.reports`),href:we}),W[3]){let e=W[3],t=$s(R,e,Ee?._packageId)?.label||Vf(e);G.push({label:ne({name:e,label:t})})}}else if(Ce===`system`)G.push({label:P(`console.breadcrumb.system`)}),W[3]&&G.push({label:Hf(W[3],P)??Vf(W[3])});else if(Ce){let e=Te.find(e=>e.name===Ce);if(e){if(W[3]===`record`&&W[4]){let e=Zo(new URLSearchParams(d.search).get(qo));e.forEach((t,n)=>{let r=Te.find(e=>e.name===t.o);G.push({label:r?F(r):Vf(t.o),href:`${we}/${t.o}`});let i=t.i.length>12?`${t.i.slice(0,8)}…`:t.i;G.push({label:t.t||`#${i}`,href:$o(we,t,e.slice(0,n))})})}if(G.push({label:F(e),href:`${we}/${Ce}`,siblings:Ne}),W[3]===`record`&&W[4]){let e=W[4].length>12?`${W[4].slice(0,8)}…`:W[4],t=le?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;G.push({label:n||`#${e}`})}else if(W[3]===`view`&&W[4]){let t=W[4],n=e.listViews||e.list_views||{},r=Ln(t,Object.keys(n),e.name),i=r?n[r]:void 0,a=i&&(i.label||i.title)||Vf(t),o=i&&Rf(se,e.name,r)?a:re(e.name,t,a);G.push({label:o})}}}}let Pe=G[G.length-1]?.label||t||``;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between w-full h-full`,children:[(0,$.jsxs)(`div`,{className:`flex items-center min-w-0 flex-1`,children:[(0,$.jsx)(p,{to:_,className:Le(`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors overflow-hidden`,u&&`hidden sm:flex`),title:Gs(),children:Rs()?(0,$.jsx)(`img`,{src:Rs(),alt:Gs(),className:`h-full w-full object-contain`}):(0,$.jsx)(fi,{className:`h-4 w-4`})}),l===`home`&&(0,$.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:Gs()}),(0,$.jsx)(Bf,{className:`ml-2 hidden sm:inline-flex`}),(0,$.jsx)(sf,{}),(0,$.jsx)(cf,{}),l===`orgs`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Uf,{}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:P(`organizations.title`,{defaultValue:`Workspaces`})})]}),u&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(zf,{className:`lg:hidden shrink-0 ml-1`,"aria-label":P(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`})}),s&&c?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,$.jsx)(Uf,{})}),(0,$.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,$.jsx)(Cf,{activeAppName:s,onAppChange:c})})]}):t?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,$.jsx)(Uf,{})}),(0,$.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,G.map((e,t)=>{let n=t===G.length-1;return(0,$.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,$.jsx)(Uf,{}),e.siblings&&e.siblings.length>1?(0,$.jsxs)(it,{children:[(0,$.jsxs)(yt,{className:`flex items-center gap-1 rounded-md px-1.5 py-1 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring hover:bg-accent hover:text-foreground ${n?`text-foreground/80`:`text-foreground/60`}`,children:[e.label,(0,$.jsx)(Ar,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,$.jsxs)(Pt,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,$.jsx)(mt,{className:`text-xs text-muted-foreground font-normal`,children:P(`topbar.switchObject`,{defaultValue:`Switch Object`})}),(0,$.jsx)(Je,{}),e.siblings.map(e=>(0,$.jsx)(kt,{asChild:!0,children:(0,$.jsx)(p,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,$.jsx)(p,{to:e.href,className:`rounded-md px-1.5 py-1 text-sm font-medium transition-colors hover:bg-accent hover:text-foreground truncate max-w-[160px] ${n?`text-foreground/80`:`text-foreground/60`}`,children:e.label}):(0,$.jsx)(`span`,{className:`px-1.5 py-1 text-sm font-medium truncate max-w-[160px] ${n?`text-foreground/80`:`text-foreground/60`}`,children:e.label})]},t)}),z&&z.views.length>0?z.views.length>1?(0,$.jsxs)(it,{children:[(0,$.jsx)(yt,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:`sm:hidden flex items-center gap-0.5 min-w-0 ml-1 rounded-md px-1.5 py-1 text-sm font-medium hover:bg-accent active:bg-accent/80 transition-colors`,"aria-label":P(`topbar.switchView`,{defaultValue:`Switch view`}),children:[(0,$.jsx)(`span`,{className:`truncate max-w-[180px]`,children:z.triggerLabel??z.views.find(e=>e.id===z.activeViewId)?.label??Pe}),(0,$.jsx)(Ar,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(Pt,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:z.views.map(e=>{let t=e.id===z.activeViewId;return(0,$.jsxs)(kt,{onSelect:()=>{t||z.onChange(e.id)},className:`gap-2`,children:[e.icon?(0,$.jsx)(`span`,{className:`shrink-0 text-muted-foreground [&>svg]:h-4 [&>svg]:w-4`,children:e.icon}):null,(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.locked?(0,$.jsx)(_i,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,$.jsx)(kr,{className:`h-4 w-4 shrink-0 text-foreground`,"aria-hidden":!0}):null]},e.id)})})]}):(0,$.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:z.triggerLabel??z.views[0].label}):(0,$.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:Pe})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1 shrink-0 [&>*+*[data-topbar-group]]:ml-1 [&>[data-topbar-group]+[data-topbar-group]]:border-l [&>[data-topbar-group]+[data-topbar-group]]:border-border/60 [&>[data-topbar-group]+[data-topbar-group]]:pl-1 sm:[&>[data-topbar-group]+[data-topbar-group]]:pl-2 sm:[&>[data-topbar-group]+[data-topbar-group]]:ml-2`,children:[!v&&(0,$.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,$.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-yellow-500 animate-pulse`}),P(`topbar.offline`,{defaultValue:`Offline`})]}),u&&i&&(0,$.jsx)(Sf,{state:i}),u&&H.length>0&&(0,$.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:P(`topbar.usersOnline`,{defaultValue:`Users currently online`}),children:(0,$.jsx)(Jo,{users:H,size:`sm`,maxVisible:3,showStatus:!0})}),(0,$.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 sm:gap-1 shrink-0`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-testid":`action:command-palette:open`,"aria-label":P(`console.search`,{defaultValue:`Search…`}),"aria-keyshortcuts":`Meta+K Control+K`,onClick:y,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,$.jsx)(Gi,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:P(`console.search`,{defaultValue:`Search…`})}),(0,$.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,$.jsx)(`span`,{className:`text-xs`,children:`⌘`}),`K`]})]}),(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`lg:hidden h-8 w-8 shrink-0`,"data-testid":`action:command-palette:open-mobile`,onClick:y,"aria-label":P(`console.search`,{defaultValue:`Search…`}),children:(0,$.jsx)(Gi,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[(0,$.jsx)(no,{notifications:B,unreadCount:me,pendingApprovalsCount:he,activities:U,onMarkAllRead:ge,onMarkRead:_e,onMarkManyRead:V}),Me&&(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"data-testid":`app-design-in-studio-button`,"aria-label":P(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),title:P(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),children:(0,$.jsx)(p,{to:Me,children:(0,$.jsx)(oi,{className:`h-4 w-4`})})}),M&&(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"aria-label":P(`topbar.aiAssistant`,{defaultValue:`AI Assistant`}),children:(0,$.jsx)(p,{to:`/ai`,children:(0,$.jsx)(xr,{className:`h-4 w-4`})})}),(0,$.jsxs)(it,{onOpenChange:e=>{e&&fe()},children:[(0,$.jsx)(yt,{asChild:!0,children:(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 hidden md:flex shrink-0`,"aria-label":P(`sidebar.helpTooltip`,{defaultValue:`Help & Documentation`}),children:(0,$.jsx)(Lr,{className:`h-4 w-4`})})}),(0,$.jsxs)(Pt,{align:`end`,className:`min-w-56 rounded-lg`,sideOffset:4,children:[je.length>0&&Ae?(0,$.jsxs)(kt,{className:`cursor-pointer`,onClick:()=>h(je.length===1?`/apps/${Ae}/docs/${je[0].name}`:`/apps/${Ae}/docs`),children:[(0,$.jsx)(br,{className:`mr-2 h-4 w-4`}),P(`help.appDocs`,{defaultValue:`This app's docs`})]}):null,(0,$.jsxs)(kt,{className:`cursor-pointer`,onClick:()=>h(`/docs`),children:[(0,$.jsx)(fi,{className:`mr-2 h-4 w-4`}),P(`help.allDocs`,{defaultValue:`All documentation`})]}),u?(0,$.jsxs)(kt,{className:`cursor-pointer`,"data-testid":`action:keyboard-shortcuts:open`,onClick:b,children:[(0,$.jsx)(di,{className:`mr-2 h-4 w-4`}),P(`help.keyboardShortcuts`,{defaultValue:`Keyboard shortcuts`})]}):null,(0,$.jsx)(Je,{}),(0,$.jsx)(kt,{asChild:!0,className:`cursor-pointer`,children:(0,$.jsxs)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,$.jsx)(Jr,{className:`mr-2 h-4 w-4`}),P(`help.onlineDocs`,{defaultValue:`Online documentation`})]})})]})]})]}),(0,$.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[` `,(0,$.jsxs)(it,{children:[(0,$.jsx)(yt,{asChild:!0,children:(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,$.jsxs)(qe,{className:`h-7 w-7 rounded-full`,children:[(0,$.jsx)(At,{src:x?.image,alt:x?.name??`User`}),(0,$.jsx)(wt,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:k(x)})]})})}),(0,$.jsxs)(Pt,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,$.jsx)(mt,{className:`p-0 font-normal`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,$.jsxs)(qe,{className:`h-8 w-8 rounded-lg`,children:[(0,$.jsx)(At,{src:x?.image,alt:x?.name??`User`}),(0,$.jsx)(wt,{className:`rounded-lg bg-primary text-primary-foreground`,children:k(x)})]}),(0,$.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,$.jsx)(`span`,{className:`truncate font-semibold`,children:x?.name??`User`}),(0,$.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:x?.email??``})]})]})}),(0,$.jsx)(Je,{}),(0,$.jsxs)(St,{children:[(0,$.jsxs)(kt,{onClick:()=>h(`/apps/account/component/account/profile_card`),className:`cursor-pointer`,children:[(0,$.jsx)(ha,{className:`mr-2 h-4 w-4`}),P(`user.profile`,{defaultValue:`Profile`})]}),ye&&(0,$.jsxs)(kt,{onClick:()=>h(`/organizations?manage=1`),className:`cursor-pointer`,"data-testid":`header-my-organizations`,children:[(0,$.jsx)(wr,{className:`mr-2 h-4 w-4`}),P(`organizations.mine`,{defaultValue:`My Workspaces`})]}),ye&&!be&&(0,$.jsxs)(kt,{onClick:()=>h(`/organizations?create=1`),className:`cursor-pointer`,"data-testid":`header-create-workspace`,children:[(0,$.jsx)(Ri,{className:`mr-2 h-4 w-4`}),P(`organizations.create`,{defaultValue:`Create workspace`})]}),(ie||[]).filter(e=>e.active!==!1&&e.hidden===!0&&e.name!==`account`).map(e=>{let t=Wc(e.icon),n=L({name:e.name,label:ec(e.label,P)});return(0,$.jsxs)(kt,{onClick:()=>h(`/apps/${ss(e)??e.name}`),className:`cursor-pointer`,children:[(0,$.jsx)(t,{className:`mr-2 h-4 w-4`}),n]},`hidden_app_${e.name}`)})]}),(0,$.jsx)(Je,{}),(0,$.jsx)(mt,{className:`text-[11px] font-normal text-muted-foreground uppercase tracking-wide px-2`,children:P(`user.preferences`,{defaultValue:`Preferences`})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,$.jsx)(`span`,{className:`text-foreground/80`,children:P(`user.theme`,{defaultValue:`Theme`})}),(0,$.jsx)(rf,{})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,$.jsx)(`span`,{className:`text-foreground/80`,children:P(`user.language`,{defaultValue:`Language`})}),(0,$.jsx)(yf,{})]}),(0,$.jsx)(bf,{}),w&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Je,{}),(0,$.jsxs)(kt,{className:`text-destructive focus:text-destructive`,onClick:()=>C(),children:[(0,$.jsx)(vi,{className:`mr-2 h-4 w-4`}),P(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var Kf=`ai-chat-dock-width`,qf=`ai-chat-dock-expanded`,Jf=`ai-chat-studio-dock-expanded`,Yf=`ai-chat-studio-dock-width`;function Xf(e,t){let n=t>0?Math.max(340,t-520):1/0;return Math.min(Math.max(e,340),n)}function Zf(e){return Xf(e,e)}function Qf(e){return e===`1`||e!==`0`&&null}function $f(e,t){try{let n=Qf(window.sessionStorage.getItem(e));return n===null?t:n}catch{return t}}function ep(e,t){try{window.sessionStorage.setItem(e,t?`1`:`0`)}catch{}}function tp(){ep(qf,!0)}var np=`ai-chat-dock-return-to`;function rp(e){try{window.sessionStorage.setItem(np,e)}catch{}}function ip(){try{let e=window.sessionStorage.getItem(np);return e&&e.startsWith(`/`)&&!e.startsWith(`//`)?e:void 0}catch{return}}function ap(e){return!(e.metaKey||e.ctrlKey)||!e.shiftKey||e.altKey?null:e.key.toLowerCase()===`i`?`toggle`:null}async function op(e){return(await ef(e)).length}var sp={"studio-build":`build`,default:`ask`};function cp(e,t,n=!0){return t&&n&&Ns(`build`,e.map(e=>e.name))!==void 0}function lp(e,t,n=!0){return cp(e,t,n)?e.filter(e=>!ws(e.name)):e}function up(e,{agents:t,appDefaultAgent:n,aiStudioEnabled:r=!0,canAuthorMetadata:i=!1}){let a=t.map(e=>e.name),o=(ys(n)?n:void 0)??sp[e]??sp.default,s=!r&&Cs(o)?`ask`:o,c=ws(s)&&cp(t,i,r)?`build`:s;return Ns(c,a)??xs(t)}function dp(e){return{status:`drafted`,drafted:e.items,...e.summary?{summary:e.summary}:{},...e.packageId?{packageId:e.packageId}:{},...e.autoPublishable?{autoPublishable:!0}:{},...e.failedCount?{failed:Array.from({length:e.failedCount},()=>null)}:{},...e.materialized?{materialized:!0}:{},...e.verification?{verification:e.verification}:{},...e.issues&&e.issues.length?{issues:e.issues}:{},...e.nextSteps&&e.nextSteps.length?{nextSteps:e.nextSteps}:{},...e.kind===`edit`?{kind:`edit`}:{}}}function fp(e){return{status:`blueprint_proposed`,...e.summary?{summary:e.summary}:{},counts:e.counts,questions:e.questions,...e.targetApp?{targetApp:e.targetApp}:{},blueprint:{objects:e.objects.map(e=>({name:e.name,...e.label?{label:e.label}:{},fields:Array.from({length:e.fieldCount},()=>null)})),assumptions:e.assumptions}}}function pp(e){return e.kind===`published`?{status:`published`}:e.kind===`failed`&&e.dispatchError?{error:e.error??`replay dispatch failed`}:{status:`drafted`,...e.packageId?{packageId:e.packageId}:{},...e.kind===`failed`?{publishFailed:!0,...e.outcome?{publishOutcome:e.outcome}:{},...e.error?{publishError:e.error}:{}}:{}}}function mp(e){return{status:`pending_approval`,pendingActionId:e}}var hp=`objectstack:ai-chat-conversation-id`,gp=`objectstack:ai-chat-messages`;function _p(e,t){return t?`${hp}:${e}:${t}`:`${hp}:${e}`}function vp(e){try{return localStorage.getItem(e)??void 0}catch{return}}function yp(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function bp(e){return`${gp}:${e}`}function xp(){try{let e=[];for(let t=0;t<localStorage.length;t+=1){let n=localStorage.key(t);n&&(n.startsWith(hp)||n.startsWith(gp))&&e.push(n)}e.forEach(e=>localStorage.removeItem(e))}catch{}}function Sp(e){try{let t=localStorage.getItem(bp(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`&&(e.role===`user`||e.role===`assistant`||e.role===`system`)&&Array.isArray(e.parts)):[]}catch{return[]}}function Cp(e,t){if(e)try{if(t.length===0){localStorage.removeItem(bp(e));return}localStorage.setItem(bp(e),JSON.stringify(t))}catch{}}function wp(e){return e.map(e=>{let t=[];if(e.content&&t.push({type:`text`,text:e.content}),e.role===`assistant`)for(let n of e.toolInvocations??[]){let e=n.replayOutcome?pp(n.replayOutcome):n.draftReview?dp(n.draftReview):n.proposedPlan?fp(n.proposedPlan):n.pendingActionId?mp(n.pendingActionId):void 0;t.push({type:`tool-${n.toolName}`,toolCallId:n.toolCallId,toolName:n.toolName,state:n.state??(n.errorText?`output-error`:`output-available`),...n.errorText?{errorText:n.errorText}:{},...n.approval?{approval:n.approval}:{},...n.pendingActionId?{pendingActionId:n.pendingActionId}:{},...e===void 0?{}:{output:e}})}if(t.length!==0)return{id:e.id,role:e.role,parts:t}}).filter(e=>!!e)}function Tp(e){return typeof e==`string`?e?[{type:`text`,text:e}]:[]:Array.isArray(e)?e.map(e=>{if(typeof e==`string`)return e?{type:`text`,text:e}:void 0;if(e&&typeof e==`object`&&`type`in e&&typeof e.type==`string`)return e;if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return{type:`text`,text:e.text}}).filter(e=>!!e):e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts)?Tp(e.parts):[]}var Ep=new Set([`approval-requested`,`approval-responded`]);function Dp(e,t){for(let n of Tp(e)){let e=typeof n.toolCallId==`string`?n.toolCallId:void 0;if(!e)continue;let r=t.get(e);if(!r)continue;let i=n.output??n.result;if(i===void 0)continue;r.output=i;let a=n.errorText,o=n.isError||typeof a==`string`?`output-error`:`output-available`,s=typeof r.state==`string`&&Ep.has(r.state)?r.state:void 0,c=hs(i)?`approval-requested`:s;r.state=c&&o!==`output-error`?c:o,typeof a==`string`&&(r.errorText=a)}}function Op(e){if(!e)return[];let t=[],n=new Map;return e.forEach((e,r)=>{let i=e.role;if(i===`tool`){Dp(e.content,n);return}if(i!==`user`&&i!==`assistant`&&i!==`system`)return;let a=Tp(e.content);if(a.length!==0){if(i===`assistant`)for(let e of a){e.type===`tool-call`&&typeof e.toolName==`string`&&e.toolName&&(e.type=`tool-${e.toolName}`);let t=typeof e.toolCallId==`string`?e.toolCallId:void 0;t&&(e.type===`tool-call`||e.type.startsWith(`tool-`))&&n.set(t,e)}t.push({id:e.id??`msg-${r}`,role:i,parts:a})}}),t}function kp(e){if(typeof e==`string`&&e)try{let t=JSON.parse(e);return Array.isArray(t)?t:void 0}catch{return}}function Ap(e){return e?e.map(e=>{let t=e.id,n=typeof e.content==`string`?e.content:``;if(e.role===`assistant`){let r=kp(e.tool_calls);if(r&&r.length>0){let e=[];return n&&e.push({type:`text`,text:n}),e.push(...r),{id:t,role:`assistant`,content:e}}return{id:t,role:`assistant`,content:n}}if(e.role===`tool`){let r=kp(e.content);return r&&r.length>0&&r[0]?.type===`tool-result`?{id:t,role:`tool`,content:r}:{id:t,role:`tool`,content:[{type:`tool-result`,toolCallId:e.tool_call_id??``,toolName:`unknown`,output:{type:`text`,value:n}}]}}return{id:t,role:e.role,content:n}}):[]}async function jp(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(n.status===404||n.status===403)return null;if(!n.ok)throw Error(`GET conversation failed: ${n.status}`);return await n.json()}async function Mp(e){let t=await fetch(`${e}/conversations`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:`{}`});if(!t.ok)throw Error(`POST conversation failed: ${t.status}`);return await t.json()}async function Np(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function Pp(e){let{userId:t,scope:n,apiBase:r,activeId:i,forceNew:a,resumeMode:o=`resume`,legacyScope:s,adoptLegacy:c}=e,l=(0,Q.useRef)(c);l.current=c;let[u,d]=(0,Q.useState)(void 0),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(!!t),g=(0,Q.useRef)(!0),_=(0,Q.useRef)(void 0),v=(0,Q.useRef)(void 0),y=(0,Q.useRef)(t);(0,Q.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,Q.useEffect)(()=>{let e=y.current;y.current=t,e&&e!==t&&xp()},[t]),(0,Q.useEffect)(()=>{if(!t){d(void 0),p([]),h(!1),_.current=void 0,v.current=void 0;return}let e=v.current!==n;if(!i&&!a&&!e&&_.current===t&&u)return;let c=!1,f=_p(t,n);return!i&&(a||e&&_.current===t)&&(d(void 0),p([])),h(!0),(async()=>{let e=i;try{if(i){let a=await jp(r,i);if(c)return;if(a){yp(f,a.id),d(a.id);let e=Op(a.messages),r=e.length>0?e:Sp(a.id);(r.length>0||a.id!==u)&&p(r),_.current=t,v.current=n;return}e=void 0,yp(f,void 0),Cp(i,[])}else if(!a){let i=vp(f);if(e=i,!i&&s&&l.current){let e=vp(_p(t,s));if(e){try{let i=await jp(r,e);if(c)return;if(i){let e=Op(i.messages),r=e.length>0?e:Sp(i.id);if(l.current?.(r)){yp(f,i.id),d(i.id),p(r),_.current=t,v.current=n;return}}}catch{}if(c)return}}if(i){let a=await jp(r,i);if(c)return;if(a){let r=Op(a.messages);if(o!==`fresh`||r.length===0){d(a.id),p(o===`fresh`?[]:r.length>0?r:Sp(a.id)),_.current=t,v.current=n;return}e=void 0}else e=void 0,yp(f,void 0),Cp(i,[])}}let m=await Mp(r);if(c)return;yp(f,m.id),d(m.id),p(Op(m.messages)),_.current=t,v.current=n}catch{if(c||e&&e===u)return;d(void 0),p([])}finally{c||h(!1)}})(),()=>{c=!0}},[t,n,r,i,a,o,s]);let b=(0,Q.useCallback)(async()=>{if(!t)return;let e=_p(t,n);h(!0);try{u&&await Np(r,u),Cp(u,[]),yp(e,void 0);let t=await Mp(r);if(yp(e,t.id),Cp(t.id,[]),!g.current)return;d(t.id),p([])}catch{g.current&&(d(void 0),p([]))}finally{g.current&&h(!1)}},[u,t,n,r]),x=(0,Q.useCallback)(async()=>{if(!t)return;let e=_p(t,n);h(!0);try{let i=await Mp(r);if(yp(e,i.id),Cp(i.id,[]),!g.current)return;d(i.id),p([]),_.current=t,v.current=n}catch{}finally{g.current&&h(!1)}},[t,n,r]),S=(0,Q.useCallback)(e=>{t&&u&&(yp(_p(t,e),u),_.current=t,v.current=e)},[t,u]);return{conversationId:u,conversationScope:v.current,initialMessages:f,isLoading:m,reset:b,startNew:x,rekeyScope:S}}function Fp(e){if(!e||e.length===0)return!1;let t=e[e.length-1];return!t||t.role!==`assistant`?!1:t.parts.some(e=>e.type===`text`&&String(e.text??``).trim().length>0)}function Ip(e){let{chatApi:t,conversationId:n}=e,[r,i]=(0,Q.useState)(!1),a=(0,Q.useRef)(void 0);return{errorSuppressed:r,handleChatError:(0,Q.useCallback)(async e=>{if(e?.notSent){i(!1);return}let r=t?.replace(/\/agents\/[^/]+\/chat$/,``);if(!n||!r){i(!1);return}try{let e=Op((await jp(r,n))?.messages);if(Fp(e)&&a.current){a.current(e),i(!0);return}}catch{}i(!1)},[n,t]),setMessagesRef:a,resetSuppression:(0,Q.useCallback)(()=>i(!1),[])}}function Lp(e){return e&&Cs(e)?`build`:`ask`}function Rp({appId:e,product:t}){return e?`app:${e}:${t}`:t}var zp=new Set([`new chat`,`new conversation`,`untitled`,`新对话`]);function Bp(e){let t=e?.trim().toLowerCase();return!t||zp.has(t)}function Vp(e){let t=e.messages;if(!t||t.length===0)return;for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.role===`user`){let e=Hp(n.content);if(e)return e}}let n=t[t.length-1];return Hp(n?.content)}function Hp(e){if(typeof e==`string`)return e.slice(0,140);if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return e.text.slice(0,140);if(e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts))return Hp(e.parts);if(Array.isArray(e)){let t=e.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`?e.text:``).join(``);return t?t.slice(0,140):void 0}}function Up(e){let t=e.title?.trim(),n=Vp(e)??Hp(e.preview);return{id:e.id,title:Bp(t)?void 0:t,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:n}}async function Wp(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(!n.ok)return;let r=await n.json();return Up(`conversation`in r&&r.conversation?r.conversation:r)}function Gp(e){let{userId:t,apiBase:n,limit:r=50,refreshKey:i}=e,[a,o]=(0,Q.useState)([]),[s,c]=(0,Q.useState)(!!t),[l,u]=(0,Q.useState)(void 0),[d,f]=(0,Q.useState)(0),p=(0,Q.useCallback)(async()=>{f(e=>e+1)},[]),m=(0,Q.useCallback)(async e=>{try{await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`})}finally{o(t=>t.filter(t=>t.id!==e))}},[n]),h=(0,Q.useCallback)(async(e,t)=>{let r=t.trim();o(t=>t.map(t=>t.id===e?{...t,title:r||void 0}:t));let i=await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:r})});if(!i.ok)throw f(e=>e+1),Error(`PATCH conversation failed: ${i.status}`)},[n]);return(0,Q.useEffect)(()=>{if(!t){o([]),c(!1),u(void 0);return}let e=!1;return c(!0),u(void 0),(async()=>{try{let t=await fetch(`${n}/conversations?limit=${encodeURIComponent(String(r))}`,{credentials:`include`});if(!t.ok)throw Error(`GET conversations failed: ${t.status}`);let i=await t.json(),a=Array.isArray(i)?i:i.conversations??i.items??[];if(e)return;let s=a.map(Up).sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));o(s);let c=s.filter(e=>!e.title&&!e.preview).slice(0,20);if(c.length>0){let t=await Promise.all(c.map(e=>Wp(n,e.id).catch(()=>void 0)));if(e)return;let r=new Map(t.filter(e=>!!(e?.preview||e?.title)).map(e=>[e.id,e]));r.size>0&&o(e=>e.map(e=>{let t=r.get(e.id);return t?{...e,title:e.title??t.title,preview:e.preview??t.preview}:e}))}}catch(t){if(e)return;u(t instanceof Error?t:Error(String(t))),o([])}finally{e||c(!1)}})(),()=>{e=!0}},[t,n,r,d,i]),{conversations:a,isLoading:s,error:l,refetch:p,remove:m,rename:h}}function Kp(e,t,n){if(!e)return``;let r=new Date(e);if(Number.isNaN(r.getTime()))return``;let i=Date.now()-r.getTime(),a=6e4,o=60*a,s=24*o;return i<a?t(`console.ai.justNow`):i<o?t(`console.ai.minutesAgo`,{count:Math.floor(i/a)}):i<s?t(`console.ai.hoursAgo`,{count:Math.floor(i/o)}):i<7*s?t(`console.ai.daysAgo`,{count:Math.floor(i/s)}):r.toLocaleDateString(n)}function qp(e,t){if(!e)return``;let n=new Date(e);return Number.isNaN(n.getTime())?``:n.toLocaleString(t)}var Jp=[`today`,`yesterday`,`previous7Days`,`previous30Days`,`older`],Yp={today:`Today`,yesterday:`Yesterday`,previous7Days:`Previous 7 days`,previous30Days:`Previous 30 days`,older:`Older`};function Xp(e,t=Date.now()){let n=new Date(t);n.setHours(0,0,0,0);let r=n.getTime(),i=864e5,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 Jp.filter(e=>o[e].length>0).map(e=>({key:e,items:o[e]}))}function Zp({userId:e,apiBase:t,activeAgent:n,includeAskConversations:i,className:a,refreshKey:o,titleHints:s,onNavigate:c}){let{t:l}=J(),u=r(),{conversationId:d}=f(),{conversations:p,isLoading:m,error:h,remove:g,rename:_}=Gp({userId:e,apiBase:t,refreshKey:o}),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(void 0),S=n?Os(n):void 0,C=(0,Q.useMemo)(()=>{if(!n)return;let e=new Set(ks(n));if(i){for(let t of ks(`ask`))e.add(t);for(let t of ks(`build`))e.add(t)}return e},[n,i]),w=(0,Q.useMemo)(()=>p.map(e=>{let t=s?.[e.id]?.trim();return!t||e.title?.trim()||e.preview?.trim()?e:{...e,preview:t}}),[p,s]),T=(0,Q.useMemo)(()=>C?w.filter(e=>!e.agentId||C.has(e.agentId)||e.id===d):w,[w,C,d]),E=(0,Q.useMemo)(()=>{let e=v.trim().toLowerCase();return e?T.filter(t=>`${t.title??``} ${t.preview??``}`.toLowerCase().includes(e)):T},[T,v]),D=(0,Q.useCallback)(e=>{let t=e.agentId?Os(e.agentId):S;return t?`/ai/${t}/${e.id}`:`/ai/${e.id}`},[S]),O=(0,Q.useCallback)(()=>{u(S?`/ai/${S}?new=1`:`/ai?new=1`),c?.()},[u,S,c]),k=(0,Q.useCallback)(async(e,t)=>{e.stopPropagation(),await g(t),t===d&&(u(S?`/ai/${S}`:`/ai`,{replace:!0}),c?.())},[g,d,u,S,c]),A=(0,Q.useCallback)(async(e,t)=>{x(void 0);try{await _(e,t)}catch{}},[_]);return(0,$.jsxs)(`aside`,{className:Le(`flex h-full min-h-0 flex-col bg-muted/30`,a),"data-testid":`ai-conversations-sidebar`,children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:l(`console.ai.chats`)}),(0,$.jsxs)(q,{size:`sm`,variant:`outline`,onClick:O,"data-testid":`ai-new-chat`,children:[(0,$.jsx)(Ri,{className:`h-3.5 w-3.5`}),l(`console.ai.newChat`)]})]}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(Gi,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(K,{value:v,onChange:e=>y(e.target.value),placeholder:l(`console.ai.searchChats`),className:`h-7 pl-7 text-xs`,"data-testid":`ai-conversations-search`})]})]}),(0,$.jsx)(xe,{className:`flex-1 min-h-0`,children:m&&p.length===0?(0,$.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:l(`common.loading`)}):h?(0,$.jsx)(`div`,{className:`px-3 py-4 text-xs text-destructive`,children:h.message}):T.length===0?(0,$.jsxs)(ve,{className:`px-3 py-8`,children:[(0,$.jsx)(Ti,{className:`h-8 w-8 text-muted-foreground`}),(0,$.jsx)(pe,{children:l(`console.ai.noChatsYet`)}),(0,$.jsx)(ge,{children:l(`console.ai.noChatsDescription`)})]}):E.length===0?(0,$.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:l(`console.ai.noMatchingChats`)}):(0,$.jsx)(`div`,{className:`flex flex-col py-1`,children:Xp(E).map(e=>(0,$.jsxs)(`section`,{"data-testid":`ai-conversation-group-${e.key}`,children:[(0,$.jsx)(`h3`,{className:`px-3 pb-1 pt-3 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:l(`console.ai.group.${e.key}`,{defaultValue:Yp[e.key]})}),(0,$.jsx)(`ul`,{className:`flex flex-col`,children:e.items.map(e=>(0,$.jsx)($p,{conversation:e,query:v.trim(),active:e.id===d,renaming:e.id===b,onSelect:()=>{u(D(e)),c?.()},onDelete:t=>k(t,e.id),onStartRename:()=>x(e.id),onCancelRename:()=>x(void 0),onSubmitRename:t=>A(e.id,t)},e.id))})]},e.key))})})]})}function Qp(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,$.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 $p({conversation:e,query:t,active:n,renaming:r,onSelect:i,onDelete:a,onStartRename:o,onCancelRename:s,onSubmitRename:c}){let{t:l}=J(),u=tr(),d=e.title?.trim()||e.preview?.trim()||l(`console.ai.newConversation`),[f,p]=(0,Q.useState)(d),m=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{r&&(p(e.title?.trim()||e.preview?.trim()||``),setTimeout(()=>m.current?.select(),0))},[r,e.title,e.preview]),r?(0,$.jsx)(`li`,{children:(0,$.jsxs)(`div`,{className:Le(`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,$.jsx)(K,{ref:m,value:f,onChange:e=>p(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),c(f)):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,$.jsx)(q,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>c(f),"data-testid":`ai-conversation-rename-confirm-${e.id}`,"aria-label":l(`console.ai.saveRename`),children:(0,$.jsx)(kr,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(q,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:s,"aria-label":l(`console.ai.cancelRename`),children:(0,$.jsx)(ba,{className:`h-3.5 w-3.5`})})]})}):(0,$.jsx)(`li`,{children:(0,$.jsxs)(`div`,{className:Le(`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,$.jsxs)(`button`,{type:`button`,onClick:i,className:`min-w-0 flex-1 text-left`,"data-testid":`ai-conversation-select-${e.id}`,children:[(0,$.jsx)(`span`,{className:`line-clamp-1 font-medium`,children:Qp(d,t)}),e.preview&&e.preview!==d?(0,$.jsx)(`span`,{className:`mt-0.5 block line-clamp-1 text-xs text-muted-foreground`,children:Qp(e.preview,t)}):null,(0,$.jsx)(`span`,{className:`mt-0.5 block text-[10px] text-muted-foreground`,title:qp(e.updatedAt??e.createdAt,u),children:Kp(e.updatedAt??e.createdAt,l,u)})]}),(0,$.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,$.jsx)(q,{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,$.jsx)(Li,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(q,{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,$.jsx)(la,{className:`h-3.5 w-3.5`})})]})]})})}function em(){return typeof window>`u`?``:window.location.pathname.startsWith(`/_console`)?`/_console`:``}function tm(e,t){let n=`${em()}/apps/${encodeURIComponent(e)}`;return t?n:`${n}?preview=draft`}function nm({appName:e,appSegment:t,materialized:n=!1,refreshKey:i,onClose:a}){let{t:o}=J(),s=r(),c=(0,Q.useRef)(null),l=t&&t.length?t:e;return(0,Q.useEffect)(()=>{if(!c.current)return;let e=tm(l,n);try{c.current.getAttribute(`src`)!==e&&c.current.setAttribute(`src`,e)}catch{}},[l,n]),(0,Q.useEffect)(()=>{if(i>0)try{c.current?.contentWindow?.location.reload()}catch{}},[i]),(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col border-l`,"data-testid":`live-canvas`,children:[(0,$.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,$.jsx)(Xr,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n?o(`console.ai.liveCanvasUnlisted`,{app:e,defaultValue:`Live app — {{app}} (unlisted until published)`}):o(`console.ai.liveCanvas`,{app:e,defaultValue:`Live preview — {{app}} (draft)`})}),t&&(0,$.jsxs)(q,{size:`sm`,variant:`ghost`,onClick:()=>s(`/studio/${t}/interfaces`),"data-testid":`live-canvas-open-designer`,className:`gap-1.5`,title:o(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),"aria-label":o(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),children:[(0,$.jsx)(oi,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:o(`topbar.designInStudio`,{defaultValue:`Design in Studio`})})]}),(0,$.jsx)(q,{size:`sm`,variant:`ghost`,onClick:a,"data-testid":`live-canvas-close`,children:(0,$.jsx)(ba,{className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`iframe`,{ref:c,title:`Draft preview: ${e}`,src:tm(l,n),className:`h-full w-full flex-1 border-0 bg-background`,"data-testid":`live-canvas-frame`})]})}function rm(e,t,n){let r=`/studio/${encodeURIComponent(e)}/${t}`;return n?`${r}?${qc}=${encodeURIComponent(Jc(n))}`:r}function im(e,t){if(!e)return null;let n=t.name?.trim();if(!n)return null;switch(t.type){case`object`:return rm(e,`data`,{type:`object`,name:n});case`flow`:return rm(e,`automations`,{type:`flow`,name:n});case`dashboard`:return rm(e,`interfaces`,{type:`dashboard`,name:n});case`page`:return rm(e,`interfaces`,{type:`page`,name:n});case`view`:{let t=n.indexOf(`.`);return rm(e,`interfaces`,{type:`object`,name:t>0?n.slice(0,t):n})}case`app`:return rm(e,`interfaces`);default:return null}}async function am(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 om({apiBase:e,conversationId:t,open:n,onOpenChange:r}){let i=tr(),{t:a}=J(),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!n||!t)return;let r=!1;return l(!0),d(null),p(!1),s(null),am(e,t).then(e=>{r||(e?s(e):p(!0))}).catch(e=>{r||d(e instanceof Error?e.message:String(e))}).finally(()=>{r||l(!1)}),()=>{r=!0}},[n,t,e]);let m=o?.reconciliation,h=m?m.orphaned.length+m.missing.length+m.errors.length:0;return(0,$.jsx)(ht,{open:n,onOpenChange:r,children:(0,$.jsxs)(ke,{side:`right`,className:`w-full overflow-y-auto sm:max-w-xl`,children:[(0,$.jsxs)(G,{children:[(0,$.jsxs)(H,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Cr,{className:`h-4 w-4`}),` `,a(`console.ai.buildDoctor`)]}),(0,$.jsx)(je,{children:a(`console.ai.buildDoctorDrawer.description`)})]}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-4 text-sm`,children:[c&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,$.jsx)(X,{className:`h-4 w-4 animate-spin`}),` `,a(`console.ai.buildDoctorDrawer.reconciling`)]}),(u||f)&&!c&&(0,$.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive`,children:f?a(`console.ai.buildDoctorDrawer.notAvailable`):u}),o&&!c&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-md border bg-muted/30 p-3 text-xs text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`font-medium text-foreground`,children:o.title??a(`console.ai.buildDoctorDrawer.untitled`)}),(0,$.jsxs)(`div`,{className:`mt-1`,children:[a(`console.ai.buildDoctorDrawer.summary`,{turns:o.summary.userTurns,messages:o.summary.messages,tokens:o.summary.totalTokens.toLocaleString(i),seconds:(o.summary.llmMs/1e3).toFixed(1)}),o.summary.models.length?` · ${o.summary.models.join(`, `)}`:``]})]}),m&&(0,$.jsxs)(`div`,{className:m.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:[m.ok?(0,$.jsx)(Ir,{className:`h-4 w-4`}):(0,$.jsx)(ua,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`font-medium`,children:m.ok?a(`console.ai.buildDoctorDrawer.allLive`,{count:m.liveCount}):a(`console.ai.buildDoctorDrawer.discrepancies`,{count:h})})]}),m&&m.orphaned.length>0&&(0,$.jsx)(sm,{icon:(0,$.jsx)(Rr,{className:`h-4 w-4 text-destructive`}),title:a(`console.ai.buildDoctorDrawer.orphanedTitle`),hint:a(`console.ai.buildDoctorDrawer.orphanedHint`),findings:m.orphaned,tone:`destructive`}),m&&m.missing.length>0&&(0,$.jsx)(sm,{icon:(0,$.jsx)(ua,{className:`h-4 w-4 text-amber-600`}),title:a(`console.ai.buildDoctorDrawer.missingTitle`),hint:a(`console.ai.buildDoctorDrawer.missingHint`),findings:m.missing,tone:`amber`}),m&&m.errors.length>0&&(0,$.jsx)(sm,{icon:(0,$.jsx)(zr,{className:`h-4 w-4 text-destructive`}),title:a(`console.ai.buildDoctorDrawer.toolErrorsTitle`),hint:a(`console.ai.buildDoctorDrawer.toolErrorsHint`),findings:m.errors,tone:`destructive`}),o.verify&&(0,$.jsxs)(`div`,{className:`rounded-md border p-3 text-xs`,children:[(0,$.jsx)(`div`,{className:`font-medium text-foreground`,children:a(`console.ai.buildDoctorDrawer.verifyTitle`)}),(0,$.jsxs)(`div`,{className:`mt-1 text-muted-foreground`,children:[a(`console.ai.buildDoctorDrawer.yourApp`),` `,o.verify.userIssues.length===0?(0,$.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:a(`console.ai.buildDoctorDrawer.noIssues`)}):(0,$.jsx)(`span`,{className:`text-destructive`,children:a(`console.ai.buildDoctorDrawer.issueCount`,{count:o.verify.userIssues.length})}),o.verify.platformNoise>0?` · ${a(`console.ai.buildDoctorDrawer.platformNoise`,{count:o.verify.platformNoise})}`:``]}),o.verify.userIssues.map((e,t)=>(0,$.jsxs)(`div`,{className:`mt-1 text-destructive`,children:[`[`,e.severity,`] `,e.code,` `,e.artifact?`${e.artifact.type}:${e.artifact.name}`:``]},t))]}),o.pendingActions.length>0&&(0,$.jsxs)(`div`,{className:`rounded-md border p-3 text-xs`,children:[(0,$.jsx)(`div`,{className:`font-medium text-foreground`,children:a(`console.ai.buildDoctorDrawer.pendingActions`)}),o.pendingActions.map((e,t)=>(0,$.jsxs)(`div`,{className:`mt-1 text-muted-foreground`,children:[e.tool??`?`,` · `,e.object??`-`,` · `,(0,$.jsx)(`span`,{className:`font-mono`,children:e.status??`-`})]},t))]}),(0,$.jsxs)(`details`,{className:`rounded-md border p-3 text-xs`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer font-medium text-foreground`,children:a(`console.ai.buildDoctorDrawer.timeline`,{count:o.timeline.length})}),(0,$.jsx)(`div`,{className:`mt-2 space-y-1 font-mono text-[11px] leading-relaxed`,children:o.timeline.map((e,t)=>(0,$.jsx)(cm,{entry:e},t))})]})]})]})]})})}function sm({icon:e,title:t,hint:n,findings:r,tone:i}){return(0,$.jsxs)(`div`,{className:`rounded-md border ${i===`destructive`?`border-destructive/30`:`border-amber-500/30`} p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-foreground`,children:[e,` `,t,` (`,r.length,`)`]}),(0,$.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:n}),(0,$.jsx)(`div`,{className:`mt-2 space-y-1`,children:r.map((e,t)=>(0,$.jsxs)(`div`,{className:`font-mono text-xs`,children:[e.t?`${e.t} · `:``,e.tool,` → `,e.artifact.type,`:`,e.artifact.name,(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (`,e.status,`)`]})]},t))})]})}function cm({entry:e}){return e.kind===`user`?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 👤 `,e.text]}):e.kind===`assistant-text`?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 🤖 `,e.text]}):e.kind===`assistant-calls`?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 🤖 →`,` `,e.calls.map(e=>e.name).join(`, `)]}):(0,$.jsxs)(`div`,{className:e.isError?`text-destructive`:``,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` ↳ `,e.name,e.status?` (${e.status})`:``]})}function lm(e){if(typeof e.content==`string`)return e.content;let t=e.parts;return Array.isArray(t)?t.map(e=>e&&typeof e==`object`&&e.type===`text`?String(e.text??``):``).join(` `):``}function um(e){if(Array.isArray(e))for(let t=e.length-1;t>=0;t--){let n=e[t];if(!n||n.role!==`user`)continue;let r=lm(n);if(r.trim())return/[一-鿿]/.test(r)?`zh-CN`:void 0}}function dm(e){return(um(e)??``).toLowerCase().startsWith(`zh`)}var fm={planApproveMessage:{zh:`确认,开始搭建。`,en:`Looks good — build it as proposed.`},planApproveDefaultsMessage:{zh:`确认搭建,未决问题按你的合理假设和默认处理。`,en:`Build it with your best assumptions; use sensible defaults for the open questions.`},planAnswerMessage:{zh:`关于「{{question}}」,我选择「{{option}}」。`,en:`For "{{question}}", go with: {{option}}.`},changesConfirmMessage:{zh:`确认修改,应用你刚才提议的改动。`,en:`Confirm — apply the change you just proposed.`}};function pm(e,t){let n=e?.console?.ai?.[t];return typeof n==`string`&&n.trim()!==``?n:void 0}function mm(e,t){return t?e.replace(/\{\{\s*(\w+)\s*\}\}/g,(e,n)=>Object.prototype.hasOwnProperty.call(t,n)?t[n]:e):e}function hm(e,t,n){let r=e?`zh`:`en`;return mm(pm(Kn()[r],t)??fm[t][r],n)}var gm=`/api/v1/ai`;function _m(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function vm(e){let t=e.approval;if(!t||typeof t!=`object`||Array.isArray(t))return;let n=t,r=n.id;if(typeof r==`string`&&r.length!==0)return{id:r,...typeof n.approved==`boolean`?{approved:n.approved}:{},...typeof n.reason==`string`?{reason:n.reason}:{},...typeof n.isAutomatic==`boolean`?{isAutomatic:n.isAutomatic}:{},...typeof n.signature==`string`?{signature:n.signature}:{}}}function ym(e){let t=_m(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 bm(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=_m(r,`toolName`)??r.type.slice(5),a=_m(r,`toolCallId`)??`${e.id}-${i}`,o=ym(r),s=r.output??r.result,c=vs(s),l=gs(s),u=ps(s),d=Es(s),f=ms(s),p=fs(a,s),m=vm(r),h=hs(s)?.pendingActionId??_m(r,`pendingActionId`);if(t.push({toolCallId:a,toolName:i,...o?{state:o}:{},...s===void 0?{}:{result:s},...m?{approval:m}:{},...h?{pendingActionId:h}:{},...c&&!p?{draftReview:c}:{},...l?{proposedPlan:l}:{},...u?{builderHandoff:u}:{},...d?{recordHandoff:d}:{},...f?{proposedChanges:f}:{},...p?{replayOutcome:p}:{},...r.errorText?{errorText:String(r.errorText)}:{}}),!n){let e=_s(c);e&&(n=e)}}return{id:e.id,role:e.role,content:r,...t.length>0?{toolInvocations:t}:{},...n?{buildProgress:n}:{}}})}function xm(e,t){if(t)return t;let n;for(let t of e)for(let e of t.toolInvocations??[]){let t=e.draftReview?.packageId||e.builderHandoff?.packageId;t&&(n=t)}return n}function Sm(e,t){return xm(bm(e),void 0)===t}var Cm=`com.objectstack.`;function wm(e){return typeof e._packageId==`string`&&e._packageId.startsWith(Cm)}function Tm(e){return e.find(e=>e.role===`user`)?.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``).trim()||void 0}var Em={ask:{key:`console.ai.agentLabels.ask`,defaultValue:`Ask`},build:{key:`console.ai.agentLabels.build`,defaultValue:`Build`}};function Dm(e,t,n){let r=t?Em[Os(t)]:void 0;return r?e(r.key,{defaultValue:r.defaultValue}):n}function Om(e,t,n){return Cs(t)?n?{title:n.appLabel?e(`console.ai.empty.editApp.title`,{defaultValue:`Editing “{{app}}”`,app:n.appLabel}):e(`console.ai.empty.editApp.titleGeneric`,{defaultValue:`Edit this app`}),description:e(`console.ai.empty.editApp.description`,{defaultValue:`What would you like to change? I’ll modify this app in place — add a field, object, view or dashboard, or adjust what’s already there.`})}:{title:e(`console.ai.empty.build.title`,{defaultValue:`Build with AI`}),description:e(`console.ai.empty.build.description`,{defaultValue:`Describe an app in plain language — I draft the objects, screens and sample data, then you review and publish.`})}:ws(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 km(e){if(e)return e.replace(/\/$/,``);let t={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},n=t.VITE_AI_BASE_URL;return n?n.replace(/\/$/,``):`${(t.VITE_SERVER_URL??``).replace(/\/$/,``)}${gm}`}var Am=`ai-chats-collapsed`;function jm(){let[e,t]=(0,Q.useState)(()=>{try{return localStorage.getItem(Am)===`1`}catch{return!1}}),n=(0,Q.useRef)(!1);return{collapsed:e,toggle:(0,Q.useCallback)(()=>{n.current=!1,t(e=>{let t=!e;try{localStorage.setItem(Am,t?`1`:`0`)}catch{}return t})},[]),handleCanvasOpenChange:(0,Q.useCallback)(e=>{e?t(e=>e||(n.current=!0,!0)):n.current&&(n.current=!1,t(!1))},[])}}var Mm=`ai-chat-pane-width`,Nm=480,Pm=360,Fm=420,Im=24;function Lm(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 Rm(e){let t=(0,Q.useRef)(null),[n,r]=(0,Q.useState)(()=>{try{let e=Number(localStorage.getItem(Mm));return Number.isFinite(e)&&e>0?e:Nm}catch{return Nm}}),[i,a]=(0,Q.useState)(!1),o=(0,Q.useCallback)(e=>Lm(e,{min:Pm,previewMin:Fm,containerWidth:t.current?.clientWidth??0}),[]),s=(0,Q.useCallback)(e=>{try{localStorage.setItem(Mm,String(Math.round(e)))}catch{}},[]);return(0,Q.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,Q.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,Q.useCallback)(e=>{let t=e.key===`ArrowLeft`?-24:e.key===`ArrowRight`?Im:0;t&&(e.preventDefault(),r(e=>{let n=o(e+t);return s(n),n}))},[o,s]),reset:(0,Q.useCallback)(()=>{let e=o(Nm);r(e),s(e)},[o,s])}}function zm(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 Bm(e,t,n){return t||(typeof e==`number`&&e>0?-1:n)}var Vm=[];function Hm(e){let{chatApi:t,conversationId:n,pendingRef:r,doSend:i,pendingSignal:a,agentRoute:o}=e,s=!!t;return(0,Q.useEffect)(()=>{if(!s||!n)return;let e=r.current;e&&(e.targetAgentRoute&&e.targetAgentRoute!==o||(r.current=null,i(e.content,e.files)))},[s,n,r,i,a,o]),(0,Q.useCallback)((e,t)=>{if(s&&!n){r.current={content:e,files:t};return}i(e,t)},[s,n,r,i])}function Um({apiBase:e,defaultAgent:t}={}){let{user:n}=A(),{t:i}=J(),a=n?.id,{agent:o,conversationId:s}=f(),[c]=l(),u=c.toString(),d=c.get(`new`)!==null,p=c.get(`package`)?.trim()||void 0,m=c.get(`handoffPrompt`)?.trim()||void 0,h=c.get(`parentConversationId`)?.trim()||void 0,g=r(),_=Qu(),{setContext:v}=Ro();(0,Q.useEffect)(()=>{v(`home`)},[v]);let y=(0,Q.useMemo)(()=>km(e),[e]),b={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_AI_DEFAULT_AGENT,{agents:x,isLoading:S,error:C,refetch:w}=Ss({apiBase:y}),T=(0,Q.useMemo)(()=>x.map(e=>e.name),[x]),E=!S&&x.length===0,D=(0,Q.useMemo)(()=>{if(!o)return!1;if(x.length!==0)return Ns(o,T)!==void 0},[o,x.length,T]),O=o?void 0:c.get(`agent`)??void 0,k=cp(x,Gc(),Js()),j=(0,Q.useMemo)(()=>{let e=xs(x,O??t??b);return k&&ws(e)?Ns(`build`,T)??e:e},[x,O,t,b,k,T]),M=(0,Q.useMemo)(()=>{if(x.length!==0)return o&&D?Ns(o,T):j},[x.length,o,D,T,j]),N=M?Os(M):void 0,ee=!!(o&&D===!1&&ys(o)),P=o&&D===!1&&!ee?o:void 0,F=M?`${y}/agents/${encodeURIComponent(M)}/chat`:void 0,te=M?Rp({appId:p,product:Lp(M)}):void 0,I=M?Lp(M):void 0,ne=p&&I===`build`&&te!==I?I:void 0,re=(0,Q.useCallback)(e=>p!==void 0&&Sm(e,p),[p]),{conversationId:L,conversationScope:ie,initialMessages:ae,rekeyScope:oe}=Pp({userId:M?a:void 0,scope:te,apiBase:y,activeId:s??P,forceNew:d,legacyScope:ne,adoptLegacy:ne?re:void 0}),R=ie===te,se=R?L:void 0,ce=R?ae:Vm;(0,Q.useEffect)(()=>{if(x.length===0||!M)return;let e=Os(M),t=new URLSearchParams(u);t.delete(`agent`);let n=t.toString()?`?${t.toString()}`:``;if(!o){g(`/ai/${e}${n}`,{replace:!0});return}if(ee){g(`/ai/${e}${n}`,{replace:!0});return}if(k&&D&&ws(M)&&!s){g(`/ai/build${n}`,{replace:!0});return}if(D&&o!==e){let t=s?`/${encodeURIComponent(s)}`:``;g(`/ai/${e}${t}${n}`,{replace:!0})}},[x.length,M,o,D,ee,k,s,u,g]),(0,Q.useEffect)(()=>{if(P===void 0)return;let e=!1;return(async()=>{let t;try{t=(await jp(y,P))?.agentId??void 0}catch{}if(e)return;let n=Ns(t??``,T),r=Os(n??M??`ask`);g(`/ai/${r}/${encodeURIComponent(P)}`,{replace:!0})})(),()=>{e=!0}},[P,y,T,M,g]);let[le,z]=(0,Q.useState)(0),[ue,de]=(0,Q.useState)({}),[fe,pe]=(0,Q.useState)(!1),[B,me]=(0,Q.useState)(!1),[he,ge]=(0,Q.useState)(!1),{collapsed:_e,toggle:V,handleCanvasOpenChange:ve}=jm();(0,Q.useEffect)(()=>{let e=e=>{let t=zm(e);t&&(e.preventDefault(),t===`toggle-list`?V():g(N?`/ai/${N}?new=1`:`/ai?new=1`))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[V,g,N]);let U=(0,Q.useMemo)(()=>y.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[y]),ye=(0,Q.useMemo)(()=>Yd(),[]),be=(0,Q.useRef)(null);d?be.current===null&&(be.current={id:L}):be.current=null,(0,Q.useEffect)(()=>{if(!D||s||!L||!N||be.current&&be.current.id===L||ie!==te)return;let e=p?`?package=${encodeURIComponent(p)}`:``;g(`/ai/${N}/${L}${e}`,{replace:!0})},[D,s,L,ie,te,N,p,g]);let xe=(0,Q.useCallback)(e=>{e&&!p&&I===`build`&&N&&te===I&&ie===te&&L&&s===L&&(oe(Rp({appId:e,product:I})),g(`/ai/${N}/${encodeURIComponent(L)}?package=${encodeURIComponent(e)}`,{replace:!0}))},[p,I,N,te,ie,L,s,oe,g]),W=(0,Q.useRef)(new Set);(0,Q.useEffect)(()=>{L&&ae.length>0&&W.current.add(L)},[L,ae.length]),(0,Q.useEffect)(()=>{if(!L)return;let e=Tm(ae);e&&de(t=>t[L]===e?t:{...t,[L]:e})},[L,ae]);let Se=(0,Q.useRef)(null),[Ce,we]=(0,Q.useState)(0),Te=(0,Q.useCallback)(e=>{Se.current=e,we(e=>e+1)},[]),Ee=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{m&&o===`build`&&Ee.current!==m&&(Ee.current=m,Te({content:m,targetAgentRoute:`build`}))},[m,o,Te]);let De=(0,Q.useCallback)(e=>{if(z(e=>e+1),e&&L&&de(t=>({...t,[L]:e})),!e||!L||W.current.has(L))return;W.current.add(L);let t=()=>z(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[L]);return(0,$.jsxs)(`div`,{className:`flex h-svh w-full flex-col bg-background`,"data-testid":`ai-chat-page`,children:[(0,$.jsxs)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background/95 px-2 backdrop-blur sm:px-4`,children:[!E&&(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 md:hidden`,onClick:()=>ge(!0),"aria-label":i(`console.ai.openChats`),"data-testid":`ai-chat-mobile-sidebar-trigger`,children:(0,$.jsx)(Pi,{className:`h-4 w-4`})}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(Gf,{variant:`home`})}),!E&&(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"data-testid":`ai-chat-collapse-to-dock`,"aria-label":i(`console.ai.collapseToDock`,{defaultValue:`Collapse to side panel`}),title:i(`console.ai.collapseToDock`,{defaultValue:`Collapse to side panel`}),onClick:()=>{tp();let e=Bm(window.history.state?.idx,ip(),_);g(e===-1?-1:e)},children:(0,$.jsx)(Ii,{className:`h-4 w-4`})})]}),E?(0,$.jsx)(Wm,{hasError:!!C,onRetry:w,onHome:()=>g(_),t:i}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ht,{open:he,onOpenChange:ge,children:(0,$.jsxs)(ke,{side:`left`,className:`w-[320px] p-0 sm:max-w-[360px]`,"data-testid":`ai-chat-mobile-sidebar`,children:[(0,$.jsxs)(G,{className:`sr-only`,children:[(0,$.jsx)(H,{children:i(`console.ai.chats`)}),(0,$.jsx)(je,{children:i(`console.ai.chatsDescription`)})]}),(0,$.jsx)(Zp,{userId:a,apiBase:y,activeAgent:M,includeAskConversations:k,refreshKey:le,titleHints:ue,className:`h-full border-r-0`,onNavigate:()=>ge(!1)})]})}),L&&(0,$.jsx)(Ct,{open:fe,onOpenChange:pe,objectName:`ai_conversations`,recordId:L,recordLabel:`this conversation`,apiBase:U,publicBaseUrl:ye}),L&&Ms(x,M,`debug`)&&(0,$.jsx)(om,{apiBase:y,conversationId:L,open:B,onOpenChange:me}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 w-full bg-background`,children:[(0,$.jsxs)(`div`,{className:`hidden shrink-0 flex-col border-r md:flex`,children:[!_e&&(0,$.jsx)(Zp,{userId:a,apiBase:y,activeAgent:M,includeAskConversations:k,refreshKey:le,titleHints:ue,className:`w-72 min-h-0 flex-1 border-r-0`}),(0,$.jsx)(`div`,{className:Le(`mt-auto p-2`,_e?`w-12`:`w-72 border-t`),children:(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:V,"aria-label":_e?i(`console.ai.showChats`,{defaultValue:`Show chats`}):i(`console.ai.hideChats`,{defaultValue:`Hide chats`}),title:_e?i(`console.ai.showChats`,{defaultValue:`Show chats`}):i(`console.ai.hideChats`,{defaultValue:`Hide chats`}),"data-testid":`ai-chat-collapse-sidebar-trigger`,"aria-pressed":_e,children:_e?(0,$.jsx)(Ni,{className:`h-4 w-4`}):(0,$.jsx)(Mi,{className:`h-4 w-4`})})})]}),(0,$.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:(0,$.jsx)(Gm,{agents:x,agentsLoading:S,agentsError:C,activeAgent:M,chatApi:F,apiBase:y,conversationId:se,editPackageId:p,onPackageBound:xe,canBind:!!s,parentHandoffConversationId:h,initialMessages:ce,pendingFirstMessageRef:Se,pendingFirstMessageSeq:Ce,onSent:De,onShare:()=>pe(!0),onDebug:()=>me(!0),showDebug:Ms(x,M,`debug`),onCanvasOpenChange:ve},`${F??`local`}:${se??`pending`}`)})]})]})]})}function Wm({hasError:e,onRetry:t,onHome:n,t:r}){return(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,"data-testid":`ai-unavailable`,children:(0,$.jsxs)(ve,{children:[(0,$.jsx)(pe,{children:r(`console.ai.unavailableTitle`,{defaultValue:`AI assistant unavailable`})}),(0,$.jsx)(ge,{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,$.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-3 sm:flex-row`,children:[e&&(0,$.jsx)(q,{variant:`outline`,onClick:t,"data-testid":`ai-unavailable-retry`,children:r(`console.ai.unavailableRetry`,{defaultValue:`Try again`})}),(0,$.jsx)(q,{onClick:n,"data-testid":`ai-unavailable-home`,children:r(`console.ai.unavailableHome`,{defaultValue:`Back to home`})})]})]})})}function Gm({agents:e,agentsLoading:t,agentsError:n,activeAgent:i,chatApi:a,apiBase:s,conversationId:c,editPackageId:l,surfaceContext:u,surfaceArtifactLabel:d,onPackageBound:f,canBind:p,parentHandoffConversationId:m,initialMessages:h,pendingFirstMessageRef:g,pendingFirstMessageSeq:_,onSent:v,onShare:y,onDebug:b,showDebug:x,onCanvasOpenChange:S}){let{t:C}=J(),w=r(),T=Da(),E=lp(e,Gc(),Js()),D=E.length>1,O=(0,Q.useCallback)(e=>{let t=new URLSearchParams,n=e.packageId||l;n&&t.set(`package`,n),e.prompt&&t.set(`handoffPrompt`,e.prompt),c&&t.set(`parentConversationId`,c);let r=t.toString();w(`/ai/build${r?`?${r}`:``}`)},[w,l,c]),k=(0,Q.useCallback)(async e=>{let t=`setup`;try{let n=await fetch(`/api/v1/meta/object/${encodeURIComponent(e.objectName)}`,{credentials:`include`});if(n.ok){let e=await n.json();typeof e?.item?._packageId==`string`&&e.item._packageId&&(t=e.item._packageId)}}catch{}w(`/apps/${encodeURIComponent(t)}/${encodeURIComponent(e.objectName)}/record/${encodeURIComponent(e.recordId)}`)},[w]),[A,j]=(0,Q.useState)(null),[M,N]=(0,Q.useState)(0),ee=de(),[P,F]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{A||F(!1)},[A]);let te=un(),[I,ne]=(0,Q.useState)(null),re=(0,Q.useRef)(null);(0,Q.useEffect)(()=>()=>{re.current&&window.clearTimeout(re.current)},[]);let L=A!==null;(0,Q.useEffect)(()=>{S?.(L)},[L,S]);let ie=Rm(L),ae=(0,Q.useCallback)((e,t)=>{let n=e.find(e=>e.type===`app`);n&&j(e=>e??{name:n.name,segment:t,materialized:!1}),re.current&&window.clearTimeout(re.current),re.current=window.setTimeout(()=>N(e=>e+1),800)},[]),oe=(0,Q.useCallback)(e=>{j(t=>t&&t.name===e&&!t.materialized?{...t,materialized:!0}:t??{name:e,materialized:!0})},[]);(0,Q.useEffect)(()=>{j(null)},[c]);let R=(0,Q.useMemo)(()=>{let t=e.find(e=>e.name===i);return Dm(C,i,t?.label??i??C(`console.ai.assistant`))},[e,i,C]),se=(0,Q.useMemo)(()=>bm(h),[h]),{errorSuppressed:ce,handleChatError:le,setMessagesRef:z,resetSuppression:ue}=Ip({chatApi:a,conversationId:c}),{models:fe,defaultModelId:pe}=Ds({apiBase:s}),[me,he]=(0,Q.useState)(void 0),ge=me??pe,{messages:_e,isLoading:V,error:ve,sendMessage:H,stop:U,reload:ye,clear:be,setMessages:xe}=bs({api:a,conversationId:c,parentConversationId:m,model:ge,onError:le,body:{context:{activeApp:`AI`,agentName:i,autoPublishAiBuilds:Ys().features.autoPublishAiBuilds,...l?{packageId:l}:{},...u?{surface:u}:{}}},initialMessages:se,autoResponse:!a,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600});(0,Q.useEffect)(()=>{z.current=xe},[xe]);let W=(0,Q.useMemo)(()=>Fs(_e),[_e]);(0,Q.useEffect)(()=>{Cp(c,wp(W))},[c,W]);let Se=(0,Q.useMemo)(()=>dm(W)||dm(h),[W,h]),Ce=(0,Q.useCallback)((e,t)=>hm(Se,e,t),[Se]),we=Ce(`planApproveMessage`),Te=Ce(`planApproveDefaultsMessage`),Ee=Ce(`changesConfirmMessage`),Oe=(0,Q.useMemo)(()=>({create_object:C(`console.ai.changeVerb.createObject`,{defaultValue:`Create object`}),add_field:C(`console.ai.changeVerb.addField`,{defaultValue:`Add field`}),modify_field:C(`console.ai.changeVerb.modifyField`,{defaultValue:`Modify field`}),delete_field:C(`console.ai.changeVerb.deleteField`,{defaultValue:`Delete field`}),create_metadata:C(`console.ai.changeVerb.createMetadata`,{defaultValue:`Create`}),update_metadata:C(`console.ai.changeVerb.updateMetadata`,{defaultValue:`Modify`}),create_seed:C(`console.ai.changeVerb.createSeed`,{defaultValue:`Generate sample data`}),create_package:C(`console.ai.changeVerb.createPackage`,{defaultValue:`Create app package`})}),[C]),ke=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{ke.current&&!V&&A&&N(e=>e+1),ke.current=V},[V,A]);let Ae=js({messages:W,apiBase:s,continueConversation:e=>{H(e)}}),je=Hm({chatApi:a,conversationId:c,pendingRef:g,doSend:(0,Q.useCallback)((e,t)=>{ue();let n=(t??[]).filter(e=>/\.(xlsx|xlsm|csv|tsv|txt)$/i.test(e.name));if(!n.length){if(t?.length){H(`${e}\n\n(用户上传了 ${t.length} 个附件:${t.map(e=>e.name).join(`、`)} — 当前仅支持读取表格类附件(Excel/CSV),这些文件的内容我没有读取。)`),v(e);return}H(e),v(e);return}ne(n[0]),(async()=>{let r=e=>e.length>40?`${e.slice(0,40)}…`:e,i=e=>e.slice(0,12).map(e=>r(String(e??``)).replace(/\s+/g,` `)).join(` | `),a=e;for(let e of n.slice(0,2))try{let{parseSpreadsheetFile:t}=await o(async()=>{let{parseSpreadsheetFile:e}=await import(`./plugin-grid-Cp4RKtMJ.js`).then(e=>e.t);return{parseSpreadsheetFile:e}},__vite__mapDeps([0]),import.meta.url),n=await t(e),r=n[0]??[],s=n.slice(1,4);a+=[`\n\n[附件表格 ${e.name} — ${Math.max(0,n.length-1)} 数据行 × ${r.length} 列(控制台已在本地解析,文件本体未上传)]`,`表头: ${i(r)}`,...s.map((e,t)=>`样例${t+1}: ${i(e)}`)].join(`
7
+ `)}catch(t){a+=`\n\n[附件表格 ${e.name}] 解析失败(${t instanceof Error?t.message:`unknown`})— 请引导用户改用对象列表的 Import 上传该文件。`}n.length>2&&(a+=`\n\n(另有 ${n.length-2} 个表格附件未读取 — 一次最多读取 2 个。)`);let s=(t??[]).length-n.length;s>0&&(a+=`\n\n(另有 ${s} 个非表格附件,内容未读取。)`),H(a),v(a)})()},[ue,H,v]),pendingSignal:_,agentRoute:i?Os(i):void 0}),Me=i?Os(i)===`build`:!1,{apps:Ne}=Yt(),G=Ne,{appLabel:Pe}=Xn(),Re=(0,Q.useMemo)(()=>xm(W,l),[W,l]),ze=(0,Q.useMemo)(()=>{if(!Re)return;let e=(G??[]).find(e=>e._packageId===Re);return e?Pe({name:e.name,label:ec(e.label,C)}):Re},[Re,G,Pe,C]),Be=(0,Q.useMemo)(()=>{if(!l)return;let e=(G??[]).find(e=>e._packageId===l);return e?Pe({name:e.name,label:ec(e.label,C)}):void 0},[l,G,Pe,C]),Ve=Me&&!!l,Ue=(0,Q.useMemo)(()=>{if(!(se.length>0))return Xm(i,R,C,Ve)},[se.length,i,R,C,Ve]),We=(0,Q.useMemo)(()=>Om(C,i,Ve?{appLabel:Be}:void 0),[C,i,Ve,Be]);(0,Q.useEffect)(()=>{Me&&p&&Re&&!l&&!V&&f?.(Re)},[Me,p,Re,l,V,f]);let K=(0,Q.useMemo)(()=>{for(let e=_e.length-1;e>=0;e--)for(let t of _e[e].toolInvocations??[]){let e=Ps(t.result);if(e)return e;let n=t.draftReview;if(n?.packageId&&n.kind!==`edit`&&n.items?.some(e=>e.type===`app`))return n.packageId}},[_e]),Ge=(0,Q.useRef)(!1),Ke=r();(0,Q.useEffect)(()=>{if(!Me||V||!p||!K||Ge.current)return;Ge.current=!0;let e=!1;try{let t=`objectstack:ai-full-page-opted:${c??``}`;sessionStorage.getItem(`objectstack:ai-full-page-requested`)===`1`?(sessionStorage.removeItem(`objectstack:ai-full-page-requested`),sessionStorage.setItem(t,`1`),e=!0):sessionStorage.getItem(t)===`1`&&(e=!0)}catch{}e||(f?.(K),Ke(`/studio/${encodeURIComponent(K)}/interfaces`))},[Me,V,p,K,c,f,Ke]);let qe=(0,Q.useRef)(void 0);(0,Q.useEffect)(()=>{if(V)return;let e=[..._e].reverse().find(e=>e.role===`assistant`);e&&e.id!==qe.current&&(e.toolInvocations??[]).some(e=>e.draftReview||e.replayOutcome)&&(qe.current=e.id,Ha())},[V,_e]);let Ye=(0,Q.useMemo)(()=>{let e=new Map;for(let t of G??[]){let n=t._packageId;!n||e.has(n)||wm(t)||e.set(n,Pe({name:t.name,label:ec(t.label,C)}))}return Array.from(e,([e,t])=>({id:e,label:t}))},[G,Pe,C]),Xe=(0,$.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,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[D?E.length<=3?(0,$.jsx)(Fe,{value:i,onValueChange:e=>w(`/ai/${Os(e)}`),children:(0,$.jsx)(rt,{className:`h-7 gap-0.5 p-0.5`,"data-testid":`ai-chat-agent-picker`,"aria-label":C(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:E.map(e=>(0,$.jsx)(Nt,{value:e.name,disabled:t,title:e.description||void 0,className:`h-6 px-2.5 text-xs`,children:Dm(C,e.name,e.label)},e.name))})}):(0,$.jsxs)(De,{value:i,onValueChange:e=>w(`/ai/${Os(e)}`),disabled:t,children:[(0,$.jsx)(B,{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":C(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:(0,$.jsx)(He,{placeholder:C(`console.ai.chooseAgent`,{defaultValue:`Choose assistant…`})})}),(0,$.jsx)(Ie,{align:`start`,children:E.map(e=>(0,$.jsxs)(Wt,{value:e.name,className:`text-xs`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:Dm(C,e.name,e.label)}),e.description?(0,$.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[260px]`,children:e.description}):null]},e.name))})]}):(0,$.jsx)(`span`,{className:`truncate text-xs font-medium text-foreground/85`,children:R}),Me?(0,$.jsxs)(it,{children:[(0,$.jsxs)(yt,{"data-testid":`ai-build-package-chip`,title:Re,"aria-label":C(`console.ai.switchApp`,{defaultValue:`Switch app`}),className:Le(`inline-flex min-w-0 items-center gap-1 rounded-md border px-2 py-0.5 text-xs hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border/80`,Re?`bg-muted/40 text-foreground/80`:`border-dashed text-muted-foreground`),children:[Re?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ji,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`max-w-[10rem] truncate`,children:ze})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ea,{className:`size-3 shrink-0`}),C(`console.ai.newApp`,{defaultValue:`New app`})]}),(0,$.jsx)(Ar,{className:`size-3 shrink-0 opacity-60`})]}),(0,$.jsxs)(Pt,{align:`start`,className:`max-h-72 w-56 overflow-y-auto`,children:[(0,$.jsx)(mt,{className:`text-xs text-muted-foreground`,children:C(`console.ai.switchAppLabel`,{defaultValue:`Build conversations by app`})}),Ye.map(e=>(0,$.jsxs)(kt,{"data-testid":`ai-build-package-option-${e.id}`,className:`text-xs`,onSelect:()=>{e.id!==Re&&w(`/ai/build?package=${encodeURIComponent(e.id)}`)},children:[(0,$.jsx)(ji,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),e.id===Re?(0,$.jsx)(kr,{className:`size-3 shrink-0`}):null]},e.id)),Ye.length>0?(0,$.jsx)(Je,{}):null,(0,$.jsxs)(kt,{"data-testid":`ai-build-package-option-new`,className:`text-xs`,onSelect:()=>w(`/ai/build?new=1`),children:[(0,$.jsx)(ea,{className:`size-3 shrink-0`}),C(`console.ai.newApp`,{defaultValue:`New app`})]})]})]}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[x&&b?(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:b,disabled:!c,"aria-label":C(`console.ai.buildDoctor`),"data-testid":`ai-chat-debug-button`,title:C(c?`console.ai.buildDoctorTitle`:`console.ai.buildDoctorDisabledTitle`),children:(0,$.jsx)(Cr,{className:`h-3.5 w-3.5`})}):null,(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:y,disabled:!c,"aria-label":C(`console.ai.share`),"data-testid":`ai-chat-share-button`,title:C(c?`console.ai.shareTitle`:`console.ai.shareDisabledTitle`),children:(0,$.jsx)(Ji,{className:`h-3.5 w-3.5`})})]}),n?(0,$.jsx)(`span`,{className:`basis-full text-[10px] text-amber-700 dark:text-amber-400`,title:n.message,children:C(`console.ai.offlineDemoMode`)}):null]}),Ze=A!==null&&!ee;return(0,$.jsxs)(`div`,{ref:ie.containerRef,className:`relative flex min-h-0 flex-1 px-0`,children:[I&&te?(0,$.jsx)(`div`,{className:`pointer-events-none absolute top-2 left-0 right-0 z-20 flex justify-center px-4`,children:(0,$.jsx)(`div`,{className:`pointer-events-auto w-full max-w-3xl`,children:(0,$.jsx)($d,{file:I,dataSource:te,defaultObjectName:A?.name,onDone:()=>ne(null)})})}):null,Me?(0,$.jsx)(`div`,{className:`pointer-events-none absolute bottom-20 left-0 right-0 z-20 flex justify-center px-4`,children:(0,$.jsx)(nf,{packageId:Re,idle:!V})}):null,(0,$.jsx)(`div`,{"data-chat-column":!0,className:Ze?`flex min-h-0 shrink-0 justify-center`:`flex min-h-0 flex-1 justify-center`,style:Ze?{width:ie.width}:void 0,children:(0,$.jsx)(As,{className:`min-h-0 flex-1 bg-background md:max-w-5xl`,onUpgrade:qs()?()=>window.open(qs(),`_blank`,`noopener,noreferrer`):void 0,onOpenBuilder:O,onOpenRecord:k,surface:`plain`,maxHeight:`100%`,headerSlot:Xe,messages:W,placeholder:i?Os(i)===`ask`?C(`console.ai.askAnything`):C(`console.ai.askAgent`,{agent:R}):C(t?`console.ai.loadingAgents`:`console.ai.askAnything`),labels:{emptyTitle:We.title,emptyDescription:We.description,clear:C(`console.ai.clearConversation`),sendHint:C(`console.ai.sendHint`),agentActivity:C(`console.ai.agentActivity`),toolCompleted:C(`console.ai.toolCompleted`),toolRunning:C(`console.ai.toolRunning`),toolAwaitingApproval:C(`console.ai.toolAwaitingApproval`),toolFailed:C(`console.ai.toolFailed`),connectionWaiting:C(`console.ai.connectionWaiting`,{defaultValue:`Waiting for server…`}),connectionStalledLabel:C(`console.ai.connectionStalled`,{defaultValue:`Still working…`}),connectionOfflineLabel:C(`console.ai.connectionOffline`,{defaultValue:`Connection lost — reconnecting…`}),designingPlanLabel:C(`console.ai.designingPlan`,{defaultValue:`Designing your app…`}),designingPlanHints:[C(`console.ai.designingPlanHint.data`,{defaultValue:`Mapping out the data you’ll track…`}),C(`console.ai.designingPlanHint.objects`,{defaultValue:`Shaping objects and their fields…`}),C(`console.ai.designingPlanHint.relations`,{defaultValue:`Connecting related records…`}),C(`console.ai.designingPlanHint.lookups`,{defaultValue:`Setting up relationships and lookups…`}),C(`console.ai.designingPlanHint.views`,{defaultValue:`Planning the screens and views…`}),C(`console.ai.designingPlanHint.forms`,{defaultValue:`Laying out forms and lists…`}),C(`console.ai.designingPlanHint.defaults`,{defaultValue:`Adding sensible defaults and validations…`}),C(`console.ai.designingPlanHint.dashboard`,{defaultValue:`Sketching a dashboard to track it…`}),C(`console.ai.designingPlanHint.review`,{defaultValue:`Double-checking the structure hangs together…`}),C(`console.ai.designingPlanHint.finalize`,{defaultValue:`Pulling the plan together…`})],toolDetailsHidden:C(`console.ai.toolDetailsHidden`),copy:C(`console.ai.copy`),copied:C(`console.ai.copied`),regenerate:C(`console.ai.regenerate`),model:C(`console.ai.model`),submit:C(`console.ai.submit`),uploadFiles:C(`console.ai.uploadFiles`),stopResponse:C(`console.ai.stopResponse`),sendFailedRateLimited:C(`console.ai.sendFailedRateLimited`,{defaultValue:`You're sending messages too quickly. Your message is kept below — wait a moment and try again.`}),sendFailedGeneric:C(`console.ai.sendFailedGeneric`,{defaultValue:`Couldn't send your message. It's kept below — please try again.`}),trace:C(`console.ai.trace`),viewTrace:C(`console.ai.viewTrace`)},models:fe,selectedModelId:ge,onModelChange:he,suggestions:Ue,onSendMessage:je,onClear:be,hideClearBar:!0,onStop:V?U:void 0,onReload:ye,isLoading:V,error:ce?void 0:ve,enableMarkdown:!0,onToolApprove:Ae.decide,toolDecisions:Ae.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onOpenBuiltApp:(e,t)=>w(`/apps/${encodeURIComponent(t??e)}`),openBuiltAppLabel:C(`console.ai.openBuiltApp`,{defaultValue:`Open app`}),onDesignBuiltApp:(e,t)=>{let n=t??A?.segment;n&&w(`/studio/${encodeURIComponent(n)}/interfaces`)},designBuiltAppLabel:C(`console.ai.designBuiltApp`,{defaultValue:`Design in Studio`}),getArtifactAction:(e,t)=>{let n=im(t??A?.segment,e);return n?()=>w(n):null},fetchPendingDraftCount:op,onPublishDrafts:async e=>{try{let t=await T.publishPackageDrafts(e);if(t?.success===!1)throw Error(rc(t)||C(`console.ai.publishFailed`,{defaultValue:`Publish failed`}));let n=t?.failedCount??0;if(n){let e=t?.failed??[];throw Error(e.length>0?Gd(e):String(n))}let r=t?.seedApplied;return r&&r.success===!1?Y.warning(C(`console.ai.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:r.error??(Array.isArray(r.errors)&&r.errors.length?String(r.errors[0]):void 0)}):Y.success(C(`console.ai.publishOk`,{defaultValue:`Published — objects are now live.`})),Ha(),{ok:!0,health:Ts(t)}}catch(e){return Y.error(C(`console.ai.publishFailed`,{defaultValue:`Publish failed`}),{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:C(`console.ai.publishDrafts`,{defaultValue:`Publish`}),publishedLabel:C(`console.ai.published`,{defaultValue:`Published`}),nextStepsLabel:C(`console.ai.nextSteps`,{defaultValue:`What's next`}),planTitleLabel:C(`console.ai.planTitle`,{defaultValue:`Proposed plan`}),planQuestionsLabel:C(`console.ai.planQuestions`,{defaultValue:`Confirm before building`}),planAssumptionsLabel:C(`console.ai.planAssumptions`,{defaultValue:`Assumptions`}),planDeferredLabel:C(`console.ai.planDeferred`,{defaultValue:`Not yet built`}),planApproveHintLabel:C(`console.ai.planApproveHint`,{defaultValue:`Reply to approve or adjust this plan.`}),planApproveLabel:C(`console.ai.planApprove`,{defaultValue:`Build it`}),planAdjustLabel:C(`console.ai.planAdjust`,{defaultValue:`Adjust`}),planBuiltLabel:C(`console.ai.planBuilt`,{defaultValue:`Built`}),planBuildingLabel:C(`console.ai.planBuilding`,{defaultValue:`Building…`}),planReadyLabel:C(`console.ai.planReady`,{defaultValue:`The plan is ready. Build it now, or tell me what to adjust.`}),planApproveMessage:we,planApproveDefaultsMessage:Te,changesTitleLabel:C(`console.ai.changesTitle`,{defaultValue:`Confirm changes`}),changesConfirmedLabel:C(`console.ai.changesConfirmed`,{defaultValue:`Confirmed`}),changesConfirmLabel:C(`console.ai.changesConfirm`,{defaultValue:`Confirm`}),changesConfirmHintLabel:C(`console.ai.changesConfirmHint`,{defaultValue:`Reply to confirm or adjust this change.`}),changesConfirmMessage:Ee,changeVerbLabels:Oe,changesApplyingLabel:C(`console.ai.changesApplying`,{defaultValue:`Applying…`}),changesAppliedLabel:C(`console.ai.changesApplied`,{defaultValue:`Applied`}),changesDraftedLabel:C(`console.ai.changesDrafted`,{defaultValue:`Saved as draft`}),changesFailedLabel:C(`console.ai.changesFailed`,{defaultValue:`Not applied`}),surfaceContextLabel:u?.artifact?C(`console.ai.discussing`,{defaultValue:`Discussing: {{target}}`,target:d||`${u.artifact.type} · ${u.artifact.name}`}):void 0,surfaceContextTitle:u?.artifact?`${u.artifact.type} · ${u.artifact.name}`:void 0,planAnswerMessage:(e,t)=>Ce(`planAnswerMessage`,{question:e,option:t}),autoPublishDrafts:Ys().features.autoPublishAiBuilds,onDraftArtifacts:ae,onPreviewDraftApp:(e,t)=>{j({name:e,segment:t?.appSegment,materialized:t?.materialized===!0}),ee&&F(!0)},onBuildMaterialized:oe,previewDraftLabel:C(`console.ai.previewDraft`,{defaultValue:`Preview`}),"data-testid":`ai-chat-panel`})}),Ze?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":C(`console.ai.resizeSplit`,{defaultValue:`Resize chat and preview`}),tabIndex:0,onPointerDown:ie.onHandlePointerDown,onKeyDown:ie.onHandleKeyDown,onDoubleClick:ie.reset,"data-testid":`ai-chat-split-handle`,className:Le(`group relative hidden w-1.5 shrink-0 cursor-col-resize touch-none select-none md:block`,`focus:outline-none`),children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 -left-1.5 -right-1.5`}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:Le(`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`,ie.dragging&&`bg-primary`)})]}),(0,$.jsx)(nm,{appName:A.name,appSegment:A.segment,materialized:A.materialized,refreshKey:M,onClose:()=>j(null)}),ie.dragging?(0,$.jsx)(`div`,{className:`fixed inset-0 z-50 cursor-col-resize`,"data-testid":`ai-chat-split-overlay`}):null]}):null,A&&ee?(0,$.jsx)($.Fragment,{children:P?(0,$.jsx)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-background`,"data-testid":`ai-chat-mobile-canvas`,children:(0,$.jsx)(nm,{appName:A.name,appSegment:A.segment,materialized:A.materialized,refreshKey:M,onClose:()=>F(!1)})}):(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-24 z-20 flex justify-center px-4`,children:(0,$.jsxs)(q,{size:`sm`,onClick:()=>F(!0),"data-testid":`ai-chat-mobile-preview-open`,className:`pointer-events-auto gap-1.5 rounded-full shadow-lg`,children:[(0,$.jsx)(Xr,{className:`h-4 w-4`}),C(`console.ai.previewApp`,{defaultValue:`Preview app`})]})})}):null]})}function Km(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 qm(e){return[e(`console.ai.suggestions.metadataAssistant.buildCrm`,{defaultValue:`Build a sales CRM — customers, contacts, and deals with a stage field, plus a dashboard that totals deal value by stage.`}),e(`console.ai.suggestions.metadataAssistant.buildApp`,{defaultValue:`Create a project tracker — projects, tasks with owners and due dates, a board grouped by status, and a calendar of due dates.`}),e(`console.ai.suggestions.metadataAssistant.buildFlow`,{defaultValue:`Design a support desk — tickets with priority and status fields, a board grouped by status, and links to customers.`}),e(`console.ai.suggestions.metadataAssistant.buildInventory`,{defaultValue:`Build an inventory app — products, stock levels, suppliers, and a view that filters the items below their reorder point.`}),e(`console.ai.suggestions.metadataAssistant.buildRecruiting`,{defaultValue:`Make an applicant tracker — candidates, open roles, an interview-stage field, and a board grouped by stage.`})]}function Jm(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 Ym(e){return[e(`console.ai.suggestions.editApp.addField`,{defaultValue:`Add a field to one of the objects.`}),e(`console.ai.suggestions.editApp.addObject`,{defaultValue:`Add a new object and relate it to an existing one.`}),e(`console.ai.suggestions.editApp.addDashboard`,{defaultValue:`Add a dashboard for the key metrics.`}),e(`console.ai.suggestions.editApp.addSampleData`,{defaultValue:`Fill the existing objects with realistic sample records so I can demo the app.`})]}function Xm(e,t,n,r=!1){if(ws(e))return Km(n);if(Cs(e))return r?Ym(n):qm(n);let i=(e??t).toLowerCase();return i.includes(`data`)?Km(n):i.includes(`metadata`)?qm(n):Jm(n)}function Zm(e){return e===null||typeof e==`number`&&Number.isFinite(e)}function Qm(e){if(!e||typeof e!=`object`)return!1;let t=e;return typeof t.planType==`string`&&Zm(t.fraction)&&typeof t.unmetered==`boolean`&&typeof t.resetKind==`string`&&(t.resetsAt===null||typeof t.resetsAt==`string`)&&typeof t.upgrade==`boolean`&&typeof t.topUp==`boolean`}function $m(e){if(!e||typeof e!=`object`)return!1;let t=e;return Zm(t.build)&&Zm(t.dataChat)}function eh(e){if(!e||typeof e!=`object`)return null;let{pool:t,breakdown:n}=e;return Qm(t)?n===void 0?{pool:t}:$m(n)?{pool:t,breakdown:{build:n.build,dataChat:n.dataChat}}:null:null}function th(e={}){let{apiBase:t,enabled:n=!0}=e,[r,i]=Q.useState(null),[a,o]=Q.useState(!1),[s,c]=Q.useState(void 0),[l,u]=Q.useState(0),d=Q.useCallback(()=>u(e=>e+1),[]),f=n&&!!t;return Q.useEffect(()=>{if(!f){i(null),c(void 0),o(!1);return}if(typeof fetch!=`function`)return;let e=!1,n=`${t.replace(/\/$/,``)}/usage`;return o(!0),fetch(n,{method:`GET`,headers:{Accept:`application/json`},credentials:`include`}).then(async e=>{if(!e.ok)throw Error(`Failed to load AI usage (${e.status})`);return e.json()}).then(t=>{if(e)return;let n=eh(t);i(n),c(n?void 0:Error(`Unrecognized AI usage response shape`))}).catch(t=>{e||(i(null),c(t instanceof Error?t:Error(String(t))))}).finally(()=>{e||o(!1)}),()=>{e=!0}},[f,t,l]),Q.useEffect(()=>{if(!f||typeof window>`u`)return;let e=()=>d(),t=()=>{document.visibilityState===`visible`&&d()};return window.addEventListener(Is,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(Is,e),document.removeEventListener(`visibilitychange`,t)}},[f,d]),{usage:r,loading:a,error:s,refetch:d}}var nh=36e5,rh=24*nh;function ih(e){return e>=1?`full`:e>=.8?`low`:`ok`}function ah(e){return e===`full`?`text-destructive`:e===`low`?`text-amber-500`:`text-primary`}function oh(e){return e===`full`?`text-destructive`:e===`low`?`text-amber-600 dark:text-amber-500`:`text-muted-foreground`}function sh(e){if(!e)return[];let t=[];return[`build`,`dataChat`].forEach(n=>{let r=e[n];r!==null&&t.push({key:n,fraction:r})}),t}function ch({fraction:e,tone:t,size:n=16}){let r=(n-2)/2,i=2*Math.PI*r,a=i*Math.min(1,Math.max(0,e)),o=n/2;return(0,$.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 ${n} ${n}`,className:ah(t),"aria-hidden":`true`,focusable:`false`,children:[(0,$.jsx)(`circle`,{cx:o,cy:o,r,fill:`none`,strokeWidth:2,className:`stroke-muted-foreground/25`}),(0,$.jsx)(`circle`,{cx:o,cy:o,r,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeDasharray:`${a} ${i}`,transform:`rotate(-90 ${o} ${o})`})]})}function lh({apiBase:e,enabled:t=!0,className:n}){let{t:r,language:i}=J(),{usage:a}=th({apiBase:e,enabled:t}),[o,s]=Q.useState(null);if(Q.useEffect(()=>{s(Date.now());let e=setInterval(()=>s(Date.now()),6e4);return()=>clearInterval(e)},[]),!t||!a)return null;let{pool:c}=a;if(c.unmetered||c.fraction===null)return null;let l=c.fraction,u=ih(l),d=sh(a.breakdown),f=e=>e===`build`?r(`console.ai.usage.meterBuild`,{defaultValue:`Build`}):r(`console.ai.usage.meterAsk`,{defaultValue:`Ask`}),p=e=>e===`full`?r(`console.ai.usage.statusFull`,{defaultValue:`Limit reached`}):e===`low`?r(`console.ai.usage.statusLow`,{defaultValue:`Running low`}):r(`console.ai.usage.statusOk`,{defaultValue:`Plenty left`}),m=e=>{let t=Math.max(1,Math.ceil(e/nh));return r(`console.ai.usage.resetsWeeklyHours`,{count:t,defaultValue:`Resets in {{count}} hours`})},h=(e,t)=>{let n=new Date(e).getTime()-t;if(n<=rh)return m(n);let i=Math.ceil(n/rh);return r(`console.ai.usage.resetsWeeklyDays`,{count:i,defaultValue:`Resets in {{count}} days`})},g=(e,t)=>m(new Date(e).getTime()-t),_=e=>e.resetKind===`daily`?r(`console.ai.usage.resetsDaily`,{defaultValue:`Resets tonight`}):e.resetKind===`monthly`?r(`console.ai.usage.resetsMonthly`,{defaultValue:`Resets next cycle`}):e.resetKind===`weekly`?e.resetsAt&&o!==null?h(e.resetsAt,o):null:e.resetKind===`fiveHour`&&e.resetsAt&&o!==null?g(e.resetsAt,o):null,v=u!==`ok`&&(c.upgrade||c.topUp)&&!!qs(),y=_(c);return(0,$.jsxs)(Te,{children:[(0,$.jsx)(we,{asChild:!0,children:(0,$.jsxs)(q,{variant:`ghost`,size:`sm`,"data-testid":`ai-usage-indicator`,className:Le(`h-7 gap-1.5 px-1.5 text-muted-foreground hover:text-foreground`,n),"aria-label":r(`console.ai.usage.ariaLabel`,{defaultValue:`AI usage: {{status}}`,status:p(u)}),children:[(0,$.jsx)(ch,{fraction:l,tone:u}),u===`ok`?null:(0,$.jsx)(`span`,{className:Le(`hidden text-xs font-medium sm:inline`,oh(u)),children:p(u)})]})}),(0,$.jsxs)(Ot,{align:`end`,className:`w-64 p-3`,"data-testid":`ai-usage-popover`,children:[(0,$.jsx)(`div`,{className:`mb-2 text-xs font-semibold text-foreground/80`,children:r(`console.ai.usage.title`,{defaultValue:`AI usage`})}),(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(ch,{fraction:l,tone:u,size:22}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:Le(`text-sm font-medium`,oh(u)),children:p(u)}),y?(0,$.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:y}):null,v?(0,$.jsx)(q,{variant:`link`,size:`sm`,className:`mt-1 h-auto p-0 text-xs`,"data-testid":`ai-usage-cta`,onClick:()=>window.open(qs(),`_blank`,`noopener,noreferrer`),children:c.upgrade?r(`console.ai.usage.ctaUpgrade`,{defaultValue:`Upgrade to keep going`}):r(`console.ai.usage.ctaTopUp`,{defaultValue:`Add credits to continue`})}):null]})]}),d.length>0?(0,$.jsxs)(`div`,{className:`mt-3 border-t pt-2`,"data-testid":`ai-usage-breakdown`,children:[(0,$.jsx)(`div`,{className:`mb-1 text-xs text-muted-foreground`,children:r(`console.ai.usage.breakdownTitle`,{defaultValue:`Used so far`})}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:d.map(e=>(0,$.jsxs)(`li`,{className:`flex items-center justify-between gap-2 text-xs`,children:[(0,$.jsx)(`span`,{className:`text-foreground`,children:f(e.key)}),(0,$.jsx)(`span`,{className:`tabular-nums text-muted-foreground`,children:nr(e.fraction,{locale:i,style:`percent`,maximumFractionDigits:0})})]},e.key))})]}):null]})]})}var uh=20;function dh(e,t=``){let{href:n,external:r}=_c(e,t);return r?n:!n||n===`#`?``:n}function fh(e){return`nav:${e}`}function ph(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=is(),a=(0,Q.useCallback)((e,i,a,o)=>{let s=fh(e);i?(a&&a.type!==`separator`&&t({id:s,label:yc(a),href:dh(a,o??``),type:`nav`,navId:e,pinned:!0}),r(s,!0)):n(s)},[t,n,r]),o=(0,Q.useCallback)(e=>i.has(e),[i]),s=(0,Q.useCallback)(e=>{if(i.size===0){let t=!1;for(let n of e)if(n.pinned){t=!0;break}if(!t)return e}let t=0,n=e=>e.map(e=>{if(e.type===`separator`)return e;let r=i.has(e.id)&&t<uh;r&&t++;let a=e.children?.length?n(e.children):e.children;return r!==(e.pinned??!1)||a!==e.children?{...e,pinned:r,children:a}:e});return n(e)},[i]),c=(0,Q.useCallback)(()=>{for(let t of e)t.type===`nav`&&n(t.id)},[e,n]);return{pinnedIds:(0,Q.useMemo)(()=>Array.from(i),[i]),togglePin:a,isPinned:o,applyPins:s,clearPins:c}}var mh=0;function hh(e=`nav`){return`${e}_${Date.now()}_${++mh}`}function gh(e,t){return[...e,t]}function _h(e,t){return{id:hh(`nav_page`),type:`page`,...t?{label:t}:{},pageName:e,icon:`FileText`}}function vh(e,t){return{id:hh(`nav_dash`),type:`dashboard`,...t?{label:t}:{},dashboardName:e,icon:`LayoutDashboard`}}function yh(e,t,n){return e.filter(e=>!(e.type===t&&(t===`page`&&e.pageName===n||t===`dashboard`&&e.dashboardName===n))).map(e=>e.children&&e.children.length>0?{...e,children:yh(e.children,t,n)}:e)}function bh(e,t,n,r){return e.map(e=>{let i=e;return t===`page`&&e.type===`page`&&e.pageName===n?i={...e,pageName:r}:t===`dashboard`&&e.type===`dashboard`&&e.dashboardName===n&&(i={...e,dashboardName:r}),i.children&&i.children.length>0?{...i,children:bh(i.children,t,n,r)}:i})}function xh(e,t){return e.length===t.length?e===t||JSON.stringify(e)===JSON.stringify(t):!1}function Sh(e){return typeof e==`string`&&e.startsWith(`sys_`)}function Ch(e){if(!e||typeof e!=`object`)return!1;let t=e;return t._packageId!=null||t._provenance===`package`||Sh(t.name)}function wh(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t._lock??t.protection?.lock;return n!==`full`&&n!==`no-overlay`}function Th(){let e=un(),{apps:t,refresh:n}=Yt(),{t:r}=J(),i=(0,Q.useRef)(e);i.current=e;let a=(0,Q.useRef)(n);a.current=n;let o=(0,Q.useCallback)(async(e,t)=>{let n=i.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await a.current?.()},[]),s=(0,Q.useCallback)(e=>as(t,e),[t]),c=(0,Q.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=gh(a,_h(t,n)),l={...i,navigation:c};try{await o(e,l),Y.success(r(`navigationSync.addedPage`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),Y.info(r(`navigationSync.undone`))}catch{Y.error(r(`navigationSync.undoFailed`))}}}})}catch{Y.error(r(`navigationSync.updateFailed`))}},[s,o,r]),l=(0,Q.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=gh(a,vh(t,n)),l={...i,navigation:c};try{await o(e,l),Y.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),Y.info(r(`navigationSync.undone`))}catch{Y.error(r(`navigationSync.undoFailed`))}}}})}catch{Y.error(r(`navigationSync.updateFailed`))}},[s,o,r]),u=(0,Q.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=yh(i,`page`,t);if(xh(a,i))return;let c={...n,navigation:a};try{await o(e,c),Y.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),Y.info(r(`navigationSync.undone`))}catch{Y.error(r(`navigationSync.undoFailed`))}}}})}catch{Y.error(r(`navigationSync.updateFailed`))}},[s,o,r]),d=(0,Q.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=yh(i,`dashboard`,t);if(xh(a,i))return;let c={...n,navigation:a};try{await o(e,c),Y.success(r(`navigationSync.removedDashboard`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),Y.info(r(`navigationSync.undone`))}catch{Y.error(r(`navigationSync.undoFailed`))}}}})}catch{Y.error(r(`navigationSync.updateFailed`))}},[s,o,r]),f=(0,Q.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=bh(a,`page`,t,n);if(xh(c,a))return;let l={...i,navigation:c};try{await o(e,l),Y.success(r(`navigationSync.renamedPage`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),Y.info(r(`navigationSync.undone`))}catch{Y.error(r(`navigationSync.undoFailed`))}}}})}catch{Y.error(r(`navigationSync.updateFailed`))}},[s,o,r]),p=(0,Q.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=bh(a,`dashboard`,t,n);if(xh(c,a))return;let l={...i,navigation:c};try{await o(e,l),Y.success(r(`navigationSync.renamedDashboard`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),Y.info(r(`navigationSync.undone`))}catch{Y.error(r(`navigationSync.undoFailed`))}}}})}catch{Y.error(r(`navigationSync.updateFailed`))}},[s,o,r]),m=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return{syncPageCreated:c,syncDashboardCreated:l,syncPageDeleted:u,syncDashboardDeleted:d,syncPageRenamed:f,syncDashboardRenamed:p,syncPageCreatedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&wh(r)&&await c(t,e,n)}},[t,c]),syncDashboardCreatedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&wh(r)&&await l(t,e,n)}},[t,l]),syncPageDeletedAllApps:(0,Q.useCallback)(async e=>{for(let n of t){let t=m(n);t&&wh(n)&&await u(t,e)}},[t,u]),syncDashboardDeletedAllApps:(0,Q.useCallback)(async e=>{for(let n of t){let t=m(n);t&&wh(n)&&await d(t,e)}},[t,d]),syncPageRenamedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&wh(r)&&await f(t,e,n)}},[t,f]),syncDashboardRenamedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);t&&wh(r)&&await p(t,e,n)}},[t,p])}}function Eh(){let{pages:e,dashboards:t,apps:n,getTypeStatus:r}=Yt(),i=un(),a=(0,Q.useRef)(i);a.current=i;let o=Oa(),{syncPageCreated:s,syncDashboardCreated:c,syncPageDeleted:l,syncDashboardDeleted:u}=Th(),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p=(0,Q.useRef)(0),m=(0,Q.useRef)(!1),h=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,Q.useEffect)(()=>{if(m.current)return;if(o){d.current=null,f.current=null;return}if(r&&(r(`page`)!==`ready`||r(`dashboard`)!==`ready`))return;let i=e=>new Set(e.filter(e=>!Ch(e)).map(e=>e?.name).filter(e=>typeof e==`string`&&e.length>0)),a=i(e??[]),g=i(t??[]),_=d.current,v=f.current;if(_===null||v===null){d.current=a,f.current=g;return}let y=[...a].filter(e=>!_.has(e)),b=[..._].filter(e=>!a.has(e)),x=[...g].filter(e=>!v.has(e)),S=[...v].filter(e=>!g.has(e));if(y.length===0&&b.length===0&&x.length===0&&S.length===0){d.current=a,f.current=g;return}let C=++p.current;m.current=!0;let w=!1;return(async()=>{try{for(let e of n){if(w||p.current!==C)break;let t=h(e);if(t&&wh(e)){for(let e of y){if(w)break;await s(t,e)}for(let e of b){if(w)break;await l(t,e)}for(let e of x){if(w)break;await c(t,e)}for(let e of S){if(w)break;await u(t,e)}}}}finally{p.current===C&&(d.current=a,f.current=g,m.current=!1)}})(),()=>{w=!0}},[e,t,n,o,r,s,c,l,u]),null}var Dh=768,Oh=1024;function kh(){let{setOpen:e,isMobile:t}=zt(),n=(0,Q.useRef)(e);(0,Q.useEffect)(()=>{n.current=e},[e]),(0,Q.useEffect)(()=>{if(t)return;let e=!1;function r(){let t=window.innerWidth,r=t>=Dh&&t<Oh;r&&!e&&n.current(!1),e=r}return r(),window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r)},[t])}var Ah=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function jh(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Mh(e){try{return decodeURIComponent(e)}catch{return e}}function Nh({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=eo(),o=(0,Q.useRef)(n);o.current=n,(0,Q.useEffect)(()=>{if(i||!t)return;let n=e.split(`/`).filter(Boolean);if(n[0]!==r||n[1]!==t)return;let s=n[2],c=n[3],l=`/${r}/${t}`;if(s===`metadata`){let e=n[3],t=n[4];e&&t&&t!==`new`&&a({id:`metadata:${e}:${Mh(t)}`,label:Mh(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!Ah.has(s)){let e=o.current.find(e=>e.name===s);e&&a({id:`object:${e.name}`,label:e.label||e.name,href:`${l}/${e.name}`,type:`object`});return}if(c)switch(s){case`dashboard`:a({id:`dashboard:${c}`,label:jh(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:jh(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:jh(c),href:`${l}/report/${c}`,type:`report`})}},[e,t,r,i])}function Ph(e){try{let t=window.localStorage.getItem(e),n=t?Number.parseInt(t,10):NaN;return Number.isFinite(n)&&n>0?n:420}catch{return 420}}function Fh(e){let{defaultExpanded:t=!1,persistExpandedKey:n,persistWidthKey:r=Kf}=e??{},[i,a]=Q.useState(()=>n?$f(n,t):t),[o,s]=Q.useState(()=>Ph(r)),[c,l]=Q.useState(!1),[u,d]=Q.useState(!1),f=Q.useRef(!1),p=Q.useRef(null),m=Q.useRef(o);m.current=o;let h=Q.useCallback(e=>{a(t=>{let r=e(t);return n&&ep(n,r),r})},[n]),g=Q.useCallback(e=>{e.preventDefault(),f.current=!1,p.current=null,d(!1);let t=e.clientX,n=o;l(!0);let i=e=>{let r=Xf(n+(t-e.clientX),window.innerWidth);s(r)},a=e=>{let o=Xf(n+(t-e.clientX),window.innerWidth);try{window.localStorage.setItem(r,String(Math.round(o)))}catch{}l(!1),window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a)},[o]),_=Q.useCallback(()=>{f.current||(f.current=!0,p.current=m.current,s(Zf(window.innerWidth)),d(!0))},[]),v=Q.useCallback(()=>{f.current&&(f.current=!1,s(p.current??Ph(r)),p.current=null,d(!1))},[r]);return{expanded:i,width:o,dragging:c,maximized:u,toggle:Q.useCallback(()=>h(e=>!e),[h]),expand:Q.useCallback(()=>h(()=>!0),[h]),collapse:Q.useCallback(()=>h(()=>!1),[h]),maximize:_,restore:v,onResizePointerDown:g}}var Ih=[];function Lh({userId:e,apiBase:t,defaultAgent:n,appPackageId:r,onCanvasOpenChange:i,onBoundPackageChange:a}){let{agents:o,isLoading:s,error:c}=Ss({apiBase:t}),l=Gc(),u=Q.useMemo(()=>up(`default`,{agents:o,appDefaultAgent:n,aiStudioEnabled:Js(),canAuthorMetadata:l}),[o,n,l]),d=u?`${t}/agents/${encodeURIComponent(u)}/chat`:void 0,f=Lp(u),p=f===`build`&&r&&!wm({_packageId:r})?r:void 0,m=u?Rp({appId:p,product:f}):void 0,h=Q.useCallback(e=>p!==void 0&&Sm(e,p),[p]),{conversationId:g,conversationScope:_,initialMessages:v}=Pp({userId:u?e:void 0,scope:m,apiBase:t,activeId:void 0,forceNew:!1,legacyScope:p?f:void 0,adoptLegacy:p?h:void 0}),y=_===m,b=y?g:void 0,x=y?v:Ih;Q.useEffect(()=>{a?.(p)},[p,a]);let S=Q.useRef(null);return!s&&o.length===0?null:(0,$.jsx)(Gm,{agents:o,agentsLoading:s,agentsError:c,activeAgent:u,chatApi:d,apiBase:t,conversationId:b,editPackageId:p,initialMessages:x,pendingFirstMessageRef:S,onSent:()=>{},onShare:()=>{},showDebug:!1,onCanvasOpenChange:i},`${d??`local`}:${b??`pending`}`)}function Rh({dock:e,userId:t,apiBase:n,defaultAgent:r,appPackageId:i,title:a,onMaximize:o,children:s}){let{t:c}=J(),l=Q.useMemo(()=>km(n),[n]),[u,d]=Q.useState(void 0),f=Q.useCallback(t=>t?e.maximize():e.restore(),[e.maximize,e.restore]);return(0,$.jsxs)(`aside`,{"data-testid":`chat-dock-panel`,style:{width:e.width},className:Le(`relative hidden h-full shrink-0 flex-col border-l bg-background md:flex`,!e.dragging&&`transition-[width] duration-200 ease-out`),children:[(0,$.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":c(`console.ai.dock.resize`,{defaultValue:`Resize chat`}),onPointerDown:e.onResizePointerDown,className:Le(`absolute left-0 top-0 z-10 h-full w-1 cursor-col-resize transition-colors hover:bg-primary/40`,e.dragging&&`bg-primary/50`)}),(0,$.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center justify-between border-b px-3`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-semibold text-foreground/80`,children:[(0,$.jsx)(Ei,{className:`size-3.5`}),a??c(`console.ai.dock.title`,{defaultValue:`Assistant`})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,$.jsx)(lh,{apiBase:l}),o?(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:()=>o(u),"aria-label":c(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),title:c(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),"data-testid":`chat-dock-maximize`,children:(0,$.jsx)(Si,{className:`h-3.5 w-3.5`})}):null,(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:e.collapse,"aria-label":c(`console.ai.dock.collapse`,{defaultValue:`Collapse chat`}),"data-testid":`chat-dock-collapse`,children:(0,$.jsx)(Fi,{className:`h-4 w-4`})})]})]}),(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:s??(0,$.jsx)(Lh,{userId:t,apiBase:l,defaultAgent:r,appPackageId:i,onCanvasOpenChange:f,onBoundPackageChange:d})})]})}function zh({open:e,onOpenChange:t,userId:n,apiBase:r,defaultAgent:i,appPackageId:a,title:o,onMaximize:s,children:c}){let{t:l}=J(),u=Q.useMemo(()=>km(r),[r]),[d,f]=Q.useState(void 0),p=Q.useRef(!1);return Q.useEffect(()=>{!e&&p.current&&(p.current=!1,s?.(d))},[e,s,d]),(0,$.jsx)(ht,{open:e,onOpenChange:t,children:(0,$.jsxs)(ke,{side:`bottom`,className:`flex h-[85svh] flex-col gap-0 p-0 md:hidden`,"data-testid":`chat-dock-mobile-sheet`,children:[(0,$.jsxs)(G,{className:`shrink-0 border-b px-4 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 pr-8`,children:[(0,$.jsxs)(H,{className:`inline-flex items-center gap-1.5 text-sm font-semibold`,children:[(0,$.jsx)(Ei,{className:`size-4`}),o??l(`console.ai.dock.title`,{defaultValue:`Assistant`})]}),(0,$.jsx)(lh,{apiBase:u}),s?(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-9 w-9 text-muted-foreground hover:text-foreground`,onClick:()=>{p.current=!0,t(!1)},"aria-label":l(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),"data-testid":`chat-dock-mobile-maximize`,children:(0,$.jsx)(Si,{className:`h-4 w-4`})}):null]}),(0,$.jsx)(je,{className:`sr-only`,children:l(`console.ai.dock.description`,{defaultValue:`AI assistant chat`})})]}),(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:c??(0,$.jsx)(Lh,{userId:n,apiBase:u,defaultAgent:i,appPackageId:a,onBoundPackageChange:f})})]})})}function Bh({onExpand:e,className:t}){let{t:n}=J();return(0,$.jsx)(q,{variant:`outline`,size:`icon`,onClick:e,"data-testid":`chat-dock-launcher`,"aria-label":n(`console.ai.dock.open`,{defaultValue:`Open assistant`}),title:n(`console.ai.dock.open`,{defaultValue:`Open assistant`}),className:Le(`fixed right-0 top-1/2 z-40 hidden h-16 w-7 -translate-y-1/2 rounded-l-md rounded-r-none border-r-0 bg-background shadow-md md:inline-flex`,t),children:(0,$.jsx)(Ei,{className:`size-4`})})}var Vh=new Set([`object`,`app`,`action`]);async function Hh(){try{let e=await o(()=>import(`./dist-yh3dYtHt.js`),[],import.meta.url);return typeof e?.validateCapabilityReferences==`function`?e.validateCapabilityReferences:null}catch{return null}}async function Uh(e,t,n){try{let r=n===void 0?await Hh():n;if(!r)return[];let i=t.filter(e=>Vh.has(e.type));if(i.length===0)return[];let a=e=>{let t=e?.item??e;return t&&typeof t==`object`?ae(t):null},o=await Promise.all(i.map(t=>e.getDraft?.(t.type,t.name,t.packageId?{packageId:t.packageId}:void 0).then(a).catch(()=>null)??Promise.resolve(null))),s=await(e.list?.(`permission`,{}))?.then(e=>Array.isArray(e)?e.map(a).filter(Boolean):[]).catch(()=>[])??[],c=await Promise.all(t.filter(e=>e.type===`permission`).map(t=>e.getDraft?.(t.type,t.name,t.packageId?{packageId:t.packageId}:void 0).then(a).catch(()=>null)??Promise.resolve(null)));return r({objects:o.filter((e,t)=>e&&i[t].type===`object`),apps:o.filter((e,t)=>e&&i[t].type===`app`),actions:o.filter((e,t)=>e&&i[t].type===`action`),permissions:[...s,...c.filter(Boolean)]}).filter(e=>e&&e.severity===`warning`).map(e=>`${e.where}: ${e.message}`)}catch{return[]}}function Wh(e){let t=Da(),[n,r]=(0,Q.useState)(!1);return{publishAll:(0,Q.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 Y.info(e(`home.pendingDrafts.nothing`,{defaultValue:`Nothing to publish.`})),{ok:!0,attempted:0};let r=await Uh(t,n),i=[...new Set(n.map(e=>e.packageId).filter(e=>e!==null))],a=n.filter(e=>e.packageId===null),o=[],s=[],c=0,l=e=>{if(e){e.seedError&&o.push(e.seedError),typeof e.seededRows==`number`&&(c+=e.seededRows);for(let t of e.issues??[])t.severity===`error`&&s.push(t.message)}};for(let e of i){let n=await t.publishPackageDrafts(e);if(n.success===!1){let e=n.error;throw Error(e?.message||`publish-drafts did not publish this package`)}l(Ts(n))}let u=[...a.filter(e=>e.type!==`seed`),...a.filter(e=>e.type===`seed`)];for(let e of u){let n=(await t.publishDraft(e.type,e.name))?.seedApplied;n&&n.success===!1&&o.push(n.error??`${e.name}: sample data failed to load`)}return s.length>0?Y.warning(e(`home.pendingDrafts.probeWarn`,{defaultValue:`Published, but verification found problems.`}),{description:s[0]}):o.length>0?Y.warning(e(`home.pendingDrafts.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:o[0]}):Y.success(c>0?e(`home.pendingDrafts.publishedVerified`,{count:c,defaultValue:`Published & verified — {{count}} sample row(s) live.`}):e(`home.pendingDrafts.published`,{defaultValue:`Published! Your changes are live.`})),r.length>0&&Y.warning(e(`home.pendingDrafts.capabilityWarn`,{count:r.length,defaultValue:`Authoring check: {{count}} capability reference(s) resolve nowhere.`}),{description:r[0],duration:1e4}),Ha(),{ok:!0,attempted:n.length}}catch(t){return Y.error(`${e(`home.pendingDrafts.publishFailed`,{defaultValue:`Publish failed`})}: ${t.message}`),{ok:!1,attempted:0}}finally{r(!1)}},[t,e]),publishing:n}}var Gh=Q.createContext(null);function Kh({onRequest:e,children:t}){let[n,r]=Q.useState(null),i=Q.useRef(0),a=Q.useRef(e);Q.useEffect(()=>{a.current=e});let o=Q.useCallback(e=>{a.current?.(e)!==!1&&(i.current+=1,r({target:e,id:i.current}))},[]),s=Q.useMemo(()=>({requested:n,request:o}),[n,o]);return Q.createElement(Gh.Provider,{value:s},t)}function qh(){return Q.useContext(Gh)?.request??null}function Jh(){return Q.useContext(Gh)?.requested??null}async function Yh(){try{let e=await o(()=>import(`./dist-yh3dYtHt.js`),[],import.meta.url);return typeof e?.validateSecurityPosture==`function`?e.validateSecurityPosture:null}catch{return null}}async function Xh(e,t,n){try{let r=n===void 0?await Yh():n;if(!r)return[];let i=t.filter(e=>e.type===`object`);if(i.length===0)return[];let a=e=>{let t=e?.item??e;return t&&typeof t==`object`?ae(t):null},o=await Promise.all(i.map(t=>e.getDraft?.(t.type,t.name,t.packageId?{packageId:t.packageId}:void 0).then(a).catch(()=>null)??Promise.resolve(null))),s=[];for(let e=0;e<o.length;e++){let t=o[e];t&&s.push({draft:i[e],body:t})}return s.length===0?[]:r({objects:s.map(e=>e.body)}).filter(e=>e&&e.severity===`error`).map(e=>{let t=Number(/^objects\[(\d+)\]/.exec(e.path??``)?.[1]??NaN),n=Number.isInteger(t)?s[t]:s.find(t=>typeof e.where==`string`&&e.where.includes(String(t.draft.name)));return{type:n?.draft.type??`object`,name:n?.draft.name??``,rule:e.rule,hint:e.hint??``,message:e.message??``}}).filter(e=>e.name!==``)}catch{return[]}}async function Zh(e){return(await ef(e)).map(e=>({type:te(e.type),name:e.name,packageId:e.packageId}))}async function Qh(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 $h(e){if(!e||typeof e!=`object`)return null;let t=e,n=t.item&&typeof t.item==`object`?t.item:t;return ae(n)}async function eg(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 $h(await a.json())}function tg(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}function ng(e,t){let n=e??{},r=t??{},i=null;if(n.fields!=null||r.fields!=null){let e=ul(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=>!tg(n[e],r[e])).sort();return{fields:i,changedKeys:o}}function rg({entry:e}){let{t}=J(),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(null);if((0,Q.useEffect)(()=>{let t=!1;return(async()=>{try{let[n,i]=await Promise.all([eg(e.type,e.name,{packageId:e.packageId}),eg(e.type,e.name,{draft:!0,packageId:e.packageId})]);t||r(ng(n,i))}catch(e){t||a(e.message)}})(),()=>{t=!0}},[e.type,e.name,e.packageId]),i)return(0,$.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,$.jsxs)(`p`,{className:`flex items-center gap-1.5 px-2 py-1 text-xs text-muted-foreground`,children:[(0,$.jsx)(X,{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,$.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,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 px-2 py-1`,"data-testid":`draft-entry-detail`,children:[o?.added.map(e=>(0,$.jsxs)(`p`,{className:`font-mono text-xs text-emerald-700 dark:text-emerald-400`,children:[`+ `,e]},`+${e}`)),o?.changed.map(e=>(0,$.jsxs)(`p`,{className:`font-mono text-xs text-amber-700 dark:text-amber-400`,children:[`~ `,e.name,e.keys.length>0&&(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.keys.join(`, `)]})]},`~${e.name}`)),o?.removed.map(e=>(0,$.jsxs)(`p`,{className:`font-mono text-xs text-red-700 line-through dark:text-red-400`,children:[`− `,e]},`-${e}`)),s.length>0&&(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[t(`preview.changes.detailChangedKeys`,{defaultValue:`Also changed:`}),` `,(0,$.jsx)(`span`,{className:`font-mono`,children:s.join(`, `)})]})]})}function ig({open:e,onOpenChange:t,packageId:n,include:r,onPublish:i,publishing:a=!1}){let{t:o}=J(),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),[d,f]=(0,Q.useState)([]),p=qh(),[m,h]=(0,Q.useState)(new Set),g=(0,Q.useCallback)(e=>{h(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),_=(0,Q.useCallback)(async()=>{c(null),u(null),f([]);try{let e=await Zh(n),t=r?e.filter(r):e;c(t),Xh({getDraft:(e,t,r)=>eg(e,t,{draft:!0,packageId:r?.packageId??n??null})},t).then(f,()=>f([]));let i=[...new Set(t.map(e=>e.type))];await Promise.all(i.map(async e=>{let t=null;try{t=await Qh(e)}catch{return}c(n=>n&&n.map(n=>n.type===e?{...n,kind:t.has(n.name)?`update`:`new`}:n))}))}catch(e){u(e.message)}},[n,r]);(0,Q.useEffect)(()=>{e&&_()},[e,_]),(0,Q.useEffect)(()=>{e&&Y.dismiss()},[e]);let v=new Map;for(let e of s??[]){let t=v.get(e.type)??[];t.push(e),v.set(e.type,t)}return(0,$.jsx)(ht,{open:e,onOpenChange:t,children:(0,$.jsxs)(ke,{side:`right`,className:`flex w-[420px] flex-col sm:max-w-[420px]`,"data-testid":`draft-changes-panel`,children:[(0,$.jsxs)(G,{children:[(0,$.jsx)(H,{children:o(`preview.changes.title`,{defaultValue:`Pending changes`})}),(0,$.jsx)(je,{children:o(`preview.changes.description`,{defaultValue:`What publishing will change. New items are added; updates overwrite the live version.`})})]}),(0,$.jsx)(`div`,{"data-testid":`draft-changes-list`,className:`mt-4 flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-4 pb-6`,children:l?(0,$.jsxs)(`p`,{className:`text-sm text-destructive`,children:[o(`preview.changes.loadFailed`,{defaultValue:`Could not load pending changes:`}),` `,l]}):s===null?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(X,{className:`h-4 w-4 animate-spin`}),o(`preview.changes.loading`,{defaultValue:`Loading pending changes…`})]}):s.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o(`preview.changes.empty`,{defaultValue:`Nothing pending — every draft has been published.`})}):[...v.entries()].map(([e,t])=>(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h4`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:[e,` · `,t.length]}),(0,$.jsx)(`ul`,{className:`flex flex-col gap-1`,children:t.map(e=>{let t=`${e.type}:${e.name}`,n=m.has(t);return(0,$.jsxs)(`li`,{className:`rounded-md border text-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>g(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,$.jsx)(Ar,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,$.jsx)(jr,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),e.kind===`new`?(0,$.jsx)(Qr,{className:`h-3.5 w-3.5 shrink-0 text-emerald-600`}):e.kind===`update`?(0,$.jsx)(Zr,{className:`h-3.5 w-3.5 shrink-0 text-amber-600`}):(0,$.jsx)(X,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs`,children:e.name}),e.kind?(0,$.jsx)(pt,{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`?o(`preview.changes.kindNew`,{defaultValue:`New`}):o(`preview.changes.kindUpdate`,{defaultValue:`Update`})}):null]}),n&&(0,$.jsx)(`div`,{className:`border-t bg-muted/20`,children:(0,$.jsx)(rg,{entry:e})})]},t)})})]},e))}),d.length>0&&!l&&(0,$.jsxs)(`div`,{"data-testid":`draft-security-problems`,className:`mt-auto border-t border-amber-200 bg-amber-50 px-4 py-3 dark:border-amber-900/60 dark:bg-amber-950/30`,children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-300`,children:[(0,$.jsx)(Yi,{className:`h-3.5 w-3.5 shrink-0`}),o(`preview.changes.securityBlockTitle`,{count:d.length,defaultValue:`Publishing will be refused — {{count}} item(s) need a decision first`})]}),(0,$.jsx)(`ul`,{className:`mt-1.5 flex flex-col gap-1.5`,children:d.map(e=>(0,$.jsxs)(`li`,{className:`text-[11px] leading-5 text-amber-900 dark:text-amber-200`,children:[p?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>p({type:e.type,name:e.name}),className:`font-mono underline decoration-dotted underline-offset-2 hover:text-amber-950 dark:hover:text-amber-100`,children:[e.type,`/`,e.name]}):(0,$.jsxs)(`span`,{className:`font-mono`,children:[e.type,`/`,e.name]}),` `,`— `,e.hint||e.message]},`${e.type}:${e.name}:${e.rule}`))}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] text-amber-800/80 dark:text-amber-300/80`,children:o(`preview.changes.securityBlockWhere`,{defaultValue:`Fix it on the object under Settings → Record sharing, then publish again.`})})]}),i&&(s?.length??0)>0&&!l&&(0,$.jsxs)(`div`,{className:`mt-auto flex flex-col gap-2 border-t px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n?o(`preview.changes.confirmNote`,{count:s.length,defaultValue:`Publishing releases all {{count}} pending drafts of this package atomically.`}):o(`preview.changes.confirmNoteSeparate`,{count:s.length,defaultValue:`Publishing releases the {{count}} pending drafts one at a time: a draft that fails stays pending while the others go live.`})}),(0,$.jsxs)(q,{size:`sm`,onClick:()=>void i(),disabled:a,"data-testid":`draft-changes-publish`,children:[a?(0,$.jsx)(X,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Bi,{className:`mr-1.5 h-3.5 w-3.5`}),o(`preview.changes.publishConfirm`,{defaultValue:`Publish all`})]})]})]})})}function ag(){let e=Oa(),t=g(),n=r(),{t:i}=J(),{publishAll:a,publishing:o}=Wh(i),[s,c]=(0,Q.useState)(!1),{count:l,refresh:u}=tf({enabled:!!e});if((0,Q.useEffect)(()=>{e&&u()},[e,t.pathname,u]),!e)return null;let d=()=>{wa();let e=new URLSearchParams(t.search);e.delete(Ta);let r=e.toString();n(`${t.pathname}${r?`?${r}`:``}${t.hash}`,{replace:!0})},f=async()=>{(await a()).ok&&(d(),setTimeout(()=>{try{window.location.reload()}catch{}},300))},p=l===0;return(0,$.jsxs)(`div`,{className:Le(`sticky top-0 z-40 border-b`,p?`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-700/60 dark:bg-slate-900/40 dark:text-slate-300`:`border-amber-300/70 bg-amber-50 text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/40 dark:text-amber-200`),"data-testid":`draft-preview-bar`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 text-sm`,children:[(0,$.jsx)(Xr,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:p?i(`preview.draftBar.messageClean`,{defaultValue:`Draft preview — no unpublished changes; everything here is already live.`}):i(`preview.draftBar.message`,{defaultValue:`Draft preview — you are seeing unpublished changes. Nothing here is live until you publish.`})}),!p&&(0,$.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>c(!0),"data-testid":`draft-preview-changes`,children:[(0,$.jsx)(ri,{className:`mr-1 h-3.5 w-3.5`}),i(`preview.draftBar.changes`,{defaultValue:`Changes`}),typeof l==`number`?` (${l})`:``]}),(0,$.jsxs)(q,{size:`sm`,variant:`outline`,onClick:d,"data-testid":`draft-preview-exit`,children:[(0,$.jsx)(ba,{className:`mr-1 h-3.5 w-3.5`}),i(`preview.draftBar.exit`,{defaultValue:`Exit preview`})]})]}),!p&&(0,$.jsxs)($.Fragment,{children:[(0,$.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,$.jsx)(ea,{className:`h-5 w-5 shrink-0 text-amber-600 dark:text-amber-300`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold leading-tight`,children:i(`preview.draftBar.sampleDataTitle`,{defaultValue:`Sample data appears once you publish`})}),(0,$.jsx)(`p`,{className:`text-xs leading-snug text-amber-800/80 dark:text-amber-200/70`,children:i(`preview.draftBar.sampleDataBody`,{defaultValue:`You’re previewing your app’s structure. Publish to load example records and make it live.`})})]}),(0,$.jsxs)(q,{onClick:f,disabled:o,"data-testid":`draft-preview-publish`,className:`shrink-0 shadow-sm`,children:[(0,$.jsx)(Bi,{className:`mr-1.5 h-4 w-4`}),o?i(`preview.draftBar.publishing`,{defaultValue:`Publishing…`}):i(`preview.draftBar.publishCta`,{defaultValue:`Publish to see it live`})]})]}),(0,$.jsx)(ig,{open:s,onOpenChange:c})]})]})}var og=class extends Error{status;code;retryable;constructor(e,t){super(e),this.name=`CommitStoreError`,this.status=t.status,this.code=t.code??null,this.retryable=t.retryable}};function sg(e){return typeof e==`object`&&!!e&&e.retryable===!0}function cg(e){let t=e?.error;if(typeof t==`string`)return{code:null,message:t.trim()||null};if(!t||typeof t!=`object`)return{code:null,message:null};let n=t,r=e=>typeof e==`string`&&e.trim()?e:null;return{code:r(n.code),message:r(n.message)}}function lg(e,t,n){let{code:r,message:i}=cg(t),a=e===503||r===`SERVICE_UNAVAILABLE`;return new og(a?`Commit store temporarily unreachable (HTTP ${e}) — the request did not reach it.`:i??n,{status:e,code:r,retryable:a})}async function ug(e){let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/commits`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok){let e=await t.json().catch(()=>null);throw lg(t.status,e,`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 dg(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)throw lg(n.status,r,`HTTP ${n.status}`)}function fg(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 pg({open:e,onOpenChange:t,packageId:n,onReverted:r}){let{t:i}=J(),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),d=(0,Q.useCallback)(async()=>{o(null),c(null);try{o(await ug(n))}catch(e){c({message:e.message,unreachable:sg(e)})}},[n]);(0,Q.useEffect)(()=>{e&&d()},[e,d]);let f=async e=>{u(e);try{await dg(n,e),Y.success(i(`preview.history.reverted`,{defaultValue:`Reverted — the change has been undone.`})),r?.(),await d()}catch(e){Y.error(sg(e)?i(`preview.history.revertUnavailable`,{defaultValue:`Commit store temporarily unreachable — the revert may not have been applied. Reopen this history to check before retrying.`}):`${i(`preview.history.revertFailed`,{defaultValue:`Revert failed`})}: ${e.message}`)}finally{u(null)}};return(0,$.jsx)(ht,{open:e,onOpenChange:t,children:(0,$.jsxs)(ke,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`commit-timeline-panel`,children:[(0,$.jsxs)(G,{children:[(0,$.jsx)(H,{children:i(`preview.history.title`,{defaultValue:`Build history`})}),(0,$.jsx)(je,{children:i(`preview.history.description`,{defaultValue:`Every change to this app, newest first. Revert any step to undo it — no publish confirmation needed.`})})]}),(0,$.jsx)(`div`,{className:`mt-4 flex flex-col gap-2 overflow-y-auto px-4 pb-6`,children:s?(0,$.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`commit-history-error`,children:s.unreachable?i(`preview.history.loadFailedUnavailable`,{defaultValue:`Commit store temporarily unreachable — this read did not happen, so no history is shown. Retry in a moment.`}):`${i(`preview.history.loadFailed`,{defaultValue:`Could not load history:`})} ${s.message}`}):a===null?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(X,{className:`h-4 w-4 animate-spin`}),i(`preview.history.loading`,{defaultValue:`Loading history…`})]}):a.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`preview.history.empty`,{defaultValue:`No history yet for this app.`})}):a.map(e=>(0,$.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,$.jsx)(ni,{className:`mt-0.5 h-4 w-4 shrink-0 ${e.operation===`revert`?`text-muted-foreground`:`text-primary`}`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.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,$.jsxs)(`p`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[e.operation===`revert`?(0,$.jsx)(pt,{variant:`outline`,className:`border-muted-foreground/30`,children:i(`preview.history.revert`,{defaultValue:`revert`})}):null,(0,$.jsx)(`span`,{children:i(`preview.history.items`,{count:e.itemCount,defaultValue:`{{count}} item(s)`})}),e.actor?(0,$.jsxs)(`span`,{children:[`· `,e.actor]}):null,e.createdAt?(0,$.jsxs)(`span`,{children:[`· `,fg(e.createdAt)]}):null]})]}),e.operation===`apply`?(0,$.jsx)(q,{size:`sm`,variant:`ghost`,className:`shrink-0`,disabled:l!==null,onClick:()=>f(e.id),"data-testid":`commit-revert`,children:l===e.id?(0,$.jsx)(X,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(da,{className:`mr-1 h-3.5 w-3.5`}),i(`preview.history.revertAction`,{defaultValue:`Revert`})]})}):null]},e.id))})]})})}function mg(){let e=Oa(),{appName:t}=f(),n=g(),{apps:r,refresh:i}=Yt(),{t:a}=J(),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1);if(e)return null;let u=t??n.pathname.match(/\/apps\/([^/?#]+)/)?.[1];if(!u)return null;let d=as(r??[],u);if(!d||d._unpublished!==!0)return null;let p=d?.packageId??d?._packageId??null;return(0,$.jsxs)($.Fragment,{children:[(0,$.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,$.jsx)(Yr,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:a(`preview.unpublishedBar.message`,{defaultValue:`Unpublished app — fully functional, but only builders can see it. Publish to make it visible to your users.`})}),p?(0,$.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>l(!0),"data-testid":`unpublished-app-history`,children:[(0,$.jsx)(Vi,{className:`mr-1 h-3.5 w-3.5`}),a(`preview.history.button`,{defaultValue:`History`})]}):null,(0,$.jsxs)(q,{size:`sm`,onClick:async()=>{s(!0);try{let e=await fetch(`/api/v1/meta/app/${encodeURIComponent(u)}`,{method:`PUT`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({...d,_unpublished:!1})});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message??t?.error??`HTTP ${e.status}`)}Y.success(a(`preview.unpublishedBar.published`,{defaultValue:`Published! The app is now visible to your users.`})),i?.()}catch(e){Y.error(`${a(`preview.unpublishedBar.publishFailed`,{defaultValue:`Publish failed`})}: ${e.message}`)}finally{s(!1)}},disabled:o,"data-testid":`unpublished-app-publish`,children:[(0,$.jsx)(Bi,{className:`mr-1 h-3.5 w-3.5`}),o?a(`preview.unpublishedBar.publishing`,{defaultValue:`Publishing…`}):a(`preview.unpublishedBar.publish`,{defaultValue:`Publish`})]})]}),p?(0,$.jsx)(pg,{open:c,onOpenChange:l,packageId:p,onReverted:i}):null]})}function hg(){return hn()?(0,$.jsx)(jt,{}):null}hg.displayName=`ConsoleNotificationBanners`;var gg=`__all__`,_g=`active_package`,vg=new Map([[_g,`package`]]);function yg(e){return vg.get(e)??e}function bg(e){return e.persist??`query`}function xg(e,t){return`objectui-ctx-${e}-${t}`}function Sg(e,t){let n={};for(let r of t)if(bg(r)===`session`)try{let t=sessionStorage.getItem(xg(e,r.id));t&&(n[r.id]=t)}catch{}return n}function Cg(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function wg(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 Tg(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=Cg(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}}return!0}function Eg(e){let[t,n]=Q.useState([]),r=e.optionsSource.endpoint,i=e.optionsSource.valueKey||`id`,a=e.optionsSource.labelKey||`name`,o=e.optionsSource.filter,s=JSON.stringify(o??[]),c=Q.useCallback(async()=>{try{let e=await fetch(r,{credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return;let t=wg(await e.json()),s=[],c=new Set;for(let e of t){if(!Tg(e,o))continue;let t=Cg(e,i);if(t==null||typeof t!=`string`||c.has(t))continue;c.add(t);let n=Cg(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 Q.useEffect(()=>{c();let e=()=>{c()};return window.addEventListener(`objectui:packages-changed`,e),()=>window.removeEventListener(`objectui:packages-changed`,e)},[c]),{options:t,refetch:c}}function Dg(e,t,n){let i=Array.isArray(t)?t:[],a=r(),o=g(),s=new URLSearchParams(o.search),[c,l]=Q.useState(()=>Sg(e,i));Q.useEffect(()=>{let t=Sg(e,i);Object.keys(t).length!==0&&l(e=>{let n;for(let[r,i]of Object.entries(t))e[r]===void 0&&(n??={...e},n[r]=i);return n??e})},[e,i]);let u=Q.useCallback((t,n)=>{let r=n===gg?t.allValue??``:n,i=bg(t);if(i!==`query`){if(l(e=>e[t.id]===r?e:{...e,[t.id]:r}),i===`session`)try{let n=xg(e,t.id);r?sessionStorage.setItem(n,r):sessionStorage.removeItem(n)}catch{}return}let s=new URLSearchParams(o.search),c=yg(t.id);r?s.set(c,r):s.delete(c),a({pathname:o.pathname,search:s.toString()},{replace:!0})},[e,o.pathname,o.search,a]);Q.useEffect(()=>{},[i]);let d={};for(let e of i){let t=bg(e)===`query`?s.get(yg(e.id))??``:c[e.id]??``;d[e.id]=t||(e.allValue??``)}return{contextValues:d,element:i.length===0?null:(0,$.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:i.map(e=>(0,$.jsx)(Og,{def:e,value:d[e.id],onChange:t=>u(e,t),t:n},e.id))})}}function Og({def:e,value:t,onChange:n,t:r}){let{options:i,refetch:a}=Eg(e),o=Wc(e.icon),s=ec(e.label,r)||e.id,c=s===`Package`?r?.(`common.package`,{defaultValue:`Package`})??s:s,l=r?.(`actionDialog.selectPlaceholder`,{label:c,defaultValue:`Select ${c}…`})??`Select ${c}…`,u=!!t&&t!==(e.allValue??``);return Q.useLayoutEffect(()=>{u||i.length>0&&n(i[0].value)},[u,n,i]),(0,$.jsxs)(De,{value:u?t:``,onValueChange:n,onOpenChange:e=>{e&&a()},children:[(0,$.jsx)(B,{"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,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2 overflow-hidden`,children:[(0,$.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,$.jsx)(o,{className:`h-3 w-3`})}),(0,$.jsx)(He,{placeholder:l,className:`truncate`})]})}),(0,$.jsx)(Ie,{className:`w-[var(--radix-select-trigger-width)]`,children:i.map(e=>(0,$.jsx)(Wt,{value:e.value,children:e.label},e.value))})]})}function kg(e){let t=`objectui-nav-order-${e}`,[n,r]=Q.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=Q.useCallback(e=>{r(e);try{localStorage.setItem(t,JSON.stringify(e))}catch{}},[t]);return{applyOrder:Q.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:Q.useCallback(e=>{let t=e.map(e=>e.id);i({...n,__root__:t})},[n,i])}}function Ag(e){return e.componentRef===`metadata:directory`}function jg(e){return e.componentRef===`developer:packages`}function Mg(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 Ng({activeAppName:e}){let{isMobile:t,setOpenMobile:n}=zt(),r=g(),{t:i,language:a}=J(),{appLabel:o}=Xn(),{context:s,currentAppName:c}=Ro(),{user:l,activeOrganization:u}=A(),{isAdmin:d}=S(),f=co(),m=ds();Q.useEffect(()=>{let e=0,r=t=>{e=t.touches[0].clientX},i=r=>{let i=r.changedTouches[0].clientX-e;e<30&&i>50&&t&&n(!0)};return document.addEventListener(`touchstart`,r,{passive:!0}),document.addEventListener(`touchend`,i,{passive:!0}),()=>{document.removeEventListener(`touchstart`,r),document.removeEventListener(`touchend`,i)}},[t,n]);let{recentItems:h}=eo(),{favorites:_,removeFavorite:v}=is(),{apps:y,objects:b}=Yt(),x=y||[],C=Qu(),w=x.filter(e=>e.active!==!1&&e.hidden!==!0),T=as(x.filter(e=>e.active!==!1),e||c)||w[0],E=s===`app`?T?.branding?.logo:void 0,{applyOrder:D,handleReorder:O}=kg(T?.name||`home`),{togglePin:k,applyPins:j}=ph(),{evaluator:M}=Ua(),N=Q.useCallback(e=>qa(e,M),[M]),{can:ee,hasCapabilities:P}=at(),F=Q.useCallback(e=>e.every(e=>{let t=e.split(`:`);return t.length>=2?ee(t[0],t[1]):P([e])||ee(e,`read`)}),[ee,P]),te=Q.useMemo(()=>new Set((b||[]).map(e=>e?.name).filter(Boolean)),[b]),I=Q.useCallback((e,t)=>e!==`object`||te.size===0||te.has(t),[te]),ne=T?.areas||[],re=ho(s===`app`?[T?.navigation,...ne.map(e=>e.navigation)]:[]),L=ne.filter(e=>bc(e.navigation,{evaluateVisibility:N,checkPermission:F,checkCapability:I,checkDocTarget:re,hasActionHandler:!!f})),[ie,ae]=Q.useState(()=>L.length>0?L[0].id:null),oe=L.map(e=>e.id).join(`,`);Q.useEffect(()=>{L.length>0?ae(e=>L.some(t=>t.id===e)?e:L[0].id):ae(null)},[T?.name,oe]);let R=L.find(e=>e.id===ie)??L[0],ce=R?.navigation||T?.navigation||[],{contextValues:le,element:z}=Dg(T?.name||`home`,T?.contextSelectors,i),ue=Q.useMemo(()=>{let e=[{id:`home-dashboard`,label:i(`home.nav`,{defaultValue:`Home`}),type:`url`,url:C,icon:`home`},{id:`docs`,label:i(`layout.systemNav.documentation`,{defaultValue:`Documentation`}),type:`url`,url:`/docs`,icon:`book-open`}];if(d){let t=[{id:`sys-settings`,label:i(`layout.systemNav.systemSettings`,{defaultValue:`System Settings`}),type:`url`,url:`/apps/setup/system`,icon:`settings`},{id:`sys-apps`,label:i(`layout.systemNav.applications`,{defaultValue:`Applications`}),type:`url`,url:`/apps/setup/system/apps`,icon:`layout-grid`},{id:`sys-marketplace`,label:i(`layout.systemNav.appMarketplace`,{defaultValue:`App Marketplace`}),type:`url`,url:`/apps/setup/system/marketplace`,icon:`store`},{id:`sys-objects`,label:i(`layout.systemNav.objectManager`,{defaultValue:`Object Manager`}),type:`url`,url:`/apps/setup/metadata/object`,icon:`database`},{id:`sys-datasources`,label:i(`layout.systemNav.datasources`,{defaultValue:`Datasources`}),type:`url`,url:`/apps/setup/metadata/datasource`,icon:`database`},{id:`sys-users`,label:i(`layout.systemNav.users`,{defaultValue:`Users`}),type:`url`,url:`/apps/setup/system/users`,icon:`users`},{id:`sys-orgs`,label:i(`layout.systemNav.organizations`,{defaultValue:`Organizations`}),type:`url`,url:`/apps/setup/system/organizations`,icon:`building-2`},{id:`sys-roles`,label:i(`layout.systemNav.roles`,{defaultValue:`Roles`}),type:`url`,url:`/apps/setup/system/roles`,icon:`shield`},{id:`sys-config`,label:i(`layout.systemNav.configuration`,{defaultValue:`Configuration`}),type:`url`,url:`/apps/setup/system/settings`,icon:`sliders-horizontal`}];e.push({id:`sys-administration`,label:i(`layout.systemNav.administration`,{defaultValue:`Administration`}),type:`group`,icon:`shield`,expanded:!0,children:t})}return e},[i,d,C]),de=s===`home`?ue:ce,fe=s===`app`&&T?`/apps/${ss(T)}`:``,pe=s===`app`&&T?.name===`studio`,B=yg(_g),me=le[_g],he=Q.useMemo(()=>{if(!pe)return``;let e=new URLSearchParams(r.search).get(B)||me;return e?`?${B}=${encodeURIComponent(e)}`:``},[me,pe,r.search,B]),ge=Q.useMemo(()=>{if(s!==`app`||T?.name!==`studio`)return de;let e=i(`sidebar.packageManagement`,{defaultValue:`Package management`}),t=n=>n.flatMap(n=>{if(Ag(n))return[];if(n.type===`separator`)return[n];let r=n.children?.length?t(n.children):n.children;return n.type===`group`&&r?.length===0?[]:jg(n)?[{...n,type:`url`,label:e,url:`${fe}/component/developer/packages${he}`,children:r}]:r===n.children?[n]:[{...n,children:r}]});return t(de).flatMap(e=>Mg(e)?e.children??[]:[e])},[T?.name,fe,s,de,he,i]),_e=Q.useMemo(()=>{let e=D(ge);return j(e)},[ge,D,j]),[V,ve]=Q.useState(!1),H=pe&&r.pathname.replace(/\/+$/,``)===fe;return(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(It,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[E&&(0,$.jsx)(ut,{className:`border-b p-2`,children:(0,$.jsx)(`img`,{src:E,alt:o({name:T.name,label:ec(T.label,i)}),className:`h-8 w-auto max-w-full object-contain object-left`})}),t&&s===`app`&&(0,$.jsx)(ut,{className:`border-b p-1.5`,children:(0,$.jsx)(Ht,{children:(0,$.jsx)(Re,{children:(0,$.jsx)(Vt,{asChild:!0,className:`min-h-[44px] text-[15px] font-medium rounded-xl`,children:(0,$.jsxs)(p,{to:C,onClick:()=>n(!1),"data-testid":`mobile-sidebar-home`,children:[(0,$.jsx)(ci,{className:`h-5 w-5`}),(0,$.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,$.jsx)(nt,{className:`pt-2`,children:(0,$.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:s===`app`&&T?(0,$.jsxs)($.Fragment,{children:[z&&(0,$.jsx)(Dt,{className:`group-data-[state=collapsed]:hidden px-2 pb-1`,children:(0,$.jsx)(`div`,{className:`rounded-lg border border-sidebar-border/70 bg-sidebar-accent/25 p-1.5 shadow-xs`,children:(0,$.jsx)(xt,{children:z})})}),pe&&(0,$.jsx)(Dt,{children:(0,$.jsx)(xt,{children:(0,$.jsx)(Ht,{children:(0,$.jsx)(Re,{children:(0,$.jsx)(Vt,{asChild:!0,isActive:H,tooltip:i(`home.nav`,{defaultValue:`Home`}),children:(0,$.jsxs)(p,{to:{pathname:fe,search:he},children:[(0,$.jsx)(ci,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:i(`home.nav`,{defaultValue:`Home`})})]})})})})})}),L.length>1&&(0,$.jsxs)(Dt,{children:[(0,$.jsxs)(ft,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(fi,{className:`h-3.5 w-3.5`}),i(`sidebar.area`,{defaultValue:`Area`})]}),(0,$.jsx)(xt,{children:(0,$.jsx)(Ht,{children:L.map(e=>{let t=Wc(e.icon),n=e.id===R?.id,r=se(e.label,a);return(0,$.jsx)(Re,{children:(0,$.jsxs)(Vt,{isActive:n,tooltip:r,onClick:()=>ae(e.id),children:[(0,$.jsx)(t,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:r})]})},e.id)})})})]}),(0,$.jsx)(vc,{items:_e,basePath:fe,evaluateVisibility:N,checkPermission:F,checkCapability:I,checkDocTarget:re,enablePinning:!t,onPinToggle:k,enableReorder:!t,onReorder:O,resolveTargetLabel:m,locale:a,onAction:f,t:i,templateContext:{currentUserId:l?.id??null,currentOrgId:u?.id??null,contextValues:le}}),h.length>0&&(0,$.jsxs)(Dt,{children:[(0,$.jsxs)(ft,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>ve(e=>!e),children:[(0,$.jsx)(jr,{className:`h-3 w-3 transition-transform duration-150 ${V?`rotate-90`:``}`}),(0,$.jsx)(Br,{className:`h-3.5 w-3.5`}),i(`sidebar.recent`,{defaultValue:`Recent`})]}),V&&(0,$.jsx)(xt,{children:(0,$.jsx)(Ht,{children:h.slice(0,5).map(e=>(0,$.jsx)(Re,{children:(0,$.jsx)(Vt,{asChild:!0,tooltip:e.label,children:(0,$.jsxs)(p,{to:e.href,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:`📄`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]})})},e.id))})})]}),_.some(e=>e.type!==`nav`)&&(0,$.jsxs)(Dt,{children:[(0,$.jsxs)(ft,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(ia,{className:`h-3.5 w-3.5`}),i(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,$.jsx)(xt,{children:(0,$.jsx)(Ht,{children:_.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,$.jsxs)(Re,{children:[(0,$.jsx)(Vt,{asChild:!0,tooltip:e.label,children:(0,$.jsxs)(p,{to:e.href,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:e.type===`page`?`📄`:`📋`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,$.jsx)(Ze,{showOnHover:!0,onClick:t=>{t.stopPropagation(),v(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,$.jsx)(ra,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(vc,{items:ue,basePath:``,evaluateVisibility:N,checkPermission:F,checkCapability:I,resolveTargetLabel:m,locale:a,onAction:f,t:i,templateContext:{currentUserId:l?.id??null,currentOrgId:u?.id??null,contextValues:le}}),_.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,$.jsxs)(Dt,{children:[(0,$.jsxs)(ft,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(ia,{className:`h-3.5 w-3.5`}),i(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,$.jsx)(xt,{children:(0,$.jsx)(Ht,{children:_.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,$.jsxs)(Re,{children:[(0,$.jsx)(Vt,{asChild:!0,tooltip:e.label,children:(0,$.jsxs)(p,{to:e.href,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`page`?`📄`:`📋`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,$.jsx)(Ze,{showOnHover:!0,onClick:t=>{t.stopPropagation(),v(e.id)},"aria-label":i(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,$.jsx)(ra,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,$.jsx)(ct,{className:`border-t p-1`,children:(0,$.jsx)(zf,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function Pg({children:e}){return kh(),(0,$.jsx)($.Fragment,{children:e})}function Fg({children:e,activeAppName:t,activeApp:n,onAppChange:i,objects:a,connectionState:o,userId:s}){let c=ec(n?.label)||t,{enabled:l}=vo(),{setContext:u,setCurrentAppName:d}=Ro(),f=Fh({persistExpandedKey:qf}),p=l,m=r(),h=g(),_=de(),v=(0,Q.useCallback)(e=>{if(rp(`${h.pathname}${h.search}`),!e){m(`/ai`);return}try{sessionStorage.setItem(`objectstack:ai-full-page-requested`,`1`)}catch{}m(`/ai/build?package=${encodeURIComponent(e)}`)},[h.pathname,h.search,m]);return(0,Q.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,Q.useEffect)(()=>{if(!p)return;let e=e=>{ap(e)===`toggle`&&(e.preventDefault(),f.toggle())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[p,f]),(0,$.jsx)(Af,{children:(0,$.jsx)(Tf,{children:(0,$.jsxs)(xc,{sidebar:(0,$.jsx)(Ng,{activeAppName:t,onAppChange:i}),navbar:(0,$.jsx)(Gf,{variant:`app`,appName:c,objects:a,connectionState:o,activeAppName:t,onAppChange:i}),className:`!p-0 overflow-y-auto overflow-x-hidden bg-muted/5`,rightRail:p&&f.expanded&&!_?(0,$.jsx)(Rh,{dock:f,userId:s,defaultAgent:n?.defaultAgent,appPackageId:n?._packageId,onMaximize:v}):void 0,branding:n?.branding?{primaryColor:n.branding.primaryColor,accentColor:n.branding.accentColor,favicon:n.branding.favicon,title:n.label?`${ec(n.label)} — ${Gs()}`:void 0}:void 0,children:[(0,$.jsxs)(Pg,{children:[(0,$.jsx)(ag,{}),(0,$.jsx)(mg,{}),(0,$.jsx)(hg,{}),e]}),l&&!f.expanded&&(0,$.jsx)(Ud,{appLabel:c,onOpenDock:f.expand}),p&&_&&(0,$.jsx)(zh,{open:f.expanded,onOpenChange:e=>e?f.expand():f.collapse(),userId:s,defaultAgent:n?.defaultAgent,appPackageId:n?._packageId,onMaximize:v})]})})})}function Ig({apps:e,activeApp:t,objects:n,onAppChange:i,dataSource:a}){let{open:o,setOpen:s}=jf(),[c,l]=(0,Q.useState)(``),u=r(),{appName:d}=f(),{setTheme:p}=td(),{evaluator:m}=Ua(),{t:h,language:g}=J(),_=ds(),v=e=>yc(e,h,_,g);(0,Q.useEffect)(()=>{o||l(``)},[o]);let y=`/apps/${d||ss(t)}`,{user:b,activeOrganization:x}=A(),S=(0,Q.useMemo)(()=>({currentUserId:b?.id??null,currentOrgId:x?.id??null}),[b?.id,x?.id]),C=(0,Q.useCallback)(e=>{s(!1),e()},[]),w=Lg(t?.navigation||[]).filter(e=>qa(e.visible??e.visibleOn,m)),T=(0,Q.useMemo)(()=>w.filter(e=>e.type===`object`&&typeof e.objectName==`string`).map(e=>e.objectName),[t?.name,w.map(e=>e.objectName||``).join(`|`)]),E=at(),{results:D,isSearching:O}=yn({query:c,objects:n,dataSource:a,objectNames:T,enabled:o&&!!a,getDisplayName:qt,fieldReadPolicy:E}),{recentItems:k}=eo(),j=(0,Q.useMemo)(()=>k.filter(e=>e.type===`record`).slice(0,5),[k]),M=o&&c.trim().length===0&&j.length>0,N=(0,Q.useMemo)(()=>{let e=new Map;for(let t of n||[])typeof t?.name==`string`&&e.set(t.name,t);return e},[n]),ee=(0,Q.useMemo)(()=>{let e=[],t=new Map;for(let n of D){let r=t.get(n.objectName);if(!r){let i=N.get(n.objectName);r={objectLabel:ec(i?.label,h)||n.objectLabel,icon:n.icon,hits:[]},t.set(n.objectName,r),e.push(n.objectName)}r.hits.push(n)}return e.map(e=>({objectName:e,...t.get(e)}))},[D,N,h]);return(0,$.jsxs)(Bt,{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,$.jsx)(he,{placeholder:h(`console.commandPalette.placeholder`),value:c,onValueChange:l}),(0,$.jsxs)(vt,{children:[(0,$.jsx)(Be,{children:O?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-muted-foreground`,children:[(0,$.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`)}),M&&(0,$.jsx)(V,{heading:h(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:j.map(e=>(0,$.jsxs)(Ne,{value:`recent ${e.label} ${e.id}`,onSelect:()=>C(()=>u(e.href)),children:[(0,$.jsx)(Gi,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]},`recent:${e.id}`))}),ee.map((e,t)=>{let n=Wc(e.icon);return(0,$.jsx)(V,{heading:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e.objectLabel,O&&t===0&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`inline-block h-1.5 w-1.5 rounded-full bg-primary motion-safe:animate-pulse`})]}),children:e.hits.map(e=>(0,$.jsxs)(Ne,{value:`record ${c} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>C(()=>u(`${y}/${e.objectName}/record/${e.recordId}`)),children:[(0,$.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.display}),e.subtitle&&(0,$.jsx)(`span`,{className:`ml-auto max-w-[45%] truncate text-xs text-muted-foreground`,children:e.subtitle})]},`${e.objectName}:${e.recordId}`))},`records:${e.objectName}`)}),w.filter(e=>e.type===`object`).length>0&&(0,$.jsx)(V,{heading:h(`console.commandPalette.objects`),children:w.filter(e=>e.type===`object`).map(e=>{let t=Wc(e.icon);return(0,$.jsxs)(Ne,{value:`object ${v(e)} ${e.objectName}`,onSelect:()=>C(()=>u(_c(e,y,S).href)),children:[(0,$.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:v(e)})]},e.id)})}),w.filter(e=>e.type===`dashboard`).length>0&&(0,$.jsx)(V,{heading:h(`console.commandPalette.dashboards`),children:w.filter(e=>e.type===`dashboard`).map(e=>(0,$.jsxs)(Ne,{value:`dashboard ${v(e)} ${e.dashboardName}`,onSelect:()=>C(()=>u(_c(e,y,S).href)),children:[(0,$.jsx)(pi,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:v(e)})]},e.id))}),w.filter(e=>e.type===`page`).length>0&&(0,$.jsx)(V,{heading:h(`console.commandPalette.pages`),children:w.filter(e=>e.type===`page`).map(e=>(0,$.jsxs)(Ne,{value:`page ${v(e)} ${e.pageName}`,onSelect:()=>C(()=>u(_c(e,y,S).href)),children:[(0,$.jsx)($r,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:v(e)})]},e.id))}),w.filter(e=>e.type===`report`).length>0&&(0,$.jsx)(V,{heading:h(`console.commandPalette.reports`),children:w.filter(e=>e.type===`report`).map(e=>(0,$.jsxs)(Ne,{value:`report ${v(e)} ${e.reportName}`,onSelect:()=>C(()=>u(_c(e,y,S).href)),children:[(0,$.jsx)(Er,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:v(e)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(fe,{}),(0,$.jsx)(V,{heading:h(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=Wc(e.icon);return(0,$.jsxs)(Ne,{value:`app ${ec(e.label,h)} ${e.name}`,onSelect:()=>C(()=>i(ss(e)??e.name)),children:[(0,$.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:ec(e.label,h)}),e.name===t?.name&&(0,$.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:h(`console.commandPalette.current`)})]},e.name)})})]}),(0,$.jsx)(fe,{}),(0,$.jsxs)(V,{heading:h(`console.commandPalette.preferences`),children:[(0,$.jsxs)(Ne,{value:`theme light`,onSelect:()=>C(()=>p(`light`)),children:[(0,$.jsx)(aa,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:h(`console.commandPalette.lightTheme`)})]}),(0,$.jsxs)(Ne,{value:`theme dark`,onSelect:()=>C(()=>p(`dark`)),children:[(0,$.jsx)(Oi,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:h(`console.commandPalette.darkTheme`)})]}),(0,$.jsxs)(Ne,{value:`theme system`,onSelect:()=>C(()=>p(`system`)),children:[(0,$.jsx)(Di,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:h(`console.commandPalette.systemTheme`)})]})]}),(0,$.jsx)(fe,{}),(0,$.jsx)(V,{heading:h(`console.commandPalette.actions`),children:(0,$.jsxs)(Ne,{value:`search all results full page`,onSelect:()=>C(()=>u(`${y}/search`)),children:[(0,$.jsx)(Gi,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:h(`console.commandPalette.openFullSearch`)})]})})]})]})}function Lg(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...Lg(n.children)):t.push(n);return t}function Rg(){let{t:e}=J(),{open:t,setOpen:n,toggleOverlay:r}=Xu(es),i=(0,Q.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,Q.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,$.jsx)(gt,{open:t,onOpenChange:n,children:(0,$.jsxs)(Ae,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,"data-testid":`overlay:keyboard-shortcuts`,children:[(0,$.jsxs)(U,{children:[(0,$.jsx)(Ce,{children:e(`console.shortcuts.title`)}),(0,$.jsx)(Me,{children:e(`console.shortcuts.description`)})]}),(0,$.jsx)(`div`,{className:`space-y-6 pt-2`,children:i.map(e=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground mb-3`,children:e.title}),(0,$.jsx)(`div`,{className:`space-y-2`,children:e.shortcuts.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm`,children:e.description}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:e.keys.map((e,t)=>(0,$.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 zg(){return null}function Bg(e){let{theme:t=`system`}=td(),{t:n}=J();return(0,$.jsx)(pr,{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,$.jsx)(Ir,{className:`h-4 w-4`}),info:(0,$.jsx)(li,{className:`h-4 w-4`}),warning:(0,$.jsx)(ua,{className:`h-4 w-4`}),error:(0,$.jsx)(Ai,{className:`h-4 w-4`}),loading:(0,$.jsx)(X,{className:`h-4 w-4 animate-spin`})},toastOptions:{duration:4e3,classNames:{toast:`group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg`,description:`group-[.toast]:text-muted-foreground`,actionButton:`group-[.toast]:bg-primary group-[.toast]:text-primary-foreground`,cancelButton:`group-[.toast]:bg-muted group-[.toast]:text-muted-foreground`}},...e})}var Vg=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function Hg({children:e,className:t}){let n=g(),r=Q.useRef(null),i=Q.useRef(n.pathname);return Q.useLayoutEffect(()=>{if(i.current===n.pathname)return;i.current=n.pathname;let e=r.current;e&&(e.classList.remove(...Vg),e.offsetWidth,e.classList.add(...Vg))},[n.pathname]),(0,$.jsx)(`div`,{ref:r,className:[...Vg,t??``].filter(Boolean).join(` `),children:e})}var Ug=null,Wg=null,Gg={enabled:!1,reason:`no-dsn`,dsn:``,sendDefaultPii:!1,environment:``,tracesSampleRate:0,replaysOnErrorSampleRate:0};function Kg(e){if(!e)return Gg;let t=typeof e.dsn==`string`?e.dsn.trim():``;return t?{enabled:!0,reason:`opted-in`,dsn:t,sendDefaultPii:e.sendDefaultPii===!0,environment:typeof e.environment==`string`?e.environment.trim():``,tracesSampleRate:qg(e.tracesSampleRate,.1),replaysOnErrorSampleRate:qg(e.replaysOnErrorSampleRate,0)}:Gg}function qg(e,t){return typeof e==`number`&&Number.isFinite(e)&&e>=0&&e<=1?e:t}function Jg(){return Wg||(Wg=(async()=>{let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},t=Kg(Ks());if(!t.enabled)return!1;try{let n=await o(()=>import(`./vendor-sentry-T8UUthV_.js`).then(e=>e.t),[],import.meta.url);return n.init({dsn:t.dsn,environment:t.environment||e.MODE||`production`,release:e.VITE_SENTRY_RELEASE||e.VITE_APP_VERSION||`unknown`,tracesSampleRate:t.tracesSampleRate,sendDefaultPii:t.sendDefaultPii,replaysSessionSampleRate:0,replaysOnErrorSampleRate:t.replaysOnErrorSampleRate,integrations:[n.browserTracingIntegration()],beforeBreadcrumb(e){return(e.category===`fetch`||e.category===`xhr`)&&e.data?.url&&typeof e.data.url==`string`&&(e.data.url=Xg(e.data.url)),e}}),Ug=n,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),Wg)}function Yg(e,t){if(Ug)try{Ug.captureException(e,t?{extra:t}:void 0)}catch{}}function Xg(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 Zg({error:e,onReset:t}){let{t:n}=J();return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-8`,children:(0,$.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,$.jsxs)(ve,{children:[(0,$.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10`,children:(0,$.jsx)(ua,{className:`h-6 w-6 text-destructive`})}),(0,$.jsx)(pe,{children:n(`console.errors.somethingWentWrong`)}),(0,$.jsx)(ge,{className:`mb-4`,children:e.message||n(`console.errors.unexpectedError`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,$.jsxs)(q,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,$.jsx)(Hi,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,$.jsxs)(q,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,$.jsx)(ci,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var Qg=class extends Q.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),Yg(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,$.jsx)(Zg,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}},$g=`list-filters`;function e_(e,t,n){if(t&&n)return`${$g}:${e||`anon`}:${t}:${n}`}function t_(e){return!e||!Array.isArray(e.conditions)||e.conditions.length===0}function n_(e){return t_(e.filters)&&!(e.search&&e.search.length>0)}function r_(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 i_={},a_={};function o_(e,t){!e||typeof localStorage>`u`||(i_[e]={...i_[e]??r_(e)??{},...t},a_[e]&&clearTimeout(a_[e]),a_[e]=setTimeout(()=>{let t=i_[e]??{};delete i_[e],delete a_[e];try{n_(t)?localStorage.removeItem(e):localStorage.setItem(e,JSON.stringify(t))}catch{}},300))}var s_=new Set([`form`,`detail`]);function c_(e){return typeof e==`string`&&s_.has(e)}function l_(e,t){let n=e.type||`grid`,r=c_(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 u_(e){let t=e.config;if(!t||typeof t!=`object`||Array.isArray(t))return e;let{config:n,...r}=e,i=typeof e.name==`string`?e.name:``,a=t;return{...r,...a,id:i,name:i,label:e.label??a.label}}function d_(e){let t=e.config??{},n={...t};return delete n.data,{...n,id:e.name,label:e.label??t.label}}function f_(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 p_({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s,metadataClient:c,dataSource:l,onAfterChange:u}){let{t:d}=J(),f=(0,Q.useRef)(null),p=El(),[m]=(0,Q.useState)(()=>`view_${Date.now()}`),h=(0,Q.useMemo)(()=>({id:m,label:d(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[]}),[]),g=n===`create`?`create`:r.id,_=(0,Q.useMemo)(()=>l_(n===`create`?h:r,i.name),[g,i.name]),[v,y]=(0,Q.useState)(_),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(0),[w,T]=(0,Q.useState)(!1),E=(0,Q.useRef)(v),D=(0,Q.useRef)(_);D.current!==_&&(D.current=_,E.current=_,y(_),x(!1)),(0,Q.useEffect)(()=>{E.current=v},[v]),(0,Q.useEffect)(()=>{e&&f.current&&f.current.focus()},[e]);let O=(0,Q.useMemo)(()=>f_(i),[i.fields]),k=go(v.viewKind)?`form`:`list`,A=(0,Q.useCallback)(e=>{let t={...E.current,...e};if(E.current=t,y(t),x(!0),a){let e=d_(t);for(let[t,n]of Object.entries(e))t!==`id`&&a(t,n)}},[a]),j=(0,Q.useCallback)(async()=>{let e=d_(v);if(n===`create`){s?.(e),x(!1);return}let t=E.current;T(!0);let r;try{r=await o?.(e)!==!1}catch{r=!1}finally{T(!1)}r&&(C(e=>e+1),E.current===t&&x(!1))},[v,o,s,n]),M=(0,Q.useCallback)(()=>{if(n===`edit`){if(a){let e=d_(_),t=d_(E.current),n=new Set([...Object.keys(t),...Object.keys(e)]);for(let t of n)t!==`id`&&a(t,e[t])}E.current=_,y(_),x(!1)}t()},[_,n,t,a]),N=(0,Q.useCallback)(e=>{let t=l_(u_(e),i.name);E.current=t,y(t),x(!1)},[i.name]),ee=d(n===`create`?`console.objectView.createView`:`console.objectView.configureView`);return e?(0,$.jsxs)(`div`,{ref:f,tabIndex:-1,role:`complementary`,"aria-label":ee,"data-testid":`view-config-panel`,className:`flex h-full flex-col`,children:[(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,$.jsx)(bo,{type:`view`,name:v.name,draft:v,variantKey:`config`,familyKey:k,isHome:!0,readOnly:!1,locale:p,objectFieldsOverride:O,onPatch:A})}),(0,$.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,$.jsx)(Il,{type:`view`,name:r.id,metadataClient:c,dataSource:l,objectName:i.name,dirty:b,onResume:N,savedSignal:S,onAfterChange:u}),(0,$.jsx)(q,{variant:`ghost`,size:`sm`,onClick:M,"data-testid":`view-config-discard`,children:d(`console.objectView.discard`)}),(0,$.jsx)(q,{size:`sm`,onClick:j,disabled:w||n===`edit`&&!b,"data-testid":`view-config-save`,children:d(`console.objectView.save`)})]})]}):(0,$.jsx)(`div`,{ref:f,tabIndex:-1,"data-testid":`view-config-panel`,"aria-hidden":!0})}var m_=`sys_user`;function h_(e,t=500){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function g_(e){let t=e.writeMode??`insert`;if(t===`update`)throw Error(`Identity import supports the insert and upsert write modes only.`);if(t===`insert`)return{mode:`insert`};let n=(e.matchFields??[])[0];if(n===`email`)return{mode:`upsert`,matchBy:`email`};if(n===`phone_number`)return{mode:`upsert`,matchBy:`phone`};throw Error(`Identity import matches existing users by "email" or "phone_number" only.`)}function __(e,t,n){let r=0,i=0,a=0,o=0,s=0,c=[],l=0;for(let n=0;n<e.length;n++){let{summary:u,rows:d}=e[n],f=t[n]??[];r+=u.total,i+=u.created,a+=u.updated,o+=u.skipped,s+=u.errors;for(let e of d){if(!e)continue;let t=f[e.row-1],n=[t?.email,t?.phone_number,t?.phoneNumber,t?.phone].find(e=>typeof e==`string`&&e.trim().length>0);c.push({row:l+e.row,ok:e.ok,action:e.action,...e.id?{id:e.id}:{},...e.field?{field:e.field}:{},...e.code?{code:e.code}:{},...e.error?{error:e.error}:{},...e.temporaryPassword?{temporaryPassword:e.temporaryPassword}:{},...n?{identity:n.trim()}:{}})}l+=f.length||u.total}return{object:m_,dryRun:n.dryRun,writeMode:n.writeMode,total:r,ok:r-s,errors:s,created:i,updated:a,skipped:o,results:c}}function v_(e){let{base:t,authFetch:n,baseUrl:r,getPasswordPolicy:i}=e,a=async(e,t)=>{let{mode:a,matchBy:o}=g_(t),s=i(),c=Array.isArray(t.rows)?t.rows:[];if(c.length===0)throw Error(`Identity import needs mapped rows (rows[]) — file uploads are parsed client-side.`);let l=h_(c),u=[];for(let e of l){let i=await n(`${r}/api/v1/auth/admin/import-users`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({format:`json`,rows:e,mode:a,...o?{matchBy:o}:{},passwordPolicy:s,...t.dryRun?{dryRun:!0}:{},...t.mappingName?{mappingName:t.mappingName}:{},...t.trimWhitespace===void 0?{}:{trimWhitespace:t.trimWhitespace},...t.nullValues?{nullValues:t.nullValues}:{}})}),c=await i.json().catch(()=>null);if(!i.ok||!c?.success||!c.data){let e=c?.error?.message??`Identity import failed with status ${i.status}`;throw Error(e)}u.push(c.data)}return __(u,l,{dryRun:t.dryRun===!0,writeMode:a})};return{...t,importRecords:a,createImportJob:void 0,getImportJobProgress:void 0,getImportJobResults:void 0,listImportJobs:void 0,cancelImportJob:void 0,undoImportJob:void 0,downloadImportTemplate:void 0,listImportMappings:t.listImportMappings?.bind(t)}}function y_(e){if(!e?.results)return[];let t=[];for(let n of e.results)n?.temporaryPassword&&t.push({row:n.row,identity:n.identity??`#${n.row}`,temporaryPassword:n.temporaryPassword});return t}function b_(e){let t=e=>/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e,n=[`row,identity,temporary_password`];for(let r of e)n.push(`${r.row},${t(r.identity)},${t(r.temporaryPassword)}`);return n.join(`
8
+ `)}var x_={auto:{label:`Automatic (recommended)`,hint:`Reachable users get an invitation (email or SMS); anyone we can't reach gets a one-time password, shown ONCE on the result screen. Works with or without an email/SMS service.`},invite:{label:`Send invitations`,hint:`Every created user gets a set-your-password email (or an invitation SMS for phone-only rows). Requires a configured email/SMS service — unreachable rows fail.`},temporary:{label:`Temporary passwords`,hint:`For deployments without email/SMS: every created user gets a one-time password, shown ONCE on the result screen. First sign-in forces a change.`},none:{label:`No password (identity only)`,hint:`Users first sign in with a phone OTP, magic link, or password-reset link, then set their own password.`}};function S_({policy:e,onPolicyChange:t}){let n=Zn();return(0,$.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 rounded-md border border-border p-3`,"data-testid":`identity-import-options`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ui,{className:`h-4 w-4 text-muted-foreground`}),(0,$.jsx)(z,{className:`text-xs font-medium`,children:n(`console.identityImport.policyTitle`,`Sign-in setup for imported users`)})]}),(0,$.jsxs)(De,{value:e,onValueChange:e=>t(e),children:[(0,$.jsx)(B,{className:`h-8 w-full sm:w-80`,"data-testid":`identity-import-policy`,children:(0,$.jsx)(He,{})}),(0,$.jsx)(Ie,{children:Object.keys(x_).map(e=>(0,$.jsx)(Wt,{value:e,children:n(`console.identityImport.policy.${e}`,x_[e].label)},e))})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`console.identityImport.policyHint.${e}`,x_[e].hint)})]})}function C_({serverResult:e}){let t=Zn(),n=(0,Q.useMemo)(()=>y_(e),[e]);return n.length===0?null:(0,$.jsxs)(`div`,{className:`mt-2 flex w-full flex-col gap-2 rounded-md border border-amber-500/50 bg-amber-500/5 p-3`,"data-testid":`identity-import-passwords`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-amber-700 dark:text-amber-400`,children:[(0,$.jsx)(Yi,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`p`,{className:`text-xs font-medium`,children:t(`console.identityImport.passwordsNote`,`Temporary passwords — shown once, never stored. Save them now; each user must change theirs at first sign-in.`)})]}),(0,$.jsxs)(`div`,{className:`max-h-40 overflow-auto rounded border bg-background p-2 font-mono text-xs`,children:[n.slice(0,50).map(e=>(0,$.jsxs)(`p`,{"data-testid":`identity-import-password-row-${e.row}`,children:[e.identity,`: `,e.temporaryPassword]},e.row)),n.length>50&&(0,$.jsx)(`p`,{className:`text-muted-foreground`,children:t(`console.identityImport.passwordsMore`,`More entries omitted — use the download.`)})]}),(0,$.jsx)(`div`,{children:(0,$.jsxs)(q,{variant:`outline`,size:`sm`,onClick:()=>{let e=b_(n),t=new Blob([e],{type:`text/csv;charset=utf-8`}),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=`temporary-passwords.csv`,i.click(),URL.revokeObjectURL(r)},"data-testid":`identity-import-passwords-download`,children:[(0,$.jsx)(Kr,{className:`mr-1 h-4 w-4`}),t(`console.identityImport.passwordsDownload`,`Download CSV`),` (`,n.length,`)`]})})]})}function w_(e){let t=(t,n)=>e?.[t]?.label||n;return[{name:`email`,label:t(`email`,`Email`),type:`text`},{name:`phone_number`,label:t(`phone_number`,`Phone Number`),type:`text`},{name:`name`,label:t(`name`,`Name`),type:`text`},{name:`role`,label:t(`role`,`Platform Role`),type:`text`}]}var T_=new Set([`formula`,`summary`]);function E_(e,t,n){let r=[];for(let[i,a]of Object.entries(t||{})){let t=T_.has(a?.type),o=!t&&a?.type!==`autonumber`&&!a?.readonly&&(!n?.isLoaded||n.checkField(e,i,`write`)),s=!o&&!t&&(!n?.isLoaded||n.checkField(e,i,`read`));(o||s)&&r.push({name:i,label:a?.label||i,type:a?.type||`text`,required:o&&!!a?.required,...s?{matchOnly:!0}:{},...a?.options?{options:a.options}:{}})}return r}function D_(e,t,n,r){switch(e){case`engine-owned`:return An({managedBy:e,userActions:r}).create?void 0:{icon:`Lock`,title:t(`list.managedBy.system.title`,{defaultValue:`Nothing here yet`}),message:t(`list.managedBy.system.message`,{defaultValue:`Entries appear automatically when their source action runs (e.g. Submit for Approval, Share, Invite). Trigger one of those on a source record to create a row.`})};case`append-only`:return{icon:`Archive`,title:t(`list.managedBy.appendOnly.title`,{defaultValue:`No events recorded`}),message:t(`list.managedBy.appendOnly.message`,{defaultValue:`This is an immutable audit log. Rows are written by the platform when events occur — you can export the history but cannot create entries from here.`})};case`better-auth`:return n===`sys_user`?{icon:`ShieldAlert`,title:t(`list.managedBy.betterAuthUser.title`,{defaultValue:`No users yet`}),message:t(`list.managedBy.betterAuthUser.message`,{defaultValue:`User accounts are provisioned by the authentication provider, not created here. Invite teammates to your organization and they appear automatically on first sign-in (SSO just-in-time provisioning). App end-users arrive when they sign up through your app.`})}:n===`sys_team`?{icon:`Users`,title:t(`list.managedBy.betterAuthTeam.title`,{defaultValue:`No teams yet`}),message:t(`list.managedBy.betterAuthTeam.message`,{defaultValue:`Teams group members within an organization. Create one with “Create Team”, or they arrive through your auth provider’s organization and SSO provisioning flows.`})}:{icon:`ShieldAlert`,title:t(`list.managedBy.betterAuth.title`,{defaultValue:`No identity records`}),message:t(`list.managedBy.betterAuth.message`,{defaultValue:`These records are created by the authentication provider — through sign-in, provisioning, and security flows — not added by hand here.`})};default:return}}function O_(e,t){if(!t||typeof t!=`object`)return;let n=t.name;return typeof n==`string`&&n.startsWith(`${e}.`)?n:I(e,{list:t})[0]?.name}function k_(e){if(!e||typeof e!=`object`)return;let t=e.name;return typeof t==`string`&&t!==``?t:void 0}function A_(e,t){return e.some(e=>k_(e)===t)}function j_(e,...t){let n={};for(let e of t)e&&typeof e==`object`&&Object.assign(n,e);return n.id=e,n}var M_=new Set;function N_(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.element===`tabs`||t.tabs!=null}function P_(e,t,n,r){let i=[];if((n?.quickFilters??r?.quickFilters)!=null&&i.push(`quickFilters`),N_(n?.userFilters??r?.userFilters)&&i.push(`userFilters (element: "tabs")`),i.length===0)return!1;let a=`${e}.${t}`;return M_.has(a)||(M_.add(a),console.warn(`[ObjectView] View "${t}" on object "${e}" defines ${i.join(` and `)}, which are ignored on an object list view (ADR-0047 "views" mode — the view switcher owns the tab bar here). Use \`listViews\` for named presets, \`element: "dropdown"\` for value chips, or move them to a page list (InterfaceListPage "filters" mode).`)),!0}var F_=`create_environment`;function I_(e,t){return mo(n=>n===F_&&e&&t!=null)!==null}function L_(e){return e.filter(e=>e?.name!==F_)}function R_({actions:e}){return e.length===0?null:(0,$.jsx)(Dn,{schema:{type:`action:bar`,location:`list_toolbar`,actions:e,size:`sm`,variant:`outline`}})}function z_({actions:e,entitlements:t,onUpgrade:n}){let{t:r}=J(),i=an(),a=(e||[]).filter(e=>on(e,`list_toolbar`)&&i(e?.requiredPermissions)),o=a.some(e=>e?.name===F_),s=t?.ready?Bo(t):null,c=I_(o,s);if((0,Q.useEffect)(()=>{c&&s===`upgrade_for_development`&&t&&n(zo(t,r))},[c,s]),a.length===0)return null;if(t===null){let e=L_(a);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R_,{actions:e}),o&&(0,$.jsx)(_t,{className:`h-9 w-44 rounded-md`,"data-testid":`environment-create-cta-loading`})]})}if(s===`upgrade_for_development`)return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R_,{actions:L_(a)}),o&&(0,$.jsxs)(q,{size:`sm`,onClick:()=>n(zo(t,r)),className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,"data-testid":`environment-add-upgrade`,children:[(0,$.jsx)(Ri,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:r(`environment.addEnvironment`)})]})]});let l={type:`action:bar`,location:`list_toolbar`,actions:a.map(e=>e?.name!==F_||s==null?e:s===`setup_production`?{...e,label:r(`environment.setUpProduction`),variant:`primary`,...c?{autoTrigger:!0}:{}}:{...e,label:r(`environment.addDevelopment`),...c?{autoTrigger:!0}:{}}),size:`sm`,variant:`outline`};return(0,$.jsx)(Dn,{schema:l})}le();var B_=(0,Q.lazy)(()=>o(()=>import(`./plugin-charts-b-yVtmdI.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),V_=(0,Q.lazy)(()=>o(()=>import(`./plugin-grid-Cp4RKtMJ.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),H_={grid:sa,kanban:na,calendar:Tr,gallery:mi,timeline:mr,gantt:Dr,map:xi,chart:Er},U_={id:`current-user`,name:`Demo User`};function W_(e,t){return cn(e,t)}function G_(e){let t=e?.timeline?.startDateField||e?.timeline?.dateField;return{...e?.timeline||{},...t?{startDateField:t}:{},titleField:e?.timeline?.titleField||`name`,descriptionField:e?.timeline?.descriptionField}}function K_(e){let t=e?.calendar;if(t&&typeof t==`object`)return{...t}}function q_(e){return{...e?.gantt||{},titleField:e?.gantt?.titleField||`name`}}function J_(e){let t=e?.gallery,n=t?.imageField||t?.coverField,r=t?.coverField||t?.imageField;return{...t||{},...n?{imageField:n}:{},...r?{coverField:r}:{},titleField:e?.gallery?.titleField||`name`}}function Y_(e,t){let n=e?.kanban?.groupByField||e?.kanban?.groupField||Xt(t)||void 0;return{...n?{groupByField:n}:{},titleField:e?.kanban?.titleField||`name`,cardFields:e?.kanban?.columns}}function X_(e){let t=e&&typeof e==`object`?e.options:void 0;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function Z_(e,t,n=0){if(Object.is(e,t))return!0;if(n>=12)return!1;if(e instanceof Date||t instanceof Date)return e instanceof Date&&t instanceof Date&&e.getTime()===t.getTime();if(Array.isArray(e)||Array.isArray(t))return!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length?!1:e.every((e,r)=>Z_(e,t[r],n+1));let r=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null};if(r(e)&&r(t)){let r=Object.keys(e);return r.length===Object.keys(t).length&&r.every(r=>Object.prototype.hasOwnProperty.call(t,r)&&Z_(e[r],t[r],n+1))}return!1}function Q_(e,t){return`${e.replace(/\/view\/.*$/,``)}/record/${encodeURIComponent(String(t))}`}var $_=Object.freeze({});function ev(e,t,n=()=>window.location.pathname){let r=(t,n)=>t===e&&n!=null&&n!==``;return{resolve:()=>$_,recordHref:(e,t)=>r(e,t)?Q_(n(),t):null,openRecord:(e,n)=>{r(e,n)&&t(n)}}}function tv(e,t=5,n){let r=t=>n?.orgAttribution&&e?.fields?.organization_id&&!t.includes(`organization_id`)?[...t,`organization_id`]:t,i=e?.highlightFields;if(Array.isArray(i)&&i.length>0)return r(Qt(e,i.filter(t=>e?.fields?.[t])));let a=e?.fields;return a&&typeof a==`object`?r(Qt(e,Object.entries(a).filter(([e,t])=>t&&!t.hidden&&!Kt(e,t)).map(([e])=>e)).slice(0,t)):[]}function nv(e,t){return hl(e,{fallbackColumns:tv(t,5)})}function rv(e){if(!e||typeof e!=`object`)return e;let t=cr(e);if(t!==e)return t;if(!Array.isArray(e.filter))return e;let n=e=>nl.has(re(String(e))),r=e.filter.filter(e=>{if(Array.isArray(e)){if(e.length<2)return!1;let[,t,r]=e;return n(t)?!0:Oe(String(t),r)}if(!e||typeof e!=`object`||typeof e.field!=`string`||e.field===``)return!1;if(n(e.operator))return!0;let t=e.value;return Oe(String(e.operator),t)});if(r.length===0){let{filter:t,...n}=e;return n}return r.length===e.filter.length?e:{...e,filter:r}}async function iv(e,t,n){if(typeof e?.listViewOverrides==`function`)try{let r=await e.listViewOverrides(t);if(r&&typeof r==`object`){let e={};for(let t of n)r[t]&&(e[t]=rv(r[t]));return e}}catch{}if(typeof e?.getView!=`function`)return{};let r=await Promise.all(n.map(async n=>{try{return[n,await e.getView(t,n)]}catch{return[n,null]}})),i={};for(let[e,t]of r)t&&typeof t==`object`&&(i[e]=rv(t));return i}function av(e,t,n,r){let i=e.label||e.name||e.id;return Rf(n,t,e.id)?i:r(t,e.name||e.id,i)}function ov(e,t,n,r){let i=e.label??``;return Rf(n,t,e.id)?i:r(t,e.name??``,i)}function sv({definedViews:e,primary:t,primaryId:n,savedViews:r,viewOverrides:i,fallbackTab:a}){let o=Object.entries(e||{}).map(([e,t])=>{let n=i[e];return j_(e,t,n,{type:n?.type||t?.type||`grid`})});if(n){let e=o.findIndex(e=>e.id===n);if(e>=0){let[t]=o.splice(e,1);o.unshift(j_(n,t,{isDefault:!0}))}else{let e=i[n];o.unshift(j_(n,t,e,{type:e?.type||t?.type||`grid`,isDefault:!0}))}}o.length===0&&o.push(a());let s=new Set(o.map(e=>e.id));for(let e of r){let t=k_(e);if(!t)continue;let n={label:e.label||e.name||t,type:e.type||`grid`,columns:e.columns,filter:e.filter,sort:e.sort,isPinned:e.isPinned,isDefault:e.isDefault,visibility:e.visibility,sortOrder:e.sortOrder,...e,id:t},r={};for(let[e,t]of Object.entries(n))t!==void 0&&(r[e]=t);if(s.has(t)){let e=o.findIndex(e=>e.id===t);o[e]=j_(t,o[e],r)}else o.push(j_(t,r))}return o}function cv(e,t){let n=e.filter(e=>k_(e)!==t&&e.isDefault).map(e=>({viewId:k_(e),patch:{isDefault:!1}}));return n.push({viewId:t,patch:{isDefault:!0}}),n}function lv(e,t){let n=new Set(e.map(e=>k_(e)));return t.filter(e=>n.has(e)).map((e,t)=>({viewId:e,patch:{sortOrder:t}}))}function uv(e,t,n){return n.map(({viewId:n,patch:r})=>e.updateView(t,n,r))}function dv(e,t,n){if(n.isSavedView)return{...e||{},...t};let r=e?.viewKind;return r===void 0?{...t}:{...t,viewKind:r}}var fv=Object.keys(ne).filter(e=>ne[e].includes(`viewItem`)),pv;function mv(){return pv??=new Set(Object.keys(F.shape)),pv}function hv(e,t){let n=String(t?.id??``),r=mv(),i={};for(let[e,n]of Object.entries(t??{}))n!==void 0&&r.has(e)&&(i[e]=n);let a={};for(let e of fv)t?.[e]!==void 0&&(a[e]=t[e]);let o=typeof t?.label==`string`?t.label:void 0;return{...Nl(e,i,{name:n,label:o}),...a,name:n}}function gv(e){let t=new URLSearchParams;return e.forEach((e,n)=>{n.startsWith(`filter[`)&&t.append(n,e)}),t}function _v({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let{objectName:i}=f(),{t:a}=J();return t.find(e=>e.name===i)?(0,$.jsx)(vv,{dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}):(0,$.jsx)(`div`,{className:`h-full p-4 flex items-center justify-center`,children:(0,$.jsxs)(ve,{children:[(0,$.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,$.jsx)(sa,{className:`h-6 w-6 text-muted-foreground`})}),(0,$.jsx)(pe,{children:a(`console.objectView.objectNotFound`)}),(0,$.jsxs)(ge,{children:[a(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,a(`console.objectView.objectNotFoundHint`)]})]})})}function vv({dataSource:e,objects:t,onEdit:n,externalRefreshKey:i}){let a=r(),{appName:o,objectName:s,viewId:c}=f(),[u,d]=l(),p=g(),{showDebug:m}=wl(),{t:h}=J(),{objectLabel:_,objectDescription:v,viewLabel:y,viewEmptyState:b,actionParamText:x,fieldLabel:C,fieldOptionLabel:w}=Xn(),T=If(),E=Gt(),{isFavorite:D,toggleFavorite:O}=is(),k=Vc()===`group`,j=Da(),M=Oa(),[N,ee]=(0,Q.useState)(!1),[P,F]=(0,Q.useState)(`edit`),[te,I]=(0,Q.useState)(!1),[ne,re]=(0,Q.useState)(!1),[L,ie]=(0,Q.useState)(null),ae=(0,Q.useRef)({}),oe=(0,Q.useRef)({}),R=(0,Q.useRef)([]),se=(0,Q.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!s||!t)return;let i=oe.current[t]||{};oe.current[t]={...i,...r};let a=ae.current[t];a&&clearTimeout(a),ae.current[t]=setTimeout(()=>{let r=oe.current[t]||{};delete oe.current[t],delete ae.current[t];let i=A_(R.current,t);Promise.resolve(e.updateViewConfig?.(s,t,dv(n,r,{isSavedView:i}),{isSavedView:i})).catch(e=>{if(ur(e)){Y.error(h(`console.objectView.viewConfigPermissionDenied`));return}console.error(`[ObjectView] Failed to persist view config:`,e),Y.error(h(`form.saveError`),{description:or(e),classNames:{description:`whitespace-pre-line`}})})},300)},[e,s]),le=(0,Q.useCallback)(async t=>{ie(t),H(e=>e+1);let n=t.id;if(!j||!n)return console.warn(`[ViewConfigPanel] Cannot persist view config: missing metadataClient or viewId.`),!1;try{return await Pl(`view`,n,hv(s,t),{metadataClient:j,dataSource:e,objectName:s}),!0}catch(e){return console.error(`[ViewConfigPanel] Failed to persist view config:`,e),Y.error(h(`form.saveError`),{description:or(e),classNames:{description:`whitespace-pre-line`}}),!1}},[j,e,s,h]),z=(0,Q.useCallback)(async n=>{try{let r;if(j){let i=t?.find?.(e=>e.name===s),a=nv(n,i),o=Nl(s,a,{name:n?.name,label:n.label});r=await Fl(`view`,o.name,o,{metadataClient:j,dataSource:e,objectName:s})}if(ee(!1),F(`edit`),H(e=>e+1),r){let e=M?``:`?${Ta}=${Aa}`;c?a(`../${r}${e}`,{relative:`path`}):a(`view/${r}${e}`)}return!0}catch(e){return console.error(`[ViewConfigPanel] Failed to create view:`,e),Y.error(h(`form.saveError`),{description:or(e),classNames:{description:`whitespace-pre-line`}}),!1}},[e,s,t,a,c,j,M,h]),[ue,de]=(0,Q.useState)(void 0),{user:fe,activeOrganization:pe}=A(),{isAdmin:B}=S(),me=at(),{can:he,getObjectApiOperations:ge}=me,{systemPermissions:_e}=me;(0,Q.useEffect)(()=>{e?.setSystemCapabilities?.(_e)},[e,_e]);let V=t.find(e=>e.name===s),[ve,H]=(0,Q.useState)(0),U=ve+(typeof i==`number`?i:0),ye=(0,Q.useCallback)(()=>{H(e=>e+1),V.name&&On({objectName:V.name})},[V.name]),be=Ho({dataSource:e,objects:t,objectName:V.name,onRefresh:ye}),{confirmHandler:xe,toastHandler:W}=be,Se=V.name===`sys_environment`,Ce=po({enabled:Se,dataSource:e,authFetch:be.authFetch,apiBase:``,refreshKey:U}),we=(0,Q.useMemo)(()=>(V.actions||[]).map(e=>E(V.name,e)),[V,E]),Te=Co(we,e=>on(e,`list_toolbar`),!Se),Ee={type:`action:bar`,location:`list_toolbar`,actions:(0,Q.useMemo)(()=>Te===null?we:we.map(e=>e?.name===Te?{...e,autoTrigger:!0}:e),[we,Te]),size:`sm`,variant:`outline`,mobileMaxVisible:0},De=(0,Q.useMemo)(()=>An(V,ge(V.name)),[V,ge]),Oe=De.create&&he(V.name,`create`),ke=Oe?De.createPredicates:void 0,Ae=$t(ke?.visibleWhen??!0,null,{fallback:!1,warnOnError:!0,label:`builtin:create:visibleWhen`}),je=$t(ke?.disabledWhen,null,{fallback:!1,warnOnError:!0,label:`builtin:create:disabledWhen`}),Me=ke?.disabledWhen!=null&&je,Ne=De.import&&he(V.name,`create`),G=Ne?De.importPredicates:void 0,Pe=$t(G?.visibleWhen??!0,null,{fallback:!1,warnOnError:!0,label:`builtin:import:visibleWhen`}),Fe=$t(G?.disabledWhen,null,{fallback:!1,warnOnError:!0,label:`builtin:import:disabledWhen`}),Ie=G?.disabledWhen!=null&&Fe,[Le,Re]=(0,Q.useState)(!1),{features:ze}=Ua(),Be=V.name===`sys_user`&&ze?.admin===!0&&B,[Ve,He]=(0,Q.useState)(`auto`),Ue=(0,Q.useRef)(`auto`);Ue.current=Ve;let We=(0,Q.useMemo)(()=>Be?v_({base:e,authFetch:be.authFetch,baseUrl:``,getPasswordPolicy:()=>Ue.current}):void 0,[Be,e,be.authFetch]),[K,Ge]=(0,Q.useState)([]);R.current=K,(0,Q.useEffect)(()=>{let t=!1;if(!s){Ge([]);return}return typeof e?.listViews==`function`?(e.listViews(s,{previewDrafts:M}).then(e=>{if(t)return;let n=(e||[]).map(e=>({...e,id:k_(e)}));Ge(n)}).catch(e=>{console.error(`[ObjectView] Failed to load overlay views:`,e),t||Ge([])}),()=>{t=!0}):(Ge([]),()=>{t=!0})},[e,s,U,M]);let[Ke,qe]=(0,Q.useState)({});(0,Q.useEffect)(()=>{let t=!1;if(!e||!s){qe({});return}let n=V.listViews||V.list_views||{},r=Object.keys(n),i=O_(V.name,V.list);if(i&&!r.includes(i)&&r.unshift(i),r.length===0){qe({});return}return iv(e,s,r).then(e=>{t||qe(e)}),()=>{t=!0}},[e,s,V.listViews,V.list_views,V.list,U]);let{list:Je,derivedColumnViewIds:Ye}=(0,Q.useMemo)(()=>{let e=()=>tv(V,5,{orgAttribution:k}),t=sv({definedViews:V.listViews||V.list_views||{},primary:V.list,primaryId:O_(V.name,V.list),savedViews:K,viewOverrides:Ke,fallbackTab:()=>({id:`all`,label:h(`console.objectView.allRecords`),type:`grid`})}),n=new Set([`grid`,`list`,`table`]),r=new Set;for(let i of t)n.has(i.type)&&(!Array.isArray(i.columns)||i.columns.length===0)&&(i.columns=e(),r.add(i.id));let i=new Map(t.map((e,t)=>[e.id,t])),a=[];try{let e=typeof window<`u`?window.localStorage?.getItem(`viewOrder:${V.name}`):null;e&&(a=JSON.parse(e))}catch{}let o=new Map(a.map((e,t)=>[e,t]));return t.sort((e,t)=>{let n=o.get(e.id),r=o.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 a=K.find(t=>k_(t)===e.id),s=K.find(e=>k_(e)===t.id),c=a&&typeof a.sortOrder==`number`,l=s&&typeof s.sortOrder==`number`;return c&&l?a.sortOrder===s.sortOrder?(a.created_at||``).localeCompare(s.created_at||``):a.sortOrder-s.sortOrder:c?-1:l?1:(i.get(e.id)??0)-(i.get(t.id)??0)}),{list:t,derivedColumnViewIds:r}},[V,K,Ke,h,k]),Xe=(0,Q.useMemo)(()=>Je.find(e=>e.isDefault)?.id,[Je]),Ze=c||u.get(`view`)||void 0,$e=(0,Q.useMemo)(()=>Ln(Ze,Je.map(e=>e.id),V.name),[Ze,Je,V.name]);(0,Q.useEffect)(()=>{Ze&&!$e&&console.warn(`[ObjectView] Requested view "${Ze}" not found on object "${V.name}"; falling back to the default view. Known views: ${Je.map(e=>e.id).join(`, `)}`)},[Ze,$e,V.name,Je]);let et=$e||Xe||Je[0]?.id,tt=Je.find(e=>e.id===et)||Je[0],nt=L&&L.id===tt?.id?{...tt,...L}:tt,rt=!!tt&&!Ye.has(tt.id)&&Array.isArray(tt.columns)&&tt.columns.length>0,it=L&&L.id===tt?.id&&`columns`in L&&!Z_(L.columns,tt?.columns)?Array.isArray(L.columns)&&L.columns.length>0:rt,ot=(0,Q.useCallback)((e,t)=>{ie(n=>({...n||{},id:tt?.id,[e]:t}))},[tt?.id]),st=e=>{let t=Je.find(t=>t.id===e);t&&(t.id!==et&&ee(!1),c?a(`../${t.id}`,{relative:`path`}):a(`view/${t.id}`))},ct=(0,Q.useMemo)(()=>(Je||[]).map(e=>{let t=H_[e.type];return{id:e.id,label:av(e,V.name,T,y),icon:t?(0,$.jsx)(t,{className:`h-4 w-4`}):void 0}}),[Je,V.name,y,T]);Of({views:ct,activeViewId:et??``,onChange:st,enabled:ct.length>0&&!!et});let lt=(0,Q.useCallback)(()=>{I(!0)},[]),ut=(0,Q.useCallback)((e,t)=>{if(e===`settings`){let e=Je.find(e=>e.type===t);e&&st(e.id),F(`edit`),ee(!0)}},[Je,st]),dt=(0,Q.useCallback)(e=>A_(K,e),[K]),ft=(0,Q.useCallback)(async(t,n)=>{if(!dt(t)){Y.error(h(`console.objectView.cannotEditMetaView`));return}try{typeof e?.updateView==`function`&&await e.updateView(s,t,{label:n}),H(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),Y.error(h(`objectViewActions.renameFailed`))}},[e,s,dt,h]),pt=(0,Q.useCallback)(async t=>{if(!e)return;if(!dt(t)){Y.error(h(`console.objectView.cannotDeleteMetaView`));return}let n=Je.find(e=>e.id===t)?.label||t;if(await xe(h(`console.objectView.deleteViewConfirm`,{name:n}),{title:h(`console.objectView.deleteViewTitle`),confirmText:h(`console.objectView.delete`),cancelText:h(`console.objectView.cancel`)}))try{if(typeof e?.deleteView==`function`&&await e.deleteView(s,t),t===et){let e=Je.find(e=>e.id!==t);e&&a(c?`../${e.id}`:`view/${e.id}`,c?{relative:`path`}:void 0)}H(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),Y.error(h(`objectViewActions.deleteFailed`))}},[e,dt,et,Je,c,a,h,xe]),mt=(0,Q.useCallback)(async(t,n)=>{if(e){if(!dt(t)){Y.error(h(`console.objectView.cannotEditMetaView`));return}try{typeof e?.updateView==`function`&&await e.updateView(s,t,{isPinned:n}),H(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e),Y.error(h(`form.saveError`),{description:or(e),classNames:{description:`whitespace-pre-line`}})}}},[e,s,dt,h]),ht=(0,Q.useCallback)(async t=>{if(e&&s){if(!dt(t)){Y.error(h(`console.objectView.cannotEditMetaView`));return}try{if(typeof e?.updateView!=`function`)return;await Promise.all(uv(e,s,cv(K,t))),H(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),Y.error(h(`form.saveError`),{description:or(e),classNames:{description:`whitespace-pre-line`}})}}},[e,s,K,dt,h]),gt=(0,Q.useCallback)(async t=>{try{typeof window<`u`&&window.localStorage?.setItem(`viewOrder:${s}`,JSON.stringify(t))}catch{}if(s&&typeof e?.updateView==`function`){let n=uv(e,s,lv(K,t));try{await Promise.all(n)}catch(e){console.error(`[ViewTabBar] Failed to reorder views:`,e),Y.error(h(`form.saveError`),{description:or(e),classNames:{description:`whitespace-pre-line`}})}}H(e=>e+1)},[e,K,s,h]),_t=(0,Q.useCallback)(e=>{if(!dt(e)){Y.error(h(`console.objectView.cannotEditMetaView`));return}e!==et&&st(e),F(`edit`),ee(!0)},[et,st,dt,h]),vt=(0,Q.useCallback)(()=>{I(!0)},[]),yt=fe?{id:fe.id,name:fe.name,avatar:fe.image}:U_,bt=(0,Q.useMemo)(()=>({currentUserId:yt.id,currentOrgId:pe?.id??null}),[yt.id,pe?.id]),xt=Ju({objectName:V.name,objectLabel:V.label,dataSource:e,onEdit:n,onRefresh:ye,onConfirm:xe,onToast:W}),{lastMessage:St}=rs({channel:`object:${V.name}`}),Ct=V.name?`user-${V.name}`:`current-user`,{hasConflicts:wt,resolveAllConflicts:Tt}=Uo(Ct);(0,Q.useEffect)(()=>{St&&(wt&&Tt(`remote`),ye())},[St,wt,Tt,ye]),(0,Q.useEffect)(()=>{e?.find&&V.name&&e.find(V.name,{$top:0}).then(e=>{typeof e?.total==`number`&&de(e.total)}).catch(()=>{})},[e,V.name,U]);let Et=(0,Q.useMemo)(()=>{let e=nt?.navigation??V.navigation;return e?e.mode===`page`?e:{...e,width:e.width??xl(e.size,V)}:ce(V)===`page`?{mode:`page`}:{mode:`drawer`,width:xl(`auto`,V)}},[nt?.navigation,V]),Dt=u.get(Go),Ot=gv(u),kt=Ot.toString(),At=(0,Q.useMemo)(()=>vl(Ot),[kt]),[jt]=(0,Q.useState)(()=>Uc(new URLSearchParams(window.location.search))),Mt=(0,Q.useCallback)(e=>{d(t=>Hc(t,e),{replace:!0})},[d]),Nt=(0,Q.useCallback)((e,t)=>{if(t===`new_window`){window.open(Q_(window.location.pathname,e),`_blank`);return}let n={from:{pathname:p.pathname+(p.search||``),label:ov({id:nt?.id,name:nt?.name,label:nt?.label},V.name,T,y)||_(V)}};c?a(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):a(`record/${encodeURIComponent(String(e))}`,{state:n})},[a,c,p.pathname,p.search,V,nt?.id,nt?.name,nt?.label,y,_,T]),Pt=(0,Q.useMemo)(()=>ev(V.name,Nt),[V.name,Nt]),Ft=In({navigation:Et,objectName:V.name,onNavigate:Nt}),It=()=>{Ft.close();let e=new URLSearchParams(u);e.delete(Go),d(e)},Lt=(0,Q.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){Ft.handleClick(e,t);return}if(Ft.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(u);e.set(Go,String(t)),d(e);return}}Ft.handleClick(e,t)},[Ft,u,d]),Rt=(0,Q.useCallback)(()=>{let e=Ft.selectedRecord,t=e&&(e.id??e._id);t!=null&&(It(),Nt(t))},[Ft.selectedRecord,Nt]);(0,Q.useEffect)(()=>{Dt&&!Ft.isOpen?Ft.open({id:Dt}):!Dt&&Ft.isOpen&&Ft.close()},[Dt]);let zt=(0,Q.useRef)(void 0),Bt=(0,Q.useRef)(void 0),Vt=(0,Q.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=U+(i||0),o=`${s}-${nt.id}`,c=nt,l=e_(fe?.id,s,nt.id),u=r_(l);if(c.type===`chart`){let e=c.chart||{};if(e.dataset){let n=Array.isArray(e.dimensions)?e.dimensions:[],r=Array.isArray(e.values)?e.values:[];return(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,$.jsx)(B_,{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})),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,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,$.jsx)(B_,{dataSource:t,schema:{type:`object-chart`,objectName:V.name,chartType:e.chartType||`bar`,aggregate:{field:r,function:i,groupBy:n},xAxisKey:n,series:a,filter:e.filter,className:`h-[400px] w-full`}})},o)}P_(V.name,c.id||c.name||``,c,e);let d=K_(c),f=X_(c),p=e=>{(it||A_(R.current,c.id))&&se(c.id,c,{hiddenFields:e})},m={...e,refreshTrigger:a,label:c.label??e.label,description:c.description??e.description,rowHeight:dn(c??{}).rowHeight??e.rowHeight,sort:c.sort??e.sort,filter:(()=>{let t=c.filter??e.filter,n=Array.isArray(t)?t:t?[t]:[],r=W_(At.length?[...n,...At]:t,bt);return Z_(Bt.current,r)?Bt.current:(Bt.current=r,r)})(),hiddenFields:it?c.hiddenFields??e.hiddenFields:void 0,fieldOrder:it?c.fieldOrder??e.fieldOrder:void 0,columnState:c.columnState??e.columnState,onDensityChange:e=>{se(c.id,c,{rowHeight:ln[e]})},onSortChange:e=>{se(c.id,c,{sort:e})},onHiddenFieldsChange:p,onColumnStateChange:e=>{se(c.id,c,{columnState:e})},inlineEdit:c.inlineEdit??e.inlineEdit,appearance:c.appearance?c.showDescription==null?c.appearance:{...c.appearance,showDescription:c.showDescription}:c.showDescription==null?e.appearance:{showDescription:c.showDescription},showViewSwitcher:((c.appearance??e.appearance)?.allowedVisualizations?.length??0)>1,userActions:{...dn(e??{}).userActions,...dn(c??{}).userActions},exportOptions:c.exportOptions??e.exportOptions,color:c.color??e.color,rowColor:c.rowColor??e.rowColor,data:c.data??e.data,navigation:c.navigation??e.navigation,selection:c.selection??e.selection,pagination:c.pagination??e.pagination,searchableFields:c.searchableFields??e.searchableFields,filterableFields:c.filterableFields??e.filterableFields,resizable:c.resizable??e.resizable,rowActions:c.rowActions??e.rowActions,rowActionDefs:Array.isArray(V?.actions)?V.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)).map(e=>E(V.name,e)):[],bulkActions:c.bulkActions??e.bulkActions,bulkActionDefs:c.bulkActionDefs??e.bulkActionDefs,sharing:c.sharing??e.sharing,addRecord:c.addRecord??e.addRecord,conditionalFormatting:c.conditionalFormatting??e.conditionalFormatting,quickFilters:void 0,userFilters:(()=>{let t=c.userFilters??e.userFilters;return t&&t.element!==`tabs`&&t.tabs==null?t:void 0})(),showRecordCount:c.showRecordCount??e.showRecordCount,allowPrinting:c.allowPrinting??e.allowPrinting,emptyState:b(V.name,c.name||c.id||``,c.emptyState??e.emptyState??D_(V?.managedBy,h,V.name,V?.userActions)),aria:c.aria??e.aria,...c.sort?.length?{sort:c.sort}:{},...f.kanban===void 0?{}:{kanban:c.kanban},...f.calendar===void 0?{}:{calendar:c.calendar},...f.timeline===void 0?{}:{timeline:c.timeline},...f.map===void 0?{}:{map:c.map},...f.gallery===void 0?{}:{gallery:c.gallery},...f.gantt===void 0?{}:{gantt:c.gantt},...f.tree===void 0?{}:{tree:c.tree},...f.chart===void 0?{}:{chart:c.chart},options:{...f,kanban:f.kanban??Y_(c,V),...f.calendar??d?{calendar:f.calendar??d}:{},timeline:f.timeline??G_(c),map:f.map??{locationField:c.map?.locationField,titleField:c.map?.titleField||`name`,latitudeField:c.map?.latitudeField,longitudeField:c.map?.longitudeField,zoom:c.map?.zoom,center:c.map?.center},gallery:f.gallery??J_(c),gantt:f.gantt??q_(c),tree:f.tree??{...c.tree||{},labelField:c.tree?.labelField||c.tree?.titleField||`name`},chart:f.chart??c.chart}};return Z_(zt.current,m.options)?m.options=zt.current:zt.current=m.options,(0,$.jsx)(yl,{schema:m,className:r,onEdit:n,onDelete:e=>{e?.id!=null&&xt.deleteRecord(String(e.id),e)},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&xt.execute({type:`delete`,confirmText:h(`console.objectView.bulkDeleteConfirm`,{count:t.length,defaultValue:`Delete ${t.length} selected records? This cannot be undone.`}),params:{records:t}})},onRowClick:(e,t)=>{Lt(e,t)},onSortChange:e=>{se(c.id,c,{sort:e})},onFilterChange:e=>{o_(l,{filters:e})},onSearchChange:e=>{o_(l,{search:e})},onHiddenFieldsChange:p,onInlineEditChange:e=>{se(c.id,c,{inlineEdit:e})},onColumnStateChange:e=>{se(c.id,c,{columnState:e})},userFilterSelections:jt,onUserFilterSelectionsChange:Mt,initialFilters:u?.filters,initialSearchTerm:u?.search,dataSource:t},o)},[nt,it,V,s,U,Ft,xt,se,At,jt,Mt,fe?.id]),Ht=(0,Q.useMemo)(()=>Je.map(e=>e.id===et&&L&&L.id===e.id?{...e,...L}:e),[Je,et,L]),Ut=dn(nt??{}).userActions,Wt=Ut?.search!==!1,Kt=Ut?.filter!==!1,qt=Ut?.sort!==!1,Jt=(0,Q.useMemo)(()=>({type:`object-view`,objectName:V.name,layout:`page`,showSearch:Wt,showFilters:Kt,showSort:qt,showCreate:!1,allowCreateView:B,viewActions:B?[{type:`settings`},{type:`share`},{type:`delete`}]:[],onNavigate:(e,t)=>{if(t===`edit`)n?.({id:e});else if(t===`view`){let t={from:{pathname:p.pathname+(p.search||``),label:ov({id:nt?.id,name:nt?.name,label:nt?.label},V.name,T,y)||_(V)}};c?a(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):a(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[V,n,Wt,Kt,qt,nt?.id,nt?.name,nt?.label,a,c,B,p.pathname,p.search,y,_,T]);return(0,$.jsx)(Pn,{...be.actionProviderProps,children:(0,$.jsxs)(xn,{value:Pt,children:[(0,$.jsxs)(`div`,{className:`h-full flex flex-col bg-background min-w-0 overflow-hidden`,children:[(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(gl,{title:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:_(V)}),(0,$.jsx)(Ll,{managedBy:V?.managedBy})]}),subtitle:V.description?v(V):void 0,icon:(()=>{let e=Wc(V?.icon);return(0,$.jsx)(e,{className:`h-4 w-4`})})(),actions:(0,$.jsxs)($.Fragment,{children:[s&&(0,$.jsx)(q,{size:`sm`,variant:`ghost`,onClick:()=>O({id:`object:${s}`,label:_(V),href:`/apps/${o}/${s}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":D(`object:${s}`),"aria-label":D(`object:${s}`)?h(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):h(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${s}`,children:D(`object:${s}`)?(0,$.jsx)(ia,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,$.jsx)(ra,{className:`h-4 w-4`})}),Oe&&Ae&&(0,$.jsxs)(q,{size:`sm`,onClick:xt.create,disabled:Me,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,"data-testid":`object-view-new-button`,children:[(0,$.jsx)(Ri,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.new`)})]}),(Be||Ne&&Pe)&&(0,$.jsxs)(q,{size:`sm`,variant:`outline`,onClick:()=>Re(!0),disabled:Ie,className:`hidden sm:inline-flex shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,title:h(`console.objectView.importTitle`),"data-testid":`object-view-import-button`,children:[(0,$.jsx)(fa,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:h(`console.objectView.import`)})]}),V.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(Se?(0,$.jsx)(z_,{actions:we,entitlements:Ce,onUpgrade:be.openEntitlementDialog}):(0,$.jsx)(Dn,{schema:Ee}))]})})}),Oe&&Ae&&(0,$.jsx)(`button`,{type:`button`,onClick:xt.create,disabled:Me,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 disabled:opacity-50 disabled:pointer-events-none`,"aria-label":h(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,$.jsx)(Ri,{className:`h-5 w-5`})}),Le&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(V_,{open:Le,onOpenChange:Re,objectName:V.name,objectLabel:_(V),fields:Be?w_(V.fields):E_(V.name,V.fields,me),dataSource:We??e,...Be?{extraOptionsContent:(0,$.jsx)(S_,{policy:Ve,onPolicyChange:He}),renderResultExtra:e=>(0,$.jsx)(C_,{serverResult:e?.serverResult})}:{},onComplete:e=>{ye();let t=e.importedRows,n=e.skippedRows;n>0?Y.warning(h(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&Y.success(h(`console.objectView.importedToast`,{count:t}))}})}),Je.length>=1&&(()=>{let e=Je.map(e=>{let t=K.find(t=>k_(t)===e.id),n=!t;return{id:e.id,label:av(e,V.name,T,y),type:e.type,hasActiveFilters:Array.isArray(e.filter)&&e.filter.length>0,hasActiveSort:Array.isArray(e.sort)&&e.sort.length>0,isDefault:!!(t?.isDefault??e.isDefault),isPinned:!!(t?.isPinned??e.isPinned),visibility:t?.visibility??e.visibility,readonly:n,readonlyReason:n?h(`console.objectView.systemViewReadonly`):void 0}});return(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`hidden sm:block border-b px-3 sm:px-4 bg-background overflow-x-auto shrink-0`,children:[(0,$.jsx)(Sl,{views:e,activeViewId:et,onViewChange:st,viewTypeIcons:H_,config:{reorderable:!1,showAddButton:B,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:B?vt:void 0,onRenameView:B?ft:void 0,onDeleteView:B?pt:void 0,onPinView:B?mt:void 0,onSetDefaultView:B?ht:void 0,onConfigView:B?_t:void 0,onManageViews:B?()=>re(!0):void 0}),B&&(0,$.jsx)(bl,{open:ne,onOpenChange:re,views:e,activeViewId:et,viewTypeIcons:H_,onRename:ft,onDelete:pt,onSetDefault:ht,onSetPinned:mt,onReorder:gt,onAddView:vt,onConfigView:_t})]})})})(),(0,$.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[Ft.mode===`split`&&Ft.isOpen?(0,$.jsx)(Qe,{...Ft,setIsOpen:e=>{e||It()},title:_(V),onExpand:Rt,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${V.name}`,mainContent:(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:[(0,$.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,$.jsx)(Cl,{schema:Jt,dataSource:e,views:Ht,activeViewId:et,onViewChange:st,onEdit:e=>n?.(e),onRowClick:(e,t)=>{Lt(e,t)},renderListView:Vt,onCreateView:lt,hideNamedViewTabs:!0,onViewAction:ut})})}),typeof ue==`number`&&(0,$.jsx)(`div`,{"data-testid":`record-count-footer`,className:`border-t px-3 sm:px-4 py-1.5 text-xs text-muted-foreground bg-muted/5 shrink-0`,children:h(`console.objectView.recordCount`,{count:ue})})]}),children:r=>{let i=r.id||r._id;return(0,$.jsx)(ts,{dataSource:e,objects:t,onEdit:n,objectNameOverride:V.name,recordIdOverride:i,embedded:!0})}}):(0,$.jsx)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:(0,$.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,$.jsx)(Cl,{schema:Jt,dataSource:e,views:Ht,activeViewId:et,onViewChange:st,onEdit:e=>n?.(e),onRowClick:(e,t)=>{Lt(e,t)},renderListView:Vt,onCreateView:lt,hideNamedViewTabs:!0,onViewAction:ut})})})}),(0,$.jsx)(Tl,{open:m&&B,sections:[{title:`View Configuration`,data:nt},{title:`Object Definition`,data:V}]}),(0,$.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${N&&B?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,$.jsx)(p_,{open:N&&B,onClose:()=>{ee(!1),F(`edit`)},mode:P,activeView:nt,objectDef:V,recordCount:ue,onSave:le,onViewUpdate:ot,onCreate:z,metadataClient:j,dataSource:e,onAfterChange:()=>H(e=>e+1)})}),(0,$.jsx)(_l,{open:te&&B,onOpenChange:I,existingLabels:Je.map(e=>e.label).filter(Boolean),objectDef:V,onCreate:e=>z(e)})]}),Ft.mode!==`split`&&(0,$.jsx)(Qe,{...Ft,setIsOpen:e=>{e||It()},title:_(V),onExpand:Rt,expandLabel:h(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${V.name}`,children:r=>{let i=r.id||r._id;return(0,$.jsx)(ts,{dataSource:e,objects:t,onEdit:n,objectNameOverride:V.name,recordIdOverride:i,embedded:!0})}})]}),be.dialogs]})})}function yv({appName:e,error:t,onRetry:n}){let{t:r}=J(),i=!!t;return(0,$.jsx)(`div`,{className:`flex h-screen items-center justify-center`,"data-testid":`preview-draft-empty-state`,children:(0,$.jsxs)(ve,{children:[(0,$.jsx)(`div`,{className:`mb-2 flex justify-center text-muted-foreground`,"aria-hidden":`true`,children:i?(0,$.jsx)(ua,{className:`h-8 w-8`}):(0,$.jsx)(Xr,{className:`h-8 w-8`})}),(0,$.jsx)(pe,{children:i?r(`preview.empty.loadFailedTitle`,{defaultValue:`Draft preview failed to load`}):e?r(`preview.empty.notReadyTitle`,{app:e,defaultValue:`“{{app}}” isn’t in the draft yet`}):r(`preview.empty.nothingTitle`,{defaultValue:`Nothing to preview yet`})}),(0,$.jsx)(ge,{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,$.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,$.jsxs)(q,{variant:`outline`,onClick:n,"data-testid":`preview-draft-retry`,children:[(0,$.jsx)(zi,{className:`mr-1.5 h-3.5 w-3.5`}),r(`preview.empty.retry`,{defaultValue:`Retry`})]})})]})})}le();var bv=(0,Q.lazy)(()=>o(()=>import(`./RecordDetailView-B3XBEgk2.js`).then(e=>e.n).then(e=>({default:e.RecordDetailView})),__vite__mapDeps([0]),import.meta.url)),xv=(0,Q.lazy)(()=>o(()=>import(`./DashboardView-juicRxcP.js`).then(e=>({default:e.DashboardView})),__vite__mapDeps([0,1]),import.meta.url)),Sv=(0,Q.lazy)(()=>o(()=>import(`./PageView-C-qWu3Jw.js`).then(e=>({default:e.PageView})),__vite__mapDeps([0]),import.meta.url)),Cv=(0,Q.lazy)(()=>o(()=>import(`./ReportView-pJCFptzp.js`).then(e=>({default:e.ReportView})),__vite__mapDeps([0,1]),import.meta.url)),wv=(0,Q.lazy)(()=>o(()=>import(`./SearchResultsPage-ChVIzFob.js`).then(e=>({default:e.SearchResultsPage})),__vite__mapDeps([0]),import.meta.url)),Tv=(0,Q.lazy)(()=>o(()=>import(`./RecordFormPage-CcoZfUJ3.js`).then(e=>({default:e.RecordFormPage})),__vite__mapDeps([0]),import.meta.url)),Ev=(0,Q.lazy)(()=>o(()=>import(`./ComponentNavView-DrlxM4SY.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),Dv=(0,Q.lazy)(()=>o(()=>import(`./ObjectDataPage-DIY-yefK.js`).then(e=>({default:e.ObjectDataPage})),__vite__mapDeps([0]),import.meta.url)),Ov=(0,Q.lazy)(()=>o(()=>import(`./metadata-admin-CEhVmXFv.js`).then(e=>({default:e.MetadataDirectoryPage})),__vite__mapDeps([0]),import.meta.url)),kv=(0,Q.lazy)(()=>o(()=>import(`./metadata-admin-CEhVmXFv.js`).then(e=>({default:e.StudioHomePage})),__vite__mapDeps([0]),import.meta.url)),Av=(0,Q.lazy)(()=>o(()=>import(`./metadata-admin-CEhVmXFv.js`).then(e=>({default:e.MetadataResourceListPage})),__vite__mapDeps([0]),import.meta.url)),jv=(0,Q.lazy)(()=>o(()=>import(`./metadata-admin-CEhVmXFv.js`).then(e=>({default:e.MetadataResourceEditPage})),__vite__mapDeps([0]),import.meta.url)),Mv=(0,Q.lazy)(()=>o(()=>import(`./metadata-admin-CEhVmXFv.js`).then(e=>({default:e.MetadataResourceHistoryPage})),__vite__mapDeps([0]),import.meta.url)),Nv=(0,Q.lazy)(()=>o(()=>import(`./metadata-admin-CEhVmXFv.js`).then(e=>({default:e.MetadataDiagnosticsPage})),__vite__mapDeps([0]),import.meta.url)),Pv=(0,Q.lazy)(()=>o(()=>import(`./src-BUry7633.js`).then(e=>({default:e.CreateAppPage})),__vite__mapDeps([0]),import.meta.url)),Fv=(0,Q.lazy)(()=>o(()=>import(`./src-BUry7633.js`).then(e=>({default:e.EditAppPage})),__vite__mapDeps([0]),import.meta.url)),Iv=(0,Q.lazy)(()=>o(()=>import(`./src-BUry7633.js`).then(e=>({default:e.DashboardDesignPage})),__vite__mapDeps([0]),import.meta.url)),Lv=(0,Q.lazy)(()=>o(()=>import(`./MarketplacePage-DO2_b64U.js`).then(e=>e.t).then(e=>({default:e.MarketplacePage})),__vite__mapDeps([0]),import.meta.url)),Rv=(0,Q.lazy)(()=>o(()=>import(`./MarketplacePackagePage-BbO27Pgs.js`).then(e=>e.t).then(e=>({default:e.MarketplacePackagePage})),__vite__mapDeps([0]),import.meta.url)),zv=(0,Q.lazy)(()=>o(()=>import(`./MarketplaceInstalledPage-DyjhcUNB.js`).then(e=>e.t).then(e=>({default:e.MarketplaceInstalledPage})),__vite__mapDeps([0]),import.meta.url));function Bv({appName:e}){let{reviewSeq:t,reviewTarget:n}=za(),i=r(),a=(0,Q.useRef)(t);return(0,Q.useEffect)(()=>{if(t===a.current||!n||!e)return;a.current=t;let{type:r,name:o}=n;i(`/apps/${e}/metadata/${encodeURIComponent(r)}/${encodeURIComponent(o)}?review=1`)},[t,n,e,i]),null}function Vv({extraRoutes:e,extraRoutesNoApp:i}={}){let[a,o]=(0,Q.useState)(`disconnected`),{user:s,getAuthConfig:c,activeOrganization:u}=A(),{isAdmin:d,isResolved:p}=S(),h=un(),[_,v]=(0,Q.useState)({});(0,Q.useEffect)(()=>{let e=!1;return c().then(t=>{e||v(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[c]);let y=r(),b=g(),{appName:x}=f(),{apps:C,objects:w,loading:T,ensureType:E,error:D,refresh:O}=Yt(),k=Qu(),j=Oa(),{t:M}=J(),{objectLabel:N}=Xn(),[ee,P]=(0,Q.useState)(!E);(0,Q.useEffect)(()=>{if(!E){P(!0);return}let e=!1;return Promise.all([E(`object`),E(`dashboard`),E(`report`),E(`page`)]).finally(()=>{e||P(!0)}),()=>{e=!0}},[E]);let F=C.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),te=b.pathname.split(`/`),I=b.pathname.endsWith(`/create-app`),ne=te.includes(`system`),re=te.includes(`metadata`),ie=b.pathname===`/apps/setup`||b.pathname.startsWith(`/apps/setup/`),ae=I||ne||re||ie,oe=as(C,x),R=oe||(!x||ae?F.find(e=>e.isDefault===!0)||F[0]:void 0),se=!!x&&!oe&&!ae,[le,z]=(0,Q.useState)(null),ue=le&&le.app===x?le.phase:`idle`;(0,Q.useEffect)(()=>{if(!se){le!==null&&z(null);return}if(ue===`idle`&&!T&&!j&&x){let e=x;z({app:e,phase:`checking`}),Promise.resolve(O()).finally(()=>z(t=>t?.app===e?{app:e,phase:`done`}:t))}},[se,T,j,ue,le,x,O]);let[de,fe]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!se||j||ue!==`done`||!x){fe(e=>e===null?e:null);return}if(de?.app===x)return;let e=h?.probeAppAccess;if(typeof e!=`function`){fe({app:x,verdict:`unknown`});return}let t=!1,n=x;return Promise.resolve(e.call(h,n)).then(e=>{t||fe({app:n,verdict:e})}).catch(()=>{t||fe({app:n,verdict:`unreachable`})}),()=>{t=!0}},[se,j,ue,x,de,h]);let B=de&&de.app===x?de.verdict:null;(0,Q.useEffect)(()=>{if(!R?.name)return;let e=x??R.name,t=`/apps/${e}/metadata/package`;(b.pathname===t||b.pathname.startsWith(`${t}/`))&&y(`/apps/${e}/component/developer/packages`,{replace:!0})},[R?.name,x,b.pathname,y]);let[me,he]=l(),_e=me.get(Ko),V=me.get(ns),H=me.get(Xo),U=(0,Q.useMemo)(()=>_e&&_e!==`new`?{id:_e}:null,[_e]),ye=(0,Q.useMemo)(()=>{if(!H)return;let e=H.indexOf(`:`);if(!(e<=0))return{[H.slice(0,e)]:H.slice(e+1)}},[H]),[be,xe]=(0,Q.useState)(0),W=!!_e,Se=(0,Q.useCallback)(()=>{let e=new URLSearchParams(window.location.search);(e.has(`form`)||e.has(`formObject`)||e.has(`formLink`))&&(e.delete(Ko),e.delete(ns),e.delete(Xo),he(e,{replace:!0}))},[he]),{execute:Ce,runner:we}=Bn();Vn(h),hf(),tn({dataSource:h??void 0,onUndo:e=>{Y.info(M(`actions.undoneOperation`,{description:e.description}),{duration:4e3}),xe(e=>e+1),e?.objectName&&On({objectName:e.objectName,recordId:e.recordId})},onRedo:e=>{Y.info(M(`actions.redoneOperation`,{description:e.description}),{duration:3e3}),xe(e=>e+1),e?.objectName&&On({objectName:e.objectName,recordId:e.recordId})}}),(0,Q.useEffect)(()=>{we.registerHandler(`crud_success`,async e=>(Se(),xe(e=>e+1),Y.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),we.registerHandler(`dialog_cancel`,async()=>(Se(),{success:!0})),we.registerHandler(`navigate_create`,async e=>{let t=we.getContext?.()??{},n=No({action:e,context:t,defaultBaseUrl:`/apps/${x??``}`});return n.success?(y(n.url),{success:!0}):n}),we.registerHandler(`navigate_edit`,async e=>{let t=we.getContext?.()??{},n=Mo({action:e,context:t,defaultBaseUrl:`/apps/${x??``}`});return n.success?(y(n.url),{success:!0}):n})},[we,y,x,Se]),(0,Q.useEffect)(()=>{if(!h)return;let e=h.onConnectionStateChange(e=>{o(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return o(h.getConnectionState()),e},[h]);let Te=b.pathname.split(`/`).filter(Boolean)[2];(Te===`view`||Te===`record`||Te===`page`||Te===`dashboard`||Te===`design`)&&(Te=``);let Ee=w.find(e=>e.name===Te),De=V?w.find(e=>e.name===V):Ee,Oe=!!V&&V!==Ee?.name,ke=(0,Q.useCallback)(()=>{let e=De?N(De):M(`common.record`,{defaultValue:`Record`});Ce({type:`crud_success`,params:{message:U?M(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):M(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[Ce,U,De,N,M]),Ae=(0,Q.useCallback)(()=>{Ce({type:`dialog_cancel`})},[Ce]),je=(0,Q.useCallback)(async e=>{if(Oe){let e=De?N(De):M(`common.record`,{defaultValue:`Record`});Y.success(U?M(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):M(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})),Se();return}if(ke(),U||!Ee)return;let t=Po({objectName:Ee.name,baseUrl:x?`/apps/${x}`:R?.name?`/apps/${R.name}`:``,pathname:b.pathname,search:window.location.search,surface:ce(Ee),recordId:e?.id??e?._id});if(t.kind!==`none`){if(t.kind===`detail-page`){let e=new URLSearchParams(window.location.search);e.delete(Ko),e.delete(ns),e.delete(Xo);let n=e.toString(),r=`${b.pathname}${n?`?${n}`:``}`,i=N(Ee);y(t.url,{replace:!0,state:i?{from:{pathname:r,label:i}}:void 0});return}y(t.url,{replace:!0})}},[ke,Oe,De,U,Ee,x,R?.name,b.pathname,y,Se,N,M]);Nh({pathname:b.pathname,appName:R?.name,objects:w});let Me=e=>{let t=Io({objectDef:Ee,baseUrl:x?`/apps/${x}`:R?.name?`/apps/${R.name}`:``,record:e});if(t.kind===`page`){y(t.url);return}let n=e?.id??e?._id,r=new URLSearchParams(window.location.search);r.set(Ko,n!=null&&n!==``?String(n):`new`),r.delete(ns),r.delete(Xo),he(r)},Ne=e=>{y(`/apps/${e}`)},G=Ka(),Pe=(0,Q.useMemo)(()=>Ga({user:Ya(s),features:_,permissions:G}),[s,_,G]);if(!h||T||!ee||!p)return(0,$.jsx)(rd,{});if(j&&(se||!R))return(0,$.jsx)(yv,{appName:x,error:D,onRetry:()=>void O()});if(se){if(ue!==`done`||B===null)return(0,$.jsx)(rd,{});if(B===`denied`)return(0,$.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,$.jsxs)(ve,{"data-testid":`app-access-denied`,children:[(0,$.jsx)(pe,{children:M(`empty.appAccessDenied`,{defaultValue:`You don't have access to this app`})}),(0,$.jsx)(ge,{children:M(`empty.appAccessDeniedDescription`,{defaultValue:`This app exists, but your account is not authorized to open it. Ask an administrator to grant you access.`})}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{onClick:()=>y(k),"data-testid":`app-access-denied-home`,children:M(`empty.appAccessDeniedHome`,{defaultValue:`Back to home`})})})]})});let e=B===`not_found`?{testId:`app-not-found`,title:M(`empty.appNotFound`,{defaultValue:`This app can't be opened`}),description:M(`empty.appNotFoundDescription`,{defaultValue:`The server did not return this app for your account.`})}:B===`unreachable`?{testId:`app-unreachable`,title:M(`empty.appUnreachable`,{defaultValue:`Couldn't reach the server`}),description:M(`empty.appUnreachableDescription`,{defaultValue:`This app could not be checked. Try again in a moment.`})}:{testId:`app-not-available`,title:M(`empty.appNotAvailable`,{defaultValue:`App not available`}),description:M(`empty.appNotAvailableDescription`,{defaultValue:`This app is not available — try again in a moment.`})};return(0,$.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,$.jsxs)(ve,{"data-testid":e.testId,children:[(0,$.jsx)(pe,{children:e.title}),(0,$.jsx)(ge,{children:e.description}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{onClick:()=>z(null),"data-testid":`${e.testId}-retry`,children:M(`common.retry`,{defaultValue:`Retry`})})})]})})}if(!R&&!I&&!ne&&!re&&!d)return(0,$.jsx)(id,{to:k,replace:!0});if(!R&&!I&&!ne&&!re)return(0,$.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,$.jsxs)(ve,{children:[(0,$.jsx)(pe,{children:M(`empty.noAppsConfigured`)}),(0,$.jsx)(ge,{children:M(`empty.noAppsConfiguredDescription`)}),(0,$.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,$.jsx)(q,{onClick:()=>y(`/apps/${x}/create-app`),"data-testid":`create-first-app-btn`,children:M(`empty.createFirstApp`)}),(0,$.jsx)(q,{variant:`outline`,onClick:()=>y(`/apps/setup/system`),"data-testid":`go-to-settings-btn`,children:M(`empty.systemSettings`)})]})]})});if(!R&&(I||ne||re))return(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsxs)(n,{children:[(0,$.jsx)(m,{path:`create-app`,element:(0,$.jsx)(Pv,{})}),(0,$.jsx)(m,{path:`system/marketplace`,element:(0,$.jsx)(Lv,{})}),(0,$.jsx)(m,{path:`system/marketplace/installed`,element:(0,$.jsx)(zv,{})}),(0,$.jsx)(m,{path:`system/marketplace/:packageId`,element:(0,$.jsx)(Rv,{})}),(0,$.jsx)(m,{path:`metadata`,element:(0,$.jsx)(Ov,{})}),(0,$.jsx)(m,{path:`metadata/_diagnostics`,element:(0,$.jsx)(Nv,{})}),(0,$.jsx)(m,{path:`metadata/:type`,element:(0,$.jsx)(Av,{})}),(0,$.jsx)(m,{path:`metadata/:type/new`,element:(0,$.jsx)(jv,{createMode:!0})}),(0,$.jsx)(m,{path:`metadata/:type/:name`,element:(0,$.jsx)(jv,{})}),(0,$.jsx)(m,{path:`metadata/:type/:name/history`,element:(0,$.jsx)(Mv,{})}),(0,$.jsx)(m,{path:`component/metadata/directory`,element:(0,$.jsx)(qv,{mode:`directory`})}),(0,$.jsx)(m,{path:`component/metadata/resource/*`,element:(0,$.jsx)(qv,{mode:`resource`})}),i,(0,$.jsx)(m,{path:`*`,element:(0,$.jsx)(Yv,{})})]})});let Fe=Ya(s);return(0,$.jsx)(Ja,{user:Fe,app:R,data:{},features:_,children:(0,$.jsxs)(Tn,{currentUserId:s?.id??null,currentOrgId:u?.id??null,children:[(0,$.jsx)(Eh,{}),(0,$.jsxs)(Fg,{activeAppName:R.name,activeApp:R,onAppChange:Ne,objects:w,connectionState:a,userId:s?.id,children:[(0,$.jsx)(Ig,{apps:C,activeApp:R,objects:w,onAppChange:Ne,dataSource:h}),(0,$.jsx)(Rg,{}),(0,$.jsx)(zg,{}),(0,$.jsx)(Bv,{appName:x}),(0,$.jsx)(Qg,{children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(Hg,{className:`h-full`,children:(0,$.jsxs)(n,{children:[(0,$.jsx)(m,{path:`/`,element:(()=>{let e=Wv(R,{currentUserId:s?.id??null});return e?(0,$.jsx)(t,{to:e,replace:!0}):(0,$.jsx)(kv,{})})()}),(0,$.jsx)(m,{path:`metadata/package/*`,element:(0,$.jsx)(t,{to:`/apps/${x??R.name}/component/developer/packages`,replace:!0})}),(0,$.jsxs)(m,{path:`metadata`,children:[(0,$.jsx)(m,{index:!0,element:(0,$.jsx)(Ov,{})}),(0,$.jsx)(m,{path:`_diagnostics`,element:(0,$.jsx)(Nv,{})}),(0,$.jsx)(m,{path:`:type`,element:(0,$.jsx)(Av,{})}),(0,$.jsx)(m,{path:`:type/new`,element:(0,$.jsx)(jv,{createMode:!0})}),(0,$.jsx)(m,{path:`:type/:name`,element:(0,$.jsx)(jv,{})}),(0,$.jsx)(m,{path:`:type/:name/history`,element:(0,$.jsx)(Mv,{})})]}),(0,$.jsx)(m,{path:`:objectName`,element:(0,$.jsx)(_v,{dataSource:h,objects:w,onEdit:Me,externalRefreshKey:be})}),(0,$.jsx)(m,{path:`:objectName/new`,element:(0,$.jsx)(Tv,{mode:`create`})}),(0,$.jsx)(m,{path:`:objectName/view/:viewId`,element:(0,$.jsx)(_v,{dataSource:h,objects:w,onEdit:Me,externalRefreshKey:be})}),(0,$.jsx)(m,{path:`:objectName/data`,element:(0,$.jsx)(Dv,{dataSource:h,objects:w})}),(0,$.jsx)(m,{path:`:objectName/record/:recordId`,element:(0,$.jsx)(bv,{dataSource:h,objects:w,onEdit:Me})}),(0,$.jsx)(m,{path:`:objectName/record/:recordId/edit`,element:(0,$.jsx)(Tv,{mode:`edit`})}),(0,$.jsx)(m,{path:`dashboard/:dashboardName`,element:(0,$.jsx)(xv,{dataSource:h})}),(0,$.jsx)(m,{path:`report/:reportName`,element:(0,$.jsx)(Cv,{dataSource:h})}),(0,$.jsx)(m,{path:`page/:pageName`,element:(0,$.jsx)(Sv,{})}),(0,$.jsx)(m,{path:`component/:ns/:name/*`,element:(0,$.jsx)(Ev,{})}),(0,$.jsx)(m,{path:`component/metadata/directory`,element:(0,$.jsx)(qv,{mode:`directory`})}),(0,$.jsx)(m,{path:`component/metadata/resource/*`,element:(0,$.jsx)(qv,{mode:`resource`})}),(0,$.jsx)(m,{path:`design/dashboard/:dashboardName`,element:(0,$.jsx)(Iv,{})}),(0,$.jsx)(m,{path:`search`,element:(0,$.jsx)(wv,{})}),(0,$.jsx)(m,{path:`create-app`,element:(0,$.jsx)(Pv,{})}),(0,$.jsx)(m,{path:`edit-app/:editAppName`,element:(0,$.jsx)(Fv,{})}),(0,$.jsx)(m,{path:`system/marketplace`,element:(0,$.jsx)(Lv,{})}),(0,$.jsx)(m,{path:`system/marketplace/installed`,element:(0,$.jsx)(zv,{})}),(0,$.jsx)(m,{path:`system/marketplace/:packageId`,element:(0,$.jsx)(Rv,{})}),e,(0,$.jsx)(m,{path:`:objectName/:maybeRecordId`,element:(0,$.jsx)(Jv,{})}),(0,$.jsx)(m,{path:`*`,element:(0,$.jsx)(Yv,{})})]})})})}),De&&(0,$.jsx)(Pa,{schema:{type:`object-form`,formType:`modal`,objectName:De.name,mode:U?`edit`:`create`,recordId:U?.id,...ye&&!U?{initialValues:ye}:{},...L(De,Oe?U?`child-edit`:`child-create`:U?`edit`:`create`).size===`full`?{modalSize:`full`}:{},...Fo(De),title:M(U?`form.editTitle`:`form.createTitle`,{object:N(De)}),open:W,onOpenChange:e=>{e||Se()},layout:`vertical`,fields:De.fields?Array.isArray(De.fields)?De.fields.filter(e=>typeof e==`string`||Wa(e,Pe)).map(e=>typeof e==`string`?e:e.name):Object.entries(De.fields).filter(([e,t])=>Wa(t,Pe)).map(([e])=>e):[],onSuccess:je,onCancel:Ae,showSubmit:!0,showCancel:!0,submitText:U?M(`form.update`,{defaultValue:`Update`}):M(`form.create`,{defaultValue:`Create`}),cancelText:M(`common.cancel`)},dataSource:h},`${De.name}:${U?.id||`new`}`)]})]})})}function Hv(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=Uv(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=Hv(n.children,t);if(e!==``)return e}}return``}function Uv(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=_c(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function Wv(e,t){return Hv(e?.navigation||[],t)}var Gv=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function Kv(e){return!e||Gv.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function qv({mode:e}){let n=g(),r=n.pathname.replace(/\/component\/metadata\/.*$/,``);if(e===`directory`)return(0,$.jsx)(t,{to:`${r}/metadata${n.search}${n.hash}`,replace:!0});let i=new URLSearchParams(n.search).get(`type`)??``,a=n.pathname.match(/\/component\/metadata\/resource(\/.*)?$/)?.[1]??``,o=i?`${r}/metadata/${encodeURIComponent(i)}${a}${n.hash}`:`${r}/metadata${n.hash}`;return(0,$.jsx)(t,{to:o,replace:!0})}function Jv(){let{objectName:e,maybeRecordId:n}=f(),r=g();if(e&&Kv(n)){let e=`${r.pathname.replace(/\/$/,``).replace(`/${n}`,`/record/${n}`)}${r.search}${r.hash}`;return(0,$.jsx)(t,{to:e,replace:!0})}return(0,$.jsx)(Yv,{})}function Yv(){let e=r(),{t}=J();return(0,$.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,$.jsxs)(ve,{children:[(0,$.jsx)(pe,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,$.jsx)(ge,{children:t(`console.notFound.description`,{defaultValue:`The URL you followed does not match any view in this app.`})}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(q,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function Xv(e){return{INVALID_EMAIL_OR_PASSWORD:e(`auth.login.errors.invalidCredentials`,{defaultValue:`Invalid email or password. Please try again.`}),EMAIL_NOT_VERIFIED:e(`auth.login.errors.emailNotVerified`,{defaultValue:`Please verify your email address before signing in.`})}}function Zv(e){let t=e(`auth.register.errors.userExists`,{defaultValue:`An account with this email already exists. Try signing in instead.`});return{USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:t,USER_ALREADY_EXISTS:t,SELF_REGISTRATION_CLOSED:e(`auth.register.errors.selfRegistrationClosed`,{defaultValue:`Self-registration is not open on this environment. Ask an administrator for an invitation.`}),EMAIL_DOMAIN_NOT_ALLOWED:e(`auth.register.errors.emailDomainNotAllowed`,{defaultValue:`This email's domain is not allowed to register here. Use your organization email, or ask an administrator for an invitation.`})}}function Qv({children:e}){let{setContext:t}=Ro(),{t:n}=J(),i=r(),a=g(),o=(0,Q.useCallback)(()=>{rp(`${a.pathname}${a.search}`),i(`/ai`)},[a.pathname,a.search,i]),{enabled:s}=vo();return(0,Q.useEffect)(()=>{t(`home`)},[t]),(0,$.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`home-layout`,children:[(0,$.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,$.jsx)(Gf,{variant:`home`})}),(0,$.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),s&&(0,$.jsx)(Ud,{appLabel:n(`workspace.default`,{defaultValue:`My Workspace`}),onOpenDock:o})]})}function $v(e,t){return e(`home.recentApps.itemType.${t}`,{defaultValue:tc(t)})}function ey({icon:e,title:t,count:n,accent:r,children:i}){return(0,$.jsxs)(`section`,{className:`rounded-2xl bg-card/80 backdrop-blur-sm p-4 `+(r?`border border-primary/30`:`border border-border/70`),children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,$.jsx)(e,{className:`h-4 w-4 `+(r?`text-primary`:`text-muted-foreground`)}),(0,$.jsx)(`h2`,{className:`flex-1 text-sm font-semibold tracking-tight`,children:t}),typeof n==`number`&&n>0&&(0,$.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 ty({icon:e,iconClass:t,label:n,meta:r,trailing:i,onClick:a,testId:o}){return(0,$.jsx)(`li`,{children:(0,$.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,$.jsx)(`span`,{className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-lg `+t,children:(0,$.jsx)(e,{className:`h-4 w-4`})}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,children:n}),r&&(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:r}),i]})})}function ny({pendingApprovalsCount:e,notifications:t,unreadTopicCount:n,notificationsStatus:r,onOpenApprovals:i,onOpenNotification:a,t:o}){let s=tr(),c=e+n,l=r===`ready`;return(0,$.jsxs)(ey,{icon:ta,accent:!0,count:c,title:o(`home.actionCenter.title`,{defaultValue:`Needs your attention`}),children:[!l&&(0,$.jsx)(`div`,{className:`flex items-center gap-2 py-2 text-sm text-muted-foreground`,"data-testid":`home-action-unanswered`,children:r===`error`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Pr,{className:`h-4 w-4 text-amber-500`}),o(`errors.unknown`,{defaultValue:`An unexpected error occurred.`})]}):o(`common.loading`,{defaultValue:`Loading…`})}),c===0?l&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(Or,{className:`h-4 w-4 text-emerald-500`}),o(`home.actionCenter.empty`,{defaultValue:`You're all caught up`})]}):(0,$.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[e>0&&(0,$.jsx)(ty,{icon:ta,iconClass:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:o(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:e}),trailing:(0,$.jsx)(gr,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),onClick:i,testId:`home-action-approvals`}),t.map(e=>(0,$.jsx)(ty,{icon:yr,iconClass:`bg-primary/10 text-primary`,label:e.title,meta:so(e.createdAt,s),onClick:()=>a(e)},e.id))]})]})}var ry={object:Gr,record:$r,dashboard:pi,page:ei},iy={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 ay({items:e,onOpen:t,t:n}){return(0,$.jsx)(ey,{icon:Br,title:n(`home.recentApps.title`,{defaultValue:`Recently Accessed`}),children:e.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`home.continueEmpty`,{defaultValue:`Items you open will show up here.`})}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:e.map(e=>(0,$.jsx)(ty,{icon:ry[e.type]||$r,iconClass:iy[e.type]||`bg-muted text-muted-foreground`,label:e.label,meta:$v(n,e.type),onClick:()=>t(e.href)},e.id))})})}function oy({items:e,onViewAll:t,t:n}){let r=tr();return(0,$.jsxs)(ey,{icon:mr,title:n(`sidebar.activityFeed`,{defaultValue:`Activity feed`}),children:[e.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`layout.activityFeed.empty`,{defaultValue:`No recent activity`})}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:e.slice(0,5).map(e=>(0,$.jsxs)(`li`,{className:`text-sm leading-snug`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.description}),(0,$.jsxs)(`div`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:[so(e.timestamp,r),` · `,e.objectName]})]},e.id))}),(0,$.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,$.jsx)(gr,{className:`h-3 w-3`})]})]})}function sy(e=5){let t=oo(),n=jo(e),{value:r,status:i}=Ao();return{pendingApprovalsCount:t,notifications:(0,Q.useMemo)(()=>{let t=new Set;return r.filter(e=>!e.is_read).filter(e=>(e.title??``).trim().length>0).map(e=>({id:e.id,title:String(e.title),actionUrl:e.action_url??void 0,createdAt:e.created_at??void 0})).filter(e=>!t.has(e.title)&&(t.add(e.title),!0)).slice(0,e)},[r,e]),unreadTopicCount:(0,Q.useMemo)(()=>ko(r).reduce((e,t)=>e+ +(t.unreadCount>0),0),[r]),notificationsStatus:i,activities:n}}function cy(){let e=(0,Q.useMemo)(()=>ao(),[]),{agents:t}=Ss({apiBase:e});return{aiEnabled:t.length>0,askAvailable:t.some(e=>ws(e.name)),buildAvailable:t.some(e=>Ms(t,e.name,`authoring`))}}function ly({icon:e,title:t,subtitle:n,onClick:r,disabled:i,disabledReason:a,testId:o}){return(0,$.jsxs)(`button`,{type:`button`,disabled:i,title:i?a:void 0,onClick:i?void 0:r,"data-testid":o,className:[`flex items-start gap-3 rounded-xl border bg-card px-4 py-3.5 text-left transition-colors`,i?`cursor-not-allowed opacity-60`:`hover:border-primary/50 hover:bg-muted/40`].join(` `),children:[(0,$.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,$.jsx)(e,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-sm font-semibold`,children:t}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:n})]})]})}function uy({askAvailable:e,buildAvailable:t,canAuthorMetadata:n,navigate:r,t:i,layout:a=`row`}){let o=t&&n;return!e&&!o?null:(0,$.jsxs)(`div`,{className:a===`stack`?`mt-6 flex flex-col sm:flex-row items-center gap-3`:`flex shrink-0 items-center gap-2`,children:[o&&(0,$.jsxs)(q,{onClick:()=>r(`/ai/build`),"data-testid":`home-build-with-ai`,children:[(0,$.jsx)(ea,{className:`mr-2 h-4 w-4`}),i(`home.buildWithAI`,{defaultValue:`Build with AI`})]}),e&&!o&&(0,$.jsxs)(q,{onClick:()=>r(`/ai/ask`),"data-testid":`home-ask-ai`,children:[(0,$.jsx)(wi,{className:`mr-2 h-4 w-4`}),i(`home.askAI`,{defaultValue:`Ask AI`})]})]})}function dy(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function fy({t:e}){let{publishAll:t,publishing:n}=Wh(e),{count:r}=tf({});return(r??0)<=0?null:(0,$.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-4`,children:(0,$.jsx)(`div`,{className:`max-w-7xl mx-auto`,children:(0,$.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,$.jsx)(Vr,{className:`h-5 w-5 shrink-0 text-indigo-600 dark:text-indigo-400`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 text-sm text-indigo-900 dark:text-indigo-200`,children:e(`home.pendingDrafts.message`,{count:r,defaultValue:`You have {{count}} unpublished change(s) — publish to make them live.`})}),(0,$.jsx)(q,{size:`sm`,onClick:async()=>{await t()},disabled:n,"data-testid":`pending-drafts-publish`,children:n?e(`home.pendingDrafts.publishing`,{defaultValue:`Publishing…`}):e(`home.pendingDrafts.cta`,{defaultValue:`Publish`})})]})})})}function py({t:e}){let t=r(),{hasLocalPassword:n,getAuthConfig:i}=A(),[a,o]=(0,Q.useState)(!1);return(0,Q.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(i?.()).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,i]),a?(0,$.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-4`,children:(0,$.jsx)(`div`,{className:`max-w-7xl mx-auto`,children:(0,$.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,$.jsx)(Yi,{className:`h-5 w-5 shrink-0 text-amber-600 dark:text-amber-400`}),(0,$.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,$.jsx)(q,{size:`sm`,variant:`outline`,onClick:()=>t(`/set-password`),"data-testid":`recovery-pw-set`,children:e(`home.recoveryReminder.cta`,{defaultValue:`Set password`})}),(0,$.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,$.jsx)(ba,{className:`h-4 w-4`})})]})})}):null}function my(){let e=r(),{t}=J(),{apps:n,loading:i}=Yt(),{recentItems:a}=eo(),{favorites:o}=is(),{user:s}=A(),{isAdmin:c,isResolved:l}=S(),{pendingApprovalsCount:u,notifications:d,unreadTopicCount:f,notificationsStatus:p,activities:m}=sy(),{currentAppName:h}=Ro(),{askAvailable:g,buildAvailable:_}=cy(),v=Gc(),y=Vs(),b=Js(),x=t(`home.build.noCapability`,{defaultValue:`Building apps isn't available in this workspace — it requires the “Manage Metadata” permission, which your account doesn't have.`}),C=t(`home.template.marketplaceDisabled`,{defaultValue:`This runtime has no app marketplace configured, so there are no templates to install here.`}),w=os(n),T=cs(w,h),E=a.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,6),D=(0,Q.useMemo)(()=>t(dy(new Date().getHours()),{defaultValue:`Welcome`}),[t]),O=(s?.name?.trim()||s?.email?.split(`@`)[0]||``).trim();return i||!l?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,$.jsx)(`div`,{className:`text-muted-foreground`,children:t(`home.loading`,{defaultValue:`Loading workspace…`})})}):w.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col flex-1`,children:[(0,$.jsx)(fy,{t}),(0,$.jsx)(py,{t}),(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:c&&!v?(0,$.jsxs)(ve,{children:[(0,$.jsx)(pe,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,$.jsx)(ge,{"data-testid":`home-authoring-gate-reason-empty`,children:x}),(0,$.jsx)(uy,{askAvailable:g,buildAvailable:_,canAuthorMetadata:v,navigate:e,t,layout:`stack`})]}):c?(0,$.jsxs)(ve,{children:[(0,$.jsx)(pe,{children:t(`home.welcome`,{defaultValue:`Build your business system with AI`})}),(0,$.jsx)(ge,{children:_?t(`home.welcomeAdminDescription`,{defaultValue:`Describe your business in one sentence — AI generates the objects, screens, APIs and agent tools. Or set things up yourself from the menu on the left.`}):g?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,$.jsx)(uy,{askAvailable:g,buildAvailable:_,canAuthorMetadata:v,navigate:e,t,layout:`stack`})]}):(0,$.jsxs)(ve,{children:[(0,$.jsx)(pe,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,$.jsx)(ge,{children:t(`home.noAppsDescription`,{defaultValue:`Your workspace is being set up — apps your admin shares with you will show up here.`})})]})})]}):(0,$.jsxs)(`div`,{className:`relative min-h-full bg-background`,children:[(0,$.jsx)(fy,{t}),(0,$.jsx)(py,{t}),(0,$.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-8 pb-16`,children:(0,$.jsxs)(`div`,{className:`max-w-7xl mx-auto`,children:[(0,$.jsxs)(`div`,{className:`mb-7 flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight text-pretty`,children:[(0,$.jsxs)(`span`,{className:`text-foreground`,children:[D,O?`, `:``]}),O&&(0,$.jsx)(`span`,{className:`text-primary`,children:O}),(0,$.jsx)(`span`,{className:`text-foreground/40`,children:`.`})]}),(0,$.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,$.jsx)(uy,{askAvailable:g,buildAvailable:_,canAuthorMetadata:v,navigate:e,t})]}),c&&(0,$.jsxs)(`div`,{className:`mb-6`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[b&&(0,$.jsx)(ly,{icon:oi,title:t(`home.build.title`,{defaultValue:`Build an app`}),subtitle:t(`home.build.subtitle`,{defaultValue:`Start from scratch — design objects, forms, automations and interfaces.`}),onClick:()=>e(`/studio`),disabled:!v,disabledReason:x,testId:`home-build-app`}),(0,$.jsx)(ly,{icon:hi,title:t(`home.template.title`,{defaultValue:`Start with a template`}),subtitle:t(`home.template.subtitle`,{defaultValue:`Install a template app from the marketplace and customize it.`}),onClick:()=>e(`/apps/setup/system/marketplace`),disabled:!v||!y,disabledReason:v?C:x,testId:`home-start-template`})]}),!v&&(0,$.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,"data-testid":`home-authoring-gate-reason`,children:x}),v&&!y&&(0,$.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,"data-testid":`home-marketplace-disabled-reason`,children:C})]}),(0,$.jsx)(Do,{apps:w,favorites:o,onOpen:t=>e(`/apps/${ss(t)??t.name}`),onBrowseMarketplace:()=>e(`/apps/setup/system/marketplace`),isAdmin:c,canAuthorMetadata:v,marketplaceEnabled:y}),(0,$.jsx)(`div`,{className:`mb-6`,children:(0,$.jsx)(ny,{pendingApprovalsCount:u,notifications:d,unreadTopicCount:f,notificationsStatus:p,onOpenApprovals:()=>e(`/apps/${T}/system/approvals`),onOpenNotification:t=>{let n=us(t.actionUrl,T);if(!n){e(`/apps/${T}/sys_inbox_message?view=mine`);return}if(n.kind===`external`){window.open(n.url,`_blank`,`noopener,noreferrer`);return}e(n.path)},t})}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,$.jsx)(ay,{items:E,onOpen:t=>e(t),t}),(0,$.jsx)(oy,{items:m,onViewAll:()=>e(`/apps/${T}/sys_activity`),t})]})]})})]})}function hy({children:e}){let{setContext:t}=Ro();return(0,Q.useEffect)(()=>{t(`home`)},[t]),(0,$.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organizations-layout`,children:[(0,$.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,$.jsx)(Gf,{variant:`orgs`})}),(0,$.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}async function gy(e){let t=await y()(`${Qs()}/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(()=>null))?.data;if(!n||typeof n!=`object`)throw Error("Malformed control-plane response: expected a `{ success, data }` envelope from POST /cloud/environments");let r=n.environment;if(!r||typeof r!=`object`)throw Error("Malformed control-plane response: `data.environment` is missing from POST /cloud/environments");return{id:r.id,hostname:r.hostname}}var _y={YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION:{key:`organization.errors.notAllowedToInvite`,defaultValue:`You are not allowed to invite users to this organization`},YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE:{key:`organization.errors.notAllowedToInviteWithRole`,defaultValue:`You are not allowed to invite a user with this role`},USER_IS_ALREADY_INVITED_TO_THIS_ORGANIZATION:{key:`organization.errors.alreadyInvited`,defaultValue:`This user has already been invited to this organization`},ORGANIZATION_ALREADY_EXISTS:{key:`organization.errors.organizationExists`,defaultValue:`Organization already exists`},ORGANIZATION_SLUG_ALREADY_TAKEN:{key:`organization.errors.slugTaken`,defaultValue:`That URL slug is already taken`},YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_ORGANIZATION:{key:`organization.errors.notAllowedToCreate`,defaultValue:`You are not allowed to create a new organization`},YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION:{key:`organization.errors.notTheRecipient`,defaultValue:`You are not the recipient of the invitation`},INVITATION_NOT_FOUND:{key:`organization.errors.invitationNotFound`,defaultValue:`This invitation no longer exists or has expired`}},vy={key:`organization.errors.unknown`,defaultValue:`Something went wrong. Please try again.`};function yy(e){if(typeof e!=`object`||!e)return;let t=e.code;return typeof t==`string`&&t?t:void 0}function by(e,t,n){let r=yy(e);if(r){let e=_y[r];if(e)return t(e.key,{defaultValue:e.defaultValue})}let i=e instanceof Error?e.message:void 0;return typeof i==`string`&&i.trim()?i:n?t(n.key,{defaultValue:n.defaultValue}):t(vy.key,{defaultValue:vy.defaultValue})}function xy(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 Sy({open:e,onOpenChange:t,onCreated:n}){let{t:r}=J(),{createOrganization:i,getAuthConfig:a}=A(),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||_(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,Q.useEffect)(()=>{u||l(xy(o))},[o,u]),(0,Q.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]);let v=(0,Q.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 gy({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(by(e,r,{key:`workspace.createFailed`,defaultValue:`Failed to create workspace`}))}finally{p(!1)}}},[o,c,g,r,i,n]);return(0,$.jsx)(gt,{open:e,onOpenChange:t,children:(0,$.jsx)(Ae,{className:`sm:max-w-[425px]`,"data-testid":`create-workspace-dialog`,children:(0,$.jsxs)(`form`,{onSubmit:v,children:[(0,$.jsxs)(U,{children:[(0,$.jsx)(Ce,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,$.jsx)(Me,{children:r(`workspace.createDescription`,{defaultValue:`A workspace is a shared space for your team to collaborate.`})})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(z,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,$.jsx)(K,{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,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(z,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,$.jsx)(K,{id:`workspace-slug`,placeholder:`acme-inc`,value:c,onChange:e=>{l(e.target.value),d(!0)},"data-testid":`workspace-slug-input`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`workspace.slugHint`,{defaultValue:`Used in URLs. Only lowercase letters, numbers, and hyphens.`})})]}),m&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`workspace-create-error`,children:m})]}),(0,$.jsxs)(Pe,{children:[(0,$.jsx)(q,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(q,{type:`submit`,disabled:f||!o.trim()||!c.trim(),"data-testid":`workspace-create-submit`,children:[f&&(0,$.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function Cy(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function wy(){let{t:e}=J(),t=r(),[n]=l(),i=n.get(`manage`)===`1`,a=n.get(`create`)===`1`,{organizations:o,activeOrganization:s,isOrganizationsLoading:c,switchOrganization:u,getAuthConfig:d}=A(),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(!0);(0,Q.useEffect)(()=>{let e=!1;return d().then(t=>{e||t?.features?.multiOrgEnabled===!1&&y(!1)}).catch(()=>{}),()=>{e=!0}},[d]);let b=o??[],x=(0,Q.useMemo)(()=>{let e=f.trim().toLowerCase();return e?b.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):b},[b,f]),S=async e=>{_(e.id);try{e.id!==s?.id&&await u(e.id),window.location.href=qd()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),_(null)}},C=e=>{h(!1),S(e)},w=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{w.current||c||a||b.length===1&&(w.current=!0,i?t(`/organizations/${b[0].slug}/members`,{replace:!0}):S(b[0]))},[c,b.length,i,a]);let T=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(c)return;let e=b.length===0&&v;(a||e)&&!T.current&&(T.current=!0,h(!0))},[a,b.length,v,c]);let E=!a&&!c&&b.length===1,D=!c&&b.length===0&&v&&!T.current;return c||E||D?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,$.jsx)(X,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-8 sm:py-12`,children:[(0,$.jsxs)(`div`,{className:`mb-8`,children:[(0,$.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:e(`organizations.heading`,{defaultValue:`Your Workspaces`})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organizations.subtitle`,{defaultValue:`Select a workspace to continue, or create a new one.`})})]}),(0,$.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`relative w-full sm:max-w-sm`,children:[(0,$.jsx)(Gi,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(K,{value:f,onChange:e=>p(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for a workspace`}),className:`pl-9`,"data-testid":`organizations-search`})]}),v&&(0,$.jsxs)(q,{onClick:()=>h(!0),"data-testid":`organizations-new`,children:[(0,$.jsx)(Ri,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New workspace`})]})]}),b.length===0?(0,$.jsxs)(ve,{children:[(0,$.jsx)(pe,{children:e(`organizations.emptyTitle`,{defaultValue:`No workspaces yet`})}),(0,$.jsx)(ge,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first workspace to get started.`})}),v&&(0,$.jsxs)(q,{className:`mt-6`,onClick:()=>h(!0),children:[(0,$.jsx)(Ri,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New workspace`})]})]}):x.length===0?(0,$.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organizations.noMatches`,{defaultValue:`No workspaces match your search.`})}):(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:x.map(n=>{let r=n.id===s?.id,i=g===n.id;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>S(n),disabled:i,className:`group flex items-center gap-3 rounded-lg border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60`,"data-testid":`organization-card-${n.slug}`,children:[(0,$.jsxs)(qe,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,$.jsx)(At,{src:n.logo,alt:n.name}),(0,$.jsx)(wt,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:Cy(n.name)})]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate font-medium`,children:n.name}),(0,$.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:r?e(`organizations.current`,{defaultValue:`Current workspace`}):n.slug})]}),(0,$.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,$.jsx)(X,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,$.jsx)(Sy,{open:m,onOpenChange:h,onCreated:C})]})}function Ty(){let{t:e}=J(),t=r(),{slug:n}=f(),{organizations:i,activeOrganization:a,isOrganizationsLoading:o,switchOrganization:c}=A(),{setContext:l}=Ro();(0,Q.useEffect)(()=>{l(`home`)},[l]);let u=(0,Q.useMemo)(()=>(i??[]).find(e=>e.slug===n)??null,[i,n]);if((0,Q.useEffect)(()=>{u&&a?.id!==u.id&&c(u.id).catch(e=>{console.error(`[OrganizationLayout] switch failed`,e)})},[u,a,c]),o)return(0,$.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center`,children:(0,$.jsx)(X,{className:`h-5 w-5 animate-spin text-muted-foreground`})});if(!u)return(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-12 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.notFound`,{defaultValue:`Organization not found`})}),(0,$.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,$.jsx)(q,{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,$.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organization-layout`,children:[(0,$.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,$.jsx)(Gf,{variant:`orgs`})}),(0,$.jsx)(`div`,{className:`border-b`,children:(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 pt-6`,children:[(i??[]).length>1&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>t(`/organizations`),className:`mb-3 inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground`,children:[(0,$.jsx)(hr,{className:`h-3.5 w-3.5`}),e(`organization.backToList`,{defaultValue:`Back to organizations`})]}),(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`h1`,{className:`truncate text-2xl font-bold tracking-tight`,children:u.name}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:u.slug})]})}),(0,$.jsx)(`nav`,{className:`mt-4 flex gap-1 -mb-px`,children:p.map(e=>(0,$.jsx)(s,{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,$.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:(0,$.jsx)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-6`,children:(0,$.jsx)(d,{context:{org:u}})})})]})}function Ey(){return i()}function Dy(e){return Object.prototype.hasOwnProperty.call(N,e)}function Oy(e,t){if(typeof e!=`string`)return``;let n=e.trim();if(!n)return``;if(!Dy(n))return n;let r=N[n];return t(r.key,{defaultValue:r.defaultValue})}function ky({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=J(),{inviteMember:a,describeDelegableScope:o,activeMember:s}=A(),c=j(s?.role),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(R),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(null),[C,w]=(0,Q.useState)(``),[T,E]=(0,Q.useState)([]);(0,Q.useEffect)(()=>{t&&(u(``),f(R),g(null),v(null),b(!1),w(``),E([]))},[t]),(0,Q.useEffect)(()=>{if(!t)return;let e=!1;return o?.().then(t=>{e||S(t)}).catch(()=>{}),()=>{e=!0}},[t,o]);let D=!!x&&x.placeableBusinessUnitIds.length>0&&x.assignablePositions.length>0,O=(0,Q.useCallback)(async t=>{if(t.preventDefault(),l.trim()){m(!0),g(null);try{let t=await a({organizationId:e,email:l.trim(),role:d,...D&&C&&T.length>0?{businessUnitId:C,positions:T}:{}});v(t),r?.(t)}catch(e){g(by(e,i,{key:`organization.invitations.inviteFailed`,defaultValue:`Failed to invite member`}))}finally{m(!1)}}},[l,d,e,a,r,D,C,T,i]),k=_?Jd(`accept-invitation/${_.id}`):null,M=(0,Q.useCallback)(async()=>{if(k)try{await navigator.clipboard.writeText(k),b(!0),Y.success(i(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>b(!1),2e3)}catch{Y.error(i(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},[k,i]);return(0,$.jsx)(gt,{open:t,onOpenChange:n,children:(0,$.jsx)(Ae,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:_?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(U,{children:[(0,$.jsx)(Ce,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,$.jsx)(Me,{children:i(`organization.invitations.sentDescription`,{defaultValue:`Share the link below with the invitee. They will need to sign in to accept.`})})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 py-4`,children:[(0,$.jsx)(z,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(K,{readOnly:!0,value:k??``,className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,$.jsx)(q,{type:`button`,variant:`outline`,size:`icon`,onClick:M,"aria-label":i(`organization.invitations.copyLinkLabel`,{defaultValue:`Copy invitation link`}),children:y?(0,$.jsx)(kr,{className:`h-4 w-4`}):(0,$.jsx)(Wr,{className:`h-4 w-4`})})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`organization.invitations.invitedAs`,{defaultValue:`{{email}} invited as {{role}}`,email:_.email,role:Oy(_.role,i)})})]}),(0,$.jsx)(Pe,{children:(0,$.jsx)(q,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,$.jsxs)(`form`,{onSubmit:O,children:[(0,$.jsxs)(U,{children:[(0,$.jsx)(Ce,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,$.jsx)(Me,{children:i(`organization.invitations.inviteDescription`,{defaultValue:`They will receive an invitation to join this organization.`})})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(z,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,$.jsx)(K,{id:`invite-email`,type:`email`,required:!0,placeholder:`user@example.com`,value:l,onChange:e=>u(e.target.value),autoFocus:!0,"data-testid":`invite-email-input`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(z,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,$.jsxs)(De,{value:d,onValueChange:e=>f(e),children:[(0,$.jsx)(B,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,$.jsx)(He,{})}),(0,$.jsx)(Ie,{children:c.map(e=>(0,$.jsx)(Wt,{value:e,"data-testid":`invite-role-${e}`,children:Oy(e,i)},e))})]})]}),D&&(0,$.jsxs)(`div`,{className:`grid gap-3 rounded-md border border-dashed p-3`,"data-testid":`invite-placement-section`,children:[(0,$.jsxs)(`div`,{className:`grid gap-1`,children:[(0,$.jsx)(z,{className:`text-sm`,children:i(`organization.invitations.placementLabel`,{defaultValue:`Placement (optional)`})}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`organization.invitations.placementDescription`,{defaultValue:`Applied when the invitation is accepted. Only units and positions you may delegate are listed.`})})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(z,{htmlFor:`invite-business-unit`,className:`text-xs`,children:i(`organization.invitations.businessUnitLabel`,{defaultValue:`Business unit`})}),(0,$.jsxs)(De,{value:C,onValueChange:w,children:[(0,$.jsx)(B,{id:`invite-business-unit`,"data-testid":`invite-business-unit-select`,children:(0,$.jsx)(He,{placeholder:i(`organization.invitations.businessUnitPlaceholder`,{defaultValue:`No placement`})})}),(0,$.jsx)(Ie,{children:x.placeableBusinessUnitIds.map(e=>(0,$.jsx)(Wt,{value:e,children:e},e))})]})]}),C&&(0,$.jsxs)(`div`,{className:`grid gap-2`,"data-testid":`invite-positions`,children:[(0,$.jsx)(z,{className:`text-xs`,children:i(`organization.invitations.positionsLabel`,{defaultValue:`Positions`})}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:x.assignablePositions.map(e=>{let t=T.includes(e);return(0,$.jsx)(q,{type:`button`,size:`sm`,variant:t?`default`:`outline`,"data-testid":`invite-position-${e}`,"aria-pressed":t,onClick:()=>E(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),children:e},e)})})]})]}),h&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`invite-error`,children:h})]}),(0,$.jsxs)(Pe,{children:[(0,$.jsx)(q,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:p,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(q,{type:`submit`,disabled:p||!l.trim(),"data-testid":`invite-submit`,children:[p&&(0,$.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}var Ay=T(ie);function jy(e){return typeof e==`string`?e.split(`,`).map(e=>e.trim().toLowerCase()).filter(Boolean):[]}function My(e){return T(e)>=Ay||jy(e).includes(oe)}function Ny(e){return T(e)>=Ay}function Py(e){return T(e)>=Ay}function Fy(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function Iy(){let{t:e}=J(),t=tr(),{org:n}=Ey(),{getMembers:r,removeMember:i,updateMemberRole:a,activeMember:o}=A(),s=My(o?.role),c=Ny(o?.role),[l,u]=(0,Q.useState)([]),[d,f]=(0,Q.useState)(!0),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(null),y=(0,Q.useCallback)(async()=>{f(!0),m(null);try{let e=await r(n.id);u(e)}catch(t){m(by(t,e,{key:`organization.members.loadFailed`,defaultValue:`Failed to load members`}))}finally{f(!1)}},[n.id,r,e]);(0,Q.useEffect)(()=>{y()},[y]);let b=async(t,r)=>{try{await a({organizationId:n.id,memberId:t.id,role:r}),Y.success(e(`organization.members.roleUpdated`,{defaultValue:`Role updated`})),y()}catch(t){Y.error(by(t,e,{key:`organization.members.roleUpdateFailed`,defaultValue:`Failed to update role`}))}};return d?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,$.jsx)(X,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):p?(0,$.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[p,(0,$.jsx)(q,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:y,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,$.jsxs)(`div`,{className:`space-y-4`,"data-testid":`members-page`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[e(`organization.members.title`,{defaultValue:`Members`}),` (`,l.length,`)`]}),s?(0,$.jsx)(q,{onClick:()=>g(!0),"data-testid":`invite-member-btn`,children:e(`organization.members.inviteMember`,{defaultValue:`Invite member`})}):(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,"data-testid":`invite-restricted-note`,children:e(`organization.members.inviteRestrictedNote`,{defaultValue:`Only organization admins can invite members.`})})]}),(0,$.jsx)(Se,{}),(0,$.jsx)(`div`,{className:`space-y-2`,children:l.map(n=>{let r=O(o?.role,n.role),i=r.length>0||c;return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`member-row-${n.id}`,children:[(0,$.jsxs)(qe,{className:`h-9 w-9 shrink-0`,children:[n.user?.image&&(0,$.jsx)(At,{src:n.user.image,alt:n.user.name}),(0,$.jsx)(wt,{className:`text-xs font-medium`,children:Fy(n.user?.name)})]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate font-medium text-sm`,children:n.user?.name??`—`}),(0,$.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:n.user?.email??`—`})]}),(0,$.jsx)(pt,{variant:`outline`,className:`shrink-0`,"data-testid":`member-role-badge-${n.id}`,children:Oy(n.role,e)}),n.createdAt&&(0,$.jsx)(`span`,{className:`hidden shrink-0 text-xs text-muted-foreground sm:block`,children:new Date(n.createdAt).toLocaleDateString(t)}),i&&(0,$.jsxs)(it,{children:[(0,$.jsx)(yt,{asChild:!0,children:(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":e(`organization.members.memberActions`,{defaultValue:`Member actions`}),children:(0,$.jsx)(qr,{className:`h-4 w-4`})})}),(0,$.jsxs)(Pt,{align:`end`,children:[r.map(t=>(0,$.jsxs)(kt,{onClick:()=>b(n,t),disabled:n.role===t,"data-testid":`member-role-${t}`,children:[(0,$.jsx)(Xi,{className:`mr-2 h-4 w-4`}),e(N[t].key,{defaultValue:N[t].defaultValue})]},t)),c&&(0,$.jsxs)(kt,{className:`text-destructive focus:text-destructive`,onClick:()=>v(n),children:[(0,$.jsx)(ma,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},n.id)})}),(0,$.jsx)(tt,{open:!!_,onOpenChange:e=>!e&&v(null),children:(0,$.jsxs)(bt,{children:[(0,$.jsxs)(Ke,{children:[(0,$.jsx)(Rt,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,$.jsx)(dt,{children:e(`organization.members.removeConfirmDescription`,{defaultValue:`This will remove {{name}} from the organization. They will lose access immediately.`,name:_?.user?.name??_?.userId??``})})]}),(0,$.jsxs)(lt,{children:[(0,$.jsx)(Et,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsx)(st,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{if(_)try{await i({organizationId:n.id,memberIdOrUserId:_.id}),Y.success(e(`organization.members.memberRemoved`,{defaultValue:`Member removed`})),v(null),y()}catch(t){Y.error(by(t,e,{key:`organization.members.removeFailed`,defaultValue:`Failed to remove member`}))}},children:e(`organization.members.removeConfirmAction`,{defaultValue:`Remove`})})]})]})}),s&&(0,$.jsx)(ky,{organizationId:n.id,open:h,onOpenChange:g,onInvited:()=>y()})]})}function Ly(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`}}function Ry(){let{t:e}=J(),t=tr(),{org:n}=Ey(),{listInvitations:r,cancelInvitation:i,activeMember:a}=A(),o=Py(a?.role),s=My(a?.role),[c,l]=(0,Q.useState)([]),[u,d]=(0,Q.useState)(!0),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(`all`),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(null),b=(0,Q.useCallback)(async()=>{d(!0),p(null);try{let e=await r(n.id);l(e)}catch(t){p(by(t,e,{key:`organization.invitations.loadFailed`,defaultValue:`Failed to load invitations`}))}finally{d(!1)}},[n.id,r,e]);(0,Q.useEffect)(()=>{b()},[b]);let x=async t=>{let n=Jd(`accept-invitation/${t.id}`);try{await navigator.clipboard.writeText(n),y(t.id),Y.success(e(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>y(null),2e3)}catch{Y.error(e(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},S=async()=>{if(g)try{await i(g.id),Y.success(e(`organization.invitations.canceled`,{defaultValue:`Invitation canceled`})),_(null),b()}catch(t){Y.error(by(t,e,{key:`organization.invitations.cancelFailed`,defaultValue:`Failed to cancel invitation`}))}},C=m===`all`?c:c.filter(e=>e.status===m),w={all:c.length,pending:c.filter(e=>e.status===`pending`).length,accepted:c.filter(e=>e.status===`accepted`).length,rejected:c.filter(e=>e.status===`rejected`).length,canceled:c.filter(e=>e.status===`canceled`).length};return u?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,$.jsx)(X,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):f?(0,$.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[f,(0,$.jsx)(q,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:b,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,$.jsxs)(`div`,{className:`space-y-4`,"data-testid":`invitations-page`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.invitations.title`,{defaultValue:`Invitations`})})}),(0,$.jsx)(`div`,{className:`flex gap-1 border-b`,children:[`all`,`pending`,`accepted`,`rejected`,`canceled`].map(t=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>h(t),className:`px-3 py-2 text-sm font-medium border-b-2 transition-colors capitalize ${m===t?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[e(`organization.invitations.status.${t}`,{defaultValue:t}),w[t]>0&&(0,$.jsx)(`span`,{className:`ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs`,children:w[t]})]},t))}),(0,$.jsx)(Se,{}),C.length===0?(0,$.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,$.jsx)(`div`,{className:`space-y-2`,children:C.map(n=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`invitation-row-${n.id}`,children:[(0,$.jsx)(qe,{className:`h-9 w-9 shrink-0`,children:(0,$.jsx)(wt,{className:`text-xs`,children:(0,$.jsx)(bi,{className:`h-4 w-4`})})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate font-medium text-sm`,children:n.email}),n.expiresAt&&(0,$.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e(`organization.invitations.expiresAt`,{defaultValue:`Expires`}),` `,new Date(n.expiresAt).toLocaleDateString(t)]})]}),(0,$.jsx)(pt,{variant:`outline`,className:`shrink-0`,"data-testid":`invitation-role-badge-${n.id}`,children:Oy(n.role,e)}),(0,$.jsx)(pt,{variant:Ly(n.status),className:`shrink-0 capitalize`,children:e(`organization.invitations.status.${n.status}`,{defaultValue:n.status})}),n.status===`pending`&&(s||o)&&(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[s&&(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>x(n),"aria-label":e(`organization.invitations.copyLinkLabel`,{defaultValue:`Copy invitation link`}),children:v===n.id?(0,$.jsx)(kr,{className:`h-4 w-4 text-green-600`}):(0,$.jsx)(Wr,{className:`h-4 w-4`})}),o&&(0,$.jsx)(q,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,onClick:()=>_(n),"aria-label":e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`}),children:(0,$.jsx)(ba,{className:`h-4 w-4`})})]})]},n.id))}),(0,$.jsx)(tt,{open:!!g,onOpenChange:e=>!e&&_(null),children:(0,$.jsxs)(bt,{children:[(0,$.jsxs)(Ke,{children:[(0,$.jsx)(Rt,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,$.jsx)(dt,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:g?.email??``})})]}),(0,$.jsxs)(lt,{children:[(0,$.jsx)(Et,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsx)(st,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:S,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function zy(){let{t:e}=J(),{org:t}=Ey(),{user:n,getMembers:i,updateOrganization:a,deleteOrganization:o,leaveOrganization:s}=A(),c=r(),[l,u]=(0,Q.useState)(t.name),[d,f]=(0,Q.useState)(t.slug??``),[p,m]=(0,Q.useState)(t.logo??``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(!1),y=(0,Q.useRef)(null),{upload:b}=me(),[x,S]=(0,Q.useState)(null),[C,w]=(0,Q.useState)(!0),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(!1),[k,j]=(0,Q.useState)(``),[M,N]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{u(t.name),f(t.slug??``),m(t.logo??``)},[t]),(0,Q.useEffect)(()=>{let e=!1;return w(!0),i(t.id).then(t=>{if(e)return;let r=t.find(e=>e.userId===n?.id);S(r?.role===`owner`)}).catch(()=>{e||S(!1)}).finally(()=>{e||w(!1)}),()=>{e=!0}},[t.id,n?.id,i]);let ee=(0,Q.useCallback)(async n=>{n.preventDefault(),g(!0);try{await a(t.id,{name:l.trim(),slug:d.trim()||void 0,logo:p.trim()||void 0}),Y.success(e(`organization.settings.saved`,{defaultValue:`Settings saved`}))}catch(t){Y.error(t instanceof Error?t.message:e(`organization.settings.saveFailed`,{defaultValue:`Failed to save settings`}))}finally{g(!1)}},[t.id,l,d,p,a,e]);return C?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,$.jsx)(X,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,$.jsxs)(`div`,{className:`space-y-8`,"data-testid":`settings-page`,children:[(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.settings.generalTitle`,{defaultValue:`General`})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organization.settings.generalDescription`,{defaultValue:`Update your organization information.`})}),(0,$.jsx)(Se,{className:`my-4`}),x?(0,$.jsxs)(`form`,{onSubmit:ee,className:`space-y-4 max-w-md`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(z,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,$.jsx)(K,{id:`org-name`,value:l,onChange:e=>u(e.target.value),required:!0,"data-testid":`settings-name-input`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(z,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,$.jsx)(K,{id:`org-slug`,value:d,onChange:e=>f(e.target.value),"data-testid":`settings-slug-input`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(z,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(qe,{className:`size-16 rounded-md`,children:[p?(0,$.jsx)(At,{src:p,alt:l,className:`object-cover`}):null,(0,$.jsx)(wt,{className:`rounded-md text-base`,children:(l||`O`).slice(0,2).toUpperCase()})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`input`,{ref:y,type:`file`,accept:`image/*`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(y.current&&(y.current.value=``),n){v(!0);try{let t=await b(n);m(t.url),Y.success(e(`organization.settings.logoUploaded`,{defaultValue:`Logo uploaded — save to apply`}))}catch(t){Y.error(t instanceof Error?t.message:e(`organization.settings.logoUploadFailed`,{defaultValue:`Failed to upload logo`}))}finally{v(!1)}}},"data-testid":`settings-logo-file`}),(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,disabled:_,onClick:()=>y.current?.click(),"data-testid":`settings-logo-upload-btn`,children:[_?(0,$.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}):(0,$.jsx)(fa,{className:`mr-2 h-4 w-4`}),p?e(`organization.settings.logoReplace`,{defaultValue:`Replace`}):e(`organization.settings.logoUpload`,{defaultValue:`Upload`})]}),p&&(0,$.jsxs)(q,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>m(``),"data-testid":`settings-logo-clear-btn`,children:[(0,$.jsx)(ba,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,$.jsx)(K,{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,$.jsxs)(q,{type:`submit`,disabled:h,"data-testid":`settings-save-btn`,children:[h&&(0,$.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.save`,{defaultValue:`Save changes`})]})]}):(0,$.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,$.jsxs)(`section`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-destructive`,children:e(`organization.settings.dangerZone`,{defaultValue:`Danger zone`})}),(0,$.jsx)(Se,{className:`my-4`}),(0,$.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-destructive/50 bg-destructive/5 p-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.leaveTitle`,{defaultValue:`Leave organization`})}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.leaveDescription`,{defaultValue:`You will lose access to this organization.`})})]}),(0,$.jsx)(q,{variant:`destructive`,size:`sm`,onClick:()=>E(!0),children:e(`organization.settings.leaveAction`,{defaultValue:`Leave`})})]}),(0,$.jsx)(Se,{}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.deleteTitle`,{defaultValue:`Delete organization`})}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.deleteDescription`,{defaultValue:`Permanently delete this organization and all its data.`})})]}),(0,$.jsx)(q,{variant:`destructive`,size:`sm`,onClick:()=>{j(``),O(!0)},disabled:!x,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,$.jsx)(tt,{open:T,onOpenChange:E,children:(0,$.jsxs)(bt,{children:[(0,$.jsxs)(Ke,{children:[(0,$.jsx)(Rt,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,$.jsx)(dt,{children:e(`organization.settings.leaveConfirmDescription`,{defaultValue:`Are you sure you want to leave {{name}}? You will lose access immediately.`,name:t.name})})]}),(0,$.jsxs)(lt,{children:[(0,$.jsx)(Et,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(st,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{N(!0);try{await s(t.id),Y.success(e(`organization.settings.leftOrg`,{defaultValue:`You have left the organization`})),c(`/organizations`)}catch(t){Y.error(t instanceof Error?t.message:e(`organization.settings.leaveFailed`,{defaultValue:`Failed to leave organization`}))}finally{N(!1)}},disabled:M,children:[M&&(0,$.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,$.jsx)(tt,{open:D,onOpenChange:e=>{O(e),e||j(``)},children:(0,$.jsxs)(bt,{children:[(0,$.jsxs)(Ke,{children:[(0,$.jsx)(Rt,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,$.jsx)(dt,{children:e(`organization.settings.deleteConfirmDescription`,{defaultValue:`This action is irreversible. All data will be permanently deleted. Type the organization slug to confirm.`})})]}),(0,$.jsxs)(`div`,{className:`px-6 pb-2`,children:[(0,$.jsx)(z,{htmlFor:`delete-confirm-slug`,className:`text-sm font-medium`,children:e(`organization.settings.deleteConfirmSlugLabel`,{defaultValue:`Type "{{slug}}" to confirm`,slug:t.slug})}),(0,$.jsx)(K,{id:`delete-confirm-slug`,className:`mt-2`,value:k,onChange:e=>j(e.target.value),placeholder:t.slug,"data-testid":`delete-confirm-slug-input`})]}),(0,$.jsxs)(lt,{children:[(0,$.jsx)(Et,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(st,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{N(!0);try{await o(t.id),Y.success(e(`organization.settings.deleted`,{defaultValue:`Organization deleted`})),c(`/organizations`)}catch(t){Y.error(t instanceof Error?t.message:e(`organization.settings.deleteFailed`,{defaultValue:`Failed to delete organization`}))}finally{N(!1)}},disabled:M||k!==t.slug,children:[M&&(0,$.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}function By(){let{t:e}=J(),t=tr(),n=r(),i=g(),{invitationId:a}=f(),{isAuthenticated:o,isLoading:s,getInvitation:c,acceptInvitation:l,rejectInvitation:u,switchOrganization:d}=A(),[p,m]=(0,Q.useState)(null),[h,_]=(0,Q.useState)(!0),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{!s&&!o&&n(`/login?redirect=`+encodeURIComponent(i.pathname+i.search))},[o,s,n,i.pathname,i.search]),(0,Q.useEffect)(()=>{if(!a||!o)return;let t=!1;return _(!0),y(null),c(a).then(e=>{t||m(e)}).catch(n=>{t||y(by(n,e,{key:`organization.errors.invitationNotFound`,defaultValue:`This invitation no longer exists or has expired`}))}).finally(()=>{t||_(!1)}),()=>{t=!0}},[a,o,c,e]),s?(0,$.jsx)(`div`,{className:`flex min-h-svh items-center justify-center`,children:(0,$.jsx)(X,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):o?(0,$.jsx)(`div`,{className:`flex min-h-svh items-center justify-center px-4 py-12 bg-background`,children:(0,$.jsx)(`div`,{className:`w-full max-w-md rounded-xl border bg-card p-8 shadow-sm`,"data-testid":`accept-invitation-page`,children:h?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-8`,children:[(0,$.jsx)(X,{className:`h-8 w-8 animate-spin text-muted-foreground`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`organization.accept.loading`,{defaultValue:`Loading invitation…`})})]}):v?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-8 text-center`,children:[(0,$.jsx)(zr,{className:`h-10 w-10 text-destructive`}),(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.accept.errorTitle`,{defaultValue:`Invitation unavailable`})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:v}),(0,$.jsx)(q,{variant:`outline`,onClick:()=>n(`/organizations`),children:e(`organization.accept.goToOrgs`,{defaultValue:`Go to organizations`})})]}):p?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 text-center`,children:[(0,$.jsx)(`div`,{className:`flex h-14 w-14 items-center justify-center rounded-full bg-primary/10`,children:(0,$.jsx)(wr,{className:`h-7 w-7 text-primary`})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-xl font-bold`,children:e(`organization.accept.title`,{defaultValue:`You have been invited`})}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e(`organization.accept.description`,{defaultValue:`You have been invited to join {{orgName}} as {{role}}.`,orgName:p.organizationName??p.organizationId,role:Oy(p.role,e)})})]}),(0,$.jsxs)(`div`,{className:`w-full rounded-lg border bg-muted/50 p-4 text-left space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.organization`,{defaultValue:`Organization`})}),(0,$.jsx)(`span`,{className:`font-medium`,children:p.organizationName??p.organizationId})]}),(0,$.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.role`,{defaultValue:`Role`})}),(0,$.jsx)(`span`,{className:`font-medium`,"data-testid":`accept-invitation-role`,children:Oy(p.role,e)})]}),p.expiresAt&&(0,$.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.expiresAt`,{defaultValue:`Expires`})}),(0,$.jsx)(`span`,{className:`font-medium`,children:new Date(p.expiresAt).toLocaleDateString(t)})]})]}),(0,$.jsxs)(`div`,{className:`flex w-full gap-3`,children:[(0,$.jsxs)(q,{variant:`outline`,className:`flex-1`,onClick:async()=>{if(a){C(!0);try{await u(a),Y.success(e(`organization.accept.declined`,{defaultValue:`Invitation declined`})),n(`/organizations`)}catch(t){Y.error(by(t,e,{key:`organization.accept.declineFailed`,defaultValue:`Failed to decline invitation`})),C(!1)}}},disabled:S||b,children:[S&&(0,$.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.accept.decline`,{defaultValue:`Decline`})]}),(0,$.jsxs)(q,{className:`flex-1`,onClick:async()=>{if(p&&a){x(!0);try{await l(a),await d(p.organizationId).catch(()=>null),Y.success(e(`organization.accept.accepted`,{defaultValue:`Invitation accepted`})),window.location.href=qd()}catch(t){Y.error(by(t,e,{key:`organization.accept.acceptFailed`,defaultValue:`Failed to accept invitation`})),x(!1)}}},disabled:b||S,children:[b&&(0,$.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}),(0,$.jsx)(Fr,{className:`mr-2 h-4 w-4`}),e(`organization.accept.accept`,{defaultValue:`Accept invitation`})]})]})]}):null})}):null}function Vy({packageId:e,onCanvasOpenChange:t,surfaceLabel:n}){let{tab:r}=f(),i=g(),a=Q.useMemo(()=>{let e=new URLSearchParams(i.search).get(`surface`),t;if(e){let n=e.indexOf(`:`);n>0&&n<e.length-1&&(t={type:e.slice(0,n),name:e.slice(n+1)})}if(r||t)return{...r?{pillar:r}:{},...t?{artifact:t}:{}}},[r,i.search]),o=a?.artifact,s=o&&n&&n.type===o.type&&n.name===o.name&&n.label||void 0,{user:c}=A(),l=c?.id,u=Q.useMemo(()=>km(),[]),{agents:d,isLoading:p,error:m}=Ss({apiBase:u}),h=Q.useMemo(()=>up(`studio-build`,{agents:d}),[d]),_=h?`${u}/agents/${encodeURIComponent(h)}/chat`:void 0,{conversationId:v,initialMessages:y}=Pp({userId:h?l:void 0,scope:h?Rp({appId:e,product:Lp(h)}):void 0,apiBase:u,activeId:void 0,forceNew:!1}),b=Q.useRef(null);return!p&&d.length===0?null:(0,$.jsx)(Gm,{agents:d,agentsLoading:p,agentsError:m,activeAgent:h,chatApi:_,apiBase:u,conversationId:v,editPackageId:e,surfaceContext:a,surfaceArtifactLabel:s,initialMessages:y,pendingFirstMessageRef:b,onSent:()=>{},onShare:()=>{},showDebug:!1,onCanvasOpenChange:t},`${_??`local`}:${v??`pending`}`)}function Hy({packageId:e,locale:t,surfaceLabel:n}){let i=r(),a=g(),o=Q.useMemo(()=>km(),[]),s=Fh({defaultExpanded:!0,persistExpandedKey:Jf,persistWidthKey:Yf}),c=de(),[l,u]=Q.useState(!1),{agents:d,isLoading:f}=Ss({apiBase:o}),p=Q.useCallback(e=>e?s.maximize():s.restore(),[s.maximize,s.restore]),m=Q.useCallback(()=>{rp(`${a.pathname}${a.search}`);try{sessionStorage.setItem(`objectstack:ai-full-page-requested`,`1`)}catch{}i(`/ai/build?package=${encodeURIComponent(e)}`)},[a.pathname,a.search,i,e]);return!f&&d.length===0?null:c?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Bh,{onExpand:()=>u(!0),className:`inline-flex md:hidden`}),(0,$.jsx)(zh,{open:l,onOpenChange:u,title:Z(`engine.studio.aiCopilot`,t),onMaximize:m,children:(0,$.jsx)(Vy,{packageId:e,surfaceLabel:n})})]}):s.expanded?(0,$.jsx)(Rh,{dock:s,title:Z(`engine.studio.aiCopilot`,t),onMaximize:m,children:(0,$.jsx)(Vy,{packageId:e,onCanvasOpenChange:p,surfaceLabel:n})}):(0,$.jsx)(Bh,{onExpand:s.expand})}function Uy(e,t,n){return!t&&n?`properties`:t&&!n?`canvas`:e}var Wy=1280;function Gy(){let[e,t]=Q.useState(void 0);return Q.useEffect(()=>{let e=window.matchMedia(`(min-width: ${Wy}px)`),n=()=>t(window.innerWidth>=Wy);return e.addEventListener(`change`,n),t(window.innerWidth>=Wy),()=>e.removeEventListener(`change`,n)},[]),!!e}var Ky=[`read`,`create`,`update`,`delete`,`transfer`,`restore`,`purge`],qy={grants:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,denies:`border-destructive/40 bg-destructive/10 text-destructive`,narrows:`border-amber-400/50 bg-amber-400/10 text-amber-700 dark:text-amber-300`,widens:`border-sky-400/50 bg-sky-400/10 text-sky-700 dark:text-sky-300`,neutral:`border-border bg-muted/40 text-muted-foreground`,not_applicable:`border-border bg-transparent text-muted-foreground/60`},Jy={admitted:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,excluded:`border-destructive/40 bg-destructive/10 text-destructive`,not_evaluated:`border-border bg-transparent text-muted-foreground/60`},Yy={admits:`bg-emerald-500`,excludes:`bg-destructive`,neutral:`bg-muted-foreground/40`},Xy=e=>{let t=e??{};return String(t.full_name||t.name||t.display_name||t.email||t.id||``)};function Zy({open:e,onOpenChange:t,defaultObject:n,packageId:r}){let i=El(),a=un(),o=Da(),s=Q.useMemo(()=>y(),[]),[c,l]=Q.useState(null);Q.useEffect(()=>{if(!e||!r){l(null);return}let t=!1;return(async()=>{try{let e=(await o.list(`object`,{packageId:r})??[]).map(e=>{let t=e?.item??e;return{name:String(t?.name??``),label:t?.label}}).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));t||l(e)}catch{t||l(null)}})(),()=>{t=!0}},[e,r,o]);let[u,d]=Q.useState(n??``),[f,p]=Q.useState(`read`),[m,h]=Q.useState(null),[g,_]=Q.useState(``),[v,b]=Q.useState(!1),[x,S]=Q.useState(!1),[C,w]=Q.useState(!1),[T,E]=Q.useState(null),[D,O]=Q.useState(null);Q.useEffect(()=>{n&&d(e=>e||n)},[n]);let k=Q.useCallback(async()=>{let e=u.trim();if(e){w(!0),E(null),O(null);try{let t=``.replace(/\/+$/,``),n=await s(`${t}/api/v1/security/explain`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({object:e,operation:f,...m?{userId:m.id}:{},...g.trim()?{recordId:g.trim()}:{}})}),r=null;try{r=await n.json()}catch{}if(n.status===403){E(Z(`engine.studio.access.explain.forbidden`,i));return}if(!n.ok){let e=r?.message||r?.error||`HTTP ${n.status} ${n.statusText}`.trim();E(e);return}O(r)}catch(e){E(e?.message??String(e))}finally{w(!1)}}},[s,u,f,m,g,i]),A=e=>Z(`engine.studio.access.explain.op.${e}`,i);return(0,$.jsx)(ht,{open:e,onOpenChange:t,children:(0,$.jsxs)(ke,{side:`right`,className:`w-full overflow-y-auto sm:max-w-xl`,children:[(0,$.jsxs)(G,{children:[(0,$.jsxs)(H,{className:`flex items-center gap-2`,children:[(0,$.jsx)(Zi,{className:`h-4 w-4`}),` `,Z(`engine.studio.access.explain.title`,i)]}),(0,$.jsx)(je,{children:Z(`engine.studio.access.explain.description`,i)})]}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-3 text-sm`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.user`,i)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>b(!0),className:`flex h-8 min-w-0 flex-1 items-center gap-2 rounded-md border bg-background px-2 text-left text-xs hover:bg-muted/60`,children:[(0,$.jsx)(ha,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:m?m.label:Z(`engine.studio.access.explain.self`,i)}),(0,$.jsx)(Nr,{className:`h-3 w-3 shrink-0 text-muted-foreground/70`})]}),m&&(0,$.jsx)(q,{variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>h(null),"aria-label":Z(`engine.studio.access.explain.clearUser`,i),title:Z(`engine.studio.access.explain.clearUser`,i),children:(0,$.jsx)(ba,{className:`h-4 w-4`})})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`explain-object`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.object`,i)}),c&&c.length>0?(0,$.jsxs)(`select`,{id:`explain-object`,value:u,onChange:e=>d(e.target.value),className:`h-8 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-1 focus:ring-primary`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.access.explain.objectSelect`,i)}),c.map(e=>(0,$.jsx)(`option`,{value:e.name,children:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name},e.name))]}):(0,$.jsx)(K,{id:`explain-object`,value:u,onChange:e=>d(e.target.value),placeholder:Z(`engine.studio.access.explain.objectPlaceholder`,i),className:`h-8 text-xs`})]}),(0,$.jsxs)(`div`,{className:`w-32 shrink-0 space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`explain-operation`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.operation`,i)}),(0,$.jsx)(`select`,{id:`explain-operation`,value:f,onChange:e=>p(e.target.value),className:`h-8 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-1 focus:ring-primary`,children:Ky.map(e=>(0,$.jsx)(`option`,{value:e,children:A(e)},e))})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`explain-record`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.record`,i)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(K,{id:`explain-record`,value:g,onChange:e=>_(e.target.value),placeholder:Z(`engine.studio.access.explain.recordPlaceholder`,i),className:`h-8 min-w-0 flex-1 text-xs`}),(0,$.jsxs)(q,{type:`button`,variant:`outline`,size:`sm`,className:`h-8 shrink-0 gap-1 text-xs`,disabled:!u.trim(),onClick:()=>S(!0),title:Z(`engine.studio.access.explain.pickRecord`,i),children:[(0,$.jsx)(Nr,{className:`h-3 w-3`}),Z(`engine.studio.access.explain.pickRecord`,i)]}),g&&(0,$.jsx)(q,{variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>_(``),"aria-label":Z(`engine.studio.access.explain.clearRecord`,i),title:Z(`engine.studio.access.explain.clearRecord`,i),children:(0,$.jsx)(ba,{className:`h-4 w-4`})})]})]}),(0,$.jsxs)(q,{size:`sm`,className:`h-8 gap-1.5 text-xs`,disabled:C||!u.trim(),onClick:()=>void k(),children:[C?(0,$.jsx)(X,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Lr,{className:`h-3.5 w-3.5`}),Z(C?`engine.studio.access.explain.running`:`engine.studio.access.explain.run`,i)]})]}),(0,$.jsxs)(`div`,{className:`mt-5 space-y-4 text-sm`,children:[T&&!C&&(0,$.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 p-3 text-xs text-destructive`,children:[(0,$.jsx)(ua,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:Z(`engine.studio.access.explain.failed`,i)}),` — `,T]})]}),!D&&!T&&!C&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Z(`engine.studio.access.explain.empty`,i)}),D&&!C&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{"data-testid":`explain-verdict`,className:D.allowed?`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/10 p-3 text-emerald-700 dark:text-emerald-400`:`flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive`,children:[D.allowed?(0,$.jsx)(Ir,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(zr,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:Dl(D.allowed?`engine.studio.access.explain.allowedLine`:`engine.studio.access.explain.deniedLine`,i,{operation:A(D.operation),object:D.object})})]}),D.record&&(0,$.jsxs)(`div`,{"data-testid":`explain-record-verdict`,className:D.record.visible?`flex items-start gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 p-3 text-emerald-700 dark:text-emerald-400`:`flex items-start gap-2 rounded-md border border-destructive/30 bg-destructive/5 p-3 text-destructive`,children:[D.record.visible?(0,$.jsx)(Ir,{className:`mt-0.5 h-4 w-4 shrink-0`}):(0,$.jsx)(zr,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0 text-xs`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:Dl(D.record.visible?`engine.studio.access.explain.recordVisibleLine`:`engine.studio.access.explain.recordHiddenLine`,i,{recordId:D.record.recordId})}),D.record.decidedBy&&(0,$.jsxs)(`div`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.decidedBy`,i),`:`,` `,(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:Z(`engine.studio.access.explain.layer.${D.record.decidedBy}`,i)})]})]})]}),(0,$.jsxs)(`div`,{className:`rounded-md border bg-muted/30 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.principal`,i)}),D.principal.posture&&(0,$.jsx)(pt,{variant:`outline`,"data-testid":`explain-posture`,className:`px-1.5 py-0 text-[10px] font-medium`,title:Z(`engine.studio.access.explain.postureHint`,i),children:Z(`engine.studio.access.explain.posture.${D.principal.posture}`,i)})]}),(0,$.jsxs)(`p`,{className:`mt-1 truncate font-mono text-xs text-foreground`,children:[D.principal.userId??`(anonymous)`,D.principal.onBehalfOf?.userId?` ⇄ ${D.principal.onBehalfOf.userId}`:``]}),(0,$.jsxs)(`div`,{className:`mt-2 space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.positions`,i),`:`]}),(D.principal.positions??[]).map(e=>(0,$.jsx)(pt,{variant:`outline`,className:`px-1.5 py-0 text-[10px] font-normal`,children:e},e))]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.permissionSets`,i),`:`]}),(D.principal.permissionSets??[]).map(e=>(0,$.jsx)(pt,{variant:`secondary`,className:`px-1.5 py-0 text-[10px] font-normal`,children:e},e))]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.layers`,i)}),(0,$.jsx)(`ol`,{className:`space-y-2`,children:D.layers.map(e=>(0,$.jsxs)(`li`,{className:`rounded-md border p-2.5`,"data-testid":`explain-layer-${e.layer}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium`,children:Z(`engine.studio.access.explain.layer.${e.layer}`,i)}),(0,$.jsx)(`span`,{className:`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none ${qy[e.verdict]??qy.neutral}`,children:Z(`engine.studio.access.explain.verdict.${e.verdict}`,i)}),e.kernelTier&&(0,$.jsx)(`span`,{className:`shrink-0 rounded border border-border bg-muted/40 px-1.5 py-0.5 text-[9px] uppercase leading-none text-muted-foreground`,title:Z(`engine.studio.access.explain.kernelTierHint`,i),children:Z(`engine.studio.access.explain.kernelTier.${e.kernelTier}`,i)})]}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-muted-foreground`,children:e.detail}),(e.contributors??[]).length>0&&(0,$.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1`,children:[(0,$.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:[Z(`engine.studio.access.explain.contributors`,i),`:`]}),(e.contributors??[]).map((e,t)=>(0,$.jsx)(pt,{variant:e.kind===`position`?`outline`:`secondary`,className:`px-1.5 py-0 text-[10px] font-normal`,title:e.via?`${e.kind} · via ${e.via}`:e.kind,children:e.name},`${e.kind}:${e.name}:${t}`))]}),e.record&&(0,$.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded border border-dashed border-border/70 bg-muted/20 p-2`,"data-testid":`explain-record-${e.layer}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-medium uppercase text-muted-foreground/70`,children:Z(`engine.studio.access.explain.recordOutcome`,i)}),(0,$.jsx)(`span`,{className:`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none ${Jy[e.record.outcome]??Jy.not_evaluated}`,children:Z(`engine.studio.access.explain.outcome.${e.record.outcome}`,i)}),e.record.matchesRecord!=null&&(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:Z(e.record.matchesRecord?`engine.studio.access.explain.matches`:`engine.studio.access.explain.noMatch`,i)})]}),e.record.detail&&(0,$.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:e.record.detail}),(e.record.rules??[]).length>0&&(0,$.jsx)(`ul`,{className:`space-y-1`,children:(e.record.rules??[]).map((e,t)=>(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${Yy[e.effect]??Yy.neutral}`,title:e.effect}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:Z(`engine.studio.access.explain.ruleKind.${e.kind}`,i)}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,title:e.name,children:e.name}),e.grants&&(0,$.jsx)(pt,{variant:`secondary`,className:`px-1 py-0 text-[9px] font-normal`,children:e.grants}),e.via&&(0,$.jsxs)(`span`,{className:`min-w-0 truncate text-[10px] text-muted-foreground/70`,children:[`· `,e.via]})]},`${e.kind}:${e.name}:${t}`))}),e.record.rowFilter!==void 0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-muted-foreground/70`,children:Z(`engine.studio.access.explain.effectiveRowFilter`,i)}),(0,$.jsx)(`pre`,{className:`mt-0.5 overflow-x-auto rounded border bg-background/60 p-1.5 font-mono text-[10px] leading-snug`,children:JSON.stringify(e.record.rowFilter,null,2)})]})]})]},e.layer))})]}),D.operation===`read`&&D.readFilter!==void 0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.readFilter`,i)}),(0,$.jsx)(`pre`,{className:`overflow-x-auto rounded-md border bg-muted/30 p-2 font-mono text-[11px] leading-snug`,children:JSON.stringify(D.readFilter,null,2)})]})]})]}),(0,$.jsx)(Ee,{open:v,onOpenChange:e=>b(e),dataSource:a,objectName:`sys_user`,title:Z(`engine.studio.access.explain.pickUserTitle`,i),onSelect:()=>{},onSelectRecords:e=>{let t=e?.[0];t?.id!=null&&h({id:String(t.id),label:Xy(t)}),b(!1)}}),u.trim()&&(0,$.jsx)(Ee,{open:x,onOpenChange:e=>S(e),dataSource:a,objectName:u.trim(),title:Z(`engine.studio.access.explain.pickRecordTitle`,i),onSelect:()=>{},onSelectRecords:e=>{let t=e?.[0];t?.id!=null&&_(String(t.id)),S(!1)}})]})})}var Qy=`~org`,$y=`automations`;function eb(e){return e===Qy}function tb(e){let t=`/studio/${Qy}/${$y}`;return e?`${t}?${qc}=${encodeURIComponent(Jc(e))}`:t}var nb=`sys_metadata`;function rb(e){return typeof e==`string`&&e!==``&&e!==nb}function ib(e){return!rb(e?._packageId)}function ab(e){return!rb(e?.packageId)}function ob(e){return te(e.type)===`flow`&&ab(e)}async function sb(e,t,n){let[r,i]=await Promise.all([e.list(t,{packageId:n}),e.listDrafts({packageId:n,type:t}).catch(()=>[])]);return lb(t,r,i)}async function cb(e,t){let[n,r]=await Promise.all([e.list(t),e.listDrafts({type:t}).catch(()=>[])]);return lb(t,(n||[]).filter(e=>ib(e)),(r||[]).filter(e=>ab(e)))}function lb(e,t,n){let r=(t||[]).map(t=>({type:e,name:String(t.name??``),label:String(t.label??t.name??``)})).filter(e=>e.name),i=new Set(r.map(e=>e.name));for(let t of n||[]){let n=String(t?.name??``);n&&!i.has(n)&&(r.push({type:e,name:n,label:n}),i.add(n))}return r}function ub(e=!1){let[t,n]=(0,Q.useState)(0),[r,i]=(0,Q.useState)(0);return(0,Q.useEffect)(()=>Ba(()=>n(e=>e+1)),[]),(0,Q.useEffect)(()=>{e||i(e=>e===t?e:t)},[e,t]),r}function db(e,t,n){let r=lo(e,t,n);switch(e.type){case`page`:return e.pageName?{type:`page`,name:String(e.pageName),label:r}:null;case`object`:return e.objectName?{type:`object`,name:String(e.objectName),label:r}:null;case`dashboard`:return e.dashboardName?{type:`dashboard`,name:String(e.dashboardName),label:r}:null;case`report`:return e.reportName?{type:`report`,name:String(e.reportName),label:r}:null;case`action`:return e.actionDef?.actionName?{type:`action`,name:String(e.actionDef.actionName),label:r}:null;default:return null}}function fb(e,t,n,r){for(let i of e)if(i.type===`group`||i.children?.length){let e=fb(i.children??[],t,n,r);if(e)return e}else{let e=db(i,n,r);if(e&&e.type===t.type&&e.name===t.name)return e}return null}function pb(e){let[t,n]=l(),r=Q.useRef(Kc(t.get(qc))),i=e?.type,a=e?.name;return Q.useEffect(()=>{i&&a&&n(e=>{let t=new URLSearchParams(e);return t.set(qc,Jc({type:i,name:a})),t},{replace:!0})},[i,a]),r.current}function mb(e,t,n){if(t&&t.type===n)return e.find(e=>e.name===t.name)}function hb(e,t,n,r){return{name:e,label:t,sharingModel:r,fields:{name:{type:`text`,label:n}}}}function gb(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 _b(e,t,n=[]){return{name:e,label:t,active:!0,navigation:n.map(e=>({id:`nav_${e.name}`,type:`object`,objectName:e.name}))}}function vb(e,t){return{name:e,label:t,objects:{},fields:{}}}var yb={private:0,public_read:1,public_read_write:2};function bb(e,t){return!!t&&t in yb&&!!e&&e in yb&&yb[t]>yb[e]}function xb(e){for(let t of el(e).entries)if((t.def.type??``)===`master_detail`){let e=t.def.reference;if(typeof e==`string`&&e)return e}}var Sb=[`private`,`public_read`,`public_read_write`],Cb=`private`;function wb({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]=Q.useState(``),[_,v]=Q.useState(``),[y,b]=Q.useState(!1);Q.useEffect(()=>{e&&(g(``),v(``),b(!1))},[e]);let x=ll((_.trim()||h).trim()),S=!!h.trim()&&!!x&&x!==`field`,C=()=>{S&&!u&&m({label:h.trim(),name:x})};return(0,$.jsx)(gt,{open:e,onOpenChange:t,children:(0,$.jsxs)(Ae,{children:[(0,$.jsxs)(U,{children:[(0,$.jsx)(Ce,{children:n}),r&&(0,$.jsx)(Me,{children:r})]}),(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(z,{children:i}),(0,$.jsx)(K,{autoFocus:!0,value:h,onChange:e=>{g(e.target.value),y||v(fl(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&C()},placeholder:a})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(z,{children:o}),(0,$.jsx)(K,{className:`font-mono`,value:_,onChange:e=>{b(!0),v(fl(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&C()},placeholder:s})]}),p,d&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:d})]}),(0,$.jsxs)(Pe,{children:[(0,$.jsx)(q,{variant:`outline`,onClick:()=>t(!1),disabled:u,children:Z(`engine.studio.cancel`,f)}),(0,$.jsx)(q,{onClick:C,disabled:!S||u,children:u?l??c:c})]})]})})}function Tb(e){return e.startsWith(`field:`)?e:ye(e)}var Eb=`__ungrouped__`,Db=e=>`g:${e}`,Ob=e=>`f:${e}`,kb=e=>e.slice(2),Ab=e=>e.slice(2);function jb({type:e}){let t=El(),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,$.jsxs)(`div`,{className:`${n} h-7 justify-between`,children:[(0,$.jsx)(`span`,{children:Z(e===`lookup`||e===`reference`||e===`user`?`engine.studio.designer.search`:`engine.studio.designer.select`,t)}),(0,$.jsx)(`span`,{children:`▾`})]});case`textarea`:case`html`:case`markdown`:case`json`:case`code`:return(0,$.jsx)(`div`,{className:`${n} h-14 items-start pt-1.5`,children:`…`});case`boolean`:case`checkbox`:case`switch`:return(0,$.jsx)(`div`,{className:`mt-1 flex items-center`,children:(0,$.jsx)(`span`,{className:`h-4 w-7 rounded-full bg-muted`})});case`number`:case`currency`:case`percent`:return(0,$.jsx)(`div`,{className:`${n} h-7`,children:`0.00`});case`date`:case`datetime`:case`time`:return(0,$.jsx)(`div`,{className:`${n} h-7`,children:Z(`engine.studio.designer.pickDate`,t)});default:return(0,$.jsx)(`div`,{className:`${n} h-7`,children:`\xA0`})}}function Mb({entry:e,label:t,columns:n,selected:r,onSelect:i}){let a=El(),{attributes:o,listeners:s,setNodeRef:c,transform:l,transition:u,isDragging:d}=Ac({id:Ob(e.name)}),f=String(e.def.type??`text`),p=!!e.def.required,m=n>1&&Ma(Tb(f));return(0,$.jsxs)(`div`,{ref:c,style:{transform:Fc.Transform.toString(l),transition:u},onClick:i,...o,...s,"aria-label":Dl(`engine.studio.designer.fieldAria`,a,{label:t}),className:`group relative flex cursor-grab touch-none select-none items-start gap-1.5 rounded-md border bg-background px-2 py-2 active:cursor-grabbing `+(m?`col-span-full `:``)+(r?`ring-2 ring-primary`:`hover:border-foreground/25`)+(d?` opacity-40`:``),children:[(0,$.jsx)(`span`,{className:`mt-0.5 text-muted-foreground opacity-0 group-hover:opacity-100`,children:(0,$.jsx)(ai,{className:`h-3.5 w-3.5`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 text-xs font-medium`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:t}),p&&(0,$.jsx)(`span`,{className:`text-destructive`,children:`*`}),(0,$.jsx)(`span`,{className:`ml-1 text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:f})]}),(0,$.jsx)(jb,{type:f})]})]})}function Nb({containerId:e,title:t,fieldIds:n,columns:r,isDeclared:i,canMoveUp:a,canMoveDown:o,entryByName:s,fieldLabelOf:c,selectedField:l,onSelectField:u,selected:d=!1,onSelect:f,onRename:p,onDelete:m,onMove:h,readOnly:g=!1}){let _=El(),{setNodeRef:v,isOver:y}=Ec({id:e});return(0,$.jsxs)(`div`,{className:`@container rounded-lg border `+(y?`border-primary bg-primary/5`:d?`border-primary/50 bg-primary/5 ring-2 ring-primary`:`bg-muted/20`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-3 py-1.5`,children:[i&&!g?(0,$.jsx)(`input`,{defaultValue:t,onBlur:e=>e.target.value.trim()&&e.target.value!==t&&p(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,$.jsx)(`span`,{className:`flex-1 px-1 text-[13px] font-medium text-muted-foreground`,children:t}),i&&f&&(0,$.jsx)(`button`,{type:`button`,onClick:f,"aria-label":Z(`engine.studio.designer.group.settings`,_),title:Z(`engine.studio.designer.group.settings`,_),className:`rounded p-0.5 hover:bg-muted `+(d?`text-primary`:`text-muted-foreground hover:text-foreground`),children:(0,$.jsx)(Ki,{className:`h-3.5 w-3.5`})}),i&&!g&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,disabled:!a,onClick:()=>h(-1),"aria-label":Z(`engine.studio.designer.groupUp`,_),className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,$.jsx)(Mr,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,disabled:!o,onClick:()=>h(1),"aria-label":Z(`engine.studio.designer.groupDown`,_),className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,$.jsx)(Ar,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:m,"aria-label":Z(`engine.studio.designer.groupDelete`,_),title:Z(`engine.studio.designer.groupDeleteTitle`,_),className:`rounded p-0.5 text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,children:(0,$.jsx)(la,{className:`h-3.5 w-3.5`})})]})]}),(0,$.jsx)(Mc,{items:n,strategy:jc,children:(0,$.jsxs)(`div`,{ref:v,className:`min-h-[52px] p-2.5 `+(Fa(r)??`grid grid-cols-1 gap-4`),children:[n.length===0&&(0,$.jsx)(`div`,{className:`col-span-full flex items-center justify-center rounded-md border border-dashed py-3 text-[11px] text-muted-foreground`,children:Z(`engine.studio.designer.dropHere`,_)}),n.map(e=>{let t=Ab(e),n=s.get(t);return n?(0,$.jsx)(Mb,{entry:n,label:c(n),columns:r,selected:l===t,onSelect:()=>u(t)},e):null})]})})]})}function Pb({draft:e,objectName:t,systemFieldNames:n,onChange:r,selectedField:i,onSelectField:a,onAddField:o,selectedGroup:s,onSelectGroup:c,readOnly:l=!1}){let u=El(),d=Q.useMemo(()=>el(e.fields),[e.fields]),f=Q.useMemo(()=>Xc(e.fieldGroups),[e.fieldGroups]),p=Q.useMemo(()=>new Map(d.entries.map(e=>[e.name,e])),[d]),{fieldLabel:m,sectionLabel:h}=$n(),g=t||(typeof e.name==`string`?e.name:``),_=Q.useCallback(e=>{let t=String(e.def.label??e.name);return g?m(g,e.name,t):t},[g,m]),v=Q.useMemo(()=>La(d.entries.filter(e=>!n.has(e.name)).length),[d.entries,n]),y=Q.useMemo(()=>[...f.map(e=>Db(e.key)),Db(Eb)],[f]),b=Q.useMemo(()=>{let e=new Map;for(let t of f){let n=t.label||t.key;e.set(Db(t.key),g?h(g,t.key,n):n)}return e.set(Db(Eb),Z(`engine.studio.designer.ungrouped`,u)),e},[f,u,g,h]),x=Q.useMemo(()=>{let e={};for(let t of y)e[t]=[];for(let t of d.entries){if(n.has(t.name))continue;let r=typeof t.def.group==`string`?t.def.group:``;e[r&&e[Db(r)]?Db(r):Db(Eb)].push(Ob(t.name))}return e},[d.entries,y,n]),[S,C]=Q.useState(x),[w,T]=Q.useState(null);Q.useEffect(()=>{w||C(x)},[x,w]);let E=Q.useRef(S);Q.useEffect(()=>{E.current=S},[S]);let D=Pc(Sc(Tc,{activationConstraint:{distance:4}}),Sc(Nc,{coordinateGetter:Cc})),O=Q.useCallback(e=>e.startsWith(`g:`)?e:Object.keys(S).find(t=>S[t].includes(e)),[S]),k=Q.useCallback(e=>{let t=[];for(let n of y){let r=kb(n);for(let i of e[n]??[]){let e=p.get(Ab(i));if(!e)continue;let n={...e.def};r===Eb?delete n.group:n.group=r,t.push({name:e.name,def:n})}}let i=d.entries.filter(e=>n.has(e.name)),a={shape:d.shape,entries:[...i,...t]};r({fields:al(a)})},[y,p,d,n,r]),A=e=>T(String(e.active.id)),j=e=>{let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=O(t),i=O(n);r&&i&&r!==i&&C(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)]}})},M=e=>{T(null);let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=E.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){k(r);return}s={...r,[a]:kc(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)]}}C(s),k(s)},N=()=>r({fieldGroups:Zc(f,Z(`engine.studio.designer.newGroup`,u))}),ee=(e,t)=>r({fieldGroups:pl(f,e,t)}),P=(e,t)=>r({fieldGroups:rl(f,e,t)}),F=e=>r({fieldGroups:sl(f,e),fields:al(Qc(d,e))}),te=w&&!w.startsWith(`g:`)?p.get(Ab(w)):null;return(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background p-4`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(Ui,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.designer.hint`,u)]}),!l&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:N,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,$.jsx)(Ri,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.designer.addGroup`,u)]}),o&&(0,$.jsxs)(`button`,{type:`button`,onClick:o,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,$.jsx)(Ri,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.addField`,u)]})]})]}),(0,$.jsxs)(wc,{sensors:l?[]:D,collisionDetection:Dc,onDragStart:A,onDragOver:j,onDragEnd:M,onDragCancel:()=>T(null),children:[(0,$.jsx)(`div`,{className:`mx-auto flex max-w-6xl flex-col gap-3`,children:y.map(e=>{let t=e===Db(Eb);if(t&&(S[e]?.length??0)===0&&f.length>0)return null;let n=f.findIndex(t=>Db(t.key)===e);return(0,$.jsx)(Nb,{containerId:e,title:b.get(e)??Z(`engine.studio.designer.ungrouped`,u),fieldIds:S[e]??[],columns:v,isDeclared:!t,canMoveUp:n>0,canMoveDown:n>=0&&n<f.length-1,entryByName:p,fieldLabelOf:_,selectedField:i,onSelectField:a,selected:!t&&s===kb(e),onSelect:!t&&c?()=>c(kb(e)):void 0,onRename:t=>ee(kb(e),t),onDelete:()=>F(kb(e)),onMove:t=>P(kb(e),t),readOnly:l},e)})}),(0,$.jsx)(Oc,{children:te?(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border bg-background px-2 py-2 shadow-lg`,children:[(0,$.jsx)(ai,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:_(te)})]}):null})]})]})}function Fb({draft:e,groupKey:t,onPatch:n,onClose:r,readOnly:i=!1,locale:a}){let o=Q.useCallback(e=>Z(e,a),[a]),s=Q.useMemo(()=>Xc(e.fieldGroups),[e.fieldGroups]),c=s.find(e=>e.key===t);if(!c)return(0,$.jsx)(kl,{kindLabel:o(`engine.studio.designer.group.kind`),title:t,onClose:r,closeLabel:o(`engine.studio.close`),children:(0,$.jsx)(Al,{message:o(`engine.studio.designer.group.missing`)})});let l=c.collapse??(c.collapsed?`collapsed`:c.collapsible?`expanded`:`none`),u=e=>n({fieldGroups:cl(s,c.key,{collapse:e===`none`?void 0:e,collapsible:void 0,collapsed:void 0,defaultExpanded:void 0})});return(0,$.jsxs)(kl,{kindLabel:o(`engine.studio.designer.group.kind`),title:c.label||c.key,onClose:r,closeLabel:o(`engine.studio.close`),children:[(0,$.jsx)(Ml,{label:o(`engine.studio.designer.group.nameLabel`),value:c.label,onCommit:e=>n({fieldGroups:cl(s,c.key,{label:e})}),disabled:i,testId:`group-label`}),(0,$.jsx)(jl,{label:o(`engine.studio.designer.group.collapseLabel`),value:l,onCommit:e=>u(e||`none`),disabled:i,options:[{value:`none`,label:o(`engine.studio.designer.group.collapseNone`)},{value:`expanded`,label:o(`engine.studio.designer.group.collapseExpanded`)},{value:`collapsed`,label:o(`engine.studio.designer.group.collapseCollapsed`)}]}),(0,$.jsx)(`p`,{className:`text-[11px] leading-4 text-muted-foreground`,children:o(`engine.studio.designer.group.collapseHint`)})]})}var Ib=[{value:`script`,labelKey:`engine.studio.rules.typeScript`},{value:`cross_field`,labelKey:`engine.studio.rules.typeCrossField`},{value:`state_machine`,labelKey:`engine.studio.rules.typeStateMachine`},{value:`format`,labelKey:`engine.studio.rules.typeFormat`},{value:`json_schema`,labelKey:`engine.studio.rules.typeJsonSchema`},{value:`conditional`,labelKey:`engine.studio.rules.typeConditional`}],Lb=[`insert`,`update`,`delete`],Rb=[``,`url`,`email`,`phone`,`json`];function zb(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`):[]}function Bb(e){let t=e.length+1,n=`validation_${t}`,r=new Set(e);for(;r.has(n);)n=`validation_${++t}`;return n}function Vb(e){return e===`conditional`?`when`:`condition`}function Hb(e,t,n){let r={name:t,message:``,severity:`error`,active:!0};switch(e){case`script`:return{...r,type:e,condition:`false`};case`cross_field`:return{...r,type:e,condition:`false`,fields:n?[n]:[]};case`state_machine`:return{...r,type:e,field:n??``,transitions:{}};case`format`:return{...r,type:e,field:n??``};case`json_schema`:return{...r,type:e,field:n??``,schema:{}};case`conditional`:return{...r,type:e,when:`false`,then:{type:`script`,name:`${t}_then`,message:``,condition:`false`,severity:`error`}}}}function Ub({label:e,value:t,onCommit:n,disabled:r,locale:i}){let a=Q.useMemo(()=>{if(t==null)return``;try{return JSON.stringify(t,null,2)}catch{return``}},[t]),[o,s]=Q.useState(a),[c,l]=Q.useState(null);return Q.useEffect(()=>{s(a),l(null)},[a]),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:e}),(0,$.jsx)(`textarea`,{value:o,disabled:r,spellCheck:!1,rows:5,onChange:e=>s(e.target.value),onBlur:()=>{let e=o.trim();if(!e){l(null),n(void 0);return}try{n(JSON.parse(e)),l(null)}catch{l(Z(`engine.studio.rules.invalidJson`,i))}},className:`w-full rounded border bg-background px-2 py-1 font-mono text-[11px]`}),c&&(0,$.jsx)(`span`,{className:`mt-1 block text-[11px] text-destructive`,children:c})]})}function Wb({transitions:e,onCommit:t,disabled:n,locale:r}){let i=Object.entries(e),a=(e,n,r)=>{let a={};i.forEach(([t,i],o)=>{o===e?n&&(a[n]=r):a[t]=i}),t(a)};return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.transitions`,r)}),i.map(([e,t],i)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`input`,{value:e,disabled:n,placeholder:Z(`engine.studio.rules.transitionFrom`,r),onChange:e=>a(i,e.target.value,t),className:`w-32 rounded border bg-background px-2 py-1 text-[12px]`}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,$.jsx)(`input`,{value:t.join(`, `),disabled:n,placeholder:Z(`engine.studio.rules.transitionTo`,r),onChange:t=>a(i,e,t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)),className:`min-w-0 flex-1 rounded border bg-background px-2 py-1 text-[12px]`}),!n&&(0,$.jsx)(`button`,{type:`button`,"aria-label":Z(`engine.studio.rules.delete`,r),onClick:()=>a(i,``,[]),className:`rounded border border-destructive/40 p-1 text-destructive hover:bg-destructive/10`,children:(0,$.jsx)(la,{className:`h-3 w-3`})})]},i)),!n&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>t({...e,"":[]}),disabled:``in e,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[(0,$.jsx)(Ri,{className:`h-3 w-3`}),` `,Z(`engine.studio.rules.addTransition`,r)]})]})}function Gb({rule:e,fields:t,patch:n,disabled:r,locale:i,onBlockingIssuesChange:a}){let o=(e,n,a)=>(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:e}),(0,$.jsxs)(`select`,{value:n??``,disabled:r,onChange:e=>a(e.target.value),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.rules.pickField`,i)}),t.map(e=>(0,$.jsx)(`option`,{value:e.name,children:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name},e.name))]})]}),s=Vb(e.type),c=(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:[Z(`engine.studio.rules.celPre`,i),(0,$.jsx)(`b`,{children:Z(`engine.studio.rules.celTrue`,i)}),Z(`engine.studio.rules.celMid`,i),(0,$.jsx)(`code`,{className:`rounded bg-muted px-1`,children:`false`}),Z(`engine.studio.rules.celPost`,i)]}),(0,$.jsx)($c,{value:ml(e[s]),onCommit:t=>n({[s]:ol(e[s],t)}),fields:t,disabled:r,scope:`record`,subjects:{context:tl},onBlockingIssuesChange:a})]});switch(e.type){case`script`:return c;case`cross_field`:{let a=Array.isArray(e.fields)?e.fields:[],o=(e,t)=>n({fields:t?[...new Set([...a,e])]:a.filter(t=>t!==e)});return(0,$.jsxs)($.Fragment,{children:[c,(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.fields`,i)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2 rounded border p-2`,children:[t.length===0&&(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.noFields`,i)}),t.map(e=>(0,$.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px]`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:a.includes(e.name),disabled:r,onChange:t=>o(e.name,t.target.checked)}),e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name]},e.name))]})]})]})}case`state_machine`:return(0,$.jsxs)($.Fragment,{children:[o(Z(`engine.studio.rules.statusField`,i),e.field,e=>n({field:e})),(0,$.jsx)(Wb,{transitions:e.transitions&&typeof e.transitions==`object`?e.transitions:{},onCommit:e=>n({transitions:e}),disabled:r,locale:i})]});case`format`:return(0,$.jsxs)($.Fragment,{children:[o(Z(`engine.studio.rules.field`,i),e.field,e=>n({field:e})),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.format`,i)}),(0,$.jsx)(`select`,{value:typeof e.format==`string`?e.format:``,disabled:r,onChange:e=>n({format:e.target.value||void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:Rb.map(e=>(0,$.jsx)(`option`,{value:e,children:e||Z(`engine.studio.rules.formatNone`,i)},e||`none`))})]}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.regex`,i)}),(0,$.jsx)(`input`,{value:typeof e.regex==`string`?e.regex:``,disabled:r,placeholder:`^[A-Z]{2}\\\\d{4}$`,onChange:e=>n({regex:e.target.value||void 0}),className:`w-full rounded border bg-background px-2 py-1 font-mono text-[12px]`})]})]});case`json_schema`:return(0,$.jsxs)($.Fragment,{children:[o(Z(`engine.studio.rules.field`,i),e.field,e=>n({field:e})),(0,$.jsx)(Ub,{label:Z(`engine.studio.rules.jsonSchema`,i),value:e.schema,onCommit:e=>n({schema:e??{}}),disabled:r,locale:i})]});case`conditional`:return(0,$.jsxs)($.Fragment,{children:[c,(0,$.jsx)(Ub,{label:Z(`engine.studio.rules.then`,i),value:e.then,onCommit:e=>n({then:e}),disabled:r,locale:i}),(0,$.jsx)(Ub,{label:Z(`engine.studio.rules.otherwise`,i),value:e.otherwise,onCommit:e=>n({otherwise:e}),disabled:r,locale:i})]});default:return null}}function Kb({draft:e,onPatch:t,disabled:n,onBlockingIssuesChange:r}){let i=El(),a=Q.useMemo(()=>zb(e.validations),[e.validations]),[o,s]=Q.useState(null),[c,l]=Q.useState(!1),u=a.some(e=>e.name===o)?o:a[0]?.name??null,d=Q.useMemo(()=>el(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]),f=d.find(e=>!e.hidden)?.name??d[0]?.name,[p,m]=Q.useState({}),h=Q.useCallback((e,t)=>{m(n=>n[e]===t?n:{...n,[e]:t})},[]),g=Q.useMemo(()=>new Set(a.map(e=>e.name??``)),[a]),_=Q.useMemo(()=>{let e=0;for(let[t,n]of Object.entries(p))g.has(t)&&(e+=n);return e},[p,g]),v=Q.useRef(r);Q.useEffect(()=>{v.current=r}),Q.useEffect(()=>{v.current?.(_)},[_]);let y=e=>t({validations:e}),b=(e,t)=>y(a.map(n=>n.name===e?{...n,...t}:n)),x=e=>{let t=Bb(a.map(e=>e.name??``));y([...a,Hb(e,t,f)]),s(t)},S=e=>{y(a.filter(t=>t.name!==e)),o===e&&s(null)},C=a.find(e=>e.name===u)??null,w=typeof C?.type==`string`?C.type:`script`,T=(e,t)=>{let n=a.find(t=>t.name===e);if(!n)return;let r=Hb(t,e,f),i=Vb(n.type),o=Vb(t);(t===`script`||t===`cross_field`||t===`conditional`)&&ml(n[i])&&(r[o]=n[i]);for(let e of[`label`,`description`,`message`,`severity`,`active`,`events`,`priority`])n[e]!==void 0&&(r[e]=n[e]);y(a.map(t=>t.name===e?r:t))};return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(Yi,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.rules.title`,i)}),(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,a.length,`)`]}),!n&&(0,$.jsxs)(Te,{open:c,onOpenChange:l,children:[(0,$.jsx)(we,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:`ml-auto inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[(0,$.jsx)(Ri,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,i),(0,$.jsx)(Ar,{className:`h-3 w-3 text-muted-foreground`})]})}),(0,$.jsxs)(Ot,{align:`end`,sideOffset:4,className:`w-56 p-1`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1 pt-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.rules.newType`,i)}),Ib.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>{x(e.value),l(!1)},className:`flex w-full items-center rounded-md px-2 py-1.5 text-left text-[12px] hover:bg-muted`,children:Z(e.labelKey,i)},e.value))]})]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:a.length===0?(0,$.jsxs)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:[Z(`engine.studio.rules.none`,i),(0,$.jsx)(`br`,{}),Z(`engine.studio.rules.explain`,i)]}):a.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name??null),className:`flex w-full items-start gap-2 border-b px-3 py-2 text-left text-[12px] `+(u===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate font-medium`,children:e.label||e.name}),(0,$.jsx)(`span`,{className:`block truncate text-[11px] text-muted-foreground`,children:e.message||Z(`engine.studio.rules.noMessage`,i)})]}),(0,$.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] text-primary`,children:e.type??`script`})]},e.name))})]}),(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col rounded-lg border`,children:C?(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-auto p-4`,children:[(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.type`,i)}),(0,$.jsx)(`select`,{value:w,disabled:n,onChange:e=>T(C.name,e.target.value),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:Ib.map(e=>(0,$.jsx)(`option`,{value:e.value,children:Z(e.labelKey,i)},e.value))})]}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.nameLabel`,i)}),(0,$.jsx)(`input`,{value:C.name??``,disabled:n,onChange:e=>{let t=e.target.value;b(C.name,{name:t}),s(t)},className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.label`,i)}),(0,$.jsx)(`input`,{value:C.label??``,disabled:n,onChange:e=>b(C.name,{label:e.target.value||void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.messageLabel`,i)}),(0,$.jsx)(`input`,{value:C.message??``,disabled:n,onChange:e=>b(C.name,{message:e.target.value}),placeholder:Z(`engine.studio.rules.messagePlaceholder`,i),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,$.jsx)(Gb,{rule:C,fields:d,patch:e=>b(C.name,e),disabled:n,locale:i,onBlockingIssuesChange:e=>h(C.name,e)}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.events`,i)}),(0,$.jsx)(`div`,{className:`flex items-center gap-4`,children:Lb.map(e=>{let t=Array.isArray(C.events)?C.events.includes(e):!1;return(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:t,disabled:n,onChange:t=>{let n=Array.isArray(C.events)?C.events:[],r=t.target.checked?[...new Set([...n,e])]:n.filter(t=>t!==e);b(C.name,{events:r})}}),Z(`engine.studio.rules.event.${e}`,i)]},e)})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:Z(`engine.studio.rules.severity`,i)}),(0,$.jsxs)(`select`,{value:C.severity??`error`,disabled:n,onChange:e=>b(C.name,{severity:e.target.value}),className:`rounded border bg-background px-1.5 py-0.5 text-[12px]`,children:[(0,$.jsx)(`option`,{value:`error`,children:Z(`engine.studio.rules.severityError`,i)}),(0,$.jsx)(`option`,{value:`warning`,children:`warning`}),(0,$.jsx)(`option`,{value:`info`,children:`info`})]})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:Z(`engine.studio.rules.priority`,i)}),(0,$.jsx)(`input`,{type:`number`,value:typeof C.priority==`number`?C.priority:``,disabled:n,onChange:e=>b(C.name,{priority:e.target.value===``?void 0:Number(e.target.value)}),className:`w-20 rounded border bg-background px-1.5 py-0.5 text-[12px]`})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:C.active!==!1,disabled:n,onChange:e=>b(C.name,{active:e.target.checked})}),Z(`engine.studio.rules.enabled`,i)]}),!n&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rule-delete`,onClick:()=>S(C.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,$.jsx)(la,{className:`h-3 w-3`}),` `,Z(`engine.studio.rules.delete`,i)]})]})]}):(0,$.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`,i)})})]})}function qb({name:e,draft:t,onPatch:n,disabled:r,locale:i,onBlockingIssuesChange:a}){let o=mc(`object`),s=Q.useMemo(()=>el(t.fields).entries,[t.fields]),c=s.filter(e=>(e.def.type??`text`)===`select`),l=typeof t.nameField==`string`?t.nameField:``,u=t.stageField,d=Array.isArray(t.highlightFields)?t.highlightFields.filter(e=>typeof e==`string`):[],f=s.filter(e=>e.def.hidden!==!0&&!d.includes(e.name)),p=typeof t.sharingModel==`string`?t.sharingModel:``,m=p===`private`?`engine.studio.settings.sharingDescPrivate`:p===`public_read`?`engine.studio.settings.sharingDescPublicRead`:p===`public_read_write`?`engine.studio.settings.sharingDescPublicReadWrite`:p===`controlled_by_parent`?`engine.studio.settings.sharingDescControlledByParent`:`engine.studio.settings.sharingDescUnset`,h=t.enable&&typeof t.enable==`object`?t.enable:{},g=(e,t)=>n({enable:{...h,[e]:t}}),_=[{key:`trackHistory`,optIn:!0,labelKey:`engine.studio.settings.capTrackHistory`,descKey:`engine.studio.settings.capTrackHistoryDesc`},{key:`files`,optIn:!0,labelKey:`engine.studio.settings.capFiles`,descKey:`engine.studio.settings.capFilesDesc`},{key:`feeds`,optIn:!1,labelKey:`engine.studio.settings.capFeeds`,descKey:`engine.studio.settings.capFeedsDesc`},{key:`activities`,optIn:!1,labelKey:`engine.studio.settings.capActivities`,descKey:`engine.studio.settings.capActivitiesDesc`},{key:`searchable`,optIn:!1,labelKey:`engine.studio.settings.capSearchable`,descKey:`engine.studio.settings.capSearchableDesc`},{key:`clone`,optIn:!1,labelKey:`engine.studio.settings.capClone`,descKey:`engine.studio.settings.capCloneDesc`}],v=typeof t.externalSharingModel==`string`?t.externalSharingModel:``,y=bb(p,v);return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-auto`,children:[(0,$.jsxs)(`section`,{className:`rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(Ki,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.basics`,i)})]}),(0,$.jsx)(`div`,{className:`max-w-xl p-3`,children:o?(0,$.jsx)(o,{type:`object`,name:e,draft:t,onPatch:n,readOnly:!!r,locale:i,onBlockingIssuesChange:a}):(0,$.jsx)(`p`,{className:`text-[12px] text-muted-foreground`,children:Z(`engine.studio.settings.noInspector`,i)})})]}),(0,$.jsxs)(`section`,{className:`rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(Xi,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.sharing`,i)}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingHint`,i)})]}),(0,$.jsxs)(`div`,{className:`grid max-w-xl gap-2 p-3`,children:[(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingModel`,i)}),(0,$.jsxs)(`select`,{value:p,disabled:r,"data-testid":`owd-internal-select`,onChange:e=>n(e.target.value?{sharingModel:e.target.value}:{sharingModel:void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingUnset`,i)}),(0,$.jsx)(`option`,{value:`private`,children:Z(`engine.studio.settings.sharingPrivate`,i)}),(0,$.jsx)(`option`,{value:`public_read`,children:Z(`engine.studio.settings.sharingPublicRead`,i)}),(0,$.jsx)(`option`,{value:`public_read_write`,children:Z(`engine.studio.settings.sharingPublicReadWrite`,i)}),(0,$.jsx)(`option`,{value:`controlled_by_parent`,children:Z(`engine.studio.settings.sharingControlledByParent`,i)})]})]}),(0,$.jsx)(`p`,{"data-testid":`owd-internal-desc`,className:p===``?`text-[11px] text-amber-600 dark:text-amber-500`:`text-[11px] text-muted-foreground`,children:Z(m,i)}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingExternal`,i)}),(0,$.jsxs)(`select`,{value:v,disabled:r,"data-testid":`owd-external-select`,onChange:e=>n(e.target.value?{externalSharingModel:e.target.value}:{externalSharingModel:void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingExternalUnset`,i)}),(0,$.jsx)(`option`,{value:`private`,children:Z(`engine.studio.settings.sharingPrivate`,i)}),(0,$.jsx)(`option`,{value:`public_read`,children:Z(`engine.studio.settings.sharingPublicRead`,i)}),(0,$.jsx)(`option`,{value:`public_read_write`,children:Z(`engine.studio.settings.sharingPublicReadWrite`,i)}),(0,$.jsx)(`option`,{value:`controlled_by_parent`,children:Z(`engine.studio.settings.sharingControlledByParent`,i)})]})]}),(0,$.jsx)(`p`,{"data-testid":`owd-external-desc`,className:y?`text-[11px] text-amber-600 dark:text-amber-500`:`text-[11px] text-muted-foreground`,children:Z(y?`engine.studio.settings.sharingExternalWider`:`engine.studio.settings.sharingExternalDesc`,i)})]})]}),(0,$.jsxs)(`section`,{className:`rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(ea,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.semanticRoles`,i)}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.semanticHint`,i)})]}),(0,$.jsxs)(`div`,{className:`grid max-w-xl gap-4 p-3`,children:[(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.nameField`,i)}),(0,$.jsxs)(`select`,{value:l,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,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.autoDerive`,i)}),s.map(e=>(0,$.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]})]}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.stageField`,i)}),(0,$.jsxs)(`select`,{value:u===!1?`__none__`:u??``,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,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.autoDetect`,i)}),(0,$.jsx)(`option`,{value:`__none__`,children:Z(`engine.studio.settings.stageNone`,i)}),c.map(e=>(0,$.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.highlightFields`,i)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d.map(e=>(0,$.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,$.jsx)(`button`,{type:`button`,"aria-label":Dl(`engine.studio.settings.removeField`,i,{field:e}),onClick:()=>n({highlightFields:d.filter(t=>t!==e)}),className:`rounded-full hover:bg-primary/20`,children:(0,$.jsx)(ba,{className:`h-3 w-3`})})]},e)),!r&&f.length>0&&(0,$.jsxs)(`select`,{value:``,onChange:e=>{e.target.value&&n({highlightFields:[...d,e.target.value]})},className:`rounded border bg-background px-1.5 py-0.5 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.addFieldOption`,i)}),f.map(e=>(0,$.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]}),d.length===0&&(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.undeclared`,i)})]})]})]})]}),(0,$.jsxs)(`section`,{className:`rounded-lg border`,"data-testid":`capabilities-section`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(ca,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.capabilities`,i)}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.capabilitiesHint`,i)})]}),(0,$.jsx)(`div`,{className:`grid max-w-xl gap-3 p-3`,children:_.map(({key:e,optIn:t,labelKey:n,descKey:a})=>{let o=h[e];return(0,$.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:t?o===!0:o!==!1,disabled:r,"data-testid":`cap-${e}`,onChange:t=>g(e,t.target.checked),className:`mt-0.5`}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-[12px]`,children:Z(n,i)}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:Z(a,i)})]})]},e)})})]})]})}var Jb=[{value:`private`,key:`engine.studio.settings.sharingPrivate`},{value:`public_read`,key:`engine.studio.settings.sharingPublicRead`},{value:`public_read_write`,key:`engine.studio.settings.sharingPublicReadWrite`},{value:`controlled_by_parent`,key:`engine.studio.settings.sharingControlledByParent`}];function Yb(e,t){if(!e)return Z(`engine.studio.settings.sharingUnset`,t);let n=Jb.find(t=>t.value===e);return n?Z(n.key,t):e}function Xb({client:e,packageId:t,publishNonce:n=0,onDraftSaved:r,readOnly:i=!1,locale:a,highlightObject:o,onDirtyChange:s}){let[c,l]=Q.useState([]),[u,d]=Q.useState({}),[f,p]=Q.useState(!1),[m,h]=Q.useState(null),[g,_]=Q.useState(!1),[v,y]=Q.useState(null),b=Q.useCallback(async()=>{p(!1),h(null);try{let[n,r]=await Promise.all([e.list(`object`,{packageId:t}),e.listDrafts({packageId:t,type:`object`}).catch(()=>[])]),i=new Map,a=[],o=new Set;for(let e of n||[]){let t=e.item??e,n=String(t.name??``);n&&!o.has(n)&&(o.add(n),a.push(n),i.set(n,String(t.label??n)))}for(let e of r||[]){let t=String(e?.name??``);t&&!o.has(t)&&(o.add(t),a.push(t))}let s=await Promise.all(a.map(async t=>{let[n,r]=await Promise.all([e.layered(`object`,t).catch(()=>null),e.getDraft(`object`,t).catch(()=>null)]),a=n??{},o=a.effective??a.code??{},s=dr(r),c=s??o,l=typeof c.sharingModel==`string`?c.sharingModel:``;return{name:t,label:String(c.label??i.get(t)??t),internal:l,external:typeof c.externalSharingModel==`string`?c.externalSharingModel:``,master:l===`controlled_by_parent`?xb(c.fields):void 0,hasDraft:!!s}}));s.sort((e,t)=>e.label.localeCompare(t.label)||e.name.localeCompare(t.name)),l(s),d(Object.fromEntries(s.map(e=>[e.name,{internal:e.internal,external:e.external}])))}catch(e){h(or(e))}finally{p(!0)}},[e,t]);Q.useEffect(()=>{b()},[b,n]);let x=Q.useRef({});Q.useEffect(()=>{if(!o||!f)return;let e=x.current[o];e&&e.scrollIntoView({block:`center`,behavior:`smooth`})},[o,f]);let S=Q.useCallback((e,t)=>{d(n=>({...n,[e]:{...n[e],...t}}))},[]),C=Q.useMemo(()=>c.map(e=>{let t=u[e.name]??{internal:e.internal,external:e.external};return{row:e,edit:t,dirty:t.internal!==e.internal||t.external!==e.external,invalid:bb(t.internal,t.external)}}),[c,u]),w=C.filter(e=>e.dirty).length,T=C.some(e=>e.invalid),E=w>0,D=Q.useRef(s);Q.useEffect(()=>{D.current=s}),Q.useEffect(()=>{D.current?.(E)},[E]),Q.useEffect(()=>()=>{D.current?.(!1)},[]);let O=Q.useCallback(async()=>{let n=C.filter(e=>e.dirty&&!e.invalid);if(n.length!==0){_(!0),y(null);try{for(let r of n){let[n,i]=await Promise.all([e.layered(`object`,r.row.name).catch(()=>null),e.getDraft(`object`,r.row.name).catch(()=>null)]),a=n??{},o=a.effective??a.code??{},s={...dr(i)??o};r.edit.internal?s.sharingModel=r.edit.internal:delete s.sharingModel,r.edit.external?s.externalSharingModel=r.edit.external:delete s.externalSharingModel,await e.save(`object`,r.row.name,s,{mode:`draft`,packageId:t})}Y.success(Dl(`engine.studio.owd.saved`,a,{count:n.length})),r?.(),await b()}catch(e){y(or(e))}finally{_(!1)}}},[C,e,t,r,b,a]),k=!i&&!g&&w>0&&!T;return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,"data-testid":`owd-overview`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-4 py-2.5`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(Xi,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate text-[15px] font-semibold leading-none text-foreground`,children:Z(`engine.studio.owd.title`,a)}),(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[11px] text-muted-foreground`,children:Z(`engine.studio.owd.subtitle`,a)})]}),i?(0,$.jsxs)(`span`,{title:Z(`engine.studio.pkg.readonlyHint`,a),className:`ml-auto flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(_i,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,a)]}):(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void O(),disabled:!k,"data-testid":`owd-save`,className:`ml-auto inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[g?(0,$.jsx)(X,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Wi,{className:`h-3.5 w-3.5`}),w>0?Dl(`engine.studio.owd.save`,a,{count:w}):Z(`engine.studio.owd.saveNone`,a)]})]}),(0,$.jsx)(`p`,{className:`border-b px-4 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.owd.description`,a)}),T&&(0,$.jsxs)(`p`,{"data-testid":`owd-invalid-banner`,className:`flex items-center gap-1.5 border-b bg-amber-400/10 px-4 py-2 text-[11px] text-amber-600 dark:text-amber-400`,children:[(0,$.jsx)(ua,{className:`h-3.5 w-3.5 shrink-0`}),Z(`engine.studio.owd.blockedSave`,a)]}),v&&(0,$.jsx)(`p`,{className:`border-b bg-destructive/10 px-4 py-2 text-[11px] text-destructive`,children:v}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:f?m?(0,$.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.owd.loadFailed`,a)}):c.length===0?(0,$.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.owd.none`,a)}):(0,$.jsxs)(`table`,{className:`w-full border-collapse text-[12px]`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b text-left text-[11px] uppercase tracking-wide text-muted-foreground`,children:[(0,$.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colObject`,a)}),(0,$.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colInternal`,a)}),(0,$.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colExternal`,a)})]})}),(0,$.jsx)(`tbody`,{children:C.map(({row:e,edit:t,dirty:n,invalid:r})=>{let s=t.internal===`controlled_by_parent`;return(0,$.jsxs)(`tr`,{ref:t=>{x.current[e.name]=t},"data-testid":`owd-row-${e.name}`,className:`border-b align-top `+(o===e.name?`bg-primary/5`:``),children:[(0,$.jsx)(`td`,{className:`px-2 py-2`,children:(0,$.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),n&&(0,$.jsx)(`span`,{"data-testid":`owd-dirty-${e.name}`,className:`rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.owd.unsaved`,a)}),e.hasDraft&&!n&&(0,$.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:Z(`engine.studio.unpublishedDraft`,a)})]}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.name})]})}),(0,$.jsx)(`td`,{className:`px-2 py-2`,children:i?(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:Yb(t.internal,a)}):(0,$.jsxs)(`select`,{value:t.internal,"data-testid":`owd-internal-${e.name}`,onChange:t=>S(e.name,{internal:t.target.value}),className:`w-full min-w-[13rem] rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingUnset`,a)}),Jb.map(e=>(0,$.jsx)(`option`,{value:e.value,children:Z(e.key,a)},e.value))]})}),(0,$.jsx)(`td`,{className:`px-2 py-2`,children:s?(0,$.jsxs)(`span`,{"data-testid":`owd-master-${e.name}`,title:Z(`engine.studio.owd.masterTip`,a),className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,$.jsx)(_r,{className:`h-3.5 w-3.5`}),e.master?Dl(`engine.studio.owd.byParent`,a,{master:e.master}):Z(`engine.studio.owd.byParentUnknown`,a)]}):i?(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:Yb(t.external,a)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`select`,{value:t.external,"data-testid":`owd-external-${e.name}`,onChange:t=>S(e.name,{external:t.target.value}),className:`w-full min-w-[13rem] rounded border bg-background px-2 py-1 text-[12px] `+(r?`border-amber-500`:``),children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingExternalUnset`,a)}),Jb.filter(e=>e.value!==`controlled_by_parent`).map(e=>(0,$.jsx)(`option`,{value:e.value,children:Z(e.key,a)},e.value))]}),r&&(0,$.jsx)(`span`,{"data-testid":`owd-error-${e.name}`,className:`mt-1 block text-[11px] text-amber-600 dark:text-amber-500`,children:Z(`engine.studio.owd.widerError`,a)})]})})]},e.name)})})]}):(0,$.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.loading`,a)})})]})}var Zb={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 Qb(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 $b(e){let t=el(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]=Qb(t.type),Object.keys(r).length>=8))break}return r}function ex({name:e,draft:t}){let n=El(),[r,i]=Q.useState(null),a=typeof window<`u`?window.location.origin:`https://your-host`,o=`/api/v1/data/${e}`,s=Q.useMemo(()=>$b(t.fields),[t.fields]),c=JSON.stringify(s,null,2),l=[{id:`list`,method:`GET`,path:o,desc:Z(`engine.studio.api.list`,n)},{id:`create`,method:`POST`,path:o,desc:Z(`engine.studio.api.create`,n),body:!0},{id:`get`,method:`GET`,path:`${o}/{id}`,desc:Z(`engine.studio.api.get`,n)},{id:`update`,method:`PATCH`,path:`${o}/{id}`,desc:Z(`engine.studio.api.update`,n),body:!0},{id:`delete`,method:`DELETE`,path:`${o}/{id}`,desc:Z(`engine.studio.api.delete`,n)}],u=e=>{let t=[`curl -X ${e.method} '${a}${e.path}'`,` -H 'Authorization: Bearer <token>'`];return e.body&&(t.push(` -H 'Content-Type: application/json'`),t.push(` -d '${JSON.stringify(s)}'`)),t.join(` \\
9
+ `)},d=(e,t)=>{navigator.clipboard?.writeText(t).then(()=>{i(e),setTimeout(()=>i(t=>t===e?null:t),1500)})};return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-auto`,children:[(0,$.jsx)(`p`,{className:`text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.api.subtitle`,n)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>(0,$.jsx)(`div`,{className:`rounded-lg border`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,$.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold `+Zb[e.method],children:e.method}),(0,$.jsx)(`code`,{className:`min-w-0 flex-1 truncate text-[12px]`,children:e.path}),(0,$.jsx)(`span`,{className:`hidden shrink-0 text-[11px] text-muted-foreground sm:inline`,children:e.desc}),(0,$.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,$.jsx)(kr,{className:`h-3 w-3 text-emerald-500`}):(0,$.jsx)(Wr,{className:`h-3 w-3`}),r===e.id?Z(`engine.studio.api.copied`,n):`cURL`]})]})},e.id))}),Object.keys(s).length>0&&(0,$.jsxs)(`div`,{className:`rounded-lg border`,children:[(0,$.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,$.jsx)(`pre`,{className:`overflow-auto px-3 py-2 text-[11px] leading-5`,children:c})]})]})}var tx=e=>dr(e);function nx(e,t){let n=e.object;return n===`*`?!0:typeof n==`string`?n===t:Array.isArray(n)?n.includes(t)||n.includes(`*`):!1}function rx(e,t){let n=(e||`hook`).replace(/[^a-z0-9_]/gi,`_`).toLowerCase(),r=new Set(t),i=t.length+1,a=`${n}_hook_${i}`;for(;r.has(a);)a=`${n}_hook_${++i}`;return a}function ix({objectName:e,packageId:t,disabled:n,hookSchema:r}){let i=El(),a=Da(),o=mc(`hook`),[s,c]=Q.useState([]),[l,u]=Q.useState(!0),[d,f]=Q.useState(null),[p,m]=Q.useState(null),[h,g]=Q.useState(null),[_,v]=Q.useState(!1),[y,b]=Q.useState(!1),[x,S]=Q.useState(0),[C,w]=Q.useState({hook:``,count:0}),T=String(h?.name??``),E=Q.useCallback(e=>{w(t=>t.hook===T&&t.count===e?t:{hook:T,count:e})},[T]),D=C.hook===T?C.count:0;Q.useEffect(()=>{let n=!1;return u(!0),f(null),(async()=>{try{let[r,i]=await Promise.all([a.list(`hook`,{packageId:t}),a.listDrafts({packageId:t,type:`hook`}).catch(()=>[])]),o=(i||[]).map(e=>String(e.name??``)).filter(Boolean),s=await Promise.all(o.map(e=>a.getDraft(`hook`,e).then(tx).catch(()=>null)));if(n)return;let l=new Map;for(let t of r||[])t?.name&&nx(t,e)&&l.set(String(t.name),t);o.forEach((t,n)=>{let r=s[n];r&&nx(r,e)&&l.set(t,r)}),c([...l.values()])}catch(e){n||f(or(e))}finally{n||u(!1)}})(),()=>{n=!0}},[a,t,e,x]),Q.useEffect(()=>{let e=s.find(e=>e.name===p)??null;g(e?{...e}:null),v(!1)},[p,s]);let O=Q.useCallback(async()=>{if(h?.name){b(!0),f(null);try{await a.save(`hook`,String(h.name),h,{mode:`draft`,packageId:t}),Y.success(Dl(`engine.studio.hooks.saved`,i,{label:String(h.label||h.name)})),v(!1),S(e=>e+1)}catch(e){f(or(e))}finally{b(!1)}}},[a,h,t,i]),k=Q.useCallback(async()=>{let n=rx(e,s.map(e=>String(e.name??``))),r={name:n,label:Z(`engine.studio.hooks.newLabel`,i),object:e,events:[`beforeInsert`],body:{language:`js`,source:`return;`},priority:100,async:!1};b(!0),f(null);try{await a.save(`hook`,n,r,{mode:`draft`,packageId:t}),S(e=>e+1),m(n)}catch(e){f(or(e))}finally{b(!1)}},[a,e,s,t,i]);return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(_a,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.data.tab.hooks`,i)}),(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,s.length,`)`]}),!n&&(0,$.jsxs)(`button`,{type:`button`,onClick:k,disabled:y,className:`ml-auto inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[(0,$.jsx)(Ri,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,i)]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:l?(0,$.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,i)}):s.length===0?(0,$.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.hooks.none`,i)}):s.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>m(e.name??null),className:`flex w-full items-center gap-2 border-b px-3 py-2 text-left text-[12px] `+(p===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,$.jsx)(_a,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.label||e.name}),e.async&&(0,$.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] text-primary`,children:Z(`engine.studio.hooks.async`,i)})]},String(e.name)))})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden rounded-lg border`,children:[d&&(0,$.jsx)(`div`,{className:`border-b border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive whitespace-pre-line`,children:d}),h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b px-3 py-1.5`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[12px] font-medium`,children:String(h.label||h.name)}),!n&&(0,$.jsxs)(`button`,{type:`button`,onClick:O,disabled:!_||y||D>0,title:D>0?Z(`perm.cel.saveBlocked`,i):void 0,className:`inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[y?(0,$.jsx)(X,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(Wi,{className:`h-3 w-3`}),Z(`engine.studio.hooks.save`,i)]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:o?(0,$.jsx)(o,{type:`hook`,name:String(h.name??``),draft:h,onPatch:e=>{g(t=>({...t,...e})),v(!0)},readOnly:!!n,locale:i,serverSchema:r,onBlockingIssuesChange:E}):(0,$.jsx)(`div`,{className:`p-3`,children:(0,$.jsx)(dl,{schema:r,value:h,onChange:e=>{g(e),v(!0)},readOnly:!!n})})})]}):(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:Z(`engine.studio.hooks.pick`,i)})]})]})}function ax(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`):[]}function ox(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 sx(e,t,n){return e==null?t:So(e,n)}function cx({draft:e,onPatch:t,disabled:n,actionSchema:r,onBlockingIssuesChange:i}){let a=El(),o=Q.useMemo(()=>ax(e.actions),[e.actions]),[s,c]=Q.useState(null),l=o.some(e=>e.name===s)?s:o[0]?.name??null,u=o.find(e=>e.name===l)??null,d=mc(`action`),f=Q.useCallback(e=>{u&&(t({actions:o.map(t=>t.name===u.name?{...t,...e}:t)}),typeof e.name==`string`&&e.name!==u.name&&c(e.name))},[o,u,t]),p=typeof e.name==`string`?e.name:``,[m,h]=Q.useState({}),g=Q.useCallback((e,t)=>{h(n=>n[e]===t?n:{...n,[e]:t})},[]),_=Q.useMemo(()=>new Set(o.map(e=>String(e.name??``))),[o]),v=Q.useMemo(()=>{let e=0;for(let[t,n]of Object.entries(m))_.has(t)&&(e+=n);return e},[m,_]),y=Q.useRef(i);Q.useEffect(()=>{y.current=i}),Q.useEffect(()=>{y.current?.(v)},[v]);let b=Q.useCallback(()=>{let e=ox(p,o.map(e=>String(e.name??``))),n={name:e,label:Z(`engine.studio.actions.newLabel`,a),type:`script`,objectName:p,locations:[`record_header`],body:{language:`js`,source:`return { ok: true };`}};t({actions:[...o,n]}),c(e)},[o,p,t,a]),x=Q.useCallback(e=>{t({actions:o.filter(t=>t.name!==e)}),c(null)},[o,t]);return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(xa,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.data.tab.actions`,a)}),(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,o.length,`)`]}),!n&&(0,$.jsxs)(`button`,{type:`button`,onClick:b,className:`ml-auto inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[(0,$.jsx)(Ri,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,a)]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:o.length===0?(0,$.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.actions.none`,a)}):o.map(e=>{let t=Wc(typeof e.icon==`string`?e.icon:void 0),n=typeof e.type==`string`?e.type:``;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>c(e.name??null),className:`flex w-full items-center gap-2 border-b px-3 py-2 text-left text-[12px] `+(l===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,$.jsx)(t,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:sx(e.label,String(e.name??``),a)}),n&&(0,$.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,$.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col overflow-auto rounded-lg border`,children:u?d?(0,$.jsxs)($.Fragment,{children:[!n&&(0,$.jsx)(`div`,{className:`flex shrink-0 items-center justify-end border-b px-2 py-1`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>x(u.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,$.jsx)(la,{className:`h-3 w-3`}),` `,Z(`engine.studio.actions.delete`,a)]})}),(0,$.jsx)(d,{type:`action`,name:String(u.name??``),draft:u,onPatch:f,readOnly:!!n,locale:a,serverSchema:r,onBlockingIssuesChange:e=>g(String(u.name??``),e)})]}):(0,$.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-2 p-6 text-center text-[12px] text-muted-foreground`,children:[(0,$.jsx)(vr,{className:`h-5 w-5`}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:sx(u.label,String(u.name??``),a)}),(0,$.jsx)(`span`,{children:Z(`engine.studio.actions.editorMissing`,a)})]}):(0,$.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`,a)})})]})}var lx={private:`engine.studio.settings.sharingPrivate`,public_read:`engine.studio.settings.sharingPublicRead`,public_read_write:`engine.studio.settings.sharingPublicReadWrite`},ux={private:`engine.studio.settings.sharingDescPrivate`,public_read:`engine.studio.settings.sharingDescPublicRead`,public_read_write:`engine.studio.settings.sharingDescPublicReadWrite`},dx=[{key:`data`,label:`Data`,Icon:Gr},{key:`automations`,label:`Automations`,Icon:ya},{key:`interfaces`,label:`Interfaces`,Icon:pi}];function fx(e,t){if(e!==`page`)return t;let n=nc(`page`)?.fromDraft;return n?n(t):t}function px(e){try{return JSON.stringify(e??null)}catch{return`"__unserializable__"`}}function mx(e){let{target:t,loadedFor:n,dirty:r,blocked:i,snapshot:a,save:o}=e,s=Q.useMemo(()=>px(a),[a]),c=Q.useRef(null),l=Q.useRef(o),u=Q.useRef({dirty:r,blocked:i,snapKey:s,target:t,loadedFor:n,since:t});Q.useLayoutEffect(()=>{let e=u.current;l.current=o,u.current={dirty:r,blocked:i,snapKey:s,target:t,loadedFor:n,since:r&&e.dirty?e.since:t}});let[d]=Q.useState(()=>{let e=(e,t)=>({unmoved:()=>u.current.target===t&&u.current.snapKey===e}),t=()=>{let{since:e,target:t,loadedFor:n}=u.current;return e===t&&n===t},n=t=>{c.current=t,l.current(e(t,u.current.target))};return{send:n,owned:t,flush:()=>{let e=u.current;return!e.dirty||e.blocked||!t()||c.current===e.snapKey?!1:(n(e.snapKey),!0)},sending:n=>t()?e(px(n),u.current.target):null}});return Q.useEffect(()=>{if(!r||i||c.current===s)return;let e=setTimeout(()=>{c.current!==s&&d.owned()&&d.send(s)},1500);return()=>clearTimeout(e)},[r,i,s,d]),{flush:d.flush,sending:d.sending,loaded:n===t}}var hx=[{key:`access`,label:`Access`,Icon:Qi}],gx={object:`data`,flow:`automations`,permission:`access`},_x={group:ti,page:$r,object:Gr,dashboard:pi,report:Er,view:oa,action:ki},vx=e=>_x[e??``]??Ur,yx=`studio-package-list`;function bx({packageId:e,tab:t,beforeNavigate:n}){let i=r(),a=El(),o=Qu(),[s,c]=Q.useState(!1),[l,u]=Q.useState(null),[d,f]=Q.useState(null),[p,m]=Q.useState(!1),[h,g]=Q.useState(null),[_,v]=Q.useState(!1),[y,b]=Q.useState(!1);Q.useEffect(()=>{let e=!1,t=()=>{sc().then(t=>{e||(u(t),f(null))}).catch(t=>{if(e)return;let n=or(t);f(n),Y.error(n,{id:yx})})};return t(),window.addEventListener(`objectui:packages-changed`,t),()=>{e=!0,window.removeEventListener(`objectui:packages-changed`,t)}},[e]);let x=l?.find(t=>t.id===e)??null,S=d===null?l===null?`loading`:`loaded`:`failed`,C=Q.useCallback(async e=>{let t=await fetch(`/api/v1/packages`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok){let e=await t.json().catch(()=>null),n=typeof e?.error?.userMessage==`string`?e.error.userMessage:``,r=typeof e?.error?.message==`string`?e.error.message:``,i=n||r,a=typeof e?.error?.code==`string`?e.error.code:``;throw Error(i?a?`${i} (${a})`:i:`HTTP ${t.status}`)}let n=await t.json(),r=n?.data??n;return(Array.isArray(r)?r:r?.packages??[]).find(t=>(t?.manifest?.id??t?.id)===e)??null},[]),w=Q.useCallback(async e=>{c(!1),b(!0);try{let t=await C(e);if(!t){Y.error(Dl(`engine.studio.pkg.manageMissing`,a,{id:e}),{id:yx});return}g(t),v(!0)}catch(e){Y.error(or(e),{id:yx})}finally{b(!1)}},[C,a]),T=Q.useCallback(async()=>{let n=null;try{n=await sc(),u(n),f(null)}catch(e){let t=or(e);f(t),Y.error(t,{id:yx})}let r=h?.manifest.id;if(r){if(n!==null&&!n.some(e=>e.id===r)){if(r===e){let e=n[0];i(e?`/studio/${encodeURIComponent(e.id)}/${t}`:o)}return}try{let e=await C(r);e?g(e):(Y.error(Dl(`engine.studio.pkg.manageMissing`,a,{id:r}),{id:yx}),v(!1))}catch(e){Y.error(Dl(`engine.studio.pkg.manageRefreshFailed`,a,{id:r,error:or(e)}),{id:yx}),v(!1)}}},[h,e,t,i,C,a,o]);return(0,$.jsxs)(Te,{open:s,onOpenChange:c,children:[(0,$.jsx)(we,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,"data-pkg-list-state":S,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`,a),children:[e===null?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(wr,{className:`h-4 w-4`}),` `,Z(`engine.studio.org.name`,a)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Sr,{className:`h-4 w-4`}),` `,x?.name??e]}),S===`loading`&&(0,$.jsx)(X,{"data-testid":`pkg-switcher-loading`,"aria-hidden":!0,className:`h-3 w-3 shrink-0 animate-spin text-muted-foreground`}),S===`failed`&&(0,$.jsxs)(`span`,{"data-testid":`pkg-switcher-failed`,title:d??void 0,className:`inline-flex items-center gap-0.5 rounded bg-destructive/10 px-1.5 py-0.5 text-[10px] font-normal text-destructive`,children:[(0,$.jsx)(ua,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.loadFailed`,a)]}),x&&!x.writable&&(0,$.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,$.jsx)(_i,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,a)]}),(0,$.jsx)(Ar,{className:`h-3.5 w-3.5 text-muted-foreground`})]})}),(0,$.jsxs)(Ot,{align:`start`,sideOffset:6,className:`w-80 rounded-lg p-1.5`,children:[(0,$.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`,a)}),(0,$.jsxs)(`div`,{className:`max-h-64 overflow-auto`,children:[S===`loading`&&(0,$.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,a)}),S===`failed`&&(0,$.jsx)(`p`,{"data-testid":`pkg-switcher-failed-detail`,className:`whitespace-pre-line px-2 py-2 text-[11px] text-destructive`,children:d}),S===`loaded`&&l?.length===0&&(0,$.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.pkg.none`,a)}),l?.map(r=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{c(!1),r.id!==e&&(!n||n())&&i(`/studio/${encodeURIComponent(r.id)}/${t}`)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(r.id===e?`bg-muted font-medium`:`hover:bg-muted/60`),children:[(0,$.jsx)(Sr,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate`,children:r.name}),(0,$.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:r.id})]}),r.writable?(0,$.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`,a)}):(0,$.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,$.jsx)(_i,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,a)]})]},r.id))]}),(0,$.jsx)(`div`,{className:`mt-1 border-t pt-1.5`,children:(0,$.jsxs)(`button`,{type:`button`,"data-testid":`studio-org-scope-entry`,onClick:()=>{c(!1),e!==null&&(!n||n())&&i(tb())},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(e===null?`bg-muted font-medium`:`hover:bg-muted/60`),children:[(0,$.jsx)(wr,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate`,children:Z(`engine.studio.org.name`,a)}),(0,$.jsx)(`span`,{className:`block truncate text-[10px] text-muted-foreground`,children:Z(`engine.studio.org.hint`,a)})]})]})}),(0,$.jsxs)(`div`,{className:`mt-1 space-y-0.5 border-t pt-1.5`,children:[x&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void w(x.id),disabled:y,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:[y?(0,$.jsx)(X,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(qi,{className:`h-3.5 w-3.5`}),Z(`engine.studio.pkg.manage`,a)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{c(!1),m(!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,$.jsx)(Ri,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.pkg.new`,a)]})]})]}),(0,$.jsx)(hc,{open:p,onOpenChange:m,onCreated:e=>{(!n||n())&&i(`/studio/${encodeURIComponent(e)}/data`)}}),(0,$.jsx)(oc,{pkg:h,open:_,onOpenChange:v,onChanged:T})]})}function xx({aiSlot:e}){let n=f(),i=n.packageId??`com.example.showcase`,a=eb(i)?null:i,o=n.tab??`interfaces`,s=El(),[c,l]=Q.useState(void 0);Q.useEffect(()=>{if(a===null)return;let e=!1;return l(void 0),sc().then(t=>{e||l(t.find(e=>e.id===a)?.writable??null)}).catch(t=>{e||(l(null),Y.error(or(t),{id:yx}))}),()=>{e=!0}},[a]);let u=a!==null&&c===!1,[d,m]=Q.useState(!1),h=Q.useCallback(()=>!d||window.confirm(Z(`engine.edit.unsavedLeaveConfirm`,s)),[d,s]);Q.useEffect(()=>{if(!d)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[d]);let g=Da(),[_,v]=Q.useState(!1),[y,b]=Q.useState(!1),[x,S]=Q.useState(0),[C,w]=Q.useState(0),{count:T,entries:E,refresh:D}=tf({packageId:a}),O=a===null?T===null?null:E.filter(ob).length:T;Q.useEffect(()=>{D()},[D,x,C]);let k=Q.useCallback(async()=>{b(!0);try{if(a===null){let e=(await ef(null)).filter(ob),t=[];for(let n of e)try{await g.publishDraft(`flow`,n.name)}catch(e){t.push({type:`flow`,name:n.name,error:or(e)})}t.length>0?Y.error(Gd(t)):(Y.success(Z(`engine.studio.org.published`,s)),v(!1)),S(e=>e+1),Ha(),await D();return}let e=await g.publishPackageDrafts(a);if(e?.success===!1)throw Object.assign(Error(rc(e)||Z(`engine.packages.detail.actionFailed`,s)),{issues:e?.error?.details?.issues});let t=e?.failed??[];t.length>0?Y.error(Gd(t)):(Y.success(Z(`engine.studio.publishedAll`,s)),v(!1)),S(e=>e+1),Ha()}catch(e){Y.error(or(e))}finally{b(!1)}await D()},[g,a,D,s]),A=Q.useCallback(()=>w(e=>e+1),[]),j=(O??0)>0,M=Q.useId(),N=r(),ee=Qu(),[P,F]=Q.useState(null),[te,I]=Q.useState(!1),[ne,re]=Q.useState(!1),[L,ie]=Q.useState(null),[ae,oe]=Q.useState(null),[R,se]=Q.useState(!0),ce=Q.useCallback(async()=>{if(a===null)return[];let[e,t]=await Promise.all([g.list(`object`,{packageId:a}),g.listDrafts({packageId:a,type:`object`}).catch(()=>[])]),n=(e||[]).map(e=>({name:String(e.name??``)})).filter(e=>e.name),r=new Set(n.map(e=>e.name));for(let e of t)e.name&&!r.has(e.name)&&n.push({name:e.name});return n},[g,a]),le=Q.useCallback(async(e,t)=>{if(a!==null){re(!0),ie(null);try{let n=R?await ce().catch(()=>[]):[];await g.save(`app`,t,_b(t,e,n),{mode:`draft`,packageId:a}),Y.success(Dl(`engine.studio.app.savedDraft`,s,{label:e})),oe(e),I(!1),w(e=>e+1)}catch(e){ie(or(e))}finally{re(!1)}}},[R,ce,g,a,s]),z=Q.useCallback(async()=>{if(a===null){F(null);return}try{let e=(await g.list(`app`,{packageId:a})||[]).map(e=>({name:String(e.name??``),label:e.label??e.name??``})).filter(e=>e.name)[0];if(!e){let t=(await g.listDrafts?.({packageId:a,type:`app`}))?.[0];t?.name&&(e={name:String(t.name),label:t.label??String(t.name)})}F(e??null)}catch{F(null)}},[g,a]);Q.useEffect(()=>(z(),Ba(()=>{z()})),[z,x,C]);let ue=!e,[de,fe]=Q.useState(null),pe=Q.useCallback(e=>{let t=gx[e.type];if(t&&t!==o&&(a!==null||t===`automations`)){if(!h())return!1;N(`/studio/${i}/${t}?${qc}=${encodeURIComponent(Jc(e))}`)}v(!1)},[o,a,i,h,N]);return(0,$.jsx)(Kh,{onRequest:pe,children:(0,$.jsxs)(`div`,{className:`flex h-screen w-full overflow-hidden bg-background text-foreground`,children:[e?(0,$.jsx)(`aside`,{className:`w-64 shrink-0 overflow-auto border-r bg-muted/40`,children:e}):null,(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-3 overflow-x-auto border-b px-3 py-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>{h()&&N(ee)},title:Z(`engine.studio.home`,s),className:`shrink-0 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,$.jsx)(ci,{className:`h-4 w-4`})}),(0,$.jsx)(`div`,{className:`shrink-0`,children:(0,$.jsx)(bx,{packageId:a,tab:o,beforeNavigate:h})}),(0,$.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:`·`}),(0,$.jsxs)(`nav`,{className:`flex shrink-0 gap-1`,children:[(a===null?dx.filter(e=>e.key===$y):dx).map(e=>(0,$.jsxs)(p,{to:`/studio/${i}/${e.key}`,onClick:t=>{o!==e.key&&(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||t.button!==0||h()||t.preventDefault())},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-colors `+(o===e.key?`bg-primary/10 font-medium text-primary`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:[(0,$.jsx)(e.Icon,{className:`h-3.5 w-3.5`}),Z(`engine.studio.pillar.${e.key}`,s)]},e.key)),a!==null&&(0,$.jsxs)(Te,{children:[(0,$.jsx)(we,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,"data-testid":`studio-nav-more`,className:`inline-flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-colors `+(hx.some(e=>o===e.key)?`bg-primary/10 font-medium text-primary`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:[hx.some(e=>o===e.key)?Z(`engine.studio.pillar.${o}`,s):Z(`engine.studio.more`,s),(0,$.jsx)(Ar,{className:`h-3 w-3`})]})}),(0,$.jsx)(Ot,{align:`start`,className:`w-44 p-1`,children:hx.map(e=>(0,$.jsxs)(p,{to:`/studio/${i}/${e.key}`,onClick:t=>{o!==e.key&&(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||t.button!==0||h()||t.preventDefault())},className:`flex items-center gap-2 rounded-md px-2.5 py-1.5 text-xs transition-colors `+(o===e.key?`bg-primary/10 font-medium text-primary`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:[(0,$.jsx)(e.Icon,{className:`h-3.5 w-3.5`}),Z(`engine.studio.pillar.${e.key}`,s)]},e.key))})]})]}),(0,$.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[a===null||P?null:ae?(0,$.jsx)(`span`,{title:Z(`engine.studio.app.willOpenAfterPublish`,s),className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Dl(`engine.studio.app.pending`,s,{label:ae})}):(0,$.jsxs)(`button`,{type:`button`,onClick:()=>I(!0),disabled:u,title:Z(u?`engine.studio.pkg.readonlyHint`:`engine.studio.app.noneTitle`,s),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,$.jsx)(Ri,{className:`h-3.5 w-3.5`}),Z(`engine.studio.app.create`,s)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>v(!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,$.jsx)(ni,{className:`h-3.5 w-3.5`}),Z(`engine.studio.changes`,s),j?` · ${O}`:``]}),!j&&!u&&!y&&(0,$.jsx)(`span`,{id:M,className:`text-[11px] text-muted-foreground`,"data-testid":`publish-none-reason`,children:Z(`engine.studio.publishNoneTitle`,s)}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>v(!0),disabled:y||!j||u,"aria-describedby":!j&&!u&&!y?M:void 0,title:Z(u?`engine.studio.pkg.readonlyHint`:j?`engine.studio.publishTitle`:`engine.studio.publishNoneTitle`,s),className:Le(`inline-flex items-center gap-1.5 rounded-md border px-3 py-1 text-xs font-medium`,y||j&&!u?`border-transparent bg-primary text-primary-foreground disabled:opacity-50`:`text-muted-foreground`),children:[y?(0,$.jsx)(X,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Bi,{className:`h-3.5 w-3.5`}),Z(`engine.studio.publish`,s)]})]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1`,children:a===null?o===`automations`?(0,$.jsx)(Mx,{packageId:null,publishNonce:x,onDraftSaved:A,readOnly:u},i):(0,$.jsx)(t,{to:tb(),replace:!0}):o===`data`?(0,$.jsx)(kx,{packageId:a,publishNonce:x,onDraftSaved:A,readOnly:u},a):o===`automations`?(0,$.jsx)(Mx,{packageId:a,publishNonce:x,onDraftSaved:A,readOnly:u},a):o===`access`?(0,$.jsx)(Nx,{packageId:a,publishNonce:x,onDraftSaved:A,readOnly:u,onDirtyChange:m}):(0,$.jsx)(Tx,{packageId:a,publishNonce:x,draftNonce:C,onDraftSaved:A,onCreateApp:u?void 0:()=>I(!0),readOnly:u,readOnlySettled:c!==void 0,foldInspector:ue,onDirtyChange:m,onSurfaceLabelChange:fe},a)})]}),ue&&a!==null&&(0,$.jsx)(Hy,{packageId:a,locale:s,surfaceLabel:de}),(0,$.jsx)(ig,{open:_,onOpenChange:v,packageId:a,include:a===null?ob:void 0,onPublish:u?void 0:k,publishing:y}),(0,$.jsx)(wb,{open:te,onOpenChange:I,title:Z(`engine.studio.app.create`,s),labelFieldLabel:Z(`engine.studio.app.nameLabel`,s),labelPlaceholder:Z(`engine.studio.app.namePlaceholder`,s),idFieldLabel:Z(`engine.studio.app.idLabel`,s),idPlaceholder:Z(`engine.studio.app.idPlaceholder`,s),submitLabel:Z(`engine.studio.createDraft`,s),submittingLabel:Z(`engine.studio.creating`,s),busy:ne,error:L,locale:s,onSubmit:({label:e,name:t})=>void le(e,t),extra:(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:R,onChange:e=>se(e.target.checked),className:`h-3.5 w-3.5 accent-primary`}),Z(`engine.studio.app.scaffoldNav`,s)]})})]})})}function Sx({nodes:e,active:t,onPick:n,objectIcons:r}){let i=El(),a=ds();return(0,$.jsx)($.Fragment,{children:e.map((e,o)=>{let s=lo(e,i,a);if(e.type===`group`||Array.isArray(e.children)&&e.children.length)return(0,$.jsxs)(`div`,{className:`mb-1`,children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-1 px-2 pb-1 pt-3 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(ti,{className:`h-3 w-3`}),` `,s]}),(0,$.jsx)(`div`,{className:`pl-1.5`,children:(0,$.jsx)(Sx,{nodes:e.children??[],active:t,onPick:n,objectIcons:r})})]},e.id??o);let c=db(e,i,a),l=c?.type===`object`?r?.[c.name]:void 0,u=e.icon?Wc(e.icon):l?Wc(l):vx(e.type),d=!!c&&t?.type===c.type&&t?.name===c.name;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>c&&n(c),disabled:!c,title:c?`${c.type} · ${c.name}`:s||void 0,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs disabled:opacity-40 `+(d?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,$.jsx)(u,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:s||c?.name}),c&&c.type!==`page`&&(0,$.jsx)(`span`,{className:`text-[9px] tracking-wide text-muted-foreground/60`,children:Ol(c.type,i)})]},e.id??o)})})}function Cx({navId:e,appDraft:t,objects:n,onNavPatch:r,onClear:i}){let a=El(),o=ds(),s=Q.useMemo(()=>{let t=/^navigation\[(\d+)\]$/.exec(e);return t?Number(t[1]):-1},[e]),c=Q.useMemo(()=>Array.isArray(t.navigation)?t.navigation:[],[t]),l=s>=0?c[s]:null;if(!l)return(0,$.jsx)(`div`,{className:`px-2 py-10 text-center text-xs text-muted-foreground`,children:Z(`engine.studio.nav.selectItem`,a)});let u=e=>{r({navigation:c.map((t,n)=>n===s?{...t,...e}:t)})},d=String(l.objectName??l.object??``),f=l.label,p=e=>{let t=e===``?wo(f,a):To(f,e,a);r({navigation:c.map((e,n)=>{if(n!==s)return e;if(t!==void 0)return{...e,label:t};let r={...e};return delete r.label,r})})},m=e=>{u({id:l.id||`nav_${e}`,type:`object`,objectName:e,object:void 0,path:void 0})};return(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.nav.label`,a)}),(0,$.jsx)(`input`,{value:So(f,a),onChange:e=>p(e.target.value),placeholder:_o(l,o),className:`w-full rounded border bg-background px-2 py-1 text-xs`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.nav.linkObject`,a)}),(0,$.jsxs)(`select`,{value:d,onChange:e=>{let t=e.target.value;if(!t){u({type:void 0,objectName:void 0,object:void 0});return}m(t)},className:`w-full rounded border bg-background px-2 py-1 text-xs`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.nav.chooseObject`,a)}),n.map(e=>(0,$.jsxs)(`option`,{value:e.name,children:[e.label,` (`,e.name,`)`]},e.name))]}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:Z(d?`engine.studio.nav.boundHint`:`engine.studio.nav.unboundHint`,a)}),n.length===0&&(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-amber-600 dark:text-amber-400`,children:Z(`engine.studio.nav.noObjects`,a)})]}),(0,$.jsx)(`button`,{type:`button`,onClick:i,className:`text-[11px] text-muted-foreground underline-offset-2 hover:underline`,children:Z(`engine.studio.deselect`,a)})]})}var wx=e=>`${e?.type??``}:${e?.name??``}`;function Tx({packageId:e,publishNonce:t=0,draftNonce:n=0,onDraftSaved:r,onCreateApp:i,readOnly:a=!1,readOnlySettled:o=!0,foldInspector:s=!1,onDirtyChange:c,onSurfaceLabelChange:l}){let u=Da(),d=El(),f=de(),[p,m]=Q.useState(!1),[h,g]=Q.useState(e),[_,v]=Q.useState(null),[y,b]=Q.useState({}),[x,S]=Q.useState(``),C=Q.useRef({}),w=Q.useMemo(()=>Array.isArray(y.navigation)?y.navigation:[],[y]),[T,E]=Q.useState(!1),[D,O]=Q.useState(null),[k,A]=Q.useState(!1),[j,M]=Q.useState(`loading`);Q.useEffect(()=>{a&&(T&&(E(!1),O(null)),k&&(b(C.current),A(!1)))},[a,T,k]);let N=Q.useMemo(()=>({navigation:w}),[w]);Yc({enabled:!0,draft:N,loaded:j===`ready`,readOnly:o?a:void 0,selection:D,onApply:(e,{enterEditing:t})=>{t&&E(!0),O({kind:`nav`,id:e.selectionId})}});let ee=Q.useRef(c);Q.useEffect(()=>{ee.current=c}),Q.useEffect(()=>{ee.current?.(k)},[k]);let P=Q.useRef({dirty:k});Q.useEffect(()=>{P.current={dirty:k}},[k]),Q.useEffect(()=>()=>{ee.current?.(!1)},[]);let[F,te]=Q.useState(!1),[I,ne]=Q.useState(!1),re=ub(k||!!I),[L,ie]=Q.useState(null),ae=ds(),oe=Q.useRef(ae);Q.useEffect(()=>{oe.current=ae});let R=pb(L),se=Q.useRef(l);Q.useEffect(()=>{se.current=l});let ce=L?.type,le=L?.name,z=L?.label;Q.useEffect(()=>{se.current?.(ce&&le&&z?{type:ce,name:le,label:z}:null)},[ce,le,z]),Q.useEffect(()=>()=>{se.current?.(null)},[]);let[fe,pe]=Q.useState(`source`),[B,me]=Q.useState({}),[he,ge]=Q.useState(``),_e=wx(L),[V,ve]=Q.useState({key:``,value:null}),H=V.key===_e?V.value:null,U=Q.useCallback(e=>ve({key:_e,value:e}),[_e]),[ye,be]=Q.useState(`canvas`),xe=Gy(),W=s&&!xe,[Se,Ce]=Q.useState(!1),we=!W,Te=!!(T&&D||H),Ee=Q.useRef(Te);Q.useEffect(()=>{if(!W)return;let e=Ee.current;Ee.current=Te,be(t=>Uy(t,e,Te))},[W,Te]);let[De,Oe]=Q.useState(!1),[ke,Ae]=Q.useState(!1),[je,Me]=Q.useState(!1),[Ne,G]=Q.useState(null),[Pe,Ie]=Q.useState([]),Re=Q.useMemo(()=>Object.fromEntries(Pe.map(e=>[e.name,e.icon])),[Pe]);Q.useEffect(()=>{let t=!1;return(async()=>{try{let[n,r]=await Promise.all([u.list(`object`,{packageId:e}),u.listDrafts({packageId:e,type:`object`}).catch(()=>[])]);if(t)return;let i=new Map;for(let e of[...n||[],...r||[]]){let t=e,n=String(t.name??``);n&&!i.has(n)&&i.set(n,{name:n,label:String(t.label??t.name??n),icon:t.icon?String(t.icon):void 0})}Ie([...i.values()])}catch{}})(),()=>{t=!0}},[u,e,t,n,re]);let ze=Q.useRef(null);Q.useEffect(()=>{let t=!1,n=ze.current===e;return ze.current=e,n||M(`loading`),(async()=>{try{let r=await u.list(`app`,{packageId:e});if(t)return;let i=r?.[0]?.name?String(r[0].name):null,a=r?.[0]?r[0].label??r[0].name??e:e;if(!i){let n=await u.listDrafts({packageId:e,type:`app`});if(t)return;let r=n?.[0];r?.name&&(i=String(r.name),a=String(r.name))}if(!i){M(`missing`);return}g(a),v(i);let[o,s]=await Promise.all([u.layered(`app`,i),u.getDraft(`app`,i).catch(()=>null)]);if(t)return;let c=o,l=c.effective??c.code??{},f=dr(s),p=f??l,m=p.label??p.name;m!=null&&g(m),(!n||!P.current.dirty)&&(b(p),S(`app:${i}`)),C.current=p,te(!!f),M(`ready`);let h=Array.isArray(p.navigation)?p.navigation:[],_=oe.current,y=(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=db(n,d,_);if(e)return e}return null})(h),x=R?fb(h,R,d,_):null;ie(e=>e??x??y)}catch(e){t||(G(or(e)),M(`missing`))}})(),()=>{t=!0}},[u,e,t,n,re]);let Be=pc(L?.type??``),Ve=Eo(L?.type??``),He=fc(L?.type??``),Ue=mc(L?.type??``),We=ac().length===0&&lc().length===0,[K,Ge]=Q.useState({key:``,count:0}),Ke=`${_e}:${H?`${H.kind}:${H.id}`:`default`}`,qe=K.key===Ke?K.count:0,Je=!!Be&&!Ve,[Ye,Xe]=Q.useState(`design`),q=Ye===`design`,Ze=L?.type===`page`?B?.kind:void 0,Qe=Ze===`html`||Ze===`react`;Q.useEffect(()=>{if(!L||!Je){me({}),ge(wx(L)),Me(!1),et(!1);return}let e=!1,t=!1;return Oe(!0),G(null),U(null),(async()=>{try{let[t,n]=await Promise.all([u.layered(L.type,L.name),u.getDraft(L.type,L.name).catch(()=>null)]);if(e)return;let r=t.effective??t.code??{},i=dr(n);me(i??r),ge(wx(L)),Me(!!i),et(!1)}catch(t){e||G(or(t))}finally{t=!0,e||Oe(!1)}})(),()=>{e=!0,t||Oe(!1)}},[u,L,Je,t]);let[$e,et]=Q.useState(!1),tt=Q.useCallback(e=>{me(t=>({...t,...e})),et(!0)},[]),nt=Q.useCallback(async t=>{if(L){Ae(`draft`);try{await u.save(L.type,L.name,fx(L.type,B),{mode:`draft`,packageId:e}),Me(!0),t.unmoved()&&et(!1),r?.()}catch(e){G(or(e))}finally{Ae(!1)}}},[u,L,B,r]),{loaded:it}=mx({target:_e,loadedFor:he,dirty:$e,blocked:!L||!Je||!!ke||a||qe>0,snapshot:B,save:nt}),at=Q.useCallback(e=>{b(t=>({...t,...e})),A(!0)},[]),ot=Q.useCallback(async t=>{if(_){ne(`draft`);try{let n=(Array.isArray(y.navigation)?y.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}`}}),i={...y,navigation:n};await u.save(`app`,_,i,{mode:`draft`,packageId:e}),C.current=i,te(!0),t.unmoved()&&A(!1),r?.()}catch(e){G(or(e))}finally{ne(!1)}}},[u,_,y,r]),{flush:st}=mx({target:`app:${_??``}`,loadedFor:x,dirty:k,blocked:!_||!T||!!I||a,snapshot:y,save:ot}),[ct,lt]=Q.useState(!1);Q.useEffect(()=>{ct&&!I&&(k&&st()||(lt(!1),!k&&(E(!1),O(null))))},[ct,I,k,st]);let ut=!(j===`missing`&&!Ne)&&!!L&&!De&&it&&!Ve&&!Qe&&!!Be,dt=(0,$.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-auto bg-muted/30 p-4`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex shrink-0 items-center gap-2`,children:[!Ve&&(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-0.5 rounded-lg bg-muted p-1`,"data-testid":`canvas-mode-toggle`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>Xe(`design`),"aria-pressed":q,className:`rounded-md px-2.5 py-0.5 text-[11px] transition-all `+(q?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.if.modeDesign`,d)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>Xe(`run`),"aria-pressed":!q,className:`rounded-md px-2.5 py-0.5 text-[11px] transition-all `+(q?`text-muted-foreground hover:text-foreground`:`bg-background font-medium text-foreground shadow-sm`),children:Z(`engine.studio.if.modeRun`,d)})]}),L&&(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,title:`${Z(`engine.studio.if.internalId`,d)}: ${L.type} · ${L.name}`,"data-testid":`if-canvas-caption`,children:[L.label||L.name,` · `,Ol(L.type,d)]})]}),Ne&&(0,$.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:Ne}),(0,$.jsx)(`div`,{className:Le(Qe?`min-h-0 flex-1 overflow-hidden`:ut?void 0:`rounded-lg border bg-background p-4`),children:j===`missing`&&!Ne?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 py-16 text-center`,children:[(0,$.jsx)(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,$.jsx)(pi,{className:`h-6 w-6 text-muted-foreground`})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.if.noAppTitle`,d)}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:Z(`engine.studio.if.noAppHint`,d)})]}),i&&(0,$.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,$.jsx)(Ri,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.app.create`,d)]})]}):L?De||!it?Ne&&!De?null:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground`,children:[(0,$.jsx)(X,{className:`h-4 w-4 animate-spin`}),` `,Z(`engine.studio.loading`,d)]}):Ve?(0,$.jsx)(Ve,{type:L.type,name:L.name,draft:B,locale:d}):Qe?(0,$.jsx)(fo,{mode:`preview`,draft:B,readOnly:!0,locale:d}):Be?(0,$.jsx)(Be,{type:L.type,name:L.name,draft:B,editing:q,selection:q?H:null,onSelectionChange:q?U:void 0,onPatch:a?void 0:tt,locale:d}):(0,$.jsx)(`div`,{className:`py-12 text-center text-xs text-muted-foreground`,children:Dl(We?`engine.studio.if.designersMissing`:`engine.studio.if.noDesigner`,d,{type:L.type})}):(0,$.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.if.pickLeft`,d)})}),!Je&&L?.type===`object`?(0,$.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(Gr,{className:`h-3 w-3`}),` `,Z(`engine.studio.if.objectHintPre`,d),(0,$.jsx)(`span`,{className:`font-medium`,children:`Data`}),Z(`engine.studio.if.objectHintPost`,d)]}):null]}),ft=(0,$.jsxs)(`header`,{className:`flex shrink-0 items-center gap-2 border-b bg-background/95 px-3 py-2`,children:[(0,$.jsx)($i,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.inspector.props`,d)}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5`,children:[H&&!Ve&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>U(null),className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.deselect`,d),children:(0,$.jsx)(ba,{className:`h-3.5 w-3.5`})}),we&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>Ce(!0),className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.inspector.collapse`,d),title:Z(`engine.studio.inspector.collapse`,d),children:(0,$.jsx)(Fi,{className:`h-3.5 w-3.5`})})]})]}),pt=(0,$.jsxs)(`aside`,{className:`flex w-9 shrink-0 flex-col items-center gap-1.5 border-l bg-background py-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>Ce(!1),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.inspector.expand`,d),title:Z(`engine.studio.inspector.props`,d),children:(0,$.jsx)(Ii,{className:`h-4 w-4`})}),(0,$.jsx)($i,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),mt=T&&D?(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsx)(Cx,{navId:D.id,appDraft:y,objects:Pe,onNavPatch:at,onClear:()=>O(null)})}):Ve&&L?(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(Xr,{className:`h-5 w-5`}),Z(`engine.studio.inspector.studioCanvasNoBlocks`,d)]})}):L&&!it?(0,$.jsx)(`div`,{className:`min-h-0 flex-1`}):H&&He&&L?(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsx)(He,{type:L.type,name:L.name,draft:B,selection:H,onPatch:tt,onClearSelection:()=>U(null),onSelectionChange:U,onBlockingIssuesChange:e=>Ge({key:Ke,count:e}),readOnly:a,locale:d})}):Qe?W?(0,$.jsx)(`div`,{className:`mt-2 min-h-0 flex-1 border-t`,children:(0,$.jsx)(fo,{mode:`editor`,draft:B,onPatch:a?void 0:tt,readOnly:a,locale:d})}):(0,$.jsxs)(Fe,{value:fe,onValueChange:e=>pe(e===`props`?`props`:`source`),className:`flex min-h-0 flex-1 flex-col`,children:[(0,$.jsxs)(rt,{className:`mx-3 mt-2 shrink-0 self-start`,children:[(0,$.jsxs)(Nt,{value:`source`,className:`gap-1 text-xs`,children:[(0,$.jsx)(Hr,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.inspector.tabSource`,d)]}),(0,$.jsx)(Nt,{value:`props`,className:`text-xs`,children:Z(`engine.studio.inspector.tabProps`,d)})]}),(0,$.jsx)(ue,{value:`source`,className:`mt-2 min-h-0 flex-1 border-t`,children:(0,$.jsx)(fo,{mode:`editor`,draft:B,onPatch:a?void 0:tt,readOnly:a,locale:d})}),(0,$.jsx)(ue,{value:`props`,className:`mt-0 min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(Hr,{className:`h-5 w-5`}),Dl(`engine.studio.inspector.sourcePageLine1`,d,{kind:Ze}),(0,$.jsx)(`br`,{}),Z(`engine.studio.inspector.sourcePageLine2`,d)]})})]}):Ue&&L&&Je?(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsx)(Ue,{type:L.type,name:L.name,draft:B,onPatch:tt,onSelectionChange:U,onBlockingIssuesChange:e=>Ge({key:Ke,count:e}),readOnly:a,locale:d})}):We?(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(vr,{className:`h-5 w-5`}),Z(`engine.studio.inspector.designersMissing`,d)]})}):(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(ki,{className:`h-5 w-5`}),Z(`engine.studio.inspector.emptyLine1`,d),(0,$.jsx)(`br`,{}),Z(`engine.studio.inspector.emptyLine2`,d)]})});return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>m(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,d),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,$.jsx)(Ci,{className:`h-4 w-4`})}),L?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-muted-foreground`,title:`${Z(`engine.studio.if.internalId`,d)}: ${L.type} · ${L.name}`,"data-testid":`if-breadcrumb`,children:[(0,$.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:L.label||L.name}),(0,$.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:Ol(L.type,d)})]}):(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.if.pickLeft`,d)}),je&&it&&(0,$.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`,d)}),ke===`draft`&&(0,$.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 text-[11px] text-muted-foreground`,"data-testid":`if-autosaving`,children:[(0,$.jsx)(X,{className:`h-3 w-3 animate-spin`}),Z(`engine.studio.autoSaving`,d)]})]}),(0,$.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[f&&p&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>m(!1),"aria-hidden":`true`}),(0,$.jsxs)(`nav`,{className:Le((T?`w-72`:`w-52`)+` flex shrink-0 flex-col border-r bg-background`,f&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,f&&!p&&`-translate-x-full`),children:[(0,$.jsxs)(`div`,{className:`shrink-0 border-b px-2 py-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-1`,children:[(0,$.jsx)(`p`,{className:`truncate text-[11px] font-medium text-muted-foreground`,children:Dl(`engine.studio.if.navHeading`,d,{app:So(h,d)})}),j===`ready`&&!a&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>{if(T){lt(!0);return}E(!0),O(null)},title:Z(T?`engine.studio.if.doneEditTitle`:`engine.studio.if.editNavTitle`,d),className:`inline-flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[10px] `+(T?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted`),children:T?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(kr,{className:`h-3 w-3`}),` `,Z(`engine.studio.done`,d)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Li,{className:`h-3 w-3`}),` `,Z(`engine.studio.edit`,d)]})})]}),T&&(0,$.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[F&&(0,$.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`,d)}),I===`draft`&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground`,"data-testid":`nav-autosaving`,children:[(0,$.jsx)(X,{className:`h-3 w-3 animate-spin`}),Z(`engine.studio.autoSaving`,d)]})]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:j===`missing`&&!Ne?(0,$.jsxs)(`div`,{className:`px-2 py-3`,children:[(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.if.noApp`,d)}),i&&(0,$.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,$.jsx)(Ri,{className:`h-3 w-3`}),` `,Z(`engine.studio.app.create`,d)]})]}):T?(0,$.jsx)(xo,{draft:y,rootKey:`navigation`,onPatch:at,selection:D,onSelectionChange:e=>O(e?{kind:e.kind,id:e.id}:null)}):w.length===0?(0,$.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(Ne?`engine.studio.loadFailed`:j===`loading`?`engine.studio.loading`:`engine.studio.if.noNavItems`,d)}):(0,$.jsx)(Sx,{nodes:w,active:L,objectIcons:Re,onPick:e=>{ie(e),f&&m(!1)}})})]}),s?xe?(0,$.jsxs)($.Fragment,{children:[dt,Se?pt:(0,$.jsxs)(`aside`,{"data-testid":`studio-folded-inspector`,className:Le(`flex shrink-0 flex-col overflow-hidden border-l`,Qe&&!(H&&He&&L)&&!(T&&D)?`w-[22rem] 2xl:w-[28rem]`:`w-72 2xl:w-80`),children:[ft,mt]})]}):(0,$.jsxs)(Fe,{value:ye,onValueChange:e=>be(e===`properties`?`properties`:`canvas`),className:`flex min-w-0 flex-1 flex-col`,"data-testid":`studio-center-tabs`,children:[(0,$.jsxs)(rt,{className:`mx-3 mt-2 shrink-0 self-start`,children:[(0,$.jsxs)(Nt,{value:`canvas`,className:`gap-1 text-xs`,children:[(0,$.jsx)(Xr,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.if.tabCanvas`,d)]}),(0,$.jsxs)(Nt,{value:`properties`,className:`gap-1 text-xs`,children:[(0,$.jsx)($i,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.inspector.props`,d)]})]}),(0,$.jsx)(ue,{forceMount:!0,value:`canvas`,className:`mt-0 flex min-h-0 flex-1 flex-col data-[state=inactive]:hidden`,children:dt}),(0,$.jsxs)(ue,{value:`properties`,className:`mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:[ft,mt]})]}):(0,$.jsxs)($.Fragment,{children:[dt,Se?pt:(0,$.jsxs)(`aside`,{className:Le(`flex shrink-0 flex-col overflow-hidden border-l`,Qe&&!(H&&He&&L)&&!(T&&D)?`w-[24rem] xl:w-[30rem] 2xl:w-[36rem]`:`w-72`),children:[ft,mt]})]})]})]})}function Ex(e){let t=e.length+1,n=`field_${t}`;for(;e.includes(n);)n=`field_${++t}`;return n}var Dx=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 Ox(e){let{schema:t,dataSource:n,onEdit:r,className:i,onAddRecord:a}=e;return(0,$.jsx)(yl,{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:a,className:i})}function kx({packageId:e,publishNonce:t=0,onDraftSaved:n,readOnly:r=!1}){let i=Da(),a=un(),o=El(),s=tr(),{entries:c}=ka(i),l=Q.useMemo(()=>{let e={};for(let t of c)e[t.type]=t.schema;return e},[c]),u=de(),[d,f]=Q.useState(!1),[p,m]=Q.useState([]),[h,g]=Q.useState(!1),_=ub(),[v,y]=Q.useState(null),b=pb(v),x=Jh(),S=Q.useRef(0);Q.useEffect(()=>{if(!x||!h||x.id===S.current)return;S.current=x.id;let e=mb(p,x.target,`object`);e&&y(e)},[x,p,h]);let[C,w]=Q.useState({}),[T,E]=Q.useState(``),[D,O]=Q.useState(!1),[k,A]=Q.useState(null),[j,M]=Q.useState(null),[N,ee]=Q.useState({key:``,count:0}),P=j?`${v?.name??``}:${j.kind}:${j.id}`:``,F=N.key===P?N.count:0,[te,I]=Q.useState({key:``,count:0}),[ne,re]=Q.useState(!1),[L,ie]=Q.useState(!1),[ae,oe]=Q.useState(!1),[R,se]=Q.useState(null),[ce,le]=Q.useState(0),[z,ue]=Q.useState(`grid`),fe=`${v?.name??``}:${z}`,pe=te.key===fe?te.count:0,B=Q.useCallback(e=>I({key:fe,count:e}),[fe]),me=F+pe,[he,ge]=Q.useState(`layout`),_e=Q.useRef(null),[V,ve]=Q.useState(``),[H,U]=Q.useState(!1),[ye,be]=Q.useState(Cb),xe=Q.useCallback(()=>{A(null),be(Cb),U(!0)},[]),[W,Se]=Q.useState(!1),[Ce,we]=Q.useState(!0),[Te,Ee]=Q.useState(new Set),[De,Oe]=Q.useState(null);Q.useEffect(()=>{let t=!1;return sc().then(n=>{t||Oe(n.find(t=>t.id===e)?.namespace??null)}).catch(e=>{t||Y.error(or(e),{id:yx})}),()=>{t=!0}},[e]),Q.useEffect(()=>{let t=!1;return(async()=>{try{let[n,r]=await Promise.all([i.list(`object`,{packageId:e}),i.listDrafts({packageId:e,type:`object`}).catch(()=>[])]);if(t)return;let a=(n||[]).map(e=>({type:`object`,name:String(e.name??``),label:String(e.label??e.name??``),icon:e.icon?String(e.icon):void 0})).filter(e=>e.name),o=new Set(a.map(e=>e.name));for(let e of r)e.name&&!o.has(e.name)&&a.push({type:`object`,name:e.name,label:e.name,icon:void 0});m(a);let s=mb(a,b,`object`);y(e=>e??s??a[0]??null)}catch(e){t||A(or(e))}finally{t||g(!0)}})(),()=>{t=!0}},[i,e,r,_]),Q.useEffect(()=>{if(!v)return;let e=`${v.name}#${t}`;if(_e.current===e)return;_e.current=e;let n=!1,r=!1;return O(!0),A(null),M(null),re(!1),(async()=>{try{let[e,t]=await Promise.all([i.layered(`object`,v.name),i.getDraft(`object`,v.name).catch(()=>null)]);if(n)return;let r=e,a=r.effective??r.code??{},o=dr(t);w(o??a),E(`object:${v.name}`),re(!1),ie(!!o),we(!!(r.effective??r.code)),Ee(new Set(el(a.fields).entries.map(e=>e.name)))}catch(e){n||A(or(e))}finally{r=!0,n||O(!1)}})(),()=>{n=!0,r||(O(!1),_e.current=null)}},[i,v,t]);let ke=Q.useMemo(()=>el(C.fields).entries.length,[C]),Ae=Q.useMemo(()=>el(C.fields).entries.map(e=>e.name).filter(e=>!Dx.has(e)&&e!==`actions`).filter(e=>Te.has(e)),[C.fields,Te]),je=Q.useMemo(()=>el(C.fields).entries.map(e=>e.name).filter(e=>!Dx.has(e)),[C.fields]),Me=Q.useCallback(e=>{w(t=>({...t,...e})),re(!0)},[]),Ne=Q.useCallback(async(t,a,s)=>{if(r)return;let c=ic(a,De);if(p.some(e=>e.name===c)){A(Dl(`engine.studio.data.idExists`,o,{name:c}));return}Se(!0),A(null);try{let r=hb(c,t,Z(`engine.studio.data.nameFieldLabel`,o),s);await i.save(`object`,c,r,{mode:`draft`,packageId:e});let a={type:`object`,name:c,label:t};m(e=>[...e,a]),y(a),ue(`form`),ge(`layout`),U(!1),n?.()}catch(e){A(or(e))}finally{Se(!1)}},[p,i,e,n,r,o,De]),G=Q.useCallback(async t=>{if(v){oe(`draft`),A(null);try{await i.save(`object`,v.name,C,{mode:`draft`,packageId:e}),ie(!0),t.unmoved()&&re(!1),se(new Date),n?.()}catch(e){A(or(e))}finally{oe(!1)}}},[i,v,C,n,e,o]),{sending:Pe,loaded:Fe}=mx({target:`object:${v?.name??``}`,loadedFor:T,dirty:ne,blocked:!v||!!ae||r||me>0,snapshot:C,save:G}),Ie=Q.useCallback(()=>{if(r||!Fe)return;let e=el(C.fields),t=Ex(e.entries.map(e=>e.name));e.entries.push(il(t,`text`,Z(`engine.studio.data.newFieldLabel`,o))),w(t=>({...t,fields:al(e)})),re(!0),M({kind:`field`,id:t})},[C,r,Fe]),Re=Q.useCallback(async t=>{if(!v)return;let r=el(C.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={...C,fields:al({...r,entries:c})},u=Pe(l);if(u){w(l),oe(`draft`),A(null);try{await i.save(`object`,v.name,l,{mode:`draft`,packageId:e}),ie(!0),u.unmoved()&&re(!1),n?.(),le(e=>e+1)}catch(e){A(or(e))}finally{oe(!1)}}},[i,v,C,n,Pe]),ze=fc(`object`),Be=[{key:`grid`,label:Z(`engine.studio.data.tab.records`,o)},{key:`form`,label:Z(`engine.studio.data.tab.form`,o)}],Ve=[{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)}],He=Ve.find(e=>e.key===z),Ue=Wc(Fe&&typeof C.icon==`string`?C.icon:v?.icon);return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-3 py-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>f(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,$.jsx)(Ci,{className:`h-4 w-4`})}),v?(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(Ue,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate text-[15px] font-semibold leading-none text-foreground`,children:v.label}),(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-muted/70 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground`,children:v.name}),Fe&&(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:Dl(`engine.studio.data.fieldCount`,o,{count:ke})})]}):(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,o)}),L&&Fe&&(0,$.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)}),ae===`draft`?(0,$.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 text-[11px] text-muted-foreground`,"data-testid":`data-autosaving`,children:[(0,$.jsx)(X,{className:`h-3 w-3 animate-spin`}),Z(`engine.studio.autoSaving`,o)]}):R&&!ne?(0,$.jsx)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,"data-testid":`data-saved-at`,children:Dl(`engine.studio.data.lastSaved`,o,{time:R.toLocaleTimeString(s,{hour:`2-digit`,minute:`2-digit`})})}):null]}),(0,$.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[u&&d&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>f(!1),"aria-hidden":`true`}),(0,$.jsxs)(`nav`,{className:Le(`flex w-52 shrink-0 flex-col border-r bg-background`,u&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,u&&!d&&`-translate-x-full`),children:[(0,$.jsxs)(`div`,{className:`shrink-0 p-2 pb-1`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1 pt-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.data.objects`,o)}),(0,$.jsx)(`input`,{value:V,onChange:e=>ve(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,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2 pt-1`,children:[p.length===0&&(0,$.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(k?`engine.studio.loadFailed`:h?`engine.studio.data.noObjects`:`engine.studio.loading`,o)}),p.filter(e=>!V.trim()||e.label.toLowerCase().includes(V.trim().toLowerCase())||e.name.toLowerCase().includes(V.trim().toLowerCase())).map(e=>{let t=Wc(e.icon);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{y(e),u&&f(!1)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(v?.name===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,$.jsx)(t,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.label})]},e.name)})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t p-2`,children:r?(0,$.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,$.jsx)(_i,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,o)]}):(0,$.jsxs)(`button`,{type:`button`,onClick:xe,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,$.jsx)(Ri,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.newObject`,o)]})})]}),(0,$.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden p-4`,children:v?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-4 flex shrink-0 items-center gap-3`,children:[(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-0.5 rounded-lg bg-muted p-1`,children:[Be.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>ue(e.key),"aria-pressed":z===e.key,className:`rounded-md px-3 py-1 text-[13px] transition-all `+(z===e.key?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:e.label},e.key)),(0,$.jsxs)(it,{children:[(0,$.jsx)(yt,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,"data-testid":`data-tabs-advanced`,"aria-pressed":!!He,className:`inline-flex items-center gap-1 rounded-md px-3 py-1 text-[13px] transition-all `+(He?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:[He?He.label:Z(`engine.studio.data.tab.advanced`,o),(0,$.jsx)(Ar,{className:`h-3 w-3`})]})}),(0,$.jsx)(Pt,{align:`start`,children:Ve.map(e=>(0,$.jsx)(kt,{onSelect:()=>ue(e.key),className:z===e.key?`font-medium text-primary`:void 0,children:e.label},e.key))})]})]}),(z===`grid`||z===`form`)&&!r&&Fe&&(0,$.jsxs)(`button`,{type:`button`,onClick:Ie,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,$.jsx)(Ri,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.addField`,o)]})]}),k&&(0,$.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:k}),Fe?z===`rules`?(0,$.jsx)(Kb,{draft:C,onPatch:Me,disabled:r,onBlockingIssuesChange:B}):z===`settings`?(0,$.jsx)(qb,{name:v.name,draft:C,onPatch:Me,locale:o,disabled:r,onBlockingIssuesChange:B}):z===`hooks`?(0,$.jsx)(ix,{objectName:v.name,packageId:e,disabled:r,hookSchema:l.hook}):z===`actions`?(0,$.jsx)(cx,{draft:C,onPatch:Me,disabled:r,actionSchema:l.action,onBlockingIssuesChange:B}):z===`api`?(0,$.jsx)(ex,{name:v.name,draft:C}):z===`grid`&&!Ce?(0,$.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,$.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.draftObjectTitle`,o)}),(0,$.jsx)(`p`,{className:`max-w-md text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.draftObjectHint`,o)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{ue(`form`),ge(`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)})]}):z===`grid`?(0,$.jsx)($.Fragment,{children:(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background`,children:(0,$.jsx)(Lt,{value:{...r?{}:{onAddColumn:Ie,addColumnLabel:Z(`engine.studio.data.addField`,o),onReorderFields:Re},onEditColumn:e=>{el(C.fields).entries.some(t=>t.name===e)&&M({kind:`field`,id:e})},editColumnLabel:Z(`engine.studio.data.editFieldProps`,o)},children:(0,$.jsx)(Mn,{dataSource:a,children:(0,$.jsx)(Cl,{schema:{type:`object-view`,objectName:v.name,showCreate:!1,table:{fields:Ae}},dataSource:a,renderListView:Ox},`${v.name}:${ce}`)})})})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-0.5 rounded-lg bg-muted p-0.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>ge(`layout`),"aria-pressed":he===`layout`,className:`rounded-md px-2.5 py-0.5 text-[12px] transition-all `+(he===`layout`?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.form.layout`,o)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>ge(`preview`),"aria-pressed":he===`preview`,className:`rounded-md px-2.5 py-0.5 text-[12px] transition-all `+(he===`preview`?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.form.preview`,o)})]}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(he===`layout`?ne&&!r?`engine.studio.data.form.layoutBadge`:`engine.studio.data.form.layoutBadgeClean`:`engine.studio.data.form.previewBadge`,o)}),he===`preview`&&(ne||L)&&(0,$.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)})]}),he===`layout`?(0,$.jsx)(Pb,{draft:C,objectName:v.name,systemFieldNames:Dx,onChange:Me,selectedField:j?.kind===`field`?j.id:null,onSelectField:e=>M({kind:`field`,id:e}),selectedGroup:j?.kind===`group`?j.id:null,onSelectGroup:e=>M({kind:`group`,id:e}),onAddField:Ie,readOnly:r}):Ce?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`style`,{children:`
10
+ /* Design preview: the form is a click-to-select canvas, not a data-entry
11
+ * form. Disable interaction on field contents so a click anywhere on a
12
+ * field routes to its [data-field] wrapper (→ select), and neutralize the
13
+ * create/cancel footer so nothing is submittable here. */
14
+ .os-form-authoring [data-field]{border-radius:8px;cursor:pointer;transition:box-shadow .12s;padding:8px;margin:-8px 0;}
15
+ .os-form-authoring [data-field] *{pointer-events:none;}
16
+ .os-form-authoring [data-field]:hover{box-shadow:0 0 0 1px hsl(var(--border));}
17
+ .os-form-authoring form > div:last-child:has(button){display:none;}
18
+ ${j?.kind===`field`?`.os-form-authoring [data-field="${String(j.id).replace(/[^\w-]/g,``)}"]{box-shadow:0 0 0 2px hsl(var(--primary));}`:``}
19
+ `}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background p-6`,children:(0,$.jsx)(`div`,{className:`os-form-authoring mx-auto max-w-6xl`,onClick:e=>{let t=e.target.closest(`[data-field]`)?.getAttribute(`data-field`);t&&el(C.fields).entries.some(e=>e.name===t)&&M({kind:`field`,id:t})},children:(0,$.jsx)(Mn,{dataSource:a,children:(0,$.jsx)(Ra,{schema:{type:`object-form`,objectName:v.name,mode:`create`,fields:je},dataSource:a},`${v.name}:${ce}:form`)})})})]}):(0,$.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,$.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.form.noPublishedTitle`,o)}),(0,$.jsx)(`p`,{className:`max-w-md text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.form.noPublishedHint`,o)})]})]}):k&&!D?null:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground`,children:[(0,$.jsx)(X,{className:`h-4 w-4 animate-spin`}),` `,Z(`engine.studio.loading`,o)]})]}):h&&p.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-16 text-center`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.firstObjectTitle`,o)}),(0,$.jsx)(`p`,{className:`max-w-sm text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.firstObjectHint`,o)}),!r&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`empty-state-new-object`,onClick:xe,className:`mt-2 inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[(0,$.jsx)(Ri,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.newObject`,o)]})]}):(0,$.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,o)})}),v&&j&&Fe&&(0,$.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-l`,children:[(0,$.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,$.jsx)($i,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(j.kind===`group`?`engine.studio.data.groupProps`:`engine.studio.data.fieldProps`,o)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>M(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,$.jsx)(ba,{className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:j.kind===`group`?(0,$.jsx)(Fb,{draft:C,groupKey:j.id,onPatch:Me,onClose:()=>M(null),readOnly:r,locale:o}):ze?Q.createElement(ze,{type:`object`,name:v.name,draft:C,selection:j,onPatch:Me,onClearSelection:()=>M(null),onSelectionChange:M,onBlockingIssuesChange:e=>ee({key:P,count:e}),readOnly:r,locale:o}):(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(vr,{className:`h-5 w-5`}),Z(`engine.studio.data.fieldInspectorMissing`,o)]})})]})]}),(0,$.jsx)(wb,{open:H,onOpenChange:U,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:W,error:k,locale:o,extra:(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.data.owdLabel`,o)}),(0,$.jsx)(`select`,{value:ye,"data-testid":`create-object-owd`,onChange:e=>be(e.target.value),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:Sb.map(e=>(0,$.jsx)(`option`,{value:e,children:Z(lx[e],o)},e))}),(0,$.jsx)(`span`,{className:`mt-1 block text-[11px] text-muted-foreground`,children:Z(ux[ye],o)}),(0,$.jsx)(`span`,{className:`mt-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.data.owdHint`,o)})]}),onSubmit:({label:e,name:t})=>void Ne(e,t,ye)})]})}function Ax(e){let{triggerType:t,reason:n}=e;return{enabled:e.enabled!==!1,bound:!!e.bound,...typeof t==`string`&&t.length>0?{triggerType:t}:{},...typeof n==`string`&&n.length>0?{reason:n}:{}}}function jx({state:e,locale:t}){if(!e)return null;let{enabled:n,bound:r,triggerType:i,reason:a}=e,o=n?r?Z(`engine.studio.auto.onBound`,t):a||Z(i?`engine.studio.auto.enabled`:`engine.studio.auto.onUnbound`,t):Z(`engine.studio.auto.offTitle`,t);return(0,$.jsxs)(`span`,{title:o,className:`inline-flex shrink-0 items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full `+(n?`bg-emerald-500`:`bg-muted-foreground/40`)}),(0,$.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 Mx({packageId:e,publishNonce:t=0,onDraftSaved:n,readOnly:i=!1}){let a=Da(),o=El(),s=r(),c=e??void 0,l=de(),[u,d]=Q.useState(!1),[f,p]=Q.useState([]),m=ub(),[h,g]=Q.useState(null),_=pb(h),v=Q.useRef(!1),[y,b]=Q.useState({}),[x,S]=Q.useState(``),[C,w]=Q.useState(null),[T,E]=Q.useState(!1),[D,O]=Q.useState(!1),[k,A]=Q.useState(!1),[j,M]=Q.useState(null),[N,ee]=Q.useState(!1),P=N&&_?.type===`flow`&&!f.some(e=>e.name===_.name)?_.name:null,[F,te]=Q.useState(!1),[I,ne]=Q.useState(!1),re=pc(`flow`),L=fc(`flow`),ie=!!re,ae=ac().length===0&&lc().length===0,[oe,R]=Q.useState({});Q.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]=Ax(e));R(i)}catch{}})(),()=>{e=!0}},[t]),Q.useEffect(()=>{let t=!1;return(async()=>{try{let n=e===null?await cb(a,`flow`):await sb(a,`flow`,e);if(t)return;p(n);let r=mb(n,_,`flow`),i=_?.type===`flow`?_.name:null;if(i&&!r&&e!==null&&!v.current){v.current=!0;let e=await cb(a,`flow`).catch(()=>[]);if(t)return;if(e.some(e=>e.name===i)){s(tb({type:`flow`,name:i}),{replace:!0});return}}g(e=>e??r??(i?null:n[0])??null)}catch(e){t||M(or(e))}finally{t||ee(!0)}})(),()=>{t=!0}},[a,e,t,m]);let se=Q.useCallback(async(e,t)=>{ne(!0),M(null);try{let r=gb(t,e,Z(`engine.studio.auto.nodeStart`,o),Z(`engine.studio.auto.nodeEnd`,o));await a.save(`flow`,t,r,{mode:`draft`,packageId:c});let i={type:`flow`,name:t,label:e};p(e=>[...e.filter(e=>e.name!==t),i]),g(i),A(!0),te(!1),n?.(),Y.success(Dl(`engine.studio.auto.savedDraft`,o,{label:e}))}catch(e){M(or(e))}finally{ne(!1)}},[a,c,n,o]);Q.useEffect(()=>{if(!h)return;let e=!1,t=!1;return E(!0),M(null),w(null),(async()=>{try{let[t,n]=await Promise.all([a.layered(`flow`,h.name),a.getDraft(`flow`,h.name).catch(()=>null)]);if(e)return;let r=t,i=r.effective??r.code??{},o=dr(n);b(o??i),S(`flow:${h.name}`),A(!!o)}catch(t){e||M(or(t))}finally{t=!0,e||(E(!1),le(!1))}})(),()=>{e=!0,t||E(!1)}},[a,h,t]);let[ce,le]=Q.useState(!1),z=Q.useCallback(e=>{b(t=>({...t,...e})),le(!0)},[]),ue=Q.useCallback(async e=>{if(h){O(`draft`),M(null);try{await a.save(`flow`,h.name,y,{mode:`draft`,packageId:c}),A(!0),e.unmoved()&&le(!1),n?.()}catch(e){M(or(e))}finally{O(!1)}}},[a,h,y,c,n]),{sending:fe,loaded:pe}=mx({target:`flow:${h?.name??``}`,loadedFor:x,dirty:ce,blocked:!h||!ie||!!D||i,snapshot:y,save:ue}),B=y.status!==`obsolete`&&y.status!==`invalid`,me=Q.useRef(null);Q.useEffect(()=>{me.current=h?.name??null},[h]);let he=Q.useCallback(async()=>{if(!h||i)return;let e=h.name,t=y,r=y.status===`obsolete`||y.status===`invalid`,s=r?`active`:`obsolete`,l={...y,status:s};if(fe(l)){b(l),O(`draft`),M(null);try{await a.save(`flow`,e,l,{mode:`draft`,packageId:c}),A(!0),n?.(),Y.success(Z(r?`engine.studio.auto.enabledToast`:`engine.studio.auto.disabledToast`,o))}catch(n){b(n=>{if(me.current!==e||n.status!==s)return n;let{status:r,...i}=n;return`status`in t?{...i,status:t.status}:i}),M(or(n))}finally{O(!1)}}},[a,h,y,c,n,o,i,fe]);return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,o),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,$.jsx)(Ci,{className:`h-4 w-4`})}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.auto.defaultOff`,o)}),k&&pe&&(0,$.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)}),h&&pe&&(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":B,onClick:he,disabled:!ie||!!D||i,title:Z(i?`engine.studio.pkg.readonlyHint`:B?`engine.studio.auto.disableTitle`:`engine.studio.auto.enableTitle`,o),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,$.jsx)(`span`,{className:`relative inline-flex h-3.5 w-6 shrink-0 items-center rounded-full transition-colors `+(B?`bg-emerald-500`:`bg-muted-foreground/40`),children:(0,$.jsx)(`span`,{className:`inline-block h-2.5 w-2.5 rounded-full bg-white transition-transform `+(B?`translate-x-3`:`translate-x-0.5`)})}),Z(B?`engine.studio.auto.enabled`:`engine.studio.auto.disabled`,o)]}),D===`draft`&&(0,$.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 text-[11px] text-muted-foreground`,"data-testid":`auto-autosaving`,children:[(0,$.jsx)(X,{className:`h-3 w-3 animate-spin`}),Z(`engine.studio.autoSaving`,o)]})]}),(0,$.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[l&&u&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>d(!1),"aria-hidden":`true`}),(0,$.jsxs)(`nav`,{className:Le(`flex w-52 shrink-0 flex-col overflow-auto border-r bg-background p-2`,l&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,l&&!u&&`-translate-x-full`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pb-1 pt-1`,children:[(0,$.jsx)(`p`,{className:`flex-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.auto.heading`,o)}),!i&&e!==null&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{M(null),te(!0)},title:Z(`engine.studio.auto.newTitle`,o),className:`inline-flex items-center gap-0.5 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[(0,$.jsx)(Ri,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,o)]})]}),f.length>0&&f.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{g(e),l&&d(!1)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(h?.name===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,$.jsx)(ya,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),(0,$.jsx)(jx,{state:oe[e.name],locale:o})]},e.name)),f.length===0&&!F&&(0,$.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(j?`engine.studio.loadFailed`:N?e===null?`engine.studio.org.none`:`engine.studio.auto.none`:`engine.studio.loading`,o)})]}),(0,$.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-auto bg-muted/30 p-4`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex shrink-0 items-center gap-2`,children:[(0,$.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,$.jsx)(ya,{className:`h-3 w-3`}),` `,Z(ie?`engine.studio.auto.canvasHint`:`engine.studio.auto.designersMissing`,o)]}),h&&(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`flow · `,h.name]})]}),j&&(0,$.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:j}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 rounded-lg border bg-background p-4`,children:h?T||!pe?j&&!T?null:(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground`,children:[(0,$.jsx)(X,{className:`h-4 w-4 animate-spin`}),` `,Z(`engine.studio.loading`,o)]}):re?Q.createElement(re,{type:h.type,name:h.name,draft:y,editing:!0,selection:C,onSelectionChange:w,onPatch:i?void 0:z,locale:o}):(0,$.jsx)(`pre`,{className:`overflow-auto text-[11px] text-muted-foreground`,children:JSON.stringify(y,null,2)}):(0,$.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:P?Dl(`engine.studio.auto.deepLinkMissing`,o,{name:P}):Z(`engine.studio.auto.pick`,o)})})]}),(0,$.jsxs)(`aside`,{className:`w-72 shrink-0 overflow-auto border-l`,children:[(0,$.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,$.jsx)($i,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.auto.config`,o)}),C&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>w(null),className:`ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.deselect`,o),children:(0,$.jsx)(ba,{className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`div`,{className:`p-3`,children:C&&L&&h&&pe?Q.createElement(L,{type:`flow`,name:h.name,draft:y,selection:C,onPatch:z,onClearSelection:()=>w(null),onSelectionChange:w,readOnly:i,locale:o}):ae?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(vr,{className:`h-5 w-5`}),Z(`engine.studio.auto.designersMissing`,o)]}):(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(ki,{className:`h-5 w-5`}),Z(`engine.studio.auto.emptyLine1`,o),(0,$.jsx)(`br`,{}),Z(`engine.studio.auto.emptyLine2`,o)]})})]})]}),(0,$.jsx)(wb,{open:F,onOpenChange:te,title:Z(`engine.studio.auto.newTitle`,o),labelFieldLabel:Z(`engine.studio.auto.nameLabel`,o),labelPlaceholder:Z(`engine.studio.auto.namePlaceholder`,o),idFieldLabel:Z(`engine.studio.auto.idLabel`,o),idPlaceholder:Z(`engine.studio.auto.idPlaceholder`,o),submitLabel:Z(`engine.studio.createDraft`,o),submittingLabel:Z(`engine.studio.creating`,o),busy:I,error:j,locale:o,onSubmit:({label:e,name:t})=>void se(e,t)})]})}function Nx({packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r=!1,onDirtyChange:i}){let a=Da(),o=El(),s=de(),[c,l]=Q.useState(!1),u=ub(),[d,f]=Q.useState([]),[p,m]=Q.useState(!1),[h,g]=Q.useState(null),[_,v]=Q.useState(null),[y,b]=Q.useState(!1),[x,S]=Q.useState(null),C=Q.useRef(!1),w=pb(Q.useMemo(()=>y?{type:`owd`,name:`overview`}:_?{type:`permission`,name:_}:null,[y,_])),[T,E]=Q.useState(``),[D,O]=Q.useState(!1),[k,A]=Q.useState(null),[j,M]=Q.useState(!1),[N,ee]=Q.useState(!1),[P,F]=Q.useState(!1),[te,I]=Q.useState(!1),ne=P||te,re=Q.useRef(i);Q.useEffect(()=>{re.current=i}),Q.useEffect(()=>{re.current?.(ne)},[ne]),Q.useEffect(()=>()=>{re.current?.(!1)},[]);let L=Q.useCallback(()=>!ne||window.confirm(Z(`engine.edit.unsavedLeaveConfirm`,o)),[ne,o]),ie=Q.useCallback(async()=>{try{let[t,n]=await Promise.all([a.list(`permission`,{packageId:e}),a.listDrafts({packageId:e,type:`permission`}).catch(()=>[])]),r=new Map;for(let e of t||[]){let t=String(e.name??e.id??``);t&&r.set(t,{name:t,label:String(e.label??e.name??``),isDefault:!!e.isDefault})}for(let e of n||[]){let t=String(e?.name??``);t&&!r.has(t)&&r.set(t,{name:t,label:t})}let i=[...r.values()];f(i),!C.current&&w?.type===`owd`&&(C.current=!0,b(!0));let o=mb(i,w,`permission`);v(e=>e??o?.name??i[0]?.name??null)}catch(e){g(or(e))}finally{m(!0)}},[a,e]);Q.useEffect(()=>{ie()},[ie,t,u]);let ae=Q.useCallback(async(t,r)=>{M(!0),A(null);try{await a.save(`permission`,r,vb(r,t),{mode:`draft`,packageId:e}),Y.success(Dl(`engine.studio.access.created`,o,{label:t})),O(!1),n?.(),await ie(),b(!1),v(r)}catch(e){A(or(e))}finally{M(!1)}},[a,ie,e,n,o]),oe=d.filter(e=>!T.trim()||e.label.toLowerCase().includes(T.trim().toLowerCase())||e.name.toLowerCase().includes(T.trim().toLowerCase()));return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,$.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,$.jsx)(Ci,{className:`h-4 w-4`})}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(Qi,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:Z(`engine.studio.access.title`,o)}),(0,$.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:Z(`engine.studio.access.subtitle`,o)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ee(!0),className:`ml-auto flex items-center gap-1.5 rounded-md border px-2 py-0.5 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,$.jsx)(Zi,{className:`h-3.5 w-3.5`}),Z(`engine.studio.access.explain.open`,o)]}),(0,$.jsx)(`span`,{title:Z(`engine.studio.access.bannerTitle`,o),className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.access.banner`,o)})]}),!r&&(0,$.jsx)(Xs,{packageId:e,className:`mx-3 mt-2`,strings:{describe:e=>Dl(e.anchor===`guest`?`engine.studio.access.suggestPromptGuest`:`engine.studio.access.suggestPromptEveryone`,o,{set:e.permission_set_name}),confirm:Z(`engine.studio.access.suggestConfirm`,o),confirming:Z(`engine.studio.access.suggestConfirming`,o),dismiss:Z(`engine.studio.access.suggestDismiss`,o),confirmedToast:e=>Dl(`engine.studio.access.suggestConfirmedToast`,o,{set:e.permission_set_name,anchor:e.anchor}),dismissedToast:e=>Dl(`engine.studio.access.suggestDismissedToast`,o,{set:e.permission_set_name})}}),(0,$.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[s&&c&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>l(!1),"aria-hidden":`true`}),(0,$.jsxs)(`nav`,{className:Le(`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,$.jsx)(`div`,{className:`border-b p-2 pb-2`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{if(y){S(null),s&&l(!1);return}L()&&(b(!0),S(null),s&&l(!1))},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(y?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,$.jsx)(Xi,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:Z(`engine.studio.owd.railLabel`,o)})]})}),(0,$.jsxs)(`div`,{className:`p-2 pb-0`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1 pt-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.heading`,o)}),(0,$.jsx)(`input`,{value:T,onChange:e=>E(e.target.value),placeholder:Z(`engine.studio.access.search`,o),className:`mb-1 h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2 pt-1`,children:[d.length===0&&(0,$.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(h?`engine.studio.loadFailed`:p?`engine.studio.access.none`:`engine.studio.loading`,o)}),oe.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{if(!y&&_===e.name){s&&l(!1);return}L()&&(b(!1),v(e.name),s&&l(!1))},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(!y&&_===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,$.jsx)(Qi,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.isDefault&&(0,$.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/60`,children:`default`})]},e.name))]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t p-2`,children:r?(0,$.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,$.jsx)(_i,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,o)]}):(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{L()&&(A(null),O(!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,$.jsx)(Ri,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.access.new`,o)]})})]}),(0,$.jsx)(`main`,{className:`min-w-0 flex-1 overflow-auto`,children:y?(0,$.jsx)(Xb,{client:a,packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r,locale:o,highlightObject:x,onDirtyChange:I}):_?(0,$.jsx)(yo,{type:`permission`,name:_,packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r,onDirtyChange:F,embedded:!0,onOpenOwd:e=>{L()&&(S(e||null),b(!0))}},_):(0,$.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:p&&d.length===0?Z(`engine.studio.access.emptyMain`,o):Z(`engine.studio.access.pick`,o)})})]}),(0,$.jsx)(Zy,{open:N,onOpenChange:ee,packageId:e}),(0,$.jsx)(wb,{open:D,onOpenChange:O,title:Z(`engine.studio.access.new`,o),labelFieldLabel:Z(`engine.studio.access.nameLabel`,o),labelPlaceholder:Z(`engine.studio.access.labelPlaceholder`,o),idFieldLabel:Z(`engine.studio.access.idLabel`,o),idPlaceholder:Z(`engine.studio.access.idPlaceholder`,o),submitLabel:Z(`engine.studio.create`,o),submittingLabel:Z(`engine.studio.creating`,o),busy:j,error:k,locale:o,onSubmit:({label:e,name:t})=>void ae(e,t)})]})}function Px({value:e,onChange:t,onEnter:n,onEscape:r,placeholder:i,autoFocus:a,locale:o,testId:s}){let[c,l]=Q.useState(!1),u=e.trim().length>0&&!uc.test(e.trim());return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`input`,{autoFocus:a,value:e,onChange:e=>{let{value:n,stripped:r}=gc(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,$.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,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,"data-testid":`pkg-id-format-hint`,children:Z(`engine.studio.pkg.idFormatHint`,o)})]})}function Fx(){let e=r(),t=El(),[n,i]=Q.useState(null),[a,o]=Q.useState(null),[s,c]=Q.useState(!1);Q.useEffect(()=>{let e=!1;return sc().then(t=>{e||i(t)}).catch(t=>{e||o(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let l=t=>e(`/studio/${encodeURIComponent(t)}/data`),u=n?.filter(e=>e.writable)??[],d=n?.filter(e=>!e.writable)??[],[f,p]=Q.useState(null),[m,h]=Q.useState(``),[g,_]=Q.useState(``),[v,y]=Q.useState(!1),[b,x]=Q.useState(null),S=e=>{p(e.id),h(Dl(`engine.studio.landing.dupDefaultName`,t,{name:e.name})),_(`${e.id}-copy`),x(null)},C=async()=>{if(!f)return;let e=g.trim(),n=m.trim();if(uc.test(e)&&n){y(!0),x(null);try{await cc(f,e,n),Y.success(Dl(`engine.studio.landing.dupCreated`,t,{name:n})),l(e)}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(!1)}}};return(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl p-6`,children:[(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,$.jsx)(oi,{className:`h-4.5 w-4.5`})}),(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:Z(`engine.studio.landing.title`,t)})]}),(0,$.jsx)(`p`,{className:`mb-5 max-w-2xl text-xs leading-5 text-muted-foreground`,children:Z(`engine.studio.landing.description`,t)}),a&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive`,children:a}),(0,$.jsx)(`h2`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.landing.mineHeading`,t)}),(0,$.jsxs)(`div`,{className:`mb-6 grid grid-cols-1 gap-2.5 sm:grid-cols-2 lg:grid-cols-3`,children:[n===null&&(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,t)}),n!==null&&u.length===0&&(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.landing.noneWritable`,t)}),u.map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2.5`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(e.id),className:`flex min-w-0 flex-1 items-center gap-2.5 text-left`,children:[(0,$.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,$.jsx)(Sr,{className:`h-4 w-4`})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-[13px] font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:e.id})]})]}),(0,$.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,$.jsxs)(`button`,{type:`button`,onClick:()=>f===e.id?p(null):S(e),title:Z(`engine.studio.landing.dupTitle`,t),className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[10px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,$.jsx)(Wr,{className:`h-3 w-3`}),` `,Z(`engine.studio.landing.dup`,t)]})]}),f===e.id&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 border-t px-3 py-2.5`,children:[(0,$.jsx)(`input`,{autoFocus:!0,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&C(),e.key===`Escape`&&p(null)},placeholder:Z(`engine.studio.landing.dupNamePlaceholder`,t),className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,$.jsx)(Px,{value:g,onChange:_,onEnter:()=>void C(),onEscape:()=>p(null),placeholder:Z(`engine.studio.landing.dupIdPlaceholder`,t),locale:t,testId:`pkg-dup-id-input`}),b&&(0,$.jsx)(`p`,{className:`text-[10px] text-destructive`,children:b}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void C(),disabled:v||!m.trim()||!uc.test(g.trim()),className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[v?(0,$.jsx)(X,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(Wr,{className:`h-3 w-3`}),Z(`engine.studio.landing.dupGo`,t)]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>p(null),className:`rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,children:Z(`engine.studio.cancel`,t)})]})]})]},e.id)),(0,$.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,$.jsx)(Ri,{className:`h-4 w-4`}),` `,Z(`engine.studio.pkg.new`,t)]})]}),(0,$.jsx)(dc,{mode:`create`,open:s,onOpenChange:c,onSaved:e=>l(e.id)}),(0,$.jsx)(`h2`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.landing.orgHeading`,t)}),(0,$.jsx)(`div`,{className:`mb-6 grid grid-cols-1 gap-2.5 sm:grid-cols-2 lg:grid-cols-3`,children:(0,$.jsxs)(`button`,{type:`button`,"data-testid":`studio-landing-org-scope`,onClick:()=>e(tb()),className:`flex items-center gap-2.5 rounded-lg border bg-background px-3 py-2.5 text-left hover:bg-muted/40`,children:[(0,$.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,$.jsx)(wr,{className:`h-4 w-4`})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-[13px] font-medium`,children:Z(`engine.studio.org.name`,t)}),(0,$.jsx)(`span`,{className:`block text-[10px] leading-4 text-muted-foreground`,children:Z(`engine.studio.org.description`,t)})]})]})}),d.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h2`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.landing.installedHeading`,t)}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-2.5 sm:grid-cols-2 lg:grid-cols-3`,children:d.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>l(e.id),className:`flex items-center gap-2.5 rounded-lg border bg-muted/20 px-3 py-2.5 text-left hover:bg-muted/40`,children:[(0,$.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground`,children:(0,$.jsx)(Sr,{className:`h-4 w-4`})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-[13px]`,children:e.name}),(0,$.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:e.id})]}),(0,$.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,$.jsx)(_i,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,t)]})]},e.id))})]})]})}var Ix={type:`element:definition-list`,properties:{columns:2,items:[{term:`Status`,description:`Active`},{term:`Owner`,description:`Ada Lovelace`},{term:`Plan`,description:`Enterprise`},{term:`Renewal`,description:`2026-12-01`}]}},Lx=()=>{let{modalHandler:e,modalElement:t}=Lo();return(0,$.jsxs)(`div`,{className:`space-y-4 p-6`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Action modal transport`}),(0,$.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`One `,(0,$.jsx)(`code`,{children:`onModal`}),` handler, four placements, arbitrary SchemaNode content.`]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(q,{"data-testid":`open-center`,onClick:()=>e({placement:`center`,size:`lg`,title:`Center modal`,content:Ix}),children:`Center`}),(0,$.jsx)(q,{"data-testid":`open-side`,variant:`outline`,onClick:()=>e({placement:`side`,title:`Side drawer`,content:Ix}),children:`Side drawer`}),(0,$.jsx)(q,{"data-testid":`open-bottom`,variant:`outline`,onClick:()=>e({placement:`bottom`,title:`Bottom sheet`,content:Ix}),children:`Bottom sheet`}),(0,$.jsx)(q,{"data-testid":`open-fullscreen`,variant:`outline`,onClick:()=>e({placement:`fullscreen`,title:`Fullscreen`,content:Ix}),children:`Fullscreen`})]}),t]})},Rx=()=>{let[e,t]=Q.useState([{},{}]);return(0,$.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-4 p-6`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Line-item grid with a lookup cell`}),(0,$.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`The `,(0,$.jsx)(`code`,{children:`Account`}),` column is a real lookup picker bound to live `,(0,$.jsx)(`code`,{children:`showcase_account`}),`.`]}),(0,$.jsx)(Xe,{value:e,onChange:t,field:{columns:[{name:`account`,label:`Account`,type:`lookup`,reference:`showcase_account`,displayField:`name`},{name:`note`,label:`Note`,type:`text`},{name:`amount`,label:`Amount`,type:`currency`}],totalField:`amount`}}),(0,$.jsx)(`pre`,{className:`rounded bg-muted p-3 text-xs`,"data-testid":`rows-json`,children:JSON.stringify(e)})]})},zx=[{id:`1`,name:`hotcrm-fix-verify`,org:`hotcrm-fix-verify`,type:`production`,status:`running`,host:`os-05ayzz.objectos.app`},{id:`2`,name:`Objectstack`,org:`Objectstack`,type:`production`,status:`running`,host:`os-0zpadn.objectos.app`},{id:`3`,name:`hotcrm`,org:`JIANGUO Zhuang's Workspace`,type:`production`,status:`running`,host:`os-48f50e60.objectos.app`}],Bx=[{name:`open`,label:`Open`,variant:`primary`},{name:`upgrade`,label:`Upgrade Plan`,variant:`primary`},{name:`rename`,label:`Rename`,variant:`secondary`},{name:`archive`,label:`Archive`,variant:`secondary`}],Vx=[{field:`name`,label:`名称`},{field:`org`,label:`所属组织`},{field:`type`,label:`类型`},{field:`status`,label:`状态`},{field:`host`,label:`公开主机名`}];function Hx({maxInlineRowActions:e}){let t={type:`object-grid`,objectName:`showcase_environment`,columns:Vx,data:{provider:`value`,items:zx},rowActionDefs:Bx,...e==null?{}:{maxInlineRowActions:e}};return(0,$.jsx)(Pn,{children:(0,$.jsx)(zc,{schema:t})})}var Ux=()=>(0,$.jsxs)(`div`,{className:`mx-auto max-w-none space-y-8 p-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Row-action overflow (default)`}),(0,$.jsxs)(`p`,{className:`mb-3 text-sm text-muted-foreground`,children:[`Two `,(0,$.jsx)(`code`,{children:`variant:'primary'`}),` row actions. Only `,(0,$.jsx)(`strong`,{children:`Open`}),` stays inline;`,(0,$.jsx)(`strong`,{children:` Upgrade Plan`}),` + the secondaries fold into the `,(0,$.jsx)(`code`,{children:`⋮`}),` menu. The actions column hugs its content and must never clip the inline button.`]}),(0,$.jsx)(`div`,{className:`rounded-lg border`,"data-testid":`grid-default`,children:(0,$.jsx)(Hx,{})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Row-action overflow (maxInlineRowActions: 2)`}),(0,$.jsxs)(`p`,{className:`mb-3 text-sm text-muted-foreground`,children:[`Same data, author opts into two inline primaries — both `,(0,$.jsx)(`strong`,{children:`Open`}),` and`,(0,$.jsx)(`strong`,{children:` Upgrade Plan`}),` render inline and the column grows to fit them.`]}),(0,$.jsx)(`div`,{className:`rounded-lg border`,"data-testid":`grid-wide`,children:(0,$.jsx)(Hx,{maxInlineRowActions:2})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Row-action sticky-right (narrow / horizontal scroll)`}),(0,$.jsxs)(`p`,{className:`mb-3 text-sm text-muted-foreground`,children:[`A deliberately narrow container so the table scrolls horizontally. The`,(0,$.jsx)(`strong`,{children:` 操作`}),` column stays pinned to the right edge (always reachable), while the first `,(0,$.jsx)(`strong`,{children:`名称`}),` column stays frozen on the left. Scroll the grid sideways to check both edges hold.`]}),(0,$.jsx)(`div`,{className:`max-w-md overflow-hidden rounded-lg border`,"data-testid":`grid-scroll`,children:(0,$.jsx)(Hx,{})})]})]}),Wx=4,Gx=1e3;function Kx({endpoint:e,children:t}){let[n,r]=(0,Q.useState)({});return(0,Q.useEffect)(()=>{let t=!1;return(async()=>{for(let n=0;n<=Wx;n++){let i=C();try{let n=await kn(e,{credentials:`include`,headers:{Accept:`application/json`}});if(n.authenticated!==!1&&C()===i&&ar(n.locale),t)return;r({currency:n.currency??void 0,locale:n.locale??void 0});return}catch(e){if(!Hn(e)||n===Wx)return;let r=e instanceof En?e.retryAfterMs:void 0;if(await bn(vn(n,Gx,r)),t)return}}})(),()=>{t=!0}},[e]),(0,$.jsx)(er,{value:n,children:t})}var qx=(0,Q.lazy)(()=>o(()=>import(`./AppManagementPage-ZwyvnHpM.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),Jx=(0,Q.lazy)(()=>o(()=>import(`./ProfilePage-Qp8DL8CF.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),Yx=(0,Q.lazy)(()=>o(()=>import(`./ApprovalsInboxPage-DD4fe0Em.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),Xx=(0,Q.lazy)(()=>o(()=>import(`./AiPendingActionsPage-Dh3-i4BB.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),Zx=(0,Q.lazy)(()=>o(()=>import(`./AuditLogPage-Sed6iMqP.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),Qx=(0,Q.lazy)(()=>o(()=>import(`./SettingsHub-CPP9FDe8.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),$x=(0,Q.lazy)(()=>o(()=>import(`./SettingsView-CrHAROu9.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),eS=(0,Q.lazy)(()=>o(()=>import(`./ApiConsolePage-CKYEqlMs.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),tS=(0,Q.lazy)(()=>o(()=>import(`./FlowRunsPage-R3W3t2s4.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),nS=(0,Q.lazy)(()=>o(()=>import(`./PublicFormsPage-D3AT2EH9.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url)),rS=(0,Q.lazy)(()=>o(()=>import(`./IntegrationsPage-DIuFLEbF.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([0]),import.meta.url)),iS=(0,Q.lazy)(()=>o(()=>import(`./DocPage-CxJaQ-pC.js`),__vite__mapDeps([0]),import.meta.url)),aS=(0,Q.lazy)(()=>o(()=>import(`./AppDocsIndex-B5Tky2xg.js`),__vite__mapDeps([0]),import.meta.url)),oS=(0,Q.lazy)(()=>o(()=>import(`./DocsSlug-CkF1E-Zs.js`),__vite__mapDeps([0]),import.meta.url)),sS=(0,Q.lazy)(()=>o(()=>import(`./DocsLayout-BAwlJQQf.js`),__vite__mapDeps([0]),import.meta.url));function cS(){let{objectName:e}=f(),n=g().pathname.replace(/\/(system\/)?objects(\/.*)?$/,``),r=e?`${n}/metadata/object/${e}`:`${n}/metadata/object`;return(0,$.jsx)(t,{to:r,replace:!0})}function lS(){let{metadataType:e,itemName:n}=f(),r=`${g().pathname.replace(/\/(system\/)?metadata(\/.*)?$/,``)}/metadata`,i=e?n?`${r}/${encodeURIComponent(e)}/${n}`:`${r}/${encodeURIComponent(e)}`:r;return(0,$.jsx)(t,{to:i,replace:!0})}function uS({objectName:e}){let n=g().pathname.replace(/\/system\/[^/]+\/?$/,``);return(0,$.jsx)(t,{to:`${n}/${e}`,replace:!0})}function dS(){return(0,$.jsx)(t,{to:`settings`,replace:!0})}var fS=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(m,{path:`system`,element:(0,$.jsx)(dS,{})}),(0,$.jsx)(m,{path:`system/apps`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(qx,{})})}),(0,$.jsx)(m,{path:`system/profile`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(Jx,{})})}),(0,$.jsx)(m,{path:`system/approvals`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(Yx,{})})}),(0,$.jsx)(m,{path:`system/ai-approvals`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(Xx,{})})}),(0,$.jsx)(m,{path:`system/audit-log`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(Zx,{})})}),(0,$.jsx)(m,{path:`system/settings`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(Qx,{})})}),(0,$.jsx)(m,{path:`system/settings/:namespace`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)($x,{})})}),(0,$.jsx)(m,{path:`developer/api-console`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(eS,{})})}),(0,$.jsx)(m,{path:`developer/flow-runs`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(tS,{})})}),(0,$.jsx)(m,{path:`developer/public-forms`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(nS,{})})}),(0,$.jsx)(m,{path:`developer/integrations`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(rS,{})})}),(0,$.jsxs)(m,{path:`docs`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(sS,{})}),children:[(0,$.jsx)(m,{index:!0,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(aS,{})})}),(0,$.jsx)(m,{path:`:slug`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(oS,{})})}),(0,$.jsx)(m,{path:`:slug/:name`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(iS,{})})})]}),(0,$.jsx)(m,{path:`system/objects`,element:(0,$.jsx)(cS,{})}),(0,$.jsx)(m,{path:`system/objects/:objectName`,element:(0,$.jsx)(cS,{})}),(0,$.jsx)(m,{path:`system/metadata`,element:(0,$.jsx)(lS,{})}),(0,$.jsx)(m,{path:`system/metadata/:metadataType`,element:(0,$.jsx)(lS,{})}),(0,$.jsx)(m,{path:`system/metadata/:metadataType/:itemName`,element:(0,$.jsx)(lS,{})}),(0,$.jsx)(m,{path:`system/users`,element:(0,$.jsx)(uS,{objectName:`sys_user`})}),(0,$.jsx)(m,{path:`system/organizations`,element:(0,$.jsx)(uS,{objectName:`sys_organization`})}),(0,$.jsx)(m,{path:`system/roles`,element:(0,$.jsx)(uS,{objectName:`sys_position`})}),(0,$.jsx)(m,{path:`system/positions`,element:(0,$.jsx)(uS,{objectName:`sys_position`})}),(0,$.jsx)(m,{path:`system/permissions`,element:(0,$.jsx)(uS,{objectName:`sys_permission_set`})})]});function pS(){let e=(0,Q.useMemo)(()=>y(),[]);return(0,$.jsx)(Ft,{endpoint:`/api/v1/auth/me/permissions`,fetcher:e,loadingFallback:(0,$.jsx)(rd,{}),errorFallback:(e,t)=>(0,$.jsx)(rd,{error:e.message,onRetry:t}),children:(0,$.jsx)(Kx,{endpoint:`/api/v1/auth/me/localization`,children:(0,$.jsx)(Vv,{extraRoutes:fS,extraRoutesNoApp:fS})})})}function mS(){return null}function hS(e){return e._packageId===`com.objectstack.setup`||e.name===`setup`}function gS(e){let t=(e??[]).filter(e=>!!e?.name),n=t.find(e=>e.isDefault===!0);if(n)return`/apps/${n.name}`;let r=t.filter(e=>e.active!==!1&&e.hidden!==!0);return r.length===1&&!hS(r[0])?`/apps/${r[0].name}`:`/home`}function _S(e){return e===void 0||e===`ready`}var vS=1500;function yS(){let{apps:e,loading:t,getTypeStatus:n,refresh:r}=Yt(),i=!t&&!_S(n?.(`app`)),a=(0,Q.useRef)(!1);return(0,Q.useEffect)(()=>{if(!i||a.current)return;a.current=!0;let e=setTimeout(()=>{r?.(`app`)},vS);return()=>clearTimeout(e)},[i,r]),t||i?(0,$.jsx)(Ad,{}):(0,$.jsx)(id,{to:gS(e),replace:!0})}function bS(){let e=g(),t=e.pathname+e.search,n=t&&t!==`/`?`?redirect=${encodeURIComponent(t)}`:``;return(0,$.jsx)(id,{to:`/login${n}`,replace:!0})}function xS({children:e,requireOrganization:t=!0}){return(0,$.jsx)(x,{fallback:(0,$.jsx)(bS,{}),loadingFallback:(0,$.jsx)(Ad,{}),children:(0,$.jsx)(Pd,{children:t?(0,$.jsx)(Rd,{children:e}):e})})}function SS({children:e,redirectTo:n}){let r=Qu(),i=zl();return i.status===`pending`?(0,$.jsx)(Ad,{}):i.status===`failed`?(0,$.jsx)(rd,{error:i.error.message,onRetry:i.retry}):Bl(i.systemPermissions)?(0,$.jsx)($.Fragment,{children:e}):(0,$.jsx)(t,{to:n??r,replace:!0})}function CS(){return(0,$.jsx)(xS,{children:(0,$.jsx)(SS,{children:(0,$.jsx)(d,{})})})}function wS(){let e=Qu(),{t}=J();return(0,$.jsxs)(`div`,{className:`flex min-h-screen flex-col bg-background text-foreground`,children:[(0,$.jsx)(`header`,{className:`flex shrink-0 items-center border-b px-3 py-2`,children:(0,$.jsx)(p,{to:e,title:t(`console.studio.backToHome`),className:`inline-flex items-center gap-1.5 rounded-md px-1.5 py-0.5 text-[13px] font-semibold hover:bg-muted`,children:Gs()})}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,$.jsx)(Fx,{})})]})}var TS=(0,$.jsxs)(m,{path:`/studio`,element:(0,$.jsx)(CS,{}),children:[(0,$.jsx)(m,{index:!0,element:(0,$.jsx)(wS,{})}),(0,$.jsx)(m,{path:Qy,element:(0,$.jsx)(t,{to:$y,replace:!0})}),(0,$.jsx)(m,{path:`:packageId`,element:(0,$.jsx)(t,{to:`data`,replace:!0})}),(0,$.jsx)(m,{path:`:packageId/:tab`,element:(0,$.jsx)(xx,{})})]}),ES=`/api/v1/auth`;function DS(e,t){return e===`fresh`?`first-run`:t.isLoading?`pending`:t.isAuthenticated?`settings`:e===`unknown`?`pending`:`settings`}function OS(e){let[t,n]=(0,Q.useState)(`unknown`);return(0,Q.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=await fetch(`${ES}/bootstrap-status`,{credentials:`include`}),r=e.ok?await e.json().catch(()=>({})):{};t||n(r.hasOwner===!0?`bootstrapped`:`fresh`)}catch{t||n(`fresh`)}})(),()=>{t=!0}},[e]),t}function kS(){let{isAuthenticated:e,isLoading:t}=A();return DS(OS(!t&&!e),{isAuthenticated:e,isLoading:t})}function AS(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}function jS(e){let t=new URL(AS(e),document.baseURI);return`${t.pathname}${t.search}${t.hash}`}var MS=`/api/v1/auth`,NS=`/`;function PS(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function FS(){let{t:e}=J(),t=r(),{user:n,signUp:i,refreshOrganizations:a,updateOrganization:o,createOrganization:s,switchOrganization:c}=A(),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await fetch(`${MS}/bootstrap-status`,{credentials:`include`}),n=t.ok?await t.json().catch(()=>({})):{};e||b(n.hasOwner===!0)}catch{e||b(!1)}})(),()=>{e=!0}},[]),(0,Q.useEffect)(()=>{y===!0&&!n&&t(`/login`,{replace:!0})},[y,n,t]),(0,Q.useEffect)(()=>{n&&!_&&window.location.assign(AS(NS))},[n,_]),y===null?(0,$.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted`,children:(0,$.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-muted-foreground/20 border-t-primary`})}):(0,$.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted p-6`,children:(0,$.jsx)(`div`,{className:`flex w-full max-w-md flex-col gap-6`,children:(0,$.jsxs)(Ue,{children:[(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(be,{children:e(`auth.setup.welcomeTitle`,{defaultValue:`Welcome to ObjectStack`})}),(0,$.jsx)(Ve,{children:e(`auth.setup.description`,{defaultValue:`Create the first owner account to finish setting up this deployment.`})})]}),(0,$.jsx)(W,{children:(0,$.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),v(!0);try{await i(l,d,p);let e=h.trim();if(e)try{let t;for(let e=0;e<4&&!t?.id;e++)e>0&&await new Promise(e=>setTimeout(e,500)),t=(await a())?.[0];let n=PS(e),r;t?.id?(await o(t.id,{name:e,...n?{slug:n}:{}}),r=t.id):r=(await s({name:e,slug:n||`org-${Date.now().toString(36)}`}))?.id,r&&await c(r).catch(()=>void 0)}catch(e){console.warn(`[setup] organization rename/create failed`,e)}window.location.assign(AS(NS))}catch(t){Y.error(e(`auth.setup.failed`,{defaultValue:`Setup failed`}),{description:t.message})}finally{v(!1)}},className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(z,{htmlFor:`name`,children:e(`auth.setup.yourName`,{defaultValue:`Your name`})}),(0,$.jsx)(K,{id:`name`,autoComplete:`name`,required:!0,value:l,onChange:e=>u(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(z,{htmlFor:`orgName`,children:e(`auth.setup.orgName`,{defaultValue:`Organization name`})}),(0,$.jsx)(K,{id:`orgName`,required:!0,placeholder:e(`auth.setup.orgNamePlaceholder`,{defaultValue:`Acme Inc.`}),value:h,onChange:e=>g(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(z,{htmlFor:`email`,children:e(`auth.setup.emailLabel`,{defaultValue:`Email`})}),(0,$.jsx)(K,{id:`email`,type:`email`,placeholder:e(`auth.setup.emailPlaceholder`,{defaultValue:`name@example.com`}),autoComplete:`email`,required:!0,value:d,onChange:e=>f(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(z,{htmlFor:`password`,children:e(`auth.setup.passwordLabel`,{defaultValue:`Password`})}),(0,$.jsx)(K,{id:`password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,placeholder:e(`auth.setup.passwordHint`,{defaultValue:`Minimum 8 characters`}),value:p,onChange:e=>m(e.target.value)})]}),(0,$.jsx)(q,{type:`submit`,className:`mt-2 w-full`,disabled:_,children:_?e(`auth.setup.submitting`,{defaultValue:`Setting up…`}):e(`auth.setup.submit`,{defaultValue:`Create owner account`})})]})})]})})})}function IS(){let e=kS();return e===`pending`?(0,$.jsx)(Ad,{}):e===`first-run`?(0,$.jsx)(FS,{}):(0,$.jsx)(xS,{requireOrganization:!1,children:(0,$.jsx)(Hd,{})})}var LS=`/api/v1`,RS=new Set([`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]),zS=`recordId`;function BS(e,t){if(e!==`internal`)return{kind:`create`};let n=t.get(zS);if(n===null)return{kind:`create`};let r=n.trim();return r?{kind:`edit`,recordId:r,recordObject:(t.get(`recordObject`)??``).trim()||null}:{kind:`refuse`,reason:`This form was opened to edit a record (?${zS}=), but no record id was supplied. Re-open it from the record, or drop the parameter to create a new one.`}}function VS(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function HS(e){if(Array.isArray(e))return e.map(e=>{if(typeof e==`string`)return{value:e,label:e};if(e&&typeof e==`object`){let t=String(e.value??e.id??``);return{value:t,label:String(e.label??e.name??t)}}return{value:String(e),label:String(e)}})}var US=`text`;function WS(e){return Ge(e)!==US||e===US}function GS(e){if(e.widget&&WS(e.widget))return Ge(e.widget);if(e.multiple){let t=ye(e.type,{multiple:!0});if(t!==ye(e.type))return Ge(t.replace(/^field:/,``))}return Ge(e.type)}function KS(e){return Mt[e]??`control`}function qS(e,t){let n=t?.fields??{},r=e.sections??e.groups??[];return(Ia(r,{objectName:t?.name??``,formType:e.type,objectDef:t})??[]).map(e=>{let t=VS(e.columns),r=[];for(let t of e.fields??[]){let e=typeof t==`string`?{field:t}:{...t},i=n[e.field]??{type:`text`};r.push({name:e.field,label:e.label??i.label??e.field,type:i.type??`text`,required:e.required??i.required??!1,readonly:e.readonly??!1,hidden:e.hidden??!1,visibleWhen:e.visibleWhen??e.visibleOn,rules:{visibleWhen:i.visibleWhen,readonlyWhen:i.readonlyWhen,requiredWhen:i.requiredWhen},placeholder:e.placeholder??i.placeholder,helpText:e.helpText??i.helpText,defaultValue:i.defaultValue,options:HS(i.options),maxLength:e.maxLength??i.maxLength,multiple:e.multiple??i.multiple,accept:i.accept,maxSize:i.maxSize,widget:e.widget??i.widget,colSpan:e.colSpan??1,meta:n[e.field]})}return{name:e.name,label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,visibleWhen:e.visibleWhen??e.visibleOn,fields:r}})}function JS(e,t,n,r){return!e.hidden&&Sn(e.visibleWhen,t,!0,n??void 0,r,{context:`visibleWhen of field '${e.name}'`})}function YS(e,t,n,r){return Sn(e.visibleWhen,t,!0,n??void 0,r,{context:`visibleWhen of section '${e.label??`(unlabelled)`}'`})}function XS(e,t,n,r,i){let a=wn(e.rules??{},t,{required:e.required,readonly:e.readonly,serverOwnedValue:fn({field:{defaultValue:e.defaultValue}},r)},n??void 0,i,`field '${e.name}'`),o=JS(e,t,n,i);return{visible:a.visible&&o,readonly:a.readonly,required:a.required,faults:a.faults}}function ZS(e,t){return t||(e===`internal`?{kind:`created-record`}:{kind:`thank-you`})}function QS(e){if(!e||typeof e!=`object`)return null;let t=e,n=typeof t.success==`boolean`&&`data`in t?t.data:t;return!n||typeof n!=`object`?null:n}function $S(e){let t=QS(e);if(!t)return null;let n=t.id;return typeof n==`string`?n===``?null:n:typeof n==`number`&&Number.isFinite(n)?String(n):null}function eC(e,t,n){let r=QS(e);if(!r)throw Error(`Could not read record "${n}" of ${t}: the server returned no record payload.`);let i=r.object;if(typeof i==`string`&&i&&i!==t)throw Error(`Record "${n}" belongs to ${i}, but this form edits ${t}. Refusing to open it — check the action that linked here.`);let a=r.record;if(!a||typeof a!=`object`||Array.isArray(a))throw Error(`Could not read record "${n}" of ${t}: the response carried no "record".`);return a}function tC(e,t,n){let r={};for(let i of e){i.defaultValue!==void 0&&!mn(i.defaultValue)&&(r[i.name]=i.defaultValue),n&&Object.prototype.hasOwnProperty.call(n,i.name)&&(r[i.name]=n[i.name]);let e=t.get(`prefill_${i.name}`);e!==null&&(r[i.name]=e)}return r}function nC(e,t,n){return n?Na(e,{fields:Object.fromEntries(t.map(e=>[e.name,{defaultValue:e.defaultValue}]))}):e}async function rC(e,t){return fetch(`${LS}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function iC(e){let t=await rC(`/forms/${encodeURIComponent(e)}`);if(!t.ok){let e=await t.text().catch(()=>``);throw Error(`Failed to load form (${t.status}): ${e||t.statusText}`)}let n=await t.json();return{label:n.label??n.form?.title??n.form?.label??n.object,object:n.object,form:n.form,objectSchema:n.objectSchema,record:null}}function aC(e,t){let n=t,r=n?.item??n,i=r?.spec??r,a=i&&typeof i==`object`&&i.config&&typeof i.config==`object`&&(`viewKind`in i||`object`in i),o=i&&typeof i==`object`?i.viewKind:void 0;if(o&&o!==`form`)throw Error(`View "${e}" is a ${o} view, not a form view — check the action or link that targets it.`);let s=a?i.config:i;if(!o&&s&&typeof s==`object`&&typeof s.type==`string`&&!RS.has(s.type))throw Error(`View "${e}" is a ${s.type} view, not a form view — check the action or link that targets it.`);return{label:(a?i.label:void 0)??s?.label??e,object:(a?i.object:void 0)??s?.data?.object??i?.object,form:s}}async function oC(e,t,n){let r=await rC(`/meta/view/${encodeURIComponent(e)}`);if(!r.ok)throw Error(`Form metadata not found: view/${e}`);let{label:i,object:a,form:o}=aC(e,await r.json());if(!a)throw Error(`FormView "${e}" is missing an "object" target`);if(n&&n!==a)throw Error(`This form edits ${a}, but the link says record "${t}" belongs to ${n}. Refusing to open it — check the action that linked here.`);let s=null;try{let e=await rC(`/meta/object/${encodeURIComponent(a)}`);if(e.ok){let t=await e.json(),n=t?.item??t,r=n?.spec??n;r?.fields&&typeof r.fields==`object`&&(s={name:r.name??a,label:r.label,fields:r.fields,fieldGroups:r.fieldGroups})}}catch{}let c=null;if(t){let e=await rC(`/data/${encodeURIComponent(a)}/${encodeURIComponent(t)}`);if(!e.ok){let n=await e.text().catch(()=>``);throw Error(`Could not open record "${t}" of ${a} for editing (${e.status})${n?`: ${n}`:e.statusText?`: ${e.statusText}`:``}`)}c=eC(await e.json(),a,t)}return{label:i,object:a,form:o,objectSchema:s,record:c}}async function sC(e,t){let n=await rC(`/forms/${encodeURIComponent(e)}/submit`,{method:`POST`,body:JSON.stringify(t)});if(!n.ok){let e=await n.text().catch(()=>``);throw Error(`Submit failed (${n.status}): ${e||n.statusText}`)}return n.json().catch(()=>({}))}async function cC(e,t,n){let r=await rC(n?`/data/${encodeURIComponent(e)}/${encodeURIComponent(n)}`:`/data/${encodeURIComponent(e)}`,{method:n?`PATCH`:`POST`,body:JSON.stringify(t)});if(!r.ok){let e=await r.text().catch(()=>``);throw Error(`${n?`Update`:`Create`} failed (${r.status}): ${e||r.statusText}`)}return r.json().catch(()=>({}))}function lC(e){return`f_${e}`}function uC(e){return`f_${e}-label`}function dC(e){return KS(GS(e))===`control`?{htmlFor:lC(e.name)}:{id:uC(e.name)}}function fC(e){return{...e.meta??{},name:e.name,label:e.label,type:e.type,widget:e.widget,placeholder:e.placeholder,options:e.options,maxLength:e.maxLength,multiple:e.multiple,accept:e.accept,maxSize:e.maxSize}}function pC(e){return e===`file`||e===`image`||e===`avatar`}function mC(e){return Cn.has(e)||en.has(e)}function hC({field:e,state:t,value:n,onChange:r,values:i,onUploadingChange:a}){let o=GS(e),s=(0,Q.useMemo)(()=>ot(o),[o]),c=(0,Q.useMemo)(()=>fC(e),[e]),l=KS(o),u=lC(e.name),d=uC(e.name),f=(0,$.jsx)(s,{...l===`display`?null:{id:u},name:e.name,value:n??null,onChange:r,field:c,disabled:t.readonly,"aria-required":t.required||void 0,...l===`group`?{"aria-labelledby":d}:null,...mC(o)?{dependentValues:i}:null,...pC(o)?{onUploadingChange:a}:null});return(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`h-9 w-full animate-pulse rounded-md bg-muted/40`,"aria-hidden":`true`}),children:l===`display`?(0,$.jsx)(`div`,{id:u,role:`group`,"aria-labelledby":d,children:f}):f})}function gC(e,t,n,r,i){let a=[],o=[];for(let s of e)if(YS(s,t,n,i))for(let e of s.fields){let s=XS(e,t,n,r,i);s.faults.visibleWhen!==void 0&&a.push(e),s.visible&&s.required&&!s.readonly&&gn(t[e.name])&&o.push(e)}return{faultedVisibleWhen:a,missing:o}}function _C({mode:e,recordPath:t}){let n=f(),[i]=l(),a=r(),o=(e===`public`?n.slug:n.name)??``,s=BS(e,i),c=s.kind===`edit`?s.recordId:null,u=s.kind===`edit`?s.recordObject:null,d=s.kind!==`edit`,p=Jt(),{sectionLabel:m,fieldLabel:h}=$n(),{t:g}=J(),[_,v]=(0,Q.useState)(!0),[y,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(null),[C,w]=(0,Q.useState)({}),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)({}),k=Object.values(D).some(Boolean),A=`form-outcome:${(0,Q.useId)()}`,[j,M]=(0,Q.useState)(!1),[N,ee]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let t=!1;return v(!0),b(null),(s.kind===`refuse`?Promise.reject(Error(s.reason)):e===`public`?iC(o):oC(o,c,u)).then(e=>{if(t)return;S(e);let n=qS(e.form,e.objectSchema).flatMap(e=>e.fields);w(tC(n,i,e.record))}).catch(e=>{t||(S(null),b(e?.message??String(e)))}).finally(()=>{t||v(!1)}),()=>{t=!0}},[e,o,i]);let P=(0,Q.useMemo)(()=>x?qS(x.form,x.objectSchema):[],[x]),F=ZS(e,x?.form?.submitBehavior),te=N?.kind===`pending`?N.path:null,I=F.kind===`redirect`?F.delayMs??0:0;(0,Q.useEffect)(()=>{if(te===null)return;let e=setTimeout(()=>a(te),I);return()=>clearTimeout(e)},[te,I,a]);let ne=async n=>{if(n.preventDefault(),!x)return;let{faultedVisibleWhen:r,missing:s}=gC(P,C,x.record,d,p);if(r.length>0){let e=g(`form.visibleWhenFaulted`,{fields:r.map(e=>h(x.object,e.name,e.label)).join(g(`validation.formInvalidJoiner`))});b(e),Y.error(e,{id:A});return}if(s.length>0){let e=g(`publicForm.requiredFields`,{fields:s.map(e=>h(x.object,e.name,e.label)).join(g(`validation.formInvalidJoiner`))});b(e),Y.error(e,{id:A});return}E(!0),b(null);try{let n=nC(C,P.flatMap(e=>e.fields),d),r=e===`public`?await sC(o,n):await cC(x.object,n,c);switch(Y.success(g(`form.submitted`),{id:A}),F.kind){case`created-record`:{let e=c??$S(r),n=e?t?.(x.object,e):null;if(n){a(n);break}M(!0);break}case`redirect`:{let e=QS(r)?.record,t=c??$S(r),i=Vl(F.url,{...n,...e&&typeof e==`object`?e:{},...t?{id:t}:{}});if(!i.ok){Y.error(i.refusal),ee({kind:`refused`,refusal:i.refusal}),M(!0);break}ee({kind:`pending`,path:i.path}),M(!0);break}case`continue`:{let e=P.flatMap(e=>e.fields);w(tC(e,i,x.record));break}default:M(!0)}}catch(e){let t=e?.message??String(e);b(t),Y.error(t,{id:A})}finally{E(!1)}};if(_)return(0,$.jsx)(`div`,{className:`flex min-h-[60vh] items-center justify-center`,children:(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:g(`common.loading`)})});if(y&&!x)return(0,$.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,$.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:y})});if(!x)return null;if(j&&(F.kind===`thank-you`||F.kind===`created-record`)){let e=F.kind===`thank-you`?F.title:void 0,t=F.kind===`thank-you`?F.message:void 0;return(0,$.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,$.jsxs)(`div`,{className:`rounded-md border bg-card p-6 text-center`,children:[(0,$.jsx)(`h2`,{className:`mb-2 text-lg font-semibold`,children:e??g(`publicForm.thankYouTitle`)}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t??g(`publicForm.thankYouMessage`)})]})})}return j&&F.kind===`redirect`?N?.kind===`refused`?(0,$.jsxs)(`div`,{className:`mx-auto max-w-2xl space-y-4 p-6`,children:[(0,$.jsxs)(`div`,{className:`rounded-md border bg-card p-6 text-center`,children:[(0,$.jsx)(`h2`,{className:`mb-2 text-lg font-semibold`,children:g(`publicForm.thankYouTitle`)}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:g(`publicForm.thankYouMessage`)})]}),(0,$.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:N.refusal})]}):(0,$.jsx)(`div`,{className:`mx-auto max-w-2xl p-6 text-center text-sm text-muted-foreground`,children:g(`publicForm.redirectPending`)}):(0,$.jsxs)(`div`,{className:`mx-auto max-w-2xl p-4 sm:p-6`,children:[(0,$.jsxs)(`header`,{className:`mb-6`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:x.label}),x.form?.description&&(0,$.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:x.form.description})]}),(0,$.jsxs)(`form`,{onSubmit:ne,className:`space-y-6`,children:[P.map((e,t)=>YS(e,C,x.record,p)?(0,$.jsxs)(`section`,{className:`rounded-md border bg-card p-4 sm:p-5`,children:[e.label&&(0,$.jsx)(`h2`,{className:`mb-3 text-sm font-medium`,children:e.name?m(x.object,e.name,e.label):e.label}),(0,$.jsx)(`div`,{className:e.columns===1?`grid grid-cols-1 gap-4`:e.columns===2?`grid grid-cols-1 gap-4 sm:grid-cols-2`:e.columns===3?`grid grid-cols-1 gap-4 sm:grid-cols-3`:`grid grid-cols-1 gap-4 sm:grid-cols-4`,children:e.fields.map(e=>{let t=XS(e,C,x.record,d,p);return t.visible?(0,$.jsxs)(`div`,{className:e.colSpan===2?`sm:col-span-2`:e.colSpan===3?`sm:col-span-3`:e.colSpan===4?`sm:col-span-4`:``,children:[(0,$.jsxs)(`label`,{...dC(e),className:`mb-1 block text-xs font-medium text-foreground`,children:[h(x.object,e.name,e.label),t.required&&(0,$.jsx)(`span`,{className:`ml-0.5 text-destructive`,"aria-hidden":`true`,children:`*`})]}),(0,$.jsx)(hC,{field:e,state:t,value:C[e.name],values:C,onChange:t=>w(n=>({...n,[e.name]:t})),onUploadingChange:t=>O(n=>n[e.name]===t?n:{...n,[e.name]:t})}),e.helpText&&(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:e.helpText})]},e.name):null})})]},t):null),y&&(0,$.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:y}),(0,$.jsx)(`div`,{className:`flex justify-end gap-2`,children:(0,$.jsx)(`button`,{type:`submit`,disabled:T||k,className:`rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow-sm hover:bg-primary/90 disabled:opacity-50`,children:g(T?`publicForm.submitting`:k?`fields.file.uploading`:`publicForm.submit`)})})]})]})}function vC(e,t,n,r){if(!n||!r)return null;let i=cs(e,t);return`/apps/${encodeURIComponent(i)}/${encodeURIComponent(n)}/record/${encodeURIComponent(r)}`}function yC(){let{apps:e}=Yt(),{currentAppName:t}=Ro(),{user:n}=A(),r=(0,Q.useMemo)(()=>(n,r)=>vC(e,t,n,r),[e,t]),i=(0,Q.useMemo)(()=>Ya(n),[n]);return(0,$.jsx)(Ja,{user:i,children:(0,$.jsx)(Qv,{userId:n?.id,children:(0,$.jsx)(_C,{mode:`internal`,recordPath:r})})})}function bC({enabled:e=!1,url:t=`/api/v1/dev/metadata-events`,debounceMs:n=400,reconnectDelayMs:r=2e3}){let i=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!e||typeof window>`u`||typeof EventSource>`u`)return;let a=null,o=null,s=!1,c=!1,l=e=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{try{Y.info(`Metadata changed (${e}) — reloading…`,{duration:800})}catch{}setTimeout(()=>{try{window.location.reload()}catch{}},150)},n)},u=e=>{try{let t=JSON.parse(e.data),n=t?.name?`${t.metadataType??`metadata`}:${t.name}`:`metadata`;l(n)}catch{l(`change`)}},d=e=>{let t=`rebuild`;try{t=JSON.parse(e.data)?.reason??t}catch{}l(t)},f=()=>{if(!s)try{a=new EventSource(t),a.addEventListener(`open`,()=>{c=!0}),a.addEventListener(`metadata-change`,u),a.addEventListener(`reload`,d),a.addEventListener(`error`,()=>{if(!s&&a?.readyState===EventSource.CLOSED){if(a=null,!c)return;o=setTimeout(f,r)}})}catch{if(!c)return;o=setTimeout(f,r)}};return f(),()=>{if(s=!0,o&&clearTimeout(o),i.current&&clearTimeout(i.current),a)try{a.close()}catch{}}},[e,t,n,r]),null}function xC(e){let t=e.data??e;return{record:t.record??{},link:t.link,redactedFields:t.redactFields}}function SC(){let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_SERVER_URL??``;return e?e.replace(/\/$/,``):typeof window<`u`?window.location.origin:``}function CC(){let{token:e}=f(),t=`${(0,Q.useMemo)(()=>SC(),[])}/api/v1`,[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!0),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(null),h=(0,Q.useCallback)(async n=>{if(e){s(!0),a(null);try{let i=new URL(`${t}/share-links/${encodeURIComponent(e)}/resolve`);n&&i.searchParams.set(`password`,n);let o=await fetch(i.toString(),{headers:{Accept:`application/json`}});if(o.status===401){l(!0),a(n?`Wrong password.`:null),s(!1);return}if(o.status===404){a(`This link is invalid or no longer available.`),s(!1);return}if(o.status===410){a(`This link has expired or was revoked.`),s(!1);return}if(!o.ok){let e=await o.json().catch(()=>null);a(e?.error?.message??`Failed to load (HTTP ${o.status}).`),s(!1);return}r(xC(await o.json())),l(!1)}catch(e){a(e?.message??`Failed to load shared content.`)}finally{s(!1)}}},[t,e]);(0,Q.useEffect)(()=>{h()},[h]),(0,Q.useEffect)(()=>{if(!n||n.link.object_name!==`ai_conversations`)return;let e=`${t}/share-links/${encodeURIComponent(n.link.token)}/messages`;fetch(e,{headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(e=>m(e?.data??[])).catch(()=>m([]))},[t,n]);let g=(0,Q.useMemo)(()=>p?bm(Op(Ap(p))):[],[p]);if(o)return(0,$.jsxs)(`div`,{className:`flex h-svh w-full items-center justify-center bg-background text-muted-foreground`,children:[(0,$.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading…`]});if(c)return(0,$.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-md flex-col items-center justify-center gap-4 px-4 text-center`,children:[(0,$.jsx)(gi,{className:`h-8 w-8 text-muted-foreground`}),(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Password required`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The owner protected this link with a password.`}),(0,$.jsxs)(`form`,{className:`flex w-full flex-col gap-2`,onSubmit:e=>{e.preventDefault(),h(u)},children:[(0,$.jsx)(z,{htmlFor:`share-pw`,className:`sr-only`,children:`Password`}),(0,$.jsx)(K,{id:`share-pw`,type:`password`,value:u,onChange:e=>d(e.target.value),autoFocus:!0,placeholder:`Enter password`}),i&&(0,$.jsx)(`p`,{className:`text-xs text-destructive`,children:i}),(0,$.jsx)(q,{type:`submit`,size:`sm`,children:`Continue`})]})]});if(i)return(0,$.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-md flex-col items-center justify-center gap-3 px-4 text-center`,children:[(0,$.jsx)(ua,{className:`h-8 w-8 text-amber-500`}),(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Can't open this link`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i})]});if(!n)return null;if(n.link.object_name===`ai_conversations`){let e=n.record;return(0,$.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,$.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background px-4 py-3`,children:[(0,$.jsx)(Ti,{className:`h-5 w-5 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h1`,{className:`truncate text-sm font-semibold`,children:e.title??`Shared conversation`}),(0,$.jsx)(`p`,{className:`truncate text-[11px] text-muted-foreground`,children:`Read-only · Shared via ObjectStack`})]}),(0,$.jsx)(pt,{variant:`outline`,className:`text-[10px] capitalize`,children:n.link.permission})]}),(0,$.jsx)(`main`,{className:`flex min-h-0 flex-1 flex-col`,children:p==null?(0,$.jsxs)(`div`,{className:`flex flex-1 items-center justify-center py-12 text-sm text-muted-foreground`,children:[(0,$.jsx)(X,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading messages…`]}):p.length===0?(0,$.jsx)(`p`,{className:`py-12 text-center text-sm text-muted-foreground`,children:`This conversation has no messages yet.`}):(0,$.jsx)(As,{readOnly:!0,surface:`plain`,messages:g,showAvatars:!0,maxHeight:`100%`,className:`flex-1`})}),(0,$.jsx)(`footer`,{className:`border-t bg-muted/30 px-4 py-2 text-center text-[11px] text-muted-foreground`,children:`Powered by ObjectStack`})]})}return(0,$.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,$.jsx)(`header`,{className:`border-b px-4 py-3`,children:(0,$.jsxs)(`h1`,{className:`text-sm font-semibold`,children:[`Shared `,n.link.object_name]})}),(0,$.jsxs)(`main`,{className:`flex-1 overflow-y-auto p-4`,children:[(0,$.jsx)(`pre`,{className:`overflow-x-auto rounded-md border bg-muted/30 p-3 text-[12px]`,children:JSON.stringify(n.record,null,2)}),n.redactedFields&&n.redactedFields.length>0&&(0,$.jsxs)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:[`Some fields are hidden by the owner: `,n.redactedFields.join(`, `)]})]})]})}function wC(e){let t=e.split(`:`)[0].toLowerCase();return/^cloud\./.test(t)}function TC(e){let t=e.split(`:`)[0].toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.local`)}function EC(){return typeof window>`u`?null:window.location.host||null}function DC(){let e=Gs(),t=Rs();return(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 select-none`,children:[(0,$.jsx)(`span`,{className:`inline-flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br from-indigo-500 to-indigo-600 text-white shadow-sm shadow-indigo-500/30 overflow-hidden`,children:t?(0,$.jsx)(`img`,{src:t,alt:e,className:`h-full w-full object-contain`}):(0,$.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,$.jsx)(`path`,{d:`M12 2 2 7l10 5 10-5-10-5Z`}),(0,$.jsx)(`path`,{d:`m2 17 10 5 10-5`}),(0,$.jsx)(`path`,{d:`m2 12 10 5 10-5`})]})}),(0,$.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-foreground`,children:e})]})}function OC({children:e,formWidth:t=`sm`}){let{t:n}=J(),r=t===`md`?`max-w-md`:`max-w-sm`,i=EC(),a=!!i&&!wC(i)&&!TC(i);return(0,Q.useEffect)(()=>{if(typeof document>`u`||!i)return;let e=document.title;return a&&(document.title=i),()=>{document.title=e}},[i,a]),(0,$.jsxs)(`div`,{className:`relative flex min-h-svh w-full items-center justify-center overflow-hidden bg-background p-6`,children:[(0,$.jsxs)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 -z-10`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 opacity-[0.35] dark:opacity-[0.25] [mask-image:radial-gradient(ellipse_at_center,black,transparent_72%)] [-webkit-mask-image:radial-gradient(ellipse_at_center,black,transparent_72%)]`,style:{backgroundImage:`radial-gradient(hsl(var(--border)) 1px, transparent 1px)`,backgroundSize:`22px 22px`}}),(0,$.jsx)(`div`,{className:`absolute left-1/2 top-1/2 h-[34rem] w-[34rem] -translate-x-1/2 -translate-y-1/2 rounded-full bg-gradient-to-br from-indigo-500/10 to-indigo-600/10 blur-3xl dark:from-indigo-500/10 dark:to-indigo-600/10`})]}),(0,$.jsxs)(`div`,{className:Le(`flex w-full flex-col gap-5`,r),children:[(0,$.jsx)(DC,{}),a?(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(`span`,{className:`rounded-full border border-border/60 bg-background/60 px-2 py-0.5 font-mono text-[10px] uppercase tracking-wide text-muted-foreground`,title:n(`auth.shell.tenantHostHint`,{defaultValue:`You are signing in to this workspace`}),children:i})}):null,e]})]})}function kC(e){let t=`/api/v1/auth/oauth2/authorize${e}`,n=()=>window.location.assign(t);fetch(t,{credentials:`include`,redirect:`manual`,headers:{accept:`application/json`}}).then(async e=>{let t=await e.json().catch(()=>null),r=t?.url??t?.redirect_uri??t?.redirectURI;if(e.ok&&r){window.location.href=r;return}n()}).catch(n)}function AC(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}var jC=`os.console.devAdminHintDismissed`;function MC(e){return(0,$.jsx)(p,{to:e.href,className:e.className,children:e.children})}function NC(){let{t:e}=J(),[t]=l(),n=t.get(`redirect`),{user:r,isLoading:i,organizations:a,isOrganizationsLoading:o,activeOrganization:s,switchOrganization:c,getAuthConfig:u}=A(),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(()=>{try{return window.localStorage.getItem(jC)===`1`}catch{return!1}}),_=()=>{g(!0);try{window.localStorage.setItem(jC,`1`)}catch{}},[v,y]=(0,Q.useState)(!1),b=(0,Q.useRef)(!1),[x,S]=(0,Q.useState)(!1);(0,Q.useLayoutEffect)(()=>{i||S(!0)},[i]);let C=(0,Q.useMemo)(()=>{if(typeof window>`u`)return null;let e=new URLSearchParams(window.location.search),t=e.get(`redirect_uri`);if(!e.has(`client_id`)||!t)return null;try{return new URL(t).host}catch{return null}},[]),w=(0,Q.useMemo)(()=>{let e=t.get(`error`);return e?{code:e,description:t.get(`error_description`)}:null},[]);if((0,Q.useEffect)(()=>{let e=!1;return u().then(t=>{if(e)return;f(t?.emailPassword?.disableSignUp===!0);let n=t?.devSeedAdmin;m(n&&typeof n.email==`string`?{email:n.email,password:typeof n.password==`string`?n.password:void 0}:null)}).catch(()=>{}),()=>{e=!0}},[u]),(0,Q.useEffect)(()=>{if(r){if(typeof window<`u`){let e=new URLSearchParams(window.location.search);if(e.has(`client_id`)&&e.has(`redirect_uri`)){b.current||(b.current=!0,kC(window.location.search));return}}if(!s){if(o||v)return;if(a.length===1){y(!0),c(a[0].id).catch(()=>void 0).finally(()=>y(!1));return}if(a.length===0){window.location.assign(AS(AC(n)?n:`/`));return}window.location.assign(AS(`/organizations`));return}v||window.location.assign(AS(AC(n)?n:`/`))}},[r,s,a,o,v,n,c]),i&&!x||r)return(0,$.jsx)(OC,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`size-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent`}),(0,$.jsx)(`span`,{children:e(`auth.login.signingIn`,{defaultValue:`Signing you in…`})})]})});let T=n?`/register?redirect=${encodeURIComponent(n)}`:`/register`;return(0,$.jsx)(OC,{formWidth:`md`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[w?(0,$.jsx)(ee,{message:e(`auth.login.errors.oauthCallbackFailed`,{defaultValue:`Single sign-on could not be completed — the sign-in link expired or was already used. Please try again.`})+(w.description?` (${w.description})`:` (${w.code})`)}):null,C?(0,$.jsxs)(`div`,{role:`status`,className:`flex items-start gap-3 rounded-md border border-primary/30 bg-primary/5 px-4 py-3 text-sm text-foreground`,children:[(0,$.jsx)(`span`,{className:`mt-0.5 inline-block size-2 shrink-0 rounded-full bg-primary`}),(0,$.jsx)(`span`,{children:e(`auth.login.ssoHandoff`,{target:C,defaultValue:`Continue to ${C}`})})]}):null,p&&!h?(0,$.jsxs)(`div`,{role:`status`,"data-testid":`dev-admin-hint`,className:`flex items-start gap-3 rounded-md border border-amber-500/40 bg-amber-500/10 px-4 py-3 text-sm text-foreground`,children:[(0,$.jsx)(`span`,{className:`mt-0.5 inline-block size-2 shrink-0 rounded-full bg-amber-500`}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:e(`auth.login.devAdminHint.title`,{defaultValue:`Development instance`})}),(0,$.jsxs)(`div`,{className:`text-muted-foreground`,children:[e(`auth.login.devAdminHint.body`,{defaultValue:`Sign in with the seeded dev admin:`}),` `,(0,$.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:p.email}),p.password?(0,$.jsxs)($.Fragment,{children:[` / `,(0,$.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:p.password})]}):null]})]}),(0,$.jsx)(`button`,{type:`button`,onClick:_,"aria-label":e(`auth.login.devAdminHint.dismiss`,{defaultValue:`Dismiss`}),className:`shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,$.jsx)(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":`true`,className:`size-3.5 fill-current`,children:(0,$.jsx)(`path`,{d:`M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.75.75 0 1 1 1.06 1.06L9.06 8l3.22 3.22a.75.75 0 1 1-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 0 1-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06Z`})})})]}):null,(0,$.jsx)(Ue,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,$.jsx)(PC,{registerUrl:d?void 0:T,redirect:n})})]})})}function PC({registerUrl:e,redirect:t}){let{t:n}=J(),i=r(),a=(0,Q.useRef)(``);return(0,Q.useEffect)(()=>{let e=e=>{let t=e.target;t?.id===`login-email`&&(a.current=t.value)};return document.addEventListener(`input`,e,!0),()=>document.removeEventListener(`input`,e,!0)},[]),(0,$.jsx)(E,{onError:e=>{let n=e.message||``,r=e.code,o=n.toLowerCase();if(r===`EMAIL_NOT_VERIFIED`||o.includes(`email`)&&(o.includes(`verif`)||o.includes(`not verified`))){let e=new URLSearchParams;a.current&&e.set(`email`,a.current),t&&e.set(`redirect`,t),i(`/verify-email-prompt?${e.toString()}`)}},title:n(`auth.login.title`,{defaultValue:`Sign in to your account`}),description:n(`auth.login.description`,{defaultValue:`Enter your email and password to continue`}),registerUrl:e,forgotPasswordUrl:`/forgot-password`,linkComponent:MC,errorMessages:Xv(n),labels:{emailLabel:n(`auth.login.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:n(`auth.login.emailPlaceholder`,{defaultValue:`name@example.com`}),emailOrPhoneLabel:n(`auth.login.emailOrPhoneLabel`,{defaultValue:`Email or phone number`}),emailOrPhonePlaceholder:n(`auth.login.emailOrPhonePlaceholder`,{defaultValue:`name@example.com or +1 555 000 0000`}),passwordLabel:n(`auth.login.passwordLabel`,{defaultValue:`Password`}),passwordPlaceholder:n(`auth.login.passwordPlaceholder`,{defaultValue:`Enter your password`}),forgotPasswordText:n(`auth.login.forgotPasswordText`,{defaultValue:`Forgot password?`}),submitButton:n(`auth.login.submitButton`,{defaultValue:`Sign In`}),submittingButton:n(`auth.login.submittingButton`,{defaultValue:`Signing in…`}),noAccountText:n(`auth.login.noAccountText`,{defaultValue:`Don't have an account?`}),signUpText:n(`auth.login.signUpText`,{defaultValue:`Sign up`}),phoneLabel:n(`auth.login.phoneLabel`,{defaultValue:`Phone number`}),phonePlaceholder:n(`auth.login.phonePlaceholder`,{defaultValue:`+1 555 000 0000`}),otpCodeLabel:n(`auth.login.otpCodeLabel`,{defaultValue:`Verification code`}),otpCodePlaceholder:n(`auth.login.otpCodePlaceholder`,{defaultValue:`6-digit code`}),sendOtpButton:n(`auth.login.sendOtpButton`,{defaultValue:`Get code`}),resendOtpCountdownText:n(`auth.login.resendOtpCountdownText`,{defaultValue:`Resend in {seconds}s`}),usePhoneOtpText:n(`auth.login.usePhoneOtpText`,{defaultValue:`Sign in with verification code`}),usePasswordSignInText:n(`auth.login.usePasswordSignInText`,{defaultValue:`Sign in with password instead`}),socialButton:n(`auth.login.socialButton`,{defaultValue:`Continue with {provider}`}),orText:n(`auth.login.orText`,{defaultValue:`or continue with email`})}})}function FC(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function IC(e){return(0,$.jsx)(p,{to:e.href,className:e.className,children:e.children})}function LC(){let{t:e}=J(),t=r(),[n]=l(),i=n.get(`redirect`),{user:a,isLoading:o,organizations:s,isOrganizationsLoading:c,activeOrganization:u,switchOrganization:d,getAuthConfig:f}=A(),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),_=(0,Q.useRef)(!1),[v,y]=(0,Q.useState)(!1);if((0,Q.useLayoutEffect)(()=>{o||y(!0)},[o]),(0,Q.useEffect)(()=>{let e=!1;return f().then(n=>{if(e)return;let r=n?.emailPassword?.disableSignUp===!0;if(m(r),r){let e=i?`?redirect=${encodeURIComponent(i)}`:``;t(`/login${e}`,{replace:!0})}}).catch(()=>{e||m(!1)}),()=>{e=!0}},[f,t,i]),(0,Q.useEffect)(()=>{if(a){if(typeof window<`u`){let e=new URLSearchParams(window.location.search);if(e.has(`client_id`)&&e.has(`redirect_uri`)){_.current||(_.current=!0,kC(window.location.search));return}}if(!u){if(c||h)return;if(s.length===1){g(!0),d(s[0].id).catch(()=>void 0).finally(()=>g(!1));return}if(s.length===0){window.location.assign(AS(FC(i)?i:`/`));return}window.location.assign(AS(`/organizations`));return}h||window.location.assign(AS(FC(i)?i:`/`))}},[a,u,s,c,h,i,d]),p===null||o&&!v||a)return(0,$.jsx)(OC,{children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:(0,$.jsx)(`div`,{className:`size-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent`})})});let x=i?`/login?redirect=${encodeURIComponent(i)}`:`/login`,S=FC(i)?jS(i):void 0;return(0,$.jsx)(OC,{formWidth:`md`,children:(0,$.jsx)(Ue,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,$.jsx)(b,{title:e(`auth.register.title`,{defaultValue:`Create an account`}),description:e(`auth.register.description`,{defaultValue:`Create your account to start building.`}),loginUrl:x,verificationCallbackURL:S,linkComponent:IC,errorMessages:Zv(e),onVerificationRequired:e=>{let n=new URLSearchParams;n.set(`email`,e),i&&n.set(`redirect`,i),t(`/verify-email-prompt?${n.toString()}`,{replace:!0})},labels:{nameLabel:e(`auth.register.nameLabel`,{defaultValue:`Name`}),namePlaceholder:e(`auth.register.namePlaceholder`,{defaultValue:`John Doe`}),emailLabel:e(`auth.register.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:e(`auth.register.emailPlaceholder`,{defaultValue:`name@example.com`}),passwordLabel:e(`auth.register.passwordLabel`,{defaultValue:`Password`}),passwordPlaceholder:e(`auth.register.passwordPlaceholder`,{defaultValue:`Create a password (min. 8 characters)`}),confirmPasswordLabel:e(`auth.register.confirmPasswordLabel`,{defaultValue:`Confirm Password`}),confirmPasswordPlaceholder:e(`auth.register.confirmPasswordPlaceholder`,{defaultValue:`Confirm your password`}),passwordMismatchError:e(`auth.register.passwordMismatchError`,{defaultValue:`Passwords do not match`}),passwordTooShortError:e(`auth.register.passwordTooShortError`,{defaultValue:`Password must be at least 8 characters`}),submitButton:e(`auth.register.submitButton`,{defaultValue:`Create Account`}),submittingButton:e(`auth.register.submittingButton`,{defaultValue:`Creating account…`}),hasAccountText:e(`auth.register.hasAccountText`,{defaultValue:`Already have an account?`}),signInText:e(`auth.register.signInText`,{defaultValue:`Sign in`}),socialButton:e(`auth.register.socialButton`,{defaultValue:`Sign up with {provider}`}),orText:e(`auth.register.orText`,{defaultValue:`or continue with email`})}})})})}function RC(e){return(0,$.jsx)(p,{to:e.href,className:e.className,children:e.children})}function zC(){let{t:e}=J();return(0,$.jsx)(OC,{formWidth:`md`,children:(0,$.jsx)(Ue,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,$.jsx)(M,{loginUrl:`/login`,linkComponent:RC,title:e(`auth.forgotPassword.title`,{defaultValue:`Reset your password`}),description:e(`auth.forgotPassword.description`,{defaultValue:`Enter your email address and we'll send you a link to reset your password`}),labels:{emailLabel:e(`auth.forgotPassword.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:e(`auth.forgotPassword.emailPlaceholder`,{defaultValue:`name@example.com`}),submitButton:e(`auth.forgotPassword.submitButton`,{defaultValue:`Send Reset Link`}),submittingButton:e(`auth.forgotPassword.submittingButton`,{defaultValue:`Sending…`}),successTitle:e(`auth.forgotPassword.successTitle`,{defaultValue:`Check your email`}),successDescription:e(`auth.forgotPassword.successDescription`,{defaultValue:`We've sent a password reset link to {email}. Please check your inbox.`}),backToSignInText:e(`auth.forgotPassword.backToSignInText`,{defaultValue:`Back to sign in`}),phoneLabel:e(`auth.forgotPassword.phoneLabel`,{defaultValue:`Phone number`}),phonePlaceholder:e(`auth.forgotPassword.phonePlaceholder`,{defaultValue:`+1 555 000 0000`}),otpCodeLabel:e(`auth.forgotPassword.otpCodeLabel`,{defaultValue:`Verification code`}),otpCodePlaceholder:e(`auth.forgotPassword.otpCodePlaceholder`,{defaultValue:`6-digit code`}),sendOtpButton:e(`auth.forgotPassword.sendOtpButton`,{defaultValue:`Get code`}),resendOtpCountdownText:e(`auth.forgotPassword.resendOtpCountdownText`,{defaultValue:`Resend in {seconds}s`}),newPasswordLabel:e(`auth.forgotPassword.newPasswordLabel`,{defaultValue:`New password`}),newPasswordPlaceholder:e(`auth.forgotPassword.newPasswordPlaceholder`,{defaultValue:`Enter a new password`}),resetButton:e(`auth.forgotPassword.resetButton`,{defaultValue:`Reset Password`}),usePhoneResetText:e(`auth.forgotPassword.usePhoneResetText`,{defaultValue:`Reset via SMS code`}),useEmailResetText:e(`auth.forgotPassword.useEmailResetText`,{defaultValue:`Reset via email instead`}),phoneSuccessTitle:e(`auth.forgotPassword.phoneSuccessTitle`,{defaultValue:`Password reset`}),phoneSuccessDescription:e(`auth.forgotPassword.phoneSuccessDescription`,{defaultValue:`Your password has been reset. You can now sign in with your new password.`}),rememberPasswordText:e(`auth.forgotPassword.rememberPasswordText`,{defaultValue:`Remember your password?`}),signInText:e(`auth.forgotPassword.signInText`,{defaultValue:`Sign in`})}})})})}function BC(){let{t:e}=J(),t=r(),[n]=l(),i=n.get(`token`),{resetPassword:a}=A(),[o,s]=(0,Q.useState)(``),[c,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(!1);return(0,$.jsx)(OC,{children:(0,$.jsxs)(Ue,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(be,{className:`text-xl tracking-tight`,children:e(`auth.resetPassword.title`,{defaultValue:`Set a new password`})}),(0,$.jsx)(Ve,{children:e(`auth.resetPassword.description`,{defaultValue:`Choose a password you have not used before.`})})]}),(0,$.jsx)(W,{children:i?(0,$.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),o!==c){Y.error(e(`auth.resetPassword.passwordsMismatch`,{defaultValue:`Passwords do not match`}));return}if(!i){Y.error(e(`auth.resetPassword.missingToken`,{defaultValue:`Reset link is missing or expired`}));return}f(!0);try{await a(i,o),Y.success(e(`auth.resetPassword.success`,{defaultValue:`Password updated`})),t(`/login`)}catch(t){Y.error(e(`auth.resetPassword.failed`,{defaultValue:`Reset failed`}),{description:t.message})}finally{f(!1)}},className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(z,{htmlFor:`new-password`,children:e(`auth.resetPassword.newPassword`,{defaultValue:`New password`})}),(0,$.jsx)(K,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:o,onChange:e=>s(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(z,{htmlFor:`confirm-password`,children:e(`auth.resetPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,$.jsx)(K,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:c,onChange:e=>u(e.target.value)})]}),(0,$.jsx)(q,{type:`submit`,className:`w-full`,disabled:d,children:d?e(`auth.resetPassword.submitting`,{defaultValue:`Updating…`}):e(`auth.resetPassword.submit`,{defaultValue:`Update password`})})]}):(0,$.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.resetPassword.invalidToken`,{defaultValue:`This reset link is invalid or has expired.`}),` `,(0,$.jsx)(p,{to:`/forgot-password`,className:`font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.resetPassword.requestNewLink`,{defaultValue:`Request a new link`})})]})})]})})}function VC(e){return e&&e.startsWith(`/`)&&!e.startsWith(`//`)?e:`/`}function HC(){let{t:e}=J(),t=r(),[n]=l(),i=VC(n.get(`next`)),{user:a,isLoading:o,setInitialPassword:s}=A(),[c,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(!1);return(0,$.jsx)(OC,{children:(0,$.jsxs)(Ue,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(be,{className:`text-xl tracking-tight`,children:e(`auth.setPassword.title`)}),(0,$.jsx)(Ve,{children:e(`auth.setPassword.description`)})]}),(0,$.jsx)(W,{children:!o&&!a?(0,$.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.setPassword.noSession`),` `,(0,$.jsx)(p,{to:`/login`,className:`font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.setPassword.backToSignIn`)})]}):(0,$.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),c!==d){Y.error(e(`auth.setPassword.passwordsMismatch`));return}h(!0);try{await s(c),Y.success(e(`auth.setPassword.success`)),t(i)}catch(t){Y.error(e(`auth.setPassword.failed`),{description:t.message})}finally{h(!1)}},className:`flex flex-col gap-4`,children:[a?.email?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(z,{htmlFor:`set-password-email`,children:e(`auth.setPassword.email`)}),(0,$.jsx)(K,{id:`set-password-email`,type:`email`,autoComplete:`username`,value:a.email,disabled:!0,className:`bg-muted text-muted-foreground`})]}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(z,{htmlFor:`new-password`,children:e(`auth.setPassword.newPassword`)}),(0,$.jsx)(K,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:c,onChange:e=>u(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(z,{htmlFor:`confirm-password`,children:e(`auth.setPassword.confirmPassword`)}),(0,$.jsx)(K,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:d,onChange:e=>f(e.target.value)})]}),(0,$.jsx)(q,{type:`submit`,className:`w-full`,disabled:m,children:e(m?`auth.setPassword.submitting`:`auth.setPassword.submit`)})]})})]})})}var UC=`/api/v1/auth`;function WC(){let{t:e}=J(),[t]=l(),n=t.get(`token`),[r,i]=(0,Q.useState)(`loading`),[a,o]=(0,Q.useState)(``);return(0,Q.useEffect)(()=>{if(!n){i(`error`),o(e(`auth.verifyEmail.missingToken`,{defaultValue:`Verification link is missing a token.`}));return}let t=!1;return(async()=>{try{let e=await fetch(`${UC}/verify-email`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({token:n})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t?.message||`Verification failed: ${e.status}`)}t||i(`success`)}catch(n){t||(i(`error`),o(n.message||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})))}})(),()=>{t=!0}},[n,e]),(0,$.jsx)(OC,{children:(0,$.jsxs)(Ue,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[r===`loading`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(be,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.verifyingTitle`,{defaultValue:`Verifying…`})}),(0,$.jsx)(Ve,{children:e(`auth.verifyEmail.verifyingDescription`,{defaultValue:`Hang tight while we confirm your email.`})})]}),(0,$.jsx)(W,{className:`flex justify-center py-6`,children:(0,$.jsx)(`div`,{className:`h-10 w-10 animate-spin rounded-full border-4 border-muted border-t-primary`})})]}),r===`success`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-2 flex size-12 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-500 ring-1 ring-emerald-500/30`,children:(0,$.jsx)(Ir,{className:`size-6`})}),(0,$.jsx)(be,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.successTitle`,{defaultValue:`Email verified`})}),(0,$.jsx)(Ve,{children:e(`auth.verifyEmail.successDescription`,{defaultValue:`Your email is confirmed. You can now sign in.`})})]}),(0,$.jsx)(W,{className:`text-center`,children:(0,$.jsx)(p,{to:`/login`,className:`text-sm font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.verifyEmail.signInLink`,{defaultValue:`Go to sign in`})})})]}),r===`error`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-2 flex size-12 items-center justify-center rounded-full bg-destructive/10 text-destructive ring-1 ring-destructive/30`,children:(0,$.jsx)(zr,{className:`size-6`})}),(0,$.jsx)(be,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.errorTitle`,{defaultValue:`Verification failed`})}),(0,$.jsx)(Ve,{children:a||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})})]}),(0,$.jsx)(W,{className:`text-center`,children:(0,$.jsx)(p,{to:`/login`,className:`text-sm font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.verifyEmail.backToSignIn`,{defaultValue:`Back to sign in`})})})]})]})})}function GC(){let{t:e}=J(),t=r(),[n]=l(),i=n.get(`email`)??``,a=n.get(`redirect`)??``,{sendVerificationEmail:o}=A(),[s,c]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(null);return(0,$.jsx)(OC,{children:(0,$.jsxs)(Ue,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-4 flex size-16 items-center justify-center rounded-full bg-primary/10`,children:(0,$.jsx)(yi,{className:`size-8 text-primary`})}),(0,$.jsx)(be,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.title`,{defaultValue:`Verify your email address`})}),(0,$.jsx)(Ve,{children:e(`auth.verifyEmail.description`,{defaultValue:`We sent a verification link to your email address. Please click the link to verify your account.`})})]}),(0,$.jsx)(W,{children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[i?(0,$.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.verifyEmail.sentTo`,{defaultValue:`Sent to:`}),` `,(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:i})]}):null,f?(0,$.jsxs)(`div`,{role:`alert`,className:`rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:[(0,$.jsx)(`p`,{className:`font-medium`,children:e(`auth.verifyEmail.resendFailed`,{defaultValue:`Cannot resend verification email`})}),(0,$.jsx)(`p`,{className:`mt-1 text-destructive/90`,children:f})]}):null,(0,$.jsx)(q,{onClick:async()=>{if(!i){Y.error(e(`auth.verifyEmail.resendFailed`,{defaultValue:`Cannot resend verification email`}),{description:e(`auth.verifyEmail.emailMissing`,{defaultValue:`Email address is missing`})});return}c(!0),p(null);try{let t=a.startsWith(`/`)&&!a.startsWith(`//`)?jS(a):void 0;await o(i,t),d(!0),Y.success(e(`auth.verifyEmail.resentSuccess`,{defaultValue:`Verification email sent!`}),{description:e(`auth.verifyEmail.resentDescription`,{defaultValue:`Please check your inbox and click the verification link.`})})}catch(t){let n=t?.message?.trim()||e(`auth.verifyEmail.resendUnavailable`,{defaultValue:`Email delivery may not be configured for this environment. Contact support if this persists.`});d(!1),p(n),Y.error(e(`auth.verifyEmail.resendFailed`,{defaultValue:`Cannot resend verification email`}),{description:n})}finally{c(!1)}},disabled:s||u,className:`w-full`,variant:u?`outline`:`default`,children:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(zi,{className:`mr-2 size-4 animate-spin`}),e(`auth.verifyEmail.resending`,{defaultValue:`Sending…`})]}):u?e(`auth.verifyEmail.resent`,{defaultValue:`Email sent! Check your inbox`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(zi,{className:`mr-2 size-4`}),e(`auth.verifyEmail.resendButton`,{defaultValue:`Resend verification email`})]})}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,$.jsx)(`span`,{className:`w-full border-t`})}),(0,$.jsx)(`div`,{className:`relative flex justify-center text-xs uppercase`,children:(0,$.jsx)(`span`,{className:`bg-card px-2 text-muted-foreground`,children:e(`auth.verifyEmail.or`,{defaultValue:`Or`})})})]}),(0,$.jsx)(q,{onClick:()=>{let e=a?`?redirect=${encodeURIComponent(a)}`:``;t(`/login${e}`)},variant:`ghost`,className:`w-full`,children:e(`auth.verifyEmail.backToLogin`,{defaultValue:`Back to login`})}),(0,$.jsx)(`p`,{className:`text-center text-xs text-muted-foreground`,children:e(`auth.verifyEmail.checkSpam`,{defaultValue:`Didn't receive the email? Check your spam folder or contact support.`})})]})})]})})}var KC=`/api/v1/auth`;function qC(){let{t:e}=J(),t=r(),{user:n,isLoading:i}=A(),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null),l=typeof window<`u`?window.location.search:``,u=l.startsWith(`?`)?l.slice(1):l,d=new URLSearchParams(u),f=d.get(`client_id`)??void 0,p=d.get(`scope`)??``;(0,Q.useEffect)(()=>{if(!i&&!n){let e=window.location.pathname+window.location.search;t(`/login?redirect=${encodeURIComponent(e)}`,{replace:!0})}},[n,i,t]),(0,Q.useEffect)(()=>{if(!f)return;let e=!1;return fetch(`${KC}/oauth2/applications/${encodeURIComponent(f)}/public`,{credentials:`include`}).then(async t=>{if(!t.ok)return;let n=await t.json().catch(()=>({}));if(e)return;let r=n?.data??n;c(r)}).catch(()=>{}),()=>{e=!0}},[f]);let m=p.split(/\s+/).filter(Boolean),h=async t=>{o(!0);try{let n=await fetch(`${KC}/oauth2/consent`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({accept:t,oauth_query:u})}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r?.message||`Consent failed: ${n.status}`);let i=r.redirect_uri??r.redirectURI??r.url;if(i){window.location.href=i;return}let a=t?e(`oauth.consent.granted`,{defaultValue:`Access granted`}):e(`oauth.consent.denied`,{defaultValue:`Access denied`});Y(a,{description:e(`oauth.consent.noRedirect`,{defaultValue:`No redirect URL returned by the server.`})})}catch(t){Y.error(e(`oauth.consent.failed`,{defaultValue:`Consent failed`}),{description:t.message})}finally{o(!1)}},g=s?.name??s?.client_name??f??e(`oauth.consent.unknownApp`,{defaultValue:`an application`});return(0,$.jsx)(`div`,{className:`flex min-h-svh w-full flex-1 items-center justify-center bg-background px-4`,children:(0,$.jsxs)(Ue,{className:`w-full max-w-md`,children:[(0,$.jsxs)(We,{className:`items-center text-center`,children:[(0,$.jsx)(`div`,{className:`mb-3 rounded-full border bg-muted p-3`,children:s?.icon||s?.logo_uri?(0,$.jsx)(`img`,{src:s.icon||s.logo_uri,alt:``,className:`h-8 w-8 rounded`,onError:e=>{e.currentTarget.style.display=`none`}}):(0,$.jsx)(ui,{className:`h-7 w-7 text-muted-foreground`})}),(0,$.jsx)(be,{className:`text-xl`,children:e(`oauth.consent.title`,{appName:g,defaultValue:`${g} wants to access your account`})}),(0,$.jsx)(Ve,{children:e(`oauth.consent.request`,{appName:g,suffix:n?.email?` (${n.email})`:``,defaultValue:`${g} is requesting permission${n?.email?` for ${n.email}`:``}.`})})]}),(0,$.jsxs)(W,{className:`space-y-4`,children:[m.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:e(`oauth.consent.willAllow`,{defaultValue:`This app will be able to:`})}),(0,$.jsx)(`ul`,{className:`space-y-1.5 rounded-md border bg-muted/40 p-3 text-sm`,children:m.map(t=>(0,$.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(kr,{className:`mt-0.5 h-4 w-4 text-green-600 dark:text-green-400`}),(0,$.jsx)(`span`,{children:JC(t,e)})]},t))})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-2`,children:[(0,$.jsxs)(q,{variant:`outline`,onClick:()=>h(!1),disabled:a,children:[(0,$.jsx)(ba,{className:`mr-2 h-4 w-4`}),e(`oauth.consent.deny`,{defaultValue:`Deny`})]}),(0,$.jsxs)(q,{onClick:()=>h(!0),disabled:a,children:[(0,$.jsx)(kr,{className:`mr-2 h-4 w-4`}),a?e(`oauth.consent.submitting`,{defaultValue:`Authorizing…`}):e(`oauth.consent.authorize`,{defaultValue:`Authorize`})]})]}),(0,$.jsx)(`p`,{className:`pt-2 text-center text-xs text-muted-foreground`,children:e(`oauth.consent.footer`,{defaultValue:`You can revoke access at any time from your account settings.`})})]})]})})}function JC(e,t){switch(e){case`openid`:return t(`oauth.consent.scope.openid`,{defaultValue:`Confirm your identity`});case`profile`:return t(`oauth.consent.scope.profile`,{defaultValue:`Read your basic profile (name, picture)`});case`email`:return t(`oauth.consent.scope.email`,{defaultValue:`Read your email address`});case`offline_access`:return t(`oauth.consent.scope.offlineAccess`,{defaultValue:`Stay signed in (refresh access)`});default:return e}}var YC=`/api/v1/auth`;function XC({children:e}){return(0,$.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center gap-6 bg-muted p-6 md:p-10`,children:(0,$.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col gap-6`,children:[(0,$.jsxs)(`a`,{href:`#`,className:`flex items-center gap-2 self-center font-medium`,children:[(0,$.jsx)(`div`,{className:`flex size-6 items-center justify-center rounded-md bg-primary text-primary-foreground overflow-hidden`,children:Rs()?(0,$.jsx)(`img`,{src:Rs(),alt:Gs(),className:`h-full w-full object-contain`}):(0,$.jsx)(Ir,{className:`size-4`})}),Gs()]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-6`,children:e})]})})}function ZC(){let{t:e}=J(),n=g(),[i]=l(),a=i.get(`user_code`)??i.get(`code`)??``,o=i.get(`runtime_name`)??``,s=i.get(`runtime_version`)??``,{user:c,isLoading:u,getAuthConfig:d}=A(),f=r(),[p,m]=(0,Q.useState)(!1),[h,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(``),[w,T]=(0,Q.useState)(null);if((0,Q.useEffect)(()=>{let e=!0;return d().then(t=>{e&&T(t?.features?.deviceAuthorization===!0)}).catch(()=>{e&&T(!0)}),()=>{e=!1}},[d]),!a)return(0,$.jsx)(XC,{children:(0,$.jsx)(Ue,{children:(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(be,{children:e(`auth.device.invalidTitle`,{defaultValue:`Invalid device link`})}),(0,$.jsx)(Ve,{children:e(`auth.device.invalidDescription`,{defaultValue:`No device code was provided in the URL.`})})]})})});if(w===!1)return(0,$.jsx)(XC,{children:(0,$.jsx)(Ue,{children:(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(be,{children:e(`auth.device.disabledTitle`,{defaultValue:`Device authorization not enabled`})}),(0,$.jsx)(Ve,{children:e(`auth.device.disabledDescription`,{defaultValue:`This deployment does not have device authorization enabled, so this device cannot be approved here.`})})]})})});if(u||w===null)return(0,$.jsx)(XC,{children:(0,$.jsx)(Ue,{children:(0,$.jsx)(We,{className:`text-center`,children:(0,$.jsx)(Ve,{children:e(`auth.device.loading`,{defaultValue:`Loading…`})})})})});if(!c)return(0,$.jsx)(t,{to:`/login?redirect=${encodeURIComponent(`/auth/device${n.search}`)}`,replace:!0});if(v)return(0,$.jsx)(XC,{children:(0,$.jsx)(Ue,{children:(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(Ir,{className:`mx-auto mb-2 h-10 w-10 text-green-500`}),(0,$.jsx)(be,{children:e(`auth.device.approvedTitle`,{defaultValue:`Device authorized`})}),(0,$.jsx)(Ve,{children:e(`auth.device.approvedDescription`,{defaultValue:`You can return to the device — it should sign in shortly.`})})]})})});if(b)return(0,$.jsx)(XC,{children:(0,$.jsx)(Ue,{children:(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(be,{children:e(`auth.device.deniedTitle`,{defaultValue:`Access denied`})}),(0,$.jsx)(Ve,{children:e(`auth.device.deniedDescription`,{defaultValue:`The device will not be granted access.`})})]})})});let E=async()=>{await fetch(`${YC}/device?user_code=${encodeURIComponent(a)}`,{credentials:`include`}).catch(()=>{})};return(0,$.jsx)(XC,{children:(0,$.jsxs)(Ue,{children:[(0,$.jsxs)(We,{className:`text-center`,children:[(0,$.jsx)(be,{children:e(`auth.device.title`,{defaultValue:`Authorize new device`})}),(0,$.jsx)(Ve,{children:e(`auth.device.subtitle`,{email:c.email,defaultValue:`Approve this device to sign in as ${c.email}.`})})]}),(0,$.jsxs)(W,{className:`space-y-4`,children:[o?(0,$.jsxs)(`div`,{className:`rounded-md border bg-background px-4 py-3 text-center`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e(`auth.device.requesterLabel`,{defaultValue:`Connection request from`})}),(0,$.jsx)(`p`,{className:`font-medium`,children:o}),s?(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[Gs().toLowerCase(),` `,s]}):null]}):null,(0,$.jsxs)(`div`,{className:`rounded-md border bg-background px-4 py-3 text-center`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e(`auth.device.userCodeLabel`,{defaultValue:`Device code`})}),(0,$.jsx)(`p`,{className:`font-mono text-lg font-semibold tracking-widest`,children:a})]}),(0,$.jsx)(`p`,{className:`text-center text-xs text-muted-foreground`,children:e(`auth.device.approveWarning`,{defaultValue:`Only approve if you started this connection yourself a moment ago. Once approved, this runtime can access your organization's private packages.`})}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-center text-sm text-muted-foreground`,children:e(`auth.device.loggedInAs`,{email:c.email,defaultValue:`Signed in as ${c.email}`})}),S&&(0,$.jsx)(`p`,{className:`text-center text-sm text-destructive`,children:S}),(0,$.jsx)(q,{onClick:async()=>{C(``),m(!0);try{await E();let t=await fetch(`${YC}/device/approve`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({userCode:a})});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n?.message??n?.error?.message??e(`auth.device.approveFailed`,{defaultValue:`Approval failed`}))}y(!0),Y.success(e(`auth.device.approveSuccess`,{defaultValue:`Device authorized`}),{description:e(`auth.device.approveSuccessDescription`,{defaultValue:`You can close this window.`})})}catch(t){C(t?.message??e(`auth.device.approveFailed`,{defaultValue:`Approval failed`}))}finally{m(!1)}},className:`w-full`,disabled:p||h,children:p?e(`auth.device.approving`,{defaultValue:`Approving…`}):e(`auth.device.approve`,{defaultValue:`Approve device`})}),(0,$.jsx)(q,{onClick:async()=>{C(``),_(!0);try{await E(),await fetch(`${YC}/device/deny`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({userCode:a})}),x(!0)}catch(t){C(t?.message??e(`auth.device.denyFailed`,{defaultValue:`Failed to deny request`}))}finally{_(!1)}},variant:`outline`,className:`w-full`,disabled:p||h,children:h?e(`auth.device.denying`,{defaultValue:`Denying…`}):e(`auth.device.deny`,{defaultValue:`Deny request`})}),(0,$.jsx)(`div`,{className:`text-center`,children:(0,$.jsx)(`button`,{type:`button`,className:`text-sm text-muted-foreground underline-offset-4 hover:underline`,onClick:()=>f(`/`),children:e(`auth.device.cancel`,{defaultValue:`Cancel`})})})]})]})]})})}var QC=(0,Q.lazy)(()=>o(()=>import(`./DocsLayout-BAwlJQQf.js`),__vite__mapDeps([0]),import.meta.url)),$C=(0,Q.lazy)(()=>o(()=>import(`./DocsIndex-LALVtIVR.js`),__vite__mapDeps([0]),import.meta.url)),ew=(0,Q.lazy)(()=>o(()=>import(`./DocsSlug-CkF1E-Zs.js`),__vite__mapDeps([0]),import.meta.url)),tw=(0,Q.lazy)(()=>o(()=>import(`./DocPage-CxJaQ-pC.js`),__vite__mapDeps([0]),import.meta.url)),nw=``,rw=`${nw}/api/v1/auth`;function iw(){try{if(typeof document>`u`)return`/`;let e=document.querySelector(`base`)?.getAttribute(`href`);return e&&new URL(e,window.location.origin).pathname.replace(/\/$/,``)||`/`}catch{return`/`}}var aw=iw();function ow(){let{user:e}=A();return(0,$.jsx)(Qv,{userId:e?.id,children:(0,$.jsx)(my,{})})}function sw(){let e=(0,Q.useMemo)(()=>y(),[]),r=(0,Q.useMemo)(()=>_e({baseUrl:nw,fetchImpl:e}),[e]);return(0,$.jsxs)(D,{authUrl:rw,children:[(0,$.jsx)(Bg,{}),(0,$.jsx)(bC,{}),(0,$.jsxs)(u,{basename:aw,children:[(0,$.jsx)(mS,{}),(0,$.jsx)(ze,{adapter:r,children:(0,$.jsx)(Md,{children:(0,$.jsxs)(n,{children:[(0,$.jsx)(m,{path:`/login`,element:(0,$.jsx)(NC,{})}),(0,$.jsx)(m,{path:`/register`,element:(0,$.jsx)(LC,{})}),(0,$.jsx)(m,{path:`/forgot-password`,element:(0,$.jsx)(zC,{})}),(0,$.jsx)(m,{path:`/reset-password`,element:(0,$.jsx)(BC,{})}),(0,$.jsx)(m,{path:`/set-password`,element:(0,$.jsx)(HC,{})}),(0,$.jsx)(m,{path:`/verify-email`,element:(0,$.jsx)(WC,{})}),(0,$.jsx)(m,{path:`/verify-email-prompt`,element:(0,$.jsx)(GC,{})}),(0,$.jsx)(m,{path:`/setup`,element:(0,$.jsx)(IS,{})}),(0,$.jsx)(m,{path:`/oauth/consent`,element:(0,$.jsx)(qC,{})}),(0,$.jsx)(m,{path:`/auth/device`,element:(0,$.jsx)(ZC,{})}),(0,$.jsx)(m,{path:`/accept-invitation/:invitationId`,element:(0,$.jsx)(By,{})}),(0,$.jsx)(m,{path:`/f/:slug`,element:(0,$.jsx)(_C,{mode:`public`})}),(0,$.jsx)(m,{path:`/s/:token`,element:(0,$.jsx)(CC,{})}),TS,(0,$.jsx)(m,{path:`/forms/:name`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(yC,{})})}),(0,$.jsxs)(m,{path:`/docs`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(QC,{})})}),children:[(0,$.jsx)(m,{index:!0,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)($C,{})})}),(0,$.jsx)(m,{path:`:slug`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(ew,{})})}),(0,$.jsx)(m,{path:`:slug/:name`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(rd,{}),children:(0,$.jsx)(tw,{})})})]}),(0,$.jsx)(m,{path:`/home`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(ow,{})})}),(0,$.jsx)(m,{path:`/dev/master-detail`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(Wl,{})})}),(0,$.jsx)(m,{path:`/dev/lists`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(ql,{})})}),(0,$.jsx)(m,{path:`/dev/modal`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(Lx,{})})}),(0,$.jsx)(m,{path:`/dev/lookup`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(Rx,{})})}),(0,$.jsx)(m,{path:`/dev/row-actions`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(Ux,{})})}),(0,$.jsx)(m,{path:`/organizations`,element:(0,$.jsx)(xS,{requireOrganization:!1,children:(0,$.jsx)(hy,{children:(0,$.jsx)(wy,{})})})}),(0,$.jsxs)(m,{path:`/organizations/:slug`,element:(0,$.jsx)(xS,{requireOrganization:!1,children:(0,$.jsx)(Ty,{})}),children:[(0,$.jsx)(m,{index:!0,element:(0,$.jsx)(t,{to:`members`,replace:!0})}),(0,$.jsx)(m,{path:`members`,element:(0,$.jsx)(Iy,{})}),(0,$.jsx)(m,{path:`invitations`,element:(0,$.jsx)(Ry,{})}),(0,$.jsx)(m,{path:`settings`,element:(0,$.jsx)(zy,{})})]}),(0,$.jsx)(m,{path:`/system/*`,element:(0,$.jsx)(Bd,{})}),(0,$.jsx)(m,{path:`/ai`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(zd,{children:(0,$.jsx)(Um,{})})})}),(0,$.jsx)(m,{path:`/ai/:agent`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(zd,{children:(0,$.jsx)(Um,{})})})}),(0,$.jsx)(m,{path:`/ai/:agent/:conversationId`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(zd,{children:(0,$.jsx)(Um,{})})})}),(0,$.jsx)(m,{path:`/apps/:appName/*`,element:(0,$.jsx)(xS,{children:(0,$.jsx)(pS,{})})}),(0,$.jsx)(m,{path:`/`,element:(0,$.jsx)(xS,{requireOrganization:!1,children:(0,$.jsx)(yS,{})})}),(0,$.jsx)(m,{path:`*`,element:(0,$.jsx)(id,{to:`/`,replace:!0})})]})})})]})]})}async function cw(e){try{let t=await fetch(`/api/v1/i18n/translations/${e}`);if(!t.ok)return console.warn(`[i18n] Failed to load translations for '${e}': HTTP ${t.status}`),{};let n=await t.json(),r;return r=n?.data?.translations&&typeof n.data.translations==`object`?n.data.translations:n,Yn(r)?Qn(r):r}catch(t){return console.warn(`[i18n] Failed to load translations for '${e}':`,t),{}}}async function lw(){try{let e=await fetch(`/api/v1/i18n/locales`);if(!e.ok)return console.warn(`[i18n] Failed to load the app locale list: HTTP ${e.status}`),[];let t=await e.json(),n=t?.data?.locales??t?.locales??t;if(!Array.isArray(n))return console.warn(`[i18n] Unexpected /i18n/locales payload; ignoring.`),[];let r=[];for(let e of n){let t=typeof e==`string`?e:e?.code;typeof t==`string`&&t.length>0&&!r.includes(t)&&r.push(t)}return r}catch(e){return console.warn(`[i18n] Failed to load the app locale list:`,e),[]}}async function uw(e){let t=C();try{let n=await kn(`${e}/api/v1/auth/me/localization`,{credentials:`include`,headers:{Accept:`application/json`}});if(n?.authenticated===!1||C()!==t)return;ar(n?.locale)}catch{}}async function dw(e,t=500){if(Gn()||ir())return;let n=uw(e);await Promise.race([n,new Promise(e=>setTimeout(e,t))])}var fw=`auth-session-token`,pw=`auth-active-organization-id`;function mw(){for(let e of Object.keys(localStorage))(e===pw||e.startsWith(`${pw}:u:`))&&localStorage.removeItem(e)}async function hw(e){if(typeof window>`u`)return;let t;try{t=localStorage.getItem(fw)}catch{return}if(t)try{let n=await fetch(`${e}/get-session`,{method:`GET`,credentials:`omit`,headers:{Authorization:`Bearer ${t}`,Accept:`application/json`}});if(n.ok){let e=await n.json().catch(()=>null);if(e?.user??e?.data?.user??null)return}localStorage.removeItem(fw),mw()}catch{}}rn.registerLazy(`object-map`,()=>o(()=>import(`./plugin-map-CBJcVJYk.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),rn.registerLazy(`object-tree`,()=>o(()=>import(`./plugin-tree-DTRPBdhe.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-tree`,category:`view`});for(let e of[`dashboard`,`object-metric`,`pivot`,`object-pivot`,`object-data-table`])rn.registerLazy(e,()=>o(()=>import(`./plugin-dashboard-DTkPoPEb.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});for(let e of[`metric`,`metric-card`])rn.registerLazy(e,()=>o(()=>import(`./plugin-dashboard-DTkPoPEb.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,skipFallback:!0,category:`view`});rn.registerLazy(`chart`,()=>o(()=>import(`./plugin-charts-b-yVtmdI.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});for(let e of[`object-chart`,`bar-chart`,`chart:bar`])rn.registerLazy(e,()=>o(()=>import(`./plugin-charts-b-yVtmdI.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});rn.registerLazy(`object-gantt`,()=>o(()=>import(`./plugin-gantt-9dtc8zzX.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),rn.registerLazy(`markdown`,()=>o(()=>import(`./plugin-markdown-CNlDzqP-.js`).then(e=>e.n),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),rn.registerLazy(`object-timeline`,()=>o(()=>import(`./plugin-timeline-DsmtjcJ3.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),rn.registerLazy(`timeline`,()=>o(()=>import(`./plugin-timeline-DsmtjcJ3.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),rn.registerLazy(`object-calendar`,()=>o(()=>import(`./plugin-calendar-b7C35ANT.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),rn.registerLazy(`calendar`,()=>o(()=>import(`./plugin-calendar-b7C35ANT.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),rn.registerLazy(`calendar-view`,()=>o(()=>import(`./plugin-calendar-b7C35ANT.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),rn.registerLazy(`object-kanban`,()=>o(()=>import(`./plugin-kanban-B2JOPZIJ.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),rn.registerLazy(`report`,()=>o(()=>import(`./plugin-report-IZzgQb-Q.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`}),rn.registerLazy(`report-viewer`,()=>o(()=>import(`./plugin-report-IZzgQb-Q.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});var gw=(0,Q.lazy)(()=>o(()=>import(`./ApiConsolePage-CKYEqlMs.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),_w=(0,Q.lazy)(()=>o(()=>import(`./FlowRunsPage-R3W3t2s4.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),vw=(0,Q.lazy)(()=>o(()=>import(`./PublicFormsPage-D3AT2EH9.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url)),yw=(0,Q.lazy)(()=>o(()=>import(`./IntegrationsPage-DIuFLEbF.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([0]),import.meta.url));function bw({label:e}){return(0,$.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}Rl({ref:`developer:api-console`,label:`API Console`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(bw,{label:`API console`}),children:(0,$.jsx)(gw,{...e})})}),Rl({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(bw,{label:`flow runs`}),children:(0,$.jsx)(_w,{...e})})}),Rl({ref:`developer:public-forms`,label:`Public Forms`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(bw,{label:`public forms`}),children:(0,$.jsx)(vw,{...e})})}),Rl({ref:`developer:integrations`,label:`Integrations & APIs`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(bw,{label:`integrations`}),children:(0,$.jsx)(yw,{...e})})}),Rl({ref:`studio:builder`,label:`应用构建`,source:`@object-ui/console`,component:Fx});var xw=(0,Q.lazy)(()=>o(()=>import(`./ProfilePage-Qp8DL8CF.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function Sw(){let{t:e}=J();return(0,$.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:e(`common.loading`,{defaultValue:`Loading…`})})}Rl({ref:`account:profile_card`,label:`My Profile`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Sw,{}),children:(0,$.jsx)(xw,{...e})})});var Cw=(0,Q.lazy)(()=>o(()=>import(`./ApprovalsInboxPage-DD4fe0Em.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url));function ww(){let{t:e}=J();return(0,$.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:e(`common.loading`,{defaultValue:`Loading…`})})}Rl({ref:`approvals:inbox`,label:`Approvals Inbox`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(ww,{}),children:(0,$.jsx)(Cw,{...e})})});var Tw=(0,Q.lazy)(()=>o(()=>import(`./AuditLogPage-Sed6iMqP.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),Ew=(0,Q.lazy)(()=>o(()=>import(`./AiPendingActionsPage-Dh3-i4BB.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url));function Dw(){let{t:e}=J();return(0,$.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:e(`common.loading`,{defaultValue:`Loading…`})})}Rl({ref:`audit:log`,label:`Audit Log`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Dw,{}),children:(0,$.jsx)(Tw,{...e})})}),Rl({ref:`ai:approvals`,label:`AI Approvals`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(Dw,{}),children:(0,$.jsx)(Ew,{...e})})});var Ow=`/api/v1/auth`;et();var kw=``.replace(/\/+$/,``);Promise.all([Ls(kw),hw(Ow),dw(kw)]).finally(async()=>{await Jn({hasLoader:!0}),Jg(),document.title=Gs();let e=Ws();if(e){let t=document.getElementById(`favicon`);t&&(t.href=e,t.type=e.endsWith(`.svg`)?`image/svg+xml`:`image/png`)}let t=Lc({enabled:!0,name:Gs(),shortName:Bs(),description:zs(),themeColor:Us(),backgroundColor:`#ffffff`,display:`standalone`,startUrl:`./`,scope:`./`,orientation:`any`,icons:[{src:e||`./favicon.svg`,sizes:`any`,type:`image/svg+xml`,purpose:`any`}]}),n=new Blob([JSON.stringify(t)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.querySelector(`link[rel="manifest"]`);i&&i.remove();let a=document.createElement(`link`);a.rel=`manifest`,a.href=r,document.head.appendChild(a),Hl.createRoot(document.getElementById(`root`)).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(Ic,{pwa:{enabled:!0,name:Gs(),shortName:Bs()},children:(0,$.jsx)(qn,{loadLanguage:cw,loadLocales:lw,children:(0,$.jsx)(sw,{})})})}))});