@objectstack/console 17.2.0 → 17.3.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 +611 -0
- package/README.md +26 -10
- package/dist/.objectstack-injection.json +2 -2
- package/dist/.objectui-sha +1 -1
- package/dist/assets/ActionResultDialog-CQwenjVA.js +9 -0
- package/dist/assets/{AiPendingActionsPage-CyG11hX9.js → AiPendingActionsPage-7gZ8zlOy.js} +1 -1
- package/dist/assets/ApiConsolePage-DUF0ysH7.js +1 -0
- package/dist/assets/{AppDocsIndex-BXkNskk1.js → AppDocsIndex-CP_AVG4X.js} +1 -1
- package/dist/assets/AppManagementPage-BJktnoa5.js +1 -0
- package/dist/assets/ApprovalsInboxPage-DlnxY-uy.js +1 -0
- package/dist/assets/{AuditLogPage-BZZ6tzHu.js → AuditLogPage-DIJPRjji.js} +1 -1
- package/dist/assets/ComponentNavView-C84QByT7.js +1 -0
- package/dist/assets/CreateViewDialog-Zbd9Cagm.js +1 -0
- package/dist/assets/DashboardView-UyKHklBx.js +1 -0
- package/dist/assets/{DeveloperHubPage-KEpKc45V.js → DeveloperHubPage-BRyNdrCJ.js} +1 -1
- package/dist/assets/DocPage-Bx8ZXCYt.js +1 -0
- package/dist/assets/{DocShell-DMJHUgE5.js → DocShell-Ipy_IDvh.js} +1 -1
- package/dist/assets/{DocsIndex-Bb5OtPb3.js → DocsIndex-CmY-7OQR.js} +1 -1
- package/dist/assets/{DocsLayout-CoIVTMH_.js → DocsLayout-BNsSvaz2.js} +1 -1
- package/dist/assets/{DocsSlug-BARWHmXg.js → DocsSlug-Cb_NMM1k.js} +1 -1
- package/dist/assets/ExpressionProvider-DqGWVuxV.js +1 -0
- package/dist/assets/FlowRunsPage-B6ustUgi.js +1 -0
- package/dist/assets/{IntegrationsPage-DTXA-Nne.js → IntegrationsPage-chOxmiyU.js} +2 -2
- package/dist/assets/InterfaceListPage-DVETnQm5.js +1 -0
- package/dist/assets/MarketplaceInstalledPage-DA5pjhAz.js +1 -0
- package/dist/assets/MarketplacePackagePage-dCIVHBFi.js +4 -0
- package/dist/assets/MarketplacePage-wJb6g1p7.js +1 -0
- package/dist/assets/MetadataInspector-Cu-n1FYz.js +1 -0
- package/dist/assets/ObjectDataPage-CP-YSZYQ.js +1 -0
- package/dist/assets/PageView-B1_ibRuM.js +1 -0
- package/dist/assets/ProfilePage-DEr5iZVB.js +1 -0
- package/dist/assets/PublicFormsPage-CBcKQbNl.js +1 -0
- package/dist/assets/RecordDetailView-A8bbPnkK.js +3 -0
- package/dist/assets/RecordFormPage-CGQlYWDk.js +1 -0
- package/dist/assets/ReportDefaultInspector-R_p6YStL.js +1 -0
- package/dist/assets/ReportView-BTMrtcGH.js +2 -0
- package/dist/assets/RuntimeDraftBar-agGU39FL.js +1 -0
- package/dist/assets/SchemaForm-DJbupOno.js +3 -0
- package/dist/assets/SearchResultsPage-CHhZUc6L.js +1 -0
- package/dist/assets/SettingsHub-BGLR_gS7.js +1 -0
- package/dist/assets/SettingsView-Bq-7Zkzs.js +1 -0
- package/dist/assets/SkeletonDetail-B4-UKxai.js +1 -0
- package/dist/assets/SystemHubPage-CVZVag1e.js +1 -0
- package/dist/assets/{abnfDiagram-N423BO3Z-DfpQlDUF.js → abnfDiagram-VCTEODGH-DUS5D5dU.js} +1 -1
- package/dist/assets/app-shell-eager-leaves-BB0oaPx6.js +1 -0
- package/dist/assets/{utils-CJ4UwXMF.js → appRoute-DEVGXLLH.js} +1 -1
- package/dist/assets/architecture-7GRP2DOG-kzM7RUjO.js +1 -0
- package/dist/assets/{architectureDiagram-T3A2C74G-Ej_4n3NG.js → architectureDiagram-5GKGNRK7-mGW8P1lC.js} +1 -1
- package/dist/assets/blockDiagram-OSKFZWR5-Bz2hnVmp.js +129 -0
- package/dist/assets/c4Diagram-7LVT6UL2-DU3u1Y6c.js +38 -0
- package/dist/assets/channel-FD4s9EIH.js +1 -0
- package/dist/assets/{chunk-U6XO7XAA-D-dXvZaW.js → chunk-2ZTRR5NV-DXmA5XXf.js} +1 -1
- package/dist/assets/chunk-3NF5O7KM-B8Q7HUio.js +168 -0
- package/dist/assets/{chunk-YOTPTUD7-CDtXQZ13.js → chunk-3Z5EZCMW-D3OlaP15.js} +1 -1
- package/dist/assets/chunk-4HAMMTFA-BPKwX4iB.js +62 -0
- package/dist/assets/{chunk-BIQX33UG-DMScvo0C.js → chunk-5V3GS4D5-sE73jHoi.js} +1 -1
- package/dist/assets/{chunk-MOZMSUNE-DG70Besp.js → chunk-6AZGARVD-dsTIs5yl.js} +1 -1
- package/dist/assets/{chunk-5JV3BV7I-BrKM6vC-.js → chunk-6EIED4P4-BB4xaK3K.js} +1 -1
- package/dist/assets/{chunk-R7FJI6CG-DsJHM8am.js → chunk-6K3QC6MW-DaG1LefG.js} +1 -1
- package/dist/assets/{chunk-OSBZ3O6U-Dch_xyhf.js → chunk-6TQVIW2G-DL8WEcT0.js} +1 -1
- package/dist/assets/{chunk-JG7HCLWE-lCTbN-f1.js → chunk-747NJXEK-Bdie6H1T.js} +1 -1
- package/dist/assets/chunk-75Z2AOVW-CkSdnmiC.js +2 -0
- package/dist/assets/chunk-CLGD4ZFX-BTkDISwp.js +1 -0
- package/dist/assets/chunk-DU6HZSFF-BkY4hAzc.js +127 -0
- package/dist/assets/{chunk-2GRJ4B5K-D1if-ThW.js → chunk-F27PBJKO-DUKg0YWV.js} +1 -1
- package/dist/assets/{chunk-KEIR6QF5-ydf36Hye.js → chunk-FOHPRMQF-C65HoZVt.js} +2 -2
- package/dist/assets/chunk-GMAD6QVW-DZo_NykZ.js +72 -0
- package/dist/assets/chunk-GVQU2GXP-9ELY9S6X.js +1 -0
- package/dist/assets/chunk-H2I77ZZE-vCr_buP7.js +1 -0
- package/dist/assets/{chunk-GF5L2VYU-Dgjjn2FR.js → chunk-HLEWEB6X-iPkY2ESt.js} +1 -1
- package/dist/assets/{chunk-QBLGF6JB-CzQYydMJ.js → chunk-I5DQTOEV-Cz6Y6T9y.js} +1 -1
- package/dist/assets/{chunk-5FCAYU7R-BuOxxvKk.js → chunk-ICYGCRZG-DdtFYQ2l.js} +1 -1
- package/dist/assets/{chunk-CQNSW5MT-CCth14ZS.js → chunk-IH6LHLGP-DybuHD8B.js} +1 -1
- package/dist/assets/{chunk-CYSBUYHQ-DIigEFGo.js → chunk-KI3K4JFJ-CB_CI00L.js} +1 -1
- package/dist/assets/chunk-L3NEJ4N5-Bzz35TZJ.js +1 -0
- package/dist/assets/chunk-LNGE3PJU-DWpGwHrW.js +34 -0
- package/dist/assets/chunk-LQGUR6SS-iVI0GACK.js +1 -0
- package/dist/assets/chunk-OSK3NFVY-DcRwXCQD.js +10 -0
- package/dist/assets/{chunk-5TONJI2A-Bdh0MHqz.js → chunk-OUJLGHUK-TbeyE6CA.js} +1 -1
- package/dist/assets/chunk-P2QGCYS3-nx2-dM5t.js +1 -0
- package/dist/assets/{chunk-KBJHAD2P-DI4-lUt-.js → chunk-POPQ4Y6H-BxLOacOG.js} +1 -1
- package/dist/assets/{chunk-4I5QYGJK-DlrWrdEa.js → chunk-PWAF6VOD-2mst9kZu.js} +1 -1
- package/dist/assets/{chunk-6Q2QTUOP-C2vvuHlO.js → chunk-SVP7TREG-C3BMpr4x.js} +1 -1
- package/dist/assets/{chunk-EMLP6XTP-B4CrDa5p.js → chunk-UY3FDG6J-CDAtW6MI.js} +1 -1
- package/dist/assets/{chunk-5HE753X5-T_shrJhj.js → chunk-XHIXRSVI-CqmtoxrP.js} +1 -1
- package/dist/assets/chunk-XXDRQBXY-iNC8aYmk.js +1 -0
- package/dist/assets/{chunk-5RXB4S5H-JwFhdddt.js → chunk-ZLD2IHE6-ZFqtFJbj.js} +2 -2
- package/dist/assets/classDiagram-CYGNFDIV-D5Pd2TCl.js +1 -0
- package/dist/assets/classDiagram-v2-TLXNO2FR-D5Pd2TCl.js +1 -0
- package/dist/assets/componentRegistry-ByxoJqMW.js +1 -0
- package/dist/assets/{cose-bilkent-JH36ORCC-XP-DnSP5.js → cose-bilkent-JH36ORCC-CPQv9aQH.js} +1 -1
- package/dist/assets/createDerive-Best2JCj.js +2 -0
- package/dist/assets/cynefin-OW5HDTMX-Dtvf1C60.js +1 -0
- package/dist/assets/{cynefinDiagram-MW4NZA55-B8MvpqXe.js → cynefinDiagram-5FMLGOSQ-Lnly8IJd.js} +1 -1
- package/dist/assets/cytoscape.esm-CGd-uY3x.js +321 -0
- package/dist/assets/dagre-OS7QT2EB-CdXLxmTK.js +4 -0
- package/dist/assets/dagre-PrKaheQc.js +1 -0
- package/dist/assets/data-adapter-DL25qpAe.js +5 -0
- package/dist/assets/default-inspector-registry-DeEG98bO.js +1 -0
- package/dist/assets/{diagram-7IWD3JNH-Xj62y5BF.js → diagram-S7CK7UJ4-DE8I3gxQ.js} +4 -4
- package/dist/assets/{diagram-UB23O5K3-bseKIzhv.js → diagram-UQ7AKVKN-D2xQpbEq.js} +1 -1
- package/dist/assets/{diagram-B4RE2ZJO-mI-iOCGl.js → diagram-VSXAHHWV-DnttDSlO.js} +1 -1
- package/dist/assets/{diagram-Q27KOJAE-B98Knrnh.js → diagram-VX7I27RA-BSEwkn7K.js} +1 -1
- package/dist/assets/{diagram-LBJQPF4R-BMTSoZch.js → diagram-Z3DM3KII-BgB9f0Nv.js} +1 -1
- package/dist/assets/dist-BpPy7hlB.js +5 -0
- package/dist/assets/{ebnfDiagram-BXEA7PRR-Bgo10FP1.js → ebnfDiagram-PWID7BFC-32WvKbS2.js} +1 -1
- package/dist/assets/erDiagram-2YWLMYGG-Dwf8uAdl.js +99 -0
- package/dist/assets/eventmodeling-NTZA5JFV-CSwP2CpK.js +1 -0
- package/dist/assets/expressionUser-CASszt1z.js +1 -0
- package/dist/assets/flowDiagram-T62WH6J4-CqVSNJ8T.js +1 -0
- package/dist/assets/framework-BfSv4Kb0.js +36 -0
- package/dist/assets/{ganttDiagram-PKOTCBZU-CrmKcYGt.js → ganttDiagram-EL5Y4UJY-DqYIE0Cu.js} +2 -2
- package/dist/assets/{getIcon-1ZXs1v-a.js → getIcon-CgyYxSEC.js} +1 -1
- package/dist/assets/gitGraph-4MIJSDKK--Dc33TN5.js +1 -0
- package/dist/assets/{gitGraphDiagram-DS77QQ5N-COu0mOui.js → gitGraphDiagram-WWUBYQGX-D1dYmoGu.js} +1 -1
- package/dist/assets/{highlighted-body-OFNGDK62-CnGKNo0r.js → highlighted-body-OFNGDK62-BxO9mjPI.js} +1 -1
- package/dist/assets/i18n-Cfqor-xb.js +9 -0
- package/dist/assets/i18n-locales-Bz4c8KXc.js +31 -0
- package/dist/assets/index-BU-FzlQ6.js +20 -0
- package/dist/assets/index-_VyGO4ms.css +2 -0
- package/dist/assets/info-A6RAGUB7-DBa3mCQO.js +1 -0
- package/dist/assets/{infoDiagram-6WML65LV-BT0Q6MIs.js → infoDiagram-FKFFQAWI-Cr1-5_Am.js} +1 -1
- package/dist/assets/infrastructure-CIpDEFyQ.js +3 -0
- package/dist/assets/{ishikawaDiagram-WSZJBQD7-kvPjMvBP.js → ishikawaDiagram-5VMMS53U-Bsjx7BsE.js} +1 -1
- package/dist/assets/{journeyDiagram-NVQOT4AX-DhXy7wxt.js → journeyDiagram-EYS64GPL-1scn5Z5c.js} +2 -2
- package/dist/assets/{kanban-definition-27J2QSJJ-CFDavpZY.js → kanban-definition-UXKFOSKX-DjLQAv5U.js} +2 -2
- package/dist/assets/mermaid-GHXKKRXX-NzEcDxBh.js +1 -0
- package/dist/assets/{mermaid-parser.core-Dd2B8Ckv.js → mermaid-parser.core-DUt1FNlO.js} +1 -1
- package/dist/assets/mermaid.core-pW40dd4u.js +10 -0
- package/dist/assets/metadata-admin-pawEBYI9.js +9 -0
- package/dist/assets/{mindmap-definition-FAOFIHXS-ITGoV4nW.js → mindmap-definition-THT77NOG-CUcYMB9H.js} +1 -1
- package/dist/assets/nav-selection-Dzm_mA3C.js +1 -0
- package/dist/assets/packet-AYTQ26CC-CPP93DZD.js +1 -0
- package/dist/assets/{pegDiagram-VL7TDLO6-BoRu9yvl.js → pegDiagram-XKGWAZYB-CT1r3sRa.js} +1 -1
- package/dist/assets/pie-WAS4IAKB-B-zzBvuc.js +1 -0
- package/dist/assets/{pieDiagram-7S7Q4E2Y-DVsM9krU.js → pieDiagram-E7YTZNPT-CSi-V1LQ.js} +3 -3
- package/dist/assets/plugin-calendar-BwiiCIjv.js +1 -0
- package/dist/assets/plugin-charts-CDGkx7z5.js +7 -0
- package/dist/assets/plugin-chatbot-BGnkLzFS.js +122 -0
- package/dist/assets/plugin-dashboard-Bj4ldCX6.js +6 -0
- package/dist/assets/plugin-form-_fjHxKTV.js +1 -0
- package/dist/assets/plugin-gantt-zR8DkpEg.js +63 -0
- package/dist/assets/plugin-grid-kkbz4uec.js +9 -0
- package/dist/assets/plugin-kanban-DA0eW6yj.js +1 -0
- package/dist/assets/plugin-map-DukneTNg.js +1 -0
- package/dist/assets/{plugin-markdown-DNllWgPM.js → plugin-markdown-B7zwZHmn.js} +1 -1
- package/dist/assets/plugin-report-DaPtlsJr.js +59 -0
- package/dist/assets/plugin-timeline-B6rsNNAK.js +1 -0
- package/dist/assets/plugin-tree-DauauLFc.js +1 -0
- package/dist/assets/plugin-view-5qxxRyZZ.js +1 -0
- package/dist/assets/plugins-views-iYcMmImr.js +4 -0
- package/dist/assets/{quadrantDiagram-CIZ2JOQS-C4VzXHnp.js → quadrantDiagram-AXDQQJYC-DUJ_94hm.js} +1 -1
- package/dist/assets/radar-RG4KPBEZ-DWmbpYEk.js +1 -0
- package/dist/assets/railroad-74A4TZTK-xJ7dMu2F.js +1 -0
- package/dist/assets/railroad-abnf-HS5TGJTU-Cw4KG_nE.js +1 -0
- package/dist/assets/railroad-ebnf-LZEXJU2U-C0cgrfTl.js +1 -0
- package/dist/assets/railroad-peg-WCYAUIDC-DOEGG9oQ.js +1 -0
- package/dist/assets/{railroadDiagram-AXF67PYL-DqZ3yKWv.js → railroadDiagram-O6MQD6OU-CEyfAhzM.js} +1 -1
- package/dist/assets/{requirementDiagram-LRYGKXZP-BeH0P3vD.js → requirementDiagram-IS5BZ75X-CAK7hvBg.js} +2 -2
- package/dist/assets/{runtime-metadata-persistence-DTOJpVmd.js → runtime-metadata-persistence-DYPxFzHI.js} +1 -1
- package/dist/assets/{sankeyDiagram-W5VNT64P-Bu_tPh-A.js → sankeyDiagram-P5KCCOFB-DgYJh7uz.js} +2 -2
- package/dist/assets/{sequenceDiagram-SI44F4Z6-BWEuLn1a.js → sequenceDiagram-WJ2MYXX4-DsQerPtC.js} +1 -1
- package/dist/assets/{src-CY2xhbXR.js → src-CVJP2nIc.js} +1 -1
- package/dist/assets/src-JX1BkhmR.js +17 -0
- package/dist/assets/{src-DhAd4aY4.js → src-S6pzKItc.js} +1 -1
- package/dist/assets/src-_DxAIBqo.js +1 -0
- package/dist/assets/{stateDiagram-OKZ733FA-Cp7aDYsZ.js → stateDiagram-XQSTLZYL-BJndPKik.js} +1 -1
- package/dist/assets/stateDiagram-v2-IH3M54BS-Bi94bTLl.js +1 -0
- package/dist/assets/studioEntry-C6G8U-LG.js +1 -0
- package/dist/assets/submitRedirect-UXd9NsjL.js +1 -0
- package/dist/assets/swimlanes-V6O3JKXN-BiKyiEJr.js +1 -0
- package/dist/assets/swimlanesDiagram-JKAHXJPX-DKIR852g.js +8 -0
- package/dist/assets/{timeline-definition-Z64GVDOM-BcUiJfLU.js → timeline-definition-24CTP7MA-CW5rY3PX.js} +2 -2
- package/dist/assets/treeView-Q6P3EWNA-BcWCBGcU.js +1 -0
- package/dist/assets/treemap-WGGIJYW6-DMTEJzXV.js +1 -0
- package/dist/assets/ui-components-D2lrjG-t.js +43 -0
- package/dist/assets/ui-layout-UUTFXV6S.js +1 -0
- package/dist/assets/use-book-data-qUZAxIs0.js +1 -0
- package/dist/assets/useActionModal-CkM-zGdy.js +1 -0
- package/dist/assets/usePackageL10n-F9isJ9pn.js +1 -0
- package/dist/assets/useSettingsLabel-CSZBfUiw.js +1 -0
- package/dist/assets/utils-MjUhYVsx.js +1 -0
- package/dist/assets/{vendor-charts-BEGSmcjR.js → vendor-charts-CY9WhhzX.js} +1 -1
- package/dist/assets/vendor-i18n-C1AQDWux.js +1 -0
- package/dist/assets/{vendor-markdown-C_Ip9E_I.js → vendor-markdown-BW_XFZ_b.js} +25 -25
- package/dist/assets/vendor-objectstack-BeKUVjuj.js +270 -0
- package/dist/assets/{vennDiagram-T6HMQDX7-BKJsL5fS.js → vennDiagram-4TSXK5OY-C79cMc25.js} +1 -1
- package/dist/assets/wardley-WFR3VGLG-BRyRizpT.js +1 -0
- package/dist/assets/{wardleyDiagram-T6FBY63Y-CZ0aMbYX.js → wardleyDiagram-VM6X3IG4-BAO0_jUk.js} +1 -1
- package/dist/assets/{xychartDiagram-ELKLHX3M-BpK2RmQ_.js → xychartDiagram-S5SC5T6Z-BIRd7YRo.js} +3 -3
- package/dist/eager-closure.json +180 -139
- package/dist/index.html +222 -6
- package/package.json +2 -2
- package/dist/assets/AdapterProvider-gULVLpjV.js +0 -3
- package/dist/assets/ApiConsolePage-DYuOp_W4.js +0 -1
- package/dist/assets/AppManagementPage-BvSxDdA_.js +0 -1
- package/dist/assets/ApprovalsInboxPage-oep3a-Ek.js +0 -1
- package/dist/assets/ComponentNavView-Cq4wkNUa.js +0 -1
- package/dist/assets/DashboardView-C23ZCS2S.js +0 -1
- package/dist/assets/DocPage-Y4rWCZ3E.js +0 -1
- package/dist/assets/ExpressionProvider-vGLngw8h.js +0 -1
- package/dist/assets/FlowRunsPage-BeGa9_ge.js +0 -1
- package/dist/assets/InterfaceListPage-BMvedZyV.js +0 -1
- package/dist/assets/ManagedByBadge-mKmG0hP7.js +0 -1
- package/dist/assets/MarketplaceAccessDenied-BBMyNu2w.js +0 -1
- package/dist/assets/MarketplaceInstalledPage-B4qrvb7w.js +0 -1
- package/dist/assets/MarketplacePackagePage-BuVfVeBj.js +0 -4
- package/dist/assets/MarketplacePage-Cmltk5nG.js +0 -1
- package/dist/assets/MetadataInspector-kVAu8vlh.js +0 -1
- package/dist/assets/MetadataProvider-DyFZSNqq.js +0 -1
- package/dist/assets/ObjectDataPage-BKHEYwXA.js +0 -1
- package/dist/assets/PageView-CTqS-VD9.js +0 -1
- package/dist/assets/ProfilePage-CBUxXn5a.js +0 -1
- package/dist/assets/PublicFormsPage-B8Dk8fky.js +0 -1
- package/dist/assets/RecordDetailView-BBNqsNy9.js +0 -11
- package/dist/assets/RecordFormPage-CeUmmc_n.js +0 -1
- package/dist/assets/ReportDefaultInspector-CRjDi2Er.js +0 -3
- package/dist/assets/ReportView-Cwi_Po4H.js +0 -2
- package/dist/assets/SearchResultsPage-Cg0oq2by.js +0 -1
- package/dist/assets/SettingsHub-B5_S9YgI.js +0 -1
- package/dist/assets/SettingsView-Csi1awf-.js +0 -1
- package/dist/assets/SystemHubPage-CnDri9oU.js +0 -1
- package/dist/assets/architecture-TIHT7OUA-B8Ln-u1a.js +0 -1
- package/dist/assets/blockDiagram-VBNYF7ZC-l_P_W7_Y.js +0 -132
- package/dist/assets/c4Diagram-5PPSVZJV-CE82HAlO.js +0 -10
- package/dist/assets/channel-DowAYf9b.js +0 -1
- package/dist/assets/chunk-3NCLNEKW-Z5ckM4mG.js +0 -1
- package/dist/assets/chunk-7BUUIJ7U-Bb538aSH.js +0 -1
- package/dist/assets/chunk-7Z6QIM7H-m6s_oalL.js +0 -10
- package/dist/assets/chunk-I66GZJ75-BsY3mBMx.js +0 -127
- package/dist/assets/chunk-J7OUQ5F2-Cl4FNR_k.js +0 -1
- package/dist/assets/chunk-JQJVKLGR-BApWxqMA.js +0 -156
- package/dist/assets/chunk-NSK5VX7P-BBTxIP6Z.js +0 -2
- package/dist/assets/chunk-QR6OTTB3-DJcD7xr-.js +0 -62
- package/dist/assets/chunk-RYQCIY6F-CnMsR_qh.js +0 -1
- package/dist/assets/chunk-UBXNYLIW-B7z1tp3V.js +0 -1
- package/dist/assets/chunk-W5SLKNZC-BnMc5i0B.js +0 -1
- package/dist/assets/chunk-WRU74C26-MrzCPX2E.js +0 -70
- package/dist/assets/chunk-XXDRQBXY-NKBlW2Dm.js +0 -1
- package/dist/assets/chunk-ZIRB5QZD-O39ZBUk3.js +0 -32
- package/dist/assets/classDiagram-JCYQIIEL-C4ADaKBz.js +0 -1
- package/dist/assets/classDiagram-v2-OCEON4UE-C4ADaKBz.js +0 -1
- package/dist/assets/createDerive-B3AGnDaY.js +0 -1
- package/dist/assets/cynefin-VYW2F7L2-exAq6djZ.js +0 -1
- package/dist/assets/cytoscape.esm-B-NFISlW.js +0 -321
- package/dist/assets/dagre-Buvkdvvj.js +0 -1
- package/dist/assets/dagre-VZM6K2ZE-B5E8-xuM.js +0 -4
- package/dist/assets/dist-Ck19TqqJ.js +0 -5
- package/dist/assets/erDiagram-JOGREHBK-BU4b8mUv.js +0 -85
- package/dist/assets/eventmodeling-45OFAUF4-DVTVIsGT.js +0 -1
- package/dist/assets/flowDiagram-UKHOOZJN-BDHHPApJ.js +0 -1
- package/dist/assets/framework-BwfIhdyz.js +0 -55
- package/dist/assets/gitGraph-TEB2WS4Q-DizXBl0d.js +0 -1
- package/dist/assets/i18n-rra-09wp.js +0 -9
- package/dist/assets/index-BLepsDd_.js +0 -19
- package/dist/assets/index-D26gl3rg.css +0 -2
- package/dist/assets/info-DKCQHKI2-CfAGND28.js +0 -1
- package/dist/assets/infrastructure-BCTDJsqi.js +0 -3
- package/dist/assets/map-BaFkSB1l.js +0 -1
- package/dist/assets/mermaid-GHXKKRXX-CR9PcY0X.js +0 -1
- package/dist/assets/mermaid.core-BwiBFu_S.js +0 -10
- package/dist/assets/metadata-admin-BE9_-F_f.js +0 -25
- package/dist/assets/packet-7NZHBO7P-DeymwuCa.js +0 -1
- package/dist/assets/pie-RZYD4A2V-C2S5u8nr.js +0 -1
- package/dist/assets/plugin-calendar-BfY9ZunQ.js +0 -1
- package/dist/assets/plugin-charts-CmWL7Og-.js +0 -7
- package/dist/assets/plugin-chatbot-mxoQfkdx.js +0 -120
- package/dist/assets/plugin-dashboard-CzbAW1Rz.js +0 -6
- package/dist/assets/plugin-form-ItAwTFz-.js +0 -1
- package/dist/assets/plugin-gantt-DF5W5xkN.js +0 -64
- package/dist/assets/plugin-grid-B42Photo.js +0 -9
- package/dist/assets/plugin-kanban-Dh3HIJIm.js +0 -1
- package/dist/assets/plugin-map-C1wSLqlB.js +0 -1
- package/dist/assets/plugin-report-yfOfZPQg.js +0 -59
- package/dist/assets/plugin-timeline-BpuaaqBd.js +0 -1
- package/dist/assets/plugin-tree-BrXE50se.js +0 -1
- package/dist/assets/plugin-view-Jc0rkk7A.js +0 -1
- package/dist/assets/plugins-views-cOiN-mPq.js +0 -4
- package/dist/assets/radar-I7S5WNFK-DzcfTC8k.js +0 -1
- package/dist/assets/railroad-3IZDKUUU-DT2-gzup.js +0 -1
- package/dist/assets/railroad-abnf-AHOZXSZD-BvCkhVdg.js +0 -1
- package/dist/assets/railroad-ebnf-EBAXGLYW-rvjxEE4k.js +0 -1
- package/dist/assets/railroad-peg-LSFZ7HO6-BIzZt1tD.js +0 -1
- package/dist/assets/skeletons-BwA1TSR2.js +0 -1
- package/dist/assets/src-BLbFBP_B.js +0 -1
- package/dist/assets/stateDiagram-v2-UEYNNEHI-DaTg8C5m.js +0 -1
- package/dist/assets/swimlanes-SLNWSIFB-wrx1JN6o.js +0 -1
- package/dist/assets/swimlanesDiagram-ULZ7WXOC-Bqz9GVuM.js +0 -8
- package/dist/assets/treeView-QDETBFTQ-DKZwqlNb.js +0 -1
- package/dist/assets/treemap-6X3UGDF4-Bqsldamv.js +0 -1
- package/dist/assets/ui-components-Dwq5utCl.js +0 -42
- package/dist/assets/ui-layout-DPFlQaQp.js +0 -1
- package/dist/assets/use-book-data-CZc8MJsb.js +0 -1
- package/dist/assets/useActionModal-DYiSBx1G.js +0 -1
- package/dist/assets/usePackageL10n-D91-102Q.js +0 -1
- package/dist/assets/useSettingsLabel-CeZ36S4g.js +0 -1
- package/dist/assets/vendor-i18n-Cpia2wlg.js +0 -1
- package/dist/assets/vendor-objectstack-B1R3ym-9.js +0 -264
- package/dist/assets/wardley-OPB4EBWU-C_U_bbc2.js +0 -1
- /package/dist/assets/{sizeCapture-X5ZJPWSS-B0uUizjq.js → sizeCapture-INFHLROL-B0uUizjq.js} +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./ui-components-BL3SEdAz.css","./plugin-dashboard-DnNKJB60.css","./plugin-map-DSnsEFKn.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,c as i,d as a,f as o,g as s,h as c,i as l,l as u,m as d,o as f,p,r as m,s as h,u as g,v as _}from"./vendor-react-CsWFRkED.js";import{_ as v,a as y,c as b,d as x,f as S,g as C,h as w,i as T,l as E,m as D,n as O,o as k,p as A,r as j,s as M,u as ee,v as N,y as te}from"./infrastructure-CIpDEFyQ.js";import{A as P,Bn as F,Et as ne,On as re,Ot as I,Pn as ie,Rn as L,Tt as ae,zn as oe}from"./vendor-objectstack-BeKUVjuj.js";import{a as R,i as se,r as z,s as B,t as ce}from"./data-adapter-DL25qpAe.js";import{$ as le,$n as ue,A as de,Cr as fe,D as pe,Dn as me,E as V,Er as he,Et as ge,F as _e,G as ve,Hr as ye,J as be,K as xe,L as Se,Lt as Ce,Nt as H,Q as we,Qn as U,Qr as W,S as Te,Tt as Ee,Xr as De,Yr as Oe,_ as ke,ar as Ae,at as je,b as Me,cr as Ne,dt as Pe,et as Fe,fr as Ie,ft as Le,hr as Re,ht as ze,ir as Be,k as Ve,lr as He,q as Ue,sr as We,ti as Ge,ur as Ke,ut as qe,zt as Je}from"./framework-BfSv4Kb0.js";import{S as Ye,_ as Xe,b as Ze,c as Qe,d as $e,g as et,h as tt,m as nt,r as rt,s as it,u as at,v as ot,x as st,y as G}from"./i18n-locales-Bz4c8KXc.js";import{$ as ct,$i as lt,$s as ut,$t as dt,Ac as ft,Ar as pt,Ba as mt,Bc as ht,Bn as K,Bo as gt,Bt as _t,C as vt,Ci as yt,Cn as bt,Cr as xt,Cs as St,Da as Ct,Dc as wt,Dn as Tt,Do as Et,En as Dt,Eo as Ot,Fn as kt,Fr as At,Fs as jt,Gn as Mt,Gr as Nt,Ha as Pt,Hc as Ft,Hn as It,Hr as Lt,Ht as Rt,Ic as zt,In as q,Io as Bt,Ir as Vt,Is as Ht,J as Ut,Ja as Wt,Jc as Gt,Jo as Kt,Jr as qt,Ki as Jt,Kn as Yt,Ko as Xt,Kr as Zt,Lr as Qt,Mi as $t,Mr as en,Ms as tn,Ni as nn,Nn as rn,No as an,Nt as on,On as sn,Oo as cn,Or as ln,Os as un,Pa as dn,Pc as fn,Pi as pn,Pn as mn,Pr as hn,Q as gn,Qc as _n,Qi as vn,Qs as yn,Qt as bn,R as xn,Rc as Sn,Ri as Cn,Si as wn,Sn as Tn,Sr as En,Ss as Dn,T as On,Tc as kn,Tn as An,To as jn,Ts as Mn,Tt as Nn,Ua as Pn,Ui as Fn,Un as In,Ur as Ln,Us as Rn,Va as zn,Vn as Bn,Vr as Vn,Vs as Hn,Vt as Un,W as Wn,Wa as Gn,Wi as Kn,Wn as qn,Wo as Jn,Wr as Yn,Xa as Xn,Xc as Zn,Xi as Qn,Xn as $n,Xo as er,Xr as J,Ys as tr,Z as nr,Zo as rr,Zt as ir,_c as ar,_i as or,_n as sr,_o as cr,_r as lr,aa as ur,ac as dr,ai as fr,b as pr,bc as mr,bn as hr,br as gr,cc as _r,cn as vr,co as yr,di as br,dn as xr,do as Sr,dr as Cr,dt as wr,ea as Tr,ei as Er,en as Dr,eo as Or,et as kr,fa as Ar,fc as jr,fi as Mr,fr as Nr,gc as Pr,gn as Fr,go as Ir,gr as Lr,gs as Rr,hc as zr,hi as Br,ho as Vr,hr as Hr,hs as Ur,ht as Wr,ic as Gr,ii as Kr,il as qr,jo as Jr,jr as Yr,jt as Xr,kc as Zr,kn as Qr,ko as $r,kr as ei,la as ti,ln as ni,ma as ri,mo as ii,mr as ai,mt as oi,na as si,ni as ci,nn as li,no as ui,nt as di,oi as fi,on as pi,oo as mi,pa as hi,pc as gi,pi as _i,po as vi,pr as yi,qi as bi,qr as xi,ra as Si,rl as Ci,rn as wi,sa as Ti,sc as Ei,sn as Di,so as Oi,ss as ki,ta as Ai,tn as ji,to as Mi,ts as Ni,tt as Pi,ui as Fi,uo as Ii,us as Li,ut as Ri,va as zi,vn as Bi,vo as Y,vr as Vi,vt as Hi,w as Ui,wn as Wi,ws as Gi,xn as Ki,xr as qi,yi as Ji,yn as Yi,yr as Xi,zi as Zi,zs as Qi,zt as $i}from"./ui-components-D2lrjG-t.js";import{n as ea,r as X}from"./vendor-ui-utils-BFw4cGI6.js";import{c as ta,d as na,f as ra,l as ia,m as aa,o as oa,p as sa,s as ca,u as la}from"./createDerive-Best2JCj.js";import{a as ua,c as da,i as fa,n as pa,o as ma,s as ha,t as ga}from"./plugin-form-_fjHxKTV.js";import{a as _a,i as va,r as ya,t as ba}from"./assistantBus-DNH-fDWN.js";import{a as xa,i as Sa,n as Ca,r as wa,t as Ta}from"./ExpressionProvider-DqGWVuxV.js";import{t as Ea}from"./expressionUser-CASszt1z.js";import{c as Da,d as Oa,n as ka,o as Aa,s as ja}from"./ActionResultDialog-CQwenjVA.js";import{a as Ma,i as Na,o as Pa,r as Fa,s as Ia,t as La}from"./useActionModal-CkM-zGdy.js";import{C as Ra,D as za,E as Ba,O as Va,S as Ha,T as Ua,_ as Wa,b as Ga,c as Ka,d as qa,f as Ja,g as Ya,h as Xa,l as Za,m as Qa,o as $a,p as eo,s as to,t as no,u as ro,v as io,x as ao}from"./RecordDetailView-A8bbPnkK.js";import{a as oo,i as so,n as co,o as lo,r as uo,t as fo}from"./appRoute-DEVGXLLH.js";import{C as po,D as mo,E as ho,O as go,S as _o,T as vo,_ as yo,b as bo,d as xo,f as So,g as Co,h as wo,i as To,k as Eo,l as Do,m as Oo,p as ko,r as Ao,t as jo,u as Mo,v as No,w as Po,x as Fo,y as Io}from"./plugin-chatbot-BGnkLzFS.js";import{_ as Lo,a as Ro,b as zo,c as Bo,d as Vo,f as Ho,g as Uo,h as Wo,i as Go,l as Ko,m as qo,n as Jo,o as Yo,p as Xo,r as Zo,s as Qo,t as $o,u as es,v as ts,y as ns}from"./src-JX1BkhmR.js";import{A as rs,C as is,D as as,E as os,M as ss,O as cs,S as ls,T as us,b as ds,i as fs,j as ps,k as ms,n as hs,w as gs,x as _s}from"./app-shell-eager-leaves-BB0oaPx6.js";import{t as vs}from"./preferLocal-CKqyhTP9.js";import{n as ys,t as bs}from"./utils-MjUhYVsx.js";import{i as xs,o as Ss,r as Cs,t as ws}from"./ui-layout-UUTFXV6S.js";import{_ as Ts,a as Es,c as Ds,d as Os,g as ks,h as As,l as js,n as Ms,o as Ns,s as Ps,t as Fs,u as Is,v as Ls,y as Rs}from"./vendor-dndkit-CkJ59XFL.js";import{a as zs,i as Bs,n as Vs,o as Hs}from"./plugin-grid-kkbz4uec.js";import{c as Us,l as Ws,o as Gs,s as Ks}from"./InterfaceListPage-DVETnQm5.js";import{t as qs}from"./getIcon-CgyYxSEC.js";import{a as Js,i as Ys,n as Xs,o as Zs,r as Qs,s as $s,t as ec}from"./nav-selection-Dzm_mA3C.js";import{B as tc,F as nc,G as rc,H as ic,I as ac,J as oc,K as sc,L as cc,O as lc,P as uc,U as dc,V as fc,W as pc,Y as mc,d as hc,f as gc,q as _c,r as vc}from"./SchemaForm-DJbupOno.js";import{n as yc,t as bc}from"./CreateViewDialog-Zbd9Cagm.js";import{f as xc}from"./plugins-views-iYcMmImr.js";import{c as Sc,d as Cc,l as wc,u as Tc}from"./plugin-view-5qxxRyZZ.js";import{n as Ec,t as Dc}from"./MetadataInspector-Cu-n1FYz.js";import{_ as Oc,f as kc,g as Ac,v as jc}from"./ReportDefaultInspector-R_p6YStL.js";import{g as Mc,i as Nc,r as Z,u as Pc}from"./i18n-Cfqor-xb.js";import{o as Fc,r as Ic,t as Lc}from"./runtime-metadata-persistence-DYPxFzHI.js";import{t as Rc}from"./RuntimeDraftBar-agGU39FL.js";import{n as zc}from"./SkeletonDetail-B4-UKxai.js";import{n as Bc}from"./componentRegistry-ByxoJqMW.js";import{_ as Vc,c as Hc,d as Uc,g as Wc,h as Gc,i as Kc,m as qc,p as Jc,r as Yc,s as Xc,t as Zc,u as Qc,v as $c}from"./default-inspector-registry-DeEG98bO.js";import{n as el,t as tl}from"./studioEntry-C6G8U-LG.js";import{n as nl}from"./submitRedirect-UXd9NsjL.js";var Q=e(r(),1),rl=e(_(),1),$=m(),il={type:`object-master-detail-form`,objectName:`expense_claim`,mode:`create`,formType:`simple`,title:`New Expense Claim`,submitText:`Create Claim`,fields:[`title`,`applicant`,`department`,`reason`,`currency`,`claim_status`,`payment_status`,`remarks`],details:[{title:`Expense Lines`,childObject:`expense_line`,relationshipField:`expense_claim`,amountField:`amount`,totalField:`total_amount`,columns:[{name:`expense_date`,label:`Date`,type:`date`},{name:`category`,label:`Category`,type:`select`,options:[{label:`Travel & Transport`,value:`travel_transport`},{label:`Lodging`,value:`lodging`},{label:`Meals & Entertainment`,value:`meals_entertainment`},{label:`Office Supplies`,value:`office_supplies`},{label:`Communications`,value:`communications`},{label:`Training & Conference`,value:`training_conference`},{label:`Client / Project`,value:`client_project`},{label:`Other`,value:`other`}]},{name:`description`,label:`Description`,type:`text`},{name:`merchant_vendor`,label:`Merchant`,type:`text`},{name:`amount`,label:`Amount`,type:`currency`}]}]},al=()=>(0,$.jsxs)(`div`,{className:`mx-auto max-w-3xl p-6`,children:[(0,$.jsx)(`h1`,{className:`mb-4 text-lg font-semibold`,children:`Dev · Master-Detail Form (ADR-0001)`}),(0,$.jsx)(ze,{schema:il})]}),ol={type:`element:definition-list`,properties:{columns:2,items:[{term:`Status`,description:`Active`},{term:`Owner`,description:`Ada Lovelace`},{term:`Plan`,description:`Enterprise`},{term:`Renewal`,description:`2026-12-01`}]}},sl={type:`element:repeater`,properties:{object:`showcase_category`,titleField:`name`,fields:[`color`],limit:10,emptyText:`No categories`}},cl=()=>(0,$.jsxs)(`div`,{className:`mx-auto max-w-2xl space-y-8 p-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`mb-3 text-lg font-semibold`,children:`Dev · element:definition-list`}),(0,$.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,$.jsx)(ze,{schema:ol})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`mb-3 text-lg font-semibold`,children:`Dev · element:repeater (showcase_category)`}),(0,$.jsx)(`div`,{className:`rounded-lg border p-4`,children:(0,$.jsx)(ze,{schema:sl})})]})]}),ll=0,ul=new Set,dl=[];function fl(){for(let e of ul)try{e(ll)}catch{}if(ll===0&&dl.length>0){let e=dl;dl=[];for(let t of e)try{t()}catch{}}}function pl(){ll+=1,fl()}function ml(){ll=Math.max(0,ll-1),fl()}function hl(){return ll}function gl(){return ll===0}function _l(e){return ul.add(e),()=>{ul.delete(e)}}function vl(e=1e4){return ll===0?Promise.resolve():new Promise(t=>{let n=!1,r=()=>{n||(n=!0,t())};dl.push(r),e>0&&typeof setTimeout<`u`&&setTimeout(r,e)})}function yl(e){return(async(...t)=>{pl();try{return await e(...t)}finally{ml()}})}function bl(){if(typeof window>`u`)return;let e=window,t=e.__objectui??={};Object.defineProperty(t,"pendingRequests",{get:hl,configurable:!0}),Object.defineProperty(t,"idle",{get:gl,configurable:!0}),t.whenIdle=vl,t.subscribe=_l}async function xl(e,t,n){let r;try{r=(await e.getObjectSchema(t))?.fields}catch{}return e=>n(t,e,r?.[e]?.label||e)}var Sl={readonly:(e,t)=>e(`detail.writeStrippedReadonly`,{fields:t,defaultValue:`Read-only, so it did not take effect: {{fields}}`}),readonly_when:(e,t)=>e(`detail.writeStrippedByState`,{fields:t,defaultValue:`Not editable in this record's current state, so it did not take effect: {{fields}}`}),primary_key:(e,t)=>e(`detail.writeStrippedPrimaryKey`,{fields:t,defaultValue:`The record's identifier cannot be changed by a save, so it did not take effect: {{fields}}`})},Cl=(e,t)=>e(`detail.writeStrippedUnknownReason`,{fields:t,defaultValue:`Not applied by the server: {{fields}}`});function wl(e){return Sl[e]??Cl}async function Tl(e,t,n,r,i){let a=new Map;for(let t of e.droppedFields){let e=a.get(t.reason)??[];for(let n of t.fields)e.includes(n)||e.push(n);a.set(t.reason,e)}if(a.size===0)return;let o=n&&e.resource?await xl(n,e.resource,r):e=>e,s=[];for(let[e,n]of a){if(n.length===0)continue;let r=n.map(o).join(`, `);s.push(wl(e)(t,r))}s.length!==0&&i.warning(t(`detail.writeStrippedTitle`,{defaultValue:`Saved — but some fields did not take effect`}),{description:s.join(`
|
|
3
|
+
`)})}function El({children:e,adapter:t}){let[n,r]=(0,Q.useState)(t??null),{t:i}=G(),a=(0,Q.useRef)(i);a.current=i;let{fieldLabel:o}=$e(),s=(0,Q.useRef)(o);return s.current=o,(0,Q.useEffect)(()=>{if(t){r(t);return}let e=!1,n,i;bl();async function o(){try{let t=new ce({baseUrl:``,fetch:yl(b()),autoReconnect:!0,maxReconnectAttempts:5,reconnectDelay:1e3,cache:{maxSize:50,ttl:3e5}});n=t.onWriteWarning(e=>{Tl(e,a.current,t,s.current,X)}),i=t.onSaveAdvisory(e=>{aa(e,a.current,X)}),await t.connect(),e||r(t)}catch(t){e||console.error(`[Console] Failed to initialize:`,t)}}return o(),()=>{e=!0,n?.(),i?.()}},[t]),(0,$.jsx)(ve.Provider,{value:n,children:e})}var Dl=3e5,Ol=[`app`,`view`],kl=1e3,Al={apps:`app`,objects:`object`,dashboards:`dashboard`,reports:`report`,pages:`page`},jl=`objectui:metadata:`,Ml=`@none`;function Nl(){try{return N.get()||Ml}catch{return Ml}}var Pl=`@anon`;function Fl(e){let t=2166136261,n=3266489909;for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);t=Math.imul(t^i,16777619),n=Math.imul(n^i,2246822507)}t=Math.imul(t^t>>>15,625341585),n=Math.imul(n^n>>>13,668265263);let r=e=>(e>>>0).toString(36).padStart(7,`0`);return`${r(t)}${r(n)}`}function Il(){let e=null;try{e=te.get()}catch{}return e?Fl(e):Pl}function Ll(e,t){return`${jl}${e}:${t}:${Il()}`}function Rl(e){return Ll(e,Nl())}function zl(){if(!(typeof sessionStorage>`u`))try{let e=`:${Il()}`;for(let t of Object.keys(sessionStorage))t.startsWith(jl)&&!t.endsWith(e)&&sessionStorage.removeItem(t)}catch{}}function Bl(){try{let e=import.meta;if(e&&e.env&&typeof e.env.MODE==`string`)return e.env.MODE!==`production`}catch{}return!1}var Vl=Bl();function Hl(...e){Vl&&console.debug(`[MetadataProvider]`,...e)}function Ul(e){return Array.isArray(e)?e:e&&typeof e==`object`&&`items`in e&&Array.isArray(e.items)?e.items:[]}function Wl(e){return e==null?null:typeof e==`object`&&`item`in e?e.item??null:e}function Gl(e){return!!e&&typeof e==`object`&&`name`in e&&typeof e.name==`string`}function Kl(e){return!!e&&typeof e==`object`&&!!e.viewKind&&!!e.object}function ql(e,t){let n=t.name||`${t.object}.${t.viewKind}`,r=t.config&&typeof t.config==`object`?t.config:{},i={...r,name:n,label:t.label??r.label,isDefault:!!t.isDefault};t.viewKind===`form`?(e.formViews[n]=i,(t.isDefault||!e.form)&&(e.form=i)):(e.listViews[n]=i,t.isDefault&&(e.primary=i))}function Jl(e,t){if(!e.length||!t.length)return e;let n={},r=new Set;for(let e of t)Kl(e)&&r.add(e.object);for(let e of t){if(Kl(e)){ql(n[e.object]||={listViews:{},formViews:{}},e);continue}let t=e?.name||e?.list?.data?.object||e?.form?.data?.object;if(!t||r.has(t))continue;let i=n[t]||={listViews:{},formViews:{}};for(let n of re(t,e))ql(i,n)}return e.map(e=>{let t=n[e.name];if(!t)return e;let r=e.listViews||e.list_views||{},i=e.formViews||e.form_views||{},a={...e,listViews:{...t.listViews,...r}};return(Object.keys(t.formViews).length||Object.keys(i).length)&&(a.formViews={...t.formViews,...i}),t.primary&&!e.list&&(a.list=t.primary),t.form&&!e.form&&(a.form=t.form),a})}function Yl(e){if(!e?.length)return e;let t={};for(let n of e){let e=n?.fields;if(!e)continue;let r=Array.isArray(e)?e.map(e=>[e?.name,e]):Object.entries(e);for(let[e,i]of r){let r=i;if(!e||!r?.inlineEdit||r.type!==`master_detail`&&r.type!==`lookup`)continue;let a=r.reference??r.reference_to;a&&(t[a]||=[]).push({childObject:n.name,relationshipField:e,inlineMode:fa(n,r.inlineEdit,{relationshipField:e}),...r.inlineTitle?{title:r.inlineTitle}:{},...Array.isArray(r.inlineColumns)?{columns:r.inlineColumns}:{},...typeof r.inlineAmountField==`string`?{amountField:r.inlineAmountField}:{}})}}return Object.keys(t).length?e.map(e=>{let n=t[e.name];if(!n?.length)return e;let r={...e.form||{type:`simple`}},i=Array.isArray(r.subforms)?r.subforms:[],a=new Set(i.map(e=>e.childObject));r.subforms=[...n.filter(e=>!a.has(e.childObject)),...i];let o={...e,form:r};return e.formViews?.default&&(o.formViews={...e.formViews,default:{...e.formViews.default,subforms:r.subforms}}),o}):e}function Xl(){return{status:`idle`,items:[],byName:new Map,error:null,fetchedAt:0,promise:null}}function Zl(e){if(typeof sessionStorage>`u`)return null;try{let t=sessionStorage.getItem(Rl(e));if(!t)return null;let n=JSON.parse(t);return Array.isArray(n)?n:null}catch{return null}}function Ql(e,t,n=Nl()){if(!(typeof sessionStorage>`u`))try{sessionStorage.setItem(Ll(e,n),JSON.stringify(t))}catch{}}function $l(e){if(!(typeof sessionStorage>`u`))try{sessionStorage.removeItem(Ll(e,Ml))}catch{}}function eu({children:e,adapter:t,ttlMs:n=Dl}){let r=(0,Q.useRef)(new Map),i=(0,Q.useRef)(new Map),a=(0,Q.useRef)(new Set),o=(0,Q.useRef)(t);o.current=t;let s=sa(),c=(0,Q.useMemo)(()=>s?ta({previewDrafts:!0}):null,[s]),l=(0,Q.useRef)(c);l.current=c;let[u,d]=(0,Q.useState)(0),f=(0,Q.useCallback)(()=>{typeof queueMicrotask==`function`?queueMicrotask(()=>d(e=>e+1)):Promise.resolve().then(()=>d(e=>e+1))},[]),p=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(!p.current){p.current=!0;return}r.current.clear(),i.current.clear(),f()},[s,f]);let m=(0,Q.useCallback)(e=>{let t=r.current.get(e);return t||(t=Xl(),r.current.set(e,t)),t},[]),h=(0,Q.useCallback)(e=>{let t=m(e);if(t.promise)return t.promise;if(t.status===`ready`&&Date.now()-t.fetchedAt<n)return Hl(`cache hit (fresh) type=${e} items=${t.items.length}`),Promise.resolve(t.items);if(t.status===`error`&&Date.now()-t.fetchedAt<kl)return Hl(`cache hit (recent failure) type=${e}`),Promise.resolve(t.items);let r=Date.now();t.status=`loading`,t.error=null;let i=l.current,s=(i?i.list(e):o.current.getClient().meta.getItems(e)).then(n=>{let o=Ul(n);if(e===`object`)for(let e of o)B(e);t.items=o,t.status=`ready`,t.error=null,t.fetchedAt=Date.now(),t.promise=null,t.byName.clear();for(let e of o)Gl(e)&&t.byName.set(e.name,e);if(e===`app`&&!i){let t=Nl();Ql(e,o,t),t===Ml?a.current.add(e):a.current.delete(e)}return Hl(`fetched type=${e} items=${o.length} in ${Date.now()-r}ms`),f(),o}).catch(n=>{let r=n instanceof Error?n:Error(String(n));return t.status=`error`,t.error=r,t.promise=null,t.fetchedAt=Date.now(),Hl(`fetch failed type=${e}`,r),f(),[]});return t.promise=s,s},[f,m,n]),g=(0,Q.useCallback)((e,t)=>{let n=m(e);if(n.byName.has(t))return Hl(`item cache hit type=${e} name=${t}`),Promise.resolve(n.byName.get(t)??null);let r=i.current.get(e);r||(r=new Map,i.current.set(e,r));let a=r.get(t);if(a)return a;let s=Date.now(),c=l.current,u=(c?c.get(e,t):o.current.getClient().meta.getItem(e,t)).then(i=>{let a=Wl(i);return a&&n.byName.set(t,a),Hl(`fetched item type=${e} name=${t} in ${Date.now()-s}ms`),r.delete(t),a}).catch(n=>(r.delete(t),Hl(`fetch item failed type=${e} name=${t}`,n),null));return r.set(t,u),u},[m]),_=(0,Q.useCallback)(async e=>{if(e){let t=m(e);t.fetchedAt=0,t.byName.clear(),await h(e);return}let t=Array.from(r.current.keys()).filter(e=>r.current.get(e).status!==`idle`);await Promise.all(t.map(e=>{let t=r.current.get(e);return t.fetchedAt=0,t.byName.clear(),h(e)}))},[h,m]),v=(0,Q.useCallback)((e,t)=>{let n=r.current.get(e);n&&(t?(n.byName.delete(t),n.items=n.items.filter(e=>e?.name!==t),Hl(`invalidated type=${e} name=${t}`)):(n.status=`idle`,n.items=[],n.byName.clear(),n.error=null,n.fetchedAt=0,Hl(`invalidated type=${e}`)),f())},[f]);(0,Q.useEffect)(()=>{if(s)return ya(({type:e})=>{v(e)})},[s,v]),(0,Q.useEffect)(()=>va(()=>{try{o.current?.clearCache?.()}catch{}_()}),[_]);let[y,b]=(0,Q.useState)(!0),[x,S]=(0,Q.useState)(null),{activeOrganization:w}=C(),T=w?.id??null,E=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=E.current;if(E.current=T,e===null||e===T){if(e===null&&T&&a.current.size>0){for(let e of a.current){let t=r.current.get(e);t&&t.status===`ready`&&t.items.length>0&&Ql(e,t.items,T),$l(e)}a.current.clear()}return}let t=!1;return r.current.clear(),i.current.clear(),b(!0),h(`app`).finally(()=>{t||b(!1)}),f(),()=>{t=!0}},[T,f,h]),(0,Q.useEffect)(()=>{let e=!1,t=s?null:Zl(`app`);if(zl(),t&&t.length>0){let e=m(`app`);e.items=t,e.status=`ready`,e.fetchedAt=0;for(let n of t)Gl(n)&&e.byName.set(n.name,n);f(),b(!1)}return(async()=>{for(let t of Ol)try{await h(t),e||S(null)}catch(t){e||S(t instanceof Error?t:Error(String(t)))}e||b(!1)})(),()=>{e=!0}},[t,h,m,f,s]);let D=(0,Q.useMemo)(()=>{let e=e=>{let t=m(e);return t.status===`idle`&&h(e),t.items};return{apps:m(`app`).items,get objects(){let t=e(Al.objects),n=e(`view`);return Yl(n.length?Jl(t,n):t)},get dashboards(){return e(Al.dashboards)},get reports(){return e(Al.reports)},get pages(){return e(Al.pages)},loading:y,error:x??m(`app`).error,refresh:_,invalidate:v,ensureType:h,getItem:g,getItemsByType:t=>e(t),getTypeStatus:e=>m(e).status}},[u,y,x,h,g,m,_,v]);return(0,$.jsx)(xe.Provider,{value:D,children:e})}function tu({objectName:e,objectLabel:t,dataSource:n,onEdit:r,onRefresh:i,onConfirm:a,onToast:o}){let s=p(),{appName:l}=c(),{t:u}=G(),d=`/apps/${l}`,{execute:f,loading:m,error:h,runner:g}=Pe({context:{objectName:e,objectLabel:t||e,baseUrl:d},onConfirm:a,onToast:o});return(0,Q.useEffect)(()=>{g.registerHandler(`create`,async()=>(r?.(null),{success:!0})),g.registerHandler(`delete`,async r=>{let a=Array.isArray(r.params?.records)?r.params.records.filter(e=>e?.id!=null):null;if(a&&a.length>1){let r=await Promise.allSettled(a.map(t=>n.delete(e,t.id))),o=r.filter(e=>e.status===`rejected`).length,s=r.length-o;return i?.(),o===0?(X.success(u(`objectActions.bulkDeleteSuccess`,{count:s,label:t||e,defaultValue:`Deleted ${s} ${t||e} records`})),{success:!0,reload:!0,silent:!0}):(X.error(u(`objectActions.bulkDeletePartial`,{succeeded:s,failed:o,defaultValue:`${s} deleted, ${o} failed`})),{success:!1})}let o=r.params?.recordId??r.params?.record?.id??a?.[0]?.id??r.recordId;if(!o)return{success:!1,error:u(`objectActions.noRecordId`)};let s=!1;if(e===`sys_permission_set`)try{s=(r.params?.record?.managed_by===void 0?await n.findOne(e,o):r.params.record)?.managed_by===`package`}catch{}try{return await n.delete(e,o),i?.(),X.success(s?u(`objectActions.resetPackageSetSuccess`,{defaultValue:`Permission set reset to its shipped baseline`}):u(`objectActions.deleteSuccess`,{label:t||e})),{success:!0,reload:!0,silent:!0}}catch(n){return X.error(u(`objectActions.deleteFailed`,{label:t||e}),{description:n.message}),{success:!1}}}),g.registerHandler(`navigate`,async e=>{let t=e.params?.url||e.url;return t&&s(t.startsWith(`/`)?t:`${d}/${t}`),{success:!0}}),g.registerHandler(`refresh`,async()=>(i?.(),{success:!0,reload:!0}))},[g,e,n,r,i,s,d,u,t]),{execute:f,create:(0,Q.useCallback)(()=>{r?.(null)},[r]),deleteRecord:(0,Q.useCallback)(async(t,n)=>{let r=e===`sys_permission_set`&&n?.managed_by===`package`;return f({type:`delete`,confirmText:r?u(`objectActions.resetPackageSetConfirm`,{defaultValue:`This permission set ships with an installed package and cannot be removed. Deleting resets it to the shipped baseline and discards your environment customization. Continue?`}):u(`objectActions.deleteConfirm`),params:n?{recordId:t,record:n}:{recordId:t}})},[f,u,e]),navigateToView:(0,Q.useCallback)(t=>{s(`${d}/${e}/view/${t}`)},[s,d,e]),navigateToRecord:(0,Q.useCallback)(t=>{s(`${d}/${e}/record/${encodeURIComponent(t)}`)},[s,d,e]),loading:m,error:h}}function nu(e){return e==null?[]:Array.isArray(e)?e:[e]}function ru(e,t){let{alias:n,value:r=`1`,replace:i=!0}=t??{},[a,o]=s(),c=(0,Q.useMemo)(()=>nu(n),[n]),l=(0,Q.useCallback)(t=>t.get(e)===r||c.some(e=>t.get(e)===r),[e,r,c]),u=l(a),d=(0,Q.useCallback)(t=>{if(t===l(a))return;let n=new URLSearchParams(a);if(t){n.set(e,r);for(let e of c)n.delete(e)}else{n.delete(e);for(let e of c)n.delete(e)}o(n,{replace:i})},[l,a,o,e,r,c,i]);return{open:u,setOpen:d,openOverlay:(0,Q.useCallback)(()=>d(!0),[d]),closeOverlay:(0,Q.useCallback)(()=>d(!1),[d]),toggleOverlay:(0,Q.useCallback)(()=>{o(t=>{let n=new URLSearchParams(t);if(l(n)){n.delete(e);for(let e of c)n.delete(e)}else{n.set(e,r);for(let e of c)n.delete(e)}return n},{replace:i})},[o,l,e,r,c,i])}}var iu={info:(e,t)=>X.info(e,t),success:(e,t)=>X.success(e,t),warning:(e,t)=>X.warning(e,t),error:(e,t)=>X.error(e,t)};function au(e,t){let n=iu[e.severity]??iu.info,r=e.actions?.[0],i=on(e.icon)?(0,$.jsx)(Xr,{name:e.icon,className:`h-4 w-4`}):void 0,a=le(e,t),o=a?di[a]:void 0;n(e.title,{description:e.message,duration:e.duration===0?1/0:e.duration,dismissible:e.dismissible,...i?{icon:i}:{},...o?{position:o}:{},...r?{action:{label:r.label,onClick:r.onClick}}:{}})}var ou=(0,Q.createContext)({theme:`system`,setTheme:()=>null});function su({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`,...r}){let[i,a]=(0,Q.useState)(()=>localStorage.getItem(n)||t);(0,Q.useEffect)(()=>{let e=window.document.documentElement;if(e.classList.remove(`light`,`dark`),i===`auto`||i===`system`){let t=window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`;e.classList.add(t);return}e.classList.add(i)},[i]);let o={theme:i,setTheme:e=>{localStorage.setItem(n,e),a(e)}};return(0,$.jsx)(ou.Provider,{...r,value:o,children:e})}var cu=()=>{let e=(0,Q.useContext)(ou);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function lu(){let e=((typeof document<`u`?document.documentElement.lang:``)||(typeof navigator<`u`?navigator.language:``)||`en`).toLowerCase().split(`-`)[0],t=Ze[e]?.console;return!t||t===Ye.console?Ye.console:{...Ye.console,...t,loadingSteps:{...Ye.console.loadingSteps,...t.loadingSteps},error:{...Ye.console.error,...t.error},actions:{...Ye.console.actions,...t.actions}}}function uu({message:e,error:t,onRetry:n,retrying:r}){let[i,a]=(0,Q.useState)(0),o=lu(),s=(0,Q.useMemo)(()=>[o.loadingSteps.connecting,o.loadingSteps.loadingConfig,o.loadingSteps.preparingWorkspace],[o]);return(0,Q.useEffect)(()=>{if(e||t)return;let n=setInterval(()=>{a(e=>Math.min(e+1,s.length-1))},1200);return()=>clearInterval(n)},[e,t,s.length]),(0,$.jsx)(`div`,{className:`flex flex-col items-center justify-center h-screen bg-background`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6`,children:[(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 bg-primary/20 rounded-2xl blur-xl animate-pulse`}),(0,$.jsx)(`div`,{className:`relative bg-linear-to-br from-primary to-primary/80 p-4 rounded-2xl shadow-lg`,children:is()?(0,$.jsx)(`img`,{src:is(),alt:us(),className:`h-10 w-10 object-contain`}):(0,$.jsx)(tn,{className:`h-10 w-10 text-primary-foreground`})})]}),(0,$.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,$.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:us()}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:o.initializing})]}),t?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-4 max-w-md w-full px-6`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 p-5 rounded-lg border border-destructive/30 bg-destructive/5 w-full`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-destructive`,children:[(0,$.jsx)(Ei,{className:`h-5 w-5 shrink-0`}),(0,$.jsx)(`span`,{className:`text-sm font-semibold`,children:o.error.connectionFailed})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground text-center break-words`,children:t}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground text-center`,children:o.error.checkServer})]}),n&&(0,$.jsx)(J,{onClick:n,disabled:r,variant:`default`,size:`sm`,className:`gap-2`,children:r?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Y,{className:`h-4 w-4 animate-spin`}),o.actions.retrying]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(zi,{className:`h-4 w-4`}),o.actions.retry]})})]}):e?(0,$.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 bg-muted/50 rounded-full`,children:[(0,$.jsx)(Ri,{className:`h-4 w-4 text-primary`}),(0,$.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:e})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 w-64`,children:[s.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5 text-sm transition-opacity duration-300`,style:{opacity:t<=i?1:.3},children:[t<i?(0,$.jsx)(Gr,{className:`h-4 w-4 text-primary shrink-0`}):t===i?(0,$.jsx)(Y,{className:`h-4 w-4 text-primary shrink-0 animate-spin`}):(0,$.jsx)(`div`,{className:`h-4 w-4 rounded-full border border-muted-foreground/30 shrink-0`}),(0,$.jsx)(`span`,{className:t<=i?`text-foreground`:`text-muted-foreground`,children:e})]},e)),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:o.loadingHint})]})]})})}function du({to:e,replace:t}){return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(uu,{}),(0,$.jsx)(h,{to:e,replace:t})]})}var fu=ka();function pu(){let{remediationRequired:e}=C();return e?(0,$.jsx)(`div`,{className:`fixed inset-0 z-[200] flex items-center justify-center bg-background/95 p-4 backdrop-blur-sm`,children:(0,$.jsx)(`div`,{className:`w-full max-w-md rounded-xl border bg-card p-6 shadow-xl`,children:e.code===`PASSWORD_EXPIRED`?(0,$.jsx)(hu,{message:e.message}):(0,$.jsx)(_u,{message:e.message})})}):null}function mu(){let{signOut:e}=C(),{t}=G();return(0,$.jsx)(`button`,{type:`button`,onClick:()=>{e()},className:`mt-4 w-full text-center text-xs text-muted-foreground hover:text-foreground hover:underline`,children:t(`auth.remediation.signOut`)})}function hu({message:e}){let{changePassword:t,setRemediationRequired:n}=C(),{t:r}=G(),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(null);return(0,$.jsxs)(`form`,{onSubmit:async e=>{if(e.preventDefault(),p(null),o!==c){p(r(`auth.remediation.password.mismatch`));return}d(!0);try{await t(i,o),n(null),window.location.reload()}catch(e){p(e instanceof Error?e.message:r(`auth.remediation.password.failed`)),d(!1)}},className:`space-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:r(`auth.remediation.password.title`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||r(`auth.remediation.password.fallbackMessage`)})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(K,{htmlFor:`rem-cur`,children:r(`auth.remediation.password.current`)}),(0,$.jsx)(q,{id:`rem-cur`,type:`password`,autoComplete:`current-password`,value:i,onChange:e=>a(e.target.value),required:!0})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(K,{htmlFor:`rem-new`,children:r(`auth.remediation.password.next`)}),(0,$.jsx)(q,{id:`rem-new`,type:`password`,autoComplete:`new-password`,value:o,onChange:e=>s(e.target.value),required:!0})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(K,{htmlFor:`rem-conf`,children:r(`auth.remediation.password.confirm`)}),(0,$.jsx)(q,{id:`rem-conf`,type:`password`,autoComplete:`new-password`,value:c,onChange:e=>l(e.target.value),required:!0})]}),f?(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:f}):null,(0,$.jsx)(J,{type:`submit`,className:`w-full`,disabled:u,children:r(u?`auth.remediation.password.submitting`:`auth.remediation.password.submit`)}),(0,$.jsx)(mu,{})]})}function gu({uri:e}){let[t,n]=(0,Q.useState)(null);return(0,$.jsx)(`div`,{className:`flex justify-center rounded-md border bg-white p-3`,children:t?(0,$.jsx)(`span`,{className:`text-sm text-destructive`,children:t}):(0,$.jsx)(`canvas`,{ref:t=>{!t||!e||(0,fu.toCanvas)(t,e,{width:184,margin:1},e=>{e&&n(e.message)})}})})}function _u({message:e}){let{enrollTotp:t,verifyTotp:n,setRemediationRequired:r}=C(),{t:i}=G(),[a,o]=(0,Q.useState)(`password`),[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)([]),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(null);return a===`password`?(0,$.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),g(!0);try{let{totpURI:e,backupCodes:n}=await t(s);f(e),m(n??[]),o(`verify`)}catch(e){v(e instanceof Error?e.message:i(`auth.remediation.mfa.enrollFailed`))}finally{g(!1)}},className:`space-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:i(`auth.remediation.mfa.title`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:e||i(`auth.remediation.mfa.fallbackMessage`)})]}),(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(K,{htmlFor:`rem-pw`,children:i(`auth.remediation.mfa.confirmPassword`)}),(0,$.jsx)(q,{id:`rem-pw`,type:`password`,autoComplete:`current-password`,value:s,onChange:e=>c(e.target.value),required:!0})]}),_?(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:_}):null,(0,$.jsx)(J,{type:`submit`,className:`w-full`,disabled:h,children:i(h?`auth.remediation.mfa.preparing`:`auth.remediation.mfa.continue`)}),(0,$.jsx)(mu,{})]}):(0,$.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),v(null),g(!0);try{await n(l.trim()),r(null),window.location.reload()}catch(e){v(e instanceof Error?e.message:i(`auth.remediation.mfa.invalidCode`)),g(!1)}},className:`space-y-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:i(`auth.remediation.mfa.scanTitle`)}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:i(`auth.remediation.mfa.scanBody`)})]}),d?(0,$.jsx)(gu,{uri:d}):null,p.length>0?(0,$.jsxs)(`details`,{className:`rounded-md border bg-muted/40 p-3 text-xs`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer font-medium`,children:i(`auth.remediation.mfa.backupTitle`)}),(0,$.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:i(`auth.remediation.mfa.backupBody`)}),(0,$.jsx)(`div`,{className:`mt-2 grid grid-cols-2 gap-1 font-mono`,children:p.map(e=>(0,$.jsx)(`span`,{children:e},e))})]}):null,(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(K,{htmlFor:`rem-code`,children:i(`auth.remediation.mfa.codeLabel`)}),(0,$.jsx)(q,{id:`rem-code`,inputMode:`numeric`,autoComplete:`one-time-code`,maxLength:8,placeholder:`123456`,value:l,onChange:e=>u(e.target.value),required:!0})]}),_?(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:_}):null,(0,$.jsx)(J,{type:`submit`,className:`w-full`,disabled:h,children:i(h?`auth.remediation.mfa.verifying`:`auth.remediation.mfa.verify`)}),(0,$.jsx)(mu,{})]})}function vu({children:e}){return a()?(0,$.jsx)(yu,{children:e}):(0,$.jsx)($.Fragment,{children:e})}function yu({children:e}){let t=p(),n=(0,Q.useMemo)(()=>({navigate:(e,n)=>t(e,{replace:n?.replace??!1})}),[t]);return(0,$.jsx)(Se,{value:n,children:e})}function bu(){let{user:e,session:t,refreshSession:n}=C(),{t:r}=G(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(!1),u=(0,Q.useMemo)(()=>b(),[]),d=t?.impersonatedBy,f=(0,Q.useCallback)(async()=>{a(!0),s(null);try{let e=await u(`/api/v1/auth/admin/stop-impersonating`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:`{}`});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message??t?.message??`HTTP ${e.status}`)}await n()}catch(e){let t=e instanceof Error?e.message:String(e);s(t),X.error(r(`impersonation.banner.stopFailed`,{defaultValue:`Could not stop impersonating: {{reason}}`,reason:t}))}finally{l(!0),a(!1)}},[u,n,r]);if(!d)return null;let p=e?.name||e?.email||e?.id||``,m=c&&!i&&!o;return(0,$.jsxs)(`div`,{role:`status`,"data-testid":`impersonation-banner`,className:`sticky top-0 z-50 flex flex-wrap items-center gap-x-3 gap-y-1 border-b border-red-300/70 bg-red-50 px-4 py-2 text-sm text-red-900 dark:border-red-800/60 dark:bg-red-950/50 dark:text-red-100`,children:[(0,$.jsx)(_i,{className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),(0,$.jsxs)(`p`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:r(`impersonation.banner.message`,{defaultValue:`You are impersonating {{user}} — every action is recorded as them.`,user:p})}),` `,(0,$.jsx)(`span`,{className:`opacity-80`,children:r(`impersonation.banner.startedBy`,{defaultValue:`Started by administrator {{admin}}.`,admin:d})})]}),(0,$.jsx)(J,{size:`sm`,variant:`outline`,onClick:f,disabled:i,"data-testid":`impersonation-stop`,children:i?r(`impersonation.banner.stopping`,{defaultValue:`Stopping…`}):r(`impersonation.banner.stop`,{defaultValue:`Stop impersonating`})}),o?(0,$.jsx)(`p`,{role:`alert`,"data-testid":`impersonation-stop-error`,className:`w-full font-medium`,children:r(`impersonation.banner.stopFailed`,{defaultValue:`Could not stop impersonating: {{reason}}`,reason:o})}):null,m?(0,$.jsx)(`p`,{role:`alert`,"data-testid":`impersonation-not-restored`,className:`w-full font-medium`,children:r(`impersonation.banner.notRestored`,{defaultValue:`The server accepted the request but did not restore your administrator session — you are still impersonating {{user}}. Sign out and sign in again to end it.`,user:p})}):null]})}bu.displayName=`ImpersonationBanner`;function xu(){return(0,$.jsx)(uu,{})}function Su({dataSource:e,children:t}){let{modalHandler:n,modalElement:r}=La(e),i=Ua({dataSource:e});return(0,$.jsxs)(je,{context:i.actionProviderProps.context,onConfirm:i.actionProviderProps.onConfirm,onToast:i.actionProviderProps.onToast,onNavigate:i.actionProviderProps.onNavigate,onParamCollection:i.actionProviderProps.onParamCollection,onResultDialog:i.actionProviderProps.onResultDialog,onModal:n,handlers:{api:i.apiHandler,flow:i.flowHandler,script:i.serverActionHandler},children:[t,i.dialogs,r]})}function Cu({children:e}){return(0,$.jsx)(vu,{children:(0,$.jsx)(wu,{children:e})})}function wu({children:e}){return(0,$.jsx)(su,{defaultTheme:`system`,storageKey:`object-ui-theme`,children:(0,$.jsx)(we,{config:{defaultDuration:4e3,maxVisible:4},onToast:au,children:(0,$.jsx)(Ha,{children:(0,$.jsx)(Da,{children:(0,$.jsx)(Ga,{children:(0,$.jsx)(Aa,{children:(0,$.jsxs)(ts,{children:[(0,$.jsx)(bu,{}),(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(xu,{}),children:e}),(0,$.jsx)(pu,{}),(0,$.jsx)(gn,{}),(0,$.jsx)(nr,{})]})})})})})})})}function Tu({children:e}){return(0,$.jsx)(El,{children:(0,$.jsx)(na,{children:(0,$.jsx)(Du,{children:e})})})}var Eu=yl(b({sameOriginOnly:!0}));function Du({children:e}){let t=Ue(),{language:n}=G(),{isLoading:r}=C(),i=(0,Q.useRef)(null);return t&&i.current!==null&&i.current!==n&&t.clearCache?.(),t&&(i.current=n),!t||r?(0,$.jsx)(xu,{}):(0,$.jsx)(H,{dataSource:t,apiFetch:Eu,children:(0,$.jsxs)(eu,{adapter:t,children:[(0,$.jsx)(Ou,{}),(0,$.jsx)(Su,{dataSource:t,children:e})]},n)})}function Ou(){let{user:e}=C(),t=Ue(),n=Oa();return(0,Q.useEffect)(()=>{if(!e?.id||!t){n(`favorites`,null),n(`recent`,null),n(`flowPaletteRecents`,null);return}let r=R({dataSource:t,userId:e.id,key:`ui.favorites`}),i=R({dataSource:t,userId:e.id,key:`ui.recent`}),a=R({dataSource:t,userId:e.id,key:`ui.flow.palette.recents`});return n(`favorites`,r),n(`recent`,i),n(`flowPaletteRecents`,a),()=>{n(`favorites`,null),n(`recent`,null),n(`flowPaletteRecents`,null)}},[e?.id,t,n]),null}function ku({children:e}){let{activeOrganization:t,organizations:n,isOrganizationsLoading:r,getAuthConfig:i}=C(),[a,o]=(0,Q.useState)(null);if((0,Q.useEffect)(()=>{let e=!1;return i().then(t=>{e||o(t?.features?.multiOrgEnabled!==!1)}).catch(()=>{e||o(!1)}),()=>{e=!0}},[i]),r)return(0,$.jsx)(xu,{});let s=n??[];if((s.length>0||t)&&!t)return(0,$.jsx)(du,{to:`/organizations`,replace:!0});if(s.length===0&&!t){if(a===null)return(0,$.jsx)(xu,{});if(a)return(0,$.jsx)(du,{to:`/organizations`,replace:!0})}return(0,$.jsx)($.Fragment,{children:e})}function Au({children:e,redirectTo:t=`/home`}){let{enabled:n,isLoading:r}=zo();return r?(0,$.jsx)(xu,{}):n?(0,$.jsx)($.Fragment,{children:e}):(0,$.jsx)(du,{to:t,replace:!0})}function ju(){let e=o(),t=e.pathname.replace(/^\/system/,``),n=t?`/apps/setup/system${t}`:`/apps/setup/system`;return(0,$.jsx)(h,{to:`${n}${e.search}${e.hash}`,replace:!0})}function Mu(e){let t=e??[],n=t.find(e=>e?._packageId===`com.objectstack.setup`)??t.find(e=>e?.name===`setup`);return`/apps/${fo(n)??`com.objectstack.setup`}`}function Nu(){let{apps:e,loading:t}=be(),n=o();if(t)return(0,$.jsx)(xu,{});let r=Mu(e);return(0,$.jsx)(du,{to:`${r}${n.search}${n.hash}`,replace:!0})}function Pu(e){let t=(e??[]).find(e=>e?.isDefault===!0&&!!e?.name);return t?`/apps/${t.name}`:null}function Fu({appLabel:e,onOpenDock:t}){let{t:n}=G(),{openSeq:r}=_a(),i=(0,Q.useRef)(r);return(0,Q.useEffect)(()=>{r!==i.current&&(i.current=r,t())},[r,t]),(0,$.jsx)(`button`,{type:`button`,"aria-label":n(`topbar.openAssistant`,{defaultValue:`Open {{name}} assistant`,name:e}),onClick:t,className:`fixed bottom-20 right-6 z-50 flex h-14 w-14 items-center justify-center rounded-full bg-primary text-primary-foreground shadow-lg ring-1 ring-primary/20 transition-transform hover:scale-105 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 sm:bottom-6`,"data-testid":`console-chatbot-fab`,children:(0,$.jsxs)(`svg`,{width:`22`,height:`22`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,$.jsx)(`path`,{d:`M12 3v3`}),(0,$.jsx)(`path`,{d:`M12 18v3`}),(0,$.jsx)(`path`,{d:`M5.6 5.6l2.1 2.1`}),(0,$.jsx)(`path`,{d:`M16.3 16.3l2.1 2.1`}),(0,$.jsx)(`path`,{d:`M3 12h3`}),(0,$.jsx)(`path`,{d:`M18 12h3`}),(0,$.jsx)(`path`,{d:`M5.6 18.4l2.1-2.1`}),(0,$.jsx)(`path`,{d:`M16.3 7.7l2.1-2.1`}),(0,$.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`})]})})}function Iu(e){let t=e?.issues;return Array.isArray(t)?t:[]}function Lu(e){return`• ${e.path&&e.path.length>0?e.path:`(root)`} — ${e.message}`}function Ru(e){let t=Iu(e);return t.length>0?t.map(Lu).join(`
|
|
4
|
+
`):e?.message??String(e)}var zu=`batch_aborted`;function Bu(e){let t=e=>[`${e.type}/${e.name}: ${e.error}`,...(Array.isArray(e.issues)?e.issues:[]).map(e=>` ${Lu(e)}`)].join(`
|
|
5
|
+
`),n=e.filter(e=>e.code===zu);if(n.length>0){let r=e.filter(e=>e.code!==zu);return[`Nothing was published — the batch rolled back (all-or-nothing).`,...r.length>0?r.map(t):n.slice(0,1).map(t),`(${n.length} other draft${n.length===1?``:`s`} aborted with it — fix the cause and publish again.)`].join(`
|
|
6
|
+
`)}return e.map(t).join(`
|
|
7
|
+
`)}function Vu(){let e=document.querySelector(`base`)?.getAttribute(`href`);return e?new URL(e,window.location.origin):new URL(`/`,window.location.origin)}function Hu(e){return e===void 0?Vu().toString():new URL(`.`,e).toString()}function Uu(e,t){return new URL(e.replace(/^\//,``),Hu(t)).toString()}function Wu(){if(!(typeof window>`u`||typeof document>`u`))return Uu(`s`)}var Gu=[`sys_`,`ai_`,`cloud_`],Ku=[`formula`,`summary`,`autonumber`];function qu(e){let t=e?.fields??e?.data?.fields??e?.item?.fields??{};return(Array.isArray(t)?t.map(e=>[e?.name,e]):Object.entries(t)).map(([e,t])=>({name:t?.name??e,label:t?.label??t?.name??e,type:t?.type??`text`,required:!!t?.required,options:t?.options})).filter(e=>e.name&&!Ku.includes(e.type))}function Ju({file:e,dataSource:t,defaultObjectName:n,onDone:r}){let{t:i}=G(),a=(0,Q.useMemo)(()=>b(),[]),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(n??``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=!1,t=``.replace(/\/+$/,``);return(async()=>{try{let r=await a(`${t}/api/v1/meta/object`,{method:`GET`,credentials:`include`});if(!r.ok)throw Error(String(r.status));let i=await r.json().catch(()=>null),o=i?.data?.items??i?.items??i?.data??(Array.isArray(i)?i:[]),u=(Array.isArray(o)?o:[]).map(e=>({name:e?.name,label:e?.label||e?.name})).filter(e=>e.name&&!Gu.some(t=>e.name.startsWith(t)));if(e)return;if(s(u),!c&&u.length){let e=n&&u.find(e=>e.name===n);l(e?n:u[0].name)}}catch{e||s([])}})(),()=>{e=!0}},[a,n]);async function g(){if(c){d(!0);try{let e=qu(await t.getObjectSchema(c));if(!e.length){X.error(i(`excelImport.noImportableFields`));return}p(e),h(!0)}catch{X.error(i(`excelImport.schemaReadFailed`))}finally{d(!1)}}}let _=o?.find(e=>e.name===c)?.label??c;return m&&f?(0,$.jsx)(Vs,{open:m,onOpenChange:e=>{h(e),e||r()},objectName:c,objectLabel:_,fields:f,dataSource:t,initialFile:e,onComplete:e=>{X.success(i(`excelImport.imported`,{count:e.importedRows,object:_}))}}):(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 rounded-md border border-border bg-muted/40 px-3 py-2 text-sm`,"data-excel-import-bar":!0,children:[(0,$.jsx)(hn,{variant:`secondary`,children:`CSV / Excel`}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i(`excelImport.importFrom`)}),(0,$.jsx)(`code`,{className:`font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:i(`excelImport.into`)}),(0,$.jsx)(`select`,{className:`h-8 rounded-md border border-input bg-background px-2 text-sm`,value:c,onChange:e=>l(e.target.value),disabled:!o||o.length===0,children:(o??[]).map(e=>(0,$.jsx)(`option`,{value:e.name,children:e.label},e.name))}),(0,$.jsx)(J,{size:`sm`,onClick:g,disabled:!c||u,children:i(u?`excelImport.opening`:`excelImport.importAction`)}),(0,$.jsx)(J,{size:`sm`,variant:`ghost`,onClick:r,children:i(`excelImport.dismiss`)})]})}async function Yu(e){let t=e?`?packageId=${encodeURIComponent(e)}`:``,n=await fetch(`/api/v1/meta/_drafts${t}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!n.ok)throw Error(`_drafts HTTP ${n.status}`);let r=await n.json(),i=Array.isArray(r)?r:r?.drafts??r?.data?.drafts??[];return(Array.isArray(i)?i:[]).filter(e=>typeof e?.type==`string`&&typeof e?.name==`string`).map(e=>({type:e.type,name:e.name,packageId:typeof e.packageId==`string`&&e.packageId?e.packageId:null}))}function Xu(e={}){let{packageId:t,enabled:n=!0}=e,[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(null),s=(0,Q.useRef)(0),c=(0,Q.useCallback)(async()=>{if(!n)return;let e=++s.current;try{let n=await Yu(t);if(s.current!==e)return;i(n),o(n.length)}catch{if(s.current!==e)return;i([]),o(null)}},[t,n]);return(0,Q.useEffect)(()=>{if(!n){s.current++,i([]),o(null);return}return c(),va(()=>{c()})},[c,n]),{count:a,entries:r,refresh:c}}function Zu({packageId:e,idle:t}){let{refresh:n}=be(),{t:r}=G(),[i,a]=(0,Q.useState)(!1),{count:o,refresh:s}=Xu({packageId:e,enabled:!!e});(0,Q.useEffect)(()=>{!e||!t||s()},[t,e,s]);let c=(0,Q.useCallback)(async()=>{if(!(!e||i)){a(!0);try{let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),i=await t.json().catch(()=>void 0);if(!t.ok){let e=i?.error?.message??r(`console.ai.pendingDrafts.failed`,{defaultValue:`Publish failed.`});X.error(e);return}let a=To(i),o=(a?.issues??[]).filter(e=>e.severity===`error`);a?.seedError||o.length>0?X.warning(r(`console.ai.pendingDrafts.publishedWithFindings`,{defaultValue:`Published, but the runtime probes reported problems: {{detail}}`,detail:[a?.seedError,...o.map(e=>e.message)].filter(Boolean).join(`; `)})):X.success(r(`console.ai.pendingDrafts.published`,{defaultValue:`All pending changes are live.`}));try{await n?.()}catch{}ba()}finally{a(!1)}}},[e,i,n,r]);return!e||(o??0)<=0?null:(0,$.jsxs)(`div`,{"data-testid":`pending-drafts-bar`,className:`pointer-events-auto flex w-full max-w-3xl items-center justify-between gap-3 rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-sm shadow-sm backdrop-blur`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:r(`console.ai.pendingDrafts.count`,{defaultValue:`{{count}} change(s) are not published yet — users cannot see them.`,count:o})}),(0,$.jsxs)(J,{size:`sm`,onClick:()=>void c(),disabled:i,className:`shrink-0`,children:[i?(0,$.jsx)(Y,{className:`mr-1 h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Hn,{className:`mr-1 h-3.5 w-3.5`}),r(`console.ai.pendingDrafts.publish`,{defaultValue:`Publish`})]})]})}function Qu(){let{theme:e,setTheme:t}=cu(),{t:n}=G();return(0,$.jsxs)(Bn,{children:[(0,$.jsx)($n,{asChild:!0,children:(0,$.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,$.jsx)(pn,{className:`h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0`}),(0,$.jsx)(Mi,{className:`absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100`}),(0,$.jsx)(`span`,{className:`sr-only`,children:n(`console.theme.toggle`)})]})}),(0,$.jsxs)(It,{align:`end`,children:[(0,$.jsxs)(qn,{onClick:()=>t(`light`),className:`gap-2`,children:[(0,$.jsx)(pn,{className:`h-4 w-4`}),n(`console.theme.light`),e===`light`&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,$.jsxs)(qn,{onClick:()=>t(`dark`),className:`gap-2`,children:[(0,$.jsx)(Mi,{className:`h-4 w-4`}),n(`console.theme.dark`),e===`dark`&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]}),(0,$.jsxs)(qn,{onClick:()=>t(`system`),className:`gap-2`,children:[(0,$.jsx)(ui,{className:`h-4 w-4`}),n(`console.theme.system`),e===`system`&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]})]})]})}function $u(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function ed({name:e}){return(0,$.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded bg-muted text-[10px] font-semibold text-muted-foreground`,children:$u(e)})}function td(){let{t:e}=G(),t=p(),{organizations:n,activeOrganization:r,switchOrganization:i,getAuthConfig:a}=C(),[o,s]=(0,Q.useState)(!1),c=Ws()===`group`;(0,Q.useEffect)(()=>{let e=!1;return a?.().then(t=>{e||s(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[a]);let l=n??[],u=r??l[0]??null;if(!u||l.length<=1)return null;let d=async e=>{if(e.id!==u.id)try{await i(e.id),window.location.href=Hu()}catch(e){console.error(`[WorkspaceSwitcher] switch failed`,e)}};return(0,$.jsxs)(Bn,{children:[(0,$.jsxs)($n,{className:`ml-2 inline-flex max-w-[14rem] items-center gap-1.5 rounded-md px-1.5 py-1 text-sm font-medium text-foreground/80 transition-colors hover:bg-accent hover:text-foreground`,"data-testid":`workspace-switcher`,children:[(0,$.jsx)(ed,{name:u.name}),(0,$.jsx)(`span`,{className:`hidden truncate sm:inline`,children:u.name}),(0,$.jsx)(_r,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]}),(0,$.jsxs)(It,{align:`start`,className:`w-60`,children:[(0,$.jsx)(Mt,{className:`text-xs text-muted-foreground`,children:c?e(`organization.switcher.groupLabel`,{defaultValue:`Working organization`}):e(`organization.switcher.label`,{defaultValue:`Switch organization`})}),c&&(0,$.jsx)(`p`,{className:`px-2 pb-1.5 text-xs font-normal leading-snug text-muted-foreground`,"data-testid":`workspace-switcher-group-hint`,children:e(`organization.switcher.groupHint`,{defaultValue:`New records are created here. Views show data from all your organizations.`})}),l.map(e=>(0,$.jsxs)(qn,{onClick:()=>d(e),className:`cursor-pointer gap-2`,children:[(0,$.jsx)(ed,{name:e.name}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.name}),e.id===u.id&&(0,$.jsx)(Pr,{className:`h-4 w-4 shrink-0`})]},e.id)),(0,$.jsx)(Yt,{}),(0,$.jsxs)(qn,{onClick:()=>t(`/organizations/${u.slug}/members`),className:`cursor-pointer gap-2`,"data-testid":`workspace-manage-members`,children:[(0,$.jsx)(Fi,{className:`h-4 w-4`}),e(`organization.switcher.manageMembers`,{defaultValue:`Manage members`})]}),!o&&(0,$.jsxs)(qn,{onClick:()=>t(`/organizations?create=1`),className:`cursor-pointer gap-2`,"data-testid":`workspace-create`,children:[(0,$.jsx)(Ct,{className:`h-4 w-4`}),e(`organizations.create`,{defaultValue:`Create workspace`})]})]})]})}function nd(){let{t:e}=G(),{organizations:t,activeOrganization:n}=C(),r=Ws();if(!Us(r))return null;let i=t??[];if(i.length!==1)return null;let a=n??i[0]??null;if(!a)return null;let o=e(`organization.current.label`,{defaultValue:`Current organization`});return(0,$.jsxs)(`span`,{"data-testid":`current-organization-indicator`,className:`ml-2 inline-flex max-w-[14rem] items-center gap-1.5 rounded-md px-1.5 py-1 text-sm font-medium text-foreground/80`,title:`${o}: ${a.name}`,children:[(0,$.jsx)(ed,{name:a.name}),(0,$.jsx)(`span`,{className:`sr-only`,children:o}),(0,$.jsx)(`span`,{className:`hidden truncate sm:inline`,children:a.name})]})}var rd=new Map([[`en`,`English`],[`zh`,`中文`],[`ja`,`日本語`],[`ko`,`한국어`],[`de`,`Deutsch`],[`fr`,`Français`],[`es`,`Español`],[`pt`,`Português`],[`ru`,`Русский`],[`ar`,`العربية`]]);function id(e){let t=rd.get(e);if(t)return t;try{let t=new Intl.DisplayNames([e],{type:`language`}).of(e);return!t||t===e?e:t.charAt(0).toLocaleUpperCase(e)+t.slice(1)}catch{return e}}function ad(){let{t:e,language:t,changeLanguage:n,offerableLanguages:r}=G();return r===null?null:(0,$.jsxs)(Bn,{children:[(0,$.jsx)($n,{asChild:!0,children:(0,$.jsxs)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,children:[(0,$.jsx)(Kt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`sr-only`,children:e(`console.localeSwitcher.label`)})]})}),(0,$.jsx)(It,{align:`end`,className:`max-h-72 overflow-y-auto`,children:r.map(e=>(0,$.jsxs)(qn,{onClick:()=>n(e),className:`gap-2`,children:[id(e),t===e&&(0,$.jsx)(`span`,{className:`ml-auto text-xs`,children:`✓`})]},e))})]})}var od={connected:{labelKey:`topbar.connection.connected`,defaultValue:`Connected`,color:`text-green-500`,icon:Gr},connecting:{labelKey:`topbar.connection.connecting`,defaultValue:`Connecting…`,color:`text-yellow-500`,icon:Y},reconnecting:{labelKey:`topbar.connection.reconnecting`,defaultValue:`Reconnecting…`,color:`text-yellow-500`,icon:Y},disconnected:{labelKey:`topbar.connection.disconnected`,defaultValue:`Disconnected`,color:`text-muted-foreground`,icon:fr},error:{labelKey:`topbar.connection.error`,defaultValue:`Connection Error`,color:`text-destructive`,icon:fr}};function sd({state:e,className:t}){let n=od[e],{t:r}=G(),i=r(n.labelKey,{defaultValue:n.defaultValue}),a=n.icon,[o,s]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{if(e===`connected`){s(!0);let e=setTimeout(()=>s(!1),2e3);return()=>clearTimeout(e)}s(!1)},[e]),e===`connected`&&!o?null:(0,$.jsxs)(`div`,{className:qr(`flex items-center gap-1.5 text-xs font-medium px-2 py-1 rounded-md transition-opacity duration-300`,n.color,e===`connected`&&`bg-green-500/10`,e===`error`&&`bg-destructive/10`,e===`reconnecting`&&`bg-yellow-500/10`,t),title:i,children:[(0,$.jsx)(a,{className:qr(`h-3.5 w-3.5`,(e===`connecting`||e===`reconnecting`)&&`animate-spin`)}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:i})]})}function cd({activeAppName:e,onAppChange:t}){let{apps:n}=be(),{t:r}=G(),{appLabel:i}=at(),a=n||[],o=a.filter(e=>e.active!==!1&&e.hidden!==!0),s=so(o,e)||so(a.filter(e=>e.active!==!1),e)||o[0];if(!s)return null;let c=i({name:s.name,label:ys(s.label,r)});return(0,$.jsxs)(Bn,{children:[(0,$.jsx)($n,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1 rounded-md px-1.5 py-1 text-sm font-medium text-foreground/80 hover:bg-accent hover:text-foreground transition-colors outline-none focus-visible:ring-2 focus-visible:ring-ring max-w-[40vw] sm:max-w-none`,children:[(0,$.jsx)(`span`,{className:`truncate whitespace-nowrap`,children:c}),(0,$.jsx)(zr,{className:`h-3.5 w-3.5 text-muted-foreground shrink-0`})]})}),(0,$.jsxs)(It,{align:`start`,sideOffset:8,className:`w-60`,children:[(0,$.jsx)(Mt,{className:`text-xs text-muted-foreground font-normal`,children:r(`layout.appSwitcher.switchApplication`,{defaultValue:`Switch Application`})}),(0,$.jsx)(Yt,{}),o.map(e=>{let n=qs(e.icon),a=i({name:e.name,label:ys(e.label,r)}),o=s.name===e.name;return(0,$.jsxs)(qn,{onClick:()=>t(fo(e)??e.name),className:`flex items-center gap-2.5 py-2`,children:[(0,$.jsx)(`div`,{className:`flex size-5 shrink-0 items-center justify-center rounded border bg-muted text-muted-foreground`,children:(0,$.jsx)(n,{className:`size-3`})}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:a}),o&&(0,$.jsx)(Pr,{className:`size-3.5 text-primary shrink-0`})]},e.name)})]})]})}var ld=(0,Q.createContext)(null);function ud({children:e}){let[t,n]=(0,Q.useState)(null),r=(0,Q.useMemo)(()=>({value:t,setValue:n}),[t]);return(0,$.jsx)(ld.Provider,{value:r,children:e})}function dd(){return(0,Q.useContext)(ld)?.value??null}function fd(e){let t=(0,Q.useContext)(ld),n=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!t)return;let r=e??null;return t.setValue(r),n.current=r,()=>{t.setValue(null)}},[t,e])}function pd(e){let{views:t,activeViewId:n,onChange:r,triggerLabel:i,enabled:a=!0}=e,o=(0,Q.useRef)(r);o.current=r;let s=(0,Q.useCallback)(e=>o.current(e),[]);fd((0,Q.useMemo)(()=>a?{views:t,activeViewId:n,onChange:s,triggerLabel:i}:null,[a,t,n,s,i]))}var md=(0,Q.createContext)(null);function hd({children:e}){let{open:t,setOpen:n,openOverlay:r,closeOverlay:i,toggleOverlay:a}=ru($a,{alias:`cmdk`});(0,Q.useEffect)(()=>{let e=e=>{e.key===`k`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),a())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[a]);let o=(0,Q.useMemo)(()=>({open:t,openCommandPalette:r,closeCommandPalette:i,toggleCommandPalette:a,setOpen:n}),[t,r,i,a,n]);return(0,$.jsx)(md.Provider,{value:o,children:e})}function gd(){return(0,Q.useContext)(md)||{open:!1,openCommandPalette:()=>{},closeCommandPalette:()=>{},toggleCommandPalette:()=>{},setOpen:()=>{}}}function _d(){let{apps:e}=be();return Pu(e)??`/home`}var vd=Q.forwardRef(({className:e,onClick:t,"aria-label":n,title:r,...i},a)=>{let{toggleSidebar:o}=xr(),{t:s}=G(),c=String(n||r||s(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`}));return(0,$.jsxs)(J,{ref:a,"data-sidebar":`trigger`,variant:`ghost`,size:`icon`,className:qr(`h-7 w-7`,e),"aria-label":c,title:c,onClick:e=>{t?.(e),o()},...i,children:[(0,$.jsx)(Pt,{}),(0,$.jsx)(`span`,{className:`sr-only`,children:c})]})});vd.displayName=`LocalizedSidebarTrigger`;function yd({className:e}){let{t}=G(),n=gs();if(n!==`preview`&&n!==`beta`)return null;let r=n===`beta`?t(`topbar.stage.beta`,{defaultValue:`Beta`}):t(`topbar.stage.preview`,{defaultValue:`Preview`}),i=t(`topbar.stage.tooltip`,{defaultValue:`This platform is in preview — features may change.`});return(0,$.jsx)(hn,{variant:`secondary`,title:i,"aria-label":i,"data-testid":`platform-preview-badge`,className:qr(`shrink-0 cursor-default select-none rounded-md px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide`,e),children:r})}function bd(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function xd(){return(0,$.jsx)(`span`,{className:`select-none text-muted-foreground/40 mx-1.5 text-base font-light`,"aria-hidden":!0,children:`/`})}var Sd=[];function Cd({variant:e,appName:t,objects:r,connectionState:i,presenceUsers:a,activities:s,activeAppName:l,onAppChange:u}){let d=e??(t?`app`:`home`),f=d===`app`,m=o(),h=c(),g=p(),_=_d(),{isOnline:v}=de(),{openCommandPalette:y}=gd(),{openOverlay:b}=ru(to),{user:x,signOut:S,isAuthEnabled:T,organizations:D,activeOrganization:O,isOrganizationsLoading:k,getAuthConfig:A}=C(),j=Ue(),{enabled:M}=zo(),{isAdmin:ee}=w(),{t:N}=G(),{objectLabel:te,dashboardLabel:P,pageLabel:F,reportLabel:ne,viewLabel:re,appLabel:I}=at(),{apps:ie,dashboards:L,pages:ae,reports:oe}=be(),{currentAppName:R,recordTitle:se}=Ra(),z=dd(),[B,ce]=(0,Q.useState)(null),le=(0,Q.useCallback)(async()=>{if(B===null)try{let e=j?.getClient?.();if(!e?.meta?.getItems){ce([]);return}let t=await e.meta.getItems(`doc`),n=Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[];ce(n.map(e=>({name:e?.name,label:e?.label,_packageId:e?._packageId})).filter(e=>e.name))}catch{ce([])}},[B,j]),ue=Ho(),{notifications:fe,unreadCount:pe,pendingApprovalsCount:me,markAllRead:V,markRead:he,markManyRead:ge}=es(),_e=Xa(),ve=a??(_e.length>0?_e:Sd),ye=s??ue,xe=k||(D??[]).length>0||!!O,[Se,Ce]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=!1;return A?.().then(t=>{e||Ce(t?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{e=!0}},[A]);let H=m.pathname.split(`/`).filter(Boolean),we=h.appName||H[1],U=H[2],W=`/apps/${we}`,Te=r??[],Ee=so(ie||[],l||R||we),De=new Set,Oe=e=>{for(let t of e||[])t.type===`object`&&t.objectName&&De.add(t.objectName),t.children&&Oe(t.children)};Oe(Ee?.navigation||[]);for(let e of Ee?.areas||[])Oe(e.navigation||[]);let ke=De.size>0?Te.filter(e=>De.has(e.name)):Te.filter(e=>!e.name.startsWith(`sys_`)&&!e.name.startsWith(`auth_`)),Ae=Ee?._packageId,je=Ae?(B??[]).filter(e=>e._packageId===Ae):[],Me=f?co(Ee,ee,{type:U,name:H[3]}):null,Ne=ke.map(e=>({label:te(e),href:`${W}/${e.name}`})),Pe=[];if(f){if(U===`dashboard`){if(Pe.push({label:N(`console.breadcrumb.dashboards`),href:W}),H[3]){let e=H[3],t=vs(L,e,Ee?._packageId)?.label||bd(e);Pe.push({label:P({name:e,label:t})})}}else if(U===`page`){if(Pe.push({label:N(`console.breadcrumb.pages`),href:W}),H[3]){let e=H[3],t=vs(ae,e,Ee?._packageId)?.label||bd(e);Pe.push({label:F({name:e,label:t})})}}else if(U===`report`){if(Pe.push({label:N(`console.breadcrumb.reports`),href:W}),H[3]){let e=H[3],t=vs(oe,e,Ee?._packageId)?.label||bd(e);Pe.push({label:ne({name:e,label:t})})}}else if(U===`system`)Pe.push({label:N(`console.breadcrumb.system`)}),H[3]&&Pe.push({label:bd(H[3])});else if(U){let e=Te.find(e=>e.name===U);if(e){if(H[3]===`record`&&H[4]){let e=Qa(new URLSearchParams(m.search).get(Ja));e.forEach((t,n)=>{let r=Te.find(e=>e.name===t.o);Pe.push({label:r?te(r):bd(t.o),href:`${W}/${t.o}`});let i=t.i.length>12?`${t.i.slice(0,8)}…`:t.i;Pe.push({label:t.t||`#${i}`,href:eo(W,t,e.slice(0,n))})})}if(Pe.push({label:te(e),href:`${W}/${U}`,siblings:Ne}),H[3]===`record`&&H[4]){let e=H[4].length>12?`${H[4].slice(0,8)}…`:H[4],t=se?.trim(),n=t&&t.length>48?`${t.slice(0,45)}…`:t;Pe.push({label:n||`#${e}`})}else if(H[3]===`view`&&H[4]){let t=H[4],n=(e.listViews||e.list_views||{})[t],r=n&&(n.label||n.title)||bd(t),i=re(e.name,t,r);Pe.push({label:i})}}}}let Fe=Pe[Pe.length-1]?.label||t||``;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between w-full h-full`,children:[(0,$.jsxs)(`div`,{className:`flex items-center min-w-0 flex-1`,children:[(0,$.jsx)(n,{to:_,className:qr(`flex items-center justify-center h-7 w-7 shrink-0 rounded-md bg-primary text-primary-foreground hover:bg-primary/90 transition-colors overflow-hidden`,f&&`hidden sm:flex`),title:us(),children:is()?(0,$.jsx)(`img`,{src:is(),alt:us(),className:`h-full w-full object-contain`}):(0,$.jsx)($r,{className:`h-4 w-4`})}),d===`home`&&(0,$.jsx)(`span`,{className:`hidden sm:inline ml-2 text-sm font-semibold tracking-tight`,children:us()}),(0,$.jsx)(yd,{className:`ml-2 hidden sm:inline-flex`}),(0,$.jsx)(td,{}),(0,$.jsx)(nd,{}),d===`orgs`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(xd,{}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground/80 px-1.5`,children:N(`organizations.title`,{defaultValue:`Workspaces`})})]}),f&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(vd,{className:`lg:hidden shrink-0 ml-1`,"aria-label":N(`common.toggleSidebar`,{defaultValue:`Toggle sidebar`})}),l&&u?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,$.jsx)(xd,{})}),(0,$.jsx)(`div`,{className:`hidden sm:flex items-center`,children:(0,$.jsx)(cd,{activeAppName:l,onAppChange:u})})]}):t?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`hidden sm:flex items-center`,children:(0,$.jsx)(xd,{})}),(0,$.jsx)(`span`,{className:`hidden sm:inline text-sm font-medium text-foreground/80 px-1.5`,children:t})]}):null,Pe.map((e,t)=>{let r=t===Pe.length-1;return(0,$.jsxs)(`span`,{className:`hidden sm:flex items-center min-w-0`,children:[(0,$.jsx)(xd,{}),e.siblings&&e.siblings.length>1?(0,$.jsxs)(Bn,{children:[(0,$.jsxs)($n,{className:`flex items-center gap-1 rounded-md px-1.5 py-1 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring hover:bg-accent hover:text-foreground ${r?`text-foreground/80`:`text-foreground/60`}`,children:[e.label,(0,$.jsx)(zr,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),(0,$.jsxs)(It,{align:`start`,sideOffset:8,className:`w-56 max-h-72 overflow-y-auto`,children:[(0,$.jsx)(Mt,{className:`text-xs text-muted-foreground font-normal`,children:N(`topbar.switchObject`,{defaultValue:`Switch Object`})}),(0,$.jsx)(Yt,{}),e.siblings.map(e=>(0,$.jsx)(qn,{asChild:!0,children:(0,$.jsx)(n,{to:e.href,className:`w-full`,children:e.label})},e.href))]})]}):e.href?(0,$.jsx)(n,{to:e.href,className:`rounded-md px-1.5 py-1 text-sm font-medium transition-colors hover:bg-accent hover:text-foreground truncate max-w-[160px] ${r?`text-foreground/80`:`text-foreground/60`}`,children:e.label}):(0,$.jsx)(`span`,{className:`px-1.5 py-1 text-sm font-medium truncate max-w-[160px] ${r?`text-foreground/80`:`text-foreground/60`}`,children:e.label})]},t)}),z&&z.views.length>0?z.views.length>1?(0,$.jsxs)(Bn,{children:[(0,$.jsx)($n,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:`sm:hidden flex items-center gap-0.5 min-w-0 ml-1 rounded-md px-1.5 py-1 text-sm font-medium hover:bg-accent active:bg-accent/80 transition-colors`,"aria-label":N(`topbar.switchView`,{defaultValue:`Switch view`}),children:[(0,$.jsx)(`span`,{className:`truncate max-w-[180px]`,children:z.triggerLabel??z.views.find(e=>e.id===z.activeViewId)?.label??Fe}),(0,$.jsx)(zr,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`})]})}),(0,$.jsx)(It,{align:`start`,className:`min-w-[220px] max-w-[280px]`,children:z.views.map(e=>{let t=e.id===z.activeViewId;return(0,$.jsxs)(qn,{onSelect:()=>{t||z.onChange(e.id)},className:`gap-2`,children:[e.icon?(0,$.jsx)(`span`,{className:`shrink-0 text-muted-foreground [&>svg]:h-4 [&>svg]:w-4`,children:e.icon}):null,(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.locked?(0,$.jsx)(cr,{className:`h-3 w-3 shrink-0 text-muted-foreground`,"aria-hidden":!0}):null,t?(0,$.jsx)(Pr,{className:`h-4 w-4 shrink-0 text-foreground`,"aria-hidden":!0}):null]},e.id)})})]}):(0,$.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:z.triggerLabel??z.views[0].label}):(0,$.jsx)(`span`,{className:`text-sm font-medium sm:hidden truncate min-w-0 ml-1`,children:Fe})]})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-0.5 sm:gap-1 shrink-0 [&>*+*[data-topbar-group]]:ml-1 [&>[data-topbar-group]+[data-topbar-group]]:border-l [&>[data-topbar-group]+[data-topbar-group]]:border-border/60 [&>[data-topbar-group]+[data-topbar-group]]:pl-1 sm:[&>[data-topbar-group]+[data-topbar-group]]:pl-2 sm:[&>[data-topbar-group]+[data-topbar-group]]:ml-2`,children:[!v&&(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 py-1 rounded-full bg-yellow-100 dark:bg-yellow-900/30 text-yellow-800 dark:text-yellow-200 text-xs font-medium`,children:[(0,$.jsx)(`span`,{className:`h-2 w-2 rounded-full bg-yellow-500 animate-pulse`}),N(`topbar.offline`,{defaultValue:`Offline`})]}),f&&i&&(0,$.jsx)(sd,{state:i}),f&&ve.length>0&&(0,$.jsx)(`div`,{className:`hidden md:flex items-center shrink-0`,title:N(`topbar.usersOnline`,{defaultValue:`Users currently online`}),children:(0,$.jsx)(Ya,{users:ve,size:`sm`,maxVisible:3,showStatus:!0})}),(0,$.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 sm:gap-1 shrink-0`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-testid":`action:command-palette:open`,"aria-label":N(`console.search`,{defaultValue:`Search…`}),"aria-keyshortcuts":`Meta+K Control+K`,onClick:y,className:`hidden lg:flex relative items-center gap-2 w-48 xl:w-64 h-8 px-3 text-sm rounded-md border bg-muted/50 text-muted-foreground hover:bg-muted transition-colors`,children:[(0,$.jsx)(ur,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 text-left text-xs`,children:N(`console.search`,{defaultValue:`Search…`})}),(0,$.jsxs)(`kbd`,{className:`pointer-events-none inline-flex h-5 items-center gap-0.5 rounded border bg-background px-1.5 text-[10px] font-medium text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`text-xs`,children:`⌘`}),`K`]})]}),(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`lg:hidden h-8 w-8 shrink-0`,"data-testid":`action:command-palette:open-mobile`,onClick:y,"aria-label":N(`console.search`,{defaultValue:`Search…`}),children:(0,$.jsx)(ur,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[(0,$.jsx)(Wo,{notifications:fe,unreadCount:pe,pendingApprovalsCount:me,activities:ye,onMarkAllRead:V,onMarkRead:he,onMarkManyRead:ge}),Me&&(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"data-testid":`app-design-in-studio-button`,"aria-label":N(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),title:N(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),children:(0,$.jsx)(n,{to:Me,children:(0,$.jsx)(Jn,{className:`h-4 w-4`})})}),M&&(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,asChild:!0,"aria-label":N(`topbar.aiAssistant`,{defaultValue:`AI Assistant`}),children:(0,$.jsx)(n,{to:`/ai`,children:(0,$.jsx)(zt,{className:`h-4 w-4`})})}),(0,$.jsxs)(Bn,{onOpenChange:e=>{e&&le()},children:[(0,$.jsx)($n,{asChild:!0,children:(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 hidden md:flex shrink-0`,"aria-label":N(`sidebar.helpTooltip`,{defaultValue:`Help & Documentation`}),children:(0,$.jsx)(ut,{className:`h-4 w-4`})})}),(0,$.jsxs)(It,{align:`end`,className:`min-w-56 rounded-lg`,sideOffset:4,children:[je.length>0&&Ae?(0,$.jsxs)(qn,{className:`cursor-pointer`,onClick:()=>g(je.length===1?`/apps/${Ae}/docs/${je[0].name}`:`/apps/${Ae}/docs`),children:[(0,$.jsx)(Sn,{className:`mr-2 h-4 w-4`}),N(`help.appDocs`,{defaultValue:`This app's docs`})]}):null,(0,$.jsxs)(qn,{className:`cursor-pointer`,onClick:()=>g(`/docs`),children:[(0,$.jsx)($r,{className:`mr-2 h-4 w-4`}),N(`help.allDocs`,{defaultValue:`All documentation`})]}),f?(0,$.jsxs)(qn,{className:`cursor-pointer`,"data-testid":`action:keyboard-shortcuts:open`,onClick:b,children:[(0,$.jsx)(Jr,{className:`mr-2 h-4 w-4`}),N(`help.keyboardShortcuts`,{defaultValue:`Keyboard shortcuts`})]}):null,(0,$.jsx)(Yt,{}),(0,$.jsx)(qn,{asChild:!0,className:`cursor-pointer`,children:(0,$.jsxs)(`a`,{href:`https://docs.objectstack.ai`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,$.jsx)(Gi,{className:`mr-2 h-4 w-4`}),N(`help.onlineDocs`,{defaultValue:`Online documentation`})]})})]})]})]}),(0,$.jsxs)(`div`,{"data-topbar-group":!0,className:`flex items-center gap-0.5 shrink-0`,children:[` `,(0,$.jsxs)(Bn,{children:[(0,$.jsx)($n,{asChild:!0,children:(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 rounded-full`,children:(0,$.jsxs)(At,{className:`h-7 w-7 rounded-full`,children:[(0,$.jsx)(Qt,{src:x?.image,alt:x?.name??`User`}),(0,$.jsx)(Vt,{className:`rounded-full bg-primary text-primary-foreground text-xs`,children:E(x)})]})})}),(0,$.jsxs)(It,{align:`end`,className:`min-w-64 rounded-lg`,sideOffset:4,children:[(0,$.jsx)(Mt,{className:`p-0 font-normal`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-2 py-2`,children:[(0,$.jsxs)(At,{className:`h-8 w-8 rounded-lg`,children:[(0,$.jsx)(Qt,{src:x?.image,alt:x?.name??`User`}),(0,$.jsx)(Vt,{className:`rounded-lg bg-primary text-primary-foreground`,children:E(x)})]}),(0,$.jsxs)(`div`,{className:`grid flex-1 text-left text-sm leading-tight`,children:[(0,$.jsx)(`span`,{className:`truncate font-semibold`,children:x?.name??`User`}),(0,$.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:x?.email??``})]})]})}),(0,$.jsx)(Yt,{}),(0,$.jsxs)(In,{children:[(0,$.jsxs)(qn,{onClick:()=>g(`/apps/account/component/account/profile_card`),className:`cursor-pointer`,children:[(0,$.jsx)(br,{className:`mr-2 h-4 w-4`}),N(`user.profile`,{defaultValue:`Profile`})]}),xe&&(0,$.jsxs)(qn,{onClick:()=>g(`/organizations?manage=1`),className:`cursor-pointer`,"data-testid":`header-my-organizations`,children:[(0,$.jsx)(Zr,{className:`mr-2 h-4 w-4`}),N(`organizations.mine`,{defaultValue:`My Workspaces`})]}),xe&&!Se&&(0,$.jsxs)(qn,{onClick:()=>g(`/organizations?create=1`),className:`cursor-pointer`,"data-testid":`header-create-workspace`,children:[(0,$.jsx)(Ct,{className:`mr-2 h-4 w-4`}),N(`organizations.create`,{defaultValue:`Create workspace`})]}),(ie||[]).filter(e=>e.active!==!1&&e.hidden===!0&&e.name!==`account`).map(e=>{let t=qs(e.icon),n=I({name:e.name,label:ys(e.label,N)});return(0,$.jsxs)(qn,{onClick:()=>g(`/apps/${fo(e)??e.name}`),className:`cursor-pointer`,children:[(0,$.jsx)(t,{className:`mr-2 h-4 w-4`}),n]},`hidden_app_${e.name}`)})]}),(0,$.jsx)(Yt,{}),(0,$.jsx)(Mt,{className:`text-[11px] font-normal text-muted-foreground uppercase tracking-wide px-2`,children:N(`user.preferences`,{defaultValue:`Preferences`})}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,$.jsx)(`span`,{className:`text-foreground/80`,children:N(`user.theme`,{defaultValue:`Theme`})}),(0,$.jsx)(Qu,{})]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between px-2 py-1.5 text-sm`,children:[(0,$.jsx)(`span`,{className:`text-foreground/80`,children:N(`user.language`,{defaultValue:`Language`})}),(0,$.jsx)(ad,{})]}),T&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Yt,{}),(0,$.jsxs)(qn,{className:`text-destructive focus:text-destructive`,onClick:()=>S(),children:[(0,$.jsx)(Ir,{className:`mr-2 h-4 w-4`}),N(`user.logout`,{defaultValue:`Log out`})]})]})]})]})]})]})]})}var wd=`ai-chat-dock-width`,Td=`ai-chat-dock-expanded`,Ed=`ai-chat-studio-dock-expanded`,Dd=`ai-chat-studio-dock-width`;function Od(e,t){let n=t>0?Math.max(340,t-520):1/0;return Math.min(Math.max(e,340),n)}function kd(e){return Od(e,e)}function Ad(e){return e===`1`||e!==`0`&&null}function jd(e,t){try{let n=Ad(window.sessionStorage.getItem(e));return n===null?t:n}catch{return t}}function Md(e,t){try{window.sessionStorage.setItem(e,t?`1`:`0`)}catch{}}function Nd(){Md(Td,!0)}var Pd=`ai-chat-dock-return-to`;function Fd(e){try{window.sessionStorage.setItem(Pd,e)}catch{}}function Id(){try{let e=window.sessionStorage.getItem(Pd);return e&&e.startsWith(`/`)&&!e.startsWith(`//`)?e:void 0}catch{return}}function Ld(e){return!(e.metaKey||e.ctrlKey)||!e.shiftKey||e.altKey?null:e.key.toLowerCase()===`i`?`toggle`:null}async function Rd(e){return(await Yu(e)).length}var zd={"studio-build":`build`,default:`ask`};function Bd(e,t,n=!0){return t&&n&&No(`build`,e.map(e=>e.name))!==void 0}function Vd(e,t,n=!0){return Bd(e,t,n)?e.filter(e=>!wo(e.name)):e}function Hd(e,{agents:t,appDefaultAgent:n,aiStudioEnabled:r=!0,canAuthorMetadata:i=!1}){let a=t.map(e=>e.name),o=(yo(n)?n:void 0)??zd[e]??zd.default,s=!r&&Co(o)?`ask`:o,c=wo(s)&&Bd(t,i,r)?`build`:s;return No(c,a)??xo(t)}var Ud=`manage_metadata`;function Wd(){let{hasCapabilities:e}=O();return e([Ud])}function Gd(e){return{status:`drafted`,drafted:e.items,...e.summary?{summary:e.summary}:{},...e.packageId?{packageId:e.packageId}:{},...e.autoPublishable?{autoPublishable:!0}:{},...e.failedCount?{failed:Array.from({length:e.failedCount},()=>null)}:{},...e.materialized?{materialized:!0}:{},...e.verification?{verification:e.verification}:{},...e.issues&&e.issues.length?{issues:e.issues}:{},...e.nextSteps&&e.nextSteps.length?{nextSteps:e.nextSteps}:{}}}function Kd(e){return{status:`blueprint_proposed`,...e.summary?{summary:e.summary}:{},counts:e.counts,questions:e.questions,...e.targetApp?{targetApp:e.targetApp}:{},blueprint:{objects:e.objects.map(e=>({name:e.name,...e.label?{label:e.label}:{},fields:Array.from({length:e.fieldCount},()=>null)})),assumptions:e.assumptions}}}function qd(e){return e.kind===`published`?{status:`published`}:e.kind===`failed`&&e.dispatchError?{error:e.error??`replay dispatch failed`}:{status:`drafted`,...e.packageId?{packageId:e.packageId}:{},...e.kind===`failed`?{publishFailed:!0,...e.outcome?{publishOutcome:e.outcome}:{},...e.error?{publishError:e.error}:{}}:{}}}var Jd=`objectstack:ai-chat-conversation-id`,Yd=`objectstack:ai-chat-messages`;function Xd(e,t){return t?`${Jd}:${e}:${t}`:`${Jd}:${e}`}function Zd(e){try{return localStorage.getItem(e)??void 0}catch{return}}function Qd(e,t){try{t?localStorage.setItem(e,t):localStorage.removeItem(e)}catch{}}function $d(e){return`${Yd}:${e}`}function ef(){try{let e=[];for(let t=0;t<localStorage.length;t+=1){let n=localStorage.key(t);n&&(n.startsWith(Jd)||n.startsWith(Yd))&&e.push(n)}e.forEach(e=>localStorage.removeItem(e))}catch{}}function tf(e){try{let t=localStorage.getItem($d(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>!!e&&typeof e==`object`&&typeof e.id==`string`&&(e.role===`user`||e.role===`assistant`||e.role===`system`)&&Array.isArray(e.parts)):[]}catch{return[]}}function nf(e,t){if(e)try{if(t.length===0){localStorage.removeItem($d(e));return}localStorage.setItem($d(e),JSON.stringify(t))}catch{}}function rf(e){return e.map(e=>{let t=[];if(e.content&&t.push({type:`text`,text:e.content}),e.role===`assistant`)for(let n of e.toolInvocations??[]){let e=n.replayOutcome?qd(n.replayOutcome):n.draftReview?Gd(n.draftReview):n.proposedPlan?Kd(n.proposedPlan):void 0;t.push({type:`tool-${n.toolName}`,toolCallId:n.toolCallId,toolName:n.toolName,state:n.state??(n.errorText?`output-error`:`output-available`),...n.errorText?{errorText:n.errorText}:{},...e===void 0?{}:{output:e}})}if(t.length!==0)return{id:e.id,role:e.role,parts:t}}).filter(e=>!!e)}function af(e){return typeof e==`string`?e?[{type:`text`,text:e}]:[]:Array.isArray(e)?e.map(e=>{if(typeof e==`string`)return e?{type:`text`,text:e}:void 0;if(e&&typeof e==`object`&&`type`in e&&typeof e.type==`string`)return e;if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return{type:`text`,text:e.text}}).filter(e=>!!e):e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts)?af(e.parts):[]}function of(e,t){for(let n of af(e)){let e=typeof n.toolCallId==`string`?n.toolCallId:void 0;if(!e)continue;let r=t.get(e);if(!r)continue;let i=n.output??n.result;if(i===void 0)continue;r.output=i;let a=n.errorText;r.state=n.isError||typeof a==`string`?`output-error`:`output-available`,typeof a==`string`&&(r.errorText=a)}}function sf(e){if(!e)return[];let t=[],n=new Map;return e.forEach((e,r)=>{let i=e.role;if(i===`tool`){of(e.content,n);return}if(i!==`user`&&i!==`assistant`&&i!==`system`)return;let a=af(e.content);if(a.length!==0){if(i===`assistant`)for(let e of a){e.type===`tool-call`&&typeof e.toolName==`string`&&e.toolName&&(e.type=`tool-${e.toolName}`);let t=typeof e.toolCallId==`string`?e.toolCallId:void 0;t&&(e.type===`tool-call`||e.type.startsWith(`tool-`))&&n.set(t,e)}t.push({id:e.id??`msg-${r}`,role:i,parts:a})}}),t}function cf(e){if(!(typeof e!=`string`||!e))try{let t=JSON.parse(e);return Array.isArray(t)?t:void 0}catch{return}}function lf(e){return e?e.map(e=>{let t=e.id,n=typeof e.content==`string`?e.content:``;if(e.role===`assistant`){let r=cf(e.tool_calls);if(r&&r.length>0){let e=[];return n&&e.push({type:`text`,text:n}),e.push(...r),{id:t,role:`assistant`,content:e}}return{id:t,role:`assistant`,content:n}}if(e.role===`tool`){let r=cf(e.content);return r&&r.length>0&&r[0]?.type===`tool-result`?{id:t,role:`tool`,content:r}:{id:t,role:`tool`,content:[{type:`tool-result`,toolCallId:e.tool_call_id??``,toolName:`unknown`,output:{type:`text`,value:n}}]}}return{id:t,role:e.role,content:n}}):[]}async function uf(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(n.status===404||n.status===403)return null;if(!n.ok)throw Error(`GET conversation failed: ${n.status}`);return await n.json()}async function df(e){let t=await fetch(`${e}/conversations`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`},body:`{}`});if(!t.ok)throw Error(`POST conversation failed: ${t.status}`);return await t.json()}async function ff(e,t){await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{method:`DELETE`,credentials:`include`}).catch(()=>{})}function pf(e){let{userId:t,scope:n,apiBase:r,activeId:i,forceNew:a,resumeMode:o=`resume`,legacyScope:s,adoptLegacy:c}=e,l=(0,Q.useRef)(c);l.current=c;let[u,d]=(0,Q.useState)(void 0),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(!!t),g=(0,Q.useRef)(!0),_=(0,Q.useRef)(void 0),v=(0,Q.useRef)(void 0),y=(0,Q.useRef)(t);(0,Q.useEffect)(()=>(g.current=!0,()=>{g.current=!1}),[]),(0,Q.useEffect)(()=>{let e=y.current;y.current=t,e&&e!==t&&ef()},[t]),(0,Q.useEffect)(()=>{if(!t){d(void 0),p([]),h(!1),_.current=void 0,v.current=void 0;return}let e=v.current!==n;if(!i&&!a&&!e&&_.current===t&&u)return;let c=!1,f=Xd(t,n);return!i&&(a||e&&_.current===t)&&(d(void 0),p([])),h(!0),(async()=>{let e=i;try{if(i){let a=await uf(r,i);if(c)return;if(a){Qd(f,a.id),d(a.id);let e=sf(a.messages),r=e.length>0?e:tf(a.id);(r.length>0||a.id!==u)&&p(r),_.current=t,v.current=n;return}e=void 0,Qd(f,void 0),nf(i,[])}else if(!a){let i=Zd(f);if(e=i,!i&&s&&l.current){let e=Zd(Xd(t,s));if(e){try{let i=await uf(r,e);if(c)return;if(i){let e=sf(i.messages),r=e.length>0?e:tf(i.id);if(l.current?.(r)){Qd(f,i.id),d(i.id),p(r),_.current=t,v.current=n;return}}}catch{}if(c)return}}if(i){let a=await uf(r,i);if(c)return;if(a){let r=sf(a.messages);if(o!==`fresh`||r.length===0){d(a.id),p(o===`fresh`?[]:r.length>0?r:tf(a.id)),_.current=t,v.current=n;return}e=void 0}else e=void 0,Qd(f,void 0),nf(i,[])}}let m=await df(r);if(c)return;Qd(f,m.id),d(m.id),p(sf(m.messages)),_.current=t,v.current=n}catch{if(c||e&&e===u)return;d(void 0),p([])}finally{c||h(!1)}})(),()=>{c=!0}},[t,n,r,i,a,o,s]);let b=(0,Q.useCallback)(async()=>{if(!t)return;let e=Xd(t,n);h(!0);try{u&&await ff(r,u),nf(u,[]),Qd(e,void 0);let t=await df(r);if(Qd(e,t.id),nf(t.id,[]),!g.current)return;d(t.id),p([])}catch{g.current&&(d(void 0),p([]))}finally{g.current&&h(!1)}},[u,t,n,r]),x=(0,Q.useCallback)(async()=>{if(!t)return;let e=Xd(t,n);h(!0);try{let i=await df(r);if(Qd(e,i.id),nf(i.id,[]),!g.current)return;d(i.id),p([]),_.current=t,v.current=n}catch{}finally{g.current&&h(!1)}},[t,n,r]),S=(0,Q.useCallback)(e=>{!t||!u||(Qd(Xd(t,e),u),_.current=t,v.current=e)},[t,u]);return{conversationId:u,conversationScope:v.current,initialMessages:f,isLoading:m,reset:b,startNew:x,rekeyScope:S}}function mf(e){if(!e||e.length===0)return!1;let t=e[e.length-1];return!t||t.role!==`assistant`?!1:t.parts.some(e=>e.type===`text`&&String(e.text??``).trim().length>0)}function hf(e){let{chatApi:t,conversationId:n}=e,[r,i]=(0,Q.useState)(!1),a=(0,Q.useRef)(void 0);return{errorSuppressed:r,handleChatError:(0,Q.useCallback)(async e=>{if(e?.notSent){i(!1);return}let r=t?.replace(/\/agents\/[^/]+\/chat$/,``);if(!n||!r){i(!1);return}try{let e=sf((await uf(r,n))?.messages);if(mf(e)&&a.current){a.current(e),i(!0);return}}catch{}i(!1)},[n,t]),setMessagesRef:a,resetSuppression:(0,Q.useCallback)(()=>i(!1),[])}}function gf(e){return e&&Co(e)?`build`:`ask`}function _f({appId:e,product:t}){return e?`app:${e}:${t}`:t}var vf=new Set([`new chat`,`new conversation`,`untitled`,`新对话`]);function yf(e){let t=e?.trim().toLowerCase();return!t||vf.has(t)}function bf(e){let t=e.messages;if(!t||t.length===0)return;for(let e=t.length-1;e>=0;e--){let n=t[e];if(n.role===`user`){let e=xf(n.content);if(e)return e}}let n=t[t.length-1];return xf(n?.content)}function xf(e){if(typeof e==`string`)return e.slice(0,140);if(e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`)return e.text.slice(0,140);if(e&&typeof e==`object`&&`parts`in e&&Array.isArray(e.parts))return xf(e.parts);if(Array.isArray(e)){let t=e.map(e=>typeof e==`string`?e:e&&typeof e==`object`&&`text`in e&&typeof e.text==`string`?e.text:``).join(``);return t?t.slice(0,140):void 0}}function Sf(e){let t=e.title?.trim(),n=bf(e)??xf(e.preview);return{id:e.id,title:yf(t)?void 0:t,agentId:e.agentId,createdAt:e.createdAt,updatedAt:e.updatedAt,preview:n}}async function Cf(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}`,{credentials:`include`});if(!n.ok)return;let r=await n.json();return Sf(`conversation`in r&&r.conversation?r.conversation:r)}function wf(e){let{userId:t,apiBase:n,limit:r=50,refreshKey:i}=e,[a,o]=(0,Q.useState)([]),[s,c]=(0,Q.useState)(!!t),[l,u]=(0,Q.useState)(void 0),[d,f]=(0,Q.useState)(0),p=(0,Q.useCallback)(async()=>{f(e=>e+1)},[]),m=(0,Q.useCallback)(async e=>{try{await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`DELETE`,credentials:`include`})}finally{o(t=>t.filter(t=>t.id!==e))}},[n]),h=(0,Q.useCallback)(async(e,t)=>{let r=t.trim();o(t=>t.map(t=>t.id===e?{...t,title:r||void 0}:t));let i=await fetch(`${n}/conversations/${encodeURIComponent(e)}`,{method:`PATCH`,credentials:`include`,headers:{"Content-Type":`application/json`},body:JSON.stringify({title:r})});if(!i.ok)throw f(e=>e+1),Error(`PATCH conversation failed: ${i.status}`)},[n]);return(0,Q.useEffect)(()=>{if(!t){o([]),c(!1),u(void 0);return}let e=!1;return c(!0),u(void 0),(async()=>{try{let t=await fetch(`${n}/conversations?limit=${encodeURIComponent(String(r))}`,{credentials:`include`});if(!t.ok)throw Error(`GET conversations failed: ${t.status}`);let i=await t.json(),a=Array.isArray(i)?i:i.conversations??i.items??[];if(e)return;let s=a.map(Sf).sort((e,t)=>(t.updatedAt??``).localeCompare(e.updatedAt??``));o(s);let c=s.filter(e=>!e.title&&!e.preview).slice(0,20);if(c.length>0){let t=await Promise.all(c.map(e=>Cf(n,e.id).catch(()=>void 0)));if(e)return;let r=new Map(t.filter(e=>!!(e?.preview||e?.title)).map(e=>[e.id,e]));r.size>0&&o(e=>e.map(e=>{let t=r.get(e.id);return t?{...e,title:e.title??t.title,preview:e.preview??t.preview}:e}))}}catch(t){if(e)return;u(t instanceof Error?t:Error(String(t))),o([])}finally{e||c(!1)}})(),()=>{e=!0}},[t,n,r,d,i]),{conversations:a,isLoading:s,error:l,refetch:p,remove:m,rename:h}}function Tf(e,t){if(!e)return``;let n=new Date(e);if(Number.isNaN(n.getTime()))return``;let r=Date.now()-n.getTime(),i=6e4,a=60*i,o=24*a;return r<i?t(`console.ai.justNow`):r<a?t(`console.ai.minutesAgo`,{count:Math.floor(r/i)}):r<o?t(`console.ai.hoursAgo`,{count:Math.floor(r/a)}):r<7*o?t(`console.ai.daysAgo`,{count:Math.floor(r/o)}):n.toLocaleDateString()}function Ef(e){if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?``:t.toLocaleString()}var Df=[`today`,`yesterday`,`previous7Days`,`previous30Days`,`older`],Of={today:`Today`,yesterday:`Yesterday`,previous7Days:`Previous 7 days`,previous30Days:`Previous 30 days`,older:`Older`};function kf(e,t=Date.now()){let n=new Date(t);n.setHours(0,0,0,0);let r=n.getTime(),i=864e5,a=e=>{let t=new Date(e.updatedAt??e.createdAt??0).getTime();return Number.isNaN(t)?0:t},o={today:[],yesterday:[],previous7Days:[],previous30Days:[],older:[]};for(let t of[...e].sort((e,t)=>a(t)-a(e))){let e=a(t);e>=r?o.today.push(t):e>=r-i?o.yesterday.push(t):e>=r-7*i?o.previous7Days.push(t):e>=r-30*i?o.previous30Days.push(t):o.older.push(t)}return Df.filter(e=>o[e].length>0).map(e=>({key:e,items:o[e]}))}function Af({userId:e,apiBase:t,activeAgent:n,includeAskConversations:r,className:i,refreshKey:a,titleHints:o,onNavigate:s}){let{t:l}=G(),u=p(),{conversationId:d}=c(),{conversations:f,isLoading:m,error:h,remove:g,rename:_}=wf({userId:e,apiBase:t,refreshKey:a}),[v,y]=(0,Q.useState)(``),[b,x]=(0,Q.useState)(void 0),S=n?Oo(n):void 0,C=(0,Q.useMemo)(()=>{if(!n)return;let e=new Set(ko(n));if(r){for(let t of ko(`ask`))e.add(t);for(let t of ko(`build`))e.add(t)}return e},[n,r]),w=(0,Q.useMemo)(()=>f.map(e=>{let t=o?.[e.id]?.trim();return!t||e.title?.trim()||e.preview?.trim()?e:{...e,preview:t}}),[f,o]),T=(0,Q.useMemo)(()=>C?w.filter(e=>!e.agentId||C.has(e.agentId)||e.id===d):w,[w,C,d]),E=(0,Q.useMemo)(()=>{let e=v.trim().toLowerCase();return e?T.filter(t=>`${t.title??``} ${t.preview??``}`.toLowerCase().includes(e)):T},[T,v]),D=(0,Q.useCallback)(e=>{let t=e.agentId?Oo(e.agentId):S;return t?`/ai/${t}/${e.id}`:`/ai/${e.id}`},[S]),O=(0,Q.useCallback)(()=>{u(S?`/ai/${S}?new=1`:`/ai?new=1`),s?.()},[u,S,s]),k=(0,Q.useCallback)(async(e,t)=>{e.stopPropagation(),await g(t),t===d&&(u(S?`/ai/${S}`:`/ai`,{replace:!0}),s?.())},[g,d,u,S,s]),A=(0,Q.useCallback)(async(e,t)=>{x(void 0);try{await _(e,t)}catch{}},[_]);return(0,$.jsxs)(`aside`,{className:qr(`flex h-full min-h-0 flex-col bg-muted/30`,i),"data-testid":`ai-conversations-sidebar`,children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium`,children:l(`console.ai.chats`)}),(0,$.jsxs)(J,{size:`sm`,variant:`outline`,onClick:O,"data-testid":`ai-new-chat`,children:[(0,$.jsx)(Ct,{className:`h-3.5 w-3.5`}),l(`console.ai.newChat`)]})]}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(ur,{className:`pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(q,{value:v,onChange:e=>y(e.target.value),placeholder:l(`console.ai.searchChats`),className:`h-7 pl-7 text-xs`,"data-testid":`ai-conversations-search`})]})]}),(0,$.jsx)(Qr,{className:`flex-1 min-h-0`,children:m&&f.length===0?(0,$.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:l(`common.loading`)}):h?(0,$.jsx)(`div`,{className:`px-3 py-4 text-xs text-destructive`,children:h.message}):T.length===0?(0,$.jsxs)(oi,{className:`px-3 py-8`,children:[(0,$.jsx)(Oi,{className:`h-8 w-8 text-muted-foreground`}),(0,$.jsx)(Hi,{children:l(`console.ai.noChatsYet`)}),(0,$.jsx)(Wr,{children:l(`console.ai.noChatsDescription`)})]}):E.length===0?(0,$.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted-foreground`,children:l(`console.ai.noMatchingChats`)}):(0,$.jsx)(`div`,{className:`flex flex-col py-1`,children:kf(E).map(e=>(0,$.jsxs)(`section`,{"data-testid":`ai-conversation-group-${e.key}`,children:[(0,$.jsx)(`h3`,{className:`px-3 pb-1 pt-3 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:l(`console.ai.group.${e.key}`,{defaultValue:Of[e.key]})}),(0,$.jsx)(`ul`,{className:`flex flex-col`,children:e.items.map(e=>(0,$.jsx)(Mf,{conversation:e,query:v.trim(),active:e.id===d,renaming:e.id===b,onSelect:()=>{u(D(e)),s?.()},onDelete:t=>k(t,e.id),onStartRename:()=>x(e.id),onCancelRename:()=>x(void 0),onSubmitRename:t=>A(e.id,t)},e.id))})]},e.key))})})]})}function jf(e,t){if(!e)return e??null;let n=t?.trim().toLowerCase();if(!n)return e;let r=e.toLowerCase(),i=[],a=0,o=0;for(;;){let t=r.indexOf(n,a);if(t===-1){i.push(e.slice(a));break}t>a&&i.push(e.slice(a,t)),i.push((0,$.jsx)(`mark`,{className:`rounded-[2px] bg-primary/20 px-0.5 text-foreground`,children:e.slice(t,t+n.length)},o++)),a=t+n.length}return i}function Mf({conversation:e,query:t,active:n,renaming:r,onSelect:i,onDelete:a,onStartRename:o,onCancelRename:s,onSubmitRename:c}){let{t:l}=G(),u=e.title?.trim()||e.preview?.trim()||l(`console.ai.newConversation`),[d,f]=(0,Q.useState)(u),p=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{r&&(f(e.title?.trim()||e.preview?.trim()||``),setTimeout(()=>p.current?.select(),0))},[r,e.title,e.preview]),r?(0,$.jsx)(`li`,{children:(0,$.jsxs)(`div`,{className:qr(`flex w-full items-center gap-1 border-l-2 px-3 py-2`,n?`border-primary bg-accent`:`border-transparent`),"data-testid":`ai-conversation-rename-row-${e.id}`,children:[(0,$.jsx)(q,{ref:p,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),c(d)):e.key===`Escape`&&(e.preventDefault(),s())},className:`h-7 flex-1 text-sm`,"data-testid":`ai-conversation-rename-input-${e.id}`,"aria-label":l(`console.ai.renameConversation`)}),(0,$.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:()=>c(d),"data-testid":`ai-conversation-rename-confirm-${e.id}`,"aria-label":l(`console.ai.saveRename`),children:(0,$.jsx)(Pr,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(J,{size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0`,onClick:s,"aria-label":l(`console.ai.cancelRename`),children:(0,$.jsx)(ci,{className:`h-3.5 w-3.5`})})]})}):(0,$.jsx)(`li`,{children:(0,$.jsxs)(`div`,{className:qr(`group flex w-full items-start gap-2 border-l-2 border-transparent px-3 py-2 text-sm transition-colors hover:bg-accent/50`,n&&`border-primary bg-accent`),"data-testid":`ai-conversation-row-${e.id}`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:`min-w-0 flex-1 text-left`,"data-testid":`ai-conversation-select-${e.id}`,children:[(0,$.jsx)(`span`,{className:`line-clamp-1 font-medium`,children:jf(u,t)}),e.preview&&e.preview!==u?(0,$.jsx)(`span`,{className:`mt-0.5 block line-clamp-1 text-xs text-muted-foreground`,children:jf(e.preview,t)}):null,(0,$.jsx)(`span`,{className:`mt-0.5 block text-[10px] text-muted-foreground`,title:Ef(e.updatedAt??e.createdAt),children:Tf(e.updatedAt??e.createdAt,l)})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-0.5 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100`,children:[(0,$.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 hover:text-primary`,onClick:o,"data-testid":`ai-conversation-rename-${e.id}`,"aria-label":l(`console.ai.renameConversation`),children:(0,$.jsx)(dn,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(J,{type:`button`,size:`sm`,variant:`ghost`,className:`h-7 w-7 p-0 hover:text-destructive`,onClick:a,"data-testid":`ai-conversation-delete-${e.id}`,"aria-label":l(`console.ai.deleteConversation`),children:(0,$.jsx)(wn,{className:`h-3.5 w-3.5`})})]})]})})}function Nf(){return typeof window>`u`?``:window.location.pathname.startsWith(`/_console`)?`/_console`:``}function Pf(e,t){let n=`${Nf()}/apps/${encodeURIComponent(e)}`;return t?n:`${n}?preview=draft`}function Ff({appName:e,appSegment:t,materialized:n=!1,refreshKey:r,onClose:i}){let{t:a}=G(),o=p(),s=(0,Q.useRef)(null),c=t&&t.length?t:e;return(0,Q.useEffect)(()=>{if(!s.current)return;let e=Pf(c,n);try{s.current.getAttribute(`src`)!==e&&s.current.setAttribute(`src`,e)}catch{}},[c,n]),(0,Q.useEffect)(()=>{if(r>0)try{s.current?.contentWindow?.location.reload()}catch{}},[r]),(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1 flex-col border-l`,"data-testid":`live-canvas`,children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b bg-muted/30 px-3 py-1.5 text-xs text-muted-foreground`,children:[(0,$.jsx)(Dn,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n?a(`console.ai.liveCanvasUnlisted`,{app:e,defaultValue:`Live app — {{app}} (unlisted until published)`}):a(`console.ai.liveCanvas`,{app:e,defaultValue:`Live preview — {{app}} (draft)`})}),t&&(0,$.jsxs)(J,{size:`sm`,variant:`ghost`,onClick:()=>o(`/studio/${t}/interfaces`),"data-testid":`live-canvas-open-designer`,className:`gap-1.5`,title:a(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),"aria-label":a(`topbar.designInStudio`,{defaultValue:`Design in Studio`}),children:[(0,$.jsx)(Jn,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:a(`topbar.designInStudio`,{defaultValue:`Design in Studio`})})]}),(0,$.jsx)(J,{size:`sm`,variant:`ghost`,onClick:i,"data-testid":`live-canvas-close`,children:(0,$.jsx)(ci,{className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`iframe`,{ref:s,title:`Draft preview: ${e}`,src:Pf(c,n),className:`h-full w-full flex-1 border-0 bg-background`,"data-testid":`live-canvas-frame`})]})}function If(e,t,n){let r=`/studio/${encodeURIComponent(e)}/${t}`;return n?`${r}?${ec}=${encodeURIComponent(Ys(n))}`:r}function Lf(e,t){if(!e)return null;let n=t.name?.trim();if(!n)return null;switch(t.type){case`object`:return If(e,`data`,{type:`object`,name:n});case`flow`:return If(e,`automations`,{type:`flow`,name:n});case`dashboard`:return If(e,`interfaces`,{type:`dashboard`,name:n});case`page`:return If(e,`interfaces`,{type:`page`,name:n});case`view`:{let t=n.indexOf(`.`);return If(e,`interfaces`,{type:`object`,name:t>0?n.slice(0,t):n})}case`app`:return If(e,`interfaces`);default:return null}}async function Rf(e,t){let n=await fetch(`${e}/conversations/${encodeURIComponent(t)}/debug`,{credentials:`include`});if(n.status===404||n.status===403||n.status===401)return null;if(!n.ok)throw Error(`GET build debug failed: ${n.status}`);return await n.json()}function zf({apiBase:e,conversationId:t,open:n,onOpenChange:r}){let[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!n||!t)return;let r=!1;return s(!0),l(null),a(null),Rf(e,t).then(e=>{r||(e?a(e):l(`Not available — the conversation was not found or you are not authorized.`))}).catch(e=>{r||l(e instanceof Error?e.message:String(e))}).finally(()=>{r||s(!1)}),()=>{r=!0}},[n,t,e]);let u=i?.reconciliation,d=u?u.orphaned.length+u.missing.length+u.errors.length:0;return(0,$.jsx)(Bi,{open:n,onOpenChange:r,children:(0,$.jsxs)(Yi,{side:`right`,className:`w-full overflow-y-auto sm:max-w-xl`,children:[(0,$.jsxs)(Ki,{children:[(0,$.jsxs)(Tn,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ft,{className:`h-4 w-4`}),` Build Doctor`]}),(0,$.jsx)(hr,{children:`What the agent claimed vs what is actually live. Read-only diagnostic.`})]}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-4 text-sm`,children:[o&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,$.jsx)(Y,{className:`h-4 w-4 animate-spin`}),` Reconciling…`]}),c&&!o&&(0,$.jsx)(`div`,{className:`rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive`,children:c}),i&&!o&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`rounded-md border bg-muted/30 p-3 text-xs text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`font-medium text-foreground`,children:i.title??`(untitled)`}),(0,$.jsxs)(`div`,{className:`mt-1`,children:[i.summary.userTurns,` turn(s) · `,i.summary.messages,` msgs ·`,` `,i.summary.totalTokens.toLocaleString(),` tok ·`,` `,(i.summary.llmMs/1e3).toFixed(1),`s LLM`,i.summary.models.length?` · ${i.summary.models.join(`, `)}`:``]})]}),u&&(0,$.jsxs)(`div`,{className:u.ok?`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/10 p-3 text-emerald-700 dark:text-emerald-400`:`flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive`,children:[u.ok?(0,$.jsx)(Gr,{className:`h-4 w-4`}):(0,$.jsx)(Ji,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`font-medium`,children:u.ok?`All ${u.liveCount} attempted change(s) are live — nothing evaporated.`:`${d} discrepancy(ies) — what the chat said doesn't match what's live.`})]}),u&&u.orphaned.length>0&&(0,$.jsx)(Bf,{icon:(0,$.jsx)(yn,{className:`h-4 w-4 text-destructive`}),title:`Proposed but never applied`,hint:`A confirm card the agent proposed but no later turn applied — the change silently evaporated.`,findings:u.orphaned,tone:`destructive`}),u&&u.missing.length>0&&(0,$.jsx)(Bf,{icon:(0,$.jsx)(Ji,{className:`h-4 w-4 text-amber-600`}),title:`Claimed but missing`,hint:`A tool result said it was applied, but the artifact isn't live in sys_metadata.`,findings:u.missing,tone:`amber`}),u&&u.errors.length>0&&(0,$.jsx)(Bf,{icon:(0,$.jsx)(tr,{className:`h-4 w-4 text-destructive`}),title:`Tool errors`,hint:`Tool calls that returned an error during the build.`,findings:u.errors,tone:`destructive`}),i.verify&&(0,$.jsxs)(`div`,{className:`rounded-md border p-3 text-xs`,children:[(0,$.jsx)(`div`,{className:`font-medium text-foreground`,children:`Build check (verify_build)`}),(0,$.jsxs)(`div`,{className:`mt-1 text-muted-foreground`,children:[`Your app:`,` `,i.verify.userIssues.length===0?(0,$.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:`0 issues`}):(0,$.jsxs)(`span`,{className:`text-destructive`,children:[i.verify.userIssues.length,` issue(s)`]}),i.verify.platformNoise>0?` · ${i.verify.platformNoise} platform sys_* finding(s) hidden`:``]}),i.verify.userIssues.map((e,t)=>(0,$.jsxs)(`div`,{className:`mt-1 text-destructive`,children:[`[`,e.severity,`] `,e.code,` `,e.artifact?`${e.artifact.type}:${e.artifact.name}`:``]},t))]}),i.pendingActions.length>0&&(0,$.jsxs)(`div`,{className:`rounded-md border p-3 text-xs`,children:[(0,$.jsx)(`div`,{className:`font-medium text-foreground`,children:`Pending actions`}),i.pendingActions.map((e,t)=>(0,$.jsxs)(`div`,{className:`mt-1 text-muted-foreground`,children:[e.tool??`?`,` · `,e.object??`-`,` · `,(0,$.jsx)(`span`,{className:`font-mono`,children:e.status??`-`})]},t))]}),(0,$.jsxs)(`details`,{className:`rounded-md border p-3 text-xs`,children:[(0,$.jsxs)(`summary`,{className:`cursor-pointer font-medium text-foreground`,children:[`Timeline (`,i.timeline.length,`)`]}),(0,$.jsx)(`div`,{className:`mt-2 space-y-1 font-mono text-[11px] leading-relaxed`,children:i.timeline.map((e,t)=>(0,$.jsx)(Vf,{entry:e},t))})]})]})]})]})})}function Bf({icon:e,title:t,hint:n,findings:r,tone:i}){return(0,$.jsxs)(`div`,{className:`rounded-md border ${i===`destructive`?`border-destructive/30`:`border-amber-500/30`} p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-foreground`,children:[e,` `,t,` (`,r.length,`)`]}),(0,$.jsx)(`div`,{className:`mt-1 text-xs text-muted-foreground`,children:n}),(0,$.jsx)(`div`,{className:`mt-2 space-y-1`,children:r.map((e,t)=>(0,$.jsxs)(`div`,{className:`font-mono text-xs`,children:[e.t?`${e.t} · `:``,e.tool,` → `,e.artifact.type,`:`,e.artifact.name,(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (`,e.status,`)`]})]},t))})]})}function Vf({entry:e}){return e.kind===`user`?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 👤 `,e.text]}):e.kind===`assistant-text`?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 🤖 `,e.text]}):e.kind===`assistant-calls`?(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` 🤖 →`,` `,e.calls.map(e=>e.name).join(`, `)]}):(0,$.jsxs)(`div`,{className:e.isError?`text-destructive`:``,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.t}),` ↳ `,e.name,e.status?` (${e.status})`:``]})}function Hf(e){if(typeof e.content==`string`)return e.content;let t=e.parts;return Array.isArray(t)?t.map(e=>e&&typeof e==`object`&&e.type===`text`?String(e.text??``):``).join(` `):``}function Uf(e){if(Array.isArray(e))for(let t=e.length-1;t>=0;t--){let n=e[t];if(!n||n.role!==`user`)continue;let r=Hf(n);if(r.trim())return/[一-鿿]/.test(r)?`zh-CN`:void 0}}function Wf(e){return(Uf(e)??``).toLowerCase().startsWith(`zh`)}var Gf={planApproveMessage:{zh:`确认,开始搭建。`,en:`Looks good — build it as proposed.`},planApproveDefaultsMessage:{zh:`确认搭建,未决问题按你的合理假设和默认处理。`,en:`Build it with your best assumptions; use sensible defaults for the open questions.`},planAnswerMessage:{zh:`关于「{{question}}」,我选择「{{option}}」。`,en:`For "{{question}}", go with: {{option}}.`},changesConfirmMessage:{zh:`确认修改,应用你刚才提议的改动。`,en:`Confirm — apply the change you just proposed.`}};function Kf(e,t){let n=e?.console?.ai?.[t];return typeof n==`string`&&n.trim()!==``?n:void 0}function qf(e,t){return t?e.replace(/\{\{\s*(\w+)\s*\}\}/g,(e,n)=>Object.prototype.hasOwnProperty.call(t,n)?t[n]:e):e}function Jf(e,t,n){let r=e?`zh`:`en`;return qf(Kf(e?st:Ye,t)??Gf[t][r],n)}var Yf=`/api/v1/ai`;function Xf(e,t){let n=e[t];return typeof n==`string`&&n.length>0?n:void 0}function Zf(e){let t=Xf(e,`state`);switch(t){case`input-streaming`:case`input-available`:return`output-available`;case`approval-requested`:case`approval-responded`:case`output-available`:case`output-error`:case`output-denied`:return t;default:return`output-available`}}function Qf(e){return e.map(e=>{let t=[],n,r=e.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``);if(e.role===`assistant`)for(let r of e.parts){if(!r.type.startsWith(`tool-`))continue;let i=Xf(r,`toolName`)??r.type.slice(5),a=Xf(r,`toolCallId`)??`${e.id}-${i}`,o=Zf(r),s=r.output??r.result,c=vo(s),l=mo(s),u=po(s),d=go(s),f=ho(s),p=Eo(a,s);if(t.push({toolCallId:a,toolName:i,...o?{state:o}:{},...s===void 0?{}:{result:s},...c&&!p?{draftReview:c}:{},...l?{proposedPlan:l}:{},...u?{builderHandoff:u}:{},...d?{recordHandoff:d}:{},...f?{proposedChanges:f}:{},...p?{replayOutcome:p}:{},...r.errorText?{errorText:String(r.errorText)}:{}}),!n){let e=_o(c);e&&(n=e)}}return{id:e.id,role:e.role,content:r,...t.length>0?{toolInvocations:t}:{},...n?{buildProgress:n}:{}}})}function $f(e,t){if(t)return t;let n;for(let t of e)for(let e of t.toolInvocations??[]){let t=e.draftReview?.packageId||e.builderHandoff?.packageId;t&&(n=t)}return n}var ep=`com.objectstack.`;function tp(e){return typeof e._packageId==`string`&&e._packageId.startsWith(ep)}function np(e){return e.find(e=>e.role===`user`)?.parts.filter(e=>e.type===`text`).map(e=>e.text??``).join(``).trim()||void 0}var rp={ask:{key:`console.ai.agentLabels.ask`,defaultValue:`Ask`},build:{key:`console.ai.agentLabels.build`,defaultValue:`Build`}};function ip(e,t,n){let r=t?rp[Oo(t)]:void 0;return r?e(r.key,{defaultValue:r.defaultValue}):n}function ap(e,t,n){return Co(t)?n?{title:n.appLabel?e(`console.ai.empty.editApp.title`,{defaultValue:`Editing “{{app}}”`,app:n.appLabel}):e(`console.ai.empty.editApp.titleGeneric`,{defaultValue:`Edit this app`}),description:e(`console.ai.empty.editApp.description`,{defaultValue:`What would you like to change? I’ll modify this app in place — add a field, object, view or automation, or adjust what’s already there.`})}:{title:e(`console.ai.empty.build.title`,{defaultValue:`Build with AI`}),description:e(`console.ai.empty.build.description`,{defaultValue:`Describe an app or workflow in plain language — I draft the objects, screens and automations, then you review and publish.`})}:wo(t)?{title:e(`console.ai.empty.ask.title`,{defaultValue:`Ask your data`}),description:e(`console.ai.empty.ask.description`,{defaultValue:`Ask questions about your records — counts, lists, and summaries across the data you can access.`})}:{title:e(`console.ai.emptyTitle`,{defaultValue:`Start a conversation`}),description:e(`console.ai.emptyDescription`,{defaultValue:`Ask anything — the assistant has access to your current app context.`})}}function op(e){if(e)return e.replace(/\/$/,``);let t={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},n=t.VITE_AI_BASE_URL;return n?n.replace(/\/$/,``):`${(t.VITE_SERVER_URL??``).replace(/\/$/,``)}${Yf}`}var sp=`ai-chats-collapsed`;function cp(){let[e,t]=(0,Q.useState)(()=>{try{return localStorage.getItem(sp)===`1`}catch{return!1}}),n=(0,Q.useRef)(!1);return{collapsed:e,toggle:(0,Q.useCallback)(()=>{n.current=!1,t(e=>{let t=!e;try{localStorage.setItem(sp,t?`1`:`0`)}catch{}return t})},[]),handleCanvasOpenChange:(0,Q.useCallback)(e=>{e?t(e=>e||(n.current=!0,!0)):n.current&&(n.current=!1,t(!1))},[])}}var lp=`ai-chat-pane-width`,up=480,dp=360,fp=420,pp=24;function mp(e,t){let n=t.containerWidth>0?Math.max(t.min,t.containerWidth-t.previewMin):1/0;return Math.min(Math.max(e,t.min),n)}function hp(e){let t=(0,Q.useRef)(null),[n,r]=(0,Q.useState)(()=>{try{let e=Number(localStorage.getItem(lp));return Number.isFinite(e)&&e>0?e:up}catch{return up}}),[i,a]=(0,Q.useState)(!1),o=(0,Q.useCallback)(e=>mp(e,{min:dp,previewMin:fp,containerWidth:t.current?.clientWidth??0}),[]),s=(0,Q.useCallback)(e=>{try{localStorage.setItem(lp,String(Math.round(e)))}catch{}},[]);return(0,Q.useEffect)(()=>{if(!e)return;let n=t.current;if(!n||typeof ResizeObserver>`u`)return;let i=new ResizeObserver(()=>r(e=>o(e)));return i.observe(n),()=>i.disconnect()},[e,o]),{width:n,dragging:i,containerRef:t,onHandlePointerDown:(0,Q.useCallback)(e=>{e.preventDefault();let t=e.clientX,i=n;a(!0);let c=e=>r(o(i+(e.clientX-t))),l=e=>{let n=o(i+(e.clientX-t));r(n),s(n),a(!1),window.removeEventListener(`pointermove`,c),window.removeEventListener(`pointerup`,l)};window.addEventListener(`pointermove`,c),window.addEventListener(`pointerup`,l)},[o,s,n]),onHandleKeyDown:(0,Q.useCallback)(e=>{let t=e.key===`ArrowLeft`?-24:e.key===`ArrowRight`?pp:0;t&&(e.preventDefault(),r(e=>{let n=o(e+t);return s(n),n}))},[o,s]),reset:(0,Q.useCallback)(()=>{let e=o(up);r(e),s(e)},[o,s])}}function gp(e){if(!(e.metaKey||e.ctrlKey)||!e.shiftKey||e.altKey)return null;switch(e.key.toLowerCase()){case`o`:return`new-chat`;case`s`:return`toggle-list`;default:return null}}function _p(e,t){return t||(typeof e==`number`&&e>0?-1:`/home`)}var vp=[];function yp(e){let{chatApi:t,conversationId:n,pendingRef:r,doSend:i,pendingSignal:a,agentRoute:o}=e,s=!!t;return(0,Q.useEffect)(()=>{if(!s||!n)return;let e=r.current;e&&(e.targetAgentRoute&&e.targetAgentRoute!==o||(r.current=null,i(e.content,e.files)))},[s,n,r,i,a,o]),(0,Q.useCallback)((e,t)=>{if(s&&!n){r.current={content:e,files:t};return}i(e,t)},[s,n,r,i])}function bp({apiBase:e,defaultAgent:t}={}){let{user:n}=C(),{t:r}=G(),i=n?.id,{agent:a,conversationId:o}=c(),[l]=s(),u=l.toString(),d=l.get(`new`)!==null,f=l.get(`package`)?.trim()||void 0,m=l.get(`handoffPrompt`)?.trim()||void 0,h=l.get(`parentConversationId`)?.trim()||void 0,g=p(),{setContext:_}=Ra();(0,Q.useEffect)(()=>{_(`home`)},[_]);let v=(0,Q.useMemo)(()=>op(e),[e]),y={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_AI_DEFAULT_AGENT,{agents:b,isLoading:x,error:S,refetch:w}=So({apiBase:v}),T=(0,Q.useMemo)(()=>b.map(e=>e.name),[b]),E=!x&&b.length===0,D=(0,Q.useMemo)(()=>{if(!a)return!1;if(b.length!==0)return No(a,T)!==void 0},[a,b.length,T]),O=a?void 0:l.get(`agent`)??void 0,k=Bd(b,Wd(),ps()),A=(0,Q.useMemo)(()=>{let e=xo(b,O??t??y);return k&&wo(e)?No(`build`,T)??e:e},[b,O,t,y,k,T]),j=(0,Q.useMemo)(()=>{if(b.length!==0)return a&&D?No(a,T):A},[b.length,a,D,T,A]),M=j?Oo(j):void 0,ee=!!(a&&D===!1&&yo(a)),N=a&&D===!1&&!ee?a:void 0,te=j?`${v}/agents/${encodeURIComponent(j)}/chat`:void 0,P=j?_f({appId:f,product:gf(j)}):void 0,F=j?gf(j):void 0,ne=f&&F===`build`&&P!==F?F:void 0,re=(0,Q.useCallback)(e=>!!f&&$f(Qf(e),void 0)===f,[f]),{conversationId:I,conversationScope:ie,initialMessages:L,rekeyScope:ae}=pf({userId:j?i:void 0,scope:P,apiBase:v,activeId:o??N,forceNew:d,legacyScope:ne,adoptLegacy:ne?re:void 0}),oe=ie===P,R=oe?I:void 0,se=oe?L:vp;(0,Q.useEffect)(()=>{if(b.length===0||!j)return;let e=Oo(j),t=new URLSearchParams(u);t.delete(`agent`);let n=t.toString()?`?${t.toString()}`:``;if(!a){g(`/ai/${e}${n}`,{replace:!0});return}if(ee){g(`/ai/${e}${n}`,{replace:!0});return}if(k&&D&&wo(j)&&!o){g(`/ai/build${n}`,{replace:!0});return}if(D&&a!==e){let t=o?`/${encodeURIComponent(o)}`:``;g(`/ai/${e}${t}${n}`,{replace:!0})}},[b.length,j,a,D,ee,k,o,u,g]),(0,Q.useEffect)(()=>{if(N===void 0)return;let e=!1;return(async()=>{let t;try{t=(await uf(v,N))?.agentId??void 0}catch{}if(e)return;let n=No(t??``,T),r=Oo(n??j??`ask`);g(`/ai/${r}/${encodeURIComponent(N)}`,{replace:!0})})(),()=>{e=!0}},[N,v,T,j,g]);let[z,B]=(0,Q.useState)(0),[ce,le]=(0,Q.useState)({}),[ue,de]=(0,Q.useState)(!1),[fe,pe]=(0,Q.useState)(!1),[me,V]=(0,Q.useState)(!1),{collapsed:he,toggle:ge,handleCanvasOpenChange:_e}=cp();(0,Q.useEffect)(()=>{let e=e=>{let t=gp(e);t&&(e.preventDefault(),t===`toggle-list`?ge():g(M?`/ai/${M}?new=1`:`/ai?new=1`))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[ge,g,M]);let ve=(0,Q.useMemo)(()=>v.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[v]),ye=(0,Q.useMemo)(()=>Wu(),[]),be=(0,Q.useRef)(null);d?be.current===null&&(be.current={id:I}):be.current=null,(0,Q.useEffect)(()=>{if(!D||o||!I||!M||be.current&&be.current.id===I||ie!==P)return;let e=f?`?package=${encodeURIComponent(f)}`:``;g(`/ai/${M}/${I}${e}`,{replace:!0})},[D,o,I,ie,P,M,f,g]);let xe=(0,Q.useCallback)(e=>{!e||f||F!==`build`||!M||P===F&&ie===P&&(!I||o!==I||(ae(_f({appId:e,product:F})),g(`/ai/${M}/${encodeURIComponent(I)}?package=${encodeURIComponent(e)}`,{replace:!0})))},[f,F,M,P,ie,I,o,ae,g]),Se=(0,Q.useRef)(new Set);(0,Q.useEffect)(()=>{I&&L.length>0&&Se.current.add(I)},[I,L.length]),(0,Q.useEffect)(()=>{if(!I)return;let e=np(L);e&&le(t=>t[I]===e?t:{...t,[I]:e})},[I,L]);let Ce=(0,Q.useRef)(null),[H,we]=(0,Q.useState)(0),U=(0,Q.useCallback)(e=>{Ce.current=e,we(e=>e+1)},[]),W=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{!m||a!==`build`||W.current!==m&&(W.current=m,U({content:m,targetAgentRoute:`build`}))},[m,a,U]);let Te=(0,Q.useCallback)(e=>{if(B(e=>e+1),e&&I&&le(t=>({...t,[I]:e})),!e||!I||Se.current.has(I))return;Se.current.add(I);let t=()=>B(e=>e+1);setTimeout(t,2500),setTimeout(t,6e3)},[I]);return(0,$.jsxs)(`div`,{className:`flex h-svh w-full flex-col bg-background`,"data-testid":`ai-chat-page`,children:[(0,$.jsxs)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background/95 px-2 backdrop-blur sm:px-4`,children:[!E&&(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0 md:hidden`,onClick:()=>V(!0),"aria-label":r(`console.ai.openChats`),"data-testid":`ai-chat-mobile-sidebar-trigger`,children:(0,$.jsx)(Pt,{className:`h-4 w-4`})}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,$.jsx)(Cd,{variant:`home`})}),!E&&(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"data-testid":`ai-chat-collapse-to-dock`,"aria-label":r(`console.ai.collapseToDock`,{defaultValue:`Collapse to side panel`}),title:r(`console.ai.collapseToDock`,{defaultValue:`Collapse to side panel`}),onClick:()=>{Nd();let e=_p(window.history.state?.idx,Id());g(e===-1?-1:e)},children:(0,$.jsx)(mt,{className:`h-4 w-4`})})]}),E?(0,$.jsx)(xp,{hasError:!!S,onRetry:w,onHome:()=>g(`/home`),t:r}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Bi,{open:me,onOpenChange:V,children:(0,$.jsxs)(Yi,{side:`left`,className:`w-[320px] p-0 sm:max-w-[360px]`,"data-testid":`ai-chat-mobile-sidebar`,children:[(0,$.jsxs)(Ki,{className:`sr-only`,children:[(0,$.jsx)(Tn,{children:r(`console.ai.chats`)}),(0,$.jsx)(hr,{children:r(`console.ai.chatsDescription`)})]}),(0,$.jsx)(Af,{userId:i,apiBase:v,activeAgent:j,includeAskConversations:k,refreshKey:z,titleHints:ce,className:`h-full border-r-0`,onNavigate:()=>V(!1)})]})}),I&&(0,$.jsx)(Ut,{open:ue,onOpenChange:de,objectName:`ai_conversations`,recordId:I,recordLabel:`this conversation`,apiBase:ve,publicBaseUrl:ye}),I&&Mo(b,j,`debug`)&&(0,$.jsx)(zf,{apiBase:v,conversationId:I,open:fe,onOpenChange:pe}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 w-full bg-background`,children:[(0,$.jsxs)(`div`,{className:`hidden shrink-0 flex-col border-r md:flex`,children:[!he&&(0,$.jsx)(Af,{userId:i,apiBase:v,activeAgent:j,includeAskConversations:k,refreshKey:z,titleHints:ce,className:`w-72 min-h-0 flex-1 border-r-0`}),(0,$.jsx)(`div`,{className:qr(`mt-auto p-2`,he?`w-12`:`w-72 border-t`),children:(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:ge,"aria-label":he?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),title:he?r(`console.ai.showChats`,{defaultValue:`Show chats`}):r(`console.ai.hideChats`,{defaultValue:`Hide chats`}),"data-testid":`ai-chat-collapse-sidebar-trigger`,"aria-pressed":he,children:he?(0,$.jsx)(Pn,{className:`h-4 w-4`}):(0,$.jsx)(Gn,{className:`h-4 w-4`})})})]}),(0,$.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:(0,$.jsx)(Sp,{agents:b,agentsLoading:x,agentsError:S,activeAgent:j,chatApi:te,apiBase:v,conversationId:R,editPackageId:f,onPackageBound:xe,canBind:!!o,parentHandoffConversationId:h,initialMessages:se,pendingFirstMessageRef:Ce,pendingFirstMessageSeq:H,onSent:Te,onShare:()=>de(!0),onDebug:()=>pe(!0),showDebug:Mo(b,j,`debug`),onCanvasOpenChange:_e},`${te??`local`}:${R??`pending`}`)})]})]})]})}function xp({hasError:e,onRetry:t,onHome:n,t:r}){return(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,"data-testid":`ai-unavailable`,children:(0,$.jsxs)(oi,{children:[(0,$.jsx)(Hi,{children:r(`console.ai.unavailableTitle`,{defaultValue:`AI assistant unavailable`})}),(0,$.jsx)(Wr,{children:e?r(`console.ai.unavailableError`,{defaultValue:`Couldn't reach the AI service. It may be temporarily offline — try again, or head back home.`}):r(`console.ai.unavailableDescription`,{defaultValue:`This deployment doesn't have an AI assistant enabled. Everything else works as usual.`})}),(0,$.jsxs)(`div`,{className:`mt-6 flex flex-col items-center gap-3 sm:flex-row`,children:[e&&(0,$.jsx)(J,{variant:`outline`,onClick:t,"data-testid":`ai-unavailable-retry`,children:r(`console.ai.unavailableRetry`,{defaultValue:`Try again`})}),(0,$.jsx)(J,{onClick:n,"data-testid":`ai-unavailable-home`,children:r(`console.ai.unavailableHome`,{defaultValue:`Back to home`})})]})]})})}function Sp({agents:e,agentsLoading:n,agentsError:r,activeAgent:i,chatApi:a,apiBase:o,conversationId:s,editPackageId:c,surfaceContext:l,onPackageBound:u,canBind:d,parentHandoffConversationId:f,initialMessages:m,pendingFirstMessageRef:h,pendingFirstMessageSeq:g,onSent:_,onShare:v,onDebug:y,showDebug:b,onCanvasOpenChange:x}){let{t:S}=G(),C=p(),w=Vd(e,Wd(),ps()),T=w.length>1,E=(0,Q.useCallback)(e=>{let t=new URLSearchParams,n=e.packageId||c;n&&t.set(`package`,n),e.prompt&&t.set(`handoffPrompt`,e.prompt),s&&t.set(`parentConversationId`,s);let r=t.toString();C(`/ai/build${r?`?${r}`:``}`)},[C,c,s]),D=(0,Q.useCallback)(async e=>{let t=`setup`;try{let n=await fetch(`/api/v1/meta/object/${encodeURIComponent(e.objectName)}`,{credentials:`include`});if(n.ok){let e=await n.json();typeof e?.item?._packageId==`string`&&e.item._packageId&&(t=e.item._packageId)}}catch{}C(`/apps/${encodeURIComponent(t)}/${encodeURIComponent(e.objectName)}/record/${encodeURIComponent(e.recordId)}`)},[C]),[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(0),M=sr(),[ee,N]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{O||N(!1)},[O]);let te=Ue(),[P,F]=(0,Q.useState)(null),ne=(0,Q.useRef)(null);(0,Q.useEffect)(()=>()=>{ne.current&&window.clearTimeout(ne.current)},[]);let re=O!==null;(0,Q.useEffect)(()=>{x?.(re)},[re,x]);let I=hp(re),ie=(0,Q.useCallback)((e,t)=>{let n=e.find(e=>e.type===`app`);n&&k(e=>e??{name:n.name,segment:t,materialized:!1}),ne.current&&window.clearTimeout(ne.current),ne.current=window.setTimeout(()=>j(e=>e+1),800)},[]),L=(0,Q.useCallback)(e=>{k(t=>t&&t.name===e&&!t.materialized?{...t,materialized:!0}:t??{name:e,materialized:!0})},[]);(0,Q.useEffect)(()=>{k(null)},[s]);let ae=(0,Q.useMemo)(()=>{let t=e.find(e=>e.name===i);return ip(S,i,t?.label??i??S(`console.ai.assistant`))},[e,i,S]),oe=(0,Q.useMemo)(()=>Qf(m),[m]),{errorSuppressed:R,handleChatError:se,setMessagesRef:z,resetSuppression:B}=hf({chatApi:a,conversationId:s}),{models:ce,defaultModelId:le}=Do({apiBase:o}),[ue,de]=(0,Q.useState)(void 0),fe=ue??le,{messages:pe,isLoading:me,error:V,sendMessage:he,stop:ge,reload:_e,clear:ve,setMessages:ye}=bo({api:a,conversationId:s,parentConversationId:f,model:fe,onError:se,body:{context:{activeApp:`AI`,agentName:i,autoPublishAiBuilds:ms().features.autoPublishAiBuilds,...c?{packageId:c}:{},...l?{surface:l}:{}}},initialMessages:oe,autoResponse:!a,autoResponseText:`Thanks for your message! I'm here to help.`,autoResponseDelay:600});(0,Q.useEffect)(()=>{z.current=ye},[ye]);let xe=(0,Q.useMemo)(()=>Fo(pe),[pe]);(0,Q.useEffect)(()=>{nf(s,rf(xe))},[s,xe]);let Se=(0,Q.useMemo)(()=>Wf(xe)||Wf(m),[xe,m]),Ce=(0,Q.useCallback)((e,t)=>Jf(Se,e,t),[Se]),H=Ce(`planApproveMessage`),we=Ce(`planApproveDefaultsMessage`),U=Ce(`changesConfirmMessage`),W=(0,Q.useMemo)(()=>({create_object:S(`console.ai.changeVerb.createObject`,{defaultValue:`Create object`}),add_field:S(`console.ai.changeVerb.addField`,{defaultValue:`Add field`}),modify_field:S(`console.ai.changeVerb.modifyField`,{defaultValue:`Modify field`}),delete_field:S(`console.ai.changeVerb.deleteField`,{defaultValue:`Delete field`}),create_metadata:S(`console.ai.changeVerb.createMetadata`,{defaultValue:`Create`}),update_metadata:S(`console.ai.changeVerb.updateMetadata`,{defaultValue:`Modify`}),create_seed:S(`console.ai.changeVerb.createSeed`,{defaultValue:`Generate sample data`}),create_package:S(`console.ai.changeVerb.createPackage`,{defaultValue:`Create app package`})}),[S]),Te=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{Te.current&&!me&&O&&j(e=>e+1),Te.current=me},[me,O]);let Ee=jo({messages:xe,apiBase:o,continueConversation:e=>{he(e)}}),De=yp({chatApi:a,conversationId:s,pendingRef:h,doSend:(0,Q.useCallback)((e,n)=>{B();let r=(n??[]).filter(e=>/\.(xlsx|xlsm|csv|tsv|txt)$/i.test(e.name));if(!r.length){if(n?.length){he(`${e}\n\n(用户上传了 ${n.length} 个附件:${n.map(e=>e.name).join(`、`)} — 当前仅支持读取表格类附件(Excel/CSV),这些文件的内容我没有读取。)`),_(e);return}he(e),_(e);return}F(r[0]),(async()=>{let i=e=>e.length>40?`${e.slice(0,40)}…`:e,a=e=>e.slice(0,12).map(e=>i(String(e??``)).replace(/\s+/g,` `)).join(` | `),o=e;for(let e of r.slice(0,2))try{let{parseSpreadsheetFile:n}=await t(async()=>{let{parseSpreadsheetFile:e}=await import(`./plugin-grid-kkbz4uec.js`).then(e=>e.t);return{parseSpreadsheetFile:e}},__vite__mapDeps([0]),import.meta.url),r=await n(e),i=r[0]??[],s=r.slice(1,4);o+=[`\n\n[附件表格 ${e.name} — ${Math.max(0,r.length-1)} 数据行 × ${i.length} 列(控制台已在本地解析,文件本体未上传)]`,`表头: ${a(i)}`,...s.map((e,t)=>`样例${t+1}: ${a(e)}`)].join(`
|
|
8
|
+
`)}catch(t){o+=`\n\n[附件表格 ${e.name}] 解析失败(${t instanceof Error?t.message:`unknown`})— 请引导用户改用对象列表的 Import 上传该文件。`}r.length>2&&(o+=`\n\n(另有 ${r.length-2} 个表格附件未读取 — 一次最多读取 2 个。)`);let s=(n??[]).length-r.length;s>0&&(o+=`\n\n(另有 ${s} 个非表格附件,内容未读取。)`),he(o),_(o)})()},[B,he,_]),pendingSignal:g,agentRoute:i?Oo(i):void 0}),Oe=i?Oo(i)===`build`:!1,{apps:ke}=be(),Ae=ke,{appLabel:je}=at(),Me=(0,Q.useMemo)(()=>$f(xe,c),[xe,c]),Ne=(0,Q.useMemo)(()=>{if(!Me)return;let e=(Ae??[]).find(e=>e._packageId===Me);return e?je({name:e.name,label:ys(e.label,S)}):Me},[Me,Ae,je,S]),Pe=(0,Q.useMemo)(()=>{if(!c)return;let e=(Ae??[]).find(e=>e._packageId===c);return e?je({name:e.name,label:ys(e.label,S)}):void 0},[c,Ae,je,S]),Fe=Oe&&!!c,Ie=(0,Q.useMemo)(()=>{if(!(oe.length>0))return Dp(i,ae,S,Fe)},[oe.length,i,ae,S,Fe]),Le=(0,Q.useMemo)(()=>ap(S,i,Fe?{appLabel:Pe}:void 0),[S,i,Fe,Pe]);(0,Q.useEffect)(()=>{!Oe||!d||!Me||c||me||u?.(Me)},[Oe,d,Me,c,me,u]);let Re=(0,Q.useMemo)(()=>{for(let e=pe.length-1;e>=0;e--)for(let t of pe[e].toolInvocations??[]){let e=Po(t.result);if(e)return e;let n=t.draftReview;if(n?.packageId&&n.items?.some(e=>e.type===`app`))return n.packageId}},[pe]),ze=(0,Q.useRef)(!1),Be=p();(0,Q.useEffect)(()=>{if(!Oe||me||!d||!Re||ze.current)return;ze.current=!0;let e=!1;try{let t=`objectstack:ai-full-page-opted:${s??``}`;sessionStorage.getItem(`objectstack:ai-full-page-requested`)===`1`?(sessionStorage.removeItem(`objectstack:ai-full-page-requested`),sessionStorage.setItem(t,`1`),e=!0):sessionStorage.getItem(t)===`1`&&(e=!0)}catch{}e||(u?.(Re),Be(`/studio/${encodeURIComponent(Re)}/interfaces`))},[Oe,me,d,Re,s,u,Be]);let Ve=(0,Q.useRef)(void 0);(0,Q.useEffect)(()=>{if(me)return;let e=[...pe].reverse().find(e=>e.role===`assistant`);!e||e.id===Ve.current||(e.toolInvocations??[]).some(e=>e.draftReview||e.replayOutcome)&&(Ve.current=e.id,ba())},[me,pe]);let He=(0,Q.useMemo)(()=>{let e=new Map;for(let t of Ae??[]){let n=t._packageId;!n||e.has(n)||tp(t)||e.set(n,je({name:t.name,label:ys(t.label,S)}))}return Array.from(e,([e,t])=>({id:e,label:t}))},[Ae,je,S]),We=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border/50 px-4 pb-2 pt-3 sm:px-6`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2`,children:[T?w.length<=3?(0,$.jsx)($i,{value:i,onValueChange:e=>C(`/ai/${Oo(e)}`),children:(0,$.jsx)(Un,{className:`h-7 gap-0.5 p-0.5`,"data-testid":`ai-chat-agent-picker`,"aria-label":S(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:w.map(e=>(0,$.jsx)(Rt,{value:e.name,disabled:n,title:e.description||void 0,className:`h-6 px-2.5 text-xs`,children:ip(S,e.name,e.label)},e.name))})}):(0,$.jsxs)(Wi,{value:i,onValueChange:e=>C(`/ai/${Oo(e)}`),disabled:n,children:[(0,$.jsx)(Tt,{className:`h-7 w-auto min-w-0 border-0 bg-transparent px-1.5 text-xs shadow-none hover:bg-accent focus:ring-0 focus:ring-offset-0 focus-visible:ring-1 focus-visible:ring-border/80 focus-visible:ring-offset-0 sm:min-w-[160px]`,"data-testid":`ai-chat-agent-picker`,"aria-label":S(`console.ai.switchAssistant`,{defaultValue:`Switch assistant`}),children:(0,$.jsx)(sn,{placeholder:S(`console.ai.chooseAgent`,{defaultValue:`Choose assistant…`})})}),(0,$.jsx)(An,{align:`start`,children:w.map(e=>(0,$.jsxs)(Dt,{value:e.name,className:`text-xs`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:ip(S,e.name,e.label)}),e.description?(0,$.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[260px]`,children:e.description}):null]},e.name))})]}):(0,$.jsx)(`span`,{className:`truncate text-xs font-medium text-foreground/85`,children:ae}),Oe?(0,$.jsxs)(Bn,{children:[(0,$.jsxs)($n,{"data-testid":`ai-build-package-chip`,title:Me,"aria-label":S(`console.ai.switchApp`,{defaultValue:`Switch app`}),className:qr(`inline-flex min-w-0 items-center gap-1 rounded-md border px-2 py-0.5 text-xs hover:bg-accent focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-border/80`,Me?`bg-muted/40 text-foreground/80`:`border-dashed text-muted-foreground`),children:[Me?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Wt,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`max-w-[10rem] truncate`,children:Ne})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Jt,{className:`size-3 shrink-0`}),S(`console.ai.newApp`,{defaultValue:`New app`})]}),(0,$.jsx)(zr,{className:`size-3 shrink-0 opacity-60`})]}),(0,$.jsxs)(It,{align:`start`,className:`max-h-72 w-56 overflow-y-auto`,children:[(0,$.jsx)(Mt,{className:`text-xs text-muted-foreground`,children:S(`console.ai.switchAppLabel`,{defaultValue:`Build conversations by app`})}),He.map(e=>(0,$.jsxs)(qn,{"data-testid":`ai-build-package-option-${e.id}`,className:`text-xs`,onSelect:()=>{e.id!==Me&&C(`/ai/build?package=${encodeURIComponent(e.id)}`)},children:[(0,$.jsx)(Wt,{className:`size-3 shrink-0`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),e.id===Me?(0,$.jsx)(Pr,{className:`size-3 shrink-0`}):null]},e.id)),He.length>0?(0,$.jsx)(Yt,{}):null,(0,$.jsxs)(qn,{"data-testid":`ai-build-package-option-new`,className:`text-xs`,onSelect:()=>C(`/ai/build?new=1`),children:[(0,$.jsx)(Jt,{className:`size-3 shrink-0`}),S(`console.ai.newApp`,{defaultValue:`New app`})]})]})]}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[b&&y?(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:y,disabled:!s,"aria-label":`Build Doctor`,"data-testid":`ai-chat-debug-button`,title:s?`Build Doctor — what actually landed?`:`Send a message first`,children:(0,$.jsx)(ft,{className:`h-3.5 w-3.5`})}):null,(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:v,disabled:!s,"aria-label":S(`console.ai.share`),"data-testid":`ai-chat-share-button`,title:S(s?`console.ai.shareTitle`:`console.ai.shareDisabledTitle`),children:(0,$.jsx)(Ai,{className:`h-3.5 w-3.5`})})]}),r?(0,$.jsx)(`span`,{className:`basis-full text-[10px] text-amber-700 dark:text-amber-400`,title:r.message,children:S(`console.ai.offlineDemoMode`)}):null]}),Ge=O!==null&&!M;return(0,$.jsxs)(`div`,{ref:I.containerRef,className:`relative flex min-h-0 flex-1 px-0`,children:[P&&te?(0,$.jsx)(`div`,{className:`pointer-events-none absolute top-2 left-0 right-0 z-20 flex justify-center px-4`,children:(0,$.jsx)(`div`,{className:`pointer-events-auto w-full max-w-3xl`,children:(0,$.jsx)(Ju,{file:P,dataSource:te,defaultObjectName:O?.name,onDone:()=>F(null)})})}):null,Oe?(0,$.jsx)(`div`,{className:`pointer-events-none absolute bottom-20 left-0 right-0 z-20 flex justify-center px-4`,children:(0,$.jsx)(Zu,{packageId:Me,idle:!me})}):null,(0,$.jsx)(`div`,{"data-chat-column":!0,className:Ge?`flex min-h-0 shrink-0 justify-center`:`flex min-h-0 flex-1 justify-center`,style:Ge?{width:I.width}:void 0,children:(0,$.jsx)(Ao,{className:`min-h-0 flex-1 bg-background md:max-w-5xl`,onUpgrade:fs()?()=>window.open(fs(),`_blank`,`noopener,noreferrer`):void 0,onOpenBuilder:E,onOpenRecord:D,surface:`plain`,maxHeight:`100%`,headerSlot:We,messages:xe,placeholder:i?Oo(i)===`ask`?S(`console.ai.askAnything`):S(`console.ai.askAgent`,{agent:ae}):S(n?`console.ai.loadingAgents`:`console.ai.askAnything`),labels:{emptyTitle:Le.title,emptyDescription:Le.description,clear:S(`console.ai.clearConversation`),sendHint:S(`console.ai.sendHint`),agentActivity:S(`console.ai.agentActivity`),toolCompleted:S(`console.ai.toolCompleted`),toolRunning:S(`console.ai.toolRunning`),toolAwaitingApproval:S(`console.ai.toolAwaitingApproval`),toolFailed:S(`console.ai.toolFailed`),connectionWaiting:S(`console.ai.connectionWaiting`,{defaultValue:`Waiting for server…`}),connectionStalledLabel:S(`console.ai.connectionStalled`,{defaultValue:`Still working…`}),connectionOfflineLabel:S(`console.ai.connectionOffline`,{defaultValue:`Connection lost — reconnecting…`}),designingPlanLabel:S(`console.ai.designingPlan`,{defaultValue:`Designing your app…`}),designingPlanHints:[S(`console.ai.designingPlanHint.data`,{defaultValue:`Mapping out the data you’ll track…`}),S(`console.ai.designingPlanHint.objects`,{defaultValue:`Shaping objects and their fields…`}),S(`console.ai.designingPlanHint.relations`,{defaultValue:`Connecting related records…`}),S(`console.ai.designingPlanHint.lookups`,{defaultValue:`Setting up relationships and lookups…`}),S(`console.ai.designingPlanHint.views`,{defaultValue:`Planning the screens and views…`}),S(`console.ai.designingPlanHint.forms`,{defaultValue:`Laying out forms and lists…`}),S(`console.ai.designingPlanHint.defaults`,{defaultValue:`Adding sensible defaults and validations…`}),S(`console.ai.designingPlanHint.dashboard`,{defaultValue:`Sketching a dashboard to track it…`}),S(`console.ai.designingPlanHint.review`,{defaultValue:`Double-checking the structure hangs together…`}),S(`console.ai.designingPlanHint.finalize`,{defaultValue:`Pulling the plan together…`})],toolDetailsHidden:S(`console.ai.toolDetailsHidden`),copy:S(`console.ai.copy`),copied:S(`console.ai.copied`),regenerate:S(`console.ai.regenerate`),model:S(`console.ai.model`),submit:S(`console.ai.submit`),uploadFiles:S(`console.ai.uploadFiles`),stopResponse:S(`console.ai.stopResponse`),sendFailedRateLimited:S(`console.ai.sendFailedRateLimited`,{defaultValue:`You're sending messages too quickly. Your message is kept below — wait a moment and try again.`}),sendFailedGeneric:S(`console.ai.sendFailedGeneric`,{defaultValue:`Couldn't send your message. It's kept below — please try again.`}),trace:S(`console.ai.trace`),viewTrace:S(`console.ai.viewTrace`)},models:ce,selectedModelId:fe,onModelChange:de,suggestions:Ie,onSendMessage:De,onClear:ve,hideClearBar:!0,onStop:me?ge:void 0,onReload:_e,isLoading:me,error:R?void 0:V,enableMarkdown:!0,onToolApprove:Ee.decide,toolDecisions:Ee.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onOpenBuiltApp:(e,t)=>C(`/apps/${encodeURIComponent(t??e)}`),openBuiltAppLabel:S(`console.ai.openBuiltApp`,{defaultValue:`Open app`}),onDesignBuiltApp:(e,t)=>{let n=t??O?.segment;n&&C(`/studio/${encodeURIComponent(n)}/interfaces`)},designBuiltAppLabel:S(`console.ai.designBuiltApp`,{defaultValue:`Design in Studio`}),getArtifactAction:(e,t)=>{let n=Lf(t??O?.segment,e);return n?()=>C(n):null},fetchPendingDraftCount:Rd,onPublishDrafts:async e=>{try{let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);let r=n?.data?.failedCount??n?.failedCount??0;if(r){let e=n?.data?.failed??n?.failed??[];throw Error(e.length>0?Bu(e):String(r))}let i=n?.data?.seedApplied??n?.seedApplied;return i&&i.success===!1?X.warning(S(`console.ai.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:i.error??(Array.isArray(i.errors)&&i.errors.length?String(i.errors[0]):void 0)}):X.success(S(`console.ai.publishOk`,{defaultValue:`Published — objects are now live.`})),ba(),{ok:!0,health:To(n)}}catch(e){return X.error(S(`console.ai.publishFailed`,{defaultValue:`Publish failed`}),{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:S(`console.ai.publishDrafts`,{defaultValue:`Publish`}),publishedLabel:S(`console.ai.published`,{defaultValue:`Published`}),nextStepsLabel:S(`console.ai.nextSteps`,{defaultValue:`What's next`}),planTitleLabel:S(`console.ai.planTitle`,{defaultValue:`Proposed plan`}),planQuestionsLabel:S(`console.ai.planQuestions`,{defaultValue:`Confirm before building`}),planAssumptionsLabel:S(`console.ai.planAssumptions`,{defaultValue:`Assumptions`}),planDeferredLabel:S(`console.ai.planDeferred`,{defaultValue:`Not yet built`}),planApproveHintLabel:S(`console.ai.planApproveHint`,{defaultValue:`Reply to approve or adjust this plan.`}),planApproveLabel:S(`console.ai.planApprove`,{defaultValue:`Build it`}),planAdjustLabel:S(`console.ai.planAdjust`,{defaultValue:`Adjust`}),planBuiltLabel:S(`console.ai.planBuilt`,{defaultValue:`Built`}),planBuildingLabel:S(`console.ai.planBuilding`,{defaultValue:`Building…`}),planReadyLabel:S(`console.ai.planReady`,{defaultValue:`The plan is ready. Build it now, or tell me what to adjust.`}),planApproveMessage:H,planApproveDefaultsMessage:we,changesTitleLabel:S(`console.ai.changesTitle`,{defaultValue:`Confirm changes`}),changesConfirmedLabel:S(`console.ai.changesConfirmed`,{defaultValue:`Confirmed`}),changesConfirmLabel:S(`console.ai.changesConfirm`,{defaultValue:`Confirm`}),changesConfirmHintLabel:S(`console.ai.changesConfirmHint`,{defaultValue:`Reply to confirm or adjust this change.`}),changesConfirmMessage:U,changeVerbLabels:W,changesApplyingLabel:S(`console.ai.changesApplying`,{defaultValue:`Applying…`}),changesAppliedLabel:S(`console.ai.changesApplied`,{defaultValue:`Applied`}),changesDraftedLabel:S(`console.ai.changesDrafted`,{defaultValue:`Saved as draft`}),changesFailedLabel:S(`console.ai.changesFailed`,{defaultValue:`Not applied`}),surfaceContextLabel:l?.artifact?S(`console.ai.discussing`,{defaultValue:`Discussing: {{target}}`,target:`${l.artifact.type} · ${l.artifact.name}`}):void 0,planAnswerMessage:(e,t)=>Ce(`planAnswerMessage`,{question:e,option:t}),autoPublishDrafts:ms().features.autoPublishAiBuilds,onDraftArtifacts:ie,onPreviewDraftApp:(e,t)=>{k({name:e,segment:t?.appSegment,materialized:t?.materialized===!0}),M&&N(!0)},onBuildMaterialized:L,previewDraftLabel:S(`console.ai.previewDraft`,{defaultValue:`Preview`}),"data-testid":`ai-chat-panel`})}),Ge?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":S(`console.ai.resizeSplit`,{defaultValue:`Resize chat and preview`}),tabIndex:0,onPointerDown:I.onHandlePointerDown,onKeyDown:I.onHandleKeyDown,onDoubleClick:I.reset,"data-testid":`ai-chat-split-handle`,className:qr(`group relative hidden w-1.5 shrink-0 cursor-col-resize touch-none select-none md:block`,`focus:outline-none`),children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`absolute inset-y-0 -left-1.5 -right-1.5`}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:qr(`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border transition-colors`,`group-hover:bg-primary/60 group-focus-visible:bg-primary`,I.dragging&&`bg-primary`)})]}),(0,$.jsx)(Ff,{appName:O.name,appSegment:O.segment,materialized:O.materialized,refreshKey:A,onClose:()=>k(null)}),I.dragging?(0,$.jsx)(`div`,{className:`fixed inset-0 z-50 cursor-col-resize`,"data-testid":`ai-chat-split-overlay`}):null]}):null,O&&M?(0,$.jsx)($.Fragment,{children:ee?(0,$.jsx)(`div`,{className:`absolute inset-0 z-30 flex flex-col bg-background`,"data-testid":`ai-chat-mobile-canvas`,children:(0,$.jsx)(Ff,{appName:O.name,appSegment:O.segment,materialized:O.materialized,refreshKey:A,onClose:()=>N(!1)})}):(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-24 z-20 flex justify-center px-4`,children:(0,$.jsxs)(J,{size:`sm`,onClick:()=>N(!0),"data-testid":`ai-chat-mobile-preview-open`,className:`pointer-events-auto gap-1.5 rounded-full shadow-lg`,children:[(0,$.jsx)(Dn,{className:`h-4 w-4`}),S(`console.ai.previewApp`,{defaultValue:`Preview app`})]})})}):null]})}function Cp(e){return[e(`console.ai.suggestions.dataChat.userCount`,{defaultValue:`How many users are in the system? List their emails.`}),e(`console.ai.suggestions.dataChat.recentRecords`,{defaultValue:`List the 5 most recently created records.`}),e(`console.ai.suggestions.dataChat.recordCounts`,{defaultValue:`Count records for each object.`})]}function wp(e){return[e(`console.ai.suggestions.metadataAssistant.buildCrm`,{defaultValue:`Build a sales CRM — customers, contacts, and a deal pipeline I can total by stage.`}),e(`console.ai.suggestions.metadataAssistant.buildApp`,{defaultValue:`Create a project tracker — projects, tasks with owners and due dates, and a board by status.`}),e(`console.ai.suggestions.metadataAssistant.buildFlow`,{defaultValue:`Design a support desk — tickets with priority, a status workflow, and customer links.`}),e(`console.ai.suggestions.metadataAssistant.buildInventory`,{defaultValue:`Build an inventory app — products, stock levels, suppliers, and low-stock visibility.`}),e(`console.ai.suggestions.metadataAssistant.buildRecruiting`,{defaultValue:`Make an applicant tracker — candidates, open roles, interview stages, and notes.`})]}function Tp(e){return[e(`console.ai.suggestions.generic.help`,{defaultValue:`What can you help me with?`}),e(`console.ai.suggestions.generic.availableObjects`,{defaultValue:`List the available data objects.`}),e(`console.ai.suggestions.generic.recentActivity`,{defaultValue:`Summarize my recent activity.`})]}function Ep(e){return[e(`console.ai.suggestions.editApp.addField`,{defaultValue:`Add a field to one of the objects.`}),e(`console.ai.suggestions.editApp.addObject`,{defaultValue:`Add a new object and relate it to an existing one.`}),e(`console.ai.suggestions.editApp.addDashboard`,{defaultValue:`Add a dashboard for the key metrics.`}),e(`console.ai.suggestions.editApp.addAutomation`,{defaultValue:`Add an automation — an approval, a status flow, or a notification.`})]}function Dp(e,t,n,r=!1){if(wo(e))return Cp(n);if(Co(e))return r?Ep(n):wp(n);let i=(e??t).toLowerCase();return i.includes(`data`)?Cp(n):i.includes(`metadata`)?wp(n):Tp(n)}function Op(e){return!!e&&typeof e==`object`&&`fraction`in e}function kp(e){let t=e?.meters;return!t||!Op(t.build)||!Op(t.dataChat)?null:{meters:{build:t.build,dataChat:t.dataChat}}}function Ap(e={}){let{apiBase:t,enabled:n=!0}=e,[r,i]=Q.useState(null),[a,o]=Q.useState(!1),[s,c]=Q.useState(void 0),[l,u]=Q.useState(0),d=Q.useCallback(()=>u(e=>e+1),[]),f=n&&!!t;return Q.useEffect(()=>{if(!f){i(null),c(void 0),o(!1);return}if(typeof fetch!=`function`)return;let e=!1,n=`${t.replace(/\/$/,``)}/usage`;return o(!0),fetch(n,{method:`GET`,headers:{Accept:`application/json`},credentials:`include`}).then(async e=>{if(!e.ok)throw Error(`Failed to load AI usage (${e.status})`);return e.json()}).then(t=>{e||(i(kp(t)),c(void 0))}).catch(t=>{e||(i(null),c(t instanceof Error?t:Error(String(t))))}).finally(()=>{e||o(!1)}),()=>{e=!0}},[f,t,l]),Q.useEffect(()=>{if(!f||typeof window>`u`)return;let e=()=>d(),t=()=>{document.visibilityState===`visible`&&d()};return window.addEventListener(Io,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(Io,e),document.removeEventListener(`visibilitychange`,t)}},[f,d]),{usage:r,loading:a,error:s,refetch:d}}var jp=36e5,Mp=24*jp;function Np(e){return e>=1?`full`:e>=.8?`low`:`ok`}function Pp(e){return e===`full`?`text-destructive`:e===`low`?`text-amber-500`:`text-primary`}function Fp({fraction:e,tone:t,size:n=16}){let r=(n-2)/2,i=2*Math.PI*r,a=i*Math.min(1,Math.max(0,e)),o=n/2;return(0,$.jsxs)(`svg`,{width:n,height:n,viewBox:`0 0 ${n} ${n}`,className:Pp(t),"aria-hidden":`true`,focusable:`false`,children:[(0,$.jsx)(`circle`,{cx:o,cy:o,r,fill:`none`,strokeWidth:2,className:`stroke-muted-foreground/25`}),(0,$.jsx)(`circle`,{cx:o,cy:o,r,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeDasharray:`${a} ${i}`,transform:`rotate(-90 ${o} ${o})`})]})}function Ip({apiBase:e,enabled:t=!0,className:n}){let{t:r}=G(),{usage:i}=Ap({apiBase:e,enabled:t}),[a,o]=Q.useState(null);Q.useEffect(()=>{o(Date.now());let e=setInterval(()=>o(Date.now()),6e4);return()=>clearInterval(e)},[]);let s=Q.useMemo(()=>{if(!i)return[];let e=[];return[`build`,`dataChat`].forEach(t=>{let n=i.meters[t];if(!n||n.unmetered||n.fraction==null)return;let r=n.fraction;e.push({key:t,meter:n,fraction:r,tone:Np(r)})}),e},[i]);if(!t||s.length===0)return null;let c=e=>e===`build`?r(`console.ai.usage.meterBuild`,{defaultValue:`Build`}):r(`console.ai.usage.meterAsk`,{defaultValue:`Ask`}),l=e=>e===`full`?r(`console.ai.usage.statusFull`,{defaultValue:`Limit reached`}):e===`low`?r(`console.ai.usage.statusLow`,{defaultValue:`Running low`}):r(`console.ai.usage.statusOk`,{defaultValue:`Plenty left`}),u=(e,t)=>{let n=new Date(e).getTime()-t;if(n<=Mp){let e=Math.max(1,Math.ceil(n/jp));return r(`console.ai.usage.resetsWeeklyHours`,{count:e,defaultValue:`Resets in {{count}} hours`})}let i=Math.ceil(n/Mp);return r(`console.ai.usage.resetsWeeklyDays`,{count:i,defaultValue:`Resets in {{count}} days`})},d=e=>e.resetKind===`daily`?r(`console.ai.usage.resetsDaily`,{defaultValue:`Resets tonight`}):e.resetKind===`monthly`?r(`console.ai.usage.resetsMonthly`,{defaultValue:`Resets next cycle`}):e.resetKind===`weekly`&&e.resetsAt&&a!==null?u(e.resetsAt,a):null,f=s.reduce((e,t)=>t.fraction>e.fraction?t:e),p=f.tone!==`ok`;return(0,$.jsxs)(rn,{children:[(0,$.jsx)(kt,{asChild:!0,children:(0,$.jsxs)(J,{variant:`ghost`,size:`sm`,"data-testid":`ai-usage-indicator`,className:qr(`h-7 gap-1.5 px-1.5 text-muted-foreground hover:text-foreground`,n),"aria-label":r(`console.ai.usage.ariaLabel`,{defaultValue:`AI usage: {{status}}`,status:l(f.tone)}),children:[(0,$.jsx)(`span`,{className:`flex items-center gap-1`,children:s.map(e=>(0,$.jsx)(Fp,{fraction:e.fraction,tone:e.tone},e.key))}),p?(0,$.jsx)(`span`,{className:qr(`hidden text-xs font-medium sm:inline`,f.tone===`full`?`text-destructive`:`text-amber-600 dark:text-amber-500`),children:l(f.tone)}):null]})}),(0,$.jsxs)(mn,{align:`end`,className:`w-64 p-3`,"data-testid":`ai-usage-popover`,children:[(0,$.jsx)(`div`,{className:`mb-2 text-xs font-semibold text-foreground/80`,children:r(`console.ai.usage.title`,{defaultValue:`AI usage`})}),(0,$.jsx)(`ul`,{className:`space-y-3`,children:s.map(({key:e,meter:t,fraction:n,tone:i})=>{let a=i!==`ok`&&(t.upgrade||t.topUp)&&!!fs(),o=d(t);return(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5`,children:[(0,$.jsx)(Fp,{fraction:n,tone:i,size:22}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:c(e)}),(0,$.jsx)(`span`,{className:qr(`text-xs`,i===`full`?`text-destructive`:i===`low`?`text-amber-600 dark:text-amber-500`:`text-muted-foreground`),children:l(i)})]}),o?(0,$.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:o}):null,a?(0,$.jsx)(J,{variant:`link`,size:`sm`,className:`mt-1 h-auto p-0 text-xs`,"data-testid":`ai-usage-cta-${e}`,onClick:()=>window.open(fs(),`_blank`,`noopener,noreferrer`),children:t.upgrade?r(`console.ai.usage.ctaUpgrade`,{defaultValue:`Upgrade to keep going`}):r(`console.ai.usage.ctaTopUp`,{defaultValue:`Add credits to continue`})}):null]})]},e)})})]})]})}var Lp=20;function Rp(e,t=``){let{href:n,external:r}=Ss(e,t);return r?n:!n||n===`#`?``:n}function zp(e){return`nav:${e}`}function Bp(){let{favorites:e,addFavorite:t,removeFavorite:n,setPinned:r,pinnedNavIds:i}=ao(),a=(0,Q.useCallback)((e,i,a,o)=>{let s=zp(e);i?(a&&t({id:s,label:a.label,href:Rp(a,o??``),type:`nav`,navId:e,pinned:!0}),r(s,!0)):n(s)},[t,n,r]),o=(0,Q.useCallback)(e=>i.has(e),[i]),s=(0,Q.useCallback)(e=>{if(i.size===0){let t=!1;for(let n of e)if(n.pinned){t=!0;break}if(!t)return e}let t=0,n=e=>e.map(e=>{let r=i.has(e.id)&&t<Lp;r&&t++;let a=e.children?.length?n(e.children):e.children;return r!==(e.pinned??!1)||a!==e.children?{...e,pinned:r,children:a}:e});return n(e)},[i]),c=(0,Q.useCallback)(()=>{for(let t of e)t.type===`nav`&&n(t.id)},[e,n]);return{pinnedIds:(0,Q.useMemo)(()=>Array.from(i),[i]),togglePin:a,isPinned:o,applyPins:s,clearPins:c}}var Vp=0;function Hp(e=`nav`){return`${e}_${Date.now()}_${++Vp}`}function Up(e,t){return[...e,t]}function Wp(e,t,n){return e.filter(e=>!(e.type===t&&(t===`page`&&e.pageName===n||t===`dashboard`&&e.dashboardName===n))).map(e=>e.children&&e.children.length>0?{...e,children:Wp(e.children,t,n)}:e)}function Gp(e,t,n,r){return e.map(e=>{let i=e;return t===`page`&&e.type===`page`&&e.pageName===n?i={...e,pageName:r}:t===`dashboard`&&e.type===`dashboard`&&e.dashboardName===n&&(i={...e,dashboardName:r}),i.children&&i.children.length>0?{...i,children:Gp(i.children,t,n,r)}:i})}function Kp(e,t){return e.length===t.length?e===t||JSON.stringify(e)===JSON.stringify(t):!1}function qp(e){return typeof e==`string`&&e.startsWith(`sys_`)}function Jp(e){if(!e||typeof e!=`object`)return!1;let t=e;return t._packageId!=null||t._provenance===`package`||qp(t.name)}function Yp(e){if(!e||typeof e!=`object`)return!1;let t=e,n=t._lock??t.protection?.lock;return n!==`full`&&n!==`no-overlay`}function Xp(){let e=Ue(),{apps:t,refresh:n}=be(),{t:r}=G(),i=(0,Q.useRef)(e);i.current=e;let a=(0,Q.useRef)(n);a.current=n;let o=(0,Q.useCallback)(async(e,t)=>{let n=i.current?.getClient();n&&await n.meta.saveItem(`app`,e,t),await a.current?.()},[]),s=(0,Q.useCallback)(e=>so(t,e),[t]),c=(0,Q.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Up(a,{id:Hp(`nav_page`),type:`page`,label:n||t,pageName:t,icon:`FileText`}),l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.addedPage`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),l=(0,Q.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Up(a,{id:Hp(`nav_dash`),type:`dashboard`,label:n||t,dashboardName:t,icon:`LayoutDashboard`}),l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.addedDashboard`,{name:n||t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),u=(0,Q.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=Wp(i,`page`,t);if(Kp(a,i))return;let c={...n,navigation:a};try{await o(e,c),X.success(r(`navigationSync.removedPage`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),d=(0,Q.useCallback)(async(e,t)=>{let n=s(e);if(!n)return;let i=n.navigation??[],a=Wp(i,`dashboard`,t);if(Kp(a,i))return;let c={...n,navigation:a};try{await o(e,c),X.success(r(`navigationSync.removedDashboard`,{name:t}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...n,navigation:i}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),f=(0,Q.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Gp(a,`page`,t,n);if(Kp(c,a))return;let l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.renamedPage`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),p=(0,Q.useCallback)(async(e,t,n)=>{let i=s(e);if(!i)return;let a=i.navigation??[],c=Gp(a,`dashboard`,t,n);if(Kp(c,a))return;let l={...i,navigation:c};try{await o(e,l),X.success(r(`navigationSync.renamedDashboard`,{oldName:t,newName:n}),{action:{label:r(`navigationSync.undoLabel`),onClick:async()=>{try{await o(e,{...i,navigation:a}),X.info(r(`navigationSync.undone`))}catch{X.error(r(`navigationSync.undoFailed`))}}}})}catch{X.error(r(`navigationSync.updateFailed`))}},[s,o,r]),m=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return{syncPageCreated:c,syncDashboardCreated:l,syncPageDeleted:u,syncDashboardDeleted:d,syncPageRenamed:f,syncDashboardRenamed:p,syncPageCreatedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!Yp(r)||await c(t,e,n)}},[t,c]),syncDashboardCreatedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!Yp(r)||await l(t,e,n)}},[t,l]),syncPageDeletedAllApps:(0,Q.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!Yp(n)||await u(t,e)}},[t,u]),syncDashboardDeletedAllApps:(0,Q.useCallback)(async e=>{for(let n of t){let t=m(n);!t||!Yp(n)||await d(t,e)}},[t,d]),syncPageRenamedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!Yp(r)||await f(t,e,n)}},[t,f]),syncDashboardRenamedAllApps:(0,Q.useCallback)(async(e,n)=>{for(let r of t){let t=m(r);!t||!Yp(r)||await p(t,e,n)}},[t,p])}}function Zp(){let{pages:e,dashboards:t,apps:n,getTypeStatus:r}=be(),i=Ue(),a=(0,Q.useRef)(i);a.current=i;let o=sa(),{syncPageCreated:s,syncDashboardCreated:c,syncPageDeleted:l,syncDashboardDeleted:u}=Xp(),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p=(0,Q.useRef)(0),m=(0,Q.useRef)(!1),h=e=>e&&typeof e==`object`&&`name`in e?e.name:void 0;return(0,Q.useEffect)(()=>{if(m.current)return;if(o){d.current=null,f.current=null;return}if(r&&(r(`page`)!==`ready`||r(`dashboard`)!==`ready`))return;let i=e=>new Set(e.filter(e=>!Jp(e)).map(e=>e?.name).filter(e=>typeof e==`string`&&e.length>0)),a=i(e??[]),g=i(t??[]),_=d.current,v=f.current;if(_===null||v===null){d.current=a,f.current=g;return}let y=[...a].filter(e=>!_.has(e)),b=[..._].filter(e=>!a.has(e)),x=[...g].filter(e=>!v.has(e)),S=[...v].filter(e=>!g.has(e));if(y.length===0&&b.length===0&&x.length===0&&S.length===0){d.current=a,f.current=g;return}let C=++p.current;m.current=!0;let w=!1;return(async()=>{try{for(let e of n){if(w||p.current!==C)break;let t=h(e);if(!(!t||!Yp(e))){for(let e of y){if(w)break;await s(t,e)}for(let e of b){if(w)break;await l(t,e)}for(let e of x){if(w)break;await c(t,e)}for(let e of S){if(w)break;await u(t,e)}}}}finally{p.current===C&&(d.current=a,f.current=g,m.current=!1)}})(),()=>{w=!0}},[e,t,n,o,r,s,c,l,u]),null}var Qp=768,$p=1024;function em(){let{setOpen:e,isMobile:t}=xr(),n=(0,Q.useRef)(e);(0,Q.useEffect)(()=>{n.current=e},[e]),(0,Q.useEffect)(()=>{if(t)return;let e=!1;function r(){let t=window.innerWidth,r=t>=Qp&&t<$p;r&&!e&&n.current(!1),e=r}return r(),window.addEventListener(`resize`,r),()=>window.removeEventListener(`resize`,r)},[t])}var tm=new Set([`view`,`record`,`page`,`dashboard`,`design`,`report`]);function nm(e){return e.replace(/[-_]/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function rm(e){try{return decodeURIComponent(e)}catch{return e}}function im({pathname:e,appName:t,objects:n=[],basePathSegment:r=`apps`,disabled:i=!1}){let{addRecentItem:a}=ja(),o=(0,Q.useRef)(n);o.current=n,(0,Q.useEffect)(()=>{if(i||!t)return;let n=e.split(`/`).filter(Boolean);if(n[0]!==r||n[1]!==t)return;let s=n[2],c=n[3],l=`/${r}/${t}`;if(s===`metadata`){let e=n[3],t=n[4];e&&t&&t!==`new`&&a({id:`metadata:${e}:${rm(t)}`,label:rm(t),href:`${l}/metadata/${e}/${t}`,type:`metadata`});return}if(s&&!tm.has(s)){let e=o.current.find(e=>e.name===s);e&&a({id:`object:${e.name}`,label:e.label||e.name,href:`${l}/${e.name}`,type:`object`});return}if(c)switch(s){case`dashboard`:a({id:`dashboard:${c}`,label:nm(c),href:`${l}/dashboard/${c}`,type:`dashboard`});break;case`page`:a({id:`page:${c}`,label:nm(c),href:`${l}/page/${c}`,type:`page`});break;case`report`:a({id:`report:${c}`,label:nm(c),href:`${l}/report/${c}`,type:`report`})}},[e,t,r,i])}function am(e){try{let t=window.localStorage.getItem(e),n=t?Number.parseInt(t,10):NaN;return Number.isFinite(n)&&n>0?n:420}catch{return 420}}function om(e){let{defaultExpanded:t=!1,persistExpandedKey:n,persistWidthKey:r=wd}=e??{},[i,a]=Q.useState(()=>n?jd(n,t):t),[o,s]=Q.useState(()=>am(r)),[c,l]=Q.useState(!1),[u,d]=Q.useState(!1),f=Q.useRef(!1),p=Q.useRef(null),m=Q.useRef(o);m.current=o;let h=Q.useCallback(e=>{a(t=>{let r=e(t);return n&&Md(n,r),r})},[n]),g=Q.useCallback(e=>{e.preventDefault(),f.current=!1,p.current=null,d(!1);let t=e.clientX,n=o;l(!0);let i=e=>{let r=Od(n+(t-e.clientX),window.innerWidth);s(r)},a=e=>{let o=Od(n+(t-e.clientX),window.innerWidth);try{window.localStorage.setItem(r,String(Math.round(o)))}catch{}l(!1),window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a)},[o]),_=Q.useCallback(()=>{f.current||(f.current=!0,p.current=m.current,s(kd(window.innerWidth)),d(!0))},[]),v=Q.useCallback(()=>{f.current&&(f.current=!1,s(p.current??am(r)),p.current=null,d(!1))},[r]);return{expanded:i,width:o,dragging:c,maximized:u,toggle:Q.useCallback(()=>h(e=>!e),[h]),expand:Q.useCallback(()=>h(()=>!0),[h]),collapse:Q.useCallback(()=>h(()=>!1),[h]),maximize:_,restore:v,onResizePointerDown:g}}function sm({userId:e,apiBase:t,defaultAgent:n,onCanvasOpenChange:r}){let{agents:i,isLoading:a,error:o}=So({apiBase:t}),s=Wd(),c=Q.useMemo(()=>Hd(`default`,{agents:i,appDefaultAgent:n,aiStudioEnabled:ps(),canAuthorMetadata:s}),[i,n,s]),l=c?`${t}/agents/${encodeURIComponent(c)}/chat`:void 0,u=c?_f({appId:void 0,product:gf(c)}):void 0,{conversationId:d,initialMessages:f}=pf({userId:c?e:void 0,scope:u,apiBase:t,activeId:void 0,forceNew:!1}),p=Q.useRef(null);return!a&&i.length===0?null:(0,$.jsx)(Sp,{agents:i,agentsLoading:a,agentsError:o,activeAgent:c,chatApi:l,apiBase:t,conversationId:d,initialMessages:f,pendingFirstMessageRef:p,onSent:()=>{},onShare:()=>{},showDebug:!1,onCanvasOpenChange:r},`${l??`local`}:${d??`pending`}`)}function cm({dock:e,userId:t,apiBase:n,defaultAgent:r,title:i,onMaximize:a,children:o}){let{t:s}=G(),c=Q.useMemo(()=>op(n),[n]),l=Q.useCallback(t=>t?e.maximize():e.restore(),[e.maximize,e.restore]);return(0,$.jsxs)(`aside`,{"data-testid":`chat-dock-panel`,style:{width:e.width},className:qr(`relative hidden h-full shrink-0 flex-col border-l bg-background md:flex`,!e.dragging&&`transition-[width] duration-200 ease-out`),children:[(0,$.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":s(`console.ai.dock.resize`,{defaultValue:`Resize chat`}),onPointerDown:e.onResizePointerDown,className:qr(`absolute left-0 top-0 z-10 h-full w-1 cursor-col-resize transition-colors hover:bg-primary/40`,e.dragging&&`bg-primary/50`)}),(0,$.jsxs)(`div`,{className:`flex h-11 shrink-0 items-center justify-between border-b px-3`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-xs font-semibold text-foreground/80`,children:[(0,$.jsx)(mi,{className:`size-3.5`}),i??s(`console.ai.dock.title`,{defaultValue:`Assistant`})]}),(0,$.jsxs)(`span`,{className:`flex items-center gap-0.5`,children:[(0,$.jsx)(Ip,{apiBase:c}),a?(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:a,"aria-label":s(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),title:s(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),"data-testid":`chat-dock-maximize`,children:(0,$.jsx)(Sr,{className:`h-3.5 w-3.5`})}):null,(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-7 w-7 text-muted-foreground hover:text-foreground`,onClick:e.collapse,"aria-label":s(`console.ai.dock.collapse`,{defaultValue:`Collapse chat`}),"data-testid":`chat-dock-collapse`,children:(0,$.jsx)(zn,{className:`h-4 w-4`})})]})]}),(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:o??(0,$.jsx)(sm,{userId:t,apiBase:c,defaultAgent:r,onCanvasOpenChange:l})})]})}function lm({open:e,onOpenChange:t,userId:n,apiBase:r,defaultAgent:i,title:a,onMaximize:o,children:s}){let{t:c}=G(),l=Q.useMemo(()=>op(r),[r]),u=Q.useRef(!1);return Q.useEffect(()=>{!e&&u.current&&(u.current=!1,o?.())},[e,o]),(0,$.jsx)(Bi,{open:e,onOpenChange:t,children:(0,$.jsxs)(Yi,{side:`bottom`,className:`flex h-[85svh] flex-col gap-0 p-0 md:hidden`,"data-testid":`chat-dock-mobile-sheet`,children:[(0,$.jsxs)(Ki,{className:`shrink-0 border-b px-4 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 pr-8`,children:[(0,$.jsxs)(Tn,{className:`inline-flex items-center gap-1.5 text-sm font-semibold`,children:[(0,$.jsx)(mi,{className:`size-4`}),a??c(`console.ai.dock.title`,{defaultValue:`Assistant`})]}),(0,$.jsx)(Ip,{apiBase:l}),o?(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-9 w-9 text-muted-foreground hover:text-foreground`,onClick:()=>{u.current=!0,t(!1)},"aria-label":c(`console.ai.dock.maximize`,{defaultValue:`Open full page`}),"data-testid":`chat-dock-mobile-maximize`,children:(0,$.jsx)(Sr,{className:`h-4 w-4`})}):null]}),(0,$.jsx)(hr,{className:`sr-only`,children:c(`console.ai.dock.description`,{defaultValue:`AI assistant chat`})})]}),(0,$.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:s??(0,$.jsx)(sm,{userId:n,apiBase:l,defaultAgent:i})})]})})}function um({onExpand:e,className:t}){let{t:n}=G();return(0,$.jsx)(J,{variant:`outline`,size:`icon`,onClick:e,"data-testid":`chat-dock-launcher`,"aria-label":n(`console.ai.dock.open`,{defaultValue:`Open assistant`}),title:n(`console.ai.dock.open`,{defaultValue:`Open assistant`}),className:qr(`fixed right-0 top-1/2 z-40 hidden h-16 w-7 -translate-y-1/2 rounded-l-md rounded-r-none border-r-0 bg-background shadow-md md:inline-flex`,t),children:(0,$.jsx)(mi,{className:`size-4`})})}var dm=new Set([`object`,`app`,`action`]);async function fm(){try{let e=await t(()=>import(`./dist-BpPy7hlB.js`),[],import.meta.url);return typeof e?.validateCapabilityReferences==`function`?e.validateCapabilityReferences:null}catch{return null}}async function pm(e,t,n){try{let r=n===void 0?await fm():n;if(!r)return[];let i=t.filter(e=>dm.has(e.type));if(i.length===0)return[];let a=e=>{let t=e?.item??e;return t&&typeof t==`object`?t:null},o=await Promise.all(i.map(t=>e.getDraft?.(t.type,t.name,t.packageId?{packageId:t.packageId}:void 0).then(a).catch(()=>null)??Promise.resolve(null))),s=await(e.list?.(`permission`,{}))?.then(e=>Array.isArray(e)?e.map(a).filter(Boolean):[]).catch(()=>[])??[],c=await Promise.all(t.filter(e=>e.type===`permission`).map(t=>e.getDraft?.(t.type,t.name,t.packageId?{packageId:t.packageId}:void 0).then(a).catch(()=>null)??Promise.resolve(null)));return r({objects:o.filter((e,t)=>e&&i[t].type===`object`),apps:o.filter((e,t)=>e&&i[t].type===`app`),actions:o.filter((e,t)=>e&&i[t].type===`action`),permissions:[...s,...c.filter(Boolean)]}).filter(e=>e&&e.severity===`warning`).map(e=>`${e.where}: ${e.message}`)}catch{return[]}}function mm(e){let t=oa(),[n,r]=(0,Q.useState)(!1);return{publishAll:(0,Q.useCallback)(async()=>{r(!0);try{let n=(await t.listDrafts?.({})||[]).filter(e=>e&&typeof e.type==`string`&&typeof e.name==`string`).map(e=>({type:e.type,name:e.name,packageId:typeof e.packageId==`string`&&e.packageId?e.packageId:null}));if(n.length===0)return X.info(e(`home.pendingDrafts.nothing`,{defaultValue:`Nothing to publish.`})),{ok:!0,attempted:0};let r=await pm(t,n),i=[...new Set(n.map(e=>e.packageId).filter(e=>e!==null))],a=n.filter(e=>e.packageId===null),o=[],s=[],c=0,l=e=>{if(e){e.seedError&&o.push(e.seedError),typeof e.seededRows==`number`&&(c+=e.seededRows);for(let t of e.issues??[])t.severity===`error`&&s.push(t.message)}};for(let e of i){let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);l(To(n))}let u=[...a.filter(e=>e.type!==`seed`),...a.filter(e=>e.type===`seed`)];for(let e of u){let n=(await t.publishDraft(e.type,e.name))?.seedApplied;n&&n.success===!1&&o.push(n.error??`${e.name}: sample data failed to load`)}return s.length>0?X.warning(e(`home.pendingDrafts.probeWarn`,{defaultValue:`Published, but verification found problems.`}),{description:s[0]}):o.length>0?X.warning(e(`home.pendingDrafts.seedWarn`,{defaultValue:`Published, but some sample data failed to load.`}),{description:o[0]}):X.success(c>0?e(`home.pendingDrafts.publishedVerified`,{count:c,defaultValue:`Published & verified — {{count}} sample row(s) live.`}):e(`home.pendingDrafts.published`,{defaultValue:`Published! Your changes are live.`})),r.length>0&&X.warning(e(`home.pendingDrafts.capabilityWarn`,{count:r.length,defaultValue:`Authoring check: {{count}} capability reference(s) resolve nowhere.`}),{description:r[0],duration:1e4}),ba(),{ok:!0,attempted:n.length}}catch(t){return X.error(`${e(`home.pendingDrafts.publishFailed`,{defaultValue:`Publish failed`})}: ${t.message}`),{ok:!1,attempted:0}}finally{r(!1)}},[t,e]),publishing:n}}var hm=Q.createContext(null);function gm({onRequest:e,children:t}){let[n,r]=Q.useState(null),i=Q.useRef(0),a=Q.useRef(e);Q.useEffect(()=>{a.current=e});let o=Q.useCallback(e=>{a.current?.(e)!==!1&&(i.current+=1,r({target:e,id:i.current}))},[]),s=Q.useMemo(()=>({requested:n,request:o}),[n,o]);return Q.createElement(hm.Provider,{value:s},t)}function _m(){return Q.useContext(hm)?.request??null}function vm(){return Q.useContext(hm)?.requested??null}async function ym(){try{let e=await t(()=>import(`./dist-BpPy7hlB.js`),[],import.meta.url);return typeof e?.validateSecurityPosture==`function`?e.validateSecurityPosture:null}catch{return null}}async function bm(e,t,n){try{let r=n===void 0?await ym():n;if(!r)return[];let i=t.filter(e=>e.type===`object`);if(i.length===0)return[];let a=e=>{let t=e?.item??e;return t&&typeof t==`object`?t:null},o=await Promise.all(i.map(t=>e.getDraft?.(t.type,t.name,t.packageId?{packageId:t.packageId}:void 0).then(a).catch(()=>null)??Promise.resolve(null))),s=[];for(let e=0;e<o.length;e++){let t=o[e];t&&s.push({draft:i[e],body:t})}return s.length===0?[]:r({objects:s.map(e=>e.body)}).filter(e=>e&&e.severity===`error`).map(e=>{let t=Number(/^objects\[(\d+)\]/.exec(e.path??``)?.[1]??NaN),n=Number.isInteger(t)?s[t]:s.find(t=>typeof e.where==`string`&&e.where.includes(String(t.draft.name)));return{type:n?.draft.type??`object`,name:n?.draft.name??``,rule:e.rule,hint:e.hint??``,message:e.message??``}}).filter(e=>e.name!==``)}catch{return[]}}async function xm(e){return(await Yu(e)).map(e=>({type:P(e.type),name:e.name,packageId:e.packageId}))}async function Sm(e){let t=await fetch(`/api/v1/meta/${encodeURIComponent(e)}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok)throw Error(`published list HTTP ${t.status}`);let n=await t.json(),r=Array.isArray(n)?n:n?.items??[];return new Set(r.map(e=>typeof e?.name==`string`?e.name:null).filter(e=>e!==null))}function Cm(e){if(!e||typeof e!=`object`)return null;let t=e;return t.item&&typeof t.item==`object`?t.item:t}async function wm(e,t,n={}){let r=[];n.draft&&r.push(`state=draft`),n.packageId&&r.push(`package=${encodeURIComponent(n.packageId)}`);let i=r.length?`?${r.join(`&`)}`:``,a=await fetch(`/api/v1/meta/${encodeURIComponent(e)}/${encodeURIComponent(t)}${i}`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(a.status===404)return null;if(!a.ok)throw Error(`HTTP ${a.status}`);return Cm(await a.json())}function Tm(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}function Em(e,t){let n=e??{},r=t??{},i=null;if(n.fields!=null||r.fields!=null){let e=cc(n.fields,r.fields);i={added:Object.values(e.byName).filter(e=>e.status===`added`).map(e=>e.name).sort(),changed:Object.values(e.byName).filter(e=>e.status===`changed`).map(e=>({name:e.name,keys:e.changedKeys})).sort((e,t)=>e.name.localeCompare(t.name)),removed:e.removed.map(e=>e.name).sort()}}let a=new Set([...Object.keys(n),...Object.keys(r)]);a.delete(`fields`);let o=[...a].filter(e=>!Tm(n[e],r[e])).sort();return{fields:i,changedKeys:o}}function Dm({entry:e}){let{t}=G(),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(null);if((0,Q.useEffect)(()=>{let t=!1;return(async()=>{try{let[n,i]=await Promise.all([wm(e.type,e.name,{packageId:e.packageId}),wm(e.type,e.name,{draft:!0,packageId:e.packageId})]);t||r(Em(n,i))}catch(e){t||a(e.message)}})(),()=>{t=!0}},[e.type,e.name,e.packageId]),i)return(0,$.jsxs)(`p`,{className:`px-2 py-1 text-xs text-destructive`,children:[t(`preview.changes.detailLoadFailed`,{defaultValue:`Could not load change detail:`}),` `,i]});if(!n)return(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 px-2 py-1 text-xs text-muted-foreground`,children:[(0,$.jsx)(Y,{className:`h-3 w-3 animate-spin`}),t(`preview.changes.detailLoading`,{defaultValue:`Loading detail…`})]});let{fields:o,changedKeys:s}=n;return!(o&&(o.added.length>0||o.changed.length>0||o.removed.length>0))&&s.length===0?(0,$.jsx)(`p`,{className:`px-2 py-1 text-xs text-muted-foreground`,children:t(`preview.changes.detailNone`,{defaultValue:`No differences detected — the draft matches the published version.`})}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-0.5 px-2 py-1`,"data-testid":`draft-entry-detail`,children:[o?.added.map(e=>(0,$.jsxs)(`p`,{className:`font-mono text-xs text-emerald-700 dark:text-emerald-400`,children:[`+ `,e]},`+${e}`)),o?.changed.map(e=>(0,$.jsxs)(`p`,{className:`font-mono text-xs text-amber-700 dark:text-amber-400`,children:[`~ `,e.name,e.keys.length>0&&(0,$.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,e.keys.join(`, `)]})]},`~${e.name}`)),o?.removed.map(e=>(0,$.jsxs)(`p`,{className:`font-mono text-xs text-red-700 line-through dark:text-red-400`,children:[`− `,e]},`-${e}`)),s.length>0&&(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[t(`preview.changes.detailChangedKeys`,{defaultValue:`Also changed:`}),` `,(0,$.jsx)(`span`,{className:`font-mono`,children:s.join(`, `)})]})]})}function Om({open:e,onOpenChange:t,packageId:n,onPublish:r,publishing:i=!1}){let{t:a}=G(),[o,s]=(0,Q.useState)(null),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)([]),f=_m(),[p,m]=(0,Q.useState)(new Set),h=(0,Q.useCallback)(e=>{m(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),g=(0,Q.useCallback)(async()=>{s(null),l(null),d([]);try{let e=await xm(n);s(e),bm({getDraft:(e,t,r)=>wm(e,t,{draft:!0,packageId:r?.packageId??n??null})},e).then(d,()=>d([]));let t=[...new Set(e.map(e=>e.type))];await Promise.all(t.map(async e=>{let t=null;try{t=await Sm(e)}catch{return}s(n=>n&&n.map(n=>n.type===e?{...n,kind:t.has(n.name)?`update`:`new`}:n))}))}catch(e){l(e.message)}},[n]);(0,Q.useEffect)(()=>{e&&g()},[e,g]),(0,Q.useEffect)(()=>{e&&X.dismiss()},[e]);let _=new Map;for(let e of o??[]){let t=_.get(e.type)??[];t.push(e),_.set(e.type,t)}return(0,$.jsx)(Bi,{open:e,onOpenChange:t,children:(0,$.jsxs)(Yi,{side:`right`,className:`flex w-[420px] flex-col sm:max-w-[420px]`,"data-testid":`draft-changes-panel`,children:[(0,$.jsxs)(Ki,{children:[(0,$.jsx)(Tn,{children:a(`preview.changes.title`,{defaultValue:`Pending changes`})}),(0,$.jsx)(hr,{children:a(`preview.changes.description`,{defaultValue:`What publishing will change. New items are added; updates overwrite the live version.`})})]}),(0,$.jsx)(`div`,{"data-testid":`draft-changes-list`,className:`mt-4 flex min-h-0 flex-1 flex-col gap-4 overflow-y-auto px-4 pb-6`,children:c?(0,$.jsxs)(`p`,{className:`text-sm text-destructive`,children:[a(`preview.changes.loadFailed`,{defaultValue:`Could not load pending changes:`}),` `,c]}):o===null?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(Y,{className:`h-4 w-4 animate-spin`}),a(`preview.changes.loading`,{defaultValue:`Loading pending changes…`})]}):o.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:a(`preview.changes.empty`,{defaultValue:`Nothing pending — every draft has been published.`})}):[..._.entries()].map(([e,t])=>(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`h4`,{className:`mb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground`,children:[e,` · `,t.length]}),(0,$.jsx)(`ul`,{className:`flex flex-col gap-1`,children:t.map(e=>{let t=`${e.type}:${e.name}`,n=p.has(t);return(0,$.jsxs)(`li`,{className:`rounded-md border text-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>h(t),"aria-expanded":n,className:`flex w-full items-center gap-2 px-2.5 py-1.5 text-left hover:bg-muted/50`,"data-testid":`draft-entry-toggle`,children:[n?(0,$.jsx)(zr,{className:`h-3 w-3 shrink-0 text-muted-foreground`}):(0,$.jsx)(gi,{className:`h-3 w-3 shrink-0 text-muted-foreground`}),e.kind===`new`?(0,$.jsx)(Ur,{className:`h-3.5 w-3.5 shrink-0 text-emerald-600`}):e.kind===`update`?(0,$.jsx)(Rr,{className:`h-3.5 w-3.5 shrink-0 text-amber-600`}):(0,$.jsx)(Y,{className:`h-3.5 w-3.5 shrink-0 animate-spin text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs`,children:e.name}),e.kind?(0,$.jsx)(hn,{variant:`outline`,className:e.kind===`new`?`border-emerald-200 bg-emerald-50 text-emerald-700`:`border-amber-200 bg-amber-50 text-amber-700`,children:e.kind===`new`?a(`preview.changes.kindNew`,{defaultValue:`New`}):a(`preview.changes.kindUpdate`,{defaultValue:`Update`})}):null]}),n&&(0,$.jsx)(`div`,{className:`border-t bg-muted/20`,children:(0,$.jsx)(Dm,{entry:e})})]},t)})})]},e))}),u.length>0&&!c&&(0,$.jsxs)(`div`,{"data-testid":`draft-security-problems`,className:`mt-auto border-t border-amber-200 bg-amber-50 px-4 py-3 dark:border-amber-900/60 dark:bg-amber-950/30`,children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs font-medium text-amber-800 dark:text-amber-300`,children:[(0,$.jsx)(Tr,{className:`h-3.5 w-3.5 shrink-0`}),a(`preview.changes.securityBlockTitle`,{count:u.length,defaultValue:`Publishing will be refused — {{count}} item(s) need a decision first`})]}),(0,$.jsx)(`ul`,{className:`mt-1.5 flex flex-col gap-1.5`,children:u.map(e=>(0,$.jsxs)(`li`,{className:`text-[11px] leading-5 text-amber-900 dark:text-amber-200`,children:[f?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>f({type:e.type,name:e.name}),className:`font-mono underline decoration-dotted underline-offset-2 hover:text-amber-950 dark:hover:text-amber-100`,children:[e.type,`/`,e.name]}):(0,$.jsxs)(`span`,{className:`font-mono`,children:[e.type,`/`,e.name]}),` `,`— `,e.hint||e.message]},`${e.type}:${e.name}:${e.rule}`))}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] text-amber-800/80 dark:text-amber-300/80`,children:a(`preview.changes.securityBlockWhere`,{defaultValue:`Fix it on the object under Settings → Record sharing, then publish again.`})})]}),r&&(o?.length??0)>0&&!c&&(0,$.jsxs)(`div`,{className:`mt-auto flex flex-col gap-2 border-t px-4 py-3`,children:[(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a(`preview.changes.confirmNote`,{count:o.length,defaultValue:`Publishing releases all {{count}} pending drafts of this package atomically.`})}),(0,$.jsxs)(J,{size:`sm`,onClick:()=>void r(),disabled:i,"data-testid":`draft-changes-publish`,children:[i?(0,$.jsx)(Y,{className:`mr-1.5 h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(ri,{className:`mr-1.5 h-3.5 w-3.5`}),a(`preview.changes.publishConfirm`,{defaultValue:`Publish all`})]})]})]})})}function km(){let e=sa(),t=o(),n=p(),{t:r}=G(),{publishAll:i,publishing:a}=mm(r),[s,c]=(0,Q.useState)(!1),{count:l,refresh:u}=Xu({enabled:!!e});if((0,Q.useEffect)(()=>{e&&u()},[e,t.pathname,u]),!e)return null;let d=()=>{ra();let e=new URLSearchParams(t.search);e.delete(ia);let r=e.toString();n(`${t.pathname}${r?`?${r}`:``}${t.hash}`,{replace:!0})},f=async()=>{(await i()).ok&&(d(),setTimeout(()=>{try{window.location.reload()}catch{}},300))},m=l===0;return(0,$.jsxs)(`div`,{className:qr(`sticky top-0 z-40 border-b`,m?`border-slate-200 bg-slate-50 text-slate-700 dark:border-slate-700/60 dark:bg-slate-900/40 dark:text-slate-300`:`border-amber-300/70 bg-amber-50 text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/40 dark:text-amber-200`),"data-testid":`draft-preview-bar`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 px-4 py-2 text-sm`,children:[(0,$.jsx)(Dn,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:m?r(`preview.draftBar.messageClean`,{defaultValue:`Draft preview — no unpublished changes; everything here is already live.`}):r(`preview.draftBar.message`,{defaultValue:`Draft preview — you are seeing unpublished changes. Nothing here is live until you publish.`})}),!m&&(0,$.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>c(!0),"data-testid":`draft-preview-changes`,children:[(0,$.jsx)(er,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.changes`,{defaultValue:`Changes`}),typeof l==`number`?` (${l})`:``]}),(0,$.jsxs)(J,{size:`sm`,variant:`outline`,onClick:d,"data-testid":`draft-preview-exit`,children:[(0,$.jsx)(ci,{className:`mr-1 h-3.5 w-3.5`}),r(`preview.draftBar.exit`,{defaultValue:`Exit preview`})]})]}),!m&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 border-t border-amber-300/50 px-4 py-2.5 dark:border-amber-700/40`,"data-testid":`draft-preview-sample-hint`,children:[(0,$.jsx)(Jt,{className:`h-5 w-5 shrink-0 text-amber-600 dark:text-amber-300`,"aria-hidden":`true`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold leading-tight`,children:r(`preview.draftBar.sampleDataTitle`,{defaultValue:`Sample data appears once you publish`})}),(0,$.jsx)(`p`,{className:`text-xs leading-snug text-amber-800/80 dark:text-amber-200/70`,children:r(`preview.draftBar.sampleDataBody`,{defaultValue:`You’re previewing your app’s structure. Publish to load example records and make it live.`})})]}),(0,$.jsxs)(J,{onClick:f,disabled:a,"data-testid":`draft-preview-publish`,className:`shrink-0 shadow-sm`,children:[(0,$.jsx)(ri,{className:`mr-1.5 h-4 w-4`}),a?r(`preview.draftBar.publishing`,{defaultValue:`Publishing…`}):r(`preview.draftBar.publishCta`,{defaultValue:`Publish to see it live`})]})]}),(0,$.jsx)(Om,{open:s,onOpenChange:c})]})]})}var Am=class extends Error{status;code;retryable;constructor(e,t){super(e),this.name=`CommitStoreError`,this.status=t.status,this.code=t.code??null,this.retryable=t.retryable}};function jm(e){return typeof e==`object`&&!!e&&e.retryable===!0}function Mm(e){let t=e?.error;if(typeof t==`string`)return{code:null,message:t.trim()||null};if(!t||typeof t!=`object`)return{code:null,message:null};let n=t,r=e=>typeof e==`string`&&e.trim()?e:null;return{code:r(n.code),message:r(n.message)}}function Nm(e,t,n){let{code:r,message:i}=Mm(t),a=e===503||r===`SERVICE_UNAVAILABLE`;return new Am(a?`Commit store temporarily unreachable (HTTP ${e}) — the request did not reach it.`:i??n,{status:e,code:r,retryable:a})}async function Pm(e){let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/commits`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`});if(!t.ok){let e=await t.json().catch(()=>null);throw Nm(t.status,e,`commits HTTP ${t.status}`)}let n=await t.json(),r=Array.isArray(n)?n:n?.commits??n?.data?.commits??[];return(Array.isArray(r)?r:[]).map(e=>{let t=e;return{id:String(t.id),operation:t.operation===`revert`?`revert`:`apply`,message:typeof t.message==`string`?t.message:void 0,actor:typeof t.actor==`string`?t.actor:void 0,aiModel:typeof t.aiModel==`string`?t.aiModel:void 0,itemCount:typeof t.itemCount==`number`?t.itemCount:0,createdAt:typeof t.createdAt==`string`?t.createdAt:void 0}})}async function Fm(e,t){let n=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/commits/${encodeURIComponent(t)}/revert`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),r=await n.json().catch(()=>null),i=r?.data??r??void 0;if(!n.ok||i?.success===!1)throw Nm(n.status,r,`HTTP ${n.status}`)}function Im(e){if(!e)return``;let t=Date.parse(e);if(Number.isNaN(t))return``;let n=Math.max(0,Math.round((Date.now()-t)/1e3));if(n<60)return`${n}s`;let r=Math.round(n/60);if(r<60)return`${r}m`;let i=Math.round(r/60);return i<24?`${i}h`:`${Math.round(i/24)}d`}function Lm({open:e,onOpenChange:t,packageId:n,onReverted:r}){let{t:i}=G(),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(null),[l,u]=(0,Q.useState)(null),d=(0,Q.useCallback)(async()=>{o(null),c(null);try{o(await Pm(n))}catch(e){c({message:e.message,unreachable:jm(e)})}},[n]);(0,Q.useEffect)(()=>{e&&d()},[e,d]);let f=async e=>{u(e);try{await Fm(n,e),X.success(i(`preview.history.reverted`,{defaultValue:`Reverted — the change has been undone.`})),r?.(),await d()}catch(e){X.error(jm(e)?i(`preview.history.revertUnavailable`,{defaultValue:`Commit store temporarily unreachable — the revert may not have been applied. Reopen this history to check before retrying.`}):`${i(`preview.history.revertFailed`,{defaultValue:`Revert failed`})}: ${e.message}`)}finally{u(null)}};return(0,$.jsx)(Bi,{open:e,onOpenChange:t,children:(0,$.jsxs)(Yi,{side:`right`,className:`w-[420px] sm:max-w-[420px]`,"data-testid":`commit-timeline-panel`,children:[(0,$.jsxs)(Ki,{children:[(0,$.jsx)(Tn,{children:i(`preview.history.title`,{defaultValue:`Build history`})}),(0,$.jsx)(hr,{children:i(`preview.history.description`,{defaultValue:`Every change to this app, newest first. Revert any step to undo it — no publish confirmation needed.`})})]}),(0,$.jsx)(`div`,{className:`mt-4 flex flex-col gap-2 overflow-y-auto px-4 pb-6`,children:s?(0,$.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`commit-history-error`,children:s.unreachable?i(`preview.history.loadFailedUnavailable`,{defaultValue:`Commit store temporarily unreachable — this read did not happen, so no history is shown. Retry in a moment.`}):`${i(`preview.history.loadFailed`,{defaultValue:`Could not load history:`})} ${s.message}`}):a===null?(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(Y,{className:`h-4 w-4 animate-spin`}),i(`preview.history.loading`,{defaultValue:`Loading history…`})]}):a.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i(`preview.history.empty`,{defaultValue:`No history yet for this app.`})}):a.map(e=>(0,$.jsxs)(`div`,{className:`flex items-start gap-2.5 rounded-md border px-2.5 py-2 text-sm`,"data-testid":`commit-row`,children:[(0,$.jsx)(rr,{className:`mt-0.5 h-4 w-4 shrink-0 ${e.operation===`revert`?`text-muted-foreground`:`text-primary`}`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`truncate font-medium`,children:e.message??(e.operation===`revert`?i(`preview.history.revertLabel`,{defaultValue:`Reverted a change`}):i(`preview.history.applyLabel`,{defaultValue:`Build change`}))}),(0,$.jsxs)(`p`,{className:`mt-0.5 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[e.operation===`revert`?(0,$.jsx)(hn,{variant:`outline`,className:`border-muted-foreground/30`,children:i(`preview.history.revert`,{defaultValue:`revert`})}):null,(0,$.jsxs)(`span`,{children:[e.itemCount,` `,i(`preview.history.items`,{defaultValue:`item(s)`})]}),e.actor?(0,$.jsxs)(`span`,{children:[`· `,e.actor]}):null,e.createdAt?(0,$.jsxs)(`span`,{children:[`· `,Im(e.createdAt)]}):null]})]}),e.operation===`apply`?(0,$.jsx)(J,{size:`sm`,variant:`ghost`,className:`shrink-0`,disabled:l!==null,onClick:()=>f(e.id),"data-testid":`commit-revert`,children:l===e.id?(0,$.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(or,{className:`mr-1 h-3.5 w-3.5`}),i(`preview.history.revertAction`,{defaultValue:`Revert`})]})}):null]},e.id))})]})})}function Rm(){let e=sa(),{appName:t}=c(),n=o(),{apps:r,refresh:i}=be(),{t:a}=G(),[s,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1);if(e)return null;let f=t??n.pathname.match(/\/apps\/([^/?#]+)/)?.[1];if(!f)return null;let p=so(r??[],f);if(!p||p._unpublished!==!0)return null;let m=p?.packageId??p?._packageId??null;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`sticky top-0 z-40 flex items-center gap-3 border-b border-amber-300/70 bg-amber-50 px-4 py-2 text-sm text-amber-900 dark:border-amber-700/60 dark:bg-amber-950/40 dark:text-amber-200`,"data-testid":`unpublished-app-bar`,children:[(0,$.jsx)(St,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`p`,{className:`min-w-0 flex-1 truncate`,children:a(`preview.unpublishedBar.message`,{defaultValue:`Unpublished app — fully functional, but only builders can see it. Publish to make it visible to your users.`})}),m?(0,$.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>d(!0),"data-testid":`unpublished-app-history`,children:[(0,$.jsx)(hi,{className:`mr-1 h-3.5 w-3.5`}),a(`preview.history.button`,{defaultValue:`History`})]}):null,(0,$.jsxs)(J,{size:`sm`,onClick:async()=>{l(!0);try{let e=await fetch(`/api/v1/meta/app/${encodeURIComponent(f)}`,{method:`PUT`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:JSON.stringify({...p,_unpublished:!1})});if(!e.ok){let t=await e.json().catch(()=>null);throw Error(t?.error?.message??t?.error??`HTTP ${e.status}`)}X.success(a(`preview.unpublishedBar.published`,{defaultValue:`Published! The app is now visible to your users.`})),i?.()}catch(e){X.error(`${a(`preview.unpublishedBar.publishFailed`,{defaultValue:`Publish failed`})}: ${e.message}`)}finally{l(!1)}},disabled:s,"data-testid":`unpublished-app-publish`,children:[(0,$.jsx)(ri,{className:`mr-1 h-3.5 w-3.5`}),s?a(`preview.unpublishedBar.publishing`,{defaultValue:`Publishing…`}):a(`preview.unpublishedBar.publish`,{defaultValue:`Publish`})]})]}),m?(0,$.jsx)(Lm,{open:u,onOpenChange:d,packageId:m,onReverted:i}):null]})}function zm(){return Fe()?(0,$.jsx)(ct,{}):null}zm.displayName=`ConsoleNotificationBanners`;var Bm=`__all__`,Vm=`active_package`,Hm=new Map([[Vm,`package`]]);function Um(e){return Hm.get(e)??e}function Wm(e){return e.persist??`query`}function Gm(e,t){return`objectui-ctx-${e}-${t}`}function Km(e,t){let n={};for(let r of t)if(Wm(r)===`session`)try{let t=sessionStorage.getItem(Gm(e,r.id));t&&(n[r.id]=t)}catch{}return n}function qm(e,t){if(t)return t.split(`.`).reduce((e,t)=>e==null?e:e[t],e)}function Jm(e){if(Array.isArray(e))return e;let t=e?.data??e;return Array.isArray(t)?t:Array.isArray(t?.packages)?t.packages:Array.isArray(t?.items)?t.items:Array.isArray(e?.items)?e.items:[]}function Ym(e,t){if(!t||t.length===0)return!0;for(let n of t){let t=qm(e,n.key),r=n.op??`eq`,i=Array.isArray(n.value)?n.value:[n.value];switch(r){case`eq`:if(t!==n.value)return!1;break;case`ne`:if(t===n.value)return!1;break;case`in`:if(!i.includes(t))return!1;break;case`nin`:if(i.includes(t))return!1}}return!0}function Xm(e){let[t,n]=Q.useState([]),r=e.optionsSource.endpoint,i=e.optionsSource.valueKey||`id`,a=e.optionsSource.labelKey||`name`,o=e.optionsSource.filter,s=JSON.stringify(o??[]),c=Q.useCallback(async()=>{try{let e=await fetch(r,{credentials:`include`,headers:{Accept:`application/json`}});if(!e.ok)return;let t=Jm(await e.json()),s=[],c=new Set;for(let e of t){if(!Ym(e,o))continue;let t=qm(e,i);if(t==null||typeof t!=`string`||c.has(t))continue;c.add(t);let n=qm(e,a);s.push({value:t,label:typeof n==`string`&&n?n:t})}s.sort((e,t)=>e.label.localeCompare(t.label)),n(s)}catch{}},[r,i,a,s]);return Q.useEffect(()=>{c();let e=()=>{c()};return window.addEventListener(`objectui:packages-changed`,e),()=>window.removeEventListener(`objectui:packages-changed`,e)},[c]),{options:t,refetch:c}}function Zm(e,t,n){let r=Array.isArray(t)?t:[],i=p(),a=o(),s=new URLSearchParams(a.search),[c,l]=Q.useState(()=>Km(e,r));Q.useEffect(()=>{let t=Km(e,r);Object.keys(t).length!==0&&l(e=>{let n;for(let[r,i]of Object.entries(t))e[r]===void 0&&(n??={...e},n[r]=i);return n??e})},[e,r]);let u=Q.useCallback((t,n)=>{let r=n===Bm?t.allValue??``:n,o=Wm(t);if(o!==`query`){if(l(e=>e[t.id]===r?e:{...e,[t.id]:r}),o===`session`)try{let n=Gm(e,t.id);r?sessionStorage.setItem(n,r):sessionStorage.removeItem(n)}catch{}return}let s=new URLSearchParams(a.search),c=Um(t.id);r?s.set(c,r):s.delete(c),i({pathname:a.pathname,search:s.toString()},{replace:!0})},[e,a.pathname,a.search,i]);Q.useEffect(()=>{},[r]);let d={};for(let e of r){let t=Wm(e)===`query`?s.get(Um(e.id))??``:c[e.id]??``;d[e.id]=t||(e.allValue??``)}return{contextValues:d,element:r.length===0?null:(0,$.jsx)(`div`,{className:`flex flex-col gap-1.5`,children:r.map(e=>(0,$.jsx)(Qm,{def:e,value:d[e.id],onChange:t=>u(e,t),t:n},e.id))})}}function Qm({def:e,value:t,onChange:n,t:r}){let{options:i,refetch:a}=Xm(e),o=qs(e.icon),s=ys(e.label,r)||e.id,c=s===`Package`?r?.(`common.package`,{defaultValue:`Package`})??s:s,l=r?.(`actionDialog.selectPlaceholder`,{label:c,defaultValue:`Select ${c}…`})??`Select ${c}…`,u=!!t&&t!==(e.allValue??``);return Q.useLayoutEffect(()=>{u||i.length>0&&n(i[0].value)},[u,n,i]),(0,$.jsxs)(Wi,{value:u?t:``,onValueChange:n,onOpenChange:e=>{e&&a()},children:[(0,$.jsx)(Tt,{"aria-label":c,"data-testid":`package-switcher`,className:`h-9 w-full gap-2 rounded-md border-sidebar-border/70 bg-sidebar/80 px-2 text-xs font-medium text-sidebar-foreground shadow-none transition-colors hover:bg-sidebar-accent focus:ring-1 focus:ring-sidebar-ring data-[state=open]:bg-sidebar-accent [&>svg]:h-3.5 [&>svg]:w-3.5 [&>svg]:shrink-0`,children:(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-2 overflow-hidden`,children:[(0,$.jsx)(`span`,{className:`flex h-5 w-5 shrink-0 items-center justify-center rounded border border-sidebar-border/70 bg-sidebar-accent text-sidebar-foreground/70`,children:(0,$.jsx)(o,{className:`h-3 w-3`})}),(0,$.jsx)(sn,{placeholder:l,className:`truncate`})]})}),(0,$.jsx)(An,{className:`w-[var(--radix-select-trigger-width)]`,children:i.map(e=>(0,$.jsx)(Dt,{value:e.value,children:e.label},e.value))})]})}function $m(e){let t=`objectui-nav-order-${e}`,[n,r]=Q.useState(()=>{try{let e=localStorage.getItem(t);if(!e)return{};let n=JSON.parse(e);if(typeof n!=`object`||!n||Array.isArray(n))return{};let r={};for(let[e,t]of Object.entries(n))Array.isArray(t)&&t.every(e=>typeof e==`string`)&&(r[e]=t);return r}catch{return{}}}),i=Q.useCallback(e=>{r(e);try{localStorage.setItem(t,JSON.stringify(e))}catch{}},[t]);return{applyOrder:Q.useCallback(e=>{let t=n.__root__;if(!t)return e;let r=new Map(e.map(e=>[e.id,e])),i=[];for(let e of t){let t=r.get(e);t&&(i.push(t),r.delete(e))}return r.forEach(e=>i.push(e)),i},[n]),handleReorder:Q.useCallback(e=>{let t=e.map(e=>e.id);i({...n,__root__:t})},[n,i])}}function eh(e){return e.componentRef===`metadata:directory`}function th(e){return e.componentRef===`developer:packages`}function nh(e){if(e.type!==`group`)return!1;let t=String(e.id??``).toLowerCase(),n=typeof e.label==`string`?e.label.toLowerCase():``;return t===`overview`||n===`overview`}function rh({activeAppName:e}){let{isMobile:t,setOpenMobile:r}=xr(),i=o(),{t:a,language:s}=G(),{objectLabel:c,dashboardLabel:l,viewLabel:u}=at(),{context:d,currentAppName:f}=Ra(),{user:p,activeOrganization:m}=C(),{isAdmin:h}=w(),g=Ko();Q.useEffect(()=>{let e=0,n=t=>{e=t.touches[0].clientX},i=n=>{let i=n.changedTouches[0].clientX-e;e<30&&i>50&&t&&r(!0)};return document.addEventListener(`touchstart`,n,{passive:!0}),document.addEventListener(`touchend`,i,{passive:!0}),()=>{document.removeEventListener(`touchstart`,n),document.removeEventListener(`touchend`,i)}},[t,r]);let{recentItems:_}=ja(),{favorites:v,removeFavorite:y}=ao(),{apps:b,objects:x}=be(),S=b||[],T=_d(),E=S.filter(e=>e.active!==!1&&e.hidden!==!0),D=so(S.filter(e=>e.active!==!1),e||f)||E[0],{applyOrder:k,handleReorder:A}=$m(D?.name||`home`),{togglePin:j,applyPins:M}=Bp(),{evaluator:ee}=xa(),N=Q.useCallback(e=>wa(e,ee),[ee]),{can:te,hasCapabilities:P}=O(),F=Q.useCallback(e=>e.every(e=>{let t=e.split(`:`);return t.length>=2?te(t[0],t[1]):P([e])||te(e,`read`)}),[te,P]),ne=Q.useMemo(()=>new Set((x||[]).map(e=>e?.name).filter(Boolean)),[x]),re=Q.useCallback((e,t)=>e!==`object`||ne.size===0||ne.has(t),[ne]),I=(D?.areas||[]).filter(e=>xs(e.navigation,{evaluateVisibility:N,checkPermission:F,checkCapability:re,hasActionHandler:!!g})),[L,ae]=Q.useState(()=>I.length>0?I[0].id:null),oe=I.map(e=>e.id).join(`,`);Q.useEffect(()=>{I.length>0?ae(e=>I.some(t=>t.id===e)?e:I[0].id):ae(null)},[D?.name,oe]);let R=I.find(e=>e.id===L)??I[0],se=R?.navigation||D?.navigation||[],{contextValues:z,element:B}=Zm(D?.name||`home`,D?.contextSelectors,a),ce=Q.useMemo(()=>{let e=[{id:`home-dashboard`,label:a(`home.nav`,{defaultValue:`Home`}),type:`url`,url:T,icon:`home`},{id:`docs`,label:a(`layout.systemNav.documentation`,{defaultValue:`Documentation`}),type:`url`,url:`/docs`,icon:`book-open`}];if(h){let t=[{id:`sys-settings`,label:a(`layout.systemNav.systemSettings`,{defaultValue:`System Settings`}),type:`url`,url:`/apps/setup/system`,icon:`settings`},{id:`sys-apps`,label:a(`layout.systemNav.applications`,{defaultValue:`Applications`}),type:`url`,url:`/apps/setup/system/apps`,icon:`layout-grid`},{id:`sys-marketplace`,label:a(`layout.systemNav.appMarketplace`,{defaultValue:`App Marketplace`}),type:`url`,url:`/apps/setup/system/marketplace`,icon:`store`},{id:`sys-objects`,label:a(`layout.systemNav.objectManager`,{defaultValue:`Object Manager`}),type:`url`,url:`/apps/setup/metadata/object`,icon:`database`},{id:`sys-datasources`,label:a(`layout.systemNav.datasources`,{defaultValue:`Datasources`}),type:`url`,url:`/apps/setup/metadata/datasource`,icon:`database`},{id:`sys-users`,label:a(`layout.systemNav.users`,{defaultValue:`Users`}),type:`url`,url:`/apps/setup/system/users`,icon:`users`},{id:`sys-orgs`,label:a(`layout.systemNav.organizations`,{defaultValue:`Organizations`}),type:`url`,url:`/apps/setup/system/organizations`,icon:`building-2`},{id:`sys-roles`,label:a(`layout.systemNav.roles`,{defaultValue:`Roles`}),type:`url`,url:`/apps/setup/system/roles`,icon:`shield`},{id:`sys-config`,label:a(`layout.systemNav.configuration`,{defaultValue:`Configuration`}),type:`url`,url:`/apps/setup/system/settings`,icon:`sliders-horizontal`}];e.push({id:`sys-administration`,label:a(`layout.systemNav.administration`,{defaultValue:`Administration`}),type:`group`,icon:`shield`,expanded:!0,children:t})}return e},[a,h,T]),le=d===`home`?ce:se,ue=d===`app`&&D?`/apps/${fo(D)}`:``,de=d===`app`&&D?.name===`studio`,fe=Um(Vm),pe=z[Vm],me=Q.useMemo(()=>{if(!de)return``;let e=new URLSearchParams(i.search).get(fe)||pe;return e?`?${fe}=${encodeURIComponent(e)}`:``},[pe,de,i.search,fe]),V=Q.useMemo(()=>{if(d!==`app`||D?.name!==`studio`)return le;let e=a(`sidebar.packageManagement`,{defaultValue:`Package management`}),t=n=>n.flatMap(n=>{if(eh(n))return[];let r=n.children?.length?t(n.children):n.children;return n.type===`group`&&r?.length===0?[]:th(n)?[{...n,type:`url`,label:e,url:`${ue}/component/developer/packages${me}`,children:r}]:r===n.children?[n]:[{...n,children:r}]});return t(le).flatMap(e=>nh(e)?e.children??[]:[e])},[D?.name,ue,d,le,me,a]),he=Q.useMemo(()=>{let e=k(V);return M(e)},[V,k,M]),[ge,_e]=Q.useState(!1),ve=de&&i.pathname.replace(/\/+$/,``)===ue;return(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(ir,{collapsible:`icon`,className:`!top-14 !h-[calc(100svh-3.5rem)]`,children:[t&&d===`app`&&(0,$.jsx)(wi,{className:`border-b p-1.5`,children:(0,$.jsx)(pi,{children:(0,$.jsx)(ni,{children:(0,$.jsx)(vr,{asChild:!0,className:`min-h-[44px] text-[15px] font-medium rounded-xl`,children:(0,$.jsxs)(n,{to:T,onClick:()=>r(!1),"data-testid":`mobile-sidebar-home`,children:[(0,$.jsx)(gt,{className:`h-5 w-5`}),(0,$.jsx)(`span`,{children:a(`home.nav`,{defaultValue:`Home`})})]})})})})}),(0,$.jsx)(bn,{className:`pt-2`,children:(0,$.jsx)(`div`,{className:`transition-opacity duration-200 ease-in-out`,children:d===`app`&&D?(0,$.jsxs)($.Fragment,{children:[B&&(0,$.jsx)(Dr,{className:`group-data-[state=collapsed]:hidden px-2 pb-1`,children:(0,$.jsx)(`div`,{className:`rounded-lg border border-sidebar-border/70 bg-sidebar-accent/25 p-1.5 shadow-xs`,children:(0,$.jsx)(ji,{children:B})})}),de&&(0,$.jsx)(Dr,{children:(0,$.jsx)(ji,{children:(0,$.jsx)(pi,{children:(0,$.jsx)(ni,{children:(0,$.jsx)(vr,{asChild:!0,isActive:ve,tooltip:a(`home.nav`,{defaultValue:`Home`}),children:(0,$.jsxs)(n,{to:{pathname:ue,search:me},children:[(0,$.jsx)(gt,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:a(`home.nav`,{defaultValue:`Home`})})]})})})})})}),I.length>1&&(0,$.jsxs)(Dr,{children:[(0,$.jsxs)(li,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)($r,{className:`h-3.5 w-3.5`}),a(`sidebar.area`,{defaultValue:`Area`})]}),(0,$.jsx)(ji,{children:(0,$.jsx)(pi,{children:I.map(e=>{let t=qs(e.icon),n=e.id===R?.id,r=ie(e.label,s);return(0,$.jsx)(ni,{children:(0,$.jsxs)(vr,{isActive:n,tooltip:r,onClick:()=>ae(e.id),children:[(0,$.jsx)(t,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:r})]})},e.id)})})})]}),(0,$.jsx)(Cs,{items:he,basePath:ue,evaluateVisibility:N,checkPermission:F,checkCapability:re,enablePinning:!t,onPinToggle:j,enableReorder:!t,onReorder:A,resolveObjectLabel:(e,t)=>c({name:e,label:t}),resolveDashboardLabel:(e,t)=>l({name:e,label:t}),resolveViewLabel:(e,t,n)=>u(e,t,n),onAction:g,t:a,templateContext:{currentUserId:p?.id??null,currentOrgId:m?.id??null,contextValues:z}}),_.length>0&&(0,$.jsxs)(Dr,{children:[(0,$.jsxs)(li,{className:`flex items-center gap-1.5 cursor-pointer select-none`,onClick:()=>_e(e=>!e),children:[(0,$.jsx)(gi,{className:`h-3 w-3 transition-transform duration-150 ${ge?`rotate-90`:``}`}),(0,$.jsx)(Rn,{className:`h-3.5 w-3.5`}),a(`sidebar.recent`,{defaultValue:`Recent`})]}),ge&&(0,$.jsx)(ji,{children:(0,$.jsx)(pi,{children:_.slice(0,5).map(e=>(0,$.jsx)(ni,{children:(0,$.jsx)(vr,{asChild:!0,tooltip:e.label,children:(0,$.jsxs)(n,{to:e.href,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:`📄`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]})})},e.id))})})]}),v.some(e=>e.type!==`nav`)&&(0,$.jsxs)(Dr,{children:[(0,$.jsxs)(li,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(Cn,{className:`h-3.5 w-3.5`}),a(`sidebar.favorites`,{defaultValue:`Favorites`})]}),(0,$.jsx)(ji,{children:(0,$.jsx)(pi,{children:v.filter(e=>e.type!==`nav`).slice(0,8).map(e=>(0,$.jsxs)(ni,{children:[(0,$.jsx)(vr,{asChild:!0,tooltip:e.label,children:(0,$.jsxs)(n,{to:e.href,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`report`?`📈`:e.type===`page`?`📄`:`📋`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,$.jsx)(Di,{showOnHover:!0,onClick:t=>{t.stopPropagation(),y(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,$.jsx)(Zi,{className:`h-3 w-3`})})]},e.id))})})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Cs,{items:ce,basePath:``,evaluateVisibility:N,checkPermission:F,checkCapability:re,resolveObjectLabel:(e,t)=>c({name:e,label:t}),resolveDashboardLabel:(e,t)=>l({name:e,label:t}),resolveViewLabel:(e,t,n)=>u(e,t,n),onAction:g,t:a,templateContext:{currentUserId:p?.id??null,currentOrgId:m?.id??null,contextValues:z}}),v.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).length>0&&(0,$.jsxs)(Dr,{children:[(0,$.jsxs)(li,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(Cn,{className:`h-3.5 w-3.5`}),a(`sidebar.starred`,{defaultValue:`Starred`})]}),(0,$.jsx)(ji,{children:(0,$.jsx)(pi,{children:v.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`).slice(0,8).map(e=>(0,$.jsxs)(ni,{children:[(0,$.jsx)(vr,{asChild:!0,tooltip:e.label,children:(0,$.jsxs)(n,{to:e.href,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.type===`dashboard`?`📊`:e.type===`page`?`📄`:`📋`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]})}),(0,$.jsx)(Di,{showOnHover:!0,onClick:t=>{t.stopPropagation(),y(e.id)},"aria-label":a(`sidebar.removeFromFavorites`,{defaultValue:`Remove {{name}} from favorites`,name:e.label}),children:(0,$.jsx)(Zi,{className:`h-3 w-3`})})]},e.id))})})]})]})})}),(0,$.jsx)(dt,{className:`border-t p-1`,children:(0,$.jsx)(vd,{className:`w-full justify-start pl-2 group-data-[state=collapsed]:justify-center group-data-[state=collapsed]:pl-0`})})]})})}function ih({children:e}){return em(),(0,$.jsx)($.Fragment,{children:e})}function ah({children:e,activeAppName:t,activeApp:n,onAppChange:r,objects:i,connectionState:a,userId:s}){let c=ys(n?.label)||t,{enabled:l}=zo(),{setContext:u,setCurrentAppName:d}=Ra(),f=om({persistExpandedKey:Td}),m=l,h=p(),g=o(),_=sr(),v=(0,Q.useCallback)(()=>{Fd(`${g.pathname}${g.search}`),h(`/ai`)},[g.pathname,g.search,h]);return(0,Q.useEffect)(()=>{u(`app`),d(t)},[u,d,t]),(0,Q.useEffect)(()=>{if(!m)return;let e=e=>{Ld(e)===`toggle`&&(e.preventDefault(),f.toggle())};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[m,f]),(0,$.jsx)(hd,{children:(0,$.jsx)(ud,{children:(0,$.jsxs)(ws,{sidebar:(0,$.jsx)(rh,{activeAppName:t,onAppChange:r}),navbar:(0,$.jsx)(Cd,{variant:`app`,appName:c,objects:i,connectionState:a,activeAppName:t,onAppChange:r}),className:`!p-0 overflow-y-auto overflow-x-hidden bg-muted/5`,rightRail:m&&f.expanded&&!_?(0,$.jsx)(cm,{dock:f,userId:s,defaultAgent:n?.defaultAgent,onMaximize:v}):void 0,branding:n?.branding?{primaryColor:n.branding.primaryColor,accentColor:n.branding.accentColor,favicon:n.branding.favicon,title:n.label?`${ys(n.label)} — ${us()}`:void 0}:void 0,children:[(0,$.jsxs)(ih,{children:[(0,$.jsx)(km,{}),(0,$.jsx)(Rm,{}),(0,$.jsx)(zm,{}),e]}),l&&(0,$.jsx)(Fu,{appLabel:c,onOpenDock:f.expand}),m&&_&&(0,$.jsx)(lm,{open:f.expanded,onOpenChange:e=>e?f.expand():f.collapse(),userId:s,defaultAgent:n?.defaultAgent,onMaximize:v})]})})})}function oh({apps:e,activeApp:t,objects:n,onAppChange:r,dataSource:i}){let{open:a,setOpen:o}=gd(),[s,l]=(0,Q.useState)(``),u=p(),{appName:d}=c(),{setTheme:f}=cu(),{evaluator:m}=xa(),{t:h}=G();(0,Q.useEffect)(()=>{a||l(``)},[a]);let g=`/apps/${d||fo(t)}`,{user:_,activeOrganization:v}=C(),y=(0,Q.useMemo)(()=>({currentUserId:_?.id??null,currentOrgId:v?.id??null}),[_?.id,v?.id]),b=(0,Q.useCallback)(e=>{o(!1),e()},[]),x=sh(t?.navigation||[]).filter(e=>wa(e.visible??e.visibleOn,m)),S=(0,Q.useMemo)(()=>x.filter(e=>e.type===`object`&&typeof e.objectName==`string`).map(e=>e.objectName),[t?.name,x.map(e=>e.objectName||``).join(`|`)]),{results:w,isSearching:T}=Te({query:s,objects:n,dataSource:i,objectNames:S,enabled:a&&!!i,getDisplayName:Be}),{recentItems:E}=ja(),D=(0,Q.useMemo)(()=>E.filter(e=>e.type===`record`).slice(0,5),[E]),O=a&&s.trim().length===0&&D.length>0,k=(0,Q.useMemo)(()=>{let e=new Map;for(let t of n||[])typeof t?.name==`string`&&e.set(t.name,t);return e},[n]),A=(0,Q.useMemo)(()=>{let e=[],t=new Map;for(let n of w){let r=t.get(n.objectName);if(!r){let i=k.get(n.objectName);r={objectLabel:ys(i?.label,h)||n.objectLabel,icon:n.icon,hits:[]},t.set(n.objectName,r),e.push(n.objectName)}r.hits.push(n)}return e.map(e=>({objectName:e,...t.get(e)}))},[w,k,h]);return(0,$.jsxs)(Cr,{open:a,onOpenChange:o,title:h(`console.commandPalette.title`,{defaultValue:`Command palette`}),description:h(`console.commandPalette.placeholder`),contentProps:{"data-testid":`overlay:command-palette`},children:[(0,$.jsx)(ai,{placeholder:h(`console.commandPalette.placeholder`),value:s,onValueChange:l}),(0,$.jsxs)(Lr,{children:[(0,$.jsx)(Nr,{children:T?(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2 text-muted-foreground`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`inline-block h-1.5 w-1.5 rounded-full bg-primary motion-safe:animate-pulse`}),h(`console.commandPalette.searching`,{defaultValue:`Searching…`})]}):h(`console.commandPalette.noResults`)}),O&&(0,$.jsx)(yi,{heading:h(`console.commandPalette.recentRecords`,{defaultValue:`Recently viewed`}),children:D.map(e=>(0,$.jsxs)(Hr,{value:`recent ${e.label} ${e.id}`,onSelect:()=>b(()=>u(e.href)),children:[(0,$.jsx)(ur,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.label})]},`recent:${e.id}`))}),A.map((e,t)=>{let n=qs(e.icon);return(0,$.jsx)(yi,{heading:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[e.objectLabel,T&&t===0&&(0,$.jsx)(`span`,{"aria-hidden":!0,className:`inline-block h-1.5 w-1.5 rounded-full bg-primary motion-safe:animate-pulse`})]}),children:e.hits.map(e=>(0,$.jsxs)(Hr,{value:`record ${s} ${e.display} ${e.objectLabel} ${e.objectName} ${e.recordId}`,onSelect:()=>b(()=>u(`${g}/${e.objectName}/record/${e.recordId}`)),children:[(0,$.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.display}),e.subtitle&&(0,$.jsx)(`span`,{className:`ml-auto max-w-[45%] truncate text-xs text-muted-foreground`,children:e.subtitle})]},`${e.objectName}:${e.recordId}`))},`records:${e.objectName}`)}),x.filter(e=>e.type===`object`).length>0&&(0,$.jsx)(yi,{heading:h(`console.commandPalette.objects`),children:x.filter(e=>e.type===`object`).map(e=>{let t=qs(e.icon);return(0,$.jsxs)(Hr,{value:`object ${ys(e.label,h)} ${e.objectName}`,onSelect:()=>b(()=>u(Ss(e,g,y).href)),children:[(0,$.jsx)(t,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:ys(e.label,h)})]},e.id)})}),x.filter(e=>e.type===`dashboard`).length>0&&(0,$.jsx)(yi,{heading:h(`console.commandPalette.dashboards`),children:x.filter(e=>e.type===`dashboard`).map(e=>(0,$.jsxs)(Hr,{value:`dashboard ${ys(e.label,h)} ${e.dashboardName}`,onSelect:()=>b(()=>u(Ss(e,g,y).href)),children:[(0,$.jsx)(cn,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:ys(e.label,h)})]},e.id))}),x.filter(e=>e.type===`page`).length>0&&(0,$.jsx)(yi,{heading:h(`console.commandPalette.pages`),children:x.filter(e=>e.type===`page`).map(e=>(0,$.jsxs)(Hr,{value:`page ${ys(e.label,h)} ${e.pageName}`,onSelect:()=>b(()=>u(Ss(e,g,y).href)),children:[(0,$.jsx)(Li,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:ys(e.label,h)})]},e.id))}),x.filter(e=>e.type===`report`).length>0&&(0,$.jsx)(yi,{heading:h(`console.commandPalette.reports`),children:x.filter(e=>e.type===`report`).map(e=>(0,$.jsxs)(Hr,{value:`report ${ys(e.label,h)} ${e.reportName}`,onSelect:()=>b(()=>u(Ss(e,g,y).href)),children:[(0,$.jsx)(kn,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:ys(e.label,h)})]},e.id))}),e.filter(e=>e.active!==!1).length>1&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(lr,{}),(0,$.jsx)(yi,{heading:h(`console.commandPalette.switchApp`),children:e.filter(e=>e.active!==!1).map(e=>{let n=qs(e.icon);return(0,$.jsxs)(Hr,{value:`app ${ys(e.label,h)} ${e.name}`,onSelect:()=>b(()=>r(fo(e)??e.name)),children:[(0,$.jsx)(n,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:ys(e.label,h)}),e.name===t?.name&&(0,$.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:h(`console.commandPalette.current`)})]},e.name)})})]}),(0,$.jsx)(lr,{}),(0,$.jsxs)(yi,{heading:h(`console.commandPalette.preferences`),children:[(0,$.jsxs)(Hr,{value:`theme light`,onSelect:()=>b(()=>f(`light`)),children:[(0,$.jsx)(pn,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:h(`console.commandPalette.lightTheme`)})]}),(0,$.jsxs)(Hr,{value:`theme dark`,onSelect:()=>b(()=>f(`dark`)),children:[(0,$.jsx)(Mi,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:h(`console.commandPalette.darkTheme`)})]}),(0,$.jsxs)(Hr,{value:`theme system`,onSelect:()=>b(()=>f(`system`)),children:[(0,$.jsx)(ui,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:h(`console.commandPalette.systemTheme`)})]})]}),(0,$.jsx)(lr,{}),(0,$.jsx)(yi,{heading:h(`console.commandPalette.actions`),children:(0,$.jsxs)(Hr,{value:`search all results full page`,onSelect:()=>b(()=>u(`${g}/search`)),children:[(0,$.jsx)(ur,{className:`mr-2 h-4 w-4`}),(0,$.jsx)(`span`,{children:h(`console.commandPalette.openFullSearch`)})]})})]})]})}function sh(e){let t=[];for(let n of e)n.type===`group`&&n.children?t.push(...sh(n.children)):t.push(n);return t}function ch(){let{t:e}=G(),{open:t,setOpen:n,toggleOverlay:r}=ru(to),i=(0,Q.useMemo)(()=>[{title:e(`console.shortcuts.groups.general`),shortcuts:[{keys:[`⌘`,`K`],description:e(`console.shortcuts.openCommandPalette`)},{keys:[`?`],description:e(`console.shortcuts.showShortcuts`)},{keys:[`Esc`],description:e(`console.shortcuts.closeDialog`)}]},{title:e(`console.shortcuts.groups.navigation`),shortcuts:[{keys:[`B`],description:e(`console.shortcuts.toggleSidebar`)},{keys:[`⌘`,`/`],description:e(`console.shortcuts.focusSearch`)}]},{title:e(`console.shortcuts.groups.dataViews`),shortcuts:[{keys:[`N`],description:e(`console.shortcuts.createRecord`)},{keys:[`R`],description:e(`console.shortcuts.refreshData`)},{keys:[`⌘`,`E`],description:e(`console.shortcuts.editRecord`)}]},{title:e(`console.shortcuts.groups.aiChat`,{defaultValue:`AI assistant`}),shortcuts:[{keys:[`⌘`,`⇧`,`O`],description:e(`console.shortcuts.newChat`,{defaultValue:`New chat`})},{keys:[`⌘`,`⇧`,`S`],description:e(`console.shortcuts.toggleChatsList`,{defaultValue:`Toggle conversations list`})}]},{title:e(`console.shortcuts.groups.preferences`),shortcuts:[{keys:[`⌘`,`D`],description:e(`console.shortcuts.toggleDarkMode`)}]}],[e]);return(0,Q.useEffect)(()=>{function e(e){let t=e.target;t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.isContentEditable||e.key===`?`&&!e.metaKey&&!e.ctrlKey&&!e.altKey&&(e.preventDefault(),r())}return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[r]),(0,$.jsx)(Vi,{open:t,onOpenChange:n,children:(0,$.jsxs)(Xi,{className:`sm:max-w-lg max-h-[80vh] overflow-y-auto`,"data-testid":`overlay:keyboard-shortcuts`,children:[(0,$.jsxs)(En,{children:[(0,$.jsx)(xt,{children:e(`console.shortcuts.title`)}),(0,$.jsx)(gr,{children:e(`console.shortcuts.description`)})]}),(0,$.jsx)(`div`,{className:`space-y-6 pt-2`,children:i.map(e=>(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`text-sm font-medium text-muted-foreground mb-3`,children:e.title}),(0,$.jsx)(`div`,{className:`space-y-2`,children:e.shortcuts.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center justify-between py-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm`,children:e.description}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:e.keys.map((e,t)=>(0,$.jsx)(`kbd`,{className:`inline-flex h-6 min-w-[24px] items-center justify-center rounded border bg-muted px-1.5 text-xs font-medium text-muted-foreground`,children:e},t))})]},t))})]},e.title))})]})})}function lh(){return null}function uh(e){let{theme:t=`system`}=cu(),{t:n}=G();return(0,$.jsx)(ea,{theme:t,className:`toaster group`,position:`top-right`,closeButton:!0,richColors:!0,expand:!0,visibleToasts:4,containerAriaLabel:n(`notifications.regionLabel`,{defaultValue:`Notifications`}),icons:{success:(0,$.jsx)(Gr,{className:`h-4 w-4`}),info:(0,$.jsx)(Bt,{className:`h-4 w-4`}),warning:(0,$.jsx)(Ji,{className:`h-4 w-4`}),error:(0,$.jsx)(Xn,{className:`h-4 w-4`}),loading:(0,$.jsx)(Y,{className:`h-4 w-4 animate-spin`})},toastOptions:{duration:4e3,classNames:{toast:`group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg`,description:`group-[.toast]:text-muted-foreground`,actionButton:`group-[.toast]:bg-primary group-[.toast]:text-primary-foreground`,cancelButton:`group-[.toast]:bg-muted group-[.toast]:text-muted-foreground`}},...e})}var dh=[`motion-safe:animate-in`,`motion-safe:fade-in-0`,`motion-safe:duration-150`];function fh({children:e,className:t}){let n=o(),r=Q.useRef(null),i=Q.useRef(n.pathname);return Q.useLayoutEffect(()=>{if(i.current===n.pathname)return;i.current=n.pathname;let e=r.current;e&&(e.classList.remove(...dh),e.offsetWidth,e.classList.add(...dh))},[n.pathname]),(0,$.jsx)(`div`,{ref:r,className:[...dh,t??``].filter(Boolean).join(` `),children:e})}var ph=null,mh=null,hh={enabled:!1,reason:`no-dsn`,dsn:``,sendDefaultPii:!1,environment:``,tracesSampleRate:0,replaysOnErrorSampleRate:0};function gh(e){if(!e)return hh;let t=typeof e.dsn==`string`?e.dsn.trim():``;return t?{enabled:!0,reason:`opted-in`,dsn:t,sendDefaultPii:e.sendDefaultPii===!0,environment:typeof e.environment==`string`?e.environment.trim():``,tracesSampleRate:_h(e.tracesSampleRate,.1),replaysOnErrorSampleRate:_h(e.replaysOnErrorSampleRate,0)}:hh}function _h(e,t){return typeof e==`number`&&Number.isFinite(e)&&e>=0&&e<=1?e:t}function vh(){return mh||(mh=(async()=>{let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},n=gh(ds());if(!n.enabled)return!1;try{let r=await t(()=>import(`./vendor-sentry-B2ojA7qm.js`).then(e=>e.t),[],import.meta.url);return r.init({dsn:n.dsn,environment:n.environment||e.MODE||`production`,release:e.VITE_SENTRY_RELEASE||e.VITE_APP_VERSION||`unknown`,tracesSampleRate:n.tracesSampleRate,sendDefaultPii:n.sendDefaultPii,replaysSessionSampleRate:0,replaysOnErrorSampleRate:n.replaysOnErrorSampleRate,integrations:[r.browserTracingIntegration()],beforeBreadcrumb(e){return(e.category===`fetch`||e.category===`xhr`)&&e.data?.url&&typeof e.data.url==`string`&&(e.data.url=bh(e.data.url)),e}}),ph=r,!0}catch(e){return console.warn(`[sentry] init failed; continuing without observability:`,e),!1}})(),mh)}function yh(e,t){if(ph)try{ph.captureException(e,t?{extra:t}:void 0)}catch{}}function bh(e){try{let t=new URL(e,`http://localhost`);for(let e of[`token`,`access_token`,`id_token`,`apiKey`,`api_key`,`password`])t.searchParams.has(e)&&t.searchParams.set(e,`[redacted]`);return t.pathname+(t.searchParams.toString()?`?`+t.searchParams.toString():``)}catch{return e}}function xh({error:e,onReset:t}){let{t:n}=G();return(0,$.jsx)(`div`,{className:`flex h-full items-center justify-center p-8`,children:(0,$.jsxs)(`div`,{className:`max-w-md text-center`,children:[(0,$.jsxs)(oi,{children:[(0,$.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-destructive/10`,children:(0,$.jsx)(Ji,{className:`h-6 w-6 text-destructive`})}),(0,$.jsx)(Hi,{children:n(`console.errors.somethingWentWrong`)}),(0,$.jsx)(Wr,{className:`mb-4`,children:e.message||n(`console.errors.unexpectedError`)}),(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2`,children:[(0,$.jsxs)(J,{variant:`outline`,size:`sm`,onClick:t,className:`gap-2`,children:[(0,$.jsx)(Ar,{className:`h-4 w-4`}),n(`console.errors.tryAgain`)]}),(0,$.jsxs)(J,{variant:`ghost`,size:`sm`,onClick:()=>{window.location.href=`/`},className:`gap-2`,children:[(0,$.jsx)(gt,{className:`h-4 w-4`}),n(`console.errors.goHome`)]})]})]}),!1]})})}var Sh=class extends Q.Component{constructor(e){super(e),this.state={hasError:!1,error:null}}static getDerivedStateFromError(e){return{hasError:!0,error:e}}componentDidCatch(e,t){console.error(`[ErrorBoundary] Caught error:`,e,t),yh(e,{componentStack:t.componentStack}),this.props.onError?.(e,t)}resetErrorBoundary=()=>{this.setState({hasError:!1,error:null})};render(){return this.state.hasError&&this.state.error?this.props.fallback?typeof this.props.fallback==`function`?this.props.fallback({error:this.state.error,reset:this.resetErrorBoundary}):this.props.fallback:(0,$.jsx)(xh,{error:this.state.error,onReset:this.resetErrorBoundary}):this.props.children}},Ch=`list-filters`;function wh(e,t,n){if(!(!t||!n))return`${Ch}:${e||`anon`}:${t}:${n}`}function Th(e){return!e||!Array.isArray(e.conditions)||e.conditions.length===0}function Eh(e){return Th(e.filters)&&!(e.search&&e.search.length>0)}function Dh(e){if(!(!e||typeof localStorage>`u`))try{let t=localStorage.getItem(e);if(!t)return;let n=JSON.parse(t);return!n||typeof n!=`object`?void 0:n}catch{return}}var Oh={},kh={};function Ah(e,t){!e||typeof localStorage>`u`||(Oh[e]={...Oh[e]??Dh(e)??{},...t},kh[e]&&clearTimeout(kh[e]),kh[e]=setTimeout(()=>{let t=Oh[e]??{};delete Oh[e],delete kh[e];try{Eh(t)?localStorage.removeItem(e):localStorage.setItem(e,JSON.stringify(t))}catch{}},300))}var jh=new Set([`form`,`detail`]);function Mh(e){return typeof e==`string`&&jh.has(e)}function Nh(e,t){let n=e.type||`grid`,r=Mh(n)?`form`:`list`,i=e.label,a=e.data&&typeof e.data==`object`?e.data:void 0;return{name:e.id,object:t,viewKind:r,label:i,config:{...e,type:n,label:i,columns:Array.isArray(e.columns)?e.columns:[],data:{...a,object:t}}}}function Ph(e){let t=e.config??{},n={...t};return delete n.data,{...n,id:e.name,label:e.label??t.label}}function Fh(e){let t=e.fields;return!t||typeof t!=`object`?[]:Object.entries(t).map(([e,t])=>{let n=t??{};return{name:e,label:typeof n.label==`string`&&n.label?n.label:e,type:typeof n.type==`string`?n.type:`text`,hidden:n.hidden===!0}})}function Ih({open:e,onClose:t,mode:n=`edit`,activeView:r,objectDef:i,onViewUpdate:a,onSave:o,onCreate:s,metadataClient:c,dataSource:l,onAfterChange:u}){let{t:d}=G(),f=(0,Q.useRef)(null),p=Mc(),[m]=(0,Q.useState)(()=>`view_${Date.now()}`),h=(0,Q.useMemo)(()=>({id:m,label:d(`console.objectView.newView`),type:`grid`,columns:[],filter:[],sort:[]}),[]),g=n===`create`?`create`:r.id,_=(0,Q.useMemo)(()=>Nh(n===`create`?h:r,i.name),[g,i.name]),[v,y]=(0,Q.useState)(_),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(0),w=(0,Q.useRef)(v),T=(0,Q.useRef)(_);T.current!==_&&(T.current=_,w.current=_,y(_),x(!1)),(0,Q.useEffect)(()=>{w.current=v},[v]),(0,Q.useEffect)(()=>{e&&f.current&&f.current.focus()},[e]);let E=(0,Q.useMemo)(()=>Fh(i),[i.fields]),D=Bo(v.viewKind)?`form`:`list`,O=(0,Q.useCallback)(e=>{let t={...w.current,...e};if(w.current=t,y(t),x(!0),a){let e=Ph(t);for(let[t,n]of Object.entries(e))t!==`id`&&a(t,n)}},[a]),k=(0,Q.useCallback)(()=>{let e=Ph(v);n===`create`?s?.(e):(o?.(e),C(e=>e+1)),x(!1)},[v,o,s,n]),A=(0,Q.useCallback)(()=>{if(n===`edit`){if(a){let e=Ph(_),t=Ph(w.current),n=new Set([...Object.keys(t),...Object.keys(e)]);for(let t of n)t!==`id`&&a(t,e[t])}w.current=_,y(_),x(!1)}t()},[_,n,t,a]),j=(0,Q.useCallback)(e=>{let t=Nh(e,i.name);w.current=t,y(t),x(!1)},[i.name]),M=d(n===`create`?`console.objectView.createView`:`console.objectView.configureView`);return e?(0,$.jsxs)(`div`,{ref:f,tabIndex:-1,role:`complementary`,"aria-label":M,"data-testid":`view-config-panel`,className:`flex h-full flex-col`,children:[(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,$.jsx)(Qo,{type:`view`,name:v.name,draft:v,variantKey:`config`,familyKey:D,isHome:!0,readOnly:!1,locale:p,objectFieldsOverride:E,onPatch:O})}),(0,$.jsxs)(`div`,{"data-testid":`view-config-footer`,className:`flex items-center justify-end gap-2 border-t px-4 py-2.5`,children:[n===`edit`&&(0,$.jsx)(Rc,{type:`view`,name:r.id,metadataClient:c,dataSource:l,objectName:i.name,dirty:b,onResume:j,savedSignal:S,onAfterChange:u}),(0,$.jsx)(J,{variant:`ghost`,size:`sm`,onClick:A,"data-testid":`view-config-discard`,children:d(`console.objectView.discard`)}),(0,$.jsx)(J,{size:`sm`,onClick:k,disabled:n===`edit`&&!b,"data-testid":`view-config-save`,children:d(`console.objectView.save`)})]})]}):(0,$.jsx)(`div`,{ref:f,tabIndex:-1,"data-testid":`view-config-panel`,"aria-hidden":!0})}var Lh=`sys_user`;function Rh(e,t=500){let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function zh(e){let t=e.writeMode??`insert`;if(t===`update`)throw Error(`Identity import supports the insert and upsert write modes only.`);if(t===`insert`)return{mode:`insert`};let n=(e.matchFields??[])[0];if(n===`email`)return{mode:`upsert`,matchBy:`email`};if(n===`phone_number`)return{mode:`upsert`,matchBy:`phone`};throw Error(`Identity import matches existing users by "email" or "phone_number" only.`)}function Bh(e,t,n){let r=0,i=0,a=0,o=0,s=0,c=[],l=0;for(let n=0;n<e.length;n++){let{summary:u,rows:d}=e[n],f=t[n]??[];r+=u.total,i+=u.created,a+=u.updated,o+=u.skipped,s+=u.errors;for(let e of d){if(!e)continue;let t=f[e.row-1],n=[t?.email,t?.phone_number,t?.phoneNumber,t?.phone].find(e=>typeof e==`string`&&e.trim().length>0);c.push({row:l+e.row,ok:e.ok,action:e.action,...e.id?{id:e.id}:{},...e.field?{field:e.field}:{},...e.code?{code:e.code}:{},...e.error?{error:e.error}:{},...e.temporaryPassword?{temporaryPassword:e.temporaryPassword}:{},...n?{identity:n.trim()}:{}})}l+=f.length||u.total}return{object:Lh,dryRun:n.dryRun,writeMode:n.writeMode,total:r,ok:r-s,errors:s,created:i,updated:a,skipped:o,results:c}}function Vh(e){let{base:t,authFetch:n,baseUrl:r,getPasswordPolicy:i}=e,a=async(e,t)=>{let{mode:a,matchBy:o}=zh(t),s=i(),c=Array.isArray(t.rows)?t.rows:[];if(c.length===0)throw Error(`Identity import needs mapped rows (rows[]) — file uploads are parsed client-side.`);let l=Rh(c),u=[];for(let e of l){let i=await n(`${r}/api/v1/auth/admin/import-users`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({format:`json`,rows:e,mode:a,...o?{matchBy:o}:{},passwordPolicy:s,...t.dryRun?{dryRun:!0}:{},...t.mappingName?{mappingName:t.mappingName}:{},...t.trimWhitespace===void 0?{}:{trimWhitespace:t.trimWhitespace},...t.nullValues?{nullValues:t.nullValues}:{}})}),c=await i.json().catch(()=>null);if(!i.ok||!c?.success||!c.data){let e=c?.error?.message??`Identity import failed with status ${i.status}`;throw Error(e)}u.push(c.data)}return Bh(u,l,{dryRun:t.dryRun===!0,writeMode:a})};return{...t,importRecords:a,createImportJob:void 0,getImportJobProgress:void 0,getImportJobResults:void 0,listImportJobs:void 0,cancelImportJob:void 0,undoImportJob:void 0}}function Hh(e){if(!e?.results)return[];let t=[];for(let n of e.results)n?.temporaryPassword&&t.push({row:n.row,identity:n.identity??`#${n.row}`,temporaryPassword:n.temporaryPassword});return t}function Uh(e){let t=e=>/[",\n]/.test(e)?`"${e.replace(/"/g,`""`)}"`:e,n=[`row,identity,temporary_password`];for(let r of e)n.push(`${r.row},${t(r.identity)},${t(r.temporaryPassword)}`);return n.join(`
|
|
9
|
+
`)}var Wh={auto:{label:`Automatic (recommended)`,hint:`Reachable users get an invitation (email or SMS); anyone we can't reach gets a one-time password, shown ONCE on the result screen. Works with or without an email/SMS service.`},invite:{label:`Send invitations`,hint:`Every created user gets a set-your-password email (or an invitation SMS for phone-only rows). Requires a configured email/SMS service — unreachable rows fail.`},temporary:{label:`Temporary passwords`,hint:`For deployments without email/SMS: every created user gets a one-time password, shown ONCE on the result screen. First sign-in forces a change.`},none:{label:`No password (identity only)`,hint:`Users first sign in with a phone OTP, magic link, or password-reset link, then set their own password.`}};function Gh({policy:e,onPolicyChange:t}){let n=nt();return(0,$.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 rounded-md border border-border p-3`,"data-testid":`identity-import-options`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(an,{className:`h-4 w-4 text-muted-foreground`}),(0,$.jsx)(K,{className:`text-xs font-medium`,children:n(`console.identityImport.policyTitle`,`Sign-in setup for imported users`)})]}),(0,$.jsxs)(Wi,{value:e,onValueChange:e=>t(e),children:[(0,$.jsx)(Tt,{className:`h-8 w-full sm:w-80`,"data-testid":`identity-import-policy`,children:(0,$.jsx)(sn,{})}),(0,$.jsx)(An,{children:Object.keys(Wh).map(e=>(0,$.jsx)(Dt,{value:e,children:n(`console.identityImport.policy.${e}`,Wh[e].label)},e))})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:n(`console.identityImport.policyHint.${e}`,Wh[e].hint)})]})}function Kh({serverResult:e}){let t=nt(),n=(0,Q.useMemo)(()=>Hh(e),[e]);return n.length===0?null:(0,$.jsxs)(`div`,{className:`mt-2 flex w-full flex-col gap-2 rounded-md border border-amber-500/50 bg-amber-500/5 p-3`,"data-testid":`identity-import-passwords`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-amber-700 dark:text-amber-400`,children:[(0,$.jsx)(Tr,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`p`,{className:`text-xs font-medium`,children:t(`console.identityImport.passwordsNote`,`Temporary passwords — shown once, never stored. Save them now; each user must change theirs at first sign-in.`)})]}),(0,$.jsxs)(`div`,{className:`max-h-40 overflow-auto rounded border bg-background p-2 font-mono text-xs`,children:[n.slice(0,50).map(e=>(0,$.jsxs)(`p`,{"data-testid":`identity-import-password-row-${e.row}`,children:[e.identity,`: `,e.temporaryPassword]},e.row)),n.length>50&&(0,$.jsx)(`p`,{className:`text-muted-foreground`,children:t(`console.identityImport.passwordsMore`,`More entries omitted — use the download.`)})]}),(0,$.jsx)(`div`,{children:(0,$.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>{let e=Uh(n),t=new Blob([e],{type:`text/csv;charset=utf-8`}),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=`temporary-passwords.csv`,i.click(),URL.revokeObjectURL(r)},"data-testid":`identity-import-passwords-download`,children:[(0,$.jsx)(un,{className:`mr-1 h-4 w-4`}),t(`console.identityImport.passwordsDownload`,`Download CSV`),` (`,n.length,`)`]})})]})}function qh(e){let t=(t,n)=>e?.[t]?.label||n;return[{name:`email`,label:t(`email`,`Email`),type:`text`},{name:`phone_number`,label:t(`phone_number`,`Phone Number`),type:`text`},{name:`name`,label:t(`name`,`Name`),type:`text`},{name:`role`,label:t(`role`,`Platform Role`),type:`text`}]}var Jh=new Set([`formula`,`summary`]);function Yh(e,t,n){let r=[];for(let[i,a]of Object.entries(t||{})){let t=Jh.has(a?.type),o=!t&&a?.type!==`autonumber`&&!a?.readonly&&(!n?.isLoaded||n.checkField(e,i,`write`)),s=!o&&!t&&(!n?.isLoaded||n.checkField(e,i,`read`));!o&&!s||r.push({name:i,label:a?.label||i,type:a?.type||`text`,required:o&&!!a?.required,...s?{matchOnly:!0}:{},...a?.options?{options:a.options}:{}})}return r}function Xh(e,t,n,r){switch(e){case`engine-owned`:return ye({managedBy:e,userActions:r}).create?void 0:{icon:`Lock`,title:t(`list.managedBy.system.title`,{defaultValue:`Nothing here yet`}),message:t(`list.managedBy.system.message`,{defaultValue:`Entries appear automatically when their source action runs (e.g. Submit for Approval, Share, Invite). Trigger one of those on a source record to create a row.`})};case`append-only`:return{icon:`Archive`,title:t(`list.managedBy.appendOnly.title`,{defaultValue:`No events recorded`}),message:t(`list.managedBy.appendOnly.message`,{defaultValue:`This is an immutable audit log. Rows are written by the platform when events occur — you can export the history but cannot create entries from here.`})};case`better-auth`:return n===`sys_user`?{icon:`ShieldAlert`,title:t(`list.managedBy.betterAuthUser.title`,{defaultValue:`No users yet`}),message:t(`list.managedBy.betterAuthUser.message`,{defaultValue:`User accounts are provisioned by the authentication provider, not created here. Invite teammates to your organization and they appear automatically on first sign-in (SSO just-in-time provisioning). App end-users arrive when they sign up through your app.`})}:n===`sys_team`?{icon:`Users`,title:t(`list.managedBy.betterAuthTeam.title`,{defaultValue:`No teams yet`}),message:t(`list.managedBy.betterAuthTeam.message`,{defaultValue:`Teams group members within an organization. Create one with “Create Team”, or they arrive through your auth provider’s organization and SSO provisioning flows.`})}:{icon:`ShieldAlert`,title:t(`list.managedBy.betterAuth.title`,{defaultValue:`No identity records`}),message:t(`list.managedBy.betterAuth.message`,{defaultValue:`These records are created by the authentication provider — through sign-in, provisioning, and security flows — not added by hand here.`})};default:return}}function Zh(e,t){if(!t||typeof t!=`object`)return;let n=t.name;return typeof n==`string`&&n.startsWith(`${e}.`)?n:re(e,{list:t})[0]?.name}function Qh(e){if(!e||typeof e!=`object`)return;let t=e;for(let e of[`name`,`id`,`_id`]){let n=t[e];if(typeof n==`string`&&n!==``)return n}}function $h(e,t){return e.some(e=>Qh(e)===t)}function eg(e,...t){let n={};for(let e of t)e&&typeof e==`object`&&Object.assign(n,e);return n.id=e,n}var tg=new Set;function ng(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.element===`tabs`||t.tabs!=null}function rg(e,t,n,r){let i=[];if((n?.quickFilters??r?.quickFilters)!=null&&i.push(`quickFilters`),ng(n?.userFilters??r?.userFilters)&&i.push(`userFilters (element: "tabs")`),i.length===0)return!1;let a=`${e}.${t}`;return tg.has(a)||(tg.add(a),console.warn(`[ObjectView] View "${t}" on object "${e}" defines ${i.join(` and `)}, which are ignored on an object list view (ADR-0047 "views" mode — the view switcher owns the tab bar here). Use \`listViews\` for named presets, \`element: "dropdown"\` for value chips, or move them to a page list (InterfaceListPage "filters" mode).`)),!0}var ig=new Set([`archived`,`failed`]);function ag(e){let t=String(e?.environment_type??``).trim().toLowerCase();return t===`production`||t===`prod`?`production`:t?`development`:e?.is_default===!0||e?.is_default===1?`production`:`development`}function og(e){let{enabled:t,dataSource:n,authFetch:r,apiBase:i,refreshKey:a}=e,{activeOrganization:o}=C(),s=o?.id,[c,l]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{if(!t){l(null);return}let e=!1,a=async()=>{try{let e=(i||``).replace(/\/+$/,``),t=s?`?organizationId=${encodeURIComponent(s)}`:``,n=await r(`${e}/api/v1/cloud/environment-entitlements${t}`,{method:`GET`,credentials:`include`});if(!n.ok)return null;let a=(await n.json().catch(()=>null))?.data;return!a||typeof a!=`object`?null:{ready:!0,hasProductionEnv:a.hasProductionEnv===!0,canCreateDevelopmentEnv:a.development?.canCreate,plan:a.plan,upgradeUrl:a.upgradeUrl||`/settings/billing`,contactSalesUrl:a.contactSalesUrl,source:`summary`}}catch{return null}},o=async()=>{try{let e={$top:200};s&&(e.$filter={organization_id:s});let t=await n.find(`sys_environment`,e);return{ready:!0,hasProductionEnv:(Array.isArray(t)?t:t?.data??[]).filter(e=>!ig.has(String(e?.status??``))).some(e=>ag(e)===`production`),canCreateDevelopmentEnv:void 0,upgradeUrl:Ba,source:`derived`}}catch{return{ready:!1,hasProductionEnv:!1,canCreateDevelopmentEnv:void 0,upgradeUrl:Ba,source:`unknown`}}};return(async()=>{let t=await a()??await o();e||l(t)})(),()=>{e=!0}},[t,s,i,r,n,a]),c}var sg=`create_environment`;function cg(e,t){return Yo(n=>n===sg&&e&&t!=null)!==null}function lg(e){return e.filter(e=>e?.name!==sg)}function ug({actions:e}){return e.length===0?null:(0,$.jsx)(ze,{schema:{type:`action:bar`,location:`list_toolbar`,actions:e,size:`sm`,variant:`outline`}})}function dg({actions:e,entitlements:t,onUpgrade:n}){let{t:r}=G(),i=V(),a=(e||[]).filter(e=>Re(e,`list_toolbar`)&&i(e?.requiredPermissions)),o=a.some(e=>e?.name===sg),s=t?.ready?za(t):null,c=cg(o,s);if((0,Q.useEffect)(()=>{c&&s===`upgrade_for_development`&&t&&n(Va(t,r))},[c,s]),a.length===0)return null;if(t===null){let e=lg(a);return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ug,{actions:e}),o&&(0,$.jsx)(Fr,{className:`h-9 w-44 rounded-md`,"data-testid":`environment-create-cta-loading`})]})}if(s===`upgrade_for_development`)return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ug,{actions:lg(a)}),o&&(0,$.jsxs)(J,{size:`sm`,onClick:()=>n(Va(t,r)),className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,"data-testid":`environment-add-upgrade`,children:[(0,$.jsx)(Ct,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{children:r(`environment.addEnvironment`)})]})]});let l=a.map(e=>e?.name!==sg||s==null?e:s===`setup_production`?{...e,label:r(`environment.setUpProduction`),variant:`primary`,...c?{autoTrigger:!0}:{}}:{...e,label:r(`environment.addDevelopment`),...c?{autoTrigger:!0}:{}});return(0,$.jsx)(ze,{schema:{type:`action:bar`,location:`list_toolbar`,actions:l,size:`sm`,variant:`outline`}})}I();var fg=(0,Q.lazy)(()=>t(()=>import(`./plugin-charts-CDGkx7z5.js`).then(e=>e.t).then(e=>({default:e.ObjectChart})),__vite__mapDeps([0]),import.meta.url)),pg=(0,Q.lazy)(()=>t(()=>import(`./plugin-grid-kkbz4uec.js`).then(e=>e.t).then(e=>({default:e.ImportWizard})),__vite__mapDeps([0]),import.meta.url)),mg={grid:$t,kanban:Fn,calendar:wt,gallery:Et,timeline:Ci,gantt:mr,map:vi,chart:kn},hg={id:`current-user`,name:`Demo User`};function gg(e,t){return me(e,t)}function _g(e){let t=e?.timeline?.startDateField||e?.timeline?.dateField;return{...e?.timeline||{},...t?{startDateField:t}:{},titleField:e?.timeline?.titleField||`name`,descriptionField:e?.timeline?.descriptionField}}function vg(e){let t=e?.calendar;if(!(!t||typeof t!=`object`))return{...t}}function yg(e){return{...e?.gantt||{},titleField:e?.gantt?.titleField||`name`}}function bg(e,t){return`${e.replace(/\/view\/.*$/,``)}/record/${encodeURIComponent(String(t))}`}var xg=Object.freeze({});function Sg(e,t,n=()=>window.location.pathname){let r=(t,n)=>t===e&&n!=null&&n!==``;return{resolve:()=>xg,recordHref:(e,t)=>r(e,t)?bg(n(),t):null,openRecord:(e,n)=>{r(e,n)&&t(n)}}}function Cg(e,t=5,n){let r=t=>n?.orgAttribution&&e?.fields?.organization_id&&!t.includes(`organization_id`)?[...t,`organization_id`]:t,i=e?.highlightFields;if(Array.isArray(i)&&i.length>0)return r(Ae(e,i.filter(t=>e?.fields?.[t])));let a=e?.fields;return a&&typeof a==`object`?r(Ae(e,Object.entries(a).filter(([e,t])=>t&&!t.hidden&&!fe(e,t)).map(([e])=>e)).slice(0,t)):[]}function wg(e){if(!e||typeof e!=`object`)return e;let t=se(e);if(t!==e)return t;if(!Array.isArray(e.filter))return e;let n=e.filter.filter(e=>{if(Array.isArray(e)){if(e.length<2)return!1;let[,t,n]=e;return uc.has(String(t))?!0:Nn(String(t),n)}if(!e||typeof e!=`object`||typeof e.field!=`string`||e.field===``)return!1;if(uc.has(String(e.operator)))return!0;let t=e.value;return Nn(String(e.operator),t)});if(n.length===0){let{filter:t,...n}=e;return n}return n.length===e.filter.length?e:{...e,filter:n}}async function Tg(e,t,n){if(typeof e?.listViewOverrides==`function`)try{let r=await e.listViewOverrides(t);if(r&&typeof r==`object`){let e={};for(let t of n)r[t]&&(e[t]=wg(r[t]));return e}}catch{}if(typeof e?.getView!=`function`)return{};let r=await Promise.all(n.map(async n=>{try{return[n,await e.getView(t,n)]}catch{return[n,null]}})),i={};for(let[e,t]of r)t&&typeof t==`object`&&(i[e]=wg(t));return i}function Eg({definedViews:e,primary:t,primaryId:n,savedViews:r,viewOverrides:i,fallbackTab:a}){let o=Object.entries(e||{}).map(([e,t])=>{let n=i[e];return eg(e,t,n,{type:n?.type||t?.type||`grid`})});if(n){let e=o.findIndex(e=>e.id===n);if(e>=0){let[t]=o.splice(e,1);o.unshift(eg(n,t,{isDefault:!0}))}else{let e=i[n];o.unshift(eg(n,t,e,{type:e?.type||t?.type||`grid`,isDefault:!0}))}}o.length===0&&o.push(a());let s=new Set(o.map(e=>e.id));for(let e of r){let t=Qh(e);if(!t)continue;let n={label:e.label||e.name||t,type:e.type||`grid`,columns:e.columns,filter:e.filter,sort:e.sort,showSearch:e.showSearch,showFilters:e.showFilters,showSort:e.showSort,isPinned:e.isPinned,isDefault:e.isDefault,visibility:e.visibility,sortOrder:e.sortOrder,...e,id:t},r={};for(let[e,t]of Object.entries(n))t!==void 0&&(r[e]=t);if(s.has(t)){let e=o.findIndex(e=>e.id===t);o[e]=eg(t,o[e],r)}else o.push(eg(t,r))}return o}function Dg(e,t){let n=e.filter(e=>Qh(e)!==t&&e.isDefault).map(e=>({viewId:Qh(e),patch:{isDefault:!1}}));return n.push({viewId:t,patch:{isDefault:!0}}),n}function Og(e,t){let n=new Set(e.map(e=>Qh(e)));return t.filter(e=>n.has(e)).map((e,t)=>({viewId:e,patch:{sortOrder:t}}))}function kg(e,t,n){return n.map(({viewId:n,patch:r})=>e.updateView(t,n,r))}function Ag(e,t,n){if(n.isSavedView)return{...e||{},...t};let r=e?.viewKind;return r===void 0?{...t}:{...t,viewKind:r}}function jg({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let{objectName:i}=c(),{t:a}=G();return t.find(e=>e.name===i)?(0,$.jsx)(Mg,{dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}):(0,$.jsx)(`div`,{className:`h-full p-4 flex items-center justify-center`,children:(0,$.jsxs)(oi,{children:[(0,$.jsx)(`div`,{className:`mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,$.jsx)($t,{className:`h-6 w-6 text-muted-foreground`})}),(0,$.jsx)(Hi,{children:a(`console.objectView.objectNotFound`)}),(0,$.jsxs)(Wr,{children:[a(`console.objectView.objectNotFoundDescription`,{objectName:i}),` `,a(`console.objectView.objectNotFoundHint`)]})]})})}function Mg({dataSource:e,objects:t,onEdit:n,externalRefreshKey:r}){let i=p(),{appName:a,objectName:l,viewId:u}=c(),[d,f]=s(),m=o(),{showDebug:h}=Ec(),{t:g}=G(),{objectLabel:_,objectDescription:v,viewLabel:y,viewEmptyState:b,actionParamText:x,fieldLabel:S,fieldOptionLabel:T}=at(),E=pe(),{isFavorite:D,toggleFavorite:k}=ao(),A=Ws()===`group`,j=oa(),M=sa(),[ee,N]=(0,Q.useState)(!1),[te,P]=(0,Q.useState)(`edit`),[F,re]=(0,Q.useState)(!1),[I,ie]=(0,Q.useState)(!1),[L,ae]=(0,Q.useState)(null),oe=(0,Q.useRef)({}),R=(0,Q.useRef)({}),se=(0,Q.useRef)([]),B=(0,Q.useCallback)((t,n,r)=>{if(!e?.updateViewConfig||!l||!t)return;let i=R.current[t]||{};R.current[t]={...i,...r};let a=oe.current[t];a&&clearTimeout(a),oe.current[t]=setTimeout(()=>{let r=R.current[t]||{};delete R.current[t],delete oe.current[t];let i=$h(se.current,t);Promise.resolve(e.updateViewConfig(l,t,Ag(n,r,{isSavedView:i}),{isSavedView:i})).catch(e=>{if(z(e)){X.error(g(`console.objectView.viewConfigPermissionDenied`));return}console.error(`[ObjectView] Failed to persist view config:`,e)})},300)},[e,l]),ce=(0,Q.useCallback)(t=>{ae(t),U(e=>e+1);let n=t.id;j&&n?Ic(`view`,n,t,{metadataClient:j,dataSource:e,objectName:l}).catch(e=>{console.error(`[ViewConfigPanel] Failed to persist view config:`,e)}):console.warn(`[ViewConfigPanel] Cannot persist view config: missing metadataClient or viewId.`)},[j,e,l]),le=(0,Q.useCallback)(async n=>{try{let r;if(j){let i=t?.find?.(e=>e.name===l),a=Cg(i,5),o=Array.isArray(n.columns)&&n.columns.length>0?n.columns:a,s={...n,columns:o};if(n.type===`kanban`)s.kanban={...s.kanban||{},columns:o};else if(n.type===`gallery`){let e=s.gallery||{};(!Array.isArray(e.visibleFields)||e.visibleFields.length===0)&&(s.gallery={...e,visibleFields:o})}let c=Fc(l,s,{name:n?.name,label:n.label});r=await Lc(`view`,c.name,c,{metadataClient:j,dataSource:e,objectName:l})}if(N(!1),P(`edit`),U(e=>e+1),r){let e=M?``:`?${ia}=${la}`;u?i(`../${r}${e}`,{relative:`path`}):i(`view/${r}${e}`)}}catch(e){console.error(`[ViewConfigPanel] Failed to create view:`,e)}},[e,l,t,i,u,j,M]),[ue,de]=(0,Q.useState)(void 0),{user:fe,activeOrganization:me}=C(),{isAdmin:V}=w(),ve=O(),{can:be,getObjectApiOperations:xe}=ve,{systemPermissions:Se}=ve;(0,Q.useEffect)(()=>{e?.setSystemCapabilities?.(Se)},[e,Se]);let H=t.find(e=>e.name===l),[we,U]=(0,Q.useState)(0),W=Ua({dataSource:e,objects:t,objectName:H.name,onRefresh:()=>U(e=>e+1)}),{confirmHandler:Te,toastHandler:Ee}=W,De=H.name===`sys_environment`,Oe=og({enabled:De,dataSource:e,authFetch:W.authFetch,apiBase:``,refreshKey:we}),ke=(0,Q.useMemo)(()=>(H.actions||[]).map(e=>E(H.name,e)),[H,E]),Ae=Yo(e=>!De&&ke.some(t=>t?.name===e&&Re(t,`list_toolbar`))),Me=(0,Q.useMemo)(()=>Ae===null?ke:ke.map(e=>e?.name===Ae?{...e,autoTrigger:!0}:e),[ke,Ae]),Ne=(0,Q.useMemo)(()=>ye(H,xe(H.name)),[H,xe]);(0,Q.useEffect)(()=>{r!==void 0&&r!==0&&U(e=>e+1)},[r]);let Pe=Ne.create&&be(H.name,`create`),Fe=Pe?Ne.createPredicates:void 0,Ie=ge(Fe?.visibleWhen??!0,null,{fallback:!1,warnOnError:!0,label:`builtin:create:visibleWhen`}),Le=ge(Fe?.disabledWhen,null,{fallback:!1,warnOnError:!0,label:`builtin:create:disabledWhen`}),Be=Fe?.disabledWhen!=null&&Le,Ve=Ne.import&&be(H.name,`create`),He=Ve?Ne.importPredicates:void 0,Ue=ge(He?.visibleWhen??!0,null,{fallback:!1,warnOnError:!0,label:`builtin:import:visibleWhen`}),We=ge(He?.disabledWhen,null,{fallback:!1,warnOnError:!0,label:`builtin:import:disabledWhen`}),Ke=He?.disabledWhen!=null&&We,[Ye,Xe]=(0,Q.useState)(!1),{features:Ze}=xa(),Qe=H.name===`sys_user`&&Ze?.admin===!0&&V,[$e,et]=(0,Q.useState)(`auto`),tt=(0,Q.useRef)(`auto`);tt.current=$e;let nt=(0,Q.useMemo)(()=>Qe?Vh({base:e,authFetch:W.authFetch,baseUrl:``,getPasswordPolicy:()=>tt.current}):void 0,[Qe,e,W.authFetch]),[rt,it]=(0,Q.useState)([]);se.current=rt,(0,Q.useEffect)(()=>{let t=!1;if(!l){it([]);return}return typeof e?.listViews==`function`?(e.listViews(l,{previewDrafts:M}).then(e=>{if(t)return;let n=(e||[]).map(e=>({...e,id:Qh(e),objectName:e.objectName||e.object||l}));it(n)}).catch(e=>{console.error(`[ObjectView] Failed to load overlay views:`,e),t||it([])}),()=>{t=!0}):(it([]),()=>{t=!0})},[e,l,we,M]);let[ot,st]=(0,Q.useState)({});(0,Q.useEffect)(()=>{let t=!1;if(!e||!l){st({});return}let n=H.listViews||H.list_views||{},r=Object.keys(n),i=Zh(H.name,H.list);if(i&&!r.includes(i)&&r.unshift(i),r.length===0){st({});return}return Tg(e,l,r).then(e=>{t||st(e)}),()=>{t=!0}},[e,l,H.listViews,H.list_views,H.list,we]);let ct=(0,Q.useMemo)(()=>{let e=()=>Cg(H,5,{orgAttribution:A}),t=Eg({definedViews:H.listViews||H.list_views||{},primary:H.list,primaryId:Zh(H.name,H.list),savedViews:rt,viewOverrides:ot,fallbackTab:()=>({id:`all`,label:g(`console.objectView.allRecords`),type:`grid`,columns:e()})}),n=new Set([`grid`,`list`,`table`]);for(let r of t)n.has(r.type)&&(!Array.isArray(r.columns)||r.columns.length===0)&&(r.columns=e());let r=new Map(t.map((e,t)=>[e.id,t])),i=[];try{let e=typeof window<`u`?window.localStorage?.getItem(`viewOrder:${H.name}`):null;e&&(i=JSON.parse(e))}catch{}let a=new Map(i.map((e,t)=>[e,t]));return t.sort((e,t)=>{let n=a.get(e.id),i=a.get(t.id);if(n!==void 0&&i!==void 0)return n-i;if(n!==void 0)return-1;if(i!==void 0)return 1;let o=rt.find(t=>Qh(t)===e.id),s=rt.find(e=>Qh(e)===t.id),c=o&&typeof o.sortOrder==`number`,l=s&&typeof s.sortOrder==`number`;return c&&l?o.sortOrder===s.sortOrder?(o.created_at||``).localeCompare(s.created_at||``):o.sortOrder-s.sortOrder:c?-1:l?1:(r.get(e.id)??0)-(r.get(t.id)??0)}),t},[H,rt,ot,g,A]),lt=(0,Q.useMemo)(()=>ct.find(e=>e.isDefault)?.id,[ct]),ut=u||d.get(`view`)||void 0,dt=(0,Q.useMemo)(()=>Ge(ut,ct.map(e=>e.id),H.name),[ut,ct,H.name]);(0,Q.useEffect)(()=>{ut&&!dt&&console.warn(`[ObjectView] Requested view "${ut}" not found on object "${H.name}"; falling back to the default view. Known views: ${ct.map(e=>e.id).join(`, `)}`)},[ut,dt,H.name,ct]);let ft=dt||lt||ct[0]?.id,pt=ct.find(e=>e.id===ft)||ct[0],mt=L&&L.id===pt?.id?{...pt,...L}:pt,ht=(0,Q.useCallback)((e,t)=>{ae(n=>({...n||{},id:pt?.id,[e]:t}))},[pt?.id]),K=e=>{let t=ct.find(t=>t.id===e);t&&(t.id!==ft&&N(!1),u?i(`../${t.id}`,{relative:`path`}):i(`view/${t.id}`))},gt=(0,Q.useMemo)(()=>(ct||[]).map(e=>{let t=mg[e.type];return{id:e.id,label:y(H.name,e.name||e.id,e.label||e.name||e.id),icon:t?(0,$.jsx)(t,{className:`h-4 w-4`}):void 0}}),[ct,H.name,y]);pd({views:gt,activeViewId:ft??``,onChange:K,enabled:gt.length>0&&!!ft});let _t=(0,Q.useCallback)(()=>{re(!0)},[]),vt=(0,Q.useCallback)((e,t)=>{if(e===`settings`){let e=ct.find(e=>e.type===t);e&&K(e.id),P(`edit`),N(!0)}},[ct,K]),yt=(0,Q.useCallback)(e=>$h(rt,e),[rt]),bt=(0,Q.useCallback)(async(t,n)=>{if(!yt(t)){X.error(g(`console.objectView.cannotEditMetaView`));return}try{typeof e?.updateView==`function`&&await e.updateView(l,t,{label:n}),U(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to rename view:`,e),X.error(g(`objectViewActions.renameFailed`))}},[e,l,yt,g]),xt=(0,Q.useCallback)(async t=>{if(!e)return;if(!yt(t)){X.error(g(`console.objectView.cannotDeleteMetaView`));return}let n=ct.find(e=>e.id===t)?.label||t;if(await Te(g(`console.objectView.deleteViewConfirm`,{name:n}),{title:g(`console.objectView.deleteViewTitle`),confirmText:g(`console.objectView.delete`),cancelText:g(`console.objectView.cancel`)}))try{if(typeof e?.deleteView==`function`&&await e.deleteView(l,t),t===ft){let e=ct.find(e=>e.id!==t);e&&i(u?`../${e.id}`:`view/${e.id}`,u?{relative:`path`}:void 0)}U(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to delete view:`,e),X.error(g(`objectViewActions.deleteFailed`))}},[e,yt,ft,ct,u,i,g,Te]),St=(0,Q.useCallback)(async(t,n)=>{if(e){if(!yt(t)){X.error(g(`console.objectView.cannotEditMetaView`));return}try{typeof e?.updateView==`function`&&await e.updateView(l,t,{isPinned:n}),U(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to pin view:`,e)}}},[e,l,yt,g]),wt=(0,Q.useCallback)(async t=>{if(!(!e||!l)){if(!yt(t)){X.error(g(`console.objectView.cannotEditMetaView`));return}try{if(typeof e?.updateView!=`function`)return;await Promise.all(kg(e,l,Dg(rt,t))),U(e=>e+1)}catch(e){console.error(`[ViewTabBar] Failed to set default view:`,e),X.error(`Failed to set default view`)}}},[e,l,rt,yt,g]),Tt=(0,Q.useCallback)(async t=>{try{typeof window<`u`&&window.localStorage?.setItem(`viewOrder:${l}`,JSON.stringify(t))}catch{}if(l&&typeof e?.updateView==`function`){let n=kg(e,l,Og(rt,t));try{await Promise.all(n)}catch(e){console.error(`[ViewTabBar] Failed to reorder views:`,e)}}U(e=>e+1)},[e,rt,l]),Et=(0,Q.useCallback)(e=>{if(!yt(e)){X.error(g(`console.objectView.cannotEditMetaView`));return}e!==ft&&K(e),P(`edit`),N(!0)},[ft,K,yt,g]),Dt=(0,Q.useCallback)(()=>{re(!0)},[]),Ot=fe?{id:fe.id,name:fe.name,avatar:fe.image}:hg,kt=(0,Q.useMemo)(()=>({currentUserId:Ot.id,currentOrgId:me?.id??null}),[Ot.id,me?.id]),At=tu({objectName:H.name,objectLabel:H.label,dataSource:e,onEdit:n,onRefresh:()=>U(e=>e+1),onConfirm:Te,onToast:Ee}),{lastMessage:jt}=io({channel:`object:${H.name}`}),Mt=H.name?`user-${H.name}`:`current-user`,{hasConflicts:Nt,resolveAllConflicts:Pt}=Wa(Mt);(0,Q.useEffect)(()=>{jt&&(Nt&&Pt(`remote`),U(e=>e+1))},[jt,Nt,Pt]),(0,Q.useEffect)(()=>{e?.find&&H.name&&e.find(H.name,{$top:0}).then(e=>{typeof e?.total==`number`&&de(e.total)}).catch(()=>{})},[e,H.name,we]);let Ft=(0,Q.useMemo)(()=>{let e=mt?.navigation??H.navigation;return e?e.mode===`page`?e:{...e,width:e.width??Cc(e.size,H)}:ne(H)===`page`?{mode:`page`}:{mode:`drawer`,width:Cc(`auto`,H)}},[mt?.navigation,H]),It=d.get(Ka),Lt=Array.from(d.entries()).filter(([e])=>e.startsWith(`filter[`)).map(([e,t])=>`${e}=${t}`).join(`&`),Rt=(0,Q.useMemo)(()=>{let e=[];return new URLSearchParams(Lt).forEach((t,n)=>{let r=/^filter\[(.+)\]$/.exec(n);r&&r[1]&&t!==``&&e.push([r[1],`=`,t])}),e},[Lt]),[zt]=(0,Q.useState)(()=>Ks(new URLSearchParams(window.location.search))),q=(0,Q.useCallback)(e=>{f(t=>Gs(t,e),{replace:!0})},[f]),Bt=(0,Q.useCallback)((e,t)=>{if(t===`new_window`){window.open(bg(window.location.pathname,e),`_blank`);return}let n={from:{pathname:m.pathname+(m.search||``),label:y(H.name,mt?.name??``,mt?.label??``)||_(H)}};u?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:n}):i(`record/${encodeURIComponent(String(e))}`,{state:n})},[i,u,m.pathname,m.search,H,mt?.name,mt?.label,y,_]),Vt=(0,Q.useMemo)(()=>Sg(H.name,Bt),[H.name,Bt]),Ht=qe({navigation:Ft,objectName:H.name,onNavigate:Bt}),Ut=()=>{Ht.close();let e=new URLSearchParams(d);e.delete(Ka),f(e)},Wt=(0,Q.useCallback)((e,t)=>{if(t&&(t.metaKey||t.ctrlKey||t.button===1)){Ht.handleClick(e,t);return}if(Ht.mode===`drawer`){let t=e?.id??e?._id;if(t!=null){let e=new URLSearchParams(d);e.set(Ka,String(t)),f(e);return}}Ht.handleClick(e,t)},[Ht,d,f]),Gt=(0,Q.useCallback)(()=>{let e=Ht.selectedRecord,t=e&&(e.id??e._id);t!=null&&(Ut(),Bt(t))},[Ht.selectedRecord,Bt]);(0,Q.useEffect)(()=>{It&&!Ht.isOpen?Ht.open({id:It}):!It&&Ht.isOpen&&Ht.close()},[It]);let Kt=(0,Q.useCallback)(({schema:e,dataSource:t,onEdit:n,className:r,refreshKey:i})=>{let a=we+(i||0),o=`${l}-${mt.id}-${a}`,s=mt,c=wh(fe?.id,l,mt.id),u=Dh(c);if(s.type===`chart`){let e=s.chart||{};if(e.dataset){let n=Array.isArray(e.dimensions)?e.dimensions:[],r=Array.isArray(e.values)?e.values:[];return(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,$.jsx)(fg,{dataSource:t,schema:{type:`object-chart`,dataset:e.dataset,dimensions:n,values:r,chartType:e.chartType||`bar`,xAxisKey:n[0],series:r.map(e=>({dataKey:e,label:e})),config:e.config,className:`h-[400px] w-full`}})},o)}let n=e.xAxisField||`name`,r=Array.isArray(e.yAxisFields)&&e.yAxisFields[0]||`value`,i=e.aggregation||`count`,a=e.series&&e.series.length>0?e.series:[{dataKey:r,label:r}];return(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(`div`,{className:`p-4 text-sm text-muted-foreground`,children:`Loading chart…`}),children:(0,$.jsx)(fg,{dataSource:t,schema:{type:`object-chart`,objectName:H.name,chartType:e.chartType||`bar`,aggregate:{field:r,function:i,groupBy:n},xAxisKey:n,series:a,config:e.config,filter:e.filter,className:`h-[400px] w-full`}})},o)}rg(H.name,s.id||s.name||``,s,e);let d=vg(s),f={...e,label:s.label??e.label,description:s.description??e.description,rowHeight:s.rowHeight??e.rowHeight,densityMode:s.densityMode??e.densityMode,sort:s.sort??e.sort,filter:(()=>{let t=s.filter??e.filter,n=Array.isArray(t)?t:t?[t]:[];return gg(Rt.length?[...n,...Rt]:t,kt)})(),hiddenFields:s.hiddenFields??e.hiddenFields,columnState:s.columnState??e.columnState,onDensityChange:e=>{B(s.id,s,{rowHeight:Ce[e]})},onSortChange:e=>{B(s.id,s,{sort:e})},onHiddenFieldsChange:e=>{B(s.id,s,{hiddenFields:e})},onColumnStateChange:e=>{B(s.id,s,{columnState:e})},inlineEdit:s.inlineEdit??s.editRecordsInline??e.inlineEdit,appearance:s.appearance?s.showDescription==null?s.appearance:{...s.appearance,showDescription:s.showDescription}:s.showDescription==null?e.appearance:{showDescription:s.showDescription},showViewSwitcher:((s.appearance??e.appearance)?.allowedVisualizations?.length??0)>1,userActions:{...Je(e??{}).userActions,...Je(s??{}).userActions},allowExport:s.allowExport??e.allowExport,exportOptions:s.allowExport===!1?void 0:s.exportOptions??e.exportOptions,color:s.color??e.color,rowColor:s.rowColor??e.rowColor,wrapHeaders:s.wrapHeaders??e.wrapHeaders,clickIntoRecordDetails:s.clickIntoRecordDetails??e.clickIntoRecordDetails,addRecordViaForm:s.addRecordViaForm??e.addRecordViaForm,addDeleteRecordsInline:s.addDeleteRecordsInline??e.addDeleteRecordsInline,collapseAllByDefault:s.collapseAllByDefault??e.collapseAllByDefault,fieldTextColor:s.fieldTextColor??e.fieldTextColor,prefixField:s.prefixField??e.prefixField,data:s.data??e.data,navigation:s.navigation??e.navigation,selection:s.selection??e.selection,pagination:s.pagination??e.pagination,searchableFields:s.searchableFields??e.searchableFields,filterableFields:s.filterableFields??e.filterableFields,resizable:s.resizable??e.resizable,rowActions:s.rowActions??e.rowActions,rowActionDefs:Array.isArray(H?.actions)?H.actions.filter(e=>Array.isArray(e?.locations)&&e.locations.includes(`list_item`)).map(e=>E(H.name,e)):[],bulkActions:s.bulkActions??e.bulkActions,bulkActionDefs:s.bulkActionDefs??e.bulkActionDefs,sharing:s.sharing??e.sharing,addRecord:s.addRecord??e.addRecord,conditionalFormatting:s.conditionalFormatting??e.conditionalFormatting,quickFilters:void 0,userFilters:(()=>{let t=s.userFilters??e.userFilters;return t&&t.element!==`tabs`&&t.tabs==null?t:void 0})(),showRecordCount:s.showRecordCount??e.showRecordCount,allowPrinting:s.allowPrinting??e.allowPrinting,emptyState:b(H.name,s.name||s.id||``,s.emptyState??e.emptyState??Xh(H?.managedBy,g,H.name,H?.userActions)),aria:s.aria??e.aria,...s.sort?.length?{sort:s.sort}:{},options:{kanban:{...(()=>{let e=s.kanban?.groupByField||s.kanban?.groupField||he(H)||void 0;return e?{groupBy:e,groupField:e}:{}})(),titleField:s.kanban?.titleField||`name`,cardFields:s.kanban?.columns},...d?{calendar:d}:{},timeline:_g(s),map:{locationField:s.map?.locationField,titleField:s.map?.titleField||`name`,latitudeField:s.map?.latitudeField,longitudeField:s.map?.longitudeField,zoom:s.map?.zoom,center:s.map?.center},gallery:{...s.gallery||{},imageField:s.gallery?.imageField||s.gallery?.coverField||`image`,coverField:s.gallery?.coverField||s.gallery?.imageField,titleField:s.gallery?.titleField||`name`},gantt:yg(s),tree:{...s.tree||{},labelField:s.tree?.labelField||s.tree?.titleField||`name`},chart:{chartType:s.chart?.chartType,xAxisField:s.chart?.xAxisField,yAxisFields:s.chart?.yAxisFields,aggregation:s.chart?.aggregation,series:s.chart?.series,config:s.chart?.config}}};return(0,$.jsx)(xc,{schema:f,className:r,onEdit:n,onDelete:e=>{e?.id!=null&&At.deleteRecord(String(e.id),e)},onBulkDelete:e=>{let t=e.filter(e=>e?.id!=null);t.length!==0&&At.execute({type:`delete`,confirmText:g(`console.objectView.bulkDeleteConfirm`,{count:t.length,defaultValue:`Delete ${t.length} selected records? This cannot be undone.`}),params:{records:t}})},onRowClick:(e,t)=>{Wt(e,t)},onSortChange:e=>{B(s.id,s,{sort:e})},onFilterChange:e=>{Ah(c,{filters:e})},onSearchChange:e=>{Ah(c,{search:e})},onHiddenFieldsChange:e=>{B(s.id,s,{hiddenFields:e})},onInlineEditChange:e=>{B(s.id,s,{inlineEdit:e})},onColumnStateChange:e=>{B(s.id,s,{columnState:e})},userFilterSelections:zt,onUserFilterSelectionsChange:q,initialFilters:u?.filters,initialSearchTerm:u?.search,dataSource:t},o)},[mt,H,l,we,Ht,At,B,Rt,zt,q,fe?.id]),qt=(0,Q.useMemo)(()=>ct.map(e=>e.id===ft&&L&&L.id===e.id?{...e,...L}:e),[ct,ft,L]),Jt=(0,Q.useMemo)(()=>({type:`object-view`,objectName:H.name,layout:`page`,showSearch:mt?.showSearch!==!1,showFilters:mt?.showFilters!==!1,showSort:mt?.showSort!==!1,showCreate:!1,allowCreateView:V,viewActions:V?[{type:`settings`},{type:`share`},{type:`delete`}]:[],onNavigate:(e,t)=>{if(t===`edit`)n?.({id:e});else if(t===`view`){let t={from:{pathname:m.pathname+(m.search||``),label:y(H.name,mt?.name??``,mt?.label??``)||_(H)}};u?i(`../../record/${encodeURIComponent(String(e))}`,{relative:`path`,state:t}):i(`record/${encodeURIComponent(String(e))}`,{state:t})}}}),[H,n,mt?.showSearch,mt?.showFilters,mt?.showSort,mt?.name,mt?.label,i,u,V,m.pathname,m.search,y,_]);return(0,$.jsx)(je,{...W.actionProviderProps,children:(0,$.jsxs)(_e,{value:Vt,children:[(0,$.jsxs)(`div`,{className:`h-full flex flex-col bg-background min-w-0 overflow-hidden`,children:[(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(yc,{title:(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:_(H)}),(0,$.jsx)(zc,{managedBy:H?.managedBy})]}),subtitle:H.description?v(H):void 0,icon:(()=>{let e=qs(H?.icon);return(0,$.jsx)(e,{className:`h-4 w-4`})})(),actions:(0,$.jsxs)($.Fragment,{children:[l&&(0,$.jsx)(J,{size:`sm`,variant:`ghost`,onClick:()=>k({id:`object:${l}`,label:_(H),href:`/apps/${a}/${l}`,type:`object`}),className:`h-8 sm:h-9 px-2`,"aria-pressed":D(`object:${l}`),"aria-label":D(`object:${l}`)?g(`common.removeFromFavorites`,{defaultValue:`Remove from favorites`}):g(`common.addToFavorites`,{defaultValue:`Add to favorites`}),"data-testid":`object-favorite-btn-${l}`,children:D(`object:${l}`)?(0,$.jsx)(Cn,{className:`h-4 w-4 fill-amber-400 text-amber-400`}):(0,$.jsx)(Zi,{className:`h-4 w-4`})}),Pe&&Ie&&(0,$.jsxs)(J,{size:`sm`,onClick:At.create,disabled:Be,className:`shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,"data-testid":`object-view-new-button`,children:[(0,$.jsx)(Ct,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:g(`console.objectView.new`)})]}),(Qe||Ve&&Ue)&&(0,$.jsxs)(J,{size:`sm`,variant:`outline`,onClick:()=>Xe(!0),disabled:Ke,className:`hidden sm:inline-flex shadow-none gap-1.5 sm:gap-2 h-8 sm:h-9`,title:g(`console.objectView.importTitle`),"data-testid":`object-view-import-button`,children:[(0,$.jsx)(Br,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`hidden sm:inline`,children:g(`console.objectView.import`)})]}),H.actions?.some(e=>e.locations?.includes(`list_toolbar`))&&(De?(0,$.jsx)(dg,{actions:ke,entitlements:Oe,onUpgrade:W.openEntitlementDialog}):(0,$.jsx)(ze,{schema:{type:`action:bar`,location:`list_toolbar`,actions:Me,size:`sm`,variant:`outline`,mobileMaxVisible:0}}))]})})}),Pe&&Ie&&(0,$.jsx)(`button`,{type:`button`,onClick:At.create,disabled:Be,className:`sm:hidden fixed right-4 bottom-36 z-40 h-12 w-12 rounded-full bg-primary text-primary-foreground shadow-lg active:scale-95 transition-transform inline-flex items-center justify-center disabled:opacity-50 disabled:pointer-events-none`,"aria-label":g(`console.objectView.new`),"data-testid":`mobile-fab-create`,children:(0,$.jsx)(Ct,{className:`h-5 w-5`})}),Ye&&(0,$.jsx)(Q.Suspense,{fallback:null,children:(0,$.jsx)(pg,{open:Ye,onOpenChange:Xe,objectName:H.name,objectLabel:_(H),fields:Qe?qh(H.fields):Yh(H.name,H.fields,ve),dataSource:nt??e,...Qe?{extraOptionsContent:(0,$.jsx)(Gh,{policy:$e,onPolicyChange:et}),renderResultExtra:e=>(0,$.jsx)(Kh,{serverResult:e?.serverResult})}:{},onComplete:e=>{U(e=>e+1);let t=e.importedRows,n=e.skippedRows;n>0?X.warning(g(`console.objectView.importedWithSkipped`,{ok:t,skipped:n})):t>0&&X.success(g(`console.objectView.importedToast`,{count:t}))}})}),ct.length>=1&&(()=>{let e=ct.map(e=>{let t=rt.find(t=>Qh(t)===e.id),n=!t;return{id:e.id,label:y(H.name,e.name||e.id,e.label||e.name||e.id),type:e.type,hasActiveFilters:Array.isArray(e.filter)&&e.filter.length>0,hasActiveSort:Array.isArray(e.sort)&&e.sort.length>0,isDefault:!!(t?.isDefault??e.isDefault),isPinned:!!(t?.isPinned??e.isPinned),visibility:t?.visibility??e.visibility,readonly:n,readonlyReason:n?g(`console.objectView.systemViewReadonly`):void 0}});return(0,$.jsx)($.Fragment,{children:(0,$.jsxs)(`div`,{className:`hidden sm:block border-b px-3 sm:px-4 bg-background overflow-x-auto shrink-0`,children:[(0,$.jsx)(wc,{views:e,activeViewId:ft,onViewChange:K,viewTypeIcons:mg,config:{reorderable:!1,showAddButton:V,showPinnedSection:!0,showVisibilityGroups:!0},onAddView:V?Dt:void 0,onRenameView:V?bt:void 0,onDeleteView:V?xt:void 0,onPinView:V?St:void 0,onSetDefaultView:V?wt:void 0,onConfigView:V?Et:void 0,onManageViews:V?()=>ie(!0):void 0}),V&&(0,$.jsx)(Sc,{open:I,onOpenChange:ie,views:e,activeViewId:ft,viewTypeIcons:mg,onRename:bt,onDelete:xt,onSetDefault:wt,onSetPinned:St,onReorder:Tt,onAddView:Dt,onConfigView:Et})]})})})(),(0,$.jsxs)(`div`,{className:`flex-1 overflow-hidden relative flex flex-row`,children:[Ht.mode===`split`&&Ht.isOpen?(0,$.jsx)(wr,{...Ht,setIsOpen:e=>{e||Ut()},title:_(H),onExpand:Gt,expandLabel:g(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${H.name}`,mainContent:(0,$.jsxs)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:[(0,$.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,$.jsx)(Tc,{schema:Jt,dataSource:e,views:qt,activeViewId:ft,onViewChange:K,onEdit:e=>n?.(e),onRowClick:(e,t)=>{Wt(e,t)},renderListView:Kt,onCreateView:_t,hideNamedViewTabs:!0,onViewAction:vt})})}),typeof ue==`number`&&(0,$.jsx)(`div`,{"data-testid":`record-count-footer`,className:`border-t px-3 sm:px-4 py-1.5 text-xs text-muted-foreground bg-muted/5 shrink-0`,children:g(`console.objectView.recordCount`,{count:ue})})]}),children:r=>{let i=r.id||r._id;return(0,$.jsx)(no,{dataSource:e,objects:t,onEdit:n,objectNameOverride:H.name,recordIdOverride:i,embedded:!0})}}):(0,$.jsx)(`div`,{className:`flex-1 min-w-0 relative h-full flex flex-col`,children:(0,$.jsx)(`div`,{className:`flex-1 relative overflow-hidden`,children:(0,$.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,$.jsx)(Tc,{schema:Jt,dataSource:e,views:qt,activeViewId:ft,onViewChange:K,onEdit:e=>n?.(e),onRowClick:(e,t)=>{Wt(e,t)},renderListView:Kt,onCreateView:_t,hideNamedViewTabs:!0,onViewAction:vt})})})}),(0,$.jsx)(Dc,{open:h&&V,sections:[{title:`View Configuration`,data:mt},{title:`Object Definition`,data:H}]}),(0,$.jsx)(`div`,{"data-testid":`view-config-panel-wrapper`,className:`transition-[max-width,opacity] duration-300 ease-in-out overflow-hidden ${ee&&V?`max-w-[280px] opacity-100`:`max-w-0 opacity-0`}`,children:(0,$.jsx)(Ih,{open:ee&&V,onClose:()=>{N(!1),P(`edit`)},mode:te,activeView:mt,objectDef:H,recordCount:ue,onSave:ce,onViewUpdate:ht,onCreate:le,metadataClient:j,dataSource:e,onAfterChange:()=>U(e=>e+1)})}),(0,$.jsx)(bc,{open:F&&V,onOpenChange:re,existingLabels:ct.map(e=>e.label).filter(Boolean),objectDef:H,onCreate:e=>le(e)})]}),Ht.mode!==`split`&&(0,$.jsx)(wr,{...Ht,setIsOpen:e=>{e||Ut()},title:_(H),onExpand:Gt,expandLabel:g(`console.objectView.expandToPage`,{defaultValue:`Open as full page`}),storageKey:`drawer-width:${H.name}`,children:r=>{let i=r.id||r._id;return(0,$.jsx)(no,{dataSource:e,objects:t,onEdit:n,objectNameOverride:H.name,recordIdOverride:i,embedded:!0})}})]}),W.dialogs]})})}function Ng({appName:e,error:t,onRetry:n}){let{t:r}=G(),i=!!t;return(0,$.jsx)(`div`,{className:`flex h-screen items-center justify-center`,"data-testid":`preview-draft-empty-state`,children:(0,$.jsxs)(oi,{children:[(0,$.jsx)(`div`,{className:`mb-2 flex justify-center text-muted-foreground`,"aria-hidden":`true`,children:i?(0,$.jsx)(Ji,{className:`h-8 w-8`}):(0,$.jsx)(Dn,{className:`h-8 w-8`})}),(0,$.jsx)(Hi,{children:i?r(`preview.empty.loadFailedTitle`,{defaultValue:`Draft preview failed to load`}):e?r(`preview.empty.notReadyTitle`,{app:e,defaultValue:`“{{app}}” isn’t in the draft yet`}):r(`preview.empty.nothingTitle`,{defaultValue:`Nothing to preview yet`})}),(0,$.jsx)(Wr,{children:i?r(`preview.empty.loadFailedDescription`,{defaultValue:`The draft overlay could not be read. Retry, or check your connection.`}):r(`preview.empty.notReadyDescription`,{defaultValue:`The build may still be running, or it may have failed before this app was staged. Check the conversation for the build status — this pane refreshes as drafts land.`})}),(0,$.jsx)(`div`,{className:`mt-4 flex justify-center`,children:(0,$.jsxs)(J,{variant:`outline`,onClick:n,"data-testid":`preview-draft-retry`,children:[(0,$.jsx)(zi,{className:`mr-1.5 h-3.5 w-3.5`}),r(`preview.empty.retry`,{defaultValue:`Retry`})]})})]})})}I();var Pg=(0,Q.lazy)(()=>t(()=>import(`./RecordDetailView-A8bbPnkK.js`).then(e=>e.n).then(e=>({default:e.RecordDetailView})),__vite__mapDeps([0]),import.meta.url)),Fg=(0,Q.lazy)(()=>t(()=>import(`./DashboardView-UyKHklBx.js`).then(e=>({default:e.DashboardView})),__vite__mapDeps([0,1]),import.meta.url)),Ig=(0,Q.lazy)(()=>t(()=>import(`./PageView-B1_ibRuM.js`).then(e=>({default:e.PageView})),__vite__mapDeps([0]),import.meta.url)),Lg=(0,Q.lazy)(()=>t(()=>import(`./ReportView-BTMrtcGH.js`).then(e=>({default:e.ReportView})),__vite__mapDeps([0,1]),import.meta.url)),Rg=(0,Q.lazy)(()=>t(()=>import(`./SearchResultsPage-CHhZUc6L.js`).then(e=>({default:e.SearchResultsPage})),__vite__mapDeps([0]),import.meta.url)),zg=(0,Q.lazy)(()=>t(()=>import(`./RecordFormPage-CGQlYWDk.js`).then(e=>({default:e.RecordFormPage})),__vite__mapDeps([0]),import.meta.url)),Bg=(0,Q.lazy)(()=>t(()=>import(`./ComponentNavView-C84QByT7.js`).then(e=>({default:e.ComponentNavView})),__vite__mapDeps([0]),import.meta.url)),Vg=(0,Q.lazy)(()=>t(()=>import(`./ObjectDataPage-CP-YSZYQ.js`).then(e=>({default:e.ObjectDataPage})),__vite__mapDeps([0]),import.meta.url)),Hg=(0,Q.lazy)(()=>t(()=>import(`./metadata-admin-pawEBYI9.js`).then(e=>({default:e.MetadataDirectoryPage})),__vite__mapDeps([0]),import.meta.url)),Ug=(0,Q.lazy)(()=>t(()=>import(`./metadata-admin-pawEBYI9.js`).then(e=>({default:e.StudioHomePage})),__vite__mapDeps([0]),import.meta.url)),Wg=(0,Q.lazy)(()=>t(()=>import(`./metadata-admin-pawEBYI9.js`).then(e=>({default:e.MetadataResourceListPage})),__vite__mapDeps([0]),import.meta.url)),Gg=(0,Q.lazy)(()=>t(()=>import(`./metadata-admin-pawEBYI9.js`).then(e=>({default:e.MetadataResourceEditPage})),__vite__mapDeps([0]),import.meta.url)),Kg=(0,Q.lazy)(()=>t(()=>import(`./metadata-admin-pawEBYI9.js`).then(e=>({default:e.MetadataResourceHistoryPage})),__vite__mapDeps([0]),import.meta.url)),qg=(0,Q.lazy)(()=>t(()=>import(`./metadata-admin-pawEBYI9.js`).then(e=>({default:e.MetadataDiagnosticsPage})),__vite__mapDeps([0]),import.meta.url)),Jg=(0,Q.lazy)(()=>t(()=>import(`./src-_DxAIBqo.js`).then(e=>({default:e.CreateAppPage})),__vite__mapDeps([0]),import.meta.url)),Yg=(0,Q.lazy)(()=>t(()=>import(`./src-_DxAIBqo.js`).then(e=>({default:e.EditAppPage})),__vite__mapDeps([0]),import.meta.url)),Xg=(0,Q.lazy)(()=>t(()=>import(`./src-_DxAIBqo.js`).then(e=>({default:e.DashboardDesignPage})),__vite__mapDeps([0]),import.meta.url)),Zg=(0,Q.lazy)(()=>t(()=>import(`./MarketplacePage-wJb6g1p7.js`).then(e=>e.t).then(e=>({default:e.MarketplacePage})),__vite__mapDeps([0]),import.meta.url)),Qg=(0,Q.lazy)(()=>t(()=>import(`./MarketplacePackagePage-dCIVHBFi.js`).then(e=>e.t).then(e=>({default:e.MarketplacePackagePage})),__vite__mapDeps([0]),import.meta.url)),$g=(0,Q.lazy)(()=>t(()=>import(`./MarketplaceInstalledPage-DA5pjhAz.js`).then(e=>e.t).then(e=>({default:e.MarketplaceInstalledPage})),__vite__mapDeps([0]),import.meta.url));function e_({appName:e}){let{reviewSeq:t,reviewTarget:n}=_a(),r=p(),i=(0,Q.useRef)(t);return(0,Q.useEffect)(()=>{if(t===i.current||!n||!e)return;i.current=t;let{type:a,name:o}=n;r(`/apps/${e}/metadata/${encodeURIComponent(a)}/${encodeURIComponent(o)}?review=1`)},[t,n,e,r]),null}function t_({extraRoutes:e,extraRoutesNoApp:t}={}){let[n,r]=(0,Q.useState)(`disconnected`),{user:i,getAuthConfig:a,activeOrganization:l}=C(),{isAdmin:d,isResolved:f}=w(),m=Ue(),[_,v]=(0,Q.useState)({});(0,Q.useEffect)(()=>{let e=!1;return a().then(t=>{e||v(t?.features??{})}).catch(()=>{}),()=>{e=!0}},[a]);let y=p(),b=o(),{appName:x}=c(),{apps:S,objects:T,loading:E,ensureType:D,error:O,refresh:k}=be(),A=sa(),{t:j}=G(),{objectLabel:M}=at(),[ee,N]=(0,Q.useState)(!D);(0,Q.useEffect)(()=>{if(!D){N(!0);return}let e=!1;return Promise.all([D(`object`),D(`dashboard`),D(`report`),D(`page`)]).finally(()=>{e||N(!0)}),()=>{e=!0}},[D]);let te=S.filter(e=>e.active!==!1).filter(e=>e.hidden!==!0),P=b.pathname.split(`/`),F=b.pathname.endsWith(`/create-app`),re=P.includes(`system`),I=P.includes(`metadata`),ie=b.pathname===`/apps/setup`||b.pathname.startsWith(`/apps/setup/`),L=F||re||I||ie,oe=so(S,x),R=oe||(!x||L?te.find(e=>e.isDefault===!0)||te[0]:void 0),se=!!x&&!oe&&!L,[z,B]=(0,Q.useState)(null),ce=z&&z.app===x?z.phase:`idle`;(0,Q.useEffect)(()=>{if(!se){z!==null&&B(null);return}if(ce===`idle`&&!E&&!A&&x){let e=x;B({app:e,phase:`checking`}),Promise.resolve(k()).finally(()=>B(t=>t?.app===e?{app:e,phase:`done`}:t))}},[se,E,A,ce,z,x,k]);let[le,ue]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!se||A||ce!==`done`||!x){ue(e=>e===null?e:null);return}if(le?.app===x)return;let e=m?.probeAppAccess;if(typeof e!=`function`){ue({app:x,verdict:`unknown`});return}let t=!1,n=x;return Promise.resolve(e.call(m,n)).then(e=>{t||ue({app:n,verdict:e})}).catch(()=>{t||ue({app:n,verdict:`unknown`})}),()=>{t=!0}},[se,A,ce,x,le,m]);let de=le&&le.app===x?le.verdict:null;(0,Q.useEffect)(()=>{if(!R?.name)return;let e=x??R.name,t=`/apps/${e}/metadata/package`;(b.pathname===t||b.pathname.startsWith(`${t}/`))&&y(`/apps/${e}/component/developer/packages`,{replace:!0})},[R?.name,x,b.pathname,y]);let[fe,pe]=s(),me=fe.get(qa),V=fe.get(ro),he=fe.get(Za),ge=(0,Q.useMemo)(()=>me&&me!==`new`?{id:me}:null,[me]),_e=(0,Q.useMemo)(()=>{if(!he)return;let e=he.indexOf(`:`);if(!(e<=0))return{[he.slice(0,e)]:he.slice(e+1)}},[he]),[ve,ye]=(0,Q.useState)(0),xe=!!me,Se=(0,Q.useCallback)(()=>{let e=new URLSearchParams(window.location.search);!e.has(`form`)&&!e.has(`formObject`)&&!e.has(`formLink`)||(e.delete(qa),e.delete(ro),e.delete(Za),pe(e,{replace:!0}))},[pe]),{execute:Ce,runner:H}=Pe();Me(m),Ve({dataSource:m??void 0,onUndo:e=>{X.info(`Undo: ${e.description}`,{duration:4e3}),ye(e=>e+1),e?.objectName&&ke({objectName:e.objectName,recordId:e.recordId})},onRedo:e=>{X.info(`Redo: ${e.description}`,{duration:3e3}),ye(e=>e+1),e?.objectName&&ke({objectName:e.objectName,recordId:e.recordId})}}),(0,Q.useEffect)(()=>{H.registerHandler(`crud_success`,async e=>(Se(),ye(e=>e+1),X.success(e.params?.message??`Record saved successfully`),{success:!0,reload:!0})),H.registerHandler(`dialog_cancel`,async()=>(Se(),{success:!0})),H.registerHandler(`navigate_create`,async e=>{let t=H.getContext?.()??{},n=Na({action:e,context:t,defaultBaseUrl:`/apps/${x??``}`});return n.success?(y(n.url),{success:!0}):n}),H.registerHandler(`navigate_edit`,async e=>{let t=H.getContext?.()??{},n=Ma({action:e,context:t,defaultBaseUrl:`/apps/${x??``}`});return n.success?(y(n.url),{success:!0}):n})},[H,y,x,Se]),(0,Q.useEffect)(()=>{if(!m)return;let e=m.onConnectionStateChange(e=>{r(e.state),e.error&&console.error(`[Console] Connection error:`,e.error)});return r(m.getConnectionState()),e},[m]);let we=b.pathname.split(`/`).filter(Boolean)[2];(we===`view`||we===`record`||we===`page`||we===`dashboard`||we===`design`)&&(we=``);let U=T.find(e=>e.name===we),W=V?T.find(e=>e.name===V):U,Te=!!V&&V!==U?.name,Ee=(0,Q.useCallback)(()=>{let e=W?M(W):j(`common.record`,{defaultValue:`Record`});Ce({type:`crud_success`,params:{message:ge?j(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):j(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})}})},[Ce,ge,W,M,j]),De=(0,Q.useCallback)(()=>{Ce({type:`dialog_cancel`})},[Ce]),Oe=(0,Q.useCallback)(async e=>{if(Te){let e=W?M(W):j(`common.record`,{defaultValue:`Record`});X.success(ge?j(`form.updateSuccess`,{object:e,defaultValue:`${e} updated successfully`}):j(`form.createSuccess`,{object:e,defaultValue:`${e} created successfully`})),Se();return}if(Ee(),ge||!U)return;let t=Pa({objectName:U.name,baseUrl:x?`/apps/${x}`:R?.name?`/apps/${R.name}`:``,pathname:b.pathname,search:window.location.search,surface:ne(U),recordId:e?.id??e?._id});if(t.kind!==`none`){if(t.kind===`detail-page`){let e=new URLSearchParams(window.location.search);e.delete(qa),e.delete(ro),e.delete(Za);let n=e.toString(),r=`${b.pathname}${n?`?${n}`:``}`,i=M(U);y(t.url,{replace:!0,state:i?{from:{pathname:r,label:i}}:void 0});return}y(t.url,{replace:!0})}},[Ee,Te,W,ge,U,x,R?.name,b.pathname,y,Se,M,j]);im({pathname:b.pathname,appName:R?.name,objects:T});let Ae=e=>{let t=Ia({objectDef:U,baseUrl:x?`/apps/${x}`:R?.name?`/apps/${R.name}`:``,record:e});if(t.kind===`page`){y(t.url);return}let n=e?.id??e?._id,r=new URLSearchParams(window.location.search);r.set(qa,n!=null&&n!==``?String(n):`new`),r.delete(ro),r.delete(Za),pe(r)},je=e=>{y(`/apps/${e}`)},Ne=(0,Q.useMemo)(()=>Ca({user:Ea(i),app:R||{},data:ge||{},features:_}),[i,R,ge,_]);if(!m||E||!ee||!f)return(0,$.jsx)(uu,{});if(A&&(se||!R))return(0,$.jsx)(Ng,{appName:x,error:O,onRetry:()=>void k()});if(se)return ce!==`done`||de===null?(0,$.jsx)(uu,{}):de===`denied`?(0,$.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,$.jsxs)(oi,{"data-testid":`app-access-denied`,children:[(0,$.jsx)(Hi,{children:j(`empty.appAccessDenied`,{defaultValue:`You don't have access to this app`})}),(0,$.jsx)(Wr,{children:j(`empty.appAccessDeniedDescription`,{defaultValue:`This app exists, but your account is not authorized to open it. Ask an administrator to grant you access.`})}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(J,{onClick:()=>y(`/home`),"data-testid":`app-access-denied-home`,children:j(`empty.appAccessDeniedHome`,{defaultValue:`Back to home`})})})]})}):(0,$.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,$.jsxs)(oi,{children:[(0,$.jsx)(Hi,{children:j(`empty.appNotAvailable`,{defaultValue:`App not available`})}),(0,$.jsx)(Wr,{children:j(`empty.appNotAvailableDescription`,{defaultValue:`This app is not available yet — it may still be publishing. Try again in a moment.`})}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(J,{onClick:()=>B(null),"data-testid":`app-not-available-retry`,children:j(`common.retry`,{defaultValue:`Retry`})})})]})});if(!R&&!F&&!re&&!I&&!d)return(0,$.jsx)(du,{to:`/home`,replace:!0});if(!R&&!F&&!re&&!I)return(0,$.jsx)(`div`,{className:`h-screen flex items-center justify-center`,children:(0,$.jsxs)(oi,{children:[(0,$.jsx)(Hi,{children:j(`empty.noAppsConfigured`)}),(0,$.jsx)(Wr,{children:j(`empty.noAppsConfiguredDescription`)}),(0,$.jsxs)(`div`,{className:`mt-4 flex flex-col sm:flex-row items-center gap-3`,children:[(0,$.jsx)(J,{onClick:()=>y(`/apps/${x}/create-app`),"data-testid":`create-first-app-btn`,children:j(`empty.createFirstApp`)}),(0,$.jsx)(J,{variant:`outline`,onClick:()=>y(`/apps/setup/system`),"data-testid":`go-to-settings-btn`,children:j(`empty.systemSettings`)})]})]})});if(!R&&(F||re||I))return(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsxs)(g,{children:[(0,$.jsx)(u,{path:`create-app`,element:(0,$.jsx)(Jg,{})}),(0,$.jsx)(u,{path:`system/marketplace`,element:(0,$.jsx)(Zg,{})}),(0,$.jsx)(u,{path:`system/marketplace/installed`,element:(0,$.jsx)($g,{})}),(0,$.jsx)(u,{path:`system/marketplace/:packageId`,element:(0,$.jsx)(Qg,{})}),(0,$.jsx)(u,{path:`metadata`,element:(0,$.jsx)(Hg,{})}),(0,$.jsx)(u,{path:`metadata/_diagnostics`,element:(0,$.jsx)(qg,{})}),(0,$.jsx)(u,{path:`metadata/:type`,element:(0,$.jsx)(Wg,{})}),(0,$.jsx)(u,{path:`metadata/:type/new`,element:(0,$.jsx)(Gg,{createMode:!0})}),(0,$.jsx)(u,{path:`metadata/:type/:name`,element:(0,$.jsx)(Gg,{})}),(0,$.jsx)(u,{path:`metadata/:type/:name/history`,element:(0,$.jsx)(Kg,{})}),(0,$.jsx)(u,{path:`component/metadata/directory`,element:(0,$.jsx)(s_,{mode:`directory`})}),(0,$.jsx)(u,{path:`component/metadata/resource/*`,element:(0,$.jsx)(s_,{mode:`resource`})}),t,(0,$.jsx)(u,{path:`*`,element:(0,$.jsx)(l_,{})})]})});let Fe=Ea(i);return(0,$.jsx)(Ta,{user:Fe,app:R,data:{},features:_,children:(0,$.jsxs)(Le,{currentUserId:i?.id??null,currentOrgId:l?.id??null,children:[(0,$.jsx)(Zp,{}),(0,$.jsxs)(ah,{activeAppName:R.name,activeApp:R,onAppChange:je,objects:T,connectionState:n,userId:i?.id,children:[(0,$.jsx)(oh,{apps:S,activeApp:R,objects:T,onAppChange:je,dataSource:m}),(0,$.jsx)(ch,{}),(0,$.jsx)(lh,{}),(0,$.jsx)(e_,{appName:x}),(0,$.jsx)(Sh,{children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(fh,{className:`h-full`,children:(0,$.jsxs)(g,{children:[(0,$.jsx)(u,{path:`/`,element:(()=>{let e=i_(R,{currentUserId:i?.id??null});return e?(0,$.jsx)(h,{to:e,replace:!0}):(0,$.jsx)(Ug,{})})()}),(0,$.jsx)(u,{path:`metadata/package/*`,element:(0,$.jsx)(h,{to:`/apps/${x??R.name}/component/developer/packages`,replace:!0})}),(0,$.jsxs)(u,{path:`metadata`,children:[(0,$.jsx)(u,{index:!0,element:(0,$.jsx)(Hg,{})}),(0,$.jsx)(u,{path:`_diagnostics`,element:(0,$.jsx)(qg,{})}),(0,$.jsx)(u,{path:`:type`,element:(0,$.jsx)(Wg,{})}),(0,$.jsx)(u,{path:`:type/new`,element:(0,$.jsx)(Gg,{createMode:!0})}),(0,$.jsx)(u,{path:`:type/:name`,element:(0,$.jsx)(Gg,{})}),(0,$.jsx)(u,{path:`:type/:name/history`,element:(0,$.jsx)(Kg,{})})]}),(0,$.jsx)(u,{path:`:objectName`,element:(0,$.jsx)(jg,{dataSource:m,objects:T,onEdit:Ae,externalRefreshKey:ve})}),(0,$.jsx)(u,{path:`:objectName/new`,element:(0,$.jsx)(zg,{mode:`create`})}),(0,$.jsx)(u,{path:`:objectName/view/:viewId`,element:(0,$.jsx)(jg,{dataSource:m,objects:T,onEdit:Ae,externalRefreshKey:ve})}),(0,$.jsx)(u,{path:`:objectName/data`,element:(0,$.jsx)(Vg,{dataSource:m,objects:T})}),(0,$.jsx)(u,{path:`:objectName/record/:recordId`,element:(0,$.jsx)(Pg,{dataSource:m,objects:T,onEdit:Ae})}),(0,$.jsx)(u,{path:`:objectName/record/:recordId/edit`,element:(0,$.jsx)(zg,{mode:`edit`})}),(0,$.jsx)(u,{path:`dashboard/:dashboardName`,element:(0,$.jsx)(Fg,{dataSource:m})}),(0,$.jsx)(u,{path:`report/:reportName`,element:(0,$.jsx)(Lg,{dataSource:m})}),(0,$.jsx)(u,{path:`page/:pageName`,element:(0,$.jsx)(Ig,{})}),(0,$.jsx)(u,{path:`component/:ns/:name/*`,element:(0,$.jsx)(Bg,{})}),(0,$.jsx)(u,{path:`component/metadata/directory`,element:(0,$.jsx)(s_,{mode:`directory`})}),(0,$.jsx)(u,{path:`component/metadata/resource/*`,element:(0,$.jsx)(s_,{mode:`resource`})}),(0,$.jsx)(u,{path:`design/dashboard/:dashboardName`,element:(0,$.jsx)(Xg,{})}),(0,$.jsx)(u,{path:`search`,element:(0,$.jsx)(Rg,{})}),(0,$.jsx)(u,{path:`create-app`,element:(0,$.jsx)(Jg,{})}),(0,$.jsx)(u,{path:`edit-app/:editAppName`,element:(0,$.jsx)(Yg,{})}),(0,$.jsx)(u,{path:`system/marketplace`,element:(0,$.jsx)(Zg,{})}),(0,$.jsx)(u,{path:`system/marketplace/installed`,element:(0,$.jsx)($g,{})}),(0,$.jsx)(u,{path:`system/marketplace/:packageId`,element:(0,$.jsx)(Qg,{})}),e,(0,$.jsx)(u,{path:`:objectName/:maybeRecordId`,element:(0,$.jsx)(c_,{})}),(0,$.jsx)(u,{path:`*`,element:(0,$.jsx)(l_,{})})]})})})}),W&&(0,$.jsx)(pa,{schema:{type:`object-form`,formType:`modal`,objectName:W.name,mode:ge?`edit`:`create`,recordId:ge?.id,..._e&&!ge?{initialValues:_e}:{},...ae(W,Te?ge?`child-edit`:`child-create`:ge?`edit`:`create`).size===`full`?{modalSize:`full`}:{},...Fa(W),title:j(ge?`form.editTitle`:`form.createTitle`,{object:M(W)}),open:xe,onOpenChange:e=>{e||Se()},layout:`vertical`,fields:W.fields?Array.isArray(W.fields)?W.fields.filter(e=>typeof e==`string`||Sa(e,Ne)).map(e=>typeof e==`string`?e:e.name):Object.entries(W.fields).filter(([e,t])=>Sa(t,Ne)).map(([e])=>e):[],onSuccess:Oe,onCancel:De,showSubmit:!0,showCancel:!0,submitText:ge?j(`form.update`,{defaultValue:`Update`}):j(`form.create`,{defaultValue:`Create`}),cancelText:j(`common.cancel`)},dataSource:m},`${W.name}:${ge?.id||`new`}`)]})]})})}function n_(e,t){if(!e||e.length===0)return``;for(let n of e){if(n.type===`object`||n.type===`page`||n.type===`dashboard`||n.type===`report`){let e=r_(n,t);if(e)return e;continue}if(n.type!==`url`&&n.type===`group`&&n.children){let e=n_(n.children,t);if(e!==``)return e}}return``}function r_(e,t){if(!e||e.type===`url`||e.type===`action`||e.type===`separator`||e.type===`group`)return``;let{href:n,external:r}=Ss(e,``,t);return r||!n||n===`#`?``:n.replace(/^\//,``)}function i_(e,t){return n_(e?.navigation||[],t)}var a_=new Set([`new`,`view`,`record`,`edit`,`dashboard`,`report`,`page`,`design`,`search`,`create-app`,`edit-app`,`metadata`]);function o_(e){return!e||a_.has(e)||!/^[A-Za-z0-9_-]+$/.test(e)?!1:e.length>=6}function s_({mode:e}){let t=o(),n=t.pathname.replace(/\/component\/metadata\/.*$/,``);if(e===`directory`)return(0,$.jsx)(h,{to:`${n}/metadata${t.search}${t.hash}`,replace:!0});let r=new URLSearchParams(t.search).get(`type`)??``,i=t.pathname.match(/\/component\/metadata\/resource(\/.*)?$/)?.[1]??``,a=r?`${n}/metadata/${encodeURIComponent(r)}${i}${t.hash}`:`${n}/metadata${t.hash}`;return(0,$.jsx)(h,{to:a,replace:!0})}function c_(){let{objectName:e,maybeRecordId:t}=c(),n=o();if(e&&o_(t)){let e=`${n.pathname.replace(/\/$/,``).replace(`/${t}`,`/record/${t}`)}${n.search}${n.hash}`;return(0,$.jsx)(h,{to:e,replace:!0})}return(0,$.jsx)(l_,{})}function l_(){let e=p(),{t}=G();return(0,$.jsx)(`div`,{className:`flex h-full w-full items-center justify-center p-8`,children:(0,$.jsxs)(oi,{children:[(0,$.jsx)(Hi,{children:t(`console.notFound.title`,{defaultValue:`Page not found`})}),(0,$.jsx)(Wr,{children:t(`console.notFound.description`,{defaultValue:`The URL you followed does not match any view in this app.`})}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(J,{variant:`outline`,onClick:()=>e(-1),children:t(`console.notFound.back`,{defaultValue:`Go back`})})})]})})}function u_({children:e}){let{setContext:t}=Ra(),{t:n}=G(),r=p(),i=o(),a=(0,Q.useCallback)(()=>{Fd(`${i.pathname}${i.search}`),r(`/ai`)},[i.pathname,i.search,r]),{enabled:s}=zo();return(0,Q.useEffect)(()=>{t(`home`)},[t]),(0,$.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`home-layout`,children:[(0,$.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,$.jsx)(Cd,{variant:`home`})}),(0,$.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto pb-20 sm:pb-0`,children:e}),s&&(0,$.jsx)(Fu,{appLabel:n(`workspace.default`,{defaultValue:`My Workspace`}),onOpenDock:a})]})}function d_(e,t){return e(`home.recentApps.itemType.${t}`,{defaultValue:bs(t)})}function f_({icon:e,title:t,count:n,accent:r,children:i}){return(0,$.jsxs)(`section`,{className:`rounded-2xl bg-card/80 backdrop-blur-sm p-4 `+(r?`border border-primary/30`:`border border-border/70`),children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,$.jsx)(e,{className:`h-4 w-4 `+(r?`text-primary`:`text-muted-foreground`)}),(0,$.jsx)(`h2`,{className:`flex-1 text-sm font-semibold tracking-tight`,children:t}),typeof n==`number`&&n>0&&(0,$.jsx)(`span`,{className:`inline-flex h-5 min-w-5 items-center justify-center rounded-full bg-primary px-1.5 text-[11px] font-medium text-primary-foreground tabular-nums`,children:n})]}),i]})}function p_({icon:e,iconClass:t,label:n,meta:r,trailing:i,onClick:a,testId:o}){return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,onClick:a,"data-testid":o,className:`flex w-full items-center gap-3 rounded-lg px-2 py-2 text-left transition hover:bg-muted/60 active:scale-[0.99]`,children:[(0,$.jsx)(`span`,{className:`inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-lg `+t,children:(0,$.jsx)(e,{className:`h-4 w-4`})}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,children:n}),r&&(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:r}),i]})})}function m_({pendingApprovalsCount:e,notifications:t,unreadTopicCount:n,notificationsStatus:r,onOpenApprovals:i,onOpenNotification:a,t:o}){let{language:s}=G(),c=e+n,l=r===`ready`;return(0,$.jsxs)(f_,{icon:Kn,accent:!0,count:c,title:o(`home.actionCenter.title`,{defaultValue:`Needs your attention`}),children:[!l&&(0,$.jsx)(`div`,{className:`flex items-center gap-2 py-2 text-sm text-muted-foreground`,"data-testid":`home-action-unanswered`,children:r===`error`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ei,{className:`h-4 w-4 text-amber-500`}),o(`errors.unknown`,{defaultValue:`An unexpected error occurred.`})]}):o(`common.loading`,{defaultValue:`Loading…`})}),c===0?l&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 py-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(ar,{className:`h-4 w-4 text-emerald-500`}),o(`home.actionCenter.empty`,{defaultValue:`You're all caught up`})]}):(0,$.jsxs)(`ul`,{className:`flex flex-col gap-0.5`,children:[e>0&&(0,$.jsx)(p_,{icon:Kn,iconClass:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,label:o(`notifications.approvalsPending`,{defaultValue:`{{count}} pending approvals`,count:e}),trailing:(0,$.jsx)(Zn,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),onClick:i,testId:`home-action-approvals`}),t.map(e=>(0,$.jsx)(p_,{icon:ht,iconClass:`bg-primary/10 text-primary`,label:e.title,meta:Lo(e.createdAt,s),onClick:()=>a(e)},e.id))]})]})}var h_={object:tn,record:Li,dashboard:cn,page:ki},g_={object:`bg-blue-500/10 text-blue-600 dark:text-blue-400`,record:`bg-amber-500/10 text-amber-600 dark:text-amber-400`,dashboard:`bg-violet-500/10 text-violet-600 dark:text-violet-400`,page:`bg-emerald-500/10 text-emerald-600 dark:text-emerald-400`};function __({items:e,onOpen:t,t:n}){return(0,$.jsx)(f_,{icon:Rn,title:n(`home.recentApps.title`,{defaultValue:`Recently Accessed`}),children:e.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`home.continueEmpty`,{defaultValue:`Items you open will show up here.`})}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-0.5`,children:e.map(e=>(0,$.jsx)(p_,{icon:h_[e.type]||Li,iconClass:g_[e.type]||`bg-muted text-muted-foreground`,label:e.label,meta:d_(n,e.type),onClick:()=>t(e.href)},e.id))})})}function v_({items:e,onViewAll:t,t:n}){let{language:r}=G();return(0,$.jsxs)(f_,{icon:Ci,title:n(`sidebar.activityFeed`,{defaultValue:`Activity feed`}),children:[e.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:n(`layout.activityFeed.empty`,{defaultValue:`No recent activity`})}):(0,$.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:e.slice(0,5).map(e=>(0,$.jsxs)(`li`,{className:`text-sm leading-snug`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:e.user}),` `,(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e.description}),(0,$.jsxs)(`div`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:[Lo(e.timestamp,r),` · `,e.objectName]})]},e.id))}),(0,$.jsxs)(`button`,{type:`button`,onClick:t,className:`mt-3 inline-flex items-center gap-1 text-xs text-primary hover:underline`,children:[n(`layout.activityFeed.viewAll`,{defaultValue:`View all activity`}),(0,$.jsx)(Zn,{className:`h-3 w-3`})]})]})}function y_(e=5){let t=qo(),n=Vo(e),{value:r,status:i}=Xo();return{pendingApprovalsCount:t,notifications:(0,Q.useMemo)(()=>{let t=new Set;return r.filter(e=>!e.is_read).filter(e=>(e.title??``).trim().length>0).map(e=>({id:e.id,title:String(e.title),actionUrl:e.action_url??void 0,createdAt:e.created_at??void 0})).filter(e=>!t.has(e.title)&&(t.add(e.title),!0)).slice(0,e)},[r,e]),unreadTopicCount:(0,Q.useMemo)(()=>Uo(r).reduce((e,t)=>e+ +(t.unreadCount>0),0),[r]),notificationsStatus:i,activities:n}}function b_(){let e=(0,Q.useMemo)(()=>ns(),[]),{agents:t}=So({apiBase:e});return{aiEnabled:t.length>0,askAvailable:t.some(e=>wo(e.name)),buildAvailable:t.some(e=>Mo(t,e.name,`authoring`))}}function x_({icon:e,title:t,subtitle:n,onClick:r,disabled:i,disabledReason:a,testId:o}){return(0,$.jsxs)(`button`,{type:`button`,disabled:i,title:i?a:void 0,onClick:i?void 0:r,"data-testid":o,className:[`flex items-start gap-3 rounded-xl border bg-card px-4 py-3.5 text-left transition-colors`,i?`cursor-not-allowed opacity-60`:`hover:border-primary/50 hover:bg-muted/40`].join(` `),children:[(0,$.jsx)(`span`,{className:`mt-0.5 flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,$.jsx)(e,{className:`h-4.5 w-4.5`})}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-sm font-semibold`,children:t}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-muted-foreground`,children:n})]})]})}function S_({askAvailable:e,buildAvailable:t,canAuthorMetadata:n,navigate:r,t:i,layout:a=`row`}){let o=t&&n;return!e&&!o?null:(0,$.jsxs)(`div`,{className:a===`stack`?`mt-6 flex flex-col sm:flex-row items-center gap-3`:`flex shrink-0 items-center gap-2`,children:[o&&(0,$.jsxs)(J,{onClick:()=>r(`/ai/build`),"data-testid":`home-build-with-ai`,children:[(0,$.jsx)(Jt,{className:`mr-2 h-4 w-4`}),i(`home.buildWithAI`,{defaultValue:`Build with AI`})]}),e&&!o&&(0,$.jsxs)(J,{onClick:()=>r(`/ai/ask`),"data-testid":`home-ask-ai`,children:[(0,$.jsx)(yr,{className:`mr-2 h-4 w-4`}),i(`home.askAI`,{defaultValue:`Ask AI`})]})]})}function C_(e){return e<5?`home.greetingNight`:e<12?`home.greetingMorning`:e<18?`home.greetingAfternoon`:e<23?`home.greetingEvening`:`home.greetingNight`}function w_({t:e}){let{publishAll:t,publishing:n}=mm(e),{count:r}=Xu({});return(r??0)<=0?null:(0,$.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-4`,children:(0,$.jsx)(`div`,{className:`max-w-7xl mx-auto`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-indigo-300/60 dark:border-indigo-700/50 bg-indigo-50 dark:bg-indigo-950/30 px-4 py-3`,children:[(0,$.jsx)(Hn,{className:`h-5 w-5 shrink-0 text-indigo-600 dark:text-indigo-400`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 text-sm text-indigo-900 dark:text-indigo-200`,children:e(`home.pendingDrafts.message`,{count:r,defaultValue:`You have {{count}} unpublished change(s) — publish to make them live.`})}),(0,$.jsx)(J,{size:`sm`,onClick:async()=>{await t()},disabled:n,"data-testid":`pending-drafts-publish`,children:n?e(`home.pendingDrafts.publishing`,{defaultValue:`Publishing…`}):e(`home.pendingDrafts.cta`,{defaultValue:`Publish`})})]})})})}function T_({t:e}){let t=p(),{hasLocalPassword:n,getAuthConfig:r}=C(),[i,a]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{if(typeof localStorage<`u`&&localStorage.getItem(`os:recovery-pw-dismissed`)===`1`)return;if(typeof localStorage<`u`&&localStorage.getItem(`os:recovery-pw-first-seen`)!==`1`){try{localStorage.setItem(`os:recovery-pw-first-seen`,`1`)}catch{}return}let e=!1;return Promise.all([Promise.resolve(n?.()),Promise.resolve(r?.()).catch(()=>null)]).then(([t,n])=>{if(e)return;let r=n?.features?.ssoEnforced===!0||n?.emailPassword?.enabled===!1;t===!1&&!r&&a(!0)}).catch(()=>{}),()=>{e=!0}},[n,r]),i?(0,$.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-4`,children:(0,$.jsx)(`div`,{className:`max-w-7xl mx-auto`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl border border-amber-300/60 dark:border-amber-700/50 bg-amber-50 dark:bg-amber-950/30 px-4 py-3`,children:[(0,$.jsx)(Tr,{className:`h-5 w-5 shrink-0 text-amber-600 dark:text-amber-400`}),(0,$.jsx)(`p`,{className:`flex-1 min-w-0 text-sm text-amber-900 dark:text-amber-200`,children:e(`home.recoveryReminder.message`,{defaultValue:`Set a recovery password so you can still sign in if single sign-on is ever unavailable.`})}),(0,$.jsx)(J,{size:`sm`,variant:`outline`,onClick:()=>t(`/set-password`),"data-testid":`recovery-pw-set`,children:e(`home.recoveryReminder.cta`,{defaultValue:`Set password`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{try{localStorage.setItem(`os:recovery-pw-dismissed`,`1`)}catch{}a(!1)},"aria-label":e(`home.recoveryReminder.dismiss`,{defaultValue:`Dismiss`}),className:`shrink-0 rounded-md p-1 text-amber-700/70 hover:text-amber-900 dark:text-amber-300/70 dark:hover:text-amber-100`,children:(0,$.jsx)(ci,{className:`h-4 w-4`})})]})})}):null}function E_(){let e=p(),{t}=G(),{apps:n,loading:r}=be(),{recentItems:i}=ja(),{favorites:a}=ao(),{user:o}=C(),{isAdmin:s,isResolved:c}=w(),{pendingApprovalsCount:l,notifications:u,unreadTopicCount:d,notificationsStatus:f,activities:m}=y_(),{currentAppName:h}=Ra(),{askAvailable:g,buildAvailable:_}=b_(),v=Wd(),y=ss(),b=ps(),x=t(`home.build.noCapability`,{defaultValue:`Building apps isn't available in this workspace — it requires the “Manage Metadata” permission, which your account doesn't have.`}),S=t(`home.template.marketplaceDisabled`,{defaultValue:`This runtime has no app marketplace configured, so there are no templates to install here.`}),T=uo(n),E=oo(T,h),D=i.filter(e=>e.type===`object`||e.type===`dashboard`||e.type===`page`||e.type===`record`).slice(0,6),O=(0,Q.useMemo)(()=>t(C_(new Date().getHours()),{defaultValue:`Welcome`}),[t]),k=(o?.name?.trim()||o?.email?.split(`@`)[0]||``).trim();return r||!c?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,$.jsx)(`div`,{className:`text-muted-foreground`,children:t(`home.loading`,{defaultValue:`Loading workspace…`})})}):T.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col flex-1`,children:[(0,$.jsx)(w_,{t}),(0,$.jsx)(T_,{t}),(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6`,children:s&&!v?(0,$.jsxs)(oi,{children:[(0,$.jsx)(Hi,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,$.jsx)(Wr,{"data-testid":`home-authoring-gate-reason-empty`,children:x}),(0,$.jsx)(S_,{askAvailable:g,buildAvailable:_,canAuthorMetadata:v,navigate:e,t,layout:`stack`})]}):s?(0,$.jsxs)(oi,{children:[(0,$.jsx)(Hi,{children:t(`home.welcome`,{defaultValue:`Build your business system with AI`})}),(0,$.jsx)(Wr,{children:_?t(`home.welcomeAdminDescription`,{defaultValue:`Describe your business in one sentence — AI generates the objects, screens, APIs and agent tools. Or set things up yourself from the menu on the left.`}):g?t(`home.welcomeAdminDescriptionNoBuild`,{defaultValue:`Set up your first application from the Administration menu on the left. Once you have data, the AI assistant can help you explore it.`}):t(`home.welcomeAdminDescriptionNoAi`,{defaultValue:`Set up your first application from the Administration menu on the left.`})}),(0,$.jsx)(S_,{askAvailable:g,buildAvailable:_,canAuthorMetadata:v,navigate:e,t,layout:`stack`})]}):(0,$.jsxs)(oi,{children:[(0,$.jsx)(Hi,{children:t(`home.noAppsTitle`,{defaultValue:`No applications yet`})}),(0,$.jsx)(Wr,{children:t(`home.noAppsDescription`,{defaultValue:`Your workspace is being set up — apps your admin shares with you will show up here.`})})]})})]}):(0,$.jsxs)(`div`,{className:`relative min-h-full bg-background`,children:[(0,$.jsx)(w_,{t}),(0,$.jsx)(T_,{t}),(0,$.jsx)(`div`,{className:`px-4 sm:px-6 lg:px-8 pt-8 pb-16`,children:(0,$.jsxs)(`div`,{className:`max-w-7xl mx-auto`,children:[(0,$.jsxs)(`div`,{className:`mb-7 flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight text-pretty`,children:[(0,$.jsxs)(`span`,{className:`text-foreground`,children:[O,k?`, `:``]}),k&&(0,$.jsx)(`span`,{className:`text-primary`,children:k}),(0,$.jsx)(`span`,{className:`text-foreground/40`,children:`.`})]}),(0,$.jsx)(`p`,{className:`mt-1 text-sm sm:text-base text-muted-foreground`,children:t(`home.heroTagline`,{defaultValue:`Pick up where you left off, or explore something new.`})})]}),(0,$.jsx)(S_,{askAvailable:g,buildAvailable:_,canAuthorMetadata:v,navigate:e,t})]}),s&&(0,$.jsxs)(`div`,{className:`mb-6`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[b&&(0,$.jsx)(x_,{icon:Jn,title:t(`home.build.title`,{defaultValue:`Build an app`}),subtitle:t(`home.build.subtitle`,{defaultValue:`Start from scratch — design objects, forms, automations and interfaces.`}),onClick:()=>e(`/studio`),disabled:!v,disabledReason:x,testId:`home-build-app`}),(0,$.jsx)(x_,{icon:Ot,title:t(`home.template.title`,{defaultValue:`Start with a template`}),subtitle:t(`home.template.subtitle`,{defaultValue:`Install a template app from the marketplace and customize it.`}),onClick:()=>e(`/apps/setup/system/marketplace`),disabled:!v||!y,disabledReason:v?S:x,testId:`home-start-template`})]}),!v&&(0,$.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,"data-testid":`home-authoring-gate-reason`,children:x}),v&&!y&&(0,$.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,"data-testid":`home-marketplace-disabled-reason`,children:S})]}),(0,$.jsx)(Ro,{apps:T,favorites:a,onOpen:t=>e(`/apps/${fo(t)??t.name}`),onBrowseMarketplace:()=>e(`/apps/setup/system/marketplace`),isAdmin:s,canAuthorMetadata:v,marketplaceEnabled:y}),(0,$.jsx)(`div`,{className:`mb-6`,children:(0,$.jsx)(m_,{pendingApprovalsCount:l,notifications:u,unreadTopicCount:d,notificationsStatus:f,onOpenApprovals:()=>e(`/apps/${E}/system/approvals`),onOpenNotification:t=>{let n=lo(t.actionUrl,E);if(!n){e(`/apps/${E}/sys_inbox_message?view=mine`);return}if(n.kind===`external`){window.open(n.url,`_blank`,`noopener,noreferrer`);return}e(n.path)},t})}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-6 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,$.jsx)(__,{items:D,onOpen:t=>e(t),t}),(0,$.jsx)(v_,{items:m,onViewAll:()=>e(`/apps/${E}/sys_activity`),t})]})]})})]})}function D_({children:e}){let{setContext:t}=Ra();return(0,Q.useEffect)(()=>{t(`home`)},[t]),(0,$.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organizations-layout`,children:[(0,$.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,$.jsx)(Cd,{variant:`orgs`})}),(0,$.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:e})]})}async function O_(e){let t=await b()(`${_s()}/api/v1/cloud/environments`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({displayName:e.displayName??`Production`,organizationId:e.organizationId})});if(!t.ok){if(t.status===403||t.status===409)return{alreadyProvisioned:!0};throw Error(`Failed to provision production environment (status ${t.status})`)}let n=(await t.json().catch(()=>null))?.data;if(!n||typeof n!=`object`)throw Error("Malformed control-plane response: expected a `{ success, data }` envelope from POST /cloud/environments");let r=n.environment;if(!r||typeof r!=`object`)throw Error("Malformed control-plane response: `data.environment` is missing from POST /cloud/environments");return{id:r.id,hostname:r.hostname}}var k_={YOU_ARE_NOT_ALLOWED_TO_INVITE_USERS_TO_THIS_ORGANIZATION:{key:`organization.errors.notAllowedToInvite`,defaultValue:`You are not allowed to invite users to this organization`},YOU_ARE_NOT_ALLOWED_TO_INVITE_USER_WITH_THIS_ROLE:{key:`organization.errors.notAllowedToInviteWithRole`,defaultValue:`You are not allowed to invite a user with this role`},USER_IS_ALREADY_INVITED_TO_THIS_ORGANIZATION:{key:`organization.errors.alreadyInvited`,defaultValue:`This user has already been invited to this organization`},ORGANIZATION_ALREADY_EXISTS:{key:`organization.errors.organizationExists`,defaultValue:`Organization already exists`},ORGANIZATION_SLUG_ALREADY_TAKEN:{key:`organization.errors.slugTaken`,defaultValue:`That URL slug is already taken`},YOU_ARE_NOT_ALLOWED_TO_CREATE_A_NEW_ORGANIZATION:{key:`organization.errors.notAllowedToCreate`,defaultValue:`You are not allowed to create a new organization`},YOU_ARE_NOT_THE_RECIPIENT_OF_THE_INVITATION:{key:`organization.errors.notTheRecipient`,defaultValue:`You are not the recipient of the invitation`},INVITATION_NOT_FOUND:{key:`organization.errors.invitationNotFound`,defaultValue:`This invitation no longer exists or has expired`}},A_={key:`organization.errors.unknown`,defaultValue:`Something went wrong. Please try again.`};function j_(e){if(typeof e!=`object`||!e)return;let t=e.code;return typeof t==`string`&&t?t:void 0}function M_(e,t,n){let r=j_(e);if(r){let e=k_[r];if(e)return t(e.key,{defaultValue:e.defaultValue})}let i=e instanceof Error?e.message:void 0;return typeof i==`string`&&i.trim()?i:n?t(n.key,{defaultValue:n.defaultValue}):t(A_.key,{defaultValue:A_.defaultValue})}function N_(e){let t=e.toLowerCase().replace(/[^a-z0-9\s_-]/g,``).replace(/[\s_]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``).slice(0,48);if(t)return t;let n=e.trim();if(!n)return``;let r=0;for(let e of n)r=Math.imul(r,31)+e.charCodeAt(0)>>>0;return`workspace-${r.toString(36).slice(0,6)}`}function P_({open:e,onOpenChange:t,onCreated:n}){let{t:r}=G(),{createOrganization:i,getAuthConfig:a}=C(),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{if(!e)return;let t=!1;return a().then(e=>{t||_(e?.features?.multiOrgEnabled===!1)}).catch(()=>{}),()=>{t=!0}},[e,a]),(0,Q.useEffect)(()=>{u||l(N_(o))},[o,u]),(0,Q.useEffect)(()=>{e&&(s(``),l(``),d(!1),h(null))},[e]);let v=(0,Q.useCallback)(async e=>{if(e.preventDefault(),!(!o.trim()||!c.trim())){if(g){h(r(`workspace.multiOrgDisabled`,{defaultValue:`Creating new organizations is disabled on this instance.`}));return}p(!0),h(null);try{let e=await i({name:o.trim(),slug:c.trim()});try{await O_({organizationId:e.id,displayName:o.trim()})}catch(e){console.warn(`[CreateWorkspace] eager env provision failed; onboarding gate will provision lazily`,e)}n?.(e)}catch(e){h(M_(e,r,{key:`workspace.createFailed`,defaultValue:`Failed to create workspace`}))}finally{p(!1)}}},[o,c,g,r,i,n]);return(0,$.jsx)(Vi,{open:e,onOpenChange:t,children:(0,$.jsx)(Xi,{className:`sm:max-w-[425px]`,"data-testid":`create-workspace-dialog`,children:(0,$.jsxs)(`form`,{onSubmit:v,children:[(0,$.jsxs)(En,{children:[(0,$.jsx)(xt,{children:r(`workspace.createTitle`,{defaultValue:`Create a workspace`})}),(0,$.jsx)(gr,{children:r(`workspace.createDescription`,{defaultValue:`A workspace is a shared space for your team to collaborate.`})})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(K,{htmlFor:`workspace-name`,children:r(`workspace.nameLabel`,{defaultValue:`Workspace name`})}),(0,$.jsx)(q,{id:`workspace-name`,placeholder:r(`workspace.namePlaceholder`,{defaultValue:`e.g., Acme Inc`}),value:o,onChange:e=>s(e.target.value),autoFocus:!0,"data-testid":`workspace-name-input`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(K,{htmlFor:`workspace-slug`,children:r(`workspace.slugLabel`,{defaultValue:`URL slug`})}),(0,$.jsx)(q,{id:`workspace-slug`,placeholder:`acme-inc`,value:c,onChange:e=>{l(e.target.value),d(!0)},"data-testid":`workspace-slug-input`}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:r(`workspace.slugHint`,{defaultValue:`Used in URLs. Only lowercase letters, numbers, and hyphens.`})})]}),m&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`workspace-create-error`,children:m})]}),(0,$.jsxs)(qi,{children:[(0,$.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>t(!1),disabled:f,children:r(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(J,{type:`submit`,disabled:f||!o.trim()||!c.trim(),"data-testid":`workspace-create-submit`,children:[f&&(0,$.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),r(`workspace.createButton`,{defaultValue:`Create workspace`})]})]})]})})})}function F_(e){return e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2)}function I_(){let{t:e}=G(),t=p(),[n]=s(),r=n.get(`manage`)===`1`,i=n.get(`create`)===`1`,{organizations:a,activeOrganization:o,isOrganizationsLoading:c,switchOrganization:l,getAuthConfig:u}=C(),[d,f]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(!0);(0,Q.useEffect)(()=>{let e=!1;return u().then(t=>{e||t?.features?.multiOrgEnabled===!1&&y(!1)}).catch(()=>{}),()=>{e=!0}},[u]);let b=a??[],x=(0,Q.useMemo)(()=>{let e=d.trim().toLowerCase();return e?b.filter(t=>t.name.toLowerCase().includes(e)||t.slug?.toLowerCase().includes(e)):b},[b,d]),S=async e=>{_(e.id);try{e.id!==o?.id&&await l(e.id),window.location.href=Hu()}catch(e){console.error(`[OrganizationsPage] Failed to switch:`,e),_(null)}},w=e=>{h(!1),S(e)},T=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{T.current||c||i||b.length===1&&(T.current=!0,r?t(`/organizations/${b[0].slug}/members`,{replace:!0}):S(b[0]))},[c,b.length,r,i]);let E=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{if(c)return;let e=b.length===0&&v;(i||e)&&!E.current&&(E.current=!0,h(!0))},[i,b.length,v,c]);let D=!i&&!c&&b.length===1,O=!c&&b.length===0&&v&&!E.current;return c||D||O?(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center py-20`,children:(0,$.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-8 sm:py-12`,children:[(0,$.jsxs)(`div`,{className:`mb-8`,children:[(0,$.jsx)(`h1`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:e(`organizations.heading`,{defaultValue:`Your Workspaces`})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organizations.subtitle`,{defaultValue:`Select a workspace to continue, or create a new one.`})})]}),(0,$.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`relative w-full sm:max-w-sm`,children:[(0,$.jsx)(ur,{className:`pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`}),(0,$.jsx)(q,{value:d,onChange:e=>f(e.target.value),placeholder:e(`organizations.searchPlaceholder`,{defaultValue:`Search for a workspace`}),className:`pl-9`,"data-testid":`organizations-search`})]}),v&&(0,$.jsxs)(J,{onClick:()=>h(!0),"data-testid":`organizations-new`,children:[(0,$.jsx)(Ct,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New workspace`})]})]}),b.length===0?(0,$.jsxs)(oi,{children:[(0,$.jsx)(Hi,{children:e(`organizations.emptyTitle`,{defaultValue:`No workspaces yet`})}),(0,$.jsx)(Wr,{children:e(`organizations.emptyDescription`,{defaultValue:`Create your first workspace to get started.`})}),v&&(0,$.jsxs)(J,{className:`mt-6`,onClick:()=>h(!0),children:[(0,$.jsx)(Ct,{className:`mr-2 h-4 w-4`}),e(`organizations.new`,{defaultValue:`New workspace`})]})]}):x.length===0?(0,$.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organizations.noMatches`,{defaultValue:`No workspaces match your search.`})}):(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:x.map(n=>{let r=n.id===o?.id,i=g===n.id;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>S(n),disabled:i,className:`group flex items-center gap-3 rounded-lg border bg-card p-4 text-left transition-colors hover:border-primary/50 hover:bg-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60`,"data-testid":`organization-card-${n.slug}`,children:[(0,$.jsxs)(At,{className:`h-10 w-10 rounded-md shrink-0`,children:[n.logo&&(0,$.jsx)(Qt,{src:n.logo,alt:n.name}),(0,$.jsx)(Vt,{className:`rounded-md bg-primary/10 text-primary text-sm font-medium`,children:F_(n.name)})]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate font-medium`,children:n.name}),(0,$.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:r?e(`organizations.current`,{defaultValue:`Current workspace`}):n.slug})]}),(0,$.jsx)(`span`,{className:`text-xs text-primary underline-offset-4 hover:underline shrink-0`,onClick:e=>{e.stopPropagation(),t(`/organizations/${n.slug}/members`)},children:e(`organizations.manage`,{defaultValue:`Manage`})}),i&&(0,$.jsx)(Y,{className:`h-4 w-4 animate-spin text-muted-foreground`})]},n.id)})}),(0,$.jsx)(P_,{open:m,onOpenChange:h,onCreated:w})]})}function L_(){let{t:e}=G(),t=p(),{slug:n}=c(),{organizations:r,activeOrganization:a,isOrganizationsLoading:o,switchOrganization:s}=C(),{setContext:l}=Ra();(0,Q.useEffect)(()=>{l(`home`)},[l]);let u=(0,Q.useMemo)(()=>(r??[]).find(e=>e.slug===n)??null,[r,n]);if((0,Q.useEffect)(()=>{u&&a?.id!==u.id&&s(u.id).catch(e=>{console.error(`[OrganizationLayout] switch failed`,e)})},[u,a,s]),o)return(0,$.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center`,children:(0,$.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})});if(!u)return(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-3xl px-4 py-12 text-center`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.notFound`,{defaultValue:`Organization not found`})}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e(`organization.notFoundDescription`,{defaultValue:`This organization does not exist or you do not have access.`})}),(0,$.jsx)(J,{className:`mt-6`,onClick:()=>t(`/organizations`),children:e(`organization.backToList`,{defaultValue:`Back to organizations`})})]});let d=[{to:`members`,label:e(`organization.tabs.members`,{defaultValue:`Members`})},{to:`invitations`,label:e(`organization.tabs.invitations`,{defaultValue:`Invitations`})},{to:`settings`,label:e(`organization.tabs.settings`,{defaultValue:`Settings`})}];return(0,$.jsxs)(`div`,{className:`flex min-h-svh w-full flex-col bg-background`,"data-testid":`organization-layout`,children:[(0,$.jsx)(`header`,{className:`sticky top-0 z-30 flex h-14 w-full shrink-0 items-center gap-2 border-b bg-background px-2 sm:px-4`,children:(0,$.jsx)(Cd,{variant:`orgs`})}),(0,$.jsx)(`div`,{className:`border-b`,children:(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 pt-6`,children:[(r??[]).length>1&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>t(`/organizations`),className:`mb-3 inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground`,children:[(0,$.jsx)(_n,{className:`h-3.5 w-3.5`}),e(`organization.backToList`,{defaultValue:`Back to organizations`})]}),(0,$.jsx)(`div`,{className:`flex items-center justify-between gap-4`,children:(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`h1`,{className:`truncate text-2xl font-bold tracking-tight`,children:u.name}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:u.slug})]})}),(0,$.jsx)(`nav`,{className:`mt-4 flex gap-1 -mb-px`,children:d.map(e=>(0,$.jsx)(f,{to:e.to,end:!0,className:({isActive:e})=>`border-b-2 px-3 py-2 text-sm font-medium transition-colors ${e?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:e.label},e.to))})]})}),(0,$.jsx)(`main`,{className:`flex-1 min-w-0 overflow-auto`,children:(0,$.jsx)(`div`,{className:`mx-auto w-full max-w-5xl px-4 sm:px-6 py-6`,children:(0,$.jsx)(i,{context:{org:u}})})})]})}function R_(){return d()}function z_(e){return Object.prototype.hasOwnProperty.call(T,e)}function B_(e,t){if(typeof e!=`string`)return``;let n=e.trim();if(!n)return``;if(!z_(n))return n;let r=T[n];return t(r.key,{defaultValue:r.defaultValue})}function V_({organizationId:e,open:t,onOpenChange:n,onInvited:r}){let{t:i}=G(),{inviteMember:a,describeDelegableScope:o,activeMember:s}=C(),c=k(s?.role),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(F),[p,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(``),[E,D]=(0,Q.useState)([]);(0,Q.useEffect)(()=>{t&&(u(``),f(F),g(null),v(null),b(!1),T(``),D([]))},[t]),(0,Q.useEffect)(()=>{if(!t)return;let e=!1;return o?.().then(t=>{e||S(t)}).catch(()=>{}),()=>{e=!0}},[t,o]);let O=!!x&&x.placeableBusinessUnitIds.length>0&&x.assignablePositions.length>0,A=(0,Q.useCallback)(async t=>{if(t.preventDefault(),l.trim()){m(!0),g(null);try{let t=await a({organizationId:e,email:l.trim(),role:d,...O&&w&&E.length>0?{businessUnitId:w,positions:E}:{}});v(t),r?.(t)}catch(e){g(M_(e,i,{key:`organization.invitations.inviteFailed`,defaultValue:`Failed to invite member`}))}finally{m(!1)}}},[l,d,e,a,r,O,w,E,i]),j=_?Uu(`accept-invitation/${_.id}`):null,M=(0,Q.useCallback)(async()=>{if(j)try{await navigator.clipboard.writeText(j),b(!0),X.success(i(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>b(!1),2e3)}catch{X.error(i(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},[j,i]);return(0,$.jsx)(Vi,{open:t,onOpenChange:n,children:(0,$.jsx)(Xi,{className:`sm:max-w-[480px]`,"data-testid":`invite-member-dialog`,children:_?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(En,{children:[(0,$.jsx)(xt,{children:i(`organization.invitations.sentTitle`,{defaultValue:`Invitation created`})}),(0,$.jsx)(gr,{children:i(`organization.invitations.sentDescription`,{defaultValue:`Share the link below with the invitee. They will need to sign in to accept.`})})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 py-4`,children:[(0,$.jsx)(K,{children:i(`organization.invitations.linkLabel`,{defaultValue:`Accept link`})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(q,{readOnly:!0,value:j??``,className:`font-mono text-xs`,onFocus:e=>e.currentTarget.select()}),(0,$.jsx)(J,{type:`button`,variant:`outline`,size:`icon`,onClick:M,"aria-label":i(`organization.invitations.copyLinkLabel`,{defaultValue:`Copy invitation link`}),children:y?(0,$.jsx)(Pr,{className:`h-4 w-4`}):(0,$.jsx)(jt,{className:`h-4 w-4`})})]}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`organization.invitations.invitedAs`,{defaultValue:`{{email}} invited as {{role}}`,email:_.email,role:B_(_.role,i)})})]}),(0,$.jsx)(qi,{children:(0,$.jsx)(J,{onClick:()=>n(!1),children:i(`common.done`,{defaultValue:`Done`})})})]}):(0,$.jsxs)(`form`,{onSubmit:A,children:[(0,$.jsxs)(En,{children:[(0,$.jsx)(xt,{children:i(`organization.invitations.inviteTitle`,{defaultValue:`Invite a member`})}),(0,$.jsx)(gr,{children:i(`organization.invitations.inviteDescription`,{defaultValue:`They will receive an invitation to join this organization.`})})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 py-4`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(K,{htmlFor:`invite-email`,children:i(`organization.invitations.emailLabel`,{defaultValue:`Email`})}),(0,$.jsx)(q,{id:`invite-email`,type:`email`,required:!0,placeholder:`user@example.com`,value:l,onChange:e=>u(e.target.value),autoFocus:!0,"data-testid":`invite-email-input`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(K,{htmlFor:`invite-role`,children:i(`organization.invitations.roleLabel`,{defaultValue:`Role`})}),(0,$.jsxs)(Wi,{value:d,onValueChange:e=>f(e),children:[(0,$.jsx)(Tt,{id:`invite-role`,"data-testid":`invite-role-select`,children:(0,$.jsx)(sn,{})}),(0,$.jsx)(An,{children:c.map(e=>(0,$.jsx)(Dt,{value:e,"data-testid":`invite-role-${e}`,children:B_(e,i)},e))})]})]}),O&&(0,$.jsxs)(`div`,{className:`grid gap-3 rounded-md border border-dashed p-3`,"data-testid":`invite-placement-section`,children:[(0,$.jsxs)(`div`,{className:`grid gap-1`,children:[(0,$.jsx)(K,{className:`text-sm`,children:i(`organization.invitations.placementLabel`,{defaultValue:`Placement (optional)`})}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:i(`organization.invitations.placementDescription`,{defaultValue:`Applied when the invitation is accepted. Only units and positions you may delegate are listed.`})})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(K,{htmlFor:`invite-business-unit`,className:`text-xs`,children:i(`organization.invitations.businessUnitLabel`,{defaultValue:`Business unit`})}),(0,$.jsxs)(Wi,{value:w,onValueChange:T,children:[(0,$.jsx)(Tt,{id:`invite-business-unit`,"data-testid":`invite-business-unit-select`,children:(0,$.jsx)(sn,{placeholder:i(`organization.invitations.businessUnitPlaceholder`,{defaultValue:`No placement`})})}),(0,$.jsx)(An,{children:x.placeableBusinessUnitIds.map(e=>(0,$.jsx)(Dt,{value:e,children:e},e))})]})]}),w&&(0,$.jsxs)(`div`,{className:`grid gap-2`,"data-testid":`invite-positions`,children:[(0,$.jsx)(K,{className:`text-xs`,children:i(`organization.invitations.positionsLabel`,{defaultValue:`Positions`})}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:x.assignablePositions.map(e=>{let t=E.includes(e);return(0,$.jsx)(J,{type:`button`,size:`sm`,variant:t?`default`:`outline`,"data-testid":`invite-position-${e}`,"aria-pressed":t,onClick:()=>D(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),children:e},e)})})]})]}),h&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,"data-testid":`invite-error`,children:h})]}),(0,$.jsxs)(qi,{children:[(0,$.jsx)(J,{type:`button`,variant:`outline`,onClick:()=>n(!1),disabled:p,children:i(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(J,{type:`submit`,disabled:p||!l.trim(),"data-testid":`invite-submit`,children:[p&&(0,$.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),i(`organization.invitations.sendInvite`,{defaultValue:`Send invite`})]})]})]})})})}var H_=M(L);function U_(e){return typeof e==`string`?e.split(`,`).map(e=>e.trim().toLowerCase()).filter(Boolean):[]}function W_(e){return M(e)>=H_||U_(e).includes(oe)}function G_(e){return M(e)>=H_}function K_(e){return M(e)>=H_}function q_(e){return e?e.split(/[\s_-]+/).map(e=>e[0]).join(``).toUpperCase().slice(0,2):`?`}function J_(){let{t:e}=G(),{org:t}=R_(),{getMembers:n,removeMember:r,updateMemberRole:i,activeMember:a}=C(),o=W_(a?.role),s=G_(a?.role),[c,l]=(0,Q.useState)([]),[u,d]=(0,Q.useState)(!0),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(null),v=(0,Q.useCallback)(async()=>{d(!0),p(null);try{let e=await n(t.id);l(e)}catch(t){p(M_(t,e,{key:`organization.members.loadFailed`,defaultValue:`Failed to load members`}))}finally{d(!1)}},[t.id,n,e]);(0,Q.useEffect)(()=>{v()},[v]);let b=async(n,r)=>{try{await i({organizationId:t.id,memberId:n.id,role:r}),X.success(e(`organization.members.roleUpdated`,{defaultValue:`Role updated`})),v()}catch(t){X.error(M_(t,e,{key:`organization.members.roleUpdateFailed`,defaultValue:`Failed to update role`}))}};return u?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,$.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):f?(0,$.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[f,(0,$.jsx)(J,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:v,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,$.jsxs)(`div`,{className:`space-y-4`,"data-testid":`members-page`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsxs)(`h2`,{className:`text-lg font-semibold`,children:[e(`organization.members.title`,{defaultValue:`Members`}),` (`,c.length,`)`]}),o?(0,$.jsx)(J,{onClick:()=>h(!0),"data-testid":`invite-member-btn`,children:e(`organization.members.inviteMember`,{defaultValue:`Invite member`})}):(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,"data-testid":`invite-restricted-note`,children:e(`organization.members.inviteRestrictedNote`,{defaultValue:`Only organization admins can invite members.`})})]}),(0,$.jsx)(bt,{}),(0,$.jsx)(`div`,{className:`space-y-2`,children:c.map(t=>{let n=y(a?.role,t.role),r=n.length>0||s;return(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`member-row-${t.id}`,children:[(0,$.jsxs)(At,{className:`h-9 w-9 shrink-0`,children:[t.user?.image&&(0,$.jsx)(Qt,{src:t.user.image,alt:t.user.name}),(0,$.jsx)(Vt,{className:`text-xs font-medium`,children:q_(t.user?.name)})]}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.user?.name??`—`}),(0,$.jsx)(`div`,{className:`truncate text-xs text-muted-foreground`,children:t.user?.email??`—`})]}),(0,$.jsx)(hn,{variant:`outline`,className:`shrink-0`,"data-testid":`member-role-badge-${t.id}`,children:B_(t.role,e)}),t.createdAt&&(0,$.jsx)(`span`,{className:`hidden shrink-0 text-xs text-muted-foreground sm:block`,children:new Date(t.createdAt).toLocaleDateString()}),r&&(0,$.jsxs)(Bn,{children:[(0,$.jsx)($n,{asChild:!0,children:(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 shrink-0`,"aria-label":e(`organization.members.memberActions`,{defaultValue:`Member actions`}),children:(0,$.jsx)(Mn,{className:`h-4 w-4`})})}),(0,$.jsxs)(It,{align:`end`,children:[n.map(n=>(0,$.jsxs)(qn,{onClick:()=>b(t,n),disabled:t.role===n,"data-testid":`member-role-${n}`,children:[(0,$.jsx)(lt,{className:`mr-2 h-4 w-4`}),e(T[n].key,{defaultValue:T[n].defaultValue})]},n)),s&&(0,$.jsxs)(qn,{className:`text-destructive focus:text-destructive`,onClick:()=>_(t),children:[(0,$.jsx)(Mr,{className:`mr-2 h-4 w-4`}),e(`organization.members.removeMember`,{defaultValue:`Remove member`})]})]})]})]},t.id)})}),(0,$.jsx)(Vn,{open:!!g,onOpenChange:e=>!e&&_(null),children:(0,$.jsxs)(Yn,{children:[(0,$.jsxs)(xi,{children:[(0,$.jsx)(qt,{children:e(`organization.members.removeConfirmTitle`,{defaultValue:`Remove member?`})}),(0,$.jsx)(Nt,{children:e(`organization.members.removeConfirmDescription`,{defaultValue:`This will remove {{name}} from the organization. They will lose access immediately.`,name:g?.user?.name??g?.userId??``})})]}),(0,$.jsxs)(Zt,{children:[(0,$.jsx)(Ln,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsx)(Lt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{if(g)try{await r({organizationId:t.id,memberIdOrUserId:g.id}),X.success(e(`organization.members.memberRemoved`,{defaultValue:`Member removed`})),_(null),v()}catch(t){X.error(M_(t,e,{key:`organization.members.removeFailed`,defaultValue:`Failed to remove member`}))}},children:e(`organization.members.removeConfirmAction`,{defaultValue:`Remove`})})]})]})}),o&&(0,$.jsx)(V_,{organizationId:t.id,open:m,onOpenChange:h,onInvited:()=>v()})]})}function Y_(e){switch(e){case`pending`:return`outline`;case`accepted`:return`default`;case`rejected`:case`canceled`:return`destructive`}}function X_(){let{t:e}=G(),{org:t}=R_(),{listInvitations:n,cancelInvitation:r,activeMember:i}=C(),a=K_(i?.role),o=W_(i?.role),[s,c]=(0,Q.useState)([]),[l,u]=(0,Q.useState)(!0),[d,f]=(0,Q.useState)(null),[p,m]=(0,Q.useState)(`all`),[h,g]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(null),y=(0,Q.useCallback)(async()=>{u(!0),f(null);try{let e=await n(t.id);c(e)}catch(t){f(M_(t,e,{key:`organization.invitations.loadFailed`,defaultValue:`Failed to load invitations`}))}finally{u(!1)}},[t.id,n,e]);(0,Q.useEffect)(()=>{y()},[y]);let b=async t=>{let n=Uu(`accept-invitation/${t.id}`);try{await navigator.clipboard.writeText(n),v(t.id),X.success(e(`organization.invitations.linkCopied`,{defaultValue:`Invitation link copied`})),setTimeout(()=>v(null),2e3)}catch{X.error(e(`organization.invitations.copyFailed`,{defaultValue:`Failed to copy link`}))}},x=async()=>{if(h)try{await r(h.id),X.success(e(`organization.invitations.canceled`,{defaultValue:`Invitation canceled`})),g(null),y()}catch(t){X.error(M_(t,e,{key:`organization.invitations.cancelFailed`,defaultValue:`Failed to cancel invitation`}))}},S=p===`all`?s:s.filter(e=>e.status===p),w={all:s.length,pending:s.filter(e=>e.status===`pending`).length,accepted:s.filter(e=>e.status===`accepted`).length,rejected:s.filter(e=>e.status===`rejected`).length,canceled:s.filter(e=>e.status===`canceled`).length};return l?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,$.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):d?(0,$.jsxs)(`div`,{className:`rounded-lg border border-destructive/50 bg-destructive/10 p-6 text-center text-sm text-destructive`,children:[d,(0,$.jsx)(J,{variant:`outline`,size:`sm`,className:`ml-4`,onClick:y,children:e(`common.retry`,{defaultValue:`Retry`})})]}):(0,$.jsxs)(`div`,{className:`space-y-4`,"data-testid":`invitations-page`,children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.invitations.title`,{defaultValue:`Invitations`})})}),(0,$.jsx)(`div`,{className:`flex gap-1 border-b`,children:[`all`,`pending`,`accepted`,`rejected`,`canceled`].map(t=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>m(t),className:`px-3 py-2 text-sm font-medium border-b-2 transition-colors capitalize ${p===t?`border-primary text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[e(`organization.invitations.status.${t}`,{defaultValue:t}),w[t]>0&&(0,$.jsx)(`span`,{className:`ml-1.5 rounded-full bg-muted px-1.5 py-0.5 text-xs`,children:w[t]})]},t))}),(0,$.jsx)(bt,{}),S.length===0?(0,$.jsx)(`div`,{className:`rounded-lg border border-dashed p-8 text-center text-sm text-muted-foreground`,children:e(`organization.invitations.empty`,{defaultValue:`No invitations found.`})}):(0,$.jsx)(`div`,{className:`space-y-2`,children:S.map(t=>(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-lg border bg-card p-3`,"data-testid":`invitation-row-${t.id}`,children:[(0,$.jsx)(At,{className:`h-9 w-9 shrink-0`,children:(0,$.jsx)(Vt,{className:`text-xs`,children:(0,$.jsx)(ii,{className:`h-4 w-4`})})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate font-medium text-sm`,children:t.email}),t.expiresAt&&(0,$.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[e(`organization.invitations.expiresAt`,{defaultValue:`Expires`}),` `,new Date(t.expiresAt).toLocaleDateString()]})]}),(0,$.jsx)(hn,{variant:`outline`,className:`shrink-0`,"data-testid":`invitation-role-badge-${t.id}`,children:B_(t.role,e)}),(0,$.jsx)(hn,{variant:Y_(t.status),className:`shrink-0 capitalize`,children:e(`organization.invitations.status.${t.status}`,{defaultValue:t.status})}),t.status===`pending`&&(o||a)&&(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1`,children:[o&&(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8`,onClick:()=>b(t),"aria-label":e(`organization.invitations.copyLinkLabel`,{defaultValue:`Copy invitation link`}),children:_===t.id?(0,$.jsx)(Pr,{className:`h-4 w-4 text-green-600`}):(0,$.jsx)(jt,{className:`h-4 w-4`})}),a&&(0,$.jsx)(J,{variant:`ghost`,size:`icon`,className:`h-8 w-8 text-destructive hover:text-destructive`,onClick:()=>g(t),"aria-label":e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`}),children:(0,$.jsx)(ci,{className:`h-4 w-4`})})]})]},t.id))}),(0,$.jsx)(Vn,{open:!!h,onOpenChange:e=>!e&&g(null),children:(0,$.jsxs)(Yn,{children:[(0,$.jsxs)(xi,{children:[(0,$.jsx)(qt,{children:e(`organization.invitations.cancelTitle`,{defaultValue:`Cancel invitation?`})}),(0,$.jsx)(Nt,{children:e(`organization.invitations.cancelDescription`,{defaultValue:`The invitation for {{email}} will be revoked.`,email:h?.email??``})})]}),(0,$.jsxs)(Zt,{children:[(0,$.jsx)(Ln,{children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsx)(Lt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:x,children:e(`organization.invitations.cancelAction`,{defaultValue:`Cancel invitation`})})]})]})})]})}function Z_(){let{t:e}=G(),{org:t}=R_(),{user:n,getMembers:r,updateOrganization:i,deleteOrganization:a,leaveOrganization:o}=C(),s=p(),[c,l]=(0,Q.useState)(t.name),[u,d]=(0,Q.useState)(t.slug??``),[f,m]=(0,Q.useState)(t.logo??``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(!1),y=(0,Q.useRef)(null),{upload:b}=On(),[x,S]=(0,Q.useState)(null),[w,T]=(0,Q.useState)(!0),[E,D]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(``),[M,ee]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{l(t.name),d(t.slug??``),m(t.logo??``)},[t]),(0,Q.useEffect)(()=>{let e=!1;return T(!0),r(t.id).then(t=>{if(e)return;let r=t.find(e=>e.userId===n?.id);S(r?.role===`owner`)}).catch(()=>{e||S(!1)}).finally(()=>{e||T(!1)}),()=>{e=!0}},[t.id,n?.id,r]);let N=(0,Q.useCallback)(async n=>{n.preventDefault(),g(!0);try{await i(t.id,{name:c.trim(),slug:u.trim()||void 0,logo:f.trim()||void 0}),X.success(e(`organization.settings.saved`,{defaultValue:`Settings saved`}))}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.saveFailed`,{defaultValue:`Failed to save settings`}))}finally{g(!1)}},[t.id,c,u,f,i,e]);return w?(0,$.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,$.jsx)(Y,{className:`h-5 w-5 animate-spin text-muted-foreground`})}):(0,$.jsxs)(`div`,{className:`space-y-8`,"data-testid":`settings-page`,children:[(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold`,children:e(`organization.settings.generalTitle`,{defaultValue:`General`})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:e(`organization.settings.generalDescription`,{defaultValue:`Update your organization information.`})}),(0,$.jsx)(bt,{className:`my-4`}),x?(0,$.jsxs)(`form`,{onSubmit:N,className:`space-y-4 max-w-md`,children:[(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(K,{htmlFor:`org-name`,children:e(`organization.settings.nameLabel`,{defaultValue:`Organization name`})}),(0,$.jsx)(q,{id:`org-name`,value:c,onChange:e=>l(e.target.value),required:!0,"data-testid":`settings-name-input`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(K,{htmlFor:`org-slug`,children:e(`organization.settings.slugLabel`,{defaultValue:`Slug`})}),(0,$.jsx)(q,{id:`org-slug`,value:u,onChange:e=>d(e.target.value),"data-testid":`settings-slug-input`})]}),(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsx)(K,{children:e(`organization.settings.logoLabel`,{defaultValue:`Logo`})}),(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsxs)(At,{className:`size-16 rounded-md`,children:[f?(0,$.jsx)(Qt,{src:f,alt:c,className:`object-cover`}):null,(0,$.jsx)(Vt,{className:`rounded-md text-base`,children:(c||`O`).slice(0,2).toUpperCase()})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(`input`,{ref:y,type:`file`,accept:`image/*`,className:`hidden`,onChange:async t=>{let n=t.target.files?.[0];if(y.current&&(y.current.value=``),n){v(!0);try{let t=await b(n);m(t.url),X.success(e(`organization.settings.logoUploaded`,{defaultValue:`Logo uploaded — save to apply`}))}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.logoUploadFailed`,{defaultValue:`Failed to upload logo`}))}finally{v(!1)}}},"data-testid":`settings-logo-file`}),(0,$.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,disabled:_,onClick:()=>y.current?.click(),"data-testid":`settings-logo-upload-btn`,children:[_?(0,$.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}):(0,$.jsx)(Br,{className:`mr-2 h-4 w-4`}),f?e(`organization.settings.logoReplace`,{defaultValue:`Replace`}):e(`organization.settings.logoUpload`,{defaultValue:`Upload`})]}),f&&(0,$.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>m(``),"data-testid":`settings-logo-clear-btn`,children:[(0,$.jsx)(ci,{className:`mr-2 h-4 w-4`}),e(`organization.settings.logoClear`,{defaultValue:`Remove`})]})]}),(0,$.jsx)(q,{id:`org-logo`,type:`url`,value:f,onChange:e=>m(e.target.value),placeholder:`https://example.com/logo.png`,className:`text-xs`,"data-testid":`settings-logo-input`})]})]})]}),(0,$.jsxs)(J,{type:`submit`,disabled:h,"data-testid":`settings-save-btn`,children:[h&&(0,$.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.save`,{defaultValue:`Save changes`})]})]}):(0,$.jsx)(`div`,{className:`rounded-lg border bg-muted/50 p-4 text-sm text-muted-foreground`,children:e(`organization.settings.readOnlyNote`,{defaultValue:`Only owners can change settings.`})})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h2`,{className:`text-lg font-semibold text-destructive`,children:e(`organization.settings.dangerZone`,{defaultValue:`Danger zone`})}),(0,$.jsx)(bt,{className:`my-4`}),(0,$.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-destructive/50 bg-destructive/5 p-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.leaveTitle`,{defaultValue:`Leave organization`})}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.leaveDescription`,{defaultValue:`You will lose access to this organization.`})})]}),(0,$.jsx)(J,{variant:`destructive`,size:`sm`,onClick:()=>D(!0),children:e(`organization.settings.leaveAction`,{defaultValue:`Leave`})})]}),(0,$.jsx)(bt,{}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`font-medium text-sm`,children:e(`organization.settings.deleteTitle`,{defaultValue:`Delete organization`})}),(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e(`organization.settings.deleteDescription`,{defaultValue:`Permanently delete this organization and all its data.`})})]}),(0,$.jsx)(J,{variant:`destructive`,size:`sm`,onClick:()=>{j(``),k(!0)},disabled:!x,children:e(`organization.settings.deleteAction`,{defaultValue:`Delete`})})]})]})]}),(0,$.jsx)(Vn,{open:E,onOpenChange:D,children:(0,$.jsxs)(Yn,{children:[(0,$.jsxs)(xi,{children:[(0,$.jsx)(qt,{children:e(`organization.settings.leaveConfirmTitle`,{defaultValue:`Leave organization?`})}),(0,$.jsx)(Nt,{children:e(`organization.settings.leaveConfirmDescription`,{defaultValue:`Are you sure you want to leave {{name}}? You will lose access immediately.`,name:t.name})})]}),(0,$.jsxs)(Zt,{children:[(0,$.jsx)(Ln,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(Lt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{ee(!0);try{await o(t.id),X.success(e(`organization.settings.leftOrg`,{defaultValue:`You have left the organization`})),s(`/organizations`)}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.leaveFailed`,{defaultValue:`Failed to leave organization`}))}finally{ee(!1)}},disabled:M,children:[M&&(0,$.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.leaveConfirmAction`,{defaultValue:`Leave`})]})]})]})}),(0,$.jsx)(Vn,{open:O,onOpenChange:e=>{k(e),e||j(``)},children:(0,$.jsxs)(Yn,{children:[(0,$.jsxs)(xi,{children:[(0,$.jsx)(qt,{children:e(`organization.settings.deleteConfirmTitle`,{defaultValue:`Delete organization?`})}),(0,$.jsx)(Nt,{children:e(`organization.settings.deleteConfirmDescription`,{defaultValue:`This action is irreversible. All data will be permanently deleted. Type the organization slug to confirm.`})})]}),(0,$.jsxs)(`div`,{className:`px-6 pb-2`,children:[(0,$.jsx)(K,{htmlFor:`delete-confirm-slug`,className:`text-sm font-medium`,children:e(`organization.settings.deleteConfirmSlugLabel`,{defaultValue:`Type "{{slug}}" to confirm`,slug:t.slug})}),(0,$.jsx)(q,{id:`delete-confirm-slug`,className:`mt-2`,value:A,onChange:e=>j(e.target.value),placeholder:t.slug,"data-testid":`delete-confirm-slug-input`})]}),(0,$.jsxs)(Zt,{children:[(0,$.jsx)(Ln,{disabled:M,children:e(`common.cancel`,{defaultValue:`Cancel`})}),(0,$.jsxs)(Lt,{className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,onClick:async()=>{ee(!0);try{await a(t.id),X.success(e(`organization.settings.deleted`,{defaultValue:`Organization deleted`})),s(`/organizations`)}catch(t){X.error(t instanceof Error?t.message:e(`organization.settings.deleteFailed`,{defaultValue:`Failed to delete organization`}))}finally{ee(!1)}},disabled:M||A!==t.slug,children:[M&&(0,$.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.settings.deleteConfirmAction`,{defaultValue:`Delete organization`})]})]})]})})]})}function Q_(){let{t:e}=G(),t=p(),n=o(),{invitationId:r}=c(),{isAuthenticated:i,isLoading:a,getInvitation:s,acceptInvitation:l,rejectInvitation:u,switchOrganization:d}=C(),[f,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!0),[_,v]=(0,Q.useState)(null),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(!1);return(0,Q.useEffect)(()=>{!a&&!i&&t(`/login?redirect=`+encodeURIComponent(n.pathname+n.search))},[i,a,t,n.pathname,n.search]),(0,Q.useEffect)(()=>{if(!r||!i)return;let t=!1;return g(!0),v(null),s(r).then(e=>{t||m(e)}).catch(n=>{t||v(M_(n,e,{key:`organization.errors.invitationNotFound`,defaultValue:`This invitation no longer exists or has expired`}))}).finally(()=>{t||g(!1)}),()=>{t=!0}},[r,i,s,e]),a?(0,$.jsx)(`div`,{className:`flex min-h-svh items-center justify-center`,children:(0,$.jsx)(Y,{className:`h-6 w-6 animate-spin text-muted-foreground`})}):i?(0,$.jsx)(`div`,{className:`flex min-h-svh items-center justify-center px-4 py-12 bg-background`,children:(0,$.jsx)(`div`,{className:`w-full max-w-md rounded-xl border bg-card p-8 shadow-sm`,"data-testid":`accept-invitation-page`,children:h?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-8`,children:[(0,$.jsx)(Y,{className:`h-8 w-8 animate-spin text-muted-foreground`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e(`organization.accept.loading`,{defaultValue:`Loading invitation…`})})]}):_?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-4 py-8 text-center`,children:[(0,$.jsx)(tr,{className:`h-10 w-10 text-destructive`}),(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:e(`organization.accept.errorTitle`,{defaultValue:`Invitation unavailable`})}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:_}),(0,$.jsx)(J,{variant:`outline`,onClick:()=>t(`/organizations`),children:e(`organization.accept.goToOrgs`,{defaultValue:`Go to organizations`})})]}):f?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-6 text-center`,children:[(0,$.jsx)(`div`,{className:`flex h-14 w-14 items-center justify-center rounded-full bg-primary/10`,children:(0,$.jsx)(Zr,{className:`h-7 w-7 text-primary`})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-xl font-bold`,children:e(`organization.accept.title`,{defaultValue:`You have been invited`})}),(0,$.jsx)(`p`,{className:`mt-2 text-sm text-muted-foreground`,children:e(`organization.accept.description`,{defaultValue:`You have been invited to join {{orgName}} as {{role}}.`,orgName:f.organizationName??f.organizationId,role:B_(f.role,e)})})]}),(0,$.jsxs)(`div`,{className:`w-full rounded-lg border bg-muted/50 p-4 text-left space-y-2`,children:[(0,$.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.organization`,{defaultValue:`Organization`})}),(0,$.jsx)(`span`,{className:`font-medium`,children:f.organizationName??f.organizationId})]}),(0,$.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.role`,{defaultValue:`Role`})}),(0,$.jsx)(`span`,{className:`font-medium`,"data-testid":`accept-invitation-role`,children:B_(f.role,e)})]}),f.expiresAt&&(0,$.jsxs)(`div`,{className:`flex justify-between text-sm`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:e(`organization.accept.expiresAt`,{defaultValue:`Expires`})}),(0,$.jsx)(`span`,{className:`font-medium`,children:new Date(f.expiresAt).toLocaleDateString()})]})]}),(0,$.jsxs)(`div`,{className:`flex w-full gap-3`,children:[(0,$.jsxs)(J,{variant:`outline`,className:`flex-1`,onClick:async()=>{if(r){S(!0);try{await u(r),X.success(e(`organization.accept.declined`,{defaultValue:`Invitation declined`})),t(`/organizations`)}catch(t){X.error(M_(t,e,{key:`organization.accept.declineFailed`,defaultValue:`Failed to decline invitation`})),S(!1)}}},disabled:x||y,children:[x&&(0,$.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),e(`organization.accept.decline`,{defaultValue:`Decline`})]}),(0,$.jsxs)(J,{className:`flex-1`,onClick:async()=>{if(!(!f||!r)){b(!0);try{await l(r),await d(f.organizationId).catch(()=>null),X.success(e(`organization.accept.accepted`,{defaultValue:`Invitation accepted`})),t(`/home`)}catch(t){X.error(M_(t,e,{key:`organization.accept.acceptFailed`,defaultValue:`Failed to accept invitation`})),b(!1)}}},disabled:y||x,children:[y&&(0,$.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),(0,$.jsx)(dr,{className:`mr-2 h-4 w-4`}),e(`organization.accept.accept`,{defaultValue:`Accept invitation`})]})]})]}):null})}):null}function $_({packageId:e,onCanvasOpenChange:t}){let{tab:n}=c(),r=o(),i=Q.useMemo(()=>{let e=new URLSearchParams(r.search).get(`surface`),t;if(e){let n=e.indexOf(`:`);n>0&&n<e.length-1&&(t={type:e.slice(0,n),name:e.slice(n+1)})}if(!(!n&&!t))return{...n?{pillar:n}:{},...t?{artifact:t}:{}}},[n,r.search]),{user:a}=C(),s=a?.id,l=Q.useMemo(()=>op(),[]),{agents:u,isLoading:d,error:f}=So({apiBase:l}),p=Q.useMemo(()=>Hd(`studio-build`,{agents:u}),[u]),m=p?`${l}/agents/${encodeURIComponent(p)}/chat`:void 0,{conversationId:h,initialMessages:g}=pf({userId:p?s:void 0,scope:p?_f({appId:e,product:gf(p)}):void 0,apiBase:l,activeId:void 0,forceNew:!1}),_=Q.useRef(null);return!d&&u.length===0?null:(0,$.jsx)(Sp,{agents:u,agentsLoading:d,agentsError:f,activeAgent:p,chatApi:m,apiBase:l,conversationId:h,editPackageId:e,surfaceContext:i,initialMessages:g,pendingFirstMessageRef:_,onSent:()=>{},onShare:()=>{},showDebug:!1,onCanvasOpenChange:t},`${m??`local`}:${h??`pending`}`)}function ev({packageId:e,locale:t}){let n=p(),r=o(),i=Q.useMemo(()=>op(),[]),a=om({defaultExpanded:!0,persistExpandedKey:Ed,persistWidthKey:Dd}),s=sr(),[c,l]=Q.useState(!1),{agents:u,isLoading:d}=So({apiBase:i}),f=Q.useCallback(e=>e?a.maximize():a.restore(),[a.maximize,a.restore]),m=Q.useCallback(()=>{Fd(`${r.pathname}${r.search}`);try{sessionStorage.setItem(`objectstack:ai-full-page-requested`,`1`)}catch{}n(`/ai/build?package=${encodeURIComponent(e)}`)},[r.pathname,r.search,n,e]);return!d&&u.length===0?null:s?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(um,{onExpand:()=>l(!0),className:`inline-flex md:hidden`}),(0,$.jsx)(lm,{open:c,onOpenChange:l,title:Z(`engine.studio.aiCopilot`,t),onMaximize:m,children:(0,$.jsx)($_,{packageId:e})})]}):a.expanded?(0,$.jsx)(cm,{dock:a,title:Z(`engine.studio.aiCopilot`,t),onMaximize:m,children:(0,$.jsx)($_,{packageId:e,onCanvasOpenChange:f})}):(0,$.jsx)(um,{onExpand:a.expand})}function tv(e,t,n){return!t&&n?`properties`:t&&!n?`canvas`:e}var nv=1280;function rv(){let[e,t]=Q.useState(void 0);return Q.useEffect(()=>{let e=window.matchMedia(`(min-width: ${nv}px)`),n=()=>t(window.innerWidth>=nv);return e.addEventListener(`change`,n),t(window.innerWidth>=nv),()=>e.removeEventListener(`change`,n)},[]),!!e}var iv=[`read`,`create`,`update`,`delete`,`transfer`,`restore`,`purge`],av={grants:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,denies:`border-destructive/40 bg-destructive/10 text-destructive`,narrows:`border-amber-400/50 bg-amber-400/10 text-amber-700 dark:text-amber-300`,widens:`border-sky-400/50 bg-sky-400/10 text-sky-700 dark:text-sky-300`,neutral:`border-border bg-muted/40 text-muted-foreground`,not_applicable:`border-border bg-transparent text-muted-foreground/60`},ov={admitted:`border-emerald-500/40 bg-emerald-500/10 text-emerald-700 dark:text-emerald-400`,excluded:`border-destructive/40 bg-destructive/10 text-destructive`,not_evaluated:`border-border bg-transparent text-muted-foreground/60`},sv={admits:`bg-emerald-500`,excludes:`bg-destructive`,neutral:`bg-muted-foreground/40`},cv=e=>{let t=e??{};return String(t.full_name||t.name||t.display_name||t.email||t.id||``)};function lv({open:e,onOpenChange:t,defaultObject:n,packageId:r}){let i=Mc(),a=Ue(),o=oa(),s=Q.useMemo(()=>b(),[]),[c,l]=Q.useState(null);Q.useEffect(()=>{if(!e||!r){l(null);return}let t=!1;return(async()=>{try{let e=(await o.list(`object`,{packageId:r})??[]).map(e=>{let t=e?.item??e;return{name:String(t?.name??``),label:t?.label}}).filter(e=>!!e.name).sort((e,t)=>e.name.localeCompare(t.name));t||l(e)}catch{t||l(null)}})(),()=>{t=!0}},[e,r,o]);let[u,d]=Q.useState(n??``),[f,p]=Q.useState(`read`),[m,h]=Q.useState(null),[g,_]=Q.useState(``),[v,y]=Q.useState(!1),[x,S]=Q.useState(!1),[C,w]=Q.useState(!1),[T,E]=Q.useState(null),[D,O]=Q.useState(null);Q.useEffect(()=>{n&&d(e=>e||n)},[n]);let k=Q.useCallback(async()=>{let e=u.trim();if(e){w(!0),E(null),O(null);try{let t=``.replace(/\/+$/,``),n=await s(`${t}/api/v1/security/explain`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({object:e,operation:f,...m?{userId:m.id}:{},...g.trim()?{recordId:g.trim()}:{}})}),r=null;try{r=await n.json()}catch{}if(n.status===403){E(Z(`engine.studio.access.explain.forbidden`,i));return}if(!n.ok){let e=r?.message||r?.error||`HTTP ${n.status} ${n.statusText}`.trim();E(e);return}O(r)}catch(e){E(e?.message??String(e))}finally{w(!1)}}},[s,u,f,m,g,i]),A=e=>Z(`engine.studio.access.explain.op.${e}`,i);return(0,$.jsx)(Bi,{open:e,onOpenChange:t,children:(0,$.jsxs)(Yi,{side:`right`,className:`w-full overflow-y-auto sm:max-w-xl`,children:[(0,$.jsxs)(Ki,{children:[(0,$.jsxs)(Tn,{className:`flex items-center gap-2`,children:[(0,$.jsx)(vn,{className:`h-4 w-4`}),` `,Z(`engine.studio.access.explain.title`,i)]}),(0,$.jsx)(hr,{children:Z(`engine.studio.access.explain.description`,i)})]}),(0,$.jsxs)(`div`,{className:`mt-4 space-y-3 text-sm`,children:[(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.user`,i)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>y(!0),className:`flex h-8 min-w-0 flex-1 items-center gap-2 rounded-md border bg-background px-2 text-left text-xs hover:bg-muted/60`,children:[(0,$.jsx)(br,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:m?m.label:Z(`engine.studio.access.explain.self`,i)}),(0,$.jsx)(_r,{className:`h-3 w-3 shrink-0 text-muted-foreground/70`})]}),m&&(0,$.jsx)(J,{variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>h(null),"aria-label":Z(`engine.studio.access.explain.clearUser`,i),title:Z(`engine.studio.access.explain.clearUser`,i),children:(0,$.jsx)(ci,{className:`h-4 w-4`})})]})]}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`explain-object`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.object`,i)}),c&&c.length>0?(0,$.jsxs)(`select`,{id:`explain-object`,value:u,onChange:e=>d(e.target.value),className:`h-8 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-1 focus:ring-primary`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.access.explain.objectSelect`,i)}),c.map(e=>(0,$.jsx)(`option`,{value:e.name,children:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name},e.name))]}):(0,$.jsx)(q,{id:`explain-object`,value:u,onChange:e=>d(e.target.value),placeholder:Z(`engine.studio.access.explain.objectPlaceholder`,i),className:`h-8 text-xs`})]}),(0,$.jsxs)(`div`,{className:`w-32 shrink-0 space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`explain-operation`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.operation`,i)}),(0,$.jsx)(`select`,{id:`explain-operation`,value:f,onChange:e=>p(e.target.value),className:`h-8 w-full rounded-md border bg-background px-2 text-xs outline-none focus:ring-1 focus:ring-primary`,children:iv.map(e=>(0,$.jsx)(`option`,{value:e,children:A(e)},e))})]})]}),(0,$.jsxs)(`div`,{className:`space-y-1`,children:[(0,$.jsx)(`label`,{htmlFor:`explain-record`,className:`text-xs font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.record`,i)}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(q,{id:`explain-record`,value:g,onChange:e=>_(e.target.value),placeholder:Z(`engine.studio.access.explain.recordPlaceholder`,i),className:`h-8 min-w-0 flex-1 text-xs`}),(0,$.jsxs)(J,{type:`button`,variant:`outline`,size:`sm`,className:`h-8 shrink-0 gap-1 text-xs`,disabled:!u.trim(),onClick:()=>S(!0),title:Z(`engine.studio.access.explain.pickRecord`,i),children:[(0,$.jsx)(_r,{className:`h-3 w-3`}),Z(`engine.studio.access.explain.pickRecord`,i)]}),g&&(0,$.jsx)(J,{variant:`ghost`,size:`sm`,className:`h-8 w-8 shrink-0 p-0 text-muted-foreground`,onClick:()=>_(``),"aria-label":Z(`engine.studio.access.explain.clearRecord`,i),title:Z(`engine.studio.access.explain.clearRecord`,i),children:(0,$.jsx)(ci,{className:`h-4 w-4`})})]})]}),(0,$.jsxs)(J,{size:`sm`,className:`h-8 gap-1.5 text-xs`,disabled:C||!u.trim(),onClick:()=>void k(),children:[C?(0,$.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(ut,{className:`h-3.5 w-3.5`}),Z(C?`engine.studio.access.explain.running`:`engine.studio.access.explain.run`,i)]})]}),(0,$.jsxs)(`div`,{className:`mt-5 space-y-4 text-sm`,children:[T&&!C&&(0,$.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive/40 bg-destructive/5 p-3 text-xs text-destructive`,children:[(0,$.jsx)(Ji,{className:`mt-0.5 h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:Z(`engine.studio.access.explain.failed`,i)}),` — `,T]})]}),!D&&!T&&!C&&(0,$.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:Z(`engine.studio.access.explain.empty`,i)}),D&&!C&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{"data-testid":`explain-verdict`,className:D.allowed?`flex items-center gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/10 p-3 text-emerald-700 dark:text-emerald-400`:`flex items-center gap-2 rounded-md border border-destructive/30 bg-destructive/10 p-3 text-destructive`,children:[D.allowed?(0,$.jsx)(Gr,{className:`h-4 w-4 shrink-0`}):(0,$.jsx)(tr,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:Nc(D.allowed?`engine.studio.access.explain.allowedLine`:`engine.studio.access.explain.deniedLine`,i,{operation:A(D.operation),object:D.object})})]}),D.record&&(0,$.jsxs)(`div`,{"data-testid":`explain-record-verdict`,className:D.record.visible?`flex items-start gap-2 rounded-md border border-emerald-500/30 bg-emerald-500/5 p-3 text-emerald-700 dark:text-emerald-400`:`flex items-start gap-2 rounded-md border border-destructive/30 bg-destructive/5 p-3 text-destructive`,children:[D.record.visible?(0,$.jsx)(Gr,{className:`mt-0.5 h-4 w-4 shrink-0`}):(0,$.jsx)(tr,{className:`mt-0.5 h-4 w-4 shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0 text-xs`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:Nc(D.record.visible?`engine.studio.access.explain.recordVisibleLine`:`engine.studio.access.explain.recordHiddenLine`,i,{recordId:D.record.recordId})}),D.record.decidedBy&&(0,$.jsxs)(`div`,{className:`mt-0.5 text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.decidedBy`,i),`:`,` `,(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:Z(`engine.studio.access.explain.layer.${D.record.decidedBy}`,i)})]})]})]}),(0,$.jsxs)(`div`,{className:`rounded-md border bg-muted/30 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:`text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.principal`,i)}),D.principal.posture&&(0,$.jsx)(hn,{variant:`outline`,"data-testid":`explain-posture`,className:`px-1.5 py-0 text-[10px] font-medium`,title:Z(`engine.studio.access.explain.postureHint`,i),children:Z(`engine.studio.access.explain.posture.${D.principal.posture}`,i)})]}),(0,$.jsxs)(`p`,{className:`mt-1 truncate font-mono text-xs text-foreground`,children:[D.principal.userId??`(anonymous)`,D.principal.onBehalfOf?.userId?` ⇄ ${D.principal.onBehalfOf.userId}`:``]}),(0,$.jsxs)(`div`,{className:`mt-2 space-y-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.positions`,i),`:`]}),(D.principal.positions??[]).map(e=>(0,$.jsx)(hn,{variant:`outline`,className:`px-1.5 py-0 text-[10px] font-normal`,children:e},e))]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[Z(`engine.studio.access.explain.permissionSets`,i),`:`]}),(D.principal.permissionSets??[]).map(e=>(0,$.jsx)(hn,{variant:`secondary`,className:`px-1.5 py-0 text-[10px] font-normal`,children:e},e))]})]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.layers`,i)}),(0,$.jsx)(`ol`,{className:`space-y-2`,children:D.layers.map(e=>(0,$.jsxs)(`li`,{className:`rounded-md border p-2.5`,"data-testid":`explain-layer-${e.layer}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-xs font-medium`,children:Z(`engine.studio.access.explain.layer.${e.layer}`,i)}),(0,$.jsx)(`span`,{className:`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none ${av[e.verdict]??av.neutral}`,children:Z(`engine.studio.access.explain.verdict.${e.verdict}`,i)}),e.kernelTier&&(0,$.jsx)(`span`,{className:`shrink-0 rounded border border-border bg-muted/40 px-1.5 py-0.5 text-[9px] uppercase leading-none text-muted-foreground`,title:Z(`engine.studio.access.explain.kernelTierHint`,i),children:Z(`engine.studio.access.explain.kernelTier.${e.kernelTier}`,i)})]}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] leading-relaxed text-muted-foreground`,children:e.detail}),(e.contributors??[]).length>0&&(0,$.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap items-center gap-1`,children:[(0,$.jsxs)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:[Z(`engine.studio.access.explain.contributors`,i),`:`]}),(e.contributors??[]).map((e,t)=>(0,$.jsx)(hn,{variant:e.kind===`position`?`outline`:`secondary`,className:`px-1.5 py-0 text-[10px] font-normal`,title:e.via?`${e.kind} · via ${e.via}`:e.kind,children:e.name},`${e.kind}:${e.name}:${t}`))]}),e.record&&(0,$.jsxs)(`div`,{className:`mt-2 space-y-1.5 rounded border border-dashed border-border/70 bg-muted/20 p-2`,"data-testid":`explain-record-${e.layer}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-medium uppercase text-muted-foreground/70`,children:Z(`engine.studio.access.explain.recordOutcome`,i)}),(0,$.jsx)(`span`,{className:`shrink-0 rounded border px-1.5 py-0.5 text-[10px] leading-none ${ov[e.record.outcome]??ov.not_evaluated}`,children:Z(`engine.studio.access.explain.outcome.${e.record.outcome}`,i)}),e.record.matchesRecord!=null&&(0,$.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70`,children:Z(e.record.matchesRecord?`engine.studio.access.explain.matches`:`engine.studio.access.explain.noMatch`,i)})]}),e.record.detail&&(0,$.jsx)(`p`,{className:`text-[11px] leading-relaxed text-muted-foreground`,children:e.record.detail}),(e.record.rules??[]).length>0&&(0,$.jsx)(`ul`,{className:`space-y-1`,children:(e.record.rules??[]).map((e,t)=>(0,$.jsxs)(`li`,{className:`flex items-center gap-1.5 text-[11px]`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 shrink-0 rounded-full ${sv[e.effect]??sv.neutral}`,title:e.effect}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:Z(`engine.studio.access.explain.ruleKind.${e.kind}`,i)}),(0,$.jsx)(`span`,{className:`min-w-0 truncate text-muted-foreground`,title:e.name,children:e.name}),e.grants&&(0,$.jsx)(hn,{variant:`secondary`,className:`px-1 py-0 text-[9px] font-normal`,children:e.grants}),e.via&&(0,$.jsxs)(`span`,{className:`min-w-0 truncate text-[10px] text-muted-foreground/70`,children:[`· `,e.via]})]},`${e.kind}:${e.name}:${t}`))}),e.record.rowFilter!==void 0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-[10px] font-medium text-muted-foreground/70`,children:Z(`engine.studio.access.explain.effectiveRowFilter`,i)}),(0,$.jsx)(`pre`,{className:`mt-0.5 overflow-x-auto rounded border bg-background/60 p-1.5 font-mono text-[10px] leading-snug`,children:JSON.stringify(e.record.rowFilter,null,2)})]})]})]},e.layer))})]}),D.operation===`read`&&D.readFilter!==void 0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.explain.readFilter`,i)}),(0,$.jsx)(`pre`,{className:`overflow-x-auto rounded-md border bg-muted/30 p-2 font-mono text-[11px] leading-snug`,children:JSON.stringify(D.readFilter,null,2)})]})]})]}),(0,$.jsx)(xn,{open:v,onOpenChange:e=>y(e),dataSource:a,objectName:`sys_user`,title:Z(`engine.studio.access.explain.pickUserTitle`,i),onSelect:()=>{},onSelectRecords:e=>{let t=e?.[0];t?.id!=null&&h({id:String(t.id),label:cv(t)}),y(!1)}}),u.trim()&&(0,$.jsx)(xn,{open:x,onOpenChange:e=>S(e),dataSource:a,objectName:u.trim(),title:Z(`engine.studio.access.explain.pickRecordTitle`,i),onSelect:()=>{},onSelectRecords:e=>{let t=e?.[0];t?.id!=null&&_(String(t.id)),S(!1)}})]})})}async function uv(e,t,n){let[r,i]=await Promise.all([e.list(t,{packageId:n}),e.listDrafts({packageId:n,type:t}).catch(()=>[])]),a=(r||[]).map(e=>({type:t,name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name),o=new Set(a.map(e=>e.name));for(let e of i||[]){let n=String(e?.name??``);n&&!o.has(n)&&(a.push({type:t,name:n,label:n}),o.add(n))}return a}function dv(e=!1){let[t,n]=(0,Q.useState)(0),[r,i]=(0,Q.useState)(0);return(0,Q.useEffect)(()=>va(()=>n(e=>e+1)),[]),(0,Q.useEffect)(()=>{e||i(e=>e===t?e:t)},[e,t]),r}function fv(e){let t=String(e.label??``);switch(e.type){case`page`:return e.pageName?{type:`page`,name:String(e.pageName),label:t}:null;case`object`:return e.objectName?{type:`object`,name:String(e.objectName),label:t}:null;case`dashboard`:return e.dashboardName?{type:`dashboard`,name:String(e.dashboardName),label:t}:null;case`report`:return e.reportName?{type:`report`,name:String(e.reportName),label:t}:null;case`action`:return e.actionDef?.actionName?{type:`action`,name:String(e.actionDef.actionName),label:t}:null;default:return null}}function pv(e,t){for(let n of e)if(n.type===`group`||n.children?.length){let e=pv(n.children??[],t);if(e)return e}else{let e=fv(n);if(e&&e.type===t.type&&e.name===t.name)return e}return null}function mv(e){let[t,n]=s(),r=Q.useRef($s(t.get(ec))),i=e?.type,a=e?.name;return Q.useEffect(()=>{!i||!a||n(e=>{let t=new URLSearchParams(e);return t.set(ec,Ys({type:i,name:a})),t},{replace:!0})},[i,a]),r.current}function hv(e,t,n){if(!(!t||t.type!==n))return e.find(e=>e.name===t.name)}function gv(e,t,n,r){return{name:e,label:t,sharingModel:r,fields:{name:{type:`text`,label:n}}}}function _v(e,t,n,r){return{name:e,label:t,type:`autolaunched`,nodes:[{id:`start`,type:`start`,label:n},{id:`end`,type:`end`,label:r}],edges:[{id:`e1`,source:`start`,target:`end`}]}}function vv(e,t,n=[]){return{name:e,label:t,active:!0,navigation:n.map(e=>({id:`nav_${e.name}`,type:`object`,label:e.label,objectName:e.name}))}}function yv(e,t){return{name:e,label:t,objects:{},fields:{}}}var bv={private:0,public_read:1,public_read_write:2};function xv(e,t){return!!t&&t in bv&&!!e&&e in bv&&bv[t]>bv[e]}function Sv(e){for(let t of ic(e).entries)if((t.def.type??``)===`master_detail`){let e=t.def.reference;if(typeof e==`string`&&e)return e}}var Cv=[`private`,`public_read`,`public_read_write`],wv=`private`;function Tv({open:e,onOpenChange:t,title:n,description:r,labelFieldLabel:i,labelPlaceholder:a,idFieldLabel:o,idPlaceholder:s,submitLabel:c,submittingLabel:l,busy:u=!1,error:d,locale:f,extra:p,onSubmit:m}){let[h,g]=Q.useState(``),[_,v]=Q.useState(``),[y,b]=Q.useState(!1);Q.useEffect(()=>{e&&(g(``),v(``),b(!1))},[e]);let x=sc((_.trim()||h).trim()),S=!!h.trim()&&!!x&&x!==`field`,C=()=>{!S||u||m({label:h.trim(),name:x})};return(0,$.jsx)(Vi,{open:e,onOpenChange:t,children:(0,$.jsxs)(Xi,{children:[(0,$.jsxs)(En,{children:[(0,$.jsx)(xt,{children:n}),r&&(0,$.jsx)(gr,{children:r})]}),(0,$.jsxs)(`div`,{className:`space-y-4 py-2`,children:[(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(K,{children:i}),(0,$.jsx)(q,{autoFocus:!0,value:h,onChange:e=>{g(e.target.value),y||v(_c(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&C()},placeholder:a})]}),(0,$.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,$.jsx)(K,{children:o}),(0,$.jsx)(q,{className:`font-mono`,value:_,onChange:e=>{b(!0),v(_c(e.target.value))},onKeyDown:e=>{e.key===`Enter`&&C()},placeholder:s})]}),p,d&&(0,$.jsx)(`p`,{className:`text-sm text-destructive`,children:d})]}),(0,$.jsxs)(qi,{children:[(0,$.jsx)(J,{variant:`outline`,onClick:()=>t(!1),disabled:u,children:Z(`engine.studio.cancel`,f)}),(0,$.jsx)(J,{onClick:C,disabled:!S||u,children:u?l??c:c})]})]})})}function Ev(e){return e.startsWith(`field:`)?e:Wn(e)}var Dv=`__ungrouped__`,Ov=e=>`g:${e}`,kv=e=>`f:${e}`,Av=e=>e.slice(2),jv=e=>e.slice(2);function Mv({type:e}){let t=Mc(),n=`mt-1 flex items-center rounded-md border bg-muted/30 px-2 text-[11px] text-muted-foreground`;switch(e){case`select`:case`radio`:case`lookup`:case`reference`:case`user`:case`multiselect`:return(0,$.jsxs)(`div`,{className:`${n} h-7 justify-between`,children:[(0,$.jsx)(`span`,{children:Z(e===`lookup`||e===`reference`||e===`user`?`engine.studio.designer.search`:`engine.studio.designer.select`,t)}),(0,$.jsx)(`span`,{children:`▾`})]});case`textarea`:case`html`:case`markdown`:case`json`:case`code`:return(0,$.jsx)(`div`,{className:`${n} h-14 items-start pt-1.5`,children:`…`});case`boolean`:case`checkbox`:case`switch`:return(0,$.jsx)(`div`,{className:`mt-1 flex items-center`,children:(0,$.jsx)(`span`,{className:`h-4 w-7 rounded-full bg-muted`})});case`number`:case`currency`:case`percent`:return(0,$.jsx)(`div`,{className:`${n} h-7`,children:`0.00`});case`date`:case`datetime`:case`time`:return(0,$.jsx)(`div`,{className:`${n} h-7`,children:Z(`engine.studio.designer.pickDate`,t)});default:return(0,$.jsx)(`div`,{className:`${n} h-7`,children:`\xA0`})}}function Nv({entry:e,label:t,columns:n,selected:r,onSelect:i}){let a=Mc(),{attributes:o,listeners:s,setNodeRef:c,transform:l,transition:u,isDragging:d}=Ns({id:kv(e.name)}),f=String(e.def.type??`text`),p=!!e.def.required,m=n>1&&ha(Ev(f));return(0,$.jsxs)(`div`,{ref:c,style:{transform:Rs.Transform.toString(l),transition:u},onClick:i,...o,...s,"aria-label":Nc(`engine.studio.designer.fieldAria`,a,{label:t}),className:`group relative flex cursor-grab touch-none select-none items-start gap-1.5 rounded-md border bg-background px-2 py-2 active:cursor-grabbing `+(m?`col-span-full `:``)+(r?`ring-2 ring-primary`:`hover:border-foreground/25`)+(d?` opacity-40`:``),children:[(0,$.jsx)(`span`,{className:`mt-0.5 text-muted-foreground opacity-0 group-hover:opacity-100`,children:(0,$.jsx)(Xt,{className:`h-3.5 w-3.5`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 text-xs font-medium`,children:[(0,$.jsx)(`span`,{className:`truncate`,children:t}),p&&(0,$.jsx)(`span`,{className:`text-destructive`,children:`*`}),(0,$.jsx)(`span`,{className:`ml-1 text-[9px] uppercase tracking-wide text-muted-foreground/70`,children:f})]}),(0,$.jsx)(Mv,{type:f})]})]})}function Pv({containerId:e,title:t,fieldIds:n,columns:r,isDeclared:i,canMoveUp:a,canMoveDown:o,entryByName:s,fieldLabelOf:c,selectedField:l,onSelectField:u,selected:d=!1,onSelect:f,onRename:p,onDelete:m,onMove:h,readOnly:g=!1}){let _=Mc(),{setNodeRef:v,isOver:y}=ks({id:e});return(0,$.jsxs)(`div`,{className:`@container rounded-lg border `+(y?`border-primary bg-primary/5`:d?`border-primary/50 bg-primary/5 ring-2 ring-primary`:`bg-muted/20`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b px-3 py-1.5`,children:[i&&!g?(0,$.jsx)(`input`,{defaultValue:t,onBlur:e=>e.target.value.trim()&&e.target.value!==t&&p(e.target.value),onKeyDown:e=>{e.key===`Enter`&&e.target.blur()},className:`min-w-0 flex-1 rounded bg-transparent px-1 py-0.5 text-[13px] font-medium outline-none hover:bg-muted focus:bg-background focus:ring-1 focus:ring-primary`}):(0,$.jsx)(`span`,{className:`flex-1 px-1 text-[13px] font-medium text-muted-foreground`,children:t}),i&&f&&(0,$.jsx)(`button`,{type:`button`,onClick:f,"aria-label":Z(`engine.studio.designer.group.settings`,_),title:Z(`engine.studio.designer.group.settings`,_),className:`rounded p-0.5 hover:bg-muted `+(d?`text-primary`:`text-muted-foreground hover:text-foreground`),children:(0,$.jsx)(Si,{className:`h-3.5 w-3.5`})}),i&&!g&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{type:`button`,disabled:!a,onClick:()=>h(-1),"aria-label":Z(`engine.studio.designer.groupUp`,_),className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,$.jsx)(jr,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,disabled:!o,onClick:()=>h(1),"aria-label":Z(`engine.studio.designer.groupDown`,_),className:`rounded p-0.5 text-muted-foreground hover:bg-muted disabled:opacity-30`,children:(0,$.jsx)(zr,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:m,"aria-label":Z(`engine.studio.designer.groupDelete`,_),title:Z(`engine.studio.designer.groupDeleteTitle`,_),className:`rounded p-0.5 text-muted-foreground hover:bg-destructive/10 hover:text-destructive`,children:(0,$.jsx)(wn,{className:`h-3.5 w-3.5`})})]})]}),(0,$.jsx)(Fs,{items:n,strategy:Ps,children:(0,$.jsxs)(`div`,{ref:v,className:`min-h-[52px] p-2.5 `+(ua(r)??`grid grid-cols-1 gap-4`),children:[n.length===0&&(0,$.jsx)(`div`,{className:`col-span-full flex items-center justify-center rounded-md border border-dashed py-3 text-[11px] text-muted-foreground`,children:Z(`engine.studio.designer.dropHere`,_)}),n.map(e=>{let t=jv(e),n=s.get(t);return n?(0,$.jsx)(Nv,{entry:n,label:c(n),columns:r,selected:l===t,onSelect:()=>u(t)},e):null})]})})]})}function Fv({draft:e,objectName:t,systemFieldNames:n,onChange:r,selectedField:i,onSelectField:a,onAddField:o,selectedGroup:s,onSelectGroup:c,readOnly:l=!1}){let u=Mc(),d=Q.useMemo(()=>ic(e.fields),[e.fields]),f=Q.useMemo(()=>dc(e.fieldGroups),[e.fieldGroups]),p=Q.useMemo(()=>new Map(d.entries.map(e=>[e.name,e])),[d]),{fieldLabel:m,sectionLabel:h}=$e(),g=t||(typeof e.name==`string`?e.name:``),_=Q.useCallback(e=>{let t=String(e.def.label??e.name);return g?m(g,e.name,t):t},[g,m]),v=Q.useMemo(()=>ma(d.entries.filter(e=>!n.has(e.name)).length),[d.entries,n]),y=Q.useMemo(()=>[...f.map(e=>Ov(e.key)),Ov(Dv)],[f]),b=Q.useMemo(()=>{let e=new Map;for(let t of f){let n=t.label||t.key;e.set(Ov(t.key),g?h(g,t.key,n):n)}return e.set(Ov(Dv),Z(`engine.studio.designer.ungrouped`,u)),e},[f,u,g,h]),x=Q.useMemo(()=>{let e={};for(let t of y)e[t]=[];for(let t of d.entries){if(n.has(t.name))continue;let r=typeof t.def.group==`string`?t.def.group:``;e[r&&e[Ov(r)]?Ov(r):Ov(Dv)].push(kv(t.name))}return e},[d.entries,y,n]),[S,C]=Q.useState(x),[w,T]=Q.useState(null);Q.useEffect(()=>{w||C(x)},[x,w]);let E=Q.useRef(S);Q.useEffect(()=>{E.current=S},[S]);let D=Ls(Ts(Os,{activationConstraint:{distance:4}}),Ts(Is,{coordinateGetter:Es})),O=Q.useCallback(e=>e.startsWith(`g:`)?e:Object.keys(S).find(t=>S[t].includes(e)),[S]),k=Q.useCallback(e=>{let t=[];for(let n of y){let r=Av(n);for(let i of e[n]??[]){let e=p.get(jv(i));if(!e)continue;let n={...e.def};r===Dv?delete n.group:n.group=r,t.push({name:e.name,def:n})}}let i=d.entries.filter(e=>n.has(e.name)),a={shape:d.shape,entries:[...i,...t]};r({fields:mc(a)})},[y,p,d,n,r]),A=e=>T(String(e.active.id)),j=e=>{let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=O(t),i=O(n);!r||!i||r===i||C(e=>{let a=e[r]??[],o=e[i]??[],s=n.startsWith(`g:`)?o.length:o.indexOf(n),c=s<0?o.length:s;return{...e,[r]:a.filter(e=>e!==t),[i]:[...o.slice(0,c),t,...o.slice(c)]}})},M=e=>{T(null);let t=String(e.active.id),n=e.over?String(e.over.id):null;if(!n)return;let r=E.current,i=e=>e.startsWith(`g:`)&&e in r?e:Object.keys(r).find(t=>r[t].includes(e)),a=i(t),o=i(n);if(!a||!o)return;let s;if(a===o){let e=r[a],i=e.indexOf(t),o=n.startsWith(`g:`)?e.length-1:e.indexOf(n);if(i<0||o<0||i===o){k(r);return}s={...r,[a]:Ms(e,i,o)}}else{let e=r[a].filter(e=>e!==t),i=r[o],c=n.startsWith(`g:`)?i.length:i.indexOf(n),l=c<0?i.length:c;s={...r,[a]:e,[o]:[...i.slice(0,l),t,...i.slice(l)]}}C(s),k(s)},ee=()=>r({fieldGroups:nc(f,Z(`engine.studio.designer.newGroup`,u))}),N=(e,t)=>r({fieldGroups:rc(f,e,t)}),te=(e,t)=>r({fieldGroups:tc(f,e,t)}),P=e=>r({fieldGroups:pc(f,e),fields:mc(ac(d,e))}),F=w&&!w.startsWith(`g:`)?p.get(jv(w)):null;return(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background p-4`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(ti,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.designer.hint`,u)]}),!l&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:ee,className:`ml-auto inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,$.jsx)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.designer.addGroup`,u)]}),o&&(0,$.jsxs)(`button`,{type:`button`,onClick:o,className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,$.jsx)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.addField`,u)]})]})]}),(0,$.jsxs)(Ds,{sensors:l?[]:D,collisionDetection:As,onDragStart:A,onDragOver:j,onDragEnd:M,onDragCancel:()=>T(null),children:[(0,$.jsx)(`div`,{className:`mx-auto flex max-w-6xl flex-col gap-3`,children:y.map(e=>{let t=e===Ov(Dv);if(t&&(S[e]?.length??0)===0&&f.length>0)return null;let n=f.findIndex(t=>Ov(t.key)===e);return(0,$.jsx)(Pv,{containerId:e,title:b.get(e)??Z(`engine.studio.designer.ungrouped`,u),fieldIds:S[e]??[],columns:v,isDeclared:!t,canMoveUp:n>0,canMoveDown:n>=0&&n<f.length-1,entryByName:p,fieldLabelOf:_,selectedField:i,onSelectField:a,selected:!t&&s===Av(e),onSelect:!t&&c?()=>c(Av(e)):void 0,onRename:t=>N(Av(e),t),onDelete:()=>P(Av(e)),onMove:t=>te(Av(e),t),readOnly:l},e)})}),(0,$.jsx)(js,{children:F?(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border bg-background px-2 py-2 shadow-lg`,children:[(0,$.jsx)(Xt,{className:`h-3.5 w-3.5 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:_(F)})]}):null})]})]})}function Iv({draft:e,groupKey:t,onPatch:n,onClose:r,readOnly:i=!1,locale:a}){let o=Q.useCallback(e=>Z(e,a),[a]),s=Q.useMemo(()=>dc(e.fieldGroups),[e.fieldGroups]),c=s.find(e=>e.key===t);if(!c)return(0,$.jsx)(Oc,{kindLabel:o(`engine.studio.designer.group.kind`),title:t,onClose:r,closeLabel:o(`engine.studio.close`),children:(0,$.jsx)(kc,{message:o(`engine.studio.designer.group.missing`)})});let l=c.collapse??(c.collapsed?`collapsed`:c.collapsible?`expanded`:`none`),u=e=>n({fieldGroups:oc(s,c.key,{collapse:e===`none`?void 0:e,collapsible:void 0,collapsed:void 0,defaultExpanded:void 0})});return(0,$.jsxs)(Oc,{kindLabel:o(`engine.studio.designer.group.kind`),title:c.label||c.key,onClose:r,closeLabel:o(`engine.studio.close`),children:[(0,$.jsx)(jc,{label:o(`engine.studio.designer.group.nameLabel`),value:c.label,onCommit:e=>n({fieldGroups:oc(s,c.key,{label:e})}),disabled:i,testId:`group-label`}),(0,$.jsx)(Ac,{label:o(`engine.studio.designer.group.collapseLabel`),value:l,onCommit:e=>u(e||`none`),disabled:i,options:[{value:`none`,label:o(`engine.studio.designer.group.collapseNone`)},{value:`expanded`,label:o(`engine.studio.designer.group.collapseExpanded`)},{value:`collapsed`,label:o(`engine.studio.designer.group.collapseCollapsed`)}]}),(0,$.jsx)(`p`,{className:`text-[11px] leading-4 text-muted-foreground`,children:o(`engine.studio.designer.group.collapseHint`)})]})}var Lv=[{value:`script`,labelKey:`engine.studio.rules.typeScript`},{value:`cross_field`,labelKey:`engine.studio.rules.typeCrossField`},{value:`state_machine`,labelKey:`engine.studio.rules.typeStateMachine`},{value:`format`,labelKey:`engine.studio.rules.typeFormat`},{value:`json_schema`,labelKey:`engine.studio.rules.typeJsonSchema`},{value:`conditional`,labelKey:`engine.studio.rules.typeConditional`}],Rv=[`insert`,`update`,`delete`],zv=[``,`url`,`email`,`phone`,`json`];function Bv(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`):[]}function Vv(e){let t=e.length+1,n=`validation_${t}`,r=new Set(e);for(;r.has(n);)n=`validation_${++t}`;return n}function Hv(e,t,n){let r={name:t,message:``,severity:`error`,active:!0};switch(e){case`script`:return{...r,type:e,condition:`false`};case`cross_field`:return{...r,type:e,condition:`false`,fields:n?[n]:[]};case`state_machine`:return{...r,type:e,field:n??``,transitions:{}};case`format`:return{...r,type:e,field:n??``};case`json_schema`:return{...r,type:e,field:n??``,schema:{}};case`conditional`:return{...r,type:e,condition:`false`,then:{type:`script`,name:`${t}_then`,message:``,condition:`false`,severity:`error`}}}}function Uv({label:e,value:t,onCommit:n,disabled:r,locale:i}){let a=Q.useMemo(()=>{if(t==null)return``;try{return JSON.stringify(t,null,2)}catch{return``}},[t]),[o,s]=Q.useState(a),[c,l]=Q.useState(null);return Q.useEffect(()=>{s(a),l(null)},[a]),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:e}),(0,$.jsx)(`textarea`,{value:o,disabled:r,spellCheck:!1,rows:5,onChange:e=>s(e.target.value),onBlur:()=>{let e=o.trim();if(!e){l(null),n(void 0);return}try{n(JSON.parse(e)),l(null)}catch{l(Z(`engine.studio.rules.invalidJson`,i))}},className:`w-full rounded border bg-background px-2 py-1 font-mono text-[11px]`}),c&&(0,$.jsx)(`span`,{className:`mt-1 block text-[11px] text-destructive`,children:c})]})}function Wv({transitions:e,onCommit:t,disabled:n,locale:r}){let i=Object.entries(e),a=(e,n,r)=>{let a={};i.forEach(([t,i],o)=>{o===e?n&&(a[n]=r):a[t]=i}),t(a)};return(0,$.jsxs)(`div`,{className:`space-y-2`,children:[(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.transitions`,r)}),i.map(([e,t],i)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`input`,{value:e,disabled:n,placeholder:Z(`engine.studio.rules.transitionFrom`,r),onChange:e=>a(i,e.target.value,t),className:`w-32 rounded border bg-background px-2 py-1 text-[12px]`}),(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`→`}),(0,$.jsx)(`input`,{value:t.join(`, `),disabled:n,placeholder:Z(`engine.studio.rules.transitionTo`,r),onChange:t=>a(i,e,t.target.value.split(`,`).map(e=>e.trim()).filter(Boolean)),className:`min-w-0 flex-1 rounded border bg-background px-2 py-1 text-[12px]`}),!n&&(0,$.jsx)(`button`,{type:`button`,"aria-label":Z(`engine.studio.rules.delete`,r),onClick:()=>a(i,``,[]),className:`rounded border border-destructive/40 p-1 text-destructive hover:bg-destructive/10`,children:(0,$.jsx)(wn,{className:`h-3 w-3`})})]},i)),!n&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>t({...e,"":[]}),disabled:``in e,className:`inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[(0,$.jsx)(Ct,{className:`h-3 w-3`}),` `,Z(`engine.studio.rules.addTransition`,r)]})]})}function Gv({rule:e,fields:t,patch:n,disabled:r,locale:i,onBlockingIssuesChange:a}){let o=(e,n,a)=>(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:e}),(0,$.jsxs)(`select`,{value:n??``,disabled:r,onChange:e=>a(e.target.value),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.rules.pickField`,i)}),t.map(e=>(0,$.jsx)(`option`,{value:e.name,children:e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name},e.name))]})]}),s=(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:[Z(`engine.studio.rules.celPre`,i),(0,$.jsx)(`b`,{children:Z(`engine.studio.rules.celTrue`,i)}),Z(`engine.studio.rules.celMid`,i),(0,$.jsx)(`code`,{className:`rounded bg-muted px-1`,children:`false`}),Z(`engine.studio.rules.celPost`,i)]}),(0,$.jsx)(lc,{value:hc(e.condition),onCommit:t=>n({condition:gc(e.condition,t)}),fields:t,disabled:r,onBlockingIssuesChange:a})]});switch(e.type){case`script`:return s;case`cross_field`:{let a=Array.isArray(e.fields)?e.fields:[],o=(e,t)=>n({fields:t?[...new Set([...a,e])]:a.filter(t=>t!==e)});return(0,$.jsxs)($.Fragment,{children:[s,(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.fields`,i)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2 rounded border p-2`,children:[t.length===0&&(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.noFields`,i)}),t.map(e=>(0,$.jsxs)(`label`,{className:`flex items-center gap-1 text-[12px]`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:a.includes(e.name),disabled:r,onChange:t=>o(e.name,t.target.checked)}),e.label&&e.label!==e.name?`${e.label} (${e.name})`:e.name]},e.name))]})]})]})}case`state_machine`:return(0,$.jsxs)($.Fragment,{children:[o(Z(`engine.studio.rules.statusField`,i),e.field,e=>n({field:e})),(0,$.jsx)(Wv,{transitions:e.transitions&&typeof e.transitions==`object`?e.transitions:{},onCommit:e=>n({transitions:e}),disabled:r,locale:i})]});case`format`:return(0,$.jsxs)($.Fragment,{children:[o(Z(`engine.studio.rules.field`,i),e.field,e=>n({field:e})),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.format`,i)}),(0,$.jsx)(`select`,{value:typeof e.format==`string`?e.format:``,disabled:r,onChange:e=>n({format:e.target.value||void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:zv.map(e=>(0,$.jsx)(`option`,{value:e,children:e||Z(`engine.studio.rules.formatNone`,i)},e||`none`))})]}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.regex`,i)}),(0,$.jsx)(`input`,{value:typeof e.regex==`string`?e.regex:``,disabled:r,placeholder:`^[A-Z]{2}\\\\d{4}$`,onChange:e=>n({regex:e.target.value||void 0}),className:`w-full rounded border bg-background px-2 py-1 font-mono text-[12px]`})]})]});case`json_schema`:return(0,$.jsxs)($.Fragment,{children:[o(Z(`engine.studio.rules.field`,i),e.field,e=>n({field:e})),(0,$.jsx)(Uv,{label:Z(`engine.studio.rules.jsonSchema`,i),value:e.schema,onCommit:e=>n({schema:e??{}}),disabled:r,locale:i})]});case`conditional`:return(0,$.jsxs)($.Fragment,{children:[s,(0,$.jsx)(Uv,{label:Z(`engine.studio.rules.then`,i),value:e.then,onCommit:e=>n({then:e}),disabled:r,locale:i}),(0,$.jsx)(Uv,{label:Z(`engine.studio.rules.otherwise`,i),value:e.otherwise,onCommit:e=>n({otherwise:e}),disabled:r,locale:i})]});default:return null}}function Kv({draft:e,onPatch:t,disabled:n,onBlockingIssuesChange:r}){let i=Mc(),a=Q.useMemo(()=>Bv(e.validations),[e.validations]),[o,s]=Q.useState(null),[c,l]=Q.useState(!1),u=a.some(e=>e.name===o)?o:a[0]?.name??null,d=Q.useMemo(()=>ic(e.fields).entries.map(e=>({name:e.name,label:typeof e.def.label==`string`?e.def.label:void 0,hidden:e.def.hidden===!0})),[e.fields]),f=d.find(e=>!e.hidden)?.name??d[0]?.name,[p,m]=Q.useState({}),h=Q.useCallback((e,t)=>{m(n=>n[e]===t?n:{...n,[e]:t})},[]),g=Q.useMemo(()=>new Set(a.map(e=>e.name??``)),[a]),_=Q.useMemo(()=>{let e=0;for(let[t,n]of Object.entries(p))g.has(t)&&(e+=n);return e},[p,g]),v=Q.useRef(r);Q.useEffect(()=>{v.current=r}),Q.useEffect(()=>{v.current?.(_)},[_]);let y=e=>t({validations:e}),b=(e,t)=>y(a.map(n=>n.name===e?{...n,...t}:n)),x=e=>{let t=Vv(a.map(e=>e.name??``));y([...a,Hv(e,t,f)]),s(t)},S=e=>{y(a.filter(t=>t.name!==e)),o===e&&s(null)},C=a.find(e=>e.name===u)??null,w=typeof C?.type==`string`?C.type:`script`,T=(e,t)=>{let n=a.find(t=>t.name===e);if(!n)return;let r=Hv(t,e,f);(t===`script`||t===`cross_field`||t===`conditional`)&&hc(n.condition)&&(r.condition=n.condition);for(let e of[`label`,`description`,`message`,`severity`,`active`,`events`,`priority`])n[e]!==void 0&&(r[e]=n[e]);y(a.map(t=>t.name===e?r:t))};return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(Tr,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.rules.title`,i)}),(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,a.length,`)`]}),!n&&(0,$.jsxs)(rn,{open:c,onOpenChange:l,children:[(0,$.jsx)(kt,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:`ml-auto inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[(0,$.jsx)(Ct,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,i),(0,$.jsx)(zr,{className:`h-3 w-3 text-muted-foreground`})]})}),(0,$.jsxs)(mn,{align:`end`,sideOffset:4,className:`w-56 p-1`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1 pt-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.rules.newType`,i)}),Lv.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>{x(e.value),l(!1)},className:`flex w-full items-center rounded-md px-2 py-1.5 text-left text-[12px] hover:bg-muted`,children:Z(e.labelKey,i)},e.value))]})]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:a.length===0?(0,$.jsxs)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:[Z(`engine.studio.rules.none`,i),(0,$.jsx)(`br`,{}),Z(`engine.studio.rules.explain`,i)]}):a.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>s(e.name??null),className:`flex w-full items-start gap-2 border-b px-3 py-2 text-left text-[12px] `+(u===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate font-medium`,children:e.label||e.name}),(0,$.jsx)(`span`,{className:`block truncate text-[11px] text-muted-foreground`,children:e.message||Z(`engine.studio.rules.noMessage`,i)})]}),(0,$.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] text-primary`,children:e.type??`script`})]},e.name))})]}),(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col rounded-lg border`,children:C?(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-auto p-4`,children:[(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.type`,i)}),(0,$.jsx)(`select`,{value:w,disabled:n,onChange:e=>T(C.name,e.target.value),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:Lv.map(e=>(0,$.jsx)(`option`,{value:e.value,children:Z(e.labelKey,i)},e.value))})]}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.nameLabel`,i)}),(0,$.jsx)(`input`,{value:C.name??``,disabled:n,onChange:e=>{let t=e.target.value;b(C.name,{name:t}),s(t)},className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.label`,i)}),(0,$.jsx)(`input`,{value:C.label??``,disabled:n,onChange:e=>b(C.name,{label:e.target.value||void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.messageLabel`,i)}),(0,$.jsx)(`input`,{value:C.message??``,disabled:n,onChange:e=>b(C.name,{message:e.target.value}),placeholder:Z(`engine.studio.rules.messagePlaceholder`,i),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`})]}),(0,$.jsx)(Gv,{rule:C,fields:d,patch:e=>b(C.name,e),disabled:n,locale:i,onBlockingIssuesChange:e=>h(C.name,e)}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.rules.events`,i)}),(0,$.jsx)(`div`,{className:`flex items-center gap-4`,children:Rv.map(e=>{let t=Array.isArray(C.events)?C.events.includes(e):!1;return(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:t,disabled:n,onChange:t=>{let n=Array.isArray(C.events)?C.events:[],r=t.target.checked?[...new Set([...n,e])]:n.filter(t=>t!==e);b(C.name,{events:r})}}),Z(`engine.studio.rules.event.${e}`,i)]},e)})})]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:Z(`engine.studio.rules.severity`,i)}),(0,$.jsxs)(`select`,{value:C.severity??`error`,disabled:n,onChange:e=>b(C.name,{severity:e.target.value}),className:`rounded border bg-background px-1.5 py-0.5 text-[12px]`,children:[(0,$.jsx)(`option`,{value:`error`,children:Z(`engine.studio.rules.severityError`,i)}),(0,$.jsx)(`option`,{value:`warning`,children:`warning`}),(0,$.jsx)(`option`,{value:`info`,children:`info`})]})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:Z(`engine.studio.rules.priority`,i)}),(0,$.jsx)(`input`,{type:`number`,value:typeof C.priority==`number`?C.priority:``,disabled:n,onChange:e=>b(C.name,{priority:e.target.value===``?void 0:Number(e.target.value)}),className:`w-20 rounded border bg-background px-1.5 py-0.5 text-[12px]`})]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[12px]`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:C.active!==!1,disabled:n,onChange:e=>b(C.name,{active:e.target.checked})}),Z(`engine.studio.rules.enabled`,i)]}),!n&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`rule-delete`,onClick:()=>S(C.name),className:`ml-auto inline-flex items-center gap-1 rounded border border-destructive/40 px-2 py-1 text-[11px] text-destructive hover:bg-destructive/10`,children:[(0,$.jsx)(wn,{className:`h-3 w-3`}),` `,Z(`engine.studio.rules.delete`,i)]})]})]}):(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:Z(`engine.studio.rules.pick`,i)})})]})}function qv({name:e,draft:t,onPatch:n,disabled:r,locale:i,onBlockingIssuesChange:a}){let o=Zc(`object`),s=Q.useMemo(()=>ic(t.fields).entries,[t.fields]),c=s.filter(e=>(e.def.type??`text`)===`select`),l=typeof t.nameField==`string`?t.nameField:``,u=t.stageField,d=Array.isArray(t.highlightFields)?t.highlightFields.filter(e=>typeof e==`string`):[],f=s.filter(e=>e.def.hidden!==!0&&!d.includes(e.name)),p=typeof t.sharingModel==`string`?t.sharingModel:``,m=p===`private`?`engine.studio.settings.sharingDescPrivate`:p===`public_read`?`engine.studio.settings.sharingDescPublicRead`:p===`public_read_write`?`engine.studio.settings.sharingDescPublicReadWrite`:p===`controlled_by_parent`?`engine.studio.settings.sharingDescControlledByParent`:`engine.studio.settings.sharingDescUnset`,h=t.enable&&typeof t.enable==`object`?t.enable:{},g=(e,t)=>n({enable:{...h,[e]:t}}),_=[{key:`trackHistory`,optIn:!0,labelKey:`engine.studio.settings.capTrackHistory`,descKey:`engine.studio.settings.capTrackHistoryDesc`},{key:`files`,optIn:!0,labelKey:`engine.studio.settings.capFiles`,descKey:`engine.studio.settings.capFilesDesc`},{key:`feeds`,optIn:!1,labelKey:`engine.studio.settings.capFeeds`,descKey:`engine.studio.settings.capFeedsDesc`},{key:`activities`,optIn:!1,labelKey:`engine.studio.settings.capActivities`,descKey:`engine.studio.settings.capActivitiesDesc`},{key:`searchable`,optIn:!1,labelKey:`engine.studio.settings.capSearchable`,descKey:`engine.studio.settings.capSearchableDesc`},{key:`clone`,optIn:!1,labelKey:`engine.studio.settings.capClone`,descKey:`engine.studio.settings.capCloneDesc`}],v=typeof t.externalSharingModel==`string`?t.externalSharingModel:``,y=xv(p,v);return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-auto`,children:[(0,$.jsxs)(`section`,{className:`rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(Si,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.basics`,i)})]}),(0,$.jsx)(`div`,{className:`max-w-xl p-3`,children:o?(0,$.jsx)(o,{type:`object`,name:e,draft:t,onPatch:n,readOnly:!!r,locale:i,onBlockingIssuesChange:a}):(0,$.jsx)(`p`,{className:`text-[12px] text-muted-foreground`,children:Z(`engine.studio.settings.noInspector`,i)})})]}),(0,$.jsxs)(`section`,{className:`rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(lt,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.sharing`,i)}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingHint`,i)})]}),(0,$.jsxs)(`div`,{className:`grid max-w-xl gap-2 p-3`,children:[(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingModel`,i)}),(0,$.jsxs)(`select`,{value:p,disabled:r,"data-testid":`owd-internal-select`,onChange:e=>n(e.target.value?{sharingModel:e.target.value}:{sharingModel:void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingUnset`,i)}),(0,$.jsx)(`option`,{value:`private`,children:Z(`engine.studio.settings.sharingPrivate`,i)}),(0,$.jsx)(`option`,{value:`public_read`,children:Z(`engine.studio.settings.sharingPublicRead`,i)}),(0,$.jsx)(`option`,{value:`public_read_write`,children:Z(`engine.studio.settings.sharingPublicReadWrite`,i)}),(0,$.jsx)(`option`,{value:`controlled_by_parent`,children:Z(`engine.studio.settings.sharingControlledByParent`,i)})]})]}),(0,$.jsx)(`p`,{"data-testid":`owd-internal-desc`,className:p===``?`text-[11px] text-amber-600 dark:text-amber-500`:`text-[11px] text-muted-foreground`,children:Z(m,i)}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.sharingExternal`,i)}),(0,$.jsxs)(`select`,{value:v,disabled:r,"data-testid":`owd-external-select`,onChange:e=>n(e.target.value?{externalSharingModel:e.target.value}:{externalSharingModel:void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingExternalUnset`,i)}),(0,$.jsx)(`option`,{value:`private`,children:Z(`engine.studio.settings.sharingPrivate`,i)}),(0,$.jsx)(`option`,{value:`public_read`,children:Z(`engine.studio.settings.sharingPublicRead`,i)}),(0,$.jsx)(`option`,{value:`public_read_write`,children:Z(`engine.studio.settings.sharingPublicReadWrite`,i)}),(0,$.jsx)(`option`,{value:`controlled_by_parent`,children:Z(`engine.studio.settings.sharingControlledByParent`,i)})]})]}),(0,$.jsx)(`p`,{"data-testid":`owd-external-desc`,className:y?`text-[11px] text-amber-600 dark:text-amber-500`:`text-[11px] text-muted-foreground`,children:Z(y?`engine.studio.settings.sharingExternalWider`:`engine.studio.settings.sharingExternalDesc`,i)})]})]}),(0,$.jsxs)(`section`,{className:`rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(Jt,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.semanticRoles`,i)}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.semanticHint`,i)})]}),(0,$.jsxs)(`div`,{className:`grid max-w-xl gap-4 p-3`,children:[(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.nameField`,i)}),(0,$.jsxs)(`select`,{value:l,disabled:r,onChange:e=>n(e.target.value?{nameField:e.target.value}:{nameField:void 0}),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.autoDerive`,i)}),s.map(e=>(0,$.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]})]}),(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.stageField`,i)}),(0,$.jsxs)(`select`,{value:u===!1?`__none__`:u??``,disabled:r,onChange:e=>{let t=e.target.value;n({stageField:t===`__none__`?!1:t===``?void 0:t})},className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.autoDetect`,i)}),(0,$.jsx)(`option`,{value:`__none__`,children:Z(`engine.studio.settings.stageNone`,i)}),c.map(e=>(0,$.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.highlightFields`,i)}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[d.map(e=>(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[11px] text-primary`,children:[e,!r&&(0,$.jsx)(`button`,{type:`button`,"aria-label":Nc(`engine.studio.settings.removeField`,i,{field:e}),onClick:()=>n({highlightFields:d.filter(t=>t!==e)}),className:`rounded-full hover:bg-primary/20`,children:(0,$.jsx)(ci,{className:`h-3 w-3`})})]},e)),!r&&f.length>0&&(0,$.jsxs)(`select`,{value:``,onChange:e=>{e.target.value&&n({highlightFields:[...d,e.target.value]})},className:`rounded border bg-background px-1.5 py-0.5 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.addFieldOption`,i)}),f.map(e=>(0,$.jsx)(`option`,{value:e.name,children:typeof e.def.label==`string`?`${e.def.label} (${e.name})`:e.name},e.name))]}),d.length===0&&(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.undeclared`,i)})]})]})]})]}),(0,$.jsxs)(`section`,{className:`rounded-lg border`,"data-testid":`capabilities-section`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(yt,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.settings.capabilities`,i)}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.settings.capabilitiesHint`,i)})]}),(0,$.jsx)(`div`,{className:`grid max-w-xl gap-3 p-3`,children:_.map(({key:e,optIn:t,labelKey:n,descKey:a})=>{let o=h[e];return(0,$.jsxs)(`label`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:t?o===!0:o!==!1,disabled:r,"data-testid":`cap-${e}`,onChange:t=>g(e,t.target.checked),className:`mt-0.5`}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-[12px]`,children:Z(n,i)}),(0,$.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:Z(a,i)})]})]},e)})})]})]})}function Jv(e){if(!e||typeof e!=`object`)return null;let t=e;if(!(`item`in t))return null;let n=t.item;return!n||typeof n!=`object`?null:Object.keys(n).length>0?n:null}var Yv=[{value:`private`,key:`engine.studio.settings.sharingPrivate`},{value:`public_read`,key:`engine.studio.settings.sharingPublicRead`},{value:`public_read_write`,key:`engine.studio.settings.sharingPublicReadWrite`},{value:`controlled_by_parent`,key:`engine.studio.settings.sharingControlledByParent`}];function Xv(e,t){if(!e)return Z(`engine.studio.settings.sharingUnset`,t);let n=Yv.find(t=>t.value===e);return n?Z(n.key,t):e}function Zv({client:e,packageId:t,publishNonce:n=0,onDraftSaved:r,readOnly:i=!1,locale:a,highlightObject:o,onDirtyChange:s}){let[c,l]=Q.useState([]),[u,d]=Q.useState({}),[f,p]=Q.useState(!1),[m,h]=Q.useState(null),[g,_]=Q.useState(!1),[v,y]=Q.useState(null),b=Q.useCallback(async()=>{p(!1),h(null);try{let[n,r]=await Promise.all([e.list(`object`,{packageId:t}),e.listDrafts({packageId:t,type:`object`}).catch(()=>[])]),i=new Map,a=[],o=new Set;for(let e of n||[]){let t=e.item??e,n=String(t.name??``);!n||o.has(n)||(o.add(n),a.push(n),i.set(n,String(t.label??n)))}for(let e of r||[]){let t=String(e?.name??``);!t||o.has(t)||(o.add(t),a.push(t))}let s=await Promise.all(a.map(async t=>{let[n,r]=await Promise.all([e.layered(`object`,t).catch(()=>null),e.getDraft(`object`,t).catch(()=>null)]),a=n??{},o=a.effective??a.code??{},s=Jv(r),c=s?{...o,...s}:o,l=typeof c.sharingModel==`string`?c.sharingModel:``;return{name:t,label:String(c.label??i.get(t)??t),internal:l,external:typeof c.externalSharingModel==`string`?c.externalSharingModel:``,master:l===`controlled_by_parent`?Sv(c.fields):void 0,hasDraft:!!s}}));s.sort((e,t)=>e.label.localeCompare(t.label)||e.name.localeCompare(t.name)),l(s),d(Object.fromEntries(s.map(e=>[e.name,{internal:e.internal,external:e.external}])))}catch(e){h(Ru(e))}finally{p(!0)}},[e,t]);Q.useEffect(()=>{b()},[b,n]);let x=Q.useRef({});Q.useEffect(()=>{if(!o||!f)return;let e=x.current[o];e&&e.scrollIntoView({block:`center`,behavior:`smooth`})},[o,f]);let S=Q.useCallback((e,t)=>{d(n=>({...n,[e]:{...n[e],...t}}))},[]),C=Q.useMemo(()=>c.map(e=>{let t=u[e.name]??{internal:e.internal,external:e.external};return{row:e,edit:t,dirty:t.internal!==e.internal||t.external!==e.external,invalid:xv(t.internal,t.external)}}),[c,u]),w=C.filter(e=>e.dirty).length,T=C.some(e=>e.invalid),E=w>0,D=Q.useRef(s);Q.useEffect(()=>{D.current=s}),Q.useEffect(()=>{D.current?.(E)},[E]),Q.useEffect(()=>()=>{D.current?.(!1)},[]);let O=Q.useCallback(async()=>{let n=C.filter(e=>e.dirty&&!e.invalid);if(n.length!==0){_(!0),y(null);try{for(let r of n){let[n,i]=await Promise.all([e.layered(`object`,r.row.name).catch(()=>null),e.getDraft(`object`,r.row.name).catch(()=>null)]),a=n??{},o=a.effective??a.code??{},s=Jv(i),c={...o,...s??{}};r.edit.internal?c.sharingModel=r.edit.internal:delete c.sharingModel,r.edit.external?c.externalSharingModel=r.edit.external:delete c.externalSharingModel,await e.save(`object`,r.row.name,c,{mode:`draft`,packageId:t})}X.success(Nc(`engine.studio.owd.saved`,a,{count:n.length})),r?.(),await b()}catch(e){y(Ru(e))}finally{_(!1)}}},[C,e,t,r,b,a]),k=!i&&!g&&w>0&&!T;return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,"data-testid":`owd-overview`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-4 py-2.5`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(lt,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate text-[15px] font-semibold leading-none text-foreground`,children:Z(`engine.studio.owd.title`,a)}),(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-muted px-1.5 py-0.5 text-[11px] text-muted-foreground`,children:Z(`engine.studio.owd.subtitle`,a)})]}),i?(0,$.jsxs)(`span`,{title:Z(`engine.studio.pkg.readonlyHint`,a),className:`ml-auto flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(cr,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,a)]}):(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void O(),disabled:!k,"data-testid":`owd-save`,className:`ml-auto inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[g?(0,$.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(Ti,{className:`h-3.5 w-3.5`}),w>0?Nc(`engine.studio.owd.save`,a,{count:w}):Z(`engine.studio.owd.saveNone`,a)]})]}),(0,$.jsx)(`p`,{className:`border-b px-4 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.owd.description`,a)}),T&&(0,$.jsxs)(`p`,{"data-testid":`owd-invalid-banner`,className:`flex items-center gap-1.5 border-b bg-amber-400/10 px-4 py-2 text-[11px] text-amber-600 dark:text-amber-400`,children:[(0,$.jsx)(Ji,{className:`h-3.5 w-3.5 shrink-0`}),Z(`engine.studio.owd.blockedSave`,a)]}),v&&(0,$.jsx)(`p`,{className:`border-b bg-destructive/10 px-4 py-2 text-[11px] text-destructive`,children:v}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-4`,children:f?m?(0,$.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.owd.loadFailed`,a)}):c.length===0?(0,$.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.owd.none`,a)}):(0,$.jsxs)(`table`,{className:`w-full border-collapse text-[12px]`,children:[(0,$.jsx)(`thead`,{children:(0,$.jsxs)(`tr`,{className:`border-b text-left text-[11px] uppercase tracking-wide text-muted-foreground`,children:[(0,$.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colObject`,a)}),(0,$.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colInternal`,a)}),(0,$.jsx)(`th`,{className:`px-2 py-1.5 font-medium`,children:Z(`engine.studio.owd.colExternal`,a)})]})}),(0,$.jsx)(`tbody`,{children:C.map(({row:e,edit:t,dirty:n,invalid:r})=>{let s=t.internal===`controlled_by_parent`;return(0,$.jsxs)(`tr`,{ref:t=>{x.current[e.name]=t},"data-testid":`owd-row-${e.name}`,className:`border-b align-top `+(o===e.name?`bg-primary/5`:``),children:[(0,$.jsx)(`td`,{className:`px-2 py-2`,children:(0,$.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:e.label}),n&&(0,$.jsx)(`span`,{"data-testid":`owd-dirty-${e.name}`,className:`rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.owd.unsaved`,a)}),e.hasDraft&&!n&&(0,$.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] text-muted-foreground`,children:Z(`engine.studio.unpublishedDraft`,a)})]}),(0,$.jsx)(`span`,{className:`font-mono text-[10px] text-muted-foreground`,children:e.name})]})}),(0,$.jsx)(`td`,{className:`px-2 py-2`,children:i?(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:Xv(t.internal,a)}):(0,$.jsxs)(`select`,{value:t.internal,"data-testid":`owd-internal-${e.name}`,onChange:t=>S(e.name,{internal:t.target.value}),className:`w-full min-w-[13rem] rounded border bg-background px-2 py-1 text-[12px]`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingUnset`,a)}),Yv.map(e=>(0,$.jsx)(`option`,{value:e.value,children:Z(e.key,a)},e.value))]})}),(0,$.jsx)(`td`,{className:`px-2 py-2`,children:s?(0,$.jsxs)(`span`,{"data-testid":`owd-master-${e.name}`,title:Z(`engine.studio.owd.masterTip`,a),className:`inline-flex items-center gap-1 text-muted-foreground`,children:[(0,$.jsx)(Gt,{className:`h-3.5 w-3.5`}),e.master?Nc(`engine.studio.owd.byParent`,a,{master:e.master}):Z(`engine.studio.owd.byParentUnknown`,a)]}):i?(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:Xv(t.external,a)}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`select`,{value:t.external,"data-testid":`owd-external-${e.name}`,onChange:t=>S(e.name,{external:t.target.value}),className:`w-full min-w-[13rem] rounded border bg-background px-2 py-1 text-[12px] `+(r?`border-amber-500`:``),children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.settings.sharingExternalUnset`,a)}),Yv.filter(e=>e.value!==`controlled_by_parent`).map(e=>(0,$.jsx)(`option`,{value:e.value,children:Z(e.key,a)},e.value))]}),r&&(0,$.jsx)(`span`,{"data-testid":`owd-error-${e.name}`,className:`mt-1 block text-[11px] text-amber-600 dark:text-amber-500`,children:Z(`engine.studio.owd.widerError`,a)})]})})]},e.name)})})]}):(0,$.jsx)(`p`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.loading`,a)})})]})}var Qv={GET:`bg-emerald-500/15 text-emerald-600 dark:text-emerald-300`,POST:`bg-sky-500/15 text-sky-600 dark:text-sky-300`,PATCH:`bg-amber-500/15 text-amber-600 dark:text-amber-300`,DELETE:`bg-destructive/15 text-destructive`};function $v(e){switch(e){case`number`:case`currency`:case`percent`:return 0;case`boolean`:return!0;case`date`:return`2024-01-01`;case`datetime`:return`2024-01-01T00:00:00Z`;case`lookup`:case`master_detail`:return`related_record_id`;default:return`string`}}function ey(e){let t=ic(e).entries,n=new Set([`autonumber`,`formula`,`summary`]),r={};for(let e of t){let t=e.def;if(!n.has(String(t.type))&&t.readonly!==!0&&t.hidden!==!0&&(r[e.name]=$v(t.type),Object.keys(r).length>=8))break}return r}function ty({name:e,draft:t}){let n=Mc(),[r,i]=Q.useState(null),a=typeof window<`u`?window.location.origin:`https://your-host`,o=`/api/v1/data/${e}`,s=Q.useMemo(()=>ey(t.fields),[t.fields]),c=JSON.stringify(s,null,2),l=[{id:`list`,method:`GET`,path:o,desc:Z(`engine.studio.api.list`,n)},{id:`create`,method:`POST`,path:o,desc:Z(`engine.studio.api.create`,n),body:!0},{id:`get`,method:`GET`,path:`${o}/{id}`,desc:Z(`engine.studio.api.get`,n)},{id:`update`,method:`PATCH`,path:`${o}/{id}`,desc:Z(`engine.studio.api.update`,n),body:!0},{id:`delete`,method:`DELETE`,path:`${o}/{id}`,desc:Z(`engine.studio.api.delete`,n)}],u=e=>{let t=[`curl -X ${e.method} '${a}${e.path}'`,` -H 'Authorization: Bearer <token>'`];return e.body&&(t.push(` -H 'Content-Type: application/json'`),t.push(` -d '${JSON.stringify(s)}'`)),t.join(` \\
|
|
10
|
+
`)},d=(e,t)=>{navigator.clipboard?.writeText(t).then(()=>{i(e),setTimeout(()=>i(t=>t===e?null:t),1500)})};return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-auto`,children:[(0,$.jsx)(`p`,{className:`text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.api.subtitle`,n)}),(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:l.map(e=>(0,$.jsx)(`div`,{className:`rounded-lg border`,children:(0,$.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2`,children:[(0,$.jsx)(`span`,{className:`shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold `+Qv[e.method],children:e.method}),(0,$.jsx)(`code`,{className:`min-w-0 flex-1 truncate text-[12px]`,children:e.path}),(0,$.jsx)(`span`,{className:`hidden shrink-0 text-[11px] text-muted-foreground sm:inline`,children:e.desc}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(e.id,u(e)),title:Z(`engine.studio.api.copyCurl`,n),className:`inline-flex shrink-0 items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[r===e.id?(0,$.jsx)(Pr,{className:`h-3 w-3 text-emerald-500`}):(0,$.jsx)(jt,{className:`h-3 w-3`}),r===e.id?Z(`engine.studio.api.copied`,n):`cURL`]})]})},e.id))}),Object.keys(s).length>0&&(0,$.jsxs)(`div`,{className:`rounded-lg border`,children:[(0,$.jsx)(`header`,{className:`border-b px-3 py-1.5 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.api.body`,n)}),(0,$.jsx)(`pre`,{className:`overflow-auto px-3 py-2 text-[11px] leading-5`,children:c})]})]})}function ny(e){if(!e||typeof e!=`object`||!(`item`in e))return null;let t=e.item;return t&&typeof t==`object`&&Object.keys(t).length>0?t:null}function ry(e,t){let n=e.object;return n===`*`?!0:typeof n==`string`?n===t:Array.isArray(n)?n.includes(t)||n.includes(`*`):!1}function iy(e,t){let n=(e||`hook`).replace(/[^a-z0-9_]/gi,`_`).toLowerCase(),r=new Set(t),i=t.length+1,a=`${n}_hook_${i}`;for(;r.has(a);)a=`${n}_hook_${++i}`;return a}function ay({objectName:e,packageId:t,disabled:n,hookSchema:r}){let i=Mc(),a=oa(),o=Zc(`hook`),[s,c]=Q.useState([]),[l,u]=Q.useState(!0),[d,f]=Q.useState(null),[p,m]=Q.useState(null),[h,g]=Q.useState(null),[_,v]=Q.useState(!1),[y,b]=Q.useState(!1),[x,S]=Q.useState(0),[C,w]=Q.useState({hook:``,count:0}),T=String(h?.name??``),E=Q.useCallback(e=>{w(t=>t.hook===T&&t.count===e?t:{hook:T,count:e})},[T]),D=C.hook===T?C.count:0;Q.useEffect(()=>{let n=!1;return u(!0),f(null),(async()=>{try{let[r,i]=await Promise.all([a.list(`hook`,{packageId:t}),a.listDrafts({packageId:t,type:`hook`}).catch(()=>[])]),o=(i||[]).map(e=>String(e.name??``)).filter(Boolean),s=await Promise.all(o.map(e=>a.getDraft(`hook`,e).then(ny).catch(()=>null)));if(n)return;let l=new Map;for(let t of r||[])t?.name&&ry(t,e)&&l.set(String(t.name),t);o.forEach((t,n)=>{let r=s[n];r&&ry(r,e)&&l.set(t,r)}),c([...l.values()])}catch(e){n||f(Ru(e))}finally{n||u(!1)}})(),()=>{n=!0}},[a,t,e,x]),Q.useEffect(()=>{let e=s.find(e=>e.name===p)??null;g(e?{...e}:null),v(!1)},[p,s]);let O=Q.useCallback(async()=>{if(h?.name){b(!0),f(null);try{await a.save(`hook`,String(h.name),h,{mode:`draft`,packageId:t}),X.success(Nc(`engine.studio.hooks.saved`,i,{label:String(h.label||h.name)})),v(!1),S(e=>e+1)}catch(e){f(Ru(e))}finally{b(!1)}}},[a,h,t,i]),k=Q.useCallback(async()=>{let n=iy(e,s.map(e=>String(e.name??``))),r={name:n,label:Z(`engine.studio.hooks.newLabel`,i),object:e,events:[`beforeInsert`],body:{language:`js`,source:`return;`},priority:100,async:!1};b(!0),f(null);try{await a.save(`hook`,n,r,{mode:`draft`,packageId:t}),S(e=>e+1),m(n)}catch(e){f(Ru(e))}finally{b(!1)}},[a,e,s,t,i]);return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(fi,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.data.tab.hooks`,i)}),(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,s.length,`)`]}),!n&&(0,$.jsxs)(`button`,{type:`button`,onClick:k,disabled:y,className:`ml-auto inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[(0,$.jsx)(Ct,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,i)]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:l?(0,$.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,i)}):s.length===0?(0,$.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.hooks.none`,i)}):s.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>m(e.name??null),className:`flex w-full items-center gap-2 border-b px-3 py-2 text-left text-[12px] `+(p===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,$.jsx)(fi,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.label||e.name}),e.async&&(0,$.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] text-primary`,children:Z(`engine.studio.hooks.async`,i)})]},String(e.name)))})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden rounded-lg border`,children:[d&&(0,$.jsx)(`div`,{className:`border-b border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive whitespace-pre-line`,children:d}),h?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 border-b px-3 py-1.5`,children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[12px] font-medium`,children:String(h.label||h.name)}),!n&&(0,$.jsxs)(`button`,{type:`button`,onClick:O,disabled:!_||y||D>0,title:D>0?Z(`perm.cel.saveBlocked`,i):void 0,className:`inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-[11px] hover:bg-muted disabled:opacity-50`,children:[y?(0,$.jsx)(Y,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(Ti,{className:`h-3 w-3`}),Z(`engine.studio.hooks.save`,i)]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:o?(0,$.jsx)(o,{type:`hook`,name:String(h.name??``),draft:h,onPatch:e=>{g(t=>({...t,...e})),v(!0)},readOnly:!!n,locale:i,serverSchema:r,onBlockingIssuesChange:E}):(0,$.jsx)(`div`,{className:`p-3`,children:(0,$.jsx)(vc,{schema:r,value:h,onChange:e=>{g(e),v(!0)},readOnly:!!n})})})]}):(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:Z(`engine.studio.hooks.pick`,i)})]})]})}function oy(e){return Array.isArray(e)?e.filter(e=>!!e&&typeof e==`object`):[]}function sy(e,t){let n=(e||`action`).replace(/[^a-z0-9_]/gi,`_`).toLowerCase(),r=new Set(t),i=t.length+1,a=`${n}_action_${i}`;for(;r.has(a);)a=`${n}_action_${++i}`;return a}function cy(e,t){if(typeof e==`string`)return e;if(e&&typeof e==`object`){let t=e;for(let e of[`default`,`en-US`,`en`,`zh-CN`])if(typeof t[e]==`string`)return t[e];let n=Object.values(t).find(e=>typeof e==`string`);if(typeof n==`string`)return n}return t}function ly({draft:e,onPatch:t,disabled:n,actionSchema:r,onBlockingIssuesChange:i}){let a=Mc(),o=Q.useMemo(()=>oy(e.actions),[e.actions]),[s,c]=Q.useState(null),l=o.some(e=>e.name===s)?s:o[0]?.name??null,u=o.find(e=>e.name===l)??null,d=Zc(`action`),f=Q.useCallback(e=>{u&&(t({actions:o.map(t=>t.name===u.name?{...t,...e}:t)}),typeof e.name==`string`&&e.name!==u.name&&c(e.name))},[o,u,t]),p=typeof e.name==`string`?e.name:``,[m,h]=Q.useState({}),g=Q.useCallback((e,t)=>{h(n=>n[e]===t?n:{...n,[e]:t})},[]),_=Q.useMemo(()=>new Set(o.map(e=>String(e.name??``))),[o]),v=Q.useMemo(()=>{let e=0;for(let[t,n]of Object.entries(m))_.has(t)&&(e+=n);return e},[m,_]),y=Q.useRef(i);Q.useEffect(()=>{y.current=i}),Q.useEffect(()=>{y.current?.(v)},[v]);let b=Q.useCallback(()=>{let e=sy(p,o.map(e=>String(e.name??``))),n={name:e,label:Z(`engine.studio.actions.newLabel`,a),type:`script`,objectName:p,locations:[`record_header`],body:{language:`js`,source:`return { ok: true };`}};t({actions:[...o,n]}),c(e)},[o,p,t,a]),x=Q.useCallback(e=>{t({actions:o.filter(t=>t.name!==e)}),c(null)},[o,t]);return(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex w-72 shrink-0 flex-col rounded-lg border`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-2 border-b px-3 py-2`,children:[(0,$.jsx)(Er,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.data.tab.actions`,a)}),(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`(`,o.length,`)`]}),!n&&(0,$.jsxs)(`button`,{type:`button`,onClick:b,className:`ml-auto inline-flex items-center gap-1 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[(0,$.jsx)(Ct,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,a)]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:o.length===0?(0,$.jsx)(`p`,{className:`px-3 py-6 text-center text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.actions.none`,a)}):o.map(e=>{let t=qs(typeof e.icon==`string`?e.icon:void 0),n=typeof e.type==`string`?e.type:``;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>c(e.name??null),className:`flex w-full items-center gap-2 border-b px-3 py-2 text-left text-[12px] `+(l===e.name?`bg-muted`:`hover:bg-muted/50`),children:[(0,$.jsx)(t,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:cy(e.label,String(e.name??``))}),n&&(0,$.jsx)(`span`,{className:`shrink-0 rounded-full bg-muted px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-muted-foreground`,children:n})]},String(e.name))})})]}),(0,$.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col overflow-auto rounded-lg border`,children:u?d?(0,$.jsxs)($.Fragment,{children:[!n&&(0,$.jsx)(`div`,{className:`flex shrink-0 items-center justify-end border-b px-2 py-1`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>x(u.name),className:`inline-flex items-center gap-1 rounded border border-destructive/40 px-2 py-0.5 text-[11px] text-destructive hover:bg-destructive/10`,children:[(0,$.jsx)(wn,{className:`h-3 w-3`}),` `,Z(`engine.studio.actions.delete`,a)]})}),(0,$.jsx)(d,{type:`action`,name:String(u.name??``),draft:u,onPatch:f,readOnly:!!n,locale:a,serverSchema:r,onBlockingIssuesChange:e=>g(String(u.name??``),e)})]}):(0,$.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-2 p-6 text-center text-[12px] text-muted-foreground`,children:[(0,$.jsx)(Ft,{className:`h-5 w-5`}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:cy(u.label,String(u.name??``))}),(0,$.jsx)(`span`,{children:Z(`engine.studio.actions.editorMissing`,a)})]}):(0,$.jsx)(`div`,{className:`flex flex-1 items-center justify-center p-6 text-center text-[12px] text-muted-foreground`,children:Z(`engine.studio.actions.pick`,a)})})]})}var uy={private:`engine.studio.settings.sharingPrivate`,public_read:`engine.studio.settings.sharingPublicRead`,public_read_write:`engine.studio.settings.sharingPublicReadWrite`},dy={private:`engine.studio.settings.sharingDescPrivate`,public_read:`engine.studio.settings.sharingDescPublicRead`,public_read_write:`engine.studio.settings.sharingDescPublicReadWrite`},fy=[{key:`data`,label:`Data`,Icon:tn},{key:`automations`,label:`Automations`,Icon:Kr},{key:`interfaces`,label:`Interfaces`,Icon:cn}];function py(e){let{dirty:t,blocked:n,snapshot:r,save:i}=e,a=Q.useMemo(()=>{try{return JSON.stringify(r??null)}catch{return`"__unserializable__"`}},[r]),o=Q.useRef(null),s=Q.useRef(i);Q.useEffect(()=>{s.current=i}),Q.useEffect(()=>{if(!t||n||o.current===a)return;let e=setTimeout(()=>{o.current=a,s.current()},1500);return()=>clearTimeout(e)},[t,n,a])}var my=[{key:`access`,label:`Access`,Icon:Qn}],hy={object:`data`,flow:`automations`,permission:`access`},gy={group:Ni,page:Li,object:tn,dashboard:cn,report:kn,view:nn,action:Or},_y=e=>gy[e??``]??Ht;function vy(e){if(!e||typeof e!=`object`)return null;let t=e;if(!(`item`in t))return null;let n=t.item;return!n||typeof n!=`object`?null:Object.keys(n).length>0?n:null}function yy({packageId:e,tab:t,beforeNavigate:n}){let r=p(),i=Mc(),[a,o]=Q.useState(!1),[s,c]=Q.useState(null),[l,u]=Q.useState(!1),[d,f]=Q.useState(null),[m,h]=Q.useState(!1),[g,_]=Q.useState(!1);Q.useEffect(()=>{let e=!1,t=()=>{Wc().then(t=>{e||c(t)}).catch(()=>{})};return t(),window.addEventListener(`objectui:packages-changed`,t),()=>{e=!0,window.removeEventListener(`objectui:packages-changed`,t)}},[e]);let v=s?.find(t=>t.id===e)??null,y=Q.useCallback(async e=>{let t=await(await fetch(`/api/v1/packages`,{credentials:`include`,headers:{Accept:`application/json`},cache:`no-store`})).json(),n=t?.data??t;return(Array.isArray(n)?n:n?.packages??[]).find(t=>(t?.manifest?.id??t?.id)===e)??null},[]),b=Q.useCallback(async e=>{o(!1),_(!0);try{f(await y(e)),h(!0)}catch(e){X.error(Ru(e))}finally{_(!1)}},[y]),x=Q.useCallback(async()=>{let n=[];try{n=await Wc(),c(n)}catch{}let i=d?.manifest.id;if(i){if(!n.some(e=>e.id===i)){if(i===e){let e=n[0];r(e?`/studio/${encodeURIComponent(e.id)}/${t}`:`/home`)}return}try{let e=await y(i);e&&f(e)}catch{}}},[d,e,t,r,y]);return(0,$.jsxs)(rn,{open:a,onOpenChange:o,children:[(0,$.jsx)(kt,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,className:`flex items-center gap-1.5 whitespace-nowrap rounded-md px-1.5 py-0.5 text-[13px] font-medium hover:bg-muted`,title:Z(`engine.studio.pkg.switchTitle`,i),children:[(0,$.jsx)(fn,{className:`h-4 w-4`}),` `,v?.name??e,v&&!v.writable&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] font-normal text-amber-600 dark:text-amber-300`,children:[(0,$.jsx)(cr,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,i)]}),(0,$.jsx)(zr,{className:`h-3.5 w-3.5 text-muted-foreground`})]})}),(0,$.jsxs)(mn,{align:`start`,sideOffset:6,className:`w-80 rounded-lg p-1.5`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1 pt-0.5 text-[10px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.pkg.heading`,i)}),(0,$.jsxs)(`div`,{className:`max-h-64 overflow-auto`,children:[s===null&&(0,$.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,i)}),s?.length===0&&(0,$.jsx)(`p`,{className:`px-2 py-2 text-[11px] text-muted-foreground`,children:Z(`engine.studio.pkg.none`,i)}),s?.map(a=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{o(!1),a.id!==e&&(n&&!n()||r(`/studio/${encodeURIComponent(a.id)}/${t}`))},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(a.id===e?`bg-muted font-medium`:`hover:bg-muted/60`),children:[(0,$.jsx)(fn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate`,children:a.name}),(0,$.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:a.id})]}),a.writable?(0,$.jsx)(`span`,{className:`rounded bg-emerald-400/15 px-1.5 py-0.5 text-[10px] text-emerald-600 dark:text-emerald-300`,children:Z(`engine.studio.pkg.writable`,i)}):(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:[(0,$.jsx)(cr,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,i)]})]},a.id))]}),(0,$.jsxs)(`div`,{className:`mt-1 space-y-0.5 border-t pt-1.5`,children:[v&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void b(e),disabled:g,className:`flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground disabled:opacity-50`,children:[g?(0,$.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(si,{className:`h-3.5 w-3.5`}),Z(`engine.studio.pkg.manage`,i)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{o(!1),u(!0)},className:`flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,$.jsx)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.pkg.new`,i)]})]})]}),(0,$.jsx)(Qc,{open:l,onOpenChange:u,onCreated:e=>{n&&!n()||r(`/studio/${encodeURIComponent(e)}/data`)}}),(0,$.jsx)(Uc,{pkg:d,open:m,onOpenChange:h,onChanged:x})]})}function by({aiSlot:e}){let t=c(),r=t.packageId??`com.example.showcase`,i=t.tab??`interfaces`,a=Mc(),[o,s]=Q.useState(null);Q.useEffect(()=>{let e=!1;return s(null),Wc().then(t=>{e||s(t.find(e=>e.id===r)?.writable??null)}).catch(()=>{}),()=>{e=!0}},[r]);let l=o===!1,[u,d]=Q.useState(!1),f=Q.useCallback(()=>!u||window.confirm(Z(`engine.edit.unsavedLeaveConfirm`,a)),[u,a]);Q.useEffect(()=>{if(!u)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[u]);let[m,h]=Q.useState(!1),[g,_]=Q.useState(!1),[v,y]=Q.useState(0),[b,x]=Q.useState(0),{count:S,refresh:C}=Xu({packageId:r});Q.useEffect(()=>{C()},[C,v,b]);let w=Q.useCallback(async()=>{_(!0);try{let e=await fetch(`/api/v1/packages/${encodeURIComponent(r)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),t=await e.json().catch(()=>null);if(!e.ok||t?.success===!1)throw Object.assign(Error(t?.error?.message||`HTTP ${e.status}`),{issues:t?.error?.details?.issues});let n=t?.data?.failed??[];n.length>0?X.error(Bu(n)):(X.success(Z(`engine.studio.publishedAll`,a)),h(!1)),y(e=>e+1),ba()}catch(e){X.error(Ru(e))}finally{_(!1)}await C()},[r,C]),T=Q.useCallback(()=>x(e=>e+1),[]),E=(S??0)>0,D=p(),O=oa(),[k,A]=Q.useState(null),[j,M]=Q.useState(!1),[ee,N]=Q.useState(!1),[te,P]=Q.useState(null),[F,ne]=Q.useState(null),[re,I]=Q.useState(!0),ie=Q.useCallback(async()=>{let[e,t]=await Promise.all([O.list(`object`,{packageId:r}),O.listDrafts({packageId:r,type:`object`}).catch(()=>[])]),n=(e||[]).map(e=>({name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name),i=new Set(n.map(e=>e.name));for(let e of t)e.name&&!i.has(e.name)&&n.push({name:e.name,label:e.name});return n},[O,r]),L=Q.useCallback(async(e,t)=>{N(!0),P(null);try{let n=re?await ie().catch(()=>[]):[];await O.save(`app`,t,vv(t,e,n),{mode:`draft`,packageId:r}),X.success(Nc(`engine.studio.app.savedDraft`,a,{label:e})),ne(e),M(!1),x(e=>e+1)}catch(e){P(Ru(e))}finally{N(!1)}},[re,ie,O,r,a]),ae=Q.useCallback(async()=>{try{let e=(await O.list(`app`,{packageId:r})||[]).map(e=>({name:String(e.name??``),label:String(e.label??e.name??``)})).filter(e=>e.name)[0];if(!e){let t=(await O.listDrafts?.({packageId:r,type:`app`}))?.[0];t?.name&&(e={name:String(t.name),label:String(t.label??t.name)})}A(e??null)}catch{A(null)}},[O,r]);Q.useEffect(()=>(ae(),va(()=>{ae()})),[ae,v,b]);let oe=!e,R=Q.useCallback(e=>{let t=hy[e.type];if(t&&t!==i){if(!f())return!1;D(`/studio/${r}/${t}?${ec}=${encodeURIComponent(Ys(e))}`)}h(!1)},[i,r,f,D]);return(0,$.jsx)(gm,{onRequest:R,children:(0,$.jsxs)(`div`,{className:`flex h-screen w-full overflow-hidden bg-background text-foreground`,children:[e?(0,$.jsx)(`aside`,{className:`w-64 shrink-0 overflow-auto border-r bg-muted/40`,children:e}):null,(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,$.jsxs)(`header`,{className:`flex items-center gap-3 overflow-x-auto border-b px-3 py-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>{f()&&D(`/home`)},title:Z(`engine.studio.home`,a),className:`shrink-0 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,children:(0,$.jsx)(gt,{className:`h-4 w-4`})}),(0,$.jsx)(`div`,{className:`shrink-0`,children:(0,$.jsx)(yy,{packageId:r,tab:i,beforeNavigate:f})}),(0,$.jsx)(`span`,{className:`shrink-0 text-muted-foreground`,children:`·`}),(0,$.jsxs)(`nav`,{className:`flex shrink-0 gap-1`,children:[fy.map(e=>(0,$.jsxs)(n,{to:`/studio/${r}/${e.key}`,onClick:t=>{i!==e.key&&(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||t.button!==0||f()||t.preventDefault())},className:`inline-flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-colors `+(i===e.key?`bg-primary/10 font-medium text-primary`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:[(0,$.jsx)(e.Icon,{className:`h-3.5 w-3.5`}),Z(`engine.studio.pillar.${e.key}`,a)]},e.key)),(0,$.jsxs)(rn,{children:[(0,$.jsx)(kt,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,"data-testid":`studio-nav-more`,className:`inline-flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs transition-colors `+(my.some(e=>i===e.key)?`bg-primary/10 font-medium text-primary`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:[my.some(e=>i===e.key)?Z(`engine.studio.pillar.${i}`,a):Z(`engine.studio.more`,a),(0,$.jsx)(zr,{className:`h-3 w-3`})]})}),(0,$.jsx)(mn,{align:`start`,className:`w-44 p-1`,children:my.map(e=>(0,$.jsxs)(n,{to:`/studio/${r}/${e.key}`,onClick:t=>{i!==e.key&&(t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||t.button!==0||f()||t.preventDefault())},className:`flex items-center gap-2 rounded-md px-2.5 py-1.5 text-xs transition-colors `+(i===e.key?`bg-primary/10 font-medium text-primary`:`text-muted-foreground hover:bg-muted hover:text-foreground`),children:[(0,$.jsx)(e.Icon,{className:`h-3.5 w-3.5`}),Z(`engine.studio.pillar.${e.key}`,a)]},e.key))})]})]}),(0,$.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[k?null:F?(0,$.jsx)(`span`,{title:Z(`engine.studio.app.willOpenAfterPublish`,a),className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Nc(`engine.studio.app.pending`,a,{label:F})}):(0,$.jsxs)(`button`,{type:`button`,onClick:()=>M(!0),disabled:l,title:Z(l?`engine.studio.pkg.readonlyHint`:`engine.studio.app.noneTitle`,a),className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground disabled:pointer-events-none disabled:opacity-50`,children:[(0,$.jsx)(Ct,{className:`h-3.5 w-3.5`}),Z(`engine.studio.app.create`,a)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>h(!0),className:`inline-flex items-center gap-1.5 rounded-md border px-2.5 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,$.jsx)(rr,{className:`h-3.5 w-3.5`}),Z(`engine.studio.changes`,a),E?` · ${S}`:``]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>h(!0),disabled:g||!E||l,title:Z(l?`engine.studio.pkg.readonlyHint`:E?`engine.studio.publishTitle`:`engine.studio.publishNoneTitle`,a),className:`inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1 text-xs font-medium text-primary-foreground disabled:opacity-50`,children:[g?(0,$.jsx)(Y,{className:`h-3.5 w-3.5 animate-spin`}):(0,$.jsx)(ri,{className:`h-3.5 w-3.5`}),Z(`engine.studio.publish`,a)]})]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1`,children:i===`data`?(0,$.jsx)(Dy,{packageId:r,publishNonce:v,onDraftSaved:T,readOnly:l}):i===`automations`?(0,$.jsx)(ky,{packageId:r,publishNonce:v,onDraftSaved:T,readOnly:l}):i===`access`?(0,$.jsx)(Ay,{packageId:r,publishNonce:v,onDraftSaved:T,readOnly:l,onDirtyChange:d}):(0,$.jsx)(Cy,{packageId:r,publishNonce:v,draftNonce:b,onDraftSaved:T,onCreateApp:l?void 0:()=>M(!0),readOnly:l,foldInspector:oe,onDirtyChange:d})})]}),oe&&(0,$.jsx)(ev,{packageId:r,locale:a}),(0,$.jsx)(Om,{open:m,onOpenChange:h,packageId:r,onPublish:l?void 0:w,publishing:g}),(0,$.jsx)(Tv,{open:j,onOpenChange:M,title:Z(`engine.studio.app.create`,a),labelFieldLabel:Z(`engine.studio.app.nameLabel`,a),labelPlaceholder:Z(`engine.studio.app.namePlaceholder`,a),idFieldLabel:Z(`engine.studio.app.idLabel`,a),idPlaceholder:Z(`engine.studio.app.idPlaceholder`,a),submitLabel:Z(`engine.studio.createDraft`,a),submittingLabel:Z(`engine.studio.creating`,a),busy:ee,error:te,locale:a,onSubmit:({label:e,name:t})=>void L(e,t),extra:(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-muted-foreground`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:re,onChange:e=>I(e.target.checked),className:`h-3.5 w-3.5 accent-primary`}),Z(`engine.studio.app.scaffoldNav`,a)]})})]})})}function xy({nodes:e,active:t,onPick:n,objectIcons:r}){let i=Mc();return(0,$.jsx)($.Fragment,{children:e.map((e,a)=>{if(e.type===`group`||Array.isArray(e.children)&&e.children.length)return(0,$.jsxs)(`div`,{className:`mb-1`,children:[(0,$.jsxs)(`p`,{className:`flex items-center gap-1 px-2 pb-1 pt-3 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(Ni,{className:`h-3 w-3`}),` `,e.label]}),(0,$.jsx)(`div`,{className:`pl-1.5`,children:(0,$.jsx)(xy,{nodes:e.children??[],active:t,onPick:n,objectIcons:r})})]},e.id??a);let o=fv(e),s=o?.type===`object`?r?.[o.name]:void 0,c=e.icon?qs(e.icon):s?qs(s):_y(e.type),l=!!o&&t?.type===o.type&&t?.name===o.name;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o&&n(o),disabled:!o,title:o?`${o.type} · ${o.name}`:e.label,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs disabled:opacity-40 `+(l?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,$.jsx)(c,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.label||o?.name}),o&&o.type!==`page`&&(0,$.jsx)(`span`,{className:`text-[9px] tracking-wide text-muted-foreground/60`,children:Pc(o.type,i)})]},e.id??a)})})}function Sy({navId:e,appDraft:t,objects:n,onNavPatch:r,onClear:i}){let a=Mc(),o=Q.useMemo(()=>{let t=/^navigation\[(\d+)\]$/.exec(e);return t?Number(t[1]):-1},[e]),s=Q.useMemo(()=>Array.isArray(t.navigation)?t.navigation:[],[t]),c=o>=0?s[o]:null;if(!c)return(0,$.jsx)(`div`,{className:`px-2 py-10 text-center text-xs text-muted-foreground`,children:Z(`engine.studio.nav.selectItem`,a)});let l=e=>{r({navigation:s.map((t,n)=>n===o?{...t,...e}:t)})},u=String(c.objectName??c.object??``),d=String(c.label??c.title??c.name??``),f=!d||d===`New item`||d===Z(`engine.appNav.newItem`,a);return(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.nav.label`,a)}),(0,$.jsx)(`input`,{value:d,onChange:e=>l({label:e.target.value}),placeholder:Z(`engine.studio.nav.labelPlaceholder`,a),className:`w-full rounded border bg-background px-2 py-1 text-xs`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{className:`mb-1 block text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.nav.linkObject`,a)}),(0,$.jsxs)(`select`,{value:u,onChange:e=>{let t=e.target.value,r=n.find(e=>e.name===t);if(!t){l({type:void 0,objectName:void 0,object:void 0});return}l({id:c.id||`nav_${t}`,type:`object`,objectName:t,object:void 0,path:void 0,label:f&&r?r.label:d})},className:`w-full rounded border bg-background px-2 py-1 text-xs`,children:[(0,$.jsx)(`option`,{value:``,children:Z(`engine.studio.nav.chooseObject`,a)}),n.map(e=>(0,$.jsxs)(`option`,{value:e.name,children:[e.label,` (`,e.name,`)`]},e.name))]}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:Z(u?`engine.studio.nav.boundHint`:`engine.studio.nav.unboundHint`,a)}),n.length===0&&(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-amber-600 dark:text-amber-400`,children:Z(`engine.studio.nav.noObjects`,a)})]}),(0,$.jsx)(`button`,{type:`button`,onClick:i,className:`text-[11px] text-muted-foreground underline-offset-2 hover:underline`,children:Z(`engine.studio.deselect`,a)})]})}function Cy({packageId:e,publishNonce:t=0,draftNonce:n=0,onDraftSaved:r,onCreateApp:i,readOnly:a=!1,foldInspector:o=!1,onDirtyChange:c}){let l=oa(),u=Mc(),d=sr(),[f,p]=Q.useState(!1),[m,h]=Q.useState(e),[g,_]=Q.useState(null),[v,y]=Q.useState({}),b=Q.useMemo(()=>Array.isArray(v.navigation)?v.navigation:[],[v]),[x,S]=Q.useState(!1),[C,w]=Q.useState(null),[T,E]=s(),D=Zs(T.get(`sel`)),O=Q.useRef(null);Q.useEffect(()=>{if(!D||b.length===0||O.current===D)return;let e=Xs({navigation:b},D);e&&(O.current=D,S(!0),w({kind:`nav`,id:e.selectionId}))},[D,b]),Q.useEffect(()=>{let e=C?Js({navigation:b},C.id):null;E(t=>{let n=new URLSearchParams(t);return e?n.set(`sel`,Qs(e)):n.delete(`sel`),n},{replace:!0})},[C]);let[k,A]=Q.useState(!1),j=Q.useRef(c);Q.useEffect(()=>{j.current=c}),Q.useEffect(()=>{j.current?.(k)},[k]),Q.useEffect(()=>()=>{j.current?.(!1)},[]);let[M,ee]=Q.useState(!1),[N,te]=Q.useState(!1),P=dv(k||!!N),[F,ne]=Q.useState(null),re=mv(F),[I,ie]=Q.useState(`source`),[L,ae]=Q.useState({}),oe=`${F?.type??``}:${F?.name??``}`,[R,se]=Q.useState({key:``,value:null}),z=R.key===oe?R.value:null,B=Q.useCallback(e=>se({key:oe,value:e}),[oe]),[ce,le]=Q.useState(`canvas`),ue=rv(),de=o&&!ue,[fe,pe]=Q.useState(!1),me=!de,V=!!(x&&C||z),he=Q.useRef(V);Q.useEffect(()=>{if(!de)return;let e=he.current;he.current=V,le(t=>tv(t,e,V))},[de,V]);let[ge,_e]=Q.useState(!1),[ve,ye]=Q.useState(!1),[be,xe]=Q.useState(!1),[Se,Ce]=Q.useState(null),[H,we]=Q.useState(`loading`),[U,W]=Q.useState([]),Te=Q.useMemo(()=>Object.fromEntries(U.map(e=>[e.name,e.icon])),[U]);Q.useEffect(()=>{let t=!1;return(async()=>{try{let[n,r]=await Promise.all([l.list(`object`,{packageId:e}),l.listDrafts({packageId:e,type:`object`}).catch(()=>[])]);if(t)return;let i=new Map;for(let e of[...n||[],...r||[]]){let t=e,n=String(t.name??``);!n||i.has(n)||i.set(n,{name:n,label:String(t.label??t.name??n),icon:t.icon?String(t.icon):void 0})}W([...i.values()])}catch{}})(),()=>{t=!0}},[l,e,t,n,P]);let Ee=Q.useRef(null);Q.useEffect(()=>{let t=!1,n=Ee.current===e;return Ee.current=e,n||we(`loading`),(async()=>{try{let n=await l.list(`app`,{packageId:e});if(t)return;let r=n?.[0]?.name?String(n[0].name):null,i=n?.[0]?String(n[0].label??n[0].name??e):e;if(!r){let n=await l.listDrafts({packageId:e,type:`app`});if(t)return;let a=n?.[0];a?.name&&(r=String(a.name),i=String(a.name))}if(!r){we(`missing`);return}h(i),_(r);let[a,o]=await Promise.all([l.layered(`app`,r),l.getDraft(`app`,r).catch(()=>null)]);if(t)return;let s=a,c=s.effective??s.code??{},u=vy(o),d=u?{...c,...u}:c;(typeof d.label==`string`||typeof d.name==`string`)&&h(String(d.label??d.name??i)),y(d),ee(!!u),we(`ready`);let f=Array.isArray(d.navigation)?d.navigation:[],p=(function e(t){for(let n of t)if(n.type===`group`||n.children?.length){let t=e(n.children??[]);if(t)return t}else{let e=fv(n);if(e)return e}return null})(f),m=re?pv(f,re):null;ne(e=>e??m??p)}catch(e){t||(Ce(Ru(e)),we(`missing`))}})(),()=>{t=!0}},[l,e,t,n,P]);let De=Xc(F?.type??``),Oe=$o(F?.type??``),ke=Yc(F?.type??``),Ae=Zc(F?.type??``),je=Hc().length===0&&Kc().length===0,[Me,Ne]=Q.useState({key:``,count:0}),Pe=`${oe}:${z?`${z.kind}:${z.id}`:`default`}`,Fe=Me.key===Pe?Me.count:0,Ie=!!De&&!Oe,[Le,Re]=Q.useState(`design`),ze=Le===`design`,Be=F?.type===`page`?L?.kind:void 0,Ve=Be===`html`||Be===`react`;Q.useEffect(()=>{if(!F||!Ie){ae({}),xe(!1);return}let e=!1;return _e(!0),Ce(null),B(null),(async()=>{try{let[t,n]=await Promise.all([l.layered(F.type,F.name),l.getDraft(F.type,F.name).catch(()=>null)]);if(e)return;let r=t.effective??t.code??{},i=vy(n);ae(i?{...r,...i}:r),xe(!!i),Ue(!1)}catch(t){e||Ce(Ru(t))}finally{e||_e(!1)}})(),()=>{e=!0}},[l,F,Ie,t]);let[He,Ue]=Q.useState(!1),We=Q.useCallback(e=>{ae(t=>({...t,...e})),Ue(!0)},[]),Ge=Q.useCallback(async()=>{if(F){ye(`draft`);try{await l.save(F.type,F.name,L,{mode:`draft`,packageId:e}),xe(!0),Ue(!1),r?.()}catch(e){Ce(Ru(e))}finally{ye(!1)}}},[l,F,L,r]);py({dirty:He,blocked:!F||!Ie||!!ve||a||Fe>0,snapshot:L,save:Ge});let Ke=Q.useCallback(e=>{y(t=>({...t,...e})),A(!0)},[]),qe=Q.useCallback(async()=>{if(g){te(`draft`);try{let t=(Array.isArray(v.navigation)?v.navigation:[]).filter(e=>e&&typeof e.type==`string`).map((e,t)=>{let n=e;return typeof n.id==`string`&&n.id?n:{...n,id:`nav_item_${t+1}`}});await l.save(`app`,g,{...v,navigation:t},{mode:`draft`,packageId:e}),ee(!0),A(!1),r?.()}catch(e){Ce(Ru(e))}finally{te(!1)}}},[l,g,v,r]);py({dirty:k,blocked:!g||!x||!!N||a,snapshot:v,save:qe});let Je=(0,$.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-auto bg-muted/30 p-4`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex shrink-0 items-center gap-2`,children:[!Oe&&(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-0.5 rounded-lg bg-muted p-1`,"data-testid":`canvas-mode-toggle`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>Re(`design`),"aria-pressed":ze,className:`rounded-md px-2.5 py-0.5 text-[11px] transition-all `+(ze?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.if.modeDesign`,u)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>Re(`run`),"aria-pressed":!ze,className:`rounded-md px-2.5 py-0.5 text-[11px] transition-all `+(ze?`text-muted-foreground hover:text-foreground`:`bg-background font-medium text-foreground shadow-sm`),children:Z(`engine.studio.if.modeRun`,u)})]}),F&&(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,title:`${Z(`engine.studio.if.internalId`,u)}: ${F.type} · ${F.name}`,"data-testid":`if-canvas-caption`,children:[F.label||F.name,` · `,Pc(F.type,u)]})]}),Se&&(0,$.jsx)(`div`,{className:`mb-3 shrink-0 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line`,children:Se}),(0,$.jsx)(`div`,{className:qr(Ve?`min-h-0 flex-1 overflow-hidden`:`rounded-lg border bg-background p-4`),children:H===`missing`&&!Se?(0,$.jsxs)(`div`,{className:`flex flex-col items-center justify-center gap-3 py-16 text-center`,children:[(0,$.jsx)(`div`,{className:`flex h-12 w-12 items-center justify-center rounded-full bg-muted`,children:(0,$.jsx)(cn,{className:`h-6 w-6 text-muted-foreground`})}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.if.noAppTitle`,u)}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:Z(`engine.studio.if.noAppHint`,u)})]}),i&&(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:`inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground`,children:[(0,$.jsx)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.app.create`,u)]})]}):F?ge?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground`,children:[(0,$.jsx)(Y,{className:`h-4 w-4 animate-spin`}),` `,Z(`engine.studio.loading`,u)]}):Oe?(0,$.jsx)(Oe,{type:F.type,name:F.name,draft:L,locale:u}):Ve?(0,$.jsx)(Zo,{mode:`preview`,draft:L,readOnly:!0}):De?(0,$.jsx)(De,{type:F.type,name:F.name,draft:L,editing:ze,selection:ze?z:null,onSelectionChange:ze?B:void 0,onPatch:We,locale:u}):(0,$.jsx)(`div`,{className:`py-12 text-center text-xs text-muted-foreground`,children:Nc(je?`engine.studio.if.designersMissing`:`engine.studio.if.noDesigner`,u,{type:F.type})}):(0,$.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.if.pickLeft`,u)})}),!Ie&&F?.type===`object`?(0,$.jsxs)(`p`,{className:`mt-2 flex items-center gap-1 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(tn,{className:`h-3 w-3`}),` `,Z(`engine.studio.if.objectHintPre`,u),(0,$.jsx)(`span`,{className:`font-medium`,children:`Data`}),Z(`engine.studio.if.objectHintPost`,u)]}):null]}),Ye=(0,$.jsxs)(`header`,{className:`flex shrink-0 items-center gap-2 border-b bg-background/95 px-3 py-2`,children:[(0,$.jsx)(bi,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.inspector.props`,u)}),(0,$.jsxs)(`div`,{className:`ml-auto flex items-center gap-0.5`,children:[z&&!Oe&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>B(null),className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.deselect`,u),children:(0,$.jsx)(ci,{className:`h-3.5 w-3.5`})}),me&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>pe(!0),className:`rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.inspector.collapse`,u),title:Z(`engine.studio.inspector.collapse`,u),children:(0,$.jsx)(zn,{className:`h-3.5 w-3.5`})})]})]}),Xe=(0,$.jsxs)(`aside`,{className:`flex w-9 shrink-0 flex-col items-center gap-1.5 border-l bg-background py-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>pe(!1),className:`rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.inspector.expand`,u),title:Z(`engine.studio.inspector.props`,u),children:(0,$.jsx)(mt,{className:`h-4 w-4`})}),(0,$.jsx)(bi,{className:`h-3.5 w-3.5 text-muted-foreground`})]}),Ze=x&&C?(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsx)(Sy,{navId:C.id,appDraft:v,objects:U,onNavPatch:Ke,onClear:()=>w(null)})}):Oe&&F?(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(Dn,{className:`h-5 w-5`}),Z(`engine.studio.inspector.studioCanvasNoBlocks`,u)]})}):z&&ke&&F?(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsx)(ke,{type:F.type,name:F.name,draft:L,selection:z,onPatch:We,onClearSelection:()=>B(null),onSelectionChange:B,onBlockingIssuesChange:e=>Ne({key:Pe,count:e}),readOnly:!1,locale:u})}):Ve?de?(0,$.jsx)(`div`,{className:`mt-2 min-h-0 flex-1 border-t`,children:(0,$.jsx)(Zo,{mode:`editor`,draft:L,onPatch:We})}):(0,$.jsxs)($i,{value:I,onValueChange:e=>ie(e===`props`?`props`:`source`),className:`flex min-h-0 flex-1 flex-col`,children:[(0,$.jsxs)(Un,{className:`mx-3 mt-2 shrink-0 self-start`,children:[(0,$.jsxs)(Rt,{value:`source`,className:`gap-1 text-xs`,children:[(0,$.jsx)(Qi,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.inspector.tabSource`,u)]}),(0,$.jsx)(Rt,{value:`props`,className:`text-xs`,children:Z(`engine.studio.inspector.tabProps`,u)})]}),(0,$.jsx)(_t,{value:`source`,className:`mt-2 min-h-0 flex-1 border-t`,children:(0,$.jsx)(Zo,{mode:`editor`,draft:L,onPatch:We})}),(0,$.jsx)(_t,{value:`props`,className:`mt-0 min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(Qi,{className:`h-5 w-5`}),Nc(`engine.studio.inspector.sourcePageLine1`,u,{kind:Be}),(0,$.jsx)(`br`,{}),Z(`engine.studio.inspector.sourcePageLine2`,u)]})})]}):Ae&&F&&Ie?(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsx)(Ae,{type:F.type,name:F.name,draft:L,onPatch:We,onSelectionChange:B,onBlockingIssuesChange:e=>Ne({key:Pe,count:e}),readOnly:!1,locale:u})}):je?(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(Ft,{className:`h-5 w-5`}),Z(`engine.studio.inspector.designersMissing`,u)]})}):(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(Or,{className:`h-5 w-5`}),Z(`engine.studio.inspector.emptyLine1`,u),(0,$.jsx)(`br`,{}),Z(`engine.studio.inspector.emptyLine2`,u)]})});return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>p(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,u),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,$.jsx)(Ii,{className:`h-4 w-4`})}),F?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-muted-foreground`,title:`${Z(`engine.studio.if.internalId`,u)}: ${F.type} · ${F.name}`,"data-testid":`if-breadcrumb`,children:[(0,$.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:F.label||F.name}),(0,$.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:Pc(F.type,u)})]}):(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.if.pickLeft`,u)}),be&&(0,$.jsx)(`span`,{className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublishedDraft`,u)}),ve===`draft`&&(0,$.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 text-[11px] text-muted-foreground`,"data-testid":`if-autosaving`,children:[(0,$.jsx)(Y,{className:`h-3 w-3 animate-spin`}),Z(`engine.studio.autoSaving`,u)]})]}),(0,$.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[d&&f&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>p(!1),"aria-hidden":`true`}),(0,$.jsxs)(`nav`,{className:qr((x?`w-72`:`w-52`)+` flex shrink-0 flex-col border-r bg-background`,d&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,d&&!f&&`-translate-x-full`),children:[(0,$.jsxs)(`div`,{className:`shrink-0 border-b px-2 py-1.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-1`,children:[(0,$.jsx)(`p`,{className:`truncate text-[11px] font-medium text-muted-foreground`,children:Nc(`engine.studio.if.navHeading`,u,{app:m})}),H===`ready`&&!a&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>{S(e=>!e),w(null)},title:Z(x?`engine.studio.if.doneEditTitle`:`engine.studio.if.editNavTitle`,u),className:`inline-flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[10px] `+(x?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted`),children:x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Pr,{className:`h-3 w-3`}),` `,Z(`engine.studio.done`,u)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(dn,{className:`h-3 w-3`}),` `,Z(`engine.studio.edit`,u)]})})]}),x&&(0,$.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-1.5`,children:[M&&(0,$.jsx)(`span`,{className:`rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublished`,u)}),N===`draft`&&(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground`,"data-testid":`nav-autosaving`,children:[(0,$.jsx)(Y,{className:`h-3 w-3 animate-spin`}),Z(`engine.studio.autoSaving`,u)]})]})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2`,children:H===`missing`&&!Se?(0,$.jsxs)(`div`,{className:`px-2 py-3`,children:[(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.if.noApp`,u)}),i&&(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:`mt-2 inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] hover:bg-muted`,children:[(0,$.jsx)(Ct,{className:`h-3 w-3`}),` `,Z(`engine.studio.app.create`,u)]})]}):x?(0,$.jsx)(Jo,{draft:v,rootKey:`navigation`,onPatch:Ke,selection:C,onSelectionChange:e=>w(e?{kind:e.kind,id:e.id}:null)}):b.length===0?(0,$.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(Se?`engine.studio.loadFailed`:H===`loading`?`engine.studio.loading`:`engine.studio.if.noNavItems`,u)}):(0,$.jsx)(xy,{nodes:b,active:F,objectIcons:Te,onPick:e=>{ne(e),d&&p(!1)}})})]}),o?ue?(0,$.jsxs)($.Fragment,{children:[Je,fe?Xe:(0,$.jsxs)(`aside`,{"data-testid":`studio-folded-inspector`,className:qr(`flex shrink-0 flex-col overflow-hidden border-l`,Ve&&!(z&&ke&&F)&&!(x&&C)?`w-[22rem] 2xl:w-[28rem]`:`w-72 2xl:w-80`),children:[Ye,Ze]})]}):(0,$.jsxs)($i,{value:ce,onValueChange:e=>le(e===`properties`?`properties`:`canvas`),className:`flex min-w-0 flex-1 flex-col`,"data-testid":`studio-center-tabs`,children:[(0,$.jsxs)(Un,{className:`mx-3 mt-2 shrink-0 self-start`,children:[(0,$.jsxs)(Rt,{value:`canvas`,className:`gap-1 text-xs`,children:[(0,$.jsx)(Dn,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.if.tabCanvas`,u)]}),(0,$.jsxs)(Rt,{value:`properties`,className:`gap-1 text-xs`,children:[(0,$.jsx)(bi,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.inspector.props`,u)]})]}),(0,$.jsx)(_t,{forceMount:!0,value:`canvas`,className:`mt-0 flex min-h-0 flex-1 flex-col data-[state=inactive]:hidden`,children:Je}),(0,$.jsxs)(_t,{value:`properties`,className:`mt-0 flex min-h-0 flex-1 flex-col overflow-hidden`,children:[Ye,Ze]})]}):(0,$.jsxs)($.Fragment,{children:[Je,fe?Xe:(0,$.jsxs)(`aside`,{className:qr(`flex shrink-0 flex-col overflow-hidden border-l`,Ve&&!(z&&ke&&F)&&!(x&&C)?`w-[24rem] xl:w-[30rem] 2xl:w-[36rem]`:`w-72`),children:[Ye,Ze]})]})]})]})}function wy(e){let t=e.length+1,n=`field_${t}`;for(;e.includes(n);)n=`field_${++t}`;return n}var Ty=new Set([`_id`,`id`,`organization_id`,`org_id`,`space_id`,`created_at`,`created_by`,`updated_at`,`updated_by`,`modified_at`,`modified_by`,`created_time`,`modified_time`,`updated_time`,`deleted_at`,`deleted_by`]);function Ey(e){let{schema:t,dataSource:n,onEdit:r,className:i,onAddRecord:a}=e;return(0,$.jsx)(xc,{schema:{...t,viewType:`grid`,showSearch:!0,showSort:!0,showFilters:!0,showGroup:!0,showHideFields:!0,inlineEdit:!0,addDeleteRecordsInline:!0,addRecord:{enabled:!0}},dataSource:n,onEdit:r,onAddRecord:a,className:i})}function Dy({packageId:e,publishNonce:t=0,onDraftSaved:n,readOnly:r=!1}){let i=oa(),a=Ue(),o=Mc(),{entries:s}=ca(i),c=Q.useMemo(()=>{let e={};for(let t of s)e[t.type]=t.schema;return e},[s]),l=sr(),[u,d]=Q.useState(!1),[f,p]=Q.useState([]),[m,h]=Q.useState(!1),g=dv(),[_,v]=Q.useState(null),y=mv(_),b=vm(),x=Q.useRef(0);Q.useEffect(()=>{if(!b||!m||b.id===x.current)return;x.current=b.id;let e=hv(f,b.target,`object`);e&&v(e)},[b,f,m]);let[S,C]=Q.useState({}),[w,T]=Q.useState(!1),[E,D]=Q.useState(null),[O,k]=Q.useState(null),[A,j]=Q.useState({key:``,count:0}),M=O?`${_?.name??``}:${O.kind}:${O.id}`:``,ee=A.key===M?A.count:0,[N,te]=Q.useState({key:``,count:0}),[P,F]=Q.useState(!1),[ne,re]=Q.useState(!1),[I,ie]=Q.useState(!1),[L,ae]=Q.useState(null),[oe,R]=Q.useState(0),[se,z]=Q.useState(`grid`),B=`${_?.name??``}:${se}`,ce=N.key===B?N.count:0,le=Q.useCallback(e=>te({key:B,count:e}),[B]),ue=ee+ce,[de,fe]=Q.useState(`layout`),pe=Q.useRef(null),[me,V]=Q.useState(``),[he,ge]=Q.useState(!1),[_e,ve]=Q.useState(wv),ye=Q.useCallback(()=>{D(null),ve(wv),ge(!0)},[]),[be,xe]=Q.useState(!1),[Se,Ce]=Q.useState(!0),[we,U]=Q.useState(new Set),[W,Te]=Q.useState(null);Q.useEffect(()=>{let t=!1;return Wc().then(n=>{t||Te(n.find(t=>t.id===e)?.namespace??null)}).catch(()=>{}),()=>{t=!0}},[e]),Q.useEffect(()=>{let t=!1;return(async()=>{try{let[n,r]=await Promise.all([i.list(`object`,{packageId:e}),i.listDrafts({packageId:e,type:`object`}).catch(()=>[])]);if(t)return;let a=(n||[]).map(e=>({type:`object`,name:String(e.name??``),label:String(e.label??e.name??``),icon:e.icon?String(e.icon):void 0})).filter(e=>e.name),o=new Set(a.map(e=>e.name));for(let e of r)e.name&&!o.has(e.name)&&a.push({type:`object`,name:e.name,label:e.name,icon:void 0});p(a);let s=hv(a,y,`object`);v(e=>e??s??a[0]??null)}catch(e){t||D(Ru(e))}finally{t||h(!0)}})(),()=>{t=!0}},[i,e,r,g]),Q.useEffect(()=>{if(!_)return;let e=`${_.name}#${t}`;if(pe.current===e)return;pe.current=e;let n=!1;return T(!0),D(null),k(null),F(!1),(async()=>{try{let[e,t]=await Promise.all([i.layered(`object`,_.name),i.getDraft(`object`,_.name).catch(()=>null)]);if(n)return;let r=e,a=r.effective??r.code??{},o=vy(t);C(o?{...a,...o}:a),re(!!o),Ce(!!(r.effective??r.code)),U(new Set(ic(a.fields).entries.map(e=>e.name)))}catch(e){n||D(Ru(e))}finally{n||T(!1)}})(),()=>{n=!0}},[i,_,t]);let Ee=Q.useMemo(()=>ic(S.fields).entries.length,[S]),De=Q.useMemo(()=>ic(S.fields).entries.map(e=>e.name).filter(e=>!Ty.has(e)&&e!==`actions`).filter(e=>we.has(e)),[S.fields,we]),Oe=Q.useMemo(()=>ic(S.fields).entries.map(e=>e.name).filter(e=>!Ty.has(e)),[S.fields]),ke=Q.useCallback(e=>{C(t=>({...t,...e})),F(!0)},[]),Ae=Q.useCallback(()=>{if(r)return;let e=ic(S.fields),t=wy(e.entries.map(e=>e.name));e.entries.push(fc(t,`text`,Z(`engine.studio.data.newFieldLabel`,o))),C(t=>({...t,fields:mc(e)})),F(!0),k({kind:`field`,id:t})},[S,r]),je=Q.useCallback(async(t,a,s)=>{if(r)return;let c=Vc(a,W);if(f.some(e=>e.name===c)){D(Nc(`engine.studio.data.idExists`,o,{name:c}));return}xe(!0),D(null);try{let r=gv(c,t,Z(`engine.studio.data.nameFieldLabel`,o),s);await i.save(`object`,c,r,{mode:`draft`,packageId:e});let a={type:`object`,name:c,label:t};p(e=>[...e,a]),v(a),z(`form`),fe(`layout`),ge(!1),n?.()}catch(e){D(Ru(e))}finally{xe(!1)}},[f,i,e,n,r,o,W]),Me=Q.useCallback(async()=>{if(_){ie(`draft`),D(null);try{await i.save(`object`,_.name,S,{mode:`draft`,packageId:e}),re(!0),F(!1),ae(new Date),n?.()}catch(e){D(Ru(e))}finally{ie(!1)}}},[i,_,S,n,e,o]);py({dirty:P,blocked:!_||!!I||r||ue>0,snapshot:S,save:Me});let Ne=Q.useCallback(async t=>{if(!_)return;let r=ic(S.fields),a=new Set(t),o=t.map(e=>r.entries.find(t=>t.name===e)).filter(e=>!!e),s=0,c=r.entries.map(e=>a.has(e.name)?o[s++]:e),l={...S,fields:mc({...r,entries:c})};C(l),ie(`draft`),D(null);try{await i.save(`object`,_.name,l,{mode:`draft`,packageId:e}),re(!0),F(!1),n?.(),R(e=>e+1)}catch(e){D(Ru(e))}finally{ie(!1)}},[i,_,S,n]),Pe=Yc(`object`),Fe=[{key:`grid`,label:Z(`engine.studio.data.tab.records`,o)},{key:`form`,label:Z(`engine.studio.data.tab.form`,o)}],Ie=[{key:`rules`,label:Z(`engine.studio.data.tab.rules`,o)},{key:`hooks`,label:Z(`engine.studio.data.tab.hooks`,o)},{key:`actions`,label:Z(`engine.studio.data.tab.actions`,o)},{key:`api`,label:Z(`engine.studio.data.tab.api`,o)},{key:`settings`,label:Z(`engine.studio.data.tab.settings`,o)}],Le=Ie.find(e=>e.key===se),Re=qs(typeof S.icon==`string`?S.icon:_?.icon);return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-3 py-2`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>d(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,o),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,$.jsx)(Ii,{className:`h-4 w-4`})}),_?(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(Re,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`truncate text-[15px] font-semibold leading-none text-foreground`,children:_.label}),(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-muted/70 px-1.5 py-0.5 font-mono text-[10px] text-muted-foreground`,children:_.name}),(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-muted-foreground`,children:Nc(`engine.studio.data.fieldCount`,o,{count:Ee})})]}):(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,o)}),ne&&(0,$.jsx)(`span`,{className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublishedDraft`,o)}),I===`draft`?(0,$.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 text-[11px] text-muted-foreground`,"data-testid":`data-autosaving`,children:[(0,$.jsx)(Y,{className:`h-3 w-3 animate-spin`}),Z(`engine.studio.autoSaving`,o)]}):L&&!P?(0,$.jsx)(`span`,{className:`ml-auto text-[11px] text-muted-foreground`,"data-testid":`data-saved-at`,children:Nc(`engine.studio.data.lastSaved`,o,{time:L.toLocaleTimeString(o,{hour:`2-digit`,minute:`2-digit`})})}):null]}),(0,$.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[l&&u&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>d(!1),"aria-hidden":`true`}),(0,$.jsxs)(`nav`,{className:qr(`flex w-52 shrink-0 flex-col border-r bg-background`,l&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,l&&!u&&`-translate-x-full`),children:[(0,$.jsxs)(`div`,{className:`shrink-0 p-2 pb-1`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1 pt-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.data.objects`,o)}),(0,$.jsx)(`input`,{value:me,onChange:e=>V(e.target.value),placeholder:Z(`engine.studio.data.searchObjects`,o),className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none placeholder:text-muted-foreground/70 focus:ring-1 focus:ring-primary`})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2 pt-1`,children:[f.length===0&&(0,$.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(E?`engine.studio.loadFailed`:m?`engine.studio.data.noObjects`:`engine.studio.loading`,o)}),f.filter(e=>!me.trim()||e.label.toLowerCase().includes(me.trim().toLowerCase())||e.name.toLowerCase().includes(me.trim().toLowerCase())).map(e=>{let t=qs(e.icon);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{v(e),l&&d(!1)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(_?.name===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,$.jsx)(t,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.label})]},e.name)})]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t p-2`,children:r?(0,$.jsxs)(`p`,{title:Z(`engine.studio.pkg.readonlyHint`,o),className:`flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(cr,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,o)]}):(0,$.jsxs)(`button`,{type:`button`,onClick:ye,className:`inline-flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,$.jsx)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.newObject`,o)]})})]}),(0,$.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-hidden p-4`,children:_?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-4 flex shrink-0 items-center gap-3`,children:[(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-0.5 rounded-lg bg-muted p-1`,children:[Fe.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>z(e.key),"aria-pressed":se===e.key,className:`rounded-md px-3 py-1 text-[13px] transition-all `+(se===e.key?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:e.label},e.key)),(0,$.jsxs)(Bn,{children:[(0,$.jsx)($n,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,"data-testid":`data-tabs-advanced`,"aria-pressed":!!Le,className:`inline-flex items-center gap-1 rounded-md px-3 py-1 text-[13px] transition-all `+(Le?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:[Le?Le.label:Z(`engine.studio.data.tab.advanced`,o),(0,$.jsx)(zr,{className:`h-3 w-3`})]})}),(0,$.jsx)(It,{align:`start`,children:Ie.map(e=>(0,$.jsx)(qn,{onSelect:()=>z(e.key),className:se===e.key?`font-medium text-primary`:void 0,children:e.label},e.key))})]})]}),(se===`grid`||se===`form`)&&!r&&(0,$.jsxs)(`button`,{type:`button`,onClick:Ae,title:Z(`engine.studio.data.addFieldTitle`,o),className:`ml-auto inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,$.jsx)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.addField`,o)]})]}),E&&(0,$.jsx)(`div`,{className:`mb-2 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive whitespace-pre-line`,children:E}),se===`rules`?(0,$.jsx)(Kv,{draft:S,onPatch:ke,disabled:r,onBlockingIssuesChange:le}):se===`settings`?(0,$.jsx)(qv,{name:_.name,draft:S,onPatch:ke,locale:o,disabled:r,onBlockingIssuesChange:le}):se===`hooks`?(0,$.jsx)(ay,{objectName:_.name,packageId:e,disabled:r,hookSchema:c.hook}):se===`actions`?(0,$.jsx)(ly,{draft:S,onPatch:ke,disabled:r,actionSchema:c.action,onBlockingIssuesChange:le}):se===`api`?(0,$.jsx)(ty,{name:_.name,draft:S}):se===`grid`&&!Se?(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-2 rounded-lg border border-dashed bg-muted/20 text-center`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.draftObjectTitle`,o)}),(0,$.jsx)(`p`,{className:`max-w-md text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.draftObjectHint`,o)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{z(`form`),fe(`layout`)},className:`mt-1 inline-flex items-center gap-1 rounded-md border px-2.5 py-1 text-xs hover:bg-muted`,children:Z(`engine.studio.data.goDesignFields`,o)})]}):se===`grid`?(0,$.jsx)($.Fragment,{children:(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background`,children:(0,$.jsx)(Pi,{value:{...r?{}:{onAddColumn:Ae,addColumnLabel:Z(`engine.studio.data.addField`,o),onReorderFields:Ne},onEditColumn:e=>{ic(S.fields).entries.some(t=>t.name===e)&&k({kind:`field`,id:e})},editColumnLabel:Z(`engine.studio.data.editFieldProps`,o)},children:(0,$.jsx)(H,{dataSource:a,children:(0,$.jsx)(Tc,{schema:{type:`object-view`,objectName:_.name,showCreate:!1,table:{fields:De}},dataSource:a,renderListView:Ey},`${_.name}:${oe}`)})})})}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center gap-2`,children:[(0,$.jsxs)(`div`,{className:`inline-flex items-center gap-0.5 rounded-lg bg-muted p-0.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>fe(`layout`),"aria-pressed":de===`layout`,className:`rounded-md px-2.5 py-0.5 text-[12px] transition-all `+(de===`layout`?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.form.layout`,o)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>fe(`preview`),"aria-pressed":de===`preview`,className:`rounded-md px-2.5 py-0.5 text-[12px] transition-all `+(de===`preview`?`bg-background font-medium text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:Z(`engine.studio.data.form.preview`,o)})]}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(de===`layout`?P&&!r?`engine.studio.data.form.layoutBadge`:`engine.studio.data.form.layoutBadgeClean`:`engine.studio.data.form.previewBadge`,o)}),de===`preview`&&(P||ne)&&(0,$.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.data.form.previewWarn`,o)})]}),de===`layout`?(0,$.jsx)(Fv,{draft:S,objectName:_.name,systemFieldNames:Ty,onChange:ke,selectedField:O?.kind===`field`?O.id:null,onSelectField:e=>k({kind:`field`,id:e}),selectedGroup:O?.kind===`group`?O.id:null,onSelectGroup:e=>k({kind:`group`,id:e}),onAddField:Ae,readOnly:r}):Se?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`style`,{children:`
|
|
11
|
+
/* Design preview: the form is a click-to-select canvas, not a data-entry
|
|
12
|
+
* form. Disable interaction on field contents so a click anywhere on a
|
|
13
|
+
* field routes to its [data-field] wrapper (→ select), and neutralize the
|
|
14
|
+
* create/cancel footer so nothing is submittable here. */
|
|
15
|
+
.os-form-authoring [data-field]{border-radius:8px;cursor:pointer;transition:box-shadow .12s;padding:8px;margin:-8px 0;}
|
|
16
|
+
.os-form-authoring [data-field] *{pointer-events:none;}
|
|
17
|
+
.os-form-authoring [data-field]:hover{box-shadow:0 0 0 1px hsl(var(--border));}
|
|
18
|
+
.os-form-authoring form > div:last-child:has(button){display:none;}
|
|
19
|
+
${O?.kind===`field`?`.os-form-authoring [data-field="${String(O.id).replace(/[^\w-]/g,``)}"]{box-shadow:0 0 0 2px hsl(var(--primary));}`:``}
|
|
20
|
+
`}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto rounded-lg border bg-background p-6`,children:(0,$.jsx)(`div`,{className:`os-form-authoring mx-auto max-w-6xl`,onClick:e=>{let t=e.target.closest(`[data-field]`)?.getAttribute(`data-field`);t&&ic(S.fields).entries.some(e=>e.name===t)&&k({kind:`field`,id:t})},children:(0,$.jsx)(H,{dataSource:a,children:(0,$.jsx)(ga,{schema:{type:`object-form`,objectName:_.name,mode:`create`,fields:Oe},dataSource:a},`${_.name}:${oe}:form`)})})})]}):(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col items-center justify-center gap-2 rounded-lg border border-dashed bg-muted/20 text-center`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.form.noPublishedTitle`,o)}),(0,$.jsx)(`p`,{className:`max-w-md text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.form.noPublishedHint`,o)})]})]})]}):m&&f.length===0?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 py-16 text-center`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium`,children:Z(`engine.studio.data.firstObjectTitle`,o)}),(0,$.jsx)(`p`,{className:`max-w-sm text-[11px] leading-5 text-muted-foreground`,children:Z(`engine.studio.data.firstObjectHint`,o)}),!r&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`empty-state-new-object`,onClick:ye,className:`mt-2 inline-flex items-center gap-1.5 rounded-md bg-primary px-3 py-1.5 text-xs font-medium text-primary-foreground hover:bg-primary/90`,children:[(0,$.jsx)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.data.newObject`,o)]})]}):(0,$.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.data.pickObject`,o)})}),_&&O&&(0,$.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-l`,children:[(0,$.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 px-3 py-2 backdrop-blur`,children:[(0,$.jsx)(bi,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(O.kind===`group`?`engine.studio.data.groupProps`:`engine.studio.data.fieldProps`,o)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>k(null),className:`ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.close`,o),children:(0,$.jsx)(ci,{className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto p-3`,children:O.kind===`group`?(0,$.jsx)(Iv,{draft:S,groupKey:O.id,onPatch:ke,onClose:()=>k(null),readOnly:r,locale:o}):Pe?Q.createElement(Pe,{type:`object`,name:_.name,draft:S,selection:O,onPatch:ke,onClearSelection:()=>k(null),onSelectionChange:k,onBlockingIssuesChange:e=>j({key:M,count:e}),readOnly:r,locale:o}):(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(Ft,{className:`h-5 w-5`}),Z(`engine.studio.data.fieldInspectorMissing`,o)]})})]})]}),(0,$.jsx)(Tv,{open:he,onOpenChange:ge,title:Z(`engine.studio.data.newObject`,o),labelFieldLabel:Z(`engine.studio.data.nameLabel`,o),labelPlaceholder:Z(`engine.studio.data.labelPlaceholder`,o),idFieldLabel:Z(`engine.studio.data.idLabel`,o),idPlaceholder:Z(`engine.studio.data.idPlaceholder`,o),submitLabel:Z(`engine.studio.createDraft`,o),submittingLabel:Z(`engine.studio.creating`,o),busy:be,error:E,locale:o,extra:(0,$.jsxs)(`label`,{className:`block`,children:[(0,$.jsx)(`span`,{className:`mb-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.data.owdLabel`,o)}),(0,$.jsx)(`select`,{value:_e,"data-testid":`create-object-owd`,onChange:e=>ve(e.target.value),className:`w-full rounded border bg-background px-2 py-1 text-[12px]`,children:Cv.map(e=>(0,$.jsx)(`option`,{value:e,children:Z(uy[e],o)},e))}),(0,$.jsx)(`span`,{className:`mt-1 block text-[11px] text-muted-foreground`,children:Z(dy[_e],o)}),(0,$.jsx)(`span`,{className:`mt-1 block text-[11px] text-muted-foreground`,children:Z(`engine.studio.data.owdHint`,o)})]}),onSubmit:({label:e,name:t})=>void je(e,t,_e)})]})}function Oy({state:e,locale:t}){if(!e)return null;let{enabled:n,bound:r}=e,i=Z(n?r?`engine.studio.auto.onBound`:`engine.studio.auto.onUnbound`:`engine.studio.auto.offTitle`,t);return(0,$.jsxs)(`span`,{title:i,className:`inline-flex shrink-0 items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`h-1.5 w-1.5 rounded-full `+(n?`bg-emerald-500`:`bg-muted-foreground/40`)}),(0,$.jsx)(`span`,{className:`text-[10px] `+(n?`text-emerald-600 dark:text-emerald-400`:`text-muted-foreground`),children:Z(n?`engine.studio.auto.on`:`engine.studio.auto.off`,t)})]})}function ky({packageId:e,publishNonce:t=0,onDraftSaved:n,readOnly:r=!1}){let i=oa(),a=Mc(),o=sr(),[s,c]=Q.useState(!1),[l,u]=Q.useState([]),d=dv(),[f,p]=Q.useState(null),m=mv(f),[h,g]=Q.useState({}),[_,v]=Q.useState(null),[y,b]=Q.useState(!1),[x,S]=Q.useState(!1),[C,w]=Q.useState(!1),[T,E]=Q.useState(null),[D,O]=Q.useState(!1),[k,A]=Q.useState(!1),[j,M]=Q.useState(!1),ee=Xc(f?.type??``),N=Yc(`flow`),te=!!ee,P=Hc().length===0&&Kc().length===0,[F,ne]=Q.useState({});Q.useEffect(()=>{let e=!1;return(async()=>{try{let t=await fetch(`/api/v1/automation/_status`,{credentials:`include`,headers:{Accept:`application/json`}});if(!t.ok)return;let n=await t.json().catch(()=>null),r=n?.data?.flows??n?.flows??[];if(e||!Array.isArray(r))return;let i={};for(let e of r)e?.name&&(i[e.name]={enabled:e.enabled!==!1,bound:!!e.bound});ne(i)}catch{}})(),()=>{e=!0}},[t]),Q.useEffect(()=>{let t=!1;return(async()=>{try{let n=await uv(i,`flow`,e);if(t)return;u(n);let r=hv(n,m,`flow`);p(e=>e??r??n[0]??null)}catch(e){t||E(Ru(e))}finally{t||O(!0)}})(),()=>{t=!0}},[i,e,t,d]);let re=Q.useCallback(async(t,r)=>{M(!0),E(null);try{let o=_v(r,t,Z(`engine.studio.auto.nodeStart`,a),Z(`engine.studio.auto.nodeEnd`,a));await i.save(`flow`,r,o,{mode:`draft`,packageId:e});let s={type:`flow`,name:r,label:t};u(e=>[...e.filter(e=>e.name!==r),s]),p(s),w(!0),A(!1),n?.(),X.success(Nc(`engine.studio.auto.savedDraft`,a,{label:t}))}catch(e){E(Ru(e))}finally{M(!1)}},[i,e,n,a]);Q.useEffect(()=>{if(!f)return;let e=!1;return b(!0),E(null),v(null),(async()=>{try{let[t,n]=await Promise.all([i.layered(`flow`,f.name),i.getDraft(`flow`,f.name).catch(()=>null)]);if(e)return;let r=t,a=r.effective??r.code??{},o=vy(n);g(o?{...a,...o}:a),w(!!o)}catch(t){e||E(Ru(t))}finally{e||(b(!1),ie(!1))}})(),()=>{e=!0}},[i,f,t]);let[I,ie]=Q.useState(!1),L=Q.useCallback(e=>{g(t=>({...t,...e})),ie(!0)},[]),ae=Q.useCallback(async()=>{if(f){S(`draft`),E(null);try{await i.save(`flow`,f.name,h,{mode:`draft`,packageId:e}),w(!0),ie(!1),n?.()}catch(e){E(Ru(e))}finally{S(!1)}}},[i,f,h,n]);py({dirty:I,blocked:!f||!te||!!x||r,snapshot:h,save:ae});let oe=h.status!==`obsolete`&&h.status!==`invalid`,R=Q.useCallback(async()=>{if(!f)return;let t=h.status===`obsolete`||h.status===`invalid`,r={...h,status:t?`active`:`obsolete`};g(r),S(`draft`),E(null);try{await i.save(`flow`,f.name,r,{mode:`draft`,packageId:e}),w(!0),n?.(),X.success(Z(t?`engine.studio.auto.enabledToast`:`engine.studio.auto.disabledToast`,a))}catch(e){E(Ru(e))}finally{S(!1)}},[i,f,h,e,n,a]);return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>c(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,a),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,$.jsx)(Ii,{className:`h-4 w-4`})}),(0,$.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.auto.defaultOff`,a)}),C&&(0,$.jsx)(`span`,{className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.unpublishedDraft`,a)}),f&&(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":oe,onClick:R,disabled:!te||!!x,title:Z(oe?`engine.studio.auto.disableTitle`:`engine.studio.auto.enableTitle`,a),className:`inline-flex items-center gap-1.5 rounded-md border px-2 py-1 text-[11px] hover:bg-muted disabled:opacity-50`,children:[(0,$.jsx)(`span`,{className:`relative inline-flex h-3.5 w-6 shrink-0 items-center rounded-full transition-colors `+(oe?`bg-emerald-500`:`bg-muted-foreground/40`),children:(0,$.jsx)(`span`,{className:`inline-block h-2.5 w-2.5 rounded-full bg-white transition-transform `+(oe?`translate-x-3`:`translate-x-0.5`)})}),Z(oe?`engine.studio.auto.enabled`:`engine.studio.auto.disabled`,a)]}),x===`draft`&&(0,$.jsxs)(`span`,{className:`ml-auto inline-flex items-center gap-1 text-[11px] text-muted-foreground`,"data-testid":`auto-autosaving`,children:[(0,$.jsx)(Y,{className:`h-3 w-3 animate-spin`}),Z(`engine.studio.autoSaving`,a)]})]}),(0,$.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[o&&s&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>c(!1),"aria-hidden":`true`}),(0,$.jsxs)(`nav`,{className:qr(`flex w-52 shrink-0 flex-col overflow-auto border-r bg-background p-2`,o&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,o&&!s&&`-translate-x-full`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 px-2 pb-1 pt-1`,children:[(0,$.jsx)(`p`,{className:`flex-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.auto.heading`,a)}),!r&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{E(null),A(!0)},title:Z(`engine.studio.auto.newTitle`,a),className:`inline-flex items-center gap-0.5 rounded border px-1.5 py-0.5 text-[11px] hover:bg-muted`,children:[(0,$.jsx)(Ct,{className:`h-3 w-3`}),` `,Z(`engine.studio.new`,a)]})]}),l.length>0&&l.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{p(e),o&&c(!1)},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(f?.name===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,$.jsx)(Kr,{className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),(0,$.jsx)(Oy,{state:F[e.name],locale:a})]},e.name)),l.length===0&&!k&&(0,$.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(T?`engine.studio.loadFailed`:D?`engine.studio.auto.none`:`engine.studio.loading`,a)})]}),(0,$.jsxs)(`main`,{className:`flex min-w-0 flex-1 flex-col overflow-auto bg-muted/30 p-4`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex shrink-0 items-center gap-2`,children:[(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-full bg-primary/10 px-2 py-0.5 text-[11px] text-primary`,children:[(0,$.jsx)(Kr,{className:`h-3 w-3`}),` `,Z(te?`engine.studio.auto.canvasHint`:`engine.studio.auto.designersMissing`,a)]}),f&&(0,$.jsxs)(`span`,{className:`text-[11px] text-muted-foreground`,children:[`flow · `,f.name]})]}),T&&(0,$.jsx)(`div`,{className:`mb-3 shrink-0 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive whitespace-pre-line`,children:T}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 rounded-lg border bg-background p-4`,children:f?y?(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 py-16 text-sm text-muted-foreground`,children:[(0,$.jsx)(Y,{className:`h-4 w-4 animate-spin`}),` `,Z(`engine.studio.loading`,a)]}):ee?Q.createElement(ee,{type:f.type,name:f.name,draft:h,editing:!0,selection:_,onSelectionChange:v,onPatch:L,locale:a}):(0,$.jsx)(`pre`,{className:`overflow-auto text-[11px] text-muted-foreground`,children:JSON.stringify(h,null,2)}):(0,$.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:Z(`engine.studio.auto.pick`,a)})})]}),(0,$.jsxs)(`aside`,{className:`w-72 shrink-0 overflow-auto border-l`,children:[(0,$.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background/95 px-3 py-2 backdrop-blur`,children:[(0,$.jsx)(bi,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium`,children:Z(`engine.studio.auto.config`,a)}),_&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>v(null),className:`ml-auto rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground`,"aria-label":Z(`engine.studio.deselect`,a),children:(0,$.jsx)(ci,{className:`h-3.5 w-3.5`})})]}),(0,$.jsx)(`div`,{className:`p-3`,children:_&&N&&f?Q.createElement(N,{type:`flow`,name:f.name,draft:h,selection:_,onPatch:L,onClearSelection:()=>v(null),onSelectionChange:v,readOnly:!1,locale:a}):P?(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(Ft,{className:`h-5 w-5`}),Z(`engine.studio.auto.designersMissing`,a)]}):(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-2 px-2 py-10 text-center text-xs text-muted-foreground`,children:[(0,$.jsx)(Or,{className:`h-5 w-5`}),Z(`engine.studio.auto.emptyLine1`,a),(0,$.jsx)(`br`,{}),Z(`engine.studio.auto.emptyLine2`,a)]})})]})]}),(0,$.jsx)(Tv,{open:k,onOpenChange:A,title:Z(`engine.studio.auto.newTitle`,a),labelFieldLabel:Z(`engine.studio.auto.nameLabel`,a),labelPlaceholder:Z(`engine.studio.auto.namePlaceholder`,a),idFieldLabel:Z(`engine.studio.auto.idLabel`,a),idPlaceholder:Z(`engine.studio.auto.idPlaceholder`,a),submitLabel:Z(`engine.studio.createDraft`,a),submittingLabel:Z(`engine.studio.creating`,a),busy:j,error:T,locale:a,onSubmit:({label:e,name:t})=>void re(e,t)})]})}function Ay({packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r=!1,onDirtyChange:i}){let a=oa(),o=Mc(),s=sr(),[c,l]=Q.useState(!1),u=dv(),[d,f]=Q.useState([]),[p,m]=Q.useState(!1),[h,g]=Q.useState(null),[_,v]=Q.useState(null),[y,b]=Q.useState(!1),[x,S]=Q.useState(null),C=Q.useRef(!1),w=mv(Q.useMemo(()=>y?{type:`owd`,name:`overview`}:_?{type:`permission`,name:_}:null,[y,_])),[T,E]=Q.useState(``),[D,O]=Q.useState(!1),[k,A]=Q.useState(null),[j,M]=Q.useState(!1),[ee,N]=Q.useState(!1),[te,P]=Q.useState(!1),[F,ne]=Q.useState(!1),re=te||F,I=Q.useRef(i);Q.useEffect(()=>{I.current=i}),Q.useEffect(()=>{I.current?.(re)},[re]),Q.useEffect(()=>()=>{I.current?.(!1)},[]);let ie=Q.useCallback(()=>!re||window.confirm(Z(`engine.edit.unsavedLeaveConfirm`,o)),[re,o]),L=Q.useCallback(async()=>{try{let[t,n]=await Promise.all([a.list(`permission`,{packageId:e}),a.listDrafts({packageId:e,type:`permission`}).catch(()=>[])]),r=new Map;for(let e of t||[]){let t=String(e.name??e.id??``);t&&r.set(t,{name:t,label:String(e.label??e.name??``),isDefault:!!e.isDefault})}for(let e of n||[]){let t=String(e?.name??``);!t||r.has(t)||r.set(t,{name:t,label:t})}let i=[...r.values()];f(i),!C.current&&w?.type===`owd`&&(C.current=!0,b(!0));let o=hv(i,w,`permission`);v(e=>e??o?.name??i[0]?.name??null)}catch(e){g(Ru(e))}finally{m(!0)}},[a,e]);Q.useEffect(()=>{L()},[L,t,u]);let ae=Q.useCallback(async(t,r)=>{M(!0),A(null);try{await a.save(`permission`,r,yv(r,t),{mode:`draft`,packageId:e}),X.success(Nc(`engine.studio.access.created`,o,{label:t})),O(!1),n?.(),await L(),b(!1),v(r)}catch(e){A(Ru(e))}finally{M(!1)}},[a,L,e,n,o]),oe=d.filter(e=>!T.trim()||e.label.toLowerCase().includes(T.trim().toLowerCase())||e.name.toLowerCase().includes(T.trim().toLowerCase()));return(0,$.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-3 py-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>l(e=>!e),"aria-label":Z(`engine.studio.toggleRail`,o),className:`-ml-1 rounded-md p-1 text-muted-foreground hover:bg-muted hover:text-foreground md:hidden`,children:(0,$.jsx)(Ii,{className:`h-4 w-4`})}),(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(Qn,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-[13px] font-medium text-foreground`,children:Z(`engine.studio.access.title`,o)}),(0,$.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:Z(`engine.studio.access.subtitle`,o)})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>N(!0),className:`ml-auto flex items-center gap-1.5 rounded-md border px-2 py-0.5 text-[11px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,$.jsx)(vn,{className:`h-3.5 w-3.5`}),Z(`engine.studio.access.explain.open`,o)]}),(0,$.jsx)(`span`,{title:Z(`engine.studio.access.bannerTitle`,o),className:`rounded bg-amber-400/15 px-2 py-0.5 text-[11px] text-amber-600 dark:text-amber-300`,children:Z(`engine.studio.access.banner`,o)})]}),!r&&(0,$.jsx)(hs,{packageId:e,className:`mx-3 mt-2`,strings:{describe:e=>Nc(e.anchor===`guest`?`engine.studio.access.suggestPromptGuest`:`engine.studio.access.suggestPromptEveryone`,o,{set:e.permission_set_name}),confirm:Z(`engine.studio.access.suggestConfirm`,o),confirming:Z(`engine.studio.access.suggestConfirming`,o),dismiss:Z(`engine.studio.access.suggestDismiss`,o),confirmedToast:e=>Nc(`engine.studio.access.suggestConfirmedToast`,o,{set:e.permission_set_name,anchor:e.anchor}),dismissedToast:e=>Nc(`engine.studio.access.suggestDismissedToast`,o,{set:e.permission_set_name})}}),(0,$.jsxs)(`div`,{className:`relative flex min-h-0 flex-1`,children:[s&&c&&(0,$.jsx)(`div`,{className:`absolute inset-0 z-10 bg-black/30`,onClick:()=>l(!1),"aria-hidden":`true`}),(0,$.jsxs)(`nav`,{className:qr(`flex w-52 shrink-0 flex-col border-r bg-background`,s&&`absolute inset-y-0 left-0 z-20 shadow-lg transition-transform duration-200`,s&&!c&&`-translate-x-full`),children:[(0,$.jsx)(`div`,{className:`border-b p-2 pb-2`,children:(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{if(y){S(null),s&&l(!1);return}ie()&&(b(!0),S(null),s&&l(!1))},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(y?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,$.jsx)(lt,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:Z(`engine.studio.owd.railLabel`,o)})]})}),(0,$.jsxs)(`div`,{className:`p-2 pb-0`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1 pt-1 text-[11px] font-medium text-muted-foreground`,children:Z(`engine.studio.access.heading`,o)}),(0,$.jsx)(`input`,{value:T,onChange:e=>E(e.target.value),placeholder:Z(`engine.studio.access.search`,o),className:`mb-1 h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto p-2 pt-1`,children:[d.length===0&&(0,$.jsx)(`p`,{className:`px-2 py-3 text-[11px] text-muted-foreground`,children:Z(h?`engine.studio.loadFailed`:p?`engine.studio.access.none`:`engine.studio.loading`,o)}),oe.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{if(!y&&_===e.name){s&&l(!1);return}ie()&&(b(!1),v(e.name),s&&l(!1))},className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-xs `+(!y&&_===e.name?`bg-muted font-medium`:`text-foreground/90 hover:bg-muted/60`),children:[(0,$.jsx)(Qn,{className:`h-3.5 w-3.5 shrink-0 text-muted-foreground`}),(0,$.jsx)(`span`,{className:`flex-1 truncate`,children:e.label}),e.isDefault&&(0,$.jsx)(`span`,{className:`text-[9px] uppercase tracking-wide text-muted-foreground/60`,children:`default`})]},e.name))]}),(0,$.jsx)(`div`,{className:`shrink-0 border-t p-2`,children:r?(0,$.jsxs)(`p`,{title:Z(`engine.studio.pkg.readonlyHint`,o),className:`flex items-center gap-1.5 px-2 py-1.5 text-[11px] text-muted-foreground`,children:[(0,$.jsx)(cr,{className:`h-3 w-3`}),` `,Z(`engine.studio.pkg.readonly`,o)]}):(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{ie()&&(A(null),O(!0))},className:`flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,$.jsx)(Ct,{className:`h-3.5 w-3.5`}),` `,Z(`engine.studio.access.new`,o)]})})]}),(0,$.jsx)(`main`,{className:`min-w-0 flex-1 overflow-auto`,children:y?(0,$.jsx)(Zv,{client:a,packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r,locale:o,highlightObject:x,onDirtyChange:ne}):_?(0,$.jsx)(Go,{type:`permission`,name:_,packageId:e,publishNonce:t,onDraftSaved:n,readOnly:r,onDirtyChange:P,embedded:!0,onOpenOwd:e=>{ie()&&(S(e||null),b(!0))}},_):(0,$.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:p&&d.length===0?Z(`engine.studio.access.emptyMain`,o):Z(`engine.studio.access.pick`,o)})})]}),(0,$.jsx)(lv,{open:ee,onOpenChange:N,packageId:e}),(0,$.jsx)(Tv,{open:D,onOpenChange:O,title:Z(`engine.studio.access.new`,o),labelFieldLabel:Z(`engine.studio.access.nameLabel`,o),labelPlaceholder:Z(`engine.studio.access.labelPlaceholder`,o),idFieldLabel:Z(`engine.studio.access.idLabel`,o),idPlaceholder:Z(`engine.studio.access.idPlaceholder`,o),submitLabel:Z(`engine.studio.create`,o),submittingLabel:Z(`engine.studio.creating`,o),busy:j,error:k,locale:o,onSubmit:({label:e,name:t})=>void ae(e,t)})]})}function jy({value:e,onChange:t,onEnter:n,onEscape:r,placeholder:i,autoFocus:a,locale:o,testId:s}){let[c,l]=Q.useState(!1),u=e.trim().length>0&&!qc.test(e.trim());return(0,$.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,$.jsx)(`input`,{autoFocus:a,value:e,onChange:e=>{let{value:n,stripped:r}=$c(e.target.value);l(r),t(n)},onKeyDown:e=>{e.key===`Enter`&&n?.(),e.key===`Escape`&&r?.()},placeholder:i,"data-testid":s,className:`h-7 w-full rounded-md border bg-background px-2 font-mono text-[11px] outline-none focus:ring-1 focus:ring-primary`}),c&&(0,$.jsx)(`p`,{className:`text-[10px] text-amber-600 dark:text-amber-400`,"data-testid":`pkg-id-stripped`,children:Z(`engine.studio.pkg.idStrippedNotice`,o)}),u&&(0,$.jsx)(`p`,{className:`text-[10px] text-muted-foreground`,"data-testid":`pkg-id-format-hint`,children:Z(`engine.studio.pkg.idFormatHint`,o)})]})}function My(){let e=p(),t=Mc(),[n,r]=Q.useState(null),[i,a]=Q.useState(null),[o,s]=Q.useState(!1);Q.useEffect(()=>{let e=!1;return Wc().then(t=>{e||r(t)}).catch(t=>{e||a(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]);let c=t=>e(`/studio/${encodeURIComponent(t)}/data`),l=n?.filter(e=>e.writable)??[],u=n?.filter(e=>!e.writable)??[],[d,f]=Q.useState(null),[m,h]=Q.useState(``),[g,_]=Q.useState(``),[v,y]=Q.useState(!1),[b,x]=Q.useState(null),S=e=>{f(e.id),h(Nc(`engine.studio.landing.dupDefaultName`,t,{name:e.name})),_(`${e.id}-copy`),x(null)},C=async()=>{if(!d)return;let e=g.trim(),n=m.trim();if(!(!qc.test(e)||!n)){y(!0),x(null);try{await Gc(d,e,n),X.success(Nc(`engine.studio.landing.dupCreated`,t,{name:n})),c(e)}catch(e){x(e instanceof Error?e.message:String(e))}finally{y(!1)}}};return(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-5xl p-6`,children:[(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,$.jsx)(Jn,{className:`h-4.5 w-4.5`})}),(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:Z(`engine.studio.landing.title`,t)})]}),(0,$.jsx)(`p`,{className:`mb-5 max-w-2xl text-xs leading-5 text-muted-foreground`,children:Z(`engine.studio.landing.description`,t)}),i&&(0,$.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 px-3 py-1.5 text-[11px] text-destructive`,children:i}),(0,$.jsx)(`h2`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.landing.mineHeading`,t)}),(0,$.jsxs)(`div`,{className:`mb-6 grid grid-cols-1 gap-2.5 sm:grid-cols-2 lg:grid-cols-3`,children:[n===null&&(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.loading`,t)}),n!==null&&l.length===0&&(0,$.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:Z(`engine.studio.landing.noneWritable`,t)}),l.map(e=>(0,$.jsxs)(`div`,{className:`rounded-lg border bg-background`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5 px-3 py-2.5`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>c(e.id),className:`flex min-w-0 flex-1 items-center gap-2.5 text-left`,children:[(0,$.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,$.jsx)(fn,{className:`h-4 w-4`})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-[13px] font-medium`,children:e.name}),(0,$.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:e.id})]})]}),(0,$.jsx)(`span`,{className:`rounded bg-emerald-400/15 px-1.5 py-0.5 text-[10px] text-emerald-600 dark:text-emerald-300`,children:Z(`engine.studio.pkg.writable`,t)}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d===e.id?f(null):S(e),title:Z(`engine.studio.landing.dupTitle`,t),className:`inline-flex items-center gap-1 rounded-md border px-2 py-1 text-[10px] text-muted-foreground hover:bg-muted hover:text-foreground`,children:[(0,$.jsx)(jt,{className:`h-3 w-3`}),` `,Z(`engine.studio.landing.dup`,t)]})]}),d===e.id&&(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 border-t px-3 py-2.5`,children:[(0,$.jsx)(`input`,{autoFocus:!0,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{e.key===`Enter`&&C(),e.key===`Escape`&&f(null)},placeholder:Z(`engine.studio.landing.dupNamePlaceholder`,t),className:`h-7 w-full rounded-md border bg-background px-2 text-[11px] outline-none focus:ring-1 focus:ring-primary`}),(0,$.jsx)(jy,{value:g,onChange:_,onEnter:()=>void C(),onEscape:()=>f(null),placeholder:Z(`engine.studio.landing.dupIdPlaceholder`,t),locale:t,testId:`pkg-dup-id-input`}),b&&(0,$.jsx)(`p`,{className:`text-[10px] text-destructive`,children:b}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void C(),disabled:v||!m.trim()||!qc.test(g.trim()),className:`inline-flex flex-1 items-center justify-center gap-1 rounded-md bg-primary px-2 py-1 text-[11px] font-medium text-primary-foreground disabled:opacity-50`,children:[v?(0,$.jsx)(Y,{className:`h-3 w-3 animate-spin`}):(0,$.jsx)(jt,{className:`h-3 w-3`}),Z(`engine.studio.landing.dupGo`,t)]}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>f(null),className:`rounded-md border px-2 py-1 text-[11px] text-muted-foreground hover:bg-muted`,children:Z(`engine.studio.cancel`,t)})]})]})]},e.id)),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>s(!0),className:`flex items-center justify-center gap-1.5 rounded-lg border border-dashed px-3 py-2.5 text-xs text-muted-foreground hover:border-primary/50 hover:text-foreground`,children:[(0,$.jsx)(Ct,{className:`h-4 w-4`}),` `,Z(`engine.studio.pkg.new`,t)]})]}),(0,$.jsx)(Jc,{mode:`create`,open:o,onOpenChange:s,onSaved:e=>c(e.id)}),u.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h2`,{className:`mb-2 text-[11px] font-medium uppercase tracking-wide text-muted-foreground`,children:Z(`engine.studio.landing.installedHeading`,t)}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-2.5 sm:grid-cols-2 lg:grid-cols-3`,children:u.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>c(e.id),className:`flex items-center gap-2.5 rounded-lg border bg-muted/20 px-3 py-2.5 text-left hover:bg-muted/40`,children:[(0,$.jsx)(`span`,{className:`flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-muted text-muted-foreground`,children:(0,$.jsx)(fn,{className:`h-4 w-4`})}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-[13px]`,children:e.name}),(0,$.jsx)(`span`,{className:`block truncate font-mono text-[10px] text-muted-foreground`,children:e.id})]}),(0,$.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 rounded bg-amber-400/15 px-1.5 py-0.5 text-[10px] text-amber-600 dark:text-amber-300`,children:[(0,$.jsx)(cr,{className:`h-2.5 w-2.5`}),` `,Z(`engine.studio.pkg.readonly`,t)]})]},e.id))})]})]})}var Ny={type:`element:definition-list`,properties:{columns:2,items:[{term:`Status`,description:`Active`},{term:`Owner`,description:`Ada Lovelace`},{term:`Plan`,description:`Enterprise`},{term:`Renewal`,description:`2026-12-01`}]}},Py=()=>{let{modalHandler:e,modalElement:t}=La();return(0,$.jsxs)(`div`,{className:`space-y-4 p-6`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Action modal transport`}),(0,$.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`One `,(0,$.jsx)(`code`,{children:`onModal`}),` handler, four placements, arbitrary SchemaNode content.`]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(J,{"data-testid":`open-center`,onClick:()=>e({placement:`center`,size:`lg`,title:`Center modal`,content:Ny}),children:`Center`}),(0,$.jsx)(J,{"data-testid":`open-side`,variant:`outline`,onClick:()=>e({placement:`side`,title:`Side drawer`,content:Ny}),children:`Side drawer`}),(0,$.jsx)(J,{"data-testid":`open-bottom`,variant:`outline`,onClick:()=>e({placement:`bottom`,title:`Bottom sheet`,content:Ny}),children:`Bottom sheet`}),(0,$.jsx)(J,{"data-testid":`open-fullscreen`,variant:`outline`,onClick:()=>e({placement:`fullscreen`,title:`Fullscreen`,content:Ny}),children:`Fullscreen`})]}),t]})},Fy=()=>{let[e,t]=Q.useState([{},{}]);return(0,$.jsxs)(`div`,{className:`mx-auto max-w-3xl space-y-4 p-6`,children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Line-item grid with a lookup cell`}),(0,$.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`The `,(0,$.jsx)(`code`,{children:`Account`}),` column is a real lookup picker bound to live `,(0,$.jsx)(`code`,{children:`showcase_account`}),`.`]}),(0,$.jsx)(pr,{value:e,onChange:t,field:{columns:[{name:`account`,label:`Account`,type:`lookup`,reference:`showcase_account`,displayField:`name`},{name:`note`,label:`Note`,type:`text`},{name:`amount`,label:`Amount`,type:`currency`}],total_field:`amount`}}),(0,$.jsx)(`pre`,{className:`rounded bg-muted p-3 text-xs`,"data-testid":`rows-json`,children:JSON.stringify(e)})]})},Iy=[{id:`1`,name:`hotcrm-fix-verify`,org:`hotcrm-fix-verify`,type:`production`,status:`running`,host:`os-05ayzz.objectos.app`},{id:`2`,name:`Objectstack`,org:`Objectstack`,type:`production`,status:`running`,host:`os-0zpadn.objectos.app`},{id:`3`,name:`hotcrm`,org:`JIANGUO Zhuang's Workspace`,type:`production`,status:`running`,host:`os-48f50e60.objectos.app`}],Ly=[{name:`open`,label:`Open`,variant:`primary`},{name:`upgrade`,label:`Upgrade Plan`,variant:`primary`},{name:`rename`,label:`Rename`,variant:`secondary`},{name:`archive`,label:`Archive`,variant:`secondary`}],Ry=[{field:`name`,label:`名称`},{field:`org`,label:`所属组织`},{field:`type`,label:`类型`},{field:`status`,label:`状态`},{field:`host`,label:`公开主机名`}];function zy({maxInlineRowActions:e}){let t={type:`object-grid`,objectName:`showcase_environment`,columns:Ry,data:{provider:`value`,items:Iy},rowActionDefs:Ly,...e==null?{}:{maxInlineRowActions:e}};return(0,$.jsx)(je,{children:(0,$.jsx)(Bs,{schema:t})})}var By=()=>(0,$.jsxs)(`div`,{className:`mx-auto max-w-none space-y-8 p-6`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Row-action overflow (default)`}),(0,$.jsxs)(`p`,{className:`mb-3 text-sm text-muted-foreground`,children:[`Two `,(0,$.jsx)(`code`,{children:`variant:'primary'`}),` row actions. Only `,(0,$.jsx)(`strong`,{children:`Open`}),` stays inline;`,(0,$.jsx)(`strong`,{children:` Upgrade Plan`}),` + the secondaries fold into the `,(0,$.jsx)(`code`,{children:`⋮`}),` menu. The actions column hugs its content and must never clip the inline button.`]}),(0,$.jsx)(`div`,{className:`rounded-lg border`,"data-testid":`grid-default`,children:(0,$.jsx)(zy,{})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Row-action overflow (maxInlineRowActions: 2)`}),(0,$.jsxs)(`p`,{className:`mb-3 text-sm text-muted-foreground`,children:[`Same data, author opts into two inline primaries — both `,(0,$.jsx)(`strong`,{children:`Open`}),` and`,(0,$.jsx)(`strong`,{children:` Upgrade Plan`}),` render inline and the column grows to fit them.`]}),(0,$.jsx)(`div`,{className:`rounded-lg border`,"data-testid":`grid-wide`,children:(0,$.jsx)(zy,{maxInlineRowActions:2})})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Dev · Row-action sticky-right (narrow / horizontal scroll)`}),(0,$.jsxs)(`p`,{className:`mb-3 text-sm text-muted-foreground`,children:[`A deliberately narrow container so the table scrolls horizontally. The`,(0,$.jsx)(`strong`,{children:` 操作`}),` column stays pinned to the right edge (always reachable), while the first `,(0,$.jsx)(`strong`,{children:`名称`}),` column stays frozen on the left. Scroll the grid sideways to check both edges hold.`]}),(0,$.jsx)(`div`,{className:`max-w-md overflow-hidden rounded-lg border`,"data-testid":`grid-scroll`,children:(0,$.jsx)(zy,{})})]})]}),Vy=4,Hy=1e3;function Uy({endpoint:e,children:t}){let[n,r]=(0,Q.useState)({});return(0,Q.useEffect)(()=>{let t=!1;return(async()=>{for(let n=0;n<=Vy;n++)try{let n=await We(e,{credentials:`include`,headers:{Accept:`application/json`}});if(n.authenticated!==!1&&et(n.locale),t)return;r({currency:n.currency??void 0,locale:n.locale??void 0});return}catch(e){if(!Ke(e)||n===Vy)return;let r=e instanceof Ne?e.retryAfterMs:void 0;if(await Ie(He(n,Hy,r)),t)return}})(),()=>{t=!0}},[e]),(0,$.jsx)(rt,{value:n,children:t})}var Wy=(0,Q.lazy)(()=>t(()=>import(`./SystemHubPage-CVZVag1e.js`).then(e=>({default:e.SystemHubPage})),__vite__mapDeps([0]),import.meta.url)),Gy=(0,Q.lazy)(()=>t(()=>import(`./AppManagementPage-BJktnoa5.js`).then(e=>({default:e.AppManagementPage})),__vite__mapDeps([0]),import.meta.url)),Ky=(0,Q.lazy)(()=>t(()=>import(`./ProfilePage-DEr5iZVB.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url)),qy=(0,Q.lazy)(()=>t(()=>import(`./ApprovalsInboxPage-DlnxY-uy.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url)),Jy=(0,Q.lazy)(()=>t(()=>import(`./AiPendingActionsPage-7gZ8zlOy.js`).then(e=>({default:e.AiPendingActionsPage})),__vite__mapDeps([0]),import.meta.url)),Yy=(0,Q.lazy)(()=>t(()=>import(`./AuditLogPage-DIJPRjji.js`).then(e=>({default:e.AuditLogPage})),__vite__mapDeps([0]),import.meta.url)),Xy=(0,Q.lazy)(()=>t(()=>import(`./SettingsHub-BGLR_gS7.js`).then(e=>({default:e.SettingsHub})),__vite__mapDeps([0]),import.meta.url)),Zy=(0,Q.lazy)(()=>t(()=>import(`./SettingsView-Bq-7Zkzs.js`).then(e=>({default:e.SettingsView})),__vite__mapDeps([0]),import.meta.url)),Qy=(0,Q.lazy)(()=>t(()=>import(`./DeveloperHubPage-BRyNdrCJ.js`).then(e=>({default:e.DeveloperHubPage})),__vite__mapDeps([0]),import.meta.url)),$y=(0,Q.lazy)(()=>t(()=>import(`./ApiConsolePage-DUF0ysH7.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),eb=(0,Q.lazy)(()=>t(()=>import(`./FlowRunsPage-B6ustUgi.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),tb=(0,Q.lazy)(()=>t(()=>import(`./PublicFormsPage-CBcKQbNl.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url)),nb=(0,Q.lazy)(()=>t(()=>import(`./IntegrationsPage-chOxmiyU.js`).then(e=>({default:e.IntegrationsPage})),__vite__mapDeps([0]),import.meta.url)),rb=(0,Q.lazy)(()=>t(()=>import(`./DocPage-Bx8ZXCYt.js`),__vite__mapDeps([0]),import.meta.url)),ib=(0,Q.lazy)(()=>t(()=>import(`./AppDocsIndex-CP_AVG4X.js`),__vite__mapDeps([0]),import.meta.url)),ab=(0,Q.lazy)(()=>t(()=>import(`./DocsSlug-Cb_NMM1k.js`),__vite__mapDeps([0]),import.meta.url)),ob=(0,Q.lazy)(()=>t(()=>import(`./DocsLayout-BNsSvaz2.js`),__vite__mapDeps([0]),import.meta.url));function sb(){let{objectName:e}=c(),t=o().pathname.replace(/\/(system\/)?objects(\/.*)?$/,``),n=e?`${t}/metadata/object/${e}`:`${t}/metadata/object`;return(0,$.jsx)(h,{to:n,replace:!0})}function cb(){let{metadataType:e,itemName:t}=c(),n=`${o().pathname.replace(/\/(system\/)?metadata(\/.*)?$/,``)}/metadata`,r=e?t?`${n}/${encodeURIComponent(e)}/${t}`:`${n}/${encodeURIComponent(e)}`:n;return(0,$.jsx)(h,{to:r,replace:!0})}function lb({objectName:e}){let t=o().pathname.replace(/\/system\/[^/]+\/?$/,``);return(0,$.jsx)(h,{to:`${t}/${e}`,replace:!0})}var ub=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(u,{path:`system`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(Wy,{})})}),(0,$.jsx)(u,{path:`system/apps`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(Gy,{})})}),(0,$.jsx)(u,{path:`system/profile`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(Ky,{})})}),(0,$.jsx)(u,{path:`system/approvals`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(qy,{})})}),(0,$.jsx)(u,{path:`system/ai-approvals`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(Jy,{})})}),(0,$.jsx)(u,{path:`system/audit-log`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(Yy,{})})}),(0,$.jsx)(u,{path:`system/settings`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(Xy,{})})}),(0,$.jsx)(u,{path:`system/settings/:namespace`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(Zy,{})})}),(0,$.jsx)(u,{path:`developer`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(Qy,{})})}),(0,$.jsx)(u,{path:`developer/api-console`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)($y,{})})}),(0,$.jsx)(u,{path:`developer/flow-runs`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(eb,{})})}),(0,$.jsx)(u,{path:`developer/public-forms`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(tb,{})})}),(0,$.jsx)(u,{path:`developer/integrations`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(nb,{})})}),(0,$.jsxs)(u,{path:`docs`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(ob,{})}),children:[(0,$.jsx)(u,{index:!0,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(ib,{})})}),(0,$.jsx)(u,{path:`:slug`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(ab,{})})}),(0,$.jsx)(u,{path:`:slug/:name`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(rb,{})})})]}),(0,$.jsx)(u,{path:`system/objects`,element:(0,$.jsx)(sb,{})}),(0,$.jsx)(u,{path:`system/objects/:objectName`,element:(0,$.jsx)(sb,{})}),(0,$.jsx)(u,{path:`system/metadata`,element:(0,$.jsx)(cb,{})}),(0,$.jsx)(u,{path:`system/metadata/:metadataType`,element:(0,$.jsx)(cb,{})}),(0,$.jsx)(u,{path:`system/metadata/:metadataType/:itemName`,element:(0,$.jsx)(cb,{})}),(0,$.jsx)(u,{path:`system/users`,element:(0,$.jsx)(lb,{objectName:`sys_user`})}),(0,$.jsx)(u,{path:`system/organizations`,element:(0,$.jsx)(lb,{objectName:`sys_organization`})}),(0,$.jsx)(u,{path:`system/roles`,element:(0,$.jsx)(lb,{objectName:`sys_position`})}),(0,$.jsx)(u,{path:`system/positions`,element:(0,$.jsx)(lb,{objectName:`sys_position`})}),(0,$.jsx)(u,{path:`system/permissions`,element:(0,$.jsx)(lb,{objectName:`sys_permission_set`})})]});function db(){let e=(0,Q.useMemo)(()=>Ui({baseUrl:``}),[``]),t=(0,Q.useMemo)(()=>b(),[]);return(0,$.jsx)(j,{endpoint:`/api/v1/auth/me/permissions`,fetcher:t,loadingFallback:(0,$.jsx)(uu,{}),errorFallback:(e,t)=>(0,$.jsx)(uu,{error:e.message,onRetry:t}),children:(0,$.jsx)(Uy,{endpoint:`/api/v1/auth/me/localization`,children:(0,$.jsx)(vt,{adapter:e,children:(0,$.jsx)(t_,{extraRoutes:ub,extraRoutesNoApp:ub})})})})}function fb(e){return e._packageId===`com.objectstack.setup`||e.name===`setup`}function pb(e){let t=(e??[]).filter(e=>!!e?.name),n=t.find(e=>e.isDefault===!0);if(n)return`/apps/${n.name}`;let r=t.filter(e=>e.active!==!1&&e.hidden!==!0);return r.length===1&&!fb(r[0])?`/apps/${r[0].name}`:`/home`}function mb(e){return e===void 0||e===`ready`}var hb=1500;function gb(){let{apps:e,loading:t,getTypeStatus:n,refresh:r}=be(),i=!t&&!mb(n?.(`app`)),a=(0,Q.useRef)(!1);return(0,Q.useEffect)(()=>{if(!i||a.current)return;a.current=!0;let e=setTimeout(()=>{r?.(`app`)},hb);return()=>clearTimeout(e)},[i,r]),t||i?(0,$.jsx)(xu,{}):(0,$.jsx)(du,{to:pb(e),replace:!0})}function _b(){let e=o(),t=e.pathname+e.search,n=t&&t!==`/`?`?redirect=${encodeURIComponent(t)}`:``;return(0,$.jsx)(du,{to:`/login${n}`,replace:!0})}function vb({children:e,requireOrganization:t=!0}){return(0,$.jsx)(D,{fallback:(0,$.jsx)(_b,{}),loadingFallback:(0,$.jsx)(xu,{}),children:(0,$.jsx)(Tu,{children:t?(0,$.jsx)(ku,{children:e}):e})})}function yb({children:e,redirectTo:t=`/home`}){let n=el();return n.status===`pending`?(0,$.jsx)(xu,{}):n.status===`failed`?(0,$.jsx)(uu,{error:n.error.message,onRetry:n.retry}):tl(n.systemPermissions)?(0,$.jsx)($.Fragment,{children:e}):(0,$.jsx)(h,{to:t,replace:!0})}function bb(){return(0,$.jsx)(vb,{children:(0,$.jsx)(yb,{children:(0,$.jsx)(i,{})})})}function xb(){return(0,$.jsxs)(`div`,{className:`flex min-h-screen flex-col bg-background text-foreground`,children:[(0,$.jsx)(`header`,{className:`flex shrink-0 items-center border-b px-3 py-2`,children:(0,$.jsx)(n,{to:`/home`,title:`返回主页`,className:`inline-flex items-center gap-1.5 rounded-md px-1.5 py-0.5 text-[13px] font-semibold hover:bg-muted`,children:us()})}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:(0,$.jsx)(My,{})})]})}var Sb=(0,$.jsxs)(u,{path:`/studio`,element:(0,$.jsx)(bb,{}),children:[(0,$.jsx)(u,{index:!0,element:(0,$.jsx)(xb,{})}),(0,$.jsx)(u,{path:`:packageId`,element:(0,$.jsx)(h,{to:`data`,replace:!0})}),(0,$.jsx)(u,{path:`:packageId/:tab`,element:(0,$.jsx)(by,{})})]}),Cb=`/api/v1/auth`;function wb(e,t){return e===`fresh`?`first-run`:t.isLoading?`pending`:t.isAuthenticated?`settings`:e===`unknown`?`pending`:`settings`}function Tb(e){let[t,n]=(0,Q.useState)(`unknown`);return(0,Q.useEffect)(()=>{if(!e)return;let t=!1;return(async()=>{try{let e=await fetch(`${Cb}/bootstrap-status`,{credentials:`include`}),r=e.ok?await e.json().catch(()=>({})):{};t||n(r.hasOwner===!0?`bootstrapped`:`fresh`)}catch{t||n(`fresh`)}})(),()=>{t=!0}},[e]),t}function Eb(){let{isAuthenticated:e,isLoading:t}=C();return wb(Tb(!t&&!e),{isAuthenticated:e,isLoading:t})}function Db(e){return e.startsWith(`/_`)?e:`./`.replace(/\/$/,``)+(e.startsWith(`/`)?e:`/${e}`)}var Ob=`/api/v1/auth`,kb=`/`;function Ab(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}function jb(){let{t:e}=G(),t=p(),{user:n,signUp:r,refreshOrganizations:i,updateOrganization:a,createOrganization:o,switchOrganization:s}=C(),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(``),[f,m]=(0,Q.useState)(``),[h,g]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(null);return(0,Q.useEffect)(()=>{let e=!1;return(async()=>{try{let t=await fetch(`${Ob}/bootstrap-status`,{credentials:`include`}),n=t.ok?await t.json().catch(()=>({})):{};e||b(n.hasOwner===!0)}catch{e||b(!1)}})(),()=>{e=!0}},[]),(0,Q.useEffect)(()=>{y===!0&&!n&&t(`/login`,{replace:!0})},[y,n,t]),(0,Q.useEffect)(()=>{n&&!_&&window.location.assign(Db(kb))},[n,_]),y===null?(0,$.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted`,children:(0,$.jsx)(`div`,{className:`h-8 w-8 animate-spin rounded-full border-4 border-muted-foreground/20 border-t-primary`})}):(0,$.jsx)(`div`,{className:`flex min-h-svh w-full items-center justify-center bg-muted p-6`,children:(0,$.jsx)(`div`,{className:`flex w-full max-w-md flex-col gap-6`,children:(0,$.jsxs)(ln,{children:[(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(en,{children:e(`auth.setup.welcomeTitle`,{defaultValue:`Welcome to ObjectStack`})}),(0,$.jsx)(pt,{children:e(`auth.setup.description`,{defaultValue:`Create the first owner account to finish setting up this deployment.`})})]}),(0,$.jsx)(ei,{children:(0,$.jsxs)(`form`,{onSubmit:async t=>{t.preventDefault(),v(!0);try{await r(c,u,f);let e=h.trim();if(e)try{let t;for(let e=0;e<4&&!t?.id;e++)e>0&&await new Promise(e=>setTimeout(e,500)),t=(await i())?.[0];let n=Ab(e),r;t?.id?(await a(t.id,{name:e,...n?{slug:n}:{}}),r=t.id):r=(await o({name:e,slug:n||`org-${Date.now().toString(36)}`}))?.id,r&&await s(r).catch(()=>void 0)}catch(e){console.warn(`[setup] organization rename/create failed`,e)}window.location.assign(Db(kb))}catch(t){X.error(e(`auth.setup.failed`,{defaultValue:`Setup failed`}),{description:t.message})}finally{v(!1)}},className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(K,{htmlFor:`name`,children:e(`auth.setup.yourName`,{defaultValue:`Your name`})}),(0,$.jsx)(q,{id:`name`,autoComplete:`name`,required:!0,value:c,onChange:e=>l(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(K,{htmlFor:`orgName`,children:e(`auth.setup.orgName`,{defaultValue:`Organization name`})}),(0,$.jsx)(q,{id:`orgName`,required:!0,placeholder:e(`auth.setup.orgNamePlaceholder`,{defaultValue:`Acme Inc.`}),value:h,onChange:e=>g(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(K,{htmlFor:`email`,children:e(`auth.setup.emailLabel`,{defaultValue:`Email`})}),(0,$.jsx)(q,{id:`email`,type:`email`,placeholder:e(`auth.setup.emailPlaceholder`,{defaultValue:`name@example.com`}),autoComplete:`email`,required:!0,value:u,onChange:e=>d(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(K,{htmlFor:`password`,children:e(`auth.setup.passwordLabel`,{defaultValue:`Password`})}),(0,$.jsx)(q,{id:`password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,placeholder:e(`auth.setup.passwordHint`,{defaultValue:`Minimum 8 characters`}),value:f,onChange:e=>m(e.target.value)})]}),(0,$.jsx)(J,{type:`submit`,className:`mt-2 w-full`,disabled:_,children:_?e(`auth.setup.submitting`,{defaultValue:`Setting up…`}):e(`auth.setup.submit`,{defaultValue:`Create owner account`})})]})})]})})})}function Mb(){let e=Eb();return e===`pending`?(0,$.jsx)(xu,{}):e===`first-run`?(0,$.jsx)(jb,{}):(0,$.jsx)(vb,{requireOrganization:!1,children:(0,$.jsx)(Nu,{})})}var Nb=`/api/v1`,Pb=new Set([`simple`,`tabbed`,`wizard`,`split`,`drawer`,`modal`]),Fb=`recordId`;function Ib(e,t){if(e!==`internal`)return{kind:`create`};let n=t.get(Fb);if(n===null)return{kind:`create`};let r=n.trim();return r?{kind:`edit`,recordId:r,recordObject:(t.get(`recordObject`)??``).trim()||null}:{kind:`refuse`,reason:`This form was opened to edit a record (?${Fb}=), but no record id was supplied. Re-open it from the record, or drop the parameter to create a new one.`}}function Lb(e){let t=typeof e==`string`?parseInt(e,10):e;return t===1||t===2||t===3||t===4?t:2}function Rb(e){if(Array.isArray(e))return e.map(e=>{if(typeof e==`string`)return{value:e,label:e};if(e&&typeof e==`object`){let t=String(e.value??e.id??``);return{value:t,label:String(e.label??e.name??t)}}return{value:String(e),label:String(e)}})}function zb(e,t){let n=e.sections??e.groups??[],r=t?.fields??{};return n.map(e=>{let t=Lb(e.columns),n=[];for(let t of e.fields??[]){let e=typeof t==`string`?{field:t}:{...t},i=r[e.field]??{type:`text`};n.push({name:e.field,label:e.label??i.label??e.field,type:i.type??`text`,required:e.required??i.required??!1,readonly:e.readonly??!1,hidden:e.hidden??!1,visibleWhen:e.visibleWhen??e.visibleOn,rules:{visibleWhen:i.visibleWhen,readonlyWhen:i.readonlyWhen,requiredWhen:i.requiredWhen},placeholder:e.placeholder??i.placeholder,helpText:e.helpText??i.helpText,defaultValue:i.defaultValue,options:Rb(i.options),maxLength:e.maxLength??i.maxLength,colSpan:e.colSpan??1})}return{label:e.label,columns:t,collapsible:!!e.collapsible,collapsed:!!e.collapsed,visibleWhen:e.visibleWhen??e.visibleOn,fields:n}})}function Bb(e,t,n,r){return!e.hidden&&U(e.visibleWhen,t,!0,n??void 0,r,{context:`visibleWhen of field '${e.name}'`})}function Vb(e,t,n,r){return U(e.visibleWhen,t,!0,n??void 0,r,{context:`visibleWhen of section '${e.label??`(unlabelled)`}'`})}function Hb(e,t,n,r,i){let a=ue(e.rules??{},t,{required:e.required,readonly:e.readonly,serverOwnedValue:De({field:{defaultValue:e.defaultValue}},r)},n??void 0,i,`field '${e.name}'`),o=Bb(e,t,n,i);return{visible:a.visible&&o,readonly:a.readonly,required:a.required}}function Ub(e,t){return t||(e===`internal`?{kind:`created-record`}:{kind:`thank-you`})}function Wb(e){if(!e||typeof e!=`object`)return null;let t=e,n=typeof t.success==`boolean`&&`data`in t?t.data:t;return!n||typeof n!=`object`?null:n}function Gb(e){let t=Wb(e);if(!t)return null;let n=t.id;return typeof n==`string`?n===``?null:n:typeof n==`number`&&Number.isFinite(n)?String(n):null}function Kb(e,t,n){let r=Wb(e);if(!r)throw Error(`Could not read record "${n}" of ${t}: the server returned no record payload.`);let i=r.object;if(typeof i==`string`&&i&&i!==t)throw Error(`Record "${n}" belongs to ${i}, but this form edits ${t}. Refusing to open it — check the action that linked here.`);let a=r.record;if(!a||typeof a!=`object`||Array.isArray(a))throw Error(`Could not read record "${n}" of ${t}: the response carried no "record".`);return a}function qb(e,t,n){let r={};for(let i of e){i.defaultValue!==void 0&&!Oe(i.defaultValue)&&(r[i.name]=i.defaultValue),n&&Object.prototype.hasOwnProperty.call(n,i.name)&&(r[i.name]=n[i.name]);let e=t.get(`prefill_${i.name}`);e!==null&&(r[i.name]=e)}return r}function Jb(e,t,n){return n?da(e,{fields:Object.fromEntries(t.map(e=>[e.name,{defaultValue:e.defaultValue}]))}):e}async function Yb(e,t){return fetch(`${Nb}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers??{}},...t})}async function Xb(e){let t=await Yb(`/forms/${encodeURIComponent(e)}`);if(!t.ok){let e=await t.text().catch(()=>``);throw Error(`Failed to load form (${t.status}): ${e||t.statusText}`)}let n=await t.json();return{label:n.label??n.form?.label??n.object,object:n.object,form:n.form,objectSchema:n.objectSchema,record:null}}function Zb(e,t){let n=t,r=n?.item??n,i=r?.spec??r,a=i&&typeof i==`object`&&i.config&&typeof i.config==`object`&&(`viewKind`in i||`object`in i),o=i&&typeof i==`object`?i.viewKind:void 0;if(o&&o!==`form`)throw Error(`View "${e}" is a ${o} view, not a form view — check the action or link that targets it.`);let s=a?i.config:i;if(!o&&s&&typeof s==`object`&&typeof s.type==`string`&&!Pb.has(s.type))throw Error(`View "${e}" is a ${s.type} view, not a form view — check the action or link that targets it.`);return{label:(a?i.label:void 0)??s?.label??e,object:(a?i.object:void 0)??s?.data?.object??i?.object,form:s}}async function Qb(e,t,n){let r=await Yb(`/meta/view/${encodeURIComponent(e)}`);if(!r.ok)throw Error(`Form metadata not found: view/${e}`);let{label:i,object:a,form:o}=Zb(e,await r.json());if(!a)throw Error(`FormView "${e}" is missing an "object" target`);if(n&&n!==a)throw Error(`This form edits ${a}, but the link says record "${t}" belongs to ${n}. Refusing to open it — check the action that linked here.`);let s=null;try{let e=await Yb(`/meta/object/${encodeURIComponent(a)}`);if(e.ok){let t=await e.json(),n=t?.item??t,r=n?.spec??n;r?.fields&&typeof r.fields==`object`&&(s={name:r.name??a,label:r.label,fields:r.fields})}}catch{}let c=null;if(t){let e=await Yb(`/data/${encodeURIComponent(a)}/${encodeURIComponent(t)}`);if(!e.ok){let n=await e.text().catch(()=>``);throw Error(`Could not open record "${t}" of ${a} for editing (${e.status})${n?`: ${n}`:e.statusText?`: ${e.statusText}`:``}`)}c=Kb(await e.json(),a,t)}return{label:i,object:a,form:o,objectSchema:s,record:c}}async function $b(e,t){let n=await Yb(`/forms/${encodeURIComponent(e)}/submit`,{method:`POST`,body:JSON.stringify(t)});if(!n.ok){let e=await n.text().catch(()=>``);throw Error(`Submit failed (${n.status}): ${e||n.statusText}`)}return n.json().catch(()=>({}))}async function ex(e,t,n){let r=await Yb(n?`/data/${encodeURIComponent(e)}/${encodeURIComponent(n)}`:`/data/${encodeURIComponent(e)}`,{method:n?`PATCH`:`POST`,body:JSON.stringify(t)});if(!r.ok){let e=await r.text().catch(()=>``);throw Error(`${n?`Update`:`Create`} failed (${r.status}): ${e||r.statusText}`)}return r.json().catch(()=>({}))}var tx=`w-full rounded-md border border-input bg-background px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring disabled:opacity-50`;function nx({field:e,state:t,value:n,onChange:r}){let i={id:`f_${e.name}`,name:e.name,required:t.required,disabled:t.readonly,placeholder:e.placeholder,className:tx},a=n??``;switch(e.type){case`textarea`:case`paragraph`:case`long_text`:return(0,$.jsx)(`textarea`,{...i,rows:5,maxLength:e.maxLength,value:String(a),onChange:e=>r(e.target.value)});case`number`:case`integer`:case`decimal`:case`currency`:return(0,$.jsx)(`input`,{...i,type:`number`,value:a===``?``:Number(a),onChange:e=>r(e.target.value===``?null:Number(e.target.value))});case`email`:return(0,$.jsx)(`input`,{...i,type:`email`,value:String(a),onChange:e=>r(e.target.value)});case`url`:return(0,$.jsx)(`input`,{...i,type:`url`,value:String(a),onChange:e=>r(e.target.value)});case`password`:return(0,$.jsx)(`input`,{...i,type:`password`,value:String(a),onChange:e=>r(e.target.value)});case`date`:return(0,$.jsx)(`input`,{...i,type:`date`,value:String(a),onChange:e=>r(e.target.value)});case`time`:return(0,$.jsx)(`input`,{...i,type:`time`,value:String(a),onChange:e=>r(e.target.value)});case`datetime`:case`timestamp`:return(0,$.jsx)(`input`,{...i,type:`datetime-local`,value:String(a),onChange:e=>r(e.target.value)});case`boolean`:case`toggle`:case`checkbox`:return(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-2 text-sm`,children:[(0,$.jsx)(`input`,{id:i.id,name:i.name,type:`checkbox`,disabled:t.readonly,checked:!!a,onChange:e=>r(e.target.checked),className:`h-4 w-4 rounded border-input`}),(0,$.jsx)(`span`,{children:e.placeholder??e.label})]});case`select`:case`picklist`:case`enum`:{let n=e.options??[];return(0,$.jsxs)(`select`,{...i,value:String(a),onChange:e=>r(e.target.value),children:[(0,$.jsx)(`option`,{value:``,disabled:t.required,children:e.placeholder??`— Select —`}),n.map(e=>(0,$.jsx)(`option`,{value:e.value,children:e.label},e.value))]})}case`radio`:{let n=e.options??[];return(0,$.jsx)(`div`,{className:`flex flex-wrap gap-3`,children:n.map(n=>(0,$.jsxs)(`label`,{className:`inline-flex items-center gap-1.5 text-sm`,children:[(0,$.jsx)(`input`,{type:`radio`,name:e.name,value:n.value,checked:String(a)===n.value,disabled:t.readonly,onChange:()=>r(n.value)}),(0,$.jsx)(`span`,{children:n.label})]},n.value))})}default:return(0,$.jsx)(`input`,{...i,type:`text`,maxLength:e.maxLength,value:String(a),onChange:e=>r(e.target.value)})}}function rx({mode:e,recordPath:t}){let n=c(),[r]=s(),i=p(),a=(e===`public`?n.slug:n.name)??``,o=Ib(e,r),l=o.kind===`edit`?o.recordId:null,u=o.kind===`edit`?o.recordObject:null,d=o.kind!==`edit`,f=Ee(),[m,h]=(0,Q.useState)(!0),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(null),[b,x]=(0,Q.useState)({}),[S,C]=(0,Q.useState)(!1),w=`form-outcome:${(0,Q.useId)()}`,[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let t=!1;return h(!0),_(null),(o.kind===`refuse`?Promise.reject(Error(o.reason)):e===`public`?Xb(a):Qb(a,l,u)).then(e=>{if(t)return;y(e);let n=zb(e.form,e.objectSchema).flatMap(e=>e.fields);x(qb(n,r,e.record))}).catch(e=>{t||(y(null),_(e?.message??String(e)))}).finally(()=>{t||h(!1)}),()=>{t=!0}},[e,a,r]);let k=(0,Q.useMemo)(()=>v?zb(v.form,v.objectSchema):[],[v]),A=Ub(e,v?.form?.submitBehavior),j=D?.kind===`pending`?D.path:null,M=A.kind===`redirect`?A.delayMs??0:0;(0,Q.useEffect)(()=>{if(j===null)return;let e=setTimeout(()=>i(j),M);return()=>clearTimeout(e)},[j,M,i]);let ee=async n=>{if(n.preventDefault(),v){C(!0),_(null);try{let n=Jb(b,k.flatMap(e=>e.fields),d),o=e===`public`?await $b(a,n):await ex(v.object,n,l);switch(X.success(`Submitted`,{id:w}),A.kind){case`created-record`:{let e=l??Gb(o),n=e?t?.(v.object,e):null;if(n){i(n);break}E(!0);break}case`redirect`:{let e=Wb(o)?.record,t=l??Gb(o),r=nl(A.url,{...n,...e&&typeof e==`object`?e:{},...t?{id:t}:{}});if(!r.ok){X.error(r.refusal),O({kind:`refused`,refusal:r.refusal}),E(!0);break}O({kind:`pending`,path:r.path}),E(!0);break}case`continue`:{let e=k.flatMap(e=>e.fields);x(qb(e,r,v.record));break}default:E(!0)}}catch(e){let t=e?.message??String(e);_(t),X.error(t,{id:w})}finally{C(!1)}}};if(m)return(0,$.jsx)(`div`,{className:`flex min-h-[60vh] items-center justify-center`,children:(0,$.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Loading…`})});if(g&&!v)return(0,$.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,$.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:g})});if(!v)return null;if(T&&(A.kind===`thank-you`||A.kind===`created-record`)){let e=A.kind===`thank-you`?A.title:void 0,t=A.kind===`thank-you`?A.message:void 0;return(0,$.jsx)(`div`,{className:`mx-auto max-w-2xl p-6`,children:(0,$.jsxs)(`div`,{className:`rounded-md border bg-card p-6 text-center`,children:[(0,$.jsx)(`h2`,{className:`mb-2 text-lg font-semibold`,children:e??`Thanks!`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t??`Your submission has been received.`})]})})}return T&&A.kind===`redirect`?D?.kind===`refused`?(0,$.jsxs)(`div`,{className:`mx-auto max-w-2xl space-y-4 p-6`,children:[(0,$.jsxs)(`div`,{className:`rounded-md border bg-card p-6 text-center`,children:[(0,$.jsx)(`h2`,{className:`mb-2 text-lg font-semibold`,children:`Thanks!`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Your submission has been received.`})]}),(0,$.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-4 text-sm text-destructive`,children:D.refusal})]}):(0,$.jsx)(`div`,{className:`mx-auto max-w-2xl p-6 text-center text-sm text-muted-foreground`,children:`Redirecting…`}):(0,$.jsxs)(`div`,{className:`mx-auto max-w-2xl p-4 sm:p-6`,children:[(0,$.jsxs)(`header`,{className:`mb-6`,children:[(0,$.jsx)(`h1`,{className:`text-xl font-semibold`,children:v.label}),v.form?.label&&v.form.label!==v.label&&(0,$.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:v.form.label})]}),(0,$.jsxs)(`form`,{onSubmit:ee,className:`space-y-6`,children:[k.map((e,t)=>Vb(e,b,v.record,f)?(0,$.jsxs)(`section`,{className:`rounded-md border bg-card p-4 sm:p-5`,children:[e.label&&(0,$.jsx)(`h2`,{className:`mb-3 text-sm font-medium`,children:e.label}),(0,$.jsx)(`div`,{className:e.columns===1?`grid grid-cols-1 gap-4`:e.columns===2?`grid grid-cols-1 gap-4 sm:grid-cols-2`:e.columns===3?`grid grid-cols-1 gap-4 sm:grid-cols-3`:`grid grid-cols-1 gap-4 sm:grid-cols-4`,children:e.fields.map(e=>{let t=Hb(e,b,v.record,d,f);return t.visible?(0,$.jsxs)(`div`,{className:e.colSpan===2?`sm:col-span-2`:e.colSpan===3?`sm:col-span-3`:e.colSpan===4?`sm:col-span-4`:``,children:[(0,$.jsxs)(`label`,{htmlFor:`f_${e.name}`,className:`mb-1 block text-xs font-medium text-foreground`,children:[e.label,t.required&&(0,$.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`})]}),(0,$.jsx)(nx,{field:e,state:t,value:b[e.name],onChange:t=>x(n=>({...n,[e.name]:t}))}),e.helpText&&(0,$.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:e.helpText})]},e.name):null})})]},t):null),g&&(0,$.jsx)(`div`,{className:`rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:g}),(0,$.jsx)(`div`,{className:`flex justify-end gap-2`,children:(0,$.jsx)(`button`,{type:`submit`,disabled:S,className:`rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow-sm hover:bg-primary/90 disabled:opacity-50`,children:S?`Submitting…`:`Submit`})})]})]})}function ix(e,t,n,r){if(!n||!r)return null;let i=oo(e,t);return`/apps/${encodeURIComponent(i)}/${encodeURIComponent(n)}/record/${encodeURIComponent(r)}`}function ax(){let{apps:e}=be(),{currentAppName:t}=Ra(),{user:n}=C(),r=(0,Q.useMemo)(()=>(n,r)=>ix(e,t,n,r),[e,t]),i=(0,Q.useMemo)(()=>Ea(n),[n]);return(0,$.jsx)(Ta,{user:i,children:(0,$.jsx)(u_,{userId:n?.id,children:(0,$.jsx)(rx,{mode:`internal`,recordPath:r})})})}function ox({enabled:e=!1,url:t=`/api/v1/dev/metadata-events`,debounceMs:n=400,reconnectDelayMs:r=2e3}){let i=(0,Q.useRef)(null);return(0,Q.useEffect)(()=>{if(!e||typeof window>`u`||typeof EventSource>`u`)return;let a=null,o=null,s=!1,c=!1,l=e=>{i.current&&clearTimeout(i.current),i.current=setTimeout(()=>{try{X.info(`Metadata changed (${e}) — reloading…`,{duration:800})}catch{}setTimeout(()=>{try{window.location.reload()}catch{}},150)},n)},u=e=>{try{let t=JSON.parse(e.data),n=t?.name?`${t.metadataType??`metadata`}:${t.name}`:`metadata`;l(n)}catch{l(`change`)}},d=e=>{let t=`rebuild`;try{t=JSON.parse(e.data)?.reason??t}catch{}l(t)},f=()=>{if(!s)try{a=new EventSource(t),a.addEventListener(`open`,()=>{c=!0}),a.addEventListener(`metadata-change`,u),a.addEventListener(`reload`,d),a.addEventListener(`error`,()=>{if(!s&&a?.readyState===EventSource.CLOSED){if(a=null,!c)return;o=setTimeout(f,r)}})}catch{if(!c)return;o=setTimeout(f,r)}};return f(),()=>{if(s=!0,o&&clearTimeout(o),i.current&&clearTimeout(i.current),a)try{a.close()}catch{}}},[e,t,n,r]),null}function sx(e){let t=e.data??e;return{record:t.record??{},link:t.link,redactedFields:t.redactFields}}function cx(){let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`}.VITE_SERVER_URL??``;return e?e.replace(/\/$/,``):typeof window<`u`?window.location.origin:``}function lx(){let{token:e}=c(),t=`${(0,Q.useMemo)(()=>cx(),[])}/api/v1`,[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(!0),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(``),[p,m]=(0,Q.useState)(null),h=(0,Q.useCallback)(async n=>{if(e){s(!0),a(null);try{let i=new URL(`${t}/share-links/${encodeURIComponent(e)}/resolve`);n&&i.searchParams.set(`password`,n);let o=await fetch(i.toString(),{headers:{Accept:`application/json`}});if(o.status===401){u(!0),a(n?`Wrong password.`:null),s(!1);return}if(o.status===404){a(`This link is invalid or no longer available.`),s(!1);return}if(o.status===410){a(`This link has expired or was revoked.`),s(!1);return}if(!o.ok){let e=await o.json().catch(()=>null);a(e?.error?.message??`Failed to load (HTTP ${o.status}).`),s(!1);return}r(sx(await o.json())),u(!1)}catch(e){a(e?.message??`Failed to load shared content.`)}finally{s(!1)}}},[t,e]);(0,Q.useEffect)(()=>{h()},[h]),(0,Q.useEffect)(()=>{if(!n||n.link.object_name!==`ai_conversations`)return;let e=`${t}/share-links/${encodeURIComponent(n.link.token)}/messages`;fetch(e,{headers:{Accept:`application/json`}}).then(e=>e.ok?e.json():null).then(e=>m(e?.data??[])).catch(()=>m([]))},[t,n]);let g=(0,Q.useMemo)(()=>p?Qf(sf(lf(p))):[],[p]);if(o)return(0,$.jsxs)(`div`,{className:`flex h-svh w-full items-center justify-center bg-background text-muted-foreground`,children:[(0,$.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading…`]});if(l)return(0,$.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-md flex-col items-center justify-center gap-4 px-4 text-center`,children:[(0,$.jsx)(jn,{className:`h-8 w-8 text-muted-foreground`}),(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Password required`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The owner protected this link with a password.`}),(0,$.jsxs)(`form`,{className:`flex w-full flex-col gap-2`,onSubmit:e=>{e.preventDefault(),h(d)},children:[(0,$.jsx)(K,{htmlFor:`share-pw`,className:`sr-only`,children:`Password`}),(0,$.jsx)(q,{id:`share-pw`,type:`password`,value:d,onChange:e=>f(e.target.value),autoFocus:!0,placeholder:`Enter password`}),i&&(0,$.jsx)(`p`,{className:`text-xs text-destructive`,children:i}),(0,$.jsx)(J,{type:`submit`,size:`sm`,children:`Continue`})]})]});if(i)return(0,$.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-md flex-col items-center justify-center gap-3 px-4 text-center`,children:[(0,$.jsx)(Ji,{className:`h-8 w-8 text-amber-500`}),(0,$.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Can't open this link`}),(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:i})]});if(!n)return null;if(n.link.object_name===`ai_conversations`){let e=n.record;return(0,$.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,$.jsxs)(`header`,{className:`sticky top-0 z-10 flex items-center gap-2 border-b bg-background px-4 py-3`,children:[(0,$.jsx)(Oi,{className:`h-5 w-5 text-muted-foreground`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h1`,{className:`truncate text-sm font-semibold`,children:e.title??`Shared conversation`}),(0,$.jsx)(`p`,{className:`truncate text-[11px] text-muted-foreground`,children:`Read-only · Shared via ObjectStack`})]}),(0,$.jsx)(hn,{variant:`outline`,className:`text-[10px] capitalize`,children:n.link.permission})]}),(0,$.jsx)(`main`,{className:`flex min-h-0 flex-1 flex-col`,children:p==null?(0,$.jsxs)(`div`,{className:`flex flex-1 items-center justify-center py-12 text-sm text-muted-foreground`,children:[(0,$.jsx)(Y,{className:`mr-2 h-4 w-4 animate-spin`}),`Loading messages…`]}):p.length===0?(0,$.jsx)(`p`,{className:`py-12 text-center text-sm text-muted-foreground`,children:`This conversation has no messages yet.`}):(0,$.jsx)(Ao,{readOnly:!0,surface:`plain`,messages:g,showAvatars:!0,maxHeight:`100%`,className:`flex-1`})}),(0,$.jsx)(`footer`,{className:`border-t bg-muted/30 px-4 py-2 text-center text-[11px] text-muted-foreground`,children:`Powered by ObjectStack`})]})}return(0,$.jsxs)(`div`,{className:`mx-auto flex h-svh max-w-3xl flex-col bg-background`,children:[(0,$.jsx)(`header`,{className:`border-b px-4 py-3`,children:(0,$.jsxs)(`h1`,{className:`text-sm font-semibold`,children:[`Shared `,n.link.object_name]})}),(0,$.jsxs)(`main`,{className:`flex-1 overflow-y-auto p-4`,children:[(0,$.jsx)(`pre`,{className:`overflow-x-auto rounded-md border bg-muted/30 p-3 text-[12px]`,children:JSON.stringify(n.record,null,2)}),n.redactedFields&&n.redactedFields.length>0&&(0,$.jsxs)(`p`,{className:`mt-2 text-[11px] text-muted-foreground`,children:[`Some fields are hidden by the owner: `,n.redactedFields.join(`, `)]})]})]})}function ux(e){let t=e.split(`:`)[0].toLowerCase();return/^cloud\./.test(t)}function dx(e){let t=e.split(`:`)[0].toLowerCase();return t===`localhost`||t===`127.0.0.1`||t===`[::1]`||t.endsWith(`.local`)}function fx(){return typeof window>`u`?null:window.location.host||null}function px(){let e=us(),t=is();return(0,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 select-none`,children:[(0,$.jsx)(`span`,{className:`inline-flex h-9 w-9 items-center justify-center rounded-xl bg-gradient-to-br from-indigo-500 to-indigo-600 text-white shadow-sm shadow-indigo-500/30 overflow-hidden`,children:t?(0,$.jsx)(`img`,{src:t,alt:e,className:`h-full w-full object-contain`}):(0,$.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`18`,height:`18`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,$.jsx)(`path`,{d:`M12 2 2 7l10 5 10-5-10-5Z`}),(0,$.jsx)(`path`,{d:`m2 17 10 5 10-5`}),(0,$.jsx)(`path`,{d:`m2 12 10 5 10-5`})]})}),(0,$.jsx)(`span`,{className:`text-lg font-semibold tracking-tight text-foreground`,children:e})]})}function mx({children:e,formWidth:t=`sm`}){let{t:n}=G(),r=t===`md`?`max-w-md`:`max-w-sm`,i=fx(),a=!!i&&!ux(i)&&!dx(i);return(0,Q.useEffect)(()=>{if(typeof document>`u`||!i)return;let e=document.title;return a&&(document.title=i),()=>{document.title=e}},[i,a]),(0,$.jsxs)(`div`,{className:`relative flex min-h-svh w-full items-center justify-center overflow-hidden bg-background p-6`,children:[(0,$.jsxs)(`div`,{"aria-hidden":!0,className:`pointer-events-none absolute inset-0 -z-10`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 opacity-[0.35] dark:opacity-[0.25] [mask-image:radial-gradient(ellipse_at_center,black,transparent_72%)] [-webkit-mask-image:radial-gradient(ellipse_at_center,black,transparent_72%)]`,style:{backgroundImage:`radial-gradient(hsl(var(--border)) 1px, transparent 1px)`,backgroundSize:`22px 22px`}}),(0,$.jsx)(`div`,{className:`absolute left-1/2 top-1/2 h-[34rem] w-[34rem] -translate-x-1/2 -translate-y-1/2 rounded-full bg-gradient-to-br from-indigo-500/10 to-indigo-600/10 blur-3xl dark:from-indigo-500/10 dark:to-indigo-600/10`})]}),(0,$.jsxs)(`div`,{className:qr(`flex w-full flex-col gap-5`,r),children:[(0,$.jsx)(px,{}),a?(0,$.jsx)(`div`,{className:`flex justify-center`,children:(0,$.jsx)(`span`,{className:`rounded-full border border-border/60 bg-background/60 px-2 py-0.5 font-mono text-[10px] uppercase tracking-wide text-muted-foreground`,title:n(`auth.shell.tenantHostHint`,{defaultValue:`You are signing in to this workspace`}),children:i})}):null,e]})]})}function hx(e){let t=`/api/v1/auth/oauth2/authorize${e}`,n=()=>window.location.assign(t);fetch(t,{credentials:`include`,redirect:`manual`,headers:{accept:`application/json`}}).then(async e=>{let t=await e.json().catch(()=>null),r=t?.url??t?.redirect_uri??t?.redirectURI;if(e.ok&&r){window.location.href=r;return}n()}).catch(n)}function gx(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}var _x=`os.console.devAdminHintDismissed`;function vx(e){return(0,$.jsx)(n,{to:e.href,className:e.className,children:e.children})}function yx(){let{t:e}=G(),[t]=s(),n=t.get(`redirect`),{user:r,isLoading:i,organizations:a,isOrganizationsLoading:o,activeOrganization:c,switchOrganization:l,getAuthConfig:u}=C(),[d,f]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(()=>{try{return window.localStorage.getItem(_x)===`1`}catch{return!1}}),_=()=>{g(!0);try{window.localStorage.setItem(_x,`1`)}catch{}},[v,y]=(0,Q.useState)(!1),b=(0,Q.useRef)(!1),[x,S]=(0,Q.useState)(!1);(0,Q.useLayoutEffect)(()=>{i||S(!0)},[i]);let w=(0,Q.useMemo)(()=>{if(typeof window>`u`)return null;let e=new URLSearchParams(window.location.search),t=e.get(`redirect_uri`);if(!e.has(`client_id`)||!t)return null;try{return new URL(t).host}catch{return null}},[]),T=(0,Q.useMemo)(()=>{let e=t.get(`error`);return e?{code:e,description:t.get(`error_description`)}:null},[]);if((0,Q.useEffect)(()=>{let e=!1;return u().then(t=>{if(e)return;f(t?.emailPassword?.disableSignUp===!0);let n=t?.devSeedAdmin;m(n&&typeof n.email==`string`?{email:n.email,password:typeof n.password==`string`?n.password:void 0}:null)}).catch(()=>{}),()=>{e=!0}},[u]),(0,Q.useEffect)(()=>{if(r){if(typeof window<`u`){let e=new URLSearchParams(window.location.search);if(e.has(`client_id`)&&e.has(`redirect_uri`)){b.current||(b.current=!0,hx(window.location.search));return}}if(!c){if(o||v)return;if(a.length===1){y(!0),l(a[0].id).catch(()=>void 0).finally(()=>y(!1));return}if(a.length===0){window.location.assign(Db(gx(n)?n:`/`));return}window.location.assign(Db(`/organizations`));return}v||window.location.assign(Db(gx(n)?n:`/`))}},[r,c,a,o,v,n,l]),i&&!x||r)return(0,$.jsx)(mx,{children:(0,$.jsxs)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:[(0,$.jsx)(`div`,{className:`size-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent`}),(0,$.jsx)(`span`,{children:e(`auth.login.signingIn`,{defaultValue:`Signing you in…`})})]})});let E=n?`/register?redirect=${encodeURIComponent(n)}`:`/register`;return(0,$.jsx)(mx,{formWidth:`md`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[T?(0,$.jsx)(A,{message:e(`auth.login.errors.oauthCallbackFailed`,{defaultValue:`Single sign-on could not be completed — the sign-in link expired or was already used. Please try again.`})+(T.description?` (${T.description})`:` (${T.code})`)}):null,w?(0,$.jsxs)(`div`,{role:`status`,className:`flex items-start gap-3 rounded-md border border-primary/30 bg-primary/5 px-4 py-3 text-sm text-foreground`,children:[(0,$.jsx)(`span`,{className:`mt-0.5 inline-block size-2 shrink-0 rounded-full bg-primary`}),(0,$.jsx)(`span`,{children:e(`auth.login.ssoHandoff`,{target:w,defaultValue:`Continue to ${w}`})})]}):null,p&&!h?(0,$.jsxs)(`div`,{role:`status`,"data-testid":`dev-admin-hint`,className:`flex items-start gap-3 rounded-md border border-amber-500/40 bg-amber-500/10 px-4 py-3 text-sm text-foreground`,children:[(0,$.jsx)(`span`,{className:`mt-0.5 inline-block size-2 shrink-0 rounded-full bg-amber-500`}),(0,$.jsxs)(`div`,{className:`flex-1`,children:[(0,$.jsx)(`div`,{className:`font-medium`,children:e(`auth.login.devAdminHint.title`,{defaultValue:`Development instance`})}),(0,$.jsxs)(`div`,{className:`text-muted-foreground`,children:[e(`auth.login.devAdminHint.body`,{defaultValue:`Sign in with the seeded dev admin:`}),` `,(0,$.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:p.email}),p.password?(0,$.jsxs)($.Fragment,{children:[` / `,(0,$.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:p.password})]}):null]})]}),(0,$.jsx)(`button`,{type:`button`,onClick:_,"aria-label":e(`auth.login.devAdminHint.dismiss`,{defaultValue:`Dismiss`}),className:`shrink-0 rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,$.jsx)(`svg`,{viewBox:`0 0 16 16`,"aria-hidden":`true`,className:`size-3.5 fill-current`,children:(0,$.jsx)(`path`,{d:`M3.72 3.72a.75.75 0 0 1 1.06 0L8 6.94l3.22-3.22a.75.75 0 1 1 1.06 1.06L9.06 8l3.22 3.22a.75.75 0 1 1-1.06 1.06L8 9.06l-3.22 3.22a.75.75 0 0 1-1.06-1.06L6.94 8 3.72 4.78a.75.75 0 0 1 0-1.06Z`})})})]}):null,(0,$.jsx)(ln,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,$.jsx)(bx,{registerUrl:d?void 0:E,redirect:n})})]})})}function bx({registerUrl:e,redirect:t}){let{t:n}=G(),r=p(),i=(0,Q.useRef)(``);return(0,Q.useEffect)(()=>{let e=e=>{let t=e.target;t?.id===`login-email`&&(i.current=t.value)};return document.addEventListener(`input`,e,!0),()=>document.removeEventListener(`input`,e,!0)},[]),(0,$.jsx)(S,{onError:e=>{let n=e.message||``,a=e.code,o=n.toLowerCase();if(a===`EMAIL_NOT_VERIFIED`||o.includes(`email`)&&(o.includes(`verif`)||o.includes(`not verified`))){let e=new URLSearchParams;i.current&&e.set(`email`,i.current),t&&e.set(`redirect`,t),r(`/verify-email-prompt?${e.toString()}`)}},title:n(`auth.login.title`,{defaultValue:`Sign in to your account`}),description:n(`auth.login.description`,{defaultValue:`Enter your email and password to continue`}),registerUrl:e,forgotPasswordUrl:`/forgot-password`,linkComponent:vx,errorMessages:{INVALID_EMAIL_OR_PASSWORD:n(`auth.login.errors.invalidCredentials`,{defaultValue:`Invalid email or password. Please try again.`}),EMAIL_NOT_VERIFIED:n(`auth.login.errors.emailNotVerified`,{defaultValue:`Please verify your email address before signing in.`})},labels:{emailLabel:n(`auth.login.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:n(`auth.login.emailPlaceholder`,{defaultValue:`name@example.com`}),emailOrPhoneLabel:n(`auth.login.emailOrPhoneLabel`,{defaultValue:`Email or phone number`}),emailOrPhonePlaceholder:n(`auth.login.emailOrPhonePlaceholder`,{defaultValue:`name@example.com or +1 555 000 0000`}),passwordLabel:n(`auth.login.passwordLabel`,{defaultValue:`Password`}),passwordPlaceholder:n(`auth.login.passwordPlaceholder`,{defaultValue:`Enter your password`}),forgotPasswordText:n(`auth.login.forgotPasswordText`,{defaultValue:`Forgot password?`}),submitButton:n(`auth.login.submitButton`,{defaultValue:`Sign In`}),submittingButton:n(`auth.login.submittingButton`,{defaultValue:`Signing in…`}),noAccountText:n(`auth.login.noAccountText`,{defaultValue:`Don't have an account?`}),signUpText:n(`auth.login.signUpText`,{defaultValue:`Sign up`}),phoneLabel:n(`auth.login.phoneLabel`,{defaultValue:`Phone number`}),phonePlaceholder:n(`auth.login.phonePlaceholder`,{defaultValue:`+1 555 000 0000`}),otpCodeLabel:n(`auth.login.otpCodeLabel`,{defaultValue:`Verification code`}),otpCodePlaceholder:n(`auth.login.otpCodePlaceholder`,{defaultValue:`6-digit code`}),sendOtpButton:n(`auth.login.sendOtpButton`,{defaultValue:`Get code`}),resendOtpCountdownText:n(`auth.login.resendOtpCountdownText`,{defaultValue:`Resend in {seconds}s`}),usePhoneOtpText:n(`auth.login.usePhoneOtpText`,{defaultValue:`Sign in with verification code`}),usePasswordSignInText:n(`auth.login.usePasswordSignInText`,{defaultValue:`Sign in with password instead`})}})}function xx(e){return!!e&&e.startsWith(`/`)&&!e.startsWith(`//`)}function Sx(e){return(0,$.jsx)(n,{to:e.href,className:e.className,children:e.children})}function Cx(){let{t:e}=G(),t=p(),[n]=s(),r=n.get(`redirect`),{user:i,isLoading:a,organizations:o,isOrganizationsLoading:c,activeOrganization:l,switchOrganization:u,getAuthConfig:d}=C(),[f,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),_=(0,Q.useRef)(!1),[v,y]=(0,Q.useState)(!1);if((0,Q.useLayoutEffect)(()=>{a||y(!0)},[a]),(0,Q.useEffect)(()=>{let e=!1;return d().then(n=>{if(e)return;let i=n?.emailPassword?.disableSignUp===!0;if(m(i),i){let e=r?`?redirect=${encodeURIComponent(r)}`:``;t(`/login${e}`,{replace:!0})}}).catch(()=>{e||m(!1)}),()=>{e=!0}},[d,t,r]),(0,Q.useEffect)(()=>{if(i){if(typeof window<`u`){let e=new URLSearchParams(window.location.search);if(e.has(`client_id`)&&e.has(`redirect_uri`)){_.current||(_.current=!0,hx(window.location.search));return}}if(!l){if(c||h)return;if(o.length===1){g(!0),u(o[0].id).catch(()=>void 0).finally(()=>g(!1));return}if(o.length===0){window.location.assign(Db(xx(r)?r:`/`));return}window.location.assign(Db(`/organizations`));return}h||window.location.assign(Db(xx(r)?r:`/`))}},[i,l,o,c,h,r,u]),f===null||a&&!v||i)return(0,$.jsx)(mx,{children:(0,$.jsx)(`div`,{className:`flex flex-col items-center gap-3 py-10 text-sm text-muted-foreground`,children:(0,$.jsx)(`div`,{className:`size-6 animate-spin rounded-full border-2 border-muted-foreground border-t-transparent`})})});let b=r?`/login?redirect=${encodeURIComponent(r)}`:`/login`;return(0,$.jsx)(mx,{formWidth:`md`,children:(0,$.jsx)(ln,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,$.jsx)(x,{title:e(`auth.register.title`,{defaultValue:`Create an account`}),description:e(`auth.register.description`,{defaultValue:`Create your account to start building.`}),loginUrl:b,linkComponent:Sx,errorMessages:{USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL:e(`auth.register.errors.userExists`,{defaultValue:`An account with this email already exists. Try signing in instead.`}),USER_ALREADY_EXISTS:e(`auth.register.errors.userExists`,{defaultValue:`An account with this email already exists. Try signing in instead.`})},onVerificationRequired:e=>{let n=new URLSearchParams;n.set(`email`,e),r&&n.set(`redirect`,r),t(`/verify-email-prompt?${n.toString()}`,{replace:!0})},labels:{nameLabel:e(`auth.register.nameLabel`,{defaultValue:`Name`}),namePlaceholder:e(`auth.register.namePlaceholder`,{defaultValue:`John Doe`}),emailLabel:e(`auth.register.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:e(`auth.register.emailPlaceholder`,{defaultValue:`name@example.com`}),passwordLabel:e(`auth.register.passwordLabel`,{defaultValue:`Password`}),passwordPlaceholder:e(`auth.register.passwordPlaceholder`,{defaultValue:`Create a password (min. 8 characters)`}),confirmPasswordLabel:e(`auth.register.confirmPasswordLabel`,{defaultValue:`Confirm Password`}),confirmPasswordPlaceholder:e(`auth.register.confirmPasswordPlaceholder`,{defaultValue:`Confirm your password`}),passwordMismatchError:e(`auth.register.passwordMismatchError`,{defaultValue:`Passwords do not match`}),passwordTooShortError:e(`auth.register.passwordTooShortError`,{defaultValue:`Password must be at least 8 characters`}),submitButton:e(`auth.register.submitButton`,{defaultValue:`Create Account`}),submittingButton:e(`auth.register.submittingButton`,{defaultValue:`Creating account…`}),hasAccountText:e(`auth.register.hasAccountText`,{defaultValue:`Already have an account?`}),signInText:e(`auth.register.signInText`,{defaultValue:`Sign in`})}})})})}function wx(e){return(0,$.jsx)(n,{to:e.href,className:e.className,children:e.children})}function Tx(){let{t:e}=G();return(0,$.jsx)(mx,{formWidth:`md`,children:(0,$.jsx)(ln,{className:`border-border/60 px-4 py-8 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:(0,$.jsx)(ee,{loginUrl:`/login`,linkComponent:wx,title:e(`auth.forgotPassword.title`,{defaultValue:`Reset your password`}),description:e(`auth.forgotPassword.description`,{defaultValue:`Enter your email address and we'll send you a link to reset your password`}),labels:{emailLabel:e(`auth.forgotPassword.emailLabel`,{defaultValue:`Email`}),emailPlaceholder:e(`auth.forgotPassword.emailPlaceholder`,{defaultValue:`name@example.com`}),submitButton:e(`auth.forgotPassword.submitButton`,{defaultValue:`Send Reset Link`}),submittingButton:e(`auth.forgotPassword.submittingButton`,{defaultValue:`Sending…`}),successTitle:e(`auth.forgotPassword.successTitle`,{defaultValue:`Check your email`}),successDescription:e(`auth.forgotPassword.successDescription`,{defaultValue:`We've sent a password reset link to {email}. Please check your inbox.`}),backToSignInText:e(`auth.forgotPassword.backToSignInText`,{defaultValue:`Back to sign in`}),phoneLabel:e(`auth.forgotPassword.phoneLabel`,{defaultValue:`Phone number`}),phonePlaceholder:e(`auth.forgotPassword.phonePlaceholder`,{defaultValue:`+1 555 000 0000`}),otpCodeLabel:e(`auth.forgotPassword.otpCodeLabel`,{defaultValue:`Verification code`}),otpCodePlaceholder:e(`auth.forgotPassword.otpCodePlaceholder`,{defaultValue:`6-digit code`}),sendOtpButton:e(`auth.forgotPassword.sendOtpButton`,{defaultValue:`Get code`}),resendOtpCountdownText:e(`auth.forgotPassword.resendOtpCountdownText`,{defaultValue:`Resend in {seconds}s`}),newPasswordLabel:e(`auth.forgotPassword.newPasswordLabel`,{defaultValue:`New password`}),newPasswordPlaceholder:e(`auth.forgotPassword.newPasswordPlaceholder`,{defaultValue:`Enter a new password`}),resetButton:e(`auth.forgotPassword.resetButton`,{defaultValue:`Reset Password`}),usePhoneResetText:e(`auth.forgotPassword.usePhoneResetText`,{defaultValue:`Reset via SMS code`}),useEmailResetText:e(`auth.forgotPassword.useEmailResetText`,{defaultValue:`Reset via email instead`}),phoneSuccessTitle:e(`auth.forgotPassword.phoneSuccessTitle`,{defaultValue:`Password reset`}),phoneSuccessDescription:e(`auth.forgotPassword.phoneSuccessDescription`,{defaultValue:`Your password has been reset. You can now sign in with your new password.`}),rememberPasswordText:e(`auth.forgotPassword.rememberPasswordText`,{defaultValue:`Remember your password?`}),signInText:e(`auth.forgotPassword.signInText`,{defaultValue:`Sign in`})}})})})}function Ex(){let{t:e}=G(),t=p(),[r]=s(),i=r.get(`token`),{resetPassword:a}=C(),[o,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(!1);return(0,$.jsx)(mx,{children:(0,$.jsxs)(ln,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(en,{className:`text-xl tracking-tight`,children:e(`auth.resetPassword.title`,{defaultValue:`Set a new password`})}),(0,$.jsx)(pt,{children:e(`auth.resetPassword.description`,{defaultValue:`Choose a password you have not used before.`})})]}),(0,$.jsx)(ei,{children:i?(0,$.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),o!==l){X.error(e(`auth.resetPassword.passwordsMismatch`,{defaultValue:`Passwords do not match`}));return}if(!i){X.error(e(`auth.resetPassword.missingToken`,{defaultValue:`Reset link is missing or expired`}));return}f(!0);try{await a(i,o),X.success(e(`auth.resetPassword.success`,{defaultValue:`Password updated`})),t(`/login`)}catch(t){X.error(e(`auth.resetPassword.failed`,{defaultValue:`Reset failed`}),{description:t.message})}finally{f(!1)}},className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(K,{htmlFor:`new-password`,children:e(`auth.resetPassword.newPassword`,{defaultValue:`New password`})}),(0,$.jsx)(q,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:o,onChange:e=>c(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(K,{htmlFor:`confirm-password`,children:e(`auth.resetPassword.confirmPassword`,{defaultValue:`Confirm password`})}),(0,$.jsx)(q,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:l,onChange:e=>u(e.target.value)})]}),(0,$.jsx)(J,{type:`submit`,className:`w-full`,disabled:d,children:d?e(`auth.resetPassword.submitting`,{defaultValue:`Updating…`}):e(`auth.resetPassword.submit`,{defaultValue:`Update password`})})]}):(0,$.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.resetPassword.invalidToken`,{defaultValue:`This reset link is invalid or has expired.`}),` `,(0,$.jsx)(n,{to:`/forgot-password`,className:`font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.resetPassword.requestNewLink`,{defaultValue:`Request a new link`})})]})})]})})}function Dx(e){return e&&e.startsWith(`/`)&&!e.startsWith(`//`)?e:`/`}function Ox(){let{t:e}=G(),t=p(),[r]=s(),i=Dx(r.get(`next`)),{user:a,isLoading:o,setInitialPassword:c}=C(),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(!1);return(0,$.jsx)(mx,{children:(0,$.jsxs)(ln,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(en,{className:`text-xl tracking-tight`,children:e(`auth.setPassword.title`)}),(0,$.jsx)(pt,{children:e(`auth.setPassword.description`)})]}),(0,$.jsx)(ei,{children:!o&&!a?(0,$.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.setPassword.noSession`),` `,(0,$.jsx)(n,{to:`/login`,className:`font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.setPassword.backToSignIn`)})]}):(0,$.jsxs)(`form`,{onSubmit:async n=>{if(n.preventDefault(),l!==d){X.error(e(`auth.setPassword.passwordsMismatch`));return}h(!0);try{await c(l),X.success(e(`auth.setPassword.success`)),t(i)}catch(t){X.error(e(`auth.setPassword.failed`),{description:t.message})}finally{h(!1)}},className:`flex flex-col gap-4`,children:[a?.email?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(K,{htmlFor:`set-password-email`,children:e(`auth.setPassword.email`)}),(0,$.jsx)(q,{id:`set-password-email`,type:`email`,autoComplete:`username`,value:a.email,disabled:!0,className:`bg-muted text-muted-foreground`})]}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(K,{htmlFor:`new-password`,children:e(`auth.setPassword.newPassword`)}),(0,$.jsx)(q,{id:`new-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:l,onChange:e=>u(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsx)(K,{htmlFor:`confirm-password`,children:e(`auth.setPassword.confirmPassword`)}),(0,$.jsx)(q,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,required:!0,minLength:8,value:d,onChange:e=>f(e.target.value)})]}),(0,$.jsx)(J,{type:`submit`,className:`w-full`,disabled:m,children:e(m?`auth.setPassword.submitting`:`auth.setPassword.submit`)})]})})]})})}var kx=`/api/v1/auth`;function Ax(){let{t:e}=G(),[t]=s(),r=t.get(`token`),[i,a]=(0,Q.useState)(`loading`),[o,c]=(0,Q.useState)(``);return(0,Q.useEffect)(()=>{if(!r){a(`error`),c(e(`auth.verifyEmail.missingToken`,{defaultValue:`Verification link is missing a token.`}));return}let t=!1;return(async()=>{try{let e=await fetch(`${kx}/verify-email`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({token:r})});if(!e.ok){let t=await e.json().catch(()=>({}));throw Error(t?.message||`Verification failed: ${e.status}`)}t||a(`success`)}catch(n){t||(a(`error`),c(n.message||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})))}})(),()=>{t=!0}},[r,e]),(0,$.jsx)(mx,{children:(0,$.jsxs)(ln,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[i===`loading`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(en,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.verifyingTitle`,{defaultValue:`Verifying…`})}),(0,$.jsx)(pt,{children:e(`auth.verifyEmail.verifyingDescription`,{defaultValue:`Hang tight while we confirm your email.`})})]}),(0,$.jsx)(ei,{className:`flex justify-center py-6`,children:(0,$.jsx)(`div`,{className:`h-10 w-10 animate-spin rounded-full border-4 border-muted border-t-primary`})})]}),i===`success`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-2 flex size-12 items-center justify-center rounded-full bg-emerald-500/10 text-emerald-500 ring-1 ring-emerald-500/30`,children:(0,$.jsx)(Gr,{className:`size-6`})}),(0,$.jsx)(en,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.successTitle`,{defaultValue:`Email verified`})}),(0,$.jsx)(pt,{children:e(`auth.verifyEmail.successDescription`,{defaultValue:`Your email is confirmed. You can now sign in.`})})]}),(0,$.jsx)(ei,{className:`text-center`,children:(0,$.jsx)(n,{to:`/login`,className:`text-sm font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.verifyEmail.signInLink`,{defaultValue:`Go to sign in`})})})]}),i===`error`&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-2 flex size-12 items-center justify-center rounded-full bg-destructive/10 text-destructive ring-1 ring-destructive/30`,children:(0,$.jsx)(tr,{className:`size-6`})}),(0,$.jsx)(en,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.errorTitle`,{defaultValue:`Verification failed`})}),(0,$.jsx)(pt,{children:o||e(`auth.verifyEmail.errorDescription`,{defaultValue:`Verification failed. Please request a new link.`})})]}),(0,$.jsx)(ei,{className:`text-center`,children:(0,$.jsx)(n,{to:`/login`,className:`text-sm font-medium text-primary underline-offset-4 hover:underline`,children:e(`auth.verifyEmail.backToSignIn`,{defaultValue:`Back to sign in`})})})]})]})})}function jx(){let{t:e}=G(),t=p(),[n]=s(),r=n.get(`email`)??``,i=n.get(`redirect`)??``,{sendVerificationEmail:a}=C(),[o,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)(!1),[d,f]=(0,Q.useState)(null);return(0,$.jsx)(mx,{children:(0,$.jsxs)(ln,{className:`border-border/60 shadow-sm shadow-primary/5 backdrop-blur supports-[backdrop-filter]:bg-card/95`,children:[(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-4 flex size-16 items-center justify-center rounded-full bg-primary/10`,children:(0,$.jsx)(Vr,{className:`size-8 text-primary`})}),(0,$.jsx)(en,{className:`text-xl tracking-tight`,children:e(`auth.verifyEmail.title`,{defaultValue:`Verify your email address`})}),(0,$.jsx)(pt,{children:e(`auth.verifyEmail.description`,{defaultValue:`We sent a verification link to your email address. Please click the link to verify your account.`})})]}),(0,$.jsx)(ei,{children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[r?(0,$.jsxs)(`p`,{className:`text-center text-sm text-muted-foreground`,children:[e(`auth.verifyEmail.sentTo`,{defaultValue:`Sent to:`}),` `,(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:r})]}):null,d?(0,$.jsxs)(`div`,{role:`alert`,className:`rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-sm text-destructive`,children:[(0,$.jsx)(`p`,{className:`font-medium`,children:e(`auth.verifyEmail.resendFailed`,{defaultValue:`Cannot resend verification email`})}),(0,$.jsx)(`p`,{className:`mt-1 text-destructive/90`,children:d})]}):null,(0,$.jsx)(J,{onClick:async()=>{if(!r){X.error(e(`auth.verifyEmail.resendFailed`,{defaultValue:`Cannot resend verification email`}),{description:e(`auth.verifyEmail.emailMissing`,{defaultValue:`Email address is missing`})});return}c(!0),f(null);try{await a(r,i||`/`),u(!0),X.success(e(`auth.verifyEmail.resentSuccess`,{defaultValue:`Verification email sent!`}),{description:e(`auth.verifyEmail.resentDescription`,{defaultValue:`Please check your inbox and click the verification link.`})})}catch(t){let n=t?.message?.trim()||e(`auth.verifyEmail.resendUnavailable`,{defaultValue:`Email delivery may not be configured for this environment. Contact support if this persists.`});u(!1),f(n),X.error(e(`auth.verifyEmail.resendFailed`,{defaultValue:`Cannot resend verification email`}),{description:n})}finally{c(!1)}},disabled:o||l,className:`w-full`,variant:l?`outline`:`default`,children:o?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(zi,{className:`mr-2 size-4 animate-spin`}),e(`auth.verifyEmail.resending`,{defaultValue:`Sending…`})]}):l?e(`auth.verifyEmail.resent`,{defaultValue:`Email sent! Check your inbox`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(zi,{className:`mr-2 size-4`}),e(`auth.verifyEmail.resendButton`,{defaultValue:`Resend verification email`})]})}),(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`div`,{className:`absolute inset-0 flex items-center`,children:(0,$.jsx)(`span`,{className:`w-full border-t`})}),(0,$.jsx)(`div`,{className:`relative flex justify-center text-xs uppercase`,children:(0,$.jsx)(`span`,{className:`bg-card px-2 text-muted-foreground`,children:e(`auth.verifyEmail.or`,{defaultValue:`Or`})})})]}),(0,$.jsx)(J,{onClick:()=>{let e=i?`?redirect=${encodeURIComponent(i)}`:``;t(`/login${e}`)},variant:`ghost`,className:`w-full`,children:e(`auth.verifyEmail.backToLogin`,{defaultValue:`Back to login`})}),(0,$.jsx)(`p`,{className:`text-center text-xs text-muted-foreground`,children:e(`auth.verifyEmail.checkSpam`,{defaultValue:`Didn't receive the email? Check your spam folder or contact support.`})})]})})]})})}var Mx=`/api/v1/auth`;function Nx(){let{t:e}=G(),t=p(),{user:n,isLoading:r}=C(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null),c=typeof window<`u`?window.location.search:``,l=c.startsWith(`?`)?c.slice(1):c,u=new URLSearchParams(l),d=u.get(`client_id`)??void 0,f=u.get(`scope`)??``;(0,Q.useEffect)(()=>{if(!r&&!n){let e=window.location.pathname+window.location.search;t(`/login?redirect=${encodeURIComponent(e)}`,{replace:!0})}},[n,r,t]),(0,Q.useEffect)(()=>{if(!d)return;let e=!1;return fetch(`${Mx}/oauth2/applications/${encodeURIComponent(d)}/public`,{credentials:`include`}).then(async t=>{if(!t.ok)return;let n=await t.json().catch(()=>({}));if(e)return;let r=n?.data??n;s(r)}).catch(()=>{}),()=>{e=!0}},[d]);let m=f.split(/\s+/).filter(Boolean),h=async t=>{a(!0);try{let n=await fetch(`${Mx}/oauth2/consent`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({accept:t,oauth_query:l})}),r=await n.json().catch(()=>({}));if(!n.ok)throw Error(r?.message||`Consent failed: ${n.status}`);let i=r.redirect_uri??r.redirectURI??r.url;if(i){window.location.href=i;return}let a=t?e(`oauth.consent.granted`,{defaultValue:`Access granted`}):e(`oauth.consent.denied`,{defaultValue:`Access denied`});X(a,{description:e(`oauth.consent.noRedirect`,{defaultValue:`No redirect URL returned by the server.`})})}catch(t){X.error(e(`oauth.consent.failed`,{defaultValue:`Consent failed`}),{description:t.message})}finally{a(!1)}},g=o?.name??o?.client_name??d??e(`oauth.consent.unknownApp`,{defaultValue:`an application`});return(0,$.jsx)(`div`,{className:`flex min-h-svh w-full flex-1 items-center justify-center bg-background px-4`,children:(0,$.jsxs)(ln,{className:`w-full max-w-md`,children:[(0,$.jsxs)(Yr,{className:`items-center text-center`,children:[(0,$.jsx)(`div`,{className:`mb-3 rounded-full border bg-muted p-3`,children:o?.icon||o?.logo_uri?(0,$.jsx)(`img`,{src:o.icon||o.logo_uri,alt:``,className:`h-8 w-8 rounded`,onError:e=>{e.currentTarget.style.display=`none`}}):(0,$.jsx)(an,{className:`h-7 w-7 text-muted-foreground`})}),(0,$.jsx)(en,{className:`text-xl`,children:e(`oauth.consent.title`,{appName:g,defaultValue:`${g} wants to access your account`})}),(0,$.jsx)(pt,{children:e(`oauth.consent.request`,{appName:g,suffix:n?.email?` (${n.email})`:``,defaultValue:`${g} is requesting permission${n?.email?` for ${n.email}`:``}.`})})]}),(0,$.jsxs)(ei,{className:`space-y-4`,children:[m.length>0&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-2 text-sm font-medium`,children:e(`oauth.consent.willAllow`,{defaultValue:`This app will be able to:`})}),(0,$.jsx)(`ul`,{className:`space-y-1.5 rounded-md border bg-muted/40 p-3 text-sm`,children:m.map(t=>(0,$.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,$.jsx)(Pr,{className:`mt-0.5 h-4 w-4 text-green-600 dark:text-green-400`}),(0,$.jsx)(`span`,{children:Px(t,e)})]},t))})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-2 pt-2`,children:[(0,$.jsxs)(J,{variant:`outline`,onClick:()=>h(!1),disabled:i,children:[(0,$.jsx)(ci,{className:`mr-2 h-4 w-4`}),e(`oauth.consent.deny`,{defaultValue:`Deny`})]}),(0,$.jsxs)(J,{onClick:()=>h(!0),disabled:i,children:[(0,$.jsx)(Pr,{className:`mr-2 h-4 w-4`}),i?e(`oauth.consent.submitting`,{defaultValue:`Authorizing…`}):e(`oauth.consent.authorize`,{defaultValue:`Authorize`})]})]}),(0,$.jsx)(`p`,{className:`pt-2 text-center text-xs text-muted-foreground`,children:e(`oauth.consent.footer`,{defaultValue:`You can revoke access at any time from your account settings.`})})]})]})})}function Px(e,t){switch(e){case`openid`:return t(`oauth.consent.scope.openid`,{defaultValue:`Confirm your identity`});case`profile`:return t(`oauth.consent.scope.profile`,{defaultValue:`Read your basic profile (name, picture)`});case`email`:return t(`oauth.consent.scope.email`,{defaultValue:`Read your email address`});case`offline_access`:return t(`oauth.consent.scope.offlineAccess`,{defaultValue:`Stay signed in (refresh access)`});default:return e}}var Fx=`/api/v1/auth`;function Ix({children:e}){return(0,$.jsx)(`div`,{className:`flex min-h-svh w-full flex-col items-center justify-center gap-6 bg-muted p-6 md:p-10`,children:(0,$.jsxs)(`div`,{className:`flex w-full max-w-sm flex-col gap-6`,children:[(0,$.jsxs)(`a`,{href:`#`,className:`flex items-center gap-2 self-center font-medium`,children:[(0,$.jsx)(`div`,{className:`flex size-6 items-center justify-center rounded-md bg-primary text-primary-foreground overflow-hidden`,children:is()?(0,$.jsx)(`img`,{src:is(),alt:us(),className:`h-full w-full object-contain`}):(0,$.jsx)(Gr,{className:`size-4`})}),us()]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-6`,children:e})]})})}function Lx(){let{t:e}=G(),t=o(),[n]=s(),r=n.get(`user_code`)??n.get(`code`)??``,i=n.get(`runtime_name`)??``,a=n.get(`runtime_version`)??``,{user:c,isLoading:l,getAuthConfig:u}=C(),d=p(),[f,m]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(!1),[S,w]=(0,Q.useState)(``),[T,E]=(0,Q.useState)(null);if((0,Q.useEffect)(()=>{let e=!0;return u().then(t=>{e&&E(t?.features?.deviceAuthorization===!0)}).catch(()=>{e&&E(!0)}),()=>{e=!1}},[u]),!r)return(0,$.jsx)(Ix,{children:(0,$.jsx)(ln,{children:(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(en,{children:e(`auth.device.invalidTitle`,{defaultValue:`Invalid device link`})}),(0,$.jsx)(pt,{children:e(`auth.device.invalidDescription`,{defaultValue:`No device code was provided in the URL.`})})]})})});if(T===!1)return(0,$.jsx)(Ix,{children:(0,$.jsx)(ln,{children:(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(en,{children:e(`auth.device.disabledTitle`,{defaultValue:`Device authorization not enabled`})}),(0,$.jsx)(pt,{children:e(`auth.device.disabledDescription`,{defaultValue:`This deployment does not have device authorization enabled, so this device cannot be approved here.`})})]})})});if(l||T===null)return(0,$.jsx)(Ix,{children:(0,$.jsx)(ln,{children:(0,$.jsx)(Yr,{className:`text-center`,children:(0,$.jsx)(pt,{children:e(`auth.device.loading`,{defaultValue:`Loading…`})})})})});if(!c)return(0,$.jsx)(h,{to:`/login?redirect=${encodeURIComponent(`/auth/device${t.search}`)}`,replace:!0});if(v)return(0,$.jsx)(Ix,{children:(0,$.jsx)(ln,{children:(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(Gr,{className:`mx-auto mb-2 h-10 w-10 text-green-500`}),(0,$.jsx)(en,{children:e(`auth.device.approvedTitle`,{defaultValue:`Device authorized`})}),(0,$.jsx)(pt,{children:e(`auth.device.approvedDescription`,{defaultValue:`You can return to the device — it should sign in shortly.`})})]})})});if(b)return(0,$.jsx)(Ix,{children:(0,$.jsx)(ln,{children:(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(en,{children:e(`auth.device.deniedTitle`,{defaultValue:`Access denied`})}),(0,$.jsx)(pt,{children:e(`auth.device.deniedDescription`,{defaultValue:`The device will not be granted access.`})})]})})});let D=async()=>{await fetch(`${Fx}/device?user_code=${encodeURIComponent(r)}`,{credentials:`include`}).catch(()=>{})};return(0,$.jsx)(Ix,{children:(0,$.jsxs)(ln,{children:[(0,$.jsxs)(Yr,{className:`text-center`,children:[(0,$.jsx)(en,{children:e(`auth.device.title`,{defaultValue:`Authorize new device`})}),(0,$.jsx)(pt,{children:e(`auth.device.subtitle`,{email:c.email,defaultValue:`Approve this device to sign in as ${c.email}.`})})]}),(0,$.jsxs)(ei,{className:`space-y-4`,children:[i?(0,$.jsxs)(`div`,{className:`rounded-md border bg-background px-4 py-3 text-center`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e(`auth.device.requesterLabel`,{defaultValue:`Connection request from`})}),(0,$.jsx)(`p`,{className:`font-medium`,children:i}),a?(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[us().toLowerCase(),` `,a]}):null]}):null,(0,$.jsxs)(`div`,{className:`rounded-md border bg-background px-4 py-3 text-center`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e(`auth.device.userCodeLabel`,{defaultValue:`Device code`})}),(0,$.jsx)(`p`,{className:`font-mono text-lg font-semibold tracking-widest`,children:r})]}),(0,$.jsx)(`p`,{className:`text-center text-xs text-muted-foreground`,children:e(`auth.device.approveWarning`,{defaultValue:`Only approve if you started this connection yourself a moment ago. Once approved, this runtime can access your organization's private packages.`})}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(`p`,{className:`text-center text-sm text-muted-foreground`,children:e(`auth.device.loggedInAs`,{email:c.email,defaultValue:`Signed in as ${c.email}`})}),S&&(0,$.jsx)(`p`,{className:`text-center text-sm text-destructive`,children:S}),(0,$.jsx)(J,{onClick:async()=>{w(``),m(!0);try{await D();let t=await fetch(`${Fx}/device/approve`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({userCode:r})});if(!t.ok){let n=await t.json().catch(()=>({}));throw Error(n?.message??n?.error?.message??e(`auth.device.approveFailed`,{defaultValue:`Approval failed`}))}y(!0),X.success(e(`auth.device.approveSuccess`,{defaultValue:`Device authorized`}),{description:e(`auth.device.approveSuccessDescription`,{defaultValue:`You can close this window.`})})}catch(t){w(t?.message??e(`auth.device.approveFailed`,{defaultValue:`Approval failed`}))}finally{m(!1)}},className:`w-full`,disabled:f||g,children:f?e(`auth.device.approving`,{defaultValue:`Approving…`}):e(`auth.device.approve`,{defaultValue:`Approve device`})}),(0,$.jsx)(J,{onClick:async()=>{w(``),_(!0);try{await D(),await fetch(`${Fx}/device/deny`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`include`,body:JSON.stringify({userCode:r})}),x(!0)}catch(t){w(t?.message??e(`auth.device.denyFailed`,{defaultValue:`Failed to deny request`}))}finally{_(!1)}},variant:`outline`,className:`w-full`,disabled:f||g,children:g?e(`auth.device.denying`,{defaultValue:`Denying…`}):e(`auth.device.deny`,{defaultValue:`Deny request`})}),(0,$.jsx)(`div`,{className:`text-center`,children:(0,$.jsx)(`button`,{type:`button`,className:`text-sm text-muted-foreground underline-offset-4 hover:underline`,onClick:()=>d(`/`),children:e(`auth.device.cancel`,{defaultValue:`Cancel`})})})]})]})]})})}var Rx=(0,Q.lazy)(()=>t(()=>import(`./DocsLayout-BNsSvaz2.js`),__vite__mapDeps([0]),import.meta.url)),zx=(0,Q.lazy)(()=>t(()=>import(`./DocsIndex-CmY-7OQR.js`),__vite__mapDeps([0]),import.meta.url)),Bx=(0,Q.lazy)(()=>t(()=>import(`./DocsSlug-Cb_NMM1k.js`),__vite__mapDeps([0]),import.meta.url)),Vx=(0,Q.lazy)(()=>t(()=>import(`./DocPage-Bx8ZXCYt.js`),__vite__mapDeps([0]),import.meta.url)),Hx=`/api/v1/auth`;function Ux(){try{if(typeof document>`u`)return`/`;let e=document.querySelector(`base`)?.getAttribute(`href`);return e&&new URL(e,window.location.origin).pathname.replace(/\/$/,``)||`/`}catch{return`/`}}var Wx=Ux();function Gx(){let{user:e}=C();return(0,$.jsx)(u_,{userId:e?.id,children:(0,$.jsx)(E_,{})})}function Kx(){let e=o();return(0,Q.useEffect)(()=>{document.title=us();let e=ls();if(e){let t=document.getElementById(`favicon`);t&&(t.href=e,t.type=e.endsWith(`.svg`)?`image/svg+xml`:`image/png`)}},[e]),null}function qx(){return(0,$.jsxs)(v,{authUrl:Hx,children:[(0,$.jsx)(uh,{position:`bottom-right`}),(0,$.jsx)(ox,{}),(0,$.jsxs)(l,{basename:Wx,children:[(0,$.jsx)(Kx,{}),(0,$.jsx)(Cu,{children:(0,$.jsxs)(g,{children:[(0,$.jsx)(u,{path:`/login`,element:(0,$.jsx)(yx,{})}),(0,$.jsx)(u,{path:`/register`,element:(0,$.jsx)(Cx,{})}),(0,$.jsx)(u,{path:`/forgot-password`,element:(0,$.jsx)(Tx,{})}),(0,$.jsx)(u,{path:`/reset-password`,element:(0,$.jsx)(Ex,{})}),(0,$.jsx)(u,{path:`/set-password`,element:(0,$.jsx)(Ox,{})}),(0,$.jsx)(u,{path:`/verify-email`,element:(0,$.jsx)(Ax,{})}),(0,$.jsx)(u,{path:`/verify-email-prompt`,element:(0,$.jsx)(jx,{})}),(0,$.jsx)(u,{path:`/setup`,element:(0,$.jsx)(Mb,{})}),(0,$.jsx)(u,{path:`/oauth/consent`,element:(0,$.jsx)(Nx,{})}),(0,$.jsx)(u,{path:`/auth/device`,element:(0,$.jsx)(Lx,{})}),(0,$.jsx)(u,{path:`/accept-invitation/:invitationId`,element:(0,$.jsx)(Q_,{})}),(0,$.jsx)(u,{path:`/f/:slug`,element:(0,$.jsx)(rx,{mode:`public`})}),(0,$.jsx)(u,{path:`/s/:token`,element:(0,$.jsx)(lx,{})}),Sb,(0,$.jsx)(u,{path:`/forms/:name`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(ax,{})})}),(0,$.jsxs)(u,{path:`/docs`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(Rx,{})})}),children:[(0,$.jsx)(u,{index:!0,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(zx,{})})}),(0,$.jsx)(u,{path:`:slug`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(Bx,{})})}),(0,$.jsx)(u,{path:`:slug/:name`,element:(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(uu,{}),children:(0,$.jsx)(Vx,{})})})]}),(0,$.jsx)(u,{path:`/home`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(Gx,{})})}),(0,$.jsx)(u,{path:`/dev/master-detail`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(al,{})})}),(0,$.jsx)(u,{path:`/dev/lists`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(cl,{})})}),(0,$.jsx)(u,{path:`/dev/modal`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(Py,{})})}),(0,$.jsx)(u,{path:`/dev/lookup`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(Fy,{})})}),(0,$.jsx)(u,{path:`/dev/row-actions`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(By,{})})}),(0,$.jsx)(u,{path:`/organizations`,element:(0,$.jsx)(vb,{requireOrganization:!1,children:(0,$.jsx)(D_,{children:(0,$.jsx)(I_,{})})})}),(0,$.jsxs)(u,{path:`/organizations/:slug`,element:(0,$.jsx)(vb,{requireOrganization:!1,children:(0,$.jsx)(L_,{})}),children:[(0,$.jsx)(u,{index:!0,element:(0,$.jsx)(h,{to:`members`,replace:!0})}),(0,$.jsx)(u,{path:`members`,element:(0,$.jsx)(J_,{})}),(0,$.jsx)(u,{path:`invitations`,element:(0,$.jsx)(X_,{})}),(0,$.jsx)(u,{path:`settings`,element:(0,$.jsx)(Z_,{})})]}),(0,$.jsx)(u,{path:`/system/*`,element:(0,$.jsx)(ju,{})}),(0,$.jsx)(u,{path:`/ai`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(Au,{children:(0,$.jsx)(bp,{})})})}),(0,$.jsx)(u,{path:`/ai/:agent`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(Au,{children:(0,$.jsx)(bp,{})})})}),(0,$.jsx)(u,{path:`/ai/:agent/:conversationId`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(Au,{children:(0,$.jsx)(bp,{})})})}),(0,$.jsx)(u,{path:`/apps/:appName/*`,element:(0,$.jsx)(vb,{children:(0,$.jsx)(db,{})})}),(0,$.jsx)(u,{path:`/`,element:(0,$.jsx)(vb,{requireOrganization:!1,children:(0,$.jsx)(gb,{})})}),(0,$.jsx)(u,{path:`*`,element:(0,$.jsx)(du,{to:`/`,replace:!0})})]})})]})]})}async function Jx(e){try{let t=await fetch(`/api/v1/i18n/translations/${e}`);if(!t.ok)return console.warn(`[i18n] Failed to load translations for '${e}': HTTP ${t.status}`),{};let n=await t.json(),r;return r=n?.data?.translations&&typeof n.data.translations==`object`?n.data.translations:n,it(r)?Qe(r):r}catch(t){return console.warn(`[i18n] Failed to load translations for '${e}':`,t),{}}}async function Yx(){try{let e=await fetch(`/api/v1/i18n/locales`);if(!e.ok)return console.warn(`[i18n] Failed to load the app locale list: HTTP ${e.status}`),[];let t=await e.json(),n=t?.data?.locales??t?.locales??t;if(!Array.isArray(n))return console.warn(`[i18n] Unexpected /i18n/locales payload; ignoring.`),[];let r=[];for(let e of n){let t=typeof e==`string`?e:e?.code;typeof t==`string`&&t.length>0&&!r.includes(t)&&r.push(t)}return r}catch(e){return console.warn(`[i18n] Failed to load the app locale list:`,e),[]}}async function Xx(e){try{let t=await We(`${e}/api/v1/auth/me/localization`,{credentials:`include`,headers:{Accept:`application/json`}});if(t?.authenticated===!1)return;et(t?.locale)}catch{}}async function Zx(e,t=500){if(ot()||Xe())return;let n=Xx(e);await Promise.race([n,new Promise(e=>setTimeout(e,t))])}var Qx=`auth-session-token`,$x=`auth-active-organization-id`;function eS(){for(let e of Object.keys(localStorage))(e===$x||e.startsWith(`${$x}:u:`))&&localStorage.removeItem(e)}async function tS(e){if(typeof window>`u`)return;let t;try{t=localStorage.getItem(Qx)}catch{return}if(t)try{let n=await fetch(`${e}/get-session`,{method:`GET`,credentials:`omit`,headers:{Authorization:`Bearer ${t}`,Accept:`application/json`}});if(n.ok){let e=await n.json().catch(()=>null);if(e?.user??e?.data?.user??null)return}localStorage.removeItem(Qx),eS()}catch{}}W.registerLazy(`object-map`,()=>t(()=>import(`./plugin-map-DukneTNg.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`plugin-map`,category:`view`}),W.registerLazy(`map`,()=>t(()=>import(`./plugin-map-DukneTNg.js`).then(e=>e.t),__vite__mapDeps([0,2]),import.meta.url),{namespace:`view`,category:`view`}),W.registerLazy(`object-tree`,()=>t(()=>import(`./plugin-tree-DauauLFc.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-tree`,category:`view`}),W.registerLazy(`tree`,()=>t(()=>import(`./plugin-tree-DauauLFc.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`dashboard`,`metric`,`metric-card`,`object-metric`,`pivot`,`object-pivot`,`dashboard-grid`,`object-data-table`])W.registerLazy(e,()=>t(()=>import(`./plugin-dashboard-Bj4ldCX6.js`).then(e=>e.t),__vite__mapDeps([0,1]),import.meta.url),{namespace:`plugin-dashboard`,category:`view`});W.registerLazy(`chart`,()=>t(()=>import(`./plugin-charts-CDGkx7z5.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});for(let e of[`object-chart`,`bar-chart`,`pie-chart`,`donut-chart`,`radar-chart`,`scatter-chart`,`line-chart`,`area-chart`,`advanced-chart`,`chart:bar`])W.registerLazy(e,()=>t(()=>import(`./plugin-charts-CDGkx7z5.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-charts`,category:`chart`});W.registerLazy(`object-gantt`,()=>t(()=>import(`./plugin-gantt-zR8DkpEg.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-gantt`,category:`view`}),W.registerLazy(`gantt`,()=>t(()=>import(`./plugin-gantt-zR8DkpEg.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),W.registerLazy(`markdown`,()=>t(()=>import(`./plugin-markdown-B7zwZHmn.js`).then(e=>e.n),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-markdown`,category:`display`}),W.registerLazy(`object-timeline`,()=>t(()=>import(`./plugin-timeline-B6rsNNAK.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-timeline`,category:`view`}),W.registerLazy(`timeline`,()=>t(()=>import(`./plugin-timeline-B6rsNNAK.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),W.registerLazy(`object-calendar`,()=>t(()=>import(`./plugin-calendar-BwiiCIjv.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),W.registerLazy(`calendar`,()=>t(()=>import(`./plugin-calendar-BwiiCIjv.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`}),W.registerLazy(`calendar-view`,()=>t(()=>import(`./plugin-calendar-BwiiCIjv.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-calendar`,category:`view`}),W.registerLazy(`object-kanban`,()=>t(()=>import(`./plugin-kanban-DA0eW6yj.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`}),W.registerLazy(`kanban`,()=>t(()=>import(`./plugin-kanban-DA0eW6yj.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`view`,category:`view`});for(let e of[`kanban-ui`,`kanban-enhanced`])W.registerLazy(e,()=>t(()=>import(`./plugin-kanban-DA0eW6yj.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-kanban`,category:`view`});W.registerLazy(`report`,()=>t(()=>import(`./plugin-report-DaPtlsJr.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});for(let e of[`report-viewer`,`spec-report`])W.registerLazy(e,()=>t(()=>import(`./plugin-report-DaPtlsJr.js`).then(e=>e.t),__vite__mapDeps([0]),import.meta.url),{namespace:`plugin-report`,category:`view`});var nS=(0,Q.lazy)(()=>t(()=>import(`./ApiConsolePage-DUF0ysH7.js`).then(e=>({default:e.ApiConsolePage})),__vite__mapDeps([0]),import.meta.url)),rS=(0,Q.lazy)(()=>t(()=>import(`./FlowRunsPage-B6ustUgi.js`).then(e=>({default:e.FlowRunsPage})),__vite__mapDeps([0]),import.meta.url)),iS=(0,Q.lazy)(()=>t(()=>import(`./PublicFormsPage-CBcKQbNl.js`).then(e=>({default:e.PublicFormsPage})),__vite__mapDeps([0]),import.meta.url));function aS({label:e}){return(0,$.jsxs)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:[`Loading `,e,`…`]})}Bc({ref:`developer:api-console`,label:`API Console`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(aS,{label:`API console`}),children:(0,$.jsx)(nS,{...e})})}),Bc({ref:`developer:flow-runs`,label:`Flow Runs`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(aS,{label:`flow runs`}),children:(0,$.jsx)(rS,{...e})})}),Bc({ref:`developer:public-forms`,label:`Public Forms`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(aS,{label:`public forms`}),children:(0,$.jsx)(iS,{...e})})}),Bc({ref:`studio:builder`,label:`应用构建`,source:`@object-ui/console`,component:My});var oS=(0,Q.lazy)(()=>t(()=>import(`./ProfilePage-DEr5iZVB.js`).then(e=>({default:e.ProfilePage})),__vite__mapDeps([0]),import.meta.url));function sS(){let{t:e}=G();return(0,$.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:e(`common.loading`,{defaultValue:`Loading…`})})}Bc({ref:`account:profile_card`,label:`My Profile`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(sS,{}),children:(0,$.jsx)(oS,{...e})})});var cS=(0,Q.lazy)(()=>t(()=>import(`./ApprovalsInboxPage-DlnxY-uy.js`).then(e=>({default:e.ApprovalsInboxPage})),__vite__mapDeps([0]),import.meta.url));function lS(){let{t:e}=G();return(0,$.jsx)(`div`,{className:`p-6 text-sm text-muted-foreground`,children:e(`common.loading`,{defaultValue:`Loading…`})})}Bc({ref:`approvals:inbox`,label:`Approvals Inbox`,source:`@object-ui/console`,component:e=>(0,$.jsx)(Q.Suspense,{fallback:(0,$.jsx)(lS,{}),children:(0,$.jsx)(cS,{...e})})});var uS=`/api/v1/auth`;kr();var dS=``.replace(/\/+$/,``);Promise.all([rs(dS),tS(uS),Zx(dS)]).finally(()=>{vh(),document.title=us();let e=ls();if(e){let t=document.getElementById(`favicon`);t&&(t.href=e,t.type=e.endsWith(`.svg`)?`image/svg+xml`:`image/png`)}let t=zs({enabled:!0,name:us(),shortName:os(),description:as(),themeColor:cs(),backgroundColor:`#ffffff`,display:`standalone`,startUrl:`./`,scope:`./`,orientation:`any`,icons:[{src:e||`./favicon.svg`,sizes:`any`,type:`image/svg+xml`,purpose:`any`}]}),n=new Blob([JSON.stringify(t)],{type:`application/json`}),r=URL.createObjectURL(n),i=document.querySelector(`link[rel="manifest"]`);i&&i.remove();let a=document.createElement(`link`);a.rel=`manifest`,a.href=r,document.head.appendChild(a),rl.createRoot(document.getElementById(`root`)).render((0,$.jsx)(Q.StrictMode,{children:(0,$.jsx)(Hs,{pwa:{enabled:!0,name:us(),shortName:os()},children:(0,$.jsx)(tt,{loadLanguage:Jx,loadLocales:Yx,children:(0,$.jsx)(qx,{})})})}))});
|