@objectstack/console 16.1.0 → 17.0.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. package/CHANGELOG.md +1096 -0
  2. package/README.md +8 -3
  3. package/dist/.objectui-sha +1 -1
  4. package/dist/assets/AdapterProvider-DCL4oNgv.js +2 -0
  5. package/dist/assets/{AiPendingActionsPage-C-QNNI9k.js → AiPendingActionsPage-BvvDIWEC.js} +1 -1
  6. package/dist/assets/ApiConsolePage-Dvr5-g2X.js +1 -0
  7. package/dist/assets/{AppDocsIndex-B4Vi3Lmx.js → AppDocsIndex-Ohwtpos8.js} +1 -1
  8. package/dist/assets/{AppManagementPage-l7bxl-aE.js → AppManagementPage-DhsvWTeZ.js} +1 -1
  9. package/dist/assets/ApprovalsInboxPage-BfaGtcxV.js +1 -0
  10. package/dist/assets/AuditLogPage-D_09WrLX.js +1 -0
  11. package/dist/assets/ComponentNavView-C6J3w2IE.js +1 -0
  12. package/dist/assets/CreateViewDialog-R7kwDoaF.js +1 -0
  13. package/dist/assets/DashboardView-B-5HkqOl.js +1 -0
  14. package/dist/assets/{DeveloperHubPage-CnVzl2hV.js → DeveloperHubPage-p9oQnZuU.js} +1 -1
  15. package/dist/assets/{DocShell-D83T8iWF.js → DocShell-B8d7-ARz.js} +1 -1
  16. package/dist/assets/ExpressionProvider-BLhGrCBw.js +1 -0
  17. package/dist/assets/FlowRunsPage-DzZmtrDe.js +1 -0
  18. package/dist/assets/{IntegrationsPage-DI3vZb2A.js → IntegrationsPage-DzBKAEgn.js} +2 -2
  19. package/dist/assets/InterfaceListPage-C_M0U8ns.js +1 -0
  20. package/dist/assets/{ManagedByBadge-D8aPzQJc.js → ManagedByBadge-DWtOXcFq.js} +1 -1
  21. package/dist/assets/MarketplaceAccessDenied-C4Yrv4Q7.js +1 -0
  22. package/dist/assets/{MarketplaceInstalledPage-BdLyXA35.js → MarketplaceInstalledPage-B6cbDzf8.js} +1 -1
  23. package/dist/assets/MarketplacePackagePage-D0dT7D3x.js +4 -0
  24. package/dist/assets/MarketplacePage-CtvxvBmw.js +1 -0
  25. package/dist/assets/{MetadataInspector-CcRGESLn.js → MetadataInspector-9pMeoWpd.js} +1 -1
  26. package/dist/assets/{MetadataProvider-CjWp0ChY.js → MetadataProvider-Y0oNNDXh.js} +1 -1
  27. package/dist/assets/{MonacoImpl-_--K1JSa.js → MonacoImpl-DkEpEa5A.js} +1 -1
  28. package/dist/assets/ObjectDataPage-B8pGSNRJ.js +1 -0
  29. package/dist/assets/PageView-BBJl1RzL.js +1 -0
  30. package/dist/assets/ProfilePage-BL4aVTUO.js +1 -0
  31. package/dist/assets/{PublicFormsPage-BVEV96-N.js → PublicFormsPage-C-BWDI8O.js} +1 -1
  32. package/dist/assets/RecordDetailView-BYYpDJSj.js +9 -0
  33. package/dist/assets/RecordFormPage-SLtEal-m.js +1 -0
  34. package/dist/assets/ReportDefaultInspector-B3KEMC9M.js +3 -0
  35. package/dist/assets/ReportView-B3kMHgHe.js +2 -0
  36. package/dist/assets/{SearchResultsPage-CjSZ416m.js → SearchResultsPage-0eeyyaj-.js} +1 -1
  37. package/dist/assets/SettingsHub-BVhaidAC.js +1 -0
  38. package/dist/assets/SettingsView-D2klvVKS.js +1 -0
  39. package/dist/assets/{SystemHubPage-C5Widsf0.js → SystemHubPage-CHcrvd-n.js} +1 -1
  40. package/dist/assets/{abnfDiagram-VRR7QNED-BM2gIA2H.js → abnfDiagram-VRR7QNED-D2Rn6aHa.js} +1 -1
  41. package/dist/assets/{architectureDiagram-ZJ3FMSHR-wyeItulr.js → architectureDiagram-ZJ3FMSHR-DX6q2vGN.js} +1 -1
  42. package/dist/assets/{assistantBus-CbDb2Mju.js → assistantBus-BqJT7SGk.js} +1 -1
  43. package/dist/assets/blockDiagram-677ZJIJ3-T2IDNrvJ.js +132 -0
  44. package/dist/assets/{c4Diagram-LMCZKHZV-CZhtNS_4.js → c4Diagram-LMCZKHZV-B98pIIbx.js} +1 -1
  45. package/dist/assets/channel-BovwC1_7.js +1 -0
  46. package/dist/assets/{chunk-32BRIVSS-CjQ2uFsO.js → chunk-32BRIVSS-CYNomNWc.js} +1 -1
  47. package/dist/assets/{chunk-52WLFC77-BBx3j8yk.js → chunk-52WLFC77-DtGIB0uV.js} +2 -2
  48. package/dist/assets/{chunk-C7G6YPKG-CrZlt4pv.js → chunk-C7G6YPKG-yJXKQ2Sz.js} +1 -1
  49. package/dist/assets/{chunk-EX3LRPZG-x9nXH4xc.js → chunk-EX3LRPZG-BtAjfq6C.js} +1 -1
  50. package/dist/assets/{chunk-FWX5IMBZ-cqzp-iMz.js → chunk-FWX5IMBZ-C4k19ShS.js} +1 -1
  51. package/dist/assets/{chunk-HOUHSVGY-Bfkm0El3.js → chunk-HOUHSVGY-BuKclK6G.js} +1 -1
  52. package/dist/assets/chunk-ICXQ74PX-OP102czk.js +2 -0
  53. package/dist/assets/{chunk-MOJQB5TN-K_QM_tTs.js → chunk-MOJQB5TN-CToOzrGu.js} +1 -1
  54. package/dist/assets/{chunk-OGEWGWER-CSkoB3Mi.js → chunk-OGEWGWER-9rMC3Zdz.js} +1 -1
  55. package/dist/assets/{chunk-PUDLZKDR-BUt9iFAU.js → chunk-PUDLZKDR-Bte-Y5BM.js} +1 -1
  56. package/dist/assets/{chunk-Q4XR5HBZ-B99LraLe.js → chunk-Q4XR5HBZ-B1-bRF4T.js} +1 -1
  57. package/dist/assets/{chunk-RYQCIY6F-CdJb5y8u.js → chunk-RYQCIY6F-DX0uHAt-.js} +1 -1
  58. package/dist/assets/{chunk-V7JOEXUC-CzVnJgzj.js → chunk-V7JOEXUC-3Qai_qvf.js} +1 -1
  59. package/dist/assets/chunk-VAUOI2AC-B2LdZG5j.js +1 -0
  60. package/dist/assets/{chunk-VR4S4FIN-B2IyRlJ4.js → chunk-VR4S4FIN-C8tYB3zk.js} +1 -1
  61. package/dist/assets/{chunk-WYO6CB5R-C0_XZtpj.js → chunk-WYO6CB5R-chyhiVml.js} +1 -1
  62. package/dist/assets/chunk-XXDRQBXY-mZd7tFTQ.js +1 -0
  63. package/dist/assets/{chunk-ZGVPDNZ5-Bq7O6ELQ.js → chunk-ZGVPDNZ5-BHJQa9Yh.js} +1 -1
  64. package/dist/assets/classDiagram-OUVF2IWQ-opUQX7yT.js +1 -0
  65. package/dist/assets/classDiagram-v2-EOCWNBFH-opUQX7yT.js +1 -0
  66. package/dist/assets/{cose-bilkent-JH36ORCC-DqKYLwMN.js → cose-bilkent-JH36ORCC-wNn6_7gi.js} +1 -1
  67. package/dist/assets/{createDerive-DGOUbVlZ.js → createDerive-DDuw-xzg.js} +1 -1
  68. package/dist/assets/{cynefinDiagram-TSTJHNR4-CFApUIdk.js → cynefinDiagram-TSTJHNR4-BpiN-sI9.js} +1 -1
  69. package/dist/assets/{dagre-VKFMJZFB-D4HlgjaA.js → dagre-VKFMJZFB-D4jpVOw8.js} +1 -1
  70. package/dist/assets/data-adapter-DJl5PvjF.js +17 -0
  71. package/dist/assets/{diagram-FQU43EPY-BcnxfyH-.js → diagram-FQU43EPY-DnGyLgYE.js} +1 -1
  72. package/dist/assets/{diagram-G47NLZAW-CJxJUVu9.js → diagram-G47NLZAW-BSDChPeN.js} +1 -1
  73. package/dist/assets/{diagram-NH7WQ7WH-DmBVlyYR.js → diagram-NH7WQ7WH-Jir-M8yF.js} +1 -1
  74. package/dist/assets/{diagram-OA4YK3LP-CkaF9SQg.js → diagram-OA4YK3LP-DG1np1W1.js} +1 -1
  75. package/dist/assets/{diagram-WEI45ONY-8cpfjoG3.js → diagram-WEI45ONY-DRm_SlrH.js} +1 -1
  76. package/dist/assets/{dist-B4b49_J4.js → dist-Bq1W1ETM.js} +1 -1
  77. package/dist/assets/{ebnfDiagram-CCIWWBDH-kX04JbNj.js → ebnfDiagram-CCIWWBDH-twfLoKY3.js} +1 -1
  78. package/dist/assets/{erDiagram-Q63AITRT-GjnOtXoL.js → erDiagram-Q63AITRT-CABXVpgy.js} +1 -1
  79. package/dist/assets/flowDiagram-23GEKE2U-DxGbSmxA.js +1 -0
  80. package/dist/assets/framework-xOBpLspS.js +8 -0
  81. package/dist/assets/{ganttDiagram-NO4QXBWP-7HpPOGwX.js → ganttDiagram-NO4QXBWP-DRXGi_1T.js} +2 -2
  82. package/dist/assets/getIcon-yTDDbwhX.js +1 -0
  83. package/dist/assets/{gitGraphDiagram-IHSO6WYX-BgBKFUwZ.js → gitGraphDiagram-IHSO6WYX-BtlNUS9M.js} +1 -1
  84. package/dist/assets/{highlighted-body-OFNGDK62-CDb4f2Sa.js → highlighted-body-OFNGDK62-BNY8_Ou8.js} +1 -1
  85. package/dist/assets/i18n-CWXRbuYk.js +9 -0
  86. package/dist/assets/index-ByFHLPS0.js +2 -0
  87. package/dist/assets/index-QgmPkr95.css +2 -0
  88. package/dist/assets/{infoDiagram-FWYZ7A6U-CTsG_9Mj.js → infoDiagram-FWYZ7A6U-CrCNJ5GX.js} +1 -1
  89. package/dist/assets/infrastructure-EMqAhl6J.js +3 -0
  90. package/dist/assets/{ishikawaDiagram-FXEZZL3T-DgMu6-jd.js → ishikawaDiagram-FXEZZL3T-aBCt2dnS.js} +1 -1
  91. package/dist/assets/{journeyDiagram-5HDEW3XC-CKI4PBJp.js → journeyDiagram-5HDEW3XC-CQrIuFhF.js} +1 -1
  92. package/dist/assets/{kanban-definition-HUTT4EX6-ChvGKWDx.js → kanban-definition-HUTT4EX6-Bm4snCw1.js} +1 -1
  93. package/dist/assets/maplibre-gl-Bee-HVIi.js +801 -0
  94. package/dist/assets/mermaid-GHXKKRXX-BN2PjcSK.js +1 -0
  95. package/dist/assets/{mermaid-parser.core-B2-C9kB8.js → mermaid-parser.core-BPoagdtX.js} +1 -1
  96. package/dist/assets/mermaid.core-C5ZaZqXX.js +10 -0
  97. package/dist/assets/metadata-admin-lW4yChcf.js +25 -0
  98. package/dist/assets/{mindmap-definition-LN4V7U3C-BSAiSefe.js → mindmap-definition-LN4V7U3C-CzSOJVqY.js} +1 -1
  99. package/dist/assets/{pegDiagram-2B236MQR-BUG9TR1Z.js → pegDiagram-2B236MQR-DPkw74l3.js} +1 -1
  100. package/dist/assets/{pieDiagram-ENE6RG2P-CqKv9PBi.js → pieDiagram-ENE6RG2P-Bnny8SeQ.js} +3 -3
  101. package/dist/assets/plugin-calendar-Dikj_A8Y.js +1 -0
  102. package/dist/assets/plugin-charts-_11K-vFF.js +7 -0
  103. package/dist/assets/plugin-chatbot-D5bVXJ_O.js +120 -0
  104. package/dist/assets/plugin-dashboard-QnlQx94Y.js +6 -0
  105. package/dist/assets/plugin-form-C8ibDrVW.js +1 -0
  106. package/dist/assets/plugin-gantt-ION4WU11.js +63 -0
  107. package/dist/assets/plugin-grid-BbCjdxhg.js +8 -0
  108. package/dist/assets/plugin-kanban-DMXe4mrr.js +1 -0
  109. package/dist/assets/{plugin-map-CsMXqW6n.css → plugin-map-CZaqx61F.css} +1 -1
  110. package/dist/assets/plugin-map-ZzwBPooc.js +1 -0
  111. package/dist/assets/{plugin-markdown-By5yxTCK.js → plugin-markdown-DWlAZYfS.js} +1 -1
  112. package/dist/assets/plugin-report-4ufmhN37.js +59 -0
  113. package/dist/assets/plugin-timeline-CxuwO6Sj.js +1 -0
  114. package/dist/assets/plugin-tree-CqFsNYBt.js +1 -0
  115. package/dist/assets/plugin-view-BtrrVg8d.js +1 -0
  116. package/dist/assets/plugins-views-DuVwtJw-.js +4 -0
  117. package/dist/assets/{quadrantDiagram-ABIIQ3AL-DyfgU6pe.js → quadrantDiagram-ABIIQ3AL-DUB4EjfP.js} +1 -1
  118. package/dist/assets/{railroadDiagram-RFXS5EU6-DOOVaoMM.js → railroadDiagram-RFXS5EU6-DSfLwOL9.js} +1 -1
  119. package/dist/assets/{requirementDiagram-TGXJPOKE-B0370dfa.js → requirementDiagram-TGXJPOKE-BUoxthLY.js} +1 -1
  120. package/dist/assets/{runtime-metadata-persistence-CEZY_PIp.js → runtime-metadata-persistence-D0qPKjRP.js} +1 -1
  121. package/dist/assets/{sankeyDiagram-HTMAVEWB-BAioZail.js → sankeyDiagram-HTMAVEWB-CkjIusFl.js} +2 -2
  122. package/dist/assets/{sequenceDiagram-DBY2YBRQ-B20vuf87.js → sequenceDiagram-DBY2YBRQ-DlUPbsBe.js} +1 -1
  123. package/dist/assets/{skeletons-D0Z3uPzj.js → skeletons-DBVC-R2R.js} +1 -1
  124. package/dist/assets/{src-YtGn_UVR.js → src-CEjEbVE_.js} +1 -1
  125. package/dist/assets/src-CLs1ObAx.js +19 -0
  126. package/dist/assets/{src-Cglm_8jd.js → src-CQ-hf48v.js} +2 -2
  127. package/dist/assets/src-Cz3xMnYk.js +1 -0
  128. package/dist/assets/{src-CKPhOIOh.js → src-DMTCYJgx.js} +1 -1
  129. package/dist/assets/{stateDiagram-2N3HPSRC-BScu2B9X.js → stateDiagram-2N3HPSRC-vPDzyRlO.js} +1 -1
  130. package/dist/assets/stateDiagram-v2-6OUMAXLB-USH3Z7UN.js +1 -0
  131. package/dist/assets/{swimlanes-5IMT3BWC-VepjEXMA.js → swimlanes-5IMT3BWC-mtpJqEnb.js} +1 -1
  132. package/dist/assets/swimlanesDiagram-G3AALYLV-CJNfyMoX.js +8 -0
  133. package/dist/assets/{timeline-definition-FHXFAJF6-CvpwpY5P.js → timeline-definition-FHXFAJF6-vFc3MiyA.js} +1 -1
  134. package/dist/assets/ui-components-C5rSjsFE.js +72 -0
  135. package/dist/assets/ui-layout-D13CmhwI.js +1 -0
  136. package/dist/assets/{use-book-data-CV2dCLgr.js → use-book-data-BJgo-RvZ.js} +1 -1
  137. package/dist/assets/{useOpenRecordList-BfKYZKMn.js → useOpenRecordList-DJ-uAshJ.js} +1 -1
  138. package/dist/assets/{usePackageL10n-DfeTyD2w.js → usePackageL10n-DM6mlODA.js} +1 -1
  139. package/dist/assets/useSettingsLabel-BJ1_MAmi.js +1 -0
  140. package/dist/assets/vendor-charts-BbCFozUm.js +67 -0
  141. package/dist/assets/{vendor-dndkit-DoG7p74h.js → vendor-dndkit-CJ2SkGrK.js} +1 -1
  142. package/dist/assets/{vendor-i18n-D2ce6sLS.js → vendor-i18n-ign3ofvT.js} +1 -1
  143. package/dist/assets/{vendor-icons-core-CO5pY7RP.js → vendor-icons-core-BuLgNLyS.js} +1 -1
  144. package/dist/assets/{vendor-markdown-DlkSIxwM.js → vendor-markdown-BgvCNR3X.js} +3 -3
  145. package/dist/assets/vendor-objectstack-ChpQDQzo.js +160 -0
  146. package/dist/assets/vendor-radix-DdNkQmkB.js +46 -0
  147. package/dist/assets/{vendor-react-BKSb6vFP.js → vendor-react-20ydC9aZ.js} +2 -2
  148. package/dist/assets/vendor-sentry-BwxF-feC.js +501 -0
  149. package/dist/assets/{vendor-ui-utils-D-WJ115h.js → vendor-ui-utils-CDPjN0GN.js} +1 -1
  150. package/dist/assets/{vennDiagram-L72KCM5P-DlCQcm_6.js → vennDiagram-L72KCM5P-NYy-CpuJ.js} +1 -1
  151. package/dist/assets/{wardleyDiagram-EHGQE667-mesER_Po.js → wardleyDiagram-EHGQE667-CB-LOOnu.js} +1 -1
  152. package/dist/assets/{xychartDiagram-FW5EYKEG-cODEcpNB.js → xychartDiagram-FW5EYKEG-C04Hz7Q2.js} +2 -2
  153. package/dist/index.html +6 -6
  154. package/package.json +3 -2
  155. package/dist/assets/AdapterProvider-CqW7TSvk.js +0 -1
  156. package/dist/assets/ApiConsolePage-DSvjQt5N.js +0 -1
  157. package/dist/assets/ApprovalsInboxPage-BV4PlaEv.js +0 -1
  158. package/dist/assets/AuditLogPage-ChJYd7GY.js +0 -1
  159. package/dist/assets/ComponentNavView-C4OkKu2y.js +0 -1
  160. package/dist/assets/CreateViewDialog-DwpQ8KvO.js +0 -1
  161. package/dist/assets/DashboardView-CuDS84Jp.js +0 -1
  162. package/dist/assets/ExpressionProvider-CyltvbX0.js +0 -1
  163. package/dist/assets/FlowRunsPage-BE8HeEGL.js +0 -1
  164. package/dist/assets/InterfaceListPage-BL7sW-SC.js +0 -1
  165. package/dist/assets/MarketplaceAccessDenied-B00hPOtj.js +0 -1
  166. package/dist/assets/MarketplacePackagePage-By15SZoJ.js +0 -4
  167. package/dist/assets/MarketplacePage-BKxIWeT_.js +0 -1
  168. package/dist/assets/ObjectDataPage-DiQJROyN.js +0 -1
  169. package/dist/assets/PageView-CJY74CxE.js +0 -1
  170. package/dist/assets/ProfilePage-CjxWQMQA.js +0 -1
  171. package/dist/assets/RecordDetailView-DpRJpP6t.js +0 -9
  172. package/dist/assets/RecordFormPage-BMs8Sa4p.js +0 -1
  173. package/dist/assets/ReportDefaultInspector-BpXXGsGu.js +0 -3
  174. package/dist/assets/ReportView-C0fP1MLd.js +0 -2
  175. package/dist/assets/SettingsHub-DhWm94wF.js +0 -1
  176. package/dist/assets/SettingsView-Dd0B_UlN.js +0 -1
  177. package/dist/assets/blockDiagram-677ZJIJ3-BybRqe6u.js +0 -132
  178. package/dist/assets/channel-BAx__6e1.js +0 -1
  179. package/dist/assets/chunk-ICXQ74PX-WsDRuBhL.js +0 -2
  180. package/dist/assets/chunk-VAUOI2AC-HYDQgaka.js +0 -1
  181. package/dist/assets/chunk-XXDRQBXY-CtU5D9C8.js +0 -1
  182. package/dist/assets/classDiagram-OUVF2IWQ-DiVkGMIZ.js +0 -1
  183. package/dist/assets/classDiagram-v2-EOCWNBFH-DiVkGMIZ.js +0 -1
  184. package/dist/assets/data-adapter-Dz0aiaG6.js +0 -9
  185. package/dist/assets/flowDiagram-23GEKE2U-CpcHvuan.js +0 -1
  186. package/dist/assets/framework-BqSgd3ir.js +0 -8
  187. package/dist/assets/getIcon-BZn0biL3.js +0 -1
  188. package/dist/assets/i18n-SjY5NweX.js +0 -9
  189. package/dist/assets/index-CgfL2xiq.js +0 -2
  190. package/dist/assets/index-De6xiiED.css +0 -2
  191. package/dist/assets/infrastructure-C6pQBkbt.js +0 -3
  192. package/dist/assets/maplibre-gl-R0DO2NBr.js +0 -748
  193. package/dist/assets/mermaid-GHXKKRXX-CWn_Hnds.js +0 -1
  194. package/dist/assets/mermaid.core-CskcjgHM.js +0 -10
  195. package/dist/assets/metadata-admin-BRw86sJ-.js +0 -25
  196. package/dist/assets/plugin-calendar-C4ZXapZt.js +0 -1
  197. package/dist/assets/plugin-charts-D5Lb0q0u.js +0 -7
  198. package/dist/assets/plugin-chatbot-dJq9DS4J.js +0 -120
  199. package/dist/assets/plugin-dashboard-Cr7jkjy7.js +0 -6
  200. package/dist/assets/plugin-form-D4kHsl47.js +0 -1
  201. package/dist/assets/plugin-gantt-8LuVErg3.js +0 -63
  202. package/dist/assets/plugin-grid-CDpGckvD.js +0 -8
  203. package/dist/assets/plugin-kanban-Xwny03DA.js +0 -1
  204. package/dist/assets/plugin-map-CVC4XDJz.js +0 -1
  205. package/dist/assets/plugin-report-DwvPiTGE.js +0 -59
  206. package/dist/assets/plugin-timeline-D2Sep4-I.js +0 -1
  207. package/dist/assets/plugin-tree-Doah8whm.js +0 -1
  208. package/dist/assets/plugin-view-DZXBuUS9.js +0 -1
  209. package/dist/assets/plugins-views-BGSw-KmQ.js +0 -4
  210. package/dist/assets/src-DPHY2JFl.js +0 -1
  211. package/dist/assets/src-RHOMTPFk.js +0 -19
  212. package/dist/assets/stateDiagram-v2-6OUMAXLB-9fyTUlZR.js +0 -1
  213. package/dist/assets/swimlanesDiagram-G3AALYLV-i6IYZT2a.js +0 -8
  214. package/dist/assets/types-BR_9hYa5.js +0 -1
  215. package/dist/assets/ui-components-Ci5ufF7g.js +0 -72
  216. package/dist/assets/ui-layout-D_8Fal4s.js +0 -1
  217. package/dist/assets/vendor-charts-HLBqza5P.js +0 -67
  218. package/dist/assets/vendor-objectstack-CjHQG7Oa.js +0 -114
  219. package/dist/assets/vendor-radix-B1fu-dZi.js +0 -46
  220. package/dist/assets/vendor-sentry-BFtl-K03.js +0 -501
@@ -0,0 +1,25 @@
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-20ydC9aZ.js";import{_ as d,y as f}from"./infrastructure-EMqAhl6J.js";import{A as p,P as m,S as h,T as g,d as _,j as v,k as y,l as b,s as x,st as S,u as C,w}from"./vendor-objectstack-ChpQDQzo.js";import{Ct as T,D as E,Dn as D,J as O,N as k,P as A,Rt as j,St as M,et as ee,in as te,rn as N,xt as ne,yn as P}from"./framework-xOBpLspS.js";import{$a as re,$i as F,$n as ie,$r as I,$s as ae,Aa as oe,Ac as se,As as ce,At as le,Bi as ue,Bo as de,Bs as fe,Ca as pe,Cc as me,Cn as he,Cr as L,Cs as ge,Da as _e,Di as ve,Do as ye,Ds as be,Ec as xe,Ei as Se,Eo as Ce,Es as we,F as Te,Fa as Ee,Fc as De,Ft as Oe,Gc as ke,Gi as Ae,Go as je,Gr as Me,Ha as Ne,Hc as Pe,Hi as Fe,Ho as Ie,Hr as Le,Hs as Re,I as ze,Ic as Be,Ii as Ve,It as He,Ja as Ue,Ji as We,Jo as Ge,Jr as Ke,Js as qe,Ka as Je,Kc as Ye,Ki as Xe,Ko as Ze,Kr as Qe,Ks as $e,La as et,Li as tt,Lo as nt,Lt as rt,Mi as it,Mo as at,Mt as ot,No as st,Nt as ct,Oa as lt,Oc as ut,Os as dt,Ot as ft,P as pt,Pa as mt,Pc as ht,Pi as gt,Po as _t,Ps as vt,Pt as yt,Qa as bt,Qo as xt,Qs as St,Ra as Ct,Ri as wt,Rs as Tt,Rt as Et,Sc as Dt,Si as Ot,Sn as kt,Ss as At,Ta as jt,Tc as Mt,Tn as R,Ua as Nt,Ui as Pt,Uo as Ft,Ur as It,Vc as Lt,Vo as Rt,Vr as zt,Wc as Bt,Wo as Vt,Wr as Ht,Xa as Ut,Xi as Wt,Xo as Gt,Ya as Kt,Yi as qt,Ys as Jt,Zi as Yt,Zo as Xt,_a as Zt,_c as Qt,_n as $t,_o as en,ai as tn,an as nn,ar as rn,bc as an,bi as on,bo as sn,bs as cn,bt as ln,ci as z,cn as un,co as dn,cr as fn,cs as pn,ct as mn,dc as hn,di as gn,dn as _n,dr as vn,ds as yn,dt as bn,ei as xn,el as Sn,eo as Cn,es as wn,fc as Tn,fn as En,fo as Dn,fr as On,ga as B,gc as kn,gn as An,gr as jn,gs as Mn,ha as Nn,hc as Pn,hi as Fn,hn as In,hr as Ln,hs as Rn,ht as zn,ia as Bn,ic as Vn,ir as Hn,is as Un,ja as Wn,jt as Gn,ka as Kn,ki as qn,kn as V,ko as Jn,ks as Yn,kt as Xn,lc as Zn,ln as Qn,lr as $n,ma as er,mc as tr,mi as nr,mn as rr,mo as ir,mr as ar,ms as or,na as sr,nc as cr,no as lr,nr as ur,ns as dr,oa as fr,oc as pr,oi as mr,oo as hr,os as gr,ot as _r,pc as vr,pn as yr,po as br,pr as xr,ps as Sr,qa as Cr,qc as H,qi as wr,qo as Tr,qr as Er,qs as Dr,rc as Or,ri as kr,ro as Ar,rr as jr,sa as Mr,sc as Nr,si as Pr,sn as Fr,so as U,sr as Ir,st as Lr,tr as Rr,ts as zr,ua as Br,ui as Vr,un as Hr,ur as Ur,us as Wr,va as Gr,vo as Kr,vs as qr,wc as Jr,wn as Yr,wo as Xr,ws as Zr,xa as Qr,xi as $r,xo as ei,xt as ti,yc as ni,yo as ri,ys as ii,yt as ai,za as oi,zc as si,zi as ci,zo as li,zr as W,zs as ui,zt as di}from"./ui-components-C5rSjsFE.js";import{r as fi}from"./vendor-ui-utils-CDPjN0GN.js";import"./AdapterProvider-DCL4oNgv.js";import"./MetadataProvider-Y0oNNDXh.js";import{n as pi,o as mi}from"./assistantBus-BqJT7SGk.js";import{A as hi,F as gi,K as _i,M as vi,N as yi,W as bi,X as xi,Y as Si,j as Ci,k as wi,q as Ti}from"./RecordDetailView-BYYpDJSj.js";import{f as Ei}from"./plugin-chatbot-D5bVXJ_O.js";import{n as Di}from"./ui-layout-D13CmhwI.js";import{t as Oi}from"./InterfaceListPage-C_M0U8ns.js";import{t as ki}from"./getIcon-yTDDbwhX.js";import{a as Ai,c as ji,d as Mi,h as Ni,i as G,l as Pi,m as Fi,n as Ii,r as K,s as Li,t as Ri,u as zi}from"./i18n-CWXRbuYk.js";import{a as Bi,i as Vi,n as Hi,o as Ui,r as Wi,s as Gi,t as Ki}from"./createDerive-DDuw-xzg.js";import{A as qi,B as Ji,C as Yi,D as Xi,E as q,F as Zi,H as Qi,I as $i,K as ea,L as ta,M as na,N as ra,O as ia,P as aa,R as oa,S as sa,T as ca,U as la,V as ua,W as da,_ as fa,a as pa,b as ma,c as ha,d as ga,f as _a,g as va,h as ya,i as ba,j as xa,k as Sa,l as Ca,m as wa,n as Ta,o as Ea,p as Da,r as Oa,s as ka,t as Aa,u as ja,v as Ma,w as J,x as Na,y as Y,z as Pa}from"./ReportDefaultInspector-B3KEMC9M.js";import{n as Fa}from"./plugins-views-DuVwtJw-.js";import{r as Ia}from"./dist-Bq1W1ETM.js";var X=c(),Z=e(u(),1);function La(){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 Ra(){let{agents:e,isLoading:t}=Ei({apiBase:La()}),n=(0,Z.useRef)(!1);t&&(n.current=!0);let r=e.length>0;return{enabled:r,isLoading:r?!1:t||!n.current}}var za=`flow-palette-recents`,Ba=za,Va=5;function Ha(){try{if(typeof localStorage>`u`)return[];let e=localStorage.getItem(Ba);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`).slice(0,Va):[]}catch{return[]}}function Ua(e){if(e)try{if(typeof localStorage>`u`)return;let t=[e,...Ha().filter(t=>t!==e)].slice(0,Va);localStorage.setItem(Ba,JSON.stringify(t))}catch{}}var Wa=za;function Ga(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`).slice(0,5):[]}function Ka(e){try{let t=localStorage.getItem(Ti(Wa,e));return t?Ga(JSON.parse(t)):[]}catch{return[]}}function qa(e,t){try{localStorage.setItem(Ti(Wa,t),JSON.stringify(e))}catch{}}function Ja(e,t){if(!t)return{list:e,didMigrate:!1};let n;try{n=localStorage.getItem(Wa)}catch{return{list:e,didMigrate:!1}}if(n==null)return{list:e,didMigrate:!1};let r=[];try{r=Ga(JSON.parse(n))}catch{}try{localStorage.removeItem(Wa)}catch{}if(r.length===0)return{list:e,didMigrate:!0};let i=[...e];for(let e of r)i.includes(e)||i.push(e);return{list:i.slice(0,5),didMigrate:!0}}var Ya=(0,Z.createContext)(null);function Xa({children:e}){let{user:t}=d(),n=t?.id??null,r=xi(`flowPaletteRecents`),[i,a]=(0,Z.useState)(()=>Ka(n));Si(Ti(Wa,n),e=>{a(Ga(e))});let o=(0,Z.useMemo)(()=>_i(async e=>{r&&await r.save(e)},500),[r]);(0,Z.useEffect)(()=>()=>void o.flush(),[o]);let s=(0,Z.useCallback)(e=>{qa(e,n),r&&o.schedule(e)},[n,r,o]),c=(0,Z.useRef)(0);(0,Z.useEffect)(()=>{let e=++c.current,t=!1;return(async()=>{let i=Ka(n),s=r?Ga(await r.load().catch(()=>[])):[];if(t||e!==c.current)return;let{list:l,didMigrate:u}=Ja(s.length?s:i,n);a(l),qa(l,n),u&&r&&o.schedule(l)})(),()=>{t=!0}},[r,n,o]);let l=(0,Z.useCallback)(e=>{e&&a(t=>{let n=[e,...t.filter(t=>t!==e)].slice(0,5);return s(n),n})},[s]),u=(0,Z.useMemo)(()=>({recents:i,recordRecent:l}),[i,l]);return(0,X.jsx)(Ya.Provider,{value:u,children:e})}function Za(){let e=(0,Z.useContext)(Ya),[t,n]=(0,Z.useState)(()=>Ha()),r=(0,Z.useCallback)(e=>{Ua(e),n(Ha())},[]);return e||{recents:t,recordRecent:r}}function Qa(e,t){if(!t)return!0;let n=t.toLowerCase();return e.value.toLowerCase().includes(n)||e.label.toLowerCase().includes(n)||(e.group?.toLowerCase().includes(n)??!1)}function $a({label:e,value:t,onCommit:n,options:r,placeholder:i=`Select…`,searchPlaceholder:a=`Search or type…`,emptyText:o=`No match — keep typing to use a custom value.`,disabled:s,loading:c,allowCustom:l=!0,mono:u,className:d}){let[f,p]=Z.useState(!1),[m,h]=Z.useState(``),g=r.find(e=>e.value===t),_=g?g.label:t||(c?`Loading…`:i),v=Z.useMemo(()=>r.filter(e=>Qa(e,m)),[r,m]),y=Z.useMemo(()=>{let e=[],t=new Map;for(let n of v){let r=n.group??``;t.has(r)||(t.set(r,[]),e.push(r)),t.get(r).push(n)}return e.map(e=>({heading:e,items:t.get(e)}))},[v]),b=m.trim(),x=l&&!!b&&!r.some(e=>e.value===b),S=e=>{n(e),p(!1),h(``)},C=(0,X.jsxs)(kt,{open:f,onOpenChange:e=>{p(e),e||h(``)},children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsxs)(W,{type:`button`,variant:`outline`,role:`combobox`,"aria-expanded":f,disabled:s,className:H(`h-8 w-full justify-between px-2 text-sm font-normal`,d),children:[(0,X.jsx)(`span`,{className:H(`truncate`,u&&`font-mono`,!g&&!t&&`text-muted-foreground`),children:_}),(0,X.jsx)(ae,{className:`ml-2 h-3.5 w-3.5 shrink-0 opacity-50`})]})}),(0,X.jsx)(he,{align:`start`,className:`w-[var(--radix-popover-trigger-width)] min-w-[14rem] p-0`,children:(0,X.jsxs)(ie,{shouldFilter:!1,children:[(0,X.jsx)(jr,{value:m,onValueChange:h,placeholder:a}),(0,X.jsxs)(rn,{children:[!x&&v.length===0&&(0,X.jsx)(Rr,{children:o}),x&&(0,X.jsx)(ur,{children:(0,X.jsx)(Hn,{value:`__custom__${b}`,onSelect:()=>S(b),children:(0,X.jsxs)(`span`,{className:`truncate`,children:[`Use `,(0,X.jsxs)(`span`,{className:`font-mono`,children:[`“`,b,`”`]})]})})}),y.map((e,n)=>(0,X.jsx)(ur,{heading:e.heading||void 0,children:e.items.map(e=>(0,X.jsxs)(Hn,{value:e.value,onSelect:()=>S(e.value),children:[(0,X.jsx)(Nr,{className:H(`h-3.5 w-3.5`,e.value===t?`opacity-100`:`opacity-0`)}),(0,X.jsx)(`span`,{className:`truncate font-mono`,children:e.value}),e.label&&e.label!==e.value&&(0,X.jsx)(`span`,{className:`ml-1 truncate text-muted-foreground`,children:e.label}),e.hint&&(0,X.jsx)(`span`,{className:`ml-auto pl-2 text-[10px] text-muted-foreground`,children:e.hint})]},e.value))},e.heading||`g${n}`))]})]})})]});return e?(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),C]}):C}var eo=[`object`,`page`,`dashboard`,`report`,`url`,`group`],to=[`default`,`view`,`record`,`filters`],no={object:{targetKey:`objectName`,metaType:`object`},page:{targetKey:`pageName`,metaType:`page`},dashboard:{targetKey:`dashboardName`,metaType:`dashboard`},report:{targetKey:`reportName`,metaType:`report`},url:{targetKey:`url`},group:{}};function ro(e){return(e.pageType??e.type)!==`record`}var io=[`objectName`,`viewName`,`recordId`,`recordMode`,`filters`,`pageName`,`dashboardName`,`reportName`,`url`,`target`,`params`],ao=[`path`,`kind`,`href`,`route`,`object`,`page`,`dashboard`,`report`],oo={object:`object`,page:`page`,dashboard:`dashboard`,report:`report`,link:`url`,url:`url`,group:`group`};function so(e){let t=e.type;if(typeof t==`string`&&eo.includes(t))return t;let n=e.kind;if(typeof n==`string`&&oo[n])return oo[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 co(e){if(e.recordId)return`record`;let t=e.filters;return t&&typeof t==`object`&&!Array.isArray(t)?`filters`:e.viewName?`view`:`default`}function lo(e=[]){let t={};for(let n of[...io,...ao])e.includes(n)||(t[n]=void 0);return t}var uo={default:[`objectName`],view:[`objectName`,`viewName`],record:[`objectName`,`recordId`,`recordMode`],filters:[`objectName`,`filters`]};function fo(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 po=[`nav`,`navigation`,`tabs`,`items`,`menu`];function mo(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 ho(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 go(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:Sa(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=Sa(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function _o(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 vo(e,t){let n=Ui(),[r,i]=Z.useState({options:[],loading:!!e});return Z.useEffect(()=>{if(!e){i({options:[],loading:!1});return}let r=!1;return i(e=>({...e,loading:!0})),n.list(e).then(e=>{if(r)return;let n=(Array.isArray(e)?e:[]).filter(e=>e&&typeof e.name==`string`&&e.name).filter(e=>!t||t(e)).map(e=>({value:String(e.name),label:typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:String(e.name)}));i({options:n,loading:!1})}).catch(()=>{r||i({options:[],loading:!1})}),()=>{r=!0}},[n,e,t]),r}var yo={currentUserId:`{current_user_id}`,currentOrgId:`{current_org_id}`};function bo({objectName:e,filters:t,onCommit:n,disabled:r,locale:i}){let{fields:a}=xa(e||void 0),o=Z.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground`,children:K(`engine.inspector.appNav.filters`,i)}),s.map(([e,t],n)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)($a,{value:e,onCommit:e=>c(n,e,t),options:o,placeholder:K(`engine.inspector.appNav.filtersField`,i),disabled:r,mono:!0})}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`=`}),(0,X.jsx)(`input`,{value:t,onChange:t=>c(n,e,t.target.value),placeholder:K(`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,X.jsx)(`button`,{type:`button`,onClick:()=>l(n),disabled:r,className:`rounded p-1 text-muted-foreground hover:bg-muted`,"aria-label":K(`engine.inspector.appNav.filtersRemove`,i),"data-testid":`nav-filter-remove-${e||`new`}`,children:(0,X.jsx)(Qe,{className:`h-3 w-3`})})]},`${e}-${n}`)),(0,X.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,X.jsx)(B,{className:`h-3 w-3`}),K(`engine.inspector.appNav.filtersAdd`,i)]}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:K(`engine.inspector.appNav.filtersHint`,i)})]})}function xo({selection:e,draft:t,name:n,onPatch:r,onClearSelection:i,onSelectionChange:a,locale:o,readOnly:s}){let c=mo(e.id),{node:l,parent:u,index:d}=c?ho(t,c):{node:null,parent:[],index:-1},f=l?so(l):null,p=l?co(l):`default`,m=String(l?.objectName??l?.object??``),h=vo(f===`object`?`object`:void 0),g=f&&f!==`object`?no[f].metaType:void 0,_=vo(g,g===`page`?ro:void 0),v=vo(f===`object`&&p===`view`?`view`:void 0),y=Z.useMemo(()=>m?v.options.filter(e=>e.value.startsWith(`${m}.`)||!e.value.includes(`.`)):v.options,[v.options,m]);if(!c||!l)return(0,X.jsx)(ca,{kindLabel:K(`engine.inspector.appNav.kind`,o),title:e.label??e.id,onClose:i,closeLabel:K(`engine.inspector.appNav.close`,o),children:(0,X.jsx)(ma,{message:e.id})});let b=l.label??l.title??l.name??e.id,x=e=>{let n=e.type??l.type??f??void 0;r(go(t,c,{...l,id:fo(l,u),...n?{type:n}:{},...e}))},S=e=>{let t=no[e].targetKey,n=e===`object`?uo.default:t?[t]:[];x({type:e,...lo(n)})},C=e=>{let t=lo(uo[e]);x(e===`filters`?{...t,objectName:m,filters:l.filters??{}}:{...t,objectName:m})},w=()=>{r(go(t,c,null)),i()},T=e=>{let n=ia(u,d,e);r(_o(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(b)})},E=f&&f!==`group`?Di({...l,type:f},`/apps/${n||`app`}`,yo).href:null,D=no[f??`group`];return(0,X.jsxs)(ca,{kindLabel:K(`engine.inspector.appNav.kind`,o),title:String(b),onClose:i,closeLabel:K(`engine.inspector.appNav.close`,o),headerActions:(0,X.jsx)(Yi,{index:d,total:u.length,onMove:T,upLabel:K(`engine.inspector.reorder.up`,o),downLabel:K(`engine.inspector.reorder.down`,o),disabled:s}),footer:(0,X.jsx)(sa,{label:K(`engine.inspector.appNav.remove`,o),onClick:w,disabled:s}),children:[(0,X.jsx)(q,{label:K(`engine.inspector.appNav.label`,o),value:String(l.label??l.title??l.name??``),onCommit:e=>x({label:e}),disabled:s}),(0,X.jsx)(q,{label:K(`engine.inspector.appNav.icon`,o),value:String(l.icon??``),onCommit:e=>x({icon:e}),disabled:s}),(0,X.jsx)(J,{label:K(`engine.inspector.appNav.typeField`,o),value:f??``,options:eo.map(e=>({value:e,label:K(`engine.inspector.appNav.type.${e}`,o)})),onCommit:e=>S(e),disabled:s}),f===`object`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)($a,{label:K(`engine.inspector.appNav.object`,o),value:m,options:h.options,loading:h.loading,onCommit:e=>x({objectName:e,object:void 0}),disabled:s,mono:!0}),(0,X.jsx)(J,{label:K(`engine.inspector.appNav.targetMode`,o),value:p,options:to.map(e=>({value:e,label:K(`engine.inspector.appNav.mode.${e}`,o)})),onCommit:e=>C(e),disabled:s||!m}),p===`view`&&(0,X.jsx)($a,{label:K(`engine.inspector.appNav.view`,o),value:String(l.viewName??``),options:y,loading:v.loading,onCommit:e=>x({viewName:e}),disabled:s,mono:!0}),p===`record`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(q,{label:K(`engine.inspector.appNav.recordId`,o),value:String(l.recordId??``),onCommit:e=>x({recordId:e}),disabled:s,mono:!0}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:K(`engine.inspector.appNav.recordIdHint`,o)}),(0,X.jsx)(J,{label:K(`engine.inspector.appNav.recordMode`,o),value:String(l.recordMode??`view`),options:[{value:`view`,label:K(`engine.inspector.appNav.recordModeView`,o)},{value:`edit`,label:K(`engine.inspector.appNav.recordModeEdit`,o)}],onCommit:e=>x({recordMode:e}),disabled:s})]}),p===`filters`&&(0,X.jsx)(bo,{objectName:m,filters:l.filters??{},onCommit:e=>x({filters:e}),disabled:s,locale:o})]}),f&&f!==`object`&&f!==`group`&&D.targetKey&&(D.metaType?(0,X.jsx)($a,{label:K(`engine.inspector.appNav.type.${f}`,o),value:String(l[D.targetKey]??``),options:_.options,loading:_.loading,onCommit:e=>x({[D.targetKey]:e}),disabled:s,mono:!0}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(q,{label:K(`engine.inspector.appNav.url`,o),value:String(l.url??l.href??``),onCommit:e=>x({url:e,href:void 0}),disabled:s,mono:!0}),(0,X.jsx)(J,{label:K(`engine.inspector.appNav.urlTarget`,o),value:String(l.target??`_self`),options:[{value:`_self`,label:K(`engine.inspector.appNav.urlTargetSelf`,o)},{value:`_blank`,label:K(`engine.inspector.appNav.urlTargetBlank`,o)}],onCommit:e=>x({target:e}),disabled:s})]})),E&&(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 px-2 py-1.5`,"data-testid":`nav-target-preview`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:K(`engine.inspector.appNav.preview`,o)}),(0,X.jsx)(`div`,{className:`break-all font-mono text-[11px]`,children:E})]})]})}var So=po;function Co(e){if(!e||!e.startsWith(`nav:`))return null;let t=e.slice(4);return t.length>0?t:null}function wo(e){return`nav:${e}`}var To=`surface`;function Eo(e){return`${e.type}:${e.name}`}function Do(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 Oo(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 So){let r=e[t];if(!Array.isArray(r))continue;let i=n(r,t);if(i)return i}return null}function ko(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 Ao=new Set([`lookup`,`master_detail`,`masterdetail`,`master-detail`]);function jo(e,t){if(typeof e==`string`&&e)return e;if(e&&typeof e==`object`){let t=e.default;if(typeof t==`string`&&t)return t}return t}function Mo(e){let t=e.reference??e.reference_to??e.referenceTo??e.reference_to_object;if(typeof t==`string`&&t)return t;if(Array.isArray(t)&&typeof t[0]==`string`)return t[0];if(t&&typeof t==`object`){let e=t.object;if(typeof e==`string`&&e)return e}}function No(e){switch(e){case`lookup`:case`master_detail`:case`masterDetail`:case`master-detail`:return`lookup`;case`date`:case`datetime`:case`time`:return`date`;case`number`:case`currency`:case`percent`:case`int`:case`integer`:case`float`:case`double`:case`autonumber`:return`number`;case`boolean`:case`toggle`:return`boolean`;default:return`string`}}function Po(e,t){if(!e)return{label:t,fields:[],relationships:[]};let n=jo(e.label,t),r=Pa(e.fields).entries.map(e=>({name:e.name,label:jo(e.def.label,e.name),type:typeof e.def.type==`string`?e.def.type:void 0,def:e.def}));return{label:n,fields:r,relationships:r.filter(e=>e.type&&Ao.has(e.type.toLowerCase())).map(e=>({name:e.name,label:e.label,referenceTo:Mo(e.def)}))}}function Fo(e,t,n){let r=e,i=[];for(let e of t.split(`.`)){let t=r.relationships.find(t=>t.name===e);if(!t?.referenceTo)return;let a=n[t.referenceTo];if(!a)return;i.push(t.label),r=a}return{target:r,labels:i}}function Io(e,t,n){let r=e.fields.map(t=>({value:t.name,label:t.label,type:t.type,group:e.label}));for(let i of t){let t=Fo(e,i,n);if(!t)continue;let a=[...t.labels,t.target.label].join(` → `);for(let e of t.target.fields)r.push({value:`${i}.${e.name}`,label:e.label,type:e.type,group:a})}return r}function Lo(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e))return e.some(e=>Lo(e,t));let n=e;return typeof n.dataset==`string`&&n.dataset===t||Object.values(n).some(e=>e&&typeof e==`object`&&Lo(e,t))}function Ro(){let e=Ui(),[t,n]=Z.useState({options:[],loading:!0});return Z.useEffect(()=>{let t=!1;return n(e=>({...e,loading:!0})),e.list(`object`).then(e=>{if(t)return;let r=(Array.isArray(e)?e:[]).map(e=>({name:typeof e.name==`string`?e.name:``,label:jo(e.label,typeof e.name==`string`?e.name:``)})).filter(e=>!!e.name).sort((e,t)=>e.label.localeCompare(t.label));n({options:r,loading:!1})}).catch(()=>{t||n({options:[],loading:!1})}),()=>{t=!0}},[e]),t}function zo(e,t){let n=Ui(),r=t.join(`\0`),[i,a]=Z.useState({relationships:[],fieldOptions:[],loading:!!e});return Z.useEffect(()=>{if(!e){a({relationships:[],fieldOptions:[],loading:!1});return}let t=!1;return a(e=>({...e,loading:!0})),(async()=>{try{let i=await n.get(`object`,e);if(t)return;let o=Po(i,e),s=r?r.split(`\0`):[],c={[e]:o},l=async e=>{if(c[e])return c[e];let t;try{t=Po(await n.get(`object`,e),e)}catch{t=Po(null,e)}return c[e]=t,t};for(let e of s){let t=o;for(let n of e.split(`.`)){let e=t.relationships.find(e=>e.name===n);if(!e?.referenceTo)break;t=await l(e.referenceTo)}}if(t)return;let u=[...o.relationships];for(let e of s){if(e.split(`.`).length>=3)continue;let t=Fo(o,e,c);if(t)for(let n of t.target.relationships)u.push({name:`${e}.${n.name}`,label:`${e}.${n.name}`,referenceTo:n.referenceTo})}a({relationships:u,fieldOptions:Io(o,s,c),loading:!1})}catch{t||a({relationships:[],fieldOptions:[],loading:!1})}})(),()=>{t=!0}},[n,e,r]),i}function Bo(e){let t=Ui(),[n,r]=Z.useState({reports:0,dashboards:0,loading:!!e});return Z.useEffect(()=>{if(!e){r({reports:0,dashboards:0,loading:!1});return}let n=!1;return r(e=>({...e,loading:!0})),(async()=>{let[i,a]=await Promise.all([t.list(`report`).catch(()=>[]),t.list(`dashboard`).catch(()=>[])]);n||r({reports:(Array.isArray(i)?i:[]).filter(t=>Lo(t,e)).length,dashboards:(Array.isArray(a)?a:[]).filter(t=>Lo(t,e)).length,loading:!1})})(),()=>{n=!0}},[t,e]),n}function Vo(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 Ho(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 Uo(e){let t=new Set;for(let n of e){let e=Ho(n);e&&t.add(e)}return t}function Wo(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function Go(e,t){return e===t?null:e>t?e-1:e}function Ko(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function qo({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}=xa(i||void 0,a),m=Z.useMemo(()=>{let e=new Map;for(let t of d)e.set(t.name,t.type);return e},[d]),[h,g]=Z.useState(null),[_,v]=Z.useState(null),y=Z.useCallback(n=>{c({[e]:{...t,columns:n}})},[c,e,t]),b=Z.useCallback(t=>{let i=Xi(n,Wo(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=Z.useCallback(t=>{let r=Sa(n,t,null);if(y(r),o!=null){let n=Go(o,t);n==null?l?.(null):l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Vo(r[n],n)})}},[n,y,o,e,l]),S=Z.useCallback((t,r)=>{if(t===r)return;let i=ia(n,t,r);if(y(i),o!=null){let n=Ko(o,t,r);l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Vo(i[n],n)})}},[n,y,o,e,l]),C=Z.useCallback(t=>{l?.({kind:`column`,id:`${e}.columns[${t}]`,label:Vo(n[t],t)})},[n,e,l]),w=Uo(n);return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:`Columns`}),(0,X.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:n.length})]}),n.length===0?(0,X.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,X.jsx)(`div`,{className:`space-y-1`,children:n.map((e,t)=>(0,X.jsx)(ka,{index:t,label:Vo(e,t),fieldName:Ho(e),fieldType:m.get(Ho(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,X.jsx)(Ea,{fields:d,usedNames:w,loading:f,error:p,onAdd:b})]})}var Jo=[`record`,`current_user`,`user`,`features`,`app`,`data`,`ctx`];function Yo(e){if(e==null)return`null`;let t=typeof e;return t===`string`?JSON.stringify(e):t===`number`||t===`boolean`?String(e):Array.isArray(e)?`[${e.map(Yo).join(`, `)}]`:JSON.stringify(String(e))}function Xo(e){if(!e.field||!e.operator)return``;let t=`record[${JSON.stringify(e.field)}]`;switch(e.operator){case`equals`:return`${t} == ${Yo(e.value)}`;case`not_equals`:return`${t} != ${Yo(e.value)}`;case`greater_than`:return`${t} > ${Yo(e.value)}`;case`less_than`:return`${t} < ${Yo(e.value)}`;case`contains`:return`${t}.contains(${Yo(e.value)})`;case`in`:return`${t} in ${Yo(Array.isArray(e.value)?e.value:[e.value])}`;default:return``}}function Zo(e){return typeof e.condition==`string`?e.condition:e.condition&&typeof e.condition==`object`&&typeof e.condition.source==`string`?e.condition.source:typeof e.expression==`string`?e.expression:Xo(e)}function Qo(e){let t=Zo(e),n={};if(e.style&&typeof e.style==`object`)for(let[t,r]of Object.entries(e.style))r!=null&&(n[t]=String(r));return e.backgroundColor&&(n.backgroundColor=String(e.backgroundColor)),e.textColor&&(n.color=String(e.textColor)),e.borderColor&&(n.borderColor=String(e.borderColor)),{condition:t,style:n}}function $o({label:e,value:t,onChange:n,disabled:r}){return(0,X.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:e}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`input`,{type:`color`,value:/^#([0-9a-f]{6})$/i.test(t)?t:`#000000`,disabled:r,onChange:e=>n(e.target.value),className:`h-7 w-8 shrink-0 rounded border border-input bg-background p-0.5 disabled:opacity-60`,"aria-label":e}),(0,X.jsx)(R,{value:t,placeholder:`#RRGGBB`,disabled:r,onChange:e=>n(e.target.value),className:`h-7 text-xs font-mono`})]})]})}function es({rules:e,onChange:t,objectName:n,fieldNames:r,disabled:i,t:a}){let o=Z.useMemo(()=>Array.isArray(e)?e.map(Qo):[],[e]),s=e=>t(e),c=(e,t)=>{let n=o.map((n,r)=>r===e?{...n,...t}:n);s(n)},l=(e,t,n)=>{let r={...o[e].style};n?r[t]=n:delete r[t],c(e,{style:r})},u=()=>s([...o,{condition:``,style:{}}]),d=e=>s(o.filter((t,n)=>n!==e)),f=(e,t)=>{let n=e+t;if(n<0||n>=o.length)return;let r=o.slice();[r[e],r[n]]=[r[n],r[e]],s(r)};return(0,X.jsxs)(`div`,{className:`space-y-2`,"data-testid":`cf-editor`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:a(`engine.inspector.view.cf.title`)}),(0,X.jsxs)(W,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 px-2 text-xs`,disabled:i,onClick:u,"data-testid":`cf-add`,children:[(0,X.jsx)(B,{className:`mr-1 h-3.5 w-3.5`}),a(`engine.inspector.view.cf.add`)]})]}),o.length===0&&(0,X.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:a(`engine.inspector.view.cf.empty`)}),o.map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded-md border border-border p-2 space-y-2`,"data-testid":`cf-rule-${t}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:[a(`engine.inspector.view.cf.rule`),` `,t+1]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,X.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6`,disabled:i||t===0,onClick:()=>f(t,-1),"aria-label":a(`engine.inspector.view.cf.moveUp`),"data-testid":`cf-up-${t}`,children:(0,X.jsx)(Or,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6`,disabled:i||t===o.length-1,onClick:()=>f(t,1),"aria-label":a(`engine.inspector.view.cf.moveDown`),"data-testid":`cf-down-${t}`,children:(0,X.jsx)(pr,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(W,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6 text-destructive hover:text-destructive`,disabled:i,onClick:()=>d(t),"aria-label":a(`engine.inspector.view.cf.remove`),"data-testid":`cf-remove-${t}`,children:(0,X.jsx)(gn,{className:`h-3.5 w-3.5`})})]})]}),(0,X.jsx)(ya,{label:a(`engine.inspector.view.cf.when`),value:e.condition,disabled:i,placeholder:`record.status == 'overdue'`,objectName:n,fieldNames:r,scope:`flattened`,roots:Jo,onChange:e=>c(t,{condition:e}),t:a,id:`cf-condition-${t}`}),(0,X.jsxs)(`div`,{className:H(`grid gap-2 sm:grid-cols-3`),children:[(0,X.jsx)($o,{label:a(`engine.inspector.view.cf.background`),value:e.style.backgroundColor??``,disabled:i,onChange:e=>l(t,`backgroundColor`,e)}),(0,X.jsx)($o,{label:a(`engine.inspector.view.cf.text`),value:e.style.color??``,disabled:i,onChange:e=>l(t,`color`,e)}),(0,X.jsx)($o,{label:a(`engine.inspector.view.cf.border`),value:e.style.borderColor??``,disabled:i,onChange:e=>l(t,`borderColor`,e)})]}),(0,X.jsx)(`div`,{className:`rounded border border-dashed border-border px-2 py-1 text-xs`,style:e.style,"data-testid":`cf-preview-${t}`,children:a(`engine.inspector.view.cf.preview`)})]},t))]})}var ts={io:`input`,unrepresentable:`any`},ns=new Set([`columns`,`data`,`name`]),rs,is=!1;function as(){if(rs||is)return rs;try{rs=S(y,ts)}catch(e){is=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return rs}function os(){return as()?.properties?.list}function ss(){return as()?.properties?.form}var cs,ls=!1;function us(){if(cs||ls)return cs;try{cs=S(w,ts)}catch(e){ls=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return cs}var ds;function fs(){if(ds)return ds;if(!(!m||typeof m!=`object`)){try{let e=JSON.parse(JSON.stringify(m));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!ns.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),ds=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return ds}}var ps=new Set([`form`,`detail`]);function ms(e){return ps.has(e)}function hs(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function gs(e,t){return typeof e==`string`&&ps.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&ps.has(t)?`form`:`list`}function _s(e){let t=e.config;return hs(t)?[{storeKey:`config`,familyKey:gs(e.viewKind,t.type),schema:t}]:[]}function vs(e){return _s(e)[0]}function ys(e,t){return vs(e)}function bs({label:e,value:t,onCommit:n,placeholder:r,disabled:i}){let{options:a,loading:o}=Ro();return(0,X.jsx)($a,{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 xs=new Set([`type`,`object`,`label`,`columns`,`conditionalFormatting`]),Ss={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`};function Cs(e,t){let n=`engine.inspector.view.type.${e}`,r=K(n,t);return r===n?Ss[e]??e:r}var ws=[`columns`,`data`,`name`];function Ts(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 Es(e,t){return Z.useMemo(()=>{let n=os()?.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:Cs(e,t)}));return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:Cs(e,t)}),r},[e,t])}function Ds({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=ms(n??t),p=typeof d.type==`string`?d.type:`grid`,m=Es(p,l),h=Ts(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}=xa(h.value||void 0,c),b=Z.useCallback(e=>K(e,l),[l]),x=Z.useMemo(()=>y.map(e=>e.name),[y]),S=Array.isArray(d.conditionalFormatting)?d.conditionalFormatting:[],C=Z.useMemo(()=>({objectFields:y.map(e=>({name:e.name,label:e.label,type:e.type}))}),[y]),w=(()=>{let e=u?.properties;return f?e?.form:e?.list})(),{schema:T,form:E}=Z.useMemo(()=>pa({bundledSchema:f?ss():os(),bundledForm:f?void 0:fs(),serverSchema:w,excludeFields:xs,sectionTitle:K(`engine.inspector.moreFields`,l)}),[f,w,l]),D=e=>{i({[t]:{...d,...e}})};return(0,X.jsxs)(ca,{kindLabel:K(`engine.inspector.view.kind`,l),title:String(g||e.name||t),onClose:()=>o?.(),closeLabel:K(`engine.inspector.view.close`,l),hideClose:r,children:[(0,X.jsx)(q,{label:K(`engine.inspector.view.label`,l),value:g,onCommit:e=>{i({label:e,[t]:{...d,label:e}})},placeholder:K(`engine.inspector.view.labelPlaceholder`,l),disabled:a}),(0,X.jsx)(J,{label:K(`engine.inspector.view.type`,l),value:p,options:m,onCommit:e=>D({type:e}),disabled:a}),(0,X.jsx)(bs,{label:K(`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:K(`engine.inspector.view.objectPlaceholder`,l),disabled:a}),!f&&(0,X.jsx)(`div`,{className:`border-t pt-3`,children:(0,X.jsx)(qo,{variantKey:t,schema:d,columns:_,allStrings:v,objectName:h.value||void 0,objectFieldsOverride:c,selectedIndex:null,readOnly:a,onPatch:i,onSelectionChange:s})}),!f&&(0,X.jsx)(`div`,{className:`border-t pt-3`,children:(0,X.jsx)(es,{rules:S,objectName:h.value||void 0,fieldNames:x,disabled:a,t:b,onChange:e=>D({conditionalFormatting:e.length>0?e:void 0})})}),(0,X.jsx)(`div`,{className:`border-t pt-3`,children:T?(0,X.jsx)(ga,{schema:T,form:E,value:d,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:C,onChange:e=>{let n={...e};for(let e of ws)e in d?n[e]=d[e]:delete n[e];i({[t]:n})}}):(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:K(`engine.inspector.view.noSchema`,l)})})]})}function Os({appSlug:e}={}){let t=i(),n=Ui(),{entries:r}=Gi(n),[a,o]=Z.useState(!1),[s,c]=Z.useState(``),[l,u]=Z.useState(null),[d,f]=Z.useState(!1),[p,m]=Z.useState(0),h=Ni();Z.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)},[]),Z.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=Z.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)||Pi(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]);Z.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,X.jsx)(Ir,{open:a,onOpenChange:o,children:(0,X.jsxs)(fn,{className:`max-w-2xl p-0 overflow-hidden`,children:[(0,X.jsx)(vn,{className:`sr-only`,children:(0,X.jsx)(On,{children:K(`engine.quickfind.title`,h)})}),(0,X.jsxs)(`div`,{className:`border-b px-3 py-2 flex items-center gap-2`,children:[(0,X.jsx)(We,{className:`h-4 w-4 text-muted-foreground`}),(0,X.jsx)(R,{autoFocus:!0,placeholder:K(`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,X.jsx)(_r,{children:`esc`})]}),(0,X.jsxs)(`div`,{className:`max-h-[440px] overflow-auto`,children:[d&&(0,X.jsxs)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}),K(`engine.quickfind.indexing`,h),` `,r.length,`…`]}),!d&&g.length===0&&(0,X.jsx)(`div`,{className:`px-3 py-6 text-xs text-muted-foreground text-center`,children:K(`engine.quickfind.noMatches`,h)}),(0,X.jsx)(`ul`,{role:`listbox`,children:g.map((e,t)=>(0,X.jsx)(`li`,{children:(0,X.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,X.jsx)(L,{variant:`outline`,className:`text-[10px] font-mono shrink-0`,children:e.kind===`type`?`type`:e.type}),(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:e.kind===`type`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium truncate`,children:Pi(e.entry.type,h,e.entry.label)}),e.entry.description&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:e.entry.description})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`text-sm font-mono truncate flex items-center gap-1.5`,children:[e.lock&&e.lock!==`none`&&(0,X.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400 shrink-0`,title:e.lockReason??`_lock=${e.lock}`,"aria-label":`locked`,children:(0,X.jsx)(hr,{className:`h-3 w-3`})}),e.name,e.label&&(0,X.jsx)(`span`,{className:`text-muted-foreground font-sans ml-2`,children:e.label})]}),e.description&&(0,X.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,X.jsxs)(`div`,{className:`border-t px-3 py-1.5 flex items-center gap-3 text-[10px] text-muted-foreground`,children:[(0,X.jsxs)(`span`,{children:[(0,X.jsx)(_r,{children:`↑`}),` `,(0,X.jsx)(_r,{children:`↓`}),` navigate`]}),(0,X.jsxs)(`span`,{children:[(0,X.jsx)(_r,{children:`↵`}),` open`]}),(0,X.jsxs)(`span`,{className:`ml-auto`,children:[(0,X.jsx)(_r,{children:`⌘`}),(0,X.jsx)(_r,{children:`⇧`}),(0,X.jsx)(_r,{children:`M`}),` toggle`]})]})]})})}var ks=new Set([`system`,`cloud`]);function As(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&&!ks.has(e.scope));return t.sort((e,t)=>e.name.localeCompare(t.name)),t.map(e=>({id:e.id,name:e.name}))}var js={data:ge,ui:ri,automation:Ke,ai:gt,system:Ae,platform:Ae,identity:Fe,security:Fe},Ms=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],Ns=new Set([`field`,`package`]);function Ps(){let e=Ui(),{loading:t,error:r,entries:i}=Gi(e),a=Ni(),[s,c]=Z.useState(``),[l,u]=Z.useState(`all`),[d,f]=Z.useState(!1),[p,m]=o(),[h,g]=Z.useState(null);Z.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;g(As(n))}catch{t||g([])}})(),()=>{t=!0}},[e]);let _=p.get(`package`),v=Z.useMemo(()=>h?_&&h.some(e=>e.id===_)?_:h[0]?.id??null:null,[h,_]);Z.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}=Bi(e,`warning`,v??void 0),E=Z.useMemo(()=>i.filter(e=>Ns.has(e.type)||!v?!1:(w[e.type]??[]).includes(v)),[i,v,w]),D=Z.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)||Pi(e.type,a,e.label).toLowerCase().includes(t)||(e.description??``).toLowerCase().includes(t)))return!1}return!0}),A=Z.useMemo(()=>{let e={};for(let t of k)(e[t.domain??`other`]??=[]).push(t);return Object.entries(e).sort(([e],[t])=>{let n=Ms.indexOf(e),r=Ms.indexOf(t);return(n===-1?99:n)-(r===-1?99:r)})},[k]);return t||h===null||v&&T?(0,X.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:K(`engine.directory.loading`,a)}):r?(0,X.jsxs)(`div`,{className:`p-6 text-sm text-destructive`,children:[K(`engine.directory.loadFailed`,a),`: `,r]}):(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold`,children:K(`engine.directory.title`,a)}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,dangerouslySetInnerHTML:{__html:G(`engine.directory.description`,a,{count:`<strong class="text-foreground">${E.length}</strong>`,writable:O})}}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 mt-4 flex-wrap`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1 min-w-[240px] max-w-lg`,children:[(0,X.jsx)(We,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(R,{className:`pl-8`,placeholder:K(`engine.directory.search`,a),value:s,onChange:e=>c(e.target.value)})]}),(0,X.jsxs)(W,{variant:d?`default`:`outline`,size:`sm`,onClick:()=>f(e=>!e),children:[K(`engine.directory.writableOnly`,a),` (`,O,`)`]}),x.total>0&&(0,X.jsx)(W,{asChild:!0,variant:`outline`,size:`sm`,className:`border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive`,children:(0,X.jsxs)(n,{to:`./_diagnostics`,children:[(0,X.jsx)(z,{className:`h-3.5 w-3.5 mr-1`}),G(`engine.directory.diagnosticsLink`,a,{count:x.total})]})}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,children:[K(`engine.directory.quickFind`,a),` `,(0,X.jsx)(_r,{children:`⌘`}),(0,X.jsx)(_r,{children:`⇧`}),(0,X.jsx)(_r,{children:`M`})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 mt-3 flex-wrap`,children:[(0,X.jsx)(Fs,{domain:`all`,label:K(`engine.directory.all`,a),active:l===`all`,count:D.all??0,onClick:()=>u(`all`)}),Ms.filter(e=>D[e]).map(e=>(0,X.jsx)(Fs,{domain:e,label:ji(e,a),active:l===e,count:D[e]??0,onClick:()=>u(e)},e))]})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[h.length===0&&(0,X.jsxs)(Lr,{children:[(0,X.jsx)(bn,{children:`No project packages installed`}),(0,X.jsx)(mn,{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,X.jsxs)(Lr,{children:[(0,X.jsx)(bn,{children:K(`engine.directory.noMatches`,a)}),(0,X.jsx)(mn,{children:K(`engine.directory.noMatchesHint`,a)})]}),A.map(([e,t])=>(0,X.jsxs)(`section`,{className:`space-y-2`,children:[(0,X.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-1.5`,children:[(0,X.jsx)(js[e]??Mt,{className:`h-3.5 w-3.5`}),ji(e,a),` (`,t.length,`)`]}),(0,X.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,X.jsx)(Is,{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,X.jsx)(Os,{})]})}function Fs({domain:e,label:t,active:n,count:r,onClick:i}){return(0,X.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,X.jsxs)(`span`,{className:`opacity-70 ml-0.5`,children:[`(`,r,`)`]})]})}function Is({entry:e,locale:t,invalidCount:r=0,warnCount:i=0,itemCount:a=0,lockedCount:o=0,packageFilter:s}){let c=Pi(e.type,t,e.label);return(0,X.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,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`font-medium truncate flex items-center gap-1.5`,children:[r>0&&(0,X.jsx)(`span`,{title:G(`engine.directory.invalidTooltip`,t??`en`,{count:r}),"aria-label":G(`engine.directory.invalidTooltip`,t??`en`,{count:r}),children:(0,X.jsx)(z,{className:`h-3.5 w-3.5 text-destructive shrink-0`})}),c]}),(0,X.jsx)(`code`,{className:`text-xs text-muted-foreground font-mono`,children:e.type})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,X.jsx)(L,{variant:`secondary`,className:`text-[10px] tabular-nums`,title:G(`engine.directory.itemCountTooltip`,t??`en`,{count:a}),children:a}),r>0&&(0,X.jsx)(L,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,title:G(`engine.directory.invalidTooltip`,t??`en`,{count:r}),children:r}),i>0&&(0,X.jsx)(L,{variant:`outline`,className:`text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300 bg-amber-500/[0.06]`,title:G(`engine.directory.warnTooltip`,t??`en`,{count:i}),children:i}),o>0&&(0,X.jsxs)(L,{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,X.jsx)(hr,{className:`h-2.5 w-2.5`}),o]}),e.allowOrgOverride?(0,X.jsx)(L,{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:K(`engine.badge.writable`,t)}):e.allowRuntimeCreate?(0,X.jsx)(L,{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:K(`engine.badge.createOnly`,t)}):(0,X.jsx)(L,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:K(`engine.badge.readOnly`,t)})]})]}),e.description&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-2 line-clamp-2`,children:e.description})]})}function Ls(e){let t=e?.data??e,n=Array.isArray(t)?t:t?.packages??[],r=[];for(let e of n){if(!e||typeof e!=`object`)continue;let t=e.manifest??{},n=String(t.id??e.id??``);if(!n)continue;let i=typeof t.scope==`string`?t.scope:``;if(i===`system`||i===`cloud`)continue;let a=typeof t.namespace==`string`&&t.namespace?t.namespace:C(n);r.push({id:n,name:String(t.name??n),writable:i!==`project`,namespace:a})}return r}async function Rs(){let e=await fetch(`/api/v1/packages`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!e.ok)throw Error(`HTTP ${e.status}`);return Ls(await e.json())}async function zs(e,t,n){let r=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/duplicate`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({targetPackageId:t,...n?{targetName:n}:{}})}),i=await r.json().catch(()=>null);if(!r.ok||i?.success===!1)throw Error(i?.error?.message||`HTTP ${r.status}`)}var Bs=/^[a-z][a-z0-9_.-]*(\.[a-z0-9_-]+)+$/,Vs=/^[a-z][a-z0-9_]{1,19}$/;function Hs(e,t){return t&&_(e,t)?`${t}_${e}`:e}function Us(e){let t=e.toLowerCase().replace(/[^a-z0-9_.-]/g,``);return{value:t,stripped:t.length!==e.length}}var Ws={io:`input`,unrepresentable:`any`},Gs,Ks=!1;function qs(){if(Gs||Ks)return Gs;try{Gs=S(b,Ws)}catch(e){Ks=!0,typeof console<`u`&&console.warn(`[package-schema] failed to derive manifest JSONSchema from spec`,e)}return Gs}function Js(e){return{type:`modal`,sections:[{label:K(`engine.packages.form.basics`,e),columns:1,fields:[{field:`name`,label:K(`engine.packages.create.name`,e),placeholder:`Acme CRM`},{field:`id`,label:K(`engine.packages.create.id`,e),placeholder:`com.acme.crm`,immutable:!0},{field:`namespace`,label:K(`engine.packages.create.namespace`,e),placeholder:`crm`,immutable:!0},{field:`version`,label:K(`engine.packages.create.version`,e),placeholder:`0.1.0`},{field:`type`,label:K(`engine.packages.detail.type`,e),immutable:!0},{field:`description`,label:K(`engine.packages.detail.description`,e)}]},{label:K(`engine.packages.form.advanced`,e),collapsible:!0,collapsed:!0,columns:1,fields:[{field:`defaultDatasource`,label:K(`engine.packages.form.defaultDatasource`,e),immutable:!0},{field:`scope`,label:K(`engine.packages.form.scope`,e),immutable:!0},{field:`dependencies`,label:K(`engine.packages.form.dependencies`,e),immutable:!0}]}]}}var Ys=`/api/v1/packages`,Xs=/^\d+\.\d+\.\d+$/;async function Zs(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})`,t=Error(typeof e==`string`?e:`Request failed (${n.status})`);throw t.status=n.status,t}return i?.data??i}function Qs(){try{window.dispatchEvent(new CustomEvent(`objectui:packages-changed`))}catch{}}function $s({mode:e,open:t,onOpenChange:n,manifest:r,onSaved:i}){let a=Ni(),o=Z.useMemo(()=>qs(),[]),s=Z.useMemo(()=>Js(a),[a]),c=e===`create`,l=e===`view`,[u,d]=Z.useState({}),[f,p]=Z.useState(!1),[m,h]=Z.useState(null),g=Z.useRef(!1);Z.useEffect(()=>{t&&(g.current=!1,d(c?{version:`0.1.0`,type:`app`}:{...r??{}}),h(null),p(!1))},[t,c,r]);let _=Z.useCallback(e=>{if(!c){d(e);return}d(t=>{let n=e.namespace;return n!==t.namespace&&(g.current=!0,n=String(n??``).toLowerCase().replace(/[^a-z0-9_]/g,``)),!g.current&&e.id!==t.id&&(n=C(String(e.id??``))??``),{...e,namespace:n}})},[c]),v=Z.useMemo(()=>{if(l)return[];let e=b.safeParse(u);return e.success?[]:e.error.issues.map(e=>({path:e.path.join(`.`),message:e.message}))},[u,l]),y=!!String(u.name??``).trim(),x=String(u.version??``).trim(),S=c?Xs.test(x):!x||Xs.test(x),w=!c||!!String(u.id??``).trim(),T=!c||Vs.test(String(u.namespace??``).trim()),E=!l&&y&&S&&w&&T&&!f;async function D(){if(E){p(!0),h(null);try{let t;if(c){let n={...u,id:String(u.id??``).trim(),name:String(u.name??``).trim(),version:x,type:u.type??`app`},r=await Zs(Ys,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:n})});t={id:String(r?.manifest?.id??n.id),mode:e,package:r}}else{let n=String(r?.id??u.id??``);t={id:n,mode:e,package:await Zs(`${Ys}/${encodeURIComponent(n)}`,{method:`PATCH`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:String(u.name??``).trim(),description:String(u.description??``).trim(),version:x})})}}Qs(),i?.(t),n(!1)}catch(e){let t=e?.message??``;e?.status===409||/already exists/i.test(t)?h(K(`engine.packages.create.exists`,a)):h(t||K(c?`engine.packages.create.failed`:`engine.packages.edit.failed`,a))}finally{p(!1)}}}return(0,X.jsx)(Ir,{open:t,onOpenChange:n,children:(0,X.jsxs)(fn,{className:`max-h-[85vh] overflow-y-auto`,children:[(0,X.jsxs)(vn,{children:[(0,X.jsx)(On,{children:K(e===`create`?`engine.packages.create.title`:e===`edit`?`engine.packages.edit.title`:`engine.packages.view.title`,a)}),e===`create`?(0,X.jsx)($n,{children:G(`engine.packages.create.description`,a,{example:`com.acme.crm`})}):(0,X.jsx)($n,{className:`font-mono text-xs`,children:String(r?.id??u.id??``)})]}),(0,X.jsx)(`div`,{className:`py-1`,"data-testid":`package-form`,children:(0,X.jsx)(ga,{schema:o,form:s,value:u,onChange:_,issues:v,readOnly:l,createMode:c})}),m&&(0,X.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,X.jsx)(z,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,X.jsx)(`span`,{children:m})]}),(0,X.jsx)(Ur,{children:l?(0,X.jsx)(W,{variant:`outline`,onClick:()=>n(!1),children:K(`engine.close`,a)}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{variant:`outline`,onClick:()=>n(!1),disabled:f,children:K(`engine.cancel`,a)}),(0,X.jsx)(W,{onClick:D,disabled:!E,"data-testid":`package-form-submit`,children:K(f?c?`engine.packages.create.creating`:`engine.packages.edit.saving`:c?`engine.packages.create.submit`:`engine.packages.edit.save`,a)})]})})]})})}var ec=`/api/v1/packages`;async function tc(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 nc({scope:e}){let t=Ni();if(!e)return(0,X.jsx)(L,{className:`bg-emerald-400/15 text-emerald-600 hover:bg-emerald-400/15 dark:text-emerald-300`,children:K(`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,X.jsx)(L,{variant:n,children:r?K(r,t):e})}function rc({pkg:e}){let t=Ni(),n=e.enabled!==!1&&e.status!==`disabled`;return(0,X.jsx)(L,{variant:n?`default`:`outline`,children:K(n?`engine.packages.status.enabled`:`engine.packages.status.disabled`,t)})}function ic({open:e,onOpenChange:t,onCreated:n}){return(0,X.jsx)($s,{mode:`create`,open:e,onOpenChange:t,onSaved:e=>n(e.id)})}function ac({label:e,children:t}){return(0,X.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 py-1.5`,children:[(0,X.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-right break-all`,children:t})]})}function oc({pkg:e,open:t,onOpenChange:n,onSaved:r}){return(0,X.jsx)($s,{mode:`edit`,open:t,onOpenChange:n,manifest:e?.manifest??null,onSaved:t=>r(t.package??e)})}function sc({pkg:e,appBase:t,open:r,onOpenChange:i,onChanged:a}){let o=Ni(),[s,c]=Z.useState(null),[l,u]=Z.useState(null),[d,f]=Z.useState(null),[p,m]=Z.useState(!1),[h,g]=Z.useState(!1);if(Z.useEffect(()=>{u(null),c(null)},[e?.manifest.id]),Z.useEffect(()=>{let t=e?.manifest.id;if(!r||!t){f(null);return}let n=!1;return tc(`/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 _=e.manifest.id,v=e.enabled!==!1&&e.status!==`disabled`,y=e.manifest.scope===`system`||e.manifest.scope===`cloud`;async function b(e,t,n){c(e),u(null);try{await t(),u({kind:`ok`,text:n}),a()}catch(e){u({kind:`err`,text:e?.message??K(`engine.packages.detail.actionFailed`,o)})}finally{c(null)}}return(0,X.jsx)(Fr,{open:r,onOpenChange:i,children:(0,X.jsxs)(un,{className:`w-full sm:max-w-md overflow-y-auto`,children:[(0,X.jsxs)(Hr,{children:[(0,X.jsxs)(_n,{className:`flex items-center gap-2`,children:[(0,X.jsx)(et,{className:`h-4 w-4`}),e.manifest.name||_]}),(0,X.jsx)(Qn,{className:`font-mono text-xs`,children:_})]}),(0,X.jsxs)(`div`,{className:`mt-4`,children:[(0,X.jsx)(ac,{label:K(`engine.packages.col.version`,o),children:e.manifest.version||`—`}),(0,X.jsx)(ac,{label:K(`engine.packages.detail.type`,o),children:e.manifest.type||`—`}),(0,X.jsx)(ac,{label:K(`engine.packages.col.scope`,o),children:(0,X.jsx)(nc,{scope:e.manifest.scope})}),(0,X.jsx)(ac,{label:K(`engine.packages.col.status`,o),children:(0,X.jsx)(rc,{pkg:e})}),e.manifest.description&&(0,X.jsx)(ac,{label:K(`engine.packages.detail.description`,o),children:e.manifest.description})]}),t&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(En,{className:`my-4`}),(0,X.jsxs)(n,{to:`${t}/metadata/object?package=${encodeURIComponent(_)}`,className:`inline-flex items-center gap-1.5 text-sm text-primary hover:underline`,onClick:()=>i(!1),children:[(0,X.jsx)(Rn,{className:`h-3.5 w-3.5`}),K(`engine.packages.detail.browseMetadata`,o)]})]}),d&&d.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(En,{className:`my-4`}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`p`,{className:`flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:[K(`engine.packages.detail.pendingChanges`,o),(0,X.jsx)(L,{variant:`secondary`,children:d.length})]}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:K(`engine.packages.detail.pendingHint`,o)}),!y&&(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsxs)(W,{size:`sm`,onClick:()=>b(`publish-drafts`,()=>tc(`${ec}/${encodeURIComponent(_)}/publish-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{let e=await tc(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(_)}`);f(e?.drafts??[])}catch{f([])}if(e?.failedCount){let t=Array.isArray(e.failed)?e.failed:[],n=t.find(e=>!N(e,`BATCH_ABORTED`)&&e?.error);throw t.some(e=>N(e,`BATCH_ABORTED`))?Error(G(`engine.packages.detail.publishDraftsRolledBack`,o,{cause:n?`${n.type??`?`}/${n.name??`?`}: ${n.error}`:String(e.failedCount)})):Error(G(`engine.packages.detail.publishDraftsPartial`,o,{published:e.publishedCount??0,failed:e.failedCount}))}return e}),K(`engine.packages.detail.publishDraftsOk`,o)),disabled:!!s,children:[(0,X.jsx)(tn,{className:`mr-1.5 h-3.5 w-3.5`}),s===`publish-drafts`?K(`engine.packages.detail.publishing`,o):G(`engine.packages.detail.publishApp`,o,{count:d.length})]}),(0,X.jsxs)(W,{size:`sm`,variant:`outline`,onClick:()=>b(`discard-drafts`,()=>tc(`${ec}/${encodeURIComponent(_)}/discard-drafts`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({})}).then(async e=>{try{let e=await tc(`/api/v1/meta/_drafts?packageId=${encodeURIComponent(_)}`);f(e?.drafts??[])}catch{f([])}if(e?.failedCount)throw Error(G(`engine.packages.detail.discardDraftsPartial`,o,{discarded:e.discardedCount??0,failed:e.failedCount}));return e}),K(`engine.packages.detail.discardDraftsOk`,o)),disabled:!!s,children:[(0,X.jsx)(mr,{className:`mr-1.5 h-3.5 w-3.5`}),s===`discard-drafts`?K(`engine.packages.detail.discarding`,o):G(`engine.packages.detail.discardChanges`,o,{count:d.length})]})]}),(0,X.jsx)(`ul`,{className:`space-y-1`,children:d.map(e=>t?(0,X.jsx)(`li`,{children:(0,X.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,X.jsx)(zr,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]})},`${e.type}/${e.name}`):(0,X.jsxs)(`li`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,X.jsx)(zr,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono text-xs`,children:e.type}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),e.name]},`${e.type}/${e.name}`))})]})]}),(0,X.jsx)(En,{className:`my-4`}),y?(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:K(`engine.packages.detail.kernelReadOnly`,o)}):(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:K(`engine.packages.detail.actions`,o)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsxs)(W,{size:`sm`,variant:`outline`,onClick:()=>g(!0),disabled:!!s,children:[(0,X.jsx)(Sr,{className:`mr-1.5 h-3.5 w-3.5`}),K(`engine.packages.detail.viewInfo`,o)]}),(0,X.jsxs)(W,{size:`sm`,variant:`outline`,onClick:()=>m(!0),disabled:!!s,children:[(0,X.jsx)(pe,{className:`mr-1.5 h-3.5 w-3.5`}),K(`engine.packages.detail.edit`,o)]}),(0,X.jsxs)(W,{size:`sm`,onClick:()=>b(`publish`,()=>tc(`${ec}/${encodeURIComponent(_)}/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?G(`engine.packages.detail.publishBlocked`,o,{count:t}):e.validationErrors?.[0]?.message||K(`engine.packages.detail.nothingToPublish`,o))}return e}),K(`engine.packages.detail.published`,o)),disabled:!!s,children:[(0,X.jsx)(tn,{className:`mr-1.5 h-3.5 w-3.5`}),K(s===`publish`?`engine.packages.detail.publishing`:`engine.packages.detail.publish`,o)]}),(0,X.jsxs)(W,{size:`sm`,variant:`outline`,onClick:()=>b(`revert`,()=>tc(`${ec}/${encodeURIComponent(_)}/revert`,{method:`POST`}),K(`engine.packages.detail.reverted`,o)),disabled:!!s,children:[(0,X.jsx)(mr,{className:`mr-1.5 h-3.5 w-3.5`}),K(`engine.packages.detail.revert`,o)]}),(0,X.jsxs)(W,{size:`sm`,variant:`outline`,onClick:()=>b(`toggle`,()=>tc(`${ec}/${encodeURIComponent(_)}/${v?`disable`:`enable`}`,{method:`PATCH`}),K(v?`engine.packages.detail.disabled`:`engine.packages.detail.enabled`,o)),disabled:!!s,children:[v?(0,X.jsx)(Nn,{className:`mr-1.5 h-3.5 w-3.5`}):(0,X.jsx)(er,{className:`mr-1.5 h-3.5 w-3.5`}),K(v?`engine.packages.detail.disable`:`engine.packages.detail.enable`,o)]}),(0,X.jsxs)(W,{size:`sm`,variant:`outline`,onClick:()=>b(`export`,async()=>{let e=await tc(`${ec}/${encodeURIComponent(_)}/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=`${_}.package.json`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)},K(`engine.packages.detail.exported`,o)),disabled:!!s,children:[(0,X.jsx)(ii,{className:`mr-1.5 h-3.5 w-3.5`}),K(s===`export`?`engine.packages.detail.exporting`:`engine.packages.detail.export`,o)]}),(0,X.jsxs)(W,{size:`sm`,variant:`outline`,onClick:async()=>{let t=window.prompt(K(`engine.packages.detail.duplicatePrompt`,o),`${_}-copy`);if(!(!t||!t.trim())){c(`duplicate`),u(null);try{await tc(`${ec}/${encodeURIComponent(_)}/duplicate`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({targetPackageId:t.trim(),targetName:`${e?.manifest.name??_} (copy)`})}),u({kind:`ok`,text:K(`engine.packages.detail.duplicated`,o)}),a()}catch(e){u({kind:`err`,text:e?.message??`Duplicate failed`})}finally{c(null)}}},disabled:!!s,children:[(0,X.jsx)(we,{className:`mr-1.5 h-3.5 w-3.5`}),K(s===`duplicate`?`engine.packages.detail.duplicating`:`engine.packages.detail.duplicate`,o)]}),(0,X.jsxs)(W,{size:`sm`,variant:`outline`,onClick:async()=>{if(window.confirm(G(`engine.packages.detail.adoptConfirm`,o,{name:e?.manifest.name||_}))){c(`adopt`),u(null);try{await tc(`${ec}/${encodeURIComponent(_)}/adopt-orphans`,{method:`POST`}),u({kind:`ok`,text:K(`engine.packages.detail.adopted`,o)}),a()}catch(e){u({kind:`err`,text:e?.message??`Adopt failed`})}finally{c(null)}}},disabled:!!s,children:[(0,X.jsx)(ye,{className:`mr-1.5 h-3.5 w-3.5`}),K(s===`adopt`?`engine.packages.detail.adopting`:`engine.packages.detail.adoptOrphans`,o)]}),(0,X.jsxs)(W,{size:`sm`,variant:`outline`,onClick:async()=>{if(!window.confirm(G(`engine.packages.detail.deleteConfirm`,o,{name:e?.manifest.name||_})))return;let t=window.confirm(K(`engine.packages.detail.deleteKeepData`,o))?``:`?keepData=true`;c(`delete`),u(null);try{await tc(`${ec}/${encodeURIComponent(_)}${t}`,{method:`DELETE`}),a(),i(!1)}catch(e){u({kind:`err`,text:e?.message??K(`engine.packages.detail.deleteFailed`,o)})}finally{c(null)}},disabled:!!s,className:`text-destructive hover:bg-destructive/10 hover:text-destructive`,children:[(0,X.jsx)(gn,{className:`mr-1.5 h-3.5 w-3.5`}),K(s===`delete`?`engine.packages.detail.deleting`:`engine.packages.detail.deleteApp`,o)]})]})]}),l&&(0,X.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,X.jsx)(oc,{pkg:e,open:p,onOpenChange:m,onSaved:()=>{u({kind:`ok`,text:K(`engine.packages.edit.saved`,o)}),a()}}),(0,X.jsx)($s,{mode:`view`,open:h,onOpenChange:g,manifest:e?.manifest??null})]})})}function cc(){let e=Ni(),{pathname:t}=r(),n=Z.useMemo(()=>{let e=t.indexOf(`/component`);return e>=0?t.slice(0,e):t},[t]),[i,a]=Z.useState([]),[o,s]=Z.useState(!0),[c,l]=Z.useState(null),[u,d]=Z.useState(``),[f,p]=Z.useState(!1),[m,h]=Z.useState(!1),[g,_]=Z.useState(null),[v,y]=Z.useState(!1),b=Z.useRef(null),[x,S]=Z.useState(!1),[C,w]=Z.useState(null),T=Z.useCallback(async()=>{s(!0),l(null);try{let e=await tc(ec),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??K(`engine.packages.loadFailed`,e))}finally{s(!1)}},[e]);Z.useEffect(()=>{T()},[T]),Z.useEffect(()=>{if(!g)return;let e=i.find(e=>e.manifest.id===g.manifest.id);e&&e!==g&&_(e)},[i,g]);let E=Z.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))},[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(K(`engine.packages.import.invalidJson`,e))}if(!r||typeof r!=`object`||!r.id&&!r.name)throw Error(K(`engine.packages.import.invalidPackage`,e));let i=await tc(`/api/v1/marketplace/install-local`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({manifest:r})});w({kind:`ok`,text:G(`engine.packages.import.success`,e,{id:i?.manifestId??r.id})}),await T()}catch(t){w({kind:`err`,text:t?.message??K(`engine.packages.import.failed`,e)})}finally{S(!1)}}},k=i.filter(e=>e.manifest.scope===`system`||e.manifest.scope===`cloud`).length;return(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-6 py-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,X.jsx)(`div`,{className:`rounded-lg bg-primary/10 p-2 text-primary`,children:(0,X.jsx)(et,{className:`h-5 w-5`})}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight`,children:K(`engine.packages.title`,e)}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:K(`engine.packages.description`,e)})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>void T(),disabled:o,children:[(0,X.jsx)(Mr,{className:`mr-1.5 h-3.5 w-3.5 ${o?`animate-spin`:``}`}),K(`engine.packages.refresh`,e)]}),(0,X.jsx)(`input`,{ref:b,type:`file`,accept:`application/json,.json`,className:`hidden`,onChange:O}),(0,X.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>b.current?.click(),disabled:x,children:[(0,X.jsx)(zr,{className:`mr-1.5 h-3.5 w-3.5`}),K(x?`engine.packages.importing`:`engine.packages.import`,e)]}),(0,X.jsxs)(W,{size:`sm`,onClick:()=>h(!0),children:[(0,X.jsx)(B,{className:`mr-1.5 h-3.5 w-3.5`}),K(`engine.packages.new`,e)]})]})]}),C&&(0,X.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,X.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`relative w-full max-w-xs`,children:[(0,X.jsx)(We,{className:`absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,X.jsx)(R,{className:`pl-8`,placeholder:K(`engine.packages.search`,e),value:u,onChange:e=>d(e.target.value)})]}),k>0&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(di,{id:`show-kernel`,checked:f,onCheckedChange:p}),(0,X.jsx)(V,{htmlFor:`show-kernel`,className:`text-sm text-muted-foreground`,children:G(`engine.packages.showPlatform`,e,{count:k})})]})]}),(0,X.jsx)(`div`,{className:`mt-4 rounded-lg border`,children:o?(0,X.jsx)(`div`,{className:`space-y-2 p-4`,children:[0,1,2].map(e=>(0,X.jsx)(nn,{className:`h-10 w-full`},e))}):c?(0,X.jsxs)(`div`,{className:`flex items-start gap-2 p-4 text-sm text-destructive`,children:[(0,X.jsx)(z,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,X.jsx)(`span`,{children:c})]}):E.length===0?(0,X.jsx)(`div`,{className:`p-8`,children:(0,X.jsxs)(Lr,{children:[(0,X.jsx)(bn,{children:K(`engine.packages.empty`,e)}),(0,X.jsx)(mn,{children:i.length===0?K(`engine.packages.emptyCreate`,e):K(`engine.packages.emptyFiltered`,e)})]})}):(0,X.jsxs)(ct,{children:[(0,X.jsx)(rt,{children:(0,X.jsxs)(Et,{children:[(0,X.jsx)(He,{children:K(`engine.packages.col.name`,e)}),(0,X.jsx)(He,{children:`ID`}),(0,X.jsx)(He,{className:`w-24`,children:K(`engine.packages.col.version`,e)}),(0,X.jsx)(He,{className:`w-24`,children:K(`engine.packages.col.scope`,e)}),(0,X.jsx)(He,{className:`w-24`,children:K(`engine.packages.col.status`,e)})]})}),(0,X.jsx)(yt,{children:E.map(e=>(0,X.jsxs)(Et,{className:`cursor-pointer`,onClick:()=>D(e),children:[(0,X.jsx)(Oe,{className:`font-medium`,children:e.manifest.name||e.manifest.id}),(0,X.jsx)(Oe,{className:`font-mono text-xs text-muted-foreground`,children:e.manifest.id}),(0,X.jsx)(Oe,{children:e.manifest.version||`—`}),(0,X.jsx)(Oe,{children:(0,X.jsx)(nc,{scope:e.manifest.scope})}),(0,X.jsx)(Oe,{children:(0,X.jsx)(rc,{pkg:e})})]},e.manifest.id))})]})}),(0,X.jsx)(ic,{open:m,onOpenChange:h,onCreated:async()=>{await T()}}),(0,X.jsx)(sc,{pkg:g,appBase:n,open:v,onOpenChange:y,onChanged:()=>void T()})]})}var lc=new Set([`field`,`package`]),uc={data:ge,ui:ri,automation:Ke,ai:gt,system:Ae,platform:Ae,identity:Fe,security:Fe},dc={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`}},fc=[`data`,`ui`,`automation`,`ai`,`identity`,`security`,`system`,`platform`,`other`],pc=[`object`,`view`,`page`,`dashboard`,`report`,`flow`,`action`,`agent`],mc={object:Ot,dashboard:Kr,page:dr,report:Pn,record:Mt,metadata:ri};function hc(){let e=new Date().getHours();return e<12?`engine.home.greetingMorning`:e<18?`engine.home.greetingAfternoon`:`engine.home.greetingEvening`}function gc(e,t){let n=new Date(e).getTime();if(Number.isNaN(n))return``;let r=Math.floor((Date.now()-n)/6e4),i=new Intl.RelativeTimeFormat(t,{numeric:`auto`});if(r<1)return i.format(0,`minute`);if(r<60)return i.format(-r,`minute`);let a=Math.floor(r/60);if(a<24)return i.format(-a,`hour`);let o=Math.floor(a/24);return o<7?i.format(-o,`day`):i.format(-Math.floor(o/7),`week`)}function _c(){let e=Ui(),{loading:t,entries:r}=Gi(e),{recentItems:i}=bi(),a=Ni(),[s,c]=o(),[l,u]=Z.useState(null);Z.useEffect(()=>{let t=!1;return(async()=>{try{let n=await e.list(`package`);if(t)return;u(As(n))}catch{t||u([])}})(),()=>{t=!0}},[e]);let d=s.get(`package`),f=Z.useMemo(()=>l?d&&l.some(e=>e.id===d)?d:l[0]?.id??null:null,[l,d]);Z.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}=Bi(e,`warning`,f??void 0),b=Z.useMemo(()=>r.filter(e=>lc.has(e.type)||!f?!1:(v[e.type]??[]).includes(f)),[f,r,v]),x=Z.useMemo(()=>b.filter(e=>e.allowOrgOverride||e.allowRuntimeCreate),[b]),S=Z.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])=>(fc.indexOf(e)===-1?99:fc.indexOf(e))-(fc.indexOf(t)===-1?99:fc.indexOf(t)))},[b,_]),C=Z.useMemo(()=>{let e=new Map(x.map(e=>[e.type,e]));return pc.map(t=>e.get(t)).filter(Boolean)},[x]),w=g.total,T=!t&&!y&&w===0;return t||l===null||f&&y?(0,X.jsx)(`div`,{className:`flex h-full items-center justify-center p-8 text-sm text-muted-foreground`,children:K(`engine.home.loading`,a)}):(0,X.jsxs)(`div`,{className:`h-full overflow-auto bg-gradient-to-b from-muted/40 to-background`,children:[(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-6 py-6 space-y-6`,children:[(0,X.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,X.jsx)(`div`,{className:`pointer-events-none absolute -right-16 -top-20 h-64 w-64 rounded-full bg-white/15 blur-3xl`}),(0,X.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,X.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-[0.12]`,style:{backgroundImage:`radial-gradient(currentColor 1px, transparent 1px)`,backgroundSize:`18px 18px`}}),(0,X.jsxs)(`div`,{className:`relative flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between`,children:[(0,X.jsxs)(`div`,{className:`max-w-xl`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-white/80`,children:[(0,X.jsx)(gt,{className:`h-4 w-4`}),K(hc(),a)]}),(0,X.jsx)(`h1`,{className:`mt-2 text-3xl font-bold tracking-tight sm:text-4xl`,children:`Studio`}),(0,X.jsx)(`p`,{className:`mt-2 text-sm leading-relaxed text-white/85 sm:text-base`,children:K(`engine.home.subtitle`,a)}),(0,X.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-2.5`,children:[(0,X.jsx)(W,{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,X.jsxs)(n,{to:m,children:[(0,X.jsx)(ri,{className:`mr-1.5 h-4 w-4`}),K(`engine.home.browseAll`,a)]})}),(0,X.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,X.jsx)(We,{className:`h-3.5 w-3.5`}),K(`engine.directory.quickFind`,a),` ⌘⇧M`]})]})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-3 gap-3`,children:[(0,X.jsx)(vc,{value:b.length,label:K(`engine.home.statTypes`,a)}),(0,X.jsx)(vc,{value:x.length,label:K(`engine.home.statWritable`,a)}),(0,X.jsx)(vc,{value:l.length,label:K(`engine.home.statPackages`,a)})]})]})]}),(0,X.jsxs)(`section`,{className:`grid grid-cols-2 gap-4 lg:grid-cols-4`,children:[(0,X.jsx)(yc,{icon:ri,from:`from-indigo-500`,to:`to-violet-600`,value:b.length,label:K(`engine.home.statTypes`,a),to_link:m}),(0,X.jsx)(yc,{icon:Jt,from:`from-sky-500`,to:`to-blue-600`,value:x.length,label:K(`engine.home.statWritable`,a),to_link:m}),(0,X.jsx)(yc,{icon:et,from:`from-emerald-500`,to:`to-teal-600`,value:l.length,label:K(`engine.home.statPackages`,a),to_link:h}),(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.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,X.jsx)(Jt,{className:`h-5 w-5`}):(0,X.jsx)(z,{className:`h-5 w-5`})}),(0,X.jsx)(si,{className:`h-4 w-4 text-muted-foreground transition-transform group-hover:translate-x-0.5`})]}),(0,X.jsxs)(`div`,{className:`mt-3`,children:[(0,X.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:T?K(`engine.home.allHealthy`,a):w}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:K(T?`engine.home.allHealthyHint`:`engine.home.statIssues`,a)})]})]})]}),C.length>0&&(0,X.jsxs)(`section`,{children:[(0,X.jsx)(bc,{icon:B,title:K(`engine.home.quickActions`,a),hint:K(`engine.home.quickActionsHint`,a)}),(0,X.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2.5`,children:C.map(e=>(0,X.jsx)(W,{asChild:!0,variant:`outline`,size:`sm`,className:`group rounded-full border-transparent bg-muted hover:bg-primary/10 hover:text-primary`,children:(0,X.jsxs)(n,{to:`metadata/${encodeURIComponent(e.type)}/new${p}`,children:[(0,X.jsx)(B,{className:`mr-1 h-3.5 w-3.5 text-primary transition-transform group-hover:rotate-90`}),G(`engine.home.newItem`,a,{label:Pi(e.type,a,e.label)})]})},e.type))})]}),(0,X.jsxs)(`div`,{className:`grid gap-6 lg:grid-cols-3`,children:[(0,X.jsxs)(`section`,{className:`lg:col-span-2`,children:[(0,X.jsx)(bc,{icon:ri,title:K(`engine.home.explore`,a),hint:K(`engine.home.exploreHint`,a)}),(0,X.jsx)(`div`,{className:`mt-3 grid gap-4 sm:grid-cols-2`,children:S.map(([e,t])=>(0,X.jsx)(xc,{domain:e,group:t,countsByType:_,locale:a,packageSuffix:p},e))})]}),(0,X.jsxs)(`section`,{children:[(0,X.jsx)(bc,{icon:vt,title:K(`engine.home.recent`,a)}),(0,X.jsx)(`div`,{className:`mt-3 rounded-2xl border bg-card p-2`,children:i.length===0?(0,X.jsx)(`div`,{className:`px-3 py-8 text-center text-xs text-muted-foreground`,children:K(`engine.home.recentEmpty`,a)}):(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:i.slice(0,8).map(e=>{let t=mc[e.type]??Mt;return(0,X.jsx)(`li`,{children:(0,X.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,X.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,X.jsx)(t,{className:`h-4 w-4`})}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.label}),(0,X.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:gc(e.visitedAt,a)})]}),(0,X.jsx)(si,{className:`h-3.5 w-3.5 text-muted-foreground opacity-0 transition-opacity group-hover:opacity-100`})]})},e.id)})})})]})]})]}),(0,X.jsx)(Os,{})]})}function vc({value:e,label:t}){return(0,X.jsxs)(`div`,{className:`rounded-2xl bg-white/15 px-4 py-3 text-center backdrop-blur-sm ring-1 ring-white/20`,children:[(0,X.jsx)(`div`,{className:`text-2xl font-bold tabular-nums leading-none`,children:e}),(0,X.jsx)(`div`,{className:`mt-1 text-[11px] font-medium text-white/80`,children:t})]})}function yc({icon:e,from:t,to:r,value:i,label:a,to_link:o}){return(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.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,X.jsx)(e,{className:`h-5 w-5`})}),(0,X.jsx)(si,{className:`h-4 w-4 text-muted-foreground opacity-0 transition-all group-hover:translate-x-0.5 group-hover:opacity-100`})]}),(0,X.jsxs)(`div`,{className:`mt-3`,children:[(0,X.jsx)(`div`,{className:`text-2xl font-bold tabular-nums`,children:i}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:a})]})]})}function bc({icon:e,title:t,hint:n}){return(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2.5`,children:[(0,X.jsxs)(`h2`,{className:`flex items-center gap-2 text-base font-semibold`,children:[(0,X.jsx)(e,{className:`h-4 w-4 text-muted-foreground`}),t]}),n&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n})]})}function xc({domain:e,group:t,countsByType:r,locale:i,packageSuffix:a}){let o=uc[e]??Mt,s=dc[e]??dc.other,c=t.slice(0,6),l=t.length-c.length;return(0,X.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,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.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,X.jsx)(o,{className:`h-[18px] w-[18px]`})}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:ji(e,i)}),(0,X.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.length,` `,K(`engine.home.typesLower`,i)]})]})]}),(0,X.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:[c.map(e=>(0,X.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,X.jsx)(`span`,{className:`truncate max-w-[10rem]`,children:Pi(e.type,i,e.label)}),(0,X.jsx)(`span`,{className:`tabular-nums text-[10px] text-muted-foreground`,children:r[e.type]??0})]},e.type)),l>0&&(0,X.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 Sc({entry:e,itemName:t,subtitle:i,stats:a,actions:o,embedded:s=!1,children:c}){let l=e?.type??``,u=Ni(),d=Pi(l,u,e?.label),{pathname:f}=r(),p=Z.useMemo(()=>{let e=f.indexOf(`/metadata`);return e>=0?f.slice(0,e+9):`/metadata`},[f]);return(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[t?(0,X.jsxs)(`div`,{className:`px-6 py-2.5 border-b bg-background flex items-center gap-3 min-h-[44px]`,children:[(0,X.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground min-w-0`,children:[s?(0,X.jsx)(`span`,{className:`shrink-0`,children:d}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(n,{to:p,className:`hover:text-foreground shrink-0`,children:K(`engine.breadcrumb.allTypes`,u)}),(0,X.jsx)(Vn,{className:`h-3 w-3 shrink-0`}),(0,X.jsx)(n,{to:`${p}/${encodeURIComponent(l)}`,className:`hover:text-foreground shrink-0`,children:d})]}),(0,X.jsx)(Vn,{className:`h-3 w-3 shrink-0`}),(0,X.jsx)(`span`,{className:`text-foreground font-medium font-mono truncate`,title:t,children:t})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[e?.domain&&(0,X.jsx)(L,{variant:`outline`,className:`text-[10px] uppercase tracking-wider h-5 px-1.5`,children:ji(e.domain,u)}),e?.allowOrgOverride?(0,X.jsx)(L,{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:K(`engine.badge.writable`,u)}):e?.allowRuntimeCreate?(0,X.jsx)(L,{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:K(`engine.badge.createOnly`,u)}):(0,X.jsx)(L,{variant:`outline`,className:`text-[10px] h-5 px-1.5 text-muted-foreground`,children:K(`engine.badge.readOnly`,u)})]}),i&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground truncate`,children:i}),(0,X.jsx)(`div`,{className:`flex-1`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[a?.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-baseline gap-1 px-2 py-0.5 rounded border bg-muted/30`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,X.jsx)(`span`,{className:`text-xs font-semibold tabular-nums`,children:e.value})]},t)),o]})]}):(0,X.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[!s&&(0,X.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground mb-2`,children:[(0,X.jsx)(n,{to:p,className:`hover:text-foreground`,children:K(`engine.breadcrumb.allTypes`,u)}),(0,X.jsx)(Vn,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{className:`text-foreground font-medium`,children:d})]}),(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-3 flex-wrap`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold truncate`,children:d}),(0,X.jsx)(`code`,{className:`text-xs font-mono text-muted-foreground`,children:l}),e?.domain&&(0,X.jsx)(L,{variant:`outline`,className:`text-[10px] uppercase tracking-wider`,children:ji(e.domain,u)}),e?.allowOrgOverride?(0,X.jsx)(L,{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:K(`engine.badge.writable`,u)}):e?.allowRuntimeCreate?(0,X.jsx)(L,{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:K(`engine.badge.createOnly`,u)}):(0,X.jsx)(L,{variant:`outline`,className:`text-[10px] text-muted-foreground`,children:K(`engine.badge.readOnly`,u)})]}),i&&(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1`,children:i}),!i&&e?.description&&(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground mt-1 max-w-3xl`,children:e.description})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[a?.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex flex-col items-end px-3 py-1 rounded border bg-muted/30 min-w-[64px]`,children:[(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:e.label}),(0,X.jsx)(`span`,{className:`text-sm font-semibold tabular-nums`,children:e.value})]},t)),o]})]})]}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto`,children:c})]})}var Cc={primary:`default`,secondary:`secondary`,danger:`destructive`,ghost:`ghost`,link:`link`};function wc(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 Tc({entry:e,location:t,recordId:n,onAfter:r}){let[i,a]=Z.useState(null),[o,s]=Z.useState({open:!1,params:[]}),[c,l]=Z.useState({open:!1}),u=Z.useMemo(()=>f(),[]),d=Z.useMemo(()=>(e?.actions??[]).filter(e=>!e.locations||e.locations.length===0||e.locations.includes(t)),[e?.actions,t]);if(d.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`){fi.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=wc(e.target??``,o,i);if(!s){fi.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{}let s=o&&typeof o.success==`boolean`&&`data`in o?o.data:o;if(!a.ok||o&&o.success===!1){let n=o?.error,r=(typeof n==`object`&&n?n.message:void 0)||(typeof n==`string`?n:void 0)||o?.message||`HTTP ${a.status} ${a.statusText}`.trim();fi.error(`${e.errorMessage?`${e.errorMessage}: `:``}${t}: ${r}`);return}if(e.resultDialog)l({open:!0,spec:e.resultDialog,data:s??{}});else{let n=e.successMessage||(typeof s?.message==`string`?s.message:`${t} ✓`);fi.success(n)}e.refreshAfter&&r?.()}catch(e){fi.error(`${t}: ${e?.message??String(e)}`)}finally{a(null)}};return(0,X.jsxs)(X.Fragment,{children:[d.map(e=>{let t=e.icon?ki(e.icon):null,n=i===e.name;return(0,X.jsxs)(W,{size:`sm`,variant:Cc[e.variant??`secondary`]??`secondary`,disabled:n,onClick:()=>m(e),title:e.label??e.name,children:[n?(0,X.jsx)(U,{className:`h-4 w-4 mr-1 animate-spin`}):t?(0,X.jsx)(t,{className:`h-4 w-4 mr-1`}):null,e.label??e.name]},e.name)}),(0,X.jsx)(gi,{state:o,onOpenChange:e=>{e||(o.resolve?.(null),s({open:!1,params:[]}))}}),(0,X.jsx)(yi,{state:c,onAcknowledge:()=>l({open:!1})})]})}function Ec(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 Dc=new Map;function Oc(e){let t=Dc.get(e.type);if(!t){Dc.set(e.type,e);return}let n={...t};for(let[t,r]of Object.entries(e))r!==void 0&&(n[t]=r);Dc.set(e.type,n)}function kc(e){return Dc.get(e)}function Ac(e){let t=[];for(let n of Dc.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 jc(e,t){let n=Dc.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 Mc(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 Nc({type:e}){let t=s(),n=e??t.type??``;if(n===`package`)return(0,X.jsx)(l,{to:`/apps/${t.appName??`studio`}/component/developer/packages`,replace:!0});let r=kc(n);if(r?.ListPage){let e=r.ListPage;return(0,X.jsx)(e,{type:n})}return(0,X.jsx)(Pc,{type:n,appName:t.appName})}function Pc({type:e,appName:t}){let r=i(),a=Ui(),{entries:s}=Gi(a),c=s.find(t=>t.type===e),l=jc(e,c),[u,d]=Z.useState([]),[f,p]=Z.useState(!0),[m,h]=Z.useState(null),[g,_]=Z.useState(``),[v,y]=Z.useState(`all`),[b,x]=o(),[S,C]=Z.useState(0),[w,T]=Z.useState(null);Z.useEffect(()=>{let e=!1;return(async()=>{try{let t=await a.list(`package`);if(e)return;T(As(t))}catch{e||T([])}})(),()=>{e=!0}},[a]);let[E,D]=Z.useState(null);Z.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=Z.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]);Z.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,M]=Z.useState(!1),ee=Z.useCallback(()=>{let e=w??[];if(w!==null&&e.length===0){M(!0);return}if(e.length>0&&!k){r(`./new?package=${encodeURIComponent(e[0].id)}`);return}r(`./new${A}`)},[w,k,A,r]);Z.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:Mc(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 te=l.searchableFields??[`name`,`label`,`description`],N=Z.useMemo(()=>u.filter(e=>l.listFilter&&!l.listFilter(e.item)||!k?!1:e.item?._packageId===k),[u,k,l]),ne=N.filter(e=>!(!Vi(e.item,g,te)||v!==`all`&&e.source!==v)),P=Z.useMemo(()=>{let e={all:N.length,artifact:0,runtime:0};for(let t of N)e[t.source]++;return e},[N]),re=Z.useMemo(()=>N.filter(e=>e.diagnostics&&e.diagnostics.valid===!1).length,[N]),F=Z.useMemo(()=>N.filter(e=>e.diagnostics&&e.diagnostics.valid!==!1&&(e.diagnostics.warnings?.length??0)>0).length,[N]),ie=l.listColumns??Fc(l.primaryKey??`name`),I=Ni(),ae=Pi(e,I,c?.label??e),oe=e=>{let t=`engine.list.col.${e.key}`,n=K(t,I);return n===t?e.label:n};return(0,X.jsx)(Sc,{entry:c??{type:e,label:e},stats:[{label:K(`engine.list.items`,I),value:N.length},{label:K(`engine.list.filtered`,I),value:ne.length},...re>0?[{label:K(`engine.list.invalid`,I),value:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,X.jsx)(z,{className:`w-3.5 h-3.5`}),re]})}]:[],...F>0?[{label:K(`engine.list.warnings`,I),value:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,X.jsx)(z,{className:`w-3.5 h-3.5`}),F]})}]:[]],actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Tc,{entry:c,location:`list_toolbar`,onAfter:()=>C(e=>e+1)}),(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>C(e=>e+1),title:K(`engine.list.refresh`,I),children:(0,X.jsx)(Mr,{className:`h-4 w-4`})}),(c?.allowOrgOverride||c?.allowRuntimeCreate)&&(0,X.jsxs)(W,{size:`sm`,variant:l.createFields?`default`:`outline`,onClick:ee,title:l.createFields?G(`engine.list.createHint`,I,{type:ae}):void 0,children:[(0,X.jsx)(B,{className:`h-4 w-4 mr-1`}),K(`engine.list.create`,I)]})]}),children:(0,X.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,X.jsx)(ic,{open:j,onOpenChange:M,onCreated:e=>r(`./new?package=${encodeURIComponent(e)}`)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-md`,children:[(0,X.jsx)(We,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(R,{className:`pl-8`,placeholder:K(`engine.list.search`,I),value:g,onChange:e=>_(e.target.value)})]}),(0,X.jsxs)(yr,{value:v,onValueChange:y,children:[(0,X.jsx)(An,{className:`w-[180px]`,children:(0,X.jsx)($t,{})}),(0,X.jsxs)(rr,{children:[(0,X.jsxs)(In,{value:`all`,children:[K(`engine.list.allSources`,I),` (`,P.all,`)`]}),(0,X.jsxs)(In,{value:`artifact`,children:[K(`engine.list.source.artifact`,I),` (`,P.artifact,`)`]}),(0,X.jsxs)(In,{value:`runtime`,children:[K(`engine.list.source.runtime`,I),` (`,P.runtime,`)`]})]})]})]}),(f||w===null)&&(0,X.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[K(`engine.edit.loading`,I),` `,e,`…`]}),m&&(0,X.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,X.jsxs)(Lr,{children:[(0,X.jsx)(bn,{children:`No project packages installed`}),(0,X.jsx)(mn,{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&&ne.length===0&&(0,X.jsxs)(Lr,{children:[(0,X.jsx)(bn,{children:N.length===0?G(`engine.list.emptyType`,I,{type:ae}):G(`engine.list.emptyQuery`,I,{query:g})}),(0,X.jsx)(mn,{children:l.emptyStateHint??(c?.allowOrgOverride||c?.allowRuntimeCreate?G(`engine.list.createHint`,I,{type:ae}):K(`engine.list.readOnlyHint`,I))}),N.length===0&&(c?.allowOrgOverride||c?.allowRuntimeCreate)&&(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsxs)(W,{onClick:ee,children:[(0,X.jsx)(B,{className:`h-4 w-4 mr-1`}),K(`engine.list.create`,I)]})})]}),!f&&ne.length>0&&(0,X.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{children:[ie.map(e=>(0,X.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,style:e.width?{width:e.width}:void 0,children:oe(e)},e.key)),(0,X.jsx)(`th`,{className:`px-3 py-2 text-right font-medium w-[80px]`,children:K(`engine.list.col.source`,I)})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:ne.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,X.jsxs)(`tr`,{className:`hover:bg-accent/50 `+(s?`bg-destructive/[0.04]`:d?`bg-amber-500/[0.05]`:``),children:[ie.map((t,r)=>{let a=e.item[t.key],l=t.render?t.render(a,e.item):Ic(a);return(0,X.jsx)(`td`,{className:`px-3 py-2 align-top`,children:r===0?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[s&&(0,X.jsx)(`span`,{className:`inline-flex`,"aria-label":K(`engine.list.invalidTitle`,I),title:`${G(`engine.list.invalidCount`,I,{count:c.length})}\n${f}`,children:(0,X.jsx)(z,{className:`w-3.5 h-3.5 text-destructive shrink-0`})}),d&&(0,X.jsx)(`span`,{className:`inline-flex`,"aria-label":K(`engine.list.warnTitle`,I),title:`${G(`engine.list.warnCount`,I,{count:u.length})}\n${f}`,children:(0,X.jsx)(z,{className:`w-3.5 h-3.5 text-amber-600 dark:text-amber-400 shrink-0`})}),(0,X.jsx)(n,{to:`./${encodeURIComponent(i)}${o}`,className:`text-primary hover:underline font-mono`,children:l})]}):l},t.key)}),(0,X.jsxs)(`td`,{className:`px-3 py-2 text-right align-top`,children:[e.item._lock&&e.item._lock!==`none`&&(0,X.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,X.jsx)(hr,{className:`h-3 w-3`})}),(0,X.jsx)(L,{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`?`${K(`engine.list.source.artifactDesc`,I)}${e.item._packageId?` (${e.item._packageId})`:``}`:K(`engine.list.source.runtimeDesc`,I),children:K(`engine.list.source.${e.source}`,I)})]})]},i+t)})})]})})]})})}function Fc(e){return[{key:e,label:e,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}function Ic(e){if(e==null||e===``)return(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});if(typeof e==`boolean`)return e?`✓`:`✗`;if(typeof e==`object`)try{return(0,X.jsx)(`code`,{className:`font-mono text-xs`,children:JSON.stringify(e).slice(0,60)})}catch{return String(e)}return String(e)}var Lc={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 Rc(e,t){let n=zc(e)?e:{},r=zc(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`:Bc(o)===Bc(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 zc(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Bc(e){try{return JSON.stringify(e,(e,t)=>zc(t)?Object.keys(t).sort().reduce((e,n)=>(e[n]=t[n],e),{}):t)}catch{return String(e)}}function Vc(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 Hc(e,t){if(e==null)return 0;let n=0;for(let r of Rc(e,t))r.status!==`unchanged`&&(n+=1);return n}function Uc({layered:e,loading:t,locale:n}){if(t)return(0,X.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:K(`engine.edit.loading`,n)});if(!e)return(0,X.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:K(`engine.layers.diff.noBaseline`,n)});let r=e.overlay!=null;return(0,X.jsxs)(Xn,{defaultValue:`diff`,className:`w-full`,children:[(0,X.jsxs)(Gn,{className:`grid grid-cols-4 w-fit`,children:[(0,X.jsx)(ot,{value:`diff`,children:K(`engine.layers.diff`,n)}),(0,X.jsxs)(ot,{value:`code`,children:[K(`engine.layers.code`,n),(0,X.jsx)(L,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:Ai(`layer`,`artifact`,n)})]}),(0,X.jsxs)(ot,{value:`overlay`,children:[K(`engine.layers.overlay`,n),r?(0,X.jsx)(L,{className:`ml-1.5 text-[10px] bg-emerald-600 text-emerald-50`,children:e.overlayScope??Ai(`layer`,`set`,n)}):(0,X.jsx)(L,{variant:`outline`,className:`ml-1.5 text-[10px] text-muted-foreground`,children:Ai(`layer`,`none`,n)})]}),(0,X.jsxs)(ot,{value:`effective`,children:[K(`engine.layers.effective`,n),(0,X.jsx)(L,{variant:`outline`,className:`ml-1.5 text-[10px]`,children:Ai(`layer`,`merged`,n)})]})]}),(0,X.jsx)(le,{value:`diff`,className:`mt-3`,children:(0,X.jsx)(Wc,{code:e.code,effective:e.effective,locale:n})}),(0,X.jsx)(le,{value:`code`,className:`mt-3`,children:(0,X.jsx)(Kc,{payload:e.code,emptyHint:K(`engine.layers.diff.noBaseline`,n)})}),(0,X.jsx)(le,{value:`overlay`,className:`mt-3`,children:(0,X.jsx)(Kc,{payload:e.overlay,emptyHint:K(`engine.layers.diff.noChanges`,n)})}),(0,X.jsx)(le,{value:`effective`,className:`mt-3`,children:(0,X.jsx)(Kc,{payload:e.effective,emptyHint:`No effective value resolved.`})})]})}function Wc({code:e,effective:t,locale:n}){let[r,i]=Z.useState(!1),a=Z.useMemo(()=>e==null?[]:Rc(e,t),[e,t]),o=Z.useMemo(()=>a.reduce((e,t)=>(e[t.status]+=1,e),{unchanged:0,modified:0,added:0,removed:0}),[a]);if(e==null)return(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:K(`engine.layers.diff.noBaseline`,n)});let s=r?a:a.filter(e=>e.status!==`unchanged`),c=o.modified>0||o.added>0||o.removed>0;return(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:G(`engine.layers.diff.summary`,n,{modified:o.modified,added:o.added,removed:o.removed})}),(0,X.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground cursor-pointer select-none`,children:[(0,X.jsx)(di,{checked:r,onCheckedChange:i,"aria-label":K(`engine.layers.diff.showUnchanged`,n)}),K(`engine.layers.diff.showUnchanged`,n),(0,X.jsx)(L,{variant:`outline`,className:`ml-1 text-[10px]`,children:o.unchanged})]})]}),!c&&!r?(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 text-xs text-muted-foreground`,children:K(`engine.layers.diff.noChanges`,n)}):(0,X.jsxs)(`div`,{className:`rounded border overflow-hidden`,children:[(0,X.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,X.jsx)(`div`,{className:`px-3 py-2`,children:K(`engine.layers.diff.field`,n)}),(0,X.jsx)(`div`,{className:`px-3 py-2`,children:K(`engine.layers.diff.code`,n)}),(0,X.jsx)(`div`,{className:`px-3 py-2`,children:K(`engine.layers.diff.effective`,n)}),(0,X.jsx)(`div`,{className:`px-3 py-2`,children:K(`engine.layers.diff.status`,n)})]}),(0,X.jsx)(`div`,{className:`divide-y`,children:s.map(e=>{let t=Lc[e.status];return(0,X.jsxs)(`div`,{className:H(`grid grid-cols-[minmax(140px,1fr)_minmax(160px,1.4fr)_minmax(160px,1.4fr)_auto] text-xs`,t.row),children:[(0,X.jsx)(`div`,{className:`px-3 py-2 font-mono text-foreground truncate`,title:e.key,children:e.key}),(0,X.jsx)(Gc,{value:e.codeValue,muted:e.status===`added`}),(0,X.jsx)(Gc,{value:e.effectiveValue,muted:e.status===`removed`}),(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(`span`,{className:H(`inline-flex items-center rounded px-1.5 py-0.5 text-[10px] font-medium`,t.badge),children:K(`engine.layers.diff.${e.status}`,n)})})]},e.key)})})]})]})}function Gc({value:e,muted:t}){let n=Vc(e);return(0,X.jsx)(`div`,{className:H(`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 Kc({payload:e,emptyHint:t}){if(e==null)return(0,X.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,X.jsx)(`pre`,{className:`rounded border bg-muted/30 p-3 text-xs font-mono overflow-auto max-h-[420px]`,children:n})}var qc={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`},Jc={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 Yc(e,t){return K(e===`added`?`designer.canvas.diffAdded`:e===`removed`?`designer.canvas.diffRemoved`:`designer.canvas.diffChanged`,t)}function Xc(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 Zc(e,t){let n=0;for(let r of Rc(e,t))r.status!==`unchanged`&&(n+=1);return n}function Qc({published:e,draft:t,locale:n,className:r}){let i=Z.useMemo(()=>Rc(e,t).filter(e=>e.status!==`unchanged`),[e,t]);return i.length===0?(0,X.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground ${r??``}`,children:K(`designer.draftReview.empty`,n)}):(0,X.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,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-2 rounded-md px-2.5 py-1.5 text-xs ${Jc[t]}`,children:[(0,X.jsx)(`span`,{className:`inline-flex shrink-0 items-center rounded px-1.5 py-px text-[10px] font-medium uppercase tracking-wide ${qc[t]}`,children:Yc(t,n)}),(0,X.jsx)(`code`,{className:`font-mono font-medium text-foreground`,children:e.key}),t===`added`?(0,X.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:Xc(e.effectiveValue)}):t===`removed`?(0,X.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:Xc(e.codeValue)}):(0,X.jsxs)(`span`,{className:`inline-flex items-baseline gap-1.5 text-muted-foreground`,children:[(0,X.jsx)(`del`,{className:`text-rose-700 dark:text-rose-400`,children:Xc(e.codeValue)}),(0,X.jsx)(`span`,{"aria-hidden":`true`,children:`→`}),(0,X.jsx)(`ins`,{className:`text-emerald-700 no-underline dark:text-emerald-400`,children:Xc(e.effectiveValue)})]})]},e.key)})})}function $c({type:e,name:t,parentItem:n,onOpen:r}){let a=Ui(),o=i(),s=Z.useMemo(()=>Ac(e),[e]),[c,l]=Z.useState([]),[u,d]=Z.useState(``),[f,p]=Z.useState({});if(Z.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(el)}}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=>el(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,X.jsxs)(Lr,{children:[(0,X.jsx)(bn,{children:`No related metadata`}),(0,X.jsxs)(mn,{children:[`No metadata types are configured to anchor at `,(0,X.jsx)(`code`,{children:e}),`. You can register one via`,` `,(0,X.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,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,X.jsx)(We,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground`}),(0,X.jsx)(R,{placeholder:`Search related…`,value:u,onChange:e=>d(e.target.value),className:`pl-8 h-8 text-sm`})]}),(0,X.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,X.jsxs)(`div`,{className:`border rounded-lg overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`w-full flex items-center gap-2 px-3 py-2 bg-muted/40`,children:[(0,X.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,X.jsx)(Vn,{className:H(`h-4 w-4 text-muted-foreground transition-transform`,!a&&`rotate-90`)}),(0,X.jsx)(`div`,{className:`text-sm font-medium`,children:n.anchor.groupLabel??n.childType}),(0,X.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:n.loading?`…`:i.length})]}),(0,X.jsx)(W,{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,X.jsx)(B,{className:`h-3.5 w-3.5`})})]}),!a&&(0,X.jsxs)(`div`,{children:[n.loading&&(0,X.jsxs)(`div`,{className:`px-3 py-3 text-xs text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}),`Loading `,n.childType,`…`]}),!n.loading&&n.error&&(0,X.jsxs)(`div`,{className:`px-3 py-3 text-xs text-destructive`,children:[`Failed: `,n.error]}),!n.loading&&!n.error&&i.length===0&&(0,X.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,X.jsxs)(`table`,{className:`w-full text-sm border-t`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,X.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5 w-[45%]`,children:`Name`}),(0,X.jsx)(`th`,{className:`text-left font-medium px-3 py-1.5`,children:`Label`}),(0,X.jsx)(`th`,{className:`w-8`})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:i.map((i,a)=>(0,X.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,X.jsx)(`td`,{className:`px-3 py-1.5 font-mono text-xs truncate max-w-0`,children:i.name}),(0,X.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,X.jsx)(`td`,{className:`px-3 py-1.5 text-right`,children:(0,X.jsx)(Rn,{className:`h-3.5 w-3.5 text-muted-foreground inline`})})]},`${i.name}-${a}`))})]})]})]},n.childType)})]})}function el(e){return{name:tl(e,[`name`,`id`,`key`])??`(unnamed)`,label:tl(e,[`label`,`title`,`displayName`]),description:tl(e,[`description`,`summary`]),raw:e}}function tl(e,t){for(let n of t){let t=e[n];if(typeof t==`string`&&t.length>0)return t}}function nl({parentType:e,parentName:t,embeddedPath:n,itemName:r,editAs:i,initialRaw:a,onSaved:o}){let s=Ni(),c=Ui(),{entries:l}=Gi(c),u=i?l.find(e=>e.type===i):void 0,d=!u?.schema&&i?il[i]:void 0,f=u?.schema??d?.schema,p=u?.form??d?.form,[m,h]=Z.useState(a),[g,_]=Z.useState(!1),[v,y]=Z.useState(null),[b,x]=Z.useState([]),[S,C]=Z.useState(null);Z.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(K(`engine.embedded.saveNoPath`,s));return}_(!0),y(null),x([]);try{let i=await c.layered(e,t),a=rl(i.effective??i.code??{},n,r,m);await c.save(e,t,a),C(Date.now()),o?.(m)}catch(e){if(e?.status===422||te(e,[`INVALID_METADATA`,`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:Fi(String(e.message??`Invalid`),s)}});x(i),y(i.length===1?K(`engine.validation.failedOne`,s):G(`engine.validation.failed`,s,{count:i.length}))}else y(e?.message??String(e))}finally{_(!1)}}return f?(0,X.jsxs)(`div`,{className:`p-4 space-y-4`,children:[v&&(0,X.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:v}),S!=null&&!v&&(0,X.jsx)(`div`,{className:`text-sm text-emerald-700 border border-emerald-300 bg-emerald-50 rounded p-2`,children:K(`engine.embedded.saved`,s)}),w&&(0,X.jsx)(`div`,{className:`text-xs text-amber-800 border border-amber-300 bg-amber-50 rounded p-2`,children:K(`engine.embedded.readOnlyParent`,s)}),(0,X.jsx)(ga,{schema:f,form:p,value:m,onChange:h,issues:b}),(0,X.jsx)(`div`,{className:`flex justify-end gap-2 pt-2 border-t`,children:(0,X.jsxs)(W,{onClick:T,disabled:g||!n,children:[g?(0,X.jsx)(U,{className:`h-4 w-4 mr-1 animate-spin`}):(0,X.jsx)(Yt,{className:`h-4 w-4 mr-1`}),G(`engine.embedded.saveIntoParent`,s,{parentType:e})]})}),!n&&(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground border rounded p-3`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:K(`engine.embedded.readOnly`,s)}),(0,X.jsx)(`div`,{children:K(`engine.embedded.noPathHint`,s)})]})]}):(0,X.jsxs)(`div`,{className:`p-4 space-y-3`,children:[(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:G(`engine.embedded.noSchema`,s,{type:i??`this item`,target:`${e}/${t}.${n}.${r}`})}),(0,X.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(`${K(`engine.form.invalidJson`,s)}: ${e.message}`)}}}),v&&(0,X.jsxs)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-2 bg-destructive/5`,children:[(0,X.jsx)(z,{className:`h-4 w-4 inline mr-1`}),` `,v]}),(0,X.jsx)(`div`,{className:`flex justify-end`,children:(0,X.jsxs)(W,{onClick:T,disabled:g||!n,children:[g?(0,X.jsx)(U,{className:`h-4 w-4 mr-1 animate-spin`}):(0,X.jsx)(Yt,{className:`h-4 w-4 mr-1`}),G(`engine.embedded.saveIntoParent`,s,{parentType:`parent`})]})})]})}function rl(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 il={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 al({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,X.jsx)(Fr,{open:e!==null,onOpenChange:e=>{e||t()},children:(0,X.jsxs)(un,{side:`right`,className:H(`w-[92vw] sm:max-w-[1100px] p-0 flex flex-col gap-0`),children:[(0,X.jsxs)(Hr,{className:`px-4 py-3 border-b space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(L,{variant:`outline`,className:`font-mono text-[10px]`,children:s}),(0,X.jsx)(_n,{className:`font-mono text-base truncate`,children:c}),(0,X.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:a&&(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>{r(`../../${encodeURIComponent(e.type)}/${encodeURIComponent(e.name)}`),t()},title:`Open in full page`,children:[(0,X.jsx)(Rn,{className:`h-3.5 w-3.5 mr-1`}),`Open full page`]})})]}),n&&(0,X.jsxs)(Qn,{className:`text-xs`,children:[o?`Embedded in `:`Related to `,(0,X.jsxs)(`span`,{className:`font-mono`,children:[n.type,`/`,n.name]})]})]}),(0,X.jsxs)(`div`,{className:`flex-1 min-h-0 overflow-auto`,children:[a&&(0,X.jsx)(cu,{type:e.type,name:e.name,embedded:!0},`${e.type}/${e.name}`),o&&(0,X.jsx)(nl,{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 ol({type:e,name:t}){let n=s(),r=e??n.type??``,a=t??n.name??``,o=i(),c=Ui(),l=Ni(),{entries:u}=Gi(c),d=u.find(e=>e.type===r),[f,p]=Z.useState(0),[m,h]=Z.useState(0);return(0,X.jsx)(Sc,{entry:d??{type:r,label:r},itemName:a,subtitle:K(`engine.edit.historySubtitle`,l),stats:[{label:K(`engine.edit.historyEvents`,l),value:m}],actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>o(`../${encodeURIComponent(a)}`),children:[(0,X.jsx)(Lt,{className:`h-4 w-4 mr-1`}),`Back to item`]}),(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>p(e=>e+1),children:(0,X.jsx)(Mr,{className:`h-4 w-4`})})]}),children:(0,X.jsx)(`div`,{className:`p-6 max-w-4xl`,children:(0,X.jsx)(sl,{type:r,name:a,refreshKey:f,onCount:h,client:c,locale:l,onRollback:()=>p(e=>e+1)})})})}function sl({type:e,name:t,refreshKey:n=0,onCount:r,client:i,onRollback:a,rollbackConfirm:o,rollbackLabel:s,locale:c}){let[l,u]=Z.useState([]),[d,f]=Z.useState(!0),[p,m]=Z.useState(null),[h,g]=Z.useState(null),[_,v]=Z.useState(null),[y,b]=Z.useState(0);Z.useEffect(()=>{let n=!1;return f(!0),m(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));u(o),r?.(o.length),f(!1)}catch(e){n||(m(e?.message??String(e)),f(!1))}})(),()=>{n=!0}},[i,e,t,n,y]);async function x(n){let r=o?o(n):`Restore version ${n}? This writes the historical body back as the current overlay.`;if(confirm(r)){v(n),m(null);try{await i.rollback(e,t,n),a?.(n),b(e=>e+1)}catch(e){m(e?.message??String(e))}finally{v(null)}}}return(0,X.jsxs)(X.Fragment,{children:[d&&(0,X.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Loading history…`]}),p&&(0,X.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:p}),!d&&!p&&l.length===0&&(0,X.jsxs)(Lr,{children:[(0,X.jsx)(bn,{children:K(`engine.edit.historyEmptyTitle`,c)}),(0,X.jsx)(mn,{children:K(`engine.edit.historyEmptyDesc`,c)})]}),!d&&l.length>0&&(0,X.jsx)(`ol`,{className:`space-y-2 relative pl-6 border-l`,children:l.map((e,t)=>{let n=h===t,r=e.op??e.kind,i=e.ts??e.at,o=!!a&&typeof e.version==`number`&&r!==`delete`&&r!==`tombstone`;return(0,X.jsxs)(`li`,{className:`relative`,children:[(0,X.jsx)(`span`,{className:`absolute -left-[27px] top-2 w-3 h-3 rounded-full bg-primary ring-4 ring-background`}),(0,X.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>g(n?null:t),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&g(n?null:t)},className:`border rounded-lg p-3 hover:border-primary/50 cursor-pointer transition-colors`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,X.jsxs)(L,{variant:`outline`,className:`text-[10px] font-mono`,children:[`seq `,e.seq??`–`]}),typeof e.version==`number`&&(0,X.jsxs)(L,{variant:`outline`,className:`text-[10px] font-mono`,children:[`v`,e.version]}),r&&(0,X.jsx)(L,{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:Ai(`op`,String(r),c)}),e.actor&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`by`,` `,(0,X.jsx)(`span`,{className:`font-mono`,children:String(e.actor)})]}),i&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:cl(i)}),o&&(0,X.jsx)(W,{size:`sm`,variant:`ghost`,className:`h-6 w-6 p-0`,title:s??`Rollback to this version`,disabled:_!==null,onClick:t=>{t.stopPropagation(),x(e.version)},children:_===e.version?(0,X.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(sr,{className:`h-3.5 w-3.5`})})]}),n&&(0,X.jsx)(`pre`,{className:`mt-2 text-xs font-mono bg-muted/30 rounded p-2 overflow-auto max-h-[280px]`,children:ll(e)})]})]},`${e.seq??t}-${t}`)})})]})}function cl(e){try{let t=new Date(e);return Number.isNaN(t.getTime())?String(e):t.toLocaleString()}catch{return String(e)}}function ll(e){try{return JSON.stringify(e,null,2)}catch{return String(e)}}function ul(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function dl(e,t){let n={allowed:{label:`allowed`,cls:`bg-emerald-50 text-emerald-700 border-emerald-200`,Icon:Fe},denied:{label:`denied`,cls:`bg-rose-50 text-rose-700 border-rose-200`,Icon:ue},forced:{label:`forced`,cls:`bg-amber-50 text-amber-700 border-amber-200`,Icon:Pt}},r=n[e]??n.allowed;return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide ${r.cls}`,children:[(0,X.jsx)(r.Icon,{className:`h-3 w-3`}),Ai(`outcome`,r.label,t)]})}function fl({type:e,name:t,client:n,locale:r=`en-US`}){let[i,a]=Z.useState(!1),[o,s]=Z.useState(null),[c,l]=Z.useState(null),u=Z.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 Z.useEffect(()=>{u()},[u]),(0,X.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-b px-1 pb-2`,children:[(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[c?.length??0,` `,K(`engine.edit.auditCount`,r)]}),(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>void u(),disabled:i,className:`h-7 gap-1 text-xs`,title:K(`engine.edit.refresh`,r),children:[i?(0,X.jsx)(U,{className:`h-3 w-3 animate-spin`}):(0,X.jsx)(Mr,{className:`h-3 w-3`}),K(`engine.edit.refresh`,r)]})]}),o&&(0,X.jsx)(`div`,{className:`m-2 rounded border border-rose-200 bg-rose-50 p-2 text-xs text-rose-700`,children:o}),(0,X.jsx)(`div`,{className:`flex-1 overflow-auto`,children:i&&(!c||c.length===0)?(0,X.jsxs)(`div`,{className:`flex h-32 items-center justify-center text-xs text-muted-foreground`,children:[(0,X.jsx)(U,{className:`mr-2 h-3 w-3 animate-spin`}),K(`engine.edit.loading`,r)]}):!c||c.length===0?(0,X.jsxs)(Lr,{className:`py-10`,children:[(0,X.jsx)(bn,{children:K(`engine.edit.auditEmptyTitle`,r)}),(0,X.jsx)(mn,{children:K(`engine.edit.auditEmptyDescription`,r)})]}):(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{className:`sticky top-0 bg-muted/40 text-left text-[10px] uppercase tracking-wide text-muted-foreground`,children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:K(`engine.edit.auditColTime`,r)}),(0,X.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:K(`engine.edit.auditColActor`,r)}),(0,X.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:K(`engine.edit.auditColOperation`,r)}),(0,X.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:K(`engine.edit.auditColOutcome`,r)}),(0,X.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:K(`engine.edit.auditColLock`,r)}),(0,X.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:K(`engine.edit.auditColNote`,r)})]})}),(0,X.jsx)(`tbody`,{children:c.map(e=>(0,X.jsxs)(`tr`,{className:`border-t border-border/50 align-top hover:bg-muted/20`,children:[(0,X.jsx)(`td`,{className:`whitespace-nowrap px-2 py-1.5 font-mono text-[11px]`,children:ul(e.occurredAt)}),(0,X.jsx)(`td`,{className:`px-2 py-1.5`,children:e.actor}),(0,X.jsx)(`td`,{className:`px-2 py-1.5`,children:(0,X.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:Ai(`op`,e.operation,r)})}),(0,X.jsx)(`td`,{className:`px-2 py-1.5`,children:dl(e.outcome,r)}),(0,X.jsx)(`td`,{className:`px-2 py-1.5`,children:e.lockState&&e.lockState!==`none`?(0,X.jsxs)(`span`,{className:`font-mono text-[11px]`,children:[Ai(`lock`,e.lockState,r),e.lockOverridden?` *`:``]}):(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,X.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 pl=new Map;function ml(e,t){pl.set(e,t)}function hl(e){return pl.get(e)}var gl=new Map;function _l(e,t){gl.set(e,t)}function vl(e){return gl.get(e)}var yl=new Map;function bl(e,t){yl.set(e,t)}function xl(e){return yl.get(e)}function Sl(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&&Tl(e.charCodeAt(r));)r++;if(r<e.length&&e.charCodeAt(r)===46)if(r++,r<e.length&&Tl(e.charCodeAt(r)))for(r++;r<e.length&&Tl(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&&Tl(e.charCodeAt(r))){for(r++;r<e.length&&Tl(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(wl(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(Cl(t)){do r++,i+=String.fromCharCode(t),t=e.charCodeAt(r);while(Cl(t));return o=15}if(wl(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&&!wl(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++,wl(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||!Tl(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(Cl(e)||wl(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 Cl(e){return e===32||e===9}function wl(e){return e===10||e===13}function Tl(e){return e>=48&&e<=57}var El;(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`})(El||={}),Array(20).fill(0).map((e,t)=>` `.repeat(t));var Dl=200;Array(Dl).fill(0).map((e,t)=>`
7
+ `+` `.repeat(t)),Array(Dl).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(Dl).fill(0).map((e,t)=>`\r
8
+ `+` `.repeat(t)),Array(Dl).fill(0).map((e,t)=>`
9
+ `+` `.repeat(t)),Array(Dl).fill(0).map((e,t)=>`\r`+` `.repeat(t)),Array(Dl).fill(0).map((e,t)=>`\r
10
+ `+` `.repeat(t));var Ol;(function(e){e.DEFAULT={allowTrailingComma:!1}})(Ol||={});function kl(e,t=[],n=Ol.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}jl(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:Ml(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 Al(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 jl(e,t,n=Ol.DEFAULT){let r=Sl(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 Ml(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 Nl;(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`})(Nl||={});var Pl;(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`})(Pl||={});var Fl=kl,Il=Al,Ll;(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`})(Ll||={});function Rl(e=4e3){let t=Z.useRef(null),[n,r]=Z.useState(!1);return Z.useEffect(()=>{if(n)return;let e=!1,t=Ia?.init?.();return t&&typeof t.catch==`function`&&t.catch(()=>{e||r(!0)}),()=>{e=!0}},[n]),Z.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 zl=Z.lazy(async()=>({default:(await a(()=>import(`./dist-Bq1W1ETM.js`).then(e=>e.n),[],import.meta.url)).default}));function Bl(e){try{return JSON.stringify(e??{},null,2)}catch{return`{}`}}function Vl(e){return e?e.split(`.`).map(e=>{let t=Number(e);return Number.isInteger(t)&&String(t)===e?t:e}):[]}function Hl({value:e,onChange:t,readOnly:n,issues:r,height:i=`60vh`,fallbackDelayMs:a=4e3}){let o=Ni(),[s,c]=Z.useState(()=>Bl(e)),[l,u]=Z.useState(null),d=Z.useRef(s),f=Z.useRef(null),p=Z.useRef(null),[m,h]=Rl(a),[g,_]=Z.useState(()=>typeof document>`u`?`light`:document.documentElement.classList.contains(`dark`)?`vs-dark`:`light`);Z.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=Z.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=Fl(s)}catch{i=void 0}let a=r.map(e=>{let r=Vl(e.path),a=1,o=1,s=1,c=2,l=i?Il(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]);Z.useEffect(()=>{v()},[v]),Z.useEffect(()=>{let t=Bl(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(K(`engine.form.rootJsonObject`,o))}catch(e){u(e?.message??K(`engine.form.invalidJson`,o))}};return(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.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,X.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,X.jsx)(Z.Suspense,{fallback:(0,X.jsx)(nn,{className:`w-full h-full`}),children:(0,X.jsx)(zl,{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,X.jsxs)(`div`,{className:`text-xs text-destructive flex items-start gap-1.5`,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,children:`⚠`}),(0,X.jsx)(`span`,{children:l})]})]})}var Ul={object:async()=>(await a(async()=>{let{ObjectSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e._);return{ObjectSchema:e}},[],import.meta.url)).ObjectSchema,hook:async()=>(await a(async()=>{let{HookSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e._);return{HookSchema:e}},[],import.meta.url)).HookSchema,mapping:async()=>(await a(async()=>{let{MappingSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e._);return{MappingSchema:e}},[],import.meta.url)).MappingSchema,analytics_cube:async()=>(await a(async()=>{let{CubeSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e._);return{CubeSchema:e}},[],import.meta.url)).CubeSchema,view:async()=>(await a(async()=>{let{ViewSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.N);return{ViewSchema:e}},[],import.meta.url)).ViewSchema,page:async()=>(await a(async()=>{let{PageSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.N);return{PageSchema:e}},[],import.meta.url)).PageSchema,app:async()=>(await a(async()=>{let{AppSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.N);return{AppSchema:e}},[],import.meta.url)).AppSchema,dashboard:async()=>(await a(async()=>{let{DashboardSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.N);return{DashboardSchema:e}},[],import.meta.url)).DashboardSchema,report:async()=>(await a(async()=>{let{ReportSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.N);return{ReportSchema:e}},[],import.meta.url)).ReportSchema,action:async()=>(await a(async()=>{let{ActionSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.N);return{ActionSchema:e}},[],import.meta.url)).ActionSchema,theme:async()=>(await a(async()=>{let{ThemeSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.N);return{ThemeSchema:e}},[],import.meta.url)).ThemeSchema,flow:async()=>(await a(async()=>{let{FlowSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.c);return{FlowSchema:e}},[],import.meta.url)).FlowSchema,webhook:async()=>(await a(async()=>{let{WebhookSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.c);return{WebhookSchema:e}},[],import.meta.url)).WebhookSchema,agent:async()=>(await a(async()=>{let{AgentSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.r);return{AgentSchema:e}},[],import.meta.url)).AgentSchema,tool:async()=>(await a(async()=>{let{ToolSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.r);return{ToolSchema:e}},[],import.meta.url)).ToolSchema,skill:async()=>(await a(async()=>{let{SkillSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.r);return{SkillSchema:e}},[],import.meta.url)).SkillSchema,email_template:async()=>(await a(async()=>{let{EmailTemplateSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.a);return{EmailTemplateSchema:e}},[],import.meta.url)).EmailTemplateSchema,job:async()=>(await a(async()=>{let{JobSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.a);return{JobSchema:e}},[],import.meta.url)).JobSchema,permission:async()=>(await a(async()=>{let{PermissionSetSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.o);return{PermissionSetSchema:e}},[],import.meta.url)).PermissionSetSchema,position:async()=>(await a(async()=>{let{PositionSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.t);return{PositionSchema:e}},[],import.meta.url)).PositionSchema,api:async()=>(await a(async()=>{let{ApiEndpointSchema:e}=await import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e.n);return{ApiEndpointSchema:e}},[],import.meta.url)).ApiEndpointSchema},Wl=new Set([`approval`,`connector_action`]),Gl=/^nodes\.(\d+)\.type$/;function Kl(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 ql=[`visibleWhen`,`readonlyWhen`,`requiredWhen`];function Jl(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`&&typeof e.source==`string`){let t=e.dialect;if(t===void 0||t===`cel`)return e.source}return null}async function Yl(e){let t=e,n=Pa(t?.fields);if(n.entries.length===0)return[];let r=typeof t?.name==`string`?t.name:void 0,i=n.entries.map(e=>e.name),a=[];for(let e=0;e<n.entries.length;e++){let t=n.entries[e],o=n.shape===`array`?String(e):t.name;for(let e of ql){let n=Jl(t.def[e]);if(n==null||!n.trim())continue;let s=await va(n,{objectName:r,fields:i,scope:`record`});for(let t of s)t.severity===`error`&&a.push({path:`fields.${o}.${e}`,message:t.message})}if(t.def.type===`formula`){let e=Jl(t.def.expression);if(e==null||!e.trim())continue;let n=await va(e,{objectName:r,fields:i.filter(e=>e!==t.name),scope:`record`,role:`value`});for(let e of n)e.severity===`error`&&a.push({path:`fields.${o}.expression`,message:e.message})}}return a}var Xl=new Map;async function Zl(e){if(Xl.has(e))return Xl.get(e)??null;let t=Ul[e];if(!t)return Xl.set(e,null),null;try{let n=await t(),r=n&&typeof n.safeParse==`function`?n:null;return Xl.set(e,r),r}catch{return Xl.set(e,null),null}}function Ql(e){return e in Ul}async function $l(e,t,n){let r=await Zl(e);if(!r)return{ok:!0,issues:[]};let i=e===`object`?await Yl(t):[],a=r.safeParse(t);if(a.success)return i.length>0?{ok:!1,issues:i}:{ok:!0,issues:[]};let o=a.error?.issues??[],s=Array.isArray(n?.required)?new Set(n.required.map(e=>String(e))):void 0;if(s&&t&&typeof t==`object`&&!Array.isArray(t)){let e=t;o=o.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)&&!s.has(r))})}return e===`flow`&&(o=o.filter(e=>{let n=(e.path??[]).map(e=>String(e)).join(`.`),r=Gl.exec(n);if(!r)return!0;let i=Kl(t,Number(r[1]));return!(i&&Wl.has(i))})),o.length===0&&i.length===0?{ok:!0,issues:[]}:{ok:!1,issues:[...o.map(e=>({path:(e.path??[]).map(e=>String(e)).join(`.`),message:e.message})),...i]}}function eu(e,t,n){let r=t.split(`.`);if(r.length<=1)return e;let i=[e],a=nu(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(tu(n)??`#${e+1}`),a=n}else i.push(t),a=nu(a)?.[t]}return i.join(` → `)}function tu(e){let t=nu(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=nu(n);if(r){let e=r.defaultValue??r.key;if(typeof e==`string`&&e.trim())return e}}}function nu(e){return e&&typeof e==`object`?e:void 0}function ru(e,t,n){return e.createBuildBody?e.createBuildBody(t):{...n??e.createDefaults??{},...t}}var iu=new Set([`object`,`report`,`dataset`]),au={object:[`fields`,`fieldGroups`]};function ou(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 su(e){return e.loadFailed?!1:e.hasDiag||e.hasClientValidator}function cu({type:e,name:t,createMode:n=!1,embedded:r=!1}){let i=s(),a=e??i.type??``,o=t??i.name??``,c=kc(a);if(c?.EditPage&&!n){let e=c.EditPage;return(0,X.jsx)(e,{type:a,name:o})}if(c?.CreatePage&&n){let e=c.CreatePage;return(0,X.jsx)(e,{type:a})}return(0,X.jsx)(lu,{type:a,name:o,createMode:n,embedded:r})}function lu({type:e,name:t,createMode:n,embedded:r}){let a=i(),[s,c]=o(),l=s.get(`package`)??void 0,u=Ui(),{entries:d}=Gi(u),f=d.find(t=>t.type===e),p=jc(e,f),m=(n&&p.createSchema?p.createSchema:f?.schema)??p.defaultSchema,h=Ni(),[g,_]=Z.useState(null),v=p.identityField??`name`,[y,b]=Z.useState(()=>n?{...p.createDefaults??{},[v]:``}:{}),[x,S]=Z.useState(null),[C,w]=Z.useState(!n),[T,E]=Z.useState(!1),[D,O]=Z.useState(null),[k,A]=Z.useState(!1),[j,M]=Z.useState([]),[ee,ne]=Z.useState(!1),P=Z.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&&(ne(!0),M(e=>e.filter(e=>{let t=(e.path??``).split(`.`)[0];return!r.has(t)}))),n})},[]),[re,F]=Z.useState(null),[ie,I]=Z.useState(null),ae=Z.useCallback(e=>{P(t=>({...t,...e}))},[P]),{markTouched:se}=Wi({rules:p.createDerive,draft:y,onPatch:ae,enabled:!!n}),ce=Z.useMemo(()=>{if(n)return p.createFields&&p.createFields.length>0?p.createFields:Ki(m?.properties??void 0,m?.required??void 0)},[n,p.createFields,m]),le=Z.useMemo(()=>{let t=au[e]??[];if(!n||!ce)return t.length===0?p.hiddenFields:Array.from(new Set([...p.hiddenFields??[],...t]));let r=m?.properties??{},i=new Set(ce),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,ce,m,p.hiddenFields,e]),ue=Z.useMemo(()=>n&&ce?ce:p.fieldOrder,[n,ce,p.fieldOrder]),de=Z.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])||se(e)}P(e)},[n,y,P,se]);Z.useEffect(()=>{if(!Ql(e))return;let t=!1,n=window.setTimeout(()=>{$l(e,y,f?.schema).then(e=>{t||M(e.issues)})},200);return()=>{t=!0,window.clearTimeout(n)}},[e,y,f?.schema]);let fe=Z.useMemo(()=>n&&!ee?[]:j,[n,ee,j]),me=Z.useMemo(()=>{let t=g?._diagnostics,n=Ql(e)?fe.map(e=>({path:e.path,message:Fi(e.message,h)})):(t?.errors??[]).map(e=>({path:e.path,message:Fi(e.message,h)})),r=(t?.warnings??[]).map(e=>({path:e.path,message:Fi(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,fe,e,h]),[he,ge]=Z.useState(!1),[_e,ve]=Z.useState(!1),[ye,be]=Z.useState(0),[xe,Se]=Z.useState(!!n),[Ce,we]=Z.useState(null);Z.useEffect(()=>{we(null)},[e,t]),Z.useEffect(()=>{xe||we(null)},[xe]);let Te=Co(s.get(`sel`)),Ee=Z.useRef(null);Z.useEffect(()=>{if(e!==`app`||!Te||Ee.current===`${t}:${Te}`||!y||Object.keys(y).length===0)return;let n=Oo(y,Te);n&&(Ee.current=`${t}:${Te}`,Se(!0),we({kind:`nav`,id:n.selectionId,label:n.label}))},[e,t,Te,y]),Z.useEffect(()=>{if(e!==`app`)return;let t=Ce?.kind===`nav`?ko(y,Ce.id):null;c(e=>{let n=new URLSearchParams(e);return t?n.set(`sel`,wo(t)):n.delete(`sel`),n},{replace:!0})},[e,Ce]);let De=Z.useRef(null),[Oe,ke]=Z.useState(null),[Ae,je]=Z.useState(()=>{if(typeof window>`u`)return!0;try{let e=window.localStorage.getItem(`metadata-admin:autosave`);return e===null||e===`1`}catch{return!0}});Z.useEffect(()=>{try{window.localStorage.setItem(`metadata-admin:autosave`,Ae?`1`:`0`)}catch{}},[Ae]);let Ne=Z.useRef(null),[Pe,Ie]=Z.useState([]),[Le,Re]=Z.useState(!0);Z.useEffect(()=>{let e=!1;return(async()=>{try{let t=await u.list(`object`);if(e)return;Ie(t.map(e=>e?.name).filter(e=>!!e).sort())}catch{e||Ie([])}finally{e||Re(!1)}})(),()=>{e=!0}},[u]);let ze=y?.interfaceConfig?.source||y?.data?.object||y?.object||y?.objectName,[Be,He]=Z.useState([]),[We,Ge]=Z.useState(!1),[Ke,qe]=Z.useState([]);Z.useEffect(()=>{let e=!1;if(!ze){He([]),qe([]);return}return Ge(!0),(async()=>{try{let t=await u.get(`object`,ze);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})):[];He(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||qe(a)}catch{e||(He([]),qe([]))}finally{e||Ge(!1)}})(),()=>{e=!0}},[u,ze]);let[Je,Ye]=Z.useState([]),[Xe,Ze]=Z.useState(!1);Z.useEffect(()=>{let e=!1;if(!ze){Ye([]);return}return Ze(!0),(async()=>{try{let t=await u.list(`view`);if(e)return;let n=(t||[]).filter(e=>(e?.objectName??e?.object??e?.object_name)===ze),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));Ye(i)}catch{e||Ye([])}finally{e||Ze(!1)}})(),()=>{e=!0}},[u,ze]);let $e=Z.useMemo(()=>e===`page`?Da(y):[],[e,y]),et=Z.useMemo(()=>({objectNames:Pe,objectsLoading:Le,objectFields:Be,objectFieldsLoading:We,objectViews:Je,objectViewsLoading:Xe,objectActions:Ke,componentIds:$e}),[Pe,Le,Be,We,Je,Xe,Ke,$e]);Z.useEffect(()=>{if(n){w(!1);return}let r=!1;return w(!0),O(null),A(!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)?M(o.errors.map(e=>({path:e.path||``,message:e.message}))):M([]);let s=ou(a),c=i.effective??i.code??{},d=s?{...c,...s}:c,f=p.toDraft?p.toDraft(d):d;b(f),De.current=f,ge(!!s),w(!1)}catch(n){r||(A(!0),O(G(`engine.edit.loadFailed`,h,{type:e,name:t??``,message:n?.message??String(n)})),w(!1))}})(),()=>{r=!0}},[u,e,t,l,n,ye,h]);let[tt,nt]=Z.useState(!1);async function rt(){if(!(x!=null||tt)){nt(!0);try{let n=await u.references(e,t);S(n)}catch(e){S([]),console.error(`references() failed`,e)}finally{nt(!1)}}}let[it,ot]=Z.useState(null),st=Z.useMemo(()=>!n&&!r&&Ac(e).length>0,[e,n,r]),ct=Z.useRef(null),[ut,dt]=Z.useState(null),ft=s.get(`review`),pt=Z.useRef(!1);Z.useEffect(()=>{if(!(ft!==`1`||n)){if(!pt.current){pt.current=!0,be(e=>e+1);return}if(!C){he&&dt(`review`);let e=new URLSearchParams(s);e.delete(`review`),c(e,{replace:!0}),pt.current=!1}}},[ft,n,C,he]);let[mt,ht]=Z.useState(`properties`);Z.useEffect(()=>{if(ut===`references`&&rt(),typeof window<`u`&&!r){let e=new URL(window.location.href);ut?e.searchParams.set(`tab`,ut):e.searchParams.delete(`tab`),window.history.replaceState({},``,e.toString())}},[ut,r]);let gt=`metadata-edit:inspector-collapsed`,_t=`metadata-edit:inspector-size`,[vt,yt]=Z.useState(()=>typeof window>`u`?!1:window.localStorage.getItem(gt)===`1`),bt=Z.useRef(38);Z.useEffect(()=>{if(typeof window>`u`)return;let e=Number(window.localStorage.getItem(_t));Number.isFinite(e)&&e>=22&&e<=80&&(bt.current=e)},[]);let xt=Z.useRef(null),St=Z.useCallback(()=>{yt(e=>{let t=!e;return typeof window<`u`&&window.localStorage.setItem(gt,t?`1`:`0`),t})},[]);Z.useEffect(()=>{let e=xt.current;if(e)if(vt)e.resize?.(`0%`);else{let t=bt.current||38;e.resize?.(`${t}%`)}},[vt]);let[Ct,wt]=Z.useState(!1),[Tt,Et]=Z.useState(!1);Z.useEffect(()=>{if(typeof document>`u`||!Tt)return;let e=document.body.style.overflow;return document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=e}},[Tt]),Z.useEffect(()=>{if(typeof window>`u`||!Tt)return;function e(e){e.key===`Escape`&&(e.preventDefault(),Et(!1))}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Tt]);let Dt=Z.useRef(null);Z.useEffect(()=>{Dt.current=null},[e,t]),Z.useEffect(()=>{if(n||r||C)return;let i=`${e}/${t??``}`;Dt.current!==i&&hl(e)&&(g?.code!=null&&g.code?._packageId!==`sys_metadata`?f?.allowOrgOverride:f?.allowOrgOverride||f?.allowRuntimeCreate)&&(Dt.current=i,Se(!0))},[e,t,n,r,C,f,g]),Z.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(),St())}return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,St]),Z.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`)&&dt(t),ct.current=t;let n=e.get(`open`);if(n&&n.includes(`:`)){let[e,t]=n.split(`:`,2);e&&t&&ot({kind:`metadata`,type:e,name:t})}},[]),Z.useEffect(()=>{if(typeof window>`u`||r)return;let e=new URL(window.location.href);it?.kind===`metadata`?e.searchParams.set(`open`,`${it.type}:${it.name}`):e.searchParams.delete(`open`),window.history.replaceState({},``,e.toString())},[it,r]);function Ot(e){let t=e.split(`.`)[0];return t?eu((()=>{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 kt(r){E(!0),O(null),M([]);try{let i=f?.createSeed,o=n?ru(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(K(`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=ou(S);ge(!!C);let w=x.effective??d,T=C?{...w,...C}:w,D=p.toDraft?p.toDraft(T):T;b(D),De.current=D,ke(new Date),Ne.current=JSON.stringify(D),F(null),I(null);let k=!n&&!!hl(e);if(!n&&!k&&Se(!1),n){let e=s.toString();a(`../${encodeURIComponent(c)}${e?`?${e}`:``}`,{relative:`path`})}}catch(e){if(e?.status===409&&N(e,`DESTRUCTIVE_CHANGE`)){let t=e?.body?.issues??[];F(Array.isArray(t)?t:[]),I(y)}else if(N(e,`WRITABLE_PACKAGE_REQUIRED`))O(K(`engine.package.writableRequired`,h));else if(e?.status===422||te(e,[`INVALID_METADATA`,`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:Fi(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:Fi(e[2].trim(),h)}]:[{path:``,message:Fi(r,h)}]}M(n),n.length===1&&!n[0].path?O(n[0].message):n.length===1?O(`${Ot(n[0].path)}: ${n[0].message}`):O(G(`engine.validation.failed`,h,{count:n.length}))}else O(e?.message??String(e))}finally{E(!1)}}async function At(){let r=!n&&g?.code!=null;if(confirm(G(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),De.current=r,hl(e)?Dt.current=null:Se(!1)}else a(`../`,{relative:`path`})}catch(e){O(e?.message??String(e))}finally{E(!1)}}}async function jt(){ve(!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=ou(r);ge(!!i);let a=n.effective??y,o=i?{...a,...i}:a;b(o),De.current=o}catch(e){O(e?.message??String(e))}finally{ve(!1)}}async function Mt(){if(confirm(G(`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),De.current=r,ge(!1)}catch(e){O(e?.message??String(e))}finally{E(!1)}}}let R=Z.useMemo(()=>{if(n)return Object.keys(y).length>0;let e=De.current;if(!e)return!1;try{return JSON.stringify(y)!==JSON.stringify(e)}catch{return!1}},[y,n]),Pt=!n&&g?.code!=null&&g.code?._packageId!==`sys_metadata`,Ft=g?.editable!==!1,It=g?.deletable!==!1,Lt=g?.resettable!==!1,zt=g?.lockReason,Bt=g?.lock&&g.lock!==`none`,Vt=(n?!!(f?.allowOrgOverride||f?.allowRuntimeCreate):Pt?!!f?.allowOrgOverride:!!(f?.allowOrgOverride||f?.allowRuntimeCreate))&&(n||Ft),Ut=!Vt&&!n,Wt=Z.useRef(kt);if(Z.useEffect(()=>{Wt.current=kt}),Z.useEffect(()=>{if(!Ae||n||Ut||!xe||!R||T)return;let e;try{e=JSON.stringify(y)}catch{return}if(e===Ne.current)return;let t=window.setTimeout(()=>{Ne.current=e,Wt.current(!1)},1500);return()=>window.clearTimeout(t)},[y,R,xe,T,n,Ut,Ae]),Z.useEffect(()=>{let e=e=>{if((e.metaKey||e.ctrlKey)&&e.key.toLowerCase()===`s`){if(!Vt||Ut||!xe&&!n)return;e.preventDefault(),!T&&(n||R)&&Wt.current(!1)}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[Vt,Ut,xe,n,T,R]),Z.useEffect(()=>{if(!R)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[R]),Z.useEffect(()=>{if(!R)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(K(`engine.edit.unsavedLeaveConfirm`,h))||(e.preventDefault(),e.stopPropagation())}};return document.addEventListener(`click`,e,!0),()=>document.removeEventListener(`click`,e,!0)},[R,h]),mi(Z.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=Pa(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,X.jsx)(Sc,{entry:f,itemName:t,children:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Loading `,e,`/`,t,`…`]})});let Gt=Ut&&Pt&&!!f?.allowRuntimeCreate,Kt=iu.has(e),qt=!r&&(!n||Kt)?hl(e):void 0,Jt=vl(e),Xt=xl(e);function Zt(){De.current&&b(De.current),M([]),O(null),Se(!1)}let Qt=Ut||!xe&&!n,$t=(0,X.jsxs)(X.Fragment,{children:[!n&&(0,X.jsx)(Tc,{entry:f,location:`record_header`,recordId:t,onAfter:()=>be(e=>e+1)}),(!n||st)&&(0,X.jsxs)(`div`,{className:`flex items-center rounded-md border bg-background p-0.5`,children:[!n&&(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>dt(`layers`),title:K(`engine.edit.layers`,h),className:`h-7 w-7 p-0 relative`,children:[(0,X.jsx)(ri,{className:`h-3.5 w-3.5`}),g?.overlay&&(()=>{let e=Hc(g.code,g.effective);return e>0?(0,X.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:K(`engine.layers.diff`,h),children:e}):null})()]}),!n&&he&&(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>dt(`review`),title:K(`designer.draftReview.title`,h),className:`h-7 w-7 p-0 relative`,"data-testid":`resource-review-trigger`,children:[(0,X.jsx)(Rt,{className:`h-3.5 w-3.5`}),(()=>{let e=Zc(g?.effective??null,y);return e>0?(0,X.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:G(`designer.draftReview.badge`,h,{n:e}),children:e}):null})()]}),!n&&(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>dt(`references`),title:K(`engine.edit.references`,h),className:`h-7 w-7 p-0 relative`,children:[(0,X.jsx)(br,{className:`h-3.5 w-3.5`}),x&&x.length>0&&(0,X.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})]}),st&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>dt(`related`),title:K(`engine.edit.related`,h),className:`h-7 w-7 p-0`,children:(0,X.jsx)(Jr,{className:`h-3.5 w-3.5`})}),!n&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>dt(`history`),title:K(`engine.edit.history`,h),className:`h-7 w-7 p-0`,children:(0,X.jsx)(at,{className:`h-3.5 w-3.5`})}),!n&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>dt(`audit`),title:K(`engine.edit.auditTab`,h),className:`h-7 w-7 p-0`,children:(0,X.jsx)(Fe,{className:`h-3.5 w-3.5`})})]}),!n&&Vt&&g?.overlay&&(Pt?Lt:It)&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:At,disabled:T,title:K(Pt?`engine.edit.reset`:`engine.edit.delete`,h),className:`h-7 w-7 p-0 text-muted-foreground hover:text-destructive`,children:Pt?(0,X.jsx)(sr,{className:`h-3.5 w-3.5`}):(0,X.jsx)(gn,{className:`h-3.5 w-3.5`})}),Vt&&!n&&!xe&&!qt&&(0,X.jsxs)(W,{size:`sm`,onClick:()=>Se(!0),className:`h-7`,children:[(0,X.jsx)(pe,{className:`h-3.5 w-3.5 mr-1`}),K(`engine.edit.edit`,h)]}),Vt&&(xe||n)&&(0,X.jsx)(du,{saving:T,isDirty:R,autoSaveEnabled:Ae,lastSavedAt:Oe,createMode:!!n,locale:h}),Vt&&(xe||n)&&!n&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>je(e=>!e),className:`h-7 w-7 p-0 text-muted-foreground`,title:K(Ae?`engine.edit.autoSaveOn`:`engine.edit.autoSaveOff`,h),children:Ae?(0,X.jsx)(Ht,{className:`h-3.5 w-3.5 text-emerald-600`}):(0,X.jsx)(Me,{className:`h-3.5 w-3.5`})}),Vt&&!n&&xe&&!qt&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:Zt,disabled:T,className:`h-7 w-7 p-0`,title:K(`engine.cancel`,h),children:(0,X.jsx)(Qe,{className:`h-3.5 w-3.5`})}),Vt&&(xe||n)&&(0,X.jsxs)(W,{size:`sm`,onClick:()=>kt(!1),disabled:T||!n&&!R,className:`h-7 w-7 p-0 relative`,title:T?K(`engine.edit.saving`,h):!n&&!R?K(`engine.edit.noChanges`,h):`${K(`engine.edit.save`,h)} (⌘S)`,children:[T?(0,X.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(Yt,{className:`h-3.5 w-3.5`}),R&&!T&&(0,X.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`})]}),Vt&&!n&&he&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:Mt,disabled:T||_e,className:`h-7 w-7 p-0 text-muted-foreground`,title:K(`engine.edit.discardDraft`,h),children:(0,X.jsx)(mr,{className:`h-3.5 w-3.5`})}),Vt&&!n&&he&&(0,X.jsx)(W,{size:`sm`,onClick:jt,disabled:T||_e||R,className:`h-7 px-2 relative bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,title:K(R?`engine.edit.publishBlockedDirty`:`engine.edit.publish`,h),children:_e?(0,X.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(wr,{className:`h-3.5 w-3.5 mr-1`}),(0,X.jsx)(`span`,{className:`text-xs`,children:K(`engine.edit.publish`,h)})]})})]});return(0,X.jsxs)(Sc,{entry:f??{type:e,label:e},itemName:n?`(new)`:t,subtitle:n?K(`engine.edit.createNew`,h):void 0,actions:qt?null:$t,children:[(0,X.jsxs)(`div`,{className:qt?`flex h-full min-h-0 flex-col`:`p-6 space-y-6 max-w-7xl`,children:[(D||Ut||he||Bt)&&(0,X.jsxs)(`div`,{className:qt?`px-6 pt-4 space-y-3`:`space-y-3`,children:[D&&(0,X.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/5`,children:D}),Bt&&(0,X.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,X.jsx)(hr,{className:`h-3.5 w-3.5 mt-0.5 shrink-0 opacity-80`}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`font-medium`,children:[g?.lock===`full`&&K(`engine.edit.lockFull`,h),g?.lock===`no-overlay`&&K(`engine.edit.lockNoOverlay`,h),g?.lock===`no-delete`&&K(`engine.edit.lockNoDelete`,h)]}),zt&&(0,X.jsx)(`div`,{className:`mt-0.5 opacity-90`,children:zt}),g?.lockDocsUrl&&(0,X.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,X.jsx)(`div`,{className:`mt-0.5 text-amber-700 dark:text-amber-300/80`,children:(0,X.jsxs)(`code`,{className:`font-mono`,children:[g.packageId,g.packageVersion?`@${g.packageVersion}`:``]})})]}),Gt&&(0,X.jsx)(W,{size:`sm`,variant:`outline`,className:`shrink-0 h-7 bg-background/60`,onClick:()=>a(`../new`,{relative:`path`}),children:K(`engine.list.create`,h)})]}),he&&!n&&(0,X.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,X.jsx)(wr,{className:`h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`flex-1`,children:K(`engine.edit.draftPending`,h)}),Vt&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{size:`sm`,variant:`ghost`,onClick:Mt,disabled:T||_e,className:`h-7`,children:K(`engine.edit.discardDraft`,h)}),(0,X.jsx)(W,{size:`sm`,onClick:jt,disabled:T||_e||R,className:`h-7 bg-emerald-600 hover:bg-emerald-700 text-emerald-50`,children:_e?(0,X.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):K(`engine.edit.publish`,h)})]})]}),Ut&&!Bt&&(0,X.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,X.jsx)(`div`,{className:`flex-1`,children:Gt?K(`engine.edit.artifactLockedBanner`,h).split(/(\{type\})/).map((t,n)=>t===`{type}`?(0,X.jsx)(`code`,{className:`font-mono`,children:e},n):(0,X.jsx)(Z.Fragment,{children:t},n)):K(`engine.edit.readOnlyTypeBanner`,h).split(/(\{flag\}|\{type\}|\{override\})/).map((t,n)=>t===`{flag}`?(0,X.jsx)(`code`,{className:`font-mono`,children:`OBJECTSTACK_METADATA_WRITABLE`},n):t===`{type}`?(0,X.jsx)(`code`,{className:`font-mono`,children:e},n):t===`{override}`?(0,X.jsx)(`code`,{className:`font-mono`,children:`allowOrgOverride`},n):(0,X.jsx)(Z.Fragment,{children:t},n))}),Gt&&(0,X.jsx)(W,{size:`sm`,variant:`outline`,className:`shrink-0`,onClick:()=>a(`../new`,{relative:`path`}),children:K(`engine.list.create`,h)})]})]}),(0,X.jsx)(`div`,{className:qt?`flex w-full flex-1 min-h-0 flex-col`:`w-full`,children:(0,X.jsxs)(`div`,{className:qt?`mt-2 flex-1 min-h-0 flex flex-col px-6 pb-4`:`mt-4 space-y-3`,children:[!qt&&Qt&&!Ut&&Vt&&!n&&(0,X.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,X.jsx)(`span`,{children:K(`engine.edit.readOnlyBanner`,h).split(/\{edit\}/).map((e,t,n)=>(0,X.jsxs)(Z.Fragment,{children:[e,t<n.length-1&&(0,X.jsx)(`strong`,{children:K(`engine.edit.edit`,h)})]},t))}),(0,X.jsxs)(W,{size:`sm`,variant:`outline`,onClick:()=>Se(!0),children:[(0,X.jsx)(pe,{className:`h-3.5 w-3.5 mr-1`}),K(`engine.edit.edit`,h)]})]}),(()=>{let t=g?._diagnostics,r=Ql(e)?j.map(e=>({path:e.path,message:Fi(e.message,h)})):(t?.errors??[]).map(e=>({...e,message:Fi(e.message,h)})),i=Ql(e)?r.length===0:t?.valid!==!1;if(n&&!ee||!su({loadFailed:k,hasDiag:!!t,hasClientValidator:Ql(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,X.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,X.jsx)(z,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:G(a,h,{count:t.length})}),(0,X.jsxs)(`ul`,{className:`mt-1 space-y-0.5 font-mono text-[11px]`,children:[n.map((e,t)=>(0,X.jsxs)(`li`,{className:`truncate`,children:[(0,X.jsx)(`span`,{className:`opacity-70`,children:e.path?Ot(e.path):`(root)`}),`: `,e.message]},t)),r>0&&(0,X.jsx)(`li`,{className:`opacity-70`,children:G(`engine.edit.diagnostics.more`,h,{count:r})})]})]})]},e)};return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[s&&l(`error`,a),c&&l(`warning`,o)]})})(),qt?(0,X.jsx)(`div`,{className:Tt?`fixed inset-0 z-50 bg-background flex flex-col p-3`:`relative flex-1 min-h-0 flex`,children:(0,X.jsxs)(ti,{orientation:`horizontal`,className:`flex-1 min-h-0 rounded-md border bg-background overflow-hidden`,id:`metadata-edit-${e}`,children:[(0,X.jsx)(ln,{defaultSize:62,minSize:30,children:(0,X.jsxs)(`div`,{className:`relative h-full flex flex-col`,children:[(0,X.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,X.jsx)(`div`,{className:`flex items-center gap-1`,children:Vt&&(0,X.jsxs)(`div`,{role:`tablist`,"aria-label":K(`engine.edit.designer`,h),className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":!Ct,onClick:()=>wt(!1),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Ct?`text-muted-foreground hover:text-foreground`:`bg-background shadow-sm text-foreground`),title:K(`engine.edit.designMode`,h),children:[(0,X.jsx)(Nt,{className:`h-3.5 w-3.5`}),K(`engine.edit.designMode`,h)]}),(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":Ct,onClick:()=>wt(!0),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(Ct?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:K(`engine.edit.previewMode`,h),children:[(0,X.jsx)(Sr,{className:`h-3.5 w-3.5`}),K(`engine.edit.previewMode`,h)]})]})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[$t,(0,X.jsx)(`span`,{className:`mx-1 h-5 w-px bg-border`,"aria-hidden":!0}),qt&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:St,className:`h-7 w-7 p-0`,title:K(vt?`engine.edit.showInspector`:`engine.edit.hideInspector`,h)+` (⌘\\)`,children:vt?(0,X.jsx)(lt,{className:`h-3.5 w-3.5`}):(0,X.jsx)(oe,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>Et(e=>!e),className:`h-7 w-7 p-0`,title:K(Tt?`engine.edit.exitFullscreen`:`engine.edit.fullscreen`,h),children:Tt?(0,X.jsx)(Ue,{className:`h-3.5 w-3.5`}):(0,X.jsx)(Cn,{className:`h-3.5 w-3.5`})})]})]}),(0,X.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,X.jsx)(qt,{type:e,name:t,draft:y,baseline:n?void 0:g?.effective??void 0,editing:xe&&!Ct,selection:Ct?null:Ce,onSelectionChange:we,locale:h,diagnostics:me,onPatch:e=>P(t=>({...t,...e}))})})]})}),(0,X.jsx)(ai,{withHandle:!0,className:vt?`hidden`:`w-1.5 bg-border/40 hover:bg-primary/40 active:bg-primary/60 transition-colors`}),(0,X.jsx)(ln,{panelRef:xt,defaultSize:bt.current,minSize:22,collapsible:!0,collapsedSize:0,onResize:e=>{let t=e.asPercentage,n=t<=.5;n||(bt.current=t,typeof window<`u`&&window.localStorage.setItem(_t,String(Math.round(t)))),yt(e=>e===n?e:(typeof window<`u`&&window.localStorage.setItem(gt,n?`1`:`0`),n))},children:(0,X.jsxs)(`div`,{className:`h-full overflow-auto`,children:[(0,X.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,X.jsxs)(`div`,{role:`tablist`,className:`inline-flex items-center rounded-md border bg-muted/40 p-0.5`,children:[(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":mt===`properties`,onClick:()=>ht(`properties`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(mt===`properties`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:K(`engine.edit.inspector.properties`,h),children:[(0,X.jsx)(Ve,{className:`h-3.5 w-3.5`}),K(`engine.edit.inspector.properties`,h)]}),(0,X.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":mt===`source`,onClick:()=>ht(`source`),className:`inline-flex items-center gap-1 rounded px-2 py-1 text-xs transition-colors `+(mt===`source`?`bg-background shadow-sm text-foreground`:`text-muted-foreground hover:text-foreground`),title:K(`engine.edit.inspector.source`,h),children:[(0,X.jsx)(Wr,{className:`h-3.5 w-3.5`}),K(`engine.edit.inspector.source`,h)]})]}),R&&(0,X.jsxs)(L,{variant:`outline`,className:`text-[10px] border-amber-400/60 text-amber-600 dark:text-amber-300`,children:[(0,X.jsx)(`span`,{className:`mr-1 inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),K(`engine.edit.unsaved`,h)]})]}),(0,X.jsx)(`div`,{className:`p-4`,children:mt===`source`?(0,X.jsx)(Hl,{value:y,onChange:P,readOnly:Qt,issues:fe.map(e=>({path:e.path??``,message:e.message}))}):Ce&&Jt?(0,X.jsx)(Jt,{type:e,name:t,draft:y,selection:Ce,onPatch:e=>P(t=>({...t,...e})),onClearSelection:()=>we(null),onSelectionChange:we,readOnly:Qt,locale:h}):!Ce&&Xt?(0,X.jsx)(Xt,{type:e,name:t,draft:y,onPatch:e=>P(t=>({...t,...e})),onSelectionChange:we,readOnly:Qt,locale:h,serverSchema:f?.schema}):(0,X.jsx)(ga,{schema:m,form:n&&p.createSchema?void 0:f?.form,value:y,onChange:de,issues:fe,hiddenFields:le,fieldOrder:ue,readOnly:Qt,createMode:n,widgetContext:et})})]})})]})}):(0,X.jsx)(ga,{schema:m,form:n&&p.createSchema?void 0:f?.form,value:y,onChange:de,issues:fe,hiddenFields:le,fieldOrder:ue,readOnly:Qt,createMode:n,widgetContext:et})]})})]}),(0,X.jsx)(Fr,{open:ut===`layers`,onOpenChange:e=>!e&&dt(null),children:(0,X.jsxs)(un,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(Hr,{className:`px-4 py-3 border-b`,children:[(0,X.jsx)(_n,{className:`text-base`,children:K(`engine.edit.layers`,h)}),(0,X.jsxs)(Qn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,X.jsx)(Uc,{layered:g,locale:h})})]})}),(0,X.jsx)(Fr,{open:ut===`review`,onOpenChange:e=>!e&&dt(null),children:(0,X.jsxs)(un,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(Hr,{className:`px-4 py-3 border-b`,children:[(0,X.jsx)(_n,{className:`text-base`,children:K(`designer.draftReview.title`,h)}),(0,X.jsxs)(Qn,{className:`text-xs`,children:[e,` / `,t,` · `,K(`designer.canvas.reviewVsPublished`,h)]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,X.jsx)(Qc,{published:g?.effective??null,draft:y,locale:h})})]})}),(0,X.jsx)(Fr,{open:ut===`references`,onOpenChange:e=>!e&&dt(null),children:(0,X.jsxs)(un,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(Hr,{className:`px-4 py-3 border-b`,children:[(0,X.jsxs)(_n,{className:`text-base`,children:[K(`engine.edit.references`,h),x&&(0,X.jsx)(L,{variant:`outline`,className:`ml-2 text-[10px]`,children:x.length})]}),(0,X.jsxs)(Qn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,X.jsx)(uu,{refs:x,loading:tt,locale:h})})]})}),st&&(0,X.jsx)(Fr,{open:ut===`related`,onOpenChange:e=>!e&&dt(null),children:(0,X.jsxs)(un,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(Hr,{className:`px-4 py-3 border-b`,children:[(0,X.jsx)(_n,{className:`text-base`,children:K(`engine.edit.related`,h)}),(0,X.jsxs)(Qn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,X.jsx)($c,{type:e,name:t,parentItem:y,onOpen:e=>ot(e)})})]})}),!n&&(0,X.jsx)(Fr,{open:ut===`history`,onOpenChange:e=>!e&&dt(null),children:(0,X.jsxs)(un,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(Hr,{className:`px-4 py-3 border-b`,children:[(0,X.jsx)(_n,{className:`text-base`,children:K(`engine.edit.history`,h)}),(0,X.jsxs)(Qn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:(0,X.jsx)(sl,{type:e,name:t,client:u,locale:h,onRollback:()=>be(e=>e+1),rollbackLabel:K(`engine.edit.rollback`,h),rollbackConfirm:e=>K(`engine.edit.rollbackConfirm`,h).replace(`{version}`,String(e))})})]})}),!n&&(0,X.jsx)(Fr,{open:ut===`audit`,onOpenChange:e=>!e&&dt(null),children:(0,X.jsxs)(un,{side:`right`,className:`w-[92vw] sm:max-w-[860px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(Hr,{className:`px-4 py-3 border-b`,children:[(0,X.jsx)(_n,{className:`text-base`,children:K(`engine.edit.auditTab`,h)}),(0,X.jsxs)(Qn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden p-3`,children:(0,X.jsx)(fl,{type:e,name:t,client:u,locale:h})})]})}),(0,X.jsx)(al,{target:it,onClose:()=>ot(null),parentContext:{type:e,name:t}}),(0,X.jsx)(Ir,{open:re!=null,onOpenChange:e=>{e||(F(null),I(null))},children:(0,X.jsxs)(fn,{children:[(0,X.jsxs)(vn,{children:[(0,X.jsxs)(On,{className:`flex items-center gap-2`,children:[(0,X.jsx)(z,{className:`h-5 w-5 text-amber-600`}),K(`engine.edit.destructiveTitle`,h)]}),(0,X.jsx)($n,{children:K(`engine.edit.destructiveDesc`,h)})]}),(0,X.jsx)(`div`,{className:`max-h-[300px] overflow-auto space-y-2 my-2`,children:re?.map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded border bg-amber-50 border-amber-200 p-2 text-xs`,children:[(0,X.jsx)(`div`,{className:`font-mono text-amber-900`,children:e.kind??`change`}),e.path&&(0,X.jsx)(`div`,{className:`text-amber-800 font-mono mt-0.5`,children:e.path}),(0,X.jsx)(`div`,{className:`text-amber-900 mt-1`,children:e.message})]},t))}),(0,X.jsxs)(Ur,{children:[(0,X.jsx)(W,{variant:`ghost`,onClick:()=>F(null),children:K(`engine.cancel`,h)}),(0,X.jsx)(W,{variant:`destructive`,onClick:()=>kt(!0),disabled:T,children:K(T?`engine.edit.forcing`:`engine.edit.forceSave`,h)})]})]})})]})}function uu({refs:e,loading:t,locale:n}){return t||e==null?(0,X.jsxs)(`div`,{className:`text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`}),` `,K(`engine.edit.refsScanning`,n)]}):e.length===0?(0,X.jsxs)(Lr,{children:[(0,X.jsx)(bn,{children:K(`engine.edit.refsEmptyTitle`,n)}),(0,X.jsx)(mn,{children:K(`engine.edit.refsEmptyDesc`,n)})]}):(0,X.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From type`}),(0,X.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`From name`}),(0,X.jsx)(`th`,{className:`px-3 py-2 text-left`,children:`Path`})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:e.map((e,t)=>(0,X.jsxs)(`tr`,{className:`hover:bg-accent/50`,children:[(0,X.jsx)(`td`,{className:`px-3 py-2`,children:(0,X.jsx)(L,{variant:`outline`,className:`text-[10px] font-mono`,children:e.fromType})}),(0,X.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs`,children:e.fromName}),(0,X.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs text-muted-foreground`,children:e.path})]},t))})]})})}function du({saving:e,isDirty:t,autoSaveEnabled:n,lastSavedAt:r,createMode:i,locale:a}){let[,o]=Z.useReducer(e=>e+1,0);return Z.useEffect(()=>{if(!r)return;let e=window.setInterval(o,3e4);return()=>window.clearInterval(e)},[r]),e?(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:[(0,X.jsx)(U,{className:`h-3 w-3 animate-spin`}),K(`engine.edit.saving`,a)]}):t?i?null:(0,X.jsxs)(`span`,{className:`text-xs text-amber-600 dark:text-amber-300 hidden md:inline-flex items-center gap-1`,children:[(0,X.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full bg-amber-400`}),K(n?`engine.edit.autoSavingShortly`:`engine.edit.unsaved`,a)]}):r?(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground hidden md:inline-flex items-center gap-1`,children:G(`engine.edit.savedAt`,a,{time:`${String(r.getHours()).padStart(2,`0`)}:${String(r.getMinutes()).padStart(2,`0`)}`})}):null}function fu({type:e}){let t=r(),[n]=o(),i=e??n.get(`type`)??``;if(!i)return(0,X.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,X.jsxs)(Lr,{children:[(0,X.jsx)(bn,{children:`Missing metadata type`}),(0,X.jsxs)(mn,{children:[`This page expects a `,(0,X.jsx)(`code`,{className:`font-mono`,children:`?type=`}),` query param (e.g. `,(0,X.jsx)(`code`,{className:`font-mono`,children:`?type=view`}),`) or a nav-metadata `,(0,X.jsxs)(`code`,{className:`font-mono`,children:[`params: `,`{ type: 'view' }`]}),`.`]})]})});let a=pu(t.pathname),s=a.split(`/`).filter(Boolean);return s.length===0?(0,X.jsx)(Nc,{type:i}):s[0]===`new`&&s.length===1?(0,X.jsx)(cu,{type:i,name:``,createMode:!0},`${i}:__new__`):s.length===2&&s[1]===`history`?(0,X.jsx)(ol,{type:i,name:decodeURIComponent(s[0])}):s.length===1?(0,X.jsx)(cu,{type:i,name:decodeURIComponent(s[0])},`${i}:${s[0]}`):(0,X.jsx)(`div`,{className:`p-8 h-full flex items-center justify-center`,children:(0,X.jsxs)(Lr,{children:[(0,X.jsx)(bn,{children:`Unknown sub-path`}),(0,X.jsxs)(mn,{children:[`The path `,(0,X.jsx)(`code`,{className:`font-mono`,children:a}),` isn't recognized. Valid forms are `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/`}),` (list),`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/new`}),` (create),`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/:name`}),` (edit),`,` `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/:name/history`}),`.`]})]})})}function pu(e){let t=e.indexOf(`/metadata/resource`);return t===-1?``:e.slice(t+18)}function mu(){let e=Ui(),t=Ni(),[r,i]=Z.useState(`error`),{loading:a,error:o,summary:s,reload:c}=Bi(e,r),{entries:l}=Gi(e),u=Z.useMemo(()=>{let e={};for(let n of l)e[n.type]=Pi(n.type,t,n.label);return e},[l,t]),d=Z.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,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`px-6 pt-5 pb-4 border-b bg-background`,children:[(0,X.jsx)(`nav`,{className:`text-xs text-muted-foreground mb-2`,children:(0,X.jsxs)(n,{to:`..`,className:`hover:text-foreground inline-flex items-center gap-1`,children:[(0,X.jsx)(Lt,{className:`h-3 w-3`}),K(`engine.diagnostics.back`,t)]})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,X.jsxs)(`h1`,{className:`text-xl font-semibold flex items-center gap-2`,children:[(0,X.jsx)(z,{className:`h-5 w-5 text-destructive`}),K(`engine.diagnostics.title`,t)]}),(0,X.jsx)(L,{variant:`outline`,className:`text-[11px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:G(`engine.diagnostics.summary`,t,{count:s.total,items:s.scannedItems,types:s.scannedTypes})}),(0,X.jsx)(`div`,{className:`flex-1`}),(0,X.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,X.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:K(`engine.diagnostics.severity.${e}`,t)},e))}),(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:c,children:[(0,X.jsx)(Mr,{className:`h-3.5 w-3.5 mr-1`}),K(`engine.diagnostics.refresh`,t)]})]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground mt-2 max-w-3xl`,children:K(`engine.diagnostics.description`,t)})]}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-auto p-6 space-y-6`,children:[a&&(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:K(`engine.diagnostics.loading`,t)}),!a&&o&&(0,X.jsx)(`div`,{className:`text-sm text-destructive border border-destructive/30 rounded p-3 bg-destructive/[0.06]`,children:G(`engine.diagnostics.loadFailed`,t,{error:o})}),!a&&!o&&d.length===0&&(0,X.jsxs)(Lr,{children:[(0,X.jsx)(bn,{children:K(`engine.diagnostics.cleanTitle`,t)}),(0,X.jsx)(mn,{children:G(`engine.diagnostics.cleanHint`,t,{items:s.scannedItems,types:s.scannedTypes})})]}),d.map(([e,i])=>(0,X.jsxs)(`section`,{className:`space-y-2`,children:[(0,X.jsxs)(`h2`,{className:`text-xs font-semibold uppercase tracking-wider text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(n,{to:`../${encodeURIComponent(e)}`,className:`hover:text-foreground hover:underline`,children:u[e]??e}),(0,X.jsx)(`span`,{className:`font-mono normal-case tracking-normal text-[10px] opacity-70`,children:e}),(0,X.jsx)(L,{variant:`outline`,className:`text-[10px] border-destructive/40 text-destructive bg-destructive/[0.06]`,children:i.length})]}),(0,X.jsx)(`div`,{className:`border rounded-lg overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40 text-xs uppercase tracking-wider text-muted-foreground`,children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{className:`px-3 py-2 text-left font-medium w-[28%]`,children:K(`engine.diagnostics.col.name`,t)}),(0,X.jsx)(`th`,{className:`px-3 py-2 text-left font-medium`,children:K(`engine.diagnostics.col.issues`,t)})]})}),(0,X.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,X.jsxs)(`tr`,{className:`hover:bg-accent/50 align-top`,children:[(0,X.jsxs)(`td`,{className:`px-3 py-2 align-top`,children:[(0,X.jsx)(n,{to:`../${encodeURIComponent(e)}/${encodeURIComponent(i.name)}`,className:`text-primary hover:underline font-mono`,children:i.name}),a.length>0&&(0,X.jsx)(L,{variant:`outline`,className:`ml-2 text-[10px] border-destructive/40 text-destructive`,children:G(`engine.diagnostics.errorN`,t,{count:a.length})}),o.length>0&&(0,X.jsx)(L,{variant:`outline`,className:`ml-2 text-[10px] border-amber-500/40 text-amber-700 dark:text-amber-300`,children:G(`engine.diagnostics.warnN`,t,{count:o.length})})]}),(0,X.jsx)(`td`,{className:`px-3 py-2 align-top`,children:(0,X.jsxs)(`ul`,{className:`space-y-0.5 font-mono text-[11px]`,children:[s.map((e,t)=>(0,X.jsxs)(`li`,{className:`truncate`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.path||`(root)`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`: `}),e.message]},t)),c>0&&(0,X.jsx)(`li`,{className:`text-muted-foreground`,children:G(`engine.diagnostics.more`,t,{count:c})})]})})]},i.name)})})]})})]},e))]})]})}function hu(e){let t=e.slice(0,20);if(t.length===0)return`{
11
+ "id": "record-1"
12
+ }`;let n={};for(let e of t)n[e]=null;return JSON.stringify(n,null,2)}var gu=JSON.stringify({id:`user-1`,organization_id:`org-1`,positions:[`admin`]},null,2),_u=[];function vu({open:e,onOpenChange:t,policyName:n,objectName:r,fieldNames:i=_u,using:a,check:o,t:s}){let c=Z.useMemo(()=>{let e=[];return a&&a.trim()&&e.push(`using`),o&&o.trim()&&e.push(`check`),e},[a,o]),[l,u]=Z.useState(`using`),[d,f]=Z.useState(`{}`),[p,m]=Z.useState(gu),[h,g]=Z.useState(null),[_,v]=Z.useState(null),[y,b]=Z.useState(!1);Z.useEffect(()=>{e&&(u(c[0]??`using`),f(hu(i)),m(gu),g(null),v(null))},[e]);let x=l===`using`?a??``:o??``;async function S(){g(null),v(null);let e=yu(d,s(`perm.cel.test.record`));if(!e.ok)return v(e.error);let t=yu(p,s(`perm.cel.test.user`));if(!t.ok)return v(t.error);b(!0);try{g(await fa(x,{record:e.value,currentUser:t.value}))}finally{b(!1)}}return(0,X.jsx)(Ir,{open:e,onOpenChange:t,children:(0,X.jsxs)(fn,{className:`sm:max-w-2xl`,children:[(0,X.jsxs)(vn,{children:[(0,X.jsxs)(On,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Xt,{className:`h-4 w-4 text-muted-foreground`}),s(`perm.cel.test.title`),n?(0,X.jsxs)(`span`,{className:`text-muted-foreground font-normal`,children:[`· `,n]}):null]}),(0,X.jsx)($n,{children:s(`perm.cel.test.help`)})]}),c.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground italic py-4`,children:s(`perm.cel.test.noPredicate`)}):(0,X.jsxs)(`div`,{className:`space-y-3`,children:[c.length>1&&(0,X.jsx)(`div`,{className:`flex items-center gap-1.5`,role:`tablist`,"aria-label":s(`perm.cel.test.clause`),children:c.map(e=>(0,X.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":l===e,onClick:()=>{u(e),g(null)},className:H(`rounded-md border px-3 py-1 text-xs transition-colors`,l===e?`border-primary bg-primary text-primary-foreground`:`border-input bg-background hover:bg-accent`),children:s(e===`using`?`perm.rls.using`:`perm.rls.check`)},e))}),(0,X.jsxs)(`div`,{className:`rounded-md border bg-muted/40 px-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`text-[10px] uppercase text-muted-foreground`,children:[s(l===`using`?`perm.rls.using`:`perm.rls.check`),r?` · ${r}`:``]}),(0,X.jsx)(`code`,{className:`block whitespace-pre-wrap break-words font-mono text-xs`,children:x})]}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-[10px] uppercase text-muted-foreground`,htmlFor:`cel-test-record`,children:s(`perm.cel.test.record`)}),(0,X.jsx)(ft,{id:`cel-test-record`,value:d,onChange:e=>f(e.target.value),rows:8,spellCheck:!1,className:`font-mono text-xs`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(V,{className:`text-[10px] uppercase text-muted-foreground`,htmlFor:`cel-test-user`,children:[s(`perm.cel.test.user`),` `,(0,X.jsx)(`span`,{className:`font-mono normal-case`,children:`current_user`})]}),(0,X.jsx)(ft,{id:`cel-test-user`,value:p,onChange:e=>m(e.target.value),rows:8,spellCheck:!1,className:`font-mono text-xs`})]})]}),_&&(0,X.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-destructive`,children:[(0,X.jsx)(St,{className:`mt-[1px] h-3.5 w-3.5 shrink-0`}),_]}),h&&(0,X.jsx)(bu,{outcome:h,t:s})]}),(0,X.jsxs)(Ur,{children:[(0,X.jsx)(W,{variant:`ghost`,onClick:()=>t(!1),children:s(`engine.cancel`)}),(0,X.jsxs)(W,{onClick:S,disabled:y||c.length===0,children:[(0,X.jsx)(Xt,{className:`h-4 w-4 mr-1`}),s(`perm.cel.test.run`)]})]})]})})}function yu(e,t){let n;try{n=JSON.parse(e||`{}`)}catch(e){return{ok:!1,error:`${t}: ${e.message}`}}return!n||typeof n!=`object`||Array.isArray(n)?{ok:!1,error:`${t}: expected a JSON object.`}:{ok:!0,value:n}}function bu({outcome:e,t}){return e.status===`allow`?(0,X.jsx)(Su,{tone:`allow`,icon:(0,X.jsx)(Fe,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.allow`),children:t(`perm.cel.test.allowHint`)}):e.status===`deny`?(0,X.jsx)(Su,{tone:`deny`,icon:(0,X.jsx)(ue,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.deny`),children:t(`perm.cel.test.denyHint`)}):e.status===`value`?(0,X.jsxs)(Su,{tone:`warn`,icon:(0,X.jsx)(z,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.nonBool`),children:[(0,X.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(e.value)}),` — `,t(`perm.cel.test.nonBoolHint`)]}):e.status===`unavailable`?(0,X.jsx)(Su,{tone:`warn`,icon:(0,X.jsx)(z,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.unavailable`),children:t(`perm.cel.test.unavailableHint`)}):(0,X.jsx)(Su,{tone:`error`,icon:(0,X.jsx)(St,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.error`),children:(0,X.jsx)(`code`,{className:`block whitespace-pre-wrap break-words font-mono text-[11px]`,children:e.message})})}var xu={allow:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,deny:`border-destructive/40 bg-destructive/10 text-destructive`,warn:`border-amber-500/40 bg-amber-500/10 text-amber-700 dark:text-amber-400`,error:`border-destructive/40 bg-destructive/10 text-destructive`};function Su({tone:e,icon:t,title:n,children:r}){return(0,X.jsxs)(`div`,{className:H(`rounded-md border px-3 py-2 text-xs`,xu[e]),role:`status`,"aria-live":`polite`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium`,children:[t,n]}),(0,X.jsx)(`div`,{className:`mt-1 opacity-90`,children:r})]})}var Cu=[`all`,`select`,`insert`,`update`,`delete`],wu=[`visible`,`hidden`,`default_on`,`default_off`];function Tu(e){if(Array.isArray(e))return e;if(typeof e==`string`&&e.trim())try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}return[]}function Eu(e){if(e&&typeof e==`object`&&!Array.isArray(e))return e;if(typeof e==`string`&&e.trim())try{let t=JSON.parse(e);if(t&&typeof t==`object`&&!Array.isArray(t))return t}catch{}return{}}var Du=`h-8 rounded-md border border-input bg-background px-2 text-sm disabled:opacity-50`;function Ou({title:e,icon:t,count:n,children:r,defaultOpen:i}){let[a,o]=Z.useState(!!i);return(0,X.jsxs)(xr,{open:a,onOpenChange:o,className:`border-b`,children:[(0,X.jsxs)(Ln,{className:`flex w-full items-center gap-2 px-6 py-2.5 text-left hover:bg-muted/40`,children:[(0,X.jsx)(Vn,{className:H(`h-4 w-4 text-muted-foreground transition-transform`,a&&`rotate-90`)}),t,(0,X.jsx)(`span`,{className:`text-sm font-medium`,children:e}),n!=null&&n>0&&(0,X.jsx)(L,{variant:`secondary`,className:`text-[10px]`,children:n})]}),(0,X.jsx)(ar,{className:`px-6 pb-4 pt-1`,children:r})]})}function ku({draft:e,setDraft:t,writable:n,allSetNames:r,loadObjectFields:i,onCelErrorsChange:a,t:o}){let s=Z.useMemo(()=>Tu(e.rowLevelSecurity),[e.rowLevelSecurity]),c=Z.useMemo(()=>Eu(e.adminScope),[e.adminScope]),l=Z.useMemo(()=>Eu(e.tabPermissions),[e.tabPermissions]),[u,d]=Z.useState({}),f=Z.useRef(new Set),p=Z.useCallback(e=>{let t=(e??``).trim();!t||t===`*`||!i||f.current.has(t)||(f.current.add(t),i(t).then(e=>d(n=>({...n,[t]:e}))).catch(()=>d(e=>({...e,[t]:[]}))))},[i]),m=e=>u[(e??``).trim()]??[],[h,g]=Z.useState({}),_=Z.useCallback((e,t)=>{let n=t.filter(e=>e.severity===`error`).length;g(t=>t[e]===n?t:{...t,[e]:n})},[]),[v,y]=Z.useState(null);Z.useEffect(()=>{s.forEach(e=>p(e.object)),g(e=>{let t=new Set;s.forEach((e,n)=>{t.add(`${n}:using`),t.add(`${n}:check`)});let n=!1,r={};for(let i of Object.keys(e))t.has(i)?r[i]=e[i]:n=!0;return n?r:e})},[s,p]);let b=Z.useMemo(()=>Object.values(h).reduce((e,t)=>e+t,0),[h]),x=Z.useRef(a);Z.useEffect(()=>{x.current=a}),Z.useEffect(()=>{x.current?.(b)},[b]);let S=v==null?void 0:s[v],C=e=>t(t=>({...t,rowLevelSecurity:e})),w=e=>t(t=>({...t,adminScope:{...Eu(t.adminScope),...e}})),T=e=>t(t=>({...t,tabPermissions:e})),E=Object.entries(l);return(0,X.jsxs)(`div`,{className:`border-b bg-muted/10`,children:[(0,X.jsxs)(Ou,{title:o(`perm.rls.title`),icon:(0,X.jsx)(hr,{className:`h-4 w-4 text-muted-foreground`}),count:s.length,children:[(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:o(`perm.rls.help`)}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[s.map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2 bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(R,{value:e.name??``,disabled:!n,placeholder:o(`perm.rls.name`),onChange:n=>{let r=[...s];r[t]={...e,name:n.target.value},C(r)},className:`h-8 w-48`}),(0,X.jsx)(R,{value:e.object??``,disabled:!n,placeholder:o(`perm.rls.object`),onChange:n=>{let r=[...s];r[t]={...e,object:n.target.value},C(r)},className:`h-8 w-40`}),(0,X.jsx)(`select`,{value:e.operation??`all`,disabled:!n,onChange:n=>{let r=[...s];r[t]={...e,operation:n.target.value},C(r)},className:Du,children:Cu.map(e=>(0,X.jsx)(`option`,{value:e,children:e},e))}),(0,X.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,X.jsx)(di,{checked:e.enabled!==!1,disabled:!n,onCheckedChange:n=>{let r=[...s];r[t]={...e,enabled:!!n},C(r)}}),o(`perm.rls.enabled`)]}),(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,className:`h-7 ml-auto text-xs text-muted-foreground`,onClick:()=>y(t),title:o(`perm.cel.test.title`),children:[(0,X.jsx)(Xt,{className:`h-3.5 w-3.5 mr-1`}),o(`perm.cel.test.run`)]}),n&&(0,X.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-destructive`,onClick:()=>C(s.filter((e,n)=>n!==t)),children:(0,X.jsx)(gn,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,X.jsx)(ya,{label:o(`perm.rls.using`),value:e.using??``,disabled:!n,placeholder:`organization_id == current_user.organization_id`,objectName:e.object,fieldNames:m(e.object),clause:`using`,onLintChange:e=>_(`${t}:using`,e),onChange:n=>{let r=[...s];r[t]={...e,using:n},C(r)},t:o}),(0,X.jsx)(ya,{label:o(`perm.rls.check`),value:e.check??``,disabled:!n,placeholder:o(`perm.rls.checkPlaceholder`),objectName:e.object,fieldNames:m(e.object),clause:`check`,onLintChange:e=>_(`${t}:check`,e),onChange:n=>{let r=[...s];r[t]={...e,check:n},C(r)},t:o})]})]},t)),s.length===0&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:o(`perm.rls.empty`)}),n&&(0,X.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>C([...s,{name:``,object:`*`,operation:`all`,using:``,enabled:!0,priority:0}]),children:[(0,X.jsx)(B,{className:`h-4 w-4 mr-1`}),` `,o(`perm.rls.add`)]})]})]}),(0,X.jsx)(vu,{open:v!=null,onOpenChange:e=>y(e?v:null),policyName:S?.name||void 0,objectName:S?.object,fieldNames:m(S?.object),using:S?.using,check:S?.check,t:o}),(0,X.jsxs)(Ou,{title:o(`perm.tabs.title`),icon:(0,X.jsx)(_e,{className:`h-4 w-4 text-muted-foreground`}),count:E.length,children:[(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:o(`perm.tabs.help`)}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[E.map(([e,t])=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(R,{value:e,disabled:!n,onChange:t=>{let n=t.target.value,r={};for(let[t,i]of E)r[t===e?n:t]=i;T(r)},className:`h-8 w-64`}),(0,X.jsx)(`select`,{value:t,disabled:!n,onChange:t=>T({...l,[e]:t.target.value}),className:Du,children:wu.map(e=>(0,X.jsx)(`option`,{value:e,children:o(`perm.tabs.vis.${e}`)},e))}),n&&(0,X.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-destructive`,onClick:()=>{let t={...l};delete t[e],T(t)},children:(0,X.jsx)(gn,{className:`h-4 w-4`})})]},e)),E.length===0&&(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:o(`perm.tabs.empty`)}),n&&(0,X.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>{l[``]===void 0&&T({...l,"":`visible`})},children:[(0,X.jsx)(B,{className:`h-4 w-4 mr-1`}),` `,o(`perm.tabs.add`)]})]})]}),(0,X.jsxs)(Ou,{title:o(`perm.admin.title`),icon:(0,X.jsx)(ci,{className:`h-4 w-4 text-muted-foreground`}),count:c.businessUnit||(c.assignablePermissionSets?.length??0)?1:0,children:[(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mb-3`,children:o(`perm.admin.help`)}),(0,X.jsxs)(`div`,{className:`space-y-3 max-w-2xl`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-end gap-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs`,children:o(`perm.admin.businessUnit`)}),(0,X.jsx)(R,{value:c.businessUnit??``,disabled:!n,onChange:e=>w({businessUnit:e.target.value}),className:`h-8 w-64`})]}),(0,X.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs pb-1.5`,children:[(0,X.jsx)(di,{checked:!!c.includeSubtree,disabled:!n,onCheckedChange:e=>w({includeSubtree:!!e})}),o(`perm.admin.includeSubtree`)]})]}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-x-6 gap-y-2`,children:[[`manageAssignments`,`perm.admin.manageAssignments`],[`manageBindings`,`perm.admin.manageBindings`],[`authorEnvironmentSets`,`perm.admin.authorEnvironmentSets`]].map(([e,t])=>(0,X.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs`,children:[(0,X.jsx)(di,{checked:!!c[e],disabled:!n,onCheckedChange:t=>w({[e]:!!t})}),o(t)]},e))}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(V,{className:`text-xs`,children:o(`perm.admin.assignableSets`)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[r.length===0&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:o(`perm.admin.noSets`)}),r.map(e=>{let t=(c.assignablePermissionSets??[]).includes(e);return(0,X.jsx)(`button`,{type:`button`,disabled:!n,"aria-pressed":t,onClick:()=>{let n=c.assignablePermissionSets??[],r=t?n.filter(t=>t!==e):[...n,e];w({assignablePermissionSets:r})},className:H(`rounded-full border px-3 py-1 text-xs transition-colors disabled:opacity-50`,t?`border-primary bg-primary text-primary-foreground`:`border-input bg-background hover:bg-accent`),children:e},e)})]})]})]})]})]})}function Au(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function ju(e){return e instanceof Set?e:new Set(e)}function Mu(e,t){let n=ju(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(Au(t))&&(i[t]=r);return{objects:r,fields:i}}function Nu(e,t,n){let r=ju(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(Au(t))||(a[t]=n);for(let[e,n]of Object.entries(t.fields??{}))r.has(Au(e))&&(a[e]=n);return{...e,name:t.name,label:t.label,isDefault:t.isDefault,objects:i,fields:a}}function Pu(e,t){let n={private:`perm.owd.private`,public_read:`perm.owd.public_read`,public_read_write:`perm.owd.public_read_write`,controlled_by_parent:`perm.owd.controlled_by_parent`};return n[t]?e(n[t]):t}function Fu(e){return[{key:`allowCreate`,short:`C`,tip:K(`perm.action.create`,e)},{key:`allowRead`,short:`R`,tip:K(`perm.action.read`,e)},{key:`allowEdit`,short:`U`,tip:K(`perm.action.edit`,e)},{key:`allowDelete`,short:`D`,tip:K(`perm.action.delete`,e)},{key:`allowTransfer`,short:`Tr`,tip:K(`perm.action.transfer`,e)},{key:`allowRestore`,short:`Re`,tip:K(`perm.action.restore`,e)},{key:`allowPurge`,short:`Pu`,tip:K(`perm.action.purge`,e)},{key:`viewAllRecords`,short:`VA`,tip:K(`perm.action.viewAll`,e)},{key:`modifyAllRecords`,short:`MA`,tip:K(`perm.action.modifyAll`,e)}]}function Iu({type:e,name:t,packageId:n,onDraftSaved:r,publishNonce:a,onOpenOwd:o,onDirtyChange:s,readOnly:c=!1,embedded:l=!1}){let u=i(),d=Ui(),f=k(),{entries:p}=Gi(d),m=p.find(t=>t.type===e),h=!!jc(e,m).allowOrgOverride&&!c,g=Ni(),_=Z.useCallback(e=>K(e,g),[g]),v=Z.useMemo(()=>Fu(g),[g]),[y,b]=Z.useState({name:t,objects:{},fields:{}}),x=Z.useRef(null),S=Z.useCallback(e=>{try{x.current=JSON.stringify(e)}catch{x.current=null}b(e)},[]),[C,w]=Z.useState([]),[T,E]=Z.useState({}),[D,O]=Z.useState(new Set),[A,j]=Z.useState(!0),[M,ee]=Z.useState(!1),[te,ne]=Z.useState(null),[P,re]=Z.useState(null),[F,ie]=Z.useState(``),[I,ae]=Z.useState(!1),[oe,se]=Z.useState(!1),[ce,le]=Z.useState(!1),[ue,de]=Z.useState(!1),[fe,pe]=Z.useState([]);Z.useEffect(()=>{let e=!1;return d.list(`permission`,{}).then(t=>{e||pe((t||[]).map(e=>e?.name).filter(e=>!!e))}).catch(()=>{}),()=>{e=!0}},[d]),Z.useEffect(()=>{let r=!1;return j(!0),(async()=>{try{let[i,a,o]=await Promise.all([d.layered(e,t).catch(()=>null),d.list(`object`,n?{packageId:n}:{}).catch(()=>[]),n?d.getDraft(e,t,{packageId:n}).catch(()=>null):Promise.resolve(null)]);if(r)return;let s=(o?o.item??o:null)??i?.effective??i?.code??{name:t,objects:{}},c=(a??[]).map(e=>{let t=e?.item??e;return{name:String(t?.name??``),label:t?.label,accessDefault:t?.access?.default,owd:typeof t?.sharingModel==`string`?t.sharingModel:void 0,owdExternal:typeof t?.externalSharingModel==`string`?t.externalSharingModel:void 0}}).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));w(c);let l={...s,name:String(s?.name??t),objects:s?.objects??{},fields:s?.fields??{}};if(n){let e=Mu(l,c.map(e=>e.name));S({...l,objects:e.objects,fields:e.fields})}else S(l)}catch(e){ne(e?.message??String(e))}finally{r||j(!1)}})(),()=>{r=!0}},[d,e,t,n,a,S]);async function me(e){if(!T[e])try{let t=(await d.get(`object`,e))?.fields,n=(Array.isArray(t)?t.map(e=>({name:String(e?.name??``),label:e?.label})):t&&typeof t==`object`?Object.entries(t).map(([e,t])=>({name:String(t?.name??e),label:t?.label})):[]).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));E(t=>({...t,[e]:n}))}catch{E(t=>({...t,[e]:[]}))}}let he=Z.useCallback(async e=>{try{let t=(await d.get(`object`,e))?.fields,n=(Array.isArray(t)?t.map(e=>String(e?.name??``)):t&&typeof t==`object`?Object.entries(t).map(([e,t])=>String(t?.name??e)):[]).filter(Boolean);return Array.from(new Set(n)).sort((e,t)=>e.localeCompare(t))}catch{return[]}},[d]),[ge,_e]=Z.useState(0),ve=Z.useMemo(()=>{let e=x.current;if(e==null)return!1;try{return JSON.stringify(y)!==e}catch{return!1}},[y]),ye=Z.useRef(s);Z.useEffect(()=>{ye.current=s}),Z.useEffect(()=>{ye.current?.(ve)},[ve]),Z.useEffect(()=>()=>{ye.current?.(!1)},[]),Z.useEffect(()=>{if(!ve)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[ve]);function be(e){O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),me(e)),n})}function xe(e,t,n){b(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 Se(e,t){b(n=>{let r=t===`none`?{}:t===`all`?Object.fromEntries(v.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 Ce(e,t,n,r){let i=`${e}.${t}`;b(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 we(e,t,n){n.length!==0&&b(r=>{let i={...r.fields??{}};for(let r of n){let n=`${e}.${r}`;t===`clear`?delete i[n]:t===`readable`?i[n]={readable:!0,editable:!1}:i[n]={readable:!0,editable:!0}}return{...r,fields:i}})}function Ee(e){if(!n)return e;let t=Mu(e,C.map(e=>e.name));return{...e,objects:t.objects,fields:t.fields}}async function De(t,i){let a=i??y;ee(!0),ne(null);try{let i=a;if(n){let t=C.map(e=>e.name);i=Nu((await d.layered(e,a.name).catch(()=>null))?.effective??a,a,t)}if(await d.save(e,a.name,i,{force:t,...n?{mode:`draft`,packageId:n}:{}}),n)S(Ee(i)),r?.();else{let t=await d.layered(e,a.name);S(Ee(t.effective??i))}re(null)}catch(e){if(e?.status===409&&N(e,`DESTRUCTIVE_CHANGE`)){let t=e?.body?.issues??[];re({issues:Array.isArray(t)?t:[],pending:a})}else ne(e?.message??String(e))}finally{ee(!1)}}let Oe=Z.useMemo(()=>{let e=F.trim().toLowerCase();return C.filter(t=>{if(I){let e=y.objects[t.name];if(!e||!Object.values(e).some(Boolean))return!1}return!e||t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)})},[C,F,I,y.objects]),ke=[{label:_(`perm.stat.objectsGranted`),value:Object.values(y.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:_(`perm.stat.fieldOverrides`),value:Object.keys(y.fields??{}).length}];return A?(0,X.jsx)(Sc,{entry:m,itemName:t,embedded:l,children:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`}),` `,_(`perm.loading`).replace(`{name}`,t)]})}):(0,X.jsxs)(Sc,{entry:m??{type:e,label:e},itemName:t,subtitle:_(`perm.subtitle.set`),stats:ke,embedded:l,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>l?de(!0):u(`./history?type=${encodeURIComponent(e)}`),children:[(0,X.jsx)(at,{className:`h-4 w-4 mr-1`}),` `,_(`engine.edit.history`)]}),h&&(0,X.jsxs)(W,{size:`sm`,onClick:()=>De(!1),disabled:M||ge>0,title:ge>0?_(`perm.cel.saveBlocked`):void 0,children:[M?(0,X.jsx)(U,{className:`h-4 w-4 mr-1 animate-spin`}):(0,X.jsx)(Yt,{className:`h-4 w-4 mr-1`}),_(`engine.edit.save`)]})]}),children:[(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[te&&(0,X.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,X.jsx)(z,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,X.jsx)(`span`,{children:te})]}),(0,X.jsxs)(`div`,{className:`border-b bg-muted/30`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>se(e=>!e),"aria-expanded":oe,className:`w-full px-6 py-2.5 flex items-center gap-2 text-left hover:bg-muted/50 transition-colors`,children:[oe?(0,X.jsx)(pr,{className:`h-4 w-4 shrink-0 text-muted-foreground`}):(0,X.jsx)(Vn,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:y.label||y.name}),(0,X.jsx)(L,{variant:`outline`,className:`text-[10px] shrink-0`,children:y.managedBy===`platform`?_(`perm.badge.platform`):y.managedBy===`package`||n?_(`perm.badge.package`):_(`perm.badge.custom`)}),!!y.isDefault&&(0,X.jsx)(L,{variant:`secondary`,className:`text-[10px] shrink-0`,children:_(`perm.badge.default`)}),h&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:_(`perm.basics.editHint`)}),!h&&(0,X.jsx)(L,{variant:`secondary`,className:`ml-auto shrink-0`,title:c?_(`engine.studio.pkg.readonlyHint`):void 0,children:_(c?`engine.studio.pkg.readonly`:`perm.readOnly`)})]}),oe&&(0,X.jsxs)(`div`,{className:`px-6 pb-3 flex flex-wrap items-end gap-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{htmlFor:`perm-name`,className:`text-xs`,children:_(`perm.field.name`)}),(0,X.jsx)(R,{id:`perm-name`,value:y.name,disabled:!h,onChange:e=>b(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{htmlFor:`perm-label`,className:`text-xs`,children:_(`perm.field.label`)}),(0,X.jsx)(R,{id:`perm-label`,value:y.label??``,disabled:!h,onChange:e=>b(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]})]})]}),h&&(y.systemPermissions??[]).length===0&&!ce?(0,X.jsxs)(`div`,{className:`px-6 py-2.5 border-b flex items-center gap-2 text-xs`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:_(`perm.field.systemCapabilities`)}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:_(`perm.cap.none`)}),(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>le(!0),children:[`+ `,_(`perm.cap.add`)]})]}):(0,X.jsxs)(`div`,{className:`px-6 py-3 border-b`,children:[(0,X.jsx)(V,{className:`text-xs`,children:_(`perm.field.systemCapabilities`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5 mb-2`,children:_(`perm.field.systemCapabilitiesHelp`)}),(0,X.jsx)(pt,{value:JSON.stringify(y.systemPermissions??[]),onChange:e=>b(t=>({...t,systemPermissions:Te(e)})),field:{name:`system_permissions`},dataSource:f,readonly:!h})]}),(0,X.jsxs)(`div`,{className:`px-6 py-3 border-b flex items-center gap-3`,children:[(0,X.jsx)(R,{placeholder:_(`perm.filter.placeholder`),value:F,onChange:e=>ie(e.target.value),className:`h-8 w-72`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(di,{id:`only-enabled`,checked:I,onCheckedChange:e=>ae(!!e)}),(0,X.jsx)(V,{htmlFor:`only-enabled`,className:`text-xs`,children:_(`perm.filter.onlyGranted`)})]}),(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[Oe.length,` / `,C.length,` `,_(`perm.stat.objectsSuffix`)]})]}),(0,X.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:v.map(e=>(0,X.jsxs)(`span`,{className:`whitespace-nowrap`,children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground`,children:e.short}),` `,e.tip]},e.key))}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-auto`,children:[(0,X.jsx)(Lu,{objects:Oe,draft:y,expanded:D,fieldsByObject:T,writable:h,objectActions:v,t:_,onToggleExpand:be,onObjectPerm:xe,onFieldPerm:Ce,onBulkSet:Se,onFieldBulk:we,onOpenOwd:o}),(0,X.jsx)(ku,{draft:y,setDraft:b,writable:h,allSetNames:fe,loadObjectFields:he,onCelErrorsChange:_e,t:_})]})]}),(0,X.jsx)(Ir,{open:!!P,onOpenChange:e=>!e&&re(null),children:(0,X.jsxs)(fn,{children:[(0,X.jsxs)(vn,{children:[(0,X.jsxs)(On,{className:`flex items-center gap-2`,children:[(0,X.jsx)(z,{className:`h-4 w-4 text-amber-500`}),` `,_(`engine.edit.destructive`)]}),(0,X.jsx)($n,{children:_(`engine.edit.destructiveHint`)})]}),(0,X.jsx)(`ul`,{className:`text-sm space-y-1 max-h-64 overflow-auto`,children:P?.issues.map((e,t)=>(0,X.jsxs)(`li`,{className:`border-l-2 border-amber-500 pl-2`,children:[e.kind&&(0,X.jsx)(L,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,X.jsxs)(Ur,{children:[(0,X.jsx)(W,{variant:`ghost`,onClick:()=>re(null),children:_(`engine.cancel`)}),(0,X.jsxs)(W,{variant:`destructive`,onClick:()=>P&&De(!0,P.pending),disabled:M,children:[M&&(0,X.jsx)(U,{className:`h-4 w-4 mr-1 animate-spin`}),_(`engine.edit.forceSave`)]})]})]})}),l&&(0,X.jsx)(Fr,{open:ue,onOpenChange:de,children:(0,X.jsxs)(un,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(Hr,{className:`px-4 py-3 border-b`,children:[(0,X.jsx)(_n,{className:`text-base`,children:_(`engine.edit.history`)}),(0,X.jsxs)(Qn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:ue&&(0,X.jsx)(sl,{type:e,name:t,client:d})})]})})]})}function Lu({objects:e,draft:t,expanded:n,fieldsByObject:r,writable:i,objectActions:a,t:o,onToggleExpand:s,onObjectPerm:c,onFieldPerm:l,onBulkSet:u,onFieldBulk:d,onOpenOwd:f}){return(0,X.jsxs)(`table`,{className:`w-full min-w-[960px] text-sm`,children:[(0,X.jsx)(`thead`,{className:`sticky top-0 bg-background border-b z-10`,children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{className:`text-left px-4 py-2 font-medium w-72`,children:o(`perm.col.object`)}),a.map(e=>(0,X.jsx)(`th`,{className:`px-2 py-2 font-medium text-center w-14`,title:e.tip,children:e.short},e.key)),(0,X.jsx)(`th`,{className:`px-2 py-2 font-medium w-44 text-right`,children:o(`perm.col.bulk`)})]})}),(0,X.jsxs)(`tbody`,{children:[e.length===0&&(0,X.jsx)(`tr`,{children:(0,X.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 p=t.objects[e.name]??{},m=n.has(e.name);return(0,X.jsxs)(Z.Fragment,{children:[(0,X.jsxs)(`tr`,{className:`border-b hover:bg-muted/30`,children:[(0,X.jsxs)(`td`,{className:`px-2 py-1.5 align-middle`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name),className:`inline-flex items-center gap-1.5 hover:text-foreground`,children:[m?(0,X.jsx)(pr,{className:`h-3.5 w-3.5`}):(0,X.jsx)(Vn,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),e.label&&(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`(`,e.name,`)`]})]}),e.accessDefault===`private`&&(0,X.jsx)(L,{variant:`outline`,className:`ml-2 border-amber-500/50 text-amber-600 dark:text-amber-400 text-[10px] px-1.5 py-0 align-middle`,title:o(`perm.posture.private.tip`),children:o(`perm.posture.private`)}),(0,X.jsx)(L,{variant:`outline`,className:`ml-2 text-[10px] px-1.5 py-0 align-middle text-muted-foreground`+(f?` cursor-pointer hover:text-foreground hover:border-foreground/40 focus:outline-none focus:ring-1 focus:ring-primary`:``),title:o(f?`perm.owd.editLink`:`perm.owd.tip`),...f?{role:`button`,tabIndex:0,"data-testid":`owd-badge-${e.name}`,onClick:()=>f(e.name),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),f(e.name))}}:{},children:`OWD ${e.owd?Pu(o,e.owd):o(`perm.owd.defaultPrivate`)}`}),e.owdExternal&&(0,X.jsx)(L,{variant:`outline`,className:`ml-1 text-[10px] px-1.5 py-0 align-middle text-muted-foreground`,title:o(`perm.owd.ext.tip`),children:`Ext ${Pu(o,e.owdExternal)}`})]}),a.map(t=>(0,X.jsx)(`td`,{className:`text-center px-2 py-1.5`,children:(0,X.jsx)(jn,{checked:!!p[t.key],disabled:!i,onCheckedChange:n=>c(e.name,t.key,!!n),"aria-label":`${e.name} ${t.tip}`})},t.key)),(0,X.jsxs)(`td`,{className:`px-2 py-1.5 text-right space-x-1`,children:[(0,X.jsx)(W,{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,X.jsx)(W,{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,X.jsx)(W,{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,X.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:!i,onClick:()=>u(e.name,`none`),children:o(`perm.bulk.none`)})]})]}),m&&(0,X.jsx)(`tr`,{className:`bg-muted/10`,children:(0,X.jsx)(`td`,{colSpan:a.length+2,className:`px-12 py-3`,children:(0,X.jsx)(Ru,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l,onFieldBulk:d})})})]},e.name)})]})]})}function Ru({objectName:e,fields:t,fieldsState:n,writable:r,t:i,onFieldPerm:a,onFieldBulk:o}){let[s,c]=Z.useState(``);if(!t)return(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(U,{className:`h-3 w-3 animate-spin`}),` `,i(`perm.field.loading`)]});if(t.length===0)return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.empty`)});let l=s.trim().toLowerCase(),u=l?t.filter(e=>e.name.toLowerCase().includes(l)||(e.label??``).toLowerCase().includes(l)):t,d=u.map(e=>e.name);return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[t.length>6&&(0,X.jsx)(R,{value:s,onChange:e=>c(e.target.value),placeholder:i(`perm.field.filter`),"aria-label":i(`perm.field.filter`),className:`h-7 w-44 text-xs`}),r&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:d.length===0,onClick:()=>o(e,`readable`,d),children:i(`perm.field.bulk.readable`)}),(0,X.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:d.length===0,onClick:()=>o(e,`writable`,d),children:i(`perm.field.bulk.writable`)}),(0,X.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 px-1.5 text-xs`,disabled:d.length===0,onClick:()=>o(e,`clear`,d),children:i(`perm.field.bulk.clear`)})]}),(0,X.jsxs)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,children:[u.length,` / `,t.length]})]}),u.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:i(`perm.field.filterEmpty`)}):(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`text-muted-foreground`,children:[(0,X.jsx)(`th`,{className:`text-left py-1 font-medium`,children:i(`perm.field.col.name`)}),(0,X.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.read`),children:i(`perm.field.read`)}),(0,X.jsx)(`th`,{className:`px-2 py-1 font-medium w-16 text-center`,title:i(`perm.field.edit`),children:i(`perm.field.edit`)})]})}),(0,X.jsx)(`tbody`,{children:u.map(t=>{let i=n[`${e}.${t.name}`]??{readable:!0,editable:!1};return(0,X.jsxs)(`tr`,{className:`border-t border-muted`,children:[(0,X.jsxs)(`td`,{className:`py-1`,children:[t.label??t.name,t.label&&(0,X.jsxs)(`span`,{className:`ml-1 text-muted-foreground`,children:[`(`,t.name,`)`]})]}),(0,X.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,X.jsx)(jn,{checked:!!i.readable,disabled:!r,onCheckedChange:n=>a(e,t.name,`readable`,!!n),"aria-label":`${e}.${t.name} readable`})}),(0,X.jsx)(`td`,{className:`px-2 py-1 text-center`,children:(0,X.jsx)(jn,{checked:!!i.editable,disabled:!r,onCheckedChange:n=>a(e,t.name,`editable`,!!n),"aria-label":`${e}.${t.name} editable`})})]},t.name)})})]})]})}function zu(){Oc({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>Bu(e.fields),groupLabel:`Fields`,order:5}]}),Oc({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}]}),Oc({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>Bu(e.validations),groupLabel:`Embedded Validations`,order:15}]}),Oc({type:`hook`,anchors:[{anchorType:`object`,match:Ec(`object`),groupLabel:`Hooks`,order:20}],createFields:[`label`,`name`,`object`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`object`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable hook name.`},name:{type:`string`,title:`Name`,description:`Hook key (snake_case).`,pattern:`^[a-z_][a-z0-9_]*$`},object:{type:`string`,title:`Object`,widget:`ref:object`,description:`The object whose row lifecycle (beforeInsert / afterUpdate / …) this hook runs on.`},description:{type:`string`,title:`Description`,description:`What this hook does.`}}},createDefaults:{events:[]}}),Oc({type:`page`,anchors:[{anchorType:`object`,match:Ec(`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-DuVwtJw-.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{}}}}),Oc({type:`view`,anchors:[{anchorType:`object`,match:Ec([`object`,`config.data.object`]),groupLabel:`Views`,order:30}],createFields:[`label`,`name`,`object`,`viewKind`,`kind`,`formType`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`,`object`,`viewKind`],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`,widget:`ref:object`,description:`The object this view displays.`},viewKind:{type:`string`,title:`View family`,enum:[`list`,`form`],default:`list`,description:`List views show many records as a collection (grid, kanban, …). Form views show one record as a field layout (simple, tabbed, …).`},kind:{type:`string`,title:`List layout`,enum:[`grid`,`kanban`,`gallery`,`calendar`,`timeline`,`gantt`,`chart`],default:`grid`,description:`Pick a starter layout. Switch later in the designer.`,visibleOn:`data.viewKind == 'list'`},formType:{type:`string`,title:`Form layout`,enum:[`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`],default:`simple`,description:`Pick a starter form layout. Switch later in the designer.`,visibleOn:`data.viewKind == 'form'`}}},createBuildBody:e=>{let t=String(e.object??``),n=String(e.name??``),r=n.includes(`.`)||!t?n:`${t}.${n}`,i=e.viewKind===`form`,a=i?{type:e.formType||`simple`,data:{provider:`object`,object:t},sections:[]}:{type:e.kind||`grid`,columns:[],data:{provider:`object`,object:t}};return{name:r,object:t,viewKind:i?`form`:`list`,label:e.label,config:a}}}),Oc({type:`flow`,anchors:[{anchorType:`object`,match:Ec([`object`,`on.object`,`trigger.object`]),groupLabel:`Flows`,order:50}],createFields:[`label`,`name`,`type`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{type:`autolaunched`,nodes:[],edges:[]}}),Oc({type:`validation`,anchors:[{anchorType:`object`,match:Ec(`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`}}),Oc({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`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{objects:{}}}),Oc({type:`action`,anchors:[{anchorType:`object`,match:Ec([`object`,`target.object`,`on.object`]),groupLabel:`Actions`,order:55}],createFields:[`label`,`name`,`objectName`,`icon`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createSchema:{type:`object`,required:[`label`,`name`],properties:{label:{type:`string`,title:`Label`,description:`Human-readable action name.`},name:{type:`string`,title:`Name`,description:`Action key (snake_case). Used in URLs.`,pattern:`^[a-z_][a-z0-9_]*$`},objectName:{type:`string`,title:`Object`,widget:`ref:object`,description:`The object this action is bound to. Leave empty for a global / record-scoped action.`},icon:{type:`string`,title:`Icon`,widget:`icon`,description:`Optional icon shown on the action button.`}}},createDefaults:{type:`script`,body:{language:`js`,source:`return { success: true };`}}}),Oc({type:`dashboard`,anchors:[{anchorType:`object`,match:Ec([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),Oc({type:`report`,anchors:[{anchorType:`object`,match:Ec([`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}}),Oc({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 Bu(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var Vu={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`}},Hu={position:{type:`object`,title:`Position`,required:[`name`],properties:{...Vu}},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:{...Vu.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:Vu.label,description:Vu.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:{...Vu,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:{...Vu,instructions:{type:`string`,title:`Instructions`,format:`multiline`},tools:{type:`array`,title:`Tools`,items:{type:`string`}},surface:{type:`string`,title:`Surface`,description:`Agent surface this skill binds to (ADR-0063).`,enum:[`ask`,`build`,`both`]},triggerPhrases:{type:`array`,title:`Trigger Phrases`,description:`Natural-language phrases that activate this skill.`,items:{type:`string`}},triggerConditions:{type:`array`,title:`Trigger Conditions`,description:`Programmatic activation conditions (context field / operator / value). The activation-critical field — previously only hand-editable (#1878/#1895).`,items:{type:`object`,properties:{field:{type:`string`,title:`Field`},operator:{type:`string`,title:`Operator`,enum:[`eq`,`neq`,`in`,`not_in`,`contains`]},value:{type:`string`,title:`Value`}}}}}},app:{type:`object`,title:`Application`,required:[`name`],properties:{...Vu,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...Vu,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...Vu,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:{...Vu,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...Vu,object:{type:`string`,title:`Object`},filters:{type:`array`,title:`Filters`,items:{type:`object`}}}},book:{type:`object`,title:`Documentation Book`,required:[`name`,`groups`],properties:{...Vu,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; { permissionSet } gates by a permission set the reader must hold (ADR-0090).`,oneOf:[{type:`string`,enum:[`org`,`public`]},{type:`object`,title:`Permission-set gated`,properties:{permissionSet:{type:`string`,title:`Permission set`}},required:[`permissionSet`]}]},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:{...Vu,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 Uu(){for(let[e,t]of Object.entries(Hu))Oc({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}function Wu({status:e,reason:t}){if(!e)return null;let n=(e,n)=>(0,X.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded px-1.5 py-0.5 font-medium ${e}`,title:t||void 0,children:n});switch(e){case`ok`:return n(`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`,`connected`);case`error`:return n(`bg-destructive/10 text-destructive`,`connect failed`);case`blocked`:return n(`bg-amber-500/10 text-amber-600 dark:text-amber-400`,`blocked by policy`);case`unvalidated`:return n(`bg-muted text-muted-foreground`,`not connected`);default:return n(`bg-muted text-muted-foreground`,e)}}var Gu=[{value:`managed`,label:`Managed (ObjectStack owns the schema)`},{value:`external`,label:`External (read existing schema as-is)`},{value:`validate-only`,label:`Validate only`}],Ku=``.replace(/\/+$/,``),qu=e=>e.format===`password`;function Ju(e){let t=e?.configSchema?.properties??{},n={};for(let[e,r]of Object.entries(t))qu(r)||r.default!==void 0&&(n[e]=r.default);return n}function Yu(e){let t=Z.useMemo(()=>f(),[]),n=Ui(),[r,i]=Z.useState([]),[a,o]=Z.useState(!0),[s,c]=Z.useState(null),l=Z.useCallback(async(e,n)=>{let r=await t(`${Ku}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`},...n}),i=await r.text(),a=i;try{a=JSON.parse(i)}catch{}if(!r.ok){let e=a&&typeof a.error==`object`&&a.error?.message||(a&&typeof a.error==`string`?a.error:void 0)||a&&a.message||`HTTP ${r.status}`;throw Error(e)}return a&&typeof a.success==`boolean`&&`data`in a?a.data:a},[t]),u=Z.useCallback(async()=>{o(!0);try{let e=await l(`/api/v1/datasources`);i(Array.isArray(e?.datasources)?e.datasources:[])}catch(e){fi.error(`Load datasources: ${e.message}`),i([])}finally{o(!1)}},[l]);Z.useEffect(()=>{u()},[u]);let d=async e=>{c(`test:${e}`);try{let t=await l(`/api/v1/datasources/${encodeURIComponent(e)}/test`,{method:`POST`,body:`{}`});fi.success(t?.ok===!1?`${e}: ${t?.error??`failed`}`:`${e}: connection ok${t?.latencyMs==null?``:` (${t.latencyMs}ms)`}`),u()}catch(t){fi.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`}),fi.success(`Deleted ${e}.`),u()}catch(t){fi.error(`Delete ${e}: ${t.message}`)}finally{c(null)}}},[m,h]=Z.useState([]),[g,_]=Z.useState(!1),[v,y]=Z.useState(null),[b,x]=Z.useState(null),[S,C]=Z.useState(!1),[w,T]=Z.useState(!1),[E,D]=Z.useState(null),[O,k]=Z.useState(!1),A=Z.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 fi.error(`Load drivers: ${e.message}`),[]}},[l,m]),j=Z.useMemo(()=>m.find(e=>e.id===b?.driver),[m,b?.driver]),M=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:Ju(t),secret:``}),_(!0)},ee=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){fi.error(`Open ${e.name}: ${t.message}`)}finally{c(null)}},te=e=>{x(t=>t&&{...t,driver:e,config:Ju(m.find(t=>t.id===e)),secret:``}),D(null)},N=(e,t)=>x(n=>n&&{...n,config:{...n.config,[e]:t}}),ne=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},P=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)}}},re=async()=>{if(b){T(!0);try{v?(await l(`/api/v1/datasources/${encodeURIComponent(v)}`,{method:`PATCH`,body:JSON.stringify(ne(b))}),fi.success(`Updated ${v}.`)):(await l(`/api/v1/datasources`,{method:`POST`,body:JSON.stringify({name:b.name,...ne(b)})}),fi.success(`Created ${b.name}.`)),_(!1),u()}catch(e){fi.error(`Save: ${e.message}`)}finally{T(!1)}}},F=v?!0:/^[a-z_][a-z0-9_]*$/.test(b?.name??``),ie=!!b&&!!b.driver&&F&&!w,[I,ae]=Z.useState(null),[oe,se]=Z.useState(null),[ce,le]=Z.useState(new Set),[ue,de]=Z.useState(!1),me=async e=>{ae(e),se(null),le(new Set);try{let t=await l(`/api/v1/datasources/${encodeURIComponent(e)}/remote-tables`);se(Array.isArray(t?.tables)?t.tables:[])}catch(t){fi.error(`Introspect ${e}: ${t.message}`),se([])}},he=e=>le(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),L=async()=>{if(!I||ce.size===0)return;de(!0);let e=0,t=[];for(let r of ce)try{let{draft:t}=await l(`/api/v1/datasources/${encodeURIComponent(I)}/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}`)}de(!1),e&&fi.success(`Synced ${e} object${e>1?`s`:``} from ${I}.`),t.length&&fi.error(`Failed: ${t.join(`; `)}`),ae(null)},_e=(e,t)=>{let n=t.title||e,r=(j?.configSchema?.required??[]).includes(e);if(qu(t))return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(V,{className:`text-xs`,children:[n,r&&!v?` *`:``]}),(0,X.jsx)(R,{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,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]},e);let i=b?.config[e];if(t.type===`boolean`)return(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 py-1`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(V,{className:`text-xs`,children:n}),t.description&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]}),(0,X.jsx)(di,{checked:!!i,onCheckedChange:t=>N(e,t)})]},e);if(Array.isArray(t.enum))return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(V,{className:`text-xs`,children:[n,r?` *`:``]}),(0,X.jsxs)(yr,{value:i==null?``:String(i),onValueChange:t=>N(e,t),children:[(0,X.jsx)(An,{children:(0,X.jsx)($t,{placeholder:`Select…`})}),(0,X.jsx)(rr,{children:t.enum.map(e=>(0,X.jsx)(In,{value:String(e),children:String(e)},String(e)))})]})]},e);let a=t.type===`number`||t.type===`integer`;return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(V,{className:`text-xs`,children:[n,r?` *`:``]}),(0,X.jsx)(R,{type:a?`number`:`text`,value:i==null?``:String(i),onChange:t=>N(e,a?t.target.value===``?void 0:Number(t.target.value):t.target.value)}),t.description&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]},e)};return(0,X.jsxs)(`div`,{className:`mx-auto max-w-4xl px-6 py-8`,children:[(0,X.jsxs)(`div`,{className:`mb-6 flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`h1`,{className:`flex items-center gap-2 text-xl font-semibold`,children:[(0,X.jsx)(ge,{className:`h-5 w-5`}),` Datasources`]}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Connect external databases and sync their tables in as objects.`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>void u(),disabled:a,children:[(0,X.jsx)(Mr,{className:`mr-1.5 h-4 w-4`+(a?` animate-spin`:``)}),` Refresh`]}),(0,X.jsxs)(W,{size:`sm`,onClick:()=>void M(),children:[(0,X.jsx)(B,{className:`mr-1.5 h-4 w-4`}),` New datasource`]})]})]}),a?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 py-12 text-sm text-muted-foreground`,children:[(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Loading…`]}):r.length===0?(0,X.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,X.jsx)(`span`,{className:`font-medium`,children:`New datasource`}),` to connect one.`]}):(0,X.jsx)(`div`,{className:`divide-y rounded-lg border bg-card`,children:r.map(e=>{let t=e.origin===`code`;return(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-3`,children:[(0,X.jsx)(ge,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.label||e.name}),(0,X.jsx)(`code`,{className:`text-[11px] text-muted-foreground`,children:e.name})]}),(0,X.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 font-mono`,children:e.driver}),(0,X.jsx)(Wu,{status:e.status,reason:e.statusReason}),e.origin&&(0,X.jsxs)(`span`,{children:[`· `,e.origin]})]}),e.statusReason&&(e.status===`error`||e.status===`blocked`)&&(0,X.jsx)(`div`,{className:`mt-0.5 truncate text-[11px] text-muted-foreground`,title:e.statusReason,children:e.statusReason})]}),(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,disabled:s===`test:${e.name}`,onClick:()=>void d(e.name),children:[s===`test:${e.name}`?(0,X.jsx)(U,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,X.jsx)(Zt,{className:`mr-1.5 h-4 w-4`}),` Test`]}),(0,X.jsxs)(W,{variant:`secondary`,size:`sm`,onClick:()=>void me(e.name),children:[(0,X.jsx)(Jr,{className:`mr-1.5 h-4 w-4`}),` Sync objects`]}),!t&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,title:`Edit`,disabled:s===`edit:${e.name}`,onClick:()=>void ee(e),children:s===`edit:${e.name}`?(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`}):(0,X.jsx)(pe,{className:`h-4 w-4`})}),(0,X.jsx)(W,{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,X.jsx)(U,{className:`h-4 w-4 animate-spin`}):(0,X.jsx)(gn,{className:`h-4 w-4`})})]})]},e.name)})}),(0,X.jsx)(Ir,{open:g,onOpenChange:e=>{e||_(!1)},children:(0,X.jsxs)(fn,{className:`max-w-lg`,children:[(0,X.jsxs)(vn,{children:[(0,X.jsx)(On,{children:v?`Edit “${v}”`:`New datasource`}),(0,X.jsx)($n,{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,X.jsxs)(`div`,{className:`max-h-[60vh] space-y-3 overflow-y-auto pr-1`,children:[!v&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs`,children:`Name *`}),(0,X.jsx)(R,{value:b.name,placeholder:`my_database`,onChange:e=>x(t=>t&&{...t,name:e.target.value})}),!F&&b.name.length>0&&(0,X.jsx)(`p`,{className:`text-[11px] text-destructive`,children:`Lowercase letters, digits, and underscores; must not start with a digit.`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs`,children:`Label`}),(0,X.jsx)(R,{value:b.label,placeholder:`Human-friendly name`,onChange:e=>x(t=>t&&{...t,label:e.target.value})})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs`,children:`Driver *`}),(0,X.jsxs)(yr,{value:b.driver,onValueChange:te,disabled:!!v,children:[(0,X.jsx)(An,{children:(0,X.jsx)($t,{placeholder:`Choose a driver`})}),(0,X.jsx)(rr,{children:m.map(e=>(0,X.jsx)(In,{value:e.id,children:e.label},e.id))})]}),j?.description&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:j.description})]}),Object.entries(j?.configSchema?.properties??{}).map(([e,t])=>_e(e,t)),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs`,children:`Schema mode`}),(0,X.jsxs)(yr,{value:b.schemaMode,onValueChange:e=>x(t=>t&&{...t,schemaMode:e}),children:[(0,X.jsx)(An,{children:(0,X.jsx)($t,{})}),(0,X.jsx)(rr,{children:Gu.map(e=>(0,X.jsx)(In,{value:e.value,children:e.label},e.value))})]})]}),E&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs `+(E.ok?`text-emerald-600`:`text-destructive`),children:[E.ok?(0,X.jsx)(Jt,{className:`h-3.5 w-3.5`}):(0,X.jsx)(fe,{className:`h-3.5 w-3.5`}),E.text]})]}),(0,X.jsxs)(Ur,{className:`gap-2 sm:justify-between`,children:[(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,disabled:!b?.driver||O,onClick:()=>void P(),children:[O?(0,X.jsx)(U,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,X.jsx)(Zt,{className:`mr-1.5 h-4 w-4`}),` Test connection`]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>_(!1),children:`Cancel`}),(0,X.jsxs)(W,{size:`sm`,disabled:!ie,onClick:()=>void re(),children:[w&&(0,X.jsx)(U,{className:`mr-1.5 h-4 w-4 animate-spin`}),v?`Save changes`:`Create datasource`]})]})]})]})}),(0,X.jsx)(Ir,{open:!!I,onOpenChange:e=>{e||ae(null)},children:(0,X.jsxs)(fn,{className:`max-w-lg`,children:[(0,X.jsxs)(vn,{children:[(0,X.jsxs)(On,{children:[`Sync objects from “`,I,`”`]}),(0,X.jsx)($n,{children:`Pick the remote tables to import as objects. Each becomes an object definition.`})]}),oe==null?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 py-8 text-sm text-muted-foreground`,children:[(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Introspecting…`]}):oe.length===0?(0,X.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`No remote tables found on this datasource.`}):(0,X.jsx)(`div`,{className:`max-h-[50vh] space-y-1 overflow-y-auto`,children:oe.map(e=>{let t=e.schema?`${e.schema}.${e.name}`:e.name;return(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded px-2 py-1.5 text-sm hover:bg-accent`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:ce.has(e.name),onChange:()=>he(e.name),className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`flex-1`,children:t}),e.columnCount!=null&&(0,X.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[e.columnCount,` cols`]})]},t)})}),(0,X.jsxs)(`div`,{className:`mt-2 flex items-center justify-end gap-2`,children:[(0,X.jsx)(W,{variant:`ghost`,size:`sm`,onClick:()=>ae(null),children:`Cancel`}),(0,X.jsxs)(W,{size:`sm`,disabled:ue||ce.size===0,onClick:()=>void L(),children:[ue?(0,X.jsx)(U,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,X.jsx)(Jr,{className:`mr-1.5 h-4 w-4`}),`Create `,ce.size||``,` object`,ce.size===1?``:`s`]})]})]})})]})}var Xu=!1;function Zu(){Xu||(Xu=!0,Oc({type:`datasource`,label:`Datasources`,domain:`data`,ListPage:Yu}))}function Q({toolbar:e,children:t}){return(0,X.jsxs)(`div`,{className:`rounded-lg border bg-background overflow-hidden flex flex-col h-full`,children:[e!=null&&(0,X.jsx)(`div`,{className:`flex items-center justify-end border-b bg-muted/20 px-2 py-1 min-h-[32px]`,children:e}),(0,X.jsx)(`div`,{className:`bg-background flex-1 min-h-0 overflow-auto`,children:t})]})}function Qu({tone:e=`info`,children:t}){return(0,X.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,X.jsx)(St,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,X.jsx)(`div`,{className:`flex-1`,children:t})]})}function $u({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,X.jsx)(ye,{className:`h-8 w-8 opacity-50`});return(0,X.jsx)(`div`,{className:`h-full w-full flex items-center justify-center p-6`,children:(0,X.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,X.jsx)(`div`,{className:`text-foreground/60`,children:o}),(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground/90`,children:t}),n&&(0,X.jsx)(`div`,{className:`text-xs leading-relaxed`,children:n}),r&&(0,X.jsx)(`div`,{className:`mt-1`,children:r})]})})}var ed=class extends Z.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e){console.error(`[MetadataPreview] render failed`,e)}render(){return this.state.error?(0,X.jsxs)(Qu,{tone:`error`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:`Preview failed to render`}),(0,X.jsx)(`div`,{className:`text-xs mt-1 font-mono opacity-80`,children:this.state.error.message}),this.props.fallbackHint&&(0,X.jsx)(`div`,{className:`text-xs mt-2 opacity-70`,children:this.props.fallbackHint})]}):this.props.children}};function td({title:e,entries:t,selectedId:n,onSelect:r,onAdd:i,addLabel:a}){return t.length===0&&!i?null:(0,X.jsxs)(`div`,{className:`border-b bg-muted/30 px-3 py-2`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground mb-1.5`,children:e}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[t.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),r(e)},className:H(`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,X.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,X.jsx)(B,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:a??`Add`})]})]})]})}var nd=Z.lazy(async()=>({default:(await a(()=>import(`./dist-Bq1W1ETM.js`).then(e=>e.n),[],import.meta.url)).default}));function rd(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 id({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]=Z.useState(o),l=Z.useRef(o);Z.useEffect(()=>{o!==l.current&&(c(o),l.current=o)},[o]);let[u,d]=Rl(r),[f,p]=Z.useState(()=>typeof document<`u`&&document.documentElement.classList.contains(`dark`)?`vs-dark`:`light`);Z.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=Z.useMemo(()=>({...e,type:e.type??`page`}),[e]),g=(0,X.jsx)(`div`,{ref:d,className:`h-full min-h-[260px] overflow-hidden bg-background`,children:u?(0,X.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,X.jsx)(Z.Suspense,{fallback:(0,X.jsx)(nn,{className:`h-full w-full`}),children:(0,X.jsx)(nd,{value:s,language:`typescript`,path:a===`react`?`page.tsx`:`page.html.tsx`,theme:f,beforeMount:rd,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}}})})}),_=(0,X.jsx)(`div`,{className:`h-full min-h-[260px] overflow-auto bg-muted/20`,children:(0,X.jsx)(ed,{fallbackHint:`The page source threw while rendering — fix the code in the Source tab.`,children:(0,X.jsx)(ee,{schema:h})})});return i===`editor`?g:i===`preview`?(0,X.jsx)(Q,{hint:`page · ${a} source`,children:_}):(0,X.jsx)(Q,{hint:`page · ${a} source`,children:(0,X.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,_]})})}var ad={grid:{label:`Grid`,category:`data`,Icon:en},"object-grid":{label:`Table`,category:`data`,Icon:$r},"object-form":{label:`Form`,category:`data`,Icon:Br},"object-metric":{label:`Metric`,category:`data`,Icon:Ft},"object-kanban":{label:`Kanban`,category:`data`,Icon:dt},"page:header":{label:`Header`,category:`layout`,Icon:_e},"page:footer":{label:`Footer`,category:`layout`,Icon:mt},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:Wn},"page:tabs":{label:`Tabs`,category:`layout`,Icon:je},"page:accordion":{label:`Accordion`,category:`layout`,Icon:ae},"page:card":{label:`Card`,category:`layout`,Icon:qn},"page:section":{label:`Section`,category:`layout`,Icon:ri},"record:details":{label:`Record details`,category:`record`,Icon:dr},"record:highlights":{label:`Highlights`,category:`record`,Icon:on},"record:related_list":{label:`Related list`,category:`record`,Icon:Dn},"record:activity":{label:`Activity timeline`,category:`record`,Icon:Ye},"record:chatter":{label:`Chatter feed`,category:`record`,Icon:Ut},"record:path":{label:`Stage path`,category:`record`,Icon:be},"record:alert":{label:`Alert banner`,category:`record`,Icon:z},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:Ht},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:ut},"record:history":{label:`History`,category:`record`,Icon:at},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:re},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:be},"global:search":{label:`Global search`,category:`navigation`,Icon:We},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:gt},"element:text":{label:`Text`,category:`element`,Icon:Pr},"element:number":{label:`Number`,category:`element`,Icon:st},"element:image":{label:`Image`,category:`element`,Icon:Jn},"element:divider":{label:`Divider`,category:`element`,Icon:Cr},"element:button":{label:`Button`,category:`element`,Icon:Ne},"element:definition-list":{label:`Definition list`,category:`element`,Icon:dn},"element:repeater":{label:`Repeater`,category:`element`,Icon:F}},od={data:`Data`,layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},sd=(()=>{let e={data:[],layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(ad))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)})(),cd=Mt,ld={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 ud(e){return ld[ad[e]?.category??`misc`]}var dd={"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`},{name:`action`,label:`Action`,kind:`json`,placeholder:`{ "type": "url", "target": "/environments" }`}],"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:input":[{name:`agentName`,label:`Agent`,kind:`text`,placeholder:`agent name`},{name:`placeholder`,label:`Input placeholder`,kind:`text`}]};function fd(e){return!!e&&Array.isArray(dd[e])&&dd[e].length>0}function pd(){let e=Ui(),[t,n]=Z.useState([]),[r,i]=Z.useState(!0);return Z.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 md(e){let{fields:t}=xa(e);return Z.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 hd({label:e,value:t,onCommit:n,disabled:r}){let{options:i}=pd();return i.length===0?(0,X.jsx)(q,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,X.jsx)(J,{label:e,value:t||void 0,options:i,onCommit:n,disabled:r})}function gd({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let a=md(t);return!t||a.length===0?(0,X.jsx)(q,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,X.jsx)(J,{label:e,value:n||void 0,options:a,onCommit:r,disabled:i})}function _d({label:e,objectName:t,value:n,onChange:r,disabled:i}){let a=md(t),o=Array.isArray(n)?n:[];return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),o.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[a.length>0?(0,X.jsx)(`div`,{className:`flex-1`,children:(0,X.jsxs)(yr,{value:e?String(e):``,onValueChange:e=>{let n=[...o];n[t]=e,r(n)},disabled:i,children:[(0,X.jsx)(An,{className:`h-8`,children:(0,X.jsx)($t,{placeholder:`—`})}),(0,X.jsx)(rr,{children:a.map(e=>(0,X.jsx)(In,{value:e.value,children:e.label},e.value))})]})}):(0,X.jsx)(R,{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,X.jsx)(W,{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,X.jsx)(Qe,{className:`h-4 w-4`})})]},t)),!i&&(0,X.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...o,``]),children:[(0,X.jsx)(B,{className:`mr-1 h-3.5 w-3.5`}),` Add`]})]})}function vd(e){if(e===void 0)return``;try{return JSON.stringify(e,null,2)}catch{return``}}function yd({label:e,value:t,onCommit:n,disabled:r,placeholder:i}){let a=Z.useMemo(()=>vd(t),[t]),[o,s]=Z.useState(a),[c,l]=Z.useState(null);return Z.useEffect(()=>{s(a),l(null)},[a]),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsx)(`textarea`,{value:o,onChange:e=>s(e.target.value),onBlur:()=>{if(r)return;let e=o.trim();if(e===``){l(null),n(void 0);return}try{let t=JSON.parse(e);l(null),n(t)}catch{l(`Invalid JSON`)}},disabled:r,placeholder:i,spellCheck:!1,rows:Math.min(12,Math.max(2,o.split(`
13
+ `).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`}),c&&(0,X.jsx)(`div`,{className:`text-[11px] text-destructive`,children:c})]})}function bd({name:e,value:t,onCommit:n,disabled:r}){return typeof t==`boolean`?(0,X.jsx)(Y,{label:e,value:t,onCommit:n,disabled:r}):typeof t==`number`?(0,X.jsx)(Na,{label:e,value:t,onCommit:e=>n(e),disabled:r}):t===null||typeof t==`string`?(0,X.jsx)(q,{label:e,value:t??``,onCommit:n,disabled:r,mono:!0}):(0,X.jsx)(yd,{label:e,value:t,onCommit:n,disabled:r})}var xd=new Set([`children`,`body`]),Sd=Symbol(`remove`);function Cd(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 wd(e){let t=[];for(let n of e)t.push(n.key),n.index>=0&&t.push(n.index);return t}function Td(e,t){let n=e;for(let e of t){if(n==null)return null;n=n[e]}return n??null}function Ed(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===Sd?t.splice(r,1):t[r]=n:t[r]=Ed(t[r],i,n),t}let a={...e||{}};return i.length===0?n===Sd?delete a[r]:a[r]=n:a[r]=Ed(a[r],i,n),a}function Dd(e,t){return Td(e,wd(t))}function Od(e,t,n){let r=wd(t),i=Ed(e,r,n===null?Sd:n),a=r[0];return{[a]:i[a]}}function kd(e,t){let n=wd(t),r=n[n.length-1];if(typeof r!=`number`)return null;let i=Td(e,n.slice(0,-1));return Array.isArray(i)?{siblings:i,index:r}:null}function Ad(e,t,n){let r=wd(t),i=Ed(e,r.slice(0,-1),n),a=r[0];return{[a]:i[a]}}function jd({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:Cd(e.id),l=s?s[1]:``,u=s?Number(s[2]):-1,d=s?s[3]:void 0,f=d?Cd(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?Dd(h||{},f):h:c?Dd(t,c):null,y=s?f?kd(h||{},f):{siblings:m,index:u}:c?kd(t,c):null;if(!s&&!c||!v)return(0,X.jsx)(ca,{kindLabel:K(`engine.inspector.pageBlock.kind`,a),title:e.label??e.id,onClose:r,closeLabel:K(`engine.inspector.pageBlock.close`,a),children:(0,X.jsx)(ma,{message:e.id})});let b=e=>s?_(f?{...h,...Od(h||{},f,{...v,...e})}:{...v,...e}):n(Od(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((fd(v.type)?dd[v.type]:[]).map(e=>e.name)),D=Object.keys(x).filter(e=>!E.has(e)&&!xd.has(e)),O=(e,t,n,r=``)=>{let i=`${r}${e.name}`;switch(e.kind){case`number`:return(0,X.jsx)(Na,{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,X.jsx)(Y,{label:e.label,value:!!t(e.name),onCommit:t=>n(e.name,t),disabled:o},i);case`color`:return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e.label}),(0,X.jsx)(Ma,{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,X.jsx)(J,{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`json`:return(0,X.jsx)(yd,{label:e.label,value:t(e.name),placeholder:e.placeholder,onCommit:t=>n(e.name,t),disabled:o},i);case`string-list`:{let r=Array.isArray(t(e.name))?t(e.name):[];return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,i)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(R,{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,X.jsx)(W,{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,X.jsx)(Qe,{className:`h-4 w-4`})})]},i)),!o&&(0,X.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,``]),children:[(0,X.jsx)(B,{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,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e.label}),r.map((t,a)=>{let s=t&&typeof t==`object`?t:{};return(0,X.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border p-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[`#`,a+1]}),(0,X.jsx)(W,{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,X.jsx)(gn,{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,X.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,{}]),children:[(0,X.jsx)(B,{className:`mr-1 h-3.5 w-3.5`}),` `,e.addLabel||`Add`]})]},i)}case`object-picker`:return(0,X.jsx)(hd,{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,X.jsx)(gd,{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,X.jsx)(_d,{label:e.label,objectName:C(e),value:t(e.name),onChange:t=>n(e.name,t),disabled:o},i);default:return(0,X.jsx)(q,{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,...Od(h||{},f,null)}:null):n(Od(t,c,null)),r()},A=e=>e.map(e=>e.index>=0?`${e.key}[${e.index}]`:e.key).join(`.`);return(0,X.jsxs)(ca,{kindLabel:K(`engine.inspector.pageBlock.kind`,a),title:String(v.id||v.type||e.id),onClose:r,closeLabel:K(`engine.inspector.pageBlock.close`,a),headerActions:y?(0,X.jsx)(Yi,{index:y.index,total:y.siblings.length,onMove:e=>{if(!y)return;if(s){if(f){let t=ia(y.siblings,y.index,e);_({...h,...Ad(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(ia(m,u,e)),i?.({kind:`block`,id:`slot:${l}:${e}`,label:String(v.id||v.type||e)});return}let r=ia(y.siblings,y.index,e);n(Ad(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:K(`engine.inspector.reorder.up`,a),downLabel:K(`engine.inspector.reorder.down`,a),disabled:o}):void 0,footer:(0,X.jsx)(sa,{label:K(`engine.inspector.pageBlock.remove`,a),onClick:k,disabled:o}),children:[(0,X.jsx)(q,{label:K(`engine.inspector.pageBlock.type`,a),value:v.type??``,onCommit:e=>b({type:e}),disabled:o,mono:!0}),(0,X.jsx)(q,{label:K(`engine.inspector.pageBlock.id`,a),value:v.id??``,onCommit:e=>b({id:e}),disabled:o,mono:!0}),(0,X.jsx)(q,{label:K(`engine.inspector.pageBlock.className`,a),value:v.className??``,onCommit:e=>b({className:e}),disabled:o,mono:!0}),(0,X.jsx)(wa,{label:K(`engine.inspector.pageBlock.hidden`,a),value:v.hidden??``,onCommit:e=>b({hidden:e||void 0}),objectName:S,disabled:o}),fd(v.type)&&(0,X.jsxs)(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:K(`engine.inspector.pageBlock.properties`,a)}),dd[v.type].map(e=>O(e,w,T))]}),D.length>0&&(0,X.jsxs)(`div`,{className:`space-y-3 border-t border-border pt-3`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:K(`engine.inspector.pageBlock.advanced`,a)}),D.map(e=>(0,X.jsx)(bd,{name:e,value:x[e],onCommit:t=>T(e,t),disabled:o},e))]})]})}var Md=new Set([`simple`,`tabbed`,`wizard`,`split`]),Nd=new Set([`drawer`,`modal`]);function Pd(e){return typeof e==`string`&&Nd.has(e)}function Fd(e){return typeof e==`string`&&Md.has(e)?e:`simple`}function Id(e){let t={...e,type:String(e?.type??``)},n=t.properties&&typeof t.properties==`object`?t.properties:void 0;return Pd(n?.formType??t.formType)&&(n&&(t.properties={...n,formType:`simple`}),`formType`in t&&(t.formType=`simple`)),t}function Ld(e=`300px`){let t=Z.useRef(null),[n,r]=Z.useState(()=>typeof IntersectionObserver>`u`);return Z.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 Rd({block:e,maxHeightClass:t=`max-h-72`}){let n=String(e?.type??``),{ref:r,inView:i}=Ld();return(0,X.jsx)(`div`,{ref:r,className:H(`pointer-events-none select-none overflow-hidden p-3`,t),children:i?(0,X.jsx)(ed,{fallbackHint:`"${n}" can't render with its current configuration — check its Properties.`,children:(0,X.jsx)(O,{children:(0,X.jsx)(ee,{schema:Id(e)})})}):(0,X.jsx)(`div`,{className:`min-h-[64px] animate-pulse rounded bg-muted/40`,"aria-hidden":`true`})})}var zd={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 Bd(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 Vd=[`header`,`actions`,`alerts`,`highlights`,`details`,`tabs`,`discussion`];function Hd(e){let t=e||{};return Vd.map(e=>{let n=t[e];return{name:e,components:Array.isArray(n)?n:n==null?[]:[n]}})}function Ud(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 Wd(e){let t=e.slots;if(e.kind===`slotted`&&t&&typeof t==`object`&&!Array.isArray(t))return{regions:Hd(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 Gd(e,t,n,r){return e===`children`?`children[${n}]`:e===`slots`?`slot:${r}:${n}`:`regions[${t}].components[${n}]`}function Kd(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 qd=`text/x-objectui-pageblock`;function Jd({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=Z.useMemo(()=>Wd(e),[e]),s=n?.kind===`block`?String(n.id):null,c=Z.useCallback(e=>{if(o===`children`){let n=e.flatMap(e=>Array.isArray(e.components)?e.components:[]);t?.({children:n})}else o===`slots`?t?.({slots:Ud(e)}):t?.({regions:e})},[t,o]),l=Z.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=Gd(o,n.region,d,i[n.region]?.name);r?.({kind:`block`,id:f,label:Kd(l)})},[t,r,a,c,o]),u=Z.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:Gd(o,e,l,i[e]?.name),label:Kd(s)})},[t,r,a,c,o]),d=Z.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=Z.useCallback(()=>{if(!t)return;let e=[...a,{name:`region_${a.length+1}`,components:[]}];c(e)},[t,a,c]),p=Z.useCallback((n,i,a)=>{if(!t)return;let o=/^slot:([a-zA-Z_]+):(\d+)$/.exec(n),s=Cd(i);if(!s)return;let c=wd(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=Td(p,c)||[];f[l]=Ed(p,c,[...m,{type:a}]),t({slots:{...u,[s]:f}}),r?.({kind:`block`,id:`${n}.${i}[${m.length}]`,label:a})}else{let o=Cd(`${n}.${i}`);if(!o)return;let s=wd(o),c=Td(e,s)||[],l=Ed(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=Z.useCallback(e=>{e.target===e.currentTarget&&s&&r?.(null)},[r,s]);return a.length===0?(0,X.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,X.jsx)(`div`,{className:`mx-auto max-w-3xl px-6 py-8`,children:(0,X.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,children:`No regions yet`}),(0,X.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,X.jsx)(`div`,{className:`pt-2`,children:(0,X.jsxs)(W,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,onClick:f,children:[(0,X.jsx)(B,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}):(0,X.jsx)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:m,children:(0,X.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-5`,onClick:m,children:[a.map((e,t)=>(0,X.jsx)(Yd,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(n,i)=>r?.({kind:`block`,id:Gd(o,t,n,e.name),label:Kd(i)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d,baseIdOf:n=>Gd(o,t,n,e.name),onSelectId:(e,t)=>r?.({kind:`block`,id:e,label:t}),onAddNested:p},t)),!i&&o===`regions`&&(0,X.jsx)(`div`,{className:`pt-1`,children:(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground`,onClick:f,children:[(0,X.jsx)(B,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function Yd({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]=Z.useState(!1);return(0,X.jsxs)(`section`,{className:H(`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(qd)||(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(qd);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,X.jsxs)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-muted-foreground pl-1 mb-2 flex items-center gap-2`,children:[(0,X.jsx)(`span`,{children:e.name||`region ${t+1}`}),e.width&&(0,X.jsxs)(`span`,{className:`normal-case text-[10px] text-muted-foreground/60`,children:[`· `,e.width]}),f&&(0,X.jsx)(`span`,{className:`text-primary normal-case text-[10px]`,children:`drop here`})]}),(0,X.jsxs)(`div`,{className:`space-y-2.5`,children:[d.length===0?(0,X.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=Gd(n,t,d,e.name);return(0,X.jsxs)(Z.Fragment,{children:[(0,X.jsx)(Xd,{block:s,regionIdx:t,compIdx:d,selected:f===r,readOnly:i,onClick:()=>a(d,s),onMoveBlock:o,onRenameLabel:e=>c(t,d,e)}),(0,X.jsx)(Zd,{block:s,baseId:f,selectedId:r,readOnly:i,onSelectId:l,onAddNested:u})]},`${t}:${d}`)}),!i&&(0,X.jsx)(`div`,{className:`pt-1`,children:(0,X.jsx)(Qd,{onPick:e=>s(t,e)})})]})]})}function Xd({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=ad[c]?.Icon??cd,u=ud(c),d=Kd(e),f=!i,[p,m]=Z.useState(null),h=e=>{e.dataTransfer.setData(qd,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(qd))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(qd);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]=Z.useState(!1),[x,S]=Z.useState(d);Z.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=Bd(e).length>0;return(0,X.jsxs)(`div`,{className:H(`relative`,p===`before`&&`pt-1.5`),onDragOver:g,onDragLeave:_,onDrop:v,children:[p===`before`&&(0,X.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,X.jsx)(`div`,{className:H(`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,X.jsxs)(`button`,{type:`button`,onClick:a,draggable:f,onDragStart:h,className:H(`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,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0 flex-1`,children:[f&&(0,X.jsx)(nt,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),(0,X.jsx)(l,{className:H(`h-3.5 w-3.5 shrink-0`,u.icon)}),y?(0,X.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,X.jsx)(`span`,{className:H(`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,X.jsxs)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:[`#`,e.id]})]}),(0,X.jsx)(L,{variant:`outline`,className:H(`text-[10px] shrink-0 font-mono`,u.badge),children:c})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Rd,{block:e}),(0,X.jsx)(`button`,{type:`button`,onClick:a,draggable:f,onDragStart:h,"aria-label":`Select ${d}`,"aria-pressed":r,className:H(`absolute inset-0 z-10 rounded-md`,i&&`cursor-default`,f&&`cursor-grab active:cursor-grabbing`)}),(0,X.jsxs)(`div`,{className:H(`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,X.jsx)(nt,{className:`h-3.5 w-3.5 text-muted-foreground/60`,"aria-hidden":`true`}),(0,X.jsx)(L,{variant:`outline`,className:H(`text-[10px] font-mono shadow-sm bg-background/90 backdrop-blur`,u.badge),children:c})]})]})}),p===`after`&&(0,X.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function Zd({block:e,baseId:t,selectedId:n,readOnly:r,onSelectId:i,onAddNested:a}){let o=Bd(e);if(o.length===0)return null;let s=zd[e?.type===`grid`?Math.min(6,Math.max(1,Number(e.properties?.columns)||1)):1]??`grid-cols-1`;return(0,X.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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-medium uppercase tracking-wider text-muted-foreground/70`,children:e.label}),e.children.length===0?(0,X.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,X.jsx)(`div`,{className:H(`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,X.jsxs)(`div`,{className:H(`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,X.jsx)(Rd,{block:r,maxHeightClass:`max-h-56`}),(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i(o,Kd(r))},"aria-label":`Select ${Kd(r)}`,"aria-pressed":c,className:`absolute inset-0 z-10 rounded-md cursor-pointer`}),(0,X.jsx)(`div`,{className:H(`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,X.jsx)(L,{variant:`outline`,className:H(`text-[10px] font-mono shadow-sm bg-background/90 backdrop-blur`,ud(s).badge),children:s})})]},a)})}),!r&&(0,X.jsx)(Qd,{onPick:n=>a(t,e.pathSuffix,n)})]},o))})}function Qd({onPick:e}){let[t,n]=Z.useState(!1),[r,i]=Z.useState(``),a=r.trim().toLowerCase(),o=Z.useMemo(()=>a?sd.map(e=>({category:e.category,types:e.types.filter(e=>{let t=ad[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):sd,[a]);return(0,X.jsxs)(kt,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsxs)(W,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,X.jsx)(B,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,X.jsxs)(he,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,X.jsx)(`div`,{className:`p-2 border-b`,children:(0,X.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,X.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:o.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:`No matching types.`}):o.map(t=>(0,X.jsxs)(`div`,{className:`mb-1`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 py-1`,children:od[t.category]}),t.types.map(t=>{let r=ad[t],a=r.Icon;return(0,X.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,X.jsx)(a,{className:H(`h-3.5 w-3.5 shrink-0`,ud(t).icon)}),(0,X.jsx)(`span`,{className:`truncate`,children:r.label}),(0,X.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground/70 font-mono truncate`,children:t})]},t)})]},t.category))})]})]})}function $d({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=Z.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=Z.useMemo(()=>Array.isArray(e.regions)?`regions`:`children`,[e]),f=Z.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=Z.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,[h,g]=Z.useState([]),[_,v]=Z.useState(null),[y,b]=Z.useState(null);Z.useEffect(()=>{if(!m){g([]),v(null),b(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=D(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;g(s),v(r),b(e=>e??s[0]?.id??s[0]?._id??s[0]?.name??null)}catch{e||(g([]),v(null))}})(),()=>{e=!0}},[m]);let x=e=>e?.id??e?._id??e?.name,S=e=>String(e?.name??e?.title??e?.label??e?.subject??x(e)??`(record)`),C=Z.useMemo(()=>h.length?h.find(e=>String(x(e))===String(y))??h[0]:null,[h,y]),w=e?.kind===`slotted`,T=Z.useMemo(()=>{if(!w)return o;try{let t=e?.slots??{};return Fa(_??void 0,{slots:t})}catch{return o}},[w,o,e,_]),O=e=>!m||!C?e:(0,X.jsxs)(E,{objectName:m,recordId:x(C),data:C,objectSchema:_??void 0,embedded:!0,children:[h.length>0&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-1.5 border-b bg-muted/30 text-xs`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground shrink-0`,children:`Preview record`}),(0,X.jsx)(`select`,{className:`h-7 rounded-md border bg-background px-2 text-xs max-w-[260px]`,value:String(y??``),onChange:e=>b(e.target.value),children:h.map(e=>{let t=x(e);return(0,X.jsx)(`option`,{value:String(t),children:S(e)},String(t))})}),(0,X.jsxs)(`span`,{className:`text-muted-foreground/70 shrink-0`,children:[h.length,` sample`,h.length===1?``:`s`]})]}),e]});if(u)return(0,X.jsx)(Q,{hint:`page · interface`,children:(0,X.jsx)(ed,{fallbackHint:`The interface page references a source object/view that isn't available.`,children:(0,X.jsx)(Oi,{page:e,onConfigChange:c?t=>i({interfaceConfig:{...e.interfaceConfig||{},...t}}):void 0})})});let k=e.kind;return k===`react`||k===`html`?(0,X.jsx)(id,{draft:e,onPatch:c?i:void 0,readOnly:!c}):!o||Object.keys(o).length<=1?(0,X.jsxs)(Q,{hint:`page${s?` · design`:``}`,children:[s&&d===`regions`?(0,X.jsx)(Jd,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,X.jsx)(td,{title:K(`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:K(`engine.inspector.add.block`,a)}):null,!s&&(0,X.jsx)(Qu,{children:`Add components to the page to see a preview.`})]}):s&&d===`regions`?(0,X.jsx)(Q,{hint:`page · design`,children:O((0,X.jsx)(Jd,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}))}):(0,X.jsx)(Q,{hint:`page${s?` · design`:``}`,children:(0,X.jsxs)(ed,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,X.jsx)(td,{title:K(`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:K(`engine.inspector.add.block`,a)}),O((0,X.jsx)(`div`,{className:`min-h-[200px] max-h-[70vh] overflow-auto p-4`,children:(0,X.jsx)(ee,{schema:T})}))]})})}function ef(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 tf(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 nf(e,t){return{type:`object-form`,objectName:e,mode:`create`,formType:Fd(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(tf):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function rf({name:e,draft:t,editing:n}){let r=Z.useMemo(()=>vs(t)?.schema,[t]),i=Z.useMemo(()=>ef(t,r),[t,r]),a=!!n,{listViews:o,defaultViewId:s,defaultViewType:c}=Z.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]),l=Z.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]);if(!r&&t.type){let e={...t};return(0,X.jsx)(Q,{hint:`view · ${e.type}${a?` · design`:``}`,children:(0,X.jsx)(ed,{fallbackHint:"The view's `type` may not be registered, or required fields are missing.",children:(0,X.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,X.jsx)(O,{children:(0,X.jsx)(ee,{schema:e})})})})})}if(!i)return(0,X.jsx)(Q,{hint:`view${a?` · design`:``}`,children:(0,X.jsxs)(Qu,{tone:`warn`,children:[`This view has no object binding yet. Set the bound `,(0,X.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=nf(i,r);return(0,X.jsx)(Q,{hint:`view · ${e} · form${a?` · design`:``}`,children:(0,X.jsx)(ed,{fallbackHint:`The form view references an object or field that doesn't resolve.`,children:(0,X.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,X.jsx)(O,{children:(0,X.jsx)(ee,{schema:t})})})})})}return(0,X.jsx)(Q,{hint:`view · ${c}${a?` · design`:``}`,children:(0,X.jsx)(ed,{fallbackHint:`The view references an object or field that doesn't resolve.`,children:(0,X.jsx)(`div`,{className:`min-h-[300px] max-h-[75vh] overflow-auto`,children:(0,X.jsx)(O,{children:(0,X.jsx)(ee,{schema:l})})})})})}var af={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:st},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:vr},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:Tn},line:{id:`line`,label:`Line chart`,category:`chart`,icon:tr},area:{id:`area`,label:`Area chart`,category:`chart`,icon:kn},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:hn},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:cn},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:Zn},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:Vr},table:{id:`table`,label:`Data table`,category:`data`,icon:Ot},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:ge}},of={kpi:`Single value`,chart:`Charts`,data:`Tabular`},sf=[`kpi`,`chart`,`data`].map(e=>({category:e,types:Object.values(af).filter(t=>t.category===e)})),cf=Ye;function lf({onAdd:e,label:t=`Add widget`}){let[n,r]=Z.useState(!1),[i,a]=Z.useState(``),o=Z.useRef(null),s=Z.useMemo(()=>{let e=i.trim().toLowerCase();return e?sf.map(t=>({category:t.category,types:t.types.filter(t=>t.id.toLowerCase().includes(e)||t.label.toLowerCase().includes(e))})).filter(e=>e.types.length):sf},[i]);return(0,X.jsxs)(kt,{open:n,onOpenChange:e=>{r(e),e||a(``)},children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded border border-dashed px-3 py-1.5 text-xs text-muted-foreground hover:bg-muted/30 hover:text-foreground`,children:[(0,X.jsx)(B,{className:`h-3 w-3`}),t]})}),(0,X.jsxs)(he,{align:`end`,sideOffset:4,className:`w-72 p-0`,onOpenAutoFocus:e=>{e.preventDefault(),o.current?.focus()},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-2 py-1.5`,children:[(0,X.jsx)(We,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`input`,{ref:o,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Search widgets…`,className:`w-full bg-transparent text-xs outline-none placeholder:text-muted-foreground`})]}),(0,X.jsx)(`div`,{className:`max-h-72 overflow-auto py-1`,children:s.length===0?(0,X.jsx)(`div`,{className:`px-3 py-4 text-center text-xs text-muted-foreground`,children:`No matches.`}):s.map(t=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`px-3 pt-2 pb-1 text-[10px] uppercase tracking-wider text-muted-foreground`,children:of[t.category]}),t.types.map(t=>(0,X.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs hover:bg-accent`,onClick:()=>{e(t.id),r(!1)},children:[(0,X.jsx)(af[t.id]?.icon??cf,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:t.label}),(0,X.jsx)(`code`,{className:`ml-auto text-[10px] text-muted-foreground`,children:t.id})]},t.id))]},t.category))})]})]})}var uf=Z.lazy(()=>a(()=>import(`./plugin-dashboard-QnlQx94Y.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function df({draft:e,editing:t,onPatch:n,selection:r,onSelectionChange:i,locale:a}){let o=k(),s=Array.isArray(e.widgets)?e.widgets:[],c=!!(t&&i),l=c&&!!n,u=r&&r.kind===`widget`?r.id:null,d=Z.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=Z.useCallback(e=>{n&&n({widgets:e})},[n]),p=Z.useCallback(e=>{if(!l)return;let t=qi(`widget`,s.map(e=>e?.id).filter(Boolean)),r=af[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`,o={id:t,type:e,title:a,...r?.defaults??{}};n({widgets:Xi(s,o)}),i?.({kind:`widget`,id:t,label:a})},[l,s,n,i]),m=Z.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]),h=u?s.find(e=>e?.id===u)??null:null,g=l?(0,X.jsx)(lf,{onAdd:p,label:K(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,X.jsx)(Q,{hint:`dashboard${c?` · design`:``}`,toolbar:g,children:(0,X.jsx)(Qu,{children:`Add at least one widget to see a preview.`})}):(0,X.jsx)(Q,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:g,children:(0,X.jsxs)(ed,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:[l&&h?(0,X.jsx)(ff,{widget:h,onRename:e=>m(h.id,e),onClose:()=>i?.(null)}):null,(0,X.jsx)(Z.Suspense,{fallback:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Loading dashboard renderer…`]}),children:(0,X.jsx)(`div`,{className:`p-3 max-h-[70vh] overflow-auto`,children:(0,X.jsx)(`div`,{className:`min-w-[768px]`,children:(0,X.jsx)(uf,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})})]})})}function ff({widget:e,onRename:t,onClose:n}){let r=e.title??e.id??``,[i,a]=Z.useState(!1),[o,s]=Z.useState(r),c=Z.useRef(null);Z.useEffect(()=>{s(r),a(!1)},[e.id,r]),Z.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=af[e.type]?.icon??null;return(0,X.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,X.jsx)(d,{className:`h-3.5 w-3.5 text-primary`}):null,(0,X.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,X.jsxs)(X.Fragment,{children:[(0,X.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,X.jsx)(`button`,{type:`button`,onClick:l,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Save title`,children:(0,X.jsx)(Nr,{className:`h-3.5 w-3.5`})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.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,X.jsx)(`span`,{className:`italic text-muted-foreground`,children:`untitled`})}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>a(!0),className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Rename widget`,children:(0,X.jsx)(pe,{className:`h-3.5 w-3.5`})})]}),(0,X.jsx)(`button`,{type:`button`,onClick:n,className:`rounded p-1 hover:bg-primary/10`,"aria-label":`Clear selection`,children:(0,X.jsx)(Qe,{className:`h-3.5 w-3.5`})})]})}var pf=Z.lazy(()=>a(()=>import(`./plugin-report-4ufmhN37.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function mf({draft:e}){let t=k(),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,X.jsx)(Q,{hint:i?`report · joined · ${n.blocks.length} block${n.blocks.length===1?``:`s`}`:`report · dataset "${n.dataset}"${r.length?` · by `+r.join(`, `):``}`,children:(0,X.jsx)(ed,{fallbackHint:`The Report references a dataset/measure that doesn't resolve, or its config is incomplete.`,children:(0,X.jsx)(Z.Suspense,{fallback:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Loading report renderer…`]}),children:(0,X.jsx)(`div`,{className:`p-3 min-h-[200px] max-h-[70vh] overflow-auto`,children:(0,X.jsx)(pf,{schema:e,dataSource:t})})})})})}let a=n.type===`joined`;return(0,X.jsx)(Q,{children:(0,X.jsx)($u,{icon:(0,X.jsx)(ge,{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 hf=`text/x-objectui-nav`;function gf(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 _f(e){switch(e){case`object`:return ge;case`page`:return dr;case`dashboard`:return Kr;case`report`:return Pn;case`link`:return ir;case`group`:return Ze;default:return be}}var vf={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 yf(e){return vf[e]??vf.item}function bf(e,t){let n=e.label??e.title??e.name??e.path;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function xf(e){let t=e.path??e.href??e.route??e.url;return typeof t==`string`&&t?t:void 0}function Sf({draft:e,rootKey:t,onPatch:n,selection:r,onSelectionChange:i}){let a=Ni(),o=Z.useMemo(()=>{let n=e[t];return Array.isArray(n)?n:[]},[e,t]),s=r&&r.kind===`nav`?r.id:null,[c,l]=Z.useState(null),u=Z.useCallback(e=>{n&&n({[t]:e})},[n,t]),d=Z.useCallback(()=>{if(!n)return;let e=K(`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=Xi(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=Z.useCallback(e=>{if(!n)return;let r=Sa(o,e,null);u(r),s===`${t}[${e}]`&&i?.(null)},[n,o,u,t,s,i]),p=Z.useCallback((e,r)=>{if(!n)return;let a={...o[e]??{},label:r},c=Sa(o,e,a);u(c),s===`${t}[${e}]`&&i?.({kind:`nav`,id:`${t}[${e}]`,label:r})},[n,o,u,t,s,i]),m=Z.useCallback((e,r)=>{if(!n)return;let a=r;if(e<r&&(a=r-1),a===e)return;let s=ia(o,e,a);u(s),i?.({kind:`nav`,id:`${t}[${a}]`,label:bf(s[a]??{},a)})},[n,o,u,t,i]);return(0,X.jsxs)(`div`,{className:`rounded-md border bg-card/40`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,X.jsx)(`span`,{className:`font-medium uppercase tracking-wide text-muted-foreground`,children:K(`engine.appNav.heading`,a)}),(0,X.jsxs)(L,{variant:`outline`,className:`text-[10px]`,children:[o.length,` `,o.length===1?K(`engine.appNav.itemOne`,a):K(`engine.appNav.itemOther`,a)]})]}),n&&(0,X.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,X.jsx)(B,{className:`h-3 w-3`}),` `,K(`engine.appNav.addItem`,a)]})]}),(0,X.jsx)(`div`,{className:`space-y-1.5 p-2`,onDragOver:e=>{n&&e.dataTransfer.types.includes(hf)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(hf)&&(e.preventDefault(),c!=null&&(m(c,o.length),l(null)))},children:o.length===0?(0,X.jsx)(`div`,{className:`rounded border border-dashed px-3 py-4 text-center text-[11px] text-muted-foreground`,children:K(n?`engine.appNav.empty`:`engine.appNav.emptyReadonly`,a)}):o.map((e,r)=>(0,X.jsx)(Cf,{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 Cf({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,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(wf,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,bf(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,X.jsx)(Cf,{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 wf({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=Ni(),p=gf(e),m=_f(p),h=yf(p),g=xf(e),[_,v]=Z.useState(!1),[y,b]=Z.useState(bf(e,t)),[x,S]=Z.useState(!1),[C,w]=Z.useState(null);return Z.useEffect(()=>{_||b(bf(e,t))},[e,t,_]),(0,X.jsxs)(`div`,{className:`relative`,style:{paddingLeft:n*16},children:[C===`before`&&(0,X.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 -top-0.5 h-0.5 rounded bg-primary`}),(0,X.jsxs)(`button`,{type:`button`,draggable:a&&!_,onDragStart:e=>{a&&(e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(hf,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(hf)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,w(`before`))},onDragLeave:()=>w(null),onDrop:e=>{a&&e.dataTransfer.types.includes(hf)&&(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,X.jsx)(nt,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50 group-hover:text-muted-foreground`}):(0,X.jsx)(`span`,{className:`w-3.5`}),(0,X.jsx)(m,{className:H(`h-3.5 w-3.5 shrink-0`,h.icon)}),_?(0,X.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!==bf(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),b(bf(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,X.jsx)(`span`,{className:`flex-1 min-w-0 truncate font-medium`,onDoubleClick:e=>{a&&(e.stopPropagation(),v(!0))},children:bf(e,t)}),(0,X.jsx)(L,{variant:`outline`,className:H(`text-[10px] font-medium`,h.badge),children:p}),g&&(0,X.jsx)(`code`,{className:`ml-0 text-[10px] text-muted-foreground truncate max-w-[10rem]`,children:g}),a&&x&&!_&&(0,X.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":K(`engine.appNav.removeItem`,f),children:(0,X.jsx)(gn,{className:`h-3 w-3`})})]})]})}function Tf(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)?Tf(e.children):void 0;return{label:t||`(unnamed)`,path:n,kind:r,children:i}}).filter(e=>e!==null):[]}function Ef(e){switch(e){case`object`:return ge;case`page`:return dr;case`dashboard`:return Kr;case`report`:return Pn;default:return be}}function Df({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}=Z.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:Tf(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,X.jsx)(Q,{hint:`app`,toolbar:g&&(0,X.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,X.jsx)(Rn,{className:`h-3 w-3`})]}),children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-foreground`,children:String(s)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:o}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Landing: `,(0,X.jsx)(`code`,{className:`font-mono`,children:String(c)})]})]}),f?(0,X.jsx)(Sf,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):u.length===0?(0,X.jsxs)(Qu,{children:[`No top-level nav items. Add `,(0,X.jsx)(`code`,{children:`nav`}),` / `,(0,X.jsx)(`code`,{children:`tabs`}),` entries in the Form tab to populate the app's navigation.`]}):(0,X.jsx)(`div`,{className:`border rounded divide-y`,children:u.map((e,t)=>(0,X.jsx)(Of,{item:e,appName:o,depth:0,path:`${l}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function Of({item:e,appName:t,depth:n,path:r,onSelect:i,selectedId:a}){let o=Ef(e.kind),s=kf(t,e.path);return(0,X.jsxs)(X.Fragment,{children:[(0,X.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,X.jsx)(o,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:e.label}),e.kind&&(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider opacity-60`,children:e.kind}),s&&(0,X.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,X.jsx)(Rn,{className:`h-3 w-3`})]})]}),e.children?.map((e,o)=>(0,X.jsx)(Of,{item:e,appName:t,depth:n+1,path:`${r}.children[${o}]`,onSelect:i,selectedId:a},o))]})}function kf(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 Af(e){let{type:t,locale:n}=e;switch(t){case`text`:case`password`:return(0,X.jsx)(jf,{...e,icon:t===`password`?(0,X.jsx)(hr,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,X.jsx)(jf,{...e,icon:(0,X.jsx)(ht,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,X.jsx)(jf,{...e,icon:(0,X.jsx)(li,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,X.jsx)(jf,{...e,icon:(0,X.jsx)(Qr,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,X.jsx)(jf,{...e,icon:(0,X.jsx)(st,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,X.jsx)(jf,{...e,icon:(0,X.jsx)(Qt,{className:`h-3.5 w-3.5`}),placeholder:K(`designer.stub.pickDate`,n)});case`time`:return(0,X.jsx)(jf,{...e,icon:(0,X.jsx)(vt,{className:`h-3.5 w-3.5`}),placeholder:`hh:mm`});case`textarea`:case`markdown`:case`html`:case`richtext`:case`json`:case`code`:return(0,X.jsx)(Mf,{...e,mono:t===`json`||t===`code`});case`boolean`:case`toggle`:return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,X.jsx)(di,{disabled:!0}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??K(`designer.stub.off`,n)})]});case`select`:case`radio`:return(0,X.jsx)(Nf,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,X.jsx)(Nf,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,X.jsx)(Pf,{...e});case`image`:case`avatar`:return(0,X.jsx)(Ff,{icon:(0,X.jsx)(Jn,{className:`h-4 w-4`}),label:K(t===`avatar`?`designer.stub.uploadAvatar`:`designer.stub.uploadImage`,n)});case`file`:case`video`:case`audio`:case`signature`:return(0,X.jsx)(Ff,{icon:(0,X.jsx)(jt,{className:`h-4 w-4`}),label:G(`designer.stub.upload`,n,{type:t})});case`qrcode`:return(0,X.jsx)(Ff,{icon:(0,X.jsx)(jt,{className:`h-4 w-4`}),label:K(`designer.stub.qrcode`,n)});case`color`:return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,X.jsx)(`span`,{className:`inline-block h-6 w-6 rounded border`,style:{background:`#3b82f6`}}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`#3b82f6`}),(0,X.jsx)(Ee,{className:`h-3.5 w-3.5 text-muted-foreground`})]});case`rating`:return(0,X.jsx)(`div`,{className:`flex items-center gap-0.5 h-8`,children:[0,1,2,3,4].map(e=>(0,X.jsx)(ve,{className:`h-4 w-4 `+(e<3?`fill-amber-400 text-amber-400`:`text-muted-foreground/40`)},e))});case`slider`:return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1 h-1.5 rounded bg-muted`,children:[(0,X.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-2/5 rounded bg-primary`}),(0,X.jsx)(`div`,{className:`absolute h-3 w-3 -top-[3px] left-[40%] rounded-full border-2 border-primary bg-background`})]}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`40`})]});case`progress`:return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 h-8`,children:[(0,X.jsx)(`div`,{className:`relative flex-1 h-2 rounded bg-muted`,children:(0,X.jsx)(`div`,{className:`absolute inset-y-0 left-0 w-3/5 rounded bg-emerald-500`})}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground tabular-nums`,children:`60%`})]});case`location`:return(0,X.jsx)(jf,{...e,icon:(0,X.jsx)(lr,{className:`h-3.5 w-3.5`}),placeholder:K(`designer.stub.latLng`,n)});case`address`:return(0,X.jsx)(Mf,{...e,placeholder:e.placeholder??`Street
14
+ City, State ZIP
15
+ Country`});case`formula`:case`summary`:return(0,X.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}`:`ƒ ${K(`designer.stub.computed`,n)}`});case`composite`:return(0,X.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:K(`designer.stub.composite`,n)});case`repeater`:return(0,X.jsx)(`div`,{className:`p-2 border-dashed border-2 rounded text-[11px] text-muted-foreground italic`,children:K(`designer.stub.repeater`,n)});case`vector`:return(0,X.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,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(R,{disabled:!0,placeholder:e.placeholder??`(${t})`,className:`h-8 text-sm`}),(0,X.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:t})]})}}function jf({placeholder:e,icon:t}){return(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(R,{disabled:!0,placeholder:e??``,className:`h-8 text-sm `+(t?`pl-8`:``)}),t&&(0,X.jsx)(`div`,{className:`absolute left-2 top-1/2 -translate-y-1/2 text-muted-foreground`,children:t})]})}function Mf({placeholder:e,mono:t}){return(0,X.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 Nf({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,X.jsxs)(`div`,{className:`h-8 px-2 flex items-center justify-between text-sm border rounded bg-background text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`truncate`,children:a[0]?.label||a[0]?.value||t||K(`designer.stub.select`,r)}),(0,X.jsx)(pr,{className:`h-3.5 w-3.5 shrink-0`})]}):(0,X.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,X.jsx)(`span`,{className:`text-xs text-muted-foreground px-1`,children:t||K(`designer.stub.pickMulti`,r)}):a.map((e,t)=>(0,X.jsx)(L,{variant:`secondary`,className:`text-[10px]`,children:e.label||e.value},t)),i.length>a.length&&(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,children:[`+`,i.length-a.length]})]})}function Pf({referenceTo:e,placeholder:t,locale:n}){let r=e?Ca.lookup:null;return(0,X.jsxs)(`div`,{className:`h-8 px-2 flex items-center gap-2 border rounded bg-background text-sm text-muted-foreground`,children:[(0,X.jsx)(br,{className:`h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate flex-1`,children:t||(e?G(`designer.stub.searchRef`,n,{ref:e}):K(`designer.stub.chooseRelated`,n))}),e&&(0,X.jsxs)(L,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`→ `,e]}),!e&&(0,X.jsx)(We,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),r&&null]})}function Ff({icon:e,label:t}){return(0,X.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,X.jsx)(`span`,{className:`text-[11px]`,children:t})]})}var If=(e,t)=>e?K(`engine.fieldType.${e.id}`,t):void 0,Lf=(e,t)=>K(`engine.fieldCategory.${e}`,t);function Rf({objectName:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=!r,{enabled:c}=Ra(),l=Z.useMemo(()=>Pa(t.fields),[t]),u=Z.useMemo(()=>n?aa(n.fields,t.fields):null,[n,t]),d=u?u.counts.added+u.counts.changed+u.counts.removed:0,[f,p]=Z.useState(!1);Z.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??[]:[],_=Z.useMemo(()=>Ji(t.fieldGroups),[t]),v=_.length>0,y=Z.useMemo(()=>Zi(l,_,{includeEmptyDeclared:!s}),[l,_,s]),[b,x]=Z.useState({}),S=e=>e??`__ungrouped__`,C=Z.useCallback(e=>{let t=e??`__ungrouped__`;x(e=>({...e,[t]:!e[t]}))},[]),w=y.length>0&&y.every(e=>b[S(e.key)]),T=Z.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=Z.useCallback(e=>{a&&a({kind:`field`,id:e.name,label:typeof e.def.label==`string`?e.def.label:e.name})},[a]),[k,A]=Z.useState(()=>new Set),j=Z.useRef(null),M=Z.useMemo(()=>y.flatMap(e=>e.entries.map(e=>e.name)),[y]);Z.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 ee=Z.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=M.indexOf(j.current),t=M.indexOf(n);if(e>=0&&t>=0){let[n,r]=e<t?[e,t]:[t,e];A(new Set(M.slice(n,r+1)));return}}k.size&&A(new Set),j.current=n,O(e)},[s,M,k,O]),te=Z.useCallback(()=>A(new Set),[]),N=Z.useCallback(()=>{if(!r||k.size===0)return;let e=l.entries.filter(e=>!k.has(e.name));r({fields:ea({shape:l.shape,entries:e})}),E&&k.has(E)&&a?.(null),A(new Set)},[r,k,l,E,a]),ne=Z.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:ea({shape:l.shape,entries:t})})},[r,k,l]),P=Z.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=oa(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:ea({shape:l.shape,entries:d})}),a?.({kind:`field`,id:s,label:String(c.def.label??s)})},[r,a,l]),re=Z.useCallback(()=>{if(!r)return;let e=G(`designer.canvas.sectionN`,o,{n:_.length+1}),t=na(_,e),n=t[t.length-1];r({fieldGroups:t}),x(e=>({...e,[n.key]:!1}))},[r,_,o]),F=Z.useCallback((e,t)=>{r&&r({fieldGroups:Qi(_,e,t)})},[r,_]),ie=Z.useCallback(e=>{if(!r)return;let t=ra(l,e);r({fieldGroups:ua(_,e),fields:ea(t)})},[r,_,l]),I=Z.useCallback((e,t)=>{r&&r({fieldGroups:ta(_,e,t)})},[r,_]),ae=Z.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:ea({shape:l.shape,entries:i})})},[r,l]),oe=Z.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:ea({shape:l.shape,entries:n})})},[r,l]),se=Z.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:ea({shape:l.shape,entries:n})})},[r,l]),ce=Z.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:ea({shape:l.shape,entries:n})})},[r,l]),le=Z.useCallback(e=>{e.target===e.currentTarget&&E&&a?.(null)},[a,E]),ue=l.entries.length===0,de=v||y.length>1;return(0,X.jsxs)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:le,"data-object-name":e,children:[!s&&k.size>0&&(0,X.jsx)(Bf,{count:k.size,groups:_,onMoveToGroup:ne,onDelete:N,onClear:te,locale:o}),(0,X.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-4`,onClick:le,children:[!ue&&(0,X.jsx)(zf,{fieldCount:l.entries.length,requiredCount:D,sectionCount:_.length,allCollapsed:w,onToggleAll:de?()=>T(!w):void 0,reviewAvailable:d>0,reviewing:m,diffCounts:u?.counts,onToggleReview:()=>p(e=>!e),locale:o}),ue?(0,X.jsx)(Gf,{onAdd:s?void 0:P,locale:o,aiEnabled:c}):(0,X.jsx)(`div`,{className:`space-y-5`,children:y.map(e=>{let t=e.key?_.findIndex(t=>t.key===e.key):-1;return(0,X.jsxs)(Vf,{groupKey:e.key,label:e.key===null?K(`designer.canvas.ungrouped`,o):e.label,count:e.entries.length,showHeader:de,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=>F(e.key,t):void 0,onRemove:e.key?()=>ie(e.key):void 0,onMove:e.key?t=>I(e.key,t):void 0,onAddField:s?void 0:t=>P(t,e.key),onDropField:s?void 0:se,children:[e.entries.map(e=>(0,X.jsx)(Wf,{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=>ee(e,t),onReorder:s?void 0:ae,onRenameLabel:s?void 0:ce,onMoveOffset:s?void 0:t=>oe(e.name,t)},e.name)),e.entries.length===0&&(0,X.jsx)(`div`,{className:`rounded-md border border-dashed bg-background/40 px-3 py-4 text-center text-[11px] text-muted-foreground`,children:K(s?`designer.canvas.emptySection`:`designer.canvas.dropHint`,o)})]},e.key??`__ungrouped__`)})}),m&&u&&u.removed.length>0&&(0,X.jsxs)(`div`,{className:`space-y-2.5`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wider text-destructive/80 pl-1`,children:K(`designer.canvas.diffRemoved`,o)}),u.removed.map(e=>(0,X.jsx)(Uf,{entry:e,locale:o},e.name))]}),!ue&&!s&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,X.jsx)(Kf,{onPick:e=>P(e),locale:o}),(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground hover:text-foreground`,onClick:re,children:[(0,X.jsx)(Ge,{className:`h-3.5 w-3.5`}),K(`designer.canvas.addSection`,o)]}),c&&(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,className:`gap-1.5 ml-auto text-primary/80 hover:text-primary`,onClick:()=>pi(),children:[(0,X.jsx)(gt,{className:`h-3.5 w-3.5`}),K(`designer.canvas.askAi`,o)]})]})]})]})}function zf({fieldCount:e,requiredCount:t,sectionCount:n,allCollapsed:r,onToggleAll:i,reviewAvailable:a,reviewing:o,diffCounts:s,onToggleReview:c,locale:l}){return(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] text-muted-foreground`,children:[(0,X.jsx)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:o&&s?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`font-medium text-emerald-600 dark:text-emerald-400`,children:s.added}),` `,K(`designer.canvas.diffAdded`,l),(0,X.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,X.jsx)(`span`,{className:`font-medium text-amber-600 dark:text-amber-400`,children:s.changed}),` `,K(`designer.canvas.diffChanged`,l),(0,X.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,X.jsx)(`span`,{className:`font-medium text-destructive`,children:s.removed}),` `,K(`designer.canvas.diffRemoved`,l),(0,X.jsx)(`span`,{className:`text-muted-foreground/40 normal-case ml-1`,children:K(`designer.canvas.reviewVsPublished`,l)})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e}),` `,K(`designer.canvas.fields`,l),(0,X.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,X.jsx)(`span`,{className:`font-medium text-foreground/80`,children:t}),` `,K(`designer.canvas.required`,l),n>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-muted-foreground/50`,children:`·`}),(0,X.jsx)(`span`,{className:`font-medium text-foreground/80`,children:n}),` `,K(`designer.canvas.sections`,l)]})]})}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[a&&c&&(0,X.jsxs)(`button`,{type:`button`,onClick:c,className:H(`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,X.jsx)(Rt,{className:`h-3 w-3`}),K(o?`designer.canvas.reviewExit`:`designer.canvas.reviewChanges`,l)]}),i&&(0,X.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,X.jsx)(ae,{className:`h-3 w-3`}):(0,X.jsx)(cr,{className:`h-3 w-3`}),K(r?`designer.canvas.expandAll`:`designer.canvas.collapseAll`,l)]})]})]})}function Bf({count:e,groups:t,onMoveToGroup:n,onDelete:r,onClear:i,locale:a}){let[o,s]=Z.useState(!1);return(0,X.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,X.jsx)(`span`,{className:`font-medium text-foreground`,children:G(`designer.canvas.bulkSelected`,a,{n:e})}),(0,X.jsx)(`span`,{className:`text-muted-foreground text-[11px] hidden md:inline`,children:K(`designer.canvas.bulkHint`,a)}),(0,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[t.length>0&&(0,X.jsxs)(kt,{open:o,onOpenChange:s,children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsxs)(W,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70`,children:[(0,X.jsx)(Gt,{className:`h-3.5 w-3.5`}),K(`designer.canvas.bulkMoveTo`,a),(0,X.jsx)(pr,{className:`h-3 w-3`})]})}),(0,X.jsxs)(he,{align:`end`,className:`w-52 p-1 max-h-[300px] overflow-auto`,children:[(0,X.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:K(`designer.canvas.ungrouped`,a)}),t.map(e=>(0,X.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,X.jsxs)(W,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70 text-destructive hover:text-destructive`,onClick:r,children:[(0,X.jsx)(gn,{className:`h-3.5 w-3.5`}),K(`designer.canvas.bulkDelete`,a)]}),(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:i,children:[(0,X.jsx)(Qe,{className:`h-3.5 w-3.5`}),K(`designer.canvas.bulkClear`,a)]})]})]})}function Vf({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,_]=Z.useState(!1);return(0,X.jsxs)(`section`,{className:H(`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,X.jsx)(Hf,{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,X.jsx)(`div`,{className:`space-y-2.5`,children:h})]})}function Hf({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]=Z.useState(!1),[h,g]=Z.useState(e);Z.useEffect(()=>{g(e)},[e]);let _=()=>{if(!l){m(!1);return}let t=h.trim();t&&t!==e&&l(t),m(!1)},v=n?Vn:pr;return(0,X.jsxs)(`div`,{className:`group/sec flex items-center gap-1.5 pl-0.5 min-h-[24px]`,children:[(0,X.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":K(n?`designer.canvas.expandSection`:`designer.canvas.collapseSection`,a),"aria-expanded":!n,children:(0,X.jsx)(v,{className:`h-3.5 w-3.5`})}),p?(0,X.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,X.jsx)(`span`,{className:H(`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?K(`designer.canvas.renameHint`,a):void 0,children:e}),(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60 tabular-nums shrink-0`,children:t}),c&&(0,X.jsx)(`span`,{className:`text-primary normal-case text-[10px] font-normal`,children:K(`designer.canvas.dropToAssign`,a)}),!i&&(d||u||f)&&(0,X.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,X.jsx)(Kf,{onPick:f,compact:!0,locale:a}),d&&(0,X.jsxs)(X.Fragment,{children:[(0,X.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":K(`designer.canvas.moveSectionUp`,a),children:(0,X.jsx)(Be,{className:`h-3 w-3`})}),(0,X.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":K(`designer.canvas.moveSectionDown`,a),children:(0,X.jsx)(Pe,{className:`h-3 w-3`})})]}),u&&(0,X.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":K(`designer.canvas.removeSection`,a),title:K(`designer.canvas.removeSectionHint`,a),children:(0,X.jsx)(gn,{className:`h-3 w-3`})})]})]})}function Uf({entry:e,locale:t}){let n=e.def,r=Ca[typeof n.type==`string`?n.type:`text`]?.Icon,i=typeof n.label==`string`?n.label:e.name;return(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[r&&(0,X.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground/50`}),(0,X.jsx)(`span`,{className:`text-sm font-medium truncate line-through text-muted-foreground`,children:i}),(0,X.jsx)(`code`,{className:`text-[10px] text-muted-foreground/60 font-mono truncate line-through`,children:e.name})]}),(0,X.jsx)(L,{className:`text-[10px] font-medium border-transparent bg-destructive/15 text-destructive shrink-0`,children:K(`designer.canvas.diffRemoved`,t)})]})})}function Wf({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=Ca[f],m=p?.Icon,h=ha[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=d.expression,S=typeof x==`string`?x:x&&typeof x==`object`&&typeof x.source==`string`?x.source:typeof d.formula==`string`?d.formula:void 0,C=typeof d.placeholder==`string`?d.placeholder:void 0,[w,T]=Z.useState(null),E=!!c,[D,O]=Z.useState(!1),[k,A]=Z.useState(g);Z.useEffect(()=>{A(g)},[g]);let j=e=>{l&&(e.preventDefault(),e.stopPropagation(),A(g),O(!0))},M=()=>{if(!l){O(!1);return}let t=k.trim();t&&t!==g&&l(e.name,t),O(!1)},ee=()=>{A(g),O(!1)};return(0,X.jsxs)(`div`,{className:H(`relative`,w===`before`&&`pt-1.5`),onDragOver:e=>{if(!E)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`;T(r)},onDragLeave:()=>T(null),onDrop:t=>{if(!c)return;t.preventDefault(),t.stopPropagation();let n=t.dataTransfer.getData(`text/x-objectui-field`);T(null),n&&n!==e.name&&c(n,e.name,w??`before`)},children:[w===`before`&&(0,X.jsx)(`div`,{className:`absolute left-0 right-0 -top-0.5 h-0.5 bg-primary rounded-full`}),(0,X.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:E,onDragStart:t=>{t.dataTransfer.setData(`text/x-objectui-field`,e.name),t.dataTransfer.effectAllowed=`move`},className:H(`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`,E&&`cursor-grab active:cursor-grabbing`),"aria-pressed":t||n,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 mb-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 min-w-0`,children:[n&&(0,X.jsx)(it,{className:`h-3.5 w-3.5 text-primary shrink-0`,"aria-hidden":`true`}),E&&!n&&(0,X.jsx)(nt,{className:`h-3.5 w-3.5 text-muted-foreground/40 shrink-0 group-hover:text-muted-foreground/80`,"aria-hidden":`true`}),m&&(0,X.jsx)(m,{className:H(`h-3.5 w-3.5 shrink-0`,h.icon)}),D?(0,X.jsx)(`input`,{autoFocus:!0,value:k,onChange:e=>A(e.target.value),onClick:e=>e.stopPropagation(),onKeyDown:e=>{e.stopPropagation(),e.key===`Enter`?(e.preventDefault(),M()):e.key===`Escape`&&(e.preventDefault(),ee())},onBlur:M,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,X.jsx)(`span`,{className:H(`text-sm font-medium truncate`,l&&`cursor-text`),onDoubleClick:j,title:l?K(`designer.canvas.renameHint`,o):void 0,children:g}),_&&(0,X.jsx)(`span`,{className:`text-destructive text-sm`,children:`*`}),(0,X.jsx)(`code`,{className:`text-[10px] text-muted-foreground/70 font-mono truncate`,children:e.name})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:[r===`added`&&(0,X.jsx)(L,{className:`text-[10px] font-medium border-transparent bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,children:K(`designer.canvas.diffAdded`,o)}),r===`changed`&&(0,X.jsx)(L,{className:`text-[10px] font-medium border-transparent bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:i&&i.length?G(`designer.canvas.diffChangedKeys`,o,{keys:i.join(`, `)}):void 0,children:K(`designer.canvas.diffChanged`,o)}),(0,X.jsx)(L,{variant:`outline`,className:H(`text-[10px] font-medium`,h.badge),children:If(p,o)??f})]})]}),v&&(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground mb-1.5 line-clamp-1`,children:v}),(0,X.jsx)(Af,{type:f,label:g,placeholder:C,options:y,referenceTo:b,formula:S,locale:o})]}),w===`after`&&(0,X.jsx)(`div`,{className:`absolute left-0 right-0 -bottom-1 h-0.5 bg-primary rounded-full`})]})}function Gf({onAdd:e,locale:t,aiEnabled:n}){return(0,X.jsxs)(`div`,{className:`rounded-lg border-2 border-dashed bg-background py-16 px-6 text-center space-y-3`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium`,children:K(`designer.canvas.noFields`,t)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:K(`designer.canvas.noFieldsHint`,t)}),e&&(0,X.jsxs)(`div`,{className:`pt-2 flex items-center justify-center gap-2`,children:[(0,X.jsx)(Kf,{onPick:e,locale:t}),n&&(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-primary/80 hover:text-primary`,onClick:()=>pi(),children:[(0,X.jsx)(gt,{className:`h-3.5 w-3.5`}),K(`designer.canvas.askAiGenerate`,t)]})]})]})}function Kf({onPick:e,compact:t,locale:n}){let[r,i]=Z.useState(!1),[a,o]=Z.useState(``),s=a.trim().toLowerCase(),c=Z.useMemo(()=>s?ja.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Ca[e],r=If(t,n)??``;return e.includes(s)||t.label.toLowerCase().includes(s)||r.toLowerCase().includes(s)})})).filter(e=>e.types.length>0):ja,[s,a]);return(0,X.jsxs)(kt,{open:r,onOpenChange:e=>{i(e),e||o(``)},children:[(0,X.jsx)(Yr,{asChild:!0,children:t?(0,X.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":K(`designer.canvas.addFieldToSection`,n),title:K(`designer.canvas.addFieldToSection`,n),children:(0,X.jsx)(B,{className:`h-3 w-3`})}):(0,X.jsxs)(W,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,X.jsx)(B,{className:`h-3.5 w-3.5`}),K(`designer.canvas.addField`,n)]})}),(0,X.jsxs)(he,{align:`start`,className:`w-[320px] p-0 max-h-[480px] overflow-hidden flex flex-col`,children:[(0,X.jsx)(`div`,{className:`p-2 border-b`,children:(0,X.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),placeholder:K(`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,X.jsx)(`div`,{className:`flex-1 overflow-auto p-1`,children:c.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground p-4 text-center`,children:K(`designer.canvas.noMatchingTypes`,n)}):c.map(t=>(0,X.jsxs)(`div`,{className:`mb-1`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground px-2 pt-2 pb-1`,children:Lf(t.category,n)}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-0.5`,children:t.types.map(t=>{let r=Ca[t],a=r.Icon;return(0,X.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,X.jsx)(a,{className:H(`h-3.5 w-3.5 shrink-0`,ha[r.category].icon)}),(0,X.jsx)(`span`,{className:`truncate`,children:If(r,n)})]},t)})})]},t.category))})]})]})}function qf({name:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=String(t.name??e??``);return s?(0,X.jsx)(Q,{hint:`object · designer`,children:(0,X.jsx)(ed,{fallbackHint:`The form designer couldn't be rendered. Check the Form tab.`,children:(0,X.jsx)(Rf,{objectName:s,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o})})}):(0,X.jsx)(Q,{hint:`object`,children:(0,X.jsx)(Qu,{children:K(`designer.canvas.nameToStart`,o)})})}function Jf(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 Yf(e,t){return t[e]??``}function Xf(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>Yf(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>Yf(n,t))}function Zf({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=Z.useMemo(()=>{let e=new Set;for(let n of Jf(t))e.add(n);for(let t of Jf(i))e.add(t);for(let t of Jf(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=Z.useState({}),l=Xf(t,s),u=`<!doctype html><html><head><meta charset="utf-8"><style>
16
+ html,body{margin:0;padding:16px;font:14px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#111;background:#fff;}
17
+ a{color:#2563eb;}
18
+ </style></head><body>${(i?Xf(i,s):Xf(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,X.jsx)(Q,{hint:`email_template`,children:(0,X.jsx)(Qu,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,X.jsx)(Q,{hint:`email_template`,children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_220px] gap-0`,children:[(0,X.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 px-3 py-2 text-xs space-y-0.5`,children:[(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`From`}),(0,X.jsx)(`span`,{className:`font-mono truncate`,children:n||`—`})]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`To`}),(0,X.jsx)(`span`,{className:`font-mono truncate`,children:r||`—`})]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`span`,{className:`w-12 text-muted-foreground shrink-0`,children:`Subject`}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:l||`—`})]})]}),(0,X.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,X.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,X.jsx)(Ar,{className:`h-3 w-3`}),` Variables`]}),o.length===0?(0,X.jsxs)(`div`,{className:`text-muted-foreground italic`,children:[`No `,(0,X.jsx)(`code`,{children:`{{var}}`}),` placeholders found.`]}):(0,X.jsx)(`div`,{className:`space-y-2`,children:o.map(e=>(0,X.jsxs)(`label`,{className:`block`,children:[(0,X.jsx)(`span`,{className:`block font-mono text-[10px] text-muted-foreground mb-0.5`,children:e}),(0,X.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 Qf(e){return typeof e==`number`&&Number.isFinite(e)}function $f(e){return Qf(e.ui?.x)&&Qf(e.ui?.y)}function ep(e){if(!e||typeof e!=`object`)return null;let t=e;return!Array.isArray(t.nodes)||t.nodes.length===0?null:{nodes:t.nodes,edges:Array.isArray(t.edges)?t.edges:[]}}function tp(e){let t=e.config??{};switch(e.type){case`loop`:{let e=ep(t.body);return e?[{key:`body`,label:void 0,...e}]:[]}case`parallel`:{let e=[];return(Array.isArray(t.branches)?t.branches:[]).forEach((t,n)=>{let r=ep(t);if(!r)return;let i=t.name;e.push({key:`branch-${n}`,label:typeof i==`string`&&i?i:`Branch ${n+1}`,...r})}),e}case`try_catch`:{let e=[],n=ep(t.try);n&&e.push({key:`try`,label:`Try`,...n});let r=ep(t.catch);return r&&e.push({key:`catch`,label:`Catch`,...r}),e}default:return[]}}function np(e,t,n=()=>66){let r=new Map,i=new Map(e.map(e=>[e.id,n(e)]));if(e.length===0)return{positions:r,heights:i,size:{width:28,height:28}};let a=new Map(e.map(e=>[e.id,e])),o=new Map(e.map((e,t)=>[e.id,t])),s=new Map,c=new Map;for(let t of e)c.set(t.id,0);for(let e of t)!a.has(e.source)||!a.has(e.target)||e.source===e.target||lp(e)||(s.has(e.source)||s.set(e.source,[]),s.get(e.source).push(e.target),c.set(e.target,(c.get(e.target)??0)+1));let l=[];for(let t of e)t.type===`start`&&l.push(t.id);for(let t of e)(c.get(t.id)??0)===0&&!l.includes(t.id)&&l.push(t.id);l.length===0&&l.push(e[0].id);let u=new Map,d=[];for(let e of l)u.set(e,0),d.push(e);let f=e.length*Math.max(1,t.length)+e.length+1,p=0;for(;d.length&&p<f;){p+=1;let e=d.shift(),t=u.get(e)??0;for(let n of s.get(e)??[]){let e=t+1;(u.get(n)??-1)<e&&(u.set(n,e),d.push(n))}}let m=0;for(let e of u.values())m=Math.max(m,e);for(let t of e)u.has(t.id)||(m+=1,u.set(t.id,m));let h=new Map;for(let t of e){let e=u.get(t.id)??0;h.has(e)||h.set(e,[]),h.get(e).push(t.id)}for(let e of h.values())e.sort((e,t)=>(o.get(e)??0)-(o.get(t)??0));let g=[...h.keys()].sort((e,t)=>e-t),_=0,v;for(let e of g){v!==void 0&&(_+=(e-v-1)*122);let t=h.get(e),n=-(t.length*240+(t.length-1)*44)/2,o=66;t.forEach((e,t)=>{r.set(e,{x:n+t*284,y:_});let s=a.get(e);s&&!$f(s)&&(o=Math.max(o,i.get(e)??66))}),_+=o+56,v=e}let y=1/0,b=1/0;for(let e of r.values())y=Math.min(y,e.x),b=Math.min(b,e.y);if(Number.isFinite(y)&&Number.isFinite(b)){let e=28-y,t=28-b;for(let[n,i]of r)r.set(n,{x:i.x+e,y:i.y+t})}for(let t of e)$f(t)&&r.set(t.id,{x:Math.max(0,t.ui.x),y:Math.max(0,t.ui.y)});let x=0,S=0;for(let[e,t]of r)x=Math.max(x,t.x+240),S=Math.max(S,t.y+(i.get(e)??66));return{positions:r,heights:i,size:{width:x+28,height:S+28}}}function rp(e,t){return np(e,t).positions}function ip(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 ap(e,t=66){return{x:e.x+240/2,y:e.y+t}}function op(e){return{x:e.x+240/2,y:e.y}}function sp(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 cp(e,t){return{x:(e.x+t.x)/2,y:(e.y+t.y)/2}}function lp(e){return e.type===`back`}function up(e){return{x:e.x+240,y:e.y+66/2}}function dp(e,t){return Math.max(64,Math.abs(t.y-e.y)*.35)}function fp(e,t){let n=dp(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 pp(e,t){let n=dp(e,t);return{x:Math.max(e.x,t.x)+n*.75,y:(e.y+t.y)/2}}function mp(e,t){return e.id||`${e.source}->${e.target}#${t}`}function hp(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}var gp=212;function _p(e,t){let n=0;return e.forEach((e,r)=>{let{width:i,height:a}=ip(rp(e.nodes,e.edges)),o=Math.min(1,t/Math.max(i,1));n+=(r>0?8:0)+14+(e.label?16:0)+a*o}),n}function vp(e){return e.length===0?66:86+_p(e,gp)}function yp(e,t){let{key:n,label:r}=e;if(n===`try`)return K(`engine.flowRegion.try`,t);if(n===`catch`)return K(`engine.flowRegion.catch`,t);let i=/^branch-(\d+)$/.exec(n);if(i){let e=Number(i[1])+1;if(r===`Branch ${e}`)return G(`engine.flowRegion.branchN`,t,{n:e})}return r}function bp({node:e,x:t,y:n,selected:r,onSelect:i}){let a=Tp(e.type),o=!!i;return(0,X.jsxs)(`div`,{"data-region-node-id":e.id,role:o?`button`:void 0,tabIndex:o?0:void 0,"aria-pressed":o?!!r:void 0,onClick:o?e=>{e.stopPropagation(),i()}:void 0,onKeyDown:o?e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),i())}:void 0,className:H(`absolute flex items-center gap-2 rounded-lg border bg-card px-2 py-1.5 shadow-sm`,o&&`cursor-pointer`,r?`border-primary ring-2 ring-primary/30`:`border-border/70`),style:{left:t,top:n,width:240,height:66},children:[(0,X.jsx)(`div`,{className:H(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md`,a.chip),children:(0,X.jsx)(Ep,{type:e.type,className:H(`h-4 w-4`,a.icon)})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`truncate text-[12px] font-semibold leading-tight text-foreground`,title:e.label||e.id,children:e.label||e.id}),(0,X.jsx)(`div`,{className:H(`text-[10px] font-semibold uppercase tracking-[0.08em]`,a.label),children:e.type})]})]})}function xp({region:e,maxWidth:t,selectedNodeId:n,onSelectNode:r}){let i=Z.useMemo(()=>rp(e.nodes,e.edges),[e.nodes,e.edges]),{width:a,height:o}=Z.useMemo(()=>ip(i),[i]),s=Math.min(1,t/Math.max(a,1));return(0,X.jsx)(`div`,{className:`relative`,style:{width:a*s,height:o*s},children:(0,X.jsxs)(`div`,{className:`absolute left-0 top-0`,style:{width:a,height:o,transform:`scale(${s})`,transformOrigin:`top left`},children:[(0,X.jsx)(`svg`,{className:`pointer-events-none absolute left-0 top-0 overflow-visible`,width:a,height:o,children:e.edges.map((e,t)=>{let n=i.get(e.source),r=i.get(e.target);if(!n||!r)return null;let a=lp(e),o=a?up(n):ap(n),s=a?up(r):op(r);return(0,X.jsx)(`path`,{d:a?fp(o,s):sp(o,s),strokeDasharray:a?`5 4`:void 0,className:H(`fill-none`,a?`stroke-amber-500/60`:`stroke-muted-foreground/40`),strokeWidth:1.5},e.id||`${e.source}-${e.target}-${t}`)})}),e.nodes.map(e=>{let t=i.get(e.id);return t?(0,X.jsx)(bp,{node:e,x:t.x,y:t.y,selected:n===e.id,onSelect:r?()=>r(e):void 0},e.id):null})]})})}function Sp({regions:e,maxWidth:t,selected:n,onSelectNode:r,locale:i}){return(0,X.jsx)(`div`,{className:`flex flex-col`,style:{gap:8},children:e.map(e=>{let a=yp(e,i);return(0,X.jsxs)(`div`,{className:`rounded-md border border-dashed border-border/60 bg-muted/20`,style:{padding:6},children:[a&&(0,X.jsx)(`div`,{className:`text-[9px] font-semibold uppercase tracking-wide text-muted-foreground/80`,style:{height:16,lineHeight:`12px`,paddingBottom:4},children:a}),(0,X.jsx)(xp,{region:e,maxWidth:t,selectedNodeId:n&&n.regionKey===e.key?n.nodeId:null,onSelectNode:r?t=>r(e.key,t):void 0})]},e.key)})})}function Cp(e){switch(e){case`start`:return Gr;case`end`:return Re;case`decision`:case`branch`:case`gateway`:return At;case`wait`:case`timer`:case`delay`:return Fn;case`boundary_event`:case`signal`:return Ht;case`subflow`:case`flow`:return Ke;case`create_record`:return gr;case`update_record`:return pn;case`delete_record`:return wn;case`get_record`:return Un;case`http_request`:case`webhook`:return li;case`notify`:return se;case`script`:case`script_task`:return Yn;case`screen`:case`user_task`:return Je;case`approval`:return kr;case`connector_action`:case`service_task`:return Zt;case`assignment`:return I;case`loop`:case`for_each`:return Bn;case`map`:return Dn;case`parallel_gateway`:case`join_gateway`:case`parallel`:return de;case`try_catch`:return Pt;default:return qe}}var wp={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 Tp(e){switch(e){case`start`:return wp.start;case`end`:return wp.end;case`decision`:case`branch`:case`gateway`:case`parallel_gateway`:case`join_gateway`:case`parallel`:return wp.decision;case`wait`:case`timer`:case`delay`:return wp.wait;case`boundary_event`:case`signal`:case`try_catch`:return wp.signal;case`subflow`:case`flow`:return wp.subflow;case`approval`:return wp.approval;case`loop`:case`for_each`:case`map`:return wp.loop;case`screen`:case`user_task`:return wp.screen;case`assignment`:return wp.assignment;case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return wp.record;case`http`:case`http_request`:case`notify`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return wp.integration;default:return wp.task}}function Ep({type:e,className:t}){return Z.createElement(Cp(e),{className:t,"aria-hidden":!0})}var Dp=[`Data`,`Logic`,`Human`,`Integration`,`Flow`];function Op(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`notify`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return`Integration`;default:return`Flow`}}var kp=[{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:`notify`,label:`Notify`,hint:`Send a notification to users`,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 Ap(e,t){let n=kp.find(t=>t.type===e);return Mi(e,t,n?n.label:e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `))}function jp(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`notify`:return{config:{channels:[`inbox`],recipients:[]}};case`http`:case`http_request`:return{config:{method:`GET`}};case`script`:return{};default:return{}}}function Mp({id:e,locale:t,type:n,label:r,summary:i,position:a,selected:o,editable:s,runState:c,dimmed:l,invalid:u,badge:d,onPointerDown:f,onSelect:p,onAppend:m,onAddReviseLoop:h,regions:g,expanded:_,onToggleExpand:v,height:y,selectedNestedNode:b,onSelectNestedNode:x}){let S=Tp(n),C=!!g&&g.length>0;return(0,X.jsxs)(`div`,{className:`group absolute transition-opacity duration-200`,"data-invalid":u||void 0,"data-node-id":e,style:{left:a.x,top:a.y,width:240,height:y??66,opacity:l?.35:1},children:[(0,X.jsxs)(`div`,{role:`button`,tabIndex:0,"aria-pressed":o,onPointerDown:f,onClick:e=>{e.stopPropagation(),p?.()},onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),p?.())},style:{height:66},className:H(`group flex 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`,s?`cursor-grab active:cursor-grabbing`:`cursor-pointer`,c===`active`?`border-sky-500 shadow-md shadow-sky-500/20 ring-2 ring-sky-400/60`:c===`visited`?`border-emerald-500/70 ring-1 ring-emerald-400/40`:o?`border-primary shadow-md ring-2 ring-primary/30`:u?`border-destructive ring-2 ring-destructive/50`:`border-border/80`),children:[(0,X.jsx)(`div`,{className:H(`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg transition-transform duration-150 group-hover:scale-105`,S.chip,c===`active`&&`animate-pulse`),children:(0,X.jsx)(Ep,{type:n,className:H(`h-[18px] w-[18px]`,S.icon)})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{title:r,className:`truncate text-[13px] font-semibold leading-tight text-foreground`,children:r}),(0,X.jsxs)(`div`,{className:`mt-1 flex items-baseline gap-1.5 leading-tight`,children:[(0,X.jsx)(`span`,{className:H(`shrink-0 text-[10px] font-semibold uppercase tracking-[0.08em]`,S.label),children:n}),i&&(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-[10px] text-muted-foreground`,title:i,children:i})]})]})]}),C&&v&&(0,X.jsx)(`button`,{type:`button`,"aria-label":K(_?`engine.flowCanvas.collapseRegions`:`engine.flowCanvas.expandRegions`,t),title:K(_?`engine.flowCanvas.collapseRegions`:`engine.flowCanvas.expandRegions`,t),"aria-expanded":!!_,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),v()},className:`absolute right-1.5 top-1.5 z-20 inline-flex h-5 w-5 items-center justify-center rounded-md border bg-background/90 text-muted-foreground shadow-sm transition-colors hover:border-primary hover:text-primary`,children:(0,X.jsx)(Vn,{className:H(`h-3.5 w-3.5 transition-transform`,_&&`rotate-90`)})}),C&&_&&(0,X.jsx)(`div`,{className:`rounded-lg border bg-card shadow-sm`,style:{marginTop:6,padding:6},onPointerDown:e=>e.stopPropagation(),onClick:e=>e.stopPropagation(),children:(0,X.jsx)(Sp,{regions:g,maxWidth:gp,selected:b,onSelectNode:x,locale:t})}),d&&(0,X.jsx)(`span`,{title:d.title,"data-problem":d.level,className:H(`absolute -right-2 -top-2 z-20 inline-flex h-5 w-5 items-center justify-center rounded-full border bg-background shadow-sm`,d.level===`error`?`border-destructive/50 text-destructive`:`border-amber-500/50 text-amber-600 dark:text-amber-400`),children:d.level===`error`?(0,X.jsx)(St,{className:`h-3 w-3`}):(0,X.jsx)(z,{className:`h-3 w-3`})}),s&&n!==`end`&&(0,X.jsx)(`button`,{type:`button`,title:K(`engine.flowCanvas.addConnected`,t),"aria-label":K(`engine.flowCanvas.addConnected`,t),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m?.()},className:H(`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,X.jsx)(B,{className:`h-3.5 w-3.5`})}),h&&(0,X.jsx)(`button`,{type:`button`,title:K(`engine.flowCanvas.addReviseLoop`,t),"aria-label":K(`engine.flowCanvas.addReviseLoopShort`,t),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),h()},className:H(`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,X.jsx)(Xr,{className:`h-3.5 w-3.5`})})]})}var Np=`p-0 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:pb-1 [&_[cmdk-group-heading]]:pt-1 [&_[cmdk-group-heading]]:text-[10px] [&_[cmdk-group-heading]]:font-semibold [&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-[0.08em] [&_[cmdk-group-heading]]:text-muted-foreground [&:not(:first-child)]:mt-1 [&:not(:first-child)]:border-t [&:not(:first-child)]:border-border/60 [&:not(:first-child)]:pt-1`;function Pp({locale:e,items:t=kp,onPick:n,open:r,onOpenChange:i,children:a}){let[o,s]=Z.useState(``),{recents:c,recordRecent:l}=Za(),u=Z.useRef(null),[d,f]=Z.useState(r);r!==d&&(f(r),r||s(``));let p=o.trim().toLowerCase(),m=Z.useMemo(()=>p?t.filter(t=>t.label.toLowerCase().includes(p)||(t.hint??``).toLowerCase().includes(p)||t.type.toLowerCase().includes(p)||Mi(t.type,e,t.label).toLowerCase().includes(p)||(zi(t.type,e,t.hint)??``).toLowerCase().includes(p)):t,[t,p,e]),h=Z.useMemo(()=>{let e=new Map;for(let t of m){let n=t.category??Op(t.type),r=e.get(n)??[];r.push(t),e.set(n,r)}return Dp.map(t=>[t,e.get(t)??[]]).filter(([,e])=>e.length>0)},[m]),g=Z.useMemo(()=>{if(p)return[];let e=new Map(t.map(e=>[e.type,e]));return c.map(t=>e.get(t)).filter(e=>!!e)},[t,c,p]),_=e=>{l(e),n(e)},v=(t,n)=>{let r=Tp(t.type),i=Mi(t.type,e,t.label),a=zi(t.type,e,t.hint);return(0,X.jsxs)(Hn,{value:n?`recent:${t.type}`:t.type,onSelect:()=>_(t.type),className:`gap-2.5 rounded-lg px-2 py-1.5 [&_svg]:size-[15px]`,children:[(0,X.jsx)(`span`,{className:H(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md`,r.chip),children:(0,X.jsx)(Ep,{type:t.type,className:H(`h-[15px] w-[15px]`,r.icon)})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`truncate text-[13px] font-medium`,children:i}),a&&(0,X.jsx)(`div`,{className:`truncate text-[11px] text-muted-foreground`,children:a})]})]},n?`recent:${t.type}`:t.type)};return(0,X.jsxs)(kt,{open:r,onOpenChange:i,children:[(0,X.jsx)(Yr,{asChild:!0,children:a}),(0,X.jsx)(he,{align:`end`,sideOffset:6,className:`w-60 overflow-hidden rounded-xl border bg-popover/95 p-0 shadow-xl shadow-foreground/[0.08] ring-1 ring-black/[0.03] backdrop-blur-md`,onOpenAutoFocus:e=>{e.preventDefault(),u.current?.focus()},children:(0,X.jsxs)(ie,{shouldFilter:!1,loop:!0,className:`bg-transparent`,children:[(0,X.jsx)(jr,{ref:u,value:o,onValueChange:s,placeholder:K(`engine.flowPalette.search`,e),className:`h-9 text-[13px]`}),(0,X.jsxs)(rn,{className:`max-h-[56vh] p-1`,children:[(0,X.jsx)(Rr,{className:`py-6 text-center text-xs text-muted-foreground`,children:K(`engine.flowPalette.empty`,e)}),g.length>0&&(0,X.jsx)(ur,{heading:K(`engine.flowPalette.recent`,e),className:Np,children:g.map(e=>v(e,!0))}),h.map(([t,n])=>(0,X.jsx)(ur,{heading:K(`engine.flowPalette.category.${t.toLowerCase()}`,e),className:Np,children:n.map(e=>v(e))},t))]})]})})]})}function Fp(){return`${``.replace(/\/$/,``)}/api/v1`}function Ip(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??Op(e.type)})}return[...n.values()]}function Lp(){let[e,t]=(0,Z.useState)([]),n=(0,Z.useRef)(!0);return(0,Z.useEffect)(()=>{n.current=!0;let e=new AbortController;return(async()=>{try{let r=await fetch(`${Fp()}/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 Rp(){let e=Lp();return(0,Z.useMemo)(()=>e.length?Ip(kp,e):kp,[e])}function zp(){let e=Lp();return(0,Z.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 Bp=e=>typeof e==`string`?e:void 0;function Vp(e,t){let n=e.trim();if(!n)return{result:!1,error:`Empty condition.`};try{let e=new P({...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 Hp(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 Up(e,t,n){let r=[],i=[],a=e.map(e=>e.id),o=new Set;for(let e of a){if(!e){r.push({level:`error`,message:K(`engine.flowValidate.nodeMissingId`,n)});continue}o.has(e)&&r.push({level:`error`,nodeId:e,message:G(`engine.flowValidate.duplicateNodeId`,n,{id:e})}),o.add(e)}for(let e of t)o.has(e.source)||r.push({level:`error`,edge:{source:e.source,target:e.target},message:G(`engine.flowValidate.edgeSourceMissing`,n,{source:e.source})}),o.has(e.target)||r.push({level:`error`,edge:{source:e.source,target:e.target},message:G(`engine.flowValidate.edgeTargetMissing`,n,{target:e.target})});let s=new Set(t.map(e=>e.target)),c=e.filter(e=>e.type===`start`),l=e.filter(e=>!s.has(e.id)),u;c.length===1?(u=c[0].id,s.has(u)&&i.push({level:`warning`,nodeId:u,message:K(`engine.flowValidate.startHasIncoming`,n)})):c.length>1?r.push({level:`error`,message:G(`engine.flowValidate.multipleStart`,n,{count:c.length})}):l.length===1?(u=l[0].id,i.push({level:`warning`,nodeId:u,message:K(`engine.flowValidate.noStartUsingRoot`,n)})):l.length===0?r.push({level:`error`,message:K(`engine.flowValidate.noEntry`,n)}):r.push({level:`error`,message:G(`engine.flowValidate.ambiguousEntry`,n,{count:l.length})});for(let a of e){if(a.type!==`decision`)continue;let e=t.filter(e=>e.source===a.id),o=e.filter(e=>e.isDefault);o.length>1&&r.push({level:`error`,nodeId:a.id,message:G(`engine.flowValidate.decisionMultipleDefaults`,n,{id:a.id,count:o.length})}),e.length===0?i.push({level:`warning`,nodeId:a.id,message:G(`engine.flowValidate.decisionNoBranches`,n,{id:a.id})}):o.length===0&&e.every(e=>Bp(e.condition))&&i.push({level:`warning`,nodeId:a.id,message:G(`engine.flowValidate.decisionNoDefault`,n,{id:a.id})})}if(u){let r=new Set([u]),a=[u];for(;a.length;){let e=a.shift();for(let n of t)n.source===e&&o.has(n.target)&&!r.has(n.target)&&(r.add(n.target),a.push(n.target))}for(let t of e)r.has(t.id)||i.push({level:`warning`,nodeId:t.id,message:G(`engine.flowValidate.nodeUnreachable`,n,{id:t.id})})}let d=t.filter(e=>e.type!==`back`),f=Hp(a.filter(e=>!!e),d);return f&&r.push({level:`error`,nodeId:f[0],cycle:f,message:G(`engine.flowValidate.cycleDetected`,n,{cycle:f.join(` → `)})}),{errors:r,warnings:i,startNodeId:u}}function $(e,t,n,r={}){return{id:e,path:[`config`,e],label:t,kind:n,...r}}function Wp(e,t,n,r,i={}){return{id:`${e}.${t}`,path:[e,t],label:n,kind:r,...i}}var Gp=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`].map(e=>({value:e,label:e})),Kp={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-after-write`,label:`Record created or updated`},{value:`record-before-update`,label:`Record before update`},{value:`record-after-delete`,label:`Record deleted`},{value:`schedule`,label:`Schedule (cron)`},{value:`time_relative`,label:`Time-relative (date sweep)`},{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-after-write`,`record-before-update`,`record-after-delete`,`schedule`,`webhook`,`event`]}}),$(`condition`,`Entry condition`,`expression`,{placeholder:`status == "qualifying" && previous.status != "qualifying"`,help:'CEL predicate — the flow runs only when this is true (for time-relative sweeps it gates each matched record). Leave empty to run on every event. On a "created or updated" trigger, `previous == null` selects the create path.',showWhen:{field:`triggerType`,equals:[`record-after-create`,`record-after-update`,`record-after-write`,`record-before-update`,`record-after-delete`,`schedule`,`time_relative`,`webhook`,`event`]}}),{id:`schedule.expression`,path:[`config`,`schedule`,`expression`],fallbackPath:[`config`,`cron`],label:`Cron schedule`,kind:`text`,placeholder:`0 7 * * *`,help:`Cron expression — when the flow runs. A time-relative sweep defaults to daily if left empty.`,showWhen:{field:`triggerType`,equals:[`schedule`,`time_relative`]}},{id:`timeRelative.object`,path:[`config`,`timeRelative`,`object`],label:`Sweep object`,kind:`reference`,ref:{kind:`object`},placeholder:`contracts`,help:`Object whose records are swept each run.`,showWhen:{field:`triggerType`,equals:[`time_relative`]}},{id:`timeRelative.dateField`,path:[`config`,`timeRelative`,`dateField`],label:`Date field`,kind:`text`,placeholder:`end_date`,help:`The date / datetime field compared against today.`,showWhen:{field:`triggerType`,equals:[`time_relative`]}},{id:`timeRelative.withinDays`,path:[`config`,`timeRelative`,`withinDays`],label:`Within days`,kind:`number`,placeholder:`30`,help:`Range mode: fire while the date is within N days of today (negative = overdue lookback). Leave empty if using Offset days.`,showWhen:{field:`triggerType`,equals:[`time_relative`]}},{id:`timeRelative.offsetDays`,path:[`config`,`timeRelative`,`offsetDays`],label:`Offset days`,kind:`numberList`,placeholder:`60`,help:`Offset mode: fire when the date is exactly today + each offset (e.g. 60, 30, 7). Leave empty if using Within days.`,showWhen:{field:`triggerType`,equals:[`time_relative`]}},{id:`timeRelative.filter`,path:[`config`,`timeRelative`,`filter`],label:`Extra filter`,kind:`keyValue`,help:`Optional filter ANDed with the date window (e.g. status = active).`,showWhen:{field:`triggerType`,equals:[`time_relative`]}},{id:`timeRelative.maxRecords`,path:[`config`,`timeRelative`,`maxRecords`],label:`Max records / run`,kind:`number`,placeholder:`1000`,help:`Cap on records launched per sweep (default 1000).`,showWhen:{field:`triggerType`,equals:[`time_relative`]}},$(`criteria`,`Entry condition (legacy)`,`expression`,{placeholder:`status == "active"`,help:`Legacy key — prefer "Entry condition" (condition).`,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, a CEL expression, and a target node. A branch whose expression is "true" is the default/else path. Picking a target wires the branch’s outgoing edge (creating or updating it); clearing it detaches that edge.`,columns:[{key:`label`,label:`Label`,kind:`text`,placeholder:`Has deals`},{key:`expression`,label:`Expression`,kind:`expression`,placeholder:`expiring_deals.length > 0`},{key:`target`,label:`Target`,kind:`reference`,placeholder:`next node`,ref:{kind:`node`}}]}),$(`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}`,refMode:`template`,help:`Expression resolving to the items to iterate.`}),$(`iteratorVariable`,`Item variable`,`text`,{placeholder:`currentItem`})],map:[$(`collection`,`Collection`,`expression`,{placeholder:`{items}`,refMode:`template`,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:Gp,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:`invoke_function`,label:`Call function`},{value:`email`,label:`Email`},{value:`slack`,label:`Slack`}],defaultValue:`invoke_function`,help:`How this step runs. "Call function" invokes a registered function — the path that runs real logic.`}),$(`function`,`Function`,`text`,{placeholder:`score_lead`,help:`Registered function to call — declared via defineStack({ functions }). Always wins over Action type.`,showWhen:{field:`actionType`,equals:[`invoke_function`]}}),$(`inputs`,`Inputs`,`keyValue`,{help:`Values passed to the function; {var} references resolve against the live flow variables.`,showWhen:{field:`actionType`,equals:[`invoke_function`]}}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`aiResult`,help:`Flow variable the function's return value is bound to, for later steps.`,showWhen:{field:`actionType`,equals:[`invoke_function`]}}),$(`template`,`Template`,`reference`,{ref:{kindFrom:`actionType`,map:{email:`email-template`}},placeholder:`case_escalated`,help:`Message template id.`,showWhen:{field:`actionType`,equals:[`email`,`slack`]}}),$(`recipients`,`Recipients`,`stringList`,{help:`One recipient per row (user id, field ref, or address).`,showWhen:{field:`actionType`,equals:[`email`,`slack`]}}),$(`variables`,`Template variables`,`keyValue`,{help:`Values injected into the template.`,showWhen:{field:`actionType`,equals:[`email`,`slack`]}}),$(`script`,`Code (not executed)`,`textarea`,{placeholder:`return { ok: true };`,help:`Inline scripts are NOT executed by the built-in runtime — this node is a no-op. Move the logic into a registered function and use "Call function".`,refMode:`expression`,showWhen:{field:`__legacy__`,equals:[]}}),{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:`manager`,label:`Manager`},{value:`position`,label:`Position`},{value:`department`,label:`Department`},{value:`team`,label:`Team`},{value:`field`,label:`Field`},{value:`expression`,label:`Expression (CEL)`},{value:`org_membership_level`,label:`Organization membership (owner/admin/member)`},{value:`user`,label:`User`}]},{key:`value`,label:`Value`,kind:`reference`,placeholder:"User id / membership tier / position / team / department / field — per `type`",ref:{kindFrom:`type`,objectSource:`$trigger`,map:{user:`user`,position:`position`,org_membership_level:`org-membership-level`,role:`org-membership-level`,team:`team`,department:`department`,manager:`manager`,field:`object-field`,queue:`queue`}}},{key:`resolveAs`,label:`Resolve as`,kind:`select`,options:[{value:`user`,label:`User ids (default)`},{value:`department`,label:`Department ids → members`},{value:`position`,label:`Position names → holders`},{value:`team`,label:`Team ids → members`}]},{key:`group`,label:`Group`,kind:`text`,placeholder:`legal / finance — for per-group sign-off`}]}),$(`behavior`,`Behavior`,`select`,{options:[{value:`first_response`,label:`First response wins`},{value:`unanimous`,label:`Unanimous (all approve)`},{value:`quorum`,label:`Quorum (M of N approve)`},{value:`per_group`,label:`Per group (each group signs off)`}],defaultValue:`first_response`,help:`How multiple approvers combine. Any rejection is a veto in every mode.`}),$(`minApprovals`,`Min approvals`,`number`,{placeholder:`1`,help:`Approvals required — total for quorum, per group for per_group. Clamped server-side so it can never deadlock.`}),$(`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.`}),$(`onEmptyApprovers`,`If no approver resolves`,`select`,{options:[{value:`admin_rescue`,label:`Hold for admin takeover (default)`},{value:`fail`,label:`Fail the node (config bug)`},{value:`auto_approve`,label:`Auto-approve (waves through!)`}],defaultValue:`admin_rescue`,help:`What an empty resolved approver slate does at node entry. Auto-approve silently waves the record through — opt in deliberately.`}),{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:`position`},placeholder:`position machine name / user id`,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:[Wp(`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`]}),Wp(`waitEventConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H · P3D`,help:`ISO 8601 duration (e.g. PT1H, P3D).`,showWhen:{field:`waitEventConfig.eventType`,equals:[`timer`]},fallbackPath:[`config`,`timerDuration`]}),Wp(`waitEventConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.renewed`,showWhen:{field:`waitEventConfig.eventType`,equals:[`signal`,`webhook`]},fallbackPath:[`config`,`signalName`]}),Wp(`waitEventConfig`,`timeoutMs`,`Timeout (ms)`,`number`,{placeholder:`3600000`,fallbackPath:[`config`,`timeoutMs`]}),Wp(`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`}],notify:[$(`recipients`,`Recipients`,`stringList`,{help:`User id(s) / audience selector(s) to notify. At least one is required.`}),$(`title`,`Title`,`text`,{placeholder:`Your request was approved`,help:`Notification title (required).`}),$(`message`,`Message`,`textarea`,{placeholder:`Supports {var} template references.`,help:`Notification body.`}),$(`channels`,`Channels`,`stringList`,{help:`Channels to fan out to (default: inbox — e.g. inbox · email · push).`}),$(`topic`,`Topic`,`text`,{placeholder:`notify`,help:`Event topic (default: "notify").`}),$(`severity`,`Severity`,`select`,{options:[{value:`info`,label:`Info`},{value:`warning`,label:`Warning`},{value:`critical`,label:`Critical`}],help:`Notification severity.`}),$(`sourceObject`,`Link object`,`text`,{placeholder:`sys_approval_request`,help:`Object of the record the notification links to (requires Link record id).`}),$(`sourceId`,`Link record id`,`text`,{help:`Record id the notification links to (requires Link object).`}),$(`url`,`Click-through URL`,`text`,{help:`Explicit link; overrides the one synthesized from Link object/record.`})],connector_action:[Wp(`connectorConfig`,`connectorId`,`Connector`,`reference`,{ref:{kind:`connector`},placeholder:`slack · email · salesforce`}),Wp(`connectorConfig`,`actionId`,`Action`,`reference`,{ref:{kind:`connector-action`,connectorSource:`connectorId`},placeholder:`sendMessage · send`}),Wp(`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:[Wp(`boundaryConfig`,`attachedToNodeId`,`Attached to`,`reference`,{ref:{kind:`node`},placeholder:`host node id`,help:`Host node this boundary event monitors.`}),Wp(`boundaryConfig`,`eventType`,`Event type`,`select`,{options:[{value:`error`,label:`Error`},{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`cancel`,label:`Cancel`}],defaultValue:`error`}),Wp(`boundaryConfig`,`interrupting`,`Interrupting`,`boolean`,{help:`Cancel the host activity when this event fires.`}),Wp(`boundaryConfig`,`errorCode`,`Error code`,`text`,{placeholder:`TIMEOUT (empty = all)`,showWhen:{field:`boundaryConfig.eventType`,equals:[`error`]}}),Wp(`boundaryConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H`,showWhen:{field:`boundaryConfig.eventType`,equals:[`timer`]}}),Wp(`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`})]},qp={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 Jp(e){return e?Kp[qp[e]??e]??[]:[]}function Yp(e){return e.path[0]===`config`}function Xp(e,t){let n=Jp(t);if(!e)return n;let r=e.filter(Yp),i=n.filter(e=>!Yp(e)),a=new Set(i.map(e=>e.path[e.path.length-1]));return[...r.filter(e=>!a.has(e.path[e.path.length-1])),...i]}function Zp(e,t){if(!t)return e;let n={...e};return t.label&&(n.label=t.label),e.options&&t.opts&&(n.options=e.options.map(e=>({...e,label:t.opts[e.value]??e.label}))),n}function Qp(e,t,n){let r=Ri(e,n.id)??Ri(t,n.id);if(!r)return n;let i={...n};return r.label&&(i.label=r.label),r.help&&(i.help=r.help),n.options&&r.opts&&(i.options=n.options.map(e=>({...e,label:r.opts[e.value]??e.label}))),n.columns&&r.cols&&(i.columns=n.columns.map(e=>Zp(e,r.cols[e.key]))),i}function $p(e,t,n){if(!e||!Ii(n))return t;let r=qp[e]??e;return t.map(t=>Qp(e,r,t))}function em(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 tm(e){return e.path.length>=2&&e.path[0]===`config`?e.path[1]:void 0}function nm(e,t,n){if(!e.showWhen)return!0;let r=em(t,e);if(r!=null&&r!==``)return!0;let i=n.find(t=>t.id===e.showWhen.field);if(!i)return!1;let a=em(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 rm=[`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`],im=new Set([`record-after-create`,`record-after-update`,`record-after-write`,`record-before-write`,`record-before-update`,`record-after-delete`]),am=new Set([`record-after-update`,`record-before-update`,`record-after-write`,`record-before-write`]);function om(e){return Array.isArray(e)?e:[]}function sm(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function cm(e){return typeof e==`string`&&e?e:void 0}function lm(e,t){let n=new Map;for(let e of t){let t=cm(e.source),r=cm(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 um(e){let t=cm(e.type),n=sm(e.config),r=cm(e.id)??``,i=cm(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})};if((t===`loop`||t===`map`)&&s(cm(n.iteratorVariable),`loop`),s(cm(n.outputVariable)),s(cm(n.idVariable)),t===`assignment`){let e=n.assignments;if(Array.isArray(e))for(let t of e){let e=sm(t);s(cm(e.variable)??cm(e.name)??cm(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 om(n.fields))s(cm(sm(e).name));if(t===`approval`&&r){s(`${r}.decision`);for(let e of om(n.decisionOutputs)){let t=typeof e==`string`?e:cm(sm(e).key);t&&s(`${r}.${t}`)}}return o}function dm(e){let t=new Set;return e.filter(e=>t.has(e.token)?!1:(t.add(e.token),!0))}function fm(e,t){let n=om(e.nodes).map(sm),r=om(e.edges),i=[];for(let t of om(e.variables)){let e=sm(t),n=cm(e.name);if(!n)continue;let r=cm(e.type);i.push({token:n,label:n,detail:r?`variable · ${r}`:`variable`,group:`variables`})}if(!t)return{refs:dm(i)};let a=lm(t,r),o=n.find(e=>cm(e.type)===`start`),s=cm(o?.id);for(let e of n){let n=cm(e.id);if(!(!n||n===t||!a.has(n))&&n!==s)for(let t of um(e))i.push(t)}if(o){let e=sm(o.config),n=cm(e.triggerType),r=cm(e.objectName),c=!!n&&im.has(n),l=s===t||!!s&&a.has(s);if(c&&r&&l){let e=s===t,a=am.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:dm(i),trigger:{objectName:r,fieldPrefix:e?``:`record.`,includePrevious:a}}}}return{refs:dm(i)}}function pm(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 mm=new Set([`true`,`false`,`null`,`in`]),hm=new Set([`env`,`request`,`context`,`user`,`now`,`today`,`self`,`data`]);function gm(e){let t=new Set;for(let n of e){let e=n.token.split(`.`)[0];e&&t.add(e)}return t}function _m(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 vm(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))||mm.has(e)||n.push(e)}return n}function ym(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 vm(i)){if(a.has(e)||(a.add(e),n.has(e)||hm.has(e)||e.startsWith(`$`)))continue;let t,r=3;for(let i of n){let n=_m(e,i,2);n<r&&(r=n,t=i)}o.push({token:e,suggestion:r<=2?t:void 0})}return o}function bm(e,t){if(e.length===1){let n=e[0];return n.suggestion?G(`engine.flowRef.unknownWithSuggestion`,t,{token:n.token,suggestion:n.suggestion}):G(`engine.flowRef.notInScope`,t,{token:n.token})}return G(`engine.flowRef.notInScopeMulti`,t,{tokens:e.map(e=>`\`${e.token}\``).join(`, `)})}var xm=/(?:^|[^{])\{\s*([A-Za-z_$][\w.$]*)\s*\}(?!\})/;function Sm(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 Cm(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.`};Sm(n.replace(/\{\{/g,``).replace(/\}\}/g,``),`{`,`}`);let e=xm.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=xm.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\`).`}:Sm(n,`(`,`)`)?Sm(n,`[`,`]`)?null:{message:`Unbalanced brackets in \`${n}\`.`}:{message:`Unbalanced parentheses in \`${n}\`.`}}function wm(e){return Array.isArray(e)?e:[]}function Tm(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function Em(e){return typeof e==`string`&&e?e:void 0}function Dm(e,t,n){let r=Cm(`predicate`,e);if(r)return{level:`error`,message:r.message};if(t&&t.size>0){let r=ym(e,`predicate`,t);if(r.length>0)return{level:`warning`,message:bm(r,n)}}return null}function Om(e,t){let n=wm(e.nodes).map(Tm),r=wm(e.edges).map(Tm),i=Em(n.find(e=>Em(e.type)===`start`)?.id),a=[];for(let r of n){let n=Em(r.id),o=Em(r.type);if(!n||!o)continue;let s=n===i?null:gm(fm(e,n).refs);for(let e of Jp(o))if(e.kind===`expression`&&e.refMode!==`template`){let i=Dm(em(r,e),s,t);i&&a.push({target:{kind:`node`,nodeId:n},level:i.level,message:i.message})}else if(e.kind===`objectList`&&e.columns){let i=e.columns.filter(e=>e.kind===`expression`);if(i.length===0)continue;for(let o of wm(em(r,e))){let e=Tm(o),r=Em(e.label);for(let o of i){let i=Dm(e[o.key],s,t);if(i){let e=r||o.label;a.push({target:{kind:`node`,nodeId:n},level:i.level,message:e?`${e}: ${i.message}`:i.message})}}}}}for(let n of r){let r=Em(n.source),o=Em(n.target);if(!r||!o||n.isDefault===!0)continue;let s=r===i?null:gm(fm(e,r).refs),c=Dm(n.condition,s,t);c&&a.push({target:{kind:`edge`,source:r,target:o},level:c.level,message:c.message})}return a}function km(e,t){return`${e}->${t}`}function Am(e,t,n){let r=e.findIndex(e=>e.source===t&&e.target===n);return r>=0?mp(e[r],r):`${t}->${n}#-1`}function jm(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 Mm(e,t){if(e.edge){let{source:n,target:r}=e.edge;return{target:{kind:`edge`,source:n,target:r,edgeKey:Am(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:Am(t,r,i)},highlight:{nodeIds:a,edges:o}}}return e.nodeId?{target:{kind:`node`,nodeId:e.nodeId}}:{target:{kind:`flow`}}}function Nm(e,t,n){let r=jm(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:mp(t,e)}}}return{kind:`flow`}}function Pm(e){return e.kind===`node`?`n:${e.nodeId}`:e.kind===`edge`?`e:${e.source}->${e.target}`:`flow`}function Fm({nodes:e,edges:t,serverDiagnostics:n,variables:r,locale:i}){let a=[],o=Up(e,t,i),s=(e,n)=>{n.forEach((n,r)=>{let{target:i,highlight:o}=Mm(n,t);a.push({id:`structural:${e}:${r}:${Pm(i)}`,level:e,message:n.message,target:i,source:`structural`,...o?{highlight:o}:{}})})};return s(`error`,o.errors),s(`warning`,o.warnings),(n??[]).forEach((n,r)=>{let i=n.severity===`warning`?`warning`:`error`,o=Nm(n.path,e,t);a.push({id:`server:${r}:${Pm(o)}`,level:i,message:n.message,target:o,source:`server`})}),Om({nodes:e,edges:t,variables:r??[]},i).forEach((e,n)=>{let r=e.target.kind===`edge`?{kind:`edge`,source:e.target.source,target:e.target.target,edgeKey:Am(t,e.target.source,e.target.target)}:{kind:`node`,nodeId:e.target.nodeId};a.push({id:`expression:${e.level}:${n}:${Pm(r)}`,level:e.level,message:e.message,target:r,source:`expression`})}),a.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 Im(e){return{level:e.some(e=>e.level===`error`)?`error`:`warning`,title:e.map(e=>e.message).join(`
19
+ `),count:e.length}}function Lm(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=km(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,Im(n));let i=new Map;for(let[e,t]of n)i.set(e,Im(t));return{byNode:r,byEdge:i}}function Rm(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(km(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(km(e.source,e.target))}return{invalidNodeIds:[...t],invalidEdges:n}}var zm=.4,Bm=1.6,Vm=4;function Hm({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,selectedNestedPath:_,onSelectNested:v,onPatch:y}){let b=Z.useRef(null),[x,S]=Z.useState(1),[C,w]=Z.useState({x:0,y:0}),[T,E]=Z.useState(!1),D=Rp(),[O,k]=Z.useState(null),A=Z.useRef(null),j=Z.useRef(null),[M,ee]=Z.useState(()=>new Set),te=Z.useCallback(e=>{let t=M.has(e);ee(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),t&&_?.containerId===e&&v?.(null)},[M,_,v]),N=Z.useMemo(()=>{let t=new Map;for(let n of e){let e=tp(n);e.length>0&&t.set(n.id,e)}return t},[e]),ne=Z.useMemo(()=>{let t=new Map;for(let n of e){let e=M.has(n.id)?N.get(n.id):void 0;t.set(n.id,e?vp(e):66)}return t},[e,N,M]),{positions:P,heights:re,size:F}=Z.useMemo(()=>np(e,t,e=>ne.get(e.id)??66),[e,t,ne]),ie=Z.useMemo(()=>new Set(c??[]),[c]),I=Z.useMemo(()=>new Set(l??[]),[l]),ae=Z.useMemo(()=>new Set(u??[]),[u]),oe=(c?.length??0)>0||!!s,{byNode:se,byEdge:ce}=Z.useMemo(()=>Lm(p??[]),[p]),le=Z.useMemo(()=>(p??[]).filter(e=>e.level===`error`),[p]),ue=Z.useCallback(e=>O&&O.id===e?{x:O.x,y:O.y}:P.get(e)??{x:0,y:0},[O,P]),de=Z.useCallback((t,n,r)=>{if(!y)return;let i=e.findIndex(e=>e.id===t);if(i<0)return;let a=e[i];y({nodes:Sa(e,i,{...a,ui:{...a.ui??{},x:n,y:r}})})},[e,y]),fe=Z.useCallback((n,r)=>{if(!y)return;let i=qi(`node`,e.map(e=>e.id).filter(Boolean)),a=Ap(n,o),s=r?.at,c={id:i,type:n,label:a,...jp(n),...s?{ui:{x:s.x,y:s.y}}:{}},l={nodes:Xi(e,c)};if(r?.from){let n={id:qi(`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)}}l.edges=Xi(t,n)}y(l),h(c),E(!1)},[t,e,y,h,ue,o]),pe=Z.useCallback((n,r=`create_record`)=>{if(!y)return;let i=t.findIndex(e=>e===n);if(i<0)return;let a=qi(`node`,e.map(e=>e.id).filter(Boolean)),s=ue(n.source),c=ue(n.target),l={x:(s.x+c.x)/2,y:(s.y+c.y)/2},u={id:a,type:r,label:Ap(r,o),...jp(r),ui:{x:l.x,y:l.y}},d={...n,target:a},f={id:qi(`edge`,[...t.map(e=>e.id).filter(Boolean),`edge`]),source:a,target:n.target},p=Sa(t,i,d);y({nodes:Xi(e,u),edges:Xi(p,f)}),h(u)},[t,e,y,h,ue,o]),me=Z.useCallback(n=>{if(!y||!e.some(e=>e.id===n))return;let r=qi(`node`,e.map(e=>e.id).filter(Boolean)),i={id:r,type:`wait`,label:K(`engine.flowCanvas.awaitingRevision`,o),waitEventConfig:{eventType:`signal`,signalName:`revision`,onTimeout:`fail`}},a=t.map(e=>e.id).filter(Boolean),s=qi(`edge`,a),c=qi(`edge`,[...a,s]),l={id:s,source:n,target:r,label:`revise`},u={id:c,source:r,target:n,label:`resubmit`,type:`back`};y({nodes:Xi(e,i),edges:Xi(Xi(t,l),u)}),h(i)},[t,e,y,h,o]),he=Z.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]),L=Z.useCallback(n=>{y&&(y({nodes:e.filter(e=>e.id!==n),edges:t.filter(e=>e.source!==n&&e.target!==n)}),h(null))},[t,e,y,h]),ge=Z.useCallback(e=>t=>{if(!n||t.button!==0)return;t.stopPropagation();let r=ue(e);A.current={nodeId:e,startX:t.clientX,startY:t.clientY,originX:r.x,originY:r.y,moved:!1},t.currentTarget.setPointerCapture?.(t.pointerId)},[n,ue]),_e=Z.useCallback(e=>{let t=A.current;if(!t)return;let n=(e.clientX-t.startX)/x,r=(e.clientY-t.startY)/x;!t.moved&&Math.hypot(e.clientX-t.startX,e.clientY-t.startY)<Vm||(t.moved=!0,k({id:t.nodeId,x:Math.max(0,t.originX+n),y:Math.max(0,t.originY+r)}))},[x]),ve=Z.useCallback(e=>{let t=A.current;A.current=null,t&&(e.currentTarget.releasePointerCapture?.(e.pointerId),t.moved&&O&&de(t.nodeId,Math.round(O.x),Math.round(O.y)),k(null))},[O,de]),ye=Z.useCallback(e=>{e.button===0&&(h(null),j.current={startX:e.clientX,startY:e.clientY,originX:C.x,originY:C.y},e.currentTarget.setPointerCapture?.(e.pointerId))},[h,C.x,C.y]),be=Z.useCallback(e=>{let t=j.current;t&&w({x:t.originX+(e.clientX-t.startX),y:t.originY+(e.clientY-t.startY)})},[]),xe=Z.useCallback(e=>{j.current&&e.currentTarget.releasePointerCapture?.(e.pointerId),j.current=null},[]),Se=e=>Math.min(Bm,Math.max(zm,e)),Ce=Z.useCallback(()=>{let e=b.current;if(!e)return;let t=(e.clientWidth-32)/F.width,n=(e.clientHeight-32)/F.height,r=Se(Math.min(t,n));S(r),w({x:(e.clientWidth-F.width*r)/2,y:Math.max(16,(e.clientHeight-F.height*r)/2)})},[F.height,F.width]);Z.useEffect(()=>{let e=b.current;e&&(S(1),w({x:(e.clientWidth-F.width)/2,y:Math.max(16,(e.clientHeight-F.height)/2)}))},[]),Z.useEffect(()=>{if(!m)return;let e=b.current;if(!e)return;let t=m.target,n=null;if(t.kind===`node`){let e=P.get(t.nodeId);e&&(n={x:e.x+240/2,y:e.y+(re.get(t.nodeId)??66)/2})}else if(t.kind===`edge`){let e=P.get(t.source),r=P.get(t.target);e&&r&&(n=cp(ap(e,re.get(t.source)??66),op(r)))}n&&w({x:e.clientWidth/2-n.x*x,y:e.clientHeight/2-n.y*x})},[m?.nonce]);let we=Z.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(),L(i)}},[L,n,i]);return(0,X.jsxs)(`div`,{className:`relative h-full min-h-[320px] w-full overflow-hidden`,children:[le.length>0&&(0,X.jsxs)(`div`,{className:`absolute left-2 top-2 z-30 max-w-[min(60%,420px)] space-y-1`,children:[le.slice(0,3).map(e=>{let t=!!f&&e.target.kind!==`flow`;return(0,X.jsxs)(`button`,{type:`button`,role:`alert`,disabled:!t,onPointerDown:e=>e.stopPropagation(),onClick:t?t=>{t.stopPropagation(),f(e)}:void 0,title:t?K(`engine.flowCanvas.reveal`,o):void 0,className:H(`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,X.jsx)(z,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{children:e.message})]},e.id)}),le.length>3&&(0,X.jsx)(`div`,{className:`px-2.5 text-[10px] text-destructive/80`,children:G(`engine.flowCanvas.moreErrors`,o,{count:le.length-3})})]}),(0,X.jsxs)(`div`,{className:`absolute right-2 top-2 z-30 flex items-center gap-1.5`,children:[n&&(0,X.jsx)(Pp,{locale:o,items:D,open:T,onOpenChange:E,onPick:e=>fe(e,{from:i??void 0}),children:(0,X.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,X.jsx)(B,{className:`h-3.5 w-3.5`}),K(`engine.inspector.add.node`,o)]})}),(0,X.jsxs)(`div`,{className:`flex items-center rounded-lg border bg-background/90 shadow-sm backdrop-blur-sm`,children:[(0,X.jsx)(`button`,{type:`button`,title:K(`engine.flowCanvas.zoomOut`,o),"aria-label":K(`engine.flowCanvas.zoomOut`,o),onClick:()=>S(e=>Se(e-.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,X.jsx)(Le,{className:`h-3.5 w-3.5`})}),(0,X.jsxs)(`span`,{className:`w-10 text-center text-[11px] tabular-nums text-muted-foreground`,children:[Math.round(x*100),`%`]}),(0,X.jsx)(`button`,{type:`button`,title:K(`engine.flowCanvas.zoomIn`,o),"aria-label":K(`engine.flowCanvas.zoomIn`,o),onClick:()=>S(e=>Se(e+.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,X.jsx)(It,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,title:K(`engine.flowCanvas.fit`,o),"aria-label":K(`engine.flowCanvas.fit`,o),onClick:Ce,className:`inline-flex h-7 w-7 items-center justify-center border-l text-muted-foreground hover:text-foreground`,children:(0,X.jsx)(Cn,{className:`h-3.5 w-3.5`})})]})]}),(0,X.jsx)(`div`,{ref:b,tabIndex:0,role:`application`,"aria-label":K(`engine.flowCanvas.canvas`,o),onKeyDown:we,onPointerDown:ye,onPointerMove:e=>{be(e),_e(e)},onPointerUp:e=>{xe(e),ve(e)},className:H(`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*x}px ${18*x}px`,backgroundPosition:`${C.x}px ${C.y}px`},children:(0,X.jsxs)(`div`,{className:`relative origin-top-left`,style:{width:F.width,height:F.height,transform:`translate(${C.x}px, ${C.y}px) scale(${x})`},children:[(0,X.jsxs)(`svg`,{className:`pointer-events-none absolute left-0 top-0 overflow-visible`,width:F.width,height:F.height,children:[(0,X.jsxs)(`defs`,{children:[(0,X.jsx)(`marker`,{id:`flow-arrow`,viewBox:`0 0 10 10`,refX:`8`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto-start-reverse`,children:(0,X.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,className:`fill-muted-foreground/55`})}),(0,X.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,X.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,className:`fill-amber-500/80`})}),(0,X.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,X.jsx)(`path`,{d:`M 0 0 L 10 5 L 0 10 z`,className:`fill-destructive`})})]}),t.map((e,t)=>{let i=P.get(e.source),s=P.get(e.target);if(!i||!s)return null;let c=lp(e),l=!c&&!!d?.has(`${e.source}->${e.target}`),u=O?.id===e.source?ue(e.source):i,f=O?.id===e.target?ue(e.target):s,p=c?up(u):ap(u,re.get(e.source)??66),m=c?up(f):op(f),h=c?pp(p,m):cp(p,m),_=hp(e.condition),v=e.isDefault?`else`:_?`if ${_}`:e.label,y=mp(e,t),b=ce.get(km(e.source,e.target)),x=I.has(y),S=a===y,C=c?fp(p,m):sp(p,m),w=r&&!!g;return(0,X.jsxs)(`g`,{"data-invalid":l||void 0,children:[(0,X.jsx)(`path`,{d:C,strokeLinecap:`round`,strokeDasharray:c?`5 4`:void 0,className:H(`fill-none transition-[stroke] duration-150`,x?`stroke-sky-500`:S?`stroke-primary`:l?`stroke-destructive`:c?`stroke-amber-500/70`:oe?`stroke-muted-foreground/20`:`stroke-muted-foreground/40`),strokeWidth:x||S||l?2.5:1.75,markerEnd:l?`url(#flow-arrow-error)`:c?`url(#flow-arrow-back)`:`url(#flow-arrow)`}),w&&(0,X.jsx)(`path`,{d:C,className:`pointer-events-auto cursor-pointer fill-none stroke-transparent`,strokeWidth:14,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),g(e,y)},children:(0,X.jsx)(`title`,{children:l?`${e.source} → ${e.target} — part of an un-declared cycle; mark the edge that closes the loop as a back-edge`:c?`${e.source} ↩ ${e.target} (back-edge)`:`${e.source} → ${e.target}`})}),v&&(0,X.jsx)(`foreignObject`,{x:h.x-60,y:h.y-11,width:120,height:22,className:H(w&&`pointer-events-auto`),children:(0,X.jsx)(`div`,{className:`flex justify-center`,children:(0,X.jsx)(`span`,{onPointerDown:w?e=>e.stopPropagation():void 0,onClick:w?t=>{t.stopPropagation(),g(e,y)}:void 0,className:H(`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`,w&&`cursor-pointer hover:border-primary/60`,S?`border-primary text-primary`:l?`border-destructive/60 text-destructive`:c?`border-amber-500/50 text-amber-600 dark:text-amber-400`:`border-border text-muted-foreground`),children:v})})}),b&&(0,X.jsx)(`foreignObject`,{x:h.x-9,y:h.y-30,width:18,height:18,className:`pointer-events-auto overflow-visible`,children:(0,X.jsx)(`span`,{title:b.title,"data-problem":b.level,className:H(`inline-flex h-[18px] w-[18px] items-center justify-center rounded-full border bg-background shadow-sm`,b.level===`error`?`border-destructive/50 text-destructive`:`border-amber-500/50 text-amber-600 dark:text-amber-400`),children:b.level===`error`?(0,X.jsx)(St,{className:`h-3 w-3`}):(0,X.jsx)(z,{className:`h-3 w-3`})})}),n&&!c&&(0,X.jsx)(`foreignObject`,{x:v?h.x+66:h.x-11,y:h.y-11,width:22,height:22,className:`pointer-events-auto`,children:(0,X.jsx)(`button`,{type:`button`,title:K(`engine.flowCanvas.insertNode`,o),"aria-label":K(`engine.flowCanvas.insertNode`,o),onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),pe(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,X.jsx)(B,{className:`h-3 w-3`})})})]},e.id||`${e.source}-${e.target}-${t}`)})]}),e.map(e=>{let t=s===e.id?`active`:ie.has(e.id)?`visited`:void 0;return(0,X.jsx)(Mp,{id:e.id,locale:o,type:e.type,label:e.label||e.id,summary:Um(e),position:ue(e.id),selected:i===e.id,editable:n,runState:t,dimmed:oe&&!t,onPointerDown:ge(e.id),onSelect:()=>r&&h(e),onAppend:()=>fe(`create_record`,{from:e.id}),onAddReviseLoop:n&&e.type===`approval`&&!he.has(e.id)?()=>me(e.id):void 0,invalid:ae.has(e.id),badge:se.get(e.id),regions:N.get(e.id),expanded:M.has(e.id),onToggleExpand:N.has(e.id)?()=>te(e.id):void 0,height:re.get(e.id),selectedNestedNode:_?.containerId===e.id?{regionKey:_.regionKey,nodeId:_.nodeId}:null,onSelectNestedNode:r&&v?(t,n)=>v({containerId:e.id,regionKey:t,nodeId:n.id},n):void 0},e.id)})]})})]})}function Um(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,a=(e,r)=>{let i=t?.[e];return i&&typeof i==`object`&&!Array.isArray(i)?n(i[r]):void 0};if(e.type===`start`)return i(`condition`)||i(`criteria`)||i(`objectName`)||a(`schedule`,`expression`)||a(`schedule`,`cron`)||i(`cron`)||i(`schedule`)||a(`timeRelative`,`object`)||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 Wm=`nested-node`,Gm=/^(.+?)::(body|try|catch|branch-\d+)::(.+)$/,Km=/^branch-(\d+)$/;function qm(e){return`${e.containerId}::${e.regionKey}::${e.nodeId}`}function Jm(e){let t=Gm.exec(e);return t?{containerId:t[1],regionKey:t[2],nodeId:t[3]}:null}function Ym(e){if(e===`body`||e===`try`||e===`catch`)return{kind:`key`,key:e};let t=Km.exec(e);return t?{kind:`branch`,index:Number(t[1])}:null}function Xm(e,t){if(e===`body`)return`Body`;if(e===`try`)return`Try`;if(e===`catch`)return`Catch`;let n=Km.exec(e);if(n){let e=Number(n[1]),r=t&&typeof t.config==`object`&&t.config?t.config:{},i=(Array.isArray(r.branches)?r.branches:[])[e],a=i&&typeof i==`object`?i.name:void 0;return typeof a==`string`&&a?a:`Branch ${e+1}`}return e}function Zm(e){return Array.isArray(e)?e:[]}function Qm(e){let t=e.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function $m(e){if(!e||typeof e!=`object`||Array.isArray(e))return null;let t=e;return Array.isArray(t.nodes)?t:null}function eh(e,t){return t.kind===`key`?$m(e[t.key]):$m((Array.isArray(e.branches)?e.branches:[])[t.index])}function th(e,t,n,r,i,a){let o=Qm(n),s=eh(o,r);if(!s||i<0||i>=s.nodes.length)return null;let c={...s,nodes:Sa(s.nodes,i,a)},l=r.kind===`key`?{...o,[r.key]:c}:{...o,branches:Sa(Array.isArray(o.branches)?o.branches:[],r.index,c)};return{nodes:Sa(e,t,{...n,config:l})}}function nh(e,t){let n=Zm(e.nodes);if(t.kind===`nested-node`){let e=Jm(t.id),r=e?Ym(e.regionKey):null;if(!e||!r)return null;let i=n.findIndex(t=>t?.id===e.containerId),a=i>=0?n[i]:null;if(!a)return null;let o=eh(Qm(a),r),s=o?o.nodes.findIndex(t=>t?.id===e.nodeId):-1,c=o&&s>=0?o.nodes[s]:null;return c?{node:c,nested:!0,scopeAnchorId:a.id,container:a,regionLabel:Xm(e.regionKey,a),write:e=>th(n,i,a,r,s,e)}:null}let r=n.findIndex(e=>e?.id===t.id),i=r>=0?n[r]:null;return i?{node:i,nested:!1,scopeAnchorId:i.id,write:e=>({nodes:Sa(n,r,e)})}:null}var rh=500,ih=new Set([`start`]),ah=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`]),oh=new Set([`join_gateway`,`subflow`,`boundary_event`,`parallel`,`try_catch`]),sh=(e,t)=>e.id||`${e.source}->${e.target}#${t}`,ch=e=>typeof e==`string`?e:void 0,lh=e=>typeof e==`string`&&e?e:void 0,uh=class{nodes=new Map;edges=[];mocks={};seq=0;state={status:`idle`,variables:{},steps:[],frontier:[],activeNodeId:null,visitedNodeIds:[],traversedEdgeIds:[]};locale;constructor(e,t,n){for(let t of e)this.nodes.set(t.id,t);this.edges=t,this.locale=n}reset(e={},t={}){let n=Up([...this.nodes.values()],this.edges,this.locale);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>=rh)return e.status=`error`,e.error=`Step limit (${rh}) 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(oh.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(ah.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:ih.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=ch(e.condition);if(!t){n.push({edgeId:sh(e,a),target:e.target,result:!1,selected:!1,error:`Branch has no condition.`});continue}let o=Vp(t,this.state.variables);o.error&&!i&&(i=`${t}: ${o.error}`);let s=o.result&&!r;s&&(r={e,i:a}),n.push({edgeId:sh(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:sh(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=lh(e.config?.collection),n=lh(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=lh(t.outputVariable);return i&&(r[i]=n===void 0?{}:n,this.state.variables[i]=r[i]),Object.keys(r).length?r:void 0}mockNote(e){if(e.type===`script`){let t=lh(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=sh(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 dh(e,t){return e?t?e.replace(/\{([^{}]+)\}/g,(e,n)=>{let r=t[String(n).trim()];return r==null?e:String(r)}):e:``}function fh(e,t){if(typeof e!=`string`||!e.trim()||!t)return!0;let{result:n,error:r}=Vp(e.replace(/\{([\w.]+)\}/g,`$1`),t);return r?!0:n}function ph(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||fh(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 mh(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||fh(n.visibleWhen,t)||r++}return r}function hh(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:ph(n.fields,t),kind:r?`object-form`:`fields`,objectName:r,mode:i,defaults:a,idVariable:typeof n.idVariable==`string`?n.idVariable:void 0}}function gh({node:e,variables:t,className:n}){let r=k(),i=A(),a=Z.useMemo(()=>hh(e,t),[e,t]),o=Ci(a),s=o?i.objects:void 0,c=dh(a.title,t),l=dh(a.description,t),u=o?0:mh(e,t),d=o?`obj:${a.objectName}:${a.mode??`create`}`:`fields:`+vi(a).map(e=>`${e.name}:${e.type??``}:${+!!e.required}`).join(`|`),f=!c&&!l&&!o&&vi(a).length===0&&u===0;return(0,X.jsxs)(`div`,{className:H(`overflow-hidden rounded-md border bg-background`,n),children:[(0,X.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,X.jsx)(`div`,{className:`max-h-[60vh] overflow-auto p-4`,children:f?(0,X.jsx)(`p`,{className:`text-sm italic text-muted-foreground`,children:`Add a title, description, fields, or an object form to preview this screen.`}):(0,X.jsxs)(X.Fragment,{children:[c&&(0,X.jsx)(`h3`,{className:`text-base font-semibold leading-tight`,children:c}),l&&(0,X.jsx)(`p`,{className:H(`whitespace-pre-line text-sm text-muted-foreground`,c&&`mt-1`),children:l}),(0,X.jsx)(_h,{spec:a,adapter:r,objects:s},d),!o&&u>0&&(0,X.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&&vi(a).length>0&&(0,X.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,X.jsx)(W,{size:`sm`,disabled:!0,children:`Submit`})})]})})]})}function _h({spec:e,adapter:t,objects:n}){let[r,i]=Z.useState(()=>hi(e));return(0,X.jsx)(wi,{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 vh(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 yh=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`,`script`]);function bh(e){let t=[];for(let n of e){if(!yh.has(n.type))continue;let e=n.config??{},r=[];typeof e.outputVariable==`string`&&e.outputVariable&&r.push(e.outputVariable),t.push({id:n.id,label:n.label||n.id,type:n.type,outputs:r})}return t}var xh={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 Sh({nodes:e,edges:t,variables:n,locale:r,onRunStateChange:i}){let a=Z.useRef(null),[o,s]=Z.useState(null),[c,l]=Z.useState(null),u=Z.useMemo(()=>n.filter(e=>e.isInput),[n]),d=Z.useMemo(()=>bh(e),[e]),[f,p]=Z.useState({}),[m,h]=Z.useState([]),[g,_]=Z.useState({}),v=Z.useCallback(()=>{let e=a.current;if(!e)return;let t=e.state;s({...t,steps:[...t.steps],variables:{...t.variables},frontier:[...t.frontier],visitedNodeIds:[...t.visitedNodeIds],traversedEdgeIds:[...t.traversedEdgeIds]}),i?.({activeNodeId:t.activeNodeId,visitedNodeIds:[...t.visitedNodeIds],traversedEdgeIds:[...t.traversedEdgeIds]})},[i]),y=Z.useCallback(()=>{let e={};for(let t of u){let n=f[t.name],r=n==null?void 0:vh(n);e[t.name]=r===void 0?t.defaultValue:r}for(let t of m){let n=t.k.trim();n&&(e[n]=vh(t.v))}return e},[u,f,m]),b=Z.useCallback(()=>{let e={};for(let[t,n]of Object.entries(g))n!=null&&n.trim()!==``&&(e[t]=vh(n));return e},[g]),x=Z.useCallback(()=>{let n=new uh(e,t,r);a.current=n,l(n.reset(y(),b())),v()},[e,t,y,b,v,r]),S=Z.useCallback(()=>(a.current||x(),a.current),[x]),C=()=>{let e=a.current;if(e&&e.state.status===`paused`){if(e.state.pausedReason===`approval`){v();return}e.resume()}else x(),e=a.current;e.runToEnd(),v()},w=()=>{S().step(),v()},T=()=>E(),E=e=>{let t=S();t.resume(e?{decision:e}:{}),t.runToEnd(),v()},D=()=>{a.current=null,s(null),l(null),i?.(null)},O=o?.status??`idle`,k=(c?.errors.length??0)>0,A=Z.useMemo(()=>{if(o?.status!==`paused`||o.pausedReason!==`screen`||!o.activeNodeId)return null;let t=e.find(e=>e.id===o.activeNodeId);return t?{node:t,variables:o.variables}:null},[o,e]),j=Z.useMemo(()=>{if(o?.status!==`paused`||o.pausedReason!==`approval`||!o.activeNodeId)return null;let n=e.find(e=>e.id===o.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},[o,e,t]);return(0,X.jsxs)(`div`,{className:`flex h-full flex-col text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b bg-muted/30 px-3 py-2`,children:[(0,X.jsxs)(W,{size:`sm`,className:`h-7 gap-1 px-2`,onClick:C,disabled:k,children:[(0,X.jsx)(Gr,{className:`h-3.5 w-3.5`}),` `,K(`engine.flowSim.run`,r)]}),(0,X.jsxs)(W,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:w,disabled:k||O===`done`||O===`error`,children:[(0,X.jsx)(Se,{className:`h-3.5 w-3.5`}),` `,K(`engine.flowSim.step`,r)]}),O===`paused`&&(j&&j.decisions.length>0?(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:j.decisions.map(e=>(0,X.jsxs)(W,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2 capitalize`,onClick:()=>E(e),title:G(`engine.flowSim.resumeBranch`,r,{branch:e}),children:[(0,X.jsx)(Vn,{className:`h-3.5 w-3.5`}),` `,e]},e))}):(0,X.jsxs)(W,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:T,children:[(0,X.jsx)(Vn,{className:`h-3.5 w-3.5`}),` `,K(`engine.flowSim.continue`,r)]})),(0,X.jsxs)(W,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-muted-foreground`,onClick:D,children:[(0,X.jsx)(sr,{className:`h-3.5 w-3.5`}),` `,K(`engine.flowSim.reset`,r)]}),(0,X.jsx)(`span`,{className:H(`ml-auto rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase`,xh[O===`idle`||O===`running`?`ok`:O]??`bg-muted`),children:K(`engine.flowSim.status.${O}`,r)})]}),(0,X.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-3 overflow-auto p-3`,children:[c&&(c.errors.length>0||c.warnings.length>0)&&(0,X.jsxs)(`div`,{className:`space-y-1`,children:[c.errors.map((e,t)=>(0,X.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,X.jsx)(St,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,X.jsx)(`span`,{children:e.message})]},`e${t}`)),c.warnings.map((e,t)=>(0,X.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,X.jsx)(z,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,X.jsx)(`span`,{children:e.message})]},`w${t}`))]}),A&&(0,X.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:K(`engine.flowSim.screen`,r)}),(0,X.jsx)(gh,{node:A.node,variables:A.variables})]}),u.length>0&&(0,X.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:K(`engine.flowSim.inputs`,r)}),u.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(V,{className:`w-24 shrink-0 truncate font-mono text-[11px]`,title:e.name,children:e.name}),(0,X.jsx)(R,{value:f[e.name]??(e.defaultValue==null?``:String(e.defaultValue)),onChange:t=>p(n=>({...n,[e.name]:t.target.value})),placeholder:e.type??K(`engine.flowSim.valuePlaceholder`,r),className:`h-7 flex-1 text-xs`})]},e.name))]}),(0,X.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:K(`engine.flowSim.setVariables`,r)}),(0,X.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:()=>h(e=>[...e,{k:``,v:``}]),children:[(0,X.jsx)(B,{className:`h-3 w-3`}),` `,K(`engine.flowSim.add`,r)]})]}),m.length===0?(0,X.jsx)(`div`,{className:`italic text-muted-foreground`,children:K(`engine.flowSim.setVariablesHint`,r)}):m.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(R,{value:e.k,onChange:e=>h(n=>n.map((n,r)=>r===t?{...n,k:e.target.value}:n)),placeholder:K(`engine.flowSim.namePlaceholder`,r),className:`h-7 w-24 shrink-0 font-mono text-[11px]`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`=`}),(0,X.jsx)(R,{value:e.v,onChange:e=>h(n=>n.map((n,r)=>r===t?{...n,v:e.target.value}:n)),placeholder:K(`engine.flowSim.valuePlaceholder`,r),className:`h-7 flex-1 text-xs`}),(0,X.jsx)(`button`,{type:`button`,className:`shrink-0 rounded p-1 text-muted-foreground hover:bg-muted/50 hover:text-rose-600`,onClick:()=>h(e=>e.filter((e,n)=>n!==t)),"aria-label":K(`engine.flowSim.removeVariable`,r),children:(0,X.jsx)(gn,{className:`h-3 w-3`})})]},t))]}),d.length>0&&(0,X.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:K(`engine.flowSim.mockOutputs`,r)}),d.map(e=>(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(V,{className:`flex items-baseline gap-1.5 text-[11px]`,title:e.id,children:[(0,X.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-muted-foreground`,children:e.type.replace(/_/g,` `)}),e.outputs.length>0&&(0,X.jsxs)(`span`,{className:`truncate font-mono text-[10px] text-violet-600`,children:[`→ `,e.outputs.join(`, `)]})]}),(0,X.jsx)(R,{value:g[e.id]??``,onChange:t=>_(n=>({...n,[e.id]:t.target.value})),placeholder:e.type===`script`&&e.outputs.length?`{ "${e.outputs[0]}": … }`:K(`engine.flowSim.mockPlaceholder`,r),className:`h-7 w-full font-mono text-[11px]`})]},e.id))]}),o&&(0,X.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:K(`engine.flowSim.variables`,r)}),Object.keys(o.variables).length===0?(0,X.jsx)(`div`,{className:`italic text-muted-foreground`,children:K(`engine.flowSim.noVars`,r)}):(0,X.jsx)(`ul`,{className:`space-y-1`,children:Object.entries(o.variables).map(([e,t])=>(0,X.jsxs)(`li`,{className:`flex items-baseline gap-1.5 rounded border bg-background px-1.5 py-1`,children:[(0,X.jsx)(`span`,{className:`font-mono text-[11px]`,children:e}),(0,X.jsxs)(`span`,{className:`truncate font-mono text-[10px] text-muted-foreground`,children:[`= `,typeof t==`object`?JSON.stringify(t):String(t)]})]},e))})]}),o&&o.steps.length>0&&(0,X.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,X.jsx)(`div`,{className:`font-medium text-muted-foreground`,children:K(`engine.flowSim.timeline`,r)}),(0,X.jsx)(`ol`,{className:`space-y-1`,children:o.steps.map(e=>(0,X.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.seq+1}),(0,X.jsx)(`span`,{className:`truncate font-medium`,children:e.label}),(0,X.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type}),(0,X.jsx)(`span`,{className:H(`ml-auto rounded px-1 py-0.5 text-[9px] font-semibold uppercase`,xh[e.status]),children:e.status})]}),e.note&&(0,X.jsx)(`div`,{className:`mt-0.5 text-[10px] text-muted-foreground`,children:e.note}),e.error&&(0,X.jsx)(`div`,{className:`mt-0.5 text-[10px] text-rose-600`,children:e.error}),e.wrote&&(0,X.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,X.jsx)(`ul`,{className:`mt-0.5 space-y-0.5`,children:e.edges.map(e=>(0,X.jsxs)(`li`,{className:`space-y-0.5`,children:[(0,X.jsxs)(`div`,{className:H(`flex items-center gap-1 font-mono text-[10px]`,e.selected?`text-sky-700`:`text-muted-foreground`),children:[(0,X.jsx)(`span`,{children:e.selected?`▶`:`·`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.isDefault?`else`:e.condition}),(0,X.jsx)(`span`,{className:H(`ml-auto`,e.error&&`text-rose-600`),children:e.error?`error`:e.result?`true`:`false`})]}),e.error&&(0,X.jsx)(`div`,{className:`pl-3 text-[10px] text-rose-600`,children:e.error})]},e.edgeId))})]},e.seq))})]}),!o&&!k&&(0,X.jsx)(`p`,{className:`italic text-muted-foreground`,children:K(`engine.flowSim.idleHint`,r)})]})]})}function Ch(e){if(!e)return;if(typeof e==`string`)return e||void 0;let t=e.message;return typeof t==`string`&&t?t:void 0}function wh(e){let t=[],n=[];for(let r of e){let e={step:r,children:[]};if(r.parentNodeId==null)n.length=0,t.push(e);else{for(;n.length>0&&n[n.length-1].step.nodeId!==r.parentNodeId;)n.pop();n.length>0?n[n.length-1].children.push(e):t.push(e)}n.push(e)}return t}function Th(e,t){let{regionKind:n,iteration:r}=e;if(!n)return null;switch(n){case`loop-body`:return r==null?K(`engine.flowRuns.iteration`,t):G(`engine.flowRuns.iterationN`,t,{n:r+1});case`parallel-branch`:return r==null?K(`engine.flowRuns.branch`,t):G(`engine.flowRuns.branchN`,t,{n:r+1});case`try`:return K(`engine.flowRuns.try`,t);case`catch`:return K(`engine.flowRuns.catch`,t);default:return r==null?n:`${n} ${r+1}`}}function Eh(e){return`${e.regionKind??``}#${e.iteration??``}`}function Dh(e,t){let n=[],r;for(let i of e){let e=Eh(i.step);n.length===0||e!==r?(n.push({label:Th(i.step,t),items:[i]}),r=e):n[n.length-1].items.push(i)}return n}async function Oh(e,t){try{let n=await fetch(`${Fp()}/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 kh={completed:{icon:Jt,cls:`text-emerald-600 dark:text-emerald-400`,labelKey:`engine.flowRuns.status.completed`},failed:{icon:St,cls:`text-rose-600 dark:text-rose-400`,labelKey:`engine.flowRuns.status.failed`},paused:{icon:Dr,cls:`text-amber-600 dark:text-amber-400`,labelKey:`engine.flowRuns.status.paused`},running:{icon:U,cls:`text-sky-600 dark:text-sky-400`,labelKey:`engine.flowRuns.status.running`},cancelled:{icon:tt,cls:`text-muted-foreground`,labelKey:`engine.flowRuns.status.cancelled`}};function Ah(e,t){let n=kh[e];return n?{icon:n.icon,cls:n.cls,label:K(n.labelKey,t)}:{icon:vt,cls:`text-muted-foreground`,label:e}}function jh(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function Mh(e){return e==null?null:e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/6e4)}m`}function Nh({step:e,depth:t=0}){let n=e.status===`success`?`text-emerald-600 dark:text-emerald-400`:e.status===`failure`?`text-rose-600 dark:text-rose-400`:`text-muted-foreground`,r=Ch(e.error),i=Array.isArray(e.warnings)?e.warnings.filter(e=>typeof e==`string`&&e.length>0):[];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`li`,{className:`flex items-baseline gap-1.5 py-0.5`,style:t?{paddingLeft:t*12}:void 0,children:[(0,X.jsx)(`span`,{className:H(`shrink-0 text-[9px] font-semibold uppercase`,n),children:e.status}),(0,X.jsx)(`span`,{className:`truncate font-mono text-[10px]`,title:e.nodeId,children:e.nodeId}),e.nodeType&&(0,X.jsx)(`span`,{className:`shrink-0 text-[9px] uppercase text-muted-foreground`,children:e.nodeType}),i.length>0&&(0,X.jsx)(z,{"aria-hidden":!0,className:`h-2.5 w-2.5 shrink-0 text-amber-600 dark:text-amber-400`}),Mh(e.durationMs)&&(0,X.jsx)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground`,children:Mh(e.durationMs)}),r&&(0,X.jsx)(`span`,{className:`min-w-0 truncate text-[9px] text-rose-600`,title:r,children:r})]}),i.map((e,n)=>(0,X.jsxs)(`li`,{className:`flex items-baseline gap-1 py-0.5 text-amber-700 dark:text-amber-400`,style:{paddingLeft:(t+1)*12},children:[(0,X.jsx)(z,{"aria-hidden":!0,className:`h-2.5 w-2.5 shrink-0 self-center`}),(0,X.jsx)(`span`,{className:`min-w-0 break-words text-[9px]`,title:e,children:e})]},n))]})}function Ph({label:e,depth:t}){return(0,X.jsxs)(`li`,{className:`flex items-center gap-1 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-muted-foreground/80`,style:{paddingLeft:t*12},children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`text-muted-foreground/50`,children:`↳`}),e]})}function Fh({node:e,depth:t,locale:n}){let r=e.children.length>0?Dh(e.children,n):[];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Nh,{step:e.step,depth:t}),r.map((e,r)=>(0,X.jsxs)(Z.Fragment,{children:[e.label!=null&&(0,X.jsx)(Ph,{label:e.label,depth:t+1}),e.items.map((r,i)=>(0,X.jsx)(Fh,{node:r,depth:e.label==null?t+1:t+2,locale:n},`${r.step.nodeId}#${i}`))]},r))]})}function Ih({run:e,locale:t}){let[n,r]=Z.useState(!1),i=Ah(e.status,t),a=i.icon,o=Array.isArray(e.steps)?e.steps:[],s=Ch(e.error);return(0,X.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-1.5 p-1.5 text-left`,"aria-expanded":n,children:[n?(0,X.jsx)(pr,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,X.jsx)(Vn,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,X.jsx)(a,{className:H(`h-3.5 w-3.5 shrink-0`,i.cls,e.status===`running`&&`animate-spin`)}),(0,X.jsx)(`span`,{className:H(`shrink-0 text-[10px] font-semibold`,i.cls),children:i.label}),(0,X.jsx)(`span`,{className:`min-w-0 truncate text-[10px] text-muted-foreground`,title:e.id,children:jh(e.startedAt)}),Mh(e.durationMs)&&(0,X.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] text-muted-foreground`,children:Mh(e.durationMs)})]}),n&&(0,X.jsxs)(`div`,{className:`border-t px-2 py-1.5`,children:[(0,X.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}`]}),s&&(0,X.jsx)(`div`,{className:`pb-1 text-[10px] text-rose-600`,children:s}),o.length===0?(0,X.jsx)(`div`,{className:`text-[10px] italic text-muted-foreground`,children:K(`engine.flowRuns.noSteps`,t)}):(0,X.jsx)(`ul`,{children:wh(o).map((e,n)=>(0,X.jsx)(Fh,{node:e,depth:0,locale:t},`${e.step.nodeId}#${n}`))})]})]})}function Lh({flowName:e,locale:t}){let[n,r]=Z.useState([]),[i,a]=Z.useState(`loading`),[o,s]=Z.useState(0);return Z.useEffect(()=>{let t=new AbortController,n=!0;return a(`loading`),(async()=>{let i=await Oh(e,t.signal);n&&(i===null?a(`unavailable`):(r(i),a(`ready`)))})(),()=>{n=!1,t.abort()}},[e,o]),(0,X.jsxs)(`div`,{className:`flex h-full flex-col p-3 text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-2 font-medium text-muted-foreground`,children:[(0,X.jsx)(vt,{className:`h-3 w-3`}),` `,K(`engine.flowRuns.title`,t),(0,X.jsx)(`button`,{type:`button`,onClick:()=>s(e=>e+1),title:K(`engine.flowRuns.refresh`,t),"aria-label":K(`engine.flowRuns.refresh`,t),className:`ml-auto rounded p-0.5 text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground`,children:(0,X.jsx)(Mr,{className:H(`h-3 w-3`,i===`loading`&&`animate-spin`)})})]}),i===`unavailable`?(0,X.jsx)(`div`,{className:`italic text-muted-foreground`,children:K(`engine.flowRuns.unavailable`,t)}):i===`ready`&&n.length===0?(0,X.jsx)(`div`,{className:`italic text-muted-foreground`,children:K(`engine.flowRuns.empty`,t)}):(0,X.jsx)(`ul`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto`,children:n.map(e=>(0,X.jsx)(Ih,{run:e,locale:t},e.id))})]})}function Rh(e){return e.target.kind===`node`?e.target.nodeId:e.target.kind===`edge`?`${e.target.source} → ${e.target.target}`:`flow`}function zh({problems:e,selectedKey:t,onSelectProblem:n,locale:r}){let i=e.filter(e=>e.level===`error`).length,a=e.length-i;return(0,X.jsxs)(`div`,{className:`flex h-full flex-col text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-2 font-medium text-muted-foreground`,children:[(0,X.jsx)(`span`,{children:K(`engine.flowProblems.title`,r)}),i>0&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,X.jsx)(St,{className:`h-3 w-3`}),` `,i]}),a>0&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-amber-600 dark:text-amber-400`,children:[(0,X.jsx)(z,{className:`h-3 w-3`}),` `,a]})]}),e.length===0?(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-1.5 p-4 text-center text-muted-foreground`,children:[(0,X.jsx)(Jt,{className:`h-5 w-5 text-emerald-500`}),(0,X.jsx)(`span`,{children:K(`engine.flowProblems.empty`,r)})]}):(0,X.jsx)(`ul`,{className:`flex-1 overflow-auto p-1.5`,children:e.map(e=>{let i=e.target.kind===`edge`,a=e.target.kind===`flow`,o=e.target.kind===`node`?`node:${e.target.nodeId}`:e.target.kind===`edge`?e.target.edgeKey:null,s=!!o&&o===t,c=e.level===`error`?St:z,l=i?Ie:qe;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,disabled:a,onClick:()=>n(e),className:H(`flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors`,a?`cursor-default`:`cursor-pointer hover:bg-accent`,s&&`bg-accent ring-1 ring-primary/40`),children:[(0,X.jsx)(c,{className:H(`mt-0.5 h-3.5 w-3.5 shrink-0`,e.level===`error`?`text-destructive`:`text-amber-500`)}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block leading-snug text-foreground`,children:e.message}),(0,X.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1 text-[10px] text-muted-foreground`,children:[(0,X.jsx)(l,{className:`h-2.5 w-2.5 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate font-mono`,children:Rh(e)}),e.source===`server`&&(0,X.jsxs)(`span`,{className:`uppercase tracking-wide`,children:[`· `,K(`engine.flowProblems.sourceSchema`,r)]}),e.source===`expression`&&(0,X.jsxs)(`span`,{className:`uppercase tracking-wide`,children:[`· `,K(`engine.flowProblems.sourceExpression`,r)]})]})]})]})},e.id)})})]})}function Bh({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a,diagnostics:o}){let s=e,c=Z.useMemo(()=>Array.isArray(s.nodes)?s.nodes:[],[s.nodes]),l=Z.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=Z.useMemo(()=>n&&n.kind===`nested-node`?Jm(n.id):null,[n]),[g,_]=Z.useState(!1),[v,y]=Z.useState(!1),[b,x]=Z.useState(!1),[S,C]=Z.useState(!1),[w,T]=Z.useState(null),E=Z.useMemo(()=>Fm({nodes:c,edges:l,serverDiagnostics:o,variables:u,locale:a}),[c,l,o,s.variables,a]),D=E.filter(e=>e.level===`error`).length,{invalidNodeIds:O,invalidEdges:k}=Z.useMemo(()=>Rm(E),[E]),[A,j]=Z.useState(null),M=p?`node:${p}`:m??null,ee=Z.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}`});j(t=>({target:e.target,nonce:(t?.nonce??0)+1}))},[c,r]),te=Z.useCallback(()=>{if(!f)return;let e={id:qi(`node`,c.map(e=>e.id).filter(Boolean)),type:`start`,label:Ap(`start`,a)};i({nodes:Xi(c,e)}),r?.({kind:`node`,id:e.id,label:e.label||e.id})},[f,c,i,r,a]),N=typeof s.name==`string`&&s.name?s.name:``,ne=String(s.type??`autolaunched`),P=String(s.status??(s.active?`active`:`draft`)),re=String(s.runAs??`user`),F=s.version==null?void 0:String(s.version),ie=s.errorHandling?.strategy;return c.length===0?(0,X.jsx)(Q,{hint:`flow${d?` · design`:``}`,children:f?(0,X.jsx)(`div`,{className:`p-3`,children:(0,X.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,X.jsx)(B,{className:`h-3 w-3`}),K(`engine.inspector.add.node`,a)]})}):(0,X.jsx)(Qu,{children:K(`engine.flowPreview.emptyHint`,a)})}):(0,X.jsx)(Q,{hint:`flow · ${c.length} node${c.length===1?``:`s`}`,children:(0,X.jsx)(ed,{fallbackHint:K(`engine.flowPreview.malformed`,a),children:(0,X.jsxs)(`div`,{className:`grid gap-0 h-full min-h-[440px] `+(g||v||b||S?`lg:grid-cols-[1fr_240px]`:`grid-cols-1`),children:[(0,X.jsxs)(`div`,{className:`flex flex-col min-w-0 min-h-0`,children:[(0,X.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,X.jsx)(Vh,{icon:Ht,label:K(`engine.flowPreview.pill.trigger`,a),value:Li(`type`,ne,a)}),(0,X.jsx)(Vh,{icon:qe,label:K(`engine.flowPreview.pill.status`,a),value:Li(`status`,P,a),tone:P===`active`?`green`:P===`draft`?`gray`:`amber`}),(0,X.jsx)(Vh,{icon:Xe,label:K(`engine.flowPreview.pill.runAs`,a),value:Li(`runAs`,re,a)}),F&&(0,X.jsx)(Vh,{label:`v`,value:F}),ie&&(0,X.jsx)(Vh,{icon:Ie,label:K(`engine.flowPreview.pill.onError`,a),value:Li(`onError`,ie,a)}),(0,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[!g&&!b&&!S&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>y(e=>!e),className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(v?`border-violet-500 bg-violet-50 text-violet-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),title:K(v?`engine.flowPreview.hideVars`:`engine.flowPreview.showVars`,a),children:[(0,X.jsx)(Kn,{className:`h-3 w-3`}),` `,K(`engine.flowPreview.variables`,a)]}),N&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{x(e=>!e),_(!1),C(!1)},className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(b?`border-emerald-500 bg-emerald-50 text-emerald-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),title:K(`engine.flowPreview.runsTitle`,a),children:[(0,X.jsx)(at,{className:`h-3 w-3`}),` `,K(`engine.flowPreview.runs`,a)]}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{C(e=>!e),_(!1),x(!1)},className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(S?`border-rose-500 bg-rose-50 text-rose-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),title:K(`engine.flowPreview.problemsTitle`,a),children:[(0,X.jsx)(St,{className:`h-3 w-3`}),` `,K(`engine.flowPreview.problems`,a),E.length>0&&(0,X.jsx)(`span`,{className:`ml-0.5 inline-flex min-w-[16px] items-center justify-center rounded-full px-1 text-[10px] font-semibold `+(D>0?`bg-destructive/15 text-destructive`:`bg-amber-500/15 text-amber-600`),children:E.length})]}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{_(e=>!e),x(!1),C(!1)},className:`inline-flex items-center gap-1 rounded border px-2 py-0.5 text-[11px] font-medium transition-colors `+(g?`border-sky-500 bg-sky-50 text-sky-700`:`border-border text-muted-foreground hover:bg-muted/50 hover:text-foreground`),children:[(0,X.jsx)(an,{className:`h-3 w-3`}),` `,K(`engine.flowPreview.debug`,a)]})]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,X.jsx)(Hm,{nodes:c,edges:l,editable:f,designMode:d,selectedId:p,selectedEdgeId:m,locale:a,activeNodeId:w?.activeNodeId??null,visitedNodeIds:w?.visitedNodeIds,traversedEdgeIds:w?.traversedEdgeIds,invalidNodeIds:O,invalidEdges:k,onRevealProblem:ee,problems:E,revealSignal:A,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),selectedNestedPath:h,onSelectNested:(e,t)=>e?r?.({kind:Wm,id:qm(e),label:t?.label||e.nodeId}):r?.(null),onPatch:i})})]}),S?(0,X.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,X.jsx)(zh,{problems:E,selectedKey:M,onSelectProblem:ee,locale:a})}):g?(0,X.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,X.jsx)(Sh,{nodes:c,edges:l,variables:u,locale:a,onRunStateChange:T})}):b&&N?(0,X.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,X.jsx)(Lh,{flowName:N,locale:a})}):v?(0,X.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-muted-foreground`,children:[(0,X.jsx)(I,{className:`h-3 w-3`}),` `,K(`engine.flowPreview.variables`,a)]}),u.length===0?(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:K(`engine.flowPreview.noVars`,a)}):(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:u.map((e,t)=>(0,X.jsxs)(`li`,{className:`rounded border bg-background p-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-1 flex-wrap`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e.name}),e.type&&(0,X.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:e.type}),e.isInput&&(0,X.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-sky-100 text-sky-700`,children:`in`}),e.isOutput&&(0,X.jsx)(`span`,{className:`text-[9px] font-semibold uppercase px-1 rounded bg-emerald-100 text-emerald-700`,children:`out`})]}),e.defaultValue!==void 0&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground font-mono truncate`,children:[`= `,String(e.defaultValue)]})]},e.name||t))})]}):null]})})})}function Vh({icon:e,label:t,value:n,tone:r=`gray`}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[t,`:`]}),(0,X.jsx)(`span`,{className:`font-medium ${r===`green`?`text-emerald-700`:r===`amber`?`text-amber-700`:`text-foreground`}`,children:n})]})}function Hh({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=n.model??{},u=Array.isArray(n.skills)?n.skills:[],d=Array.isArray(n.tools)?n.tools:[],f=n.knowledge,p=n.planning,m=n.memory,h=n.guardrails,g=Array.isArray(n.permissions)?n.permissions:[];if(!r&&!s&&u.length===0&&d.length===0)return(0,X.jsx)(Q,{hint:`agent`,children:(0,X.jsx)(Qu,{children:`Fill in label, role, and instructions in the Form tab to see the agent preview.`})});let _=r?`/console/ai/agents/${encodeURIComponent(r)}/chat`:null;return(0,X.jsx)(Q,{hint:`agent`,toolbar:_&&(0,X.jsxs)(`a`,{href:_,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,X.jsx)(Rn,{className:`h-3 w-3`})]}),children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`grid lg:grid-cols-[1fr_240px] gap-0`,children:[(0,X.jsxs)(`div`,{className:`p-3 space-y-3 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 flex items-start gap-3`,children:[(0,X.jsx)(`div`,{className:`h-10 w-10 rounded-full bg-background border flex items-center justify-center shrink-0 overflow-hidden`,children:o?(0,X.jsx)(`img`,{src:o,alt:``,className:`h-full w-full object-cover`}):(0,X.jsx)(xe,{className:`h-5 w-5 text-muted-foreground`})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(Zh,{icon:c?Sr:or,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),l.provider&&(0,X.jsx)(Zh,{icon:gt,label:`${l.provider}${l.model?` · ${l.model}`:``}`,mono:!0}),l.temperature!=null&&(0,X.jsx)(Zh,{icon:Ft,label:`temp ${l.temperature}`}),l.maxTokens!=null&&(0,X.jsx)(Zh,{label:`max ${l.maxTokens}t`})]})]})]}),(0,X.jsx)(Wh,{title:`Instructions`,icon:qt,children:s?(0,X.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,X.jsx)(Gh,{children:`No system prompt set yet.`})}),(0,X.jsx)(Wh,{title:`Capabilities`,icon:Er,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(qh,{label:`Skills`,emptyHint:`Attach skills (preferred)`,items:u.map(e=>({key:e,label:e})),icon:gt,tone:`violet`,mono:!0}),(0,X.jsx)(qh,{label:`Tools`,emptyHint:`No direct tools (skills can provide them)`,items:d.map((e,t)=>({key:`${e.type??``}:${e.name??t}`,label:e.name??String(e),hint:e.type})),icon:Er,tone:`blue`,mono:!0})]})}),f&&Object.keys(f).length>0&&(0,X.jsx)(Wh,{title:`Knowledge (RAG)`,icon:ge,children:(0,X.jsx)(Uh,{knowledge:f})})]}),(0,X.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-3`,children:[p&&Object.keys(p).length>0&&(0,X.jsx)(Jh,{icon:Dt,title:`Planning`,children:(0,X.jsx)(Yh,{data:p,keys:[`maxIterations`]})}),m&&Object.keys(m).length>0&&(0,X.jsx)(Jh,{icon:Ye,title:`Memory`,children:(0,X.jsx)(Yh,{data:{"short.maxMessages":m.shortTerm?.maxMessages,"long.enabled":m.longTerm?.enabled,"long.store":m.longTerm?.store},keys:[`short.maxMessages`,`long.enabled`,`long.store`]})}),h&&Object.keys(h).length>0&&(0,X.jsx)(Jh,{icon:ci,title:`Guardrails`,children:(0,X.jsx)(Yh,{data:h,keys:Object.keys(h).slice(0,6)})}),g.length>0&&(0,X.jsx)(Jh,{icon:hr,title:`Permissions`,children:(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:g.map(e=>(0,X.jsx)(`li`,{className:`font-mono`,children:e},e))})}),!p&&!m&&!h&&g.length===0&&(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Defaults in use.`})]})]})})})}function Uh({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,X.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono`,children:t.length?t.join(`, `):`configured`})}return(0,X.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,X.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,X.jsx)(ge,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono`,children:String(r)}),i&&(0,X.jsx)(`span`,{className:`text-[10px] uppercase text-muted-foreground`,children:i})]},t)})})}function Wh({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function Gh({children:e}){return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}var Kh={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 qh({label:e,emptyHint:t,items:n,icon:r,tone:i,mono:a=!1}){let o=i?Kh[i]:null;return(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:e}),n.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:t}):(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:n.map(e=>(0,X.jsxs)(`span`,{className:H(`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,X.jsx)(r,{className:H(`h-3 w-3 shrink-0`,o?.icon)}),e.label,e.hint&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase opacity-70`,children:e.hint})]},e.key))})]})}function Jh({icon:e,title:t,children:n}){return(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[10px] uppercase text-muted-foreground tracking-wider mb-1`,children:[(0,X.jsx)(e,{className:`h-3 w-3`}),` `,t]}),n]})}function Yh({data:e,keys:t}){let n=t.map(t=>[t,Xh(e,t)]).filter(([,e])=>e!=null);return n.length===0?(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`—`}):(0,X.jsx)(`dl`,{className:`space-y-0.5`,children:n.map(([e,t])=>(0,X.jsxs)(`div`,{className:`flex justify-between gap-2`,children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground font-mono truncate`,children:e}),(0,X.jsx)(`dd`,{className:`font-mono text-right truncate`,children:String(t)})]},e))})}function Xh(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function Zh({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function Qh(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function $h(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${$h(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function eg(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 tg({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=Qh(d)?d.properties??{}:{},m=new Set(Array.isArray(d.required)?d.required:[]),h=Z.useMemo(()=>{let e={};for(let t of m)p[t]&&(e[t]=eg(p[t]));if(Object.keys(e).length===0){let t=Object.keys(p)[0];t&&(e[t]=eg(p[t]))}return e},[p,m]);return!r&&!a&&Object.keys(p).length===0?(0,X.jsx)(Q,{hint:`tool`,children:(0,X.jsx)(Qu,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,X.jsx)(Q,{hint:`tool`,toolbar:r&&(0,X.jsxs)(`a`,{href:`/developer/api-console?path=/api/v1/ai/tools/${encodeURIComponent(r)}/execute`,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,X.jsx)(Rn,{className:`h-3 w-3`})]}),children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3 space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Er,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[o&&(0,X.jsx)(ag,{icon:on,label:o}),s&&(0,X.jsx)(ag,{icon:ge,label:s,mono:!0}),(0,X.jsx)(ag,{icon:er,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),c&&(0,X.jsx)(ag,{icon:z,label:`Requires confirmation`,tone:`amber`}),u&&(0,X.jsx)(ag,{label:`built-in`})]})]})]}),a&&(0,X.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,X.jsx)(rg,{title:`Input Parameters`,count:Object.keys(p).length,children:Object.keys(p).length===0?(0,X.jsx)(ig,{children:`This tool takes no input parameters.`}):(0,X.jsx)(ng,{props:p,required:m})}),Object.keys(p).length>0&&(0,X.jsx)(rg,{title:`Example LLM Call`,icon:yn,children:(0,X.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono overflow-auto max-h-[200px]`,children:`{
20
+ "tool": "${r}",
21
+ "arguments": ${JSON.stringify(h,null,2).replace(/\n/g,`
22
+ `)}
23
+ }`})}),Qh(f)&&f.properties&&Object.keys(f.properties).length>0&&(0,X.jsx)(rg,{title:`Output Schema`,count:Object.keys(f.properties).length,icon:Mt,children:(0,X.jsx)(ng,{props:f.properties,required:new Set(Array.isArray(f.required)?f.required:[])})})]})})})}function ng({props:e,required:t}){let n=Object.keys(e);return(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`bg-muted/30 text-left text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Name`}),(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Type`}),(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Description`})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:n.map(n=>{let r=e[n],i=t.has(n);return(0,X.jsxs)(`tr`,{className:`align-top`,children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[i?(0,X.jsx)(Jt,{className:`h-3 w-3 text-emerald-600`}):(0,X.jsx)(Vn,{className:`h-3 w-3 text-muted-foreground`}),n,i&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700 ml-1`,children:`req`})]})}),(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono text-muted-foreground`,children:$h(r)}),(0,X.jsxs)(`td`,{className:`px-2.5 py-1.5`,children:[r.description&&(0,X.jsx)(`div`,{children:r.description}),Array.isArray(r.enum)&&r.enum.length>0&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`enum: `,r.enum.map(e=>JSON.stringify(e)).join(` | `)]}),r.default!==void 0&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`default: `,(0,X.jsx)(`code`,{className:`font-mono`,children:JSON.stringify(r.default)})]}),r.format&&(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`format: `,r.format]})]})]},n)})})]})})}function rg({title:e,count:t,icon:n,children:r}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,X.jsx)(n,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e}),t!=null&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function ig({children:e}){return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function ag({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var og=[{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:`allowExport`,short:`E`,long:`Export`},{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}],sg=[`own`,`own_and_reports`,`unit`,`unit_and_below`,`org`],cg={own:`own`,own_and_reports:`own+reports`,unit:`unit`,unit_and_below:`unit+below`,org:`org`};function lg(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.`});let e=r.readScope?sg.indexOf(r.readScope):-1,i=r.writeScope?sg.indexOf(r.writeScope):-1;e>=0&&i>e&&t.push({object:n,message:`Write scope (${cg[r.writeScope]}) is wider than read scope (${cg[r.readScope]}) — edits may target invisible records.`})}return t}function ug({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=!!n.isDefault,o=n.objects??{},s=n.fields??{},c=Array.isArray(n.systemPermissions)?n.systemPermissions:[],l=n.tabPermissions??{},u=Array.isArray(n.rowLevelSecurity)?n.rowLevelSecurity:[],d=Z.useMemo(()=>Object.keys(o).sort(),[o]),f=Z.useMemo(()=>lg(o),[o]),p=Z.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,X.jsx)(Q,{hint:`permission`,children:(0,X.jsx)(Qu,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,X.jsx)(Q,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[a?(0,X.jsx)(ve,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,X.jsx)(Fe,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:a?`Default Permission Set`:`Permission Set`})]}),(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(mg,{icon:ri,label:`${d.length} objects`}),(0,X.jsx)(mg,{icon:on,label:`${c.length} system perms`}),(0,X.jsx)(mg,{icon:Sr,label:`${Object.keys(l).length} tabs`}),(0,X.jsx)(mg,{icon:hr,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,X.jsxs)(pg,{title:`Object Permissions`,count:d.length,children:[(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-x-auto`,children:(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{children:(0,X.jsxs)(`tr`,{className:`bg-muted/30 text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium sticky left-0 bg-muted/30`,children:`Object`}),og.map(e=>(0,X.jsx)(`th`,{className:`px-1.5 py-1.5 text-center font-medium`,title:e.long,children:e.short},e.key)),(0,X.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium`,title:`Read / write access depth (ADR-0057)`,children:`Scope`})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:d.map(e=>{let t=o[e]??{};return(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1 font-mono sticky left-0 bg-background`,children:e}),og.map(e=>(0,X.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,X.jsx)(dg,{granted:!!t[e.key],danger:e.danger})},e.key)),(0,X.jsx)(`td`,{className:`px-2 py-1 whitespace-nowrap text-[10px] text-muted-foreground`,children:t.readScope||t.writeScope?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{title:`Read scope`,children:t.readScope?cg[t.readScope]:`—`}),(0,X.jsx)(`span`,{className:`mx-1 opacity-50`,children:`/`}),(0,X.jsx)(`span`,{title:`Write scope`,children:t.writeScope?cg[t.writeScope]:`—`})]}):(0,X.jsx)(`span`,{className:`opacity-40`,children:`default`})})]},e)})})]})}),(0,X.jsx)(fg,{})]}),p.size>0&&(0,X.jsx)(pg,{title:`Field-Level Overrides`,count:Array.from(p.values()).reduce((e,t)=>e+t.length,0),children:(0,X.jsx)(`div`,{className:`rounded border bg-background divide-y text-xs`,children:Array.from(p.entries()).sort().map(([e,t])=>(0,X.jsxs)(`div`,{className:`px-2.5 py-2`,children:[(0,X.jsx)(`div`,{className:`font-mono text-[11px] mb-1`,children:e}),(0,X.jsx)(`ul`,{className:`flex flex-wrap gap-1`,children:t.map(({field:e,perm:t})=>(0,X.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,X.jsx)(`span`,{className:`font-mono`,children:e}),t.readable===!1&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-red-700`,children:`hidden`}),t.editable&&(0,X.jsx)(`span`,{className:`text-[9px] uppercase text-emerald-700`,children:`editable`})]},e))})]},e))})}),c.length>0&&(0,X.jsx)(pg,{title:`System Permissions`,count:c.length,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:c.map(e=>(0,X.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,X.jsx)(pg,{title:`Tab Visibility`,count:Object.keys(l).length,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:Object.entries(l).map(([e,t])=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 text-[11px]`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e}),(0,X.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,X.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-amber-800`,children:[(0,X.jsx)(z,{className:`h-3.5 w-3.5`}),` `,f.length,` sanity check`,f.length===1?``:`s`,` failed`]}),(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:f.map((e,t)=>(0,X.jsxs)(`li`,{className:`text-amber-900`,children:[(0,X.jsx)(`code`,{className:`font-mono`,children:e.object}),`: `,e.message]},t))})]})]})})})}function dg({granted:e,danger:t}){return e?(0,X.jsx)(Jt,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,X.jsx)(ui,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function fg(){return(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] text-muted-foreground`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(Jt,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(Jt,{className:`h-3 w-3 text-amber-600`}),` bypass (View/Modify All, Purge)`]}),(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(ui,{className:`h-3 w-3 text-muted-foreground/40`}),` not granted`]}),(0,X.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 pg({title:e,count:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,X.jsx)(`span`,{children:e}),t!=null&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),n]})}function mg({icon:e,label:t}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{children:t})]})}function hg(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 gg(e){switch(e){case`url`:return br;case`modal`:return en;case`flow`:return Ke;case`api`:return li;case`form`:return pe;default:return ce}}function _g(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 vg(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 yg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=hg(n.label)||r,a=n.icon||void 0,o=String(n.type??`script`),s=n.target,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=hg(n.confirmText),g=hg(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=gg(o),E=l===`action:icon`;return!r&&!i?(0,X.jsx)(Q,{hint:`action`,children:(0,X.jsx)(Qu,{children:`Set name and label to see the action preview.`})}):(0,X.jsx)(Q,{hint:`action`,children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-4 flex items-center justify-center min-h-[80px]`,children:(0,X.jsx)(bg,{label:i,icon:a,variant:c,iconOnly:E,disabled:!!S&&typeof S==`boolean`})}),(0,X.jsxs)(`div`,{className:`rounded border bg-background p-3 text-xs space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(Dg,{icon:T,label:`type: ${o}`}),b&&(0,X.jsx)(Dg,{icon:qn,label:`object: ${b}`,mono:!0}),c&&(0,X.jsx)(Dg,{label:`variant: ${c}`}),l&&(0,X.jsx)(Dg,{icon:Mn,label:l}),d&&(0,X.jsx)(Dg,{icon:ei,label:d,mono:!0}),f&&(0,X.jsx)(Dg,{icon:Wt,label:`bulk`,tone:`green`}),p&&(0,X.jsx)(Dg,{icon:Mr,label:`refresh after`}),m===!1&&(0,X.jsx)(Dg,{icon:xe,label:`AI: opted out`,tone:`amber`}),m===!0&&(0,X.jsx)(Dg,{icon:gt,label:`AI: exposed`})]}),u.length>0&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 pt-1`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Locations:`}),u.map(e=>(0,X.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,X.jsx)(Tg,{label:`Visible when`,value:x,icon:Sr}),S!=null&&typeof S!=`boolean`&&(0,X.jsx)(Tg,{label:`Disabled when`,value:S,icon:hr})]}),(0,X.jsxs)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-xs`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 font-medium text-blue-900 mb-0.5`,children:[(0,X.jsx)(T,{className:`h-3.5 w-3.5`}),` On click`]}),(0,X.jsx)(`div`,{className:`text-blue-950 font-mono break-all`,children:vg(o,s,!!y?.source)}),h&&(0,X.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-1.5 text-amber-900`,children:[(0,X.jsx)(z,{className:`h-3 w-3 mt-0.5`}),(0,X.jsxs)(`span`,{children:[`First asks: `,(0,X.jsx)(`em`,{children:h})]})]}),g&&(0,X.jsxs)(`div`,{className:`mt-1.5 text-blue-950`,children:[`On success: `,(0,X.jsx)(`em`,{children:g})]})]}),u.length>0&&(0,X.jsx)(Eg,{title:`Where it appears`,children:(0,X.jsx)(kg,{locations:u,label:i,icon:a,variant:c,iconOnly:E})}),o===`api`&&!!s&&(0,X.jsx)(Eg,{title:`Test request`,icon:li,children:(0,X.jsx)(Ag,{target:s,method:C,bodyExtra:w,params:_})}),_.length>0&&(0,X.jsx)(Eg,{title:`Input Dialog`,count:_.length,children:(0,X.jsx)(Sg,{title:i,params:_,variant:c})}),v&&(0,X.jsx)(Eg,{title:`Result Dialog`,icon:Sr,children:(0,X.jsx)(wg,{dialog:v})}),y?.source&&(0,X.jsx)(Eg,{title:`Script Body (${y.language??`expression`})`,icon:ce,children:(0,X.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 bg({label:e,icon:t,variant:n,iconOnly:r,disabled:i}){return(0,X.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 ${_g(n)} ${i?`opacity-50`:``}`,"aria-disabled":!0,disabled:!0,children:[t&&(0,X.jsx)(xg,{name:t}),!r&&(0,X.jsx)(`span`,{children:e})]})}function xg({name:e}){let t=e.split(/[-_\s]+/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(``),n=zt[t===`Home`?`House`:t];return n?(0,X.jsx)(n,{className:`h-4 w-4`,"aria-hidden":!0}):(0,X.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 Sg({title:e,params:t,variant:n}){return(0,X.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,X.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:e}),(0,X.jsx)(`div`,{className:`p-3 space-y-2`,children:t.map((e,t)=>{let n=e.name??e.field??`param_${t}`;return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(`label`,{className:`text-xs flex items-center gap-1`,children:[hg(e.label)||n,e.required&&(0,X.jsx)(`span`,{className:`text-red-600 text-[10px]`,children:`*`}),(0,X.jsx)(`span`,{className:`ml-1 font-mono text-[9px] text-muted-foreground`,children:n}),e.type&&(0,X.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:e.type})]}),Cg(e),e.helpText&&(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:e.helpText})]},t)})}),(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t bg-muted/20 px-3 py-2`,children:[(0,X.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded border bg-background pointer-events-none`,children:`Cancel`}),(0,X.jsx)(`button`,{type:`button`,disabled:!0,className:`text-xs px-2.5 py-1 rounded pointer-events-none ${_g(n||`primary`)}`,children:`OK`})]})]})}function Cg(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,X.jsxs)(`select`,{className:t,disabled:!0,value:``,children:[(0,X.jsx)(`option`,{value:``,children:n||`— select —`}),e.options.map((e,t)=>(0,X.jsx)(`option`,{value:e.value,children:hg(e.label)},t))]}):e.type===`boolean`?(0,X.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-xs`,children:[(0,X.jsx)(`input`,{type:`checkbox`,disabled:!0,className:`pointer-events-none`}),` Toggle`]}):e.type===`textarea`||e.type===`html`||e.type===`long_text`?(0,X.jsx)(`textarea`,{className:`${t} min-h-[48px]`,placeholder:n,value:r==null?``:String(r),readOnly:!0}):(0,X.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 wg({dialog:e}){let t=hg(e.title)||`Result`,n=hg(e.description),r=hg(e.acknowledge)||`I have saved this`,i=e.fields??[];return(0,X.jsxs)(`div`,{className:`rounded border bg-background shadow-sm`,children:[(0,X.jsx)(`div`,{className:`border-b bg-muted/30 px-3 py-2 text-xs font-medium`,children:t}),(0,X.jsxs)(`div`,{className:`p-3 space-y-2 text-xs`,children:[n&&(0,X.jsx)(`div`,{className:`text-muted-foreground`,children:n}),i.length===0?(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Renders full JSON response.`}):(0,X.jsx)(`ul`,{className:`space-y-1.5`,children:i.map((t,n)=>(0,X.jsx)(`li`,{className:`rounded border bg-muted/20 p-2`,children:(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:hg(t.label)||t.path}),(0,X.jsx)(`span`,{className:`font-mono text-[9px] text-muted-foreground`,children:t.path}),(0,X.jsx)(`span`,{className:`ml-auto font-mono text-[9px] uppercase text-muted-foreground`,children:t.format??e.format??`json`})]})},n))})]}),(0,X.jsx)(`div`,{className:`flex items-center justify-end border-t bg-muted/20 px-3 py-2`,children:(0,X.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 Tg({label:e,value:t,icon:n}){let r=typeof t==`string`?t:t?.source??JSON.stringify(t);return(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 pt-0.5`,children:[(0,X.jsx)(n,{className:`h-3 w-3 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[e,`:`]}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:r})]})}function Eg({title:e,count:t,icon:n,children:r}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[n&&(0,X.jsx)(n,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e}),t!=null&&(0,X.jsxs)(`span`,{className:`opacity-70`,children:[`(`,t,`)`]})]}),r]})}function Dg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function Og({label:e,children:t}){return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-mono uppercase tracking-wider text-muted-foreground/70`,children:e}),t]})}function kg({locations:e,label:t,icon:n,variant:r,iconOnly:i}){let a=(0,X.jsx)(bg,{label:t,icon:n,variant:r,iconOnly:i});return(0,X.jsxs)(`div`,{className:`space-y-2.5`,children:[e.includes(`record_header`)&&(0,X.jsx)(Og,{label:`record_header`,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`h-6 w-6 rounded bg-muted`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-xs font-medium`,children:`Sample record`}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Record detail`})]})]}),(0,X.jsx)(`div`,{className:`flex items-center gap-1.5`,children:a})]}),(0,X.jsx)(`div`,{className:`p-3 text-[10px] text-muted-foreground`,children:`…record body…`})]})}),e.includes(`list_toolbar`)&&(0,X.jsx)(Og,{label:`list_toolbar`,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b px-3 py-2`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium`,children:`Records`}),(0,X.jsx)(`div`,{className:`flex items-center gap-1.5`,children:a})]}),(0,X.jsx)(`div`,{className:`px-3 py-2 text-[10px] text-muted-foreground`,children:`row 1 · row 2 · row 3`})]})}),e.includes(`list_item`)&&(0,X.jsx)(Og,{label:`list_item`,children:(0,X.jsx)(`div`,{className:`divide-y rounded border bg-background`,children:[0,1].map(e=>(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-1.5`,children:[(0,X.jsxs)(`span`,{className:`text-[11px]`,children:[`Row `,e+1]}),(0,X.jsx)(`div`,{className:`origin-right scale-90`,children:a})]},e))})}),(e.includes(`record_section`)||e.includes(`record_related`))&&(0,X.jsx)(Og,{label:e.includes(`record_related`)?`record_related`:`record_section`,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-b px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:`Section`}),a]}),(0,X.jsx)(`div`,{className:`p-3 text-[10px] text-muted-foreground`,children:`…section content…`})]})}),e.includes(`record_more`)&&(0,X.jsx)(Og,{label:`record_more`,children:(0,X.jsxs)(`div`,{className:`w-52 rounded border bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-3 py-1.5 text-[11px] text-muted-foreground`,children:[(0,X.jsx)(Mn,{className:`h-3.5 w-3.5`}),` More`]}),(0,X.jsx)(`div`,{className:`px-2 py-1.5 text-xs`,children:(0,X.jsx)(`div`,{className:`rounded px-1 py-0.5 hover:bg-accent`,children:t})})]})}),e.includes(`global_nav`)&&(0,X.jsx)(Og,{label:`global_nav`,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,X.jsx)(`div`,{className:`px-3 py-2 text-[11px] text-muted-foreground`,children:`⌘K · Command palette`}),(0,X.jsx)(`div`,{className:`border-t px-3 py-1.5 text-xs`,children:(0,X.jsx)(`div`,{className:`rounded px-1 py-0.5 hover:bg-accent`,children:t})})]})})]})}function Ag({target:e,method:t,bodyExtra:n,params:r}){let i=(t||`POST`).toUpperCase(),[a,o]=Z.useState(null),[s,c]=Z.useState(!1),l=n&&typeof n==`object`?n:{};return(0,X.jsxs)(`div`,{className:`space-y-2 text-xs`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2 font-mono text-[11px] break-all`,children:[(0,X.jsx)(`span`,{className:`font-semibold`,children:i}),` `,e]}),Object.keys(l).length>0&&(0,X.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,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground`,children:[`+ `,r.length,` user-supplied param`,r.length>1?`s`:``,` collected at runtime`]}),i!==`GET`&&(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 text-[10px] text-amber-700`,children:[(0,X.jsx)(z,{className:`mt-0.5 h-3 w-3 shrink-0`}),(0,X.jsxs)(`span`,{children:[`Sends a real `,i,` request to the live backend — may modify data.`]})]}),(0,X.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,X.jsx)(li,{className:`h-3.5 w-3.5`}),` `,s?`Sending…`:`Send test request`]}),a&&(0,X.jsxs)(`div`,{className:`rounded border p-2 `+(a.ok?`border-green-300 bg-green-50`:`border-red-300 bg-red-50`),children:[(0,X.jsx)(`div`,{className:`mb-1 text-[11px] font-medium`,children:a.error?`Network error`:`HTTP `+a.status+(a.ok?` OK`:``)}),(0,X.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 jg={"@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 Mg(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 Ng(e){let t=(jg[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=Mg(n,0,59),c=Mg(r,0,23),l=Mg(i,1,31),u=Mg(a,1,12),d=Mg(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function Pg(e,t,n){let r=Ng(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 Fg(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 Ig(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function Lg(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function Rg(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?zg(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`?zg(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function zg(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 Bg({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}=Rg(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?Fg(s):null,{nextFires:v,deltas:y}=Z.useMemo(()=>{let e=new Date,t=[];if(o)t=Pg(o,e,5);else if(_)t=Ig(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>Vg(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,X.jsx)(Q,{hint:`job`,children:(0,X.jsx)(Qu,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,X.jsx)(Q,{hint:`job`,children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(ke,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(Wg,{icon:er,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,X.jsx)(Wg,{icon:qr,label:l,mono:!0}),p!=null&&(0,X.jsx)(Wg,{icon:sr,label:`retries: ${p}${m?` (${zg(m)} backoff)`:``}`}),h!=null&&(0,X.jsx)(Wg,{icon:nr,label:`timeout: ${zg(h)}`}),g!=null&&(0,X.jsx)(Wg,{label:`concurrency: ${g}`})]})]})]})}),(0,X.jsx)(Ug,{title:`Schedule`,icon:Qt,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,X.jsx)(Hg,{label:`Cron`,children:(0,X.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,X.jsxs)(Hg,{label:`Every`,children:[(0,X.jsx)(`code`,{className:`font-mono`,children:s}),!_&&(0,X.jsx)(`span`,{className:`ml-2 text-amber-700`,children:`unparseable`})]}),c&&(0,X.jsx)(Hg,{label:`At`,children:(0,X.jsx)(`code`,{className:`font-mono`,children:c})}),!o&&!s&&!c&&(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`No schedule set — runs only when triggered manually.`})]})}),(o||_||c)&&(0,X.jsx)(Ug,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:vt,children:v.length===0?(0,X.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,X.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:v.map((e,t)=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`w-4 text-right text-muted-foreground text-[10px]`,children:t+1}),(0,X.jsx)(vt,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono`,children:Lg(e)}),(0,X.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,X.jsx)(Ug,{title:`Handler`,icon:ce,children:u?(0,X.jsxs)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs flex items-center gap-2`,children:[(0,X.jsx)($e,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:u})]}):(0,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No handler bound — the job will be a no-op.`})})]})})})}function Vg(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 Hg({label:e,children:t}){return(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsxs)(`span`,{className:`text-muted-foreground w-12 shrink-0`,children:[e,`:`]}),(0,X.jsx)(`span`,{className:`break-all`,children:t})]})}function Ug({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function Wg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var Gg=[{key:`objects`,label:`Objects`,icon:Dn,flat:!1},{key:`apps`,label:`Apps`,icon:Bt,flat:!1},{key:`messages`,label:`Messages`,icon:bt,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:Pt,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:Tt,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:Kr,flat:!1},{key:`settings`,label:`Settings`,icon:Xe,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:dr,flat:!1}];function Kg({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=Gg.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/Gg.length*100);return c===0?(0,X.jsx)(Q,{hint:`translation · ${r}`,children:(0,X.jsx)(Qu,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,X.jsx)(Q,{hint:`translation · ${r} · ${c} keys`,children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(sn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.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,X.jsx)(qr,{className:`h-3 w-3`}),` `,r]})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-2 text-[11px]`,children:[(0,X.jsx)(Ft,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Category coverage:`}),(0,X.jsx)(`div`,{className:`h-1.5 w-32 rounded-full bg-muted overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-full bg-emerald-500`,style:{width:`${u}%`}})}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[l,`/`,Gg.length,` (`,u,`%)`]}),(0,X.jsxs)(`span`,{className:`ml-3 text-muted-foreground`,children:[c,` total keys`]})]})]})]})}),(0,X.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:s.map(e=>(0,X.jsx)(qg,{cat:e},e.key))})]})})})}function qg({cat:e}){let t=e.icon;return(0,X.jsxs)(`div`,{className:`rounded border bg-background ${e.count===0?`opacity-60`:``}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between border-b px-2.5 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:e.label})]}),(0,X.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:e.count})]}),(0,X.jsx)(`div`,{className:`px-2.5 py-1.5 min-h-[3.5rem]`,children:e.count===0?(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`empty`}):(0,X.jsxs)(`ul`,{className:`space-y-0.5 text-[11px]`,children:[e.sample.map(([t,n])=>(0,X.jsxs)(`li`,{className:`flex items-baseline gap-2 truncate`,children:[(0,X.jsx)(`code`,{className:`font-mono text-muted-foreground shrink-0`,children:t}),(0,X.jsx)(`span`,{className:`truncate text-foreground/80`,children:Jg(n,e.flat)})]},t)),e.count>e.sample.length&&(0,X.jsxs)(`li`,{className:`text-[10px] text-muted-foreground italic`,children:[`+`,e.count-e.sample.length,` more…`]})]})})]})}function Jg(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function Yg({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``;return r?(0,X.jsx)(Q,{hint:`position`,children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(xn,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a})]})]})}),(0,X.jsx)(`div`,{className:`rounded border border-blue-200 bg-blue-50 p-2.5 text-[11px] text-blue-900`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5`,children:[(0,X.jsx)(Fe,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium`,children:`Positions don't grant data access on their own.`}),(0,X.jsxs)(`div`,{className:`opacity-90 mt-0.5`,children:[`Bind `,(0,X.jsx)(`code`,{className:`font-mono`,children:r}),` to one or more`,` `,(0,X.jsx)(`strong`,{children:`Permission Sets`}),` to control CRUD-VAMA, field access, and tab visibility. Record visibility comes from the business-unit tree and sharing rules, not from the position.`]})]})]})})]})})}):(0,X.jsx)(Q,{hint:`position`,children:(0,X.jsx)(Qu,{children:`Give the position a name to see the preview.`})})}function Xg({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=n.active!==!1,d=n.model??void 0;return r?(0,X.jsx)(Q,{hint:`skill`,children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(gt,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(Qg,{icon:er,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),d&&(0,X.jsx)(Qg,{label:`model: ${d}`,mono:!0})]})]})]})}),(0,X.jsx)(Zg,{title:`Instructions`,icon:ut,children:o?(0,X.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,X.jsx)(`div`,{className:`text-xs text-amber-700`,children:`No instructions yet — the skill will contribute nothing to the prompt.`})}),(0,X.jsxs)(Zg,{title:`Tools (${s.length})`,icon:Er,children:[s.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No tools whitelisted.`}):(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:s.map(e=>{let t=e.includes(`*`);return(0,X.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,X.jsx)(De,{className:`h-3 w-3`}),e]},e)})}),s.some(e=>e.includes(`*`))&&(0,X.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,X.jsx)(Zg,{title:`Trigger Phrases (${c.length})`,icon:Kt,children:(0,X.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:c.map((e,t)=>(0,X.jsxs)(`li`,{className:`px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground mr-2`,children:`"`}),e,(0,X.jsx)(`span`,{className:`text-muted-foreground ml-2`,children:`"`})]},t))})}),l.length>0&&(0,X.jsx)(Zg,{title:`Trigger Conditions (${l.length})`,icon:Vt,children:(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,X.jsx)(`table`,{className:`w-full text-xs`,children:(0,X.jsx)(`tbody`,{className:`divide-y`,children:l.map((e,t)=>(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-24 text-muted-foreground text-[10px] uppercase`,children:e.type??`cond`}),(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:e.expression??e.value??JSON.stringify(e)})]},t))})})})})]})})}):(0,X.jsx)(Q,{hint:`skill`,children:(0,X.jsx)(Qu,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function Zg({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function Qg({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var $g=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},e_=f();function t_(){return``.replace(/\/+$/,``)}function n_(e){return`${t_()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function r_(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 $g}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 i_(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await r_(await e_(`${n_(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function a_(e,t,n={}){return(await r_(await e_(`${n_(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function o_(e){return(await r_(await e_(`${n_(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function s_(e){return r_(await e_(`${n_(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function c_(e){await r_(await e_(`${t_()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function l_({datasource:e,table:t,open:n,onOpenChange:r,onImported:i}){let[a,o]=Z.useState(`loading`),[s,c]=Z.useState(null),[l,u]=Z.useState(null);Z.useEffect(()=>{if(!n||!t)return;let r=!1;return o(`loading`),c(null),u(null),(async()=>{try{let n=await a_(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof $g?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e)),o(`error`)}})(),()=>{r=!0}},[n,t,e]);let d=Z.useCallback(async()=>{if(s){o(`importing`),u(null);try{await c_(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,X.jsx)(Ir,{open:n,onOpenChange:r,children:(0,X.jsxs)(fn,{className:`max-w-2xl`,children:[(0,X.jsxs)(vn,{children:[(0,X.jsxs)(On,{className:`flex items-center gap-2`,children:[(0,X.jsx)(ge,{className:`h-4 w-4`}),`Import as Object`]}),(0,X.jsxs)($n,{children:[`Map remote table `,(0,X.jsx)(`span`,{className:`font-mono`,children:f}),` into an ObjectStack object bound to `,(0,X.jsx)(`span`,{className:`font-mono`,children:e}),`. The remote schema is never modified.`]})]}),a===`loading`&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 py-8 justify-center text-sm text-muted-foreground`,children:[(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Generating draft…`]}),a===`error`&&(0,X.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive`,children:l}),a===`done`&&s&&(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-8 text-center`,children:[(0,X.jsx)(Jt,{className:`h-8 w-8 text-emerald-500`}),(0,X.jsxs)(`div`,{className:`text-sm`,children:[`Imported object `,(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:s.name}),`.`]}),(0,X.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,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2 text-sm`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Object name`}),(0,X.jsx)(`span`,{className:`font-mono font-medium`,children:s.name})]}),l&&(0,X.jsx)(`div`,{className:`rounded border border-destructive/40 bg-destructive/5 p-2 text-xs text-destructive`,children:l}),s.review.length>0&&(0,X.jsxs)(`div`,{className:`rounded border border-amber-300 bg-amber-50 dark:bg-amber-950/20 p-2.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-300`,children:[(0,X.jsx)(z,{className:`h-3.5 w-3.5`}),s.review.length,` column`,s.review.length===1?``:`s`,` need review`]}),(0,X.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,X.jsxs)(`li`,{className:`flex flex-wrap gap-x-1.5`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e.column}),(0,X.jsxs)(`span`,{className:`text-amber-700/70 dark:text-amber-400/70`,children:[`(`,e.remoteType,`)`]}),(0,X.jsxs)(`span`,{children:[`— `,e.note]})]},e.column))})]}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[(0,X.jsx)(Wr,{className:`h-3 w-3`}),` Generated source`]}),(0,X.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,X.jsx)(Ur,{children:a===`done`?(0,X.jsx)(W,{onClick:()=>r(!1),children:`Close`}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{variant:`ghost`,onClick:()=>r(!1),disabled:a===`importing`,children:`Cancel`}),(0,X.jsx)(W,{onClick:d,disabled:a!==`ready`||!s,children:a===`importing`?(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}),` Importing…`]}):`Import as Object`})]})})]})})}function u_({datasource:e}){let[t,n]=Z.useState(`idle`),[r,i]=Z.useState([]),[a,o]=Z.useState(null),[s,c]=Z.useState(``),[l,u]=Z.useState(null),[d,f]=Z.useState(!1),p=Z.useCallback(async()=>{n(`loading`),o(null);try{let t=await i_(e);i(t),n(`loaded`)}catch(e){e instanceof $g?n(`unavailable`):(o(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);Z.useEffect(()=>{p()},[p]);let m=Z.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,X.jsx)(d_,{}):(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`div`,{className:`relative flex-1`,children:[(0,X.jsx)(We,{className:`absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,X.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,X.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>void p(),disabled:t===`loading`,children:[t===`loading`?(0,X.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(Mr,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]}),a&&(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground`,children:[(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`}),` Introspecting remote schema…`]}),t===`loaded`&&m.length===0&&(0,X.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,X.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40 text-muted-foreground`,children:(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 text-left font-medium`,children:`Table`}),(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Columns`}),(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 text-right font-medium`,children:`Rows (est.)`}),(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 w-px`})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:m.map(e=>{let t=[e.schema,e.name].filter(Boolean).join(`.`);return(0,X.jsxs)(`tr`,{className:`hover:bg-muted/30`,children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 font-mono`,children:[(0,X.jsx)(Ot,{className:`h-3.5 w-3.5 text-muted-foreground`}),e.schema&&(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[e.schema,`.`]}),(0,X.jsx)(`span`,{className:`font-medium`,children:e.name})]})}),(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 text-right tabular-nums`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,X.jsx)(dt,{className:`h-3 w-3`}),e.columnCount]})}),(0,X.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,X.jsx)(`td`,{className:`px-2.5 py-1.5`,children:(0,X.jsxs)(W,{variant:`ghost`,size:`sm`,onClick:()=>h(e),children:[(0,X.jsx)(ii,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,X.jsx)(l_,{datasource:e,table:l,open:d,onOpenChange:f})]})}function d_(){return(0,X.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,X.jsx)(`span`,{className:`font-mono`,children:` external-datasource `}),`service must be registered for table browsing, drafting, and validation to work.`]})}var f_={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 p_({datasource:e}){let[t,n]=Z.useState(`idle`),[r,i]=Z.useState([]),[a,o]=Z.useState(null),[s,c]=Z.useState(null),l=Z.useCallback(async()=>{n(`running`),c(null);try{let t=await s_(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof $g?n(`unavailable`):(c(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);return t===`unavailable`?(0,X.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,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Check that every federated object on`,` `,(0,X.jsx)(`span`,{className:`font-mono`,children:e}),` still matches its live remote table.`]}),(0,X.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:t===`running`,children:[t===`running`?(0,X.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)($e,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`ml-1.5`,children:`Run validation`})]})]}),s&&(0,X.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,X.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,X.jsx)(Jt,{className:`h-4 w-4`}):(0,X.jsx)(Pt,{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,X.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,X.jsx)(`ul`,{className:`space-y-2`,children:r.map(e=>(0,X.jsx)(m_,{result:e},e.object))})]})}function m_({result:e}){return(0,X.jsxs)(`li`,{className:`rounded border bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[e.ok?(0,X.jsx)(Fe,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,X.jsx)(Pt,{className:`h-3.5 w-3.5 text-destructive`}),(0,X.jsx)(`span`,{className:`font-mono text-xs font-medium`,children:e.object}),!e.ok&&(0,X.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,X.jsx)(`ul`,{className:`border-t divide-y`,children:e.diffs.map((e,t)=>(0,X.jsx)(h_,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function h_({diff:e}){let t=[e.remoteSchema,e.remoteName].filter(Boolean).join(`.`);return(0,X.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,X.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:f_[e.kind]??e.kind}),t&&(0,X.jsx)(`span`,{className:`font-mono text-muted-foreground`,children:t}),e.column&&(0,X.jsxs)(`span`,{className:`font-mono`,children:[`.`,e.column]}),(e.expected!==void 0||e.actual!==void 0)&&(0,X.jsxs)(`span`,{className:`text-muted-foreground`,children:[`expected `,(0,X.jsx)(`span`,{className:`font-mono`,children:e.expected??`—`}),`, actual`,` `,(0,X.jsx)(`span`,{className:`font-mono`,children:e.actual??`—`})]})]})}function g_({datasource:e,schemaMode:t,allowWrites:n}){let[r,i]=Z.useState(null),[a,o]=Z.useState(!1),[s,c]=Z.useState(null),l=Z.useCallback(async()=>{if(e){o(!0),c(null);try{let t=await o_(e);i(t)}catch(e){c(e instanceof $g?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e))}finally{o(!1)}}},[e]);return e?(0,X.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,X.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,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-medium`,children:[(0,X.jsx)(Zr,{className:`h-4 w-4 text-sky-500`}),`External Datasource`]}),(0,X.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,X.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,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[r?.snapshotAt&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,X.jsx)(vt,{className:`h-3 w-3`}),`snapshot `,__(r.snapshotAt)]}),(0,X.jsxs)(W,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:a,children:[a?(0,X.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(Mr,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`ml-1.5`,children:`Refresh catalog`})]})]})]}),s&&(0,X.jsx)(`div`,{className:`border-b border-destructive/40 bg-destructive/5 px-3 py-2 text-xs text-destructive`,children:s}),(0,X.jsxs)(Xn,{defaultValue:`tables`,className:`p-3`,children:[(0,X.jsxs)(Gn,{children:[(0,X.jsx)(ot,{value:`tables`,children:`Tables`}),(0,X.jsx)(ot,{value:`validation`,children:`Validation`})]}),(0,X.jsx)(le,{value:`tables`,className:`mt-3`,children:(0,X.jsx)(u_,{datasource:e})}),(0,X.jsx)(le,{value:`validation`,className:`mt-3`,children:(0,X.jsx)(p_,{datasource:e})})]})]}):(0,X.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 __(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var v_=/pass|secret|key|token|credential|auth/i;function y_(e){return v_.test(e)}function b_(e){return e==null||e===``?`∅`:`••••••`}function x_(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 S_({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,X.jsx)(Q,{hint:`datasource`,children:(0,X.jsx)(Qu,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,X.jsx)(Q,{hint:`datasource · ${o}`,children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(ge,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded border bg-background px-1.5 py-0.5 font-mono`,children:[(0,X.jsx)(_t,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,X.jsx)(T_,{icon:er,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`}),c&&(0,X.jsx)(T_,{icon:ve,label:`default`,tone:`amber`}),m.length>0&&(0,X.jsx)(T_,{icon:we,label:`${m.length} read replica${m.length===1?``:`s`}`})]})]})]})}),_&&(0,X.jsx)(g_,{datasource:String(e??``),schemaMode:g,allowWrites:v}),(0,X.jsx)(w_,{title:`Connection`,icon:hr,children:y.length===0?(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:`No config keys set.`}):(0,X.jsx)(`div`,{className:`rounded border bg-background overflow-hidden`,children:(0,X.jsx)(`table`,{className:`w-full text-xs`,children:(0,X.jsx)(`tbody`,{className:`divide-y`,children:y.map(([e,t])=>{let n=y_(e);return(0,X.jsxs)(`tr`,{children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 align-top w-40 font-mono text-muted-foreground`,children:e}),(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:n?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{children:b_(t)}),(0,X.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`})]}):x_(t)})]},e)})})})})}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,X.jsx)(C_,{title:`Pool`,icon:Ye,value:u}),(0,X.jsx)(C_,{title:`SSL`,icon:Fe,value:typeof d==`boolean`?{enabled:d}:d}),(0,X.jsx)(C_,{title:`Retry Policy`,icon:sr,value:f}),(0,X.jsx)(C_,{title:`Health Check`,icon:Ye,value:p})]}),h.length>0&&(0,X.jsx)(w_,{title:`Capabilities`,icon:Fe,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:h.map(e=>(0,X.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 C_({title:e,icon:t,value:n}){let r=n&&typeof n==`object`&&Object.keys(n).length>0;return(0,X.jsxs)(`div`,{className:`rounded border bg-background ${r?``:`opacity-60`}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 border-b px-2.5 py-1.5`,children:[(0,X.jsx)(t,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:e})]}),(0,X.jsx)(`div`,{className:`px-2.5 py-1.5 text-[11px]`,children:r?(0,X.jsx)(`dl`,{className:`space-y-0.5`,children:Object.entries(n).slice(0,6).map(([e,t])=>(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2 truncate`,children:[(0,X.jsxs)(`dt`,{className:`text-muted-foreground font-mono shrink-0`,children:[e,`:`]}),(0,X.jsx)(`dd`,{className:`font-mono truncate`,children:y_(e)?b_(t):x_(t)})]},e))}):(0,X.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function w_({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function T_({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700`:n===`amber`?`text-amber-700`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}function E_(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function D_(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:oi};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:z};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:Ce}}}function O_({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=D_(l);return r?(0,X.jsx)(Q,{hint:`validation · ${o}`,children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsx)(`div`,{className:`rounded border bg-muted/30 p-3`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(Pt,{className:`h-4 w-4 mt-0.5 text-muted-foreground shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:i}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:r}),(0,X.jsx)(`span`,{className:`rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono`,children:o})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-0.5`,children:a}),(0,X.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:[(0,X.jsx)(M_,{icon:er,label:u?`Active`:`Disabled`,tone:u?`green`:`gray`}),s&&(0,X.jsx)(M_,{label:`object: ${s}`,mono:!0}),f!=null&&(0,X.jsx)(M_,{label:`priority ${f}`}),d.length>0&&(0,X.jsx)(M_,{label:`on ${d.join(`, `)}`})]})]})]})}),(0,X.jsx)(`div`,{className:`rounded border p-2.5 text-xs ${m.ring}`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 ${m.text}`,children:[(0,X.jsx)(m.icon,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium uppercase tracking-wider text-[10px]`,children:l}),(0,X.jsx)(`div`,{className:`font-normal mt-0.5 text-foreground`,children:c||(0,X.jsx)(`span`,{className:`italic text-muted-foreground`,children:`no message set`})})]})]})}),(0,X.jsx)(k_,{type:o,d:n}),p.length>0&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground uppercase tracking-wider mb-1`,children:`Tags`}),(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:p.map(e=>(0,X.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,X.jsx)(Q,{hint:`validation`,children:(0,X.jsx)(Qu,{children:`Give the validation a name to see the preview.`})})}function k_({type:e,d:t}){switch(e){case`script`:case`conditional`:return(0,X.jsx)(j_,{title:`Condition`,icon:ce,children:(0,X.jsx)(A_,{value:E_(t.condition)??E_(t.expression)})});case`unique`:{let e=Array.isArray(t.fields)?t.fields:[],n=E_(t.scope)??E_(t.where);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(j_,{title:`Unique on ${e.length} field${e.length===1?``:`s`}`,icon:xt,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:e.length===0?(0,X.jsx)(`span`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`no fields set`}):e.map(e=>(0,X.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[11px] font-mono`,children:e},e))})}),n&&(0,X.jsx)(j_,{title:`Scope`,icon:wt,children:(0,X.jsx)(A_,{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,X.jsx)(j_,{title:`Transitions${r?` on ${r}`:``}`,icon:Ke,children:n.length===0?(0,X.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No transitions declared.`}):(0,X.jsx)(`ul`,{className:`rounded border bg-background divide-y text-xs`,children:n.map(([e,t])=>(0,X.jsxs)(`li`,{className:`flex items-center gap-2 px-2.5 py-1.5`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:e}),(0,X.jsx)(si,{className:`h-3 w-3 text-muted-foreground`}),(0,X.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,X.jsx)(j_,{title:`Format`,icon:fr,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[n&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Built-in:`}),` `,(0,X.jsx)(`code`,{className:`font-mono`,children:n})]}),e&&(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`Pattern:`}),` `,(0,X.jsx)(`code`,{className:`font-mono break-all`,children:e})]}),!n&&!e&&(0,X.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=E_(t.condition);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(j_,{title:`Fields involved`,icon:wt,children:(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[e.map(e=>(0,X.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,X.jsx)(`span`,{className:`text-xs text-muted-foreground italic`,children:`none`})]})}),(0,X.jsx)(j_,{title:`Cross-field condition`,icon:ce,children:(0,X.jsx)(A_,{value:n})})]})}case`async`:{let e=t.endpoint??t.url,n=t.timeoutMs;return(0,X.jsx)(j_,{title:`Async endpoint`,icon:qr,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-mono`,children:t.method??`POST`}),(0,X.jsx)(`code`,{className:`font-mono break-all`,children:e??`—`})]}),n!=null&&(0,X.jsxs)(`div`,{className:`text-muted-foreground`,children:[`timeout: `,n,`ms`]})]})})}case`custom`:{let e=t.handler??t.function;return(0,X.jsx)(j_,{title:`Custom handler`,icon:ce,children:(0,X.jsx)(`div`,{className:`rounded border bg-background px-2.5 py-1.5 text-xs`,children:e?(0,X.jsx)(`code`,{className:`font-mono break-all`,children:e}):(0,X.jsx)(`span`,{className:`text-amber-700 dark:text-amber-400`,children:`No handler set.`})})})}default:return(0,X.jsx)(j_,{title:`Rule`,icon:Pt,children:(0,X.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 A_({value:e}){return e?(0,X.jsx)(`pre`,{className:`rounded border bg-background p-2.5 text-xs font-mono whitespace-pre-wrap break-words`,children:e}):(0,X.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No expression set.`})}function j_({title:e,icon:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-medium text-muted-foreground uppercase tracking-wider`,children:[t&&(0,X.jsx)(t,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:e})]}),n]})}function M_({icon:e,label:t,tone:n=`gray`,mono:r=!1}){return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[e&&(0,X.jsx)(e,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`${n===`green`?`text-emerald-700 dark:text-emerald-400`:`text-foreground`} ${r?`font-mono`:``}`,children:t})]})}var N_=Z.lazy(()=>a(()=>import(`./plugin-charts-_11K-vFF.js`).then(e=>e.t).then(e=>({default:e.ChartRenderer})),__vite__mapDeps([0]),import.meta.url));function P_({draft:e}){let t=k(),{fieldLabel:n}=Sn(),r=e.object,i=Z.useMemo(()=>(Array.isArray(e.measures)?e.measures:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),a=Z.useMemo(()=>(Array.isArray(e.dimensions)?e.dimensions:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),o=!!r&&i.length>0,[s,c]=Z.useState({status:`idle`,rows:[]}),l=Z.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){if(e?.code===`ANALYTICS_NOT_INSTALLED`){c({status:`not-installed`,rows:[]});return}c({status:`error`,rows:[],error:String(e?.message??e)})}}},[t,e,a,i,o]),u=`${r??``}|${a.join(`,`)}|${i.join(`,`)}`;if(Z.useEffect(()=>{o&&l()},[u]),!r)return(0,X.jsx)(Q,{children:(0,X.jsx)($u,{icon:(0,X.jsx)(Pn,{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,X.jsx)(Q,{children:(0,X.jsx)($u,{icon:(0,X.jsx)(Pn,{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}=ne(s.status===`ok`?s.fields:void 0,s.status===`ok`?s.object:void 0,n),p=[...a,...i],m=e=>{let t=d(e)?.format;return typeof t==`string`&&t.includes(`%`)},h=i.filter(m),g=h.length>0&&h.length<i.length;return(0,X.jsx)(Q,{hint:`dataset · ${r}${a.length?` · by `+a.join(`, `):``}`,children:(0,X.jsxs)(`div`,{className:`p-3 space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.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,X.jsx)(U,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(Pn,{className:`h-3.5 w-3.5`}),`Run preview`]}),(0,X.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,X.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,X.jsx)(z,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,X.jsx)(`span`,{className:`break-words`,children:s.error})]}),s.status===`not-installed`&&(0,X.jsx)($u,{icon:(0,X.jsx)(Ct,{className:`h-8 w-8`}),title:`Analytics capability not installed`,description:`This deployment has no analytics service, so dataset previews can't run. Install @objectstack/service-analytics and mount AnalyticsServicePlugin — the dataset definition itself is fine.`}),s.status===`ok`&&s.rows.length===0&&(0,X.jsx)($u,{icon:(0,X.jsx)(Pn,{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,X.jsx)(ed,{fallbackHint:`Couldn't render the chart for this result — the table below still shows the data.`,children:(0,X.jsx)(Z.Suspense,{fallback:(0,X.jsx)(`div`,{className:`h-[260px] flex items-center justify-center text-xs text-muted-foreground`,children:(0,X.jsx)(U,{className:`h-4 w-4 animate-spin`})}),children:(0,X.jsxs)(`div`,{className:`rounded-md border p-2`,children:[(0,X.jsx)(N_,{schema:{data:s.rows,xAxisKey:a[0],chartType:g?`combo`:`bar`,series:i.map(e=>({dataKey:e,label:f(e),chartType:g&&m(e)?`line`:`bar`}))}}),g&&(0,X.jsxs)(`p`,{className:`mt-1 px-1 text-[10px] text-muted-foreground`,children:[`Ratio measures (`,h.map(f).join(`, `),`) use the right axis.`]})]})})}),s.rows.length>0&&(0,X.jsx)(`div`,{className:`overflow-auto max-h-[60vh] rounded-md border`,children:(0,X.jsxs)(`table`,{className:`w-full text-xs`,children:[(0,X.jsx)(`thead`,{className:`bg-muted/40`,children:(0,X.jsx)(`tr`,{children:p.map(e=>(0,X.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:f(e)},e))})}),(0,X.jsx)(`tbody`,{children:s.rows.map((e,t)=>(0,X.jsx)(`tr`,{className:`border-t`,children:p.map(t=>(0,X.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:i.includes(t)?T(e[t],d(t)?.format,d(t)?.currency):M(e[t])},t))},t))})]})})]})})}function F_(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:I_(e.include),package:typeof e.package==`string`?e.package:void 0,pages:L_(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 I_(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`&&typeof e.tag==`string`)return{tag:e.tag}}function L_(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 R_(e){return e===`public`?{icon:(0,X.jsx)(li,{className:`h-3 w-3`}),label:`Public`,tone:`text-emerald-700 bg-emerald-50 border-emerald-200`}:e&&typeof e==`object`&&typeof e.permissionSet==`string`?{icon:(0,X.jsx)(hr,{className:`h-3 w-3`}),label:`Permission set: ${e.permissionSet}`,tone:`text-amber-800 bg-amber-50 border-amber-200`}:{icon:(0,X.jsx)(ni,{className:`h-3 w-3`}),label:`Org`,tone:`text-muted-foreground bg-muted/40 border-muted`}}function z_({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=Z.useMemo(()=>F_(n.groups),[n.groups]),c=R_(n.audience);return r?(0,X.jsx)(Q,{hint:`book · spine`,toolbar:(0,X.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,X.jsx)(Rn,{className:`h-3 w-3`})]}),children:(0,X.jsx)(ed,{children:(0,X.jsxs)(`div`,{className:`p-3 space-y-3`,children:[(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(ut,{className:`h-4 w-4 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:i}),(0,X.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,X.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono mt-0.5`,children:r}),o&&(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:[`Slug: `,(0,X.jsx)(`code`,{className:`font-mono`,children:o})]}),a&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1.5`,children:a})]}),s.length===0?(0,X.jsx)($u,{icon:(0,X.jsx)(Tr,{className:`h-8 w-8 opacity-50`}),title:`No groups yet`,tone:`warn`,description:(0,X.jsxs)(X.Fragment,{children:[`A book needs at least one group in its `,(0,X.jsx)(`code`,{children:`groups`}),` spine. Each group derives its members from an `,(0,X.jsx)(`code`,{children:`include`}),` rule (a glob like`,` `,(0,X.jsx)(`code`,{children:`crm_guide_*`}),` or a `,(0,X.jsx)(`code`,{children:`{ tag }`}),`).`]})}):(0,X.jsx)(`div`,{className:`space-y-2`,children:s.map((e,t)=>(0,X.jsx)(B_,{group:e},`${e.key}-${t}`))})]})})}):(0,X.jsx)(Q,{hint:`book`,children:(0,X.jsx)($u,{icon:(0,X.jsx)(ut,{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 B_({group:e}){return(0,X.jsxs)(`div`,{className:`rounded border bg-background`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 border-b bg-muted/20 px-3 py-2`,children:[(0,X.jsx)(Tr,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`text-xs font-medium text-foreground truncate`,children:e.label}),(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.key}),typeof e.order==`number`&&(0,X.jsxs)(`span`,{className:`text-[10px] text-muted-foreground`,title:`Order within the book`,children:[`#`,e.order]}),(0,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[e.package&&(0,X.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,X.jsx)(et,{className:`h-3 w-3`}),e.package]}),(0,X.jsx)(V_,{include:e.include,hasOverride:!!e.pages?.length})]})]}),(0,X.jsx)(`div`,{className:`px-3 py-2`,children:e.pages?.length?(0,X.jsx)(`ol`,{className:`space-y-1`,children:e.pages.map((e,t)=>(0,X.jsx)(H_,{node:e},t))}):e.include==null?(0,X.jsxs)(`div`,{className:`text-[11px] text-amber-700 italic`,children:[`No `,(0,X.jsx)(`code`,{children:`include`}),` rule and no explicit `,(0,X.jsx)(`code`,{children:`pages`}),` — this group matches nothing unless docs set `,(0,X.jsxs)(`code`,{children:[`group: "`,e.key,`"`]}),`.`]}):(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground italic`,children:`Members derived from the rule above — resolved against the live doc set.`})})]})}function V_({include:e,hasOverride:t}){return e==null?t?(0,X.jsx)(`span`,{className:`text-[10px] text-muted-foreground`,title:`Curated order via explicit pages`,children:`curated`}):null:typeof e==`string`?(0,X.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,X.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,X.jsx)(on,{className:`h-3 w-3`}),e.tag]})}function H_({node:e}){if(e.literal===`---`)return(0,X.jsxs)(`li`,{className:`flex items-center gap-2 text-[10px] uppercase tracking-wider text-muted-foreground/60`,children:[(0,X.jsx)(Cr,{className:`h-3 w-3`}),`separator`]});if(e.literal===`...`)return(0,X.jsxs)(`li`,{className:`flex items-center gap-2 text-[11px] italic text-muted-foreground`,children:[(0,X.jsx)(Mn,{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,X.jsxs)(`li`,{className:`flex items-center gap-2 text-xs`,children:[t?(0,X.jsx)(Rn,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,X.jsx)(dr,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}),(0,X.jsx)(`span`,{className:`truncate`,children:r}),!t&&n&&e.label&&(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:n}),e.badge&&(0,X.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,X.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 U_(){ml(`page`,$d),ml(`view`,rf),ml(`dashboard`,df),ml(`report`,mf),ml(`app`,Df),ml(`action`,yg),ml(`object`,qf),ml(`datasource`,S_),ml(`validation`,O_),ml(`dataset`,P_),ml(`email_template`,Zf),ml(`translation`,Kg),ml(`book`,z_),ml(`flow`,Bh),ml(`job`,Bg),ml(`agent`,Hh),ml(`tool`,tg),ml(`skill`,Xg),ml(`permission`,ug),ml(`profile`,ug),ml(`position`,Yg),ml(`role`,Yg)}var W_=[{value:`metric`,label:`KPI Metric`},{value:`bar`,label:`Bar Chart`},{value:`horizontal-bar`,label:`Horizontal Bar`},{value:`line`,label:`Line Chart`},{value:`area`,label:`Area Chart`},{value:`pie`,label:`Pie Chart`},{value:`donut`,label:`Donut Chart`},{value:`funnel`,label:`Funnel`},{value:`table`,label:`Table`},{value:`pivot`,label:`Pivot Table`}],G_=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function K_(e,t){let n=Array.isArray(e.widgets)?e.widgets:[],r=n.findIndex(e=>e?.id===t);return r<0?null:{widget:n[r],index:r}}function q_({draft:e,selection:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=Array.isArray(e.widgets)?e.widgets:[],c=t.kind===`widget`?t.id:void 0,l=c?K_(e,c):null,u=l?.widget??{},d=typeof u.dataset==`string`?u.dataset:``,f=Array.isArray(u.dimensions)?u.dimensions.filter(e=>typeof e==`string`):[],p=Array.isArray(u.values)?u.values.filter(e=>typeof e==`string`):[],m=Oa(),h=ba(d||void 0,m),g=Z.useMemo(()=>{let e=m.datasets.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));return d&&!e.some(e=>e.value===d)&&e.push({value:d,label:d}),e},[m.datasets,d]),_=Z.useMemo(()=>h.measures.map(e=>({name:e.name,label:e.aggregate?`${e.name} · ${e.aggregate}`:e.name,type:`number`,hidden:!1})),[h.measures]),v=Z.useMemo(()=>h.dimensions.map(e=>({name:e.name,label:e.name,type:e.type??`text`,hidden:!1})),[h.dimensions]),y=Z.useMemo(()=>h.dimensions.map(e=>({value:e.name,label:e.name,hint:e.type})),[h.dimensions]),b=Z.useMemo(()=>j({globalFilters:e.globalFilters,dateRange:e.dateRange}),[e]);if(t.kind!==`widget`)return(0,X.jsx)(Y_,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});if(!l)return(0,X.jsx)(Y_,{message:`The selected widget was removed from the draft.`,onClose:r,locale:o});let{widget:x,index:S}=l;function C(e){let t=[...s];t[S]={...t[S],...e},n({widgets:t})}function w(e){n({widgets:ia(s,S,e)}),x.id&&i?.({kind:`widget`,id:x.id,label:x.title??void 0})}return(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-muted-foreground`,children:K(`engine.inspector.widget.kind`,o)}),(0,X.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:x.title||t.label||`Widget ${S+1}`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,X.jsx)(Yi,{index:S,total:s.length,onMove:w,upLabel:K(`engine.inspector.reorder.up`,o),downLabel:K(`engine.inspector.reorder.down`,o),disabled:a}),(0,X.jsx)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:r,title:K(`engine.inspector.widget.close`,o),"aria-label":K(`engine.inspector.widget.close`,o),children:(0,X.jsx)(Qe,{className:`h-3.5 w-3.5`})})]})]}),(0,X.jsx)(J_,{id:`widget-title`,label:K(`engine.inspector.widget.title`,o),children:(0,X.jsx)(R,{id:`widget-title`,value:x.title??``,onChange:e=>C({title:e.target.value}),disabled:a})}),(0,X.jsx)(J_,{id:`widget-type`,label:K(`engine.inspector.widget.type`,o),children:(0,X.jsxs)(yr,{value:x.type??`metric`,onValueChange:e=>C({type:e}),disabled:a,children:[(0,X.jsx)(An,{id:`widget-type`,children:(0,X.jsx)($t,{})}),(0,X.jsx)(rr,{children:W_.map(e=>(0,X.jsx)(In,{value:e.value,children:e.label},e.value))})]})}),(0,X.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:K(`engine.inspector.widget.datasetSection`,o)}),(0,X.jsxs)(J_,{id:`widget-dataset`,label:K(`engine.inspector.widget.dataset`,o),children:[(0,X.jsx)($a,{value:d,onCommit:e=>C({dataset:e||void 0}),options:g,loading:m.loading,placeholder:K(`engine.inspector.widget.datasetPlaceholder`,o),searchPlaceholder:K(`engine.inspector.widget.datasetPlaceholder`,o),disabled:a,mono:!0}),(0,X.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:K(`engine.inspector.widget.datasetHint`,o)})]}),d&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Aa,{label:K(`engine.inspector.widget.dimensions`,o),emptyText:K(`engine.inspector.widget.dimensionsHint`,o),names:f,options:v,loading:h.loading,error:h.error,readOnly:a,onCommit:e=>C({dimensions:e})}),(0,X.jsx)(Aa,{label:K(`engine.inspector.widget.values`,o),emptyText:K(`engine.inspector.widget.valuesHint`,o),names:p,options:_,loading:h.loading,error:h.error,readOnly:a,onCommit:e=>C({values:e})})]})]}),b.length>0&&(0,X.jsxs)(`div`,{className:`space-y-3 rounded-md border p-3`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:K(`engine.inspector.widget.filterBindingsSection`,o)}),(0,X.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:K(`engine.inspector.widget.filterBindingsHint`,o)}),b.map(e=>{let t=x.filterBindings,n=t?.[e.name],r=n===!1,i=typeof n==`string`?n:``,s=n=>{let r={...t??{}};n===void 0?delete r[e.name]:r[e.name]=n,C({filterBindings:Object.keys(r).length>0?r:void 0})};return(0,X.jsxs)(`div`,{className:`space-y-1.5`,"data-testid":`widget-filter-binding-${e.name}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(V,{className:`text-xs font-medium text-muted-foreground truncate`,children:e.label||e.name}),(0,X.jsx)(Y,{label:K(`engine.inspector.widget.filterBindingApply`,o),value:!r,onCommit:e=>s(e?void 0:!1),disabled:a})]}),!r&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)($a,{value:i,onCommit:e=>s(e||void 0),options:y,placeholder:G(`engine.inspector.widget.filterBindingDefault`,o,{field:e.field}),searchPlaceholder:`Search fields…`,disabled:a,mono:!0})}),i&&!a&&(0,X.jsx)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 shrink-0 px-2 text-[10px] text-muted-foreground`,onClick:()=>s(void 0),children:K(`engine.inspector.widget.filterBindingReset`,o)})]})]},e.name)})]}),(0,X.jsx)(J_,{id:`widget-color`,label:K(`engine.inspector.widget.color`,o),children:(0,X.jsx)(Ma,{value:x.colorVariant??`default`,onChange:e=>C({colorVariant:e}),disabled:a,options:G_.map(e=>({value:e}))})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsx)(J_,{id:`widget-w`,label:K(`engine.inspector.widget.width`,o),children:(0,X.jsx)(R,{id:`widget-w`,type:`number`,min:1,value:x.layout?.w??1,onChange:e=>C({layout:{...x.layout??{},w:Number(e.target.value)||1}}),disabled:a})}),(0,X.jsx)(J_,{id:`widget-h`,label:K(`engine.inspector.widget.height`,o),children:(0,X.jsx)(R,{id:`widget-h`,type:`number`,min:1,value:x.layout?.h??1,onChange:e=>C({layout:{...x.layout??{},h:Number(e.target.value)||1}}),disabled:a})})]}),!a&&(0,X.jsx)(`div`,{className:`pt-2 border-t`,children:(0,X.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,className:`w-full text-destructive hover:text-destructive`,onClick:()=>{let t=Array.isArray(e.widgets)?[...e.widgets]:[];t.splice(S,1),n({widgets:t}),r()},children:K(`engine.inspector.widget.remove`,o)})})]})}function J_({id:e,label:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(V,{htmlFor:e,className:`text-xs font-medium text-muted-foreground`,children:t}),n]})}function Y_({message:e,onClose:t,locale:n}){return(0,X.jsxs)(`div`,{className:`space-y-3 rounded-md border border-dashed p-4 text-sm text-muted-foreground`,children:[(0,X.jsx)(`p`,{children:e}),(0,X.jsx)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:K(`engine.inspector.widget.close`,n)})]})}var X_={io:`input`,unrepresentable:`any`},Z_=new Set([`widgets`,`label`,`description`,`name`]),Q_,$_=!1;function ev(){if(Q_||$_)return Q_;try{Q_=S(h,X_)}catch(e){$_=!0,typeof console<`u`&&console.warn(`[dashboard-schema] failed to derive Dashboard JSONSchema from spec`,e)}return Q_}var tv;function nv(){if(tv)return tv;if(!(!p||typeof p!=`object`)){try{let e=JSON.parse(JSON.stringify(p));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Z_.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),tv=e}catch(e){typeof console<`u`&&console.warn(`[dashboard-schema] failed to prepare dashboardForm from spec`,e);return}return tv}}var rv=new Set([`name`,`label`,`description`,`widgets`]);function iv({draft:e,onPatch:t,readOnly:n,locale:r,onSelectionChange:i,serverSchema:a}){let o=Z.useCallback(e=>K(e,r),[r]),s=typeof e.label==`string`?e.label:``,c=typeof e.description==`string`?e.description:``,l=Z.useMemo(()=>Array.isArray(e.widgets)?e.widgets:[],[e.widgets]),u=e=>{let n=qi(`widget`,l.map(e=>e?.id).filter(Boolean)),r=af[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`,o={id:n,type:e,title:a,...r?.defaults??{}};t({widgets:Xi(l,o)}),i?.({kind:`widget`,id:n,label:a})},d=e=>{t({widgets:Sa(l,e,null)})},f=(e,n)=>{e!==n&&t({widgets:ia(l,e,n)})},p=(e,t)=>{e?.id&&i?.({kind:`widget`,id:e.id,label:e.title||e.id||`Widget ${t+1}`})},[m,h]=Z.useState(null),[g,_]=Z.useState(null),{schema:v,form:y}=Z.useMemo(()=>pa({bundledSchema:ev(),bundledForm:nv(),serverSchema:a,excludeFields:rv,sectionTitle:K(`engine.inspector.moreFields`,r)}),[a,r]);return(0,X.jsxs)(ca,{kindLabel:o(`engine.inspector.dashboard.kind`),title:String(s||e.name||o(`engine.inspector.dashboard.kind`)),onClose:()=>{},closeLabel:o(`engine.inspector.dashboard.close`),hideClose:!0,children:[(0,X.jsx)(q,{label:o(`engine.inspector.dashboard.label`),value:s,onCommit:e=>t({label:e}),placeholder:o(`engine.inspector.dashboard.labelPlaceholder`),disabled:n}),(0,X.jsx)(q,{label:o(`engine.inspector.dashboard.description`),value:c,onCommit:e=>t({description:e}),placeholder:o(`engine.inspector.dashboard.descriptionPlaceholder`),disabled:n}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:o(`engine.inspector.dashboard.widgets`)}),(0,X.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:l.length})]}),l.length===0?(0,X.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-3 text-center text-[11px] text-muted-foreground`,children:o(`engine.inspector.dashboard.widgetsEmpty`)}):(0,X.jsx)(`div`,{className:`space-y-1`,children:l.map((e,t)=>{let r=af[e?.type]?.icon??cf;return(0,X.jsxs)(`div`,{draggable:!n,onDragStart:()=>h(t),onDragEnd:()=>{h(null),_(null)},onDragOver:e=>{e.preventDefault(),_(t)},onDrop:()=>{m!=null&&m!==t&&f(m,t),h(null),_(null)},className:`group flex items-center gap-2 rounded-md border px-2 py-1.5 text-xs hover:bg-accent`+(g===t&&m!==null&&m!==t?` border-primary`:``),children:[!n&&(0,X.jsx)(nt,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground`}),(0,X.jsx)(r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,X.jsx)(`button`,{type:`button`,className:`min-w-0 flex-1 truncate text-left font-medium`,onClick:()=>p(e,t),title:e?.title||e?.id,children:e?.title||e?.id||`Widget ${t+1}`}),(0,X.jsx)(`code`,{className:`text-[10px] text-muted-foreground`,children:e?.type}),!n&&(0,X.jsx)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 shrink-0 p-0 opacity-0 group-hover:opacity-100`,onClick:()=>d(t),title:o(`engine.inspector.dashboard.removeWidget`),"aria-label":o(`engine.inspector.dashboard.removeWidget`),children:(0,X.jsx)(Qe,{className:`h-3.5 w-3.5`})})]},e?.id??t)})}),!n&&(0,X.jsx)(lf,{onAdd:u,label:o(`engine.inspector.add.widget`)})]}),(0,X.jsx)(`div`,{className:`border-t pt-3`,children:v?(0,X.jsx)(ga,{schema:v,form:y,value:e,hiddenFields:[`name`,`label`,`description`,`widgets`],readOnly:n,onChange:e=>t(e)}):(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:o(`engine.inspector.dashboard.noSchema`)})})]})}var av=new Set([`object`,`object-field`,`flow`,`org-membership-level`,`position`,`node`,`user`,`team`,`queue`,`department`,`manager`,`connector`,`email-template`]);function ov(e){if(!e||typeof e!=`object`)return;let t=e;if(t.source===`data`)return typeof t.object==`string`&&t.object&&typeof t.valueField==`string`&&t.valueField?{source:`data`,object:t.object,valueField:t.valueField}:void 0;if(t.source===`enum`){let e=Array.isArray(t.values)?t.values.filter(e=>typeof e==`string`):[];return e.length?{source:`enum`,values:e}:void 0}if(t.source===`auto`||t.source===`trigger-field`||t.source===`expression`||t.source===`unsupported`)return{source:t.source}}function sv(e){if(!e||typeof e!=`object`)return;let t={};for(let[n,r]of Object.entries(e)){let e=ov(r);e&&(t[n]=e)}return Object.keys(t).length?t:void 0}function cv(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`&&av.has(r)&&(e[n]=r);if(Object.keys(e).length===0)return;let r=sv(t.sources);return{kindFrom:t.kindFrom,map:e,...n,...r?{sources:r}:{}}}if(typeof t.kind==`string`&&av.has(t.kind))return{kind:t.kind,...n}}function lv(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 uv(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function dv(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 fv(e,t){let n=new Set((t??[]).filter(e=>typeof e==`string`));return e.filter(e=>typeof e==`string`).filter(e=>!n.has(e)).map(e=>({value:e,label:lv(e)}))}function pv(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 mv(e){return e.xExpression===`expression`||e.xExpression===`template`?e.xExpression:void 0}function hv(e){if(Array.isArray(e.enum))return{kind:`select`};let t=dv(e);if(t===`boolean`)return{kind:`boolean`};if(t===`number`||t===`integer`)return{kind:`number`};if(t===`string`){let t=e.format===`multiline`,n=mv(e);return n===`expression`?t?{kind:`textarea`,refMode:`expression`}:{kind:`expression`}:n===`template`?t?{kind:`textarea`,refMode:`template`}:{kind:`expression`,refMode:`template`}:{kind:t?`textarea`:`text`}}}var gv=4;function _v(e,t){let n=uv(e.items)?e.items:void 0,r=n?dv(n):void 0;return n&&r===`object`&&uv(n.properties)?t>=gv?null:{kind:`objectList`,columns:vv(n,t+1)}:r===`string`?{kind:`stringList`}:r===`number`||r===`integer`?{kind:`numberList`}:null}function vv(e,t=0){let n=e.properties??{},r=[];for(let[e,i]of Object.entries(n)){if(!uv(i))continue;let n=dv(i);if(n===`array`){let n=_v(i,t);if(n){r.push({key:e,label:i.title||lv(e),kind:n.kind,...n.columns?{columns:n.columns}:{},...i.description?{placeholder:i.description}:{}});continue}}let a,o,s=cv(i);s?a=`reference`:Array.isArray(i.enum)?(a=`select`,o=fv(i.enum,i.xEnumDeprecated)):a=n===`boolean`?`boolean`:mv(i)===`expression`?`expression`:`text`,r.push({key:e,label:i.title||lv(e),kind:a,...o?{options:o}:{},...s?{ref:s}:{},...i.description?{placeholder:i.description}:{}})}return r}function yv(e,t){return{label:e.title||lv(t),...e.description?{help:e.description}:{},...pv(e)?{defaultValue:pv(e)}:{}}}function bv(e){if(!uv(e)||dv(e)!==`object`||!uv(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!uv(r))continue;let e=dv(r);if(e===`array`){let e=uv(r.items)?r.items:void 0,i=e?dv(e):void 0;e&&i===`object`&&uv(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:vv(e),...yv(r,n)}):i===`string`?t.push({id:n,path:[`config`,n],kind:`stringList`,...yv(r,n)}):(i===`number`||i===`integer`)&&t.push({id:n,path:[`config`,n],kind:`numberList`,...yv(r,n)});continue}if(e===`object`&&uv(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>uv(e)),i=e.some(([e,t])=>e===`enabled`&&dv(t)===`boolean`);for(let[a,o]of e){let e=o,s=cv(e),c=s?void 0:hv(e),l=s?`reference`:c?.kind;if(!l)continue;let u=`${n}.${a}`,d=i&&a===`enabled`,f={id:u,path:[`config`,n,a],kind:l,...d?{label:r.title||lv(n),...r.description?{help:r.description}:{},...pv(e)?{defaultValue:pv(e)}:{}}:yv(e,a),...s?{ref:s}:{},...c?.refMode?{refMode:c.refMode}:{},...l===`select`&&Array.isArray(e.enum)?{options:fv(e.enum,e.xEnumDeprecated)}:{},...i&&!d?{showWhen:{field:`${n}.enabled`,equals:[`true`]}}:{}};t.push(f)}continue}if(e===`object`&&r.additionalProperties!==void 0&&r.additionalProperties!==!1){t.push({id:n,path:[`config`,n],kind:`keyValue`,...yv(r,n)});continue}let i=cv(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,...yv(r,n)});continue}let a=hv(r);a&&t.push({id:n,path:[`config`,n],kind:a.kind,...yv(r,n),...a.refMode?{refMode:a.refMode}:{},...a.kind===`select`&&Array.isArray(r.enum)?{options:fv(r.enum,r.xEnumDeprecated)}:{}})}return t}var xv=e=>hp(e),Sv=e=>typeof e.expression==`string`?e.expression.trim():``,Cv=e=>typeof e.label==`string`?e.label.trim():``,wv=e=>typeof e.target==`string`?e.target.trim():``,Tv=e=>{let t=Sv(e);return t===``||t===`true`};function Ev(e){return Array.isArray(e)?e.filter(e=>e&&typeof e==`object`&&!Array.isArray(e)):[]}function Dv(e,t){if(Tv(e))return t.isDefault===!0;let n=Sv(e),r=xv(t.condition);if(n&&r===n)return!0;let i=Cv(e);return i!==``&&t.label===i}var Ov=e=>t=>t.source===e&&t.type!==`fault`&&t.type!==`back`;function kv(e,t){let n=Sv(t),r=Cv(t),i={...e};return r?i.label=r:delete i.label,n&&n!==`true`?(i.condition=n,delete i.isDefault):n===`true`?(i.isDefault=!0,delete i.condition):(delete i.condition,delete i.isDefault),i}function Av(e,t,n){let r=Ev(t),i=Ov(e),a=0;return n.map(e=>{if(!i(e))return e;let t=r[a++];return t?kv(e,t):e})}function jv(e,t,n){let r=Ev(t);if(r.length===0)return r;let i=n.map((e,t)=>t).filter(t=>Ov(e)(n[t])),a=new Set,o=new Map;return r.forEach((e,t)=>{let r=i.find(t=>!a.has(t)&&Dv(e,n[t]));r!==void 0&&(a.add(r),o.set(t,r))}),r.forEach((e,t)=>{if(o.has(t))return;let n=i.find(e=>!a.has(e));n!==void 0&&(a.add(n),o.set(t,n))}),r.map((e,t)=>{let{target:r,...i}=e,a=o.get(t);return a===void 0?i:{...i,target:n[a].target}})}function Mv(e,t,n){let r=Ev(t),i=r.map(e=>{let{target:t,...n}=e;return n});if(!r.some(e=>wv(e)!==``))return{conditions:i,edges:Av(e,i,n)};let a=n.map((e,t)=>t).filter(t=>Ov(e)(n[t])),o=new Set,s=new Map,c=[(e,t)=>t.target===wv(e)&&Dv(e,t),(e,t)=>t.target===wv(e),(e,t)=>Dv(e,t)];for(let e of c)r.forEach((t,r)=>{if(s.has(r)||wv(t)===``)return;let i=a.find(r=>!o.has(r)&&e(t,n[r]));i!==void 0&&(o.add(i),s.set(r,i))});let l=new Map,u=[],d=new Set;return r.forEach((t,r)=>{let i=wv(t);if(i===``){let e=a.find(e=>!o.has(e)&&Dv(t,n[e]));e!==void 0&&(o.add(e),d.add(e));return}let c=s.get(r);c===void 0?u.push(kv({source:e,target:i},t)):l.set(c,kv({...n[c],target:i},t))}),{conditions:i,edges:n.map((e,t)=>d.has(t)?null:l.get(t)??e).filter(e=>e!==null).concat(u)}}function Nv(e,t){return t===`template`?`{${e}}`:e}function Pv(e,t,n,r,i){let a=Nv(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 Fv=`Insert a reference`,Iv=`Search references…`,Lv=`No matching references.`;function Rv({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=Z.useRef(null),p=Z.useRef({start:0,end:0}),[m,h]=Z.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}=Pv(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,X.jsxs)(`div`,{className:H(`relative`,d),children:[c?(0,X.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,X.jsx)(R,{ref:g,...b,className:H(`h-8 pr-8 text-sm`,u&&`font-mono`)}),y&&!s&&(0,X.jsxs)(kt,{open:m,onOpenChange:h,children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,"aria-label":Fv,title:Fv,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,X.jsx)(me,{className:`h-3.5 w-3.5`})})}),(0,X.jsx)(he,{align:`end`,className:`w-72 p-0`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,X.jsxs)(ie,{children:[(0,X.jsx)(jr,{placeholder:Iv,className:`h-9`}),(0,X.jsxs)(rn,{children:[(0,X.jsx)(Rr,{children:Lv}),a.map(e=>(0,X.jsx)(ur,{heading:e.label,children:e.refs.map(t=>(0,X.jsxs)(Hn,{value:`${t.token} ${t.label} ${t.detail??``}`,onSelect:()=>v(t.token),className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:`truncate font-mono text-xs`,children:Nv(t.token,i)}),t.detail&&(0,X.jsx)(`span`,{className:`shrink-0 truncate text-[10px] text-muted-foreground`,children:t.detail})]},`${e.id}:${t.token}`))},e.id))]})]})})]})]})}function zv({value:e,role:t,scopeGroups:n}){let r=t===`template`?null:Cm(t,e);if(r)return(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:r.message});let i=n&&n.length>0?gm(n.flatMap(e=>e.refs)):null,a=i?ym(e,t,i):[];return a.length>0?(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:bm(a)}):null}function Bv(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Vv(e){return e==null?``:typeof e==`string`?e:typeof e==`number`||typeof e==`boolean`?String(e):JSON.stringify(e)}function Hv(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 Uv(e){return Array.isArray(e)?e.filter(e=>Bv(e)).map(e=>{let t=e.variable??e.name??e.key;return[typeof t==`string`?t:``,e.value]}):Bv(e)?Object.entries(e):[]}function Wv(e,t){let n=[...t];return Uv(e).map(([e,t])=>{let r=qi(`kv`,n);return n.push(r),{id:r,key:e,raw:Vv(t)}})}function Gv(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:Hv(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]=Hv(t.raw))}return r}function Kv(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 qv({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=Z.useMemo(()=>Kv(Gv(Wv(t,[]),d)),[t,d]),[p,m]=Z.useState(()=>Wv(t,[])),h=Z.useRef(f);Z.useEffect(()=>{f!==h.current&&(m(Wv(t,[])),h.current=f)},[f,t]);let g=e=>{let t=Gv(e,d);h.current=Kv(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:qi(`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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[p.length===0&&(0,X.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:l}),p.map(e=>(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(R,{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,X.jsx)(Rv,{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,X.jsx)(W,{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,X.jsx)(Qe,{className:`h-3.5 w-3.5`})})]}),(0,X.jsx)(zv,{value:e.raw,role:`template`,scopeGroups:u})]},e.id))]}),(0,X.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:v,disabled:r,children:[(0,X.jsx)(B,{className:`mr-1 h-3.5 w-3.5`}),a]}),i&&(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:i})]})}function Jv(e,t){let n=[...t];return e.map(e=>{let t=qi(`sl`,n);return n.push(t),{id:t,value:e}})}function Yv(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function Xv({label:e,value:t,onCommit:n,disabled:r,addLabel:i,itemLabel:a,removeLabel:o,emptyLabel:s}){let c=Z.useMemo(()=>Array.isArray(t)?t.map(e=>String(e)):[],[t]),[l,u]=Z.useState(()=>Jv(c,[])),d=Z.useRef(JSON.stringify(c));Z.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(Jv(c,[])),d.current=e)},[c]);let f=e=>{let t=Yv(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:qi(`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,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[l.length===0&&(0,X.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),l.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(R,{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,X.jsx)(W,{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,X.jsx)(Qe,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,X.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:m,disabled:r,children:[(0,X.jsx)(B,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}var Zv={object:`object`,flow:`flow`,connector:`connector`,"email-template":`email_template`},Qv=Object.fromEntries(Object.entries({user:{displayField:`name`,picker:`search`,subtitle:[`email`]},team:{displayField:`name`},department:{displayField:`name`},position:{displayField:`label`}}).flatMap(([e,t])=>{let n=x[e];return!n||n.source!==`data`?[]:[[e,{object:n.object,valueField:n.valueField,...t}]]})),$v=[{value:`owner`,label:`Owner`},{value:`admin`,label:`Admin`},{value:`member`,label:`Member`}];function ey(e,t){if(e){if(e.kind)return{kind:e.kind,objectSource:e.objectSource,connectorSource:e.connectorSource,source:e.sources?.[e.kind]};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,source:typeof n==`string`?e.sources?.[n]:void 0}}}}function ty(e){if(!e)return;let t=Qv[e.kind],n=e.source;if(!(n&&n.source!==`data`))return n?{object:n.object,valueField:n.valueField,displayField:t?.displayField??n.valueField,...t?.picker?{picker:t.picker}:{},...t?.subtitle?{subtitle:t.subtitle}:{}}:t}function ny(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 ry(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?ny((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):ny(n.node,r)}function iy(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 ay(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 oy(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e.name==`string`&&!!e.name).map(e=>{let t=typeof e.label==`string`&&e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name;return{value:e.name,label:e.origin===`declarative`?`${t} · declarative`:t}}):[]}function sy(e){let t=Ui(),[n,r]=Z.useState({options:[],loading:!!e});return Z.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 cy(e){let[t,n]=Z.useState({options:[],loading:!!e});return Z.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:ay(a?.actions),loading:!1})}).catch(()=>{t||n({options:[],loading:!1})}),()=>{t=!0}},[e]),t}function ly(e){let[t,n]=Z.useState({options:[]});return Z.useEffect(()=>{if(!e){n({options:[]});return}let t=!1;return fetch(`/api/v1/automation/connectors`,{credentials:`include`,headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(e=>{if(t)return;let r=e?.data?.connectors??e?.connectors??[];n({options:oy(r)})}).catch(()=>{t||n({options:[]})}),()=>{t=!0}},[e]),t}function uy({binding:e,value:t,onPick:n,onCommit:r,onBlur:i,disabled:a,placeholder:o}){let s=k(),[c,l]=Z.useState(!1),u=t==null?``:String(t);return!s||c?(0,X.jsxs)(`div`,{className:`flex w-full items-center gap-1`,children:[(0,X.jsx)(R,{value:u,onChange:e=>r(e.target.value),onBlur:i,onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},placeholder:o,disabled:a,className:`h-8 flex-1 text-sm`}),s&&(0,X.jsx)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>l(!1),disabled:a,"aria-label":`Pick from records`,title:`Pick from records`,children:(0,X.jsx)(We,{className:`h-3.5 w-3.5`})})]}):(0,X.jsxs)(`div`,{className:`flex w-full items-center gap-1`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(ze,{value:u||null,onChange:e=>n(e==null?``:String(e)),readonly:a,dataSource:s,field:{type:`lookup`,name:`value`,reference_to:e.object,display_field:e.displayField,id_field:e.valueField,multiple:!1,allow_create:!1,placeholder:o,...e.picker?{picker:e.picker}:{},...e.subtitle?{subtitle:e.subtitle}:{}}})}),(0,X.jsx)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>l(!0),disabled:a,"aria-label":`Enter value manually`,title:`Enter value manually`,children:(0,X.jsx)(pe,{className:`h-3.5 w-3.5`})})]})}function dy({resolved:e,value:t,onCommit:n,onBlur:r,onSelect:i,disabled:a,placeholder:o,context:s,showHint:c=!0}){let l=Z.useId(),u=s??{draft:{},node:null},d=e?.kind,f=i??(e=>{n(e),r?.()}),p=e?ry(e.kind,e.objectSource,u):void 0,{fields:m}=xa(d===`object-field`?p:void 0),h=e?iy(e.kind,e.connectorSource,u):void 0,{options:g}=cy(d===`connector-action`?h:void 0),{options:_}=ly(d===`connector`),v=d&&d!==`object-field`&&d!==`node`&&d!==`connector-action`&&d!==`connector`?Zv[d]:void 0,{options:y}=sy(v),b=Z.useMemo(()=>{if(d===`object-field`)return m.map(e=>({value:e.name,label:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name}));if(d===`connector-action`)return g;if(d===`connector`)return _;if(d===`node`){let e=Array.isArray(u.draft.nodes)?u.draft.nodes:[],t=typeof u.node?.id==`string`?u.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 v?y:[]},[d,v,m,g,_,y,u.draft,u.node]),x=d===`object-field`&&!p,S=d===`connector-action`&&!h,C=ty(e);if(C)return(0,X.jsx)(uy,{binding:C,value:t,onPick:f,onCommit:n,onBlur:r,disabled:a,placeholder:o});if(d===`org-membership-level`){let e=t==null?``:String(t),n=e&&!$v.some(t=>t.value===e)?[...$v,{value:e,label:`${e} (invalid)`}]:$v;return(0,X.jsxs)(yr,{value:e||void 0,onValueChange:f,disabled:a,children:[(0,X.jsx)(An,{className:`h-8 w-full text-sm`,children:(0,X.jsx)($t,{placeholder:o??`—`})}),(0,X.jsx)(rr,{children:n.map(e=>(0,X.jsx)(In,{value:e.value,children:e.label},e.value))})]})}return d===`manager`?(0,X.jsxs)(`div`,{className:`w-full space-y-1`,children:[(0,X.jsx)(R,{value:t==null?``:String(t),disabled:!0,placeholder:`Resolved automatically`,className:`h-8 text-sm`}),(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Resolved at runtime from the submitter's manager — no value needed.`})]}):d===`queue`?(0,X.jsxs)(`div`,{className:`w-full space-y-1`,children:[(0,X.jsx)(R,{value:t==null?``:String(t),onChange:e=>n(e.target.value),onBlur:r,placeholder:o,disabled:a,className:`h-8 text-sm`}),(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,children:`Queue approvers are not supported by the runtime yet — this slot resolves to nobody.`})]}):(0,X.jsxs)(`div`,{className:`w-full space-y-1`,children:[(0,X.jsx)(R,{list:b.length?l:void 0,value:t==null?``:String(t),onChange:e=>n(e.target.value),onBlur:r,placeholder:o,disabled:a,className:`h-8 text-sm`}),b.length>0&&(0,X.jsx)(`datalist`,{id:l,children:b.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))}),c&&d===`object-field`&&p&&(0,X.jsxs)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:[`Fields of `,p,`.`]}),c&&x&&(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Set the flow’s trigger object (on the Start node) to list fields.`}),c&&d===`connector-action`&&h&&(0,X.jsxs)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:[`Actions of `,h,`.`]}),c&&S&&(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:`Choose a Connector above to list its actions.`})]})}function fy({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=ey(e.ref,e=>ny(a,e));return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e.label}),(0,X.jsx)(dy,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function py(e){return e===`stringList`||e===`numberList`||e===`objectList`}function my(e,t){let n=[];return e.map(e=>{let r=qi(`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:py(n.kind)?i[n.key]=Array.isArray(t)?t:[]:t==null?i[n.key]=``:i[n.key]=String(t)}return{id:r,values:i}})}function hy(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):py(n.kind)?Array.isArray(t)&&t.length>0&&(e[n.key]=t,i=!0):typeof t==`string`&&t.trim()!==``&&(e[n.key]=t.trim(),i=!0)}i&&n.push(e)}return n}function gy({label:e,columns:t,value:n,onCommit:r,disabled:i,addLabel:a,removeLabel:o,emptyLabel:s,itemLabel:c,context:l,scopeGroups:u,approvalScopeGroups:d}){let f=Z.useMemo(()=>Array.isArray(n)?n.filter(e=>e&&typeof e==`object`):[],[n]),[p,m]=Z.useState(()=>my(f,t)),h=Z.useRef(JSON.stringify(f));Z.useEffect(()=>{let e=JSON.stringify(f);e!==h.current&&(m(my(f,t)),h.current=e)},[f,t]);let g=e=>{let n=hy(e,t);h.current=JSON.stringify(n),r(n.length?n:void 0)},_=(e,t,n)=>{m(r=>r.map(r=>r.id===e?{...r,values:{...r.values,[t]:n}}:r))},[v,y]=Z.useState(0);Z.useEffect(()=>{v!==0&&g(p)},[v]);let b=(e,t,n)=>{m(r=>r.map(r=>r.id===e?{...r,values:{...r.values,[t]:n}}:r)),y(e=>e+1)},x=()=>{let e={};for(let n of t)e[n.key]=n.kind===`boolean`?!1:py(n.kind)?[]:``;m(t=>[...t,{id:qi(`ol`,t.map(e=>e.id)),values:e}])},S=e=>{m(t=>t.filter(t=>t.id!==e)),y(e=>e+1)};return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[p.length===0&&(0,X.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:s}),p.map(e=>(0,X.jsxs)(`div`,{className:`rounded border bg-muted/30 p-2`,children:[(0,X.jsx)(`div`,{className:`mb-1 flex justify-end`,children:(0,X.jsx)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-muted-foreground`,onClick:()=>S(e.id),disabled:i,"aria-label":o,title:o,children:(0,X.jsx)(Qe,{className:`h-3.5 w-3.5`})})}),(0,X.jsx)(`div`,{className:`space-y-1.5`,children:t.map(t=>{if(t.kind===`stringList`||t.kind===`numberList`){let n=e.values[t.key],r=Array.isArray(n)?n:[];return(0,X.jsx)(`div`,{className:`border-l-2 border-muted/60 pl-2`,children:(0,X.jsx)(Xv,{label:t.label,value:t.kind===`numberList`?r.map(e=>String(e)):r,onCommit:n=>{if(t.kind===`numberList`){let r=(n??[]).map(e=>Number(String(e).trim())).filter(e=>Number.isFinite(e));b(e.id,t.key,r)}else b(e.id,t.key,n??[])},disabled:i,addLabel:a,itemLabel:c??t.label,removeLabel:o,emptyLabel:s})},t.key)}if(t.kind===`objectList`){let n=e.values[t.key],r=Array.isArray(n)?n:[];return(0,X.jsx)(`div`,{className:`border-l-2 border-muted/60 pl-2`,children:(0,X.jsx)(gy,{label:t.label,columns:t.columns??[],value:r,onCommit:n=>b(e.id,t.key,n??[]),disabled:i,addLabel:a,removeLabel:o,emptyLabel:s,itemLabel:c,context:l,scopeGroups:u})},t.key)}return(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(V,{className:`w-24 shrink-0 text-[11px] text-muted-foreground`,children:t.label}),t.kind===`boolean`?(0,X.jsx)(jn,{checked:e.values[t.key]===!0,onCheckedChange:n=>b(e.id,t.key,n===!0),disabled:i}):t.kind===`reference`?(()=>{let n=ey(t.ref,t=>e.values[t]),r=t.ref?.kindFrom?String(e.values[t.ref.kindFrom]??``):``;if(n===void 0&&r===`expression`){let n=typeof e.values[t.key]==`string`?e.values[t.key]:``;return(0,X.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,X.jsx)(Rv,{mode:`expression`,mono:!0,value:n,onValueChange:n=>_(e.id,t.key,n),onBlur:()=>g(p),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},groups:d??[],placeholder:t.placeholder??`current.<field> · trigger.<field> · vars.<node>.<key>`,disabled:i}),(0,X.jsx)(zv,{value:n,role:`value`,scopeGroups:d})]})}return(0,X.jsx)(`div`,{className:`flex-1`,children:(0,X.jsx)(dy,{resolved:n,value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onCommit:n=>_(e.id,t.key,typeof n==`string`?n:``),onBlur:()=>g(p),onSelect:n=>b(e.id,t.key,n),placeholder:t.placeholder,disabled:i,context:l,showHint:!1})})})():t.kind===`select`?(()=>{let n=typeof e.values[t.key]==`string`?e.values[t.key]:``,r=t.options??[],a=n&&!r.some(e=>e.value===n)?[...r,{value:n,label:`${n} (deprecated)`}]:r;return(0,X.jsx)(`div`,{className:`flex-1`,children:(0,X.jsxs)(yr,{value:n||void 0,onValueChange:n=>b(e.id,t.key,n),disabled:i,children:[(0,X.jsx)(An,{className:`h-8 w-full text-xs`,children:(0,X.jsx)($t,{placeholder:t.placeholder??`—`})}),(0,X.jsx)(rr,{children:a.map(e=>(0,X.jsx)(In,{value:e.value,children:e.label},e.value))})]})})})():t.kind===`expression`?(0,X.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,X.jsx)(Rv,{mode:`expression`,mono:!0,value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onValueChange:n=>_(e.id,t.key,n),onBlur:()=>g(p),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},groups:u??[],placeholder:t.placeholder,disabled:i}),(0,X.jsx)(zv,{value:typeof e.values[t.key]==`string`?e.values[t.key]:``,role:`predicate`,scopeGroups:u})]}):(0,X.jsx)(R,{value:typeof e.values[t.key]==`string`?e.values[t.key]:``,onChange:n=>_(e.id,t.key,n.target.value),onBlur:()=>g(p),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,X.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:x,disabled:i,children:[(0,X.jsx)(B,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}function _y({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a,scopeGroups:o,approvalScopeGroups:s}){let c=e.refMode??(e.kind===`expression`?`expression`:`template`),l=(()=>{switch(e.kind){case`reference`:return(0,X.jsx)(fy,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,X.jsx)(qv,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:K(`engine.inspector.flowNode.kv.add`,i),keyLabel:K(`engine.inspector.flowNode.kv.key`,i),valueLabel:K(`engine.inspector.flowNode.kv.value`,i),removeLabel:K(`engine.inspector.flowNode.kv.remove`,i),emptyLabel:K(`engine.inspector.flowNode.kv.empty`,i),scopeGroups:o});case`stringList`:return(0,X.jsx)(Xv,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:K(`engine.inspector.flowNode.list.add`,i),itemLabel:K(`engine.inspector.flowNode.list.item`,i),removeLabel:K(`engine.inspector.flowNode.list.remove`,i),emptyLabel:K(`engine.inspector.flowNode.list.empty`,i)});case`numberList`:return(0,X.jsx)(Xv,{label:e.label,value:Array.isArray(t)?t.map(e=>String(e)):t,onCommit:e=>{if(e==null)return n(void 0);let t=e.map(e=>Number(String(e).trim())).filter(e=>Number.isFinite(e));n(t.length?t:void 0)},disabled:r,addLabel:K(`engine.inspector.flowNode.list.add`,i),itemLabel:K(`engine.inspector.flowNode.list.item`,i),removeLabel:K(`engine.inspector.flowNode.list.remove`,i),emptyLabel:K(`engine.inspector.flowNode.list.empty`,i)});case`objectList`:return(0,X.jsx)(gy,{label:e.label,columns:e.columns??[],value:t,onCommit:e=>n(e),disabled:r,addLabel:K(`engine.inspector.flowNode.list.add`,i),removeLabel:K(`engine.inspector.flowNode.list.remove`,i),emptyLabel:K(`engine.inspector.flowNode.list.empty`,i),itemLabel:K(`engine.inspector.flowNode.list.item`,i),context:a,scopeGroups:o,approvalScopeGroups:s});case`number`:return(0,X.jsx)(Na,{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,X.jsx)(Y,{label:e.label,value:t===!0,onCommit:e=>n(e),disabled:r});case`select`:return(()=>{let i=t==null?``:String(t),a=e.options??[],o=i&&!a.some(e=>e.value===i)?[...a,{value:i,label:`${i} (deprecated)`}]:a;return(0,X.jsx)(J,{label:e.label,value:i,options:o,onCommit:e=>n(e),disabled:r})})();case`textarea`:return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e.label}),(0,X.jsx)(Rv,{multiline:!0,rows:4,mode:c,value:t==null?``:String(t),onValueChange:e=>n(e),groups:o??[],placeholder:e.placeholder,disabled:r})]});default:return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e.label}),(0,X.jsx)(Rv,{mode:c,mono:e.kind===`expression`,value:t==null?``:String(t),onValueChange:e=>n(e),groups:o??[],placeholder:e.placeholder,disabled:r})]})}})(),u=c===`template`,d=e.kind===`expression`&&!u?Cm(`predicate`,t):null,f=e.kind===`expression`?u?`template`:`predicate`:c===`template`&&(e.kind===`text`||e.kind===`textarea`)?`template`:null,p=!d&&f&&o&&o.length>0?ym(t,f,gm(o.flatMap(e=>e.refs))):[];return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[l,d&&(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:d.message}),!d&&p.length>0&&(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:bm(p,i)}),e.help&&!d&&p.length===0&&(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:e.help})]})}var vy=[`variables`,`outputs`,`loop`,`trigger`],yy={variables:`Flow variables`,outputs:`Upstream outputs`,loop:`Loop item`,trigger:`Trigger record`};function by(e,t,n){let r=Z.useMemo(()=>fm(e??{},t),[e,t]),{fields:i,loading:a}=xa(r.trigger?.objectName);return Z.useMemo(()=>{let e=[...r.refs];n&&n.length&&e.push(...n),r.trigger&&e.push(...pm(r.trigger,i));let t=new Set,o=e.filter(e=>t.has(e.token)?!1:(t.add(e.token),!0)),s=vy.map(e=>({id:e,label:yy[e],refs:o.filter(t=>t.group===e)})).filter(e=>e.refs.length>0),c=[],l=[];for(let e of i){if(!e?.name)continue;let t=e.label&&e.label!==e.name?e.label:e.type;c.push({token:`current.${e.name}`,label:`current.${e.name}`,detail:t,group:`approval_current`}),l.push({token:`trigger.${e.name}`,label:`trigger.${e.name}`,detail:t,group:`approval_trigger`})}let u=o.filter(e=>e.group===`variables`||e.group===`outputs`||e.group===`loop`).map(e=>({...e,token:`vars.${e.token}`,label:`vars.${e.token}`,group:`approval_vars`}));return u.push({token:`vars.previous`,label:`vars.previous`,detail:`pre-update row`,group:`approval_vars`}),{groups:s,refs:o,approvalExpressionGroups:[{id:`approval_current`,label:`Current record (live at node entry)`,refs:c},{id:`approval_trigger`,label:`Trigger snapshot (at submit)`,refs:l},{id:`approval_vars`,label:`Flow variables`,refs:u}].filter(e=>e.refs.length>0),loading:!!r.trigger&&a,isEmpty:o.length===0}},[r,i,a,n])}function xy(e){return e.kind===`objectList`&&tm(e)===`conditions`&&(e.columns??[]).some(e=>e.key===`target`)}function Sy(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function Cy(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=Cy(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function wy({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=Z.useMemo(()=>nh(t,e),[t,e]),s=o?.node??null,c=zp(),l=Z.useMemo(()=>o?.nested&&o.container?um(o.container).filter(e=>e.group===`loop`):[],[o]),{groups:u,approvalExpressionGroups:d}=by(t,o?.scopeAnchorId,l),f=Z.useMemo(()=>{let e=s?.type?c[s.type]:void 0,t=Xp(e===void 0?null:bv(e),s?.type);return $p(s?.type,t,i)},[c,s?.type,i]),p=Sy(s),m=f.filter(e=>nm(e,s,f)),h=Z.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]),g=Z.useMemo(()=>{let e=new Set;for(let t of f){let n=tm(t);n&&e.add(n),t.fallbackPath&&t.fallbackPath.length>=2&&t.fallbackPath[0]===`config`&&e.add(t.fallbackPath[1])}return e},[f]),_=Z.useMemo(()=>{let e=Object.fromEntries(Object.entries(p).filter(([e])=>!g.has(e)));return Object.keys(e).length?JSON.stringify(e,null,2):``},[s,g]),[v,y]=Z.useState(_),[b,x]=Z.useState(null),[S,C]=Z.useState(_.trim()!==``),[w,T]=Z.useState(!1);if(Z.useEffect(()=>{y(_),x(null),C(_.trim()!==``),T(!1)},[_]),!s){let t=(e.kind===`nested-node`?Jm(e.id):null)?.nodeId??e.id;return(0,X.jsx)(ca,{kindLabel:K(`engine.inspector.flowNode.kind`,i),title:e.label??t,onClose:r,closeLabel:K(`engine.inspector.flowNode.close`,i),children:(0,X.jsx)(ma,{message:t})})}let E=e=>{let t=o?.write({...s,...e});t&&n(t)},D=_.trim()!==``,O=s.type===`screen`||s.type===`user_task`,k=(e,r)=>{if(!o)return;let i=e.path,a=r,c;if(!o.nested){let n=Array.isArray(t.edges)?t.edges:[];if(xy(e)){let e=Mv(s.id,r,n);a=e.conditions.length?e.conditions:void 0,c=e.edges}else s.type===`decision`&&i.length===2&&i[0]===`config`&&i[1]===`conditions`&&(c=Av(s.id,r,n))}let l=Cy(s,i,a);e.fallbackPath&&(l=Cy(l,e.fallbackPath,void 0));let u=o.write(l);u&&(c&&(u.edges=c),n(u))},A=()=>{try{let e=v.trim()===``?{}:JSON.parse(v);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Must be a JSON object`);let t=Object.fromEntries(Object.entries(p).filter(([e])=>g.has(e))),r=Object.fromEntries(Object.entries(e).filter(([e])=>!g.has(e))),i={...t,...r};x(null);let a={...s};Object.keys(i).length===0?delete a.config:a.config=i;let c=o?.write(a);c&&n(c)}catch(e){x(String(e.message))}},j=()=>{let e=o?.write(null);e&&n(e),r()},M=rm.includes(s.type)?[...rm]:[...rm,s.type??``].filter(Boolean),ee=!!o?.nested;return(0,X.jsxs)(ca,{kindLabel:K(`engine.inspector.flowNode.kind`,i),title:s.label||s.id,onClose:r,closeLabel:K(`engine.inspector.flowNode.close`,i),footer:ee?void 0:(0,X.jsx)(sa,{label:K(`engine.inspector.flowNode.remove`,i),onClick:j,disabled:a}),children:[ee&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 text-[11px] text-muted-foreground`,"aria-label":`nested node location`,children:[(0,X.jsx)(`span`,{className:`max-w-[45%] truncate font-medium`,children:o?.container?.label||o?.container?.id}),(0,X.jsx)(`span`,{"aria-hidden":!0,children:`›`}),(0,X.jsx)(`span`,{className:`truncate`,children:o?.regionLabel}),(0,X.jsx)(`span`,{"aria-hidden":!0,children:`›`}),(0,X.jsx)(`span`,{className:`max-w-[45%] truncate font-medium text-foreground`,children:s.label||s.id})]}),(0,X.jsx)(q,{label:K(`engine.inspector.flowNode.id`,i),value:s.id,onCommit:e=>E({id:e}),disabled:a||ee,mono:!0}),ee&&(0,X.jsx)(`p`,{className:`-mt-1 text-[11px] leading-snug text-muted-foreground`,children:K(`engine.inspector.flowNode.nestedIdHint`,i)}),(0,X.jsx)(q,{label:K(`engine.inspector.flowNode.label`,i),value:s.label??``,onCommit:e=>E({label:e}),disabled:a}),(0,X.jsx)(J,{label:K(`engine.inspector.flowNode.type`,i),value:s.type,options:M.map(e=>({value:e,label:Mi(e,i,e)})),onCommit:e=>E({type:e}),disabled:a}),(0,X.jsx)(q,{label:K(`engine.inspector.flowNode.description`,i),value:s.description??``,onCommit:e=>E({description:e||void 0}),disabled:a}),f.length===0?(0,X.jsx)(`p`,{className:`pt-1 text-xs italic text-muted-foreground`,children:K(`engine.inspector.flowNode.noConfig`,i)}):m.length>0&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,X.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:K(`engine.inspector.flowNode.configuration`,i)}),(0,X.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),m.map(e=>{let n=xy(e),r=ee&&n?{...e,columns:(e.columns??[]).filter(e=>e.key!==`target`)}:e;return(0,X.jsx)(_y,{field:r,value:n&&!ee?jv(s.id,em(s,e),Array.isArray(t.edges)?t.edges:[]):em(s,r),onCommit:t=>k(e,t),disabled:a,locale:i,context:{draft:t,node:s},scopeGroups:u,approvalScopeGroups:d},e.id)}),O&&(0,X.jsx)(gh,{node:s,variables:h,className:`mt-1`}),D||w?(0,X.jsxs)(`details`,{className:`group rounded border bg-muted/20`,open:S,onToggle:e=>C(e.target.open),children:[(0,X.jsx)(`summary`,{className:`cursor-pointer select-none px-2 py-1.5 text-xs font-medium text-muted-foreground`,children:K(`engine.inspector.flowNode.advanced`,i)}),(0,X.jsxs)(`div`,{className:`space-y-1 border-t p-2`,children:[(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:K(`engine.inspector.flowNode.advancedHint`,i)}),(0,X.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),onBlur:A,disabled:a,rows:6,placeholder:`{ }`,className:`w-full rounded border bg-background px-2 py-1.5 font-mono text-xs`}),b&&(0,X.jsx)(`div`,{className:`text-xs text-destructive`,children:b})]})]}):!a&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{T(!0),C(!0)},className:`inline-flex items-center gap-1 self-start text-[11px] text-muted-foreground transition-colors hover:text-foreground`,children:[(0,X.jsx)(B,{className:`h-3 w-3`}),K(`engine.inspector.flowNode.advanced`,i)]})]})}function Ty({label:e,value:t}){return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,X.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 Ey({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)=>mp(t,n)===e.id),c=s>=0?o[s]:null,{groups:l}=by(t,c?.source);if(!c)return(0,X.jsx)(ca,{kindLabel:K(`engine.inspector.flowEdge.kind`,i),title:e.label??e.id,onClose:r,closeLabel:K(`engine.inspector.flowEdge.close`,i),children:(0,X.jsx)(ma,{message:K(`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:Sa(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=hp(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,X.jsxs)(ca,{kindLabel:K(`engine.inspector.flowEdge.kind`,i),title:e.label??`${c.source} → ${c.target}`,onClose:r,closeLabel:K(`engine.inspector.flowEdge.close`,i),footer:(0,X.jsx)(sa,{label:K(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:Sa(o,s,null)}),r()},disabled:a}),children:[(0,X.jsx)(Ty,{label:K(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,X.jsx)(Ty,{label:K(`engine.inspector.flowEdge.target`,i),value:c.target}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,X.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:K(`engine.inspector.flowEdge.routing`,i)}),(0,X.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),p.length>0&&(0,X.jsx)(J,{label:K(`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,X.jsx)(J,{label:K(`engine.inspector.flowEdge.approvalBranch`,i),value:b,options:[{value:`approve`,label:K(`engine.inspector.flowEdge.branchApprove`,i)},{value:`reject`,label:K(`engine.inspector.flowEdge.branchReject`,i)},{value:`revise`,label:K(`engine.inspector.flowEdge.branchRevise`,i)},{value:``,label:K(`engine.inspector.flowEdge.branchCustom`,i)}],onCommit:e=>{e&&u({label:e})},disabled:a}),(0,X.jsx)(q,{label:K(`engine.inspector.flowEdge.label`,i),value:c.label??``,onCommit:e=>u({label:e}),placeholder:K(`engine.inspector.flowEdge.labelHint`,i),disabled:a||d}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:K(`engine.inspector.flowEdge.condition`,i)}),(0,X.jsx)(Rv,{mode:`expression`,mono:!0,value:hp(c.condition)??``,onValueChange:e=>u({condition:e||void 0}),groups:l,placeholder:K(`engine.inspector.flowEdge.conditionHint`,i),disabled:a||d})]}),(()=>{let e=d?null:Cm(`predicate`,c.condition);if(e)return(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:e.message});let t=d?[]:ym(hp(c.condition),`predicate`,gm(l.flatMap(e=>e.refs)));return t.length>0?(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:bm(t,i)}):null})(),(0,X.jsx)(Y,{label:K(`engine.inspector.flowEdge.isDefault`,i),value:d,onCommit:e=>u(e?{isDefault:!0,condition:void 0,label:void 0}:{isDefault:!1}),disabled:a}),(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:K(`engine.inspector.flowEdge.hint`,i)}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,X.jsx)(`span`,{className:`text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:K(`engine.inspector.flowEdge.connection`,i)}),(0,X.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),(0,X.jsx)(J,{label:K(`engine.inspector.flowEdge.type`,i),value:x,options:[{value:`default`,label:K(`engine.inspector.flowEdge.typeDefault`,i)},{value:`conditional`,label:K(`engine.inspector.flowEdge.typeConditional`,i)},{value:`fault`,label:K(`engine.inspector.flowEdge.typeFault`,i)},{value:`back`,label:K(`engine.inspector.flowEdge.typeBack`,i)}],onCommit:e=>u({type:e}),disabled:a}),c.type===`back`&&(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:K(`engine.inspector.flowEdge.backHint`,i)})]})}function Dy(e){return e.selection.kind===`edge`?(0,X.jsx)(Ey,{...e}):(0,X.jsx)(wy,{...e})}var Oy=[`field`,`label`,`accessorKey`,`header`];function ky(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function Ay(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function jy(e){return e.field??e.accessorKey??``}function My(e){return e.label??e.header??jy(e)}function Ny(e){return Object.keys(e).some(e=>!Oy.includes(e))}function Py(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function Fy({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=ky(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(Ay),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=Z.useMemo(()=>us(),[]),m=Py(c),{fields:h}=xa(m||void 0),g=d?jy(d):``,_=Z.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,X.jsx)(ca,{kindLabel:K(`engine.inspector.viewColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:K(`engine.inspector.viewColumn.close`,a),children:(0,X.jsx)(ma,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=jy(e);return n&&!Ny(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(Sa(u,s.index,{...d,...r}))};return(0,X.jsxs)(ca,{kindLabel:K(`engine.inspector.viewColumn.kind`,a),title:My(d)||e.id,onClose:r,closeLabel:K(`engine.inspector.viewColumn.close`,a),headerActions:(0,X.jsx)(Yi,{index:s.index,total:u.length,onMove:e=>{v(ia(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:My(d)||`columns[${e}]`})},upLabel:K(`engine.inspector.reorder.up`,a),downLabel:K(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,X.jsx)(sa,{label:K(`engine.inspector.viewColumn.remove`,a),onClick:()=>{v(Sa(u,s.index,null)),r()},disabled:o}),children:[c&&(0,X.jsx)(`div`,{className:`pb-1`,children:(0,X.jsx)(qo,{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,X.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[_.length>0?(0,X.jsx)(J,{label:K(`engine.inspector.viewColumn.accessorKey`,a),value:jy(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,X.jsx)(q,{label:K(`engine.inspector.viewColumn.accessorKey`,a),value:jy(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,X.jsx)(q,{label:K(`engine.inspector.viewColumn.header`,a),value:My(d)===jy(d)?``:My(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,X.jsx)(`div`,{className:`border-t pt-3`,children:(0,X.jsx)(ga,{schema:p,value:d,hiddenFields:Oy,readOnly:o,onChange:e=>{v(Sa(u,s.index,e))}})}):null]})]})}function Iy(e){let{selection:t}=e;if(t.kind===`column`)return(0,X.jsx)(Fy,{...e});let n=ys(e.draft,t.id||void 0)??vs(e.draft);return(0,X.jsx)(Ds,{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 Ly(e){let t=vs(e.draft);return(0,X.jsx)(Ds,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}var Ry={io:`input`,unrepresentable:`any`},zy=new Set([`name`,`regions`,`children`]),By,Vy=!1;function Hy(){if(By||Vy)return By;try{By=S(g,Ry)}catch(e){Vy=!0,typeof console<`u`&&console.warn(`[page-schema] failed to derive Page JSONSchema from spec`,e)}return By}var Uy;function Wy(){if(Uy)return Uy;if(!(!v||typeof v!=`object`)){try{let e=JSON.parse(JSON.stringify(v));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!zy.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Uy=e}catch(e){typeof console<`u`&&console.warn(`[page-schema] failed to prune Page authoring form from spec`,e),Uy=v}return Uy}}function Gy({draft:e,onPatch:t,readOnly:n,serverSchema:r,locale:i}){let{schema:a,form:o}=Z.useMemo(()=>pa({bundledSchema:Hy(),bundledForm:Wy(),serverSchema:r,excludeFields:zy,sectionTitle:K(`engine.inspector.moreFields`,i)}),[r,i]);return a?(0,X.jsx)(ga,{schema:a,form:o,value:e,hiddenFields:[...zy],readOnly:n,onChange:e=>t(e)}):(0,X.jsx)(`p`,{className:`px-1 py-2 text-xs text-muted-foreground`,children:K(`engine.studio.inspector.noPageSchema`,i)})}function Ky(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 qy(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function Jy(e){return e===`lookup`||e===`master_detail`||e===`tree`}function Yy(e){return e===`formula`||e===`summary`}function Xy(e){return e===`number`||e===`currency`||e===`percent`}function Zy(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}function Qy(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`}var $y=[`record`,`previous`,`parent`],eb=[`record`];function tb(e){return typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:``}function nb(e,t){if(t.trim()){if(e&&typeof e==`object`&&!Array.isArray(e)){let n=e;return{...n,dialect:typeof n.dialect==`string`?n.dialect:`cel`,source:t}}return t}}function rb(e){return ja.flatMap(t=>t.types.map(n=>({value:n,label:`${K(`engine.fieldCategory.${t.category}`,e)} · ${K(`engine.fieldType.${n}`,e)}`})))}function ib({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,readOnly:a,locale:o}){let s=Z.useCallback(e=>K(e,o),[o]),c=Z.useMemo(()=>rb(o),[o]),l=Z.useMemo(()=>Pa(t.fields),[t]),u=String(e.id),d=$i(l,u),f=d>=0?l.entries[d]:null,p=Array.isArray(t.fieldGroups)?t.fieldGroups:[],m=wb(o),h=Z.useRef(!1);if(Z.useEffect(()=>{h.current=!1},[u]),!f)return(0,X.jsx)(ca,{kindLabel:s(`designer.field.kind`),title:u||s(`designer.field.kind`),onClose:r,closeLabel:s(`designer.field.close`),children:(0,X.jsx)(ma,{message:s(`designer.field.missing`)})});let g=f.def,_=typeof g.type==`string`?g.type:`text`,v=Ca[_],y=e=>{n({fields:ea(e)})},b=e=>{let t=[...l.entries];t[d]={...f,def:{...g,...e}},y({shape:l.shape,entries:t})},x=e=>{let t=da(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},y({shape:l.shape,entries:n}),i?.({kind:`field`,id:t,label:String(g.label??t)})},S=e=>{if(a)return null;let t=_===`select`?`status`:_;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=da(e);return!n||n===f.name||l.entries.some((e,t)=>t!==d&&e.name===n)?null:n},C=()=>{let e=l.entries.filter((e,t)=>t!==d);y({shape:l.shape,entries:e}),r()},w=()=>{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 g.label==`string`&&g.label?g.label:``,o={name:n,def:{...g,label:a?a+s(`designer.field.copySuffix`):void 0}},c=[...l.entries];c.splice(d+1,0,o),y({shape:l.shape,entries:c}),i?.({kind:`field`,id:n,label:String(o.def.label??n)})},T=e=>{let t={shape:l.shape,entries:ia(l.entries,d,e)};y(t)},E=Ky(g),D=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});b({options:t})},O=(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!a&&(0,X.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:w,title:s(`designer.field.duplicate`),"aria-label":s(`designer.field.duplicate`),children:(0,X.jsx)(we,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(Yi,{index:d,total:l.entries.length,onMove:T,disabled:a})]}),k=(0,X.jsx)(sa,{label:G(`designer.field.remove`,o,{label:typeof g.label==`string`?g.label:f.name}),onClick:C,disabled:a}),A=v?K(`engine.fieldType.${v.id}`,o):void 0;return(0,X.jsxs)(ca,{kindLabel:s(`designer.field.kind`),title:typeof g.label==`string`&&g.label?g.label:f.name,onClose:r,closeLabel:s(`designer.field.close`),headerActions:O,footer:k,children:[(0,X.jsxs)(ab,{title:s(`designer.field.section.basic`),children:[(0,X.jsx)(q,{label:s(`designer.field.apiName`),value:f.name,onCommit:x,disabled:a,mono:!0,testId:`field-apiname-input`}),(0,X.jsx)(q,{label:s(`designer.field.label`),value:typeof g.label==`string`?g.label:``,onCommit:e=>{let t=S(e),n=[...l.entries];n[d]={...f,name:t??f.name,def:{...g,label:e}},y({shape:l.shape,entries:n}),t&&i?.({kind:`field`,id:t,label:e})},disabled:a,testId:`field-label-input`}),(0,X.jsx)(J,{label:s(`designer.field.type`),value:_,options:c,onCommit:e=>b({type:e}),disabled:a}),(0,X.jsxs)(`div`,{className:`flex items-center gap-4 pt-1`,children:[(0,X.jsx)(Y,{label:s(`designer.field.required`),value:!!g.required,onCommit:e=>b({required:e||void 0}),disabled:a}),(0,X.jsx)(Y,{label:s(`designer.field.unique`),value:!!g.unique,onCommit:e=>b({unique:e||void 0}),disabled:a})]}),(0,X.jsx)(sb,{label:s(`designer.field.description`),value:typeof g.description==`string`?g.description:``,onCommit:e=>b({description:e||void 0}),disabled:a,rows:2}),Qy(_)&&(0,X.jsx)(ob,{kind:Qy(_),value:g.defaultValue,options:E,onCommit:e=>b({defaultValue:e}),disabled:a,locale:o}),(0,X.jsx)(sb,{label:s(`designer.field.helpText`),value:typeof g.inlineHelpText==`string`?g.inlineHelpText:``,onCommit:e=>b({inlineHelpText:e||void 0}),disabled:a,rows:2,placeholder:s(`designer.field.helpTextPlaceholder`)})]}),(qy(_)||Jy(_)||Yy(_)||Xy(_)||Zy(_))&&(0,X.jsxs)(ab,{title:G(`designer.field.section.options`,o,{type:A??_}),children:[qy(_)&&(0,X.jsx)(lb,{options:E,onChange:D,disabled:a,locale:o},f.name),Jy(_)&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(cb,{label:s(`designer.field.relatedObject`),value:typeof g.reference==`string`?g.reference:``,options:m,onCommit:e=>b({reference:e||void 0}),disabled:a,placeholder:s(`designer.field.objectNamePlaceholder`)}),(0,X.jsx)(q,{label:s(`designer.field.relationshipName`),value:typeof g.relationshipName==`string`?g.relationshipName:``,onCommit:e=>b({relationshipName:e||void 0}),disabled:a,placeholder:s(`designer.field.relationshipNameHint`)}),(0,X.jsx)(pb,{def:g,patchDef:b,hostFieldNames:l.entries.map(e=>e.name).filter(e=>e!==f.name),readOnly:a,locale:o})]}),_===`formula`&&(0,X.jsx)(ya,{id:`field-formula-${f.name}`,label:s(`designer.field.formula`),value:tb(g.expression??g.formula),onChange:e=>{h.current=!0,b({expression:nb(g.expression??g.formula,e),formula:void 0,...e.trim()?{}:{returnType:void 0}})},onInferredTypeChange:e=>{if(!h.current)return;let t=e&&e!==`unknown`?e:void 0;g.returnType!==t&&b({returnType:t})},disabled:a,placeholder:`record.amount * 0.2`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name).filter(e=>e!==f.name),scope:`record`,roots:eb,role:`value`,t:s}),_===`summary`&&(0,X.jsx)(Cb,{def:g,patchDef:b,objectOptions:m,readOnly:a,locale:o}),Xy(_)&&(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)(Na,{label:s(`designer.field.precision`),value:typeof g.precision==`number`?g.precision:void 0,onCommit:e=>b({precision:e}),disabled:a}),(0,X.jsx)(Na,{label:s(`designer.field.scale`),value:typeof g.scale==`number`?g.scale:void 0,onCommit:e=>b({scale:e}),disabled:a}),(0,X.jsx)(Na,{label:s(`designer.field.min`),value:typeof g.min==`number`?g.min:void 0,onCommit:e=>b({min:e}),disabled:a}),(0,X.jsx)(Na,{label:s(`designer.field.max`),value:typeof g.max==`number`?g.max:void 0,onCommit:e=>b({max:e}),disabled:a})]}),Zy(_)&&(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)(Na,{label:s(`designer.field.minLength`),value:typeof g.minLength==`number`?g.minLength:void 0,onCommit:e=>b({minLength:e}),disabled:a,placeholder:`0`}),(0,X.jsx)(Na,{label:s(`designer.field.maxLength`),value:typeof g.maxLength==`number`?g.maxLength:void 0,onCommit:e=>b({maxLength:e}),disabled:a,placeholder:`255`})]})]}),(0,X.jsxs)(ab,{title:s(`designer.field.section.advanced`),children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)(Y,{label:s(`designer.field.readonly`),value:!!g.readonly,onCommit:e=>b({readonly:e||void 0}),disabled:a}),(0,X.jsx)(Y,{label:s(`designer.field.hidden`),value:!!g.hidden,onCommit:e=>b({hidden:e||void 0}),disabled:a}),(0,X.jsx)(Y,{label:s(`designer.field.indexed`),value:!!g.indexed,onCommit:e=>b({indexed:e||void 0}),disabled:a}),(0,X.jsx)(Y,{label:s(`designer.field.externalId`),value:!!g.externalId,onCommit:e=>b({externalId:e||void 0}),disabled:a}),(0,X.jsx)(Y,{label:s(`designer.field.trackHistory`),value:!!g.trackHistory,onCommit:e=>b({trackHistory:e||void 0}),disabled:a})]}),(0,X.jsx)(q,{label:s(`designer.field.placeholder`),value:typeof g.placeholder==`string`?g.placeholder:``,onCommit:e=>b({placeholder:e||void 0}),disabled:a}),(0,X.jsxs)(`div`,{className:`space-y-2 border-t pt-2.5`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground`,children:s(`designer.field.conditionalRules`)}),(0,X.jsx)(ya,{id:`field-rule-visible-${f.name}`,label:s(`designer.field.visibleWhen`),value:tb(g.visibleWhen),onChange:e=>b({visibleWhen:nb(g.visibleWhen,e)}),disabled:a,placeholder:`record.status != 'draft'`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name),scope:`record`,roots:$y,t:s}),(0,X.jsx)(ya,{id:`field-rule-readonly-${f.name}`,label:s(`designer.field.readonlyWhen`),value:tb(g.readonlyWhen),onChange:e=>b({readonlyWhen:nb(g.readonlyWhen,e)}),disabled:a,placeholder:`record.status == 'closed'`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name),scope:`record`,roots:$y,t:s}),(0,X.jsx)(ya,{id:`field-rule-required-${f.name}`,label:s(`designer.field.requiredWhen`),value:tb(g.requiredWhen),onChange:e=>b({requiredWhen:nb(g.requiredWhen,e)}),disabled:a,placeholder:`record.amount > 10000`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:l.entries.map(e=>e.name),scope:`record`,roots:$y,t:s}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:s(`designer.field.conditionalRulesHint`)})]}),p.length>0&&(0,X.jsx)(J,{label:s(`designer.field.group`),value:typeof g.group==`string`?g.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=>b({group:e||void 0}),disabled:a})]})]})}function ab({title:e,children:t}){return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground border-b pb-1`,children:e}),(0,X.jsx)(`div`,{className:`space-y-2`,children:t})]})}function ob({kind:e,value:t,options:n,onCommit:r,disabled:i,locale:a}){let o=K(`designer.field.defaultValue`,a),s=K(`designer.field.defaultNone`,a);return e===`bool`?(0,X.jsx)(J,{label:o,value:t===!0?`true`:t===!1?`false`:``,options:[{value:``,label:s},{value:`true`,label:K(`designer.field.true`,a)},{value:`false`,label:K(`designer.field.false`,a)}],onCommit:e=>r(e===``?void 0:e===`true`),disabled:i}):e===`number`?(0,X.jsx)(Na,{label:o,value:typeof t==`number`?t:void 0,onCommit:e=>r(e),disabled:i}):e===`picklist`?(0,X.jsx)(J,{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,X.jsx)(q,{label:o,value:typeof t==`string`?t:t==null?``:String(t),onCommit:e=>r(e||void 0),disabled:i})}function sb({label:e,value:t,onCommit:n,disabled:r,rows:i=2,mono:a,placeholder:o}){return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,X.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 cb({label:e,value:t,options:n,onCommit:r,disabled:i,placeholder:a}){let o=Z.useId();return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsx)(R,{list:o,value:t,onChange:e=>r(e.target.value),disabled:i,className:`h-8 text-sm font-mono`,placeholder:a??`object_name`}),(0,X.jsx)(`datalist`,{id:o,children:n.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})}function lb({options:e,onChange:t,disabled:n,locale:r}){let[i,a]=Z.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(ia(i,e,t));return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:K(`designer.field.picklistValues`,r)}),(0,X.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:i.length})]}),i.length===0?(0,X.jsx)(`div`,{className:`text-[11px] italic text-muted-foreground px-1`,children:K(`designer.field.noValues`,r)}):(0,X.jsx)(`div`,{className:`space-y-1.5`,children:i.map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded-md border border-border/60 p-1.5 space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(R,{value:e.value,onChange:e=>s(t,{value:e.target.value}),placeholder:K(`designer.field.optValue`,r),disabled:n,className:`h-7 min-w-0 flex-1 text-xs font-mono`}),(0,X.jsx)(R,{value:e.label??``,onChange:e=>s(t,{label:e.target.value}),placeholder:K(`designer.field.optLabel`,r),disabled:n,className:`h-7 min-w-0 flex-1 text-xs`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.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:K(`designer.field.optColor`,r)}),(0,X.jsx)(`span`,{className:`flex-1`}),(0,X.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>l(t,t-1),disabled:n||t===0,"aria-label":K(`designer.field.moveUp`,r),children:(0,X.jsx)(Be,{className:`h-3 w-3`})}),(0,X.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>l(t,t+1),disabled:n||t===i.length-1,"aria-label":K(`designer.field.moveDown`,r),children:(0,X.jsx)(Pe,{className:`h-3 w-3`})}),(0,X.jsx)(W,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-destructive`,onClick:()=>c(t),disabled:n,"aria-label":K(`designer.field.removeValue`,r),children:(0,X.jsx)(Qe,{className:`h-3 w-3`})})]})]},t))}),!n&&(0,X.jsxs)(W,{variant:`outline`,size:`sm`,className:`h-7 gap-1 text-xs`,onClick:()=>o([...i,{value:``,label:``}]),children:[(0,X.jsx)(B,{className:`h-3 w-3`}),K(`designer.field.addValue`,r)]})]})}var ub=[{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 db(e){let t=e.lookupFilters??e.lookup_filters;return Array.isArray(t)?t:[]}function fb(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 pb({def:e,patchDef:t,hostFieldNames:n,readOnly:r,locale:i}){let a=e=>K(e,i),o=typeof e.reference==`string`?e.reference:void 0,{fields:s,loading:c}=xa(o),l=Z.useMemo(()=>s.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label,hint:e.type})),[s]),u=Z.useMemo(()=>n.map(e=>({value:e,label:e})),[n]),d=db(e),f=fb(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,X.jsxs)(`div`,{className:`space-y-2 border-t pt-2.5`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground`,children:a(`designer.field.lookup.pickerConfig`)}),(0,X.jsx)($a,{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,X.jsx)($a,{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,X.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:a(`designer.field.lookup.selectableRecords`)}),(0,X.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:d.length})]}),!r&&(0,X.jsxs)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:m,children:[(0,X.jsx)(B,{className:`h-3 w-3`}),` `,a(`designer.field.lookup.addFilter`)]})]}),d.length===0?(0,X.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:G(`designer.field.lookup.noFilter`,i,{ref:o||`related`})}):d.map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:G(`designer.field.lookup.filterN`,i,{n:t+1})}),!r&&(0,X.jsx)(W,{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,X.jsx)(Qe,{className:`h-3.5 w-3.5`})})]}),(0,X.jsx)($a,{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,X.jsx)(J,{label:a(`designer.field.lookup.filterOperator`),value:e.operator??`eq`,options:ub,onCommit:e=>p(t,{operator:e}),disabled:r}),(0,X.jsx)(q,{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,X.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:a(`designer.field.lookup.dependsOn`)}),f.length>0&&(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:f.map(e=>(0,X.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,X.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,X.jsx)($a,{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,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-1`,children:[(0,X.jsx)(Na,{label:a(`designer.field.lookup.pageSize`),value:S,onCommit:e=>t({lookupPageSize:e}),placeholder:`10`,disabled:r}),(0,X.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,X.jsx)(Y,{label:a(`designer.field.lookup.allowCreate`),value:C,onCommit:e=>t({allowCreate:e||void 0}),disabled:r})})]})]})}var mb=[`count`,`sum`,`min`,`max`,`avg`];function hb(e){let t=e.summaryOperations;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}var gb={ne:`$ne`,gt:`$gt`,lt:`$lt`,gte:`$gte`,lte:`$lte`,contains:`$contains`,in:`$in`,notIn:`$nin`},_b={$eq:`eq`,$ne:`ne`,$gt:`gt`,$lt:`lt`,$gte:`gte`,$lte:`lte`,$contains:`contains`,$in:`in`,$nin:`notIn`},vb=new Set([`number`,`currency`,`percent`,`rating`,`slider`,`autonumber`]);function yb(e,t,n){let r=e=>{if(typeof e!=`string`)return e;let n=e.trim();if(t===`boolean`||t===`toggle`)return n===`true`||n===`1`;if(t&&vb.has(t)){let t=Number(n);return n!==``&&Number.isFinite(t)?t:e}return e};return n?(Array.isArray(e)?e:String(e??``).split(`,`).map(e=>e.trim()).filter(Boolean)).map(r):r(e)}function bb(e){if(!e||typeof e!=`object`||Array.isArray(e))return{rows:[],advanced:!1};let t=[],n=!1,r=e=>{for(let[i,a]of Object.entries(e)){if(i===`$and`&&Array.isArray(a)){for(let e of a)e&&typeof e==`object`&&!Array.isArray(e)?r(e):n=!0;continue}if(i.startsWith(`$`)){n=!0;continue}if(typeof a==`object`&&a&&!Array.isArray(a)){let e=Object.entries(a);if(e.length===0){n=!0;continue}for(let[r,a]of e){let e=_b[r];e?t.push({field:i,operator:e,value:a}):n=!0}}else t.push({field:i,operator:`eq`,value:a})}};return r(e),{rows:t,advanced:n}}function xb(e,t){let n=e.filter(e=>e.field);if(n.length===0)return;let r=n.map(e=>{let n=e.operator===`in`||e.operator===`notIn`,r=yb(e.value,t(e.field),n);return e.operator===`eq`?{[e.field]:r}:{[e.field]:{[gb[e.operator]??`$eq`]:r}}});if(r.length===1)return r[0];let i=r.map(e=>Object.keys(e)[0]);return new Set(i).size===i.length?Object.assign({},...r):{$and:r}}var Sb=e=>Array.isArray(e)?e.join(`, `):e==null?``:String(e);function Cb({def:e,patchDef:t,objectOptions:n,readOnly:r,locale:i}){let a=e=>K(e,i),o=hb(e),s=typeof o.object==`string`?o.object:``,c=typeof o.function==`string`?o.function:``,{fields:l,loading:u}=xa(s||void 0),d=e=>{let n={...o,...e};for(let e of Object.keys(n))(n[e]===void 0||n[e]===``)&&delete n[e];t({summaryOperations:Object.keys(n).length>0?n:void 0})},f=Z.useMemo(()=>l.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label,hint:e.type})),[l]),p=Z.useMemo(()=>l.filter(e=>e.type===`lookup`||e.type===`master_detail`).map(e=>({value:e.name,label:e.label,hint:e.type})),[l]),m=a(s?`designer.field.lookup.selectField`:`designer.field.summary.setObjectFirst`),h=Z.useCallback(e=>l.find(t=>t.name===e)?.type,[l]),{rows:g,advanced:_}=bb(o.filter),v=e=>d({filter:xb(e,h)}),y=(e,t)=>v(g.map((n,r)=>r===e?{...n,...t}:n)),b=()=>v([...g,{field:f[0]?.value??``,operator:`eq`,value:``}]),x=e=>v(g.filter((t,n)=>n!==e));return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(cb,{label:a(`designer.field.summary.object`),value:s,options:n,onCommit:e=>d({object:e||void 0}),disabled:r,placeholder:a(`designer.field.objectNamePlaceholder`)}),(0,X.jsx)(J,{label:a(`designer.field.summary.function`),value:c,options:[{value:``,label:a(`designer.field.defaultNone`)},...mb.map(e=>({value:e,label:a(`designer.field.summary.fn.${e}`)}))],onCommit:e=>d({function:e||void 0}),disabled:r}),(0,X.jsx)($a,{label:a(`designer.field.summary.field`),value:typeof o.field==`string`?o.field:``,onCommit:e=>d({field:e||void 0}),options:f,loading:u,placeholder:m,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),c===`count`&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/70 px-0.5 -mt-1`,children:a(`designer.field.summary.countFieldHint`)}),(0,X.jsx)($a,{label:a(`designer.field.summary.relationshipField`),value:typeof o.relationshipField==`string`?o.relationshipField:``,onCommit:e=>d({relationshipField:e||void 0}),options:p,loading:u,placeholder:m,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,X.jsxs)(`div`,{className:`space-y-1.5 border-t pt-2.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:a(`designer.field.summary.filterSection`)}),!_&&(0,X.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:g.length})]}),!r&&!_&&(0,X.jsxs)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:b,disabled:f.length===0,children:[(0,X.jsx)(B,{className:`h-3 w-3`}),` `,a(`designer.field.summary.addFilter`)]})]}),_?(0,X.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-[11px] text-muted-foreground`,children:a(`designer.field.summary.filterAdvanced`)}):g.length===0?(0,X.jsx)(`p`,{className:`rounded-md border border-dashed bg-muted/30 px-3 py-2 text-center text-[11px] text-muted-foreground`,children:a(`designer.field.summary.noFilter`)}):g.map((e,t)=>(0,X.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:G(`designer.field.lookup.filterN`,i,{n:t+1})}),!r&&(0,X.jsx)(W,{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:()=>x(t),children:(0,X.jsx)(Qe,{className:`h-3.5 w-3.5`})})]}),(0,X.jsx)($a,{label:a(`designer.field.lookup.filterField`),value:e.field??``,onCommit:e=>y(t,{field:e}),options:f,loading:u,placeholder:m,searchPlaceholder:a(`designer.field.lookup.searchFields`),disabled:r,mono:!0}),(0,X.jsx)(J,{label:a(`designer.field.lookup.filterOperator`),value:e.operator??`eq`,options:ub,onCommit:e=>y(t,{operator:e}),disabled:r}),(0,X.jsx)(q,{label:a(`designer.field.lookup.filterValue`),value:Sb(e.value),onCommit:e=>y(t,{value:e}),placeholder:e.operator===`in`||e.operator===`notIn`?`comma,separated,values`:`value`,disabled:r,mono:!0})]},t)),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:a(`designer.field.summary.filterHint`)})]}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:a(`designer.field.summary.hint`)})]})}function wb(e){let t=Ui(),[n,r]=Z.useState([]);return Z.useEffect(()=>{let n=!1;return Promise.all([t.list(`object`),t.listDrafts({type:`object`}).catch(()=>[])]).then(([t,i])=>{if(n)return;let a=new Map;for(let e of t??[])typeof e?.name==`string`&&e.name&&!a.has(e.name)&&a.set(e.name,{value:e.name,label:e.label?`${e.label} (${e.name})`:e.name});for(let t of i??[]){let n=t.name;typeof n==`string`&&n&&!a.has(n)&&a.set(n,{value:n,label:`${n} ${K(`engine.inspector.draftSuffix`,e)}`})}r([...a.values()].sort((e,t)=>e.value.localeCompare(t.value)))}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function Tb({name:e,draft:t,onPatch:n,readOnly:r,locale:i}){let a=Z.useCallback(e=>K(e,i),[i]),o=!e,s=e=>typeof t[e]==`string`?t[e]:``,c=Z.useRef(!1),l=e=>{let t={label:e||void 0};o&&!c.current&&(t.name=Hi(e)),n(t)},u=e=>{c.current=!0,n({name:da(e)})},d=o?s(`name`):e||s(`name`),f=s(`label`)||e||a(`designer.object.kind`);return(0,X.jsxs)(ca,{kindLabel:a(`designer.object.kind`),title:f,onClose:()=>{},hideClose:!0,children:[(0,X.jsxs)(jb,{title:a(`designer.object.section.basic`),hint:a(`designer.object.section.basicHint`),children:[(0,X.jsx)(Mb,{hint:a(`designer.object.nameHint`),children:(0,X.jsx)(q,{label:a(`designer.object.name`),value:d,onCommit:u,disabled:r||!o,mono:!0,testId:`object-name-input`,placeholder:a(`designer.object.namePlaceholder`)})}),(0,X.jsx)(q,{label:a(`designer.object.label`),value:s(`label`),onCommit:l,disabled:r,placeholder:a(`designer.object.labelPlaceholder`)}),(0,X.jsx)(q,{label:a(`designer.object.pluralLabel`),value:s(`pluralLabel`),onCommit:e=>n({pluralLabel:e||void 0}),disabled:r,placeholder:a(`designer.object.pluralPlaceholder`)}),(0,X.jsx)(Mb,{hint:a(`designer.object.iconHint`),children:(0,X.jsx)(q,{label:a(`designer.object.icon`),value:s(`icon`),onCommit:e=>n({icon:e||void 0}),disabled:r,mono:!0,placeholder:`building`})}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:a(`designer.object.description`)}),(0,X.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`})]})]}),(0,X.jsx)(Ab,{draft:t,onPatch:n,readOnly:r,tr:a})]})}var Eb=[`read`,`create`,`update`,`delete`];function Db(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}function Ob(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`).join(`, `):``}function kb(){let[e,t]=Z.useState(!1);return Z.useEffect(()=>{let e=!1;return a(()=>import(`./vendor-objectstack-ChpQDQzo.js`).then(e=>e._).then(n=>{e||t(n?.ObjectRequiredPermissionsSchema!==void 0)}),[],import.meta.url).catch(()=>{}),()=>{e=!0}},[]),e}function Ab({draft:e,onPatch:t,readOnly:n,tr:r}){let i=kb(),a=e.access?.default===`private`?`private`:`public`,o=e.requiredPermissions,s=!!o&&typeof o==`object`&&!Array.isArray(o),c=s?`perOp`:`all`,l=e=>{t({access:e===`private`?{default:`private`}:void 0})},u=e=>{let n=Db(e);t({requiredPermissions:n.length>0?n:void 0})},d=(e,n)=>{let r=s?{...o}:{},i=Db(n);i.length>0?r[e]=i:delete r[e],t({requiredPermissions:Object.keys(r).length>0?r:void 0})},f=e=>{if(e!==c)if(e===`perOp`){let e=Array.isArray(o)?o:[];t({requiredPermissions:e.length>0?{read:e,create:e,update:e,delete:e}:{}})}else{let e=s?o:{},n=[...new Set(Eb.flatMap(t=>Array.isArray(e[t])?e[t]:[]))];t({requiredPermissions:n.length>0?n:void 0})}};return(0,X.jsxs)(jb,{title:r(`designer.object.section.access`),hint:r(`designer.object.section.accessHint`),children:[(0,X.jsx)(Mb,{hint:r(a===`private`?`designer.object.posture.privateHint`:`designer.object.posture.publicHint`),children:(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:r(`designer.object.posture`)}),(0,X.jsxs)(`select`,{value:a,disabled:n,onChange:e=>l(e.target.value),"data-testid":`object-access-posture`,className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,X.jsx)(`option`,{value:`public`,children:r(`designer.object.posture.public`)}),(0,X.jsx)(`option`,{value:`private`,children:r(`designer.object.posture.private`)})]})]})}),(0,X.jsx)(Mb,{hint:r(`designer.object.reqPerms.hint`),children:(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:r(`designer.object.reqPerms`)}),i&&(0,X.jsxs)(`div`,{className:`inline-flex rounded border text-[11px]`,role:`group`,children:[(0,X.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>f(`all`),className:`px-1.5 py-0.5 rounded-l ${c===`all`?`bg-primary/10 text-primary`:`text-muted-foreground`}`,children:r(`designer.object.reqPerms.mode.all`)}),(0,X.jsx)(`button`,{type:`button`,disabled:n,onClick:()=>f(`perOp`),"data-testid":`object-reqperms-perop`,className:`px-1.5 py-0.5 rounded-r border-l ${c===`perOp`?`bg-primary/10 text-primary`:`text-muted-foreground`}`,children:r(`designer.object.reqPerms.mode.perOp`)})]})]}),c===`all`?(0,X.jsx)(q,{label:``,value:Ob(o),onCommit:u,disabled:n,mono:!0,testId:`object-reqperms-all`,placeholder:r(`designer.object.reqPerms.placeholder`)}):(0,X.jsx)(`div`,{className:`space-y-1.5`,children:Eb.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`w-14 shrink-0 text-[11px] text-muted-foreground capitalize`,children:r(`designer.object.reqPerms.op.${e}`)}),(0,X.jsx)(`div`,{className:`flex-1`,children:(0,X.jsx)(q,{label:``,value:Ob(o?.[e]),onCommit:t=>d(e,t),disabled:n,mono:!0,testId:`object-reqperms-${e}`,placeholder:r(`designer.object.reqPerms.placeholder`)})})]},e))})]})})]})}function jb({title:e,hint:t,children:n}){return(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`border-b pb-1`,children:[(0,X.jsx)(`div`,{className:`text-[10px] font-semibold uppercase tracking-wider text-muted-foreground`,children:e}),t&&(0,X.jsx)(`div`,{className:`text-[10px] normal-case text-muted-foreground/70 mt-0.5`,children:t})]}),(0,X.jsx)(`div`,{className:`space-y-2`,children:n})]})}function Mb({hint:e,children:t}){return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[t,e&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:e})]})}var Nb={equals:`$eq`,notEquals:`$ne`,greaterThan:`$gt`,greaterOrEqual:`$gte`,lessThan:`$lt`,lessOrEqual:`$lte`,after:`$gt`,before:`$lt`,contains:`$contains`,in:`$in`,notIn:`$nin`},Pb={$eq:`equals`,$ne:`notEquals`,$gt:`greaterThan`,$gte:`greaterOrEqual`,$lt:`lessThan`,$lte:`lessOrEqual`,$contains:`contains`,$in:`in`,$nin:`notIn`};function Fb(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=Nb[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 Ib(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=Pb[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 Lb=[{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`}],Rb=[{value:`string`,label:`string`},{value:`number`,label:`number`},{value:`date`,label:`date`},{value:`boolean`,label:`boolean`},{value:`lookup`,label:`lookup`}],zb=[{value:``,label:`— none —`},{value:`day`,label:`day`},{value:`week`,label:`week`},{value:`month`,label:`month`},{value:`quarter`,label:`quarter`},{value:`year`,label:`year`}],Bb=[{value:`ratio`,label:`ratio (a ÷ b)`},{value:`sum`,label:`sum (a + b)`},{value:`difference`,label:`difference (a − b)`},{value:`product`,label:`product (a × b)`}],Vb=[{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%`}],Hb=[{value:`0`,label:`0`},{value:`1`,label:`1`},{value:`2`,label:`2`}],Ub=[{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 Wb({title:e,count:t,onAdd:n,addLabel:r}){return(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsx)(L,{variant:`outline`,className:`text-[10px]`,children:t})]}),n&&(0,X.jsxs)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:n,children:[(0,X.jsx)(B,{className:`h-3 w-3`}),` `,r]})]})}function Gb({children:e}){return(0,X.jsxs)(`details`,{className:`group`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer select-none list-none text-[11px] text-muted-foreground hover:text-foreground`,children:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(si,{className:`h-3 w-3 transition-transform group-open:rotate-90`}),`Advanced`]})}),(0,X.jsx)(`div`,{className:`mt-1.5 space-y-1.5 border-l pl-2.5`,children:e})]})}function Kb(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 qb(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 Jb({measure:e,onPatch:t,disabled:n}){let{kind:r,decimals:i}=Kb(e.format,e.currency),a=e.currency||`USD`,o=(e,n,r)=>t(qb(e,n,r)),s=T(r===`percent`?.1234:1234.5,e.format,e.currency);return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-1.5`,children:[(0,X.jsx)(J,{label:`Display format`,value:r,options:Vb,onCommit:e=>o(e,i,a),disabled:n}),r!==`raw`&&(0,X.jsx)(J,{label:`Decimals`,value:String(i),options:Hb,onCommit:e=>o(r,parseInt(e,10)||0,a),disabled:n})]}),r===`currency`&&(0,X.jsx)(J,{label:`Currency`,value:a,options:Ub,onCommit:e=>o(r,i,e),disabled:n}),r!==`raw`&&(0,X.jsxs)(`p`,{className:`text-[10px] text-muted-foreground`,children:[`Sample: `,(0,X.jsx)(`span`,{className:`font-mono tabular-nums`,children:s})]})]})}function Yb(e,t){if(!e||!e.includes(`.`))return null;let n=e.slice(0,e.lastIndexOf(`.`));return n&&!t.includes(n)?n:null}function Xb({rel:e,onAdd:t,disabled:n}){return(0,X.jsxs)(`p`,{className:`flex items-center gap-1 text-[10px] text-amber-600 dark:text-amber-400`,children:[(0,X.jsx)(z,{className:`h-3 w-3 shrink-0`}),(0,X.jsxs)(`span`,{children:[`Relationship `,(0,X.jsx)(`code`,{className:`font-mono`,children:e}),` isn't in Included relationships.`]}),!n&&t&&(0,X.jsx)(`button`,{type:`button`,className:`underline hover:no-underline`,onClick:t,children:`Add it`})]})}function Zb({label:e,help:t,value:n,onCommit:r,fields:i,disabled:a}){let{group:o,representable:s}=Ib(n),c=o.conditions.length;return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:e}),s?(0,X.jsxs)(kt,{children:[(0,X.jsx)(Yr,{asChild:!0,children:(0,X.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,disabled:a,className:`h-8 w-full justify-between text-xs font-normal`,children:[(0,X.jsx)(`span`,{className:`truncate text-left`,children:c?`${c} condition${c===1?``:`s`}`:(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`+ Add filter…`})}),(0,X.jsx)(pr,{className:`h-3.5 w-3.5 opacity-60 shrink-0`})]})}),(0,X.jsx)(he,{align:`start`,className:`w-[440px] max-w-[90vw] p-3`,children:i.length===0?(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Pick a base object to add filter conditions.`}):(0,X.jsx)(zn,{fields:i,value:o,onChange:e=>r(Fb(e))})})]}):(0,X.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,X.jsx)(`span`,{className:`font-medium`,children:`Source`}),` tab.`]}),t&&(0,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:t})]})}function Qb(e,t){return e===t?{object:e}:{object:e,include:[],dimensions:[],measures:[],filter:void 0}}function $b({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=Z.useRef(!1),p=typeof e.name==`string`?e.name:``,{options:m,loading:h}=Ro(),{relationships:g,fieldOptions:_,loading:v}=zo(o,s),y=Bo(u),b=Z.useMemo(()=>m.map(e=>({value:e.name,label:e.label})),[m]),x=Z.useMemo(()=>g.map(e=>({value:e.name,label:e.label,hint:e.referenceTo?`→ ${e.referenceTo}`:void 0})),[g]),S=Z.useMemo(()=>_.map(e=>({value:e.value,label:e.label,hint:e.type,group:e.group})),[_]),C=Z.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:No(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,X.jsxs)(ca,{kindLabel:`Dataset`,title:String(i||e.name||`Dataset`),onClose:()=>{},hideClose:!0,children:[u&&!y.loading&&(0,X.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,X.jsx)(q,{label:`Name`,value:p,onCommit:e=>{f.current=!0,t({name:la(e)})},placeholder:`snake_case identifier`,disabled:n,mono:!0}),(0,X.jsx)(q,{label:`Label`,value:i,onCommit:e=>{let n={label:e};d&&!f.current&&(n.name=la(e)),t(n)},disabled:n}),(0,X.jsx)(q,{label:`Description`,value:a,onCommit:e=>t({description:e}),disabled:n}),(0,X.jsx)($a,{label:`Base object`,value:o,onCommit:e=>t(Qb(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,X.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,children:`Changing the base object clears its dimensions, measures, joins & filters.`}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,X.jsx)(Wb,{title:`Included relationships`,count:s.length,addLabel:`Add`,onAdd:n?void 0:()=>t({include:Xi(s,``)})}),s.length===0?(0,X.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,X.jsx)(`code`,{children:T||`the base object`}),`) to use `,(0,X.jsx)(`code`,{children:`relationship.field`}),` dimensions/measures.`]}):s.map((e,r)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)($a,{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,X.jsx)(W,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>t({include:Sa(s,r,null)}),"aria-label":`Remove relationship`,children:(0,X.jsx)(Qe,{className:`h-3.5 w-3.5`})})]},r)),o&&s.length>0&&(0,X.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,X.jsx)(`span`,{className:`font-mono font-medium`,children:T}),s.map((e,t)=>{let n=g.find(t=>t.name===e);return(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(si,{className:`h-3 w-3 opacity-60`}),(0,X.jsxs)(`span`,{className:`font-mono`,children:[e,n?.referenceTo?` (${n.referenceTo})`:``]})]},t)})]})]}),(0,X.jsx)(`div`,{className:`border-t pt-3`,children:(0,X.jsx)(Zb,{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,X.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,X.jsx)(Wb,{title:`Dimensions`,count:c.length,addLabel:`Add dimension`,onAdd:n?void 0:()=>t({dimensions:Xi(c,{name:``,field:``,type:`string`})})}),c.map((e,r)=>(0,X.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Dimension `,r+1]}),!n&&(0,X.jsx)(W,{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:Sa(c,r,null)}),children:(0,X.jsx)(gn,{className:`h-3.5 w-3.5`})})]}),(0,X.jsx)(q,{label:`Name`,value:e.name??``,onCommit:e=>E(r,{name:e}),placeholder:`e.g. region`,disabled:n,mono:!0}),(0,X.jsx)($a,{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=Yb(e.field,s);return r?(0,X.jsx)(Xb,{rel:r,disabled:n,onAdd:()=>t({include:Xi(s,r)})}):null})(),(0,X.jsx)(J,{label:`Type`,value:e.type,options:Rb,onCommit:e=>E(r,{type:e}),disabled:n}),(0,X.jsxs)(Gb,{children:[(0,X.jsx)(q,{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,X.jsx)(J,{label:`Date bucket`,value:e.dateGranularity??``,options:zb,onCommit:e=>E(r,{dateGranularity:e||void 0}),disabled:n})]})]},r))]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,X.jsx)(Wb,{title:`Measures`,count:l.length,addLabel:`Add measure`,onAdd:n?void 0:()=>t({measures:Xi(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,X.jsxs)(`div`,{className:`rounded-md border p-2 space-y-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`span`,{className:`text-[11px] font-medium text-muted-foreground`,children:[`Measure `,r+1]}),!n&&(0,X.jsx)(W,{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:Sa(l,r,null)}),children:(0,X.jsx)(gn,{className:`h-3.5 w-3.5`})})]}),(0,X.jsx)(q,{label:`Name`,value:e.name??``,onCommit:e=>D(r,{name:e}),placeholder:`e.g. revenue`,disabled:n,mono:!0}),(0,X.jsx)(J,{label:`Aggregate`,value:e.aggregate,options:Lb,onCommit:e=>D(r,{aggregate:e}),disabled:n}),(0,X.jsx)($a,{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=Yb(e.field,s);return r?(0,X.jsx)(Xb,{rel:r,disabled:n,onAdd:()=>t({include:Xi(s,r)})}):null})(),(0,X.jsxs)(Gb,{children:[(0,X.jsx)(q,{label:`Label (optional)`,value:e.label??``,onCommit:e=>D(r,{label:e||void 0}),placeholder:e.name||`Display label`,disabled:n}),(0,X.jsx)(Jb,{measure:e,onPatch:e=>D(r,e),disabled:n}),(0,X.jsx)(Zb,{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,X.jsx)(Y,{label:`Derived — computed from other measures`,value:!!a,onCommit:e=>D(r,{derived:e?{op:`ratio`,of:[]}:void 0}),disabled:n}),a&&(0,X.jsxs)(`div`,{className:`space-y-1.5 rounded-md border border-dashed p-2`,children:[(0,X.jsx)(J,{label:`Operation`,value:a.op,options:Bb,onCommit:e=>D(r,{derived:{...a,op:e}}),disabled:n}),(0,X.jsx)(V,{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,X.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,X.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:`Add other measures first.`}):(0,X.jsx)(`div`,{className:`space-y-1`,children:i.map(e=>(0,X.jsx)(Y,{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 ex(e){let t=Ui(),[n,r]=Z.useState([]),[i,a]=Z.useState(!!e);return Z.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 tx=[{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`}],nx=[{value:`primary`,label:`Primary`},{value:`secondary`,label:`Secondary`},{value:`danger`,label:`Danger`},{value:`ghost`,label:`Ghost`},{value:`link`,label:`Link`}],rx=[{value:`action:button`,label:`Button`},{value:`action:icon`,label:`Icon only`},{value:`action:menu`,label:`Menu item`},{value:`action:group`,label:`Button group`}],ix=[{value:`create`,label:`Create`},{value:`edit`,label:`Edit`},{value:`delete`,label:`Delete`},{value:`custom`,label:`Custom`}],ax=[{value:`POST`,label:`POST`},{value:`PATCH`,label:`PATCH`},{value:`PUT`,label:`PUT`},{value:`DELETE`,label:`DELETE`}],ox=[{value:`expression`,label:`Expression (L1)`},{value:`js`,label:`Sandboxed JS (L2)`}],sx=[{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`}],cx={record_header:`Record header`,record_more:`Record · more menu`,record_section:`Record · section`,record_related:`Record · related list`,list_toolbar:`List toolbar`,list_item:`List · row`,global_nav:`Global nav / command palette`},lx=Object.keys(cx).map(e=>({value:e,label:cx[e]})),ux={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.`}},dx={flow:`flow`,modal:`page`,form:`view`};function fx({type:e,value:t,onCommit:n,cfg:r,readOnly:i}){let a=dx[e]??null,{options:o}=ex(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,X.jsxs)(`div`,{className:`space-y-1`,children:[s?(0,X.jsx)(J,{label:`${r.label} *`,value:t||void 0,options:c,onCommit:n,disabled:i}):(0,X.jsx)(q,{label:`${r.label} *`,value:t,onCommit:n,placeholder:r.placeholder,disabled:i,mono:!0}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:r.hint})]})}var px=[`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 mx({title:e,hint:t}){return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:e}),t&&(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:t})]})}function hx(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 gx({label:e,value:t,onCommit:n,disabled:r,hint:i}){let{options:a}=pd();return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[a.length===0?(0,X.jsx)(q,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,X.jsx)(J,{label:e,value:t||void 0,options:[{value:``,label:`— None (global) —`},...a],onCommit:n,disabled:r}),i&&(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:i})]})}function _x({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let{fields:a}=xa(t),o=Z.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,X.jsx)(q,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,X.jsx)(J,{label:e,value:n||void 0,options:[{value:``,label:`—`},...o],onCommit:r,disabled:i})}function vx({draft:e,onPatch:t,readOnly:n,locale:r,serverSchema:i}){let a=Z.useCallback(e=>K(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)})},_=ux[s],v=i;return(0,X.jsxs)(ca,{kindLabel:a(`engine.inspector.action.kind`),title:String(hx(e.label)||e.name||a(`engine.inspector.action.kind`)),onClose:()=>{},closeLabel:a(`engine.inspector.action.close`),hideClose:!0,children:[(0,X.jsx)(mx,{title:`Basics`}),(0,X.jsx)(q,{label:`Label`,value:hx(e.label),onCommit:e=>t({label:e}),placeholder:`Button text shown to users`,disabled:n}),(0,X.jsx)(q,{label:`Name`,value:o(`name`),onCommit:e=>t({name:e}),placeholder:`snake_case identifier`,disabled:n,mono:!0}),(0,X.jsx)(gx,{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,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:`Icon`}),(0,X.jsx)(_a,{schema:{type:`string`},value:o(`icon`),onChange:e=>t({icon:e||void 0}),readOnly:n})]}),(0,X.jsx)(J,{label:`Variant`,value:o(`variant`)||void 0,options:nx,onCommit:e=>t({variant:e}),disabled:n})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,X.jsx)(mx,{title:`Behavior`,hint:`What happens when the action is triggered.`}),(0,X.jsx)(J,{label:`Type`,value:s,options:tx,onCommit:e=>t({type:e}),disabled:n}),s===`script`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(J,{label:`Script language`,value:(typeof l.language==`string`?l.language:void 0)||`expression`,options:ox,onCommit:e=>m({language:e}),disabled:n}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:`Script body`}),(0,X.jsx)(ft,{value:typeof l.source==`string`?l.source:``,onChange:e=>m({source:e.target.value}),disabled:n,spellCheck:!1,rows:5,placeholder:`// (input, ctx) => result
24
+ return { ok: true }`,className:`text-xs font-mono`}),(0,X.jsxs)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:[`Runs in the sandbox as `,(0,X.jsx)(`code`,{children:`(input, ctx) => Promise<output>`}),`.`]})]})]}):(0,X.jsxs)(X.Fragment,{children:[s===`api`&&(0,X.jsx)(J,{label:`Method`,value:o(`method`)||`POST`,options:ax,onCommit:e=>t({method:e}),disabled:n}),_&&(0,X.jsx)(fx,{type:s,value:o(`target`),onCommit:e=>t({target:e}),cfg:_,readOnly:n})]})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,X.jsx)(mx,{title:`Inputs`,hint:`Collected from the user in a dialog before the action runs.`}),u.length===0?(0,X.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,X.jsxs)(`div`,{className:`space-y-2 rounded-md border border-border p-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,X.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`#`,r+1]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-0.5`,children:[(0,X.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n||r===0,"aria-label":`Move up`,onClick:()=>t({params:ia(u,r,r-1)}),children:`↑`}),(0,X.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n||r===u.length-1,"aria-label":`Move down`,onClick:()=>t({params:ia(u,r,r+1)}),children:`↓`}),(0,X.jsx)(W,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n,"aria-label":`Remove input`,onClick:()=>t({params:Sa(u,r,null)}),children:(0,X.jsx)(gn,{className:`h-3.5 w-3.5`})})]})]}),c?(0,X.jsx)(_x,{label:`Bind to field`,objectName:c,value:e.field,onCommit:e=>h(r,{field:e||void 0}),disabled:n}):null,!e.field&&(0,X.jsx)(q,{label:`Name`,value:e.name??``,onCommit:e=>h(r,{name:e}),placeholder:`request-body key`,disabled:n,mono:!0}),(0,X.jsx)(q,{label:`Label`,value:hx(e.label),onCommit:e=>h(r,{label:e}),disabled:n}),!e.field&&(0,X.jsx)(J,{label:`Type`,value:e.type||void 0,options:sx,onCommit:e=>h(r,{type:e}),disabled:n}),(0,X.jsx)(q,{label:`Placeholder`,value:e.placeholder??``,onCommit:e=>h(r,{placeholder:e}),disabled:n}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1`,children:[(0,X.jsx)(Y,{label:`Required`,value:!!e.required,onCommit:e=>h(r,{required:e}),disabled:n}),(0,X.jsx)(Y,{label:`Pre-fill from row`,value:!!e.defaultFromRow,onCommit:e=>h(r,{defaultFromRow:e}),disabled:n})]})]},r)),!n&&(0,X.jsxs)(W,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>t({params:Xi(u,{})}),children:[(0,X.jsx)(B,{className:`mr-1 h-3.5 w-3.5`}),` Add input`]})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,X.jsx)(mx,{title:`Placement`,hint:`Where this action surfaces in the UI.`}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-1`,children:lx.map(e=>(0,X.jsx)(Y,{label:e.label,value:d.includes(e.value),onCommit:t=>g(e.value,t),disabled:n},e.value))}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-2 pt-1`,children:(0,X.jsx)(J,{label:`Component`,value:o(`component`)||void 0,options:rx,onCommit:e=>t({component:e}),disabled:n})}),(0,X.jsx)(Y,{label:`Bulk — apply to multiple selected rows`,value:!!e.bulkEnabled,onCommit:e=>t({bulkEnabled:e}),disabled:n})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,X.jsx)(mx,{title:`Feedback`,hint:`Confirmation and post-run messaging.`}),(0,X.jsx)(q,{label:`Confirm prompt`,value:hx(e.confirmText),onCommit:e=>t({confirmText:e}),placeholder:`Ask before running (leave blank to skip)`,disabled:n}),(0,X.jsx)(q,{label:`Success message`,value:hx(e.successMessage),onCommit:e=>t({successMessage:e}),disabled:n}),(0,X.jsx)(q,{label:`Error message`,value:hx(e.errorMessage),onCommit:e=>t({errorMessage:e}),disabled:n}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)(J,{label:`Mode`,value:o(`mode`)||void 0,options:ix,onCommit:e=>t({mode:e}),disabled:n}),(0,X.jsx)(q,{label:`Shortcut`,value:o(`shortcut`),onCommit:e=>t({shortcut:e}),placeholder:`e.g. Ctrl+S`,disabled:n,mono:!0})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1`,children:[(0,X.jsx)(Y,{label:`Refresh view after`,value:!!e.refreshAfter,onCommit:e=>t({refreshAfter:e}),disabled:n}),(0,X.jsx)(Y,{label:`Offer undo`,value:!!e.undoable,onCommit:e=>t({undoable:e}),disabled:n})]})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,X.jsx)(mx,{title:`Conditions`,hint:`No-code predicates over the record / user / ctx (compiled to CEL).`}),(0,X.jsx)(wa,{label:`Visible when`,value:typeof e.visible==`string`?e.visible:``,onCommit:e=>t({visible:e||void 0}),objectName:c,disabled:n}),(0,X.jsx)(wa,{label:`Disabled when`,value:typeof e.disabled==`string`?e.disabled:``,onCommit:e=>t({disabled:e||void 0}),objectName:c,disabled:n})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,X.jsx)(mx,{title:`AI exposure`,hint:`Opt-in: expose this action to AI agents as a callable tool.`}),(0,X.jsx)(Y,{label:`Expose to AI agents`,value:f,onCommit:e=>t({aiExposed:e}),disabled:n}),f?(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:`Tool description (required, ≥40 chars)`}),(0,X.jsx)(ft,{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,X.jsx)(`div`,{className:`text-[11px] text-destructive`,children:`A ≥40-character description is required while exposed.`})]}):null]}),v&&(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,X.jsx)(mx,{title:a(`engine.inspector.moreFields`),hint:`Advanced / rarely-used properties.`}),(0,X.jsx)(ga,{schema:v,value:e,hiddenFields:px,readOnly:n,onChange:e=>t(e)})]})]})}var yx=[{value:`expression`,label:`Expression (L1)`},{value:`js`,label:`Sandboxed JS (L2)`}],bx=[`beforeInsert`,`afterInsert`,`beforeUpdate`,`afterUpdate`,`beforeDelete`,`afterDelete`,`beforeUpdateMany`,`afterUpdateMany`,`beforeDeleteMany`,`afterDeleteMany`],xx=[`beforeFind`,`afterFind`,`beforeFindOne`,`afterFindOne`,`beforeCount`,`afterCount`,`beforeAggregate`,`afterAggregate`],Sx=`*`,Cx=[`name`,`label`,`object`,`events`,`body`,`priority`,`async`,`condition`];function wx({title:e,hint:t}){return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:e}),t&&(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:t})]})}function Tx(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 Ex(e){if(e===Sx)return{all:!0,names:[]};if(typeof e==`string`)return{all:!1,names:e?[e]:[]};if(Array.isArray(e)){let t=e.filter(e=>typeof e==`string`&&e!==Sx);return{all:e.includes(Sx),names:t}}return{all:!1,names:[]}}function Dx(e,t){return e?Sx:t.length===1?t[0]:t}function Ox({draft:e,onPatch:t,readOnly:n,locale:r,serverSchema:i}){let a=Z.useCallback(e=>K(e,r),[r]),o=t=>typeof e[t]==`string`?e[t]:``,s=e.body&&typeof e.body==`object`?e.body:{},c=Array.isArray(e.events)?e.events:[],{all:l,names:u}=Ex(e.object),{options:d}=pd(),f=Z.useMemo(()=>{let e=new Set(d.map(e=>e.value));return[...u.filter(t=>!e.has(t)).map(e=>({value:e,label:`${e} (not published)`})),...d]},[d,u]),p=e=>t({body:{...s,...e}}),m=(e,n)=>{t({object:Dx(!1,n?[...new Set([...u,e])]:u.filter(t=>t!==e))})},h=(e,n)=>{t({events:n?[...new Set([...c,e])]:c.filter(t=>t!==e)})},g=!l&&u.length===1?u[0]:void 0,_=typeof s.language==`string`?s.language:`expression`,v=i;return(0,X.jsxs)(ca,{kindLabel:a(`engine.inspector.hook.kind`),title:String(Tx(e.label)||e.name||a(`engine.inspector.hook.kind`)),onClose:()=>{},closeLabel:a(`engine.inspector.action.close`),hideClose:!0,children:[(0,X.jsx)(wx,{title:`Basics`}),(0,X.jsx)(q,{label:`Label`,value:Tx(e.label),onCommit:e=>t({label:e||void 0}),placeholder:`Human-readable name`,disabled:n}),(0,X.jsx)(q,{label:`Name`,value:o(`name`),onCommit:e=>t({name:e}),placeholder:`snake_case identifier`,disabled:n,mono:!0,testId:`hook-name`}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,"data-testid":`hook-object-picker`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:`Object(s) this hook fires on`}),(0,X.jsx)(Y,{label:`All objects (*)`,value:l,onCommit:e=>t({object:e?Sx:Dx(!1,u)}),disabled:n}),!l&&(0,X.jsx)(`div`,{className:`max-h-40 space-y-1 overflow-auto rounded-md border p-2`,children:f.length===0?(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`No objects found — publish an object, then pick it here.`}):f.map(e=>(0,X.jsx)(Y,{label:e.label,value:u.includes(e.value),onCommit:t=>m(e.value,t),disabled:n},e.value))}),!l&&u.length===0&&(0,X.jsx)(`p`,{className:`text-[11px] text-amber-600 dark:text-amber-400`,children:`Pick at least one object (or All objects).`})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,X.jsx)(wx,{title:`Events`,hint:`Which lifecycle events invoke this hook.`}),(0,X.jsx)(`div`,{className:`text-[11px] font-medium text-muted-foreground/80`,children:`Write`}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1`,children:bx.map(e=>(0,X.jsx)(Y,{label:e,value:c.includes(e),onCommit:t=>h(e,t),disabled:n},e))}),(0,X.jsx)(`div`,{className:`pt-1 text-[11px] font-medium text-muted-foreground/80`,children:`Query`}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1`,children:xx.map(e=>(0,X.jsx)(Y,{label:e,value:c.includes(e),onCommit:t=>h(e,t),disabled:n},e))}),c.length===0&&(0,X.jsx)(`p`,{className:`text-[11px] text-amber-600 dark:text-amber-400`,children:`Select at least one event.`})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,X.jsx)(wx,{title:`Function`,hint:`The handler that runs when the hook fires.`}),(0,X.jsx)(J,{label:`Language`,value:_,options:yx,onCommit:e=>p({language:e}),disabled:n}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(V,{className:`text-xs text-muted-foreground`,children:`Handler body`}),(0,X.jsx)(ft,{"data-testid":`hook-body-source`,value:typeof s.source==`string`?s.source:``,onChange:e=>p({source:e.target.value}),disabled:n,spellCheck:!1,rows:8,placeholder:_===`expression`?`record.amount >= 0`:`// (ctx) => { ... }
25
+ return;`,className:`text-xs font-mono`}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:_===`expression`?`A single L1 expression evaluated against the record / ctx.`:`Runs in the sandbox as (ctx) => Promise<void>.`})]})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,X.jsx)(wx,{title:`Options`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsx)(Na,{label:`Priority`,value:typeof e.priority==`number`?e.priority:void 0,onCommit:e=>t({priority:e}),placeholder:`100`,disabled:n}),(0,X.jsx)(`div`,{className:`flex items-end pb-1.5`,children:(0,X.jsx)(Y,{label:`Run asynchronously (after commit)`,value:e.async===!0,onCommit:e=>t({async:e}),disabled:n})})]}),(0,X.jsx)(wa,{label:`Run only when (optional CEL)`,value:typeof e.condition==`string`?e.condition:``,onCommit:e=>t({condition:e||void 0}),objectName:g,disabled:n})]}),v&&(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,X.jsx)(wx,{title:a(`engine.inspector.moreFields`),hint:`Advanced / rarely-used properties.`}),(0,X.jsx)(ga,{schema:v,value:e,hiddenFields:Cx,readOnly:n,onChange:e=>t(e)})]})]})}function kx(){_l(`dashboard`,q_),bl(`dashboard`,iv),_l(`flow`,Dy),_l(`app`,xo),_l(`view`,Iy),bl(`view`,Ly),_l(`page`,jd),bl(`page`,Gy),bl(`report`,Ta),_l(`object`,ib),bl(`object`,Tb),bl(`dataset`,$b),bl(`action`,vx),bl(`hook`,Ox)}var Ax=t({MetadataDiagnosticsPage:()=>mu,MetadataDirectoryPage:()=>Ps,MetadataResourceEditPage:()=>cu,MetadataResourceHistoryPage:()=>ol,MetadataResourceListPage:()=>Nc,StudioHomePage:()=>_c});zu(),Uu(),Zu(),U_(),kx();export{La as A,Oo as C,Co as D,ko as E,Do as O,To as S,Eo as T,Hs as _,fu as a,Ds as b,hl as c,sc as d,cc as f,Rs as g,zs as h,Iu as i,Ra as j,Xa as k,Oc as l,Bs as m,Sf as n,xl as o,$s as p,id as r,vl as s,Ax as t,ic as u,Us as v,wo as w,ms as x,Ps as y};