@objectstack/console 12.3.0 → 12.4.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 (248) hide show
  1. package/dist/.objectui-sha +1 -1
  2. package/dist/assets/{AdapterProvider-_4c7hk3d.js → AdapterProvider-DYYVhErE.js} +1 -1
  3. package/dist/assets/{AiPendingActionsPage-Gc2Wh8Kh.js → AiPendingActionsPage-BRZ9smBE.js} +1 -1
  4. package/dist/assets/ApiConsolePage-DqCLFtg6.js +1 -0
  5. package/dist/assets/AppDocsIndex-ChTjYsgs.js +1 -0
  6. package/dist/assets/AppManagementPage-CpBtMYk7.js +1 -0
  7. package/dist/assets/ApprovalsInboxPage-Cm6RlF50.js +1 -0
  8. package/dist/assets/{AuditLogPage-C-rDSpPt.js → AuditLogPage-BUapxa-t.js} +1 -1
  9. package/dist/assets/{ComponentNavView-DX23dzZd.js → ComponentNavView-CV-L0t8o.js} +1 -1
  10. package/dist/assets/ConsoleFloatingChatbot-BtSnKZ5C.js +1 -0
  11. package/dist/assets/CreateViewDialog-CMNLzv6j.js +1 -0
  12. package/dist/assets/DashboardView-DTeb8b6a.js +1 -0
  13. package/dist/assets/DashboardWidgetInspector-CUJFDeER.js +1 -0
  14. package/dist/assets/DeveloperHubPage-CigDAiDQ.js +1 -0
  15. package/dist/assets/{ExpressionProvider-w-HoWEV1.js → ExpressionProvider-ODpzkcN3.js} +1 -1
  16. package/dist/assets/FlowRunsPage-BCTyVNQV.js +1 -0
  17. package/dist/assets/{IntegrationsPage-COvUlRq2.js → IntegrationsPage-D8453O8m.js} +2 -2
  18. package/dist/assets/InterfaceListPage-CaG6oJ3-.js +1 -0
  19. package/dist/assets/{ManagedByBadge-BZofhfqM.js → ManagedByBadge-BGSB7vGi.js} +1 -1
  20. package/dist/assets/MarketplaceAccessDenied-CAuxNcMw.js +1 -0
  21. package/dist/assets/MarketplaceInstalledPage-DIKAvmEt.js +1 -0
  22. package/dist/assets/MarketplacePackagePage-CxoOdisY.js +4 -0
  23. package/dist/assets/MarketplacePage-SkUEdd3B.js +1 -0
  24. package/dist/assets/{MetadataInspector-CpceGXDL.js → MetadataInspector-RvnQ-QOT.js} +1 -1
  25. package/dist/assets/MetadataProvider-BpQl3Bw2.js +1 -0
  26. package/dist/assets/{MonacoImpl-DoDns4Vj.js → MonacoImpl-nyLaER8_.js} +1 -1
  27. package/dist/assets/ObjectDataPage-CnMdpBNe.js +1 -0
  28. package/dist/assets/PageView-Ckvi7QO6.js +1 -0
  29. package/dist/assets/ProfilePage-7etuxYZk.js +1 -0
  30. package/dist/assets/PublicFormsPage-xWq9jZzJ.js +1 -0
  31. package/dist/assets/RecordDetailView-CzR6BAUv.js +9 -0
  32. package/dist/assets/{RecordFormPage-CbvOD5UT.js → RecordFormPage-DTyNzewM.js} +1 -1
  33. package/dist/assets/ReportDefaultInspector-BA-D9th_.js +11 -0
  34. package/dist/assets/ReportView-CHBbT7mP.js +2 -0
  35. package/dist/assets/{SearchResultsPage-D0nbmFox.js → SearchResultsPage-BIuFjDoa.js} +1 -1
  36. package/dist/assets/{SettingsHub-BsZee-2C.js → SettingsHub-ZMQjBQwP.js} +1 -1
  37. package/dist/assets/SettingsView-eCnpX1vu.js +1 -0
  38. package/dist/assets/SystemHubPage-f4hYqDoI.js +1 -0
  39. package/dist/assets/{abnfDiagram-VRR7QNED-DWrainSQ.js → abnfDiagram-VRR7QNED-o_fBNeYD.js} +1 -1
  40. package/dist/assets/architecture-TIHT7OUA-BF_0SrOH.js +1 -0
  41. package/dist/assets/{architectureDiagram-ZJ3FMSHR-BqIfH_cZ.js → architectureDiagram-ZJ3FMSHR-Bk_LES5L.js} +1 -1
  42. package/dist/assets/{assistantBus-DosfPCbN.js → assistantBus-BFk4fCbM.js} +1 -1
  43. package/dist/assets/{blockDiagram-677ZJIJ3-BDhRO3KX.js → blockDiagram-677ZJIJ3-BmONypzo.js} +1 -1
  44. package/dist/assets/{c4Diagram-LMCZKHZV-DBmvkEa3.js → c4Diagram-LMCZKHZV-DqIiaVjm.js} +1 -1
  45. package/dist/assets/channel-CvRTB8GE.js +1 -0
  46. package/dist/assets/{chunk-32BRIVSS-1_aHOdgh.js → chunk-32BRIVSS-BbTX8O4m.js} +1 -1
  47. package/dist/assets/{chunk-52WLFC77-C-mFgIG6.js → chunk-52WLFC77-DkgICN4F.js} +1 -1
  48. package/dist/assets/{chunk-C7G6YPKG-DvvI9WqY.js → chunk-C7G6YPKG-UMP_bNDd.js} +1 -1
  49. package/dist/assets/{chunk-EX3LRPZG-BaKE258M.js → chunk-EX3LRPZG-B0dJ64Ff.js} +1 -1
  50. package/dist/assets/{chunk-FWX5IMBZ-BZ1KYToN.js → chunk-FWX5IMBZ-B8cCL4T7.js} +1 -1
  51. package/dist/assets/{chunk-HOUHSVGY-BjQmUg1D.js → chunk-HOUHSVGY-B5nScni0.js} +1 -1
  52. package/dist/assets/{chunk-ICXQ74PX-DGFLQjwm.js → chunk-ICXQ74PX-zJg8KmvA.js} +1 -1
  53. package/dist/assets/{chunk-KEIR6QF5-MVybfwhZ.js → chunk-KEIR6QF5-CxDrFr0l.js} +3 -3
  54. package/dist/assets/{chunk-MOJQB5TN-aPZk6pC8.js → chunk-MOJQB5TN-DBKCpvOi.js} +1 -1
  55. package/dist/assets/{chunk-OGEWGWER-C_9e4OS0.js → chunk-OGEWGWER-bKk51Nxt.js} +1 -1
  56. package/dist/assets/{chunk-PUDLZKDR-c0kZKR-G.js → chunk-PUDLZKDR-CKn_9iXM.js} +1 -1
  57. package/dist/assets/{chunk-Q4XR5HBZ-o24M5lkF.js → chunk-Q4XR5HBZ-BP9atbVx.js} +1 -1
  58. package/dist/assets/{chunk-RYQCIY6F-DUMnfbFk.js → chunk-RYQCIY6F-B5RR1tIz.js} +1 -1
  59. package/dist/assets/{chunk-V7JOEXUC-BP0RE3_V.js → chunk-V7JOEXUC-DTerDTcg.js} +1 -1
  60. package/dist/assets/chunk-VAUOI2AC-BrcFPe7Z.js +1 -0
  61. package/dist/assets/{chunk-VR4S4FIN-DykLEeqy.js → chunk-VR4S4FIN-jB_W-MHs.js} +1 -1
  62. package/dist/assets/chunk-WYO6CB5R-Cndg0Yo5.js +127 -0
  63. package/dist/assets/chunk-XXDRQBXY-DGANY6E3.js +1 -0
  64. package/dist/assets/{chunk-ZGVPDNZ5-DQH9cJwj.js → chunk-ZGVPDNZ5-BUUSzPje.js} +1 -1
  65. package/dist/assets/classDiagram-OUVF2IWQ-BGL42sFI.js +1 -0
  66. package/dist/assets/classDiagram-v2-EOCWNBFH-BGL42sFI.js +1 -0
  67. package/dist/assets/{cose-bilkent-JH36ORCC-CDWwyRUu.js → cose-bilkent-JH36ORCC-DJ-X6wmF.js} +1 -1
  68. package/dist/assets/cynefin-VYW2F7L2-CXt4AgYW.js +1 -0
  69. package/dist/assets/{cynefinDiagram-TSTJHNR4-Dn83Cn2D.js → cynefinDiagram-TSTJHNR4-C5mKt5aU.js} +1 -1
  70. package/dist/assets/{cytoscape.esm-Djp6vQyU.js → cytoscape.esm-B3I8pqwA.js} +1 -1
  71. package/dist/assets/{dagre-VKFMJZFB-DYKhgtL2.js → dagre-VKFMJZFB-Crs38V5P.js} +2 -2
  72. package/dist/assets/{data-adapter-W6WwA2ln.js → data-adapter-DLOPVTZ2.js} +1 -1
  73. package/dist/assets/{diagram-FQU43EPY-84kGXmcJ.js → diagram-FQU43EPY-Bkx8ccpS.js} +1 -1
  74. package/dist/assets/{diagram-G47NLZAW-FzYRzXJF.js → diagram-G47NLZAW-CSNJrWDK.js} +1 -1
  75. package/dist/assets/{diagram-NH7WQ7WH-D2_7Upma.js → diagram-NH7WQ7WH-PaRAbfdR.js} +1 -1
  76. package/dist/assets/{diagram-OA4YK3LP-uqOHgtNB.js → diagram-OA4YK3LP-C2A07yOA.js} +1 -1
  77. package/dist/assets/{diagram-WEI45ONY-BoLpoJXF.js → diagram-WEI45ONY-BEyyGNpU.js} +1 -1
  78. package/dist/assets/{dist-CfcbLQde.js → dist-YwlXXOlT.js} +1 -1
  79. package/dist/assets/{ebnfDiagram-CCIWWBDH-DLYgN3Ab.js → ebnfDiagram-CCIWWBDH-CtfwkNuv.js} +1 -1
  80. package/dist/assets/{erDiagram-Q63AITRT-BmagGyFR.js → erDiagram-Q63AITRT-DjK6P1sf.js} +1 -1
  81. package/dist/assets/eventmodeling-45OFAUF4-Dmacb12o.js +1 -0
  82. package/dist/assets/{exceljs.min-DIyttv_G.js → exceljs.min-Dpb6mnud.js} +2 -2
  83. package/dist/assets/flowDiagram-23GEKE2U-DfQvGNQk.js +1 -0
  84. package/dist/assets/framework-B3O15Lsq.js +36 -0
  85. package/dist/assets/{ganttDiagram-NO4QXBWP-DdGzwLRB.js → ganttDiagram-NO4QXBWP-UPhpWlEd.js} +1 -1
  86. package/dist/assets/getIcon-B5xaQx5N.js +1 -0
  87. package/dist/assets/gitGraph-TEB2WS4Q-ChM6j6Bd.js +1 -0
  88. package/dist/assets/{gitGraphDiagram-IHSO6WYX-Dv8qb0qh.js → gitGraphDiagram-IHSO6WYX-B6Qcltd9.js} +2 -2
  89. package/dist/assets/{highlighted-body-OFNGDK62-CLUabCIi.js → highlighted-body-OFNGDK62-B_roNkgm.js} +1 -1
  90. package/dist/assets/index-B-sF8xtC.css +2 -0
  91. package/dist/assets/index-TdJi7kFM.js +2 -0
  92. package/dist/assets/info-DKCQHKI2-C0RTkygr.js +1 -0
  93. package/dist/assets/{infoDiagram-FWYZ7A6U-BnI8Gbdt.js → infoDiagram-FWYZ7A6U-CgEoZeWY.js} +1 -1
  94. package/dist/assets/infrastructure-Bcx6-8du.js +3 -0
  95. package/dist/assets/{ishikawaDiagram-FXEZZL3T-BfpmvVA0.js → ishikawaDiagram-FXEZZL3T-DvmRhm8H.js} +1 -1
  96. package/dist/assets/{journeyDiagram-5HDEW3XC-8UQvh7pY.js → journeyDiagram-5HDEW3XC-DFf6bjOX.js} +2 -2
  97. package/dist/assets/{kanban-definition-HUTT4EX6-CFX7QbbK.js → kanban-definition-HUTT4EX6-DLK5X8Ol.js} +1 -1
  98. package/dist/assets/maplibre-gl-R0DO2NBr.js +748 -0
  99. package/dist/assets/{marketplaceApi-BLyDDfGk.js → marketplaceApi-zYQofLEk.js} +1 -1
  100. package/dist/assets/mermaid-GHXKKRXX-B7uCX_yo.js +1 -0
  101. package/dist/assets/{mermaid-parser.core-qFqgm_H6.js → mermaid-parser.core-DV_Ys_OF.js} +2 -2
  102. package/dist/assets/{mermaid.core-T8rJXbMH.js → mermaid.core-D3axazyv.js} +2 -2
  103. package/dist/assets/metadata-admin-DJAg5WLs.js +22 -0
  104. package/dist/assets/{mindmap-definition-LN4V7U3C-BmcygCh7.js → mindmap-definition-LN4V7U3C-DwbonLR_.js} +1 -1
  105. package/dist/assets/packet-7NZHBO7P-DSHvkxBR.js +1 -0
  106. package/dist/assets/{pegDiagram-2B236MQR-D3IbyQE9.js → pegDiagram-2B236MQR-B4IMkAIV.js} +1 -1
  107. package/dist/assets/pie-RZYD4A2V-DjNUdL88.js +1 -0
  108. package/dist/assets/{pieDiagram-ENE6RG2P-BZteOl-k.js → pieDiagram-ENE6RG2P-D8jBhNXT.js} +1 -1
  109. package/dist/assets/plugin-calendar-BKbWgkod.js +1 -0
  110. package/dist/assets/plugin-charts-BZo5ApEF.js +7 -0
  111. package/dist/assets/plugin-chatbot-D2Uv-hn9.js +120 -0
  112. package/dist/assets/plugin-dashboard-CRFZp7gC.js +6 -0
  113. package/dist/assets/plugin-form-FeZEoC2R.js +1 -0
  114. package/dist/assets/plugin-gantt-D9YRdBGD.js +93 -0
  115. package/dist/assets/plugin-grid-eiIl2HN_.js +8 -0
  116. package/dist/assets/plugin-kanban-3rFMGC21.js +1 -0
  117. package/dist/assets/plugin-map-BHQrQ_Wu.js +1 -0
  118. package/dist/assets/{plugin-markdown-CWbusz5W.js → plugin-markdown-DesFSRDB.js} +1 -1
  119. package/dist/assets/{plugin-report-Cy6FwNfk.js → plugin-report-BKD6SOp5.js} +4 -4
  120. package/dist/assets/plugin-timeline-BrkABjqu.js +1 -0
  121. package/dist/assets/{plugin-tree-CtakCCIf.js → plugin-tree-CKck3lEJ.js} +1 -1
  122. package/dist/assets/plugin-view-BJ9uLrnO.js +1 -0
  123. package/dist/assets/plugins-views-CibWNUsP.js +4 -0
  124. package/dist/assets/{quadrantDiagram-ABIIQ3AL-DPVvulM5.js → quadrantDiagram-ABIIQ3AL-Do3adYzz.js} +1 -1
  125. package/dist/assets/radar-I7S5WNFK-qO0bWLwF.js +1 -0
  126. package/dist/assets/railroad-3IZDKUUU-CAj9esX-.js +1 -0
  127. package/dist/assets/railroad-abnf-AHOZXSZD-Ci_Yg729.js +1 -0
  128. package/dist/assets/railroad-ebnf-EBAXGLYW-Tz7H2Jrw.js +1 -0
  129. package/dist/assets/railroad-peg-LSFZ7HO6-BJIalSaK.js +1 -0
  130. package/dist/assets/{railroadDiagram-RFXS5EU6-CgLSy8wn.js → railroadDiagram-RFXS5EU6-DDA7XtKq.js} +1 -1
  131. package/dist/assets/{requirementDiagram-TGXJPOKE-DYX2pMfn.js → requirementDiagram-TGXJPOKE-CClkXauU.js} +1 -1
  132. package/dist/assets/{sankeyDiagram-HTMAVEWB-amvhkMhz.js → sankeyDiagram-HTMAVEWB-DlUFch6E.js} +1 -1
  133. package/dist/assets/{sequenceDiagram-DBY2YBRQ-CPxWMCbb.js → sequenceDiagram-DBY2YBRQ-BEDTwji4.js} +1 -1
  134. package/dist/assets/{skeletons-BK6x7CYd.js → skeletons-CzC0fiXD.js} +1 -1
  135. package/dist/assets/src-6xqJEeiC.js +15 -0
  136. package/dist/assets/{src-BPEDMjfw.js → src-BeTFx9-N.js} +1 -1
  137. package/dist/assets/{src-BvIm_4jD.js → src-CSRoqdRD.js} +1 -1
  138. package/dist/assets/{src-6rOMKMLU.js → src-D0ZYDfff.js} +1 -1
  139. package/dist/assets/{stateDiagram-2N3HPSRC-DkFPpTq2.js → stateDiagram-2N3HPSRC-BN6M4MGy.js} +1 -1
  140. package/dist/assets/stateDiagram-v2-6OUMAXLB-DCaXJLPh.js +1 -0
  141. package/dist/assets/{swimlanes-5IMT3BWC-DMPnpahc.js → swimlanes-5IMT3BWC-Bycq06w3.js} +1 -1
  142. package/dist/assets/swimlanesDiagram-G3AALYLV-DWFAvAh7.js +8 -0
  143. package/dist/assets/{timeline-definition-FHXFAJF6-DMhg5ZmV.js → timeline-definition-FHXFAJF6-B6Oiv_gP.js} +1 -1
  144. package/dist/assets/treeView-QDETBFTQ-Cc2FYETg.js +1 -0
  145. package/dist/assets/treemap-6X3UGDF4-a4EjGpO3.js +1 -0
  146. package/dist/assets/{types-X8W-qTHJ.js → types-UYoEctl-.js} +1 -1
  147. package/dist/assets/ui-components-rkvkkTxO.js +42 -0
  148. package/dist/assets/{ui-layout-BdFgfR9C.js → ui-layout-CAjjF5_S.js} +1 -1
  149. package/dist/assets/{useMetadata-DAEfn7ks.js → useMetadata-Eb5o6ihl.js} +1 -1
  150. package/dist/assets/useOpenRecordList-DIo7M1au.js +1 -0
  151. package/dist/assets/{usePackageL10n-CasuagU5.js → usePackageL10n-CiFMHfKe.js} +1 -1
  152. package/dist/assets/{useReconcileOnError-CtvIPgmD.js → useReconcileOnError-4is_Tic6.js} +1 -1
  153. package/dist/assets/{useRecordApprovals-BHkgfYJW.js → useRecordApprovals-obyIj2_8.js} +1 -1
  154. package/dist/assets/vendor-charts-D_CNNxD5.js +67 -0
  155. package/dist/assets/vendor-dndkit-CzBh0_98.js +5 -0
  156. package/dist/assets/vendor-i18n-B6GOGCem.js +1 -0
  157. package/dist/assets/{vendor-icons-core-CPQTXONm.js → vendor-icons-core-DvLgTVYc.js} +1 -1
  158. package/dist/assets/{vendor-markdown-Cbritblm.js → vendor-markdown-BJvgKhXw.js} +18 -18
  159. package/dist/assets/vendor-objectstack-Bw0HRuFa.js +95 -0
  160. package/dist/assets/vendor-radix-DCTEpigg.js +46 -0
  161. package/dist/assets/vendor-react-BGDDiZfJ.js +13 -0
  162. package/dist/assets/vendor-sentry-CHRc7_3y.js +501 -0
  163. package/dist/assets/{vendor-ui-utils-C1OpMExs.js → vendor-ui-utils-BzQBRdq3.js} +1 -1
  164. package/dist/assets/{vennDiagram-L72KCM5P-BCn9MNWT.js → vennDiagram-L72KCM5P-DqRcgOxS.js} +1 -1
  165. package/dist/assets/wardley-OPB4EBWU-CuNyH0xZ.js +1 -0
  166. package/dist/assets/{wardleyDiagram-EHGQE667-ShqmBgOZ.js → wardleyDiagram-EHGQE667-BDyIMWfB.js} +1 -1
  167. package/dist/assets/{xychartDiagram-FW5EYKEG-D1hShMP_.js → xychartDiagram-FW5EYKEG-BRNQk20I.js} +1 -1
  168. package/dist/index.html +6 -6
  169. package/package.json +1 -1
  170. package/dist/assets/ApiConsolePage-CmiLmtuU.js +0 -1
  171. package/dist/assets/AppDocsIndex-CG7e4V2y.js +0 -1
  172. package/dist/assets/AppManagementPage-C7T-9Exg.js +0 -1
  173. package/dist/assets/ApprovalsInboxPage-D9PFFxKD.js +0 -1
  174. package/dist/assets/ConsoleFloatingChatbot-CmLazUxX.js +0 -1
  175. package/dist/assets/CreateViewDialog-6JmiAMxS.js +0 -1
  176. package/dist/assets/DashboardView-Al7ce4gm.js +0 -1
  177. package/dist/assets/DashboardWidgetInspector-BmIMgSGO.js +0 -1
  178. package/dist/assets/DeveloperHubPage-D8eYekI9.js +0 -1
  179. package/dist/assets/FlowRunsPage-Hs5i7s3C.js +0 -1
  180. package/dist/assets/InterfaceListPage-JNxR3qlQ.js +0 -1
  181. package/dist/assets/MarketplaceAccessDenied-Cur1UQ0U.js +0 -1
  182. package/dist/assets/MarketplaceInstalledPage-D9ow2tlx.js +0 -1
  183. package/dist/assets/MarketplacePackagePage-0AKyKbMD.js +0 -4
  184. package/dist/assets/MarketplacePage-DUzZZa8D.js +0 -1
  185. package/dist/assets/MetadataProvider-MNkZn-bR.js +0 -1
  186. package/dist/assets/ObjectDataPage-CUJksP8e.js +0 -1
  187. package/dist/assets/PageView-AS6xg5z-.js +0 -1
  188. package/dist/assets/ProfilePage-iJeMD7FK.js +0 -1
  189. package/dist/assets/PublicFormsPage-C-wbtEXG.js +0 -1
  190. package/dist/assets/RecordDetailView-Ba0xool8.js +0 -9
  191. package/dist/assets/ReportDefaultInspector-OSqdhKEL.js +0 -11
  192. package/dist/assets/ReportView-Df7cdlQo.js +0 -2
  193. package/dist/assets/SettingsView-CSBwd4YP.js +0 -1
  194. package/dist/assets/SystemHubPage-n41ly_cC.js +0 -1
  195. package/dist/assets/architecture-TIHT7OUA-D3WxD8aQ.js +0 -1
  196. package/dist/assets/channel-MM6d7ooS.js +0 -1
  197. package/dist/assets/chunk-VAUOI2AC-Bgyec1On.js +0 -1
  198. package/dist/assets/chunk-WYO6CB5R-BBbafnWJ.js +0 -127
  199. package/dist/assets/chunk-XXDRQBXY-V26l8fww.js +0 -1
  200. package/dist/assets/classDiagram-OUVF2IWQ-BOtUpfWB.js +0 -1
  201. package/dist/assets/classDiagram-v2-EOCWNBFH-BOtUpfWB.js +0 -1
  202. package/dist/assets/cynefin-VYW2F7L2-v0nc1IZv.js +0 -1
  203. package/dist/assets/eventmodeling-45OFAUF4-CHsG6T7D.js +0 -1
  204. package/dist/assets/flowDiagram-23GEKE2U-BZtO2Jjx.js +0 -1
  205. package/dist/assets/framework-B9PMswdm.js +0 -36
  206. package/dist/assets/getIcon-DkcFniPV.js +0 -1
  207. package/dist/assets/gitGraph-TEB2WS4Q-DEB3Nljf.js +0 -1
  208. package/dist/assets/index-Oki50z-M.js +0 -2
  209. package/dist/assets/index-rbBh03NP.css +0 -2
  210. package/dist/assets/info-DKCQHKI2-BMNzABlv.js +0 -1
  211. package/dist/assets/infrastructure-BnbfcrX8.js +0 -3
  212. package/dist/assets/maplibre-gl-DGbvC0OV.js +0 -748
  213. package/dist/assets/mermaid-GHXKKRXX-Df_DEhBm.js +0 -1
  214. package/dist/assets/metadata-admin-DiOg8Tx8.js +0 -22
  215. package/dist/assets/packet-7NZHBO7P-CVEX3X_K.js +0 -1
  216. package/dist/assets/pie-RZYD4A2V-VzBvughO.js +0 -1
  217. package/dist/assets/plugin-calendar-CVeG5Hhb.js +0 -1
  218. package/dist/assets/plugin-charts-BTfOaZVx.js +0 -7
  219. package/dist/assets/plugin-chatbot-COpsZSy4.js +0 -120
  220. package/dist/assets/plugin-dashboard-Bi5WrqPG.js +0 -6
  221. package/dist/assets/plugin-form-CzotVFc-.js +0 -1
  222. package/dist/assets/plugin-gantt-BUcqVYxX.js +0 -93
  223. package/dist/assets/plugin-grid-BXfwTczT.js +0 -8
  224. package/dist/assets/plugin-kanban-Dw_QTU-e.js +0 -1
  225. package/dist/assets/plugin-map-D89OX2_H.js +0 -1
  226. package/dist/assets/plugin-timeline-BAImk_4t.js +0 -1
  227. package/dist/assets/plugin-view-DZC_ZJtv.js +0 -1
  228. package/dist/assets/plugins-views-CxFTNQJ7.js +0 -4
  229. package/dist/assets/radar-I7S5WNFK-BvMfKOT_.js +0 -1
  230. package/dist/assets/railroad-3IZDKUUU-DfKQD3PJ.js +0 -1
  231. package/dist/assets/railroad-abnf-AHOZXSZD-DVyrJPzV.js +0 -1
  232. package/dist/assets/railroad-ebnf-EBAXGLYW-Cri8VQ5d.js +0 -1
  233. package/dist/assets/railroad-peg-LSFZ7HO6-Bmvxxxt6.js +0 -1
  234. package/dist/assets/src-CCztNT-4.js +0 -15
  235. package/dist/assets/stateDiagram-v2-6OUMAXLB-C_tQckF_.js +0 -1
  236. package/dist/assets/swimlanesDiagram-G3AALYLV-BLVdl7Q4.js +0 -8
  237. package/dist/assets/treeView-QDETBFTQ-Cz0fwXom.js +0 -1
  238. package/dist/assets/treemap-6X3UGDF4-BlqJD81v.js +0 -1
  239. package/dist/assets/ui-components-DsYvPIox.js +0 -42
  240. package/dist/assets/useOpenRecordList-DL3H_OJi.js +0 -1
  241. package/dist/assets/vendor-charts-DVOdzzh2.js +0 -67
  242. package/dist/assets/vendor-dndkit-0M_nRjzm.js +0 -5
  243. package/dist/assets/vendor-i18n-sU23bKX1.js +0 -1
  244. package/dist/assets/vendor-objectstack-sPlD8LgO.js +0 -95
  245. package/dist/assets/vendor-radix-DniuRzL-.js +0 -46
  246. package/dist/assets/vendor-react-slxo-5GC.js +0 -11
  247. package/dist/assets/vendor-sentry-BnfuR4xu.js +0 -501
  248. package/dist/assets/wardley-OPB4EBWU-DdYQ8RHK.js +0 -1
@@ -0,0 +1,22 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css"])))=>i.map(i=>d[i]);
2
+ import{o as e,r as t}from"./rolldown-runtime-DAXXjFlN.js";import{a as n,d as r,f as i,g as a,h as o,m as s,r as c,s as l,y as u}from"./vendor-react-BGDDiZfJ.js";import{m as d}from"./infrastructure-Bcx6-8du.js";import{G as f,L as p,R as m,Ut as h,Vt as g,Y as _,dt as v,ft as y,j as b,ut as x}from"./framework-B3O15Lsq.js";import{S,U as C,_ as w,h as T,m as E,y as D}from"./vendor-objectstack-Bw0HRuFa.js";import{$a as O,$s as k,$t as A,Aa as j,Ai as ee,Ao as te,Ar as ne,As as M,Ba as re,Bi as ie,Bn as ae,Br as oe,Bs as N,Bt as P,Cc as se,Ci as ce,Cr as le,Da as ue,Dc as de,Di as fe,Do as pe,Dr as me,E as he,Ea as ge,Ec as _e,Ei as ve,Eo as ye,Er as be,Fa as xe,Fn as Se,Fo as Ce,Fr as we,G as F,Ga as Te,Gn as Ee,Gt as De,Hr as Oe,Hs as ke,Ht as Ae,Ic as je,Ii as Me,Ir as Ne,Is as Pe,J as Fe,Ji as Ie,Jn as Le,Jo as Re,Jt as ze,Ka as Be,Kn as Ve,Ko as He,Kt as Ue,Ln as We,Lo as Ge,Ma as Ke,No as qe,Oa as Je,Oc as Ye,Oi as Xe,Oo as Ze,Or as Qe,Os as $e,Pa as et,Pi as tt,Po as nt,Ps as rt,Q as it,Qa as at,Qn as ot,Qo as st,Qt as ct,Ra as lt,Ri as ut,Rn as dt,Rs as ft,Rt as pt,Si as mt,So as ht,Ss as gt,Ta as _t,Ti as vt,To as yt,Tr as bt,U as xt,Un as St,Uo as Ct,Ur as wt,Us as Tt,Ut as Et,Vi as Dt,Vn as Ot,Vo as kt,Vt as At,W as jt,Wa as Mt,Wi as Nt,Wn as Pt,Wo as Ft,Wr as I,Wt as It,Xa as Lt,Xi as Rt,Xr as zt,Xt as Bt,Ya as Vt,Yi as L,Yo as Ht,Yt as Ut,Za as Wt,Zi as Gt,Zo as Kt,Zr as qt,Zs as Jt,_a as Yt,_c as Xt,_i as Zt,_t as Qt,ac as $t,an as en,ao as tn,ar as R,ba as nn,bi as rn,bo as an,bs as on,ca as sn,cc as cn,ci as ln,co as un,cs as dn,ct as fn,dn as z,do as pn,ds as mn,dt as hn,ea as gn,en as _n,fo as vn,fs as yn,ft as bn,ga as xn,gc as Sn,go as Cn,gs as wn,gt as Tn,hi as En,ht as Dn,ia as On,ic as kn,ii as An,in as jn,io as Mn,ja as Nn,ji as Pn,jo as Fn,js as In,kc as B,ki as Ln,kr as Rn,ks as zn,la as Bn,ls as Vn,lt as Hn,ma as Un,mt as Wn,na as Gn,nc as Kn,ni as qn,no as Jn,ns as Yn,oa as Xn,oc as Zn,on as Qn,os as $n,pa as er,pi as tr,po as nr,pt as rr,qi as ir,qn as ar,qo as or,qr as sr,qt as cr,ri as lr,rs as ur,sa as dr,sc as fr,si as pr,sn as V,so as mr,st as hr,tc as gr,ts as _r,ua as vr,uc as yr,ui as br,us as xr,ut as Sr,vc as Cr,vi as wr,vo as Tr,vt as Er,wa as Dr,wc as Or,wo as kr,wr as Ar,ws as jr,xa as Mr,xc as Nr,xi as Pr,xo as Fr,xr as H,xs as Ir,yi as Lr,yo as Rr,za as U,zn as zr,zo as Br,zr as Vr}from"./ui-components-rkvkkTxO.js";import{r as Hr}from"./vendor-ui-utils-BzQBRdq3.js";import"./AdapterProvider-DYYVhErE.js";import"./MetadataProvider-BpQl3Bw2.js";import{c as Ur,r as Wr}from"./assistantBus-BFk4fCbM.js";import{o as Gr}from"./useRecordApprovals-obyIj2_8.js";import{f as Kr}from"./plugin-chatbot-D2Uv-hn9.js";import{a as qr,c as Jr,l as Yr,o as Xr,s as Zr}from"./RecordDetailView-CzR6BAUv.js";import{n as Qr}from"./ui-layout-CAjjF5_S.js";import{i as $r,n as ei,r as ti,t as ni}from"./useMetadata-Eb5o6ihl.js";import{A as W,B as ri,C as ii,D as ai,E as oi,F as si,G as ci,H as li,I as ui,J as di,K as fi,L as pi,M as G,N as mi,O as hi,P as gi,R as _i,S as vi,T as K,U as yi,V as bi,W as xi,X as Si,Y as Ci,_ as wi,a as Ti,b as q,c as Ei,d as Di,f as Oi,g as ki,h as Ai,j as ji,k as Mi,l as Ni,m as Pi,n as Fi,o as Ii,p as Li,q as Ri,s as zi,u as Bi,v as Vi,w as Hi,x as Ui,y as J,z as Wi}from"./ReportDefaultInspector-BA-D9th_.js";import{t as Gi}from"./getIcon-B5xaQx5N.js";import{t as Ki}from"./InterfaceListPage-CaG6oJ3-.js";import{n as qi}from"./plugins-views-CibWNUsP.js";import{a as Ji,c as Yi,i as Xi,l as Zi,n as Qi,o as $i,r as ea,s as ta,t as na}from"./DashboardWidgetInspector-CUJFDeER.js";import{r as ra}from"./dist-YwlXXOlT.js";var Y=c(),X=e(u(),1);function ia(){let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},t=e.VITE_AI_BASE_URL;return t?t.replace(/\/$/,``):`${(e.VITE_SERVER_URL??``).replace(/\/$/,``)}/api/v1/ai`}function aa(){let{agents:e,isLoading:t}=Kr({apiBase:ia()}),n=(0,X.useRef)(!1);t&&(n.current=!0);let r=e.length>0;return{enabled:r,isLoading:r?!1:t||!n.current}}function oa(e,t){if(typeof e==`string`)return e||`col ${t+1}`;if(e&&typeof e==`object`){let n=e;return String(n.label??n.header??n.field??n.accessorKey??`col ${t+1}`)}return`col ${t+1}`}function sa(e){if(typeof e==`string`)return e||void 0;if(e&&typeof e==`object`){let t=e,n=t.field??t.accessorKey;return typeof n==`string`&&n?n:void 0}}function ca(e){let t=new Set;for(let n of e){let e=sa(n);e&&t.add(e)}return t}function la(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function ua(e,t){return e===t?null:e>t?e-1:e}function da(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function fa({variantKey:e,schema:t,columns:n,allStrings:r,objectName:i,objectFieldsOverride:a,selectedIndex:o,readOnly:s,onPatch:c,onSelectionChange:l}){let u=!s,{fields:d,loading:f,error:p}=ki(i||void 0,a),m=X.useMemo(()=>{let e=new Map;for(let t of d)e.set(t.name,t.type);return e},[d]),[h,g]=X.useState(null),[_,v]=X.useState(null),y=X.useCallback(n=>{c({[e]:{...t,columns:n}})},[c,e,t]),b=X.useCallback(t=>{let i=mi(n,la(r,t.name,t.label));y(i),l?.({kind:`column`,id:`${e}.columns[${i.length-1}]`,label:t.label})},[r,n,y,e,l]),x=X.useCallback(t=>{let r=si(n,t,null);if(y(r),o!=null){let n=ua(o,t);n==null?l?.(null):l?.({kind:`column`,id:`${e}.columns[${n}]`,label:oa(r[n],n)})}},[n,y,o,e,l]),S=X.useCallback((t,r)=>{if(t===r)return;let i=gi(n,t,r);if(y(i),o!=null){let n=da(o,t,r);l?.({kind:`column`,id:`${e}.columns[${n}]`,label:oa(i[n],n)})}},[n,y,o,e,l]),C=X.useCallback(t=>{l?.({kind:`column`,id:`${e}.columns[${t}]`,label:oa(n[t],t)})},[n,e,l]),w=ca(n);return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:`Columns`}),(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px]`,children:n.length})]}),n.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:`No columns yet. Add a field below.`}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,Y.jsx)(zi,{index:t,label:oa(e,t),fieldName:sa(e),fieldType:m.get(sa(e)??``)??`text`,selected:o===t,canEdit:u,dragging:h!==null,dropBefore:_===t&&h!==null&&h!==t,onSelect:()=>C(t),onRemove:()=>x(t),onDragStart:()=>g(t),onDragEnd:()=>{g(null),v(null)},onDragOverRow:()=>v(t),onDropRow:()=>{h!=null&&h!==t&&S(h,t),g(null),v(null)}},t))}),u&&(0,Y.jsx)(Ii,{fields:d,usedNames:w,loading:f,error:p,onAdd:b})]})}var pa={io:`input`,unrepresentable:`any`},ma=new Set([`columns`,`data`,`name`]),ha,ga=!1;function _a(){if(ha||ga)return ha;try{ha=C(w,pa)}catch(e){ga=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return ha}function va(){return _a()?.properties?.list}function ya(){return _a()?.properties?.form}var ba,xa=!1;function Sa(){if(ba||xa)return ba;try{ba=C(E,pa)}catch(e){xa=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return ba}var Ca;function wa(){if(Ca)return Ca;if(!(!S||typeof S!=`object`)){try{let e=JSON.parse(JSON.stringify(S));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!ma.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Ca=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return Ca}}var Ta=new Set([`form`,`detail`]);function Ea(e){return Ta.has(e)}function Da(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Oa(e,t){return typeof e==`string`&&Ta.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&Ta.has(t)?`form`:`list`}function ka(e){let t=e.config;return Da(t)?[{storeKey:`config`,familyKey:Oa(e.viewKind,t.type),schema:t}]:[]}function Aa(e){return ka(e)[0]}function ja(e,t){return Aa(e)}function Ma({label:e,value:t,onCommit:n,placeholder:r,disabled:i}){let{options:a,loading:o}=Yi();return(0,Y.jsx)(Zi,{label:e,value:t,onCommit:n,options:a.map(e=>({value:e.name,label:e.label})),loading:o,placeholder:r,searchPlaceholder:`Search objects…`,disabled:i,mono:!0})}var Na=new Set([`type`,`object`,`label`,`columns`]),Pa={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`};function Fa(e,t){let n=`engine.inspector.view.type.${e}`,r=J(n,t);return r===n?Pa[e]??e:r}var Ia=[`columns`,`data`,`name`];function La(e,t){let n=e.data;return n&&typeof n==`object`&&typeof n.object==`string`&&n.object?{value:n.object,path:`data.object`}:typeof e.object==`string`&&e.object?{value:e.object,path:`object`}:typeof t.object==`string`&&t.object?{value:t.object,path:`top`}:{value:``,path:`top`}}function Ra(e,t){return X.useMemo(()=>{let n=va()?.properties?.type?.enum,r=(Array.isArray(n)&&n.length?n.filter(e=>typeof e==`string`):[`grid`,`kanban`,`calendar`,`gallery`,`gantt`,`timeline`]).map(e=>({value:e,label:Fa(e,t)}));return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:Fa(e,t)}),r},[e,t])}function za({draft:e,variantKey:t,familyKey:n,isHome:r,onPatch:i,readOnly:a,onClearSelection:o,onSelectionChange:s,objectFieldsOverride:c,locale:l,serverSchema:u}){let d=e[t]??{},f=Ea(n??t),p=typeof d.type==`string`?d.type:`grid`,m=Ra(p,l),h=La(d,e),g=typeof e.label==`string`&&e.label||(typeof d.label==`string`?d.label:``)||``,_=Array.isArray(d.columns)?d.columns:[],v=_.length>0&&_.every(e=>typeof e==`string`),{fields:y}=ki(h.value||void 0,c),b=X.useMemo(()=>({objectFields:y.map(e=>({name:e.name,label:e.label,type:e.type}))}),[y]),x=(()=>{let e=u?.properties;return f?e?.form:e?.list})(),{schema:S,form:C}=X.useMemo(()=>Ti({bundledSchema:f?ya():va(),bundledForm:f?void 0:wa(),serverSchema:x,excludeFields:Na,sectionTitle:J(`engine.inspector.moreFields`,l)}),[f,x,l]),w=e=>{i({[t]:{...d,...e}})};return(0,Y.jsxs)(ji,{kindLabel:J(`engine.inspector.view.kind`,l),title:String(g||e.name||t),onClose:()=>o?.(),closeLabel:J(`engine.inspector.view.close`,l),hideClose:r,children:[(0,Y.jsx)(G,{label:J(`engine.inspector.view.label`,l),value:g,onCommit:e=>{i({label:e,[t]:{...d,label:e}})},placeholder:J(`engine.inspector.view.labelPlaceholder`,l),disabled:a}),(0,Y.jsx)(W,{label:J(`engine.inspector.view.type`,l),value:p,options:m,onCommit:e=>w({type:e}),disabled:a}),(0,Y.jsx)(Ma,{label:J(`engine.inspector.view.object`,l),value:h.value,onCommit:e=>{let n={object:e};d.data&&typeof d.data==`object`?n[t]={...d,data:{...d.data,object:e}}:h.path===`object`&&(n[t]={...d,object:e}),i(n)},placeholder:J(`engine.inspector.view.objectPlaceholder`,l),disabled:a}),!f&&(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(fa,{variantKey:t,schema:d,columns:_,allStrings:v,objectName:h.value||void 0,objectFieldsOverride:c,selectedIndex:null,readOnly:a,onPatch:i,onSelectionChange:s})}),(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:S?(0,Y.jsx)(Li,{schema:S,form:C,value:d,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:b,onChange:e=>{let n={...e};for(let e of Ia)e in d?n[e]=d[e]:delete n[e];i({[t]:n})}}):(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:J(`engine.inspector.view.noSchema`,l)})})]})}function Ba({appSlug:e}={}){let t=i(),n=ti(),{entries:r}=$r(n),[a,o]=X.useState(!1),[s,c]=X.useState(``),[l,u]=X.useState(null),[d,f]=X.useState(!1),[p,m]=X.useState(0),h=X.useMemo(()=>Vi(),[]);X.useEffect(()=>{function e(e){(e.metaKey||e.ctrlKey)&&e.shiftKey&&e.key.toLowerCase()===`m`&&(e.preventDefault(),o(e=>!e))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),X.useEffect(()=>{if(!a||l!=null||d||r.length===0)return;f(!0);let e=!1;return(async()=>{try{let t=[];await Promise.all(r.map(async e=>{try{let r=await n.list(e.type);for(let n of r??[]){let r=(n&&typeof n==`object`&&`item`in n?n.item:n)??{},i=r?.name;i&&t.push({kind:`item`,type:e.type,name:String(i),label:r?.label,description:r?.description,lock:typeof r?._lock==`string`?r._lock:void 0,lockReason:typeof r?._lockReason==`string`?r._lockReason:void 0})}}catch{}})),e||u(t)}finally{e||f(!1)}})(),()=>{e=!0}},[a,l,d,r,n]);let g=X.useMemo(()=>{let e=s.trim().toLowerCase();if(!e)return r.slice(0,20).map(e=>({kind:`type`,entry:e}));let t=r.filter(t=>t.type.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||vi(t.type,h,t.label).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)).slice(0,8).map(e=>({kind:`type`,entry:e})),n=(l??[]).filter(t=>t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e)||t.type.toLowerCase().includes(e)).slice(0,40);return[...t,...n]},[s,r,l]);X.useEffect(()=>{m(0)},[s,a]);function _(n){o(!1);let r=e?`/apps/${e}`:`..`;n.kind===`type`?t(`${r}/metadata/${encodeURIComponent(n.entry.type)}`):t(`${r}/metadata/${encodeURIComponent(n.type)}/${encodeURIComponent(n.name)}`)}function v(e){e.key===`ArrowDown`?(e.preventDefault(),m(e=>Math.min(e+1,g.length-1))):e.key===`ArrowUp`?(e.preventDefault(),m(e=>Math.max(e-1,0))):e.key===`Enter`&&g[p]&&(e.preventDefault(),_(g[p]))}return(0,Y.jsx)(St,{open:a,onOpenChange:o,children:(0,Y.jsxs)(Pt,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,Y.jsx)(ar,{className:`sr-only`,children:(0,Y.jsx)(Le,{children:J(`engine.quickfind.title`,h)})}),(0,Y.jsxs)(`div`,{className:`border-b px-3 py-2 flex items-center gap-2`,children:[(0,Y.jsx)(Xe,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(V,{autoFocus:!0,placeholder:J(`engine.quickfind.placeholder`,h),value:s,onChange:e=>c(e.target.value),onKeyDown:v,className:`border-0 shadow-none focus-visible:ring-0 px-0`}),(0,Y.jsx)(xt,{children:`esc`})]}),(0,Y.jsxs)(`div`,{className:`max-h-[440px] overflow-auto`,children:[d&&(0,Y.jsxs)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}),J(`engine.quickfind.indexing`,h),` `,r.length,`…`]}),!d&&g.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-6 text-xs text-muted-foreground text-center`,children:J(`engine.quickfind.noMatches`,h)}),(0,Y.jsx)(`ul`,{role:`listbox`,children:g.map((e,t)=>(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>_(e),onMouseEnter:()=>m(t),className:`w-full text-left px-3 py-2 flex items-center gap-3 hover:bg-accent `+(t===p?`bg-accent`:``),children:[(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px] font-mono shrink-0`,children:e.kind===`type`?`type`:e.type}),(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.kind===`type`?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium truncate`,children:vi(e.entry.type,h,e.entry.label)}),e.entry.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.entry.description})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`text-sm font-mono truncate flex items-center gap-1.5`,children:[e.lock&&e.lock!==`none`&&(0,Y.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400 shrink-0`,title:e.lockReason??`_lock=${e.lock}`,"aria-label":`locked`,children:(0,Y.jsx)(lt,{className:`h-3 w-3`})}),e.name,e.label&&(0,Y.jsx)(`span`,{className:`text-muted-foreground font-sans ml-2`,children:e.label})]}),e.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.description})]})})]})},e.kind===`type`?`t:${e.entry.type}`:`i:${e.type}:${e.name}`))})]}),(0,Y.jsxs)(`div`,{className:`border-t px-3 py-1.5 flex items-center gap-3 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(xt,{children:`↑`}),` `,(0,Y.jsx)(xt,{children:`↓`}),` navigate`]}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(xt,{children:`↵`}),` open`]}),(0,Y.jsxs)(`span`,{className:`ml-auto`,children:[(0,Y.jsx)(xt,{children:`⌘`}),(0,Y.jsx)(xt,{children:`⇧`}),(0,Y.jsx)(xt,{children:`M`}),` toggle`]})]})]})})}var Va=new Set([`system`,`cloud`]);function Ha(e){let t=(e??[]).map(e=>{let t=e&&typeof e==`object`&&`item`in e?e.item:e,n=t?.manifest??t??{};return{id:n.id,scope:n.scope,name:n.name||n.id}}).filter(e=>e.id&&!Va.has(e.scope));return t.sort((e,t)=>e.name.localeCompare(t.name)),t.map(e=>({id:e.id,name:e.name}))}var Ua={data:Yn,ui:Wt,automation:ne,ai:En,system:vt,platform:vt,identity:mt,security:mt},Wa=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Ga=new Set([`field`,`package`]);function Ka(){let e=ti(),{loading:t,error:r,entries:i}=$r(e),a=X.useMemo(()=>Vi(),[]),[s,c]=X.useState(``),[l,u]=X.useState(`all`),[d,f]=X.useState(!1),[p,m]=o(),[h,g]=X.useState(null);X.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;g(Ha(n))}catch{t||g([])}})(),()=>{t=!0}},[e]);let _=p.get(`package`),v=X.useMemo(()=>h?_&&h.some(e=>e.id===_)?_:h[0]?.id??null:null,[h,_]);X.useEffect(()=>{if(!h||h.length===0||_&&h.some(e=>e.id===_))return;let e=new URLSearchParams(p);e.set(`package`,h[0].id),m(e,{replace:!0})},[h,_]);let{byType:y,warnByType:b,summary:x,countsByType:S,lockedByType:C,packagesByType:w,loading:T}=ei(e,`warning`,v??void 0),E=X.useMemo(()=>i.filter(e=>Ga.has(e.type)||!v?!1:(w[e.type]??[]).includes(v)),[i,v,w]),D=X.useMemo(()=>{let e={all:E.length};for(let t of E){let n=t.domain??`other`;e[n]=(e[n]??0)+1}return e},[E]),O=E.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate).length,k=E.filter(e=>{if(d&&!(e.allowOrgOverride||e.allowRuntimeCreate)||l!==`all`&&(e.domain??`other`)!==l)return!1;if(s){let t=s.toLowerCase();if(!(e.type.toLowerCase().includes(t)||(e.label??``).toLowerCase().includes(t)||vi(e.type,a,e.label).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),A=X.useMemo(()=>{let e={};for(let t of k)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=Wa.indexOf(e),r=Wa.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[k]);return t||h===null||v&&T?(0,Y.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:J(`engine.directory.loading`,a)}):r?(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[J(`engine.directory.loadFailed`,a),`: `,r]}):(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold`,children:J(`engine.directory.title`,a)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:q(`engine.directory.description`,a,{count:`<strong class="text-foreground">${E.length}</strong>`,writable:O})}}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[240px] max-w-lg`,children:[(0,Y.jsx)(Xe,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(V,{className:`pl-8`,placeholder:J(`engine.directory.search`,a),value:s,onChange:e=>c(e.target.value)})]}),(0,Y.jsxs)(H,{variant:d?`default`:`outline`,size:`sm`,onClick:()=>f(e=>!e),children:[J(`engine.directory.writableOnly`,a),` (`,O,`)`]}),x.total>0&&(0,Y.jsx)(H,{asChild:!0,variant:`outline`,size:`sm`,className:`border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,Y.jsxs)(n,{to:`./_diagnostics`,children:[(0,Y.jsx)(I,{className:`h-3.5 w-3.5 mr-1`}),q(`engine.directory.diagnosticsLink`,a,{count:x.total})]})}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[J(`engine.directory.quickFind`,a),` `,(0,Y.jsx)(xt,{children:`⌘`}),(0,Y.jsx)(xt,{children:`⇧`}),(0,Y.jsx)(xt,{children:`M`})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,Y.jsx)(qa,{domain:`all`,label:J(`engine.directory.all`,a),active:l===`all`,count:D.all??0,onClick:()=>u(`all`)}),Wa.filter(e=>D[e]).map(e=>(0,Y.jsx)(qa,{domain:e,label:Ui(e,a),active:l===e,count:D[e]??0,onClick:()=>u(e)},e))]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[h.length===0&&(0,Y.jsxs)(jt,{children:[(0,Y.jsx)(Fe,{children:`No project packages installed`}),(0,Y.jsx)(F,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),h.length>0&&k.length===0&&(0,Y.jsxs)(jt,{children:[(0,Y.jsx)(Fe,{children:J(`engine.directory.noMatches`,a)}),(0,Y.jsx)(F,{children:J(`engine.directory.noMatchesHint`,a)})]}),A.map(([e,t])=>(0,Y.jsxs)(`section`,{className:`space-y-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5`,children:[(0,Y.jsx)(Ua[e]??fr,{className:`h-3.5 w-3.5`}),Ui(e,a),` (`,t.length,`)`]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t.map(e=>{let t=S[e.type]??0;return(0,Y.jsx)(Ja,{entry:e,locale:a,invalidCount:y[e.type]??0,warnCount:b[e.type]??0,lockedCount:C[e.type]??0,itemCount:t,packageFilter:v??void 0},e.type)})})]},e))]}),(0,Y.jsx)(Ba,{})]})}function qa({domain:e,label:t,active:n,count:r,onClick:i}){return(0,Y.jsxs)(`button`,{type:`button`,onClick:i,className:`px-2.5 py-1 rounded-full text-xs border transition-colors `+(n?`bg-primary text-primary-foreground border-primary`:`bg-background hover:bg-accent border-border text-muted-foreground`),children:[t??e,` `,(0,Y.jsxs)(`span`,{className:`opacity-70 ml-0.5`,children:[`(`,r,`)`]})]})}function Ja({entry:e,locale:t,invalidCount:r=0,warnCount:i=0,itemCount:a=0,lockedCount:o=0,packageFilter:s}){let c=vi(e.type,t,e.label);return(0,Y.jsxs)(n,{to:s?`./${encodeURIComponent(e.type)}?package=${encodeURIComponent(s)}`:`./${encodeURIComponent(e.type)}`,className:`block p-4 border rounded-lg hover:bg-accent transition-colors `+(r>0?`border-destructive/40 hover:border-destructive`:`hover:border-primary`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1.5`,children:[r>0&&(0,Y.jsx)(`span`,{title:q(`engine.directory.invalidTooltip`,t??`en`,{count:r}),"aria-label":q(`engine.directory.invalidTooltip`,t??`en`,{count:r}),children:(0,Y.jsx)(I,{className:`h-3.5 w-3.5 text-destructive shrink-0`})}),c]}),(0,Y.jsx)(`code`,{className:`text-xs text-muted-foreground font-mono`,children:e.type})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,Y.jsx)(R,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:q(`engine.directory.itemCountTooltip`,t??`en`,{count:a}),children:a}),r>0&&(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,title:q(`engine.directory.invalidTooltip`,t??`en`,{count:r}),children:r}),i>0&&(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06]`,title:q(`engine.directory.warnTooltip`,t??`en`,{count:i}),children:i}),o>0&&(0,Y.jsxs)(R,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06] inline-flex items-center gap-0.5 px-1.5`,title:`${o} locked item${o===1?``:`s`} — see ADR-0010`,"aria-label":`${o} locked items`,children:[(0,Y.jsx)(lt,{className:`h-2.5 w-2.5`}),o]}),e.allowOrgOverride?(0,Y.jsx)(R,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:J(`engine.badge.writable`,t)}):e.allowRuntimeCreate?(0,Y.jsx)(R,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:J(`engine.badge.createOnly`,t)}):(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:J(`engine.badge.readOnly`,t)})]})]}),e.description&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 line-clamp-2`,children:e.description})]})}var Ya=`/api/v1/packages`;async function Xa(e,t){let n=await fetch(e,{credentials:`include`,headers:{Accept:`application/json`,...t?.headers||{}},...t}),r=await n.text(),i=r?JSON.parse(r):null;if(!n.ok||i?.success===!1){let e=i?.error?.message||i?.error||i?.message||`Request failed (${n.status})`;throw Error(typeof e==`string`?e:`Request failed (${n.status})`)}return i?.data??i}function Za({scope:e}){let t=X.useMemo(()=>Vi(),[]);if(!e)return(0,Y.jsx)(R,{className:`bg-emerald-400/15 text-emerald-600 hover:bg-emerald-400/15 dark:text-emerald-300`,children:J(`engine.packages.scope.writable`,t)});let n=e===`project`?`default`:e===`system`?`secondary`:`outline`,r=e===`project`?`engine.packages.scope.project`:e===`system`?`engine.packages.scope.system`:e===`cloud`?`engine.packages.scope.cloud`:``;return(0,Y.jsx)(R,{variant:n,children:r?J(r,t):e})}function Qa({pkg:e}){let t=X.useMemo(()=>Vi(),[]),n=e.enabled!==!1&&e.status!==`disabled`;return(0,Y.jsx)(R,{variant:n?`default`:`outline`,children:J(n?`engine.packages.status.enabled`:`engine.packages.status.disabled`,t)})}var $a=/^[a-z0-9][a-z0-9._-]{1,254}$/i,eo=/^\d+\.\d+\.\d+$/;function to({open:e,onOpenChange:t,onCreated:n}){let r=X.useMemo(()=>Vi(),[]),[i,a]=X.useState(``),[o,s]=X.useState(``),[c,l]=X.useState(`0.1.0`),[u,d]=X.useState(!1),[f,p]=X.useState(null);X.useEffect(()=>{e&&(a(``),s(``),l(`0.1.0`),p(null),d(!1))},[e]);let m=$a.test(i),h=eo.test(c),g=m&&h&&!!o.trim()&&!u;async function _(){if(g){d(!0),p(null);try{await Xa(Ya,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:{id:i.trim(),name:o.trim(),version:c.trim(),type:`app`}})}),n(i.trim());try{window.dispatchEvent(new CustomEvent(`objectui:packages-changed`))}catch{}t(!1)}catch(e){p(e?.message??J(`engine.packages.create.failed`,r))}finally{d(!1)}}}return(0,Y.jsx)(St,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Pt,{children:[(0,Y.jsxs)(ar,{children:[(0,Y.jsx)(Le,{children:J(`engine.packages.create.title`,r)}),(0,Y.jsx)(Ee,{children:q(`engine.packages.create.description`,r,{example:`com.acme.crm`})})]}),(0,Y.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(z,{htmlFor:`pkg-id`,children:J(`engine.packages.create.id`,r)}),(0,Y.jsx)(V,{id:`pkg-id`,"data-testid":`package-id-input`,placeholder:`com.acme.crm`,value:i,onChange:e=>a(e.target.value),"aria-invalid":!!i&&!m}),!!i&&!m&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:J(`engine.packages.create.idInvalid`,r)})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(z,{htmlFor:`pkg-name`,children:J(`engine.packages.create.name`,r)}),(0,Y.jsx)(V,{id:`pkg-name`,"data-testid":`package-name-input`,placeholder:`Acme CRM`,value:o,onChange:e=>s(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(z,{htmlFor:`pkg-version`,children:J(`engine.packages.create.version`,r)}),(0,Y.jsx)(V,{id:`pkg-version`,placeholder:`0.1.0`,value:c,onChange:e=>l(e.target.value),"aria-invalid":!!c&&!h}),!!c&&!h&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:J(`engine.packages.create.versionInvalid`,r)})]}),f&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-sm text-destructive`,children:[(0,Y.jsx)(I,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Y.jsx)(`span`,{children:f})]})]}),(0,Y.jsxs)(Ve,{children:[(0,Y.jsx)(H,{variant:`outline`,onClick:()=>t(!1),disabled:u,children:J(`engine.cancel`,r)}),(0,Y.jsx)(H,{onClick:_,disabled:!g,children:J(u?`engine.packages.create.creating`:`engine.packages.create.submit`,r)})]})]})})}function no({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,Y.jsx)(`span`,{className:`text-sm font-medium text-right break-all`,children:t})]})}function ro({pkg:e,open:t,onOpenChange:n,onSaved:r}){let i=X.useMemo(()=>Vi(),[]),[a,o]=X.useState(``),[s,c]=X.useState(``),[l,u]=X.useState(``),[d,f]=X.useState(!1),[p,m]=X.useState(null);X.useEffect(()=>{t&&e&&(o(e.manifest.name??``),c(e.manifest.description??``),u(e.manifest.version??``),m(null),f(!1))},[t,e]);let h=!l.trim()||eo.test(l.trim()),g=!!a.trim()&&h&&!d;async function _(){if(!(!g||!e)){f(!0),m(null);try{let t=await Xa(`${Ya}/${encodeURIComponent(e.manifest.id)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:a.trim(),description:s.trim(),version:l.trim()})});try{window.dispatchEvent(new CustomEvent(`objectui:packages-changed`))}catch{}r(t),n(!1)}catch(e){m(e?.message??J(`engine.packages.edit.failed`,i))}finally{f(!1)}}}return(0,Y.jsx)(St,{open:t,onOpenChange:n,children:(0,Y.jsxs)(Pt,{children:[(0,Y.jsxs)(ar,{children:[(0,Y.jsx)(Le,{children:J(`engine.packages.edit.title`,i)}),(0,Y.jsx)(Ee,{className:`font-mono text-xs`,children:e?.manifest.id})]}),(0,Y.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(z,{htmlFor:`pkg-edit-name`,children:J(`engine.packages.create.name`,i)}),(0,Y.jsx)(V,{id:`pkg-edit-name`,"data-testid":`package-edit-name-input`,value:a,onChange:e=>o(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(z,{htmlFor:`pkg-edit-desc`,children:J(`engine.packages.detail.description`,i)}),(0,Y.jsx)(V,{id:`pkg-edit-desc`,"data-testid":`package-edit-desc-input`,value:s,onChange:e=>c(e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(z,{htmlFor:`pkg-edit-version`,children:J(`engine.packages.create.version`,i)}),(0,Y.jsx)(V,{id:`pkg-edit-version`,value:l,onChange:e=>u(e.target.value),"aria-invalid":!!l.trim()&&!h}),!!l.trim()&&!h&&(0,Y.jsx)(`p`,{className:`text-xs text-destructive`,children:J(`engine.packages.create.versionInvalid`,i)})]}),p&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/10 p-2 text-sm text-destructive`,children:[(0,Y.jsx)(I,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Y.jsx)(`span`,{children:p})]})]}),(0,Y.jsxs)(Ve,{children:[(0,Y.jsx)(H,{variant:`outline`,onClick:()=>n(!1),disabled:d,children:J(`engine.cancel`,i)}),(0,Y.jsx)(H,{onClick:_,disabled:!g,"data-testid":`package-edit-save`,children:J(d?`engine.packages.edit.saving`:`engine.packages.edit.save`,i)})]})]})})}function io({pkg:e,appBase:t,open:r,onOpenChange:i,onChanged:a}){let o=X.useMemo(()=>Vi(),[]),[s,c]=X.useState(null),[l,u]=X.useState(null),[d,f]=X.useState(null),[p,m]=X.useState(!1);if(X.useEffect(()=>{u(null),c(null)},[e?.manifest.id]),X.useEffect(()=>{let t=e?.manifest.id;if(!r||!t){f(null);return}let n=!1;return Xa(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(t)}`).then(e=>{n||f(e?.drafts??[])}).catch(()=>{n||f([])}),()=>{n=!0}},[r,e?.manifest.id]),!e)return null;let h=e.manifest.id,g=e.enabled!==!1&&e.status!==`disabled`,_=e.manifest.scope===`system`||e.manifest.scope===`cloud`;async function v(e,t,n){c(e),u(null);try{await t(),u({kind:`ok`,text:n}),a()}catch(e){u({kind:`err`,text:e?.message??J(`engine.packages.detail.actionFailed`,o)})}finally{c(null)}}return(0,Y.jsx)(P,{open:r,onOpenChange:i,children:(0,Y.jsxs)(At,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,Y.jsxs)(Et,{children:[(0,Y.jsxs)(It,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(xn,{className:`h-4 w-4`}),e.manifest.name||h]}),(0,Y.jsx)(Ae,{className:`font-mono text-xs`,children:h})]}),(0,Y.jsxs)(`div`,{className:`mt-4`,children:[(0,Y.jsx)(no,{label:J(`engine.packages.col.version`,o),children:e.manifest.version||`—`}),(0,Y.jsx)(no,{label:J(`engine.packages.detail.type`,o),children:e.manifest.type||`—`}),(0,Y.jsx)(no,{label:J(`engine.packages.col.scope`,o),children:(0,Y.jsx)(Za,{scope:e.manifest.scope})}),(0,Y.jsx)(no,{label:J(`engine.packages.col.status`,o),children:(0,Y.jsx)(Qa,{pkg:e})}),e.manifest.description&&(0,Y.jsx)(no,{label:J(`engine.packages.detail.description`,o),children:e.manifest.description})]}),t&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(De,{className:`my-4`}),(0,Y.jsxs)(n,{to:`${t}/metadata/object?package=${encodeURIComponent(h)}`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>i(!1),children:[(0,Y.jsx)(Re,{className:`h-3.5 w-3.5`}),J(`engine.packages.detail.browseMetadata`,o)]})]}),d&&d.length>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(De,{className:`my-4`}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:[J(`engine.packages.detail.pendingChanges`,o),(0,Y.jsx)(R,{variant:`secondary`,children:d.length})]}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:J(`engine.packages.detail.pendingHint`,o)}),!_&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsxs)(H,{size:`sm`,onClick:()=>v(`publish-drafts`,()=>Xa(`${Ya}/${encodeURIComponent(h)}/publish-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{let e=await Xa(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(h)}`);f(e?.drafts??[])}catch{f([])}if(e?.failedCount)throw Error(q(`engine.packages.detail.publishDraftsPartial`,o,{published:e.publishedCount??0,failed:e.failedCount}));return e}),J(`engine.packages.detail.publishDraftsOk`,o)),disabled:!!s,children:[(0,Y.jsx)(oe,{className:`mr-1.5 h-3.5 w-3.5`}),s===`publish-drafts`?J(`engine.packages.detail.publishing`,o):q(`engine.packages.detail.publishApp`,o,{count:d.length})]}),(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,onClick:()=>v(`discard-drafts`,()=>Xa(`${Ya}/${encodeURIComponent(h)}/discard-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{let e=await Xa(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(h)}`);f(e?.drafts??[])}catch{f([])}if(e?.failedCount)throw Error(q(`engine.packages.detail.discardDraftsPartial`,o,{discarded:e.discardedCount??0,failed:e.failedCount}));return e}),J(`engine.packages.detail.discardDraftsOk`,o)),disabled:!!s,children:[(0,Y.jsx)(Oe,{className:`mr-1.5 h-3.5 w-3.5`}),s===`discard-drafts`?J(`engine.packages.detail.discarding`,o):q(`engine.packages.detail.discardChanges`,o,{count:d.length})]})]}),(0,Y.jsx)(`ul`,{className:`space-y-1`,children:d.map(e=>t?(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(n,{to:`${t}/metadata/${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}?review=1`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>i(!1),children:[(0,Y.jsx)(nt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]})},`${e.type}/${e.name}`):(0,Y.jsxs)(`li`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,Y.jsx)(nt,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]},`${e.type}/${e.name}`))})]})]}),(0,Y.jsx)(De,{className:`my-4`}),_?(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:J(`engine.packages.detail.kernelReadOnly`,o)}):(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:J(`engine.packages.detail.actions`,o)}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,onClick:()=>m(!0),disabled:!!s,children:[(0,Y.jsx)(Gn,{className:`mr-1.5 h-3.5 w-3.5`}),J(`engine.packages.detail.edit`,o)]}),(0,Y.jsxs)(H,{size:`sm`,onClick:()=>v(`publish`,()=>Xa(`${Ya}/${encodeURIComponent(h)}/publish`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(e=>{if(e&&e.success===!1){let t=e.validationErrors?.length??0;throw Error(t?q(`engine.packages.detail.publishBlocked`,o,{count:t}):e.validationErrors?.[0]?.message||J(`engine.packages.detail.nothingToPublish`,o))}return e}),J(`engine.packages.detail.published`,o)),disabled:!!s,children:[(0,Y.jsx)(oe,{className:`mr-1.5 h-3.5 w-3.5`}),J(s===`publish`?`engine.packages.detail.publishing`:`engine.packages.detail.publish`,o)]}),(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,onClick:()=>v(`revert`,()=>Xa(`${Ya}/${encodeURIComponent(h)}/revert`,{method:`POST`}),J(`engine.packages.detail.reverted`,o)),disabled:!!s,children:[(0,Y.jsx)(Oe,{className:`mr-1.5 h-3.5 w-3.5`}),J(`engine.packages.detail.revert`,o)]}),(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,onClick:()=>v(`toggle`,()=>Xa(`${Ya}/${encodeURIComponent(h)}/${g?`disable`:`enable`}`,{method:`PATCH`}),J(g?`engine.packages.detail.disabled`:`engine.packages.detail.enabled`,o)),disabled:!!s,children:[g?(0,Y.jsx)(Ie,{className:`mr-1.5 h-3.5 w-3.5`}):(0,Y.jsx)(ir,{className:`mr-1.5 h-3.5 w-3.5`}),J(g?`engine.packages.detail.disable`:`engine.packages.detail.enable`,o)]}),(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,onClick:()=>v(`export`,async()=>{let e=await Xa(`${Ya}/${encodeURIComponent(h)}/export`),t=new Blob([JSON.stringify(e,null,2)],{type:`application/json`}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${h}.package.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)},J(`engine.packages.detail.exported`,o)),disabled:!!s,children:[(0,Y.jsx)(st,{className:`mr-1.5 h-3.5 w-3.5`}),J(s===`export`?`engine.packages.detail.exporting`:`engine.packages.detail.export`,o)]}),(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,onClick:async()=>{let t=window.prompt(J(`engine.packages.detail.duplicatePrompt`,o),`${h}-copy`);if(!(!t||!t.trim())){c(`duplicate`),u(null);try{await Xa(`${Ya}/${encodeURIComponent(h)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({targetPackageId:t.trim(),targetName:`${e?.manifest.name??h} (copy)`})}),u({kind:`ok`,text:J(`engine.packages.detail.duplicated`,o)}),a()}catch(e){u({kind:`err`,text:e?.message??`Duplicate failed`})}finally{c(null)}}},disabled:!!s,children:[(0,Y.jsx)(dn,{className:`mr-1.5 h-3.5 w-3.5`}),J(s===`duplicate`?`engine.packages.detail.duplicating`:`engine.packages.detail.duplicate`,o)]}),(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,onClick:async()=>{if(window.confirm(q(`engine.packages.detail.adoptConfirm`,o,{name:e?.manifest.name||h}))){c(`adopt`),u(null);try{await Xa(`${Ya}/${encodeURIComponent(h)}/adopt-orphans`,{method:`POST`}),u({kind:`ok`,text:J(`engine.packages.detail.adopted`,o)}),a()}catch(e){u({kind:`err`,text:e?.message??`Adopt failed`})}finally{c(null)}}},disabled:!!s,children:[(0,Y.jsx)(tn,{className:`mr-1.5 h-3.5 w-3.5`}),J(s===`adopt`?`engine.packages.detail.adopting`:`engine.packages.detail.adoptOrphans`,o)]}),(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,onClick:async()=>{if(!window.confirm(q(`engine.packages.detail.deleteConfirm`,o,{name:e?.manifest.name||h})))return;let t=window.confirm(J(`engine.packages.detail.deleteKeepData`,o))?``:`?keepData=true`;c(`delete`),u(null);try{await Xa(`${Ya}/${encodeURIComponent(h)}${t}`,{method:`DELETE`}),a(),i(!1)}catch(e){u({kind:`err`,text:e?.message??J(`engine.packages.detail.deleteFailed`,o)})}finally{c(null)}},disabled:!!s,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:[(0,Y.jsx)(sr,{className:`mr-1.5 h-3.5 w-3.5`}),J(s===`delete`?`engine.packages.detail.deleting`:`engine.packages.detail.deleteApp`,o)]})]})]}),l&&(0,Y.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${l.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:l.text}),(0,Y.jsx)(ro,{pkg:e,open:p,onOpenChange:m,onSaved:()=>{u({kind:`ok`,text:J(`engine.packages.edit.saved`,o)}),a()}})]})})}function ao(){let e=X.useMemo(()=>Vi(),[]),{pathname:t}=r(),n=X.useMemo(()=>{let e=t.indexOf(`/component`);return e>=0?t.slice(0,e):t},[t]),[i,a]=X.useState([]),[o,s]=X.useState(!0),[c,l]=X.useState(null),[u,d]=X.useState(``),[f,p]=X.useState(!1),[m,h]=X.useState(!1),[g,_]=X.useState(null),[v,y]=X.useState(!1),b=X.useRef(null),[x,S]=X.useState(!1),[C,w]=X.useState(null),T=X.useCallback(async()=>{s(!0),l(null);try{let e=await Xa(Ya),t=Array.isArray(e?.packages)?e.packages:[];t.sort((e,t)=>{let n=e.manifest.scope===`project`?0:1,r=t.manifest.scope===`project`?0:1;return n===r?(e.manifest.name||e.manifest.id).localeCompare(t.manifest.name||t.manifest.id):n-r}),a(t)}catch(t){l(t?.message??J(`engine.packages.loadFailed`,e))}finally{s(!1)}},[e]);X.useEffect(()=>{T()},[T]),X.useEffect(()=>{if(!g)return;let e=i.find(e=>e.manifest.id===g.manifest.id);e&&e!==g&&_(e)},[i,g]);let E=X.useMemo(()=>{let e=u.trim().toLowerCase();return i.filter(t=>(t.manifest.scope===`system`||t.manifest.scope===`cloud`)&&!f?!1:e?t.manifest.id.toLowerCase().includes(e)||(t.manifest.name||``).toLowerCase().includes(e):!0)},[i,u,f]),D=e=>{_(e),y(!0)},O=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){S(!0),w(null);try{let t=await n.text(),r;try{r=JSON.parse(t)}catch{throw Error(J(`engine.packages.import.invalidJson`,e))}if(!r||typeof r!=`object`||!r.id&&!r.name)throw Error(J(`engine.packages.import.invalidPackage`,e));let i=await Xa(`/api/v1/marketplace/install-local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:r})});w({kind:`ok`,text:q(`engine.packages.import.success`,e,{id:i?.manifestId??r.id})}),await T()}catch(t){w({kind:`err`,text:t?.message??J(`engine.packages.import.failed`,e)})}finally{S(!1)}}},k=i.filter(e=>e.manifest.scope===`system`||e.manifest.scope===`cloud`).length;return(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-6 py-6`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Y.jsx)(`div`,{className:`rounded-lg bg-primary/10 p-2 text-primary`,children:(0,Y.jsx)(xn,{className:`h-5 w-5`})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:J(`engine.packages.title`,e)}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:J(`engine.packages.description`,e)})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>void T(),disabled:o,children:[(0,Y.jsx)(Dt,{className:`mr-1.5 h-3.5 w-3.5 ${o?`animate-spin`:``}`}),J(`engine.packages.refresh`,e)]}),(0,Y.jsx)(`input`,{ref:b,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:O}),(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>b.current?.click(),disabled:x,children:[(0,Y.jsx)(nt,{className:`mr-1.5 h-3.5 w-3.5`}),J(x?`engine.packages.importing`:`engine.packages.import`,e)]}),(0,Y.jsxs)(H,{size:`sm`,onClick:()=>h(!0),children:[(0,Y.jsx)(L,{className:`mr-1.5 h-3.5 w-3.5`}),J(`engine.packages.new`,e)]})]})]}),C&&(0,Y.jsx)(`div`,{className:`mt-4 rounded-md border p-2 text-sm ${C.kind===`ok`?`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`:`border-destructive/40 bg-destructive/10 text-destructive`}`,children:C.text}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`relative w-full max-w-xs`,children:[(0,Y.jsx)(Xe,{className:`absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(V,{className:`pl-8`,placeholder:J(`engine.packages.search`,e),value:u,onChange:e=>d(e.target.value)})]}),k>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Er,{id:`show-kernel`,checked:f,onCheckedChange:p}),(0,Y.jsx)(z,{htmlFor:`show-kernel`,className:`text-sm text-muted-foreground`,children:q(`engine.packages.showPlatform`,e,{count:k})})]})]}),(0,Y.jsx)(`div`,{className:`mt-4 rounded-lg border`,children:o?(0,Y.jsx)(`div`,{className:`space-y-2 p-4`,children:[0,1,2].map(e=>(0,Y.jsx)(pt,{className:`h-10 w-full`},e))}):c?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 p-4 text-sm text-destructive`,children:[(0,Y.jsx)(I,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,Y.jsx)(`span`,{children:c})]}):E.length===0?(0,Y.jsx)(`div`,{className:`p-8`,children:(0,Y.jsxs)(jt,{children:[(0,Y.jsx)(Fe,{children:J(`engine.packages.empty`,e)}),(0,Y.jsx)(F,{children:i.length===0?J(`engine.packages.emptyCreate`,e):J(`engine.packages.emptyFiltered`,e)})]})}):(0,Y.jsxs)(bn,{children:[(0,Y.jsx)(Tn,{children:(0,Y.jsxs)(Qt,{children:[(0,Y.jsx)(Dn,{children:J(`engine.packages.col.name`,e)}),(0,Y.jsx)(Dn,{children:`ID`}),(0,Y.jsx)(Dn,{className:`w-24`,children:J(`engine.packages.col.version`,e)}),(0,Y.jsx)(Dn,{className:`w-24`,children:J(`engine.packages.col.scope`,e)}),(0,Y.jsx)(Dn,{className:`w-24`,children:J(`engine.packages.col.status`,e)})]})}),(0,Y.jsx)(rr,{children:E.map(e=>(0,Y.jsxs)(Qt,{className:`cursor-pointer`,onClick:()=>D(e),children:[(0,Y.jsx)(Wn,{className:`font-medium`,children:e.manifest.name||e.manifest.id}),(0,Y.jsx)(Wn,{className:`font-mono text-xs text-muted-foreground`,children:e.manifest.id}),(0,Y.jsx)(Wn,{children:e.manifest.version||`—`}),(0,Y.jsx)(Wn,{children:(0,Y.jsx)(Za,{scope:e.manifest.scope})}),(0,Y.jsx)(Wn,{children:(0,Y.jsx)(Qa,{pkg:e})})]},e.manifest.id))})]})}),(0,Y.jsx)(to,{open:m,onOpenChange:h,onCreated:async()=>{await T()}}),(0,Y.jsx)(io,{pkg:g,appBase:n,open:v,onOpenChange:y,onChanged:()=>void T()})]})}var oo=new Set([`field`,`package`]),so={data:Yn,ui:Wt,automation:ne,ai:En,system:vt,platform:vt,identity:mt,security:mt},co={data:{from:`from-sky-500`,to:`to-blue-600`,ring:`hover:ring-sky-400/40`,text:`text-sky-600 dark:text-sky-400`},ui:{from:`from-violet-500`,to:`to-fuchsia-600`,ring:`hover:ring-violet-400/40`,text:`text-violet-600 dark:text-violet-400`},automation:{from:`from-amber-500`,to:`to-orange-600`,ring:`hover:ring-amber-400/40`,text:`text-amber-600 dark:text-amber-400`},ai:{from:`from-pink-500`,to:`to-rose-600`,ring:`hover:ring-pink-400/40`,text:`text-pink-600 dark:text-pink-400`},identity:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},security:{from:`from-emerald-500`,to:`to-teal-600`,ring:`hover:ring-emerald-400/40`,text:`text-emerald-600 dark:text-emerald-400`},system:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},platform:{from:`from-slate-500`,to:`to-slate-700`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`},other:{from:`from-slate-400`,to:`to-slate-600`,ring:`hover:ring-slate-400/40`,text:`text-slate-600 dark:text-slate-300`}},lo=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],uo=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],fo={object:An,dashboard:Lt,page:Ce,report:Jt,record:fr,metadata:Wt};function po(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function mo(e,t){let n=new Date(e).getTime();if(Number.isNaN(n))return``;let r=Date.now()-n,i=t.startsWith(`zh`),a=Math.floor(r/6e4);if(a<1)return i?`刚刚`:`just now`;if(a<60)return i?`${a} 分钟前`:`${a}m ago`;let o=Math.floor(a/60);if(o<24)return i?`${o} 小时前`:`${o}h ago`;let s=Math.floor(o/24);if(s<7)return i?`${s} 天前`:`${s}d ago`;let c=Math.floor(s/7);return i?`${c} 周前`:`${c}w ago`}function ho(){let e=ti(),{loading:t,entries:r}=$r(e),{recentItems:i}=Gr(),a=X.useMemo(()=>Vi(),[]),[s,c]=o(),[l,u]=X.useState(null);X.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;u(Ha(n))}catch{t||u([])}})(),()=>{t=!0}},[e]);let d=s.get(`package`),f=X.useMemo(()=>l?d&&l.some(e=>e.id===d)?d:l[0]?.id??null:null,[l,d]);X.useEffect(()=>{if(!l||l.length===0||d&&l.some(e=>e.id===d))return;let e=new URLSearchParams(s);e.set(`package`,l[0].id),c(e,{replace:!0})},[l,d]);let p=f?`?package=${encodeURIComponent(f)}`:``,m=`metadata${p}`,h=`component/developer/packages${p}`,{summary:g,countsByType:_,packagesByType:v,loading:y}=ei(e,`warning`,f??void 0),b=X.useMemo(()=>r.filter(e=>oo.has(e.type)||!f?!1:(v[e.type]??[]).includes(f)),[f,r,v]),x=X.useMemo(()=>b.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate),[b]),S=X.useMemo(()=>{let e={};for(let t of b)(e[t.domain??`other`]??=[]).push(t);for(let t of Object.values(e))t.sort((e,t)=>(_[t.type]??0)-(_[e.type]??0));return Object.entries(e).sort(([e],[t])=>(lo.indexOf(e)===-1?99:lo.indexOf(e))-(lo.indexOf(t)===-1?99:lo.indexOf(t)))},[b,_]),C=X.useMemo(()=>{let e=new Map(x.map(e=>[e.type,e]));return uo.map(t=>e.get(t)).filter(Boolean)},[x]),w=g.total,T=!t&&!y&&w===0;return t||l===null||f&&y?(0,Y.jsx)(`div`,{className:`flex h-full items-center justify-center p-8 text-sm text-muted-foreground`,children:J(`engine.home.loading`,a)}):(0,Y.jsxs)(`div`,{className:`h-full overflow-auto bg-gradient-to-b from-muted/40 to-background`,children:[(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-6 py-6 space-y-6`,children:[(0,Y.jsxs)(`section`,{className:`relative overflow-hidden rounded-3xl bg-gradient-to-br from-indigo-600 via-violet-600 to-fuchsia-600 px-7 py-8 text-white shadow-xl shadow-violet-500/20`,children:[(0,Y.jsx)(`div`,{className:`pointer-events-none absolute -right-16 -top-20 h-64 w-64 rounded-full bg-white/15 blur-3xl`}),(0,Y.jsx)(`div`,{className:`pointer-events-none absolute -bottom-24 left-1/3 h-56 w-56 rounded-full bg-fuchsia-300/20 blur-3xl`}),(0,Y.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-[0.12]`,style:{backgroundImage:`radial-gradient(currentColor 1px, transparent 1px)`,backgroundSize:`18px 18px`}}),(0,Y.jsxs)(`div`,{className:`relative flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`max-w-xl`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white/80`,children:[(0,Y.jsx)(En,{className:`h-4 w-4`}),J(po(),a)]}),(0,Y.jsx)(`h1`,{className:`mt-2 text-3xl font-bold tracking-tight sm:text-4xl`,children:`Studio`}),(0,Y.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-white/85 sm:text-base`,children:J(`engine.home.subtitle`,a)}),(0,Y.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,Y.jsx)(H,{asChild:!0,size:`sm`,variant:`ghost`,className:`bg-white/10 text-white shadow-sm ring-1 ring-white/25 hover:bg-white/20 hover:text-white`,children:(0,Y.jsxs)(n,{to:m,children:[(0,Y.jsx)(Wt,{className:`mr-1.5 h-4 w-4`}),J(`engine.home.browseAll`,a)]})}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full bg-white/15 px-3 py-1.5 text-xs font-medium text-white/90 backdrop-blur-sm`,children:[(0,Y.jsx)(Xe,{className:`h-3.5 w-3.5`}),J(`engine.directory.quickFind`,a),` ⌘⇧M`]})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,Y.jsx)(go,{value:b.length,label:J(`engine.home.statTypes`,a)}),(0,Y.jsx)(go,{value:x.length,label:J(`engine.home.statWritable`,a)}),(0,Y.jsx)(go,{value:l.length,label:J(`engine.home.statPackages`,a)})]})]})]}),(0,Y.jsxs)(`section`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-4`,children:[(0,Y.jsx)(_o,{icon:Wt,from:`from-indigo-500`,to:`to-violet-600`,value:b.length,label:J(`engine.home.statTypes`,a),to_link:m}),(0,Y.jsx)(_o,{icon:In,from:`from-sky-500`,to:`to-blue-600`,value:x.length,label:J(`engine.home.statWritable`,a),to_link:m}),(0,Y.jsx)(_o,{icon:xn,from:`from-emerald-500`,to:`to-teal-600`,value:l.length,label:J(`engine.home.statPackages`,a),to_link:h}),(0,Y.jsxs)(n,{to:T?m:`metadata/_diagnostics${p}`,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border p-4 transition-all hover:-translate-y-0.5 hover:shadow-lg `+(T?`border-emerald-200 bg-emerald-50/60 dark:border-emerald-900/50 dark:bg-emerald-950/30`:`border-amber-300 bg-amber-50/70 dark:border-amber-900/50 dark:bg-amber-950/30`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br text-white shadow-sm `+(T?`from-emerald-500 to-teal-600`:`from-amber-500 to-orange-600`),children:T?(0,Y.jsx)(In,{className:`h-5 w-5`}):(0,Y.jsx)(I,{className:`h-5 w-5`})}),(0,Y.jsx)(Nr,{className:`h-4 w-4 text-muted-foreground transition-transform group-hover:translate-x-0.5`})]}),(0,Y.jsxs)(`div`,{className:`mt-3`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:T?J(`engine.home.allHealthy`,a):w}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:J(T?`engine.home.allHealthyHint`:`engine.home.statIssues`,a)})]})]})]}),C.length>0&&(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(vo,{icon:L,title:J(`engine.home.quickActions`,a),hint:J(`engine.home.quickActionsHint`,a)}),(0,Y.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2.5`,children:C.map(e=>(0,Y.jsx)(H,{asChild:!0,variant:`outline`,size:`sm`,className:`group rounded-full border-transparent bg-muted hover:bg-primary/10 hover:text-primary`,children:(0,Y.jsxs)(n,{to:`metadata/${encodeURIComponent(e.type)}/new${p}`,children:[(0,Y.jsx)(L,{className:`mr-1 h-3.5 w-3.5 text-primary transition-transform group-hover:rotate-90`}),q(`engine.home.newItem`,a,{label:vi(e.type,a,e.label)})]})},e.type))})]}),(0,Y.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-3`,children:[(0,Y.jsxs)(`section`,{className:`lg:col-span-2`,children:[(0,Y.jsx)(vo,{icon:Wt,title:J(`engine.home.explore`,a),hint:J(`engine.home.exploreHint`,a)}),(0,Y.jsx)(`div`,{className:`mt-3 grid gap-4 sm:grid-cols-2`,children:S.map(([e,t])=>(0,Y.jsx)(yo,{domain:e,group:t,countsByType:_,locale:a,packageSuffix:p},e))})]}),(0,Y.jsxs)(`section`,{children:[(0,Y.jsx)(vo,{icon:wn,title:J(`engine.home.recent`,a)}),(0,Y.jsx)(`div`,{className:`mt-3 rounded-2xl border bg-card p-2`,children:i.length===0?(0,Y.jsx)(`div`,{className:`px-3 py-8 text-center text-xs text-muted-foreground`,children:J(`engine.home.recentEmpty`,a)}):(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:i.slice(0,8).map(e=>{let t=fo[e.type]??fr;return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(n,{to:e.href,className:`group flex items-center gap-3 rounded-xl px-3 py-2 transition-colors hover:bg-accent`,children:[(0,Y.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground transition-colors group-hover:bg-primary/10 group-hover:text-primary`,children:(0,Y.jsx)(t,{className:`h-4 w-4`})}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.label}),(0,Y.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:mo(e.visitedAt,a)})]}),(0,Y.jsx)(Nr,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,Y.jsx)(Ba,{})]})}function go({value:e,label:t}){return(0,Y.jsxs)(`div`,{className:`rounded-2xl bg-white/15 px-4 py-3 text-center backdrop-blur-sm ring-1 ring-white/20`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums leading-none`,children:e}),(0,Y.jsx)(`div`,{className:`mt-1 text-[11px] font-medium text-white/80`,children:t})]})}function _o({icon:e,from:t,to:r,value:i,label:a,to_link:o}){return(0,Y.jsxs)(n,{to:o,className:`group relative flex flex-col justify-between overflow-hidden rounded-2xl border bg-card p-4 transition-all hover:-translate-y-0.5 hover:border-primary/40 hover:shadow-lg`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`div`,{className:`flex h-10 w-10 items-center justify-center rounded-xl bg-gradient-to-br ${t} ${r} text-white shadow-sm`,children:(0,Y.jsx)(e,{className:`h-5 w-5`})}),(0,Y.jsx)(Nr,{className:`h-4 w-4 text-muted-foreground opacity-0 transition-all group-hover:translate-x-0.5 group-hover:opacity-100`})]}),(0,Y.jsxs)(`div`,{className:`mt-3`,children:[(0,Y.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:i}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:a})]})]})}function vo({icon:e,title:t,hint:n}){return(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2.5`,children:[(0,Y.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,Y.jsx)(e,{className:`h-4 w-4 text-muted-foreground`}),t]}),n&&(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]})}function yo({domain:e,group:t,countsByType:r,locale:i,packageSuffix:a}){let o=so[e]??fr,s=co[e]??co.other,c=t.slice(0,6),l=t.length-c.length;return(0,Y.jsxs)(`div`,{className:`group rounded-2xl border bg-card p-4 ring-1 ring-transparent transition-all hover:-translate-y-0.5 hover:shadow-lg ${s.ring}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(`div`,{className:`flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br ${s.from} ${s.to} text-white shadow-sm`,children:(0,Y.jsx)(o,{className:`h-[18px] w-[18px]`})}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:Ui(e,i)}),(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.length,` `,J(`engine.home.typesLower`,i)]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[c.map(e=>(0,Y.jsxs)(n,{to:`metadata/${encodeURIComponent(e.type)}${a}`,className:`inline-flex items-center gap-1.5 rounded-lg border bg-background px-2 py-1 text-xs transition-colors hover:border-primary/50 hover:bg-accent`,children:[(0,Y.jsx)(`span`,{className:`truncate max-w-[10rem]`,children:vi(e.type,i,e.label)}),(0,Y.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:r[e.type]??0})]},e.type)),l>0&&(0,Y.jsxs)(n,{to:`metadata${a}`,className:`inline-flex items-center gap-1 rounded-lg px-2 py-1 text-xs font-medium ${s.text} hover:underline`,children:[`+`,l]})]})]})}function bo({entry:e,itemName:t,subtitle:i,stats:a,actions:o,children:s}){let c=e?.type??``,l=X.useMemo(()=>Vi(),[]),u=vi(c,l,e?.label),{pathname:d}=r(),f=X.useMemo(()=>{let e=d.indexOf(`/metadata`);return e>=0?d.slice(0,e+9):`/metadata`},[d]);return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[t?(0,Y.jsxs)(`div`,{className:`px-6 py-2.5 border-b bg-background flex items-center gap-3 min-h-[44px]`,children:[(0,Y.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground min-w-0`,children:[(0,Y.jsx)(n,{to:f,className:`hover:text-foreground shrink-0`,children:J(`engine.breadcrumb.allTypes`,l)}),(0,Y.jsx)(N,{className:`h-3 w-3 shrink-0`}),(0,Y.jsx)(n,{to:`${f}/${encodeURIComponent(c)}`,className:`hover:text-foreground shrink-0`,children:u}),(0,Y.jsx)(N,{className:`h-3 w-3 shrink-0`}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium font-mono truncate`,title:t,children:t})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[e?.domain&&(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:Ui(e.domain,l)}),e?.allowOrgOverride?(0,Y.jsx)(R,{className:`text-[10px] h-5 px-1.5 `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:J(`engine.badge.writable`,l)}):e?.allowRuntimeCreate?(0,Y.jsx)(R,{className:`text-[10px] h-5 px-1.5 bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:J(`engine.badge.createOnly`,l)}):(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px] h-5 px-1.5 text-muted-foreground`,children:J(`engine.badge.readOnly`,l)})]}),i&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:i}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[a?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-1 px-2 py-0.5 rounded border bg-muted/30`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-xs font-semibold tabular-nums`,children:e.value})]},t)),o]})]}):(0,Y.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Y.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground mb-2`,children:[(0,Y.jsx)(n,{to:f,className:`hover:text-foreground`,children:J(`engine.breadcrumb.allTypes`,l)}),(0,Y.jsx)(N,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{className:`text-foreground font-medium`,children:u})]}),(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold truncate`,children:u}),(0,Y.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:c}),e?.domain&&(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:Ui(e.domain,l)}),e?.allowOrgOverride?(0,Y.jsx)(R,{className:`text-[10px] `+(e.overrideSource===`env`?`bg-amber-100 text-amber-800 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),title:e.overrideSource===`env`?`Writable via OBJECTSTACK_METADATA_WRITABLE env var`:`Writable per ADR-0005 overlay opt-in`,children:J(`engine.badge.writable`,l)}):e?.allowRuntimeCreate?(0,Y.jsx)(R,{className:`text-[10px] bg-sky-100 text-sky-800 hover:bg-sky-100`,title:`Code-shipped items are locked; new items can be created at runtime`,children:J(`engine.badge.createOnly`,l)}):(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:J(`engine.badge.readOnly`,l)})]}),i&&(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1`,children:i}),!i&&e?.description&&(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,children:e.description})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex flex-col items-end px-3 py-1 rounded border bg-muted/30 min-w-[64px]`,children:[(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:e.value})]},t)),o]})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:s})]})}var xo={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function So(e,t,n){return e.indexOf("${")===-1?e:e.replace(/\$\{(param|ctx)\.([\w.]+)\}/g,(e,r,i)=>{let a=r===`param`?n:t,o=i.split(`.`).reduce((e,t)=>e?.[t],a);return o==null?``:encodeURIComponent(String(o))})}function Co({entry:e,location:t,recordId:n,onAfter:r}){let[i,a]=X.useState(null),[o,s]=X.useState({open:!1,params:[]}),[c,l]=X.useState({open:!1}),u=X.useMemo(()=>d(),[]),f=X.useMemo(()=>(e?.actions??[]).filter(e=>!e.locations||e.locations.length===0||e.locations.includes(t)),[e?.actions,t]);if(f.length===0)return null;let p=(e,t)=>new Promise(n=>{s({open:!0,params:e,title:t,resolve:n})}),m=async e=>{let t=e.label??e.name;if(e.type!==`api`){Hr.error(`Action “${t}”: type "${e.type??`script`}" is not supported here yet.`);return}if(e.confirmText&&!window.confirm(e.confirmText))return;let i;if(Array.isArray(e.params)&&e.params.length>0){let n=await p(e.params,t);if(n==null)return;i=n}else i=e.params??{};let o={recordId:n,origin:window.location.origin},s=So(e.target??``,o,i);if(!s){Hr.error(`Action “${t}” has no target.`);return}let c=``.replace(/\/+$/,``),d=/^https?:\/\//i.test(s)?s:`${c}${s}`,f=(e.method||`POST`).toUpperCase();a(e.name);try{let n={method:f,headers:{"Content-Type":`application/json`},credentials:`include`};f!==`GET`&&f!==`DELETE`&&(n.body=JSON.stringify(i));let a=await u(d,n),o=null;try{o=await a.json()}catch{}if(!a.ok||o&&o.success===!1){let n=o?.error||o?.message||`HTTP ${a.status} ${a.statusText}`.trim();Hr.error(`${e.errorMessage?`${e.errorMessage}: `:``}${t}: ${n}`);return}if(e.resultDialog)l({open:!0,spec:e.resultDialog,data:o??{}});else{let n=e.successMessage||(typeof o?.message==`string`?o.message:`${t} ✓`);Hr.success(n)}e.refreshAfter&&r?.()}catch(e){Hr.error(`${t}: ${e?.message??String(e)}`)}finally{a(null)}};return(0,Y.jsxs)(Y.Fragment,{children:[f.map(e=>{let t=e.icon?Gi(e.icon):null,n=i===e.name;return(0,Y.jsxs)(H,{size:`sm`,variant:xo[e.variant??`secondary`]??`secondary`,disabled:n,onClick:()=>m(e),title:e.label??e.name,children:[n?(0,Y.jsx)(U,{className:`h-4 w-4 mr-1 animate-spin`}):t?(0,Y.jsx)(t,{className:`h-4 w-4 mr-1`}):null,e.label??e.name]},e.name)}),(0,Y.jsx)(Yr,{state:o,onOpenChange:e=>{e||(o.resolve?.(null),s({open:!1,params:[]}))}}),(0,Y.jsx)(Jr,{state:c,onAcknowledge:()=>l({open:!1})})]})}function wo(e){let t=(Array.isArray(e)?e:[e]).map(e=>e.split(`.`));return(e,n)=>{for(let r of t){let t=e;for(let e of r)if(t&&typeof t==`object`&&e in t)t=t[e];else{t=void 0;break}if(t===n)return!0}return!1}}var To=new Map;function Eo(e){let t=To.get(e.type);if(!t){To.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);To.set(e.type,n)}function Do(e){return To.get(e)}function Oo(e){let t=[];for(let n of To.values())if(n.anchors?.length)for(let r of n.anchors)r.anchorType===e&&t.push({type:n.type,config:n,anchor:r});return t.sort((e,t)=>{let n=e.anchor.order??100,r=t.anchor.order??100;if(n!==r)return n-r;let i=e.anchor.groupLabel??e.config.label??e.type,a=t.anchor.groupLabel??t.config.label??t.type;return i.localeCompare(a)}),t}function ko(e,t){let n=To.get(e)??{type:e};return{...n,type:e,label:n.label??t?.label??e,description:n.description??t?.description,domain:n.domain??t?.domain??`other`,allowOrgOverride:t?.allowOrgOverride,defaultSchema:n.defaultSchema}}function Ao(e,t){if(t===`overlay`||t===`runtime`)return`runtime`;if(t===`code`||t===`artifact`)return`artifact`;let n=e._packageId;return!n||n===`sys_metadata`?`runtime`:`artifact`}function jo({type:e}){let t=s(),n=e??t.type??``;if(n===`package`)return(0,Y.jsx)(l,{to:`/apps/${t.appName??`studio`}/component/developer/packages`,replace:!0});let r=Do(n);if(r?.ListPage){let e=r.ListPage;return(0,Y.jsx)(e,{type:n})}return(0,Y.jsx)(Mo,{type:n,appName:t.appName})}function Mo({type:e,appName:t}){let r=i(),a=ti(),{entries:s}=$r(a),c=s.find(t=>t.type===e),l=ko(e,c),[u,d]=X.useState([]),[f,p]=X.useState(!0),[m,h]=X.useState(null),[g,_]=X.useState(``),[v,y]=X.useState(`all`),[b,x]=o(),[S,C]=X.useState(0),[w,T]=X.useState(null);X.useEffect(()=>{let e=!1;return(async()=>{try{let t=await a.list(`package`);if(e)return;T(Ha(t))}catch{e||T([])}})(),()=>{e=!0}},[a]);let[E,D]=X.useState(null);X.useEffect(()=>{let e=!1;if(!t){D(null);return}return(async()=>{try{let n=await a.list(`app`);if(e)return;let r=(n??[]).map(e=>e&&typeof e==`object`&&`item`in e?e.item:e).find(e=>e?.name===t||e?._packageId===t);D(r?._packageId??null)}catch{e||D(null)}})(),()=>{e=!0}},[a,t]);let O=b.get(`package`),k=X.useMemo(()=>{if(!w)return null;if(O&&w.some(e=>e.id===O))return O;if(w.length===0)return null;if(E&&w.some(e=>e.id===E))return E;let e=new Map;for(let t of u){let n=t.item?._packageId;n&&n!==`sys_metadata`&&e.set(n,(e.get(n)??0)+1)}let t=null,n=0;for(let r of w){let i=e.get(r.id)??0;i>n&&(t=r.id,n=i)}return t??w[0]?.id??null},[w,O,u,E]);X.useEffect(()=>{if(!w||w.length===0||O&&w.some(e=>e.id===O)||!(E&&w.some(e=>e.id===E))&&u.length===0||!k)return;let e=new URLSearchParams(b);e.set(`package`,k),x(e,{replace:!0})},[w,O,u,k,E]);let A=k?`?package=${encodeURIComponent(k)}`:``,[j,ee]=X.useState(!1),te=X.useCallback(()=>{let e=w??[];if(w!==null&&e.length===0){ee(!0);return}if(e.length>0&&!k){r(`./new?package=${encodeURIComponent(e[0].id)}`);return}r(`./new${A}`)},[w,k,A,r]);X.useEffect(()=>{let t=!1;return p(!0),h(null),(async()=>{try{let n=await a.list(e);if(t)return;let r=(n??[]).map(e=>{let t=(e&&typeof e==`object`&&`item`in e?e.item:e)??{},n=t?._diagnostics??e?._diagnostics??void 0;return{raw:e,item:t,source:Ao(t,e?.source),diagnostics:n}});d(r),p(!1)}catch(e){t||(h(e?.message??String(e)),p(!1))}})(),()=>{t=!0}},[a,e,S]);let ne=l.searchableFields??[`name`,`label`,`description`],M=X.useMemo(()=>u.filter(e=>l.listFilter&&!l.listFilter(e.item)||!k?!1:e.item?._packageId===k),[u,k,l]),re=M.filter(e=>!(!ni(e.item,g,ne)||v!==`all`&&e.source!==v)),ie=X.useMemo(()=>{let e={all:M.length,artifact:0,runtime:0};for(let t of M)e[t.source]++;return e},[M]),ae=X.useMemo(()=>M.filter(e=>e.diagnostics&&e.diagnostics.valid===!1).length,[M]),oe=X.useMemo(()=>M.filter(e=>e.diagnostics&&e.diagnostics.valid!==!1&&(e.diagnostics.warnings?.length??0)>0).length,[M]),N=l.listColumns??No(l.primaryKey??`name`),P=Vi(),se=vi(e,P,c?.label??e),ce=e=>{let t=`engine.list.col.${e.key}`,n=J(t,P);return n===t?e.label:n};return(0,Y.jsx)(bo,{entry:c??{type:e,label:e},stats:[{label:J(`engine.list.items`,P),value:M.length},{label:J(`engine.list.filtered`,P),value:re.length},...ae>0?[{label:J(`engine.list.invalid`,P),value:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,Y.jsx)(I,{className:`w-3.5 h-3.5`}),ae]})}]:[],...oe>0?[{label:J(`engine.list.warnings`,P),value:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,Y.jsx)(I,{className:`w-3.5 h-3.5`}),oe]})}]:[]],actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Co,{entry:c,location:`list_toolbar`,onAfter:()=>C(e=>e+1)}),(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>C(e=>e+1),title:J(`engine.list.refresh`,P),children:(0,Y.jsx)(Dt,{className:`h-4 w-4`})}),(c?.allowOrgOverride||c?.allowRuntimeCreate)&&(0,Y.jsxs)(H,{size:`sm`,variant:l.createFields?`default`:`outline`,onClick:te,title:l.createFields?q(`engine.list.createHint`,P,{type:se}):void 0,children:[(0,Y.jsx)(L,{className:`h-4 w-4 mr-1`}),J(`engine.list.create`,P)]})]}),children:(0,Y.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,Y.jsx)(to,{open:j,onOpenChange:ee,onCreated:e=>r(`./new?package=${encodeURIComponent(e)}`)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-md`,children:[(0,Y.jsx)(Xe,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(V,{className:`pl-8`,placeholder:J(`engine.list.search`,P),value:g,onChange:e=>_(e.target.value)})]}),(0,Y.jsxs)(Ue,{value:v,onValueChange:y,children:[(0,Y.jsx)(Ut,{className:`w-[180px]`,children:(0,Y.jsx)(Bt,{})}),(0,Y.jsxs)(cr,{children:[(0,Y.jsxs)(ze,{value:`all`,children:[J(`engine.list.allSources`,P),` (`,ie.all,`)`]}),(0,Y.jsxs)(ze,{value:`artifact`,children:[J(`engine.list.source.artifact`,P),` (`,ie.artifact,`)`]}),(0,Y.jsxs)(ze,{value:`runtime`,children:[J(`engine.list.source.runtime`,P),` (`,ie.runtime,`)`]})]})]})]}),(f||w===null)&&(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[J(`engine.edit.loading`,P),` `,e,`…`]}),m&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:m}),!f&&!m&&w!==null&&w.length===0&&(0,Y.jsxs)(jt,{children:[(0,Y.jsx)(Fe,{children:`No project packages installed`}),(0,Y.jsx)(F,{children:`Studio only shows metadata that belongs to a project software package. Install or create a project package to manage its metadata here.`})]}),!f&&!m&&w!==null&&w.length>0&&re.length===0&&(0,Y.jsxs)(jt,{children:[(0,Y.jsx)(Fe,{children:M.length===0?q(`engine.list.emptyType`,P,{type:se}):q(`engine.list.emptyQuery`,P,{query:g})}),(0,Y.jsx)(F,{children:l.emptyStateHint??(c?.allowOrgOverride||c?.allowRuntimeCreate?q(`engine.list.createHint`,P,{type:se}):J(`engine.list.readOnlyHint`,P))}),M.length===0&&(c?.allowOrgOverride||c?.allowRuntimeCreate)&&(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsxs)(H,{onClick:te,children:[(0,Y.jsx)(L,{className:`h-4 w-4 mr-1`}),J(`engine.list.create`,P)]})})]}),!f&&re.length>0&&(0,Y.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[N.map(e=>(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,style:e.width?{width:e.width}:void 0,children:ce(e)},e.key)),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:J(`engine.list.col.source`,P)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:re.map((e,t)=>{let r=l.primaryKey??`name`,i=String(e.item[r]??`(unnamed-${t})`),a=e.item._packageId,o=a&&a!==`sys_metadata`?`?package=${encodeURIComponent(a)}`:A,s=e.diagnostics?.valid===!1,c=e.diagnostics?.errors??[],u=e.diagnostics?.warnings??[],d=!s&&u.length>0,f=s?c.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
3
+ `)+(c.length>3?`\n+${c.length-3} more`:``):d?u.slice(0,3).map(e=>`${e.path||`(root)`}: ${e.message}`).join(`
4
+ `)+(u.length>3?`\n+${u.length-3} more`:``):``;return(0,Y.jsxs)(`tr`,{className:`hover:bg-accent/50 `+(s?`bg-destructive/[0.04]`:d?`bg-amber-500/[0.05]`:``),children:[N.map((t,r)=>{let a=e.item[t.key],l=t.render?t.render(a,e.item):Po(a);return(0,Y.jsx)(`td`,{className:`px-3 py-2 align-top`,children:r===0?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[s&&(0,Y.jsx)(`span`,{className:`inline-flex`,"aria-label":J(`engine.list.invalidTitle`,P),title:`${q(`engine.list.invalidCount`,P,{count:c.length})}\n${f}`,children:(0,Y.jsx)(I,{className:`w-3.5 h-3.5 text-destructive shrink-0`})}),d&&(0,Y.jsx)(`span`,{className:`inline-flex`,"aria-label":J(`engine.list.warnTitle`,P),title:`${q(`engine.list.warnCount`,P,{count:u.length})}\n${f}`,children:(0,Y.jsx)(I,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 shrink-0`})}),(0,Y.jsx)(n,{to:`./${encodeURIComponent(i)}${o}`,className:`text-primary hover:underline font-mono`,children:l})]}):l},t.key)}),(0,Y.jsxs)(`td`,{className:`px-3 py-2 text-right align-top`,children:[e.item._lock&&e.item._lock!==`none`&&(0,Y.jsx)(`span`,{className:`inline-flex items-center mr-1 text-amber-600 dark:text-amber-400`,title:e.item._lockReason??`_lock=${String(e.item._lock)}`,children:(0,Y.jsx)(lt,{className:`h-3 w-3`})}),(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px] `+(e.source===`artifact`?`border-sky-500/50 text-sky-700 dark:text-sky-300`:`border-emerald-500/50 text-emerald-700 dark:text-emerald-300`),title:e.source===`artifact`?`${J(`engine.list.source.artifactDesc`,P)}${e.item._packageId?` (${e.item._packageId})`:``}`:J(`engine.list.source.runtimeDesc`,P),children:J(`engine.list.source.${e.source}`,P)})]})]},i+t)})})]})})]})})}function No(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function Po(e){if(e==null||e===``)return(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});if(typeof e==`boolean`)return e?`✓`:`✗`;if(typeof e==`object`)try{return(0,Y.jsx)(`code`,{className:`font-mono text-xs`,children:JSON.stringify(e).slice(0,60)})}catch{return String(e)}return String(e)}var Fo=[`object`,`page`,`dashboard`,`report`,`url`,`group`],Io=[`default`,`view`,`record`,`filters`],Lo={object:{targetKey:`objectName`,metaType:`object`},page:{targetKey:`pageName`,metaType:`page`},dashboard:{targetKey:`dashboardName`,metaType:`dashboard`},report:{targetKey:`reportName`,metaType:`report`},url:{targetKey:`url`},group:{}},Ro=[`objectName`,`viewName`,`recordId`,`recordMode`,`filters`,`pageName`,`dashboardName`,`reportName`,`url`,`target`,`params`],zo=[`path`,`kind`,`href`,`route`,`object`,`page`,`dashboard`,`report`],Bo={object:`object`,page:`page`,dashboard:`dashboard`,report:`report`,link:`url`,url:`url`,group:`group`};function Vo(e){let t=e.type;if(typeof t==`string`&&Fo.includes(t))return t;let n=e.kind;if(typeof n==`string`&&Bo[n])return Bo[n];if(e.objectName||e.object)return`object`;if(e.pageName||e.page)return`page`;if(e.dashboardName||e.dashboard)return`dashboard`;if(e.reportName||e.report)return`report`;if(e.url||e.href)return`url`;if(Array.isArray(e.children)&&e.children.length>0)return`group`;let r=e.path;return typeof r==`string`&&/^https?:/i.test(r)?`url`:null}function Ho(e){if(e.recordId)return`record`;let t=e.filters;return t&&typeof t==`object`&&!Array.isArray(t)?`filters`:e.viewName?`view`:`default`}function Uo(e=[]){let t={};for(let n of[...Ro,...zo])e.includes(n)||(t[n]=void 0);return t}var Wo={default:[`objectName`],view:[`objectName`,`viewName`],record:[`objectName`,`recordId`,`recordMode`],filters:[`objectName`,`filters`]};function Go(e,t,n){let r=e.id;if(typeof r==`string`&&r)return r;let i=`nav_${(n??String(e.objectName??e.label??`item`)).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``)||`item`}`,a=new Set(t.map(e=>typeof e.id==`string`?e.id:``).filter(Boolean));if(!a.has(i))return i;let o=2;for(;a.has(`${i}_${o}`);)o++;return`${i}_${o}`}var Ko=[`nav`,`navigation`,`tabs`,`items`,`menu`];function qo(e){let t=e.split(`.`),n=[];for(let e of t){let t=/^([a-zA-Z_]\w*)\[(\d+)\]$/.exec(e);if(!t)return null;n.push({key:t[1],index:Number(t[2])})}return n.length>0?n:null}function Jo(e,t){let n=e[t[0].key];if(!Array.isArray(n))return{parent:[],node:null,index:-1};let r=n[t[0].index]??null;for(let e=1;e<t.length;e++){if(!r)return{parent:n,node:null,index:t[e].index};if(n=r[t[e].key],!Array.isArray(n))return{parent:[],node:null,index:-1};r=n[t[e].index]??null}return{parent:n,node:r,index:t[t.length-1].index}}function Yo(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:si(i,t[0].index,n)};let a=i,o=[];for(let e=0;e<t.length-1;e++){let n={...a[t[e].index]??{}};o.push({arr:a,index:t[e].index,node:n});let r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let s=si(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function Xo(e,t,n){let r=t[0].key;if(t.length===1)return{[r]:n};let i=Array.isArray(e[r])?[...e[r]]:[],a=i;for(let e=0;e<t.length-2;e++){let n={...a[t[e].index]??{}},r=t[e+1].key,i=Array.isArray(n[r])?[...n[r]]:[];n[r]=i,a[t[e].index]=n,a=i}let o=t[t.length-2],s=t[t.length-1].key,c={...a[o.index]??{}};return c[s]=n,a[o.index]=c,{[r]:i}}function Zo(e){let t=ti(),[n,r]=X.useState({options:[],loading:!!e});return X.useEffect(()=>{if(!e){r({options:[],loading:!1});return}let n=!1;return r(e=>({...e,loading:!0})),t.list(e).then(e=>{if(n)return;let t=(Array.isArray(e)?e:[]).filter(e=>e&&typeof e.name==`string`&&e.name).map(e=>({value:String(e.name),label:typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:String(e.name)}));r({options:t,loading:!1})}).catch(()=>{n||r({options:[],loading:!1})}),()=>{n=!0}},[t,e]),n}var Qo={currentUserId:`{current_user_id}`,currentOrgId:`{current_org_id}`};function $o({objectName:e,filters:t,onCommit:n,disabled:r,locale:i}){let{fields:a}=ki(e||void 0),o=X.useMemo(()=>a.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),[a]),s=Object.entries(t),c=(e,t,r)=>{let i=s.slice();i[e]=[t,r],n(Object.fromEntries(i.filter(([e])=>e!==``)))},l=e=>{let t=s.slice();t.splice(e,1),n(Object.fromEntries(t))};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground`,children:J(`engine.inspector.appNav.filters`,i)}),s.map(([e,t],n)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Zi,{value:e,onCommit:e=>c(n,e,t),options:o,placeholder:J(`engine.inspector.appNav.filtersField`,i),disabled:r,mono:!0})}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`=`}),(0,Y.jsx)(`input`,{value:t,onChange:t=>c(n,e,t.target.value),placeholder:J(`engine.inspector.appNav.filtersValue`,i),disabled:r,className:`h-7 w-0 min-w-0 flex-1 rounded border bg-background px-2 font-mono text-xs`,"data-testid":`nav-filter-value-${e||`new`}`}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>l(n),disabled:r,className:`rounded p-1 text-muted-foreground hover:bg-muted`,"aria-label":J(`engine.inspector.appNav.filtersRemove`,i),"data-testid":`nav-filter-remove-${e||`new`}`,children:(0,Y.jsx)(Qe,{className:`h-3 w-3`})})]},`${e}-${n}`)),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>n({...t,"":``}),disabled:r||Object.prototype.hasOwnProperty.call(t,``),className:`inline-flex items-center gap-1 rounded border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,"data-testid":`nav-filter-add`,children:[(0,Y.jsx)(L,{className:`h-3 w-3`}),J(`engine.inspector.appNav.filtersAdd`,i)]}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:J(`engine.inspector.appNav.filtersHint`,i)})]})}function es({selection:e,draft:t,name:n,onPatch:r,onClearSelection:i,onSelectionChange:a,locale:o,readOnly:s}){let c=qo(e.id),{node:l,parent:u,index:d}=c?Jo(t,c):{node:null,parent:[],index:-1},f=l?Vo(l):null,p=l?Ho(l):`default`,m=String(l?.objectName??l?.object??``),h=Zo(f===`object`?`object`:void 0),g=Zo(f&&f!==`object`?Lo[f].metaType:void 0),_=Zo(f===`object`&&p===`view`?`view`:void 0),v=X.useMemo(()=>m?_.options.filter(e=>e.value.startsWith(`${m}.`)||!e.value.includes(`.`)):_.options,[_.options,m]);if(!c||!l)return(0,Y.jsx)(ji,{kindLabel:J(`engine.inspector.appNav.kind`,o),title:e.label??e.id,onClose:i,closeLabel:J(`engine.inspector.appNav.close`,o),children:(0,Y.jsx)(oi,{message:e.id})});let y=l.label??l.title??l.name??e.id,b=e=>{let n=e.type??l.type??f??void 0;r(Yo(t,c,{...l,id:Go(l,u),...n?{type:n}:{},...e}))},x=e=>{let t=Lo[e].targetKey,n=e===`object`?Wo.default:t?[t]:[];b({type:e,...Uo(n)})},S=e=>{let t=Uo(Wo[e]);b(e===`filters`?{...t,objectName:m,filters:l.filters??{}}:{...t,objectName:m})},C=()=>{r(Yo(t,c,null)),i()},w=e=>{let n=gi(u,d,e);r(Xo(t,c,n));let i=c.slice(0,-1).map(e=>`${e.key}[${e.index}]`).join(`.`),o=c[c.length-1].key,s=i?`${i}.${o}[${e}]`:`${o}[${e}]`;a?.({kind:`nav`,id:s,label:String(y)})},T=f&&f!==`group`?Qr({...l,type:f},`/apps/${n||`app`}`,Qo).href:null,E=Lo[f??`group`];return(0,Y.jsxs)(ji,{kindLabel:J(`engine.inspector.appNav.kind`,o),title:String(y),onClose:i,closeLabel:J(`engine.inspector.appNav.close`,o),headerActions:(0,Y.jsx)(Mi,{index:d,total:u.length,onMove:w,upLabel:J(`engine.inspector.reorder.up`,o),downLabel:J(`engine.inspector.reorder.down`,o),disabled:s}),footer:(0,Y.jsx)(hi,{label:J(`engine.inspector.appNav.remove`,o),onClick:C,disabled:s}),children:[(0,Y.jsx)(G,{label:J(`engine.inspector.appNav.label`,o),value:String(l.label??l.title??l.name??``),onCommit:e=>b({label:e}),disabled:s}),(0,Y.jsx)(G,{label:J(`engine.inspector.appNav.icon`,o),value:String(l.icon??``),onCommit:e=>b({icon:e}),disabled:s}),(0,Y.jsx)(W,{label:J(`engine.inspector.appNav.typeField`,o),value:f??``,options:Fo.map(e=>({value:e,label:J(`engine.inspector.appNav.type.${e}`,o)})),onCommit:e=>x(e),disabled:s}),f===`object`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Zi,{label:J(`engine.inspector.appNav.object`,o),value:m,options:h.options,loading:h.loading,onCommit:e=>b({objectName:e,object:void 0}),disabled:s,mono:!0}),(0,Y.jsx)(W,{label:J(`engine.inspector.appNav.targetMode`,o),value:p,options:Io.map(e=>({value:e,label:J(`engine.inspector.appNav.mode.${e}`,o)})),onCommit:e=>S(e),disabled:s||!m}),p===`view`&&(0,Y.jsx)(Zi,{label:J(`engine.inspector.appNav.view`,o),value:String(l.viewName??``),options:v,loading:_.loading,onCommit:e=>b({viewName:e}),disabled:s,mono:!0}),p===`record`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{label:J(`engine.inspector.appNav.recordId`,o),value:String(l.recordId??``),onCommit:e=>b({recordId:e}),disabled:s,mono:!0}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:J(`engine.inspector.appNav.recordIdHint`,o)}),(0,Y.jsx)(W,{label:J(`engine.inspector.appNav.recordMode`,o),value:String(l.recordMode??`view`),options:[{value:`view`,label:J(`engine.inspector.appNav.recordModeView`,o)},{value:`edit`,label:J(`engine.inspector.appNav.recordModeEdit`,o)}],onCommit:e=>b({recordMode:e}),disabled:s})]}),p===`filters`&&(0,Y.jsx)($o,{objectName:m,filters:l.filters??{},onCommit:e=>b({filters:e}),disabled:s,locale:o})]}),f&&f!==`object`&&f!==`group`&&E.targetKey&&(E.metaType?(0,Y.jsx)(Zi,{label:J(`engine.inspector.appNav.type.${f}`,o),value:String(l[E.targetKey]??``),options:g.options,loading:g.loading,onCommit:e=>b({[E.targetKey]:e}),disabled:s,mono:!0}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(G,{label:J(`engine.inspector.appNav.url`,o),value:String(l.url??l.href??``),onCommit:e=>b({url:e,href:void 0}),disabled:s,mono:!0}),(0,Y.jsx)(W,{label:J(`engine.inspector.appNav.urlTarget`,o),value:String(l.target??`_self`),options:[{value:`_self`,label:J(`engine.inspector.appNav.urlTargetSelf`,o)},{value:`_blank`,label:J(`engine.inspector.appNav.urlTargetBlank`,o)}],onCommit:e=>b({target:e}),disabled:s})]})),T&&(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 px-2 py-1.5`,"data-testid":`nav-target-preview`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:J(`engine.inspector.appNav.preview`,o)}),(0,Y.jsx)(`div`,{className:`break-all font-mono text-[11px]`,children:T})]})]})}var ts=Ko;function ns(e){if(!e||!e.startsWith(`nav:`))return null;let t=e.slice(4);return t.length>0?t:null}function rs(e){return`nav:${e}`}var is=`surface`;function as(e){return`${e.type}:${e.name}`}function os(e){if(!e)return null;let t=e.indexOf(`:`);if(t<=0)return null;let n=e.slice(0,t),r=e.slice(t+1);return n&&r?{type:n,name:r}:null}function ss(e,t){let n=(e,r)=>{for(let i=0;i<e.length;i++){let a=e[i];if(!a||typeof a!=`object`)continue;let o=`${r}[${i}]`;if(a.id===t){let e=a.label??a.title??a.name;return{selectionId:o,label:typeof e==`string`?e:void 0}}if(Array.isArray(a.children)){let e=n(a.children,`${o}.children`);if(e)return e}}return null};for(let t of ts){let r=e[t];if(!Array.isArray(r))continue;let i=n(r,t);if(i)return i}return null}function cs(e,t){let n=t.split(`.`),r;for(let t=0;t<n.length;t++){let i=/^([a-zA-Z_]\w*)\[(\d+)\]$/.exec(n[t]);if(!i)return null;let a=i[1],o=Number(i[2]),s=t===0?e[a]:r?.[a];if(!Array.isArray(s)||(r=s[o],!r||typeof r!=`object`))return null}return typeof r?.id==`string`&&r.id?r.id:null}var ls={unchanged:{badge:`bg-muted text-muted-foreground border border-border`,row:``},modified:{badge:`bg-amber-100 text-amber-900 border border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-800`,row:`bg-amber-50/50 dark:bg-amber-950/20`},added:{badge:`bg-emerald-100 text-emerald-900 border border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-800`,row:`bg-emerald-50/50 dark:bg-emerald-950/20`},removed:{badge:`bg-rose-100 text-rose-900 border border-rose-300 dark:bg-rose-950/60 dark:text-rose-200 dark:border-rose-800`,row:`bg-rose-50/50 dark:bg-rose-950/20`}};function us(e,t){let n=ds(e)?e:{},r=ds(t)?t:{},i=new Set([...Object.keys(n),...Object.keys(r)]),a=[];for(let e of i){let t=e in n,i=e in r,o=n[e],s=r[e],c;c=t&&!i?`removed`:!t&&i?`added`:fs(o)===fs(s)?`unchanged`:`modified`,a.push({key:e,status:c,codeValue:o,effectiveValue:s})}let o={modified:0,added:1,removed:2,unchanged:3};return a.sort((e,t)=>o[e.status]===o[t.status]?e.key.localeCompare(t.key):o[e.status]-o[t.status]),a}function ds(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function fs(e){try{return JSON.stringify(e,(e,t)=>ds(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function ps(e){if(e===void 0)return`—`;if(e===null)return`null`;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{return JSON.stringify(e)}catch{return String(e)}}function ms(e,t){if(e==null)return 0;let n=0;for(let r of us(e,t))r.status!==`unchanged`&&(n+=1);return n}function hs({layered:e,loading:t,locale:n}){if(t)return(0,Y.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:J(`engine.edit.loading`,n)});if(!e)return(0,Y.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:J(`engine.layers.diff.noBaseline`,n)});let r=e.overlay!=null;return(0,Y.jsxs)(fn,{defaultValue:`diff`,className:`w-full`,children:[(0,Y.jsxs)(Sr,{className:`grid grid-cols-4 w-fit`,children:[(0,Y.jsx)(hn,{value:`diff`,children:J(`engine.layers.diff`,n)}),(0,Y.jsxs)(hn,{value:`code`,children:[J(`engine.layers.code`,n),(0,Y.jsx)(R,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`artifact`})]}),(0,Y.jsxs)(hn,{value:`overlay`,children:[J(`engine.layers.overlay`,n),r?(0,Y.jsx)(R,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??`set`}):(0,Y.jsx)(R,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:`none`})]}),(0,Y.jsxs)(hn,{value:`effective`,children:[J(`engine.layers.effective`,n),(0,Y.jsx)(R,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:`merged`})]})]}),(0,Y.jsx)(Hn,{value:`diff`,className:`mt-3`,children:(0,Y.jsx)(gs,{code:e.code,effective:e.effective,locale:n})}),(0,Y.jsx)(Hn,{value:`code`,className:`mt-3`,children:(0,Y.jsx)(vs,{payload:e.code,emptyHint:J(`engine.layers.diff.noBaseline`,n)})}),(0,Y.jsx)(Hn,{value:`overlay`,className:`mt-3`,children:(0,Y.jsx)(vs,{payload:e.overlay,emptyHint:J(`engine.layers.diff.noChanges`,n)})}),(0,Y.jsx)(Hn,{value:`effective`,className:`mt-3`,children:(0,Y.jsx)(vs,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function gs({code:e,effective:t,locale:n}){let[r,i]=X.useState(!1);if(e==null)return(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:J(`engine.layers.diff.noBaseline`,n)});let a=X.useMemo(()=>us(e,t),[e,t]),o=X.useMemo(()=>a.reduce((e,t)=>(e[t.status]+=1,e),{unchanged:0,modified:0,added:0,removed:0}),[a]),s=r?a:a.filter(e=>e.status!==`unchanged`),c=o.modified>0||o.added>0||o.removed>0;return(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:q(`engine.layers.diff.summary`,n,{modified:o.modified,added:o.added,removed:o.removed})}),(0,Y.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground cursor-pointer select-none`,children:[(0,Y.jsx)(Er,{checked:r,onCheckedChange:i,"aria-label":J(`engine.layers.diff.showUnchanged`,n)}),J(`engine.layers.diff.showUnchanged`,n),(0,Y.jsx)(R,{variant:`outline`,className:`ml-1 text-[10px]`,children:o.unchanged})]})]}),!c&&!r?(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:J(`engine.layers.diff.noChanges`,n)}):(0,Y.jsxs)(`div`,{className:`rounded border overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] bg-muted/50 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:J(`engine.layers.diff.field`,n)}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:J(`engine.layers.diff.code`,n)}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:J(`engine.layers.diff.effective`,n)}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:J(`engine.layers.diff.status`,n)})]}),(0,Y.jsx)(`div`,{className:`divide-y`,children:s.map(e=>{let t=ls[e.status];return(0,Y.jsxs)(`div`,{className:B(`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] text-xs`,t.row),children:[(0,Y.jsx)(`div`,{className:`px-3 py-2 font-mono text-foreground truncate`,title:e.key,children:e.key}),(0,Y.jsx)(_s,{value:e.codeValue,muted:e.status===`added`}),(0,Y.jsx)(_s,{value:e.effectiveValue,muted:e.status===`removed`}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:(0,Y.jsx)(`span`,{className:B(`inline-flex items-center rounded px-1.5 py-0.5 text-[10px] font-medium`,t.badge),children:J(`engine.layers.diff.${e.status}`,n)})})]},e.key)})})]})]})}function _s({value:e,muted:t}){let n=ps(e);return(0,Y.jsx)(`div`,{className:B(`px-3 py-2 font-mono break-all`,t||e===void 0?`text-muted-foreground italic`:`text-foreground`),title:n.length>200?n:void 0,children:n.length>200?`${n.slice(0,200)}…`:n})}function vs({payload:e,emptyHint:t}){if(e==null)return(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:t});let n;try{n=JSON.stringify(e,null,2)}catch{n=String(e)}return(0,Y.jsx)(`pre`,{className:`rounded border bg-muted/30 p-3 text-xs font-mono overflow-auto max-h-[420px]`,children:n})}var ys={modified:`bg-amber-100 text-amber-900 border border-amber-300 dark:bg-amber-950/60 dark:text-amber-200 dark:border-amber-800`,added:`bg-emerald-100 text-emerald-900 border border-emerald-300 dark:bg-emerald-950/60 dark:text-emerald-200 dark:border-emerald-800`,removed:`bg-rose-100 text-rose-900 border border-rose-300 dark:bg-rose-950/60 dark:text-rose-200 dark:border-rose-800`},bs={modified:`bg-amber-50/50 dark:bg-amber-950/20`,added:`bg-emerald-50/50 dark:bg-emerald-950/20`,removed:`bg-rose-50/50 dark:bg-rose-950/20`};function xs(e,t){return J(e===`added`?`designer.canvas.diffAdded`:e===`removed`?`designer.canvas.diffRemoved`:`designer.canvas.diffChanged`,t)}function Ss(e){if(e===void 0)return`—`;if(e===null)return`null`;if(typeof e==`string`)return e.length>200?`${e.slice(0,200)}…`:e;if(typeof e==`number`||typeof e==`boolean`)return String(e);try{let t=JSON.stringify(e);return t.length>200?`${t.slice(0,200)}…`:t}catch{return String(e)}}function Cs(e,t){let n=0;for(let r of us(e,t))r.status!==`unchanged`&&(n+=1);return n}function ws({published:e,draft:t,locale:n,className:r}){let i=X.useMemo(()=>us(e,t).filter(e=>e.status!==`unchanged`),[e,t]);return i.length===0?(0,Y.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground ${r??``}`,children:J(`designer.draftReview.empty`,n)}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-1.5 ${r??``}`,"data-testid":`draft-review-panel`,children:i.map(e=>{let t=e.status;return(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2 rounded-md px-2.5 py-1.5 text-xs ${bs[t]}`,children:[(0,Y.jsx)(`span`,{className:`inline-flex shrink-0 items-center rounded px-1.5 py-px text-[10px] font-medium uppercase tracking-wide ${ys[t]}`,children:xs(t,n)}),(0,Y.jsx)(`code`,{className:`font-mono font-medium text-foreground`,children:e.key}),t===`added`?(0,Y.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:Ss(e.effectiveValue)}):t===`removed`?(0,Y.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:Ss(e.codeValue)}):(0,Y.jsxs)(`span`,{className:`inline-flex items-baseline gap-1.5 text-muted-foreground`,children:[(0,Y.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:Ss(e.codeValue)}),(0,Y.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),(0,Y.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:Ss(e.effectiveValue)})]})]},e.key)})})}function Ts(e){if(typeof e!=`string`)return``;let t=e.normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,`_`).replace(/^_+|_+$/g,``);return/^\d/.test(t)&&(t=`n_${t}`),t.length>64&&(t=t.slice(0,64).replace(/_+$/g,``)),t}function Es(e){if(typeof e!=`string`)return``;let t=e.trim();return t?!/[A-Za-z]/.test(t)||/(s|ses|xes|zes|ches|shes|ies)$/i.test(t)?t:/[^aeiou]y$/i.test(t)?t.replace(/y$/i,`ies`):/(s|x|z|ch|sh)$/i.test(t)?`${t}es`:`${t}s`:``}function Ds(e){return typeof e==`string`?e.replace(/[_-]+/g,` `).split(/\s+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(` `):``}function Os(e){if(typeof e!=`string`)return``;let t=e.trim().match(/^[^\s_-]+/);return t?t[0]:``}function ks(e,t){let n=typeof t==`string`?t:t==null?``:String(t);switch(e){case`slugify`:return Ts(n);case`plural-en`:return Es(n);case`titlecase`:return Ds(n);case`first-token`:return Os(n);default:return n}}function As(e){let{rules:t,draft:n,onPatch:r,enabled:i=!0}=e,a=(0,X.useRef)(new Set),o=(0,X.useRef)({}),s=(0,X.useCallback)(e=>{a.current.add(e)},[]);return(0,X.useEffect)(()=>{if(!i||!t||t.length===0)return;let e={},s=o.current,c={};for(let r of t){let t=n[r.from];if(c[r.from]=t,Object.is(s[r.from],t)||r.untilUserEdits!==!1&&a.current.has(r.to)||r.to in e)continue;let i=ks(r.transform,t);n[r.to]!==i&&(e[r.to]=i)}o.current={...s,...c},Object.keys(e).length>0&&r(e)},[n,i]),{markTouched:s,touched:a.current}}function js(e,t){let n=e?Object.keys(e):[],r=[],i=e=>{!r.includes(e)&&n.includes(e)&&r.push(e)};for(let e of n)t?.includes(e)&&i(e);for(let e of[`label`,`pluralLabel`,`name`,`description`])i(e);return r}function Ms({type:e,name:t,parentItem:n,onOpen:r}){let a=ti(),o=i(),s=X.useMemo(()=>Oo(e),[e]),[c,l]=X.useState([]),[u,d]=X.useState(``),[f,p]=X.useState({});if(X.useEffect(()=>{if(s.length===0){l([]);return}let e=!1,r=[...s].sort((e,t)=>(e.anchor.order??999)-(t.anchor.order??999)).map(e=>{if(e.anchor.source===`embedded`){let t=e.anchor.extract&&n?e.anchor.extract(n):[];return{childType:e.type,anchor:e.anchor,loading:!1,error:null,items:t.map(Ns)}}return{childType:e.type,anchor:e.anchor,loading:!0,error:null,items:[]}});return l(r),Promise.all(r.map(async n=>{if(n.anchor.source===`embedded`)return n;try{let r=await a.list(n.childType);if(e)return n;let i=n.anchor.match??(()=>!1),o=r.filter(e=>i(e,t)).map(e=>Ns(e));return{...n,loading:!1,items:o}}catch(t){return e?n:{...n,loading:!1,error:t instanceof Error?t.message:String(t)}}})).then(t=>{e||l(t)}),()=>{e=!0}},[a,e,t,s,n]),s.length===0)return(0,Y.jsxs)(jt,{children:[(0,Y.jsx)(Fe,{children:`No related metadata`}),(0,Y.jsxs)(F,{children:[`No metadata types are configured to anchor at `,(0,Y.jsx)(`code`,{children:e}),`. You can register one via`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`registerMetadataResource`}),`.`]})]});let m=c.reduce((e,t)=>e+t.items.length,0),h=c.some(e=>e.loading),g=u.trim().toLowerCase();return(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,Y.jsx)(Xe,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(V,{placeholder:`Search related…`,value:u,onChange:e=>d(e.target.value),className:`pl-8 h-8 text-sm`})]}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:h?`Scanning…`:`${m} item${m===1?``:`s`}`})]}),c.map(n=>{let i=g?n.items.filter(e=>e.name.toLowerCase().includes(g)||(e.label??``).toLowerCase().includes(g)):n.items,a=f[n.childType]??!1;return!(!g||i.length>0)&&!n.loading?null:(0,Y.jsxs)(`div`,{className:`border rounded-lg overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`w-full flex items-center gap-2 px-3 py-2 bg-muted/40`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`flex items-center gap-2 flex-1 text-left hover:opacity-80`,onClick:()=>p(e=>({...e,[n.childType]:!a})),children:[(0,Y.jsx)(N,{className:B(`h-4 w-4 text-muted-foreground transition-transform`,!a&&`rotate-90`)}),(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:n.anchor.groupLabel??n.childType}),(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px]`,children:n.loading?`…`:i.length})]}),(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,className:`h-7 px-2`,onClick:()=>{if(n.anchor.source===`embedded`){if(typeof window<`u`){let e=new URL(window.location.href);e.searchParams.set(`tab`,`form`),e.searchParams.delete(`open`),window.location.assign(e.toString())}return}o(`../../${encodeURIComponent(n.childType)}/_new?anchor=${encodeURIComponent(`${e}:${t}`)}`)},title:n.anchor.source===`embedded`?`Edit in Form tab`:`New ${n.childType}`,children:(0,Y.jsx)(L,{className:`h-3.5 w-3.5`})})]}),!a&&(0,Y.jsxs)(`div`,{children:[n.loading&&(0,Y.jsxs)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}),`Loading `,n.childType,`…`]}),!n.loading&&n.error&&(0,Y.jsxs)(`div`,{className:`px-3 py-3 text-xs text-destructive`,children:[`Failed: `,n.error]}),!n.loading&&!n.error&&i.length===0&&(0,Y.jsx)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground`,children:g?`No matches.`:`Nothing here yet.`}),!n.loading&&!n.error&&i.length>0&&(0,Y.jsxs)(`table`,{className:`w-full text-sm border-t`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5 w-[45%]`,children:`Name`}),(0,Y.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5`,children:`Label`}),(0,Y.jsx)(`th`,{className:`w-8`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:i.map((i,a)=>(0,Y.jsxs)(`tr`,{role:`button`,tabIndex:0,onClick:()=>r(n.anchor.source===`embedded`?{kind:`embedded`,parentType:e,parentName:t,groupLabel:n.anchor.groupLabel??n.childType,itemName:i.name,raw:i.raw,editAs:n.anchor.editAs,embeddedPath:n.anchor.embeddedPath}:{kind:`metadata`,type:n.childType,name:i.name}),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&e.currentTarget.click()},className:`hover:bg-accent/50 cursor-pointer`,children:[(0,Y.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-xs truncate max-w-0`,children:i.name}),(0,Y.jsx)(`td`,{className:`px-3 py-1.5 text-xs text-muted-foreground truncate max-w-0`,children:i.label&&i.label!==i.name?i.label:``}),(0,Y.jsx)(`td`,{className:`px-3 py-1.5 text-right`,children:(0,Y.jsx)(Re,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function Ns(e){return{name:Ps(e,[`name`,`id`,`key`])??`(unnamed)`,label:Ps(e,[`label`,`title`,`displayName`]),description:Ps(e,[`description`,`summary`]),raw:e}}function Ps(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function Fs({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=X.useMemo(()=>Vi(),[]),c=ti(),{entries:l}=$r(c),u=i?l.find(e=>e.type===i):void 0,d=!u?.schema&&i?Ls[i]:void 0,f=u?.schema??d?.schema,p=u?.form??d?.form,[m,h]=X.useState(a),[g,_]=X.useState(!1),[v,y]=X.useState(null),[b,x]=X.useState([]),[S,C]=X.useState(null);X.useEffect(()=>{h(a),y(null),x([]),C(null)},[a,r,e,t]);let w=u!=null&&!u.allowOrgOverride&&!u.allowRuntimeCreate;async function T(){if(!n){y(J(`engine.embedded.saveNoPath`,s));return}_(!0),y(null),x([]);try{let i=await c.layered(e,t),a=Is(i.effective??i.code??{},n,r,m);await c.save(e,t,a),C(Date.now()),o?.(m)}catch(e){if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],i=(Array.isArray(t)?t:[]).map(e=>{let t=Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),i=`${n}.${r}.`;return{path:t.startsWith(i)?t.slice(i.length):t,message:ii(String(e.message??`Invalid`),s)}});x(i),y(i.length===1?J(`engine.validation.failedOne`,s):q(`engine.validation.failed`,s,{count:i.length}))}else y(e?.message??String(e))}finally{_(!1)}}return f?(0,Y.jsxs)(`div`,{className:`p-4 space-y-4`,children:[v&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:v}),S!=null&&!v&&(0,Y.jsx)(`div`,{className:`text-sm text-emerald-700 border border-emerald-300 bg-emerald-50 rounded p-2`,children:J(`engine.embedded.saved`,s)}),w&&(0,Y.jsx)(`div`,{className:`text-xs text-amber-800 border border-amber-300 bg-amber-50 rounded p-2`,children:J(`engine.embedded.readOnlyParent`,s)}),(0,Y.jsx)(Li,{schema:f,form:p,value:m,onChange:h,issues:b}),(0,Y.jsx)(`div`,{className:`flex justify-end gap-2 pt-2 border-t`,children:(0,Y.jsxs)(H,{onClick:T,disabled:g||!n,children:[g?(0,Y.jsx)(U,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(Pn,{className:`h-4 w-4 mr-1`}),q(`engine.embedded.saveIntoParent`,s,{parentType:e})]})}),!n&&(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground border rounded p-3`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:J(`engine.embedded.readOnly`,s)}),(0,Y.jsx)(`div`,{children:J(`engine.embedded.noPathHint`,s)})]})]}):(0,Y.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:q(`engine.embedded.noSchema`,s,{type:i??`this item`,target:`${e}/${t}.${n}.${r}`})}),(0,Y.jsx)(`textarea`,{className:`w-full h-[60vh] font-mono text-xs border rounded p-3 bg-muted/30`,value:JSON.stringify(m,null,2),onChange:e=>{try{h(JSON.parse(e.target.value)),y(null)}catch(e){y(`${J(`engine.form.invalidJson`,s)}: ${e.message}`)}}}),v&&(0,Y.jsxs)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-2 bg-destructive/5`,children:[(0,Y.jsx)(I,{className:`h-4 w-4 inline mr-1`}),` `,v]}),(0,Y.jsx)(`div`,{className:`flex justify-end`,children:(0,Y.jsxs)(H,{onClick:T,disabled:g||!n,children:[g?(0,Y.jsx)(U,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(Pn,{className:`h-4 w-4 mr-1`}),q(`engine.embedded.saveIntoParent`,s,{parentType:`parent`})]})})]})}function Is(e,t,n,r){let i=t.split(`.`),a=structuredClone(e),o=a;for(let e=0;e<i.length-1;e++)o[i[e]]??(o[i[e]]={}),o=o[i[e]];let s=i[i.length-1],c=o[s];if(Array.isArray(c)){let e=c.findIndex(e=>e&&typeof e==`object`&&e.name===n);e>=0?c[e]=r:c.push(r)}else if(c&&typeof c==`object`){let{name:e,...t}=r;c[n]=t}else{let{name:e,...t}=r;o[s]={[n]:t}}return a}var Ls={index:{schema:{type:`object`,required:[`fields`],properties:{name:{type:`string`,title:`Name`,description:`Synthesised from columns if omitted (e.g. idx_email).`},fields:{type:`array`,title:`Fields`,description:`Columns to index, in order.`,items:{type:`string`}},type:{type:`string`,title:`Algorithm`,enum:[`btree`,`hash`,`gin`,`gist`,`brin`],default:`btree`},unique:{type:`boolean`,title:`Unique`,description:`Enforce uniqueness across the indexed columns.`},where:{type:`string`,title:`Partial-index predicate`,description:`Optional WHERE clause for a partial index.`}}}}};function Rs({target:e,onClose:t,parentContext:n}){let r=i(),a=e?.kind===`metadata`,o=e?.kind===`embedded`,s=a?e.type:o?e.groupLabel:``,c=a?e.name:o?e.itemName:``;return(0,Y.jsx)(P,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,Y.jsxs)(At,{side:`right`,className:B(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,Y.jsxs)(Et,{className:`px-4 py-3 border-b space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(R,{variant:`outline`,className:`font-mono text-[10px]`,children:s}),(0,Y.jsx)(It,{className:`font-mono text-base truncate`,children:c}),(0,Y.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:a&&(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:()=>{r(`../../${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`),t()},title:`Open in full page`,children:[(0,Y.jsx)(Re,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,Y.jsxs)(Ae,{className:`text-xs`,children:[o?`Embedded in `:`Related to `,(0,Y.jsxs)(`span`,{className:`font-mono`,children:[n.type,`/`,n.name]})]})]}),(0,Y.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:[a&&(0,Y.jsx)(zc,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),o&&(0,Y.jsx)(Fs,{parentType:e.parentType,parentName:e.parentName,embeddedPath:e.embeddedPath,itemName:e.itemName,editAs:e.editAs,initialRaw:e.raw},`${e.parentType}/${e.parentName}/${e.embeddedPath}/${e.itemName}`)]})]})})}function zs({type:e,name:t}){let n=s(),r=e??n.type??``,a=t??n.name??``,o=i(),c=ti(),{entries:l}=$r(c),u=l.find(e=>e.type===r),[d,f]=X.useState(0),[p,m]=X.useState(0);return(0,Y.jsx)(bo,{entry:u??{type:r,label:r},itemName:a,subtitle:`Version history`,stats:[{label:`Events`,value:p}],actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:()=>o(`../${encodeURIComponent(a)}`),children:[(0,Y.jsx)(se,{className:`h-4 w-4 mr-1`}),`Back to item`]}),(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>f(e=>e+1),children:(0,Y.jsx)(Dt,{className:`h-4 w-4`})})]}),children:(0,Y.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,Y.jsx)(Bs,{type:r,name:a,refreshKey:d,onCount:m,client:c,onRollback:()=>f(e=>e+1)})})})}function Bs({type:e,name:t,refreshKey:n=0,onCount:r,client:i,onRollback:a,rollbackConfirm:o,rollbackLabel:s}){let[c,l]=X.useState([]),[u,d]=X.useState(!0),[f,p]=X.useState(null),[m,h]=X.useState(null),[g,_]=X.useState(null),[v,y]=X.useState(0);X.useEffect(()=>{let n=!1;return d(!0),p(null),(async()=>{try{let a=await i.history(e,t,{limit:100});if(n)return;let o=[...Array.isArray(a)?a:Array.isArray(a?.events)?a.events:[]].sort((e,t)=>(t.seq??0)-(e.seq??0));l(o),r?.(o.length),d(!1)}catch(e){n||(p(e?.message??String(e)),d(!1))}})(),()=>{n=!0}},[i,e,t,n,v]);async function b(n){let r=o?o(n):`Restore version ${n}? This writes the historical body back as the current overlay.`;if(confirm(r)){_(n),p(null);try{await i.rollback(e,t,n),a?.(n),y(e=>e+1)}catch(e){p(e?.message??String(e))}finally{_(null)}}}return(0,Y.jsxs)(Y.Fragment,{children:[u&&(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Loading history…`]}),f&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:f}),!u&&!f&&c.length===0&&(0,Y.jsxs)(jt,{children:[(0,Y.jsx)(Fe,{children:`No history yet`}),(0,Y.jsx)(F,{children:`This item has never been edited via an overlay. The first save will create the initial history record.`})]}),!u&&c.length>0&&(0,Y.jsx)(`ol`,{className:`space-y-2 relative pl-6 border-l`,children:c.map((e,t)=>{let n=m===t,r=e.op??e.kind,i=e.ts??e.at,o=!!a&&typeof e.version==`number`&&r!==`delete`&&r!==`tombstone`;return(0,Y.jsxs)(`li`,{className:`relative`,children:[(0,Y.jsx)(`span`,{className:`absolute -left-[27px] top-2 w-3 h-3 rounded-full bg-primary ring-4 ring-background`}),(0,Y.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>h(n?null:t),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&h(n?null:t)},className:`border rounded-lg p-3 hover:border-primary/50 cursor-pointer transition-colors`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,Y.jsxs)(R,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),typeof e.version==`number`&&(0,Y.jsxs)(R,{variant:`outline`,className:`text-[10px] font-mono`,children:[`v`,e.version]}),r&&(0,Y.jsx)(R,{className:`text-[10px] `+(r===`delete`||r===`tombstone`?`bg-red-100 text-red-800 hover:bg-red-100`:r===`create`?`bg-blue-100 text-blue-800 hover:bg-blue-100`:r===`publish`?`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`:r===`revert`?`bg-amber-100 text-amber-900 hover:bg-amber-100`:`bg-emerald-100 text-emerald-800 hover:bg-emerald-100`),children:String(r)}),e.actor&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`by`,` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:String(e.actor)})]}),i&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:Vs(i)}),o&&(0,Y.jsx)(H,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0`,title:s??`Rollback to this version`,disabled:g!==null,onClick:t=>{t.stopPropagation(),b(e.version)},children:g===e.version?(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Me,{className:`h-3.5 w-3.5`})})]}),n&&(0,Y.jsx)(`pre`,{className:`mt-2 text-xs font-mono bg-muted/30 rounded p-2 overflow-auto max-h-[280px]`,children:Hs(e)})]})]},`${e.seq??t}-${t}`)})})]})}function Vs(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function Hs(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Us(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function Ws(e){let t={allowed:{label:`allowed`,cls:`bg-emerald-50 text-emerald-700 border-emerald-200`,Icon:mt},denied:{label:`denied`,cls:`bg-rose-50 text-rose-700 border-rose-200`,Icon:Pr},forced:{label:`forced`,cls:`bg-amber-50 text-amber-700 border-amber-200`,Icon:ce}},n=t[e]??t.allowed;return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide ${n.cls}`,children:[(0,Y.jsx)(n.Icon,{className:`h-3 w-3`}),n.label]})}function Gs({type:e,name:t,client:n,locale:r=`en-US`}){let[i,a]=X.useState(!1),[o,s]=X.useState(null),[c,l]=X.useState(null),u=X.useCallback(async()=>{a(!0),s(null);try{let r=await n.audit(e,t,{limit:100});l(r.events??[])}catch(e){s(String(e?.message??e)),l([])}finally{a(!1)}},[n,e,t]);return X.useEffect(()=>{u()},[u]),(0,Y.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-1 pb-2`,children:[(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[c?.length??0,` `,J(`engine.edit.auditCount`,r)]}),(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:()=>void u(),disabled:i,className:`h-7 gap-1 text-xs`,title:J(`engine.edit.refresh`,r),children:[i?(0,Y.jsx)(U,{className:`h-3 w-3 animate-spin`}):(0,Y.jsx)(Dt,{className:`h-3 w-3`}),J(`engine.edit.refresh`,r)]})]}),o&&(0,Y.jsx)(`div`,{className:`m-2 rounded border border-rose-200 bg-rose-50 p-2 text-xs text-rose-700`,children:o}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:i&&(!c||c.length===0)?(0,Y.jsxs)(`div`,{className:`flex h-32 items-center justify-center text-xs text-muted-foreground`,children:[(0,Y.jsx)(U,{className:`mr-2 h-3 w-3 animate-spin`}),J(`engine.edit.loading`,r)]}):!c||c.length===0?(0,Y.jsxs)(jt,{className:`py-10`,children:[(0,Y.jsx)(Fe,{children:J(`engine.edit.auditEmptyTitle`,r)}),(0,Y.jsx)(F,{children:J(`engine.edit.auditEmptyDescription`,r)})]}):(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{className:`sticky top-0 bg-muted/40 text-left text-[10px] uppercase tracking-wide text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColTime`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColActor`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColOperation`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColOutcome`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColLock`,r)}),(0,Y.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:J(`engine.edit.auditColNote`,r)})]})}),(0,Y.jsx)(`tbody`,{children:c.map(e=>(0,Y.jsxs)(`tr`,{className:`border-t border-border/50 align-top hover:bg-muted/20`,children:[(0,Y.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 font-mono text-[11px]`,children:Us(e.occurredAt)}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:e.actor}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px]`,children:e.operation})}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:Ws(e.outcome)}),(0,Y.jsx)(`td`,{className:`px-2 py-1.5`,children:e.lockState&&e.lockState!==`none`?(0,Y.jsxs)(`span`,{className:`font-mono text-[11px]`,children:[e.lockState,e.lockOverridden?` *`:``]}):(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,Y.jsx)(`td`,{className:`max-w-[28ch] truncate px-2 py-1.5 text-muted-foreground`,title:e.note??e.code,children:e.note??e.code})]},String(e.id)))})]})})]})}var Ks=new Map;function qs(e,t){Ks.set(e,t)}function Js(e){return Ks.get(e)}var Ys=new Map;function Xs(e,t){Ys.set(e,t)}function Zs(e){return Ys.get(e)}var Qs=new Map;function $s(e,t){Qs.set(e,t)}function ec(e){return Qs.get(e)}function tc(e,t=!1){let n=e.length,r=0,i=``,a=0,o=16,s=0,c=0,l=0,u=0,d=0;function f(t,n){let i=0,a=0;for(;i<t||!n;){let t=e.charCodeAt(r);if(t>=48&&t<=57)a=a*16+t-48;else if(t>=65&&t<=70)a=a*16+t-65+10;else if(t>=97&&t<=102)a=a*16+t-97+10;else break;r++,i++}return i<t&&(a=-1),a}function p(e){r=e,i=``,a=0,o=16,d=0}function m(){let t=r;if(e.charCodeAt(r)===48)r++;else for(r++;r<e.length&&ic(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&ic(e.charCodeAt(r)))for(r++;r<e.length&&ic(e.charCodeAt(r));)r++;else return d=3,e.substring(t,r);let n=r;if(r<e.length&&(e.charCodeAt(r)===69||e.charCodeAt(r)===101))if(r++,(r<e.length&&e.charCodeAt(r)===43||e.charCodeAt(r)===45)&&r++,r<e.length&&ic(e.charCodeAt(r))){for(r++;r<e.length&&ic(e.charCodeAt(r));)r++;n=r}else d=3;return e.substring(t,n)}function h(){let t=``,i=r;for(;;){if(r>=n){t+=e.substring(i,r),d=2;break}let a=e.charCodeAt(r);if(a===34){t+=e.substring(i,r),r++;break}if(a===92){if(t+=e.substring(i,r),r++,r>=n){d=2;break}switch(e.charCodeAt(r++)){case 34:t+=`"`;break;case 92:t+=`\\`;break;case 47:t+=`/`;break;case 98:t+=`\b`;break;case 102:t+=`\f`;break;case 110:t+=`
5
+ `;break;case 114:t+=`\r`;break;case 116:t+=` `;break;case 117:let e=f(4,!0);e>=0?t+=String.fromCharCode(e):d=4;break;default:d=5}i=r;continue}if(a>=0&&a<=31)if(rc(a)){t+=e.substring(i,r),d=2;break}else d=6;r++}return t}function g(){if(i=``,d=0,a=r,c=s,u=l,r>=n)return a=n,o=17;let t=e.charCodeAt(r);if(nc(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while(nc(t));return o=15}if(rc(t))return r++,i+=String.fromCharCode(t),t===13&&e.charCodeAt(r)===10&&(r++,i+=`
6
+ `),s++,l=r,o=14;switch(t){case 123:return r++,o=1;case 125:return r++,o=2;case 91:return r++,o=3;case 93:return r++,o=4;case 58:return r++,o=6;case 44:return r++,o=5;case 34:return r++,i=h(),o=10;case 47:let c=r-1;if(e.charCodeAt(r+1)===47){for(r+=2;r<n&&!rc(e.charCodeAt(r));)r++;return i=e.substring(c,r),o=12}if(e.charCodeAt(r+1)===42){r+=2;let t=n-1,a=!1;for(;r<t;){let t=e.charCodeAt(r);if(t===42&&e.charCodeAt(r+1)===47){r+=2,a=!0;break}r++,rc(t)&&(t===13&&e.charCodeAt(r)===10&&r++,s++,l=r)}return a||(r++,d=1),i=e.substring(c,r),o=13}return i+=String.fromCharCode(t),r++,o=16;case 45:if(i+=String.fromCharCode(t),r++,r===n||!ic(e.charCodeAt(r)))return o=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return i+=m(),o=11;default:for(;r<n&&_(t);)r++,t=e.charCodeAt(r);if(a!==r){switch(i=e.substring(a,r),i){case`true`:return o=8;case`false`:return o=9;case`null`:return o=7}return o=16}return i+=String.fromCharCode(t),r++,o=16}}function _(e){if(nc(e)||rc(e))return!1;switch(e){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}function v(){let e;do e=g();while(e>=12&&e<=15);return e}return{setPosition:p,getPosition:()=>r,scan:t?v:g,getToken:()=>o,getTokenValue:()=>i,getTokenOffset:()=>a,getTokenLength:()=>r-a,getTokenStartLine:()=>c,getTokenStartCharacter:()=>a-u,getTokenError:()=>d}}function nc(e){return e===32||e===9}function rc(e){return e===10||e===13}function ic(e){return e>=48&&e<=57}var ac;(function(e){e[e.lineFeed=10]=`lineFeed`,e[e.carriageReturn=13]=`carriageReturn`,e[e.space=32]=`space`,e[e._0=48]=`_0`,e[e._1=49]=`_1`,e[e._2=50]=`_2`,e[e._3=51]=`_3`,e[e._4=52]=`_4`,e[e._5=53]=`_5`,e[e._6=54]=`_6`,e[e._7=55]=`_7`,e[e._8=56]=`_8`,e[e._9=57]=`_9`,e[e.a=97]=`a`,e[e.b=98]=`b`,e[e.c=99]=`c`,e[e.d=100]=`d`,e[e.e=101]=`e`,e[e.f=102]=`f`,e[e.g=103]=`g`,e[e.h=104]=`h`,e[e.i=105]=`i`,e[e.j=106]=`j`,e[e.k=107]=`k`,e[e.l=108]=`l`,e[e.m=109]=`m`,e[e.n=110]=`n`,e[e.o=111]=`o`,e[e.p=112]=`p`,e[e.q=113]=`q`,e[e.r=114]=`r`,e[e.s=115]=`s`,e[e.t=116]=`t`,e[e.u=117]=`u`,e[e.v=118]=`v`,e[e.w=119]=`w`,e[e.x=120]=`x`,e[e.y=121]=`y`,e[e.z=122]=`z`,e[e.A=65]=`A`,e[e.B=66]=`B`,e[e.C=67]=`C`,e[e.D=68]=`D`,e[e.E=69]=`E`,e[e.F=70]=`F`,e[e.G=71]=`G`,e[e.H=72]=`H`,e[e.I=73]=`I`,e[e.J=74]=`J`,e[e.K=75]=`K`,e[e.L=76]=`L`,e[e.M=77]=`M`,e[e.N=78]=`N`,e[e.O=79]=`O`,e[e.P=80]=`P`,e[e.Q=81]=`Q`,e[e.R=82]=`R`,e[e.S=83]=`S`,e[e.T=84]=`T`,e[e.U=85]=`U`,e[e.V=86]=`V`,e[e.W=87]=`W`,e[e.X=88]=`X`,e[e.Y=89]=`Y`,e[e.Z=90]=`Z`,e[e.asterisk=42]=`asterisk`,e[e.backslash=92]=`backslash`,e[e.closeBrace=125]=`closeBrace`,e[e.closeBracket=93]=`closeBracket`,e[e.colon=58]=`colon`,e[e.comma=44]=`comma`,e[e.dot=46]=`dot`,e[e.doubleQuote=34]=`doubleQuote`,e[e.minus=45]=`minus`,e[e.openBrace=123]=`openBrace`,e[e.openBracket=91]=`openBracket`,e[e.plus=43]=`plus`,e[e.slash=47]=`slash`,e[e.formFeed=12]=`formFeed`,e[e.tab=9]=`tab`})(ac||={}),Array(20).fill(0).map((e,t)=>` `.repeat(t));var oc=200;Array(oc).fill(0).map((e,t)=>`
7
+ `+` `.repeat(t)),Array(oc).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(oc).fill(0).map((e,t)=>`\r
8
+ `+` `.repeat(t)),Array(oc).fill(0).map((e,t)=>`
9
+ `+` `.repeat(t)),Array(oc).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(oc).fill(0).map((e,t)=>`\r
10
+ `+` `.repeat(t));var sc;(function(e){e.DEFAULT={allowTrailingComma:!1}})(sc||={});function cc(e,t=[],n=sc.DEFAULT){let r={type:`array`,offset:-1,length:-1,children:[],parent:void 0};function i(e){r.type===`property`&&(r.length=e-r.offset,r=r.parent)}function a(e){return r.children.push(e),e}uc(e,{onObjectBegin:e=>{r=a({type:`object`,offset:e,length:-1,parent:r,children:[]})},onObjectProperty:(e,t,n)=>{r=a({type:`property`,offset:t,length:-1,parent:r,children:[]}),r.children.push({type:`string`,value:e,offset:t,length:n,parent:r})},onObjectEnd:(e,t)=>{i(e+t),r.length=e+t-r.offset,r=r.parent,i(e+t)},onArrayBegin:(e,t)=>{r=a({type:`array`,offset:e,length:-1,parent:r,children:[]})},onArrayEnd:(e,t)=>{r.length=e+t-r.offset,r=r.parent,i(e+t)},onLiteralValue:(e,t,n)=>{a({type:dc(e),offset:t,length:n,parent:r,value:e}),i(t+n)},onSeparator:(e,t,n)=>{r.type===`property`&&(e===`:`?r.colonOffset=t:e===`,`&&i(t))},onError:(e,n,r)=>{t.push({error:e,offset:n,length:r})}},n);let o=r.children[0];return o&&delete o.parent,o}function lc(e,t){if(!e)return;let n=e;for(let e of t)if(typeof e==`string`){if(n.type!==`object`||!Array.isArray(n.children))return;let t=!1;for(let r of n.children)if(Array.isArray(r.children)&&r.children[0].value===e&&r.children.length===2){n=r.children[1],t=!0;break}if(!t)return}else{let t=e;if(n.type!==`array`||t<0||!Array.isArray(n.children)||t>=n.children.length)return;n=n.children[t]}return n}function uc(e,t,n=sc.DEFAULT){let r=tc(e,!1),i=[],a=0;function o(e){return e?()=>a===0&&e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function s(e){return e?t=>a===0&&e(t,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter()):()=>!0}function c(e){return e?t=>a===0&&e(t,r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice()):()=>!0}function l(e){return e?()=>{a>0?a++:e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter(),()=>i.slice())===!1&&(a=1)}:()=>!0}function u(e){return e?()=>{a>0&&a--,a===0&&e(r.getTokenOffset(),r.getTokenLength(),r.getTokenStartLine(),r.getTokenStartCharacter())}:()=>!0}let d=l(t.onObjectBegin),f=c(t.onObjectProperty),p=u(t.onObjectEnd),m=l(t.onArrayBegin),h=u(t.onArrayEnd),g=c(t.onLiteralValue),_=s(t.onSeparator),v=o(t.onComment),y=s(t.onError),b=n&&n.disallowComments,x=n&&n.allowTrailingComma;function S(){for(;;){let e=r.scan();switch(r.getTokenError()){case 4:C(14);break;case 5:C(15);break;case 3:C(13);break;case 1:b||C(11);break;case 2:C(12);break;case 6:C(16);break}switch(e){case 12:case 13:b?C(10):v();break;case 16:C(1);break;case 15:case 14:break;default:return e}}}function C(e,t=[],n=[]){if(y(e),t.length+n.length>0){let e=r.getToken();for(;e!==17;){if(t.indexOf(e)!==-1){S();break}else if(n.indexOf(e)!==-1)break;e=S()}}}function w(e){let t=r.getTokenValue();return e?g(t):(f(t),i.push(t)),S(),!0}function T(){switch(r.getToken()){case 11:let e=r.getTokenValue(),t=Number(e);isNaN(t)&&(C(2),t=0),g(t);break;case 7:g(null);break;case 8:g(!0);break;case 9:g(!1);break;default:return!1}return S(),!0}function E(){return r.getToken()===10?(w(!1),r.getToken()===6?(_(`:`),S(),k()||C(4,[],[2,5])):C(5,[],[2,5]),i.pop(),!0):(C(3,[],[2,5]),!1)}function D(){d(),S();let e=!1;for(;r.getToken()!==2&&r.getToken()!==17;){if(r.getToken()===5){if(e||C(4,[],[]),_(`,`),S(),r.getToken()===2&&x)break}else e&&C(6,[],[]);E()||C(4,[],[2,5]),e=!0}return p(),r.getToken()===2?S():C(7,[2],[]),!0}function O(){m(),S();let e=!0,t=!1;for(;r.getToken()!==4&&r.getToken()!==17;){if(r.getToken()===5){if(t||C(4,[],[]),_(`,`),S(),r.getToken()===4&&x)break}else t&&C(6,[],[]);e?(i.push(0),e=!1):i[i.length-1]++,k()||C(4,[],[4,5]),t=!0}return h(),e||i.pop(),r.getToken()===4?S():C(8,[4],[]),!0}function k(){switch(r.getToken()){case 3:return O();case 1:return D();case 10:return w(!0);default:return T()}}return S(),r.getToken()===17?n.allowEmptyContent?!0:(C(4,[],[]),!1):k()?(r.getToken()!==17&&C(9,[],[]),!0):(C(4,[],[]),!1)}function dc(e){switch(typeof e){case`boolean`:return`boolean`;case`number`:return`number`;case`string`:return`string`;case`object`:return e?Array.isArray(e)?`array`:`object`:`null`;default:return`null`}}var fc;(function(e){e[e.None=0]=`None`,e[e.UnexpectedEndOfComment=1]=`UnexpectedEndOfComment`,e[e.UnexpectedEndOfString=2]=`UnexpectedEndOfString`,e[e.UnexpectedEndOfNumber=3]=`UnexpectedEndOfNumber`,e[e.InvalidUnicode=4]=`InvalidUnicode`,e[e.InvalidEscapeCharacter=5]=`InvalidEscapeCharacter`,e[e.InvalidCharacter=6]=`InvalidCharacter`})(fc||={});var pc;(function(e){e[e.OpenBraceToken=1]=`OpenBraceToken`,e[e.CloseBraceToken=2]=`CloseBraceToken`,e[e.OpenBracketToken=3]=`OpenBracketToken`,e[e.CloseBracketToken=4]=`CloseBracketToken`,e[e.CommaToken=5]=`CommaToken`,e[e.ColonToken=6]=`ColonToken`,e[e.NullKeyword=7]=`NullKeyword`,e[e.TrueKeyword=8]=`TrueKeyword`,e[e.FalseKeyword=9]=`FalseKeyword`,e[e.StringLiteral=10]=`StringLiteral`,e[e.NumericLiteral=11]=`NumericLiteral`,e[e.LineCommentTrivia=12]=`LineCommentTrivia`,e[e.BlockCommentTrivia=13]=`BlockCommentTrivia`,e[e.LineBreakTrivia=14]=`LineBreakTrivia`,e[e.Trivia=15]=`Trivia`,e[e.Unknown=16]=`Unknown`,e[e.EOF=17]=`EOF`})(pc||={});var mc=cc,hc=lc,gc;(function(e){e[e.InvalidSymbol=1]=`InvalidSymbol`,e[e.InvalidNumberFormat=2]=`InvalidNumberFormat`,e[e.PropertyNameExpected=3]=`PropertyNameExpected`,e[e.ValueExpected=4]=`ValueExpected`,e[e.ColonExpected=5]=`ColonExpected`,e[e.CommaExpected=6]=`CommaExpected`,e[e.CloseBraceExpected=7]=`CloseBraceExpected`,e[e.CloseBracketExpected=8]=`CloseBracketExpected`,e[e.EndOfFileExpected=9]=`EndOfFileExpected`,e[e.InvalidCommentToken=10]=`InvalidCommentToken`,e[e.UnexpectedEndOfComment=11]=`UnexpectedEndOfComment`,e[e.UnexpectedEndOfString=12]=`UnexpectedEndOfString`,e[e.UnexpectedEndOfNumber=13]=`UnexpectedEndOfNumber`,e[e.InvalidUnicode=14]=`InvalidUnicode`,e[e.InvalidEscapeCharacter=15]=`InvalidEscapeCharacter`,e[e.InvalidCharacter=16]=`InvalidCharacter`})(gc||={});function _c(e=4e3){let t=X.useRef(null),[n,r]=X.useState(!1);return X.useEffect(()=>{if(n)return;let e=!1,t=ra?.init?.();return t&&typeof t.catch==`function`&&t.catch(()=>{e||r(!0)}),()=>{e=!0}},[n]),X.useEffect(()=>{if(n)return;let i=setTimeout(()=>{let e=t.current;(!e||!e.querySelector(`.view-line`))&&r(!0)},e);return()=>clearTimeout(i)},[n,e]),[n,t]}var vc=X.lazy(async()=>({default:(await a(()=>import(`./dist-YwlXXOlT.js`).then(e=>e.n),[],import.meta.url)).default}));function yc(e){try{return JSON.stringify(e??{},null,2)}catch{return`{}`}}function bc(e){return e?e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e}):[]}function xc({value:e,onChange:t,readOnly:n,issues:r,height:i=`60vh`,fallbackDelayMs:a=4e3}){let o=X.useMemo(()=>Vi(),[]),[s,c]=X.useState(()=>yc(e)),[l,u]=X.useState(null),d=X.useRef(s),f=X.useRef(null),p=X.useRef(null),[m,h]=_c(a),[g,_]=X.useState(()=>typeof document>`u`?`light`:document.documentElement.classList.contains(`dark`)?`vs-dark`:`light`);X.useEffect(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=new MutationObserver(()=>_(e.classList.contains(`dark`)?`vs-dark`:`light`));return t.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let v=X.useCallback(()=>{let e=f.current,t=p.current;if(!e||!t)return;let n=e.getModel();if(!n)return;if(!r||r.length===0){t.editor.setModelMarkers(n,`objectui-diagnostics`,[]);return}let i;try{i=mc(s)}catch{i=void 0}let a=r.map(e=>{let r=bc(e.path),a=1,o=1,s=1,c=2,l=i?hc(i,r):void 0;if(l){let e=n.getPositionAt(l.offset),t=n.getPositionAt(l.offset+l.length);a=e.lineNumber,o=e.column,s=t.lineNumber,c=t.column}return{severity:e.severity===`warning`?t.MarkerSeverity.Warning:t.MarkerSeverity.Error,message:e.path?`${e.path}: ${e.message}`:e.message,startLineNumber:a,startColumn:o,endLineNumber:s,endColumn:c,source:`metadata`}});t.editor.setModelMarkers(n,`objectui-diagnostics`,a)},[r,s]);X.useEffect(()=>{v()},[v]),X.useEffect(()=>{let t=yc(e);t!==d.current&&(c(t),d.current=t,u(null))},[e]);let y=e=>{let n=e??``;c(n);try{let e=JSON.parse(n);e&&typeof e==`object`&&!Array.isArray(e)?(u(null),d.current=n,t(e)):u(J(`engine.form.rootJsonObject`,o))}catch(e){u(e?.message??J(`engine.form.invalidJson`,o))}};return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`div`,{ref:h,"data-testid":`source-editor`,className:`border rounded overflow-hidden bg-background`,style:{height:typeof i==`number`?`${i}px`:i},children:m?(0,Y.jsx)(`textarea`,{value:s,onChange:e=>y(e.target.value),readOnly:n,spellCheck:!1,"aria-label":`JSON source`,className:`w-full h-full resize-none bg-background p-3 font-mono text-xs leading-relaxed outline-none`}):(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsx)(pt,{className:`w-full h-full`}),children:(0,Y.jsx)(vc,{value:s,language:`json`,theme:g,onChange:y,onMount:(e,t)=>{f.current=e,p.current=t,setTimeout(v,0)},options:{readOnly:n,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,folding:!0,wordWrap:`on`,tabSize:2,renderLineHighlight:`line`,scrollbar:{verticalScrollbarSize:10,horizontalScrollbarSize:10}}})})}),l&&(0,Y.jsxs)(`div`,{className:`text-xs text-destructive flex items-start gap-1.5`,children:[(0,Y.jsx)(`span`,{"aria-hidden":!0,children:`⚠`}),(0,Y.jsx)(`span`,{children:l})]})]})}var Sc={object:async()=>(await a(async()=>{let{ObjectSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.c);return{ObjectSchema:e}},[],import.meta.url)).ObjectSchema,hook:async()=>(await a(async()=>{let{HookSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.c);return{HookSchema:e}},[],import.meta.url)).HookSchema,mapping:async()=>(await a(async()=>{let{MappingSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.c);return{MappingSchema:e}},[],import.meta.url)).MappingSchema,analytics_cube:async()=>(await a(async()=>{let{CubeSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.c);return{CubeSchema:e}},[],import.meta.url)).CubeSchema,view:async()=>(await a(async()=>{let{ViewSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.x);return{ViewSchema:e}},[],import.meta.url)).ViewSchema,page:async()=>(await a(async()=>{let{PageSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.x);return{PageSchema:e}},[],import.meta.url)).PageSchema,app:async()=>(await a(async()=>{let{AppSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.x);return{AppSchema:e}},[],import.meta.url)).AppSchema,dashboard:async()=>(await a(async()=>{let{DashboardSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.x);return{DashboardSchema:e}},[],import.meta.url)).DashboardSchema,report:async()=>(await a(async()=>{let{ReportSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.x);return{ReportSchema:e}},[],import.meta.url)).ReportSchema,action:async()=>(await a(async()=>{let{ActionSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.x);return{ActionSchema:e}},[],import.meta.url)).ActionSchema,theme:async()=>(await a(async()=>{let{ThemeSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.x);return{ThemeSchema:e}},[],import.meta.url)).ThemeSchema,flow:async()=>(await a(async()=>{let{FlowSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.i);return{FlowSchema:e}},[],import.meta.url)).FlowSchema,webhook:async()=>(await a(async()=>{let{WebhookSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.i);return{WebhookSchema:e}},[],import.meta.url)).WebhookSchema,agent:async()=>(await a(async()=>{let{AgentSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.o);return{AgentSchema:e}},[],import.meta.url)).AgentSchema,tool:async()=>(await a(async()=>{let{ToolSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.o);return{ToolSchema:e}},[],import.meta.url)).ToolSchema,skill:async()=>(await a(async()=>{let{SkillSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.o);return{SkillSchema:e}},[],import.meta.url)).SkillSchema,email_template:async()=>(await a(async()=>{let{EmailTemplateSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.t);return{EmailTemplateSchema:e}},[],import.meta.url)).EmailTemplateSchema,job:async()=>(await a(async()=>{let{JobSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.t);return{JobSchema:e}},[],import.meta.url)).JobSchema,permission:async()=>(await a(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,profile:async()=>(await a(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.n);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,role:async()=>(await a(async()=>{let{RoleSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.r);return{RoleSchema:e}},[],import.meta.url)).RoleSchema,api:async()=>(await a(async()=>{let{ApiEndpointSchema:e}=await import(`./vendor-objectstack-Bw0HRuFa.js`).then(e=>e.a);return{ApiEndpointSchema:e}},[],import.meta.url)).ApiEndpointSchema},Cc=new Set([`approval`,`connector_action`]),wc=/^nodes\.(\d+)\.type$/;function Tc(e,t){let n=e?.nodes;if(!Array.isArray(n))return;let r=n[t];return typeof r?.type==`string`?r.type:void 0}var Ec=new Map;async function Dc(e){if(Ec.has(e))return Ec.get(e)??null;let t=Sc[e];if(!t)return Ec.set(e,null),null;try{let n=await t(),r=n&&typeof n.safeParse==`function`?n:null;return Ec.set(e,r),r}catch{return Ec.set(e,null),null}}function Oc(e){return e in Sc}async function kc(e,t,n){let r=await Dc(e);if(!r)return{ok:!0,issues:[]};let i=r.safeParse(t);if(i.success)return{ok:!0,issues:[]};let a=i.error?.issues??[],o=Array.isArray(n?.required)?new Set(n.required.map(e=>String(e))):void 0;if(o&&t&&typeof t==`object`&&!Array.isArray(t)){let e=t;a=a.filter(t=>{let n=t.path??[];if(n.length!==1)return!0;let r=String(n[0]);return!((e[r]===void 0||e[r]===null)&&!o.has(r))})}return e===`flow`&&(a=a.filter(e=>{let n=(e.path??[]).map(e=>String(e)).join(`.`),r=wc.exec(n);if(!r)return!0;let i=Tc(t,Number(r[1]));return!(i&&Cc.has(i))})),a.length===0?{ok:!0,issues:[]}:{ok:!1,issues:a.map(e=>({path:(e.path??[]).map(e=>String(e)).join(`.`),message:e.message}))}}function Ac(e,t,n){let r=t.split(`.`);if(r.length<=1)return e;let i=[e],a=Mc(n)?.[r[0]];for(let e=1;e<r.length;e++){let t=r[e];if(/^\d+$/.test(t)){let e=Number(t),n=Array.isArray(a)?a[e]:void 0;i.push(jc(n)??`#${e+1}`),a=n}else i.push(t),a=Mc(a)?.[t]}return i.join(` → `)}function jc(e){let t=Mc(e);if(t)for(let e of[`id`,`name`,`key`,`title`,`label`]){let n=t[e];if(typeof n==`string`&&n.trim())return n;let r=Mc(n);if(r){let e=r.defaultValue??r.key;if(typeof e==`string`&&e.trim())return e}}}function Mc(e){return e&&typeof e==`object`?e:void 0}function Nc(e,t,n){return e.createBuildBody?e.createBuildBody(t):{...n??e.createDefaults??{},...t}}var Pc=_n,Fc=new Set([`object`,`report`,`dataset`]),Ic={object:[`fields`,`fieldGroups`]};function Lc(e){if(!e||typeof e!=`object`)return null;let t=e;if(!(`item`in t))return null;let n=t.item;return!n||typeof n!=`object`?null:Object.keys(n).length>0?n:null}function Rc(e){return e.loadFailed?!1:e.hasDiag||e.hasClientValidator}function zc({type:e,name:t,createMode:n=!1,embedded:r=!1}){let i=s(),a=e??i.type??``,o=t??i.name??``,c=Do(a);if(c?.EditPage&&!n){let e=c.EditPage;return(0,Y.jsx)(e,{type:a,name:o})}if(c?.CreatePage&&n){let e=c.CreatePage;return(0,Y.jsx)(e,{type:a})}return(0,Y.jsx)(Bc,{type:a,name:o,createMode:n,embedded:r})}function Bc({type:e,name:t,createMode:n,embedded:r}){let a=i(),[s,c]=o(),l=s.get(`package`)??void 0,u=ti(),{entries:d}=$r(u),f=d.find(t=>t.type===e),p=ko(e,f),m=(n&&p.createSchema?p.createSchema:f?.schema)??p.defaultSchema,h=X.useMemo(()=>Vi(),[]),[g,_]=X.useState(null),v=p.identityField??`name`,[y,b]=X.useState(()=>n?{...p.createDefaults??{},[v]:``}:{}),[x,S]=X.useState(null),[C,w]=X.useState(!n),[T,E]=X.useState(!1),[D,O]=X.useState(null),[k,j]=X.useState(!1),[ee,te]=X.useState([]),[ne,M]=X.useState(!1),re=X.useCallback(e=>{b(t=>{let n=typeof e==`function`?e(t):e,r=new Set,i=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of i)Object.is(t?.[e],n?.[e])||r.add(e);return r.size>0&&(M(!0),te(e=>e.filter(e=>{let t=(e.path??``).split(`.`)[0];return!r.has(t)}))),n})},[]),[ie,ae]=X.useState(null),[oe,N]=X.useState(null),se=X.useCallback(e=>{re(t=>({...t,...e}))},[re]),{markTouched:ce}=As({rules:p.createDerive,draft:y,onPatch:se,enabled:!!n}),le=X.useMemo(()=>{if(n)return p.createFields&&p.createFields.length>0?p.createFields:js(m?.properties??void 0,m?.required??void 0)},[n,p.createFields,m]),ue=X.useMemo(()=>{let t=Ic[e]??[];if(!n||!le)return t.length===0?p.hiddenFields:Array.from(new Set([...p.hiddenFields??[],...t]));let r=m?.properties??{},i=new Set(le),a=Object.keys(r).filter(e=>!i.has(e));if(p.hiddenFields)for(let e of p.hiddenFields)a.includes(e)||a.push(e);for(let e of t)a.includes(e)||a.push(e);return a},[n,le,m,p.hiddenFields,e]),de=X.useMemo(()=>n&&le?le:p.fieldOrder,[n,le,p.fieldOrder]),pe=X.useCallback(e=>{if(n){let t=y,n=typeof e==`function`?e(t):e,r=new Set([...Object.keys(t??{}),...Object.keys(n??{})]);for(let e of r)Object.is(t?.[e],n?.[e])||ce(e)}re(e)},[n,y,re,ce]);X.useEffect(()=>{if(!Oc(e))return;let t=!1,n=window.setTimeout(()=>{kc(e,y,f?.schema).then(e=>{t||te(e.issues)})},200);return()=>{t=!0,window.clearTimeout(n)}},[e,y,f?.schema]);let he=X.useMemo(()=>n&&!ne?[]:ee,[n,ne,ee]),_e=X.useMemo(()=>{let t=g?._diagnostics,n=Oc(e)?he.map(e=>({path:e.path,message:ii(e.message,h)})):(t?.errors??[]).map(e=>({path:e.path,message:ii(e.message,h)})),r=(t?.warnings??[]).map(e=>({path:e.path,message:ii(e.message,h)}));return[...n.map(e=>({path:e.path||void 0,message:e.message,severity:`error`})),...r.map(e=>({path:e.path||void 0,message:e.message,severity:`warning`}))]},[g,he,e,h]),[ve,ye]=X.useState(!1),[xe,Se]=X.useState(!1),[Ce,we]=X.useState(0),[F,Te]=X.useState(!!n),[De,ke]=X.useState(null);X.useEffect(()=>{ke(null)},[e,t]),X.useEffect(()=>{F||ke(null)},[F]);let je=ns(s.get(`sel`)),Ne=X.useRef(null);X.useEffect(()=>{if(e!==`app`||!je||Ne.current===`${t}:${je}`||!y||Object.keys(y).length===0)return;let n=ss(y,je);n&&(Ne.current=`${t}:${je}`,Te(!0),ke({kind:`nav`,id:n.selectionId,label:n.label}))},[e,t,je,y]),X.useEffect(()=>{if(e!==`app`)return;let t=De?.kind===`nav`?cs(y,De.id):null;c(e=>{let n=new URLSearchParams(e);return t?n.set(`sel`,rs(t)):n.delete(`sel`),n},{replace:!0})},[e,De]);let Pe=X.useRef(null),[Fe,Ie]=X.useState(null),[Re,ze]=X.useState(()=>{if(typeof window>`u`)return!0;try{let e=window.localStorage.getItem(`metadata-admin:autosave`);return e===null?!0:e===`1`}catch{return!0}});X.useEffect(()=>{try{window.localStorage.setItem(`metadata-admin:autosave`,Re?`1`:`0`)}catch{}},[Re]);let Ue=X.useRef(null),[We,Ge]=X.useState([]),[qe,Je]=X.useState(!0);X.useEffect(()=>{let e=!1;return(async()=>{try{let t=await u.list(`object`);if(e)return;Ge(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||Ge([])}finally{e||Je(!1)}})(),()=>{e=!0}},[u]);let Ye=y?.interfaceConfig?.source||y?.object||y?.objectName,[Xe,Ze]=X.useState([]),[$e,et]=X.useState(!1),[tt,nt]=X.useState([]);X.useEffect(()=>{let e=!1;if(!Ye){Ze([]),nt([]);return}return et(!0),(async()=>{try{let t=await u.get(`object`,Ye);if(e)return;let n=t?.fields,r=Array.isArray(n)?n.map(e=>({name:e?.name,label:e?.label,type:e?.type})):n&&typeof n==`object`?Object.entries(n).map(([e,t])=>({name:e,label:t?.label,type:t?.type})):[];Ze(r.filter(e=>!!e.name));let i=t?.actions,a=Array.isArray(i)?i.map(e=>({name:e?.name,label:e?.label,locations:e?.locations})).filter(e=>!!e.name):[];e||nt(a)}catch{e||(Ze([]),nt([]))}finally{e||et(!1)}})(),()=>{e=!0}},[u,Ye]);let[rt,it]=X.useState([]),[at,ot]=X.useState(!1);X.useEffect(()=>{let e=!1;if(!Ye){it([]);return}return ot(!0),(async()=>{try{let t=await u.list(`view`);if(e)return;let n=(t||[]).filter(e=>(e?.objectName??e?.object??e?.object_name)===Ye),r=new Set,i=n.map(e=>({name:e?.name,label:e?.label||void 0})).filter(e=>!!e.name&&!r.has(e.name)&&r.add(e.name));it(i)}catch{e||it([])}finally{e||ot(!1)}})(),()=>{e=!0}},[u,Ye]);let st=X.useMemo(()=>({objectNames:We,objectsLoading:qe,objectFields:Xe,objectFieldsLoading:$e,objectViews:rt,objectViewsLoading:at,objectActions:tt}),[We,qe,Xe,$e,rt,at,tt]);X.useEffect(()=>{if(n){w(!1);return}let r=!1;return w(!0),O(null),j(!1),(async()=>{try{let n=l?{packageId:l}:{},[i,a]=await Promise.all([u.layered(e,t,n),u.getDraft(e,t,n).catch(()=>null)]);if(r)return;_(i);let o=i?._diagnostics;o&&o.valid===!1&&Array.isArray(o.errors)?te(o.errors.map(e=>({path:e.path||``,message:e.message}))):te([]);let s=Lc(a),c=i.effective??i.code??{},d=s?{...c,...s}:c,f=p.toDraft?p.toDraft(d):d;b(f),Pe.current=f,ye(!!s),w(!1)}catch(n){r||(j(!0),O(q(`engine.edit.loadFailed`,h,{type:e,name:t??``,message:n?.message??String(n)})),w(!1))}})(),()=>{r=!0}},[u,e,t,l,n,Ce,h]);let[ut,dt]=X.useState(!1);async function ft(){if(!(x!=null||ut)){dt(!0);try{let n=await u.references(e,t);S(n)}catch(e){S([]),console.error(`references() failed`,e)}finally{dt(!1)}}}let[pt,ht]=X.useState(null),gt=X.useMemo(()=>!n&&!r&&Oo(e).length>0,[e,n,r]),_t=X.useRef(null),[vt,yt]=X.useState(null),bt=s.get(`review`),xt=X.useRef(!1);X.useEffect(()=>{if(!(bt!==`1`||n)){if(!xt.current){xt.current=!0,we(e=>e+1);return}if(!C){ve&&yt(`review`);let e=new URLSearchParams(s);e.delete(`review`),c(e,{replace:!0}),xt.current=!1}}},[bt,n,C,ve]);let[wt,Tt]=X.useState(`properties`);X.useEffect(()=>{if(vt===`references`&&ft(),typeof window<`u`&&!r){let e=new URL(window.location.href);vt?e.searchParams.set(`tab`,vt):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[vt,r]);let Dt=`metadata-edit:inspector-collapsed`,Ot=`metadata-edit:inspector-size`,[kt,jt]=X.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(Dt)===`1`),Mt=X.useRef(38);X.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(Ot));Number.isFinite(e)&&e>=22&&e<=80&&(Mt.current=e)},[]);let Nt=X.useRef(null),Ft=X.useCallback(()=>{jt(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(Dt,t?`1`:`0`),t})},[]);X.useEffect(()=>{let e=Nt.current;if(e)if(kt)e.resize?.(`0%`);else{let t=Mt.current||38;e.resize?.(`${t}%`)}},[kt]);let[Lt,Rt]=X.useState(!1),[zt,Bt]=X.useState(!1);X.useEffect(()=>{if(typeof document>`u`||!zt)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[zt]),X.useEffect(()=>{if(typeof window>`u`||!zt)return;function e(e){e.key===`Escape`&&(e.preventDefault(),Bt(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[zt]);let Vt=X.useRef(null);X.useEffect(()=>{Vt.current=null},[e,t]),X.useEffect(()=>{if(n||r||C)return;let i=`${e}/${t??``}`;Vt.current!==i&&Js(e)&&(g?.code!=null&&g.code?._packageId!==`sys_metadata`?f?.allowOrgOverride:f?.allowOrgOverride||f?.allowRuntimeCreate)&&(Vt.current=i,Te(!0))},[e,t,n,r,C,f,g]),X.useEffect(()=>{if(typeof window>`u`||r)return;function e(e){if(!(e.metaKey||e.ctrlKey)||e.shiftKey||e.altKey||e.key!==`\\`)return;let t=e.target;t&&(t.tagName===`TEXTAREA`||t.isContentEditable)||(e.preventDefault(),Ft())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,Ft]),X.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URLSearchParams(window.location.search),t=e.get(`tab`);(t===`layers`||t===`references`||t===`related`||t===`audit`)&&yt(t),_t.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&ht({kind:`metadata`,type:e,name:t})}},[]),X.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);pt?.kind===`metadata`?e.searchParams.set(`open`,`${pt.type}:${pt.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[pt,r]);function L(e){let t=e.split(`.`)[0];return t?Ac((()=>{let e=n&&p.createSchema?void 0:f?.form,r=Array.isArray(e?.sections)?e.sections:[];for(let e of r){let n=Array.isArray(e?.fields)?e.fields:[];for(let e of n)if(typeof e==`string`){if(e===t)return e}else if(e?.field===t)return String(e.label??t)}let i=m?.properties??{};return String(i[t]?.title??t)})(),e,y):e}async function Ht(r){E(!0),O(null),te([]);try{let i=f?.createSeed,o=n?Nc(p,y,i):p.fromDraft?p.fromDraft(y):y;if(n&&p.createSeed)try{let e=await p.createSeed(y,{client:u});e&&typeof e==`object`&&(o={...o,...e})}catch{}let c=String(o[v]??y[v]??t),d=n?{...o,[v]:c}:o;if(!c){O(J(`engine.validation.nameRequired`,h)),E(!1);return}let m=(()=>{try{let e=new URLSearchParams(window.location.search).get(`package`);return e&&e!==`all`?e:void 0}catch{return}})();await u.save(e,c,d,{force:r,mode:`draft`,...m?{packageId:m}:{}});let g=l?{packageId:l}:{},[x,S]=await Promise.all([u.layered(e,c,g),u.getDraft(e,c,g).catch(()=>null)]);_(x);let C=Lc(S);ye(!!C);let w=x.effective??d,T=C?{...w,...C}:w,D=p.toDraft?p.toDraft(T):T;b(D),Pe.current=D,Ie(new Date),Ue.current=JSON.stringify(D),ae(null),N(null);let k=!n&&!!Js(e);if(!n&&!k&&Te(!1),n){let e=s.toString();a(`../${encodeURIComponent(c)}${e?`?${e}`:``}`,{relative:`path`})}}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];ae(Array.isArray(t)?t:[]),N(y)}else if(e?.code===`writable_package_required`)O(J(`engine.package.writableRequired`,h));else if(e?.status===422||e?.code===`invalid_metadata`||e?.code===`invalid_payload`){let t=e?.body?.issues??[],n=(Array.isArray(t)?t:[]).map(e=>({path:Array.isArray(e.path)?e.path.join(`.`):String(e.path??``),message:ii(String(e.message??`Invalid`),h)})),r=String(e?.body?.error??e?.message??``);if(n.length===0&&r){let e=r.match(/failed spec validation:\s*(.+?):\s*(.+)$/);n=e?[{path:e[1].trim(),message:ii(e[2].trim(),h)}]:[{path:``,message:ii(r,h)}]}te(n),n.length===1&&!n[0].path?O(n[0].message):n.length===1?O(`${L(n[0].path)}: ${n[0].message}`):O(q(`engine.validation.failed`,h,{count:n.length}))}else O(e?.message??String(e))}finally{E(!1)}}async function Ut(){let r=!n&&g?.code!=null;if(confirm(q(r?`engine.edit.resetConfirm`:`engine.edit.deleteConfirm`,h,{type:e,name:t??``}))){E(!0),O(null);try{if(await u.reset(e,t),r){let n=await u.layered(e,t);_(n);let r=n.effective??n.code??{};b(r),Pe.current=r,Js(e)?Vt.current=null:Te(!1)}else a(`../`,{relative:`path`})}catch(e){O(e?.message??String(e))}finally{E(!1)}}}async function Gt(){Se(!0),O(null);try{await u.publish(e,t);let[n,r]=await Promise.all([u.layered(e,t),u.getDraft(e,t).catch(()=>null)]);_(n);let i=Lc(r);ye(!!i);let a=n.effective??y,o=i?{...a,...i}:a;b(o),Pe.current=o}catch(e){O(e?.message??String(e))}finally{Se(!1)}}async function Kt(){if(confirm(q(`engine.edit.discardDraftConfirm`,h,{type:e,name:t??``}))){E(!0),O(null);try{await u.reset(e,t,{state:`draft`});let n=await u.layered(e,t);_(n);let r=n.effective??n.code??{};b(r),Pe.current=r,ye(!1)}catch(e){O(e?.message??String(e))}finally{E(!1)}}}let qt=X.useMemo(()=>{if(n)return Object.keys(y).length>0;let e=Pe.current;if(!e)return!1;try{return JSON.stringify(y)!==JSON.stringify(e)}catch{return!1}},[y,n]),Jt=!n&&g?.code!=null&&g.code?._packageId!==`sys_metadata`,Yt=g?.editable!==!1,Xt=g?.deletable!==!1,Qt=g?.resettable!==!1,$t=g?.lockReason,en=g?.lock&&g.lock!==`none`,tn=(n?!!(f?.allowOrgOverride||f?.allowRuntimeCreate):Jt?!!f?.allowOrgOverride:!!(f?.allowOrgOverride||f?.allowRuntimeCreate))&&(n||Yt),nn=!tn&&!n,rn=X.useRef(Ht);if(X.useEffect(()=>{rn.current=Ht}),X.useEffect(()=>{if(!Re||n||nn||!F||!qt||T)return;let e;try{e=JSON.stringify(y)}catch{return}if(e===Ue.current)return;let t=window.setTimeout(()=>{Ue.current=e,rn.current(!1)},1500);return()=>window.clearTimeout(t)},[y,qt,F,T,n,nn,Re]),X.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!tn||nn||!F&&!n)return;e.preventDefault(),!T&&(n||qt)&&rn.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[tn,nn,F,n,T,qt]),X.useEffect(()=>{if(!qt)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[qt]),X.useEffect(()=>{if(!qt)return;let e=e=>{if(e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)return;let t=e.target?.closest?.(`a[href]`);if(t&&!(t.target&&t.target!==`_self`)&&!t.hasAttribute(`download`)){try{let e=new URL(t.href,window.location.href);if(e.origin!==window.location.origin||e.pathname===window.location.pathname)return}catch{return}confirm(J(`engine.edit.unsavedLeaveConfirm`,h))||(e.preventDefault(),e.stopPropagation())}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[qt,h]),Ur(X.useMemo(()=>{if(r)return null;let n=String(y.name??t??``);if(!n)return null;let i={type:e,name:n,label:typeof y.label==`string`?y.label:void 0};return e===`object`&&(i.fields=xi(y.fields).entries.slice(0,60).map(e=>({name:e.name,type:typeof e.def.type==`string`?e.def.type:void 0,label:typeof e.def.label==`string`?e.def.label:void 0,required:!!e.def.required||void 0}))),i},[r,e,t,y])),C)return(0,Y.jsx)(bo,{entry:f,itemName:t,children:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Loading `,e,`/`,t,`…`]})});let on=nn&&Jt&&!!f?.allowRuntimeCreate,cn=Fc.has(e),ln=!r&&(!n||cn)?Js(e):void 0,un=Zs(e),dn=ec(e);function fn(){Pe.current&&b(Pe.current),te([]),O(null),Te(!1)}let z=nn||!F&&!n,mn=(0,Y.jsxs)(Y.Fragment,{children:[!n&&(0,Y.jsx)(Co,{entry:f,location:`record_header`,recordId:t,onAfter:()=>we(e=>e+1)}),(!n||gt)&&(0,Y.jsxs)(`div`,{className:`flex items-center rounded-md border bg-background p-0.5`,children:[!n&&(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:()=>yt(`layers`),title:J(`engine.edit.layers`,h),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(Wt,{className:`h-3.5 w-3.5`}),g?.overlay&&(()=>{let e=ms(g.code,g.effective);return e>0?(0,Y.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-emerald-600 text-emerald-50 text-[9px] leading-[14px] text-center font-medium`,title:J(`engine.layers.diff`,h),children:e}):null})()]}),!n&&ve&&(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:()=>yt(`review`),title:J(`designer.draftReview.title`,h),className:`h-7 w-7 p-0 relative`,"data-testid":`resource-review-trigger`,children:[(0,Y.jsx)(an,{className:`h-3.5 w-3.5`}),(()=>{let e=Cs(g?.effective??null,y);return e>0?(0,Y.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-amber-500 text-amber-50 text-[9px] leading-[14px] text-center font-medium`,title:q(`designer.draftReview.badge`,h,{n:e}),children:e}):null})()]}),!n&&(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:()=>yt(`references`),title:J(`engine.edit.references`,h),className:`h-7 w-7 p-0 relative`,children:[(0,Y.jsx)(Be,{className:`h-3.5 w-3.5`}),x&&x.length>0&&(0,Y.jsx)(`span`,{className:`absolute -top-1 -right-1 min-w-[14px] h-[14px] px-1 rounded-full bg-muted text-foreground text-[9px] leading-[14px] text-center font-medium border`,children:x.length})]}),gt&&(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>yt(`related`),title:J(`engine.edit.related`,h),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(Zn,{className:`h-3.5 w-3.5`})}),!n&&(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>yt(`history`),title:J(`engine.edit.history`,h),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(pn,{className:`h-3.5 w-3.5`})}),!n&&(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>yt(`audit`),title:J(`engine.edit.auditTab`,h),className:`h-7 w-7 p-0`,children:(0,Y.jsx)(mt,{className:`h-3.5 w-3.5`})})]}),!n&&tn&&g?.overlay&&(Jt?Qt:Xt)&&(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:Ut,disabled:T,title:J(Jt?`engine.edit.reset`:`engine.edit.delete`,h),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:Jt?(0,Y.jsx)(Me,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(sr,{className:`h-3.5 w-3.5`})}),tn&&!n&&!F&&!ln&&(0,Y.jsxs)(H,{size:`sm`,onClick:()=>Te(!0),className:`h-7`,children:[(0,Y.jsx)(Gn,{className:`h-3.5 w-3.5 mr-1`}),J(`engine.edit.edit`,h)]}),tn&&(F||n)&&(0,Y.jsx)(Hc,{saving:T,isDirty:qt,autoSaveEnabled:Re,lastSavedAt:Fe,createMode:!!n,locale:h}),tn&&(F||n)&&!n&&(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>ze(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:J(Re?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,h),children:Re?(0,Y.jsx)(me,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,Y.jsx)(be,{className:`h-3.5 w-3.5`})}),tn&&!n&&F&&!ln&&(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:fn,disabled:T,className:`h-7 w-7 p-0`,title:J(`engine.cancel`,h),children:(0,Y.jsx)(Qe,{className:`h-3.5 w-3.5`})}),tn&&(F||n)&&(0,Y.jsxs)(H,{size:`sm`,onClick:()=>Ht(!1),disabled:T||!n&&!qt,className:`h-7 w-7 p-0 relative`,title:T?J(`engine.edit.saving`,h):!n&&!qt?J(`engine.edit.noChanges`,h):`${J(`engine.edit.save`,h)} (⌘S)`,children:[T?(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Pn,{className:`h-3.5 w-3.5`}),qt&&!T&&(0,Y.jsx)(`span`,{"aria-hidden":!0,className:`absolute -top-0.5 -right-0.5 inline-block h-2 w-2 rounded-full bg-amber-300 ring-2 ring-background`})]}),tn&&!n&&ve&&(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:Kt,disabled:T||xe,className:`h-7 w-7 p-0 text-muted-foreground`,title:J(`engine.edit.discardDraft`,h),children:(0,Y.jsx)(Oe,{className:`h-3.5 w-3.5`})}),tn&&!n&&ve&&(0,Y.jsx)(H,{size:`sm`,onClick:Gt,disabled:T||xe||qt,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:J(qt?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,h),children:xe?(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(fe,{className:`h-3.5 w-3.5 mr-1`}),(0,Y.jsx)(`span`,{className:`text-xs`,children:J(`engine.edit.publish`,h)})]})})]});return(0,Y.jsxs)(bo,{entry:f??{type:e,label:e},itemName:n?`(new)`:t,subtitle:n?J(`engine.edit.createNew`,h):void 0,actions:ln?null:mn,children:[(0,Y.jsxs)(`div`,{className:ln?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(D||nn||ve||en)&&(0,Y.jsxs)(`div`,{className:ln?`px-6 pt-4 space-y-3`:`space-y-3`,children:[D&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:D}),en&&(0,Y.jsxs)(`div`,{className:`text-xs text-amber-900 border border-amber-300/70 bg-amber-50/70 rounded-md px-3 py-2.5 dark:text-amber-200 dark:border-amber-700/40 dark:bg-amber-950/20 flex items-start gap-2.5`,children:[(0,Y.jsx)(lt,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 opacity-80`}),(0,Y.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`font-medium`,children:[g?.lock===`full`&&J(`engine.edit.lockFull`,h),g?.lock===`no-overlay`&&J(`engine.edit.lockNoOverlay`,h),g?.lock===`no-delete`&&J(`engine.edit.lockNoDelete`,h)]}),$t&&(0,Y.jsx)(`div`,{className:`mt-0.5 opacity-90`,children:$t}),g?.lockDocsUrl&&(0,Y.jsxs)(`a`,{href:g.lockDocsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-amber-800 underline hover:text-amber-900 dark:text-amber-200 dark:hover:text-amber-100`,children:[h===`zh-CN`?`查看文档`:`View docs`,` →`]}),g?.packageId&&(0,Y.jsx)(`div`,{className:`mt-0.5 text-amber-700 dark:text-amber-300/80`,children:(0,Y.jsxs)(`code`,{className:`font-mono`,children:[g.packageId,g.packageVersion?`@${g.packageVersion}`:``]})})]}),on&&(0,Y.jsx)(H,{size:`sm`,variant:`outline`,className:`shrink-0 h-7 bg-background/60`,onClick:()=>a(`../new`,{relative:`path`}),children:J(`engine.list.create`,h)})]}),ve&&!n&&(0,Y.jsxs)(`div`,{className:`text-xs text-emerald-900 border border-emerald-300 bg-emerald-50 rounded p-3 dark:text-emerald-200 dark:border-emerald-700/50 dark:bg-emerald-950/30 flex items-center gap-3`,children:[(0,Y.jsx)(fe,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`flex-1`,children:J(`engine.edit.draftPending`,h)}),tn&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(H,{size:`sm`,variant:`ghost`,onClick:Kt,disabled:T||xe,className:`h-7`,children:J(`engine.edit.discardDraft`,h)}),(0,Y.jsx)(H,{size:`sm`,onClick:Gt,disabled:T||xe||qt,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:xe?(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):J(`engine.edit.publish`,h)})]})]}),nn&&!en&&(0,Y.jsxs)(`div`,{"data-testid":`readonly-banner`,className:`text-xs text-amber-800 border border-amber-300/70 bg-amber-50/70 rounded-md px-3 py-2.5 dark:text-amber-200 dark:border-amber-700/40 dark:bg-amber-950/20 flex items-start gap-3`,children:[(0,Y.jsx)(`div`,{className:`flex-1`,children:on?J(`engine.edit.artifactLockedBanner`,h).split(/(\{type\})/).map((t,n)=>t===`{type}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:e},n):(0,Y.jsx)(X.Fragment,{children:t},n)):J(`engine.edit.readOnlyTypeBanner`,h).split(/(\{flag\}|\{type\}|\{override\})/).map((t,n)=>t===`{flag}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:`OBJECTSTACK_METADATA_WRITABLE`},n):t===`{type}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:e},n):t===`{override}`?(0,Y.jsx)(`code`,{className:`font-mono`,children:`allowOrgOverride`},n):(0,Y.jsx)(X.Fragment,{children:t},n))}),on&&(0,Y.jsx)(H,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>a(`../new`,{relative:`path`}),children:J(`engine.list.create`,h)})]})]}),(0,Y.jsx)(`div`,{className:ln?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,Y.jsxs)(`div`,{className:ln?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!ln&&z&&!nn&&tn&&!n&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 text-xs text-muted-foreground border rounded p-2.5 bg-muted/30`,children:[(0,Y.jsx)(`span`,{children:J(`engine.edit.readOnlyBanner`,h).split(/\{edit\}/).map((e,t,n)=>(0,Y.jsxs)(X.Fragment,{children:[e,t<n.length-1&&(0,Y.jsx)(`strong`,{children:J(`engine.edit.edit`,h)})]},t))}),(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,onClick:()=>Te(!0),children:[(0,Y.jsx)(Gn,{className:`h-3.5 w-3.5 mr-1`}),J(`engine.edit.edit`,h)]})]}),(()=>{let t=g?._diagnostics,r=Oc(e)?ee.map(e=>({path:e.path,message:ii(e.message,h)})):(t?.errors??[]).map(e=>({...e,message:ii(e.message,h)})),i=Oc(e)?r.length===0:t?.valid!==!1;if(n&&!ne||!Rc({loadFailed:k,hasDiag:!!t,hasClientValidator:Oc(e)}))return null;let a=r,o=t?.warnings??[],s=!i&&a.length>0,c=o.length>0;if(!s&&!c)return null;let l=(e,t)=>{let n=t.slice(0,3),r=Math.max(0,t.length-n.length),i=e===`error`?`border-destructive/40 bg-destructive/[0.06] text-destructive`:`border-amber-500/40 bg-amber-500/[0.08] text-amber-800 dark:text-amber-200`,a=e===`error`?`engine.edit.diagnostics.title`:`engine.edit.diagnostics.warnTitle`;return(0,Y.jsxs)(`div`,{"data-testid":e===`error`?`metadata-validation-banner`:void 0,className:`flex items-start gap-2 text-xs border rounded p-2.5 ${i}`,children:[(0,Y.jsx)(I,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:q(a,h,{count:t.length})}),(0,Y.jsxs)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[11px]`,children:[n.map((e,t)=>(0,Y.jsxs)(`li`,{className:`truncate`,children:[(0,Y.jsx)(`span`,{className:`opacity-70`,children:e.path?L(e.path):`(root)`}),`: `,e.message]},t)),r>0&&(0,Y.jsx)(`li`,{className:`opacity-70`,children:q(`engine.edit.diagnostics.more`,h,{count:r})})]})]})]},e)};return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[s&&l(`error`,a),c&&l(`warning`,o)]})})(),ln?(0,Y.jsx)(`div`,{className:zt?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,Y.jsxs)(Pc,{direction:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${e}`,children:[(0,Y.jsx)(A,{defaultSize:62,minSize:30,children:(0,Y.jsxs)(`div`,{className:`relative h-full flex flex-col`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b bg-background/95 backdrop-blur px-3 py-2 sticky top-0 z-10`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-1`,children:tn&&(0,Y.jsxs)(`div`,{role:`tablist`,"aria-label":J(`engine.edit.designer`,h),className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":!Lt,onClick:()=>Rt(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Lt?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:J(`engine.edit.designMode`,h),children:[(0,Y.jsx)(Mr,{className:`h-3.5 w-3.5`}),J(`engine.edit.designMode`,h)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Lt,onClick:()=>Rt(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Lt?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:J(`engine.edit.previewMode`,h),children:[(0,Y.jsx)(He,{className:`h-3.5 w-3.5`}),J(`engine.edit.previewMode`,h)]})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[mn,(0,Y.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),ln&&(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:Ft,className:`h-7 w-7 p-0`,title:J(kt?`engine.edit.showInspector`:`engine.edit.hideInspector`,h)+` (⌘\\)`,children:kt?(0,Y.jsx)(sn,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(vr,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>Bt(e=>!e),className:`h-7 w-7 p-0`,title:J(zt?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,h),children:zt?(0,Y.jsx)(ge,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4 bg-[radial-gradient(circle_at_1px_1px,theme(colors.border)_1px,transparent_0)] [background-size:16px_16px] bg-muted/30`,children:(0,Y.jsx)(ln,{type:e,name:t,draft:y,baseline:n?void 0:g?.effective??void 0,editing:F&&!Lt,selection:Lt?null:De,onSelectionChange:ke,locale:h,diagnostics:_e,onPatch:e=>re(t=>({...t,...e}))})})]})}),(0,Y.jsx)(ct,{withHandle:!0,className:kt?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,Y.jsx)(A,{panelRef:Nt,defaultSize:Mt.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(Mt.current=t,typeof window<`u`&&window.localStorage.setItem(Ot,String(Math.round(t)))),jt(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(Dt,n?`1`:`0`),n))},children:(0,Y.jsxs)(`div`,{className:`h-full overflow-auto`,children:[(0,Y.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 backdrop-blur px-3 py-2`,children:[(0,Y.jsxs)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":wt===`properties`,onClick:()=>Tt(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(wt===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:J(`engine.edit.inspector.properties`,h),children:[(0,Y.jsx)(Zt,{className:`h-3.5 w-3.5`}),J(`engine.edit.inspector.properties`,h)]}),(0,Y.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":wt===`source`,onClick:()=>Tt(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(wt===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:J(`engine.edit.inspector.source`,h),children:[(0,Y.jsx)(Ct,{className:`h-3.5 w-3.5`}),J(`engine.edit.inspector.source`,h)]})]}),qt&&(0,Y.jsxs)(R,{variant:`outline`,className:`text-[10px] border-amber-400/60 text-amber-600 dark:text-amber-300`,children:[(0,Y.jsx)(`span`,{className:`mr-1 inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),J(`engine.edit.unsaved`,h)]})]}),(0,Y.jsx)(`div`,{className:`p-4`,children:wt===`source`?(0,Y.jsx)(xc,{value:y,onChange:re,readOnly:z,issues:he.map(e=>({path:e.path??``,message:e.message}))}):De&&un?(0,Y.jsx)(un,{type:e,name:t,draft:y,selection:De,onPatch:e=>re(t=>({...t,...e})),onClearSelection:()=>ke(null),onSelectionChange:ke,readOnly:z,locale:h}):!De&&dn?(0,Y.jsx)(dn,{type:e,name:t,draft:y,onPatch:e=>re(t=>({...t,...e})),onSelectionChange:ke,readOnly:z,locale:h,serverSchema:f?.schema}):(0,Y.jsx)(Li,{schema:m,form:n&&p.createSchema?void 0:f?.form,value:y,onChange:pe,issues:he,hiddenFields:ue,fieldOrder:de,readOnly:z,createMode:n,widgetContext:st})})]})})]})}):(0,Y.jsx)(Li,{schema:m,form:n&&p.createSchema?void 0:f?.form,value:y,onChange:pe,issues:he,hiddenFields:ue,fieldOrder:de,readOnly:z,createMode:n,widgetContext:st})]})})]}),(0,Y.jsx)(P,{open:vt===`layers`,onOpenChange:e=>!e&&yt(null),children:(0,Y.jsxs)(At,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Et,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(It,{className:`text-base`,children:J(`engine.edit.layers`,h)}),(0,Y.jsxs)(Ae,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(hs,{layered:g,locale:h})})]})}),(0,Y.jsx)(P,{open:vt===`review`,onOpenChange:e=>!e&&yt(null),children:(0,Y.jsxs)(At,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Et,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(It,{className:`text-base`,children:J(`designer.draftReview.title`,h)}),(0,Y.jsxs)(Ae,{className:`text-xs`,children:[e,` / `,t,` · `,J(`designer.canvas.reviewVsPublished`,h)]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(ws,{published:g?.effective??null,draft:y,locale:h})})]})}),(0,Y.jsx)(P,{open:vt===`references`,onOpenChange:e=>!e&&yt(null),children:(0,Y.jsxs)(At,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Et,{className:`px-4 py-3 border-b`,children:[(0,Y.jsxs)(It,{className:`text-base`,children:[J(`engine.edit.references`,h),x&&(0,Y.jsx)(R,{variant:`outline`,className:`ml-2 text-[10px]`,children:x.length})]}),(0,Y.jsxs)(Ae,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Vc,{refs:x,loading:ut})})]})}),gt&&(0,Y.jsx)(P,{open:vt===`related`,onOpenChange:e=>!e&&yt(null),children:(0,Y.jsxs)(At,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Et,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(It,{className:`text-base`,children:J(`engine.edit.related`,h)}),(0,Y.jsxs)(Ae,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Ms,{type:e,name:t,parentItem:y,onOpen:e=>ht(e)})})]})}),!n&&(0,Y.jsx)(P,{open:vt===`history`,onOpenChange:e=>!e&&yt(null),children:(0,Y.jsxs)(At,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Et,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(It,{className:`text-base`,children:J(`engine.edit.history`,h)}),(0,Y.jsxs)(Ae,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,Y.jsx)(Bs,{type:e,name:t,client:u,onRollback:()=>we(e=>e+1),rollbackLabel:J(`engine.edit.rollback`,h),rollbackConfirm:e=>J(`engine.edit.rollbackConfirm`,h).replace(`{version}`,String(e))})})]})}),!n&&(0,Y.jsx)(P,{open:vt===`audit`,onOpenChange:e=>!e&&yt(null),children:(0,Y.jsxs)(At,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,Y.jsxs)(Et,{className:`px-4 py-3 border-b`,children:[(0,Y.jsx)(It,{className:`text-base`,children:J(`engine.edit.auditTab`,h)}),(0,Y.jsxs)(Ae,{className:`text-xs`,children:[e,` / `,t]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden p-3`,children:(0,Y.jsx)(Gs,{type:e,name:t,client:u,locale:h})})]})}),(0,Y.jsx)(Rs,{target:pt,onClose:()=>ht(null),parentContext:{type:e,name:t}}),(0,Y.jsx)(St,{open:ie!=null,onOpenChange:e=>{e||(ae(null),N(null))},children:(0,Y.jsxs)(Pt,{children:[(0,Y.jsxs)(ar,{children:[(0,Y.jsxs)(Le,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(I,{className:`h-5 w-5 text-amber-600`}),`Destructive change detected`]}),(0,Y.jsx)(Ee,{children:`The framework refused this save because it would drop or narrow data already in use. Review the issues and confirm to override.`})]}),(0,Y.jsx)(`div`,{className:`max-h-[300px] overflow-auto space-y-2 my-2`,children:ie?.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded border bg-amber-50 border-amber-200 p-2 text-xs`,children:[(0,Y.jsx)(`div`,{className:`font-mono text-amber-900`,children:e.kind??`change`}),e.path&&(0,Y.jsx)(`div`,{className:`text-amber-800 font-mono mt-0.5`,children:e.path}),(0,Y.jsx)(`div`,{className:`text-amber-900 mt-1`,children:e.message})]},t))}),(0,Y.jsxs)(Ve,{children:[(0,Y.jsx)(H,{variant:`ghost`,onClick:()=>ae(null),children:`Cancel`}),(0,Y.jsx)(H,{variant:`destructive`,onClick:()=>Ht(!0),disabled:T,children:T?`Forcing…`:`Force save`})]})]})})]})}function Vc({refs:e,loading:t}){return t||e==null?(0,Y.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Scanning references…`]}):e.length===0?(0,Y.jsxs)(jt,{children:[(0,Y.jsx)(Fe,{children:`No references found`}),(0,Y.jsx)(F,{children:`Nothing in the metadata graph points at this item. Safe to delete.`})]}):(0,Y.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From type`}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From name`}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Path`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:e.map((e,t)=>(0,Y.jsxs)(`tr`,{className:`hover:bg-accent/50`,children:[(0,Y.jsx)(`td`,{className:`px-3 py-2`,children:(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px] font-mono`,children:e.fromType})}),(0,Y.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs`,children:e.fromName}),(0,Y.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-muted-foreground`,children:e.path})]},t))})]})})}function Hc({saving:e,isDirty:t,autoSaveEnabled:n,lastSavedAt:r,createMode:i,locale:a}){let[,o]=X.useReducer(e=>e+1,0);return X.useEffect(()=>{if(!r)return;let e=window.setInterval(o,3e4);return()=>window.clearInterval(e)},[r]),e?(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:[(0,Y.jsx)(U,{className:`h-3 w-3 animate-spin`}),J(`engine.edit.saving`,a)]}):t?i?null:(0,Y.jsxs)(`span`,{className:`text-xs text-amber-600 dark:text-amber-300 hidden md:inline-flex items-center gap-1`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),J(n?`engine.edit.autoSavingShortly`:`engine.edit.unsaved`,a)]}):r?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:q(`engine.edit.savedAt`,a,{time:`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`})}):null}function Uc({type:e}){let t=r(),[n]=o(),i=e??n.get(`type`)??``;if(!i)return(0,Y.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,Y.jsxs)(jt,{children:[(0,Y.jsx)(Fe,{children:`Missing metadata type`}),(0,Y.jsxs)(F,{children:[`This page expects a `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`?type=`}),` query param (e.g. `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`?type=view`}),`) or a nav-metadata `,(0,Y.jsxs)(`code`,{className:`font-mono`,children:[`params: `,`{ type: 'view' }`]}),`.`]})]})});let a=Wc(t.pathname),s=a.split(`/`).filter(Boolean);return s.length===0?(0,Y.jsx)(jo,{type:i}):s[0]===`new`&&s.length===1?(0,Y.jsx)(zc,{type:i,name:``,createMode:!0},`${i}:__new__`):s.length===2&&s[1]===`history`?(0,Y.jsx)(zs,{type:i,name:decodeURIComponent(s[0])}):s.length===1?(0,Y.jsx)(zc,{type:i,name:decodeURIComponent(s[0])},`${i}:${s[0]}`):(0,Y.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,Y.jsxs)(jt,{children:[(0,Y.jsx)(Fe,{children:`Unknown sub-path`}),(0,Y.jsxs)(F,{children:[`The path `,(0,Y.jsx)(`code`,{className:`font-mono`,children:a}),` isn't recognized. Valid forms are `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/`}),` (list),`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/new`}),` (create),`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/:name`}),` (edit),`,` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:`/:name/history`}),`.`]})]})})}function Wc(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function Gc(){let e=ti(),t=X.useMemo(()=>Vi(),[]),[r,i]=X.useState(`error`),{loading:a,error:o,summary:s,reload:c}=ei(e,r),{entries:l}=$r(e),u=X.useMemo(()=>{let e={};for(let n of l)e[n.type]=vi(n.type,t,n.label);return e},[l,t]),d=X.useMemo(()=>{let e={};for(let t of s.entries)(e[t.type]??=[]).push(t);return Object.entries(e).sort(([,e],[,t])=>t.length-e.length)},[s]);return(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,Y.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,Y.jsx)(`nav`,{className:`text-xs text-muted-foreground mb-2`,children:(0,Y.jsxs)(n,{to:`..`,className:`hover:text-foreground inline-flex items-center gap-1`,children:[(0,Y.jsx)(se,{className:`h-3 w-3`}),J(`engine.diagnostics.back`,t)]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,Y.jsxs)(`h1`,{className:`text-xl font-semibold flex items-center gap-2`,children:[(0,Y.jsx)(I,{className:`h-5 w-5 text-destructive`}),J(`engine.diagnostics.title`,t)]}),(0,Y.jsx)(R,{variant:`outline`,className:`text-[11px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:q(`engine.diagnostics.summary`,t,{count:s.total,items:s.scannedItems,types:s.scannedTypes})}),(0,Y.jsx)(`div`,{className:`flex-1`}),(0,Y.jsx)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5 text-xs`,children:[`error`,`warning`].map(e=>(0,Y.jsx)(`button`,{role:`tab`,type:`button`,"aria-selected":r===e,onClick:()=>i(e),className:`px-2.5 py-1 rounded transition-colors `+(r===e?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),children:J(`engine.diagnostics.severity.${e}`,t)},e))}),(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:c,children:[(0,Y.jsx)(Dt,{className:`h-3.5 w-3.5 mr-1`}),J(`engine.diagnostics.refresh`,t)]})]}),(0,Y.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-3xl`,children:J(`engine.diagnostics.description`,t)})]}),(0,Y.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[a&&(0,Y.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:J(`engine.diagnostics.loading`,t)}),!a&&o&&(0,Y.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/[0.06]`,children:q(`engine.diagnostics.loadFailed`,t,{error:o})}),!a&&!o&&d.length===0&&(0,Y.jsxs)(jt,{children:[(0,Y.jsx)(Fe,{children:J(`engine.diagnostics.cleanTitle`,t)}),(0,Y.jsx)(F,{children:q(`engine.diagnostics.cleanHint`,t,{items:s.scannedItems,types:s.scannedTypes})})]}),d.map(([e,i])=>(0,Y.jsxs)(`section`,{className:`space-y-2`,children:[(0,Y.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(n,{to:`../${encodeURIComponent(e)}`,className:`hover:text-foreground hover:underline`,children:u[e]??e}),(0,Y.jsx)(`span`,{className:`font-mono normal-case tracking-normal text-[10px] opacity-70`,children:e}),(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:i.length})]}),(0,Y.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left font-medium w-[28%]`,children:J(`engine.diagnostics.col.name`,t)}),(0,Y.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:J(`engine.diagnostics.col.issues`,t)})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:i.map(i=>{let a=i.diagnostics.errors??[],o=i.diagnostics.warnings??[],s=(r===`warning`&&a.length===0?o:a).slice(0,3),c=Math.max(0,(a.length||o.length)-s.length);return(0,Y.jsxs)(`tr`,{className:`hover:bg-accent/50 align-top`,children:[(0,Y.jsxs)(`td`,{className:`px-3 py-2 align-top`,children:[(0,Y.jsx)(n,{to:`../${encodeURIComponent(e)}/${encodeURIComponent(i.name)}`,className:`text-primary hover:underline font-mono`,children:i.name}),a.length>0&&(0,Y.jsx)(R,{variant:`outline`,className:`ml-2 text-[10px] border-destructive/40 text-destructive`,children:q(`engine.diagnostics.errorN`,t,{count:a.length})}),o.length>0&&(0,Y.jsx)(R,{variant:`outline`,className:`ml-2 text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300`,children:q(`engine.diagnostics.warnN`,t,{count:o.length})})]}),(0,Y.jsx)(`td`,{className:`px-3 py-2 align-top`,children:(0,Y.jsxs)(`ul`,{className:`space-y-0.5 font-mono text-[11px]`,children:[s.map((e,t)=>(0,Y.jsxs)(`li`,{className:`truncate`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:e.path||`(root)`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`: `}),e.message]},t)),c>0&&(0,Y.jsx)(`li`,{className:`text-muted-foreground`,children:q(`engine.diagnostics.more`,t,{count:c})})]})})]},i.name)})})]})})]},e))]})]})}function Kc(){let e=X.useMemo(()=>Vi().toLowerCase().startsWith(`zh`),[]);return X.useMemo(()=>e?{title:`已分配用户`,add:`添加用户`,remove:`移除`,empty:`还没有分配任何用户。点击「添加用户」来分配。`,loading:`加载中…`,pickTitle:`选择要分配的用户`,seatFull:e=>`AI 席位已用完(`+e+`/`+e+`)。请先移除一个用户,或在许可证中提升席位上限,再分配新用户。`,addFailed:`分配失败,请重试。`,countOf:e=>e+` 人`}:{title:`Assigned Users`,add:`Add user`,remove:`Remove`,empty:`No users assigned yet. Click "Add user" to assign.`,loading:`Loading…`,pickTitle:`Select users to assign`,seatFull:e=>`All `+e+` AI seat(s) are in use. Remove a user or raise the license cap before assigning another.`,addFailed:`Failed to assign. Please try again.`,countOf:e=>String(e)},[e])}var qc=e=>Array.isArray(e)?e:e?.records??e?.items??e?.data??[],Jc=e=>e?.full_name||e?.name||e?.display_name||e?.email||String(e?.id??``);function Yc({permissionSetName:e}){let t=p(),n=Kc(),[r,i]=X.useState(null),[a,o]=X.useState([]),[s,c]=X.useState(!0),[l,u]=X.useState(!1),[d,f]=X.useState(!1),[m,h]=X.useState(null),g=X.useCallback(async()=>{c(!0);try{let n=qc(await t.find(`sys_permission_set`,{$filter:{name:e},limit:1})),r=n[0]?.id?String(n[0].id):null;if(i(r),!r){o([]);return}let a=qc(await t.find(`sys_user_permission_set`,{$filter:{permission_set_id:r},$top:500})),s=[...new Set(a.map(e=>e.user_id).filter(Boolean).map(String))],c=s.length?qc(await t.find(`sys_user`,{$filter:{id:{$in:s}},$top:500})):[],l=new Map(c.map(e=>[String(e.id),e]));o(a.filter(e=>e.user_id).map(e=>{let t=l.get(String(e.user_id));return{grantId:String(e.id),userId:String(e.user_id),name:t?Jc(t):String(e.user_id),email:t?.email??``}}))}catch{o([])}finally{c(!1)}},[t,e]);X.useEffect(()=>{g()},[g]);let _=X.useMemo(()=>new Set(a.map(e=>e.userId)),[a]),v=X.useCallback(async e=>{if(r){f(!0),h(null);try{for(let n of e||[]){let e=n?.id==null?null:String(n.id);!e||_.has(e)||await t.create(`sys_user_permission_set`,{permission_set_id:r,user_id:e})}await g()}catch(e){let t=String(e?.body?.error??e?.error??e?.message??``),r=t.match(/(\d+)\s*of\s*(\d+)\s*seat/i);if(/cap reached|seat cap|ai[-_ ]?seat/i.test(t))h(n.seatFull(r?Number(r[2]):a.length));else{let e=t.replace(/^\s*\[[^\]]*\]\s*/,``).trim();h(e||n.addFailed)}}finally{f(!1),u(!1)}}},[t,r,_,g,a.length,n]),y=X.useCallback(async e=>{h(null);try{await t.delete(`sys_user_permission_set`,e),await g()}catch{}},[t,g]);return(0,Y.jsxs)(`div`,{className:`px-4 py-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[(0,Y.jsx)(Ne,{className:`h-4 w-4 text-muted-foreground`}),(0,Y.jsx)(`span`,{children:n.title}),!s&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground font-normal`,children:n.countOf(a.length)})]}),(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,disabled:d||!r,onClick:()=>{h(null),u(!0)},className:`gap-1 h-8 text-xs`,children:[d?(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(L,{className:`h-3.5 w-3.5`}),n.add]})]}),m&&(0,Y.jsxs)(`div`,{className:`mb-3 flex items-start gap-2 rounded-md border border-amber-300/60 bg-amber-50 dark:bg-amber-950/30 px-3 py-2 text-xs text-amber-800 dark:text-amber-200`,role:`alert`,children:[(0,Y.jsx)(rt,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{children:m})]}),s?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground py-3`,children:[(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}),n.loading]}):a.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic py-3`,children:n.empty}):(0,Y.jsx)(`ul`,{className:`divide-y rounded-md border`,children:a.map(e=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,Y.jsx)(`div`,{className:`flex h-7 w-7 items-center justify-center rounded-full bg-primary/10 text-primary text-xs font-medium shrink-0`,children:(e.name||`?`).slice(0,1).toUpperCase()}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm truncate`,children:e.name}),e.email&&e.email!==e.name&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.email})]}),(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>void y(e.grantId),"aria-label":n.remove,title:n.remove,className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive shrink-0`,children:(0,Y.jsx)(Qe,{className:`h-4 w-4`})})]},e.grantId))}),r&&(0,Y.jsx)(he,{open:l,onOpenChange:e=>u(e),multiple:!0,dataSource:t,objectName:`sys_user`,title:n.pickTitle,onSelect:()=>{},onSelectRecords:e=>void v(e)})]})}function Xc(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function Zc(e){return e instanceof Set?e:new Set(e)}function Qc(e,t){let n=Zc(t),r={};for(let[t,i]of Object.entries(e.objects??{}))n.has(t)&&(r[t]=i);let i={};for(let[t,r]of Object.entries(e.fields??{}))n.has(Xc(t))&&(i[t]=r);return{objects:r,fields:i}}function $c(e,t,n){let r=Zc(n),i={};for(let[t,n]of Object.entries(e.objects??{}))r.has(t)||(i[t]=n);for(let[e,n]of Object.entries(t.objects??{}))r.has(e)&&(i[e]=n);let a={};for(let[t,n]of Object.entries(e.fields??{}))r.has(Xc(t))||(a[t]=n);for(let[e,n]of Object.entries(t.fields??{}))r.has(Xc(e))&&(a[e]=n);return{...e,name:t.name,label:t.label,isProfile:t.isProfile,objects:i,fields:a}}function el(e){return[{key:`allowCreate`,short:`C`,tip:J(`perm.action.create`,e)},{key:`allowRead`,short:`R`,tip:J(`perm.action.read`,e)},{key:`allowEdit`,short:`U`,tip:J(`perm.action.edit`,e)},{key:`allowDelete`,short:`D`,tip:J(`perm.action.delete`,e)},{key:`allowTransfer`,short:`Tr`,tip:J(`perm.action.transfer`,e)},{key:`allowRestore`,short:`Re`,tip:J(`perm.action.restore`,e)},{key:`allowPurge`,short:`Pu`,tip:J(`perm.action.purge`,e)},{key:`viewAllRecords`,short:`VA`,tip:J(`perm.action.viewAll`,e)},{key:`modifyAllRecords`,short:`MA`,tip:J(`perm.action.modifyAll`,e)}]}function tl({type:e,name:t,packageId:n,onDraftSaved:r,publishNonce:a}){let o=i(),s=ti(),{entries:c}=$r(s),l=c.find(t=>t.type===e),u=!!ko(e,l).allowOrgOverride,d=X.useMemo(()=>Vi(),[]),f=X.useCallback(e=>J(e,d),[d]),p=X.useMemo(()=>el(d),[d]),[m,h]=X.useState({name:t,objects:{},fields:{}}),[g,_]=X.useState([]),[v,y]=X.useState({}),[b,x]=X.useState(new Set),[S,C]=X.useState(!0),[w,T]=X.useState(!1),[E,D]=X.useState(null),[O,k]=X.useState(null),[A,j]=X.useState(``),[ee,te]=X.useState(!1);X.useEffect(()=>{let r=!1;return C(!0),(async()=>{try{let[i,a,o]=await Promise.all([s.layered(e,t).catch(()=>null),s.list(`object`,n?{packageId:n}:{}).catch(()=>[]),n?s.getDraft(e,t,{packageId:n}).catch(()=>null):Promise.resolve(null)]);if(r)return;let c=(o?o.item??o:null)??i?.effective??i?.code??{name:t,objects:{}},l=(a??[]).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));_(l);let u={...c,name:String(c?.name??t),objects:c?.objects??{},fields:c?.fields??{}};if(n){let e=Qc(u,l.map(e=>e.name));h({...u,objects:e.objects,fields:e.fields})}else h(u)}catch(e){D(e?.message??String(e))}finally{r||C(!1)}})(),()=>{r=!0}},[s,e,t,n,a]);async function ne(e){if(!v[e])try{let t=(await s.list(`field`)??[]).map(e=>e?.item??e).filter(t=>String(t?.object??``)===e).map(e=>({name:String(e?.name??``),label:e?.label})).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));y(n=>({...n,[e]:t}))}catch{y(t=>({...t,[e]:[]}))}}function M(e){x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),ne(e)),n})}function re(e,t,n){h(r=>{let i={...r.objects[e]??{},[t]:n};return t===`viewAllRecords`&&n&&(i.allowRead=!0),t===`modifyAllRecords`&&n&&(i.allowEdit=!0,i.allowRead=!0),{...r,objects:{...r.objects,[e]:i}}})}function ie(e,t){h(n=>{let r=t===`none`?{}:t===`all`?Object.fromEntries(p.map(e=>[e.key,!0])):t===`crud`?{allowCreate:!0,allowRead:!0,allowEdit:!0,allowDelete:!0}:{allowRead:!0};return{...n,objects:{...n.objects,[e]:r}}})}function ae(e,t,n,r){let i=`${e}.${t}`;h(e=>{let t={...e.fields??{}},a={...t[i]??{readable:!0,editable:!1},[n]:r};return n===`readable`&&!r&&(a.editable=!1),n===`editable`&&r&&(a.readable=!0),t[i]=a,{...e,fields:t}})}function oe(e){if(!n)return e;let t=Qc(e,g.map(e=>e.name));return{...e,objects:t.objects,fields:t.fields}}async function N(t,i){let a=i??m;T(!0),D(null);try{let i=a;if(n){let t=g.map(e=>e.name);i=$c((await s.layered(e,a.name).catch(()=>null))?.effective??a,a,t)}if(await s.save(e,a.name,i,{force:t,...n?{mode:`draft`,packageId:n}:{}}),n)h(oe(i)),r?.();else{let t=await s.layered(e,a.name);h(oe(t.effective??i))}k(null)}catch(e){if(e?.status===409&&e?.code===`destructive_change`){let t=e?.body?.issues??[];k({issues:Array.isArray(t)?t:[],pending:a})}else D(e?.message??String(e))}finally{T(!1)}}let P=X.useMemo(()=>{let e=A.trim().toLowerCase();return g.filter(t=>{if(ee){let e=m.objects[t.name];if(!e||!Object.values(e).some(Boolean))return!1}return e?t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e):!0})},[g,A,ee,m.objects]),se=[{label:f(`perm.stat.objectsGranted`),value:Object.values(m.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:f(`perm.stat.fieldOverrides`),value:Object.keys(m.fields??{}).length}];return S?(0,Y.jsx)(bo,{entry:l,itemName:t,children:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}),` `,f(`perm.loading`).replace(`{name}`,t)]})}):(0,Y.jsxs)(bo,{entry:l??{type:e,label:e},itemName:t,subtitle:m.isProfile?f(`perm.subtitle.profile`):f(`perm.subtitle.set`),stats:se,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:()=>o(`./history?type=${encodeURIComponent(e)}`),children:[(0,Y.jsx)(pn,{className:`h-4 w-4 mr-1`}),` `,f(`engine.edit.history`)]}),u&&(0,Y.jsxs)(H,{size:`sm`,onClick:()=>N(!1),disabled:w,children:[w?(0,Y.jsx)(U,{className:`h-4 w-4 mr-1 animate-spin`}):(0,Y.jsx)(Pn,{className:`h-4 w-4 mr-1`}),f(`engine.edit.save`)]})]}),children:[(0,Y.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[E&&(0,Y.jsxs)(`div`,{className:`m-4 rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive flex items-start gap-2`,children:[(0,Y.jsx)(I,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{children:E})]}),(0,Y.jsxs)(`div`,{className:`px-6 py-3 border-b bg-muted/30 flex flex-wrap items-end gap-4`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{htmlFor:`perm-name`,className:`text-xs`,children:f(`perm.field.name`)}),(0,Y.jsx)(V,{id:`perm-name`,value:m.name,disabled:!u,onChange:e=>h(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{htmlFor:`perm-label`,className:`text-xs`,children:f(`perm.field.label`)}),(0,Y.jsx)(V,{id:`perm-label`,value:m.label??``,disabled:!u,onChange:e=>h(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pb-1`,children:[(0,Y.jsx)(Er,{id:`perm-is-profile`,checked:!!m.isProfile,disabled:!u,onCheckedChange:e=>h(t=>({...t,isProfile:!!e}))}),(0,Y.jsx)(z,{htmlFor:`perm-is-profile`,className:`text-xs`,children:f(`perm.field.isProfile`)})]}),!u&&(0,Y.jsx)(R,{variant:`secondary`,className:`ml-auto`,children:f(`perm.readOnly`)})]}),(0,Y.jsxs)(`div`,{className:`px-6 py-3 border-b flex items-center gap-3`,children:[(0,Y.jsx)(V,{placeholder:f(`perm.filter.placeholder`),value:A,onChange:e=>j(e.target.value),className:`h-8 w-72`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Er,{id:`only-enabled`,checked:ee,onCheckedChange:e=>te(!!e)}),(0,Y.jsx)(z,{htmlFor:`only-enabled`,className:`text-xs`,children:f(`perm.filter.onlyGranted`)})]}),(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[P.length,` / `,g.length,` `,f(`perm.stat.objectsSuffix`)]})]}),(0,Y.jsx)(`div`,{className:`px-6 py-2 border-b flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground`,children:p.map(e=>(0,Y.jsxs)(`span`,{className:`whitespace-nowrap`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:e.short}),` `,e.tip]},e.key))}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,Y.jsx)(nl,{objects:P,draft:m,expanded:b,fieldsByObject:v,writable:u,objectActions:p,t:f,onToggleExpand:M,onObjectPerm:re,onFieldPerm:ae,onBulkSet:ie})}),(0,Y.jsx)(`div`,{className:`shrink-0 border-t max-h-80 overflow-auto bg-background`,children:(0,Y.jsx)(Yc,{permissionSetName:t})})]}),(0,Y.jsx)(St,{open:!!O,onOpenChange:e=>!e&&k(null),children:(0,Y.jsxs)(Pt,{children:[(0,Y.jsxs)(ar,{children:[(0,Y.jsxs)(Le,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(I,{className:`h-4 w-4 text-amber-500`}),` `,f(`engine.edit.destructive`)]}),(0,Y.jsx)(Ee,{children:f(`engine.edit.destructiveHint`)})]}),(0,Y.jsx)(`ul`,{className:`text-sm space-y-1 max-h-64 overflow-auto`,children:O?.issues.map((e,t)=>(0,Y.jsxs)(`li`,{className:`border-l-2 border-amber-500 pl-2`,children:[e.kind&&(0,Y.jsx)(R,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,Y.jsxs)(Ve,{children:[(0,Y.jsx)(H,{variant:`ghost`,onClick:()=>k(null),children:f(`engine.cancel`)}),(0,Y.jsxs)(H,{variant:`destructive`,onClick:()=>O&&N(!0,O.pending),disabled:w,children:[w&&(0,Y.jsx)(U,{className:`h-4 w-4 mr-1 animate-spin`}),f(`engine.edit.forceSave`)]})]})]})})]})}function nl({objects:e,draft:t,expanded:n,fieldsByObject:r,writable:i,objectActions:a,t:o,onToggleExpand:s,onObjectPerm:c,onFieldPerm:l,onBulkSet:u}){return(0,Y.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,Y.jsx)(`thead`,{className:`sticky top-0 bg-background border-b z-10`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`text-left px-4 py-2 font-medium w-72`,children:o(`perm.col.object`)}),a.map(e=>(0,Y.jsx)(`th`,{className:`px-2 py-2 font-medium text-center w-14`,title:e.tip,children:e.short},e.key)),(0,Y.jsx)(`th`,{className:`px-2 py-2 font-medium w-44 text-right`,children:o(`perm.col.bulk`)})]})}),(0,Y.jsxs)(`tbody`,{children:[e.length===0&&(0,Y.jsx)(`tr`,{children:(0,Y.jsx)(`td`,{colSpan:a.length+2,className:`px-4 py-8 text-center text-muted-foreground`,children:o(`perm.filter.empty`)})}),e.map(e=>{let d=t.objects[e.name]??{},f=n.has(e.name);return(0,Y.jsxs)(X.Fragment,{children:[(0,Y.jsxs)(`tr`,{className:`border-b hover:bg-muted/30`,children:[(0,Y.jsx)(`td`,{className:`px-2 py-1.5 align-middle`,children:(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name),className:`inline-flex items-center gap-1.5 hover:text-foreground`,children:[f?(0,Y.jsx)(ke,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(N,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),e.label&&(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,e.name,`)`]})]})}),a.map(t=>(0,Y.jsx)(`td`,{className:`text-center px-2 py-1.5`,children:(0,Y.jsx)(ot,{checked:!!d[t.key],disabled:!i,onCheckedChange:n=>c(e.name,t.key,!!n),"aria-label":`${e.name} ${t.tip}`})},t.key)),(0,Y.jsxs)(`td`,{className:`px-2 py-1.5 text-right space-x-1`,children:[(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`read`),children:o(`perm.bulk.read`)}),(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`crud`),children:o(`perm.bulk.crud`)}),(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`all`),children:o(`perm.bulk.all`)}),(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`none`),children:o(`perm.bulk.none`)})]})]}),f&&(0,Y.jsx)(`tr`,{className:`bg-muted/10`,children:(0,Y.jsx)(`td`,{colSpan:a.length+2,className:`px-12 py-3`,children:(0,Y.jsx)(rl,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l})})})]},e.name)})]})]})}function rl({objectName:e,fields:t,fieldsState:n,writable:r,t:i,onFieldPerm:a}){return t?t.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.empty`)}):(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`text-left py-1 font-medium`,children:i(`perm.field.col.name`)}),(0,Y.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.read`),children:i(`perm.field.read`)}),(0,Y.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.edit`),children:i(`perm.field.edit`)})]})}),(0,Y.jsx)(`tbody`,{children:t.map(t=>{let i=n[`${e}.${t.name}`]??{readable:!0,editable:!1};return(0,Y.jsxs)(`tr`,{className:`border-t border-muted`,children:[(0,Y.jsxs)(`td`,{className:`py-1`,children:[t.label??t.name,t.label&&(0,Y.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`(`,t.name,`)`]})]}),(0,Y.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,Y.jsx)(ot,{checked:!!i.readable,disabled:!r,onCheckedChange:n=>a(e,t.name,`readable`,!!n),"aria-label":`${e}.${t.name} readable`})}),(0,Y.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,Y.jsx)(ot,{checked:!!i.editable,disabled:!r,onCheckedChange:n=>a(e,t.name,`editable`,!!n),"aria-label":`${e}.${t.name} editable`})})]},t.name)})})]}):(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]})}function il(){Eo({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>al(e.fields),groupLabel:`Fields`,order:5}]}),Eo({type:`__object_index`,label:`Index`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`index`,embeddedPath:`indexes`,extract:e=>{let t=e.indexes;return Array.isArray(t)?t.map((e,t)=>{let n=Array.isArray(e.fields)?e.fields.join(`,`):``;return{name:n?`idx_${n}`:`index_${t}`,...e}}):[]},groupLabel:`Indexes`,order:10}]}),Eo({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>al(e.validations),groupLabel:`Embedded Validations`,order:15}]}),Eo({type:`hook`,anchors:[{anchorType:`object`,match:wo(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{events:[]}}),Eo({type:`page`,anchors:[{anchorType:`object`,match:wo(`object`),groupLabel:`Pages`,order:40}],createFields:[`label`,`name`,`object`,`type`,`kind`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`type`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable page title.`},name:{type:`string`,title:`Name`,description:`Page key (snake_case).`,pattern:`^[a-z_][a-z0-9_]*$`},type:{type:`string`,title:`Page type`,enum:[`list`,`record`,`home`,`app`,`utility`],default:`list`,description:`List / Interface page = a data view (Airtable-style: columns, filters, visualizations). Record page renders one object record.`},object:{type:`string`,title:`Object`,widget:`ref:object`,description:`The object this page reads from — the data source for a list page, or the record object for a record page.`},kind:{type:`string`,title:`Kind`,enum:[`full`,`slotted`],default:`full`,description:`full = the whole page; slotted = override only named slots of the default.`}}},createDefaults:{type:`list`,kind:`full`,regions:[]},createSeed:async(e,{client:t})=>{if(e?.type===`list`)return e?.object?{interfaceConfig:{source:String(e.object)}}:{};if(e?.type!==`record`||!e?.object)return{};try{let n=await t.get(`object`,String(e.object));if(!n||typeof n!=`object`)return{};let{buildDefaultPageSchema:r}=await a(async()=>{let{buildDefaultPageSchema:e}=await import(`./plugins-views-CibWNUsP.js`).then(e=>e.t);return{buildDefaultPageSchema:e}},__vite__mapDeps([0]),import.meta.url),i=r(n),o={};return Array.isArray(i?.regions)&&i.regions.length&&(o.regions=i.regions),i?.template&&(o.template=i.template),o}catch{return{}}}}),Eo({type:`view`,anchors:[{anchorType:`object`,match:wo([`object`,`config.data.object`]),groupLabel:`Views`,order:30}],createFields:[`label`,`name`,`object`,`kind`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`object`,`kind`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable view name.`},name:{type:`string`,title:`Name`,description:`View key (snake_case). Qualified to <object>.<key> on save.`,pattern:`^[a-z_][a-z0-9_]*$`},object:{type:`string`,title:`Object`,description:`The object this view displays.`},kind:{type:`string`,title:`View kind`,enum:[`grid`,`kanban`,`gallery`,`calendar`,`timeline`,`gantt`,`chart`],default:`grid`,description:`Pick a starter layout. Switch later in the designer.`}}},createBuildBody:e=>{let t=String(e.object??``),n=String(e.name??``);return{name:n.includes(`.`)||!t?n:`${t}.${n}`,object:t,viewKind:`list`,label:e.label,config:{type:e.kind||`grid`,columns:[],data:{provider:`object`,object:t}}}}}),Eo({type:`flow`,anchors:[{anchorType:`object`,match:wo([`object`,`on.object`,`trigger.object`]),groupLabel:`Flows`,order:50}],createFields:[`label`,`name`,`type`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{nodes:[],edges:[]}}),Eo({type:`trigger`,anchors:[{anchorType:`object`,match:wo([`object`,`on.object`]),groupLabel:`Triggers`,order:52}],createFields:[`label`,`name`,`object`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}]}),Eo({type:`validation`,anchors:[{anchorType:`object`,match:wo(`object`),groupLabel:`Validations`,order:25}],createFields:[`label`,`name`,`message`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`message`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable rule name.`},name:{type:`string`,title:`Name`,description:`Machine name (snake_case). Used in URLs.`,pattern:`^[a-z_][a-z0-9_]*$`},message:{type:`string`,title:`Error message`,description:`Shown to the user when the rule blocks save.`}}},createDefaults:{type:`script`,active:!0,events:[`insert`,`update`],priority:10,severity:`error`,condition:`false`}}),Eo({type:`permission`,anchors:[{anchorType:`object`,match:(e,t)=>{let n=e?.objects;return!!n&&typeof n==`object`&&t in n},groupLabel:`Permissions`,order:60}],createFields:[`label`,`name`,`isProfile`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{objects:{}}}),Eo({type:`action`,anchors:[{anchorType:`object`,match:wo([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{type:`script`,body:{language:`js`,source:`return { success: true };`}}}),Eo({type:`dashboard`,anchors:[{anchorType:`object`,match:wo([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),Eo({type:`report`,anchors:[{anchorType:`object`,match:wo([`object`,`data.object`]),groupLabel:`Reports`,order:81}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{type:`summary`,drilldown:!0}}),Eo({type:`object`,iconName:`database`,domain:`data`,createFields:[`label`,`pluralLabel`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0},{from:`label`,to:`pluralLabel`,transform:`plural-en`,untilUserEdits:!0}],createDefaults:{fields:{}},searchableFields:[`name`,`label`,`pluralLabel`,`description`],listColumns:[{key:`name`,label:`Name`,width:`24%`},{key:`label`,label:`Label`,width:`22%`},{key:`pluralLabel`,label:`Plural`,width:`22%`},{key:`fields`,label:`Fields`,width:`90px`,render:e=>e==null?`—`:Array.isArray(e)?e.length:typeof e==`object`?Object.keys(e).length:0},{key:`description`,label:`Description`}]})}function al(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var ol={name:{type:`string`,title:`Name`,description:`Machine name. snake_case, used as the URL path and DB key.`,pattern:`^[a-z_][a-z0-9_]*$`},label:{type:`string`,title:`Label`,description:`Human-readable display name.`},description:{type:`string`,title:`Description`,format:`multiline`}},sl={role:{type:`object`,title:`Role`,required:[`name`],properties:{...ol,level:{type:`string`,title:`Level`,description:`Coarse seniority tier (used by UI / sort order).`,enum:[`member`,`lead`,`manager`,`director`,`executive`,`admin`]},parentRole:{type:`string`,title:`Parent Role`,description:`Optional parent role name for hierarchy.`}}},profile:{type:`object`,title:`Profile`,required:[`name`],properties:{...ol,isProfile:{type:`boolean`,title:`Is profile`,description:`Profiles are mutually exclusive (one per user).`},objects:{type:`object`,title:`Object Permissions`,description:`Edit this via the Permission Matrix tab for a row-by-row UI.`}}},permission:{type:`object`,title:`Permission`,required:[`id`,`resource`,`actions`,`description`],properties:{id:{type:`string`,title:`ID`,description:`Stable identifier (e.g. crm.account.read).`},resource:{type:`string`,title:`Resource`,description:`What this permission applies to.`,enum:[`data.object`,`data.record`,`data.field`,`ui.view`,`ui.dashboard`,`ui.report`,`system.config`,`system.plugin`,`system.api`,`system.service`,`storage.file`,`storage.database`,`network.http`,`network.websocket`,`process.spawn`,`process.env`]},actions:{type:`array`,title:`Actions`,description:`Permitted operations on the resource.`,items:{type:`string`,enum:[`create`,`read`,`update`,`delete`,`execute`,`admin`,`manage`,`configure`,`import`,`export`,`share`]}},description:{type:`string`,title:`Description`,description:`Why this permission exists (shown in admin UIs).`},scope:{type:`string`,title:`Scope`,enum:[`tenant`,`user`,`plugin`,`global`,`resource`],default:`tenant`},required:{type:`boolean`,title:`Required`,description:`Must be present for the holder to function.`},justification:{type:`string`,title:`Justification`}}},translation:{type:`object`,title:`Translation Bundle`,required:[`name`],properties:{name:{...ol.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:ol.label,description:ol.description,locale:{type:`string`,title:`Locale`,description:`BCP-47 tag, e.g. en, zh-Hans, ja-JP.`},strings:{type:`object`,title:`Strings`,description:`Key → translated string map.`}}},tool:{type:`object`,title:`AI Tool`,required:[`name`],properties:{...ol,kind:{type:`string`,title:`Kind`,enum:[`function`,`http`,`mcp`]},inputSchema:{type:`object`,title:`Input Schema (JSON Schema)`},outputSchema:{type:`object`,title:`Output Schema (JSON Schema)`}}},skill:{type:`object`,title:`AI Skill`,required:[`name`],properties:{...ol,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...ol,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...ol,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...ol,type:{type:`string`,title:`View Type`,enum:[`grid`,`kanban`,`calendar`,`gantt`,`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]}}},dashboard:{type:`object`,title:`Dashboard`,required:[`name`],properties:{...ol,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...ol,object:{type:`string`,title:`Object`},filters:{type:`array`,title:`Filters`,items:{type:`object`}}}},book:{type:`object`,title:`Documentation Book`,required:[`name`,`groups`],properties:{...ol,slug:{type:`string`,title:`Slug`,description:`Portal URL segment; defaults to the name without its package prefix.`},icon:{type:`string`,title:`Icon`},order:{type:`number`,title:`Order`,description:`Orders books within the portal.`},audience:{title:`Audience`,description:`Access audience. 'org' (default) inherits the package grant; 'public' is anonymously readable; { profile } gates by role.`,oneOf:[{type:`string`,enum:[`org`,`public`]},{type:`object`,title:`Role-gated`,properties:{profile:{type:`string`,title:`Profile`}},required:[`profile`]}]},groups:{type:`array`,title:`Groups (spine)`,description:`Ordered sections. Membership is derived from each group's include rule — edit the structure visually in the Preview tab.`,items:{type:`object`,required:[`key`,`label`],properties:{key:{type:`string`,title:`Key`,pattern:`^[a-z][a-z0-9_]*$`},label:{type:`string`,title:`Label`},order:{type:`number`,title:`Order`},include:{title:`Include rule`,description:`Glob over doc names (e.g. crm_guide_*) or { tag }.`},package:{type:`string`,title:`Package scope`},pages:{type:`array`,title:`Explicit pages (override)`,items:{}}}}}}},email_template:{type:`object`,title:`Email Template`,required:[`name`,`label`,`subject`,`bodyHtml`],properties:{...ol,category:{type:`string`,title:`Category`,enum:[`auth`,`notification`,`workflow`,`marketing`,`custom`],default:`custom`},locale:{type:`string`,title:`Locale`,default:`en-US`,description:`BCP-47 tag (en-US, zh-CN, …)`},subject:{type:`string`,title:`Subject`,description:`Supports {{var.path}} interpolation`},bodyHtml:{type:`string`,title:`HTML Body`,format:`multiline`},bodyText:{type:`string`,title:`Plain-Text Body`,format:`multiline`},variables:{type:`array`,title:`Variables`,items:{type:`object`}},fromOverride:{type:`object`,title:`From Override`},replyTo:{type:`string`,title:`Reply-To`},active:{type:`boolean`,title:`Active`,default:!0},isSystem:{type:`boolean`,title:`System Template`,default:!1}}}};function cl(){for(let[e,t]of Object.entries(sl))Eo({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}var ll=[{value:`managed`,label:`Managed (ObjectStack owns the schema)`},{value:`external`,label:`External (read existing schema as-is)`},{value:`validate-only`,label:`Validate only`}],ul=``.replace(/\/+$/,``),dl=e=>e.format===`password`;function fl(e){let t=e?.configSchema?.properties??{},n={};for(let[e,r]of Object.entries(t))dl(r)||r.default!==void 0&&(n[e]=r.default);return n}function pl(e){let t=X.useMemo(()=>d(),[]),n=ti(),[r,i]=X.useState([]),[a,o]=X.useState(!0),[s,c]=X.useState(null),l=X.useCallback(async(e,n)=>{let r=await t(`${ul}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`},...n}),i=await r.text(),a=i;try{a=JSON.parse(i)}catch{}if(!r.ok)throw Error(a&&(a.message||a.error)||`HTTP ${r.status}`);return a},[t]),u=X.useCallback(async()=>{o(!0);try{let e=await l(`/api/v1/datasources`);i(Array.isArray(e?.datasources)?e.datasources:[])}catch(e){Hr.error(`Load datasources: ${e.message}`),i([])}finally{o(!1)}},[l]);X.useEffect(()=>{u()},[u]);let f=async e=>{c(`test:${e}`);try{let t=await l(`/api/v1/datasources/${encodeURIComponent(e)}/test`,{method:`POST`,body:`{}`});Hr.success(t?.ok===!1?`${e}: ${t?.error??`failed`}`:`${e}: connection ok${t?.latencyMs==null?``:` (${t.latencyMs}ms)`}`),u()}catch(t){Hr.error(`${e}: ${t.message}`)}finally{c(null)}},p=async e=>{if(window.confirm(`Delete datasource “${e}”? This cannot be undone.`)){c(`del:${e}`);try{await l(`/api/v1/datasources/${encodeURIComponent(e)}`,{method:`DELETE`}),Hr.success(`Deleted ${e}.`),u()}catch(t){Hr.error(`Delete ${e}: ${t.message}`)}finally{c(null)}}},[m,h]=X.useState([]),[g,_]=X.useState(!1),[v,y]=X.useState(null),[b,x]=X.useState(null),[S,C]=X.useState(!1),[w,T]=X.useState(!1),[E,D]=X.useState(null),[O,k]=X.useState(!1),A=X.useCallback(async()=>{if(m.length)return m;try{let e=await l(`/api/v1/datasources/drivers`),t=Array.isArray(e?.drivers)?e.drivers:[];return h(t),t}catch(e){return Hr.error(`Load drivers: ${e.message}`),[]}},[l,m]),j=X.useMemo(()=>m.find(e=>e.id===b?.driver),[m,b?.driver]),ee=async()=>{let e=await A(),t=e.find(e=>e.id!==`memory`)??e[0];y(null),C(!1),D(null),x({name:``,label:``,driver:t?.id??``,schemaMode:`managed`,config:fl(t),secret:``}),_(!0)},te=async e=>{let t=await A();c(`edit:${e.name}`);try{let n=(await l(`/api/v1/datasources/${encodeURIComponent(e.name)}`))?.datasource??{};y(e.name),C(!!n.hasSecret),D(null),x({name:n.name??e.name,label:n.label??``,driver:n.driver??e.driver??t[0]?.id??``,schemaMode:n.schemaMode??`managed`,config:{...n.config??{}},secret:``}),_(!0)}catch(t){Hr.error(`Open ${e.name}: ${t.message}`)}finally{c(null)}},ne=e=>{x(t=>t&&{...t,driver:e,config:fl(m.find(t=>t.id===e)),secret:``}),D(null)},M=(e,t)=>x(n=>n&&{...n,config:{...n.config,[e]:t}}),re=e=>{let t={label:e.label||void 0,driver:e.driver,schemaMode:e.schemaMode,config:e.config};return e.secret&&(t.secret=e.secret),t},ie=async()=>{if(b){k(!0),D(null);try{let e=await l(`/api/v1/datasources/test`,{method:`POST`,body:JSON.stringify({driver:b.driver,config:b.config,...b.secret?{secret:b.secret}:{}})}),t=e?.result??e;t?.ok===!1?D({ok:!1,text:t?.error??`Connection failed`}):D({ok:!0,text:`Connection ok${t?.latencyMs==null?``:` (${t.latencyMs}ms)`}`})}catch(e){D({ok:!1,text:e.message})}finally{k(!1)}}},ae=async()=>{if(b){T(!0);try{v?(await l(`/api/v1/datasources/${encodeURIComponent(v)}`,{method:`PATCH`,body:JSON.stringify(re(b))}),Hr.success(`Updated ${v}.`)):(await l(`/api/v1/datasources`,{method:`POST`,body:JSON.stringify({name:b.name,...re(b)})}),Hr.success(`Created ${b.name}.`)),_(!1),u()}catch(e){Hr.error(`Save: ${e.message}`)}finally{T(!1)}}},oe=v?!0:/^[a-z_][a-z0-9_]*$/.test(b?.name??``),N=!!b&&!!b.driver&&oe&&!w,[P,se]=X.useState(null),[ce,le]=X.useState(null),[ue,de]=X.useState(new Set),[fe,pe]=X.useState(!1),me=async e=>{se(e),le(null),de(new Set);try{let t=await l(`/api/v1/datasources/${encodeURIComponent(e)}/remote-tables`);le(Array.isArray(t?.tables)?t.tables:[])}catch(t){Hr.error(`Introspect ${e}: ${t.message}`),le([])}},he=e=>de(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),ge=async()=>{if(!P||ue.size===0)return;pe(!0);let e=0,t=[];for(let r of ue)try{let{draft:t}=await l(`/api/v1/datasources/${encodeURIComponent(P)}/object-draft`,{method:`POST`,body:JSON.stringify({table:r})});await n.save(`object`,t.name,t.definition),e+=1}catch(e){t.push(`${r}: ${e.message}`)}pe(!1),e&&Hr.success(`Synced ${e} object${e>1?`s`:``} from ${P}.`),t.length&&Hr.error(`Failed: ${t.join(`; `)}`),se(null)},_e=(e,t)=>{let n=t.title||e,r=(j?.configSchema?.required??[]).includes(e);if(dl(t))return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(z,{className:`text-xs`,children:[n,r&&!v?` *`:``]}),(0,Y.jsx)(V,{type:`password`,value:b?.secret??``,placeholder:v&&S?`•••••••• (leave blank to keep)`:``,onChange:e=>x(t=>t&&{...t,secret:e.target.value})}),t.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]},e);let i=b?.config[e];if(t.type===`boolean`)return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(z,{className:`text-xs`,children:n}),t.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]}),(0,Y.jsx)(Er,{checked:!!i,onCheckedChange:t=>M(e,t)})]},e);if(Array.isArray(t.enum))return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(z,{className:`text-xs`,children:[n,r?` *`:``]}),(0,Y.jsxs)(Ue,{value:i==null?``:String(i),onValueChange:t=>M(e,t),children:[(0,Y.jsx)(Ut,{children:(0,Y.jsx)(Bt,{placeholder:`Select…`})}),(0,Y.jsx)(cr,{children:t.enum.map(e=>(0,Y.jsx)(ze,{value:String(e),children:String(e)},String(e)))})]})]},e);let a=t.type===`number`||t.type===`integer`;return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(z,{className:`text-xs`,children:[n,r?` *`:``]}),(0,Y.jsx)(V,{type:a?`number`:`text`,value:i==null?``:String(i),onChange:t=>M(e,a?t.target.value===``?void 0:Number(t.target.value):t.target.value)}),t.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]},e)};return(0,Y.jsxs)(`div`,{className:`mx-auto max-w-4xl px-6 py-8`,children:[(0,Y.jsxs)(`div`,{className:`mb-6 flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold`,children:[(0,Y.jsx)(Yn,{className:`h-5 w-5`}),` Datasources`]}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Connect external databases and sync their tables in as objects.`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>void u(),disabled:a,children:[(0,Y.jsx)(Dt,{className:`mr-1.5 h-4 w-4`+(a?` animate-spin`:``)}),` Refresh`]}),(0,Y.jsxs)(H,{size:`sm`,onClick:()=>void ee(),children:[(0,Y.jsx)(L,{className:`mr-1.5 h-4 w-4`}),` New datasource`]})]})]}),a?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-12 text-sm text-muted-foreground`,children:[(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Loading…`]}):r.length===0?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-dashed bg-muted/20 py-16 text-center text-sm text-muted-foreground`,children:[`No datasources yet. Click `,(0,Y.jsx)(`span`,{className:`font-medium`,children:`New datasource`}),` to connect one.`]}):(0,Y.jsx)(`div`,{className:`divide-y rounded-lg border bg-card`,children:r.map(e=>{let t=e.origin===`code`;return(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,Y.jsx)(Yn,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:e.label||e.name}),(0,Y.jsx)(`code`,{className:`text-[11px] text-muted-foreground`,children:e.name})]}),(0,Y.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono`,children:e.driver}),e.status&&(0,Y.jsxs)(`span`,{children:[`· `,e.status]}),e.origin&&(0,Y.jsxs)(`span`,{children:[`· `,e.origin]})]})]}),(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,disabled:s===`test:${e.name}`,onClick:()=>void f(e.name),children:[s===`test:${e.name}`?(0,Y.jsx)(U,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,Y.jsx)(Rt,{className:`mr-1.5 h-4 w-4`}),` Test`]}),(0,Y.jsxs)(H,{variant:`secondary`,size:`sm`,onClick:()=>void me(e.name),children:[(0,Y.jsx)(Zn,{className:`mr-1.5 h-4 w-4`}),` Sync objects`]}),!t&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(H,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,title:`Edit`,disabled:s===`edit:${e.name}`,onClick:()=>void te(e),children:s===`edit:${e.name}`?(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}):(0,Y.jsx)(Gn,{className:`h-4 w-4`})}),(0,Y.jsx)(H,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,title:`Delete`,disabled:s===`del:${e.name}`,onClick:()=>void p(e.name),children:s===`del:${e.name}`?(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}):(0,Y.jsx)(sr,{className:`h-4 w-4`})})]})]},e.name)})}),(0,Y.jsx)(St,{open:g,onOpenChange:e=>{e||_(!1)},children:(0,Y.jsxs)(Pt,{className:`max-w-lg`,children:[(0,Y.jsxs)(ar,{children:[(0,Y.jsx)(Le,{children:v?`Edit “${v}”`:`New datasource`}),(0,Y.jsx)(Ee,{children:v?`Update the connection. Leave the credential blank to keep the current one.`:`Connect an external database. Credentials are encrypted and never stored in metadata.`})]}),b&&(0,Y.jsxs)(`div`,{className:`max-h-[60vh] space-y-3 overflow-y-auto pr-1`,children:[!v&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs`,children:`Name *`}),(0,Y.jsx)(V,{value:b.name,placeholder:`my_database`,onChange:e=>x(t=>t&&{...t,name:e.target.value})}),!oe&&b.name.length>0&&(0,Y.jsx)(`p`,{className:`text-[11px] text-destructive`,children:`Lowercase letters, digits, and underscores; must not start with a digit.`})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs`,children:`Label`}),(0,Y.jsx)(V,{value:b.label,placeholder:`Human-friendly name`,onChange:e=>x(t=>t&&{...t,label:e.target.value})})]}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs`,children:`Driver *`}),(0,Y.jsxs)(Ue,{value:b.driver,onValueChange:ne,disabled:!!v,children:[(0,Y.jsx)(Ut,{children:(0,Y.jsx)(Bt,{placeholder:`Choose a driver`})}),(0,Y.jsx)(cr,{children:m.map(e=>(0,Y.jsx)(ze,{value:e.id,children:e.label},e.id))})]}),j?.description&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:j.description})]}),Object.entries(j?.configSchema?.properties??{}).map(([e,t])=>_e(e,t)),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs`,children:`Schema mode`}),(0,Y.jsxs)(Ue,{value:b.schemaMode,onValueChange:e=>x(t=>t&&{...t,schemaMode:e}),children:[(0,Y.jsx)(Ut,{children:(0,Y.jsx)(Bt,{})}),(0,Y.jsx)(cr,{children:ll.map(e=>(0,Y.jsx)(ze,{value:e.value,children:e.label},e.value))})]})]}),E&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs `+(E.ok?`text-emerald-600`:`text-destructive`),children:[E.ok?(0,Y.jsx)(In,{className:`h-3.5 w-3.5`}):(0,Y.jsx)(gt,{className:`h-3.5 w-3.5`}),E.text]})]}),(0,Y.jsxs)(Ve,{className:`gap-2 sm:justify-between`,children:[(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,disabled:!b?.driver||O,onClick:()=>void ie(),children:[O?(0,Y.jsx)(U,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,Y.jsx)(Rt,{className:`mr-1.5 h-4 w-4`}),` Test connection`]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>_(!1),children:`Cancel`}),(0,Y.jsxs)(H,{size:`sm`,disabled:!N,onClick:()=>void ae(),children:[w&&(0,Y.jsx)(U,{className:`mr-1.5 h-4 w-4 animate-spin`}),v?`Save changes`:`Create datasource`]})]})]})]})}),(0,Y.jsx)(St,{open:!!P,onOpenChange:e=>{e||se(null)},children:(0,Y.jsxs)(Pt,{className:`max-w-lg`,children:[(0,Y.jsxs)(ar,{children:[(0,Y.jsxs)(Le,{children:[`Sync objects from “`,P,`”`]}),(0,Y.jsx)(Ee,{children:`Pick the remote tables to import as objects. Each becomes an object definition.`})]}),ce==null?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-8 text-sm text-muted-foreground`,children:[(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Introspecting…`]}):ce.length===0?(0,Y.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`No remote tables found on this datasource.`}):(0,Y.jsx)(`div`,{className:`max-h-[50vh] space-y-1 overflow-y-auto`,children:ce.map(e=>{let t=e.schema?`${e.schema}.${e.name}`:e.name;return(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-accent`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:ue.has(e.name),onChange:()=>he(e.name),className:`h-4 w-4`}),(0,Y.jsx)(`span`,{className:`flex-1`,children:t}),e.columnCount!=null&&(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[e.columnCount,` cols`]})]},t)})}),(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center justify-end gap-2`,children:[(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,onClick:()=>se(null),children:`Cancel`}),(0,Y.jsxs)(H,{size:`sm`,disabled:fe||ue.size===0,onClick:()=>void ge(),children:[fe?(0,Y.jsx)(U,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,Y.jsx)(Zn,{className:`mr-1.5 h-4 w-4`}),`Create `,ue.size||``,` object`,ue.size===1?``:`s`]})]})]})})]})}var ml=!1;function hl(){ml||(ml=!0,Eo({type:`datasource`,label:`Datasources`,domain:`data`,ListPage:pl}))}function Z({toolbar:e,children:t}){return(0,Y.jsxs)(`div`,{className:`rounded-lg border bg-background overflow-hidden flex flex-col h-full`,children:[e!=null&&(0,Y.jsx)(`div`,{className:`flex items-center justify-end border-b bg-muted/20 px-2 py-1 min-h-[32px]`,children:e}),(0,Y.jsx)(`div`,{className:`bg-background flex-1 min-h-0 overflow-auto`,children:t})]})}function gl({tone:e=`info`,children:t}){return(0,Y.jsxs)(`div`,{className:`m-4 rounded border p-3 text-sm flex items-start gap-2 ${e===`warn`?`text-amber-800 bg-amber-50 border-amber-200`:e===`error`?`text-destructive bg-destructive/5 border-destructive/30`:`text-muted-foreground border-muted`}`,children:[e!==`info`&&(0,Y.jsx)(rt,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,Y.jsx)(`div`,{className:`flex-1`,children:t})]})}function _l({icon:e,title:t,description:n,action:r,tone:i=`info`}){let a=i===`warn`?`text-amber-700 bg-amber-50/40 border-amber-200/60`:`text-muted-foreground border-dashed border-muted-foreground/25 bg-muted/10`,o=e??(0,Y.jsx)(tn,{className:`h-8 w-8 opacity-50`});return(0,Y.jsx)(`div`,{className:`h-full w-full flex items-center justify-center p-6`,children:(0,Y.jsxs)(`div`,{className:`max-w-md w-full rounded-lg border ${a} px-6 py-10 flex flex-col items-center gap-3 text-center`,children:[(0,Y.jsx)(`div`,{className:`text-foreground/60`,children:o}),(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground/90`,children:t}),n&&(0,Y.jsx)(`div`,{className:`text-xs leading-relaxed`,children:n}),r&&(0,Y.jsx)(`div`,{className:`mt-1`,children:r})]})})}var Q=class extends X.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e){console.error(`[MetadataPreview] render failed`,e)}render(){return this.state.error?(0,Y.jsxs)(gl,{tone:`error`,children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:`Preview failed to render`}),(0,Y.jsx)(`div`,{className:`text-xs mt-1 font-mono opacity-80`,children:this.state.error.message}),this.props.fallbackHint&&(0,Y.jsx)(`div`,{className:`text-xs mt-2 opacity-70`,children:this.props.fallbackHint})]}):this.props.children}};function vl({title:e,entries:t,selectedId:n,onSelect:r,onAdd:i,addLabel:a}){return t.length===0&&!i?null:(0,Y.jsxs)(`div`,{className:`border-b bg-muted/30 px-3 py-2`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-1.5`,children:e}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[t.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e)},className:B(`rounded border bg-background px-2 py-0.5 text-xs hover:border-primary/50 cursor-pointer`,n===e.id&&`ring-2 ring-primary border-primary`),children:e.label},e.id)),i&&(0,Y.jsxs)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i()},className:`rounded border border-dashed bg-background px-2 py-0.5 text-xs text-muted-foreground hover:border-primary hover:text-primary cursor-pointer inline-flex items-center gap-1`,"aria-label":a??`Add`,title:a??`Add`,children:[(0,Y.jsx)(L,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:a??`Add`})]})]})]})}var yl=X.lazy(async()=>({default:(await a(()=>import(`./dist-YwlXXOlT.js`).then(e=>e.n),[],import.meta.url)).default}));function bl(e){let t=e.languages.typescript;t.typescriptDefaults.setDiagnosticsOptions({noSemanticValidation:!0,noSyntaxValidation:!0,noSuggestionDiagnostics:!0}),t.typescriptDefaults.setCompilerOptions({jsx:t.JsxEmit.React,target:t.ScriptTarget.Latest,allowNonTsExtensions:!0,allowJs:!0,noEmit:!0})}function xl({draft:e,onPatch:t,readOnly:n,fallbackDelayMs:r=4e3,mode:i=`split`}){let a=e.kind===`react`?`react`:`html`,o=typeof e.source==`string`?e.source:``,[s,c]=X.useState(o),l=X.useRef(o);X.useEffect(()=>{o!==l.current&&(c(o),l.current=o)},[o]);let[u,d]=_c(r),[f,p]=X.useState(()=>typeof document<`u`&&document.documentElement.classList.contains(`dark`)?`vs-dark`:`light`);X.useEffect(()=>{if(typeof document>`u`)return;let e=document.documentElement,t=new MutationObserver(()=>p(e.classList.contains(`dark`)?`vs-dark`:`light`));return t.observe(e,{attributes:!0,attributeFilter:[`class`]}),()=>t.disconnect()},[]);let m=e=>{let n=e??``;c(n),l.current=n,t?.({source:n})},h=X.useMemo(()=>({...e,type:e.type??`page`}),[e]),g=(0,Y.jsx)(`div`,{ref:d,className:`h-full min-h-[260px] overflow-hidden bg-background`,children:u?(0,Y.jsx)(`textarea`,{value:s,onChange:e=>m(e.target.value),readOnly:n,spellCheck:!1,"aria-label":`Page source`,className:`h-full w-full resize-none bg-background p-3 font-mono text-xs leading-relaxed outline-none`}):(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsx)(pt,{className:`h-full w-full`}),children:(0,Y.jsx)(yl,{value:s,language:`typescript`,path:a===`react`?`page.tsx`:`page.html.tsx`,theme:f,beforeMount:bl,onChange:m,options:{readOnly:n,minimap:{enabled:!1},fontSize:12,lineNumbers:`on`,scrollBeyondLastLine:!1,automaticLayout:!0,folding:!0,wordWrap:`on`,tabSize:2,scrollbar:{verticalScrollbarSize:10,horizontalScrollbarSize:10}}})})}),v=(0,Y.jsx)(`div`,{className:`h-full min-h-[260px] overflow-auto bg-muted/20`,children:(0,Y.jsx)(Q,{fallbackHint:`The page source threw while rendering — fix the code in the Source tab.`,children:(0,Y.jsx)(_,{schema:h})})});return i===`editor`?g:i===`preview`?(0,Y.jsx)(Z,{hint:`page · ${a} source`,children:v}):(0,Y.jsx)(Z,{hint:`page · ${a} source`,children:(0,Y.jsxs)(`div`,{className:`grid h-full grid-cols-1 divide-y divide-border lg:grid-cols-2 lg:divide-x lg:divide-y-0`,children:[g,v]})})}var Sl={grid:{label:`Grid`,category:`data`,Icon:Vt},"object-grid":{label:`Table`,category:`data`,Icon:lr},"object-form":{label:`Form`,category:`data`,Icon:Nt},"object-metric":{label:`Metric`,category:`data`,Icon:ht},"object-kanban":{label:`Kanban`,category:`data`,Icon:xr},"page:header":{label:`Header`,category:`layout`,Icon:Xn},"page:footer":{label:`Footer`,category:`layout`,Icon:er},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:Bn},"page:tabs":{label:`Tabs`,category:`layout`,Icon:yt},"page:accordion":{label:`Accordion`,category:`layout`,Icon:Pe},"page:card":{label:`Card`,category:`layout`,Icon:br},"page:section":{label:`Section`,category:`layout`,Icon:Wt},"record:details":{label:`Record details`,category:`record`,Icon:Ce},"record:highlights":{label:`Highlights`,category:`record`,Icon:qn},"record:related_list":{label:`Related list`,category:`record`,Icon:Mt},"record:activity":{label:`Activity timeline`,category:`record`,Icon:Ye},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:Je},"record:path":{label:`Stage path`,category:`record`,Icon:Vn},"record:alert":{label:`Alert banner`,category:`record`,Icon:I},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:me},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:yr},"record:history":{label:`History`,category:`record`,Icon:pn},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:Nn},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:Vn},"global:search":{label:`Global search`,category:`navigation`,Icon:Xe},"ai:chat_window":{label:`AI chat window`,category:`ai`,Icon:cn},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:En},"element:text":{label:`Text`,category:`element`,Icon:wt},"element:number":{label:`Number`,category:`element`,Icon:vn},"element:image":{label:`Image`,category:`element`,Icon:mr},"element:divider":{label:`Divider`,category:`element`,Icon:_t},"element:button":{label:`Button`,category:`element`,Icon:nn},"element:definition-list":{label:`Definition list`,category:`element`,Icon:re},"element:repeater":{label:`Repeater`,category:`element`,Icon:tt}},Cl={data:`Data`,layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},wl=(()=>{let e={data:[],layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(Sl))e[n.category].push(t);return[`data`,`layout`,`record`,`element`,`navigation`,`ai`,`misc`].map(t=>({category:t,types:e[t]})).filter(e=>e.types.length>0)})(),Tl=fr,El={data:{icon:`text-emerald-500 dark:text-emerald-400`,badge:`border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-900 dark:bg-emerald-950/40 dark:text-emerald-300`},layout:{icon:`text-slate-500 dark:text-slate-400`,badge:`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-800 dark:bg-slate-900/40 dark:text-slate-300`},record:{icon:`text-blue-500 dark:text-blue-400`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`},navigation:{icon:`text-indigo-500 dark:text-indigo-400`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-900 dark:bg-indigo-950/40 dark:text-indigo-300`},element:{icon:`text-teal-500 dark:text-teal-400`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-900 dark:bg-teal-950/40 dark:text-teal-300`},ai:{icon:`text-violet-500 dark:text-violet-400`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`},misc:{icon:`text-zinc-500 dark:text-zinc-400`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900/40 dark:text-zinc-400`}};function Dl(e){return El[Sl[e]?.category??`misc`]}var Ol={"object-grid":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`columns`,label:`Columns`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`},{name:`pageSize`,label:`Page size`,kind:`number`,placeholder:`20`},{name:`striped`,label:`Striped rows`,kind:`boolean`},{name:`bordered`,label:`Bordered`,kind:`boolean`}],"object-form":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`mode`,label:`Mode`,kind:`select`,options:[{value:`create`,label:`Create`},{value:`edit`,label:`Edit`},{value:`view`,label:`View`}]},{name:`formType`,label:`Form type`,kind:`select`,options:[{value:`simple`,label:`Simple`},{value:`tabbed`,label:`Tabbed`},{value:`wizard`,label:`Wizard`},{value:`split`,label:`Split`},{value:`drawer`,label:`Drawer`},{value:`modal`,label:`Modal`}]},{name:`layout`,label:`Layout`,kind:`select`,options:[{value:`vertical`,label:`Vertical`},{value:`horizontal`,label:`Horizontal`},{value:`inline`,label:`Inline`},{value:`grid`,label:`Grid`}]},{name:`columns`,label:`Columns (grid layout)`,kind:`number`,placeholder:`2`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`},{name:`title`,label:`Title`,kind:`text`},{name:`description`,label:`Description`,kind:`text`}],"object-metric":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`label`,label:`Label`,kind:`text`},{name:`description`,label:`Description`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`colorVariant`,label:`Color`,kind:`color`,options:[{value:`default`,label:`Default`},{value:`blue`,label:`Blue`},{value:`teal`,label:`Teal`},{value:`orange`,label:`Orange`},{value:`purple`,label:`Purple`},{value:`success`,label:`Success`},{value:`warning`,label:`Warning`},{value:`danger`,label:`Danger`}]},{name:`format`,label:`Format`,kind:`select`,options:[{value:`number`,label:`Number`},{value:`currency`,label:`Currency`},{value:`percent`,label:`Percent`}]},{name:`prefix`,label:`Prefix`,kind:`text`},{name:`suffix`,label:`Suffix`,kind:`text`}],"object-kanban":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`groupField`,label:`Group by field`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`titleField`,label:`Title field`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`cardFields`,label:`Card fields`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`}],grid:[{name:`columns`,label:`Columns`,kind:`number`,placeholder:`3`},{name:`gap`,label:`Gap`,kind:`number`,placeholder:`4`}],"element:text":[{name:`content`,label:`Content`,kind:`text`,placeholder:`Text…`},{name:`variant`,label:`Variant`,kind:`select`,options:[{value:`heading`,label:`Heading`},{value:`subheading`,label:`Subheading`},{value:`body`,label:`Body`},{value:`caption`,label:`Caption`}]},{name:`align`,label:`Align`,kind:`select`,options:[{value:`left`,label:`Left`},{value:`center`,label:`Center`},{value:`right`,label:`Right`}]}],"element:image":[{name:`src`,label:`Source URL`,kind:`text`,placeholder:`https://…`},{name:`alt`,label:`Alt text`,kind:`text`},{name:`fit`,label:`Fit`,kind:`select`,options:[{value:`cover`,label:`Cover`},{value:`contain`,label:`Contain`},{value:`fill`,label:`Fill`}]}],"element:definition-list":[{name:`items`,label:`Items`,kind:`array`,addLabel:`Add item`,itemFields:[{name:`label`,label:`Label`,kind:`text`},{name:`value`,label:`Value`,kind:`text`}]},{name:`columns`,label:`Columns (1 or 2)`,kind:`number`,placeholder:`1`},{name:`inline`,label:`Inline (label · value)`,kind:`boolean`}],"element:repeater":[{name:`object`,label:`Object`,kind:`object-picker`},{name:`titleField`,label:`Title field`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`self`,objectProp:`object`},{name:`limit`,label:`Limit`,kind:`number`,placeholder:`10`},{name:`emptyText`,label:`Empty text`,kind:`text`},{name:`divided`,label:`Dividers between rows`,kind:`boolean`}],"element:number":[{name:`object`,label:`Object`,kind:`object-picker`},{name:`field`,label:`Field`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`aggregate`,label:`Aggregate`,kind:`select`,options:[{value:`count`,label:`Count`},{value:`sum`,label:`Sum`},{value:`avg`,label:`Average`},{value:`min`,label:`Min`},{value:`max`,label:`Max`}]},{name:`format`,label:`Format`,kind:`select`,options:[{value:`number`,label:`Number`},{value:`currency`,label:`Currency`},{value:`percent`,label:`Percent`}]},{name:`prefix`,label:`Prefix`,kind:`text`},{name:`suffix`,label:`Suffix`,kind:`text`}],"element:button":[{name:`label`,label:`Label`,kind:`text`},{name:`variant`,label:`Variant`,kind:`select`,options:[{value:`primary`,label:`Primary`},{value:`secondary`,label:`Secondary`},{value:`danger`,label:`Danger`},{value:`ghost`,label:`Ghost`},{value:`link`,label:`Link`}]},{name:`size`,label:`Size`,kind:`select`,options:[{value:`small`,label:`Small`},{value:`medium`,label:`Medium`},{value:`large`,label:`Large`}]},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`}],"page:header":[{name:`title`,label:`Title`,kind:`text`},{name:`subtitle`,label:`Subtitle`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`breadcrumb`,label:`Show breadcrumb`,kind:`boolean`}],"page:card":[{name:`title`,label:`Title`,kind:`text`},{name:`bordered`,label:`Bordered`,kind:`boolean`}],"page:tabs":[{name:`items`,label:`Tabs`,kind:`array`,addLabel:`Add tab`,itemFields:[{name:`key`,label:`Key`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"page:accordion":[{name:`title`,label:`Title`,kind:`text`},{name:`items`,label:`Sections`,kind:`array`,addLabel:`Add section`,itemFields:[{name:`value`,label:`Key`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"record:related_list":[{name:`objectName`,label:`Object`,kind:`object-picker`},{name:`relationshipField`,label:`Relationship field`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`title`,label:`Title`,kind:`text`},{name:`limit`,label:`Limit`,kind:`number`,placeholder:`10`}],"record:highlights":[{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`page`}],"record:details":[{name:`sections`,label:`Sections`,kind:`array`,addLabel:`Add section`,itemFields:[{name:`label`,label:`Label`,kind:`text`},{name:`columns`,label:`Columns`,kind:`number`,placeholder:`2`},{name:`fields`,label:`Fields`,kind:`field-list`,objectFrom:`page`}]}],"record:alert":[{name:`severity`,label:`Severity`,kind:`select`,options:[{value:`info`,label:`Info`},{value:`warning`,label:`Warning`},{value:`error`,label:`Error`},{value:`success`,label:`Success`}]},{name:`title`,label:`Title`,kind:`text`},{name:`body`,label:`Body`,kind:`text`},{name:`icon`,label:`Icon`,kind:`text`,placeholder:`lucide icon name`},{name:`dismissible`,label:`Dismissible`,kind:`boolean`}],"record:path":[{name:`statusField`,label:`Status field`,kind:`field-picker`,objectFrom:`page`},{name:`stages`,label:`Stages`,kind:`array`,addLabel:`Add stage`,itemFields:[{name:`value`,label:`Value`,kind:`text`},{name:`label`,label:`Label`,kind:`text`}]}],"record:quick_actions":[{name:`actionNames`,label:`Action names`,kind:`string-list`,placeholder:`action name`},{name:`location`,label:`Location`,kind:`select`,options:[{value:`record_header`,label:`Record header`},{value:`record_more`,label:`Record more menu`},{value:`record_section`,label:`Record section`},{value:`record_related`,label:`Record related`},{value:`list_toolbar`,label:`List toolbar`},{value:`list_item`,label:`List item`},{value:`global_nav`,label:`Global nav`}]}],"ai:chat_window":[{name:`agentName`,label:`Agent`,kind:`text`,placeholder:`agent name`},{name:`placeholder`,label:`Input placeholder`,kind:`text`}],"ai:input":[{name:`agentName`,label:`Agent`,kind:`text`,placeholder:`agent name`},{name:`placeholder`,label:`Input placeholder`,kind:`text`}]};function kl(e){return!!e&&Array.isArray(Ol[e])&&Ol[e].length>0}function Al(){let e=ti(),[t,n]=X.useState([]),[r,i]=X.useState(!0);return X.useEffect(()=>{let t=!1;return i(!0),e.list(`object`).then(e=>{if(t)return;let r=(e??[]).map(e=>e&&typeof e==`object`&&`item`in e?e.item:e).filter(e=>typeof e?.name==`string`&&e.name).map(e=>({value:e.name,label:e.label?`${e.label} (${e.name})`:e.name})).sort((e,t)=>e.value.localeCompare(t.value));n(r),i(!1)}).catch(()=>{t||(n([]),i(!1))}),()=>{t=!0}},[e]),{options:t,loading:r}}function jl(e){let{fields:t}=ki(e);return X.useMemo(()=>t.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),[t])}function Ml({label:e,value:t,onCommit:n,disabled:r}){let{options:i}=Al();return i.length===0?(0,Y.jsx)(G,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,Y.jsx)(W,{label:e,value:t||void 0,options:i,onCommit:n,disabled:r})}function Nl({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let a=jl(t);return!t||a.length===0?(0,Y.jsx)(G,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,Y.jsx)(W,{label:e,value:n||void 0,options:a,onCommit:r,disabled:i})}function Pl({label:e,objectName:t,value:n,onChange:r,disabled:i}){let a=jl(t),o=Array.isArray(n)?n:[];return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e}),o.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a.length>0?(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsxs)(Ue,{value:e?String(e):``,onValueChange:e=>{let n=[...o];n[t]=e,r(n)},disabled:i,children:[(0,Y.jsx)(Ut,{className:`h-8`,children:(0,Y.jsx)(Bt,{placeholder:`—`})}),(0,Y.jsx)(cr,{children:a.map(e=>(0,Y.jsx)(ze,{value:e.value,children:e.label},e.value))})]})}):(0,Y.jsx)(V,{className:`h-8 text-sm`,value:String(e??``),placeholder:`field name`,disabled:i,onChange:e=>{let n=[...o];n[t]=e.target.value,r(n)}}),(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:i,"aria-label":`Remove`,onClick:()=>r(o.filter((e,n)=>n!==t)),children:(0,Y.jsx)(Qe,{className:`h-4 w-4`})})]},t)),!i&&(0,Y.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...o,``]),children:[(0,Y.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]})}function Fl(e){if(e===void 0)return``;try{return JSON.stringify(e,null,2)}catch{return``}}function Il({label:e,value:t,onCommit:n,disabled:r}){let i=X.useMemo(()=>Fl(t),[t]),[a,o]=X.useState(i),[s,c]=X.useState(null);return X.useEffect(()=>{o(i),c(null)},[i]),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(`textarea`,{value:a,onChange:e=>o(e.target.value),onBlur:()=>{if(r)return;let e=a.trim();if(e===``){c(null),n(void 0);return}try{let t=JSON.parse(e);c(null),n(t)}catch{c(`Invalid JSON`)}},disabled:r,spellCheck:!1,rows:Math.min(12,Math.max(2,a.split(`
11
+ `).length)),className:`w-full rounded border border-input bg-background px-2 py-1.5 text-xs font-mono outline-none focus:ring-1 focus:ring-primary resize-y disabled:opacity-60`}),s&&(0,Y.jsx)(`div`,{className:`text-[11px] text-destructive`,children:s})]})}function Ll({name:e,value:t,onCommit:n,disabled:r}){return typeof t==`boolean`?(0,Y.jsx)(K,{label:e,value:t,onCommit:n,disabled:r}):typeof t==`number`?(0,Y.jsx)(ai,{label:e,value:t,onCommit:e=>n(e),disabled:r}):t===null||typeof t==`string`?(0,Y.jsx)(G,{label:e,value:t??``,onCommit:n,disabled:r,mono:!0}):(0,Y.jsx)(Il,{label:e,value:t,onCommit:n,disabled:r})}var Rl=new Set([`children`,`body`]),zl=Symbol(`remove`);function Bl(e){let t=e.split(`.`),n=[];for(let e of t){let t=/^([a-zA-Z_]\w*)(?:\[(\d+)\])?$/.exec(e);if(!t)return null;n.push({key:t[1],index:t[2]==null?-1:Number(t[2])})}return n.length>0?n:null}function Vl(e){let t=[];for(let n of e)t.push(n.key),n.index>=0&&t.push(n.index);return t}function Hl(e,t){let n=e;for(let e of t){if(n==null)return null;n=n[e]}return n??null}function Ul(e,t,n){if(t.length===0)return n;let[r,...i]=t;if(typeof r==`number`){let t=Array.isArray(e)?[...e]:[];return i.length===0?n===zl?t.splice(r,1):t[r]=n:t[r]=Ul(t[r],i,n),t}let a={...e||{}};return i.length===0?n===zl?delete a[r]:a[r]=n:a[r]=Ul(a[r],i,n),a}function Wl(e,t){return Hl(e,Vl(t))}function Gl(e,t,n){let r=Vl(t),i=Ul(e,r,n===null?zl:n),a=r[0];return{[a]:i[a]}}function Kl(e,t){let n=Vl(t),r=n[n.length-1];if(typeof r!=`number`)return null;let i=Hl(e,n.slice(0,-1));return Array.isArray(i)?{siblings:i,index:r}:null}function ql(e,t,n){let r=Vl(t),i=Ul(e,r.slice(0,-1),n),a=r[0];return{[a]:i[a]}}function Jl({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=/^slot:([a-zA-Z_]+):(\d+)(?:\.(.+))?$/.exec(e.id),c=s?null:Bl(e.id),l=s?s[1]:``,u=s?Number(s[2]):-1,d=s?s[3]:void 0,f=d?Bl(d):null,p=t.slots&&typeof t.slots==`object`?t.slots:{},m=s?Array.isArray(p[l])?p[l]:p[l]==null?[]:[p[l]]:[],h=s?m[u]??null:null,g=e=>n({slots:{...p,[l]:e}}),_=e=>g(e===null?m.filter((e,t)=>t!==u):m.map((t,n)=>n===u?e:t)),v=s?f?Wl(h||{},f):h:c?Wl(t,c):null,y=s?f?Kl(h||{},f):{siblings:m,index:u}:c?Kl(t,c):null;if(!s&&!c||!v)return(0,Y.jsx)(ji,{kindLabel:J(`engine.inspector.pageBlock.kind`,a),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.pageBlock.close`,a),children:(0,Y.jsx)(oi,{message:e.id})});let b=e=>s?_(f?{...h,...Gl(h||{},f,{...v,...e})}:{...v,...e}):n(Gl(t,c,{...v,...e})),x=v.properties||{},S=typeof t?.object==`string`?t.object:void 0,C=e=>e.objectFrom===`page`?S:e.objectProp!=null&&x[e.objectProp]!=null?String(x[e.objectProp]):void 0,w=e=>x[e]??v[e],T=(e,t)=>b({properties:{...x,[e]:t}}),E=new Set((kl(v.type)?Ol[v.type]:[]).map(e=>e.name)),D=Object.keys(x).filter(e=>!E.has(e)&&!Rl.has(e)),O=(e,t,n,r=``)=>{let i=`${r}${e.name}`;switch(e.kind){case`number`:return(0,Y.jsx)(ai,{label:e.label,value:typeof t(e.name)==`number`?t(e.name):void 0,placeholder:e.placeholder,onCommit:t=>n(e.name,t),disabled:o},i);case`boolean`:return(0,Y.jsx)(K,{label:e.label,value:!!t(e.name),onCommit:t=>n(e.name,t),disabled:o},i);case`color`:return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(wi,{value:t(e.name)==null?void 0:String(t(e.name)),onChange:t=>n(e.name,t),disabled:o,options:e.options})]},i);case`select`:return(0,Y.jsx)(W,{label:e.label,value:t(e.name)==null?void 0:String(t(e.name)),options:e.options,onCommit:t=>n(e.name,t),disabled:o},i);case`string-list`:{let r=Array.isArray(t(e.name))?t(e.name):[];return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,i)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(V,{className:`h-8 text-sm`,value:String(t??``),placeholder:e.placeholder,disabled:o,onChange:t=>{let a=[...r];a[i]=t.target.value,n(e.name,a)}}),(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:o,"aria-label":`Remove`,onClick:()=>n(e.name,r.filter((e,t)=>t!==i)),children:(0,Y.jsx)(Qe,{className:`h-4 w-4`})})]},i)),!o&&(0,Y.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,``]),children:[(0,Y.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]},i)}case`array`:{let r=Array.isArray(t(e.name))?t(e.name):[];return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,a)=>{let s=t&&typeof t==`object`?t:{};return(0,Y.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border p-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`#`,a+1]}),(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,disabled:o,"aria-label":`Remove item`,onClick:()=>n(e.name,r.filter((e,t)=>t!==a)),children:(0,Y.jsx)(sr,{className:`h-3.5 w-3.5`})})]}),e.itemFields.map(t=>O(t,e=>s[e],(t,i)=>{let o=[...r];o[a]={...s,[t]:i},n(e.name,o)},`${i}-${a}-`))]},a)}),!o&&(0,Y.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,{}]),children:[(0,Y.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),` `,e.addLabel||`Add`]})]},i)}case`object-picker`:return(0,Y.jsx)(Ml,{label:e.label,value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:o},i);case`field-picker`:return(0,Y.jsx)(Nl,{label:e.label,objectName:C(e),value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:o},i);case`field-list`:return(0,Y.jsx)(Pl,{label:e.label,objectName:C(e),value:t(e.name),onChange:t=>n(e.name,t),disabled:o},i);default:return(0,Y.jsx)(G,{label:e.label,value:t(e.name)==null?``:String(t(e.name)),placeholder:e.placeholder,onCommit:t=>n(e.name,t),disabled:o},i)}},k=()=>{s?_(f?{...h,...Gl(h||{},f,null)}:null):n(Gl(t,c,null)),r()},A=e=>e.map(e=>e.index>=0?`${e.key}[${e.index}]`:e.key).join(`.`);return(0,Y.jsxs)(ji,{kindLabel:J(`engine.inspector.pageBlock.kind`,a),title:String(v.id||v.type||e.id),onClose:r,closeLabel:J(`engine.inspector.pageBlock.close`,a),headerActions:y?(0,Y.jsx)(Mi,{index:y.index,total:y.siblings.length,onMove:e=>{if(!y)return;if(s){if(f){let t=gi(y.siblings,y.index,e);_({...h,...ql(h||{},f,t)});let n=A([...f.slice(0,-1),{key:f[f.length-1].key,index:e}]);i?.({kind:`block`,id:`slot:${l}:${u}.${n}`,label:String(v.id||v.type||e)})}else g(gi(m,u,e)),i?.({kind:`block`,id:`slot:${l}:${e}`,label:String(v.id||v.type||e)});return}let r=gi(y.siblings,y.index,e);n(ql(t,c,r));let a=A([...c.slice(0,-1),{key:c[c.length-1].key,index:e}]);i?.({kind:`block`,id:a,label:String(v.id||v.type||a)})},upLabel:J(`engine.inspector.reorder.up`,a),downLabel:J(`engine.inspector.reorder.down`,a),disabled:o}):void 0,footer:(0,Y.jsx)(hi,{label:J(`engine.inspector.pageBlock.remove`,a),onClick:k,disabled:o}),children:[(0,Y.jsx)(G,{label:J(`engine.inspector.pageBlock.type`,a),value:v.type??``,onCommit:e=>b({type:e}),disabled:o,mono:!0}),(0,Y.jsx)(G,{label:J(`engine.inspector.pageBlock.id`,a),value:v.id??``,onCommit:e=>b({id:e}),disabled:o,mono:!0}),(0,Y.jsx)(G,{label:J(`engine.inspector.pageBlock.className`,a),value:v.className??``,onCommit:e=>b({className:e}),disabled:o,mono:!0}),(0,Y.jsx)(Ai,{label:J(`engine.inspector.pageBlock.hidden`,a),value:v.hidden??``,onCommit:e=>b({hidden:e||void 0}),objectName:S,disabled:o}),kl(v.type)&&(0,Y.jsxs)(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:J(`engine.inspector.pageBlock.properties`,a)}),Ol[v.type].map(e=>O(e,w,T))]}),D.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:J(`engine.inspector.pageBlock.advanced`,a)}),D.map(e=>(0,Y.jsx)(Ll,{name:e,value:x[e],onCommit:t=>T(e,t),disabled:o},e))]})]})}var Yl=new Set([`simple`,`tabbed`,`wizard`,`split`]),Xl=new Set([`drawer`,`modal`]);function Zl(e){return typeof e==`string`&&Xl.has(e)}function Ql(e){return typeof e==`string`&&Yl.has(e)?e:`simple`}function $l(e){let t={...e,type:String(e?.type??``)},n=t.properties&&typeof t.properties==`object`?t.properties:void 0;return Zl(n?.formType??t.formType)&&(n&&(t.properties={...n,formType:`simple`}),`formType`in t&&(t.formType=`simple`)),t}function eu(e=`300px`){let t=X.useRef(null),[n,r]=X.useState(()=>typeof IntersectionObserver>`u`);return X.useEffect(()=>{if(n)return;let i=t.current;if(!i)return;let a=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(r(!0),a.disconnect())},{rootMargin:e});return a.observe(i),()=>a.disconnect()},[n,e]),{ref:t,inView:n}}function tu({block:e,maxHeightClass:t=`max-h-72`}){let n=String(e?.type??``),{ref:r,inView:i}=eu();return(0,Y.jsx)(`div`,{ref:r,className:B(`pointer-events-none select-none overflow-hidden p-3`,t),children:i?(0,Y.jsx)(Q,{fallbackHint:`"${n}" can't render with its current configuration — check its Properties.`,children:(0,Y.jsx)(f,{children:(0,Y.jsx)(_,{schema:$l(e)})})}):(0,Y.jsx)(`div`,{className:`min-h-[64px] animate-pulse rounded bg-muted/40`,"aria-hidden":`true`})})}var nu={1:`grid-cols-1`,2:`grid-cols-2`,3:`grid-cols-3`,4:`grid-cols-4`,5:`grid-cols-5`,6:`grid-cols-6`};function ru(e){let t=e?.properties||{};switch(e?.type){case`page:tabs`:case`page:accordion`:return(Array.isArray(t.items)?t.items:[]).map((e,t)=>({label:e?.label||e?.key||`Item ${t+1}`,pathSuffix:`properties.items[${t}].children`,children:Array.isArray(e?.children)?e.children:[]}));case`page:card`:return Array.isArray(t.body)&&!Array.isArray(t.children)?[{label:`Body`,pathSuffix:`properties.body`,children:t.body}]:[{label:`Body`,pathSuffix:`properties.children`,children:Array.isArray(t.children)?t.children:[]}];case`page:section`:case`grid`:return[{label:`Content`,pathSuffix:`properties.children`,children:Array.isArray(t.children)?t.children:[]}];default:return Array.isArray(t.children)?[{label:`Content`,pathSuffix:`properties.children`,children:t.children}]:[]}}var iu=[`header`,`actions`,`alerts`,`highlights`,`details`,`tabs`,`discussion`];function au(e){let t=e||{};return iu.map(e=>{let n=t[e];return{name:e,components:Array.isArray(n)?n:n==null?[]:[n]}})}function ou(e){let t={};for(let n of e){let e=Array.isArray(n.components)?n.components:[];e.length===0||!n.name||(t[n.name]=e)}return t}function su(e){let t=e.slots;if(e.kind===`slotted`&&t&&typeof t==`object`&&!Array.isArray(t))return{regions:au(t),shape:`slots`};let n=e.regions;if(Array.isArray(n))return{regions:n,shape:`regions`};let r=e.children;return Array.isArray(r)?{regions:[{name:`children`,components:r}],shape:`children`}:{regions:[],shape:`regions`}}function cu(e,t,n,r){return e===`children`?`children[${n}]`:e===`slots`?`slot:${r}:${n}`:`regions[${t}].components[${n}]`}function lu(e){return typeof e.label==`string`&&e.label||typeof e.title==`string`&&e.title||typeof e.id==`string`&&e.id||String(e.type??`block`)}var uu=`text/x-objectui-pageblock`;function du({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=X.useMemo(()=>su(e),[e]),s=n?.kind===`block`?String(n.id):null,c=X.useCallback(e=>{if(o===`children`){let n=e.flatMap(e=>Array.isArray(e.components)?e.components:[]);t?.({children:n})}else o===`slots`?t?.({slots:ou(e)}):t?.({regions:e})},[t,o]),l=X.useCallback((e,n)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]})),s=i[e.region]?.components;if(!s)return;let[l]=s.splice(e.comp,1);if(!l)return;let u=i[n.region]?.components;if(!u)return;let d=u.length;if(`appendEnd`in n)d=u.length;else if(n.before!=null){let t=n.before;e.region===n.region&&e.comp<t&&--t,d=t}else if(n.after!=null){let t=n.after+1;e.region===n.region&&e.comp<n.after+1&&--t,d=t}u.splice(d,0,l),c(i);let f=cu(o,n.region,d,i[n.region]?.name);r?.({kind:`block`,id:f,label:lu(l)})},[t,r,a,c,o]),u=X.useCallback((e,n)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]}));i[e]||(i[e]={name:`region_${e+1}`,components:[]});let s={type:n};i[e].components.push(s),c(i);let l=i[e].components.length-1;r?.({kind:`block`,id:cu(o,e,l,i[e]?.name),label:lu(s)})},[t,r,a,c,o]),d=X.useCallback((e,n,r)=>{if(!t)return;let i=a.map(e=>({...e,components:Array.isArray(e.components)?[...e.components]:[]})),o=i[e]?.components?.[n];o&&(i[e].components[n]={...o,label:r||void 0},c(i))},[t,a,c]),f=X.useCallback(()=>{if(!t)return;let e=[...a,{name:`region_${a.length+1}`,components:[]}];c(e)},[t,a,c]),p=X.useCallback((n,i,a)=>{if(!t)return;let o=/^slot:([a-zA-Z_]+):(\d+)$/.exec(n),s=Bl(i);if(!s)return;let c=Vl(s);if(o){let s=o[1],l=Number(o[2]),u=e.slots||{},d=u[s],f=Array.isArray(d)?[...d]:d==null?[]:[d],p=f[l];if(!p)return;let m=Hl(p,c)||[];f[l]=Ul(p,c,[...m,{type:a}]),t({slots:{...u,[s]:f}}),r?.({kind:`block`,id:`${n}.${i}[${m.length}]`,label:a})}else{let o=Bl(`${n}.${i}`);if(!o)return;let s=Vl(o),c=Hl(e,s)||[],l=Ul(e,s,[...c,{type:a}]);t({[s[0]]:l[s[0]]}),r?.({kind:`block`,id:`${n}.${i}[${c.length}]`,label:a})}},[t,e,r]),m=X.useCallback(e=>{e.target===e.currentTarget&&s&&r?.(null)},[r,s]);return a.length===0?(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,Y.jsx)(`div`,{className:`mx-auto max-w-3xl px-6 py-8`,children:(0,Y.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:`No regions yet`}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`A Page is composed of regions (header / main / sidebar / …). Add a region to start dropping blocks into it.`}),!i&&(0,Y.jsx)(`div`,{className:`pt-2`,children:(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,onClick:f,children:[(0,Y.jsx)(L,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}):(0,Y.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-5`,onClick:m,children:[a.map((e,t)=>(0,Y.jsx)(fu,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(n,i)=>r?.({kind:`block`,id:cu(o,t,n,e.name),label:lu(i)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d,baseIdOf:n=>cu(o,t,n,e.name),onSelectId:(e,t)=>r?.({kind:`block`,id:e,label:t}),onAddNested:p},t)),!i&&o===`regions`&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground`,onClick:f,children:[(0,Y.jsx)(L,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function fu({region:e,regionIdx:t,shape:n,selectedId:r,readOnly:i,onSelectBlock:a,onMoveBlock:o,onAddBlock:s,onRenameLabel:c,onSelectId:l,onAddNested:u}){let d=Array.isArray(e.components)?e.components:[],[f,p]=X.useState(!1);return(0,Y.jsxs)(`section`,{className:B(`rounded-md transition-colors`,f&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(i)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(uu)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,p(!0))},onDragLeave:e=>{e.currentTarget===e.target&&p(!1)},onDrop:e=>{if(i||(p(!1),e.defaultPrevented))return;e.preventDefault();let n=e.dataTransfer.getData(uu);if(n)try{let e=JSON.parse(n);if(typeof e.region!=`number`||typeof e.comp!=`number`)return;o(e,{region:t,appendEnd:!0})}catch{}},children:[(0,Y.jsxs)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground pl-1 mb-2 flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{children:e.name||`region ${t+1}`}),e.width&&(0,Y.jsxs)(`span`,{className:`normal-case text-[10px] text-muted-foreground/60`,children:[`· `,e.width]}),f&&(0,Y.jsx)(`span`,{className:`text-primary normal-case text-[10px]`,children:`drop here`})]}),(0,Y.jsxs)(`div`,{className:`space-y-2.5`,children:[d.length===0?(0,Y.jsx)(`div`,{className:`rounded border border-dashed bg-background/50 py-6 px-4 text-center text-xs text-muted-foreground`,children:n===`slots`?`Inherited from the default page — add a block to override this slot.`:`Empty region — drop a block here or use the add button below.`}):d.map((s,d)=>{let f=cu(n,t,d,e.name);return(0,Y.jsxs)(X.Fragment,{children:[(0,Y.jsx)(pu,{block:s,regionIdx:t,compIdx:d,selected:f===r,readOnly:i,onClick:()=>a(d,s),onMoveBlock:o,onRenameLabel:e=>c(t,d,e)}),(0,Y.jsx)(mu,{block:s,baseId:f,selectedId:r,readOnly:i,onSelectId:l,onAddNested:u})]},`${t}:${d}`)}),!i&&(0,Y.jsx)(`div`,{className:`pt-1`,children:(0,Y.jsx)(hu,{onPick:e=>s(t,e)})})]})]})}function pu({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=Sl[c]?.Icon??Tl,u=Dl(c),d=lu(e),f=!i,[p,m]=X.useState(null),h=e=>{e.dataTransfer.setData(uu,JSON.stringify({region:t,comp:n})),e.dataTransfer.effectAllowed=`move`},g=e=>{if(!f)return;let t=e.dataTransfer.types;if(!t||!Array.from(t).includes(uu))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect();m(e.clientY-n.top<n.height/2?`before`:`after`)},_=()=>m(null),v=e=>{if(i)return;e.preventDefault(),e.stopPropagation();let r=p??`before`;m(null);let a=e.dataTransfer.getData(uu);if(a)try{let e=JSON.parse(a);if(e.region===t&&e.comp===n)return;o(e,r===`before`?{region:t,before:n}:{region:t,after:n})}catch{}},[y,b]=X.useState(!1),[x,S]=X.useState(d);X.useEffect(()=>{S(d)},[d]);let C=e=>{i||(e.preventDefault(),e.stopPropagation(),S(d),b(!0))},w=()=>{if(i){b(!1);return}let e=x.trim();e&&e!==d&&s(e),b(!1)},T=()=>{S(d),b(!1)},E=ru(e).length>0;return(0,Y.jsxs)(`div`,{className:B(`relative`,p===`before`&&`pt-1.5`),onDragOver:g,onDragLeave:_,onDrop:v,children:[p===`before`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,Y.jsx)(`div`,{className:B(`group relative rounded-md border bg-card transition-colors hover:border-primary/40`,r?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`),children:E?(0,Y.jsxs)(`button`,{type:`button`,onClick:a,draggable:f,onDragStart:h,className:B(`flex w-full items-center justify-between gap-2 rounded-md px-3.5 py-2.5 text-left`,i&&`cursor-default`,f&&`cursor-grab active:cursor-grabbing`),"aria-pressed":r,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1`,children:[f&&(0,Y.jsx)(Cn,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),(0,Y.jsx)(l,{className:B(`h-3.5 w-3.5 shrink-0`,u.icon)}),y?(0,Y.jsx)(`input`,{autoFocus:!0,value:x,onChange:e=>S(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),w()):e.key===`Escape`&&(e.preventDefault(),T())},onBlur:w,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,Y.jsx)(`span`,{className:B(`text-sm font-medium truncate`,!i&&`cursor-text`),onDoubleClick:C,title:i?void 0:`Double-click to rename`,children:d}),e.id&&e.id!==d&&(0,Y.jsxs)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:[`#`,e.id]})]}),(0,Y.jsx)(R,{variant:`outline`,className:B(`text-[10px] shrink-0 font-mono`,u.badge),children:c})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(tu,{block:e}),(0,Y.jsx)(`button`,{type:`button`,onClick:a,draggable:f,onDragStart:h,"aria-label":`Select ${d}`,"aria-pressed":r,className:B(`absolute inset-0 z-10 rounded-md`,i&&`cursor-default`,f&&`cursor-grab active:cursor-grabbing`)}),(0,Y.jsxs)(`div`,{className:B(`pointer-events-none absolute right-1.5 top-1.5 z-20 flex items-center gap-1 transition-opacity`,r?`opacity-100`:`opacity-0 group-hover:opacity-100`),children:[f&&(0,Y.jsx)(Cn,{className:`h-3.5 w-3.5 text-muted-foreground/60`,"aria-hidden":`true`}),(0,Y.jsx)(R,{variant:`outline`,className:B(`text-[10px] font-mono shadow-sm bg-background/90 backdrop-blur`,u.badge),children:c})]})]})}),p===`after`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function mu({block:e,baseId:t,selectedId:n,readOnly:r,onSelectId:i,onAddNested:a}){let o=ru(e);if(o.length===0)return null;let s=nu[e?.type===`grid`?Math.min(6,Math.max(1,Number(e.properties?.columns)||1)):1]??`grid-cols-1`;return(0,Y.jsx)(`div`,{className:`ml-5 mt-1.5 space-y-2.5 border-l border-dashed border-border pl-3`,children:o.map((e,o)=>(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wider text-muted-foreground/70`,children:e.label}),e.children.length===0?(0,Y.jsx)(`div`,{className:`rounded border border-dashed bg-background/40 py-2 px-3 text-[11px] text-muted-foreground`,children:`Empty — add a block.`}):(0,Y.jsx)(`div`,{className:B(`grid gap-2`,s),children:e.children.map((r,a)=>{let o=`${t}.${e.pathSuffix}[${a}]`,s=String(r?.type??``),c=o===n;return(0,Y.jsxs)(`div`,{className:B(`group relative rounded-md border bg-card transition-colors hover:border-primary/40`,c?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`),children:[(0,Y.jsx)(tu,{block:r,maxHeightClass:`max-h-56`}),(0,Y.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i(o,lu(r))},"aria-label":`Select ${lu(r)}`,"aria-pressed":c,className:`absolute inset-0 z-10 rounded-md cursor-pointer`}),(0,Y.jsx)(`div`,{className:B(`pointer-events-none absolute right-1.5 top-1.5 z-20 transition-opacity`,c?`opacity-100`:`opacity-0 group-hover:opacity-100`),children:(0,Y.jsx)(R,{variant:`outline`,className:B(`text-[10px] font-mono shadow-sm bg-background/90 backdrop-blur`,Dl(s).badge),children:s})})]},a)})}),!r&&(0,Y.jsx)(hu,{onPick:n=>a(t,e.pathSuffix,n)})]},o))})}function hu({onPick:e}){let[t,n]=X.useState(!1),[r,i]=X.useState(``),a=r.trim().toLowerCase(),o=X.useMemo(()=>a?wl.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Sl[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):wl,[a]);return(0,Y.jsxs)(jn,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,Y.jsx)(Qn,{asChild:!0,children:(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(L,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,Y.jsxs)(en,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b`,children:(0,Y.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),placeholder:`Search block type…`,className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:o.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:`No matching types.`}):o.map(t=>(0,Y.jsxs)(`div`,{className:`mb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 py-1`,children:Cl[t.category]}),t.types.map(t=>{let r=Sl[t],a=r.Icon;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),n(!1),i(``)},className:`w-full flex items-center gap-2 px-2 py-1.5 rounded text-sm hover:bg-accent text-left`,children:[(0,Y.jsx)(a,{className:B(`h-3.5 w-3.5 shrink-0`,Dl(t).icon)}),(0,Y.jsx)(`span`,{className:`truncate`,children:r.label}),(0,Y.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground/70 font-mono truncate`,children:t})]},t)})]},t.category))})]})]})}function gu({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=X.useMemo(()=>{let t=e.type??`page`;return{...e,type:t}},[e]),s=!!(t&&r),c=s&&!!i,l=n&&n.kind===`block`?n.id:null,u=!!e?.interfaceConfig?.source,d=X.useMemo(()=>Array.isArray(e.regions)?`regions`:`children`,[e]),f=X.useMemo(()=>{if(d===`regions`){let t=e.regions,n=[];return t.forEach((e,t)=>{(Array.isArray(e.components)?e.components:[]).forEach((r,i)=>{n.push({id:`regions[${t}].components[${i}]`,label:r.id||r.type||`${e.name??`region ${t+1}`} · ${i+1}`})})}),n}return(Array.isArray(e.children)?e.children:[]).map((e,t)=>({id:`children[${t}]`,label:e.id||e.type||`block ${t+1}`}))},[e,d]),p=X.useCallback(()=>{if(!c)return;let t={type:`container`};if(d===`regions`){let n=Array.isArray(e.regions)?[...e.regions]:[],a=n.length-1;a<0&&(n.push({name:`main`,components:[]}),a=0);let o={...n[a]},s=Array.isArray(o.components)?[...o.components]:[];s.push(t),o.components=s,n[a]=o,i({regions:n}),r?.({kind:`block`,id:`regions[${a}].components[${s.length-1}]`,label:t.type});return}let n=[...Array.isArray(e.children)?e.children:[],t];i({children:n}),r?.({kind:`block`,id:`children[${n.length-1}]`,label:t.type})},[c,e,i,r,d]),m=e?.type===`record`||e?.pageType===`record`?e?.object:void 0,[g,v]=X.useState([]),[y,x]=X.useState(null),[S,C]=X.useState(null);X.useEffect(()=>{if(!m){v([]),x(null),C(null);return}let e=!1;return(async()=>{try{let t={headers:{accept:`application/json`},credentials:`include`},n=await(await fetch(`/api/v1/meta/object/${encodeURIComponent(m)}`,t)).json().catch(()=>null),r=n?.item??n?.data??n,i=h(r?.fields),a=i.length>0?`?$top=50&$expand=${encodeURIComponent(i.join(`,`))}`:`?$top=50`,o=await(await fetch(`/api/v1/data/${encodeURIComponent(m)}${a}`,t)).json().catch(()=>null),s=Array.isArray(o?.records)?o.records:Array.isArray(o?.items)?o.items:Array.isArray(o?.data)?o.data:Array.isArray(o)?o:[];if(e)return;v(s),x(r),C(e=>e??s[0]?.id??s[0]?._id??s[0]?.name??null)}catch{e||(v([]),x(null))}})(),()=>{e=!0}},[m]);let w=e=>e?.id??e?._id??e?.name,T=e=>String(e?.name??e?.title??e?.label??e?.subject??w(e)??`(record)`),E=X.useMemo(()=>g.length?g.find(e=>String(w(e))===String(S))??g[0]:null,[g,S]),D=e?.kind===`slotted`,O=X.useMemo(()=>{if(!D)return o;try{let t=e?.slots??{};return qi(y??void 0,{slots:t})}catch{return o}},[D,o,e,y]),k=e=>!m||!E?e:(0,Y.jsxs)(b,{objectName:m,recordId:w(E),data:E,objectSchema:y??void 0,embedded:!0,children:[g.length>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b bg-muted/30 text-xs`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:`Preview record`}),(0,Y.jsx)(`select`,{className:`h-7 rounded-md border bg-background px-2 text-xs max-w-[260px]`,value:String(S??``),onChange:e=>C(e.target.value),children:g.map(e=>{let t=w(e);return(0,Y.jsx)(`option`,{value:String(t),children:T(e)},String(t))})}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground/70 shrink-0`,children:[g.length,` sample`,g.length===1?``:`s`]})]}),e]});if(u)return(0,Y.jsx)(Z,{hint:`page · interface`,children:(0,Y.jsx)(Q,{fallbackHint:`The interface page references a source object/view that isn't available.`,children:(0,Y.jsx)(Ki,{page:e,onConfigChange:c?t=>i({interfaceConfig:{...e.interfaceConfig||{},...t}}):void 0})})});let A=e.kind;return A===`react`||A===`html`?(0,Y.jsx)(xl,{draft:e,onPatch:c?i:void 0,readOnly:!c}):!o||Object.keys(o).length<=1?(0,Y.jsxs)(Z,{hint:`page${s?` · design`:``}`,children:[s&&d===`regions`?(0,Y.jsx)(du,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,Y.jsx)(vl,{title:J(`engine.inspector.pageBlock.outlineLabel`,a),entries:f,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?p:void 0,addLabel:J(`engine.inspector.add.block`,a)}):null,!s&&(0,Y.jsx)(gl,{children:`Add components to the page to see a preview.`})]}):s&&d===`regions`?(0,Y.jsx)(Z,{hint:`page · design`,children:k((0,Y.jsx)(du,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}))}):(0,Y.jsx)(Z,{hint:`page${s?` · design`:``}`,children:(0,Y.jsxs)(Q,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,Y.jsx)(vl,{title:J(`engine.inspector.pageBlock.outlineLabel`,a),entries:f,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?p:void 0,addLabel:J(`engine.inspector.add.block`,a)}),k((0,Y.jsx)(`div`,{className:`min-h-[200px] max-h-[70vh] overflow-auto p-4`,children:(0,Y.jsx)(_,{schema:O})}))]})})}function _u(e,t){let n=[t?.object,t?.data?.object,t?.objectName,e.object,e.objectName,e.data?.object];for(let e of n)if(typeof e==`string`&&e)return e}function vu(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e,n=t.field??t.name;return n?{...t,name:n,readOnly:t.readOnly??t.readonly}:t}return String(e)}function yu(e,t){return{type:`object-form`,objectName:e,mode:`create`,formType:Ql(typeof t.type==`string`?t.type:`simple`),sections:Array.isArray(t.sections)?t.sections.map(e=>({...e,fields:Array.isArray(e?.fields)?e.fields.map(vu):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function bu({name:e,draft:t,editing:n}){let r=X.useMemo(()=>Aa(t)?.schema,[t]),i=X.useMemo(()=>_u(t,r),[t,r]),a=!!n,{listViews:o,defaultViewId:s,defaultViewType:c}=X.useMemo(()=>{if(!r)return{listViews:{},defaultViewId:void 0,defaultViewType:`grid`};let n=String(e)||`default`;return{listViews:{[n]:{...r,label:r.label??t.label??e}},defaultViewId:n,defaultViewType:r.type??`grid`}},[r,t,e]);if(!r&&t.type){let e={...t};return(0,Y.jsx)(Z,{hint:`view · ${e.type}${a?` · design`:``}`,children:(0,Y.jsx)(Q,{fallbackHint:"The view's `type` may not be registered, or required fields are missing.",children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(f,{children:(0,Y.jsx)(_,{schema:e})})})})})}if(!i)return(0,Y.jsx)(Z,{hint:`view${a?` · design`:``}`,children:(0,Y.jsxs)(gl,{tone:`warn`,children:[`This view has no object binding yet. Set the bound `,(0,Y.jsx)(`code`,{children:`Object`}),` in the right panel to fetch live data and field options.`]})});if(t.viewKind===`form`&&r){let e=String(r.type??`simple`),t=yu(i,r);return(0,Y.jsx)(Z,{hint:`view · ${e} · form${a?` · design`:``}`,children:(0,Y.jsx)(Q,{fallbackHint:`The form view references an object or field that doesn't resolve.`,children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(f,{children:(0,Y.jsx)(_,{schema:t})})})})})}let l=X.useMemo(()=>({type:`object-view`,objectName:i,defaultViewType:c,defaultListView:s,listViews:o,showSearch:!0,showFilters:!0,showCreate:!1,showRefresh:!0,showViewSwitcher:!0}),[i,c,s,o]);return(0,Y.jsx)(Z,{hint:`view · ${c}${a?` · design`:``}`,children:(0,Y.jsx)(Q,{fallbackHint:`The view references an object or field that doesn't resolve.`,children:(0,Y.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,Y.jsx)(f,{children:(0,Y.jsx)(_,{schema:l})})})})})}var xu=X.lazy(()=>a(()=>import(`./plugin-dashboard-CRFZp7gC.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function Su({draft:e,editing:t,onPatch:n,selection:r,onSelectionChange:i,locale:a}){let o=p(),s=Array.isArray(e.widgets)?e.widgets:[],c=!!(t&&i),l=c&&!!n,u=r&&r.kind===`widget`?r.id:null,d=X.useCallback(e=>{if(i){if(!e){i(null);return}i({kind:`widget`,id:e,label:s.find(t=>t?.id===e)?.title||e})}},[i,s]),f=X.useCallback(e=>{n&&n({widgets:e})},[n]),m=X.useCallback(e=>{if(!l)return;let t=ui(`widget`,s.map(e=>e?.id).filter(Boolean)),r=Xi[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`,o={id:t,type:e,title:a,...r?.defaults??{}};n({widgets:mi(s,o)}),i?.({kind:`widget`,id:t,label:a})},[l,s,n,i]),h=X.useCallback((e,t)=>{if(!l)return;let r=t.trim();n({widgets:s.map(t=>t?.id===e?{...t,title:r}:t)}),i?.({kind:`widget`,id:e,label:r||e})},[l,s,n,i]),g=u?s.find(e=>e?.id===u)??null:null,_=l?(0,Y.jsx)(ea,{onAdd:m,label:J(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,Y.jsx)(Z,{hint:`dashboard${c?` · design`:``}`,toolbar:_,children:(0,Y.jsx)(gl,{children:`Add at least one widget to see a preview.`})}):(0,Y.jsx)(Z,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:_,children:(0,Y.jsxs)(Q,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:[l&&g?(0,Y.jsx)(Cu,{widget:g,onRename:e=>h(g.id,e),onClose:()=>i?.(null)}):null,(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Loading dashboard renderer…`]}),children:(0,Y.jsx)(`div`,{className:`p-3 max-h-[70vh] overflow-auto`,children:(0,Y.jsx)(`div`,{className:`min-w-[768px]`,children:(0,Y.jsx)(xu,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})})]})})}function Cu({widget:e,onRename:t,onClose:n}){let r=e.title??e.id??``,[i,a]=X.useState(!1),[o,s]=X.useState(r),c=X.useRef(null);X.useEffect(()=>{s(r),a(!1)},[e.id,r]),X.useEffect(()=>{i&&c.current?.select()},[i]);let l=()=>{let e=o.trim();e&&e!==r&&t(e),a(!1)},u=()=>{s(r),a(!1)},d=Xi[e.type]?.icon??null;return(0,Y.jsxs)(`div`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-primary/5 px-3 py-1.5 text-xs`,children:[d?(0,Y.jsx)(d,{className:`h-3.5 w-3.5 text-primary`}):null,(0,Y.jsx)(`span`,{className:`rounded bg-primary px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-primary-foreground`,children:`Selected`}),i?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`input`,{ref:c,value:o,onChange:e=>s(e.target.value),onBlur:l,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),l()):e.key===`Escape`&&(e.preventDefault(),u())},className:`flex-1 min-w-0 rounded border bg-background px-2 py-0.5 text-xs outline-none focus:ring-1 focus:ring-primary`}),(0,Y.jsx)(`button`,{type:`button`,onClick:l,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Save title`,children:(0,Y.jsx)(Tt,{className:`h-3.5 w-3.5`})})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`flex-1 min-w-0 truncate text-left font-medium hover:underline`,title:`Click to rename`,children:r||(0,Y.jsx)(`span`,{className:`italic text-muted-foreground`,children:`untitled`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Rename widget`,children:(0,Y.jsx)(Gn,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Clear selection`,children:(0,Y.jsx)(Qe,{className:`h-3.5 w-3.5`})})]})}var wu=X.lazy(()=>a(()=>import(`./plugin-report-BKD6SOp5.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function Tu({draft:e}){let t=p(),n=e,r=typeof n.dataset==`string`&&!!n.dataset,i=n.type===`joined`&&Array.isArray(n.blocks)&&n.blocks.some(e=>typeof e?.dataset==`string`&&!!e.dataset);if(r||i){let r=Array.isArray(n.rows)?n.rows.filter(Boolean):[];return(0,Y.jsx)(Z,{hint:i?`report · joined · ${n.blocks.length} block${n.blocks.length===1?``:`s`}`:`report · dataset "${n.dataset}"${r.length?` · by `+r.join(`, `):``}`,children:(0,Y.jsx)(Q,{fallbackHint:`The Report references a dataset/measure that doesn't resolve, or its config is incomplete.`,children:(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Loading report renderer…`]}),children:(0,Y.jsx)(`div`,{className:`p-3 min-h-[200px] max-h-[70vh] overflow-auto`,children:(0,Y.jsx)(wu,{schema:e,dataSource:t})})})})})}let a=n.type===`joined`;return(0,Y.jsx)(Z,{children:(0,Y.jsx)(_l,{icon:(0,Y.jsx)(Yn,{className:`h-8 w-8`}),title:a?`Add a block to preview this joined report`:`Bind a dataset to preview this report`,description:a?`A joined report stacks dataset-bound blocks. Add a block and bind its dataset + measures in the right panel to start designing.`:`Since the 9.0 single-form cutover a report renders its dataset's measures (values) grouped by dimensions (rows). Choose a Dataset in the right panel to start designing.`})})}var Eu=`text/x-objectui-nav`;function Du(e){if(e.kind)return String(e.kind);if(e.object||e.objectName)return`object`;if(e.page||e.pageName)return`page`;if(e.dashboard)return`dashboard`;if(e.report)return`report`;if(Array.isArray(e.children)&&e.children.length)return`group`;let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&/^https?:/i.test(t)?`link`:`item`}function Ou(e){switch(e){case`object`:return Yn;case`page`:return Ce;case`dashboard`:return Lt;case`report`:return Jt;case`link`:return Te;case`group`:return ye;default:return Vn}}var ku={object:{icon:`text-blue-500`,badge:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`},page:{icon:`text-violet-500`,badge:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`},dashboard:{icon:`text-teal-500`,badge:`border-teal-200 bg-teal-50 text-teal-700 dark:border-teal-900 dark:bg-teal-950/40 dark:text-teal-300`},report:{icon:`text-amber-500`,badge:`border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-300`},link:{icon:`text-indigo-500`,badge:`border-indigo-200 bg-indigo-50 text-indigo-700 dark:border-indigo-900 dark:bg-indigo-950/40 dark:text-indigo-300`},group:{icon:`text-slate-500`,badge:`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-800 dark:bg-slate-900/40 dark:text-slate-300`},item:{icon:`text-zinc-500`,badge:`border-zinc-200 bg-zinc-50 text-zinc-600 dark:border-zinc-800 dark:bg-zinc-900/40 dark:text-zinc-400`}};function Au(e){return ku[e]??ku.item}function ju(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function Mu(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function Nu({draft:e,rootKey:t,onPatch:n,selection:r,onSelectionChange:i}){let a=Hi(),o=X.useMemo(()=>{let n=e[t];return Array.isArray(n)?n:[]},[e,t]),s=r&&r.kind===`nav`?r.id:null,[c,l]=X.useState(null),u=X.useCallback(e=>{n&&n({[t]:e})},[n,t]),d=X.useCallback(()=>{if(!n)return;let e=J(`engine.appNav.newItem`,a),r=new Set(o.map(e=>typeof e.id==`string`?e.id:``).filter(Boolean)),s=`nav_item_${o.length+1}`;for(let e=o.length+2;r.has(s);e++)s=`nav_item_${e}`;let c=mi(o,{id:s,type:`object`,label:e});u(c),i?.({kind:`nav`,id:`${t}[${c.length-1}]`,label:e})},[n,o,u,t,i,a]),f=X.useCallback(e=>{if(!n)return;let r=si(o,e,null);u(r),s===`${t}[${e}]`&&i?.(null)},[n,o,u,t,s,i]),p=X.useCallback((e,r)=>{if(!n)return;let a={...o[e]??{},label:r},c=si(o,e,a);u(c),s===`${t}[${e}]`&&i?.({kind:`nav`,id:`${t}[${e}]`,label:r})},[n,o,u,t,s,i]),m=X.useCallback((e,r)=>{if(!n)return;let a=r;if(e<r&&(a=r-1),a===e)return;let s=gi(o,e,a);u(s),i?.({kind:`nav`,id:`${t}[${a}]`,label:ju(s[a]??{},a)})},[n,o,u,t,i]);return(0,Y.jsxs)(`div`,{className:`rounded-md border bg-card/40`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,Y.jsx)(`span`,{className:`font-medium uppercase tracking-wide text-muted-foreground`,children:J(`engine.appNav.heading`,a)}),(0,Y.jsxs)(R,{variant:`outline`,className:`text-[10px]`,children:[o.length,` `,o.length===1?J(`engine.appNav.itemOne`,a):J(`engine.appNav.itemOther`,a)]})]}),n&&(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:d,children:[(0,Y.jsx)(L,{className:`h-3 w-3`}),` `,J(`engine.appNav.addItem`,a)]})]}),(0,Y.jsx)(`div`,{className:`space-y-1.5 p-2`,onDragOver:e=>{n&&e.dataTransfer.types.includes(Eu)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(Eu)&&(e.preventDefault(),c!=null&&(m(c,o.length),l(null)))},children:o.length===0?(0,Y.jsx)(`div`,{className:`rounded border border-dashed px-3 py-4 text-center text-[11px] text-muted-foreground`,children:J(n?`engine.appNav.empty`:`engine.appNav.emptyReadonly`,a)}):o.map((e,r)=>(0,Y.jsx)(Pu,{item:e,index:r,depth:0,path:`${t}[${r}]`,selectedId:s,canEdit:!!n,onClick:(e,t)=>i?.({kind:`nav`,id:e,label:t}),onRename:e=>p(r,e),onRemove:()=>f(r),onDragStart:()=>l(r),onDragEnd:()=>l(null),onDropBefore:()=>{c!=null&&(m(c,r),l(null))}},r))})]})}function Pu({item:e,index:t,depth:n,path:r,selectedId:i,canEdit:a,onClick:o,onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}){return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Fu,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,ju(e,t)),onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}),Array.isArray(e.children)&&e.children.map((e,t)=>{let s=`${r}.children[${t}]`;return(0,Y.jsx)(Pu,{item:e,index:t,depth:n+1,path:s,selectedId:i,canEdit:a,onClick:o,onRename:()=>void 0,onRemove:()=>void 0,onDragStart:()=>void 0,onDragEnd:()=>void 0,onDropBefore:()=>void 0},t)})]})}function Fu({item:e,index:t,depth:n,path:r,isSelected:i,canEdit:a,onClick:o,onRename:s,onRemove:c,onDragStart:l,onDragEnd:u,onDropBefore:d}){let f=Hi(),p=Du(e),m=Ou(p),h=Au(p),g=Mu(e),[_,v]=X.useState(!1),[y,b]=X.useState(ju(e,t)),[x,S]=X.useState(!1),[C,w]=X.useState(null);return X.useEffect(()=>{_||b(ju(e,t))},[e,t,_]),(0,Y.jsxs)(`div`,{className:`relative`,style:{paddingLeft:n*16},children:[C===`before`&&(0,Y.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 -top-0.5 h-0.5 rounded bg-primary`}),(0,Y.jsxs)(`button`,{type:`button`,draggable:a&&!_,onDragStart:e=>{a&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(Eu,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(Eu)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,w(`before`))},onDragLeave:()=>w(null),onDrop:e=>{a&&e.dataTransfer.types.includes(Eu)&&(e.preventDefault(),e.stopPropagation(),w(null),d())},onClick:o,onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),"aria-pressed":i,className:`group flex w-full items-center gap-2 rounded-md border bg-card px-2.5 py-2 text-left text-xs transition-colors hover:border-primary/40 ${i?`border-primary ring-1 ring-primary`:`border-border`} ${a&&!_?`cursor-grab active:cursor-grabbing`:``}`,children:[a?(0,Y.jsx)(Cn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50 group-hover:text-muted-foreground`}):(0,Y.jsx)(`span`,{className:`w-3.5`}),(0,Y.jsx)(m,{className:B(`h-3.5 w-3.5 shrink-0`,h.icon)}),_?(0,Y.jsx)(`input`,{autoFocus:!0,value:y,onChange:e=>b(e.target.value),onClick:e=>e.stopPropagation(),onBlur:()=>{v(!1);let n=y.trim();n&&n!==ju(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),b(ju(e,t)),v(!1))},className:`flex-1 min-w-0 rounded border border-input bg-background px-1.5 py-0.5 text-xs outline-none focus:border-primary`}):(0,Y.jsx)(`span`,{className:`flex-1 min-w-0 truncate font-medium`,onDoubleClick:e=>{a&&(e.stopPropagation(),v(!0))},children:ju(e,t)}),(0,Y.jsx)(R,{variant:`outline`,className:B(`text-[10px] font-medium`,h.badge),children:p}),g&&(0,Y.jsx)(`code`,{className:`ml-0 text-[10px] text-muted-foreground truncate max-w-[10rem]`,children:g}),a&&x&&!_&&(0,Y.jsx)(`span`,{role:`button`,tabIndex:0,onClick:e=>{e.stopPropagation(),c()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),c())},className:`inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,"aria-label":J(`engine.appNav.removeItem`,f),children:(0,Y.jsx)(sr,{className:`h-3 w-3`})})]})]})}function Iu(e){return Array.isArray(e)?e.map(e=>{if(!e||typeof e!=`object`)return null;let t=String(e.label??e.title??e.name??e.path??``).trim();if(!t&&!e.children)return null;let n=e.path??e.href??e.route??e.url??void 0,r;e.object||e.objectName?r=`object`:e.page||e.pageName?r=`page`:e.dashboard?r=`dashboard`:e.report?r=`report`:typeof n==`string`&&/^https?:/i.test(n)?r=`link`:Array.isArray(e.children)&&e.children.length&&(r=`group`);let i=Array.isArray(e.children)?Iu(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function Lu(e){switch(e){case`object`:return Yn;case`page`:return Ce;case`dashboard`:return Lt;case`report`:return Jt;default:return Vn}}function Ru({name:e,draft:t,editing:n,selection:r,onSelectionChange:i,onPatch:a}){let o=String(t.name??e??``),s=t.label??o,c=t.landingRoute??t.landing??t.defaultRoute??`/`,{rootKey:l,navItems:u}=X.useMemo(()=>{let e=[[`nav`,t.nav],[`navigation`,t.navigation],[`tabs`,t.tabs],[`items`,t.items],[`menu`,t.menu]];for(let[t,n]of e)if(Array.isArray(n)&&n.length)return{rootKey:t,navItems:Iu(n)};return{rootKey:null,navItems:[]}},[t]),d=l??`navigation`,f=!!(n&&i),p=f&&!!a,m=r&&r.kind===`nav`?r.id:null,h=f?(e,t)=>i({kind:`nav`,id:e,label:t.label}):void 0,g=o?`/apps/${encodeURIComponent(o)}/`:null;return(0,Y.jsx)(Z,{hint:`app`,toolbar:g&&(0,Y.jsxs)(`a`,{href:g,target:`_blank`,rel:`noreferrer`,className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,title:`Open this app in a new tab`,children:[`Open `,(0,Y.jsx)(Re,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:String(s)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:o}),(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Landing: `,(0,Y.jsx)(`code`,{className:`font-mono`,children:String(c)})]})]}),f?(0,Y.jsx)(Nu,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):u.length===0?(0,Y.jsxs)(gl,{children:[`No top-level nav items. Add `,(0,Y.jsx)(`code`,{children:`nav`}),` / `,(0,Y.jsx)(`code`,{children:`tabs`}),` entries in the Form tab to populate the app's navigation.`]}):(0,Y.jsx)(`div`,{className:`border rounded divide-y`,children:u.map((e,t)=>(0,Y.jsx)(zu,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function zu({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=Lu(e.kind),s=Bu(t,e.path);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 text-xs hover:bg-accent/40 ${i?`cursor-pointer`:``} ${a===r?`bg-primary/5 ring-1 ring-primary`:``}`,style:{paddingLeft:`${12+n*16}px`},onClick:i?t=>{t.stopPropagation(),i(r,e)}:void 0,children:[(0,Y.jsx)(o,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:e.label}),e.kind&&(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider opacity-60`,children:e.kind}),s&&(0,Y.jsxs)(`a`,{href:s,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`ml-auto font-mono text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[e.path,` `,(0,Y.jsx)(Re,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,Y.jsx)(zu,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function Bu(e,t){if(!t)return null;if(/^https?:/i.test(t))return t;if(!e)return null;let n=t.startsWith(`/`)?t.slice(1):t;return`/apps/${encodeURIComponent(e)}/${n}`}function Vu(e){let{type:t,locale:n}=e;switch(t){case`text`:case`password`:return(0,Y.jsx)(Hu,{...e,icon:t===`password`?(0,Y.jsx)(lt,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,Y.jsx)(Hu,{...e,icon:(0,Y.jsx)(Sn,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,Y.jsx)(Hu,{...e,icon:(0,Y.jsx)(Tr,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,Y.jsx)(Hu,{...e,icon:(0,Y.jsx)(gn,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,Y.jsx)(Hu,{...e,icon:(0,Y.jsx)(vn,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,Y.jsx)(Hu,{...e,icon:(0,Y.jsx)(k,{className:`h-3.5 w-3.5`}),placeholder:J(`designer.stub.pickDate`,n)});case`time`:return(0,Y.jsx)(Hu,{...e,icon:(0,Y.jsx)(wn,{className:`h-3.5 w-3.5`}),placeholder:`hh:mm`});case`textarea`:case`markdown`:case`html`:case`richtext`:case`json`:case`code`:return(0,Y.jsx)(Uu,{...e,mono:t===`json`||t===`code`});case`boolean`:case`toggle`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(Er,{disabled:!0}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??J(`designer.stub.off`,n)})]});case`select`:case`radio`:return(0,Y.jsx)(Wu,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,Y.jsx)(Wu,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,Y.jsx)(Gu,{...e});case`image`:case`avatar`:return(0,Y.jsx)(Ku,{icon:(0,Y.jsx)(mr,{className:`h-4 w-4`}),label:J(t===`avatar`?`designer.stub.uploadAvatar`:`designer.stub.uploadImage`,n)});case`file`:case`video`:case`audio`:case`signature`:return(0,Y.jsx)(Ku,{icon:(0,Y.jsx)(On,{className:`h-4 w-4`}),label:q(`designer.stub.upload`,n,{type:t})});case`qrcode`:return(0,Y.jsx)(Ku,{icon:(0,Y.jsx)(On,{className:`h-4 w-4`}),label:J(`designer.stub.qrcode`,n)});case`color`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(`span`,{className:`inline-block h-6 w-6 rounded border`,style:{background:`#3b82f6`}}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`#3b82f6`}),(0,Y.jsx)(Un,{className:`h-3.5 w-3.5 text-muted-foreground`})]});case`rating`:return(0,Y.jsx)(`div`,{className:`flex items-center gap-0.5 h-8`,children:[0,1,2,3,4].map(e=>(0,Y.jsx)(ln,{className:`h-4 w-4 `+(e<3?`fill-amber-400 text-amber-400`:`text-muted-foreground/40`)},e))});case`slider`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1 h-1.5 rounded bg-muted`,children:[(0,Y.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-2/5 rounded bg-primary`}),(0,Y.jsx)(`div`,{className:`absolute h-3 w-3 -top-[3px] left-[40%] rounded-full border-2 border-primary bg-background`})]}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`40`})]});case`progress`:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,Y.jsx)(`div`,{className:`relative flex-1 h-2 rounded bg-muted`,children:(0,Y.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-3/5 rounded bg-emerald-500`})}),(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`60%`})]});case`location`:return(0,Y.jsx)(Hu,{...e,icon:(0,Y.jsx)(et,{className:`h-3.5 w-3.5`}),placeholder:J(`designer.stub.latLng`,n)});case`address`:return(0,Y.jsx)(Uu,{...e,placeholder:e.placeholder??`Street
12
+ City, State ZIP
13
+ Country`});case`formula`:case`summary`:return(0,Y.jsx)(`div`,{className:`h-8 px-2 flex items-center text-xs font-mono bg-muted/40 border rounded text-muted-foreground`,children:e.formula?`ƒ ${e.formula}`:`ƒ ${J(`designer.stub.computed`,n)}`});case`composite`:return(0,Y.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:J(`designer.stub.composite`,n)});case`repeater`:return(0,Y.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:J(`designer.stub.repeater`,n)});case`vector`:return(0,Y.jsxs)(`div`,{className:`h-8 px-2 flex items-center text-xs font-mono bg-muted/40 border rounded text-muted-foreground`,children:[`[0.124, 0.337, …] `,e.placeholder?`(${e.placeholder})`:``]});default:return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(V,{disabled:!0,placeholder:e.placeholder??`(${t})`,className:`h-8 text-sm`}),(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px]`,children:t})]})}}function Hu({placeholder:e,icon:t}){return(0,Y.jsxs)(`div`,{className:`relative`,children:[(0,Y.jsx)(V,{disabled:!0,placeholder:e??``,className:`h-8 text-sm `+(t?`pl-8`:``)}),t&&(0,Y.jsx)(`div`,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground`,children:t})]})}function Uu({placeholder:e,mono:t}){return(0,Y.jsx)(`textarea`,{disabled:!0,placeholder:e??``,className:`w-full min-h-[60px] text-sm rounded-md border bg-background px-2 py-1.5 disabled:opacity-100 `+(t?`font-mono text-xs`:``)})}function Wu({options:e,placeholder:t,single:n,locale:r}){let i=e??[],a=i.slice(0,n?1:3).filter(e=>e.value||e.label);return n?(0,Y.jsxs)(`div`,{className:`h-8 px-2 flex items-center justify-between text-sm border rounded bg-background text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:a[0]?.label||a[0]?.value||t||J(`designer.stub.select`,r)}),(0,Y.jsx)(ke,{className:`h-3.5 w-3.5 shrink-0`})]}):(0,Y.jsxs)(`div`,{className:`min-h-8 px-1.5 py-1 flex items-center flex-wrap gap-1 border rounded bg-background`,children:[a.length===0?(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground px-1`,children:t||J(`designer.stub.pickMulti`,r)}):a.map((e,t)=>(0,Y.jsx)(R,{variant:`secondary`,className:`text-[10px]`,children:e.label||e.value},t)),i.length>a.length&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,i.length-a.length]})]})}function Gu({referenceTo:e,placeholder:t,locale:n}){let r=e?Di.lookup:null;return(0,Y.jsxs)(`div`,{className:`h-8 px-2 flex items-center gap-2 border rounded bg-background text-sm text-muted-foreground`,children:[(0,Y.jsx)(Be,{className:`h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate flex-1`,children:t||(e?q(`designer.stub.searchRef`,n,{ref:e}):J(`designer.stub.chooseRelated`,n))}),e&&(0,Y.jsxs)(R,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`→ `,e]}),!e&&(0,Y.jsx)(Xe,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),r&&null]})}function Ku({icon:e,label:t}){return(0,Y.jsxs)(`div`,{className:`h-16 w-full border-2 border-dashed rounded flex flex-col items-center justify-center gap-1 text-muted-foreground bg-muted/20`,children:[e,(0,Y.jsx)(`span`,{className:`text-[11px]`,children:t})]})}var qu=e=>(e??``).toLowerCase().startsWith(`zh`),Ju=(e,t)=>e?qu(t)?e.labelZh:e.label:void 0,Yu=(e,t)=>(qu(t)?Ni:Ei)[e];function Xu({objectName:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=!r,{enabled:c}=aa(),l=X.useMemo(()=>xi(t.fields),[t]),u=X.useMemo(()=>n?Wi(n.fields,t.fields):null,[n,t]),d=u?u.counts.added+u.counts.changed+u.counts.removed:0,[f,p]=X.useState(!1);X.useEffect(()=>{f&&d===0&&p(!1)},[f,d]);let m=f&&d>0,h=e=>m?u?.byName[e]?.status:void 0,g=e=>m?u?.byName[e]?.changedKeys??[]:[],_=X.useMemo(()=>ci(t.fieldGroups),[t]),v=_.length>0,y=X.useMemo(()=>ri(l,_,{includeEmptyDeclared:!s}),[l,_,s]),[b,x]=X.useState({}),S=e=>e??`__ungrouped__`,C=X.useCallback(e=>{let t=e??`__ungrouped__`;x(e=>({...e,[t]:!e[t]}))},[]),w=y.length>0&&y.every(e=>b[S(e.key)]),T=X.useCallback(e=>{x(()=>{let t={};for(let n of y)t[S(n.key)]=e;return t})},[y]),E=i?.kind===`field`?String(i.id):null,D=l.entries.filter(e=>!!e.def.required).length,O=X.useCallback(e=>{a&&a({kind:`field`,id:e.name,label:typeof e.def.label==`string`?e.def.label:e.name})},[a]),[k,A]=X.useState(()=>new Set),j=X.useRef(null),ee=X.useMemo(()=>y.flatMap(e=>e.entries.map(e=>e.name)),[y]);X.useEffect(()=>{A(e=>{if(e.size===0)return e;let t=new Set([...e].filter(e=>l.entries.some(t=>t.name===e)));return t.size===e.size?e:t})},[l]);let te=X.useCallback((e,t)=>{let n=e.name;if(!s&&t&&(t.metaKey||t.ctrlKey)){A(e=>{let t=new Set(e);return t.has(n)?t.delete(n):t.add(n),t}),j.current=n;return}if(!s&&t&&t.shiftKey&&j.current&&j.current!==n){let e=ee.indexOf(j.current),t=ee.indexOf(n);if(e>=0&&t>=0){let[n,r]=e<t?[e,t]:[t,e];A(new Set(ee.slice(n,r+1)));return}}k.size&&A(new Set),j.current=n,O(e)},[s,ee,k,O]),ne=X.useCallback(()=>A(new Set),[]),M=X.useCallback(()=>{if(!r||k.size===0)return;let e=l.entries.filter(e=>!k.has(e.name));r({fields:Si({shape:l.shape,entries:e})}),E&&k.has(E)&&a?.(null),A(new Set)},[r,k,l,E,a]),re=X.useCallback(e=>{if(!r||k.size===0)return;let t=l.entries.map(t=>k.has(t.name)?{name:t.name,def:{...t.def,group:e??void 0}}:t);r({fields:Si({shape:l.shape,entries:t})})},[r,k,l]),ie=X.useCallback((e,t)=>{if(!r)return;let n=l.entries.map(e=>e.name),i=e===`select`?`status`:e,o=1,s=i;for(;n.includes(s);)o+=1,s=`${i}_${o}`;let c=yi(s,e);t&&(c.def={...c.def,group:t});let u=l.entries.length;if(t){for(let e=l.entries.length-1;e>=0;--e)if(l.entries[e].def.group===t){u=e+1;break}}let d=l.entries.slice();d.splice(u,0,c),r({fields:Si({shape:l.shape,entries:d})}),a?.({kind:`field`,id:s,label:String(c.def.label??s)})},[r,a,l]),ae=X.useCallback(()=>{if(!r)return;let e=q(`designer.canvas.sectionN`,o,{n:_.length+1}),t=pi(_,e),n=t[t.length-1];r({fieldGroups:t}),x(e=>({...e,[n.key]:!1}))},[r,_,o]),oe=X.useCallback((e,t)=>{r&&r({fieldGroups:Ri(_,e,t)})},[r,_]),N=X.useCallback(e=>{if(!r)return;let t=_i(l,e);r({fieldGroups:fi(_,e),fields:Si(t)})},[r,_,l]),P=X.useCallback((e,t)=>{r&&r({fieldGroups:li(_,e,t)})},[r,_]),se=X.useCallback((e,t,n)=>{if(!r||e===t)return;let i=l.entries.slice(),a=i.findIndex(t=>t.name===e);if(a<0)return;let[o]=i.splice(a,1),s=i.findIndex(e=>e.name===t),c=s>=0?i[s]:void 0;if(c){let e=typeof c.def.group==`string`?c.def.group:void 0;e!==(typeof o.def.group==`string`?o.def.group:void 0)&&(o.def={...o.def,group:e})}s<0?i.push(o):i.splice(n===`before`?s:s+1,0,o),r({fields:Si({shape:l.shape,entries:i})})},[r,l]),ce=X.useCallback((e,t)=>{if(!r)return;let n=l.entries.slice(),i=n.findIndex(t=>t.name===e);if(i<0)return;let a=typeof n[i].def.group==`string`?n[i].def.group:null,o=i+t;for(;o>=0&&o<n.length&&(typeof n[o].def.group==`string`?n[o].def.group:null)!==a;)o+=t;if(o<0||o>=n.length)return;let s=n[i];n[i]=n[o],n[o]=s,r({fields:Si({shape:l.shape,entries:n})})},[r,l]),le=X.useCallback((e,t)=>{if(!r)return;let n=l.entries.slice(),i=n.findIndex(t=>t.name===e);if(i<0)return;let[a]=n.splice(i,1);if((typeof a.def.group==`string`?a.def.group:null)===t){n.splice(i,0,a);return}a.def={...a.def,group:t??void 0};let o=n.length;for(let e=n.length-1;e>=0;--e)if((typeof n[e].def.group==`string`?n[e].def.group:null)===t){o=e+1;break}n.splice(o,0,a),r({fields:Si({shape:l.shape,entries:n})})},[r,l]),ue=X.useCallback((e,t)=>{if(!r)return;let n=l.entries.map(n=>n.name===e?{name:e,def:{...n.def,label:t||void 0}}:n);r({fields:Si({shape:l.shape,entries:n})})},[r,l]),de=X.useCallback(e=>{e.target===e.currentTarget&&E&&a?.(null)},[a,E]),fe=l.entries.length===0,pe=v||y.length>1;return(0,Y.jsxs)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:de,"data-object-name":e,children:[!s&&k.size>0&&(0,Y.jsx)(Qu,{count:k.size,groups:_,onMoveToGroup:re,onDelete:M,onClear:ne,locale:o}),(0,Y.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-4`,onClick:de,children:[!fe&&(0,Y.jsx)(Zu,{fieldCount:l.entries.length,requiredCount:D,sectionCount:_.length,allCollapsed:w,onToggleAll:pe?()=>T(!w):void 0,reviewAvailable:d>0,reviewing:m,diffCounts:u?.counts,onToggleReview:()=>p(e=>!e),locale:o}),fe?(0,Y.jsx)(rd,{onAdd:s?void 0:ie,locale:o,aiEnabled:c}):(0,Y.jsx)(`div`,{className:`space-y-5`,children:y.map(e=>{let t=e.key?_.findIndex(t=>t.key===e.key):-1;return(0,Y.jsxs)($u,{groupKey:e.key,label:e.key===null?J(`designer.canvas.ungrouped`,o):e.label,count:e.entries.length,showHeader:pe,collapsed:!!b[S(e.key)],onToggleCollapse:()=>C(e.key),readOnly:s,locale:o,canMoveUp:t>0,canMoveDown:t>=0&&t<_.length-1,onRename:e.key?t=>oe(e.key,t):void 0,onRemove:e.key?()=>N(e.key):void 0,onMove:e.key?t=>P(e.key,t):void 0,onAddField:s?void 0:t=>ie(t,e.key),onDropField:s?void 0:le,children:[e.entries.map(e=>(0,Y.jsx)(nd,{entry:e,selected:e.name===E,multiSelected:k.has(e.name),diffStatus:h(e.name),changedKeys:g(e.name),readOnly:s,locale:o,onClick:t=>te(e,t),onReorder:s?void 0:se,onRenameLabel:s?void 0:ue,onMoveOffset:s?void 0:t=>ce(e.name,t)},e.name)),e.entries.length===0&&(0,Y.jsx)(`div`,{className:`rounded-md border border-dashed bg-background/40 px-3 py-4 text-center text-[11px] text-muted-foreground`,children:J(s?`designer.canvas.emptySection`:`designer.canvas.dropHint`,o)})]},e.key??`__ungrouped__`)})}),m&&u&&u.removed.length>0&&(0,Y.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-destructive/80 pl-1`,children:J(`designer.canvas.diffRemoved`,o)}),u.removed.map(e=>(0,Y.jsx)(td,{entry:e,locale:o},e.name))]}),!fe&&!s&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(id,{onPick:e=>ie(e),locale:o}),(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground hover:text-foreground`,onClick:ae,children:[(0,Y.jsx)(Ze,{className:`h-3.5 w-3.5`}),J(`designer.canvas.addSection`,o)]}),c&&(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,className:`gap-1.5 ml-auto text-primary/80 hover:text-primary`,onClick:()=>Wr(),children:[(0,Y.jsx)(En,{className:`h-3.5 w-3.5`}),J(`designer.canvas.askAi`,o)]})]})]})]})}function Zu({fieldCount:e,requiredCount:t,sectionCount:n,allCollapsed:r,onToggleAll:i,reviewAvailable:a,reviewing:o,diffCounts:s,onToggleReview:c,locale:l}){return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:o&&s?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`font-medium text-emerald-600 dark:text-emerald-400`,children:s.added}),` `,J(`designer.canvas.diffAdded`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-amber-600 dark:text-amber-400`,children:s.changed}),` `,J(`designer.canvas.diffChanged`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-destructive`,children:s.removed}),` `,J(`designer.canvas.diffRemoved`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/40 normal-case ml-1`,children:J(`designer.canvas.reviewVsPublished`,l)})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e}),` `,J(`designer.canvas.fields`,l),(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-foreground/80`,children:t}),` `,J(`designer.canvas.required`,l),n>0&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,Y.jsx)(`span`,{className:`font-medium text-foreground/80`,children:n}),` `,J(`designer.canvas.sections`,l)]})]})}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a&&c&&(0,Y.jsxs)(`button`,{type:`button`,onClick:c,className:B(`inline-flex items-center gap-1 rounded px-1.5 py-0.5 transition-colors`,o?`bg-primary/10 text-primary hover:bg-primary/15`:`hover:bg-accent hover:text-foreground`),children:[(0,Y.jsx)(an,{className:`h-3 w-3`}),J(o?`designer.canvas.reviewExit`:`designer.canvas.reviewChanges`,l)]}),i&&(0,Y.jsxs)(`button`,{type:`button`,onClick:i,className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 hover:bg-accent hover:text-foreground transition-colors`,children:[r?(0,Y.jsx)(Pe,{className:`h-3 w-3`}):(0,Y.jsx)(ft,{className:`h-3 w-3`}),J(r?`designer.canvas.expandAll`:`designer.canvas.collapseAll`,l)]})]})]})}function Qu({count:e,groups:t,onMoveToGroup:n,onDelete:r,onClear:i,locale:a}){let[o,s]=X.useState(!1);return(0,Y.jsxs)(`div`,{className:`sticky top-0 z-20 flex items-center gap-2 border-b border-primary/20 bg-primary/10 backdrop-blur px-6 py-2 text-sm`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:q(`designer.canvas.bulkSelected`,a,{n:e})}),(0,Y.jsx)(`span`,{className:`text-muted-foreground text-[11px] hidden md:inline`,children:J(`designer.canvas.bulkHint`,a)}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[t.length>0&&(0,Y.jsxs)(jn,{open:o,onOpenChange:s,children:[(0,Y.jsx)(Qn,{asChild:!0,children:(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70`,children:[(0,Y.jsx)(te,{className:`h-3.5 w-3.5`}),J(`designer.canvas.bulkMoveTo`,a),(0,Y.jsx)(ke,{className:`h-3 w-3`})]})}),(0,Y.jsxs)(en,{align:`end`,className:`w-52 p-1 max-h-[300px] overflow-auto`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{n(null),s(!1)},className:`w-full text-left px-2 py-1.5 rounded text-sm hover:bg-accent`,children:J(`designer.canvas.ungrouped`,a)}),t.map(e=>(0,Y.jsx)(`button`,{type:`button`,onClick:()=>{n(e.key),s(!1)},className:`w-full text-left px-2 py-1.5 rounded text-sm hover:bg-accent truncate`,children:e.label||e.key},e.key))]})]}),(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70 text-destructive hover:text-destructive`,onClick:r,children:[(0,Y.jsx)(sr,{className:`h-3.5 w-3.5`}),J(`designer.canvas.bulkDelete`,a)]}),(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:i,children:[(0,Y.jsx)(Qe,{className:`h-3.5 w-3.5`}),J(`designer.canvas.bulkClear`,a)]})]})]})}function $u({groupKey:e,label:t,count:n,showHeader:r,collapsed:i,onToggleCollapse:a,readOnly:o,locale:s,canMoveUp:c,canMoveDown:l,onRename:u,onRemove:d,onMove:f,onAddField:p,onDropField:m,children:h}){let[g,_]=X.useState(!1);return(0,Y.jsxs)(`section`,{className:B(`space-y-2.5 rounded-md transition-colors`,g&&`bg-primary/5 ring-1 ring-primary/30 -mx-1 px-1 py-1`),onDragOver:e=>{if(!m)return;let t=e.dataTransfer.types;!t||!Array.from(t).includes(`text/x-objectui-field`)||(e.preventDefault(),e.dataTransfer.dropEffect=`move`,_(!0))},onDragLeave:e=>{e.currentTarget===e.target&&_(!1)},onDrop:t=>{if(!m)return;if(t.defaultPrevented){_(!1);return}t.preventDefault();let n=t.dataTransfer.getData(`text/x-objectui-field`);_(!1),n&&m(n,e)},children:[r&&(0,Y.jsx)(ed,{label:t,count:n,collapsed:i,onToggleCollapse:a,readOnly:o,locale:s,canMoveUp:c,canMoveDown:l,dropActive:g,onRename:u,onRemove:d,onMove:f,onAddField:p}),!i&&(0,Y.jsx)(`div`,{className:`space-y-2.5`,children:h})]})}function ed({label:e,count:t,collapsed:n,onToggleCollapse:r,readOnly:i,locale:a,canMoveUp:o,canMoveDown:s,dropActive:c,onRename:l,onRemove:u,onMove:d,onAddField:f}){let[p,m]=X.useState(!1),[h,g]=X.useState(e);X.useEffect(()=>{g(e)},[e]);let _=()=>{if(!l){m(!1);return}let t=h.trim();t&&t!==e&&l(t),m(!1)},v=n?N:ke;return(0,Y.jsxs)(`div`,{className:`group/sec flex items-center gap-1.5 pl-0.5 min-h-[24px]`,children:[(0,Y.jsx)(`button`,{type:`button`,onClick:r,className:`flex items-center justify-center h-5 w-5 rounded text-muted-foreground hover:bg-accent hover:text-foreground transition-colors shrink-0`,"aria-label":J(n?`designer.canvas.expandSection`:`designer.canvas.collapseSection`,a),"aria-expanded":!n,children:(0,Y.jsx)(v,{className:`h-3.5 w-3.5`})}),p?(0,Y.jsx)(`input`,{autoFocus:!0,value:h,onChange:e=>g(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:t=>{t.stopPropagation(),t.key===`Enter`?(t.preventDefault(),_()):t.key===`Escape`&&(t.preventDefault(),g(e),m(!1))},onBlur:_,className:`text-[11px] font-medium uppercase tracking-wider px-1 py-0.5 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1 max-w-[220px]`}):(0,Y.jsx)(`span`,{className:B(`text-[11px] font-medium uppercase tracking-wider text-muted-foreground truncate`,l&&`cursor-text hover:text-foreground`),onDoubleClick:l?()=>{g(e),m(!0)}:void 0,title:l?J(`designer.canvas.renameHint`,a):void 0,children:e}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums shrink-0`,children:t}),c&&(0,Y.jsx)(`span`,{className:`text-primary normal-case text-[10px] font-normal`,children:J(`designer.canvas.dropToAssign`,a)}),!i&&(d||u||f)&&(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5 opacity-0 group-hover/sec:opacity-100 focus-within:opacity-100 transition-opacity`,children:[f&&(0,Y.jsx)(id,{onPick:f,compact:!0,locale:a}),d&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{type:`button`,onClick:()=>d(-1),disabled:!o,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-30 disabled:pointer-events-none`,"aria-label":J(`designer.canvas.moveSectionUp`,a),children:(0,Y.jsx)(Cr,{className:`h-3 w-3`})}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>d(1),disabled:!s,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-30 disabled:pointer-events-none`,"aria-label":J(`designer.canvas.moveSectionDown`,a),children:(0,Y.jsx)(Or,{className:`h-3 w-3`})})]}),u&&(0,Y.jsx)(`button`,{type:`button`,onClick:u,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,"aria-label":J(`designer.canvas.removeSection`,a),title:J(`designer.canvas.removeSectionHint`,a),children:(0,Y.jsx)(sr,{className:`h-3 w-3`})})]})]})}function td({entry:e,locale:t}){let n=e.def,r=Di[typeof n.type==`string`?n.type:`text`]?.Icon,i=typeof n.label==`string`?n.label:e.name;return(0,Y.jsx)(`div`,{className:`rounded-md border border-dashed border-destructive/30 bg-destructive/[0.03] px-3.5 py-2.5 opacity-80`,children:(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[r&&(0,Y.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate line-through text-muted-foreground`,children:i}),(0,Y.jsx)(`code`,{className:`text-[10px] text-muted-foreground/60 font-mono truncate line-through`,children:e.name})]}),(0,Y.jsx)(R,{className:`text-[10px] font-medium border-transparent bg-destructive/15 text-destructive shrink-0`,children:J(`designer.canvas.diffRemoved`,t)})]})})}function nd({entry:e,selected:t,multiSelected:n,diffStatus:r,changedKeys:i,readOnly:a,locale:o,onClick:s,onReorder:c,onRenameLabel:l,onMoveOffset:u}){let d=e.def,f=typeof d.type==`string`?d.type:`text`,p=Di[f],m=p?.Icon,h=Bi[p?.category??`advanced`],g=typeof d.label==`string`?d.label:e.name,_=!!d.required,v=typeof d.description==`string`?d.description:null,y=Array.isArray(d.options)?d.options.map(e=>({value:String(e.value??``),label:typeof e.label==`string`?e.label:void 0})):void 0,b=typeof d.reference==`string`?d.reference:void 0,x=typeof d.formula==`string`?d.formula:void 0,S=typeof d.placeholder==`string`?d.placeholder:void 0,[C,w]=X.useState(null),T=!!c,[E,D]=X.useState(!1),[O,k]=X.useState(g);X.useEffect(()=>{k(g)},[g]);let A=e=>{l&&(e.preventDefault(),e.stopPropagation(),k(g),D(!0))},j=()=>{if(!l){D(!1);return}let t=O.trim();t&&t!==g&&l(e.name,t),D(!1)},ee=()=>{k(g),D(!1)};return(0,Y.jsxs)(`div`,{className:B(`relative`,C===`before`&&`pt-1.5`),onDragOver:e=>{if(!T)return;let t=e.dataTransfer.types;if(!t||!Array.from(t).includes(`text/x-objectui-field`))return;e.preventDefault(),e.dataTransfer.dropEffect=`move`;let n=e.currentTarget.getBoundingClientRect(),r=e.clientY-n.top<n.height/2?`before`:`after`;w(r)},onDragLeave:()=>w(null),onDrop:t=>{if(!c)return;t.preventDefault(),t.stopPropagation();let n=t.dataTransfer.getData(`text/x-objectui-field`);w(null),n&&n!==e.name&&c(n,e.name,C??`before`)},children:[C===`before`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,Y.jsxs)(`div`,{role:`button`,tabIndex:a?-1:0,onClick:s,onKeyDown:e=>{if(e.target===e.currentTarget){if(e.altKey&&(e.key===`ArrowUp`||e.key===`ArrowDown`)){u&&(e.preventDefault(),u(e.key===`ArrowUp`?-1:1));return}(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),s?.())}},draggable:T,onDragStart:t=>{t.dataTransfer.setData(`text/x-objectui-field`,e.name),t.dataTransfer.effectAllowed=`move`},className:B(`group block w-full text-left rounded-md border bg-card px-3.5 py-2.5 transition-colors`,`hover:border-primary/40 hover:bg-card outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,t?`border-primary ring-2 ring-primary/30 shadow-sm`:`border-border`,n&&`border-primary/60 ring-2 ring-primary/40 bg-primary/[0.04]`,r===`added`&&`border-l-[3px] border-l-emerald-500`,r===`changed`&&`border-l-[3px] border-l-amber-500`,a&&`cursor-default`,T&&`cursor-grab active:cursor-grabbing`),"aria-pressed":t||n,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[n&&(0,Y.jsx)(tr,{className:`h-3.5 w-3.5 text-primary shrink-0`,"aria-hidden":`true`}),T&&!n&&(0,Y.jsx)(Cn,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),m&&(0,Y.jsx)(m,{className:B(`h-3.5 w-3.5 shrink-0`,h.icon)}),E?(0,Y.jsx)(`input`,{autoFocus:!0,value:O,onChange:e=>k(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),j()):e.key===`Escape`&&(e.preventDefault(),ee())},onBlur:j,className:`text-sm font-medium px-1 py-0.5 -mx-1 -my-0.5 rounded border border-primary bg-background outline-none min-w-0 flex-1`}):(0,Y.jsx)(`span`,{className:B(`text-sm font-medium truncate`,l&&`cursor-text`),onDoubleClick:A,title:l?J(`designer.canvas.renameHint`,o):void 0,children:g}),_&&(0,Y.jsx)(`span`,{className:`text-destructive text-sm`,children:`*`}),(0,Y.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:e.name})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[r===`added`&&(0,Y.jsx)(R,{className:`text-[10px] font-medium border-transparent bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,children:J(`designer.canvas.diffAdded`,o)}),r===`changed`&&(0,Y.jsx)(R,{className:`text-[10px] font-medium border-transparent bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:i&&i.length?q(`designer.canvas.diffChangedKeys`,o,{keys:i.join(`, `)}):void 0,children:J(`designer.canvas.diffChanged`,o)}),(0,Y.jsx)(R,{variant:`outline`,className:B(`text-[10px] font-medium`,h.badge),children:Ju(p,o)??f})]})]}),v&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground mb-1.5 line-clamp-1`,children:v}),(0,Y.jsx)(Vu,{type:f,label:g,placeholder:S,options:y,referenceTo:b,formula:x,locale:o})]}),C===`after`&&(0,Y.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function rd({onAdd:e,locale:t,aiEnabled:n}){return(0,Y.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium`,children:J(`designer.canvas.noFields`,t)}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:J(`designer.canvas.noFieldsHint`,t)}),e&&(0,Y.jsxs)(`div`,{className:`pt-2 flex items-center justify-center gap-2`,children:[(0,Y.jsx)(id,{onPick:e,locale:t}),n&&(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-primary/80 hover:text-primary`,onClick:()=>Wr(),children:[(0,Y.jsx)(En,{className:`h-3.5 w-3.5`}),J(`designer.canvas.askAiGenerate`,t)]})]})]})}function id({onPick:e,compact:t,locale:n}){let[r,i]=X.useState(!1),[a,o]=X.useState(``),s=a.trim().toLowerCase(),c=X.useMemo(()=>s?Oi.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Di[e];return e.includes(s)||t.label.toLowerCase().includes(s)||t.labelZh.includes(a.trim())})})).filter(e=>e.types.length>0):Oi,[s,a]);return(0,Y.jsxs)(jn,{open:r,onOpenChange:e=>{i(e),e||o(``)},children:[(0,Y.jsx)(Qn,{asChild:!0,children:t?(0,Y.jsx)(`button`,{type:`button`,className:`h-5 w-5 flex items-center justify-center rounded text-muted-foreground hover:bg-accent hover:text-foreground`,"aria-label":J(`designer.canvas.addFieldToSection`,n),title:J(`designer.canvas.addFieldToSection`,n),children:(0,Y.jsx)(L,{className:`h-3 w-3`})}):(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,Y.jsx)(L,{className:`h-3.5 w-3.5`}),J(`designer.canvas.addField`,n)]})}),(0,Y.jsxs)(en,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,Y.jsx)(`div`,{className:`p-2 border-b`,children:(0,Y.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),placeholder:J(`designer.canvas.searchFieldType`,n),className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,Y.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:c.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:J(`designer.canvas.noMatchingTypes`,n)}):c.map(t=>(0,Y.jsxs)(`div`,{className:`mb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 pt-2 pb-1`,children:Yu(t.category,n)}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-0.5`,children:t.types.map(t=>{let r=Di[t],a=r.Icon;return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{e(t),i(!1),o(``)},className:`flex items-center gap-2 px-2 py-1.5 rounded text-left text-xs hover:bg-accent`,children:[(0,Y.jsx)(a,{className:B(`h-3.5 w-3.5 shrink-0`,Bi[r.category].icon)}),(0,Y.jsx)(`span`,{className:`truncate`,children:Ju(r,n)})]},t)})})]},t.category))})]})]})}function ad({name:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=String(t.name??e??``);return s?(0,Y.jsx)(Z,{hint:`object · designer`,children:(0,Y.jsx)(Q,{fallbackHint:`The form designer couldn't be rendered. Check the Form tab.`,children:(0,Y.jsx)(Xu,{objectName:s,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o})})}):(0,Y.jsx)(Z,{hint:`object`,children:(0,Y.jsx)(gl,{children:J(`designer.canvas.nameToStart`,o)})})}function od(e){let t=new Set;for(let n of e.matchAll(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g))t.add(n[1]);for(let n of e.matchAll(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g))t.add(n[1]);return Array.from(t).sort()}function sd(e,t){return t[e]??``}function cd(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>sd(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>sd(n,t))}function ld({draft:e}){let t=String(e.subject??``),n=String(e.from??e.fromAddress??``),r=String(e.to??``),i=String(e.bodyHtml??e.html??e.body??``),a=String(e.bodyText??e.text??``),o=X.useMemo(()=>{let e=new Set;for(let n of od(t))e.add(n);for(let t of od(i))e.add(t);for(let t of od(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=X.useState({}),l=cd(t,s),u=`<!doctype html><html><head><meta charset="utf-8"><style>
14
+ html,body{margin:0;padding:16px;font:14px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#111;background:#fff;}
15
+ a{color:#2563eb;}
16
+ </style></head><body>${(i?cd(i,s):cd(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,Y.jsx)(Z,{hint:`email_template`,children:(0,Y.jsx)(gl,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,Y.jsx)(Z,{hint:`email_template`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_220px] gap-0`,children:[(0,Y.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 px-3 py-2 text-xs space-y-0.5`,children:[(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`From`}),(0,Y.jsx)(`span`,{className:`font-mono truncate`,children:n||`—`})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`To`}),(0,Y.jsx)(`span`,{className:`font-mono truncate`,children:r||`—`})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`Subject`}),(0,Y.jsx)(`span`,{className:`font-medium truncate`,children:l||`—`})]})]}),(0,Y.jsx)(`iframe`,{title:`Email preview`,srcDoc:u,sandbox:`allow-same-origin`,className:`w-full min-h-[400px] max-h-[60vh] border rounded bg-white`})]}),(0,Y.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,Y.jsx)(xe,{className:`h-3 w-3`}),` Variables`]}),o.length===0?(0,Y.jsxs)(`div`,{className:`text-muted-foreground italic`,children:[`No `,(0,Y.jsx)(`code`,{children:`{{var}}`}),` placeholders found.`]}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:o.map(e=>(0,Y.jsxs)(`label`,{className:`block`,children:[(0,Y.jsx)(`span`,{className:`block font-mono text-[10px] text-muted-foreground mb-0.5`,children:e}),(0,Y.jsx)(`input`,{type:`text`,value:s[e]??``,onChange:t=>c(n=>({...n,[e]:t.target.value})),placeholder:`sample for ${e}`,className:`w-full text-xs px-2 py-1 border rounded bg-background`})]},e))})]})]})})})}function ud(e){return typeof e==`number`&&Number.isFinite(e)}function dd(e){return ud(e.ui?.x)&&ud(e.ui?.y)}function fd(e,t){let n=new Map;if(e.length===0)return n;let r=new Map(e.map(e=>[e.id,e])),i=new Map(e.map((e,t)=>[e.id,t])),a=new Map,o=new Map;for(let t of e)o.set(t.id,0);for(let e of t)!r.has(e.source)||!r.has(e.target)||e.source===e.target||vd(e)||(a.has(e.source)||a.set(e.source,[]),a.get(e.source).push(e.target),o.set(e.target,(o.get(e.target)??0)+1));let s=[];for(let t of e)t.type===`start`&&s.push(t.id);for(let t of e)(o.get(t.id)??0)===0&&!s.includes(t.id)&&s.push(t.id);s.length===0&&s.push(e[0].id);let c=new Map,l=[];for(let e of s)c.set(e,0),l.push(e);let u=e.length*Math.max(1,t.length)+e.length+1,d=0;for(;l.length&&d<u;){d+=1;let e=l.shift(),t=c.get(e)??0;for(let n of a.get(e)??[]){let e=t+1;(c.get(n)??-1)<e&&(c.set(n,e),l.push(n))}}let f=0;for(let e of c.values())f=Math.max(f,e);for(let t of e)c.has(t.id)||(f+=1,c.set(t.id,f));let p=new Map;for(let t of e){let e=c.get(t.id)??0;p.has(e)||p.set(e,[]),p.get(e).push(t.id)}for(let e of p.values())e.sort((e,t)=>(i.get(e)??0)-(i.get(t)??0));let m=[...p.keys()].sort((e,t)=>e-t);for(let e of m){let t=p.get(e),r=-(t.length*240+(t.length-1)*44)/2;t.forEach((t,i)=>{n.set(t,{x:r+i*284,y:e*122})})}let h=1/0,g=1/0;for(let e of n.values())h=Math.min(h,e.x),g=Math.min(g,e.y);if(Number.isFinite(h)&&Number.isFinite(g)){let e=28-h,t=28-g;for(let[r,i]of n)n.set(r,{x:i.x+e,y:i.y+t})}for(let t of e)dd(t)&&n.set(t.id,{x:Math.max(0,t.ui.x),y:Math.max(0,t.ui.y)});return n}function pd(e){let t=0,n=0;for(let r of e.values())t=Math.max(t,r.x+240),n=Math.max(n,r.y+66);return{width:t+28,height:n+28}}function md(e){return{x:e.x+240/2,y:e.y+66}}function hd(e){return{x:e.x+240/2,y:e.y}}function gd(e,t){let n=Math.max(Math.abs(t.y-e.y)*.5,24),r={x:e.x,y:e.y+n},i={x:t.x,y:t.y-n};return`M ${e.x},${e.y} C ${r.x},${r.y} ${i.x},${i.y} ${t.x},${t.y}`}function _d(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function vd(e){return e.type===`back`}function yd(e){return{x:e.x+240,y:e.y+66/2}}function bd(e,t){return Math.max(64,Math.abs(t.y-e.y)*.35)}function xd(e,t){let n=bd(e,t),r={x:e.x+n,y:e.y},i={x:t.x+n,y:t.y};return`M ${e.x},${e.y} C ${r.x},${r.y} ${i.x},${i.y} ${t.x},${t.y}`}function Sd(e,t){let n=bd(e,t);return{x:Math.max(e.x,t.x)+n*.75,y:(e.y+t.y)/2}}function Cd(e,t){return e.id||`${e.source}->${e.target}#${t}`}function wd(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Td(e){switch(e){case`start`:return Gt;case`end`:return jr;case`decision`:case`branch`:case`gateway`:return _r;case`wait`:case`timer`:case`delay`:return qt;case`boundary_event`:case`signal`:return me;case`subflow`:case`flow`:return ne;case`create_record`:return Br;case`update_record`:return kt;case`delete_record`:return qe;case`get_record`:return Ge;case`http_request`:case`webhook`:return Tr;case`script`:case`script_task`:return yn;case`screen`:case`user_task`:return Dr;case`approval`:return Vr;case`connector_action`:case`service_task`:return Rt;case`assignment`:return we;case`loop`:case`for_each`:return ut;case`map`:return Mt;case`parallel_gateway`:case`join_gateway`:case`parallel`:return Rr;case`try_catch`:return ce;default:return M}}var Ed={start:{icon:`text-emerald-600 dark:text-emerald-400`,accent:`border-l-emerald-500`,label:`text-emerald-600 dark:text-emerald-400`,chip:`bg-emerald-500/10 ring-1 ring-inset ring-emerald-500/20 dark:bg-emerald-400/10`},end:{icon:`text-rose-600 dark:text-rose-400`,accent:`border-l-rose-500`,label:`text-rose-600 dark:text-rose-400`,chip:`bg-rose-500/10 ring-1 ring-inset ring-rose-500/20 dark:bg-rose-400/10`},decision:{icon:`text-amber-600 dark:text-amber-400`,accent:`border-l-amber-500`,label:`text-amber-600 dark:text-amber-400`,chip:`bg-amber-500/10 ring-1 ring-inset ring-amber-500/20 dark:bg-amber-400/10`},wait:{icon:`text-blue-600 dark:text-blue-400`,accent:`border-l-blue-500`,label:`text-blue-600 dark:text-blue-400`,chip:`bg-blue-500/10 ring-1 ring-inset ring-blue-500/20 dark:bg-blue-400/10`},signal:{icon:`text-violet-600 dark:text-violet-400`,accent:`border-l-violet-500`,label:`text-violet-600 dark:text-violet-400`,chip:`bg-violet-500/10 ring-1 ring-inset ring-violet-500/20 dark:bg-violet-400/10`},subflow:{icon:`text-indigo-600 dark:text-indigo-400`,accent:`border-l-indigo-500`,label:`text-indigo-600 dark:text-indigo-400`,chip:`bg-indigo-500/10 ring-1 ring-inset ring-indigo-500/20 dark:bg-indigo-400/10`},task:{icon:`text-slate-500 dark:text-slate-400`,accent:`border-l-slate-400`,label:`text-slate-500 dark:text-slate-400`,chip:`bg-slate-500/10 ring-1 ring-inset ring-slate-500/20 dark:bg-slate-400/10`},record:{icon:`text-cyan-600 dark:text-cyan-400`,accent:`border-l-cyan-500`,label:`text-cyan-600 dark:text-cyan-400`,chip:`bg-cyan-500/10 ring-1 ring-inset ring-cyan-500/20 dark:bg-cyan-400/10`},integration:{icon:`text-fuchsia-600 dark:text-fuchsia-400`,accent:`border-l-fuchsia-500`,label:`text-fuchsia-600 dark:text-fuchsia-400`,chip:`bg-fuchsia-500/10 ring-1 ring-inset ring-fuchsia-500/20 dark:bg-fuchsia-400/10`},approval:{icon:`text-teal-600 dark:text-teal-400`,accent:`border-l-teal-500`,label:`text-teal-600 dark:text-teal-400`,chip:`bg-teal-500/10 ring-1 ring-inset ring-teal-500/20 dark:bg-teal-400/10`},loop:{icon:`text-sky-600 dark:text-sky-400`,accent:`border-l-sky-500`,label:`text-sky-600 dark:text-sky-400`,chip:`bg-sky-500/10 ring-1 ring-inset ring-sky-500/20 dark:bg-sky-400/10`},screen:{icon:`text-pink-600 dark:text-pink-400`,accent:`border-l-pink-500`,label:`text-pink-600 dark:text-pink-400`,chip:`bg-pink-500/10 ring-1 ring-inset ring-pink-500/20 dark:bg-pink-400/10`},assignment:{icon:`text-purple-600 dark:text-purple-400`,accent:`border-l-purple-500`,label:`text-purple-600 dark:text-purple-400`,chip:`bg-purple-500/10 ring-1 ring-inset ring-purple-500/20 dark:bg-purple-400/10`}};function Dd(e){switch(e){case`start`:return Ed.start;case`end`:return Ed.end;case`decision`:case`branch`:case`gateway`:case`parallel_gateway`:case`join_gateway`:case`parallel`:return Ed.decision;case`wait`:case`timer`:case`delay`:return Ed.wait;case`boundary_event`:case`signal`:case`try_catch`:return Ed.signal;case`subflow`:case`flow`:return Ed.subflow;case`approval`:return Ed.approval;case`loop`:case`for_each`:case`map`:return Ed.loop;case`screen`:case`user_task`:return Ed.screen;case`assignment`:return Ed.assignment;case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return Ed.record;case`http`:case`http_request`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return Ed.integration;default:return Ed.task}}function Od({type:e,className:t}){return X.createElement(Td(e),{className:t,"aria-hidden":!0})}var kd=[`Data`,`Logic`,`Human`,`Integration`,`Flow`];function Ad(e){switch(e){case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return`Data`;case`decision`:case`branch`:case`gateway`:case`loop`:case`for_each`:case`map`:case`assignment`:case`parallel_gateway`:case`join_gateway`:case`parallel`:case`try_catch`:return`Logic`;case`approval`:case`screen`:case`user_task`:return`Human`;case`http`:case`http_request`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return`Integration`;default:return`Flow`}}var jd=[{type:`create_record`,label:`Create record`,hint:`Insert a new record`,category:`Data`},{type:`update_record`,label:`Update record`,hint:`Modify an existing record`,category:`Data`},{type:`get_record`,label:`Get record`,hint:`Query records`,category:`Data`},{type:`delete_record`,label:`Delete record`,hint:`Remove matching records`,category:`Data`},{type:`decision`,label:`Decision`,hint:`Branch on a condition`,category:`Logic`},{type:`loop`,label:`Loop`,hint:`Iterate over a collection`,category:`Logic`},{type:`assignment`,label:`Set variables`,hint:`Assign flow variables`,category:`Logic`},{type:`parallel`,label:`Parallel`,hint:`Run branches concurrently, join at end`,category:`Logic`},{type:`try_catch`,label:`Try / Catch`,hint:`Protect steps with error handling and retry`,category:`Logic`},{type:`approval`,label:`Approval`,hint:`Pause for a human decision`,category:`Human`},{type:`screen`,label:`Screen`,hint:`Collect input from a user`,category:`Human`},{type:`http`,label:`HTTP request`,hint:`Call an external API`,category:`Integration`},{type:`connector_action`,label:`Connector`,hint:`Run an integration action`,category:`Integration`},{type:`script`,label:`Script`,hint:`Run custom code`,category:`Integration`},{type:`subflow`,label:`Subflow`,hint:`Invoke another flow`,category:`Flow`},{type:`wait`,label:`Wait`,hint:`Pause for an event or timer`,category:`Flow`},{type:`end`,label:`End`,hint:`Terminate the flow`,category:`Flow`}];function Md(e){let t=jd.find(t=>t.type===e);return t?t.label:e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Nd(e){switch(e){case`start`:return{};case`wait`:return{waitEventConfig:{eventType:`timer`,onTimeout:`fail`}};case`connector_action`:return{connectorConfig:{connectorId:``,actionId:``,input:{}}};case`boundary_event`:return{boundaryConfig:{attachedToNodeId:``,eventType:`error`,interrupting:!0}};case`approval`:return{config:{approvers:[{type:`manager`}],behavior:`first_response`,lockRecord:!0}};case`http`:case`http_request`:return{config:{method:`GET`}};case`script`:return{};default:return{}}}function Pd({type:e,label:t,summary:n,position:r,selected:i,editable:a,runState:o,dimmed:s,invalid:c,badge:l,onPointerDown:u,onSelect:d,onAppend:f,onAddReviseLoop:p}){let m=Dd(e);return(0,Y.jsxs)(`div`,{className:`group absolute transition-opacity duration-200`,"data-invalid":c||void 0,style:{left:r.x,top:r.y,width:240,height:66,opacity:s?.35:1},children:[(0,Y.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-pressed":i,onPointerDown:u,onClick:e=>{e.stopPropagation(),d?.()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),d?.())},className:B(`group flex h-full w-full items-center gap-3 rounded-xl border bg-card px-2.5 py-2 text-left shadow-sm outline-none`,`transition-[transform,box-shadow,border-color] duration-150 ease-out will-change-transform`,`hover:-translate-y-0.5 hover:shadow-lg hover:shadow-foreground/[0.06] focus-visible:ring-2 focus-visible:ring-primary/40`,a?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,o===`active`?`border-sky-500 shadow-md shadow-sky-500/20 ring-2 ring-sky-400/60`:o===`visited`?`border-emerald-500/70 ring-1 ring-emerald-400/40`:i?`border-primary shadow-md ring-2 ring-primary/30`:c?`border-destructive ring-2 ring-destructive/50`:`border-border/80`),children:[(0,Y.jsx)(`div`,{className:B(`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg transition-transform duration-150 group-hover:scale-105`,m.chip,o===`active`&&`animate-pulse`),children:(0,Y.jsx)(Od,{type:e,className:B(`h-[18px] w-[18px]`,m.icon)})}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{title:t,className:`truncate text-[13px] font-semibold leading-tight text-foreground`,children:t}),(0,Y.jsxs)(`div`,{className:`mt-1 flex items-baseline gap-1.5 leading-tight`,children:[(0,Y.jsx)(`span`,{className:B(`shrink-0 text-[10px] font-semibold uppercase tracking-[0.08em]`,m.label),children:e}),n&&(0,Y.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,title:n,children:n})]})]})]}),l&&(0,Y.jsx)(`span`,{title:l.title,"data-problem":l.level,className:B(`absolute -right-2 -top-2 z-20 inline-flex h-5 w-5 items-center justify-center rounded-full border bg-background shadow-sm`,l.level===`error`?`border-destructive/50 text-destructive`:`border-amber-500/50 text-amber-600 dark:text-amber-400`),children:l.level===`error`?(0,Y.jsx)(rt,{className:`h-3 w-3`}):(0,Y.jsx)(I,{className:`h-3 w-3`})}),a&&e!==`end`&&(0,Y.jsx)(`button`,{type:`button`,title:`Add connected node`,"aria-label":`Add connected node`,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),f?.()},className:B(`absolute left-1/2 -bottom-3 z-10 inline-flex h-6 w-6 -translate-x-1/2 items-center justify-center rounded-full border bg-background text-muted-foreground shadow-sm transition-colors`,`opacity-0 hover:border-primary hover:text-primary group-hover:opacity-100 focus-visible:opacity-100`),children:(0,Y.jsx)(L,{className:`h-3.5 w-3.5`})}),p&&(0,Y.jsx)(`button`,{type:`button`,title:`Add revision loop (send back for revision)`,"aria-label":`Add revision loop`,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),p()},className:B(`absolute -right-3 top-1/2 z-10 inline-flex h-6 w-6 -translate-y-1/2 items-center justify-center rounded-full border bg-background text-amber-600 shadow-sm transition-colors dark:text-amber-400`,`opacity-0 hover:border-amber-500 hover:text-amber-600 group-hover:opacity-100 focus-visible:opacity-100 dark:hover:text-amber-400`),children:(0,Y.jsx)(Jn,{className:`h-3.5 w-3.5`})})]})}function Fd({items:e=jd,onPick:t,open:n,onOpenChange:r,children:i}){let a=X.useMemo(()=>{let t=new Map;for(let n of e){let e=n.category??Ad(n.type),r=t.get(e)??[];r.push(n),t.set(e,r)}return kd.map(e=>[e,t.get(e)??[]]).filter(([,e])=>e.length>0)},[e]),o=e=>{let n=Dd(e.type);return(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>t(e.type),className:`flex w-full items-center gap-2.5 rounded-lg px-2 py-1.5 text-left transition-colors hover:bg-accent`,children:[(0,Y.jsx)(`span`,{className:B(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md`,n.chip),children:(0,Y.jsx)(Od,{type:e.type,className:B(`h-[15px] w-[15px]`,n.icon)})}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`truncate text-[13px] font-medium`,children:e.label}),e.hint&&(0,Y.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:e.hint})]})]},e.type)};return(0,Y.jsxs)(jn,{open:n,onOpenChange:r,children:[(0,Y.jsx)(Qn,{asChild:!0,children:i}),(0,Y.jsx)(en,{align:`end`,sideOffset:6,className:`max-h-[66vh] w-60 overflow-y-auto rounded-xl border bg-popover/95 p-1.5 shadow-xl shadow-foreground/[0.08] ring-1 ring-black/[0.03] backdrop-blur-md`,children:a.map(([e,t],n)=>(0,Y.jsxs)(`div`,{className:B(n>0&&`mt-1 border-t border-border/60 pt-1`),children:[(0,Y.jsx)(`div`,{className:`px-2 pb-1 pt-1 text-[10px] font-semibold uppercase tracking-[0.08em] text-muted-foreground`,children:e}),t.map(o)]},e))})]})}function Id(){return`${``.replace(/\/$/,``)}/api/v1`}function Ld(e,t){let n=new Map;for(let t of e)n.set(t.type,t);for(let e of t){if(!e?.type||e.deprecated||Array.isArray(e.paradigms)&&e.paradigms.length>0&&!e.paradigms.includes(`flow`))continue;let t=n.get(e.type);n.set(e.type,{type:e.type,label:e.name||t?.label||e.type,hint:e.description||t?.hint,category:t?.category??Ad(e.type)})}return[...n.values()]}function Rd(){let[e,t]=(0,X.useState)([]),n=(0,X.useRef)(!0);return(0,X.useEffect)(()=>{n.current=!0;let e=new AbortController;return(async()=>{try{let r=await fetch(`${Id()}/automation/actions`,{credentials:`include`,headers:{"Content-Type":`application/json`},signal:e.signal});if(!r.ok)return;let i=(await r.json())?.data?.actions;if(!Array.isArray(i)||i.length===0)return;n.current&&t(i)}catch{}})(),()=>{n.current=!1,e.abort()}},[]),e}function zd(){let e=Rd();return(0,X.useMemo)(()=>e.length?Ld(jd,e):jd,[e])}function Bd(){let e=Rd();return(0,X.useMemo)(()=>{let t={};for(let n of e)n?.type&&n.configSchema!==void 0&&n.configSchema!==null&&(t[n.type]=n.configSchema);return t},[e])}var Vd=e=>typeof e==`string`?e:void 0;function Hd(e,t){let n=e.trim();if(!n)return{result:!1,error:`Empty condition.`};try{let e=new g({...t,data:t});return{result:(/\$\{/.test(n)?e.evaluate(n,{throwOnError:!0}):e.evaluateExpression(n))===!0}}catch(e){return{result:!1,error:e.message||`Evaluation failed.`}}}function Ud(e,t){let n=new Map;for(let t of e)n.set(t,[]);for(let e of t)n.has(e.source)&&n.has(e.target)&&n.get(e.source).push(e.target);let r=new Map(e.map(e=>[e,0])),i=[],a=e=>{let t=[{id:e,i:0}];for(r.set(e,1),i.push(e);t.length;){let e=t[t.length-1],a=n.get(e.id)??[];if(e.i<a.length){let n=a[e.i++],o=r.get(n);if(o===1){let e=i.indexOf(n);return[...i.slice(e),n]}o===0&&(r.set(n,1),i.push(n),t.push({id:n,i:0}))}else r.set(e.id,2),i.pop(),t.pop()}return null};for(let t of e)if(r.get(t)===0){let e=a(t);if(e)return e}return null}function Wd(e,t){let n=[],r=[],i=e.map(e=>e.id),a=new Set;for(let e of i){if(!e){n.push({level:`error`,message:`A node is missing an id.`});continue}a.has(e)&&n.push({level:`error`,nodeId:e,message:`Duplicate node id "${e}".`}),a.add(e)}for(let e of t)a.has(e.source)||n.push({level:`error`,edge:{source:e.source,target:e.target},message:`Edge source "${e.source}" does not exist.`}),a.has(e.target)||n.push({level:`error`,edge:{source:e.source,target:e.target},message:`Edge target "${e.target}" does not exist.`});let o=new Set(t.map(e=>e.target)),s=e.filter(e=>e.type===`start`),c=e.filter(e=>!o.has(e.id)),l;s.length===1?(l=s[0].id,o.has(l)&&r.push({level:`warning`,nodeId:l,message:`Start node has an incoming edge.`})):s.length>1?n.push({level:`error`,message:`Flow has ${s.length} start nodes; expected one.`}):c.length===1?(l=c[0].id,r.push({level:`warning`,nodeId:l,message:`No "start" node; using the only root node as the entry.`})):c.length===0?n.push({level:`error`,message:`No entry node (every node has an incoming edge — the graph is fully cyclic).`}):n.push({level:`error`,message:`Cannot determine a single entry node (${c.length} candidates). Add a "start" node.`});for(let i of e){if(i.type!==`decision`)continue;let e=t.filter(e=>e.source===i.id),a=e.filter(e=>e.isDefault);a.length>1&&n.push({level:`error`,nodeId:i.id,message:`Decision "${i.id}" has ${a.length} default branches.`}),e.length===0?r.push({level:`warning`,nodeId:i.id,message:`Decision "${i.id}" has no outgoing branches.`}):a.length===0&&e.every(e=>Vd(e.condition))&&r.push({level:`warning`,nodeId:i.id,message:`Decision "${i.id}" has no default branch; it may dead-end when no condition matches.`})}if(l){let n=new Set([l]),i=[l];for(;i.length;){let e=i.shift();for(let r of t)r.source===e&&a.has(r.target)&&!n.has(r.target)&&(n.add(r.target),i.push(r.target))}for(let t of e)n.has(t.id)||r.push({level:`warning`,nodeId:t.id,message:`Node "${t.id}" is unreachable from the entry.`})}let u=t.filter(e=>e.type!==`back`),d=Ud(i.filter(e=>!!e),u);return d&&n.push({level:`error`,nodeId:d[0],cycle:d,message:`Cycle detected (${d.join(` → `)}). Mark the connection that closes the loop as a back-edge (Connection type → Back-edge) to declare an intentional revise/rework loop.`}),{errors:n,warnings:r,startNodeId:l}}function $(e,t,n,r={}){return{id:e,path:[`config`,e],label:t,kind:n,...r}}function Gd(e,t,n,r,i={}){return{id:`${e}.${t}`,path:[e,t],label:n,kind:r,...i}}var Kd=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`].map(e=>({value:e,label:e})),qd={start:[$(`triggerType`,`Trigger`,`select`,{help:`When this flow starts. Record triggers fire on data changes; schedule triggers fire on a cron.`,options:[{value:`record-after-create`,label:`Record created`},{value:`record-after-update`,label:`Record updated`},{value:`record-before-update`,label:`Record before update`},{value:`record-after-delete`,label:`Record deleted`},{value:`record-change`,label:`Record changed (any)`},{value:`schedule`,label:`Schedule (cron)`},{value:`manual`,label:`Manual / autolaunched`},{value:`webhook`,label:`Webhook / API`},{value:`event`,label:`Platform event`}]}),$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`crm_lead`,help:`Target object for record / scheduled-scan triggers.`,showWhen:{field:`triggerType`,equals:[`record-after-create`,`record-after-update`,`record-before-update`,`record-after-delete`,`record-change`,`schedule`,`webhook`,`event`]}}),$(`condition`,`Entry condition`,`expression`,{placeholder:`status == "qualifying" && previous.status != "qualifying"`,help:`CEL predicate — the flow runs only when this is true. Leave empty to run on every event.`,showWhen:{field:`triggerType`,equals:[`record-after-create`,`record-after-update`,`record-before-update`,`record-after-delete`,`record-change`,`schedule`,`webhook`,`event`]}}),$(`cron`,`Cron schedule`,`text`,{placeholder:`0 7 * * *`,help:`Cron expression for scheduled triggers.`,showWhen:{field:`triggerType`,equals:[`schedule`]}}),$(`criteria`,`Entry condition (legacy)`,`expression`,{placeholder:`status == "active"`,help:`Legacy key — prefer "Entry condition" (condition).`,showWhen:{field:`__legacy__`,equals:[]}}),$(`schedule`,`Cron schedule (legacy)`,`text`,{placeholder:`0 9 * * *`,help:`Legacy key — prefer "Cron schedule" (cron).`,showWhen:{field:`__legacy__`,equals:[]}})],end:[$(`outcome`,`Outcome`,`text`,{placeholder:`success · failure`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`result`})],decision:[$(`conditions`,`Branches`,`objectList`,{help:`Each branch has a label and a CEL expression (spec decision shape). A branch whose expression is "true" is the default/else path.`,columns:[{key:`label`,label:`Label`,kind:`text`,placeholder:`Has deals`},{key:`expression`,label:`Expression`,kind:`expression`,placeholder:`expiring_deals.length > 0`}]}),$(`condition`,`Condition (single)`,`expression`,{placeholder:`amount > 10000`,help:`Legacy single-branch condition (CEL). Prefer Branches above; per-edge conditions also live on the outgoing edges.`,showWhen:{field:`__legacy__`,equals:[]}})],assignment:[$(`assignments`,`Assignments`,`keyValue`,{help:`Set variables: each key is a variable, each value an expression or literal.`})],loop:[$(`collection`,`Collection`,`expression`,{placeholder:`{leadList}`,help:`Expression resolving to the items to iterate.`}),$(`iteratorVariable`,`Item variable`,`text`,{placeholder:`currentItem`})],map:[$(`collection`,`Collection`,`expression`,{placeholder:`{items}`,help:`Expression resolving to the array to process, one item at a time.`}),$(`flowName`,`Per-item flow`,`reference`,{ref:{kind:`flow`},placeholder:`one_task_signoff`,help:`Subflow run for each item — it may pause (e.g. an approval).`}),$(`iteratorVariable`,`Item variable`,`text`,{placeholder:`item`}),$(`itemObject`,`Item object`,`reference`,{ref:{kind:`object`},placeholder:`showcase_task`,help:`When items are records, the object they belong to (exposes each item as the child’s record).`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`results`,help:`Each item’s subflow output, collected in order.`})],create_record:[$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),$(`fields`,`Field values`,`keyValue`,{help:`Field values to write on the new record.`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`newRecord`})],update_record:[$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),$(`filter`,`Filter`,`keyValue`,{help:`Field/value pairs identifying the record(s) to update (e.g. id → {recordId}).`}),$(`fields`,`Field values`,`keyValue`,{help:`Field values to write.`})],delete_record:[$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),$(`filter`,`Filter`,`keyValue`,{help:`Field/value pairs identifying the record(s) to delete.`})],get_record:[$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),$(`filter`,`Filter`,`keyValue`,{help:`Field/value pairs to match (e.g. status → active). Operator values like {"$ne": null} are preserved.`}),$(`limit`,`Limit`,`number`,{placeholder:`100`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`records`})],http_request:[$(`method`,`Method`,`select`,{options:Kd,defaultValue:`GET`}),$(`url`,`URL`,`text`,{placeholder:`https://api.example.com/v1/contracts`}),$(`headers`,`Headers`,`keyValue`,{help:`Request headers (e.g. Authorization, Content-Type).`}),$(`body`,`Body`,`textarea`,{placeholder:`{ "key": "value" }`,help:`Request payload (JSON or expression).`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`response`}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`30000`}],script:[$(`actionType`,`Action type`,`select`,{options:[{value:`code`,label:`Code`},{value:`email`,label:`Email`},{value:`sms`,label:`SMS`},{value:`notification`,label:`Notification`}],defaultValue:`code`,help:`How this step runs. Leave as Code for a raw script.`}),$(`template`,`Template`,`reference`,{ref:{kindFrom:`actionType`,map:{email:`email-template`}},placeholder:`case_escalated`,help:`Message template id.`,showWhen:{field:`actionType`,equals:[`email`,`sms`,`notification`]}}),$(`recipients`,`Recipients`,`stringList`,{help:`One recipient per row (user id, field ref, or address).`,showWhen:{field:`actionType`,equals:[`email`,`sms`,`notification`]}}),$(`variables`,`Template variables`,`keyValue`,{help:`Values injected into the template.`,showWhen:{field:`actionType`,equals:[`email`,`sms`,`notification`]}}),$(`script`,`Code`,`textarea`,{placeholder:`return { ok: true };`,help:`Script body (JS/TS).`,refMode:`expression`,showWhen:{field:`actionType`,equals:[`code`]}}),$(`outputVariables`,`Output variables`,`stringList`,{help:`Names of variables this script writes back.`,showWhen:{field:`actionType`,equals:[`code`]}}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`30000`}],screen:[$(`title`,`Title`,`text`,{placeholder:`Request a discount`,help:`Heading shown above the screen.`}),$(`description`,`Description`,`textarea`,{placeholder:`Enter the deal amount and the discount you want.`,help:`Body text. Interpolates {var} references (e.g. {approval_path}).`}),$(`fields`,`Fields`,`objectList`,{help:`Input fields collected on this screen. Leave empty for a message-only screen.`,columns:[{key:`name`,label:`Name`,kind:`text`,placeholder:`discount`},{key:`label`,label:`Label`,kind:`text`,placeholder:`Discount %`},{key:`type`,label:`Type`,kind:`text`,placeholder:`number`},{key:`required`,label:`Required`,kind:`boolean`},{key:`visibleWhen`,label:`Visible when`,kind:`expression`,placeholder:`stage == "review"`}]}),$(`waitForInput`,`Wait for input`,`boolean`,{help:`Pause to show this screen even with no fields (a message / confirmation). A field-less screen with this off is a server pass-through.`}),$(`objectName`,`Object form`,`reference`,{ref:{kind:`object`},placeholder:`crm_account`,help:`Render this object’s full create/edit form (incl. master-detail) instead of a flat field list.`}),$(`idVariable`,`Saved-record variable`,`text`,{placeholder:`account_id`,help:`Object form only: variable bound to the saved record’s id, for later steps.`}),$(`mode`,`Form mode`,`select`,{options:[{value:`create`,label:`Create`},{value:`edit`,label:`Edit`}],defaultValue:`create`,help:`Object form only.`}),$(`defaults`,`Form defaults`,`keyValue`,{help:`Object form only: prefilled values (e.g. account → {account_id}).`})],approval:[$(`approvers`,`Approvers`,`objectList`,{help:`Who may act on this step. Wire the node’s out-edges with labels "approve" and "reject".`,columns:[{key:`type`,label:`Type`,kind:`select`,options:[{value:`user`,label:`User`},{value:`role`,label:`Role`},{value:`team`,label:`Team`},{value:`department`,label:`Department`},{value:`manager`,label:`Manager`},{value:`field`,label:`Field`},{value:`queue`,label:`Queue`}]},{key:`value`,label:`Value`,kind:`reference`,placeholder:`user id / role / field — per type`,ref:{kindFrom:`type`,objectSource:`$trigger`,map:{user:`user`,role:`role`,team:`team`,department:`department`,field:`object-field`,queue:`queue`}}}]}),$(`behavior`,`Behavior`,`select`,{options:[{value:`first_response`,label:`First response wins`},{value:`unanimous`,label:`Unanimous (all approve)`}],defaultValue:`first_response`,help:`How multiple approvers combine.`}),$(`lockRecord`,`Lock record`,`boolean`,{help:`Lock the triggering record from edits while this node is pending.`}),$(`approvalStatusField`,`Status field`,`reference`,{ref:{kind:`object-field`,objectSource:`$trigger`},placeholder:`approval_status`,help:`Business-object field to mirror request status onto (pending/approved/rejected). Should be readonly.`}),{id:`escalation.enabled`,path:[`config`,`escalation`,`enabled`],label:`SLA escalation`,kind:`boolean`,defaultValue:`false`,help:`Escalate when a decision is not recorded within the timeout.`},{id:`escalation.timeoutHours`,path:[`config`,`escalation`,`timeoutHours`],label:`Timeout (hours)`,kind:`number`,placeholder:`24`,showWhen:{field:`escalation.enabled`,equals:[`true`]}},{id:`escalation.action`,path:[`config`,`escalation`,`action`],label:`On timeout`,kind:`select`,defaultValue:`notify`,options:[{value:`notify`,label:`Notify`},{value:`reassign`,label:`Reassign`},{value:`auto_approve`,label:`Auto-approve`},{value:`auto_reject`,label:`Auto-reject`}],showWhen:{field:`escalation.enabled`,equals:[`true`]}},{id:`escalation.escalateTo`,path:[`config`,`escalation`,`escalateTo`],label:`Escalate to`,kind:`reference`,ref:{kind:`role`},placeholder:`user id / role / manager level`,showWhen:{field:`escalation.enabled`,equals:[`true`]}},{id:`escalation.notifySubmitter`,path:[`config`,`escalation`,`notifySubmitter`],label:`Notify submitter`,kind:`boolean`,showWhen:{field:`escalation.enabled`,equals:[`true`]}},$(`maxRevisions`,`Max revisions`,`number`,{placeholder:`3`,defaultValue:`3`,help:`Max send-backs for revision before the request auto-rejects (0 disables send-back). Needs a "revise" out-edge to take effect.`})],wait:[Gd(`waitEventConfig`,`eventType`,`Wait for`,`select`,{options:[{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`webhook`,label:`Webhook`},{value:`manual`,label:`Manual`},{value:`condition`,label:`Condition`}],defaultValue:`timer`,fallbackPath:[`config`,`eventType`]}),Gd(`waitEventConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H · P3D`,help:`ISO 8601 duration (e.g. PT1H, P3D).`,showWhen:{field:`waitEventConfig.eventType`,equals:[`timer`]},fallbackPath:[`config`,`timerDuration`]}),Gd(`waitEventConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.renewed`,showWhen:{field:`waitEventConfig.eventType`,equals:[`signal`,`webhook`]},fallbackPath:[`config`,`signalName`]}),Gd(`waitEventConfig`,`timeoutMs`,`Timeout (ms)`,`number`,{placeholder:`3600000`,fallbackPath:[`config`,`timeoutMs`]}),Gd(`waitEventConfig`,`onTimeout`,`On timeout`,`select`,{options:[{value:`fail`,label:`Fail`},{value:`continue`,label:`Continue`}],defaultValue:`fail`,fallbackPath:[`config`,`onTimeout`]})],subflow:[$(`flowName`,`Flow`,`reference`,{ref:{kind:`flow`},placeholder:`escalation_flow`}),$(`input`,`Input mapping`,`keyValue`,{help:`Values passed to the subflow’s input variables.`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`subResult`}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`60000`}],connector_action:[Gd(`connectorConfig`,`connectorId`,`Connector`,`reference`,{ref:{kind:`connector`},placeholder:`slack · email · salesforce`}),Gd(`connectorConfig`,`actionId`,`Action`,`reference`,{ref:{kind:`connector-action`,connectorSource:`connectorId`},placeholder:`sendMessage · send`}),Gd(`connectorConfig`,`input`,`Input`,`keyValue`,{help:`Mapped inputs for the connector action.`}),{id:`timeoutMs`,path:[`timeoutMs`],label:`Timeout (ms)`,kind:`number`,placeholder:`30000`}],parallel:[],try_catch:[$(`errorVariable`,`Error variable`,`text`,{placeholder:`$error`,help:`Variable the caught error is bound to inside the catch region.`})],parallel_gateway:[],join_gateway:[],boundary_event:[Gd(`boundaryConfig`,`attachedToNodeId`,`Attached to`,`reference`,{ref:{kind:`node`},placeholder:`host node id`,help:`Host node this boundary event monitors.`}),Gd(`boundaryConfig`,`eventType`,`Event type`,`select`,{options:[{value:`error`,label:`Error`},{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`cancel`,label:`Cancel`}],defaultValue:`error`}),Gd(`boundaryConfig`,`interrupting`,`Interrupting`,`boolean`,{help:`Cancel the host activity when this event fires.`}),Gd(`boundaryConfig`,`errorCode`,`Error code`,`text`,{placeholder:`TIMEOUT (empty = all)`,showWhen:{field:`boundaryConfig.eventType`,equals:[`error`]}}),Gd(`boundaryConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H`,showWhen:{field:`boundaryConfig.eventType`,equals:[`timer`]}}),Gd(`boundaryConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.cancelled`,showWhen:{field:`boundaryConfig.eventType`,equals:[`signal`]}})],legacy_action:[$(`action`,`Action`,`text`,{placeholder:`sendEmail · createTask · update · query`}),$(`objectName`,`Object`,`reference`,{ref:{kind:`object`},placeholder:`contract`}),$(`recordId`,`Record`,`expression`,{placeholder:`record.id`}),$(`params`,`Parameters`,`keyValue`,{help:`Action inputs. Values auto-typed: 3 → number, true → boolean.`}),$(`fields`,`Field values`,`keyValue`),$(`outputVariable`,`Output variable`,`text`,{placeholder:`result`})]},Jd={action:`legacy_action`,http:`http_request`,branch:`decision`,gateway:`decision`,condition:`decision`,timer:`wait`,delay:`wait`,flow:`subflow`,invoke:`subflow`,task:`legacy_action`,user_task:`screen`,service_task:`connector_action`,script_task:`script`,notification:`connector_action`,signal:`boundary_event`,webhook:`connector_action`,for_each:`loop`};function Yd(e){return e?qd[Jd[e]??e]??[]:[]}function Xd(e,t){let n=t=>{let n=e;for(let e of t)if(n&&typeof n==`object`&&!Array.isArray(n))n=n[e];else return;return n},r=n(t.path);return r===void 0?t.fallbackPath?n(t.fallbackPath):void 0:r}function Zd(e){return e.path.length>=2&&e.path[0]===`config`?e.path[1]:void 0}function Qd(e,t,n){if(!e.showWhen)return!0;let r=Xd(t,e);if(r!=null&&r!==``)return!0;let i=n.find(t=>t.id===e.showWhen.field);if(!i)return!1;let a=Xd(t,i),o=a==null||a===``?i.defaultValue:a,s=typeof o==`boolean`?String(o):o;return typeof s==`string`&&e.showWhen.equals.includes(s)}var $d=[`start`,`create_record`,`update_record`,`delete_record`,`get_record`,`decision`,`assignment`,`loop`,`http_request`,`script`,`screen`,`approval`,`wait`,`subflow`,`map`,`connector_action`,`parallel`,`try_catch`,`end`],ef=new Set([`record-after-create`,`record-after-update`,`record-before-update`,`record-after-delete`,`record-change`]),tf=new Set([`record-after-update`,`record-before-update`,`record-change`]);function nf(e){return Array.isArray(e)?e:[]}function rf(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function af(e){return typeof e==`string`&&e?e:void 0}function of(e,t){let n=new Map;for(let e of t){let t=af(e.source),r=af(e.target);if(!t||!r)continue;let i=n.get(r);i?i.push(t):n.set(r,[t])}let r=new Set,i=[...n.get(e)??[]];for(;i.length;){let t=i.pop();if(!(t===e||r.has(t))){r.add(t);for(let e of n.get(t)??[])i.push(e)}}return r}function sf(e){let t=af(e.type),n=rf(e.config),r=af(e.id)??``,i=af(e.label),a=i&&i!==r?i:r||void 0,o=[],s=(e,t=`outputs`)=>{e&&!o.some(t=>t.token===e)&&o.push({token:e,label:e,detail:a,group:t})};(t===`loop`||t===`map`)&&s(af(n.iteratorVariable),`loop`),s(af(n.outputVariable));for(let e of nf(n.outputVariables))s(af(e));if(s(af(n.idVariable)),t===`assignment`){let e=n.assignments;if(Array.isArray(e))for(let t of e){let e=rf(t);s(af(e.variable)??af(e.name)??af(e.key))}else if(e&&typeof e==`object`)for(let t of Object.keys(e))s(t)}if(t===`screen`||t===`user_task`)for(let e of nf(n.fields))s(af(rf(e).name));return o}function cf(e){let t=new Set;return e.filter(e=>t.has(e.token)?!1:(t.add(e.token),!0))}function lf(e,t){let n=nf(e.nodes).map(rf),r=nf(e.edges),i=[];for(let t of nf(e.variables)){let e=rf(t),n=af(e.name);if(!n)continue;let r=af(e.type);i.push({token:n,label:n,detail:r?`variable · ${r}`:`variable`,group:`variables`})}if(!t)return{refs:cf(i)};let a=of(t,r),o=n.find(e=>af(e.type)===`start`),s=af(o?.id);for(let e of n){let n=af(e.id);if(!(!n||n===t||!a.has(n))&&n!==s)for(let t of sf(e))i.push(t)}if(o){let e=rf(o.config),n=af(e.triggerType),r=af(e.objectName),c=!!n&&ef.has(n),l=s===t||!!s&&a.has(s);if(c&&r&&l){let e=s===t,a=tf.has(n);return e||i.push({token:`record`,label:`record`,detail:`trigger record · ${r}`,group:`trigger`}),a&&i.push({token:`previous`,label:`previous`,detail:`record values before the change`,group:`trigger`}),{refs:cf(i),trigger:{objectName:r,fieldPrefix:e?``:`record.`,includePrevious:a}}}}return{refs:cf(i)}}function uf(e,t){let n=[];for(let r of t){if(!r?.name)continue;let t=`${e.fieldPrefix}${r.name}`,i=r.label&&r.label!==r.name?r.label:r.type;n.push({token:t,label:t,detail:i,group:`trigger`}),e.includePrevious&&n.push({token:`previous.${r.name}`,label:`previous.${r.name}`,detail:i?`prior ${i}`:`prior value`,group:`trigger`})}return n}var df=new Set([`true`,`false`,`null`,`in`]),ff=new Set([`env`,`request`,`context`,`user`,`now`,`today`,`self`,`data`]);function pf(e){let t=new Set;for(let n of e){let e=n.token.split(`.`)[0];e&&t.add(e)}return t}function mf(e,t,n=2){if(Math.abs(e.length-t.length)>n)return n+1;let r=Array(t.length+1);for(let e=0;e<=t.length;e++)r[e]=e;for(let i=1;i<=e.length;i++){let a=r[0];r[0]=i;let o=r[0];for(let n=1;n<=t.length;n++){let s=r[n];r[n]=Math.min(r[n]+1,r[n-1]+1,a+(e[i-1]===t[n-1]?0:1)),a=s,r[n]<o&&(o=r[n])}if(o>n)return n+1}return r[t.length]}function hf(e){let t=e.replace(/'(?:[^'\\]|\\.)*'/g,` `).replace(/"(?:[^"\\]|\\.)*"/g,` `),n=[],r=/(?<![.\w$])([A-Za-z_$][\w$]*)/g,i;for(;i=r.exec(t);){let e=i[1];/^\s*\(/.test(t.slice(i.index+e.length))||df.has(e)||n.push(e)}return n}function gf(e,t,n){let r=``;if(typeof e==`string`?r=e:e&&typeof e==`object`&&(r=String(e.source??``)),!r.trim()||n.size===0)return[];let i=r;if(t===`template`){let e=r.match(/\{([^{}]+)\}/g);if(!e)return[];i=e.map(e=>e.slice(1,-1)).join(` ; `)}let a=new Set,o=[];for(let e of hf(i)){if(a.has(e)||(a.add(e),n.has(e)||ff.has(e)||e.startsWith(`$`)))continue;let t,r=3;for(let i of n){let n=mf(e,i,2);n<r&&(r=n,t=i)}o.push({token:e,suggestion:r<=2?t:void 0})}return o}function _f(e){if(e.length===1){let t=e[0];return t.suggestion?`Unknown reference \`${t.token}\` — did you mean \`${t.suggestion}\`?`:`\`${t.token}\` is not a reference in scope at this step.`}return`Not in scope: ${e.map(e=>`\`${e.token}\``).join(`, `)}.`}var vf=/(?:^|[^{])\{\s*([A-Za-z_$][\w.$]*)\s*\}(?!\})/;function yf(e,t,n){let r=0;for(let i of e)if(i===t)r++;else if(i===n&&(r--,r<0))return!1;return r===0}function bf(e,t){let n=``,r;if(typeof t==`string`)n=t;else if(t&&typeof t==`object`){let e=t;r=e.dialect,n=e.source??``}if(!n.trim())return null;if(e===`template`){if(r&&r!==`template`)return{message:`Expected a text template but got a \`${r}\` expression.`};yf(n.replace(/\{\{/g,``).replace(/\}\}/g,``),`{`,`}`);let e=vf.exec(n);return e?{message:`Single-brace \`{${e[1]}}\` is not a valid template hole — use double braces: \`{{ ${e[1]} }}\`.`}:null}if(r&&r!==`cel`)return{message:`Expected a CEL expression but got a \`${r}\` dialect.`};let i=vf.exec(n);return i?{message:`It looks like a \`{${i[1]}}\` template brace was used inside a condition — \`{…}\` parses as a CEL map literal and fails. Write the bare reference instead, e.g. \`${i[1]}\`. Conditions are bare CEL (e.g. \`record.rating >= 4\`).`}:yf(n,`(`,`)`)?yf(n,`[`,`]`)?null:{message:`Unbalanced brackets in \`${n}\`.`}:{message:`Unbalanced parentheses in \`${n}\`.`}}function xf(e){return Array.isArray(e)?e:[]}function Sf(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function Cf(e){return typeof e==`string`&&e?e:void 0}function wf(e,t){let n=bf(`predicate`,e);if(n)return{level:`error`,message:n.message};if(t&&t.size>0){let n=gf(e,`predicate`,t);if(n.length>0)return{level:`warning`,message:_f(n)}}return null}function Tf(e){let t=xf(e.nodes).map(Sf),n=xf(e.edges).map(Sf),r=Cf(t.find(e=>Cf(e.type)===`start`)?.id),i=[];for(let n of t){let t=Cf(n.id),a=Cf(n.type);if(!t||!a)continue;let o=t===r?null:pf(lf(e,t).refs);for(let e of Yd(a))if(e.kind===`expression`){let r=wf(Xd(n,e),o);r&&i.push({target:{kind:`node`,nodeId:t},level:r.level,message:r.message})}else if(e.kind===`objectList`&&e.columns){let r=e.columns.filter(e=>e.kind===`expression`);if(r.length===0)continue;for(let a of xf(Xd(n,e))){let e=Sf(a),n=Cf(e.label);for(let a of r){let r=wf(e[a.key],o);if(r){let e=n||a.label;i.push({target:{kind:`node`,nodeId:t},level:r.level,message:e?`${e}: ${r.message}`:r.message})}}}}}for(let t of n){let n=Cf(t.source),a=Cf(t.target);if(!n||!a||t.isDefault===!0)continue;let o=n===r?null:pf(lf(e,n).refs),s=wf(t.condition,o);s&&i.push({target:{kind:`edge`,source:n,target:a},level:s.level,message:s.message})}return i}function Ef(e,t){return`${e}->${t}`}function Df(e,t,n){let r=e.findIndex(e=>e.source===t&&e.target===n);return r>=0?Cd(e[r],r):`${t}->${n}#-1`}function Of(e){return Array.isArray(e)?e:typeof e!=`string`||!e?[]:e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e})}function kf(e,t){if(e.edge){let{source:n,target:r}=e.edge;return{target:{kind:`edge`,source:n,target:r,edgeKey:Df(t,n,r)}}}if(e.cycle&&e.cycle.length>=2){let n=e.cycle,r=n[n.length-2],i=n[n.length-1],a=[],o=[];for(let e=0;e<n.length-1;e++)a.push(n[e]),o.push({source:n[e],target:n[e+1]});return{target:{kind:`edge`,source:r,target:i,edgeKey:Df(t,r,i)},highlight:{nodeIds:a,edges:o}}}return e.nodeId?{target:{kind:`node`,nodeId:e.nodeId}}:{target:{kind:`flow`}}}function Af(e,t,n){let r=Of(e);if(r.length>=2&&typeof r[1]==`number`){let e=r[1];if(r[0]===`nodes`&&t[e]?.id)return{kind:`node`,nodeId:t[e].id};if(r[0]===`edges`&&n[e]){let t=n[e];return{kind:`edge`,source:t.source,target:t.target,edgeKey:Cd(t,e)}}}return{kind:`flow`}}function jf(e){return e.kind===`node`?`n:${e.nodeId}`:e.kind===`edge`?`e:${e.source}->${e.target}`:`flow`}function Mf({nodes:e,edges:t,serverDiagnostics:n,variables:r}){let i=[],a=Wd(e,t),o=(e,n)=>{n.forEach((n,r)=>{let{target:a,highlight:o}=kf(n,t);i.push({id:`structural:${e}:${r}:${jf(a)}`,level:e,message:n.message,target:a,source:`structural`,...o?{highlight:o}:{}})})};return o(`error`,a.errors),o(`warning`,a.warnings),(n??[]).forEach((n,r)=>{let a=n.severity===`warning`?`warning`:`error`,o=Af(n.path,e,t);i.push({id:`server:${r}:${jf(o)}`,level:a,message:n.message,target:o,source:`server`})}),Tf({nodes:e,edges:t,variables:r??[]}).forEach((e,n)=>{let r=e.target.kind===`edge`?{kind:`edge`,source:e.target.source,target:e.target.target,edgeKey:Df(t,e.target.source,e.target.target)}:{kind:`node`,nodeId:e.target.nodeId};i.push({id:`expression:${e.level}:${n}:${jf(r)}`,level:e.level,message:e.message,target:r,source:`expression`})}),i.map((e,t)=>[e,t]).sort((e,t)=>e[0].level===t[0].level?e[1]-t[1]:e[0].level===`error`?-1:1).map(([e])=>e)}function Nf(e){return{level:e.some(e=>e.level===`error`)?`error`:`warning`,title:e.map(e=>e.message).join(`
17
+ `),count:e.length}}function Pf(e){let t=new Map,n=new Map;for(let r of e)if(r.target.kind===`node`){let e=t.get(r.target.nodeId)??[];e.push(r),t.set(r.target.nodeId,e)}else if(r.target.kind===`edge`){let e=Ef(r.target.source,r.target.target),t=n.get(e)??[];t.push(r),n.set(e,t)}let r=new Map;for(let[e,n]of t)r.set(e,Nf(n));let i=new Map;for(let[e,t]of n)i.set(e,Nf(t));return{byNode:r,byEdge:i}}function Ff(e){let t=new Set,n=new Set;for(let r of e)if(r.level===`error`){r.target.kind===`node`?t.add(r.target.nodeId):r.target.kind===`edge`&&n.add(Ef(r.target.source,r.target.target));for(let e of r.highlight?.nodeIds??[])t.add(e);for(let e of r.highlight?.edges??[])n.add(Ef(e.source,e.target))}return{invalidNodeIds:[...t],invalidEdges:n}}var If=.4,Lf=1.6,Rf=4;function zf({nodes:e,edges:t,editable:n,designMode:r,selectedId:i,selectedEdgeId:a,locale:o,activeNodeId:s,visitedNodeIds:c,traversedEdgeIds:l,invalidNodeIds:u,invalidEdges:d,onRevealProblem:f,problems:p,revealSignal:m,onSelect:h,onSelectEdge:g,onPatch:_}){let v=X.useRef(null),[y,b]=X.useState(1),[x,S]=X.useState({x:0,y:0}),[C,w]=X.useState(!1),T=zd(),[E,D]=X.useState(null),O=X.useRef(null),k=X.useRef(null),A=X.useMemo(()=>fd(e,t),[e,t]),j=X.useMemo(()=>pd(A),[A]),ee=X.useMemo(()=>new Set(c??[]),[c]),te=X.useMemo(()=>new Set(l??[]),[l]),ne=X.useMemo(()=>new Set(u??[]),[u]),M=(c?.length??0)>0||!!s,{byNode:re,byEdge:ie}=X.useMemo(()=>Pf(p??[]),[p]),ae=X.useMemo(()=>(p??[]).filter(e=>e.level===`error`),[p]),oe=X.useCallback(e=>E&&E.id===e?{x:E.x,y:E.y}:A.get(e)??{x:0,y:0},[E,A]),N=X.useCallback((t,n,r)=>{if(!_)return;let i=e.findIndex(e=>e.id===t);if(i<0)return;let a=e[i];_({nodes:si(e,i,{...a,ui:{...a.ui??{},x:n,y:r}})})},[e,_]),P=X.useCallback((n,r)=>{if(!_)return;let i=ui(`node`,e.map(e=>e.id).filter(Boolean)),a=n===`end`?`End`:Md(n),o=r?.at,s={id:i,type:n,label:a,...Nd(n),...o?{ui:{x:o.x,y:o.y}}:{}},c={nodes:mi(e,s)};if(r?.from){let n={id:ui(`edge`,t.map(e=>e.id).filter(Boolean)),source:r.from,target:i},a=e.find(e=>e.id===r.from);if(a?.type===`decision`){let e=(Array.isArray(a.config?.conditions)?a.config.conditions:[])[t.filter(e=>e.source===r.from).length];if(e&&typeof e==`object`){let t=typeof e.expression==`string`?e.expression.trim():``,r=typeof e.label==`string`?e.label.trim():``;r&&(n.label=r),t===`true`?n.isDefault=!0:t&&(n.condition=t)}}c.edges=mi(t,n)}_(c),h(s),w(!1)},[t,e,_,h,oe]),se=X.useCallback((n,r=`create_record`)=>{if(!_)return;let i=t.findIndex(e=>e===n);if(i<0)return;let a=ui(`node`,e.map(e=>e.id).filter(Boolean)),o=oe(n.source),s=oe(n.target),c={x:(o.x+s.x)/2,y:(o.y+s.y)/2},l={id:a,type:r,label:Md(r),...Nd(r),ui:{x:c.x,y:c.y}},u={...n,target:a},d={id:ui(`edge`,[...t.map(e=>e.id).filter(Boolean),`edge`]),source:a,target:n.target},f=si(t,i,u);_({nodes:mi(e,l),edges:mi(f,d)}),h(l)},[t,e,_,h,oe]),ce=X.useCallback(n=>{if(!_||!e.some(e=>e.id===n))return;let r=ui(`node`,e.map(e=>e.id).filter(Boolean)),i={id:r,type:`wait`,label:`Awaiting Revision`,waitEventConfig:{eventType:`signal`,signalName:`revision`,onTimeout:`fail`}},a=t.map(e=>e.id).filter(Boolean),o=ui(`edge`,a),s=ui(`edge`,[...a,o]),c={id:o,source:n,target:r,label:`revise`},l={id:s,source:r,target:n,label:`resubmit`,type:`back`};_({nodes:mi(e,i),edges:mi(mi(t,c),l)}),h(i)},[t,e,_,h]),le=X.useMemo(()=>{let e=new Set;for(let n of t)typeof n.label==`string`&&n.label.trim().toLowerCase()===`revise`&&e.add(n.source);return e},[t]),ue=X.useCallback(n=>{_&&(_({nodes:e.filter(e=>e.id!==n),edges:t.filter(e=>e.source!==n&&e.target!==n)}),h(null))},[t,e,_,h]),de=X.useCallback(e=>t=>{if(!n||t.button!==0)return;t.stopPropagation();let r=oe(e);O.current={nodeId:e,startX:t.clientX,startY:t.clientY,originX:r.x,originY:r.y,moved:!1},t.currentTarget.setPointerCapture?.(t.pointerId)},[n,oe]),fe=X.useCallback(e=>{let t=O.current;if(!t)return;let n=(e.clientX-t.startX)/y,r=(e.clientY-t.startY)/y;!t.moved&&Math.hypot(e.clientX-t.startX,e.clientY-t.startY)<Rf||(t.moved=!0,D({id:t.nodeId,x:Math.max(0,t.originX+n),y:Math.max(0,t.originY+r)}))},[y]),pe=X.useCallback(e=>{let t=O.current;O.current=null,t&&(e.currentTarget.releasePointerCapture?.(e.pointerId),t.moved&&E&&N(t.nodeId,Math.round(E.x),Math.round(E.y)),D(null))},[E,N]),me=X.useCallback(e=>{e.button===0&&(h(null),k.current={startX:e.clientX,startY:e.clientY,originX:x.x,originY:x.y},e.currentTarget.setPointerCapture?.(e.pointerId))},[h,x.x,x.y]),he=X.useCallback(e=>{let t=k.current;t&&S({x:t.originX+(e.clientX-t.startX),y:t.originY+(e.clientY-t.startY)})},[]),ge=X.useCallback(e=>{k.current&&e.currentTarget.releasePointerCapture?.(e.pointerId),k.current=null},[]),_e=e=>Math.min(Lf,Math.max(If,e)),ve=X.useCallback(()=>{let e=v.current;if(!e)return;let t=(e.clientWidth-32)/j.width,n=(e.clientHeight-32)/j.height,r=_e(Math.min(t,n));b(r),S({x:(e.clientWidth-j.width*r)/2,y:Math.max(16,(e.clientHeight-j.height*r)/2)})},[j.height,j.width]);X.useEffect(()=>{let e=v.current;e&&(b(1),S({x:(e.clientWidth-j.width)/2,y:Math.max(16,(e.clientHeight-j.height)/2)}))},[]),X.useEffect(()=>{if(!m)return;let e=v.current;if(!e)return;let t=m.target,n=null;if(t.kind===`node`){let e=A.get(t.nodeId);e&&(n={x:e.x+240/2,y:e.y+66/2})}else if(t.kind===`edge`){let e=A.get(t.source),r=A.get(t.target);e&&r&&(n={x:(e.x+r.x)/2+240/2,y:(e.y+r.y)/2+66/2})}n&&S({x:e.clientWidth/2-n.x*y,y:e.clientHeight/2-n.y*y})},[m?.nonce]);let ye=X.useCallback(e=>{if(!(!n||!i)&&(e.key===`Delete`||e.key===`Backspace`)){let t=e.target;if(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable)return;e.preventDefault(),ue(i)}},[ue,n,i]);return(0,Y.jsxs)(`div`,{className:`relative h-full min-h-[320px] w-full overflow-hidden`,children:[ae.length>0&&(0,Y.jsxs)(`div`,{className:`absolute left-2 top-2 z-30 max-w-[min(60%,420px)] space-y-1`,children:[ae.slice(0,3).map(e=>{let t=!!f&&e.target.kind!==`flow`;return(0,Y.jsxs)(`button`,{type:`button`,role:`alert`,disabled:!t,onPointerDown:e=>e.stopPropagation(),onClick:t?t=>{t.stopPropagation(),f(e)}:void 0,title:t?`Reveal on canvas`:void 0,className:B(`flex w-full items-start gap-1.5 rounded-lg border border-destructive/40 bg-destructive/10 px-2.5 py-1.5 text-left text-[11px] leading-snug text-destructive shadow-sm backdrop-blur-sm transition-colors`,t&&`cursor-pointer hover:border-destructive/60 hover:bg-destructive/20`),children:[(0,Y.jsx)(I,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,Y.jsx)(`span`,{children:e.message})]},e.id)}),ae.length>3&&(0,Y.jsxs)(`div`,{className:`px-2.5 text-[10px] text-destructive/80`,children:[`+`,ae.length-3,` more…`]})]}),(0,Y.jsxs)(`div`,{className:`absolute right-2 top-2 z-30 flex items-center gap-1.5`,children:[n&&(0,Y.jsx)(Fd,{locale:o,items:T,open:C,onOpenChange:w,onPick:e=>P(e,{from:i??void 0}),children:(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-lg border bg-background/90 px-2.5 py-1.5 text-xs font-medium shadow-sm backdrop-blur-sm transition-colors hover:border-primary/50 hover:bg-accent hover:text-foreground`,children:[(0,Y.jsx)(L,{className:`h-3.5 w-3.5`}),J(`engine.inspector.add.node`,o)]})}),(0,Y.jsxs)(`div`,{className:`flex items-center rounded-lg border bg-background/90 shadow-sm backdrop-blur-sm`,children:[(0,Y.jsx)(`button`,{type:`button`,title:`Zoom out`,"aria-label":`Zoom out`,onClick:()=>b(e=>_e(e-.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(Ar,{className:`h-3.5 w-3.5`})}),(0,Y.jsxs)(`span`,{className:`w-10 text-center text-[11px] tabular-nums text-muted-foreground`,children:[Math.round(y*100),`%`]}),(0,Y.jsx)(`button`,{type:`button`,title:`Zoom in`,"aria-label":`Zoom in`,onClick:()=>b(e=>_e(e+.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(bt,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(`button`,{type:`button`,title:`Fit to view`,"aria-label":`Fit to view`,onClick:ve,className:`inline-flex h-7 w-7 items-center justify-center border-l text-muted-foreground hover:text-foreground`,children:(0,Y.jsx)(Ke,{className:`h-3.5 w-3.5`})})]})]}),(0,Y.jsx)(`div`,{ref:v,tabIndex:0,role:`application`,"aria-label":`Flow canvas`,onKeyDown:ye,onPointerDown:me,onPointerMove:e=>{he(e),fe(e)},onPointerUp:e=>{ge(e),pe(e)},className:B(`h-full w-full cursor-grab outline-none active:cursor-grabbing`,`bg-muted/15 dark:bg-background/30`,`shadow-[inset_0_0_90px_rgba(0,0,0,0.05)]`),style:{backgroundImage:`radial-gradient(circle at 1px 1px, hsl(var(--border)) 1px, transparent 0)`,backgroundSize:`${18*y}px ${18*y}px`,backgroundPosition:`${x.x}px ${x.y}px`},children:(0,Y.jsxs)(`div`,{className:`relative origin-top-left`,style:{width:j.width,height:j.height,transform:`translate(${x.x}px, ${x.y}px) scale(${y})`},children:[(0,Y.jsxs)(`svg`,{className:`pointer-events-none absolute left-0 top-0 overflow-visible`,width:j.width,height:j.height,children:[(0,Y.jsxs)(`defs`,{children:[(0,Y.jsx)(`marker`,{id:`flow-arrow`,viewBox:`0 0 10 10`,refX:`8`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,Y.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,className:`fill-muted-foreground/55`})}),(0,Y.jsx)(`marker`,{id:`flow-arrow-back`,viewBox:`0 0 10 10`,refX:`8`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,Y.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,className:`fill-amber-500/80`})}),(0,Y.jsx)(`marker`,{id:`flow-arrow-error`,viewBox:`0 0 10 10`,refX:`8`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,Y.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,className:`fill-destructive`})})]}),t.map((e,t)=>{let i=A.get(e.source),o=A.get(e.target);if(!i||!o)return null;let s=vd(e),c=!s&&!!d?.has(`${e.source}->${e.target}`),l=E?.id===e.source?oe(e.source):i,u=E?.id===e.target?oe(e.target):o,f=s?yd(l):md(l),p=s?yd(u):hd(u),m=s?Sd(f,p):_d(f,p),h=wd(e.condition),_=e.isDefault?`else`:h?`if ${h}`:e.label,v=Cd(e,t),y=ie.get(Ef(e.source,e.target)),b=te.has(v),x=a===v,S=s?xd(f,p):gd(f,p),C=r&&!!g;return(0,Y.jsxs)(`g`,{"data-invalid":c||void 0,children:[(0,Y.jsx)(`path`,{d:S,strokeLinecap:`round`,strokeDasharray:s?`5 4`:void 0,className:B(`fill-none transition-[stroke] duration-150`,b?`stroke-sky-500`:x?`stroke-primary`:c?`stroke-destructive`:s?`stroke-amber-500/70`:M?`stroke-muted-foreground/20`:`stroke-muted-foreground/40`),strokeWidth:b||x||c?2.5:1.75,markerEnd:c?`url(#flow-arrow-error)`:s?`url(#flow-arrow-back)`:`url(#flow-arrow)`}),C&&(0,Y.jsx)(`path`,{d:S,className:`pointer-events-auto cursor-pointer fill-none stroke-transparent`,strokeWidth:14,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),g(e,v)},children:(0,Y.jsx)(`title`,{children:c?`${e.source} → ${e.target} — part of an un-declared cycle; mark the edge that closes the loop as a back-edge`:s?`${e.source} ↩ ${e.target} (back-edge)`:`${e.source} → ${e.target}`})}),_&&(0,Y.jsx)(`foreignObject`,{x:m.x-60,y:m.y-11,width:120,height:22,className:B(C&&`pointer-events-auto`),children:(0,Y.jsx)(`div`,{className:`flex justify-center`,children:(0,Y.jsx)(`span`,{onPointerDown:C?e=>e.stopPropagation():void 0,onClick:C?t=>{t.stopPropagation(),g(e,v)}:void 0,className:B(`max-w-full truncate rounded-full border bg-background/95 px-2 py-0.5 text-[10px] font-medium shadow-sm backdrop-blur-sm transition-colors`,C&&`cursor-pointer hover:border-primary/60`,x?`border-primary text-primary`:c?`border-destructive/60 text-destructive`:s?`border-amber-500/50 text-amber-600 dark:text-amber-400`:`border-border text-muted-foreground`),children:_})})}),y&&(0,Y.jsx)(`foreignObject`,{x:m.x-9,y:m.y-30,width:18,height:18,className:`pointer-events-auto overflow-visible`,children:(0,Y.jsx)(`span`,{title:y.title,"data-problem":y.level,className:B(`inline-flex h-[18px] w-[18px] items-center justify-center rounded-full border bg-background shadow-sm`,y.level===`error`?`border-destructive/50 text-destructive`:`border-amber-500/50 text-amber-600 dark:text-amber-400`),children:y.level===`error`?(0,Y.jsx)(rt,{className:`h-3 w-3`}):(0,Y.jsx)(I,{className:`h-3 w-3`})})}),n&&!s&&(0,Y.jsx)(`foreignObject`,{x:_?m.x+66:m.x-11,y:m.y-11,width:22,height:22,className:`pointer-events-auto`,children:(0,Y.jsx)(`button`,{type:`button`,title:`Insert node here`,"aria-label":`Insert node here`,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),se(e)},className:`inline-flex h-[22px] w-[22px] items-center justify-center rounded-full border bg-background/90 text-muted-foreground opacity-50 shadow-sm backdrop-blur-sm transition-all hover:scale-110 hover:border-primary hover:bg-background hover:text-primary hover:opacity-100 focus-visible:opacity-100`,children:(0,Y.jsx)(L,{className:`h-3 w-3`})})})]},e.id||`${e.source}-${e.target}-${t}`)})]}),e.map(e=>{let t=s===e.id?`active`:ee.has(e.id)?`visited`:void 0;return(0,Y.jsx)(Pd,{id:e.id,type:e.type,label:e.label||e.id,summary:Bf(e),position:oe(e.id),selected:i===e.id,editable:n,runState:t,dimmed:M&&!t,onPointerDown:de(e.id),onSelect:()=>r&&h(e),onAppend:()=>P(`create_record`,{from:e.id}),onAddReviseLoop:n&&e.type===`approval`&&!le.has(e.id)?()=>ce(e.id):void 0,invalid:ne.has(e.id),badge:re.get(e.id)},e.id)})]})})]})}function Bf(e){let t=e.config,n=e=>typeof e==`string`&&e?e:void 0,r=(t,r)=>{let i=e[t];return i&&typeof i==`object`?n(i[r]):void 0},i=e=>t?n(t[e]):void 0;if(e.type===`start`)return i(`condition`)||i(`criteria`)||i(`objectName`)||i(`cron`)||i(`schedule`)||i(`triggerType`);if(e.type===`decision`){let e=t?.conditions;if(Array.isArray(e)&&e.length){let t=e.map(e=>e&&typeof e==`object`?n(e.label):void 0).filter(Boolean);return t.length?t.join(` / `):`${e.length} branches`}return i(`condition`)}if(e.type===`script`)return i(`actionType`)||i(`template`)||(t&&t.script?`code`:void 0);if(e.type===`approval`){let e=t?.approvers,n=Array.isArray(e)?e.length:0,r=i(`behavior`);return n>0?`${n} approver${n===1?``:`s`}${r===`unanimous`?` · all`:``}`:r||void 0}return i(`objectName`)||r(`connectorConfig`,`actionId`)||r(`waitEventConfig`,`timerDuration`)||r(`waitEventConfig`,`eventType`)||r(`boundaryConfig`,`eventType`)||i(`condition`)||i(`flowName`)||i(`url`)||i(`collection`)||i(`action`)||i(`flow`)||i(`event`)||i(`duration`)||void 0}var Vf=500,Hf=new Set([`start`]),Uf=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`]),Wf=new Set([`join_gateway`,`subflow`,`boundary_event`,`parallel`,`try_catch`]),Gf=(e,t)=>e.id||`${e.source}->${e.target}#${t}`,Kf=e=>typeof e==`string`?e:void 0,qf=e=>typeof e==`string`&&e?e:void 0,Jf=class{nodes=new Map;edges=[];mocks={};seq=0;state={status:`idle`,variables:{},steps:[],frontier:[],activeNodeId:null,visitedNodeIds:[],traversedEdgeIds:[]};constructor(e,t){for(let t of e)this.nodes.set(t.id,t);this.edges=t}reset(e={},t={}){let n=Wd([...this.nodes.values()],this.edges);return this.mocks=t,this.seq=0,this.state={status:n.errors.length?`error`:`idle`,variables:{...e},steps:[],frontier:n.startNodeId?[n.startNodeId]:[],activeNodeId:null,visitedNodeIds:[],traversedEdgeIds:[],error:n.errors.length?n.errors[0].message:void 0},n}get done(){return this.state.status===`done`||this.state.status===`error`}step(){let e=this.state;if(e.status===`error`||e.status===`done`||e.status===`paused`)return null;if(this.seq>=Vf)return e.status=`error`,e.error=`Step limit (${Vf}) exceeded — the flow may contain an infinite loop.`,null;let t=e.frontier.shift();if(!t)return e.status=`done`,e.activeNodeId=null,null;let n=this.nodes.get(t);if(!n)return this.record(t,`unknown`,t,`error`,{error:`Node "${t}" not found.`});e.status=`running`,e.activeNodeId=t,e.visitedNodeIds.includes(t)||e.visitedNodeIds.push(t);let r=this.execute(n);return e.status===`running`&&e.frontier.length===0&&(e.status=`done`,e.activeNodeId=null),r}runToEnd(){let e=0;for(;this.state.status!==`done`&&this.state.status!==`error`&&this.state.status!==`paused`&&!(++e>505);)this.step();return this.state}resume(e={}){let t=this.state;if(t.status!==`paused`||!t.activeNodeId)return;let n=this.nodes.get(t.activeNodeId);e.screenOutputs&&n?.type===`screen`&&Object.assign(t.variables,e.screenOutputs),t.pausedReason=void 0,t.status=`running`,n?.type===`approval`?this.resumeApproval(n,e.decision):n&&this.enqueueSuccessors(n),t.frontier.length===0&&(t.status=`done`,t.activeNodeId=null)}resumeApproval(e,t){let n=this.edges.map((e,t)=>({e,i:t})).filter(t=>t.e.source===e.id),r=(t??``).trim().toLowerCase(),i=r?n.find(e=>(e.e.label??``).trim().toLowerCase()===r):void 0;if(i)this.traverse(i.e,i.i),this.record(e.id,`approval`,e.label,`ok`,{note:`Decision: ${t} → ${i.e.target}`});else{for(let e of n)this.traverse(e.e,e.i);this.record(e.id,`approval`,e.label,`ok`,{note:r?`No out-edge labelled "${t}"; took all branches (engine label-fallback).`:`No decision supplied; took all branches.`})}}execute(e){let t=e.type;if(t===`end`)return this.record(e.id,t,e.label,`ok`,{note:`Flow end reached.`});if(t===`decision`)return this.executeDecision(e);if(t===`assignment`)return this.executeAssignment(e);if(Wf.has(t))return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`skipped`,{note:`"${t}" is not modelled by the simulator; passing through without its real semantics.`});if(t===`parallel_gateway`)return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`ok`,{note:`Parallel split — branches fan out (no join synchronization is simulated).`});if(t===`approval`)return this.state.status=`paused`,this.state.pausedReason=`approval`,this.record(e.id,t,e.label,`paused`,{note:`Approval reached — choose a decision to continue.`});if(t===`wait`)return this.state.status=`paused`,this.state.pausedReason=`wait`,this.record(e.id,t,e.label,`paused`,{note:`Wait reached — continue manually.`});if(t===`screen`){let n=Array.isArray(e.config?.fields)?e.config.fields:[],r=e.config?.waitForInput;return r===!0||n.length>0&&r!==!1?(this.state.status=`paused`,this.state.pausedReason=`screen`,this.record(e.id,t,e.label,`paused`,{note:`Screen reached — provide inputs, then continue.`})):(this.enqueueSuccessors(e),this.record(e.id,t,e.label,`ok`,{note:`Screen has no input — passed through (matches runtime).`}))}if(t===`loop`){let t=this.executeLoop(e);return this.enqueueSuccessors(e),t}if(Uf.has(t)||t===`script`){let n=this.applyMock(e);return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`mocked`,{wrote:n,note:this.mockNote(e)})}return this.enqueueSuccessors(e),this.record(e.id,t,e.label,`ok`,{note:Hf.has(t)?void 0:`Type "${t}" treated as pass-through.`})}executeDecision(e){let t=this.edges.map((e,t)=>({e,i:t})).filter(t=>t.e.source===e.id),n=[],r,i;for(let{e,i:a}of t){if(e.isDefault)continue;let t=Kf(e.condition);if(!t){n.push({edgeId:Gf(e,a),target:e.target,result:!1,selected:!1,error:`Branch has no condition.`});continue}let o=Hd(t,this.state.variables);o.error&&!i&&(i=`${t}: ${o.error}`);let s=o.result&&!r;s&&(r={e,i:a}),n.push({edgeId:Gf(e,a),target:e.target,condition:t,result:o.result,error:o.error,selected:s})}if(!r){let e=t.find(e=>e.e.isDefault);e&&(r=e,n.push({edgeId:Gf(e.e,e.i),target:e.e.target,isDefault:!0,result:!0,selected:!0}))}let a=n.filter(e=>e.result&&!e.isDefault).length>1;return r&&this.traverse(r.e,r.i),this.record(e.id,`decision`,e.label,r?`ok`:`error`,{edges:n,error:r?void 0:i??`No branch matched and there is no default branch.`,note:a?`Multiple conditions matched; the first declared branch was taken.`:void 0})}executeAssignment(e){let t=e.config??{},n=t.assignments,r=[];if(Array.isArray(n)){for(let e of n)if(e&&typeof e==`object`){let t=e,n=t.variable??t.name??t.key;typeof n==`string`&&n&&r.push([n,t.value])}}else if(n&&typeof n==`object`)for(let[e,t]of Object.entries(n))r.push([e,t]);else for(let[e,n]of Object.entries(t))r.push([e,n]);let i={};for(let[e,t]of r){let n=this.interpolateValue(t);this.state.variables[e]=n,i[e]=n}return this.enqueueSuccessors(e),this.record(e.id,`assignment`,e.label,`ok`,{wrote:Object.keys(i).length?i:void 0,note:Object.keys(i).length?void 0:`No assignments defined.`})}interpolateValue(e){if(typeof e!=`string`)return e;let t=e.match(/^\{([^}]+)\}$/);if(t){let n=this.state.variables[t[1].trim()];return n===void 0?e:n}return e.replace(/\{([^}]+)\}/g,(e,t)=>{let n=this.state.variables[String(t).trim()];return n==null?``:String(n)})}executeLoop(e){let t=qf(e.config?.collection),n=qf(e.config?.iteratorVariable),r=`Loop simulated as a single pass (body re-execution is not modelled).`;if(t){let e=this.resolveRef(t);Array.isArray(e)?(r=`Collection "${t}" has ${e.length} item(s); simulated as a single pass.`,n&&e.length&&(this.state.variables[n]=e[0])):e!==void 0&&(r=`Collection "${t}" is not an array; loop may not run at runtime.`)}return this.record(e.id,`loop`,e.label,`ok`,{note:r})}resolveRef(e){let t=e.match(/^\{(.+)\}$/),n=(t?t[1]:e).trim();return this.state.variables[n]}applyMock(e){let t=e.config??{},n=this.mocks[e.id],r={},i=qf(t.outputVariable);i&&(r[i]=n===void 0?{}:n,this.state.variables[i]=r[i]);let a=Array.isArray(t.outputVariables)?t.outputVariables:[];if(a.length){let e=n&&typeof n==`object`?n:{};for(let t of a)typeof t==`string`&&(r[t]=t in e?e[t]:void 0,this.state.variables[t]=r[t])}return Object.keys(r).length?r:void 0}mockNote(e){if(e.type===`script`){let t=qf(e.config?.actionType);if(t&&t!==`code`){let n=Array.isArray(e.config?.recipients)?e.config.recipients.length:0;return`Mocked ${t} notification${n?` to ${n} recipient(s)`:``}.`}return`Mocked code script (no real code executed).`}return`Mocked ${e.type.replace(/_/g,` `)} (no backend call).`}enqueueSuccessors(e){this.edges.forEach((t,n)=>{t.source===e.id&&this.traverse(t,n)})}traverse(e,t){let n=Gf(e,t);this.state.traversedEdgeIds.includes(n)||this.state.traversedEdgeIds.push(n),this.nodes.has(e.target)&&this.state.frontier.push(e.target)}record(e,t,n,r,i={}){let a={seq:this.seq++,nodeId:e,type:t,label:n||e,status:r,...i};return this.state.steps.push(a),r===`error`&&this.state.status!==`paused`&&(this.state.status=`error`,this.state.error=i.error),a}};function Yf(e,t){return e?t?e.replace(/\{([^{}]+)\}/g,(e,n)=>{let r=t[String(n).trim()];return r==null?e:String(r)}):e:``}function Xf(e,t){if(typeof e!=`string`||!e.trim()||!t)return!0;let{result:n,error:r}=Hd(e.replace(/\{([\w.]+)\}/g,`$1`),t);return r?!0:n}function Zf(e,t){if(!Array.isArray(e))return[];let n=[];for(let r of e){if(!r||typeof r!=`object`)continue;let e=r;typeof e.name!=`string`||!e.name||Xf(e.visibleWhen,t)&&n.push({name:e.name,label:typeof e.label==`string`?e.label:void 0,type:typeof e.type==`string`?e.type:void 0,required:e.required===!0})}return n}function Qf(e,t){let n=e.config?.fields;if(!Array.isArray(n))return 0;let r=0;for(let e of n){if(!e||typeof e!=`object`)continue;let n=e;typeof n.name!=`string`||!n.name||Xf(n.visibleWhen,t)||r++}return r}function $f(e,t){let n=e.config&&typeof e.config==`object`?e.config:{},r=typeof n.objectName==`string`&&n.objectName?n.objectName:void 0,i=n.mode===`edit`?`edit`:n.mode===`create`?`create`:void 0,a=n.defaults&&typeof n.defaults==`object`&&!Array.isArray(n.defaults)?n.defaults:void 0;return{nodeId:e.id,title:typeof n.title==`string`?n.title:void 0,description:typeof n.description==`string`?n.description:void 0,fields:Zf(n.fields,t),kind:r?`object-form`:`fields`,objectName:r,mode:i,defaults:a,idVariable:typeof n.idVariable==`string`?n.idVariable:void 0}}function ep({node:e,variables:t,className:n}){let r=p(),i=m(),a=X.useMemo(()=>$f(e,t),[e,t]),o=Zr(a),s=o?i.objects:void 0,c=Yf(a.title,t),l=Yf(a.description,t),u=o?0:Qf(e,t),d=o?`obj:${a.objectName}:${a.mode??`create`}`:`fields:`+a.fields.map(e=>`${e.name}:${e.type??``}:${+!!e.required}`).join(`|`),f=!c&&!l&&!o&&a.fields.length===0&&u===0;return(0,Y.jsxs)(`div`,{className:B(`overflow-hidden rounded-md border bg-background`,n),children:[(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5 border-b bg-muted/30 px-3 py-1.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:`Preview`}),(0,Y.jsx)(`div`,{className:`max-h-[60vh] overflow-auto p-4`,children:f?(0,Y.jsx)(`p`,{className:`text-sm italic text-muted-foreground`,children:`Add a title, description, fields, or an object form to preview this screen.`}):(0,Y.jsxs)(Y.Fragment,{children:[c&&(0,Y.jsx)(`h3`,{className:`text-base font-semibold leading-tight`,children:c}),l&&(0,Y.jsx)(`p`,{className:B(`whitespace-pre-line text-sm text-muted-foreground`,c&&`mt-1`),children:l}),(0,Y.jsx)(tp,{spec:a,adapter:r,objects:s},d),!o&&u>0&&(0,Y.jsxs)(`p`,{className:`mt-3 text-[11px] italic text-muted-foreground`,children:[u,` field`,u===1?``:`s`,` hidden by `,u===1?`its`:`their`,` “visible when”`,` `,`condition`,u===1?``:`s`,`.`]}),!o&&a.fields.length>0&&(0,Y.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,Y.jsx)(H,{size:`sm`,disabled:!0,children:`Submit`})})]})})]})}function tp({spec:e,adapter:t,objects:n}){let[r,i]=X.useState(()=>Xr(e));return(0,Y.jsx)(qr,{screen:e,values:r,onValueChange:(e,t)=>i(n=>({...n,[e]:t})),dataSource:t??void 0,objects:n,objectForm:{showSubmit:!1,showCancel:!1,noDataSourceMessage:`Connect to a backend to preview this object form.`}})}function np(e){let t=e.trim();if(t!==``){if(t===`true`)return!0;if(t===`false`)return!1;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}}var rp=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`,`script`]);function ip(e){let t=[];for(let n of e){if(!rp.has(n.type))continue;let e=n.config??{},r=[];if(typeof e.outputVariable==`string`&&e.outputVariable&&r.push(e.outputVariable),Array.isArray(e.outputVariables))for(let t of e.outputVariables)typeof t==`string`&&r.push(t);t.push({id:n.id,label:n.label||n.id,type:n.type,outputs:r})}return t}var ap={ok:`bg-emerald-100 text-emerald-700`,mocked:`bg-violet-100 text-violet-700`,paused:`bg-amber-100 text-amber-700`,skipped:`bg-zinc-100 text-zinc-600`,error:`bg-rose-100 text-rose-700`};function op({nodes:e,edges:t,variables:n,onRunStateChange:r}){let i=X.useRef(null),[a,o]=X.useState(null),[s,c]=X.useState(null),l=X.useMemo(()=>n.filter(e=>e.isInput),[n]),u=X.useMemo(()=>ip(e),[e]),[d,f]=X.useState({}),[p,m]=X.useState([]),[h,g]=X.useState({}),_=X.useCallback(()=>{let e=i.current;if(!e)return;let t=e.state;o({...t,steps:[...t.steps],variables:{...t.variables},frontier:[...t.frontier],visitedNodeIds:[...t.visitedNodeIds],traversedEdgeIds:[...t.traversedEdgeIds]}),r?.({activeNodeId:t.activeNodeId,visitedNodeIds:[...t.visitedNodeIds],traversedEdgeIds:[...t.traversedEdgeIds]})},[r]),v=X.useCallback(()=>{let e={};for(let t of l){let n=d[t.name],r=n==null?void 0:np(n);e[t.name]=r===void 0?t.defaultValue:r}for(let t of p){let n=t.k.trim();n&&(e[n]=np(t.v))}return e},[l,d,p]),y=X.useCallback(()=>{let e={};for(let[t,n]of Object.entries(h))n!=null&&n.trim()!==``&&(e[t]=np(n));return e},[h]),b=X.useCallback(()=>{let n=new Jf(e,t);i.current=n,c(n.reset(v(),y())),_()},[e,t,v,y,_]),x=X.useCallback(()=>(i.current||b(),i.current),[b]),S=()=>{let e=i.current;if(e&&e.state.status===`paused`){if(e.state.pausedReason===`approval`){_();return}e.resume()}else b(),e=i.current;e.runToEnd(),_()},C=()=>{x().step(),_()},w=()=>T(),T=e=>{let t=x();t.resume(e?{decision:e}:{}),t.runToEnd(),_()},E=()=>{i.current=null,o(null),c(null),r?.(null)},D=a?.status??`idle`,O=(s?.errors.length??0)>0,k=X.useMemo(()=>{if(a?.status!==`paused`||a.pausedReason!==`screen`||!a.activeNodeId)return null;let t=e.find(e=>e.id===a.activeNodeId);return t?{node:t,variables:a.variables}:null},[a,e]),A=X.useMemo(()=>{if(a?.status!==`paused`||a.pausedReason!==`approval`||!a.activeNodeId)return null;let n=e.find(e=>e.id===a.activeNodeId);return n?{node:n,decisions:[...new Set(t.filter(e=>e.source===n.id&&typeof e.label==`string`&&e.label.trim()).map(e=>e.label.trim()))]}:null},[a,e,t]);return(0,Y.jsxs)(`div`,{className:`flex h-full flex-col text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(H,{size:`sm`,className:`h-7 gap-1 px-2`,onClick:S,disabled:O,children:[(0,Y.jsx)(Gt,{className:`h-3.5 w-3.5`}),` Run`]}),(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:C,disabled:O||D===`done`||D===`error`,children:[(0,Y.jsx)(pr,{className:`h-3.5 w-3.5`}),` Step`]}),D===`paused`&&(A&&A.decisions.length>0?(0,Y.jsx)(`div`,{className:`flex items-center gap-1`,children:A.decisions.map(e=>(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2 capitalize`,onClick:()=>T(e),title:`Resume down the "${e}" branch`,children:[(0,Y.jsx)(N,{className:`h-3.5 w-3.5`}),` `,e]},e))}):(0,Y.jsxs)(H,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:w,children:[(0,Y.jsx)(N,{className:`h-3.5 w-3.5`}),` Continue`]})),(0,Y.jsxs)(H,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-muted-foreground`,onClick:E,children:[(0,Y.jsx)(Me,{className:`h-3.5 w-3.5`}),` Reset`]}),(0,Y.jsx)(`span`,{className:B(`ml-auto rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase`,ap[D===`idle`||D===`running`?`ok`:D]??`bg-muted`),children:D})]}),(0,Y.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-auto p-3`,children:[s&&(s.errors.length>0||s.warnings.length>0)&&(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[s.errors.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 rounded border border-rose-200 bg-rose-50 px-2 py-1 text-rose-700`,children:[(0,Y.jsx)(rt,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,Y.jsx)(`span`,{children:e.message})]},`e${t}`)),s.warnings.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 rounded border border-amber-200 bg-amber-50 px-2 py-1 text-amber-700`,children:[(0,Y.jsx)(I,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,Y.jsx)(`span`,{children:e.message})]},`w${t}`))]}),k&&(0,Y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Screen`}),(0,Y.jsx)(ep,{node:k.node,variables:k.variables})]}),l.length>0&&(0,Y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Inputs`}),l.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(z,{className:`w-24 shrink-0 truncate font-mono text-[11px]`,title:e.name,children:e.name}),(0,Y.jsx)(V,{value:d[e.name]??(e.defaultValue==null?``:String(e.defaultValue)),onChange:t=>f(n=>({...n,[e.name]:t.target.value})),placeholder:e.type??`value`,className:`h-7 flex-1 text-xs`})]},e.name))]}),(0,Y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,Y.jsx)(`span`,{children:`Set variables`}),(0,Y.jsxs)(`button`,{type:`button`,className:`ml-auto inline-flex items-center gap-0.5 rounded border px-1.5 py-0.5 text-[10px] hover:bg-muted/50`,onClick:()=>m(e=>[...e,{k:``,v:``}]),children:[(0,Y.jsx)(L,{className:`h-3 w-3`}),` Add`]})]}),p.length===0?(0,Y.jsx)(`div`,{className:`italic text-muted-foreground`,children:`Override or inject any variable (wins over inputs and mocks at start).`}):p.map((e,t)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(V,{value:e.k,onChange:e=>m(n=>n.map((n,r)=>r===t?{...n,k:e.target.value}:n)),placeholder:`name`,className:`h-7 w-24 shrink-0 font-mono text-[11px]`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`=`}),(0,Y.jsx)(V,{value:e.v,onChange:e=>m(n=>n.map((n,r)=>r===t?{...n,v:e.target.value}:n)),placeholder:`value`,className:`h-7 flex-1 text-xs`}),(0,Y.jsx)(`button`,{type:`button`,className:`shrink-0 rounded p-1 text-muted-foreground hover:bg-muted/50 hover:text-rose-600`,onClick:()=>m(e=>e.filter((e,n)=>n!==t)),"aria-label":`Remove variable`,children:(0,Y.jsx)(sr,{className:`h-3 w-3`})})]},t))]}),u.length>0&&(0,Y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Mock outputs`}),u.map(e=>(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsxs)(z,{className:`flex items-baseline gap-1.5 text-[11px]`,title:e.id,children:[(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-muted-foreground`,children:e.type.replace(/_/g,` `)}),e.outputs.length>0&&(0,Y.jsxs)(`span`,{className:`truncate font-mono text-[10px] text-violet-600`,children:[`→ `,e.outputs.join(`, `)]})]}),(0,Y.jsx)(V,{value:h[e.id]??``,onChange:t=>g(n=>({...n,[e.id]:t.target.value})),placeholder:e.type===`script`&&e.outputs.length?`{ "${e.outputs[0]}": … }`:`mocked result (JSON)`,className:`h-7 w-full font-mono text-[11px]`})]},e.id))]}),a&&(0,Y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Variables`}),Object.keys(a.variables).length===0?(0,Y.jsx)(`div`,{className:`italic text-muted-foreground`,children:`No variables set.`}):(0,Y.jsx)(`ul`,{className:`space-y-1`,children:Object.entries(a.variables).map(([e,t])=>(0,Y.jsxs)(`li`,{className:`flex items-baseline gap-1.5 rounded border bg-background px-1.5 py-1`,children:[(0,Y.jsx)(`span`,{className:`font-mono text-[11px]`,children:e}),(0,Y.jsxs)(`span`,{className:`truncate font-mono text-[10px] text-muted-foreground`,children:[`= `,typeof t==`object`?JSON.stringify(t):String(t)]})]},e))})]}),a&&a.steps.length>0&&(0,Y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:`Timeline`}),(0,Y.jsx)(`ol`,{className:`space-y-1`,children:a.steps.map(e=>(0,Y.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.seq+1}),(0,Y.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,Y.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type}),(0,Y.jsx)(`span`,{className:B(`ml-auto rounded px-1 py-0.5 text-[9px] font-semibold uppercase`,ap[e.status]),children:e.status})]}),e.note&&(0,Y.jsx)(`div`,{className:`mt-0.5 text-[10px] text-muted-foreground`,children:e.note}),e.error&&(0,Y.jsx)(`div`,{className:`mt-0.5 text-[10px] text-rose-600`,children:e.error}),e.wrote&&(0,Y.jsxs)(`div`,{className:`mt-0.5 truncate font-mono text-[10px] text-violet-600`,children:[`→ `,Object.keys(e.wrote).join(`, `)]}),e.edges&&e.edges.length>0&&(0,Y.jsx)(`ul`,{className:`mt-0.5 space-y-0.5`,children:e.edges.map(e=>(0,Y.jsxs)(`li`,{className:`space-y-0.5`,children:[(0,Y.jsxs)(`div`,{className:B(`flex items-center gap-1 font-mono text-[10px]`,e.selected?`text-sky-700`:`text-muted-foreground`),children:[(0,Y.jsx)(`span`,{children:e.selected?`▶`:`·`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e.isDefault?`else`:e.condition}),(0,Y.jsx)(`span`,{className:B(`ml-auto`,e.error&&`text-rose-600`),children:e.error?`error`:e.result?`true`:`false`})]}),e.error&&(0,Y.jsx)(`div`,{className:`pl-3 text-[10px] text-rose-600`,children:e.error})]},e.edgeId))})]},e.seq))})]}),!a&&!O&&(0,Y.jsx)(`p`,{className:`italic text-muted-foreground`,children:`Press Run to simulate, or Step to walk node by node. Side effects are mocked — no backend is called.`})]})]})}function sp(e){if(!e)return;if(typeof e==`string`)return e||void 0;let t=e.message;return typeof t==`string`&&t?t:void 0}async function cp(e,t){try{let n=await fetch(`${Id()}/automation/${encodeURIComponent(e)}/runs?limit=25`,{credentials:`include`,headers:{"Content-Type":`application/json`},signal:t});if(!n.ok)return null;let r=await n.json(),i=r?.data?.runs??r?.runs;return Array.isArray(i)?i:null}catch{return null}}var lp={completed:{icon:In,cls:`text-emerald-600 dark:text-emerald-400`,label:`Completed`},failed:{icon:rt,cls:`text-rose-600 dark:text-rose-400`,label:`Failed`},paused:{icon:zn,cls:`text-amber-600 dark:text-amber-400`,label:`Paused`},running:{icon:U,cls:`text-sky-600 dark:text-sky-400`,label:`Running`},cancelled:{icon:wr,cls:`text-muted-foreground`,label:`Cancelled`}};function up(e){return lp[e]??{icon:wn,cls:`text-muted-foreground`,label:e}}function dp(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function fp(e){return e==null?null:e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/6e4)}m`}function pp({step:e}){let t=e.status===`success`?`text-emerald-600 dark:text-emerald-400`:e.status===`failure`?`text-rose-600 dark:text-rose-400`:`text-muted-foreground`,n=sp(e.error);return(0,Y.jsxs)(`li`,{className:`flex items-baseline gap-1.5 py-0.5`,children:[(0,Y.jsx)(`span`,{className:B(`shrink-0 text-[9px] font-semibold uppercase`,t),children:e.status}),(0,Y.jsx)(`span`,{className:`truncate font-mono text-[10px]`,title:e.nodeId,children:e.nodeId}),e.nodeType&&(0,Y.jsx)(`span`,{className:`shrink-0 text-[9px] uppercase text-muted-foreground`,children:e.nodeType}),fp(e.durationMs)&&(0,Y.jsx)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground`,children:fp(e.durationMs)}),n&&(0,Y.jsx)(`span`,{className:`min-w-0 truncate text-[9px] text-rose-600`,title:n,children:n})]})}function mp({run:e}){let[t,n]=X.useState(!1),r=up(e.status),i=r.icon,a=Array.isArray(e.steps)?e.steps:[],o=sp(e.error);return(0,Y.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`flex w-full items-center gap-1.5 p-1.5 text-left`,"aria-expanded":t,children:[t?(0,Y.jsx)(ke,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,Y.jsx)(N,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,Y.jsx)(i,{className:B(`h-3.5 w-3.5 shrink-0`,r.cls,e.status===`running`&&`animate-spin`)}),(0,Y.jsx)(`span`,{className:B(`shrink-0 text-[10px] font-semibold`,r.cls),children:r.label}),(0,Y.jsx)(`span`,{className:`min-w-0 truncate text-[10px] text-muted-foreground`,title:e.id,children:dp(e.startedAt)}),fp(e.durationMs)&&(0,Y.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] text-muted-foreground`,children:fp(e.durationMs)})]}),t&&(0,Y.jsxs)(`div`,{className:`border-t px-2 py-1.5`,children:[(0,Y.jsxs)(`div`,{className:`pb-1 font-mono text-[9px] text-muted-foreground`,title:e.id,children:[`run `,e.id,e.trigger?.type&&` · trigger ${e.trigger.type}`]}),o&&(0,Y.jsx)(`div`,{className:`pb-1 text-[10px] text-rose-600`,children:o}),a.length===0?(0,Y.jsx)(`div`,{className:`text-[10px] italic text-muted-foreground`,children:`No step log recorded.`}):(0,Y.jsx)(`ul`,{className:`divide-y divide-border/50`,children:a.map((e,t)=>(0,Y.jsx)(pp,{step:e},`${e.nodeId}#${t}`))})]})]})}function hp({flowName:e}){let[t,n]=X.useState([]),[r,i]=X.useState(`loading`),[a,o]=X.useState(0);return X.useEffect(()=>{let t=new AbortController,r=!0;return i(`loading`),(async()=>{let a=await cp(e,t.signal);r&&(a===null?i(`unavailable`):(n(a),i(`ready`)))})(),()=>{r=!1,t.abort()}},[e,a]),(0,Y.jsxs)(`div`,{className:`flex h-full flex-col p-3 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-2 font-medium text-muted-foreground`,children:[(0,Y.jsx)(wn,{className:`h-3 w-3`}),` Runs`,(0,Y.jsx)(`button`,{type:`button`,onClick:()=>o(e=>e+1),title:`Refresh run history`,"aria-label":`Refresh run history`,className:`ml-auto rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground`,children:(0,Y.jsx)(Dt,{className:B(`h-3 w-3`,r===`loading`&&`animate-spin`)})})]}),r===`unavailable`?(0,Y.jsx)(`div`,{className:`italic text-muted-foreground`,children:`Run history unavailable — the automation engine is offline or this flow hasn’t been published.`}):r===`ready`&&t.length===0?(0,Y.jsx)(`div`,{className:`italic text-muted-foreground`,children:`No runs yet.`}):(0,Y.jsx)(`ul`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto`,children:t.map(e=>(0,Y.jsx)(mp,{run:e},e.id))})]})}function gp(e){return e.target.kind===`node`?e.target.nodeId:e.target.kind===`edge`?`${e.target.source} → ${e.target.target}`:`flow`}function _p({problems:e,selectedKey:t,onSelectProblem:n}){let r=e.filter(e=>e.level===`error`).length,i=e.length-r;return(0,Y.jsxs)(`div`,{className:`flex h-full flex-col text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2 font-medium text-muted-foreground`,children:[(0,Y.jsx)(`span`,{children:`Problems`}),r>0&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,Y.jsx)(rt,{className:`h-3 w-3`}),` `,r]}),i>0&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,Y.jsx)(I,{className:`h-3 w-3`}),` `,i]})]}),e.length===0?(0,Y.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-1.5 p-4 text-center text-muted-foreground`,children:[(0,Y.jsx)(In,{className:`h-5 w-5 text-emerald-500`}),(0,Y.jsx)(`span`,{children:`No problems — this flow is structurally valid.`})]}):(0,Y.jsx)(`ul`,{className:`flex-1 overflow-auto p-1.5`,children:e.map(e=>{let r=e.target.kind===`edge`,i=e.target.kind===`flow`,a=e.target.kind===`node`?`node:${e.target.nodeId}`:e.target.kind===`edge`?e.target.edgeKey:null,o=!!a&&a===t,s=e.level===`error`?rt:I,c=r?Fr:M;return(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(`button`,{type:`button`,disabled:i,onClick:()=>n(e),className:B(`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors`,i?`cursor-default`:`cursor-pointer hover:bg-accent`,o&&`bg-accent ring-1 ring-primary/40`),children:[(0,Y.jsx)(s,{className:B(`mt-0.5 h-3.5 w-3.5 shrink-0`,e.level===`error`?`text-destructive`:`text-amber-500`)}),(0,Y.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`span`,{className:`block leading-snug text-foreground`,children:e.message}),(0,Y.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(c,{className:`h-2.5 w-2.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate font-mono`,children:gp(e)}),e.source===`server`&&(0,Y.jsx)(`span`,{className:`uppercase tracking-wide`,children:`· schema`}),e.source===`expression`&&(0,Y.jsx)(`span`,{className:`uppercase tracking-wide`,children:`· expression`})]})]})]})},e.id)})})]})}function vp({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a,diagnostics:o}){let s=e,c=X.useMemo(()=>Array.isArray(s.nodes)?s.nodes:[],[s.nodes]),l=X.useMemo(()=>Array.isArray(s.edges)?s.edges:[],[s.edges]),u=Array.isArray(s.variables)?s.variables:[],d=!!(t&&r),f=d&&!!i,p=n&&n.kind===`node`?n.id:null,m=n&&n.kind===`edge`?n.id:null,[h,g]=X.useState(!1),[_,v]=X.useState(!1),[y,b]=X.useState(!1),[x,S]=X.useState(!1),[C,w]=X.useState(null),T=X.useMemo(()=>Mf({nodes:c,edges:l,serverDiagnostics:o,variables:u}),[c,l,o,s.variables]),E=T.filter(e=>e.level===`error`).length,{invalidNodeIds:D,invalidEdges:O}=X.useMemo(()=>Ff(T),[T]),[k,A]=X.useState(null),j=p?`node:${p}`:m??null,ee=X.useCallback(e=>{if(e.target.kind===`node`){let{nodeId:t}=e.target,n=c.find(e=>e.id===t);r?.({kind:`node`,id:t,label:n?.label||t})}else e.target.kind===`edge`&&r?.({kind:`edge`,id:e.target.edgeKey,label:`${e.target.source} → ${e.target.target}`});A(t=>({target:e.target,nonce:(t?.nonce??0)+1}))},[c,r]),te=X.useCallback(()=>{if(!f)return;let e={id:ui(`node`,c.map(e=>e.id).filter(Boolean)),type:`start`,label:`Start`};i({nodes:mi(c,e)}),r?.({kind:`node`,id:e.id,label:e.label||e.id})},[f,c,i,r]),ne=typeof s.name==`string`&&s.name?s.name:``,re=String(s.type??`autolaunched`),ie=String(s.status??(s.active?`active`:`draft`)),ae=String(s.runAs??`user`),oe=s.version==null?void 0:String(s.version),N=s.errorHandling?.strategy;return c.length===0?(0,Y.jsx)(Z,{hint:`flow${d?` · design`:``}`,children:f?(0,Y.jsx)(`div`,{className:`p-3`,children:(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-2 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,onClick:te,children:[(0,Y.jsx)(L,{className:`h-3 w-3`}),J(`engine.inspector.add.node`,a)]})}):(0,Y.jsx)(gl,{children:`Add nodes in the Form tab to see the flow preview.`})}):(0,Y.jsx)(Z,{hint:`flow · ${c.length} node${c.length===1?``:`s`}`,children:(0,Y.jsx)(Q,{fallbackHint:`One of the flow nodes or edges is malformed.`,children:(0,Y.jsxs)(`div`,{className:`grid gap-0 h-full min-h-[440px] `+(h||_||y||x?`lg:grid-cols-[1fr_240px]`:`grid-cols-1`),children:[(0,Y.jsxs)(`div`,{className:`flex flex-col min-w-0 min-h-0`,children:[(0,Y.jsxs)(`div`,{className:`rounded-none border-b bg-muted/30 px-3 py-2 text-xs flex flex-wrap items-center gap-x-4 gap-y-1`,children:[(0,Y.jsx)(yp,{icon:me,label:`Trigger`,value:re}),(0,Y.jsx)(yp,{icon:M,label:`Status`,value:ie,tone:ie===`active`?`green`:ie===`draft`?`gray`:`amber`}),(0,Y.jsx)(yp,{icon:ve,label:`Run as`,value:ae}),oe&&(0,Y.jsx)(yp,{label:`v`,value:oe}),N&&(0,Y.jsx)(yp,{icon:Fr,label:`On error`,value:N}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[!h&&!y&&!x&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>v(e=>!e),className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(_?`border-violet-500 bg-violet-50 text-violet-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),title:_?`Hide variables panel`:`Show variables panel`,children:[(0,Y.jsx)(dr,{className:`h-3 w-3`}),` Variables`]}),ne&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{b(e=>!e),g(!1),S(!1)},className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(y?`border-emerald-500 bg-emerald-50 text-emerald-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),title:`Run history from the automation engine`,children:[(0,Y.jsx)(pn,{className:`h-3 w-3`}),` Runs`]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{S(e=>!e),g(!1),b(!1)},className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(x?`border-rose-500 bg-rose-50 text-rose-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),title:`Validation problems`,children:[(0,Y.jsx)(rt,{className:`h-3 w-3`}),` Problems`,T.length>0&&(0,Y.jsx)(`span`,{className:`ml-0.5 inline-flex min-w-[16px] items-center justify-center rounded-full px-1 text-[10px] font-semibold `+(E>0?`bg-destructive/15 text-destructive`:`bg-amber-500/15 text-amber-600`),children:T.length})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{g(e=>!e),b(!1),S(!1)},className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(h?`border-sky-500 bg-sky-50 text-sky-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),children:[(0,Y.jsx)(Kn,{className:`h-3 w-3`}),` Debug`]})]})]}),(0,Y.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,Y.jsx)(zf,{nodes:c,edges:l,editable:f,designMode:d,selectedId:p,selectedEdgeId:m,locale:a,activeNodeId:C?.activeNodeId??null,visitedNodeIds:C?.visitedNodeIds,traversedEdgeIds:C?.traversedEdgeIds,invalidNodeIds:D,invalidEdges:O,onRevealProblem:ee,problems:T,revealSignal:k,onSelect:e=>e?r?.({kind:`node`,id:e.id,label:e.label||e.id}):r?.(null),onSelectEdge:(e,t)=>e?r?.({kind:`edge`,id:t,label:`${e.source} → ${e.target}`}):r?.(null),onPatch:i})})]}),x?(0,Y.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,Y.jsx)(_p,{problems:T,selectedKey:j,onSelectProblem:ee})}):h?(0,Y.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,Y.jsx)(op,{nodes:c,edges:l,variables:u,onRunStateChange:w})}):y&&ne?(0,Y.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,Y.jsx)(hp,{flowName:ne})}):_?(0,Y.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,Y.jsx)(we,{className:`h-3 w-3`}),` Variables`]}),u.length===0?(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No variables declared.`}):(0,Y.jsx)(`ul`,{className:`space-y-1.5`,children:u.map((e,t)=>(0,Y.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e.name}),e.type&&(0,Y.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type}),e.isInput&&(0,Y.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-sky-100 text-sky-700`,children:`in`}),e.isOutput&&(0,Y.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-emerald-100 text-emerald-700`,children:`out`})]}),e.defaultValue!==void 0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[`= `,String(e.defaultValue)]})]},e.name||t))})]}):null]})})})}function yp({icon:e,label:t,value:n,tone:r=`gray`}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[t,`:`]}),(0,Y.jsx)(`span`,{className:`font-medium ${r===`green`?`text-emerald-700`:r===`amber`?`text-amber-700`:`text-foreground`}`,children:n})]})}function bp({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=String(n.role??``),o=n.avatar||void 0,s=String(n.instructions??``),c=n.active!==!1,l=String(n.visibility??`organization`),u=n.model??{},d=Array.isArray(n.skills)?n.skills:[],f=Array.isArray(n.tools)?n.tools:[],p=n.knowledge,m=n.planning,h=n.memory,g=n.guardrails,_=Array.isArray(n.permissions)?n.permissions:[];if(!r&&!s&&d.length===0&&f.length===0)return(0,Y.jsx)(Z,{hint:`agent`,children:(0,Y.jsx)(gl,{children:`Fill in label, role, and instructions in the Form tab to see the agent preview.`})});let v=r?`/console/ai/agents/${encodeURIComponent(r)}/chat`:null;return(0,Y.jsx)(Z,{hint:`agent`,toolbar:v&&(0,Y.jsxs)(`a`,{href:v,target:`_blank`,rel:`noreferrer`,className:`text-xs inline-flex items-center gap-1 text-muted-foreground hover:text-foreground`,title:`Open the saved version of this agent in a new chat`,children:[`Try in chat `,(0,Y.jsx)(Re,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_240px] gap-0`,children:[(0,Y.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 flex items-start gap-3`,children:[(0,Y.jsx)(`div`,{className:`h-10 w-10 rounded-full bg-background border flex items-center justify-center shrink-0 overflow-hidden`,children:o?(0,Y.jsx)(`img`,{src:o,alt:``,className:`h-full w-full object-cover`}):(0,Y.jsx)(cn,{className:`h-5 w-5 text-muted-foreground`})}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(kp,{icon:c?He:or,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),(0,Y.jsx)(kp,{icon:lt,label:l}),u.provider&&(0,Y.jsx)(kp,{icon:En,label:`${u.provider}${u.model?` · ${u.model}`:``}`,mono:!0}),u.temperature!=null&&(0,Y.jsx)(kp,{icon:ht,label:`temp ${u.temperature}`}),u.maxTokens!=null&&(0,Y.jsx)(kp,{label:`max ${u.maxTokens}t`})]})]})]}),(0,Y.jsx)(Sp,{title:`Instructions`,icon:Ln,children:s?(0,Y.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs whitespace-pre-wrap font-mono max-h-[40vh] overflow-auto`,children:s}):(0,Y.jsx)(Cp,{children:`No system prompt set yet.`})}),(0,Y.jsx)(Sp,{title:`Capabilities`,icon:Rn,children:(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(Tp,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:d.map(e=>({key:e,label:e})),icon:En,tone:`violet`,mono:!0}),(0,Y.jsx)(Tp,{label:`Tools`,emptyHint:`No direct tools (skills can provide them)`,items:f.map((e,t)=>({key:`${e.type??``}:${e.name??t}`,label:e.name??String(e),hint:e.type})),icon:Rn,tone:`blue`,mono:!0})]})}),p&&Object.keys(p).length>0&&(0,Y.jsx)(Sp,{title:`Knowledge (RAG)`,icon:Yn,children:(0,Y.jsx)(xp,{knowledge:p})})]}),(0,Y.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-3`,children:[m&&Object.keys(m).length>0&&(0,Y.jsx)(Ep,{icon:kn,title:`Planning`,children:(0,Y.jsx)(Dp,{data:m,keys:[`strategy`,`maxIterations`,`allowReplan`]})}),h&&Object.keys(h).length>0&&(0,Y.jsx)(Ep,{icon:Ye,title:`Memory`,children:(0,Y.jsx)(Dp,{data:{"short.maxMessages":h.shortTerm?.maxMessages,"long.enabled":h.longTerm?.enabled,"long.store":h.longTerm?.store},keys:[`short.maxMessages`,`long.enabled`,`long.store`]})}),g&&Object.keys(g).length>0&&(0,Y.jsx)(Ep,{icon:rn,title:`Guardrails`,children:(0,Y.jsx)(Dp,{data:g,keys:Object.keys(g).slice(0,6)})}),_.length>0&&(0,Y.jsx)(Ep,{icon:lt,title:`Permissions`,children:(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:_.map(e=>(0,Y.jsx)(`li`,{className:`font-mono`,children:e},e))})}),!m&&!h&&!g&&_.length===0&&(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Defaults in use.`})]})]})})})}function xp({knowledge:e}){let t=Array.isArray(e.sources)?e.sources:[],n=Array.isArray(e.indexes)?e.indexes:[],r=[...t,...n];if(r.length===0){let t=Object.keys(e);return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.length?t.join(`, `):`configured`})}return(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:r.map((e,t)=>{let n=e??{},r=n.id??n.name??`source ${t+1}`,i=n.type??n.kind??``;return(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Y.jsx)(Yn,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:String(r)}),i&&(0,Y.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:i})]},t)})})}function Sp({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function Cp({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}var wp={violet:{chip:`border-violet-200 bg-violet-50 text-violet-700 dark:border-violet-900 dark:bg-violet-950/40 dark:text-violet-300`,icon:`text-violet-500 dark:text-violet-400`},blue:{chip:`border-blue-200 bg-blue-50 text-blue-700 dark:border-blue-900 dark:bg-blue-950/40 dark:text-blue-300`,icon:`text-blue-500 dark:text-blue-400`}};function Tp({label:e,emptyHint:t,items:n,icon:r,tone:i,mono:a=!1}){let o=i?wp[i]:null;return(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:e}),n.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:t}):(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,Y.jsxs)(`span`,{className:B(`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px]`,o?o.chip:`bg-background`,a&&`font-mono`),children:[r&&(0,Y.jsx)(r,{className:B(`h-3 w-3 shrink-0`,o?.icon)}),e.label,e.hint&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase opacity-70`,children:e.hint})]},e.key))})]})}function Ep({icon:e,title:t,children:n}){return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:[(0,Y.jsx)(e,{className:`h-3 w-3`}),` `,t]}),n]})}function Dp({data:e,keys:t}){let n=t.map(t=>[t,Op(e,t)]).filter(([,e])=>e!=null);return n.length===0?(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`—`}):(0,Y.jsx)(`dl`,{className:`space-y-0.5`,children:n.map(([e,t])=>(0,Y.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,Y.jsx)(`dt`,{className:`text-muted-foreground font-mono truncate`,children:e}),(0,Y.jsx)(`dd`,{className:`font-mono text-right truncate`,children:String(t)})]},e))})}function Op(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function kp({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function Ap(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function jp(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${jp(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function Mp(e){if(e.default!==void 0)return e.default;if(Array.isArray(e.enum)&&e.enum.length)return e.enum[0];switch(Array.isArray(e.type)?e.type[0]:e.type){case`string`:return e.format?`<${e.format}>`:`<string>`;case`number`:case`integer`:return 0;case`boolean`:return!1;case`array`:return[];case`object`:return{};default:return null}}function Np({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=String(n.description??``),o=n.category||void 0,s=n.objectName||void 0,c=!!n.requiresConfirmation,l=n.active!==!1,u=!!n.builtIn,d=n.parameters??{},f=n.outputSchema??void 0,p=Ap(d)?d.properties??{}:{},m=new Set(Array.isArray(d.required)?d.required:[]),h=X.useMemo(()=>{let e={};for(let t of m)p[t]&&(e[t]=Mp(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=Mp(p[t]))}return e},[p,m]);return!r&&!a&&Object.keys(p).length===0?(0,Y.jsx)(Z,{hint:`tool`,children:(0,Y.jsx)(gl,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,Y.jsx)(Z,{hint:`tool`,toolbar:r&&(0,Y.jsxs)(`a`,{href:`/developer/api-console?path=/api/v1/ai/tools/${encodeURIComponent(r)}/invoke`,target:`_blank`,rel:`noreferrer`,className:`text-xs inline-flex items-center gap-1 text-muted-foreground hover:text-foreground`,title:`Open API Console to test invocation`,children:[`Open in API Console `,(0,Y.jsx)(Re,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Rn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[o&&(0,Y.jsx)(Lp,{icon:qn,label:o}),s&&(0,Y.jsx)(Lp,{icon:Yn,label:s,mono:!0}),(0,Y.jsx)(Lp,{icon:ir,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,Y.jsx)(Lp,{icon:I,label:`Requires confirmation`,tone:`amber`}),u&&(0,Y.jsx)(Lp,{label:`built-in`})]})]})]}),a&&(0,Y.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,Y.jsx)(Fp,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,Y.jsx)(Ip,{children:`This tool takes no input parameters.`}):(0,Y.jsx)(Pp,{props:p,required:m})}),Object.keys(p).length>0&&(0,Y.jsx)(Fp,{title:`Example LLM Call`,icon:Ft,children:(0,Y.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono overflow-auto max-h-[200px]`,children:`{
18
+ "tool": "${r}",
19
+ "arguments": ${JSON.stringify(h,null,2).replace(/\n/g,`
20
+ `)}
21
+ }`})}),Ap(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,Y.jsx)(Fp,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:fr,children:(0,Y.jsx)(Pp,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function Pp({props:e,required:t}){let n=Object.keys(e);return(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`bg-muted/30 text-left text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Name`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Type`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Description`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:n.map(n=>{let r=e[n],i=t.has(n);return(0,Y.jsxs)(`tr`,{className:`align-top`,children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i?(0,Y.jsx)(In,{className:`h-3 w-3 text-emerald-600`}):(0,Y.jsx)(N,{className:`h-3 w-3 text-muted-foreground`}),n,i&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700 ml-1`,children:`req`})]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono text-muted-foreground`,children:jp(r)}),(0,Y.jsxs)(`td`,{className:`px-2.5 py-1.5`,children:[r.description&&(0,Y.jsx)(`div`,{children:r.description}),Array.isArray(r.enum)&&r.enum.length>0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`enum: `,r.enum.map(e=>JSON.stringify(e)).join(` | `)]}),r.default!==void 0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`default: `,(0,Y.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(r.default)})]}),r.format&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`format: `,r.format]})]})]},n)})})]})})}function Fp({title:e,count:t,icon:n,children:r}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,Y.jsx)(n,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function Ip({children:e}){return(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function Lp({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Rp=[{key:`allowCreate`,short:`C`,long:`Create`},{key:`allowRead`,short:`R`,long:`Read`},{key:`allowEdit`,short:`U`,long:`Edit`},{key:`allowDelete`,short:`D`,long:`Delete`},{key:`allowTransfer`,short:`T`,long:`Transfer`},{key:`allowRestore`,short:`Re`,long:`Restore`},{key:`allowPurge`,short:`P`,long:`Purge`,danger:!0},{key:`viewAllRecords`,short:`V*`,long:`View All`,danger:!0},{key:`modifyAllRecords`,short:`M*`,long:`Modify All`,danger:!0}];function zp(e){let t=[];for(let[n,r]of Object.entries(e))r.allowEdit&&!r.allowRead&&t.push({object:n,message:`Edit granted without Read (record updates will fail).`}),r.allowDelete&&!r.allowRead&&t.push({object:n,message:`Delete granted without Read.`}),r.modifyAllRecords&&!r.viewAllRecords&&t.push({object:n,message:`Modify All without View All — modifications may target invisible records.`}),r.allowPurge&&!r.allowDelete&&t.push({object:n,message:`Purge (hard delete) granted without Delete.`});return t}function Bp({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=!!n.isProfile,o=n.objects??{},s=n.fields??{},c=Array.isArray(n.systemPermissions)?n.systemPermissions:[],l=n.tabPermissions??{},u=Array.isArray(n.rowLevelSecurity)?n.rowLevelSecurity:[],d=X.useMemo(()=>Object.keys(o).sort(),[o]),f=X.useMemo(()=>zp(o),[o]),p=X.useMemo(()=>{let e=new Map;for(let[t,n]of Object.entries(s)){let[r,...i]=t.split(`.`);if(!r||i.length===0)continue;let a=i.join(`.`);(n.readable===!1||n.editable===!0)&&(e.has(r)||e.set(r,[]),e.get(r).push({field:a,perm:n}))}return e},[s]);return d.length===0&&c.length===0&&Object.keys(l).length===0?(0,Y.jsx)(Z,{hint:`permission`,children:(0,Y.jsx)(gl,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,Y.jsx)(Z,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[a?(0,Y.jsx)(ln,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,Y.jsx)(mt,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,Y.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:a?`Profile`:`Permission Set`})]}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(Wp,{icon:Wt,label:`${d.length} objects`}),(0,Y.jsx)(Wp,{icon:qn,label:`${c.length} system perms`}),(0,Y.jsx)(Wp,{icon:He,label:`${Object.keys(l).length} tabs`}),(0,Y.jsx)(Wp,{icon:lt,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,Y.jsxs)(Up,{title:`Object Permissions`,count:d.length,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{children:(0,Y.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium sticky left-0 bg-muted/30`,children:`Object`}),Rp.map(e=>(0,Y.jsx)(`th`,{className:`px-1.5 py-1.5 text-center font-medium`,title:e.long,children:e.short},e.key))]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:d.map(e=>{let t=o[e]??{};return(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1 font-mono sticky left-0 bg-background`,children:e}),Rp.map(e=>(0,Y.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,Y.jsx)(Vp,{granted:!!t[e.key],danger:e.danger})},e.key))]},e)})})]})}),(0,Y.jsx)(Hp,{})]}),p.size>0&&(0,Y.jsx)(Up,{title:`Field-Level Overrides`,count:Array.from(p.values()).reduce((e,t)=>e+t.length,0),children:(0,Y.jsx)(`div`,{className:`rounded border bg-background divide-y text-xs`,children:Array.from(p.entries()).sort().map(([e,t])=>(0,Y.jsxs)(`div`,{className:`px-2.5 py-2`,children:[(0,Y.jsx)(`div`,{className:`font-mono text-[11px] mb-1`,children:e}),(0,Y.jsx)(`ul`,{className:`flex flex-wrap gap-1`,children:t.map(({field:e,perm:t})=>(0,Y.jsxs)(`li`,{className:`inline-flex items-center gap-1 rounded border bg-muted/30 px-1.5 py-0.5`,title:`readable=${t.readable!==!1}, editable=${!!t.editable}`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),t.readable===!1&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-red-700`,children:`hidden`}),t.editable&&(0,Y.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700`,children:`editable`})]},e))})]},e))})}),c.length>0&&(0,Y.jsx)(Up,{title:`System Permissions`,count:c.length,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),Object.keys(l).length>0&&(0,Y.jsx)(Up,{title:`Tab Visibility`,count:Object.keys(l).length,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.entries(l).map(([e,t])=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),(0,Y.jsx)(`span`,{className:t===`hidden`?`text-[9px] uppercase text-red-700`:t===`visible`||t===`default_on`?`text-[9px] uppercase text-emerald-700`:`text-[9px] uppercase text-muted-foreground`,children:t})]},e))})}),f.length>0&&(0,Y.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-800`,children:[(0,Y.jsx)(I,{className:`h-3.5 w-3.5`}),` `,f.length,` sanity check`,f.length===1?``:`s`,` failed`]}),(0,Y.jsx)(`ul`,{className:`space-y-0.5`,children:f.map((e,t)=>(0,Y.jsxs)(`li`,{className:`text-amber-900`,children:[(0,Y.jsx)(`code`,{className:`font-mono`,children:e.object}),`: `,e.message]},t))})]})]})})})}function Vp({granted:e,danger:t}){return e?(0,Y.jsx)(In,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,Y.jsx)(Ir,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function Hp(){return(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(In,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(In,{className:`h-3 w-3 text-amber-600`}),` bypass (View/Modify All, Purge)`]}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(Ir,{className:`h-3 w-3 text-muted-foreground/40`}),` not granted`]}),(0,Y.jsx)(`span`,{className:`ml-auto font-mono`,children:`C R U D = CRUD · T Re P = Transfer/Restore/Purge · V* M* = View/Modify All`})]})}function Up({title:e,count:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function Wp({icon:e,label:t}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{children:t})]})}function Gp(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`object`){let t=e;return t.en??t[`en-US`]??Object.values(t)[0]??``}return String(e)}function Kp(e){switch(e){case`url`:return Be;case`modal`:return Vt;case`flow`:return ne;case`api`:return Tr;case`form`:return Gn;default:return mn}}function qp(e){switch(e){case`primary`:case`default`:case void 0:return`bg-primary text-primary-foreground hover:opacity-90`;case`danger`:case`destructive`:return`bg-red-600 text-white hover:bg-red-700`;case`secondary`:return`bg-secondary text-secondary-foreground hover:opacity-90`;case`ghost`:return`bg-transparent text-foreground hover:bg-accent`;case`link`:return`bg-transparent text-primary underline-offset-2 hover:underline px-0`;default:return`border bg-background text-foreground hover:bg-accent`}}function Jp(e,t,n){if(!t&&!n)return`No handler bound yet.`;switch(e){case`url`:return`Navigate to ${t}`;case`flow`:return`Run flow ${t}`;case`modal`:return`Open modal ${t}`;case`api`:return`Call API endpoint ${t}`;case`form`:return`Open form view ${t} (/console/forms/${t??`?`})`;case`script`:return n?`Run inline script body (L1 expression or L2 sandboxed JS).`:`Run named script ${t}`;default:return`Invoke ${t}`}}function Yp({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=Gp(n.label)||r,a=n.icon||void 0,o=String(n.type??`script`),s=n.target??n.execute,c=n.variant||void 0,l=String(n.component??``),u=Array.isArray(n.locations)?n.locations:[],d=n.shortcut||void 0,f=!!n.bulkEnabled,p=!!n.refreshAfter,m=n.aiExposed,h=Gp(n.confirmText),g=Gp(n.successMessage),_=Array.isArray(n.params)?n.params:[],v=n.resultDialog,y=n.body,b=n.objectName||void 0,x=n.visible,S=n.disabled,C=n.method||`POST`,w=n.bodyExtra,T=Kp(o),E=l===`action:icon`;return!r&&!i?(0,Y.jsx)(Z,{hint:`action`,children:(0,Y.jsx)(gl,{children:`Set name and label to see the action preview.`})}):(0,Y.jsx)(Z,{hint:`action`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 flex items-center justify-center min-h-[80px]`,children:(0,Y.jsx)(Xp,{label:i,icon:a,variant:c,iconOnly:E,disabled:!!S&&typeof S==`boolean`})}),(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-3 text-xs space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(rm,{icon:T,label:`type: ${o}`}),b&&(0,Y.jsx)(rm,{icon:br,label:`object: ${b}`,mono:!0}),c&&(0,Y.jsx)(rm,{label:`variant: ${c}`}),l&&(0,Y.jsx)(rm,{icon:Ht,label:l}),d&&(0,Y.jsx)(rm,{icon:O,label:d,mono:!0}),f&&(0,Y.jsx)(rm,{icon:ee,label:`bulk`,tone:`green`}),p&&(0,Y.jsx)(rm,{icon:Dt,label:`refresh after`}),m===!1&&(0,Y.jsx)(rm,{icon:cn,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,Y.jsx)(rm,{icon:En,label:`AI: exposed`})]}),u.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Locations:`}),u.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e},e))]}),!!(typeof x==`string`||x&&typeof x==`object`)&&(0,Y.jsx)(tm,{label:`Visible when`,value:x,icon:He}),S!=null&&typeof S!=`boolean`&&(0,Y.jsx)(tm,{label:`Disabled when`,value:S,icon:lt})]}),(0,Y.jsxs)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-blue-900 mb-0.5`,children:[(0,Y.jsx)(T,{className:`h-3.5 w-3.5`}),` On click`]}),(0,Y.jsx)(`div`,{className:`text-blue-950 font-mono break-all`,children:Jp(o,s,!!y?.source)}),h&&(0,Y.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-1.5 text-amber-900`,children:[(0,Y.jsx)(I,{className:`h-3 w-3 mt-0.5`}),(0,Y.jsxs)(`span`,{children:[`First asks: `,(0,Y.jsx)(`em`,{children:h})]})]}),g&&(0,Y.jsxs)(`div`,{className:`mt-1.5 text-blue-950`,children:[`On success: `,(0,Y.jsx)(`em`,{children:g})]})]}),u.length>0&&(0,Y.jsx)(nm,{title:`Where it appears`,children:(0,Y.jsx)(am,{locations:u,label:i,icon:a,variant:c,iconOnly:E})}),o===`api`&&!!s&&(0,Y.jsx)(nm,{title:`Test request`,icon:Tr,children:(0,Y.jsx)(om,{target:s,method:C,bodyExtra:w,params:_})}),_.length>0&&(0,Y.jsx)(nm,{title:`Input Dialog`,count:_.length,children:(0,Y.jsx)(Qp,{title:i,params:_,variant:c})}),v&&(0,Y.jsx)(nm,{title:`Result Dialog`,icon:He,children:(0,Y.jsx)(em,{dialog:v})}),y?.source&&(0,Y.jsx)(nm,{title:`Script Body (${y.language??`expression`})`,icon:mn,children:(0,Y.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap max-h-[200px] overflow-auto`,children:y.source})})]})})})}function Xp({label:e,icon:t,variant:n,iconOnly:r,disabled:i}){return(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded px-3 py-1.5 text-sm font-medium pointer-events-none ${qp(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,Y.jsx)(Zp,{name:t}),!r&&(0,Y.jsx)(`span`,{children:e})]})}function Zp({name:e}){let t=e.split(/[-_\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),n=le[t===`Home`?`House`:t];return n?(0,Y.jsx)(n,{className:`h-4 w-4`,"aria-hidden":!0}):(0,Y.jsx)(`span`,{className:`inline-flex h-4 min-w-4 items-center justify-center rounded bg-white/30 px-1 text-[9px] uppercase font-mono`,children:e.slice(0,3)})}function Qp({title:e,params:t,variant:n}){return(0,Y.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,Y.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:e}),(0,Y.jsx)(`div`,{className:`p-3 space-y-2`,children:t.map((e,t)=>{let n=e.name??e.field??`param_${t}`;return(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsxs)(`label`,{className:`text-xs flex items-center gap-1`,children:[Gp(e.label)||n,e.required&&(0,Y.jsx)(`span`,{className:`text-red-600 text-[10px]`,children:`*`}),(0,Y.jsx)(`span`,{className:`ml-1 font-mono text-[9px] text-muted-foreground`,children:n}),e.type&&(0,Y.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:e.type})]}),$p(e),e.helpText&&(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e.helpText})]},t)})}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t bg-muted/20 px-3 py-2`,children:[(0,Y.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded border bg-background pointer-events-none`,children:`Cancel`}),(0,Y.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded pointer-events-none ${qp(n||`primary`)}`,children:`OK`})]})]})}function $p(e){let t=`w-full text-xs px-2 py-1 border rounded bg-background pointer-events-none`,n=e.placeholder||(e.defaultFromRow?`(from selected row)`:``),r=e.defaultValue;return Array.isArray(e.options)&&e.options.length>0?(0,Y.jsxs)(`select`,{className:t,disabled:!0,value:``,children:[(0,Y.jsx)(`option`,{value:``,children:n||`— select —`}),e.options.map((e,t)=>(0,Y.jsx)(`option`,{value:e.value,children:Gp(e.label)},t))]}):e.type===`boolean`?(0,Y.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,disabled:!0,className:`pointer-events-none`}),` Toggle`]}):e.type===`textarea`||e.type===`html`||e.type===`long_text`?(0,Y.jsx)(`textarea`,{className:`${t} min-h-[48px]`,placeholder:n,value:r==null?``:String(r),readOnly:!0}):(0,Y.jsx)(`input`,{type:e.type===`number`||e.type===`integer`?`number`:e.type===`date`?`date`:`text`,className:t,placeholder:n,value:r==null?``:String(r),readOnly:!0})}function em({dialog:e}){let t=Gp(e.title)||`Result`,n=Gp(e.description),r=Gp(e.acknowledge)||`I have saved this`,i=e.fields??[];return(0,Y.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,Y.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:t}),(0,Y.jsxs)(`div`,{className:`p-3 space-y-2 text-xs`,children:[n&&(0,Y.jsx)(`div`,{className:`text-muted-foreground`,children:n}),i.length===0?(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Renders full JSON response.`}):(0,Y.jsx)(`ul`,{className:`space-y-1.5`,children:i.map((t,n)=>(0,Y.jsx)(`li`,{className:`rounded border bg-muted/20 p-2`,children:(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,Y.jsx)(`span`,{className:`font-medium`,children:Gp(t.label)||t.path}),(0,Y.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:t.path}),(0,Y.jsx)(`span`,{className:`ml-auto font-mono text-[9px] uppercase text-muted-foreground`,children:t.format??e.format??`json`})]})},n))})]}),(0,Y.jsx)(`div`,{className:`flex items-center justify-end border-t bg-muted/20 px-3 py-2`,children:(0,Y.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded bg-primary text-primary-foreground pointer-events-none`,children:r})})]})}function tm({label:e,value:t,icon:n}){let r=typeof t==`string`?t:t?.source??JSON.stringify(t);return(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 pt-0.5`,children:[(0,Y.jsx)(n,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:r})]})}function nm({title:e,count:t,icon:n,children:r}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,Y.jsx)(n,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e}),t!=null&&(0,Y.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function rm({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function im({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-mono uppercase tracking-wider text-muted-foreground/70`,children:e}),t]})}function am({locations:e,label:t,icon:n,variant:r,iconOnly:i}){let a=(0,Y.jsx)(Xp,{label:t,icon:n,variant:r,iconOnly:i});return(0,Y.jsxs)(`div`,{className:`space-y-2.5`,children:[e.includes(`record_header`)&&(0,Y.jsx)(im,{label:`record_header`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`div`,{className:`h-6 w-6 rounded bg-muted`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium`,children:`Sample record`}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Record detail`})]})]}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5`,children:a})]}),(0,Y.jsx)(`div`,{className:`p-3 text-[10px] text-muted-foreground`,children:`…record body…`})]})}),e.includes(`list_toolbar`)&&(0,Y.jsx)(im,{label:`list_toolbar`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium`,children:`Records`}),(0,Y.jsx)(`div`,{className:`flex items-center gap-1.5`,children:a})]}),(0,Y.jsx)(`div`,{className:`px-3 py-2 text-[10px] text-muted-foreground`,children:`row 1 · row 2 · row 3`})]})}),e.includes(`list_item`)&&(0,Y.jsx)(im,{label:`list_item`,children:(0,Y.jsx)(`div`,{className:`divide-y rounded border bg-background`,children:[0,1].map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-1.5`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px]`,children:[`Row `,e+1]}),(0,Y.jsx)(`div`,{className:`origin-right scale-90`,children:a})]},e))})}),(e.includes(`record_section`)||e.includes(`record_related`))&&(0,Y.jsx)(im,{label:e.includes(`record_related`)?`record_related`:`record_section`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:`Section`}),a]}),(0,Y.jsx)(`div`,{className:`p-3 text-[10px] text-muted-foreground`,children:`…section content…`})]})}),e.includes(`record_more`)&&(0,Y.jsx)(im,{label:`record_more`,children:(0,Y.jsxs)(`div`,{className:`w-52 rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-3 py-1.5 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(Ht,{className:`h-3.5 w-3.5`}),` More`]}),(0,Y.jsx)(`div`,{className:`px-2 py-1.5 text-xs`,children:(0,Y.jsx)(`div`,{className:`rounded px-1 py-0.5 hover:bg-accent`,children:t})})]})}),e.includes(`global_nav`)&&(0,Y.jsx)(im,{label:`global_nav`,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsx)(`div`,{className:`px-3 py-2 text-[11px] text-muted-foreground`,children:`⌘K · Command palette`}),(0,Y.jsx)(`div`,{className:`border-t px-3 py-1.5 text-xs`,children:(0,Y.jsx)(`div`,{className:`rounded px-1 py-0.5 hover:bg-accent`,children:t})})]})})]})}function om({target:e,method:t,bodyExtra:n,params:r}){let i=(t||`POST`).toUpperCase(),[a,o]=X.useState(null),[s,c]=X.useState(!1),l=n&&typeof n==`object`?n:{};return(0,Y.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2 font-mono text-[11px] break-all`,children:[(0,Y.jsx)(`span`,{className:`font-semibold`,children:i}),` `,e]}),Object.keys(l).length>0&&(0,Y.jsx)(`pre`,{className:`m-0 rounded border bg-muted/30 p-2 text-[10px] font-mono whitespace-pre-wrap`,children:JSON.stringify(l,null,2)}),r.length>0&&(0,Y.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`+ `,r.length,` user-supplied param`,r.length>1?`s`:``,` collected at runtime`]}),i!==`GET`&&(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-amber-700`,children:[(0,Y.jsx)(I,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,Y.jsxs)(`span`,{children:[`Sends a real `,i,` request to the live backend — may modify data.`]})]}),(0,Y.jsxs)(`button`,{type:`button`,onClick:async()=>{c(!0),o(null);try{let t=typeof localStorage<`u`?localStorage.getItem(`auth-session-token`):null,n={"Content-Type":`application/json`};t&&(n.Authorization=`Bearer ${t}`);let r={method:i,headers:n,credentials:`include`};i!==`GET`&&i!==`HEAD`&&(r.body=JSON.stringify(l));let a=await fetch(e,r),s=await a.text(),c=s;try{c=JSON.parse(s)}catch{}o({status:a.status,ok:a.ok,body:c})}catch(e){o({status:0,ok:!1,error:e instanceof Error?e.message:String(e)})}finally{c(!1)}},disabled:s,className:`inline-flex items-center gap-1.5 rounded border bg-background px-2.5 py-1 text-xs font-medium hover:bg-accent disabled:opacity-50`,children:[(0,Y.jsx)(Tr,{className:`h-3.5 w-3.5`}),` `,s?`Sending…`:`Send test request`]}),a&&(0,Y.jsxs)(`div`,{className:`rounded border p-2 `+(a.ok?`border-green-300 bg-green-50`:`border-red-300 bg-red-50`),children:[(0,Y.jsx)(`div`,{className:`mb-1 text-[11px] font-medium`,children:a.error?`Network error`:`HTTP `+a.status+(a.ok?` OK`:``)}),(0,Y.jsx)(`pre`,{className:`m-0 max-h-[200px] overflow-auto text-[10px] font-mono whitespace-pre-wrap`,children:a.error??(typeof a.body==`string`?a.body:JSON.stringify(a.body,null,2))})]})]})}var sm={"@yearly":`0 0 1 1 *`,"@annually":`0 0 1 1 *`,"@monthly":`0 0 1 * *`,"@weekly":`0 0 * * 0`,"@daily":`0 0 * * *`,"@midnight":`0 0 * * *`,"@hourly":`0 * * * *`};function cm(e,t,n){let r={values:new Set,any:!1};if(e===`*`){for(let e=t;e<=n;e++)r.values.add(e);return r.any=!0,r}for(let i of e.split(`,`)){let e,a=i;if(i.includes(`/`)){let[t,n]=i.split(`/`);a=t,e=n}let o=e?Math.max(1,parseInt(e,10)||1):1,s=t,c=n;if(a!==`*`)if(a.includes(`-`)){let[e,t]=a.split(`-`).map(e=>parseInt(e,10));if(Number.isNaN(e)||Number.isNaN(t))return null;s=e,c=t}else{let e=parseInt(a,10);if(Number.isNaN(e))return null;s=e,c=e}for(let e=s;e<=c;e+=o)e>=t&&e<=n&&r.values.add(e)}return r}function lm(e){let t=(sm[e.trim()]??e.trim()).split(/\s+/);if(t.length!==5&&t.length!==6)return null;let[n,r,i,a,o]=t.length===6?t.slice(1):t,s=cm(n,0,59),c=cm(r,0,23),l=cm(i,1,31),u=cm(a,1,12),d=cm(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function um(e,t,n){let r=lm(e);if(!r)return[];let i=[],a=new Date(t.getTime());a.setSeconds(0,0),a.setMinutes(a.getMinutes()+1);let o=t.getTime()+366*24*60*60*1e3;for(;i.length<n&&a.getTime()<=o;)r.minute.values.has(a.getMinutes())&&r.hour.values.has(a.getHours())&&r.month.values.has(a.getMonth()+1)&&(r.dom.any||r.dow.any?r.dom.values.has(a.getDate())&&r.dow.values.has(a.getDay()):r.dom.values.has(a.getDate())||r.dow.values.has(a.getDay()))&&i.push(new Date(a.getTime())),a.setMinutes(a.getMinutes()+1);return i}function dm(e){let t=/^(\d+)\s*(ms|s|m|h|d)$/.exec(e.trim());if(!t)return null;let n=parseInt(t[1],10);switch(t[2]){case`ms`:return n;case`s`:return n*1e3;case`m`:return n*6e4;case`h`:return n*36e5;case`d`:return n*864e5;default:return null}}function fm(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function pm(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function mm(e){if(e.schedule&&typeof e.schedule==`object`){let t=e.schedule,n=String(t.type??``),r=t.timezone??e.timezone??e.tz;if(n===`cron`){let e=t.expression;return{cron:typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:void 0,timezone:r}}if(n===`interval`){let e=Number(t.intervalMs);return{every:Number.isFinite(e)&&e>0?hm(e):void 0,timezone:r}}if(n===`once`)return{at:typeof t.at==`string`?t.at:void 0,timezone:r}}let t=typeof e.cron==`string`?e.cron:typeof e.schedule==`string`?e.schedule:void 0,n=e.every??e.interval;return{cron:t,every:typeof n==`string`?n:typeof n==`number`?hm(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function hm(e){return e%864e5==0?`${e/864e5}d`:e%36e5==0?`${e/36e5}h`:e%6e4==0?`${e/6e4}m`:e%1e3==0?`${e/1e3}s`:`${e}ms`}function gm({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,{cron:o,every:s,at:c,timezone:l}=mm(n),u=n.handler??n.target??n.function??n.functionName,d=n.active!==!1&&n.enabled!==!1,f=n.retryPolicy,p=f?.maxRetries??n.maxRetries??n.retries,m=f?.backoffMs,h=n.timeout??n.timeoutMs,g=n.concurrency,_=s?dm(s):null,{nextFires:v,deltas:y}=X.useMemo(()=>{let e=new Date,t=[];if(o)t=um(o,e,5);else if(_)t=fm(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>_m(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,Y.jsx)(Z,{hint:`job`,children:(0,Y.jsx)(gl,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,Y.jsx)(Z,{hint:`job`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(de,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(bm,{icon:ir,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,Y.jsx)(bm,{icon:Kt,label:l,mono:!0}),p!=null&&(0,Y.jsx)(bm,{icon:Me,label:`retries: ${p}${m?` (${hm(m)} backoff)`:``}`}),h!=null&&(0,Y.jsx)(bm,{icon:zt,label:`timeout: ${hm(h)}`}),g!=null&&(0,Y.jsx)(bm,{label:`concurrency: ${g}`})]})]})]})}),(0,Y.jsx)(ym,{title:`Schedule`,icon:k,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,Y.jsx)(vm,{label:`Cron`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,Y.jsxs)(vm,{label:`Every`,children:[(0,Y.jsx)(`code`,{className:`font-mono`,children:s}),!_&&(0,Y.jsx)(`span`,{className:`ml-2 text-amber-700`,children:`unparseable`})]}),c&&(0,Y.jsx)(vm,{label:`At`,children:(0,Y.jsx)(`code`,{className:`font-mono`,children:c})}),!o&&!s&&!c&&(0,Y.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No schedule set — runs only when triggered manually.`})]})}),(o||_||c)&&(0,Y.jsx)(ym,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:wn,children:v.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-amber-700`,children:b?`Could not derive any future fire time. Check the schedule syntax.`:`No upcoming runs in the next 366 days.`}):(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:v.map((e,t)=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`w-4 text-right text-muted-foreground text-[10px]`,children:t+1}),(0,Y.jsx)(wn,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono`,children:pm(e)}),(0,Y.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,Y.jsx)(ym,{title:`Handler`,icon:mn,children:u?(0,Y.jsxs)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs flex items-center gap-2`,children:[(0,Y.jsx)($e,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:u})]}):(0,Y.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No handler bound — the job will be a no-op.`})})]})})})}function _m(e){if(e<=0)return`now`;let t=Math.round(e/1e3);if(t<60)return`${t}s`;let n=Math.round(t/60);if(n<60)return`${n}m`;let r=Math.round(n/60);return r<48?`${r}h`:`${Math.round(r/24)}d`}function vm({label:e,children:t}){return(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsxs)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:[e,`:`]}),(0,Y.jsx)(`span`,{className:`break-all`,children:t})]})}function ym({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function bm({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var xm=[{key:`objects`,label:`Objects`,icon:Mt,flat:!1},{key:`apps`,label:`Apps`,icon:_e,flat:!1},{key:`messages`,label:`Messages`,icon:j,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:ce,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:on,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:Lt,flat:!1},{key:`settings`,label:`Settings`,icon:ve,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:Ce,flat:!1}];function Sm({name:e,draft:t}){let n=t,r=n.locale??n.language??`?`,i=n.label??n.name??e??``,a=n.description,o=n.data??n,s=xm.map(e=>{let t=o?.[e.key];if(!t||typeof t!=`object`)return{...e,count:0,sample:[]};let n=Object.entries(t);return{...e,count:n.length,sample:n.slice(0,5)}}),c=s.reduce((e,t)=>e+t.count,0),l=s.filter(e=>e.count>0).length,u=Math.round(l/xm.length*100);return c===0?(0,Y.jsx)(Z,{hint:`translation · ${r}`,children:(0,Y.jsx)(gl,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,Y.jsx)(Z,{hint:`translation · ${r} · ${c} keys`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(at,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 text-[10px] font-mono text-emerald-800`,children:[(0,Y.jsx)(Kt,{className:`h-3 w-3`}),` `,r]})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-[11px]`,children:[(0,Y.jsx)(ht,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Category coverage:`}),(0,Y.jsx)(`div`,{className:`h-1.5 w-32 rounded-full bg-muted overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${u}%`}})}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[l,`/`,xm.length,` (`,u,`%)`]}),(0,Y.jsxs)(`span`,{className:`ml-3 text-muted-foreground`,children:[c,` total keys`]})]})]})]})}),(0,Y.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,Y.jsx)(Cm,{cat:e},e.key))})]})})})}function Cm({cat:e}){let t=e.icon;return(0,Y.jsxs)(`div`,{className:`rounded border bg-background ${e.count===0?`opacity-60`:``}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between border-b px-2.5 py-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:e.label})]}),(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e.count})]}),(0,Y.jsx)(`div`,{className:`px-2.5 py-1.5 min-h-[3.5rem]`,children:e.count===0?(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`empty`}):(0,Y.jsxs)(`ul`,{className:`space-y-0.5 text-[11px]`,children:[e.sample.map(([t,n])=>(0,Y.jsxs)(`li`,{className:`flex items-baseline gap-2 truncate`,children:[(0,Y.jsx)(`code`,{className:`font-mono text-muted-foreground shrink-0`,children:t}),(0,Y.jsx)(`span`,{className:`truncate text-foreground/80`,children:wm(n,e.flat)})]},t)),e.count>e.sample.length&&(0,Y.jsxs)(`li`,{className:`text-[10px] text-muted-foreground italic`,children:[`+`,e.count-e.sample.length,` more…`]})]})})]})}function wm(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function Tm({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.parent;return r?(0,Y.jsx)(Z,{hint:`role`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Ne,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a})]})]})}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1.5`,children:`Hierarchy`}),(0,Y.jsx)(`div`,{className:`rounded border bg-background p-2.5 text-xs`,children:o?(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(un,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Parent:`}),(0,Y.jsx)(`code`,{className:`font-mono`,children:o})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 pl-4`,children:[(0,Y.jsx)($n,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`rounded bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 text-[11px] font-mono text-emerald-800`,children:r}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`this role`})]}),(0,Y.jsx)(`div`,{className:`text-[10px] text-muted-foreground pt-1`,children:`Open the parent role to walk further up the chain.`})]}):(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`rounded bg-emerald-50 border border-emerald-200 px-1.5 py-0.5 text-[11px] font-mono text-emerald-800`,children:r}),(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground italic`,children:`root role — no parent`})]})})]}),(0,Y.jsx)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-[11px] text-blue-900`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,Y.jsx)(mt,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium`,children:`Roles don't grant data access on their own.`}),(0,Y.jsxs)(`div`,{className:`opacity-90 mt-0.5`,children:[`Bind `,(0,Y.jsx)(`code`,{className:`font-mono`,children:r}),` to one or more `,(0,Y.jsx)(`strong`,{children:`Permission Sets`}),` `,`or assign it to a `,(0,Y.jsx)(`strong`,{children:`Profile`}),` to control CRUD-VAMA, field access, and tab visibility.`]})]})]})})]})})}):(0,Y.jsx)(Z,{hint:`role`,children:(0,Y.jsx)(gl,{children:`Give the role a name to see the preview.`})})}function Em({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.instructions??``,s=Array.isArray(n.tools)?n.tools:[],c=Array.isArray(n.triggerPhrases)?n.triggerPhrases:[],l=Array.isArray(n.triggerConditions)?n.triggerConditions:[],u=Array.isArray(n.permissions)?n.permissions:[],d=n.active!==!1,f=n.model??void 0;return r?(0,Y.jsx)(Z,{hint:`skill`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(En,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(Om,{icon:ir,label:d?`Active`:`Disabled`,tone:d?`green`:`gray`}),f&&(0,Y.jsx)(Om,{label:`model: ${f}`,mono:!0}),u.length>0&&(0,Y.jsx)(Om,{icon:mt,label:`${u.length} required perm${u.length===1?``:`s`}`})]})]})]})}),(0,Y.jsx)(Dm,{title:`Instructions`,icon:yr,children:o?(0,Y.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words max-h-64 overflow-auto`,children:o}):(0,Y.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No instructions yet — the skill will contribute nothing to the prompt.`})}),(0,Y.jsxs)(Dm,{title:`Tools (${s.length})`,icon:Rn,children:[s.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No tools whitelisted.`}):(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>{let t=e.includes(`*`);return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 text-[11px] font-mono border ${t?`border-amber-300 bg-amber-50 text-amber-900`:`border-border bg-muted/40`}`,children:[t&&(0,Y.jsx)(Xt,{className:`h-3 w-3`}),e]},e)})}),s.some(e=>e.includes(`*`))&&(0,Y.jsx)(`div`,{className:`mt-1 text-[10px] text-amber-700`,children:`Wildcards expand to many tools at runtime — review the matching set in the agent before activating.`})]}),c.length>0&&(0,Y.jsx)(Dm,{title:`Trigger Phrases (${c.length})`,icon:ue,children:(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:c.map((e,t)=>(0,Y.jsxs)(`li`,{className:`px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground mr-2`,children:`"`}),e,(0,Y.jsx)(`span`,{className:`text-muted-foreground ml-2`,children:`"`})]},t))})}),l.length>0&&(0,Y.jsx)(Dm,{title:`Trigger Conditions (${l.length})`,icon:kr,children:(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsx)(`table`,{className:`w-full text-xs`,children:(0,Y.jsx)(`tbody`,{className:`divide-y`,children:l.map((e,t)=>(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-24 text-muted-foreground text-[10px] uppercase`,children:e.type??`cond`}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:e.expression??e.value??JSON.stringify(e)})]},t))})})})}),u.length>0&&(0,Y.jsx)(Dm,{title:`Required Permissions`,icon:mt,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:u.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})})]})})}):(0,Y.jsx)(Z,{hint:`skill`,children:(0,Y.jsx)(gl,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function Dm({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function Om({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var km=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},Am=d();function jm(){return``.replace(/\/+$/,``)}function Mm(e){return`${jm()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function Nm(e){if(e.status===503){let t;try{t=await e.json()}catch{t=void 0}if((t&&typeof t==`object`&&`error`in t?String(t.error):``)===`external_service_unavailable`)throw new km}if(!e.ok){let t=`${e.status} ${e.statusText}`;try{let n=await e.json();n&&typeof n==`object`&&`error`in n&&(t=String(n.error))}catch{}throw Error(t)}return await e.json()}async function Pm(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await Nm(await Am(`${Mm(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function Fm(e,t,n={}){return(await Nm(await Am(`${Mm(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function Im(e){return(await Nm(await Am(`${Mm(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function Lm(e){return Nm(await Am(`${Mm(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function Rm(e){await Nm(await Am(`${jm()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function zm({datasource:e,table:t,open:n,onOpenChange:r,onImported:i}){let[a,o]=X.useState(`loading`),[s,c]=X.useState(null),[l,u]=X.useState(null);X.useEffect(()=>{if(!n||!t)return;let r=!1;return o(`loading`),c(null),u(null),(async()=>{try{let n=await Fm(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof km?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e)),o(`error`)}})(),()=>{r=!0}},[n,t,e]);let d=X.useCallback(async()=>{if(s){o(`importing`),u(null);try{await Rm(s),o(`done`),i?.(s.name)}catch(e){u(e instanceof Error?e.message:String(e)),o(`ready`)}}},[s,i]),f=t?[t.schema,t.name].filter(Boolean).join(`.`):``;return(0,Y.jsx)(St,{open:n,onOpenChange:r,children:(0,Y.jsxs)(Pt,{className:`max-w-2xl`,children:[(0,Y.jsxs)(ar,{children:[(0,Y.jsxs)(Le,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(Yn,{className:`h-4 w-4`}),`Import as Object`]}),(0,Y.jsxs)(Ee,{children:[`Map remote table `,(0,Y.jsx)(`span`,{className:`font-mono`,children:f}),` into an ObjectStack object bound to `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),`. The remote schema is never modified.`]})]}),a===`loading`&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 py-8 justify-center text-sm text-muted-foreground`,children:[(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Generating draft…`]}),a===`error`&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive`,children:l}),a===`done`&&s&&(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,Y.jsx)(In,{className:`h-8 w-8 text-emerald-500`}),(0,Y.jsxs)(`div`,{className:`text-sm`,children:[`Imported object `,(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:s.name}),`.`]}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Review its binding and run validation to confirm it matches the remote table.`})]}),(a===`ready`||a===`importing`)&&s&&(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-sm`,children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Object name`}),(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:s.name})]}),l&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2 text-xs text-destructive`,children:l}),s.review.length>0&&(0,Y.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-2.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-300`,children:[(0,Y.jsx)(I,{className:`h-3.5 w-3.5`}),s.review.length,` column`,s.review.length===1?``:`s`,` need review`]}),(0,Y.jsx)(`ul`,{className:`mt-1.5 space-y-1 text-[11px] text-amber-900/90 dark:text-amber-200/80`,children:s.review.map(e=>(0,Y.jsxs)(`li`,{className:`flex flex-wrap gap-x-1.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e.column}),(0,Y.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-400/70`,children:[`(`,e.remoteType,`)`]}),(0,Y.jsxs)(`span`,{children:[`— `,e.note]})]},e.column))})]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,Y.jsx)(Ct,{className:`h-3 w-3`}),` Generated source`]}),(0,Y.jsx)(`pre`,{className:`max-h-64 overflow-auto rounded border bg-muted/30 p-2.5 text-[11px] leading-relaxed font-mono`,children:s.source})]})]}),(0,Y.jsx)(Ve,{children:a===`done`?(0,Y.jsx)(H,{onClick:()=>r(!1),children:`Close`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(H,{variant:`ghost`,onClick:()=>r(!1),disabled:a===`importing`,children:`Cancel`}),(0,Y.jsx)(H,{onClick:d,disabled:a!==`ready`||!s,children:a===`importing`?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}),` Importing…`]}):`Import as Object`})]})})]})})}function Bm({datasource:e}){let[t,n]=X.useState(`idle`),[r,i]=X.useState([]),[a,o]=X.useState(null),[s,c]=X.useState(``),[l,u]=X.useState(null),[d,f]=X.useState(!1),p=X.useCallback(async()=>{n(`loading`),o(null);try{let t=await Pm(e);i(t),n(`loaded`)}catch(e){e instanceof km?n(`unavailable`):(o(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);X.useEffect(()=>{p()},[p]);let m=X.useMemo(()=>{let e=s.trim().toLowerCase();return e?r.filter(t=>[t.schema,t.name].filter(Boolean).join(`.`).toLowerCase().includes(e)):r},[r,s]),h=e=>{u(e),f(!0)};return t===`unavailable`?(0,Y.jsx)(Vm,{}):(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex-1`,children:[(0,Y.jsx)(Xe,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`input`,{value:s,onChange:e=>c(e.target.value),placeholder:`Filter tables…`,className:`w-full rounded border bg-background pl-7 pr-2 py-1.5 text-xs outline-none focus:ring-1 focus:ring-ring`})]}),(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>void p(),disabled:t===`loading`,children:[t===`loading`?(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Dt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]}),a&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2.5 text-xs text-destructive`,children:a}),t===`loading`&&r.length===0&&(0,Y.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground`,children:[(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Introspecting remote schema…`]}),t===`loaded`&&m.length===0&&(0,Y.jsx)(`div`,{className:`py-10 text-center text-sm text-muted-foreground`,children:r.length===0?`No remote tables found (check the datasource’s allowedSchemas).`:`No tables match the filter.`}),m.length>0&&(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40 text-muted-foreground`,children:(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium`,children:`Table`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Columns`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Rows (est.)`}),(0,Y.jsx)(`th`,{className:`px-2.5 py-1.5 w-px`})]})}),(0,Y.jsx)(`tbody`,{className:`divide-y`,children:m.map(e=>{let t=[e.schema,e.name].filter(Boolean).join(`.`);return(0,Y.jsxs)(`tr`,{className:`hover:bg-muted/30`,children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 font-mono`,children:[(0,Y.jsx)(An,{className:`h-3.5 w-3.5 text-muted-foreground`}),e.schema&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.schema,`.`]}),(0,Y.jsx)(`span`,{className:`font-medium`,children:e.name})]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,Y.jsx)(xr,{className:`h-3 w-3`}),e.columnCount]})}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums text-muted-foreground`,children:typeof e.rowCountEstimate==`number`?e.rowCountEstimate.toLocaleString():`—`}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,Y.jsxs)(H,{variant:`ghost`,size:`sm`,onClick:()=>h(e),children:[(0,Y.jsx)(st,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,Y.jsx)(zm,{datasource:e,table:l,open:d,onOpenChange:f})]})}function Vm(){return(0,Y.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-3 text-xs text-amber-900 dark:text-amber-200`,children:[`Federation is not enabled on this server. The`,(0,Y.jsx)(`span`,{className:`font-mono`,children:` external-datasource `}),`service must be registered for table browsing, drafting, and validation to work.`]})}var Hm={missing_table:`Missing table`,missing_column:`Missing column`,type_mismatch:`Type mismatch`,nullability_mismatch:`Nullability mismatch`,unmapped_column:`Unmapped column`,pk_mismatch:`Primary-key mismatch`};function Um({datasource:e}){let[t,n]=X.useState(`idle`),[r,i]=X.useState([]),[a,o]=X.useState(null),[s,c]=X.useState(null),l=X.useCallback(async()=>{n(`running`),c(null);try{let t=await Lm(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof km?n(`unavailable`):(c(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);return t===`unavailable`?(0,Y.jsx)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-3 text-xs text-amber-900 dark:text-amber-200`,children:`Federation is not enabled on this server, so validation is unavailable.`}):(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Check that every federated object on`,` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),` still matches its live remote table.`]}),(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:t===`running`,children:[t===`running`?(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)($e,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Run validation`})]})]}),s&&(0,Y.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2.5 text-xs text-destructive`,children:s}),t===`done`&&a!==null&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 rounded border p-2.5 text-sm ${a?`border-emerald-300 bg-emerald-50 dark:bg-emerald-950/20 text-emerald-800 dark:text-emerald-300`:`border-destructive/40 bg-destructive/5 text-destructive`}`,children:[a?(0,Y.jsx)(In,{className:`h-4 w-4`}):(0,Y.jsx)(ce,{className:`h-4 w-4`}),a?`All ${r.length} object${r.length===1?``:`s`} match the remote schema.`:`${r.filter(e=>!e.ok).length} of ${r.length} object${r.length===1?``:`s`} diverge from the remote schema.`]}),t===`done`&&r.length===0&&(0,Y.jsx)(`div`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`No federated objects are bound to this datasource yet. Import a table from the Tables tab to get started.`}),r.length>0&&(0,Y.jsx)(`ul`,{className:`space-y-2`,children:r.map(e=>(0,Y.jsx)(Wm,{result:e},e.object))})]})}function Wm({result:e}){return(0,Y.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[e.ok?(0,Y.jsx)(mt,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,Y.jsx)(ce,{className:`h-3.5 w-3.5 text-destructive`}),(0,Y.jsx)(`span`,{className:`font-mono text-xs font-medium`,children:e.object}),!e.ok&&(0,Y.jsxs)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[e.diffs.length,` diff`,e.diffs.length===1?``:`s`]})]}),e.diffs.length>0&&(0,Y.jsx)(`ul`,{className:`border-t divide-y`,children:e.diffs.map((e,t)=>(0,Y.jsx)(Gm,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function Gm({diff:e}){let t=[e.remoteSchema,e.remoteName].filter(Boolean).join(`.`);return(0,Y.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-x-2 gap-y-0.5 px-2.5 py-1.5 text-[11px]`,children:[(0,Y.jsx)(`span`,{className:`rounded px-1 py-0.5 font-medium uppercase tracking-wide text-[9px] ${e.severity===`error`?`bg-destructive/10 text-destructive`:`bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300`}`,children:Hm[e.kind]??e.kind}),t&&(0,Y.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:t}),e.column&&(0,Y.jsxs)(`span`,{className:`font-mono`,children:[`.`,e.column]}),(e.expected!==void 0||e.actual!==void 0)&&(0,Y.jsxs)(`span`,{className:`text-muted-foreground`,children:[`expected `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.expected??`—`}),`, actual`,` `,(0,Y.jsx)(`span`,{className:`font-mono`,children:e.actual??`—`})]})]})}function Km({datasource:e,schemaMode:t,allowWrites:n}){let[r,i]=X.useState(null),[a,o]=X.useState(!1),[s,c]=X.useState(null),l=X.useCallback(async()=>{if(e){o(!0),c(null);try{let t=await Im(e);i(t)}catch(e){c(e instanceof km?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e))}finally{o(!1)}}},[e]);return e?(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1.5 border-b bg-muted/30 px-3 py-2`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-medium`,children:[(0,Y.jsx)(ur,{className:`h-4 w-4 text-sky-500`}),`External Datasource`]}),(0,Y.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 font-mono text-[10px] uppercase tracking-wider text-muted-foreground`,children:t??`external`}),(0,Y.jsx)(`span`,{className:`rounded px-1.5 py-0.5 text-[10px] uppercase tracking-wider ${n?`bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300`:`bg-muted text-muted-foreground`}`,children:n?`writes allowed`:`read-only`}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[r?.snapshotAt&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,Y.jsx)(wn,{className:`h-3 w-3`}),`snapshot `,qm(r.snapshotAt)]}),(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:a,children:[a?(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Dt,{className:`h-3.5 w-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:`Refresh catalog`})]})]})]}),s&&(0,Y.jsx)(`div`,{className:`border-b border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:s}),(0,Y.jsxs)(fn,{defaultValue:`tables`,className:`p-3`,children:[(0,Y.jsxs)(Sr,{children:[(0,Y.jsx)(hn,{value:`tables`,children:`Tables`}),(0,Y.jsx)(hn,{value:`validation`,children:`Validation`})]}),(0,Y.jsx)(Hn,{value:`tables`,className:`mt-3`,children:(0,Y.jsx)(Bm,{datasource:e})}),(0,Y.jsx)(Hn,{value:`validation`,className:`mt-3`,children:(0,Y.jsx)(Um,{datasource:e})})]})]}):(0,Y.jsx)(`div`,{className:`rounded border bg-muted/20 p-3 text-xs text-muted-foreground`,children:`Save the datasource first to browse its remote tables and validate federated objects.`})}function qm(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var Jm=/pass|secret|key|token|credential|auth/i;function Ym(e){return Jm.test(e)}function Xm(e){return e==null||e===``?`∅`:`••••••`}function Zm(e){return e==null?`∅`:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):Array.isArray(e)?`[${e.length}]`:typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e)}function Qm({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.driver??n.type??`unknown`,s=n.active!==!1,c=!!n.isDefault||!!n.default,l=n.config??{},u=n.pool,d=n.ssl,f=n.retryPolicy,p=n.healthCheck,m=Array.isArray(n.readReplicas)?n.readReplicas:[],h=Array.isArray(n.capabilities)?n.capabilities:[],g=n.schemaMode??`managed`,_=g!==`managed`,v=!!(n.external??void 0)?.allowWrites,y=Object.entries(l);return!r&&y.length===0?(0,Y.jsx)(Z,{hint:`datasource`,children:(0,Y.jsx)(gl,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,Y.jsx)(Z,{hint:`datasource · ${o}`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(Yn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 font-mono`,children:[(0,Y.jsx)(nr,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,Y.jsx)(th,{icon:ir,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,Y.jsx)(th,{icon:ln,label:`default`,tone:`amber`}),m.length>0&&(0,Y.jsx)(th,{icon:dn,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),_&&(0,Y.jsx)(Km,{datasource:String(e??``),schemaMode:g,allowWrites:v}),(0,Y.jsx)(eh,{title:`Connection`,icon:lt,children:y.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No config keys set.`}):(0,Y.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,Y.jsx)(`table`,{className:`w-full text-xs`,children:(0,Y.jsx)(`tbody`,{className:`divide-y`,children:y.map(([e,t])=>{let n=Ym(e);return(0,Y.jsxs)(`tr`,{children:[(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-40 font-mono text-muted-foreground`,children:e}),(0,Y.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:n?(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{children:Xm(t)}),(0,Y.jsx)(`span`,{className:`rounded bg-amber-50 border border-amber-200 px-1 py-0.5 text-[9px] uppercase tracking-wider text-amber-800`,children:`redacted`})]}):Zm(t)})]},e)})})})})}),(0,Y.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,Y.jsx)($m,{title:`Pool`,icon:Ye,value:u}),(0,Y.jsx)($m,{title:`SSL`,icon:mt,value:typeof d==`boolean`?{enabled:d}:d}),(0,Y.jsx)($m,{title:`Retry Policy`,icon:Me,value:f}),(0,Y.jsx)($m,{title:`Health Check`,icon:Ye,value:p})]}),h.length>0&&(0,Y.jsx)(eh,{title:`Capabilities`,icon:mt,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})})]})})})}function $m({title:e,icon:t,value:n}){let r=n&&typeof n==`object`&&Object.keys(n).length>0;return(0,Y.jsxs)(`div`,{className:`rounded border bg-background ${r?``:`opacity-60`}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-2.5 py-1.5`,children:[(0,Y.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium`,children:e})]}),(0,Y.jsx)(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:r?(0,Y.jsx)(`dl`,{className:`space-y-0.5`,children:Object.entries(n).slice(0,6).map(([e,t])=>(0,Y.jsxs)(`div`,{className:`flex items-baseline gap-2 truncate`,children:[(0,Y.jsxs)(`dt`,{className:`text-muted-foreground font-mono shrink-0`,children:[e,`:`]}),(0,Y.jsx)(`dd`,{className:`font-mono truncate`,children:Ym(e)?Xm(t):Zm(t)})]},e))}):(0,Y.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function eh({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function th({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function nh(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function rh(e){switch(e){case`error`:return{ring:`border-red-200 bg-red-50 dark:border-red-900 dark:bg-red-950/40`,text:`text-red-700 dark:text-red-300`,icon:Yt};case`warning`:return{ring:`border-amber-200 bg-amber-50 dark:border-amber-900 dark:bg-amber-950/40`,text:`text-amber-800 dark:text-amber-300`,icon:I};default:return{ring:`border-blue-200 bg-blue-50 dark:border-blue-900 dark:bg-blue-950/40`,text:`text-blue-800 dark:text-blue-300`,icon:Mn}}}function ih({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.type??`script`,s=n.object,c=n.message??``,l=n.severity??`error`,u=n.active!==!1,d=Array.isArray(n.events)?n.events:[],f=n.priority,p=Array.isArray(n.tags)?n.tags:[],m=rh(l);return r?(0,Y.jsx)(Z,{hint:`validation · ${o}`,children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(ce,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,Y.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono`,children:o})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,Y.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,Y.jsx)(ch,{icon:ir,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,Y.jsx)(ch,{label:`object: ${s}`,mono:!0}),f!=null&&(0,Y.jsx)(ch,{label:`priority ${f}`}),d.length>0&&(0,Y.jsx)(ch,{label:`on ${d.join(`, `)}`})]})]})]})}),(0,Y.jsx)(`div`,{className:`rounded border p-2.5 text-xs ${m.ring}`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-1.5 ${m.text}`,children:[(0,Y.jsx)(m.icon,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`font-medium uppercase tracking-wider text-[10px]`,children:l}),(0,Y.jsx)(`div`,{className:`font-normal mt-0.5 text-foreground`,children:c||(0,Y.jsx)(`span`,{className:`italic text-muted-foreground`,children:`no message set`})})]})]})}),(0,Y.jsx)(ah,{type:o,d:n}),p.length>0&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1`,children:`Tags`}),(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:p.map(e=>(0,Y.jsx)(`span`,{className:`inline-flex items-center rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})]})]})})}):(0,Y.jsx)(Z,{hint:`validation`,children:(0,Y.jsx)(gl,{children:`Give the validation a name to see the preview.`})})}function ah({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,Y.jsx)(sh,{title:`Condition`,icon:mn,children:(0,Y.jsx)(oh,{value:nh(t.condition)??nh(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=nh(t.scope)??nh(t.where);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(sh,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:Fn,children:(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.length===0?(0,Y.jsx)(`span`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`no fields set`}):e.map(e=>(0,Y.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),n&&(0,Y.jsx)(sh,{title:`Scope`,icon:Lr,children:(0,Y.jsx)(oh,{value:n})})]})}case`state_machine`:{let e=t.transitions&&typeof t.transitions==`object`&&!Array.isArray(t.transitions)?t.transitions:{},n=Object.entries(e),r=t.field;return(0,Y.jsx)(sh,{title:`Transitions${r?` on ${r}`:``}`,icon:ne,children:n.length===0?(0,Y.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No transitions declared.`}):(0,Y.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:n.map(([e,t])=>(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,Y.jsx)(`span`,{className:`font-mono`,children:e}),(0,Y.jsx)(Nr,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`font-mono text-emerald-700 dark:text-emerald-400`,children:Array.isArray(t)&&t.length>0?t.join(` | `):`∅ (dead-end)`})]},e))})})}case`format`:{let e=t.pattern??t.regex,n=t.format;return(0,Y.jsx)(sh,{title:`Format`,icon:ie,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[n&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Built-in:`}),` `,(0,Y.jsx)(`code`,{className:`font-mono`,children:n})]}),e&&(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`Pattern:`}),` `,(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e})]}),!n&&!e&&(0,Y.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No format or regex set.`})]})})}case`cross_field`:{let e=Array.isArray(t.fields)?t.fields:[],n=nh(t.condition);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(sh,{title:`Fields involved`,icon:Lr,children:(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[e.map(e=>(0,Y.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e)),e.length===0&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`none`})]})}),(0,Y.jsx)(sh,{title:`Cross-field condition`,icon:mn,children:(0,Y.jsx)(oh,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,Y.jsx)(sh,{title:`Async endpoint`,icon:Kt,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:t.method??`POST`}),(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e??`—`})]}),n!=null&&(0,Y.jsxs)(`div`,{className:`text-muted-foreground`,children:[`timeout: `,n,`ms`]})]})})}case`custom`:{let e=t.handler??t.function;return(0,Y.jsx)(sh,{title:`Custom handler`,icon:mn,children:(0,Y.jsx)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs`,children:e?(0,Y.jsx)(`code`,{className:`font-mono break-all`,children:e}):(0,Y.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No handler set.`})})})}default:return(0,Y.jsx)(sh,{title:`Rule`,icon:ce,children:(0,Y.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs text-muted-foreground italic`,children:[`Unknown rule type "`,e,`". Showing common fields only.`]})})}}function oh({value:e}){return e?(0,Y.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words`,children:e}):(0,Y.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No expression set.`})}function sh({title:e,icon:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,Y.jsx)(t,{className:`h-3 w-3`}),(0,Y.jsx)(`span`,{children:e})]}),n]})}function ch({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,Y.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,Y.jsx)(`span`,{className:`${n===`green`?`text-emerald-700 dark:text-emerald-400`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var lh=X.lazy(()=>a(()=>import(`./plugin-charts-BZo5ApEF.js`).then(e=>e.t).then(e=>({default:e.ChartRenderer})),__vite__mapDeps([0]),import.meta.url));function uh({draft:e}){let t=p(),{fieldLabel:n}=je(),r=e.object,i=X.useMemo(()=>(Array.isArray(e.measures)?e.measures:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),a=X.useMemo(()=>(Array.isArray(e.dimensions)?e.dimensions:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),o=!!r&&i.length>0,[s,c]=X.useState({status:`idle`,rows:[]}),l=X.useCallback(async()=>{if(o){c({status:`loading`,rows:[]});try{let n=await t.queryDataset(e,{dimensions:a,measures:i});c({status:`ok`,rows:Array.isArray(n?.rows)?n.rows:[],fields:Array.isArray(n?.fields)?n.fields:[],object:n?.object})}catch(e){c({status:`error`,rows:[],error:String(e?.message??e)})}}},[t,e,a,i,o]),u=`${r??``}|${a.join(`,`)}|${i.join(`,`)}`;if(X.useEffect(()=>{o&&l()},[u]),!r)return(0,Y.jsx)(Z,{children:(0,Y.jsx)(_l,{icon:(0,Y.jsx)(Jt,{className:`h-8 w-8`}),title:`Pick a base object`,description:"Set the dataset's `object` to preview it against live data."})});if(i.length===0)return(0,Y.jsx)(Z,{children:(0,Y.jsx)(_l,{icon:(0,Y.jsx)(Jt,{className:`h-8 w-8`}),title:`Add a measure`,description:`A dataset needs at least one measure (e.g. revenue = sum(amount)) to preview.`})});let{measureField:d,headerLabel:f}=x(s.status===`ok`?s.fields:void 0,s.status===`ok`?s.object:void 0,n),m=[...a,...i],h=e=>{let t=d(e)?.format;return typeof t==`string`&&t.includes(`%`)},g=i.filter(h),_=g.length>0&&g.length<i.length;return(0,Y.jsx)(Z,{hint:`dataset · ${r}${a.length?` · by `+a.join(`, `):``}`,children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>void l(),disabled:s.status===`loading`,className:`inline-flex items-center gap-1.5 rounded-md border bg-background px-3 py-1.5 text-xs font-medium hover:bg-accent disabled:opacity-50`,children:[s.status===`loading`?(0,Y.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,Y.jsx)(Jt,{className:`h-3.5 w-3.5`}),`Run preview`]}),(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[i.length,` measure`,i.length===1?``:`s`,` · `,a.length,` dimension`,a.length===1?``:`s`]})]}),s.status===`error`&&(0,Y.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:[(0,Y.jsx)(I,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,Y.jsx)(`span`,{className:`break-words`,children:s.error})]}),s.status===`ok`&&s.rows.length===0&&(0,Y.jsx)(_l,{icon:(0,Y.jsx)(Jt,{className:`h-8 w-8`}),title:`No rows`,description:`The dataset returned no rows for the current scope.`}),s.rows.length>0&&a.length>=1&&(0,Y.jsx)(Q,{fallbackHint:`Couldn't render the chart for this result — the table below still shows the data.`,children:(0,Y.jsx)(X.Suspense,{fallback:(0,Y.jsx)(`div`,{className:`h-[260px] flex items-center justify-center text-xs text-muted-foreground`,children:(0,Y.jsx)(U,{className:`h-4 w-4 animate-spin`})}),children:(0,Y.jsxs)(`div`,{className:`rounded-md border p-2`,children:[(0,Y.jsx)(lh,{schema:{data:s.rows,xAxisKey:a[0],chartType:_?`combo`:`bar`,series:i.map(e=>({dataKey:e,label:f(e),chartType:_&&h(e)?`line`:`bar`}))}}),_&&(0,Y.jsxs)(`p`,{className:`mt-1 px-1 text-[10px] text-muted-foreground`,children:[`Ratio measures (`,g.map(f).join(`, `),`) use the right axis.`]})]})})}),s.rows.length>0&&(0,Y.jsx)(`div`,{className:`overflow-auto max-h-[60vh] rounded-md border`,children:(0,Y.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,Y.jsx)(`thead`,{className:`bg-muted/40`,children:(0,Y.jsx)(`tr`,{children:m.map(e=>(0,Y.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:f(e)},e))})}),(0,Y.jsx)(`tbody`,{children:s.rows.map((e,t)=>(0,Y.jsx)(`tr`,{className:`border-t`,children:m.map(t=>(0,Y.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:i.includes(t)?y(e[t],d(t)?.format,d(t)?.currency):v(e[t])},t))},t))})]})})]})})}function dh(e){return Array.isArray(e)?e.map((e,t)=>{if(!e||typeof e!=`object`)return null;let n=String(e.key??``).trim(),r=String(e.label??n??``).trim();return!n&&!r?null:{g:{key:n||`(no key)`,label:r||n||`(unnamed)`,order:typeof e.order==`number`?e.order:void 0,include:fh(e.include),package:typeof e.package==`string`?e.package:void 0,pages:ph(e.pages)},i:t}}).filter(e=>e!==null).sort((e,t)=>(e.g.order??0)-(t.g.order??0)||e.i-t.i).map(e=>e.g):[]}function fh(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`&&typeof e.tag==`string`)return{tag:e.tag}}function ph(e){if(Array.isArray(e))return e.map(e=>typeof e==`string`?{literal:e}:e&&typeof e==`object`?{doc:typeof e.doc==`string`?e.doc:void 0,href:typeof e.href==`string`?e.href:void 0,label:typeof e.label==`string`?e.label:void 0,badge:typeof e.badge==`string`?e.badge:void 0,icon:typeof e.icon==`string`?e.icon:void 0}:null).filter(e=>e!==null)}function mh(e){return e===`public`?{icon:(0,Y.jsx)(Tr,{className:`h-3 w-3`}),label:`Public`,tone:`text-emerald-700 bg-emerald-50 border-emerald-200`}:e&&typeof e==`object`&&typeof e.profile==`string`?{icon:(0,Y.jsx)(lt,{className:`h-3 w-3`}),label:`Profile: ${e.profile}`,tone:`text-amber-800 bg-amber-50 border-amber-200`}:{icon:(0,Y.jsx)(gr,{className:`h-3 w-3`}),label:`Org`,tone:`text-muted-foreground bg-muted/40 border-muted`}}function hh({name:e,draft:t}){let n=t,r=String(n.name??e??``).trim(),i=String(n.label??r),a=typeof n.description==`string`?n.description:``,o=typeof n.slug==`string`?n.slug:``,s=X.useMemo(()=>dh(n.groups),[n.groups]),c=mh(n.audience);return r?(0,Y.jsx)(Z,{hint:`book · spine`,toolbar:(0,Y.jsxs)(`a`,{href:`/meta/book/${encodeURIComponent(r)}/tree`,target:`_blank`,rel:`noreferrer`,className:`text-xs text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,title:`Open the live-resolved navigation tree (actual docs per group)`,children:[`Resolved tree `,(0,Y.jsx)(Re,{className:`h-3 w-3`})]}),children:(0,Y.jsx)(Q,{children:(0,Y.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(yr,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:i}),(0,Y.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 rounded-full border px-2 py-0.5 text-[10px] font-medium ${c.tone}`,children:[c.icon,c.label]})]}),(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:r}),o&&(0,Y.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Slug: `,(0,Y.jsx)(`code`,{className:`font-mono`,children:o})]}),a&&(0,Y.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1.5`,children:a})]}),s.length===0?(0,Y.jsx)(_l,{icon:(0,Y.jsx)(pe,{className:`h-8 w-8 opacity-50`}),title:`No groups yet`,tone:`warn`,description:(0,Y.jsxs)(Y.Fragment,{children:[`A book needs at least one group in its `,(0,Y.jsx)(`code`,{children:`groups`}),` spine. Each group derives its members from an `,(0,Y.jsx)(`code`,{children:`include`}),` rule (a glob like`,` `,(0,Y.jsx)(`code`,{children:`crm_guide_*`}),` or a `,(0,Y.jsx)(`code`,{children:`{ tag }`}),`).`]})}):(0,Y.jsx)(`div`,{className:`space-y-2`,children:s.map((e,t)=>(0,Y.jsx)(gh,{group:e},`${e.key}-${t}`))})]})})}):(0,Y.jsx)(Z,{hint:`book`,children:(0,Y.jsx)(_l,{icon:(0,Y.jsx)(yr,{className:`h-8 w-8 opacity-50`}),title:`Name your book`,description:`Enter a name in the Form tab to start authoring the documentation spine.`})})}function gh({group:e}){return(0,Y.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 border-b bg-muted/20 px-3 py-2`,children:[(0,Y.jsx)(pe,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label}),(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.key}),typeof e.order==`number`&&(0,Y.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,title:`Order within the book`,children:[`#`,e.order]}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[e.package&&(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] text-muted-foreground`,title:`Membership rule is scoped to this package`,children:[(0,Y.jsx)(xn,{className:`h-3 w-3`}),e.package]}),(0,Y.jsx)(_h,{include:e.include,hasOverride:!!e.pages?.length})]})]}),(0,Y.jsx)(`div`,{className:`px-3 py-2`,children:e.pages?.length?(0,Y.jsx)(`ol`,{className:`space-y-1`,children:e.pages.map((e,t)=>(0,Y.jsx)(vh,{node:e},t))}):e.include==null?(0,Y.jsxs)(`div`,{className:`text-[11px] text-amber-700 italic`,children:[`No `,(0,Y.jsx)(`code`,{children:`include`}),` rule and no explicit `,(0,Y.jsx)(`code`,{children:`pages`}),` — this group matches nothing unless docs set `,(0,Y.jsxs)(`code`,{children:[`group: "`,e.key,`"`]}),`.`]}):(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`Members derived from the rule above — resolved against the live doc set.`})})]})}function _h({include:e,hasOverride:t}){return e==null?t?(0,Y.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,title:`Curated order via explicit pages`,children:`curated`}):null:typeof e==`string`?(0,Y.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded border border-primary/30 bg-primary/5 px-1.5 py-0.5 font-mono text-[10px] text-foreground`,title:`Glob over doc names`,children:e}):(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border border-primary/30 bg-primary/5 px-1.5 py-0.5 text-[10px] text-foreground`,title:`Match by doc tag`,children:[(0,Y.jsx)(qn,{className:`h-3 w-3`}),e.tag]})}function vh({node:e}){if(e.literal===`---`)return(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 text-[10px] uppercase tracking-wider text-muted-foreground/60`,children:[(0,Y.jsx)(_t,{className:`h-3 w-3`}),`separator`]});if(e.literal===`...`)return(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 text-[11px] italic text-muted-foreground`,children:[(0,Y.jsx)(Ht,{className:`h-3.5 w-3.5`}),`…rest (remaining matched docs, by order)`]});let t=!!e.href,n=e.literal??e.doc,r=e.label??n??e.href??`(empty)`;return(0,Y.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[t?(0,Y.jsx)(Re,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,Y.jsx)(Ce,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,Y.jsx)(`span`,{className:`truncate`,children:r}),!t&&n&&e.label&&(0,Y.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:n}),e.badge&&(0,Y.jsx)(`span`,{className:`rounded-full border border-primary/30 bg-primary/5 px-1.5 py-0.5 text-[9px] uppercase tracking-wider text-foreground`,children:e.badge}),t&&(0,Y.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),className:`ml-auto font-mono text-[10px] text-muted-foreground hover:text-foreground truncate max-w-[40%]`,title:e.href,children:e.href})]})}function yh(){qs(`page`,gu),qs(`view`,bu),qs(`dashboard`,Su),qs(`report`,Tu),qs(`app`,Ru),qs(`action`,Yp),qs(`object`,ad),qs(`datasource`,Qm),qs(`validation`,ih),qs(`dataset`,uh),qs(`email_template`,ld),qs(`translation`,Sm),qs(`book`,hh),qs(`flow`,vp),qs(`job`,gm),qs(`agent`,bp),qs(`tool`,Np),qs(`skill`,Em),qs(`permission`,Bp),qs(`profile`,Bp),qs(`role`,Tm)}var bh=new Set([`object`,`object-field`,`flow`,`role`,`node`,`user`,`team`,`queue`,`department`,`connector`,`email-template`]);function xh(e){let t=e.xRef;if(!t||typeof t!=`object`)return;let n=typeof t.objectSource==`string`&&t.objectSource?{objectSource:t.objectSource}:{};if(typeof t.kindFrom==`string`&&t.kindFrom&&t.map&&typeof t.map==`object`){let e={};for(let[n,r]of Object.entries(t.map))typeof r==`string`&&bh.has(r)&&(e[n]=r);return Object.keys(e).length===0?void 0:{kindFrom:t.kindFrom,map:e,...n}}if(typeof t.kind==`string`&&bh.has(t.kind))return{kind:t.kind,...n}}function Sh(e){let t=e.replace(/[_-]+/g,` `).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).trim();return t?t.split(/\s+/).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `):e}function Ch(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function wh(e){if(Array.isArray(e.type))return e.type.find(e=>e!==`null`);if(typeof e.type==`string`)return e.type;if(Array.isArray(e.enum))return`string`;if(e.properties)return`object`;if(e.items)return`array`}function Th(e){return e.filter(e=>typeof e==`string`).map(e=>({value:e,label:Sh(e)}))}function Eh(e){if(!(e.default===void 0||e.default===null)){if(typeof e.default==`boolean`||typeof e.default==`number`)return String(e.default);if(typeof e.default==`string`)return e.default}}function Dh(e){if(Array.isArray(e.enum))return`select`;let t=wh(e);if(t===`boolean`)return`boolean`;if(t===`number`||t===`integer`)return`number`;if(t===`string`)return e.format===`multiline`?`textarea`:`text`}function Oh(e){let t=e.properties??{},n=[];for(let[e,r]of Object.entries(t)){if(!Ch(r))continue;let t=wh(r),i,a,o=xh(r);o?i=`reference`:Array.isArray(r.enum)?(i=`select`,a=Th(r.enum)):i=t===`boolean`?`boolean`:`text`,n.push({key:e,label:r.title||Sh(e),kind:i,...a?{options:a}:{},...o?{ref:o}:{},...r.description?{placeholder:r.description}:{}})}return n}function kh(e,t){return{label:e.title||Sh(t),...e.description?{help:e.description}:{},...Eh(e)?{defaultValue:Eh(e)}:{}}}function Ah(e){if(!Ch(e)||wh(e)!==`object`||!Ch(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!Ch(r))continue;let e=wh(r);if(e===`array`){let e=Ch(r.items)?r.items:void 0,i=e?wh(e):void 0;e&&i===`object`&&Ch(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:Oh(e),...kh(r,n)}):i===`string`&&t.push({id:n,path:[`config`,n],kind:`stringList`,...kh(r,n)});continue}if(e===`object`&&Ch(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>Ch(e)),i=e.some(([e,t])=>e===`enabled`&&wh(t)===`boolean`);for(let[a,o]of e){let e=o,s=xh(e),c=s?`reference`:Dh(e);if(!c)continue;let l=`${n}.${a}`,u=i&&a===`enabled`,d={id:l,path:[`config`,n,a],kind:c,...u?{label:r.title||Sh(n),...r.description?{help:r.description}:{},...Eh(e)?{defaultValue:Eh(e)}:{}}:kh(e,a),...s?{ref:s}:{},...c===`select`&&Array.isArray(e.enum)?{options:Th(e.enum)}:{},...i&&!u?{showWhen:{field:`${n}.enabled`,equals:[`true`]}}:{}};t.push(d)}continue}let i=xh(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,...kh(r,n)});continue}let a=Dh(r);a&&t.push({id:n,path:[`config`,n],kind:a,...kh(r,n),...a===`select`&&Array.isArray(r.enum)?{options:Th(r.enum)}:{}})}return t}function jh(e,t){return t===`template`?`{${e}}`:e}function Mh(e,t,n,r,i){let a=jh(n,t),o=Math.min(Math.max(r,0),e.length),s=Math.min(Math.max(i,0),e.length),c=Math.min(o,s),l=Math.max(o,s);return{next:e.slice(0,c)+a+e.slice(l),caret:c+a.length}}var Nh=`Insert a reference`,Ph=`Search references…`,Fh=`No matching references.`;function Ih({value:e,onValueChange:t,onBlur:n,onKeyDown:r,mode:i,groups:a,placeholder:o,disabled:s,multiline:c,rows:l=4,mono:u,className:d}){let f=X.useRef(null),p=X.useRef({start:0,end:0}),[m,h]=X.useState(!1),g=e=>{f.current=e},_=()=>{let t=f.current;t&&(p.current={start:t.selectionStart??e.length,end:t.selectionEnd??e.length})},v=n=>{let{next:r,caret:a}=Mh(e,i,n,p.current.start,p.current.end);t(r),h(!1),requestAnimationFrame(()=>{let e=f.current;if(e){e.focus();try{e.setSelectionRange(a,a)}catch{}p.current={start:a,end:a}}})},y=a.some(e=>e.refs.length>0),b={value:e,onChange:e=>t(e.target.value),onBlur:n,onKeyDown:r,onSelect:_,onKeyUp:_,onClick:_,placeholder:o,disabled:s};return(0,Y.jsxs)(`div`,{className:B(`relative`,d),children:[c?(0,Y.jsx)(`textarea`,{ref:g,...b,rows:l,className:`w-full rounded border bg-background px-2 py-1.5 pr-8 font-mono text-xs`}):(0,Y.jsx)(V,{ref:g,...b,className:B(`h-8 pr-8 text-sm`,u&&`font-mono`)}),y&&!s&&(0,Y.jsxs)(jn,{open:m,onOpenChange:h,children:[(0,Y.jsx)(Qn,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,"aria-label":Nh,title:Nh,onMouseDown:_,className:`absolute right-1 top-1 inline-flex h-6 w-6 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,Y.jsx)($t,{className:`h-3.5 w-3.5`})})}),(0,Y.jsx)(en,{align:`end`,className:`w-72 p-0`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,Y.jsxs)(Se,{children:[(0,Y.jsx)(zr,{placeholder:Ph,className:`h-9`}),(0,Y.jsxs)(Ot,{children:[(0,Y.jsx)(We,{children:Fh}),a.map(e=>(0,Y.jsx)(dt,{heading:e.label,children:e.refs.map(t=>(0,Y.jsxs)(ae,{value:`${t.token} ${t.label} ${t.detail??``}`,onSelect:()=>v(t.token),className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`truncate font-mono text-xs`,children:jh(t.token,i)}),t.detail&&(0,Y.jsx)(`span`,{className:`shrink-0 truncate text-[10px] text-muted-foreground`,children:t.detail})]},`${e.id}:${t.token}`))},e.id))]})]})})]})]})}function Lh({value:e,role:t,scopeGroups:n}){let r=t===`template`?null:bf(t,e);if(r)return(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:r.message});let i=n&&n.length>0?pf(n.flatMap(e=>e.refs)):null,a=i?gf(e,t,i):[];return a.length>0?(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:_f(a)}):null}function Rh(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function zh(e){return e==null?``:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Bh(e){let t=e.trim();if(t===``)return``;if(t===`true`)return!0;if(t===`false`)return!1;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);if(t.startsWith(`{`)&&t.endsWith(`}`)||t.startsWith(`[`)&&t.endsWith(`]`))try{return JSON.parse(t)}catch{return e}return e}function Vh(e){return Array.isArray(e)?e.filter(e=>Rh(e)).map(e=>{let t=e.variable??e.name??e.key;return[typeof t==`string`?t:``,e.value]}):Rh(e)?Object.entries(e):[]}function Hh(e,t){let n=[...t];return Vh(e).map(([e,t])=>{let r=ui(`kv`,n);return n.push(r),{id:r,key:e,raw:zh(t)}})}function Uh(e,t){let n=new Set;if(t){let t=[];for(let r of e){let e=r.key.trim();!e||n.has(e)||(n.add(e),t.push({variable:e,value:Bh(r.raw)}))}return t}let r={};for(let t of e){let e=t.key.trim();!e||n.has(e)||(n.add(e),r[e]=Bh(t.raw))}return r}function Wh(e){if(Array.isArray(e))return JSON.stringify(e);let t=e??{},n=Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{});return JSON.stringify(n)}function Gh({label:e,value:t,onCommit:n,disabled:r,help:i,addLabel:a,keyLabel:o,valueLabel:s,removeLabel:c,emptyLabel:l,scopeGroups:u}){let d=Array.isArray(t),f=X.useMemo(()=>Wh(Uh(Hh(t,[]),d)),[t,d]),[p,m]=X.useState(()=>Hh(t,[])),h=X.useRef(f);X.useEffect(()=>{f!==h.current&&(m(Hh(t,[])),h.current=f)},[f,t]);let g=e=>{let t=Uh(e,d);h.current=Wh(t),n((Array.isArray(t)?t.length===0:Object.keys(t).length===0)?void 0:t)},_=(e,t)=>{m(n=>n.map(n=>n.id===e?{...n,...t}:n))},v=()=>{m(e=>[...e,{id:ui(`kv`,e.map(e=>e.id)),key:``,raw:``}])},y=e=>{m(t=>{let n=t.filter(t=>t.id!==e);return g(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[p.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:l}),p.map(e=>(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(V,{value:e.key,onChange:t=>_(e.id,{key:t.target.value}),onBlur:()=>g(p),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:o,disabled:r,className:`h-8 flex-1 font-mono text-xs`}),(0,Y.jsx)(Ih,{mode:`template`,value:e.raw,onValueChange:t=>_(e.id,{raw:t}),onBlur:()=>g(p),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},groups:u??[],placeholder:s,disabled:r,className:`flex-1`}),(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>y(e.id),disabled:r,"aria-label":c,title:c,children:(0,Y.jsx)(Qe,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(Lh,{value:e.raw,role:`template`,scopeGroups:u})]},e.id))]}),(0,Y.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:v,disabled:r,children:[(0,Y.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),a]}),i&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:i})]})}function Kh(e,t){let n=[...t];return e.map(e=>{let t=ui(`sl`,n);return n.push(t),{id:t,value:e}})}function qh(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function Jh({label:e,value:t,onCommit:n,disabled:r,addLabel:i,itemLabel:a,removeLabel:o,emptyLabel:s}){let c=X.useMemo(()=>Array.isArray(t)?t.map(e=>String(e)):[],[t]),[l,u]=X.useState(()=>Kh(c,[])),d=X.useRef(JSON.stringify(c));X.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(Kh(c,[])),d.current=e)},[c]);let f=e=>{let t=qh(e);d.current=JSON.stringify(t),n(t.length?t:void 0)},p=(e,t)=>{u(n=>n.map(n=>n.id===e?{...n,value:t}:n))},m=()=>{u(e=>[...e,{id:ui(`sl`,e.map(e=>e.id)),value:``}])},h=e=>{u(t=>{let n=t.filter(t=>t.id!==e);return f(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[l.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),l.map(e=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(V,{value:e.value,onChange:t=>p(e.id,t.target.value),onBlur:()=>f(l),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:a,disabled:r,className:`h-8 flex-1 text-xs`}),(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>h(e.id),disabled:r,"aria-label":o,title:o,children:(0,Y.jsx)(Qe,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,Y.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:m,disabled:r,children:[(0,Y.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}var Yh={object:`object`,flow:`flow`,role:`role`,user:`user`,team:`team`,queue:`queue`,department:`department`,connector:`connector`,"email-template":`email_template`};function Xh(e,t){if(e){if(e.kind)return{kind:e.kind,objectSource:e.objectSource,connectorSource:e.connectorSource};if(e.kindFrom&&e.map){let n=t(e.kindFrom),r=typeof n==`string`?e.map[n]:void 0;if(r)return{kind:r,objectSource:e.objectSource,connectorSource:e.connectorSource}}}}function Zh(e,t){let n=e?.config;if(!n||typeof n!=`object`||Array.isArray(n))return;let r=n[t];return typeof r==`string`&&r?r:void 0}function Qh(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?Zh((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):Zh(n.node,r)}function $h(e,t,n){if(e!==`connector-action`)return;let r=n.node?.connectorConfig;if(!r||typeof r!=`object`||Array.isArray(r))return;let i=r[t||`connectorId`];return typeof i==`string`&&i?i:void 0}function eg(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e.key==`string`&&!!e.key).map(e=>({value:e.key,label:typeof e.label==`string`&&e.label&&e.label!==e.key?`${e.label} (${e.key})`:e.key})):[]}function tg(e){let t=ti(),[n,r]=X.useState({options:[],loading:!!e});return X.useEffect(()=>{if(!e){r({options:[],loading:!1});return}let n=!1;return r(e=>({...e,loading:!0})),t.list(e).then(e=>{if(n)return;let t=(Array.isArray(e)?e:[]).filter(e=>e&&typeof e.name==`string`&&e.name).map(e=>({value:String(e.name),label:typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:String(e.name)}));r({options:t,loading:!1})}).catch(()=>{n||r({options:[],loading:!1})}),()=>{n=!0}},[t,e]),n}function ng(e){let[t,n]=X.useState({options:[],loading:!!e});return X.useEffect(()=>{if(!e){n({options:[],loading:!1});return}let t=!1;return n(e=>({...e,loading:!0})),fetch(`/api/v1/automation/connectors`,{credentials:`include`,headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(r=>{if(t)return;let i=r?.data?.connectors??r?.connectors??[],a=Array.isArray(i)?i.find(t=>t?.name===e):void 0;n({options:eg(a?.actions),loading:!1})}).catch(()=>{t||n({options:[],loading:!1})}),()=>{t=!0}},[e]),t}function rg({resolved:e,value:t,onCommit:n,onBlur:r,disabled:i,placeholder:a,context:o,showHint:s=!0}){let c=X.useId(),l=o??{draft:{},node:null},u=e?.kind,d=e?Qh(e.kind,e.objectSource,l):void 0,{fields:f}=ki(u===`object-field`?d:void 0),p=e?$h(e.kind,e.connectorSource,l):void 0,{options:m}=ng(u===`connector-action`?p:void 0),h=u&&u!==`object-field`&&u!==`node`&&u!==`connector-action`?Yh[u]:void 0,{options:g}=tg(h),_=X.useMemo(()=>{if(u===`object-field`)return f.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));if(u===`connector-action`)return m;if(u===`node`){let e=Array.isArray(l.draft.nodes)?l.draft.nodes:[],t=typeof l.node?.id==`string`?l.node.id:void 0;return e.filter(e=>typeof e?.id==`string`&&e.id&&e.id!==t).map(e=>{let t=String(e.id);return{value:t,label:typeof e.label==`string`&&e.label?`${e.label} (${t})`:t}})}return h?g:[]},[u,h,f,m,g,l.draft,l.node]),v=u===`object-field`&&!d,y=u===`connector-action`&&!p;return(0,Y.jsxs)(`div`,{className:`w-full space-y-1`,children:[(0,Y.jsx)(V,{list:_.length?c:void 0,value:t==null?``:String(t),onChange:e=>n(e.target.value),onBlur:r,placeholder:a,disabled:i,className:`h-8 text-sm`}),_.length>0&&(0,Y.jsx)(`datalist`,{id:c,children:_.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))}),s&&u===`object-field`&&d&&(0,Y.jsxs)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:[`Fields of `,d,`.`]}),s&&v&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Set the flow’s trigger object (on the Start node) to list fields.`}),s&&u===`connector-action`&&p&&(0,Y.jsxs)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:[`Actions of `,p,`.`]}),s&&y&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Choose a Connector above to list its actions.`})]})}function ig({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=Xh(e.ref,e=>Zh(a,e));return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(rg,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function ag(e,t){let n=[];return e.map(e=>{let r=ui(`ol`,n);n.push(r);let i={};for(let n of t){let t=e[n.key];n.kind===`boolean`?i[n.key]=t===!0:t==null?i[n.key]=``:i[n.key]=String(t)}return{id:r,values:i}})}function og(e,t){let n=[];for(let r of e){let e={},i=!1;for(let n of t){let t=r.values[n.key];n.kind===`boolean`?t===!0&&(e[n.key]=!0,i=!0):typeof t==`string`&&t.trim()!==``&&(e[n.key]=t.trim(),i=!0)}i&&n.push(e)}return n}function sg({label:e,columns:t,value:n,onCommit:r,disabled:i,addLabel:a,removeLabel:o,emptyLabel:s,context:c,scopeGroups:l}){let u=X.useMemo(()=>Array.isArray(n)?n.filter(e=>e&&typeof e==`object`):[],[n]),[d,f]=X.useState(()=>ag(u,t)),p=X.useRef(JSON.stringify(u));X.useEffect(()=>{let e=JSON.stringify(u);e!==p.current&&(f(ag(u,t)),p.current=e)},[u,t]);let m=e=>{let n=og(e,t);p.current=JSON.stringify(n),r(n.length?n:void 0)},h=(e,t,n)=>{f(r=>r.map(r=>r.id===e?{...r,values:{...r.values,[t]:n}}:r))},g=()=>{let e={};for(let n of t)e[n.key]=n.kind===`boolean`?!1:``;f(t=>[...t,{id:ui(`ol`,t.map(e=>e.id)),values:e}])},_=e=>{f(t=>{let n=t.filter(t=>t.id!==e);return m(n),n})};return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[d.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),d.map(e=>(0,Y.jsxs)(`div`,{className:`rounded border bg-muted/30 p-2`,children:[(0,Y.jsx)(`div`,{className:`mb-1 flex justify-end`,children:(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-muted-foreground`,onClick:()=>_(e.id),disabled:i,"aria-label":o,title:o,children:(0,Y.jsx)(Qe,{className:`h-3.5 w-3.5`})})}),(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:t.map(t=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(z,{className:`w-24 shrink-0 text-[11px] text-muted-foreground`,children:t.label}),t.kind===`boolean`?(0,Y.jsx)(ot,{checked:e.values[t.key]===!0,onCheckedChange:n=>{f(r=>{let i=r.map(r=>r.id===e.id?{...r,values:{...r.values,[t.key]:n===!0}}:r);return m(i),i})},disabled:i}):t.kind===`reference`?(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsx)(rg,{resolved:Xh(t.ref,t=>e.values[t]),value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onCommit:n=>h(e.id,t.key,typeof n==`string`?n:``),onBlur:()=>m(d),placeholder:t.placeholder,disabled:i,context:c,showHint:!1})}):t.kind===`expression`?(0,Y.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,Y.jsx)(Ih,{mode:`expression`,mono:!0,value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onValueChange:n=>h(e.id,t.key,n),onBlur:()=>m(d),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},groups:l??[],placeholder:t.placeholder,disabled:i}),(0,Y.jsx)(Lh,{value:typeof e.values[t.key]==`string`?e.values[t.key]:``,role:`predicate`,scopeGroups:l})]}):(0,Y.jsx)(V,{value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onChange:n=>h(e.id,t.key,n.target.value),onBlur:()=>m(d),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:t.placeholder,disabled:i,className:`h-8 flex-1 text-xs`})]},t.key))})]},e.id))]}),(0,Y.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:g,disabled:i,children:[(0,Y.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}function cg({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a,scopeGroups:o}){let s=e.refMode??(e.kind===`expression`?`expression`:`template`),c=(()=>{switch(e.kind){case`reference`:return(0,Y.jsx)(ig,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,Y.jsx)(Gh,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:J(`engine.inspector.flowNode.kv.add`,i),keyLabel:J(`engine.inspector.flowNode.kv.key`,i),valueLabel:J(`engine.inspector.flowNode.kv.value`,i),removeLabel:J(`engine.inspector.flowNode.kv.remove`,i),emptyLabel:J(`engine.inspector.flowNode.kv.empty`,i),scopeGroups:o});case`stringList`:return(0,Y.jsx)(Jh,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:J(`engine.inspector.flowNode.list.add`,i),itemLabel:J(`engine.inspector.flowNode.list.item`,i),removeLabel:J(`engine.inspector.flowNode.list.remove`,i),emptyLabel:J(`engine.inspector.flowNode.list.empty`,i)});case`objectList`:return(0,Y.jsx)(sg,{label:e.label,columns:e.columns??[],value:t,onCommit:e=>n(e),disabled:r,addLabel:J(`engine.inspector.flowNode.list.add`,i),removeLabel:J(`engine.inspector.flowNode.list.remove`,i),emptyLabel:J(`engine.inspector.flowNode.list.empty`,i),context:a,scopeGroups:o});case`number`:return(0,Y.jsx)(ai,{label:e.label,value:typeof t==`number`?t:t!=null&&t!==``?Number(t):void 0,placeholder:e.placeholder,onCommit:e=>n(e),disabled:r});case`boolean`:return(0,Y.jsx)(K,{label:e.label,value:t===!0,onCommit:e=>n(e),disabled:r});case`select`:return(0,Y.jsx)(W,{label:e.label,value:t==null?``:String(t),options:e.options??[],onCommit:e=>n(e),disabled:r});case`textarea`:return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(Ih,{multiline:!0,rows:4,mode:s,value:t==null?``:String(t),onValueChange:e=>n(e),groups:o??[],placeholder:e.placeholder,disabled:r})]});default:return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e.label}),(0,Y.jsx)(Ih,{mode:s,mono:e.kind===`expression`,value:t==null?``:String(t),onValueChange:e=>n(e),groups:o??[],placeholder:e.placeholder,disabled:r})]})}})(),l=e.kind===`expression`?bf(`predicate`,t):null,u=e.kind===`expression`?`predicate`:s===`template`&&(e.kind===`text`||e.kind===`textarea`)?`template`:null,d=!l&&u&&o&&o.length>0?gf(t,u,pf(o.flatMap(e=>e.refs))):[];return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[c,l&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:l.message}),!l&&d.length>0&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:_f(d)}),e.help&&!l&&d.length===0&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:e.help})]})}var lg=[`variables`,`outputs`,`loop`,`trigger`],ug={variables:`Flow variables`,outputs:`Upstream outputs`,loop:`Loop item`,trigger:`Trigger record`};function dg(e,t){let n=X.useMemo(()=>lf(e??{},t),[e,t]),{fields:r,loading:i}=ki(n.trigger?.objectName);return X.useMemo(()=>{let e=[...n.refs];n.trigger&&e.push(...uf(n.trigger,r));let t=new Set,a=e.filter(e=>t.has(e.token)?!1:(t.add(e.token),!0));return{groups:lg.map(e=>({id:e,label:ug[e],refs:a.filter(t=>t.group===e)})).filter(e=>e.refs.length>0),refs:a,loading:!!n.trigger&&i,isEmpty:a.length===0}},[n,r,i])}function fg(e,t,n){let r=Array.isArray(t)?t:[],i=0;return n.map(t=>{if(t.source!==e||t.type===`fault`||t.type===`back`)return t;let n=r[i++];if(!n||typeof n!=`object`)return t;let a=typeof n.expression==`string`?n.expression.trim():``,o=typeof n.label==`string`?n.label.trim():``,s={...t};return o?s.label=o:delete s.label,a&&a!==`true`?(s.condition=a,delete s.isDefault):a===`true`?(s.isDefault=!0,delete s.condition):(delete s.condition,delete s.isDefault),s})}function pg(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function mg(e,t,n){let[r,...i]=t,a={...e};if(i.length===0)n==null||n===``?delete a[r]:a[r]=n;else{let e=a[r],t=mg(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function hg({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=Array.isArray(t.nodes)?t.nodes:[],s=o.findIndex(t=>t?.id===e.id),c=s>=0?o[s]:null,l=Bd(),{groups:u}=dg(t,c?.id),d=X.useMemo(()=>{let e=c?.type?l[c.type]:void 0;return(e===void 0?null:Ah(e))??Yd(c?.type)},[l,c?.type]),f=pg(c),p=d.filter(e=>Qd(e,c,d)),m=X.useMemo(()=>{let e=Array.isArray(t.variables)?t.variables:[],n={};for(let t of e)t&&typeof t.name==`string`&&(n[t.name]=t.defaultValue);return n},[t]),h=X.useMemo(()=>{let e=new Set;for(let t of d){let n=Zd(t);n&&e.add(n),t.fallbackPath&&t.fallbackPath.length>=2&&t.fallbackPath[0]===`config`&&e.add(t.fallbackPath[1])}return e},[d]),g=X.useMemo(()=>{let e=Object.fromEntries(Object.entries(f).filter(([e])=>!h.has(e)));return Object.keys(e).length?JSON.stringify(e,null,2):``},[c,h]),[_,v]=X.useState(g),[y,b]=X.useState(null),[x,S]=X.useState(g.trim()!==``),[C,w]=X.useState(!1);if(X.useEffect(()=>{v(g),b(null),S(g.trim()!==``),w(!1)},[g]),!c)return(0,Y.jsx)(ji,{kindLabel:J(`engine.inspector.flowNode.kind`,i),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.flowNode.close`,i),children:(0,Y.jsx)(oi,{message:e.id})});let T=e=>{n({nodes:si(o,s,{...c,...e})})},E=g.trim()!==``,D=c.type===`screen`||c.type===`user_task`,O=(e,r)=>{let i=e.path,a=mg(c,i,r);e.fallbackPath&&(a=mg(a,e.fallbackPath,void 0));let l={nodes:si(o,s,a)};if(c.type===`decision`&&i.length===2&&i[0]===`config`&&i[1]===`conditions`){let e=Array.isArray(t.edges)?t.edges:[];l.edges=fg(c.id,r,e)}n(l)},k=()=>{try{let e=_.trim()===``?{}:JSON.parse(_);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Must be a JSON object`);let t=Object.fromEntries(Object.entries(f).filter(([e])=>h.has(e))),r=Object.fromEntries(Object.entries(e).filter(([e])=>!h.has(e))),i={...t,...r};b(null);let a={...c};Object.keys(i).length===0?delete a.config:a.config=i,n({nodes:si(o,s,a)})}catch(e){b(String(e.message))}},A=()=>{n({nodes:si(o,s,null)}),r()},j=$d.includes(c.type)?[...$d]:[...$d,c.type??``].filter(Boolean);return(0,Y.jsxs)(ji,{kindLabel:J(`engine.inspector.flowNode.kind`,i),title:c.label||c.id,onClose:r,closeLabel:J(`engine.inspector.flowNode.close`,i),footer:(0,Y.jsx)(hi,{label:J(`engine.inspector.flowNode.remove`,i),onClick:A,disabled:a}),children:[(0,Y.jsx)(G,{label:J(`engine.inspector.flowNode.id`,i),value:c.id,onCommit:e=>T({id:e}),disabled:a,mono:!0}),(0,Y.jsx)(G,{label:J(`engine.inspector.flowNode.label`,i),value:c.label??``,onCommit:e=>T({label:e}),disabled:a}),(0,Y.jsx)(W,{label:J(`engine.inspector.flowNode.type`,i),value:c.type,options:j.map(e=>({value:e,label:e})),onCommit:e=>T({type:e}),disabled:a}),(0,Y.jsx)(G,{label:J(`engine.inspector.flowNode.description`,i),value:c.description??``,onCommit:e=>T({description:e||void 0}),disabled:a}),d.length===0?(0,Y.jsx)(`p`,{className:`pt-1 text-xs italic text-muted-foreground`,children:J(`engine.inspector.flowNode.noConfig`,i)}):p.length>0&&(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:J(`engine.inspector.flowNode.configuration`,i)}),(0,Y.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),p.map(e=>(0,Y.jsx)(cg,{field:e,value:Xd(c,e),onCommit:t=>O(e,t),disabled:a,locale:i,context:{draft:t,node:c},scopeGroups:u},e.id)),D&&(0,Y.jsx)(ep,{node:c,variables:m,className:`mt-1`}),E||C?(0,Y.jsxs)(`details`,{className:`group rounded border bg-muted/20`,open:x,onToggle:e=>S(e.target.open),children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer select-none px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:J(`engine.inspector.flowNode.advanced`,i)}),(0,Y.jsxs)(`div`,{className:`space-y-1 border-t p-2`,children:[(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:J(`engine.inspector.flowNode.advancedHint`,i)}),(0,Y.jsx)(`textarea`,{value:_,onChange:e=>v(e.target.value),onBlur:k,disabled:a,rows:6,placeholder:`{ }`,className:`w-full rounded border bg-background px-2 py-1.5 font-mono text-xs`}),y&&(0,Y.jsx)(`div`,{className:`text-xs text-destructive`,children:y})]})]}):!a&&(0,Y.jsxs)(`button`,{type:`button`,onClick:()=>{w(!0),S(!0)},className:`inline-flex items-center gap-1 self-start text-[11px] text-muted-foreground transition-colors hover:text-foreground`,children:[(0,Y.jsx)(L,{className:`h-3 w-3`}),J(`engine.inspector.flowNode.advanced`,i)]})]})}function gg({label:e,value:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(`div`,{className:`flex h-8 items-center rounded border bg-muted/30 px-2 font-mono text-sm text-muted-foreground`,children:t})]})}function _g({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=Array.isArray(t.edges)?t.edges:[],s=o.findIndex((t,n)=>Cd(t,n)===e.id),c=s>=0?o[s]:null,{groups:l}=dg(t,c?.source);if(!c)return(0,Y.jsx)(ji,{kindLabel:J(`engine.inspector.flowEdge.kind`,i),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.flowEdge.close`,i),children:(0,Y.jsx)(oi,{message:J(`engine.inspector.flowEdge.missing`,i)})});let u=e=>{let t={...c,...e};for(let e of[`label`,`condition`,`isDefault`]){let n=t[e];(n===void 0||n===``||n===!1)&&delete t[e]}(t.type==="default"||t.type===``||t.type===void 0)&&delete t.type,n({edges:si(o,s,t)})},d=c.isDefault===!0,f=(Array.isArray(t.nodes)?t.nodes:[]).find(e=>e.id===c.source),p=f?.type===`decision`&&Array.isArray(f.config?.conditions)?f.config.conditions:[],m=e=>typeof e.expression==`string`?e.expression.trim():``,h=e=>typeof e.label==`string`?e.label.trim():``,g=(()=>{if(!p.length)return``;if(d){let e=p.findIndex(e=>{let t=m(e);return t===``||t===`true`});return e>=0?String(e):``}let e=wd(c.condition),t=e?p.findIndex(t=>m(t)===e):-1;return t<0&&c.label&&(t=p.findIndex(e=>h(e)===c.label)),t>=0?String(t):``})(),_=e=>{if(e===``)return;let t=p[Number(e)];if(!t)return;let n=m(t),r=h(t)||void 0;u(n===``||n===`true`?{isDefault:!0,condition:void 0,label:r}:{isDefault:!1,condition:n,label:r})},v=f?.type===`approval`,y=[`approve`,`reject`,`revise`],b=(()=>{let e=(c.label??``).trim().toLowerCase();return y.includes(e)?e:``})(),x=typeof c.type==`string`&&c.type||`default`;return(0,Y.jsxs)(ji,{kindLabel:J(`engine.inspector.flowEdge.kind`,i),title:e.label??`${c.source} → ${c.target}`,onClose:r,closeLabel:J(`engine.inspector.flowEdge.close`,i),footer:(0,Y.jsx)(hi,{label:J(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:si(o,s,null)}),r()},disabled:a}),children:[(0,Y.jsx)(gg,{label:J(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,Y.jsx)(gg,{label:J(`engine.inspector.flowEdge.target`,i),value:c.target}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:J(`engine.inspector.flowEdge.routing`,i)}),(0,Y.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),p.length>0&&(0,Y.jsx)(W,{label:J(`engine.inspector.flowEdge.branch`,i),value:g,options:[...p.map((e,t)=>{let n=m(e),r=h(e)||`Branch ${t+1}`,i=n===``||n===`true`?` · default`:` \u00b7 ${n}`;return{value:String(t),label:`${r}${i}`}}),{value:``,label:`— Custom —`}],onCommit:_,disabled:a}),v&&(0,Y.jsx)(W,{label:J(`engine.inspector.flowEdge.approvalBranch`,i),value:b,options:[{value:`approve`,label:J(`engine.inspector.flowEdge.branchApprove`,i)},{value:`reject`,label:J(`engine.inspector.flowEdge.branchReject`,i)},{value:`revise`,label:J(`engine.inspector.flowEdge.branchRevise`,i)},{value:``,label:J(`engine.inspector.flowEdge.branchCustom`,i)}],onCommit:e=>{e&&u({label:e})},disabled:a}),(0,Y.jsx)(G,{label:J(`engine.inspector.flowEdge.label`,i),value:c.label??``,onCommit:e=>u({label:e}),placeholder:J(`engine.inspector.flowEdge.labelHint`,i),disabled:a||d}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:J(`engine.inspector.flowEdge.condition`,i)}),(0,Y.jsx)(Ih,{mode:`expression`,mono:!0,value:wd(c.condition)??``,onValueChange:e=>u({condition:e||void 0}),groups:l,placeholder:J(`engine.inspector.flowEdge.conditionHint`,i),disabled:a||d})]}),(()=>{let e=d?null:bf(`predicate`,c.condition);if(e)return(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:e.message});let t=d?[]:gf(wd(c.condition),`predicate`,pf(l.flatMap(e=>e.refs)));return t.length>0?(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:_f(t)}):null})(),(0,Y.jsx)(K,{label:J(`engine.inspector.flowEdge.isDefault`,i),value:d,onCommit:e=>u(e?{isDefault:!0,condition:void 0,label:void 0}:{isDefault:!1}),disabled:a}),(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:J(`engine.inspector.flowEdge.hint`,i)}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:J(`engine.inspector.flowEdge.connection`,i)}),(0,Y.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),(0,Y.jsx)(W,{label:J(`engine.inspector.flowEdge.type`,i),value:x,options:[{value:`default`,label:J(`engine.inspector.flowEdge.typeDefault`,i)},{value:`conditional`,label:J(`engine.inspector.flowEdge.typeConditional`,i)},{value:`fault`,label:J(`engine.inspector.flowEdge.typeFault`,i)},{value:`back`,label:J(`engine.inspector.flowEdge.typeBack`,i)}],onCommit:e=>u({type:e}),disabled:a}),c.type===`back`&&(0,Y.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:J(`engine.inspector.flowEdge.backHint`,i)})]})}function vg(e){return e.selection.kind===`edge`?(0,Y.jsx)(_g,{...e}):(0,Y.jsx)(hg,{...e})}var yg=[`field`,`label`,`accessorKey`,`header`];function bg(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function xg(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function Sg(e){return e.field??e.accessorKey??``}function Cg(e){return e.label??e.header??Sg(e)}function wg(e){return Object.keys(e).some(e=>!yg.includes(e))}function Tg(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function Eg({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=bg(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(xg),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=X.useMemo(()=>Sa(),[]),m=Tg(c),{fields:h}=ki(m||void 0),g=d?Sg(d):``,_=X.useMemo(()=>{let e=h.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} · ${e.name}`:e.name}));return g&&!e.some(e=>e.value===g)&&e.unshift({value:g,label:`${g} (not in object)`}),e},[h,g]);if(!s||!d)return(0,Y.jsx)(ji,{kindLabel:J(`engine.inspector.viewColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.viewColumn.close`,a),children:(0,Y.jsx)(oi,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=Sg(e);return n&&!wg(e)&&!e.label&&!e.header&&r?r:e});n({[s.variant]:{...c,columns:t}})},y=e=>{let t=`field`in d||!(`accessorKey`in d)?`field`:`accessorKey`,n=`label`in d||!(`header`in d)?`label`:`header`,r={...e};`field`in e&&(r[t]=e.field,t!==`field`&&delete r.field),`label`in e&&(r[n]=e.label,n!==`label`&&delete r.label),v(si(u,s.index,{...d,...r}))};return(0,Y.jsxs)(ji,{kindLabel:J(`engine.inspector.viewColumn.kind`,a),title:Cg(d)||e.id,onClose:r,closeLabel:J(`engine.inspector.viewColumn.close`,a),headerActions:(0,Y.jsx)(Mi,{index:s.index,total:u.length,onMove:e=>{v(gi(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:Cg(d)||`columns[${e}]`})},upLabel:J(`engine.inspector.reorder.up`,a),downLabel:J(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,Y.jsx)(hi,{label:J(`engine.inspector.viewColumn.remove`,a),onClick:()=>{v(si(u,s.index,null)),r()},disabled:o}),children:[c&&(0,Y.jsx)(`div`,{className:`pb-1`,children:(0,Y.jsx)(fa,{variantKey:s.variant,schema:c,columns:l,allStrings:l.length>0&&l.every(e=>typeof e==`string`),objectName:m||void 0,selectedIndex:s.index,readOnly:o,onPatch:n,onSelectionChange:i})}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[_.length>0?(0,Y.jsx)(W,{label:J(`engine.inspector.viewColumn.accessorKey`,a),value:Sg(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,Y.jsx)(G,{label:J(`engine.inspector.viewColumn.accessorKey`,a),value:Sg(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,Y.jsx)(G,{label:J(`engine.inspector.viewColumn.header`,a),value:Cg(d)===Sg(d)?``:Cg(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(Li,{schema:p,value:d,hiddenFields:yg,readOnly:o,onChange:e=>{v(si(u,s.index,e))}})}):null]})]})}function Dg(e){let{selection:t}=e;if(t.kind===`column`)return(0,Y.jsx)(Eg,{...e});let n=ja(e.draft,t.id||void 0)??Aa(e.draft);return(0,Y.jsx)(za,{type:e.type,name:e.name,draft:e.draft,onPatch:e.onPatch,onSelectionChange:e.onSelectionChange,onClearSelection:e.onClearSelection,readOnly:e.readOnly,locale:e.locale,variantKey:n?.storeKey??`list`,familyKey:n?.familyKey??n?.storeKey??`list`,isHome:!1})}function Og(e){let t=Aa(e.draft);return(0,Y.jsx)(za,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}var kg={io:`input`,unrepresentable:`any`},Ag=new Set([`name`,`regions`,`children`]),jg,Mg=!1;function Ng(){if(jg||Mg)return jg;try{jg=C(T,kg)}catch(e){Mg=!0,typeof console<`u`&&console.warn(`[page-schema] failed to derive Page JSONSchema from spec`,e)}return jg}var Pg;function Fg(){if(Pg)return Pg;if(!(!D||typeof D!=`object`)){try{let e=JSON.parse(JSON.stringify(D));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Ag.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Pg=e}catch(e){typeof console<`u`&&console.warn(`[page-schema] failed to prune Page authoring form from spec`,e),Pg=D}return Pg}}function Ig({draft:e,onPatch:t,readOnly:n,serverSchema:r,locale:i}){let{schema:a,form:o}=X.useMemo(()=>Ti({bundledSchema:Ng(),bundledForm:Fg(),serverSchema:r,excludeFields:Ag,sectionTitle:J(`engine.inspector.moreFields`,i)}),[r,i]);return a?(0,Y.jsx)(Li,{schema:a,form:o,value:e,hiddenFields:[...Ag],readOnly:n,onChange:e=>t(e)}):(0,Y.jsx)(`p`,{className:`px-1 py-2 text-xs text-muted-foreground`,children:J(`engine.studio.inspector.noPageSchema`,i)})}var Lg=e=>(e??``).toLowerCase().startsWith(`zh`);function Rg(e){let t=e.options;return Array.isArray(t)?t.map(e=>({value:String(e?.value??``),label:typeof e?.label==`string`?e.label:void 0,color:typeof e?.color==`string`?e.color:void 0})):[]}function zg(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function Bg(e){return e===`lookup`||e===`master_detail`||e===`tree`}function Vg(e){return e===`formula`||e===`summary`}function Hg(e){return e===`number`||e===`currency`||e===`percent`}function Ug(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}function Wg(e){return e===`boolean`||e===`toggle`?`bool`:e===`number`||e===`currency`||e===`percent`?`number`:e===`select`||e===`radio`?`picklist`:[`formula`,`summary`,`autonumber`,`lookup`,`master_detail`,`tree`,`file`,`image`,`avatar`,`video`,`audio`,`signature`,`qrcode`,`composite`,`repeater`,`vector`,`multiselect`,`checkboxes`,`tags`].includes(e)?null:`text`}function Gg(e){let t=(e??``).toLowerCase().startsWith(`zh`),n=t?Ni:Ei;return Oi.flatMap(e=>e.types.map(r=>{let i=Di[r];return{value:r,label:`${n[e.category]} · ${t?i.labelZh:i.label}`}}))}function Kg({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=X.useCallback(e=>J(e,o),[o]),c=X.useMemo(()=>Gg(o),[o]),l=X.useMemo(()=>xi(t.fields),[t]),u=String(e.id),d=bi(l,u),f=d>=0?l.entries[d]:null,p=Array.isArray(t.fieldGroups)?t.fieldGroups:[],m=n_();if(!f)return(0,Y.jsx)(ji,{kindLabel:s(`designer.field.kind`),title:u||s(`designer.field.kind`),onClose:r,closeLabel:s(`designer.field.close`),children:(0,Y.jsx)(oi,{message:s(`designer.field.missing`)})});let h=f.def,g=typeof h.type==`string`?h.type:`text`,_=Di[g],v=e=>{n({fields:Si(e)})},y=e=>{let t=[...l.entries];t[d]={...f,def:{...h,...e}},v({shape:l.shape,entries:t})},b=e=>{let t=Ci(e);if(!t||t===f.name||l.entries.some((e,n)=>n!==d&&e.name===t))return;let n=[...l.entries];n[d]={...f,name:t},v({shape:l.shape,entries:n}),i?.({kind:`field`,id:t,label:String(h.label??t)})},x=e=>{if(a)return null;let t=g===`select`?`status`:g;if(!(f.name===t||f.name.startsWith(`${t}_`)&&/^\d+$/.test(f.name.slice(t.length+1))||/^field_\d+$/.test(f.name)))return null;let n=Ci(e);return!n||n===f.name||l.entries.some((e,t)=>t!==d&&e.name===n)?null:n},S=()=>{let e=l.entries.filter((e,t)=>t!==d);v({shape:l.shape,entries:e}),r()},C=()=>{let e=new Set(l.entries.map(e=>e.name)),t=`${f.name}_copy`,n=t,r=1;for(;e.has(n);)r+=1,n=`${t}_${r}`;let a=typeof h.label==`string`&&h.label?h.label:``,o={name:n,def:{...h,label:a?a+s(`designer.field.copySuffix`):void 0}},c=[...l.entries];c.splice(d+1,0,o),v({shape:l.shape,entries:c}),i?.({kind:`field`,id:n,label:String(o.def.label??n)})},w=e=>{let t={shape:l.shape,entries:gi(l.entries,d,e)};v(t)},T=Rg(h),E=e=>{let t=e.map(e=>{let t={value:e.value};return e.label&&(t.label=e.label),e.color&&(t.color=e.color),t});y({options:t})},D=(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!a&&(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:C,title:s(`designer.field.duplicate`),"aria-label":s(`designer.field.duplicate`),children:(0,Y.jsx)(dn,{className:`h-3.5 w-3.5`})}),(0,Y.jsx)(Mi,{index:d,total:l.entries.length,onMove:w,disabled:a})]}),O=(0,Y.jsx)(hi,{label:q(`designer.field.remove`,o,{label:typeof h.label==`string`?h.label:f.name}),onClick:S,disabled:a}),k=Lg(o)?_?.labelZh:_?.label;return(0,Y.jsxs)(ji,{kindLabel:s(`designer.field.kind`),title:typeof h.label==`string`&&h.label?h.label:f.name,onClose:r,closeLabel:s(`designer.field.close`),headerActions:D,footer:O,children:[(0,Y.jsxs)(qg,{title:s(`designer.field.section.basic`),children:[(0,Y.jsx)(G,{label:s(`designer.field.apiName`),value:f.name,onCommit:b,disabled:a,mono:!0,testId:`field-apiname-input`}),(0,Y.jsx)(G,{label:s(`designer.field.label`),value:typeof h.label==`string`?h.label:``,onCommit:e=>{let t=x(e),n=[...l.entries];n[d]={...f,name:t??f.name,def:{...h,label:e}},v({shape:l.shape,entries:n}),t&&i?.({kind:`field`,id:t,label:e})},disabled:a,testId:`field-label-input`}),(0,Y.jsx)(W,{label:s(`designer.field.type`),value:g,options:c,onCommit:e=>y({type:e}),disabled:a}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 pt-1`,children:[(0,Y.jsx)(K,{label:s(`designer.field.required`),value:!!h.required,onCommit:e=>y({required:e||void 0}),disabled:a}),(0,Y.jsx)(K,{label:s(`designer.field.unique`),value:!!h.unique,onCommit:e=>y({unique:e||void 0}),disabled:a})]}),(0,Y.jsx)(Yg,{label:s(`designer.field.description`),value:typeof h.description==`string`?h.description:``,onCommit:e=>y({description:e||void 0}),disabled:a,rows:2}),Wg(g)&&(0,Y.jsx)(Jg,{kind:Wg(g),value:h.defaultValue,options:T,onCommit:e=>y({defaultValue:e}),disabled:a,locale:o}),(0,Y.jsx)(Yg,{label:s(`designer.field.helpText`),value:typeof h.inlineHelpText==`string`?h.inlineHelpText:``,onCommit:e=>y({inlineHelpText:e||void 0}),disabled:a,rows:2,placeholder:s(`designer.field.helpTextPlaceholder`)})]}),(zg(g)||Bg(g)||Vg(g)||Hg(g)||Ug(g))&&(0,Y.jsxs)(qg,{title:q(`designer.field.section.options`,o,{type:k??g}),children:[zg(g)&&(0,Y.jsx)(Zg,{options:T,onChange:E,disabled:a,locale:o},f.name),Bg(g)&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Xg,{label:s(`designer.field.relatedObject`),value:typeof h.reference==`string`?h.reference:``,options:m,onCommit:e=>y({reference:e||void 0}),disabled:a,placeholder:s(`designer.field.objectNamePlaceholder`)}),(0,Y.jsx)(G,{label:s(`designer.field.relationshipName`),value:typeof h.relationshipName==`string`?h.relationshipName:``,onCommit:e=>y({relationshipName:e||void 0}),disabled:a,placeholder:s(`designer.field.relationshipNameHint`)}),(0,Y.jsx)(t_,{def:h,patchDef:y,hostFieldNames:l.entries.map(e=>e.name).filter(e=>e!==f.name),readOnly:a,locale:o})]}),Vg(g)&&(0,Y.jsx)(Yg,{label:s(`designer.field.formula`),value:typeof h.formula==`string`?h.formula:``,onCommit:e=>y({formula:e||void 0}),disabled:a,rows:4,mono:!0,placeholder:`record.amount * 0.2`}),Hg(g)&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(ai,{label:s(`designer.field.precision`),value:typeof h.precision==`number`?h.precision:void 0,onCommit:e=>y({precision:e}),disabled:a}),(0,Y.jsx)(ai,{label:s(`designer.field.scale`),value:typeof h.scale==`number`?h.scale:void 0,onCommit:e=>y({scale:e}),disabled:a}),(0,Y.jsx)(ai,{label:s(`designer.field.min`),value:typeof h.min==`number`?h.min:void 0,onCommit:e=>y({min:e}),disabled:a}),(0,Y.jsx)(ai,{label:s(`designer.field.max`),value:typeof h.max==`number`?h.max:void 0,onCommit:e=>y({max:e}),disabled:a})]}),Ug(g)&&(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(ai,{label:s(`designer.field.minLength`),value:typeof h.minLength==`number`?h.minLength:void 0,onCommit:e=>y({minLength:e}),disabled:a,placeholder:`0`}),(0,Y.jsx)(ai,{label:s(`designer.field.maxLength`),value:typeof h.maxLength==`number`?h.maxLength:void 0,onCommit:e=>y({maxLength:e}),disabled:a,placeholder:`255`})]})]}),(0,Y.jsxs)(qg,{title:s(`designer.field.section.advanced`),children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(K,{label:s(`designer.field.readonly`),value:!!h.readonly,onCommit:e=>y({readonly:e||void 0}),disabled:a}),(0,Y.jsx)(K,{label:s(`designer.field.hidden`),value:!!h.hidden,onCommit:e=>y({hidden:e||void 0}),disabled:a}),(0,Y.jsx)(K,{label:s(`designer.field.indexed`),value:!!h.indexed,onCommit:e=>y({indexed:e||void 0}),disabled:a}),(0,Y.jsx)(K,{label:s(`designer.field.externalId`),value:!!h.externalId,onCommit:e=>y({externalId:e||void 0}),disabled:a}),(0,Y.jsx)(K,{label:s(`designer.field.trackHistory`),value:!!h.trackHistory,onCommit:e=>y({trackHistory:e||void 0}),disabled:a})]}),(0,Y.jsx)(G,{label:s(`designer.field.placeholder`),value:typeof h.placeholder==`string`?h.placeholder:``,onCommit:e=>y({placeholder:e||void 0}),disabled:a}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(G,{label:s(`designer.field.conditionalRequired`),value:typeof h.conditionalRequired==`string`?h.conditionalRequired:``,onCommit:e=>y({conditionalRequired:e||void 0}),disabled:a,mono:!0,placeholder:`record.status == 'closed'`}),(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:s(`designer.field.conditionalRequiredHint`)})]}),p.length>0&&(0,Y.jsx)(W,{label:s(`designer.field.group`),value:typeof h.group==`string`?h.group:``,options:[{value:``,label:s(`designer.field.noGroup`)},...p.filter(e=>typeof e.key==`string`).map(e=>({value:e.key,label:String(e.label??e.key)}))],onCommit:e=>y({group:e||void 0}),disabled:a})]})]})}function qg({title:e,children:t}){return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground border-b pb-1`,children:e}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:t})]})}function Jg({kind:e,value:t,options:n,onCommit:r,disabled:i,locale:a}){let o=J(`designer.field.defaultValue`,a),s=J(`designer.field.defaultNone`,a);return e===`bool`?(0,Y.jsx)(W,{label:o,value:t===!0?`true`:t===!1?`false`:``,options:[{value:``,label:s},{value:`true`,label:J(`designer.field.true`,a)},{value:`false`,label:J(`designer.field.false`,a)}],onCommit:e=>r(e===``?void 0:e===`true`),disabled:i}):e===`number`?(0,Y.jsx)(ai,{label:o,value:typeof t==`number`?t:void 0,onCommit:e=>r(e),disabled:i}):e===`picklist`?(0,Y.jsx)(W,{label:o,value:typeof t==`string`?t:``,options:[{value:``,label:s},...n.filter(e=>e.value).map(e=>({value:e.value,label:e.label||e.value}))],onCommit:e=>r(e||void 0),disabled:i}):(0,Y.jsx)(G,{label:o,value:typeof t==`string`?t:t==null?``:String(t),onCommit:e=>r(e||void 0),disabled:i})}function Yg({label:e,value:t,onCommit:n,disabled:r,rows:i=2,mono:a,placeholder:o}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(`textarea`,{value:t,disabled:r,rows:i,placeholder:o,onChange:e=>n(e.target.value),className:`w-full text-sm rounded-md border bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary `+(a?`font-mono text-xs `:``)})]})}function Xg({label:e,value:t,options:n,onCommit:r,disabled:i,placeholder:a}){let o=X.useId();return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(V,{list:o,value:t,onChange:e=>r(e.target.value),disabled:i,className:`h-8 text-sm font-mono`,placeholder:a??`object_name`}),(0,Y.jsx)(`datalist`,{id:o,children:n.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function Zg({options:e,onChange:t,disabled:n,locale:r}){let[i,a]=X.useState(()=>e.length>0?e:[{value:``,label:``}]),o=e=>{a(e),t(e.filter(e=>e.value.trim()!==``))},s=(e,t)=>{let n=[...i];n[e]={...n[e],...t},o(n)},c=e=>o(i.filter((t,n)=>n!==e)),l=(e,t)=>o(gi(i,e,t));return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:J(`designer.field.picklistValues`,r)}),(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px]`,children:i.length})]}),i.length===0?(0,Y.jsx)(`div`,{className:`text-[11px] italic text-muted-foreground px-1`,children:J(`designer.field.noValues`,r)}):(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:i.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border border-border/60 p-1.5 space-y-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(V,{value:e.value,onChange:e=>s(t,{value:e.target.value}),placeholder:J(`designer.field.optValue`,r),disabled:n,className:`h-7 min-w-0 flex-1 text-xs font-mono`}),(0,Y.jsx)(V,{value:e.label??``,onChange:e=>s(t,{label:e.target.value}),placeholder:J(`designer.field.optLabel`,r),disabled:n,className:`h-7 min-w-0 flex-1 text-xs`})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`input`,{type:`color`,value:e.color??`#cccccc`,onChange:e=>s(t,{color:e.target.value}),disabled:n,className:`h-6 w-6 rounded border bg-background cursor-pointer p-0.5`,title:J(`designer.field.optColor`,r)}),(0,Y.jsx)(`span`,{className:`flex-1`}),(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>l(t,t-1),disabled:n||t===0,"aria-label":J(`designer.field.moveUp`,r),children:(0,Y.jsx)(Cr,{className:`h-3 w-3`})}),(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>l(t,t+1),disabled:n||t===i.length-1,"aria-label":J(`designer.field.moveDown`,r),children:(0,Y.jsx)(Or,{className:`h-3 w-3`})}),(0,Y.jsx)(H,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-destructive`,onClick:()=>c(t),disabled:n,"aria-label":J(`designer.field.removeValue`,r),children:(0,Y.jsx)(Qe,{className:`h-3 w-3`})})]})]},t))}),!n&&(0,Y.jsxs)(H,{variant:`outline`,size:`sm`,className:`h-7 gap-1 text-xs`,onClick:()=>o([...i,{value:``,label:``}]),children:[(0,Y.jsx)(L,{className:`h-3 w-3`}),J(`designer.field.addValue`,r)]})]})}var Qg=[{value:`eq`,label:`= equals`},{value:`ne`,label:`≠ not equals`},{value:`gt`,label:`> greater than`},{value:`lt`,label:`< less than`},{value:`gte`,label:`≥ at least`},{value:`lte`,label:`≤ at most`},{value:`contains`,label:`contains`},{value:`in`,label:`in (any of)`},{value:`notIn`,label:`not in`}];function $g(e){let t=e.lookupFilters??e.lookup_filters;return Array.isArray(t)?t:[]}function e_(e){let t=e.dependsOn??e.depends_on;return Array.isArray(t)?t.map(e=>typeof e==`string`?e:e&&typeof e==`object`?e.field:void 0).filter(e=>!!e):[]}function t_({def:e,patchDef:t,hostFieldNames:n,readOnly:r,locale:i}){let a=e=>J(e,i),o=typeof e.reference==`string`?e.reference:void 0,{fields:s,loading:c}=ki(o),l=X.useMemo(()=>s.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label,hint:e.type})),[s]),u=X.useMemo(()=>n.map(e=>({value:e,label:e})),[n]),d=$g(e),f=e_(e),p=(e,n)=>t({lookupFilters:d.map((t,r)=>r===e?{...t,...n}:t)}),m=()=>t({lookupFilters:[...d,{field:``,operator:`eq`,value:``}]}),h=e=>{let n=d.filter((t,n)=>n!==e);t({lookupFilters:n.length?n:void 0})},g=e=>Array.isArray(e)?e.join(`, `):e==null?``:String(e),_=(e,t)=>e===`in`||e===`notIn`?t.split(`,`).map(e=>e.trim()).filter(Boolean):t,v=e=>{!e||f.includes(e)||t({dependsOn:[...f,e]})},y=e=>{let n=f.filter(t=>t!==e);t({dependsOn:n.length?n:void 0})},b=typeof e.displayField==`string`?e.displayField:``,x=typeof e.descriptionField==`string`?e.descriptionField:``,S=typeof e.lookupPageSize==`number`?e.lookupPageSize:void 0,C=e.allowCreate===!0,w=a(o?`designer.field.lookup.selectField`:`designer.field.lookup.setTargetFirst`);return(0,Y.jsxs)(`div`,{className:`space-y-2 border-t pt-2.5`,children:[(0,Y.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground`,children:a(`designer.field.lookup.pickerConfig`)}),(0,Y.jsx)(Zi,{label:a(`designer.field.lookup.displayField`),value:b,onCommit:e=>t({displayField:e||void 0}),options:l,loading:c,placeholder:w,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsx)(Zi,{label:a(`designer.field.lookup.descriptionField`),value:x,onCommit:e=>t({descriptionField:e||void 0}),options:l,loading:c,placeholder:w,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:a(`designer.field.lookup.selectableRecords`)}),(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px]`,children:d.length})]}),!r&&(0,Y.jsxs)(H,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:m,children:[(0,Y.jsx)(L,{className:`h-3 w-3`}),` `,a(`designer.field.lookup.addFilter`)]})]}),d.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:q(`designer.field.lookup.noFilter`,i,{ref:o||`related`})}):d.map((e,t)=>(0,Y.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:q(`designer.field.lookup.filterN`,i,{n:t+1})}),!r&&(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":a(`designer.field.lookup.removeFilter`),className:`h-6 w-6 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>h(t),children:(0,Y.jsx)(Qe,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(Zi,{label:a(`designer.field.lookup.filterField`),value:e.field??``,onCommit:e=>p(t,{field:e}),options:l,loading:c,placeholder:w,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,Y.jsx)(W,{label:a(`designer.field.lookup.filterOperator`),value:e.operator??`eq`,options:Qg,onCommit:e=>p(t,{operator:e}),disabled:r}),(0,Y.jsx)(G,{label:a(`designer.field.lookup.filterValue`),value:g(e.value),onCommit:n=>p(t,{value:_(e.operator,n)}),placeholder:e.operator===`in`||e.operator===`notIn`?`comma,separated,values`:`value`,disabled:r,mono:!0})]},t))]}),(0,Y.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:a(`designer.field.lookup.dependsOn`)}),f.length>0&&(0,Y.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:f.map(e=>(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded bg-secondary px-2 py-0.5 text-[11px] font-mono`,children:[e,!r&&(0,Y.jsx)(`button`,{type:`button`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>y(e),"aria-label":`Remove ${e}`,children:`×`})]},e))}),!r&&u.length>0&&(0,Y.jsx)(Zi,{value:``,onCommit:e=>v(e),options:u.filter(e=>!f.includes(e.value)),placeholder:a(`designer.field.lookup.addDependsOn`),searchPlaceholder:a(`designer.field.lookup.searchHostFields`),disabled:r,allowCustom:!1,mono:!0})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-1`,children:[(0,Y.jsx)(ai,{label:a(`designer.field.lookup.pageSize`),value:S,onCommit:e=>t({lookupPageSize:e}),placeholder:`10`,disabled:r}),(0,Y.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,Y.jsx)(K,{label:a(`designer.field.lookup.allowCreate`),value:C,onCommit:e=>t({allowCreate:e||void 0}),disabled:r})})]})]})}function n_(){let e=ti(),[t,n]=X.useState([]);return X.useEffect(()=>{let t=!1;return Promise.all([e.list(`object`),e.listDrafts({type:`object`}).catch(()=>[])]).then(([e,r])=>{if(t)return;let i=new Map;for(let t of e??[])typeof t?.name==`string`&&t.name&&!i.has(t.name)&&i.set(t.name,{value:t.name,label:t.label?`${t.label} (${t.name})`:t.name});for(let e of r??[]){let t=e.name;typeof t==`string`&&t&&!i.has(t)&&i.set(t,{value:t,label:`${t} (草稿)`})}n([...i.values()].sort((e,t)=>e.value.localeCompare(t.value)))}).catch(()=>{}),()=>{t=!0}},[e]),t}function r_({name:e,draft:t,onPatch:n,readOnly:r,locale:i}){let a=X.useCallback(e=>J(e,i),[i]),o=!e,s=e=>typeof t[e]==`string`?t[e]:``,c=X.useRef(!1),l=e=>{let t={label:e||void 0};o&&!c.current&&(t.name=Ts(e)),n(t)},u=e=>{c.current=!0,n({name:Ci(e)})},d=o?s(`name`):e||s(`name`),f=s(`label`)||e||a(`designer.object.kind`);return(0,Y.jsx)(ji,{kindLabel:a(`designer.object.kind`),title:f,onClose:()=>{},hideClose:!0,children:(0,Y.jsxs)(i_,{title:a(`designer.object.section.basic`),hint:a(`designer.object.section.basicHint`),children:[(0,Y.jsx)(a_,{hint:a(`designer.object.nameHint`),children:(0,Y.jsx)(G,{label:a(`designer.object.name`),value:d,onCommit:u,disabled:r||!o,mono:!0,testId:`object-name-input`,placeholder:a(`designer.object.namePlaceholder`)})}),(0,Y.jsx)(G,{label:a(`designer.object.label`),value:s(`label`),onCommit:l,disabled:r,placeholder:a(`designer.object.labelPlaceholder`)}),(0,Y.jsx)(G,{label:a(`designer.object.pluralLabel`),value:s(`pluralLabel`),onCommit:e=>n({pluralLabel:e||void 0}),disabled:r,placeholder:a(`designer.object.pluralPlaceholder`)}),(0,Y.jsx)(a_,{hint:a(`designer.object.iconHint`),children:(0,Y.jsx)(G,{label:a(`designer.object.icon`),value:s(`icon`),onCommit:e=>n({icon:e||void 0}),disabled:r,mono:!0,placeholder:`building`})}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:a(`designer.object.description`)}),(0,Y.jsx)(`textarea`,{value:s(`description`),disabled:r,rows:2,placeholder:a(`designer.object.descriptionPlaceholder`),onChange:e=>n({description:e.target.value||void 0}),className:`w-full text-sm rounded-md border bg-background px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-primary`})]})]})})}function i_({title:e,hint:t,children:n}){return(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`border-b pb-1`,children:[(0,Y.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-[10px] normal-case text-muted-foreground/70 mt-0.5`,children:t})]}),(0,Y.jsx)(`div`,{className:`space-y-2`,children:n})]})}function a_({hint:e,children:t}){return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[t,e&&(0,Y.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:e})]})}var o_={equals:`$eq`,notEquals:`$ne`,greaterThan:`$gt`,greaterOrEqual:`$gte`,lessThan:`$lt`,lessOrEqual:`$lte`,after:`$gt`,before:`$lt`,contains:`$contains`,in:`$in`,notIn:`$nin`},s_={$eq:`equals`,$ne:`notEquals`,$gt:`greaterThan`,$gte:`greaterOrEqual`,$lt:`lessThan`,$lte:`lessOrEqual`,$contains:`contains`,$in:`in`,$nin:`notIn`};function c_(e){let t=(e?.conditions??[]).filter(e=>e&&e.field),n=[];for(let e of t){if(e.operator===`isEmpty`){n.push({[e.field]:{$exists:!1}});continue}if(e.operator===`isNotEmpty`){n.push({[e.field]:{$exists:!0}});continue}let t=o_[e.operator];if(!t)continue;let r=e.value;r==null||r===``||Array.isArray(r)&&r.length===0||n.push({[e.field]:{[t]:r}})}if(n.length!==0)return n.length===1?n[0]:{$and:n}}function l_(e){let t={id:`g`,logic:`and`,conditions:[]};if(e==null)return{group:t,representable:!0};if(typeof e!=`object`||Array.isArray(e)||`$or`in e)return{group:t,representable:!1};let n=Array.isArray(e.$and)?e.$and:[e],r=[];for(let e=0;e<n.length;e++){let i=n[e];if(!i||typeof i!=`object`||Array.isArray(i)||`$and`in i||`$or`in i)return{group:t,representable:!1};let a=Object.keys(i);if(a.length!==1)return{group:t,representable:!1};let o=a[0],s=i[o];if(s&&typeof s==`object`&&!Array.isArray(s)){let n=Object.keys(s);if(n.length!==1)return{group:t,representable:!1};let i=n[0];if(i===`$exists`)r.push({id:`c${e}`,field:o,operator:s.$exists?`isNotEmpty`:`isEmpty`,value:``});else{let n=s_[i];if(!n)return{group:t,representable:!1};r.push({id:`c${e}`,field:o,operator:n,value:s[i]})}}else r.push({id:`c${e}`,field:o,operator:`equals`,value:s})}return{group:{id:`g`,logic:`and`,conditions:r},representable:!0}}var u_=[{value:`count`,label:`count`},{value:`sum`,label:`sum`},{value:`avg`,label:`avg`},{value:`min`,label:`min`},{value:`max`,label:`max`},{value:`count_distinct`,label:`count distinct`}],d_=[{value:`string`,label:`string`},{value:`number`,label:`number`},{value:`date`,label:`date`},{value:`boolean`,label:`boolean`},{value:`lookup`,label:`lookup`}],f_=[{value:``,label:`— none —`},{value:`day`,label:`day`},{value:`week`,label:`week`},{value:`month`,label:`month`},{value:`quarter`,label:`quarter`},{value:`year`,label:`year`}],p_=[{value:`ratio`,label:`ratio (a ÷ b)`},{value:`sum`,label:`sum (a + b)`},{value:`difference`,label:`difference (a − b)`},{value:`product`,label:`product (a × b)`}],m_=[{value:`raw`,label:`Raw number`},{value:`number`,label:`Number — 1,234.5`},{value:`currency`,label:`Currency — $1,234.50`},{value:`percent`,label:`Percent — 12.3%`}],h_=[{value:`0`,label:`0`},{value:`1`,label:`1`},{value:`2`,label:`2`}],g_=[{value:`USD`,label:`USD ($)`},{value:`EUR`,label:`EUR (€)`},{value:`GBP`,label:`GBP (£)`},{value:`CNY`,label:`CNY (¥)`},{value:`JPY`,label:`JPY (¥)`},{value:`INR`,label:`INR (₹)`},{value:`CAD`,label:`CAD ($)`},{value:`AUD`,label:`AUD ($)`}];function __({title:e,count:t,onAdd:n,addLabel:r}){return(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e}),(0,Y.jsx)(R,{variant:`outline`,className:`text-[10px]`,children:t})]}),n&&(0,Y.jsxs)(H,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:n,children:[(0,Y.jsx)(L,{className:`h-3 w-3`}),` `,r]})]})}function v_({children:e}){return(0,Y.jsxs)(`details`,{className:`group`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer select-none list-none text-[11px] text-muted-foreground hover:text-foreground`,children:(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(Nr,{className:`h-3 w-3 transition-transform group-open:rotate-90`}),`Advanced`]})}),(0,Y.jsx)(`div`,{className:`mt-1.5 space-y-1.5 border-l pl-2.5`,children:e})]})}function y_(e,t){let n=(e??``).trim(),r=n.match(/\.(0+)/),i=r?Math.min(r[1].length,2):0;return t||/[$£€¥₹]/.test(n)?{kind:`currency`,decimals:i}:n.includes(`%`)?{kind:`percent`,decimals:i}:n?{kind:`number`,decimals:i}:{kind:`raw`,decimals:0}}function b_(e,t,n){let r=t>0?`.`+`0`.repeat(t):``;switch(e){case`number`:return{format:`0,0${r}`,currency:void 0};case`currency`:return{format:`0,0${r}`,currency:n||`USD`};case`percent`:return{format:`0${r}%`,currency:void 0};default:return{format:void 0,currency:void 0}}}function x_({measure:e,onPatch:t,disabled:n}){let{kind:r,decimals:i}=y_(e.format,e.currency),a=e.currency||`USD`,o=(e,n,r)=>t(b_(e,n,r)),s=y(r===`percent`?.1234:1234.5,e.format,e.currency);return(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,Y.jsx)(W,{label:`Display format`,value:r,options:m_,onCommit:e=>o(e,i,a),disabled:n}),r!==`raw`&&(0,Y.jsx)(W,{label:`Decimals`,value:String(i),options:h_,onCommit:e=>o(r,parseInt(e,10)||0,a),disabled:n})]}),r===`currency`&&(0,Y.jsx)(W,{label:`Currency`,value:a,options:g_,onCommit:e=>o(r,i,e),disabled:n}),r!==`raw`&&(0,Y.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Sample: `,(0,Y.jsx)(`span`,{className:`font-mono tabular-nums`,children:s})]})]})}function S_(e,t){if(!e||!e.includes(`.`))return null;let n=e.slice(0,e.lastIndexOf(`.`));return n&&!t.includes(n)?n:null}function C_({rel:e,onAdd:t,disabled:n}){return(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-[10px] text-amber-600 dark:text-amber-400`,children:[(0,Y.jsx)(I,{className:`h-3 w-3 shrink-0`}),(0,Y.jsxs)(`span`,{children:[`Relationship `,(0,Y.jsx)(`code`,{className:`font-mono`,children:e}),` isn't in Included relationships.`]}),!n&&t&&(0,Y.jsx)(`button`,{type:`button`,className:`underline hover:no-underline`,onClick:t,children:`Add it`})]})}function w_({label:e,help:t,value:n,onCommit:r,fields:i,disabled:a}){let{group:o,representable:s}=l_(n),c=o.conditions.length;return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:e}),s?(0,Y.jsxs)(jn,{children:[(0,Y.jsx)(Qn,{asChild:!0,children:(0,Y.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,disabled:a,className:`h-8 w-full justify-between text-xs font-normal`,children:[(0,Y.jsx)(`span`,{className:`truncate text-left`,children:c?`${c} condition${c===1?``:`s`}`:(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`+ Add filter…`})}),(0,Y.jsx)(ke,{className:`h-3.5 w-3.5 opacity-60 shrink-0`})]})}),(0,Y.jsx)(en,{align:`start`,className:`w-[440px] max-w-[90vw] p-3`,children:i.length===0?(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Pick a base object to add filter conditions.`}):(0,Y.jsx)(it,{fields:i,value:o,onChange:e=>r(c_(e))})})]}):(0,Y.jsxs)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-2.5 py-1.5 text-[11px] text-muted-foreground`,children:[`Advanced filter (nested / OR) — edit it in the `,(0,Y.jsx)(`span`,{className:`font-medium`,children:`Source`}),` tab.`]}),t&&(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:t})]})}function T_(e,t){return e===t?{object:e}:{object:e,include:[],dimensions:[],measures:[],filter:void 0}}function E_({draft:e,onPatch:t,readOnly:n,name:r}){let i=typeof e.label==`string`?e.label:``,a=typeof e.description==`string`?e.description:``,o=typeof e.object==`string`?e.object:``,s=Array.isArray(e.include)?e.include:[],c=Array.isArray(e.dimensions)?e.dimensions:[],l=Array.isArray(e.measures)?e.measures:[],u=typeof e.name==`string`?e.name:void 0,d=!r,f=X.useRef(!1),p=typeof e.name==`string`?e.name:``,{options:m,loading:h}=Yi(),{relationships:g,fieldOptions:_,loading:v}=$i(o,s),y=ta(u),b=X.useMemo(()=>m.map(e=>({value:e.name,label:e.label})),[m]),x=X.useMemo(()=>g.map(e=>({value:e.name,label:e.label,hint:e.referenceTo?`→ ${e.referenceTo}`:void 0})),[g]),S=X.useMemo(()=>_.map(e=>({value:e.value,label:e.label,hint:e.type,group:e.group})),[_]),C=X.useMemo(()=>_.filter(e=>!e.value.includes(`.`)).map(e=>({value:e.value,label:e.label,type:e.type})),[_]),w=e.filter&&typeof e.filter==`object`?e.filter:void 0,T=b.find(e=>e.value===o)?.label??o,E=(e,n)=>t({dimensions:c.map((t,r)=>r===e?{...t,...n}:t)}),D=(e,n)=>t({measures:l.map((t,r)=>r===e?{...t,...n}:t)}),O=e=>e.includes(`.`)?e.split(`.`).pop()??e:e,k=(e,t)=>{let n=_.find(e=>e.value===t),r=n?.type?{field:t,type:Ji(n.type)}:{field:t};c[e]?.name||(r.name=O(t)),E(e,r)},A=(e,t)=>{let n={field:t};l[e]?.name||(n.name=O(t)),D(e,n)};return(0,Y.jsxs)(ji,{kindLabel:`Dataset`,title:String(i||e.name||`Dataset`),onClose:()=>{},hideClose:!0,children:[u&&!y.loading&&(0,Y.jsx)(`p`,{className:y.reports+y.dashboards>0?`rounded-md border border-amber-500/30 bg-amber-500/5 px-2.5 py-1.5 text-[11px] text-amber-700 dark:text-amber-300`:`text-[11px] text-muted-foreground`,children:y.reports+y.dashboards>0?`Bound by ${y.reports} report${y.reports===1?``:`s`} · ${y.dashboards} dashboard${y.dashboards===1?``:`s`} — changes affect them.`:`Not yet bound by any report or dashboard.`}),d&&(0,Y.jsx)(G,{label:`Name`,value:p,onCommit:e=>{f.current=!0,t({name:di(e)})},placeholder:`snake_case identifier`,disabled:n,mono:!0}),(0,Y.jsx)(G,{label:`Label`,value:i,onCommit:e=>{let n={label:e};d&&!f.current&&(n.name=di(e)),t(n)},disabled:n}),(0,Y.jsx)(G,{label:`Description`,value:a,onCommit:e=>t({description:e}),disabled:n}),(0,Y.jsx)(Zi,{label:`Base object`,value:o,onCommit:e=>t(T_(e,o)),options:b,loading:h,placeholder:`Select an object…`,searchPlaceholder:`Search objects…`,disabled:n,mono:!0}),o&&(c.length>0||l.length>0||s.length>0||!!w)&&(0,Y.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Changing the base object clears its dimensions, measures, joins & filters.`}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,Y.jsx)(__,{title:`Included relationships`,count:s.length,addLabel:`Add`,onAdd:n?void 0:()=>t({include:mi(s,``)})}),s.length===0?(0,Y.jsxs)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:[`No joins. Add a relationship (a lookup field on `,(0,Y.jsx)(`code`,{children:T||`the base object`}),`) to use `,(0,Y.jsx)(`code`,{children:`relationship.field`}),` dimensions/measures.`]}):s.map((e,r)=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Y.jsx)(Zi,{value:e,onCommit:e=>t({include:s.map((t,n)=>n===r?e:t)}),options:x,loading:v,placeholder:`Select a relationship…`,searchPlaceholder:`Search relationships…`,disabled:n,mono:!0}),!n&&(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>t({include:si(s,r,null)}),"aria-label":`Remove relationship`,children:(0,Y.jsx)(Qe,{className:`h-3.5 w-3.5`})})]},r)),o&&s.length>0&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-1 gap-y-0.5 pt-0.5 text-[10px] text-muted-foreground`,children:[(0,Y.jsx)(`span`,{className:`font-mono font-medium`,children:T}),s.map((e,t)=>{let n=g.find(t=>t.name===e);return(0,Y.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,Y.jsx)(Nr,{className:`h-3 w-3 opacity-60`}),(0,Y.jsxs)(`span`,{className:`font-mono`,children:[e,n?.referenceTo?` (${n.referenceTo})`:``]})]},t)})]})]}),(0,Y.jsx)(`div`,{className:`border-t pt-3`,children:(0,Y.jsx)(w_,{label:`Scope filter`,help:`Intrinsic scope, ANDed into every query (e.g. exclude soft-deleted records).`,value:w,onCommit:e=>t({filter:e}),fields:C,disabled:n})}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(__,{title:`Dimensions`,count:c.length,addLabel:`Add dimension`,onAdd:n?void 0:()=>t({dimensions:mi(c,{name:``,field:``,type:`string`})})}),c.map((e,r)=>(0,Y.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Dimension `,r+1]}),!n&&(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":`Remove dimension`,title:`Remove dimension`,className:`h-6 w-6 shrink-0 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>t({dimensions:si(c,r,null)}),children:(0,Y.jsx)(sr,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(G,{label:`Name`,value:e.name??``,onCommit:e=>E(r,{name:e}),placeholder:`e.g. region`,disabled:n,mono:!0}),(0,Y.jsx)(Zi,{label:`Field`,value:e.field??``,onCommit:e=>k(r,e),options:S,loading:v,placeholder:`field or relationship.field`,searchPlaceholder:`Search fields…`,disabled:n,mono:!0}),(()=>{let r=S_(e.field,s);return r?(0,Y.jsx)(C_,{rel:r,disabled:n,onAdd:()=>t({include:mi(s,r)})}):null})(),(0,Y.jsx)(W,{label:`Type`,value:e.type,options:d_,onCommit:e=>E(r,{type:e}),disabled:n}),(0,Y.jsxs)(v_,{children:[(0,Y.jsx)(G,{label:`Label (optional)`,value:e.label??``,onCommit:e=>E(r,{label:e||void 0}),placeholder:e.name||`Display label`,disabled:n}),e.type===`date`&&(0,Y.jsx)(W,{label:`Date bucket`,value:e.dateGranularity??``,options:f_,onCommit:e=>E(r,{dateGranularity:e||void 0}),disabled:n})]})]},r))]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(__,{title:`Measures`,count:l.length,addLabel:`Add measure`,onAdd:n?void 0:()=>t({measures:mi(l,{name:``,aggregate:`sum`,field:``})})}),l.map((e,r)=>{let i=l.filter((e,t)=>t!==r).map(e=>e.name).filter(e=>!!e),a=e.derived;return(0,Y.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Measure `,r+1]}),!n&&(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`sm`,"aria-label":`Remove measure`,title:`Remove measure`,className:`h-6 w-6 shrink-0 p-0 text-muted-foreground hover:text-destructive`,onClick:()=>t({measures:si(l,r,null)}),children:(0,Y.jsx)(sr,{className:`h-3.5 w-3.5`})})]}),(0,Y.jsx)(G,{label:`Name`,value:e.name??``,onCommit:e=>D(r,{name:e}),placeholder:`e.g. revenue`,disabled:n,mono:!0}),(0,Y.jsx)(W,{label:`Aggregate`,value:e.aggregate,options:u_,onCommit:e=>D(r,{aggregate:e}),disabled:n}),(0,Y.jsx)(Zi,{label:`Field`,value:e.field??``,onCommit:e=>A(r,e),options:S,loading:v,placeholder:`field (optional for count)`,searchPlaceholder:`Search fields…`,disabled:n,mono:!0}),(()=>{let r=S_(e.field,s);return r?(0,Y.jsx)(C_,{rel:r,disabled:n,onAdd:()=>t({include:mi(s,r)})}):null})(),(0,Y.jsxs)(v_,{children:[(0,Y.jsx)(G,{label:`Label (optional)`,value:e.label??``,onCommit:e=>D(r,{label:e||void 0}),placeholder:e.name||`Display label`,disabled:n}),(0,Y.jsx)(x_,{measure:e,onPatch:e=>D(r,e),disabled:n}),(0,Y.jsx)(w_,{label:`Filter (measure-scoped)`,help:`Only rows matching this filter feed this measure (e.g. won_amount = sum(amount) where stage = won).`,value:e.filter,onCommit:e=>D(r,{filter:e}),fields:C,disabled:n}),(0,Y.jsx)(K,{label:`Derived — computed from other measures`,value:!!a,onCommit:e=>D(r,{derived:e?{op:`ratio`,of:[]}:void 0}),disabled:n}),a&&(0,Y.jsxs)(`div`,{className:`space-y-1.5 rounded-md border border-dashed p-2`,children:[(0,Y.jsx)(W,{label:`Operation`,value:a.op,options:p_,onCommit:e=>D(r,{derived:{...a,op:e}}),disabled:n}),(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:`Operands (other measures)`}),(()=>{let e=a.op===`ratio`||a.op===`difference`?2:1;return(Array.isArray(a.of)?a.of.length:0)<e?(0,Y.jsxs)(`p`,{className:`text-[10px] text-amber-600 dark:text-amber-400`,children:[`Select `,e===2?`exactly 2 measures`:`at least 1 measure`,` for `,a.op,`.`]}):null})(),i.length===0?(0,Y.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:`Add other measures first.`}):(0,Y.jsx)(`div`,{className:`space-y-1`,children:i.map(e=>(0,Y.jsx)(K,{label:e,value:Array.isArray(a.of)&&a.of.includes(e),disabled:n,onCommit:t=>{let n=Array.isArray(a.of)?a.of:[],i=t?[...n,e]:n.filter(t=>t!==e);D(r,{derived:{...a,of:i}})}},e))})]})]})]},r)})]})]})}function D_(e){let t=ti(),[n,r]=X.useState([]),[i,a]=X.useState(!!e);return X.useEffect(()=>{if(!e){r([]),a(!1);return}let n=!1;return a(!0),t.list(e).then(e=>{if(n)return;let t=(e??[]).map(e=>e&&typeof e==`object`&&`item`in e?e.item:e).filter(e=>typeof e?.name==`string`&&e.name).map(e=>({value:e.name,label:e.label?`${e.label} (${e.name})`:e.name})).sort((e,t)=>e.value.localeCompare(t.value));r(t),a(!1)}).catch(()=>{n||(r([]),a(!1))}),()=>{n=!0}},[t,e]),{options:n,loading:i}}var O_=[{value:`script`,label:`Script — run an expression / sandboxed JS`},{value:`api`,label:`API — call an endpoint`},{value:`flow`,label:`Flow — invoke a flow`},{value:`modal`,label:`Modal — open a modal/page`},{value:`form`,label:`Form — open a FormView`},{value:`url`,label:`URL — navigate to a link`}],k_=[{value:`primary`,label:`Primary`},{value:`secondary`,label:`Secondary`},{value:`danger`,label:`Danger`},{value:`ghost`,label:`Ghost`},{value:`link`,label:`Link`}],A_=[{value:`action:button`,label:`Button`},{value:`action:icon`,label:`Icon only`},{value:`action:menu`,label:`Menu item`},{value:`action:group`,label:`Button group`}],j_=[{value:`create`,label:`Create`},{value:`edit`,label:`Edit`},{value:`delete`,label:`Delete`},{value:`custom`,label:`Custom`}],M_=[{value:`POST`,label:`POST`},{value:`PATCH`,label:`PATCH`},{value:`PUT`,label:`PUT`},{value:`DELETE`,label:`DELETE`}],N_=[{value:`expression`,label:`Expression (L1)`},{value:`js`,label:`Sandboxed JS (L2)`}],P_=[{value:`text`,label:`Text`},{value:`textarea`,label:`Long text`},{value:`number`,label:`Number`},{value:`boolean`,label:`Checkbox`},{value:`select`,label:`Select`},{value:`date`,label:`Date`},{value:`datetime`,label:`Date/time`},{value:`lookup`,label:`Lookup`}],F_=[{value:`record_header`,label:`Record header`},{value:`record_more`,label:`Record · more menu`},{value:`record_section`,label:`Record · section`},{value:`record_related`,label:`Record · related list`},{value:`list_toolbar`,label:`List toolbar`},{value:`list_item`,label:`List · row`},{value:`global_nav`,label:`Global nav / command palette`}],I_={url:{label:`URL`,placeholder:"https://… or /path?x=${param.x}",hint:"Supports ${param.x} and ${ctx.x} interpolation."},flow:{label:`Flow name`,placeholder:`snake_case flow`,hint:`The flow to invoke when clicked.`},modal:{label:`Modal / page name`,placeholder:`snake_case page`,hint:`The modal or page to open.`},form:{label:`Form view name`,placeholder:`object.viewKey`,hint:`Opens /console/forms/<name>.`},api:{label:`API endpoint`,placeholder:`/api/v1/…`,hint:`Endpoint called with the request body below.`}},L_={flow:`flow`,modal:`page`,form:`view`};function R_({type:e,value:t,onCommit:n,cfg:r,readOnly:i}){let a=L_[e]??null,{options:o}=D_(a),s=!!a&&o.length>0,c=s&&t&&!o.some(e=>e.value===t)?[{value:t,label:`${t} (not found)`},...o]:o;return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[s?(0,Y.jsx)(W,{label:`${r.label} *`,value:t||void 0,options:c,onCommit:n,disabled:i}):(0,Y.jsx)(G,{label:`${r.label} *`,value:t,onCommit:n,placeholder:r.placeholder,disabled:i,mono:!0}),(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:r.hint})]})}var z_=[`name`,`label`,`objectName`,`icon`,`variant`,`component`,`type`,`target`,`execute`,`body`,`method`,`params`,`locations`,`bulkEnabled`,`confirmText`,`successMessage`,`errorMessage`,`refreshAfter`,`undoable`,`mode`,`shortcut`,`visible`,`disabled`,`aiExposed`,`aiDescription`];function B_({title:e,hint:t}){return(0,Y.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,Y.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:e}),t&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:t})]})}function V_(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`object`){let t=e;return t.en??t[`en-US`]??Object.values(t)[0]??``}return String(e)}function H_({label:e,value:t,onCommit:n,disabled:r,hint:i}){let{options:a}=Al();return(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[a.length===0?(0,Y.jsx)(G,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,Y.jsx)(W,{label:e,value:t||void 0,options:[{value:``,label:`— None (global) —`},...a],onCommit:n,disabled:r}),i&&(0,Y.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:i})]})}function U_({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let{fields:a}=ki(t),o=X.useMemo(()=>a.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name})),[a]);return!t||o.length===0?(0,Y.jsx)(G,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,Y.jsx)(W,{label:e,value:n||void 0,options:[{value:``,label:`—`},...o],onCommit:r,disabled:i})}function W_({draft:e,onPatch:t,readOnly:n,locale:r,serverSchema:i}){let a=X.useCallback(e=>J(e,r),[r]),o=t=>typeof e[t]==`string`?e[t]:``,s=o(`type`)||`script`,c=o(`objectName`),l=e.body&&typeof e.body==`object`?e.body:{},u=Array.isArray(e.params)?e.params:[],d=Array.isArray(e.locations)?e.locations:[],f=e.aiExposed===!0,p=typeof e.aiDescription==`string`?e.aiDescription:``,m=e=>t({body:{...l,...e}}),h=(e,n)=>t({params:u.map((t,r)=>r===e?{...t,...n}:t)}),g=(e,n)=>{t({locations:n?[...new Set([...d,e])]:d.filter(t=>t!==e)})},_=I_[s],v=i;return(0,Y.jsxs)(ji,{kindLabel:a(`engine.inspector.action.kind`),title:String(V_(e.label)||e.name||a(`engine.inspector.action.kind`)),onClose:()=>{},closeLabel:a(`engine.inspector.action.close`),hideClose:!0,children:[(0,Y.jsx)(B_,{title:`Basics`}),(0,Y.jsx)(G,{label:`Label`,value:V_(e.label),onCommit:e=>t({label:e}),placeholder:`Button text shown to users`,disabled:n}),(0,Y.jsx)(G,{label:`Name`,value:o(`name`),onCommit:e=>t({name:e}),placeholder:`snake_case identifier`,disabled:n,mono:!0}),(0,Y.jsx)(H_,{label:`Object`,value:c,onCommit:e=>t({objectName:e||void 0}),disabled:n,hint:c?`Bound action — surfaces in this object’s views per the placement below.`:`Empty = global action — must be referenced by a page’s quick actions, global nav, a flow, or AI to appear.`}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:`Icon`}),(0,Y.jsx)(Pi,{schema:{type:`string`},value:o(`icon`),onChange:e=>t({icon:e||void 0}),readOnly:n})]}),(0,Y.jsx)(W,{label:`Variant`,value:o(`variant`)||void 0,options:k_,onCommit:e=>t({variant:e}),disabled:n})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,Y.jsx)(B_,{title:`Behavior`,hint:`What happens when the action is triggered.`}),(0,Y.jsx)(W,{label:`Type`,value:s,options:O_,onCommit:e=>t({type:e}),disabled:n}),s===`script`?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(W,{label:`Script language`,value:(typeof l.language==`string`?l.language:void 0)||`expression`,options:N_,onCommit:e=>m({language:e}),disabled:n}),(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:`Script body`}),(0,Y.jsx)(hr,{value:typeof l.source==`string`?l.source:``,onChange:e=>m({source:e.target.value}),disabled:n,spellCheck:!1,rows:5,placeholder:`// (input, ctx) => result
22
+ return { ok: true }`,className:`text-xs font-mono`}),(0,Y.jsxs)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:[`Runs in the sandbox as `,(0,Y.jsx)(`code`,{children:`(input, ctx) => Promise<output>`}),`.`]})]})]}):(0,Y.jsxs)(Y.Fragment,{children:[s===`api`&&(0,Y.jsx)(W,{label:`Method`,value:o(`method`)||`POST`,options:M_,onCommit:e=>t({method:e}),disabled:n}),_&&(0,Y.jsx)(R_,{type:s,value:o(`target`),onCommit:e=>t({target:e}),cfg:_,readOnly:n})]})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(B_,{title:`Inputs`,hint:`Collected from the user in a dialog before the action runs.`}),u.length===0?(0,Y.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2.5 text-center text-[11px] text-muted-foreground`,children:`No inputs — the action runs immediately on click.`}):u.map((e,r)=>(0,Y.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border p-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,Y.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`#`,r+1]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n||r===0,"aria-label":`Move up`,onClick:()=>t({params:gi(u,r,r-1)}),children:`↑`}),(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n||r===u.length-1,"aria-label":`Move down`,onClick:()=>t({params:gi(u,r,r+1)}),children:`↓`}),(0,Y.jsx)(H,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n,"aria-label":`Remove input`,onClick:()=>t({params:si(u,r,null)}),children:(0,Y.jsx)(sr,{className:`h-3.5 w-3.5`})})]})]}),c?(0,Y.jsx)(U_,{label:`Bind to field`,objectName:c,value:e.field,onCommit:e=>h(r,{field:e||void 0}),disabled:n}):null,!e.field&&(0,Y.jsx)(G,{label:`Name`,value:e.name??``,onCommit:e=>h(r,{name:e}),placeholder:`request-body key`,disabled:n,mono:!0}),(0,Y.jsx)(G,{label:`Label`,value:V_(e.label),onCommit:e=>h(r,{label:e}),disabled:n}),!e.field&&(0,Y.jsx)(W,{label:`Type`,value:e.type||void 0,options:P_,onCommit:e=>h(r,{type:e}),disabled:n}),(0,Y.jsx)(G,{label:`Placeholder`,value:e.placeholder??``,onCommit:e=>h(r,{placeholder:e}),disabled:n}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1`,children:[(0,Y.jsx)(K,{label:`Required`,value:!!e.required,onCommit:e=>h(r,{required:e}),disabled:n}),(0,Y.jsx)(K,{label:`Pre-fill from row`,value:!!e.defaultFromRow,onCommit:e=>h(r,{defaultFromRow:e}),disabled:n})]})]},r)),!n&&(0,Y.jsxs)(H,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>t({params:mi(u,{})}),children:[(0,Y.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),` Add input`]})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(B_,{title:`Placement`,hint:`Where this action surfaces in the UI.`}),(0,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-1`,children:F_.map(e=>(0,Y.jsx)(K,{label:e.label,value:d.includes(e.value),onCommit:t=>g(e.value,t),disabled:n},e.value))}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-2 pt-1`,children:(0,Y.jsx)(W,{label:`Component`,value:o(`component`)||void 0,options:A_,onCommit:e=>t({component:e}),disabled:n})}),(0,Y.jsx)(K,{label:`Bulk — apply to multiple selected rows`,value:!!e.bulkEnabled,onCommit:e=>t({bulkEnabled:e}),disabled:n})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(B_,{title:`Feedback`,hint:`Confirmation and post-run messaging.`}),(0,Y.jsx)(G,{label:`Confirm prompt`,value:V_(e.confirmText),onCommit:e=>t({confirmText:e}),placeholder:`Ask before running (leave blank to skip)`,disabled:n}),(0,Y.jsx)(G,{label:`Success message`,value:V_(e.successMessage),onCommit:e=>t({successMessage:e}),disabled:n}),(0,Y.jsx)(G,{label:`Error message`,value:V_(e.errorMessage),onCommit:e=>t({errorMessage:e}),disabled:n}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,Y.jsx)(W,{label:`Mode`,value:o(`mode`)||void 0,options:j_,onCommit:e=>t({mode:e}),disabled:n}),(0,Y.jsx)(G,{label:`Shortcut`,value:o(`shortcut`),onCommit:e=>t({shortcut:e}),placeholder:`e.g. Ctrl+S`,disabled:n,mono:!0})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1`,children:[(0,Y.jsx)(K,{label:`Refresh view after`,value:!!e.refreshAfter,onCommit:e=>t({refreshAfter:e}),disabled:n}),(0,Y.jsx)(K,{label:`Offer undo`,value:!!e.undoable,onCommit:e=>t({undoable:e}),disabled:n})]})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,Y.jsx)(B_,{title:`Conditions`,hint:`No-code predicates over the record / user / ctx (compiled to CEL).`}),(0,Y.jsx)(Ai,{label:`Visible when`,value:typeof e.visible==`string`?e.visible:``,onCommit:e=>t({visible:e||void 0}),objectName:c,disabled:n}),(0,Y.jsx)(Ai,{label:`Disabled when`,value:typeof e.disabled==`string`?e.disabled:``,onCommit:e=>t({disabled:e||void 0}),objectName:c,disabled:n})]}),(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,Y.jsx)(B_,{title:`AI exposure`,hint:`Opt-in: expose this action to AI agents as a callable tool.`}),(0,Y.jsx)(K,{label:`Expose to AI agents`,value:f,onCommit:e=>t({aiExposed:e}),disabled:n}),f?(0,Y.jsxs)(`div`,{className:`space-y-1`,children:[(0,Y.jsx)(z,{className:`text-xs text-muted-foreground`,children:`Tool description (required, ≥40 chars)`}),(0,Y.jsx)(hr,{value:p,onChange:e=>t({aiDescription:e.target.value}),disabled:n,rows:3,placeholder:`When and why an agent should call this action…`,className:`text-xs`}),p.length<40&&(0,Y.jsx)(`div`,{className:`text-[11px] text-destructive`,children:`A ≥40-character description is required while exposed.`})]}):null]}),v&&(0,Y.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,Y.jsx)(B_,{title:a(`engine.inspector.moreFields`),hint:`Advanced / rarely-used properties.`}),(0,Y.jsx)(Li,{schema:v,value:e,hiddenFields:z_,readOnly:n,onChange:e=>t(e)})]})]})}function G_(){Xs(`dashboard`,na),$s(`dashboard`,Qi),Xs(`flow`,vg),Xs(`app`,es),Xs(`view`,Dg),$s(`view`,Og),Xs(`page`,Jl),$s(`page`,Ig),$s(`report`,Fi),Xs(`object`,Kg),$s(`object`,r_),$s(`dataset`,E_),$s(`action`,W_)}var K_=t({MetadataDiagnosticsPage:()=>Gc,MetadataDirectoryPage:()=>Ka,MetadataResourceEditPage:()=>zc,MetadataResourceHistoryPage:()=>zs,MetadataResourceListPage:()=>jo,StudioHomePage:()=>ho});il(),cl(),hl(),yh(),G_();export{ia as C,Ea as S,to as _,Uc as a,Ka as b,Js as c,rs as d,as as f,Eo as g,os as h,tl as i,is as l,ns as m,Nu as n,ec as o,cs as p,xl as r,Zs as s,K_ as t,ss as u,io as v,aa as w,za as x,ao as y};