@protobase/ui 0.122.1 → 0.123.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) hide show
  1. package/dist/account/messages.d.ts +2 -2
  2. package/dist/app/conversation-page/conversation-page.d.ts +5 -4
  3. package/dist/app/conversation-page/conversation-page.js +14 -11
  4. package/dist/app/conversation-page/thread-panel.d.ts +6 -2
  5. package/dist/app/conversation-page/thread-panel.js +12 -6
  6. package/dist/app/conversation-page/use-conversation-typing.d.ts +8 -0
  7. package/dist/app/conversation-page/use-conversation-typing.js +20 -0
  8. package/dist/app/create/messages.d.ts +2 -2
  9. package/dist/app/displays/messages.d.ts +2 -2
  10. package/dist/app/export/messages.d.ts +2 -2
  11. package/dist/app/field-types/json/messages.d.ts +2 -2
  12. package/dist/app/field-types/runner-install/messages.d.ts +2 -2
  13. package/dist/app/field-types/workflow/messages.d.ts +2 -2
  14. package/dist/app/field-types/workflow-page/messages.d.ts +2 -2
  15. package/dist/app/field-types/workflow-run/messages.d.ts +2 -2
  16. package/dist/app/focus/messages.d.ts +2 -2
  17. package/dist/app/gallery/gallery-layout.d.ts +2 -2
  18. package/dist/app/import/messages.d.ts +2 -2
  19. package/dist/app/list-messages.d.ts +2 -2
  20. package/dist/app/messages.d.ts +2 -2
  21. package/dist/app/meta-gate-messages.d.ts +2 -2
  22. package/dist/app/new-version/messages.d.ts +2 -2
  23. package/dist/app/pages/messages.d.ts +2 -2
  24. package/dist/app/record-messages.d.ts +2 -2
  25. package/dist/app/related-cards/messages.d.ts +2 -2
  26. package/dist/app/runtime/messages.d.ts +2 -2
  27. package/dist/app/saved/messages.d.ts +2 -2
  28. package/dist/app/searches/messages.d.ts +2 -2
  29. package/dist/app-shell/messages.d.ts +2 -2
  30. package/dist/assistant-dock/messages.d.ts +2 -2
  31. package/dist/auth/messages.d.ts +2 -2
  32. package/dist/calls/messages.d.ts +2 -2
  33. package/dist/data-grid/column-spec.d.ts +1 -1
  34. package/dist/data-grid/messages.d.ts +2 -2
  35. package/dist/filter-panel/messages.d.ts +2 -2
  36. package/dist/inline-child-table/messages.d.ts +2 -2
  37. package/dist/invitations/messages.d.ts +2 -2
  38. package/dist/mocks/orders.d.ts +1 -1
  39. package/dist/notifications/bell/messages.d.ts +2 -2
  40. package/dist/organizations/messages.d.ts +2 -2
  41. package/dist/package.js +1 -1
  42. package/dist/primitives/messages.d.ts +2 -2
  43. package/dist/relay/relay-context.js +1 -1
  44. package/dist/relay/relay-store.d.ts +1 -1
  45. package/dist/relay/relay-store.js +11 -18
  46. package/dist/relay/typing-line.d.ts +1 -6
  47. package/dist/relay/typing-line.js +4 -26
  48. package/dist/relay/use-relay-typing.d.ts +8 -0
  49. package/dist/relay/use-relay-typing.js +38 -0
  50. package/dist/relay/use-typing-sender.d.ts +5 -2
  51. package/dist/relay/use-typing-sender.js +5 -27
  52. package/dist/shell/assets/{account-page-BESKgoYT.js → account-page-DS2lZVD1.js} +2 -2
  53. package/dist/shell/assets/{app-DANB5cb3.js → app-1IZYQXW2.js} +13 -13
  54. package/dist/shell/assets/{assistant-shell-DUxCRpci.js → assistant-shell-BIpWuqnT.js} +2 -2
  55. package/dist/shell/assets/board-display-Buo0YyZ5.js +2 -0
  56. package/dist/shell/assets/calendar-display-10AgoW3N.js +2 -0
  57. package/dist/shell/assets/{call-rings-BGJkCQwP.js → call-rings-BUUwC1QU.js} +2 -2
  58. package/dist/shell/assets/{calls-BRoDIvWu.js → calls-eQ3_Fp6k.js} +2 -2
  59. package/dist/shell/assets/{circle-alert-BZyGgZSj.js → circle-alert-D7B_KeB7.js} +2 -2
  60. package/dist/shell/assets/{composed-page-By2d8F85.js → composed-page-Btkd6u0m.js} +2 -2
  61. package/dist/shell/assets/{composer-section-BiCIOqwU.js → composer-section-DUmPQLgo.js} +2 -2
  62. package/dist/shell/assets/{connect-route-BZsnJGaF.js → connect-route-DQIlzdmb.js} +2 -2
  63. package/dist/shell/assets/{copy-field-DpbjVuK4.js → copy-field-BfYo47Io.js} +2 -2
  64. package/dist/shell/assets/{create-route-DglCC2Tk.js → create-route-CSTAtNAw.js} +2 -2
  65. package/dist/shell/assets/{custom-step-container-field-DJbluU0F.js → custom-step-container-field-Dxltzn8J.js} +4 -4
  66. package/dist/shell/assets/embedded-list-7l7TUHug.js +3 -0
  67. package/dist/shell/assets/{export-dialog-B9fvLoT2.js → export-dialog-DWcXdfEj.js} +2 -2
  68. package/dist/shell/assets/{first-organization-page-CSIsJmoQ.js → first-organization-page-77PHesxY.js} +2 -2
  69. package/dist/shell/assets/{graph-view-IPDrZVmC.js → graph-view-DQOQDrmJ.js} +2 -2
  70. package/dist/shell/assets/{group-donut-DRT539D9.js → group-donut-BGfuQ6iU.js} +2 -2
  71. package/dist/shell/assets/{guest-call-page-IxjqrW0F.js → guest-call-page-BdV2Hwhv.js} +3 -3
  72. package/dist/shell/assets/{html-viewer-C-FI9kDC.js → html-viewer-CXABej3u.js} +2 -2
  73. package/dist/shell/assets/{import-dialog-DDaXN05w.js → import-dialog-Cqu_xO6L.js} +2 -2
  74. package/dist/shell/assets/import-table-dialog-MwfAiAmM.js +2 -0
  75. package/dist/shell/assets/{index-tI-2Oomu.js → index-DJQ4glyU.js} +1 -1
  76. package/dist/shell/assets/invitations-page-C6LjToJR.js +2 -0
  77. package/dist/shell/assets/{layout-grid-7R6t_Nlh.js → layout-grid-C_uTX3Tb.js} +2 -2
  78. package/dist/shell/assets/{legend-item-C-DA-JTo.js → legend-item-DzqFlC4D.js} +2 -2
  79. package/dist/shell/assets/list-page-CTGtveKF.js +4 -0
  80. package/dist/shell/assets/{maplibre-D0uTAdwG.js → maplibre-aCJmOb1H.js} +2 -2
  81. package/dist/shell/assets/{markdown-content-BpKVfSRq.js → markdown-content-CDmFTB6r.js} +2 -2
  82. package/dist/shell/assets/members-page-Defqhu24.js +2 -0
  83. package/dist/shell/assets/{message-content-DSZOlZUY.js → message-content-CeLDUud8.js} +3 -3
  84. package/dist/shell/assets/messages-XnV72On0.js +2 -0
  85. package/dist/shell/assets/organization-page-Cdfaqvsh.js +2 -0
  86. package/dist/shell/assets/organizations-page-C37kxzUq.js +2 -0
  87. package/dist/shell/assets/{pending-invitation-row-Bs60Zx0i.js → pending-invitation-row-Cyu7Ucej.js} +2 -2
  88. package/dist/shell/assets/{period-chart-CIgxhMTn.js → period-chart-T4rBI9Y2.js} +2 -2
  89. package/dist/shell/assets/{person-row-BH3iAvuG.js → person-row-DjxZAaa3.js} +2 -2
  90. package/dist/shell/assets/public-form-page-DaPFaXOT.js +2 -0
  91. package/dist/shell/assets/{record-lines-hY9wRXCf.js → record-lines-CSeqYQnm.js} +2 -2
  92. package/dist/shell/assets/{record-map-Dzt7xpK8.js → record-map-l-E3DvxV.js} +2 -2
  93. package/dist/shell/assets/{record-opens-DN1LnH9j.js → record-opens-DPMtZw1p.js} +2 -2
  94. package/dist/shell/assets/record-page-DK2-zwXx.js +3 -0
  95. package/dist/shell/assets/{record-preview-B1WiPOw4.js → record-preview-0BdCZkO9.js} +2 -2
  96. package/dist/shell/assets/{records-map-BLcMBygH.js → records-map-DSg2fbqb.js} +2 -2
  97. package/dist/shell/assets/render-node-qPc-4XAK.js +3 -0
  98. package/dist/shell/assets/reorder-button-Z_evPIxl.js +2 -0
  99. package/dist/shell/assets/{run-trace-view-BoBj-5R0.js → run-trace-view-ChuThRe4.js} +2 -2
  100. package/dist/shell/assets/{runner-install-field-BdfsPY9H.js → runner-install-field-8Ap9WvhK.js} +2 -2
  101. package/dist/shell/assets/{runtime-update-CRO1fS5O.js → runtime-update-B4DPgHIL.js} +2 -2
  102. package/dist/shell/assets/shared-protobase-ui-ClTsd7Ce.js +1 -0
  103. package/dist/shell/assets/{sheet-source-DSJ73Heh.js → sheet-source-D0v07JHr.js} +3 -3
  104. package/dist/shell/assets/sign-in-policy-page-CV3iE_o8.js +2 -0
  105. package/dist/shell/assets/start-block-queries-DJX-JI2P.js +2 -0
  106. package/dist/shell/assets/step-catalog-DSHlXxWA.js +2 -0
  107. package/dist/shell/assets/{step-panel-BkpaCVJd.js → step-panel-CF6x9K8Y.js} +2 -2
  108. package/dist/shell/assets/timeline-display-DpVKeXjG.js +2 -0
  109. package/dist/shell/assets/{trash-IV6Ox5bV.js → trash-Ccs0JhuD.js} +2 -2
  110. package/dist/shell/assets/{update-set-BTHuLrBr.js → update-set-L1kw--38.js} +2 -2
  111. package/dist/shell/assets/use-calendar-move-DHCS22jF.js +2 -0
  112. package/dist/shell/assets/{use-display-rows-C_H7lxLW.js → use-display-rows-DcY7w9cN.js} +2 -2
  113. package/dist/shell/assets/{use-my-invitations-DSp8OwP9.js → use-my-invitations-Dodu_ib9.js} +2 -2
  114. package/dist/shell/assets/{use-paged-search-DOcO0Rbz.js → use-paged-search-Crpqw2e-.js} +2 -2
  115. package/dist/shell/assets/{use-run-trace-BsH3vq5k.js → use-run-trace-Cozaxsfl.js} +2 -2
  116. package/dist/shell/assets/{use-workflow-page-DDl2MUPY.js → use-workflow-page-eP9jGrad.js} +2 -2
  117. package/dist/shell/assets/{use-workflow-types-nJ6UhHeL.js → use-workflow-types-DjJ87TLL.js} +2 -2
  118. package/dist/shell/assets/{workflow-canvas-xG0FmrJj.js → workflow-canvas-NJSHRDav.js} +4 -4
  119. package/dist/shell/assets/{workflow-field-fuI75chK.js → workflow-field-D_pqVGeK.js} +3 -3
  120. package/dist/shell/assets/{workflow-graph-editor-DCCcZ5AP.js → workflow-graph-editor-D4zxMPy4.js} +2 -2
  121. package/dist/shell/assets/{workflow-run-field-BxIU66mn.js → workflow-run-field-DcL-8XS_.js} +3 -3
  122. package/dist/shell/assets/workflow-status-field-15bq7T5K.js +2 -0
  123. package/dist/shell/assets/workflow-workbench-CC_mXUfW.js +4 -0
  124. package/dist/shell/index.html +3 -3
  125. package/dist/shell/protobase.shell.json +2 -2
  126. package/dist/shell/protobase.sw.js +2 -2
  127. package/dist/shell-source-maps/assets/{account-page-BESKgoYT.js.map → account-page-DS2lZVD1.js.map} +1 -1
  128. package/dist/shell-source-maps/assets/{app-DANB5cb3.js.map → app-1IZYQXW2.js.map} +1 -1
  129. package/dist/shell-source-maps/assets/{assistant-shell-DUxCRpci.js.map → assistant-shell-BIpWuqnT.js.map} +1 -1
  130. package/dist/shell-source-maps/assets/{board-display-Blx6nTDs.js.map → board-display-Buo0YyZ5.js.map} +1 -1
  131. package/dist/shell-source-maps/assets/{calendar-display-SPyIwDLG.js.map → calendar-display-10AgoW3N.js.map} +1 -1
  132. package/dist/shell-source-maps/assets/{call-rings-BGJkCQwP.js.map → call-rings-BUUwC1QU.js.map} +1 -1
  133. package/dist/shell-source-maps/assets/{calls-BRoDIvWu.js.map → calls-eQ3_Fp6k.js.map} +1 -1
  134. package/dist/shell-source-maps/assets/{circle-alert-BZyGgZSj.js.map → circle-alert-D7B_KeB7.js.map} +1 -1
  135. package/dist/shell-source-maps/assets/{composed-page-By2d8F85.js.map → composed-page-Btkd6u0m.js.map} +1 -1
  136. package/dist/shell-source-maps/assets/{composer-section-BiCIOqwU.js.map → composer-section-DUmPQLgo.js.map} +1 -1
  137. package/dist/shell-source-maps/assets/{connect-route-BZsnJGaF.js.map → connect-route-DQIlzdmb.js.map} +1 -1
  138. package/dist/shell-source-maps/assets/{copy-field-DpbjVuK4.js.map → copy-field-BfYo47Io.js.map} +1 -1
  139. package/dist/shell-source-maps/assets/{create-route-DglCC2Tk.js.map → create-route-CSTAtNAw.js.map} +1 -1
  140. package/dist/shell-source-maps/assets/{custom-step-container-field-DJbluU0F.js.map → custom-step-container-field-Dxltzn8J.js.map} +1 -1
  141. package/dist/shell-source-maps/assets/{embedded-list-CepLmiOu.js.map → embedded-list-7l7TUHug.js.map} +1 -1
  142. package/dist/shell-source-maps/assets/{export-dialog-B9fvLoT2.js.map → export-dialog-DWcXdfEj.js.map} +1 -1
  143. package/dist/shell-source-maps/assets/{first-organization-page-CSIsJmoQ.js.map → first-organization-page-77PHesxY.js.map} +1 -1
  144. package/dist/shell-source-maps/assets/{graph-view-IPDrZVmC.js.map → graph-view-DQOQDrmJ.js.map} +1 -1
  145. package/dist/shell-source-maps/assets/{group-donut-DRT539D9.js.map → group-donut-BGfuQ6iU.js.map} +1 -1
  146. package/dist/shell-source-maps/assets/{guest-call-page-IxjqrW0F.js.map → guest-call-page-BdV2Hwhv.js.map} +1 -1
  147. package/dist/shell-source-maps/assets/{html-viewer-C-FI9kDC.js.map → html-viewer-CXABej3u.js.map} +1 -1
  148. package/dist/shell-source-maps/assets/{import-dialog-DDaXN05w.js.map → import-dialog-Cqu_xO6L.js.map} +1 -1
  149. package/dist/shell-source-maps/assets/{import-table-dialog-CHWoi7_S.js.map → import-table-dialog-MwfAiAmM.js.map} +1 -1
  150. package/dist/shell-source-maps/assets/{invitations-page-BE0tj3Aw.js.map → invitations-page-C6LjToJR.js.map} +1 -1
  151. package/dist/shell-source-maps/assets/{layout-grid-7R6t_Nlh.js.map → layout-grid-C_uTX3Tb.js.map} +1 -1
  152. package/dist/shell-source-maps/assets/{legend-item-C-DA-JTo.js.map → legend-item-DzqFlC4D.js.map} +1 -1
  153. package/dist/shell-source-maps/assets/{list-page-Dj-oZ99M.js.map → list-page-CTGtveKF.js.map} +1 -1
  154. package/dist/shell-source-maps/assets/{maplibre-D0uTAdwG.js.map → maplibre-aCJmOb1H.js.map} +1 -1
  155. package/dist/shell-source-maps/assets/{markdown-content-BpKVfSRq.js.map → markdown-content-CDmFTB6r.js.map} +1 -1
  156. package/dist/shell-source-maps/assets/{members-page-Ced4meCg.js.map → members-page-Defqhu24.js.map} +1 -1
  157. package/dist/shell-source-maps/assets/{message-content-DSZOlZUY.js.map → message-content-CeLDUud8.js.map} +1 -1
  158. package/dist/shell-source-maps/assets/{messages-CEK97JXa.js.map → messages-XnV72On0.js.map} +1 -1
  159. package/dist/shell-source-maps/assets/{organization-page-Dp_D2xbC.js.map → organization-page-Cdfaqvsh.js.map} +1 -1
  160. package/dist/shell-source-maps/assets/{organizations-page-CtrgjIWL.js.map → organizations-page-C37kxzUq.js.map} +1 -1
  161. package/dist/shell-source-maps/assets/{pending-invitation-row-Bs60Zx0i.js.map → pending-invitation-row-Cyu7Ucej.js.map} +1 -1
  162. package/dist/shell-source-maps/assets/{period-chart-CIgxhMTn.js.map → period-chart-T4rBI9Y2.js.map} +1 -1
  163. package/dist/shell-source-maps/assets/{person-row-BH3iAvuG.js.map → person-row-DjxZAaa3.js.map} +1 -1
  164. package/dist/shell-source-maps/assets/{public-form-page-NPPZ_rgo.js.map → public-form-page-DaPFaXOT.js.map} +1 -1
  165. package/dist/shell-source-maps/assets/{record-lines-hY9wRXCf.js.map → record-lines-CSeqYQnm.js.map} +1 -1
  166. package/dist/shell-source-maps/assets/{record-map-Dzt7xpK8.js.map → record-map-l-E3DvxV.js.map} +1 -1
  167. package/dist/shell-source-maps/assets/{record-opens-DN1LnH9j.js.map → record-opens-DPMtZw1p.js.map} +1 -1
  168. package/dist/shell-source-maps/assets/record-page-DK2-zwXx.js.map +1 -0
  169. package/dist/shell-source-maps/assets/{record-preview-B1WiPOw4.js.map → record-preview-0BdCZkO9.js.map} +1 -1
  170. package/dist/shell-source-maps/assets/{records-map-BLcMBygH.js.map → records-map-DSg2fbqb.js.map} +1 -1
  171. package/dist/shell-source-maps/assets/{render-node-DyvozeRy.js.map → render-node-qPc-4XAK.js.map} +1 -1
  172. package/dist/shell-source-maps/assets/{reorder-button-NNfcfua7.js.map → reorder-button-Z_evPIxl.js.map} +1 -1
  173. package/dist/shell-source-maps/assets/{run-trace-view-BoBj-5R0.js.map → run-trace-view-ChuThRe4.js.map} +1 -1
  174. package/dist/shell-source-maps/assets/{runner-install-field-BdfsPY9H.js.map → runner-install-field-8Ap9WvhK.js.map} +1 -1
  175. package/dist/shell-source-maps/assets/{runtime-update-CRO1fS5O.js.map → runtime-update-B4DPgHIL.js.map} +1 -1
  176. package/dist/shell-source-maps/assets/{sheet-source-DSJ73Heh.js.map → sheet-source-D0v07JHr.js.map} +1 -1
  177. package/dist/shell-source-maps/assets/{sign-in-policy-page-RaxuDREW.js.map → sign-in-policy-page-CV3iE_o8.js.map} +1 -1
  178. package/dist/shell-source-maps/assets/{start-block-queries-DTa6akPc.js.map → start-block-queries-DJX-JI2P.js.map} +1 -1
  179. package/dist/shell-source-maps/assets/{step-catalog-UHxllpni.js.map → step-catalog-DSHlXxWA.js.map} +1 -1
  180. package/dist/shell-source-maps/assets/{step-panel-BkpaCVJd.js.map → step-panel-CF6x9K8Y.js.map} +1 -1
  181. package/dist/shell-source-maps/assets/{timeline-display-CFIOdA59.js.map → timeline-display-DpVKeXjG.js.map} +1 -1
  182. package/dist/shell-source-maps/assets/{trash-IV6Ox5bV.js.map → trash-Ccs0JhuD.js.map} +1 -1
  183. package/dist/shell-source-maps/assets/{update-set-BTHuLrBr.js.map → update-set-L1kw--38.js.map} +1 -1
  184. package/dist/shell-source-maps/assets/{use-calendar-move-CaU_5smA.js.map → use-calendar-move-DHCS22jF.js.map} +1 -1
  185. package/dist/shell-source-maps/assets/{use-display-rows-C_H7lxLW.js.map → use-display-rows-DcY7w9cN.js.map} +1 -1
  186. package/dist/shell-source-maps/assets/{use-my-invitations-DSp8OwP9.js.map → use-my-invitations-Dodu_ib9.js.map} +1 -1
  187. package/dist/shell-source-maps/assets/{use-paged-search-DOcO0Rbz.js.map → use-paged-search-Crpqw2e-.js.map} +1 -1
  188. package/dist/shell-source-maps/assets/{use-run-trace-BsH3vq5k.js.map → use-run-trace-Cozaxsfl.js.map} +1 -1
  189. package/dist/shell-source-maps/assets/{use-workflow-page-DDl2MUPY.js.map → use-workflow-page-eP9jGrad.js.map} +1 -1
  190. package/dist/shell-source-maps/assets/{use-workflow-types-nJ6UhHeL.js.map → use-workflow-types-DjJ87TLL.js.map} +1 -1
  191. package/dist/shell-source-maps/assets/{workflow-canvas-xG0FmrJj.js.map → workflow-canvas-NJSHRDav.js.map} +1 -1
  192. package/dist/shell-source-maps/assets/{workflow-field-fuI75chK.js.map → workflow-field-D_pqVGeK.js.map} +1 -1
  193. package/dist/shell-source-maps/assets/{workflow-graph-editor-DCCcZ5AP.js.map → workflow-graph-editor-D4zxMPy4.js.map} +1 -1
  194. package/dist/shell-source-maps/assets/{workflow-run-field-BxIU66mn.js.map → workflow-run-field-DcL-8XS_.js.map} +1 -1
  195. package/dist/shell-source-maps/assets/{workflow-status-field-Bnk5IHI5.js.map → workflow-status-field-15bq7T5K.js.map} +1 -1
  196. package/dist/shell-source-maps/assets/{workflow-workbench-7EvpXFq6.js.map → workflow-workbench-CC_mXUfW.js.map} +1 -1
  197. package/dist/status/messages.d.ts +2 -2
  198. package/dist/typing/conversation-typing.d.ts +15 -0
  199. package/dist/typing/conversation-typing.js +11 -0
  200. package/dist/typing/record-channel-typing.d.ts +14 -0
  201. package/dist/typing/record-channel-typing.js +33 -0
  202. package/dist/typing/typers-store.d.ts +15 -0
  203. package/dist/typing/typers-store.js +31 -0
  204. package/dist/typing/typing-names.d.ts +11 -0
  205. package/dist/typing/typing-names.js +29 -0
  206. package/dist/typing/typing.d.ts +49 -0
  207. package/dist/typing/typing.js +102 -0
  208. package/dist/typing/use-record-typing.d.ts +11 -0
  209. package/dist/typing/use-record-typing.js +51 -0
  210. package/dist/typing/use-typing-box.d.ts +16 -0
  211. package/dist/typing/use-typing-box.js +30 -0
  212. package/dist/users/messages.d.ts +2 -2
  213. package/package.json +5 -5
  214. package/dist/relay/typing.d.ts +0 -37
  215. package/dist/relay/typing.js +0 -78
  216. package/dist/shell/assets/board-display-Blx6nTDs.js +0 -2
  217. package/dist/shell/assets/calendar-display-SPyIwDLG.js +0 -2
  218. package/dist/shell/assets/embedded-list-CepLmiOu.js +0 -3
  219. package/dist/shell/assets/import-table-dialog-CHWoi7_S.js +0 -2
  220. package/dist/shell/assets/invitations-page-BE0tj3Aw.js +0 -2
  221. package/dist/shell/assets/list-page-Dj-oZ99M.js +0 -4
  222. package/dist/shell/assets/members-page-Ced4meCg.js +0 -2
  223. package/dist/shell/assets/messages-CEK97JXa.js +0 -2
  224. package/dist/shell/assets/organization-page-Dp_D2xbC.js +0 -2
  225. package/dist/shell/assets/organizations-page-CtrgjIWL.js +0 -2
  226. package/dist/shell/assets/public-form-page-NPPZ_rgo.js +0 -2
  227. package/dist/shell/assets/record-page-CSsNYC0Q.js +0 -3
  228. package/dist/shell/assets/render-node-DyvozeRy.js +0 -3
  229. package/dist/shell/assets/reorder-button-NNfcfua7.js +0 -2
  230. package/dist/shell/assets/shared-protobase-ui-BbJCcQ0y.js +0 -1
  231. package/dist/shell/assets/sign-in-policy-page-RaxuDREW.js +0 -2
  232. package/dist/shell/assets/start-block-queries-DTa6akPc.js +0 -2
  233. package/dist/shell/assets/step-catalog-UHxllpni.js +0 -2
  234. package/dist/shell/assets/timeline-display-CFIOdA59.js +0 -2
  235. package/dist/shell/assets/use-calendar-move-CaU_5smA.js +0 -2
  236. package/dist/shell/assets/workflow-status-field-Bnk5IHI5.js +0 -2
  237. package/dist/shell/assets/workflow-workbench-7EvpXFq6.js +0 -4
  238. package/dist/shell-source-maps/assets/record-page-CSsNYC0Q.js.map +0 -1
@@ -1,3 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/record-map-Dzt7xpK8.js","assets/rolldown-runtime-DFwUHQ4A.js","assets/react-CuiNlnus.js","assets/maplibre-D0uTAdwG.js","assets/app-DANB5cb3.js","assets/vendor-t7Q7QbPu.js","assets/app-lQJl2mz_.css","assets/lib-maplibre-gl-CFGgq6sa.js","assets/lib-maplibre-gl-DBE96hFo.css","assets/lib-vis.gl-react-maplibre-1cv426UN.js","assets/lib-pmtiles-G7iEFxNu.js","assets/lib-fflate-HbhbPPwS.js","assets/record-lines-hY9wRXCf.js","assets/embedded-list-CepLmiOu.js","assets/update-set-BTHuLrBr.js","assets/layout-grid-7R6t_Nlh.js","assets/lib-tanstack-react-table-uAPG3Sdi.js","assets/lib-tanstack-store-KbP08Dw1.js","assets/lib-tanstack-react-store-BKI8EKbh.js","assets/lib-use-sync-external-store-D4s7MiFL.js","assets/lib-tanstack-table-core-2MHQ7o_e.js","assets/record-preview-B1WiPOw4.js","assets/lib-dnd-kit-core-xi-7xL_N.js","assets/lib-dnd-kit-utilities-Bvr0fWXF.js","assets/lib-dnd-kit-accessibility-AUTLnqh4.js","assets/lib-dnd-kit-sortable-CNDSKqCD.js","assets/composer-section-BiCIOqwU.js","assets/render-node-DyvozeRy.js","assets/circle-alert-BZyGgZSj.js","assets/page-header-Ddz2r5ic.js","assets/pending-invitation-row-Bs60Zx0i.js","assets/person-row-BH3iAvuG.js","assets/use-paged-search-DOcO0Rbz.js","assets/client-publisher-D39SlIhp.js","assets/copy-field-DpbjVuK4.js"])))=>i.map(i=>d[i]);
2
- (function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,r as n,t as r}from"./react-CuiNlnus.js";import{$ as i,$c as a,$i as o,$o as s,$s as c,A as l,Ai as u,An as d,Ao as f,At as p,Ba as m,Bi as h,Bn as g,Bt as _,Cl as v,Cn as y,Cr as b,Ct as x,D as S,Di as C,Dt as w,Ec as T,Ei as ee,Et as te,F as E,Fa as D,Fo as O,Fs as ne,Ft as k,Ga as A,Ht as re,In as ie,Io as ae,Ir as oe,Is as se,It as ce,Ja as le,Ji as ue,Jt as de,Ka as fe,Kr as j,L as pe,La as me,Lc as he,Li as ge,Ln as _e,Lo as ve,Lr as ye,Mi as be,Ml as xe,Mo as Se,Ms as Ce,Mt as we,Nn as Te,Nr as Ee,Nt as De,O as M,Ol as N,Pa as Oe,Pr as P,Pt as F,Qa as I,Qc as L,Qi as ke,Qo as Ae,Ra as R,Ri as je,S as Me,Sa as Ne,Sc as z,Sr as Pe,T as Fe,Tc as B,Ti as Ie,Tn as Le,Ts as V,Tt as Re,Ur as ze,Ut as Be,Vi as Ve,Vl as He,Vn as Ue,Wc as We,Wi as Ge,Xl as Ke,Xo as qe,Xt as H,Yi as Je,Yn as Ye,Yo as Xe,Yt as Ze,Z as Qe,Za as $e,Zi as et,Zn as tt,Zo as nt,_ as U,_s as rt,ao as it,b as at,bc as ot,bi as st,bn as ct,bu as lt,c as ut,ct as dt,dr as ft,ec as pt,eo as mt,et as ht,f as gt,fr as _t,fu as W,g as vt,ga as yt,gc as bt,gl as xt,gn as St,h as Ct,ha as wt,hl as G,ic as Tt,ir as Et,it as Dt,ja as Ot,ji as kt,k as At,kc as jt,kn as Mt,la as Nt,m as Pt,mc as Ft,mu as K,n as It,ns as Lt,nt as Rt,ol as zt,on as Bt,ot as Vt,p as Ht,ps as Ut,qa as Wt,qi as Gt,qr as Kt,qt,ra as Jt,rr as Yt,rt as Xt,sl as q,st as Zt,tl as Qt,ts as $t,u as en,uc as tn,v as nn,vi as rn,vs as J,vu as an,w as on,wc as sn,wi as cn,wn as ln,x as un,xc as dn,y as fn,yc as pn,yl as mn,ys as hn,z as gn,za as _n,zi as vn,zn as yn,zt as bn}from"./app-DANB5cb3.js";import{C as xn,h as Sn,i as Cn,o as wn,r as Tn,s as En}from"./vendor-t7Q7QbPu.js";import{Ct as Dn,Dt as On,Et as kn,Tt as An,_ as jn,a as Mn,c as Nn,jt as Pn,lt as Fn,n as In,ot as Ln,pt as Rn,rt as zn,s as Bn,t as Vn,tt as Hn,yt as Un}from"./embedded-list-CepLmiOu.js";import{a as Wn,i as Gn,n as Kn,r as qn,t as Jn}from"./reorder-button-NNfcfua7.js";import{a as Yn,c as Xn,d as Zn,f as Qn,h as $n,i as er,l as tr,m as nr,n as rr,o as ir,p as ar,r as or,s as sr,t as cr,u as lr}from"./render-node-DyvozeRy.js";import{t as ur}from"./trash-IV6Ox5bV.js";import{n as dr,t as fr}from"./record-sidebar-HqyBXBwn.js";import{t as pr}from"./start-block-queries-DTa6akPc.js";import{t as mr}from"./record-opens-DN1LnH9j.js";import{u as hr}from"./messages-CEK97JXa.js";var gr={name:`images`,size:24,node:[[`path`,{d:`m22 11-1.296-1.296a2.4 2.4 0 0 0-3.408 0L11 16`,key:`9kzy35`}],[`path`,{d:`M4 8a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2`,key:`1t0f0t`}],[`circle`,{cx:`13`,cy:`7`,r:`1`,fill:`currentColor`,key:`1obus6`}],[`rect`,{x:`8`,y:`2`,width:`14`,height:`14`,rx:`2`,key:`1gvhby`}]]};gr.node;var _r=zt(gr),vr={name:`info`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 16v-4`,key:`1dtifu`}],[`path`,{d:`M12 8h.01`,key:`e9boi3`}]]};vr.node;var yr=zt(vr),br={name:`list-tree`,size:24,node:[[`path`,{d:`M8 5h13`,key:`1pao27`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`M3 10a2 2 0 0 0 2 2h3`,key:`1npucw`}],[`path`,{d:`M3 5v12a2 2 0 0 0 2 2h3`,key:`x1gjn2`}]]};br.node;var xr=zt(br),Sr={name:`undo-2`,size:24,node:[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]};Sr.node;var Cr=zt(Sr),wr={name:`zap`,size:24,node:[[`path`,{d:`M15.914 4a1.5 1.5 0 00-2.474-1.561l-9 9A1.5 1.5 0 005.5 14h4.002a.5.5 0 01.471.666L8.086 20a1.5 1.5 0 002.475 1.56l9-9A1.5 1.5 0 0018.5 10h-3.997a.5.5 0 01-.472-.667z`,key:`1v7up4`}]]};wr.node;var Tr=zt(wr),Y=e(r(),1),Er=({collection:e,title:t,badge:n,lastEditedBy:r,presence:i=[],actions:a})=>(0,Y.jsxs)(`header`,{className:`flex flex-col gap-4 border-b border-border pb-6 md:flex-row md:items-end md:justify-between md:gap-6`,children:[(0,Y.jsxs)(`div`,{children:[e&&(0,Y.jsx)(`p`,{className:`mb-1 text-xs text-muted-foreground`,children:e}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-foreground md:text-2xl`,children:t}),n]}),r&&(0,Y.jsx)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:r.name?(0,Y.jsxs)(Y.Fragment,{children:[dt(`lastEditedBy`),` `,(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:r.name}),` `,r.ago]}):(0,Y.jsx)(Y.Fragment,{children:dt(`lastUpdated`,{ago:r.ago})})})]}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4`,children:[i.length>0&&(0,Y.jsxs)(`span`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,Y.jsx)(Ae,{people:i,size:`md`}),dt(`viewing`,{count:i.length})]}),a]})]}),X=e(t(),1),Dr=`text-base font-semibold text-foreground`,Or=({title:e,help:t,count:n,open:r,toggle:i,children:a})=>{let o=(0,X.useId)();return(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`div`,{className:q(`py-8`,r&&`pb-0`),children:[(0,Y.jsxs)(`h2`,{className:`flex items-center gap-2`,children:[i?(0,Y.jsxs)(j,{to:i,replace:!0,"aria-expanded":r,"aria-controls":o,className:q(`inline-flex items-center gap-1.5`,Dr),children:[(0,Y.jsx)(L,{className:q(`size-4 transition-transform`,r&&`rotate-90`)}),e]}):(0,Y.jsx)(`span`,{className:Dr,children:e}),n]}),t&&(0,Y.jsx)(`p`,{className:q(`mt-1 max-w-xl leading-6 text-muted-foreground`,i&&`pl-5.5`),children:t})]}),r&&(0,Y.jsx)(`div`,{id:o,className:`divide-y divide-border`,children:(0,Y.jsx)(pe.Provider,{value:2,children:a})})]})},kr=({tabs:e})=>(0,Y.jsx)(`nav`,{"aria-label":dt(`tabs`),className:`overflow-x-auto py-6`,children:(0,Y.jsx)(`span`,{className:ve.group(`md`),children:e.map(e=>(0,Y.jsx)(j,{to:e.to,replace:!0,"aria-current":e.current?`page`:void 0,className:q(ve.option(e.current,`md`),`whitespace-nowrap`),children:e.title},e.title))})}),Ar=({rows:e})=>(0,Y.jsx)(`dl`,{className:`border-t border-border`,children:e.map(e=>(0,Y.jsxs)(`div`,{className:q(`grid gap-x-4 border-b border-border py-2.5`,e.wide?`grid-cols-1 gap-y-1.5`:`grid-cols-[minmax(0,2fr)_minmax(0,3fr)]`),children:[(0,Y.jsxs)(`dt`,{className:`min-w-0 text-muted-foreground`,children:[e.label,e.help&&(0,Y.jsx)(`span`,{className:`mt-0.5 block text-xs text-faint-foreground`,children:e.help})]}),(0,Y.jsx)(`dd`,{className:`min-w-0 break-words text-foreground`,children:e.value})]},e.label))}),jr=({facts:e})=>(0,Y.jsx)(`dl`,{className:`grid grid-cols-2 gap-x-4 gap-y-5 sm:flex sm:flex-wrap sm:gap-x-10`,children:e.map(({label:e,value:t,icon:n})=>(0,Y.jsxs)(`div`,{title:e,className:`flex min-w-0 flex-col gap-1.5`,children:[(0,Y.jsx)(`dt`,{className:`text-muted-foreground`,children:n?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(n,{className:`size-5`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{className:`sr-only`,children:e})]}):e}),(0,Y.jsx)(`dd`,{className:`min-w-0 break-words text-base font-semibold text-foreground`,children:t})]},e))}),Mr=`flex min-h-11 items-center gap-2 rounded-md border border-border-strong px-3 text-left hover:bg-surface disabled:cursor-default disabled:opacity-60 md:min-h-0 md:w-full md:items-start md:gap-3 md:rounded-none md:border-0 md:px-4 md:py-3`,Nr=({actions:e})=>(0,Y.jsxs)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-background`,children:[(0,Y.jsx)(`h2`,{className:`hidden border-b border-border px-4 py-2.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground md:block`,children:dt(`actions`)}),(0,Y.jsx)(`ul`,{className:`flex flex-wrap gap-2 p-2 md:block md:divide-y md:divide-border md:p-0`,children:e.map(({name:e,description:t,icon:n,onRun:r,blocked:i,running:a,tone:o,render:s})=>{let c=(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(n,{className:q(`size-4 shrink-0 md:mt-0.5`,o===`danger`?`text-danger-text`:`text-muted-foreground`),"aria-hidden":!0}),(0,Y.jsxs)(`span`,{children:[(0,Y.jsx)(`span`,{className:q(`block font-medium`,o===`danger`?`text-danger-text`:`text-foreground`),children:e}),t&&(0,Y.jsx)(`span`,{className:`mt-0.5 hidden text-xs leading-snug text-muted-foreground md:block`,children:t})]})]});return(0,Y.jsx)(`li`,{children:s?s({className:Mr,children:c}):(0,Y.jsx)(`button`,{type:`button`,onClick:r,disabled:!!i||a,title:i,className:Mr,children:c})},e)})})]}),Pr=e(n(),1),Fr=1e3,Ir=(e,t,n,r,i)=>{let a=ze(e?.name??``,{enabled:!!(e&&t),filter:t?`${t.name} = "${r}"`:void 0,pageSize:500,labels:i,...n&&e?.fields[n]?.sortable&&{orderBy:`${n} asc`}}),o=(0,X.useMemo)(()=>n?[...a.items].sort((e,t)=>Number(e[n])-Number(t[n])):a.items,[a.data,n]),s=a.hasNextPage&&a.items.length<1e3;return(0,X.useEffect)(()=>{s&&!a.isFetchingNextPage&&a.fetchNextPage()},[s,a.isFetchingNextPage]),{items:o,labels:a.labels,loading:(a.isPending||s)&&!!e,complete:!a.hasNextPage}},Lr=(e,t)=>[`${t}_at`,`${t}At`].find(t=>e.fields[t]),Rr=(e,t)=>e.sidebar?e.title?(0,Y.jsx)(dr,{title:e.title,children:t}):t:e.title?(0,Y.jsx)(E,{title:e.title,children:t}):(0,Y.jsx)(`section`,{className:`py-8`,children:t}),zr=({item:e,scope:t,fallback:n})=>{let{components:r}=A(),i=r?.[e.component],a=i&&(0,Y.jsx)(ft,{value:t,children:(0,Y.jsx)(i,{...Ke(e.props??{})})});return n===void 0?Rr(e,(0,Y.jsx)(rr,{name:e.component,registered:!!i,fallback:void 0,children:a})):(0,Y.jsx)(rr,{name:e.component,registered:!!i,fallback:n,children:Rr(e,a)})},Br=({component:e,scope:t,standard:n})=>{let{components:r}=A(),i=r?.[e];return i?(0,Y.jsx)(it,{name:e,fallback:n,children:(0,Y.jsx)(Vr,{children:(0,Y.jsx)(ft,{value:t,children:(0,Y.jsx)(i,{})})})}):n},Vr=({children:e})=>(s(!1),(0,Y.jsx)(`div`,{className:`grid min-h-0 flex-1 grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)]`,children:e})),Hr=({page:e,scope:t})=>{let{joining:n}=Be(t.model.name,t.key),r=V(),i=o();return e.call===void 0||!n?null:(0,Y.jsx)(`div`,{className:`grid min-h-0 min-w-0 shrink-0 grid-cols-[minmax(0,1fr)] grid-rows-[minmax(0,1fr)] border-border max-md:h-1/2 max-md:border-b md:w-1/2 md:border-r`,children:(0,Y.jsx)(re,{resource:t.model.name,recordKey:t.key,url:r.functionSocketUrl(e.call,{key:t.key}),nameOf:e=>i.member(e)?.name??e})})},Ur=({value:e,fallback:t})=>{let n=se(),r=n?.state.kind===`signed-in`?n.state.user.id:void 0,{member:i}=o(),a=Wt(),s=ke(e,r);return s.length===0||!s.every(e=>i(e))?t:s.map((e,t)=>(0,Y.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5`,children:[i(e).name,(0,Y.jsx)(Se,{status:i(e).status,presence:fe(a,e),textShown:s.length===1?`full`:`hover`}),t<s.length-1&&`,`]},e))},Wr=({page:e,scope:t,title:n})=>{let r=e.subtitle===void 0?void 0:t.record[e.subtitle],i=e.members!==void 0;return(0,Y.jsxs)(`div`,{className:`flex h-12 shrink-0 items-center gap-3 border-b border-border bg-background px-4`,children:[(0,Y.jsx)(`h1`,{className:q(i?`flex`:`hidden md:flex`,`min-w-0 items-center gap-2 truncate font-medium`),children:i?(0,Y.jsx)(Ur,{value:t.record[e.members],fallback:n}):n}),typeof r==`string`&&r!==``&&(0,Y.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-sm text-muted-foreground`,children:r}),(0,Y.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-2`,children:[e.call!==void 0&&(0,Y.jsx)(_,{resource:t.model.name,recordKey:t.key}),(0,Y.jsx)(j,{to:{kind:`record`,resource:t.model.name,key:t.key,standard:!0},className:T({variant:`ghost`,size:`sm`}),children:H(`details`)})]})]})},Gr=({onDelete:e,onClose:t})=>(0,Y.jsx)(Jt,{open:!0,title:H(`deleteTitle`),description:H(`deleteDescription`),onClose:t,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(B,{onClick:t,children:H(`cancel`)}),(0,Y.jsx)(B,{variant:`danger`,onClick:e,children:H(`delete`)})]})}),Kr=({controls:e})=>{let{emoji:t,groups:n,onReact:r,thread:i,onEdit:a,onDelete:o}=e,s=new Set(n.filter(e=>e.mine).map(e=>e.emoji)),c=r?t.filter(e=>!s.has(e.emoji)):[];return c.length===0&&!i&&!a&&!o?null:(0,Y.jsxs)(`div`,{role:`toolbar`,"aria-label":H(`messageActions`),className:`pointer-events-none absolute -top-3 right-0 z-10 hidden items-center gap-0.5 rounded-md border border-border bg-background p-0.5 opacity-0 shadow-sm transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 focus-within:pointer-events-auto focus-within:opacity-100 [@media(hover:hover)]:flex`,children:[c.map(({emoji:e,symbol:t,name:n})=>(0,Y.jsx)(B,{size:`icon`,variant:`ghost`,"aria-label":H(`reactWith`,{name:n}),title:n,onClick:()=>r(e),children:(0,Y.jsx)(`span`,{"aria-hidden":!0,children:t})},e)),i&&(0,Y.jsx)(j,{to:i,className:T({variant:`ghost`,size:`sm`}),children:H(`replyInThread`)}),a&&(0,Y.jsx)(B,{size:`sm`,variant:`ghost`,onClick:a,children:H(`edit`)}),o&&(0,Y.jsx)(B,{size:`sm`,variant:`ghost`,onClick:o,children:H(`delete`)})]})},qr=({controls:e,title:t,preview:n,onClose:r})=>{let{emoji:i,groups:a,onReact:o,onUnreact:s,thread:c,onCopy:l,onEdit:u,onDelete:d}=e,f=new Map(a.flatMap(e=>e.mine?[[e.emoji,e.mine]]:[])),p=e=>()=>{r(),e()};return(0,Y.jsx)(Jt,{open:!0,title:t,description:n&&(0,Y.jsx)(`span`,{className:`line-clamp-2`,children:n}),onClose:r,actions:(0,Y.jsxs)(Y.Fragment,{children:[d&&(0,Y.jsx)(B,{variant:`danger`,onClick:p(d),children:H(`delete`)}),u&&(0,Y.jsx)(B,{onClick:p(u),children:H(`edit`)}),l&&(0,Y.jsx)(B,{onClick:p(l),children:H(`copyText`)}),c&&(0,Y.jsx)(j,{to:c,className:T(),onClick:r,children:H(`replyInThread`)})]}),children:i.length>0&&(0,Y.jsx)(`div`,{role:`group`,"aria-label":H(`react`),className:`flex flex-wrap gap-1`,children:i.map(({emoji:e,symbol:t,name:n})=>{let r=f.get(e),i=r?s&&(()=>s(r)):o&&(()=>o(e));return(0,Y.jsx)(B,{size:`icon`,variant:r?`secondary`:`ghost`,"aria-pressed":r!==void 0,"aria-label":H(`reactWith`,{name:n}),disabled:!i,onClick:i&&p(i),children:(0,Y.jsx)(`span`,{"aria-hidden":!0,children:t})},e)})})})},Jr=e=>typeof e==`number`?e:void 0,Yr=(e,t,n)=>{let r=ge(e[n.file]);if(!r)return;let i=`missing`in r?void 0:r;return{key:D(t,e),name:r.name,type:r.type,size:i?.size,url:i?.url,width:n.width===void 0?void 0:Jr(e[n.width]),height:n.height===void 0?void 0:Jr(e[n.height])}},Xr=(e,t,n)=>{let r=new Map;for(let i of e){let e=Yr(i,t,n);if(!e)continue;let a=String(i[n.field]);r.set(a,[...r.get(a)??[],e])}return r},Zr=e=>e.url!==void 0&&vn(e.type),Qr=({attachment:e})=>(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(We,{className:`size-4`}),(0,Y.jsx)(`span`,{className:`max-w-64 truncate`,children:e.name}),e.size!==void 0&&(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:je(e.size)})]}),$r=({attachment:e})=>{let t=T({variant:`secondary`,size:`sm`});return e.url===void 0?(0,Y.jsx)(`span`,{className:t,"aria-disabled":!0,title:H(`fileMissing`),children:(0,Y.jsx)(Qr,{attachment:e})}):(0,Y.jsx)(`a`,{href:e.url,download:e.name,className:t,children:(0,Y.jsx)(Qr,{attachment:e})})},ei=({attachments:e})=>(0,Y.jsx)(`div`,{className:`flex flex-wrap items-start gap-2`,children:e.map(e=>Zr(e)?(0,Y.jsx)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer`,title:e.name,className:`max-w-full`,children:(0,Y.jsx)(`img`,{src:e.url,alt:e.name,width:e.width,height:e.height,style:{maxHeight:240},className:`h-auto w-auto max-w-full rounded-md border border-border object-contain`})},String(e.key)):(0,Y.jsx)($r,{attachment:e},String(e.key)))}),ti=({body:e,picked:t,searchPeople:n,onSave:r,onCancel:i})=>{let[a,o]=(0,X.useState)({text:e,picked:t}),[s,c]=(0,X.useState)(!1),l=(0,X.useRef)(!0);(0,X.useEffect)(()=>(l.current=!0,()=>{l.current=!1}),[]);let u=a.text.trim(),d=async()=>{if(u===``||s)return;if(u===e)return i();c(!0);let t=await r(u,p(u,a.picked));l.current&&(c(!1),t&&i())};return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 whitespace-normal`,children:[(0,Y.jsx)(te,{value:a,onChange:o,searchPeople:n,onKeyDown:e=>{if(!e.nativeEvent.isComposing){if(e.key===`Escape`)return i();e.key!==`Enter`||e.shiftKey||(e.preventDefault(),d())}},readOnly:s,"aria-label":H(`editMessage`),autoFocus:!0}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(B,{size:`sm`,variant:`primary`,disabled:u===``,loading:s,onClick:()=>void d(),children:H(`save`)}),(0,Y.jsx)(B,{size:`sm`,onClick:i,children:H(`cancel`)})]})]})},ni=({groups:e,member:t,onReact:n,onUnreact:r})=>e.map(({emoji:e,symbol:i,name:a,count:o,userIds:s,mine:c})=>{let l=s.map(e=>t(e)?.name??H(`someone`)).join(`, `),u=c?r&&(()=>r(c)):n&&(()=>n(e));return(0,Y.jsxs)(B,{size:`sm`,variant:c?`primary`:`secondary`,"aria-pressed":c!==void 0,"aria-label":H(`reactedBy`,{name:a,people:l}),title:l,disabled:!u,onClick:u,children:[(0,Y.jsx)(`span`,{"aria-hidden":!0,children:i}),(0,Y.jsx)(`span`,{children:o})]},e)}),ri=(e,t=Date.now(),n=Ne())=>H(`lastReply`,{time:`${k(e,t,n)}, ${yt(Date.parse(e),n)}`}),ii=({count:e,last:t,to:n})=>(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 whitespace-normal`,children:[(0,Y.jsx)(j,{to:n,className:`${T({variant:`ghost`,size:`sm`})} -ml-2.5`,children:H(`replies`,{count:e})}),t!==void 0&&(0,Y.jsx)(`time`,{dateTime:t,title:Nt(Date.parse(t)),className:`text-xs text-muted-foreground`,children:ri(t)})]}),ai=(e,t)=>{if(e===void 0||e===!1)return!1;if(e===!0)return!0;let n=pt(e.unless);return n.ok&&!c(n,t)},oi=(e,t,n,r)=>({edit:e.edit===!0&&n&&R(r,`update`)&&m(t,`update`),delete:ai(e.delete,t)&&R(r,`delete`)&&m(t,`delete`)}),si=e=>({react:R(e,`create`),unreact:R(e,`delete`)}),ci=(e,t)=>t.flatMap(t=>Object.hasOwn(e.labels,t)?[{emoji:t,...e.labels[t]}]:[]),li=(e,t)=>{let n=new Map;for(let r of e){let e=String(r[t]);n.set(e,[...n.get(e)??[],r])}return n},ui=(e,{user:t,emoji:n},r,i)=>r.flatMap(({emoji:r,symbol:a,name:o})=>{let s=e.filter(e=>e[n]===r);if(s.length===0)return[];let c=s.map(e=>String(e[t]));return[{emoji:r,symbol:a,name:o,count:s.length,userIds:c,mine:i===void 0?void 0:s.find(e=>e[t]===i)}]}),di=(e,{row:t,key:n,mine:r,body:i,onEdit:a,onDelete:o})=>{let s=le(),{page:c,me:l,writes:u}=e,d=oi(c,t,r,e.messagePermissions),f=si(e.reactionPermissions),p=c.reactions?ui(e.reactionsOf(n),c.reactions,e.emoji,l):[],m=()=>navigator.clipboard.writeText(i).then(()=>void s.show({state:`success`,title:H(`copied`)}),()=>void s.show({state:`error`,title:H(`notCopied`)}));return{emoji:f.react?e.emoji:[],groups:p,onReact:u.react&&f.react?e=>void u.react(n,e):void 0,onUnreact:u.unreact&&f.unreact?e=>void u.unreact(e):void 0,thread:e.threadTo?.(n),onCopy:i===``?void 0:()=>void m(),onEdit:d.edit?a:void 0,onDelete:d.delete?o:void 0}},fi=(e,t)=>t.type===`down`?{press:t.touch&&!t.onControl?{x:t.x,y:t.y,tapOpens:!t.typing}:void 0,open:!1}:t.type===`cancel`?{press:void 0,open:!1}:t.type===`up`?{press:e&&{...e,lifted:!0},open:!1}:t.type===`move`?e?{press:Math.hypot(t.x-e.x,t.y-e.y)>10?void 0:e,open:!1}:{press:e,open:!1}:t.type===`tap`?{press:void 0,open:e?.tapOpens===!0}:e?.lifted?{press:e,open:!1}:{press:void 0,open:e!==void 0},pi=`a[href], button, input, textarea, select, [role="button"]`,mi=`input, textarea, [contenteditable]:not([contenteditable="false"])`,hi=()=>{let e=e=>{e.preventDefault(),e.stopPropagation(),t()},t=()=>{window.removeEventListener(`click`,e,!0),window.removeEventListener(`pointerdown`,t,!0),window.removeEventListener(`keydown`,t,!0)};window.addEventListener(`click`,e,!0),window.addEventListener(`pointerdown`,t,!0),window.addEventListener(`keydown`,t,!0)},gi=e=>{let t=(0,X.useRef)(void 0),n=(0,X.useRef)(void 0),r=(0,X.useRef)(!1),i=e=>{let r=fi(t.current,e);return t.current=r.press,r.press||clearTimeout(n.current),r.open};return(0,X.useEffect)(()=>()=>clearTimeout(n.current),[]),{onPointerDown:a=>{clearTimeout(n.current);let o=a.target instanceof Element&&a.target.closest(pi)!==null,s=document.activeElement instanceof Element&&document.activeElement.matches(mi);i({type:`down`,x:a.clientX,y:a.clientY,touch:a.pointerType===`touch`,onControl:o,typing:s}),r.current=t.current!==void 0,t.current&&(n.current=setTimeout(()=>{i({type:`held`})&&(navigator.vibrate?.(10),hi(),e())},500))},onPointerMove:e=>i({type:`move`,x:e.clientX,y:e.clientY}),onPointerUp:()=>{clearTimeout(n.current),i({type:`up`})},onPointerCancel:()=>i({type:`cancel`}),onClick:()=>{let n=t.current?.tapOpens===!1;i({type:`tap`})&&e(),n&&document.activeElement instanceof HTMLElement&&document.activeElement.blur()},onContextMenu:e=>{r.current&&e.preventDefault()}}},_i=e=>Array.isArray(e)?e.filter(e=>typeof e==`string`):[],vi=({setup:e,row:t,messageKey:n,author:r,time:i,continued:a})=>{let{page:o,me:s,member:c}=e,[l,u]=(0,X.useState)(!1),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),h=gi(()=>m(!0)),g=t[o.text]==null?``:String(t[o.text]),_=s!==void 0&&r.id===s,v=c(r.id)?.name??r.name,y=e.attachmentsOf(n),b=o.mentions===void 0?[]:_i(t[o.mentions]),x=di(e,{row:t,key:n,mine:_,body:g,onEdit:()=>u(!0),onDelete:()=>f(!0)}),S=o.edited===void 0?void 0:t[o.edited],C=o.thread&&e.threadTo?Number(t[o.thread.count]??0):0,w=o.thread&&typeof t[o.thread.last]==`string`?t[o.thread.last]:void 0,ee=x.groups.length>0&&(0,Y.jsx)(ni,{groups:x.groups,member:c,onReact:x.onReact,onUnreact:x.onUnreact}),te=(typeof S==`string`||ee)&&(0,Y.jsxs)(`span`,{className:`flex flex-wrap items-center gap-1`,children:[typeof S==`string`&&(0,Y.jsx)(`span`,{title:H(`editedAt`,{time:Nt(Date.parse(S))}),children:H(`edited`)}),ee]}),E=_?H(`yourMessage`):v?H(`messageFrom`,{name:v}):H(`message`),D=_?H(`showYourActions`):v?H(`showActionsFrom`,{name:v}):H(`showActions`);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{"data-message":n,className:q(`group relative rounded-md [@media(hover:none)]:select-none [@media(hover:none)]:[-webkit-touch-callout:none] [&_a]:[-webkit-touch-callout:default]`,p&&`bg-muted`),...!l&&h,children:[!l&&(0,Y.jsx)(Kr,{controls:x}),!l&&(0,Y.jsx)(`button`,{type:`button`,className:q(T({variant:`secondary`,size:`sm`}),`sr-only focus-visible:not-sr-only focus-visible:absolute focus-visible:right-0 focus-visible:top-0 focus-visible:z-10 [@media(hover:hover)]:hidden`),onClick:()=>m(!0),children:D}),(0,Y.jsxs)(De,{author:{id:r.id,name:v},time:i,continued:a,footer:te,children:[l?(0,Y.jsx)(ti,{body:g,picked:b.flatMap(e=>c(e)?[{id:e,name:c(e).name}]:[]),searchPeople:e.searchPeople,onSave:(t,r)=>e.writes.edit(n,t,r),onCancel:()=>u(!1)}):g!==``&&(0,Y.jsx)(Re,{text:g,mentions:b.map(e=>({name:c(e)?.name}))}),y.length>0&&(0,Y.jsx)(ei,{attachments:y}),C>0&&x.thread&&(0,Y.jsx)(ii,{count:C,last:w,to:x.thread})]})]}),d&&(0,Y.jsx)(Gr,{onClose:()=>f(!1),onDelete:()=>{f(!1),e.writes.remove(n,y)}}),p&&!l&&(0,Y.jsx)(qr,{controls:x,title:E,preview:g,onClose:()=>m(!1)})]})},Z=W(),yi=(e,t)=>({filter:K(e.thread?Z.and(Z.eq(e.field,t),Z.isNull(e.thread.field)):Z.eq(e.field,t)),orderBy:Tt(e.time),pageSize:50}),bi=(e,t,n)=>({filter:K(Z.eq(t.field,n)),orderBy:Tt(e.time),pageSize:50}),xi=(e,t)=>K(Z.in(e.field,[...t])),Si=async(e,t,n)=>{let r=xi(t,n),i=[],a=``;do{let n=await e.list(t.resource,{filter:r,pageSize:500,pageToken:a});i.push(...n.items),a=n.nextPageToken}while(a);return i},Ci=(e,t,n,r)=>K(Z.and(Z.eq(e.field,t),Z.eq(n,r))),wi=(e,t)=>typeof e[t]==`string`?e[t]:void 0,Ti=(e,{key:t,sender:n,time:r},i,a=Date.now())=>e.flatMap((o,s)=>{let c=e[s-1],l=wi(o,r),u=c&&wi(c,r),d=l!==void 0&&(u===void 0||!ce(u,l)),f=t(o)===i,p=l!==void 0&&u!==void 0&&Date.parse(l)-Date.parse(u)<3e5,m=Xn(o[n]),h=!d&&!f&&p&&Xn(c[n]).id===m.id;return[...d?[{kind:`day`,key:`day:${t(o)}`,label:k(l,a)}]:[],...f?[{kind:`new`,key:`new:${t(o)}`}]:[],{kind:`message`,key:t(o),row:o,author:m,time:l,continued:h}]}),Ei=(e,t)=>e.map(e=>Number(t(e))),Di=(e,{key:t,sender:n},r,i,a)=>{if(a&&Math.min(...Ei(e,t))>r)return;let o=e.find(e=>Number(t(e))>r&&Xn(e[n]).id!==i);return o&&t(o)},Oi=(e,t)=>e.length===0?void 0:Math.max(...Ei(e,t)),ki=(e,t)=>{let n=V(),{resources:r}=J(),i=En({queries:(e?t.filter(e=>e.length>0):[]).map(t=>({queryKey:G.attachmentsOf(e.resource,xi(e,t)),queryFn:()=>Si(n,e,t)}))}),a=e&&r[e.resource],o=i.flatMap(e=>e.data??[]);return{byMessage:e&&a?Xr(o,a,e):new Map,error:i.find(e=>e.error)?.error??void 0}},Ai=(e,t)=>{let n=V(),r=En({queries:(e?t.filter(e=>e.length>0):[]).map(t=>({queryKey:G.reactionsOf(e.resource,xi(e,t)),queryFn:()=>Si(n,e,t)}))});return{byMessage:li(r.flatMap(e=>e.data??[]),e?.field??``),error:r.find(e=>e.error)?.error??void 0}},ji=e=>{let t=V(),n=le(),r=ln(),{resources:i}=J(),a=i[e.resource],o=e.reactions,s=(e,t,i)=>i().then(()=>(r(e),!0),e=>(n.show({state:`error`,title:t,description:rn(e)}),!1));return{edit:(n,r,i)=>s(e.resource,H(`notSaved`),()=>t.update(e.resource,n,{[e.text]:r,...e.mentions!==void 0&&{[e.mentions]:i}},`*`)),remove:(n,r)=>s(e.resource,H(`notDeleted`),()=>e.attachments&&r.length>0?t.batchWrite($n(e,a,n,r)):t.remove(e.resource,n)),react:o&&((e,n)=>s(o.resource,H(`reactionNotSaved`),()=>t.create(o.resource,{[o.field]:en(a,e),[o.emoji]:n}))),unreact:o&&(e=>s(o.resource,H(`reactionNotSaved`),()=>t.remove(o.resource,D(i[o.resource],e))))}},Mi=({page:e,me:t,pages:n,threadTo:r,searchPeople:i})=>{let{resources:a}=J(),{member:s}=o(),c=ji(e),l=hn(e.resource),u=hn(e.reactions?.resource??e.resource),d=Ai(e.reactions,n),f=ki(e.attachments,n),p=e.reactions?a[e.reactions.resource]?.fields[e.reactions.emoji]?.enumValues??[]:[];return{setup:{page:e,me:t,member:s,writes:c,emoji:e.reactions?ci(e.reactions,p):[],messagePermissions:l,reactionPermissions:u,reactionsOf:e=>d.byMessage.get(e)??[],attachmentsOf:e=>f.byMessage.get(e)??[],threadTo:r,searchPeople:i},reactionsError:d.error,attachmentsError:f.error}},Ni=(e,t)=>{let[n,r]=(0,X.useState)();if(!n&&e){let e={above:t()};return r(e),e.above}return n?.above},Pi=({page:e,model:t,recordKey:n,me:r,position:i,threadTo:a,searchPeople:o})=>{let{resources:s,views:c}=J(),l=[e.sender],u=ze(t.name,{...yi(e,n),labels:Yt(s,c,t,l)}),d=Et(s,t,l,u.items,u.labels).reverse(),f=e=>String(D(t,e)),{setup:p,reactionsError:m,attachmentsError:h}=Mi({page:e,me:r,pages:(u.data?.pages??[]).map(e=>e.items.map(f)),threadTo:a,searchPeople:o}),g=sr(u),_=g===`messages`&&!u.isLoading&&i.ready,v=Ni(_&&d.length>0&&i.openedAt!==void 0&&r!==void 0,()=>Di(d,{key:f,sender:e.sender},i.openedAt,r,u.hasNextPage));if(g===`error`)return(0,Y.jsx)(`div`,{className:`flex-1 p-4`,children:(0,Y.jsx)(b,{title:H(`couldNotLoad`),error:u.error,onRetry:Yn(u)})});if(!_)return(0,Y.jsx)(`div`,{className:`flex-1 p-4`,children:(0,Y.jsx)(Pe,{children:H(`loadingMessages`)})});let y=Ti(d,{key:f,sender:e.sender,time:e.time},v),x=Oi(d,f),S=y.findLast(e=>e.kind===`message`&&r!==void 0&&e.author.id===r),C=i.readTo;return(0,Y.jsxs)(Y.Fragment,{children:[ir(u)&&(0,Y.jsx)(`div`,{className:`shrink-0 p-2`,children:(0,Y.jsx)(b,{title:H(`couldNotLoad`),error:u.error,onRetry:Yn(u)})}),m!==void 0&&(0,Y.jsx)(`div`,{className:`shrink-0 p-2`,children:(0,Y.jsx)(b,{title:H(`couldNotLoadReactions`),error:m})}),h!==void 0&&(0,Y.jsx)(`div`,{className:`shrink-0 p-2`,children:(0,Y.jsx)(b,{title:H(`couldNotLoadFiles`),error:h})}),(0,Y.jsx)(we,{length:d.length,followKey:S?.key,empty:e.empty??H(`noMessages`),onLoadEarlier:u.hasNextPage?()=>void u.fetchNextPage():void 0,loadingEarlier:u.isFetchingNextPage,onReadToEnd:C&&x!==void 0?()=>C(x):void 0,children:y.map(e=>e.kind===`day`?(0,Y.jsx)(F,{label:e.label},e.key):e.kind===`new`?(0,Y.jsx)(F,{tone:`new`},e.key):(0,Y.jsx)(vi,{setup:p,row:e.row,messageKey:e.key,author:e.author,time:e.time,continued:e.continued},e.key))})]})},Fi=(e,t,n)=>{let r=t.toLocaleLowerCase();return e.filter(e=>e.id!==n&&e.name.toLocaleLowerCase().includes(r)).slice(0,8).map(({id:e,name:t})=>({id:e,name:t}))},Ii=(e,t,n)=>e[t]!=null&&String(e[t])===n,Li=(e,t,n,r)=>{let{resources:i,views:a}=J(),o=I(e.resource,en(t,r)),s=o.data?.record,c=[e.sender],l=t.fields[e.sender],u=e.sender in Yt(i,a,t,c)&&l?.relation?i[l.relation.resource]:void 0,d=u&&s?.[e.sender]!=null?[String(s[e.sender])]:[],f=It(u??t,u&&a[u.name],d),p=s!==void 0&&!Ii(s,e.field,n),[m]=s&&!p?Et(i,t,c,[s],{[e.sender]:Object.fromEntries(f)}):[];return{row:m,elsewhere:p,error:o.error}},Ri=({page:e,owner:t,recordKey:n,first:r,me:i,searchPeople:a,onClose:o})=>{let{resources:s,views:c}=J(),l=s[e.resource],u=[e.sender],d=Li(e,l,n,r),f=ze(e.resource,{...bi(e,e.thread,r),labels:Yt(s,c,l,u)}),p=Et(s,l,u,f.items,f.labels).reverse(),m=e=>String(D(l,e)),{setup:h,reactionsError:g,attachmentsError:_}=Mi({page:e,me:i,pages:[[r],...(f.data?.pages??[]).map(e=>e.items.map(m))],searchPeople:a}),v=d.row,y=d.error??f.error??g??_,S=Ti(p,{key:m,sender:e.sender,time:e.time}),C=S.findLast(e=>e.kind===`message`&&i!==void 0&&e.author.id===i),w=v?Number(v[e.thread.count]??0):0;return(0,Y.jsxs)(x,{title:H(`thread`),onClose:o,footer:!d.elsewhere&&(0,Y.jsx)(nr,{resource:e.resource,field:e.text,values:{[e.field]:en(t,n),[e.thread.field]:en(l,r)},placeholder:H(`replyPlaceholder`),searchPeople:a,mentions:e.mentions,attachments:e.attachments}),children:[y&&(0,Y.jsx)(`div`,{className:`shrink-0 p-2`,children:(0,Y.jsx)(b,{title:H(`couldNotLoadThread`),error:y})}),d.elsewhere?(0,Y.jsx)(`div`,{className:`flex-1 p-4`,children:(0,Y.jsx)(Pe,{children:H(`threadElsewhere`)})}):!v||f.isLoading?(0,Y.jsx)(`div`,{className:`flex-1 p-4`,children:(0,Y.jsx)(Pe,{children:H(`loadingMessages`)})}):(0,Y.jsxs)(we,{length:p.length+1,followKey:C?.key,onLoadEarlier:f.hasNextPage?()=>void f.fetchNextPage():void 0,loadingEarlier:f.isFetchingNextPage,children:[(0,Y.jsx)(vi,{setup:h,row:v,messageKey:r,author:Xn(v[e.sender]),time:typeof v[e.time]==`string`?v[e.time]:void 0,continued:!1}),w>0&&(0,Y.jsx)(F,{label:H(`replies`,{count:w})}),S.map(e=>e.kind===`day`?(0,Y.jsx)(F,{label:e.label},e.key):e.kind===`new`?null:(0,Y.jsx)(vi,{setup:h,row:e.row,messageKey:e.key,author:e.author,time:e.time,continued:e.continued},e.key))]})]})},zi=async(e,t)=>{let n=await e.find();if(!n)throw t;return n},Bi=(e,t,n)=>t.lastRead>=n?t:e.update(t,n),Vi=async(e,t,n)=>{if(t&&t.lastRead>=n)return t;let r=t?e.update(t,n):e.create(n),i=t?412:409;return r.catch(async t=>{if(!tn(t)||t.status!==i)throw t;return Bi(e,await zi(e,t),n)})},Hi=({position:e,model:t,owner:n,recordKey:r,me:i})=>{let a=V(),o=t?.author,s=e!==void 0&&o!==void 0&&i!==void 0,[c,l]=(0,X.useState)(),[u,d]=(0,X.useState)(),f=(0,X.useRef)(void 0),p=(0,X.useRef)(Promise.resolve()),m=(0,X.useCallback)(async()=>{if(!s)return;let{items:n}=await a.list(e.resource,{filter:Ci(e,r,o,i),pageSize:1}),[c]=n;if(c)return{key:String(D(t,c)),lastRead:Number(c[e.message]??0),etag:String(c.etag)}},[a,s,e,t,r,o,i]);(0,X.useEffect)(()=>{s&&m().then(e=>{f.current=e,l(e?.lastRead??0)},d)},[s,m]);let h=(0,X.useMemo)(()=>({find:m,create:async i=>{let o=await a.create(e.resource,{[e.field]:en(n,r),[e.message]:i});return{key:String(D(t,o.record)),lastRead:i,etag:o.etag}},update:async(t,n)=>{let{etag:r}=await a.update(e.resource,t.key,{[e.message]:n},t.etag);return{key:t.key,lastRead:n,etag:r}}}),[a,e,n,r,t,m]),g=(0,X.useCallback)(e=>{p.current=p.current.then(async()=>{f.current=await Vi(h,f.current,e)}).catch(d)},[h]);return{ready:!s||c!==void 0||u!==void 0,openedAt:s?c:void 0,readTo:s&&c!==void 0?g:void 0,error:u}},Ui=(e,t)=>{let{address:n,go:r}=Kt(),i=n?.kind===`record`&&n.resource===e&&n.key===t?n:void 0,a=i?.call&&{call:i.call};return{open:i?.thread,to:n=>({kind:`record`,resource:e,key:t,...a,thread:n}),close:()=>r({kind:`record`,resource:e,key:t,...a})}},Wi=({page:e,scope:t})=>{let{resources:n,views:r}=J(),i=et()(t.model,r[t.model.name],t.record,t.key),a=se(),s=a?.state.kind===`signed-in`?a.state.user.id:void 0,c=o(),l=n[e.resource],u=Hi({position:e.readPosition,model:e.readPosition&&n[e.readPosition.resource],owner:t.model,recordKey:t.key,me:s}),d=e.mentions===void 0?void 0:async e=>Fi(c.data??[],e,s),f=Ui(t.model.name,t.key),p=e.thread&&{...e,thread:e.thread},m=`${t.model.name}/${t.key}`,h=mt();qt(m);let g=de(m),_=e.typing&&h?g:void 0;return(0,Y.jsx)(Vr,{children:(0,Y.jsxs)(`div`,{className:`flex min-h-0 min-w-0`,children:[(0,Y.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,Y.jsx)(Wr,{page:e,scope:t,title:i}),(0,Y.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 max-md:flex-col`,children:[(0,Y.jsx)(Hr,{page:e,scope:t}),(0,Y.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,Y.jsx)(Pi,{page:e,model:l,recordKey:t.key,me:s,position:u,threadTo:p&&f.to,searchPeople:d}),u.error!==void 0&&(0,Y.jsx)(`p`,{className:`shrink-0 px-4 text-sm text-danger-text`,children:H(`positionNotSaved`)}),_&&(0,Y.jsx)(Ze,{channel:m}),(0,Y.jsx)(`div`,{className:`shrink-0 px-3 pb-3`,children:(0,Y.jsx)(nr,{resource:e.resource,field:e.text,values:{[e.field]:en(t.model,t.key)},placeholder:e.placeholder,searchPeople:d,mentions:e.mentions,attachments:e.attachments,onDraft:_?.onText,onSent:e=>{_?.onSent(),h?.store.sent(e)}})})]})]})]}),p&&f.open!==void 0&&(0,Y.jsx)(Ri,{page:p,owner:t.model,recordKey:t.key,first:f.open,me:s,searchPeople:d,onClose:f.close},f.open)]})})},Gi=(e,t,n)=>`protobase:draft:${e}:${t}:${n}`,Ki=(e,t,n)=>lt(()=>{let r=e.getItem(t);if(r===null)return;let i=JSON.parse(r);if(i&&i.etag===n&&typeof i.fields==`object`&&i.fields!==null)return{etag:n,fields:i.fields,...Array.isArray(i.order)&&{order:i.order.map(String)}}},void 0),qi=(e,t,n)=>lt(()=>n?e.setItem(t,JSON.stringify(n)):e.removeItem(t),void 0),Ji=e=>bn(e)??Tr,Yi=({model:e,stored:t,recordKey:n,edit:r,onDelete:i})=>{let a=Kt(),{go:o}=a,s={model:e,record:t.record,key:n,etag:t.etag,permissions:t.permissions},c=Dn(e.name,s,t=>t.run?.kind===`delete`&&o({kind:`list`,resource:e.name},{replace:!0})),[l,u]=(0,X.useState)(),d=c.actions.map(e=>{let n=c.blocked(e),r=e.run?.kind===`link`&&!n?Mn(e.run,t.record,a):void 0;return{name:e.label,icon:Ji(e.icon),blocked:n,running:c.running===e.name,...On(e)&&{tone:`danger`},onRun:()=>kn(e)?u(e):void c.run(e),...r&&{render:({className:e,children:t,role:n})=>(0,Y.jsx)(ot,{to:r,role:n,className:e,children:t})}}}),f=c.actions.some(e=>e.run?.kind===`delete`);return{actions:[...r?[{name:U(`edit`),icon:Wn,render:({className:e,children:t,role:n})=>(0,Y.jsx)(j,{to:r,role:n,className:e,children:t})}]:[],...d,...i&&!f?[{name:U(`delete`),icon:ur,tone:`danger`,onRun:i}]:[]],prompt:l&&(0,Y.jsx)(An,{action:l,label:l.label,danger:On(l),records:[t.record],onCancel:()=>u(void 0),onConfirm:()=>{u(void 0),c.run(l)},onSubmit:async e=>{await c.submit(l,e),u(void 0)}})}},Xi=e=>{let t=f(),{actions:n,prompt:r}=Yi(e);return n.length===0?null:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:t?`max-md:hidden`:void 0,children:(0,Y.jsx)(Nr,{actions:n})}),t&&(0,Pr.createPortal)((0,Y.jsx)(Zt,{actions:n,label:U(`recordActions`),className:`inline-flex size-[min(2.75rem,max(44px,13vw))] shrink-0 items-center justify-center rounded-md text-muted-foreground hover:bg-muted md:hidden [&_svg]:size-[min(1.25rem,max(20px,6vw))]`}),t),r]})},Zi=e=>{let t=typeof e.resource==`string`?e.resource:e.resource.toModel().name;return e.op===`reorder`?`reorder ${t} by ${e.field}`:`${e.op} ${t}`},Qi=(e,t)=>{let n=e.operation,r=n===void 0?void 0:t[n];return r?pn(`operationFailed`,{index:n+1,label:Zi(r),message:e.message}):pn(`nothingSaved`,{message:e.message})},$i=(e,t)=>new e.constructor({...e.problem,detail:Qi(e,t)}),ea=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),ta=({model:e,stored:t,recordKey:n,mode:r,subject:i,draftKey:a,lines:o})=>{let s=V(),c=Sn(),u=P(e.name,n),d=vt(r,i),[f]=(0,X.useState)(()=>a?Ki(localStorage,a,t.etag):void 0),[p,m]=(0,X.useState)(f?.fields??{}),[h,g]=(0,X.useState)(!!f),[_,v]=(0,X.useState)(!1),[y,b]=(0,X.useState)({}),[x,S]=(0,X.useState)({}),[C,w]=(0,X.useState)(0),T=Object.entries(p).filter(([n,r])=>on(e.fields[n],r,t.record[n])),ee=T.length>0,te=ee||!!o?.dirty;(0,X.useEffect)(()=>{f?.order&&o?.setOrder(f.order)},[]),(0,X.useEffect)(()=>{if(!a)return;let n=Object.fromEntries(Object.entries(p).filter(([t])=>!e.fields[t]?.sensitive)),r=Object.keys(n).length>0||!!o?.order;qi(localStorage,a,r?{etag:t.etag,fields:n,...o?.order&&{order:o.order}}:void 0)},[a,e,p,o?.order,t.etag]);let E=n=>n in p?p[n]:[`boolean`,`file`].includes(e.fields[n].type)?t.record[n]:M(t.record[n]),D=(n,r)=>{S(e=>ea(e,n));let i=typeof r==`string`?r!==M(t.record[n]):on(e.fields[n],r,t.record[n]);m(e=>i?{...e,[n]:r}:ea(e,n))},O=async()=>{let r=await s.get(e.name,n);c.setQueryData(G.record(e.name,n),r);let i={},a={};for(let[n,o]of Object.entries(p)){let s=e.fields[n];on(s,o,r.record[n])&&(a[n]=o,M(r.record[n])!==M(t.record[n])&&(i[n]=s.type===`file`?Ie(s,r.record[n]):M(r.record[n])))}m(a),b(i)},ne=()=>Object.fromEntries(T.map(([t,n])=>[t,l(e.fields[t],n)])),k=e=>{let t=fn(e);S(t),Object.keys(t).length>0&&w(e=>e+1)},A=async()=>{try{await u.mutateAsync({patch:ne(),etag:t.etag})}catch(e){throw Ee(e)?await O():tn(e)&&k(e),e}},re=async r=>{let i=ee?[{op:`update`,resource:e.name,key:n,data:ne(),etag:t.etag}]:[],a=[...i,...r.ops];try{await s.batchWrite(a)}catch(e){if(Ee(e))await O(),await c.invalidateQueries({queryKey:[`list`]}),v(!0);else if(tn(e)){let t=e.operation===void 0?-1:e.operation-i.length,n=r.rows[t];t<0?k(e):n&&o?.reject(n,e)}throw tn(e)?$i(e,a):e}await Promise.all([c.invalidateQueries({queryKey:G.record(e.name,n)}),c.invalidateQueries({queryKey:[`list`]}),c.invalidateQueries({queryKey:[`page`]}),c.invalidateQueries({queryKey:[`map`]}),c.invalidateQueries({queryKey:[`aggregate`]})]),o?.reset()};return{value:E,change:D,save:()=>d.run(async()=>{let e=o?.plan();e&&e.ops.length>0?await re(e):await A(),m({}),b({}),S({}),v(!1),g(!1)}),dirty:te,discard:()=>{m({}),b({}),S({}),v(!1),g(!1),o?.reset()},restored:h&&te,dismissRestored:()=>g(!1),linesConflict:_,saving:d.phase===`saving`,phase:d.phase,message:d.message,conflicts:y,errors:x,rejections:C,keepMine:e=>b(t=>ea(t,e)),useTheirs:e=>{b(t=>ea(t,e)),m(t=>ea(t,e))}}},Q=xt(`focus-record`),na=({fields:e,onKeepMine:t,onUseTheirs:n})=>(0,Y.jsx)(Y.Fragment,{children:e.map(({name:e,label:r})=>[(0,Y.jsx)(B,{size:`sm`,onClick:()=>t(e),children:Q(`keepMine`,{field:r})},`mine:${e}`),(0,Y.jsx)(B,{size:`sm`,onClick:()=>n(e),children:Q(`useTheirs`,{field:r})},`theirs:${e}`)])}),ra=({record:e,label:t})=>{let{dirty:n,saving:r,save:i}=e,a=Xt(`primary`),o=Vt()?.size===`compact`,s=(0,Y.jsx)(B,{variant:!a||n?`primary`:`secondary`,loading:r,"aria-disabled":!n,className:`max-md:min-h-11`,onClick:()=>void(n&&!r&&i()),children:t});return o&&!n?null:a?(0,Y.jsx)(Rt,{zone:`secondary`,children:s}):(0,Y.jsx)(Rt,{zone:`primary`,fallback:!0,children:s})},ia=({record:e,saved:t,readOnly:n})=>{let r=Vt()?.size,i=n?Q(`readOnly`):e.saving?Q(`saving`):e.dirty?Q(r===`wide`?`unsaved`:`unsavedShort`):t?Q(`saved`):void 0;return i?(0,Y.jsx)(Rt,{zone:`state`,fallback:!0,children:(0,Y.jsxs)(`span`,{role:`status`,title:n?Q(`readOnlyWhy`):void 0,className:`flex items-center gap-1 truncate`,children:[!n&&!e.dirty&&!e.saving&&(0,Y.jsx)(Qt,{className:`size-3.5 text-success-text`,"aria-hidden":!0}),i]})}):null},aa=({model:e,recordKey:t,stored:n,page:r})=>{let a=J().views[e.name],{address:o,go:s}=Kt(),c=et()(e,a,n.record,t),{state:l}=ne(),u=ta({model:e,stored:n,recordKey:t,mode:`button`,subject:c,draftKey:l.kind===`signed-in`?`${Gi(l.user.id,e.name,t)}:focus`:void 0});bt(u.dirty||u.saving),Ce(u.dirty);let d=Sn(),[f,p]=(0,X.useState)(!1),m=a?.names?.singular??N(e.name),h=hn(e.name),g=qn(e),_=o?.kind===`record`&&o.version!==void 0&&o.version!==Number(n.record.version),v=`surface`in r&&(_n(n.permissions,r.surface)===`read`||e.fields[r.surface]?.readOnly===!0),y=R(h,`update`)&&n.permissions?.update!==!1&&!v,b=!y||_,x=R(h,`delete`)&&n.permissions?.delete!==!1,S=Gn({model:e,view:a,restore:g,onDeleted:()=>s({kind:`list`,resource:e.name},{replace:!0}),onReview:()=>void d.invalidateQueries({queryKey:G.record(e.name,t)})}),{actions:C,prompt:w}=Yi({model:e,stored:n,recordKey:t,onDelete:x?()=>void S.start({key:t,title:c,etag:n.etag,snapshot:n.record}):void 0}),T=(0,X.useMemo)(()=>({kind:`record`,resource:e.name,key:t,standard:!0}),[e.name,t]),ee=C.filter(e=>e.tone===`danger`),te=[...C.filter(e=>e.tone!==`danger`),...u.dirty?[{name:Q(`discardChanges`),icon:Cr,onRun:()=>p(!0)}]:[],{name:Q(`detailsOf`,{noun:m}),icon:xr,render:({className:e,children:t,role:n})=>(0,Y.jsx)(j,{to:T,role:n,className:e,children:t})},...ee],E={model:e,record:n.record,key:t,...n.etag!==void 0&&{etag:n.etag},...n.permissions&&{permissions:n.permissions},readOnly:b,mayUpdate:y,value:u.value,change:(e,t)=>b?void 0:u.change(e,t),dirty:u.dirty,saving:u.saving,refused:u.message!==void 0,save:async()=>!b&&!!await u.save(),discard:u.discard,details:T},D=`surface`in r?r.surface:void 0,O=f&&u.dirty&&(0,Y.jsx)(ht,{level:`draft`,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(B,{size:`sm`,variant:`danger`,onClick:()=>{u.discard(),p(!1)},children:Q(`discardChanges`)}),(0,Y.jsx)(B,{size:`sm`,onClick:()=>p(!1),children:Q(`keep`)})]}),children:Q(`discardAsk`)}),k=Object.keys(u.conflicts).length>0,A=D?u.errors[D]:void 0,re=A&&D?at(e.fields[D],a?.fields[D]?.label??N(D),A):void 0;return(0,Y.jsxs)(Qe.Provider,{value:E,children:[!b&&(0,Y.jsx)(ra,{record:E,label:Q(`save`)}),(0,Y.jsx)(ia,{record:E,saved:u.phase===`saved`,readOnly:b}),(0,Y.jsx)(i,{actions:te}),u.message&&!f&&(0,Y.jsxs)(ht,{level:`refused`,actions:(0,Y.jsx)(j,{to:T,className:`text-body font-medium text-primary-text hover:underline`,children:Q(`detailsOf`,{noun:m})}),children:[(0,Y.jsx)(`strong`,{className:`font-medium`,children:Q(`notSaved`)}),` `,re??u.message]}),k&&(0,Y.jsx)(ht,{level:`conflict`,actions:(0,Y.jsx)(na,{fields:Object.keys(u.conflicts).map(e=>({name:e,label:a?.fields[e]?.label??N(e)})),onKeepMine:u.keepMine,onUseTheirs:u.useTheirs}),children:Q(`conflict`)}),O,u.restored&&!f&&(0,Y.jsx)(ht,{level:`draft`,actions:(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(B,{size:`sm`,onClick:u.dismissRestored,children:Q(`keep`)}),(0,Y.jsx)(B,{size:`sm`,onClick:u.discard,children:Q(`discard`)})]}),children:Q(`restored`)}),D?(0,Y.jsx)(oa,{model:e,name:D,stored:n,editor:u,readOnly:b}):(0,Y.jsx)(sa,{name:r.component,model:e,stored:n,recordKey:t}),S.dialogs,w]})},oa=({model:e,name:t,stored:n,editor:r,readOnly:i})=>{let a=J().views[e.name]?.fields[t];if(_n(n.permissions,t)===`hidden`)throw Error(`The surface's field ${t} is hidden from this reader`);return(0,Y.jsx)(`div`,{className:`absolute inset-0`,children:(0,Y.jsx)(un,{field:e.fields[t],hints:a,value:r.value(t),stored:n.record[t],locked:i,invalid:!!r.errors[t],resource:e.name,onChange:e=>r.change(t,e)})})},sa=({name:e,model:t,stored:n,recordKey:r})=>{let i=A().components?.[e];if(!i)throw Error(`No component is registered as ${e}`);return(0,Y.jsx)(`div`,{className:`absolute inset-0`,children:(0,Y.jsx)(ft,{value:{model:t,record:n.record,key:r,etag:n.etag,permissions:n.permissions},children:(0,Y.jsx)(i,{})})})},ca=({model:e,recordKey:t,stored:n,page:r,standard:i})=>{let a=et()(e,J().views[e.name],n.record,t);return(0,Y.jsx)(it,{name:`surface`in r?r.surface:r.component,fallback:i,resetKey:e,children:(0,Y.jsx)(Dt,{label:a,children:(0,Y.jsx)(aa,{model:e,recordKey:t,stored:n,page:r})})})},la=(0,X.lazy)(()=>xn(()=>import(`./record-map-Dzt7xpK8.js`).then(e=>({default:e.RecordMap})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11]))),ua=15,da=({item:e,record:t})=>{let n=J().maps,r=n?.style,i=jn(t,e);if(!r||!i)return null;let a=(0,Y.jsx)(`div`,{className:`overflow-hidden rounded-lg border border-border bg-muted ${e.sidebar?`h-48`:`h-64 md:h-80`}`,children:(0,Y.jsx)(X.Suspense,{fallback:null,children:(0,Y.jsx)(la,{style:r,layers:n?.layers,position:i,zoom:e.zoom??ua},`${i.latitude},${i.longitude}`)})});return e.sidebar?(0,Y.jsx)(dr,{title:e.title,children:a}):(0,Y.jsx)(E,{title:e.title,children:a})},fa={"1h":`minute`,"24h":`5_minutes`,"7d":`hour`},pa=(e,t,n)=>{let r=new Map;e.forEach((e,i)=>{for(let a of e){let e=Date.parse(`${String(a.value)}Z`),o=r.get(e)??{at:e,value:null,count:0};o[t[i]]=a[n]??null,o.count=Math.max(o.count,a.count),r.set(e,o)}});let i=Object.fromEntries(t.map(e=>[e,null]));return[...r.values()].sort((e,t)=>e.at-t.at).map(e=>({...i,...e}))},ma=xt(`app/record-chart`),ha=W(),ga=[`1h`,`24h`,`7d`],_a={"1h":`hour`,"24h":`day`,"7d":`week`},va=({item:e,recordKey:t})=>{let{resources:n,views:r}=J(),[i,a]=(0,X.useState)(e.range??`1h`),[o,s]=(0,X.useState)(`average`),c=n[e.resource],l=r[e.resource],u=fa[i],d=K(ha.eq(e.field,t)),f=e.series.map(t=>({groupBy:e.at,filter:d,...o===`average`?{average:t}:{maximum:t},range:i,granularity:u,timeZone:Ne()})),p=ye(e.resource,f,!!c);if(!c)return null;let m=e.series.map(e=>({kind:o,field:c.fields[e],...l?.fields[e]&&{hints:l.fields[e]}})),h=e.series.map((e,t)=>({key:`s${t}`,label:l?.fields[e]?.label??N(e),color:`var(--chart-${t+1})`,measure:m[t]})),g=p.every(e=>e.data)?pa(p.map(e=>e.data.groups),h.map(e=>e.key),o):[],_=(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(ae,{label:ma(`measure`),value:o,onChange:s,options:[{value:`average`,label:ma(`average`)},{value:`maximum`,label:ma(`maximum`)}]}),(0,Y.jsx)(ae,{label:ma(`range`),value:i,onChange:a,options:ga.map(e=>({value:e,label:ma(_a[e])}))})]});return(0,Y.jsx)(E,{title:e.title,help:e.help,actions:_,children:p.some(e=>e.error)?(0,Y.jsx)(`p`,{className:`text-danger-text`,children:ma(`couldNotLoad`)}):p.some(e=>e.isPending)?(0,Y.jsx)(z,{className:`h-40 w-full`}):g.every(e=>e.count===0)?(0,Y.jsx)(`p`,{className:`text-muted-foreground`,children:ma(`noSamples`)}):(0,Y.jsx)(Rn,{points:g,measure:m[0],bucket:u,type:`line`,series:h,...h.length>1&&{resource:e.resource,view:l}})})},ya=xt(`app/record-trend`),ba=(e,t)=>ya(`total_${t}`,{count:e}),xa=W(),Sa={kind:`count`},Ca=({item:e,recordKey:t})=>{let n=K(xa.eq(e.field,t)),r=oe(e.resource,{groupBy:e.at,filter:n,granularity:e.granularity,range:e.range,timeZone:Ne()});return(0,Y.jsx)(E,{title:e.title,help:e.help,children:(0,Y.jsx)(`div`,{"aria-busy":r.isPending,children:(()=>{if(r.isPending)return(0,Y.jsx)(z,{className:`h-[calc(10rem+2rem)] w-full`});if(r.error)return(0,Y.jsx)(b,{title:ya(`couldNotLoad`),error:r.error,onRetry:()=>void r.refetch()});let t=r.data.groups.reduce((e,t)=>e+t.count,0);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`p`,{className:`mb-3 leading-5 text-foreground`,children:ba(t,e.range)}),(0,Y.jsx)(Rn,{points:Un(r.data.groups,Sa),measure:Sa,bucket:e.granularity,type:`bar`})]})})()})})},wa=(e=[],t)=>e.includes(t)?e.filter(e=>e!==t):[...e,t],Ta=(e,t=[],n)=>!e.collapsed||t.includes(e.title)||e.items.some(e=>e.kind===`section`&&e.fields.some(n)),Ea=e=>{let t=e.findIndex(e=>e.kind===`tab`);if(t===-1)return{before:e,tabs:[],after:[]};let n=[];for(let r of e.slice(t)){if(r.kind!==`tab`)break;n.push(r)}return{before:e.slice(0,t),tabs:n,after:e.slice(t+n.length)}},Da=(e,t)=>e.find(e=>e.title===t)??e[0],Oa=e=>He(e.items).flatMap(e=>e.kind===`section`?e.fields:[]),ka=(e,t,n)=>{if(t&&!Oa(t).some(n))return e.find(e=>Oa(e).some(n))},Aa={added:[],edits:{},removed:[]},ja=(e,t)=>{let n=[...e.filter(e=>!t.removed.includes(e)),...t.added];return t.order?[...t.order.filter(e=>n.includes(e)),...n.filter(e=>!t.order.includes(e))]:n},Ma=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let i=e.fields[t];return i&&on(i,r,n[t])?[[t,l(i,r)]]:[]})),Na=(e,t)=>Object.fromEntries(Object.entries(t).flatMap(([t,n])=>{let r=e.fields[t];return!r||r.type!==`boolean`&&String(n??``).trim()===``?[]:[[t,l(r,n)]]})),Pa=({model:e,position:t,link:n,stored:r,state:i})=>{let a={ops:[],rows:[]},o=(e,t)=>{a.ops.push(e),a.rows.push(t)},s=new Map(r.map(t=>[Oe(e,t),t])),c=[...s.keys()],l=ja(c,i),u=t=>D(e,s.get(t)),d=e=>{let t=s.get(e).etag;return typeof t==`string`?t:void 0};for(let t of i.removed){if(!s.has(t))continue;let n=d(t);o({op:`delete`,resource:e.name,key:u(t),...n&&{etag:n}},t)}let f=new Set;for(let[t,n]of Object.entries(i.edits)){if(!s.has(t)||i.removed.includes(t))continue;let r=Ma(e,n,s.get(t));if(Object.keys(r).length===0)continue;let a=d(t);o({op:`update`,resource:e.name,key:u(t),data:r,...a&&{etag:a}},t),f.add(t)}let p=l.filter(e=>s.has(e)),m=l.filter(e=>!s.has(e)),h=(e,t)=>Object.fromEntries(e.flatMap(e=>{let n=t||f.has(e)?`*`:d(e);return n?[[xe(u(e)),n]]:[]})),g=(n,r,i)=>({op:`reorder`,resource:e.name,field:t,keys:n,...r!==1&&{start:r},etags:i}),_=(r,a,o)=>({op:`create`,resource:e.name,data:{...Na(e,i.edits[r]??{}),[n.field]:n.value,[t]:a},...o&&{ref:o}}),v=e=>Number(e[t])||0,y=p.some((e,t)=>e!==c.filter(e=>p.includes(e))[t]);if(m.every(e=>l.indexOf(e)>=p.length)){y&&o(g(p.map(u),1,h(p,!1)));let e=y?p.length:Math.max(0,...p.map(e=>v(s.get(e))));return m.forEach((t,n)=>o(_(t,e+1+n),t)),a}let b=Math.max(l.length,...r.map(v))+1;p.length>0&&o(g(p.map(u),b,h(p,!1)));let x=e=>`line${m.indexOf(e)+1}`;for(let e of m)o(_(e,l.indexOf(e)+1,x(e)),e);return o(g(l.map(e=>s.has(e)?u(e):{$ref:x(e)}),1,h(p,!0))),a},Fa=(e,t)=>Object.fromEntries(Object.entries(e).filter(([e])=>e!==t)),Ia=(e,t)=>{let[n,r]=(0,X.useState)(Aa),[i,a]=(0,X.useState)(),o=(0,X.useRef)(1),s=(0,X.useMemo)(()=>new Map(e?t.map(t=>[Oe(e.model,t),t]):[]),[e,t]),c=ja([...s.keys()],n).map(e=>({id:e,stored:s.get(e)})),l=()=>e?Pa({...e,stored:t,state:n}):{ops:[],rows:[]},u=l().ops.length>0,d=(0,X.useMemo)(()=>{let e=ja([...s.keys()],n).filter(e=>s.has(e)),t=[...s.keys()].filter(t=>e.includes(t));return n.order!==void 0&&e.some((e,n)=>e!==t[n])?e:void 0},[s,n]),f=(t,r)=>{let i=n.edits[t];if(i&&r in i)return i[r];let a=e?.model.fields[r],o=s.get(t)?.[r];return a?[`boolean`,`file`].includes(a.type)?o:At(a,o):o},p=e=>a(t=>t?.id===e?void 0:t);return{shown:c,dirty:u,order:d,value:f,change:(e,t,n)=>{p(e),r(r=>({...r,edits:{...r.edits,[e]:{...r.edits[e],[t]:n}}}))},add:()=>{let e=`new:${o.current++}`;return r(t=>({...t,added:[...t.added,e]})),e},remove:e=>{p(e),r(t=>t.added.includes(e)?{...t,added:t.added.filter(t=>t!==e),edits:Fa(t.edits,e)}:{...t,removed:[...t.removed,e]})},setOrder:e=>r(t=>({...t,order:e})),reset:()=>{r(Aa),a(void 0)},reject:(e,t)=>a({id:e,fields:fn(t),message:t.message}),rejection:i,plan:l}},La=(e,t)=>{let n=He(t?.layout??[]).find(e=>e.kind===`related`&&e.lines===!0);if(n?.kind!==`related`)return;let r=e[n.resource],i=r?.fields[n.field],a=r?.position?.field;if(r&&i&&a&&r.position?.within===n.field)return{item:n,model:r,link:i,position:a}},Ra=(e,t,n,r)=>v(e,t).filter(t=>{let i=e.fields[t];return i&&!i.writeOnly&&t!==n&&t!==r&&t!==e.tenant&&!e.primaryKey.includes(t)}),za=(e,t)=>{let{resources:n,views:r}=J(),i=(0,X.useMemo)(()=>La(n,r[e.name]),[n,r,e]),a=i?.model,o=i?Ra(i.model,r[i.model.name],i.link.name,i.position):[],s=Ir(a,i?.link,i?.position,t,a?Yt(n,r,a,o):void 0),c=Ia((0,X.useMemo)(()=>i?{model:i.model,position:i.position,link:{field:i.link.name,value:en(e,t)}}:void 0,[i,e,t]),s.items);return{item:i?.item,model:a,columns:o,data:s,draft:c}},Ba=e=>{let t=e>=5?5:e===4?3:e;return{shown:t,more:e-t}},Va=(e,t)=>Math.abs(e)<40||Math.abs(e)<=Math.abs(t)?0:e<0?1:-1,Ha=e=>e===`ArrowRight`?1:e===`ArrowLeft`?-1:0,Ua=(e,t,n)=>Math.min(Math.max(e+t,0),Math.max(n-1,0)),Wa=e=>e.key===`i`&&!e.ctrlKey&&!e.metaKey&&!e.altKey,Ga=`protobase:lightbox-details`,Ka=e=>lt(()=>e.getItem(Ga)===`true`,!1),qa=(e,t)=>lt(()=>t?e.setItem(Ga,`true`):e.removeItem(Ga),void 0),$=xt(`app/gallery`),Ja=`flex size-10 shrink-0 items-center justify-center rounded-full bg-background/85 text-foreground shadow-sm transition-colors hover:bg-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/40`,Ya=({title:e,photos:t,index:n,onIndex:r,onClose:i,details:o,detailsTitle:s=$(`details`)})=>{let c=(0,X.useRef)(null),l=(0,X.useRef)(void 0),u=(0,X.useId)(),d=$t(),[f,p]=(0,X.useState)(()=>Ka(localStorage)),[m,h]=(0,X.useState)(!1);sn(c,!0,i),(0,X.useEffect)(()=>h(!0),[]);let g=t.length,_=e=>{let t=Ua(n,e,g);t!==n&&r(t)},v=Ve(t[n],{width:1600,height:1200}),y=o?.(n),b=y!==void 0,x=e=>{p(e),qa(localStorage,e)};return(0,Y.jsxs)(`div`,{ref:c,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":e,onKeyDown:e=>{if(b&&Wa(e))return e.preventDefault(),x(!f);let t=Ha(e.key);t!==0&&(e.preventDefault(),_(t))},className:`fixed inset-0 z-[90] flex flex-col overflow-y-auto overscroll-contain bg-backdrop pl-[var(--pb-safe-left)] pr-[var(--pb-safe-right)] outline-none md:flex-row`,children:[(0,Y.jsxs)(`div`,{className:`flex h-dvh shrink-0 flex-col md:sticky md:top-0 md:min-w-0 md:flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-between gap-2 p-3 pt-[calc(0.75rem+var(--pb-safe-top))]`,children:[(0,Y.jsx)(`span`,{className:`rounded-full bg-background/85 px-3 py-1 font-medium tabular-nums text-foreground`,"aria-live":`polite`,children:`${n+1} / ${g}`}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[b&&(0,Y.jsx)(`button`,{type:`button`,className:q(Ja,`aria-expanded:bg-foreground aria-expanded:text-background`),"aria-label":s,"aria-expanded":f,"aria-controls":d?u:void 0,"aria-keyshortcuts":`i`,onClick:()=>x(!f),children:(0,Y.jsx)(yr,{className:`size-4`,"aria-hidden":!0})}),(0,Y.jsx)(`button`,{type:`button`,className:Ja,"aria-label":$(`close`),onClick:i,children:(0,Y.jsx)(jt,{className:`size-4`,"aria-hidden":!0})})]})]}),(0,Y.jsxs)(`div`,{className:`relative flex min-h-0 flex-1 touch-pan-y items-center justify-center px-3 pb-[calc(0.75rem+var(--pb-safe-bottom))] md:px-16`,onPointerDown:e=>{e.pointerType===`touch`&&(l.current={x:e.clientX,y:e.clientY})},onPointerUp:e=>{l.current&&=(_(Va(e.clientX-l.current.x,e.clientY-l.current.y)),void 0)},onPointerCancel:()=>l.current=void 0,children:[v&&(0,Y.jsx)(tt,{image:v,className:`max-h-full max-w-full select-none object-contain`},v.url),g>1&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`button`,{type:`button`,className:q(Ja,`absolute left-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":$(`previousPhoto`),"aria-disabled":n===0,onClick:()=>_(-1),children:(0,Y.jsx)(a,{className:`size-5`,"aria-hidden":!0})}),(0,Y.jsx)(`button`,{type:`button`,className:q(Ja,`absolute right-3 top-1/2 -translate-y-1/2 aria-disabled:cursor-default aria-disabled:opacity-40`),"aria-label":$(`nextPhoto`),"aria-disabled":n===g-1,onClick:()=>_(1),children:(0,Y.jsx)(L,{className:`size-5`,"aria-hidden":!0})})]})]})]}),b&&f&&d&&(0,Y.jsxs)(`aside`,{id:u,"aria-label":s,className:`min-h-dvh w-[360px] shrink-0 border-l border-border bg-background p-5 pt-[calc(1.25rem+var(--pb-safe-top))] text-foreground`,children:[(0,Y.jsx)(`h2`,{className:`mb-3 text-base font-semibold`,children:s}),y]}),(0,Y.jsx)(O,{title:s,open:b&&f&&!d&&m,onClose:()=>x(!1),children:(0,Y.jsx)(`div`,{className:`pt-3`,children:y})})]})},Xa=(e,t,n)=>{let r=He(t?.layout??[]).flatMap(e=>e.kind===`section`&&Ct(e.when,!1)?e.fields:[]);return(r.length>0?[...new Set(r)]:Object.keys(e.fields).filter(t=>t!==e.tenant&&!e.primaryKey.includes(t))).filter(r=>e.fields[r]&&!e.fields[r].sensitive&&!n.includes(r)&&Ct(t?.fields[r]?.when,!1))},Za=({model:e,view:t,photoKey:n,fields:r})=>{let i=I(e.name,n),a=(t?.names?.singular??N(e.name)).toLowerCase();if(i.isPending)return(0,Y.jsx)(z,{className:`h-4 w-48`});if(i.error)return(0,Y.jsx)(b,{title:$(`couldNotLoadOne`,{singular:a}),error:i.error});let o=r.filter(e=>_n(i.data.permissions,e)!==`hidden`);return(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ar,{rows:o.map(n=>({label:t?.fields[n]?.label??N(n),value:(0,Y.jsx)(Le,{model:e,field:e.fields[n],value:i.data.record[n]})}))}),(0,Y.jsx)(j,{to:{kind:`record`,resource:e.name,key:n},className:`mt-3 inline-block font-medium text-primary-text hover:underline`,children:$(`open`,{singular:a})})]})},Qa=e=>Ve(e,{width:0,height:0})!==void 0,$a=(e,t)=>{let n=e.primaryKey.map(e=>t[e]);if(!n.some(e=>e==null))return xe(n)},eo=(e,t,n,r)=>{let i=n===void 0?[]:t.flatMap(e=>{let t=e[n];if(!h(t)||!Qa(t))return[];let i=r&&$a(r,e);return[{file:t,...i!==void 0&&{key:i}}]});if(!h(e)||!Qa(e))return i;let a=t=>h(t.file)&&t.file.uri===e.uri,o=i.find(a)?.key;return[{file:e,...o!==void 0&&{key:o}},...i.filter(e=>!a(e))]},to=W(),no=(e,t,n)=>{let r=V(),{resources:i}=J(),a=e.photos?i[e.photos.resource]:void 0,o=e.photos?K(to.eq(e.photos.field,n)):``,s=e.photos?.sort??``,c=wn({queryKey:G.list(a?.name??``,o,s,500,`gallery`),enabled:a!==void 0,queryFn:async()=>(await r.list(a.name,{filter:o,...s&&{orderBy:s},pageSize:500})).items});return{holder:a,items:eo(e.image===void 0?void 0:t[e.image],c.data??[],e.photos?.image,a),isPending:a!==void 0&&c.isPending,error:c.error}},ro={1:[`md:col-span-4 md:row-span-2`],2:[`md:col-span-2 md:row-span-2`,`md:col-span-2 md:row-span-2`],3:[`md:col-span-2 md:row-span-2`,`md:col-span-2`,`md:col-span-2`],5:[`md:col-span-2 md:row-span-2`,``,``,``,``]},io=({photo:e,large:t})=>{let n=Ve(e,t?{width:960,height:720}:{width:480,height:360});return n?(0,Y.jsx)(tt,{image:n,loading:`lazy`,className:`size-full object-cover transition-transform duration-300 group-hover/tile:scale-[1.02]`}):null},ao=({item:e,record:t,recordKey:n})=>{let{views:r}=J(),i=no(e,t,n),a=hn(i.holder?.name??``),[o,s]=(0,X.useState)();if(i.isPending)return(0,Y.jsx)(E,{title:e.title,children:(0,Y.jsx)(z,{className:`aspect-[4/3] w-full rounded-lg md:aspect-[2/1]`})});if(i.error)return(0,Y.jsx)(E,{title:e.title,children:(0,Y.jsx)(b,{title:$(`couldNotLoad`),error:i.error})});let c=i.items.length;if(c===0)return null;let{shown:l,more:u}=Ba(c),d=i.holder,f=d&&r[d.name],p=d?Xa(d,f,[e.photos?.image,e.photos?.field].filter(e=>e!==void 0)):[],m=d!==void 0&&a.read!==!1&&p.length>0;return(0,Y.jsxs)(E,{title:e.title,children:[(0,Y.jsx)(`div`,{className:`grid aspect-[4/3] grid-cols-4 grid-rows-2 gap-1.5 overflow-hidden rounded-lg md:aspect-[2/1]`,children:i.items.slice(0,l).map((e,t)=>{let n=t===l-1&&u>0;return(0,Y.jsxs)(`button`,{type:`button`,"aria-label":n?$(`showAll`,{count:c}):$(`showPhoto`,{index:t+1,count:c}),onClick:()=>s(t),className:q(`group/tile relative overflow-hidden bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary`,t===0?`col-span-4 row-span-2`:`max-md:hidden`,ro[l][t]),children:[(0,Y.jsx)(io,{photo:e.file,large:t===0}),n&&(0,Y.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center bg-backdrop/55 text-lg font-semibold text-white`,"aria-hidden":!0,children:`+${u}`}),t===0&&c>1&&(0,Y.jsxs)(`span`,{className:`absolute bottom-2 right-2 flex items-center gap-1.5 rounded-full bg-background/85 px-2.5 py-1 text-xs font-medium tabular-nums text-foreground md:hidden`,"aria-hidden":!0,children:[(0,Y.jsx)(_r,{className:`size-3.5`}),c]})]},t)})}),o!==void 0&&(0,Y.jsx)(Ya,{title:e.title,photos:i.items.map(e=>e.file),index:o,onIndex:s,onClose:()=>s(void 0),details:e=>{let t=i.items[e]?.key;return m&&t!==void 0?(0,Y.jsx)(Za,{model:d,view:f,photoKey:t,fields:p},t):void 0},detailsTitle:d&&$(`holderDetails`,{singular:f?.names?.singular??N(d.name)})})]})},oo=xt(`app/history`),so=e=>e.actor?e.actor.name??e.actor.id:e.databaseRole?oo(`databaseRole`,{role:e.databaseRole}):oo(`database`),co=(e,t,n)=>{let r=(e.operation===`create`?[]:e.changed).flatMap(r=>{let i=t.fields[r];if(!i||r===t.softDelete)return[];let a=n?.fields[r],o=a?.label??N(r);return i.sensitive||!e.before||!e.after?[{name:r,label:o}]:[{name:r,label:o,before:Ie(i,e.before[r],a),after:Ie(i,e.after[r],a)}]}),i=e.operation===`update`&&r.length===0?oo(`changedThis`):oo(e.operation);return{who:so(e),verb:i,fields:r}},lo=1500,uo=(e,t,n,r)=>{let i=V(),a=Tn({queryKey:G.history(e,t,n),initialPageParam:``,queryFn:({pageParam:r})=>i.history(e,t,{pageSize:n,pageToken:r}),getNextPageParam:e=>e.nextPageToken||void 0}),{refetch:o}=a;return(0,X.useEffect)(()=>{let e=setTimeout(()=>void o(),lo);return()=>clearTimeout(e)},[r,o]),{...a,items:a.data?.pages.flatMap(e=>e.items)??[]}},fo=()=>(0,Y.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,Y.jsx)(z,{className:`h-4 w-full`},t))}),po=({change:e,model:t,view:n})=>{let{who:r,verb:i,fields:a}=co(e,t,n),o=Date.parse(e.at);return(0,Y.jsxs)(`li`,{className:`flex flex-col gap-1.5 py-3 first:pt-0 last:pb-0`,children:[(0,Y.jsxs)(`p`,{children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:r}),` `,(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:i}),` `,(0,Y.jsxs)(`time`,{dateTime:e.at,title:Nt(o),className:`text-muted-foreground`,children:[`· `,wt(Math.max(0,Math.round((Date.now()-o)/1e3)))]})]}),a.length>0&&(0,Y.jsx)(`dl`,{className:`grid grid-cols-[minmax(0,auto)_minmax(0,1fr)] gap-x-4 gap-y-1`,children:a.map(e=>(0,Y.jsxs)(`div`,{className:`contents`,children:[(0,Y.jsx)(`dt`,{className:`text-muted-foreground`,children:e.label}),(0,Y.jsx)(`dd`,{className:`min-w-0 break-words`,children:e.before===void 0?(0,Y.jsx)(`span`,{className:`text-muted-foreground`,children:`changed`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`del`,{className:`text-muted-foreground`,children:e.before}),` → `,(0,Y.jsx)(`ins`,{className:`no-underline`,children:e.after})]})})]},e.name))})]})},mo=({item:e,model:t,view:n,recordKey:r,etag:i})=>{let a=uo(t.name,r,e.limit??10,i);return(0,Y.jsx)(E,{title:e.title,children:a.isPending?(0,Y.jsx)(fo,{}):a.error?(0,Y.jsx)(b,{title:`Could not load the history`,error:a.error}):a.items.length===0?(0,Y.jsx)(`p`,{className:`text-muted-foreground`,children:`No changes kept yet.`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`ol`,{className:`divide-y divide-border`,children:a.items.map(e=>(0,Y.jsx)(po,{change:e,model:t,view:n},e.id))}),a.hasNextPage&&(0,Y.jsx)(B,{size:`sm`,className:`mt-4`,disabled:a.isFetchingNextPage,onClick:()=>void a.fetchNextPage(),children:`Show more`})]})})},ho=({comment:e})=>(0,Y.jsx)(Re,{text:e.body,mentions:e.mentions}),go=(e,t)=>{let n=V(),r=Sn();return Cn({mutationFn:r=>n.comment(e,t,r),onSuccess:()=>r.invalidateQueries({queryKey:G.comments(e,t)})})},_o=xt(`app/comments`),vo=({resource:e,recordKey:t})=>{let[n,r]=(0,X.useState)(w),i=V(),a=le(),o=go(e,t),s=(0,X.useCallback)(n=>i.mentionable(e,t,n),[i,e,t]);bt(n.text.trim()!==``||o.isPending,`input-lost`);let c=()=>{n.text.trim()===``||o.isPending||o.mutate({body:n.text,mentions:p(n.text,n.picked)},{onSuccess:()=>r(w),onError:e=>a.show({state:`error`,title:_o(`couldNotPost`),description:rn(e)})})};return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(te,{"aria-label":_o(`comment`),placeholder:_o(`placeholder`),value:n,onChange:r,searchPeople:s,onKeyDown:e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),c())}}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(B,{variant:`primary`,size:`sm`,disabled:n.text.trim()===``,loading:o.isPending,onClick:c,children:_o(`comment`)})})]})},yo=20,bo=(e,t)=>{let n=V(),r=Tn({queryKey:G.comments(e,t),initialPageParam:``,queryFn:({pageParam:r})=>n.comments(e,t,{pageSize:yo,pageToken:r}),getNextPageParam:e=>e.nextPageToken||void 0});return{...r,items:r.data?.pages.flatMap(e=>e.items).reverse()??[]}},xo=()=>(0,Y.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,Y.jsx)(z,{className:`h-4 w-full`},t))}),So=({comment:e})=>{let t=e.author.name??e.author.id,n=Date.parse(e.createdAt);return(0,Y.jsxs)(`li`,{className:`flex gap-3 py-3 first:pt-0 last:pb-0`,children:[(0,Y.jsx)(nt,{initials:qe(t)||`?`,hue:Xe(e.author.id),size:`md`,className:`ring-0`}),(0,Y.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,Y.jsxs)(`p`,{children:[(0,Y.jsx)(`span`,{className:`font-medium text-foreground`,children:t}),` `,(0,Y.jsxs)(`time`,{dateTime:e.createdAt,title:Nt(n),className:`text-muted-foreground`,children:[`· `,wt(Math.max(0,Math.round((Date.now()-n)/1e3)))]})]}),(0,Y.jsx)(ho,{comment:e})]})]})},Co=({item:e,resource:t,recordKey:n,canWrite:r})=>{let i=bo(t,n);return(0,Y.jsxs)(E,{title:e.title,children:[i.isPending?(0,Y.jsx)(xo,{}):i.error?(0,Y.jsx)(b,{title:_o(`couldNotLoad`),error:i.error}):(0,Y.jsxs)(Y.Fragment,{children:[i.hasNextPage&&(0,Y.jsx)(B,{size:`sm`,className:`mb-4`,disabled:i.isFetchingNextPage,onClick:()=>void i.fetchNextPage(),children:_o(`showEarlier`)}),i.items.length===0?(0,Y.jsx)(`p`,{className:`text-muted-foreground`,children:_o(`noComments`)}):(0,Y.jsx)(`ol`,{className:`divide-y divide-border`,children:i.items.map(e=>(0,Y.jsx)(So,{comment:e},e.id))})]}),r&&(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsx)(vo,{resource:t,recordKey:n})})]})},wo=e=>e.kind===`group`||e.kind===`tab`?e.items:e.kind===`custom`?e.fallback??[]:[],To=e=>e.kind===`tab`?void 0:e.when,Eo=e=>e.flatMap(e=>[e,...Eo(wo(e))]).filter(e=>Ft(To(e))),Do=e=>(e.fallback??[]).map((t,n)=>[t,e.fallbackAt?.[n]??n]),Oo=(e,t,n,r)=>{let i=0,a=e=>{let a=To(e);return Ft(a)?!r&&t[i++]===!0:Ct(a,n)},o=e=>e.flatMap(e=>{let t=a(e);if(e.kind===`custom`&&e.fallback){let n=e.fallback.map(e=>o([e])),r=n.flatMap((e,t)=>e.length>0?[t]:[]);return t?[{...e,fallback:n.flat(),fallbackAt:r}]:[]}if(e.kind!==`group`&&e.kind!==`tab`)return t?[e]:[];let n=o(e.items);return t&&n.length>0?[{...e,items:n}]:[]});return o(e)},ko=(e,t,n,r)=>{let i=r?[]:Eo(e).map(e=>To(e));return Oo(e,lr(i,t),n,r)},Ao=W(),jo=(e,t)=>{let[n,...r]=e.primaryKey;if(!(!e.tenantAcross||e.tenant===void 0||n===void 0||r.length>0||!e.fields[n]?.filterable))return{filter:K(Ao.eq(n,t)),pageSize:1,fields:[n,e.tenant]}},Mo=(e,t,n)=>{let r=t?.[e.tenant];if(r!=null&&String(r)!==n)return String(r)},No=(e,t)=>{let n=V(),{session:r,organizations:i}=ne(),a=(0,X.useMemo)(()=>i?jo(e,t):void 0,[i,e,t]),[o,s]=(0,X.useState)(a?{state:`looking`}:{state:`missing`});return(0,X.useEffect)(()=>{a&&(async()=>{let[t,i]=await Promise.all([n.list(e.name,a),r.organizations.current()]),o=Mo(e,t.items[0],i.organization?.id);if(o===void 0)return s({state:`missing`});s({state:`switching`}),await r.organizations.switchTo(o),window.location.reload()})().catch(e=>s({state:`failed`,error:e}))},[n,r,e,a]),o},Po=(e,t,n,r)=>{let i=V(),a=Sn(),o=et(),s=Object.values(e.fields).filter(n=>n.type===`relation`&&n.relation&&n.name!==e.tenant&&r[n.name]!=null&&t[n.relation.resource]?.primaryKey.length===1),c=En({queries:s.map(e=>{let o=t[e.relation.resource];return _e(a,i,o,n[o.name],String(r[e.name]))})}),l=s.map(e=>({kind:`record`,resource:e.relation.resource,key:String(r[e.name])}));return{addresses:Object.fromEntries(s.map((e,t)=>[e.name,l[t]])),labels:Object.fromEntries(s.map((e,i)=>{let a=t[e.relation.resource];return[e.name,ie(c[i]?.data,o,a,n[a.name],String(r[e.name]))]}))}},Fo=W(),Io=(e,t,n,r,i)=>{if(e.primaryKey.length!==1)return[];let a=new Set(Lo(r,i).flatMap(e=>e.kind===`thread`?[`${e.resource}.${e.field}`,...e.calls?[`${e.calls.resource}.${e.calls.field}`]:[]]:e.kind===`related`&&!e.through&&!e.from?[`${e.resource}.${e.field}`]:[])),o=Object.values(t).flatMap(t=>Object.values(t.fields).filter(t=>t.type===`relation`&&t.relation?.resource===e.name&&t.relation.columns.length===1&&t.filterable).filter(e=>e.name!==t.tenant&&!a.has(`${t.name}.${e.name}`)).map(e=>({source:t,field:e.name})));return o.map(({source:e,field:t})=>{let r=n[e.name],i=r?.names?.plural??N(e.name),a=o.filter(t=>t.source.name===e.name).length>1;return{resource:e.name,field:t,label:a?`${i} (${r?.fields[t]?.label??N(t)})`:i}})},Lo=(e,t)=>e.flatMap(e=>e.kind===`group`||e.kind===`tab`?Lo(e.items,t):e.kind===`custom`&&!t(e.component)?[e,...Lo(e.fallback??[],t)]:[e]),Ro=(e,t)=>({kind:`list`,resource:e.resource,filter:K(Fo.eq(e.field,t))}),zo=W(),Bo=(e,t,n)=>{let r=V(),i=En({queries:e.map(e=>{let i=K(zo.eq(e.field,n));return{queryKey:G.list(e.resource,i,``,1,`incoming`),queryFn:async()=>{let n=await r.list(e.resource,{filter:i,pageSize:1,count:`exact`,fields:t[e.resource].primaryKey});return{count:n.totalSize??n.totalSizeEstimate,exact:n.totalSize!==void 0}}}})});return e.flatMap((e,t)=>{let n=i[t];return n.error?[]:[{relation:e,count:n.data}]})},Vo=({model:e,recordKey:t,layout:n})=>{let{resources:r,views:i}=J(),{components:a}=A(),o=Bo(Io(e,r,i,n,e=>!!a?.[e]),r,t);return o.length===0?null:(0,Y.jsx)(dr,{title:U(`relatedRecords`),children:(0,Y.jsx)(`ul`,{className:`-mx-2`,children:o.map(({relation:e,count:n})=>(0,Y.jsx)(`li`,{children:(0,Y.jsxs)(j,{to:Ro(e,t),className:`group flex items-center justify-between gap-3 rounded-md px-2 py-2 hover:bg-muted`,children:[(0,Y.jsx)(`span`,{className:`min-w-0 truncate font-medium text-primary-text`,children:e.label}),(0,Y.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 tabular-nums text-muted-foreground`,children:[n===void 0?(0,Y.jsx)(z,{className:`h-4 w-6`}):`${Ge(n.count)}${n.exact?``:`+`}`,(0,Y.jsx)(L,{className:`size-4 text-faint-foreground group-hover:text-foreground`})]})]})},`${e.resource}.${e.field}`))})})},Ho=({count:e,names:t})=>e===null?null:e===void 0?(0,Y.jsx)(z,{className:`inline-block h-5 w-7 rounded-full`}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ut,{dot:!1,className:q(`tabular-nums`,e===0&&`bg-transparent ring-1 ring-border ring-inset`),children:(0,Y.jsx)(`span`,{"aria-hidden":!0,children:e.toLocaleString(mn())})}),(0,Y.jsx)(`span`,{className:`sr-only`,children:t?dt(`headingCount`,{count:e,...t}):dt(`headingCountRecords`,{count:e})})]}),Uo=(e,t,n,r,i)=>{if(!(e.through||t===null)&&me(n,r,i))return{kind:`create`,resource:e.resource,values:{[e.field]:String(t)}}},Wo=({empty:e})=>(0,Y.jsx)(`p`,{className:`text-muted-foreground`,children:e??ar(`nothingYet`)}),Go=(e,t)=>(t?.names?.singular??N(e.name)).toLowerCase(),Ko=({title:e,help:t,count:n,model:r,view:i,filter:a,sort:o,fields:s,button:c,empty:l,add:u})=>{let d=Lt(),{resources:f}=J(),p=o||Ot(r,i),m=y(r,{filter:a,sort:p,pageSize:2});if(m.isPending)return(0,Y.jsx)(E,{title:e,help:t,count:n,children:(0,Y.jsx)(z,{className:`h-24 w-full`})});if(m.error)return(0,Y.jsx)(E,{title:e,help:t,count:n,children:(0,Y.jsx)(b,{title:ar(`couldNotLoad`),error:m.error})});let[h,g]=m.data.items;if(!h){let a=u&&(0,Y.jsxs)(j,{to:u,className:T({size:`sm`}),children:[(0,Y.jsx)(he,{className:`size-3.5`}),ar(`add`,{singular:Go(r,i)})]});return(0,Y.jsx)(E,{title:e,help:t,count:n,actions:a,children:(0,Y.jsx)(Wo,{empty:l})})}let _=ct(r,h),v=Go(r,i),x=i?.names?.plural??N(r.name),S=s.length>1,C=s.map(e=>(0,Y.jsx)(Qn,{scope:_,path:e,labelled:S},e)),w=(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[c&&(0,Y.jsx)(Hn,{button:c,model:r,view:i,record:h,models:f}),(0,Y.jsx)(j,{to:{kind:`record`,resource:r.name,key:D(r,h)},className:T({size:`sm`}),children:ar(`open`,{singular:v})})]});return(0,Y.jsx)(E,{title:e,help:t,count:n,actions:w,children:(0,Y.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[S?(0,Y.jsx)(`dl`,{className:`flex flex-col gap-4`,children:C}):C,g&&(0,Y.jsxs)(j,{to:Ln(r,i,d,{filter:a,orderBy:p,display:zn(i,d,{})}),className:`flex items-center gap-1 self-start font-medium text-primary-text hover:underline`,children:[Fn(`viewAll`),` `,(0,Y.jsx)(`span`,{className:`sr-only`,children:x.toLowerCase()}),(0,Y.jsx)(Pn,{className:`size-3.5`,"aria-hidden":!0})]})]})})},qo=W(),Jo=(...e)=>{let t=e.filter(e=>!!e);return t.length===1?t[0]:t.map(e=>`(${e})`).join(` AND `)},Yo=(e,t,n)=>{let{through:r}=e;if(t===null)return null;if(!r)return Jo(K(qo.eq(e.field,t)),e.filter);let i=r.key??n[r.resource]?.primaryKey[0],a=an(Jo(K(qo.eq(r.field,t)),r.filter));return!a.ok||!i?null:Jo(K(qo.related(e.field,r.resource,i,a.ast)),e.filter)},Xo=e=>{if(e.some(e=>e===null))return null;if(!e.some(e=>e===void 0))return e.reduce((e,t)=>e+t,0)},Zo=(e,t=!0)=>{let n=V(),{resources:r}=J(),i=e.flatMap(({item:e,value:t})=>{let n=r[e.resource];return n?[{model:n,match:Yo(e,t,r)}]:[]}),a=En({queries:i.map(({model:e,match:r})=>({...St(n,e,r??``),enabled:t&&r!==null}))});return Xo(i.map(({match:e},t)=>{if(e===null)return 0;let n=a[t];return n.isError?null:n.isSuccess?n.data??null:void 0}))},Qo=W(),$o=({empty:e})=>(0,Y.jsx)(`p`,{className:`text-muted-foreground`,children:e??U(`nothingYet`)}),es=({item:e,value:t,owner:n})=>{let{resources:r,views:i,pages:a}=J(),o=r[e.resource],s=o&&i[o.name],c=Yo(e,t,r),[l,u]=tr(s,`related:${n}:${e.title}`,e.display),d=hn(e.resource),[f,p]=(0,X.useState)(!1),m=Zo([{item:e,value:t}],!!(e.hideEmpty||e.count));if(!o||e.hideEmpty&&(m===void 0||m===0))return null;let h={title:e.title,help:e.help,count:e.count?(0,Y.jsx)(Ho,{count:m,names:s?.names}):void 0},g=Bn(e,o,r),_=e.columns??v(o,s).filter(t=>t!==e.field),y=t=>c===null?(0,Y.jsx)($o,{empty:e.empty}):t(c);if(e.presentation===`cards`||e.presentation===`compact`){let t=e.presentation===`compact`?{time:e.time}:void 0,n=t?_.filter(t=>t!==e.time):_,r=e.tone===void 0||n.includes(e.tone)?n:[e.tone,...n];return(0,Y.jsx)(E,{...h,children:y(n=>(0,Y.jsx)(Zn,{model:o,view:s,filter:n,sort:e.sort??``,fields:r,actions:e.actions??[],button:e.button,limit:e.limit??10,display:e.display,empty:e.empty,compact:t,tone:e.tone}))})}if(e.presentation===`record`)return c===null?(0,Y.jsx)(E,{...h,children:(0,Y.jsx)($o,{empty:e.empty})}):(0,Y.jsx)(Ko,{...h,model:o,view:s,filter:c,sort:e.sort??``,fields:_,button:e.button,empty:e.empty,add:Uo(e,t,s,a,d)},c);let b=hr(e,o,d),x=(0,Y.jsx)(Vn,{view:s,value:l,onChange:u}),S=b?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!f&&x,(0,Y.jsx)(Jn,{size:`sm`,sorting:f,onChange:p})]}):x;return f&&b?(0,Y.jsx)(E,{...h,actions:S,children:(0,Y.jsx)(Kn,{model:o,view:s,field:b,filter:K(Qo.eq(e.field,t)),columns:_})}):(0,Y.jsx)(E,{...h,actions:S,children:y(t=>(0,Y.jsx)(In,{model:o,view:s,filter:t,sort:e.sort??``,columns:_,limit:e.limit??10,display:l,empty:e.empty,opens:g,button:e.button},t))})},ts=(e,t,n)=>{if(e.from===void 0)return n;let r=t[e.from];return typeof r==`boolean`?r:Nn(t,e.from)??null},ns=({sections:e})=>{let t=Zo(e),{views:n}=J(),r=new Set(e.map(({item:e})=>e.resource)),[i]=r,a=r.size===1?n[i]?.names:void 0;return(0,Y.jsx)(Ho,{count:t,names:a})},rs=(e,t,n,r,i)=>{let a=e.fields.status?.type===`enum`&&!r.includes(`status`)?`status`:void 0,o=t?.titleBadge??a;if(o===void 0||!e.fields[o]||!i(o))return;let s=n[o];if(s!=null&&s!==``)return o},is=W(),as=(e,t)=>K(is.eq(e,t)),os=({item:e,scope:t})=>{let{resources:n}=J(),[r]=lr(e.working===void 0?[]:[e.working],t),i=n[e.resource];if(!i)return null;let a=e.calls&&n[e.calls.resource],o=e.calls&&a&&{model:a,filter:as(e.calls.field,t.key),fields:e.calls};return(0,Y.jsx)(E,{title:e.title,help:e.help,children:(0,Y.jsx)(or,{children:(0,Y.jsx)(er,{model:i,filter:as(e.field,t.key),sender:e.sender,time:e.time,text:e.text,status:e.status,calls:o,limit:e.limit,empty:e.empty,working:e.working===void 0?void 0:r===!0})})})},ss=({item:e,scope:t})=>{let n=e.tree,r=e.reads;return(0,Y.jsx)(_t,{value:t,children:(0,Y.jsxs)(Bt,{tree:n,plan:r,children:[(0,Y.jsx)(pr,{tree:n,plan:r}),(0,Y.jsx)(cr,{node:n,at:``})]})})},cs=ue(()=>xn(()=>import(`./record-lines-hY9wRXCf.js`).then(e=>e.RecordLines),__vite__mapDeps([12,1,2,4,5,6,13,14,15,16,17,18,19,20,21,22,23,24,25])),()=>(0,Y.jsx)(z,{className:`h-32 w-full rounded-lg`})),ls=ue(()=>xn(()=>import(`./composer-section-BiCIOqwU.js`).then(e=>e.ComposerSection),__vite__mapDeps([26,1,2,4,5,6,27,13,14,15,16,17,18,19,20,21,22,23,24,25,28,29,30,31,32,33,34])),()=>(0,Y.jsx)(z,{className:`h-24 w-full rounded-lg`})),us=(e,t)=>t===e.tenant||e.primaryKey.includes(t),ds=(e,t,n)=>{if(t&&t.layout.length>0)return t.layout;let r=Object.values(e.fields).filter(t=>!us(e,t.name)&&!t.writeOnly),i=r.filter(e=>!e.readOnly),a=(i.length>0&&!n?i:r).map(e=>e.name);return[{kind:`section`,title:U(`details`),fields:a},...e.history?[{kind:`history`,title:U(`history`)}]:[],...e.comments?[{kind:`comments`,title:U(`comments`)}]:[]]},fs=({resource:e,recordKey:t})=>{let{resources:n,views:r}=J(),{address:i}=Kt(),a=A(),o=n[e],s=$e(e,t);if(!o)return(0,Y.jsx)(rt,{title:pn(`notFound`),children:pn(`noResource`,{name:e})});if(s.isPending)return(0,Y.jsx)(Gt,{});if(s.error)return(0,Y.jsx)(`div`,{className:`p-8`,children:tn(s.error)&&s.error.status===404?(0,Y.jsx)(ps,{model:o,recordKey:t}):(0,Y.jsx)(b,{title:U(`couldNotLoad`),error:s.error})});let c=(0,Y.jsx)(ms,{model:o,recordKey:t,stored:s.data,preview:s.isPlaceholderData},s.isPlaceholderData?`preview`:`loaded`),l=i?.kind===`record`&&i.file!==void 0&&!s.isPlaceholderData?d(a,o,s.data.record,i.file):void 0,u={kind:`record`,resource:e,key:t,...(r[e]?.recordOpens!==void 0||r[e]?.record!==void 0)&&{standard:!0}};if(l)return(0,Y.jsx)(Mt,{model:o,record:s.data.record,viewed:l,back:u},l.file.uri);let f=i?.kind===`record`&&i.standard===!0,p=r[e]?.recordOpens;if(p&&!f){if(s.isPlaceholderData)return(0,Y.jsx)(Gt,{});let e=Je(p,s.data.record);if(e)return(0,Y.jsx)(mr,{to:e})}let m=r[e]?.record;if(!m||f)return c;if(s.isPlaceholderData)return(0,Y.jsx)(Gt,{});let{record:h,etag:g,permissions:_}=s.data;return`conversation`in m?(0,Y.jsx)(Wi,{page:m.conversation,scope:{model:o,record:h,key:t,etag:g,permissions:_}},t):`surface`in m||m.focus?(0,Y.jsx)(ca,{model:o,recordKey:t,stored:s.data,page:m,standard:c}):(0,Y.jsx)(Br,{component:m.component,scope:{model:o,record:h,key:t,etag:g,permissions:_},standard:c})},ps=({model:e,recordKey:t})=>{let n=No(e,t);return n.state===`looking`?(0,Y.jsx)(Gt,{}):n.state===`switching`?(0,Y.jsx)(rt,{title:U(`loading`),children:U(`openingElsewhere`)}):n.state===`failed`?(0,Y.jsx)(b,{title:U(`couldNotLoad`),error:n.error}):(0,Y.jsx)(rt,{title:pn(`notFound`),children:U(`noRecord`)})},ms=({model:e,recordKey:t,stored:n,preview:r})=>{let i=J(),{address:a,go:o}=Kt(),s=i.views[e.name],c=et()(e,s,n.record,t),{state:l}=ne(),d=za(e,t),f=ta({model:e,stored:n,recordKey:t,mode:s?.saveFeedback??`toast`,subject:c,draftKey:!r&&l.kind===`signed-in`?Gi(l.user.id,e.name,t):void 0,lines:d.draft}),p=Sn(),m=V(),h=nn(f.rejections),_=hn(e.name),v=qn(e),y=a?.kind===`record`&&a.version!==void 0,x=R(_,`update`)&&n.permissions?.update!==!1&&!y,{shown:w,offersEdit:te,editing:D}=Pt(s?.recordMode,x,a?.kind===`record`&&a.edit===!0);bt(f.dirty&&w===`form`||f.saving),Ce(f.dirty);let O=a?.kind===`record`?a.open:void 0,k=a?.kind===`record`&&a.edit===!0,re=a?.kind===`record`?a.tab:void 0,ie=a?.kind===`record`&&a.standard===!0,ae=(n=[],r=!1,i)=>({kind:`record`,resource:e.name,key:t,...r&&{edit:r},...n.length>0&&{open:n},...i&&{tab:i},...ie&&{standard:ie}}),oe=ae(O,!1,re),se=ae(O,!0,re),ce=w===`form`&&s?.recordMode!==void 0&&s.recordMode!==`edit`,le=R(_,`delete`)&&n.permissions?.delete!==!1,ue=Gn({model:e,view:s,restore:v,onDeleted:()=>o({kind:`list`,resource:e.name},{replace:!0}),onReview:()=>void p.invalidateQueries({queryKey:G.record(e.name,t)})}),de=Po(e,i.resources,i.views,n.record),fe=t=>{let n=e.fields[t],r=n?.relation?i.resources[n.relation.resource]:void 0;if(r&&r.primaryKey.length===1&&t!==e.tenant&&!e.primaryKey.includes(t))return r},pe=Object.values(e.fields).filter(e=>fe(e.name)),me={...n.record,...Object.fromEntries(pe.map(e=>[e.name,Fe(e,f.value(e.name))]))},he=Po(e,i.resources,i.views,me),ge=(e,t)=>{let n=fe(e);if(!n||!ut(t))return f.change(e,t);p.setQueryData(G.relatedLabel(n.name,t.key),{label:t.label}),f.change(e,en(n,t.key))},{fields:_e}=A(),ve={model:e,record:n.record,key:t,etag:n.etag,permissions:n.permissions},ye=ko(ds(e,s,w===`read`),ve,D,r),{before:xe,tabs:Se,after:we}=Ea(ye),Ee=Da(Se,re),De=e=>D&&(f.errors[e]!==void 0||f.conflicts[e]!==void 0);(0,X.useEffect)(()=>{if(f.rejections===0)return;let e=ka(Se,Ee,De);e&&o(ae(O,k,e===Se[0]?void 0:e.title),{replace:!0})},[f.rejections]);let M=ye.flatMap(e=>e.kind===`sidebar`?e.fields:[]),Oe=Lr(e,`updated`),P=e=>s?.fields[e],F=t=>_n(n.permissions,t)!==`hidden`&&Ct(P(t)?.when,D)&&(w===`form`||!e.fields[t]?.writeOnly),I=e=>!r||Object.hasOwn(n.record,e),L=rs(e,s,n.record,M,F),ke=L&&(0,Y.jsxs)(Te,{value:n.record[L],hints:P(L),children:[(0,Y.jsxs)(`span`,{className:`sr-only`,children:[P(L)?.label??N(L),`: `]}),Ie(e.fields[L],n.record[L],P(L))]}),Ae=r=>{let a=e.fields[r],o=_n(n.permissions,r);if(!a||o===`hidden`)return null;let c=f.conflicts[r],l=fe(r),u=P(r)?.label??N(r),d=f.errors[r],p=w!==`form`||o===`read`;return(0,Y.jsx)(gn,{name:r,label:u,required:w===`form`&&o!==`read`&&S(a),help:gt(P(r),s,D),error:d&&at(a,u,d),wide:g(_e,a,P(r)),readOnly:Me(a,P(r),p,!!l),conflict:c===void 0?void 0:{user:{name:U(`someoneElse`),initials:`?`,hue:40},ago:U(`justNow`),theirValue:c||`—`,onKeepMine:()=>f.keepMine(r),onUseTheirs:()=>f.useTheirs(r)},children:I(r)?(0,Y.jsx)(un,{field:a,hints:P(r),value:f.value(r),stored:n.record[r],relationLabel:he.labels[r],relationTo:he.addresses[r],relationPicker:l&&{target:l,view:i.views[l.name]},locked:p,invalid:!!f.errors[r],reveal:a.sensitive&&!a.writeOnly?()=>m.reveal(e.name,t,r):void 0,resource:e.name,record:n.record,linkText:P(r)?.format===`url`?cn(e,s,r,n.record,de.labels):void 0,onChange:e=>ge(r,e)}):(0,Y.jsx)(z,{className:`h-9`})},a.sensitive?`${r}:${n.etag}`:r)},je=r=>{let i=e.fields[r],a=I(r)?i.sensitive?(0,Y.jsx)(un,{field:i,hints:P(r),value:``,stored:n.record[r],locked:!0,reveal:()=>m.reveal(e.name,t,r),resource:e.name,onChange:e=>f.change(r,e)}):(0,Y.jsx)(Le,{model:e,field:i,value:n.record[r],relationLabel:de.labels[r],record:n.record,relationLabels:de.labels}):(0,Y.jsx)(z,{className:`h-4 w-32`});return{label:P(r)?.label??N(r),help:gt(P(r),s,D),wide:g(_e,i,P(r)),value:a}},Ne=ye.findIndex(e=>e.kind===`sidebar`),Pe=(0,Y.jsx)(fr,{title:U(`summary`),rows:M.flatMap(t=>{let r=e.fields[t];if(!r||!F(t))return[];if(!I(t))return[{label:P(t)?.label??N(t),value:(0,Y.jsx)(z,{className:`h-4 w-24`})}];let i=n.record[t],a=kt(r,P(t))&&typeof i==`string`&&i!==``,o=r.type===`json`&&i!=null,c=a?be(i):o?C(i):Ie(r,i,P(t)),l=r.type===`text`&&typeof i==`string`&&i!==``?u(P(t)):void 0,d=r.type===`enum`?(0,Y.jsx)(Te,{value:i,hints:P(t),children:c}):l?(0,Y.jsx)(Ye,{format:l,value:c,label:cn(e,s,t,n.record,de.labels)}):(0,Y.jsx)(`span`,{title:ee(r,i,void 0,P(t)),children:c}),f=Ue(_e,r,P(t));return[{label:P(t)?.label??N(t),title:c,value:f?(0,Y.jsx)(yn,{shown:f,part:`display`,field:r,value:n.record[t],fallback:d}):d}]})}),Re=async()=>{await f.save()&&ce&&o(oe,{replace:!0})},ze=le?()=>void ue.start({key:t,title:c,etag:n.etag,snapshot:n.record}):void 0,Be=w===`form`&&(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(B,{variant:`primary`,className:`max-md:min-h-11 max-md:flex-1 md:w-full`,loading:f.saving,disabled:!f.dirty&&f.phase!==`saved`,onClick:()=>void Re(),children:[f.phase===`saved`&&(0,Y.jsx)(Qt,{className:`size-4`}),f.phase===`saved`?U(`saved`):U(`save`)]}),ce&&(0,Y.jsx)(j,{to:oe,className:q(T(),`max-md:min-h-11 md:w-full`),onClick:e=>dn(e)&&f.discard(),children:U(`cancel`)}),f.dirty&&(0,Y.jsx)(`span`,{className:`text-xs text-muted-foreground max-md:order-first`,children:U(`unsavedChanges`)})]}),Ve=(i,a)=>{if(i.kind===`group`){let e=i.items.flatMap(Ve);if(e.length===0)return[];let r=Ta(i,O,De),a=i.collapsed?ae(wa(O,i.title),k,re):void 0,o=i.items.flatMap(e=>e.kind===`related`&&(e.from===void 0||I(e.from))?[{item:e,value:ts(e,n.record,t)}]:[]),s=i.count?(0,Y.jsx)(ns,{sections:o}):void 0;return[(0,Y.jsx)(Or,{title:i.title,help:i.help,count:s,open:r,toggle:a,children:e},`group:${i.title}`)]}if(i.kind===`related`&&i.lines)return!d.model||!d.item||r?[]:[(0,Y.jsx)(cs,{lines:{...d,model:d.model,item:d.item},editable:w===`form`,saving:f.saving},`lines:${i.title}`)];if(i.kind===`related`)return i.from!==void 0&&!I(i.from)?[]:[(0,Y.jsx)(es,{item:i,value:ts(i,n.record,t),owner:e.name},`related:${i.title}`)];if(i.kind===`chart`)return[(0,Y.jsx)(va,{item:i,recordKey:t},`chart:${a}`)];if(i.kind===`trend`)return[(0,Y.jsx)(Ca,{item:i,recordKey:t},`trend:${a}`)];if(r&&(i.kind===`custom`||i.kind===`map`||i.kind===`gallery`||i.kind===`blocks`))return[];if(i.kind===`custom`)return i.sidebar?[]:[(0,Y.jsx)(zr,{item:i,scope:ve,fallback:i.fallback&&(0,Y.jsx)(Y.Fragment,{children:Do(i).flatMap(([e,t])=>Ve(e,t))})},`custom:${a}`)];if(i.kind===`map`)return i.sidebar?[]:[(0,Y.jsx)(da,{item:i,record:n.record},`map:${a}`)];if(i.kind===`gallery`)return[(0,Y.jsx)(ao,{item:i,record:n.record,recordKey:t},`gallery:${a}`)];if(i.kind===`history`)return[(0,Y.jsx)(mo,{item:i,model:e,view:s,recordKey:t,etag:n.etag},`history:${a}`)];if(i.kind===`thread`)return[(0,Y.jsx)(os,{item:i,scope:ve},`thread:${a}`)];if(i.kind===`blocks`)return[(0,Y.jsx)(ss,{item:i,scope:ve},`blocks:${a}`)];if(i.kind===`composer`)return r?[]:[(0,Y.jsx)(ls,{item:i,owner:e,recordKey:t},`composer:${a}`)];if(i.kind===`comments`)return[(0,Y.jsx)(Co,{item:i,resource:e.name,recordKey:t,canWrite:l.kind!==`visitor`},`comments:${a}`)];if(i.kind!==`section`)return[];let o=i.fields.filter(t=>e.fields[t]&&F(t)),c=w===`read`&&i.presentation===`facts`,u=c?st(n.record,o):o;return u.length===0?[]:[(0,Y.jsx)(E,{title:i.title,help:Ht(i.helpWhen,s,D)?i.help:void 0,children:c?(0,Y.jsx)(jr,{facts:u.map(e=>({label:je(e).label,value:je(e).value,icon:bn(P(e)?.icon)}))}):w===`read`?(0,Y.jsx)(Ar,{rows:u.map(je)}):(0,Y.jsx)(`div`,{className:`grid grid-cols-1 gap-x-6 gap-y-5 sm:grid-cols-2`,children:u.map(Ae)})},i.title)]},He=(e,t)=>e.kind===`map`?(0,Y.jsx)(da,{item:e,record:n.record},`map:${t}`):e.kind===`custom`?(0,Y.jsx)(zr,{item:e,scope:ve,fallback:e.fallback&&(0,Y.jsx)(Y.Fragment,{children:Do(e).map(([e,t])=>He(e,t))})},`custom:${t}`):null;return(0,Y.jsxs)(`div`,{ref:h,className:`flex flex-1 flex-col`,inert:r,children:[ue.dialogs,(0,Y.jsx)(`div`,{className:`flex-1`,children:(0,Y.jsxs)(`div`,{className:q(s?.recordWidth!==`full`&&`mx-auto max-w-[1100px]`,`px-4 pb-8 pt-6 md:px-10 md:py-8`),children:[(0,Y.jsx)(Er,{title:c,badge:ke}),f.message&&(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsx)(b,{title:U(`notSaved`),error:Error(f.message)})}),f.linesConflict&&(0,Y.jsx)(`div`,{className:`mt-4`,children:(0,Y.jsx)(b,{title:U(`linesChanged`),error:Error(U(`linesReloaded`))})}),w!==`form`&&te&&f.dirty&&(0,Y.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3 rounded-lg border bg-surface px-3 py-2`,role:`status`,children:[(0,Y.jsx)(`span`,{children:U(`unsavedKept`)}),(0,Y.jsxs)(`span`,{className:`flex gap-2`,children:[(0,Y.jsx)(j,{to:se,className:T({size:`sm`}),children:U(`continueEditing`)}),(0,Y.jsx)(B,{size:`sm`,onClick:f.discard,children:U(`discard`)})]})]}),w===`form`&&f.restored&&(0,Y.jsxs)(`div`,{className:`mt-4 flex items-center justify-between gap-3 rounded-lg border bg-surface px-3 py-2`,role:`status`,children:[(0,Y.jsx)(`span`,{children:U(`unsavedRestored`)}),(0,Y.jsxs)(`span`,{className:`flex gap-2`,children:[(0,Y.jsx)(B,{size:`sm`,onClick:f.dismissRestored,children:U(`keep`)}),(0,Y.jsx)(B,{size:`sm`,onClick:f.discard,children:U(`discard`)})]})]}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-8 md:grid-cols-[minmax(0,1fr)_300px] md:gap-12`,children:[(0,Y.jsxs)(`div`,{className:`divide-y divide-border`,children:[xe.flatMap(Ve),Ee&&(0,Y.jsx)(kr,{tabs:Se.map((e,t)=>({title:e.title,to:ae(O,k,t===0?void 0:e.title),current:e===Ee}))}),Ee&&(0,Y.jsx)(`div`,{className:`divide-y divide-border`,children:Ee.items.flatMap(Ve)},`tab:${Ee.title}`),we.flatMap(Ve)]}),(0,Y.jsxs)(`aside`,{className:`space-y-4 md:sticky md:top-[var(--pb-sticky-top,0px)] md:max-h-[calc(100dvh-var(--pb-sticky-top,0px)-var(--pb-sticky-bottom,0px))] md:self-start md:overflow-y-auto md:pb-4 md:pt-8`,children:[Be&&(0,Y.jsx)(`div`,{className:`hidden flex-col items-center gap-2 md:flex`,children:Be}),!r&&(0,Y.jsx)(Xi,{model:e,stored:n,recordKey:t,edit:te?se:void 0,onDelete:ze}),Ne===-1&&Pe,ye.map((e,t)=>(e.kind===`custom`||e.kind===`map`)&&e.sidebar&&!r?He(e,t):t===Ne?(0,Y.jsx)(X.Fragment,{children:Pe},`summary`):null),(0,Y.jsx)(fr,{title:U(`details`),rows:[Lr(e,`created`),Oe].flatMap(t=>{let r=t?e.fields[t]:void 0;return!t||!r||!F(t)||M.includes(t)?[]:[{label:P(t)?.label??N(t),value:I(t)?(0,Y.jsx)(`span`,{title:ee(r,n.record[t],void 0,P(t)),children:Ie(r,n.record[t],P(t))}):(0,Y.jsx)(z,{className:`h-4 w-24`})}]})}),!r&&(0,Y.jsx)(Vo,{model:e,recordKey:t,layout:ye})]})]})]})}),Be&&(0,Y.jsx)(`div`,{className:`sticky bottom-[var(--pb-sticky-bottom,0px)] z-20 flex shrink-0 items-center gap-2 border-t bg-background p-3 md:hidden`,children:Be})]})};export{fs as RecordPage,Fr as t};
3
- //# debugId=92b0d602-d104-45c6-968a-42dcbf456cdb
@@ -1,3 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/graph-view-IPDrZVmC.js","assets/rolldown-runtime-DFwUHQ4A.js","assets/react-CuiNlnus.js","assets/app-DANB5cb3.js","assets/vendor-t7Q7QbPu.js","assets/app-lQJl2mz_.css","assets/lib-xyflow-system-hojcPWkY.js","assets/lib-d3-interpolate-C7dFwq8w.js","assets/lib-d3-color-B6XHLQii.js","assets/lib-d3-selection-C1a5EtaJ.js","assets/lib-d3-drag-CUJR_Vab.js","assets/lib-d3-dispatch-Bjkn7q4t.js","assets/lib-d3-zoom-DuEhbOrX.js","assets/lib-d3-transition-CUMO2iZu.js","assets/lib-d3-timer-CduGpaSm.js","assets/lib-d3-ease-ouQSXgQM.js","assets/lib-xyflow-react-CuNAzocq.js","assets/lib-classcat-otpLnDWv.js","assets/lib-zustand-r6mNROKr.js","assets/lib-use-sync-external-store-D4s7MiFL.js","assets/lib-xyflow-react-DLioOiRN.css","assets/use-elk-u1Ql5AOs.js","assets/lib-elkjs-ylMkguT9.js"])))=>i.map(i=>d[i]);
2
- (function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{$s as r,A as i,Aa as a,Cc as o,Cl as s,Cn as c,Cr as l,Dc as u,Dl as d,Dn as f,Ec as p,En as m,Fa as h,Fn as g,Fs as _,Ft as v,Ga as y,Gc as b,Gn as x,Hc as S,Hi as C,Hs as w,I as T,Ii as E,Is as ee,It as te,Ja as ne,Js as re,Kn as ie,Kr as D,Ks as ae,Lc as oe,Ls as se,Ml as ce,Mn as le,Mt as ue,N as de,Nn as fe,Nt as pe,O as me,Oa as he,Ol as ge,On as _e,Oo as ve,Pa as ye,Pl as be,Ps as O,Pt as xe,Qc as Se,Qn as Ce,Qs as we,Ra as Te,Ri as Ee,Rs as k,Sa as De,Sc as A,Sn as Oe,Sr as j,Ss as ke,Tc as M,Ti as Ae,Tl as je,Tn as Me,Ts as Ne,Un as Pe,Uo as N,Ur as Fe,Us as Ie,V as Le,Wn as Re,Ws as ze,Xl as Be,Xr as Ve,Xt as P,Ya as He,Yl as Ue,Ys as We,Zi as Ge,Zt as Ke,_c as qe,_r as F,_t as Je,a as Ye,ac as Xe,an as Ze,ao as Qe,as as $e,at as et,b as tt,bc as nt,bn as rt,br as it,c as at,ca as ot,cn as st,co as ct,cr as lt,cs as I,da as ut,dr as dt,ds as L,ec as ft,en as pt,fn as mt,fs as ht,ga as gt,gc as _t,gl as vt,gn as yt,gr as R,gs as bt,gt as xt,ha as St,hc as Ct,hl as wt,hn as Tt,ho as Et,hr as Dt,hs as z,ic as Ot,ir as kt,ja as At,ji as jt,ka as Mt,kc as Nt,ki as Pt,la as Ft,ln as It,ls as Lt,mn as Rt,ms as zt,nc as Bt,nn as Vt,ns as Ht,nu as Ut,oc as Wt,ol as B,oo as V,os as Gt,pc as Kt,pn as qt,pr as Jt,ps as H,qn as Yt,qr as Xt,qs as Zt,rc as Qt,rr as $t,ru as en,sc as tn,sl as U,sn as nn,so as rn,sr as an,ss as W,tc as on,tl as sn,ts as cn,u as ln,un as G,ur as un,us as K,uu as dn,v as fn,vc as pn,vi as mn,vo as hn,vr as gn,vs as q,w as _n,wn as vn,wt as yn,x as bn,xn,xo as Sn,xr as J,xs as Cn,y as wn,yl as Tn,yn as En,yo as Dn,yr as On,ys as kn,z as An,zc as jn,zs as Mn}from"./app-DANB5cb3.js";import{C as Nn,f as Pn,o as Fn,s as In}from"./vendor-t7Q7QbPu.js";import{C as Ln,Ct as Rn,Dt as zn,Et as Bn,O as Vn,Ot as Hn,Q as Un,St as Wn,Tt as Gn,X as Kn,Z as qn,_t as Jn,at as Yn,b as Xn,ct as Zn,dt as Qn,ft as $n,gt as er,it as tr,jt as nr,k as rr,l as ir,lt as ar,mt as or,n as sr,nt as cr,o as lr,ot as ur,rt as dr,st as fr,t as pr,tt as mr,ut as hr,wt as gr,x as _r,xt as vr,y as yr}from"./embedded-list-CepLmiOu.js";import{t as br}from"./circle-alert-BZyGgZSj.js";import{t as xr}from"./page-header-Ddz2r5ic.js";import{n as Sr,t as Cr}from"./pending-invitation-row-Bs60Zx0i.js";import{n as wr,t as Tr}from"./person-row-BH3iAvuG.js";import{n as Er,t as Dr}from"./use-paged-search-DOcO0Rbz.js";import{n as Or,t as kr}from"./client-publisher-D39SlIhp.js";import{t as Ar}from"./copy-field-DpbjVuK4.js";var jr={name:`at-sign`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`4`,key:`4exip2`}],[`path`,{d:`M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-4 8`,key:`7n84p3`}]]};jr.node;var Mr=B(jr),Nr={name:`bot`,size:24,node:[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]};Nr.node;var Pr=B(Nr),Fr={name:`key-square`,size:24,node:[[`path`,{d:`M12.4 2.7a2.5 2.5 0 0 1 3.4 0l5.5 5.5a2.5 2.5 0 0 1 0 3.4l-3.7 3.7a2.5 2.5 0 0 1-3.4 0L8.7 9.8a2.5 2.5 0 0 1 0-3.4z`,key:`165ttr`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`m9.4 10.6-6.814 6.814A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814`,key:`1ubxi2`}]]};Fr.node;var Ir=B(Fr),Lr={name:`laptop`,size:24,node:[[`path`,{d:`M18 5a2 2 0 0 1 2 2v8.526a2 2 0 0 0 .212.897l1.068 2.127a1 1 0 0 1-.9 1.45H3.62a1 1 0 0 1-.9-1.45l1.068-2.127A2 2 0 0 0 4 15.526V7a2 2 0 0 1 2-2z`,key:`1pdavp`}],[`path`,{d:`M20.054 15.987H3.946`,key:`14rxg9`}]]};Lr.node;var Rr=B(Lr),zr={name:`plug-zap`,size:24,node:[[`path`,{d:`M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z`,key:`goz73y`}],[`path`,{d:`m2 22 3-3`,key:`19mgm9`}],[`path`,{d:`M7.5 13.5 10 11`,key:`7xgeeb`}],[`path`,{d:`M10.5 16.5 13 14`,key:`10btkg`}],[`path`,{d:`m18 3-4 4h6l-4 4`,key:`16psg9`}]],aliases:[`plug-zap-2`]};zr.node;var Br=B(zr),Vr={name:`shield-user`,size:24,node:[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M6.376 18.91a6 6 0 0 1 11.249.003`,key:`hnjrf2`}],[`circle`,{cx:`12`,cy:`11`,r:`4`,key:`1gt34v`}]]};Vr.node;var Hr=B(Vr),Ur={name:`smartphone`,size:24,node:[[`rect`,{width:`14`,height:`20`,x:`5`,y:`2`,rx:`2`,ry:`2`,key:`1yt0o3`}],[`path`,{d:`M12 18h.01`,key:`mhygvu`}]]};Ur.node;var Wr=B(Ur),Gr={name:`tablet`,size:24,node:[[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,ry:`2`,key:`76otgf`}],[`line`,{x1:`12`,x2:`12.01`,y1:`18`,y2:`18`,key:`1dp563`}]]};Gr.node;var Kr=B(Gr),qr=[`done`,`error`,`running`];Wt(`TextField`,!1),Wt(`NumberField`,!1),Wt(`DateField`,!1),Wt(`BooleanField`,!1),Wt(`UrlField`,!1),Wt(`ChipField`,!1);var Jr=new Set([`TextField`,`NumberField`,`DateField`,`BooleanField`,`UrlField`,`ChipField`]),Yr=e=>typeof e!=`string`&&!e.custom&&Jr.has(e.type),Xr=e=>typeof e==`string`||Yr(e)||!e.custom&&(e.type===`Link`||e.type===`Trans`||e.type===`Text`&&[`span`,`strong`,`em`].includes(String(e.props.as))),Zr=(e,t)=>e===`BooleanField`?t!==!0&&t!==!1:e===`NumberField`||e===`UrlField`?t==null:t==null||t===``,Qr=e=>typeof e==`object`&&e?JSON.stringify(e):String(e),$r=(e,{locales:t,options:n},r)=>{let i=typeof e==`string`&&e!==``&&!Number.isNaN(Number(e))?Number(e):e;return typeof i==`number`?i.toLocaleString(t??r,n):String(i)},ei=(e,t,n)=>{let r=e instanceof Date?e:typeof e==`string`||typeof e==`number`?new Date(e):void 0;if(!r||Number.isNaN(r.getTime()))return``;if(t.format===`relative`)return n.relative(Math.round((n.now-r.getTime())/1e3));let{showDate:i=!0,showTime:a=!1,options:o}=t,s=t.locales??n.locale;if(i&&a)return r.toLocaleString(s,o);if(a)return r.toLocaleTimeString(s,o);let c=o??(typeof e==`string`&&e.length<=10?{timeZone:`UTC`}:void 0);return r.toLocaleDateString(s,c)},ti=(e,t,n)=>e?t.valueLabelTrue??n.yes:t.valueLabelFalse??n.no,ni=new Set([`http:`,`https:`,`mailto:`,`tel:`]),ri=e=>{let t=e.replace(/^[\u0000- ]+/,``).replace(/[\t\n\r]/g,``),n=/^([A-Za-z][A-Za-z0-9+.-]*):/.exec(t)?.[1];return n===void 0?t.startsWith(`/`)||!t.includes(`:`)?e:void 0:ni.has(`${n.toLowerCase()}:`)?e:void 0},ii=({layout:e,cardWidth:t})=>({layout:e??`stack`,cardWidth:t??`2/3`}),ai=e=>e==null||e===``?void 0:String(e),oi=(e,t)=>e<t?-1:+(e>t),si=({nodes:e,edges:t,key:n,edgeKey:r,fields:i})=>{let a=new Map,o=new Map;for(let t of e){let e=ai(t[n]);if(e===void 0||a.has(e))continue;let r=i.group===void 0?void 0:t[i.group],s=ai(r);s!==void 0&&!o.has(s)&&o.set(s,{id:s,value:r}),a.set(e,{id:e,row:t,...s!==void 0&&{group:s}})}let s=t.flatMap(e=>{let t=r.map(t=>ai(e[t])),n=t.includes(void 0)?void 0:t.length===1?t[0]:JSON.stringify(t),o=ai(e[i.source]),s=ai(e[i.target]);return n===void 0||o===void 0||s===void 0||!a.has(o)||!a.has(s)?[]:[{id:n,source:o,target:s,row:e}]});return{groups:[...o.values()].sort((e,t)=>oi(e.id,t.id)),nodes:[...a.values()].sort((e,t)=>oi(e.id,t.id)),edges:s.sort((e,t)=>oi(e.source,t.source)||oi(e.target,t.target)||oi(e.id,t.id))}},Y=e(t(),1),X=e(n(),1),ci=({model:e,items:t,name:n,label:r,variant:i,className:a})=>{let{views:o}=q(),s=Rn(e.name,void 0),c=Ge(),[l,u]=(0,Y.useState)(!1),d=o[e.name]?.actions?.find(e=>e.name===n);if(!d||d.run?.kind===`link`)return null;let f=t.map(t=>rt(e,t)),p=f.filter(e=>s.verdictOn(d,e)!==`skip`);if(p.length===0)return null;let m=f.length-p.length,h=vr(`actionCount`,{label:r??d.label,count:p.length}),g=e=>s.runEach(d,p,m,e);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{size:`sm`,variant:i??d.variant??`secondary`,className:a,loading:s.running===n,onClick:()=>Bn(d)?u(!0):void g(),children:h}),l&&(0,X.jsx)(Gn,{action:d,label:h,danger:i===`danger`||i===void 0&&zn(d),records:p.map(e=>e.record),names:p.map(t=>Wn(c(e,o[e.name],t.record,t.key))),onCancel:()=>u(!1),onConfirm:()=>{u(!1),g()},onSubmit:async e=>{u(!1),await g(e)}})]})},li=({name:e,resource:t,label:n,variant:r,className:i,about:a,onRun:o})=>{let s=Dt(),c=gr(t??s?.model.name??``,e,t===void 0||t===s?.model.name?s:void 0,e=>o?.(n??e.label)),[l,u]=(0,Y.useState)(!1);if(!c.action)return null;let d=n??c.action.label,f=r??c.action.variant??`secondary`;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{size:`sm`,variant:f,className:i,loading:c.running,disabled:!!c.blocked,title:c.blocked,"aria-label":a===void 0?void 0:`${d}: ${a}`,onClick:()=>Bn(c.action)?u(!0):void c.run(),children:d}),l&&(0,X.jsx)(Gn,{action:c.action,label:d,danger:f===`danger`,records:c.record?[c.record]:[],onCancel:()=>u(!1),onConfirm:()=>{u(!1),c.run()},onSubmit:async e=>{await c.submit(e),u(!1)}})]})},ui=({node:e,className:t})=>{let n=G(e),r=it(),i=r?.model;return i&&(n.resource===void 0||n.resource===i.name)?(0,X.jsx)(ci,{...n,model:i,items:r.items,className:t}):(0,X.jsx)(li,{...n,className:t})},di=({node:e,children:t,slots:n,className:r})=>{let{title:i,description:a}=G(e);return(0,X.jsx)(J,{title:i,description:a,actions:n.actions,className:U(`h-full`,r),children:(0,X.jsx)(`div`,{className:`flex flex-col gap-3`,children:t})})},fi=({children:e,wrap:t=(e,t)=>(0,X.jsx)(Y.Fragment,{children:e},t)})=>{let n=it();if(!n)return null;let{model:r,items:i,planned:a}=n;return i.map((n,o)=>{let s=r?{...rt(r,n),...a&&{planned:a}}:{item:n},c=`key`in s?s.key:o;return t((0,X.jsx)(dt,{value:s,row:{index:o,count:i.length},children:e}),c)})},pi=({children:e})=>(0,X.jsx)(fi,{children:e}),mi=({model:e,at:t,filter:n,sort:r,limit:i=12,title:a,description:o,empty:s,actions:u,children:d,className:f})=>{let p=nn(t),m=c(e,{filter:n,sort:r,pageSize:i,enabled:!p}),h=p??m,g=p?p.rows:m.data?.items??[];return(0,X.jsx)(J,{title:a,description:o,actions:u,className:f,children:h.isPending?(0,X.jsx)(`div`,{className:`flex gap-3`,children:Array.from({length:3},(e,t)=>(0,X.jsx)(A,{className:`h-24 w-56`},t))}):h.error?(0,X.jsx)(l,{title:V(`couldNotLoad`),error:h.error}):g.length===0?(0,X.jsx)(j,{children:s??V(`nothingYet`)}):(0,X.jsx)(`ul`,{className:`relative -mx-4 flex snap-x gap-3 overflow-x-auto px-4 pb-1`,children:(0,X.jsx)(gn,{value:{model:e,items:g,...p&&{planned:!0}},children:(0,X.jsx)(fi,{wrap:(e,t)=>(0,X.jsx)(`li`,{className:`flex w-60 shrink-0 snap-start flex-col gap-2 rounded-lg border border-border bg-surface p-3`,children:e},t),children:d})})})})},hi=({node:e,at:t,children:n,slots:r})=>{let{resource:i,...a}=G(e),o=q().resources[i];return o?(0,X.jsx)(mi,{...a,model:o,...t!==void 0&&{at:t},actions:r.actions,children:n}):null},gi=({node:e,slots:t,className:n})=>{let{resource:r,title:i,description:a,actions:o,span:s,className:c,...l}=G(e),{resources:u,views:d}=q(),f=u[r];return f?(0,X.jsx)(J,{title:i,description:a,actions:t.actions,className:U(`h-full`,n),children:(0,X.jsx)($n,{model:f,view:d[r],...l})}):null},_i=({model:e,query:t,className:n=`mt-4 border-t pt-4`,children:r})=>{let i=Oe(e,t),a=i.isPending?(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(A,{className:`h-4 w-1/2`}),(0,X.jsx)(A,{className:`h-4 w-1/3`})]}):i.error?(0,X.jsx)(l,{title:V(`couldNotLoad`),error:i.error}):i.data?(0,X.jsx)(dt,{value:i.data,children:(0,X.jsx)(`div`,{className:`flex flex-col gap-3`,children:r})}):(0,X.jsx)(j,{children:V(`nothingYet`)});return(0,X.jsx)(`div`,{className:n,children:a})},vi=e=>{if(typeof e!=`string`&&typeof e!=`number`)return;let t=typeof e==`number`?e:Date.parse(e);return Number.isNaN(t)?void 0:t},yi=e=>e==null?``:String(e),bi=(e,t,n)=>n===0?0:(e-t)/n*100,xi=(e,t,n)=>{let r=new Map;for(let i of e){let e=vi(i[t.start]);if(e===void 0)continue;let a=vi(i[t.end]),o=Math.max(e,a??n),s=r.get(yi(i[t.lane]))??{value:i[t.lane],bars:new Map};r.set(yi(i[t.lane]),s);let c=s.bars.get(yi(i[t.bar]))??{value:i[t.bar],records:[]};s.bars.set(yi(i[t.bar]),c),c.records.push({record:i,start:e,end:o,open:a===void 0})}return r},Si=e=>{let t=[];for(let n of[...e].sort((e,t)=>e.start-t.start)){let e=t.find(e=>e.at(-1).end<=n.start);e?e.push(n):t.push([n])}return t},Ci=(e,t,n)=>{let r=xi(e,t,n),i=[...r.values()].flatMap(e=>[...e.bars.values()].flatMap(e=>e.records));if(i.length===0)return{lanes:[],from:n,to:n};let a=Math.min(...i.map(e=>e.start)),o=Math.max(...i.map(e=>e.end)),s=o-a;return{lanes:[...r.entries()].map(([e,n])=>{let r=[...n.bars.entries()].map(([e,r])=>{let i=r.records.sort((e,t)=>e.start-t.start).map(({record:e,start:n,end:r,open:i})=>({record:e,value:e[t.color],start:n,end:r,open:i,left:bi(n,a,s),width:bi(r,a,s)-bi(n,a,s)})),o=i[0].start,c=Math.max(...i.map(e=>e.end));return{key:e,value:r.value,lane:n.value,start:o,end:c,left:bi(o,a,s),width:bi(c,a,s)-bi(o,a,s),segments:i}});return{key:e,value:n.value,rows:Si(r)}}),from:a,to:o}},wi=(e,t)=>{let n=e.end-e.start;return{left:bi(t.start,e.start,n),width:n===0?100:(t.end-t.start)/n*100}},Ti=6e4,Ei=60*Ti,Z=24*Ei,Di=[5*Ti,15*Ti,30*Ti,Ei,3*Ei,6*Ei,12*Ei,Z,2*Z,7*Z,14*Z,30*Z,90*Z,365*Z],Oi=365*Z,ki=(e,t,n,r,i)=>Math.floor((t+i)/n)-Math.ceil((e+r)/n)+1,Ai=(e,t,n=()=>0)=>{let r=t-e;if(r<=0)return{daily:!1,ticks:[]};let i=n(e),a=n(t),o=Di.find(n=>ki(e,t,n,i,a)<=6)??Math.ceil(r/5/Oi)*Oi,s=[];for(let c=Math.ceil((e+i)/o)*o;c<=t+a;c+=o){let a=c-n(c-i);a+n(a)===c&&a>=e&&a<=t&&s.push({at:a,left:bi(a,e,r)})}return{daily:o>=Z,ticks:s}},ji=e=>({lane:yi(e.lane),bar:e.key}),Mi=(e,t)=>t?e.lanes.find(e=>e.key===t.lane)?.rows.flat().find(e=>e.key===t.bar)??null:null,Ni=(e,t)=>{let n=Object.fromEntries(new Intl.DateTimeFormat(`en-US`,{timeZone:t,hourCycle:`h23`,year:`numeric`,month:`numeric`,day:`numeric`,hour:`numeric`,minute:`numeric`}).formatToParts(e).map(e=>[e.type,e.value]));return Date.UTC(Number(n.year),Number(n.month)-1,Number(n.day),Number(n.hour),Number(n.minute))-Math.floor(e/6e4)*6e4},Pi=e=>e<8?`translate-x-0`:e>92?`-translate-x-full`:`-translate-x-1/2`,Fi=({from:e,to:t,dated:n})=>{let r=n?`UTC`:De(),i=e=>n?0:Ni(e,r),{daily:a,ticks:o}=Ai(e,t,i);return(0,X.jsx)(`div`,{"aria-hidden":`true`,className:`relative h-5 min-w-0 flex-1 border-b border-border text-xs text-muted-foreground tabular-nums`,children:o.map(e=>(0,X.jsx)(`span`,{className:`absolute bottom-1 whitespace-nowrap ${Pi(e.left)}`,style:{left:`${e.left}%`},children:a?ut(e.at+i(e.at)):gt(e.at,r)},e.at))})},Ii=(e,t,n)=>{let r=String(n),i=t?.waitingValues?.includes(r)??!1,a=t?.valueColors&&Object.hasOwn(t.valueColors,r)?t.valueColors[r]:void 0;return a!==void 0&&be(a)?{className:zt[a],striped:i}:{color:er(e,t,n===void 0?null:n,-1),striped:i}},Li=e=>({...e.color!==void 0&&{backgroundColor:e.color},...e.striped&&{backgroundImage:`repeating-linear-gradient(-45deg, transparent 0 4px, color-mix(in srgb, var(--background) 55%, transparent) 4px 6px)`}}),Ri=({bar:e,field:t,hints:n})=>e.segments.map((r,i)=>{let a=Ii(t,n,r.value),{left:o,width:s}=wi(e,r);return(0,X.jsx)(`span`,{"aria-hidden":`true`,className:U(`absolute inset-y-0`,a.className),style:{left:`${o}%`,width:`${s}%`,...Li(a)}},i)}),zi=(e,t)=>t?ot(e):Ft(e),Bi=(e,t,n,r,i)=>{let a=e.fields[t.start]?.type===`date`;return V(`timelineRange`,{from:zi(n,a),to:i?V(`timelineNow`):zi(r,a)})},Vi=(e,t,n,r)=>`${Ae(t.fields[r.color],e.value,n?.fields[r.color])}: ${Bi(t,r,e.start,e.end,e.open)}`,Hi=(e,t,n,r,i)=>{let a=e.segments.some(t=>t.open&&t.end===e.end);return[`${i??Ae(t.fields[r.bar],e.value,n?.fields[r.bar])}: ${Bi(t,r,e.start,e.end,a)}`,...e.segments.map(e=>Vi(e,t,n,r))].join(`; `)},Ui=`absolute inset-y-0 flex overflow-hidden rounded-sm ring-offset-1 ring-offset-background outline-none hover:ring-2 hover:ring-border-strong focus-visible:ring-2 focus-visible:ring-primary`,Wi=({bar:e,model:t,view:n,fields:r,point:i,choose:a})=>{let o=q().resources[t.fields[r.bar]?.relation?.resource??``],s=g(o??t,e.key,o!==void 0),c=Hi(e,t,n,r,o?s:void 0),l={onMouseEnter:()=>i.hover(e),onMouseLeave:()=>i.hover(null),onFocus:()=>i.focus(e),onBlur:()=>i.focus(null)},u={left:`${e.left}%`,width:`max(${e.width}%, 4px)`},d=(0,X.jsx)(Ri,{bar:e,field:t.fields[r.color],hints:n?.fields[r.color]});if(!a)return(0,X.jsx)(`span`,{role:`img`,tabIndex:0,"aria-label":c,style:u,className:Ui,...l,children:d});let f=a.chosen===e.key;return(0,X.jsx)(nt,{to:a.barTo(e.key),"aria-label":c,"aria-current":f?`true`:void 0,style:u,className:U(Ui,f&&`ring-2 ring-foreground`),...l,children:d})},Gi=({shape:e,...t})=>{let{model:n,fields:r}=t,i=n.fields[r.lane];return(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(`div`,{className:`flex sm:pl-40`,children:(0,X.jsx)(Fi,{from:e.from,to:e.to,dated:n.fields[r.start]?.type===`date`})}),(0,X.jsx)(`ul`,{className:`flex flex-col gap-3 sm:gap-2`,children:e.lanes.map(e=>(0,X.jsxs)(`li`,{className:`flex flex-col gap-1 sm:flex-row sm:items-center`,children:[(0,X.jsx)(`div`,{className:`min-w-0 truncate text-sm font-medium sm:w-40 sm:shrink-0 sm:pr-3`,children:(0,X.jsx)(Me,{model:n,field:i,value:e.value})}),(0,X.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1 border-l border-border pl-px`,children:e.rows.map((e,n)=>(0,X.jsx)(`div`,{className:`relative h-6 overflow-x-clip`,children:e.map(e=>(0,X.jsx)(Wi,{bar:e,...t},e.key))},n))})]},e.key))})]})},Ki=({model:e,view:t,fields:n,value:r})=>{let i=Ii(e.fields[n.color],t?.fields[n.color],r);return(0,X.jsx)(`span`,{"aria-hidden":`true`,className:U(`inline-block size-3 shrink-0 rounded-sm`,i.className),style:Li(i)})},qi=({values:e,...t})=>{let n=t.model.fields[t.fields.color],r=(n.enumValues??[]).filter(t=>e.has(t));return(0,X.jsx)(`ul`,{className:`flex flex-wrap gap-x-4 gap-y-1.5 text-xs text-muted-foreground`,children:r.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(Ki,{...t,value:e}),Ae(n,e,t.view?.fields[t.fields.color])]},e))})},Ji=({bar:e,...t})=>{let{model:n,view:r,fields:i}=t;if(!e)return(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:V(`timelinePoint`)});let a=e.segments.some(t=>t.open&&t.end===e.end);return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,X.jsxs)(`p`,{className:`flex flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:(0,X.jsx)(Me,{model:n,field:n.fields[i.bar],value:e.value})}),(0,X.jsx)(`span`,{className:`text-muted-foreground tabular-nums`,children:Bi(n,i,e.start,e.end,a)})]}),(0,X.jsx)(`ul`,{className:`flex flex-col gap-0.5 text-xs text-muted-foreground`,children:e.segments.map((e,a)=>(0,X.jsxs)(`li`,{className:`flex items-center gap-1.5 tabular-nums`,children:[(0,X.jsx)(Ki,{...t,value:e.value}),Ae(n.fields[i.color],e.value,r?.fields[i.color]),`: `,Bi(n,i,e.start,e.end,e.open)]},a))})]})},Yi=500,Xi=(e,t,{filter:n=``,sort:r,fields:i,limit:a})=>({queryKey:[...wt.list(t.name,n,r,a,`timeline`),i.join(`,`)],queryFn:async()=>{let o=[],s;do{let c=await e.list(t.name,{filter:n||void 0,orderBy:r,pageSize:Math.min(Yi,a-o.length),fields:i,etag:!1,...s&&{pageToken:s}});o.push(...c.items),s=c.nextPageToken||void 0}while(s&&o.length<a);return{rows:o.toReversed(),cut:s!==void 0}}}),Zi=(e,{enabled:t=!0,...n})=>Fn({...Xi(Ne(),e,n),enabled:t,placeholderData:Pn}),Qi=({model:e,view:t,fields:n,readSort:r,at:i,filter:a,limit:o=on,title:s,description:c,empty:u,actions:d,className:f,choose:p,details:m})=>{let[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(null),y=e=>e?ji(e):null,b={hover:e=>g(y(e)),focus:e=>v(y(e))},x=nn(i),S=Zi(e,{filter:a,sort:r,fields:[...new Set([...Object.values(n),...e.primaryKey])],limit:o,enabled:!x}),C=x??S,w=x?x.rows:S.data?.rows??[],T=!x&&S.data?.cut===!0,E=Ci(w,n,Date.now());return(0,X.jsxs)(J,{title:s,description:c,actions:d,className:U(`h-full`,f),children:[(()=>{if(C.isPending)return(0,X.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,X.jsx)(A,{className:`h-6`},t))});if(C.error)return(0,X.jsx)(l,{title:V(`couldNotLoad`),error:C.error});if(E.lanes.length===0)return(0,X.jsx)(j,{children:u??V(`nothingYet`)});let r=new Set(w.map(e=>String(e[n.color])));return(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsx)(qi,{model:e,view:t,fields:n,values:r}),(0,X.jsx)(Gi,{shape:E,model:e,view:t,fields:n,point:b,...p&&{choose:p}}),T&&(0,X.jsx)(j,{children:V(`timelineCut`,{count:w.length})}),(0,X.jsx)(`div`,{"aria-live":`polite`,children:(0,X.jsx)(Ji,{bar:Mi(E,h)??Mi(E,_),model:e,view:t,fields:n})})]})})(),m]})},$i=(e,t)=>e.type===`integer`?Number(t):t,ea=({select:e,children:t,...n})=>{let{given:r,linkTo:i}=lt(),a=r[e],o=t=>i({[e]:t}),s=n.model.fields[n.fields.bar],c=a===void 0?null:(0,X.jsx)(pn,{name:e,children:(0,X.jsx)(_i,{model:n.model,query:{filter:Jn(s,$i(s,a),n.filter),sort:n.sort},children:t},a)});return(0,X.jsx)(Qi,{...n,choose:{barTo:o,chosen:a},details:c})},ta=({node:e,at:t,slots:n,children:r,className:i})=>{let{className:a,resource:o,select:s,lane:c,bar:l,start:u,end:d,color:f,children:p,...m}=G(e),{resources:h,views:g}=q(),_=h[o];if(!_)return null;let v={...m,model:_,view:g[_.name],fields:{lane:c,bar:l,start:u,end:d,color:f},readSort:Bt(e),sort:Qt(e),...t!==void 0&&{at:t},actions:n.actions,className:i};return s===void 0?(0,X.jsx)(Qi,{...v}):(0,X.jsx)(ea,{...v,select:s,children:r})},na=({node:e,children:t})=>{let n=Xe(e),r=un(),{resources:i}=q();if(!n||!r)return t;let a=r.given[n.param],o=n.resource===void 0?void 0:i[n.resource];return a===void 0||!o?null:(0,X.jsx)(pn,{name:n.param,children:(0,X.jsx)(_i,{model:o,query:{key:a},className:``,children:t},a)})},ra=(0,Y.lazy)(()=>Nn(()=>import(`./graph-view-IPDrZVmC.js`).then(e=>({default:e.GraphView})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22]))),ia=(0,X.jsx)(`div`,{className:`flex h-64 w-full items-center justify-center`,children:(0,X.jsx)(u,{})}),aa=({node:e,at:t,slots:n,children:r,className:i})=>{let a=G(e),o=Ze(e,t),s=un(),c=o.nodes,u=o.edges,{label:d,group:f,status:p,source:m,target:h}=a,g=(0,Y.useMemo)(()=>({label:d,source:m,target:h,...f!==void 0&&{group:f},...p!==void 0&&{status:p}}),[d,m,h,f,p]),_=JSON.stringify([c?.rows,u?.rows,g]),v=(0,Y.useMemo)(()=>c&&u&&si({nodes:c.rows,edges:u.rows,key:c.model.primaryKey[0],edgeKey:u.model.primaryKey,fields:g}),[_]);if(!c||!u||!v)return null;let y=c.error??u.error;if(y&&e.fallback)throw y;if(y)return(0,X.jsx)(l,{title:V(`couldNotLoad`),error:y});if(c.isPending||u.isPending)return ia;if(v.nodes.length===0)return(0,X.jsx)(j,{children:a.empty??V(`nothingYet`)});let b=a.select,x=b!==void 0&&s?{chosen:s.given[b],linkTo:e=>s.linkTo({[b]:e})}:void 0;return(0,X.jsxs)(`div`,{className:U(`flex flex-col gap-4 lg:flex-row`,i),children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(Y.Suspense,{fallback:ia,children:(0,X.jsx)(ra,{shape:v,nodes:c,edges:u,fields:g,props:a,...x&&{select:x},...a.node!==void 0&&{content:n.node}})})}),r.length>0&&x?.chosen!==void 0&&(0,X.jsx)(`div`,{className:`min-w-0 lg:w-80 lg:shrink-0`,children:(0,X.jsx)(na,{node:e,children:r})})]})},oa=({onPick:e,accept:t})=>{let n=(0,Y.useRef)(null);return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`input`,{ref:n,type:`file`,multiple:!0,hidden:!0,accept:t,"aria-label":P(`filesToAttach`),onChange:t=>{e([...t.target.files??[]]),t.target.value=``}}),(0,X.jsx)(M,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":P(`attachFiles`),title:P(`attachFiles`),onClick:()=>n.current?.click(),children:(0,X.jsx)(jn,{className:`size-4`})})]})},sa=`message`,ca=(e,t,n,r)=>[{op:`create`,resource:e,ref:sa,data:t},...r.map(e=>({op:`create`,resource:n.resource,data:{[n.field]:{$ref:sa},[n.file]:e}}))],la=e=>{let t=e.results[0];if(t?.op!==`create`)throw Error(`A message batch starts with the message it creates`);return t.record},ua=(e,t,n,r)=>[...e.attachments?r.map(t=>({op:`delete`,resource:e.attachments.resource,key:t.key})):[],{op:`delete`,resource:e.resource,key:ln(t,n)}],da=(e,t)=>{if(!(t===void 0||e.size<=t))return P(`fileTooLarge`,{size:Ee(e.size),max:Ee(t)})},fa=(e,t,n)=>e.map((e,r)=>({key:t+r,name:e.name,size:e.size,sent:0,refusal:da(e,n)})),pa=e=>e.ticket===void 0&&e.refusal===void 0,ma=e=>e.flatMap(e=>e.ticket===void 0?[]:[e.ticket]),ha=e=>!e.some(pa)&&ma(e).length>0,ga=e=>e.refusal===void 0?e.ticket!==void 0||e.size===0?Ee(e.size):P(`uploadedPercent`,{percent:Math.floor(Math.min(e.sent,e.size)/e.size*100)}):e.refusal,_a=({uploads:e,onRemove:t})=>(0,X.jsx)(`ul`,{"aria-label":P(`filesToSend`),className:`flex flex-wrap gap-2`,children:e.map(e=>(0,X.jsxs)(`li`,{className:`flex max-w-full items-center gap-1 rounded-md border border-border py-0.5 pl-2 text-sm`,children:[(0,X.jsx)(`span`,{className:`min-w-0 max-w-48 truncate`,children:e.name}),(0,X.jsx)(`span`,{role:e.refusal===void 0?void 0:`alert`,className:U(`min-w-0`,e.refusal===void 0?`text-muted-foreground`:`text-danger-text`),children:ga(e)}),(0,X.jsx)(M,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":P(`takeFileOff`,{name:e.name}),title:P(`takeFileOff`,{name:e.name}),onClick:()=>t(e.key),children:(0,X.jsx)(Nt,{className:`size-3.5`})})]},e.key))}),va=e=>{let t=Ne(),{resources:n}=q(),r=e&&n[e.resource]?.fields[e.file]?.file?.maxSize,[i,a]=(0,Y.useState)([]),o=(0,Y.useRef)(0),s=(0,Y.useRef)(new Map),c=(e,t)=>a(n=>n.map(n=>n.key===e?{...n,...t}:n)),l=(e,n,r)=>{let i=new AbortController;s.current.set(n.key,i),t.upload(e.resource,e.file,r,{signal:i.signal,onProgress:e=>c(n.key,{sent:e})}).then(e=>c(n.key,{ticket:e.value}),e=>{i.signal.aborted||c(n.key,{refusal:P(`fileNotUploaded`,{reason:mn(e)})})}).finally(()=>s.current.delete(n.key))};return(0,Y.useEffect)(()=>{let e=s.current;return()=>e.forEach(e=>e.abort())},[]),{uploads:i,tickets:ma(i),uploading:i.some(pa),ready:ha(i),pick:t=>{if(!e||t.length===0)return;let n=fa(t,o.current,r);o.current+=t.length,a(e=>[...e,...n]),n.forEach((n,r)=>{n.refusal===void 0&&l(e,n,t[r])})},remove:e=>{s.current.get(e)?.abort(),a(t=>t.filter(t=>t.key!==e))},sent:e=>a(t=>t.filter(t=>pa(t)||t.ticket!==void 0&&!e.includes(t.ticket)))}},Q=vt(`app/conversation`),ya=({resource:e,field:t,values:n,placeholder:r,searchPeople:i,mentions:a,attachments:o,onDraft:s,onSent:c})=>{let{resources:u}=q(),d=Ne(),f=vn(),p=kn(e),[m,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(),y=va(o);if(!u[e]||!Te(p,`create`))return null;let b=o&&u[o.resource]?.fields[o.file],x=b&&E(b);return(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[_!==void 0&&(0,X.jsx)(l,{title:Q(`notSent`),error:_}),(0,X.jsx)(yn,{onSend:async(r,i)=>{g(!0),v(void 0);let s=y.tickets,l={...n,...r!==``&&{[t]:r},...a!==void 0&&{[a]:i}},p=o&&s.length>0?d.batchWrite(ca(e,l,o,s)).then(la):d.create(e,l).then(e=>e.record),m=u[e],_=await p.then(e=>(c?.(String(h(m,e))),!0),e=>(v(e),!1));return g(!1),_?(f(e),o&&y.sent(s),o&&s.length>0&&f(o.resource),!0):!1},busy:m||y.uploading,placeholder:r,searchPeople:i,onDraft:s,...o&&{actions:(0,X.jsx)(oa,{onPick:y.pick,accept:x}),attachments:y.uploads.length>0&&(0,X.jsx)(_a,{uploads:y.uploads,onRemove:y.remove}),canSendEmpty:y.ready,onFiles:y.pick}})]})},ba=({node:e})=>{let{resource:t,field:n,values:r,placeholder:i}=G(e);return(0,X.jsx)(ya,{resource:t,field:n,values:r,placeholder:i})},xa=({node:e,children:t,className:n})=>{let{open:r}=G(e);return(0,X.jsx)(`details`,{open:r,className:U(`[&[open]>summary]:mb-2`,n),children:t})},Sa=({children:e,className:t})=>(0,X.jsx)(`summary`,{className:U(`cursor-pointer font-medium`,t),children:e}),Ca=({node:e,className:t})=>{let{source:n,emptyText:r}=G(e),i=Tt(n);if(i.state===`missing`)return null;if(i.state===`loading`)return(0,X.jsx)(A,{className:U(`h-24 w-full`,t)});if(i.value===null||i.value===void 0||i.value===``)return r?(0,X.jsx)(`p`,{className:U(`text-sm text-muted-foreground`,t),children:r}):null;let a=String(i.value),o=xt(a);return o?(0,X.jsx)(`div`,{className:U(`flex flex-col gap-3`,t),children:o.map((e,t)=>(0,X.jsx)(Je,{source:e.lines,path:e.path,split:!0,className:`rounded-md border border-border`},`${t}-${e.path}`))}):(0,X.jsx)(`pre`,{className:U(`overflow-x-auto whitespace-pre-wrap break-words rounded-md border border-border bg-background p-3 font-mono text-[0.6875rem] leading-[18px]`,t),children:a})},wa=e=>e==null?``:typeof e==`object`?JSON.stringify(e):String(e),Ta=(e,t)=>{if(t)return t;let n=e.split(`.`).map(e=>ge(e).toLowerCase()).join(` `);return n[0].toUpperCase()+n.slice(1)},Ea=({node:e,className:t})=>{let{source:n,label:r,format:i}=G(e),{views:a}=q(),o=Tt(n);if(o.state===`missing`)return null;let s=o.state===`loading`?(0,X.jsx)(A,{className:`h-4 w-24`}):o.state===`plain`?wa(o.value):(0,X.jsx)(Me,{model:o.model,field:o.field,value:o.value,format:i});if(r===!1)return(0,X.jsx)(`div`,{className:t,children:s});let c=r??Ta(n,o.state===`ready`?a[o.model.name]?.fields[o.field.name]?.label:void 0);return(0,X.jsxs)(`div`,{className:U(`min-w-0`,t),children:[(0,X.jsx)(`div`,{className:`text-body text-muted-foreground`,children:c}),(0,X.jsx)(`div`,{className:`mt-0.5 truncate`,children:s})]})},Da={1:``,2:`md:grid-cols-2`,3:`md:grid-cols-2 xl:grid-cols-3`,4:`sm:grid-cols-2 xl:grid-cols-4`},Oa={1:``,2:`grid-cols-2`,3:`grid-cols-2 xl:grid-cols-3`,4:`grid-cols-2 xl:grid-cols-4`},ka={1:``,2:`md:col-span-2`,3:`md:col-span-2 xl:col-span-3`,4:`sm:col-span-2 md:col-span-2 xl:col-span-4`},Aa=e=>typeof e==`object`&&!e.custom&&e.type===`Stat`,ja=({node:e,children:t,className:n})=>{let{columns:r=2}=G(e),i=e.children,a=i.length>0&&i.every(Aa);return(0,X.jsx)(`div`,{className:U(`grid grid-cols-1 gap-4`,a?Oa[r]:Da[r],n),children:t.map((e,t)=>{let n=i[t],r=typeof n==`object`?n.props.span:void 0;return(0,X.jsx)(`div`,{className:U(`min-w-0`,r&&ka[r]),children:e},t)})})},Ma=({src:e,alt:t,width:n,height:r,className:i})=>(0,X.jsx)(`img`,{src:e,alt:t??``,width:n,height:r,className:i??`max-w-full`}),Na=({width:e,height:t,space:n,theme:r})=>{let i=e??Math.ceil(n/100)*100;if(i!==0)return{width:String(i),...t!==void 0&&{height:String(t)},theme:r}},Pa=e=>({staleTime:1/0,refetchOnWindowFocus:!1,...e!==void 0&&{refetchInterval:e*1e3}}),Fa=e=>e instanceof Blob&&e.type.startsWith(`image/`),Ia=e=>{let[t,n]=(0,Y.useState)();return(0,Y.useEffect)(()=>{if(!e)return n(void 0);let t=URL.createObjectURL(e);return n(t),()=>URL.revokeObjectURL(t)},[e]),t},La=e=>{let[t,n]=(0,Y.useState)();return[t!==void 0&&t===e,()=>n(e)]},Ra=({name:e,alt:t,width:n,height:r,refresh:i,className:a})=>{let o=Ne(),{theme:s}=He(),[c,l]=et(),u=Na({width:n,height:r,space:l,theme:s}),d=Fn({queryKey:wt.image(e,u??{}),enabled:u!==void 0,placeholderData:Pn,...Pa(i),queryFn:async()=>{let t=await o.invoke(e,{query:u,cache:`no-store`});if(!Fa(t))throw Error(`The function "${e}" answered no picture`);return t}}),f=Ia(d.data),[p,m]=La(f),h={...n!==void 0&&{width:n},...r!==void 0&&{height:r}};return(0,X.jsx)(`div`,{ref:c,className:U(`min-w-0`,a),children:d.isError||p?t&&(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:t}):f?(0,X.jsx)(`img`,{src:f,alt:t??``,onError:m,style:h,className:n===void 0?`w-full max-w-full object-contain`:`max-w-full object-contain`}):(0,X.jsx)(A,{className:`w-full max-w-full`,style:{height:r??160,...n!==void 0&&{width:n}}})})},za=({node:e,className:t})=>{let n=G(e);return n.src===void 0?(0,X.jsx)(Ra,{name:n.function,alt:n.alt,width:n.width,height:n.height,refresh:n.refresh,className:t}):(0,X.jsx)(Ma,{src:n.src,alt:n.alt,width:n.width,height:n.height,className:t})},Ba=e=>function({node:t,className:n}){let r=G(t),{views:i}=q(),a=Tt(r.source);return a.state===`missing`?null:a.state===`loading`?(0,X.jsx)(A,{className:`inline-block h-3 w-16 align-middle`}):Zr(t.type,a.value)?r.emptyText?(0,X.jsx)(`span`,{className:n,children:r.emptyText}):null:a.state===`plain`?(0,X.jsx)(`span`,{className:n,children:e({value:a.value,field:void 0,hints:void 0,props:r})}):(0,X.jsx)(`span`,{className:n,children:e({value:a.value,field:a.field,hints:i[a.model.name]?.fields[a.field.name],props:r})})},Va=({value:e,field:t,hints:n})=>t?.type===`enum`&&typeof e==`string`?d(e,n?.valueLabels):Qr(e),Ha=Ba(Va),Ua=Ba(({value:e,props:t})=>(0,X.jsx)(`span`,{className:`tabular-nums`,children:$r(e,t,Tn())})),Wa=Ba(({value:e,props:t})=>{let n=ei(e,t,{locale:Tn(),now:Date.now(),relative:St});return(0,X.jsx)(`time`,{dateTime:String(e),children:n})}),Ga=Ba(({value:e,props:t})=>{let n=ti(e,t,{yes:C(`yes`),no:C(`no`)});return e?(0,X.jsx)(Ce,{label:n,className:`align-middle`}):(0,X.jsx)(`span`,{className:`text-faint-foreground`,children:n})}),Ka=Ba(({value:e,props:t})=>{let n=String(e),r=t.content??n,i=ri(n);return i===void 0?r:(0,X.jsx)(`a`,{href:i,className:`font-medium text-primary-text hover:underline`,.../^https?:/i.test(i)&&{target:`_blank`,rel:`noreferrer`},children:r})}),qa=Ba(e=>(0,X.jsx)(fe,{value:e.value,hints:e.hints,children:Va(e)})),Ja=`font-medium text-primary-text hover:underline`,Ya=({node:e,children:t,className:n})=>{let r=G(e),i={...F(R()),params:an()},a=r.variant?U(p({variant:r.variant}),n):n??Ja,o=e.children.some(e=>typeof e!=`string`||e.trim()!==``)?t:void 0;if(r.to){let e=Ut(r.to,Ie(i));return(0,X.jsx)(D,{to:e,className:a,children:o??Kt(e)})}let s=r.href??``;return(0,X.jsx)(`a`,{href:s,className:a,...s.startsWith(`http`)&&{target:`_blank`,rel:`noreferrer`},children:o??s})},Xa=(e,t,n)=>Object.fromEntries(t.map(t=>{let r=e.fields[t];if(r.type===`file`)return[t,n?.[t]??null];if(n)return[t,r.type===`boolean`?!!n[t]:me(n[t])];let i=r.default&&`value`in r.default?r.default.value:void 0;return[t,r.type===`boolean`?!!i:me(i)]})),Za=(e,t,n)=>Object.fromEntries(Object.entries(t).flatMap(([t,r])=>{let a=e.fields[t];return at(r)?r.key===me(n[t])?[]:[[t,a.type===`integer`?Number(r.key):r.key]]:_n(a,r,n[t])?[[t,i(a,r)]]:[]})),Qa=({model:e,record:t,mode:n,label:r,title:i,fields:a,values:s,onClose:c})=>{let{resources:u,views:d}=q(),f=Ne(),p=ne(),m=vn(),h=d[e.name],[g,_]=(0,Y.useState)(()=>Xa(e,a,t?.record)),[v,y]=(0,Y.useState)({}),[b,x]=(0,Y.useState)(0),S=fn(b),[C,w]=(0,Y.useState)(),[T,E]=(0,Y.useState)(!1),[ee,te]=(0,Y.useState)(!1);_t(ee||T,`input-lost`);let re=async()=>{E(!0),w(void 0),await(n===`create`?f.create(e.name,{...Ye(e,u,g),...s}):f.update(e.name,t.key,Za(e,g,t.record),t.etag??`*`)).then(async()=>{await m(e.name),p.show({state:`success`,title:V(`saved`,{label:i??r})}),c()},e=>{let t=wn(e);y(t),Object.keys(t).length>0&&x(e=>e+1),w(e)}),E(!1)};return(0,X.jsx)(o,{title:i??r,onClose:c,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:c,children:V(`cancel`)}),(0,X.jsx)(M,{variant:`primary`,loading:T,onClick:()=>void re(),children:V(n===`create`?`create`:`save`)})]}),children:(0,X.jsxs)(`form`,{ref:S,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),re()},children:[C!==void 0&&Object.keys(v).length===0&&(0,X.jsx)(l,{title:V(`notSaved`),error:C}),a.map(n=>{let r=e.fields[n],i=g[n],a=r.relation?u[r.relation.resource]:void 0,o=h?.fields[n]?.label??ge(n),s=v[n];return(0,X.jsx)(An,{name:n,label:o,help:h?.fields[n]?.help,error:s&&tt(r,o,s),children:(0,X.jsx)(bn,{field:r,hints:h?.fields[n],value:at(i)?i.key:i,stored:t?.record[n],relationLabel:at(i)?i.label:void 0,relationPicker:a?{target:a,view:d[a.name]}:void 0,invalid:!!v[n],resource:e.name,onChange:e=>{y(({[n]:e,...t})=>t),te(!0),_(t=>({...t,[n]:e}))}})},n)})]})})},$a=({model:e,recordKey:t,children:n})=>{let r=Oe(e,{key:t});return(0,X.jsx)(X.Fragment,{children:n(r.data??void 0)})},eo=({node:e})=>{let t=G(e),n=Dt(),{resources:r}=q(),i=r[t.resource??n?.model.name??``],a=kn(i?.name??``),[o,s]=(0,Y.useState)(!1);if(!i||!(t.mode===`create`?Te(a,`create`):Te(a,`update`)&&n?.permissions?.update!==!1))return null;let c=e=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{size:`sm`,variant:t.variant??`secondary`,disabled:t.mode===`edit`&&!e,onClick:()=>s(!0),children:t.label}),o&&(0,X.jsx)(Qa,{...t,model:i,record:t.mode===`edit`?e:void 0,onClose:()=>s(!1)})]});return t.mode===`edit`&&t.recordKey!==void 0?(0,X.jsx)($a,{model:i,recordKey:t.recordKey,children:c}):c(t.mode===`edit`?n:void 0)},to=({node:e,children:t,slots:n,className:r})=>{let{title:i,description:a,width:o}=G(e);return(0,X.jsx)(`div`,{className:U(`flex-1`,r),children:(0,X.jsxs)(`div`,{className:U(`flex flex-col gap-6 px-4 pb-16 pt-6 md:px-10 md:py-8`,o!==`full`&&`mx-auto max-w-[1200px]`),children:[(0,X.jsx)(xr,{title:i,subtitle:a,actions:n.actions}),t]})})},no=(e,t)=>{let n=R(),r=typeof e==`string`?Jt(n,e):void 0,i=qt(r&&`frame`in r?r.frame:void 0,r&&`path`in r?r.path:``);return typeof e==`number`?e:e===void 0?t:r&&`item`in r?Number(r.item):i.state===`ready`?Number(i.value):i.state===`loading`?void 0:NaN},ro=({node:e,className:t})=>{let{value:n,max:r,label:i}=G(e),a=no(n,0),o=no(r,100);if(a===void 0||o===void 0)return(0,X.jsx)(A,{className:`h-6 w-full`});if(!Number.isFinite(a)||!Number.isFinite(o))return null;let s=o>0?Math.min(1,Math.max(0,a/o)):0;return(0,X.jsxs)(`div`,{className:U(`min-w-0`,t),children:[(0,X.jsxs)(`div`,{className:`flex items-baseline justify-between gap-2 text-body`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:i}),(0,X.jsxs)(`span`,{className:`tabular-nums`,children:[a.toLocaleString(Tn()),` / `,o.toLocaleString(Tn())]})]}),(0,X.jsx)(`div`,{role:`progressbar`,"aria-label":i,"aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":o,className:`mt-1.5 h-2 overflow-hidden rounded-full bg-muted`,children:(0,X.jsx)(`div`,{className:s>=.9?`h-full rounded-full bg-warning`:`h-full rounded-full bg-primary`,style:{width:`${s*100}%`}})})]})},io=({model:e,at:t,filter:n,sort:r,recordKey:i,title:a,description:o,empty:s,actions:c,children:u,className:d})=>{let f=nn(t),p=Oe(e,{filter:n,sort:r,key:i,enabled:!f}),m=f?En(e,f):p,h=e=>m.data?(0,X.jsx)(dt,{value:m.data,children:e}):void 0,g=m.isPending?(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(A,{className:`h-4 w-1/2`}),(0,X.jsx)(A,{className:`h-4 w-1/3`})]}):m.error?(0,X.jsx)(l,{title:V(`couldNotLoad`),error:m.error}):m.data?h((0,X.jsx)(`div`,{className:`flex flex-col gap-3`,children:u})):(0,X.jsx)(j,{children:s??V(`nothingYet`)});return(0,X.jsx)(J,{title:a,description:o,actions:c?h(c):void 0,className:U(`h-full`,d),children:g})},ao=({node:e,at:t,children:n,slots:r,className:i})=>{let{resource:a,filter:o,sort:s,recordKey:c,title:l,description:u,empty:d}=G(e),f=q().resources[a];return f?(0,X.jsx)(io,{model:f,...t!==void 0&&{at:t},filter:o,sort:s,recordKey:c,title:l,description:u,empty:d,actions:r.actions,className:i,children:n}):null},oo=vt(`app/related-cards`),so=({children:e})=>{let t=(0,Y.useRef)(null),[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(!1);return(0,Y.useLayoutEffect)(()=>{let e=t.current;if(!e)return;let n=()=>a(e.scrollHeight>e.parentElement.clientHeight+1);n();let r=new ResizeObserver(n);return r.observe(e),()=>r.disconnect()},[n]),(0,X.jsxs)(`div`,{className:`flex flex-col items-start gap-1`,children:[(0,X.jsx)(`div`,{className:U(`w-full min-w-0`,!n&&`max-h-40 overflow-hidden`),children:(0,X.jsx)(`div`,{ref:t,children:e})}),(i||n)&&(0,X.jsx)(M,{size:`sm`,variant:`ghost`,className:`-ml-2`,"aria-expanded":n,onClick:()=>r(!n),children:oo(n?`showLess`:`showMore`)})]})},co=e=>e==null||e===``,lo=({scope:e,path:t,labelled:n=!0,clamped:r=!1})=>{let{views:i}=q(),a=qt(e,t);if(a.state===`missing`||a.state===`ready`&&co(a.value))return null;let o=a.state===`loading`?(0,X.jsx)(A,{className:`h-4 w-24`}):(0,X.jsx)(Me,{model:a.model,field:a.field,value:a.value}),s=r?(0,X.jsx)(so,{children:o}):o;if(!n)return(0,X.jsx)(`div`,{className:`min-w-0`,children:s});let c=Ta(t,a.state===`ready`?i[a.model.name]?.fields[a.field.name]?.label:void 0);return(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`dt`,{className:`text-body text-muted-foreground`,children:c}),(0,X.jsx)(`dd`,{className:`mt-0.5`,children:s})]})},uo=({scope:e,view:t,fields:n,time:r,tone:i,actions:a,button:o,onActed:s})=>{let c=Ge(),{resources:l}=q(),u=c(e.model,t,e.record,e.key),d=a.length>0||o!==void 0;return(0,X.jsxs)(`li`,{"data-card":e.key,className:U(`relative grid min-w-0 items-center gap-x-4 gap-y-1 rounded-lg border border-border bg-surface px-4 py-2.5`,d?`grid-cols-[minmax(0,1fr)_auto]`:`grid-cols-[minmax(0,1fr)]`),children:[i&&(0,X.jsx)(pt,{view:t,field:i,record:e.record}),(0,X.jsxs)(`div`,{className:U(`flex min-w-0 items-baseline gap-2`,d&&`col-span-2 sm:col-span-1`),children:[(0,X.jsx)(D,{to:{kind:`record`,resource:e.model.name,key:h(e.model,e.record)},className:`line-clamp-2 min-w-0 font-medium [overflow-wrap:anywhere] text-primary-text hover:underline`,children:u}),r&&(0,X.jsx)(`div`,{className:`ml-auto shrink-0 text-body whitespace-nowrap text-muted-foreground empty:hidden`,children:(0,X.jsx)(lo,{scope:e,path:r,labelled:!1})})]}),n.length>0&&(0,X.jsx)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-y-0.5 text-body text-muted-foreground`,children:n.map(t=>(0,X.jsx)(`div`,{className:`flex max-w-full min-w-0 items-center whitespace-nowrap empty:hidden [&>div]:truncate [:not(:empty)~&]:before:mx-2 [:not(:empty)~&]:before:content-['·'_/_'']`,children:(0,X.jsx)(lo,{scope:e,path:t,labelled:!1})},t))}),d&&(0,X.jsx)(dt,{value:e,children:(0,X.jsxs)(`div`,{className:`col-start-2 flex flex-wrap items-center justify-end gap-2 sm:row-span-2 sm:row-start-1`,children:[o&&(0,X.jsx)(mr,{button:o,model:e.model,view:t,record:e.record,models:l}),a.map(e=>(0,X.jsx)(li,{name:e,about:u,onRun:e=>s?.(e,u)},e))]})})]})},fo=({scope:e,view:t,fields:n,tone:r,actions:i,button:a,onActed:o})=>{let s=Ge(),{resources:c}=q(),l=s(e.model,t,e.record,e.key);return(0,X.jsxs)(`li`,{"data-card":e.key,className:`relative flex min-w-0 flex-col gap-3 rounded-lg border border-border bg-surface p-4`,children:[r&&(0,X.jsx)(pt,{view:t,field:r,record:e.record}),(0,X.jsx)(D,{to:{kind:`record`,resource:e.model.name,key:h(e.model,e.record)},className:`self-start font-medium text-primary-text hover:underline`,children:l}),n.length>0&&(0,X.jsx)(`dl`,{className:`flex flex-col gap-3`,children:n.map(t=>(0,X.jsx)(lo,{scope:e,path:t,clamped:!0},t))}),(i.length>0||a)&&(0,X.jsx)(dt,{value:e,children:(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a&&(0,X.jsx)(mr,{button:a,model:e.model,view:t,record:e.record,models:c}),i.map(e=>(0,X.jsx)(li,{name:e,about:l,onRun:e=>o?.(e,l)},e))]})})]})},po=e=>!e.disabled&&e.getAttribute(`aria-disabled`)!==`true`,mo=e=>[...e.querySelectorAll(`button`)].find(po)??e.querySelector(`a`),ho=(e,t,n)=>{let r=e.indexOf(n),i=e=>t.includes(e);return e.slice(r+1).find(i)??e.slice(0,Math.max(r,0)).findLast(i)},go=e=>{let t=e.closest(`section`)?.querySelector(`h2`);return t&&!t.hasAttribute(`tabindex`)&&(t.tabIndex=-1),t},_o=e=>{let t=(0,Y.useRef)(null),n=(0,Y.useRef)({current:e,previous:e}),r=(0,Y.useRef)(void 0),[i,a]=(0,Y.useState)(``),o=(e,n,i)=>{if(r.current=void 0,i.includes(e.key)||!t.current||(a(oo(`left`,{action:e.action,title:e.title})),document.activeElement&&document.activeElement!==document.body))return;let o=ho(n,i,e.key),s=o===void 0?void 0:t.current.querySelector(`[data-card="${CSS.escape(o)}"]`);(s?mo(s):go(t.current))?.focus()};return(0,Y.useEffect)(()=>{let t=n.current.current;n.current={current:e,previous:t},r.current&&o(r.current,t,e)},[e]),{root:t,acted:(e,t,i)=>{let{current:a,previous:s}=n.current;if(a.includes(e)){r.current={key:e,action:t,title:i};return}o({key:e,action:t,title:i},s,a)},announcement:i}},vo=({compact:e,limit:t})=>(0,X.jsx)(`div`,{className:e?`flex flex-col gap-2`:`flex flex-col gap-3`,children:Array.from({length:e?Math.min(t,3):2},(t,n)=>(0,X.jsx)(A,{className:e?`h-17.5 w-full max-sm:h-24`:`h-24 w-full`},n))}),yo=({model:e,view:t,filter:n,sort:r,fields:i,actions:a,button:o,limit:s,display:u,empty:d,carousel:f,compact:p,tone:m,planned:h})=>{let g=Ht(),_=hr(),v=t?.names?.plural??ge(e.name),y=r||At(e,t),b=c(e,{filter:n,sort:y,pageSize:s,enabled:!h}),x=xn(e,n,!h),S=h?h.rows:{isPending:b.isPending,error:b.error},C=h?h.rows.rows:b.data?.items,w=h?{data:h.total&&!h.total.isPending&&!h.total.error?cr(h.total):void 0}:x,T=(0,Y.useMemo)(()=>(C??[]).map(t=>rt(e,t)),[e,C]),E=_o((0,Y.useMemo)(()=>T.map(e=>e.key),[T]));return(0,X.jsxs)(`div`,{ref:E.root,children:[(()=>{if(S.isPending)return(0,X.jsx)(vo,{compact:!!p,limit:s});if(S.error)return(0,X.jsx)(l,{title:oo(`couldNotLoad`),error:S.error});if(T.length===0)return(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:d??oo(`nothingYet`)});let r=T.map(e=>{let n=(t,n)=>E.acted(e.key,t,n);return p?(0,X.jsx)(uo,{scope:e,view:t,fields:i,time:p.time,tone:m,actions:a,button:o,onActed:n},e.key):(0,X.jsx)(fo,{scope:e,view:t,fields:i,tone:m,actions:a,button:o,onActed:n},e.key)}),c=w.data===void 0?void 0:Zn(T.length,w.data,!1);return(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[f===void 0?(0,X.jsx)(`ul`,{className:p?`flex flex-col gap-2`:`flex flex-col gap-3`,children:r}):(0,X.jsx)(Qn,{scroll:_,label:v,share:f,children:r}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:c}),(0,X.jsxs)(D,{to:ur(e,t,g,{filter:n,orderBy:y,display:dr(t,g,{preferred:u})}),className:`flex items-center gap-1 font-medium text-primary-text hover:underline`,children:[ar(`viewAll`),` `,(0,X.jsx)(`span`,{className:`sr-only`,children:v.toLowerCase()}),(0,X.jsx)(nr,{className:`size-3.5`,"aria-hidden":!0})]})]})]})})(),(0,X.jsx)(`p`,{role:`status`,className:`sr-only`,children:E.announcement})]})},bo={"1/4":1/4,"1/3":1/3,"1/2":1/2,"2/3":2/3},xo=({node:e,at:t,slots:n,className:r})=>{let i=G(e),{resource:a,filter:o=``,sort:c=``,fields:l,cardActions:u=[],limit:d=10,display:f,title:p,description:m,empty:h}=i,{layout:g,cardWidth:_}=ii(i),{resources:v,views:y}=q(),[b,x]=st([t,t===void 0?void 0:`${t}#total`]),S=(0,Y.useMemo)(()=>b&&{rows:b,total:x},[b,x]),C=v[a];if(!C)return null;let w=y[C.name];return(0,X.jsx)(`section`,{className:U(`min-w-0`,r),"aria-label":p,children:(0,X.jsx)(T,{title:p,help:m,actions:n.actions,children:(0,X.jsx)(yo,{model:C,view:w,filter:o,sort:c,fields:l??s(C,w),actions:u,limit:d,display:f,empty:h,carousel:g===`carousel`?bo[_]:void 0,...S&&{planned:S}})})})},So=({model:e,view:t,empty:n,...r})=>{let{resources:i,views:a}=q(),o=Ve(i,a,e.name),s=Vn(e.name,t.listOf,!0),c=(t.names?.plural??ge(e.name)).toLowerCase();if(!o.listOf)return null;if(s.error)return(0,X.jsx)(l,{title:Ln(`couldNotLoadYour`,{plural:c}),error:s.error});if(!s.data)return(0,X.jsx)(A,{className:`h-24`});let u=rr(o.model,s.data);return u?(0,X.jsx)(_r,{...r,model:o.model,view:o.view,filter:``,scope:u,list:e.name,empty:n}):(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:n??Ln(`noneYet`,{plural:c})})},Co=({model:e,view:t,target:n,targetView:r,row:i})=>{let a=ce(h(e,i)),{name:o,chips:s,title:c,body:l}=yr({model:e,of:t.searchesOf,target:n,targetView:r,row:i,recordKey:a});return(0,X.jsxs)(`section`,{"aria-label":c,className:`flex flex-col gap-3 py-4 first:pt-0 last:pb-0`,children:[(0,X.jsx)(`h3`,{className:`text-[0.9375rem] font-semibold`,children:(0,X.jsx)(D,{to:{kind:`record`,resource:e.name,key:a},className:`hover:underline`,children:o??(0,X.jsx)(Kn,{chips:s})})}),(0,X.jsx)(_r,{...l})]})},wo=({model:e,view:t,empty:n})=>{let{resources:r,views:i}=q(),a=t.searchesOf,o=r[a.resource],s=Xn(e.name,!0),c=(t.names?.plural??ge(e.name)).toLowerCase();return o?s.error?(0,X.jsx)(l,{title:qn(`couldNotLoadYour`,{plural:c}),error:s.error}):s.data?s.data.length===0?(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:n??qn(`noneYet`,{plural:c})}):(0,X.jsx)(`div`,{className:`flex flex-col divide-y`,children:s.data.map(n=>(0,X.jsx)(Co,{model:e,view:t,target:o,targetView:i[a.resource],row:n},ce(h(e,n))))}):(0,X.jsx)(A,{className:`h-40`}):null},To=({node:e,slots:t,className:n})=>{let{resource:r,filter:i=``,sort:a,limit:o,display:s,title:c,description:l,empty:u}=G(e),{resources:d,views:f}=q(),p=d[r];if(!p)return null;let m=f[p.name];return(0,X.jsx)(J,{title:c,description:l,actions:t.actions,className:n,children:m?.searchesOf?(0,X.jsx)(wo,{model:p,view:m,empty:u}):m?.listOf===void 0?(0,X.jsx)(_r,{model:p,view:m,filter:i,sort:a,limit:o,display:s,empty:u}):(0,X.jsx)(So,{model:p,view:m,limit:o,display:s,empty:u})})},Eo=e=>e.type===`boolean`||e.type===`enum`,Do=({model:e,fields:t,title:n,description:r,stored:i,className:a})=>{let{resources:o,views:s}=q(),c=kn(e.name),u=Ne(),d=ne(),f=vn(),p=s[e.name],[m,h]=(0,Y.useState)(i),[g,_]=(0,Y.useState)(()=>Xa(e,t,i?.record)),[v,y]=(0,Y.useState)({}),[b,x]=(0,Y.useState)(),[S,C]=(0,Y.useState)(!1),w=(0,Y.useRef)(Promise.resolve()),T=(0,Y.useRef)(i),E=Xa(e,t,void 0),ee=m?Te(c,`update`)&&m.permissions?.update!==!1:Te(c,`create`),te=t.filter(t=>!Eo(e.fields[t])),re=te.some(t=>m?_n(e.fields[t],g[t],m.record[t]):g[t]!==E[t]),ie=async t=>{let n=T.current;if(n){let r=await u.update(e.name,n.key,Za(e,t,n.record),n.etag??`*`);return{...rt(e,r.record),etag:r.etag,permissions:r.permissions??n.permissions}}let r=await u.create(e.name,Ye(e,o,{...E,...t}));return{...rt(e,r.record),etag:r.etag}},D=t=>{let r=w.current.then(async()=>{C(!0),x(void 0),await ie(t).then(async r=>{T.current=r,h(r),y(e=>Object.fromEntries(Object.entries(e).filter(([e])=>!Object.hasOwn(t,e)))),await f(e.name),d.show({state:`success`,title:V(`saved`,{label:n??V(`settings`)})})},e=>{y(t=>({...t,...wn(e)})),x(e)}),C(!1)});w.current=r},ae=(t,n)=>{_(e=>({...e,[t]:n})),Eo(e.fields[t])&&D({[t]:n})};return(0,X.jsx)(J,{title:n,description:r,className:U(`h-full`,a),children:(0,X.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),re&&D(Object.fromEntries(te.map(e=>[e,g[e]])))},children:[b!==void 0&&Object.keys(v).length===0&&(0,X.jsx)(l,{title:V(`notSaved`),error:b}),t.map(t=>{let n=e.fields[t],r=p?.fields[t]?.label??ge(t),i=v[t];return(0,X.jsx)(An,{name:t,label:r,help:p?.fields[t]?.help,error:i&&tt(n,r,i),children:(0,X.jsx)(bn,{field:n,hints:p?.fields[t],value:g[t],stored:m?.record[t]??E[t],invalid:!!i,locked:!ee||n.readOnly,resource:e.name,onChange:e=>ae(t,e)})},t)}),ee&&re&&(0,X.jsx)(`div`,{children:(0,X.jsx)(M,{type:`submit`,variant:`primary`,size:`sm`,loading:S,children:V(`save`)})})]})})},Oo=e=>{let t=Oe(e.model,{});return t.isPending?(0,X.jsx)(J,{title:e.title,description:e.description,className:e.className,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(A,{className:`h-4 w-1/2`}),(0,X.jsx)(A,{className:`h-4 w-1/3`})]})}):t.error?(0,X.jsx)(J,{title:e.title,description:e.description,className:e.className,children:(0,X.jsx)(l,{title:V(`couldNotLoad`),error:t.error})}):(0,X.jsx)(Do,{...e,stored:t.data??void 0})},ko=({node:e,className:t})=>{let{resource:n,fields:r=[],className:i,...a}=G(e),o=q().resources[n];return o?(0,X.jsx)(Oo,{...a,model:o,fields:r.filter(e=>Object.hasOwn(o.fields,e)),stored:void 0,className:t}):null},Ao=(e,t)=>jo(e,t?[t]:[]),jo=(e,t)=>{let{resources:n}=q(),i=Ne(),a=JSON.stringify(e),o=(0,Y.useMemo)(()=>JSON.parse(a).map(ft),[a]),s=e=>t.some(t=>`item`in t?typeof t.item==`object`&&t.item!==null&&Object.hasOwn(t.item,e):Object.hasOwn(t.model.fields,e)),c=[...new Set(o.flatMap(e=>e.ok?e.paths:[]))],l=new Map(c.flatMap(e=>{let t=we(e,s);return t===void 0?[]:[[e,t]]})),u=c.filter(e=>!l.has(e)),d=[...new Set(l.values())].flatMap(e=>n[e]?[n[e]]:[]),f=u.map(e=>Jt(t,e)),p=Rt(u.map((e,t)=>{let n=f[t];return n&&`frame`in n?{scope:n.frame,path:n.path}:{scope:void 0,path:e}})),m=In({queries:d.map(e=>yt(i,e))});return o.map(e=>{if(!e.ok)return!1;let t={};for(let n of e.paths){let e=l.get(n);if(e===void 0){let e=u.indexOf(n),r=f[e];if(r&&`item`in r){t[n]=r.item;continue}let i=p[e];if(i.state===`loading`)return;i.state===`ready`&&(t[n]=i.value);continue}let r=d.findIndex(t=>t.name===e);if(r===-1)t[n]=0;else if(m[r].isPending)return;else t[n]=m[r].data??0}return r(e,t)})},Mo=(e,t)=>typeof e.props.fallback==`string`?e.props.fallback:t.fallback,No=({node:e,children:t,slots:n,className:r})=>{let{when:i}=G(e),[a]=jo([i],R());if(a===void 0)return null;let o=a?t:Mo(e,n);return o==null?null:r===void 0?(0,X.jsx)(X.Fragment,{children:o}):(0,X.jsx)(`div`,{className:r,children:o})},Po=(e,t)=>e.flatMap(e=>typeof e==`string`?[]:[String(w(e,F(t)).props.when)]),Fo=({node:e,children:t,slots:n,className:r})=>{let i=R(),a=jo(Po(e.children,i),i),o=a.findIndex(e=>e!==!1);if(o!==-1&&a[o]===void 0)return null;let s=o===-1?Mo(e,n):t[o];return s==null?null:r===void 0?(0,X.jsx)(X.Fragment,{children:s}):(0,X.jsx)(`div`,{className:r,children:s})},Io=({children:e})=>(0,X.jsx)(X.Fragment,{children:e}),Lo=`text-2xl font-semibold tracking-tight tabular-nums`,Ro=({model:e,at:t,filter:n})=>{let{views:r}=q(),i=nn(t),a=xn(e,n,!i),o=i??a;if(o.isPending)return(0,X.jsx)(A,{className:`h-8 w-16`});if(o.error)return(0,X.jsx)(`span`,{className:`text-danger-text`,children:V(`couldNotCount`)});let s=i?cr(i):a.data;return(0,X.jsx)(D,{to:or(r[e.name],e.name,n),className:`${Lo} hover:text-primary-text after:absolute after:inset-0 after:content-['']`,children:s.toLocaleString(Tn())})},zo=({field:e,format:t})=>{let n=Tt(e);return n.state===`loading`?(0,X.jsx)(A,{className:`h-8 w-16`}):n.state===`missing`?null:n.state===`plain`?(0,X.jsx)(`span`,{className:Lo,children:wa(n.value)}):(0,X.jsx)(`span`,{className:Lo,children:(0,X.jsx)(Me,{model:n.model,field:n.field,value:n.value,format:t})})},Bo=({node:e,at:t,className:n})=>{let{label:r,value:i,resource:a,filter:o,field:s,format:c,description:l}=G(e),{resources:u}=q(),d=a===void 0?void 0:u[a];return(0,X.jsxs)(J,{className:U(`relative h-full`,n),bodyClassName:`flex flex-col`,children:[(0,X.jsx)(`p`,{className:`text-muted-foreground break-words`,children:r}),(0,X.jsxs)(`div`,{className:`mt-auto pt-1`,children:[i!==void 0&&(0,X.jsx)(`span`,{className:Lo,children:i}),d&&(0,X.jsx)(Ro,{model:d,...t!==void 0&&{at:t},filter:o}),s!==void 0&&(0,X.jsx)(zo,{field:s,format:c})]}),l&&(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:l})]})},Vo=(e,t,n)=>{let r=Ht(),i=tr(t),[a,o]=(0,Y.useState)(()=>Yn(localStorage,i)),s=(0,Y.useCallback)(e=>{o(e),fr(localStorage,i,e)},[i]);return[dr(e,r,{picked:a,preferred:n}),s]},Ho=({model:e,items:t,columns:n,button:r,title:i,description:a,empty:o,actions:c,className:l})=>{let{resources:u,views:d}=q(),f=d[e.name],{fields:p}=y(),m=Te(kn(e.name),`update`),{go:h,href:g}=Xt(),_=Ht(),v=!cn(),b=(0,Y.useMemo)(()=>n?.map(Zt)??s(e,f),[n,e,f]),x=(0,Y.useMemo)(()=>mt(e,f,b,{resources:u,views:d,fieldTypes:p}),[e,f,b,u,d,p]),S=(0,Y.useMemo)(()=>_?It(n)(x):x,[_,n,x]),C=(0,Y.useMemo)(()=>r?ir(S,e,f,r,u,v):S,[S,e,f,r,u,v]),w=(0,Y.useMemo)(()=>t.map(t=>({...t,id:ye(e,t)})),[t,e]),T=(0,Y.useMemo)(()=>({total:w.length,rowAt:e=>w[e]}),[w]),E=lr({model:e,view:f,opens:void 0,resources:u,views:d,canUpdate:m}),ee=e=>({href:g(e),onFollow:()=>h(e)});return(0,X.jsx)(J,{title:i,description:a,actions:c,className:l,children:w.length===0?(0,X.jsx)(j,{children:o??V(`nothingYet`)}):(0,X.jsx)(Un,{fit:!0,columns:C,source:T,latencyMs:0,onOpenRow:e=>h(E.address(e)),rowLink:e=>ee(E.address(e)),rowActions:E.actions(ee),rowNumbers:!1,selectable:!1})})},Uo=e=>{let t=it();return t?.model?(0,X.jsx)(Ho,{...e,model:t.model,items:t.items}):null},Wo=({model:e,view:t,filter:n=``,sort:r=``,columns:i,button:a,bulk:o,limit:s=10,display:c,title:l,description:u,empty:d,actions:f,className:p,chosen:m,planned:h})=>{let[g,_]=Vo(t,`page:${e.name}:${l??``}:${n}`,c),v=m?Ue:g,y=(0,Y.useMemo)(()=>i?.map(Zt),[i]),b=(0,Y.useMemo)(()=>It(i),[i]);return(0,X.jsxs)(J,{title:l,description:u,actions:(0,X.jsxs)(X.Fragment,{children:[!m&&(0,X.jsx)(pr,{view:t,value:v,onChange:_}),f]}),className:U(`h-full`,p),children:[(0,X.jsx)(sr,{model:e,view:t,filter:n,sort:r,columns:y,button:a,bulk:o,limit:s,display:v,empty:d,phoneColumns:b,...m&&{rowTo:m.rowTo,chosenKey:m.key},...h&&{planned:h}}),m?.details]})},Go=({node:e,at:t,slots:n,children:r,className:i})=>{let{className:a,resource:o,select:s,children:c,...l}=G(e),{resources:u,views:d}=q(),[f,p]=st([t,t===void 0?void 0:`${t}#total`]),m=(0,Y.useMemo)(()=>f&&{rows:f,total:p},[f,p]);if(o===void 0)return(0,X.jsx)(Uo,{...l,actions:n.actions,className:i});let h=u[o];return h?s===void 0?(0,X.jsx)(Wo,{...l,model:h,view:d[h.name],actions:n.actions,className:i,...m&&{planned:m}}):(0,X.jsx)(Ko,{...l,model:h,view:d[h.name],actions:n.actions,className:i,select:s,...m&&{planned:m},children:r}):null},Ko=({select:e,children:t,...n})=>{let{given:r,linkTo:i}=lt(),a=t=>i({[e]:t}),o=r[e],s=o===void 0?null:(0,X.jsx)(pn,{name:e,children:(0,X.jsx)(_i,{model:n.model,query:{key:o},children:t},o)});return(0,X.jsx)(Wo,{...n,chosen:{rowTo:a,key:o,details:s}})},qo=({node:e,children:t,className:n})=>{let{tab:r,pathOf:i}=a(),{navigate:o}=qe(),s=Mt(e),c=he(s,r),l=e=>i(e===s[0]?.name?void 0:e);return(0,X.jsxs)(`div`,{className:U(`flex flex-col gap-6`,n),children:[(0,X.jsxs)(`select`,{"aria-label":V(`tabs`),value:c?.name??``,onChange:e=>o(l(e.target.value)),className:`h-9 rounded-md border border-border-strong bg-background px-2 font-medium md:hidden`,children:[!c&&(0,X.jsx)(`option`,{value:``,disabled:!0}),s.map(e=>(0,X.jsx)(`option`,{value:e.name,children:e.label},e.name))]}),(0,X.jsx)(`nav`,{"aria-label":V(`tabs`),className:`hidden border-b md:block`,children:(0,X.jsx)(`ul`,{className:`flex gap-1`,children:s.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(Ct,{to:l(e.name),"aria-current":e===c?`page`:void 0,className:U(`-mb-px inline-flex h-9 items-center whitespace-nowrap border-b-2 px-3 font-medium transition-colors`,e===c?`border-foreground text-foreground`:`border-transparent text-muted-foreground hover:text-foreground`),children:e.label})},e.name))})}),c?(0,X.jsx)(Y.Fragment,{children:t[s.indexOf(c)]},c.name):(0,X.jsx)(rn,{children:V(`noTab`,{name:r??``})})]})},Jo=({children:e})=>(0,X.jsx)(`div`,{className:`flex flex-col gap-6`,children:e}),Yo=e=>e===void 0?1/0:Date.parse(e),Xo=(e,t)=>{let n=e=>e.more&&e.items.length>0?Yo(e.items.at(-1).time):-1/0,r=Math.max(n(e),n(t)),i=[],a=0,o=0;for(;a<e.items.length||o<t.items.length;){let n=o>=t.items.length||a<e.items.length&&Yo(e.items[a].time)>=Yo(t.items[o].time)?e.items[a++]:t.items[o++];if(Yo(n.time)<r)break;i.push(n)}return i},Zo=({value:e,hints:t,mark:n})=>{let r=d(e,t?.valueLabels);return n===`done`?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(sn,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-success-text`}),r]}):n===`running`?(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,X.jsx)(u,{hidden:!0,className:`size-3.5 shrink-0`}),r]}):n!==`error`&&Pt(t?.valueColors,e)!==`red`?r:(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-danger-text`,children:[(0,X.jsx)(br,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),r]})},Qo=({value:e})=>{let t=typeof e==`string`?Pe(e):e;return t===Re?(0,X.jsx)(ie,{children:String(e)}):(0,X.jsx)(x,{value:t})},$o=({label:e,children:t})=>(0,X.jsxs)(`div`,{className:`grid gap-1`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium text-muted-foreground`,children:e}),t]}),es=({call:e,statusHints:t})=>{let[n,r]=(0,Y.useState)(!1),i=(0,Y.useId)(),a=e.status!==void 0&&(0,X.jsx)(Zo,{value:e.status,hints:t,mark:e.state}),o=(0,X.jsx)(`span`,{className:`font-mono text-xs text-foreground`,children:e.name}),s=e.input!==void 0||e.result!==void 0||e.error!==void 0;return(0,X.jsxs)(`div`,{"data-tool-call":!0,className:`flex min-w-0 flex-col gap-1 pl-11 text-xs text-muted-foreground`,children:[s?(0,X.jsxs)(M,{size:`sm`,variant:`ghost`,className:`-ml-2.5 self-start`,"aria-expanded":n,"aria-controls":i,onClick:()=>r(!n),children:[(0,X.jsx)(Se,{"aria-hidden":!0,className:U(`size-3.5 transition-transform`,n&&`rotate-90`)}),o,a]}):(0,X.jsxs)(`p`,{className:`flex items-center gap-1.5`,children:[o,a]}),n&&(0,X.jsxs)(`div`,{id:i,className:`grid gap-2`,children:[e.input!==void 0&&(0,X.jsx)($o,{label:Q(`callInput`),children:(0,X.jsx)(Qo,{value:e.input})}),e.result!==void 0&&(0,X.jsx)($o,{label:Q(`callResult`),children:(0,X.jsx)(Qo,{value:e.result})}),e.error!==void 0&&(0,X.jsx)($o,{label:Q(`callError`),children:(0,X.jsx)(ie,{children:e.error})})]})]})},ts=(e,t)=>e.map(e=>({kind:`message`,row:e,time:typeof e[t]==`string`?e[t]:void 0})),ns=e=>{if(typeof e==`object`&&e&&`id`in e){let{id:t,name:n}=e;return{id:String(t),...typeof n==`string`&&{name:n}}}return{id:String(e??``),...typeof e==`string`&&{name:e}}},rs=(e,{key:t,sender:n,text:r,status:i},a=Date.now())=>{let o=[],s;for(let c of[...e].reverse()){let e=c.time,l=s?.time!==void 0&&e!==void 0&&te(s.time,e);if(e!==void 0&&!l&&o.push({kind:`day`,key:`day:${c.kind===`call`?c.key:t(c.row)}`,label:v(e,a)}),c.kind===`call`){o.push(c),s={author:void 0,time:e};continue}let{row:u}=c,d=n===void 0?void 0:ns(u[n]),f=d?.id??``,p=i===void 0||u[i]==null||u[i]===``?void 0:String(u[i]);o.push({kind:`message`,key:t(u),...d&&{author:d},time:e,text:u[r]==null?``:String(u[r]),...p!==void 0&&{status:p},continued:l&&s?.author===f}),s={author:f,time:e}}return o},is=e=>qr.includes(e??``)?e:void 0,as=e=>e==null||e===``?void 0:String(e),os=e=>`call:${JSON.stringify(e)}`,ss=(e,t,n)=>{let r=as(e[n.status]),i=is(r),a=n.input===void 0?void 0:e[n.input],o=n.result===void 0?void 0:e[n.result],s=n.error===void 0?void 0:as(e[n.error]);return{kind:`call`,key:t,name:String(e[n.name]??``),time:typeof e[n.time]==`string`?e[n.time]:void 0,...r!==void 0&&{status:r},...i!==void 0&&{state:i},...a!=null&&{input:a},...o!=null&&{result:o},...s!==void 0&&{error:s}}},cs=({planned:e,limit:t,expanded:n,expand:r,own:i})=>{if(!e)return i;let a=n&&!i.error&&i.pages<2&&(i.pages===0||i.hasNextPage),o={items:e.rows,labels:e.labels??{},hasNextPage:e.rows.length>=t,isFetchingNextPage:a,isFetchNextPageError:!1,isLoading:e.isPending};return n&&i.error&&i.pages===0?{...o,error:i.error,fetchNextPage:i.refetch,refetch:i.refetch}:n&&!a?i:{...o,error:e.error,fetchNextPage:r,refetch:r}},ls=(e,{pageSize:t=50,enabled:n=!0,...r},i)=>{let[a,o]=(0,Y.useState)(!1),s=Fe(e,{...r,pageSize:t,enabled:n&&(!i||a)}),c=s.data?.pages.length??0,{hasNextPage:l,isFetchingNextPage:u,fetchNextPage:d,error:f}=s;return(0,Y.useEffect)(()=>{i&&a&&!f&&c===1&&l&&!u&&d()},[i,a,f,c,l,u,d]),cs({planned:i,limit:t,expanded:a,expand:()=>o(!0),own:{...s,pages:c}})},us=(e,t,n)=>{let{views:r}=q(),i=e?.model.name??``,a=ls(i,{filter:e?.filter,orderBy:e&&Ot(e.fields.time),pageSize:t,enabled:e!==void 0},n);return e?{calls:a.items.map(t=>ss(t,os(h(e.model,t)),e.fields)),hasNextPage:a.hasNextPage,isFetchingNextPage:a.isFetchingNextPage,list:a,statusHints:r[i]?.fields[e.fields.status]}:{calls:[],hasNextPage:!1,isFetchingNextPage:!1,list:a,statusHints:void 0}},ds=e=>e.items.length>0?`messages`:e.error?`error`:e.isLoading?`loading`:`messages`,fs=(e,t)=>e.isLoading?t.loading:t.empty,ps=e=>e.items.length>0&&!!e.error,ms=e=>e.isFetchNextPageError?()=>void e.fetchNextPage():()=>void e.refetch(),hs=e=>{for(let t of e)t.hasNextPage&&t.fetchNextPage()},gs=({model:e,filter:t,sender:n,time:r,text:i,status:a,limit:o=50,empty:s,working:c,calls:u,planned:d})=>{let{resources:f,views:p}=q(),m=ee(),g=m?.state.kind===`signed-in`?m.state.user.id:void 0,_=n===void 0?[]:[n],v=$t(f,p,e,_),y=ls(e.name,{filter:t,orderBy:Ot(r),pageSize:o,labels:v},d?.messages),b=us(u,o,d?.calls),x=ds(y);if(x===`error`)return(0,X.jsx)(l,{title:Q(`couldNotLoad`),error:y.error,onRetry:ms(y)});if(x===`loading`)return(0,X.jsx)(`div`,{className:`p-4`,children:(0,X.jsx)(j,{children:Q(`loadingMessages`)})});let S=kt(f,e,_,y.items,y.labels),C=Xo({items:b.calls,more:b.hasNextPage},{items:ts(S,r),more:y.hasNextPage}),w=rs(C,{key:t=>String(h(e,t)),sender:n,time:r,text:i,status:a}),T=a===void 0?void 0:p[e.name]?.fields[a],E=e.fields[i]!==void 0&&jt(e.fields[i],p[e.name]?.fields[i]),te=w.findLast(e=>e.kind===`message`&&e.author!==void 0&&e.author.id===g);return(0,X.jsxs)(X.Fragment,{children:[ps(y)&&(0,X.jsx)(`div`,{className:`shrink-0 p-2`,children:(0,X.jsx)(l,{title:Q(`couldNotLoad`),error:y.error,onRetry:ms(y)})}),u&&b.list.error&&(0,X.jsx)(`div`,{className:`shrink-0 p-2`,children:(0,X.jsx)(l,{title:Q(`couldNotLoadCalls`),error:b.list.error,onRetry:ms(b.list)})}),(0,X.jsx)(ue,{length:C.length,followKey:te?.key,working:c,empty:fs(b.list,{loading:Q(`loadingMessages`),empty:s??Q(`noMessages`)}),onLoadEarlier:y.hasNextPage||b.hasNextPage?()=>hs([y,b.list]):void 0,loadingEarlier:y.isFetchingNextPage||b.isFetchingNextPage,children:w.map(e=>e.kind===`day`?(0,X.jsx)(xe,{label:e.label},e.key):e.kind===`call`?(0,X.jsx)(es,{call:e,statusHints:b.statusHints},e.key):(0,X.jsx)(pe,{...e.author?{author:e.author}:{alone:!0},time:e.time,continued:e.continued,footer:e.status!==void 0&&(0,X.jsx)(Zo,{value:e.status,hints:T}),children:E&&e.text!==``?(0,X.jsx)(le,{source:e.text,className:`whitespace-normal`}):e.text},e.key))})]})},_s=({children:e})=>(0,X.jsx)(`div`,{className:`flex h-[min(36rem,65dvh)] flex-col rounded-lg border border-border bg-background`,children:e}),vs=({node:e,at:t,slots:n,className:r})=>{let{title:i,description:a,resource:o,filter:s,sender:c,time:l,text:u,status:d,working:f,calls:p,limit:m,empty:h}=G(e),{resources:g}=q(),[_]=jo(f===void 0?[]:[f],R()),[v,y]=st([t,t===void 0?void 0:`${t}#calls`]),b=g[o];if(!b)return null;let x=p&&g[p.resource];return(0,X.jsx)(`section`,{className:U(`flex min-w-0 flex-col`,r),"aria-label":i,children:(0,X.jsx)(T,{title:i,help:a,actions:n.actions,children:(0,X.jsx)(_s,{children:(0,X.jsx)(gs,{model:b,filter:s,sender:c,time:l,text:u,status:d,calls:p&&x&&{model:x,filter:p.filter,fields:p},limit:m,empty:h,working:f===void 0?void 0:_===!0,...(v||y)&&{planned:{messages:v,calls:y}}})})})})},ys=({children:e,className:t})=>(0,X.jsx)(`div`,{className:t,children:e}),bs=({children:e,className:t})=>(0,X.jsx)(`div`,{className:U(`flex`,t),children:e}),xs=({children:e,className:t})=>(0,X.jsx)(`div`,{className:U(`flex flex-col`,t),children:e}),Ss=({node:e,children:t,className:n})=>{let{as:r=`p`}=G(e);return(0,X.jsx)(r,{className:n,children:t})},Cs=({node:e,children:t})=>{let{source:n}=G(e),r=ze(F(R()),n),i=(0,Y.useMemo)(()=>({items:Array.isArray(r)?r:[]}),[r]);return(0,X.jsx)(gn,{value:i,children:t})},ws=({node:e,className:t})=>{let{source:n,choices:r,label:i=n,defaultValue:a}=G(e),{values:o,linkTo:s}=lt(),c=o[n];return(0,X.jsxs)(`div`,{className:U(`flex flex-wrap items-center gap-2`,t),children:[(0,X.jsx)(`span`,{className:`font-medium text-muted-foreground`,children:i}),r?(0,X.jsx)(Le,{label:i,value:c??``,options:r.map(e=>({value:String(e.id),label:e.name})),link:e=>s({[n]:a!==void 0&&e===String(a)?void 0:e})}):(0,X.jsx)(`span`,{children:c})]})},Ts=({model:e,filter:t,perPage:n,more:r,planned:i,expanded:a,expand:o,own:s})=>{if(t===void 0)return{read:{isPending:!1,error:null},list:{model:e,items:[]}};if(i&&!a){let t=i.rows.slice(0,n),a=r&&t.length===n?o:void 0;return{read:i,list:{model:e,items:t,planned:!0,...a&&{loadMore:a}}}}if(i&&!s.error&&s.pages<2&&(s.pages===0||s.hasNextPage))return{read:i,list:{model:e,items:i.rows.slice(0,n),planned:!0,loadMore:()=>{},loadingMore:!0}};let c=r&&s.hasNextPage?()=>void s.fetchNextPage():void 0;return{read:{isPending:s.isPending,error:s.error},list:{model:e,items:s.items,...c&&{loadMore:c,loadingMore:s.isFetchingNextPage}}}},Es=({model:e,filter:t,sort:n,perPage:r,more:i,planned:a})=>{let[o,s]=(0,Y.useState)(!1),c=Fe(e.name,{filter:t,orderBy:n,pageSize:r,enabled:t!==void 0&&(!a||o)}),l=c.data?.pages.length??0,{hasNextPage:u,isFetchingNextPage:d,fetchNextPage:f,error:p}=c;return(0,Y.useEffect)(()=>{a&&o&&!p&&l===1&&u&&!d&&f()},[a,o,p,l,u,d,f]),Ts({model:e,filter:t,perPage:r,more:i,planned:a,expanded:o,expand:()=>s(!0),own:{pages:l,items:c.items,hasNextPage:u,isFetchingNextPage:d,isPending:c.isPending,error:p,fetchNextPage:f}})},Ds=({node:e,at:t,children:n})=>{let r=G(e),i=q().resources[r.reference],a=Ie(F(R())),o=nn(t);return i?(0,X.jsx)(Os,{model:i,...We(r,i.primaryKey[0],a),more:r.pagination===`more`,empty:r.empty,...o&&{planned:o},children:n}):null},Os=({empty:e,children:t,...n})=>{let{read:r,list:i}=Es(n);return(0,X.jsx)(On,{read:r,list:i,empty:e,children:t})},ks=({node:e,at:t,children:n})=>{let r=G(e),i=q().resources[r.reference],a=Ie(F(R())),o=nn(t);return i?(0,X.jsx)(Os,{model:i,...re(r,i.primaryKey[0],a),more:!1,empty:r.empty,...o&&{planned:o},children:n}):null},As=({model:e,at:t,recordKey:n,link:r=`edit`,children:i,className:a})=>{let{views:o}=q(),s=nn(t),c=Oe(e,{key:n,enabled:!s}),u=s?En(e,s):c;if(u.isPending)return(0,X.jsx)(A,{className:`h-4 w-24`});if(u.error)return(0,X.jsx)(l,{title:V(`couldNotLoad`),error:u.error});if(!u.data)return null;let d=i.length>0?(0,X.jsx)(dt,{value:u.data,children:i}):je(e,o[e.name],u.data.record,n);return r===!1?(0,X.jsx)(`span`,{className:a,children:d}):(0,X.jsx)(D,{to:{kind:`record`,resource:e.name,key:n},className:a??`font-medium text-primary-text hover:underline`,children:d})},js=({node:e,at:t,children:n,className:r})=>{let{reference:i,source:a,link:o,empty:s}=G(e),c=q().resources[i],l=ze(F(R()),a);return c?l==null||l===``?s===void 0?null:(0,X.jsx)(`span`,{className:r,children:s}):(0,X.jsx)(As,{model:c,...t!==void 0&&{at:t},recordKey:String(l),link:o,className:r,children:n}):null},Ms=(e,t)=>t.map(t=>Et(e,t)).join(`, `),$=vt(`users`),Ns=({roles:e})=>{let{session:t}=_(),[n,r]=(0,Y.useState)([]),[i,a]=(0,Y.useState)([]),o=(0,Y.useCallback)(()=>void t.users.invitations().then(a,()=>a([])),[t]);return(0,Y.useEffect)(o,[o]),(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Sr,{title:$(`inviteSomeone`),description:$(`inviteDescription`),onInvite:async e=>{let i=await t.users.invite({email:e,roles:n});return r([]),o(),i},incomplete:n.length===0,children:(0,X.jsx)(wr,{roles:e,selected:n,grantable:new Set(e.map(e=>e.name)),onChange:r})}),(0,X.jsx)(K,{title:$(`notAcceptedYet`),description:i.length>0?$(`sendingAgain`):$(`nobodyWaiting`),children:i.length>0&&(0,X.jsx)(`ul`,{className:`divide-y rounded-md border`,children:i.map(n=>(0,X.jsx)(Cr,{email:n.email,gives:Ms(e,n.roles),expiresAt:n.expiresAt,onResend:async()=>{let e=await t.users.invite({email:n.email,roles:n.roles});return o(),e},onRevoke:async()=>{await t.users.revoke(n.id),o()}},n.id))})})]})},Ps=({roles:e,onCreated:t})=>{let{session:n}=_(),[r,i]=(0,Y.useState)(``),[a,o]=(0,Y.useState)(``),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)([]),{busy:d,error:f,run:p}=ct(),m=()=>p(async()=>{await n.users.create({email:r.trim(),name:a.trim(),roles:l,...s&&{password:s}}),i(``),o(``),c(``),u([]),t()}),h=!r.trim()||!a.trim()||l.length===0||s!==``&&s.length<12;return(0,X.jsxs)(K,{title:$(`addAnAccount`),description:$(`addDescription`),children:[(0,X.jsx)(L,{message:f}),(0,X.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),m()},children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,X.jsx)(N,{"aria-label":$(`email`),type:`email`,placeholder:`name@example.com`,value:r,onChange:e=>i(e.target.value),wrapperClassName:`flex-1`}),(0,X.jsx)(N,{"aria-label":$(`name`),placeholder:$(`name`),autoComplete:`off`,value:a,onChange:e=>o(e.target.value),wrapperClassName:`flex-1`})]}),(0,X.jsx)(N,{"aria-label":$(`password`),type:`password`,autoComplete:`new-password`,placeholder:$(`passwordOptional`,{length:12}),value:s,onChange:e=>c(e.target.value)}),(0,X.jsx)(wr,{roles:e,selected:l,grantable:new Set(e.map(e=>e.name)),onChange:u}),(0,X.jsx)(`div`,{children:(0,X.jsx)(M,{type:`submit`,variant:`primary`,loading:d,disabled:h,children:$(`addAccount`)})})]})]})},Fs=({user:e,roles:t,self:n})=>{let{session:r}=_(),[i,a]=(0,Y.useState)(e),{busy:o,error:s,run:c,setError:l}=ct(),u=e=>{if(e.length===0)return l($(`keepOneRole`));c(async()=>{await r.users.setRoles(i.id,e),a({...i,roles:e})})},d=e=>void c(async()=>{await(e?r.users.block(i.id):r.users.unblock(i.id)),a({...i,blocked:e})});return(0,X.jsx)(Tr,{name:i.name,email:i.email,self:n,error:s,actions:(0,X.jsxs)(X.Fragment,{children:[i.blocked&&(0,X.jsx)(H,{tone:`red`,children:$(`blocked`)}),!n&&(i.blocked?(0,X.jsx)(M,{size:`sm`,loading:o,onClick:()=>d(!1),children:$(`unblock`)}):(0,X.jsx)(M,{size:`sm`,variant:`danger`,loading:o,onClick:()=>d(!0),children:$(`block`)}))]}),children:(0,X.jsx)(wr,{roles:t,selected:i.roles,grantable:new Set(t.map(e=>e.name)),disabled:o,onChange:u})})},Is=({roles:e,version:t})=>{let{session:n,state:r}=_(),[i,a]=(0,Y.useState)(``),o=(0,Y.useCallback)((e,t)=>n.users.search(e,t).then(e=>({items:e.users,total:e.total})),[n,t]),s=Dr(o,i),c=r.kind===`signed-in`?r.user.id:void 0;return(0,X.jsx)(Er,{title:$(`people`),description:$(`peopleDescription`),searchLabel:$(`findSomeone`),placeholder:$(`emailAddress`),query:i,onQuery:a,list:s,renderRow:n=>(0,X.jsx)(Fs,{user:n,roles:e,self:n.id===c},`${t}/${n.id}`)})},Ls=()=>{let{session:e}=_(),[t,n]=(0,Y.useState)([]),[r,i]=(0,Y.useState)();return(0,Y.useEffect)(()=>{e.users.roles().then(n,e=>i(e instanceof k?z(e):$(`couldNotReadRoles`)))},[e]),{roles:t,error:r}},Rs=()=>{let{roles:e,error:t}=Ls(),[n,r]=(0,Y.useState)(0);return(0,X.jsxs)(`div`,{className:`flex max-w-3xl flex-col gap-4`,children:[(0,X.jsx)(L,{message:t}),(0,X.jsx)(Is,{roles:e,version:n}),(0,X.jsx)(Ns,{roles:e}),(0,X.jsx)(Ps,{roles:e,onCreated:()=>r(e=>e+1)})]})},zs=()=>(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(ht,{message:O(`checkUnavailable`)})}),Bs=(e,t)=>t.status===`waiting`?(0,X.jsx)(ht,{message:O(`checkWaiting`,{address:e})}):t.status===`confirmed`?(0,X.jsx)(ht,{message:O(`checkConfirmed`,{address:e})}):t.status===`mismatch`?(0,X.jsx)(L,{message:O(`checkMismatch`,{address:e,from:t.from})}):t.status===`timed_out`?(0,X.jsx)(ht,{message:O(`checkTimedOut`)}):null,Vs=({address:e,state:t,error:n,onCheck:r})=>{if(t.status===`unchecked`)return(0,X.jsx)(zs,{});let i=t.status===`waiting`;return(0,X.jsxs)(`div`,{className:`mt-4`,children:[Bs(e,t),(0,X.jsx)(L,{message:n}),(0,X.jsx)(M,{size:`sm`,loading:i,onClick:r,children:t.status===`idle`||i?O(`checkFromAddress`):O(`checkAgain`)})]})},Hs=3e3,Us=async({start:e,result:t,wait:n,stopped:r,onState:i})=>{i({status:`waiting`});let a=await e();if(!r()){if(a.status!==`waiting`)return i(a);for(let e=0;e<40;e++){if(await n(Hs),r())return;let e=await t(a.check);if(r())return;if(e.status!==`waiting`)return i(e)}i({status:`timed_out`})}},Ws=e=>new Promise(t=>setTimeout(t,e)),Gs=(e,t=!1)=>{let[n,r]=(0,Y.useState)({status:`idle`}),[i,a]=(0,Y.useState)(),o=(0,Y.useRef)(!1),s=(0,Y.useRef)(!1),c=(0,Y.useRef)(e);c.current=e;let l=(0,Y.useCallback)(async()=>{if(!o.current){o.current=!0,a(void 0);try{await Us({...c.current,wait:Ws,stopped:()=>s.current,onState:r})}catch(e){if(s.current)return;if(r({status:`idle`}),e instanceof TypeError)return a(O(`noAnswerFromServer`));if(!(e instanceof k))throw e;a(z(e))}finally{o.current=!1}}},[]);return(0,Y.useEffect)(()=>(s.current=!1,t&&l(),()=>{s.current=!0}),[t,l]),{state:n,error:i,check:l}},Ks=({address:e,calls:t,auto:n=!1})=>{let{state:r,error:i,check:a}=Gs(t,n);return(0,X.jsx)(Vs,{address:e,state:r,error:i,onCheck:()=>void a()})},qs=({sender:e,check:t,busy:n,error:r,onSave:i,onClose:a})=>{let[s,c]=(0,Y.useState)(e?.address??``),[l,u]=(0,Y.useState)(e?.name??``),[d,f]=(0,Y.useState)(e?.signature??``),[p,m]=(0,Y.useState)(e?.isDefault??!1);return(0,X.jsxs)(o,{title:e?e.address:O(`addFromAddress`),description:O(e?`changeFromAddressDescription`:`addFromAddressDescription`),onClose:a,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:a,children:O(`cancel`)}),(0,X.jsx)(M,{variant:`primary`,loading:n,disabled:!s.trim(),onClick:()=>i({address:s.trim(),name:l.trim(),signature:d,isDefault:p}),children:O(e?`save`:`addAddress`)})]}),children:[!e&&(0,X.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[O(`fromAddress`),(0,X.jsx)(N,{autoFocus:!0,type:`email`,value:s,maxLength:254,placeholder:O(`fromAddressPlaceholder`),onChange:e=>c(e.target.value)})]}),(0,X.jsxs)(`label`,{className:`mt-3 flex flex-col gap-1.5 font-medium`,children:[O(`fromName`),(0,X.jsx)(N,{value:l,maxLength:100,placeholder:O(`fromNamePlaceholder`),onChange:e=>u(e.target.value)})]}),(0,X.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-center justify-between gap-3`,children:[(0,X.jsx)(`span`,{children:O(`defaultFromAddress`)}),(0,X.jsx)(de,{checked:p,onChange:m,label:O(`defaultFromAddress`)})]}),(0,X.jsxs)(`label`,{className:`mt-3 flex flex-col gap-1.5 font-medium`,children:[O(`signature`),(0,X.jsx)(Yt,{value:d,maxLength:2e3,placeholder:O(`signaturePlaceholder`),onChange:e=>f(e.target.value)})]}),(0,X.jsx)(L,{message:r}),t&&!t.available&&(0,X.jsx)(zs,{}),e&&t?.available&&t.calls&&(0,X.jsx)(Ks,{address:e.address,calls:t.calls,...t.auto&&{auto:!0}})]})},Js=e=>e.signature?O(`ownSignature`):O(`genericSignature`),Ys=({senders:{address:e,senders:t,checks:n=!1},onAdd:r,onUpdate:i,onRemove:a,onCheck:s,onCheckResult:c})=>{let[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(),[p,m]=(0,Y.useState)(),h=(0,Y.useRef)(!1),g=t.find(e=>e.isDefault),_=()=>{m(void 0),f(void 0)},v=async e=>{if(!h.current){h.current=!0,u(!0),f(void 0);try{m(await e()||void 0)}catch(e){if(e instanceof TypeError)return f(O(`noAnswerFromServer`));if(!(e instanceof k))throw e;f(z(e))}finally{h.current=!1,u(!1)}}},y=e=>v(async()=>{let t=e.name||null,a=e.signature.trim()?e.signature:null;if(p?.kind===`change`)return void await i(p.sender.id,{name:t,signature:a,isDefault:e.isDefault});let o=await r({address:e.address,...t&&{name:t},...a&&{signature:a}});if(e.isDefault&&await i(o.id,{isDefault:!0}),n)return{kind:`change`,sender:{...o,isDefault:e.isDefault},autoCheck:!0}});return(0,X.jsxs)(`div`,{className:`mt-5 border-t pt-4`,children:[(0,X.jsx)(`h3`,{className:`font-semibold`,children:O(`fromAddresses`)}),(0,X.jsx)(`p`,{className:`mt-1 mb-3 text-muted-foreground`,children:O(`fromAddressesDescription`)}),(0,X.jsx)(L,{message:p?void 0:d}),(e||t.length>0)&&(0,X.jsxs)(`ul`,{className:`mb-3 divide-y rounded-md border`,children:[e&&(0,X.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,X.jsx)(Mr,{className:`size-4 shrink-0 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`bdi`,{className:`block truncate font-medium`,children:e}),(0,X.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:O(`mailboxOwnAddress`)})]}),g?(0,X.jsx)(M,{size:`sm`,variant:`ghost`,loading:l,onClick:()=>void v(async()=>void await i(g.id,{isDefault:!1})),children:O(`makeDefault`)}):(0,X.jsx)(H,{tone:`blue`,children:O(`default`)})]}),t.map(e=>(0,X.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,X.jsx)(Mr,{className:`size-4 shrink-0 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`bdi`,{className:`block truncate font-medium`,children:e.address}),e.name&&(0,X.jsx)(`bdi`,{className:`block truncate`,children:e.name}),(0,X.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:Js(e)})]}),e.isDefault&&(0,X.jsx)(H,{tone:`blue`,children:O(`default`)}),(0,X.jsx)(M,{size:`sm`,variant:`ghost`,onClick:()=>m({kind:`change`,sender:e}),children:O(`edit`)}),(0,X.jsx)(M,{size:`sm`,variant:`ghost`,onClick:()=>m({kind:`remove`,sender:e}),children:O(`remove`)})]},e.id))]}),(0,X.jsxs)(M,{onClick:()=>m({kind:`add`}),children:[(0,X.jsx)(oe,{className:`size-3.5`}),O(`addFromAddress`)]}),p?.kind===`add`&&(0,X.jsx)(qs,{check:{available:n},busy:l,error:d,onSave:e=>void y(e),onClose:_}),p?.kind===`change`&&(0,X.jsx)(qs,{sender:p.sender,check:((e,t=!1)=>({available:n,calls:{start:()=>s(e.id),result:t=>c(e.id,t)},...t&&{auto:t}}))(p.sender,p.autoCheck),busy:l,error:d,onSave:e=>void y(e),onClose:_},p.sender.id),p?.kind===`remove`&&(0,X.jsx)(o,{title:O(`removeFromAddress`,{address:p.sender.address}),description:O(`removeFromAddressDescription`),onClose:_,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:_,children:O(`cancel`)}),(0,X.jsx)(M,{variant:`danger`,loading:l,onClick:()=>void v(()=>a(p.sender.id)),children:O(`remove`)})]}),children:(0,X.jsx)(L,{message:d})})]})},Xs=(e,t,n)=>Object.fromEntries(Hn(e,t,{code:`not_linked`}).filter(e=>e.signInOnly).map(({link:e})=>[e.id,f(`signInOnly`,{provider:n(e.provider),name:e.name})])),Zs=({links:e})=>{let{session:t,linkPersonalMail:n,signInProviders:r}=_(),{account:i}=t,[a]=(0,Y.useState)(Gt),o=(0,Y.useCallback)(async()=>{let[t,n,r]=await Promise.all([i.linkedPersonalMail(e),i.linkedProviders(),i.mailSenders()]);return{mail:t,providers:n,senders:r}},[i,e]),{data:s,error:c,reload:l}=W(o,O(`couldNotReadMethods`));return s?(0,X.jsx)(Lt,{title:O(`mailbox`),description:O(`mailboxDescription`),providers:e.map(({id:e,name:t})=>({id:e,name:t})),linked:s.mail,notes:Xs(e,s,e=>r.find(t=>t.id===e)?.name??se(e)),reconnect:!0,onConnect:t=>n(e.find(e=>e.id===t)),error:a&&bt(a,e.length===1?e[0].name:O(`theProvider`)),children:(0,X.jsx)(Ys,{senders:s.senders,onAdd:async e=>{let t=await i.addMailSender(e);return m(),await l(),t},onUpdate:async(e,t)=>{await i.updateMailSender(e,t),m(),await l()},onRemove:async e=>{await i.removeMailSender(e),m(),await l()},onCheck:e=>i.checkMailSender(e),onCheckResult:(e,t)=>i.mailSenderCheckResult(e,t)})}):(0,X.jsx)(I,{error:c})},Qs=()=>{let{personalMail:e}=_();return e.length>0?(0,X.jsx)(Zs,{links:e}):null},$s=e=>Or(e.name)??`An unnamed app`,ec=e=>e.access.map(({role:e,organization:t})=>`as ${e||`no role`}${t?` in ${t}`:``}`).join(`, `),tc=({apps:e,onDisconnect:t})=>{let[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(),[s,c]=(0,Y.useState)(),l=async e=>{r(!0),a(void 0);try{await t(e.clientId),c(void 0)}catch(e){if(!(e instanceof k))throw e;a(z(e))}r(!1)};return(0,X.jsxs)(K,{title:`Connected apps`,description:`AI assistants and other apps you allowed to act as you here. Disconnecting one stops it within 15 minutes; it has to ask you again to come back.`,children:[(0,X.jsx)(L,{message:s?void 0:i}),e.length===0?(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:`No apps are connected. Add this app's MCP address to an AI assistant to connect one.`}):(0,X.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.map(e=>{let t=kr(e.clientId);return(0,X.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,X.jsx)(Pr,{className:`size-4 shrink-0 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`bdi`,{className:`block truncate font-medium`,children:$s(e)}),(0,X.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[t&&`Published by ${t} · `,`Allowed `,ot(Date.parse(e.allowedAt)),` · `,ec(e)]})]}),(0,X.jsx)(M,{size:`sm`,variant:`ghost`,onClick:()=>c(e),children:`Disconnect`})]},e.clientId)})}),s&&(0,X.jsx)(o,{title:`Disconnect ${$s(s)}?`,description:`It can no longer read or change anything as you. What it already started may keep working for up to 15 minutes.`,onClose:()=>c(void 0),actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:()=>c(void 0),children:`Cancel`}),(0,X.jsx)(M,{variant:`danger`,loading:n,onClick:()=>void l(s),children:`Disconnect`})]}),children:i&&(0,X.jsx)(L,{message:i})})]})},nc=(e,t)=>{let n=new URL(`https://claude.ai/customize/connectors`);return n.searchParams.set(`modal`,`add-custom-connector`),t&&n.searchParams.set(`connectorName`,t),n.searchParams.set(`connectorUrl`,e),n.href},rc=({url:e,appName:t})=>(0,X.jsx)(K,{title:O(`mcpAddress`),description:O(`mcpAddressDescription`),children:(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(Ar,{value:e,copyLabel:O(`copyMcpAddress`)}),(0,X.jsxs)(`a`,{href:nc(e,t),target:`_blank`,rel:`noreferrer`,className:p(),children:[(0,X.jsx)(b,{className:`size-3.5`}),O(`addToClaude`)]})]})}),ic=()=>{let{account:e}=_().session,{data:t,error:n,reload:r}=W((0,Y.useCallback)(()=>e.connectedApps(),[e]),O(`couldNotReadMethods`));return t?(0,X.jsx)(tc,{apps:t,onDisconnect:t=>e.disconnectApp(t).then(r)}):(0,X.jsx)(I,{error:n})},ac=({url:e})=>(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(rc,{url:e,appName:q().appName}),(0,X.jsx)(ic,{})]}),oc=()=>{let{mcp:e}=_();return e?(0,X.jsx)(ac,{url:e.url}):null},sc={30:30,90:90,365:365,never:void 0},cc={30:`expiresIn30Days`,90:`expiresIn90Days`,365:`expiresInAYear`,never:`neverExpires`},lc=e=>ot(Date.parse(e)),uc=e=>e?O(Date.parse(e)<=Date.now()?`expiredOn`:`expiresOn`,{date:lc(e)}):O(`neverExpires`),dc=e=>[O(`createdOn`,{date:lc(e.createdAt)}),uc(e.expiresAt),e.lastUsedAt?O(`lastUsedOn`,{date:lc(e.lastUsedAt)}):O(`notUsedYet`),e.organization?O(`actsAsIn`,{role:e.role,organization:e.organization}):O(`actsAs`,{role:e.role})].join(` · `),fc=({tokens:e,onCreate:t,onRevoke:n})=>{let[r,i]=(0,Y.useState)(!1),[a,s]=(0,Y.useState)(),[c,l]=(0,Y.useState)(),[u,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(`90`),[m,h]=(0,Y.useState)(),g=()=>{l(void 0),s(void 0),h(void 0)},_=(0,Y.useRef)(!1),v=async e=>{if(!_.current){_.current=!0,i(!0),s(void 0);try{l(await e()),h(void 0)}catch(e){if(e instanceof TypeError)return s(O(`noAnswerFromServer`));if(!(e instanceof k))throw e;e.code===`STRONG_SIGN_IN_REQUIRED`?h(`asked`):s(z(e))}finally{_.current=!1,i(!1)}}},y=()=>v(async()=>{let e=sc[f];return{kind:`created`,created:await t({name:u.trim(),...e!==void 0&&{expiresInDays:e}})}});return(0,X.jsxs)(K,{title:O(`accessTokens`),description:O(`accessTokensDescription`),children:[(0,X.jsx)(L,{message:c?void 0:a}),e.length===0?(0,X.jsx)(`p`,{className:`mb-3 text-muted-foreground`,children:O(`noAccessTokens`)}):(0,X.jsx)(`ul`,{className:`mb-3 divide-y rounded-md border`,children:e.map(e=>(0,X.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,X.jsx)(Ir,{className:`size-4 shrink-0 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`bdi`,{className:`block truncate font-medium`,children:e.name}),(0,X.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:dc(e)})]}),(0,X.jsx)(M,{size:`sm`,variant:`ghost`,onClick:()=>l({kind:`revoke`,token:e}),children:O(`revoke`)})]},e.id))}),(0,X.jsxs)(M,{onClick:()=>{d(``),p(`90`),l({kind:`create`})},children:[(0,X.jsx)(oe,{className:`size-3.5`}),O(`newAccessToken`)]}),c?.kind===`create`&&(0,X.jsxs)(o,{title:O(`newAccessToken`),description:O(`newAccessTokenDescription`),onClose:g,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:g,children:O(`cancel`)}),(0,X.jsx)(M,{variant:`primary`,loading:r,disabled:!u.trim(),onClick:()=>void y(),children:O(`createAccessToken`)})]}),children:[(0,X.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[O(`name`),(0,X.jsx)(N,{autoFocus:!0,value:u,maxLength:100,placeholder:O(`accessTokenNamePlaceholder`),onChange:e=>d(e.target.value)})]}),(0,X.jsxs)(`label`,{className:`mt-3 flex flex-col gap-1.5 font-medium`,children:[O(`accessTokenExpiry`),(0,X.jsx)(_e,{value:f,onChange:e=>p(e.target.value),children:Object.keys(sc).map(e=>(0,X.jsx)(`option`,{value:e,children:O(cc[e])},e))})]}),m===`asked`&&(0,X.jsx)(Sn,{purpose:`change`,minutes:15,onConfirmed:()=>h(`done`)}),m===`done`&&(0,X.jsx)(`p`,{className:`mt-2 text-muted-foreground`,children:O(`confirmedCreateAccessToken`)}),(0,X.jsx)(L,{message:a})]}),c?.kind===`created`&&(0,X.jsx)(o,{title:O(`accessTokenCreated`,{name:c.created.personalAccessToken.name}),description:O(`accessTokenCreatedDescription`),onClose:g,actions:(0,X.jsx)(M,{variant:`primary`,onClick:g,children:O(`done`)}),children:(0,X.jsx)(Ar,{value:c.created.token,copyLabel:O(`copyAccessToken`)})}),c?.kind===`revoke`&&(0,X.jsx)(o,{title:O(`revokeAccessToken`,{name:c.token.name}),description:O(`revokeAccessTokenDescription`),onClose:g,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:g,children:O(`cancel`)}),(0,X.jsx)(M,{variant:`danger`,loading:r,onClick:()=>void v(async()=>(await n(c.token.id),void 0)),children:O(`revoke`)})]}),children:(0,X.jsx)(L,{message:a})})]})},pc=()=>{let{account:e}=_().session,{data:t,error:n,reload:r}=W((0,Y.useCallback)(()=>e.personalAccessTokens(),[e]),O(`couldNotReadAccessTokens`));return t?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(L,{message:n}),(0,X.jsx)(fc,{tokens:t,onCreate:t=>e.createPersonalAccessToken(t).then(e=>(r(),e),async e=>{throw await r(),e}),onRevoke:t=>e.revokePersonalAccessToken(t).finally(r)})]}):(0,X.jsx)(I,{error:n})},mc=()=>_().personalAccessTokens?(0,X.jsx)(pc,{}):null,hc={revoked:`disconnectedRevoked`,queued:`disconnectedQueued`,not_revoked:`disconnectedNotRevoked`},gc=e=>e.provider===`google`,_c=({connections:e,onConnect:t,onDisconnect:n,error:r})=>{let[i,a]=(0,Y.useState)(),[s,c]=(0,Y.useState)(r),[l,u]=(0,Y.useState)(),[d,f]=(0,Y.useState)(),p=async(e,t)=>{a(e),c(void 0),f(void 0);try{await t(),u(void 0)}catch(e){if(!(e instanceof k))throw e;c(z(e))}finally{a(void 0)}};return(0,X.jsxs)(K,{title:O(`connections`),description:O(`connectionsDescription`),children:[(0,X.jsx)(L,{message:l?void 0:s}),(0,X.jsx)(ht,{message:d}),(0,X.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.map(e=>(0,X.jsxs)(`li`,{className:`flex flex-col gap-2 px-3 py-2.5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,X.jsx)(Br,{className:`size-4 shrink-0 text-muted-foreground`}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-medium`,children:e.label}),(0,X.jsx)(M,{size:`sm`,loading:i===e.key,disabled:i!==void 0,onClick:()=>void p(e.key,()=>t(e)),children:e.accounts.length>0?O(`connectAgain`,{name:e.label}):O(`connect`,{name:e.label})})]}),e.accounts.map(t=>(0,X.jsxs)(Y.Fragment,{children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 pl-7 text-sm`,children:[(0,X.jsxs)(`span`,{className:`min-w-0 flex-1 text-muted-foreground`,children:[O(`connectedOn`,{date:ot(Date.parse(t.created_at))}),` · `,(0,X.jsx)(`code`,{className:`text-xs`,children:t.id})]}),t.needs_sign_in?(0,X.jsx)(H,{tone:`amber`,children:O(`connectionNeedsSignIn`)}):(0,X.jsx)(H,{tone:`green`,children:O(`connected`)}),(0,X.jsx)(M,{size:`sm`,variant:`ghost`,onClick:()=>u({connection:e,accountId:t.id}),children:O(`disconnect`)})]}),t.used_by.length>0&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 pl-7 text-sm`,children:[(0,X.jsx)(`span`,{className:`text-muted-foreground`,children:O(`connectionUsedBy`)}),t.used_by.map(e=>(0,X.jsx)(Ke,{resource:`workflows`,recordKey:e.id,className:`font-medium text-primary-text hover:underline`,children:e.name},e.id))]})]},t.id))]},e.key))}),l&&(0,X.jsx)(o,{title:O(`disconnectTitle`,{name:l.connection.label}),description:gc(l.connection)?`${O(`disconnectDescription`)} ${O(`disconnectWholeGrant`)}`:O(`disconnectDescription`),onClose:()=>u(void 0),actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:()=>u(void 0),children:O(`cancel`)}),(0,X.jsx)(M,{variant:`danger`,loading:i===l.accountId,onClick:()=>void p(l.accountId,async()=>f(O(hc[await n(l.accountId)]))),children:O(`disconnect`)})]}),children:s&&(0,X.jsx)(L,{message:s})})]})},vc=()=>{let{session:e,connectAccount:t}=_(),{account:n}=e,[r]=(0,Y.useState)(Gt),{data:i,error:a,reload:o}=W((0,Y.useCallback)(()=>n.workflowConnections(),[n]),O(`couldNotReadMethods`));return i?i.length===0?null:(0,X.jsx)(_c,{connections:i,onConnect:t,onDisconnect:e=>n.disconnectAccount(e).finally(o),error:r&&bt(r,O(`theProvider`))}):(0,X.jsx)(I,{error:a})},yc=e=>e.code===`LAST_ADMIN`?O(`deleteAccountLastAdmin`):e.code===`ACCOUNT_LOCKED`?O(`deleteAccountLocked`):z(e),bc=({hasPassword:e,onDelete:t,onClose:n})=>{let[r,i]=(0,Y.useState)(``),[a,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(),[u,d]=(0,Y.useState)(!1),f=(0,Y.useId)(),p=async()=>{s(!0),l(void 0),d(!1);try{await t(e?r:void 0)}catch(e){if(!(e instanceof k))throw e;e.code===`STRONG_SIGN_IN_REQUIRED`?d(!0):l(yc(e)),s(!1)}};return(0,X.jsxs)(o,{title:O(`deleteAccountQuestion`),description:O(`deleteAccountWarning`),onClose:n,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:n,children:O(`cancel`)}),(0,X.jsx)(M,{variant:`danger`,type:`submit`,form:f,loading:a,disabled:e&&!r,children:O(`deleteAccountConfirm`)})]}),children:[(0,X.jsxs)(`form`,{id:f,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),p()},children:[e&&(0,X.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[O(`deleteAccountPassword`),(0,X.jsx)(N,{type:`password`,name:`current-password`,autoComplete:`current-password`,autoFocus:!0,value:r,invalid:!!c,onChange:e=>i(e.target.value)})]}),(0,X.jsx)(L,{message:c})]}),u&&(0,X.jsx)(Sn,{purpose:`change`,minutes:15,onConfirmed:()=>void p()})]})},xc=({hasPassword:e,staff:t,onDelete:n})=>{let[r,i]=(0,Y.useState)(!1);return(0,X.jsxs)(K,{title:O(`deleteAccount`),description:O(t?`deleteAccountStaff`:`deleteAccountDescription`),children:[!t&&(0,X.jsx)(M,{variant:`danger`,onClick:()=>i(!0),children:O(`deleteAccount`)}),r&&(0,X.jsx)(bc,{hasPassword:e,onDelete:n,onClose:()=>i(!1)})]})},Sc=()=>{let{session:e,state:t,deleteAccount:n}=_(),{account:r}=e,{data:i,error:a}=W((0,Y.useCallback)(()=>r.signInMethods(),[r]),O(`couldNotReadMethods`));return i?(0,X.jsx)(xc,{hasPassword:i.account.password,staff:t.kind===`signed-in`&&!!t.staff,onDelete:n}):(0,X.jsx)(I,{error:a})},Cc=[[/Edg(e|A|iOS)?\//,`Edge`],[/OPR\/|Opera/,`Opera`],[/SamsungBrowser\//,`Samsung Internet`],[/Firefox\/|FxiOS\//,`Firefox`],[/Chrome\/|CriOS\//,`Chrome`],[/Safari\//,`Safari`]],wc=[[/iPhone/,`iPhone`],[/iPad/,`iPad`],[/Android/,`Android`],[/CrOS/,`ChromeOS`],[/Windows/,`Windows`],[/Mac OS X|Macintosh/,`macOS`],[/Linux/,`Linux`]],Tc=(e,t)=>e.find(([e])=>e.test(t))?.[1],Ec=e=>e?{browser:Tc(Cc,e),system:Tc(wc,e)}:{},Dc=e=>e.device?O(`deviceThrough`,{device:e.device,provider:e.name}):e.name,Oc=(e,t)=>{if(e.staff)return t?O(`staffOf`,{operator:t}):O(`staff`);let{browser:n,system:r}=Ec(e.userAgent);return n&&r?O(`browserOn`,{browser:n,system:r}):r?O(`aBrowserOn`,{system:r}):n??O(`unknownDevice`)},kc=e=>{if(e.staff)return Hr;let{system:t}=Ec(e.userAgent);return t===`iPhone`||t===`Android`?Wr:t===`iPad`?Kr:Rr},Ac=e=>[...e].sort((e,t)=>Number(t.current)-Number(e.current)||t.createdAt.localeCompare(e.createdAt)),jc=(e,t)=>e.kind===`one`?O(`signOutDevice`,{name:Oc(e.session,t)}):e.kind===`link`?O(`signOutDevice`,{name:Dc(e.link)}):O(`signOutOthersTitle`),Mc=e=>O(e.kind===`one`?`signOutDeviceDescription`:e.kind===`link`?`signOutLinkedDeviceDescription`:`signOutOthersDescription`),Nc=({sessions:e,operator:t,links:n=[],onSignOut:r,onSignOutOthers:i,onSignOutLink:a})=>{let[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(),[d,f]=(0,Y.useState)(),p=e.filter(e=>!n.some(t=>t.sessions.includes(e.token))),m=e.filter(e=>!e.current),h=e=>e.kind===`one`?r(e.session.token):e.kind===`link`?a(e.link.id):i(),g=async e=>{c(!0),u(void 0);try{await h(e),f(void 0)}catch(e){if(!(e instanceof k))throw e;u(z(e))}c(!1)},_=e=>{u(void 0),f(e)};return(0,X.jsxs)(K,{title:O(`devices`),description:O(`devicesDescription`),children:[p.length===0&&n.length===0?(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:O(`noDevices`)}):(0,X.jsxs)(`ul`,{className:`divide-y rounded-md border`,children:[Ac(p).map(e=>{let n=kc(e);return(0,X.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,X.jsx)(n,{className:`size-4 shrink-0 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`bdi`,{className:`truncate font-medium`,children:Oc(e,t)}),e.current&&(0,X.jsx)(H,{tone:`green`,children:O(`thisDevice`)})]}),(0,X.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[O(`signedInFromUntil`,{from:Ft(Date.parse(e.createdAt)),until:Ft(Date.parse(e.expiresAt))}),!e.staff&&e.ipAddress&&` · ${e.ipAddress}`]})]}),!e.current&&(0,X.jsx)(M,{size:`sm`,variant:`ghost`,onClick:()=>_({kind:`one`,session:e}),children:O(`signOut`)})]},e.token)}),n.map(t=>{let n=e.some(e=>e.current&&t.sessions.includes(e.token));return(0,X.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,X.jsx)(Wr,{className:`size-4 shrink-0 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`bdi`,{className:`truncate font-medium`,children:Dc(t)}),n&&(0,X.jsx)(H,{tone:`green`,children:O(`thisDevice`)})]}),(0,X.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:O(`linkedOn`,{date:Ft(Date.parse(t.linkedAt))})})]}),!n&&a&&(0,X.jsx)(M,{size:`sm`,variant:`ghost`,onClick:()=>_({kind:`link`,link:t}),children:O(`signOut`)})]},t.id)})]}),m.length>0&&(0,X.jsx)(M,{className:`mt-3`,onClick:()=>_({kind:`others`}),children:O(`signOutOthers`)}),d&&(0,X.jsx)(o,{title:jc(d,t),description:Mc(d),onClose:()=>f(void 0),actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:()=>f(void 0),children:O(`cancel`)}),(0,X.jsx)(M,{variant:`danger`,loading:s,onClick:()=>void g(d),children:O(`signOut`)})]}),children:(0,X.jsx)(L,{message:l})})]})},Pc=()=>{let{session:e,staffSignIn:t,deviceLinks:n}=_(),{account:r}=e,i=(0,Y.useCallback)(async()=>{let[e,t]=await Promise.all([r.sessions(),n?r.deviceLinks():[]]);return{sessions:e,links:t}},[r,n]),{data:a,error:o,reload:s}=W(i,O(`couldNotReadDevices`));return a?(0,X.jsx)(Nc,{sessions:a.sessions,links:a.links,operator:t,onSignOut:e=>r.revokeSession(e).then(s),onSignOutOthers:()=>r.revokeOtherSessions().then(s),onSignOutLink:e=>r.signOutDeviceLink(e).then(s)}):(0,X.jsx)(I,{error:o})},Fc={allowed:`passkeysAllowed`,required:`passkeysRequired`,forbidden:`passkeysForbidden`},Ic=({rule:e,passkeys:t,onAdd:n,onRename:r,onRemove:i})=>{let[a,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(),[u,d]=(0,Y.useState)(),[f,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)(),g=e===`required`&&t.length<=1,_=async e=>{s(!0),l(void 0),h(void 0);try{await e(),d(void 0)}catch(e){if(!(e instanceof k))throw e;e.code===`STRONG_SIGN_IN_REQUIRED`?h(`asked`):l(z(e))}s(!1)};return(0,X.jsxs)(K,{title:O(`passkeys`),status:e===`required`&&(0,X.jsx)(H,{tone:`blue`,children:O(`required`)}),description:O(Fc[e]),children:[(0,X.jsx)(L,{message:u?void 0:c}),t.length>0&&(0,X.jsx)(`ul`,{className:`mb-3 divide-y rounded-md border`,children:t.map(e=>(0,X.jsxs)(`li`,{className:`flex flex-wrap items-center gap-3 px-3 py-2.5`,children:[(0,X.jsx)(S,{className:`size-4 shrink-0 text-muted-foreground`}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block truncate font-medium`,children:e.name??O(`passkey`)}),(0,X.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[e.createdAt?O(`addedOn`,{date:ot(Date.parse(e.createdAt))}):O(`addedEarlier`),` · `,e.backedUp?O(`synced`):O(`oneDevice`)]})]}),(0,X.jsxs)(`span`,{className:`flex gap-1`,children:[(0,X.jsx)(M,{size:`sm`,variant:`ghost`,onClick:()=>{p(e.name??``),d({kind:`rename`,passkey:e})},children:O(`rename`)}),(0,X.jsx)(M,{size:`sm`,variant:`ghost`,disabled:g,title:g?O(`keepLastPasskey`):void 0,onClick:()=>d({kind:`remove`,passkey:e}),children:O(`remove`)})]})]},e.id))}),e!==`forbidden`&&(0,X.jsxs)(M,{loading:a&&!u,onClick:()=>void _(n),children:[(0,X.jsx)(oe,{className:`size-3.5`}),O(`addPasskey`)]}),m===`asked`&&(0,X.jsx)(Sn,{purpose:`change`,withPassword:!0,minutes:15,onConfirmed:()=>h(`done`)}),m===`done`&&(0,X.jsx)(`p`,{className:`mt-2 text-muted-foreground`,children:O(`confirmedAddPasskey`)}),u?.kind===`rename`&&(0,X.jsxs)(o,{title:O(`renamePasskey`),description:O(`renamePasskeyDescription`),onClose:()=>d(void 0),actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:()=>d(void 0),children:O(`cancel`)}),(0,X.jsx)(M,{variant:`primary`,loading:a,disabled:!f.trim(),onClick:()=>void _(()=>r(u.passkey.id,f.trim())),children:O(`save`)})]}),children:[(0,X.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[O(`name`),(0,X.jsx)(N,{autoFocus:!0,value:f,maxLength:60,onChange:e=>p(e.target.value)})]}),(0,X.jsx)(L,{message:c})]}),u?.kind===`remove`&&(0,X.jsx)(o,{title:O(`removePasskey`),description:O(`removePasskeyDescription`,{name:u.passkey.name??O(`thisPasskey`)}),onClose:()=>d(void 0),actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:()=>d(void 0),children:O(`cancel`)}),(0,X.jsx)(M,{variant:`danger`,loading:a,onClick:()=>void _(()=>i(u.passkey.id)),children:O(`remove`)})]}),children:c&&(0,X.jsx)(L,{message:c})})]})},Lc=()=>{let{account:e}=_().session,t=(0,Y.useCallback)(()=>Promise.all([e.signInMethods(),e.passkeys()]),[e]),{data:n,error:r,reload:i}=W(t,O(`couldNotReadMethods`));if(!n)return(0,X.jsx)(I,{error:r});let[a,o]=n;return(0,X.jsx)(Ic,{rule:a.policy.passkey,passkeys:o,onAdd:()=>e.addPasskey().then(i),onRename:(t,n)=>e.renamePasskey(t,n).then(i),onRemove:t=>e.removePasskey(t).then(i)})},Rc=e=>e.code===`PASSWORD_TOO_SHORT`?O(`useAtLeast`,{length:12}):e.code===`PASSWORD_TOO_LONG`?O(`passwordTooLong`):z(e),zc=(e,t)=>{if(e.length<12)return O(`useAtLeast`,{length:12});if(e!==t)return O(`passwordsDiffer`)},Bc=({hasPassword:e,onSave:t,onClose:n})=>{let[r,i]=(0,Y.useState)(``),[a,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(),m=(0,Y.useId)(),h=(!e||r)&&a&&c,g=async()=>{let e=zc(a,c);if(p(e),!e){d(!0);try{await t({current:r,next:a})}catch(e){if(!(e instanceof k))throw e;p(Rc(e)),d(!1)}}};return(0,X.jsx)(o,{title:O(e?`changePassword`:`setPassword`),description:O(`atLeast`,{length:12}),onClose:n,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:n,children:O(`cancel`)}),(0,X.jsx)(M,{variant:`primary`,type:`submit`,form:m,loading:u,disabled:!h,children:O(`save`)})]}),children:(0,X.jsxs)(`form`,{id:m,className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),g()},children:[e&&(0,X.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[O(`currentPassword`),(0,X.jsx)(N,{type:`password`,name:`current-password`,autoComplete:`current-password`,autoFocus:!0,value:r,onChange:e=>i(e.target.value)})]}),(0,X.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[O(`newPassword`),(0,X.jsx)(N,{type:`password`,name:`new-password`,autoComplete:`new-password`,autoFocus:!e,value:a,invalid:!!f,onChange:e=>s(e.target.value)})]}),(0,X.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[O(`repeatPassword`),(0,X.jsx)(N,{type:`password`,name:`repeat-password`,autoComplete:`new-password`,value:c,invalid:!!f,onChange:e=>l(e.target.value)})]}),e&&(0,X.jsx)(`p`,{className:`text-muted-foreground`,children:O(`changeSignsOutOthers`)}),(0,X.jsx)(L,{message:f})]})})},Vc=({rule:e,hasPassword:t,staff:n})=>O(n?`passwordStaff`:e===`forbidden`?`passwordForbidden`:t?`passwordIsSet`:`passwordNotSet`),Hc=({rule:e,hasPassword:t,staff:n,onChange:r,onSet:i})=>{let[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),l=!n&&e===`allowed`;return(0,X.jsxs)(K,{title:O(`password`),description:Vc({rule:e,hasPassword:t,staff:n}),children:[(0,X.jsx)(ht,{message:s?O(`passwordSaved`):void 0}),l&&(0,X.jsx)(M,{onClick:()=>{c(!1),o(!0)},children:O(t?`changePassword`:`setPassword`)}),a&&(0,X.jsx)(Bc,{hasPassword:t,onClose:()=>o(!1),onSave:async({current:e,next:n})=>{await(t?r(e,n):i(n)),o(!1),c(!0)}})]})},Uc=()=>{let{session:e,state:t}=_(),{account:n}=e,{data:r,error:i,reload:a}=W((0,Y.useCallback)(()=>n.signInMethods(),[n]),O(`couldNotReadMethods`));return r?(0,X.jsx)(Hc,{rule:r.policy.password,hasPassword:r.account.password,staff:t.kind===`signed-in`&&!!t.staff,onChange:(e,t)=>n.changePassword(e,t).then(a),onSet:e=>n.setPassword(e).then(a)}):(0,X.jsx)(I,{error:i})},Wc=({email:e,change:t,onDone:n,onClose:r})=>{let[i,a]=(0,Y.useState)(``),[s,c]=(0,Y.useState)(),[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)(),h=async e=>{f(!0),m(void 0);try{await e()}catch(e){if(!(e instanceof k))throw e;m(z(e))}f(!1)},g=i.trim(),_=()=>h(async()=>{await t.request(g),u(``),c(g)}),v=e=>h(async()=>{await t.confirm(s,e),n()});return s?(0,X.jsxs)(o,{title:O(`changeEmail`),description:O(`codeSentTo`,{email:s,minutes:10}),onClose:r,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{variant:`ghost`,onClick:()=>{c(void 0),m(void 0)},children:O(`otherAddress`)}),(0,X.jsx)(M,{variant:`primary`,loading:d,disabled:l.length<6,onClick:()=>void v(l),children:O(`changeEmail`)})]}),children:[(0,X.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[O(`code`),(0,X.jsx)(ve,{name:`code`,required:!0,autoFocus:!0,value:l,invalid:!!p,onChange:u,onComplete:e=>!d&&void v(e)})]}),(0,X.jsx)(L,{message:p})]}):(0,X.jsxs)(o,{title:O(`changeEmail`),description:O(`changeEmailDescription`),onClose:r,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:r,children:O(`cancel`)}),(0,X.jsx)(M,{variant:`primary`,loading:d,disabled:!g||g.toLowerCase()===e.toLowerCase(),onClick:()=>void _(),children:O(`sendCode`)})]}),children:[(0,X.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[O(`newEmail`),(0,X.jsx)(N,{type:`email`,autoComplete:`email`,autoFocus:!0,value:i,onChange:e=>a(e.target.value)})]}),(0,X.jsx)(L,{message:p})]})},Gc=({name:e,email:t,onRename:n,emailChange:r,onEmailChanged:i})=>{let[a,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)(),g=async()=>{p(!0),h(void 0);try{await n(u.trim()),s(!1)}catch(e){if(!(e instanceof k))throw e;h(z(e))}p(!1)};return(0,X.jsxs)(K,{title:O(`profile`),description:O(`profileDescription`),children:[(0,X.jsxs)(`dl`,{className:`mb-3 grid grid-cols-[auto_1fr] gap-x-6 gap-y-1.5`,children:[(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:O(`name`)}),(0,X.jsx)(`dd`,{className:`min-w-0 truncate font-medium`,children:e}),(0,X.jsx)(`dt`,{className:`text-muted-foreground`,children:O(`email`)}),(0,X.jsx)(`dd`,{className:`min-w-0 truncate font-medium`,children:t})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(M,{onClick:()=>{d(e),h(void 0),s(!0)},children:O(`changeName`)}),r&&(0,X.jsx)(M,{onClick:()=>l(!0),children:O(`changeEmail`)})]}),a&&(0,X.jsxs)(o,{title:O(`changeName`),description:O(`changeNameDescription`),onClose:()=>s(!1),actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:()=>s(!1),children:O(`cancel`)}),(0,X.jsx)(M,{variant:`primary`,loading:f,disabled:!u.trim()||u.trim()===e,onClick:()=>void g(),children:O(`save`)})]}),children:[(0,X.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[O(`name`),(0,X.jsx)(N,{autoFocus:!0,value:u,maxLength:100,onChange:e=>d(e.target.value)})]}),(0,X.jsx)(L,{message:m})]}),c&&r&&(0,X.jsx)(Wc,{email:t,change:r,onClose:()=>l(!1),onDone:()=>{l(!1),i?.()}})]})},Kc=()=>{let{session:e,changeEmail:t}=_(),{data:n,loaded:r,error:i,reload:a}=W((0,Y.useCallback)(()=>e.session(),[e]),O(`couldNotReadProfile`));if(!r)return(0,X.jsx)(I,{error:i});if(!n)return null;let o=t?{request:e.account.requestEmailChange,confirm:e.account.changeEmail}:void 0;return(0,X.jsx)(Gc,{name:n.name,email:n.email,onRename:t=>e.account.updateName(t).then(a),emailChange:o,onEmailChanged:a})},qc=({title:e,description:t,confirmLabel:n,danger:r,needsPassword:i,onConfirm:a,onClose:s})=>{let[c,l]=(0,Y.useState)(``),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(),[m,h]=(0,Y.useState)(!1),g=async()=>{d(!0),p(void 0),h(!1);try{await a(i?c:void 0)}catch(e){if(!(e instanceof k))throw e;e.code===`STRONG_SIGN_IN_REQUIRED`?h(!0):p(z(e)),d(!1)}};return(0,X.jsxs)(o,{title:e,description:t,onClose:s,actions:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(M,{onClick:s,children:O(`cancel`)}),(0,X.jsx)(M,{variant:r?`danger`:`primary`,loading:u,disabled:i&&!c,onClick:()=>void g(),children:n})]}),children:[i&&(0,X.jsxs)(`label`,{className:`flex flex-col gap-1.5 font-medium`,children:[O(`yourPassword`),(0,X.jsx)(N,{type:`password`,autoComplete:`current-password`,autoFocus:!0,value:c,invalid:!!f,onChange:e=>l(e.target.value),onKeyDown:e=>e.key===`Enter`&&c&&void g()})]}),f&&(0,X.jsx)(`p`,{role:`alert`,className:`mt-2 text-body font-medium text-danger-text`,children:f}),m&&(0,X.jsx)(Sn,{purpose:`change`,minutes:15,onConfirmed:()=>void g()})]})},Jc={allowed:`twoFactorAllowed`,required:`twoFactorRequired`,forbidden:`twoFactorForbidden`},Yc=e=>{let{rule:t,enabled:n,authenticatorApp:r,mail:i,needsPassword:a,onTurnOff:s,onNewBackupCodes:c,onChanged:l}=e,[u,d]=(0,Y.useState)(),f=()=>d(void 0),p=n?(0,X.jsx)(H,{tone:`green`,children:O(`on`)}):t===`required`?(0,X.jsx)(H,{tone:`amber`,children:O(`required`)}):(0,X.jsx)(H,{children:O(`off`)}),m=O(n?r?i?`twoFactorOnWithAppOrMail`:`twoFactorOnWithApp`:`twoFactorOnWithMail`:Jc[t]);return u?.kind===`setup`?(0,X.jsx)(K,{title:O(`twoFactor`),status:p,description:m,children:(0,X.jsx)(`div`,{className:`max-w-sm`,children:(0,X.jsx)(hn,{offerEmailedCodes:i&&!u.appOnly,needsPassword:a,onStartApp:e.onStartApp,onConfirmApp:e.onConfirmApp,onEmailedCodes:e.onEmailedCodes,onCancel:f,onDone:()=>{f(),l()}})})}):(0,X.jsxs)(K,{title:O(`twoFactor`),status:p,description:m,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[!n&&t!==`forbidden`&&(0,X.jsx)(M,{variant:`primary`,onClick:()=>d({kind:`setup`,appOnly:!1}),children:O(`turnOn`)}),n&&!r&&t!==`forbidden`&&(0,X.jsx)(M,{onClick:()=>d({kind:`setup`,appOnly:!0}),children:O(`addAuthenticator`)}),n&&r&&(0,X.jsx)(M,{onClick:()=>d({kind:`new-codes`}),children:O(`newBackupCodes`)}),n&&(0,X.jsx)(M,{variant:`danger`,disabled:t===`required`,title:t===`required`?O(`twoFactorIsRequired`):void 0,onClick:()=>d({kind:`turn-off`}),children:O(`turnOff`)})]}),u?.kind===`turn-off`&&(0,X.jsx)(qc,{title:O(`turnOffTitle`),description:O(`turnOffDescription`),confirmLabel:O(`turnOff`),danger:!0,needsPassword:a,onClose:f,onConfirm:async e=>{await s(e),f(),l()}}),u?.kind===`new-codes`&&(0,X.jsx)(qc,{title:O(`newCodesTitle`),description:O(`newCodesDescription`),confirmLabel:O(`makeNewCodes`),needsPassword:a,onClose:f,onConfirm:async e=>d({kind:`codes`,codes:await c(e)})}),u?.kind===`codes`&&(0,X.jsx)(o,{title:O(`yourNewCodes`),description:O(`keepCodesSafe`),onClose:f,actions:(0,X.jsx)(M,{variant:`primary`,onClick:f,children:O(`savedCodes`)}),children:(0,X.jsx)(Dn,{codes:u.codes})})]})},Xc=()=>{let{account:e}=_().session,{data:t,error:n,reload:r}=W((0,Y.useCallback)(()=>e.signInMethods(),[e]),O(`couldNotReadMethods`));return t?(0,X.jsx)(Yc,{rule:t.policy.twoFactor,enabled:t.account.twoFactor,authenticatorApp:t.account.authenticatorApp,mail:t.mail,needsPassword:t.account.password,onStartApp:t=>e.startAuthenticatorApp(t),onConfirmApp:t=>e.confirmAuthenticatorApp(t),onEmailedCodes:t=>e.turnOnEmailedCodes(t),onTurnOff:t=>e.turnOffTwoFactor(t),onNewBackupCodes:t=>e.newBackupCodes(t),onChanged:r}):(0,X.jsx)(I,{error:n})},Zc=({problem:e,fallback:t})=>t===void 0?(0,X.jsx)(rn,{children:e}):(0,X.jsxs)(X.Fragment,{children:[!1,t]}),Qc=({name:e,registered:t,fallback:n,children:r})=>t?(0,X.jsx)(Qe,{name:e,fallback:n===void 0?void 0:(0,X.jsx)(Zc,{problem:V.rich(`couldNotDraw`,{name:e}),fallback:n}),children:r}):(0,X.jsx)(Zc,{problem:V.rich(`noComponent`,{component:e}),fallback:n}),$c={Page:to,Grid:ja,Card:di,Stat:Bo,RecordCard:ao,Field:Ea,Diff:Ca,Table:Go,CardRow:hi,RecordRow:To,RecordCards:xo,Chart:gi,Timeline:ta,Graph:aa,Progress:ro,Image:za,ModalForm:eo,Thread:vs,Composer:ba,Action:ui,Show:No,Switch:Fo,Match:Io,Link:Ya,Settings:ko,Tabs:qo,Tab:Jo,Users:Rs,Profile:Kc,Password:Uc,Passkeys:Lc,TwoFactor:Xc,ConnectedAccounts:$e,PersonalMail:Qs,Connections:vc,Devices:Pc,ConnectedApps:oc,PersonalAccessTokens:mc,DeleteAccount:Sc,Box:ys,Row:bs,Column:xs,Text:Ss,ReferenceManyField:Ds,ReferenceArrayField:ks,ArrayField:Cs,RecordsIterator:pi,ReferenceField:js,SelectInput:ws,Details:xa,Summary:Sa,TextField:Ha,NumberField:Ua,DateField:Wa,BooleanField:Ga,UrlField:Ka,ChipField:qa},el=new Set(`Page.Grid.Card.Stat.RecordCard.Field.Diff.Table.CardRow.RecordRow.RecordCards.Chart.Timeline.Graph.Progress.Image.Thread.Link.Tabs.Settings.Show.Switch.Action.Box.Row.Column.Text.ReferenceField.SelectInput.Details.Summary.TextField.NumberField.DateField.BooleanField.UrlField.ChipField`.split(`.`)),tl=(e,t,...n)=>e.map((e,r)=>({child:e,...t!==void 0&&{at:ae(t,...n,r)}})),nl=({text:e})=>{let t=R(),n=an(),r={...F(t),params:n};return(0,X.jsx)(X.Fragment,{children:en(e,e=>dn(ze(r,e)))})},rl=(e,t)=>e.includes(`{{`)?(0,X.jsx)(nl,{text:e},t):(0,X.jsx)(Y.Fragment,{children:e},t),il=e=>e.map(({child:e,at:t},n)=>typeof e==`string`?rl(e,n):(0,X.jsx)(dl,{node:e,at:t},n)),al=e=>{let t=[];for(let n of e){let e=t.at(-1);Xr(n.child)&&e&&Xr(e[0].child)?e.push(n):t.push([n])}return t.map((e,t)=>{let[n]=e;return Xr(n.child)?(0,X.jsx)(`p`,{className:`leading-6`,children:il(e)},t):(0,X.jsx)(dl,{node:n.child,at:n.at},t)})},ol=e=>tn(e)||Array.isArray(e)&&e.length>0&&e.every(tn),sl=(e,t)=>Object.fromEntries(Object.entries(e.props).flatMap(([e,n])=>ol(n)?[[e,(0,X.jsx)(X.Fragment,{children:al(cl(n,t,e))})]]:[])),cl=(e,t,n)=>Array.isArray(e)?tl(e,t,`props`,n):[{child:e,...t!==void 0&&{at:ae(t,`props`,n)}}],ll=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ul=(e,t)=>{let n=ll(e.props.components)?e.props.components:{},r=Object.fromEntries(Object.entries(n).flatMap(([e,t])=>tn(t)?[[e,e=>({...t,children:[...t.children,...e]})]]:[])),i=Mn(t,String(e.props.i18nKey),ll(e.props.values)?e.props.values:{},r);return Array.isArray(i)?i.map(e=>typeof e==`string`||tn(e)?e:String(e)):[i]},dl=({node:e,at:t})=>{let{components:n}=y(),r=R(),i=an(),a=Cn(),o=(0,Y.useMemo)(()=>ke(w(e,{...F(r),params:i}),a),[e,r,i,a]);if(o.type===`Trans`&&!o.custom)return(0,X.jsx)(X.Fragment,{children:il(ul(o,a).map(e=>({child:e})))});if(o.custom){let e=n?.[o.type],r=o.children.length>0?(0,X.jsx)(na,{node:o,children:al(tl(o.children,t,`children`))}):void 0;return(0,X.jsx)(Qc,{name:o.type,registered:!!e,fallback:o.fallback&&(0,X.jsx)(X.Fragment,{children:al(tl(o.fallback,t,`fallback`))}),children:e&&(0,X.jsx)(Vt,{node:o,...t!==void 0&&{at:t},children:(0,X.jsx)(e,{...Be(o.props),children:r})})})}let s=$c[o.type];if(!s)return(0,X.jsx)(rn,{children:V.rich(`unknownBlock`,{type:o.type})});let c=typeof o.props.className==`string`?o.props.className:void 0,l=tl(o.children,t,`children`),u=(0,X.jsx)(s,{node:o,at:t,slots:sl(o,t),className:c,children:o.type===`Text`||o.type===`Link`||o.type===`Summary`?il(l):al(o.type===`Switch`?l.filter(({child:e})=>typeof e!=`string`):l)}),d=c===void 0||el.has(o.type)?u:(0,X.jsx)(`div`,{className:c,children:u});return o.fallback?(0,X.jsx)(Qe,{name:o.type,resetKey:o,fallback:(0,X.jsx)(X.Fragment,{children:al(tl(o.fallback,t,`fallback`))}),children:d}):d};export{ms as a,ns as c,yo as d,lo as f,ua as h,gs as i,Vo as l,ya as m,Qc as n,ps as o,oo as p,_s as r,ds as s,dl as t,Ao as u};
3
- //# debugId=f2be8cde-4728-48c4-af02-b802f6ab262b
@@ -1,2 +0,0 @@
1
- (function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{Cc as r,Cr as i,Fa as a,Ga as o,Ja as s,Ml as c,Ol as l,Pa as u,Sc as d,Tc as f,Ti as p,Tl as m,Ts as h,fn as g,fu as _,gl as v,hl as y,ir as b,lc as x,mu as S,ol as C,qr as w,rr as T,si as E,so as D,ti as O,tl as k,uc as A,vs as j,wn as M}from"./app-DANB5cb3.js";import{h as N,o as P}from"./vendor-t7Q7QbPu.js";import{Q as F}from"./embedded-list-CepLmiOu.js";import{n as I}from"./lib-dnd-kit-sortable-CNDSKqCD.js";import{a as L,i as R,n as z,o as B,r as ee,s as V,t as H}from"./messages-CEK97JXa.js";var U={name:`arrow-up-down`,size:24,node:[[`path`,{d:`m21 16-4 4-4-4`,key:`f6ql7i`}],[`path`,{d:`M17 20V4`,key:`1ejh1v`}],[`path`,{d:`m3 8 4-4 4 4`,key:`11wl7u`}],[`path`,{d:`M7 4v16`,key:`1glfcx`}]]};U.node;var W=C(U),G={name:`pencil`,size:24,node:[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]};G.node;var K=C(G),q=e(t(),1),J=v(`app/delete`),Y=_(),X=({blockingPlural:e,noun:t})=>J(`stillPointAt`,{plural:e,noun:t}),Z=({blockedBy:e,resources:t,views:n,noun:r,key:i})=>{let{resource:a,field:o}=e;if(!t[a])return;let s=n[a]?.names?.plural??l(a),c=X({blockingPlural:s,noun:r});if(!o||i===void 0)return{text:c};let u={kind:`list`,resource:a,filter:S(Y.eq(o,i))};return{text:c,link:{label:J(`show`,{plural:s}),to:u}}},Q=e(n(),1),te=({title:e,noun:t,busy:n,onConfirm:i,onCancel:a})=>(0,Q.jsx)(r,{title:J(`confirmTitle`,{title:e}),description:J(`confirmDescription`,{noun:t,title:e}),onClose:a,actions:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(f,{onClick:a,children:J(`cancel`)}),(0,Q.jsx)(f,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:i,children:J(`delete`)})]})}),ne=({title:e,changes:t,busy:n,onReview:i,onDeleteAnyway:a,onCancel:o})=>(0,Q.jsx)(r,{title:J(`changedTitle`,{title:e}),description:J(`changedDescription`),onClose:o,actions:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(f,{onClick:i,children:J(`reviewChanges`)}),(0,Q.jsx)(f,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,loading:n,onClick:a,children:J(`deleteAnyway`)})]}),children:t.length===0?(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:J(`noVisibleChanges`)}):(0,Q.jsx)(`ul`,{className:`divide-y rounded-md border`,children:t.map(e=>(0,Q.jsxs)(`li`,{className:`grid grid-cols-[96px_1fr] gap-3 px-3 py-2`,children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground`,children:e.label}),(0,Q.jsxs)(`span`,{children:[(0,Q.jsx)(`span`,{className:`text-muted-foreground line-through`,children:e.before}),` `,(0,Q.jsx)(`span`,{className:`font-medium`,children:e.after})]})]},e.field))})}),$=e=>{if(e.stage===`confirm`)return(0,Q.jsx)(r,{title:J(`bulkConfirmTitle`,{count:e.count,noun:e.noun,plural:e.plural}),description:J(`bulkConfirmDescription`),onClose:e.onCancel,actions:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(f,{onClick:e.onCancel,children:J(`cancel`)}),(0,Q.jsx)(f,{variant:`primary`,className:`bg-danger hover:bg-danger/90`,onClick:e.onConfirm,children:J(`deleteCount`,{count:e.count})})]})});if(e.stage===`running`)return(0,Q.jsx)(r,{title:J(`deleting`),description:J(`progress`,{done:e.done,total:e.total}),onClose:()=>void 0,actions:(0,Q.jsx)(f,{loading:!0,disabled:!0,children:J(`working`)})});let t=e.total-e.failures.length;return(0,Q.jsx)(r,{title:e.failures.length===0?J(`deleted`,{count:t}):J(`deletedOf`,{count:t,total:e.total}),description:e.failures.length===0?void 0:J(`kept`,{count:e.failures.length}),onClose:e.onClose,actions:(0,Q.jsx)(f,{variant:`primary`,onClick:e.onClose,children:J(`done`)}),children:e.failures.length>0&&(0,Q.jsx)(`ul`,{className:`max-h-48 divide-y overflow-y-auto rounded-md border`,children:e.failures.map(e=>(0,Q.jsxs)(`li`,{className:`px-3 py-2`,children:[(0,Q.jsx)(`span`,{className:`font-medium`,children:e.title}),(0,Q.jsx)(`span`,{className:`block text-xs text-danger-text`,children:e.message})]},e.title))})})},re=new Set([`updated_at`,`updatedAt`]),ie=(e,t,n,r)=>Object.values(e.fields).flatMap(e=>{if(re.has(e.name)||JSON.stringify(n[e.name]??null)===JSON.stringify(r[e.name]??null))return[];let i=t?.fields[e.name];return[{field:e.name,label:i?.label??l(e.name),before:p(e,n[e.name],i),after:p(e,r[e.name],i)}]}),ae=4,oe=({model:e,view:t,onDeleted:n,onReview:r,restore:i})=>{let a=h(),o=N(),c=s(),[u,d]=(0,q.useState)(),[f,p]=(0,q.useState)(!1),m=t?.names?.singular??l(e.name),g=t?.names?.plural??l(e.name),{resources:_,views:v}=j(),{href:y,open:b}=w(),S=(t,n)=>t.blockedBy&&Z({blockedBy:t.blockedBy,resources:_,views:v,noun:m,...e.primaryKey.length===1&&{key:n.key}}),C=()=>{for(let t of[`page`,`list`,`first-page`,`map`])o.invalidateQueries({queryKey:[t,e.name]});for(let t of[`facets`,`series`,`aggregate`,`histogram`,`count`])o.invalidateQueries({queryKey:[t,e.name]})},T=async(t,n)=>{let r=n??(await a.get(e.name,t.key)).etag;try{await a.remove(e.name,t.key,{etag:r})}catch(e){if(!(e instanceof x))throw e;return e}},E=t=>{C(),d(void 0),n?.(t),c.show({state:`success`,title:J(`deletedToast`,{title:t.title}),...e.softDelete&&i&&{action:{label:J(`undo`),onClick:()=>{i(t).then(()=>{C(),c.show({state:`success`,title:J(`restored`,{title:t.title})})},e=>{if(!A(e))throw e;C(),c.show({state:e.status===409?`success`:`error`,title:e.status===409?J(`alreadyBack`,{title:t.title}):J(`couldNotRestore`,{title:t.title}),description:e.status===409?void 0:e.message})})}}}})},D=async(n,r)=>{p(!0);try{if(!await T(n,r))return E(n);let i=(await a.get(e.name,n.key)).record;d({kind:`conflict`,target:n,fresh:i,changes:ie(e,t,n.snapshot,i)})}catch(e){if(!A(e))throw e;d(void 0);let t=S(e,n);c.show({state:`error`,title:J(`couldNotDelete`,{title:n.title}),description:t?.text??e.message,...t?.link&&{action:{label:t.link.label,href:y(t.link.to),onNavigate:b}}})}finally{p(!1)}},O=async e=>{try{return await T(e,e.etag)?{title:e.title,message:J(`changedSinceLoaded`)}:void 0}catch(t){if(!A(t))throw t;return{title:e.title,message:S(t,e)?.text??t.message}}},k=async e=>{let t=[],n=[],r=0;d({kind:`bulk-running`,done:r,total:e.length});let i=[...e];return await Promise.all(Array.from({length:Math.min(ae,e.length)},async()=>{for(let a=i.shift();a;a=i.shift()){let i=await O(a);i&&(t.push(i),n.push(a)),r+=1,d({kind:`bulk-running`,done:r,total:e.length})}})),C(),d({kind:`bulk-done`,total:e.length,failures:t}),n},M=()=>d(void 0);return{dialogs:u&&(0,Q.jsxs)(Q.Fragment,{children:[u.kind===`confirm`&&(0,Q.jsx)(te,{title:u.target.title,noun:m,busy:f,onCancel:M,onConfirm:()=>void D(u.target,u.target.etag)}),u.kind===`conflict`&&(0,Q.jsx)(ne,{title:u.target.title,changes:u.changes,busy:f,onCancel:M,onReview:()=>{M(),r?.(u.target,u.fresh)},onDeleteAnyway:()=>void D(u.target,`*`)}),u.kind===`bulk-confirm`&&(0,Q.jsx)($,{stage:`confirm`,count:u.targets.length,noun:m,plural:g,onCancel:()=>{M(),u.settle(u.targets)},onConfirm:()=>u.settle(k(u.targets))}),u.kind===`bulk-running`&&(0,Q.jsx)($,{stage:`running`,done:u.done,total:u.total}),u.kind===`bulk-done`&&(0,Q.jsx)($,{stage:`done`,total:u.total,failures:u.failures,onClose:M})]}),start:t=>e.softDelete?D(t,t.etag):d({kind:`confirm`,target:t}),startBulk:e=>new Promise(t=>d({kind:`bulk-confirm`,targets:e,settle:t}))}},se=e=>{let t=h();return e.softDelete?async n=>void await t.undelete(e.name,n.key):void 0},ce=(e,t,n)=>({order:r,index:i})=>{let o=t=>r.findIndex(n=>c(a(e,n))===t),s=t.after.find(e=>o(e.key)>i);if(s)return H(`dependsOn`,{record:n,other:s.title});let l=t.before.find(e=>o(e.key)!==-1&&o(e.key)<i);return l?H(`dependsOn`,{record:l.title,other:n}):void 0},le=(e,t,n,r)=>{let i=e[t],a;for(let o=n;o<e.length;o++){let n=r({record:i,order:I(e,t,o),index:o});if(n===void 0)return{to:o,...a!==void 0&&{reason:a}};a??=n}return{to:t,reason:a}},ue=({model:e,view:t,field:n,filter:r,fields:i,rule:a})=>{let o=h(),c=s(),l=M(),{resources:d,views:f}=j(),p=`${n} asc`,g=P({queryKey:[...y.list(e.name,r,p,500,`hand-order`),i.join(`,`)],queryFn:async()=>{let t=T(d,f,e,i),n=[],a=``;do{let s=await o.search(e.name,{filter:r||void 0,orderBy:p,pageSize:500,labels:t,...a&&{pageToken:a}});n.push(...b(d,e,i,s.items,s.labels).map((t,n)=>({...t,id:u(e,s.items[n])}))),a=s.nextPageToken}while(a);return n}}),[_,v]=(0,q.useState)(),x=(0,q.useRef)(void 0),S=(0,q.useRef)([]),C=(0,q.useRef)(void 0),w=(0,q.useRef)(Promise.resolve()),E=(0,q.useRef)(0),D=(0,q.useRef)(void 0),k=async()=>{let t=x.current,r=S.current;if(S.current=[],!t||r.length===0)return;let i=await o.batchWrite(r),a=new Map(i.results.flatMap(e=>e.op===`move`?e.records:[]).map(t=>[u(e,t.record),t])),s=z(i.results,t=>u(e,t)),l=L(e,[...a].map(([e,t])=>({...t,before:{[n]:s.get(e)}})),[n]);D.current!==void 0&&c.dismiss(D.current),D.current=c.show({state:`success`,title:V(`orderChanged`),action:{label:V(`undo`),onClick:()=>W(l)}}),x.current&&=x.current.map(e=>{let t=a.get(e.id);return t?{...e,[n]:t.record[n],etag:t.etag}:e})},A=(e,t)=>n=>{x.current=void 0,S.current=[],v(void 0),c.show(B(n,e,{place:`list`,title:t?C.current:void 0}))},N=async()=>{--E.current,!(E.current>0)&&(await l(e.name),!(E.current>0)&&(x.current=void 0,v(void 0)))},F=(n,r)=>{let i=x.current??g.data;if(!i||n===r)return;if(!e.position?.after)return H(i,n,r,a);let s=O(e,i[n]).record,c=i[n].id;R(o,e,t,s).then(n=>{let i=x.current??g.data,o=ce(e,n,m(e,t,s,c));H(i,i.findIndex(e=>e.id===c),r,e=>o(e)??a?.(e))},A(V(`couldNotChange`),!1))},H=(i,a,o,s)=>{if(a===-1||a===o)return;let c=s?U(i,a,o,s):o;a!==c&&(x.current=I(i,a,c),S.current=[...S.current,ee(e,n,r,x.current,c)],v(x.current),E.current+=1,C.current=m(e,t,O(e,i[a]).record,i[a].id),w.current=w.current.then(k).catch(A(V(`couldNotChange`),!0)).then(N))},U=(t,n,r,i)=>{let a=le(t.map(t=>O(e,t).record),n,r,i);return a.reason!==void 0&&c.show({state:`warning`,title:a.to===n?V(`notMoved`):V(`movedToPlace`,{place:a.to+1}),description:a.reason}),a.to},W=e=>{D.current!==void 0&&c.dismiss(D.current),D.current=void 0,E.current+=1,w.current=w.current.then(async()=>{await o.batchWrite(e),x.current=void 0,S.current=[],v(void 0)}).catch(A(V(`couldNotUndo`),!1)).then(N)};return{rows:_??g.data,loading:g.isPending,error:g.error,move:F}},de=({model:e,view:t,field:n,filter:r,columns:s,sort:c})=>{let{resources:l,views:u}=j(),{fields:f,dropRules:p}=o(),{go:h,href:_}=w(),v=c!==void 0,y=(0,q.useMemo)(()=>g(e,t,s,{resources:l,views:u,fieldTypes:f}).map(e=>v?e:{...e,sortable:!1}),[e,t,s.join(`,`),l,u,f,v]),b=(0,q.useMemo)(()=>E(e,t,y.map(e=>e.id)),[e,t,y]),x=t?.list?.drag?.rule,S=x===void 0?void 0:p?.[x],C=ue({model:e,view:t,field:n,filter:r,fields:b,...S&&{rule:S}}),T=C.rows,O=(0,q.useMemo)(()=>T&&{total:T.length,rowAt:e=>T[e]},[T]);if(x!==void 0&&!S)return(0,Q.jsx)(D,{children:V.rich(`noRule`,{rule:x})});if(C.loading)return(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:Array.from({length:3},(e,t)=>(0,Q.jsx)(d,{className:`h-4 w-full`},t))});if(C.error)return(0,Q.jsx)(i,{title:V(`couldNotLoad`),error:C.error});if(!O||O.total===0)return(0,Q.jsx)(`p`,{className:`text-muted-foreground`,children:V(`nothingYet`)});let k=t=>h({kind:`record`,resource:e.name,key:a(e,t)});return(0,Q.jsx)(F,{fit:!0,scroll:`parent`,columns:y,source:O,latencyMs:0,onOpenRow:k,rowLink:t=>({href:_({kind:`record`,resource:e.name,key:a(e,t)}),onFollow:()=>k(t)}),...c&&{sort:c.value,onSortChange:c.onChange},rowNumbers:!1,reorder:{label:n=>m(e,t,n,n.id),onMove:C.move}})},fe=({sorting:e,onChange:t,size:n,iconOnly:r=!1})=>{let i=V(e?`done`:`reorder`);return(0,Q.jsxs)(f,{size:n,variant:e?`primary`:`secondary`,onClick:()=>t(!e),...r&&{"aria-label":i,title:i},children:[e?(0,Q.jsx)(k,{className:`size-3.5`}):(0,Q.jsx)(W,{className:`size-3.5`}),!r&&i]})};export{K as a,oe as i,de as n,se as r,fe as t};
2
- //# debugId=0d35f71f-b9ae-45dc-a0be-e3738adaa28e
@@ -1 +0,0 @@
1
- (function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{$ as e,$i as t,$t as n,Ar as r,At as ee,B as te,Br as i,Bt as a,Cc as o,Co as s,Cs as c,Ct as l,Dc as u,Dt as d,Ea as f,Ec as p,Er as m,Es as h,Et as g,F as _,Ft as v,G as y,Go as b,Gr as x,H as S,Ht as C,Io as w,It as T,Ja as E,Jo as D,Jt as O,K as k,Ko as A,Kr as j,Lt as M,Mn as N,Mo as P,Mt as F,Nr as I,Nt as L,On as R,Oo as z,Or as B,P as V,Po as H,Pr as U,Pt as W,Q as G,Qa as K,Rr as q,So as J,St as Y,Ta as X,Tc as Z,Tr as Q,Ts as ne,Tt as re,U as ie,Ua as ae,Uo as oe,Ur as se,Ut as ce,V as le,Vt as ue,W as de,Wa as fe,Wr as pe,Wt as me,X as he,Yt as ge,Zt as _e,_l as ve,_t as $,aa as ye,bc as be,bt as xe,cl as Se,dl as Ce,dt as we,ea as Te,en as Ee,es as De,et as Oe,fl as ke,ft as Ae,gt as je,hr as Me,ht as Ne,i as Pe,ia as Fe,in as Ie,it as Le,jo as Re,jr as ze,ko as Be,kr as Ve,ll as He,lt as Ue,ml as We,mt as Ge,na as Ke,no as qe,nt as Je,oa as Ye,ot as Xe,pl as Ze,pt as Qe,qa as $e,qn as et,qo as tt,qr as nt,qt as rt,r as it,ra as at,rn as ot,ro as st,rt as ct,t as lt,ta as ut,tn as dt,to as ft,tt as pt,ul as mt,ut as ht,vt as gt,wo as _t,wr as vt,ws as yt,wt as bt,xt,yt as St,z as Ct,zr as wt}from"./app-DANB5cb3.js";import{h as Tt,o as Et}from"./vendor-t7Q7QbPu.js";export{Y as ActionCard,ze as ActionInputError,yt as ApiProvider,pe as App,j as AppLink,tt as AppMark,Ae as AssistantDock,_t as AuthLayout,Re as AvailabilityMark,Z as Button,a as CallMark,me as CallView,k as Carousel,W as ChatDivider,L as ChatMessage,F as ChatThread,te as Choices,J as CodeForm,xe as CompactTable,bt as Composer,o as Dialog,$ as DiffView,Ct as Field,dt as FieldBadge,xt as FieldList,Q as FileReadError,e as FocusActions,Oe as FocusNotice,Le as FocusPage,pt as FocusPanel,Je as FocusSlot,V as Form,Ve as HtmlFrame,it as InPlaceForm,oe as Input,D as LogoMark,N as Markdown,g as MentionBox,re as MentionedText,le as MenuSelect,H as MenuSurface,z as OtpInput,Ge as PartView,C as RecordCall,_e as RecordLink,lt as RecordPicker,s as ResendCodeButton,at as ResponsiveDialog,be as RouteLink,he as SearchPicker,_ as Section,w as Segmented,R as Select,l as SidePanel,M as SignInPrompt,u as Spinner,P as StatusMark,Ne as StepList,et as Textarea,Ee as ToneEdge,ge as TypingLine,S as allowDelayMs,p as buttonClass,v as chatDayLabel,De as closeSidebarEvent,ae as definePlugin,fe as defineUi,gt as diffStats,d as emptyDraft,He as extensionPointsOf,r as fileNamed,I as isConflict,ie as isFramed,A as logoTapEvent,ee as mentionedIds,Ue as menuItemClass,Ce as mergeUi,St as parseDiff,je as parsePatch,Ze as pluginApi,Se as pluginsChangedEvent,We as protobaseVersion,T as sameChatDay,ve as showTextsIn,B as siblingPage,Be as signedOutEvent,Te as statusRefreshMs,ke as uiFromModule,x as uiReadyEvent,st as useApiToken,nt as useAppAddress,de as useArmedAfterFocus,we as useAssistant,ht as useAssistantClient,Qe as useBackendData,ne as useClient,ot as useComponentReads,Ie as useComponentSelect,Pe as useCreateForm,q as useFacets,b as useFieldControl,m as useFileText,Xe as useFocusPage,G as useFocusRecord,ct as useFocusZoneFilled,y as useGuardedPress,wt as useHistogram,Fe as useInbox,Me as useLayoutRecord,se as useList,n as useListDisplay,ye as useMarkNotificationsRead,t as useMembers,c as useMeta,ut as useOwnStatus,mt as usePlugin,f as usePopoverMenu,$e as usePresence,X as usePushNotifications,Et as useQuery,Tt as useQueryClient,K as useRecord,ce as useRecordCallAddress,ue as useRecordCalls,h as useResourceClient,i as useSeries,vt as useSiblingPage,qe as useSignedInUser,Ke as useStatuses,E as useToast,ft as useTypers,O as useTypingSender,Ye as useUnreadNotifications,U as useUpdateRecord,rt as useViewChannel};
@@ -1,2 +0,0 @@
1
- (function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t,t as n}from"./react-CuiNlnus.js";import{Dc as r,Fs as i,Ps as a,Rs as o,Tc as s,ds as c,hs as l,la as u,ps as d,sl as f,us as p,yl as m}from"./app-DANB5cb3.js";import{t as h}from"./page-header-Ddz2r5ic.js";var g=e(t(),1),_=()=>[{value:`allowed`,label:a(`on`)},{value:`forbidden`,label:a(`off`)}],v=()=>[{value:`allowed`,label:a(`optional`)},{value:`required`,label:a(`required`)},{value:`forbidden`,label:a(`off`)}],y=()=>[{method:`password`,label:a(`password`),description:a(`passwordDescription`),rules:_()},{method:`emailCode`,label:a(`emailedSignInCode`),description:a(`emailedSignInCodeDescription`),rules:_()},{method:`passkey`,label:a(`passkeys`),description:a(`passkeysPolicyDescription`),rules:v()},{method:`twoFactor`,label:a(`twoFactor`),description:a(`twoFactorPolicyDescription`),rules:v()},{method:`staffAccess`,label:a(`staffAccess`),description:a(`staffAccessDescription`),rules:[{value:`allowed`,label:a(`on`)},{value:`notify`,label:a(`emailThePerson`)},{value:`forbidden`,label:a(`off`)}]},{method:`platformSignIn`,label:a(`platformSignIn`),description:a(`platformSignInDescription`),rules:_()}],b=(e,t)=>{let n=y().find(t=>t.method===e)?.rules.find(e=>e.value===t)?.label;if(n===void 0)throw Error(`No label for the ${t} rule of ${e}`);return n},x=e(n(),1),S=({row:e,value:t,onChange:n})=>(0,x.jsx)(`span`,{role:`radiogroup`,"aria-label":e.label,className:`inline-flex h-8 shrink-0 rounded-md bg-muted p-0.5`,children:e.rules.map(e=>(0,x.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":e.value===t,onClick:()=>n(e.value),className:f(`rounded px-3 text-body font-medium transition-colors`,e.value===t?`bg-background text-foreground shadow-sm`:`text-muted-foreground hover:text-foreground`),children:e.label},e.value))}),C=({method:e},t,{mail:n,effective:r,policy:i})=>{if(e===`emailCode`&&!n)return a(`codeNeedsMail`);if(e===`password`&&!n&&t.password===`forbidden`)return a(`passwordStaysOn`);if(e===`staffAccess`&&!n&&t.staffAccess===`notify`)return a(`staffNeedsMail`);if(e===`platformSignIn`&&t.platformSignIn===`allowed`&&t.passkey===`required`)return a(`platformOff`);if(t[e]===i[e]&&r[e]!==i[e])return a(`appliesAs`,{rule:b(e,r[e])})},w=({operator:e,platformProviders:t=[]})=>y().flatMap(n=>n.method===`staffAccess`&&!e?[]:n.method===`platformSignIn`?t.length>0?[{...n,label:a(`platformSignInWith`,{provider:new Intl.ListFormat(m(),{type:`conjunction`}).format(t)})}]:[]:[n]),T=({state:e,onSave:t,busy:n,error:r,notice:i})=>{let[o,c]=(0,g.useState)(e.policy),l=w(e),d=l.some(({method:t})=>o[t]!==e.policy[t]);return(0,x.jsxs)(`form`,{className:`flex flex-col gap-4`,onSubmit:e=>{e.preventDefault(),t(o)},children:[(0,x.jsx)(`ul`,{className:`divide-y rounded-lg border bg-background`,children:l.map(t=>{let n=C(t,o,e);return(0,x.jsxs)(`li`,{className:`flex flex-col gap-3 p-4 sm:flex-row sm:items-start sm:justify-between`,children:[(0,x.jsxs)(`div`,{className:`min-w-0`,children:[(0,x.jsx)(`h2`,{className:`font-semibold`,children:t.label}),(0,x.jsx)(`p`,{className:`mt-0.5 text-muted-foreground`,children:t.description}),n&&(0,x.jsx)(`p`,{className:`mt-1.5 text-xs font-medium text-warning-text`,children:n})]}),(0,x.jsx)(S,{row:t,value:o[t.method],onChange:e=>c({...o,[t.method]:e})})]},t.method)})}),r&&(0,x.jsx)(`p`,{role:`alert`,className:`rounded-md bg-danger-soft px-3 py-2 text-body font-medium text-danger-text`,children:r}),i&&!d&&(0,x.jsx)(`p`,{role:`status`,className:`rounded-md bg-success-soft px-3 py-2 text-body font-medium text-success-text`,children:i}),(0,x.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,x.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.savedAt?e.savedBy?a(`lastSavedBy`,{name:e.savedBy,time:u(Date.parse(e.savedAt))}):a(`lastSaved`,{time:u(Date.parse(e.savedAt))}):a(`neverChanged`)}),(0,x.jsxs)(`div`,{className:`flex gap-2`,children:[d&&(0,x.jsx)(s,{onClick:()=>c(e.policy),children:a(`reset`)}),(0,x.jsx)(s,{variant:`primary`,type:`submit`,loading:n,disabled:!d,children:a(`save`)})]})]})]})},E=(e,t)=>e.endedAt?(0,x.jsx)(d,{tone:`neutral`,children:a(`stopped`,{time:u(Date.parse(e.endedAt))})}):Date.parse(e.expiresAt)<=t?(0,x.jsx)(d,{tone:`neutral`,children:a(`ended`,{time:u(Date.parse(e.expiresAt))})}):(0,x.jsx)(d,{tone:`amber`,children:a(`signedInUntil`,{time:u(Date.parse(e.expiresAt))})}),D=({signIns:e,operator:t,error:n,now:r=Date.now()})=>(0,x.jsxs)(p,{title:a(`staffSignIns`),description:a(`staffSignInsDescription`,{operator:t}),children:[(0,x.jsx)(c,{message:n}),e&&e.length===0&&(0,x.jsx)(`p`,{className:`text-muted-foreground`,children:a(`noStaffSignIns`)}),e&&e.length>0&&(0,x.jsx)(`ul`,{className:`divide-y rounded-md border`,children:e.map(e=>(0,x.jsxs)(`li`,{className:`flex flex-col gap-1.5 p-3`,children:[(0,x.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,x.jsx)(`span`,{className:`font-medium break-all`,children:e.staffName?`${e.staffName} (${e.staff})`:e.staff}),(0,x.jsx)(`span`,{className:`text-muted-foreground`,children:a(`as`)}),(0,x.jsx)(`span`,{className:`font-medium break-all`,children:e.user})]}),(0,x.jsx)(`p`,{className:`break-words`,children:e.reason}),(0,x.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-muted-foreground`,children:[(0,x.jsx)(`span`,{children:u(Date.parse(e.startedAt))}),E(e,r)]})]},e.id))})]}),O=({operator:e})=>{let{session:t}=i(),[n,r]=(0,g.useState)(),[s,c]=(0,g.useState)();return(0,g.useEffect)(()=>{t.staff.log().then(r,e=>c(e instanceof o?l(e):a(`couldNotReadStaffSignIns`)))},[t]),(0,x.jsx)(D,{operator:e,signIns:n,error:s})},k=()=>{let{session:e}=i(),[t,n]=(0,g.useState)(),[s,c]=(0,g.useState)(!1),[u,d]=(0,g.useState)(),[f,p]=(0,g.useState)();(0,g.useEffect)(()=>{e.signInPolicy.read().then(n,e=>d(e instanceof o?l(e):a(`couldNotReadPolicy`)))},[e]);let m=async t=>{c(!0),d(void 0),p(void 0);try{n(await e.signInPolicy.save(t)),p(a(`policySaved`))}catch(e){if(!(e instanceof o))throw e;d(l(e))}c(!1)};return(0,x.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6 md:px-6`,children:[(0,x.jsx)(h,{title:a(`signInPolicy`),subtitle:a(`policySubtitle`)}),t?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(T,{state:t,busy:s,error:u,notice:f,onSave:e=>void m(e)},t.savedAt??`default`),t.operator&&(0,x.jsx)(O,{operator:t.operator})]}):u?(0,x.jsx)(`p`,{role:`alert`,className:`text-danger-text`,children:u}):(0,x.jsxs)(`div`,{className:`flex items-center gap-2 text-muted-foreground`,children:[(0,x.jsx)(r,{}),` `,a(`loading`)]})]})};export{k as SignInPolicyPage};
2
- //# debugId=116b1b83-4445-4bf5-9857-2780f222798e
@@ -1,2 +0,0 @@
1
- (function(){try{var e=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:typeof self<`u`?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[new e.Error().stack]=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];if(n!=null)for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},e._sentryModuleMetadata[new e.Error().stack],{"_sentryBundlerPluginAppKey:protobase-app":!0})}catch{}})();import{o as e}from"./rolldown-runtime-DFwUHQ4A.js";import{i as t}from"./react-CuiNlnus.js";import{Fr as n,Ga as r,Gs as i,Hr as a,Hs as o,Ts as s,_n as c,dn as l,gn as u,gr as d,ic as f,ja as p,ln as m,lr as h,mr as g,ns as _,qs as v,rr as y,sr as b,un as x,vn as S,vs as C}from"./app-DANB5cb3.js";import{h as w}from"./vendor-t7Q7QbPu.js";import{S as T,ht as E,r as D}from"./embedded-list-CepLmiOu.js";import{n as O}from"./record-preview-B1WiPOw4.js";var k=e(t(),1),A=e=>({queryKey:e.queryKey,start:t=>t.prefetchQuery(e)}),j=e=>({queryKey:e.queryKey,start:t=>t.prefetchInfiniteQuery(e)}),M={Table:(e,t,n)=>{let{resource:r,filter:i=``,sort:a=``,columns:o,button:s,bulk:u=!1,limit:d=10,select:f}=x(e),h=r===void 0?void 0:n.resources[r];if(!h)return[];if(t.part===`chosen`){let e=f===void 0?void 0:n.given[f];return e?[A(c(n.client,h,{key:e}))]:[]}let g=n.views[h.name],{fields:_,read:y}=l({...n,model:h,view:g,columns:o?.map(v),button:s,bulk:u,phoneColumns:m(o)});return[A(D(n,{model:h,filter:i,orderBy:a||p(h,g),limit:d,fields:_,read:y}))]},Chart:(e,t,{client:r,resources:i,views:a})=>{let{resource:o,groupBy:s,splitBy:c,sum:l,average:u,filter:d,granularity:f,range:p,limit:m}=x(e),h=i[o],g=h&&E({model:h,groupBy:s,splitBy:c,sum:l,average:u,filter:d,granularity:f,range:p,limit:m},i,a);return h&&g?[A(n(r,h.name,g))]:[]},RecordCards:(e,t,{client:n,resources:r,views:i})=>{let{resource:a,filter:o=``,sort:s=``,limit:c=10}=x(e),l=r[a];if(!l)return[];let d=s||p(l,i[l.name]);return[A(S(n,l,{filter:o,sort:d,pageSize:c})),A(u(n,l,o))]},RecordRow:(e,t,{client:n,queryClient:r,resources:i,views:a})=>{let{resource:o,filter:s=``,sort:c=``}=x(e),l=i[o];if(!l)return[];let u=a[l.name];return u?.searchesOf||u?.listOf!==void 0?[]:[A(O({queryClient:r,client:n,resources:i,views:a,model:l,...T(l,u,{filter:s,sort:c})}))]},Thread:(e,t,{client:n,resources:r,views:i})=>{let{resource:o,filter:s,sender:c,time:l,calls:u,limit:d=50}=x(e);if(t.part===`calls`){let e=u&&r[u.resource];return e?[j(a(n,e.name,{filter:u.filter,orderBy:f(u.time),pageSize:d}))]:[]}let p=r[o];if(!p)return[];let m=y(r,i,p,c===void 0?[]:[c]);return[j(a(n,p.name,{filter:s,orderBy:f(l),pageSize:d,labels:m}))]}},N=(e,t,{client:n,resources:r})=>{let i=r[t.resource];return i?[A(u(n,i))]:[]},P=(e,t,n)=>(n?.reads??[]).flatMap(n=>{let r=i(t,n.block);if(!r||r.custom)return[];if(n.part===`condition`)return N(r,n,e);if(n.split)return[];let a=M[r.type];return a?a(o(r,{stack:[],params:e.params,...e.root&&{root:e.root}}),n,e):[]}),F=({tree:e,plan:t})=>{let n=s(),i=w(),{resources:a,views:o}=C(),c=r().fields,l=_(),u=b(),f=h(),p=g(d()),m=(0,k.useMemo)(()=>P({client:n,queryClient:i,resources:a,views:o,fieldTypes:c,xs:l,params:u,given:f,...p&&{root:p}},e,t),[n,i,a,o,c,l,u,f,p,e,t]);return(0,k.useEffect)(()=>{for(let e of m)e.start(i)},[m,i]),null};export{F as t};
2
- //# debugId=d36ba6a4-3dc0-4122-8d83-3b9383196048