@objectstack/console 17.3.0 → 17.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +87 -0
- package/dist/.objectui-sha +1 -1
- package/dist/assets/{ActionResultDialog-CQwenjVA.js → ActionResultDialog-Bsr2GS71.js} +1 -1
- package/dist/assets/{AiPendingActionsPage-7gZ8zlOy.js → AiPendingActionsPage-DB-UVcdM.js} +1 -1
- package/dist/assets/{ApiConsolePage-DUF0ysH7.js → ApiConsolePage-Bzqo2owc.js} +1 -1
- package/dist/assets/{AppDocsIndex-CP_AVG4X.js → AppDocsIndex-KhVqdZ-P.js} +1 -1
- package/dist/assets/{AppManagementPage-BJktnoa5.js → AppManagementPage-CsZ0LMQn.js} +1 -1
- package/dist/assets/{ApprovalsInboxPage-DlnxY-uy.js → ApprovalsInboxPage-D_LOnhJ7.js} +1 -1
- package/dist/assets/{AuditLogPage-DIJPRjji.js → AuditLogPage-B9eqwuzl.js} +1 -1
- package/dist/assets/{ComponentNavView-C84QByT7.js → ComponentNavView-DeokLfkW.js} +1 -1
- package/dist/assets/{CreateViewDialog-Zbd9Cagm.js → CreateViewDialog-BMdQ4ZYy.js} +1 -1
- package/dist/assets/{DashboardView-UyKHklBx.js → DashboardView-DHZboRi8.js} +1 -1
- package/dist/assets/{DeveloperHubPage-BRyNdrCJ.js → DeveloperHubPage-C_VYirN0.js} +1 -1
- package/dist/assets/{DocPage-Bx8ZXCYt.js → DocPage-_9x-3Dbi.js} +1 -1
- package/dist/assets/{DocShell-Ipy_IDvh.js → DocShell-D4dSPfBz.js} +1 -1
- package/dist/assets/{DocsIndex-CmY-7OQR.js → DocsIndex-CJVRa_hE.js} +1 -1
- package/dist/assets/{DocsLayout-BNsSvaz2.js → DocsLayout-C-tYgUZv.js} +1 -1
- package/dist/assets/{DocsSlug-Cb_NMM1k.js → DocsSlug-DmyGpfEy.js} +1 -1
- package/dist/assets/{ExpressionProvider-DqGWVuxV.js → ExpressionProvider-B6z09kM6.js} +1 -1
- package/dist/assets/{FlowRunsPage-B6ustUgi.js → FlowRunsPage-OjGJi-JU.js} +1 -1
- package/dist/assets/{IntegrationsPage-chOxmiyU.js → IntegrationsPage-CrDMDe62.js} +1 -1
- package/dist/assets/{InterfaceListPage-DVETnQm5.js → InterfaceListPage-P3y6hqTX.js} +1 -1
- package/dist/assets/{MarketplaceInstalledPage-DA5pjhAz.js → MarketplaceInstalledPage-CQek7WnV.js} +1 -1
- package/dist/assets/{MarketplacePackagePage-dCIVHBFi.js → MarketplacePackagePage-DL2ivKSc.js} +1 -1
- package/dist/assets/{MarketplacePage-wJb6g1p7.js → MarketplacePage-B-6EokyB.js} +1 -1
- package/dist/assets/{MetadataInspector-Cu-n1FYz.js → MetadataInspector-IQGUoLyp.js} +1 -1
- package/dist/assets/{ObjectDataPage-CP-YSZYQ.js → ObjectDataPage-Bmc3RQhM.js} +1 -1
- package/dist/assets/{PageView-B1_ibRuM.js → PageView-DzUZqB_h.js} +1 -1
- package/dist/assets/{ProfilePage-DEr5iZVB.js → ProfilePage-NklCqPxc.js} +1 -1
- package/dist/assets/{PublicFormsPage-CBcKQbNl.js → PublicFormsPage-CItIvcLQ.js} +1 -1
- package/dist/assets/RecordDetailView-XWxuegfV.js +3 -0
- package/dist/assets/{RecordFormPage-CGQlYWDk.js → RecordFormPage-B-yrhs7J.js} +1 -1
- package/dist/assets/{ReportDefaultInspector-R_p6YStL.js → ReportDefaultInspector-D5Kro5_t.js} +1 -1
- package/dist/assets/{ReportView-BTMrtcGH.js → ReportView-COpZ8PQT.js} +1 -1
- package/dist/assets/{RuntimeDraftBar-agGU39FL.js → RuntimeDraftBar-CSVtuByp.js} +1 -1
- package/dist/assets/{SchemaForm-DJbupOno.js → SchemaForm-DIsxxOZF.js} +1 -1
- package/dist/assets/{SearchResultsPage-CHhZUc6L.js → SearchResultsPage-B2r6kgni.js} +1 -1
- package/dist/assets/{SettingsHub-BGLR_gS7.js → SettingsHub-DQz2HDtZ.js} +1 -1
- package/dist/assets/{SettingsView-Bq-7Zkzs.js → SettingsView-BfOEalDW.js} +1 -1
- package/dist/assets/{SkeletonDetail-B4-UKxai.js → SkeletonDetail-DMOa5zcl.js} +1 -1
- package/dist/assets/{SystemHubPage-CVZVag1e.js → SystemHubPage-DM2VRSIP.js} +1 -1
- package/dist/assets/{abnfDiagram-VCTEODGH-DUS5D5dU.js → abnfDiagram-VCTEODGH-DaPlU6Hz.js} +1 -1
- package/dist/assets/{app-shell-eager-leaves-BB0oaPx6.js → app-shell-eager-leaves-wjbiJgVZ.js} +1 -1
- package/dist/assets/architectureDiagram-5GKGNRK7-Cq014PwG.js +36 -0
- package/dist/assets/{blockDiagram-OSKFZWR5-Bz2hnVmp.js → blockDiagram-OSKFZWR5-vtlcoeZc.js} +1 -1
- package/dist/assets/{c4Diagram-7LVT6UL2-DU3u1Y6c.js → c4Diagram-7LVT6UL2-BrdwRG2M.js} +1 -1
- package/dist/assets/channel-D2IgUFnY.js +1 -0
- package/dist/assets/{chunk-3NF5O7KM-B8Q7HUio.js → chunk-3NF5O7KM-CjWAf_Jo.js} +1 -1
- package/dist/assets/{chunk-4HAMMTFA-BPKwX4iB.js → chunk-4HAMMTFA-BtV_msXT.js} +1 -1
- package/dist/assets/chunk-75Z2AOVW-DdRL9yNr.js +2 -0
- package/dist/assets/chunk-CLGD4ZFX-De9kMAXh.js +1 -0
- package/dist/assets/{chunk-DU6HZSFF-BkY4hAzc.js → chunk-DU6HZSFF-DqjylQO-.js} +1 -1
- package/dist/assets/chunk-F27PBJKO-tEB_K-iD.js +1 -0
- package/dist/assets/{chunk-GMAD6QVW-DZo_NykZ.js → chunk-GMAD6QVW-BMzd_HHM.js} +1 -1
- package/dist/assets/{chunk-GVQU2GXP-9ELY9S6X.js → chunk-GVQU2GXP-B1p1nHC0.js} +1 -1
- package/dist/assets/{chunk-H2I77ZZE-vCr_buP7.js → chunk-H2I77ZZE-ioXC4dHO.js} +1 -1
- package/dist/assets/{chunk-HLEWEB6X-iPkY2ESt.js → chunk-HLEWEB6X-zZ3ZMup3.js} +1 -1
- package/dist/assets/chunk-L3NEJ4N5-DePXufTQ.js +1 -0
- package/dist/assets/{chunk-LQGUR6SS-iVI0GACK.js → chunk-LQGUR6SS-BUWUp_dz.js} +1 -1
- package/dist/assets/{chunk-OSK3NFVY-DcRwXCQD.js → chunk-OSK3NFVY-L7nTUJKT.js} +2 -2
- package/dist/assets/{chunk-P2QGCYS3-nx2-dM5t.js → chunk-P2QGCYS3-BG-i3rdI.js} +1 -1
- package/dist/assets/{chunk-POPQ4Y6H-BxLOacOG.js → chunk-POPQ4Y6H-DLEB8EqK.js} +1 -1
- package/dist/assets/{chunk-PWAF6VOD-2mst9kZu.js → chunk-PWAF6VOD-Be_prJjm.js} +1 -1
- package/dist/assets/{chunk-SVP7TREG-C3BMpr4x.js → chunk-SVP7TREG-BdJpxJji.js} +1 -1
- package/dist/assets/chunk-XXDRQBXY-CEXsCcSu.js +1 -0
- package/dist/assets/{chunk-ZLD2IHE6-ZFqtFJbj.js → chunk-ZLD2IHE6-BLIPZykR.js} +1 -1
- package/dist/assets/classDiagram-CYGNFDIV-BielDdJQ.js +1 -0
- package/dist/assets/classDiagram-v2-TLXNO2FR-BielDdJQ.js +1 -0
- package/dist/assets/cose-bilkent-JH36ORCC-CnLWv9XE.js +1 -0
- package/dist/assets/{createDerive-Best2JCj.js → createDerive-DtfnFzGm.js} +1 -1
- package/dist/assets/{cynefinDiagram-5FMLGOSQ-Lnly8IJd.js → cynefinDiagram-5FMLGOSQ-Do1SZz4I.js} +1 -1
- package/dist/assets/{dagre-OS7QT2EB-CdXLxmTK.js → dagre-OS7QT2EB-CqmZ9Y9O.js} +1 -1
- package/dist/assets/data-adapter-1YRpH3h_.js +5 -0
- package/dist/assets/{default-inspector-registry-DeEG98bO.js → default-inspector-registry-CmSpNwTr.js} +1 -1
- package/dist/assets/{diagram-S7CK7UJ4-DE8I3gxQ.js → diagram-S7CK7UJ4-CMpcDWop.js} +1 -1
- package/dist/assets/{diagram-UQ7AKVKN-D2xQpbEq.js → diagram-UQ7AKVKN-DLK_4yej.js} +1 -1
- package/dist/assets/{diagram-VSXAHHWV-DnttDSlO.js → diagram-VSXAHHWV-MAILxw0S.js} +1 -1
- package/dist/assets/diagram-VX7I27RA-DGiXGVX7.js +24 -0
- package/dist/assets/{diagram-Z3DM3KII-BgB9f0Nv.js → diagram-Z3DM3KII-BywboeGI.js} +1 -1
- package/dist/assets/dist-B88JFSFg.js +5 -0
- package/dist/assets/{ebnfDiagram-PWID7BFC-32WvKbS2.js → ebnfDiagram-PWID7BFC-DdMLbnuP.js} +1 -1
- package/dist/assets/{erDiagram-2YWLMYGG-Dwf8uAdl.js → erDiagram-2YWLMYGG-O6raGx2P.js} +1 -1
- package/dist/assets/flowDiagram-T62WH6J4-CkAxOnqU.js +1 -0
- package/dist/assets/framework-DFE_Mws9.js +36 -0
- package/dist/assets/{ganttDiagram-EL5Y4UJY-DqYIE0Cu.js → ganttDiagram-EL5Y4UJY-Dijdjc50.js} +2 -2
- package/dist/assets/{getIcon-CgyYxSEC.js → getIcon-B4Pp7Q-0.js} +1 -1
- package/dist/assets/gitGraphDiagram-WWUBYQGX-Cfl4OIGG.js +106 -0
- package/dist/assets/{highlighted-body-OFNGDK62-BxO9mjPI.js → highlighted-body-OFNGDK62-BlqGRgbU.js} +1 -1
- package/dist/assets/{i18n-Cfqor-xb.js → i18n-DGcOKnTh.js} +1 -1
- package/dist/assets/{i18n-locales-Bz4c8KXc.js → i18n-locales-BBA090ve.js} +10 -10
- package/dist/assets/index-C5Fu9Kda.css +2 -0
- package/dist/assets/index-ClPLLRzK.js +20 -0
- package/dist/assets/{infoDiagram-FKFFQAWI-Cr1-5_Am.js → infoDiagram-FKFFQAWI-oOVNWlVA.js} +1 -1
- package/dist/assets/{infrastructure-CIpDEFyQ.js → infrastructure-B4zG1jNa.js} +2 -2
- package/dist/assets/{ishikawaDiagram-5VMMS53U-Bsjx7BsE.js → ishikawaDiagram-5VMMS53U-BUfTfup1.js} +1 -1
- package/dist/assets/{journeyDiagram-EYS64GPL-1scn5Z5c.js → journeyDiagram-EYS64GPL-4fyU8Ui9.js} +2 -2
- package/dist/assets/{kanban-definition-UXKFOSKX-DjLQAv5U.js → kanban-definition-UXKFOSKX-qwquHo2y.js} +1 -1
- package/dist/assets/mermaid-GHXKKRXX-_UhQGe8N.js +1 -0
- package/dist/assets/{mermaid.core-pW40dd4u.js → mermaid.core-RfBGJVq5.js} +2 -2
- package/dist/assets/{metadata-admin-pawEBYI9.js → metadata-admin-Bo-vWW2Z.js} +3 -3
- package/dist/assets/{mindmap-definition-THT77NOG-CUcYMB9H.js → mindmap-definition-THT77NOG-cOVHgGB_.js} +1 -1
- package/dist/assets/{pegDiagram-XKGWAZYB-CT1r3sRa.js → pegDiagram-XKGWAZYB-DQikOuPL.js} +1 -1
- package/dist/assets/{pieDiagram-E7YTZNPT-CSi-V1LQ.js → pieDiagram-E7YTZNPT-Cu9wPXiv.js} +2 -2
- package/dist/assets/plugin-calendar-DqlnPeWE.js +1 -0
- package/dist/assets/plugin-charts-hJ5C1pY-.js +7 -0
- package/dist/assets/{plugin-chatbot-BGnkLzFS.js → plugin-chatbot-BeSLDg4N.js} +5 -5
- package/dist/assets/plugin-dashboard-d1o52lHr.js +6 -0
- package/dist/assets/{plugin-form-_fjHxKTV.js → plugin-form-D8x_rH5w.js} +1 -1
- package/dist/assets/plugin-gantt-B2GTMGPH.js +63 -0
- package/dist/assets/plugin-grid-DGXy_yQF.js +9 -0
- package/dist/assets/{plugin-kanban-DA0eW6yj.js → plugin-kanban-CVf6Nj3e.js} +1 -1
- package/dist/assets/plugin-map-hkbw1bGS.js +1 -0
- package/dist/assets/{plugin-markdown-B7zwZHmn.js → plugin-markdown-Bdb2UThR.js} +4 -4
- package/dist/assets/plugin-report-CelulaB7.js +59 -0
- package/dist/assets/{plugin-timeline-B6rsNNAK.js → plugin-timeline-DTcJ-hts.js} +1 -1
- package/dist/assets/plugin-tree-Bk5vG9la.js +1 -0
- package/dist/assets/{plugin-view-5qxxRyZZ.js → plugin-view-CKs41t7o.js} +1 -1
- package/dist/assets/plugins-views-DZmsFOak.js +4 -0
- package/dist/assets/{quadrantDiagram-AXDQQJYC-DUJ_94hm.js → quadrantDiagram-AXDQQJYC-DqTU6p89.js} +3 -3
- package/dist/assets/{railroadDiagram-O6MQD6OU-CEyfAhzM.js → railroadDiagram-O6MQD6OU-CHGgIBKb.js} +1 -1
- package/dist/assets/{requirementDiagram-IS5BZ75X-CAK7hvBg.js → requirementDiagram-IS5BZ75X-B20mHS5h.js} +1 -1
- package/dist/assets/{runtime-metadata-persistence-DYPxFzHI.js → runtime-metadata-persistence-DzS2YaNb.js} +1 -1
- package/dist/assets/{sankeyDiagram-P5KCCOFB-DgYJh7uz.js → sankeyDiagram-P5KCCOFB-oqGY91Cw.js} +3 -3
- package/dist/assets/{sequenceDiagram-WJ2MYXX4-DsQerPtC.js → sequenceDiagram-WJ2MYXX4-CVMm7Aid.js} +1 -1
- package/dist/assets/{src-CVJP2nIc.js → src-D7tZqf12.js} +1 -1
- package/dist/assets/{src-_DxAIBqo.js → src-DCXZnd2l.js} +1 -1
- package/dist/assets/{src-S6pzKItc.js → src-DEMdKbQy.js} +1 -1
- package/dist/assets/src-hcMLuWxG.js +17 -0
- package/dist/assets/stateDiagram-XQSTLZYL-3oM7IdVe.js +1 -0
- package/dist/assets/stateDiagram-v2-IH3M54BS-BznjPAgb.js +1 -0
- package/dist/assets/studioEntry-BUFsLXCL.js +1 -0
- package/dist/assets/{submitRedirect-UXd9NsjL.js → submitRedirect-7ExeC4kw.js} +1 -1
- package/dist/assets/{swimlanes-V6O3JKXN-BiKyiEJr.js → swimlanes-V6O3JKXN-Djgbrkmh.js} +1 -1
- package/dist/assets/swimlanesDiagram-JKAHXJPX-DHJJ3qZq.js +8 -0
- package/dist/assets/{timeline-definition-24CTP7MA-CW5rY3PX.js → timeline-definition-24CTP7MA-k2lbfDvL.js} +2 -2
- package/dist/assets/ui-components-CMHDBJEm.js +37 -0
- package/dist/assets/{ui-layout-UUTFXV6S.js → ui-layout-Jk_qY9Ni.js} +1 -1
- package/dist/assets/{use-book-data-qUZAxIs0.js → use-book-data-CM73PGvc.js} +1 -1
- package/dist/assets/{useActionModal-CkM-zGdy.js → useActionModal-D_iilsul.js} +1 -1
- package/dist/assets/{usePackageL10n-F9isJ9pn.js → usePackageL10n-BfPqgsRL.js} +1 -1
- package/dist/assets/{useSettingsLabel-CSZBfUiw.js → useSettingsLabel-CW2sBbmj.js} +1 -1
- package/dist/assets/vendor-charts-BBlPrtHS.js +67 -0
- package/dist/assets/{vendor-i18n-C1AQDWux.js → vendor-i18n-CzBLXLJU.js} +1 -1
- package/dist/assets/vendor-objectstack-BU0HrnMy.js +270 -0
- package/dist/assets/{vendor-zod-r9lyeyrU.js → vendor-zod-Bwe8XZZa.js} +3 -3
- package/dist/assets/{vennDiagram-4TSXK5OY-C79cMc25.js → vennDiagram-4TSXK5OY-zweM554s.js} +1 -1
- package/dist/assets/{wardleyDiagram-VM6X3IG4-BAO0_jUk.js → wardleyDiagram-VM6X3IG4-Dg9r6Ajz.js} +1 -1
- package/dist/assets/{xychartDiagram-S5SC5T6Z-BIRd7YRo.js → xychartDiagram-S5SC5T6Z-CraplxeN.js} +2 -2
- package/dist/eager-closure.json +87 -87
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/dist/assets/RecordDetailView-A8bbPnkK.js +0 -3
- package/dist/assets/architectureDiagram-5GKGNRK7-mGW8P1lC.js +0 -36
- package/dist/assets/channel-FD4s9EIH.js +0 -1
- package/dist/assets/chunk-75Z2AOVW-CkSdnmiC.js +0 -2
- package/dist/assets/chunk-CLGD4ZFX-BTkDISwp.js +0 -1
- package/dist/assets/chunk-F27PBJKO-DUKg0YWV.js +0 -1
- package/dist/assets/chunk-L3NEJ4N5-Bzz35TZJ.js +0 -1
- package/dist/assets/chunk-XXDRQBXY-iNC8aYmk.js +0 -1
- package/dist/assets/classDiagram-CYGNFDIV-D5Pd2TCl.js +0 -1
- package/dist/assets/classDiagram-v2-TLXNO2FR-D5Pd2TCl.js +0 -1
- package/dist/assets/cose-bilkent-JH36ORCC-CPQv9aQH.js +0 -1
- package/dist/assets/data-adapter-DL25qpAe.js +0 -5
- package/dist/assets/diagram-VX7I27RA-BSEwkn7K.js +0 -24
- package/dist/assets/dist-BpPy7hlB.js +0 -5
- package/dist/assets/flowDiagram-T62WH6J4-CqVSNJ8T.js +0 -1
- package/dist/assets/framework-BfSv4Kb0.js +0 -36
- package/dist/assets/gitGraphDiagram-WWUBYQGX-D1dYmoGu.js +0 -106
- package/dist/assets/index-BU-FzlQ6.js +0 -20
- package/dist/assets/index-_VyGO4ms.css +0 -2
- package/dist/assets/mermaid-GHXKKRXX-NzEcDxBh.js +0 -1
- package/dist/assets/plugin-calendar-BwiiCIjv.js +0 -1
- package/dist/assets/plugin-charts-CDGkx7z5.js +0 -7
- package/dist/assets/plugin-dashboard-Bj4ldCX6.js +0 -6
- package/dist/assets/plugin-gantt-zR8DkpEg.js +0 -63
- package/dist/assets/plugin-grid-kkbz4uec.js +0 -9
- package/dist/assets/plugin-map-DukneTNg.js +0 -1
- package/dist/assets/plugin-report-DaPtlsJr.js +0 -59
- package/dist/assets/plugin-tree-DauauLFc.js +0 -1
- package/dist/assets/plugins-views-iYcMmImr.js +0 -4
- package/dist/assets/src-JX1BkhmR.js +0 -17
- package/dist/assets/stateDiagram-XQSTLZYL-BJndPKik.js +0 -1
- package/dist/assets/stateDiagram-v2-IH3M54BS-Bi94bTLl.js +0 -1
- package/dist/assets/studioEntry-C6G8U-LG.js +0 -1
- package/dist/assets/swimlanesDiagram-JKAHXJPX-DKIR852g.js +0 -8
- package/dist/assets/ui-components-D2lrjG-t.js +0 -43
- package/dist/assets/vendor-charts-CY9WhhzX.js +0 -67
- package/dist/assets/vendor-objectstack-BeKUVjuj.js +0 -270
|
@@ -0,0 +1,17 @@
|
|
|
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}from"./rolldown-runtime-C0FnF6B9.js";import{_ as t,a as n,b as r,f as i,h as a,p as o,r as s}from"./vendor-react-CsWFRkED.js";import{c,g as l,n as u,y as d}from"./infrastructure-B4zG1jNa.js";import{En as f,Fn as p,Ln as m,Nn as h,On as g,a as _,cn as v,dn as y,p as b,qn as x,tn as S,v as C}from"./vendor-objectstack-BU0HrnMy.js";import{u as w}from"./data-adapter-1YRpH3h_.js";import{$t as T,At as E,J as D,Kn as O,On as k,Ot as A,Qt as j,S as M,_r as N,ct as P,en as ee,er as te,gr as ne,ht as re,ot as ie,q as F,sr as ae,ti as oe,zr as se}from"./framework-DFE_Mws9.js";import{d as ce,f as le,l as ue,m as de,o as fe,t as pe,u as me,y as he}from"./i18n-locales-BBA090ve.js";import{$a as ge,$c as _e,$i as ve,$o as ye,$r as be,Ac as xe,Ai as Se,Ao as Ce,Bc as we,Bn as I,Bs as Te,Bt as Ee,Ca as De,Cc as Oe,Cn as ke,Co as Ae,Cr as je,Cs as Me,D as Ne,Da as L,Dc as Pe,Dn as Fe,Do as Ie,Dr as Le,Ds as Re,E as ze,Ec as Be,Ei as Ve,En as He,Er as Ue,Fc as We,Fi as Ge,Fn as Ke,Fs as qe,Ga as Je,Gc as Ye,Gt as Xe,Ha as Ze,Ho as Qe,Hs as $e,Ht as et,I as tt,Ia as nt,Ic as rt,In as R,Io as it,Is as at,Ja as ot,Ji as st,Jo as ct,Js as lt,Jt as ut,Ka as dt,Kc as ft,Ki as pt,Ko as mt,Kt as ht,Li as gt,Lo as _t,Ls as vt,Lt as yt,Ma as bt,Mc as xt,Mi as St,Mr as Ct,Ms as wt,Nc as Tt,Ni as Et,Nn as Dt,No as Ot,Ns as kt,Oa as At,On as jt,Oo as Mt,Or as Nt,Os as Pt,Pa as Ft,Pc as It,Pn as Lt,Po as Rt,Pr as z,Qo as zt,Qr as Bt,Ra as Vt,Rc as Ht,Ri as Ut,Rs as Wt,Rt as Gt,Sc as Kt,Si as qt,Sn as Jt,Sr as Yt,Ss as Xt,St as Zt,Ta as Qt,Tc as $t,Ti as en,Tn as tn,To as nn,Tr as rn,Ts as an,Uo as on,Us as sn,Ut as cn,Vi as ln,Vt as un,Wi as dn,Wt as fn,Xa as pn,Xc as mn,Xi as hn,Xo as gn,Xr as B,Ya as _n,Yi as vn,Yo as yn,Ys as bn,Yt as xn,Zi as Sn,Zo as Cn,Zs as wn,_a as Tn,_o as En,aa as Dn,as as On,bn as kn,br as An,cc as jn,cs as Mn,dc as Nn,do as Pn,ea as Fn,ei as In,es as Ln,fa as Rn,fc as zn,fr as Bn,fs as Vn,gc as Hn,gi as Un,gn as Wn,gr as Gn,gs as Kn,ha as qn,hc as Jn,hr as Yn,ht as Xn,ic as Zn,ii as Qn,il as V,io as $n,jr as er,js as tr,ka as nr,kc as rr,ko as ir,kr as ar,ks as or,la as sr,li as cr,lo as lr,ma as ur,mi as dr,mo as fr,mr as pr,ms as mr,mt as hr,nc as gr,ni as _r,nl as vr,ns as yr,oa as br,os as xr,pa as Sr,pc as Cr,po as wr,pr as Tr,qc as Er,qs as Dr,qt as Or,ra as kr,rc as Ar,ri as jr,rl as Mr,ro as Nr,rs as Pr,sa as Fr,sc as Ir,so as Lr,tc as Rr,tl as zr,ts as Br,ui as Vr,uo as Hr,ur as Ur,us as Wr,va as Gr,vc as Kr,vi as qr,vn as Jr,vo as H,vr as Yr,vs as Xr,vt as Zr,wn as Qr,wo as $r,wr as ei,ws as ti,xa as ni,xc as ri,xi as ii,xn as ai,xr as oi,yc as si,yi as ci,yn as li,yo as ui,yr as di,ys as fi,za as pi,zo as mi,zs as hi,zt as gi}from"./ui-components-CMHDBJEm.js";import{r as _i}from"./vendor-ui-utils-BFw4cGI6.js";import{n as vi,o as yi,s as bi}from"./createDerive-DtfnFzGm.js";import{n as xi}from"./assistantBus-DNH-fDWN.js";import{a as Si,r as Ci}from"./ExpressionProvider-B6z09kM6.js";import{a as wi,f as Ti,i as Ei,l as Di,p as Oi,u as ki}from"./ActionResultDialog-Bsr2GS71.js";import{A as Ai,C as ji,M as Mi,N as Ni,a as Pi,i as Fi,j as Ii,x as Li}from"./RecordDetailView-XWxuegfV.js";import{a as Ri,i as zi,o as Bi,r as Vi,t as Hi}from"./appRoute-DEVGXLLH.js";import{f as Ui}from"./plugin-chatbot-BeSLDg4N.js";import{w as Wi}from"./vendor-zod-Bwe8XZZa.js";import"./app-shell-eager-leaves-wjbiJgVZ.js";import{n as Gi}from"./utils-MjUhYVsx.js";import{a as Ki,i as qi,n as Ji,o as Yi,s as Xi}from"./ui-layout-Jk_qY9Ni.js";import{t as Zi}from"./InterfaceListPage-P3y6hqTX.js";import{t as Qi}from"./getIcon-B4Pp7Q-0.js";import{B as $i,C as ea,D as ta,E as na,F as ra,G as ia,H as aa,I as oa,K as sa,L as ca,M as la,N as ua,O as da,R as fa,S as pa,T as ma,U as ha,V as ga,W as _a,Y as va,_ as ya,b as ba,c as xa,d as Sa,f as Ca,g as wa,h as Ta,i as Ea,j as Da,k as Oa,m as ka,o as Aa,p as ja,q as Ma,r as Na,v as Pa,w as Fa,x as Ia,y as La,z as Ra}from"./SchemaForm-DIsxxOZF.js";import{n as za}from"./plugins-views-DZmsFOak.js";import{_ as Ba,a as Va,b as Ha,c as Ua,d as U,f as Wa,g as W,h as Ga,i as Ka,l as qa,m as Ja,n as Ya,o as Xa,p as Za,r as Qa,s as $a,t as eo,u as to,v as G,x as K,y as no}from"./ReportDefaultInspector-D5Kro5_t.js";import{c as ro,d as io,f as ao,g as oo,i as q,n as so,r as J,t as co}from"./i18n-DGcOKnTh.js";import{n as lo}from"./componentRegistry-ByxoJqMW.js";import{S as uo,T as fo,a as po,f as mo,l as ho,n as go,o as _o,x as vo,y as yo}from"./default-inspector-registry-CmSpNwTr.js";var Y=e(r(),1);function bo(){let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,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 xo(){let{agents:e,isLoading:t}=Ui({apiBase:bo()}),n=(0,Y.useRef)(!1);t&&(n.current=!0);let r=e.length>0;return{enabled:r,isLoading:r?!1:t||!n.current}}var X=s(),So=`flow-palette-recents`,Co=So,wo=5;function To(){try{if(typeof localStorage>`u`)return[];let e=localStorage.getItem(Co);if(!e)return[];let t=JSON.parse(e);return Array.isArray(t)?t.filter(e=>typeof e==`string`).slice(0,wo):[]}catch{return[]}}function Eo(e){if(e)try{if(typeof localStorage>`u`)return;let t=[e,...To().filter(t=>t!==e)].slice(0,wo);localStorage.setItem(Co,JSON.stringify(t))}catch{}}var Do=So;function Oo(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`).slice(0,5):[]}function ko(e){try{let t=localStorage.getItem(ki(Do,e));return t?Oo(JSON.parse(t)):[]}catch{return[]}}function Ao(e,t){try{localStorage.setItem(ki(Do,t),JSON.stringify(e))}catch{}}function jo(e,t){if(!t)return{list:e,didMigrate:!1};let n;try{n=localStorage.getItem(Do)}catch{return{list:e,didMigrate:!1}}if(n==null)return{list:e,didMigrate:!1};let r=[];try{r=Oo(JSON.parse(n))}catch{}try{localStorage.removeItem(Do)}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 Mo=(0,Y.createContext)(null);function No({children:e}){let{user:t}=l(),n=t?.id??null,r=Oi(`flowPaletteRecents`),[i,a]=(0,Y.useState)(()=>ko(n));Ti(ki(Do,n),e=>{a(Oo(e))});let o=(0,Y.useMemo)(()=>Di(async e=>{r&&await r.save(e)},500),[r]);(0,Y.useEffect)(()=>()=>void o.flush(),[o]);let s=(0,Y.useCallback)(e=>{Ao(e,n),r&&o.schedule(e)},[n,r,o]),c=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=++c.current,t=!1;return(async()=>{let i=ko(n),s=r?Oo(await r.load().catch(()=>[])):[];if(t||e!==c.current)return;let{list:l,didMigrate:u}=jo(s.length?s:i,n);a(l),Ao(l,n),u&&r&&o.schedule(l)})(),()=>{t=!0}},[r,n,o]);let u=(0,Y.useCallback)(e=>{e&&a(t=>{let n=[e,...t.filter(t=>t!==e)].slice(0,5);return s(n),n})},[s]),d=(0,Y.useMemo)(()=>({recents:i,recordRecent:u}),[i,u]);return(0,X.jsx)(Mo.Provider,{value:d,children:e})}function Po(){let e=(0,Y.useContext)(Mo),[t,n]=(0,Y.useState)(()=>To()),r=(0,Y.useCallback)(e=>{Eo(e),n(To())},[]);return e||{recents:t,recordRecent:r}}function Fo(e,t){if(!e)return``;let n=new Date(e).getTime();return Number.isNaN(n)?``:ue(n,t)}function Io(e){let t=[],n=new Map;for(let r of e){let e=(r.type??``).trim(),i=(r.title??``).trim(),a=e||i?`${e}\u0000${i}`:`__row__${r.id}`,o=n.get(a);o||(o={key:a,type:r.type,title:r.title,items:[],unreadCount:0,latestCreatedAt:r.created_at},n.set(a,o),t.push(o)),o.items.push(r),r.is_read||(o.unreadCount+=1),r.created_at&&(!o.latestCreatedAt||r.created_at>o.latestCreatedAt)&&(o.latestCreatedAt=r.created_at)}return t}function Lo({notifications:e,unreadCount:t,pendingApprovalsCount:n,activities:r,onMarkAllRead:i,onMarkRead:s,onMarkManyRead:c}){let{t:l,language:u}=he(),d=o(),f=a(),{currentAppName:p}=ji(),{apps:m}=D(),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(`notifications`),[y,b]=(0,Y.useState)(`unread`),[x,S]=(0,Y.useState)(()=>new Set),C=(0,Y.useMemo)(()=>Io(e),[e]).reduce((e,t)=>e+ +(t.unreadCount>0),0),w=C+n,T=l(`sidebar.inboxAriaLabel`,{defaultValue:`Open inbox`}),E=(0,Y.useRef)(null),[O,k]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{let e=E.current;if(e!==null&&w>e){k(!0);let e=window.setTimeout(()=>k(!1),1200);return()=>window.clearTimeout(e)}E.current=w},[w]),(0,Y.useEffect)(()=>{O||(E.current=w)},[O,w]);let A=()=>{g(!1);let e=p??f.appName;d(e?`/apps/${e}/system/approvals`:`/apps/setup/system/approvals`)},j=Ri(m,p??f.appName),M=()=>{g(!1),d(`/apps/${j}/sys_inbox_message?view=mine`)},N=()=>{g(!1),d(`/apps/${j}/sys_activity`)},P=e=>{s(e.id);let t=Bi(e.action_url,j);if(!t){M();return}if(g(!1),t.kind===`external`){window.open(t.url,`_blank`,`noopener,noreferrer`);return}d(t.path)},ee=e=>{S(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},te=e=>{let t=e.items.filter(e=>!e.is_read).map(e=>e.id);t.length!==0&&(c?c(t):t.forEach(s))},ne=(e,t)=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>P(e),className:`w-full text-left ${t?`pl-9 pr-3 py-2`:`px-3 py-2.5`} hover:bg-accent transition-colors duration-150 ${e.is_read?``:`bg-accent/40`}`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(`span`,{className:`mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full bg-primary transition-opacity duration-200 ${e.is_read?`opacity-0`:`opacity-100`}`,"aria-hidden":!0}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium leading-tight truncate`,children:e.title}),e.body&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-2 mt-0.5`,children:e.body}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:Fo(e.created_at,u)})]})]})});return(0,X.jsxs)(Dt,{open:h,onOpenChange:g,children:[(0,X.jsx)(Ke,{asChild:!0,children:(0,X.jsxs)(B,{variant:`ghost`,size:`icon`,className:`h-8 w-8 relative shrink-0 ${O?`motion-safe:animate-bounce`:``}`,"aria-label":T,title:l(`sidebar.inbox`,{defaultValue:`Inbox`}),children:[(0,X.jsx)(we,{className:`h-4 w-4`}),w>0&&(0,X.jsx)(`span`,{"data-testid":`inbox-bell-badge`,className:`absolute -top-0.5 -right-0.5 h-4 min-w-[16px] rounded-full bg-red-500 text-[10px] leading-4 text-white text-center px-1 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:fade-in-0 motion-safe:duration-200`,children:w>9?`9+`:w},w)]})}),(0,X.jsxs)(Lt,{align:`end`,sideOffset:8,className:`w-96 p-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-3 pt-3 pb-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold`,children:l(`sidebar.inbox`,{defaultValue:`Inbox`})}),_===`notifications`&&t>0&&(0,X.jsx)(`button`,{type:`button`,onClick:i,className:`text-xs text-muted-foreground hover:text-foreground`,children:l(`notifications.markAllRead`,{defaultValue:`Mark all read`})})]}),w>0&&(0,X.jsxs)(`div`,{"data-testid":`inbox-badge-breakdown`,className:`flex flex-wrap items-center gap-x-2 gap-y-1 px-3 pb-2 text-xs text-muted-foreground`,children:[(0,X.jsx)(`span`,{"data-testid":`inbox-badge-breakdown-total`,className:`font-medium text-foreground`,children:l(`notifications.badgeTotal`,{defaultValue:`{{total}} total`,total:w})}),(0,X.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,X.jsx)(`span`,{"data-testid":`inbox-badge-breakdown-notifications`,children:l(`notifications.badgeNotifications`,{defaultValue:`{{unread}} notifications`,unread:C})}),(0,X.jsx)(`span`,{"aria-hidden":!0,children:`+`}),(0,X.jsx)(`span`,{"data-testid":`inbox-badge-breakdown-approvals`,children:l(`notifications.badgeApprovals`,{defaultValue:`{{approvals}} pending approvals`,approvals:n})})]}),(0,X.jsxs)(gi,{value:_,onValueChange:e=>v(e),className:`w-full`,children:[(0,X.jsxs)(un,{className:`w-full justify-start rounded-none border-b bg-transparent px-1 h-9`,children:[(0,X.jsxs)(et,{value:`notifications`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,X.jsx)(we,{className:`h-3.5 w-3.5`}),l(`sidebar.notifications`,{defaultValue:`Notifications`}),C>0&&(0,X.jsx)(`span`,{className:`ml-0.5 inline-flex h-4 min-w-[16px] items-center justify-center rounded-full bg-red-500 px-1 text-[10px] text-white motion-safe:animate-in motion-safe:zoom-in-75 motion-safe:duration-200`,children:C>9?`9+`:C},`notif-${C}`)]}),(0,X.jsxs)(et,{value:`approvals`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,X.jsx)(dn,{className:`h-3.5 w-3.5`}),l(`sidebar.approvals`,{defaultValue:`Approvals`}),n>0&&(0,X.jsx)(`span`,{className:`ml-0.5 inline-flex h-4 min-w-[16px] items-center justify-center rounded-full bg-amber-500 px-1 text-[10px] text-white motion-safe:animate-in motion-safe:zoom-in-75 motion-safe:duration-200`,children:n>9?`9+`:n},`appr-${n}`)]}),(0,X.jsxs)(et,{value:`activity`,className:`text-xs gap-1.5 data-[state=active]:bg-transparent`,children:[(0,X.jsx)(Mr,{className:`h-3.5 w-3.5`}),l(`sidebar.activityFeed`,{defaultValue:`Activity feed`})]})]}),(0,X.jsxs)(Ee,{value:`notifications`,className:`m-0 max-h-80 overflow-auto`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-2 py-1.5`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>b(`unread`),className:`text-xs px-2 py-1 rounded-md transition-colors ${y===`unread`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:[l(`notifications.filterUnread`,{defaultValue:`Unread`}),C>0&&(0,X.jsx)(`span`,{className:`ml-1 text-[10px] opacity-70`,children:C})]}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>b(`all`),className:`text-xs px-2 py-1 rounded-md transition-colors ${y===`all`?`bg-accent text-foreground font-medium`:`text-muted-foreground hover:text-foreground`}`,children:l(`notifications.filterAll`,{defaultValue:`All`})})]}),(()=>{let t=y===`unread`?e.filter(e=>!e.is_read):e;if(t.length===0)return(0,X.jsx)(`div`,{className:`px-3 py-8 text-sm text-muted-foreground text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:y===`unread`?l(`notifications.emptyUnread`,{defaultValue:`You're all caught up`}):l(`notifications.empty`,{defaultValue:`No notifications`})});let n=Io(t);return(0,X.jsx)(`ul`,{className:`divide-y`,children:n.map((e,t)=>{let n={className:`motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-top-1 motion-safe:duration-200`,style:{animationDelay:`${Math.min(t,6)*20}ms`}};if(e.items.length===1)return(0,X.jsx)(`li`,{...n,children:ne(e.items[0],!1)},e.key);let r=x.has(e.key);return(0,X.jsxs)(`li`,{...n,children:[(0,X.jsxs)(`div`,{className:`flex items-stretch`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>ee(e.key),"aria-expanded":r,className:`flex-1 min-w-0 text-left px-3 py-2.5 hover:bg-accent transition-colors duration-150 ${e.unreadCount>0?`bg-accent/40`:``}`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(`span`,{className:`mt-1.5 h-1.5 w-1.5 shrink-0 rounded-full bg-primary transition-opacity duration-200 ${e.unreadCount>0?`opacity-100`:`opacity-0`}`,"aria-hidden":!0}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium leading-tight truncate`,children:e.title}),(0,X.jsxs)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 text-[10px] font-medium leading-4 text-muted-foreground`,"aria-label":l(`notifications.groupCount`,{defaultValue:`{{count}} notifications`,count:e.items.length}),children:[`×`,e.items.length]})]}),e.items[0].body&&(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground line-clamp-1 mt-0.5`,children:e.items[0].body}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[Fo(e.latestCreatedAt,u),e.unreadCount>0&&(0,X.jsxs)(`span`,{className:`ml-1`,children:[`·`,` `,l(`notifications.groupUnread`,{defaultValue:`{{count}} unread`,count:e.unreadCount})]})]})]}),(0,X.jsx)(Cr,{className:`mt-1 h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200 ${r?`rotate-90`:``}`,"aria-hidden":!0})]})}),e.unreadCount>0&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>te(e),className:`shrink-0 px-2 text-[10px] text-muted-foreground hover:text-foreground hover:bg-accent transition-colors border-l`,title:l(`notifications.groupMarkReadTitle`,{defaultValue:`Mark all of this type read`}),children:l(`notifications.groupMarkRead`,{defaultValue:`Mark read`})})]}),r&&(0,X.jsx)(`ul`,{className:`divide-y border-t bg-muted/20`,children:e.items.map(e=>(0,X.jsx)(`li`,{children:ne(e,!0)},e.id))})]},e.key)})})})(),(0,X.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,X.jsx)(`button`,{type:`button`,onClick:M,className:`text-xs text-primary hover:underline`,children:l(`notifications.viewAll`,{defaultValue:`View all notifications`})})})]}),(0,X.jsx)(Ee,{value:`approvals`,className:`m-0 max-h-80 overflow-auto`,children:(0,X.jsx)(`div`,{className:`px-3 py-6 text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:n>0?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(dn,{className:`mx-auto h-6 w-6 text-amber-500 motion-safe:animate-in motion-safe:zoom-in-50 motion-safe:duration-300`}),(0,X.jsx)(`div`,{className:`mt-2 text-sm font-medium`,children:l(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:n})}),(0,X.jsx)(B,{size:`sm`,className:`mt-3`,onClick:A,children:l(`notifications.viewApprovals`,{defaultValue:`View approvals`})})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:l(`notifications.noPendingApprovals`,{defaultValue:`No pending approvals`})}),(0,X.jsx)(`button`,{type:`button`,onClick:A,className:`mt-2 text-xs text-primary hover:underline`,children:l(`notifications.openApprovalsInbox`,{defaultValue:`Open Approvals Inbox`})})]})})}),(0,X.jsxs)(Ee,{value:`activity`,className:`m-0 max-h-80 overflow-auto`,children:[r.length===0?(0,X.jsx)(`div`,{className:`px-3 py-8 text-sm text-muted-foreground text-center motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-300`,children:l(`layout.activityFeed.empty`,{defaultValue:`No recent activity`})}):(0,X.jsx)(`ul`,{className:`divide-y`,children:r.slice(0,20).map((e,t)=>(0,X.jsxs)(`li`,{className:`px-3 py-2.5 motion-safe:animate-in motion-safe:fade-in-0 motion-safe:slide-in-from-top-1 motion-safe:duration-200`,style:{animationDelay:`${Math.min(t,6)*20}ms`},children:[(0,X.jsxs)(`div`,{className:`text-sm leading-tight truncate`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:e.description})]}),(0,X.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-0.5`,children:[Fo(e.timestamp,u),` · `,e.objectName]})]},e.id))}),(0,X.jsx)(`div`,{className:`border-t px-3 py-2 text-center`,children:(0,X.jsx)(`button`,{type:`button`,onClick:N,className:`text-xs text-primary hover:underline`,children:l(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`})})})]})]})]})]})}function Ro(e){return e===void 0||e===`ready`||e===`error`}function zo(e,t,n){return t!==void 0&&t!==`ready`||n.length===0?`unknown`:n.some(t=>t?.name===e)?`present`:`absent`}function Bo(e){let{getItemsByType:t,getTypeStatus:n}=D(),r=t(`object`),i=n?.(`object`);return{presence:zo(e,i,r),settled:Ro(i)}}var Vo={created:`create`,updated:`update`,deleted:`delete`,assigned:`update`,shared:`update`,commented:`comment`,mentioned:`comment`,system:`system`,completed:`system`,scheduled:`system`,login:`system`,logout:`system`},Ho=`system`,Uo=new Set;function Wo(e){Uo.has(e)||(Uo.add(e),console.warn(`[app-shell] rendered a sys_activity row with type "${e}" through the generic "${Ho}" presentation: no activity item type is mapped for it. \`sys_activity.type\` is author-extensible (objectstack#11507, ruled 2026-08-24) and is not validated on write, so a producer can store a value the platform never declared — the row is shown rather than dropped, and it no longer claims to be an update. Map it in ACTIVITY_TYPE_TO_ACTIVITY_ITEM_TYPE (@object-ui/app-shell, layout/activityItemType.ts) to give it its own presentation.`))}function Go(e){return(Object.prototype.hasOwnProperty.call(Vo,e)?Vo[e]:void 0)||(Wo(e),Ho)}function Ko(e){let t=e.timestamp;return String(!t||t===`NOW()`||Number.isNaN(Date.parse(String(t)))?e.created_at??``:t)}function qo(e){if(!e||typeof e!=`object`)return null;let t=e;return typeof t.type!=`string`||String(t.summary??``).trim().length===0?null:{id:String(t.id),type:Go(t.type),objectName:String(t.object_name??``),recordId:t.record_id==null?void 0:String(t.record_id),user:String(t.actor_name??``),description:String(t.summary??``),timestamp:Ko(t)}}var Jo=3e4,Yo=1e4,Xo=6e4,Zo=12e4,Qo=3e4,$o=6e4,es=[],ts=[],ns=class{empty;pollMs;snapshot;key=null;listeners=new Set;runner=null;consumers=0;inFlight=!1;unavailable=!1;retiredAt=0;probesLeft=3;fetchedAt=0;timer=null;backoffMs;visibilityBound=!1;constructor(e,t){this.empty=e,this.pollMs=t,this.snapshot={value:e,status:`idle`},this.idleSnapshot=this.snapshot,this.backoffMs=t}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.snapshot;idleSnapshot;attach(e,t){return e!==this.key&&(this.key=e,this.unavailable=!1,this.retiredAt=0,this.probesLeft=3,this.fetchedAt=0,this.backoffMs=this.pollMs,this.publish(this.empty,`idle`)),this.runner=t,this.consumers+=1,this.consumers===1&&(this.bindVisibility(),this.schedule()),this.refresh(),()=>{this.consumers=Math.max(0,this.consumers-1),this.consumers===0&&(this.stopPolling(),this.unbindVisibility())}}async refresh(e=!1){let t=this.runner;if(!t||this.inFlight)return;let n=this.unavailable;if(n&&!this.mayProbe()||!e&&!n&&this.fetchedAt&&Date.now()-this.fetchedAt<Qo)return;this.inFlight=!0,this.snapshot.status===`idle`&&this.publish(this.snapshot.value,`loading`);let r=!1;try{let e=await t({markUnavailable:()=>n?this.spendProbe():this.retire(),markFailed:()=>{r=!0}});e===void 0?r&&(n?this.spendProbe():this.fail()):(this.unavailable=!1,this.probesLeft=3,this.fetchedAt=Date.now(),this.backoffMs=this.pollMs,this.publish(e,`ready`))}catch{n?this.spendProbe():this.fail()}finally{this.inFlight=!1,this.consumers>0&&this.schedule()}}mayProbe(){return this.probesLeft>0&&Date.now()-this.retiredAt>=6e4}retire(){this.unavailable=!0,this.retiredAt=Date.now(),this.fetchedAt=Date.now(),this.stopPolling(),this.publish(this.snapshot.value,`ready`)}spendProbe(){this.probesLeft=Math.max(0,this.probesLeft-1),this.retiredAt=Date.now(),this.fetchedAt=Date.now(),this.stopPolling()}fail(){this.backoffMs=Math.min(Math.max(this.backoffMs,this.pollMs)*2,Zo),this.publish(this.snapshot.value,`error`)}schedule(){if(this.timer)return;if(this.unavailable){if(this.probesLeft<=0)return;this.timer=setTimeout(()=>{this.timer=null,this.refresh(!0)},$o);return}if(this.pollMs<=0)return;let e=typeof document<`u`&&document.hidden?Math.max(Xo,this.backoffMs):this.backoffMs;this.timer=setTimeout(()=>{this.timer=null,this.refresh(!0)},e)}onVisibilityChange=()=>{typeof document>`u`||document.hidden||this.consumers!==0&&(this.unavailable&&!this.mayProbe()||(this.stopPolling(),this.unavailable||(this.backoffMs=this.pollMs),this.refresh(!0)))};bindVisibility(){this.pollMs<=0||this.visibilityBound||typeof document>`u`||(document.addEventListener(`visibilitychange`,this.onVisibilityChange),this.visibilityBound=!0)}unbindVisibility(){!this.visibilityBound||typeof document>`u`||(document.removeEventListener(`visibilitychange`,this.onVisibilityChange),this.visibilityBound=!1)}stopPolling(){this.timer&&=(clearTimeout(this.timer),null)}publish(e,t){if(!(Object.is(e,this.snapshot.value)&&t===this.snapshot.status)){this.snapshot={value:e,status:t};for(let e of[...this.listeners])e()}}reset(){this.stopPolling(),this.unbindVisibility(),this.snapshot={value:this.empty,status:`idle`},this.key=null,this.runner=null,this.consumers=0,this.inFlight=!1,this.unavailable=!1,this.retiredAt=0,this.probesLeft=3,this.fetchedAt=0,this.backoffMs=this.pollMs}};function rs(e,t,n){let r=(0,Y.useSyncExternalStore)(e.subscribe,e.getSnapshot,e.getSnapshot),i=(0,Y.useRef)(n);return(0,Y.useEffect)(()=>{i.current=n}),(0,Y.useEffect)(()=>{if(t)return e.attach(t,e=>i.current(e))},[e,t]),t?r:e.idleSnapshot}var is=new ns(0,Jo);function as(e){let t=e,n=[];t?.id&&n.push(t.id),t?.email&&n.push(t.email);for(let e of t?.positions??[])e&&n.push(`role:${e}`);return n}function os(){let{user:e}=l(),t=as(e);return rs(is,e?.id&&t.length>0?t.join(`,`):null,async({markUnavailable:e,markFailed:n})=>{let r=``.replace(/\/$/,``),i=new URLSearchParams({status:`pending`,approverId:t.join(`,`)}),a=await fetch(`${r}/api/v1/approvals/requests?${i}`,{credentials:`include`,headers:Pi()});if(a.status===404){e();return}if(!a.ok){n();return}let o=await a.json().catch(()=>null),s=new Set;for(let e of o?.data||[])s.add(e.id);return s.size}).value}var ss=new ns(es,0),cs=new WeakMap,ls=0;function us(e){if(!e||typeof e!=`object`)return null;let t=cs.get(e);return t||(t=`adapter@${++ls}`,cs.set(e,t)),t}function ds(e){return e.map(e=>qo(e)).filter(e=>e!==null)}function fs(e){let t=e;return t?.httpStatus===404||t?.status===404||w(e,`OBJECT_NOT_FOUND`)}function ps(){let e=F(),t=Bo(`sys_activity`);return rs(ss,t.settled?us(e):null,async({markUnavailable:n,markFailed:r})=>{if(!e)return;if(t.presence===`absent`){n();return}let i=await Promise.resolve(e.find(`sys_activity`,{$orderby:{timestamp:`desc`},$top:20})).catch(e=>(fs(e)?n():r(),null));if(i)return ds(Array.isArray(i.data)?i.data:[])}).value}function ms(e){let t=ps();return(0,Y.useMemo)(()=>t.filter(e=>{let t=e.user.trim();return t.length>0&&t.toLowerCase()!==`system`}).slice(0,e),[t,e])}var hs=new ns(ts,Yo),gs=new Set([`read`,`clicked`,`dismissed`]);function _s(e,t){let n=new Map;for(let e of t){let t=e,r=t?.notification_id==null?``:String(t.notification_id);if(!r)continue;let i=String(t?.state??``),a=n.get(r);(!a||!gs.has(a.state)&&gs.has(i))&&n.set(r,{id:String(t?.id),state:i})}return e.map(e=>{let t=e,r=t?.notification_id==null?null:String(t.notification_id),i=r?n.get(r):void 0;return{id:String(t.id),notification_id:r,receipt_id:i?.id??null,type:t.topic??`notification`,title:t.title??``,body:t.body_md??null,action_url:t.action_url??null,is_read:i?gs.has(i.state):!1,created_at:t.created_at}})}function vs(){let e=F(),{user:t}=l(),n=t?.id,r=us(e);return rs(hs,r&&n?`${r}:${n}`:null,async({markUnavailable:t,markFailed:r})=>{if(!(!e||!n))try{let[t,r]=await Promise.all([Promise.resolve(e.find(`sys_inbox_message`,{$filter:{user_id:n},$orderby:{created_at:`desc`},$top:20})),Promise.resolve(e.find(`sys_notification_receipt`,{$filter:{user_id:n,channel:`inbox`},$top:200})).catch(()=>({data:[]}))]);return _s(Array.isArray(t?.data)?t.data:[],Array.isArray(r?.data)?r.data:[])}catch(e){fs(e)?t():r();return}})}var ys=new Set;function bs(){let{value:e}=vs(),[t,n]=(0,Y.useState)(ys),r=(0,Y.useMemo)(()=>t.size===0?e:e.map(e=>t.has(e.id)?{...e,is_read:!0}:e),[e,t]),i=os(),a=r.reduce((e,t)=>e+ +!t.is_read,0),o=(0,Y.useCallback)(async(e,t)=>{let n=``.replace(/\/$/,``);await fetch(`${n}/api/v1/notifications/${e}`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,...Pi()},body:JSON.stringify(t?{ids:t}:{})})},[]),s=(0,Y.useCallback)(e=>{e.length!==0&&n(t=>{let n=new Set(t);for(let t of e)n.add(t);return n})},[]),c=(0,Y.useCallback)(async e=>{let t=r.find(t=>t.id===e);if(s([e]),t?.notification_id)try{await o(`read`,[t.notification_id])}catch{}},[r,s,o]);return{notifications:r,unreadCount:a,pendingApprovalsCount:i,markAllRead:(0,Y.useCallback)(async()=>{if(r.filter(e=>!e.is_read).length){s(r.map(e=>e.id));try{await o(`read/all`)}catch{}}},[r,s,o]),markRead:c,markManyRead:(0,Y.useCallback)(async e=>{let t=new Set(e),n=r.filter(e=>t.has(e.id)&&!e.is_read).map(e=>e.notification_id).filter(e=>!!e);if(s(e),n.length)try{await o(`read`,n)}catch{}},[r,s,o])}}function xs(){let{execute:e}=ie(),{getItem:t}=D();return(0,Y.useCallback)(n=>{(async()=>{let r=n.actionDef,i=r?.actionName;if(!i){console.warn(`[nav] action item has no actionDef.actionName — nothing to dispatch`,n?.id),_i.error(`This menu item is not configured to run an action.`);return}let a;try{a=await t(`action`,i)}catch(e){console.warn(`[nav] failed to resolve action '${i}'`,e),_i.error(`Could not load action "${i}".`);return}if(!a){console.warn(`[nav] action '${i}' is not defined — nav item ${n?.id} cannot run`),_i.error(`Action "${i}" is not defined.`);return}try{let{params:t,...n}=a,i={...n},o=Array.isArray(t)?t:[];o.length>0&&(i.actionParams=o),r?.params&&typeof r.params==`object`&&(i.params={...r.params}),await e(i)}catch(e){console.warn(`[nav] action '${i}' failed`,e),_i.error(`Action "${i}" failed to run.`)}})()},[e,t])}function Ss(e,t){let n=new Set(t.filter(e=>typeof e==`string`));for(let t=1;t<1e4;t++){let r=`${e}_${t}`;if(!n.has(r))return r}return`${e}_${Date.now()}`}function Cs(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 ws({label:e,ariaLabel:t,id:n,value:r,onCommit:i,options:a,placeholder:o=`Select…`,searchPlaceholder:s=`Search or type…`,emptyText:c=`No match — keep typing to use a custom value.`,disabled:l,loading:u,allowCustom:d=!0,mono:f,className:p}){let[m,h]=Y.useState(!1),[g,_]=Y.useState(``),v=Y.useId(),y=e?v:n,b=a.find(e=>e.value===r),x=b?b.label:r||(u?`Loading…`:o),S=Y.useMemo(()=>a.filter(e=>Cs(e,g)),[a,g]),C=Y.useMemo(()=>{let e=[],t=new Map;for(let n of S){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)}))},[S]),w=g.trim(),T=d&&!!w&&!a.some(e=>e.value===w),E=e=>{i(e),h(!1),_(``)},D=(0,X.jsxs)(Dt,{open:m,onOpenChange:e=>{h(e),e||_(``)},children:[(0,X.jsx)(Ke,{asChild:!0,children:(0,X.jsxs)(B,{type:`button`,variant:`outline`,role:`combobox`,id:y,"aria-label":t,"aria-expanded":m,disabled:l,className:V(`h-8 w-full justify-between px-2 text-sm font-normal`,p),children:[(0,X.jsx)(`span`,{className:V(`truncate`,f&&`font-mono`,!b&&!r&&`text-muted-foreground`),children:x}),(0,X.jsx)(jn,{className:`ml-2 h-3.5 w-3.5 shrink-0 opacity-50`})]})}),(0,X.jsx)(Lt,{align:`start`,className:`w-[var(--radix-popover-trigger-width)] min-w-[14rem] p-0`,children:(0,X.jsxs)(Ur,{shouldFilter:!1,children:[(0,X.jsx)(pr,{value:g,onValueChange:_,placeholder:s}),(0,X.jsxs)(Gn,{children:[!T&&S.length===0&&(0,X.jsx)(Bn,{children:c}),T&&(0,X.jsx)(Tr,{children:(0,X.jsx)(Yn,{value:`__custom__${w}`,onSelect:()=>E(w),children:(0,X.jsxs)(`span`,{className:`truncate`,children:[`Use `,(0,X.jsxs)(`span`,{className:`font-mono`,children:[`“`,w,`”`]})]})})}),C.map((e,t)=>(0,X.jsx)(Tr,{heading:e.heading||void 0,children:e.items.map(e=>(0,X.jsxs)(Yn,{value:e.value,onSelect:()=>E(e.value),children:[(0,X.jsx)(Hn,{className:V(`h-3.5 w-3.5`,e.value===r?`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${t}`))]})]})})]});return e?(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{htmlFor:v,className:`text-xs text-muted-foreground`,children:e}),D]}):D}var Ts=new Set([`lookup`,`master_detail`,`masterdetail`,`master-detail`]);function Es(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 Ds(e){let t=e.reference;return typeof t==`string`&&t?t:void 0}function Os(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 ks(e,t){if(!e)return{label:t,fields:[],relationships:[]};let n=Es(e.label,t),r=aa(e.fields).entries.map(e=>({name:e.name,label:Es(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&&Ts.has(e.type.toLowerCase())).map(e=>({name:e.name,label:e.label,referenceTo:Ds(e.def)}))}}function As(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 js(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=As(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 Ms(e,t){if(!e||typeof e!=`object`)return!1;if(Array.isArray(e))return e.some(e=>Ms(e,t));let n=e;return typeof n.dataset==`string`&&n.dataset===t||Object.values(n).some(e=>e&&typeof e==`object`&&Ms(e,t))}function Ns(){let e=yi(),[t,n]=Y.useState({options:[],loading:!0});return Y.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:Es(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 Ps(e,t){let n=yi(),r=JSON.stringify(t),[i,a]=Y.useState({relationships:[],fieldOptions:[],loading:!!e});return Y.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=ks(i,e),s=JSON.parse(r),c={[e]:o},l=async e=>{if(c[e])return c[e];let t;try{t=ks(await n.get(`object`,e),e)}catch{t=ks(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=As(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:js(o,s,c),loading:!1})}catch{t||a({relationships:[],fieldOptions:[],loading:!1})}})(),()=>{t=!0}},[n,e,r]),i}function Fs(e){let t=yi(),[n,r]=Y.useState({reports:0,dashboards:0,loading:!!e});return Y.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=>Ms(t,e)).length,dashboards:(Array.isArray(a)?a:[]).filter(t=>Ms(t,e)).length,loading:!1})})(),()=>{n=!0}},[t,e]),n}function Is(e,t){if(typeof e==`string`)return e||`col ${t+1}`;if(e&&typeof e==`object`){let n=e;return String(n.label??n.field??`col ${t+1}`)}return`col ${t+1}`}function Ls(e){if(typeof e==`string`)return e||void 0;if(e&&typeof e==`object`){let t=e.field;return typeof t==`string`&&t?t:void 0}}function Rs(e){let t=new Set;for(let n of e){let e=Ls(n);e&&t.add(e)}return t}function zs(e,t,n){if(e)return t;let r={field:t};return n&&n!==t&&(r.label=n),r}function Bs(e,t){return e===t?null:e>t?e-1:e}function Vs(e,t,n){if(e===t)return n;let r=e;return t<r&&--r,n<=r&&(r+=1),r}function Hs({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}=la(i||void 0,a),m=Y.useMemo(()=>{let e=new Map;for(let t of d)e.set(t.name,t.type);return e},[d]),[h,g]=Y.useState(null),[_,v]=Y.useState(null),y=Y.useCallback(n=>{c({[e]:{...t,columns:n}})},[c,e,t]),b=Y.useCallback(t=>{let i=zs(r,t.name,t.label),a=no(n,i);y(a),l?.({kind:`column`,id:`${e}.columns[${a.length-1}]`,label:t.label})},[r,n,y,e,l]),x=Y.useCallback(t=>{let r=K(n,t,null);if(y(r),o!=null){let n=Bs(o,t);n==null?l?.(null):l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Is(r[n],n)})}},[n,y,o,e,l]),S=Y.useCallback((t,r)=>{if(t===r)return;let i=Ha(n,t,r);if(y(i),o!=null){let n=Vs(o,t,r);l?.({kind:`column`,id:`${e}.columns[${n}]`,label:Is(i[n],n)})}},[n,y,o,e,l]),C=Y.useCallback(t=>{l?.({kind:`column`,id:`${e}.columns[${t}]`,label:Is(n[t],t)})},[n,e,l]),w=Rs(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)(I,{className:`text-xs text-muted-foreground`,children:`Columns`}),(0,X.jsx)(z,{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)($a,{index:t,label:Is(e,t),fieldName:Ls(e),fieldType:m.get(Ls(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)(Xa,{fields:d,usedNames:w,loading:f,error:p,onAdd:b})]})}var Us=[`record`,`current_user`,`user`,`features`,`app`,`data`,`ctx`];function Ws(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(Ws).join(`, `)}]`:JSON.stringify(String(e))}function Gs(e){if(!e.field||!e.operator)return``;let t=`record[${JSON.stringify(e.field)}]`;switch(e.operator){case`equals`:return`${t} == ${Ws(e.value)}`;case`not_equals`:return`${t} != ${Ws(e.value)}`;case`greater_than`:return`${t} > ${Ws(e.value)}`;case`less_than`:return`${t} < ${Ws(e.value)}`;case`contains`:return`${t}.contains(${Ws(e.value)})`;case`in`:return`${t} in ${Ws(Array.isArray(e.value)?e.value:[e.value])}`;default:return``}}function Ks(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:Gs(e)}function qs(e){let t=Ks(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 Js({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 Ys({rules:e,onChange:t,objectName:n,fieldNames:r,disabled:i,t:a,onBlockingIssuesChange:o}){let s=Y.useMemo(()=>Array.isArray(e)?e.map(qs):[],[e]),[c,l]=Y.useState({}),u=Y.useCallback((e,t)=>{let n=t.filter(e=>e.severity===`error`).length;l(t=>t[e]===n?t:{...t,[e]:n})},[]),d=s.length,f=Y.useMemo(()=>{let e=0;for(let[t,n]of Object.entries(c))Number(t)>=d||(e+=n);return e},[c,d]),p=Y.useRef(o);Y.useEffect(()=>{p.current=o}),Y.useEffect(()=>{p.current?.(f)},[f]);let m=e=>t(e),h=(e,t)=>{let n=s.map((n,r)=>r===e?{...n,...t}:n);m(n)},g=(e,t,n)=>{let r={...s[e].style};n?r[t]=n:delete r[t],h(e,{style:r})},_=()=>m([...s,{condition:``,style:{}}]),v=e=>m(s.filter((t,n)=>n!==e)),y=(e,t)=>{let n=e+t;if(n<0||n>=s.length)return;let r=s.slice();[r[e],r[n]]=[r[n],r[e]],m(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)(B,{type:`button`,size:`sm`,variant:`ghost`,className:`h-6 px-2 text-xs`,disabled:i,onClick:_,"data-testid":`cf-add`,children:[(0,X.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),a(`engine.inspector.view.cf.add`)]})]}),s.length===0&&(0,X.jsx)(`p`,{className:`text-[11px] italic text-muted-foreground`,children:a(`engine.inspector.view.cf.empty`)}),s.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)(B,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6`,disabled:i||t===0,onClick:()=>y(t,-1),"aria-label":a(`engine.inspector.view.cf.moveUp`),"data-testid":`cf-up-${t}`,children:(0,X.jsx)(zn,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(B,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6`,disabled:i||t===s.length-1,onClick:()=>y(t,1),"aria-label":a(`engine.inspector.view.cf.moveDown`),"data-testid":`cf-down-${t}`,children:(0,X.jsx)(Jn,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(B,{type:`button`,size:`icon`,variant:`ghost`,className:`h-6 w-6 text-destructive hover:text-destructive`,disabled:i,onClick:()=>v(t),"aria-label":a(`engine.inspector.view.cf.remove`),"data-testid":`cf-remove-${t}`,children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]})]}),(0,X.jsx)(Oa,{label:a(`engine.inspector.view.cf.when`),value:e.condition,disabled:i,placeholder:`record.status == 'overdue'`,objectName:n,fieldNames:r,scope:`flattened`,roots:Us,onChange:e=>h(t,{condition:e}),onLintChange:e=>u(t,e),t:a,id:`cf-condition-${t}`}),(0,X.jsxs)(`div`,{className:V(`grid gap-2 sm:grid-cols-3`),children:[(0,X.jsx)(Js,{label:a(`engine.inspector.view.cf.background`),value:e.style.backgroundColor??``,disabled:i,onChange:e=>g(t,`backgroundColor`,e)}),(0,X.jsx)(Js,{label:a(`engine.inspector.view.cf.text`),value:e.style.color??``,disabled:i,onChange:e=>g(t,`color`,e)}),(0,X.jsx)(Js,{label:a(`engine.inspector.view.cf.border`),value:e.style.borderColor??``,disabled:i,onChange:e=>g(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 Xs={io:`input`,unrepresentable:`any`},Zs=new Set([`columns`,`data`,`name`]),Qs,$s=!1;function ec(){if(Qs||$s)return Qs;try{Qs=Wi(f,Xs)}catch(e){$s=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive View JSONSchema from spec`,e)}return Qs}function tc(){return ec()?.properties?.list}function nc(){return ec()?.properties?.form}var rc,ic=!1;function ac(){if(rc||ic)return rc;try{rc=Wi(v,Xs)}catch(e){ic=!0,typeof console<`u`&&console.warn(`[view-schema] failed to derive ListColumn JSONSchema from spec`,e)}return rc}var oc;function sc(){if(oc)return oc;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!Zs.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),oc=e}catch(e){typeof console<`u`&&console.warn(`[view-schema] failed to prepare viewForm from spec`,e);return}return oc}}var cc=new Set([`form`,`detail`]);function lc(e){return cc.has(e)}function uc(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function dc(e,t){return typeof e==`string`&&cc.has(e)?e:typeof e==`string`&&e?`list`:typeof t==`string`&&cc.has(t)?`form`:`list`}function fc(e){let t=e.config;return uc(t)?[{storeKey:`config`,familyKey:dc(e.viewKind,t.type),schema:t}]:[]}function pc(e){return fc(e)[0]}function mc(e,t){return pc(e)}function hc({label:e,value:t,onCommit:n,placeholder:r,disabled:i}){let{options:a,loading:o}=Ns();return(0,X.jsx)(ws,{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 gc=new Set([`type`,`object`,`label`,`columns`,`conditionalFormatting`]),_c={grid:`Table / List`,kanban:`Kanban`,calendar:`Calendar`,gallery:`Gallery`,gantt:`Gantt`,timeline:`Timeline`,map:`Map`,chart:`Chart`};function vc(e,t){let n=`engine.inspector.view.type.${e}`,r=J(n,t);return r===n?_c[e]??e:r}var yc=[`columns`,`data`,`name`];function bc(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 xc(e,t){return Y.useMemo(()=>{let n=tc()?.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:vc(e,t)}));return!r.some(t=>t.value===e)&&e&&r.push({value:e,label:vc(e,t)}),r},[e,t])}function Sc({draft:e,variantKey:t,familyKey:n,isHome:r,onPatch:i,readOnly:a,onClearSelection:o,onSelectionChange:s,onBlockingIssuesChange:c,objectFieldsOverride:l,locale:u,serverSchema:d}){let f=e[t]??{},p=lc(n??t),m=typeof f.type==`string`?f.type:`grid`,h=xc(m,u),g=bc(f,e),_=typeof e.label==`string`&&e.label||(typeof f.label==`string`?f.label:``)||``,v=Array.isArray(f.columns)?f.columns:[],y=v.length>0&&v.every(e=>typeof e==`string`),{fields:b,loading:x,error:S}=la(g.value||void 0,l),C=Y.useCallback(e=>J(e,u),[u]),w=Y.useMemo(()=>b.map(e=>e.name),[b]),T=Array.isArray(f.conditionalFormatting)?f.conditionalFormatting:[],[E,D]=Y.useState({variant:t,count:0}),O=Y.useCallback(e=>{D(n=>n.variant===t&&n.count===e?n:{variant:t,count:e})},[t]),k=E.variant===t&&!p?E.count:0,A=Y.useRef(c);Y.useEffect(()=>{A.current=c}),Y.useEffect(()=>{A.current?.(k)},[k]);let j=Y.useMemo(()=>{let e;return e=S?Aa(S):x?{status:`loading`}:xa(b.map(e=>({name:e.name,label:e.label,type:e.type}))),{objectFields:e}},[b,x,S]),M=(()=>{let e=d?.properties;return p?e?.form:e?.list})(),{schema:N,form:P}=Y.useMemo(()=>Va({bundledSchema:p?nc():tc(),bundledForm:p?void 0:sc(),serverSchema:M,excludeFields:gc,sectionTitle:J(`engine.inspector.moreFields`,u)}),[p,M,u]),ee=e=>{i({[t]:{...f,...e}})};return(0,X.jsxs)(Ba,{kindLabel:J(`engine.inspector.view.kind`,u),title:String(_||e.name||t),onClose:()=>o?.(),closeLabel:J(`engine.inspector.view.close`,u),hideClose:r,children:[(0,X.jsx)(G,{label:J(`engine.inspector.view.label`,u),value:_,onCommit:e=>{i({label:e,[t]:{...f,label:e}})},placeholder:J(`engine.inspector.view.labelPlaceholder`,u),disabled:a}),(0,X.jsx)(W,{label:J(`engine.inspector.view.type`,u),value:m,options:h,onCommit:e=>ee({type:e}),disabled:a}),(0,X.jsx)(hc,{label:J(`engine.inspector.view.object`,u),value:g.value,onCommit:e=>{let n={object:e};f.data&&typeof f.data==`object`?n[t]={...f,data:{...f.data,object:e}}:g.path===`object`&&(n[t]={...f,object:e}),i(n)},placeholder:J(`engine.inspector.view.objectPlaceholder`,u),disabled:a}),!p&&(0,X.jsx)(`div`,{className:`border-t pt-3`,children:(0,X.jsx)(Hs,{variantKey:t,schema:f,columns:v,allStrings:y,objectName:g.value||void 0,objectFieldsOverride:l,selectedIndex:null,readOnly:a,onPatch:i,onSelectionChange:s})}),!p&&(0,X.jsx)(`div`,{className:`border-t pt-3`,children:(0,X.jsx)(Ys,{rules:T,objectName:g.value||void 0,fieldNames:w,disabled:a,t:C,onChange:e=>ee({conditionalFormatting:e.length>0?e:void 0}),onBlockingIssuesChange:O})}),(0,X.jsx)(`div`,{className:`border-t pt-3`,children:N?(0,X.jsx)(Na,{schema:N,form:P,value:f,hiddenFields:[`type`,`object`,`label`],readOnly:a,widgetContext:j,onChange:e=>{let n={...e};for(let e of yc)e in f?n[e]=f[e]:delete n[e];i({[t]:n})}}):(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:J(`engine.inspector.view.noSchema`,u)})})]})}function Cc(e){let[t]=(0,Y.useState)(()=>{try{let e=new URLSearchParams(window.location.search).get(Ji);return e&&e!==``?e:null}catch{return null}}),n=(0,Y.useRef)(!1),r=t!==null&&!n.current&&e(t);return(0,Y.useEffect)(()=>{if(r){n.current=!0;try{let e=new URL(window.location.href);e.searchParams.delete(Ji),window.history.replaceState(window.history.state,``,e)}catch{}}},[r]),r?t:null}function wc(e,t){return t?`${e}${e.includes(`?`)?`&`:`?`}${Ji}=${encodeURIComponent(t)}`:e}var Tc=19,Ec=[`from-blue-500 to-indigo-600`,`from-violet-500 to-purple-600`,`from-pink-500 to-rose-600`,`from-amber-400 to-orange-500`,`from-emerald-500 to-teal-600`,`from-sky-500 to-cyan-600`,`from-fuchsia-500 to-pink-600`,`from-orange-500 to-red-600`,`from-indigo-500 to-blue-600`,`from-teal-500 to-green-600`],Dc=`shadow-[0_4px_10px_-2px_rgb(0_0_0/0.25),inset_0_1px_0_0_rgb(255_255_255/0.45)]`;function Oc(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return Math.abs(t)}function kc({apps:e,favorites:t,onOpen:n,onBrowseMarketplace:r,isAdmin:i,canAuthorMetadata:a=!0,marketplaceEnabled:o=!0}){let{t:s}=he(),{appLabel:c}=me(),[l,u]=(0,Y.useState)(!1),d=(0,Y.useMemo)(()=>new Set(t.filter(e=>e.id.startsWith(`app:`)).map(e=>e.id.slice(4))),[t]),f=(0,Y.useMemo)(()=>[...e].sort((e,t)=>!!d.has(t.name)-+!!d.has(e.name)),[e,d]),p=f.length-Tc,m=l?f:f.slice(0,Tc);return(0,X.jsxs)(`section`,{className:`mb-6`,children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-center gap-2.5`,children:[(0,X.jsx)(`span`,{className:`inline-flex h-8 w-8 items-center justify-center rounded-xl border border-border bg-muted text-muted-foreground`,children:(0,X.jsx)(Ie,{className:`h-4 w-4`})}),(0,X.jsx)(`h2`,{className:`text-base font-semibold tracking-tight`,children:s(`home.yourApps`,{defaultValue:`Your apps`})}),(0,X.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:f.length}),i&&a&&o&&(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,className:`ml-auto h-8 text-muted-foreground`,onClick:r,"data-testid":`browse-marketplace-btn`,children:[(0,X.jsx)(Ge,{className:`mr-1.5 h-4 w-4`}),s(`home.browseMarketplace`,{defaultValue:`Browse App Marketplace`})]})]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-4 gap-1 sm:grid-cols-6 lg:grid-cols-8 xl:grid-cols-10`,children:[m.map(e=>{let t=Qi(e.icon),r=c({name:e.name,label:Gi(e.label,s)}),i=d.has(e.name),a=Ec[Oc(e.name)%Ec.length];return(0,X.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:`group relative flex flex-col items-center gap-2 rounded-xl p-2.5 text-center transition hover:bg-muted/40 active:scale-[0.96]`,"data-testid":`app-tile-${e.name}`,children:[(0,X.jsxs)(`span`,{className:V(`relative inline-flex h-12 w-12 items-center justify-center rounded-[13px]`,`bg-gradient-to-br text-white transition-transform group-hover:scale-105`,Dc,a),children:[(0,X.jsx)(t,{className:`h-6 w-6`}),i&&(0,X.jsx)(`span`,{className:`absolute -right-1 -top-1 inline-flex h-4 w-4 items-center justify-center rounded-full bg-amber-400 ring-2 ring-background`,children:(0,X.jsx)(Ut,{className:`h-2.5 w-2.5 fill-white text-white`})})]}),(0,X.jsx)(`span`,{className:`w-full truncate text-xs font-medium`,children:r})]},e.name)}),!l&&p>0&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>u(!0),className:`group flex flex-col items-center gap-2 rounded-xl p-2.5 text-center transition hover:bg-muted/40 active:scale-[0.96]`,"data-testid":`apps-show-all`,children:[(0,X.jsxs)(`span`,{className:`inline-flex h-12 w-12 items-center justify-center rounded-[13px] border border-dashed border-border text-sm font-medium text-muted-foreground transition-colors group-hover:border-foreground/30 group-hover:text-foreground`,children:[`+`,p]}),(0,X.jsx)(`span`,{className:`w-full truncate text-xs text-muted-foreground`,children:s(`home.showMoreApps`,{defaultValue:`More`})})]})]}),l&&p>0&&(0,X.jsx)(`button`,{type:`button`,onClick:()=>u(!1),className:`mt-2.5 text-xs text-primary hover:underline`,children:s(`home.showLess`,{defaultValue:`Show less`})})]})}function Ac(e){let t=e.slice(0,20);if(t.length===0)return`{
|
|
3
|
+
"id": "record-1"
|
|
4
|
+
}`;let n={};for(let e of t)n[e]=null;return JSON.stringify(n,null,2)}var jc=JSON.stringify({id:`user-1`,organization_id:`org-1`,positions:[`admin`]},null,2),Mc=[];function Nc({open:e,onOpenChange:t,policyName:n,objectName:r,fieldNames:i=Mc,using:a,check:o,t:s}){let c=Y.useMemo(()=>{let e=[];return a&&a.trim()&&e.push(`using`),o&&o.trim()&&e.push(`check`),e},[a,o]),[l,u]=Y.useState(`using`),[d,f]=Y.useState(`{}`),[p,m]=Y.useState(jc),[h,g]=Y.useState(null),[_,v]=Y.useState(null),[y,b]=Y.useState(!1);Y.useEffect(()=>{e&&(u(c[0]??`using`),f(Ac(i)),m(jc),g(null),v(null))},[e]);let x=l===`using`?a??``:o??``;async function S(){g(null),v(null);let e=Pc(d,s(`perm.cel.test.record`));if(!e.ok)return v(e.error);let t=Pc(p,s(`perm.cel.test.user`));if(!t.ok)return v(t.error);b(!0);try{g(await Da(x,{record:e.value,currentUser:t.value}))}finally{b(!1)}}return(0,X.jsx)(Yr,{open:e,onOpenChange:t,children:(0,X.jsxs)(di,{className:`sm:max-w-2xl`,children:[(0,X.jsxs)(Yt,{children:[(0,X.jsxs)(je,{className:`flex items-center gap-2`,children:[(0,X.jsx)(xr,{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)(An,{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:V(`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)(I,{className:`text-[10px] uppercase text-muted-foreground`,htmlFor:`cel-test-record`,children:s(`perm.cel.test.record`)}),(0,X.jsx)(Gt,{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)(I,{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)(Gt,{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)(Ir,{className:`mt-[1px] h-3.5 w-3.5 shrink-0`}),_]}),h&&(0,X.jsx)(Fc,{outcome:h,t:s})]}),(0,X.jsxs)(oi,{children:[(0,X.jsx)(B,{variant:`ghost`,onClick:()=>t(!1),children:s(`engine.cancel`)}),(0,X.jsxs)(B,{onClick:S,disabled:y||c.length===0,children:[(0,X.jsx)(xr,{className:`h-4 w-4 mr-1`}),s(`perm.cel.test.run`)]})]})]})})}function Pc(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 Fc({outcome:e,t}){return e.status===`allow`?(0,X.jsx)(Lc,{tone:`allow`,icon:(0,X.jsx)(ve,{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)(Lc,{tone:`deny`,icon:(0,X.jsx)(Sn,{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)(Lc,{tone:`warn`,icon:(0,X.jsx)(ci,{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)(Lc,{tone:`warn`,icon:(0,X.jsx)(ci,{className:`h-4 w-4 shrink-0`}),title:t(`perm.cel.test.unavailable`),children:t(`perm.cel.test.unavailableHint`)}):(0,X.jsx)(Lc,{tone:`error`,icon:(0,X.jsx)(Ir,{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 Ic={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 Lc({tone:e,icon:t,title:n,children:r}){return(0,X.jsxs)(`div`,{className:V(`rounded-md border px-3 py-2 text-xs`,Ic[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 Rc=[`priority`];function zc(e){if(!e||typeof e!=`object`)return e;let t=Rc.filter(t=>t in e);if(t.length===0)return e;let n={...e};for(let e of t)delete n[e];return n}var Bc=[`all`,`select`,`insert`,`update`,`delete`],Vc=[`visible`,`hidden`,`default_on`,`default_off`];function Hc(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 Uc(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 Wc=`h-8 rounded-md border border-input bg-background px-2 text-sm disabled:opacity-50`;function Gc({title:e,icon:t,count:n,children:r,defaultOpen:i}){let[a,o]=Y.useState(!!i);return(0,X.jsxs)(ei,{open:a,onOpenChange:o,className:`border-b`,children:[(0,X.jsxs)(Ue,{className:`flex w-full items-center gap-2 px-6 py-2.5 text-left hover:bg-muted/40`,children:[(0,X.jsx)(Cr,{className:V(`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)(z,{variant:`secondary`,className:`text-[10px]`,children:n})]}),(0,X.jsx)(rn,{className:`px-6 pb-4 pt-1`,children:r})]})}function Kc({draft:e,setDraft:t,writable:n,allSetNames:r,loadObjectFields:i,onCelErrorsChange:a,t:o}){let s=Y.useMemo(()=>Hc(e.rowLevelSecurity).map(zc),[e.rowLevelSecurity]),c=Y.useMemo(()=>Uc(e.adminScope),[e.adminScope]),l=Y.useMemo(()=>Uc(e.tabPermissions),[e.tabPermissions]),[u,d]=Y.useState({}),f=Y.useRef(new Set),p=Y.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]=Y.useState({}),_=Y.useCallback((e,t)=>{let n=t.filter(e=>e.severity===`error`).length;g(t=>t[e]===n?t:{...t,[e]:n})},[]),[v,y]=Y.useState(null);Y.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=Y.useMemo(()=>Object.values(h).reduce((e,t)=>e+t,0),[h]),x=Y.useRef(a);Y.useEffect(()=>{x.current=a}),Y.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:{...Uc(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)(Gc,{title:o(`perm.rls.title`),icon:(0,X.jsx)(En,{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:Wc,children:Bc.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)(xn,{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)(B,{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)(xr,{className:`h-3.5 w-3.5 mr-1`}),o(`perm.cel.test.run`)]}),n&&(0,X.jsx)(B,{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)(qt,{className:`h-4 w-4`})})]}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,X.jsx)(Oa,{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)(Oa,{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)(B,{variant:`outline`,size:`sm`,onClick:()=>C([...s,{name:``,object:`*`,operation:`all`,using:``,enabled:!0}]),children:[(0,X.jsx)(L,{className:`h-4 w-4 mr-1`}),` `,o(`perm.rls.add`)]})]})]}),(0,X.jsx)(Nc,{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)(Gc,{title:o(`perm.tabs.title`),icon:(0,X.jsx)(Vt,{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:Wc,children:Vc.map(e=>(0,X.jsx)(`option`,{value:e,children:o(`perm.tabs.vis.${e}`)},e))}),n&&(0,X.jsx)(B,{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)(qt,{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)(B,{variant:`outline`,size:`sm`,onClick:()=>{l[``]===void 0&&T({...l,"":`visible`})},children:[(0,X.jsx)(L,{className:`h-4 w-4 mr-1`}),` `,o(`perm.tabs.add`)]})]})]}),(0,X.jsxs)(Gc,{title:o(`perm.admin.title`),icon:(0,X.jsx)(hn,{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)(I,{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)(xn,{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)(xn,{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)(I,{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:V(`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)})]})]})]})]})]})}var qc=[`name`,`label`,`isDefault`,`objects`,`fields`,`systemPermissions`,`rowLevelSecurity`,`tabPermissions`,`adminScope`];function Jc(e){let t=e.indexOf(`.`);return t===-1?e:e.slice(0,t)}function Yc(e){return e instanceof Set?e:new Set(e)}function Xc(e,t){let n=Yc(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(Jc(t))&&(i[t]=r);return{objects:r,fields:i}}function Zc(e,t,n){let r=Yc(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(Jc(t))||(a[t]=n);for(let[e,n]of Object.entries(t.fields??{}))r.has(Jc(e))&&(a[e]=n);let o={...e};for(let e of qc)e in t&&(o[e]=t[e]);return o.objects=i,o.fields=a,o}function Qc(e){let t=e?.code;return t!=null&&t._packageId!==`sys_metadata`}function $c(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 el(e){return[{key:`allowCreate`,short:`C`,tip:J(`perm.action.create`,e)},{key:`allowRead`,short:`R`,tip:J(`perm.action.read`,e)},{key:`allowEdit`,short:`U`,tip:J(`perm.action.edit`,e)},{key:`allowDelete`,short:`D`,tip:J(`perm.action.delete`,e)},{key:`allowTransfer`,short:`Tr`,tip:J(`perm.action.transfer`,e)},{key:`viewAllRecords`,short:`VA`,tip:J(`perm.action.viewAll`,e)},{key:`modifyAllRecords`,short:`MA`,tip:J(`perm.action.modifyAll`,e)}]}function tl({type:e,name:t,packageId:n,onDraftSaved:r,publishNonce:i,onOpenOwd:a,onDirtyChange:s,readOnly:c=!1,embedded:l=!1}){let u=o(),d=yi(),f=F(),{entries:p}=bi(d),m=p.find(t=>t.type===e),[h,g]=Y.useState(!1),_=!n&&h,v=(_?!!m?.allowOrgOverride:!!(m?.allowOrgOverride||m?.allowRuntimeCreate))&&!c,y=_&&!m?.allowOrgOverride&&!!m?.allowRuntimeCreate,b=oo(),x=Y.useCallback(e=>J(e,b),[b]),S=Y.useMemo(()=>el(b),[b]),[C,T]=Y.useState({name:t,objects:{},fields:{}}),E=Y.useRef(null),D=Y.useCallback(e=>{try{E.current=JSON.stringify(e)}catch{E.current=null}T(e)},[]),[O,k]=Y.useState([]),[A,j]=Y.useState({}),[M,N]=Y.useState(new Set),[P,ee]=Y.useState(!0),[te,ne]=Y.useState(!1),[re,ie]=Y.useState(null),[ae,oe]=Y.useState(null),[se,ce]=Y.useState(``),[le,ue]=Y.useState(!1),[de,fe]=Y.useState(!1),[pe,me]=Y.useState(!1),[he,ge]=Y.useState(!1),[_e,ve]=Y.useState([]);Y.useEffect(()=>{let e=!1;return d.list(`permission`,{}).then(t=>{e||ve((t||[]).map(e=>e?.name).filter(e=>!!e))}).catch(()=>{}),()=>{e=!0}},[d]),Y.useEffect(()=>{let r=!1;return ee(!0),g(!1),(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;g(Qc(i));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));k(c);let l={...s,name:String(s?.name??t),objects:s?.objects??{},fields:s?.fields??{}};if(n){let e=Xc(l,c.map(e=>e.name));D({...l,objects:e.objects,fields:e.fields})}else D(l)}catch(e){ie(e?.message??String(e))}finally{r||ee(!1)}})(),()=>{r=!0}},[d,e,t,n,i,D]);async function ye(e){if(!A[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));j(t=>({...t,[e]:n}))}catch{j(t=>({...t,[e]:[]}))}}let be=Y.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]),[xe,Se]=Y.useState(0),Ce=Y.useMemo(()=>{let e=E.current;if(e==null)return!1;try{return JSON.stringify(C)!==e}catch{return!1}},[C]),we=Y.useRef(s);Y.useEffect(()=>{we.current=s}),Y.useEffect(()=>{we.current?.(Ce)},[Ce]),Y.useEffect(()=>()=>{we.current?.(!1)},[]),Y.useEffect(()=>{if(!Ce)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[Ce]);function Te(e){N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),ye(e)),n})}function Ee(e,t,n){T(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 De(e,t){T(n=>{if(t===`none`)return{...n,objects:{...n.objects,[e]:{}}};let r={...n.objects[e]??{}};for(let e of S)delete r[e.key];let i=t===`all`?S.map(e=>e.key):t===`crud`?[`allowCreate`,`allowRead`,`allowEdit`,`allowDelete`]:[`allowRead`];for(let e of i)r[e]=!0;return{...n,objects:{...n.objects,[e]:r}}})}function Oe(e,t,n,r){let i=`${e}.${t}`;T(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 ke(e,t,n){n.length!==0&&T(r=>{let i={...r.fields??{}};for(let r of n){let n=`${e}.${r}`;t===`clear`?delete i[n]:i[n]=t===`readable`?{readable:!0,editable:!1}:{readable:!0,editable:!0}}return{...r,fields:i}})}function Ae(e){if(!n)return e;let t=Xc(e,O.map(e=>e.name));return{...e,objects:t.objects,fields:t.fields}}async function Me(t,i){let a=i??C;ne(!0),ie(null);try{let i=a;if(n){let t=O.map(e=>e.name);i=Zc((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)D(Ae(i)),r?.();else{let t=await d.layered(e,a.name);D(Ae(t.effective??i))}oe(null)}catch(e){if(e?.status===409&&w(e,`DESTRUCTIVE_CHANGE`)){let t=e?.body?.issues??[];oe({issues:Array.isArray(t)?t:[],pending:a})}else ie(e?.message??String(e))}finally{ne(!1)}}let L=Y.useMemo(()=>{let e=se.trim().toLowerCase();return O.filter(t=>{if(le){let e=C.objects[t.name];if(!e||!Object.values(e).some(Boolean))return!1}return!e||t.name.toLowerCase().includes(e)||(t.label??``).toLowerCase().includes(e)})},[O,se,le,C.objects]),Pe=[{label:x(`perm.stat.objectsGranted`),value:Object.values(C.objects).filter(e=>Object.values(e).some(Boolean)).length},{label:x(`perm.stat.fieldOverrides`),value:Object.keys(C.fields??{}).length}];return P?(0,X.jsx)(vo,{entry:m,itemName:t,embedded:l,readOnly:c,children:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(H,{className:`h-4 w-4 animate-spin`}),` `,x(`perm.loading`).replace(`{name}`,t)]})}):(0,X.jsxs)(vo,{entry:m??{type:e,label:e},itemName:t,subtitle:x(`perm.subtitle.set`),stats:Pe,embedded:l,readOnly:c,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,onClick:()=>l?ge(!0):u(`./history?type=${encodeURIComponent(e)}`),children:[(0,X.jsx)(Sr,{className:`h-4 w-4 mr-1`}),` `,x(`engine.edit.history`)]}),v&&(0,X.jsxs)(B,{size:`sm`,onClick:()=>Me(!1),disabled:te||xe>0,title:xe>0?x(`perm.cel.saveBlocked`):void 0,children:[te?(0,X.jsx)(H,{className:`h-4 w-4 mr-1 animate-spin`}):(0,X.jsx)(Fr,{className:`h-4 w-4 mr-1`}),x(`engine.edit.save`)]})]}),children:[(0,X.jsxs)(`div`,{className:`flex flex-col h-full overflow-hidden`,children:[re&&(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)(ci,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,X.jsx)(`span`,{children:re})]}),(0,X.jsxs)(`div`,{className:`border-b bg-muted/30`,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>fe(e=>!e),"aria-expanded":de,className:`w-full px-6 py-2.5 flex items-center gap-2 text-left hover:bg-muted/50 transition-colors`,children:[de?(0,X.jsx)(Jn,{className:`h-4 w-4 shrink-0 text-muted-foreground`}):(0,X.jsx)(Cr,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-medium truncate`,children:C.label||C.name}),(0,X.jsx)(z,{variant:`outline`,className:`text-[10px] shrink-0`,children:C.managedBy===`platform`?x(`perm.badge.platform`):C.managedBy===`package`||n?x(`perm.badge.package`):x(`perm.badge.custom`)}),!!C.isDefault&&(0,X.jsx)(z,{variant:`secondary`,className:`text-[10px] shrink-0`,children:x(`perm.badge.default`)}),v&&(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground shrink-0`,children:x(`perm.basics.editHint`)}),!v&&(0,X.jsx)(z,{variant:`secondary`,className:`ml-auto shrink-0`,title:x(c?`engine.studio.pkg.readonlyHint`:y?`perm.readOnly.artifact.hint`:`perm.readOnly.hint`),children:x(c?`engine.studio.pkg.readonly`:y?`perm.readOnly.artifact`:`perm.readOnly`)})]}),de&&(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)(I,{htmlFor:`perm-name`,className:`text-xs`,children:x(`perm.field.name`)}),(0,X.jsx)(R,{id:`perm-name`,value:C.name,disabled:!v,onChange:e=>T(t=>({...t,name:e.target.value})),className:`h-8 w-56`})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{htmlFor:`perm-label`,className:`text-xs`,children:x(`perm.field.label`)}),(0,X.jsx)(R,{id:`perm-label`,value:C.label??``,disabled:!v,onChange:e=>T(t=>({...t,label:e.target.value})),className:`h-8 w-72`})]})]})]}),v&&(C.systemPermissions??[]).length===0&&!pe?(0,X.jsxs)(`div`,{className:`px-6 py-2.5 border-b flex items-center gap-2 text-xs`,children:[(0,X.jsx)(I,{className:`text-xs text-muted-foreground`,children:x(`perm.field.systemCapabilities`)}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:`·`}),(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:x(`perm.cap.none`)}),(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,className:`h-6 px-2 text-xs`,onClick:()=>me(!0),children:[`+ `,x(`perm.cap.add`)]})]}):(0,X.jsxs)(`div`,{className:`px-6 py-3 border-b`,children:[(0,X.jsx)(I,{className:`text-xs`,children:x(`perm.field.systemCapabilities`)}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5 mb-2`,children:x(`perm.field.systemCapabilitiesHelp`)}),(0,X.jsx)(`div`,{"data-testid":`capability-scroll`,className:`max-h-[30vh] overflow-y-auto overscroll-contain`,children:(0,X.jsx)(ze,{value:JSON.stringify(C.systemPermissions??[]),onChange:e=>T(t=>({...t,systemPermissions:Ne(e)})),field:{name:`system_permissions`},dataSource:f,readonly:!v})})]}),(0,X.jsxs)(`div`,{className:`px-6 py-3 border-b flex items-center gap-3`,children:[(0,X.jsx)(R,{placeholder:x(`perm.filter.placeholder`),value:se,onChange:e=>ce(e.target.value),className:`h-8 w-72`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(xn,{id:`only-enabled`,checked:le,onCheckedChange:e=>ue(!!e)}),(0,X.jsx)(I,{htmlFor:`only-enabled`,className:`text-xs`,children:x(`perm.filter.onlyGranted`)})]}),(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground ml-auto`,children:[L.length,` / `,O.length,` `,x(`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:S.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)(nl,{objects:L,draft:C,expanded:M,fieldsByObject:A,writable:v,objectActions:S,t:x,onToggleExpand:Te,onObjectPerm:Ee,onFieldPerm:Oe,onBulkSet:De,onFieldBulk:ke,onOpenOwd:a}),(0,X.jsx)(Kc,{draft:C,setDraft:T,writable:v,allSetNames:_e,loadObjectFields:be,onCelErrorsChange:Se,t:x})]})]}),(0,X.jsx)(Yr,{open:!!ae,onOpenChange:e=>!e&&oe(null),children:(0,X.jsxs)(di,{children:[(0,X.jsxs)(Yt,{children:[(0,X.jsxs)(je,{className:`flex items-center gap-2`,children:[(0,X.jsx)(ci,{className:`h-4 w-4 text-amber-500`}),` `,x(`engine.edit.destructive`)]}),(0,X.jsx)(An,{children:x(`engine.edit.destructiveHint`)})]}),(0,X.jsx)(`ul`,{className:`text-sm space-y-1 max-h-64 overflow-auto`,children:ae?.issues.map((e,t)=>(0,X.jsxs)(`li`,{className:`border-l-2 border-amber-500 pl-2`,children:[e.kind&&(0,X.jsx)(z,{variant:`outline`,className:`mr-2`,children:e.kind}),e.message??JSON.stringify(e)]},t))}),(0,X.jsxs)(oi,{children:[(0,X.jsx)(B,{variant:`ghost`,onClick:()=>oe(null),children:x(`engine.cancel`)}),(0,X.jsxs)(B,{variant:`destructive`,onClick:()=>ae&&Me(!0,ae.pending),disabled:te,children:[te&&(0,X.jsx)(H,{className:`h-4 w-4 mr-1 animate-spin`}),x(`engine.edit.forceSave`)]})]})]})}),l&&(0,X.jsx)(Jr,{open:he,onOpenChange:ge,children:(0,X.jsxs)(li,{side:`right`,className:`w-[92vw] sm:max-w-[720px] p-0 flex flex-col gap-0`,children:[(0,X.jsxs)(ai,{className:`px-4 py-3 border-b`,children:[(0,X.jsx)(Jt,{className:`text-base`,children:x(`engine.edit.history`)}),(0,X.jsxs)(kn,{className:`text-xs`,children:[e,` / `,t]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0 overflow-auto p-4`,children:he&&(0,X.jsx)(yo,{type:e,name:t,client:d})})]})})]})}function nl({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)(Y.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)(Jn,{className:`h-3.5 w-3.5`}):(0,X.jsx)(Cr,{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)(z,{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)(z,{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?$c(o,e.owd):o(`perm.owd.defaultPrivate`)}`}),e.owdExternal&&(0,X.jsx)(z,{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 ${$c(o,e.owdExternal)}`})]}),a.map(t=>(0,X.jsx)(`td`,{className:`text-center px-2 py-1.5`,children:(0,X.jsx)(Le,{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)(B,{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)(B,{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)(B,{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)(B,{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)(rl,{objectName:e.name,fields:r[e.name],fieldsState:t.fields??{},writable:i,t:o,onFieldPerm:l,onFieldBulk:d})})})]},e.name)})]})]})}function rl({objectName:e,fields:t,fieldsState:n,writable:r,t:i,onFieldPerm:a,onFieldBulk:o}){let[s,c]=Y.useState(``);if(!t)return(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(H,{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)(B,{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)(B,{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)(B,{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)(Le,{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)(Le,{checked:!!i.editable,disabled:!r,onCheckedChange:n=>a(e,t.name,`editable`,!!n),"aria-label":`${e}.${t.name} editable`})})]},t.name)})})]})]})}function il(){return`${``.replace(/\/$/,``)}/api/v1`}function al(e){let t=e,n=t?._packageId;return typeof n!=`string`||!n||n===`sys_metadata`?!1:t?._provenance!==`org`}function ol(e,t){let n=new Map;for(let e of t){let t=e,r=t?.name;typeof r!=`string`||!r||al(t)&&n.set(r,t)}let r=[];for(let t of e){let e=t?.name;if(typeof e!=`string`||!e)continue;let i=n.get(e);if(!i)continue;let a=i.label;r.push({name:e,label:typeof a==`string`&&a?a:e,enabled:t.enabled!==!1})}return r.sort((e,t)=>e.label.localeCompare(t.label)||e.name.localeCompare(t.name))}function sl(e){let t=e?.data;return!t||typeof t!=`object`||Array.isArray(t)?{}:t}function cl(e){return e?.success===!1}function ll(e){let t=e,n=t?.data?.flows??t?.flows??[];return Array.isArray(n)?n:[]}function ul(e){if(Array.isArray(e))return e;let t=e?.items;return Array.isArray(t)?t:[]}var dl=`global`;function fl(e){let t=e,n=t?.data?.records??t?.records??[];return Array.isArray(n)?n:[]}function pl(e){let t=e;return(t?.data?.hasMore??t?.hasMore)===!0}function ml(e){let t=new Map;for(let n of e){if(n?.metadata_type!==`action`||n?.organization_id!=null)continue;let e=n?.name;if(typeof e!=`string`||!e)continue;let r=n?.active;t.set(e,r!==!1&&r!==0)}return t}function hl(e){let t=e;return typeof t?.objectName==`string`&&t.objectName.length>0?t.objectName:typeof t?.object==`string`&&t.object.length>0?t.object:dl}function gl(e,t){let n=e;return typeof n?._packageId==`string`||typeof n?._provenance==`string`?e:t}function _l(e,t,n){let r=[],i=new Set,a=(e,t,a)=>{let o=e,s=o?.name;if(typeof s!=`string`||!s)return;let c=`${t}:${s}`;if(i.has(c)||(i.add(c),!al(gl(e,a))))return;let l=o?.label;r.push({name:s,objectName:t,label:typeof l==`string`&&l?l:s,enabled:n.get(s)??!0})},o=new Map;for(let t of e){let e=t;typeof e?.name==`string`&&e.name&&o.set(e.name,t)}for(let t of e){let e=t,n=e?.name;if(!(typeof n!=`string`||!n))for(let r of Array.isArray(e?.actions)?e.actions:[])a(r,n,t)}for(let e of t){let t=hl(e);a(e,t,o.get(t))}return r.sort((e,t)=>e.label.localeCompare(t.label)||e.objectName.localeCompare(t.objectName)||e.name.localeCompare(t.name))}var vl={Accept:`application/json`},yl=1e3;async function bl(e){return e.json().catch(()=>null)}async function xl(e,t){return fetch(`${il()}${e}`,{credentials:`include`,headers:vl,cache:`no-store`,signal:t})}async function Sl(e){let t=await xl(`/meta/object`,e);if(!t.ok)throw Error(`object metadata HTTP ${t.status}`);return ul(await bl(t))}async function Cl(e){try{let t=await xl(`/meta/action`,e);return t.ok?ul(await bl(t)):[]}catch(e){if(e?.name===`AbortError`)throw e;return[]}}async function wl(e){let t=await xl(`/data/sys_metadata_activation?top=${yl}`,e);if(!t.ok)throw Error(`activation ledger HTTP ${t.status}`);let n=await bl(t);if(pl(n))throw Error(`activation ledger returned more than ${yl} rows; refusing to show a partial ledger because a missing row reads as "active"`);return ml(fl(n))}function Tl(e){return`${e.objectName}:${e.name}`}function El({nonce:e=0}){let{t}=he(),[n,r]=Y.useState(null),[i,a]=Y.useState(null),[o,s]=Y.useState(null),[c,l]=Y.useState({});Y.useEffect(()=>{let e=new AbortController,n=!1;return a(null),(async()=>{try{let[t,i,a]=await Promise.all([Sl(e.signal),Cl(e.signal),wl(e.signal)]);if(n)return;r(_l(t,i,a))}catch(i){if(n||e.signal.aborted)return;r([]),a(i instanceof Error&&i.message?i.message:t(`packagedAutomation.actionsLoadFailed`,{defaultValue:`Could not load packaged actions.`}))}})(),()=>{n=!0,e.abort()}},[e,t]);let u=Y.useCallback(e=>{l(t=>{if(!(e in t))return t;let n={...t};return delete n[e],n})},[]);async function d(e,n){let i=Tl(e);s(i),u(i);try{let a=await fetch(`${il()}/actions/_activation/${encodeURIComponent(e.objectName)}/${encodeURIComponent(e.name)}`,{method:`POST`,credentials:`include`,headers:{...vl,"Content-Type":`application/json`},body:JSON.stringify({enabled:n})}),o=await bl(a);if(!a.ok||cl(o)){l(e=>({...e,[i]:O(o,t(`packagedAutomation.toggleFailedHttp`,{defaultValue:`Could not change activation (HTTP {{status}}).`,status:a.status}))}));return}let s=sl(o).enabled,c=typeof s==`boolean`?s:n;r(e=>e?.map(e=>Tl(e)===i?{...e,enabled:c}:e)??e)}catch(e){l(n=>({...n,[i]:e instanceof Error&&e.message?e.message:t(`packagedAutomation.toggleFailed`,{defaultValue:`Could not change activation.`})}))}finally{s(null)}}return(0,X.jsxs)(`section`,{className:`space-y-3`,"data-testid":`packaged-actions-section`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`h2`,{className:`text-base font-semibold`,children:t(`packagedAutomation.actionsHeading`,{defaultValue:`Packaged actions`})}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-2xl`,children:t(`packagedAutomation.actionsSubtitle`,{defaultValue:`Actions shipped by installed packages. Turn one off for this deployment and it stops running everywhere it is offered. Authoring your own action alongside it stays open in Studio.`})})]}),i&&(0,X.jsx)(`div`,{role:`alert`,className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm`,children:i}),n===null&&(0,X.jsxs)(`div`,{className:`space-y-2`,"data-testid":`packaged-actions-loading`,children:[(0,X.jsx)(Wn,{className:`h-10 w-full`}),(0,X.jsx)(Wn,{className:`h-10 w-full`})]}),n!==null&&n.length===0&&!i&&(0,X.jsxs)(hr,{children:[(0,X.jsx)(Zr,{children:t(`packagedAutomation.actionsEmptyTitle`,{defaultValue:`No packaged actions`})}),(0,X.jsx)(Xn,{children:t(`packagedAutomation.actionsEmptyBody`,{defaultValue:`No installed package declares an action on this deployment. Actions you author yourself live in Studio.`})})]}),n!==null&&n.length>0&&(0,X.jsxs)(cn,{children:[(0,X.jsx)(Or,{children:(0,X.jsxs)(ut,{children:[(0,X.jsx)(ht,{children:t(`packagedAutomation.colAction`,{defaultValue:`Action`})}),(0,X.jsx)(ht,{className:`w-[200px]`,children:t(`packagedAutomation.colObject`,{defaultValue:`Object`})}),(0,X.jsx)(ht,{className:`w-[220px]`,children:t(`packagedAutomation.colActivation`,{defaultValue:`Activation`})})]})}),(0,X.jsx)(fn,{children:n.map(e=>{let n=Tl(e),r=c[n];return(0,X.jsxs)(ut,{"data-testid":`packaged-action-${e.objectName}-${e.name}`,children:[(0,X.jsxs)(Xe,{className:`align-top`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:e.label}),(0,X.jsx)(`code`,{className:`font-mono text-xs text-muted-foreground`,children:e.name}),r&&(0,X.jsx)(`p`,{role:`alert`,className:`mt-2 text-sm text-destructive`,children:r})]}),(0,X.jsx)(Xe,{className:`align-top`,children:(0,X.jsx)(`code`,{className:`font-mono text-xs text-muted-foreground`,children:e.objectName})}),(0,X.jsx)(Xe,{className:`align-top`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(xn,{checked:e.enabled,disabled:o===n,onCheckedChange:t=>void d(e,t),"aria-label":t(`packagedAutomation.actionToggleLabel`,{defaultValue:`Activation for {{label}} on {{object}}`,label:e.label,object:e.objectName})}),(0,X.jsx)(z,{variant:e.enabled?`default`:`secondary`,children:e.enabled?t(`packagedAutomation.on`,{defaultValue:`On`}):t(`packagedAutomation.off`,{defaultValue:`Off`})})]})})]},n)})})]})]})}var Dl={Accept:`application/json`};async function Ol(e){return e.json().catch(()=>null)}async function kl(e){let t=await fetch(`${il()}/automation/_status`,{credentials:`include`,headers:Dl,cache:`no-store`,signal:e});if(!t.ok)throw Error(`automation status HTTP ${t.status}`);return ll(await Ol(t))}async function Al(e){let t=await fetch(`${il()}/meta/flow`,{credentials:`include`,headers:Dl,cache:`no-store`,signal:e});if(!t.ok)throw Error(`flow metadata HTTP ${t.status}`);return ul(await Ol(t))}function jl(){let{t:e}=he(),[t,n]=Y.useState(null),[r,i]=Y.useState(null),[a,o]=Y.useState(0),[s,c]=Y.useState(null),[l,u]=Y.useState({}),[d,f]=Y.useState(null),[p,m]=Y.useState(null);Y.useEffect(()=>{let t=new AbortController,r=!1;return i(null),(async()=>{try{let[e,i]=await Promise.all([kl(t.signal),Al(t.signal)]);if(r)return;n(ol(e,i))}catch(a){if(r||t.signal.aborted)return;n([]),i(a instanceof Error&&a.message?a.message:e(`packagedAutomation.loadFailed`,{defaultValue:`Could not load packaged automation.`}))}})(),()=>{r=!0,t.abort()}},[a,e]);let h=Y.useCallback(e=>{u(t=>{if(!(e in t))return t;let n={...t};return delete n[e],n})},[]);async function g(t,r){c(t.name),h(t.name),m(null);try{let i=await fetch(`${il()}/automation/${encodeURIComponent(t.name)}/toggle`,{method:`POST`,credentials:`include`,headers:{...Dl,"Content-Type":`application/json`},body:JSON.stringify({enabled:r})}),a=await Ol(i);if(!i.ok||cl(a)){u(n=>({...n,[t.name]:O(a,e(`packagedAutomation.toggleFailedHttp`,{defaultValue:`Could not change activation (HTTP {{status}}).`,status:i.status}))}));return}let o=sl(a).enabled,s=typeof o==`boolean`?o:r;n(e=>e?.map(e=>e.name===t.name?{...e,enabled:s}:e)??e)}catch(n){u(r=>({...r,[t.name]:n instanceof Error&&n.message?n.message:e(`packagedAutomation.toggleFailed`,{defaultValue:`Could not change activation.`})}))}finally{c(null)}}async function _(t){f({...t,busy:!0,refusal:null});try{let n=await fetch(`${il()}/automation/${encodeURIComponent(t.source)}/clone`,{method:`POST`,credentials:`include`,headers:{...Dl,"Content-Type":`application/json`},body:JSON.stringify({name:t.name.trim(),label:t.label.trim()})}),r=await Ol(n);if(!n.ok||cl(r)){f({...t,busy:!1,refusal:O(r,e(`packagedAutomation.cloneFailedHttp`,{defaultValue:`Could not clone this flow (HTTP {{status}}).`,status:n.status}))});return}let i=sl(r),a=i.flow?.name,s=i.notice;f(null),m({name:typeof a==`string`&&a?a:t.name.trim(),notice:typeof s==`string`?s:``}),o(e=>e+1)}catch(n){f({...t,busy:!1,refusal:n instanceof Error&&n.message?n.message:e(`packagedAutomation.cloneFailed`,{defaultValue:`Could not clone this flow.`})})}}let v=e(`packagedAutomation.title`,{defaultValue:`Packaged automation`}),y=!!d&&d.name.trim()!==``&&d.label.trim()!==``;return(0,X.jsxs)(`div`,{className:`p-6 space-y-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold`,children:v}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground max-w-2xl`,children:e(`packagedAutomation.subtitle`,{defaultValue:`Flows and actions shipped by installed packages. Turn one off for this deployment, or clone a flow under a new name to customize it. Editing happens in Studio.`})})]}),(0,X.jsx)(B,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>o(e=>e+1),"aria-label":e(`packagedAutomation.refresh`,{defaultValue:`Refresh`}),children:(0,X.jsx)(Gr,{className:`h-4 w-4`})})]}),(0,X.jsx)(`h2`,{className:`text-base font-semibold`,children:e(`packagedAutomation.flowsHeading`,{defaultValue:`Packaged flows`})}),p&&(0,X.jsxs)(`div`,{role:`status`,className:`rounded-md border border-border bg-muted/40 p-3 text-sm space-y-1`,children:[(0,X.jsx)(`p`,{className:`font-medium`,children:e(`packagedAutomation.cloneCreated`,{defaultValue:`Created flow "{{name}}".`,name:p.name})}),p.notice&&(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:p.notice})]}),r&&(0,X.jsx)(`div`,{role:`alert`,className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm`,children:r}),t===null&&(0,X.jsxs)(`div`,{className:`space-y-2`,"data-testid":`packaged-automation-loading`,children:[(0,X.jsx)(Wn,{className:`h-10 w-full`}),(0,X.jsx)(Wn,{className:`h-10 w-full`}),(0,X.jsx)(Wn,{className:`h-10 w-full`})]}),t!==null&&t.length===0&&!r&&(0,X.jsxs)(hr,{children:[(0,X.jsx)(Zr,{children:e(`packagedAutomation.emptyTitle`,{defaultValue:`No packaged flows`})}),(0,X.jsx)(Xn,{children:e(`packagedAutomation.emptyBody`,{defaultValue:`No installed package ships an automation flow on this deployment. Flows you author yourself live in Studio.`})})]}),t!==null&&t.length>0&&(0,X.jsxs)(cn,{children:[(0,X.jsx)(Or,{children:(0,X.jsxs)(ut,{children:[(0,X.jsx)(ht,{children:e(`packagedAutomation.colFlow`,{defaultValue:`Flow`})}),(0,X.jsx)(ht,{className:`w-[220px]`,children:e(`packagedAutomation.colActivation`,{defaultValue:`Activation`})}),(0,X.jsx)(ht,{className:`w-[140px] text-right`,children:e(`packagedAutomation.colActions`,{defaultValue:`Actions`})})]})}),(0,X.jsx)(fn,{children:t.map(t=>{let n=l[t.name];return(0,X.jsxs)(ut,{"data-testid":`packaged-flow-${t.name}`,children:[(0,X.jsxs)(Xe,{className:`align-top`,children:[(0,X.jsx)(`div`,{className:`font-medium`,children:t.label}),(0,X.jsx)(`code`,{className:`font-mono text-xs text-muted-foreground`,children:t.name}),n&&(0,X.jsx)(`p`,{role:`alert`,className:`mt-2 text-sm text-destructive`,children:n})]}),(0,X.jsx)(Xe,{className:`align-top`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(xn,{checked:t.enabled,disabled:s===t.name,onCheckedChange:e=>void g(t,e),"aria-label":e(`packagedAutomation.toggleLabel`,{defaultValue:`Activation for {{label}}`,label:t.label})}),(0,X.jsx)(z,{variant:t.enabled?`default`:`secondary`,children:t.enabled?e(`packagedAutomation.on`,{defaultValue:`On`}):e(`packagedAutomation.off`,{defaultValue:`Off`})})]})}),(0,X.jsx)(Xe,{className:`align-top text-right`,children:(0,X.jsx)(B,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>f({source:t.name,name:``,label:``,refusal:null,busy:!1}),children:e(`packagedAutomation.clone`,{defaultValue:`Clone`})})})]},t.name)})})]}),(0,X.jsx)(El,{nonce:a}),(0,X.jsx)(Yr,{open:!!d,onOpenChange:e=>!e&&f(null),children:(0,X.jsxs)(di,{children:[(0,X.jsxs)(Yt,{children:[(0,X.jsx)(je,{children:e(`packagedAutomation.cloneTitle`,{defaultValue:`Clone packaged flow`})}),(0,X.jsx)(An,{children:e(`packagedAutomation.cloneBody`,{defaultValue:`The copy carries the whole definition and takes a new machine name and label. Edit the copy in Studio.`})})]}),d&&(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{htmlFor:`packaged-clone-name`,children:e(`packagedAutomation.cloneName`,{defaultValue:`New machine name`})}),(0,X.jsx)(R,{id:`packaged-clone-name`,value:d.name,onChange:e=>f({...d,name:e.target.value,refusal:null})})]}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{htmlFor:`packaged-clone-label`,children:e(`packagedAutomation.cloneLabel`,{defaultValue:`New label`})}),(0,X.jsx)(R,{id:`packaged-clone-label`,value:d.label,onChange:e=>f({...d,label:e.target.value,refusal:null})})]}),d.refusal&&(0,X.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:d.refusal})]}),(0,X.jsxs)(oi,{children:[(0,X.jsx)(B,{type:`button`,variant:`ghost`,onClick:()=>f(null),children:e(`packagedAutomation.cancel`,{defaultValue:`Cancel`})}),(0,X.jsx)(B,{type:`button`,disabled:!y||!!d?.busy,onClick:()=>d&&void _(d),children:e(`packagedAutomation.cloneConfirm`,{defaultValue:`Create clone`})})]})]})})]})}function Ml(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Nl(e){if(!Ml(e))return;let t=e.config;if(Ml(t)&&typeof t.type==`string`)return t.type;if(typeof e.type==`string`)return e.type;if(e.viewKind===`form`)return`form`;if(e.viewKind===`list`)return`list`}var Pl=(0,Y.lazy)(()=>t(()=>import(`./metadata-admin-Bo-vWW2Z.js`).then(e=>({default:e.MetadataDirectoryPage})),__vite__mapDeps([0]),import.meta.url)),Fl=(0,Y.lazy)(()=>t(()=>import(`./metadata-admin-Bo-vWW2Z.js`).then(e=>({default:e.MetadataResourceRouter})),__vite__mapDeps([0]),import.meta.url));function Il({label:e}){return(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}lo({ref:`metadata:directory`,label:`All Metadata Types`,source:`@object-ui/app-shell`,component:e=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(Il,{label:`metadata types`}),children:(0,X.jsx)(Pl,{...e})})}),lo({ref:`metadata:resource`,label:`Metadata Resource`,source:`@object-ui/app-shell`,component:e=>(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(Il,{label:`metadata resource`}),children:(0,X.jsx)(Fl,{...e})})}),lo({ref:`developer:packages`,label:`Packages`,source:`@object-ui/app-shell`,component:mo}),lo({ref:`automation:packaged`,label:`Packaged Automation`,source:`@object-ui/app-shell`,component:jl}),fo({type:`object`,label:`Objects`,description:`Domain entities — tables in the data model. Each object owns its fields, relationships, validations, and lifecycle hooks.`,domain:`data`,searchableFields:[`name`,`label`,`description`],listColumns:[{key:`name`,label:`Name`,width:`25%`},{key:`label`,label:`Label`,width:`25%`},{key:`description`,label:`Description`}]}),fo({type:`field`,label:`Fields`,description:`Columns attached to objects — name, type, validation, and storage settings.`,domain:`data`,searchableFields:[`name`,`label`,`object`,`type`],listColumns:[{key:`name`,label:`Name`,width:`25%`},{key:`object`,label:`Object`,width:`20%`},{key:`type`,label:`Type`,width:`15%`},{key:`label`,label:`Label`}]}),fo({type:`permission`,label:`Permission sets`,description:`Object-level CRUD + VAMA + lifecycle permissions, and field-level R/W. The only capability container (ADR-0090); distributed to users via positions.`,domain:`security`,EditPage:tl,searchableFields:[`name`,`label`],listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`managedBy`,label:`Source`,width:`15%`,render:e=>e===`package`?`Package`:`Custom`}]}),fo({type:`view`,label:`Views`,description:`Saved list / kanban / calendar / gantt configurations on top of an object.`,domain:`ui`,listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`object`,label:`Object`,width:`20%`},{key:`type`,label:`Type`,width:`15%`,render:(e,t)=>Nl(t)??`—`},{key:`label`,label:`Label`}],listFilter:e=>!x(e)}),fo({type:`dashboard`,label:`Dashboards`,description:`Composed dashboards with charts, KPIs, and tables.`,domain:`ui`,listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`description`,label:`Description`}]}),fo({type:`page`,label:`Pages`,description:`Visual page layouts authored as JSON metadata.`,domain:`ui`,listColumns:[{key:`name`,label:`Name`,width:`30%`},{key:`label`,label:`Label`,width:`30%`},{key:`route`,label:`Route`}]}),fo({type:`book`,label:`Documentation Books`,description:`Documentation navigation spine — ordered groups with membership derived over docs (glob/tag rules), plus an explicit pages override for curated order.`,domain:`system`,searchableFields:[`name`,`label`,`description`,`slug`],listColumns:[{key:`name`,label:`Name`,width:`25%`},{key:`label`,label:`Label`,width:`25%`},{key:`audience`,label:`Audience`,width:`12%`,render:e=>e==null?`org`:typeof e==`object`&&e&&`permissionSet`in e?`permission set: ${e.permissionSet}`:String(e)},{key:`groups`,label:`Groups`,width:`10%`,render:e=>Array.isArray(e)?String(e.length):`0`},{key:`description`,label:`Description`}]});var Ll=`/api/v1/cloud-connection`;function Rl(e,t,n){for(let r of[t,n]){if(r===`expired_token`)return e(`cloudConnection.errors.expired`);if(r===`access_denied`)return e(`cloudConnection.errors.accessDenied`)}return null}async function zl(e,t){let n=await fetch(e,{credentials:`same-origin`,headers:{"Content-Type":`application/json`},...t}),r=await n.json().catch(()=>({}));if(!n.ok&&r?.success!==!0){let e=r?.error?.message??r?.error?.code??r?.error??`HTTP ${n.status}`;throw Object.assign(Error(typeof e==`string`?e:JSON.stringify(e)),{declaredCode:typeof r?.error?.declaredCode==`string`?r.error.declaredCode:void 0,code:typeof r?.error?.code==`string`?r.error.code:void 0})}return r}function Bl(){let{t:e,language:t}=he(),[n,r]=(0,Y.useState)({kind:`loading`}),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(!1),c=(0,Y.useRef)(null),l=(0,Y.useRef)(e);(0,Y.useEffect)(()=>{l.current=e},[e]);let u=(0,Y.useCallback)(e=>{let t=e;return Rl(l.current,t?.declaredCode,t?.code)??t?.message??String(e)},[]),d=(0,Y.useCallback)(()=>{c.current&&=(clearTimeout(c.current),null)},[]),f=(0,Y.useCallback)(async()=>{try{let e=(await zl(`${Ll}/status`))?.data??{environmentId:null,bound:!1,connection:null};r(e.bound?{kind:`bound`,status:e}:{kind:`unbound`})}catch(e){r({kind:`error`,message:u(e)})}},[u]);(0,Y.useEffect)(()=>(f(),d),[f,d]);let p=(0,Y.useCallback)((t,n)=>{let i=Math.max(t.interval,2)*1e3,a=async()=>{if(Date.now()-n>t.expires_in*1e3){r({kind:`error`,message:e(`cloudConnection.errors.expired`)});return}try{let n=await zl(`${Ll}/bind/poll`,{method:`POST`,body:JSON.stringify({device_code:t.device_code})});if(n?.data?.pending){c.current=setTimeout(a,i);return}if(n?.data?.bound||n?.success){await f();return}r({kind:`error`,message:Rl(e,n?.error?.declaredCode,n?.error?.code)??n?.error?.message??n?.error?.code??e(`cloudConnection.errors.bindFailed`)})}catch(e){r({kind:`error`,message:u(e)})}};c.current=setTimeout(a,i)},[u,f,e]),m=(0,Y.useCallback)(async()=>{a(!0);try{let t=(await zl(`${Ll}/bind/start`,{method:`POST`,body:`{}`}))?.data;if(!t?.device_code||!t?.user_code)throw Error(e(`cloudConnection.errors.deviceCodeFailed`));let n=t.verification_uri_complete??t.verification_uri,i=!1;if(n)try{i=!!window.open(n,`_blank`,`noopener,width=520,height=720`)}catch{}r({kind:`waiting`,code:t,popupOpened:i}),p(t,Date.now())}catch(e){r({kind:`error`,message:u(e)})}finally{a(!1)}},[u,p,e]),h=(0,Y.useCallback)(async()=>{a(!0);try{await zl(`${Ll}/unbind`,{method:`POST`,body:`{}`}),await f()}catch(e){r({kind:`error`,message:u(e)})}finally{a(!1)}},[u,f]),g=(0,Y.useCallback)(async e=>{try{await navigator.clipboard.writeText(e),s(!0),setTimeout(()=>s(!1),1500)}catch{}},[]);if(n.kind===`loading`)return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border p-6 text-sm text-muted-foreground`,children:[(0,X.jsx)(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),` `,e(`cloudConnection.checking`)]});if(n.kind===`error`)return(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-destructive/40 bg-destructive/5 p-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-destructive`,children:[(0,X.jsx)(Ir,{className:`h-4 w-4`,"aria-hidden":`true`}),` `,n.message]}),(0,X.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{d(),f()},children:e(`cloudConnection.retry`)})]});if(n.kind===`waiting`){let t=n.code.verification_uri_complete??n.code.verification_uri;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,X.jsx)(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),n.popupOpened?e(`cloudConnection.waiting.popupOpened`):e(`cloudConnection.waiting.polling`)]}),!n.popupOpened&&t?(0,X.jsxs)(`a`,{className:`inline-flex items-center gap-1.5 self-start rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90`,href:t,target:`_blank`,rel:`noreferrer`,children:[e(`cloudConnection.waiting.openApproval`),` `,(0,X.jsx)(ti,{className:`h-3.5 w-3.5`,"aria-hidden":`true`})]}):null,(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(`code`,{className:`rounded-md bg-muted px-4 py-2 text-2xl font-semibold tracking-[0.25em]`,children:n.code.user_code}),(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>void g(n.code.user_code),children:[(0,X.jsx)(qe,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e(o?`cloudConnection.waiting.copied`:`cloudConnection.waiting.copy`)]})]}),(0,X.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[e(`cloudConnection.waiting.codePrefilled`),n.popupOpened&&t?(0,X.jsxs)(X.Fragment,{children:[` `,(0,X.jsxs)(`a`,{className:`inline-flex items-center gap-1 text-primary underline-offset-2 hover:underline`,href:t,target:`_blank`,rel:`noreferrer`,children:[e(`cloudConnection.waiting.openItHere`),` `,(0,X.jsx)(ti,{className:`h-3 w-3`,"aria-hidden":`true`})]})]}):null]}),(0,X.jsx)(`button`,{type:`button`,className:`self-start rounded-md border px-3 py-1.5 text-sm hover:bg-accent`,onClick:()=>{d(),f()},children:e(`cloudConnection.waiting.cancel`)})]})}if(n.kind===`bound`){let r=n.status.connection??{},a=r.runtime_id??n.status.runtimeId;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(Zn,{className:`h-5 w-5 text-emerald-600`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`font-medium`,children:e(`cloudConnection.bound.title`)})]}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-6 gap-y-1.5 text-sm`,children:[r.name?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.runtime`)}),(0,X.jsx)(`dd`,{children:r.name})]}):null,r.organization_id?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.organization`)}),(0,X.jsx)(`dd`,{className:`font-mono`,children:r.organization_id})]}):null,r.account_email?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.approvedBy`)}),(0,X.jsx)(`dd`,{children:r.account_email})]}):null,a?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.runtimeId`)}),(0,X.jsx)(`dd`,{className:`font-mono text-xs`,children:a})]}):null,n.status.environmentId?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.environment`)}),(0,X.jsx)(`dd`,{className:`font-mono`,children:n.status.environmentId})]}):null,r.bound_at?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:e(`cloudConnection.bound.since`)}),(0,X.jsx)(`dd`,{children:new Date(r.bound_at).toLocaleString(t)})]}):null]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`cloudConnection.bound.privatePackages`)}),(0,X.jsxs)(`button`,{type:`button`,disabled:i,className:`inline-flex items-center gap-1.5 self-start rounded-md border border-destructive/40 px-3 py-1.5 text-sm text-destructive hover:bg-destructive/5 disabled:opacity-50`,onClick:()=>void h(),children:[(0,X.jsx)(Un,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),` `,e(`cloudConnection.bound.disconnect`)]})]})}return(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 rounded-lg border p-6`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)($e,{className:`h-5 w-5 text-muted-foreground`,"aria-hidden":`true`}),(0,X.jsx)(`span`,{className:`font-medium`,children:e(`cloudConnection.unbound.title`)})]}),(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`cloudConnection.unbound.body`)}),(0,X.jsxs)(`button`,{type:`button`,disabled:i,className:`inline-flex items-center gap-1.5 self-start rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50`,onClick:()=>void m(),children:[i?(0,X.jsx)(H,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}):(0,X.jsx)(Te,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`cloudConnection.unbound.connect`)]})]})}oe.register(`cloud-connection:panel`,()=>(0,X.jsx)(Bl,{}),{namespace:`app-shell`,label:`Cloud Connection Panel`,category:`plugin`,inputs:[]});var Vl=``.replace(/\/$/,``);function Hl(e){let t=d.get();return t?{...e,Authorization:`Bearer ${t}`}:e}function Ul(e){let t=Vl||(typeof window<`u`?window.location.origin:``);try{return new URL(e,t||void 0).toString()}catch{return e}}function Wl({text:e,label:t}){let[n,r]=(0,Y.useState)(!1);return(0,X.jsxs)(B,{variant:`outline`,size:`sm`,onClick:async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),1500)}catch{}},children:[n?(0,X.jsx)(Hn,{className:`h-3.5 w-3.5`}):(0,X.jsx)(qe,{className:`h-3.5 w-3.5`}),t?(0,X.jsx)(`span`,{className:`ml-1`,children:t}):null]})}function Gl({text:e}){return(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(`pre`,{className:`flex-1 overflow-x-auto rounded-md bg-muted px-3 py-2 text-xs leading-relaxed`,children:(0,X.jsx)(`code`,{children:e})}),(0,X.jsx)(Wl,{text:e})]})}function Kl(){let{t:e}=he(),[t,n]=(0,Y.useState)(!0),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{(async()=>{try{let e=await(await fetch(`${Vl}/api/v1/discovery`,{credentials:`include`})).json().catch(()=>({})),t=(e?.data??e)?.routes??{};i(typeof t.mcp==`string`?Ul(t.mcp):null)}catch(e){o(e?.message??String(e))}finally{n(!1)}})()},[]);let h=r?`${r}/skill`:null,g=(0,Y.useMemo)(()=>{if(!r)return null;let e=btoa(JSON.stringify({url:r}));return`cursor://anysphere.cursor-deeplink/mcp/install?name=objectstack&config=${encodeURIComponent(e)}`},[r]);return t?(0,X.jsxs)(`div`,{className:`space-y-3 p-1`,children:[(0,X.jsx)(Wn,{className:`h-10 w-full`}),(0,X.jsx)(Wn,{className:`h-40 w-full`})]}):r?(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(Nt,{children:[(0,X.jsx)(er,{className:`pb-2`,children:(0,X.jsxs)(Ct,{className:`flex items-center gap-2 text-base`,children:[(0,X.jsx)(rt,{className:`h-4 w-4`}),e(`connectAgent.url.title`)]})}),(0,X.jsxs)(ar,{className:`space-y-3`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`connectAgent.url.body`)}),(0,X.jsx)(Gl,{text:r}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[h&&(0,X.jsx)(B,{variant:`outline`,size:`sm`,asChild:!0,children:(0,X.jsxs)(`a`,{href:h,download:`SKILL.md`,children:[(0,X.jsx)(Pt,{className:`mr-1 h-3.5 w-3.5`}),e(`connectAgent.url.downloadSkill`)]})}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e(`connectAgent.url.skillHint`)})]})]})]}),(0,X.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,X.jsxs)(Nt,{children:[(0,X.jsx)(er,{className:`pb-2`,children:(0,X.jsx)(Ct,{className:`text-base`,children:`Claude (claude.ai / Desktop)`})}),(0,X.jsxs)(ar,{className:`space-y-2 text-sm`,children:[(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.claude.body`)}),(0,X.jsx)(Gl,{text:r}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`connectAgent.claude.reachability`)})]})]}),(0,X.jsxs)(Nt,{children:[(0,X.jsx)(er,{className:`pb-2`,children:(0,X.jsx)(Ct,{className:`text-base`,children:`Claude Code`})}),(0,X.jsxs)(ar,{className:`space-y-2 text-sm`,children:[(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.claudeCode.body`)}),(0,X.jsx)(Gl,{text:`claude mcp add --transport http objectstack ${r}`}),(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.claudeCode.plugin`)}),(0,X.jsx)(Gl,{text:`claude plugin marketplace add objectstack-ai/claude-plugin`})]})]}),(0,X.jsxs)(Nt,{children:[(0,X.jsx)(er,{className:`pb-2`,children:(0,X.jsxs)(Ct,{className:`flex items-center justify-between text-base`,children:[`Cursor`,g&&(0,X.jsx)(B,{variant:`outline`,size:`sm`,asChild:!0,children:(0,X.jsxs)(`a`,{href:g,children:[(0,X.jsx)(ti,{className:`mr-1 h-3.5 w-3.5`}),e(`connectAgent.cursor.addButton`)]})})]})}),(0,X.jsxs)(ar,{className:`space-y-2 text-sm`,children:[(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.cursor.body`)}),(0,X.jsx)(Gl,{text:JSON.stringify({mcpServers:{objectstack:{url:r}}},null,2)})]})]}),(0,X.jsxs)(Nt,{children:[(0,X.jsx)(er,{className:`pb-2`,children:(0,X.jsx)(Ct,{className:`text-base`,children:`VS Code / Copilot`})}),(0,X.jsxs)(ar,{className:`space-y-2 text-sm`,children:[(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.vscode.body`)}),(0,X.jsx)(Gl,{text:JSON.stringify({servers:{objectstack:{type:`http`,url:r}}},null,2)})]})]}),(0,X.jsxs)(Nt,{children:[(0,X.jsx)(er,{className:`pb-2`,children:(0,X.jsx)(Ct,{className:`text-base`,children:`Codex CLI`})}),(0,X.jsxs)(ar,{className:`space-y-2 text-sm`,children:[(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.codex.body`)}),(0,X.jsx)(Gl,{text:`[mcp_servers.objectstack]\nurl = "${r}"`})]})]}),(0,X.jsxs)(Nt,{children:[(0,X.jsx)(er,{className:`pb-2`,children:(0,X.jsxs)(Ct,{className:`flex items-center gap-2 text-base`,children:[(0,X.jsx)(Ot,{className:`h-4 w-4`}),e(`connectAgent.apiKey.title`),(0,X.jsx)(z,{variant:`secondary`,children:e(`connectAgent.apiKey.badge`)})]})}),(0,X.jsxs)(ar,{className:`space-y-2 text-sm`,children:[(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:e(`connectAgent.apiKey.body`)}),d?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium text-amber-600 dark:text-amber-400`,children:e(`connectAgent.apiKey.showOnce`,{name:d.name})}),(0,X.jsx)(Gl,{text:d.key}),(0,X.jsx)(Gl,{text:`x-api-key: ${d.key}`}),(0,X.jsx)(B,{variant:`outline`,size:`sm`,onClick:()=>f(null),children:e(`connectAgent.apiKey.done`)})]}):(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(R,{value:s,onChange:e=>c(e.target.value),placeholder:e(`connectAgent.apiKey.namePlaceholder`),className:`h-8 max-w-56`}),(0,X.jsx)(B,{size:`sm`,onClick:async()=>{u(!0),m(null);try{let e=await fetch(`${Vl}/api/v1/keys`,{method:`POST`,credentials:`include`,headers:Hl({"content-type":`application/json`}),body:JSON.stringify({name:s.trim()||`agent-key`})}),t=await e.json().catch(()=>({}));if(!e.ok||t?.success===!1)throw Error(t?.error?.message??t?.error??`HTTP ${e.status}`);let n=t?.data??t;f({name:n?.name??s,key:n?.key??``}),c(``)}catch(e){m(e?.message??String(e))}finally{u(!1)}},disabled:l,children:e(l?`connectAgent.apiKey.minting`:`connectAgent.apiKey.mint`)})]}),p&&(0,X.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-destructive`,children:[(0,X.jsx)(Ir,{className:`h-3.5 w-3.5`}),` `,p]})]})]})]})]}):(0,X.jsx)(Nt,{children:(0,X.jsxs)(ar,{className:`flex items-center gap-3 py-8 text-muted-foreground`,children:[(0,X.jsx)(Ir,{className:`h-5 w-5 shrink-0`}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`font-medium text-foreground`,children:e(`connectAgent.disabled.title`)}),(0,X.jsx)(`div`,{className:`text-sm`,children:a||e(`connectAgent.disabled.body`)})]})]})})}oe.register(`mcp:connect-agent`,()=>(0,X.jsx)(Kl,{}),{namespace:`app-shell`,label:`Connect an Agent`,category:`plugin`,inputs:[]});var ql=`/api/v1/cloud/environments/production/sso-open`,Jl=`/apps/cloud_control/sys_environment`,Yl=`create_environment`;function Xl(e){let{activeOrganization:t}=l(),n=t?.id,r=(0,Y.useMemo)(()=>c(),[]),[i,a]=(0,Y.useState)({phase:`loading`});return(0,Y.useEffect)(()=>{let t=!1,i=``.replace(/\/+$/,``),o=n?`?organizationId=${encodeURIComponent(n)}`:``;return(async()=>{try{let n=await r(`${i}/api/v1/cloud/environment-entitlements${o}`,{method:`GET`,credentials:`include`});if(!n.ok)throw Error(`entitlements ${n.status}`);let s=(await n.json().catch(()=>null))?.data;if(t)return;if(!s||typeof s!=`object`){a({phase:`unknown`});return}let c=s.hasProductionEnv===!0;a({phase:`ready`,hasProductionEnv:c}),c&&e&&r(`${i}${e}`,{method:`GET`,credentials:`include`}).catch(()=>{})}catch{t||a({phase:`unknown`})}})(),()=>{t=!0}},[r,n,e]),i}function Zl(e){window.location.href=e}function Ql({properties:e}){let{t}=he(),n=o(),r=Xl(e?.warmUrl),i=e?.openProductionUrl||ql,a=e?.environmentsRoute||Jl,s=e?.createAction||Yl;if(r.phase===`loading`)return(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,"data-onboarding":`loading`,children:[(0,X.jsx)(Wn,{className:`h-11 w-44 rounded-md`}),(0,X.jsx)(Wn,{className:`h-11 w-44 rounded-md`})]});let c=r.phase===`ready`&&!r.hasProductionEnv?t(`cloudOnboarding.hintCreate`):t(`cloudOnboarding.hintReady`),l=r.phase===`ready`&&!r.hasProductionEnv;return(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,"data-onboarding":r.phase,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,children:[l?(0,X.jsxs)(B,{size:`lg`,onClick:()=>n(wc(a,s)),children:[(0,X.jsx)(L,{className:`mr-2 h-4 w-4`}),t(`cloudOnboarding.createEnvironment`)]}):(0,X.jsxs)(B,{size:`lg`,onClick:()=>Zl(i),children:[(0,X.jsx)(ur,{className:`mr-2 h-4 w-4`}),t(`cloudOnboarding.openProduction`)]}),(0,X.jsxs)(B,{size:`lg`,variant:`secondary`,onClick:()=>n(a),children:[(0,X.jsx)(kr,{className:`mr-2 h-4 w-4`}),t(`cloudOnboarding.manageEnvironments`)]})]}),(0,X.jsx)(`p`,{className:`max-w-xl text-center text-sm text-muted-foreground`,children:c})]})}oe.register(`cloud:onboarding-next`,e=>(0,X.jsx)(Ql,{...e}),{namespace:`app-shell`,label:`Cloud Onboarding Next-Step`,category:`plugin`,inputs:[]});var $l=`/api/v1/ai/effective-model`;function eu(e,t){return e===`code-default`?t(`aiModelStatus.sourceCodeDefault`):e===`inherits-conversational`?t(`aiModelStatus.sourceInherits`):e.startsWith(`env:`)?t(`aiModelStatus.sourcePinned`,{source:e.slice(4)}):e===`unknown`?t(`aiModelStatus.sourceUnknown`):e}function tu(e){return e.startsWith(`env:`)?`default`:`secondary`}function nu(e){let t=(0,Y.useMemo)(()=>c(),[]),[n,r]=(0,Y.useState)({phase:`loading`});return(0,Y.useEffect)(()=>{let n=!1,i=``.replace(/\/+$/,``);return(async()=>{try{let a=await t(`${i}${e}`,{method:`GET`,credentials:`include`});if(!a.ok){n||r({phase:`error`,status:a.status});return}let o=await a.json().catch(()=>null),s=o?.data??o;if(n)return;if(!s||typeof s!=`object`||!s.conversational){r({phase:`error`});return}r({phase:`ready`,report:s})}catch{n||r({phase:`error`})}})(),()=>{n=!0}},[t,e]),n}function ru({label:e,model:t,source:n,t:r}){return(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 py-2 border-b border-border last:border-b-0`,children:[(0,X.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e}),(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`code`,{className:`text-sm font-medium`,children:t??`—`}),(0,X.jsx)(z,{variant:tu(n),children:eu(n,r)})]})]})}function iu({properties:e}){let{t}=he(),n=nu(e?.effectiveModelUrl||$l);if(n.phase===`loading`)return(0,X.jsxs)(`div`,{className:`space-y-2`,"data-ai-model-status":`loading`,children:[(0,X.jsx)(Wn,{className:`h-5 w-3/4 rounded`}),(0,X.jsx)(Wn,{className:`h-10 w-full rounded`}),(0,X.jsx)(Wn,{className:`h-10 w-full rounded`})]});if(n.phase===`error`)return(0,X.jsx)(`div`,{className:`text-sm text-muted-foreground`,"data-ai-model-status":`error`,children:n.status?t(`aiModelStatus.readFailedWithStatus`,{status:n.status}):t(`aiModelStatus.readFailed`)});let{report:r}=n,i=Object.entries(r.overrides).filter(([,e])=>e!=null),a=t(`aiModelStatus.modelUnknown`);return(0,X.jsxs)(`div`,{className:`space-y-4`,"data-ai-model-status":`ready`,children:[(0,X.jsxs)(`p`,{className:`text-sm text-foreground`,"data-testid":`ai-model-summary`,children:[t(`aiModelStatus.summary`,{conversational:r.conversational.model??a,conversationalSource:eu(r.conversational.source,t),structured:r.structured.model??a,structuredSource:eu(r.structured.source,t)}),r.routing?(0,X.jsxs)(X.Fragment,{children:[` `,t(`aiModelStatus.summaryRouting`,{free:r.routing.free,paid:r.routing.paid})]}):null]}),(0,X.jsxs)(`div`,{className:`rounded-md border border-border px-3`,children:[(0,X.jsx)(ru,{label:t(`aiModelStatus.rowConversational`),t,model:r.conversational.model,source:r.conversational.source}),(0,X.jsx)(ru,{label:t(`aiModelStatus.rowStructured`),t,model:r.structured.model,source:r.structured.source}),(0,X.jsx)(ru,{label:t(`aiModelStatus.rowReasoning`),t,model:r.reasoningEffort.effective,source:r.reasoningEffort.source})]}),(0,X.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:t(`aiModelStatus.overridesInEffect`)}),i.length===0?(0,X.jsx)(`span`,{children:t(`aiModelStatus.noOverrides`)}):(0,X.jsx)(`code`,{children:i.map(([e,t])=>`${e}=${t}`).join(` · `)})]}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[t(`aiModelStatus.adapter`),(0,X.jsxs)(`code`,{children:[r.adapter,r.provider?` / ${r.provider}`:``]})]})]})}oe.register(`cloud:ai-model-status`,e=>(0,X.jsx)(iu,{...e}),{namespace:`app-shell`,label:`Cloud AI Model Status`,category:`plugin`,inputs:[]});var au=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r,...i}=e||{};return{designer:{"data-obj-id":t,"data-obj-type":n,style:r},rest:i}};oe.register(`attachments`,({schema:e,className:t,...n})=>{let r=E(),{user:i}=l(),{designer:a}=au(n),o=r?.objectName,s=r?.recordId==null?``:String(r.recordId);return!o||!s?null:(0,X.jsx)(`div`,{className:t,...a,children:(0,X.jsx)(Fi,{objectName:o,recordId:s,dataSource:r?.dataSource,currentUserId:i?.id})})},{namespace:`record`,skipFallback:!0,category:`record`,label:`Attachments`,icon:`Paperclip`,inputs:[{name:`className`,type:`string`,label:`CSS Class`}]});var ou=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r}=e||{};return{"data-obj-id":t,"data-obj-type":n,style:r}};oe.register(`search`,({className:e,schema:t,...r})=>{let{t:i}=he(),[o,s]=(0,Y.useState)(``),{objects:c}=D(),l=F(),{appName:u}=a(),{currentAppName:d}=ji(),f=(0,Y.useMemo)(()=>c||[],[c]),{results:p,isSearching:m}=M({query:o,objects:f,dataSource:l,enabled:!!l,getDisplayName:ae}),h=`/apps/${u||d||``}`,g=i(`search.placeholder`,{defaultValue:`Search objects, dashboards, pages, reports…`}),_=i(`search.inputAriaLabel`,{defaultValue:`Search objects, dashboards, pages, reports`});return(0,X.jsxs)(`div`,{className:e,"data-block":`global:search`,role:`search`,...ou(r),children:[(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Dn,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`,"aria-hidden":!0}),(0,X.jsx)(R,{type:`search`,className:`pl-8`,value:o,"aria-label":_,placeholder:g,onChange:e=>s(e.target.value)})]}),m&&(0,X.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:i(`console.commandPalette.searching`,{defaultValue:`Searching…`})}),p.length>0&&(0,X.jsx)(`ul`,{className:`mt-2 grid gap-2`,"aria-label":i(`console.commandPalette.records`,{defaultValue:`Records`}),children:p.map(e=>{let t=Qi(e.icon);return(0,X.jsx)(`li`,{children:(0,X.jsx)(n,{to:`${h}/${e.objectName}/record/${e.recordId}`,className:`block rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:(0,X.jsx)(Nt,{className:`hover:bg-accent/50 transition-colors`,children:(0,X.jsxs)(ar,{className:`flex items-center gap-3 p-3`,children:[(0,X.jsx)(`div`,{className:`flex h-8 w-8 items-center justify-center rounded bg-primary/10 text-primary`,children:(0,X.jsx)(t,{className:`h-4 w-4`})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`p`,{className:`truncate text-sm font-medium`,children:e.display}),e.subtitle&&(0,X.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:e.subtitle})]}),(0,X.jsx)(z,{variant:`outline`,className:`shrink-0 text-xs`,children:e.objectLabel})]})})})},`${e.objectName}:${e.recordId}`)})})]})},{namespace:`global`,skipFallback:!0,category:`navigation`,label:`Global Search`,icon:`Search`});var su=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r}=e||{};return{"data-obj-id":t,"data-obj-type":n,style:r}};oe.register(`notifications`,({className:e,schema:t,...n})=>{let{notifications:r,unreadCount:i,pendingApprovalsCount:a,markAllRead:o,markRead:s,markManyRead:c}=bs(),l=ps();return(0,X.jsx)(`div`,{className:e,"data-block":`global:notifications`,...su(n),children:(0,X.jsx)(Lo,{notifications:r,unreadCount:i,pendingApprovalsCount:a,activities:l,onMarkAllRead:o,onMarkRead:s,onMarkManyRead:c})})},{namespace:`global`,skipFallback:!0,category:`navigation`,label:`Notifications`,icon:`Bell`});var cu=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r}=e||{};return{"data-obj-id":t,"data-obj-type":n,style:r}};oe.register(`launcher`,({className:e,schema:t,...n})=>{let{t:r}=he(),i=o(),{apps:a}=D(),{favorites:s}=Li(),c=(0,Y.useMemo)(()=>Vi(a),[a]),l=(0,Y.useCallback)(e=>i(`/apps/${Hi(e)??e?.name}`),[i]);return(0,X.jsx)(`nav`,{className:e,"aria-label":r(`console.nav.launcherLabel`,{defaultValue:`App launcher`}),"data-block":`app:launcher`,...cu(n),children:(0,X.jsx)(kc,{apps:c,favorites:s,onOpen:l,isAdmin:!1,onBrowseMarketplace:()=>{}})})},{namespace:`app`,skipFallback:!0,category:`navigation`,label:`App Launcher`,icon:`LayoutGrid`});var lu=e=>{let{"data-obj-id":t,"data-obj-type":n,style:r}=e||{};return{"data-obj-id":t,"data-obj-type":n,style:r}},uu=`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-sm text-foreground/80 transition-colors hover:bg-accent hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`;oe.register(`menu`,({className:e,schema:t,...r})=>{let{t:o}=he(),{objectLabel:s,viewLabel:c,dashboardLabel:d}=me(),{apps:f,objects:p}=D(),{appName:m}=a(),{currentAppName:h}=ji(),{pathname:g,search:_}=i(),{user:v,activeOrganization:y}=l(),b=xs(),{evaluator:x}=Si(),S=(0,Y.useCallback)(e=>Ci(e,x),[x]),{can:C,hasCapabilities:w}=u(),T=(0,Y.useCallback)(e=>e.every(e=>{let t=e.split(`:`);return t.length>=2?C(t[0],t[1]):w([e])||C(e,`read`)}),[C,w]),E=(0,Y.useMemo)(()=>new Set((p||[]).map(e=>e?.name).filter(Boolean)),[p]),O=(0,Y.useCallback)((e,t)=>e!==`object`||E.size===0||E.has(t),[E]),k=(0,Y.useMemo)(()=>{let e=(f||[]).filter(e=>e?.active!==!1);return zi(e,m??h??null)},[f,m,h]),A=(0,Y.useMemo)(()=>({evaluateVisibility:S,checkPermission:T,checkCapability:O,hasActionHandler:!0}),[S,T,O]),j=(0,Y.useMemo)(()=>{let e=k?.areas||[];if(e.length>0){let t=e.find(e=>qi(e?.navigation??[],A));if(t)return t.navigation??[]}return k?.navigation??[]},[k,A]),M=k?`/apps/${Hi(k)??k.name}`:``,N=(0,Y.useMemo)(()=>({currentUserId:v?.id??null,currentOrgId:y?.id??null}),[v?.id,y?.id]),P=(0,Y.useMemo)(()=>Ki(j,g,_,M,N)?.id??null,[j,g,_,M,N]),ee=(0,Y.useCallback)(e=>Xi(e,(e,t)=>s({name:e,label:t}),o,(e,t)=>d({name:e,label:t}),(e,t,n)=>c(e,t,n)),[s,d,c,o]);function te(e){if(!S(e.visible)||e.requiredPermissions?.length&&!T(e.requiredPermissions)||e.requiresObject&&!O(`object`,e.requiresObject)||e.requiresService&&!O(`service`,e.requiresService))return null;if(e.type===`separator`)return(0,X.jsx)(`li`,{"aria-hidden":`true`,className:`py-1`,children:(0,X.jsx)(ke,{})},e.id);if(e.type===`group`){let t=(e.children??[]).map(e=>te(e)).filter(Boolean);return t.length===0?null:(0,X.jsxs)(`li`,{children:[(0,X.jsx)(`div`,{className:`px-2 py-1 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:ee(e)}),(0,X.jsx)(`ul`,{className:`ml-2 grid gap-0.5 border-l pl-2`,children:t})]},e.id)}let t=Qi(e.icon),r=ee(e),i=e.badge!==void 0&&e.badge!==null&&e.badge!==``?(0,X.jsx)(z,{variant:e.badgeVariant??`secondary`,className:`ml-auto shrink-0`,children:e.badge}):null,a=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(t,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`truncate`,children:r}),i]}),o=P!==null&&e.id===P,s=V(uu,o&&`bg-accent font-medium text-foreground`);if(e.type===`action`)return(0,X.jsx)(`li`,{children:(0,X.jsx)(`button`,{type:`button`,className:s,onClick:()=>b(e),children:a})},e.id);let{href:c,external:l}=Yi(e,M,N);return(0,X.jsx)(`li`,{children:l?(0,X.jsx)(`a`,{href:c,target:`_blank`,rel:`noopener noreferrer`,className:s,"aria-current":o?`page`:void 0,children:a}):(0,X.jsx)(n,{to:c,className:s,"aria-current":o?`page`:void 0,children:a})},e.id)}let ne=j.map(e=>te(e)).filter(Boolean);return(0,X.jsx)(`nav`,{className:e,"aria-label":o(`console.nav.menuLabel`,{defaultValue:`App navigation`}),"data-block":`nav:menu`,...lu(r),children:ne.length>0?(0,X.jsx)(`ul`,{className:`grid gap-0.5`,children:ne}):(0,X.jsx)(`p`,{className:`px-2 py-1.5 text-sm text-muted-foreground`,children:o(`console.nav.menuEmpty`,{defaultValue:`This app has no navigation entries you can open.`})})})},{namespace:`nav`,skipFallback:!0,category:`navigation`,label:`Nav Menu`,icon:`Menu`});function du(){fo({type:`__object_field`,label:`Field`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`field`,embeddedPath:`fields`,extract:e=>fu(e.fields),groupLabel:`Fields`,order:5}]}),fo({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}]}),fo({type:`__object_validation`,label:`Embedded validation`,anchors:[{anchorType:`object`,source:`embedded`,editAs:`validation`,embeddedPath:`validations`,extract:e=>fu(e.validations),groupLabel:`Embedded Validations`,order:15}]}),fo({type:`hook`,anchors:[{anchorType:`object`,match:uo(`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:[]}}),fo({type:`page`,anchors:[{anchorType:`object`,match:uo(`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:n})=>{if(e?.type===`list`)return e?.object?{interfaceConfig:{source:String(e.object)}}:{};if(e?.type!==`record`||!e?.object)return{};try{let r=await n.get(`object`,String(e.object));if(!r||typeof r!=`object`)return{};let{buildDefaultPageSchema:i}=await t(async()=>{let{buildDefaultPageSchema:e}=await import(`./plugins-views-DZmsFOak.js`).then(e=>e.t);return{buildDefaultPageSchema:e}},__vite__mapDeps([0]),import.meta.url),a=i(r),o={};return Array.isArray(a?.regions)&&a.regions.length&&(o.regions=a.regions),a?.template&&(o.template=a.template),o}catch{return{}}}}),fo({type:`view`,anchors:[{anchorType:`object`,match:uo([`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=e.formType||`simple`,o=i?{type:a,data:{provider:`object`,object:t},sections:a===`wizard`?[{label:`Step 1`,fields:[]}]:[]}:{type:e.kind||`grid`,columns:[],data:{provider:`object`,object:t}};return{name:r,object:t,viewKind:i?`form`:`list`,label:e.label,config:o}}}),fo({type:`flow`,anchors:[{anchorType:`object`,match:uo([`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:[]}}),fo({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:{}}}),fo({type:`action`,anchors:[{anchorType:`object`,match:uo([`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 };`}}}),fo({type:`dashboard`,anchors:[{anchorType:`object`,match:uo([`object`,`data.object`]),groupLabel:`Dashboards`,order:80}],createFields:[`label`,`name`,`description`],createDerive:[{from:`label`,to:`name`,transform:`slugify`,untilUserEdits:!0}],createDefaults:{widgets:[]}}),fo({type:`report`,anchors:[{anchorType:`object`,match:uo([`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}}),fo({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 fu(e){return Array.isArray(e)?e:e&&typeof e==`object`?Object.entries(e).map(([e,t])=>({name:e,...t&&typeof t==`object`?t:{}})):[]}var pu={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`}},mu={position:{type:`object`,title:`Position`,required:[`name`],properties:{...pu}},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:{...pu.name,description:`Bundle id (e.g. zh_CN, en_US, package-locale).`},label:pu.label,description:pu.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:{...pu,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:{...pu,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:{...pu,icon:{type:`string`,title:`Icon`},navigation:{type:`array`,title:`Navigation`,items:{type:`object`}}}},page:{type:`object`,title:`Page`,required:[`name`],properties:{...pu,route:{type:`string`,title:`Route`,description:`URL path under the app.`},layout:{type:`string`,title:`Layout`}}},view:{type:`object`,title:`View`,required:[`name`],properties:{...pu,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:{...pu,widgets:{type:`array`,title:`Widgets`,items:{type:`object`}}}},report:{type:`object`,title:`Report`,required:[`name`],properties:{...pu,object:{type:`string`,title:`Object`},filters:{type:`array`,title:`Filters`,items:{type:`object`}}}},book:{type:`object`,title:`Documentation Book`,required:[`name`,`groups`],properties:{...pu,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:{...pu,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 hu(){for(let[e,t]of Object.entries(mu))fo({type:e,defaultSchema:t,fieldOrder:[`name`,`label`,`description`]})}function gu({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 _u=[{value:`managed`,label:`Managed (ObjectStack owns the schema)`},{value:`external`,label:`External (read existing schema as-is)`},{value:`validate-only`,label:`Validate only`}],vu=``.replace(/\/+$/,``),yu=e=>e.format===`password`;function bu(e){let t=e?.configSchema?.properties??{},n={};for(let[e,r]of Object.entries(t))yu(r)||r.default!==void 0&&(n[e]=r.default);return n}function xu(e){let t=Y.useMemo(()=>c(),[]),n=yi(),[r,i]=Y.useState([]),[a,o]=Y.useState(!0),[s,l]=Y.useState(null),u=Y.useCallback(async(e,n)=>{let r=await t(`${vu}${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]),d=Y.useCallback(async()=>{o(!0);try{let e=await u(`/api/v1/datasources`);i(Array.isArray(e?.datasources)?e.datasources:[])}catch(e){_i.error(`Load datasources: ${e.message}`),i([])}finally{o(!1)}},[u]);Y.useEffect(()=>{d()},[d]);let f=async e=>{l(`test:${e}`);try{let t=await u(`/api/v1/datasources/${encodeURIComponent(e)}/test`,{method:`POST`,body:`{}`});_i.success(t?.ok===!1?`${e}: ${t?.error??`failed`}`:`${e}: connection ok${t?.latencyMs==null?``:` (${t.latencyMs}ms)`}`),d()}catch(t){_i.error(`${e}: ${t.message}`)}finally{l(null)}},p=async e=>{if(window.confirm(`Delete datasource “${e}”? This cannot be undone.`)){l(`del:${e}`);try{await u(`/api/v1/datasources/${encodeURIComponent(e)}`,{method:`DELETE`}),_i.success(`Deleted ${e}.`),d()}catch(t){_i.error(`Delete ${e}: ${t.message}`)}finally{l(null)}}},[m,h]=Y.useState([]),[g,_]=Y.useState(!1),[v,y]=Y.useState(null),[b,x]=Y.useState(null),[S,C]=Y.useState(!1),[w,T]=Y.useState(!1),[E,D]=Y.useState(null),[O,k]=Y.useState(!1),A=Y.useCallback(async()=>{if(m.length)return m;try{let e=await u(`/api/v1/datasources/drivers`),t=Array.isArray(e?.drivers)?e.drivers:[];return h(t),t}catch(e){return _i.error(`Load drivers: ${e.message}`),[]}},[u,m]),j=Y.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:bu(t),secret:``}),_(!0)},N=async e=>{let t=await A();l(`edit:${e.name}`);try{let n=(await u(`/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){_i.error(`Open ${e.name}: ${t.message}`)}finally{l(null)}},P=e=>{x(t=>t&&{...t,driver:e,config:bu(m.find(t=>t.id===e)),secret:``}),D(null)},ee=(e,t)=>x(n=>n&&{...n,config:{...n.config,[e]:t}}),te=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},ne=async()=>{if(b){k(!0),D(null);try{let e=await u(`/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 u(`/api/v1/datasources/${encodeURIComponent(v)}`,{method:`PATCH`,body:JSON.stringify(te(b))}),_i.success(`Updated ${v}.`)):(await u(`/api/v1/datasources`,{method:`POST`,body:JSON.stringify({name:b.name,...te(b)})}),_i.success(`Created ${b.name}.`)),_(!1),d()}catch(e){_i.error(`Save: ${e.message}`)}finally{T(!1)}}},ie=v?!0:/^[a-z_][a-z0-9_]*$/.test(b?.name??``),F=!!b&&!!b.driver&&ie&&!w,[ae,oe]=Y.useState(null),[se,ce]=Y.useState(null),[le,ue]=Y.useState(new Set),[de,fe]=Y.useState(!1),pe=async e=>{oe(e),ce(null),ue(new Set);try{let t=await u(`/api/v1/datasources/${encodeURIComponent(e)}/remote-tables`);ce(Array.isArray(t?.tables)?t.tables:[])}catch(t){_i.error(`Introspect ${e}: ${t.message}`),ce([])}},me=e=>ue(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),he=async()=>{if(!ae||le.size===0)return;fe(!0);let e=0,t=[];for(let r of le)try{let{draft:t}=await u(`/api/v1/datasources/${encodeURIComponent(ae)}/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}`)}fe(!1),e&&_i.success(`Synced ${e} object${e>1?`s`:``} from ${ae}.`),t.length&&_i.error(`Failed: ${t.join(`; `)}`),oe(null)},ge=(e,t)=>{let n=t.title||e,r=(j?.configSchema?.required??[]).includes(e);if(yu(t))return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(I,{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)(I,{className:`text-xs`,children:n}),t.description&&(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:t.description})]}),(0,X.jsx)(xn,{checked:!!i,onCheckedChange:t=>ee(e,t)})]},e);if(Array.isArray(t.enum))return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsxs)(I,{className:`text-xs`,children:[n,r?` *`:``]}),(0,X.jsxs)(Qr,{value:i==null?``:String(i),onValueChange:t=>ee(e,t),children:[(0,X.jsx)(Fe,{children:(0,X.jsx)(jt,{placeholder:`Select…`})}),(0,X.jsx)(tn,{children:t.enum.map(e=>(0,X.jsx)(He,{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)(I,{className:`text-xs`,children:[n,r?` *`:``]}),(0,X.jsx)(R,{type:a?`number`:`text`,value:i==null?``:String(i),onChange:t=>ee(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)(wt,{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)(B,{variant:`outline`,size:`sm`,onClick:()=>void d(),disabled:a,children:[(0,X.jsx)(Gr,{className:`mr-1.5 h-4 w-4`+(a?` animate-spin`:``)}),` Refresh`]}),(0,X.jsxs)(B,{size:`sm`,onClick:()=>void M(),children:[(0,X.jsx)(L,{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)(H,{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)(wt,{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)(gu,{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)(B,{variant:`ghost`,size:`sm`,disabled:s===`test:${e.name}`,onClick:()=>void f(e.name),children:[s===`test:${e.name}`?(0,X.jsx)(H,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,X.jsx)(At,{className:`mr-1.5 h-4 w-4`}),` Test`]}),(0,X.jsxs)(B,{variant:`secondary`,size:`sm`,onClick:()=>void pe(e.name),children:[(0,X.jsx)(It,{className:`mr-1.5 h-4 w-4`}),` Sync objects`]}),!t&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,title:`Edit`,disabled:s===`edit:${e.name}`,onClick:()=>void N(e),children:s===`edit:${e.name}`?(0,X.jsx)(H,{className:`h-4 w-4 animate-spin`}):(0,X.jsx)(Ft,{className:`h-4 w-4`})}),(0,X.jsx)(B,{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)(H,{className:`h-4 w-4 animate-spin`}):(0,X.jsx)(qt,{className:`h-4 w-4`})})]})]},e.name)})}),(0,X.jsx)(Yr,{open:g,onOpenChange:e=>{e||_(!1)},children:(0,X.jsxs)(di,{className:`max-w-lg`,children:[(0,X.jsxs)(Yt,{children:[(0,X.jsx)(je,{children:v?`Edit “${v}”`:`New datasource`}),(0,X.jsx)(An,{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)(I,{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})}),!ie&&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)(I,{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)(I,{className:`text-xs`,children:`Driver *`}),(0,X.jsxs)(Qr,{value:b.driver,onValueChange:P,disabled:!!v,children:[(0,X.jsx)(Fe,{children:(0,X.jsx)(jt,{placeholder:`Choose a driver`})}),(0,X.jsx)(tn,{children:m.map(e=>(0,X.jsx)(He,{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])=>ge(e,t)),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{className:`text-xs`,children:`Schema mode`}),(0,X.jsxs)(Qr,{value:b.schemaMode,onValueChange:e=>x(t=>t&&{...t,schemaMode:e}),children:[(0,X.jsx)(Fe,{children:(0,X.jsx)(jt,{})}),(0,X.jsx)(tn,{children:_u.map(e=>(0,X.jsx)(He,{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)(Zn,{className:`h-3.5 w-3.5`}):(0,X.jsx)(bn,{className:`h-3.5 w-3.5`}),E.text]})]}),(0,X.jsxs)(oi,{className:`gap-2 sm:justify-between`,children:[(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,disabled:!b?.driver||O,onClick:()=>void ne(),children:[O?(0,X.jsx)(H,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,X.jsx)(At,{className:`mr-1.5 h-4 w-4`}),` Test connection`]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(B,{variant:`ghost`,size:`sm`,onClick:()=>_(!1),children:`Cancel`}),(0,X.jsxs)(B,{size:`sm`,disabled:!F,onClick:()=>void re(),children:[w&&(0,X.jsx)(H,{className:`mr-1.5 h-4 w-4 animate-spin`}),v?`Save changes`:`Create datasource`]})]})]})]})}),(0,X.jsx)(Yr,{open:!!ae,onOpenChange:e=>{e||oe(null)},children:(0,X.jsxs)(di,{className:`max-w-lg`,children:[(0,X.jsxs)(Yt,{children:[(0,X.jsxs)(je,{children:[`Sync objects from “`,ae,`”`]}),(0,X.jsx)(An,{children:`Pick the remote tables to import as objects. Each becomes an object definition.`})]}),se==null?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 py-8 text-sm text-muted-foreground`,children:[(0,X.jsx)(H,{className:`h-4 w-4 animate-spin`}),` Introspecting…`]}):se.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:se.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:le.has(e.name),onChange:()=>me(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)(B,{variant:`ghost`,size:`sm`,onClick:()=>oe(null),children:`Cancel`}),(0,X.jsxs)(B,{size:`sm`,disabled:de||le.size===0,onClick:()=>void he(),children:[de?(0,X.jsx)(H,{className:`mr-1.5 h-4 w-4 animate-spin`}):(0,X.jsx)(It,{className:`mr-1.5 h-4 w-4`}),`Create `,le.size||``,` object`,le.size===1?``:`s`]})]})]})})]})}var Su=!1;function Cu(){Su||(Su=!0,fo({type:`datasource`,label:`Datasources`,domain:`data`,ListPage:xu}))}function Z({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 wu({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)(Ir,{className:`h-4 w-4 mt-0.5 shrink-0`}),(0,X.jsx)(`div`,{className:`flex-1`,children:t})]})}function Tu({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)(_t,{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 Q=class extends Y.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)(wu,{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 Eu({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:V(`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)(L,{className:`h-3 w-3`}),(0,X.jsx)(`span`,{children:a??`Add`})]})]})]})}var Du=Y.lazy(async()=>({default:(await t(()=>import(`./dist-BK-OswHQ.js`).then(e=>e.n),[],import.meta.url)).Editor}));function Ou(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 ku({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]=Y.useState(o),l=Y.useRef(o);Y.useEffect(()=>{o!==l.current&&(c(o),l.current=o)},[o]);let[u,d]=_o(r),[f,p]=Y.useState(()=>typeof document<`u`&&document.documentElement.classList.contains(`dark`)?`vs-dark`:`light`);Y.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=Y.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)(Y.Suspense,{fallback:(0,X.jsx)(Wn,{className:`h-full w-full`}),children:(0,X.jsx)(Du,{value:s,language:`typescript`,path:a===`react`?`page.tsx`:`page.html.tsx`,theme:f,beforeMount:Ou,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)(Q,{fallbackHint:`The page source threw while rendering — fix the code in the Source tab.`,children:(0,X.jsx)(re,{schema:h})})});return i===`editor`?g:i===`preview`?(0,X.jsx)(Z,{hint:`page · ${a} source`,children:_}):(0,X.jsx)(Z,{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 Au={grid:{label:`Grid`,category:`data`,Icon:Ie},"object-grid":{label:`Table`,category:`data`,Icon:St},"object-form":{label:`Form`,category:`data`,Icon:ni},"object-metric":{label:`Metric`,category:`data`,Icon:zt},"object-kanban":{label:`Kanban`,category:`data`,Icon:vt},"page:header":{label:`Header`,category:`layout`,Icon:Vt},"page:footer":{label:`Footer`,category:`layout`,Icon:Je},"page:sidebar":{label:`Sidebar`,category:`layout`,Icon:Ze},"page:tabs":{label:`Tabs`,category:`layout`,Icon:Ln},"page:accordion":{label:`Accordion`,category:`layout`,Icon:jn},"page:card":{label:`Card`,category:`layout`,Icon:ln},"page:section":{label:`Section`,category:`layout`,Icon:ir},"record:details":{label:`Record details`,category:`record`,Icon:Wr},"record:highlights":{label:`Highlights`,category:`record`,Icon:Se},"record:related_list":{label:`Related list`,category:`record`,Icon:Ae},"record:activity":{label:`Activity timeline`,category:`record`,Icon:Mr},"record:discussion":{label:`Discussion`,category:`record`,Icon:Lr},"record:path":{label:`Stage path`,category:`record`,Icon:at},"record:alert":{label:`Alert banner`,category:`record`,Icon:ci},"record:quick_actions":{label:`Quick actions`,category:`record`,Icon:In},"record:reference_rail":{label:`Reference rail`,category:`record`,Icon:Ht},"record:history":{label:`History`,category:`record`,Icon:Sr},"nav:menu":{label:`Nav menu`,category:`navigation`,Icon:Hr},"nav:breadcrumb":{label:`Breadcrumb`,category:`navigation`,Icon:at},"global:search":{label:`Global search`,category:`navigation`,Icon:Dn},"ai:suggestion":{label:`AI suggestion`,category:`ai`,Icon:pt},"element:text":{label:`Text`,category:`element`,Icon:qr},"element:number":{label:`Number`,category:`element`,Icon:Qe},"element:image":{label:`Image`,category:`element`,Icon:mi},"element:divider":{label:`Divider`,category:`element`,Icon:$n},"element:button":{label:`Button`,category:`element`,Icon:ge},"element:definition-list":{label:`Definition list`,category:`element`,Icon:ui},"element:repeater":{label:`Repeater`,category:`element`,Icon:sr}},ju=[[`record:discussion`,`record:chatter`]],Mu={data:`Data`,layout:`Layout`,record:`Record context`,navigation:`Navigation`,element:`Elements`,ai:`AI`,misc:`Other`},Nu=(()=>{let e={data:[],layout:[],record:[],navigation:[],element:[],ai:[],misc:[]};for(let[t,n]of Object.entries(Au))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)})(),Pu=We,Fu={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 Iu(e){let t=Au[e];if(t)return{Icon:t.Icon,category:t.category};for(let t of ju)if(t.includes(e))for(let e of t){let t=Au[e];if(t)return{Icon:t.Icon,category:t.category}}}function Lu(e){return Fu[Iu(e)?.category??`misc`]}var Ru={"object-grid":[{name:`objectName`,label:`engine.inspector.pageBlock.field.object-grid.objectName`,kind:`object-picker`},{name:`columns`,label:`engine.inspector.pageBlock.field.object-grid.columns`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`},{name:`pageSize`,label:`engine.inspector.pageBlock.field.object-grid.pageSize`,kind:`number`,placeholder:{literal:`20`}}],"object-form":[{name:`objectName`,label:`engine.inspector.pageBlock.field.object-form.objectName`,kind:`object-picker`},{name:`mode`,label:`engine.inspector.pageBlock.field.object-form.mode`,kind:`select`,options:[{value:`create`,label:`engine.inspector.pageBlock.option.mode.create`},{value:`edit`,label:`engine.inspector.pageBlock.option.mode.edit`},{value:`view`,label:`engine.inspector.pageBlock.option.mode.view`}]},{name:`formType`,label:`engine.inspector.pageBlock.field.object-form.formType`,kind:`select`,options:[{value:`simple`,label:`engine.inspector.pageBlock.option.formType.simple`},{value:`tabbed`,label:`engine.inspector.pageBlock.option.formType.tabbed`},{value:`wizard`,label:`engine.inspector.pageBlock.option.formType.wizard`},{value:`split`,label:`engine.inspector.pageBlock.option.formType.split`},{value:`drawer`,label:`engine.inspector.pageBlock.option.formType.drawer`},{value:`modal`,label:`engine.inspector.pageBlock.option.formType.modal`}]},{name:`layout`,label:`engine.inspector.pageBlock.field.object-form.layout`,kind:`select`,options:[{value:`vertical`,label:`engine.inspector.pageBlock.option.layout.vertical`},{value:`horizontal`,label:`engine.inspector.pageBlock.option.layout.horizontal`},{value:`inline`,label:`engine.inspector.pageBlock.option.layout.inline`},{value:`grid`,label:`engine.inspector.pageBlock.option.layout.grid`}]},{name:`columns`,label:`engine.inspector.pageBlock.field.object-form.columns`,kind:`number`,placeholder:{literal:`2`}},{name:`fields`,label:`engine.inspector.pageBlock.field.object-form.fields`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`},{name:`title`,label:`engine.inspector.pageBlock.field.object-form.title`,kind:`text`},{name:`description`,label:`engine.inspector.pageBlock.field.object-form.description`,kind:`text`}],"object-metric":[{name:`objectName`,label:`engine.inspector.pageBlock.field.object-metric.objectName`,kind:`object-picker`},{name:`label`,label:`engine.inspector.pageBlock.field.object-metric.label`,kind:`text`},{name:`description`,label:`engine.inspector.pageBlock.field.object-metric.description`,kind:`text`},{name:`icon`,label:`engine.inspector.pageBlock.field.object-metric.icon`,kind:`text`,placeholder:{key:`engine.inspector.pageBlock.placeholder.object-metric.icon`}},{name:`colorVariant`,label:`engine.inspector.pageBlock.field.object-metric.colorVariant`,kind:`color`,options:[{value:`default`,label:`engine.inspector.pageBlock.option.colorVariant.default`},{value:`blue`,label:`engine.inspector.pageBlock.option.colorVariant.blue`},{value:`teal`,label:`engine.inspector.pageBlock.option.colorVariant.teal`},{value:`orange`,label:`engine.inspector.pageBlock.option.colorVariant.orange`},{value:`purple`,label:`engine.inspector.pageBlock.option.colorVariant.purple`},{value:`success`,label:`engine.inspector.pageBlock.option.colorVariant.success`},{value:`warning`,label:`engine.inspector.pageBlock.option.colorVariant.warning`},{value:`danger`,label:`engine.inspector.pageBlock.option.colorVariant.danger`}]},{name:`format`,label:`engine.inspector.pageBlock.field.object-metric.format`,kind:`select`,options:[{value:`number`,label:`engine.inspector.pageBlock.option.format.number`},{value:`currency`,label:`engine.inspector.pageBlock.option.format.currency`},{value:`percent`,label:`engine.inspector.pageBlock.option.format.percent`}]},{name:`prefix`,label:`engine.inspector.pageBlock.field.object-metric.prefix`,kind:`text`},{name:`suffix`,label:`engine.inspector.pageBlock.field.object-metric.suffix`,kind:`text`}],"object-kanban":[{name:`objectName`,label:`engine.inspector.pageBlock.field.object-kanban.objectName`,kind:`object-picker`},{name:`groupField`,label:`engine.inspector.pageBlock.field.object-kanban.groupField`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`titleField`,label:`engine.inspector.pageBlock.field.object-kanban.titleField`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`cardFields`,label:`engine.inspector.pageBlock.field.object-kanban.cardFields`,kind:`field-list`,objectFrom:`self`,objectProp:`objectName`}],grid:[{name:`columns`,label:`engine.inspector.pageBlock.field.grid.columns`,kind:`number`,placeholder:{literal:`3`}},{name:`gap`,label:`engine.inspector.pageBlock.field.grid.gap`,kind:`number`,placeholder:{literal:`4`}}],"element:text":[{name:`content`,label:`engine.inspector.pageBlock.field.element:text.content`,kind:`text`,placeholder:{key:`engine.inspector.pageBlock.placeholder.element:text.content`}},{name:`variant`,label:`engine.inspector.pageBlock.field.element:text.variant`,kind:`select`,options:[{value:`heading`,label:`engine.inspector.pageBlock.option.variant.heading`},{value:`subheading`,label:`engine.inspector.pageBlock.option.variant.subheading`},{value:`body`,label:`engine.inspector.pageBlock.option.variant.body`},{value:`caption`,label:`engine.inspector.pageBlock.option.variant.caption`}]},{name:`align`,label:`engine.inspector.pageBlock.field.element:text.align`,kind:`select`,options:[{value:`left`,label:`engine.inspector.pageBlock.option.align.left`},{value:`center`,label:`engine.inspector.pageBlock.option.align.center`},{value:`right`,label:`engine.inspector.pageBlock.option.align.right`}]}],"element:image":[{name:`src`,label:`engine.inspector.pageBlock.field.element:image.src`,kind:`text`,placeholder:{literal:`https://…`}},{name:`alt`,label:`engine.inspector.pageBlock.field.element:image.alt`,kind:`text`},{name:`fit`,label:`engine.inspector.pageBlock.field.element:image.fit`,kind:`select`,options:[{value:`cover`,label:`engine.inspector.pageBlock.option.fit.cover`},{value:`contain`,label:`engine.inspector.pageBlock.option.fit.contain`},{value:`fill`,label:`engine.inspector.pageBlock.option.fit.fill`}]}],"element:definition-list":[{name:`items`,label:`engine.inspector.pageBlock.field.element:definition-list.items`,kind:`array`,addLabel:`engine.inspector.pageBlock.add.element:definition-list.items`,itemFields:[{name:`label`,label:`engine.inspector.pageBlock.field.element:definition-list.items.label`,kind:`text`},{name:`value`,label:`engine.inspector.pageBlock.field.element:definition-list.items.value`,kind:`text`}]},{name:`columns`,label:`engine.inspector.pageBlock.field.element:definition-list.columns`,kind:`number`,placeholder:{literal:`1`}},{name:`inline`,label:`engine.inspector.pageBlock.field.element:definition-list.inline`,kind:`boolean`}],"element:repeater":[{name:`object`,label:`engine.inspector.pageBlock.field.element:repeater.object`,kind:`object-picker`},{name:`titleField`,label:`engine.inspector.pageBlock.field.element:repeater.titleField`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`fields`,label:`engine.inspector.pageBlock.field.element:repeater.fields`,kind:`field-list`,objectFrom:`self`,objectProp:`object`},{name:`limit`,label:`engine.inspector.pageBlock.field.element:repeater.limit`,kind:`number`,placeholder:{literal:`10`}},{name:`emptyText`,label:`engine.inspector.pageBlock.field.element:repeater.emptyText`,kind:`text`},{name:`divided`,label:`engine.inspector.pageBlock.field.element:repeater.divided`,kind:`boolean`}],"element:number":[{name:`object`,label:`engine.inspector.pageBlock.field.element:number.object`,kind:`object-picker`},{name:`field`,label:`engine.inspector.pageBlock.field.element:number.field`,kind:`field-picker`,objectFrom:`self`,objectProp:`object`},{name:`aggregate`,label:`engine.inspector.pageBlock.field.element:number.aggregate`,kind:`select`,options:[{value:`count`,label:`engine.inspector.pageBlock.option.aggregate.count`},{value:`sum`,label:`engine.inspector.pageBlock.option.aggregate.sum`},{value:`avg`,label:`engine.inspector.pageBlock.option.aggregate.avg`},{value:`min`,label:`engine.inspector.pageBlock.option.aggregate.min`},{value:`max`,label:`engine.inspector.pageBlock.option.aggregate.max`}]},{name:`format`,label:`engine.inspector.pageBlock.field.element:number.format`,kind:`select`,options:[{value:`number`,label:`engine.inspector.pageBlock.option.format.number`},{value:`currency`,label:`engine.inspector.pageBlock.option.format.currency`},{value:`percent`,label:`engine.inspector.pageBlock.option.format.percent`}]},{name:`prefix`,label:`engine.inspector.pageBlock.field.element:number.prefix`,kind:`text`},{name:`suffix`,label:`engine.inspector.pageBlock.field.element:number.suffix`,kind:`text`}],"element:button":[{name:`label`,label:`engine.inspector.pageBlock.field.element:button.label`,kind:`text`},{name:`variant`,label:`engine.inspector.pageBlock.field.element:button.variant`,kind:`select`,options:[{value:`primary`,label:`engine.inspector.pageBlock.option.variant.primary`},{value:`secondary`,label:`engine.inspector.pageBlock.option.variant.secondary`},{value:`danger`,label:`engine.inspector.pageBlock.option.variant.danger`},{value:`ghost`,label:`engine.inspector.pageBlock.option.variant.ghost`},{value:`link`,label:`engine.inspector.pageBlock.option.variant.link`}]},{name:`size`,label:`engine.inspector.pageBlock.field.element:button.size`,kind:`select`,options:[{value:`small`,label:`engine.inspector.pageBlock.option.size.small`},{value:`medium`,label:`engine.inspector.pageBlock.option.size.medium`},{value:`large`,label:`engine.inspector.pageBlock.option.size.large`}]},{name:`icon`,label:`engine.inspector.pageBlock.field.element:button.icon`,kind:`text`,placeholder:{key:`engine.inspector.pageBlock.placeholder.element:button.icon`}},{name:`action`,label:`engine.inspector.pageBlock.field.element:button.action`,kind:`json`,placeholder:{literal:`{ "type": "url", "target": "/environments" }`}}],"page:header":[{name:`title`,label:`engine.inspector.pageBlock.field.page:header.title`,kind:`text`},{name:`subtitle`,label:`engine.inspector.pageBlock.field.page:header.subtitle`,kind:`text`},{name:`breadcrumb`,label:`engine.inspector.pageBlock.field.page:header.breadcrumb`,kind:`boolean`}],"page:card":[{name:`title`,label:`engine.inspector.pageBlock.field.page:card.title`,kind:`text`},{name:`bordered`,label:`engine.inspector.pageBlock.field.page:card.bordered`,kind:`boolean`}],"page:tabs":[{name:`items`,label:`engine.inspector.pageBlock.field.page:tabs.items`,kind:`array`,addLabel:`engine.inspector.pageBlock.add.page:tabs.items`,itemFields:[{name:`key`,label:`engine.inspector.pageBlock.field.page:tabs.items.key`,kind:`text`},{name:`label`,label:`engine.inspector.pageBlock.field.page:tabs.items.label`,kind:`text`}]}],"page:accordion":[{name:`items`,label:`engine.inspector.pageBlock.field.page:accordion.items`,kind:`array`,addLabel:`engine.inspector.pageBlock.add.page:accordion.items`,itemFields:[{name:`label`,label:`engine.inspector.pageBlock.field.page:accordion.items.label`,kind:`text`}]}],"record:related_list":[{name:`objectName`,label:`engine.inspector.pageBlock.field.record:related_list.objectName`,kind:`object-picker`},{name:`relationshipField`,label:`engine.inspector.pageBlock.field.record:related_list.relationshipField`,kind:`field-picker`,objectFrom:`self`,objectProp:`objectName`},{name:`title`,label:`engine.inspector.pageBlock.field.record:related_list.title`,kind:`text`},{name:`limit`,label:`engine.inspector.pageBlock.field.record:related_list.limit`,kind:`number`,placeholder:{literal:`10`}}],"record:highlights":[{name:`fields`,label:`engine.inspector.pageBlock.field.record:highlights.fields`,kind:`field-list`,objectFrom:`page`}],"record:details":[{name:`sections`,label:`engine.inspector.pageBlock.field.record:details.sections`,kind:`array`,addLabel:`engine.inspector.pageBlock.add.record:details.sections`,itemFields:[{name:`name`,label:`engine.inspector.pageBlock.field.record:details.sections.name`,kind:`text`,placeholder:{key:`engine.inspector.pageBlock.placeholder.record:details.sections.name`}},{name:`label`,label:`engine.inspector.pageBlock.field.record:details.sections.label`,kind:`text`},{name:`columns`,label:`engine.inspector.pageBlock.field.record:details.sections.columns`,kind:`number`,placeholder:{literal:`2`}},{name:`fields`,label:`engine.inspector.pageBlock.field.record:details.sections.fields`,kind:`field-list`,objectFrom:`page`}]}],"record:alert":[{name:`severity`,label:`engine.inspector.pageBlock.field.record:alert.severity`,kind:`select`,options:[{value:`info`,label:`engine.inspector.pageBlock.option.severity.info`},{value:`warning`,label:`engine.inspector.pageBlock.option.severity.warning`},{value:`error`,label:`engine.inspector.pageBlock.option.severity.error`},{value:`success`,label:`engine.inspector.pageBlock.option.severity.success`}]},{name:`title`,label:`engine.inspector.pageBlock.field.record:alert.title`,kind:`text`},{name:`body`,label:`engine.inspector.pageBlock.field.record:alert.body`,kind:`text`},{name:`icon`,label:`engine.inspector.pageBlock.field.record:alert.icon`,kind:`text`,placeholder:{key:`engine.inspector.pageBlock.placeholder.record:alert.icon`}},{name:`dismissible`,label:`engine.inspector.pageBlock.field.record:alert.dismissible`,kind:`boolean`}],"record:path":[{name:`statusField`,label:`engine.inspector.pageBlock.field.record:path.statusField`,kind:`field-picker`,objectFrom:`page`},{name:`stages`,label:`engine.inspector.pageBlock.field.record:path.stages`,kind:`array`,addLabel:`engine.inspector.pageBlock.add.record:path.stages`,itemFields:[{name:`value`,label:`engine.inspector.pageBlock.field.record:path.stages.value`,kind:`text`},{name:`label`,label:`engine.inspector.pageBlock.field.record:path.stages.label`,kind:`text`}]}],"record:quick_actions":[{name:`actionNames`,label:`engine.inspector.pageBlock.field.record:quick_actions.actionNames`,kind:`string-list`,placeholder:{key:`engine.inspector.pageBlock.placeholder.record:quick_actions.actionNames`}},{name:`location`,label:`engine.inspector.pageBlock.field.record:quick_actions.location`,kind:`select`,options:[{value:`record_header`,label:`engine.inspector.pageBlock.option.location.record_header`},{value:`record_more`,label:`engine.inspector.pageBlock.option.location.record_more`},{value:`record_section`,label:`engine.inspector.pageBlock.option.location.record_section`},{value:`record_related`,label:`engine.inspector.pageBlock.option.location.record_related`},{value:`list_toolbar`,label:`engine.inspector.pageBlock.option.location.list_toolbar`},{value:`list_item`,label:`engine.inspector.pageBlock.option.location.list_item`}]}],"ai:input":[{name:`agentName`,label:`engine.inspector.pageBlock.field.ai:input.agentName`,kind:`text`,placeholder:{key:`engine.inspector.pageBlock.placeholder.ai:input.agentName`}},{name:`placeholder`,label:`engine.inspector.pageBlock.field.ai:input.placeholder`,kind:`text`}]};function zu(e){return!!e&&Array.isArray(Ru[e])&&Ru[e].length>0}function Bu(){let e=yi(),[t,n]=Y.useState([]),[r,i]=Y.useState(!0);return Y.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 Vu(e){let{fields:t}=la(e);return Y.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 Hu({label:e,value:t,onCommit:n,disabled:r,locale:i}){let{options:a}=Bu();return a.length===0?(0,X.jsx)(G,{label:e,value:t??``,placeholder:J(`engine.inspector.pageBlock.objectPlaceholder`,i),onCommit:n,disabled:r,mono:!0}):(0,X.jsx)(W,{label:e,value:t||void 0,options:a,onCommit:n,disabled:r})}function Uu({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let a=Vu(t);return!t||a.length===0?(0,X.jsx)(G,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,X.jsx)(W,{label:e,value:n||void 0,options:a,onCommit:r,disabled:i})}function Wu({label:e,objectName:t,value:n,onChange:r,disabled:i,locale:a}){let o=Vu(t),s=Array.isArray(n)?n:[];return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(I,{className:`text-xs text-muted-foreground`,children:e}),s.map((e,t)=>(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[o.length>0?(0,X.jsx)(`div`,{className:`flex-1`,children:(0,X.jsxs)(Qr,{value:e?String(e):``,onValueChange:e=>{let n=[...s];n[t]=e,r(n)},disabled:i,children:[(0,X.jsx)(Fe,{className:`h-8`,children:(0,X.jsx)(jt,{placeholder:`—`})}),(0,X.jsx)(tn,{children:o.map(e=>(0,X.jsx)(He,{value:e.value,children:e.label},e.value))})]})}):(0,X.jsx)(R,{className:`h-8 text-sm`,value:String(e??``),placeholder:J(`engine.inspector.pageBlock.fieldPlaceholder`,a),disabled:i,onChange:e=>{let n=[...s];n[t]=e.target.value,r(n)}}),(0,X.jsx)(B,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:i,"aria-label":J(`engine.inspector.pageBlock.list.remove`,a),onClick:()=>r(s.filter((e,n)=>n!==t)),children:(0,X.jsx)(_r,{className:`h-4 w-4`})})]},t)),!i&&(0,X.jsxs)(B,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>r([...s,``]),children:[(0,X.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),` `,J(`engine.inspector.pageBlock.list.add`,a)]})]})}function Gu(e){if(e===void 0)return``;try{return JSON.stringify(e,null,2)}catch{return``}}function Ku({label:e,value:t,onCommit:n,disabled:r,placeholder:i,locale:a}){let o=Y.useMemo(()=>Gu(t),[t]),[s,c]=Y.useState(o),[l,u]=Y.useState(!1);return Y.useEffect(()=>{c(o),u(!1)},[o]),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),onBlur:()=>{if(r)return;let e=s.trim();if(e===``){u(!1),n(void 0);return}try{let t=JSON.parse(e);u(!1),n(t)}catch{u(!0)}},disabled:r,placeholder:i,spellCheck:!1,rows:Math.min(12,Math.max(2,s.split(`
|
|
5
|
+
`).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`}),l&&(0,X.jsx)(`div`,{className:`text-[11px] text-destructive`,children:J(`engine.form.invalidJson`,a)})]})}function qu({name:e,value:t,onCommit:n,disabled:r,locale:i}){return typeof t==`boolean`?(0,X.jsx)(U,{label:e,value:t,onCommit:n,disabled:r}):typeof t==`number`?(0,X.jsx)(Za,{label:e,value:t,onCommit:e=>n(e),disabled:r}):t===null||typeof t==`string`?(0,X.jsx)(G,{label:e,value:t??``,onCommit:n,disabled:r,mono:!0}):(0,X.jsx)(Ku,{label:e,value:t,onCommit:n,disabled:r,locale:i})}function Ju({label:e,value:t,onChange:n,disabled:r,options:i}){let a=Y.useId();return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{id:a,className:`text-xs text-muted-foreground`,children:e}),(0,X.jsx)(ua,{ariaLabelledBy:a,value:t,onChange:n,disabled:r,options:i})]})}var Yu=new Set([`children`,`body`]),Xu=Symbol(`remove`);function Zu(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 Qu(e){let t=[];for(let n of e)t.push(n.key),n.index>=0&&t.push(n.index);return t}function $u(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===Xu?t.splice(r,1):t[r]=n:t[r]=ed(t[r],i,n),t}let a={...e||{}};return i.length===0?n===Xu?delete a[r]:a[r]=n:a[r]=ed(a[r],i,n),a}function td(e,t){return $u(e,Qu(t))}function nd(e,t,n){let r=Qu(t),i=ed(e,r,n===null?Xu:n),a=r[0];return{[a]:i[a]}}function rd(e,t){let n=Qu(t),r=n[n.length-1];if(typeof r!=`number`)return null;let i=$u(e,n.slice(0,-1));return Array.isArray(i)?{siblings:i,index:r}:null}function id(e,t,n){let r=Qu(t),i=ed(e,r.slice(0,-1),n),a=r[0];return{[a]:i[a]}}function ad({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,onBlockingIssuesChange:a,locale:o,readOnly:s}){let c=/^slot:([a-zA-Z_]+):(\d+)(?:\.(.+))?$/.exec(e.id),l=c?null:Zu(e.id),u=c?c[1]:``,d=c?Number(c[2]):-1,f=c?c[3]:void 0,p=f?Zu(f):null,m=t.slots&&typeof t.slots==`object`?t.slots:{},h=c?Array.isArray(m[u])?m[u]:m[u]==null?[]:[m[u]]:[],g=c?h[d]??null:null,_=e=>n({slots:{...m,[u]:e}}),v=e=>_(e===null?h.filter((e,t)=>t!==d):h.map((t,n)=>n===d?e:t)),y=c?p?td(g||{},p):g:l?td(t,l):null,b=c?p?rd(g||{},p):{siblings:h,index:d}:l?rd(t,l):null,[x,S]=Y.useState({block:e.id,count:0}),C=Y.useCallback(t=>{S(n=>n.block===e.id&&n.count===t?n:{block:e.id,count:t})},[e.id]),w=x.block===e.id?x.count:0,T=Y.useRef(a);if(Y.useEffect(()=>{T.current=a}),Y.useEffect(()=>{T.current?.(w)},[w]),!c&&!l||!y)return(0,X.jsx)(Ba,{kindLabel:J(`engine.inspector.pageBlock.kind`,o),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.pageBlock.close`,o),children:(0,X.jsx)(Wa,{message:e.id})});let E=e=>c?v(p?{...g,...nd(g||{},p,{...y,...e})}:{...y,...e}):n(nd(t,l,{...y,...e})),D=y.properties||{},O=typeof t?.object==`string`?t.object:void 0,k=e=>e.objectFrom===`page`?O:e.objectProp!=null&&D[e.objectProp]!=null?String(D[e.objectProp]):void 0,A=e=>D[e]??y[e],j=(e,t)=>E({properties:{...D,[e]:t}}),M=new Set((zu(y.type)?Ru[y.type]:[]).map(e=>e.name)),N=Object.keys(D).filter(e=>!M.has(e)&&!Yu.has(e)),P=e=>J(e,o),ee=e=>e.map(e=>({...e,label:J(e.label,o)})),te=e=>e===void 0?void 0:e.key===void 0?e.literal:J(e.key,o),ne=(e,t,n,r=``)=>{let i=`${r}${e.name}`;switch(e.kind){case`number`:return(0,X.jsx)(Za,{label:P(e.label),value:typeof t(e.name)==`number`?t(e.name):void 0,placeholder:te(e.placeholder),onCommit:t=>n(e.name,t),disabled:s},i);case`boolean`:return(0,X.jsx)(U,{label:P(e.label),value:!!t(e.name),onCommit:t=>n(e.name,t),disabled:s},i);case`color`:return(0,X.jsx)(Ju,{label:P(e.label),value:t(e.name)==null?void 0:String(t(e.name)),onChange:t=>n(e.name,t),disabled:s,options:e.options?ee(e.options):void 0},i);case`select`:return(0,X.jsx)(W,{label:P(e.label),value:t(e.name)==null?void 0:String(t(e.name)),options:ee(e.options),onCommit:t=>n(e.name,t),disabled:s},i);case`json`:return(0,X.jsx)(Ku,{label:P(e.label),value:t(e.name),placeholder:te(e.placeholder),locale:o,onCommit:t=>n(e.name,t),disabled:s},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)(I,{className:`text-xs text-muted-foreground`,children:P(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:te(e.placeholder),disabled:s,onChange:t=>{let a=[...r];a[i]=t.target.value,n(e.name,a)}}),(0,X.jsx)(B,{type:`button`,variant:`ghost`,size:`icon`,className:`h-8 w-8`,disabled:s,"aria-label":J(`engine.inspector.pageBlock.list.remove`,o),onClick:()=>n(e.name,r.filter((e,t)=>t!==i)),children:(0,X.jsx)(_r,{className:`h-4 w-4`})})]},i)),!s&&(0,X.jsxs)(B,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,``]),children:[(0,X.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),` `,J(`engine.inspector.pageBlock.list.add`,o)]})]},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)(I,{className:`text-xs text-muted-foreground`,children:P(e.label)}),r.map((t,a)=>{let c=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)(B,{type:`button`,variant:`ghost`,size:`icon`,className:`h-7 w-7`,disabled:s,"aria-label":J(`engine.inspector.pageBlock.list.removeItem`,o),onClick:()=>n(e.name,r.filter((e,t)=>t!==a)),children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]}),e.itemFields.map(t=>ne(t,e=>c[e],(t,i)=>{let o=[...r];o[a]={...c,[t]:i},n(e.name,o)},`${i}-${a}-`))]},a)}),!s&&(0,X.jsxs)(B,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>n(e.name,[...r,{}]),children:[(0,X.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),` `,P(e.addLabel)]})]},i)}case`object-picker`:return(0,X.jsx)(Hu,{label:P(e.label),locale:o,value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:s},i);case`field-picker`:return(0,X.jsx)(Uu,{label:P(e.label),objectName:k(e),value:t(e.name)==null?void 0:String(t(e.name)),onCommit:t=>n(e.name,t),disabled:s},i);case`field-list`:return(0,X.jsx)(Wu,{label:P(e.label),objectName:k(e),locale:o,value:t(e.name),onChange:t=>n(e.name,t),disabled:s},i);default:return(0,X.jsx)(G,{label:P(e.label),value:t(e.name)==null?``:String(t(e.name)),placeholder:te(e.placeholder),onCommit:t=>n(e.name,t),disabled:s},i)}},re=()=>{c?v(p?{...g,...nd(g||{},p,null)}:null):n(nd(t,l,null)),r()},ie=e=>e.map(e=>e.index>=0?`${e.key}[${e.index}]`:e.key).join(`.`);return(0,X.jsxs)(Ba,{kindLabel:J(`engine.inspector.pageBlock.kind`,o),title:String(y.id||y.type||e.id),onClose:r,closeLabel:J(`engine.inspector.pageBlock.close`,o),headerActions:b?(0,X.jsx)(Ga,{index:b.index,total:b.siblings.length,onMove:e=>{if(!b)return;if(c){if(p){let t=Ha(b.siblings,b.index,e);v({...g,...id(g||{},p,t)});let n=ie([...p.slice(0,-1),{key:p[p.length-1].key,index:e}]);i?.({kind:`block`,id:`slot:${u}:${d}.${n}`,label:String(y.id||y.type||e)})}else _(Ha(h,d,e)),i?.({kind:`block`,id:`slot:${u}:${e}`,label:String(y.id||y.type||e)});return}let r=Ha(b.siblings,b.index,e);n(id(t,l,r));let a=ie([...l.slice(0,-1),{key:l[l.length-1].key,index:e}]);i?.({kind:`block`,id:a,label:String(y.id||y.type||a)})},upLabel:J(`engine.inspector.reorder.up`,o),downLabel:J(`engine.inspector.reorder.down`,o),disabled:s}):void 0,footer:(0,X.jsx)(Ja,{label:J(`engine.inspector.pageBlock.remove`,o),onClick:re,disabled:s}),children:[(0,X.jsx)(G,{label:J(`engine.inspector.pageBlock.type`,o),value:y.type??``,onCommit:e=>E({type:e}),disabled:s,mono:!0}),(0,X.jsx)(G,{label:J(`engine.inspector.pageBlock.id`,o),value:y.id??``,onCommit:e=>E({id:e}),disabled:s,mono:!0}),(0,X.jsx)(G,{label:J(`engine.inspector.pageBlock.className`,o),value:y.className??``,onCommit:e=>E({className:e}),disabled:s,mono:!0}),(0,X.jsx)(da,{label:J(`engine.inspector.pageBlock.visibleWhen`,o),value:Sa(y.visibleWhen),onCommit:e=>E({visibleWhen:Ca(y.visibleWhen,e)}),objectName:O,disabled:s,onBlockingIssuesChange:C}),zu(y.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:J(`engine.inspector.pageBlock.properties`,o)}),Ru[y.type].map(e=>ne(e,A,j))]}),N.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:J(`engine.inspector.pageBlock.advanced`,o)}),N.map(e=>(0,X.jsx)(qu,{name:e,value:D[e],onCommit:t=>j(e,t),disabled:s,locale:o},e))]})]})}var od=new Set([`simple`,`tabbed`,`wizard`,`split`]),sd=new Set([`drawer`,`modal`]);function cd(e){return typeof e==`string`&&sd.has(e)}function ld(e){return typeof e==`string`&&od.has(e)?e:`simple`}function ud(e){let t={...e,type:String(e?.type??``)},n=t.properties&&typeof t.properties==`object`?t.properties:void 0;return cd(n?.formType??t.formType)&&(n&&(t.properties={...n,formType:`simple`}),`formType`in t&&(t.formType=`simple`)),t}function dd(e=`300px`){let t=Y.useRef(null),[n,r]=Y.useState(()=>typeof IntersectionObserver>`u`);return Y.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 fd({block:e,maxHeightClass:t=`max-h-72`}){let n=String(e?.type??``),{ref:r,inView:i}=dd();return(0,X.jsx)(`div`,{ref:r,className:V(`pointer-events-none select-none overflow-hidden p-3`,t),children:i?(0,X.jsx)(Q,{fallbackHint:`"${n}" can't render with its current configuration — check its Properties.`,children:(0,X.jsx)(P,{children:(0,X.jsx)(re,{schema:ud(e)})})}):(0,X.jsx)(`div`,{className:`min-h-[64px] animate-pulse rounded bg-muted/40`,"aria-hidden":`true`})})}var pd={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 md(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 hd=[`header`,`actions`,`alerts`,`highlights`,`details`,`tabs`,`discussion`];function gd(e){let t=e||{};return hd.map(e=>{let n=t[e];return{name:e,components:Array.isArray(n)?n:n==null?[]:[n]}})}function _d(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 vd(e){let t=e.slots;if(e.kind===`slotted`&&t&&typeof t==`object`&&!Array.isArray(t))return{regions:gd(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 yd(e,t,n,r){return e===`children`?`children[${n}]`:e===`slots`?`slot:${r}:${n}`:`regions[${t}].components[${n}]`}function bd(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 xd=`text/x-objectui-pageblock`;function Sd({draft:e,onPatch:t,selection:n,onSelectionChange:r}){let i=!t,{regions:a,shape:o}=Y.useMemo(()=>vd(e),[e]),s=n?.kind===`block`?String(n.id):null,c=Y.useCallback(e=>{if(o===`children`){let n=e.flatMap(e=>Array.isArray(e.components)?e.components:[]);t?.({children:n})}else o===`slots`?t?.({slots:_d(e)}):t?.({regions:e})},[t,o]),l=Y.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=yd(o,n.region,d,i[n.region]?.name);r?.({kind:`block`,id:f,label:bd(l)})},[t,r,a,c,o]),u=Y.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:yd(o,e,l,i[e]?.name),label:bd(s)})},[t,r,a,c,o]),d=Y.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=Y.useCallback(()=>{if(!t)return;let e=[...a,{name:`region_${a.length+1}`,components:[]}];c(e)},[t,a,c]),p=Y.useCallback((n,i,a)=>{if(!t)return;let o=/^slot:([a-zA-Z_]+):(\d+)$/.exec(n),s=Zu(i);if(!s)return;let c=Qu(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=$u(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=Zu(`${n}.${i}`);if(!o)return;let s=Qu(o),c=$u(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=Y.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)(B,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,onClick:f,children:[(0,X.jsx)(L,{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)(Cd,{region:e,regionIdx:t,shape:o,selectedId:s,readOnly:i,onSelectBlock:(n,i)=>r?.({kind:`block`,id:yd(o,t,n,e.name),label:bd(i)}),onMoveBlock:l,onAddBlock:u,onRenameLabel:d,baseIdOf:n=>yd(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)(B,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground`,onClick:f,children:[(0,X.jsx)(L,{className:`h-3.5 w-3.5`}),`Add region`]})})]})})}function Cd({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]=Y.useState(!1);return(0,X.jsxs)(`section`,{className:V(`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(xd)||(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(xd);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=yd(n,t,d,e.name);return(0,X.jsxs)(Y.Fragment,{children:[(0,X.jsx)(wd,{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)(Td,{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)(Ed,{onPick:e=>s(t,e)})})]})]})}function wd({block:e,regionIdx:t,compIdx:n,selected:r,readOnly:i,onClick:a,onMoveBlock:o,onRenameLabel:s}){let c=String(e.type??``),l=Iu(c)?.Icon??Pu,u=Lu(c),d=bd(e),f=!i,[p,m]=Y.useState(null),h=e=>{e.dataTransfer.setData(xd,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(xd))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(xd);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]=Y.useState(!1),[x,S]=Y.useState(d);Y.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=md(e).length>0;return(0,X.jsxs)(`div`,{className:V(`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:V(`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:V(`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)(mt,{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:V(`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:V(`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)(z,{variant:`outline`,className:V(`text-[10px] shrink-0 font-mono`,u.badge),children:c})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(fd,{block:e}),(0,X.jsx)(`button`,{type:`button`,onClick:a,draggable:f,onDragStart:h,"aria-label":`Select ${d}`,"aria-pressed":r,className:V(`absolute inset-0 z-10 rounded-md`,i&&`cursor-default`,f&&`cursor-grab active:cursor-grabbing`)}),(0,X.jsxs)(`div`,{className:V(`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)(mt,{className:`h-3.5 w-3.5 text-muted-foreground/60`,"aria-hidden":`true`}),(0,X.jsx)(z,{variant:`outline`,className:V(`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 Td({block:e,baseId:t,selectedId:n,readOnly:r,onSelectId:i,onAddNested:a}){let o=md(e);if(o.length===0)return null;let s=pd[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:V(`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:V(`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)(fd,{block:r,maxHeightClass:`max-h-56`}),(0,X.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),i(o,bd(r))},"aria-label":`Select ${bd(r)}`,"aria-pressed":c,className:`absolute inset-0 z-10 rounded-md cursor-pointer`}),(0,X.jsx)(`div`,{className:V(`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)(z,{variant:`outline`,className:V(`text-[10px] font-mono shadow-sm bg-background/90 backdrop-blur`,Lu(s).badge),children:s})})]},a)})}),!r&&(0,X.jsx)(Ed,{onPick:n=>a(t,e.pathSuffix,n)})]},o))})}function Ed({onPick:e}){let[t,n]=Y.useState(!1),[r,i]=Y.useState(``),a=r.trim().toLowerCase(),o=Y.useMemo(()=>a?Nu.map(e=>({category:e.category,types:e.types.filter(e=>{let t=Au[e];return e.includes(a)||t.label.toLowerCase().includes(a)})})).filter(e=>e.types.length>0):Nu,[a]);return(0,X.jsxs)(Dt,{open:t,onOpenChange:e=>{n(e),e||i(``)},children:[(0,X.jsx)(Ke,{asChild:!0,children:(0,X.jsxs)(B,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,X.jsx)(L,{className:`h-3.5 w-3.5`}),`Add block`]})}),(0,X.jsxs)(Lt,{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:Mu[t.category]}),t.types.map(t=>{let r=Au[t],a=r.Icon,o=Lu(t);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:V(`h-3.5 w-3.5 shrink-0`,o.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 Dd({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a}){let o=Y.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=Y.useMemo(()=>Array.isArray(e.regions)?`regions`:`children`,[e]),f=Y.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=Y.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]=Y.useState([]),[_,v]=Y.useState(null),[y,b]=Y.useState(null);Y.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=se(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=Y.useMemo(()=>h.length?h.find(e=>String(x(e))===String(y))??h[0]:null,[h,y]),w=e?.kind===`slotted`,T=Y.useMemo(()=>{if(!w)return o;try{let t=e?.slots??{};return za(_??void 0,{slots:t})}catch{return o}},[w,o,e,_]),E=e=>!m||!C?e:(0,X.jsxs)(A,{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)(Z,{hint:`page · interface`,children:(0,X.jsx)(Q,{fallbackHint:`The interface page references a source object/view that isn't available.`,children:(0,X.jsx)(Zi,{page:e,onConfigChange:c?t=>i({interfaceConfig:{...e.interfaceConfig||{},...t}}):void 0})})});let D=e.kind;return D===`react`||D===`html`?(0,X.jsx)(ku,{draft:e,onPatch:c?i:void 0,readOnly:!c}):!o||Object.keys(o).length<=1?(0,X.jsxs)(Z,{hint:`page${s?` · design`:``}`,children:[s&&d===`regions`?(0,X.jsx)(Sd,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}):s?(0,X.jsx)(Eu,{title:J(`engine.inspector.pageBlock.outlineLabel`,a),entries:f,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?p:void 0,addLabel:J(`engine.inspector.add.block`,a)}):null,!s&&(0,X.jsx)(wu,{children:`Add components to the page to see a preview.`})]}):s&&d===`regions`?(0,X.jsx)(Z,{hint:`page · design`,children:E((0,X.jsx)(Sd,{draft:e,onPatch:c?i:void 0,selection:n??null,onSelectionChange:r}))}):(0,X.jsx)(Z,{hint:`page${s?` · design`:``}`,children:(0,X.jsxs)(Q,{fallbackHint:`The Page schema is incomplete or references a component that hasn't been registered yet.`,children:[s&&(0,X.jsx)(Eu,{title:J(`engine.inspector.pageBlock.outlineLabel`,a),entries:f,selectedId:l,onSelect:e=>r?.({kind:`block`,id:e.id,label:e.label}),onAdd:c?p:void 0,addLabel:J(`engine.inspector.add.block`,a)}),E((0,X.jsx)(`div`,{className:`min-h-[200px] max-h-[70vh] overflow-auto p-4`,children:(0,X.jsx)(re,{schema:T})}))]})})}function Od(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 kd(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 Ad(e,t){return{type:`object-form`,objectName:e,mode:`create`,formType:ld(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(kd):[]})):void 0,fields:Array.isArray(t.fields)?t.fields:void 0,showSubmit:!1,showCancel:!1}}function jd({name:e,draft:t,editing:n}){let r=Y.useMemo(()=>pc(t)?.schema,[t]),i=Y.useMemo(()=>Od(t,r),[t,r]),a=!!n,{listViews:o,defaultViewId:s,defaultViewType:c}=Y.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=Y.useMemo(()=>({type:`object-view`,objectName:i,defaultViewType:c,defaultListView:s,listViews:o,showSearch:!0,showFilters:!0,showCreate:!1,showViewSwitcher:!0}),[i,c,s,o]);if(!r&&t.type){let e={...t};return(0,X.jsx)(Z,{hint:`view · ${e.type}${a?` · design`:``}`,children:(0,X.jsx)(Q,{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)(P,{children:(0,X.jsx)(re,{schema:e})})})})})}if(!i)return(0,X.jsx)(Z,{hint:`view${a?` · design`:``}`,children:(0,X.jsxs)(wu,{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=Ad(i,r);return(0,X.jsx)(Z,{hint:`view · ${e} · form${a?` · design`:``}`,children:(0,X.jsx)(Q,{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)(P,{children:(0,X.jsx)(re,{schema:t})})})})})}return(0,X.jsx)(Z,{hint:`view · ${c}${a?` · design`:``}`,children:(0,X.jsx)(Q,{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)(P,{children:(0,X.jsx)(re,{schema:l})})})})})}var Md={metric:{id:`metric`,label:`Metric (KPI)`,category:`kpi`,icon:Qe},bar:{id:`bar`,label:`Bar chart`,category:`chart`,icon:Kt},"horizontal-bar":{id:`horizontal-bar`,label:`Horizontal bar`,category:`chart`,icon:ri},line:{id:`line`,label:`Line chart`,category:`chart`,icon:Oe},area:{id:`area`,label:`Area chart`,category:`chart`,icon:Be},pie:{id:`pie`,label:`Pie chart`,category:`chart`,icon:si},donut:{id:`donut`,label:`Donut chart`,category:`chart`,icon:or},scatter:{id:`scatter`,label:`Scatter plot`,category:`chart`,icon:Kr},funnel:{id:`funnel`,label:`Funnel`,category:`chart`,icon:ii},table:{id:`table`,label:`Data table`,category:`data`,icon:Et},pivot:{id:`pivot`,label:`Pivot table`,category:`data`,icon:wt}},Nd={kpi:`Single value`,chart:`Charts`,data:`Tabular`},Pd=[`kpi`,`chart`,`data`].map(e=>({category:e,types:Object.values(Md).filter(t=>t.category===e)})),Fd=Mr;function Id({onAdd:e,label:t=`Add widget`}){let[n,r]=Y.useState(!1),[i,a]=Y.useState(``),o=Y.useRef(null),s=Y.useMemo(()=>{let e=i.trim().toLowerCase();return e?Pd.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):Pd},[i]);return(0,X.jsxs)(Dt,{open:n,onOpenChange:e=>{r(e),e||a(``)},children:[(0,X.jsx)(Ke,{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)(L,{className:`h-3 w-3`}),t]})}),(0,X.jsxs)(Lt,{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)(Dn,{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:Nd[t.category]}),t.types.map(t=>{let n=Md[t.id]?.icon??Fd;return(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)(n,{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 Ld=Y.lazy(()=>t(()=>import(`./plugin-dashboard-d1o52lHr.js`).then(e=>e.t).then(e=>({default:e.DashboardRenderer})),__vite__mapDeps([0,1]),import.meta.url));function Rd({draft:e,editing:t,onPatch:n,selection:r,onSelectionChange:i,locale:a}){let o=F(),s=Array.isArray(e.widgets)?e.widgets:[],c=!!(t&&i),l=c&&!!n,u=r&&r.kind===`widget`?r.id:null,d=Y.useCallback(e=>{if(!i)return;if(!e){i(null);return}let t=s.find(t=>t?.id===e);i({kind:`widget`,id:e,label:p(t?.title,a)||e})},[i,s,a]),f=Y.useCallback(e=>{n&&n({widgets:e})},[n]),m=Y.useCallback(e=>{if(!l)return;let t=Ss(`widget`,s.map(e=>e?.id).filter(Boolean)),r=Md[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`,o={id:t,type:e,title:a,...r?.defaults??{}};n({widgets:no(s,o)}),i?.({kind:`widget`,id:t,label:a})},[l,s,n,i]),h=Y.useCallback((e,t)=>{if(!l)return;let r=t.trim();n({widgets:s.map(t=>t?.id===e?{...t,title:r}:t)}),i?.({kind:`widget`,id:e,label:r||e})},[l,s,n,i]),g=u?s.find(e=>e?.id===u)??null:null,_=l?(0,X.jsx)(Id,{onAdd:m,label:J(`engine.inspector.add.widget`,a)}):null;return s.length===0?(0,X.jsx)(Z,{hint:`dashboard${c?` · design`:``}`,toolbar:_,children:(0,X.jsx)(wu,{children:`Add at least one widget to see a preview.`})}):(0,X.jsx)(Z,{hint:`dashboard · ${s.length} widget${s.length===1?``:`s`}${c?` · design`:``}`,toolbar:_,children:(0,X.jsxs)(Q,{fallbackHint:`A widget references an object or field that doesn't resolve.`,children:[l&&g?(0,X.jsx)(zd,{widget:g,onRename:e=>h(g.id,e),onClose:()=>i?.(null)}):null,(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground flex items-center gap-2`,children:[(0,X.jsx)(H,{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)(Ld,{schema:e,dataSource:o,designMode:c,selectedWidgetId:u,onWidgetClick:c?d:void 0,onWidgetsReorder:c&&n?f:void 0,hideHeaderText:!0})})})})]})})}function zd({widget:e,onRename:t,onClose:n}){let r=e.title??e.id??``,[i,a]=Y.useState(!1),[o,s]=Y.useState(r),c=Y.useRef(null);Y.useEffect(()=>{s(r),a(!1)},[e.id,r]),Y.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=Md[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)(Hn,{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)(Ft,{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)(_r,{className:`h-3.5 w-3.5`})})]})}var Bd=Y.lazy(()=>t(()=>import(`./plugin-report-CelulaB7.js`).then(e=>e.t).then(e=>({default:e.ReportRenderer})),__vite__mapDeps([0]),import.meta.url));function Vd({draft:e}){let t=F(),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):[],a=i?`report · joined · ${n.blocks.length} block${n.blocks.length===1?``:`s`}`:`report · dataset "${n.dataset}"${r.length?` · by `+r.join(`, `):``}`;return(0,X.jsx)(Z,{hint:a,children:(0,X.jsx)(Q,{fallbackHint:`The Report references a dataset/measure that doesn't resolve, or its config is incomplete.`,children:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-4 text-xs text-muted-foreground`,children:[(0,X.jsx)(H,{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)(Bd,{schema:e,dataSource:t})})})})})}let a=n.type===`joined`;return(0,X.jsx)(Z,{children:(0,X.jsx)(Tu,{icon:(0,X.jsx)(wt,{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 Hd=`text/x-objectui-nav`;function Ud(e){return typeof e.type==`string`&&e.type?e.type:`untyped`}function Wd(e){switch(e){case`object`:return wt;case`page`:return Wr;case`dashboard`:return Mt;case`report`:return $t;case`url`:return $r;case`group`:return Br;case`action`:return ge;case`component`:return De;case`separator`:return $n;default:return at}}var Gd={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`},url:{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`},action:{icon:`text-rose-500`,badge:`border-rose-200 bg-rose-50 text-rose-700 dark:border-rose-900 dark:bg-rose-950/40 dark:text-rose-300`},component:{icon:`text-cyan-500`,badge:`border-cyan-200 bg-cyan-50 text-cyan-700 dark:border-cyan-900 dark:bg-cyan-950/40 dark:text-cyan-300`},separator:{icon:`text-zinc-400`,badge:`border-zinc-200 bg-zinc-50 text-zinc-500 dark:border-zinc-800 dark:bg-zinc-900/40 dark:text-zinc-400`},untyped:{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`}};function Kd(e){return Gd[e]??Gd.untyped}function qd(e,t){let n=e.label;return typeof n==`string`&&n.trim()?n.trim():`Item ${t+1}`}function Jd(e){let t=e=>typeof e==`string`&&e?e:void 0;switch(e.type){case`object`:return t(e.objectName);case`page`:return t(e.pageName);case`dashboard`:return t(e.dashboardName);case`report`:return t(e.reportName);case`url`:return t(e.url);case`component`:return t(e.componentRef);case`action`:return t(e.actionDef?.actionName);default:return}}function Yd({draft:e,rootKey:t,onPatch:n,selection:r,onSelectionChange:i}){let a=oo(),o=Y.useMemo(()=>{let n=e[t];return Array.isArray(n)?n:[]},[e,t]),s=r&&r.kind===`nav`?r.id:null,[c,l]=Y.useState(null),u=Y.useCallback(e=>{n&&n({[t]:e})},[n,t]),d=Y.useCallback(()=>{if(!n)return;let e=J(`engine.appNav.newItem`,a),r=new Set(o.map(e=>typeof e.id==`string`?e.id:``).filter(Boolean)),s=`nav_item_${o.length+1}`;for(let e=o.length+2;r.has(s);e++)s=`nav_item_${e}`;let c=no(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=Y.useCallback(e=>{if(!n)return;let r=K(o,e,null);u(r),s===`${t}[${e}]`&&i?.(null)},[n,o,u,t,s,i]),p=Y.useCallback((e,r)=>{if(!n)return;let a={...o[e]??{},label:r},c=K(o,e,a);u(c),s===`${t}[${e}]`&&i?.({kind:`nav`,id:`${t}[${e}]`,label:r})},[n,o,u,t,s,i]),m=Y.useCallback((e,r)=>{if(!n)return;let a=r;if(e<r&&(a=r-1),a===e)return;let s=Ha(o,e,a);u(s),i?.({kind:`nav`,id:`${t}[${a}]`,label:qd(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:J(`engine.appNav.heading`,a)}),(0,X.jsxs)(z,{variant:`outline`,className:`text-[10px]`,children:[o.length,` `,o.length===1?J(`engine.appNav.itemOne`,a):J(`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)(L,{className:`h-3 w-3`}),` `,J(`engine.appNav.addItem`,a)]})]}),(0,X.jsx)(`div`,{className:`space-y-1.5 p-2`,onDragOver:e=>{n&&e.dataTransfer.types.includes(Hd)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`)},onDrop:e=>{n&&e.dataTransfer.types.includes(Hd)&&(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:J(n?`engine.appNav.empty`:`engine.appNav.emptyReadonly`,a)}):o.map((e,r)=>(0,X.jsx)(Xd,{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 Xd({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)(Zd,{item:e,index:t,depth:n,path:r,isSelected:i===r,canEdit:a&&n===0,onClick:()=>o(r,qd(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)(Xd,{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 Zd({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=oo(),p=Ud(e),m=Wd(p),h=Kd(p),g=Jd(e),[_,v]=Y.useState(!1),[y,b]=Y.useState(qd(e,t)),[x,S]=Y.useState(!1),[C,w]=Y.useState(null);return Y.useEffect(()=>{_||b(qd(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(Hd,r),l())},onDragEnd:u,onDragOver:e=>{a&&e.dataTransfer.types.includes(Hd)&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,w(`before`))},onDragLeave:()=>w(null),onDrop:e=>{a&&e.dataTransfer.types.includes(Hd)&&(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)(mt,{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:V(`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!==qd(e,t)&&s(n)},onKeyDown:n=>{n.key===`Enter`?(n.preventDefault(),n.target.blur()):n.key===`Escape`&&(n.preventDefault(),b(qd(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:qd(e,t)}),(0,X.jsx)(z,{variant:`outline`,className:V(`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":J(`engine.appNav.removeItem`,f),children:(0,X.jsx)(qt,{className:`h-3 w-3`})})]})]})}var Qd=[`object`,`dashboard`,`page`,`url`,`report`,`action`,`component`,`group`,`separator`];function $d(e,t){switch(t){case`object`:return typeof e.objectName==`string`?e.objectName:void 0;case`dashboard`:return typeof e.dashboardName==`string`?e.dashboardName:void 0;case`page`:return typeof e.pageName==`string`?e.pageName:void 0;case`report`:return typeof e.reportName==`string`?e.reportName:void 0;case`url`:return typeof e.url==`string`?e.url:void 0;case`component`:return typeof e.componentRef==`string`?e.componentRef:void 0;case`action`:{let t=e.actionDef;return t&&typeof t.actionName==`string`?t.actionName:void 0}default:return}}function ef(e,t){return Array.isArray(e)?e.map(e=>{if(!e||typeof e!=`object`)return null;let n=typeof e.type==`string`&&Qd.includes(e.type)?e.type:void 0;if(n===`separator`)return{id:typeof e.id==`string`?e.id:void 0,label:``,kind:n};let r=typeof e.label==`string`?e.label.trim():``;if(!r&&!e.children)return null;let i=$d(e,n),a,o=!1;if(n&&t)try{let n=Yi(e,`/apps/${encodeURIComponent(t)}`);n.href&&n.href!==`#`&&(a=n.href,o=n.external)}catch{a=void 0}let s=Array.isArray(e.children)?ef(e.children,t):void 0;return{id:typeof e.id==`string`?e.id:void 0,label:r||`(unnamed)`,kind:n,target:i,href:a,external:o,children:s}}).filter(e=>e!==null):[]}function tf(e){switch(e){case`object`:return wt;case`page`:return Wr;case`dashboard`:return Mt;case`report`:return $t;case`url`:return $r;case`group`:return Br;case`action`:return ge;case`component`:return De;case`separator`:return $n;default:return at}}function nf(e){for(let t of e){if(t.kind===`group`){let e=t.children?nf(t.children):void 0;if(e)return e;continue}if(t.kind!==`url`&&t.kind!==`separator`&&t.kind!==`action`&&t.href)return t}}function rf({name:e,draft:t,editing:n,selection:r,onSelectionChange:i,onPatch:a}){let o=String(t.name??e??``),s=t.label??o,{rootKey:c,navItems:l}=Y.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:ef(n,o)};return{rootKey:null,navItems:[]}},[t,o]),u=Y.useMemo(()=>nf(l),[l]),d=c??`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)(Z,{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)(ti,{className:`h-3 w-3`})]}),children:(0,X.jsx)(Q,{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.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1`,children:u?(0,X.jsxs)(X.Fragment,{children:[`Home: opens the first navigation item`,(0,X.jsxs)(`span`,{className:`ml-1.5`,children:[`→ `,u.label]})]}):(0,X.jsx)(X.Fragment,{children:`Home: no navigation item yields a route yet`})})]}),f?(0,X.jsx)(Yd,{draft:t,rootKey:d,onPatch:p?a:void 0,selection:r??null,onSelectionChange:i}):l.length===0?(0,X.jsxs)(wu,{children:[`No top-level nav items. Add `,(0,X.jsx)(`code`,{children:`navigation`}),` entries in the Form tab to populate the app's navigation.`]}):(0,X.jsx)(`div`,{className:`border rounded divide-y`,children:l.map((e,t)=>(0,X.jsx)(af,{item:e,depth:0,path:`${c}[${t}]`,onSelect:h,selectedId:m},t))})]})})})}function af({item:e,depth:t,path:n,onSelect:r,selectedId:i}){let a=tf(e.kind),o=e.href;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 ${r?`cursor-pointer`:``} ${i===n?`bg-primary/5 ring-1 ring-primary`:``}`,style:{paddingLeft:`${12+t*16}px`},onClick:r?t=>{t.stopPropagation(),r(n,e)}:void 0,children:[(0,X.jsx)(a,{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}):(0,X.jsx)(`span`,{className:`text-[10px] uppercase tracking-wider text-amber-700`,title:"Every navigation item needs a `type` discriminator — this entry will be rejected on save.",children:`no type`}),e.target&&(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground truncate`,children:e.target}),o&&(0,X.jsxs)(`a`,{href:o,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:[o,` `,(0,X.jsx)(ti,{className:`h-3 w-3`})]})]}),e.children?.map((e,a)=>(0,X.jsx)(af,{item:e,depth:t+1,path:`${n}.children[${a}]`,onSelect:r,selectedId:i},a))]})}function of(e){let{type:t,locale:n}=e;switch(t){case`text`:case`password`:return(0,X.jsx)(sf,{...e,icon:t===`password`?(0,X.jsx)(En,{className:`h-3.5 w-3.5`}):void 0});case`email`:return(0,X.jsx)(sf,{...e,icon:(0,X.jsx)(Ye,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`name@example.com`});case`url`:return(0,X.jsx)(sf,{...e,icon:(0,X.jsx)(ct,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`https://…`});case`phone`:return(0,X.jsx)(sf,{...e,icon:(0,X.jsx)(bt,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`+1 555 …`});case`number`:case`currency`:case`percent`:case`autonumber`:return(0,X.jsx)(sf,{...e,icon:(0,X.jsx)(Qe,{className:`h-3.5 w-3.5`}),placeholder:e.placeholder??`0`});case`date`:case`datetime`:return(0,X.jsx)(sf,{...e,icon:(0,X.jsx)(Pe,{className:`h-3.5 w-3.5`}),placeholder:J(`designer.stub.pickDate`,n)});case`time`:return(0,X.jsx)(sf,{...e,icon:(0,X.jsx)(sn,{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)(cf,{...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)(xn,{disabled:!0}),(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.placeholder??J(`designer.stub.off`,n)})]});case`select`:case`radio`:return(0,X.jsx)(lf,{...e,single:!0});case`multiselect`:case`checkboxes`:case`tags`:return(0,X.jsx)(lf,{...e,single:!1});case`lookup`:case`master_detail`:case`tree`:return(0,X.jsx)(uf,{...e});case`image`:case`avatar`:return(0,X.jsx)(df,{icon:(0,X.jsx)(mi,{className:`h-4 w-4`}),label:J(t===`avatar`?`designer.stub.uploadAvatar`:`designer.stub.uploadImage`,n)});case`file`:case`video`:case`audio`:case`signature`:return(0,X.jsx)(df,{icon:(0,X.jsx)(nt,{className:`h-4 w-4`}),label:q(`designer.stub.upload`,n,{type:t})});case`qrcode`:return(0,X.jsx)(df,{icon:(0,X.jsx)(nt,{className:`h-4 w-4`}),label:J(`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)(dt,{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)(Ut,{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)(sf,{...e,icon:(0,X.jsx)(wr,{className:`h-3.5 w-3.5`}),placeholder:J(`designer.stub.latLng`,n)});case`address`:return(0,X.jsx)(cf,{...e,placeholder:e.placeholder??`Street
|
|
6
|
+
City, State ZIP
|
|
7
|
+
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}`:`ƒ ${J(`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:J(`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:J(`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)(z,{variant:`outline`,className:`text-[10px]`,children:t})]})}}function sf({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 cf({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 lf({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||J(`designer.stub.select`,r)}),(0,X.jsx)(Jn,{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||J(`designer.stub.pickMulti`,r)}):a.map((e,t)=>(0,X.jsx)(z,{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 uf({referenceTo:e,placeholder:t,locale:n}){let r=e?qa.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)(nn,{className:`h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate flex-1`,children:t||(e?q(`designer.stub.searchRef`,n,{ref:e}):J(`designer.stub.chooseRelated`,n))}),e&&(0,X.jsxs)(z,{variant:`outline`,className:`text-[10px] shrink-0`,children:[`→ `,e]}),!e&&(0,X.jsx)(Dn,{className:`h-3.5 w-3.5 shrink-0 text-amber-500`}),r&&null]})}function df({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 ff=(e,t)=>e?J(`engine.fieldType.${e.id}`,t):void 0,pf=(e,t)=>J(`engine.fieldCategory.${e}`,t);function mf({objectName:e,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o}){let s=!r,{enabled:c}=xo(),l=Y.useMemo(()=>aa(t.fields),[t]),u=Y.useMemo(()=>n?ca(n.fields,t.fields):null,[n,t]),d=u?u.counts.added+u.counts.changed+u.counts.removed:0,[f,p]=Y.useState(!1);Y.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??[]:[],_=Y.useMemo(()=>ha(t.fieldGroups),[t]),v=_.length>0,y=Y.useMemo(()=>fa(l,_,{includeEmptyDeclared:!s}),[l,_,s]),[b,x]=Y.useState({}),S=e=>e??`__ungrouped__`,C=Y.useCallback(e=>{let t=e??`__ungrouped__`;x(e=>({...e,[t]:!e[t]}))},[]),w=y.length>0&&y.every(e=>b[S(e.key)]),T=Y.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=Y.useCallback(e=>{a&&a({kind:`field`,id:e.name,label:typeof e.def.label==`string`?e.def.label:e.name})},[a]),[k,A]=Y.useState(()=>new Set),j=Y.useRef(null),M=Y.useMemo(()=>y.flatMap(e=>e.entries.map(e=>e.name)),[y]);Y.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 N=Y.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]),P=Y.useCallback(()=>A(new Set),[]),ee=Y.useCallback(()=>{if(!r||k.size===0)return;let e=l.entries.filter(e=>!k.has(e.name));r({fields:va({shape:l.shape,entries:e})}),E&&k.has(E)&&a?.(null),A(new Set)},[r,k,l,E,a]),te=Y.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:va({shape:l.shape,entries:t})})},[r,k,l]),ne=Y.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=ga(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:va({shape:l.shape,entries:d})}),a?.({kind:`field`,id:s,label:String(c.def.label??s)})},[r,a,l]),re=Y.useCallback(()=>{if(!r)return;let e=q(`designer.canvas.sectionN`,o,{n:_.length+1}),t=ra(_,e),n=t[t.length-1];r({fieldGroups:t}),x(e=>({...e,[n.key]:!1}))},[r,_,o]),ie=Y.useCallback((e,t)=>{r&&r({fieldGroups:ia(_,e,t)})},[r,_]),F=Y.useCallback(e=>{if(!r)return;let t=oa(l,e);r({fieldGroups:_a(_,e),fields:va(t)})},[r,_,l]),ae=Y.useCallback((e,t)=>{r&&r({fieldGroups:$i(_,e,t)})},[r,_]),oe=Y.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:va({shape:l.shape,entries:i})})},[r,l]),se=Y.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:va({shape:l.shape,entries:n})})},[r,l]),ce=Y.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:va({shape:l.shape,entries:n})})},[r,l]),le=Y.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:va({shape:l.shape,entries:n})})},[r,l]),ue=Y.useCallback(e=>{e.target===e.currentTarget&&E&&a?.(null)},[a,E]),de=l.entries.length===0,fe=v||y.length>1;return(0,X.jsxs)(`div`,{className:`h-full overflow-auto bg-muted/20`,onClick:ue,"data-object-name":e,children:[!s&&k.size>0&&(0,X.jsx)(gf,{count:k.size,groups:_,onMoveToGroup:te,onDelete:ee,onClear:P,locale:o}),(0,X.jsxs)(`div`,{className:`mx-auto max-w-3xl px-6 py-6 space-y-4`,onClick:ue,children:[!de&&(0,X.jsx)(hf,{fieldCount:l.entries.length,requiredCount:D,sectionCount:_.length,allCollapsed:w,onToggleAll:fe?()=>T(!w):void 0,reviewAvailable:d>0,reviewing:m,diffCounts:u?.counts,onToggleReview:()=>p(e=>!e),locale:o}),de?(0,X.jsx)(xf,{onAdd:s?void 0:ne,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)(_f,{groupKey:e.key,label:e.key===null?J(`designer.canvas.ungrouped`,o):e.label,count:e.entries.length,showHeader:fe,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=>ie(e.key,t):void 0,onRemove:e.key?()=>F(e.key):void 0,onMove:e.key?t=>ae(e.key,t):void 0,onAddField:s?void 0:t=>ne(t,e.key),onDropField:s?void 0:ce,children:[e.entries.map(e=>(0,X.jsx)(bf,{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=>N(e,t),onReorder:s?void 0:oe,onRenameLabel:s?void 0:le,onMoveOffset:s?void 0:t=>se(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:J(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:J(`designer.canvas.diffRemoved`,o)}),u.removed.map(e=>(0,X.jsx)(yf,{entry:e,locale:o},e.name))]}),!de&&!s&&(0,X.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,X.jsx)(Sf,{onPick:e=>ne(e),locale:o}),(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-muted-foreground hover:text-foreground`,onClick:re,children:[(0,X.jsx)(Pr,{className:`h-3.5 w-3.5`}),J(`designer.canvas.addSection`,o)]}),c&&(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,className:`gap-1.5 ml-auto text-primary/80 hover:text-primary`,onClick:()=>xi(),children:[(0,X.jsx)(pt,{className:`h-3.5 w-3.5`}),J(`designer.canvas.askAi`,o)]})]})]})]})}function hf({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}),` `,J(`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}),` `,J(`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}),` `,J(`designer.canvas.diffRemoved`,l),(0,X.jsx)(`span`,{className:`text-muted-foreground/40 normal-case ml-1`,children:J(`designer.canvas.reviewVsPublished`,l)})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`font-medium text-foreground/80`,children:e}),` `,J(`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}),` `,J(`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}),` `,J(`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:V(`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)(gn,{className:`h-3 w-3`}),J(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)(jn,{className:`h-3 w-3`}):(0,X.jsx)(Nn,{className:`h-3 w-3`}),J(r?`designer.canvas.expandAll`:`designer.canvas.collapseAll`,l)]})]})]})}function gf({count:e,groups:t,onMoveToGroup:n,onDelete:r,onClear:i,locale:a}){let[o,s]=Y.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:q(`designer.canvas.bulkSelected`,a,{n:e})}),(0,X.jsx)(`span`,{className:`text-muted-foreground text-[11px] hidden md:inline`,children:J(`designer.canvas.bulkHint`,a)}),(0,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-1.5`,children:[t.length>0&&(0,X.jsxs)(Dt,{open:o,onOpenChange:s,children:[(0,X.jsx)(Ke,{asChild:!0,children:(0,X.jsxs)(B,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70`,children:[(0,X.jsx)(On,{className:`h-3.5 w-3.5`}),J(`designer.canvas.bulkMoveTo`,a),(0,X.jsx)(Jn,{className:`h-3 w-3`})]})}),(0,X.jsxs)(Lt,{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:J(`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)(B,{variant:`outline`,size:`sm`,className:`h-7 gap-1.5 bg-background/70 text-destructive hover:text-destructive`,onClick:r,children:[(0,X.jsx)(qt,{className:`h-3.5 w-3.5`}),J(`designer.canvas.bulkDelete`,a)]}),(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,className:`h-7 gap-1.5`,onClick:i,children:[(0,X.jsx)(_r,{className:`h-3.5 w-3.5`}),J(`designer.canvas.bulkClear`,a)]})]})]})}function _f({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,_]=Y.useState(!1);return(0,X.jsxs)(`section`,{className:V(`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)(vf,{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 vf({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]=Y.useState(!1),[h,g]=Y.useState(e);Y.useEffect(()=>{g(e)},[e]);let _=()=>{if(!l){m(!1);return}let t=h.trim();t&&t!==e&&l(t),m(!1)},v=n?Cr:Jn;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":J(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:V(`text-[11px] font-medium uppercase tracking-wider text-muted-foreground truncate`,l&&`cursor-text hover:text-foreground`),onDoubleClick:l?()=>{g(e),m(!0)}:void 0,title:l?J(`designer.canvas.renameHint`,a):void 0,children:e}),(0,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:J(`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)(Sf,{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":J(`designer.canvas.moveSectionUp`,a),children:(0,X.jsx)(Er,{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":J(`designer.canvas.moveSectionDown`,a),children:(0,X.jsx)(_e,{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":J(`designer.canvas.removeSection`,a),title:J(`designer.canvas.removeSectionHint`,a),children:(0,X.jsx)(qt,{className:`h-3 w-3`})})]})]})}function yf({entry:e,locale:t}){let n=e.def,r=typeof n.type==`string`?n.type:`text`,i=qa[r]?.Icon,a=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:[i&&(0,X.jsx)(i,{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:a}),(0,X.jsx)(`code`,{className:`text-[10px] text-muted-foreground/60 font-mono truncate line-through`,children:e.name})]}),(0,X.jsx)(z,{className:`text-[10px] font-medium border-transparent bg-destructive/15 text-destructive shrink-0`,children:J(`designer.canvas.diffRemoved`,t)})]})})}function bf({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=qa[f],m=p?.Icon,h=Ua[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]=Y.useState(null),E=!!c,[D,O]=Y.useState(!1),[k,A]=Y.useState(g);Y.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)},N=()=>{A(g),O(!1)};return(0,X.jsxs)(`div`,{className:V(`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:V(`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)(dn,{className:`h-3.5 w-3.5 text-primary shrink-0`,"aria-hidden":`true`}),E&&!n&&(0,X.jsx)(mt,{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:V(`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(),N())},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:V(`text-sm font-medium truncate`,l&&`cursor-text`),onDoubleClick:j,title:l?J(`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)(z,{className:`text-[10px] font-medium border-transparent bg-emerald-500/15 text-emerald-700 dark:text-emerald-300`,children:J(`designer.canvas.diffAdded`,o)}),r===`changed`&&(0,X.jsx)(z,{className:`text-[10px] font-medium border-transparent bg-amber-500/15 text-amber-700 dark:text-amber-300`,title:i&&i.length?q(`designer.canvas.diffChangedKeys`,o,{keys:i.join(`, `)}):void 0,children:J(`designer.canvas.diffChanged`,o)}),(0,X.jsx)(z,{variant:`outline`,className:V(`text-[10px] font-medium`,h.badge),children:ff(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)(of,{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 xf({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:J(`designer.canvas.noFields`,t)}),(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:J(`designer.canvas.noFieldsHint`,t)}),e&&(0,X.jsxs)(`div`,{className:`pt-2 flex items-center justify-center gap-2`,children:[(0,X.jsx)(Sf,{onPick:e,locale:t}),n&&(0,X.jsxs)(B,{variant:`ghost`,size:`sm`,className:`gap-1.5 text-primary/80 hover:text-primary`,onClick:()=>xi(),children:[(0,X.jsx)(pt,{className:`h-3.5 w-3.5`}),J(`designer.canvas.askAiGenerate`,t)]})]})]})}function Sf({onPick:e,compact:t,locale:n}){let[r,i]=Y.useState(!1),[a,o]=Y.useState(``),s=a.trim().toLowerCase(),c=Y.useMemo(()=>s?to.map(e=>({category:e.category,types:e.types.filter(e=>{let t=qa[e],r=ff(t,n)??``;return e.includes(s)||t.label.toLowerCase().includes(s)||r.toLowerCase().includes(s)})})).filter(e=>e.types.length>0):to,[s,a]);return(0,X.jsxs)(Dt,{open:r,onOpenChange:e=>{i(e),e||o(``)},children:[(0,X.jsx)(Ke,{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":J(`designer.canvas.addFieldToSection`,n),title:J(`designer.canvas.addFieldToSection`,n),children:(0,X.jsx)(L,{className:`h-3 w-3`})}):(0,X.jsxs)(B,{variant:`outline`,size:`sm`,className:`gap-1.5 border-dashed`,children:[(0,X.jsx)(L,{className:`h-3.5 w-3.5`}),J(`designer.canvas.addField`,n)]})}),(0,X.jsxs)(Lt,{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:J(`designer.canvas.searchFieldType`,n),className:`h-7 w-full px-2 text-sm border rounded bg-background outline-none focus:ring-1 focus:ring-primary`})}),(0,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:J(`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:pf(t.category,n)}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-0.5`,children:t.types.map(t=>{let r=qa[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:V(`h-3.5 w-3.5 shrink-0`,Ua[r.category].icon)}),(0,X.jsx)(`span`,{className:`truncate`,children:ff(r,n)})]},t)})})]},t.category))})]})]})}function Cf({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)(Z,{hint:`object · designer`,children:(0,X.jsx)(Q,{fallbackHint:`The form designer couldn't be rendered. Check the Form tab.`,children:(0,X.jsx)(mf,{objectName:s,draft:t,baseline:n,onPatch:r,selection:i,onSelectionChange:a,locale:o})})}):(0,X.jsx)(Z,{hint:`object`,children:(0,X.jsx)(wu,{children:J(`designer.canvas.nameToStart`,o)})})}function wf(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 Tf(e,t){return t[e]??``}function Ef(e,t){return e.replace(/\{\{\s*([a-zA-Z_][\w.]*)\s*\}\}/g,(e,n)=>Tf(n,t)).replace(/\$\{\s*([a-zA-Z_][\w.]*)\s*\}/g,(e,n)=>Tf(n,t))}function Df({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=Y.useMemo(()=>{let e=new Set;for(let n of wf(t))e.add(n);for(let t of wf(i))e.add(t);for(let t of wf(a))e.add(t);return Array.from(e).sort()},[t,i,a]),[s,c]=Y.useState({}),l=Ef(t,s),u=`<!doctype html><html><head><meta charset="utf-8"><style>
|
|
8
|
+
html,body{margin:0;padding:16px;font:14px -apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;color:#111;background:#fff;}
|
|
9
|
+
a{color:#2563eb;}
|
|
10
|
+
</style></head><body>${(i?Ef(i,s):Ef(a,s).replace(/\n/g,`<br/>`))||`<p style="color:#888">(empty body)</p>`}</body></html>`;return!i&&!a&&!t?(0,X.jsx)(Z,{hint:`email_template`,children:(0,X.jsx)(wu,{children:`Fill in the subject / body in the Form tab to see a preview.`})}):(0,X.jsx)(Z,{hint:`email_template`,children:(0,X.jsx)(Q,{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)(fr,{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))})]})]})})})}var Of=212;function kf(e,t){let n=0;return e.forEach((e,r)=>{let{width:i,height:a}=La(wa(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 Af(e){return e.length===0?66:86+kf(e,Of)}function jf(e,t){let{key:n,label:r}=e;if(n===`try`)return J(`engine.flowRegion.try`,t);if(n===`catch`)return J(`engine.flowRegion.catch`,t);let i=/^branch-(\d+)$/.exec(n);if(i){let e=Number(i[1])+1;if(r===`Branch ${e}`)return q(`engine.flowRegion.branchN`,t,{n:e})}return r}function Mf({node:e,x:t,y:n,selected:r,onSelect:i}){let a=Lf(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:V(`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:V(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md`,a.chip),children:(0,X.jsx)(Rf,{type:e.type,className:V(`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:V(`text-[10px] font-semibold uppercase tracking-[0.08em]`,a.label),children:e.type})]})]})}function Nf({region:e,maxWidth:t,selectedNodeId:n,onSelectNode:r}){let i=Y.useMemo(()=>wa(e.nodes,e.edges),[e.nodes,e.edges]),{width:a,height:o}=Y.useMemo(()=>La(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=Fa(e),o=a?ma(n):Ta(n),s=a?ma(r):na(r);return(0,X.jsx)(`path`,{d:a?ka(o,s):pa(o,s),strokeDasharray:a?`5 4`:void 0,className:V(`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)(Mf,{node:e,x:t.x,y:t.y,selected:n===e.id,onSelect:r?()=>r(e):void 0},e.id):null})]})})}function Pf({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=jf(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)(Nf,{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 Ff(e){switch(e){case`start`:return nr;case`end`:return wn;case`decision`:case`branch`:case`gateway`:return tr;case`wait`:case`timer`:case`delay`:return Ve;case`boundary_event`:case`signal`:return In;case`subflow`:case`flow`:return Qn;case`create_record`:return mr;case`update_record`:return Kn;case`delete_record`:return Mn;case`get_record`:return Vn;case`http_request`:case`webhook`:return ct;case`notify`:return we;case`script`:case`script_task`:return Wt;case`screen`:case`user_task`:return Nr;case`approval`:return dr;case`connector_action`:case`service_task`:return At;case`assignment`:return cr;case`loop`:case`for_each`:return qn;case`map`:return Ae;case`parallel_gateway`:case`join_gateway`:case`parallel`:return yn;case`try_catch`:return Fn;default:return Ar}}var If={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 Lf(e){switch(e){case`start`:return If.start;case`end`:return If.end;case`decision`:case`branch`:case`gateway`:case`parallel_gateway`:case`join_gateway`:case`parallel`:return If.decision;case`wait`:case`timer`:case`delay`:return If.wait;case`boundary_event`:case`signal`:case`try_catch`:return If.signal;case`subflow`:case`flow`:return If.subflow;case`approval`:return If.approval;case`loop`:case`for_each`:case`map`:return If.loop;case`screen`:case`user_task`:return If.screen;case`assignment`:return If.assignment;case`create_record`:case`update_record`:case`delete_record`:case`get_record`:return If.record;case`http`:case`http_request`:case`notify`:case`connector_action`:case`script`:case`webhook`:case`service_task`:case`script_task`:return If.integration;default:return If.task}}function Rf({type:e,className:t}){return Y.createElement(Ff(e),{className:t,"aria-hidden":!0})}var zf=[`Data`,`Logic`,`Human`,`Integration`,`Flow`];function Bf(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 Vf=[{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 Hf(e,t){let n=Vf.find(t=>t.type===e),r=n?n.label:e.split(`_`).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `);return ao(e,t,r)}function Uf(e){switch(e){case`start`:return{};case`wait`:return{waitEventConfig:{eventType:`timer`}};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 Wf({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=Lf(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:V(`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:V(`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)(Rf,{type:n,className:V(`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:V(`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":J(_?`engine.flowCanvas.collapseRegions`:`engine.flowCanvas.expandRegions`,t),title:J(_?`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)(Cr,{className:V(`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)(Pf,{regions:g,maxWidth:Of,selected:b,onSelectNode:x,locale:t})}),d&&(0,X.jsx)(`span`,{title:d.title,"data-problem":d.level,className:V(`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)(Ir,{className:`h-3 w-3`}):(0,X.jsx)(ci,{className:`h-3 w-3`})}),s&&n!==`end`&&(0,X.jsx)(`button`,{type:`button`,title:J(`engine.flowCanvas.addConnected`,t),"aria-label":J(`engine.flowCanvas.addConnected`,t),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),m?.()},className:V(`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)(L,{className:`h-3.5 w-3.5`})}),h&&(0,X.jsx)(`button`,{type:`button`,title:J(`engine.flowCanvas.addReviseLoop`,t),"aria-label":J(`engine.flowCanvas.addReviseLoopShort`,t),onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),h()},className:V(`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)(Rt,{className:`h-3.5 w-3.5`})})]})}var Gf=`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 Kf({locale:e,items:t=Vf,onPick:n,open:r,onOpenChange:i,children:a}){let[o,s]=Y.useState(``),{recents:c,recordRecent:l}=Po(),u=Y.useRef(null),[d,f]=Y.useState(r);r!==d&&(f(r),r||s(``));let p=o.trim().toLowerCase(),m=Y.useMemo(()=>p?t.filter(t=>t.label.toLowerCase().includes(p)||(t.hint??``).toLowerCase().includes(p)||t.type.toLowerCase().includes(p)||ao(t.type,e,t.label).toLowerCase().includes(p)||(io(t.type,e,t.hint)??``).toLowerCase().includes(p)):t,[t,p,e]),h=Y.useMemo(()=>{let e=new Map;for(let t of m){let n=t.category??Bf(t.type),r=e.get(n)??[];r.push(t),e.set(n,r)}return zf.map(t=>[t,e.get(t)??[]]).filter(([,e])=>e.length>0)},[m]),g=Y.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=Lf(t.type),i=ao(t.type,e,t.label),a=io(t.type,e,t.hint);return(0,X.jsxs)(Yn,{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:V(`flex h-7 w-7 shrink-0 items-center justify-center rounded-md`,r.chip),children:(0,X.jsx)(Rf,{type:t.type,className:V(`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)(Dt,{open:r,onOpenChange:i,children:[(0,X.jsx)(Ke,{asChild:!0,children:a}),(0,X.jsx)(Lt,{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)(Ur,{shouldFilter:!1,loop:!0,className:`bg-transparent`,children:[(0,X.jsx)(pr,{ref:u,value:o,onValueChange:s,placeholder:J(`engine.flowPalette.search`,e),className:`h-9 text-[13px]`}),(0,X.jsxs)(Gn,{className:`max-h-[56vh] p-1`,children:[(0,X.jsx)(Bn,{className:`py-6 text-center text-xs text-muted-foreground`,children:J(`engine.flowPalette.empty`,e)}),g.length>0&&(0,X.jsx)(Tr,{heading:J(`engine.flowPalette.recent`,e),className:Gf,children:g.map(e=>v(e,!0))}),h.map(([t,n])=>(0,X.jsx)(Tr,{heading:J(`engine.flowPalette.category.${t.toLowerCase()}`,e),className:Gf,children:n.map(e=>v(e))},t))]})]})})]})}function qf(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??Bf(e.type)})}return[...n.values()]}function Jf(){let[e,t]=(0,Y.useState)([]),n=(0,Y.useRef)(!0);return(0,Y.useEffect)(()=>{n.current=!0;let e=new AbortController;return(async()=>{try{let r=await fetch(`${il()}/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 Yf(){let e=Jf();return(0,Y.useMemo)(()=>e.length?qf(Vf,e):Vf,[e])}function Xf(){let e=Jf();return(0,Y.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])}function Zf(e,t){let n=e.trim();if(!n)return{result:!1,error:`Empty condition.`};try{let e=new te({...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 Qf(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 $f(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:J(`engine.flowValidate.nodeMissingId`,n)});continue}o.has(e)&&r.push({level:`error`,nodeId:e,message:q(`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:q(`engine.flowValidate.edgeSourceMissing`,n,{source:e.source})}),o.has(e.target)||r.push({level:`error`,edge:{source:e.source,target:e.target},message:q(`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:J(`engine.flowValidate.startHasIncoming`,n)})):c.length>1?r.push({level:`error`,message:q(`engine.flowValidate.multipleStart`,n,{count:c.length})}):l.length===1?(u=l[0].id,i.push({level:`warning`,nodeId:u,message:J(`engine.flowValidate.noStartUsingRoot`,n)})):l.length===0?r.push({level:`error`,message:J(`engine.flowValidate.noEntry`,n)}):r.push({level:`error`,message:q(`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:q(`engine.flowValidate.decisionMultipleDefaults`,n,{id:a.id,count:o.length})}),e.length===0?i.push({level:`warning`,nodeId:a.id,message:q(`engine.flowValidate.decisionNoBranches`,n,{id:a.id})}):o.length===0&&e.every(e=>Pa(e.condition))&&i.push({level:`warning`,nodeId:a.id,message:q(`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:q(`engine.flowValidate.nodeUnreachable`,n,{id:t.id})})}let d=t.filter(e=>e.type!==`back`),f=Qf(a.filter(e=>!!e),d);return f&&r.push({level:`error`,nodeId:f[0],cycle:f,message:q(`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 ep(e,t,n,r,i={}){return{id:`${e}.${t}`,path:[e,t],label:n,kind:r,...i}}var tp=[`GET`,`POST`,`PUT`,`PATCH`,`DELETE`].map(e=>({value:e,label:e})),np={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`,{conditionBuilder:!0,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 (no {braces}), and a target node. Branches are tried in order and the first match wins. A branch whose expression is "true" is the catch-all: picking its target marks that out-edge as the default path, taken only when no other branch matched. 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:"Inert — nothing reads this. The engine only honours `condition` on a Start node (the trigger gate); on a Decision it gates nothing. Shown so a stored value is not invisible. Move the predicate to a branch above, or to the outgoing edge’s own condition, then clear this.",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:tp,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:[$(`function`,`Function`,`text`,{placeholder:`score_lead`,help:`Registered function to call — declared via defineStack({ functions }). Required: it is what this step runs.`}),$(`inputs`,`Inputs`,`keyValue`,{help:`Values passed to the function; {var} references resolve against the live flow variables.`}),$(`outputVariable`,`Output variable`,`text`,{placeholder:`aiResult`,help:`Flow variable the function's return value is bound to, for later steps.`}),$(`actionType`,`Action type (retired)`,`text`,{help:`Retired in spec 17 — "email"/"slack" never delivered anything, and any other value was just the function name. Use a notify node for messages, a Slack connector for Slack, or move the name into Function.`,showWhen:{field:`__legacy__`,equals:[]}}),$(`template`,`Template (retired)`,`text`,{help:`Retired in spec 17 — it fed a side effect that never rendered or sent a message. A notify node carries its own title/message.`,showWhen:{field:`__legacy__`,equals:[]}}),$(`recipients`,`Recipients (retired)`,`stringList`,{help:`Retired in spec 17 — these addresses were logged, never messaged. Use a notify node, whose recipients reach the messaging service.`,showWhen:{field:`__legacy__`,equals:[]}}),$(`variables`,`Template variables (retired)`,`keyValue`,{help:`Retired in spec 17 — injected into a template nothing rendered. A notify node carries structured data in payload.`,showWhen:{field:`__legacy__`,equals:[]}}),$(`script`,`Code (not executed, retired)`,`textarea`,{placeholder:`return { ok: true };`,help:`Retired in spec 17 — inline scripts were NEVER executed by the built-in runtime (no server-side sandbox). Move the logic into a registered function and name it in 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 tier`},{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`,defaultValue:`true`,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:[ep(`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`]}),ep(`waitEventConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H · P3D`,help:`ISO 8601 duration (e.g. PT1H, P3D).`,showWhen:{field:`waitEventConfig.eventType`,equals:[`timer`]},fallbackPath:[`config`,`timerDuration`]}),ep(`waitEventConfig`,`signalName`,`Signal name`,`text`,{placeholder:`contract.renewed`,showWhen:{field:`waitEventConfig.eventType`,equals:[`signal`,`webhook`]},fallbackPath:[`config`,`signalName`]})],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:[ep(`connectorConfig`,`connectorId`,`Connector`,`reference`,{ref:{kind:`connector`},placeholder:`slack · email · salesforce`}),ep(`connectorConfig`,`actionId`,`Action`,`reference`,{ref:{kind:`connector-action`,connectorSource:`connectorId`},placeholder:`sendMessage · send`}),ep(`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:[ep(`boundaryConfig`,`attachedToNodeId`,`Attached to`,`reference`,{ref:{kind:`node`},placeholder:`host node id`,help:`Host node this boundary event monitors.`}),ep(`boundaryConfig`,`eventType`,`Event type`,`select`,{options:[{value:`error`,label:`Error`},{value:`timer`,label:`Timer`},{value:`signal`,label:`Signal`},{value:`cancel`,label:`Cancel`}],defaultValue:`error`}),ep(`boundaryConfig`,`interrupting`,`Interrupting`,`boolean`,{help:`Cancel the host activity when this event fires.`}),ep(`boundaryConfig`,`errorCode`,`Error code`,`text`,{placeholder:`TIMEOUT (empty = all)`,showWhen:{field:`boundaryConfig.eventType`,equals:[`error`]}}),ep(`boundaryConfig`,`timerDuration`,`Duration`,`text`,{placeholder:`PT1H`,showWhen:{field:`boundaryConfig.eventType`,equals:[`timer`]}}),ep(`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`})]},rp={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 ip(e){return e?np[rp[e]??e]??[]:[]}function ap(e){return e.path[0]===`config`}function op(e,t){let n=ip(t);if(!e)return n;let r=e.filter(ap),i=n.filter(e=>!ap(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 sp(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 cp(e,t,n){let r=co(e,n.id)??co(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=>sp(e,r.cols[e.key]))),i}function lp(e,t,n){if(!e||!so(n))return t;let r=rp[e]??e;return t.map(t=>cp(e,r,t))}function up(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 dp(e){return e.path.length>=2&&e.path[0]===`config`?e.path[1]:void 0}function fp(e,t,n){return!e.showWhen||pp(e,t)?!0:mp(e,t,n)}function pp(e,t){let n=up(t,e);return n!=null&&n!==``}function mp(e,t,n){if(!e.showWhen)return!0;let r=n.find(t=>t.id===e.showWhen.field);if(!r)return!1;let i=up(t,r),a=i==null||i===``?r.defaultValue:i,o=typeof a==`boolean`?String(a):a;return typeof o==`string`&&e.showWhen.equals.includes(o)}function hp(e,t,n){return!e.showWhen||!pp(e,t)||mp(e,t,n)?null:n.some(t=>t.id===e.showWhen.field)?`controller-off`:`no-controller`}var gp=[`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`],_p=new Set([`record-after-create`,`record-after-update`,`record-after-write`,`record-before-write`,`record-before-update`,`record-after-delete`]),vp=new Set([`record-after-update`,`record-before-update`,`record-after-write`,`record-before-write`]);function yp(e){return Array.isArray(e)?e:[]}function bp(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function xp(e){return typeof e==`string`&&e?e:void 0}function Sp(e,t){let n=new Map;for(let e of t){let t=xp(e.source),r=xp(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 Cp(e){let t=xp(e.type),n=bp(e.config),r=xp(e.id)??``,i=xp(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(xp(n.iteratorVariable),`loop`),s(xp(n.outputVariable)),s(xp(n.idVariable)),t===`assignment`){let e=n.assignments;if(Array.isArray(e))for(let t of e){let e=bp(t);s(xp(e.variable)??xp(e.name)??xp(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 yp(n.fields))s(xp(bp(e).name));if(t===`approval`&&r){s(`${r}.decision`);for(let e of yp(n.decisionOutputs)){let t=typeof e==`string`?e:xp(bp(e).key);t&&s(`${r}.${t}`)}}return o}function wp(e){let t=new Set;return e.filter(e=>!t.has(e.token)&&(t.add(e.token),!0))}function Tp(e,t){let n=yp(e.nodes).map(bp),r=yp(e.edges),i=[];for(let t of yp(e.variables)){let e=bp(t),n=xp(e.name);if(!n)continue;let r=xp(e.type);i.push({token:n,label:n,detail:r?`variable · ${r}`:`variable`,group:`variables`})}if(!t)return{refs:wp(i)};let a=Sp(t,r),o=n.find(e=>xp(e.type)===`start`),s=xp(o?.id);for(let e of n){let n=xp(e.id);if(!(!n||n===t||!a.has(n))&&n!==s)for(let t of Cp(e))i.push(t)}if(o){let e=bp(o.config),n=xp(e.triggerType),r=xp(e.objectName),c=!!n&&_p.has(n),l=s===t||!!s&&a.has(s);if(c&&r&&l){let e=s===t,a=vp.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:wp(i),trigger:{objectName:r,fieldPrefix:e?``:`record.`,includePrevious:a}}}}return{refs:wp(i)}}function Ep(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 Dp=new Set([`true`,`false`,`null`,`in`]),Op=new Set([`env`,`request`,`context`,`user`,`now`,`today`,`self`,`data`]);function kp(e){let t=new Set;for(let n of e){let e=n.token.split(`.`)[0];e&&t.add(e)}return t}function Ap(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 jp(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))||Dp.has(e)||n.push(e)}return n}function Mp(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 jp(i)){if(a.has(e)||(a.add(e),n.has(e)||Op.has(e)||e.startsWith(`$`)))continue;let t,r=3;for(let i of n){let n=Ap(e,i,2);n<r&&(r=n,t=i)}o.push({token:e,suggestion:r<=2?t:void 0})}return o}function Np(e,t){if(e.length===1){let n=e[0];return n.suggestion?q(`engine.flowRef.unknownWithSuggestion`,t,{token:n.token,suggestion:n.suggestion}):q(`engine.flowRef.notInScope`,t,{token:n.token})}return q(`engine.flowRef.notInScopeMulti`,t,{tokens:e.map(e=>`\`${e.token}\``).join(`, `)})}var Pp=/(?:^|[^{])\{\s*([A-Za-z_$][\w.$]*)\s*\}(?!\})/;function Fp(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 Ip(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.`};Fp(n.replace(/\{\{/g,``).replace(/\}\}/g,``),`{`,`}`);let e=Pp.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=Pp.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\`).`}:Fp(n,`(`,`)`)?Fp(n,`[`,`]`)?null:{message:`Unbalanced brackets in \`${n}\`.`}:{message:`Unbalanced parentheses in \`${n}\`.`}}function Lp(e){return Array.isArray(e)?e:[]}function Rp(e){return e&&typeof e==`object`&&!Array.isArray(e)?e:{}}function zp(e){return typeof e==`string`&&e?e:void 0}function Bp(e,t,n){let r=Ip(`predicate`,e);if(r)return{level:`error`,message:r.message};if(t&&t.size>0){let r=Mp(e,`predicate`,t);if(r.length>0)return{level:`warning`,message:Np(r,n)}}return null}function Vp(e,t){let n=Lp(e.nodes).map(Rp),r=Lp(e.edges).map(Rp),i=zp(n.find(e=>zp(e.type)===`start`)?.id),a=[];for(let r of n){let n=zp(r.id),o=zp(r.type);if(!n||!o)continue;let s=n===i?null:kp(Tp(e,n).refs);for(let e of ip(o))if(e.kind===`expression`&&e.refMode!==`template`){let i=Bp(up(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 Lp(up(r,e))){let e=Rp(o),r=zp(e.label);for(let o of i){let i=Bp(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=zp(n.source),o=zp(n.target);if(!r||!o||n.isDefault===!0)continue;let s=r===i?null:kp(Tp(e,r).refs),c=Bp(n.condition,s,t);c&&a.push({target:{kind:`edge`,source:r,target:o},level:c.level,message:c.message})}return a}function Hp(e,t){return`${e}->${t}`}function Up(e,t,n){let r=e.findIndex(e=>e.source===t&&e.target===n);return r>=0?ba(e[r],r):`${t}->${n}#-1`}function Wp(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 Gp(e,t){if(e.edge){let{source:n,target:r}=e.edge;return{target:{kind:`edge`,source:n,target:r,edgeKey:Up(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:Up(t,r,i)},highlight:{nodeIds:a,edges:o}}}return e.nodeId?{target:{kind:`node`,nodeId:e.nodeId}}:{target:{kind:`flow`}}}function Kp(e,t,n){let r=Wp(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:ba(t,e)}}}return{kind:`flow`}}function qp(e){return e.kind===`node`?`n:${e.nodeId}`:e.kind===`edge`?`e:${e.source}->${e.target}`:`flow`}function Jp({nodes:e,edges:t,serverDiagnostics:n,variables:r,locale:i}){let a=[],o=$f(e,t,i),s=(e,n)=>{n.forEach((n,r)=>{let{target:i,highlight:o}=Gp(n,t);a.push({id:`structural:${e}:${r}:${qp(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=Kp(n.path,e,t);a.push({id:`server:${r}:${qp(o)}`,level:i,message:n.message,target:o,source:`server`})}),Vp({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:Up(t,e.target.source,e.target.target)}:{kind:`node`,nodeId:e.target.nodeId};a.push({id:`expression:${e.level}:${n}:${qp(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 Yp(e){return{level:e.some(e=>e.level===`error`)?`error`:`warning`,title:e.map(e=>e.message).join(`
|
|
11
|
+
`),count:e.length}}function Xp(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=Hp(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,Yp(n));let i=new Map;for(let[e,t]of n)i.set(e,Yp(t));return{byNode:r,byEdge:i}}function Zp(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(Hp(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(Hp(e.source,e.target))}return{invalidNodeIds:[...t],invalidEdges:n}}var Qp=.4,$p=1.6,em=4;function tm({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=Y.useMemo(()=>ta(e),[e]),x=Y.useRef(null),[S,C]=Y.useState(1),[w,T]=Y.useState({x:0,y:0}),[E,D]=Y.useState(!1),O=Yf(),[k,A]=Y.useState(null),j=Y.useRef(null),M=Y.useRef(null),[N,P]=Y.useState(()=>new Set),ee=Y.useCallback(e=>{let t=N.has(e);P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),t&&_?.containerId===e&&v?.(null)},[N,_,v]),te=Y.useMemo(()=>{let e=new Map;for(let t of b){let n=ea(t);n.length>0&&e.set(t.id,n)}return e},[b]),ne=Y.useMemo(()=>{let e=new Map;for(let t of b){let n=N.has(t.id)?te.get(t.id):void 0;e.set(t.id,n?Af(n):66)}return e},[b,te,N]),{positions:re,heights:ie,size:F}=Y.useMemo(()=>ya(b,t,e=>ne.get(e.id)??66),[b,t,ne]),ae=Y.useMemo(()=>new Set(c??[]),[c]),oe=Y.useMemo(()=>new Set(l??[]),[l]),se=Y.useMemo(()=>new Set(u??[]),[u]),ce=(c?.length??0)>0||!!s,{byNode:le,byEdge:ue}=Y.useMemo(()=>Xp(p??[]),[p]),de=Y.useMemo(()=>(p??[]).filter(e=>e.level===`error`),[p]),fe=Y.useCallback(e=>k&&k.id===e?{x:k.x,y:k.y}:re.get(e)??{x:0,y:0},[k,re]),pe=Y.useCallback((e,t,n)=>{if(!y)return;let r=b.findIndex(t=>t.id===e);if(r<0)return;let i={...b[r],position:{x:t,y:n}};y({nodes:K(b,r,i)})},[b,y]),me=Y.useCallback((e,n)=>{if(!y)return;let r=Ss(`node`,b.map(e=>e.id).filter(Boolean)),i=Hf(e,o),a=n?.at,s={id:r,type:e,label:i,...Uf(e),...a?{position:{x:a.x,y:a.y}}:{}},c={nodes:no(b,s)};if(n?.from){let e={id:Ss(`edge`,t.map(e=>e.id).filter(Boolean)),source:n.from,target:r},i=b.find(e=>e.id===n.from);if(i?.type===`decision`){let r=(Array.isArray(i.config?.conditions)?i.config.conditions:[])[t.filter(e=>e.source===n.from).length];if(r&&typeof r==`object`){let t=typeof r.expression==`string`?r.expression.trim():``,n=typeof r.label==`string`?r.label.trim():``;n&&(e.label=n),t===`true`?e.isDefault=!0:t&&(e.condition=t)}}c.edges=no(t,e)}y(c),h(s),D(!1)},[t,b,y,h,fe,o]),he=Y.useCallback((e,n=`create_record`)=>{if(!y)return;let r=t.findIndex(t=>t===e);if(r<0)return;let i=Ss(`node`,b.map(e=>e.id).filter(Boolean)),a=fe(e.source),s=fe(e.target),c={x:(a.x+s.x)/2,y:(a.y+s.y)/2},l={id:i,type:n,label:Hf(n,o),...Uf(n),position:{x:c.x,y:c.y}},u={...e,target:i},d={id:Ss(`edge`,[...t.map(e=>e.id).filter(Boolean),`edge`]),source:i,target:e.target},f=K(t,r,u);y({nodes:no(b,l),edges:no(f,d)}),h(l)},[t,b,y,h,fe,o]),ge=Y.useCallback(e=>{if(!y||!b.some(t=>t.id===e))return;let n=Ss(`node`,b.map(e=>e.id).filter(Boolean)),r={id:n,type:`wait`,label:J(`engine.flowCanvas.awaitingRevision`,o),waitEventConfig:{eventType:`signal`,signalName:`revision`}},i=t.map(e=>e.id).filter(Boolean),a=Ss(`edge`,i),s=Ss(`edge`,[...i,a]),c={id:a,source:e,target:n,label:`revise`},l={id:s,source:n,target:e,label:`resubmit`,type:`back`};y({nodes:no(b,r),edges:no(no(t,c),l)}),h(r)},[t,b,y,h,o]),_e=Y.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]),ve=Y.useCallback(e=>{y&&(y({nodes:b.filter(t=>t.id!==e),edges:t.filter(t=>t.source!==e&&t.target!==e)}),h(null))},[t,b,y,h]),ye=Y.useCallback(e=>t=>{if(!n||t.button!==0)return;t.stopPropagation();let r=fe(e);j.current={nodeId:e,startX:t.clientX,startY:t.clientY,originX:r.x,originY:r.y,moved:!1},t.currentTarget.setPointerCapture?.(t.pointerId)},[n,fe]),xe=Y.useCallback(e=>{let t=j.current;if(!t)return;let n=(e.clientX-t.startX)/S,r=(e.clientY-t.startY)/S;!t.moved&&Math.hypot(e.clientX-t.startX,e.clientY-t.startY)<em||(t.moved=!0,A({id:t.nodeId,x:Math.max(0,t.originX+n),y:Math.max(0,t.originY+r)}))},[S]),Se=Y.useCallback(e=>{let t=j.current;j.current=null,t&&(e.currentTarget.releasePointerCapture?.(e.pointerId),t.moved&&k&&pe(t.nodeId,Math.round(k.x),Math.round(k.y)),A(null))},[k,pe]),Ce=Y.useCallback(e=>{e.button===0&&(h(null),M.current={startX:e.clientX,startY:e.clientY,originX:w.x,originY:w.y},e.currentTarget.setPointerCapture?.(e.pointerId))},[h,w.x,w.y]),we=Y.useCallback(e=>{let t=M.current;t&&T({x:t.originX+(e.clientX-t.startX),y:t.originY+(e.clientY-t.startY)})},[]),I=Y.useCallback(e=>{M.current&&e.currentTarget.releasePointerCapture?.(e.pointerId),M.current=null},[]),Te=e=>Math.min($p,Math.max(Qp,e)),Ee=Y.useCallback(()=>{let e=x.current;if(!e)return;let t=(e.clientWidth-32)/F.width,n=(e.clientHeight-32)/F.height,r=Te(Math.min(t,n));C(r),T({x:(e.clientWidth-F.width*r)/2,y:Math.max(16,(e.clientHeight-F.height*r)/2)})},[F.height,F.width]);Y.useEffect(()=>{let e=x.current;e&&(C(1),T({x:(e.clientWidth-F.width)/2,y:Math.max(16,(e.clientHeight-F.height)/2)}))},[]),Y.useEffect(()=>{if(!m)return;let e=x.current;if(!e)return;let t=m.target,n=null;if(t.kind===`node`){let e=re.get(t.nodeId);e&&(n={x:e.x+120,y:e.y+(ie.get(t.nodeId)??66)/2})}else if(t.kind===`edge`){let e=re.get(t.source),r=re.get(t.target);e&&r&&(n=Ia(Ta(e,ie.get(t.source)??66),na(r)))}n&&T({x:e.clientWidth/2-n.x*S,y:e.clientHeight/2-n.y*S})},[m?.nonce]);let De=Y.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(),ve(i)}},[ve,n,i]);return(0,X.jsxs)(`div`,{className:`relative h-full min-h-[320px] w-full overflow-hidden`,children:[de.length>0&&(0,X.jsxs)(`div`,{className:`absolute left-2 top-2 z-30 max-w-[min(60%,420px)] space-y-1`,children:[de.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?J(`engine.flowCanvas.reveal`,o):void 0,className:V(`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)(ci,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,X.jsx)(`span`,{children:e.message})]},e.id)}),de.length>3&&(0,X.jsx)(`div`,{className:`px-2.5 text-[10px] text-destructive/80`,children:q(`engine.flowCanvas.moreErrors`,o,{count:de.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)(Kf,{locale:o,items:O,open:E,onOpenChange:D,onPick:e=>me(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)(L,{className:`h-3.5 w-3.5`}),J(`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:J(`engine.flowCanvas.zoomOut`,o),"aria-label":J(`engine.flowCanvas.zoomOut`,o),onClick:()=>C(e=>Te(e-.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,X.jsx)(Bt,{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(S*100),`%`]}),(0,X.jsx)(`button`,{type:`button`,title:J(`engine.flowCanvas.zoomIn`,o),"aria-label":J(`engine.flowCanvas.zoomIn`,o),onClick:()=>C(e=>Te(e+.15)),className:`inline-flex h-7 w-7 items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,X.jsx)(be,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`button`,{type:`button`,title:J(`engine.flowCanvas.fit`,o),"aria-label":J(`engine.flowCanvas.fit`,o),onClick:Ee,className:`inline-flex h-7 w-7 items-center justify-center border-l text-muted-foreground hover:text-foreground`,children:(0,X.jsx)(Pn,{className:`h-3.5 w-3.5`})})]})]}),(0,X.jsx)(`div`,{ref:x,tabIndex:0,role:`application`,"aria-label":J(`engine.flowCanvas.canvas`,o),onKeyDown:De,onPointerDown:Ce,onPointerMove:e=>{we(e),xe(e)},onPointerUp:e=>{I(e),Se(e)},className:V(`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*S}px ${18*S}px`,backgroundPosition:`${w.x}px ${w.y}px`},children:(0,X.jsxs)(`div`,{className:`relative origin-top-left`,style:{width:F.width,height:F.height,transform:`translate(${w.x}px, ${w.y}px) scale(${S})`},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=re.get(e.source),s=re.get(e.target);if(!i||!s)return null;let c=Fa(e),l=!c&&!!d?.has(`${e.source}->${e.target}`),u=k?.id===e.source?fe(e.source):i,f=k?.id===e.target?fe(e.target):s,p=c?ma(u):Ta(u,ie.get(e.source)??66),m=c?ma(f):na(f),h=c?ja(p,m):Ia(p,m),_=Pa(e.condition),v=e.isDefault?`else`:_?`if ${_}`:e.label,y=ba(e,t),b=ue.get(Hp(e.source,e.target)),x=oe.has(y),S=a===y,C=c?ka(p,m):pa(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:V(`fill-none transition-[stroke] duration-150`,x?`stroke-sky-500`:S?`stroke-primary`:l?`stroke-destructive`:c?`stroke-amber-500/70`:ce?`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:V(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:V(`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:V(`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)(Ir,{className:`h-3 w-3`}):(0,X.jsx)(ci,{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:J(`engine.flowCanvas.insertNode`,o),"aria-label":J(`engine.flowCanvas.insertNode`,o),onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),he(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)(L,{className:`h-3 w-3`})})})]},e.id||`${e.source}-${e.target}-${t}`)})]}),b.map(e=>{let t=s===e.id?`active`:ae.has(e.id)?`visited`:void 0;return(0,X.jsx)(Wf,{id:e.id,locale:o,type:e.type,label:e.label||e.id,summary:nm(e),position:fe(e.id),selected:i===e.id,editable:n,runState:t,dimmed:ce&&!t,onPointerDown:ye(e.id),onSelect:()=>r&&h(e),onAppend:()=>me(`create_record`,{from:e.id}),onAddReviseLoop:n&&e.type===`approval`&&!_e.has(e.id)?()=>ge(e.id):void 0,invalid:se.has(e.id),badge:le.get(e.id),regions:te.get(e.id),expanded:N.has(e.id),onToggleExpand:te.has(e.id)?()=>ee(e.id):void 0,height:ie.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 nm(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(`function`)||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 rm=`nested-node`,im=/^(.+?)::(body|try|catch|branch-\d+)::(.+)$/,am=/^branch-(\d+)$/;function om(e){return`${e.containerId}::${e.regionKey}::${e.nodeId}`}function sm(e){let t=im.exec(e);return t?{containerId:t[1],regionKey:t[2],nodeId:t[3]}:null}function cm(e){if(e===`body`||e===`try`||e===`catch`)return{kind:`key`,key:e};let t=am.exec(e);return t?{kind:`branch`,index:Number(t[1])}:null}function lm(e,t){if(e===`body`)return`Body`;if(e===`try`)return`Try`;if(e===`catch`)return`Catch`;let n=am.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 um(e){return Array.isArray(e)?e:[]}function dm(e){let t=e.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function fm(e){if(!e||typeof e!=`object`||Array.isArray(e))return null;let t=e;return Array.isArray(t.nodes)?t:null}function pm(e,t){return t.kind===`key`?fm(e[t.key]):fm((Array.isArray(e.branches)?e.branches:[])[t.index])}function mm(e,t,n,r,i,a){let o=dm(n),s=pm(o,r);if(!s||i<0||i>=s.nodes.length)return null;let c={...s,nodes:K(s.nodes,i,a)},l=r.kind===`key`?{...o,[r.key]:c}:{...o,branches:K(Array.isArray(o.branches)?o.branches:[],r.index,c)},u={...n,config:l};return{nodes:K(e,t,u)}}function hm(e,t){let n=um(e.nodes);if(t.kind===`nested-node`){let e=sm(t.id),r=e?cm(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=pm(dm(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:lm(e.regionKey,a),write:e=>mm(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:K(n,r,e)})}:null}var gm=500,_m=new Set([`start`]),vm=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`]),ym=new Set([`join_gateway`,`subflow`,`boundary_event`,`parallel`,`try_catch`]),bm=(e,t)=>e.id||`${e.source}->${e.target}#${t}`,xm=e=>typeof e==`string`&&e?e:void 0,Sm=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=$f([...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>=gm)return e.status=`error`,e.error=`Step limit (${gm}) 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(ym.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(vm.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:_m.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=Pa(e.condition);if(!t){n.push({edgeId:bm(e,a),target:e.target,result:!1,selected:!1,error:`Branch has no condition.`});continue}let o=Zf(t,this.state.variables);o.error&&!i&&(i=`${t}: ${o.error}`);let s=o.result&&!r;s&&(r={e,i:a}),n.push({edgeId:bm(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:bm(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=xm(e.config?.collection),n=xm(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=xm(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=xm(e.config?.function);if(t)return`Mocked call to '${t}' (no function executed).`;let n=xm(e.config?.actionType);return n&&n!==`code`?`Retired '${n}' action — it never delivered anything; use a notify node (or a connector for Slack).`:`Retired inline script — the runtime never executed it; move the logic into a registered function.`}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=bm(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 Cm(e,t){return e?t?e.replace(/\{([^{}]+)\}/g,(e,n)=>{let r=t[String(n).trim()];return r==null?e:String(r)}):e:``}function wm(e,t){if(typeof e!=`string`||!e.trim()||!t)return!0;let{result:n,error:r}=Zf(e.replace(/\{([\w.]+)\}/g,`$1`),t);return r?!0:n}function Tm(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||wm(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 Em(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||wm(n.visibleWhen,t)||r++}return r}function Dm(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:Tm(n.fields,t),kind:r?`object-form`:`fields`,objectName:r,mode:i,defaults:a,idVariable:typeof n.idVariable==`string`?n.idVariable:void 0}}function Om({node:e,variables:t,className:n}){let r=F(),i=D(),a=Y.useMemo(()=>Dm(e,t),[e,t]),o=Mi(a),s=o?i.objects:void 0,c=Cm(a.title,t),l=Cm(a.description,t),u=o?0:Em(e,t),d=o?`obj:${a.objectName}:${a.mode??`create`}`:`fields:`+Ni(a).map(e=>`${e.name}:${e.type??``}:${+!!e.required}`).join(`|`),f=!c&&!l&&!o&&Ni(a).length===0&&u===0;return(0,X.jsxs)(`div`,{className:V(`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:V(`whitespace-pre-line text-sm text-muted-foreground`,c&&`mt-1`),children:l}),(0,X.jsx)(km,{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&&Ni(a).length>0&&(0,X.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,X.jsx)(B,{size:`sm`,disabled:!0,children:`Submit`})})]})})]})}function km({spec:e,adapter:t,objects:n}){let[r,i]=Y.useState(()=>Ii(e));return(0,X.jsx)(Ai,{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 Am(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 jm=new Set([`create_record`,`update_record`,`delete_record`,`get_record`,`http_request`,`connector_action`,`script`]);function Mm(e){let t=[];for(let n of e){if(!jm.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 Nm={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 Pm({nodes:e,edges:t,variables:n,locale:r,onRunStateChange:i}){let a=Y.useRef(null),[o,s]=Y.useState(null),[c,l]=Y.useState(null),u=Y.useMemo(()=>n.filter(e=>e.isInput),[n]),d=Y.useMemo(()=>Mm(e),[e]),[f,p]=Y.useState({}),[m,h]=Y.useState([]),[g,_]=Y.useState({}),v=Y.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=Y.useCallback(()=>{let e={};for(let t of u){let n=f[t.name],r=n==null?void 0:Am(n);e[t.name]=r===void 0?t.defaultValue:r}for(let t of m){let n=t.k.trim();n&&(e[n]=Am(t.v))}return e},[u,f,m]),b=Y.useCallback(()=>{let e={};for(let[t,n]of Object.entries(g))n!=null&&n.trim()!==``&&(e[t]=Am(n));return e},[g]),x=Y.useCallback(()=>{let n=new Sm(e,t,r);a.current=n,l(n.reset(y(),b())),v()},[e,t,y,b,v,r]),S=Y.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=Y.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=Y.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)(B,{size:`sm`,className:`h-7 gap-1 px-2`,onClick:C,disabled:k,children:[(0,X.jsx)(nr,{className:`h-3.5 w-3.5`}),` `,J(`engine.flowSim.run`,r)]}),(0,X.jsxs)(B,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:w,disabled:k||O===`done`||O===`error`,children:[(0,X.jsx)(gt,{className:`h-3.5 w-3.5`}),` `,J(`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)(B,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2 capitalize`,onClick:()=>E(e),title:q(`engine.flowSim.resumeBranch`,r,{branch:e}),children:[(0,X.jsx)(Cr,{className:`h-3.5 w-3.5`}),` `,e]},e))}):(0,X.jsxs)(B,{size:`sm`,variant:`outline`,className:`h-7 gap-1 px-2`,onClick:T,children:[(0,X.jsx)(Cr,{className:`h-3.5 w-3.5`}),` `,J(`engine.flowSim.continue`,r)]})),(0,X.jsxs)(B,{size:`sm`,variant:`ghost`,className:`h-7 gap-1 px-2 text-muted-foreground`,onClick:D,children:[(0,X.jsx)(Rn,{className:`h-3.5 w-3.5`}),` `,J(`engine.flowSim.reset`,r)]}),(0,X.jsx)(`span`,{className:V(`ml-auto rounded px-1.5 py-0.5 text-[10px] font-semibold uppercase`,Nm[O===`idle`||O===`running`?`ok`:O]??`bg-muted`),children:J(`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)(Ir,{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)(ci,{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:J(`engine.flowSim.screen`,r)}),(0,X.jsx)(Om,{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:J(`engine.flowSim.inputs`,r)}),u.map(e=>(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(I,{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??J(`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:J(`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)(L,{className:`h-3 w-3`}),` `,J(`engine.flowSim.add`,r)]})]}),m.length===0?(0,X.jsx)(`div`,{className:`italic text-muted-foreground`,children:J(`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:J(`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:J(`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":J(`engine.flowSim.removeVariable`,r),children:(0,X.jsx)(qt,{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:J(`engine.flowSim.mockOutputs`,r)}),d.map(e=>(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(I,{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]}": … }`:J(`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:J(`engine.flowSim.variables`,r)}),Object.keys(o.variables).length===0?(0,X.jsx)(`div`,{className:`italic text-muted-foreground`,children:J(`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:J(`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:V(`ml-auto rounded px-1 py-0.5 text-[9px] font-semibold uppercase`,Nm[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:V(`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:V(`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:J(`engine.flowSim.idleHint`,r)})]})]})}function Fm(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 Im(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 Lm(e,t){let{regionKind:n,iteration:r}=e;if(!n)return null;switch(n){case`loop-body`:return r==null?J(`engine.flowRuns.iteration`,t):q(`engine.flowRuns.iterationN`,t,{n:r+1});case`parallel-branch`:return r==null?J(`engine.flowRuns.branch`,t):q(`engine.flowRuns.branchN`,t,{n:r+1});case`try`:return J(`engine.flowRuns.try`,t);case`catch`:return J(`engine.flowRuns.catch`,t);default:return r==null?n:`${n} ${r+1}`}}function Rm(e){return`${e.regionKind??``}#${e.iteration??``}`}function zm(e,t){let n=[],r;for(let i of e){let e=Rm(i.step);n.length===0||e!==r?(n.push({label:Lm(i.step,t),items:[i]}),r=e):n[n.length-1].items.push(i)}return n}async function Bm(e,t){try{let n=await fetch(`${il()}/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 Vm={completed:{icon:Zn,cls:`text-emerald-600 dark:text-emerald-400`,labelKey:`engine.flowRuns.status.completed`},failed:{icon:Ir,cls:`text-rose-600 dark:text-rose-400`,labelKey:`engine.flowRuns.status.failed`},paused:{icon:gr,cls:`text-amber-600 dark:text-amber-400`,labelKey:`engine.flowRuns.status.paused`},running:{icon:H,cls:`text-sky-600 dark:text-sky-400`,labelKey:`engine.flowRuns.status.running`},cancelled:{icon:st,cls:`text-muted-foreground`,labelKey:`engine.flowRuns.status.cancelled`}};function Hm(e,t){let n=Vm[e];return n?{icon:n.icon,cls:n.cls,label:J(n.labelKey,t)}:{icon:sn,cls:`text-muted-foreground`,label:e}}function Um(e){if(!e)return`—`;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function Wm(e){return e==null?null:e<1e3?`${e}ms`:e<6e4?`${(e/1e3).toFixed(1)}s`:`${Math.round(e/6e4)}m`}function Gm({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=Fm(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:V(`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)(ci,{"aria-hidden":!0,className:`h-2.5 w-2.5 shrink-0 text-amber-600 dark:text-amber-400`}),Wm(e.durationMs)&&(0,X.jsx)(`span`,{className:`ml-auto shrink-0 text-[9px] text-muted-foreground`,children:Wm(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)(ci,{"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 Km({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 qm({node:e,depth:t,locale:n}){let r=e.children.length>0?zm(e.children,n):[];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Gm,{step:e.step,depth:t}),r.map((e,r)=>(0,X.jsxs)(Y.Fragment,{children:[e.label!=null&&(0,X.jsx)(Km,{label:e.label,depth:t+1}),e.items.map((r,i)=>(0,X.jsx)(qm,{node:r,depth:e.label==null?t+1:t+2,locale:n},`${r.step.nodeId}#${i}`))]},r))]})}function Jm({run:e,locale:t}){let[n,r]=Y.useState(!1),i=Hm(e.status,t),a=i.icon,o=Array.isArray(e.steps)?e.steps:[],s=Fm(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)(Jn,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,X.jsx)(Cr,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),(0,X.jsx)(a,{className:V(`h-3.5 w-3.5 shrink-0`,i.cls,e.status===`running`&&`animate-spin`)}),(0,X.jsx)(`span`,{className:V(`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:Um(e.startedAt)}),Wm(e.durationMs)&&(0,X.jsx)(`span`,{className:`ml-auto shrink-0 text-[10px] text-muted-foreground`,children:Wm(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:J(`engine.flowRuns.noSteps`,t)}):(0,X.jsx)(`ul`,{children:Im(o).map((e,n)=>(0,X.jsx)(qm,{node:e,depth:0,locale:t},`${e.step.nodeId}#${n}`))})]})]})}function Ym({flowName:e,locale:t}){let[n,r]=Y.useState([]),[i,a]=Y.useState(`loading`),[o,s]=Y.useState(0);return Y.useEffect(()=>{let t=new AbortController,n=!0;return a(`loading`),(async()=>{let i=await Bm(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)(sn,{className:`h-3 w-3`}),` `,J(`engine.flowRuns.title`,t),(0,X.jsx)(`button`,{type:`button`,onClick:()=>s(e=>e+1),title:J(`engine.flowRuns.refresh`,t),"aria-label":J(`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)(Gr,{className:V(`h-3 w-3`,i===`loading`&&`animate-spin`)})})]}),i===`unavailable`?(0,X.jsx)(`div`,{className:`italic text-muted-foreground`,children:J(`engine.flowRuns.unavailable`,t)}):i===`ready`&&n.length===0?(0,X.jsx)(`div`,{className:`italic text-muted-foreground`,children:J(`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)(Jm,{run:e,locale:t},e.id))})]})}function Xm(e){return e.target.kind===`node`?e.target.nodeId:e.target.kind===`edge`?`${e.target.source} → ${e.target.target}`:`flow`}function Zm({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:J(`engine.flowProblems.title`,r)}),i>0&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-destructive`,children:[(0,X.jsx)(Ir,{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)(ci,{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)(Zn,{className:`h-5 w-5 text-emerald-500`}),(0,X.jsx)(`span`,{children:J(`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`?Ir:ci,l=i?Cn:Ar;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,disabled:a,onClick:()=>n(e),className:V(`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:V(`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:Xm(e)}),e.source===`server`&&(0,X.jsxs)(`span`,{className:`uppercase tracking-wide`,children:[`· `,J(`engine.flowProblems.sourceSchema`,r)]}),e.source===`expression`&&(0,X.jsxs)(`span`,{className:`uppercase tracking-wide`,children:[`· `,J(`engine.flowProblems.sourceExpression`,r)]})]})]})]})},e.id)})})]})}function Qm({draft:e,editing:t,selection:n,onSelectionChange:r,onPatch:i,locale:a,diagnostics:o}){let s=e,c=Y.useMemo(()=>Array.isArray(s.nodes)?s.nodes:[],[s.nodes]),l=Y.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=Y.useMemo(()=>n&&n.kind===`nested-node`?sm(n.id):null,[n]),[g,_]=Y.useState(!1),[v,y]=Y.useState(!1),[b,x]=Y.useState(!1),[S,C]=Y.useState(!1),[w,T]=Y.useState(null),E=Y.useMemo(()=>Jp({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}=Y.useMemo(()=>Zp(E),[E]),[A,j]=Y.useState(null),M=p?`node:${p}`:m??null,N=Y.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]),P=Y.useCallback(()=>{if(!f)return;let e={id:Ss(`node`,c.map(e=>e.id).filter(Boolean)),type:`start`,label:Hf(`start`,a)};i({nodes:no(c,e)}),r?.({kind:`node`,id:e.id,label:e.label||e.id})},[f,c,i,r,a]),ee=typeof s.name==`string`&&s.name?s.name:``,te=String(s.type??`autolaunched`),ne=String(s.status??(s.active?`active`:`draft`)),re=String(s.runAs??`user`),ie=s.version==null?void 0:String(s.version),F=s.errorHandling?.strategy;return c.length===0?(0,X.jsx)(Z,{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:P,children:[(0,X.jsx)(L,{className:`h-3 w-3`}),J(`engine.inspector.add.node`,a)]})}):(0,X.jsx)(wu,{children:J(`engine.flowPreview.emptyHint`,a)})}):(0,X.jsx)(Z,{hint:`flow · ${c.length} node${c.length===1?``:`s`}`,children:(0,X.jsx)(Q,{fallbackHint:J(`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)($m,{icon:In,label:J(`engine.flowPreview.pill.trigger`,a),value:ro(`type`,te,a)}),(0,X.jsx)($m,{icon:Ar,label:J(`engine.flowPreview.pill.status`,a),value:ro(`status`,ne,a),tone:ne===`active`?`green`:ne===`draft`?`gray`:`amber`}),(0,X.jsx)($m,{icon:kr,label:J(`engine.flowPreview.pill.runAs`,a),value:ro(`runAs`,re,a)}),ie&&(0,X.jsx)($m,{label:`v`,value:ie}),F&&(0,X.jsx)($m,{icon:Cn,label:J(`engine.flowPreview.pill.onError`,a),value:ro(`onError`,F,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:J(v?`engine.flowPreview.hideVars`:`engine.flowPreview.showVars`,a),children:[(0,X.jsx)(pi,{className:`h-3 w-3`}),` `,J(`engine.flowPreview.variables`,a)]}),ee&&(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:J(`engine.flowPreview.runsTitle`,a),children:[(0,X.jsx)(Sr,{className:`h-3 w-3`}),` `,J(`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:J(`engine.flowPreview.problemsTitle`,a),children:[(0,X.jsx)(Ir,{className:`h-3 w-3`}),` `,J(`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)(xe,{className:`h-3 w-3`}),` `,J(`engine.flowPreview.debug`,a)]})]})]}),(0,X.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,X.jsx)(tm,{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:N,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:rm,id:om(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)(Zm,{problems:E,selectedKey:M,onSelectProblem:N,locale:a})}):g?(0,X.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,X.jsx)(Pm,{nodes:c,edges:l,variables:u,locale:a,onRunStateChange:T})}):b&&ee?(0,X.jsx)(`div`,{className:`border-l bg-muted/20`,children:(0,X.jsx)(Ym,{flowName:ee,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)(cr,{className:`h-3 w-3`}),` `,J(`engine.flowPreview.variables`,a)]}),u.length===0?(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:J(`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 $m({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 eh({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=n.planning,f=n.memory,p=n.guardrails,m=Array.isArray(n.permissions)?n.permissions:[];if(!r&&!s&&u.length===0)return(0,X.jsx)(Z,{hint:`agent`,children:(0,X.jsx)(wu,{children:`Fill in label, role, and instructions in the Form tab to see the agent preview.`})});let h=r?`/console/ai/agents/${encodeURIComponent(r)}/chat`:null;return(0,X.jsx)(Z,{hint:`agent`,toolbar:h&&(0,X.jsxs)(`a`,{href:h,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)(ti,{className:`h-3 w-3`})]}),children:(0,X.jsx)(Q,{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)(rt,{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)(ch,{icon:c?Xt:Me,label:c?`Active`:`Disabled`,tone:c?`green`:`gray`}),l.provider&&(0,X.jsx)(ch,{icon:pt,label:`${l.provider}${l.model?` · ${l.model}`:``}`,mono:!0}),l.temperature!=null&&(0,X.jsx)(ch,{icon:zt,label:`temp ${l.temperature}`}),l.maxTokens!=null&&(0,X.jsx)(ch,{label:`max ${l.maxTokens}t`})]})]})]}),(0,X.jsx)(th,{title:`Instructions`,icon:br,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)(nh,{children:`No system prompt set yet.`})}),(0,X.jsx)(th,{title:`Capabilities`,icon:pt,children:(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(ih,{label:`Skills`,emptyHint:`No skills attached — this agent can reach no tools.`,items:u.map(e=>({key:e,label:e})),icon:pt,tone:`violet`,mono:!0}),(0,X.jsx)(`div`,{className:`text-[10px] text-muted-foreground`,children:`Tools come from the attached skills; grounding is described in the instructions.`})]})})]}),(0,X.jsxs)(`div`,{className:`border-l bg-muted/20 p-3 text-xs space-y-3`,children:[d&&Object.keys(d).length>0&&(0,X.jsx)(ah,{icon:xt,title:`Planning`,children:(0,X.jsx)(oh,{data:d,keys:[`maxIterations`]})}),f&&Object.keys(f).length>0&&(0,X.jsx)(ah,{icon:Mr,title:`Memory`,children:(0,X.jsx)(oh,{data:{"short.maxMessages":f.shortTerm?.maxMessages,"long.enabled":f.longTerm?.enabled,"long.store":f.longTerm?.store},keys:[`short.maxMessages`,`long.enabled`,`long.store`]})}),p&&Object.keys(p).length>0&&(0,X.jsx)(ah,{icon:hn,title:`Guardrails`,children:(0,X.jsx)(oh,{data:p,keys:Object.keys(p).slice(0,6)})}),m.length>0&&(0,X.jsx)(ah,{icon:En,title:`Permissions`,children:(0,X.jsx)(`ul`,{className:`space-y-0.5`,children:m.map(e=>(0,X.jsx)(`li`,{className:`font-mono`,children:e},e))})}),!d&&!f&&!p&&m.length===0&&(0,X.jsx)(`div`,{className:`text-muted-foreground italic`,children:`Defaults in use.`})]})]})})})}function th({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 nh({children:e}){return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}var rh={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`}};function ih({label:e,emptyHint:t,items:n,icon:r,tone:i,mono:a=!1}){let o=i?rh[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:V(`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:V(`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 ah({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 oh({data:e,keys:t}){let n=t.map(t=>[t,sh(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 sh(e,t){let n=t.split(`.`),r=e;for(let e of n){if(r==null)return;r=r[e]}return r}function ch({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 lh(e){return!!e&&typeof e==`object`&&typeof e.properties==`object`}function uh(e){return e?Array.isArray(e.type)?e.type.join(`|`):e.type===`array`&&e.items?`${uh(e.items)}[]`:e.$ref?e.$ref.split(`/`).pop()||`ref`:e.type??`any`:`any`}function dh(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 fh({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=String(n.description??``),o=n.objectName||void 0,s=n.parameters??{},c=n.outputSchema??void 0,l=lh(s)?s.properties??{}:{},u=new Set(Array.isArray(s.required)?s.required:[]),d=Y.useMemo(()=>{let e={};for(let t of u)l[t]&&(e[t]=dh(l[t]));if(Object.keys(e).length===0){let t=Object.keys(l)[0];t&&(e[t]=dh(l[t]))}return e},[l,u]);return!r&&!a&&Object.keys(l).length===0?(0,X.jsx)(Z,{hint:`tool`,children:(0,X.jsx)(wu,{children:`Set name, description, and parameters to see the tool preview.`})}):(0,X.jsx)(Z,{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)(ti,{className:`h-3 w-3`})]}),children:(0,X.jsx)(Q,{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)(jr,{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})]}),o&&(0,X.jsx)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px]`,children:(0,X.jsx)(gh,{icon:wt,label:o,mono:!0})})]})]}),a&&(0,X.jsx)(`div`,{className:`pl-6 text-xs text-foreground whitespace-pre-wrap`,children:a})]}),(0,X.jsx)(mh,{title:`Input Parameters`,count:Object.keys(l).length,children:Object.keys(l).length===0?(0,X.jsx)(hh,{children:`This tool takes no input parameters.`}):(0,X.jsx)(ph,{props:l,required:u})}),Object.keys(l).length>0&&(0,X.jsx)(mh,{title:`Example LLM Call`,icon:fi,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:`{
|
|
12
|
+
"tool": "${r}",
|
|
13
|
+
"arguments": ${JSON.stringify(d,null,2).replace(/\n/g,`
|
|
14
|
+
`)}
|
|
15
|
+
}`})}),lh(c)&&c.properties&&Object.keys(c.properties).length>0&&(0,X.jsx)(mh,{title:`Output Schema`,count:Object.keys(c.properties).length,icon:We,children:(0,X.jsx)(ph,{props:c.properties,required:new Set(Array.isArray(c.required)?c.required:[])})})]})})})}function ph({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)(Zn,{className:`h-3 w-3 text-emerald-600`}):(0,X.jsx)(Cr,{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:uh(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 mh({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 hh({children:e}){return(0,X.jsx)(`div`,{className:`text-xs text-muted-foreground italic`,children:e})}function gh({icon:e,label:t,mono:n=!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:`text-foreground ${n?`font-mono`:``}`,children:t})]})}var _h=[{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:`viewAllRecords`,short:`V*`,long:`View All`,danger:!0},{key:`modifyAllRecords`,short:`M*`,long:`Modify All`,danger:!0}],vh=[`own`,`own_and_reports`,`unit`,`unit_and_below`,`org`],yh={own:`own`,own_and_reports:`own+reports`,unit:`unit`,unit_and_below:`unit+below`,org:`org`};function bh(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.`});let e=r.readScope?vh.indexOf(r.readScope):-1,i=r.writeScope?vh.indexOf(r.writeScope):-1;e>=0&&i>e&&t.push({object:n,message:`Write scope (${yh[r.writeScope]}) is wider than read scope (${yh[r.readScope]}) — edits may target invisible records.`})}return t}function xh({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=Y.useMemo(()=>Object.keys(o).sort(),[o]),f=Y.useMemo(()=>bh(o),[o]),p=Y.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)(Z,{hint:`permission`,children:(0,X.jsx)(wu,{children:`Grant at least one object, system, or tab permission to see the matrix.`})}):(0,X.jsx)(Z,{hint:`permission · ${d.length} object${d.length===1?``:`s`}`,children:(0,X.jsx)(Q,{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)(Ut,{className:`h-4 w-4 mt-0.5 text-amber-600 shrink-0`}):(0,X.jsx)(ve,{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)(Th,{icon:ir,label:`${d.length} objects`}),(0,X.jsx)(Th,{icon:Se,label:`${c.length} system perms`}),(0,X.jsx)(Th,{icon:Xt,label:`${Object.keys(l).length} tabs`}),(0,X.jsx)(Th,{icon:En,label:`${u.length} RLS rules`})]})]})]})}),d.length>0&&(0,X.jsxs)(wh,{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`}),_h.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}),_h.map(e=>{let n=!!t[e.key];return(0,X.jsx)(`td`,{className:`px-1.5 py-1 text-center`,children:(0,X.jsx)(Sh,{granted:n,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?yh[t.readScope]:`—`}),(0,X.jsx)(`span`,{className:`mx-1 opacity-50`,children:`/`}),(0,X.jsx)(`span`,{title:`Write scope`,children:t.writeScope?yh[t.writeScope]:`—`})]}):(0,X.jsx)(`span`,{className:`opacity-40`,children:`default`})})]},e)})})]})}),(0,X.jsx)(Ch,{})]}),p.size>0&&(0,X.jsx)(wh,{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)(wh,{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)(wh,{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)(ci,{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 Sh({granted:e,danger:t}){return e?(0,X.jsx)(Zn,{className:`inline-block h-3.5 w-3.5 ${t?`text-amber-600`:`text-emerald-600`}`,"aria-label":`granted`}):(0,X.jsx)(lt,{className:`inline-block h-3 w-3 text-muted-foreground/40`,"aria-label":`not granted`})}function Ch(){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)(Zn,{className:`h-3 w-3 text-emerald-600`}),` granted`]}),(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(Zn,{className:`h-3 w-3 text-amber-600`}),` bypass (View/Modify All)`]}),(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(lt,{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 · E T = Export/Transfer · V* M* = View/Modify All`})]})}function wh({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 Th({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 Eh(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 Dh(e){switch(e){case`url`:return nn;case`modal`:return Ie;case`flow`:return Qn;case`api`:return ct;case`form`:return Ft;default:return hi}}function Oh(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 kh(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 Ah({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=Eh(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.refreshAfter,f=n.aiExposed,p=Eh(n.confirmText),m=Eh(n.successMessage),h=Array.isArray(n.params)?n.params:[],g=n.resultDialog,_=n.body,v=n.objectName||void 0,y=n.visible,b=n.disabled,x=n.method||`POST`,S=n.bodyExtra,C=Dh(o),w=l===`action:icon`;return!r&&!i?(0,X.jsx)(Z,{hint:`action`,children:(0,X.jsx)(wu,{children:`Set name and label to see the action preview.`})}):(0,X.jsx)(Z,{hint:`action`,children:(0,X.jsx)(Q,{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)(jh,{label:i,icon:a,variant:c,iconOnly:w,disabled:!!b&&typeof b==`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)(Bh,{icon:C,label:`type: ${o}`}),v&&(0,X.jsx)(Bh,{icon:ln,label:`object: ${v}`,mono:!0}),c&&(0,X.jsx)(Bh,{label:`variant: ${c}`}),l&&(0,X.jsx)(Bh,{icon:an,label:l}),d&&(0,X.jsx)(Bh,{icon:Gr,label:`refresh after`}),f===!1&&(0,X.jsx)(Bh,{icon:rt,label:`AI: opted out`,tone:`amber`}),f===!0&&(0,X.jsx)(Bh,{icon:pt,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 y==`string`||y&&typeof y==`object`)&&(0,X.jsx)(Rh,{label:`Visible when`,value:y,icon:Xt}),b!=null&&typeof b!=`boolean`&&(0,X.jsx)(Rh,{label:`Disabled when`,value:b,icon:En})]}),(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)(C,{className:`h-3.5 w-3.5`}),` On click`]}),(0,X.jsx)(`div`,{className:`text-blue-950 font-mono break-all`,children:kh(o,s,!!_?.source)}),p&&(0,X.jsxs)(`div`,{className:`mt-1.5 flex items-start gap-1.5 text-amber-900`,children:[(0,X.jsx)(ci,{className:`h-3 w-3 mt-0.5`}),(0,X.jsxs)(`span`,{children:[`First asks: `,(0,X.jsx)(`em`,{children:p})]})]}),m&&(0,X.jsxs)(`div`,{className:`mt-1.5 text-blue-950`,children:[`On success: `,(0,X.jsx)(`em`,{children:m})]})]}),u.length>0&&(0,X.jsx)(zh,{title:`Where it appears`,children:(0,X.jsx)(Hh,{locations:u,label:i,icon:a,variant:c,iconOnly:w})}),o===`api`&&!!s&&(0,X.jsx)(zh,{title:`Test request`,icon:ct,children:(0,X.jsx)(Uh,{target:s,method:x,bodyExtra:S,params:h})}),h.length>0&&(0,X.jsx)(zh,{title:`Input Dialog`,count:h.length,children:(0,X.jsx)(Nh,{title:i,params:h,variant:c})}),g&&(0,X.jsx)(zh,{title:`Result Dialog`,icon:Xt,children:(0,X.jsx)(Lh,{dialog:g})}),_?.source&&(0,X.jsx)(zh,{title:`Script Body (${_.language??`expression`})`,icon:hi,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:_.source})})]})})})}function jh({label:e,icon:t,variant:n,iconOnly:r,disabled:i}){let a=`inline-flex items-center gap-1.5 rounded px-3 py-1.5 text-sm font-medium pointer-events-none ${Oh(n)} ${i?`opacity-50`:``}`;return(0,X.jsxs)(`button`,{type:`button`,className:a,"aria-disabled":!0,disabled:!0,children:[t&&(0,X.jsx)(Mh,{name:t}),!r&&(0,X.jsx)(`span`,{children:e})]})}function Mh({name:e}){let t=yt(e);return t?(0,X.jsx)(t,{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 Nh({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}`,r=Eh(e.label)||n;return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsxs)(`label`,{className:`text-xs flex items-center gap-1`,children:[r,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})]}),Ih(e,r),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 ${Oh(n||`primary`)}`,children:`OK`})]})]})}var Ph=`(inherited from the bound field)`;function Fh(e){if(!e.type)return{widget:void 0,degraded:!1};let t=e.reference??(e.field?Ph:void 0),n=Ei({name:e.name??``,label:``,type:e.type,referenceTo:t});return{widget:n?`text`:wi(e.type),degraded:n}}function Ih(e,t){let n=`w-full text-xs px-2 py-1 border rounded bg-background pointer-events-none`,r=e.placeholder||(e.defaultFromRow?`(from selected row)`:``),i=e.defaultValue,a=i==null?``:String(i),o=Array.isArray(e.options)?e.options:[],{widget:s,degraded:c}=Fh(e),l=e=>(0,X.jsx)(`input`,{type:e,className:n,placeholder:r,value:a,readOnly:!0}),u=(0,X.jsxs)(`select`,{className:n,disabled:!0,value:``,children:[(0,X.jsx)(`option`,{value:``,children:r||`Select ${t}`}),o.map((e,t)=>(0,X.jsx)(`option`,{value:e.value,children:Eh(e.label)},t))]}),d=e=>(0,X.jsx)(`div`,{className:`text-[10px] text-amber-700`,children:e});if(s===void 0)return o.length>0?u:l(`text`);if(c)return(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,X.jsx)(`input`,{type:`text`,className:n,placeholder:r||`Record id for ${t}`,value:a,readOnly:!0}),d((0,X.jsxs)(X.Fragment,{children:[`No `,(0,X.jsx)(`code`,{className:`font-mono`,children:`reference`}),` object is configured, so the record picker is unavailable and the dialog asks for a record id.`]}))]});switch(s){case`boolean`:return(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`]});case`textarea`:case`html`:return(0,X.jsx)(`textarea`,{className:`${n} min-h-[48px]`,placeholder:r,value:a,readOnly:!0});case`select`:return o.length>0?u:(0,X.jsxs)(`div`,{className:`space-y-0.5`,children:[u,d(`No choices authored yet — the dialog opens an empty picker.`)]});case`number`:return l(`number`);case`date`:return l(`date`);case`datetime`:return l(`datetime-local`);case`lookup`:return(0,X.jsxs)(`button`,{type:`button`,disabled:!0,role:`combobox`,"aria-expanded":!1,"aria-haspopup":`dialog`,className:`${n} flex items-center gap-1.5 text-left text-muted-foreground`,children:[(0,X.jsx)(Dn,{className:`h-3 w-3 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`truncate`,children:r||`Search ${e.reference??`records`}…`})]});default:return l(`text`)}}function Lh({dialog:e}){let t=Eh(e.title)||`Result`,n=Eh(e.description),r=Eh(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:Eh(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 Rh({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 zh({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 Bh({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 Vh({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 Hh({locations:e,label:t,icon:n,variant:r,iconOnly:i}){let a=(0,X.jsx)(jh,{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)(Vh,{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)(Vh,{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)(Vh,{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)(Vh,{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)(Vh,{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)(an,{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})})]})})]})}function Uh({target:e,method:t,bodyExtra:n,params:r}){let i=(t||`POST`).toUpperCase(),[a,o]=Y.useState(null),[s,c]=Y.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)(ci,{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)(ct,{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 Wh={"@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 Gh(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 Kh(e){let t=(Wh[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=Gh(n,0,59),c=Gh(r,0,23),l=Gh(i,1,31),u=Gh(a,1,12),d=Gh(o===`7`?`0`:o,0,6);return!s||!c||!l||!u||!d?null:{minute:s,hour:c,dom:l,month:u,dow:d}}function qh(e,t,n){let r=Kh(e);if(!r)return[];let i=[],a=new Date(t.getTime());a.setSeconds(0,0),a.setMinutes(a.getMinutes()+1);let o=t.getTime()+316224e5;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 Jh(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 Yh(e,t,n){let r=[];for(let i=1;i<=n;i++)r.push(new Date(t.getTime()+i*e));return r}function Xh(e){return e.toLocaleString(void 0,{weekday:`short`,month:`short`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function Zh(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?Qh(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`?Qh(n):void 0,at:typeof e.at==`string`?e.at:typeof e.runAt==`string`?e.runAt:void 0,timezone:e.timezone??e.tz}}function Qh(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 $h({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}=Zh(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?Jh(s):null,{nextFires:v,deltas:y}=Y.useMemo(()=>{let e=new Date,t=[];if(o)t=qh(o,e,5);else if(_)t=Yh(_,e,5);else if(c){let e=Date.parse(c);Number.isNaN(e)||(t=[new Date(e)])}return{nextFires:t,deltas:t.map(t=>eg(t.getTime()-e.getTime()))}},[o,_,c]),b=o&&v.length===0||s&&!_;return!r&&!o&&!s&&!c&&!u?(0,X.jsx)(Z,{hint:`job`,children:(0,X.jsx)(wu,{children:`Set a schedule (cron / every / at) and a handler to see the job preview.`})}):(0,X.jsx)(Z,{hint:`job`,children:(0,X.jsx)(Q,{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)(vr,{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)(rg,{icon:Qt,label:d?`Active`:`Paused`,tone:d?`green`:`gray`}),l&&(0,X.jsx)(rg,{icon:Re,label:l,mono:!0}),p!=null&&(0,X.jsx)(rg,{icon:Rn,label:`retries: ${p}${m?` (${Qh(m)} backoff)`:``}`}),h!=null&&(0,X.jsx)(rg,{icon:en,label:`timeout: ${Qh(h)}`}),g!=null&&(0,X.jsx)(rg,{label:`concurrency: ${g}`})]})]})]})}),(0,X.jsx)(ng,{title:`Schedule`,icon:Pe,children:(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[o&&(0,X.jsx)(tg,{label:`Cron`,children:(0,X.jsx)(`code`,{className:`font-mono`,children:o})}),s&&(0,X.jsxs)(tg,{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)(tg,{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)(ng,{title:`Next ${Math.max(v.length,1)} run${v.length===1?``:`s`}`,icon:sn,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)(sn,{className:`h-3 w-3 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`font-mono`,children:Xh(e)}),(0,X.jsxs)(`span`,{className:`ml-auto text-[10px] text-muted-foreground`,children:[`in `,y[t]]})]},t))})}),(0,X.jsx)(ng,{title:`Handler`,icon:hi,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)(Rr,{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 eg(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 tg({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 ng({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 rg({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 ig=[{key:`objects`,label:`Objects`,icon:Ae,flat:!1},{key:`apps`,label:`Apps`,icon:zr,flat:!1},{key:`messages`,label:`Messages`,icon:lr,flat:!0},{key:`validationMessages`,label:`Validation Messages`,icon:Fn,flat:!0},{key:`globalActions`,label:`Global Actions`,icon:Dr,flat:!0},{key:`dashboards`,label:`Dashboards`,icon:Mt,flat:!1},{key:`settings`,label:`Settings`,icon:kr,flat:!0},{key:`metadataForms`,label:`Metadata Forms`,icon:Wr,flat:!1}];function ag({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=ig.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/ig.length*100);return c===0?(0,X.jsx)(Z,{hint:`translation · ${r}`,children:(0,X.jsx)(wu,{children:`This bundle is empty — add at least one translated string to see the coverage report.`})}):(0,X.jsx)(Z,{hint:`translation · ${r} · ${c} keys`,children:(0,X.jsx)(Q,{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)(Ce,{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)(Re,{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)(zt,{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,`/`,ig.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)(og,{cat:e},e.key))})]})})})}function og({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:sg(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 sg(e,t){return t?typeof e==`string`?`"${e}"`:e==null?`∅`:String(e):e&&typeof e==`object`?`{${Object.keys(e).length} keys}`:String(e??`∅`)}function cg({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)(Z,{hint:`position`,children:(0,X.jsx)(Q,{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)(Vr,{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)(ve,{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)(Z,{hint:`position`,children:(0,X.jsx)(wu,{children:`Give the position a name to see the preview.`})})}function lg({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.triggerConditions)?n.triggerConditions:[],l=n.active!==!1,u=n.model??void 0;return r?(0,X.jsx)(Z,{hint:`skill`,children:(0,X.jsx)(Q,{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})]}),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)(fg,{icon:Qt,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),u&&(0,X.jsx)(fg,{label:`model: ${u}`,mono:!0})]})]})]})}),(0,X.jsx)(dg,{title:`Instructions`,icon:Ht,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)(dg,{title:`Tools (${s.length})`,icon:jr,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)(ft,{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.jsxs)(dg,{title:`Trigger Conditions (${c.length})`,icon:ye,children:[(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:`Field`}),(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Operator`}),(0,X.jsx)(`th`,{className:`px-2.5 py-1.5 font-medium`,children:`Value`})]})}),(0,X.jsx)(`tbody`,{className:`divide-y`,children:c.map((e,t)=>(0,X.jsxs)(`tr`,{className:`align-top`,children:[(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:ug(e.field)}),(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono text-muted-foreground`,children:ug(e.operator)}),(0,X.jsx)(`td`,{className:`px-2.5 py-1.5 font-mono break-all`,children:ug(e.value)})]},t))})]})}),c.length>1&&(0,X.jsx)(`div`,{className:`mt-1 text-[10px] text-muted-foreground`,children:`All conditions must hold (AND) for the skill to activate.`})]})]})})}):(0,X.jsx)(Z,{hint:`skill`,children:(0,X.jsx)(wu,{children:`Give the skill a name and at least an instructions block to see the preview.`})})}function ug(e){return typeof e==`string`&&e!==``?e:Array.isArray(e)&&e.every(e=>typeof e==`string`)?e.join(`, `):(0,X.jsx)(`span`,{className:`text-amber-700`,title:`Required by SkillTriggerConditionSchema — this draft will be rejected on save.`,children:`missing`})}function dg({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 fg({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 pg=class extends Error{constructor(){super(`external_service_unavailable`),this.name=`ExternalServiceUnavailableError`}},mg=c();function hg(){return``.replace(/\/+$/,``)}function gg(e){return`${hg()}/api/v1/datasources/${encodeURIComponent(e)}/external`}async function _g(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 pg}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 vg(e,t={}){let n=t.schema?`?schema=${encodeURIComponent(t.schema)}`:``;return(await _g(await mg(`${gg(e)}/tables${n}`,{method:`GET`,headers:{Accept:`application/json`}}))).tables??[]}async function yg(e,t,n={}){return(await _g(await mg(`${gg(e)}/tables/${encodeURIComponent(t)}/draft`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(n)}))).draft}async function bg(e){return(await _g(await mg(`${gg(e)}/refresh-catalog`,{method:`POST`,headers:{Accept:`application/json`}}))).catalog}async function xg(e){return _g(await mg(`${gg(e)}/validate`,{method:`POST`,headers:{Accept:`application/json`}}))}async function Sg(e){await _g(await mg(`${hg()}/api/v1/meta/object/${encodeURIComponent(e.name)}`,{method:`PUT`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify(e.definition)}))}function Cg({datasource:e,table:t,open:n,onOpenChange:r,onImported:i}){let[a,o]=Y.useState(`loading`),[s,c]=Y.useState(null),[l,u]=Y.useState(null);Y.useEffect(()=>{if(!n||!t)return;let r=!1;return o(`loading`),c(null),u(null),(async()=>{try{let n=await yg(e,t.name,{remoteSchema:t.schema});if(r)return;c(n),o(`ready`)}catch(e){if(r)return;u(e instanceof pg?`Federation is not enabled on this server.`:e instanceof Error?e.message:String(e)),o(`error`)}})(),()=>{r=!0}},[n,t,e]);let d=Y.useCallback(async()=>{if(s){o(`importing`),u(null);try{await Sg(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)(Yr,{open:n,onOpenChange:r,children:(0,X.jsxs)(di,{className:`max-w-2xl`,children:[(0,X.jsxs)(Yt,{children:[(0,X.jsxs)(je,{className:`flex items-center gap-2`,children:[(0,X.jsx)(wt,{className:`h-4 w-4`}),`Import as Object`]}),(0,X.jsxs)(An,{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)(H,{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)(Zn,{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)(ci,{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)(Xr,{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)(oi,{children:a===`done`?(0,X.jsx)(B,{onClick:()=>r(!1),children:`Close`}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(B,{variant:`ghost`,onClick:()=>r(!1),disabled:a===`importing`,children:`Cancel`}),(0,X.jsx)(B,{onClick:d,disabled:a!==`ready`||!s,children:a===`importing`?(0,X.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}),` Importing…`]}):`Import as Object`})]})})]})})}function wg({datasource:e}){let[t,n]=Y.useState(`idle`),[r,i]=Y.useState([]),[a,o]=Y.useState(null),[s,c]=Y.useState(``),[l,u]=Y.useState(null),[d,f]=Y.useState(!1),p=Y.useCallback(async()=>{n(`loading`),o(null);try{let t=await vg(e);i(t),n(`loaded`)}catch(e){e instanceof pg?n(`unavailable`):(o(e instanceof Error?e.message:String(e)),n(`error`))}},[e]);Y.useEffect(()=>{p()},[p]);let m=Y.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)(Tg,{}):(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)(Dn,{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)(B,{variant:`outline`,size:`sm`,onClick:()=>void p(),disabled:t===`loading`,children:[t===`loading`?(0,X.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(Gr,{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)(H,{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)(Et,{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)(vt,{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)(B,{variant:`ghost`,size:`sm`,onClick:()=>h(e),children:[(0,X.jsx)(Pt,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`ml-1.5`,children:`Import`})]})})]},t)})})]})}),(0,X.jsx)(Cg,{datasource:e,table:l,open:d,onOpenChange:f})]})}function Tg(){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 Eg={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`,index_mismatch:`Index mismatch`,unmapped_index:`Unmapped index`,default_mismatch:`Column default mismatch`};function Dg({datasource:e}){let[t,n]=Y.useState(`idle`),[r,i]=Y.useState([]),[a,o]=Y.useState(null),[s,c]=Y.useState(null),l=Y.useCallback(async()=>{n(`running`),c(null);try{let t=await xg(e);i(t.results),o(t.ok),n(`done`)}catch(e){e instanceof pg?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)(B,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:t===`running`,children:[t===`running`?(0,X.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(Rr,{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)(Zn,{className:`h-4 w-4`}):(0,X.jsx)(Fn,{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)(Og,{result:e},e.object))})]})}function Og({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)(ve,{className:`h-3.5 w-3.5 text-emerald-500`}):(0,X.jsx)(Fn,{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)(kg,{diff:e},`${e.kind}:${e.column??``}:${t}`))})]})}function kg({diff:e}){let t=[e.remoteSchema,e.remoteName].filter(Boolean).join(`.`),n=e.severity===`error`;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] ${n?`bg-destructive/10 text-destructive`:`bg-amber-100 text-amber-800 dark:bg-amber-950/40 dark:text-amber-300`}`,children:Eg[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 Ag({datasource:e,schemaMode:t,allowWrites:n}){let[r,i]=Y.useState(null),[a,o]=Y.useState(!1),[s,c]=Y.useState(null),l=Y.useCallback(async()=>{if(e){o(!0),c(null);try{let t=await bg(e);i(t)}catch(e){c(e instanceof pg?`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)(kt,{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)(sn,{className:`h-3 w-3`}),`snapshot `,jg(r.snapshotAt)]}),(0,X.jsxs)(B,{variant:`outline`,size:`sm`,onClick:()=>void l(),disabled:a,children:[a?(0,X.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)(Gr,{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)(gi,{defaultValue:`tables`,className:`p-3`,children:[(0,X.jsxs)(un,{children:[(0,X.jsx)(et,{value:`tables`,children:`Tables`}),(0,X.jsx)(et,{value:`validation`,children:`Validation`})]}),(0,X.jsx)(Ee,{value:`tables`,className:`mt-3`,children:(0,X.jsx)(wg,{datasource:e})}),(0,X.jsx)(Ee,{value:`validation`,className:`mt-3`,children:(0,X.jsx)(Dg,{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 jg(e){let t=new Date(e).getTime();if(Number.isNaN(t))return e;try{return new Date(t).toLocaleString()}catch{return e}}var Mg=/pass|secret|key|token|credential|auth/i;function Ng(e){return Mg.test(e)}function Pg(e){return e==null||e===``?`∅`:`••••••`}function Fg(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 Ig({name:e,draft:t}){let n=t,r=String(n.name??e??``),i=String(n.label??r),a=n.description??``,o=n.driver??`unknown`,s=n.active!==!1,c=n.config??{},l=n.pool,u=n.ssl,d=n.schemaMode??`managed`,f=d!==`managed`,p=!!(n.external??void 0)?.allowWrites,m=Object.entries(c);return!r&&m.length===0?(0,X.jsx)(Z,{hint:`datasource`,children:(0,X.jsx)(wu,{children:`Set a name and at least a driver to see the datasource preview.`})}):(0,X.jsx)(Z,{hint:`datasource · ${o}`,children:(0,X.jsx)(Q,{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)(wt,{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)(on,{className:`h-3 w-3 text-muted-foreground`}),` `,o]}),(0,X.jsx)(zg,{icon:Qt,label:s?`Active`:`Disabled`,tone:s?`green`:`gray`})]})]})]})}),f&&(0,X.jsx)(Ag,{datasource:String(e??``),schemaMode:d,allowWrites:p}),(0,X.jsx)(Rg,{title:`Connection`,icon:En,children:m.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:m.map(([e,t])=>{let n=Ng(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:Pg(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`})]}):Fg(t)})]},e)})})})})}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,X.jsx)(Lg,{title:`Pool`,icon:Mr,value:l}),(0,X.jsx)(Lg,{title:`SSL`,icon:ve,value:typeof u==`boolean`?{enabled:u}:u})]})]})})})}function Lg({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:Ng(e)?Pg(t):Fg(t)})]},e))}):(0,X.jsx)(`span`,{className:`text-muted-foreground italic`,children:`not configured`})})]})}function Rg({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 zg({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 Bg(e){if(e){if(typeof e==`string`)return e;if(typeof e==`object`&&typeof e.source==`string`)return e.source}}function Vg(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:pn};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:ci};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:it}}}function Hg({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.message??``,c=n.severity??`error`,l=n.active!==!1,u=Array.isArray(n.events)?n.events:[],d=n.priority,f=Array.isArray(n.tags)?n.tags:[],p=Vg(c);return r?(0,X.jsx)(Z,{hint:`validation · ${o}`,children:(0,X.jsx)(Q,{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)(Fn,{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)(Jg,{icon:Qt,label:l?`Active`:`Disabled`,tone:l?`green`:`gray`}),d!=null&&(0,X.jsx)(Jg,{label:`priority ${d}`}),u.length>0&&(0,X.jsx)(Jg,{label:`on ${u.join(`, `)}`})]})]})]})}),(0,X.jsx)(`div`,{className:`rounded border p-2.5 text-xs ${p.ring}`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-1.5 ${p.text}`,children:[(0,X.jsx)(p.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:c}),(0,X.jsx)(`div`,{className:`font-normal mt-0.5 text-foreground`,children:s||(0,X.jsx)(`span`,{className:`italic text-muted-foreground`,children:`no message set`})})]})]})}),(0,X.jsx)(Wg,{type:o,d:n}),f.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:f.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)(Z,{hint:`validation`,children:(0,X.jsx)(wu,{children:`Give the validation a name to see the preview.`})})}var Ug={unique:"Uniqueness is a unique INDEX, not a validation rule: declare it on the object as `indexes: [{ fields: [...], unique: true }]` (or `unique: true` on the field). A SELECT-then-INSERT rule is inherently racy (TOCTOU); a database constraint is not.",async:`Remote/async validation is a form-layer concern — on the server write path it is an SSRF and latency hazard. Keep it in the form, or enforce the underlying invariant with a unique index or a lifecycle hook.`,custom:"Arbitrary validation code belongs in a `beforeInsert` / `beforeUpdate` lifecycle hook — the typed, supported extension point."};function Wg({type:e,d:t}){let n=Ug[e];if(n)return(0,X.jsx)(qg,{title:`Not a validation rule`,icon:Fn,children:(0,X.jsxs)(`div`,{className:`rounded border border-amber-200 bg-amber-50 p-2.5 text-xs text-amber-900 dark:border-amber-900 dark:bg-amber-950/40 dark:text-amber-200`,children:[(0,X.jsxs)(`div`,{className:`font-medium`,children:[(0,X.jsx)(`code`,{className:`font-mono`,children:e}),` was removed from ValidationRuleSchema — this rule cannot be saved.`]}),(0,X.jsx)(`div`,{className:`mt-1`,children:n})]})});switch(e){case`script`:return(0,X.jsx)(qg,{title:`Condition`,icon:hi,children:(0,X.jsx)(Kg,{value:Bg(t.condition)})});case`conditional`:{let e=t.then,n=t.otherwise;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(qg,{title:`When`,icon:hi,children:(0,X.jsx)(Kg,{value:Bg(t.when)})}),(0,X.jsx)(qg,{title:`Then apply`,icon:Fn,children:(0,X.jsx)(Gg,{rule:e,emptyHint:`No nested rule set — this rule enforces nothing.`})}),n&&(0,X.jsx)(qg,{title:`Otherwise apply`,icon:Fn,children:(0,X.jsx)(Gg,{rule:n,emptyHint:`—`})})]})}case`state_machine`:{let e=t.transitions&&typeof t.transitions==`object`&&!Array.isArray(t.transitions)?t.transitions:{},n=Object.entries(e),r=t.field,i=Array.isArray(t.initialStates)?t.initialStates:[];return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(qg,{title:`Transitions${r?` on ${r}`:``}`,icon:Qn,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)(mn,{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))})}),i.length>0&&(0,X.jsx)(qg,{title:`May be created in`,icon:vn,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:i.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))})})]})}case`format`:{let e=t.regex,n=t.format,r=t.field;return(0,X.jsx)(qg,{title:`Format${r?` on ${r}`:``}`,icon:Tn,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:`Regex:`}),` `,(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=Bg(t.condition);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(qg,{title:`Fields involved`,icon:vn,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)(qg,{title:`Cross-field condition`,icon:hi,children:(0,X.jsx)(Kg,{value:n})})]})}case`json_schema`:{let e=t.field,n=t.schema,r=n&&typeof n==`object`?JSON.stringify(n,null,2):void 0;return(0,X.jsx)(qg,{title:`JSON Schema${e?` on ${e}`:``}`,icon:Tt,children:r?(0,X.jsx)(`pre`,{className:`m-0 rounded border bg-background p-2.5 text-xs font-mono overflow-auto max-h-[240px]`,children:r}):(0,X.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:`No JSON Schema set.`})})}default:return(0,X.jsx)(qg,{title:`Rule`,icon:Fn,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 Gg({rule:e,emptyHint:t}){if(!e||typeof e!=`object`)return(0,X.jsx)(`div`,{className:`text-xs text-amber-700 dark:text-amber-400`,children:t});let n=String(e.type??``),r=Bg(e.condition)??Bg(e.when);return(0,X.jsxs)(`div`,{className:`rounded border bg-background p-2.5 text-xs space-y-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`rounded border bg-muted/40 px-1.5 py-0.5 text-[10px] font-mono`,children:n||`no type`}),typeof e.name==`string`&&(0,X.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.name})]}),typeof e.message==`string`&&e.message&&(0,X.jsx)(`div`,{className:`text-foreground`,children:e.message}),r&&(0,X.jsx)(`pre`,{className:`m-0 rounded border bg-muted/30 p-2 font-mono whitespace-pre-wrap break-words`,children:r})]})}function Kg({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 qg({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 Jg({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 Yg=Y.lazy(()=>t(()=>import(`./plugin-charts-hJ5C1pY-.js`).then(e=>e.t).then(e=>({default:e.ChartRenderer})),__vite__mapDeps([0]),import.meta.url));function Xg({draft:e}){let t=F(),{fieldLabel:n}=ce(),r=de(),i=pe(),a=e.object,o=Y.useMemo(()=>(Array.isArray(e.measures)?e.measures:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),s=Y.useMemo(()=>(Array.isArray(e.dimensions)?e.dimensions:[]).map(e=>String(e?.name??``)).filter(Boolean),[e]),c=!!a&&o.length>0,[l,u]=Y.useState({status:`idle`,rows:[]}),d=Y.useCallback(async()=>{if(c){u({status:`loading`,rows:[]});try{let n=await t.queryDataset(e,{dimensions:s,measures:o});u({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`){u({status:`not-installed`,rows:[]});return}u({status:`error`,rows:[],error:String(e?.message??e)})}}},[t,e,s,o,c]),f=`${a??``}|${s.join(`,`)}|${o.join(`,`)}`;if(Y.useEffect(()=>{c&&d()},[f]),!a)return(0,X.jsx)(Z,{children:(0,X.jsx)(Tu,{icon:(0,X.jsx)($t,{className:`h-8 w-8`}),title:`Pick a base object`,description:"Set the dataset's `object` to preview it against live data."})});if(o.length===0)return(0,X.jsx)(Z,{children:(0,X.jsx)(Tu,{icon:(0,X.jsx)($t,{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 p=l.status===`ok`?l.fields:void 0,m=l.status===`ok`?l.object:void 0,{measureField:h,headerLabel:g}=j(p,m,n,le(r)),_=[...s,...o],v=e=>{let t=h(e)?.format;return typeof t==`string`&&t.includes(`%`)},y=o.filter(v),b=y.length>0&&y.length<o.length;return(0,X.jsx)(Z,{hint:`dataset · ${a}${s.length?` · by `+s.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 d(),disabled:l.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:[l.status===`loading`?(0,X.jsx)(H,{className:`h-3.5 w-3.5 animate-spin`}):(0,X.jsx)($t,{className:`h-3.5 w-3.5`}),`Run preview`]}),(0,X.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[o.length,` measure`,o.length===1?``:`s`,` · `,s.length,` dimension`,s.length===1?``:`s`]})]}),l.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)(ci,{className:`h-3.5 w-3.5 mt-0.5 shrink-0`}),(0,X.jsx)(`span`,{className:`break-words`,children:l.error})]}),l.status===`not-installed`&&(0,X.jsx)(Tu,{icon:(0,X.jsx)(_n,{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.`}),l.status===`ok`&&l.rows.length===0&&(0,X.jsx)(Tu,{icon:(0,X.jsx)($t,{className:`h-8 w-8`}),title:`No rows`,description:`The dataset returned no rows for the current scope.`}),l.rows.length>0&&s.length>=1&&(0,X.jsx)(Q,{fallbackHint:`Couldn't render the chart for this result — the table below still shows the data.`,children:(0,X.jsx)(Y.Suspense,{fallback:(0,X.jsx)(`div`,{className:`h-[260px] flex items-center justify-center text-xs text-muted-foreground`,children:(0,X.jsx)(H,{className:`h-4 w-4 animate-spin`})}),children:(0,X.jsxs)(`div`,{className:`rounded-md border p-2`,children:[(0,X.jsx)(Yg,{schema:{data:l.rows,xAxisKey:s[0],chartType:b?`combo`:`bar`,series:o.map(e=>({dataKey:e,label:g(e),chartType:b&&v(e)?`line`:`bar`}))}}),b&&(0,X.jsxs)(`p`,{className:`mt-1 px-1 text-[10px] text-muted-foreground`,children:[`Ratio measures (`,y.map(g).join(`, `),`) use the right axis.`]})]})})}),l.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:_.map(e=>(0,X.jsx)(`th`,{className:`px-2 py-1.5 text-left font-medium whitespace-nowrap`,children:g(e)},e))})}),(0,X.jsx)(`tbody`,{children:l.rows.map((e,t)=>(0,X.jsx)(`tr`,{className:`border-t`,children:_.map(t=>(0,X.jsx)(`td`,{className:`px-2 py-1 tabular-nums whitespace-nowrap`,children:o.includes(t)?ee(e[t],h(t)?.format,h(t)?.currency,h(t)?.percentScale,i):T(e[t],i)},t))},t))})]})})]})})}function Zg(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:Qg(e.include),package:typeof e.package==`string`?e.package:void 0,pages:$g(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 Qg(e){if(typeof e==`string`)return e;if(e&&typeof e==`object`&&typeof e.tag==`string`)return{tag:e.tag}}function $g(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 e_(e){return e===`public`?{icon:(0,X.jsx)(ct,{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)(En,{className:`h-3 w-3`}),label:`Permission set: ${e.permissionSet}`,tone:`text-amber-800 bg-amber-50 border-amber-200`}:{icon:(0,X.jsx)(rr,{className:`h-3 w-3`}),label:`Org`,tone:`text-muted-foreground bg-muted/40 border-muted`}}function t_({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=Y.useMemo(()=>Zg(n.groups),[n.groups]),c=e_(n.audience);if(!r)return(0,X.jsx)(Z,{hint:`book`,children:(0,X.jsx)(Tu,{icon:(0,X.jsx)(Ht,{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.`})});let l=`/meta/book/${encodeURIComponent(r)}/tree`;return(0,X.jsx)(Z,{hint:`book · spine`,toolbar:(0,X.jsxs)(`a`,{href:l,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)(ti,{className:`h-3 w-3`})]}),children:(0,X.jsx)(Q,{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)(Ht,{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)(Tu,{icon:(0,X.jsx)(yr,{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)(n_,{group:e},`${e.key}-${t}`))})]})})})}function n_({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)(yr,{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)(ot,{className:`h-3 w-3`}),e.package]}),(0,X.jsx)(r_,{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)(i_,{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 r_({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)(Se,{className:`h-3 w-3`}),e.tag]})}function i_({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)($n,{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)(an,{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)(ti,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`}):(0,X.jsx)(Wr,{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 a_(){ho(`page`,Dd),ho(`view`,jd),ho(`dashboard`,Rd),ho(`report`,Vd),ho(`app`,rf),ho(`action`,Ah),ho(`object`,Cf),ho(`datasource`,Ig),ho(`validation`,Hg),ho(`dataset`,Xg),ho(`email_template`,Df),ho(`translation`,ag),ho(`book`,t_),ho(`flow`,Qm),ho(`job`,$h),ho(`agent`,eh),ho(`tool`,fh),ho(`skill`,lg),ho(`permission`,xh),ho(`profile`,xh),ho(`position`,cg),ho(`role`,cg)}var o_=[{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`}],s_=[`default`,`blue`,`teal`,`orange`,`purple`,`success`,`warning`,`danger`];function c_(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 l_({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?c_(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`):[],m=Array.isArray(u.values)?u.values.filter(e=>typeof e==`string`):[],h=Qa(),g=Ka(d||void 0,h),_=Y.useMemo(()=>{let e=h.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},[h.datasets,d]),v=Y.useMemo(()=>g.measures.map(e=>({name:e.name,label:e.aggregate?`${e.name} · ${e.aggregate}`:e.name,type:`number`,hidden:!1})),[g.measures]),y=Y.useMemo(()=>g.dimensions.map(e=>({name:e.name,label:e.name,type:e.type??`text`,hidden:!1})),[g.dimensions]),b=Y.useMemo(()=>g.dimensions.map(e=>({value:e.name,label:e.name,hint:e.type})),[g.dimensions]),x=Y.useMemo(()=>k({globalFilters:e.globalFilters,dateRange:e.dateRange}),[e]);if(t.kind!==`widget`)return(0,X.jsx)(f_,{message:`Unsupported selection kind: ${t.kind}`,onClose:r,locale:o});if(!l)return(0,X.jsx)(f_,{message:`The selected widget was removed from the draft.`,onClose:r,locale:o});let{widget:S,index:C}=l;function w(e){let t=[...s];t[C]={...t[C],...e},n({widgets:t})}function T(e){n({widgets:Ha(s,C,e)}),S.id&&i?.({kind:`widget`,id:S.id,label:p(S.title,o)})}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:J(`engine.inspector.widget.kind`,o)}),(0,X.jsx)(`div`,{className:`truncate text-sm font-semibold`,children:p(S.title,o)||t.label||`Widget ${C+1}`})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,X.jsx)(Ga,{index:C,total:s.length,onMove:T,upLabel:J(`engine.inspector.reorder.up`,o),downLabel:J(`engine.inspector.reorder.down`,o),disabled:a}),(0,X.jsx)(B,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:r,title:J(`engine.inspector.widget.close`,o),"aria-label":J(`engine.inspector.widget.close`,o),children:(0,X.jsx)(_r,{className:`h-3.5 w-3.5`})})]})]}),(0,X.jsx)(d_,{id:`widget-title`,label:J(`engine.inspector.widget.title`,o),children:(0,X.jsx)(R,{id:`widget-title`,value:p(S.title,o)??``,onChange:e=>w({title:fe(S.title,o,e.target.value)}),disabled:a})}),(0,X.jsx)(d_,{id:`widget-type`,label:J(`engine.inspector.widget.type`,o),children:(0,X.jsxs)(Qr,{value:S.type??`metric`,onValueChange:e=>{let t=o_.find(t=>t.value===e);t&&w({type:t.value})},disabled:a,children:[(0,X.jsx)(Fe,{id:`widget-type`,children:(0,X.jsx)(jt,{})}),(0,X.jsx)(tn,{children:o_.map(e=>(0,X.jsx)(He,{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:J(`engine.inspector.widget.datasetSection`,o)}),(0,X.jsxs)(d_,{id:`widget-dataset`,label:J(`engine.inspector.widget.dataset`,o),children:[(0,X.jsx)(ws,{id:`widget-dataset`,value:d,onCommit:e=>w({dataset:e||void 0}),options:_,loading:h.loading,placeholder:J(`engine.inspector.widget.datasetPlaceholder`,o),searchPlaceholder:J(`engine.inspector.widget.datasetPlaceholder`,o),disabled:a,mono:!0}),(0,X.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:J(`engine.inspector.widget.datasetHint`,o)})]}),d&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(eo,{label:J(`engine.inspector.widget.dimensions`,o),emptyText:J(`engine.inspector.widget.dimensionsHint`,o),names:f,options:y,loading:g.loading,error:g.error,readOnly:a,onCommit:e=>w({dimensions:e})}),(0,X.jsx)(eo,{label:J(`engine.inspector.widget.values`,o),emptyText:J(`engine.inspector.widget.valuesHint`,o),names:m,options:v,loading:g.loading,error:g.error,readOnly:a,onCommit:e=>w({values:e})})]})]}),x.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:J(`engine.inspector.widget.filterBindingsSection`,o)}),(0,X.jsx)(`p`,{className:`text-[10px] leading-snug text-muted-foreground`,children:J(`engine.inspector.widget.filterBindingsHint`,o)}),x.map(e=>{let t=S.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,w({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)(I,{className:`text-xs font-medium text-muted-foreground truncate`,children:p(e.label,o)||e.name}),(0,X.jsx)(U,{label:J(`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)(ws,{ariaLabel:q(`engine.inspector.widget.filterBindingField`,o,{filter:p(e.label,o)||e.name}),value:i,onCommit:e=>s(e||void 0),options:b,placeholder:q(`engine.inspector.widget.filterBindingDefault`,o,{field:e.field}),searchPlaceholder:`Search fields…`,disabled:a,mono:!0})}),i&&!a&&(0,X.jsx)(B,{type:`button`,variant:`ghost`,size:`sm`,className:`h-8 shrink-0 px-2 text-[10px] text-muted-foreground`,onClick:()=>s(void 0),children:J(`engine.inspector.widget.filterBindingReset`,o)})]})]},e.name)})]}),(0,X.jsx)(d_,{id:`widget-color`,labelling:`group`,label:J(`engine.inspector.widget.color`,o),children:(0,X.jsx)(ua,{ariaLabelledBy:u_(`widget-color`),value:S.colorVariant??`default`,onChange:e=>w({colorVariant:e}),disabled:a,options:s_.map(e=>({value:e}))})}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsx)(d_,{id:`widget-w`,label:J(`engine.inspector.widget.width`,o),children:(0,X.jsx)(R,{id:`widget-w`,type:`number`,min:1,value:S.layout?.w??1,onChange:e=>w({layout:{...S.layout??{},w:Number(e.target.value)||1}}),disabled:a})}),(0,X.jsx)(d_,{id:`widget-h`,label:J(`engine.inspector.widget.height`,o),children:(0,X.jsx)(R,{id:`widget-h`,type:`number`,min:1,value:S.layout?.h??1,onChange:e=>w({layout:{...S.layout??{},h:Number(e.target.value)||1}}),disabled:a})})]}),!a&&(0,X.jsx)(`div`,{className:`pt-2 border-t`,children:(0,X.jsx)(B,{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(C,1),n({widgets:t}),r()},children:J(`engine.inspector.widget.remove`,o)})})]})}var u_=e=>`${e}-label`;function d_({id:e,label:t,labelling:n=`control`,children:r}){return(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(I,{...n===`group`?{id:u_(e)}:{htmlFor:e},className:`text-xs font-medium text-muted-foreground`,children:t}),r]})}function f_({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)(B,{type:`button`,variant:`outline`,size:`sm`,onClick:t,children:J(`engine.inspector.widget.close`,n)})]})}var p_={"zh-CN":{metadataForms:{dashboard:{label:`仪表板`,sections:{basics:{label:`基本信息`,description:`仪表板的名称与描述。`},layout:{label:`布局`,description:`栅格尺寸与刷新频率。`},widgets:{label:`组件`,description:`放在栅格上的卡片与图表。`},filters:{label:`筛选`,description:`应用到全部组件的默认筛选与全局筛选。`},advanced:{label:`高级`,description:`无障碍与性能调优。`}},fields:{name:{label:`名称`,helpText:`snake_case 唯一标识`},label:{label:`显示名称`,helpText:`展示给使用者的名称`},description:{label:`描述`},columns:{label:`列数`,helpText:`栅格列数(默认 12)`},gap:{label:`间距`,helpText:`组件之间的间距,数值越大越松`},refreshInterval:{label:`自动刷新`,helpText:`自动刷新间隔(秒),0 表示不自动刷新`},header:{label:`页眉`,helpText:`页眉设置:标题、描述与操作按钮`},"header.showTitle":{label:`显示标题`,helpText:`在页眉中显示仪表板名称`},"header.showDescription":{label:`显示描述`,helpText:`在页眉中显示仪表板描述`},"header.actions":{label:`操作按钮`,helpText:`显示在页眉里的操作按钮`},widgets:{label:`组件`,helpText:`仪表板组件,含位置与尺寸`},dateRange:{label:`日期范围`,helpText:`默认的日期范围选择器`},globalFilters:{label:`全局筛选`,helpText:`应用到全部组件的筛选条件`}}}}}};function m_(e){return so(e)?`zh-CN`:void 0}function h_(e,t,n){if(!e)return e;let r=m_(n);return r?b(e,t,p_,{locale:r}):e}var g_={io:`input`,unrepresentable:`any`},__=new Set([`widgets`,`label`,`description`,`name`]),v_,y_=!1;function b_(){if(v_||y_)return v_;try{v_=Wi(S,g_)}catch(e){y_=!0,typeof console<`u`&&console.warn(`[dashboard-schema] failed to derive Dashboard JSONSchema from spec`,e)}return v_}var x_=new Map;function S_(e){let t=String(e??``);if(x_.has(t))return x_.get(t);if(!(!g||typeof g!=`object`))try{let n=JSON.parse(JSON.stringify(g));for(let e of n.sections??[])e.fields=(e.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!__.has(t)});n.sections=(n.sections??[]).filter(e=>(e.fields??[]).length>0);let r=h_(n,`dashboard`,e);return x_.set(t,r),r}catch(e){typeof console<`u`&&console.warn(`[dashboard-schema] failed to prepare dashboardForm from spec`,e);return}}var C_=new Set([`name`,`label`,`description`,`widgets`]);function w_({draft:e,onPatch:t,readOnly:n,locale:r,onSelectionChange:i,serverSchema:a}){let o=Y.useCallback(e=>J(e,r),[r]),s=typeof e.label==`string`?e.label:``,c=typeof e.description==`string`?e.description:``,l=Y.useMemo(()=>Array.isArray(e.widgets)?e.widgets:[],[e.widgets]),u=e=>{let n=Ss(`widget`,l.map(e=>e?.id).filter(Boolean)),r=Md[e],a=r?`New ${r.label.toLowerCase()}`:`New widget`,o={id:n,type:e,title:a,...r?.defaults??{}};t({widgets:no(l,o)}),i?.({kind:`widget`,id:n,label:a})},d=e=>{t({widgets:K(l,e,null)})},f=(e,n)=>{e!==n&&t({widgets:Ha(l,e,n)})},m=(e,t)=>{e?.id&&i?.({kind:`widget`,id:e.id,label:p(e.title,r)||e.id||`Widget ${t+1}`})},[h,g]=Y.useState(null),[_,v]=Y.useState(null),{schema:y,form:b}=Y.useMemo(()=>Va({bundledSchema:b_(),bundledForm:S_(r),serverSchema:a,excludeFields:C_,sectionTitle:J(`engine.inspector.moreFields`,r)}),[a,r]);return(0,X.jsxs)(Ba,{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)(G,{label:o(`engine.inspector.dashboard.label`),value:s,onCommit:e=>t({label:e}),placeholder:o(`engine.inspector.dashboard.labelPlaceholder`),disabled:n}),(0,X.jsx)(G,{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)(I,{className:`text-xs text-muted-foreground`,children:o(`engine.inspector.dashboard.widgets`)}),(0,X.jsx)(z,{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 i=Md[e?.type]?.icon??Fd;return(0,X.jsxs)(`div`,{draggable:!n,onDragStart:()=>g(t),onDragEnd:()=>{g(null),v(null)},onDragOver:e=>{e.preventDefault(),v(t)},onDrop:()=>{h!=null&&h!==t&&f(h,t),g(null),v(null)},className:`group flex items-center gap-2 rounded-md border px-2 py-1.5 text-xs hover:bg-accent`+(_===t&&h!==null&&h!==t?` border-primary`:``),children:[!n&&(0,X.jsx)(mt,{className:`h-3.5 w-3.5 shrink-0 cursor-grab text-muted-foreground`}),(0,X.jsx)(i,{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:()=>m(e,t),title:p(e?.title,r)||e?.id,children:p(e?.title,r)||e?.id||`Widget ${t+1}`}),(0,X.jsx)(`code`,{className:`text-[10px] text-muted-foreground`,children:e?.type}),!n&&(0,X.jsx)(B,{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)(_r,{className:`h-3.5 w-3.5`})})]},e?.id??t)})}),!n&&(0,X.jsx)(Id,{onAdd:u,label:o(`engine.inspector.add.widget`)})]}),(0,X.jsx)(`div`,{className:`border-t pt-3`,children:y?(0,X.jsx)(Na,{schema:y,form:b,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 T_=new Set([`object`,`object-field`,`flow`,`org-membership-level`,`position`,`node`,`user`,`team`,`queue`,`department`,`manager`,`connector`,`email-template`]);function E_(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 D_(e){if(!e||typeof e!=`object`)return;let t={};for(let[n,r]of Object.entries(e)){let e=E_(r);e&&(t[n]=e)}return Object.keys(t).length?t:void 0}function O_(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`&&T_.has(r)&&(e[n]=r);if(Object.keys(e).length===0)return;let r=D_(t.sources);return{kindFrom:t.kindFrom,map:e,...n,...r?{sources:r}:{}}}if(typeof t.kind==`string`&&T_.has(t.kind))return{kind:t.kind,...n}}function k_(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 A_(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function j_(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 M_(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:k_(e)}))}function N_(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 P_(e){return e.xExpression===`expression`||e.xExpression===`template`?e.xExpression:void 0}function F_(e){if(Array.isArray(e.enum))return{kind:`select`};let t=j_(e);if(t===`boolean`)return{kind:`boolean`};if(t===`number`||t===`integer`)return{kind:`number`};if(t===`string`){let t=e.format===`multiline`,n=P_(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 I_=4;function L_(e,t){let n=A_(e.items)?e.items:void 0,r=n?j_(n):void 0;return n&&r===`object`&&A_(n.properties)?t>=I_?null:{kind:`objectList`,columns:R_(n,t+1)}:r===`string`?{kind:`stringList`}:r===`number`||r===`integer`?{kind:`numberList`}:null}function R_(e,t=0){let n=e.properties??{},r=[];for(let[e,i]of Object.entries(n)){if(!A_(i))continue;let n=j_(i);if(n===`array`){let n=L_(i,t);if(n){r.push({key:e,label:i.title||k_(e),kind:n.kind,...n.columns?{columns:n.columns}:{},...i.description?{placeholder:i.description}:{}});continue}}let a,o,s=O_(i);s?a=`reference`:Array.isArray(i.enum)?(a=`select`,o=M_(i.enum,i.xEnumDeprecated)):a=n===`boolean`?`boolean`:P_(i)===`expression`?`expression`:`text`,r.push({key:e,label:i.title||k_(e),kind:a,...o?{options:o}:{},...s?{ref:s}:{},...i.description?{placeholder:i.description}:{}})}return r}function z_(e,t){return{label:e.title||k_(t),...e.description?{help:e.description}:{},...N_(e)?{defaultValue:N_(e)}:{}}}function B_(e){if(!A_(e)||j_(e)!==`object`||!A_(e.properties))return null;let t=[];for(let[n,r]of Object.entries(e.properties)){if(!A_(r))continue;let e=j_(r);if(e===`array`){let e=A_(r.items)?r.items:void 0,i=e?j_(e):void 0;e&&i===`object`&&A_(e.properties)?t.push({id:n,path:[`config`,n],kind:`objectList`,columns:R_(e),...z_(r,n)}):i===`string`?t.push({id:n,path:[`config`,n],kind:`stringList`,...z_(r,n)}):(i===`number`||i===`integer`)&&t.push({id:n,path:[`config`,n],kind:`numberList`,...z_(r,n)});continue}if(e===`object`&&A_(r.properties)){let e=Object.entries(r.properties).filter(([,e])=>A_(e)),i=e.some(([e,t])=>e===`enabled`&&j_(t)===`boolean`);for(let[a,o]of e){let e=o,s=O_(e),c=s?void 0:F_(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||k_(n),...r.description?{help:r.description}:{},...N_(e)?{defaultValue:N_(e)}:{}}:z_(e,a),...s?{ref:s}:{},...c?.refMode?{refMode:c.refMode}:{},...l===`select`&&Array.isArray(e.enum)?{options:M_(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`,...z_(r,n)});continue}let i=O_(r);if(i){t.push({id:n,path:[`config`,n],kind:`reference`,ref:i,...z_(r,n)});continue}let a=F_(r);a&&t.push({id:n,path:[`config`,n],kind:a.kind,...z_(r,n),...a.refMode?{refMode:a.refMode}:{},...a.kind===`select`&&Array.isArray(r.enum)?{options:M_(r.enum,r.xEnumDeprecated)}:{}})}return t}var V_=[`connectorConfig`,`input`],H_=V_.join(`.`),U_=H_;function W_(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function G_(e,t,n){if(!Array.isArray(e)||!t||!n)return;let r=e.find(e=>W_(e)&&e.name===t);if(!r||!Array.isArray(r.actions))return;let i=r.actions.find(e=>W_(e)&&e.key===n)?.inputSchema;return W_(i)?i:void 0}function K_(e){let t={...e,id:`${H_}.${e.id}`,path:[...V_,...e.path.slice(1)]};return e.showWhen&&(t.showWhen={...e.showWhen,field:`${H_}.${e.showWhen.field}`}),t}function q_(e){let t=B_(e);if(!t||t.length===0)return null;let n=t.map(K_),r=[];for(let e of n){let t=e.path[V_.length];t&&!r.includes(t)&&r.push(t)}return{fields:n,declaredKeys:r,open:(W_(e)?e.additionalProperties:void 0)!==!1}}function J_(e,t){if(!W_(e))return{};let n={};for(let[r,i]of Object.entries(e))t.includes(r)||(n[r]=i);return n}function Y_(e,t,n){let r=W_(e)?e:{},i={};for(let[e,a]of Object.entries(r))n.includes(e)?i[e]=a:Object.prototype.hasOwnProperty.call(t,e)&&(i[e]=t[e]);for(let[e,n]of Object.entries(t))Object.prototype.hasOwnProperty.call(i,e)||(i[e]=n);return Object.keys(i).length?i:void 0}function X_(e,t,n){if(!t||Array.isArray(n))return e;let r=e.findIndex(e=>e.id===U_);if(r===-1)return e;let i=e[r],a=Object.keys(J_(n,t.declaredKeys)).length>0,o=t.open||a;return[...e.slice(0,r),...t.fields,...o?[{...i,omitKeys:t.declaredKeys}]:[],...e.slice(r+1)]}function Z_(e){let[t,n]=Y.useState([]);return Y.useEffect(()=>{if(!e)return;let t=!1,r=new AbortController;return(async()=>{try{let e=await fetch(`${il()}/automation/connectors`,{credentials:`include`,headers:{Accept:`application/json`},signal:r.signal});if(!e.ok)return;let i=await e.json(),a=i?.data?.connectors??i?.connectors??[];!t&&Array.isArray(a)&&n(a)}catch{}})(),()=>{t=!0,r.abort()}},[e]),t}var Q_=e=>Pa(e),$_=e=>typeof e.expression==`string`?e.expression.trim():``,ev=e=>typeof e.label==`string`?e.label.trim():``,tv=e=>typeof e.target==`string`?e.target.trim():``,nv=e=>{let t=$_(e);return t===``||t===`true`};function rv(e){return Array.isArray(e)?e.filter(e=>e&&typeof e==`object`&&!Array.isArray(e)):[]}function iv(e,t){if(nv(e))return t.isDefault===!0;let n=$_(e),r=Q_(t.condition);if(n&&r===n)return!0;let i=ev(e);return i!==``&&t.label===i}var av=e=>t=>t.source===e&&t.type!==`fault`&&t.type!==`back`;function ov(e,t){let n=$_(t),r=ev(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 sv(e,t,n){let r=rv(t),i=av(e),a=0;return n.map(e=>{if(!i(e))return e;let t=r[a++];return t?ov(e,t):e})}function cv(e,t,n){let r=rv(t);if(r.length===0)return r;let i=n.map((e,t)=>t).filter(t=>av(e)(n[t])),a=new Set,o=new Map;return r.forEach((e,t)=>{let r=i.find(t=>!a.has(t)&&iv(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 lv(e,t,n){let r=rv(t),i=r.map(e=>{let{target:t,...n}=e;return n});if(!r.some(e=>tv(e)!==``))return{conditions:i,edges:sv(e,i,n)};let a=n.map((e,t)=>t).filter(t=>av(e)(n[t])),o=new Set,s=new Map,c=[(e,t)=>t.target===tv(e)&&iv(e,t),(e,t)=>t.target===tv(e),(e,t)=>iv(e,t)];for(let e of c)r.forEach((t,r)=>{if(s.has(r)||tv(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,f=n.map(e=>e.id);return r.forEach((t,r)=>{let i=tv(t);if(i===``){let e=a.find(e=>!o.has(e)&&iv(t,n[e]));e!==void 0&&(o.add(e),d.add(e));return}let c=s.get(r);if(c!==void 0){l.set(c,ov({...n[c],target:i},t));return}let p=Ss(`edge`,f);f.push(p),u.push(ov({id:p,source:e,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 uv(e,t){return t===`template`?`{${e}}`:e}function dv(e,t,n,r,i){let a=uv(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`,pv=`Search references…`,mv=`No matching references.`;function hv({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=Y.useRef(null),p=Y.useRef({start:0,end:0}),[m,h]=Y.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}=dv(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:V(`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:V(`h-8 pr-8 text-sm`,u&&`font-mono`)}),y&&!s&&(0,X.jsxs)(Dt,{open:m,onOpenChange:h,children:[(0,X.jsx)(Ke,{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)(Tt,{className:`h-3.5 w-3.5`})})}),(0,X.jsx)(Lt,{align:`end`,className:`w-72 p-0`,onCloseAutoFocus:e=>e.preventDefault(),children:(0,X.jsxs)(Ur,{children:[(0,X.jsx)(pr,{placeholder:pv,className:`h-9`}),(0,X.jsxs)(Gn,{children:[(0,X.jsx)(Bn,{children:mv}),a.map(e=>(0,X.jsx)(Tr,{heading:e.label,children:e.refs.map(t=>(0,X.jsxs)(Yn,{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:uv(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 gv({value:e,role:t,scopeGroups:n}){let r=t===`template`?null:Ip(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?kp(n.flatMap(e=>e.refs)):null,a=i?Mp(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:Np(a)}):null}function _v(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 yv(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 bv(e){return Array.isArray(e)?e.filter(e=>_v(e)).map(e=>{let t=e.variable??e.name??e.key;return[typeof t==`string`?t:``,e.value]}):_v(e)?Object.entries(e):[]}function xv(e,t){let n=[...t];return bv(e).map(([e,t])=>{let r=Ss(`kv`,n);return n.push(r),{id:r,key:e,raw:vv(t)}})}function Sv(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:yv(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]=yv(t.raw))}return r}function Cv(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 wv({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=Y.useMemo(()=>Cv(Sv(xv(t,[]),d)),[t,d]),[p,m]=Y.useState(()=>xv(t,[])),h=Y.useRef(f);Y.useEffect(()=>{f!==h.current&&(m(xv(t,[])),h.current=f)},[f,t]);let g=e=>{let t=Sv(e,d);h.current=Cv(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:Ss(`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)(I,{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)(hv,{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)(B,{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)(_r,{className:`h-3.5 w-3.5`})})]}),(0,X.jsx)(gv,{value:e.raw,role:`template`,scopeGroups:u})]},e.id))]}),(0,X.jsxs)(B,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:v,disabled:r,children:[(0,X.jsx)(L,{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 Tv(e,t){let n=[...t];return e.map(e=>{let t=Ss(`sl`,n);return n.push(t),{id:t,value:e}})}function Ev(e){return e.map(e=>e.value.trim()).filter(e=>e!==``)}function Dv({label:e,value:t,onCommit:n,disabled:r,addLabel:i,itemLabel:a,removeLabel:o,emptyLabel:s}){let c=Y.useMemo(()=>Array.isArray(t)?t.map(e=>String(e)):[],[t]),[l,u]=Y.useState(()=>Tv(c,[])),d=Y.useRef(JSON.stringify(c));Y.useEffect(()=>{let e=JSON.stringify(c);e!==d.current&&(u(Tv(c,[])),d.current=e)},[c]);let f=e=>{let t=Ev(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:Ss(`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)(I,{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)(B,{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)(_r,{className:`h-3.5 w-3.5`})})]},e.id))]}),(0,X.jsxs)(B,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:m,disabled:r,children:[(0,X.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),i]})]})}var Ov={object:`object`,flow:`flow`,connector:`connector`,"email-template":`email_template`},kv=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=C[e];return!n||n.source!==`data`?[]:[[e,{object:n.object,valueField:n.valueField,...t}]]})),Av=_.map(({value:e,label:t})=>({value:e,label:t}));function jv(e){let t=Av.find(t=>t.value===e);return t?t.label:e.split(`_`).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(` `)}function Mv(e){return e?.source===`enum`&&e.values.length>0?e.values.map(e=>({value:e,label:jv(e)})):Av}function Nv(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 Pv(e){if(!e)return;let t=kv[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 Fv(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 Iv(e,t,n){if(e!==`object-field`)return;let r=t||`$trigger`;return r===`$trigger`?Fv((Array.isArray(n.draft.nodes)?n.draft.nodes:[]).find(e=>e?.type===`start`),`objectName`):Fv(n.node,r)}function Lv(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 Rv(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 zv(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 Bv(e){let t=yi(),[n,r]=Y.useState({options:[],loading:!!e});return Y.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 Vv(e){let[t,n]=Y.useState({options:[],loading:!!e});return Y.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:Rv(a?.actions),loading:!1})}).catch(()=>{t||n({options:[],loading:!1})}),()=>{t=!0}},[e]),t}function Hv(e){let[t,n]=Y.useState({options:[]});return Y.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:zv(r)})}).catch(()=>{t||n({options:[]})}),()=>{t=!0}},[e]),t}function Uv({binding:e,value:t,onPick:n,onCommit:r,onBlur:i,disabled:a,placeholder:o}){let s=F(),[c,l]=Y.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)(B,{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)(Dn,{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)(tt,{value:u||null,onChange:e=>n(e==null?``:String(e)),readonly:a,dataSource:s,field:{type:`lookup`,name:`value`,reference_to:e.object,displayField:e.displayField,idField:e.valueField,multiple:!1,allow_create:!1,placeholder:o,...e.picker?{picker:e.picker}:{},...e.subtitle?{subtitle:e.subtitle}:{}}})}),(0,X.jsx)(B,{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)(Ft,{className:`h-3.5 w-3.5`})})]})}function Wv({resolved:e,value:t,onCommit:n,onBlur:r,onSelect:i,disabled:a,placeholder:o,context:s,showHint:c=!0}){let l=Y.useId(),u=s??{draft:{},node:null},d=e?.kind,f=i??(e=>{n(e),r?.()}),p=e?Iv(e.kind,e.objectSource,u):void 0,{fields:m}=la(d===`object-field`?p:void 0),h=e?Lv(e.kind,e.connectorSource,u):void 0,{options:g}=Vv(d===`connector-action`?h:void 0),{options:_}=Hv(d===`connector`),v=d&&d!==`object-field`&&d!==`node`&&d!==`connector-action`&&d!==`connector`?Ov[d]:void 0,{options:y}=Bv(v),b=Y.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=Pv(e);if(C)return(0,X.jsx)(Uv,{binding:C,value:t,onPick:f,onCommit:n,onBlur:r,disabled:a,placeholder:o});if(d===`org-membership-level`){let n=t==null?``:String(t),r=Mv(e?.source),i=n&&!r.some(e=>e.value===n)?[...r,{value:n,label:`${n} (invalid)`}]:r;return(0,X.jsxs)(Qr,{value:n||void 0,onValueChange:f,disabled:a,children:[(0,X.jsx)(Fe,{className:`h-8 w-full text-sm`,children:(0,X.jsx)(jt,{placeholder:o??`—`})}),(0,X.jsx)(tn,{children:i.map(e=>(0,X.jsx)(He,{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 Gv({field:e,value:t,onCommit:n,disabled:r,context:i}){let a=i?.node??null,o=Nv(e.ref,e=>Fv(a,e));return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{className:`text-xs text-muted-foreground`,children:e.label}),(0,X.jsx)(Wv,{resolved:o,value:t,onCommit:n,disabled:r,placeholder:e.placeholder,context:i})]})}function Kv(e){return e===`stringList`||e===`numberList`||e===`objectList`}function qv(e,t){let n=[];return e.map(e=>{let r=Ss(`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:Kv(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 Jv(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):Kv(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 Yv({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=Y.useMemo(()=>Array.isArray(n)?n.filter(e=>e&&typeof e==`object`):[],[n]),[p,m]=Y.useState(()=>qv(f,t)),h=Y.useRef(JSON.stringify(f));Y.useEffect(()=>{let e=JSON.stringify(f);e!==h.current&&(m(qv(f,t)),h.current=e)},[f,t]);let g=e=>{let n=Jv(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]=Y.useState(0);Y.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:Kv(n.kind)?[]:``;m(t=>[...t,{id:Ss(`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)(I,{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)(B,{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)(_r,{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)(Dv,{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)(Yv,{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)(I,{className:`w-24 shrink-0 text-[11px] text-muted-foreground`,children:t.label}),t.kind===`boolean`?(0,X.jsx)(Le,{checked:e.values[t.key]===!0,onCheckedChange:n=>b(e.id,t.key,n===!0),disabled:i}):t.kind===`reference`?(()=>{let n=Nv(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)(hv,{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)(gv,{value:n,role:`value`,scopeGroups:d})]})}return(0,X.jsx)(`div`,{className:`flex-1`,children:(0,X.jsx)(Wv,{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)(Qr,{value:n||void 0,onValueChange:n=>b(e.id,t.key,n),disabled:i,children:[(0,X.jsx)(Fe,{className:`h-8 w-full text-xs`,children:(0,X.jsx)(jt,{placeholder:t.placeholder??`—`})}),(0,X.jsx)(tn,{children:a.map(e=>(0,X.jsx)(He,{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)(hv,{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)(gv,{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)(B,{type:`button`,variant:`outline`,size:`sm`,className:`h-7 w-full text-xs`,onClick:x,disabled:i,children:[(0,X.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),a]})]})}var Xv=[];function Zv({field:e,value:t,onCommit:n,disabled:r,locale:i,context:a,scopeGroups:o,approvalScopeGroups:s,triggerScope:c,inactiveRetained:l,onClearInactive:u}){let d=e.refMode??(e.kind===`expression`?`expression`:`template`),f=e.kind===`expression`&&!!e.conditionBuilder&&!!c&&d!==`template`,p=(()=>{if(f&&c)return(0,X.jsx)(da,{label:e.label,value:t==null?``:String(t),onCommit:e=>n(e),objectName:c.objectName,disabled:r,subjects:{fieldPrefix:c.fieldPrefix,includePrevious:c.includePrevious,context:Xv}});switch(e.kind){case`reference`:return(0,X.jsx)(Gv,{field:e,value:t,onCommit:e=>n(e),disabled:r,context:a});case`keyValue`:return(0,X.jsx)(wv,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:J(`engine.inspector.flowNode.kv.add`,i),keyLabel:J(`engine.inspector.flowNode.kv.key`,i),valueLabel:J(`engine.inspector.flowNode.kv.value`,i),removeLabel:J(`engine.inspector.flowNode.kv.remove`,i),emptyLabel:J(`engine.inspector.flowNode.kv.empty`,i),scopeGroups:o});case`stringList`:return(0,X.jsx)(Dv,{label:e.label,value:t,onCommit:e=>n(e),disabled:r,addLabel:J(`engine.inspector.flowNode.list.add`,i),itemLabel:J(`engine.inspector.flowNode.list.item`,i),removeLabel:J(`engine.inspector.flowNode.list.remove`,i),emptyLabel:J(`engine.inspector.flowNode.list.empty`,i)});case`numberList`:return(0,X.jsx)(Dv,{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:J(`engine.inspector.flowNode.list.add`,i),itemLabel:J(`engine.inspector.flowNode.list.item`,i),removeLabel:J(`engine.inspector.flowNode.list.remove`,i),emptyLabel:J(`engine.inspector.flowNode.list.empty`,i)});case`objectList`:return(0,X.jsx)(Yv,{label:e.label,columns:e.columns??[],value:t,onCommit:e=>n(e),disabled:r,addLabel:J(`engine.inspector.flowNode.list.add`,i),removeLabel:J(`engine.inspector.flowNode.list.remove`,i),emptyLabel:J(`engine.inspector.flowNode.list.empty`,i),itemLabel:J(`engine.inspector.flowNode.list.item`,i),context:a,scopeGroups:o,approvalScopeGroups:s});case`number`:return(0,X.jsx)(Za,{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)(U,{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)(W,{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)(I,{className:`text-xs text-muted-foreground`,children:e.label}),(0,X.jsx)(hv,{multiline:!0,rows:4,mode:d,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)(I,{className:`text-xs text-muted-foreground`,children:e.label}),(0,X.jsx)(hv,{mode:d,mono:e.kind===`expression`,value:t==null?``:String(t),onValueChange:e=>n(e),groups:o??[],placeholder:e.placeholder,disabled:r})]})}})(),m=d===`template`,h=e.kind===`expression`&&!m?Ip(`predicate`,t):null,g=e.kind===`expression`?m?`template`:`predicate`:d===`template`&&(e.kind===`text`||e.kind===`textarea`)?`template`:null,_=!h&&g&&o&&o.length>0?Mp(t,g,kp(o.flatMap(e=>e.refs))):[];return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[p,l&&(0,X.jsxs)(`div`,{className:`flex items-start gap-2 rounded border border-amber-500/40 bg-amber-500/10 px-2 py-1.5`,role:`note`,"data-testid":`inactive-retained`,"data-inactive-retained":l,children:[(0,X.jsx)(`p`,{className:`flex-1 text-[11px] leading-snug text-amber-700 dark:text-amber-400`,children:J(l===`no-controller`?`engine.inspector.flowNode.inactiveRetainedOrphan`:`engine.inspector.flowNode.inactiveRetained`,i)}),u&&(0,X.jsx)(B,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 shrink-0 px-2 text-[11px] text-amber-700 dark:text-amber-400`,onClick:u,disabled:r,children:J(`engine.inspector.flowNode.inactiveRetainedClear`,i)})]}),h&&(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-destructive`,role:`alert`,children:h.message}),!h&&_.length>0&&(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:Np(_,i)}),e.help&&!h&&_.length===0&&(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:e.help})]})}var Qv=[`variables`,`outputs`,`loop`,`trigger`],$v={variables:`Flow variables`,outputs:`Upstream outputs`,loop:`Loop item`,trigger:`Trigger record`};function ey(e,t,n){let r=Y.useMemo(()=>Tp(e??{},t),[e,t]),{fields:i,loading:a}=la(r.trigger?.objectName);return Y.useMemo(()=>{let e=[...r.refs];n&&n.length&&e.push(...n),r.trigger&&e.push(...Ep(r.trigger,i));let t=new Set,o=e.filter(e=>!t.has(e.token)&&(t.add(e.token),!0)),s=Qv.map(e=>({id:e,label:$v[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),trigger:r.trigger,loading:!!r.trigger&&a,isEmpty:o.length===0}},[r,i,a,n])}var ty=[`description`];function ny(e){if(!ty.some(t=>t in e))return e;let t={...e};for(let e of ty)delete t[e];return t}function ry(e){return e.kind===`objectList`&&dp(e)===`conditions`&&(e.columns??[]).some(e=>e.key===`target`)}function iy(e){let t=e?.config;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}function ay(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=ay(e&&typeof e==`object`&&!Array.isArray(e)?e:{},i,n);Object.keys(t).length===0?delete a[r]:a[r]=t}return a}function oy({selection:e,draft:t,onPatch:n,onClearSelection:r,locale:i,readOnly:a}){let o=Y.useMemo(()=>hm(t,e),[t,e]),s=o?.node??null,c=Xf(),l=Y.useMemo(()=>o?.nested&&o.container?Cp(o.container).filter(e=>e.group===`loop`):[],[o]),{groups:u,approvalExpressionGroups:d,trigger:f}=ey(t,o?.scopeAnchorId,l),{connectorId:p,actionId:m,storedInput:h}=Y.useMemo(()=>{let e=s?.connectorConfig;if(!e||typeof e!=`object`||Array.isArray(e))return{};let t=e;return{connectorId:typeof t.connectorId==`string`&&t.connectorId?t.connectorId:void 0,actionId:typeof t.actionId==`string`&&t.actionId?t.actionId:void 0,storedInput:t.input}},[s]),g=Z_(!!p&&!!m),_=Y.useMemo(()=>q_(G_(g,p,m)),[g,p,m]),v=s?.type,y=Y.useMemo(()=>{let e=v?c[v]:void 0,t=op(e===void 0?null:B_(e),v);return X_(lp(v,t,i),_,h)},[c,v,i,_,h]),b=iy(s),x=y.filter(e=>fp(e,s,y)),S=Y.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]),C=Y.useMemo(()=>{let e=new Set;for(let t of y){let n=dp(t);n&&e.add(n),t.fallbackPath&&t.fallbackPath.length>=2&&t.fallbackPath[0]===`config`&&e.add(t.fallbackPath[1])}return e},[y]),w=Y.useMemo(()=>{let e=Object.fromEntries(Object.entries(b).filter(([e])=>!C.has(e)));return Object.keys(e).length?JSON.stringify(e,null,2):``},[s,C]),[T,E]=Y.useState(w),[D,O]=Y.useState(null),[k,A]=Y.useState(w.trim()!==``),[j,M]=Y.useState(!1);if(Y.useEffect(()=>{E(w),O(null),A(w.trim()!==``),M(!1)},[w]),!s){let t=(e.kind===`nested-node`?sm(e.id):null)?.nodeId??e.id;return(0,X.jsx)(Ba,{kindLabel:J(`engine.inspector.flowNode.kind`,i),title:e.label??t,onClose:r,closeLabel:J(`engine.inspector.flowNode.close`,i),children:(0,X.jsx)(Wa,{message:t})})}let N=e=>{let t=o?.write(ny({...s,...e}));t&&n(t)},P=w.trim()!==``,ee=s.type===`screen`||s.type===`user_task`,te=(e,r)=>{if(!o)return;let i=e.path,a=r,c;if(e.omitKeys&&(a=Y_(up(s,e),r&&typeof r==`object`&&!Array.isArray(r)?r:{},e.omitKeys)),!o.nested){let n=Array.isArray(t.edges)?t.edges:[];if(ry(e)){let e=lv(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=sv(s.id,r,n))}let l=ay(s,i,a);e.fallbackPath&&(l=ay(l,e.fallbackPath,void 0));let u=o.write(ny(l));u&&(c&&(u.edges=c),n(u))},ne=()=>{try{let e=T.trim()===``?{}:JSON.parse(T);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Must be a JSON object`);let t=Object.fromEntries(Object.entries(b).filter(([e])=>C.has(e))),r=Object.fromEntries(Object.entries(e).filter(([e])=>!C.has(e))),i={...t,...r};O(null);let a={...s};Object.keys(i).length===0?delete a.config:a.config=i;let c=o?.write(ny(a));c&&n(c)}catch(e){O(String(e.message))}},re=()=>{let e=o?.write(null);e&&n(e),r()},ie=gp.includes(s.type)?[...gp]:[...gp,s.type??``].filter(Boolean),F=!!o?.nested;return(0,X.jsxs)(Ba,{kindLabel:J(`engine.inspector.flowNode.kind`,i),title:s.label||s.id,onClose:r,closeLabel:J(`engine.inspector.flowNode.close`,i),footer:F?void 0:(0,X.jsx)(Ja,{label:J(`engine.inspector.flowNode.remove`,i),onClick:re,disabled:a}),children:[F&&(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)(G,{label:J(`engine.inspector.flowNode.id`,i),value:s.id,onCommit:e=>N({id:e}),disabled:a||F,mono:!0}),F&&(0,X.jsx)(`p`,{className:`-mt-1 text-[11px] leading-snug text-muted-foreground`,children:J(`engine.inspector.flowNode.nestedIdHint`,i)}),(0,X.jsx)(G,{label:J(`engine.inspector.flowNode.label`,i),value:s.label??``,onCommit:e=>N({label:e}),disabled:a}),(0,X.jsx)(W,{label:J(`engine.inspector.flowNode.type`,i),value:s.type,options:ie.map(e=>({value:e,label:ao(e,i,e)})),onCommit:e=>N({type:e}),disabled:a}),y.length===0?(0,X.jsx)(`p`,{className:`pt-1 text-xs italic text-muted-foreground`,children:J(`engine.inspector.flowNode.noConfig`,i)}):x.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:J(`engine.inspector.flowNode.configuration`,i)}),(0,X.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),x.map(e=>{let n=ry(e),r=F&&n?{...e,columns:(e.columns??[]).filter(e=>e.key!==`target`)}:e,o=n&&!F?cv(s.id,up(s,e),Array.isArray(t.edges)?t.edges:[]):r.omitKeys?J_(up(s,r),r.omitKeys):up(s,r);return(0,X.jsx)(Zv,{field:r,value:o,onCommit:t=>te(e,t),disabled:a,locale:i,context:{draft:t,node:s},scopeGroups:u,approvalScopeGroups:d,triggerScope:f,inactiveRetained:hp(e,s,y),onClearInactive:a?void 0:()=>te(e,void 0)},e.id)}),ee&&(0,X.jsx)(Om,{node:s,variables:S,className:`mt-1`}),P||j?(0,X.jsxs)(`details`,{className:`group rounded border bg-muted/20`,open:k,onToggle:e=>A(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:J(`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:J(`engine.inspector.flowNode.advancedHint`,i)}),(0,X.jsx)(`textarea`,{value:T,onChange:e=>E(e.target.value),onBlur:ne,disabled:a,rows:6,placeholder:`{ }`,className:`w-full rounded border bg-background px-2 py-1.5 font-mono text-xs`}),D&&(0,X.jsx)(`div`,{className:`text-xs text-destructive`,children:D})]})]}):!a&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>{M(!0),A(!0)},className:`inline-flex items-center gap-1 self-start text-[11px] text-muted-foreground transition-colors hover:text-foreground`,children:[(0,X.jsx)(L,{className:`h-3 w-3`}),J(`engine.inspector.flowNode.advanced`,i)]})]})}function sy({label:e,value:t}){return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{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 cy({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)=>ba(t,n)===e.id),c=s>=0?o[s]:null,{groups:l}=ey(t,c?.source);if(!c)return(0,X.jsx)(Ba,{kindLabel:J(`engine.inspector.flowEdge.kind`,i),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.flowEdge.close`,i),children:(0,X.jsx)(Wa,{message:J(`engine.inspector.flowEdge.missing`,i)})});let u=e=>{let t={...c,...e};for(let e of[`label`,`condition`,`isDefault`]){let n=t[e];(n===void 0||n===``||n===!1)&&delete t[e]}(t.type==="default"||t.type===``||t.type===void 0)&&delete t.type,n({edges:K(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=Pa(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)(Ba,{kindLabel:J(`engine.inspector.flowEdge.kind`,i),title:e.label??`${c.source} → ${c.target}`,onClose:r,closeLabel:J(`engine.inspector.flowEdge.close`,i),footer:(0,X.jsx)(Ja,{label:J(`engine.inspector.flowEdge.remove`,i),onClick:()=>{n({edges:K(o,s,null)}),r()},disabled:a}),children:[(0,X.jsx)(sy,{label:J(`engine.inspector.flowEdge.source`,i),value:c.source}),(0,X.jsx)(sy,{label:J(`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:J(`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)(W,{label:J(`engine.inspector.flowEdge.branch`,i),value:g,options:[...p.map((e,t)=>{let n=m(e),r=h(e)||`Branch ${t+1}`,i=n===``||n===`true`?` · default`:` \u00b7 ${n}`;return{value:String(t),label:`${r}${i}`}}),{value:``,label:`— Custom —`}],onCommit:_,disabled:a}),v&&(0,X.jsx)(W,{label:J(`engine.inspector.flowEdge.approvalBranch`,i),value:b,options:[{value:`approve`,label:J(`engine.inspector.flowEdge.branchApprove`,i)},{value:`reject`,label:J(`engine.inspector.flowEdge.branchReject`,i)},{value:`revise`,label:J(`engine.inspector.flowEdge.branchRevise`,i)},{value:``,label:J(`engine.inspector.flowEdge.branchCustom`,i)}],onCommit:e=>{e&&u({label:e})},disabled:a}),(0,X.jsx)(G,{label:J(`engine.inspector.flowEdge.label`,i),value:c.label??``,onCommit:e=>u({label:e}),placeholder:J(`engine.inspector.flowEdge.labelHint`,i),disabled:a||d}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{className:`text-xs text-muted-foreground`,children:J(`engine.inspector.flowEdge.condition`,i)}),(0,X.jsx)(hv,{mode:`expression`,mono:!0,value:Pa(c.condition)??``,onValueChange:e=>u({condition:Ca(c.condition,e)}),groups:l,placeholder:J(`engine.inspector.flowEdge.conditionHint`,i),disabled:a||d})]}),(()=>{let e=d?null:Ip(`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?[]:Mp(Pa(c.condition),`predicate`,kp(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:Np(t,i)}):null})(),(0,X.jsx)(U,{label:J(`engine.inspector.flowEdge.isDefault`,i),value:d,onCommit:e=>u(e?{isDefault:!0,condition:void 0,label:void 0}:{isDefault:!1}),disabled:a}),(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-muted-foreground`,children:J(`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:J(`engine.inspector.flowEdge.connection`,i)}),(0,X.jsx)(`span`,{className:`h-px flex-1 bg-border`,"aria-hidden":!0})]}),(0,X.jsx)(W,{label:J(`engine.inspector.flowEdge.type`,i),value:x,options:[{value:`default`,label:J(`engine.inspector.flowEdge.typeDefault`,i)},{value:`conditional`,label:J(`engine.inspector.flowEdge.typeConditional`,i)},{value:`fault`,label:J(`engine.inspector.flowEdge.typeFault`,i)},{value:`back`,label:J(`engine.inspector.flowEdge.typeBack`,i)}],onCommit:e=>u({type:e}),disabled:a}),c.type===`back`&&(0,X.jsx)(`p`,{className:`text-[11px] leading-snug text-amber-600 dark:text-amber-400`,role:`note`,children:J(`engine.inspector.flowEdge.backHint`,i)})]})}function ly(e){return e.selection.kind===`edge`?(0,X.jsx)(cy,{...e}):(0,X.jsx)(oy,{...e})}var uy=[`object`,`page`,`dashboard`,`report`,`url`,`group`],dy=[`default`,`view`,`record`,`filters`],fy={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 py(e){return(e.pageType??e.type)!==`record`}var my=[`objectName`,`viewName`,`recordId`,`recordMode`,`filters`,`pageName`,`dashboardName`,`reportName`,`url`,`target`,`params`],hy=[`path`,`kind`,`href`,`route`,`object`,`page`,`dashboard`,`report`],gy={object:`object`,page:`page`,dashboard:`dashboard`,report:`report`,link:`url`,url:`url`,group:`group`};function _y(e){let t=e.type;if(typeof t==`string`&&uy.includes(t))return t;let n=e.kind;if(typeof n==`string`&&gy[n])return gy[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 vy(e){if(e.recordId)return`record`;let t=e.filters;return t&&typeof t==`object`&&!Array.isArray(t)?`filters`:e.viewName?`view`:`default`}function yy(e=[]){let t={};for(let n of[...my,...hy])e.includes(n)||(t[n]=void 0);return t}var by={default:[`objectName`],view:[`objectName`,`viewName`],record:[`objectName`,`recordId`,`recordMode`],filters:[`objectName`,`filters`]};function xy(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}`}function Sy(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 Cy(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 wy(e,t,n){let r=t[0].key,i=Array.isArray(e[r])?[...e[r]]:[];if(t.length===1)return{[r]:K(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=K(a,t[t.length-1].index,n);return o[o.length-1].node[t[t.length-1].key]=s,{[r]:i}}function Ty(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 Ey(e,t){let n=yi(),[r,i]=Y.useState({options:[],loading:!!e});return Y.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 Dy={currentUserId:`{current_user_id}`,currentOrgId:`{current_org_id}`};function Oy({objectName:e,filters:t,onCommit:n,disabled:r,locale:i}){let{fields:a}=la(e||void 0),o=Y.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:J(`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)(ws,{ariaLabel:J(`engine.inspector.appNav.filtersField`,i),value:e,onCommit:e=>c(n,e,t),options:o,placeholder:J(`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:J(`engine.inspector.appNav.filtersValue`,i),disabled:r,className:`h-7 w-0 min-w-0 flex-1 rounded border bg-background px-2 font-mono text-xs`,"data-testid":`nav-filter-value-${e||`new`}`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>l(n),disabled:r,className:`rounded p-1 text-muted-foreground hover:bg-muted`,"aria-label":J(`engine.inspector.appNav.filtersRemove`,i),"data-testid":`nav-filter-remove-${e||`new`}`,children:(0,X.jsx)(_r,{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)(L,{className:`h-3 w-3`}),J(`engine.inspector.appNav.filtersAdd`,i)]}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:J(`engine.inspector.appNav.filtersHint`,i)})]})}function ky({selection:e,draft:t,name:n,onPatch:r,onClearSelection:i,onSelectionChange:a,locale:o,readOnly:s}){let c=Sy(e.id),{node:l,parent:u,index:d}=c?Cy(t,c):{node:null,parent:[],index:-1},f=l?_y(l):null,p=l?vy(l):`default`,m=String(l?.objectName??l?.object??``),h=Ey(f===`object`?`object`:void 0),g=f&&f!==`object`?fy[f].metaType:void 0,_=Ey(g,g===`page`?py:void 0),v=Ey(f===`object`&&p===`view`?`view`:void 0),y=Y.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)(Ba,{kindLabel:J(`engine.inspector.appNav.kind`,o),title:e.label??e.id,onClose:i,closeLabel:J(`engine.inspector.appNav.close`,o),children:(0,X.jsx)(Wa,{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(wy(t,c,{...l,id:xy(l,u),...n?{type:n}:{},...e}))},S=e=>{let t=fy[e].targetKey,n=e===`object`?by.default:t?[t]:[];x({type:e,...yy(n)})},C=e=>{let t=yy(by[e]);x(e===`filters`?{...t,objectName:m,filters:l.filters??{}}:{...t,objectName:m})},w=()=>{r(wy(t,c,null)),i()},T=e=>{let n=Ha(u,d,e);r(Ty(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`?Yi({...l,type:f},`/apps/${n||`app`}`,Dy).href:null,D=fy[f??`group`];return(0,X.jsxs)(Ba,{kindLabel:J(`engine.inspector.appNav.kind`,o),title:String(b),onClose:i,closeLabel:J(`engine.inspector.appNav.close`,o),headerActions:(0,X.jsx)(Ga,{index:d,total:u.length,onMove:T,upLabel:J(`engine.inspector.reorder.up`,o),downLabel:J(`engine.inspector.reorder.down`,o),disabled:s}),footer:(0,X.jsx)(Ja,{label:J(`engine.inspector.appNav.remove`,o),onClick:w,disabled:s}),children:[(0,X.jsx)(G,{label:J(`engine.inspector.appNav.label`,o),value:String(l.label??l.title??l.name??``),onCommit:e=>x({label:e}),disabled:s}),(0,X.jsx)(G,{label:J(`engine.inspector.appNav.icon`,o),value:String(l.icon??``),onCommit:e=>x({icon:e}),disabled:s}),(0,X.jsx)(W,{label:J(`engine.inspector.appNav.typeField`,o),value:f??``,options:uy.map(e=>({value:e,label:J(`engine.inspector.appNav.type.${e}`,o)})),onCommit:e=>S(e),disabled:s}),f===`object`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ws,{label:J(`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)(W,{label:J(`engine.inspector.appNav.targetMode`,o),value:p,options:dy.map(e=>({value:e,label:J(`engine.inspector.appNav.mode.${e}`,o)})),onCommit:e=>C(e),disabled:s||!m}),p===`view`&&(0,X.jsx)(ws,{label:J(`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)(G,{label:J(`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:J(`engine.inspector.appNav.recordIdHint`,o)}),(0,X.jsx)(W,{label:J(`engine.inspector.appNav.recordMode`,o),value:String(l.recordMode??`view`),options:[{value:`view`,label:J(`engine.inspector.appNav.recordModeView`,o)},{value:`edit`,label:J(`engine.inspector.appNav.recordModeEdit`,o)}],onCommit:e=>x({recordMode:e}),disabled:s})]}),p===`filters`&&(0,X.jsx)(Oy,{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)(ws,{label:J(`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)(G,{label:J(`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)(W,{label:J(`engine.inspector.appNav.urlTarget`,o),value:String(l.target??`_self`),options:[{value:`_self`,label:J(`engine.inspector.appNav.urlTargetSelf`,o)},{value:`_blank`,label:J(`engine.inspector.appNav.urlTargetBlank`,o)}],onCommit:e=>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:J(`engine.inspector.appNav.preview`,o)}),(0,X.jsx)(`div`,{className:`break-all font-mono text-[11px]`,children:E})]})]})}var Ay=[`field`,`label`,`accessorKey`,`header`];function jy(e){let t=/^([a-zA-Z_][\w]*)\.columns\[(\d+)\]$/.exec(e);return t?{variant:t[1],index:Number(t[2])}:null}function My(e){return typeof e==`string`?{field:e}:e&&typeof e==`object`?e:{}}function Ny(e){return e.field??``}function Py(e){return e.label??Ny(e)}function Fy(e){return Object.keys(e).some(e=>!Ay.includes(e))}function Iy(e){if(!e)return``;let t=e.data;return t&&typeof t.object==`string`?t.object:typeof e.object==`string`?e.object:``}function Ly({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,locale:a,readOnly:o}){let s=jy(e.id),c=s?t[s.variant]:void 0,l=s&&Array.isArray(c?.columns)?c.columns:[],u=l.map(My),d=s?u[s.index]??null:null,f=s?typeof l[s.index]==`string`:!1,p=Y.useMemo(()=>ac(),[]),m=Iy(c),{fields:h}=la(m||void 0),g=d?Ny(d):``,_=Y.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)(Ba,{kindLabel:J(`engine.inspector.viewColumn.kind`,a),title:e.label??e.id,onClose:r,closeLabel:J(`engine.inspector.viewColumn.close`,a),children:(0,X.jsx)(Wa,{message:e.id})});let v=e=>{let t=e.map((e,t)=>{let n=typeof l[t]==`string`,r=Ny(e);return n&&!Fy(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(K(u,s.index,{...d,...r}))};return(0,X.jsxs)(Ba,{kindLabel:J(`engine.inspector.viewColumn.kind`,a),title:Py(d)||e.id,onClose:r,closeLabel:J(`engine.inspector.viewColumn.close`,a),headerActions:(0,X.jsx)(Ga,{index:s.index,total:u.length,onMove:e=>{v(Ha(u,s.index,e)),i?.({kind:`column`,id:`${s.variant}.columns[${e}]`,label:Py(d)||`columns[${e}]`})},upLabel:J(`engine.inspector.reorder.up`,a),downLabel:J(`engine.inspector.reorder.down`,a),disabled:o}),footer:(0,X.jsx)(Ja,{label:J(`engine.inspector.viewColumn.remove`,a),onClick:()=>{v(K(u,s.index,null)),r()},disabled:o}),children:[c&&(0,X.jsx)(`div`,{className:`pb-1`,children:(0,X.jsx)(Hs,{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)(W,{label:J(`engine.inspector.viewColumn.accessorKey`,a),value:Ny(d),options:_,onCommit:e=>y({field:e}),disabled:o}):(0,X.jsx)(G,{label:J(`engine.inspector.viewColumn.accessorKey`,a),value:Ny(d),onCommit:e=>y({field:e}),disabled:o,mono:!0}),(0,X.jsx)(G,{label:J(`engine.inspector.viewColumn.header`,a),value:Py(d)===Ny(d)?``:Py(d),onCommit:e=>y({label:e}),disabled:o}),!f&&p?(0,X.jsx)(`div`,{className:`border-t pt-3`,children:(0,X.jsx)(Na,{schema:p,value:d,hiddenFields:Ay,readOnly:o,onChange:e=>{v(K(u,s.index,e))}})}):null]})]})}function Ry(e){let{selection:t}=e;if(t.kind===`column`)return(0,X.jsx)(Ly,{...e});let n=mc(e.draft,t.id||void 0)??pc(e.draft);return(0,X.jsx)(Sc,{type:e.type,name:e.name,draft:e.draft,onPatch:e.onPatch,onSelectionChange:e.onSelectionChange,onClearSelection:e.onClearSelection,onBlockingIssuesChange:e.onBlockingIssuesChange,readOnly:e.readOnly,locale:e.locale,variantKey:n?.storeKey??`list`,familyKey:n?.familyKey??n?.storeKey??`list`,isHome:!1})}function zy(e){let t=pc(e.draft);return(0,X.jsx)(Sc,{...e,variantKey:t?.storeKey??`list`,familyKey:t?.familyKey??t?.storeKey??`list`,isHome:!0})}var By={io:`input`,unrepresentable:`any`},Vy=new Set([`name`,`regions`,`children`]),Hy,Uy=!1;function Wy(){if(Hy||Uy)return Hy;try{Hy=Wi(y,By)}catch(e){Uy=!0,typeof console<`u`&&console.warn(`[page-schema] failed to derive Page JSONSchema from spec`,e)}return Hy}var Gy;function Ky(){if(Gy)return Gy;if(!(!h||typeof h!=`object`)){try{let e=JSON.parse(JSON.stringify(h));for(let t of e.sections??[])t.fields=(t.fields??[]).filter(e=>{let t=typeof e==`string`?e:e?.field;return!Vy.has(t)});e.sections=(e.sections??[]).filter(e=>(e.fields??[]).length>0),Gy=e}catch(e){typeof console<`u`&&console.warn(`[page-schema] failed to prune Page authoring form from spec`,e),Gy=h}return Gy}}function qy({draft:e,onPatch:t,readOnly:n,serverSchema:r,locale:i}){let{schema:a,form:o}=Y.useMemo(()=>Va({bundledSchema:Wy(),bundledForm:Ky(),serverSchema:r,excludeFields:Vy,sectionTitle:J(`engine.inspector.moreFields`,i)}),[r,i]);return a?(0,X.jsx)(Na,{schema:a,form:o,value:e,hiddenFields:[...Vy],readOnly:n,onChange:e=>t(e)}):(0,X.jsx)(`p`,{className:`px-1 py-2 text-xs text-muted-foreground`,children:J(`engine.studio.inspector.noPageSchema`,i)})}function Jy(e){let t=e.options;return Array.isArray(t)?t.map(e=>{let t=e&&typeof e==`object`&&!Array.isArray(e)?{...e}:{};delete t.value,delete t.label,delete t.color;let n={value:String(e?.value??``),label:typeof e?.label==`string`?e.label:void 0,color:typeof e?.color==`string`?e.color:void 0};return Object.keys(t).length>0&&(n.rest=t),n}):[]}function Yy(e){return e===`select`||e===`multiselect`||e===`radio`||e===`checkboxes`}function Xy(e){return e===`lookup`||e===`master_detail`||e===`tree`}function Zy(e){return e===`formula`||e===`summary`}function Qy(e){return e===`number`||e===`currency`||e===`percent`}function $y(e){return e===`text`||e===`textarea`||e===`email`||e===`url`||e===`phone`||e===`password`}function eb(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 tb=[`record`,`previous`,`parent`],nb=[`record`];function rb(e){return typeof e==`string`?e:e&&typeof e==`object`&&typeof e.source==`string`?e.source:``}function ib(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 ab(e){return to.flatMap(t=>t.types.map(n=>({value:n,label:`${J(`engine.fieldCategory.${t.category}`,e)} · ${J(`engine.fieldType.${n}`,e)}`})))}function ob({selection:e,draft:t,onPatch:n,onClearSelection:r,onSelectionChange:i,onBlockingIssuesChange:a,readOnly:o,locale:s}){let c=Y.useCallback(e=>J(e,s),[s]),l=Y.useMemo(()=>ab(s),[s]),u=Y.useMemo(()=>aa(t.fields),[t]),d=String(e.id),f=Ra(u,d),p=f>=0?u.entries[f]:null,m=Array.isArray(t.fieldGroups)?t.fieldGroups:[],h=Eb(s),g=Y.useRef(!1);Y.useEffect(()=>{g.current=!1},[d]);let _=p?typeof p.def.type==`string`?p.def.type:`text`:null,[v,y]=Y.useState({field:d,sites:{}}),b=Y.useCallback((e,t)=>{let n=t.filter(e=>e.severity===`error`).length;y(t=>t.field===d?t.sites[e]===n?t:{field:d,sites:{...t.sites,[e]:n}}:{field:d,sites:{[e]:n}})},[d]),x=Y.useMemo(()=>{if(v.field!==d)return 0;let e=0;for(let[t,n]of Object.entries(v.sites))(t!==`formula`||_===`formula`)&&(e+=n??0);return e},[v,d,_]),S=Y.useRef(a);if(Y.useEffect(()=>{S.current=a}),Y.useEffect(()=>{S.current?.(x)},[x]),!p)return(0,X.jsx)(Ba,{kindLabel:c(`designer.field.kind`),title:d||c(`designer.field.kind`),onClose:r,closeLabel:c(`designer.field.close`),children:(0,X.jsx)(Wa,{message:c(`designer.field.missing`)})});let C=p.def,w=_,T=qa[w],E=e=>{n({fields:va(e)})},D=e=>{let t=[...u.entries];t[f]={...p,def:{...C,...e}},E({shape:u.shape,entries:t})},O=e=>{let t=Ma(e);if(!t||t===p.name||u.entries.some((e,n)=>n!==f&&e.name===t))return;let n=[...u.entries];n[f]={...p,name:t},E({shape:u.shape,entries:n}),i?.({kind:`field`,id:t,label:String(C.label??t)})},k=e=>{if(o)return null;let t=w===`select`?`status`:w;if(!(p.name===t||p.name.startsWith(`${t}_`)&&/^\d+$/.test(p.name.slice(t.length+1))||/^field_\d+$/.test(p.name)))return null;let n=Ma(e);return!n||n===p.name||u.entries.some((e,t)=>t!==f&&e.name===n)?null:n},A=()=>{let e=u.entries.filter((e,t)=>t!==f);E({shape:u.shape,entries:e}),r()},j=()=>{let e=new Set(u.entries.map(e=>e.name)),t=`${p.name}_copy`,n=t,r=1;for(;e.has(n);)r+=1,n=`${t}_${r}`;let a=typeof C.label==`string`&&C.label?C.label:``,o={name:n,def:{...C,label:a?a+c(`designer.field.copySuffix`):void 0}},s=[...u.entries];s.splice(f+1,0,o),E({shape:u.shape,entries:s}),i?.({kind:`field`,id:n,label:String(o.def.label??n)})},M=e=>{let t={shape:u.shape,entries:Ha(u.entries,f,e)};E(t)},N=Jy(C),P=e=>{let t=e.map(e=>{let t={...e.rest,value:e.value,label:e.label??``};return e.color&&(t.color=e.color),t});D({options:t})},ee=(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[!o&&(0,X.jsx)(B,{variant:`ghost`,size:`sm`,className:`h-7 w-7 p-0`,onClick:j,title:c(`designer.field.duplicate`),"aria-label":c(`designer.field.duplicate`),children:(0,X.jsx)(qe,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(Ga,{index:f,total:u.entries.length,onMove:M,disabled:o})]}),te=(0,X.jsx)(Ja,{label:q(`designer.field.remove`,s,{label:typeof C.label==`string`?C.label:p.name}),onClick:A,disabled:o}),ne=T?J(`engine.fieldType.${T.id}`,s):void 0;return(0,X.jsxs)(Ba,{kindLabel:c(`designer.field.kind`),title:typeof C.label==`string`&&C.label?C.label:p.name,onClose:r,closeLabel:c(`designer.field.close`),headerActions:ee,footer:te,children:[(0,X.jsxs)(sb,{title:c(`designer.field.section.basic`),children:[(0,X.jsx)(G,{label:c(`designer.field.apiName`),value:p.name,onCommit:O,disabled:o,mono:!0,testId:`field-apiname-input`}),(0,X.jsx)(G,{label:c(`designer.field.label`),value:typeof C.label==`string`?C.label:``,onCommit:e=>{let t=k(e),n=[...u.entries];n[f]={...p,name:t??p.name,def:{...C,label:e}},E({shape:u.shape,entries:n}),t&&i?.({kind:`field`,id:t,label:e})},disabled:o,testId:`field-label-input`}),(0,X.jsx)(W,{label:c(`designer.field.type`),value:w,options:l,onCommit:e=>D({type:e}),disabled:o}),(0,X.jsxs)(`div`,{className:`flex items-center gap-4 pt-1`,children:[(0,X.jsx)(U,{label:c(`designer.field.required`),value:!!C.required,onCommit:e=>D({required:e||void 0}),disabled:o}),(0,X.jsx)(U,{label:c(`designer.field.unique`),value:!!C.unique,onCommit:e=>D({unique:e||void 0}),disabled:o})]}),(0,X.jsx)(lb,{label:c(`designer.field.description`),value:typeof C.description==`string`?C.description:``,onCommit:e=>D({description:e||void 0}),disabled:o,rows:2}),eb(w)&&(0,X.jsx)(cb,{kind:eb(w),value:C.defaultValue,options:N,onCommit:e=>D({defaultValue:e}),disabled:o,locale:s}),(0,X.jsx)(lb,{label:c(`designer.field.helpText`),value:typeof C.inlineHelpText==`string`?C.inlineHelpText:``,onCommit:e=>D({inlineHelpText:e||void 0}),disabled:o,rows:2,placeholder:c(`designer.field.helpTextPlaceholder`)})]}),(Yy(w)||Xy(w)||Zy(w)||Qy(w)||$y(w))&&(0,X.jsxs)(sb,{title:q(`designer.field.section.options`,s,{type:ne??w}),children:[Yy(w)&&(0,X.jsx)(db,{options:N,onChange:P,disabled:o,locale:s},p.name),Xy(w)&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ub,{label:c(`designer.field.relatedObject`),value:typeof C.reference==`string`?C.reference:``,options:h,onCommit:e=>D({reference:e||void 0}),disabled:o,placeholder:c(`designer.field.objectNamePlaceholder`)}),(0,X.jsx)(G,{label:c(`designer.field.relationshipName`),value:typeof C.relationshipName==`string`?C.relationshipName:``,onCommit:e=>D({relationshipName:e||void 0}),disabled:o,placeholder:c(`designer.field.relationshipNameHint`)}),(0,X.jsx)(hb,{def:C,patchDef:D,hostFieldNames:u.entries.map(e=>e.name).filter(e=>e!==p.name),readOnly:o,locale:s})]}),w===`formula`&&(0,X.jsx)(Oa,{id:`field-formula-${p.name}`,label:c(`designer.field.formula`),value:rb(C.expression??C.formula),onChange:e=>{g.current=!0,D({expression:ib(C.expression??C.formula,e),formula:void 0,...e.trim()?{}:{returnType:void 0}})},onLintChange:e=>b(`formula`,e),onInferredTypeChange:e=>{if(!g.current)return;let t=e&&e!==`unknown`?e:void 0;C.returnType!==t&&D({returnType:t})},disabled:o,placeholder:`record.amount * 0.2`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:u.entries.map(e=>e.name).filter(e=>e!==p.name),scope:`record`,roots:nb,role:`value`,t:c}),w===`summary`&&(0,X.jsx)(Tb,{def:C,patchDef:D,objectOptions:h,readOnly:o,locale:s}),Qy(w)&&(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)(Za,{label:c(`designer.field.precision`),value:typeof C.precision==`number`?C.precision:void 0,onCommit:e=>D({precision:e}),disabled:o}),(0,X.jsx)(Za,{label:c(`designer.field.scale`),value:typeof C.scale==`number`?C.scale:void 0,onCommit:e=>D({scale:e}),disabled:o}),(0,X.jsx)(Za,{label:c(`designer.field.min`),value:typeof C.min==`number`?C.min:void 0,onCommit:e=>D({min:e}),disabled:o}),(0,X.jsx)(Za,{label:c(`designer.field.max`),value:typeof C.max==`number`?C.max:void 0,onCommit:e=>D({max:e}),disabled:o})]}),$y(w)&&(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)(Za,{label:c(`designer.field.minLength`),value:typeof C.minLength==`number`?C.minLength:void 0,onCommit:e=>D({minLength:e}),disabled:o,placeholder:`0`}),(0,X.jsx)(Za,{label:c(`designer.field.maxLength`),value:typeof C.maxLength==`number`?C.maxLength:void 0,onCommit:e=>D({maxLength:e}),disabled:o,placeholder:`255`})]})]}),(0,X.jsxs)(sb,{title:c(`designer.field.section.advanced`),children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-2`,children:[(0,X.jsx)(U,{label:c(`designer.field.readonly`),value:!!C.readonly,onCommit:e=>D({readonly:e||void 0}),disabled:o}),(0,X.jsx)(U,{label:c(`designer.field.hidden`),value:!!C.hidden,onCommit:e=>D({hidden:e||void 0}),disabled:o}),(0,X.jsx)(U,{label:c(`designer.field.externalId`),value:!!C.externalId,onCommit:e=>D({externalId:e||void 0}),disabled:o}),(0,X.jsx)(U,{label:c(`designer.field.trackHistory`),value:!!C.trackHistory,onCommit:e=>D({trackHistory:e||void 0}),disabled:o})]}),(0,X.jsx)(G,{label:c(`designer.field.placeholder`),value:typeof C.placeholder==`string`?C.placeholder:``,onCommit:e=>D({placeholder:e||void 0}),disabled:o}),(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:c(`designer.field.conditionalRules`)}),(0,X.jsx)(Oa,{id:`field-rule-visible-${p.name}`,label:c(`designer.field.visibleWhen`),value:rb(C.visibleWhen),onChange:e=>D({visibleWhen:ib(C.visibleWhen,e)}),onLintChange:e=>b(`visibleWhen`,e),disabled:o,placeholder:`record.status != 'draft'`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:u.entries.map(e=>e.name),scope:`record`,roots:tb,t:c}),(0,X.jsx)(Oa,{id:`field-rule-readonly-${p.name}`,label:c(`designer.field.readonlyWhen`),value:rb(C.readonlyWhen),onChange:e=>D({readonlyWhen:ib(C.readonlyWhen,e)}),onLintChange:e=>b(`readonlyWhen`,e),disabled:o,placeholder:`record.status == 'closed'`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:u.entries.map(e=>e.name),scope:`record`,roots:tb,t:c}),(0,X.jsx)(Oa,{id:`field-rule-required-${p.name}`,label:c(`designer.field.requiredWhen`),value:rb(C.requiredWhen),onChange:e=>D({requiredWhen:ib(C.requiredWhen,e)}),onLintChange:e=>b(`requiredWhen`,e),disabled:o,placeholder:`record.amount > 10000`,objectName:typeof t.name==`string`?t.name:void 0,fieldNames:u.entries.map(e=>e.name),scope:`record`,roots:tb,t:c}),(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80 px-0.5 leading-snug`,children:c(`designer.field.conditionalRulesHint`)})]}),m.length>0&&(0,X.jsx)(W,{label:c(`designer.field.group`),value:typeof C.group==`string`?C.group:``,options:[{value:``,label:c(`designer.field.noGroup`)},...m.filter(e=>typeof e.key==`string`).map(e=>({value:e.key,label:String(e.label??e.key)}))],onCommit:e=>D({group:e||void 0}),disabled:o})]})]})}function sb({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 cb({kind:e,value:t,options:n,onCommit:r,disabled:i,locale:a}){let o=J(`designer.field.defaultValue`,a),s=J(`designer.field.defaultNone`,a);return e===`bool`?(0,X.jsx)(W,{label:o,value:t===!0?`true`:t===!1?`false`:``,options:[{value:``,label:s},{value:`true`,label:J(`designer.field.true`,a)},{value:`false`,label:J(`designer.field.false`,a)}],onCommit:e=>r(e===``?void 0:e===`true`),disabled:i}):e===`number`?(0,X.jsx)(Za,{label:o,value:typeof t==`number`?t:void 0,onCommit:e=>r(e),disabled:i}):e===`picklist`?(0,X.jsx)(W,{label:o,value:typeof t==`string`?t:``,options:[{value:``,label:s},...n.filter(e=>e.value).map(e=>({value:e.value,label:e.label||e.value}))],onCommit:e=>r(e||void 0),disabled:i}):(0,X.jsx)(G,{label:o,value:typeof t==`string`?t:t==null?``:String(t),onCommit:e=>r(e||void 0),disabled:i})}function lb({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)(I,{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 ub({label:e,value:t,options:n,onCommit:r,disabled:i,placeholder:a}){let o=Y.useId();return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{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 db({options:e,onChange:t,disabled:n,locale:r}){let[i,a]=Y.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(Ha(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)(I,{className:`text-xs text-muted-foreground`,children:J(`designer.field.picklistValues`,r)}),(0,X.jsx)(z,{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:J(`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:J(`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:J(`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:J(`designer.field.optColor`,r)}),(0,X.jsx)(`span`,{className:`flex-1`}),(0,X.jsx)(B,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>l(t,t-1),disabled:n||t===0,"aria-label":J(`designer.field.moveUp`,r),children:(0,X.jsx)(Er,{className:`h-3 w-3`})}),(0,X.jsx)(B,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0`,onClick:()=>l(t,t+1),disabled:n||t===i.length-1,"aria-label":J(`designer.field.moveDown`,r),children:(0,X.jsx)(_e,{className:`h-3 w-3`})}),(0,X.jsx)(B,{variant:`ghost`,size:`sm`,className:`h-6 w-6 p-0 text-destructive`,onClick:()=>c(t),disabled:n,"aria-label":J(`designer.field.removeValue`,r),children:(0,X.jsx)(_r,{className:`h-3 w-3`})})]})]},t))}),!n&&(0,X.jsxs)(B,{variant:`outline`,size:`sm`,className:`h-7 gap-1 text-xs`,onClick:()=>o([...i,{value:``,label:``}]),children:[(0,X.jsx)(L,{className:`h-3 w-3`}),J(`designer.field.addValue`,r)]})]})}var fb=[{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 pb(e){let t=e.lookupFilters??e.lookup_filters;return Array.isArray(t)?t:[]}function mb(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 hb({def:e,patchDef:t,hostFieldNames:n,readOnly:r,locale:i}){let a=e=>J(e,i),o=typeof e.reference==`string`?e.reference:void 0,{fields:s,loading:c}=la(o),l=Y.useMemo(()=>s.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label,hint:e.type})),[s]),u=Y.useMemo(()=>n.map(e=>({value:e,label:e})),[n]),d=pb(e),f=mb(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)(ws,{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)(ws,{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)(I,{className:`text-xs text-muted-foreground`,children:a(`designer.field.lookup.selectableRecords`)}),(0,X.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:d.length})]}),!r&&(0,X.jsxs)(B,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:m,children:[(0,X.jsx)(L,{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:q(`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:q(`designer.field.lookup.filterN`,i,{n:t+1})}),!r&&(0,X.jsx)(B,{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)(_r,{className:`h-3.5 w-3.5`})})]}),(0,X.jsx)(ws,{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)(W,{label:a(`designer.field.lookup.filterOperator`),value:e.operator??`eq`,options:fb,onCommit:e=>p(t,{operator:e}),disabled:r}),(0,X.jsx)(G,{label:a(`designer.field.lookup.filterValue`),value:g(e.value),onCommit:n=>p(t,{value:_(e.operator,n)}),placeholder:e.operator===`in`||e.operator===`notIn`?`comma,separated,values`:`value`,disabled:r,mono:!0})]},t))]}),(0,X.jsxs)(`div`,{className:`space-y-1.5 pt-1`,children:[(0,X.jsx)(I,{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)(ws,{ariaLabel:a(`designer.field.lookup.addDependsOn`),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)(Za,{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)(U,{label:a(`designer.field.lookup.allowCreate`),value:C,onCommit:e=>t({allowCreate:e||void 0}),disabled:r})})]})]})}var gb=[`count`,`sum`,`min`,`max`,`avg`];function _b(e){let t=e.summaryOperations;return t&&typeof t==`object`&&!Array.isArray(t)?t:{}}var vb={ne:`$ne`,gt:`$gt`,lt:`$lt`,gte:`$gte`,lte:`$lte`,contains:`$contains`,in:`$in`,notIn:`$nin`},yb={$eq:`eq`,$ne:`ne`,$gt:`gt`,$lt:`lt`,$gte:`gte`,$lte:`lte`,$contains:`contains`,$in:`in`,$nin:`notIn`},bb=new Set([`number`,`currency`,`percent`,`rating`,`slider`,`autonumber`]);function xb(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&&bb.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 Sb(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=yb[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 Cb(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=xb(e.value,t(e.field),n);return e.operator===`eq`?{[e.field]:r}:{[e.field]:{[vb[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 wb=e=>Array.isArray(e)?e.join(`, `):e==null?``:String(e);function Tb({def:e,patchDef:t,objectOptions:n,readOnly:r,locale:i}){let a=e=>J(e,i),o=_b(e),s=typeof o.object==`string`?o.object:``,c=typeof o.function==`string`?o.function:``,{fields:l,loading:u}=la(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=Y.useMemo(()=>l.filter(e=>!e.hidden).map(e=>({value:e.name,label:e.label,hint:e.type})),[l]),p=Y.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=Y.useCallback(e=>l.find(t=>t.name===e)?.type,[l]),{rows:g,advanced:_}=Sb(o.filter),v=e=>d({filter:Cb(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)(ub,{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)(W,{label:a(`designer.field.summary.function`),value:c,options:[{value:``,label:a(`designer.field.defaultNone`)},...gb.map(e=>({value:e,label:a(`designer.field.summary.fn.${e}`)}))],onCommit:e=>d({function:e||void 0}),disabled:r}),(0,X.jsx)(ws,{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)(ws,{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)(I,{className:`text-xs text-muted-foreground`,children:a(`designer.field.summary.filterSection`)}),!_&&(0,X.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:g.length})]}),!r&&!_&&(0,X.jsxs)(B,{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)(L,{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:q(`designer.field.lookup.filterN`,i,{n:t+1})}),!r&&(0,X.jsx)(B,{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)(_r,{className:`h-3.5 w-3.5`})})]}),(0,X.jsx)(ws,{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)(W,{label:a(`designer.field.lookup.filterOperator`),value:e.operator??`eq`,options:fb,onCommit:e=>y(t,{operator:e}),disabled:r}),(0,X.jsx)(G,{label:a(`designer.field.lookup.filterValue`),value:wb(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 Eb(e){let t=yi(),[n,r]=Y.useState([]);return Y.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} ${J(`engine.inspector.draftSuffix`,e)}`})}r([...a.values()].sort((e,t)=>e.value.localeCompare(t.value)))}).catch(()=>{}),()=>{n=!0}},[t,e]),n}function Db({name:e,draft:t,onPatch:n,readOnly:r,locale:i}){let a=Y.useCallback(e=>J(e,i),[i]),o=!e,s=e=>typeof t[e]==`string`?t[e]:``,c=Y.useRef(!1),l=e=>{let t={label:e||void 0};o&&!c.current&&(t.name=vi(e)),n(t)},u=e=>{c.current=!0,n({name:Ma(e)})},d=o?s(`name`):e||s(`name`),f=s(`label`)||e||a(`designer.object.kind`);return(0,X.jsxs)(Ba,{kindLabel:a(`designer.object.kind`),title:f,onClose:()=>{},hideClose:!0,children:[(0,X.jsxs)(Nb,{title:a(`designer.object.section.basic`),hint:a(`designer.object.section.basicHint`),children:[(0,X.jsx)(Pb,{hint:a(`designer.object.nameHint`),children:(0,X.jsx)(G,{label:a(`designer.object.name`),value:d,onCommit:u,disabled:r||!o,mono:!0,testId:`object-name-input`,placeholder:a(`designer.object.namePlaceholder`)})}),(0,X.jsx)(G,{label:a(`designer.object.label`),value:s(`label`),onCommit:l,disabled:r,placeholder:a(`designer.object.labelPlaceholder`)}),(0,X.jsx)(G,{label:a(`designer.object.pluralLabel`),value:s(`pluralLabel`),onCommit:e=>n({pluralLabel:e||void 0}),disabled:r,placeholder:a(`designer.object.pluralPlaceholder`)}),(0,X.jsx)(Pb,{hint:a(`designer.object.iconHint`),children:(0,X.jsx)(G,{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)(I,{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)(Mb,{draft:t,onPatch:n,readOnly:r,tr:a})]})}var Ob=[`read`,`create`,`update`,`delete`];function kb(e){return e.split(/[,\s]+/).map(e=>e.trim()).filter(Boolean)}function Ab(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`).join(`, `):``}function jb(){let[e,n]=Y.useState(!1);return Y.useEffect(()=>{let e=!1;return t(()=>import(`./vendor-objectstack-BU0HrnMy.js`).then(e=>(e.Ot(),e.Ct)).then(t=>{e||n(t?.ObjectRequiredPermissionsSchema!==void 0)}),[],import.meta.url).catch(()=>{}),()=>{e=!0}},[]),e}function Mb({draft:e,onPatch:t,readOnly:n,tr:r}){let i=jb(),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=kb(e);t({requiredPermissions:n.length>0?n:void 0})},d=(e,n)=>{let r=s?{...o}:{},i=kb(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(Ob.flatMap(t=>Array.isArray(e[t])?e[t]:[]))];t({requiredPermissions:n.length>0?n:void 0})}}};return(0,X.jsxs)(Nb,{title:r(`designer.object.section.access`),hint:r(`designer.object.section.accessHint`),children:[(0,X.jsx)(Pb,{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)(I,{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)(Pb,{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)(I,{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)(G,{label:``,value:Ab(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:Ob.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)(G,{label:``,value:Ab(o?.[e]),onCommit:t=>d(e,t),disabled:n,mono:!0,testId:`object-reqperms-${e}`,placeholder:r(`designer.object.reqPerms.placeholder`)})})]},e))})]})})]})}function Nb({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 Pb({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 Fb={equals:`$eq`,notEquals:`$ne`,greaterThan:`$gt`,greaterOrEqual:`$gte`,lessThan:`$lt`,lessOrEqual:`$lte`,after:`$gt`,before:`$lt`,contains:`$contains`,in:`$in`,notIn:`$nin`},Ib={$eq:`equals`,$ne:`notEquals`,$gt:`greaterThan`,$gte:`greaterOrEqual`,$lt:`lessThan`,$lte:`lessOrEqual`,$contains:`contains`,$in:`in`,$nin:`notIn`};function Lb(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=Fb[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 Rb(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=Ib[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 zb=[{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`}],Bb=[{value:`string`,label:`string`},{value:`number`,label:`number`},{value:`date`,label:`date`},{value:`boolean`,label:`boolean`},{value:`lookup`,label:`lookup`}],Vb=[{value:``,label:`— none —`},{value:`day`,label:`day`},{value:`week`,label:`week`},{value:`month`,label:`month`},{value:`quarter`,label:`quarter`},{value:`year`,label:`year`}],Hb=[{value:`ratio`,label:`ratio (a ÷ b)`},{value:`sum`,label:`sum (a + b)`},{value:`difference`,label:`difference (a − b)`},{value:`product`,label:`product (a × b)`}],Ub=[{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%`}],Wb=[{value:`0`,label:`0`},{value:`1`,label:`1`},{value:`2`,label:`2`}],Gb=[{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 Kb({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)(I,{className:`text-xs text-muted-foreground`,children:e}),(0,X.jsx)(z,{variant:`outline`,className:`text-[10px]`,children:t})]}),n&&(0,X.jsxs)(B,{type:`button`,variant:`ghost`,size:`sm`,className:`h-6 gap-1 px-1.5 text-[11px]`,onClick:n,children:[(0,X.jsx)(L,{className:`h-3 w-3`}),` `,r]})]})}function qb({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)(mn,{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 Jb(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 Yb(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 Xb({measure:e,onPatch:t,disabled:n}){let{kind:r,decimals:i}=Jb(e.format,e.currency),a=e.currency||`USD`,o=(e,n,r)=>t(Yb(e,n,r)),s=pe(),c=ee(r===`percent`?.1234:1234.5,e.format,e.currency,r===`percent`?`fraction`:void 0,s);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)(W,{label:`Display format`,value:r,options:Ub,onCommit:e=>o(e,i,a),disabled:n}),r!==`raw`&&(0,X.jsx)(W,{label:`Decimals`,value:String(i),options:Wb,onCommit:e=>o(r,parseInt(e,10)||0,a),disabled:n})]}),r===`currency`&&(0,X.jsx)(W,{label:`Currency`,value:a,options:Gb,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:c})]})]})}function Zb(e,t){if(!e||!e.includes(`.`))return null;let n=e.slice(0,e.lastIndexOf(`.`));return n&&!t.includes(n)?n:null}function Qb({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)(ci,{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 $b({label:e,help:t,value:n,onCommit:r,fields:i,disabled:a}){let{group:o,representable:s}=Rb(n),c=o.conditions.length;return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{className:`text-xs text-muted-foreground`,children:e}),s?(0,X.jsxs)(Dt,{children:[(0,X.jsx)(Ke,{asChild:!0,children:(0,X.jsxs)(B,{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)(Jn,{className:`h-3.5 w-3.5 opacity-60 shrink-0`})]})}),(0,X.jsx)(Lt,{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)(Zt,{fields:i,value:o,onChange:e=>r(Lb(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 ex(e,t){return e===t?{object:e}:{object:e,include:[],dimensions:[],measures:[],filter:void 0}}function tx({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=Y.useRef(!1),p=typeof e.name==`string`?e.name:``,{options:m,loading:h}=Ns(),{relationships:g,fieldOptions:_,loading:v}=Ps(o,s),y=Fs(u),b=Y.useMemo(()=>m.map(e=>({value:e.name,label:e.label})),[m]),x=Y.useMemo(()=>g.map(e=>({value:e.name,label:e.label,hint:e.referenceTo?`→ ${e.referenceTo}`:void 0})),[g]),S=Y.useMemo(()=>_.map(e=>({value:e.value,label:e.label,hint:e.type,group:e.group})),[_]),C=Y.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:Os(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)(Ba,{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)(G,{label:`Name`,value:p,onCommit:e=>{f.current=!0,t({name:sa(e)})},placeholder:`snake_case identifier`,disabled:n,mono:!0}),(0,X.jsx)(G,{label:`Label`,value:i,onCommit:e=>{let n={label:e};d&&!f.current&&(n.name=sa(e)),t(n)},disabled:n}),(0,X.jsx)(G,{label:`Description`,value:a,onCommit:e=>t({description:e}),disabled:n}),(0,X.jsx)(ws,{label:`Base object`,value:o,onCommit:e=>t(ex(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)(Kb,{title:`Included relationships`,count:s.length,addLabel:`Add`,onAdd:n?void 0:()=>t({include:no(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)(ws,{ariaLabel:`Included relationship`,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)(B,{type:`button`,variant:`ghost`,size:`sm`,className:`h-7 w-7 shrink-0 p-0`,onClick:()=>t({include:K(s,r,null)}),"aria-label":`Remove relationship`,children:(0,X.jsx)(_r,{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)(mn,{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)($b,{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)(Kb,{title:`Dimensions`,count:c.length,addLabel:`Add dimension`,onAdd:n?void 0:()=>t({dimensions:no(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)(B,{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:K(c,r,null)}),children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]}),(0,X.jsx)(G,{label:`Name`,value:e.name??``,onCommit:e=>E(r,{name:e}),placeholder:`e.g. region`,disabled:n,mono:!0}),(0,X.jsx)(ws,{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=Zb(e.field,s);return r?(0,X.jsx)(Qb,{rel:r,disabled:n,onAdd:()=>t({include:no(s,r)})}):null})(),(0,X.jsx)(W,{label:`Type`,value:e.type,options:Bb,onCommit:e=>E(r,{type:e}),disabled:n}),(0,X.jsxs)(qb,{children:[(0,X.jsx)(G,{label:`Label (optional)`,value:e.label??``,onCommit:e=>E(r,{label:e||void 0}),placeholder:e.name||`Display label`,disabled:n}),e.type===`date`&&(0,X.jsx)(W,{label:`Date bucket`,value:e.dateGranularity??``,options:Vb,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)(Kb,{title:`Measures`,count:l.length,addLabel:`Add measure`,onAdd:n?void 0:()=>t({measures:no(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)(B,{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:K(l,r,null)}),children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]}),(0,X.jsx)(G,{label:`Name`,value:e.name??``,onCommit:e=>D(r,{name:e}),placeholder:`e.g. revenue`,disabled:n,mono:!0}),(0,X.jsx)(W,{label:`Aggregate`,value:e.aggregate,options:zb,onCommit:e=>D(r,{aggregate:e}),disabled:n}),(0,X.jsx)(ws,{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=Zb(e.field,s);return r?(0,X.jsx)(Qb,{rel:r,disabled:n,onAdd:()=>t({include:no(s,r)})}):null})(),(0,X.jsxs)(qb,{children:[(0,X.jsx)(G,{label:`Label (optional)`,value:e.label??``,onCommit:e=>D(r,{label:e||void 0}),placeholder:e.name||`Display label`,disabled:n}),(0,X.jsx)(Xb,{measure:e,onPatch:e=>D(r,e),disabled:n}),(0,X.jsx)($b,{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)(U,{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)(W,{label:`Operation`,value:a.op,options:Hb,onCommit:e=>D(r,{derived:{...a,op:e}}),disabled:n}),(0,X.jsx)(I,{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=>{let t=Array.isArray(a.of)&&a.of.includes(e);return(0,X.jsx)(U,{label:e,value:t,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 nx(e){let t=yi(),[n,r]=Y.useState([]),[i,a]=Y.useState(!!e);return Y.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 rx=[{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`}],ix=[{value:`primary`,label:`Primary`},{value:`secondary`,label:`Secondary`},{value:`danger`,label:`Danger`},{value:`ghost`,label:`Ghost`},{value:`link`,label:`Link`}],ax=[{value:`action:button`,label:`Button`},{value:`action:icon`,label:`Icon only`},{value:`action:menu`,label:`Menu item`},{value:`action:group`,label:`Button group`}],ox=[{value:`create`,label:`Create`},{value:`edit`,label:`Edit`},{value:`delete`,label:`Delete`},{value:`custom`,label:`Custom`}],sx=[{value:`POST`,label:`POST`},{value:`PATCH`,label:`PATCH`},{value:`PUT`,label:`PUT`},{value:`DELETE`,label:`DELETE`}],cx=[{value:`expression`,label:`Expression (L1)`},{value:`js`,label:`Sandboxed JS (L2)`}],lx=[{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`}],ux=new Set([...ne,...N]);function dx(e){return ux.has(e)?e:void 0}var fx={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`},px=Object.keys(fx).map(e=>({value:e,label:fx[e]})),mx={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.`}},hx={flow:`flow`,modal:`page`,form:`view`};function gx({type:e,value:t,onCommit:n,cfg:r,readOnly:i}){let a=hx[e]??null,{options:o}=nx(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)(W,{label:`${r.label} *`,value:t||void 0,options:c,onCommit:n,disabled:i}):(0,X.jsx)(G,{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 _x=[`name`,`label`,`objectName`,`icon`,`variant`,`component`,`type`,`target`,`execute`,`body`,`method`,`params`,`locations`,`confirmText`,`successMessage`,`errorMessage`,`refreshAfter`,`undoable`,`mode`,`visible`,`disabled`,`aiExposed`,`aiDescription`],vx=[`bulkEnabled`,`shortcut`];function yx({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 bx(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 xx({label:e,value:t,onCommit:n,disabled:r,hint:i}){let{options:a}=Bu();return(0,X.jsxs)(`div`,{className:`space-y-1`,children:[a.length===0?(0,X.jsx)(G,{label:e,value:t??``,placeholder:`snake_case object`,onCommit:n,disabled:r,mono:!0}):(0,X.jsx)(W,{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 Sx({label:e,objectName:t,value:n,onCommit:r,disabled:i}){let{fields:a}=la(t),o=Y.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)(G,{label:e,value:n??``,onCommit:r,disabled:i,mono:!0}):(0,X.jsx)(W,{label:e,value:n||void 0,options:[{value:``,label:`—`},...o],onCommit:r,disabled:i})}function Cx({options:e,onCommit:t,disabled:n}){let r=Array.isArray(e)?e:[];return(0,X.jsxs)(`div`,{role:`group`,"aria-label":`Options`,className:`space-y-1.5 rounded-md border border-dashed border-border p-2`,children:[(0,X.jsx)(`div`,{className:`text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:`Options`}),r.length===0?(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground/80`,children:`No choices yet — a Select with no options opens an empty picker in the dialog.`}):r.map((e,i)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-1`,children:[(0,X.jsxs)(`div`,{className:`grid flex-1 grid-cols-2 gap-2`,children:[(0,X.jsx)(G,{label:`Label`,value:bx(e.label),onCommit:n=>t(K(r,i,{...e,label:n})),disabled:n}),(0,X.jsx)(G,{label:`Value`,value:e.value??``,onCommit:n=>t(K(r,i,{...e,value:n})),disabled:n,mono:!0})]}),(0,X.jsx)(B,{type:`button`,variant:`ghost`,size:`icon`,className:`mt-[22px] h-6 w-6`,disabled:n,"aria-label":`Remove option ${i+1}`,onClick:()=>t(K(r,i,null)),children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]},i)),!n&&(0,X.jsxs)(B,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>t(no(r,{label:``,value:``})),children:[(0,X.jsx)(L,{className:`mr-1 h-3.5 w-3.5`}),` Add option`]})]})}function wx({draft:e,onPatch:t,readOnly:n,locale:r,serverSchema:i,onBlockingIssuesChange:a}){let o=Y.useCallback(e=>J(e,r),[r]),s=t=>typeof e[t]==`string`?e[t]:``,c=s(`type`)||`script`,l=s(`objectName`),u=e.body&&typeof e.body==`object`?e.body:{},d=Array.isArray(e.params)?e.params:[],f=Array.isArray(e.locations)?e.locations:[],p=e.aiExposed===!0,m=typeof e.aiDescription==`string`?e.aiDescription:``,h=s(`name`),[g,_]=Y.useState({action:h,sites:{}}),v=Y.useCallback((e,t)=>{_(n=>n.action===h?n.sites[e]===t?n:{action:h,sites:{...n.sites,[e]:t}}:{action:h,sites:{[e]:t}})},[h]),y=Y.useMemo(()=>{if(g.action!==h)return 0;let e=0;for(let t of Object.values(g.sites))e+=t??0;return e},[g,h]),b=Y.useRef(a);Y.useEffect(()=>{b.current=a}),Y.useEffect(()=>{b.current?.(y)},[y]);let x=e=>t({body:{...u,...e}}),S=(e,n)=>t({params:d.map((t,r)=>r===e?{...t,...n}:t)}),C=(e,n)=>{t({locations:n?[...new Set([...f,e])]:f.filter(t=>t!==e)})},w=mx[c],T=i;return(0,X.jsxs)(Ba,{kindLabel:o(`engine.inspector.action.kind`),title:String(bx(e.label)||e.name||o(`engine.inspector.action.kind`)),onClose:()=>{},closeLabel:o(`engine.inspector.action.close`),hideClose:!0,children:[(0,X.jsx)(yx,{title:`Basics`}),(0,X.jsx)(G,{label:`Label`,value:bx(e.label),onCommit:e=>t({label:e}),placeholder:`Button text shown to users`,disabled:n}),(0,X.jsx)(G,{label:`Name`,value:s(`name`),onCommit:e=>t({name:e}),placeholder:`snake_case identifier`,disabled:n,mono:!0}),(0,X.jsx)(xx,{label:`Object`,value:l,onCommit:e=>t({objectName:e||void 0}),disabled:n,hint:l?`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)(I,{className:`text-xs text-muted-foreground`,children:`Icon`}),(0,X.jsx)(Ea,{schema:{type:`string`},value:s(`icon`),onChange:e=>t({icon:e||void 0}),readOnly:n})]}),(0,X.jsx)(W,{label:`Variant`,value:s(`variant`)||void 0,options:ix,onCommit:e=>t({variant:e}),disabled:n})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-3`,children:[(0,X.jsx)(yx,{title:`Behavior`,hint:`What happens when the action is triggered.`}),(0,X.jsx)(W,{label:`Type`,value:c,options:rx,onCommit:e=>t({type:e}),disabled:n}),c===`script`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(W,{label:`Script language`,value:(typeof u.language==`string`?u.language:void 0)||`expression`,options:cx,onCommit:e=>x({language:e}),disabled:n}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{className:`text-xs text-muted-foreground`,children:`Script body`}),(0,X.jsx)(Gt,{value:typeof u.source==`string`?u.source:``,onChange:e=>x({source:e.target.value}),disabled:n,spellCheck:!1,rows:5,placeholder:`// (input, ctx) => result
|
|
16
|
+
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:[c===`api`&&(0,X.jsx)(W,{label:`Method`,value:s(`method`)||`POST`,options:sx,onCommit:e=>t({method:e}),disabled:n}),w&&(0,X.jsx)(gx,{type:c,value:s(`target`),onCommit:e=>t({target:e}),cfg:w,readOnly:n})]})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,X.jsx)(yx,{title:`Inputs`,hint:`Collected from the user in a dialog before the action runs.`}),d.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.`}):d.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)(B,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n||r===0,"aria-label":`Move up`,onClick:()=>t({params:Ha(d,r,r-1)}),children:`↑`}),(0,X.jsx)(B,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n||r===d.length-1,"aria-label":`Move down`,onClick:()=>t({params:Ha(d,r,r+1)}),children:`↓`}),(0,X.jsx)(B,{type:`button`,variant:`ghost`,size:`icon`,className:`h-6 w-6`,disabled:n,"aria-label":`Remove input`,onClick:()=>t({params:K(d,r,null)}),children:(0,X.jsx)(qt,{className:`h-3.5 w-3.5`})})]})]}),l?(0,X.jsx)(Sx,{label:`Bind to field`,objectName:l,value:e.field,onCommit:e=>S(r,{field:e||void 0}),disabled:n}):null,!e.field&&(0,X.jsx)(G,{label:`Name`,value:e.name??``,onCommit:e=>S(r,{name:e}),placeholder:`request-body key`,disabled:n,mono:!0}),(0,X.jsx)(G,{label:`Label`,value:bx(e.label),onCommit:e=>S(r,{label:e}),disabled:n}),!e.field&&(0,X.jsx)(W,{label:`Type`,value:e.type||void 0,options:lx,onCommit:e=>S(r,{type:dx(e)}),disabled:n}),!e.field&&e.type===`select`&&(0,X.jsx)(Cx,{options:e.options,onCommit:e=>S(r,{options:e.length>0?e:void 0}),disabled:n}),(0,X.jsx)(G,{label:`Placeholder`,value:e.placeholder??``,onCommit:e=>S(r,{placeholder:e}),disabled:n}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1`,children:[(0,X.jsx)(U,{label:`Required`,value:!!e.required,onCommit:e=>S(r,{required:e}),disabled:n}),(0,X.jsx)(U,{label:`Pre-fill from row`,value:!!e.defaultFromRow,onCommit:e=>S(r,{defaultFromRow:e}),disabled:n})]})]},r)),!n&&(0,X.jsxs)(B,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>t({params:no(d,{})}),children:[(0,X.jsx)(L,{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)(yx,{title:`Placement`,hint:`Where this action surfaces in the UI.`}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-1`,children:px.map(e=>(0,X.jsx)(U,{label:e.label,value:f.includes(e.value),onCommit:t=>C(e.value,t),disabled:n},e.value))}),f.length===0&&(0,X.jsx)(`div`,{className:`text-[11px] text-destructive`,children:`No placement selected — this action will not appear on any record or list surface. Tick a placement above, or place it from a view’s bulk actions.`}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-2 pt-1`,children:(0,X.jsx)(W,{label:`Component`,value:s(`component`)||void 0,options:ax,onCommit:e=>t({component:e}),disabled:n})})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,X.jsx)(yx,{title:`Feedback`,hint:`Confirmation and post-run messaging.`}),(0,X.jsx)(G,{label:`Confirm prompt`,value:bx(e.confirmText),onCommit:e=>t({confirmText:e}),placeholder:`Ask before running (leave blank to skip)`,disabled:n}),(0,X.jsx)(G,{label:`Success message`,value:bx(e.successMessage),onCommit:e=>t({successMessage:e}),disabled:n}),(0,X.jsx)(G,{label:`Error message`,value:bx(e.errorMessage),onCommit:e=>t({errorMessage:e}),disabled:n}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:(0,X.jsx)(W,{label:`Mode`,value:s(`mode`)||void 0,options:ox,onCommit:e=>t({mode:e}),disabled:n})}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1`,children:[(0,X.jsx)(U,{label:`Refresh view after`,value:!!e.refreshAfter,onCommit:e=>t({refreshAfter:e}),disabled:n}),(0,X.jsx)(U,{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)(yx,{title:`Conditions`,hint:`No-code predicates over the record / user / ctx (compiled to CEL).`}),(0,X.jsx)(da,{label:`Visible when`,value:Sa(e.visible),onCommit:n=>t({visible:Ca(e.visible,n)}),objectName:l,disabled:n,onBlockingIssuesChange:e=>v(`visible`,e)}),(0,X.jsx)(da,{label:`Disabled when`,value:Sa(e.disabled),onCommit:n=>t({disabled:Ca(e.disabled,n)}),objectName:l,disabled:n,onBlockingIssuesChange:e=>v(`disabled`,e)})]}),(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-2`,children:[(0,X.jsx)(yx,{title:`AI exposure`,hint:`Opt-in: expose this action to AI agents as a callable tool.`}),(0,X.jsx)(U,{label:`Expose to AI agents`,value:p,onCommit:e=>t({aiExposed:e}),disabled:n}),p?(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{className:`text-xs text-muted-foreground`,children:`Tool description (required, ≥40 chars)`}),(0,X.jsx)(Gt,{value:m,onChange:e=>t({aiDescription:e.target.value}),disabled:n,rows:3,placeholder:`When and why an agent should call this action…`,className:`text-xs`}),m.length<40&&(0,X.jsx)(`div`,{className:`text-[11px] text-destructive`,children:`A ≥40-character description is required while exposed.`})]}):null]}),T&&(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,X.jsx)(yx,{title:o(`engine.inspector.moreFields`),hint:`Advanced / rarely-used properties.`}),(0,X.jsx)(Na,{schema:T,value:e,hiddenFields:[..._x,...vx],readOnly:n,onChange:e=>t(e)})]})]})}var Tx=[{value:`expression`,label:`Expression (L1)`},{value:`js`,label:`Sandboxed JS (L2)`}],Ex=[`beforeInsert`,`afterInsert`,`beforeUpdate`,`afterUpdate`,`beforeDelete`,`afterDelete`,`beforeUpdateMany`,`afterUpdateMany`,`beforeDeleteMany`,`afterDeleteMany`],Dx=[`beforeFind`,`afterFind`,`beforeFindOne`,`afterFindOne`,`beforeCount`,`afterCount`,`beforeAggregate`,`afterAggregate`],Ox=`*`,kx=[`name`,`label`,`object`,`events`,`body`,`priority`,`async`,`condition`];function Ax({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 jx(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 Mx(e){if(e===Ox)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!==Ox);return{all:e.includes(Ox),names:t}}return{all:!1,names:[]}}function Nx(e,t){return e?Ox:t.length===1?t[0]:t}function Px({draft:e,onPatch:t,readOnly:n,locale:r,serverSchema:i,onBlockingIssuesChange:a}){let o=Y.useCallback(e=>J(e,r),[r]),s=t=>typeof e[t]==`string`?e[t]:``,c=e.body&&typeof e.body==`object`?e.body:{},l=Array.isArray(e.events)?e.events:[],{all:u,names:d}=Mx(e.object),{options:f}=Bu(),p=Y.useMemo(()=>{let e=new Set(f.map(e=>e.value));return[...d.filter(t=>!e.has(t)).map(e=>({value:e,label:`${e} (not published)`})),...f]},[f,d]),m=e=>t({body:{...c,...e}}),h=(e,n)=>{t({object:Nx(!1,n?[...new Set([...d,e])]:d.filter(t=>t!==e))})},g=(e,n)=>{t({events:n?[...new Set([...l,e])]:l.filter(t=>t!==e)})},_=s(`name`),[v,y]=Y.useState({hook:_,count:0}),b=Y.useCallback(e=>{y(t=>t.hook===_&&t.count===e?t:{hook:_,count:e})},[_]),x=v.hook===_?v.count:0,S=Y.useRef(a);Y.useEffect(()=>{S.current=a}),Y.useEffect(()=>{S.current?.(x)},[x]);let C=!u&&d.length===1?d[0]:void 0,w=typeof c.language==`string`?c.language:`expression`,T=i;return(0,X.jsxs)(Ba,{kindLabel:o(`engine.inspector.hook.kind`),title:String(jx(e.label)||e.name||o(`engine.inspector.hook.kind`)),onClose:()=>{},closeLabel:o(`engine.inspector.action.close`),hideClose:!0,children:[(0,X.jsx)(Ax,{title:`Basics`}),(0,X.jsx)(G,{label:`Label`,value:jx(e.label),onCommit:e=>t({label:e||void 0}),placeholder:`Human-readable name`,disabled:n}),(0,X.jsx)(G,{label:`Name`,value:s(`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)(I,{className:`text-xs text-muted-foreground`,children:`Object(s) this hook fires on`}),(0,X.jsx)(U,{label:`All objects (*)`,value:u,onCommit:e=>t({object:e?Ox:Nx(!1,d)}),disabled:n}),!u&&(0,X.jsx)(`div`,{className:`max-h-40 space-y-1 overflow-auto rounded-md border p-2`,children:p.length===0?(0,X.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:`No objects found — publish an object, then pick it here.`}):p.map(e=>(0,X.jsx)(U,{label:e.label,value:d.includes(e.value),onCommit:t=>h(e.value,t),disabled:n},e.value))}),!u&&d.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)(Ax,{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:Ex.map(e=>(0,X.jsx)(U,{label:e,value:l.includes(e),onCommit:t=>g(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:Dx.map(e=>(0,X.jsx)(U,{label:e,value:l.includes(e),onCommit:t=>g(e,t),disabled:n},e))}),l.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)(Ax,{title:`Function`,hint:`The handler that runs when the hook fires.`}),(0,X.jsx)(W,{label:`Language`,value:w,options:Tx,onCommit:e=>m({language:e}),disabled:n}),(0,X.jsxs)(`div`,{className:`space-y-1`,children:[(0,X.jsx)(I,{className:`text-xs text-muted-foreground`,children:`Handler body`}),(0,X.jsx)(Gt,{"data-testid":`hook-body-source`,value:typeof c.source==`string`?c.source:``,onChange:e=>m({source:e.target.value}),disabled:n,spellCheck:!1,rows:8,placeholder:w===`expression`?`record.amount >= 0`:`// (ctx) => { ... }
|
|
17
|
+
return;`,className:`text-xs font-mono`}),(0,X.jsx)(`div`,{className:`text-[11px] text-muted-foreground/70`,children:w===`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)(Ax,{title:`Options`}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsx)(Za,{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)(U,{label:`Run asynchronously (after commit)`,value:e.async===!0,onCommit:e=>t({async:e}),disabled:n})})]}),(0,X.jsx)(da,{label:`Run only when (optional CEL)`,value:Sa(e.condition),onCommit:n=>t({condition:Ca(e.condition,n)}),objectName:C,disabled:n,onBlockingIssuesChange:b})]}),T&&(0,X.jsxs)(`div`,{className:`border-t pt-3 space-y-1.5`,children:[(0,X.jsx)(Ax,{title:o(`engine.inspector.moreFields`),hint:`Advanced / rarely-used properties.`}),(0,X.jsx)(Na,{schema:T,value:e,hiddenFields:kx,readOnly:n,onChange:e=>t(e)})]})]})}function Fx(){po(`dashboard`,l_),go(`dashboard`,w_),po(`flow`,ly),po(`app`,ky),po(`view`,Ry),go(`view`,zy),po(`page`,ad),go(`page`,qy),go(`report`,Ya),po(`object`,ob),go(`object`,Db),go(`dataset`,tx),go(`action`,wx),go(`hook`,Px)}du(),hu(),Cu(),a_(),Fx();var Ix=new Map;function Lx(e,t){Ix.set(e,t)}function Rx(e){return Ix.get(e)}function zx({name:e}){return(0,X.jsx)(re,{schema:{type:`object-view`,objectName:e}})}Lx(`object`,zx);export{Fo as _,kc as a,xo as b,lc as c,ms as d,ps as f,Io as g,Lo as h,tl as i,xs as l,os as m,Yd as n,Cc as o,vs as p,ku as r,Sc as s,Rx as t,bs as u,No as v,bo as y};
|